Changeset 1406


Ignore:
Timestamp:
Oct 17, 2011, 4:45:52 PM (10 years ago)
Author:
Martin Svensson
Message:

References #330 The partition registration wizard is almost finished. Known issues are: not enough validation of data, no 'move forward on enter' in the fields and perhaps more

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

Legend:

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

    r1403 r1406  
    6262}
    6363
     64function step3IsValid()
     65{
     66  for (var i=0; i<spWeightsAreValid.length; i++)
     67  {
     68    if (spWeightsAreValid[i] == false ||
     69        apWeightsAreValid[i] == false ||
     70        hisWeightsAreValid[i] == false ||
     71        nofPiecesAreValid[i] == false)
     72    {
     73      return false;
     74    }
     75  }
     76  return true;
     77}
     78
    6479function gotoStep2()
    6580{
     
    91106  frm.partitionComment.disabled = true;
    92107 
    93   var tubes = caseSpecimenTubes.specimen;
     108  var tubes = caseInfo.specimen;
    94109  var inputWeightHtml;
    95110  if (tubes.length > 0)
     
    100115    nofPiecesAreValid = Array(tubes.lenth);
    101116   
     117   
    102118    inputWeightHtml = '';
     119    inputWeightHtml +='<tr>';
     120    inputWeightHtml += '<td class="prompt">Specimen tube</td>';
     121    inputWeightHtml += '<td><table class="prompt" style=width:90% class="input"><tr><td style=width:25%>Sp</td><td style=width:25%>Ap</td><td style=width:25%>His</td><td style=width:25%>NofPieces</td></tr></table></td>';
     122    inputWeightHtml += '<td>&nbsp;</td><td>&nbsp;</td>';
     123    inputWeightHtml +='</tr>';
    103124    for (var i=0;i<tubes.length; i++)
    104125    {
     126      spWeightsAreValid[i] = true;
     127      apWeightsAreValid[i] = true;
     128      hisWeightsAreValid[i] = true;
     129      nofPiecesAreValid[i] = true;
     130     
    105131      spInputTitle = '';
    106132      apInputTitle = '';
    107133      hisInputTitle = '';
    108134      nofPiecesTitle = '';
    109       if (i==0)
    110       {
    111         spInputTitle = 'Sp<br>';
    112         apInputTitle = 'Ap<br>';
    113         hisInputTitle = 'His<br>';
    114         nofPiecesTitle = 'NofPieces<br>';
    115       }
     135     
     136      var doOnTab = i==(tubes.length-1) ? 'doOnTab(event, goCreate)' : '';
    116137      inputWeightHtml += '<tr>';
    117       inputWeightHtml += '<td class="prompt">Specimen tube '+caseSpecimenTubes.name+'.'+(i+1)+'</td>';
     138      inputWeightHtml += '<td class="subprompt">'+caseInfo.name+'.'+(i+1)+' ['+tubes[i].box+'&nbsp;'+tubes[i].row+tubes[i].column+']</td>';
    118139      inputWeightHtml += '<td class="input">';
    119       inputWeightHtml += '<table>';     
     140      inputWeightHtml += '<table style=width:90%>';     
    120141      inputWeightHtml += '<tr>';
    121       inputWeightHtml += '<td>' + spInputTitle + '<input size=4 type="text" onChange="spWeightOnChange('+i+')" name="spWeight'+i+'" /></td>';
    122       inputWeightHtml += '<td>' + apInputTitle + '<input size=4 type="text" onChange="apWeightOnChange('+i+')" name="apWeight'+i+'" /></td>';
    123       inputWeightHtml += '<td>' + hisInputTitle + '<input size=4 type="text" onChange="hisWeightOnChange('+i+')" name="hisWeight'+i+'" /></td>';
    124       inputWeightHtml += '<td>' + nofPiecesTitle + '<input size=4 type="text" onChange="nofPiecesOnChange('+i+')" name="nofPieces'+i+'" /></td>';
     142      inputWeightHtml += '<td>' + spInputTitle + '<input size=3 type="text" onChange="spWeightOnChange('+i+')" name="spWeight'+i+'" /></td>';
     143      inputWeightHtml += '<td>' + apInputTitle + '<input size=3 type="text" onChange="apWeightOnChange('+i+')" name="apWeight'+i+'" /></td>';
     144      inputWeightHtml += '<td>' + hisInputTitle + '<input size=3 type="text" onChange="hisWeightOnChange('+i+')" name="hisWeight'+i+'" /></td>';
     145      inputWeightHtml += '<td>' + nofPiecesTitle + '<input size=3 type="text" onkeypress="'+doOnTab+'" onChange="nofPiecesOnChange('+i+')" name="nofPieces'+i+'" /></td>';
    125146      inputWeightHtml += '</tr>';
    126147      inputWeightHtml += '</table>';
     
    130151      inputWeightHtml += '<span id="weight'+i+'.message" class="message" style="display:none;"></span>';
    131152      inputWeightHtml += 'Weights should be given in [mg]</td>';
    132       inputWeightHtml += '</tr>';
    133      
     153      inputWeightHtml += '</tr>';     
    134154    }   
    135155    setInnerHTML('weightInputs', inputWeightHtml);
     
    282302  else
    283303  {
    284     setInputStatus('partitionDate', 'Missing', 'warning');
     304    setInputStatus('partitionDate', 'Missing', 'invalid');
     305    return;
    285306  }
    286307  partitionDateIsValid = true;
     
    305326    return false;
    306327  }
    307   caseSpecimenTubes = response.caseInfo;
     328  caseInfo = response.caseInfo;
     329}
     330
     331function goCreate()
     332{
     333  if (!step3IsValid()) return;
     334 
     335  Main.hide('gocancel');
     336  Main.hide('gocreate');
     337  var frm = document.forms['reggie'];
     338 
     339  var specimens = caseInfo.specimen;
     340  var nofTubes = specimens.length;
     341  var partitionDateValue = frm.elements['partitionDate'].value;
     342  var partitionCommentValue = frm.elements['partitionComment'].value;
     343  caseInfo.partitionDate = partitionDateValue;
     344  if (partitionCommentValue != null) caseInfo.partitionComment = partitionCommentValue;
     345 
     346  for (var i=0; i<nofTubes; i++)
     347  {
     348    frm.elements['spWeight'+i].disabled = true;
     349    frm.elements['apWeight'+i].disabled = true;
     350    frm.elements['hisWeight'+i].disabled = true;
     351    frm.elements['nofPieces'+i].disabled = true;
     352   
     353    var specimenTube = specimens[i];
     354   
     355    var spWeightValue = frm.elements['spWeight'+i].value;
     356    if (spWeightValue != '') specimenTube.spWeight = spWeightValue;
     357    var apWeightValue = frm.elements['apWeight'+i].value;
     358    if (apWeightValue != '') specimenTube.apWeight = apWeightValue;
     359    var hisWeightValue = frm.elements['hisWeight'+i].value;
     360    if (hisWeightValue != '') specimenTube.hisWeight = hisWeightValue;
     361    var nofPiecesValue = frm.elements['nofPieces'+i].value;
     362    if (nofPiecesValue != '') specimenTube.nofPieces = nofPiecesValue;
     363   
     364    caseInfo.specimen[i] = specimenTube;   
     365  }
     366  var submitInfo = new Object();
     367  submitInfo.caseInfo = caseInfo;
     368 
     369  if (debug) Main.debug(JSON.stringify(caseInfo));
     370 
     371  var request = Ajax.getXmlHttpRequest();
     372  var url = 'PartitionRegistration.servlet?ID=<%=ID%>&cmd=CreatePartitions';
     373  request.open("POST", url, false);
     374  request.setRequestHeader("Content-Type", "application/json");
     375  request.send(JSON.stringify(submitInfo));
     376
     377  if (debug) Main.debug(request.responseText);
     378
     379  var response = JSON.parse(request.responseText);
     380  if (response.status != 'ok')
     381  {
     382    setFatalError(response.message);
     383    return false;
     384  }
     385
     386  var msg = '<ul>';
     387  for (var i = 0; i < response.messages.length; i++)
     388  {
     389    msg += '<li>' + response.messages[i];
     390  }
     391  msg += '</ul>';
     392  setInnerHTML('done', msg);
     393 
     394 
     395  Main.show('done');
     396  Main.show('gorestart');
    308397}
    309398</script>
     
    366455          <td class="prompt">Partition date</td>
    367456          <td class="input"><input type="text" name="partitionDate"
    368             size="12" maxlength="10" onBlur="partitionDateOnBlur()"></td>
     457             onkeypress="focusOnEnter(event, 'partitionComment')" size="12" maxlength="10" onBlur="partitionDateOnBlur()"></td>
    369458          <td class="status" id="partitionDate.status"></td>
    370459          <td class="help"><span id="partitionDate.message" class="message" style="display: none;"></span>The date when the partition was done.</td>
  • extensions/net.sf.basedb.reggie/trunk/resources/specimentube.jsp

    r1400 r1406  
    354354    inputTubeHtml += '</tr>';
    355355
    356     var box = 'box'+i;   
     356    var box = 'box'+i; 
     357    var row = 'row'+i;
     358    var column = 'column'+i;
     359    var operatorComment = 'operatorComment'+i;
    357360    inputTubeHtml += '<tr>';
    358361    inputTubeHtml += '<td class="subprompt">Box</td>';
    359362    inputTubeHtml += '<td class="input">';
    360     inputTubeHtml += '<input type="text" name='+box+' value="' + boxValue + '" '+ boxDisabled +' size="12" maxlength="12" onKeyUp="boxOnKeyUp('+i+')" onBlur="boxOnChange('+i+')"></td>';
     363    inputTubeHtml += '<input type="text" onkeypress="focusOnEnter(event, \''+row+'\')" name='+box+' value="' + boxValue + '" '+ boxDisabled +' size="12" maxlength="12" onKeyUp="boxOnKeyUp('+i+')" onBlur="boxOnChange('+i+')"></td>';
    361364    inputTubeHtml += '<td class="status" id="'+box+'.status"></td>';
    362365    inputTubeHtml += '<td class="help"><span id="'+box+'.message" class="message" style="display: none;"></span>Box-number where the specimen tube is located in.</td>';   
    363366    inputTubeHtml += '</tr>';       
    364 
    365     var row = 'row'+i;
    366     var column = 'column'+i;
     367   
    367368    var wellDisabled = rowValue != '' || boxValue == '' ? 'disabled' : '';
    368369    inputTubeHtml += '<tr>';
    369370    inputTubeHtml += '<td class="subprompt">Row</td>';
    370     inputTubeHtml += '<td class="input"><input style="text-transform:uppercase;" type="text" onKeyPress="" name='+row+' value="' + rowValue + '" size="3" maxlength="2" ' + wellDisabled;
     371    inputTubeHtml += '<td class="input"><input style="text-transform:uppercase;" type="text"  onkeypress="focusOnEnter(event, \''+column+'\')" name='+row+' value="' + rowValue + '" size="3" maxlength="2" ' + wellDisabled;
    371372    inputTubeHtml += ' onBlur="wellOnChange('+i+')">';
    372     inputTubeHtml += '&nbsp;Column<input type="text" name='+column+' value="'+ columnValue + '" size="3" maxlength="3" ' + wellDisabled;
     373    inputTubeHtml += '&nbsp;Column<input type="text" onkeypress="focusOnEnter(event, \''+operatorComment+'\')" name='+column+' value="'+ columnValue + '" size="3" maxlength="3" ' + wellDisabled;
    373374    inputTubeHtml += ' onBlur="wellOnChange('+i+')">';
    374375    inputTubeHtml += '&nbsp;<a href="javascript:suggestWellOnClick('+i+')" disabled>Suggest</a>'
     
    378379    inputTubeHtml += '</tr>';
    379380
    380     var operatorComment = 'operatorComment'+i;
    381381    var doOnTab = i==(nofTubes-1) ? 'doOnTab(event, goCreate)' : '';
    382382    inputTubeHtml += '<tr>';
     
    10571057      <td class="prompt">Number of tubes</td>
    10581058      <td class="input"><input type="text" name="nofTubes"
    1059         value="" size="12" maxlength="10" onblur='nofTubesOnChange()'></td>
     1059        onkeypress="focusOnEnter(event, 'arrivalDate')" value="1" size="12" maxlength="10" onblur='nofTubesOnChange()'></td>
    10601060      <td class="status" id="nofTubes.status"></td>
    10611061      <td class="help"><span id="nofTubes.message" class="message" style="display:none"></span>Number of tubes in this case.</td>
     
    10641064      <td class="prompt">Arrival date</td>
    10651065      <td class="input"><input type="text" name="arrivalDate"
    1066         value="" size="12" maxlength="10" onblur="arrivalDateOnBlur()"></td>
     1066        onkeypress="focusOnEnter(event, 'pad')" value="" size="12" maxlength="10" onblur="arrivalDateOnBlur()"></td>
    10671067      <td class="status" id="arrivalDate.status"></td>
    10681068      <td class="help"><span id="arrivalDate.message" class="message" style="display:none"></span>Date when the specimen tubes arrived(YYYYMMDD or MMDD).</td>
     
    10721072      <td class="input"><input type="text" name="pad"
    10731073        value="" size="12" maxlength="10"
    1074         onblur="padOnChange()"></td>
     1074        onkeypress="focusOnEnter(event, 'samplingDate')" onblur="padOnChange()"></td>
    10751075      <td class="status" id="pad.status"></td>
    10761076      <td class="help"><span id="pad.message" class="message" style="display: none;"></span></td>
     
    10901090          onkeypress="focusOnEnter(event, 'rnaLaterTime')" onblur="rnaLaterDateTimeOnChange()">
    10911091        Time <input type="text" name="rnaLaterTime" value="" size="6" maxlength="4"
    1092           onblur="rnaLaterDateTimeOnChange()"></td>
     1092          onkeypress="focusOnEnter(event, 'specimenType')" onblur="rnaLaterDateTimeOnChange()"></td>
    10931093      <td class="status" id="rnaLaterDate.status"></td>
    10941094      <td class="help"><span id="rnaLaterDate.message" class="message" style="display: none;"></span>Date+time of pathology handling (YYYYMMDD, HHMM or MMDD, HMM)</td>
     
    11071107      <td class="prompt" id="specimenType.prompt">Speciment type</td>
    11081108      <td class="input" id="specimenType.input">
    1109         <select name="specimenType" onChange="specimenTypeOnClick()">
    1110           <option selected value="Primary">Primary
     1109        <select onkeypress="focusOnEnter(event, 'biopsyType')"
     1110          name="specimenType" onChange="specimenTypeOnClick()"
     1111        >
     1112          <option selected value="" >unknown
     1113          <option value="Primary">Primary
    11111114          <option value="LymfnodeRegional">LymfnodeRegional         
    11121115          <option value="MetastasisDistant">MetastasisDistant
    11131116          <option value="RecurrenceLocal">RecurrenceLocal
    1114           <option value="RecurrenceRegional">RecurrenceRegional
    1115           <option value="" >unknown
     1117          <option value="RecurrenceRegional">RecurrenceRegional         
    11161118        </select>
    11171119      </td>
     
    11221124      <td class="prompt" id="biopsyType.prompt">Biopsy type</td>
    11231125      <td class="input" id="biopsyType.input">
    1124         <select name="biopsyType" onChange="biopsyTypeOnClick()">
     1126        <select onkeypress="focusOnEnter(event, 'otherPathNote')"
     1127          name="biopsyType" onChange="biopsyTypeOnClick()"
     1128        >
     1129          <option selected value="" >unknown
    11251130          <option value="SpecimenSurgery">SpecimenSurgery
    11261131          <option value="SpecimenCoreBiopsy">SpecimenCoreBiopsy
    1127           <option value="SpecimenFineNeedleAspiration" >SpecimenFineNeedleAspiration       
    1128           <option value="" >unknown
     1132          <option value="SpecimenFineNeedleAspiration" >SpecimenFineNeedleAspiration
    11291133        </select>
    11301134      </td>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/Reggie.java

    r1402 r1406  
    167167 
    168168  /**
     169    The name of the "Other partition comment" annotation type, used
     170    for samples(Specimen tube). It s a String annotation type.   
     171  */
     172  public static final String ANNOTATION_OTHER_PARTITION_COMMENT = "OtherPartitionComment";
     173 
     174  /**
     175    The name of the "Partition date" annotation type, used for
     176    samples(His-sample). It is a date annotation type.
     177   */
     178  public static final String ANNOTATION_SAMPLE_PARTITION_DATE = "SamplePartitionDate";
     179 
     180  /**
     181    The name of the "Partition date" annotation type, used for
     182    extracts(Lys-extract). It is a date annotation type.
     183   */
     184  public static final String ANNOTATION_EXTRACT_PARTITION_DATE = "ExtractPartitionDate";
     185 
     186  /**
    169187    List all groups with the given name.
    170188  */
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/SpecimenTube.java

    r1380 r1406  
    44import java.util.List;
    55
    6 import org.json.simple.JSONObject;
    7 
    8 import net.sf.basedb.core.BioPlate;
    96import net.sf.basedb.core.BioWell;
    107import net.sf.basedb.core.DbControl;
     
    1916import net.sf.basedb.core.query.Restrictions;
    2017import net.sf.basedb.util.formatter.WellCoordinateFormatter;
     18
     19import org.json.simple.JSONObject;
    2120
    2221/**
     
    101100  private final String row;
    102101  private final String column;
     102  private final Float originalQuantity;
    103103 
    104104  private SpecimenTube(Sample sample)
     
    113113      row = wcfRow.format(well.getRow());     
    114114      column = wcfColumn.format(well.getColumn());
     115      originalQuantity = sample.getOriginalQuantity();
    115116    }
    116117    else
     
    119120      row = null;
    120121      column = null;
     122      originalQuantity = null;
    121123    }
    122124  }
     
    155157  }
    156158 
     159  public Float getOriginalQuantity()
     160  {
     161    return originalQuantity;
     162  }
     163 
    157164  @SuppressWarnings("unchecked")
    158165  @Override
     
    162169    json.put("row", row);
    163170    json.put("column", column);
     171    json.put("originalQuantity", originalQuantity);
    164172  }
    165173}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/InstallServlet.java

    r1403 r1406  
    141141        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_NOF_PIECES, Item.SAMPLE, Type.INT, 1,
    142142            null, effectiveOptions, createIfMissing));
     143        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_OTHER_PARTITION_COMMENT, Item.SAMPLE, Type.STRING, 1,
     144            null, effectiveOptions, createIfMissing));
     145        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_SAMPLE_PARTITION_DATE, Item.SAMPLE, Type.DATE, 1,
     146            null, effectiveOptions, createIfMissing));
     147        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_EXTRACT_PARTITION_DATE, Item.EXTRACT, Type.DATE, 1,
     148            null, effectiveOptions, createIfMissing));
    143149               
    144150        json.put("checks", jsonChecks);
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/PartitionRegistrationServlet.java

    r1403 r1406  
    33import java.io.IOException;
    44import java.text.SimpleDateFormat;
     5import java.util.ArrayList;
     6import java.util.Date;
    57import java.util.List;
    68
     
    1214import net.sf.basedb.core.AnnotationType;
    1315import net.sf.basedb.core.Application;
     16import net.sf.basedb.core.BioMaterialEvent;
     17import net.sf.basedb.core.BioPlate;
     18import net.sf.basedb.core.BioWell;
    1419import net.sf.basedb.core.DbControl;
     20import net.sf.basedb.core.Extract;
    1521import net.sf.basedb.core.InvalidDataException;
    1622import net.sf.basedb.core.Item;
     23import net.sf.basedb.core.ItemQuery;
     24import net.sf.basedb.core.Sample;
    1725import net.sf.basedb.core.SessionControl;
     26import net.sf.basedb.core.query.Expressions;
     27import net.sf.basedb.core.query.Hql;
     28import net.sf.basedb.core.query.Restrictions;
    1829import net.sf.basedb.reggie.Reggie;
    19 import net.sf.basedb.reggie.converter.DateToStringConverter;
     30import net.sf.basedb.reggie.converter.StringToDateConverter;
    2031import net.sf.basedb.reggie.dao.Case;
    2132import net.sf.basedb.reggie.dao.SpecimenTube;
     33import net.sf.basedb.util.Values;
    2234import net.sf.basedb.util.error.ThrowableUtil;
    2335
    2436import org.json.simple.JSONArray;
    2537import org.json.simple.JSONObject;
     38import org.json.simple.parser.JSONParser;
    2639
    2740public class PartitionRegistrationServlet
     
    4659    resp.setCharacterEncoding("UTF-8");
    4760   
    48     JSONObject json = new JSONObject();
     61    JSONObject json = new JSONObject();   
    4962    json.put("status", "ok");
    5063   
     
    8396       
    8497        for (SpecimenTube tube : specimenTubes)
    85         {         
    86           jsonTubes.add(tube.asJSONObject());
     98        {
     99          if (tube.getOriginalQuantity() != null)
     100          {
     101            throw new InvalidDataException("Original quantity exists. Partition has already been done.");
     102          }
     103          jsonTubes.add(tube.asJSONObject());         
    87104        }       
    88105        jsonCase.put("specimen", jsonTubes);       
    89106        json.put("caseInfo", jsonCase);
    90107      }
     108     
     109     
    91110    }
    92111    catch (Throwable t)
     
    110129    throws ServletException, IOException
    111130  {
    112    
     131    String ID = req.getParameter("ID");
     132    String cmd = req.getParameter("cmd");
     133    resp.setContentType("application/json");
     134    resp.setCharacterEncoding("UTF-8");
     135   
     136    JSONObject json = new JSONObject();
     137    JSONArray jsonMessages = new JSONArray();
     138    json.put("status", "ok");
     139   
     140    final SessionControl sc = Application.getSessionControl(ID, req.getRemoteAddr());
     141    DbControl dc = null;
     142     
     143    try
     144    {
     145      if ("CreatePartitions".equals(cmd))
     146      {
     147        dc = sc.newDbControl();
     148        JSONObject jsonReq = (JSONObject)new JSONParser().parse(req.getReader());       
     149        JSONObject jsonCase = (JSONObject)jsonReq.get("caseInfo");       
     150        JSONArray jsonSpecimens = (JSONArray)jsonCase.get("specimen");
     151       
     152        AnnotationType samplePartitionDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SAMPLE_PARTITION_DATE, true);
     153        AnnotationType extractPartitionDateType = Reggie.findAnnotationType(dc, Item.EXTRACT, Reggie.ANNOTATION_EXTRACT_PARTITION_DATE, true);
     154        AnnotationType partitionCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OTHER_PARTITION_COMMENT, true);
     155        AnnotationType nofPiecesType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_NOF_PIECES, true);
     156       
     157        StringToDateConverter dateConverter = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd"));
     158        String otherPartitionComment = Values.getStringOrNull((String)jsonCase.get("otherPartitionComment"));
     159        Date partitionDate = dateConverter.convert((String)jsonCase.get("partitionDate"));
     160       
     161        if (jsonSpecimens != null && jsonSpecimens.size()>0)
     162        {
     163          for (int i=0; i<jsonSpecimens.size(); i++)
     164          {
     165            List<String> subMessages = new ArrayList<String>();
     166           
     167            Float originalQuantity = new Float(0);
     168            JSONObject jsonSpecimen = (JSONObject)jsonSpecimens.get(i);
     169            Number specimenId = (Number)jsonSpecimen.get("id");
     170            Sample specimen = Sample.getById(dc, specimenId.intValue());
     171            Sample hisSample = null;
     172           
     173            BioWell specimenWell = specimen.getBioWell();
     174            String specimenBoxName = null;
     175            if (specimenWell != null) specimenBoxName = specimenWell.getPlate().getName();
     176                       
     177            Float spWeight = Values.getFloat((String)jsonSpecimen.get("spWeight"), null)*1000;
     178            Float apWeight = Values.getFloat((String)jsonSpecimen.get("apWeight"), null)*1000;
     179            Float hisWeight = Values.getFloat((String)jsonSpecimen.get("hisWeight"), null)*1000;           
     180            Integer nofPieces = Values.getInteger((String)jsonSpecimen.get("nofPieces"), null);           
     181           
     182            Reggie.setAnnotationValue(specimen, samplePartitionDateType, partitionDate);
     183            if (nofPieces != null) Reggie.setAnnotationValue(specimen, nofPiecesType, nofPieces);           
     184            if (otherPartitionComment != null) Reggie.setAnnotationValue(specimen, partitionCommentType, otherPartitionComment);           
     185            if (spWeight != null) originalQuantity = originalQuantity + spWeight;
     186           
     187            // Create lys-extract
     188            if (apWeight != null)
     189            {
     190              originalQuantity = originalQuantity + apWeight;
     191              if (apWeight > 0)
     192              {
     193                Extract lysExtract = specimen.newExtract(apWeight);
     194                lysExtract.setName(specimen.getName()+".l");
     195                dc.saveItem(lysExtract);
     196               
     197                Reggie.setAnnotationValue(lysExtract, extractPartitionDateType, partitionDate);
     198               
     199                // Set box position
     200                if (specimenBoxName != null)
     201                {
     202                  String lysBoxName = "Lys"+specimenBoxName.substring(2);
     203                  ItemQuery<BioPlate> lysBoxQuery = BioPlate.getQuery();
     204                  lysBoxQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(lysBoxName)));
     205                  List<BioPlate> lysBoxes = lysBoxQuery.list(dc);
     206                  if (lysBoxes.size()<1)
     207                  {
     208                    throw new InvalidDataException("No lys-box was found with name: "+lysBoxName+". " +
     209                        "This wizard can not be used until this is fixed.");
     210                  }
     211                  else if (lysBoxes.size() > 1)
     212                  {
     213                    throw new InvalidDataException("More then one lys-box were found with name: "+lysBoxName+". " +
     214                        "This wizard can not be used until this is fixed.");
     215                  }
     216                 
     217                  BioPlate lysBox = lysBoxes.get(0);
     218                  if (!lysBox.getBioWell(specimenWell.getRow(), specimenWell.getColumn()).isEmpty())
     219                  {
     220                    throw new InvalidDataException("Position [" + specimenWell.getRow() + "," + specimenWell.getColumn() + "]" +
     221                        " is not empty in box: " + lysBoxName);
     222                  }
     223                  lysExtract.setBioWell(lysBox.getBioWell(specimenWell.getRow(), specimenWell.getColumn()));                 
     224                }               
     225                subMessages.add("--Lysate "+specimen.getName()+".l created successfully");
     226              }
     227            }
     228           
     229            // Create his-sample
     230            if (hisWeight != null)
     231            {
     232              originalQuantity = originalQuantity + hisWeight;
     233              if (hisWeight > 0)
     234              {
     235                hisSample = Sample.getNew(dc);
     236                hisSample.setName(specimen.getName() + ".his");
     237                dc.saveItem(hisSample);
     238               
     239                hisSample.setPooled(true);
     240                BioMaterialEvent creationEvent = hisSample.getCreationEvent();
     241                creationEvent.addSource(specimen, hisWeight);
     242               
     243                // Set box position
     244                if (specimenBoxName != null)
     245                {
     246                  String hisBoxName = "His" + specimenBoxName.substring(2);               
     247                  ItemQuery<BioPlate> hisBoxQuery = BioPlate.getQuery();
     248                  hisBoxQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(hisBoxName)));
     249                  List<BioPlate> hisBoxes = hisBoxQuery.list(dc);
     250                  if (hisBoxes.size()>1)
     251                  {
     252                    throw new InvalidDataException("More then one his-box were found with name: "+hisBoxName+". " +
     253                        "This wizard can not be used until this is fixed.");
     254                  }
     255                  else if (hisBoxes.size()<1)
     256                  {
     257                    throw new InvalidDataException("No his-box was found with name: "+hisBoxName+". " +
     258                        "This wizard can not be used until this is fixed.");
     259                  }
     260                  BioPlate hisBox = hisBoxes.get(0);
     261                  if (!hisBox.getBioWell(specimenWell.getRow(), specimenWell.getColumn()).isEmpty())
     262                  {
     263                    throw new InvalidDataException("Position [" + specimenWell.getRow() + "," + specimenWell.getColumn() + "]" +
     264                        " is not empty in box: " + hisBoxName);
     265                  }
     266                  hisSample.setBioWell(hisBox.getBioWell(specimenWell.getRow(), specimenWell.getColumn()));                 
     267                }
     268                subMessages.add("--His sample "+specimen.getName() + ".his created successfully");
     269              }
     270            }
     271           
     272            specimen.setOriginalQuantity(originalQuantity);
     273           
     274            jsonMessages.add("Specimen tube " + specimen.getName() + " partitioned successfully");
     275            for(String m : subMessages)
     276            {
     277              jsonMessages.add(m);
     278            }
     279          }
     280        }
     281        dc.commit();
     282      }
     283      json.put("messages", jsonMessages);
     284    }
     285    catch (Throwable t)
     286    {
     287      t.printStackTrace();
     288      json.clear();
     289      json.put("status", "error");
     290      json.put("message", t.getMessage());
     291      json.put("stacktrace", ThrowableUtil.stackTraceToString(t));     
     292    }
     293    finally
     294    {
     295      if (dc != null) dc.close();
     296      json.writeJSONString(resp.getWriter());
     297    }
    113298  }
    114299}
Note: See TracChangeset for help on using the changeset viewer.