Changeset 1504


Ignore:
Timestamp:
Jan 18, 2012, 1:43:53 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #346: Create virtual patient for cases with consent=no or not asked

Location:
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/Patient.java

    r1503 r1504  
    88import net.sf.basedb.core.BioSource;
    99import net.sf.basedb.core.DbControl;
     10import net.sf.basedb.core.Include;
    1011import net.sf.basedb.core.InvalidDataException;
    1112import net.sf.basedb.core.Item;
     
    1314import net.sf.basedb.core.Sample;
    1415import net.sf.basedb.core.query.Annotations;
     16import net.sf.basedb.core.query.Expressions;
     17import net.sf.basedb.core.query.Hql;
     18import net.sf.basedb.core.query.Orders;
     19import net.sf.basedb.core.query.Restrictions;
    1520import net.sf.basedb.reggie.Reggie;
    1621import net.sf.basedb.reggie.converter.DateToStringConverter;
     22import net.sf.basedb.util.MD5;
    1723
    1824/**
     
    7379 
    7480 
     81  /**
     82    Generate the next auto-generated patient name. This method will search all patients
     83    starting with the given prefix and find the one with the highest numeric suffix.
     84    The returned name is the found patient + 1.
     85    @since 2.1
     86  */
     87  public static String generateNextName(DbControl dc, String prefix)
     88  {
     89    ItemQuery<BioSource> patientQuery = BioSource.getQuery();
     90    Subtype.PATIENT.addFilter(dc, patientQuery);
     91    patientQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.string(prefix + "%")));
     92    patientQuery.order(Orders.desc(Hql.property("name")));
     93    patientQuery.setMaxResults(1);
     94    patientQuery.include(Include.ALL);
     95    List<BioSource> patients = patientQuery.list(dc);
     96    String name = null;
     97    if (patients.size() == 0)
     98    {
     99      name = prefix + "000001";
     100    }
     101    else
     102    {
     103      String patientName = patients.get(0).getName().substring(prefix.length());
     104      int nextPatientNumber = Integer.parseInt(patientName) + 1;
     105      name = prefix + MD5.leftPad(Integer.toString(nextPatientNumber), '0', 6);
     106    }
     107    return name;
     108  }
     109 
    75110  private Patient(BioSource bioSource)
    76111  {
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/ConsentFormServlet.java

    r1463 r1504  
    1717import net.sf.basedb.core.AnnotationType;
    1818import net.sf.basedb.core.Application;
     19import net.sf.basedb.core.BioSource;
    1920import net.sf.basedb.core.DbControl;
    2021import net.sf.basedb.core.Item;
     
    2526import net.sf.basedb.reggie.converter.StringToDateConverter;
    2627import net.sf.basedb.reggie.dao.Case;
     28import net.sf.basedb.reggie.dao.Patient;
    2729import net.sf.basedb.reggie.dao.SpecimenTube;
    2830import net.sf.basedb.reggie.dao.Subtype;
     
    169171            theCase.setDescription((String)jsonCase.get("reasonIfNotAsked"));
    170172          }
     173          if (!"Yes".equals(consent))
     174          {
     175            // Create virtual patient
     176            BioSource vPat = BioSource.getNew(dc);
     177            vPat.setItemSubtype(Subtype.PATIENT.load(dc));
     178            vPat.setName(Patient.generateNextName(dc, consent));
     179            theCase.getCreationEvent().setSource(vPat);
     180            dc.saveItem(vPat);
     181            jsonMessages.add("Patient '" + vPat.getName() + "' created.");
     182          }
     183         
    171184          dc.saveItem(theCase);
    172185          jsonMessages.add("Case '" + caseName + "' created successfully with consent: " + consent);
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/PersonalRegistrationServlet.java

    r1503 r1504  
    2020import net.sf.basedb.core.BioSource;
    2121import net.sf.basedb.core.DbControl;
    22 import net.sf.basedb.core.Include;
    2322import net.sf.basedb.core.InvalidDataException;
    2423import net.sf.basedb.core.Item;
    25 import net.sf.basedb.core.ItemQuery;
    2624import net.sf.basedb.core.Sample;
    2725import net.sf.basedb.core.SessionControl;
    28 import net.sf.basedb.core.query.Expressions;
    29 import net.sf.basedb.core.query.Hql;
    30 import net.sf.basedb.core.query.Orders;
    31 import net.sf.basedb.core.query.Restrictions;
    3226import net.sf.basedb.reggie.Reggie;
    3327import net.sf.basedb.reggie.converter.DateToStringConverter;
     
    192186        {
    193187          // No patient was found -- try to find the highest existing patient number
    194           ItemQuery<BioSource> patientQuery = BioSource.getQuery();
    195           Subtype.PATIENT.addFilter(dc, patientQuery);
    196           patientQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.string("PAT%")));
    197           patientQuery.order(Orders.desc(Hql.property("name")));
    198           patientQuery.setMaxResults(1);
    199           patientQuery.include(Include.ALL);
    200           List<BioSource> patients = patientQuery.list(dc);
    201188          jsonPat = new JSONObject();
    202189          jsonPat.put("personalNumber", pnr);
    203           if (patients.size() == 0)
    204           {
    205             jsonPat.put("name", "PAT000001");
    206           }
    207           else
    208           {
    209             String patientName = patients.get(0).getName().replace("PAT", "");
    210             int nextPatientNumber = Integer.parseInt(patientName) + 1;
    211             jsonPat.put("name", "PAT" + MD5.leftPad(Integer.toString(nextPatientNumber), '0', 6));
    212           }
     190          jsonPat.put("name", Patient.generateNextName(dc, "PAT"));
    213191          if (pnrIsValid)
    214192          {
Note: See TracChangeset for help on using the changeset viewer.