Changeset 1307


Ignore:
Timestamp:
Mar 4, 2011, 11:33:52 AM (11 years ago)
Author:
Nicklas Nordborg
Message:

References #291: Personal information registration

Allow laterality=unknown option since that is not always known at the time of registration. On the other hand, if a laterality has been selected but the associated specimen tubes doesn't have that information the specimen tubes will be updated with the selected laterality.

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

Legend:

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

    r1306 r1307  
    179179 
    180180  var laterality = selectedLaterality.value;
    181   if (laterality != 'LEFT' && laterality != 'RIGHT')
     181  if (laterality.match(/\d+/))
    182182  {
    183183    // It is the ID of an existing case
     
    192192    }
    193193  }
    194  
    195   if (!laterality) return;
    196  
    197   // No specimen tubes
     194  else  if (laterality == '')
     195  {
     196    laterality = null;
     197  }
     198   
     199  // No specimen tubes?
    198200  if (!caseInfo.specimen || caseInfo.specimen.length == 0) return;
     201 
    199202  for (var i = 0; i < caseInfo.specimen.length; i++)
    200203  {
    201204    var specimen = caseInfo.specimen[i];
    202     if (specimen.laterality && specimen.laterality != laterality)
    203     {
    204       setInputStatus('laterality', 'Not same laterality as specimen tubes', 'warning');
     205    if (specimen.laterality != laterality)
     206    {
     207      if (specimen.laterality == null)
     208      {
     209        setInputStatus('laterality', 'Specimen tubes are updated to: ' + laterality, 'valid')
     210      }
     211      else
     212      {
     213        setInputStatus('laterality', 'Not same laterality as specimen tubes', 'warning');
     214      }
    205215      return;
    206216    }
     
    294304 
    295305  // Generate list of specimen tubes
    296   var thisCaseLaterality;
     306  var hasLeftSpecimen = false;
     307  var hasRightSpecimen = false;
     308  var hasUnknownSpecimen = false;
     309  var thisCaseLaterality = null;
    297310  if (caseInfo.specimen && caseInfo.specimen.length > 0)
    298311  {
     
    302315    {
    303316      var specimen = caseInfo.specimen[i];
    304       specimenTubes += specimen.name ;
     317      specimenTubes += specimen.name;
    305318      if (specimen.laterality)
    306319      {
    307320        specimenTubes += ' ('+specimen.laterality + ')';
    308321        Forms.checkRadio(frm.laterality, specimen.laterality);
    309        
    310         if (thisCaseLaterality && thisCaseLaterality != specimen.laterality)
    311         {
    312           setInputStatus('specimenTubes', 'Specimen tubes with different laterality', 'warning');
    313         }
     322        if (specimen.laterality == 'LEFT') hasLeftSpecimen = true;
     323        if (specimen.laterality == 'RIGHT') hasRightSpecimen = true;
    314324        thisCaseLaterality = specimen.laterality;
    315325      }
    316326      else
    317327      {
     328        hasUnknownSpecimen = true;
    318329        specimenTubes += ' (<i>unknown laterality</i>)';
    319330      }
     
    321332    }
    322333    setInnerHTML('specimenTubes', specimenTubes);
    323   }
    324 
    325  
     334   
     335    // Check that all specimen tubes have the same laterality
     336    var numLateralities = 0;
     337    if (hasLeftSpecimen) numLateralities++;
     338    if (hasRightSpecimen) numLateralities++;
     339    if (hasUnknownSpecimen) numLateralities++;
     340    if (numLateralities > 1)
     341    {
     342      setInputStatus('specimenTubes', 'Specimen tubes with different laterality', 'warning');
     343      thisCaseLaterality = null;
     344    }
     345  }
     346
    326347  Main.show('caseSection');
    327348 
     
    329350  var hasLeftCase = false;
    330351  var hasRightCase = false;
     352  var hasUnknownCase = false;
    331353  if (patientInfo.cases && patientInfo.cases.length > 0)
    332354  {
     
    338360      if (cc.laterality == 'LEFT')
    339361      {
    340         if (hasLeftCase) setInputStatus('laterality', 'Two cases with LEFT', 'warning');
     362        if (hasLeftCase) setInputStatus('laterality', 'Two cases with laterality=LEFT', 'warning');
    341363        hasLeftCase = true;
    342364      }
    343       if (cc.laterality == 'RIGHT')
    344       {
    345         if (hasRightCase) setInputStatus('laterality', 'Two cases with RIGHT', 'warning');
     365      else if (cc.laterality == 'RIGHT')
     366      {
     367        if (hasRightCase) setInputStatus('laterality', 'Two cases with laterality=RIGHT', 'warning');
    346368        hasRightCase = true;
     369      }
     370      else
     371      {
     372        hasUnknownCase = true; 
    347373      }
    348374      if (cc.laterality == thisCaseLaterality) cases += ' checked';
     
    372398        cases += ' onclick="lateralityOnChange()"><i>new case</i> (RIGHT)<br>';
    373399      }
     400      cases += '<input type="radio" name="laterality" value=""';
     401      if (thisCaseLaterality == null) cases += ' checked';
     402      cases += ' onclick="lateralityOnChange()"><i>new case</i> (<i>unknown laterality</i>)<br>';
    374403    }
    375404   
     
    727756        <td class="prompt" id="laterality.prompt">Laterality</td>
    728757        <td class="input" id="laterality.input">
    729           <input type="radio" name="laterality" value="LEFT" onclick="lateralityOnChange()">LEFT
    730           <input type="radio" name="laterality" value="RIGHT" onclick="lateralityOnChange()">RIGHT
     758          <input type="radio" name="laterality" value="LEFT" onclick="lateralityOnChange()">LEFT<br>
     759          <input type="radio" name="laterality" value="RIGHT" onclick="lateralityOnChange()">RIGHT<br>
     760          <input type="radio" name="laterality" value="" checked onclick="lateralityOnChange()"><i>unknown</i>
    731761        </td>
    732762        <td class="status" id="laterality.status"></td>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/Reggie.java

    r1302 r1307  
    178178    return as.getAnnotation(at).getValues().get(0);
    179179  }
     180
     181  /**
     182    Set a (single) annotation value on an item.
     183  */
     184  public static void setAnnotationValue(Annotatable item, AnnotationType at, Object value)
     185  {
     186    item.getAnnotationSet().getAnnotation(at).setValue(value);
     187  }
     188
    180189 
    181190}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/PersonalRegistrationServlet.java

    r1290 r1307  
    252252        }
    253253       
    254         String laterality = (String)jsonCase.get("laterality");
    255        
     254        // Get laterality
     255        String laterality = Values.getStringOrNull((String)jsonCase.get("laterality"));
     256        AnnotationType lateralityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true);
     257       
     258        // Load/create case
    256259        String originalCaseName = (String)jsonCase.get("name");
     260        // If merging with an existing case the 'laterality' value holds the id
     261        int caseId = Values.getInt(laterality);
    257262        Sample theCase = null;
    258         if ("LEFT".equals(laterality) || "RIGHT".equals(laterality))
     263        if (caseId > 0)
     264        {
     265          // Merge with existing case
     266          theCase = Sample.getById(dc, caseId);
     267          laterality = (String)Reggie.getAnnotationValue(theCase, lateralityType);
     268          jsonMessages.add("Case '" + originalCaseName + "' merged with case '" + theCase.getName() + "' successfully.");
     269        }
     270        else
    259271        {
    260272          // Register a new case
    261273          theCase = Sample.getNew(dc);
    262274          theCase.setName(originalCaseName);
    263           AnnotationType lateralityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true);
    264           AnnotationSet as = theCase.getAnnotationSet();
    265           as.getAnnotation(lateralityType).setValue((String)jsonCase.get("laterality"));
     275          if (laterality != null)
     276          {
     277            Reggie.setAnnotationValue(theCase, lateralityType, laterality);
     278          }
    266279          theCase.setBioSource(patient);
    267280          dc.saveItem(theCase);
    268281          jsonMessages.add("Case '" + originalCaseName + "' created successfully.");
    269         }
    270         else
    271         {
    272           // Merge with existing case
    273           theCase = Sample.getById(dc, Values.getInt(laterality));
    274           jsonMessages.add("Case '" + originalCaseName + "' merged with case '" + theCase.getName() + "' successfully.");
    275282        }
    276283       
     
    282289          AnnotationType padType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD, true);
    283290          AnnotationType padCaseType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD_CASE, true);
    284           List padCase = new ArrayList(caseAnnotations.getAnnotation(padCaseType).getValues());
     291          List padCase = new ArrayList();
     292          if (caseAnnotations.hasAnnotation(padCaseType))
     293          {
     294            padCase.addAll(caseAnnotations.getAnnotation(padCaseType).getValues());
     295          }
    285296          for (int i = 0; i < jsonSpecimen.size(); ++i)
    286297          {
     
    293304            String pad = (String)Reggie.getAnnotationValue(specimen, padType);
    294305            if (pad != null && !padCase.contains(pad)) padCase.add(pad);
     306            // Set laterality on the specimen tube if it is missing
     307            if (laterality != null)
     308            {
     309              String specimenLaterality = (String)Reggie.getAnnotationValue(specimen, lateralityType);
     310              if (specimenLaterality == null)
     311              {
     312                Reggie.setAnnotationValue(specimen, lateralityType, laterality);
     313                jsonMessages.add("Updated laterality on '" + specimen.getName() + "' to " + laterality + ".");
     314              }
     315            }
     316           
    295317          }
    296318          if (padCase.size() > 0) caseAnnotations.getAnnotation(padCaseType).setValues(padCase);
    297           jsonMessages.add(jsonSpecimen.size() + " specimen tubes linked with case '" + theCase.getName() + "' successfully.");
     319          jsonMessages.add(jsonSpecimen.size() + " specimen tube(s) linked with case '" + theCase.getName() + "' successfully.");
    298320        }
    299321        else
Note: See TracChangeset for help on using the changeset viewer.