Changeset 1400


Ignore:
Timestamp:
Oct 10, 2011, 3:51:24 PM (12 years ago)
Author:
Martin Svensson
Message:

References #317. Updated the functionality when selecting box and position to store the specimen tube in. Reggie now remember the box that was used the time before and it also suggest which position to choose depending on free positions in the corresponding lys-box. Operator comment field was renamed to Operator delivery comment.

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

Legend:

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

    r1397 r1400  
    33  session="false"
    44  import="net.sf.basedb.core.User"
    5   import="net.sf.basedb.core.DbControl"
     5  import="net.sf.basedb.core.BioPlate"
     6  import="net.sf.basedb.core.DbControl"
     7  import="net.sf.basedb.core.Item"
     8  import="net.sf.basedb.core.ItemContext"
    69  import="net.sf.basedb.core.SessionControl"
    710  import="net.sf.basedb.clients.web.Base"
     11  import="net.sf.basedb.util.Values"
     12  import="java.util.List"
    813%>
    914<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    1823  dc = sc.newDbControl();
    1924  final User user = User.getById(dc, sc.getLoggedInUserId());
     25  final ItemContext cc = Base.getAndSetCurrentContext(sc, Item.SAMPLE, null, null);
     26  final List<BioPlate> recentBoxes = (List<BioPlate>)cc.getRecent(dc, Item.BIOPLATE, "reggie_specimentube");
     27  BioPlate recentBox = null;
     28  String recentBoxName = ""; 
     29  if (recentBoxes.size() > 0)
     30  {
     31    recentBox = recentBoxes.get(0);
     32    int lastRow = recentBox.getRows()-1;
     33    int lastColumn = recentBox.getColumns()-1;
     34    // Move on to next box in order if the last position isn't empty.
     35    if (!recentBox.getBioWell(lastRow, lastColumn).isEmpty())
     36    {
     37      Integer currentBoxNumber = Values.getInteger(recentBox.getName().substring(2), null);
     38      if (currentBoxNumber != null)
     39      {
     40        currentBoxNumber++;
     41        String nameString = ""+currentBoxNumber;       
     42        while(nameString.length() < 3)
     43        {
     44          nameString = "0"+nameString;
     45        }
     46        recentBoxName = "Sp"+nameString;       
     47      }     
     48    }
     49    else
     50    {
     51      recentBoxName = recentBox.getName();
     52    }
     53  }
    2054%>
    2155<base:page type="default" >
     
    2761<script language="JavaScript">
    2862var caseIsValid = false;
    29 var arrivalDateIsValid = false;
    30 var nofDeliveredTubesIsValid = true;
     63var arrivalDateIsValid = true;
    3164var nofTubesIsValid = false;
    3265var lateralityIsValid = false;
     
    3467var wellsAreValidValid = null;
    3568var specimenTypeIsValid = false;
     69var samplingDateIsValid = true;
     70var rnaLaterDateIsValid = true;
    3671var debug = false;
    3772var currentStep = 1;
     
    6499{
    65100  var frm = document.forms['reggie'];
    66   if (!nofTubesIsValid) frm.nofTubes.focus();
    67   else if (lateralityIsValid) return true;
     101  if (!nofTubesIsValid)
     102  {
     103    frm.nofTubes.focus();
     104    return false;
     105  }
     106  if (!arrivalDateIsValid)
     107  {
     108    frm.arrivalDate.focus();
     109    return false;
     110  }
     111  if (!samplingDateIsValid)
     112  {
     113    frm.samplingDate.focus();
     114    return false;
     115  }
     116  if (!rnaLaterDateIsValid)
     117  {
     118    frm.rnaLaterDate.focus();
     119    return false;
     120  }
     121  if (!lateralityIsValid) return false;
     122  return true;
    68123}
    69124
     
    147202      if (specimen.samplingDate && !thisCaseSamplingDate)
    148203      {
    149         thisCaseSamplingDate = specimen.samplingDate;         
     204        thisCaseSamplingDate = specimen.samplingDate;
    150205      }
    151206      if (specimen.rnaLaterDate && !thisCaseRNALaterDate)
     
    267322  frm.samplingTime.disabled = true;
    268323  frm.otherPathNote.disabled = true;
     324  frm.specimenType.disabled = true;
     325  frm.biopsyType.disabled = true;
    269326 
    270327  if (updateMode)
     
    276333  {
    277334    var specimen = null;
    278     var boxValue = '';
     335    var boxValue = '<%=recentBoxName %>';
    279336    var rowValue = '';
    280337    var columnValue = '';
     
    283340    var allPrepWeightValue = '';
    284341
    285     boxInfo[i] = null; 
     342    boxInfo[i] = null;
     343    var boxDisabled = '';
    286344    if (caseInfo.specimen && caseInfo.specimen.length>0 && i<caseInfo.specimen.length)
    287345    {
     346      boxDisabled = 'disabled';
    288347      specimen = caseInfo.specimen[i];
    289348      boxValue = specimen.box == null ? '' : specimen.box;
     
    295354    inputTubeHtml += '</tr>';
    296355
    297     var box = 'box'+i;
    298     var boxDisabled = boxValue == '' ? '' : 'disabled';
     356    var box = 'box'+i;   
    299357    inputTubeHtml += '<tr>';
    300358    inputTubeHtml += '<td class="subprompt">Box</td>';
    301359    inputTubeHtml += '<td class="input">';
    302     inputTubeHtml += '<input type="text" name='+box+' value="Sp' + boxValue + '" '+ boxDisabled +' size="12" maxlength="12" onKeyUp="boxOnKeyUp('+i+')" onChange="boxOnChange('+i+')"></td>';
     360    inputTubeHtml += '<input type="text" name='+box+' value="' + boxValue + '" '+ boxDisabled +' size="12" maxlength="12" onKeyUp="boxOnKeyUp('+i+')" onBlur="boxOnChange('+i+')"></td>';
    303361    inputTubeHtml += '<td class="status" id="'+box+'.status"></td>';
    304362    inputTubeHtml += '<td class="help"><span id="'+box+'.message" class="message" style="display: none;"></span>Box-number where the specimen tube is located in.</td>';   
     
    314372    inputTubeHtml += '&nbsp;Column<input type="text" name='+column+' value="'+ columnValue + '" size="3" maxlength="3" ' + wellDisabled;
    315373    inputTubeHtml += ' onBlur="wellOnChange('+i+')">';
     374    inputTubeHtml += '&nbsp;<a href="javascript:suggestWellOnClick('+i+')" disabled>Suggest</a>'
    316375    inputTubeHtml += '</td>';
    317376    inputTubeHtml += '<td class="status" id="rowColumn'+i+'.status"></td>';
     
    322381    var doOnTab = i==(nofTubes-1) ? 'doOnTab(event, goCreate)' : '';
    323382    inputTubeHtml += '<tr>';
    324     inputTubeHtml += '<td class="subprompt">Operator comment</td>';
     383    inputTubeHtml += '<td class="subprompt">Operator delivery comment</td>';
    325384    inputTubeHtml += '<td class="input"><textarea rows="3" cols="30" name='+operatorComment+' value="" onkeypress="'+doOnTab+'"></textarea></td>';
    326385    inputTubeHtml += '<td class="status" id="'+operatorComment+'.status"></td>';
     
    338397  else Main.show('gocreate');
    339398
    340   if (frm.box0.value == 'Sp') frm.box0.focus();
    341   else frm.operatorComment0.focus();
     399  var textLength = frm.box0.value.length;
     400  frm.box0.focus();
     401  frm.box0.setSelectionRange(textLength,textLength);
    342402}
    343403
     
    381441  }
    382442  samplingDateIsValid = true;
     443  rnaLaterDateTimeOnChange();
    383444}
    384445
     
    388449  var boxName = 'box'+tubeIndex;
    389450  var boxValue = frm.elements[boxName].value;
    390   if (boxValue.substring(0,2) != 'Sp')
     451  if (boxValue.length>0 && boxValue.substring(0,2) != 'Sp')
    391452  {
    392453    boxValue = 'Sp'+boxValue;
     
    409470    boxValue = '0'+boxValue;
    410471  }
    411   boxValue = 'Sp'+boxValue;
     472  if (boxValue.length > 0)
     473  {
     474    boxValue = 'Sp'+boxValue;
     475  }
    412476  frm.elements[boxName].value = boxValue;
    413477 
    414478  wellsAreValid[tubeIndex] = false;
    415479 
    416   if (frm.elements[boxName].value == 'Sp')
     480  if (frm.elements[boxName].value == 'Sp' || frm.elements[boxName].value == '')
    417481  {
    418482    boxesAreValid[tubeIndex] = true;
     
    430494  var url = 'SpecimenTubeRegistration.servlet?ID=<%=ID%>&cmd=GetBoxInfo';
    431495  url += '&boxName=' + boxValue; 
     496  url += '&nofTubes=' + nofTubes;
    432497  request.open("GET", url, false);
    433498  request.send(null);
     
    475540    }
    476541   
    477     nextWellRow = response.freeRow;
    478     nextWellColumn = parseInt(response.freeColumn)+1;   
    479     if( (nextWellColumn + tubeIndex) > response.columns)
    480     {
    481       nextWellColumn = 0;
    482       nextWellRow = '';
     542    if (response.freeRow != null && response.freeColumn != null)
     543    {
     544      nextWellRow = response.freeRow;
     545      nextWellColumn = parseInt(response.freeColumn)+1;   
     546     
     547      nextWellColumn = nextWellColumn + tubeIndex;
     548     
     549      if (frm.elements[rowName].value == '' &&
     550          frm.elements[columnName].value == '')
     551      {
     552        frm.elements[rowName].value = nextWellRow;   
     553        frm.elements[columnName].value = nextWellColumn;
     554      }
     555    }         
     556    setInputStatus('rowColumn'+tubeIndex,'Row[A-'+response.rows+'], Columns[1-'+response.columns+']','');
     557    if (response.message && "Warning:" == response.message.substring(0,8))
     558    {
     559      setInputStatus(boxName, response.message.substring(8), 'warning');
    483560    }
    484561    else
    485562    {
    486       nextWellColumn = nextWellColumn + tubeIndex;
    487     }   
    488    
    489     if (frm.elements[rowName].value == '' &&
    490         frm.elements[columnName].value == '')
    491     {
    492       frm.elements[rowName].value = nextWellRow;   
    493       frm.elements[columnName].value = nextWellColumn;
    494     }     
    495     setInputStatus('rowColumn'+tubeIndex,'Row[A-'+response.rows+'], Columns[1-'+response.columns+']','');
    496     setInputStatus(boxName, '', 'valid');   
     563      setInputStatus(boxName, '', 'valid');
     564    }       
    497565    frm.elements[rowName].focus();   
    498566  }   
     
    537605  if (response.message)
    538606  {
    539     wellsAreValid[tubeIndex] = false;
    540     setInputStatus('rowColumn'+tubeIndex, response.message, 'invalid')
    541     return false;
     607    if (response.message.length>8 && response.message.substring(0,8) == "Warning:")
     608    {
     609      setInputStatus('rowColumn'+tubeIndex, response.message.substring(8), 'warning');
     610    }
     611    else
     612    {
     613      wellsAreValid[tubeIndex] = false;
     614      setInputStatus('rowColumn'+tubeIndex, response.message, 'invalid')
     615      return false;
     616    }   
    542617  }
    543618  for (var i=0;i<nofTubes;i++)
     
    558633}
    559634
     635function suggestWellOnClick(tubeIndex)
     636{
     637  var frm = document.forms['reggie'];
     638  var boxName = 'box'+tubeIndex;
     639  var boxValue = frm.elements[boxName].value;
     640  var rowName = 'row'+tubeIndex;
     641  var columnName = 'column'+tubeIndex;
     642  var nextWellRow = '';
     643  var nextWellColumn = '';
     644  var nofTubes = frm.nofTubes.value;
     645 
     646  if (boxValue && boxValue != 'Sp')
     647  {
     648    var request = Ajax.getXmlHttpRequest();
     649    var url = 'SpecimenTubeRegistration.servlet?ID=<%=ID%>&cmd=GetBoxInfo';
     650    url += '&boxName=' + boxValue; 
     651    url += '&nofTubes=' + nofTubes;
     652    request.open("GET", url, false);
     653    request.send(null);
     654
     655    if (debug) Main.debug(request.responseText);
     656
     657    var response = JSON.parse(request.responseText);
     658    if (response.status != 'ok')
     659    {
     660      boxesAreValid[tubeIndex] = false;   
     661      setFatalError(response.message);
     662      return false;
     663    }
     664    if (response.boxInfo)
     665    {
     666      if (response.freeRow && response.freeColumn)
     667      {
     668        nextWellRow = response.freeRow;
     669        nextWellColumn = parseInt(response.freeColumn)+1;
     670        if( (nextWellColumn + tubeIndex) > response.columns)
     671        {
     672          nextWellColumn = 0;
     673          nextWellRow = '';
     674        }
     675        else
     676        {
     677          nextWellColumn = nextWellColumn + tubeIndex;
     678        }
     679        frm.elements[rowName].value = nextWellRow;   
     680        frm.elements[columnName].value = nextWellColumn;
     681      }     
     682    }
     683    wellOnChange(tubeIndex);
     684    frm.elements['operatorComment'+tubeIndex].focus();
     685  }
     686}
     687
    560688function rnaLaterDateTimeOnChange()
    561689{
     
    596724    if (samplingDateIsValid && rnaLaterTimestamp)
    597725    {
    598       var samplingTimestamp = Dates.parseString(frm.samplingDate.value + ' ' + frm.samplingTime.value, 'yyyyMMdd Hmm');
    599       if (samplingTimestamp && rnaLaterTimestamp.getDate() != samplingTimestamp.getDate())
    600       {
    601         setInputStatus('rnaLaterDate', 'Sampling and RNA later dates are different', 'warning');
    602         return;
     726      var samplingTimestamp = Dates.parseString(frm.samplingDate.value + ' ' + frm.samplingTime.value, 'yyyyMMdd Hmm');     
     727      if (samplingTimestamp)
     728      {
     729        if (rnaLaterTimestamp.getDate() == samplingTimestamp.getDate() && rnaLaterTimestamp.getTime()<samplingTimestamp.getTime())
     730        {
     731          setInputStatus('rnaLaterDate', 'RNA-later date+time must later then Sampling date+time','invalid');
     732          return;
     733        }
     734        if (rnaLaterTimestamp.getDate() != samplingTimestamp.getDate())
     735        {
     736          setInputStatus('rnaLaterDate', 'Sampling and RNA later dates are different', 'warning');
     737          return;
     738        }
    603739      }
     740     
    604741    }
    605742    setInputStatus('rnaLaterDate', '', 'valid');
     
    634771    }
    635772    setInputStatus('arrivalDate', '', 'valid');
    636     arrivalDateIsValid = true;   
    637773  }
    638774  else
     
    640776    setInputStatus('arrivalDate', 'Missing', 'warning');
    641777  }
     778  arrivalDateIsValid = true;
    642779}
    643780
     
    652789    return;
    653790  }
    654   if (nofTubes == '0')
     791  if (nofTubes < '1')
    655792  {
    656793    setInputStatus('nofTubes', 'Must be at least 1', 'invalid');
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/Reggie.java

    r1389 r1400  
    146146    for samples (Specimen tube). It is a String annotation type.
    147147  */
    148   public static final String ANNOTATION_OPERATOR_COMMENT = "OperatorComment";
     148  public static final String ANNOTATION_OPERATOR_DELIVERY_COMMENT = "OperatorDeliveryComment";
    149149 
    150150  /**
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SpecimenTubeServlet.java

    r1389 r1400  
    1818import net.sf.basedb.core.InvalidDataException;
    1919import net.sf.basedb.core.Item;
     20import net.sf.basedb.core.ItemContext;
    2021import net.sf.basedb.core.ItemQuery;
    2122import net.sf.basedb.core.Sample;
     
    4041public class SpecimenTubeServlet
    4142  extends HttpServlet
    42 {
    43 
    44  
     43{
    4544  private static final long serialVersionUID = -8107161732923753803L;
    4645
     
    105104        AnnotationType arrivalDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ARRIVAL_DATE, true);       
    106105        AnnotationType nofDeliveredTubesType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_NOF_DELIVERED_TUBES, true);
    107         AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_COMMENT, true);
     106        AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_DELIVERY_COMMENT, true);
    108107        AnnotationType pathNoteType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OTHER_PATH_NOTE, true);
    109108        AnnotationType specimenType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SPECIMEN_TYPE, true);
     
    134133        dc = sc.newDbControl();
    135134       
    136         String boxName = req.getParameter("boxName");
    137         ItemQuery<BioPlate> boxQuery = BioPlate.getQuery();
    138         boxQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(boxName)));
    139         List<BioPlate> boxes = boxQuery.list(dc);
    140        
    141         if (boxes.size() == 0)
    142         {
    143           json.put("message", "Box does not exist.");         
    144         }
    145         else if (boxes.size() > 1)
    146         {
    147           json.put("message", "More then one box were found.");
    148         }
    149         else
    150         {         
    151           BioPlate box = boxes.get(0);
     135        // Get spBox
     136        String boxName = req.getParameter("boxName");       
     137        Integer spaceReq = Values.getInt(req.getParameter("nofTubes"), 1);
     138        ItemQuery<BioPlate> spBoxQuery = BioPlate.getQuery();
     139        spBoxQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(boxName)));
     140        List<BioPlate> spBoxes = spBoxQuery.list(dc);
     141       
     142       
     143        // Looking for free place in the corresponding LYS-box
     144        String lysBoxName = "Lys"+boxName.substring(2);
     145        ItemQuery<BioPlate> lysBoxQuery = BioPlate.getQuery();
     146        lysBoxQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(lysBoxName)));
     147        List<BioPlate> lysBoxes = lysBoxQuery.list(dc);
     148        BioWell emptyWell = null;
     149       
     150        if (spBoxes.size() == 1)
     151        {
     152          BioPlate box = spBoxes.get(0);
     153          if (lysBoxes.size() == 0)
     154          {
     155            json.put("message", "Warning:There is no corresponding Lys-box for this Sp-box.");
     156          }
     157          else if (lysBoxes.size() > 1)
     158          {
     159            json.put("message", "Warning:More then one lys-box were found.");
     160          }
     161          else
     162          {
     163            // Search for empty position in corresponding lys-box.
     164            emptyWell = getFirstFreeWell(lysBoxes.get(0),spaceReq);
     165          }
     166         
     167          // No empty position were found in lys-box. Search for empty position in Sp-box.
     168          if (emptyWell == null)
     169          {
     170            emptyWell = getFirstFreeWell(box, spaceReq);
     171          }
     172          else
     173          {
     174            // else control that same position is free in Sp-box or look in Sp-box.
     175            if (!box.getBioWell(emptyWell.getRow(), emptyWell.getColumn()).isEmpty())
     176            {
     177              emptyWell = getFirstFreeWell(box, spaceReq);             
     178            }
     179          }
     180         
     181          if (emptyWell == null)
     182          {
     183            json.put("message", "Warning:An empty position can not be suggested.");
     184          }
     185         
    152186          WellCoordinateFormatter wcfRow = new WellCoordinateFormatter(true);
    153          
    154           int rowIndex = box.getRows()-1;
    155           boolean isLastEmpty = false;
    156           BioWell emptyWell = null;
    157           while (rowIndex >= 0 && !isLastEmpty)
    158           {
    159             int columnIndex = box.getColumns()-1;
    160             while (columnIndex >= 0 && !isLastEmpty)
    161             {
    162               if (box.getBioWell(rowIndex, columnIndex).isEmpty())
    163               {               
    164                 emptyWell = box.getBioWell(rowIndex, columnIndex);
    165               }
    166               else
    167               {
    168                 isLastEmpty = true;
    169               }
    170               columnIndex--;
    171             }
    172             rowIndex--;
    173           }
    174          
    175           json.put("boxInfo", boxes.get(0).getId());
    176           json.put("rows", wcfRow.format(boxes.get(0).getRows()-1));
    177           json.put("columns", boxes.get(0).getColumns());
    178           json.put("freeColumn", emptyWell.getColumn());
    179           json.put("freeRow", wcfRow.format(emptyWell.getRow()));         
     187          json.put("boxInfo", spBoxes.get(0).getId());
     188          json.put("rows", wcfRow.format(spBoxes.get(0).getRows()-1));
     189          json.put("columns", spBoxes.get(0).getColumns());
     190          if (emptyWell != null)
     191          {
     192            json.put("freeColumn", emptyWell.getColumn());
     193            json.put("freeRow", wcfRow.format(emptyWell.getRow()));
     194          }                   
     195        }
     196        else if (spBoxes.size()==0)
     197        {
     198          json.put("message", "There is no Sp-box with name: "+boxName);
     199        }
     200        else
     201        {
     202          json.put("message", "More then one Sp-box were found with the name: " + boxName);
    180203        }
    181204       
     
    271294        AnnotationType rnaLaterDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_RNALATER_DATETIME, true);
    272295        AnnotationType arrivalDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ARRIVAL_DATE, true);       
    273         AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_COMMENT, true);
     296        AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_DELIVERY_COMMENT, true);
    274297        AnnotationType specimenType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SPECIMEN_TYPE, true);
    275298        AnnotationType biopsyType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_BIOPSY_TYPE, true);
     
    320343      {
    321344        dc = sc.newDbControl();
    322        
     345        ItemContext cc = sc.getCurrentContext(Item.SAMPLE);
    323346        JSONObject jsonReq = (JSONObject)new JSONParser().parse(req.getReader());       
    324347        JSONObject jsonCase = (JSONObject)jsonReq.get("caseInfo");
     
    340363        AnnotationType rnaLaterDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_RNALATER_DATETIME, true);
    341364        AnnotationType arrivalDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ARRIVAL_DATE, true);
    342         AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_COMMENT, true);
     365        AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_DELIVERY_COMMENT, true);
    343366        AnnotationType specimenType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SPECIMEN_TYPE, true);
    344367        AnnotationType biopsyType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_BIOPSY_TYPE, true);
     
    388411              {
    389412                specimen.setBioWell(well);
     413                cc.setRecent(well.getPlate(), "reggie_specimentube", 1);               
    390414              }
    391415            }           
     
    412436    }
    413437  }
     438 
     439  private BioWell getFirstFreeWell(BioPlate box, Integer numberOfWells)
     440  {
     441    // First free well in the box.
     442    BioWell firstFreeWell= null;
     443   
     444    int rowIndex = box.getRows()-1;
     445    boolean foundLastEmpty = false;         
     446    while (rowIndex >= 0 && !foundLastEmpty)
     447    {
     448      int columnIndex = box.getColumns()-1;
     449      while (columnIndex >= 0 && !foundLastEmpty)
     450      {
     451        if (!box.getBioWell(rowIndex, columnIndex).isEmpty())
     452        {
     453          /* We past the last free well or reach the beginning of the plate,
     454             take one step forward and check if all tubes can be placed on the same row
     455          */
     456          int freeColumn = columnIndex;
     457          int freeRow = rowIndex;
     458          if (!(box.getColumns() > (freeColumn+numberOfWells)))
     459          {
     460            freeRow++;
     461            freeColumn = 0;
     462          }
     463          else
     464          {
     465            freeColumn++;
     466          }
     467                   
     468          if (freeRow<box.getRows() && freeColumn<box.getColumns())
     469          {
     470            firstFreeWell = box.getBioWell(freeRow, freeColumn);
     471          }         
     472          foundLastEmpty = true;
     473        }
     474        else if (rowIndex == 0 && columnIndex==0)
     475        {
     476          firstFreeWell = box.getBioWell(rowIndex, columnIndex);
     477        }
     478        columnIndex--;
     479      }
     480      rowIndex--;
     481    }   
     482    return firstFreeWell;
     483  }
    414484}
Note: See TracChangeset for help on using the changeset viewer.