Changeset 1380 for extensions


Ignore:
Timestamp:
Aug 12, 2011, 2:57:39 PM (12 years ago)
Author:
Martin Svensson
Message:

References #317. The wizzard is more or less complete now. The work-flow needs to be tested and approved by an user

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

Legend:

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

    r1379 r1380  
    2828var caseIsValid = false;
    2929var arrivalDateIsValid = false;
     30var partitionDateIsValid = false;
    3031var nofDeliveredTubesIsValid = true;
    3132var nofTubesIsValid = false;
    3233var lateralityIsValid = false;
     34var boxesAreValid = null;
     35var wellsAreValidValid = null;
    3336var debug = false;
    3437var currentStep = 1;
     
    3639var caseInfo = null;
    3740var boxInfo = null;
     41var updateMode = null;
    3842
    3943function init()
     
    7680  getCaseInfo();
    7781 
    78   var hasSpecimen = caseInfo.specimen && caseInfo.specimen.length > 0;
     82  var hasSpecimen = caseInfo.specimen && caseInfo.specimen.length > 0; 
    7983  var hasLeftSpecimen = false;
    8084  var hasRightSpecimen = false;
    8185  var hasUnknownSpecimen = false;
    8286  var thisArrivalDate = null;
     87  var thisPartitionDate = null;
    8388  var thisNumberOfTubes = null;
    8489  var thisCaseSamplingDate = null;
    8590  var thisCaseRNALaterDate = null;
    8691  var thisCaseLaterality = null;
    87   var thisPad = null;
     92  var thisCasePad = null;
     93  var thisCasePathNote = null;
    8894
    8995  frm.caseName.disabled = true;
     
    9197  Main.show('gocancel');
    9298  Main.show('caseSection');
    93  
    94   frm.nofTubes.focus();
    95   currentStep = 2;
    96      
     99
     100  var hasLeftCase = false;
     101  var hasRightCase = false;
     102  var hasUnknownCase = false;
     103 
    97104  // Load annotations from the actual case
     105  thisCaseLaterality = caseInfo.laterality;
     106  thisCasePathNote = caseInfo.pathNote;
     107  thisCasePad = caseInfo.pad;
     108  if (caseInfo.reasonIfNoSpecimen && caseInfo.reasonIfNoSpecimen.length>0)
     109  {
     110    setFatalError("There is a reason given why this case doesn't have specimen tubes. " +
     111        "This wizard can't be used until that is corrected.");
     112  }
     113 
     114  //Adjust the step-title
     115  if (caseInfo.id)
     116  {
     117    setInnerHTML('step2.title', 'Add Specimen tube Information');
     118  }
    98119  if (hasSpecimen)
    99120  {
     121    setInnerHTML('step2.title', 'Update Case Information');
     122    updateMode = true;   
    100123    frm.nofTubes.value = thisNumberOfTubes;
    101124    frm.nofTubes.disabled = true;
    102125    frm.arrivalDate.focus();
     126
     127    // If the number of tubes not is set - use the current number of specimen tubes.
     128    if (!thisNumberOfTubes) thisNumberOfTubes = caseInfo.specimen.length;
     129       
    103130    for (var i=0; i < caseInfo.specimen.length; i++)
    104131    {
    105132      var specimen = caseInfo.specimen[i];       
    106       if (specimen.pad && !thisPad)
     133      if (specimen.pad && !thisCasePad)
    107134      {         
    108         thisPad = specimen.pad;
     135        thisCasePad = specimen.pad;
     136      }     
     137      if(specimen.arrivalDate && !thisArrivalDate)
     138      {         
     139        thisArrivalDate = specimen.arrivalDate;
    109140      }
    110       if(specimen.arrivalDate && !thisArrivalDate)
    111       {
    112         thisArrivalDate = specimen.arrivalDate;
     141      if(specimen.partitionDate && !thisPartitionDate)
     142      {        
     143        thisPartitionDate = specimen.partitionDate;
    113144      }
    114145      if (specimen.nofTubes && !thisNumberOfTubes)
     
    124155        thisCaseRNALaterDate = specimen.rnaLaterDate;
    125156      }
     157      if (specimen.pathNote && !thisCasePathNote)
     158      {
     159        thisCasePathNote = specimen.pathNote;
     160      }
    126161      if (specimen.laterality && !thisCaseLaterality)
    127162      {
     
    132167      else if(!thisCaseLaterality)
    133168      {
    134         hasUnknownSpecimen = true;       
     169        hasUnknownSpecimen = true;
    135170      }
    136171    }
    137     // If the number of tubes not is set - use the current number of specimen tubes.
    138     if (!thisNumberOfTubes) thisNumberOfTubes = caseInfo.specimen.length;
    139          
     172             
    140173    // Check that all specimen tubes have the same laterality
    141174    var numLateralities = 0;
     
    148181      thisCaseLaterality = null;
    149182      Forms.checkRadio(frm.laterality, thisCaseLaterality);       
    150     }     
    151     Forms.checkRadio(frm.laterality, thisCaseLaterality);
    152     lateralityOnChange();
    153    
    154     if (thisPad != null)
    155     {
    156       frm.pad.value = thisPad;
    157       padOnChange();
    158     }
    159     if (thisArrivalDate != null)
    160     {
    161       frm.arrivalDate.value = thisArrivalDate;
    162     }
    163     if (thisNumberOfTubes != null)
    164     {
    165       frm.nofTubes.value = thisNumberOfTubes;
    166       nofTubesOnChange();
    167     }
    168     if (thisCaseSamplingDate != null)
    169     {
    170       frm.samplingDate.value = thisCaseSamplingDate.substring(0, 8);
    171       frm.samplingTime.value = thisCaseSamplingDate.substring(9, 13);
    172       samplingDateTimeOnChange();
    173     }
    174     if (thisCaseRNALaterDate != null)
    175     {
    176       frm.rnaLaterDate.value = thisCaseRNALaterDate.substring(0, 8);
    177       frm.rnaLaterTime.value = thisCaseRNALaterDate.substring(9, 13);
    178       rnaLaterDateTimeOnChange();
    179     }
    180   }
    181 
    182   var hasLeftCase = false;
    183   var hasRightCase = false;
    184   var hasUnknownCase = false;
    185   if (caseInfo.id)
    186   {
    187     setInnerHTML('step2.title', 'Update Case Information');
    188     if (caseInfo.pad && !thisPad)     
    189     {     
    190       thisPad = caseInfo.pad;     
    191     }
    192     if (caseInfo.laterality)
    193     {
    194       var lateralityInput = '';
    195       lateralityInput += '<input type="radio" name="laterality" value="LEFT" ';
    196       if (caseInfo.laterality == 'LEFT') lateralityInput += 'checked';
    197       lateralityInput += ' onChange="lateralityOnChange()">LEFT';
    198       lateralityInput += '<br>';
    199       lateralityInput += '<input type="radio" name="laterality" value="RIGHT" ';
    200       if (caseInfo.laterality == 'RIGHT') lateralityInput += 'checked';
    201       lateralityInput += ' onChange="lateralityOnChange()">RIGHT';
    202       setInnerHTML('laterality.input', lateralityInput);
    203       lateralityOnChange();
    204     }
     183    }   
     184  }
     185  if (thisCaseLaterality != null)
     186  {
     187    var lateralityInput = '';
     188    lateralityInput += '<input type="radio" name="laterality" value="LEFT" ';
     189    if (thisCaseLaterality == 'LEFT') lateralityInput += 'checked';
     190    lateralityInput += ' onChange="lateralityOnChange()">LEFT';
     191    lateralityInput += '<br>';
     192    lateralityInput += '<input type="radio" name="laterality" value="RIGHT" ';
     193    if (thisCaseLaterality == 'RIGHT') lateralityInput += 'checked';
     194    lateralityInput += ' onChange="lateralityOnChange()">RIGHT';
     195    setInnerHTML('laterality.input', lateralityInput);                 
     196  }
     197  lateralityOnChange();
     198  if (thisCasePad != null)
     199  {
     200    frm.pad.value = thisCasePad;
     201    padOnChange();
     202  }
     203  if (thisArrivalDate != null)
     204  {
     205    frm.arrivalDate.value = thisArrivalDate;
     206  }
     207  if (thisPartitionDate != null)
     208  {
     209    frm.partitionDate.value = thisPartitionDate;
     210  }
     211  if (thisNumberOfTubes != null)
     212  {
     213    frm.nofTubes.value = thisNumberOfTubes;
     214    nofTubesOnChange();
     215  }
     216  if (thisCaseSamplingDate != null)
     217  {
     218    frm.samplingDate.value = thisCaseSamplingDate.substring(0, 8);
     219    frm.samplingTime.value = thisCaseSamplingDate.substring(9, 13);
     220    samplingDateTimeOnChange();
     221  }
     222  if (thisCaseRNALaterDate != null)
     223  {
     224    frm.rnaLaterDate.value = thisCaseRNALaterDate.substring(0, 8);
     225    frm.rnaLaterTime.value = thisCaseRNALaterDate.substring(9, 13);
     226    rnaLaterDateTimeOnChange();
     227  }
     228  if (thisCasePathNote != null)
     229  {
     230    frm.pathNote.value = thisCasePathNote;
    205231  }
     232  frm.nofTubes.focus();
     233  currentStep = 2;   
    206234}
    207235
     
    211239  var inputTubeHtml = '';
    212240  var nofTubes = frm.nofTubes.value;
    213 
     241  boxInfo = Array(nofTubes);
     242 
    214243  frm.arrivalDate.disabled = true;
     244  frm.partitionDate.disabled = true;
    215245  frm.nofTubes.disabled = true;
    216246  frm.pad.disabled = true;
     
    225255  frm.pathNote.disabled = true;
    226256 
     257  if (updateMode)
     258  {
     259    //setInnerHTML('step3.title', 'Update Tube Information');
     260  }
     261
    227262  for (var i=0;i<nofTubes;i++)
    228263  {
     
    231266    var rowValue = '';
    232267    var columnValue = '';
     268    var spWeightValue = '';
     269    var hisWeightValue = '';
     270    var allPrepWeightValue = '';
     271
     272    boxInfo[i] = null; 
    233273    if (caseInfo.specimen && caseInfo.specimen.length>0 && i<caseInfo.specimen.length)
    234274    {
    235275      specimen = caseInfo.specimen[i];
    236       boxValue = specimen.box;
    237       rowValue = specimen.row;
    238       columnValue = specimen.column;
     276      boxValue = specimen.box == null ? '' : specimen.box;
     277      rowValue = specimen.row == null ? '' : specimen.row;
     278      columnValue = specimen.column == null ? '' : specimen.column;
     279      spWeightValue = specimen.spWeight == null ? '' : specimen.spWeight;
     280      hisWeightValue = specimen.hisWeight == null ? '' : specimen.hisWeight;
     281      allPrepWeightValue = specimen.allPrepWeight == null ? '' : specimen.allPrepWeight;
    239282    }
    240283    inputTubeHtml += '<tr>';
     
    243286
    244287    var box = 'box'+i;
     288    var boxDisabled = boxValue == '' ? '' : 'disabled';
    245289    inputTubeHtml += '<tr>';
    246290    inputTubeHtml += '<td class="subprompt">Box</td>';
    247     inputTubeHtml += '<td class="input"><input type="text" name='+box+' value="' + boxValue + '" size="18" maxlength="12" onBlur="boxOnChange('+i+')"></td>';
     291    inputTubeHtml += '<td class="input"><input type="text" name='+box+' value="' + boxValue + '" '+ boxDisabled +' size="12" maxlength="12" onChange="boxOnChange('+i+')"></td>';
    248292    inputTubeHtml += '<td class="status" id="'+box+'.status"></td>';
    249293    inputTubeHtml += '<td class="help"><span id="'+box+'.message" class="message" style="display: none;"></span>Box the specimen tube is located in.</td>';   
     
    252296    var row = 'row'+i;
    253297    var column = 'column'+i;
     298    var wellDisabled = rowValue != '' || boxValue == '' ? 'disabled' : '';
    254299    inputTubeHtml += '<tr>';
    255300    inputTubeHtml += '<td class="subprompt">Row</td>';
    256     inputTubeHtml += '<td class="input"><input type="text" name='+row+' value="' + rowValue + '" size="3" maxlength="3"';
    257     inputTubeHtml += boxValue != '' ? '' : ' disabled';
     301    inputTubeHtml += '<td class="input"><input style="text-transform:uppercase;" type="text" onKeyPress="" name='+row+' value="' + rowValue + '" size="3" maxlength="2" ' + wellDisabled;
    258302    inputTubeHtml += ' onBlur="wellOnChange('+i+')">';
    259     inputTubeHtml += '&nbsp;Column<input type="text" name='+column+' value="'+ columnValue + '" size="3" maxlength="3"';
    260     inputTubeHtml += boxValue != '' ? '' : ' disabled';
     303    inputTubeHtml += '&nbsp;Column<input type="text" name='+column+' value="'+ columnValue + '" size="3" maxlength="3" ' + wellDisabled;
    261304    inputTubeHtml += ' onBlur="wellOnChange('+i+')">';
    262305    inputTubeHtml += '</td>';
     
    264307    inputTubeHtml += '<td class="help"><span id="rowColumn'+i+'.message" class="message" style="display: none;"></span></td>';   
    265308    inputTubeHtml += '</tr>';
     309
     310    var spWeight = 'spWeight'+i;
     311    inputTubeHtml += '<tr>';
     312    inputTubeHtml += '<td class="subprompt">Sp weight</td>';
     313    inputTubeHtml += '<td class="input"><input type="text" name='+spWeight+' value="' + spWeightValue + '" size="12" maxlength="10"></td>';
     314    inputTubeHtml += '<td class="status" id="'+spWeight+'.status"></td>';
     315    inputTubeHtml += '<td class="help"><span id="'+spWeight+'.message" class="message" style="display: none;"></span>[mg]</td>';   
     316    inputTubeHtml += '</tr>';
     317
     318    var allPrep = 'allPrepWeight' + i;
     319    inputTubeHtml += '<tr>';
     320    inputTubeHtml += '<td class="subprompt">Allprep weight</td>';
     321    inputTubeHtml += '<td class="input"><input type="text" name='+allPrep+' value="'+allPrepWeightValue+'" size="12" maxlength="10"></td>';
     322    inputTubeHtml += '<td class="status" id="'+allPrep+'.status"></td>';
     323    inputTubeHtml += '<td class="help"><span id="'+allPrep+'.message" class="message" style="display: none;"></span>[mg]</td>';   
     324    inputTubeHtml += '</tr>';
    266325   
    267     var his = 'his'+i;   
     326    var his = 'hisWeight'+i;   
    268327    inputTubeHtml += '<tr>';
    269     inputTubeHtml += '<td class="subprompt">His</td>';
    270     inputTubeHtml += '<td class="input"><input type="text" name='+his+' value="" size="12" maxlength="10"></td>';
     328    inputTubeHtml += '<td class="subprompt">His weight</td>';
     329    inputTubeHtml += '<td class="input"><input type="text" name='+his+' value="'+hisWeightValue+'" size="12" maxlength="10"></td>';
    271330    inputTubeHtml += '<td class="status" id="his.status"></td>';
    272     inputTubeHtml += '<td class="help"><span id="'+his+'.message" class="message" style="display: none;"></span>[µg]</td>';   
    273     inputTubeHtml += '</tr>';
    274 
    275     var allPrep = 'allPrep' + i;
    276     inputTubeHtml += '<tr>';
    277     inputTubeHtml += '<td class="subprompt">Allprep</td>';
    278     inputTubeHtml += '<td class="input"><input type="text" name='+allPrep+' value="" size="12" maxlength="10"></td>';
    279     inputTubeHtml += '<td class="status" id="'+allPrep+'.status"></td>';
    280     inputTubeHtml += '<td class="help"><span id="'+allPrep+'.message" class="message" style="display: none;"></span>[µg]</td>';   
    281     inputTubeHtml += '</tr>';
    282 
    283     var backupWeight = 'backupWeight'+i;
    284     inputTubeHtml += '<tr>';
    285     inputTubeHtml += '<td class="subprompt">Backup weight</td>';
    286     inputTubeHtml += '<td class="input"><input type="text" name='+backupWeight+' value="" size="12" maxlength="10"></td>';
    287     inputTubeHtml += '<td class="status" id="'+backupWeight+'.status"></td>';
    288     inputTubeHtml += '<td class="help"><span id="'+backupWeight+'.message" class="message" style="display: none;"></span>[µg]</td>';   
    289     inputTubeHtml += '</tr>';
    290 
    291     var deliveryComment = 'deliveryComment'+i;
     331    inputTubeHtml += '<td class="help"><span id="'+his+'.message" class="message" style="display: none;"></span>[mg]</td>';   
     332    inputTubeHtml += '</tr>';   
     333
     334    var operatorComment = 'operatorComment'+i;
     335    var doOnTab = i==(nofTubes-1) ? 'doOnTab(event, goCreate)' : '';
    292336    inputTubeHtml += '<tr>';
    293337    inputTubeHtml += '<td class="subprompt">Operator comment</td>';
    294     inputTubeHtml += '<td class="input"><textarea rows="3" cols="30" name='+deliveryComment+' value=""></textarea></td>';
    295     inputTubeHtml += '<td class="status" id="'+deliveryComment+'.status"></td>';
    296     inputTubeHtml += '<td class="help"><span id="'+deliveryComment+'.message" class="message" style="display: none;"></span>Operator delivery comment</td>';   
     338    inputTubeHtml += '<td class="input"><textarea rows="3" cols="30" name='+operatorComment+' value="" onkeypress="'+doOnTab+'"></textarea></td>';
     339    inputTubeHtml += '<td class="status" id="'+operatorComment+'.status"></td>';
     340    inputTubeHtml += '<td class="help"><span id="'+operatorComment+'.message" class="message" style="display: none;"></span>Operator delivery comment</td>';   
    297341    inputTubeHtml += '</tr>';
    298342  }
    299   setInnerHTML('tubeInputs', inputTubeHtml);
    300   boxInfo = Array();
     343  setInnerHTML('tubeInputs', inputTubeHtml); 
     344  boxesAreValid = Array(nofTubes);
     345  wellsAreValid = Array(nofTubes);
    301346  currentStep = 3;
    302347  Main.show('tubeSection');
    303348  Main.hide('gonext');
    304   Main.show('gocreate'); 
    305   frm.box0.focus();
     349
     350  if (updateMode) Main.show('goupdate');
     351  else Main.show('gocreate');
     352
     353  if (frm.box0.value == '') frm.box0.focus();
     354  else frm.his0.focus();
    306355}
    307356
     
    348397  var columnName = 'column'+tubeIndex; 
    349398  var boxValue = frm.elements[boxName].value;
     399
     400  wellsAreValid[tubeIndex] = false;
    350401 
    351402  if (frm.elements[boxName].value == '')
    352403  {
     404    boxesAreValid[tubeIndex] = true;
     405    wellsAreValid[tubeIndex] = true;
    353406    frm.elements[rowName].disabled = true;
    354407    frm.elements[rowName].value = '';
     
    372425  if (response.status != 'ok')
    373426  {
     427    boxesAreValid[tubeIndex] = false;   
    374428    setFatalError(response.message);
    375429    return false;
     
    377431  if (!response.boxInfo)
    378432  {
    379     setInputStatus(boxName, response.message, 'invalid');
     433    boxesAreValid[tubeIndex] = false;
     434    setInputStatus(boxName, response.message, 'invalid');   
    380435    frm.elements[rowName].value = '';
    381436    frm.elements[columnName].value = '';
     
    385440  }   
    386441  else
    387   {
     442  {
     443    boxesAreValid[tubeIndex] = true;
    388444    boxInfo[tubeIndex] = response.boxInfo; 
    389445    frm.elements[rowName].disabled = false;
    390446    frm.elements[columnName].disabled = false;
    391447    frm.elements[rowName].value = '';
    392     setInputStatus('rowColumn'+tubeIndex,'Row[A-'+response.rows+'], Columns[1-'+response.columns+']','');   
    393     frm.elements[columnName].disabled = '';
     448    frm.elements[columnName].value = '';
     449    setInputStatus('rowColumn'+tubeIndex,'Row[A-'+response.rows+'], Columns[1-'+response.columns+']','');
    394450    setInputStatus(boxName, '', 'valid');   
    395451    frm.elements[rowName].focus();   
     
    411467      (rowValue == '' || columnValue == ''))
    412468  {
     469    wellsAreValid[tubeIndex] = false;
    413470    setInputStatus('rowColumn'+tubeIndex, 'Row or column cannot be empty when the box is specified.', 'invalid');
    414471    return false;
    415   }
     472  } 
    416473 
    417474  var request = Ajax.getXmlHttpRequest();
     
    428485  if (response.status != 'ok')
    429486  {
     487    wellsAreValid[tubeIndex] = false;
    430488    setFatalError(response.message);
    431489    return false;
     
    433491  if (response.message)
    434492  {
     493    wellsAreValid[tubeIndex] = false;
    435494    setInputStatus('rowColumn'+tubeIndex, response.message, 'invalid')
    436495    return false;
     
    443502          columnValue == frm.elements['column'+i].value)
    444503      {
     504        wellsAreValid[tubeIndex] = false;
    445505        setInputStatus('rowColumn'+tubeIndex, 'The row and column are already used once in this wizard','invalid');       
    446506        return false;
     
    448508    }
    449509  }
     510  wellsAreValid[tubeIndex] = true;
    450511  setInputStatus('rowColumn'+tubeIndex, '', 'valid');
    451512}
     
    523584}
    524585
     586function partitionDateOnBlur()
     587{
     588  var frm = document.forms['reggie'];
     589  var partitionDate = frm.partitionDate.value;
     590  partitionDateIsValid = false;
     591
     592  setInputStatus('partitionDate', '', '');
     593
     594  if (partitionDate != '')
     595  {
     596    partitionDate = autoFillDate(partitionDate);
     597    frm.partitionDate.value = partitionDate;
     598
     599    if (!Dates.isDate(partitionDate, 'yyyyMMdd'))
     600    {
     601      setInputStatus('partitionDate', 'Not a valid date', 'invalid');
     602      return;
     603    }
     604    setInputStatus('partitionDate', '', 'valid');
     605    partitionDateIsValid = true;   
     606  }
     607  else
     608  {
     609    setInputStatus('partitionDate', 'Missing', 'warning');
     610  }
     611}
     612
    525613function nofTubesOnChange()
    526614{
     
    533621    return;
    534622  }
     623  if (nofTubes == '0')
     624  {
     625    setInputStatus('nofTubes', 'Must be at least 1', 'invalid');
     626    return;   
     627  }
    535628  setInputStatus('nofTubes','', 'valid');
    536629  nofTubesIsValid = true;
     
    552645function lateralityOnChange()
    553646{
     647  // No specimen tubes?
     648  //if (!caseInfo.specimen || caseInfo.specimen.length == 0) return;
     649 
    554650  lateralityIsValid = false;
    555   var updateMode = caseInfo.id;
    556651 
    557652  // Check selected laterality against specimen tubes
     
    568663  lateralityIsValid = true;
    569664  var laterality = selectedLaterality.value; 
    570  
    571   // No specimen tubes?
    572   if (!caseInfo.specimen || caseInfo.specimen.length == 0) return;
     665  if (laterality == '')
     666  {
     667    laterality = null;
     668  }
    573669 
    574670  for (var i = 0; i < caseInfo.specimen.length; i++)
     
    577673    if (specimen.laterality != laterality)
    578674    {
    579       if (specimen.laterality == null || updateMode)
    580       {
    581         setInputStatus('laterality', 'Specimen tubes are updated to: ' + laterality, 'valid')
    582       }
    583       else
    584       {
    585         setInputStatus('laterality', 'Not same laterality as specimen tubes', 'warning');
    586       }
     675      setInputStatus('laterality', 'Specimen tubes are updated to: ' + laterality, 'valid')         
    587676      return;
    588677    }
     
    591680
    592681function step3IsValid()
    593 {
    594   return false;
     682{
     683  var step3IsValid = false;
     684  var i=0;
     685  var bioWellsAreValid = true;
     686 
     687  while (i<boxesAreValid.length && bioWellsAreValid)
     688  {
     689    if (!boxesAreValid[i] || !wellsAreValid[i])
     690    {
     691      bioWellsAreValid = false;
     692    }     
     693    i++;
     694  }
     695  step3IsValid = bioWellsAreValid; 
     696  return step3IsValid;
    595697}
    596698
     
    601703  Main.hide('gocancel');
    602704  Main.hide('gocreate');
    603   var frm = document.forms['reggie'];
     705  Main.hide('goupdate');
     706  var frm = document.forms['reggie'];
     707 
    604708
    605709  caseInfo.laterality = Forms.getCheckedRadio(frm.laterality).value;
     
    608712  caseInfo.rnaLaterDate = Main.trimString(frm.rnaLaterDate.value + ' ' + frm.rnaLaterTime.value);
    609713  caseInfo.pathNote = frm.pathNote.value;
    610 
     714  caseInfo.arrivalDate = Main.trimString(frm.arrivalDate.value); 
     715  caseInfo.partitionDate = Main.trimString(frm.partitionDate.value);
     716 
    611717  var nofTubes = frm.nofTubes.value;
    612718  for (var i=0; i<nofTubes; i++)
    613719  {
    614     var specimenTube = new Object();   
     720    var specimenTube = new Object();       
    615721    if (caseInfo.specimen[i]) specimenTube = caseInfo.specimen[i];
    616     specimenTube.name = caseInfo.name+'.'+i;
    617 
     722    specimenTube.name = caseInfo.name+'.'+(1+i);
     723
     724    frm.elements['box'+i].disabled = true;
     725    frm.elements['row'+i].disabled = true;
     726    frm.elements['column'+i].disabled = true;
     727    frm.elements['spWeight'+i].disabled = true;
     728    frm.elements['allPrepWeight'+i].disabled = true;
     729    frm.elements['hisWeight'+i].disabled = true;
     730    frm.elements['operatorComment'+i].disabled = true;
     731   
     732    if (boxInfo[i] != '') specimenTube.boxId = boxInfo[i];
     733    if (frm.elements['row'+i].value != '') specimenTube.row = frm.elements['row'+i].value;
     734    if (frm.elements['column'+i].value != '') specimenTube.column = frm.elements['column'+i].value;
     735    if (frm.elements['operatorComment'+i].value != '') specimenTube.operatorComment = frm.elements['operatorComment'+i].value; 
     736
     737    if (frm.elements['spWeight'+i].value != '') specimenTube.spWeight = frm.elements['spWeight'+i].value;
     738    if (frm.elements['allPrepWeight'+i].value != '') specimenTube.allPrepWeight = frm.elements['allPrepWeight'+i].value;
     739    if (frm.elements['hisWeight'+i].value != '') specimenTube.hisWeight = frm.elements['hisWeight'+i].value;
     740   
    618741    caseInfo.specimen[i] = specimenTube;
    619742  }
     
    626749  var request = Ajax.getXmlHttpRequest();
    627750  var url = 'SpecimenTubeRegistration.servlet?ID=<%=ID%>&cmd=';
    628   url += 'CreateSpecimenTubes';
     751  url += updateMode ? 'UpdateSpecimenTubes' : 'CreateSpecimenTubes';
    629752  request.open("POST", url, false);
    630753  request.setRequestHeader("Content-Type", "application/json");
     
    638761    setFatalError(response.message);
    639762    return false;
    640   }
     763  }
     764
     765  var msg = '<ul>';
     766  for (var i = 0; i < response.messages.length; i++)
     767  {
     768    msg += '<li>' + response.messages[i];
     769  }
     770  msg += '</ul>';
     771  setInnerHTML('done', msg);
     772  Main.show('done');
     773  Main.show('gorestart');
    641774}
    642775
     
    728861      <td class="status" id="arrivalDate.status"></td>
    729862      <td class="help"><span id="arrivalDate.message" class="message" style="display:none"></span>Date when the specimen tubes arrived(YYYYMMDD or MMDD).</td>
     863    </tr>
     864    <tr valign="top">
     865      <td class="prompt">Partition date</td>
     866      <td class="input"><input type="text" name="partitionDate"
     867        value="" size="12" maxlength="10" onblur="partitionDateOnBlur()"></td>
     868      <td class="status" id="partitionDate.status"></td>
     869      <td class="help"><span id="partitionDate.message" class="message" style="display:none"></span>Date when the specimen tubes were partitioned(YYYYMMDD or MMDD).</td>
    730870    </tr>
    731871    <tr>
     
    768908      <td class="prompt" id="pathNote.prompt">Path note</td>
    769909      <td class="input" id="pathNote.input"><textarea rows="3" cols="30"
    770         name="pathNote" value="" onkeypress="doOnTabOrEnter(event, goNext)"></textarea></td>
     910        name="pathNote" value="" onkeypress="doOnTab(event, goNext)"></textarea></td>
    771911      <td class="status" id="pathNote.status"></td>
    772912      <td class="help"><span id="pathNote.message" class="message" style="display: none;"></span></td>
     
    804944      <td><base:button id="gonext" title="Next" image="gonext.gif" onclick="goNext(true)"/></td>
    805945      <td><base:button id="gocreate" title="Create" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td>
     946      <td><base:button id="goupdate" title="Update" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td>
    806947      <td><base:button id="gorestart" title="Restart" image="goback.gif" onclick="goRestart(true)" style="display: none;"/></td>
    807948      <td id="gonext.message" class="message"></td>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/Reggie.java

    r1379 r1380  
    131131 
    132132  /**
     133    The name of the "PartitionDate" annotation type, used
     134    for samples (Specimen tube). It is a timestamp annotation.
     135  */
     136  public static final String ANNOTATION_PARTITION_DATE = "PartitionDate";
     137  /**
    133138    The name of the "NofDeliveredTubes" annotation type, used
    134139    for samples (Specimen tube). It is an Integer annotation type.
     
    147152  */
    148153  public static final String ANNOTATION_OPERATOR_COMMENT = "OperatorComment";
     154 
     155  /**
     156    The name of the Sp-weight annotation type, use
     157    for samples (Specimen tube). It is a Float annotation type.
     158   */
     159  public static final String ANNOTATION_SP_WEIGTH = "SpWeight";
     160 
     161  /**
     162    The name of the allPrep-weight annotation type, use
     163    for samples (Specimen tube). It is a Float annotation type.
     164   */
     165  public static final String ANNOTATION_ALLPREP_WEIGTH = "AllPrepWeight";
     166 
     167  /**
     168    The name of the his-weight annotation type, use
     169    for samples (Specimen tube). It is a Float annotation type.
     170   */
     171  public static final String ANNOTATION_HIS_WEIGTH = "HisWeight";
    149172 
    150173  /**
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/SpecimenTube.java

    r1379 r1380  
    1818import net.sf.basedb.core.query.Orders;
    1919import net.sf.basedb.core.query.Restrictions;
     20import net.sf.basedb.util.formatter.WellCoordinateFormatter;
    2021
    2122/**
     
    9899 
    99100  private final String box;
    100   private final Integer row;
    101   private final Integer column;
     101  private final String row;
     102  private final String column;
    102103 
    103104  private SpecimenTube(Sample sample)
     
    106107    if (sample.getBioWell() != null)
    107108    {
     109      WellCoordinateFormatter wcfRow = new WellCoordinateFormatter(true);
     110      WellCoordinateFormatter wcfColumn = new WellCoordinateFormatter(false);
    108111      BioWell well = sample.getBioWell();
    109112      box = well.getPlate().getName();
    110       row = well.getRow();
    111       column = well.getColumn();
     113      row = wcfRow.format(well.getRow());     
     114      column = wcfColumn.format(well.getColumn());
    112115    }
    113116    else
     
    139142    Get the row index in the box, where this specimen tube can be found.
    140143  */
    141   public Integer getRow()
     144  public String getRow()
    142145  {
    143146    return row;
     
    147150    Get the column index in the box, where this specimen tube can be found.
    148151  */
    149   public Integer getColumn()
     152  public String getColumn()
    150153  {
    151154    return column;
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/InstallServlet.java

    r1379 r1380  
    127127        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_ARRIVAL_DATE, Item.SAMPLE, Type.DATE, 1,
    128128            null, effectiveOptions, createIfMissing));
     129        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_PARTITION_DATE, Item.SAMPLE, Type.DATE, 1,
     130            null, effectiveOptions, createIfMissing));
    129131        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_NOF_DELIVERED_TUBES, Item.SAMPLE, Type.INT, 1,
    130132            null, effectiveOptions, createIfMissing));
     
    133135        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_PATH_NOTE, Item.SAMPLE, Type.STRING, 1,
    134136            null, effectiveOptions, createIfMissing));
     137        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_ALLPREP_WEIGTH, Item.SAMPLE, Type.FLOAT, 1,
     138            null,effectiveOptions, createIfMissing));
     139        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_SP_WEIGTH, Item.SAMPLE, Type.FLOAT, 1,
     140            null,effectiveOptions, createIfMissing));
     141        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_HIS_WEIGTH, Item.SAMPLE, Type.FLOAT, 1,
     142            null,effectiveOptions, createIfMissing));
    135143       
    136144        json.put("checks", jsonChecks);
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SpecimenTubeServlet.java

    r1379 r1380  
    2121import net.sf.basedb.core.Sample;
    2222import net.sf.basedb.core.SessionControl;
    23 import net.sf.basedb.core.Type;
    24 import net.sf.basedb.core.query.Expression;
    2523import net.sf.basedb.core.query.Expressions;
    2624import net.sf.basedb.core.query.Hql;
     
    7674        JSONObject jsonCase = null;
    7775       
     76        // Load specimen tubes for the case
     77        specimenTubes = SpecimenTube.findByCaseName(dc, caseName);
    7878        if (theCase == null)
    79         {
    80           specimenTubes = SpecimenTube.findByCaseName(dc, caseName);
     79        {         
    8180          jsonCase = new JSONObject();
    8281          jsonCase.put("name", caseName);
    8382        }
    8483        else
    85         {
    86           // Load specimen tubes for the case
    87           specimenTubes = SpecimenTube.findByCase(dc, theCase, true);
    88          
    89           // Load case annotations
     84        {         
    9085          theCase.loadAnnotations(dc, "laterality", Reggie.ANNOTATION_LATERALITY, null);
    91           theCase.loadAnnotations(dc, "pad", Reggie.ANNOTATION_PAD_CASE, null);
    92           theCase.loadAnnotations(dc, "reasonIfNoSpeciment", Reggie.ANNOTATION_REASON_IF_NO_SPECIMEN, null);
     86          theCase.loadAnnotations(dc, "pad", Reggie.ANNOTATION_PAD_CASE, null);         
     87          theCase.loadAnnotations(dc, "reasonIfNoSpecimen", Reggie.ANNOTATION_REASON_IF_NO_SPECIMEN, null);
     88          theCase.loadAnnotations(dc, "pathNote", Reggie.ANNOTATION_PATH_NOTE, null);
    9389         
    9490          jsonCase = theCase.asJSONObject();
     91         
    9592        }
    9693       
    9794        JSONArray jsonTubes = new JSONArray();
    98         if (specimenTubes.size() > 0)
    99         {
    100           AnnotationType padType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD, true);
    101           AnnotationType laterlityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true);
    102           AnnotationType samplingDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SAMPLING_DATETIME, true);
    103           AnnotationType rnaLaterDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_RNALATER_DATETIME, true);
    104           AnnotationType arrivalDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ARRIVAL_DATE, true);
    105           AnnotationType nofDeliveredTubesType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_NOF_DELIVERED_TUBES, true);
    106           AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_COMMENT, true);
     95        if (theCase != null && specimenTubes.size() == 0)
     96        {
     97          throw new InvalidDataException("The case (" + caseName + ") was found " +
     98              "but has no tubes to update");
     99        }
     100       
     101        AnnotationType padType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD, true);
     102        AnnotationType laterlityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true);
     103        AnnotationType samplingDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SAMPLING_DATETIME, true);
     104        AnnotationType rnaLaterDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_RNALATER_DATETIME, true);
     105        AnnotationType arrivalDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ARRIVAL_DATE, true);
     106        AnnotationType partitionDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PARTITION_DATE, true);
     107        AnnotationType nofDeliveredTubesType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_NOF_DELIVERED_TUBES, true);
     108        AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_COMMENT, true);
     109        AnnotationType pathNoteType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PATH_NOTE, true);
     110        AnnotationType spWeightType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SP_WEIGTH, true);
     111        AnnotationType allPrepWeightType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ALLPREP_WEIGTH, true);
     112        AnnotationType hisWeightType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_HIS_WEIGTH, true);
     113                 
     114        DateToStringConverter dateTimeConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd HHmm"));
     115        DateToStringConverter dateConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd"));
     116        for (SpecimenTube tube : specimenTubes)
     117        {         
     118          tube.loadAnnotations("pad", padType, null);
     119          tube.loadAnnotations("laterality", laterlityType, null);
     120          tube.loadAnnotations("samplingDate", samplingDateType, dateTimeConverter);
     121          tube.loadAnnotations("rnaLaterDate", rnaLaterDateType, dateTimeConverter);
     122          tube.loadAnnotations("arrivalDate", arrivalDateType, dateConverter);
     123          tube.loadAnnotations("partitionDate", partitionDateType, dateConverter);
     124          tube.loadAnnotations("nofTubes", nofDeliveredTubesType, null);
     125          tube.loadAnnotations("operatorComment", operatorCommentType, null);
     126          tube.loadAnnotations("pathNote", pathNoteType, null);
     127          tube.loadAnnotations("allPrepWeight", allPrepWeightType, null);
     128          tube.loadAnnotations("spWeight", spWeightType, null);
     129          tube.loadAnnotations("hisWeight", hisWeightType, null);
    107130         
    108           DateToStringConverter dateTimeConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd HHmm"));
    109           DateToStringConverter dateConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd"));
    110           for (SpecimenTube tube : specimenTubes)
    111           {
    112             tube.loadAnnotations("pad", padType, null);
    113             tube.loadAnnotations("laterality", laterlityType, null);
    114             tube.loadAnnotations("samplingDate", samplingDateType, dateTimeConverter);
    115             tube.loadAnnotations("rnaLaterDate", rnaLaterDateType, dateTimeConverter);
    116             tube.loadAnnotations("arrivalDate", arrivalDateType, dateConverter);
    117             tube.loadAnnotations("nofTubes", nofDeliveredTubesType, null);
    118             tube.loadAnnotations("operatorComment", operatorCommentType, null);
    119            
    120             jsonTubes.add(tube.asJSONObject());
    121           }
    122         }
    123         jsonCase.put("specimen", jsonTubes);
    124        
     131          jsonTubes.add(tube.asJSONObject());
     132        }       
     133        jsonCase.put("specimen", jsonTubes);       
    125134        json.put("caseInfo", jsonCase);
    126135      }
     
    175184          msg = "The column must be between " +  1 + " and " + plate.getColumns();
    176185        }
    177         else if (!plate.getBioWell(rowNumber-1, columnIndex).isEmpty())
     186        else if (!plate.getBioWell(rowNumber-1, columnIndex).isEmpty() )
    178187        {
    179188          msg = "Specified row:column("+rowString+":"+wcfColumn.format(columnIndex)+") is already taken.";
     
    201210  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    202211    throws ServletException, IOException
    203   {
     212  { 
    204213    String ID = req.getParameter("ID");
    205214    String cmd = req.getParameter("cmd");
     
    213222    final SessionControl sc = Application.getSessionControl(ID, req.getRemoteAddr());
    214223    DbControl dc = null;
    215    
     224       
    216225    try
    217226    {
    218       if ("CreateSpecimenTubes".equals(cmd))
     227      if ("UpdateSpecimenTubes".equals(cmd))
    219228      {
    220229        dc = sc.newDbControl();
    221230       
     231        JSONObject jsonReq = (JSONObject) new JSONParser().parse(req.getReader());
     232        JSONObject jsonCase = (JSONObject)jsonReq.get("caseInfo");
     233        Sample theCase = null;
     234       
     235        Number caseId = (Number)jsonCase.get("id");       
     236        String laterality = Values.getStringOrNull((String)jsonCase.get("laterality"));       
     237        String padCase = Values.getStringOrNull((String)jsonCase.get("pad"));       
     238        String pathNote = Values.getStringOrNull((String)jsonCase.get("pathNote"));
     239        StringToDateConverter dateTimeConverter = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd HHmm"));
     240        StringToDateConverter dateConverter = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd"));       
     241        Date samplingDate = dateTimeConverter.convert((String)jsonCase.get("samplingDate"));
     242        Date rnaLaterDate = dateTimeConverter.convert((String)jsonCase.get("rnaLaterDate"));
     243        Date arrivalDate = dateConverter.convert((String)jsonCase.get("arrivalDate")); 
     244        Date partitionDate = dateConverter.convert((String)jsonCase.get("partitionDate"));
     245       
     246        AnnotationType nofDeliveredTubesType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_NOF_DELIVERED_TUBES, true);
     247        AnnotationType padType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD, true);
     248        AnnotationType padCaseType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD_CASE, true);
     249        AnnotationType lateralityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true);
     250        AnnotationType pathNoteType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PATH_NOTE, true);
     251        AnnotationType samplingDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SAMPLING_DATETIME, true);
     252        AnnotationType rnaLaterDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_RNALATER_DATETIME, true);
     253        AnnotationType arrivalDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ARRIVAL_DATE, true);
     254        AnnotationType partitionDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PARTITION_DATE, true);
     255        AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_COMMENT, true);
     256        AnnotationType spWeightType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SP_WEIGTH, true);
     257        AnnotationType allPrepWeightType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ALLPREP_WEIGTH, true);
     258        AnnotationType hisWeightType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_HIS_WEIGTH, true);
     259       
     260        // Checking if it is an existing case or a new should be created.
     261        if (caseId != null)
     262        {
     263          theCase = Sample.getById(dc, caseId.intValue());
     264         
     265          if (laterality != null) Reggie.setAnnotationValue(theCase, lateralityType, laterality);
     266          if (arrivalDate != null) Reggie.setAnnotationValue(theCase, arrivalDateType, arrivalDate);
     267          if (partitionDate != null) Reggie.setAnnotationValue(theCase, partitionDateType, partitionDate);
     268          if (pathNote != null) Reggie.setAnnotationValue(theCase, pathNoteType, pathNote);       
     269          if (padCase != null) Reggie.appendAnnotationValueIfUnique(theCase, padCaseType, padCase);
     270        }       
     271       
     272        JSONArray jsonSpecimen = (JSONArray)jsonCase.get("specimen");
     273        if (jsonSpecimen != null && jsonSpecimen.size() > 0)
     274        {
     275          int nofTubes = jsonSpecimen.size();
     276          for (int i=0; i < jsonSpecimen.size(); i++)
     277          {
     278            JSONObject jsonSpec = (JSONObject)jsonSpecimen.get(i);
     279            Number specimenId = (Number)jsonSpec.get("id");
     280            Sample specimen = Sample.getById(dc, specimenId.intValue());
     281           
     282            float originalQuantity = 0;
     283            Float spWeight = null;
     284            Float allPrepWeight = null;
     285            Float hisWeight = null;
     286            if (jsonSpec.get("spWeight") != null && jsonSpec.get("spWeight") != "")
     287            {
     288              spWeight = Values.getFloat(((String)jsonSpec.get("spWeight")));
     289            }
     290            if (jsonSpec.get("hisWeight") != null && jsonSpec.get("hisWeight") != "")
     291            {
     292              hisWeight = Values.getFloat((String)jsonSpec.get("hisWeight"));
     293            }
     294            if (jsonSpec.get("allPrepWeight") != null && jsonSpec.get("allPrepWeight") != "")
     295            {
     296              allPrepWeight = Values.getFloat((String)jsonSpec.get("allPrepWeight"));
     297            }
     298            String operatorComment = Values.getStringOrNull((String)jsonSpec.get("operatorComment"));
     299           
     300            Reggie.setAnnotationValue(specimen, nofDeliveredTubesType, nofTubes);
     301            if (arrivalDate != null) Reggie.setAnnotationValue(specimen, arrivalDateType, arrivalDate);           
     302            if (partitionDate != null) Reggie.setAnnotationValue(specimen, partitionDateType, partitionDate);
     303            if (laterality != null) Reggie.setAnnotationValue(specimen, lateralityType, laterality);
     304            if (samplingDate != null) Reggie.setAnnotationValue(specimen, samplingDateType, samplingDate);
     305            if (rnaLaterDate != null) Reggie.setAnnotationValue(specimen, rnaLaterDateType, rnaLaterDate);
     306            if (padCase != null) Reggie.setAnnotationValue(specimen, padType, padCase);
     307            if (pathNote != null) Reggie.setAnnotationValue(specimen, pathNoteType, pathNote);           
     308            if (spWeight != null)
     309            {
     310              Reggie.setAnnotationValue(specimen, spWeightType, spWeight.floatValue());
     311              originalQuantity = originalQuantity + spWeight * 1000;
     312            }
     313            if (allPrepWeight != null)
     314            {
     315              Reggie.setAnnotationValue(specimen, allPrepWeightType, allPrepWeight.floatValue());
     316              originalQuantity = originalQuantity + allPrepWeight.floatValue() * 1000;
     317            }
     318            if (hisWeight != null)
     319            {
     320              Reggie.setAnnotationValue(specimen, hisWeightType, hisWeight.floatValue());
     321              originalQuantity = originalQuantity + hisWeight.floatValue() * 1000;
     322            }
     323            if (operatorComment != null) Reggie.setAnnotationValue(specimen, operatorCommentType, operatorComment);           
     324            if (originalQuantity > 0) specimen.setOriginalQuantity(originalQuantity);
     325           
     326            jsonMessages.add("Specimen tube '" + specimen.getName() + "' updated successfully.");
     327          }
     328        }
     329        dc.commit();
     330        json.put("messages", jsonMessages);
     331      }
     332      else if ("CreateSpecimenTubes".equals(cmd))
     333      {
     334        dc = sc.newDbControl();
     335       
    222336        JSONObject jsonReq = (JSONObject)new JSONParser().parse(req.getReader());       
    223337        JSONObject jsonCase = (JSONObject)jsonReq.get("caseInfo");
    224         Number caseId = (Number)jsonCase.get("id");
    225         Sample theCase = null;
    226        
    227         if (caseId != null)
    228         {
    229           theCase = Sample.getById(dc, caseId.intValue());
    230         }
    231         else
    232         {
    233           theCase = Sample.getNew(dc);
    234           theCase.setName((String)jsonCase.get("name"));
    235          
    236           dc.saveItem(theCase);
    237         }
    238          
    239         String laterality = Values.getStringOrNull((String)jsonCase.get("laterality"));
     338
     339        String laterality = Values.getStringOrNull((String)jsonCase.get("laterality"));       
    240340        String padCase = Values.getStringOrNull((String)jsonCase.get("pad"));
    241341        String pathNote = Values.getStringOrNull((String)jsonCase.get("pathNote"));
     
    244344        Date samplingDate = dateTimeConverter.convert((String)jsonCase.get("samplingDate"));
    245345        Date rnaLaterDate = dateTimeConverter.convert((String)jsonCase.get("rnaLaterDate"));
    246         Date arrivalDate = dateConverter.convert((String)jsonCase.get("arrivalDate"));
    247        
     346        Date arrivalDate = dateConverter.convert((String)jsonCase.get("arrivalDate"));       
     347        Date partitionDate = dateConverter.convert((String)jsonCase.get("partitionDate"));
     348       
     349        AnnotationType nofDeliveredTubesType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_NOF_DELIVERED_TUBES, true);
     350        AnnotationType padType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD, true);
    248351        AnnotationType padCaseType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD_CASE, true);
    249352        AnnotationType lateralityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true);
    250 //        AnnotationType pathNoteType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PATH_NOTE, true);
     353        AnnotationType pathNoteType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PATH_NOTE, true);
    251354        AnnotationType samplingDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SAMPLING_DATETIME, true);
    252355        AnnotationType rnaLaterDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_RNALATER_DATETIME, true);
    253356        AnnotationType arrivalDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ARRIVAL_DATE, true);
    254        
    255         Reggie.setAnnotationValue(theCase, lateralityType, laterality);
    256         Reggie.setAnnotationValue(theCase, arrivalDateType, arrivalDate);
    257 //        Reggie.setAnnotationValue(theCase, pathNoteType, pathNote);
    258        
    259         if (padCase != null) Reggie.appendAnnotationValueIfUnique(theCase, padCaseType, padCase);
    260        
     357        AnnotationType partitionDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PARTITION_DATE, true);
     358        AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_COMMENT, true);
     359        AnnotationType spWeightType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SP_WEIGTH, true);
     360        AnnotationType allPrepWeightType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ALLPREP_WEIGTH, true);
     361        AnnotationType hisWeightType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_HIS_WEIGTH, true);
     362       
     363        JSONArray jsonSpecimen = (JSONArray)jsonCase.get("specimen");
     364       
     365        if (jsonSpecimen != null && jsonSpecimen.size() > 0)
     366        {
     367          int nofTubes = jsonSpecimen.size();
     368          for (int i=0; i < jsonSpecimen.size(); i++)
     369          {
     370            JSONObject jsonSpec = (JSONObject)jsonSpecimen.get(i);
     371            Sample specimen = Sample.getNew(dc);
     372            specimen.setName((String)jsonSpec.get("name"));
     373            dc.saveItem(specimen);
     374           
     375            float originalQuantity = 0;
     376            Float spWeight = null;
     377            Float allPrepWeight = null;
     378            Float hisWeight = null;
     379            if (jsonSpec.get("spWeight") != null && jsonSpec.get("spWeight") != "")
     380            {
     381              spWeight = Values.getFloat(((String)jsonSpec.get("spWeight")));
     382            }
     383            if (jsonSpec.get("hisWeight") != null && jsonSpec.get("hisWeight") != "")
     384            {
     385              hisWeight = Values.getFloat((String)jsonSpec.get("hisWeight"));
     386            }
     387            if (jsonSpec.get("allPrepWeight") != null && jsonSpec.get("allPrepWeight") != "")
     388            {
     389              allPrepWeight = Values.getFloat((String)jsonSpec.get("allPrepWeight"));
     390            }
     391           
     392            String operatorComment = Values.getStringOrNull((String)jsonSpec.get("operatorComment"));
     393           
     394            Reggie.setAnnotationValue(specimen, nofDeliveredTubesType, nofTubes);
     395            if (arrivalDate != null) Reggie.setAnnotationValue(specimen, arrivalDateType, arrivalDate);
     396            if (partitionDate != null) Reggie.setAnnotationValue(specimen, partitionDateType, partitionDate);
     397            if (laterality != null) Reggie.setAnnotationValue(specimen, lateralityType, laterality);
     398            if (samplingDate != null) Reggie.setAnnotationValue(specimen, samplingDateType, samplingDate);
     399            if (rnaLaterDate != null) Reggie.setAnnotationValue(specimen, rnaLaterDateType, rnaLaterDate);
     400            if (padCase != null) Reggie.setAnnotationValue(specimen, padType, padCase);
     401            if (pathNote != null) Reggie.setAnnotationValue(specimen, pathNoteType, pathNote);
     402           
     403            if (spWeight != null)
     404            {             
     405              System.out.println("sp: " + spWeight);
     406              Reggie.setAnnotationValue(specimen, spWeightType, spWeight.floatValue());
     407              originalQuantity = originalQuantity + spWeight * 1000;
     408            }
     409            if (allPrepWeight != null)
     410            {
     411              Reggie.setAnnotationValue(specimen, allPrepWeightType, allPrepWeight.floatValue());
     412              originalQuantity = originalQuantity + allPrepWeight.floatValue() * 1000;
     413            }
     414            if (hisWeight != null)
     415            {
     416              Reggie.setAnnotationValue(specimen, hisWeightType, hisWeight.floatValue());
     417              originalQuantity = originalQuantity + hisWeight.floatValue() * 1000;
     418            }
     419            if (operatorComment != null) Reggie.setAnnotationValue(specimen, operatorCommentType, operatorComment);           
     420            if (originalQuantity > 0) specimen.setOriginalQuantity(originalQuantity);
     421           
     422            // Set biowell if it is specified for this tube
     423            Number boxId = (Number)jsonSpec.get("boxId");
     424            String rowString = (String)jsonSpec.get("row");
     425            String columnString = (String)jsonSpec.get("column");
     426           
     427            if (boxId != null &&
     428                rowString != null && columnString != null)
     429            {
     430              WellCoordinateFormatter wcfRow = new WellCoordinateFormatter(true);
     431              Integer rowIndex = wcfRow.parseString(rowString)-1;
     432              Integer columnIndex = Integer.parseInt(columnString)-1;             
     433              BioPlate plate = BioPlate.getById(dc, boxId.intValue());             
     434              BioWell well = plate.getBioWell(rowIndex, columnIndex);
     435              if (well != null)
     436              {
     437                specimen.setBioWell(well);
     438              }
     439            }           
     440            jsonMessages.add("Specimen tube '" + specimen.getName() + "' created successfully.");
     441          }
     442        }
     443               
    261444        dc.commit();
    262445        json.put("messages", jsonMessages);
Note: See TracChangeset for help on using the changeset viewer.