Changeset 1513


Ignore:
Timestamp:
Jan 19, 2012, 1:56:41 PM (11 years ago)
Author:
Nicklas Nordborg
Message:

References #348: Consent form registration wizard should allow 'Yes' in all cases

This should more or less be working now... I hope I havn't missed some exotic case. Need to add more things when the blood registration wizard (#350) has been implemented so I'll keep this ticket open.

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

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/consentform.jsp

    r1369 r1513  
    135135    enableConsentOption('consent.yes', true);
    136136    setInputStatus('consent', 'This case already exists.', 'valid');
    137     Main.showInline('morehelp.yes');
     137    Main.showInline('morehelp.yesonly');
    138138    Main.show('gocancel');
    139139    Main.show('goregister');
     
    142142  {
    143143    // There is no existing case but there are specimen related to it
    144     // This wizard can't be used until the "Personal registration wizard"
    145     // has been completed for this case
    146     setInputStatus('consent', 'Specimen tubes for this case already exists.', 'invalid');
    147     Main.showInline('morehelp.specimen');
    148     Main.show('gorestart');
    149     frm.consentDate.disabled = true;
     144    // This wizard will only allow 'Yes' option on the consent form
     145    enableConsentOption('consent.yes', true);
     146    setInputStatus('consent', 'Specimen tubes for this case already exists.', 'valid');
     147    Main.showInline('morehelp.yesonly');
     148    Main.show('gocancel');
     149    Main.show('goregister');
    150150  }
    151151  else
    152152  {
    153     // We have no information about this case
    154     // The wizard will only allow 'No' and 'Not asked' option on the consent form
     153    // We have no information about this case -- but allow a consent to be registered in any case
    155154    enableConsentOption('consent.no', true);
    156155    enableConsentOption('consent.notAsked');
    157     Main.showInline('morehelp.no');
     156    enableConsentOption('consent.yes');
     157    Main.showInline('morehelp.any');
    158158    Main.show('gocancel');
    159159    Main.show('goregister');
     
    377377        <td class="help" rowspan="2">
    378378          <span id="consent.message" class="message" style="display: none;"></span>
    379           <span id="morehelp.yes" style="display: none;">
     379          <span id="morehelp.yesonly" style="display: none;">
    380380            <b>Yes</b> is the only option supported by this wizard. The other alternatives
    381381            may require manual deletion of already registered information.
    382382          </span>
    383           <span id="morehelp.specimen" style="display: none;">
    384             The <b>Personal information registration</b> wizard must be completed before a
    385             <b>Yes</b> can be registered. The other alternatives may require manual
    386             deletion of already registered information.
    387           </span>
    388           <span id="morehelp.no" style="display: none;">
    389             The <b>Personal information registration</b> wizard must be completed for
    390             this case before a <b>Yes</b> can be registered.
     383          <span id="morehelp.any" style="display: none;">
     384            There is currently no information about this case.
    391385          </span>
    392386        </td>
  • extensions/net.sf.basedb.reggie/trunk/resources/persinfo.jsp

    r1367 r1513  
    473473  currentStep = 3;
    474474 
    475   var updateMode = caseInfo.id;
     475  var updateMode = caseInfo.id && caseInfo.patient;
    476476 
    477477  // Generate list of specimen tubes
     
    614614      if (!updateMode || cc.id == caseInfo.id)
    615615      {
    616         cases += '<input type="radio" name="laterality" value="' + cc.id + '"';
     616        cases += '<input type="radio" name="laterality" value="' + cc.id + '" id="laterality'+cc.id+'"';
    617617        if (cc.laterality == thisCaseLaterality) cases += ' checked';
    618         cases += ' onclick="lateralityOnChange()">';
     618        cases += ' onclick="lateralityOnChange()"><label for="laterality' + cc.id + '">';
    619619        if (cc.laterality)
    620620        {
     
    629629          cases += ' [merge with ' + cc.name + ']';
    630630        }
    631         cases += '<br>';
     631        cases += '</label><br>';
    632632      }
    633633    }
     
    637637      if (!hasLeftCase)
    638638      {
    639         cases += '<input type="radio" name="laterality" value="LEFT" ';
     639        cases += '<input type="radio" name="laterality" value="LEFT" id="lateralityLeft"';
    640640        if (thisCaseLaterality == 'LEFT') cases += ' checked';
    641         cases += ' onclick="lateralityOnChange()">LEFT';
    642         if (!updateMode) cases += ' [<i>new case</i>]';
     641        cases += ' onclick="lateralityOnChange()"><label for="lateralityLeft">LEFT';
     642        if (!updateMode) cases += ' [<i>new case</i>]</label>';
    643643        cases += '<br>';
    644644      }
    645645      if (!hasRightCase)
    646646      {
    647         cases += '<input type="radio" name="laterality" value="RIGHT"';
     647        cases += '<input type="radio" name="laterality" value="RIGHT" id="lateralityRight"';
    648648        if (thisCaseLaterality == 'RIGHT') cases += ' checked';
    649         cases += ' onclick="lateralityOnChange()">RIGHT';
    650         if (!updateMode) cases += ' [<i>new case</i>]';
     649        cases += ' onclick="lateralityOnChange()"><label for="lateralityRight">RIGHT';
     650        if (!updateMode) cases += ' [<i>new case</i>]</label>';
    651651        cases += '<br>';
    652652      }
    653653      if (!updateMode && !hasLeftCase && !hasRightCase)
    654654      {
    655         cases += '<input type="radio" name="laterality" value=""';
     655        cases += '<input type="radio" name="laterality" value="" id="lateralityUnknown"';
    656656        if (thisCaseLaterality == null) cases += ' checked';
    657         cases += ' onclick="lateralityOnChange()"><i>unknown laterality</i> [<i>new case</i>]<br>';
     657        cases += ' onclick="lateralityOnChange()"><label for="lateralityUnknown"><i>unknown laterality</i> [<i>new case</i>]</label><br>';
    658658      }
    659659    }
     
    723723  frm.rnaLaterTime.disabled = true;
    724724
    725   var updateMode = caseInfo.id;
     725  var updateMode = caseInfo.id && caseInfo.patient;
    726726  var submitInfo = new Object();
    727727  submitInfo.patientInfo = patientInfo;
     
    921921        <td class="prompt" id="laterality.prompt">Laterality</td>
    922922        <td class="input" id="laterality.input">
    923           <input type="radio" name="laterality" value="LEFT" onclick="lateralityOnChange()">LEFT<br>
    924           <input type="radio" name="laterality" value="RIGHT" onclick="lateralityOnChange()">RIGHT<br>
    925           <input type="radio" name="laterality" value="" checked onclick="lateralityOnChange()"><i>unknown</i>
     923          <input type="radio" name="laterality" value="LEFT" id="lateralityLeft" onclick="lateralityOnChange()"><label for="lateralityLeft">LEFT</label><br>
     924          <input type="radio" name="laterality" value="RIGHT" id="lateralityRight" onclick="lateralityOnChange()"><label for="lateralityRight">RIGHT</label><br>
     925          <input type="radio" name="laterality" value="" checked id="lateralityUnknown" onclick="lateralityOnChange()"><i><label for="lateralityUnknown">unknown</label></i>
    926926        </td>
    927927        <td class="status" id="laterality.status"></td>
  • extensions/net.sf.basedb.reggie/trunk/resources/specimentube.jsp

    r1499 r1513  
    948948      <td class="prompt" id="laterality.prompt">Laterality</td>
    949949      <td class="input" id="laterality.input">
    950         <input type="radio" name="laterality" value="LEFT" onclick="lateralityOnChange()">LEFT<br>
    951         <input type="radio" name="laterality" value="RIGHT" onclick="lateralityOnChange()">RIGHT<br>
    952         <input type="radio" name="laterality" value="" checked onclick="lateralityOnChange()"><i>unknown</i>
     950        <input type="radio" name="laterality" value="LEFT" id="lateralityLeft" onclick="lateralityOnChange()"><label for="lateralityLeft">LEFT</label><br>
     951        <input type="radio" name="laterality" value="RIGHT" id="lateralityRight" onclick="lateralityOnChange()"><label for="lateralityRight">RIGHT</label><br>
     952        <input type="radio" name="laterality" value="" id="lateralityUnknown" checked onclick="lateralityOnChange()"><i><label for="lateralityUnknown">unknown</label></i>
    953953      </td>
    954954      <td class="status" id="laterality.status"></td>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/Reggie.java

    r1512 r1513  
    387387  }
    388388
     389  /**
     390    Copy annotation values between two items.
     391   
     392    @param from The item to copy from. If this item is not annotated with
     393      the given annotation type, nothing is copied
     394    @param to The item to copy to. If this item already has been annotated with
     395      the given annotation type, the 'force' paremter decides if the annotation is
     396      overwritten or not
     397    @param at The annotation type to copy
     398    @param force TRUE to overwrite existing annotations, FALSE to not
     399    @return TRUE if this method copied annotations, FALSE if not
     400    @since 2.2
     401  */
     402  public static boolean copyAnnotationValues(Annotatable from, Annotatable to, AnnotationType at, boolean force)
     403  {
     404    List<?> annotations = getAnnotationValues(from, at);
     405    if (annotations == null || annotations.size() == 0) return false;
     406   
     407    if (!force)
     408    {
     409      // We need to check if the 'to' item already has the annotation
     410      if (to.isAnnotated() && to.getAnnotationSet().hasAnnotation(at)) return false;
     411    }
     412   
     413    // Copy the values
     414    to.getAnnotationSet().getAnnotation(at).setValues(annotations);
     415    return true;
     416  }
    389417 
    390418}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/PersonalRegistrationServlet.java

    r1504 r1513  
    2020import net.sf.basedb.core.BioSource;
    2121import net.sf.basedb.core.DbControl;
    22 import net.sf.basedb.core.InvalidDataException;
    2322import net.sf.basedb.core.Item;
    2423import net.sf.basedb.core.Sample;
     
    8281        if (theCase != null)
    8382        {
     83          // Check that the registration is not prohibited
    8484          theCase.verifyConsent(dc, null);
    85          
    86           // Load the patient associated with the case
    87           Patient patient = Patient.findByCase(dc, theCase);
    88           if (patient == null)
    89           {
    90             throw new InvalidDataException("The case (" + caseName + ") was found but it is not associated " +
    91                 "with any patient. This wizard can't be used until that is corrected.");
    92           }
    9385         
    9486          // Load specimen tubes for the case
    9587          specimenTubes = SpecimenTube.findByCase(dc, theCase, true);
     88          if (specimenTubes.size() == 0)
     89          {
     90            // No specimen tubes are linked with the case -- see if we can find some unlinked
     91            specimenTubes = SpecimenTube.findByCaseName(dc, caseName);
     92          }
    9693
    9794          // Continue to load some more info (annotations, etc...)
     
    10097          theCase.loadAnnotations(dc, "pad", Reggie.ANNOTATION_PAD_CASE, null);
    10198          theCase.loadAnnotations(dc, "reasonIfNoSpecimen", Reggie.ANNOTATION_REASON_IF_NO_SPECIMEN, null);
    102          
    103           // ... patient annotations
    104           patient.loadDefaultAnnotations(dc);
    105          
     99
    106100          // Wrap what we have so far up into JSON objects
    107101          jsonCase = theCase.asJSONObject();
    108           jsonCase.put("patient", patient.asJSONObject());
     102
     103          // Load the patient associated with the case
     104          Patient patient = Patient.findByCase(dc, theCase);
     105          // The patient can be null if (for example) we have only registered consent=yes so far
     106          if (patient != null)
     107          {
     108            patient.loadDefaultAnnotations(dc);
     109            jsonCase.put("patient", patient.asJSONObject());
     110          }
    109111        }
    110112        else
     
    245247       
    246248        dc = sc.newDbControl();
    247         Number patientId = (Number)jsonPat.get("id");
    248         BioSource patient = null;
    249        
    250         if (patientId != null)
    251         {
    252           patient = BioSource.getById(dc, patientId.intValue());
    253         }
    254         else
    255         {
    256           // Create new patient
    257           patient = BioSource.getNew(dc);
    258           patient.setItemSubtype(Subtype.PATIENT.load(dc));
    259           patient.setName((String)jsonPat.get("name"));
    260           String pnr = (String)jsonPat.get("personalNumber");
    261           String dateOfBirth = (String)jsonPat.get("dateOfBirth");
    262           String gender = (String)jsonPat.get("gender");
    263          
    264           AnnotationType personalNumberType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_PERSONAL_NUMBER, true);
    265           AnnotationType familyNameType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_FAMILY_NAME, true);
    266           AnnotationType allFirstNamesType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_ALL_FIRST_NAMES, true);
    267           AnnotationType genderType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_GENDER, true);
    268           AnnotationType dateOfBirthType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_DATE_OF_BIRTH, true);
    269          
    270           AnnotationSet as = patient.getAnnotationSet();
    271           as.getAnnotation(personalNumberType).setValue(pnr);
    272           as.getAnnotation(familyNameType).setValue((String)jsonPat.get("familyName"));
    273           as.getAnnotation(allFirstNamesType).setValue((String)jsonPat.get("allFirstNames"));
    274           if (gender != null) as.getAnnotation(genderType).setValue(gender);
    275           if (dateOfBirth != null)
    276           {
    277             SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    278             df.setLenient(false);
    279             as.getAnnotation(dateOfBirthType).setValue(df.parse(dateOfBirth));
    280           }
    281           if (gender == null || dateOfBirth == null)
    282           {
    283             patient.setDescription("This patient was recorded with a non-standard PersonalNumber. " +
    284                 "DateOfBirth and Gender annotations could not be automatically generated.");
    285           }
    286           dc.saveItem(patient);
    287          
    288           jsonMessages.add("Patient '" + patient.getName() + "' created successfully.");
    289         }
     249        BioSource patient = getOrCreatePatient(dc, jsonPat, jsonMessages);
     250       
     251        // If we already have a case with id it is probably due to an already registered consent=yes
     252        Number preCaseId = (Number)jsonCase.get("id");
    290253       
    291254        // Get laterality
     
    304267          // Load the real laterality from the case
    305268          laterality = (String)Reggie.getAnnotationValue(theCase, lateralityType);
     269         
     270          if (preCaseId != null)
     271          {
     272            // Remove the pre-registered case but copy consent information first
     273            AnnotationType consentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_CONSENT, true);
     274            AnnotationType consentDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_CONSENT_DATE, true);
     275           
     276            Sample preCase = Sample.getById(dc, preCaseId.intValue());
     277            Reggie.copyAnnotationValues(preCase, theCase, consentType, false);
     278            Reggie.copyAnnotationValues(preCase, theCase, consentDateType, false);
     279            dc.deleteItem(preCase);
     280          }
     281         
    306282          jsonMessages.add("Case '" + originalCaseName + "' merged with case '" + theCase.getName() + "' successfully.");
    307283        }
    308284        else
    309285        {
    310           // Register a new case
    311           theCase = Sample.getNew(dc);
     286          if (preCaseId != null)
     287          {
     288            // Load existing case
     289            theCase = Sample.getById(dc, preCaseId.intValue());
     290          }
     291          else
     292          {
     293            // Register a new case
     294            theCase = Sample.getNew(dc);
     295            dc.saveItem(theCase);
     296          }
    312297          theCase.setItemSubtype(Subtype.CASE.load(dc));
    313298          theCase.setName(originalCaseName);
     
    317302          }
    318303          theCase.getCreationEvent().setSource(patient);
    319           dc.saveItem(theCase);
    320304          jsonMessages.add("Case '" + originalCaseName + "' created successfully.");
    321305        }
     
    368352        JSONObject jsonReq = (JSONObject)new JSONParser().parse(req.getReader());
    369353        JSONObject jsonCase = (JSONObject)jsonReq.get("caseInfo");
    370        
    371354        dc = sc.newDbControl();
     355       
    372356        Number caseId = (Number)jsonCase.get("id");
    373357        Sample theCase = Sample.getById(dc, caseId.intValue());
     
    461445  }
    462446 
     447  @SuppressWarnings("unchecked")
     448  private BioSource getOrCreatePatient(DbControl dc, JSONObject jsonPat, JSONArray jsonMessages)
     449    throws Exception
     450  {
     451    Number patientId = (Number)jsonPat.get("id");
     452    BioSource patient = null;
     453   
     454    if (patientId != null)
     455    {
     456      patient = BioSource.getById(dc, patientId.intValue());
     457    }
     458    else
     459    {
     460      // Create new patient
     461      patient = BioSource.getNew(dc);
     462      patient.setItemSubtype(Subtype.PATIENT.load(dc));
     463      patient.setName((String)jsonPat.get("name"));
     464      String pnr = (String)jsonPat.get("personalNumber");
     465      String dateOfBirth = (String)jsonPat.get("dateOfBirth");
     466      String gender = (String)jsonPat.get("gender");
     467     
     468      AnnotationType personalNumberType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_PERSONAL_NUMBER, true);
     469      AnnotationType familyNameType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_FAMILY_NAME, true);
     470      AnnotationType allFirstNamesType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_ALL_FIRST_NAMES, true);
     471      AnnotationType genderType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_GENDER, true);
     472      AnnotationType dateOfBirthType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_DATE_OF_BIRTH, true);
     473     
     474      AnnotationSet as = patient.getAnnotationSet();
     475      as.getAnnotation(personalNumberType).setValue(pnr);
     476      as.getAnnotation(familyNameType).setValue((String)jsonPat.get("familyName"));
     477      as.getAnnotation(allFirstNamesType).setValue((String)jsonPat.get("allFirstNames"));
     478      if (gender != null) as.getAnnotation(genderType).setValue(gender);
     479      if (dateOfBirth != null)
     480      {
     481        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
     482        df.setLenient(false);
     483        as.getAnnotation(dateOfBirthType).setValue(df.parse(dateOfBirth));
     484      }
     485      if (gender == null || dateOfBirth == null)
     486      {
     487        patient.setDescription("This patient was recorded with a non-standard PersonalNumber. " +
     488            "DateOfBirth and Gender annotations could not be automatically generated.");
     489      }
     490      dc.saveItem(patient);
     491     
     492      jsonMessages.add("Patient '" + patient.getName() + "' created successfully.");
     493    }
     494    return patient;
     495
     496  }
    463497 
    464498 
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SpecimenTubeServlet.java

    r1463 r1513  
    6969       
    7070        String caseName = req.getParameter("caseName");
    71         Case theCase = Case.findByName(dc, caseName);       
     71        Case theCase = Case.findByName(dc, caseName);
     72
    7273        if (theCase != null)
    7374        {
    74           throw new InvalidDataException("The case (" + caseName + ") already exists in BASE. " +
    75               "This wizard cannot be used to update tubes that already been connected to a case.");
     75          // Verify that consent has been given
     76          theCase.verifyConsent(dc, null);
    7677        }
    7778       
     
    7980        if (specimenTubes.size() > 0)
    8081        {
    81           throw new InvalidDataException("There are already specimen tubes in this case.");
    82         }
    83        
    84         JSONObject jsonCase = null;
    85         if (theCase == null)
    86         {         
    87           jsonCase = new JSONObject();
    88           jsonCase.put("name", caseName);
    89         }             
     82          throw new InvalidDataException(specimenTubes.size() +
     83            " specimen tubes have already been registered for this case. This wizard can't be used for updating.");
     84        }
     85       
     86        JSONObject jsonCase = new JSONObject();
     87        jsonCase.put("name", caseName);
    9088        json.put("caseInfo", jsonCase);
    9189      }
Note: See TracChangeset for help on using the changeset viewer.