extensions/net.sf.basedb.meludi/trunk/resources/personal/ffpe_block_registration_alt_rec.js

Code
Comments
Other
Rev Date Author Line
5044 19 Oct 18 olle 1 var Ffpe_reg = function()
5044 19 Oct 18 olle 2 {
5044 19 Oct 18 olle 3   var ffpe_reg = {};
5044 19 Oct 18 olle 4   var consentToId = { "Yes": "consent.yes", "No" : "consent.no", "Not asked": "consent.notAsked" };
5044 19 Oct 18 olle 5   var patientInfo = null;
5044 19 Oct 18 olle 6   var caseInfo = null;
5044 19 Oct 18 olle 7   var debug = 0;
5044 19 Oct 18 olle 8   
5044 19 Oct 18 olle 9   var sampleItemPrefix = '';
5044 19 Oct 18 olle 10   var sampleItemNumDigits = 5;
5044 19 Oct 18 olle 11   var referralPrefix = '';
5044 19 Oct 18 olle 12   var referralNumDigits = 5;
5044 19 Oct 18 olle 13   var ffpeBlockItemPrefix = '';
5044 19 Oct 18 olle 14   var ffpeBlockItemNumDigits = 1;  
5044 19 Oct 18 olle 15
5044 19 Oct 18 olle 16   var pnrIsValid = false;
5044 19 Oct 18 olle 17   var pnrIsAcceptable = false;
5044 19 Oct 18 olle 18
5044 19 Oct 18 olle 19   ffpe_reg.initPage = function()
5044 19 Oct 18 olle 20   {
5044 19 Oct 18 olle 21     
5044 19 Oct 18 olle 22     // Step 1
5044 19 Oct 18 olle 23     Events.addEventHandler('step-1', 'wizard-validate', ffpe_reg.validateStep1);
5237 16 Jan 19 olle 24     Events.addEventHandler('extractSourceItems', 'change', ffpe_reg.sourceItemsOnChange);
5265 24 Jan 19 olle 25     Events.addEventHandler('personalNumber', 'keyup', ffpe_reg.personalNumberOnChange);
5237 16 Jan 19 olle 26     //Events.addEventHandler('personalNumber', 'keypress', Wizard.goNextOnTabOrEnter);    
5044 19 Oct 18 olle 27
5044 19 Oct 18 olle 28     // Step 2
5044 19 Oct 18 olle 29     Events.addEventHandler('step-2', 'wizard-initialize', ffpe_reg.initializeStep2);
5044 19 Oct 18 olle 30     Events.addEventHandler('step-2', 'wizard-validate', ffpe_reg.validateStep2);
5044 19 Oct 18 olle 31     Events.addEventHandler('consentDate', 'blur', Wizard.validateDate);
5044 19 Oct 18 olle 32     
5044 19 Oct 18 olle 33     Events.addEventHandler('consent.yes', 'change', ffpe_reg.consentOnChange);
5044 19 Oct 18 olle 34     Events.addEventHandler('consent.no', 'change', ffpe_reg.consentOnChange);
5044 19 Oct 18 olle 35     Events.addEventHandler('consent.notAsked', 'change', ffpe_reg.consentOnChange);
5044 19 Oct 18 olle 36     Events.addEventHandler('otherReasonIfNotAsked', 'focus', ffpe_reg.onOtherReasonFocus);
5044 19 Oct 18 olle 37
5237 16 Jan 19 olle 38     //Events.addEventHandler('personalNumber', 'keyup', ffpe_reg.personalNumberOnChange);
5237 16 Jan 19 olle 39     //Events.addEventHandler('personalNumber', 'keypress', Wizard.goNextOnTabOrEnter);
5044 19 Oct 18 olle 40     
5044 19 Oct 18 olle 41     // Step 3
5044 19 Oct 18 olle 42     Events.addEventHandler('step-3', 'wizard-initialize', ffpe_reg.initializeStep3);
5044 19 Oct 18 olle 43     Events.addEventHandler('step-3', 'wizard-validate', ffpe_reg.validateStep3);
5541 05 Jul 19 olle 44     //Events.addEventHandler('addGeneralCommentSelect', 'change', ffpe_reg.addCommentGeneral2);
5044 19 Oct 18 olle 45     Events.addEventHandler('familyName', 'blur', ffpe_reg.nameOnChange);
5044 19 Oct 18 olle 46     Events.addEventHandler('allFirstNames', 'blur', ffpe_reg.nameOnChange);
5044 19 Oct 18 olle 47     Events.addEventHandler('allFirstNames', 'keypress', Wizard.goNextOnTabOrEnter);
5044 19 Oct 18 olle 48
5044 19 Oct 18 olle 49     // Navigation
5044 19 Oct 18 olle 50     Buttons.addClickHandler('gocancel', Wizard.cancelWizard);
5044 19 Oct 18 olle 51     Buttons.addClickHandler('gorestart', Wizard.restartWizard);
5044 19 Oct 18 olle 52     Buttons.addClickHandler('gonext', Wizard.goNextOnClick);
5044 19 Oct 18 olle 53     Buttons.addClickHandler('goregister', Wizard.goRegister);
5203 07 Jan 19 olle 54     Buttons.addClickHandler('today', ffpe_reg.arrivalDateToday);
5044 19 Oct 18 olle 55     
5044 19 Oct 18 olle 56     // Final registration
5044 19 Oct 18 olle 57     Events.addEventHandler('wizard', 'wizard-submit', ffpe_reg.submit);
5044 19 Oct 18 olle 58     
5044 19 Oct 18 olle 59     // Load permissions
5044 19 Oct 18 olle 60     ffpe_reg.initPermissions();
5044 19 Oct 18 olle 61     // Load configuration
5044 19 Oct 18 olle 62     ffpe_reg.loadConfiguration();
5044 19 Oct 18 olle 63
5044 19 Oct 18 olle 64     //Doc.show('step-1');
5044 19 Oct 18 olle 65     //Doc.show('gonext');
5237 16 Jan 19 olle 66
5237 16 Jan 19 olle 67     // Get case items used for FFPE order forms
5237 16 Jan 19 olle 68     var url = '../Extraction.servlet?ID='+App.getSessionId();
5237 16 Jan 19 olle 69     url += '&cmd=GetCasesWithUnprocessedFfpeBlockOrders';    
5237 16 Jan 19 olle 70     Wizard.showLoadingAnimation('Loading processed items...');
5237 16 Jan 19 olle 71     Wizard.asyncJsonRequest(url, ffpe_reg.initializeStep1);
5044 19 Oct 18 olle 72   }
5044 19 Oct 18 olle 73   
5044 19 Oct 18 olle 74   ffpe_reg.initPermissions = function()
5044 19 Oct 18 olle 75   {
5044 19 Oct 18 olle 76     // Get permission information
5044 19 Oct 18 olle 77     var url = '../Install.servlet?ID='+App.getSessionId();
5044 19 Oct 18 olle 78     url += '&cmd=GetPermissions';
5044 19 Oct 18 olle 79     var request = Ajax.getXmlHttpRequest();
5044 19 Oct 18 olle 80     request.open("GET", url, true);
5044 19 Oct 18 olle 81     Ajax.setReadyStateHandler(request, ffpe_reg.onPermissionsLoaded, ffpe_reg.onPermissionsLoaded);
5044 19 Oct 18 olle 82     request.send(null);
5044 19 Oct 18 olle 83   }
5044 19 Oct 18 olle 84   
5044 19 Oct 18 olle 85   // Callback when permission information is ready
5044 19 Oct 18 olle 86   ffpe_reg.onPermissionsLoaded = function(request)
5044 19 Oct 18 olle 87   {
5044 19 Oct 18 olle 88     if (debug) App.debug(Strings.encodeTags(request.responseText));
5044 19 Oct 18 olle 89     var response;
5044 19 Oct 18 olle 90     var error = false;
5044 19 Oct 18 olle 91     try
5044 19 Oct 18 olle 92     {
5044 19 Oct 18 olle 93       response = JSON.parse(request.responseText);
5044 19 Oct 18 olle 94       if (response.status != 'ok')
5044 19 Oct 18 olle 95       {
5044 19 Oct 18 olle 96         error = response.message || response.stacktrace || 'Unexpected error';
5044 19 Oct 18 olle 97       }
5044 19 Oct 18 olle 98     }
5044 19 Oct 18 olle 99     catch (ex)
5044 19 Oct 18 olle 100     {
5044 19 Oct 18 olle 101       error = ex;
5044 19 Oct 18 olle 102     }
5044 19 Oct 18 olle 103     
5044 19 Oct 18 olle 104     if (error)
5044 19 Oct 18 olle 105     {
5044 19 Oct 18 olle 106       alert(error);
5044 19 Oct 18 olle 107       return;
5044 19 Oct 18 olle 108     }
5044 19 Oct 18 olle 109     
5044 19 Oct 18 olle 110     myPermissions = response.permissions;
5044 19 Oct 18 olle 111     //var isAdmin = myPermissions['Administrator'] == 1;
5044 19 Oct 18 olle 112     //var noProjectIsActive = !App.getActiveProjectId();
5044 19 Oct 18 olle 113   }
5044 19 Oct 18 olle 114
5044 19 Oct 18 olle 115   ffpe_reg.loadConfiguration = function()
5044 19 Oct 18 olle 116   {
5044 19 Oct 18 olle 117     var url = '../Session.servlet?ID='+App.getSessionId();
5044 19 Oct 18 olle 118     url += '&cmd=GetConfiguration'
5044 19 Oct 18 olle 119     var request = Ajax.getXmlHttpRequest();
5044 19 Oct 18 olle 120     request.open("GET", url, true);
5044 19 Oct 18 olle 121     Ajax.setReadyStateHandler(request, ffpe_reg.onConfiguration, ffpe_reg.onConfiguration);
5044 19 Oct 18 olle 122     request.send(null);
5044 19 Oct 18 olle 123   }
5044 19 Oct 18 olle 124   
5044 19 Oct 18 olle 125   ffpe_reg.onConfiguration = function(request)
5044 19 Oct 18 olle 126   {
5044 19 Oct 18 olle 127     var frm = document.forms['meludi'];  
5044 19 Oct 18 olle 128
5044 19 Oct 18 olle 129     if (debug)
5044 19 Oct 18 olle 130     {
5044 19 Oct 18 olle 131       App.debug(Strings.encodeTags(request.responseText));
5044 19 Oct 18 olle 132     }
5044 19 Oct 18 olle 133     
5044 19 Oct 18 olle 134     var response;
5044 19 Oct 18 olle 135     var error = false;
5044 19 Oct 18 olle 136     try
5044 19 Oct 18 olle 137     {
5044 19 Oct 18 olle 138       response = JSON.parse(request.responseText);
5044 19 Oct 18 olle 139       if (response.status != 'ok')
5044 19 Oct 18 olle 140       {
5044 19 Oct 18 olle 141         error = response.message || response.stacktrace || 'Unexpected error';
5044 19 Oct 18 olle 142       }
5044 19 Oct 18 olle 143     }
5044 19 Oct 18 olle 144     catch (ex)
5044 19 Oct 18 olle 145     {
5044 19 Oct 18 olle 146       error = ex;
5044 19 Oct 18 olle 147     }
5044 19 Oct 18 olle 148     if (error) App.debug(error);
5044 19 Oct 18 olle 149
5044 19 Oct 18 olle 150     // Get configuration result    
5044 19 Oct 18 olle 151     var conf = response.configuration;
5044 19 Oct 18 olle 152     // Check for uses site prefix flag
5044 19 Oct 18 olle 153     usesSitePrefix = conf.usesSitePrefix;
5044 19 Oct 18 olle 154     ffpeBlockItemPrefix = conf.ffpeBlockItemPrefix;
5044 19 Oct 18 olle 155     ffpeBlockItemNumDigits = conf.ffpeBlockItemNumDigits;
5044 19 Oct 18 olle 156
5044 19 Oct 18 olle 157     // Continue with initializing info for case
5044 19 Oct 18 olle 158     var url = '../ConsentForm.servlet?ID='+App.getSessionId();
5044 19 Oct 18 olle 159     url += '&cmd=CountCases';
5044 19 Oct 18 olle 160     Wizard.showLoadingAnimation('Loading cases...');
5044 19 Oct 18 olle 161     Wizard.asyncJsonRequest(url, ffpe_reg.caseInfoLoadedStep1);
5044 19 Oct 18 olle 162   }
5044 19 Oct 18 olle 163
5044 19 Oct 18 olle 164   ffpe_reg.caseInfoLoadedStep1 = function(response)
5044 19 Oct 18 olle 165   {
5044 19 Oct 18 olle 166     var frm = document.forms['meludi'];  
5044 19 Oct 18 olle 167
5044 19 Oct 18 olle 168     //sampleItemPrefix = response.sampleItemPrefix;
5044 19 Oct 18 olle 169     //sampleItemNumDigits = response.sampleItemNumDigits;
5044 19 Oct 18 olle 170     var nofCases = response.count;
5044 19 Oct 18 olle 171     referralPrefix = response.referralPrefix;
5044 19 Oct 18 olle 172     referralNumDigits = response.referralNumDigits;
5044 19 Oct 18 olle 173 //alert("ffpe_block_registration_alt_rec.js::caseInfoLoadedStep1(): referralPrefix = " + referralPrefix + " referralNumDigits = " + referralNumDigits + " nofCases = " + nofCases);
5044 19 Oct 18 olle 174     //Doc.element('referralIdText').innerHTML = 'The referral ID (barcode) associated with this specimen tube ("' + referralPrefix + '" + ' + referralNumDigits + ' digits).';
5044 19 Oct 18 olle 175 /*
5044 19 Oct 18 olle 176     Doc.element('referralIdText').innerHTML = 'The referral ID (barcode) associated with this case ("' + referralPrefix + '" + ' + referralNumDigits + ' digits).';
5044 19 Oct 18 olle 177 */
5044 19 Oct 18 olle 178   
5044 19 Oct 18 olle 179     Doc.show('step-1');
5044 19 Oct 18 olle 180     Doc.show('gonext');
5044 19 Oct 18 olle 181
5237 16 Jan 19 olle 182     //frm.personalNumber.focus();
5044 19 Oct 18 olle 183   }
5044 19 Oct 18 olle 184
5044 19 Oct 18 olle 185   /**
5044 19 Oct 18 olle 186     Check that the case number is valid.
5044 19 Oct 18 olle 187   */
5237 16 Jan 19 olle 188 /*
5044 19 Oct 18 olle 189   ffpe_reg.validateStep1 = function(event)
5044 19 Oct 18 olle 190   {
5044 19 Oct 18 olle 191     var frm = document.forms['meludi'];
5044 19 Oct 18 olle 192
5044 19 Oct 18 olle 193     var pnr = frm.personalNumber.value;
5044 19 Oct 18 olle 194     var pnrIsValid = false;
5044 19 Oct 18 olle 195     Wizard.setInputStatus('personalNumber');
5044 19 Oct 18 olle 196     if (pnr == '')
5044 19 Oct 18 olle 197     {
5044 19 Oct 18 olle 198       Wizard.setInputStatus('personalNumber', 'invalid', 'Missing');
5044 19 Oct 18 olle 199       frm.personalNumber.focus();
5044 19 Oct 18 olle 200     }
5044 19 Oct 18 olle 201     else
5044 19 Oct 18 olle 202     {
5044 19 Oct 18 olle 203       Wizard.setInputStatus('personalNumber', 'valid');
5044 19 Oct 18 olle 204       pnrIsValid = true;
5044 19 Oct 18 olle 205     }
5044 19 Oct 18 olle 206     
5044 19 Oct 18 olle 207     // If not valid, we prevent the wizard from moving to the next step
5044 19 Oct 18 olle 208     if (!pnrIsValid) event.preventDefault();
5044 19 Oct 18 olle 209   }
5237 16 Jan 19 olle 210 */
5237 16 Jan 19 olle 211
5237 16 Jan 19 olle 212   ffpe_reg.initializeStep1 = function(response)
5237 16 Jan 19 olle 213   {
5237 16 Jan 19 olle 214     var frm = document.forms['meludi'];
5237 16 Jan 19 olle 215     var items = response.items;
5265 24 Jan 19 olle 216     var optPno = frm.personalNumber.value;
5265 24 Jan 19 olle 217     var optPnoLen = optPno.length;
5265 24 Jan 19 olle 218     if (optPnoLen == 13)
5265 24 Jan 19 olle 219     {
5265 24 Jan 19 olle 220       // Remove hyphen
5265 24 Jan 19 olle 221       optPno = optPno.substr(0, 8) + optPno.substr(9, 4);
5265 24 Jan 19 olle 222       optPnoLen = optPno.length;
5265 24 Jan 19 olle 223     }
5237 16 Jan 19 olle 224     
5237 16 Jan 19 olle 225     var sourceItemList = frm.extractSourceItems;
5265 24 Jan 19 olle 226     sourceItemList.length = 0;
5237 16 Jan 19 olle 227     if (items.length)
5237 16 Jan 19 olle 228     {
5237 16 Jan 19 olle 229       var numItems = items.length;
5237 16 Jan 19 olle 230       for (var i=0; i < items.length; i++)
5237 16 Jan 19 olle 231       {
5237 16 Jan 19 olle 232         var item = items[i];
5237 16 Jan 19 olle 233         var name = (i+1) + ': ' + Strings.encodeTags(item.name);
5237 16 Jan 19 olle 234         var referralId = "";
5237 16 Jan 19 olle 235         if (item.referralId)
5237 16 Jan 19 olle 236         {
5237 16 Jan 19 olle 237           referralId = item.referralId;
5237 16 Jan 19 olle 238         }
5265 24 Jan 19 olle 239         var pno = "";
5265 24 Jan 19 olle 240         var pnoInList = "";
5237 16 Jan 19 olle 241         if (item.personalNumber)
5237 16 Jan 19 olle 242         {
5265 24 Jan 19 olle 243           pno = item.personalNumber;
5265 24 Jan 19 olle 244           pnoInList = "" + pno;
5265 24 Jan 19 olle 245           // Add hyphen "-" between birth date and rest of number, if not already there
5265 24 Jan 19 olle 246           if (pnoInList.length == 12)
5265 24 Jan 19 olle 247           {
5265 24 Jan 19 olle 248             pnoInList = pnoInList.substr(0, 8) + '-' + pnoInList.substr(8, 4);
5265 24 Jan 19 olle 249           }
5237 16 Jan 19 olle 250         }
5243 17 Jan 19 olle 251         var ffpeBlockOrderDate = "";
5243 17 Jan 19 olle 252         if (item.ffpeBlockOrderDate)
5243 17 Jan 19 olle 253         {
5243 17 Jan 19 olle 254           ffpeBlockOrderDate = item.ffpeBlockOrderDate;
5243 17 Jan 19 olle 255         }
5265 24 Jan 19 olle 256         //name += ' -- (Referral-ID: ' + Strings.encodeTags(referralId) + ' Pno: ' + Strings.encodeTags(pno) + ')';
5265 24 Jan 19 olle 257         name += ' -- (Pno: ' + Strings.encodeTags(pnoInList) + ' Order date: ' + Strings.encodeTags(ffpeBlockOrderDate) + ')';
5237 16 Jan 19 olle 258         var selected = i < 1;
5265 24 Jan 19 olle 259         if (optPno)
5265 24 Jan 19 olle 260         {
5265 24 Jan 19 olle 261           selected = false;
5265 24 Jan 19 olle 262           if (pno == optPno)
5265 24 Jan 19 olle 263           {
5265 24 Jan 19 olle 264             selected = true;
5265 24 Jan 19 olle 265           }
5265 24 Jan 19 olle 266 //alert("ffpe_block_registration_alt_rec.js::initializeStep1(): optPno = '" + optPno + "' pno = '" + pno + "' selected = " + selected);
5265 24 Jan 19 olle 267         }
5237 16 Jan 19 olle 268         var option = new Option(name, item.id, selected, selected);
5237 16 Jan 19 olle 269         option.item = item;
5237 16 Jan 19 olle 270         sourceItemList.options[sourceItemList.length] = option;
5237 16 Jan 19 olle 271       }
5237 16 Jan 19 olle 272       ffpe_reg.sourceItemsOnChange();
5237 16 Jan 19 olle 273     }
5237 16 Jan 19 olle 274     else
5237 16 Jan 19 olle 275     {
5237 16 Jan 19 olle 276       Wizard.setFatalError('No case items available.');
5237 16 Jan 19 olle 277       return;
5237 16 Jan 19 olle 278     }
5265 24 Jan 19 olle 279     if (!optPno)
5265 24 Jan 19 olle 280     {
5265 24 Jan 19 olle 281       frm.personalNumber.focus();
5265 24 Jan 19 olle 282     }
5237 16 Jan 19 olle 283
5237 16 Jan 19 olle 284     Doc.show('step-1');
5237 16 Jan 19 olle 285     Doc.show('gonext');
5237 16 Jan 19 olle 286   }
5237 16 Jan 19 olle 287     
5237 16 Jan 19 olle 288   ffpe_reg.sourceItemsOnChange = function()
5237 16 Jan 19 olle 289   {
5237 16 Jan 19 olle 290     sourceItemListIsValid = false;
5237 16 Jan 19 olle 291     Wizard.setInputStatus('extractSourceItems');
5237 16 Jan 19 olle 292     
5237 16 Jan 19 olle 293     var frm = document.forms['meludi'];
5237 16 Jan 19 olle 294     var sourceItemList = frm.extractSourceItems;
5237 16 Jan 19 olle 295     
5237 16 Jan 19 olle 296     var numSelected = 0;
5237 16 Jan 19 olle 297     for (var i = 0; i < sourceItemList.length; i++)
5237 16 Jan 19 olle 298     {
5237 16 Jan 19 olle 299       if (sourceItemList[i].selected) numSelected++;
5237 16 Jan 19 olle 300     }
5237 16 Jan 19 olle 301
5237 16 Jan 19 olle 302     if (numSelected < 1)
5237 16 Jan 19 olle 303     {
5237 16 Jan 19 olle 304       Wizard.setInputStatus('extractSourceItems', 'invalid', 'Must select a number of FFPE block items.');
5237 16 Jan 19 olle 305       return;
5237 16 Jan 19 olle 306     }
5237 16 Jan 19 olle 307     
5237 16 Jan 19 olle 308     sourceItemListIsValid = true;
5237 16 Jan 19 olle 309     Wizard.setInputStatus('extractSourceItems', 'valid');
5237 16 Jan 19 olle 310   }
5237 16 Jan 19 olle 311
5237 16 Jan 19 olle 312   ffpe_reg.getSelectedItemsList = function()
5237 16 Jan 19 olle 313   {
5237 16 Jan 19 olle 314     var frm = document.forms['meludi'];
5237 16 Jan 19 olle 315     
5237 16 Jan 19 olle 316     // Get number of selected extract source items
5237 16 Jan 19 olle 317     var numItems = 0;
5237 16 Jan 19 olle 318     var selItemsList = [];
5237 16 Jan 19 olle 319     for (var i = 0; i < frm.extractSourceItems.length; i++)
5237 16 Jan 19 olle 320     {
5237 16 Jan 19 olle 321       if (frm.extractSourceItems[i].selected)
5237 16 Jan 19 olle 322       {
5237 16 Jan 19 olle 323         if (frm.extractSourceItems[i].item != null)
5237 16 Jan 19 olle 324         {
5237 16 Jan 19 olle 325           selItemsList[numItems] = frm.extractSourceItems[i].item;
5237 16 Jan 19 olle 326           numItems++;
5237 16 Jan 19 olle 327         }
5237 16 Jan 19 olle 328       }
5237 16 Jan 19 olle 329     }
5237 16 Jan 19 olle 330     return selItemsList;
5237 16 Jan 19 olle 331   }
5237 16 Jan 19 olle 332
5044 19 Oct 18 olle 333   ffpe_reg.referralIdOnChange = function()
5044 19 Oct 18 olle 334   {
5044 19 Oct 18 olle 335     var frm = document.forms['meludi'];
5044 19 Oct 18 olle 336     var referralId = frm.referralId.value.toUpperCase();
5044 19 Oct 18 olle 337     referralIsValid = false;
5044 19 Oct 18 olle 338     if (referralId == '')
5044 19 Oct 18 olle 339     {
5044 19 Oct 18 olle 340       Wizard.setInputStatus('referralId', 'invalid', 'Missing');
5044 19 Oct 18 olle 341       frm.referralId.focus();
5044 19 Oct 18 olle 342       return;
5044 19 Oct 18 olle 343     }
5044 19 Oct 18 olle 344     if (!Meludi.isValidCaseName2(referralId, referralPrefix, referralNumDigits))
5044 19 Oct 18 olle 345     {
5044 19 Oct 18 olle 346       Wizard.setInputStatus('referralId', 'invalid', 'Only "' + referralPrefix + '" + ' + referralNumDigits + ' digits is allowed.');
5044 19 Oct 18 olle 347       frm.referralId.focus();
5044 19 Oct 18 olle 348       return;
5044 19 Oct 18 olle 349     }
5044 19 Oct 18 olle 350
5044 19 Oct 18 olle 351     frm.referralId.value = referralId;
5044 19 Oct 18 olle 352     Wizard.setInputStatus('referralId', 'valid');
5044 19 Oct 18 olle 353     referralIsValid = true;
5044 19 Oct 18 olle 354
5044 19 Oct 18 olle 355     var url = '../ConsentForm.servlet?ID='+App.getSessionId();
5044 19 Oct 18 olle 356     url += '&cmd=GetCaseInfo';
5044 19 Oct 18 olle 357     url += '&referralId=' + encodeURIComponent(referralId);
5044 19 Oct 18 olle 358     url += '&caseName=';
5044 19 Oct 18 olle 359     Wizard.showLoadingAnimation('Loading information about case...');
5044 19 Oct 18 olle 360     Wizard.asyncJsonRequest(url, ffpe_reg.onCaseInfoLoaded);
5044 19 Oct 18 olle 361   }
5044 19 Oct 18 olle 362
5044 19 Oct 18 olle 363   // Check that the date is valid
5044 19 Oct 18 olle 364   ffpe_reg.validateStep2 = function(event)
5044 19 Oct 18 olle 365   {
5541 05 Jul 19 olle 366 /*  
5044 19 Oct 18 olle 367     var consentDateIsValid = Wizard.isValid('consentDate');
5044 19 Oct 18 olle 368     if (!consentDateIsValid) event.preventDefault();
5541 05 Jul 19 olle 369 */
5044 19 Oct 18 olle 370   }
5044 19 Oct 18 olle 371   
5044 19 Oct 18 olle 372   /**
5044 19 Oct 18 olle 373     Load information about the given case.
5044 19 Oct 18 olle 374   */
5044 19 Oct 18 olle 375   ffpe_reg.initializeStep2 = function(event)
5044 19 Oct 18 olle 376   {
5044 19 Oct 18 olle 377     var frm = document.forms['meludi'];
5237 16 Jan 19 olle 378     //var pnr = frm.personalNumber.value;
5237 16 Jan 19 olle 379     var caseList = ffpe_reg.getSelectedItemsList();
5237 16 Jan 19 olle 380     var caseItem = caseList[0];
5237 16 Jan 19 olle 381     var caseName = caseItem.name;
5237 16 Jan 19 olle 382     var pnr = caseItem.personalNumber;
5044 19 Oct 18 olle 383
5044 19 Oct 18 olle 384     var url = '../ConsentForm.servlet?ID='+App.getSessionId();
5044 19 Oct 18 olle 385     url += '&cmd=GetCaseInfo';
5237 16 Jan 19 olle 386     //url += '&personalNumber=' + encodeURIComponent(pnr);
5237 16 Jan 19 olle 387     url += '&caseName=' + encodeURIComponent(caseName);
5044 19 Oct 18 olle 388     
5044 19 Oct 18 olle 389     Wizard.showLoadingAnimation('Loading case information...');
5044 19 Oct 18 olle 390     Wizard.asyncJsonRequest(url, ffpe_reg.caseInfoLoaded);
5044 19 Oct 18 olle 391   }
5044 19 Oct 18 olle 392   
5044 19 Oct 18 olle 393   /**
5044 19 Oct 18 olle 394     Initalize the second step based on the information we have about the case.
5044 19 Oct 18 olle 395   */
5044 19 Oct 18 olle 396   ffpe_reg.caseInfoLoaded = function(response)
5044 19 Oct 18 olle 397   {
5044 19 Oct 18 olle 398     var frm = document.forms['meludi'];
5044 19 Oct 18 olle 399     caseInfo = response.caseInfo;
5044 19 Oct 18 olle 400     patientInfo = response.patientInfo;
5044 19 Oct 18 olle 401     var caseName = caseInfo.name;
5044 19 Oct 18 olle 402     var specimenInfo = response.specimenInfo;
5044 19 Oct 18 olle 403
5044 19 Oct 18 olle 404     sampleItemPrefix = response.sampleItemPrefix;
5044 19 Oct 18 olle 405     sampleItemNumDigits = response.sampleItemNumDigits;
5044 19 Oct 18 olle 406     
5044 19 Oct 18 olle 407     frm.caseName.value = caseName;
5044 19 Oct 18 olle 408
5044 19 Oct 18 olle 409     if (caseInfo)
5044 19 Oct 18 olle 410     {
5044 19 Oct 18 olle 411       Doc.show('step-2');
5044 19 Oct 18 olle 412       Doc.show('gonext');
5044 19 Oct 18 olle 413     }
5044 19 Oct 18 olle 414
5044 19 Oct 18 olle 415     Wizard.setCurrentStep(2);
5044 19 Oct 18 olle 416   }
5044 19 Oct 18 olle 417   
5044 19 Oct 18 olle 418   ffpe_reg.personalNumberOnChange = function()
5044 19 Oct 18 olle 419   {
5044 19 Oct 18 olle 420     var frm = document.forms['meludi'];
5044 19 Oct 18 olle 421     var pnr = frm.personalNumber.value;
5044 19 Oct 18 olle 422     pnrIsValid = false;
5044 19 Oct 18 olle 423     pnrIsAcceptable = true;
5044 19 Oct 18 olle 424     
5044 19 Oct 18 olle 425     var pnrLen = pnr.length;
5265 24 Jan 19 olle 426     if (pnrLen == 13)
5265 24 Jan 19 olle 427     {
5265 24 Jan 19 olle 428       // Remove hyphen
5265 24 Jan 19 olle 429       pnr = pnr.substr(0, 8) + pnr.substr(9, 4);
5265 24 Jan 19 olle 430       pnrLen = pnr.length;
5265 24 Jan 19 olle 431     }
5044 19 Oct 18 olle 432     if (pnrLen != 12 && pnrLen != 10)
5044 19 Oct 18 olle 433     {
5044 19 Oct 18 olle 434       Wizard.setInputStatus('personalNumber', 'warning', pnrLen < 12 ? 'Too short' : 'Too long');
5044 19 Oct 18 olle 435       return;
5044 19 Oct 18 olle 436     }
5044 19 Oct 18 olle 437
5044 19 Oct 18 olle 438     if (!pnr.match(/^\d+$/))
5044 19 Oct 18 olle 439     {
5044 19 Oct 18 olle 440       Wizard.setInputStatus('personalNumber', 'warning', 'Non-standard personal number');
5044 19 Oct 18 olle 441       return;
5044 19 Oct 18 olle 442     }
5044 19 Oct 18 olle 443     
5044 19 Oct 18 olle 444     var datePart = pnr.substring(0, pnrLen - 4); // Remove last four digits
5044 19 Oct 18 olle 445     var dateFormat = pnrLen == 10 ? 'yyMMdd' : 'yyyyMMdd';
5044 19 Oct 18 olle 446     var isValidDate = Dates.isDate(datePart, dateFormat);
5044 19 Oct 18 olle 447     if (!isValidDate)
5044 19 Oct 18 olle 448     {
5044 19 Oct 18 olle 449       var dayInMonth = parseInt(datePart.substring(-2), 10); // Last two characters
5044 19 Oct 18 olle 450       if (dayInMonth > 60)
5044 19 Oct 18 olle 451       {
5044 19 Oct 18 olle 452         // 'Samordningsnummer' has day-in-month + 60; check this
5044 19 Oct 18 olle 453         dayInMonth -= 60;
5044 19 Oct 18 olle 454         var tmpPnr = pnr.substring(0, pnrLen - 6); // First 4 or 6 digits is year+month
5044 19 Oct 18 olle 455         if (dayInMonth < 10) tmpPnr += '0';
5044 19 Oct 18 olle 456         tmpPnr += dayInMonth;
5044 19 Oct 18 olle 457         isValidDate = Dates.isDate(tmpPnr, dateFormat);
5044 19 Oct 18 olle 458       }
5044 19 Oct 18 olle 459     }
5044 19 Oct 18 olle 460     if (!isValidDate)
5044 19 Oct 18 olle 461     {
5044 19 Oct 18 olle 462       Wizard.setInputStatus('personalNumber', 'warning', 'Not a valid date');
5044 19 Oct 18 olle 463       return;
5044 19 Oct 18 olle 464     }
5044 19 Oct 18 olle 465     
5044 19 Oct 18 olle 466     if (!Meludi.personalNumberControlDigitCheck(pnr.substr(pnrLen == 10 ? 0 : 2)))
5044 19 Oct 18 olle 467     {
5044 19 Oct 18 olle 468       Wizard.setInputStatus('personalNumber', 'warning', 'Invalid control digit');
5044 19 Oct 18 olle 469       return;
5044 19 Oct 18 olle 470     }
5044 19 Oct 18 olle 471
5044 19 Oct 18 olle 472     Wizard.setInputStatus('personalNumber', 'valid');
5044 19 Oct 18 olle 473     pnrIsValid = true;
5044 19 Oct 18 olle 474     Wizard.hideGoNextConfirmation();
5265 24 Jan 19 olle 475
5265 24 Jan 19 olle 476
5265 24 Jan 19 olle 477     // Get case items used for FFPE order forms
5265 24 Jan 19 olle 478     var url = '../Extraction.servlet?ID='+App.getSessionId();
5265 24 Jan 19 olle 479     url += '&cmd=GetCasesWithUnprocessedFfpeBlockOrders';    
5265 24 Jan 19 olle 480     Wizard.showLoadingAnimation('Loading processed items...');
5265 24 Jan 19 olle 481     Wizard.asyncJsonRequest(url, ffpe_reg.initializeStep1);
5044 19 Oct 18 olle 482   }
5044 19 Oct 18 olle 483
5044 19 Oct 18 olle 484   ffpe_reg.initializeStep3 = function()
5044 19 Oct 18 olle 485   {
5044 19 Oct 18 olle 486     var frm = document.forms['meludi'];
5044 19 Oct 18 olle 487     //var tubeContentType = frm.tubeContentType.value;
5044 19 Oct 18 olle 488     //var tubeContentType = 'Specimen';
5044 19 Oct 18 olle 489     var nofBlocks = parseInt(frm.nofBlocks.value);
5044 19 Oct 18 olle 490     //var storageBoxSuffix = streg.fetchStorageBoxSuffix(tubeContentType);
5044 19 Oct 18 olle 491     if (nofBlocks > 2) Doc.addClass('step-2', 'auto-hide');
5044 19 Oct 18 olle 492     
5044 19 Oct 18 olle 493     var html = '';
5044 19 Oct 18 olle 494
5044 19 Oct 18 olle 495     // Add buttons for adding standard comments for all FFPE blocks
5044 19 Oct 18 olle 496     html += '<tr class="section-header">';
5044 19 Oct 18 olle 497     html += '<td colspan="4">Standard comments</td>';
5044 19 Oct 18 olle 498     html += '</tr>';
5044 19 Oct 18 olle 499
5541 05 Jul 19 olle 500 /*
5044 19 Oct 18 olle 501     html += '<tr class="align-top">';
5044 19 Oct 18 olle 502     html += '<td class="subprompt"></td>';
5541 05 Jul 19 olle 503     html += '<td><div class="button basicbutton interactable" id="addClinicalTcPctComment" style="font-weight: normal;">Add &quot;Clinical TC (%)&quot;</div></td>';
5541 05 Jul 19 olle 504     html += '<td class="status" id="addClinicalTcPctComment.status"></td>';
5541 05 Jul 19 olle 505     html += '<td class="help"><span id="addClinicalTcPctComment.message" class="message"></span>Click button to add standard comment for all items.</td>';    
5044 19 Oct 18 olle 506     html += '</tr>';
5541 05 Jul 19 olle 507 */
5044 19 Oct 18 olle 508
5044 19 Oct 18 olle 509     html += '<tr class="align-top">';
5044 19 Oct 18 olle 510     html += '<td class="subprompt"></td>';
5541 05 Jul 19 olle 511     html += '<td class="input">'
5541 05 Jul 19 olle 512     html += '<select name="addGeneralCommentSelect" id="addGeneralCommentSelect" class="auto-init"  data-auto-init="focus-on-enter" >'
5541 05 Jul 19 olle 513     html += '<option selected value="" >- No comment -'
5541 05 Jul 19 olle 514     html += '<option value="Clinical TC (%)" >Add &quot;Clinical TC (%)&quot;'
5541 05 Jul 19 olle 515     //html += '<option value="Another comment" >Add &quot;Another comment&quot;'
5541 05 Jul 19 olle 516     html += '</select>';
5541 05 Jul 19 olle 517     html += '</td>';
5541 05 Jul 19 olle 518     html += '<td class="status" id="addGeneralCommentSelect.status"></td>';
5541 05 Jul 19 olle 519     html += '<td class="help"><span id="addGeneralCommentSelect.message" class="message"></span>Select optional standard comment for all items.</td>';    
5044 19 Oct 18 olle 520     html += '</tr>';
5044 19 Oct 18 olle 521
5541 05 Jul 19 olle 522     html += '<tr class="align-top">';
5541 05 Jul 19 olle 523     html += '<td class="subprompt"></td>';
5541 05 Jul 19 olle 524     html += '<td><div class="button basicbutton interactable" id="addGeneralComment" style="font-weight: normal;">Add general comment</div></td>';
5541 05 Jul 19 olle 525     html += '<td class="status" id="addGeneralComment.status"></td>';
5541 05 Jul 19 olle 526     html += '<td class="help"><span id="addGeneralComment.message" class="message"></span>Click button to add standard comment for all items.</td>';    
5541 05 Jul 19 olle 527     html += '</tr>';
5541 05 Jul 19 olle 528
5044 19 Oct 18 olle 529     for (var i=0; i < nofBlocks; i++)
5044 19 Oct 18 olle 530     {
5044 19 Oct 18 olle 531       var tubeContentTypeName = 'FFPE block ' + i;
5044 19 Oct 18 olle 532       var tubeContentTypeNameInternal =  'FFPE block ' + (i + 1);
5044 19 Oct 18 olle 533       //var blockName = 'BlockName' + i;
5044 19 Oct 18 olle 534       var blockName = '' + (i + 1);
5044 19 Oct 18 olle 535       var tubeNo = i+caseInfo.specimenFirstIndex;
5044 19 Oct 18 olle 536       var tubeIdentifier = 'TubeId' + blockName + i;
5044 19 Oct 18 olle 537       html += '<tr class="section-header">';
5044 19 Oct 18 olle 538       html += '<td colspan="4">FFPE block '+blockName+'</td>';
5044 19 Oct 18 olle 539       html += '</tr>';
5044 19 Oct 18 olle 540
5044 19 Oct 18 olle 541       var padMsg = 'PAD number for '+tubeContentTypeNameInternal+'.';
5160 30 Nov 18 olle 542       var materialNumberMsg = 'Material number for '+tubeContentTypeNameInternal+'.';
5160 30 Nov 18 olle 543       var localisationMsg = 'Localisation for '+tubeContentTypeNameInternal+'.';
5044 19 Oct 18 olle 544       var yellowLabelMsg = 'Assign yellow label for '+tubeContentTypeNameInternal+' (selected for processing).';
5044 19 Oct 18 olle 545       var disabledAttribute = '';
5044 19 Oct 18 olle 546
5044 19 Oct 18 olle 547       // PAD number input field
5044 19 Oct 18 olle 548       html += '<tr>';
5044 19 Oct 18 olle 549       html += '<td class="subprompt">PAD</td>';
5044 19 Oct 18 olle 550       html += '<td class="input">';
5044 19 Oct 18 olle 551       html += '<input type="text" name="pad.'+i+'" id="pad.'+i+'" style="width: 12em;" maxlength="12"'+disabledAttribute+'>';
5044 19 Oct 18 olle 552       html += '</td>';
5044 19 Oct 18 olle 553       html += '<td class="status" id="pad.'+i+'.status"></td>';
5044 19 Oct 18 olle 554       html += '<td class="help"><span id="pad.'+i+'.message" class="message"></span>'+padMsg+'<span id="pad.'+i+'.message" class="message"></span></td>';
5044 19 Oct 18 olle 555       html += '</tr>';
5044 19 Oct 18 olle 556
5074 06 Nov 18 olle 557       // Material number input field
5074 06 Nov 18 olle 558       html += '<tr>';
5074 06 Nov 18 olle 559       html += '<td class="subprompt">Material number</td>';
5074 06 Nov 18 olle 560       html += '<td class="input">';
5160 30 Nov 18 olle 561       html += '<input type="text" name="materialNumber.'+i+'" id="materialNumber.'+i+'" style="width: 12em;" maxlength="12"'+disabledAttribute+'>';
5074 06 Nov 18 olle 562       html += '</td>';
5160 30 Nov 18 olle 563       html += '<td class="status" id="materialNumber.'+i+'.status"></td>';
5160 30 Nov 18 olle 564       html += '<td class="help"><span id="materialNumber.'+i+'.message" class="message"></span>'+materialNumberMsg+'<span id="materialNumber.'+i+'.message" class="message"></span></td>';
5074 06 Nov 18 olle 565       html += '</tr>';
5074 06 Nov 18 olle 566
5160 30 Nov 18 olle 567       // Localisation input field
5074 06 Nov 18 olle 568       html += '<tr>';
5160 30 Nov 18 olle 569       html += '<td class="subprompt">Localisation</td>';
5074 06 Nov 18 olle 570       html += '<td class="input">';
5160 30 Nov 18 olle 571       html += '<input type="text" name="localisation.'+i+'" id="localisation.'+i+'" style="width: 12em;" maxlength="12"'+disabledAttribute+'>';
5074 06 Nov 18 olle 572       html += '</td>';
5160 30 Nov 18 olle 573       html += '<td class="status" id="localisation.'+i+'.status"></td>';
5160 30 Nov 18 olle 574       html += '<td class="help"><span id="localisation.'+i+'.message" class="message"></span>'+localisationMsg+'<span id="localisation.'+i+'.message" class="message"></span></td>';
5074 06 Nov 18 olle 575       html += '</tr>';
5074 06 Nov 18 olle 576
5044 19 Oct 18 olle 577       // Yellow label check box
5044 19 Oct 18 olle 578       html += '<tr>';
5044 19 Oct 18 olle 579       html += '<td class="subprompt">Select for processing</td>';
5044 19 Oct 18 olle 580       html += '<td class="input">';
5044 19 Oct 18 olle 581       html += '<label id="yellowLabel.'+i+'"><input type="checkbox" name="yellowLabel.'+i+'" id="yellowLabel.'+i+'" '+disabledAttribute+'>Yellow label</label>';
5044 19 Oct 18 olle 582       html += '</td>';
5044 19 Oct 18 olle 583       html += '<td class="status" id="yellowLabel.'+i+'.status"></td>';
5044 19 Oct 18 olle 584       html += '<td class="help"><span id="yellowLabel.'+i+'.message" class="message"></span>'+yellowLabelMsg+'<span id="yellowLabel.'+i+'.message" class="message"></span></td>';
5044 19 Oct 18 olle 585       html += '</tr>';
5044 19 Oct 18 olle 586
5044 19 Oct 18 olle 587       // Operator delivery comment
5044 19 Oct 18 olle 588       html += '<tr class="align-top">';
5044 19 Oct 18 olle 589       html += '<td class="subprompt">Operator delivery comment</td>';
5044 19 Oct 18 olle 590       html += '<td class="input"><textarea rows="3" name="comment.'+i+'" id="comment.'+i+'"></textarea></td>';
5044 19 Oct 18 olle 591       html += '<td class="status" id="comment.'+i+'.status"></td>';
5044 19 Oct 18 olle 592       html += '<td class="help"><span id="comment.'+i+'.message" class="message"></span>In this field, enter information specific for '+tubeContentTypeNameInternal+'.</td>';    
5044 19 Oct 18 olle 593       html += '</tr>';
5044 19 Oct 18 olle 594     }
5044 19 Oct 18 olle 595     Doc.element('ffpe-blocks').innerHTML = html;
5044 19 Oct 18 olle 596
5044 19 Oct 18 olle 597     // Add click handlers for buttons for adding standard comments for all specimens/RNA/DNA
5541 05 Jul 19 olle 598     var addGeneralCommentButton = Doc.element('addGeneralComment');
5541 05 Jul 19 olle 599     Buttons.addClickHandler(addGeneralCommentButton, ffpe_reg.addCommentGeneral2, {'nofBlocks': nofBlocks, 'text-field': 'comment.', 'text': 'Not used'});
5541 05 Jul 19 olle 600 /*
5541 05 Jul 19 olle 601     var addClinicalTcPctCommentGeneralButton = Doc.element('addClinicalTcPctComment');
5541 05 Jul 19 olle 602     Buttons.addClickHandler(addClinicalTcPctCommentGeneralButton, ffpe_reg.addCommentGeneral, {'nofBlocks': nofBlocks, 'text-field': 'comment.', 'text': 'Clinical TC (%)'});
5541 05 Jul 19 olle 603 */
5044 19 Oct 18 olle 604
5044 19 Oct 18 olle 605     Wizard.setCurrentStep(3);
5044 19 Oct 18 olle 606     Doc.show('goregister');
5044 19 Oct 18 olle 607     Doc.show('gocancel');
5044 19 Oct 18 olle 608     frm['pad.0'].focus();
5044 19 Oct 18 olle 609   }
5044 19 Oct 18 olle 610
5044 19 Oct 18 olle 611   ffpe_reg.addCommentGeneral = function(event)
5044 19 Oct 18 olle 612   {
5044 19 Oct 18 olle 613     var nofBlocks = Data.get(event.currentTarget, 'nofBlocks', event.currentTarget.id);
5044 19 Oct 18 olle 614     var textFieldBase = Data.get(event.currentTarget, 'text-field', event.currentTarget.id);
5044 19 Oct 18 olle 615     // Get standard comment text to add
5044 19 Oct 18 olle 616     var text = Data.get(event.currentTarget, 'text', event.currentTarget.id);
5541 05 Jul 19 olle 617     //alert("ffpe_block_registration_alt_rec.js::addCommentGeneral(): text = '" + text + "'.");
5044 19 Oct 18 olle 618     // Loop over comment fields to update
5044 19 Oct 18 olle 619     for (var i=0; i < nofBlocks; i++)
5044 19 Oct 18 olle 620     {
5044 19 Oct 18 olle 621       var textField = Doc.element(textFieldBase+i);
5044 19 Oct 18 olle 622       if (textField)
5044 19 Oct 18 olle 623       {
5044 19 Oct 18 olle 624         if (text && text != '')
5044 19 Oct 18 olle 625         {
5044 19 Oct 18 olle 626           // Check if current comment field already contains text
5044 19 Oct 18 olle 627           if (textField.value != '')
5044 19 Oct 18 olle 628           {
5044 19 Oct 18 olle 629             // Add space to text in current comment field
5044 19 Oct 18 olle 630             textField.value += ' ';
5044 19 Oct 18 olle 631           }
5044 19 Oct 18 olle 632           // Add standard comment text
5044 19 Oct 18 olle 633           textField.value += text;
5044 19 Oct 18 olle 634         }
5044 19 Oct 18 olle 635       }
5044 19 Oct 18 olle 636     }
5044 19 Oct 18 olle 637   }
5044 19 Oct 18 olle 638   
5541 05 Jul 19 olle 639   ffpe_reg.addCommentGeneral2 = function(event)
5541 05 Jul 19 olle 640   {
5541 05 Jul 19 olle 641     var nofBlocks = Data.get(event.currentTarget, 'nofBlocks', event.currentTarget.id);
5541 05 Jul 19 olle 642     var textFieldBase = Data.get(event.currentTarget, 'text-field', event.currentTarget.id);
5541 05 Jul 19 olle 643     // Get standard comment text to add
5541 05 Jul 19 olle 644     var frm = document.forms['meludi'];
5541 05 Jul 19 olle 645     var genCmtItemList = frm.addGeneralCommentSelect;
5541 05 Jul 19 olle 646     //alert("ffpe_block_registration_alt_rec.js::addCommentGeneral2(): genCmtItemList.length = " + genCmtItemList.length);
5541 05 Jul 19 olle 647     var text = "";
5541 05 Jul 19 olle 648     var numSelected = 0;
5541 05 Jul 19 olle 649     var optSelected = -1;
5541 05 Jul 19 olle 650     for (var i = 0; i < genCmtItemList.length; i++)
5541 05 Jul 19 olle 651     {
5541 05 Jul 19 olle 652       if (genCmtItemList[i].selected)
5541 05 Jul 19 olle 653       {
5541 05 Jul 19 olle 654         text = genCmtItemList[i].value;
5541 05 Jul 19 olle 655         numSelected++;
5541 05 Jul 19 olle 656         optSelected = i;
5541 05 Jul 19 olle 657       }
5541 05 Jul 19 olle 658     }
5541 05 Jul 19 olle 659     //alert("ffpe_block_registration_alt_rec.js::addCommentGeneral2(): numSelected = " + numSelected + " optSelected = " + optSelected + " text = '" + text + "'.");
5541 05 Jul 19 olle 660     // Loop over comment fields to update
5541 05 Jul 19 olle 661     for (var i=0; i < nofBlocks; i++)
5541 05 Jul 19 olle 662     {
5541 05 Jul 19 olle 663       var textField = Doc.element(textFieldBase+i);
5541 05 Jul 19 olle 664       if (textField)
5541 05 Jul 19 olle 665       {
5541 05 Jul 19 olle 666         if (text && text != '')
5541 05 Jul 19 olle 667         {
5541 05 Jul 19 olle 668           // Check if current comment field already contains text
5541 05 Jul 19 olle 669           if (textField.value != '')
5541 05 Jul 19 olle 670           {
5541 05 Jul 19 olle 671             // Add space to text in current comment field
5541 05 Jul 19 olle 672             textField.value += ' ';
5541 05 Jul 19 olle 673           }
5541 05 Jul 19 olle 674           // Add standard comment text
5541 05 Jul 19 olle 675           textField.value += text;
5541 05 Jul 19 olle 676         }
5541 05 Jul 19 olle 677       }
5541 05 Jul 19 olle 678     }
5541 05 Jul 19 olle 679   }
5541 05 Jul 19 olle 680     
5044 19 Oct 18 olle 681   ffpe_reg.patientInfoLoaded = function(response)
5044 19 Oct 18 olle 682   {
5044 19 Oct 18 olle 683     Wizard.setCurrentStep(3);
5044 19 Oct 18 olle 684     // Get patient information from the AJAX response
5044 19 Oct 18 olle 685     patientInfo = response.patientInfo;
5044 19 Oct 18 olle 686     var frm = document.forms['meludi'];
5044 19 Oct 18 olle 687
5044 19 Oct 18 olle 688
5044 19 Oct 18 olle 689     frm.patientCode.value=patientInfo.name;
5044 19 Oct 18 olle 690     frm.familyName.value = patientInfo.familyName || '';
5044 19 Oct 18 olle 691     frm.allFirstNames.value = patientInfo.allFirstNames || '';
5044 19 Oct 18 olle 692     Doc.element('dateOfBirth').innerHTML = patientInfo.dateOfBirth ? Strings.encodeTags(patientInfo.dateOfBirth) : '---';
5044 19 Oct 18 olle 693     Doc.element('gender').innerHTML = patientInfo.gender ? Strings.encodeTags(patientInfo.gender) : '---';
5044 19 Oct 18 olle 694     frm.familyName.focus();
5044 19 Oct 18 olle 695
5044 19 Oct 18 olle 696     if (!patientInfo.id)
5044 19 Oct 18 olle 697     {
5044 19 Oct 18 olle 698       if (!pnrIsValid)
5044 19 Oct 18 olle 699       {
5044 19 Oct 18 olle 700         Wizard.setInputStatus('gender', 'warning', 'Gender and DateOfBirth can\'t be automatically generated for non-standard Personal number');
5044 19 Oct 18 olle 701       }
5044 19 Oct 18 olle 702     }
5044 19 Oct 18 olle 703     else
5044 19 Oct 18 olle 704     {
5044 19 Oct 18 olle 705       Doc.element('step-3-title').innerHTML = 'Existing patient: Verify names';
5044 19 Oct 18 olle 706       frm.patientCode.disabled = true;
5044 19 Oct 18 olle 707     }
5044 19 Oct 18 olle 708     
5044 19 Oct 18 olle 709     //Doc.show('gonext');
5044 19 Oct 18 olle 710     //Doc.show('gocancel');    
5044 19 Oct 18 olle 711     Doc.show('gocancel');
5044 19 Oct 18 olle 712     Doc.show('goregister');
5044 19 Oct 18 olle 713   }
5044 19 Oct 18 olle 714   
5044 19 Oct 18 olle 715   ffpe_reg.validateStep3 = function(event)
5044 19 Oct 18 olle 716   {
5044 19 Oct 18 olle 717     var valid = true;
5044 19 Oct 18 olle 718     var acceptable = true;
5044 19 Oct 18 olle 719     var frm = document.forms['meludi'];
5044 19 Oct 18 olle 720
5044 19 Oct 18 olle 721     // Check that all FFPE blocks have PAD numbers
5044 19 Oct 18 olle 722     var nofBlocks = parseInt(frm.nofBlocks.value);
5044 19 Oct 18 olle 723     for (var i = 0; i < nofBlocks; i++)
5044 19 Oct 18 olle 724     {
5044 19 Oct 18 olle 725       if (frm['pad.'+i].value == '')
5044 19 Oct 18 olle 726       {
5044 19 Oct 18 olle 727         Wizard.setInputStatus('pad.'+i, 'warning', 'Missing');
5044 19 Oct 18 olle 728         valid = false;
5044 19 Oct 18 olle 729       }
5044 19 Oct 18 olle 730     }
5044 19 Oct 18 olle 731
5044 19 Oct 18 olle 732     if (!valid)
5044 19 Oct 18 olle 733     {
5044 19 Oct 18 olle 734       event.preventDefault();
5044 19 Oct 18 olle 735     }
5044 19 Oct 18 olle 736   }
5044 19 Oct 18 olle 737
5044 19 Oct 18 olle 738   ffpe_reg.submit = function()
5044 19 Oct 18 olle 739   {
5044 19 Oct 18 olle 740     var frm = document.forms['meludi'];
5044 19 Oct 18 olle 741     //var updateMode = caseInfo.id;
5044 19 Oct 18 olle 742     
5044 19 Oct 18 olle 743     var ffpeBlockInfo = {};
5044 19 Oct 18 olle 744     var nofBlocks = parseInt(frm.nofBlocks.value);
5044 19 Oct 18 olle 745     ffpeBlockInfo.ffpeBlock = [];
5044 19 Oct 18 olle 746     for (var i = 0; i < nofBlocks; i++)
5044 19 Oct 18 olle 747     {
5044 19 Oct 18 olle 748       var ffpeBlock ={};
5044 19 Oct 18 olle 749       ffpeBlock.caseName = frm['caseName'].value;
5044 19 Oct 18 olle 750       //ffpeBlock.samplingDate = frm['samplingDate'].value;
5044 19 Oct 18 olle 751       ffpeBlock.arrivalDate = frm['arrivalDate'].value;
5044 19 Oct 18 olle 752       ffpeBlock.pad = frm['pad.'+i].value;
5160 30 Nov 18 olle 753       ffpeBlock.materialNumber = frm['materialNumber.'+i].value;
5160 30 Nov 18 olle 754       ffpeBlock.localisation = frm['localisation.'+i].value;
5047 22 Oct 18 olle 755       ffpeBlock.yellowLabel = null;
5047 22 Oct 18 olle 756       var yellowLabelCB = false;
5047 22 Oct 18 olle 757       yellowLabelCB = frm['yellowLabel.'+i].checked;
5047 22 Oct 18 olle 758       if (yellowLabelCB)
5047 22 Oct 18 olle 759       {
5047 22 Oct 18 olle 760         ffpeBlock.yellowLabel = 'yellow';
5047 22 Oct 18 olle 761       }
5044 19 Oct 18 olle 762       ffpeBlock.comment = frm['comment.'+i].value;
5044 19 Oct 18 olle 763       //ffpeBlock.operator = frm['operator'].value;
5044 19 Oct 18 olle 764       ffpeBlockInfo.ffpeBlock[i] = ffpeBlock;
5044 19 Oct 18 olle 765     }
5044 19 Oct 18 olle 766     var submitInfo = {};
5044 19 Oct 18 olle 767     submitInfo.ffpeBlockInfo = ffpeBlockInfo;
5044 19 Oct 18 olle 768
5044 19 Oct 18 olle 769     var url = '../BaseLineRegistration.servlet?ID='+App.getSessionId();
5044 19 Oct 18 olle 770     url += '&cmd=RegisterFFPEBlocks';
5044 19 Oct 18 olle 771     Wizard.showLoadingAnimation('Registering FFPE block[s]...');
5044 19 Oct 18 olle 772     Wizard.asyncJsonRequest(url, ffpe_reg.submissionResults, 'POST', JSON.stringify(submitInfo));
5044 19 Oct 18 olle 773   }
5044 19 Oct 18 olle 774   
5044 19 Oct 18 olle 775   ffpe_reg.submissionResults = function(response)
5044 19 Oct 18 olle 776   {
5044 19 Oct 18 olle 777     Wizard.showFinalMessage(response.messages);
5044 19 Oct 18 olle 778     Doc.show('gorestart');
5044 19 Oct 18 olle 779     //Doc.show('downloadformbatch2');
5044 19 Oct 18 olle 780   }
5044 19 Oct 18 olle 781
5044 19 Oct 18 olle 782
5044 19 Oct 18 olle 783   ffpe_reg.enableConsentOption = function(option, checkIt)
5044 19 Oct 18 olle 784   {
5044 19 Oct 18 olle 785     option = Doc.element(option); // The radio button
5044 19 Oct 18 olle 786     option.disabled = false;
5044 19 Oct 18 olle 787     if (checkIt) option.checked = true;
5044 19 Oct 18 olle 788     
5044 19 Oct 18 olle 789     var label = Doc.element(option.id + '.label'); // The label
5044 19 Oct 18 olle 790     Doc.removeClass(label, 'disabled');
5044 19 Oct 18 olle 791   }
5044 19 Oct 18 olle 792
5044 19 Oct 18 olle 793
5044 19 Oct 18 olle 794
5044 19 Oct 18 olle 795   ffpe_reg.consentOnChange = function()
5044 19 Oct 18 olle 796   {
5044 19 Oct 18 olle 797     // If "Not asked" is selected we must enable the second question
5044 19 Oct 18 olle 798     var isAsked = !Doc.element('consent.notAsked').checked;
5044 19 Oct 18 olle 799     
5044 19 Oct 18 olle 800     var frm = document.forms['meludi'];
5044 19 Oct 18 olle 801     var reasonIfNotAsked = frm.reasonIfNotAsked;
5044 19 Oct 18 olle 802     for (var i = 0; i < reasonIfNotAsked.length; i++)
5044 19 Oct 18 olle 803     {
5044 19 Oct 18 olle 804       reasonIfNotAsked[i].disabled = isAsked;
5044 19 Oct 18 olle 805       Doc.addOrRemoveClass(reasonIfNotAsked[i].id + '.label', 'disabled', isAsked);
5044 19 Oct 18 olle 806     }
5044 19 Oct 18 olle 807     frm.otherReasonIfNotAsked.disabled = isAsked;    
5044 19 Oct 18 olle 808   }
5044 19 Oct 18 olle 809   
5044 19 Oct 18 olle 810   ffpe_reg.onOtherReasonFocus = function()
5044 19 Oct 18 olle 811   {
5044 19 Oct 18 olle 812     Doc.element('notAsked.other').checked = true;
5044 19 Oct 18 olle 813   }
5044 19 Oct 18 olle 814
5203 07 Jan 19 olle 815   Date.prototype.yyyymmdd = function()
5203 07 Jan 19 olle 816   {
5203 07 Jan 19 olle 817     var mm = this.getMonth() + 1; // getMonth() is zero-based
5203 07 Jan 19 olle 818     var dd = this.getDate();
5203 07 Jan 19 olle 819
5203 07 Jan 19 olle 820     return [this.getFullYear(),
5203 07 Jan 19 olle 821       (mm>9 ? '' : '0') + mm,
5203 07 Jan 19 olle 822       (dd>9 ? '' : '0') + dd
5203 07 Jan 19 olle 823       ].join('');
5203 07 Jan 19 olle 824   };
5203 07 Jan 19 olle 825
5203 07 Jan 19 olle 826   ffpe_reg.arrivalDateToday = function()
5203 07 Jan 19 olle 827   {
5203 07 Jan 19 olle 828     var frm = document.forms['meludi'];
5203 07 Jan 19 olle 829
5203 07 Jan 19 olle 830     // Get today's date and insert into date field
5203 07 Jan 19 olle 831     var date = new Date();
5203 07 Jan 19 olle 832     frm['arrivalDate'].value = date.yyyymmdd();
5203 07 Jan 19 olle 833   }
5203 07 Jan 19 olle 834
5044 19 Oct 18 olle 835   return ffpe_reg;
5044 19 Oct 18 olle 836 }();
5044 19 Oct 18 olle 837
5044 19 Oct 18 olle 838 Doc.onLoad(Ffpe_reg.initPage);
5044 19 Oct 18 olle 839