extensions/net.sf.basedb.meludi/trunk/resources/personal/generate-referral-forms_alt_ntr.js

Code
Comments
Other
Rev Date Author Line
5686 25 Oct 19 olle 1 var Istat = function()
5686 25 Oct 19 olle 2 {
5686 25 Oct 19 olle 3   var istat = {};
5686 25 Oct 19 olle 4   var debug = 0;
5686 25 Oct 19 olle 5
5686 25 Oct 19 olle 6   var caseInfo;
5686 25 Oct 19 olle 7
5686 25 Oct 19 olle 8   var usesSitePrefix = false;
5686 25 Oct 19 olle 9   var referralPrefix = '';
5686 25 Oct 19 olle 10   var referralNumDigits = 5;
5686 25 Oct 19 olle 11   var refVariantDefault = 'kit1_standard';
5686 25 Oct 19 olle 12   
5686 25 Oct 19 olle 13   var refStartItemIdPure;
5686 25 Oct 19 olle 14   var itemIsValid = false;
5686 25 Oct 19 olle 15
5686 25 Oct 19 olle 16   istat.initPage = function()
5686 25 Oct 19 olle 17   {
5695 04 Nov 19 olle 18 //alert("generate-referral-forms_alt_ntr.js::initPage(): Start");
5686 25 Oct 19 olle 19     // Step 1
5695 04 Nov 19 olle 20     /*
5686 25 Oct 19 olle 21     Events.addEventHandler('step-1', 'wizard-validate', istat.validateStep1);
5686 25 Oct 19 olle 22     Events.addEventHandler('sites', 'change', istat.siteAndVariantOnChange);
5686 25 Oct 19 olle 23     //Events.addEventHandler('referralvariant', 'change', istat.siteAndVariantOnChange);
5686 25 Oct 19 olle 24     Buttons.addClickHandler('gonext', Wizard.goNextOnClick);
5686 25 Oct 19 olle 25     
5686 25 Oct 19 olle 26     // Step 2
5686 25 Oct 19 olle 27     Events.addEventHandler('step-2', 'wizard-validate', istat.validateStep2);
5695 04 Nov 19 olle 28     */
5695 04 Nov 19 olle 29     Events.addEventHandler('step-1', 'wizard-validate', istat.validateStep2);
5686 25 Oct 19 olle 30     Events.addEventHandler('itemName', 'keypress', Wizard.focusOnEnter);
5686 25 Oct 19 olle 31     Events.addEventHandler('itemName', 'blur', istat.itemNameOnChange);
5695 04 Nov 19 olle 32     Buttons.addClickHandler('gonext', Wizard.goNextOnClick);
5686 25 Oct 19 olle 33     
5695 04 Nov 19 olle 34     // Step 2
5686 25 Oct 19 olle 35     Buttons.addClickHandler('downloadformbatch1', istat.downloadFormBatch1);
5686 25 Oct 19 olle 36     Buttons.addClickHandler('downloadformbatch2', istat.downloadFormBatch2);
5686 25 Oct 19 olle 37     Buttons.addClickHandler('downloadlabelfile', istat.downloadLabelFile);
5686 25 Oct 19 olle 38     Buttons.addClickHandler('updateuseditemidlist', istat.updateUsedItemIdDigitsList);
5686 25 Oct 19 olle 39     
5686 25 Oct 19 olle 40     // Navigation
5686 25 Oct 19 olle 41     Buttons.addClickHandler('gocancel', Wizard.cancelWizard);
5686 25 Oct 19 olle 42     Buttons.addClickHandler('gorestart', Wizard.restartWizard);
5686 25 Oct 19 olle 43
5686 25 Oct 19 olle 44     Doc.show('step-1');
5686 25 Oct 19 olle 45     Doc.show('gonext');
5686 25 Oct 19 olle 46     Doc.addClass('gonext', 'disabled');
5686 25 Oct 19 olle 47
5686 25 Oct 19 olle 48     refStartItemIdPure = '';
5686 25 Oct 19 olle 49
5695 04 Nov 19 olle 50 /*
5686 25 Oct 19 olle 51     // Load sites
5686 25 Oct 19 olle 52     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 53     var url = '../ReferralGenerator.servlet?ID='+App.getSessionId();
5686 25 Oct 19 olle 54     url += '&cmd=GetSites';    
5686 25 Oct 19 olle 55     Doc.addClass('sites', 'list-loading');
5686 25 Oct 19 olle 56     frm.sites[0] = new Option('loading...');
5686 25 Oct 19 olle 57     Wizard.asyncJsonRequest(url, istat.sitesLoaded);
5695 04 Nov 19 olle 58 */
5686 25 Oct 19 olle 59     
5686 25 Oct 19 olle 60     // Load permissions
5686 25 Oct 19 olle 61     istat.initPermissions();
5686 25 Oct 19 olle 62     // Load configuration
5686 25 Oct 19 olle 63     istat.loadConfiguration();
5695 04 Nov 19 olle 64     //
5695 04 Nov 19 olle 65     istat.initializeStep2();
5686 25 Oct 19 olle 66   }
5686 25 Oct 19 olle 67   
5686 25 Oct 19 olle 68   istat.initPermissions = function()
5686 25 Oct 19 olle 69   {
5686 25 Oct 19 olle 70     // Get permission information
5686 25 Oct 19 olle 71     var url = '../Install.servlet?ID='+App.getSessionId();
5686 25 Oct 19 olle 72     url += '&cmd=GetPermissions';
5686 25 Oct 19 olle 73     var request = Ajax.getXmlHttpRequest();
5686 25 Oct 19 olle 74     request.open("GET", url, true);
5686 25 Oct 19 olle 75     Ajax.setReadyStateHandler(request, istat.onPermissionsLoaded, istat.onPermissionsLoaded);
5686 25 Oct 19 olle 76     request.send(null);
5686 25 Oct 19 olle 77   }
5686 25 Oct 19 olle 78   
5686 25 Oct 19 olle 79   // Callback when permission information is ready
5686 25 Oct 19 olle 80   istat.onPermissionsLoaded = function(request)
5686 25 Oct 19 olle 81   {
5686 25 Oct 19 olle 82     if (debug) App.debug(Strings.encodeTags(request.responseText));
5686 25 Oct 19 olle 83     var response;
5686 25 Oct 19 olle 84     var error = false;
5686 25 Oct 19 olle 85     try
5686 25 Oct 19 olle 86     {
5686 25 Oct 19 olle 87       response = JSON.parse(request.responseText);
5686 25 Oct 19 olle 88       if (response.status != 'ok')
5686 25 Oct 19 olle 89       {
5686 25 Oct 19 olle 90         error = response.message || response.stacktrace || 'Unexpected error';
5686 25 Oct 19 olle 91       }
5686 25 Oct 19 olle 92     }
5686 25 Oct 19 olle 93     catch (ex)
5686 25 Oct 19 olle 94     {
5686 25 Oct 19 olle 95       error = ex;
5686 25 Oct 19 olle 96     }
5686 25 Oct 19 olle 97     
5686 25 Oct 19 olle 98     if (error)
5686 25 Oct 19 olle 99     {
5686 25 Oct 19 olle 100       alert(error);
5686 25 Oct 19 olle 101       return;
5686 25 Oct 19 olle 102     }
5686 25 Oct 19 olle 103     
5686 25 Oct 19 olle 104     myPermissions = response.permissions;
5686 25 Oct 19 olle 105     //var isAdmin = myPermissions['Administrator'] == 1;
5686 25 Oct 19 olle 106     //var noProjectIsActive = !App.getActiveProjectId();
5686 25 Oct 19 olle 107   }
5686 25 Oct 19 olle 108
5686 25 Oct 19 olle 109   istat.loadConfiguration = function()
5686 25 Oct 19 olle 110   {
5686 25 Oct 19 olle 111     var url = '../Session.servlet?ID='+App.getSessionId();
5686 25 Oct 19 olle 112     url += '&cmd=GetConfiguration'
5686 25 Oct 19 olle 113     var request = Ajax.getXmlHttpRequest();
5686 25 Oct 19 olle 114     request.open("GET", url, true);
5686 25 Oct 19 olle 115     Ajax.setReadyStateHandler(request, istat.onConfiguration, istat.onConfiguration);
5686 25 Oct 19 olle 116     request.send(null);
5686 25 Oct 19 olle 117   }
5686 25 Oct 19 olle 118   
5686 25 Oct 19 olle 119   istat.onConfiguration = function(request)
5686 25 Oct 19 olle 120   {
5686 25 Oct 19 olle 121     var frm = document.forms['meludi'];  
5686 25 Oct 19 olle 122
5686 25 Oct 19 olle 123     if (debug)
5686 25 Oct 19 olle 124     {
5686 25 Oct 19 olle 125       App.debug(Strings.encodeTags(request.responseText));
5686 25 Oct 19 olle 126     }
5686 25 Oct 19 olle 127     
5686 25 Oct 19 olle 128     var response;
5686 25 Oct 19 olle 129     var error = false;
5686 25 Oct 19 olle 130     try
5686 25 Oct 19 olle 131     {
5686 25 Oct 19 olle 132       response = JSON.parse(request.responseText);
5686 25 Oct 19 olle 133       if (response.status != 'ok')
5686 25 Oct 19 olle 134       {
5686 25 Oct 19 olle 135         error = response.message || response.stacktrace || 'Unexpected error';
5686 25 Oct 19 olle 136       }
5686 25 Oct 19 olle 137     }
5686 25 Oct 19 olle 138     catch (ex)
5686 25 Oct 19 olle 139     {
5686 25 Oct 19 olle 140       error = ex;
5686 25 Oct 19 olle 141     }
5686 25 Oct 19 olle 142     if (error) App.debug(error);
5686 25 Oct 19 olle 143
5686 25 Oct 19 olle 144     // Get configuration result    
5686 25 Oct 19 olle 145     var conf = response.configuration;
5686 25 Oct 19 olle 146     // Check for uses site prefix flag
5686 25 Oct 19 olle 147     usesSitePrefix = conf.usesSitePrefix;
5686 25 Oct 19 olle 148     referralPrefix = conf.referralPrefix;
5686 25 Oct 19 olle 149     referralNumDigits = conf.referralNumDigits;
5686 25 Oct 19 olle 150     //alert("generate-referral-forms.js::onConfiguration(): usesSitePrefix = " + usesSitePrefix + " referralPrefix = " + referralPrefix + " referralNumDigits = " + referralNumDigits);
5686 25 Oct 19 olle 151 /*
5686 25 Oct 19 olle 152     // Check for project focus default
5686 25 Oct 19 olle 153     var projectFocusDefault = conf.projectFocusDefault;
5686 25 Oct 19 olle 154     if (projectFocusDefault != null)
5686 25 Oct 19 olle 155     {
5686 25 Oct 19 olle 156       frm.projectFocus.value = projectFocusDefault;
5686 25 Oct 19 olle 157       streg.projectFocusOnChange();
5686 25 Oct 19 olle 158     }
5686 25 Oct 19 olle 159     // Check for specimen type default
5686 25 Oct 19 olle 160     var specimenTypeDefault = conf.specimenTypeDefault;
5686 25 Oct 19 olle 161     if (specimenTypeDefault != null)
5686 25 Oct 19 olle 162     {
5686 25 Oct 19 olle 163       frm.specimenType.value = specimenTypeDefault;
5686 25 Oct 19 olle 164     }
5686 25 Oct 19 olle 165     // Check for specimen input type default
5686 25 Oct 19 olle 166     var specimenInputTypeDefault = conf.specimenInputTypeDefault;
5686 25 Oct 19 olle 167     if (specimenInputTypeDefault != null)
5686 25 Oct 19 olle 168     {
5686 25 Oct 19 olle 169       frm.specimenInputType.value = specimenInputTypeDefault;
5686 25 Oct 19 olle 170     }
5686 25 Oct 19 olle 171     // Check for extracts from first specimen only default
5686 25 Oct 19 olle 172     var extractsFromFirstSpecimenOnlyDefault = conf.extractsFromFirstSpecimenOnlyDefault;
5686 25 Oct 19 olle 173     if (extractsFromFirstSpecimenOnlyDefault != null)
5686 25 Oct 19 olle 174     {
5686 25 Oct 19 olle 175       frm.extractsFromFirstSpecimenOnlyCB.checked = extractsFromFirstSpecimenOnlyDefault;
5686 25 Oct 19 olle 176     }
5686 25 Oct 19 olle 177 */
5686 25 Oct 19 olle 178
5686 25 Oct 19 olle 179 /*
5686 25 Oct 19 olle 180     // Continue with initializing info for case
5686 25 Oct 19 olle 181     var url = '../LabelGeneration.servlet?ID='+App.getSessionId();
5686 25 Oct 19 olle 182     url += '&cmd=CountCases';
5686 25 Oct 19 olle 183     Wizard.showLoadingAnimation('Loading cases...');
5686 25 Oct 19 olle 184     Wizard.asyncJsonRequest(url, streg.caseInfoLoadedStep1);
5686 25 Oct 19 olle 185 */
5695 04 Nov 19 olle 186     if (usesSitePrefix)
5695 04 Nov 19 olle 187     {
5695 04 Nov 19 olle 188       // Load sites
5695 04 Nov 19 olle 189       var frm = document.forms['meludi'];
5695 04 Nov 19 olle 190       var url = '../ReferralGenerator.servlet?ID='+App.getSessionId();
5695 04 Nov 19 olle 191       url += '&cmd=GetSites';    
5695 04 Nov 19 olle 192       Doc.addClass('sites', 'list-loading');
5695 04 Nov 19 olle 193       frm.sites[0] = new Option('loading...');
5695 04 Nov 19 olle 194       Wizard.asyncJsonRequest(url, istat.sitesLoaded);
5695 04 Nov 19 olle 195     }
5686 25 Oct 19 olle 196   }
5686 25 Oct 19 olle 197
5686 25 Oct 19 olle 198   istat.sitesLoaded = function(response)
5686 25 Oct 19 olle 199   {
5686 25 Oct 19 olle 200     Doc.removeClass('sites', 'list-loading');
5686 25 Oct 19 olle 201     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 202     var sites = response.sites;
5686 25 Oct 19 olle 203     frm.sites.length = 0;
5686 25 Oct 19 olle 204     //frm.sites[0] = new Option('All sites together', '');
5686 25 Oct 19 olle 205     frm.sites[0] = new Option('- Select site -', '');
5686 25 Oct 19 olle 206     for (var i = 0; i < sites.length; i++)
5686 25 Oct 19 olle 207     {
5686 25 Oct 19 olle 208       var s = sites[i];
5686 25 Oct 19 olle 209       //var option = new Option(s.name, s.prefix);
5686 25 Oct 19 olle 210       var option = new Option(s.name + '  [' + s.prefix + ']', s.prefix);
5686 25 Oct 19 olle 211       frm.sites[frm.sites.length] = option;
5686 25 Oct 19 olle 212     }
5686 25 Oct 19 olle 213   }
5686 25 Oct 19 olle 214
5686 25 Oct 19 olle 215   istat.siteAndVariantOnChange = function()
5686 25 Oct 19 olle 216   {
5686 25 Oct 19 olle 217     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 218     var site = frm.sites.value;
5686 25 Oct 19 olle 219     //var refVariant = frm.referralvariant.value;
5686 25 Oct 19 olle 220     var refVariant = refVariantDefault;
5686 25 Oct 19 olle 221     var siteAndVariantAreValid = false;
5686 25 Oct 19 olle 222     if (site != '' && refVariant != '')
5686 25 Oct 19 olle 223     {
5686 25 Oct 19 olle 224       siteAndVariantAreValid = true;
5686 25 Oct 19 olle 225     }
5686 25 Oct 19 olle 226     if (siteAndVariantAreValid)
5686 25 Oct 19 olle 227     {
5686 25 Oct 19 olle 228       // Check if multiple template files for same referral from type
5686 25 Oct 19 olle 229       var url = '../ReferralGenerator.servlet?ID='+App.getSessionId();
5686 25 Oct 19 olle 230       url += '&cmd=GetReferralTemplateInfo';
5686 25 Oct 19 olle 231       url += '&site='+encodeURIComponent(site);
5686 25 Oct 19 olle 232       url += '&referralvariant='+encodeURIComponent(refVariant);
5686 25 Oct 19 olle 233       Wizard.showLoadingAnimation('Getting referral template info...', 'ref-gen-progress');
5686 25 Oct 19 olle 234       Wizard.asyncJsonRequest(url, istat.preValidateStep1);
5686 25 Oct 19 olle 235     }
5686 25 Oct 19 olle 236     else
5686 25 Oct 19 olle 237     {
5686 25 Oct 19 olle 238       Doc.addClass('gonext', 'disabled');
5686 25 Oct 19 olle 239     }
5686 25 Oct 19 olle 240   }
5686 25 Oct 19 olle 241
5686 25 Oct 19 olle 242   istat.preValidateStep1 = function(response)
5686 25 Oct 19 olle 243   {
5686 25 Oct 19 olle 244     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 245
5686 25 Oct 19 olle 246     var jsonMultTemplates = response.multTemplates;
5686 25 Oct 19 olle 247     if (jsonMultTemplates.length > 0)
5686 25 Oct 19 olle 248     {
5686 25 Oct 19 olle 249       // List multiple templates/type
5686 25 Oct 19 olle 250       //var html = '<table id="templateFilesTable" class="step-form">';
5686 25 Oct 19 olle 251       var html = '<br>';
5686 25 Oct 19 olle 252       html += '<table id="templateFilesTable">';
5686 25 Oct 19 olle 253       // Header row
5686 25 Oct 19 olle 254       html += '<tr>';
5686 25 Oct 19 olle 255       html += '<th>Multiple template files for same type</th>';
5686 25 Oct 19 olle 256       html += '<th>Template type</th>';
5686 25 Oct 19 olle 257       html += '</tr>';
5686 25 Oct 19 olle 258       // File list
5686 25 Oct 19 olle 259       for (var i = 0; i < jsonMultTemplates.length; i++)
5686 25 Oct 19 olle 260       {
5686 25 Oct 19 olle 261         //var filename = jsonMultTemplates[i];
5686 25 Oct 19 olle 262         var jsonMultTempl = jsonMultTemplates[i];
5686 25 Oct 19 olle 263         var filename = jsonMultTempl['file'];
5686 25 Oct 19 olle 264         var type = jsonMultTempl['type'];
5686 25 Oct 19 olle 265         html += '<tr>';
5686 25 Oct 19 olle 266         html += '<td>&nbsp;&nbsp;' + filename + '</td>';
5686 25 Oct 19 olle 267         html += '<td>&nbsp;&nbsp;' + type + '</td>';
5686 25 Oct 19 olle 268         html += '</tr>';
5686 25 Oct 19 olle 269       }
5686 25 Oct 19 olle 270       html += '</table>';
5686 25 Oct 19 olle 271       Doc.element('step1message').innerHTML = html;
5686 25 Oct 19 olle 272
5686 25 Oct 19 olle 273       // Display extra checkbox to confirm use of multiple templates/type
5686 25 Oct 19 olle 274       var confirmMsg = 'Check to verify use of multiple template files for same type.';
5686 25 Oct 19 olle 275       Wizard.showGoNextConfirmation(true, confirmMsg);
5686 25 Oct 19 olle 276       return;
5686 25 Oct 19 olle 277     }
5686 25 Oct 19 olle 278     else
5686 25 Oct 19 olle 279     {
5686 25 Oct 19 olle 280       Doc.removeClass('gonext', 'disabled');
5686 25 Oct 19 olle 281     }
5686 25 Oct 19 olle 282   }
5686 25 Oct 19 olle 283
5686 25 Oct 19 olle 284   istat.validateStep1 = function(event)
5686 25 Oct 19 olle 285   {
5686 25 Oct 19 olle 286     istat.initializeStep2();
5686 25 Oct 19 olle 287   }
5686 25 Oct 19 olle 288
5686 25 Oct 19 olle 289   istat.initializeStep2 = function(response)
5686 25 Oct 19 olle 290   {
5695 04 Nov 19 olle 291 //alert("generate-referral-forms_alt_ntr.js::initializeStep2(): Start");
5686 25 Oct 19 olle 292     var frm = document.forms['meludi'];
5695 04 Nov 19 olle 293     //Wizard.setCurrentStep(2);
5695 04 Nov 19 olle 294     Wizard.setCurrentStep(1);
5686 25 Oct 19 olle 295
5695 04 Nov 19 olle 296     //istat.selectOptionsDisabled('sites', true);
5686 25 Oct 19 olle 297     //istat.selectOptionsDisabled('referralvariant', true);
5686 25 Oct 19 olle 298
5686 25 Oct 19 olle 299     // Get referral start info
5686 25 Oct 19 olle 300     var url = '../ReferralGenerator.servlet?ID='+App.getSessionId();
5686 25 Oct 19 olle 301     url += '&cmd=GetReferralStartInfo';
5686 25 Oct 19 olle 302     Wizard.showLoadingAnimation('Getting referral start info...', 'ref-gen-progress');
5686 25 Oct 19 olle 303     Wizard.asyncJsonRequest(url, istat.initializeStep2a);
5686 25 Oct 19 olle 304   }
5686 25 Oct 19 olle 305     
5686 25 Oct 19 olle 306   istat.initializeStep2a = function(response)
5686 25 Oct 19 olle 307   {
5695 04 Nov 19 olle 308 //alert("generate-referral-forms_alt_ntr.js::initializeStep2a(): Start");
5686 25 Oct 19 olle 309     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 310
5686 25 Oct 19 olle 311     var jsonRefStartInfo = response.refStartInfo;
5686 25 Oct 19 olle 312     
5695 04 Nov 19 olle 313     //var site = frm.sites.value;
5686 25 Oct 19 olle 314     //var refVariant = frm.referralvariant.value;
5686 25 Oct 19 olle 315     var refVariant = refVariantDefault;
5686 25 Oct 19 olle 316
5686 25 Oct 19 olle 317     // Initialize number of referral forms to generate
5686 25 Oct 19 olle 318     var nofFormSetsDefault = 50;
5686 25 Oct 19 olle 319     if (refVariant == 'kit2_neoadjuvant')
5686 25 Oct 19 olle 320     {
5686 25 Oct 19 olle 321       nofFormSetsDefault = 25;
5686 25 Oct 19 olle 322     }
5686 25 Oct 19 olle 323     frm.nofFormSets.value = nofFormSetsDefault;    
5686 25 Oct 19 olle 324     
5726 14 Nov 19 olle 325     if (referralPrefix == null || referralPrefix == '')
5726 14 Nov 19 olle 326     {
5726 14 Nov 19 olle 327       referralPrefix = 'NT';
5726 14 Nov 19 olle 328     }
5686 25 Oct 19 olle 329     refStartItemIdPure = jsonRefStartInfo['startItemIdDigitsPure'];
5686 25 Oct 19 olle 330     //alert("generate-referral-forms.js::initializeStep2a(): refStartItemIdPure = " + refStartItemIdPure);
5686 25 Oct 19 olle 331     var lastUpdated = jsonRefStartInfo['lastUpdated'];
5686 25 Oct 19 olle 332     // Add site prefix to referral pure start item id
5695 04 Nov 19 olle 333     //var refStartItemId = referralPrefix + site + refStartItemIdPure;
5695 04 Nov 19 olle 334     var refStartItemId = referralPrefix + refStartItemIdPure;
5686 25 Oct 19 olle 335     if (lastUpdated != null && lastUpdated != '')
5686 25 Oct 19 olle 336     {
5686 25 Oct 19 olle 337       Doc.element('referralIdLastUpdated').innerHTML = lastUpdated;
5686 25 Oct 19 olle 338     }
5686 25 Oct 19 olle 339     frm.itemName.value = refStartItemId;
5686 25 Oct 19 olle 340
5686 25 Oct 19 olle 341     Doc.show('gonext');
5686 25 Oct 19 olle 342
5695 04 Nov 19 olle 343     //Doc.show('step-2');
5695 04 Nov 19 olle 344     Doc.show('step-1');
5686 25 Oct 19 olle 345   }
5686 25 Oct 19 olle 346
5686 25 Oct 19 olle 347   istat.itemNameOnChange = function()
5686 25 Oct 19 olle 348   {
5686 25 Oct 19 olle 349     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 350     var itemName = frm.itemName.value.toUpperCase();
5686 25 Oct 19 olle 351     itemIsValid = false;
5686 25 Oct 19 olle 352     Doc.addClass('gonext', 'disabled');
5686 25 Oct 19 olle 353     if (itemName == '')
5686 25 Oct 19 olle 354     {
5686 25 Oct 19 olle 355       Wizard.setInputStatus('itemName', 'invalid', 'Missing');
5686 25 Oct 19 olle 356       frm.itemName.focus();
5686 25 Oct 19 olle 357       return;
5686 25 Oct 19 olle 358     }
5686 25 Oct 19 olle 359     //alert("generate-referral-forms.js::itemNameOnChange(): itemName = " + itemName)
5686 25 Oct 19 olle 360 /*
5686 25 Oct 19 olle 361     if (!Meludi.isValidCaseName(caseName, true)) // Allow C/D suffix to be used
5686 25 Oct 19 olle 362     {
5686 25 Oct 19 olle 363       Wizard.setInputStatus('caseName', 'invalid', 'Only 7-digits name + optional \'C\' or \'D\' is allowed.');
5686 25 Oct 19 olle 364       frm.caseName.focus();
5686 25 Oct 19 olle 365       return;
5686 25 Oct 19 olle 366     }
5686 25 Oct 19 olle 367     // Check if pure case name < stored next pure case name
5686 25 Oct 19 olle 368     var currefStartCaseIdPure = caseName.substring(2);
5686 25 Oct 19 olle 369     if (currefStartCaseIdPure < refStartCaseIdPure)
5686 25 Oct 19 olle 370     {
5686 25 Oct 19 olle 371       var confirmMsg = 'Check to verify use of pure SCAN-B ID < ' + refStartCaseIdPure + ' (stored value).';
5686 25 Oct 19 olle 372       Wizard.showGoNextConfirmation(true, confirmMsg);
5686 25 Oct 19 olle 373       return;
5686 25 Oct 19 olle 374     }
5686 25 Oct 19 olle 375 */
5686 25 Oct 19 olle 376     Wizard.setInputStatus('itemName');
5686 25 Oct 19 olle 377     if (itemName == '')
5686 25 Oct 19 olle 378     {
5686 25 Oct 19 olle 379       Wizard.setInputStatus('itemName', 'invalid', 'Missing');
5686 25 Oct 19 olle 380       frm.itemName.focus();
5686 25 Oct 19 olle 381     }
5686 25 Oct 19 olle 382     else if (!Meludi.isValidCaseName2(itemName, referralPrefix, referralNumDigits))
5686 25 Oct 19 olle 383     {
5686 25 Oct 19 olle 384       Wizard.setInputStatus('itemName', 'invalid', 'Only name = "' + referralPrefix + '" + ' + referralNumDigits + ' digits is allowed.');
5686 25 Oct 19 olle 385       frm.itemName.focus();
5686 25 Oct 19 olle 386     }
5686 25 Oct 19 olle 387     else
5686 25 Oct 19 olle 388     {
5686 25 Oct 19 olle 389       Wizard.setInputStatus('itemName', 'valid');
5686 25 Oct 19 olle 390       itemIsValid = true;
5686 25 Oct 19 olle 391     }
5686 25 Oct 19 olle 392 /*
5686 25 Oct 19 olle 393     // Check if pure case name < stored next pure case name
5686 25 Oct 19 olle 394     var currefStartCaseIdPure = caseName.substring(2);
5686 25 Oct 19 olle 395     if (currefStartCaseIdPure < refStartCaseIdPure)
5686 25 Oct 19 olle 396     {
5686 25 Oct 19 olle 397       var confirmMsg = 'Check to verify use of pure SCAN-B ID < ' + refStartCaseIdPure + ' (stored value).';
5686 25 Oct 19 olle 398       Wizard.showGoNextConfirmation(true, confirmMsg);
5686 25 Oct 19 olle 399       return;
5686 25 Oct 19 olle 400     }
5686 25 Oct 19 olle 401 */
5686 25 Oct 19 olle 402
5686 25 Oct 19 olle 403     frm.itemName.value = itemName;
5686 25 Oct 19 olle 404     Wizard.setInputStatus('itemName', 'valid');
5686 25 Oct 19 olle 405     itemIsValid = true;
5686 25 Oct 19 olle 406     Doc.removeClass('gonext', 'disabled');
5686 25 Oct 19 olle 407   }
5686 25 Oct 19 olle 408
5686 25 Oct 19 olle 409   istat.validateStep2 = function(event)
5686 25 Oct 19 olle 410   {
5686 25 Oct 19 olle 411     var valid = true;
5686 25 Oct 19 olle 412     valid &= Wizard.isValid('itemName');
5686 25 Oct 19 olle 413     if (!valid) event.preventDefault();
5686 25 Oct 19 olle 414
5686 25 Oct 19 olle 415     istat.generateReferralForms();
5686 25 Oct 19 olle 416   }
5686 25 Oct 19 olle 417
5686 25 Oct 19 olle 418   istat.generateReferralForms = function()
5686 25 Oct 19 olle 419   {
5686 25 Oct 19 olle 420     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 421     //var refVariant = frm.referralvariant.value;
5686 25 Oct 19 olle 422     var refVariant = refVariantDefault;
5686 25 Oct 19 olle 423     var startItemName = frm.itemName.value;
5686 25 Oct 19 olle 424     var nofFormSets = frm.nofFormSets.value;
5686 25 Oct 19 olle 425
5686 25 Oct 19 olle 426     Doc.addClass('itemName', 'disabled');
5686 25 Oct 19 olle 427     Doc.addClass('nofFormSets', 'disabled');
5686 25 Oct 19 olle 428
5686 25 Oct 19 olle 429     Doc.hide('gonext');
5686 25 Oct 19 olle 430
5686 25 Oct 19 olle 431     var url = '../ReferralGenerator.servlet?ID='+App.getSessionId();
5686 25 Oct 19 olle 432     url += '&cmd=GenerateReferralForms';
5686 25 Oct 19 olle 433     url += '&referralvariant='+encodeURIComponent(refVariant);
5686 25 Oct 19 olle 434     url += '&startitemname='+encodeURIComponent(startItemName);
5686 25 Oct 19 olle 435     url += '&nofformsets='+encodeURIComponent(nofFormSets);
5686 25 Oct 19 olle 436
5686 25 Oct 19 olle 437     Wizard.showLoadingAnimation('Generating referral forms...', 'ref-gen-progress');
5686 25 Oct 19 olle 438     Wizard.asyncJsonRequest(url, istat.initializeStep3);
5686 25 Oct 19 olle 439 /*
5686 25 Oct 19 olle 440     // POST
5686 25 Oct 19 olle 441     Wizard.showLoadingAnimation('Generating referral forms...', 'ref-gen-progress');
5686 25 Oct 19 olle 442     Wizard.asyncJsonRequest(url, istat.initializeStep2, 'POST', formData);
5686 25 Oct 19 olle 443 */
5686 25 Oct 19 olle 444   }
5686 25 Oct 19 olle 445
5686 25 Oct 19 olle 446   istat.initializeStep3 = function(response)
5686 25 Oct 19 olle 447   {
5686 25 Oct 19 olle 448     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 449     Wizard.setCurrentStep(3);
5686 25 Oct 19 olle 450     Wizard.showFinalMessage(response.messages);
5686 25 Oct 19 olle 451
5686 25 Oct 19 olle 452     Doc.hide('gonext');
5686 25 Oct 19 olle 453     Doc.show('downloadformbatch1');
5686 25 Oct 19 olle 454     Doc.show('downloadformbatch2');
5686 25 Oct 19 olle 455     Doc.show('downloadlabelfile');
5686 25 Oct 19 olle 456     Doc.show('updateuseditemidlist');
5686 25 Oct 19 olle 457   
5686 25 Oct 19 olle 458     Doc.show('step-3');
5686 25 Oct 19 olle 459   }
5686 25 Oct 19 olle 460     
5686 25 Oct 19 olle 461   istat.initializeStep3a = function(response)
5686 25 Oct 19 olle 462   {
5686 25 Oct 19 olle 463     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 464     Wizard.setCurrentStep(3);
5686 25 Oct 19 olle 465     Wizard.showFinalMessage(response.messages);
5686 25 Oct 19 olle 466
5686 25 Oct 19 olle 467     Doc.show('gorestart');
5686 25 Oct 19 olle 468     Doc.hide('gonext');
5686 25 Oct 19 olle 469     Doc.show('downloadformbatch1');
5686 25 Oct 19 olle 470     Doc.show('downloadformbatch2');
5686 25 Oct 19 olle 471     Doc.show('downloadlabelfile');
5686 25 Oct 19 olle 472     Doc.show('updateuseditemidlist');
5686 25 Oct 19 olle 473     Doc.addClass('updateuseditemidlist', 'disabled');
5686 25 Oct 19 olle 474   
5686 25 Oct 19 olle 475     Doc.show('step-3');
5686 25 Oct 19 olle 476   }
5686 25 Oct 19 olle 477     
5686 25 Oct 19 olle 478   istat.downloadFormBatch1 = function()
5686 25 Oct 19 olle 479   {
5686 25 Oct 19 olle 480     istat.downloadFormBatch(1);
5686 25 Oct 19 olle 481   }
5686 25 Oct 19 olle 482
5686 25 Oct 19 olle 483   istat.downloadFormBatch2 = function()
5686 25 Oct 19 olle 484   {
5686 25 Oct 19 olle 485     istat.downloadFormBatch(2);
5686 25 Oct 19 olle 486   }
5686 25 Oct 19 olle 487
5686 25 Oct 19 olle 488   istat.downloadFormBatch = function(batchType)
5686 25 Oct 19 olle 489   {
5686 25 Oct 19 olle 490     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 491     var startItemName = frm.itemName.value;
5686 25 Oct 19 olle 492     var nofFormSets = frm.nofFormSets.value;
5686 25 Oct 19 olle 493
5686 25 Oct 19 olle 494     var url = '../ReferralGenerator.servlet?ID='+App.getSessionId();
5686 25 Oct 19 olle 495     url += '&cmd=DownloadFormBatchFile';
5686 25 Oct 19 olle 496     url += '&batchType='+batchType;
5686 25 Oct 19 olle 497     url += '&startitemname='+encodeURIComponent(startItemName);
5686 25 Oct 19 olle 498     url += '&nofformsets='+encodeURIComponent(nofFormSets);
5686 25 Oct 19 olle 499     window.open(url);
5686 25 Oct 19 olle 500   }
5686 25 Oct 19 olle 501
5686 25 Oct 19 olle 502   istat.downloadLabelFile = function()
5686 25 Oct 19 olle 503   {
5686 25 Oct 19 olle 504     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 505     var startItemName = frm.itemName.value;
5686 25 Oct 19 olle 506     var nofFormSets = frm.nofFormSets.value;
5686 25 Oct 19 olle 507     var preview = false;
5686 25 Oct 19 olle 508
5686 25 Oct 19 olle 509     var url = '../LabelGeneration.servlet?ID=' + App.getSessionId();
5686 25 Oct 19 olle 510     url += '&cmd=GetSerumLabelFile';
5686 25 Oct 19 olle 511     url += '&startitemname='+encodeURIComponent(startItemName);
5686 25 Oct 19 olle 512     url += '&nofformsets='+encodeURIComponent(nofFormSets);
5686 25 Oct 19 olle 513     url += '&preview=' + preview;
5686 25 Oct 19 olle 514     
5686 25 Oct 19 olle 515     if (preview) 
5686 25 Oct 19 olle 516     {
5686 25 Oct 19 olle 517       Doc.hide('previewWrapper');
5686 25 Oct 19 olle 518       url += '&preview=1';
5686 25 Oct 19 olle 519       
5686 25 Oct 19 olle 520       Wizard.showLoadingAnimation('Working...');
5686 25 Oct 19 olle 521       Doc.hide('navigation');
5686 25 Oct 19 olle 522       Wizard.asyncJsonRequest(url, istat.onPreviewLoaded);
5686 25 Oct 19 olle 523     }
5686 25 Oct 19 olle 524     else
5686 25 Oct 19 olle 525     {
5686 25 Oct 19 olle 526       //window.location = url;    
5686 25 Oct 19 olle 527       window.open(url);    
5686 25 Oct 19 olle 528     }
5686 25 Oct 19 olle 529   }
5686 25 Oct 19 olle 530
5686 25 Oct 19 olle 531   istat.updateUsedItemIdDigitsList = function()
5686 25 Oct 19 olle 532   {
5686 25 Oct 19 olle 533     var frm = document.forms['meludi'];
5686 25 Oct 19 olle 534     var startItemName = frm.itemName.value;
5686 25 Oct 19 olle 535     var nofFormSets = frm.nofFormSets.value;
5686 25 Oct 19 olle 536
5686 25 Oct 19 olle 537     var url = '../ReferralGenerator.servlet?ID='+App.getSessionId();
5686 25 Oct 19 olle 538     url += '&cmd=UpdateUsedItemIdDigitsList';
5686 25 Oct 19 olle 539     url += '&startitemname='+encodeURIComponent(startItemName);
5686 25 Oct 19 olle 540     url += '&nofformsets='+encodeURIComponent(nofFormSets);
5686 25 Oct 19 olle 541
5686 25 Oct 19 olle 542     Wizard.asyncJsonRequest(url, istat.initializeStep3a);
5686 25 Oct 19 olle 543   }
5686 25 Oct 19 olle 544
5686 25 Oct 19 olle 545   istat.selectOptionsDisabled = function(id, value)
5686 25 Oct 19 olle 546   {
5686 25 Oct 19 olle 547     var op = document.getElementById(id).getElementsByTagName('option');
5686 25 Oct 19 olle 548     for (var i = 0; i < op.length; i++)
5686 25 Oct 19 olle 549     {
5686 25 Oct 19 olle 550       op[i].disabled = value;
5686 25 Oct 19 olle 551     }
5686 25 Oct 19 olle 552   }
5686 25 Oct 19 olle 553
5686 25 Oct 19 olle 554   return istat;
5686 25 Oct 19 olle 555 }();
5686 25 Oct 19 olle 556
5686 25 Oct 19 olle 557 Doc.onLoad(Istat.initPage);
5686 25 Oct 19 olle 558