extensions/net.sf.basedb.reggie/trunk/resources/personal/export-monthly-oplist.js

Code
Comments
Other
Rev Date Author Line
2374 23 Apr 14 nicklas 1 var Xport = function()
2374 23 Apr 14 nicklas 2 {
2374 23 Apr 14 nicklas 3   var xport = {};
2374 23 Apr 14 nicklas 4   var previewTitle;
2374 23 Apr 14 nicklas 5   var previewList;
2374 23 Apr 14 nicklas 6   
2374 23 Apr 14 nicklas 7   xport.initPage = function()
2374 23 Apr 14 nicklas 8   {
2374 23 Apr 14 nicklas 9     previewTitle = Doc.element('previewTitle');
2374 23 Apr 14 nicklas 10     previewList = Doc.element('previewList');
2374 23 Apr 14 nicklas 11     
2374 23 Apr 14 nicklas 12     Buttons.addClickHandler('goexport', xport.goExport);
2374 23 Apr 14 nicklas 13     Buttons.addClickHandler('gopreview', xport.goPreview);
2603 27 Aug 14 nicklas 14     
2603 27 Aug 14 nicklas 15     Doc.show('step-1');
2603 27 Aug 14 nicklas 16     Doc.show('gopreview');
2603 27 Aug 14 nicklas 17     Doc.show('goexport');
2374 23 Apr 14 nicklas 18   }
2374 23 Apr 14 nicklas 19   
2374 23 Apr 14 nicklas 20   xport.goPreview = function()
2374 23 Apr 14 nicklas 21   {
2374 23 Apr 14 nicklas 22     xport.doExport(true);
2374 23 Apr 14 nicklas 23   }
2374 23 Apr 14 nicklas 24   
2374 23 Apr 14 nicklas 25   xport.goExport = function()
2374 23 Apr 14 nicklas 26   {
2374 23 Apr 14 nicklas 27     xport.doExport(false);
2374 23 Apr 14 nicklas 28   }
2374 23 Apr 14 nicklas 29   
2374 23 Apr 14 nicklas 30   xport.doExport = function(preview)
2374 23 Apr 14 nicklas 31   {
2374 23 Apr 14 nicklas 32     var frm = document.forms['reggie'];
2374 23 Apr 14 nicklas 33     var url = '../Export.servlet?ID='+App.getSessionId();
2374 23 Apr 14 nicklas 34     url += '&cmd=ExportMonthlyOpList';
2374 23 Apr 14 nicklas 35     url += '&time=' + frm.time.value;
2374 23 Apr 14 nicklas 36     url += '&exportSubtype=0';
2374 23 Apr 14 nicklas 37     url += '&exportPatientId=0';
2374 23 Apr 14 nicklas 38
2374 23 Apr 14 nicklas 39     if (preview) 
2374 23 Apr 14 nicklas 40     {
2374 23 Apr 14 nicklas 41       Doc.hide('previewWrapper');
2603 27 Aug 14 nicklas 42       url += '&preview=1';
2374 23 Apr 14 nicklas 43       
2603 27 Aug 14 nicklas 44       Wizard.showLoadingAnimation('Working...');
2603 27 Aug 14 nicklas 45       Doc.hide('navigation');
2603 27 Aug 14 nicklas 46       Wizard.asyncJsonRequest(url, xport.onPreviewLoaded);
2374 23 Apr 14 nicklas 47     }
2374 23 Apr 14 nicklas 48     else
2374 23 Apr 14 nicklas 49     {
2603 27 Aug 14 nicklas 50       window.location = url;
2374 23 Apr 14 nicklas 51     }
2374 23 Apr 14 nicklas 52   }
2374 23 Apr 14 nicklas 53
2603 27 Aug 14 nicklas 54   xport.onPreviewLoaded = function(response)
2374 23 Apr 14 nicklas 55   {
2603 27 Aug 14 nicklas 56     Doc.show('navigation');
2374 23 Apr 14 nicklas 57     var frm = document.forms['reggie'];
2603 27 Aug 14 nicklas 58     var allLines = response.split('\n');
2374 23 Apr 14 nicklas 59     var numCases = allLines.length - 2; // First line is a header line
2374 23 Apr 14 nicklas 60     
2374 23 Apr 14 nicklas 61     var html = '<tr><th>'+allLines[0].replace(/\t/g, '</th><th>')+'</th></tr>';
2374 23 Apr 14 nicklas 62     // Check last column for the 'Consent' value. All should be 'YES' for the export to be ok.
2374 23 Apr 14 nicklas 63     var numNoConsent = 0;
2374 23 Apr 14 nicklas 64     var numMissingConsent = 0;
2374 23 Apr 14 nicklas 65     for (var i = 1 ; i <= numCases; i++)
2374 23 Apr 14 nicklas 66     {
2374 23 Apr 14 nicklas 67       var line = allLines[i];
2374 23 Apr 14 nicklas 68       var cols = line.split(/\t/);
2374 23 Apr 14 nicklas 69       var consent = cols[cols.length-1];
2374 23 Apr 14 nicklas 70       var rowClass = '';
2374 23 Apr 14 nicklas 71       if (consent != 'YES')
2374 23 Apr 14 nicklas 72       {
2374 23 Apr 14 nicklas 73         rowClass = 'consent-warning';
2374 23 Apr 14 nicklas 74         if (consent == 'MISSING')
2374 23 Apr 14 nicklas 75         {
2374 23 Apr 14 nicklas 76           numMissingConsent++;
2374 23 Apr 14 nicklas 77         }
2374 23 Apr 14 nicklas 78         else
2374 23 Apr 14 nicklas 79         {
2374 23 Apr 14 nicklas 80           numNoConsent++;
2374 23 Apr 14 nicklas 81         }
2374 23 Apr 14 nicklas 82       }
2374 23 Apr 14 nicklas 83       html += '<tr class="'+rowClass+'"><td>'+cols.join('</td><td>')+'</td></tr>';
2374 23 Apr 14 nicklas 84     }
2374 23 Apr 14 nicklas 85     
2374 23 Apr 14 nicklas 86     var previewWarning = Doc.element('previewWarning');
2374 23 Apr 14 nicklas 87     if (numMissingConsent > 0 || numNoConsent > 0)
2374 23 Apr 14 nicklas 88     {
2374 23 Apr 14 nicklas 89       var warning = '<img src="../images/warning.png" alt="!">';
2374 23 Apr 14 nicklas 90       warning += ' Found ' + (numNoConsent+numMissingConsent) + ' case(s) with denied or missing consent!';
2374 23 Apr 14 nicklas 91       previewWarning.innerHTML = warning;
2374 23 Apr 14 nicklas 92     }
2374 23 Apr 14 nicklas 93     else
2374 23 Apr 14 nicklas 94     {
2374 23 Apr 14 nicklas 95       previewWarning.innerHTML = '';
2374 23 Apr 14 nicklas 96     }
2374 23 Apr 14 nicklas 97     
2374 23 Apr 14 nicklas 98     previewTitle.innerHTML = 'Operation dates - ' + frm.time[frm.time.selectedIndex].text + ' (' + numCases + ')';
2374 23 Apr 14 nicklas 99     previewList.innerHTML = '<table>'+html+'</table>';
2374 23 Apr 14 nicklas 100     Doc.show('previewWrapper');
2374 23 Apr 14 nicklas 101   }
2374 23 Apr 14 nicklas 102   
2374 23 Apr 14 nicklas 103   return xport;
2374 23 Apr 14 nicklas 104 }();
2374 23 Apr 14 nicklas 105
2374 23 Apr 14 nicklas 106 Doc.onLoad(Xport.initPage);
2374 23 Apr 14 nicklas 107