Changeset 1326


Ignore:
Timestamp:
Mar 29, 2011, 2:55:33 PM (11 years ago)
Author:
Nicklas Nordborg
Message:

References #302: Update functionality in the Personal information registration

Restructured the code which should make it easier to keep track of related reggie items (patient/case/specimen tube). It is also easier to make sure that JSON representations are consistent if more functions are needed in the future.

The wizard now recognises 3 variants of existing cases:

  1. Match by exact name
  2. Match by name of specimen tubes that have been merged with a different case
  3. Match by [prefix] of ResonIfNoSpecimen? comment for a merged case without specimen tubes.

If an existing case is found, the wizard loads patient information, etc. and proceeds immediately to step 3 in "Update mode". Currently, only the laterality value can be updated. PAD, the various timestamps, comments, etc. are not yet supported.

Hopefully this has been done without breaking any of the functions for registering a new case...

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

Legend:

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

    r1319 r1326  
    139139  setInputStatus('case', '', 'valid');
    140140  caseIsValid = true;
     141 
     142  getCaseInfo();
    141143}
    142144
     
    208210{
    209211  lateralityIsValid = false;
     212  var updateMode = caseInfo.id;
    210213 
    211214  // Check selected laterality against specimen tubes
     
    219222    return;
    220223  }
    221   setInputStatus('laterality', '', 'valid');
     224 
     225  var numCases = patientInfo.cases ? patientInfo.cases.length : 0;
     226  setInputStatus('laterality', updateMode && numCases > 1 ? 'NOTE! Some alternatives may be missing if there is another case for the patient.' : '', 'valid');
    222227  lateralityIsValid = true;
    223228 
     
    249254    if (specimen.laterality != laterality)
    250255    {
    251       if (specimen.laterality == null)
     256      if (specimen.laterality == null || updateMode)
    252257      {
    253258        setInputStatus('laterality', 'Specimen tubes are updated to: ' + laterality, 'valid')
     
    260265    }
    261266  }
     267 
    262268}
    263269
     
    292298  if (event.keyCode == 13) setTimeout("document.forms['reggie']."+inputField+".focus()", 200);
    293299  return true;
     300}
     301
     302function getCaseInfo()
     303{
     304  // Check entered case and pnr with AJAX
     305  var frm = document.forms['reggie'];
     306  var caseName = frm.caseName.value;
     307  var request = Ajax.getXmlHttpRequest();
     308  var url = 'PersonalRegistration.servlet?ID=<%=ID%>&cmd=GetCaseInfo';
     309  url += '&caseName=' + caseName;
     310  request.open("GET", url, false);
     311  request.send(null);
     312 
     313  setInnerHTML('debug', request.responseText);
     314  var response = JSON.parse(request.responseText);
     315  if (response.status != 'ok')
     316  {
     317    setFatalError(response.message);
     318    return false;
     319  }
     320 
     321  // Get biosource information from the AJAX response
     322  caseInfo = response.caseInfo;
     323 
     324  if (caseInfo && caseInfo.patient)
     325  {
     326    frm.personalNumber.value = caseInfo.patient.personalNumber;
     327    gotoStep2();
     328  }
     329 
    294330}
    295331
     
    303339 
    304340  var pnr = frm.personalNumber.value;
    305   var caseName = frm.caseName.value;
    306341  var request = Ajax.getXmlHttpRequest();
    307   var url = 'PersonalRegistration.servlet?ID=<%=ID%>&cmd=CheckPersonalNumberAndCaseName';
     342  var url = 'PersonalRegistration.servlet?ID=<%=ID%>&cmd=GetPatientInfo';
    308343  url += '&personalNumber=' + pnr;
    309344  url += '&pnrIsValid=' + pnrIsValid;
    310   url += '&caseName=' + caseName;
    311345  request.open("GET", url, false);
    312346  request.send(null);
    313347 
    314   //setInnerHTML('debug', request.responseText);
     348  setInnerHTML('debug', request.responseText);
    315349 
    316350  var response = JSON.parse(request.responseText);
     
    321355  }
    322356 
     357  // Get patient information from the AJAX response
     358  patientInfo = response.patientInfo;
     359
    323360  Main.show('gocancel');
    324  
    325   // Get biosource information from the AJAX response
    326   patientInfo = response.patientInfo;
    327   caseInfo = response.caseInfo;
    328361 
    329362  if (!patientInfo.id)
     
    366399  currentStep = 3;
    367400 
     401  var updateMode = caseInfo.id;
     402 
    368403  // Generate list of specimen tubes
    369404  var hasLeftSpecimen = false;
    370405  var hasRightSpecimen = false;
    371406  var hasUnknownSpecimen = false;
    372   var thisCaseLaterality = null;
     407  var thisCaseLaterality = caseInfo.laterality;
     408  var thisCasePAD = null;
    373409  var hasPAD = false;
    374410  if (caseInfo.specimen && caseInfo.specimen.length > 0)
     
    380416      var specimen = caseInfo.specimen[i];
    381417      specimenTubes += specimen.name;
    382       if (specimen.pad) hasPAD = true;
     418      if (specimen.pad)
     419      {
     420        hasPAD = true;
     421        thisCasePAD = specimen.pad;
     422      }
    383423      if (specimen.laterality)
    384424      {
     
    410450  }
    411451
    412   Main.showHide('padSection', !hasPAD);
     452  frm.pad.value = thisCasePAD;
     453  Main.showHide('padSection', !hasPAD || updateMode);
    413454 
    414455  Main.show('caseSection');
     
    424465    {
    425466      var cc = patientInfo.cases[i];
    426       cases += '<input type="radio" name="laterality" value="' + cc.id + '"';
    427467      if (cc.laterality == 'LEFT')
    428468      {
    429         if (hasLeftCase) setInputStatus('laterality', 'Two cases with laterality=LEFT', 'warning');
     469        if (hasLeftCase && !updateMode) setInputStatus('laterality', 'Two cases with laterality=LEFT', 'warning');
    430470        hasLeftCase = true;
    431471      }
    432472      else if (cc.laterality == 'RIGHT')
    433473      {
    434         if (hasRightCase) setInputStatus('laterality', 'Two cases with laterality=RIGHT', 'warning');
     474        if (hasRightCase && !updateMode) setInputStatus('laterality', 'Two cases with laterality=RIGHT', 'warning');
    435475        hasRightCase = true;
    436476      }
     
    439479        hasUnknownCase = true; 
    440480      }
    441       if (cc.laterality == thisCaseLaterality) cases += ' checked';
    442       cases += ' onclick="lateralityOnChange()">' + cc.name;
    443       if (cc.laterality)
    444       {
    445         cases += ' (' + cc.laterality + ')<br>';
    446       }
    447       else
    448       {
    449         cases += ' (<i>unknown laterality</i>)<br>';
     481      if (!updateMode || cc.id == caseInfo.id)
     482      {
     483        cases += '<input type="radio" name="laterality" value="' + cc.id + '"';
     484        if (cc.laterality == thisCaseLaterality) cases += ' checked';
     485        cases += ' onclick="lateralityOnChange()">';
     486        if (cc.laterality)
     487        {
     488          cases += cc.laterality;
     489        }
     490        else
     491        {
     492          cases += '<i>unknown laterality</i>';
     493        }
     494        if (!updateMode)
     495        {
     496          cases += ' [merge with ' + cc.name + ']';
     497        }
     498        cases += '<br>';
    450499      }
    451500    }
    452501   
    453     if (patientInfo.cases.length == 1)
     502    if (patientInfo.cases.length == 1 || updateMode)
    454503    {
    455504      if (!hasLeftCase)
     
    457506        cases += '<input type="radio" name="laterality" value="LEFT" ';
    458507        if (thisCaseLaterality == 'LEFT') cases += ' checked';
    459         cases += ' onclick="lateralityOnChange()"><i>new case</i> (LEFT)<br>';
     508        cases += ' onclick="lateralityOnChange()">LEFT';
     509        if (!updateMode) cases += ' [<i>new case</i>]';
     510        cases += '<br>';
    460511      }
    461512      if (!hasRightCase)
     
    463514        cases += '<input type="radio" name="laterality" value="RIGHT"';
    464515        if (thisCaseLaterality == 'RIGHT') cases += ' checked';
    465         cases += ' onclick="lateralityOnChange()"><i>new case</i> (RIGHT)<br>';
    466       }
    467       cases += '<input type="radio" name="laterality" value=""';
    468       if (thisCaseLaterality == null) cases += ' checked';
    469       cases += ' onclick="lateralityOnChange()"><i>new case</i> (<i>unknown laterality</i>)<br>';
     516        cases += ' onclick="lateralityOnChange()">RIGHT';
     517        if (!updateMode) cases += ' [<i>new case</i>]';
     518        cases += '<br>';
     519      }
     520      if (!updateMode && !hasLeftCase && !hasRightCase)
     521      {
     522        cases += '<input type="radio" name="laterality" value=""';
     523        if (thisCaseLaterality == null) cases += ' checked';
     524        cases += ' onclick="lateralityOnChange()"><i>unknown laterality</i> [<i>new case</i>]<br>';
     525      }
    470526    }
    471527   
    472     if (patientInfo.cases.length == 2)
    473     {
    474       setInnerHTML('laterality.prompt', 'Merge with case');
    475     }
    476     else
    477     {
    478       setInnerHTML('laterality.prompt', 'Merge/create new case');
     528    if (updateMode)
     529    {
     530      if (caseInfo.merged)
     531      {
     532        setInnerHTML('step3.title', 'Update case \''+caseInfo.originalName+'\' (which is merged with case \'' + caseInfo.name + '\')');
     533      }
     534      else
     535      {
     536        setInnerHTML('step3.title', 'Update case \''+caseInfo.name+'\'');
     537      }
     538     
     539    }
     540    else if (patientInfo.cases.length == 2)
     541    {
     542      setInnerHTML('step3.title', 'Merge with existing case'); 
     543    }
     544    else if (patientInfo.cases.length > 0)
     545    {
     546      setInnerHTML('step3.title', 'Create new case or merge with existing case');
    479547    }
    480548   
     
    484552
    485553  Main.hide('gonext');
    486   Main.show('gocreate');
     554  if (updateMode)
     555  {
     556    Main.show('goupdate');
     557  }
     558  else
     559  {
     560    Main.show('gocreate');
     561  }
    487562 
    488563  if (!hasPAD && lateralityIsValid) frm.pad.focus();
     
    495570  Main.hide('gocreate');
    496571  Main.hide('gocancel');
     572  Main.hide('goupdate');
    497573  var frm = document.forms['reggie'];
    498574
     
    508584  frm.pad.disabled = true;
    509585
     586  var updateMode = caseInfo.id;
    510587  var submitInfo = new Object();
    511588  submitInfo.patientInfo = patientInfo;
     
    515592 
    516593  var request = Ajax.getXmlHttpRequest();
    517   var url = 'PersonalRegistration.servlet?ID=<%=ID%>&cmd=Create';
     594  var url = 'PersonalRegistration.servlet?ID=<%=ID%>&cmd=';
     595  url += updateMode ? 'UpdateCase' : 'CreateCase';
    518596  request.open("POST", url, false);
    519597  request.setRequestHeader("Content-Type", "application/json");
    520598  request.send(JSON.stringify(submitInfo));
    521599
    522   //setInnerHTML('debug', request.responseText);
     600  setInnerHTML('debug', request.responseText);
    523601 
    524602  var response = JSON.parse(request.responseText);
     
    572650  Main.hide('gocancel');
    573651  Main.show('gorestart');
     652  var frm = document.forms['reggie'];
     653  for (var i = 0; i < frm.elements.length; i++)
     654  {
     655    frm.elements[i].disabled = true; 
     656  }
     657
    574658}
    575659
     
    831915  <tr>
    832916    <td rowspan="2" class="stepno">3</td>
    833     <td class="steptitle">About this case</td>
     917    <td class="steptitle" id="step3.title">Create new case</td>
    834918  </tr>
    835919  <tr>
     
    859943          onblur="padOnChange()"></td>
    860944        <td class="status" id="pad.status"></td>
    861         <td class="help"><span id="pad.message" class="message" style="display: none;"></span>PAD should be entered when no specimen tubes have been registered</td>
     945        <td class="help"><span id="pad.message" class="message" style="display: none;"></span>PAD should be entered when no specimen tubes have been registered.</td>
    862946      </tr>
    863947      <tr id="reasonIfNoSpecimenSection" valign="top">
     
    882966    <td><base:button id="gonext" title="Next" image="gonext.gif" onclick="goNext(true)"/></td>
    883967    <td><base:button id="gocreate" title="Create" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td>
     968    <td><base:button id="goupdate" title="Update" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td>
    884969    <td><base:button id="gorestart" title="Restart" image="goback.gif" onclick="goRestart(true)" style="display: none;"/></td>
    885970    <td id="gonext.message" class="message"></td>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/Reggie.java

    r1325 r1326  
    11package net.sf.basedb.reggie;
    22
     3import java.util.Collections;
    34import java.util.List;
    45
     
    198199  }
    199200
    200  
     201  /**
     202    Get an array annotation value from an item. Returns an empty list if
     203    there are no annotations of the given type.
     204    @since 1.2
     205  */
     206  public static List<?> getAnnotationValues(Annotatable item, AnnotationType at)
     207  {
     208    if (!item.isAnnotated()) return Collections.emptyList();
     209    AnnotationSet as = item.getAnnotationSet();
     210    if (!as.hasAnnotation(at)) return Collections.emptyList();
     211    return as.getAnnotation(at).getValues();
     212  }
     213   
     214
     215
    201216}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/PersonalRegistrationServlet.java

    r1319 r1326  
    44import java.text.SimpleDateFormat;
    55import java.util.ArrayList;
    6 import java.util.Date;
    76import java.util.List;
    87
     
    2827import net.sf.basedb.core.Sample;
    2928import net.sf.basedb.core.SessionControl;
    30 import net.sf.basedb.core.Type;
    31 import net.sf.basedb.core.query.Annotations;
    3229import net.sf.basedb.core.query.Expressions;
    3330import net.sf.basedb.core.query.Hql;
     
    3532import net.sf.basedb.core.query.Restrictions;
    3633import net.sf.basedb.reggie.Reggie;
     34import net.sf.basedb.reggie.dao.Case;
     35import net.sf.basedb.reggie.dao.Patient;
     36import net.sf.basedb.reggie.dao.SpecimenTube;
    3737import net.sf.basedb.util.MD5;
    3838import net.sf.basedb.util.Values;
     
    6767    try
    6868    {
    69       if ("CheckPersonalNumberAndCaseName".equals(cmd))
     69      if ("GetCaseInfo".equals(cmd))
    7070      {
     71        /*
     72          Load information about a single case when given the case name/barcode
     73          If a case is found we will load annotations, the patient it is associated with
     74          and specimen tubes for the case. If no case is found we check to see
     75          if there are any specimen tubes that have the case name as prefix and
     76          load information about them.
     77        */
    7178        dc = sc.newDbControl();
    72         AnnotationType pnrType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_PERSONAL_NUMBER, true);
    73         AnnotationType lateralityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true);
    74         AnnotationType padType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD, true);
    75        
     79       
     80        // Find a case by name
     81        String caseName = req.getParameter("caseName");
     82        Case theCase = Case.findByName(dc, caseName);
     83        List<SpecimenTube> specimenTubes = null;
     84        JSONObject jsonCase = null;
     85       
     86        if (theCase != null)
     87        {
     88          // Load the patient associated with the case
     89          Patient patient = Patient.findByCase(dc, theCase);
     90          if (patient == null)
     91          {
     92            throw new InvalidDataException("The case (" + caseName + ") was found but it is not associated " +
     93                "with any patient. This wizard can't be used until that is corrected.");
     94          }
     95         
     96          // Load specimen tubes for the case
     97          specimenTubes = SpecimenTube.findByCase(dc, theCase, true);
     98
     99          // Continue to load some more info (annotations, etc...)
     100          // ... case annotations
     101          theCase.loadAnnotations(dc, "laterality", Reggie.ANNOTATION_LATERALITY);
     102          theCase.loadAnnotations(dc, "pad", Reggie.ANNOTATION_PAD_CASE);
     103          theCase.loadAnnotations(dc, "reasonIfNoSpecimen", Reggie.ANNOTATION_REASON_IF_NO_SPECIMEN);
     104         
     105          // ... patient annotations
     106          patient.loadDefaultAnnotations(dc);
     107         
     108          // Wrap what we have so far up into JSON objects
     109          jsonCase = theCase.asJSONObject();
     110          jsonCase.put("patient", patient.asJSONObject());
     111        }
     112        else
     113        {
     114          // Could not find the registered case -- see if we can find any specimen tubes
     115          specimenTubes = SpecimenTube.findByCaseName(dc, caseName);
     116          jsonCase = new JSONObject();
     117          jsonCase.put("name", caseName);
     118        }
     119
     120        // Load specimen tube annotations
     121        JSONArray jsonTubes = new JSONArray();
     122        if (specimenTubes.size() > 0)
     123        {
     124          AnnotationType padType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD, true);
     125          AnnotationType lateralityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true);
     126          for (SpecimenTube tube : specimenTubes)
     127          {
     128            tube.loadAnnotations("pad", padType);
     129            tube.loadAnnotations("laterality", lateralityType);
     130            jsonTubes.add(tube.asJSONObject());
     131          }
     132        }
     133        jsonCase.put("specimen", jsonTubes);
     134       
     135        // This is what we send back to the browser
     136        json.put("caseInfo", jsonCase);
     137
     138      }
     139     
     140      else if ("GetPatientInfo".equals(cmd))
     141      {
     142        /*
     143          Load information about a single patient when given a personal number
     144          If a patient is found we will load annotations and the cases associated
     145          with it. If no patient is found, we populate a new object with some
     146          information (eg. birth date and gender) from the information we have.
     147        */
     148        dc = sc.newDbControl();
     149       
     150        // Request parameters
    76151        String pnr = req.getParameter("personalNumber");
    77         String caseName = req.getParameter("caseName");
    78152        boolean pnrIsValid = Values.getBoolean(req.getParameter("pnrIsValid"));
    79        
    80         // Find patient information given the personal number
    81         ItemQuery<BioSource> patientQuery = BioSource.getQuery();
    82         patientQuery.restrict(Annotations.eq(null, pnrType, pnr, false));
    83         List<BioSource> patients = patientQuery.list(dc);
    84         JSONObject jsonPat = new JSONObject();
    85         jsonPat.put("personalNumber", pnr);
    86        
    87         if (patients.size() > 1)
    88         {
    89           throw new InvalidDataException(
    90             "More than one patient with the given personal number was found. " +
    91             "This wizard can't be used for registration until that is corrected.");
    92          
    93         }
    94        
    95         if (patients.size() == 1)
    96         {
    97           AnnotationType familyNameType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_FAMILY_NAME, true);
    98           AnnotationType allFirstNamesType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_ALL_FIRST_NAMES, true);
    99           AnnotationType genderType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_GENDER, true);
    100           AnnotationType dateOfBirthType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_DATE_OF_BIRTH, true);
    101           SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    102           BioSource bs = patients.get(0);
    103           jsonPat.put("id", bs.getId());
    104           jsonPat.put("name", bs.getName());
    105           jsonPat.put("familyName", Reggie.getAnnotationValue(bs, familyNameType));
    106           jsonPat.put("allFirstNames", Reggie.getAnnotationValue(bs, allFirstNamesType));
    107           jsonPat.put("gender", Reggie.getAnnotationValue(bs, genderType));
    108           jsonPat.put("dateOfBirth", df.format((Date)Reggie.getAnnotationValue(bs, dateOfBirthType)));
    109          
    110           // Find existing cases for the patient
    111           ItemQuery<Sample> caseQuery = bs.getSamples();
    112           caseQuery.include(Include.ALL);
     153
     154        // Find a patient by personalNumber
     155        Patient patient = Patient.findByPersonalNumber(dc, pnr);
     156        JSONObject jsonPat = null;
     157       
     158        if (patient != null)
     159        {
     160          // Load patient annotations
     161          patient.loadDefaultAnnotations(dc);
     162
     163          // Load cases associated with this patient
     164          List<Case> cases = Case.findByPatient(dc, patient);
     165         
     166          // Load case annotations
    113167          JSONArray jsonCases = new JSONArray();
    114           for (Sample s : caseQuery.list(dc))
    115           {
    116             JSONObject jsonCase = new JSONObject();
    117             jsonCase.put("id", s.getId());
    118             jsonCase.put("name", s.getName());
    119             jsonCase.put("laterality",  Reggie.getAnnotationValue(s, lateralityType));
    120             jsonCases.add(jsonCase);
    121           }
     168          if (cases.size() > 0)
     169          {
     170            AnnotationType lateralityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true);
     171            for (Case c : cases)
     172            {
     173              c.loadAnnotations("laterality", lateralityType);
     174              jsonCases.add(c.asJSONObject());
     175            }
     176          }
     177         
     178          jsonPat = patient.asJSONObject();
    122179          jsonPat.put("cases", jsonCases);
     180
    123181        }
    124182        else
    125183        {
    126           // Try to find the highest existing patient number
    127           patientQuery = BioSource.getQuery();
     184          // No patient was found -- try to find the highest existing patient number
     185          ItemQuery<BioSource> patientQuery = BioSource.getQuery();
    128186          patientQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.string("PAT%")));
    129187          patientQuery.order(Orders.desc(Hql.property("name")));
    130188          patientQuery.setMaxResults(1);
    131189          patientQuery.include(Include.ALL);
    132           patients = patientQuery.list(dc);
    133          
     190          List<BioSource> patients = patientQuery.list(dc);
     191          jsonPat = new JSONObject();
     192          jsonPat.put("personalNumber", pnr);
    134193          if (patients.size() == 0)
    135194          {
     
    150209            jsonPat.put("gender", Integer.parseInt(pnr.substring(10,11)) % 2 == 0 ? "F" : "M");
    151210          }
    152          
    153         }
    154        
    155         // Check for existing case
    156         ItemQuery<Sample> caseQuery = Sample.getQuery();
    157         caseQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.parameter("name", caseName, Type.STRING)));
    158         List<Sample> cases = caseQuery.list(dc);
    159         JSONObject jsonCase = new JSONObject();
    160         if (cases.size() >= 1)
    161         {
    162           throw new InvalidDataException(
    163             "At least one case with the given case name already exists. " +
    164             "This wizard can't be used for registration until that is corrected.");
    165         }
    166         jsonCase.put("name", caseName);
    167        
    168         // Find specimen information
    169         ItemQuery<Sample> specimenQuery = Sample.getQuery();
    170         specimenQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.parameter("name", caseName + ".%", Type.STRING)));
    171 
    172         JSONArray jsonSpecimens = new JSONArray();
    173         for (Sample specimen : specimenQuery.list(dc))
    174         {
    175           JSONObject jsonSpecimen = new JSONObject();
    176           jsonSpecimen.put("id", specimen.getId());
    177           jsonSpecimen.put("name", specimen.getName());
    178           jsonSpecimen.put("laterality", Reggie.getAnnotationValue(specimen, lateralityType));
    179           jsonSpecimen.put("pad", Reggie.getAnnotationValue(specimen, padType));
    180           jsonSpecimens.add(jsonSpecimen);
    181         }
    182         jsonCase.put("specimen", jsonSpecimens);
    183        
     211        }
     212
    184213        json.put("patientInfo", jsonPat);
    185         json.put("caseInfo", jsonCase);
    186214      }
    187215    }
     
    222250    try
    223251    {
    224       if ("Create".equals(cmd))
     252      if ("CreateCase".equals(cmd))
    225253      {
    226254        JSONObject jsonReq = (JSONObject)new JSONParser().parse(req.getReader());
    227        
    228255        JSONObject jsonPat = (JSONObject)jsonReq.get("patientInfo");
    229256        JSONObject jsonCase = (JSONObject)jsonReq.get("caseInfo");
     
    322349          {
    323350            JSONObject jsonSpec = (JSONObject)jsonSpecimen.get(i);
    324             Sample specimen = Sample.getById(dc, ((Long)jsonSpec.get("id")).intValue());
     351            Sample specimen = Sample.getById(dc, ((Number)jsonSpec.get("id")).intValue());
    325352            // Set specimen to 'pooled' and link with case
    326353            specimen.setPooled(true);
     
    360387       
    361388      }
     389     
     390      else if ("UpdateCase".equals(cmd))
     391      {
     392        JSONObject jsonReq = (JSONObject)new JSONParser().parse(req.getReader());
     393        JSONObject jsonCase = (JSONObject)jsonReq.get("caseInfo");
     394       
     395        dc = sc.newDbControl();
     396        Number caseId = (Number)jsonCase.get("id");
     397       
     398        Sample theCase = Sample.getById(dc, caseId.intValue());
     399       
     400        // Get laterality
     401        String laterality = Values.getStringOrNull((String)jsonCase.get("laterality"));
     402        // If the 'laterality' value is a number, then it hasn't changed
     403        if (Values.getInt(laterality) == 0)
     404        {
     405          AnnotationType lateralityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true);
     406          Reggie.setAnnotationValue(theCase, lateralityType, laterality);
     407          int numSpecimen = 0;
     408          for (Sample specimen : theCase.getChildSamples().list(dc))
     409          {
     410            Reggie.setAnnotationValue(specimen, lateralityType, laterality);
     411            numSpecimen++;
     412          }
     413          jsonMessages.add("Updated case '" + theCase.getName() + "' and " +numSpecimen +
     414              " specimen tube(s) to laterality="+laterality);
     415        }
     416
     417        dc.commit();
     418        json.put("messages", jsonMessages);
     419      }
     420     
    362421    }
    363422    catch (Throwable t)
Note: See TracChangeset for help on using the changeset viewer.