7173 |
17 May 23 |
nicklas |
var Protocol = function() |
7173 |
17 May 23 |
nicklas |
2 |
{ |
7173 |
17 May 23 |
nicklas |
var protocol = {}; |
7173 |
17 May 23 |
nicklas |
var debug = 0; |
7173 |
17 May 23 |
nicklas |
5 |
|
7173 |
17 May 23 |
nicklas |
// Page initialization |
7173 |
17 May 23 |
nicklas |
protocol.initPage = function() |
7173 |
17 May 23 |
nicklas |
8 |
{ |
7173 |
17 May 23 |
nicklas |
var pageId = Doc.getPageId(); |
7173 |
17 May 23 |
nicklas |
if (pageId == 'protocol') |
7173 |
17 May 23 |
nicklas |
11 |
{ |
7173 |
17 May 23 |
nicklas |
Buttons.addClickHandler('print-button', Wizard.goPrint); |
7173 |
17 May 23 |
nicklas |
13 |
|
7173 |
17 May 23 |
nicklas |
var boxId = Data.int('page-data', 'transport-box'); |
7173 |
17 May 23 |
nicklas |
var url = '../ExternalSpecimen.servlet?ID='+App.getSessionId(); |
7173 |
17 May 23 |
nicklas |
url += '&cmd=GetTransportBoxDetailsForMove&listId='+boxId; |
7173 |
17 May 23 |
nicklas |
Wizard.showLoadingAnimation('Loading transport box information...'); |
7173 |
17 May 23 |
nicklas |
Wizard.asyncJsonRequest(url, protocol.initializeProtocol); |
7173 |
17 May 23 |
nicklas |
19 |
} |
7173 |
17 May 23 |
nicklas |
else |
7173 |
17 May 23 |
nicklas |
21 |
{ |
7173 |
17 May 23 |
nicklas |
Events.addEventHandler('transportBox', 'change', protocol.transportBoxOnChange); |
7173 |
17 May 23 |
nicklas |
Events.addEventHandler('listview', 'click', protocol.viewProtocol); |
7173 |
17 May 23 |
nicklas |
Events.addEventHandler('plateview', 'click', protocol.viewProtocol); |
7173 |
17 May 23 |
nicklas |
25 |
|
7173 |
17 May 23 |
nicklas |
var url = '../ExternalSpecimen.servlet?ID='+App.getSessionId(); |
7173 |
17 May 23 |
nicklas |
url += '&cmd=GetTransportBoxesToMove'; |
7173 |
17 May 23 |
nicklas |
Wizard.showLoadingAnimation('Loading transport boxes...'); |
7173 |
17 May 23 |
nicklas |
Wizard.asyncJsonRequest(url, protocol.initializeStep1); |
7173 |
17 May 23 |
nicklas |
30 |
} |
7173 |
17 May 23 |
nicklas |
31 |
} |
7173 |
17 May 23 |
nicklas |
32 |
|
7173 |
17 May 23 |
nicklas |
33 |
|
7173 |
17 May 23 |
nicklas |
protocol.initializeStep1 = function(response) |
7173 |
17 May 23 |
nicklas |
35 |
{ |
7173 |
17 May 23 |
nicklas |
var frm = document.forms['reggie']; |
7173 |
17 May 23 |
nicklas |
37 |
|
7173 |
17 May 23 |
nicklas |
var transportBoxes = response.transportBoxes; |
7173 |
17 May 23 |
nicklas |
var boxes = frm.transportBox; |
7173 |
17 May 23 |
nicklas |
if (transportBoxes.length > 0) |
7173 |
17 May 23 |
nicklas |
41 |
{ |
7173 |
17 May 23 |
nicklas |
for (var i=0; i < transportBoxes.length; i++) |
7173 |
17 May 23 |
nicklas |
43 |
{ |
7173 |
17 May 23 |
nicklas |
var box = transportBoxes[i]; |
7173 |
17 May 23 |
nicklas |
var name = box.name + ' ('+box.size+' samples)'; |
7173 |
17 May 23 |
nicklas |
var option = new Option(name, box.id); |
7173 |
17 May 23 |
nicklas |
option.box = box; |
7173 |
17 May 23 |
nicklas |
boxes.options[boxes.length] = option; |
7173 |
17 May 23 |
nicklas |
49 |
} |
7173 |
17 May 23 |
nicklas |
50 |
|
7173 |
17 May 23 |
nicklas |
protocol.transportBoxOnChange(); |
7173 |
17 May 23 |
nicklas |
52 |
} |
7173 |
17 May 23 |
nicklas |
else |
7173 |
17 May 23 |
nicklas |
54 |
{ |
7173 |
17 May 23 |
nicklas |
Wizard.setFatalError('No transport boxes available for processing.'); |
7173 |
17 May 23 |
nicklas |
return; |
7173 |
17 May 23 |
nicklas |
57 |
} |
7173 |
17 May 23 |
nicklas |
58 |
|
7173 |
17 May 23 |
nicklas |
Doc.show('step-1'); |
7173 |
17 May 23 |
nicklas |
Doc.show('gonext'); |
7173 |
17 May 23 |
nicklas |
61 |
} |
7173 |
17 May 23 |
nicklas |
62 |
|
7173 |
17 May 23 |
nicklas |
63 |
|
7173 |
17 May 23 |
nicklas |
// Add pools to the pools list based on the bioplate selection |
7173 |
17 May 23 |
nicklas |
protocol.transportBoxOnChange = function() |
7173 |
17 May 23 |
nicklas |
66 |
{ |
7173 |
17 May 23 |
nicklas |
var frm = document.forms['reggie']; |
7173 |
17 May 23 |
nicklas |
var box = frm.transportBox[frm.transportBox.selectedIndex].box; |
7173 |
17 May 23 |
nicklas |
Doc.element('comments').innerHTML = Strings.encodeTags(box.comments); |
7173 |
17 May 23 |
nicklas |
70 |
} |
7173 |
17 May 23 |
nicklas |
71 |
|
7173 |
17 May 23 |
nicklas |
protocol.viewProtocol = function(event) |
7173 |
17 May 23 |
nicklas |
73 |
{ |
7173 |
17 May 23 |
nicklas |
var frm = document.forms['reggie']; |
7173 |
17 May 23 |
nicklas |
if (frm.transportBox && !frm.transportBox.disabled) |
7173 |
17 May 23 |
nicklas |
76 |
{ |
7173 |
17 May 23 |
nicklas |
frm.view.value = Data.get(event.currentTarget, 'protocol-type'); |
7173 |
17 May 23 |
nicklas |
frm.submit(); |
7173 |
17 May 23 |
nicklas |
79 |
} |
7173 |
17 May 23 |
nicklas |
80 |
} |
7173 |
17 May 23 |
nicklas |
81 |
|
7173 |
17 May 23 |
nicklas |
82 |
|
7173 |
17 May 23 |
nicklas |
protocol.initializeProtocol = function(response) |
7173 |
17 May 23 |
nicklas |
84 |
{ |
7173 |
17 May 23 |
nicklas |
var transportBox = response.transportBox; |
7173 |
17 May 23 |
nicklas |
var storageBoxes = response.storageBoxes; |
7173 |
17 May 23 |
nicklas |
var samples = response.samples; |
7173 |
17 May 23 |
nicklas |
88 |
|
7175 |
17 May 23 |
nicklas |
if (transportBox.externalRef) |
7175 |
17 May 23 |
nicklas |
90 |
{ |
7175 |
17 May 23 |
nicklas |
Doc.element('boxName').innerHTML = Strings.encodeTags(transportBox.externalRef); |
7175 |
17 May 23 |
nicklas |
92 |
} |
7175 |
17 May 23 |
nicklas |
93 |
|
7173 |
17 May 23 |
nicklas |
var boxNames = []; |
7173 |
17 May 23 |
nicklas |
for (var boxNo = 0; boxNo < storageBoxes.length; boxNo++) |
7173 |
17 May 23 |
nicklas |
96 |
{ |
7173 |
17 May 23 |
nicklas |
var box = storageBoxes[boxNo]; |
7189 |
22 May 23 |
nicklas |
boxNames[boxNames.length] = Strings.encodeTags(box.name + ' ('+box.freezer+')'); |
7173 |
17 May 23 |
nicklas |
99 |
} |
7189 |
22 May 23 |
nicklas |
Doc.element('storageBoxes').innerHTML = boxNames.join('<br>'); |
7173 |
17 May 23 |
nicklas |
101 |
|
7173 |
17 May 23 |
nicklas |
var html = ''; |
7173 |
17 May 23 |
nicklas |
if (transportBox.messages.length > 0) |
7173 |
17 May 23 |
nicklas |
104 |
{ |
7173 |
17 May 23 |
nicklas |
html += '<b>Notes</b>'; |
7173 |
17 May 23 |
nicklas |
html += '<ul>'; |
7173 |
17 May 23 |
nicklas |
for (var msgNo = 0; msgNo < transportBox.messages.length; msgNo++) |
7173 |
17 May 23 |
nicklas |
108 |
{ |
7173 |
17 May 23 |
nicklas |
var msg = transportBox.messages[msgNo]; |
7173 |
17 May 23 |
nicklas |
// Typically the message starts with a Clarity ID in which case |
7173 |
17 May 23 |
nicklas |
// we try to enhance the last digits that are printed larger on the tube |
7173 |
17 May 23 |
nicklas |
var ref = msg.match('^(.*?)(\\d+)(\\:.*)$'); |
7173 |
17 May 23 |
nicklas |
if (ref) |
7173 |
17 May 23 |
nicklas |
114 |
{ |
7173 |
17 May 23 |
nicklas |
html += '<li>'+ref[1]+'<span class="major-ref">'+ref[2]+'</span>'+Strings.encodeTags(ref[3]); |
7173 |
17 May 23 |
nicklas |
116 |
} |
7173 |
17 May 23 |
nicklas |
else |
7173 |
17 May 23 |
nicklas |
118 |
{ |
7173 |
17 May 23 |
nicklas |
html += '<li>'+Strings.encodeTags(msg); |
7173 |
17 May 23 |
nicklas |
120 |
} |
7173 |
17 May 23 |
nicklas |
121 |
} |
7173 |
17 May 23 |
nicklas |
html += '</ul>'; |
7173 |
17 May 23 |
nicklas |
Doc.element('transportMessages').innerHTML = html; |
7173 |
17 May 23 |
nicklas |
124 |
} |
7173 |
17 May 23 |
nicklas |
125 |
|
7173 |
17 May 23 |
nicklas |
var view = Data.get('page-data', 'view'); |
7173 |
17 May 23 |
nicklas |
if (view == 'list') |
7173 |
17 May 23 |
nicklas |
128 |
{ |
7173 |
17 May 23 |
nicklas |
protocol.viewAsList(samples); |
7173 |
17 May 23 |
nicklas |
130 |
} |
7173 |
17 May 23 |
nicklas |
else |
7173 |
17 May 23 |
nicklas |
132 |
{ |
7173 |
17 May 23 |
nicklas |
protocol.viewAsBox(samples) |
7173 |
17 May 23 |
nicklas |
134 |
} |
7173 |
17 May 23 |
nicklas |
Doc.show('all-protocol'); |
7173 |
17 May 23 |
nicklas |
136 |
} |
7173 |
17 May 23 |
nicklas |
137 |
|
7173 |
17 May 23 |
nicklas |
138 |
|
7173 |
17 May 23 |
nicklas |
protocol.viewAsBox = function(samples) |
7173 |
17 May 23 |
nicklas |
140 |
{ |
7173 |
17 May 23 |
nicklas |
var box1 = new StorageBox('box.1', 9, 9, BoxPainter); |
7173 |
17 May 23 |
nicklas |
var box2 = new StorageBox('box.2', 9, 9, BoxPainter); |
7173 |
17 May 23 |
nicklas |
143 |
|
7173 |
17 May 23 |
nicklas |
var currentBox = box1; |
7173 |
17 May 23 |
nicklas |
var lastBox = null; |
7173 |
17 May 23 |
nicklas |
var addName = true; |
7173 |
17 May 23 |
nicklas |
for (var i = 0; i < samples.length; i++) |
7173 |
17 May 23 |
nicklas |
148 |
{ |
7173 |
17 May 23 |
nicklas |
var sample = samples[i]; |
7173 |
17 May 23 |
nicklas |
var well = sample.well; |
7173 |
17 May 23 |
nicklas |
if (lastBox != null && well.bioPlate.id != lastBox) |
7173 |
17 May 23 |
nicklas |
152 |
{ |
7173 |
17 May 23 |
nicklas |
Doc.show(currentBox.id+'.more-boxes'); |
7173 |
17 May 23 |
nicklas |
currentBox = box2; |
7173 |
17 May 23 |
nicklas |
addName = true; |
7173 |
17 May 23 |
nicklas |
156 |
} |
7173 |
17 May 23 |
nicklas |
if (addName) |
7173 |
17 May 23 |
nicklas |
158 |
{ |
7173 |
17 May 23 |
nicklas |
Doc.show(currentBox.id); |
7173 |
17 May 23 |
nicklas |
Doc.element(currentBox.id+'.name').innerHTML = well.bioPlate.name; |
7173 |
17 May 23 |
nicklas |
lastBox = well.bioPlate.id; |
7173 |
17 May 23 |
nicklas |
addName = false; |
7173 |
17 May 23 |
nicklas |
163 |
} |
7173 |
17 May 23 |
nicklas |
Doc.removeClass(currentBox.id+'.row.'+well.row, 'empty-row'); |
7208 |
26 May 23 |
nicklas |
var tmp = currentBox.getWell(well.row, well.column); |
7208 |
26 May 23 |
nicklas |
tmp.setSample(sample); |
7208 |
26 May 23 |
nicklas |
Data.set(tmp.tag, 'name', sample.name); |
7208 |
26 May 23 |
nicklas |
tmp.tag.title = 'Open case summary: '+sample.name; |
7208 |
26 May 23 |
nicklas |
Events.addEventHandler(tmp.tag, 'click', Reggie.openCaseSummaryPopupOnEvent); |
7173 |
17 May 23 |
nicklas |
170 |
} |
7173 |
17 May 23 |
nicklas |
171 |
|
7173 |
17 May 23 |
nicklas |
// Normally, the wells before the first one with a sample should have other tubes already |
7173 |
17 May 23 |
nicklas |
// we simply "fake" it here by setting the "locked" property |
7173 |
17 May 23 |
nicklas |
var wells = box1.getWells(); |
7173 |
17 May 23 |
nicklas |
for (var i = 0; i < wells.length; i++) |
7173 |
17 May 23 |
nicklas |
176 |
{ |
7173 |
17 May 23 |
nicklas |
var w = wells[i]; |
7173 |
17 May 23 |
nicklas |
if (w.sample) break; |
7173 |
17 May 23 |
nicklas |
w.setLocked(true); |
7173 |
17 May 23 |
nicklas |
180 |
} |
7173 |
17 May 23 |
nicklas |
181 |
|
7173 |
17 May 23 |
nicklas |
box1.paint(box1.getWells()); |
7173 |
17 May 23 |
nicklas |
box2.paint(box2.getWells()); |
7173 |
17 May 23 |
nicklas |
184 |
} |
7173 |
17 May 23 |
nicklas |
185 |
|
7173 |
17 May 23 |
nicklas |
protocol.viewAsList = function(samples) |
7173 |
17 May 23 |
nicklas |
187 |
{ |
7173 |
17 May 23 |
nicklas |
var html = ''; |
7173 |
17 May 23 |
nicklas |
var lastRow = -1; |
7173 |
17 May 23 |
nicklas |
var rowClass = 'odd-row'; |
7173 |
17 May 23 |
nicklas |
for (var i = 0; i < samples.length; i++) |
7173 |
17 May 23 |
nicklas |
192 |
{ |
7173 |
17 May 23 |
nicklas |
var sample = samples[i]; |
7173 |
17 May 23 |
nicklas |
var well = sample.well; |
7173 |
17 May 23 |
nicklas |
if (lastRow != well.row) |
7173 |
17 May 23 |
nicklas |
196 |
{ |
7173 |
17 May 23 |
nicklas |
rowClass = rowClass=='even-row' ? 'odd-row' : 'even-row'; |
7173 |
17 May 23 |
nicklas |
198 |
} |
7173 |
17 May 23 |
nicklas |
lastRow = well.row; |
7173 |
17 May 23 |
nicklas |
200 |
|
7173 |
17 May 23 |
nicklas |
html += '<tr class="'+rowClass+'">'; |
7173 |
17 May 23 |
nicklas |
html += '<td class="clarityId">'; |
7173 |
17 May 23 |
nicklas |
// We try to enhance the last digits that are printed larger on the tube |
7173 |
17 May 23 |
nicklas |
// Eg. cmd:CMD655A21 --> CMD655A (21) |
7173 |
17 May 23 |
nicklas |
var ref = sample.externalRef.match('^cmd\\:(.*?)(\\d+)$'); |
7173 |
17 May 23 |
nicklas |
if (ref) |
7173 |
17 May 23 |
nicklas |
207 |
{ |
7173 |
17 May 23 |
nicklas |
html += Strings.encodeTags(ref[1])+'<span class="major-ref">'+Strings.encodeTags(ref[2])+'</span>'; |
7173 |
17 May 23 |
nicklas |
209 |
} |
7173 |
17 May 23 |
nicklas |
else |
7173 |
17 May 23 |
nicklas |
211 |
{ |
7173 |
17 May 23 |
nicklas |
html += Strings.encodeTags(sample.externalRef); |
7173 |
17 May 23 |
nicklas |
213 |
} |
7173 |
17 May 23 |
nicklas |
html += '</td>'; |
7173 |
17 May 23 |
nicklas |
html += '<td class="specimen">'+Strings.encodeTags(sample.specimenName || sample.name)+'</td>'; |
7173 |
17 May 23 |
nicklas |
html += '<td class="box">'+Strings.encodeTags(well.bioPlate.name)+'</td>'; |
7173 |
17 May 23 |
nicklas |
html += '<td class="location">'+Strings.encodeTags(well.location)+'</td>'; |
7208 |
26 May 23 |
nicklas |
html += '<td class="remain">'+Protocol.formatRemainingQuantity(sample.remain, sample.type)+'</td>'; |
7173 |
17 May 23 |
nicklas |
html += '<td class="comment">'+Strings.encodeTags(sample.comment)+'</td>'; |
7173 |
17 May 23 |
nicklas |
html += '</tr>'; |
7173 |
17 May 23 |
nicklas |
221 |
} |
7173 |
17 May 23 |
nicklas |
Doc.element('listData').innerHTML = html; |
7173 |
17 May 23 |
nicklas |
223 |
} |
7208 |
26 May 23 |
nicklas |
224 |
|
7208 |
26 May 23 |
nicklas |
protocol.formatRemainingQuantity = function(remain, sampleType) |
7208 |
26 May 23 |
nicklas |
226 |
{ |
7208 |
26 May 23 |
nicklas |
var result = ''; |
7208 |
26 May 23 |
nicklas |
if (sampleType == 'Specimen') |
7208 |
26 May 23 |
nicklas |
229 |
{ |
7208 |
26 May 23 |
nicklas |
result = Numbers.formatNumber(remain/1000, 0, ' mg'); |
7208 |
26 May 23 |
nicklas |
231 |
} |
7208 |
26 May 23 |
nicklas |
else if (sampleType == 'Lysate' || sampleType == 'FlowThrough') |
7208 |
26 May 23 |
nicklas |
233 |
{ |
7208 |
26 May 23 |
nicklas |
result = Numbers.formatNumber(remain, 0, ' µl'); |
7208 |
26 May 23 |
nicklas |
235 |
} |
7208 |
26 May 23 |
nicklas |
else // RNA and DNA |
7208 |
26 May 23 |
nicklas |
237 |
{ |
7208 |
26 May 23 |
nicklas |
result = Numbers.formatNumber(remain, 1, ' µg'); |
7208 |
26 May 23 |
nicklas |
239 |
} |
7208 |
26 May 23 |
nicklas |
return result; |
7208 |
26 May 23 |
nicklas |
241 |
} |
7173 |
17 May 23 |
nicklas |
242 |
|
7173 |
17 May 23 |
nicklas |
return protocol; |
7173 |
17 May 23 |
nicklas |
244 |
}(); |
7173 |
17 May 23 |
nicklas |
245 |
|
7173 |
17 May 23 |
nicklas |
Doc.onLoad(Protocol.initPage); |
7173 |
17 May 23 |
nicklas |
247 |
|
7173 |
17 May 23 |
nicklas |
248 |
|
7173 |
17 May 23 |
nicklas |
var BoxPainter = function() |
7173 |
17 May 23 |
nicklas |
250 |
{ |
7173 |
17 May 23 |
nicklas |
var painter = {}; |
7173 |
17 May 23 |
nicklas |
252 |
|
7173 |
17 May 23 |
nicklas |
painter.getClassNameForWell = function(well) |
7173 |
17 May 23 |
nicklas |
254 |
{ |
7173 |
17 May 23 |
nicklas |
var cls = ''; |
7173 |
17 May 23 |
nicklas |
if (well.sample) |
7173 |
17 May 23 |
nicklas |
257 |
{ |
7173 |
17 May 23 |
nicklas |
cls += ' not-empty'; |
7173 |
17 May 23 |
nicklas |
259 |
} |
7173 |
17 May 23 |
nicklas |
if (well.locked) |
7173 |
17 May 23 |
nicklas |
261 |
{ |
7173 |
17 May 23 |
nicklas |
cls += ' locked'; |
7173 |
17 May 23 |
nicklas |
263 |
} |
7173 |
17 May 23 |
nicklas |
return cls; |
7173 |
17 May 23 |
nicklas |
265 |
} |
7173 |
17 May 23 |
nicklas |
266 |
|
7173 |
17 May 23 |
nicklas |
painter.getWellText = function(well) |
7173 |
17 May 23 |
nicklas |
268 |
{ |
7173 |
17 May 23 |
nicklas |
var text = ''; |
7173 |
17 May 23 |
nicklas |
var sample = well.sample; |
7173 |
17 May 23 |
nicklas |
if (sample) |
7173 |
17 May 23 |
nicklas |
272 |
{ |
7173 |
17 May 23 |
nicklas |
// We try to enhance the last digits that are printed larger on the tube |
7173 |
17 May 23 |
nicklas |
// Eg. cmd:CMD655A21 --> CMD655A (21) |
7173 |
17 May 23 |
nicklas |
var ref = sample.externalRef.match('^cmd\\:(.*?)(\\d+)$'); |
7173 |
17 May 23 |
nicklas |
if (ref) |
7173 |
17 May 23 |
nicklas |
277 |
{ |
7173 |
17 May 23 |
nicklas |
text += '<div class="minor-ref">'+Strings.encodeTags(ref[1])+'</div>'; |
7173 |
17 May 23 |
nicklas |
text += '<div class="major-ref">'+Strings.encodeTags(ref[2])+'</div>'; |
7173 |
17 May 23 |
nicklas |
280 |
} |
7173 |
17 May 23 |
nicklas |
else |
7173 |
17 May 23 |
nicklas |
282 |
{ |
7173 |
17 May 23 |
nicklas |
text += '<div class="major-ref">'+Strings.encodeTags(sample.externalRef)+'</div>'; |
7173 |
17 May 23 |
nicklas |
284 |
} |
7173 |
17 May 23 |
nicklas |
text += '<div class="specimen-name">'+Strings.encodeTags(sample.specimenName || sample.name)+'</div>'; |
7208 |
26 May 23 |
nicklas |
if (sample.remain != null) |
7208 |
26 May 23 |
nicklas |
287 |
{ |
7208 |
26 May 23 |
nicklas |
text += '<div class="remain">'; |
7208 |
26 May 23 |
nicklas |
text += Protocol.formatRemainingQuantity(sample.remain, sample.type); |
7208 |
26 May 23 |
nicklas |
text += '</div>'; |
7208 |
26 May 23 |
nicklas |
291 |
} |
7173 |
17 May 23 |
nicklas |
292 |
} |
7173 |
17 May 23 |
nicklas |
else if (well.locked) |
7173 |
17 May 23 |
nicklas |
294 |
{ |
7173 |
17 May 23 |
nicklas |
text = '×'; |
7173 |
17 May 23 |
nicklas |
296 |
} |
7173 |
17 May 23 |
nicklas |
return text; |
7173 |
17 May 23 |
nicklas |
298 |
} |
7173 |
17 May 23 |
nicklas |
299 |
|
7173 |
17 May 23 |
nicklas |
return painter; |
7173 |
17 May 23 |
nicklas |
301 |
}(); |
7173 |
17 May 23 |
nicklas |
302 |
|