2964 |
20 Nov 14 |
olle |
var Labelgen = function() |
2964 |
20 Nov 14 |
olle |
2 |
{ |
2964 |
20 Nov 14 |
olle |
var labelgen = {}; |
3030 |
11 Dec 14 |
olle |
var debug = 0; |
2964 |
20 Nov 14 |
olle |
5 |
|
4144 |
30 Sep 16 |
olle |
var sampleItemPrefix = ''; |
4215 |
08 Nov 16 |
olle |
var sampleItemNumDigits = 5; |
2964 |
20 Nov 14 |
olle |
var caseIsValid = true; |
2964 |
20 Nov 14 |
olle |
var nofCasesIsValid = true; |
2964 |
20 Nov 14 |
olle |
10 |
|
2964 |
20 Nov 14 |
olle |
// Page initialization |
2964 |
20 Nov 14 |
olle |
labelgen.initPage = function() |
2964 |
20 Nov 14 |
olle |
13 |
{ |
2964 |
20 Nov 14 |
olle |
previewTitle = Doc.element('previewTitle'); |
2964 |
20 Nov 14 |
olle |
previewList = Doc.element('previewList'); |
2964 |
20 Nov 14 |
olle |
16 |
|
2964 |
20 Nov 14 |
olle |
// Step 1 |
2964 |
20 Nov 14 |
olle |
Events.addEventHandler('step-1', 'wizard-validate', labelgen.validateStep1); |
2964 |
20 Nov 14 |
olle |
Events.addEventHandler('nofCases', 'blur', labelgen.nofCasesOnChange); |
4960 |
03 Sep 18 |
olle |
Events.addEventHandler('tubeContentType', 'blur', labelgen.tubeContentTypeOnChange); |
2964 |
20 Nov 14 |
olle |
Events.addEventHandler('caseName', 'blur', labelgen.caseNameOnChange); |
2964 |
20 Nov 14 |
olle |
Events.addEventHandler('caseName', 'keypress', labelgen.validateStep1); |
2964 |
20 Nov 14 |
olle |
23 |
|
2964 |
20 Nov 14 |
olle |
// Navigation |
2964 |
20 Nov 14 |
olle |
Buttons.addClickHandler('goexport', labelgen.goExport); |
2964 |
20 Nov 14 |
olle |
Buttons.addClickHandler('gopreview', labelgen.goPreview); |
2964 |
20 Nov 14 |
olle |
27 |
|
4252 |
25 Nov 16 |
olle |
// Load configuration |
4252 |
25 Nov 16 |
olle |
labelgen.loadConfiguration(); |
4252 |
25 Nov 16 |
olle |
30 |
} |
4252 |
25 Nov 16 |
olle |
31 |
|
4252 |
25 Nov 16 |
olle |
labelgen.loadConfiguration = function() |
4252 |
25 Nov 16 |
olle |
33 |
{ |
4252 |
25 Nov 16 |
olle |
var url = '../Session.servlet?ID='+App.getSessionId(); |
4252 |
25 Nov 16 |
olle |
url += '&cmd=GetConfiguration' |
4252 |
25 Nov 16 |
olle |
var request = Ajax.getXmlHttpRequest(); |
4252 |
25 Nov 16 |
olle |
request.open("GET", url, true); |
4252 |
25 Nov 16 |
olle |
Ajax.setReadyStateHandler(request, labelgen.onConfiguration, labelgen.onConfiguration); |
4252 |
25 Nov 16 |
olle |
request.send(null); |
4252 |
25 Nov 16 |
olle |
40 |
} |
4252 |
25 Nov 16 |
olle |
41 |
|
4252 |
25 Nov 16 |
olle |
labelgen.onConfiguration = function(request) |
4252 |
25 Nov 16 |
olle |
43 |
{ |
4252 |
25 Nov 16 |
olle |
var frm = document.forms['meludi']; |
4252 |
25 Nov 16 |
olle |
45 |
|
4252 |
25 Nov 16 |
olle |
if (debug) |
4252 |
25 Nov 16 |
olle |
47 |
{ |
4252 |
25 Nov 16 |
olle |
App.debug(Strings.encodeTags(request.responseText)); |
4252 |
25 Nov 16 |
olle |
49 |
} |
4252 |
25 Nov 16 |
olle |
50 |
|
4252 |
25 Nov 16 |
olle |
var response; |
4252 |
25 Nov 16 |
olle |
var error = false; |
4252 |
25 Nov 16 |
olle |
try |
4252 |
25 Nov 16 |
olle |
54 |
{ |
4252 |
25 Nov 16 |
olle |
response = JSON.parse(request.responseText); |
4252 |
25 Nov 16 |
olle |
if (response.status != 'ok') |
4252 |
25 Nov 16 |
olle |
57 |
{ |
4252 |
25 Nov 16 |
olle |
error = response.message || response.stacktrace || 'Unexpected error'; |
4252 |
25 Nov 16 |
olle |
59 |
} |
4252 |
25 Nov 16 |
olle |
60 |
} |
4252 |
25 Nov 16 |
olle |
catch (ex) |
4252 |
25 Nov 16 |
olle |
62 |
{ |
4252 |
25 Nov 16 |
olle |
error = ex; |
4252 |
25 Nov 16 |
olle |
64 |
} |
4252 |
25 Nov 16 |
olle |
if (error) App.debug(error); |
4252 |
25 Nov 16 |
olle |
66 |
|
4252 |
25 Nov 16 |
olle |
// Get configuration result |
4252 |
25 Nov 16 |
olle |
var conf = response.configuration; |
4252 |
25 Nov 16 |
olle |
69 |
|
4252 |
25 Nov 16 |
olle |
// Check for extracts from first specimen only default |
4252 |
25 Nov 16 |
olle |
var extractsFromFirstSpecimenOnlyDefault = conf.extractsFromFirstSpecimenOnlyDefault; |
4252 |
25 Nov 16 |
olle |
if (extractsFromFirstSpecimenOnlyDefault != null) |
4252 |
25 Nov 16 |
olle |
73 |
{ |
4252 |
25 Nov 16 |
olle |
frm.extractsFromFirstSpecimenOnlyCB.checked = extractsFromFirstSpecimenOnlyDefault; |
4252 |
25 Nov 16 |
olle |
75 |
} |
4252 |
25 Nov 16 |
olle |
76 |
|
4252 |
25 Nov 16 |
olle |
// Continue with initializing info for case |
2964 |
20 Nov 14 |
olle |
var url = '../LabelGeneration.servlet?ID='+App.getSessionId(); |
3668 |
17 Dec 15 |
olle |
url += '&cmd=GetLastLabelCase'; |
2964 |
20 Nov 14 |
olle |
Wizard.showLoadingAnimation('Loading cases...'); |
2964 |
20 Nov 14 |
olle |
Wizard.asyncJsonRequest(url, labelgen.caseInfoLoaded); |
2964 |
20 Nov 14 |
olle |
82 |
} |
2964 |
20 Nov 14 |
olle |
83 |
|
2964 |
20 Nov 14 |
olle |
labelgen.caseInfoLoaded = function(response) |
2964 |
20 Nov 14 |
olle |
85 |
{ |
2964 |
20 Nov 14 |
olle |
var frm = document.forms['meludi']; |
2964 |
20 Nov 14 |
olle |
87 |
|
4144 |
30 Sep 16 |
olle |
sampleItemPrefix = response.sampleItemPrefix; |
4215 |
08 Nov 16 |
olle |
sampleItemNumDigits = response.sampleItemNumDigits; |
2964 |
20 Nov 14 |
olle |
var nofCases = response.count; |
2964 |
20 Nov 14 |
olle |
if (nofCases == null) |
2964 |
20 Nov 14 |
olle |
92 |
{ |
2964 |
20 Nov 14 |
olle |
nofCases = 0; |
2964 |
20 Nov 14 |
olle |
94 |
} |
2964 |
20 Nov 14 |
olle |
var startNum = nofCases + 1; |
4215 |
08 Nov 16 |
olle |
// Pad number with leading zeros to get right number of digits |
4215 |
08 Nov 16 |
olle |
startNum = String('0000000000' + startNum).slice(-sampleItemNumDigits); |
4144 |
30 Sep 16 |
olle |
var startCase = sampleItemPrefix + startNum; |
2964 |
20 Nov 14 |
olle |
frm.caseName.value = startCase; |
2964 |
20 Nov 14 |
olle |
100 |
|
2964 |
20 Nov 14 |
olle |
Doc.show('step-1'); |
2964 |
20 Nov 14 |
olle |
Doc.show('gopreview'); |
2964 |
20 Nov 14 |
olle |
Doc.show('goexport'); |
2964 |
20 Nov 14 |
olle |
104 |
} |
2964 |
20 Nov 14 |
olle |
105 |
|
2964 |
20 Nov 14 |
olle |
labelgen.goPreview = function() |
2964 |
20 Nov 14 |
olle |
107 |
{ |
2964 |
20 Nov 14 |
olle |
labelgen.doExport(true); |
2964 |
20 Nov 14 |
olle |
109 |
} |
2964 |
20 Nov 14 |
olle |
110 |
|
2964 |
20 Nov 14 |
olle |
labelgen.goExport = function() |
2964 |
20 Nov 14 |
olle |
112 |
{ |
2964 |
20 Nov 14 |
olle |
labelgen.doExport(false); |
2964 |
20 Nov 14 |
olle |
114 |
} |
2964 |
20 Nov 14 |
olle |
115 |
|
2964 |
20 Nov 14 |
olle |
labelgen.doExport = function(preview) |
2964 |
20 Nov 14 |
olle |
117 |
{ |
2964 |
20 Nov 14 |
olle |
var frm = document.forms['meludi']; |
2964 |
20 Nov 14 |
olle |
var nofCases = frm.nofCases.value; |
2964 |
20 Nov 14 |
olle |
var nofTubesPerCase = frm.nofTubesPerCase.value; |
2964 |
20 Nov 14 |
olle |
var startCase = frm.caseName.value; |
4869 |
25 Jun 18 |
olle |
var tubeContentType = frm.tubeContentType.value; |
4252 |
25 Nov 16 |
olle |
var extractsFromFirstSpecimenOnly = frm.extractsFromFirstSpecimenOnlyCB.checked; |
2964 |
20 Nov 14 |
olle |
124 |
|
2964 |
20 Nov 14 |
olle |
var url = '../LabelGeneration.servlet?ID=' + App.getSessionId(); |
4252 |
25 Nov 16 |
olle |
url += '&cmd=GetLabelFile'; |
4252 |
25 Nov 16 |
olle |
url += '&nofCases=' + nofCases; |
4252 |
25 Nov 16 |
olle |
url += '&nofTubesPerCase=' + nofTubesPerCase; |
4252 |
25 Nov 16 |
olle |
url += '&startCase=' + encodeURIComponent(startCase); |
4869 |
25 Jun 18 |
olle |
url += '&tubeContentType=' + encodeURIComponent(tubeContentType); |
4252 |
25 Nov 16 |
olle |
url += '&extractsFromFirstSpecimenOnly=' + extractsFromFirstSpecimenOnly; |
4252 |
25 Nov 16 |
olle |
url += '&preview=' + preview; |
4869 |
25 Jun 18 |
olle |
//alert("labelgeneration.js::doExport(): tubeContentType = '" + tubeContentType + "' url = " + url); |
2964 |
20 Nov 14 |
olle |
134 |
|
2964 |
20 Nov 14 |
olle |
if (preview) |
2964 |
20 Nov 14 |
olle |
136 |
{ |
2964 |
20 Nov 14 |
olle |
Doc.hide('previewWrapper'); |
2964 |
20 Nov 14 |
olle |
url += '&preview=1'; |
2964 |
20 Nov 14 |
olle |
139 |
|
2964 |
20 Nov 14 |
olle |
Wizard.showLoadingAnimation('Working...'); |
2964 |
20 Nov 14 |
olle |
Doc.hide('navigation'); |
2964 |
20 Nov 14 |
olle |
Wizard.asyncJsonRequest(url, labelgen.onPreviewLoaded); |
2964 |
20 Nov 14 |
olle |
143 |
} |
2964 |
20 Nov 14 |
olle |
else |
2964 |
20 Nov 14 |
olle |
145 |
{ |
2964 |
20 Nov 14 |
olle |
window.location = url; |
2964 |
20 Nov 14 |
olle |
147 |
} |
2964 |
20 Nov 14 |
olle |
148 |
} |
2964 |
20 Nov 14 |
olle |
149 |
|
2964 |
20 Nov 14 |
olle |
labelgen.onPreviewLoaded = function(response) |
2964 |
20 Nov 14 |
olle |
151 |
{ |
2964 |
20 Nov 14 |
olle |
Doc.show('navigation'); |
2964 |
20 Nov 14 |
olle |
var frm = document.forms['meludi']; |
2964 |
20 Nov 14 |
olle |
var allLines = response.split('\n'); |
2964 |
20 Nov 14 |
olle |
var numLines = allLines.length - 1; |
2964 |
20 Nov 14 |
olle |
156 |
|
2964 |
20 Nov 14 |
olle |
var html = '<tr><th>'+allLines[0].replace(/\t/g, '</th><th>')+'</th></tr>'; |
2964 |
20 Nov 14 |
olle |
// Check first column for 'ItemType' string, which indicates a header line. |
2964 |
20 Nov 14 |
olle |
var numNoConsent = 0; |
2964 |
20 Nov 14 |
olle |
var numMissingConsent = 0; |
2964 |
20 Nov 14 |
olle |
for (var i = 1 ; i <= numLines; i++) |
2964 |
20 Nov 14 |
olle |
162 |
{ |
2964 |
20 Nov 14 |
olle |
var line = allLines[i]; |
2964 |
20 Nov 14 |
olle |
var cols = line.split(/\t/); |
2964 |
20 Nov 14 |
olle |
var firstColumnVal = cols[0]; |
2964 |
20 Nov 14 |
olle |
var lineIsHeader = false; |
2964 |
20 Nov 14 |
olle |
if (firstColumnVal == 'ItemType') |
2964 |
20 Nov 14 |
olle |
168 |
{ |
2964 |
20 Nov 14 |
olle |
lineIsHeader = true; |
2964 |
20 Nov 14 |
olle |
170 |
} |
2964 |
20 Nov 14 |
olle |
var rowClass = ''; |
2964 |
20 Nov 14 |
olle |
if (lineIsHeader) |
2964 |
20 Nov 14 |
olle |
173 |
{ |
2964 |
20 Nov 14 |
olle |
html += '<tr><th>'+line.replace(/\t/g, '</th><th>')+'</th></tr>'; |
2964 |
20 Nov 14 |
olle |
175 |
} |
2964 |
20 Nov 14 |
olle |
else |
2964 |
20 Nov 14 |
olle |
177 |
{ |
2964 |
20 Nov 14 |
olle |
html += '<tr class="'+rowClass+'"><td>'+cols.join('</td><td>')+'</td></tr>'; |
2964 |
20 Nov 14 |
olle |
179 |
} |
2964 |
20 Nov 14 |
olle |
180 |
} |
2964 |
20 Nov 14 |
olle |
181 |
|
2964 |
20 Nov 14 |
olle |
previewList.innerHTML = '<table>'+html+'</table>'; |
2964 |
20 Nov 14 |
olle |
Doc.show('previewWrapper'); |
2964 |
20 Nov 14 |
olle |
184 |
} |
2964 |
20 Nov 14 |
olle |
185 |
|
2964 |
20 Nov 14 |
olle |
labelgen.nofCasesOnChange = function() |
2964 |
20 Nov 14 |
olle |
187 |
{ |
2964 |
20 Nov 14 |
olle |
var frm = document.forms['meludi']; |
2964 |
20 Nov 14 |
olle |
var nofCases = frm.nofCases.value; |
2964 |
20 Nov 14 |
olle |
nofCasesIsValid = false; |
2964 |
20 Nov 14 |
olle |
if (nofCases == '') |
2964 |
20 Nov 14 |
olle |
192 |
{ |
2964 |
20 Nov 14 |
olle |
Wizard.setInputStatus('nofCases', 'invalid', 'Missing'); |
2964 |
20 Nov 14 |
olle |
frm.nofCases.focus(); |
2964 |
20 Nov 14 |
olle |
return; |
2964 |
20 Nov 14 |
olle |
196 |
} |
2964 |
20 Nov 14 |
olle |
// Check that input is a natural number (1, 2, 3, ...) |
2964 |
20 Nov 14 |
olle |
var regex = /^[1-9][0-9]*$/; |
2964 |
20 Nov 14 |
olle |
if (!nofCases.match(regex)) |
2964 |
20 Nov 14 |
olle |
200 |
{ |
2964 |
20 Nov 14 |
olle |
Wizard.setInputStatus('nofCases', 'invalid', 'Only numbers > 0 are allowed.'); |
2964 |
20 Nov 14 |
olle |
frm.nofCases.focus(); |
2964 |
20 Nov 14 |
olle |
return; |
2964 |
20 Nov 14 |
olle |
204 |
} |
2964 |
20 Nov 14 |
olle |
Wizard.setInputStatus('nofCases', 'valid', ''); |
2964 |
20 Nov 14 |
olle |
nofCasesIsValid = true; |
2964 |
20 Nov 14 |
olle |
207 |
} |
2964 |
20 Nov 14 |
olle |
208 |
|
4960 |
03 Sep 18 |
olle |
labelgen.tubeContentTypeOnChange = function() |
4960 |
03 Sep 18 |
olle |
210 |
{ |
4960 |
03 Sep 18 |
olle |
var frm = document.forms['meludi']; |
4960 |
03 Sep 18 |
olle |
212 |
|
4960 |
03 Sep 18 |
olle |
var tubeContentType = frm.tubeContentType.value; |
4960 |
03 Sep 18 |
olle |
if (tubeContentType == 'Specimen') |
4960 |
03 Sep 18 |
olle |
215 |
{ |
4960 |
03 Sep 18 |
olle |
frm.nofTubesPerCase.value = 1; |
4960 |
03 Sep 18 |
olle |
217 |
} |
4960 |
03 Sep 18 |
olle |
else if (tubeContentType == 'Blood') |
4960 |
03 Sep 18 |
olle |
219 |
{ |
4960 |
03 Sep 18 |
olle |
frm.nofTubesPerCase.value = 2; |
4960 |
03 Sep 18 |
olle |
221 |
} |
4960 |
03 Sep 18 |
olle |
frm.nofTubesPerCase.focus(); |
4960 |
03 Sep 18 |
olle |
223 |
} |
4960 |
03 Sep 18 |
olle |
224 |
|
2964 |
20 Nov 14 |
olle |
labelgen.caseNameOnChange = function() |
2964 |
20 Nov 14 |
olle |
226 |
{ |
2964 |
20 Nov 14 |
olle |
var frm = document.forms['meludi']; |
2964 |
20 Nov 14 |
olle |
228 |
|
2964 |
20 Nov 14 |
olle |
var caseName = frm.caseName.value.toUpperCase(); |
2964 |
20 Nov 14 |
olle |
caseIsValid = false; |
2964 |
20 Nov 14 |
olle |
if (caseName == '') |
2964 |
20 Nov 14 |
olle |
232 |
{ |
2964 |
20 Nov 14 |
olle |
Wizard.setInputStatus('caseName', 'invalid', 'Missing'); |
2964 |
20 Nov 14 |
olle |
frm.caseName.focus(); |
2964 |
20 Nov 14 |
olle |
return; |
2964 |
20 Nov 14 |
olle |
236 |
} |
4215 |
08 Nov 16 |
olle |
if (!Meludi.isValidCaseName2(caseName, sampleItemPrefix, sampleItemNumDigits)) |
2964 |
20 Nov 14 |
olle |
238 |
{ |
4215 |
08 Nov 16 |
olle |
Wizard.setInputStatus('caseName', 'invalid', 'Only "' + sampleItemPrefix + '" + ' + sampleItemNumDigits + ' digits is allowed.'); |
2964 |
20 Nov 14 |
olle |
frm.caseName.focus(); |
2964 |
20 Nov 14 |
olle |
return; |
2964 |
20 Nov 14 |
olle |
242 |
} |
2964 |
20 Nov 14 |
olle |
243 |
|
2964 |
20 Nov 14 |
olle |
frm.caseName.value = caseName; |
2964 |
20 Nov 14 |
olle |
Wizard.setInputStatus('caseName', 'valid'); |
2964 |
20 Nov 14 |
olle |
caseIsValid = true; |
2964 |
20 Nov 14 |
olle |
247 |
} |
2964 |
20 Nov 14 |
olle |
248 |
|
2964 |
20 Nov 14 |
olle |
labelgen.validateStep1 = function(event) |
2964 |
20 Nov 14 |
olle |
250 |
{ |
2964 |
20 Nov 14 |
olle |
// Everything should be OK here, this is for future use |
2964 |
20 Nov 14 |
olle |
var frm = document.forms['meludi']; |
2964 |
20 Nov 14 |
olle |
if (nofCasesIsValid && caseIsValid) |
2964 |
20 Nov 14 |
olle |
254 |
{ |
2964 |
20 Nov 14 |
olle |
return; |
2964 |
20 Nov 14 |
olle |
256 |
} |
2964 |
20 Nov 14 |
olle |
event.preventDefault(); |
2964 |
20 Nov 14 |
olle |
258 |
} |
2964 |
20 Nov 14 |
olle |
259 |
|
2964 |
20 Nov 14 |
olle |
labelgen.addEventHandlers = function(elements, eventName, handler) |
2964 |
20 Nov 14 |
olle |
261 |
{ |
2964 |
20 Nov 14 |
olle |
for (var i = 0; i < elements.length; i++) |
2964 |
20 Nov 14 |
olle |
263 |
{ |
2964 |
20 Nov 14 |
olle |
Events.addEventHandler(elements[i], eventName, handler); |
2964 |
20 Nov 14 |
olle |
265 |
} |
2964 |
20 Nov 14 |
olle |
266 |
} |
2964 |
20 Nov 14 |
olle |
267 |
|
2964 |
20 Nov 14 |
olle |
return labelgen; |
2964 |
20 Nov 14 |
olle |
269 |
}(); |
2964 |
20 Nov 14 |
olle |
270 |
|
2964 |
20 Nov 14 |
olle |
Doc.onLoad(Labelgen.initPage); |
2964 |
20 Nov 14 |
olle |
272 |
|