2602 |
27 Aug 14 |
nicklas |
var Blood = function() |
2602 |
27 Aug 14 |
nicklas |
2 |
{ |
2602 |
27 Aug 14 |
nicklas |
var blood = {}; |
2656 |
11 Sep 14 |
nicklas |
var debug = 0; |
2602 |
27 Aug 14 |
nicklas |
5 |
|
2602 |
27 Aug 14 |
nicklas |
var patientInfo = null; |
2602 |
27 Aug 14 |
nicklas |
var bloodInfo = null; |
2602 |
27 Aug 14 |
nicklas |
var consentInfo = null; |
2602 |
27 Aug 14 |
nicklas |
var caseInfo = null; |
2602 |
27 Aug 14 |
nicklas |
10 |
|
2602 |
27 Aug 14 |
nicklas |
var rccidIsValid = false; |
2602 |
27 Aug 14 |
nicklas |
var pnrIsValid = false; |
2602 |
27 Aug 14 |
nicklas |
var pnrIsAcceptable = false; |
2602 |
27 Aug 14 |
nicklas |
14 |
|
2602 |
27 Aug 14 |
nicklas |
var samplingDateIsValid = true; |
2602 |
27 Aug 14 |
nicklas |
var freezerDateIsValid = true; |
2602 |
27 Aug 14 |
nicklas |
17 |
|
2602 |
27 Aug 14 |
nicklas |
blood.initPage = function() |
2602 |
27 Aug 14 |
nicklas |
19 |
{ |
2602 |
27 Aug 14 |
nicklas |
// Step 1 |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('step-1', 'wizard-validate', blood.validateStep1); |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('rccidNumber', 'keypress', Wizard.focusOnEnter); |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('rccidNumber', 'blur', blood.rccidNumberOnChange); |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('personalNumber', 'keyup', blood.personalNumberOnChange); |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('personalNumber', 'keypress', Wizard.goNextOnTabOrEnter); |
2602 |
27 Aug 14 |
nicklas |
26 |
|
2602 |
27 Aug 14 |
nicklas |
// Step 2 |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('step-2', 'wizard-initialize', blood.initializeStep2); |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('step-2', 'wizard-validate', blood.validateStep2); |
2602 |
27 Aug 14 |
nicklas |
30 |
|
2602 |
27 Aug 14 |
nicklas |
// Step 3 |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('step-3', 'wizard-initialize', blood.initializeStep3); |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('step-3', 'wizard-validate', blood.validateStep3); |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('samplingDate', 'blur', blood.samplingDateTimeOnChange); |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('samplingTime', 'blur', blood.samplingDateTimeOnChange); |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('freezerDate', 'blur', blood.freezerDateTimeOnChange); |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('freezerTime', 'blur', blood.freezerDateTimeOnChange); |
2602 |
27 Aug 14 |
nicklas |
38 |
|
2602 |
27 Aug 14 |
nicklas |
// Navigation |
2602 |
27 Aug 14 |
nicklas |
Buttons.addClickHandler('gocancel', Wizard.cancelWizard); |
2602 |
27 Aug 14 |
nicklas |
Buttons.addClickHandler('gorestart', Wizard.restartWizard); |
2602 |
27 Aug 14 |
nicklas |
Buttons.addClickHandler('gonext', Wizard.goNextOnClick); |
2602 |
27 Aug 14 |
nicklas |
Buttons.addClickHandler('goregister', Wizard.goRegister); |
2602 |
27 Aug 14 |
nicklas |
Buttons.addClickHandler('goupdate', Wizard.goRegister); |
2602 |
27 Aug 14 |
nicklas |
45 |
|
2602 |
27 Aug 14 |
nicklas |
// Final registration |
2602 |
27 Aug 14 |
nicklas |
Events.addEventHandler('wizard', 'wizard-submit', blood.submit); |
2602 |
27 Aug 14 |
nicklas |
48 |
|
2602 |
27 Aug 14 |
nicklas |
Doc.show('step-1'); |
2602 |
27 Aug 14 |
nicklas |
Doc.show('gonext'); |
2602 |
27 Aug 14 |
nicklas |
51 |
} |
2602 |
27 Aug 14 |
nicklas |
52 |
|
2602 |
27 Aug 14 |
nicklas |
53 |
|
2602 |
27 Aug 14 |
nicklas |
blood.rccidNumberOnChange = function() |
2602 |
27 Aug 14 |
nicklas |
55 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('rccidNumber'); |
2602 |
27 Aug 14 |
nicklas |
58 |
|
2602 |
27 Aug 14 |
nicklas |
var rccidNumber = frm.rccidNumber.value.toUpperCase(); |
2602 |
27 Aug 14 |
nicklas |
rccidIsValid = false; |
2602 |
27 Aug 14 |
nicklas |
if (rccidNumber == '') |
2602 |
27 Aug 14 |
nicklas |
62 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('rccidNumber', 'invalid', 'Missing'); |
2602 |
27 Aug 14 |
nicklas |
frm.rccidNumber.focus(); |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
66 |
} |
2602 |
27 Aug 14 |
nicklas |
67 |
|
2602 |
27 Aug 14 |
nicklas |
if (!Reggie.isValidRccidNumber(rccidNumber)) |
2602 |
27 Aug 14 |
nicklas |
69 |
{ |
6801 |
11 Aug 22 |
nicklas |
Wizard.setInputStatus('rccidNumber', 'invalid', 'Expected NNNN-NNNNNNNN where N is a digit, or 10 digits + \'B\', \'C\', or \'D\''); |
2602 |
27 Aug 14 |
nicklas |
frm.rccidNumber.focus(); |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
73 |
} |
2602 |
27 Aug 14 |
nicklas |
74 |
|
2602 |
27 Aug 14 |
nicklas |
frm.rccidNumber.value = rccidNumber; |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('rccidNumber', 'valid'); |
2602 |
27 Aug 14 |
nicklas |
rccidIsValid = true; |
2602 |
27 Aug 14 |
nicklas |
78 |
|
2602 |
27 Aug 14 |
nicklas |
79 |
|
2602 |
27 Aug 14 |
nicklas |
var url = '../BloodFollowUpRegistration.servlet?ID='+App.getSessionId(); |
2602 |
27 Aug 14 |
nicklas |
url += '&cmd=GetBloodFollowUpInfo'; |
2602 |
27 Aug 14 |
nicklas |
url += '&rccidNumber=' + encodeURIComponent(rccidNumber); |
2602 |
27 Aug 14 |
nicklas |
Wizard.showLoadingAnimation('Loading information follow-up blood...'); |
2602 |
27 Aug 14 |
nicklas |
Wizard.asyncJsonRequest(url, blood.bloodInfoLoadedFromRccid); |
2602 |
27 Aug 14 |
nicklas |
85 |
} |
2602 |
27 Aug 14 |
nicklas |
86 |
|
2602 |
27 Aug 14 |
nicklas |
blood.bloodInfoLoadedFromRccid = function(response) |
2602 |
27 Aug 14 |
nicklas |
88 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
2602 |
27 Aug 14 |
nicklas |
bloodInfo = response.bloodInfo; |
2602 |
27 Aug 14 |
nicklas |
patientInfo = response.patientInfo; |
2602 |
27 Aug 14 |
nicklas |
consentInfo = response.consentInfo; |
2602 |
27 Aug 14 |
nicklas |
caseInfo = response.caseInfo; |
2602 |
27 Aug 14 |
nicklas |
94 |
|
2602 |
27 Aug 14 |
nicklas |
if (patientInfo) |
2602 |
27 Aug 14 |
nicklas |
96 |
{ |
2602 |
27 Aug 14 |
nicklas |
// Move to next step |
2602 |
27 Aug 14 |
nicklas |
frm.personalNumber.value = patientInfo.personalNumber; |
2602 |
27 Aug 14 |
nicklas |
blood.personalNumberOnChange(); |
2602 |
27 Aug 14 |
nicklas |
Wizard.goNext(false); |
2602 |
27 Aug 14 |
nicklas |
101 |
} |
2602 |
27 Aug 14 |
nicklas |
102 |
} |
2602 |
27 Aug 14 |
nicklas |
103 |
|
2602 |
27 Aug 14 |
nicklas |
blood.personalNumberOnChange = function() |
2602 |
27 Aug 14 |
nicklas |
105 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
2602 |
27 Aug 14 |
nicklas |
var pnr = frm.personalNumber.value; |
2602 |
27 Aug 14 |
nicklas |
pnrIsValid = false; |
2602 |
27 Aug 14 |
nicklas |
pnrIsAcceptable = true; |
2602 |
27 Aug 14 |
nicklas |
110 |
|
2602 |
27 Aug 14 |
nicklas |
var pnrLen = pnr.length; |
2602 |
27 Aug 14 |
nicklas |
if (pnrLen != 12 && pnrLen != 10) |
2602 |
27 Aug 14 |
nicklas |
113 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('personalNumber', 'warning', pnrLen < 12 ? 'Too short' : 'Too long'); |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
116 |
} |
2602 |
27 Aug 14 |
nicklas |
117 |
|
2602 |
27 Aug 14 |
nicklas |
if (!pnr.match(/^\d+$/)) |
2602 |
27 Aug 14 |
nicklas |
119 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('personalNumber', 'warning', 'Non-standard personal number'); |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
122 |
} |
2602 |
27 Aug 14 |
nicklas |
123 |
|
2602 |
27 Aug 14 |
nicklas |
var datePart = pnr.substring(0, pnrLen - 4); // Remove last four digits |
2602 |
27 Aug 14 |
nicklas |
var dateFormat = pnrLen == 10 ? 'yyMMdd' : 'yyyyMMdd'; |
2602 |
27 Aug 14 |
nicklas |
var isValidDate = Dates.isDate(datePart, dateFormat); |
2602 |
27 Aug 14 |
nicklas |
if (!isValidDate) |
2602 |
27 Aug 14 |
nicklas |
128 |
{ |
2602 |
27 Aug 14 |
nicklas |
var dayInMonth = parseInt(datePart.substring(-2), 10); // Last two characters |
2602 |
27 Aug 14 |
nicklas |
if (dayInMonth > 60) |
2602 |
27 Aug 14 |
nicklas |
131 |
{ |
2602 |
27 Aug 14 |
nicklas |
// 'Samordningsnummer' has day-in-month + 60; check this |
2602 |
27 Aug 14 |
nicklas |
dayInMonth -= 60; |
2602 |
27 Aug 14 |
nicklas |
var tmpPnr = pnr.substring(0, pnrLen - 6); // First 4 or 6 digits is year+month |
2602 |
27 Aug 14 |
nicklas |
if (dayInMonth < 10) tmpPnr += '0'; |
2602 |
27 Aug 14 |
nicklas |
tmpPnr += dayInMonth; |
2602 |
27 Aug 14 |
nicklas |
isValidDate = Dates.isDate(tmpPnr, dateFormat); |
2602 |
27 Aug 14 |
nicklas |
138 |
} |
2602 |
27 Aug 14 |
nicklas |
139 |
} |
2602 |
27 Aug 14 |
nicklas |
if (!isValidDate) |
2602 |
27 Aug 14 |
nicklas |
141 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('personalNumber', 'warning', 'Not a valid date'); |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
144 |
} |
2602 |
27 Aug 14 |
nicklas |
145 |
|
2602 |
27 Aug 14 |
nicklas |
if (!Reggie.personalNumberControlDigitCheck(pnr.substr(pnrLen == 10 ? 0 : 2))) |
2602 |
27 Aug 14 |
nicklas |
147 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('personalNumber', 'warning', 'Invalid control digit'); |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
150 |
} |
2602 |
27 Aug 14 |
nicklas |
151 |
|
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('personalNumber', 'valid'); |
2602 |
27 Aug 14 |
nicklas |
pnrIsValid = true; |
2602 |
27 Aug 14 |
nicklas |
Wizard.hideGoNextConfirmation(); |
2602 |
27 Aug 14 |
nicklas |
155 |
} |
2602 |
27 Aug 14 |
nicklas |
156 |
|
2602 |
27 Aug 14 |
nicklas |
blood.validateStep1 = function(event) |
2602 |
27 Aug 14 |
nicklas |
158 |
{ |
2602 |
27 Aug 14 |
nicklas |
App.debug('gonext:'+event.detail.auto); |
2602 |
27 Aug 14 |
nicklas |
if (event.detail.auto) |
2602 |
27 Aug 14 |
nicklas |
161 |
{ |
2602 |
27 Aug 14 |
nicklas |
if (!rccidIsValid || !pnrIsValid) |
2602 |
27 Aug 14 |
nicklas |
163 |
{ |
2602 |
27 Aug 14 |
nicklas |
if (pnrIsAcceptable) |
2602 |
27 Aug 14 |
nicklas |
165 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
2602 |
27 Aug 14 |
nicklas |
frm.personalNumber.focus(); |
2602 |
27 Aug 14 |
nicklas |
Wizard.showGoNextConfirmation(true, 'Check to verify registration of non-standard personal number.'); |
2602 |
27 Aug 14 |
nicklas |
169 |
} |
2602 |
27 Aug 14 |
nicklas |
event.preventDefault(); |
2602 |
27 Aug 14 |
nicklas |
171 |
} |
2602 |
27 Aug 14 |
nicklas |
172 |
} |
2602 |
27 Aug 14 |
nicklas |
else |
2602 |
27 Aug 14 |
nicklas |
174 |
{ |
2602 |
27 Aug 14 |
nicklas |
if (!rccidIsValid || !pnrIsAcceptable) event.preventDefault(); |
2602 |
27 Aug 14 |
nicklas |
176 |
} |
2602 |
27 Aug 14 |
nicklas |
177 |
|
2602 |
27 Aug 14 |
nicklas |
178 |
} |
2602 |
27 Aug 14 |
nicklas |
179 |
|
6824 |
30 Aug 22 |
nicklas |
blood.initializeStep2 = function() |
2602 |
27 Aug 14 |
nicklas |
181 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
2602 |
27 Aug 14 |
nicklas |
if (!patientInfo || !patientInfo.id) |
2602 |
27 Aug 14 |
nicklas |
184 |
{ |
2602 |
27 Aug 14 |
nicklas |
var pnr = frm.personalNumber.value; |
2602 |
27 Aug 14 |
nicklas |
if (pnr.length == 10 && pnrIsValid) |
2602 |
27 Aug 14 |
nicklas |
187 |
{ |
2602 |
27 Aug 14 |
nicklas |
var year = Reggie.fullYear(parseInt(pnr.substr(0, 2), 10)); |
2602 |
27 Aug 14 |
nicklas |
pnr = year + pnr.substr(2); |
2602 |
27 Aug 14 |
nicklas |
190 |
} |
2602 |
27 Aug 14 |
nicklas |
var url = '../PersonalRegistration.servlet?ID='+App.getSessionId(); |
2602 |
27 Aug 14 |
nicklas |
url += '&cmd=GetPatientInfo'; |
2602 |
27 Aug 14 |
nicklas |
url += '&personalNumber=' + encodeURIComponent(pnr); |
2602 |
27 Aug 14 |
nicklas |
url += '&pnrIsValid=' + pnrIsValid; |
2602 |
27 Aug 14 |
nicklas |
195 |
|
2602 |
27 Aug 14 |
nicklas |
Wizard.showLoadingAnimation('Loading patient information...'); |
6824 |
30 Aug 22 |
nicklas |
Wizard.asyncJsonRequest(url, blood.patientInfoLoaded); |
2602 |
27 Aug 14 |
nicklas |
198 |
} |
2602 |
27 Aug 14 |
nicklas |
else |
2602 |
27 Aug 14 |
nicklas |
200 |
{ |
2602 |
27 Aug 14 |
nicklas |
blood.patientInfoLoaded(); |
2602 |
27 Aug 14 |
nicklas |
202 |
} |
2602 |
27 Aug 14 |
nicklas |
203 |
} |
2602 |
27 Aug 14 |
nicklas |
204 |
|
2602 |
27 Aug 14 |
nicklas |
blood.patientInfoLoaded = function(response) |
2602 |
27 Aug 14 |
nicklas |
206 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
2602 |
27 Aug 14 |
nicklas |
if (response) patientInfo = response.patientInfo; |
2602 |
27 Aug 14 |
nicklas |
if (!patientInfo || !patientInfo.id) |
2602 |
27 Aug 14 |
nicklas |
210 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setFatalError('No patient found for personal number: ' + Strings.encodeTags(frm.personalNumber.value)); |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
213 |
} |
2602 |
27 Aug 14 |
nicklas |
214 |
|
2602 |
27 Aug 14 |
nicklas |
Doc.element('existing.patientCode').innerHTML = Strings.encodeTags(patientInfo.name); |
2602 |
27 Aug 14 |
nicklas |
Doc.element('existing.familyName').innerHTML = Strings.encodeTags(patientInfo.familyName); |
2602 |
27 Aug 14 |
nicklas |
Doc.element('existing.allFirstNames').innerHTML = Strings.encodeTags(patientInfo.allFirstNames); |
2602 |
27 Aug 14 |
nicklas |
if (patientInfo.gender) |
2602 |
27 Aug 14 |
nicklas |
219 |
{ |
2602 |
27 Aug 14 |
nicklas |
Doc.element('existing.gender').innerHTML = Strings.encodeTags(patientInfo.gender); |
2602 |
27 Aug 14 |
nicklas |
221 |
} |
2602 |
27 Aug 14 |
nicklas |
if (patientInfo.dateOfBirth) |
2602 |
27 Aug 14 |
nicklas |
223 |
{ |
2602 |
27 Aug 14 |
nicklas |
Doc.element('existing.dateOfBirth').innerHTML = Strings.encodeTags(patientInfo.dateOfBirth); |
2602 |
27 Aug 14 |
nicklas |
225 |
} |
2602 |
27 Aug 14 |
nicklas |
226 |
|
2602 |
27 Aug 14 |
nicklas |
// Get case option list JSON object from personal number with AJAX |
2602 |
27 Aug 14 |
nicklas |
var url = '../BloodFollowUpRegistration.servlet?ID='+App.getSessionId(); |
2602 |
27 Aug 14 |
nicklas |
url += '&cmd=GetCaseOptions'; |
6801 |
11 Aug 22 |
nicklas |
url += '&patientId='+patientInfo.id; |
2602 |
27 Aug 14 |
nicklas |
if (caseInfo && caseInfo.id) |
2602 |
27 Aug 14 |
nicklas |
232 |
{ |
2602 |
27 Aug 14 |
nicklas |
url += '&caseId='+caseInfo.id; |
2602 |
27 Aug 14 |
nicklas |
234 |
} |
2602 |
27 Aug 14 |
nicklas |
235 |
|
2602 |
27 Aug 14 |
nicklas |
Wizard.showLoadingAnimation('Loading case information...'); |
2602 |
27 Aug 14 |
nicklas |
Wizard.asyncJsonRequest(url, blood.caseInfoLoaded); |
2602 |
27 Aug 14 |
nicklas |
238 |
} |
2602 |
27 Aug 14 |
nicklas |
239 |
|
2602 |
27 Aug 14 |
nicklas |
blood.caseInfoLoaded = function(response) |
2602 |
27 Aug 14 |
nicklas |
241 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
6801 |
11 Aug 22 |
nicklas |
var caseOptions = response.caseOptionArray || []; |
2602 |
27 Aug 14 |
nicklas |
// Construct case name menu from JSON data |
2602 |
27 Aug 14 |
nicklas |
for (var i = 0; i < caseOptions.length; i++) |
2602 |
27 Aug 14 |
nicklas |
246 |
{ |
2602 |
27 Aug 14 |
nicklas |
var option = caseOptions[i]; |
2602 |
27 Aug 14 |
nicklas |
frm.caseName[frm.caseName.length] = new Option(option.text, option.id); |
2602 |
27 Aug 14 |
nicklas |
249 |
} |
2602 |
27 Aug 14 |
nicklas |
Wizard.setCurrentStep(2); |
2602 |
27 Aug 14 |
nicklas |
251 |
|
2602 |
27 Aug 14 |
nicklas |
if (caseOptions.length == 0) |
2602 |
27 Aug 14 |
nicklas |
253 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setFatalError('Can\'t find any case for this patient'); |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
256 |
} |
2602 |
27 Aug 14 |
nicklas |
else if (caseOptions.length == 1) |
2602 |
27 Aug 14 |
nicklas |
258 |
{ |
2602 |
27 Aug 14 |
nicklas |
// Only one case, go directly to blood data entries |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('caseName', 'valid', 'Only one case found'); |
2602 |
27 Aug 14 |
nicklas |
Wizard.goNext(true); |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
263 |
} |
2602 |
27 Aug 14 |
nicklas |
else if (caseOptions.length > 1) |
2602 |
27 Aug 14 |
nicklas |
265 |
{ |
2602 |
27 Aug 14 |
nicklas |
// More than one case, let user select case to use |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('caseName', 'valid', caseOptions.length + ' cases found. Select case to use.') |
2602 |
27 Aug 14 |
nicklas |
268 |
} |
2602 |
27 Aug 14 |
nicklas |
269 |
|
2602 |
27 Aug 14 |
nicklas |
Doc.show('gonext'); |
2602 |
27 Aug 14 |
nicklas |
Doc.show('gocancel'); |
2602 |
27 Aug 14 |
nicklas |
272 |
} |
2602 |
27 Aug 14 |
nicklas |
273 |
|
2602 |
27 Aug 14 |
nicklas |
// Nothing to validate |
2602 |
27 Aug 14 |
nicklas |
blood.validateStep2 = function(event) |
2602 |
27 Aug 14 |
nicklas |
276 |
{} |
2602 |
27 Aug 14 |
nicklas |
277 |
|
2602 |
27 Aug 14 |
nicklas |
278 |
|
6824 |
30 Aug 22 |
nicklas |
blood.initializeStep3 = function() |
2602 |
27 Aug 14 |
nicklas |
280 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
2602 |
27 Aug 14 |
nicklas |
282 |
|
2602 |
27 Aug 14 |
nicklas |
var caseId = frm.caseName.value; |
2602 |
27 Aug 14 |
nicklas |
284 |
|
2602 |
27 Aug 14 |
nicklas |
if (!bloodInfo) |
2602 |
27 Aug 14 |
nicklas |
286 |
{ |
2602 |
27 Aug 14 |
nicklas |
var url = '../BloodFollowUpRegistration.servlet?ID='+App.getSessionId(); |
2602 |
27 Aug 14 |
nicklas |
url += '&cmd=GetNextBloodName'; |
2602 |
27 Aug 14 |
nicklas |
url += '&caseId=' + caseId; |
2602 |
27 Aug 14 |
nicklas |
290 |
|
2602 |
27 Aug 14 |
nicklas |
Wizard.showLoadingAnimation('Loading blood information...'); |
2602 |
27 Aug 14 |
nicklas |
Wizard.asyncJsonRequest(url, blood.bloodInfoLoadedFromCase); |
2602 |
27 Aug 14 |
nicklas |
293 |
} |
2602 |
27 Aug 14 |
nicklas |
else |
2602 |
27 Aug 14 |
nicklas |
295 |
{ |
2602 |
27 Aug 14 |
nicklas |
blood.bloodInfoLoadedFromCase(); |
2602 |
27 Aug 14 |
nicklas |
297 |
} |
2602 |
27 Aug 14 |
nicklas |
298 |
} |
2602 |
27 Aug 14 |
nicklas |
299 |
|
2602 |
27 Aug 14 |
nicklas |
blood.bloodInfoLoadedFromCase = function(response) |
2602 |
27 Aug 14 |
nicklas |
301 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
2602 |
27 Aug 14 |
nicklas |
if (response) |
2602 |
27 Aug 14 |
nicklas |
304 |
{ |
2602 |
27 Aug 14 |
nicklas |
bloodInfo = response.bloodInfo; |
2602 |
27 Aug 14 |
nicklas |
consentInfo = response.consentInfo; |
2602 |
27 Aug 14 |
nicklas |
307 |
} |
2602 |
27 Aug 14 |
nicklas |
308 |
|
2602 |
27 Aug 14 |
nicklas |
var updateMode = bloodInfo.id; |
2602 |
27 Aug 14 |
nicklas |
310 |
|
2602 |
27 Aug 14 |
nicklas |
if (updateMode) |
2602 |
27 Aug 14 |
nicklas |
312 |
{ |
2602 |
27 Aug 14 |
nicklas |
Doc.element('step-3-title').innerHTML = 'Update blood \''+Strings.encodeTags(bloodInfo.name)+'\''; |
2602 |
27 Aug 14 |
nicklas |
if (bloodInfo.samplingDate != null) |
2602 |
27 Aug 14 |
nicklas |
315 |
{ |
2602 |
27 Aug 14 |
nicklas |
frm.samplingDate.value = bloodInfo.samplingDate.substring(0, 8); |
2602 |
27 Aug 14 |
nicklas |
frm.samplingTime.value = bloodInfo.samplingDate.substring(9, 13); |
2602 |
27 Aug 14 |
nicklas |
blood.samplingDateTimeOnChange(); |
2602 |
27 Aug 14 |
nicklas |
319 |
} |
2602 |
27 Aug 14 |
nicklas |
if (bloodInfo.freezerDate != null) |
2602 |
27 Aug 14 |
nicklas |
321 |
{ |
2602 |
27 Aug 14 |
nicklas |
frm.freezerDate.value = bloodInfo.freezerDate.substring(0, 8); |
2602 |
27 Aug 14 |
nicklas |
frm.freezerTime.value = bloodInfo.freezerDate.substring(9, 13); |
2602 |
27 Aug 14 |
nicklas |
blood.freezerDateTimeOnChange(); |
2602 |
27 Aug 14 |
nicklas |
325 |
} |
2602 |
27 Aug 14 |
nicklas |
frm.serum.checked = bloodInfo.serum == 'Yes'; |
2602 |
27 Aug 14 |
nicklas |
if (bloodInfo.bloodSample) |
2602 |
27 Aug 14 |
nicklas |
328 |
{ |
2602 |
27 Aug 14 |
nicklas |
Forms.selectListOption(frm.bloodSample, bloodInfo.bloodSample); |
2602 |
27 Aug 14 |
nicklas |
330 |
} |
2602 |
27 Aug 14 |
nicklas |
if (bloodInfo.otherPathNote) |
2602 |
27 Aug 14 |
nicklas |
332 |
{ |
2602 |
27 Aug 14 |
nicklas |
frm.otherPathNote.value = bloodInfo.otherPathNote; |
2602 |
27 Aug 14 |
nicklas |
334 |
} |
2602 |
27 Aug 14 |
nicklas |
335 |
} |
2602 |
27 Aug 14 |
nicklas |
else |
2602 |
27 Aug 14 |
nicklas |
337 |
{ |
2602 |
27 Aug 14 |
nicklas |
frm.serum.checked = true; |
2602 |
27 Aug 14 |
nicklas |
frm.serum.disabled = true; |
2602 |
27 Aug 14 |
nicklas |
// Select follow-up blood annotation from RCCID suffix letter (last character in name) |
2602 |
27 Aug 14 |
nicklas |
var rccidNumber = frm.rccidNumber.value; |
2602 |
27 Aug 14 |
nicklas |
var rccidSuffixLetter = rccidNumber.substring(rccidNumber.length-1, rccidNumber.length); |
2602 |
27 Aug 14 |
nicklas |
var followUpCode = null; |
2602 |
27 Aug 14 |
nicklas |
if (rccidSuffixLetter == 'B') |
2602 |
27 Aug 14 |
nicklas |
345 |
{ |
2602 |
27 Aug 14 |
nicklas |
followUpCode = 'FollowUp06'; |
2602 |
27 Aug 14 |
nicklas |
347 |
} |
2602 |
27 Aug 14 |
nicklas |
else if (rccidSuffixLetter == 'C') |
2602 |
27 Aug 14 |
nicklas |
349 |
{ |
2602 |
27 Aug 14 |
nicklas |
followUpCode = 'FollowUp12'; |
2602 |
27 Aug 14 |
nicklas |
351 |
} |
2602 |
27 Aug 14 |
nicklas |
else if (rccidSuffixLetter == 'D') |
2602 |
27 Aug 14 |
nicklas |
353 |
{ |
2602 |
27 Aug 14 |
nicklas |
followUpCode = 'FollowUp36'; |
2602 |
27 Aug 14 |
nicklas |
355 |
} |
2602 |
27 Aug 14 |
nicklas |
if (followUpCode != null) |
2602 |
27 Aug 14 |
nicklas |
357 |
{ |
2602 |
27 Aug 14 |
nicklas |
Forms.selectListOption(frm.bloodSample, followUpCode); |
2602 |
27 Aug 14 |
nicklas |
frm.bloodSample.disabled = true; |
2602 |
27 Aug 14 |
nicklas |
360 |
} |
2602 |
27 Aug 14 |
nicklas |
if (consentInfo && consentInfo.consent) |
2602 |
27 Aug 14 |
nicklas |
362 |
{ |
2602 |
27 Aug 14 |
nicklas |
frm.copyConsent.value = consentInfo.id; |
2602 |
27 Aug 14 |
nicklas |
var html = "From '" + Strings.encodeTags(consentInfo.name) + "' (" + consentInfo.consent; |
2602 |
27 Aug 14 |
nicklas |
if (consentInfo.consentDate) html += '; ' + consentInfo.consentDate; |
2602 |
27 Aug 14 |
nicklas |
html += ')'; |
2602 |
27 Aug 14 |
nicklas |
Doc.element('copyConsent.text').innerHTML = html; |
2602 |
27 Aug 14 |
nicklas |
Doc.show("copyConsentSection"); |
2602 |
27 Aug 14 |
nicklas |
369 |
} |
2602 |
27 Aug 14 |
nicklas |
370 |
} |
2602 |
27 Aug 14 |
nicklas |
371 |
|
2602 |
27 Aug 14 |
nicklas |
if (updateMode) |
2602 |
27 Aug 14 |
nicklas |
373 |
{ |
2602 |
27 Aug 14 |
nicklas |
Doc.show('goupdate'); |
2602 |
27 Aug 14 |
nicklas |
375 |
} |
2602 |
27 Aug 14 |
nicklas |
else |
2602 |
27 Aug 14 |
nicklas |
377 |
{ |
2602 |
27 Aug 14 |
nicklas |
Doc.show('goregister'); |
2602 |
27 Aug 14 |
nicklas |
379 |
} |
2602 |
27 Aug 14 |
nicklas |
Doc.show('gocancel'); |
2602 |
27 Aug 14 |
nicklas |
Wizard.setCurrentStep(3); |
2602 |
27 Aug 14 |
nicklas |
frm.samplingDate.focus(); |
2602 |
27 Aug 14 |
nicklas |
383 |
} |
2602 |
27 Aug 14 |
nicklas |
384 |
|
2602 |
27 Aug 14 |
nicklas |
blood.validateStep3 = function(event) |
2602 |
27 Aug 14 |
nicklas |
386 |
{ |
2602 |
27 Aug 14 |
nicklas |
if (!samplingDateIsValid || !freezerDateIsValid) |
2602 |
27 Aug 14 |
nicklas |
388 |
{ |
2602 |
27 Aug 14 |
nicklas |
event.preventDefault(); |
2602 |
27 Aug 14 |
nicklas |
390 |
} |
2602 |
27 Aug 14 |
nicklas |
391 |
} |
2602 |
27 Aug 14 |
nicklas |
392 |
|
2602 |
27 Aug 14 |
nicklas |
blood.samplingDateTimeOnChange = function() |
2602 |
27 Aug 14 |
nicklas |
394 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
2602 |
27 Aug 14 |
nicklas |
samplingDateIsValid = false; |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('samplingDate'); |
2602 |
27 Aug 14 |
nicklas |
398 |
|
2602 |
27 Aug 14 |
nicklas |
var samplingDate = frm.samplingDate.value; |
2602 |
27 Aug 14 |
nicklas |
var samplingTime = frm.samplingTime.value; |
2602 |
27 Aug 14 |
nicklas |
401 |
|
2602 |
27 Aug 14 |
nicklas |
if (samplingDate != '' || samplingTime != '') |
2602 |
27 Aug 14 |
nicklas |
403 |
{ |
2602 |
27 Aug 14 |
nicklas |
// Auto-fill the date if it's only given with 4(MMdd) or 6(yyMMdd) digits. |
2602 |
27 Aug 14 |
nicklas |
samplingDate = Reggie.autoFillDate(samplingDate, true); |
2602 |
27 Aug 14 |
nicklas |
frm.samplingDate.value = samplingDate; |
2602 |
27 Aug 14 |
nicklas |
407 |
|
2602 |
27 Aug 14 |
nicklas |
samplingTime = Reggie.autoFillTime(samplingTime); |
2602 |
27 Aug 14 |
nicklas |
frm.samplingTime.value = samplingTime; |
2602 |
27 Aug 14 |
nicklas |
410 |
|
2602 |
27 Aug 14 |
nicklas |
if (!Dates.isDate(samplingDate, 'yyyyMMdd')) |
2602 |
27 Aug 14 |
nicklas |
412 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('samplingDate', 'invalid', 'Not a valid date'); |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
415 |
} |
2602 |
27 Aug 14 |
nicklas |
if (frm.freezerDate.value == '') frm.freezerDate.value = samplingDate; |
2602 |
27 Aug 14 |
nicklas |
417 |
|
2602 |
27 Aug 14 |
nicklas |
if (!Dates.isDate(samplingDate + ' ' + samplingTime, 'yyyyMMdd HHmm')) |
2602 |
27 Aug 14 |
nicklas |
419 |
{ |
2602 |
27 Aug 14 |
nicklas |
if (samplingDate != '') |
2602 |
27 Aug 14 |
nicklas |
421 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('samplingDate', 'invalid', 'Not a valid time'); |
2602 |
27 Aug 14 |
nicklas |
423 |
} |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
425 |
} |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('samplingDate', 'valid'); |
2602 |
27 Aug 14 |
nicklas |
427 |
} |
2602 |
27 Aug 14 |
nicklas |
samplingDateIsValid = true; |
2602 |
27 Aug 14 |
nicklas |
429 |
} |
2602 |
27 Aug 14 |
nicklas |
430 |
|
2602 |
27 Aug 14 |
nicklas |
blood.freezerDateTimeOnChange = function() |
2602 |
27 Aug 14 |
nicklas |
432 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
2602 |
27 Aug 14 |
nicklas |
freezerDateIsValid = false; |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('freezerDate'); |
2602 |
27 Aug 14 |
nicklas |
436 |
|
2602 |
27 Aug 14 |
nicklas |
var freezerDate = frm.freezerDate.value; |
2602 |
27 Aug 14 |
nicklas |
var freezerTime = frm.freezerTime.value; |
2602 |
27 Aug 14 |
nicklas |
var freezerTimestamp; |
2602 |
27 Aug 14 |
nicklas |
440 |
|
2602 |
27 Aug 14 |
nicklas |
if (freezerDate != '' || freezerTime != '') |
2602 |
27 Aug 14 |
nicklas |
442 |
{ |
2602 |
27 Aug 14 |
nicklas |
// Auto-fill the date if it's only given with 4(MMdd) or 6(yyMMdd) digits. |
2602 |
27 Aug 14 |
nicklas |
freezerDate = Reggie.autoFillDate(freezerDate, true); |
2602 |
27 Aug 14 |
nicklas |
frm.freezerDate.value = freezerDate; |
2602 |
27 Aug 14 |
nicklas |
446 |
|
2602 |
27 Aug 14 |
nicklas |
freezerTime = Reggie.autoFillTime(freezerTime); |
2602 |
27 Aug 14 |
nicklas |
frm.freezerTime.value = freezerTime; |
2602 |
27 Aug 14 |
nicklas |
449 |
|
2602 |
27 Aug 14 |
nicklas |
if (!Dates.isDate(freezerDate, 'yyyyMMdd')) |
2602 |
27 Aug 14 |
nicklas |
451 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('freezerDate', 'invalid', 'Not a valid date'); |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
454 |
} |
2602 |
27 Aug 14 |
nicklas |
freezerTimestamp = Dates.parseString(freezerDate + ' ' + freezerTime, 'yyyyMMdd HHmm'); |
2602 |
27 Aug 14 |
nicklas |
if (freezerTimestamp == null) |
2602 |
27 Aug 14 |
nicklas |
457 |
{ |
2602 |
27 Aug 14 |
nicklas |
if (freezerDate != '') |
2602 |
27 Aug 14 |
nicklas |
459 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('freezerDate', 'invalid', 'Not a valid time'); |
2602 |
27 Aug 14 |
nicklas |
461 |
} |
2602 |
27 Aug 14 |
nicklas |
return; |
2602 |
27 Aug 14 |
nicklas |
463 |
} |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('freezerDate', 'valid'); |
2602 |
27 Aug 14 |
nicklas |
465 |
} |
2602 |
27 Aug 14 |
nicklas |
466 |
|
2602 |
27 Aug 14 |
nicklas |
freezerDateIsValid = true; |
2602 |
27 Aug 14 |
nicklas |
468 |
|
2602 |
27 Aug 14 |
nicklas |
if (samplingDateIsValid && freezerTimestamp) |
2602 |
27 Aug 14 |
nicklas |
470 |
{ |
2602 |
27 Aug 14 |
nicklas |
var samplingTimestamp = Dates.parseString(frm.samplingDate.value + ' ' + frm.samplingTime.value, 'yyyyMMdd Hmm'); |
2602 |
27 Aug 14 |
nicklas |
if (samplingTimestamp && samplingTimestamp.getDate() != freezerTimestamp.getDate()) |
2602 |
27 Aug 14 |
nicklas |
473 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.setInputStatus('freezerDate', 'warning', 'Sampling and freezer dates are different'); |
2602 |
27 Aug 14 |
nicklas |
475 |
} |
2602 |
27 Aug 14 |
nicklas |
476 |
} |
2602 |
27 Aug 14 |
nicklas |
477 |
} |
2602 |
27 Aug 14 |
nicklas |
478 |
|
2602 |
27 Aug 14 |
nicklas |
479 |
|
2602 |
27 Aug 14 |
nicklas |
blood.submit = function() |
2602 |
27 Aug 14 |
nicklas |
481 |
{ |
2602 |
27 Aug 14 |
nicklas |
var frm = document.forms['reggie']; |
2602 |
27 Aug 14 |
nicklas |
483 |
|
2602 |
27 Aug 14 |
nicklas |
bloodInfo.rccidNumber = frm.rccidNumber.value; |
2602 |
27 Aug 14 |
nicklas |
bloodInfo.samplingDate = Strings.trim(frm.samplingDate.value + ' ' + frm.samplingTime.value); |
2602 |
27 Aug 14 |
nicklas |
bloodInfo.freezerDate = Strings.trim(frm.freezerDate.value + ' ' + frm.freezerTime.value); |
2602 |
27 Aug 14 |
nicklas |
bloodInfo.serum = "Yes"; |
2602 |
27 Aug 14 |
nicklas |
bloodInfo.bloodSample = frm.bloodSample.value; |
2602 |
27 Aug 14 |
nicklas |
bloodInfo.otherPathNote = frm.otherPathNote.value; |
2602 |
27 Aug 14 |
nicklas |
if (frm.copyConsent.checked && frm.copyConsent.value) |
2602 |
27 Aug 14 |
nicklas |
491 |
{ |
2602 |
27 Aug 14 |
nicklas |
bloodInfo.copyConsent = parseInt(frm.copyConsent.value, 10); |
2602 |
27 Aug 14 |
nicklas |
493 |
} |
2602 |
27 Aug 14 |
nicklas |
494 |
|
2602 |
27 Aug 14 |
nicklas |
var updateMode = bloodInfo.id; |
2602 |
27 Aug 14 |
nicklas |
var submitInfo = {}; |
2602 |
27 Aug 14 |
nicklas |
submitInfo.patientInfo = patientInfo; |
2602 |
27 Aug 14 |
nicklas |
submitInfo.bloodInfo = bloodInfo; |
2602 |
27 Aug 14 |
nicklas |
499 |
|
2602 |
27 Aug 14 |
nicklas |
var url = '../BloodFollowUpRegistration.servlet?ID='+App.getSessionId(); |
2602 |
27 Aug 14 |
nicklas |
url += '&cmd=' + (updateMode ? 'UpdateBlood' : 'CreateBlood'); |
2602 |
27 Aug 14 |
nicklas |
502 |
|
2602 |
27 Aug 14 |
nicklas |
Wizard.showLoadingAnimation('Registering blood information...'); |
2602 |
27 Aug 14 |
nicklas |
Wizard.asyncJsonRequest(url, blood.submissionResults, 'POST', JSON.stringify(submitInfo)); |
2602 |
27 Aug 14 |
nicklas |
505 |
} |
2602 |
27 Aug 14 |
nicklas |
506 |
|
2602 |
27 Aug 14 |
nicklas |
blood.submissionResults = function(response) |
2602 |
27 Aug 14 |
nicklas |
508 |
{ |
2602 |
27 Aug 14 |
nicklas |
Wizard.showFinalMessage(response.messages); |
2602 |
27 Aug 14 |
nicklas |
Doc.show('gorestart'); |
2602 |
27 Aug 14 |
nicklas |
511 |
} |
2602 |
27 Aug 14 |
nicklas |
512 |
|
2602 |
27 Aug 14 |
nicklas |
return blood; |
2602 |
27 Aug 14 |
nicklas |
514 |
}(); |
2602 |
27 Aug 14 |
nicklas |
515 |
|
2602 |
27 Aug 14 |
nicklas |
Doc.onLoad(Blood.initPage); |
2602 |
27 Aug 14 |
nicklas |
517 |
|