2686 |
22 Sep 14 |
nicklas |
var Protocol = function() |
2686 |
22 Sep 14 |
nicklas |
2 |
{ |
2686 |
22 Sep 14 |
nicklas |
var protocol = {}; |
2702 |
26 Sep 14 |
nicklas |
var debug = 0; |
2686 |
22 Sep 14 |
nicklas |
5 |
|
2686 |
22 Sep 14 |
nicklas |
var lysatesIsValid = false; |
2686 |
22 Sep 14 |
nicklas |
7 |
|
2686 |
22 Sep 14 |
nicklas |
// Page initialization |
2686 |
22 Sep 14 |
nicklas |
protocol.initPage = function() |
2686 |
22 Sep 14 |
nicklas |
10 |
{ |
2686 |
22 Sep 14 |
nicklas |
var pageId = Doc.getPageId(); |
2686 |
22 Sep 14 |
nicklas |
if (pageId == 'protocol') |
2686 |
22 Sep 14 |
nicklas |
13 |
{ |
2686 |
22 Sep 14 |
nicklas |
Buttons.addClickHandler('print-button', Wizard.goPrint); |
2686 |
22 Sep 14 |
nicklas |
Doc.show('all-protocol'); |
3168 |
05 Mar 15 |
nicklas |
16 |
|
3168 |
05 Mar 15 |
nicklas |
var url = '../Extraction.servlet?ID='+App.getSessionId(); |
3168 |
05 Mar 15 |
nicklas |
url += '&cmd=GetLatestReagentLotNumbers'; |
3168 |
05 Mar 15 |
nicklas |
Wizard.showLoadingAnimation('Loading recent reagent lot numbers...'); |
3168 |
05 Mar 15 |
nicklas |
Wizard.asyncJsonRequest(url, protocol.reagentsLoaded); |
3168 |
05 Mar 15 |
nicklas |
21 |
|
3168 |
05 Mar 15 |
nicklas |
Events.addEventHandler('showReagents', 'click', protocol.toggleReagents); |
2686 |
22 Sep 14 |
nicklas |
23 |
} |
2686 |
22 Sep 14 |
nicklas |
else |
2686 |
22 Sep 14 |
nicklas |
25 |
{ |
2686 |
22 Sep 14 |
nicklas |
Events.addEventHandler('lysates', 'change', protocol.lysatesOnChange); |
4097 |
13 Sep 16 |
nicklas |
Events.addEventHandler('reextraction', 'change', protocol.lysatesOnChange); |
5304 |
15 Feb 19 |
nicklas |
Buttons.addClickHandler('downloadLabelsCsv', protocol.downloadLabels); |
5304 |
15 Feb 19 |
nicklas |
Buttons.addClickHandler('downloadLabelsXlsx', protocol.downloadLabels); |
2686 |
22 Sep 14 |
nicklas |
Buttons.addClickHandler('gocreate', protocol.viewProtocol); |
2686 |
22 Sep 14 |
nicklas |
31 |
|
2686 |
22 Sep 14 |
nicklas |
var url = '../Extraction.servlet?ID='+App.getSessionId(); |
4093 |
12 Sep 16 |
nicklas |
url += '&cmd=GetUnprocessedLysates&includeReprocess=1'; |
2686 |
22 Sep 14 |
nicklas |
Wizard.showLoadingAnimation('Loading Lysate extracts...'); |
2686 |
22 Sep 14 |
nicklas |
Wizard.asyncJsonRequest(url, protocol.initializeStep1); |
2686 |
22 Sep 14 |
nicklas |
36 |
} |
2686 |
22 Sep 14 |
nicklas |
37 |
} |
2686 |
22 Sep 14 |
nicklas |
38 |
|
2686 |
22 Sep 14 |
nicklas |
39 |
|
2686 |
22 Sep 14 |
nicklas |
protocol.initializeStep1 = function(response) |
2686 |
22 Sep 14 |
nicklas |
41 |
{ |
2686 |
22 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2686 |
22 Sep 14 |
nicklas |
var lysates = response.lysates; |
2686 |
22 Sep 14 |
nicklas |
44 |
|
3469 |
27 Aug 15 |
nicklas |
Doc.element('reserve').value = response.ReservedBy.id; |
3740 |
11 Feb 16 |
nicklas |
Doc.element('YellowLabel').value = response.YellowLabel.id; |
4093 |
12 Sep 16 |
nicklas |
Doc.element('AutoProcessing').value = response.AutoProcessing.id; |
6723 |
04 May 22 |
nicklas |
Doc.element('TubeLabel').value = response.TubeLabel.id; |
3469 |
27 Aug 15 |
nicklas |
49 |
|
2686 |
22 Sep 14 |
nicklas |
var lysateList = frm.lysates; |
4097 |
13 Sep 16 |
nicklas |
var reextractList = frm.reextraction; |
2686 |
22 Sep 14 |
nicklas |
if (lysates.length > 0) |
2686 |
22 Sep 14 |
nicklas |
53 |
{ |
3469 |
27 Aug 15 |
nicklas |
// Check if we have any lysate reserved by the current user |
3469 |
27 Aug 15 |
nicklas |
var currentUser = Data.get(lysateList, 'current-user'); |
3469 |
27 Aug 15 |
nicklas |
var hasReserved = false; |
3740 |
11 Feb 16 |
nicklas |
var numYellow = 0; |
2686 |
22 Sep 14 |
nicklas |
for (var i=0; i < lysates.length; i++) |
2686 |
22 Sep 14 |
nicklas |
59 |
{ |
3740 |
11 Feb 16 |
nicklas |
var lysate = lysates[i]; |
3740 |
11 Feb 16 |
nicklas |
if (lysate.ReservedBy == currentUser) hasReserved = true; |
3740 |
11 Feb 16 |
nicklas |
if (lysate.specimen.YellowLabel != null) numYellow++; |
3469 |
27 Aug 15 |
nicklas |
63 |
} |
3469 |
27 Aug 15 |
nicklas |
64 |
|
3469 |
27 Aug 15 |
nicklas |
var numSelected = 0; |
3740 |
11 Feb 16 |
nicklas |
var maxNonYellow = 12-numYellow; |
3469 |
27 Aug 15 |
nicklas |
for (var i=0; i < lysates.length; i++) |
3469 |
27 Aug 15 |
nicklas |
68 |
{ |
2686 |
22 Sep 14 |
nicklas |
var lysate = lysates[i]; |
3740 |
11 Feb 16 |
nicklas |
var isYellow = lysate.specimen.YellowLabel != null; |
4097 |
13 Sep 16 |
nicklas |
lysate.isReProcess = lysate.AutoProcessing == 'ReProcess'; |
2686 |
22 Sep 14 |
nicklas |
var name = (i+1) + ': ' + Strings.encodeTags(lysate.name); |
2686 |
22 Sep 14 |
nicklas |
if (lysate.bioWell) |
2686 |
22 Sep 14 |
nicklas |
74 |
{ |
2686 |
22 Sep 14 |
nicklas |
name += ' -- ' + Strings.encodeTags(lysate.bioWell.bioPlate.name + ' (' + lysate.bioWell.location+')'); |
2686 |
22 Sep 14 |
nicklas |
76 |
} |
3469 |
27 Aug 15 |
nicklas |
if (lysate.ReservedBy) |
3469 |
27 Aug 15 |
nicklas |
78 |
{ |
3469 |
27 Aug 15 |
nicklas |
name += ' ['+lysate.ReservedBy+']'; |
3469 |
27 Aug 15 |
nicklas |
80 |
} |
3469 |
27 Aug 15 |
nicklas |
81 |
|
3469 |
27 Aug 15 |
nicklas |
// We only auto-select items reserved by the current user (if it has any) |
3469 |
27 Aug 15 |
nicklas |
// and never any items reserved by other users |
3469 |
27 Aug 15 |
nicklas |
var selected = false; |
3469 |
27 Aug 15 |
nicklas |
if (numSelected < 12) |
3469 |
27 Aug 15 |
nicklas |
86 |
{ |
3740 |
11 Feb 16 |
nicklas |
if (hasReserved) |
3740 |
11 Feb 16 |
nicklas |
88 |
{ |
3740 |
11 Feb 16 |
nicklas |
selected = lysate.ReservedBy == currentUser; |
3740 |
11 Feb 16 |
nicklas |
90 |
} |
3740 |
11 Feb 16 |
nicklas |
else |
3740 |
11 Feb 16 |
nicklas |
92 |
{ |
3740 |
11 Feb 16 |
nicklas |
selected = isYellow || maxNonYellow > 0; |
3740 |
11 Feb 16 |
nicklas |
94 |
} |
3740 |
11 Feb 16 |
nicklas |
if (selected) |
3740 |
11 Feb 16 |
nicklas |
96 |
{ |
3740 |
11 Feb 16 |
nicklas |
numSelected++; |
3740 |
11 Feb 16 |
nicklas |
if (!isYellow) maxNonYellow--; |
3740 |
11 Feb 16 |
nicklas |
99 |
} |
3469 |
27 Aug 15 |
nicklas |
100 |
} |
3469 |
27 Aug 15 |
nicklas |
101 |
|
2686 |
22 Sep 14 |
nicklas |
var option = new Option(name, lysate.id, selected, selected); |
3740 |
11 Feb 16 |
nicklas |
if (isYellow) option.className = 'yellow'; |
2686 |
22 Sep 14 |
nicklas |
option.lysate = lysate; |
4097 |
13 Sep 16 |
nicklas |
if (lysate.isReProcess) |
4097 |
13 Sep 16 |
nicklas |
106 |
{ |
4097 |
13 Sep 16 |
nicklas |
reextractList.options[reextractList.length] = option; |
4097 |
13 Sep 16 |
nicklas |
108 |
} |
4097 |
13 Sep 16 |
nicklas |
else |
4097 |
13 Sep 16 |
nicklas |
110 |
{ |
4097 |
13 Sep 16 |
nicklas |
lysateList.options[lysateList.length] = option; |
4097 |
13 Sep 16 |
nicklas |
112 |
} |
2686 |
22 Sep 14 |
nicklas |
113 |
} |
4097 |
13 Sep 16 |
nicklas |
if (lysateList.length == 0) Doc.hide('regularFlowRow'); |
4097 |
13 Sep 16 |
nicklas |
if (reextractList.length > 0) Doc.show('reExtractionRow'); |
2686 |
22 Sep 14 |
nicklas |
protocol.lysatesOnChange(); |
2686 |
22 Sep 14 |
nicklas |
117 |
} |
2686 |
22 Sep 14 |
nicklas |
else |
2686 |
22 Sep 14 |
nicklas |
119 |
{ |
2686 |
22 Sep 14 |
nicklas |
Wizard.setFatalError('No Lysate available for processing.'); |
2686 |
22 Sep 14 |
nicklas |
return; |
2686 |
22 Sep 14 |
nicklas |
122 |
} |
2686 |
22 Sep 14 |
nicklas |
123 |
|
2686 |
22 Sep 14 |
nicklas |
Doc.show('step-1'); |
2686 |
22 Sep 14 |
nicklas |
Doc.show('gocreate'); |
2686 |
22 Sep 14 |
nicklas |
126 |
} |
2686 |
22 Sep 14 |
nicklas |
127 |
|
2686 |
22 Sep 14 |
nicklas |
128 |
|
2686 |
22 Sep 14 |
nicklas |
// Add pools to the pools list based on the bioplate selection |
2686 |
22 Sep 14 |
nicklas |
protocol.lysatesOnChange = function() |
2686 |
22 Sep 14 |
nicklas |
131 |
{ |
4097 |
13 Sep 16 |
nicklas |
var frm = document.forms['reggie']; |
2686 |
22 Sep 14 |
nicklas |
lysatesIsValid = false; |
4097 |
13 Sep 16 |
nicklas |
Wizard.setInputStatus('lysates'); |
4097 |
13 Sep 16 |
nicklas |
Wizard.setInputStatus('reextraction'); |
2686 |
22 Sep 14 |
nicklas |
136 |
|
4097 |
13 Sep 16 |
nicklas |
var numLysates = 0; |
4097 |
13 Sep 16 |
nicklas |
var numReextraction = 0; |
4097 |
13 Sep 16 |
nicklas |
var numUnselectedYellowLysates = 0; |
4097 |
13 Sep 16 |
nicklas |
var numUnselectedYellowReextraction = 0; |
2686 |
22 Sep 14 |
nicklas |
141 |
|
4097 |
13 Sep 16 |
nicklas |
for (var i = 0; i < frm.lysates.length; i++) |
2686 |
22 Sep 14 |
nicklas |
143 |
{ |
4097 |
13 Sep 16 |
nicklas |
var lysate = frm.lysates[i].lysate; |
4097 |
13 Sep 16 |
nicklas |
if (frm.lysates[i].selected) |
3740 |
11 Feb 16 |
nicklas |
146 |
{ |
4097 |
13 Sep 16 |
nicklas |
numLysates++; |
3740 |
11 Feb 16 |
nicklas |
148 |
} |
4097 |
13 Sep 16 |
nicklas |
else if (lysate.specimen.YellowLabel != null) |
3740 |
11 Feb 16 |
nicklas |
150 |
{ |
4097 |
13 Sep 16 |
nicklas |
numUnselectedYellowLysates++; |
3740 |
11 Feb 16 |
nicklas |
152 |
} |
2686 |
22 Sep 14 |
nicklas |
153 |
} |
4097 |
13 Sep 16 |
nicklas |
for (var i = 0; i < frm.reextraction.length; i++) |
4097 |
13 Sep 16 |
nicklas |
155 |
{ |
4097 |
13 Sep 16 |
nicklas |
var lysate = frm.reextraction[i].lysate; |
4097 |
13 Sep 16 |
nicklas |
if (frm.reextraction[i].selected) |
4097 |
13 Sep 16 |
nicklas |
158 |
{ |
4097 |
13 Sep 16 |
nicklas |
numReextraction++; |
4097 |
13 Sep 16 |
nicklas |
160 |
} |
4097 |
13 Sep 16 |
nicklas |
else if (lysate.specimen.YellowLabel != null) |
4097 |
13 Sep 16 |
nicklas |
162 |
{ |
4097 |
13 Sep 16 |
nicklas |
numUnselectedYellowReextraction++; |
4097 |
13 Sep 16 |
nicklas |
164 |
} |
4097 |
13 Sep 16 |
nicklas |
165 |
} |
2686 |
22 Sep 14 |
nicklas |
166 |
|
4097 |
13 Sep 16 |
nicklas |
if (numReextraction == 0 && numLysates == 0) |
2686 |
22 Sep 14 |
nicklas |
168 |
{ |
4097 |
13 Sep 16 |
nicklas |
Wizard.setInputStatus('lysates', 'invalid', 'At least one lysate must be selected'); |
4097 |
13 Sep 16 |
nicklas |
Wizard.setInputStatus('reextraction', 'invalid', 'At least one lysate must be selected'); |
2686 |
22 Sep 14 |
nicklas |
return; |
2686 |
22 Sep 14 |
nicklas |
172 |
} |
4097 |
13 Sep 16 |
nicklas |
173 |
|
4097 |
13 Sep 16 |
nicklas |
if (numReextraction+numLysates > 12) |
3466 |
25 Aug 15 |
nicklas |
175 |
{ |
4097 |
13 Sep 16 |
nicklas |
if (numLysates > 0) Wizard.setInputStatus('lysates', 'invalid', 'Must not select more than 12 items.'); |
4097 |
13 Sep 16 |
nicklas |
if (numReextraction > 0) Wizard.setInputStatus('reextraction', 'invalid', 'Must not select more than 12 items.'); |
3466 |
25 Aug 15 |
nicklas |
return; |
3466 |
25 Aug 15 |
nicklas |
179 |
} |
2686 |
22 Sep 14 |
nicklas |
180 |
|
2686 |
22 Sep 14 |
nicklas |
lysatesIsValid = true; |
4097 |
13 Sep 16 |
nicklas |
if (numUnselectedYellowLysates > 0) |
4097 |
13 Sep 16 |
nicklas |
183 |
{ |
4097 |
13 Sep 16 |
nicklas |
Wizard.setInputStatus('lysates', 'warning', 'Not all YellowLabel specimen are selected.'); |
4097 |
13 Sep 16 |
nicklas |
185 |
} |
4097 |
13 Sep 16 |
nicklas |
else |
4097 |
13 Sep 16 |
nicklas |
187 |
{ |
4097 |
13 Sep 16 |
nicklas |
Wizard.setInputStatus('lysates', 'valid'); |
4097 |
13 Sep 16 |
nicklas |
189 |
} |
4097 |
13 Sep 16 |
nicklas |
if (numUnselectedYellowReextraction > 0) |
4097 |
13 Sep 16 |
nicklas |
191 |
{ |
4097 |
13 Sep 16 |
nicklas |
Wizard.setInputStatus('reextraction', 'warning', 'Not all YellowLabel specimen are selected.'); |
4097 |
13 Sep 16 |
nicklas |
193 |
} |
4097 |
13 Sep 16 |
nicklas |
else |
4097 |
13 Sep 16 |
nicklas |
195 |
{ |
4097 |
13 Sep 16 |
nicklas |
Wizard.setInputStatus('reextraction', 'valid'); |
4097 |
13 Sep 16 |
nicklas |
197 |
} |
3740 |
11 Feb 16 |
nicklas |
198 |
|
4097 |
13 Sep 16 |
nicklas |
if (numReextraction > 0) |
3740 |
11 Feb 16 |
nicklas |
200 |
{ |
5304 |
15 Feb 19 |
nicklas |
Doc.removeClass('downloadLabelsCsv', 'disabled'); |
5304 |
15 Feb 19 |
nicklas |
Doc.removeClass('downloadLabelsXlsx', 'disabled'); |
3740 |
11 Feb 16 |
nicklas |
203 |
} |
3740 |
11 Feb 16 |
nicklas |
else |
3740 |
11 Feb 16 |
nicklas |
205 |
{ |
5304 |
15 Feb 19 |
nicklas |
Doc.addClass('downloadLabelsCsv', 'disabled'); |
5304 |
15 Feb 19 |
nicklas |
Doc.addClass('downloadLabelsXlsx', 'disabled'); |
3740 |
11 Feb 16 |
nicklas |
208 |
} |
4097 |
13 Sep 16 |
nicklas |
209 |
|
2686 |
22 Sep 14 |
nicklas |
210 |
} |
2686 |
22 Sep 14 |
nicklas |
211 |
|
5304 |
15 Feb 19 |
nicklas |
protocol.downloadLabels = function(event) |
4097 |
13 Sep 16 |
nicklas |
213 |
{ |
4097 |
13 Sep 16 |
nicklas |
var frm = document.forms['reggie']; |
5304 |
15 Feb 19 |
nicklas |
var format = Data.get(event.currentTarget, 'format'); |
4097 |
13 Sep 16 |
nicklas |
216 |
|
4097 |
13 Sep 16 |
nicklas |
var lysates = []; |
4097 |
13 Sep 16 |
nicklas |
for (var i = 0; i < frm.reextraction.length; i++) |
4097 |
13 Sep 16 |
nicklas |
219 |
{ |
4097 |
13 Sep 16 |
nicklas |
var lysate = frm.reextraction[i].lysate; |
4097 |
13 Sep 16 |
nicklas |
if (frm.reextraction[i].selected) |
4097 |
13 Sep 16 |
nicklas |
222 |
{ |
4097 |
13 Sep 16 |
nicklas |
lysates[lysates.length] = lysate.id; |
4097 |
13 Sep 16 |
nicklas |
224 |
} |
4097 |
13 Sep 16 |
nicklas |
225 |
} |
4097 |
13 Sep 16 |
nicklas |
226 |
|
4097 |
13 Sep 16 |
nicklas |
var frm = document.forms['reggie']; |
4097 |
13 Sep 16 |
nicklas |
var url = '../Extraction.servlet?ID='+App.getSessionId(); |
4097 |
13 Sep 16 |
nicklas |
url += '&cmd=DownloadLabelFile'; |
4097 |
13 Sep 16 |
nicklas |
url += '&lysates=' + encodeURIComponent(lysates.join(',')); |
5304 |
15 Feb 19 |
nicklas |
url += '&format='+encodeURIComponent(format); |
4097 |
13 Sep 16 |
nicklas |
window.open(url); |
4097 |
13 Sep 16 |
nicklas |
233 |
} |
4097 |
13 Sep 16 |
nicklas |
234 |
|
2686 |
22 Sep 14 |
nicklas |
protocol.viewProtocol = function() |
2686 |
22 Sep 14 |
nicklas |
236 |
{ |
2686 |
22 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2686 |
22 Sep 14 |
nicklas |
if (!lysatesIsValid) |
2686 |
22 Sep 14 |
nicklas |
239 |
{ |
2686 |
22 Sep 14 |
nicklas |
Wizard.notifyError(); |
2686 |
22 Sep 14 |
nicklas |
return; |
2686 |
22 Sep 14 |
nicklas |
242 |
} |
2686 |
22 Sep 14 |
nicklas |
frm.submit(); |
2686 |
22 Sep 14 |
nicklas |
244 |
} |
2686 |
22 Sep 14 |
nicklas |
245 |
|
3168 |
05 Mar 15 |
nicklas |
protocol.reagentsLoaded = function(response) |
3168 |
05 Mar 15 |
nicklas |
247 |
{ |
3168 |
05 Mar 15 |
nicklas |
var rna = response.rna; |
3168 |
05 Mar 15 |
nicklas |
var lysate = response.lysate; |
3168 |
05 Mar 15 |
nicklas |
if (rna) |
3168 |
05 Mar 15 |
nicklas |
251 |
{ |
3168 |
05 Mar 15 |
nicklas |
protocol.fillLatestReagents(rna); |
3168 |
05 Mar 15 |
nicklas |
Doc.element('latestQiaCubeDate').innerHTML = Reggie.reformatDate(rna.QiaCubeDate); |
3168 |
05 Mar 15 |
nicklas |
Doc.show('showLatestReagents', 'inline'); |
3168 |
05 Mar 15 |
nicklas |
255 |
} |
3168 |
05 Mar 15 |
nicklas |
if (lysate) protocol.fillLatestReagents(lysate); |
3168 |
05 Mar 15 |
nicklas |
257 |
} |
3168 |
05 Mar 15 |
nicklas |
258 |
|
3168 |
05 Mar 15 |
nicklas |
protocol.fillLatestReagents = function(item) |
3168 |
05 Mar 15 |
nicklas |
260 |
{ |
3168 |
05 Mar 15 |
nicklas |
for (var rg in item) |
3168 |
05 Mar 15 |
nicklas |
262 |
{ |
3168 |
05 Mar 15 |
nicklas |
if (item[rg] != null) |
3168 |
05 Mar 15 |
nicklas |
264 |
{ |
3168 |
05 Mar 15 |
nicklas |
var e = Doc.element(rg); |
3168 |
05 Mar 15 |
nicklas |
if (e) |
3168 |
05 Mar 15 |
nicklas |
267 |
{ |
3168 |
05 Mar 15 |
nicklas |
e.innerHTML = Strings.encodeTags(item[rg]); |
3168 |
05 Mar 15 |
nicklas |
269 |
} |
3168 |
05 Mar 15 |
nicklas |
270 |
|
3168 |
05 Mar 15 |
nicklas |
271 |
} |
3168 |
05 Mar 15 |
nicklas |
272 |
} |
3168 |
05 Mar 15 |
nicklas |
273 |
} |
3168 |
05 Mar 15 |
nicklas |
274 |
|
3168 |
05 Mar 15 |
nicklas |
protocol.toggleReagents = function(event) |
3168 |
05 Mar 15 |
nicklas |
276 |
{ |
3168 |
05 Mar 15 |
nicklas |
Doc.addOrRemoveClass(document.body, 'hide-reagents', !event.currentTarget.checked); |
3168 |
05 Mar 15 |
nicklas |
278 |
} |
4097 |
13 Sep 16 |
nicklas |
279 |
|
2686 |
22 Sep 14 |
nicklas |
return protocol; |
2686 |
22 Sep 14 |
nicklas |
281 |
}(); |
2686 |
22 Sep 14 |
nicklas |
282 |
|
2686 |
22 Sep 14 |
nicklas |
Doc.onLoad(Protocol.initPage); |
2686 |
22 Sep 14 |
nicklas |
284 |
|