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

Code
Comments
Other
Rev Date Author Line
5000 03 Oct 18 olle 1 var PersInfo = function()
5000 03 Oct 18 olle 2 {
5000 03 Oct 18 olle 3   var persinfo = {};
5000 03 Oct 18 olle 4   var debug = 0;
5000 03 Oct 18 olle 5   
5000 03 Oct 18 olle 6   //var caseInfo = null;
5000 03 Oct 18 olle 7   //var bloodInfo = null;
5000 03 Oct 18 olle 8   var nofBloodTubes = 0;
5000 03 Oct 18 olle 9
5000 03 Oct 18 olle 10   var baseLineFileIsValid = false;
5000 03 Oct 18 olle 11
5000 03 Oct 18 olle 12   var pnrIsValid = false;
5000 03 Oct 18 olle 13   var pnrIsAcceptable = false;
5000 03 Oct 18 olle 14   var caseIsValid = false;
5000 03 Oct 18 olle 15
5000 03 Oct 18 olle 16   var sampleItemPrefix = '';
5000 03 Oct 18 olle 17   var sampleItemNumDigits = 5;
5000 03 Oct 18 olle 18   var bloodItemPrefix = '';
5000 03 Oct 18 olle 19   var nofTubesIsValid = false;
5000 03 Oct 18 olle 20   var bloodItemNumDigits = 5;
5000 03 Oct 18 olle 21   var bloodSamplingDateIsValid = true;
5000 03 Oct 18 olle 22   var viableTumourCellsPercentIsValid = true;
5000 03 Oct 18 olle 23   var usesSitePrefix = false;
5002 04 Oct 18 olle 24   var problemFound = false;
5000 03 Oct 18 olle 25
5000 03 Oct 18 olle 26   // Well validation variable for input specimen, DNA, RNA
5000 03 Oct 18 olle 27   var wellIsValid = [];
5000 03 Oct 18 olle 28   // Well validation variables for extracts from specimen
5000 03 Oct 18 olle 29   var dnaWellIsValid = [];
5000 03 Oct 18 olle 30   var rnaWellIsValid = [];
5000 03 Oct 18 olle 31
5000 03 Oct 18 olle 32   persinfo.initPage = function()
5000 03 Oct 18 olle 33   {
5000 03 Oct 18 olle 34     
5000 03 Oct 18 olle 35     // Step 1
5149 28 Nov 18 olle 36     Wizard.initFileSelectionField('baseLineFile');
5000 03 Oct 18 olle 37     Events.addEventHandler('step-1', 'wizard-validate', persinfo.validateStep1);
5000 03 Oct 18 olle 38     //Events.addEventHandler('caseName', 'keypress', Wizard.goNextOnTabOrEnter);
5000 03 Oct 18 olle 39     //Events.addEventHandler('caseName', 'blur', persinfo.caseNameOnChange);
5000 03 Oct 18 olle 40     // Events.addEventHandler('baseLineFile', 'change', persinfo.baseLineFileOnChange);
5000 03 Oct 18 olle 41         
5000 03 Oct 18 olle 42     // Step 2
5000 03 Oct 18 olle 43     Events.addEventHandler('step-2', 'wizard-initialize', persinfo.initializeStep2);
5000 03 Oct 18 olle 44     Events.addEventHandler('step-2', 'wizard-validate', persinfo.validateStep2);
5000 03 Oct 18 olle 45     
5000 03 Oct 18 olle 46     // Navigation
5000 03 Oct 18 olle 47     Buttons.addClickHandler('gocancel', Wizard.cancelWizard);
5000 03 Oct 18 olle 48     Buttons.addClickHandler('gorestart', Wizard.restartWizard);
5000 03 Oct 18 olle 49     Buttons.addClickHandler('gonext', Wizard.goNextOnClick);
5000 03 Oct 18 olle 50     Buttons.addClickHandler('goregister', Wizard.goRegister);
5000 03 Oct 18 olle 51     Buttons.addClickHandler('goupdate', Wizard.goRegister);
5000 03 Oct 18 olle 52     //Buttons.addClickHandler('downloadformbatch2', persinfo.downloadFormBatch2);
5000 03 Oct 18 olle 53     
5000 03 Oct 18 olle 54     // Final registration
5000 03 Oct 18 olle 55     Events.addEventHandler('wizard', 'wizard-submit', persinfo.submit);
5000 03 Oct 18 olle 56     
5000 03 Oct 18 olle 57     // Load configuration
5000 03 Oct 18 olle 58     persinfo.loadConfiguration();
5000 03 Oct 18 olle 59   }
5000 03 Oct 18 olle 60   
5000 03 Oct 18 olle 61   persinfo.loadConfiguration = function()
5000 03 Oct 18 olle 62   {
5000 03 Oct 18 olle 63     var url = '../Session.servlet?ID='+App.getSessionId();
5000 03 Oct 18 olle 64     url += '&cmd=GetConfiguration'
5000 03 Oct 18 olle 65     var request = Ajax.getXmlHttpRequest();
5000 03 Oct 18 olle 66     request.open("GET", url, true);
5000 03 Oct 18 olle 67     Ajax.setReadyStateHandler(request, persinfo.onConfiguration, persinfo.onConfiguration);
5000 03 Oct 18 olle 68     request.send(null);
5000 03 Oct 18 olle 69   }
5000 03 Oct 18 olle 70   
5000 03 Oct 18 olle 71   persinfo.onConfiguration = function(request)
5000 03 Oct 18 olle 72   {
5000 03 Oct 18 olle 73     var frm = document.forms['meludi'];  
5000 03 Oct 18 olle 74
5000 03 Oct 18 olle 75     if (debug)
5000 03 Oct 18 olle 76     {
5000 03 Oct 18 olle 77       App.debug(Strings.encodeTags(request.responseText));
5000 03 Oct 18 olle 78     }
5000 03 Oct 18 olle 79     
5000 03 Oct 18 olle 80     var response;
5000 03 Oct 18 olle 81     var error = false;
5000 03 Oct 18 olle 82     try
5000 03 Oct 18 olle 83     {
5000 03 Oct 18 olle 84       response = JSON.parse(request.responseText);
5000 03 Oct 18 olle 85       if (response.status != 'ok')
5000 03 Oct 18 olle 86       {
5000 03 Oct 18 olle 87         error = response.message || response.stacktrace || 'Unexpected error';
5000 03 Oct 18 olle 88       }
5000 03 Oct 18 olle 89     }
5000 03 Oct 18 olle 90     catch (ex)
5000 03 Oct 18 olle 91     {
5000 03 Oct 18 olle 92       error = ex;
5000 03 Oct 18 olle 93     }
5000 03 Oct 18 olle 94     if (error) App.debug(error);
5000 03 Oct 18 olle 95
5000 03 Oct 18 olle 96     // Get configuration result    
5000 03 Oct 18 olle 97     var conf = response.configuration;
5000 03 Oct 18 olle 98     // Check for uses site prefix flag
5000 03 Oct 18 olle 99     usesSitePrefix = conf.usesSitePrefix;
5000 03 Oct 18 olle 100     sampleItemPrefix = conf.sampleItemPrefix;
5000 03 Oct 18 olle 101     sampleItemNumDigits = conf.sampleItemNumDigits;
5000 03 Oct 18 olle 102     bloodItemPrefix = conf.bloodItemPrefix;
5000 03 Oct 18 olle 103     bloodItemNumDigits = conf.bloodItemNumDigits;
5000 03 Oct 18 olle 104
5000 03 Oct 18 olle 105 /*
5000 03 Oct 18 olle 106     // Continue with initializing info for case
5000 03 Oct 18 olle 107     var url = '../LabelGeneration.servlet?ID='+App.getSessionId();
5000 03 Oct 18 olle 108     url += '&cmd=CountCases';
5000 03 Oct 18 olle 109     Wizard.showLoadingAnimation('Loading cases...');
5000 03 Oct 18 olle 110     Wizard.asyncJsonRequest(url, persinfo.caseInfoLoadedStep1);
5000 03 Oct 18 olle 111 */
5000 03 Oct 18 olle 112     Doc.show('step-1');
5000 03 Oct 18 olle 113     Doc.show('gonext');
5000 03 Oct 18 olle 114
5000 03 Oct 18 olle 115     // Ensure that flag 'caseIsValid' is set to 'true' or error reported
5000 03 Oct 18 olle 116     //persinfo.caseNameOnChange();
5000 03 Oct 18 olle 117   }
5000 03 Oct 18 olle 118
5000 03 Oct 18 olle 119   persinfo.caseInfoLoadedStep1 = function(response)
5000 03 Oct 18 olle 120   {
5000 03 Oct 18 olle 121     var frm = document.forms['meludi'];  
5000 03 Oct 18 olle 122
5000 03 Oct 18 olle 123     sampleItemPrefix = response.sampleItemPrefix;
5000 03 Oct 18 olle 124     sampleItemNumDigits = response.sampleItemNumDigits;
5000 03 Oct 18 olle 125     bloodItemPrefix = response.bloodItemPrefix;
5000 03 Oct 18 olle 126     var nofCases = response.count;
5000 03 Oct 18 olle 127     if (nofCases == null)
5000 03 Oct 18 olle 128     {
5000 03 Oct 18 olle 129       nofCases = 0;
5000 03 Oct 18 olle 130     }
5000 03 Oct 18 olle 131     var startNum = nofCases + 1;
5000 03 Oct 18 olle 132     // Pad number with leading zeros to get right number of digits
5000 03 Oct 18 olle 133     startNum = String('0000000000' + startNum).slice(-sampleItemNumDigits);
5000 03 Oct 18 olle 134     var startCase = sampleItemPrefix + startNum;
5000 03 Oct 18 olle 135     if (usesSitePrefix != null && usesSitePrefix)
5000 03 Oct 18 olle 136     {
5000 03 Oct 18 olle 137       startCase = '';
5000 03 Oct 18 olle 138     }
5000 03 Oct 18 olle 139     frm.caseName.value = startCase;
5000 03 Oct 18 olle 140     
5000 03 Oct 18 olle 141     Doc.show('step-1');
5000 03 Oct 18 olle 142     Doc.show('gonext');
5000 03 Oct 18 olle 143
5000 03 Oct 18 olle 144     // Ensure that flag 'caseIsValid' is set to 'true' or error reported
5000 03 Oct 18 olle 145     persinfo.caseNameOnChange();
5000 03 Oct 18 olle 146   }
5000 03 Oct 18 olle 147   
5000 03 Oct 18 olle 148   persinfo.caseNameOnChange = function()
5000 03 Oct 18 olle 149   {
5000 03 Oct 18 olle 150     var frm = document.forms['meludi'];
5000 03 Oct 18 olle 151     var caseName = frm.caseName.value.toUpperCase();
5000 03 Oct 18 olle 152     caseIsValid = false;
5000 03 Oct 18 olle 153     if (caseName == '')
5000 03 Oct 18 olle 154     {
5000 03 Oct 18 olle 155       Wizard.setInputStatus('caseName', 'invalid', 'Missing');
5000 03 Oct 18 olle 156       frm.caseName.focus();
5000 03 Oct 18 olle 157       return;
5000 03 Oct 18 olle 158     }
5000 03 Oct 18 olle 159     if (!Meludi.isValidCaseName2(caseName, sampleItemPrefix, sampleItemNumDigits))
5000 03 Oct 18 olle 160     {
5000 03 Oct 18 olle 161       Wizard.setInputStatus('caseName', 'invalid', 'Only "' + sampleItemPrefix + '" + ' + sampleItemNumDigits + ' digits is allowed.');
5000 03 Oct 18 olle 162       frm.caseName.focus();
5000 03 Oct 18 olle 163       return;
5000 03 Oct 18 olle 164     }
5000 03 Oct 18 olle 165
5000 03 Oct 18 olle 166     frm.caseName.value = caseName;
5000 03 Oct 18 olle 167     Wizard.setInputStatus('caseName', 'valid');
5000 03 Oct 18 olle 168     caseIsValid = true;
5000 03 Oct 18 olle 169     
5000 03 Oct 18 olle 170     var url = '../BaseLineRegistration.servlet?ID='+App.getSessionId();
5000 03 Oct 18 olle 171     url += '&cmd=GetCaseInfo&caseName=' + encodeURIComponent(caseName);
5000 03 Oct 18 olle 172     Wizard.showLoadingAnimation('Loading information about case...');
5000 03 Oct 18 olle 173     Wizard.asyncJsonRequest(url, persinfo.onCaseInfoLoaded);
5000 03 Oct 18 olle 174   }
5000 03 Oct 18 olle 175
5000 03 Oct 18 olle 176   persinfo.onCaseInfoLoaded = function(response)
5000 03 Oct 18 olle 177   {
5000 03 Oct 18 olle 178     var frm = document.forms['meludi'];
5000 03 Oct 18 olle 179     
5000 03 Oct 18 olle 180     // Get biosource information from the AJAX response
5000 03 Oct 18 olle 181     caseInfo = response.caseInfo;
5000 03 Oct 18 olle 182
5000 03 Oct 18 olle 183 /*    
5000 03 Oct 18 olle 184     // If site determined by site prefix in case name, set site default value and disable site menu
5000 03 Oct 18 olle 185     //alert("persinfo.js:: persinfo.caseInfoLoaded: caseInfo.siteDefault = " + caseInfo.siteDefault);
5000 03 Oct 18 olle 186     if (caseInfo.siteDefault != null)
5000 03 Oct 18 olle 187     {
5000 03 Oct 18 olle 188       frm.site.value = caseInfo.siteDefault;
5000 03 Oct 18 olle 189       frm.site.disabled = true;
5000 03 Oct 18 olle 190     }
5000 03 Oct 18 olle 191
5000 03 Oct 18 olle 192     if (caseInfo && caseInfo.patient)
5000 03 Oct 18 olle 193     {
5000 03 Oct 18 olle 194       frm.personalNumber.value = caseInfo.patient.personalNumber;
5000 03 Oct 18 olle 195       persinfo.personalNumberOnChange();
5000 03 Oct 18 olle 196       Wizard.goNext(false);
5000 03 Oct 18 olle 197     }
5000 03 Oct 18 olle 198 */
5000 03 Oct 18 olle 199   }
5000 03 Oct 18 olle 200
5000 03 Oct 18 olle 201   persinfo.validateStep1 = function(event)
5000 03 Oct 18 olle 202   {
5000 03 Oct 18 olle 203     // Check that BASE-line CSV file has been selected
5000 03 Oct 18 olle 204     var frm = document.forms['meludi'];
5149 28 Nov 18 olle 205     //var file = frm.baseLineFile.files[0];
5149 28 Nov 18 olle 206     var file = frm.baseLineFile.value;
5000 03 Oct 18 olle 207     if (!file) 
5000 03 Oct 18 olle 208     {
5000 03 Oct 18 olle 209       Wizard.setInputStatus('baseLineFile', 'invalid', 'Missing');
5000 03 Oct 18 olle 210       frm.baseLineFile.focus();
5000 03 Oct 18 olle 211       event.preventDefault();
5000 03 Oct 18 olle 212     }
5000 03 Oct 18 olle 213   }
5000 03 Oct 18 olle 214
5000 03 Oct 18 olle 215   persinfo.initializeStep2a = function()
5000 03 Oct 18 olle 216   {
5000 03 Oct 18 olle 217     // Get referral ID/Case ID mapping
5000 03 Oct 18 olle 218     
5000 03 Oct 18 olle 219     var url = '../BaseLineRegistration.servlet?ID='+App.getSessionId();
5000 03 Oct 18 olle 220     url += '&cmd=GetReferralIdCaseIdMap';
5000 03 Oct 18 olle 221     Wizard.showLoadingAnimation('Loading information about cases...');
5000 03 Oct 18 olle 222     Wizard.asyncJsonRequest(url, persinfo.onCaseInfoLoaded);
5000 03 Oct 18 olle 223   }
5000 03 Oct 18 olle 224
5000 03 Oct 18 olle 225   persinfo.initializeStep2 = function()
5000 03 Oct 18 olle 226   {
5000 03 Oct 18 olle 227     persinfo.baseLineFileOnChange();
5000 03 Oct 18 olle 228
5000 03 Oct 18 olle 229     Doc.show('step-2');
5000 03 Oct 18 olle 230     Doc.show('gocancel');
5000 03 Oct 18 olle 231   }
5000 03 Oct 18 olle 232
5000 03 Oct 18 olle 233   persinfo.baseLineFileOnChange = function()
5000 03 Oct 18 olle 234   {
5000 03 Oct 18 olle 235     var frm = document.forms['meludi'];
5149 28 Nov 18 olle 236 /*
5149 28 Nov 18 olle 237     // For outside file, read in Javascript
5000 03 Oct 18 olle 238     var file = frm.baseLineFile.files[0];
5000 03 Oct 18 olle 239     
5000 03 Oct 18 olle 240     var reader = new FileReader();
5000 03 Oct 18 olle 241     reader.onload = persinfo.baseLineFileLoaded;
5000 03 Oct 18 olle 242     reader.readAsText(file);
5149 28 Nov 18 olle 243 */
5149 28 Nov 18 olle 244     // For file on BASE file system, contact server
5149 28 Nov 18 olle 245     var file = frm.baseLineFile.value;
5149 28 Nov 18 olle 246     var url = '../BaseLineRegistration.servlet?ID='+App.getSessionId();
5149 28 Nov 18 olle 247     url += '&cmd=ImportBaseLineFile';
5149 28 Nov 18 olle 248     url += '&csvPath='+file;
5149 28 Nov 18 olle 249     Wizard.showLoadingAnimation('Importing BASE-line file...');
5149 28 Nov 18 olle 250     Wizard.asyncJsonRequest(url, persinfo.parseBaseLineFile);
5000 03 Oct 18 olle 251   }
5000 03 Oct 18 olle 252
5000 03 Oct 18 olle 253   persinfo.baseLineFileLoaded = function(event)
5000 03 Oct 18 olle 254   {
5000 03 Oct 18 olle 255     persinfo.parseBaseLineFile(event.target.result);
5002 04 Oct 18 olle 256     if (problemFound)
5002 04 Oct 18 olle 257     {
5002 04 Oct 18 olle 258       event.preventDefault();
5002 04 Oct 18 olle 259     }
5002 04 Oct 18 olle 260     else
5002 04 Oct 18 olle 261     {
5002 04 Oct 18 olle 262       Doc.show('goregister');
5002 04 Oct 18 olle 263     }
5000 03 Oct 18 olle 264   }
5000 03 Oct 18 olle 265
5000 03 Oct 18 olle 266   persinfo.parseBaseLineFile = function(data)
5000 03 Oct 18 olle 267   {
5000 03 Oct 18 olle 268     //alert("baseline_from_file_alt_rec.js::parseBaseLineFile(data): Start");
5000 03 Oct 18 olle 269     var frm = document.forms['meludi'];
5000 03 Oct 18 olle 270     baseLineFileIsValid = false;
5000 03 Oct 18 olle 271
5326 05 Mar 19 olle 272 /*
5027 15 Oct 18 olle 273     var REFERRAL_ID_HEADER = 'Studielöpnummer';
5027 15 Oct 18 olle 274     var SAMPLING_DATE_HEADER = 'Provtagningsdatum';
5000 03 Oct 18 olle 275     var ARRIVAL_DATE_HEADER = 'Ankomstdatum';
5027 15 Oct 18 olle 276     var BLOOD_BOX_HEADER = 'Bankat helblod box';
5027 15 Oct 18 olle 277     var BLOOD_TUBE_1_POS_HEADER = 'Bankat helblod position rör b.1';
5027 15 Oct 18 olle 278     var BLOOD_TUBE_2_POS_HEADER = 'Bankat helblod position rör b.2';
5027 15 Oct 18 olle 279     var BLOOD_TUBE_3_POS_HEADER = 'Bankat helblod position rör b.3';
5027 15 Oct 18 olle 280     var COMMENT_HEADER = 'Kommentar';
5027 15 Oct 18 olle 281     var OPERATOR_HEADER = 'Namn';
5326 05 Mar 19 olle 282 */
5326 05 Mar 19 olle 283     // Use regular expressions to avoid problems with national characters
5326 05 Mar 19 olle 284     var REFERRAL_ID_HEADER = /Studiel.pnummer/;
5326 05 Mar 19 olle 285     var SAMPLING_DATE_HEADER = /Provtagningsdatum/;
5326 05 Mar 19 olle 286     var ARRIVAL_DATE_HEADER = /Ankomstdatum/;
5326 05 Mar 19 olle 287     var BLOOD_BOX_HEADER = /Bankat\shelblod\sbox/;
5326 05 Mar 19 olle 288     var BLOOD_TUBE_1_POS_HEADER = /Bankat\shelblod\sposition\sr.r\sb\.1/;
5326 05 Mar 19 olle 289     var BLOOD_TUBE_2_POS_HEADER = /Bankat\shelblod\sposition\sr.r\sb\.2/;
5326 05 Mar 19 olle 290     var BLOOD_TUBE_3_POS_HEADER = /Bankat\shelblod\sposition\sr.r\sb\.3/;
5326 05 Mar 19 olle 291     var COMMENT_HEADER = /Kommentar/;
5326 05 Mar 19 olle 292     var OPERATOR_HEADER = /Namn/;
5326 05 Mar 19 olle 293
5000 03 Oct 18 olle 294     //
5027 15 Oct 18 olle 295     var referralIdClmIndex = null;
5027 15 Oct 18 olle 296     var samplingDateClmIndex = null;
5027 15 Oct 18 olle 297     var arrivalDateClmIndex = null;
5027 15 Oct 18 olle 298     var bloodBoxClmIndex = null;
5027 15 Oct 18 olle 299     var bloodTube1PosClmIndex = null;
5027 15 Oct 18 olle 300     var bloodTube2PosClmIndex = null;
5027 15 Oct 18 olle 301     var bloodTube3PosClmIndex = null;
5027 15 Oct 18 olle 302     var commentClmIndex = null;
5027 15 Oct 18 olle 303     var operatorClmIndex = null;
5326 05 Mar 19 olle 304
5326 05 Mar 19 olle 305 /*
5027 15 Oct 18 olle 306     //
5312 20 Feb 19 olle 307     var referralIdClmIndex = 0;
5312 20 Feb 19 olle 308     var samplingDateClmIndex = 1;
5312 20 Feb 19 olle 309     var arrivalDateClmIndex = 2;
5312 20 Feb 19 olle 310     var bloodBoxClmIndex = 3;
5312 20 Feb 19 olle 311     var bloodTube1PosClmIndex = 4;
5312 20 Feb 19 olle 312     var bloodTube2PosClmIndex = 5;
5312 20 Feb 19 olle 313     var bloodTube3PosClmIndex = 6;
5312 20 Feb 19 olle 314     var commentClmIndex = 7;
5312 20 Feb 19 olle 315     var operatorClmIndex = 8;
5326 05 Mar 19 olle 316 */
5312 20 Feb 19 olle 317     //
5000 03 Oct 18 olle 318     var numReferralItems = 0;
5000 03 Oct 18 olle 319     var referralIdArr = [];
5027 15 Oct 18 olle 320     var samplingDateArr = [];
5000 03 Oct 18 olle 321     var arrivalDateArr = [];
5000 03 Oct 18 olle 322     var bloodTubeLabelArr = [];
5000 03 Oct 18 olle 323     var bloodItemIdArr = [];
5000 03 Oct 18 olle 324     var bloodItemBoxArr = [];
5000 03 Oct 18 olle 325     var bloodItemBoxPosArr = [];
5000 03 Oct 18 olle 326     var bloodItemBoxRowArr = [];
5000 03 Oct 18 olle 327     var bloodItemBoxClmArr = [];
5027 15 Oct 18 olle 328     var commentArr = [];
5027 15 Oct 18 olle 329     var operatorArr = [];
5000 03 Oct 18 olle 330
5313 27 Feb 19 olle 331     // Find column separator as first character of comma, semicolon, or tab
5313 27 Feb 19 olle 332     var separator = ExtractUtils.findSeparatorFromJSONArray(data, "baseLineData");
5313 27 Feb 19 olle 333 //alert("baseline_from_file_alt_rec.js::parseBaseLineFile(): separator = '" + separator + "'.");
5313 27 Feb 19 olle 334     if (separator == null)
5313 27 Feb 19 olle 335     {
5313 27 Feb 19 olle 336       // Tab is default separator
5313 27 Feb 19 olle 337       separator = "\\t"
5313 27 Feb 19 olle 338     }
5149 28 Nov 18 olle 339 /*
5000 03 Oct 18 olle 340     // Find column separator as first character after first occurrence of search string
5027 15 Oct 18 olle 341     var separator = ExtractUtils.findSeparator(data, REFERRAL_ID_HEADER);
5000 03 Oct 18 olle 342     if (separator == null)
5000 03 Oct 18 olle 343     {
5000 03 Oct 18 olle 344       // Comma is default separator
5000 03 Oct 18 olle 345       separator = ',';
5000 03 Oct 18 olle 346     }
5149 28 Nov 18 olle 347 */
5313 27 Feb 19 olle 348 /*
5149 28 Nov 18 olle 349     // Tab is default separator
5149 28 Nov 18 olle 350     var separator = "\\t"
5313 27 Feb 19 olle 351 */
5313 27 Feb 19 olle 352
5000 03 Oct 18 olle 353     var columnSplitRegexp = new RegExp(" *" + separator + " *",'');
5027 15 Oct 18 olle 354
5027 15 Oct 18 olle 355     // Get array of lines
5149 28 Nov 18 olle 356     //var lines = data.split(/[\n\r]+/);
5149 28 Nov 18 olle 357     // When file is on BASE file system, data is response from servlet
5149 28 Nov 18 olle 358     var lines = data.baseLineData;
5312 20 Feb 19 olle 359
5312 20 Feb 19 olle 360 /*    
5027 15 Oct 18 olle 361     // Find column indices for columns of interest from column header names
5027 15 Oct 18 olle 362     // This allows column values in a line to be read in any order
5027 15 Oct 18 olle 363
5027 15 Oct 18 olle 364     // Get array of column headers from first line
5000 03 Oct 18 olle 365     var columns = lines[0].split(columnSplitRegexp);
5027 15 Oct 18 olle 366     for (var j = 0; j < columns.length; j++)
5027 15 Oct 18 olle 367     {
5027 15 Oct 18 olle 368       // Referral ID
5027 15 Oct 18 olle 369       if (columns[j] == REFERRAL_ID_HEADER)
5027 15 Oct 18 olle 370       {
5027 15 Oct 18 olle 371         referralIdClmIndex = j;
5027 15 Oct 18 olle 372       }
5000 03 Oct 18 olle 373
5027 15 Oct 18 olle 374       // Sampling date
5027 15 Oct 18 olle 375       if (columns[j] == SAMPLING_DATE_HEADER)
5027 15 Oct 18 olle 376       {
5027 15 Oct 18 olle 377         samplingDateClmIndex = j;
5027 15 Oct 18 olle 378       }
5027 15 Oct 18 olle 379
5027 15 Oct 18 olle 380       // Arrival date
5027 15 Oct 18 olle 381       if (columns[j] == ARRIVAL_DATE_HEADER)
5027 15 Oct 18 olle 382       {
5027 15 Oct 18 olle 383         arrivalDateClmIndex = j;
5027 15 Oct 18 olle 384       }
5027 15 Oct 18 olle 385       
5027 15 Oct 18 olle 386       // Box name
5027 15 Oct 18 olle 387       if (columns[j] == BLOOD_BOX_HEADER)
5027 15 Oct 18 olle 388       {
5027 15 Oct 18 olle 389         bloodBoxClmIndex = j;
5027 15 Oct 18 olle 390       }
5027 15 Oct 18 olle 391
5027 15 Oct 18 olle 392       // Blood item 1 tube box position
5027 15 Oct 18 olle 393       if (columns[j] == BLOOD_TUBE_1_POS_HEADER)
5027 15 Oct 18 olle 394       {
5027 15 Oct 18 olle 395         bloodTube1PosClmIndex = j;
5027 15 Oct 18 olle 396       }
5027 15 Oct 18 olle 397
5027 15 Oct 18 olle 398       // Blood item 2 tube box position
5027 15 Oct 18 olle 399       if (columns[j] == BLOOD_TUBE_2_POS_HEADER)
5027 15 Oct 18 olle 400       {
5027 15 Oct 18 olle 401         bloodTube2PosClmIndex = j;
5027 15 Oct 18 olle 402       }
5027 15 Oct 18 olle 403
5027 15 Oct 18 olle 404       // Blood item 3 tube box position
5027 15 Oct 18 olle 405       if (columns[j] == BLOOD_TUBE_3_POS_HEADER)
5027 15 Oct 18 olle 406       {
5027 15 Oct 18 olle 407         bloodTube3PosClmIndex = j;
5027 15 Oct 18 olle 408       }
5027 15 Oct 18 olle 409
5027 15 Oct 18 olle 410       // Comment
5027 15 Oct 18 olle 411       if (columns[j] == COMMENT_HEADER)
5027 15 Oct 18 olle 412       {
5027 15 Oct 18 olle 413         commentClmIndex = j;
5027 15 Oct 18 olle 414       }
5027 15 Oct 18 olle 415
5027 15 Oct 18 olle 416       // Operator
5027 15 Oct 18 olle 417       if (columns[j] == OPERATOR_HEADER)
5027 15 Oct 18 olle 418       {
5027 15 Oct 18 olle 419         operatorClmIndex = j;
5027 15 Oct 18 olle 420       }
5027 15 Oct 18 olle 421     }
5312 20 Feb 19 olle 422 */
5326 05 Mar 19 olle 423     // Find column indices for columns of interest from column header names
5326 05 Mar 19 olle 424     // This allows column values in a line to be read in any order
5027 15 Oct 18 olle 425
5326 05 Mar 19 olle 426     // Get array of column headers from first line
5326 05 Mar 19 olle 427     var columns = lines[0].split(columnSplitRegexp);
5326 05 Mar 19 olle 428     for (var j = 0; j < columns.length; j++)
5326 05 Mar 19 olle 429     {
5326 05 Mar 19 olle 430       // Referral ID
5326 05 Mar 19 olle 431       if (REFERRAL_ID_HEADER.test(columns[j]))
5326 05 Mar 19 olle 432       {
5326 05 Mar 19 olle 433         referralIdClmIndex = j;
5326 05 Mar 19 olle 434       }
5326 05 Mar 19 olle 435
5326 05 Mar 19 olle 436       // Sampling date
5326 05 Mar 19 olle 437       if (SAMPLING_DATE_HEADER.test(columns[j]))
5326 05 Mar 19 olle 438       {
5326 05 Mar 19 olle 439         samplingDateClmIndex = j;
5326 05 Mar 19 olle 440       }
5326 05 Mar 19 olle 441
5326 05 Mar 19 olle 442       // Arrival date
5326 05 Mar 19 olle 443       if (ARRIVAL_DATE_HEADER.test(columns[j]))
5326 05 Mar 19 olle 444       {
5326 05 Mar 19 olle 445         arrivalDateClmIndex = j;
5326 05 Mar 19 olle 446       }
5326 05 Mar 19 olle 447       
5326 05 Mar 19 olle 448       // Box name
5326 05 Mar 19 olle 449       if (BLOOD_BOX_HEADER.test(columns[j]))
5326 05 Mar 19 olle 450       {
5326 05 Mar 19 olle 451         bloodBoxClmIndex = j;
5326 05 Mar 19 olle 452       }
5326 05 Mar 19 olle 453
5326 05 Mar 19 olle 454       // Blood item 1 tube box position
5326 05 Mar 19 olle 455       if (BLOOD_TUBE_1_POS_HEADER.test(columns[j]))
5326 05 Mar 19 olle 456       {
5326 05 Mar 19 olle 457         bloodTube1PosClmIndex = j;
5326 05 Mar 19 olle 458       }
5326 05 Mar 19 olle 459
5326 05 Mar 19 olle 460       // Blood item 2 tube box position
5326 05 Mar 19 olle 461       if (BLOOD_TUBE_2_POS_HEADER.test(columns[j]))
5326 05 Mar 19 olle 462       {
5326 05 Mar 19 olle 463         bloodTube2PosClmIndex = j;
5326 05 Mar 19 olle 464       }
5326 05 Mar 19 olle 465
5326 05 Mar 19 olle 466       // Blood item 3 tube box position
5326 05 Mar 19 olle 467       if (BLOOD_TUBE_3_POS_HEADER.test(columns[j]))
5326 05 Mar 19 olle 468       {
5326 05 Mar 19 olle 469         bloodTube3PosClmIndex = j;
5326 05 Mar 19 olle 470       }
5326 05 Mar 19 olle 471
5326 05 Mar 19 olle 472       // Comment
5326 05 Mar 19 olle 473       if (COMMENT_HEADER.test(columns[j]))
5326 05 Mar 19 olle 474       {
5326 05 Mar 19 olle 475         commentClmIndex = j;
5326 05 Mar 19 olle 476       }
5326 05 Mar 19 olle 477
5326 05 Mar 19 olle 478       // Operator
5326 05 Mar 19 olle 479       if (OPERATOR_HEADER.test(columns[j]))
5326 05 Mar 19 olle 480       {
5326 05 Mar 19 olle 481         operatorClmIndex = j;
5326 05 Mar 19 olle 482       }
5326 05 Mar 19 olle 483     }
5326 05 Mar 19 olle 484
5000 03 Oct 18 olle 485     var numImported = 0;
5000 03 Oct 18 olle 486     var tubeNo = -1;
5027 15 Oct 18 olle 487
5027 15 Oct 18 olle 488     // Process lines in file, skipping first header line
5000 03 Oct 18 olle 489     for (var i = 1; i < lines.length; i++)
5000 03 Oct 18 olle 490     {
5000 03 Oct 18 olle 491       // Ignore empty lines
5000 03 Oct 18 olle 492       if (lines[i].match(/^\s*$/)) continue;
5027 15 Oct 18 olle 493       
5027 15 Oct 18 olle 494       // Get array of columns values in line
5000 03 Oct 18 olle 495       var row = lines[i].split(columnSplitRegexp);
5000 03 Oct 18 olle 496
5027 15 Oct 18 olle 497       // Get values in selected columns
5027 15 Oct 18 olle 498       var referralId = row[referralIdClmIndex];
5027 15 Oct 18 olle 499       var samplingDate = row[samplingDateClmIndex];
5027 15 Oct 18 olle 500       var arrivalDate = row[arrivalDateClmIndex];
5027 15 Oct 18 olle 501       var bloodBox = row[bloodBoxClmIndex];
5027 15 Oct 18 olle 502       var tube1Pos = row[bloodTube1PosClmIndex];
5027 15 Oct 18 olle 503       var tube2Pos = row[bloodTube2PosClmIndex];
5027 15 Oct 18 olle 504       var tube3Pos = row[bloodTube3PosClmIndex];
5027 15 Oct 18 olle 505       var comment = row[commentClmIndex];
5027 15 Oct 18 olle 506       var operator = row[operatorClmIndex];
5027 15 Oct 18 olle 507
5027 15 Oct 18 olle 508       // Create a new blood tube item where a blood tube box position is specified
5027 15 Oct 18 olle 509       if (tube1Pos)
5000 03 Oct 18 olle 510       {
5027 15 Oct 18 olle 511         var tubeLabel = referralId + ".b1";
5027 15 Oct 18 olle 512         var position = tube1Pos;
5027 15 Oct 18 olle 513         //
5027 15 Oct 18 olle 514         tubeNo = tubeNo + 1;
5027 15 Oct 18 olle 515         bloodTubeLabelArr[tubeNo] = tubeLabel;
5027 15 Oct 18 olle 516         referralIdArr[tubeNo] = referralId;
5027 15 Oct 18 olle 517         samplingDateArr[tubeNo] = samplingDate;
5027 15 Oct 18 olle 518         arrivalDateArr[tubeNo] = arrivalDate;
5027 15 Oct 18 olle 519         bloodItemBoxArr[tubeNo] = bloodBox;
5027 15 Oct 18 olle 520         bloodItemBoxPosArr[tubeNo] = position;
5027 15 Oct 18 olle 521         bloodItemBoxRowArr[tubeNo] = position.substring(0, 1);
5027 15 Oct 18 olle 522         bloodItemBoxClmArr[tubeNo] = position.substring(1);
5027 15 Oct 18 olle 523         commentArr[tubeNo] = comment;
5027 15 Oct 18 olle 524         operatorArr[tubeNo] = operator;
5027 15 Oct 18 olle 525       }
5000 03 Oct 18 olle 526
5027 15 Oct 18 olle 527       if (tube2Pos)
5027 15 Oct 18 olle 528       {
5027 15 Oct 18 olle 529         var tubeLabel = referralId + ".b2";
5027 15 Oct 18 olle 530         var position = tube2Pos;
5027 15 Oct 18 olle 531         //
5027 15 Oct 18 olle 532         tubeNo = tubeNo + 1;
5027 15 Oct 18 olle 533         bloodTubeLabelArr[tubeNo] = tubeLabel;
5027 15 Oct 18 olle 534         referralIdArr[tubeNo] = referralId;
5027 15 Oct 18 olle 535         samplingDateArr[tubeNo] = samplingDate;
5027 15 Oct 18 olle 536         arrivalDateArr[tubeNo] = arrivalDate;
5027 15 Oct 18 olle 537         bloodItemBoxArr[tubeNo] = bloodBox;
5027 15 Oct 18 olle 538         bloodItemBoxPosArr[tubeNo] = position;
5027 15 Oct 18 olle 539         bloodItemBoxRowArr[tubeNo] = position.substring(0, 1);
5027 15 Oct 18 olle 540         bloodItemBoxClmArr[tubeNo] = position.substring(1);
5027 15 Oct 18 olle 541         commentArr[tubeNo] = comment;
5027 15 Oct 18 olle 542         operatorArr[tubeNo] = operator;
5027 15 Oct 18 olle 543       }
5000 03 Oct 18 olle 544
5027 15 Oct 18 olle 545       if (tube3Pos)
5027 15 Oct 18 olle 546       {
5027 15 Oct 18 olle 547         var tubeLabel = referralId + ".b3";
5027 15 Oct 18 olle 548         var position = tube3Pos;
5027 15 Oct 18 olle 549         //
5027 15 Oct 18 olle 550         tubeNo = tubeNo + 1;
5027 15 Oct 18 olle 551         bloodTubeLabelArr[tubeNo] = tubeLabel;
5027 15 Oct 18 olle 552         referralIdArr[tubeNo] = referralId;
5027 15 Oct 18 olle 553         samplingDateArr[tubeNo] = samplingDate;
5027 15 Oct 18 olle 554         arrivalDateArr[tubeNo] = arrivalDate;
5027 15 Oct 18 olle 555         bloodItemBoxArr[tubeNo] = bloodBox;
5027 15 Oct 18 olle 556         bloodItemBoxPosArr[tubeNo] = position;
5027 15 Oct 18 olle 557         bloodItemBoxRowArr[tubeNo] = position.substring(0, 1);
5027 15 Oct 18 olle 558         bloodItemBoxClmArr[tubeNo] = position.substring(1);
5027 15 Oct 18 olle 559         commentArr[tubeNo] = comment;
5027 15 Oct 18 olle 560         operatorArr[tubeNo] = operator;
5000 03 Oct 18 olle 561       }
5016 09 Oct 18 olle 562       //alert("baseline_from_file_alt_rec.js::parseBaseLineFile(data): line = " + i + " referralId = " + referralIdArr[i] + " arrival date = " + arrivalDateArr[i] + " box 1 = " + bloodItem1BoxArr[i] + " row 1 = " + bloodItem1BoxRowArr[i] + " clm 1 = " + bloodItem1BoxClmArr[i] + " box 2 = " + bloodItem2BoxArr[i] + " row 2 = " + bloodItem2BoxRowArr[i] + " clm 2 = " + bloodItem2BoxClmArr[i]);
5000 03 Oct 18 olle 563     }
5000 03 Oct 18 olle 564     //alert("baseline_from_file_alt_rec.js::parseBaseLineFile(data): tubeNo = " + tubeNo);
5000 03 Oct 18 olle 565
5000 03 Oct 18 olle 566     Wizard.setInputStatus('baseLineFile', 'valid');
5000 03 Oct 18 olle 567     baseLineFileIsValid = true;
5000 03 Oct 18 olle 568
5000 03 Oct 18 olle 569     var html = '';
5000 03 Oct 18 olle 570     nofBloodTubes = tubeNo + 1;
5000 03 Oct 18 olle 571     var tubeContentType = 'Blood';
5002 04 Oct 18 olle 572     problemFound = false;
5000 03 Oct 18 olle 573     
5000 03 Oct 18 olle 574     for (var i=0; i <= tubeNo; i++)
5000 03 Oct 18 olle 575     {
5027 15 Oct 18 olle 576       // Check if necessary blood tube data entered
5002 04 Oct 18 olle 577       var problemFoundForTube = false;
5027 15 Oct 18 olle 578       // Check that box name entered
5027 15 Oct 18 olle 579       if (referralIdArr[i] == "" || bloodItemBoxArr[i] == "")
5002 04 Oct 18 olle 580       {
5002 04 Oct 18 olle 581         problemFoundForTube = true;
5002 04 Oct 18 olle 582         problemFound = true;
5002 04 Oct 18 olle 583       }
5000 03 Oct 18 olle 584       var tubeContentTypeName = 'Blood';
5000 03 Oct 18 olle 585       var tubeContentTypeNameInternal = persinfo.fetchTubeContentTypeNameInternal(tubeContentType, tubeContentTypeName);
5000 03 Oct 18 olle 586       var tubeName = bloodTubeLabelArr[i];
5000 03 Oct 18 olle 587       //var tubeIdentifier = persinfo.fetchTubeIdentifier(tubeContentType, caseInfo, i);
5149 28 Nov 18 olle 588       var boxMsg = 'Box-number and position where blood tube #' + (i+1) + ' is placed.';
5027 15 Oct 18 olle 589       if (referralIdArr[i] == "")
5002 04 Oct 18 olle 590       {
5027 15 Oct 18 olle 591         boxMsg = 'Referral ID missing for blood tube #' + (i+1) + '!';
5027 15 Oct 18 olle 592         if (bloodItemBoxArr[i] == "")
5027 15 Oct 18 olle 593         {
5027 15 Oct 18 olle 594           boxMsg = 'Referral ID and box name missing for blood tube #' + (i+1) + '!';
5027 15 Oct 18 olle 595         }
5002 04 Oct 18 olle 596       }
5027 15 Oct 18 olle 597       else if (bloodItemBoxArr[i] == "")
5027 15 Oct 18 olle 598       {
5027 15 Oct 18 olle 599         boxMsg = 'Box name missing for blood tube #' + (i+1) + '!';
5027 15 Oct 18 olle 600       }
5159 30 Nov 18 olle 601       var disabledAttribute = 'disabled';
5000 03 Oct 18 olle 602       html += '<tr>';
5000 03 Oct 18 olle 603       //html += '<td class="subprompt">Blood Tube label&nbsp;'+tubeName+'&nbsp;&nbsp;&nbsp;'+'Box</td>';
5000 03 Oct 18 olle 604       //html += '<td class="subprompt">Label&nbsp;'+tubeName+'&nbsp;&nbsp;&nbsp;'+'Box</td>';
5000 03 Oct 18 olle 605       html += '<td class="input">';
5000 03 Oct 18 olle 606       html += 'Label&nbsp;<input type="text" name="tubeLabel.'+i+'" id="tubeLabel.'+i+'" style="width: 8em;" maxlength="13"'+disabledAttribute+'>';
5000 03 Oct 18 olle 607       html += '&nbsp;&nbsp;&nbsp;'+'Box&nbsp;<input type="text" name="box.'+i+'" id="box.'+i+'" style="width: 6em;" maxlength="10"'+disabledAttribute+'>';
5000 03 Oct 18 olle 608       html += '&nbsp;&nbsp;Row&nbsp;<input type="text" name="row.'+i+'" id="row.'+i+'" style="text-transform:uppercase; width: 1em;" maxlength="1"'+disabledAttribute+'>';
5000 03 Oct 18 olle 609       //html += '&nbsp;&nbsp;Column&nbsp;<input type="text" name="column.'+i+'" id="column.'+i+'" style="width: 1.5em;" maxlength="2"'+disabledAttribute+'>';
5000 03 Oct 18 olle 610       html += '&nbsp;&nbsp;Col&nbsp;<input type="text" name="column.'+i+'" id="column.'+i+'" style="width: 1.5em;" maxlength="2"'+disabledAttribute+'>';
5027 15 Oct 18 olle 611       html += '&nbsp;&nbsp;Sampling date&nbsp;<input type="text" name="samplingDate.'+i+'" id="samplingDate.'+i+'" style="width: 6em;" maxlength="10"'+disabledAttribute+'>';
5000 03 Oct 18 olle 612       html += '&nbsp;&nbsp;Arrival date&nbsp;<input type="text" name="arrivalDate.'+i+'" id="arrivalDate.'+i+'" style="width: 6em;" maxlength="10"'+disabledAttribute+'>';
5027 15 Oct 18 olle 613       html += '<input type="hidden" name="comment.'+i+'" id="comment.'+i+'" style="width: 6em;" maxlength="10"'+disabledAttribute+'>';
5027 15 Oct 18 olle 614       html += '<input type="hidden" name="operator.'+i+'" id="operator.'+i+'" style="width: 6em;" maxlength="10"'+disabledAttribute+'>';
5000 03 Oct 18 olle 615       html += '</td>';
5000 03 Oct 18 olle 616       html += '<td class="status" id="box.'+i+'.status"></td>';
5002 04 Oct 18 olle 617       if (!problemFoundForTube)
5002 04 Oct 18 olle 618       {
5002 04 Oct 18 olle 619         html += '<td class="help"><span id="box.'+i+'.message" class="message"></span>'+boxMsg+'<span id="position.'+i+'.message" class="message"></span></td>';
5002 04 Oct 18 olle 620       }
5002 04 Oct 18 olle 621       else
5002 04 Oct 18 olle 622       {
5002 04 Oct 18 olle 623         html += '<td class="help"><span id="box.'+i+'.message" class="fail-info"></span>' + boxMsg + '&nbsp;' + '<img src="../images/error.png"><span id="position.'+i+'.message" class="message"></span></td>';
5002 04 Oct 18 olle 624       }
5000 03 Oct 18 olle 625       html += '</tr>';
5000 03 Oct 18 olle 626     }
5000 03 Oct 18 olle 627     Doc.element('blood-tubes').innerHTML = html;
5000 03 Oct 18 olle 628
5000 03 Oct 18 olle 629     // Enter read input data
5000 03 Oct 18 olle 630     for (var i=0; i <= tubeNo; i++)
5000 03 Oct 18 olle 631     {
5000 03 Oct 18 olle 632       frm['tubeLabel.'+i].value = bloodTubeLabelArr[i];
5027 15 Oct 18 olle 633       frm['samplingDate.'+i].value = samplingDateArr[i];
5027 15 Oct 18 olle 634       frm['arrivalDate.'+i].value = arrivalDateArr[i];
5000 03 Oct 18 olle 635       frm['box.'+i].value = bloodItemBoxArr[i];
5000 03 Oct 18 olle 636       frm['row.'+i].value = bloodItemBoxRowArr[i];
5000 03 Oct 18 olle 637       frm['column.'+i].value = bloodItemBoxClmArr[i];
5027 15 Oct 18 olle 638       frm['comment.'+i].value = commentArr[i];
5027 15 Oct 18 olle 639       frm['operator.'+i].value = operatorArr[i];
5000 03 Oct 18 olle 640     }
5149 28 Nov 18 olle 641     Doc.show('goregister');
5000 03 Oct 18 olle 642   }
5000 03 Oct 18 olle 643
5000 03 Oct 18 olle 644   persinfo.nofTubesOnChange = function()
5000 03 Oct 18 olle 645   {
5000 03 Oct 18 olle 646     nofTubesIsValid = false;
5000 03 Oct 18 olle 647
5000 03 Oct 18 olle 648     var frm = document.forms['meludi'];
5000 03 Oct 18 olle 649     var nofTubes = frm.nofTubes.value;
5000 03 Oct 18 olle 650     
5000 03 Oct 18 olle 651     if (nofTubes == '')
5000 03 Oct 18 olle 652     {
5000 03 Oct 18 olle 653       Wizard.setInputStatus('nofTubes', 'invalid', 'Missing');
5000 03 Oct 18 olle 654       return;
5000 03 Oct 18 olle 655     }
5000 03 Oct 18 olle 656     if (parseInt(nofTubes) < 1)
5000 03 Oct 18 olle 657     {
5000 03 Oct 18 olle 658       Wizard.setInputStatus('nofTubes', 'invalid', 'Must be at least 1');
5000 03 Oct 18 olle 659       return;    
5000 03 Oct 18 olle 660     }
5000 03 Oct 18 olle 661     Wizard.setInputStatus('nofTubes', 'valid');
5000 03 Oct 18 olle 662     nofTubesIsValid = true; 
5000 03 Oct 18 olle 663   }
5000 03 Oct 18 olle 664
5000 03 Oct 18 olle 665   persinfo.validateStep2 = function(event)
5000 03 Oct 18 olle 666   {
5000 03 Oct 18 olle 667     var isValid = bloodSamplingDateIsValid;
5000 03 Oct 18 olle 668     var hasSpecimen = caseInfo.specimen && caseInfo.specimen.length > 0;
5000 03 Oct 18 olle 669     if (hasSpecimen)
5000 03 Oct 18 olle 670     {
5000 03 Oct 18 olle 671       isValid &= viableTumourCellsPercentIsValid;
5000 03 Oct 18 olle 672     }
5000 03 Oct 18 olle 673     if (!isValid) event.preventDefault();
5000 03 Oct 18 olle 674   }
5000 03 Oct 18 olle 675
5000 03 Oct 18 olle 676   persinfo.fetchTubeContentTypeName = function(tubeContentType, tubeIndex)
5000 03 Oct 18 olle 677   {
5000 03 Oct 18 olle 678     var tubeContentTypeName = tubeContentType;
5000 03 Oct 18 olle 679     if (tubeContentType == 'DNA_RNA')
5000 03 Oct 18 olle 680     {
5000 03 Oct 18 olle 681       if (tubeIndex == 0)
5000 03 Oct 18 olle 682       {
5000 03 Oct 18 olle 683         tubeContentTypeName = 'DNA';
5000 03 Oct 18 olle 684       }
5000 03 Oct 18 olle 685       else if (tubeIndex == 1)
5000 03 Oct 18 olle 686       {
5000 03 Oct 18 olle 687         tubeContentTypeName = 'RNA';
5000 03 Oct 18 olle 688       }
5000 03 Oct 18 olle 689     }
5000 03 Oct 18 olle 690     return tubeContentTypeName;
5000 03 Oct 18 olle 691   }
5000 03 Oct 18 olle 692   
5000 03 Oct 18 olle 693   persinfo.fetchTubeContentTypeNameInternal = function(tubeContentType, tubeContentTypeName)
5000 03 Oct 18 olle 694   {
5000 03 Oct 18 olle 695     var tubeContentTypeNameInternal = tubeContentTypeName;
5000 03 Oct 18 olle 696     // Convert all names except abbreviations to all lower case
5000 03 Oct 18 olle 697     if (tubeContentType == 'Specimen')
5000 03 Oct 18 olle 698     {
5000 03 Oct 18 olle 699       tubeContentTypeNameInternal = tubeContentTypeName.toLowerCase();
5000 03 Oct 18 olle 700     }
5000 03 Oct 18 olle 701     return tubeContentTypeNameInternal;
5000 03 Oct 18 olle 702   }
5000 03 Oct 18 olle 703   
5000 03 Oct 18 olle 704   persinfo.fetchTubeName = function(tubeContentType, caseInfo, tubeIndex)
5000 03 Oct 18 olle 705   {
5000 03 Oct 18 olle 706     var tubeName = Strings.encodeTags(caseInfo.originalName);
5000 03 Oct 18 olle 707     if (tubeContentType == 'Blood')
5000 03 Oct 18 olle 708     {
5000 03 Oct 18 olle 709       // Exchange sample item prefix for blood item prefix
5000 03 Oct 18 olle 710       if (tubeName.startsWith(sampleItemPrefix))
5000 03 Oct 18 olle 711       {
5000 03 Oct 18 olle 712         //var tubeNameDigits = tubeName.substring(sampleItemPrefix.length);
5000 03 Oct 18 olle 713         tubeNameDigits = caseInfo.highestBloodItemNumber + (tubeIndex + 1);
5000 03 Oct 18 olle 714         tubeNameDigits = '0000000000000' + tubeNameDigits;
5000 03 Oct 18 olle 715         tubeNameDigits = tubeNameDigits.substring(tubeNameDigits.length - bloodItemNumDigits);
5000 03 Oct 18 olle 716         tubeName = bloodItemPrefix + tubeNameDigits;
5000 03 Oct 18 olle 717       }
5000 03 Oct 18 olle 718
5000 03 Oct 18 olle 719       // Add suffix
5000 03 Oct 18 olle 720       if (bloodItemPrefix == sampleItemPrefix)
5000 03 Oct 18 olle 721       {
5000 03 Oct 18 olle 722         tubeName = tubeName+'.b';
5000 03 Oct 18 olle 723         if (tubeIndex > 0)
5000 03 Oct 18 olle 724         {
5000 03 Oct 18 olle 725           tubeName = tubeName + (tubeIndex + 1);
5000 03 Oct 18 olle 726         }
5000 03 Oct 18 olle 727       }
5000 03 Oct 18 olle 728     }
5000 03 Oct 18 olle 729     else if (tubeContentType == 'Specimen')
5000 03 Oct 18 olle 730     {
5000 03 Oct 18 olle 731       var tubeNo = tubeIndex + caseInfo.specimenFirstIndex;
5000 03 Oct 18 olle 732       tubeName = tubeName+'.'+tubeNo;
5000 03 Oct 18 olle 733     }
5000 03 Oct 18 olle 734     else if (tubeContentType == 'DNA')
5000 03 Oct 18 olle 735     {
5000 03 Oct 18 olle 736       tubeName = tubeName+'.d';
5000 03 Oct 18 olle 737     }
5000 03 Oct 18 olle 738     else if (tubeContentType == 'RNA')
5000 03 Oct 18 olle 739     {
5000 03 Oct 18 olle 740       tubeName = tubeName+'.r';
5000 03 Oct 18 olle 741     }
5000 03 Oct 18 olle 742     else if (tubeContentType == 'DNA_RNA')
5000 03 Oct 18 olle 743     {
5000 03 Oct 18 olle 744       if (tubeIndex == 0)
5000 03 Oct 18 olle 745       {
5000 03 Oct 18 olle 746         tubeName = tubeName+'.d';
5000 03 Oct 18 olle 747       }
5000 03 Oct 18 olle 748       else if (tubeIndex == 1)
5000 03 Oct 18 olle 749       {
5000 03 Oct 18 olle 750         tubeName = tubeName+'.r';
5000 03 Oct 18 olle 751       }
5000 03 Oct 18 olle 752     }
5000 03 Oct 18 olle 753     return tubeName;
5000 03 Oct 18 olle 754   }
5000 03 Oct 18 olle 755   
5000 03 Oct 18 olle 756   persinfo.fetchTubeIdentifier = function(tubeContentType, tubeName, tubeNo)
5000 03 Oct 18 olle 757   {
5000 03 Oct 18 olle 758     var tubeIdentifier = tubeName;
5000 03 Oct 18 olle 759     if (tubeContentType == 'Specimen')
5000 03 Oct 18 olle 760     {
5000 03 Oct 18 olle 761       tubeIdentifier = tubeNo;
5000 03 Oct 18 olle 762     }
5000 03 Oct 18 olle 763     return tubeIdentifier;
5000 03 Oct 18 olle 764   }
5000 03 Oct 18 olle 765   
5000 03 Oct 18 olle 766   persinfo.boxOnKeyUp = function(event)
5000 03 Oct 18 olle 767   {
5000 03 Oct 18 olle 768     var frm = document.forms['meludi'];
5000 03 Oct 18 olle 769     var tubeContentType = frm.tubeContentType.value;
5000 03 Oct 18 olle 770     
5000 03 Oct 18 olle 771     var boxType = Data.get(event.currentTarget, 'boxtype');
5000 03 Oct 18 olle 772     var index = Data.int(event.currentTarget, 'index');
5000 03 Oct 18 olle 773
5000 03 Oct 18 olle 774     // Get box prefix, default is for input tubes
5000 03 Oct 18 olle 775     var boxPrefix = 'box.';
5000 03 Oct 18 olle 776     if (boxType && boxType == 'DNA')
5000 03 Oct 18 olle 777     {
5000 03 Oct 18 olle 778       boxPrefix = 'dnaBox.';
5000 03 Oct 18 olle 779     }
5000 03 Oct 18 olle 780     if (boxType && boxType == 'RNA')
5000 03 Oct 18 olle 781     {
5000 03 Oct 18 olle 782       boxPrefix = 'rnaBox.';
5000 03 Oct 18 olle 783     }
5000 03 Oct 18 olle 784
5000 03 Oct 18 olle 785     // Check box name
5000 03 Oct 18 olle 786     var boxIsValid = true;
5000 03 Oct 18 olle 787     var box = frm[boxPrefix+index].value;
5000 03 Oct 18 olle 788     Wizard.setInputStatus(boxPrefix+index);
5000 03 Oct 18 olle 789     // Check for prefix "ML_"
5000 03 Oct 18 olle 790     if (box.indexOf('ML_') != 0)
5000 03 Oct 18 olle 791     {
5000 03 Oct 18 olle 792       boxIsValid = false;
5000 03 Oct 18 olle 793     }
5000 03 Oct 18 olle 794     var suffix = '_sp';
5000 03 Oct 18 olle 795     if (tubeContentType == 'DNA' || (boxType && boxType == 'DNA'))
5000 03 Oct 18 olle 796     {
5000 03 Oct 18 olle 797       suffix = '_dna';
5000 03 Oct 18 olle 798     }
5000 03 Oct 18 olle 799     else if (tubeContentType == 'RNA' || (boxType && boxType == 'RNA'))
5000 03 Oct 18 olle 800     {
5000 03 Oct 18 olle 801       suffix = '_rna';
5000 03 Oct 18 olle 802     }
5000 03 Oct 18 olle 803     // Check for suffix
5000 03 Oct 18 olle 804     if (box.indexOf(suffix) != (box.length - suffix.length))
5000 03 Oct 18 olle 805     {
5000 03 Oct 18 olle 806       boxIsValid = false;
5000 03 Oct 18 olle 807     }
5000 03 Oct 18 olle 808     
5000 03 Oct 18 olle 809     if (!boxIsValid)
5000 03 Oct 18 olle 810     {
5000 03 Oct 18 olle 811       Wizard.setInputStatus(boxPrefix+index, 'invalid', 'Box name must start with "ML_" and end with "'+suffix+'"');
5000 03 Oct 18 olle 812       return;
5000 03 Oct 18 olle 813     }
5000 03 Oct 18 olle 814   }
5000 03 Oct 18 olle 815   
5000 03 Oct 18 olle 816   persinfo.wellOnChange = function(event)
5000 03 Oct 18 olle 817   {
5000 03 Oct 18 olle 818     var frm = document.forms['meludi'];
5000 03 Oct 18 olle 819     var target = event.currentTarget;
5000 03 Oct 18 olle 820
5000 03 Oct 18 olle 821     var boxType = Data.get(target, 'boxtype');
5000 03 Oct 18 olle 822     var index = Data.int(target, 'index');
5000 03 Oct 18 olle 823
5000 03 Oct 18 olle 824     // Get well position prefixes, default is for input tubes
5000 03 Oct 18 olle 825     var boxPrefix = 'box.';
5000 03 Oct 18 olle 826     var rowPrefix = 'row.';
5000 03 Oct 18 olle 827     var columnPrefix = 'column.';
5000 03 Oct 18 olle 828     if (boxType && boxType == 'DNA')
5000 03 Oct 18 olle 829     {
5000 03 Oct 18 olle 830       boxPrefix = 'dnaBox.';
5000 03 Oct 18 olle 831       rowPrefix = 'dnaRow.';
5000 03 Oct 18 olle 832       columnPrefix = 'dnaColumn.';
5000 03 Oct 18 olle 833     }
5000 03 Oct 18 olle 834     if (boxType && boxType == 'RNA')
5000 03 Oct 18 olle 835     {
5000 03 Oct 18 olle 836       boxPrefix = 'rnaBox.';
5000 03 Oct 18 olle 837       rowPrefix = 'rnaRow.';
5000 03 Oct 18 olle 838       columnPrefix = 'rnaColumn.';
5000 03 Oct 18 olle 839     }
5000 03 Oct 18 olle 840     var box = frm[boxPrefix+index].value;
5000 03 Oct 18 olle 841     var row = frm[rowPrefix+index].value;
5000 03 Oct 18 olle 842     var column = frm[columnPrefix+index].value;
5000 03 Oct 18 olle 843     
5000 03 Oct 18 olle 844     //wellIsValid[index] = true;
5000 03 Oct 18 olle 845     if (!boxType || boxType == 'Specimen')
5000 03 Oct 18 olle 846     {
5000 03 Oct 18 olle 847       wellIsValid[index] = false;
5000 03 Oct 18 olle 848     }
5000 03 Oct 18 olle 849     else if (boxType && boxType == 'DNA')
5000 03 Oct 18 olle 850     {
5000 03 Oct 18 olle 851       dnaWellIsValid[index] = false;
5000 03 Oct 18 olle 852     }
5000 03 Oct 18 olle 853     else if (boxType && boxType == 'RNA')
5000 03 Oct 18 olle 854     {
5000 03 Oct 18 olle 855       rnaWellIsValid[index] = false;
5000 03 Oct 18 olle 856     }
5000 03 Oct 18 olle 857     else
5000 03 Oct 18 olle 858     {
5000 03 Oct 18 olle 859       wellIsValid[index] = false;
5000 03 Oct 18 olle 860     }
5000 03 Oct 18 olle 861     Wizard.setInputStatus(boxPrefix+index);
5000 03 Oct 18 olle 862 /*
5000 03 Oct 18 olle 863     Wizard.setInputStatus('position.'+index);
5000 03 Oct 18 olle 864 */
5000 03 Oct 18 olle 865     
5000 03 Oct 18 olle 866     if (box == '') 
5000 03 Oct 18 olle 867     {
5000 03 Oct 18 olle 868       Wizard.setInputStatus(boxPrefix+index, 'invalid', 'Missing box');
5000 03 Oct 18 olle 869       return;
5000 03 Oct 18 olle 870     }
5000 03 Oct 18 olle 871     
5000 03 Oct 18 olle 872     // Position errors are reported on box message line    
5000 03 Oct 18 olle 873     if (row == '')
5000 03 Oct 18 olle 874     {
5000 03 Oct 18 olle 875       Wizard.setInputStatus(boxPrefix+index, 'invalid', 'Missing row');
5000 03 Oct 18 olle 876       return;
5000 03 Oct 18 olle 877     }
5000 03 Oct 18 olle 878
5000 03 Oct 18 olle 879     if (column == '')
5000 03 Oct 18 olle 880     {
5000 03 Oct 18 olle 881       Wizard.setInputStatus(boxPrefix+index, 'invalid', 'Missing column');
5000 03 Oct 18 olle 882       return;
5000 03 Oct 18 olle 883     }
5000 03 Oct 18 olle 884     
5000 03 Oct 18 olle 885     // Check for duplicates
5000 03 Oct 18 olle 886     var nofTubes = parseInt(frm.nofTubes.value);
5000 03 Oct 18 olle 887     for (var i=0; i < nofTubes; i++)
5000 03 Oct 18 olle 888     {    
5000 03 Oct 18 olle 889       if (i != index)
5000 03 Oct 18 olle 890       {
5000 03 Oct 18 olle 891         if (box == frm.elements[boxPrefix+i].value && row == frm[rowPrefix+i].value && column == frm[columnPrefix+i].value)
5000 03 Oct 18 olle 892         {
5000 03 Oct 18 olle 893           Wizard.setInputStatus(boxPrefix+index, 'invalid', 'The position is already used once in this wizard');        
5000 03 Oct 18 olle 894           return;
5000 03 Oct 18 olle 895         }
5000 03 Oct 18 olle 896       }
5000 03 Oct 18 olle 897     }
5000 03 Oct 18 olle 898
5000 03 Oct 18 olle 899     //Wizard.setInputStatus('position.'+index, 'checking', 'Checking...');
5000 03 Oct 18 olle 900     Wizard.setInputStatus(boxPrefix+index, 'checking', 'Checking...');
5000 03 Oct 18 olle 901     
5000 03 Oct 18 olle 902     // Seems to be ok -- check if used by another sample
5000 03 Oct 18 olle 903     var request = Ajax.getXmlHttpRequest();
5000 03 Oct 18 olle 904     var url = '../SpecimenTubeRegistration.servlet?ID='+App.getSessionId();
5000 03 Oct 18 olle 905     url += '&cmd=ValidateWell';
5000 03 Oct 18 olle 906     url += '&box=' + encodeURIComponent(box);  
5000 03 Oct 18 olle 907     url += '&row=' + encodeURIComponent(row);
5000 03 Oct 18 olle 908     url += '&column=' + encodeURIComponent(column);
5000 03 Oct 18 olle 909     
5000 03 Oct 18 olle 910     Wizard.asyncJsonRequest(url, function(response) { persinfo.onBoxValidated(response, boxType, index) } );
5000 03 Oct 18 olle 911   }
5000 03 Oct 18 olle 912   
5000 03 Oct 18 olle 913   persinfo.onBoxValidated = function(response, boxType, index)
5000 03 Oct 18 olle 914   {
5000 03 Oct 18 olle 915     // Get well position prefixes, default is for input tubes
5000 03 Oct 18 olle 916     var boxPrefix = 'box.';
5000 03 Oct 18 olle 917     if (boxType && boxType == 'DNA')
5000 03 Oct 18 olle 918     {
5000 03 Oct 18 olle 919       boxPrefix = 'dnaBox.';
5000 03 Oct 18 olle 920     }
5000 03 Oct 18 olle 921     if (boxType && boxType == 'RNA')
5000 03 Oct 18 olle 922     {
5000 03 Oct 18 olle 923       boxPrefix = 'rnaBox.';
5000 03 Oct 18 olle 924     }
5000 03 Oct 18 olle 925
5000 03 Oct 18 olle 926     //Wizard.setInputStatus('position.'+index);
5000 03 Oct 18 olle 927     Wizard.setInputStatus(boxPrefix+index);
5000 03 Oct 18 olle 928     if (response.message)
5000 03 Oct 18 olle 929     {
5000 03 Oct 18 olle 930       //Wizard.setInputStatus(response.box ? 'box.'+index : 'position.'+index, 'invalid', Strings.encodeTags(response.message));
5000 03 Oct 18 olle 931       Wizard.setInputStatus(boxPrefix+index, 'invalid', Strings.encodeTags(response.message));
5000 03 Oct 18 olle 932       return;
5000 03 Oct 18 olle 933     }
5000 03 Oct 18 olle 934     
5000 03 Oct 18 olle 935     //wellIsValid[index] = true;
5000 03 Oct 18 olle 936     if (!boxType || boxType == 'Specimen')
5000 03 Oct 18 olle 937     {
5000 03 Oct 18 olle 938       wellIsValid[index] = true;
5000 03 Oct 18 olle 939     }
5000 03 Oct 18 olle 940     else if (boxType && boxType == 'DNA')
5000 03 Oct 18 olle 941     {
5000 03 Oct 18 olle 942       dnaWellIsValid[index] = true;
5000 03 Oct 18 olle 943     }
5000 03 Oct 18 olle 944     else if (boxType && boxType == 'RNA')
5000 03 Oct 18 olle 945     {
5000 03 Oct 18 olle 946       rnaWellIsValid[index] = true;
5000 03 Oct 18 olle 947     }
5000 03 Oct 18 olle 948     else
5000 03 Oct 18 olle 949     {
5000 03 Oct 18 olle 950       wellIsValid[index] = true;
5000 03 Oct 18 olle 951     }
5000 03 Oct 18 olle 952     Wizard.setInputStatus(boxPrefix+index, 'valid');
5000 03 Oct 18 olle 953 /*
5000 03 Oct 18 olle 954     Wizard.setInputStatus('position.'+index, 'valid');
5000 03 Oct 18 olle 955 */
5000 03 Oct 18 olle 956   }
5000 03 Oct 18 olle 957
5000 03 Oct 18 olle 958   persinfo.nofSectionsOnChange = function(event)
5000 03 Oct 18 olle 959   {
5000 03 Oct 18 olle 960     var frm = document.forms['meludi'];
5000 03 Oct 18 olle 961     var target = event.currentTarget;
5000 03 Oct 18 olle 962
5000 03 Oct 18 olle 963     var index = Data.int(target, 'index');
5000 03 Oct 18 olle 964     var nofSections = frm['nofSections.'+index].value;
5000 03 Oct 18 olle 965
5000 03 Oct 18 olle 966     Wizard.setInputStatus('nofSections.'+index);
5000 03 Oct 18 olle 967
5000 03 Oct 18 olle 968     if (nofSections == '')
5000 03 Oct 18 olle 969     {
5000 03 Oct 18 olle 970       Wizard.setInputStatus('nofSections'+index, 'invalid', 'Missing');
5000 03 Oct 18 olle 971       return;
5000 03 Oct 18 olle 972     }
5000 03 Oct 18 olle 973     if (parseInt(nofSections) < 1)
5000 03 Oct 18 olle 974     {
5000 03 Oct 18 olle 975       Wizard.setInputStatus('nofSections'+index, 'invalid', 'Must be at least 1');
5000 03 Oct 18 olle 976       return;    
5000 03 Oct 18 olle 977     }
5000 03 Oct 18 olle 978     Wizard.setInputStatus('nofSections'+index, 'valid');
5000 03 Oct 18 olle 979   }
5000 03 Oct 18 olle 980
5000 03 Oct 18 olle 981   persinfo.validateStep4 = function(event)
5000 03 Oct 18 olle 982   {
5000 03 Oct 18 olle 983     var valid = false;
5000 03 Oct 18 olle 984
5000 03 Oct 18 olle 985     var frm = document.forms['meludi'];
5000 03 Oct 18 olle 986     var tubeContentType = frm.tubeContentType.value;
5000 03 Oct 18 olle 987     if (tubeContentType == 'Specimen')
5000 03 Oct 18 olle 988     {
5000 03 Oct 18 olle 989       for (var i = 0; i < wellIsValid.length; i++)
5000 03 Oct 18 olle 990       {
5000 03 Oct 18 olle 991         // No storage space is allocated for first specimen,
5000 03 Oct 18 olle 992         // since all amount is expected to be used for analysis.
5000 03 Oct 18 olle 993         // Specimen tube with i == 0 is therefore skipped.
5000 03 Oct 18 olle 994         if (i > 0)
5000 03 Oct 18 olle 995         {
5000 03 Oct 18 olle 996           if (!wellIsValid[i])
5000 03 Oct 18 olle 997           {
5000 03 Oct 18 olle 998             event.preventDefault();
5000 03 Oct 18 olle 999             return;
5000 03 Oct 18 olle 1000           }
5000 03 Oct 18 olle 1001         }
5000 03 Oct 18 olle 1002         if (!dnaWellIsValid[i])
5000 03 Oct 18 olle 1003         {
5000 03 Oct 18 olle 1004           event.preventDefault();
5000 03 Oct 18 olle 1005           return;
5000 03 Oct 18 olle 1006         }
5000 03 Oct 18 olle 1007         if (!rnaWellIsValid[i])
5000 03 Oct 18 olle 1008         {
5000 03 Oct 18 olle 1009           event.preventDefault();
5000 03 Oct 18 olle 1010           return;
5000 03 Oct 18 olle 1011         }
5000 03 Oct 18 olle 1012       }
5000 03 Oct 18 olle 1013     }
5000 03 Oct 18 olle 1014     else
5000 03 Oct 18 olle 1015     {
5000 03 Oct 18 olle 1016       // Input DNA, RNA, or DNA + RNA
5000 03 Oct 18 olle 1017       for (var i = 0; i < wellIsValid.length; i++)
5000 03 Oct 18 olle 1018       {
5000 03 Oct 18 olle 1019         if (!wellIsValid[i])
5000 03 Oct 18 olle 1020         {
5000 03 Oct 18 olle 1021           event.preventDefault();
5000 03 Oct 18 olle 1022           return;
5000 03 Oct 18 olle 1023         }
5000 03 Oct 18 olle 1024       }
5000 03 Oct 18 olle 1025     }
5000 03 Oct 18 olle 1026   }
5000 03 Oct 18 olle 1027
5000 03 Oct 18 olle 1028   persinfo.submit = function()
5000 03 Oct 18 olle 1029   {
5000 03 Oct 18 olle 1030     var frm = document.forms['meludi'];
5000 03 Oct 18 olle 1031     //var updateMode = caseInfo.id;
5000 03 Oct 18 olle 1032     
5000 03 Oct 18 olle 1033     var bloodInfo = {};
5000 03 Oct 18 olle 1034     //var nofTubes = parseInt(frm.nofTubes.value);
5000 03 Oct 18 olle 1035     bloodInfo.blood = [];
5000 03 Oct 18 olle 1036     for (var i = 0; i < nofBloodTubes; i++)
5000 03 Oct 18 olle 1037     {
5000 03 Oct 18 olle 1038       var bloodTube ={};
5000 03 Oct 18 olle 1039       bloodTube.tubeLabel = frm['tubeLabel.'+i].value;
5027 15 Oct 18 olle 1040       bloodTube.samplingDate = frm['samplingDate.'+i].value;
5027 15 Oct 18 olle 1041       bloodTube.arrivalDate = frm['arrivalDate.'+i].value;
5000 03 Oct 18 olle 1042       bloodTube.box = frm['box.'+i].value;
5000 03 Oct 18 olle 1043       bloodTube.row = frm['row.'+i].value;
5000 03 Oct 18 olle 1044       bloodTube.column = frm['column.'+i].value;
5027 15 Oct 18 olle 1045       bloodTube.comment = frm['comment.'+i].value;
5027 15 Oct 18 olle 1046       bloodTube.operator = frm['operator.'+i].value;
5000 03 Oct 18 olle 1047 //alert("baseline_alt_rec.js::submit(): i = " + i + " bloodTube = " + JSON.stringify(bloodTube));
5000 03 Oct 18 olle 1048       bloodInfo.blood[i] = bloodTube;
5000 03 Oct 18 olle 1049     }
5000 03 Oct 18 olle 1050     var submitInfo = {};
5000 03 Oct 18 olle 1051     submitInfo.bloodInfo = bloodInfo;
5000 03 Oct 18 olle 1052
5000 03 Oct 18 olle 1053     var url = '../BaseLineRegistration.servlet?ID='+App.getSessionId();
5000 03 Oct 18 olle 1054     //url += '&cmd=' + (updateMode ? 'UpdateCase' : 'CreateCase');
5000 03 Oct 18 olle 1055     //Wizard.showLoadingAnimation('Registering case...');
5000 03 Oct 18 olle 1056     url += '&cmd=RegisterBloodSamples';
5000 03 Oct 18 olle 1057     Wizard.showLoadingAnimation('Registering blood samples...');
5000 03 Oct 18 olle 1058     Wizard.asyncJsonRequest(url, persinfo.submissionResults, 'POST', JSON.stringify(submitInfo));
5000 03 Oct 18 olle 1059   }
5000 03 Oct 18 olle 1060   
5000 03 Oct 18 olle 1061   persinfo.submissionResults = function(response)
5000 03 Oct 18 olle 1062   {
5000 03 Oct 18 olle 1063     Wizard.showFinalMessage(response.messages);
5000 03 Oct 18 olle 1064     Doc.show('gorestart');
5000 03 Oct 18 olle 1065     //Doc.show('downloadformbatch2');
5000 03 Oct 18 olle 1066   }
5000 03 Oct 18 olle 1067
5000 03 Oct 18 olle 1068   persinfo.downloadFormBatch1 = function()
5000 03 Oct 18 olle 1069   {
5000 03 Oct 18 olle 1070     persinfo.downloadFormBatch(1);
5000 03 Oct 18 olle 1071   }
5000 03 Oct 18 olle 1072
5000 03 Oct 18 olle 1073   persinfo.downloadFormBatch2 = function()
5000 03 Oct 18 olle 1074   {
5000 03 Oct 18 olle 1075     persinfo.downloadFormBatch(2);
5000 03 Oct 18 olle 1076   }
5000 03 Oct 18 olle 1077
5000 03 Oct 18 olle 1078   persinfo.downloadFormBatch = function(batchType)
5000 03 Oct 18 olle 1079   {
5000 03 Oct 18 olle 1080     var frm = document.forms['meludi'];
5000 03 Oct 18 olle 1081     var startItemName = frm.caseName.value;
5000 03 Oct 18 olle 1082     //var nofFormSets = frm.nofFormSets.value;
5000 03 Oct 18 olle 1083     var nofFormSets = 1;
5000 03 Oct 18 olle 1084
5000 03 Oct 18 olle 1085     var url = '../ReferralGenerator.servlet?ID='+App.getSessionId();
5000 03 Oct 18 olle 1086     url += '&cmd=DownloadFormBatchFile';
5000 03 Oct 18 olle 1087     url += '&batchType='+batchType;
5000 03 Oct 18 olle 1088     url += '&startitemname='+encodeURIComponent(startItemName);
5000 03 Oct 18 olle 1089     url += '&nofformsets='+encodeURIComponent(nofFormSets);
5000 03 Oct 18 olle 1090     window.open(url);
5000 03 Oct 18 olle 1091   }
5000 03 Oct 18 olle 1092
5000 03 Oct 18 olle 1093   return persinfo;
5000 03 Oct 18 olle 1094 }();
5000 03 Oct 18 olle 1095
5000 03 Oct 18 olle 1096 Doc.onLoad(PersInfo.initPage);
5000 03 Oct 18 olle 1097