Changeset 1692


Ignore:
Timestamp:
Jun 8, 2012, 11:12:51 AM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #371: Wizard that move histology samples to paraffin blocks

Added step for recording storage box for the blocks.

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

Legend:

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

    r1689 r1692  
    77  import="net.sf.basedb.core.Application"
    88  import="net.sf.basedb.clients.web.Base"
     9  import="net.sf.basedb.clients.web.util.HTML" 
    910  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
    1011  import="java.text.SimpleDateFormat"
     
    2425  final User user = User.getById(dc, sc.getLoggedInUserId());
    2526  final String today = new SimpleDateFormat("yyyyMMdd").format(new Date());
     27  String lastBlockBox = sc.getUserClientSetting("net.sf.basedb.reggie.histology.last-block-box");
     28  if (lastBlockBox == null) lastBlockBox = "";
    2629%>
    2730<base:page type="default" >
     
    2932  <link rel="stylesheet" type="text/css" href="css/reggie.css">
    3033  <script language="JavaScript" src="reggie.js" type="text/javascript" charset="UTF-8"></script>
     34<style>
     35#blockTable
     36{
     37  width: 100%;
     38  border-collapse: collapse;
     39}
     40
     41#blockTable th
     42{
     43  padding-left: 2px;
     44  padding-right: 2px;
     45  text-align: left;
     46}
     47
     48#blockTable td
     49{
     50  padding: 2px;
     51  text-align: left;
     52}
     53</style>
    3154
    3255<script language="JavaScript">
     
    3457var currentStep = 1;
    3558var moveDateIsValid = false;
     59var workList;
    3660
    3761function init()
     
    5276    workListIsValid = true;
    5377    moveDateOnChange();
    54     Main.show('gocreate');
     78    Main.show('gonext');
    5579  }
    5680  else
     
    139163    gotoStep2();
    140164  }
    141   else if (currentStep == 2)
    142   {
    143     gotoStep3();
    144   }
    145165  Main.show('navigation');
    146166}
     
    148168function step1IsValid()
    149169{
    150   var frm = document.forms['reggie'];
    151 
     170  return moveDateIsValid;
     171}
     172
     173function step2IsValid()
     174{
     175  var frm = document.forms['reggie'];
     176  setInputStatus('blockBox', '', '');
     177  var blockNo = 0;
     178  while (frm['blockBox'+blockNo])
     179  {
     180    if (frm['blockBox'+blockNo].value == '')
     181    {
     182      setInputStatus('blockBox', 'A storage box must be specified for all blocks.', 'invalid');
     183      frm['blockBox'+blockNo].focus();
     184      return false;
     185    }
     186    blockNo++;
     187  }
     188  setInputStatus('blockBox', '', 'valid');
    152189  return true;
    153190}
     
    159196  var frm = document.forms['reggie'];
    160197 
     198  frm.workList.disabled = true;
     199  frm.moveDate.disabled = true;
     200  frm.histologyProtocol.disabled = true;
     201 
    161202  currentStep = 2;
    162 }
    163 
    164 function goCreate()
    165 {
    166   var frm = document.forms['reggie'];
    167 
    168   if (frm.moveDate.value != '' && !moveDateIsValid) return;
    169  
    170   Main.hide('gocreate');
    171 
    172   var listId = frm.workList[frm.workList.selectedIndex].value;
     203  Main.hide('gonext');
     204  Main.show('gocreate');
     205  Main.show('blockBoxSection');
     206 
     207  workList = getWorkListInfo();
     208 
     209  var html = '<table id="blockTable">';
     210  html += '<thead>';
     211  // First header row
     212  html += '<tr>';
     213  html += '<th>Paraffin block</th>';
     214  html += '<th>Storage box</th>';
     215  html += '</tr>';
     216  html += '</thead>';
     217  html += '<tbody>';
     218 
     219  for (var blockNo = 0; blockNo < workList.blocks.length; blockNo++)
     220  {
     221    var block = workList.blocks[blockNo];
     222    var nextStep = blockNo < (workList.blocks.length-1) ? 'focusOnEnter(event, \'blockBox'+(blockNo+1)+'\')' : '';
     223
     224    html += '<tr>';
     225    html += '<td style="width: 150px;">' + block.name + '</td>';
     226    html += '<td><input name="blockBox'+blockNo+'" value="<%=lastBlockBox%>" onblur="blockBoxOnChange('+blockNo+')"';
     227    html += ' onkeypress="' + nextStep + '" size="10" ></td>';
     228    html += '</tr>';
     229  }
     230  html += '</tbody>';
     231  html += '</table>';
     232  setInnerHTML('blockBoxInput', html);
     233 
     234  frm.blockBox0.focus();
     235}
     236
     237
     238function getWorkListInfo()
     239{
     240  var frm = document.forms['reggie'];
     241 
    173242  var request = Ajax.getXmlHttpRequest();
    174243  try
    175244  {
     245    showLoadingAnimation('Loading histology work list information...');
     246    var url = 'Histology.servlet?ID=<%=ID%>&cmd=GetHistologyWorkListInfo&workListId='+frm.workList[frm.workList.selectedIndex].value;   
     247    request.open("GET", url, false);
     248    request.send(null);
     249  }
     250  finally
     251  {
     252    hideLoadingAnimation();
     253  }
     254 
     255  if (debug) Main.debug(request.responseText);
     256  var response = JSON.parse(request.responseText); 
     257  if (response.status != 'ok')
     258  {
     259    setFatalError(response.message);
     260    return false;
     261  }
     262  return response.workList;
     263}
     264
     265
     266function goCreate()
     267{
     268  if (!step2IsValid()) return;
     269 
     270  var frm = document.forms['reggie'];
     271  Main.hide('gocreate');
     272 
     273  workList.moveDate = frm.moveDate.value;
     274  workList.protocolId = parseInt(frm.histologyProtocol[frm.histologyProtocol.selectedIndex].value);
     275
     276  for (var blockNo = 0; blockNo < workList.blocks.length; blockNo++)
     277  {
     278    var block = workList.blocks[blockNo];
     279    block.storageBox = frm['blockBox'+blockNo].value;
     280    frm['blockBox'+blockNo].disabled = true;
     281  }
     282
     283  if (debug) Main.debug(JSON.stringify(workList));
     284  var request = Ajax.getXmlHttpRequest();
     285  try
     286  {
    176287    showLoadingAnimation('Moving histology samples to paraffin blocks...');
    177     var url = 'Histology.servlet?ID=<%=ID%>&cmd=MoveHistologySamplesToParaffinBlocks&workListId='+listId;
    178     url += '&moveDate=' + frm.moveDate.value;
    179     url += '&protocolId=' + frm.histologyProtocol[frm.histologyProtocol.selectedIndex].value;
     288    var url = 'Histology.servlet?ID=<%=ID%>&cmd=MoveHistologySamplesToParaffinBlocks';
    180289    request.open("POST", url, false);
    181     request.send(null);
     290    request.setRequestHeader("Content-Type", "application/json");
     291    request.send(JSON.stringify(workList));
    182292  }
    183293  finally
     
    242352}
    243353
     354function blockBoxOnChange(blockNo)
     355{
     356  var frm = document.forms['reggie'];
     357 
     358  var blockName = frm['blockBox'+blockNo].value;
     359  while (frm['blockBox'+blockNo])
     360  {
     361    frm['blockBox'+blockNo].value = blockName;
     362    blockNo++;
     363  }
     364 
     365}
     366
    244367</script>
    245368
     
    267390
    268391  <form name="reggie" onsubmit="return false;">
    269  
    270392  <table class="stepform">
    271393  <tr>
     
    312434  </table>
    313435 
     436  <div id="blockBoxSection" style="display:none;">
     437    <table class="stepform">
     438    <tr>
     439      <td rowspan="3" class="stepno">2</td>
     440      <td class="steptitle">Storage location for paraffin blocks</td>
     441    </tr>
     442    <tr>
     443      <td class="stepfields">
     444        <table style="width: 100%;">
     445        <tr valign="top">
     446          <td class="input" style="width: 450px;">
     447            <div id="blockBoxInput"></div>
     448          </td>
     449          <td class="status" id="blockBox.status"></td>
     450          <td class="help"><span id="blockBox.message" class="message" style="display: none;"></span>
     451            Enter the box number/name in which the paraffin blocks are stored.
     452            Changes are automatically propagated downwards.
     453          </td>
     454        </tr>
     455        </table>
     456      </td>
     457    </tr>
     458    </table>
     459  </div>
     460 
    314461  <div class="loading" id="loading" style="display: none;"><table><tr><td><img src="images/loading.gif"></td><td id="loading.msg">Please wait...</td></tr></table></div>
    315462 
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/Histology.java

    r1682 r1692  
    3131  */
    3232  public static final String WORK_LIST_ID_PREFIX = "net.sf.basedb.reggie.histology.work-list";
     33 
     34  /**
     35    The number of samples per paraffin block.
     36  */
     37  public static final int SAMPLES_PER_BLOCK = 5;
    3338 
    3439  /**
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/HistologyServlet.java

    r1691 r1692  
    33import java.io.IOException;
    44import java.io.PrintWriter;
    5 import java.util.ArrayList;
    65import java.util.Date;
    76import java.util.List;
     
    122121        json.put("histology", jsonHistology);
    123122      }
     123     
     124      else if ("GetHistologyWorkListInfo".equals(cmd))
     125      {
     126        /*
     127          Get information about a histology work list and paraffin blocks it is associated with.
     128        */
     129        dc = sc.newDbControl();
     130        int workListId = Values.getInt(req.getParameter("workListId"));
     131        BioMaterialList workList = BioMaterialList.getById(dc, workListId);
     132       
     133        JSONObject jsonList = new JSONObject();
     134        jsonList.put("id", workList.getId());
     135        jsonList.put("name", workList.getName());
     136        jsonList.put("size", workList.getSize());
     137       
     138        JSONArray jsonBlocks = new JSONArray();
     139        int totalBlocks = 1 + (workList.getSize()-1) / Histology.SAMPLES_PER_BLOCK;
     140        for (int blockNo = 1; blockNo <= totalBlocks; blockNo++)
     141        {
     142          AnyToAny link = AnyToAny.getByName(dc, workList, "block." + blockNo);
     143          ReactionPlate plate = ReactionPlate.getById(dc, link.getToId(), BioplateType.PARAFFIN_BLOCK);
     144          jsonBlocks.add(plate.asJSONObject());
     145        }
     146        jsonList.put("blocks", jsonBlocks);
     147        json.put("workList", jsonList);
     148      }
     149     
    124150      else if ("GetParaffinBlocks".equals(cmd))
    125151      {
     
    208234       
    209235        BioMaterialList workList = BioMaterialList.getById(dc, workListId);
    210         final int SAMPLES_PER_BLOCK = 5;
    211         int totalBlocks = 1 + (workList.getSize()-1) / SAMPLES_PER_BLOCK;
     236        int totalBlocks = 1 + (workList.getSize()-1) / Histology.SAMPLES_PER_BLOCK;
    212237       
    213238        resp.setHeader("Content-Disposition", "attachment; filename=he-glass-labels.txt");
     
    302327        for (int i = 0; i < jsonHistology.size(); ++i)
    303328        {
    304           if (i % 5 == 0)
     329          if (i % Histology.SAMPLES_PER_BLOCK == 0)
    305330          {
    306331            // Create a new Paraffin block and associate it with the list
     
    330355      else if ("MoveHistologySamplesToParaffinBlocks".equals(cmd))
    331356      {
    332         int workListId = Values.getInt(req.getParameter("workListId"));
    333         Date moveDate = Reggie.CONVERTER_STRING_TO_DATE.convert(req.getParameter("moveDate"));
    334         int protocolId = Values.getInt(req.getParameter("protocolId"));
    335        
    336         dc = sc.newDbControl();
    337        
    338         BioMaterialList workList = BioMaterialList.getById(dc, workListId);
    339         Protocol protocol = protocolId != 0 ? Protocol.getById(dc, protocolId) : null;
     357        JSONObject jsonReq = (JSONObject)new JSONParser().parse(req.getReader());
     358        JSONArray jsonBlocks = (JSONArray)jsonReq.get("blocks");
     359        Number workListId = (Number)jsonReq.get("id");
     360       
     361        Date moveDate = Reggie.CONVERTER_STRING_TO_DATE.convert((String)jsonReq.get("moveDate"));
     362        Number protocolId = (Number)jsonReq.get("protocolId");
     363        String storageBox = "";
     364       
     365        dc = sc.newDbControl();
     366       
     367        BioMaterialList workList = BioMaterialList.getById(dc, workListId.intValue());
     368        Protocol protocol = protocolId != null ? Protocol.getById(dc, protocolId.intValue()) : null;
    340369       
    341370        BioPlateEvent placeEvent = BioPlateEvent.getNew(dc, BioPlateEventType.getById(dc, BioPlateEventType.PLACE_ON_PLATE));
     
    373402        BioPlate paraffinBlock = null;
    374403        BioPlateEventParticipant blockEvent = null;
    375         int blockPos = 5; // Start outside trigger creation of a new paraffin block
     404        int blockPos = Histology.SAMPLES_PER_BLOCK; // Start outside trigger creation of a new paraffin block
    376405        int blockNo = 0;
    377         List<BioPlate> paraffinBlocks = new ArrayList<BioPlate>(allBioMaterial.size() / 5);
    378406        int remainingBioMaterial = allBioMaterial.size();
    379407
    380408        for (Sample his : allBioMaterial)
    381409        {
    382           if (blockPos == 5)
    383           {
     410          if (blockPos == Histology.SAMPLES_PER_BLOCK)
     411          {
     412            JSONObject jsonBlock = (JSONObject)jsonBlocks.get(blockNo);
     413            storageBox = (String)jsonBlock.get("storageBox");
     414            Number blockId = (Number)jsonBlock.get("id");
    384415            blockPos = 0;
    385416            blockNo++;
    386417           
    387             AnyToAny link = AnyToAny.getByName(dc, workList, "block."+blockNo);
    388             paraffinBlock = (BioPlate)link.getTo();
    389            
    390             paraffinBlocks.add(paraffinBlock);
     418            paraffinBlock = BioPlate.getById(dc, blockId.intValue());
    391419            paraffinBlock.setEventDate(moveDate);
     420            paraffinBlock.setDescription("Stored in block box: " + storageBox);
    392421           
    393422            // Attach the new paraffin block to the PLACE-ON-PLATE event
     
    395424            dc.saveItem(blockEvent);
    396425           
    397             int numSamples = remainingBioMaterial > 5 ? 5 : remainingBioMaterial;
     426            int numSamples = remainingBioMaterial > Histology.SAMPLES_PER_BLOCK ? Histology.SAMPLES_PER_BLOCK : remainingBioMaterial;
    398427           
    399             jsonMessages.add("Moved " + numSamples + " samples to '" + paraffinBlock.getName() + "'");
     428            jsonMessages.add("Moved " + numSamples + " samples to '" + paraffinBlock.getName() + "' (" + paraffinBlock.getDescription() + ")");
    400429          }
    401430         
     
    421450        // Mark the work list as removed
    422451        workList.setRemoved(true);
    423        
     452        sc.setUserClientSetting("net.sf.basedb.reggie.histology.last-block-box", storageBox);
     453
    424454        dc.commit();
    425        
    426         JSONArray jsonParaffinBlocks = new JSONArray();
    427         for (BioPlate pb : paraffinBlocks)
    428         {
    429           JSONObject jsonPb = new JSONObject();
    430           jsonPb.put("id", pb.getId());
    431           jsonPb.put("name", pb.getName());
    432           jsonParaffinBlocks.add(jsonPb);
    433         }
    434        
    435         json.put("paraffinBlocks", jsonParaffinBlocks);
    436455      }
    437456     
Note: See TracChangeset for help on using the changeset viewer.