5341 |
02 Apr 19 |
nicklas |
var PausedSpecimen = function() |
5341 |
02 Apr 19 |
nicklas |
2 |
{ |
5341 |
02 Apr 19 |
nicklas |
var paused = {}; |
5341 |
02 Apr 19 |
nicklas |
var debug = 0; |
5341 |
02 Apr 19 |
nicklas |
5 |
|
5341 |
02 Apr 19 |
nicklas |
var specimen; |
5341 |
02 Apr 19 |
nicklas |
var sites; |
5341 |
02 Apr 19 |
nicklas |
8 |
|
5341 |
02 Apr 19 |
nicklas |
// Page initialization |
5341 |
02 Apr 19 |
nicklas |
paused.initPage = function() |
5341 |
02 Apr 19 |
nicklas |
11 |
{ |
5341 |
02 Apr 19 |
nicklas |
// Step 1 |
5341 |
02 Apr 19 |
nicklas |
Events.addEventHandler('nameFilter', 'change', paused.filterOnChange); |
5341 |
02 Apr 19 |
nicklas |
Events.addEventHandler('statusFilter', 'change', paused.filterOnChange); |
5341 |
02 Apr 19 |
nicklas |
Events.addEventHandler('siteFilter', 'change', paused.filterOnChange); |
5341 |
02 Apr 19 |
nicklas |
Events.addEventHandler('samplingDateFilter', 'change', paused.filterOnChange); |
5341 |
02 Apr 19 |
nicklas |
Events.addEventHandler('arrivalDateFilter', 'change', paused.filterOnChange); |
5341 |
02 Apr 19 |
nicklas |
Events.addEventHandler('storageBoxFilter', 'change', paused.filterOnChange); |
5341 |
02 Apr 19 |
nicklas |
Buttons.addClickHandler('btnExtractSpecimen', paused.extractSpecimen); |
5341 |
02 Apr 19 |
nicklas |
Buttons.addClickHandler('btnPauseSpecimen', paused.pauseSpecimen); |
5344 |
02 Apr 19 |
nicklas |
Buttons.addClickHandler('btnPauseSettings', paused.openSettings); |
5341 |
02 Apr 19 |
nicklas |
Buttons.addClickHandler('check_uncheck', paused.selectAll); |
5341 |
02 Apr 19 |
nicklas |
23 |
|
5341 |
02 Apr 19 |
nicklas |
// Navigation |
5341 |
02 Apr 19 |
nicklas |
Buttons.addClickHandler('gocancel', Wizard.cancelWizard); |
5341 |
02 Apr 19 |
nicklas |
Buttons.addClickHandler('gorestart', Wizard.restartWizard); |
5341 |
02 Apr 19 |
nicklas |
Buttons.addClickHandler('gonext', Wizard.goNextOnClick); |
5341 |
02 Apr 19 |
nicklas |
Buttons.addClickHandler('goregister', Wizard.goRegister); |
5341 |
02 Apr 19 |
nicklas |
29 |
|
5341 |
02 Apr 19 |
nicklas |
30 |
|
5341 |
02 Apr 19 |
nicklas |
var url = '../SpecimenTubeRegistration.servlet?ID='+App.getSessionId(); |
5341 |
02 Apr 19 |
nicklas |
url += '&cmd=GetPausedSpecimenTubes'; |
5341 |
02 Apr 19 |
nicklas |
Wizard.showLoadingAnimation('Loading paused specimen...'); |
5341 |
02 Apr 19 |
nicklas |
Wizard.asyncJsonRequest(url, paused.onSpecimenLoaded); |
5341 |
02 Apr 19 |
nicklas |
35 |
} |
5341 |
02 Apr 19 |
nicklas |
36 |
|
5341 |
02 Apr 19 |
nicklas |
paused.onSpecimenLoaded = function(response) |
5341 |
02 Apr 19 |
nicklas |
38 |
{ |
5341 |
02 Apr 19 |
nicklas |
specimen = response.specimenTubes; |
5341 |
02 Apr 19 |
nicklas |
sites = response.sites; |
5341 |
02 Apr 19 |
nicklas |
41 |
|
5341 |
02 Apr 19 |
nicklas |
var frm = document.forms['reggie']; |
5341 |
02 Apr 19 |
nicklas |
var siteCount = []; |
5344 |
02 Apr 19 |
nicklas |
var pausedSites = []; |
5341 |
02 Apr 19 |
nicklas |
for (var siteNo = 0; siteNo < sites.length; siteNo++) |
5341 |
02 Apr 19 |
nicklas |
46 |
{ |
5341 |
02 Apr 19 |
nicklas |
var site = sites[siteNo]; |
5344 |
02 Apr 19 |
nicklas |
if (site.paused) pausedSites[pausedSites.length] = site.name; |
5341 |
02 Apr 19 |
nicklas |
siteCount[site.prefix] = 0; |
5341 |
02 Apr 19 |
nicklas |
50 |
} |
5344 |
02 Apr 19 |
nicklas |
Doc.element('pausedInfo').innerHTML = pausedSites.length > 0 ? |
5344 |
02 Apr 19 |
nicklas |
'<b>Paused sites</b>: ' + pausedSites.join(', ') : '<b>No sites are paused</b>'; |
5341 |
02 Apr 19 |
nicklas |
53 |
|
5341 |
02 Apr 19 |
nicklas |
var html = ''; |
5341 |
02 Apr 19 |
nicklas |
for (var spNo = 0; spNo < specimen.length; spNo++) |
5341 |
02 Apr 19 |
nicklas |
56 |
{ |
5341 |
02 Apr 19 |
nicklas |
var sp = specimen[spNo]; |
5341 |
02 Apr 19 |
nicklas |
sp.include = true; |
5341 |
02 Apr 19 |
nicklas |
siteCount[sp.site.prefix]++; |
5341 |
02 Apr 19 |
nicklas |
var rowClass = 'highlight'; |
5341 |
02 Apr 19 |
nicklas |
rowClass += spNo % 2 == 0 ? ' oddrow' : ' evenrow'; |
5341 |
02 Apr 19 |
nicklas |
if (sp.YellowLabel != null) rowClass += ' yellow-specimen'; |
5341 |
02 Apr 19 |
nicklas |
63 |
|
5341 |
02 Apr 19 |
nicklas |
html += '<tr class="' + rowClass + '" id="specimen.'+sp.id + '">'; |
5341 |
02 Apr 19 |
nicklas |
html += '<td><span id="index.'+sp.id+'">'+(spNo+1)+'</span> <input type="checkbox" name="sp.'+sp.id+'"></td>'; |
5341 |
02 Apr 19 |
nicklas |
html += '<td class="dottedleft if-yellow"><span class="link linked-item" data-item-type="SAMPLE" data-item-id="'+sp.id+'">'+Strings.encodeTags(sp.name)+'</span>'; |
5341 |
02 Apr 19 |
nicklas |
html += '<img class="link case-summary" data-name="'+Strings.encodeTags(sp.name)+'" src="../images/case_summary.png"></td>'; |
5341 |
02 Apr 19 |
nicklas |
html += '<td>'+(sp.AutoProcessing == 'Disable' ? 'Paused' : 'Scheduled') + '</td>'; |
5341 |
02 Apr 19 |
nicklas |
html += '<td>'+Strings.encodeTags(sp.site.name) + '</td>'; |
5341 |
02 Apr 19 |
nicklas |
html += '<td>'+Reggie.reformatDate(sp.SamplingDate)+'</td>'; |
5341 |
02 Apr 19 |
nicklas |
html += '<td>'+Reggie.reformatDate(sp.ArrivalDate)+'</td>'; |
5341 |
02 Apr 19 |
nicklas |
html += '<td>'+Strings.encodeTags(sp.bioWell.bioPlate.name + ' ' + sp.bioWell.location)+'</td>'; |
5341 |
02 Apr 19 |
nicklas |
html += '<td style="width: auto;"></td>'; |
5341 |
02 Apr 19 |
nicklas |
html += '</tr>'; |
5341 |
02 Apr 19 |
nicklas |
75 |
} |
5341 |
02 Apr 19 |
nicklas |
76 |
|
5341 |
02 Apr 19 |
nicklas |
Doc.element('specimen-list').innerHTML = html; |
5341 |
02 Apr 19 |
nicklas |
78 |
|
5341 |
02 Apr 19 |
nicklas |
frm.siteFilter.length = 0; |
5341 |
02 Apr 19 |
nicklas |
frm.siteFilter[0] = new Option(' ', ''); |
5341 |
02 Apr 19 |
nicklas |
for (var siteNo = 0; siteNo < sites.length; siteNo++) |
5341 |
02 Apr 19 |
nicklas |
82 |
{ |
5341 |
02 Apr 19 |
nicklas |
var site = sites[siteNo]; |
5341 |
02 Apr 19 |
nicklas |
frm.siteFilter[frm.siteFilter.length] = new Option(site.name + ' ('+siteCount[site.prefix]+')', site.prefix); |
5341 |
02 Apr 19 |
nicklas |
85 |
} |
5341 |
02 Apr 19 |
nicklas |
86 |
|
5341 |
02 Apr 19 |
nicklas |
paused.filterOnChange(); |
5341 |
02 Apr 19 |
nicklas |
88 |
|
5341 |
02 Apr 19 |
nicklas |
if (submitMessages) |
5341 |
02 Apr 19 |
nicklas |
90 |
{ |
5341 |
02 Apr 19 |
nicklas |
Wizard.showFinalMessage(submitMessages); |
5341 |
02 Apr 19 |
nicklas |
submitMessages = null; |
5341 |
02 Apr 19 |
nicklas |
setTimeout(Wizard.showFinalMessage, 10000, []); // Hide after 10 seconds |
5341 |
02 Apr 19 |
nicklas |
94 |
} |
5341 |
02 Apr 19 |
nicklas |
95 |
|
5341 |
02 Apr 19 |
nicklas |
Doc.show('step-1'); |
5341 |
02 Apr 19 |
nicklas |
97 |
|
5341 |
02 Apr 19 |
nicklas |
var cs = document.getElementsByClassName('case-summary'); |
5341 |
02 Apr 19 |
nicklas |
for (var i = 0; i < cs.length; i++) |
5341 |
02 Apr 19 |
nicklas |
100 |
{ |
5341 |
02 Apr 19 |
nicklas |
Events.addEventHandler(cs[i], 'click', Reggie.openCaseSummaryPopupOnEvent); |
5341 |
02 Apr 19 |
nicklas |
102 |
} |
5341 |
02 Apr 19 |
nicklas |
103 |
|
5341 |
02 Apr 19 |
nicklas |
var linkedItems = document.getElementsByClassName('linked-item'); |
5341 |
02 Apr 19 |
nicklas |
for (var itemNo = 0; itemNo < linkedItems.length; itemNo++) |
5341 |
02 Apr 19 |
nicklas |
106 |
{ |
5341 |
02 Apr 19 |
nicklas |
Events.addEventHandler(linkedItems[itemNo], 'click', Items.itemOnClick); |
5341 |
02 Apr 19 |
nicklas |
108 |
} |
5341 |
02 Apr 19 |
nicklas |
109 |
} |
5341 |
02 Apr 19 |
nicklas |
110 |
|
5341 |
02 Apr 19 |
nicklas |
paused.selectAll = function() |
5341 |
02 Apr 19 |
nicklas |
112 |
{ |
5341 |
02 Apr 19 |
nicklas |
var frm = document.forms['reggie']; |
5341 |
02 Apr 19 |
nicklas |
var firstChecked = null; |
5341 |
02 Apr 19 |
nicklas |
for (var spNo = 0; spNo < specimen.length; spNo++) |
5341 |
02 Apr 19 |
nicklas |
116 |
{ |
5341 |
02 Apr 19 |
nicklas |
var sp = specimen[spNo]; |
5341 |
02 Apr 19 |
nicklas |
if (sp.include) |
5341 |
02 Apr 19 |
nicklas |
119 |
{ |
5341 |
02 Apr 19 |
nicklas |
if (firstChecked == null) |
5341 |
02 Apr 19 |
nicklas |
121 |
{ |
5341 |
02 Apr 19 |
nicklas |
firstChecked = frm['sp.'+sp.id].checked; |
5341 |
02 Apr 19 |
nicklas |
123 |
} |
5341 |
02 Apr 19 |
nicklas |
frm['sp.'+sp.id].checked = !firstChecked; |
5341 |
02 Apr 19 |
nicklas |
125 |
} |
5341 |
02 Apr 19 |
nicklas |
126 |
} |
5341 |
02 Apr 19 |
nicklas |
127 |
} |
5341 |
02 Apr 19 |
nicklas |
128 |
|
5341 |
02 Apr 19 |
nicklas |
paused.filterOnChange = function() |
5341 |
02 Apr 19 |
nicklas |
130 |
{ |
5341 |
02 Apr 19 |
nicklas |
var frm = document.forms['reggie']; |
5341 |
02 Apr 19 |
nicklas |
132 |
|
5341 |
02 Apr 19 |
nicklas |
var filter = new Filter(); |
5341 |
02 Apr 19 |
nicklas |
filter.addContainsCriteria(ItemProperty.Name, frm.nameFilter.value); |
5341 |
02 Apr 19 |
nicklas |
filter.addTextCriteria(ItemProperty.AutoProcessing, frm.statusFilter.value); |
5341 |
02 Apr 19 |
nicklas |
filter.addTextCriteria(ItemProperty.Site, frm.siteFilter.value); |
5341 |
02 Apr 19 |
nicklas |
filter.addDateCriteria(ItemProperty.SamplingDate, frm.samplingDateFilter.value); |
5341 |
02 Apr 19 |
nicklas |
filter.addDateCriteria(ItemProperty.ArrivalDate, frm.arrivalDateFilter.value); |
5341 |
02 Apr 19 |
nicklas |
filter.addContainsCriteria(ItemProperty.StorageBox, frm.storageBoxFilter.value); |
5341 |
02 Apr 19 |
nicklas |
140 |
|
5341 |
02 Apr 19 |
nicklas |
var index = 0; |
5341 |
02 Apr 19 |
nicklas |
var numPaused = 0; |
5341 |
02 Apr 19 |
nicklas |
for (var spNo = 0; spNo < specimen.length; spNo++) |
5341 |
02 Apr 19 |
nicklas |
144 |
{ |
5341 |
02 Apr 19 |
nicklas |
var sp = specimen[spNo]; |
5341 |
02 Apr 19 |
nicklas |
sp.include = filter.check(sp); |
5341 |
02 Apr 19 |
nicklas |
var tr = Doc.element('specimen.'+sp.id); |
5341 |
02 Apr 19 |
nicklas |
if (sp.include) |
5341 |
02 Apr 19 |
nicklas |
149 |
{ |
5341 |
02 Apr 19 |
nicklas |
index++; |
5341 |
02 Apr 19 |
nicklas |
var evenRow = index % 2 == 0; |
5341 |
02 Apr 19 |
nicklas |
Doc.addOrRemoveClass(tr, 'oddrow', !evenRow); |
5341 |
02 Apr 19 |
nicklas |
Doc.addOrRemoveClass(tr, 'evenrow', evenRow); |
5341 |
02 Apr 19 |
nicklas |
Doc.element('index.'+sp.id).innerHTML = index; |
5341 |
02 Apr 19 |
nicklas |
Doc.show(tr); |
5341 |
02 Apr 19 |
nicklas |
if (sp.AutoProcessing == 'Disable') numPaused++; |
5341 |
02 Apr 19 |
nicklas |
157 |
} |
5341 |
02 Apr 19 |
nicklas |
else |
5341 |
02 Apr 19 |
nicklas |
159 |
{ |
5341 |
02 Apr 19 |
nicklas |
Doc.hide(tr); |
5341 |
02 Apr 19 |
nicklas |
161 |
} |
5341 |
02 Apr 19 |
nicklas |
162 |
} |
5341 |
02 Apr 19 |
nicklas |
163 |
|
5341 |
02 Apr 19 |
nicklas |
Doc.showHide('specimen-list', index != 0); |
5341 |
02 Apr 19 |
nicklas |
Doc.showHide('no-match', index==0); |
5341 |
02 Apr 19 |
nicklas |
Doc.addOrRemoveClass('btnExtractSpecimen', 'disabled', numPaused==0); |
5341 |
02 Apr 19 |
nicklas |
Doc.addOrRemoveClass('btnPauseSpecimen', 'disabled', index==numPaused); |
5341 |
02 Apr 19 |
nicklas |
168 |
|
5341 |
02 Apr 19 |
nicklas |
Doc.element('num-matching').innerHTML = index; |
5341 |
02 Apr 19 |
nicklas |
170 |
} |
5341 |
02 Apr 19 |
nicklas |
171 |
|
5341 |
02 Apr 19 |
nicklas |
paused.checkSelected = function(noNotification) |
5341 |
02 Apr 19 |
nicklas |
173 |
{ |
5341 |
02 Apr 19 |
nicklas |
var frm = document.forms['reggie']; |
5341 |
02 Apr 19 |
nicklas |
var selected = []; |
5341 |
02 Apr 19 |
nicklas |
176 |
|
5341 |
02 Apr 19 |
nicklas |
for (var spNo = 0; spNo < specimen.length; spNo++) |
5341 |
02 Apr 19 |
nicklas |
178 |
{ |
5341 |
02 Apr 19 |
nicklas |
var sp = specimen[spNo]; |
5341 |
02 Apr 19 |
nicklas |
if (sp.include && frm['sp.'+sp.id].checked) |
5341 |
02 Apr 19 |
nicklas |
181 |
{ |
5341 |
02 Apr 19 |
nicklas |
selected[selected.length] = sp.id; |
5341 |
02 Apr 19 |
nicklas |
183 |
} |
5341 |
02 Apr 19 |
nicklas |
184 |
} |
5341 |
02 Apr 19 |
nicklas |
185 |
|
5341 |
02 Apr 19 |
nicklas |
if (selected.length == 0 && !noNotification) |
5341 |
02 Apr 19 |
nicklas |
187 |
{ |
5341 |
02 Apr 19 |
nicklas |
Forms.showNotification('check_uncheck', 'Please select at least one specimen from the list', null, 'pointer-below'); |
5341 |
02 Apr 19 |
nicklas |
189 |
} |
5341 |
02 Apr 19 |
nicklas |
190 |
|
5341 |
02 Apr 19 |
nicklas |
return selected; |
5341 |
02 Apr 19 |
nicklas |
192 |
} |
5341 |
02 Apr 19 |
nicklas |
193 |
|
5341 |
02 Apr 19 |
nicklas |
paused.extractSpecimen = function() |
5341 |
02 Apr 19 |
nicklas |
195 |
{ |
5341 |
02 Apr 19 |
nicklas |
var selected = paused.checkSelected(); |
5341 |
02 Apr 19 |
nicklas |
if (selected.length == 0) return; |
5341 |
02 Apr 19 |
nicklas |
198 |
|
5341 |
02 Apr 19 |
nicklas |
var submitInfo = {}; |
5341 |
02 Apr 19 |
nicklas |
submitInfo.specimen = selected; |
5341 |
02 Apr 19 |
nicklas |
var url = '../SpecimenTubeRegistration.servlet?ID='+App.getSessionId(); |
5341 |
02 Apr 19 |
nicklas |
url += '&cmd=SchedulePausedSpecimenForExtraction'; |
5341 |
02 Apr 19 |
nicklas |
Wizard.showLoadingAnimation('Registering selected specimen for extraction...'); |
5341 |
02 Apr 19 |
nicklas |
Wizard.asyncJsonRequest(url, paused.submissionResults, 'POST', JSON.stringify(submitInfo)); |
5341 |
02 Apr 19 |
nicklas |
205 |
} |
5341 |
02 Apr 19 |
nicklas |
206 |
|
5341 |
02 Apr 19 |
nicklas |
paused.pauseSpecimen = function() |
5341 |
02 Apr 19 |
nicklas |
208 |
{ |
5341 |
02 Apr 19 |
nicklas |
var selected = paused.checkSelected(); |
5341 |
02 Apr 19 |
nicklas |
if (selected.length == 0) return; |
5341 |
02 Apr 19 |
nicklas |
211 |
|
5341 |
02 Apr 19 |
nicklas |
var submitInfo = {}; |
5341 |
02 Apr 19 |
nicklas |
submitInfo.specimen = selected; |
5341 |
02 Apr 19 |
nicklas |
var url = '../SpecimenTubeRegistration.servlet?ID='+App.getSessionId(); |
5341 |
02 Apr 19 |
nicklas |
url += '&cmd=RegisterPausedSpecimen'; |
5341 |
02 Apr 19 |
nicklas |
Wizard.showLoadingAnimation('Registering selected specimen as paused...'); |
5341 |
02 Apr 19 |
nicklas |
Wizard.asyncJsonRequest(url, paused.submissionResults, 'POST', JSON.stringify(submitInfo)); |
5341 |
02 Apr 19 |
nicklas |
218 |
} |
5341 |
02 Apr 19 |
nicklas |
219 |
|
5344 |
02 Apr 19 |
nicklas |
paused.openSettings = function() |
5344 |
02 Apr 19 |
nicklas |
221 |
{ |
5344 |
02 Apr 19 |
nicklas |
var url = 'pause-settings.jsp?ID='+App.getSessionId(); |
5344 |
02 Apr 19 |
nicklas |
Dialogs.openPopup(url, 'PauseSettings', 500, 350); |
5344 |
02 Apr 19 |
nicklas |
224 |
} |
5344 |
02 Apr 19 |
nicklas |
225 |
|
5341 |
02 Apr 19 |
nicklas |
var submitMessages; |
5341 |
02 Apr 19 |
nicklas |
// Re-load the updated information |
5341 |
02 Apr 19 |
nicklas |
paused.submissionResults = function(response) |
5341 |
02 Apr 19 |
nicklas |
229 |
{ |
5341 |
02 Apr 19 |
nicklas |
submitMessages = response.messages; |
5341 |
02 Apr 19 |
nicklas |
var url = '../SpecimenTubeRegistration.servlet?ID='+App.getSessionId(); |
5341 |
02 Apr 19 |
nicklas |
url += '&cmd=GetPausedSpecimenTubes'; |
5341 |
02 Apr 19 |
nicklas |
Wizard.showLoadingAnimation('Loading paused specimen...'); |
5341 |
02 Apr 19 |
nicklas |
Wizard.asyncJsonRequest(url, paused.onSpecimenLoaded); |
5341 |
02 Apr 19 |
nicklas |
235 |
} |
5341 |
02 Apr 19 |
nicklas |
236 |
|
5341 |
02 Apr 19 |
nicklas |
return paused; |
5341 |
02 Apr 19 |
nicklas |
238 |
}(); |
5341 |
02 Apr 19 |
nicklas |
239 |
|
5341 |
02 Apr 19 |
nicklas |
Doc.onLoad(PausedSpecimen.initPage); |
5341 |
02 Apr 19 |
nicklas |
241 |
|
5341 |
02 Apr 19 |
nicklas |
242 |
|
5341 |
02 Apr 19 |
nicklas |
243 |
/** |
5341 |
02 Apr 19 |
nicklas |
Holds one or more filter criterias. Use the 'add*' methods |
5341 |
02 Apr 19 |
nicklas |
to add criterias to the filter, and the 'check(specimen)' method |
5341 |
02 Apr 19 |
nicklas |
to evaluate all criterias against a single specimen item. |
5341 |
02 Apr 19 |
nicklas |
247 |
*/ |
5341 |
02 Apr 19 |
nicklas |
var Filter = function() |
5341 |
02 Apr 19 |
nicklas |
249 |
{ |
5341 |
02 Apr 19 |
nicklas |
this.criterias = []; |
5341 |
02 Apr 19 |
nicklas |
251 |
} |
5341 |
02 Apr 19 |
nicklas |
252 |
|
5341 |
02 Apr 19 |
nicklas |
253 |
/** |
5341 |
02 Apr 19 |
nicklas |
Adds a text criteria comparing the given property to |
5341 |
02 Apr 19 |
nicklas |
a static value (f2). |
5341 |
02 Apr 19 |
nicklas |
256 |
*/ |
5341 |
02 Apr 19 |
nicklas |
Filter.prototype.addTextCriteria = function(itemProp, f2) |
5341 |
02 Apr 19 |
nicklas |
258 |
{ |
5341 |
02 Apr 19 |
nicklas |
if (f2 != '') |
5341 |
02 Apr 19 |
nicklas |
260 |
{ |
5341 |
02 Apr 19 |
nicklas |
var cmp; |
5341 |
02 Apr 19 |
nicklas |
if (f2 == '=') |
5341 |
02 Apr 19 |
nicklas |
263 |
{ |
5341 |
02 Apr 19 |
nicklas |
cmp = Comparator.eq; |
5341 |
02 Apr 19 |
nicklas |
f2 = null; |
5341 |
02 Apr 19 |
nicklas |
266 |
} |
5341 |
02 Apr 19 |
nicklas |
else if (f2 == '<>') |
5341 |
02 Apr 19 |
nicklas |
268 |
{ |
5341 |
02 Apr 19 |
nicklas |
cmp = Comparator.neq; |
5341 |
02 Apr 19 |
nicklas |
f2 = null; |
5341 |
02 Apr 19 |
nicklas |
271 |
} |
5341 |
02 Apr 19 |
nicklas |
else |
5341 |
02 Apr 19 |
nicklas |
273 |
{ |
5341 |
02 Apr 19 |
nicklas |
cmp = Comparator.eq; |
5341 |
02 Apr 19 |
nicklas |
275 |
} |
5341 |
02 Apr 19 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return cmp(itemProp(item), f2) }; |
5341 |
02 Apr 19 |
nicklas |
277 |
} |
5341 |
02 Apr 19 |
nicklas |
278 |
} |
5341 |
02 Apr 19 |
nicklas |
279 |
|
5341 |
02 Apr 19 |
nicklas |
280 |
/** |
5341 |
02 Apr 19 |
nicklas |
Adds a text criteria checking if the given item property to |
5341 |
02 Apr 19 |
nicklas |
contains a static value (f2). |
5341 |
02 Apr 19 |
nicklas |
283 |
*/ |
5341 |
02 Apr 19 |
nicklas |
Filter.prototype.addContainsCriteria = function(itemProp, f2) |
5341 |
02 Apr 19 |
nicklas |
285 |
{ |
5341 |
02 Apr 19 |
nicklas |
if (f2 != '') |
5341 |
02 Apr 19 |
nicklas |
287 |
{ |
5341 |
02 Apr 19 |
nicklas |
var cmp; |
5341 |
02 Apr 19 |
nicklas |
if (f2 == '=') |
5341 |
02 Apr 19 |
nicklas |
290 |
{ |
5341 |
02 Apr 19 |
nicklas |
cmp = Comparator.eq; |
5341 |
02 Apr 19 |
nicklas |
f2 = null; |
5341 |
02 Apr 19 |
nicklas |
293 |
} |
5341 |
02 Apr 19 |
nicklas |
else if (f2 == '<>') |
5341 |
02 Apr 19 |
nicklas |
295 |
{ |
5341 |
02 Apr 19 |
nicklas |
cmp = Comparator.neq; |
5341 |
02 Apr 19 |
nicklas |
f2 = null; |
5341 |
02 Apr 19 |
nicklas |
298 |
} |
5341 |
02 Apr 19 |
nicklas |
else |
5341 |
02 Apr 19 |
nicklas |
300 |
{ |
5341 |
02 Apr 19 |
nicklas |
cmp = Comparator.contains; |
5341 |
02 Apr 19 |
nicklas |
302 |
} |
5341 |
02 Apr 19 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return cmp(itemProp(item), f2) }; |
5341 |
02 Apr 19 |
nicklas |
304 |
} |
5341 |
02 Apr 19 |
nicklas |
305 |
} |
5341 |
02 Apr 19 |
nicklas |
306 |
|
5341 |
02 Apr 19 |
nicklas |
307 |
/** |
5341 |
02 Apr 19 |
nicklas |
Adds a temporal criteria for comparing dates. The 'f2' value |
5341 |
02 Apr 19 |
nicklas |
may start with either '<' or '>' to compare with earlier/later |
5341 |
02 Apr 19 |
nicklas |
than operators. In all cases, the 'f2' value is stripped from '-' |
5341 |
02 Apr 19 |
nicklas |
characters. |
5341 |
02 Apr 19 |
nicklas |
312 |
*/ |
5341 |
02 Apr 19 |
nicklas |
Filter.prototype.addDateCriteria = function(itemProp, f2) |
5341 |
02 Apr 19 |
nicklas |
314 |
{ |
5341 |
02 Apr 19 |
nicklas |
if (f2 != '') |
5341 |
02 Apr 19 |
nicklas |
316 |
{ |
5341 |
02 Apr 19 |
nicklas |
var cmp; |
5341 |
02 Apr 19 |
nicklas |
if (f2 == '=') |
5341 |
02 Apr 19 |
nicklas |
319 |
{ |
5341 |
02 Apr 19 |
nicklas |
cmp = Comparator.eq; |
5341 |
02 Apr 19 |
nicklas |
f2 = null; |
5341 |
02 Apr 19 |
nicklas |
322 |
} |
5341 |
02 Apr 19 |
nicklas |
else if (f2 == '<>') |
5341 |
02 Apr 19 |
nicklas |
324 |
{ |
5341 |
02 Apr 19 |
nicklas |
cmp = Comparator.neq; |
5341 |
02 Apr 19 |
nicklas |
f2 = null; |
5341 |
02 Apr 19 |
nicklas |
327 |
} |
5341 |
02 Apr 19 |
nicklas |
else |
5341 |
02 Apr 19 |
nicklas |
329 |
{ |
5341 |
02 Apr 19 |
nicklas |
var firstChar = f2.charAt(0); |
5341 |
02 Apr 19 |
nicklas |
if (firstChar == '<' || firstChar == '>') f2 = f2.substring(1); |
5341 |
02 Apr 19 |
nicklas |
f2 = f2.replace(/\-/g, ''); |
5341 |
02 Apr 19 |
nicklas |
cmp = Comparator.get(firstChar, Comparator.startsWith); |
5341 |
02 Apr 19 |
nicklas |
334 |
} |
5341 |
02 Apr 19 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return cmp(itemProp(item), f2) }; |
5341 |
02 Apr 19 |
nicklas |
336 |
} |
5341 |
02 Apr 19 |
nicklas |
337 |
} |
5341 |
02 Apr 19 |
nicklas |
338 |
|
5341 |
02 Apr 19 |
nicklas |
339 |
|
5341 |
02 Apr 19 |
nicklas |
340 |
/** |
5341 |
02 Apr 19 |
nicklas |
Evaluate all criterias. Return true if all pass, false otherwise. |
5341 |
02 Apr 19 |
nicklas |
342 |
*/ |
5341 |
02 Apr 19 |
nicklas |
Filter.prototype.check = function(sp) |
5341 |
02 Apr 19 |
nicklas |
344 |
{ |
5341 |
02 Apr 19 |
nicklas |
for (var i = 0; i < this.criterias.length; i++) |
5341 |
02 Apr 19 |
nicklas |
346 |
{ |
5341 |
02 Apr 19 |
nicklas |
if (!this.criterias[i](sp)) return false; |
5341 |
02 Apr 19 |
nicklas |
348 |
} |
5341 |
02 Apr 19 |
nicklas |
return true; |
5341 |
02 Apr 19 |
nicklas |
350 |
} |
5341 |
02 Apr 19 |
nicklas |
351 |
|
5341 |
02 Apr 19 |
nicklas |
352 |
/** |
5341 |
02 Apr 19 |
nicklas |
Functions for extracting various properties from |
5341 |
02 Apr 19 |
nicklas |
specimen items. Each method accepts a single specimen as a parameter |
5341 |
02 Apr 19 |
nicklas |
and return a value from the specimen item. The methods |
5341 |
02 Apr 19 |
nicklas |
are used as parameters to Filter.add*Criteria() methods. |
5341 |
02 Apr 19 |
nicklas |
357 |
*/ |
5341 |
02 Apr 19 |
nicklas |
var ItemProperty = function() |
5341 |
02 Apr 19 |
nicklas |
359 |
{ |
5341 |
02 Apr 19 |
nicklas |
var p = {}; |
5341 |
02 Apr 19 |
nicklas |
361 |
|
5341 |
02 Apr 19 |
nicklas |
p.Name = function(item) |
5341 |
02 Apr 19 |
nicklas |
363 |
{ |
5341 |
02 Apr 19 |
nicklas |
return item.name; |
5341 |
02 Apr 19 |
nicklas |
365 |
} |
5341 |
02 Apr 19 |
nicklas |
366 |
|
5341 |
02 Apr 19 |
nicklas |
p.AutoProcessing = function(item) |
5341 |
02 Apr 19 |
nicklas |
368 |
{ |
5341 |
02 Apr 19 |
nicklas |
return item.AutoProcessing; |
5341 |
02 Apr 19 |
nicklas |
370 |
} |
5341 |
02 Apr 19 |
nicklas |
371 |
|
5341 |
02 Apr 19 |
nicklas |
// Get the item.site.prefix value |
5341 |
02 Apr 19 |
nicklas |
p.Site = function(item) |
5341 |
02 Apr 19 |
nicklas |
374 |
{ |
5341 |
02 Apr 19 |
nicklas |
return item.site.prefix; |
5341 |
02 Apr 19 |
nicklas |
376 |
} |
5341 |
02 Apr 19 |
nicklas |
377 |
|
5341 |
02 Apr 19 |
nicklas |
p.ArrivalDate = function(item) |
5341 |
02 Apr 19 |
nicklas |
379 |
{ |
5341 |
02 Apr 19 |
nicklas |
return item.ArrivalDate; |
5341 |
02 Apr 19 |
nicklas |
381 |
} |
5341 |
02 Apr 19 |
nicklas |
382 |
|
5341 |
02 Apr 19 |
nicklas |
p.SamplingDate = function(item) |
5341 |
02 Apr 19 |
nicklas |
384 |
{ |
5341 |
02 Apr 19 |
nicklas |
return item.SamplingDate; |
5341 |
02 Apr 19 |
nicklas |
386 |
} |
5341 |
02 Apr 19 |
nicklas |
387 |
|
5341 |
02 Apr 19 |
nicklas |
p.StorageBox = function(item) |
5341 |
02 Apr 19 |
nicklas |
389 |
{ |
5341 |
02 Apr 19 |
nicklas |
return item.bioWell.bioPlate.name + ' ' + item.bioWell.location; |
5341 |
02 Apr 19 |
nicklas |
391 |
} |
5341 |
02 Apr 19 |
nicklas |
392 |
|
5341 |
02 Apr 19 |
nicklas |
return p; |
5341 |
02 Apr 19 |
nicklas |
394 |
}(); |
5341 |
02 Apr 19 |
nicklas |
395 |
|
5341 |
02 Apr 19 |
nicklas |
396 |
/** |
5341 |
02 Apr 19 |
nicklas |
Comparator functions for comparing two values. |
5341 |
02 Apr 19 |
nicklas |
398 |
*/ |
5341 |
02 Apr 19 |
nicklas |
var Comparator = function() |
5341 |
02 Apr 19 |
nicklas |
400 |
{ |
5341 |
02 Apr 19 |
nicklas |
var cmp = {}; |
5341 |
02 Apr 19 |
nicklas |
402 |
|
5341 |
02 Apr 19 |
nicklas |
403 |
/** |
5341 |
02 Apr 19 |
nicklas |
Return a comparator based on the symbol |
5341 |
02 Apr 19 |
nicklas |
which can be either '>' or '<' to return |
5341 |
02 Apr 19 |
nicklas |
Comparator.gt or Comparator.lt. Otherwise |
5341 |
02 Apr 19 |
nicklas |
the given default or Comparator.eq is returned. |
5341 |
02 Apr 19 |
nicklas |
408 |
*/ |
5341 |
02 Apr 19 |
nicklas |
cmp.get = function(symbol, defaultCmp) |
5341 |
02 Apr 19 |
nicklas |
410 |
{ |
5341 |
02 Apr 19 |
nicklas |
var c; |
5341 |
02 Apr 19 |
nicklas |
if (symbol == '<') |
5341 |
02 Apr 19 |
nicklas |
413 |
{ |
5341 |
02 Apr 19 |
nicklas |
c = cmp.lt; |
5341 |
02 Apr 19 |
nicklas |
415 |
} |
5341 |
02 Apr 19 |
nicklas |
else if (symbol == '>') |
5341 |
02 Apr 19 |
nicklas |
417 |
{ |
5341 |
02 Apr 19 |
nicklas |
c = cmp.gt; |
5341 |
02 Apr 19 |
nicklas |
419 |
} |
5341 |
02 Apr 19 |
nicklas |
else |
5341 |
02 Apr 19 |
nicklas |
421 |
{ |
5341 |
02 Apr 19 |
nicklas |
c = defaultCmp || cmp.eq; |
5341 |
02 Apr 19 |
nicklas |
423 |
} |
5341 |
02 Apr 19 |
nicklas |
return c; |
5341 |
02 Apr 19 |
nicklas |
425 |
} |
5341 |
02 Apr 19 |
nicklas |
426 |
|
5341 |
02 Apr 19 |
nicklas |
// Compare if two values are equal |
5341 |
02 Apr 19 |
nicklas |
cmp.eq = function(v1, v2) |
5341 |
02 Apr 19 |
nicklas |
429 |
{ |
5341 |
02 Apr 19 |
nicklas |
return v1 == v2; |
5341 |
02 Apr 19 |
nicklas |
431 |
} |
5341 |
02 Apr 19 |
nicklas |
432 |
|
5341 |
02 Apr 19 |
nicklas |
// Compare if two values are different |
5341 |
02 Apr 19 |
nicklas |
cmp.neq = function(v1, v2) |
5341 |
02 Apr 19 |
nicklas |
435 |
{ |
5341 |
02 Apr 19 |
nicklas |
return v1 != v2; |
5341 |
02 Apr 19 |
nicklas |
437 |
} |
5341 |
02 Apr 19 |
nicklas |
438 |
|
5341 |
02 Apr 19 |
nicklas |
// Check if v2 is contained in v1 |
5341 |
02 Apr 19 |
nicklas |
cmp.contains = function(v1, v2) |
5341 |
02 Apr 19 |
nicklas |
441 |
{ |
5341 |
02 Apr 19 |
nicklas |
return v1 != null && v2 != null && v1.indexOf(v2) >= 0; |
5341 |
02 Apr 19 |
nicklas |
443 |
} |
5341 |
02 Apr 19 |
nicklas |
444 |
|
5341 |
02 Apr 19 |
nicklas |
// Compare if v1 starts with the same string as v2 |
5341 |
02 Apr 19 |
nicklas |
cmp.startsWith = function(v1, v2) |
5341 |
02 Apr 19 |
nicklas |
447 |
{ |
5341 |
02 Apr 19 |
nicklas |
return v1 != null && v1.indexOf(v2) == 0; |
5341 |
02 Apr 19 |
nicklas |
449 |
} |
5341 |
02 Apr 19 |
nicklas |
450 |
|
5341 |
02 Apr 19 |
nicklas |
// Compare if two values are appoximately equals (difference is not more than 0.05) |
5341 |
02 Apr 19 |
nicklas |
cmp.approx = function(v1, v2) |
5341 |
02 Apr 19 |
nicklas |
453 |
{ |
5341 |
02 Apr 19 |
nicklas |
return Math.abs(v2 - v1) < 0.05; |
5341 |
02 Apr 19 |
nicklas |
455 |
} |
5341 |
02 Apr 19 |
nicklas |
456 |
|
5341 |
02 Apr 19 |
nicklas |
// Compare if v1 is greater than or equal to v2 |
5341 |
02 Apr 19 |
nicklas |
cmp.gt = function(v1, v2) |
5341 |
02 Apr 19 |
nicklas |
459 |
{ |
5341 |
02 Apr 19 |
nicklas |
return v1 >= v2; |
5341 |
02 Apr 19 |
nicklas |
461 |
} |
5341 |
02 Apr 19 |
nicklas |
462 |
|
5341 |
02 Apr 19 |
nicklas |
// Compare if v1 is less than or equal to v2 |
5341 |
02 Apr 19 |
nicklas |
cmp.lt = function(v1, v2) |
5341 |
02 Apr 19 |
nicklas |
465 |
{ |
5341 |
02 Apr 19 |
nicklas |
return v1 <= v2; |
5341 |
02 Apr 19 |
nicklas |
467 |
} |
5341 |
02 Apr 19 |
nicklas |
468 |
|
5341 |
02 Apr 19 |
nicklas |
return cmp; |
5341 |
02 Apr 19 |
nicklas |
470 |
}(); |
5341 |
02 Apr 19 |
nicklas |
471 |
|