Changeset 1738


Ignore:
Timestamp:
Nov 20, 2012, 3:04:02 PM (9 years ago)
Author:
olle
Message:

Fixes #430. Refs #426. Consent count report updated to allow a time period to be selected. Results are now shown in two tables, one for consents with dates in the selected time period (plus a column for items, where the date is unknown), and one special table for items with unknown dates.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/samplereportgenerator.jsp

    r1737 r1738  
    6565    if (frm.reporttype[frm.reporttype.selectedIndex].value == 'samplecount')
    6666    {
    67       Main.show('sampleCountSection');
     67      // Set item name for report period text
     68      document.getElementById("items01").innerHTML="tubes";
     69      // Show view type pop-up menu
     70      document.getElementById("viewTypeSubSection01").style.display = 'block';
     71      document.getElementById("viewTypeSubSection02").style.display = 'block';
     72      document.getElementById("viewTypeSubSection04").style.display = 'block';
    6873    }
    6974    else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'consentcount')
    7075    {
    71       Main.show('consentCountSection');
    72     }
     76      // Set item name for report period text
     77      document.getElementById("items01").innerHTML="consents";
     78      // Hide view type pop-up menu
     79      document.getElementById("viewTypeSubSection01").style.display = 'none';
     80      document.getElementById("viewTypeSubSection02").style.display = 'none';
     81      document.getElementById("viewTypeSubSection04").style.display = 'none';
     82    }
     83    Main.show('itemCountSection');
    7384       
    7485    Main.show('gocreate');   
     
    132143    var cellElement = document.getElementById('reportcell');
    133144    var frm = document.forms['reggie'];   
     145    var reportType = frm.reporttype[frm.reporttype.selectedIndex].value;   
    134146    frm.fromdate.disabled = true;
    135147    frm.todate.disabled = true;
    136     frm.viewtype.disabled = true;
     148    if (reportType == 'samplecount')
     149    {
     150      frm.viewtype.disabled = true;
     151    }
    137152    Main.hide('gocreate');
    138153    Main.show('reportSection');
    139     var reportType = frm.reporttype[frm.reporttype.selectedIndex].value;   
    140154    var url = 'SampleReport.servlet?ID=<%=ID%>&cmd='+reportType;   
    141155   
     156    if (frm.fromdate.value != null) url += '&fdate='+frm.fromdate.value;
     157    if (frm.todate.value != null) url += '&tdate='+frm.todate.value;
    142158    if (reportType == 'samplecount')
    143159    {     
    144       if (frm.fromdate.value != null) url += '&fdate='+frm.fromdate.value;
    145       if (frm.todate.value != null) url += '&tdate='+frm.todate.value;
    146160      if (frm.viewtype.value != null) url += '&vtype='+frm.viewtype.value;
    147161    }
     162   
    148163    var request = Ajax.getXmlHttpRequest();
    149164    request.open("GET", url, false);
     
    182197    setInnerHTML('reportcell', '');
    183198    cellElement.appendChild(reportTable);
     199    // Optional extra tables
     200    if ('consentcount' == reportType)
     201    {
     202      var spacer = document.createElement('text');
     203      spacer.innerHTML = "<BR>";
     204      cellElement.appendChild(spacer);
     205      var unknownDateTable = createConsentCountUnknownDateTable(report);
     206      cellElement.appendChild(unknownDateTable);
     207    }
     208    // Summary list
    184209    var summaryList = document.createElement('ul');
    185210    if (unknownSite == null) unknownSite = 0;
     
    203228      }
    204229      summaryList.appendChild(getListElement(unknownSite + ' consents registered to unknown sites.'));
    205       summaryList.appendChild(getListElement(unknownCreation + ' consents without known date.'));
     230      summaryList.appendChild(getListElement(unknownCreation + ' consents without known date. These are included in the \'Total\' column.'));
    206231      summaryList.appendChild(getListElement(numDuplicates + ' duplicates ignored.'));
    207232
     
    418443  {
    419444    var reportTable = getReportTable();
    420 /*
    421445    var sdString = report.beginDate;
    422446    var edString = report.endDate;
     447/*
    423448    var psdString = report.periodBeginDate;
     449*/
    424450    var ldString = report.latestDate;
    425451    var startDate = new Date();
     
    431457    endDate.setMonth(edString.substr(4,2)-1);
    432458    endDate.setDate(edString.substr(6));
     459/*
    433460    var periodStartDate = new Date();
    434461    periodStartDate.setYear(psdString.substr(0,4));
    435462    periodStartDate.setMonth(psdString.substr(4,2)-1);
    436463    periodStartDate.setDate(psdString.substr(6));
     464*/
    437465    var latestDate;
    438466    if (ldString != null)
     
    443471      latestDate.setDate(ldString.substr(6));
    444472    }   
    445    
     473
     474/*   
    446475    var viewType = report.viewType;
    447476*/ 
     
    451480    var columnHeaderRow = document.createElement('tr');
    452481   
    453     var numCols = 8;
     482    var numCols = 5;
    454483    var numDecimals = 0;
    455484    var headerText = '# Consent forms of different types for cases and blood samples';
    456     headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+4)));
     485    var startDateStr = addHyphensToDateString(sdString);
     486    var endDateStr = addHyphensToDateString(edString);
     487    var latestDateStr = addHyphensToDateString(ldString);
     488    headerText += ' (betweeen ' + startDateStr + ' and ' + endDateStr + ')';
     489    if (latestDate != null)
     490    {
     491        headerText += '\nLast registration ' + latestDateStr;
     492    }
     493    headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+5)));
    457494   
    458495    // Subheader   
    459     subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
    460     subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 2));
    461    
    462     //subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
    463     subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
     496    subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 3));
     497   
    464498    subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
    465499    subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
    466500    subHeaderRow.appendChild(getTableCellElement('No', 'reportsubheader'));
    467     subHeaderRow.appendChild(getTableCellElement('No', 'reportsubheader'));
    468501    subHeaderRow.appendChild(getTableCellElement('Not asked', 'reportsubheader'));
    469     subHeaderRow.appendChild(getTableCellElement('Not asked', 'reportsubheader'));
    470     //subHeaderRow.appendChild(getTableCellElement('Other', 'reportsubheader'));
    471     subHeaderRow.appendChild(getTableCellElement('Missing', 'reportsubheader'));
    472     subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
    473     //subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
     502    subHeaderRow.appendChild(getTableCellElement('Unknown date', 'reportsubheader'));
     503    subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 2));
    474504
    475505    // Columnsheader   
     
    481511    columnHeaderRow.appendChild(latestDateHeader); 
    482512   
    483     //columnHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
    484     columnHeaderRow.appendChild(getTableCellElement('date, PAT#', 'reportsubheader'));
    485     columnHeaderRow.appendChild(getTableCellElement('date, no PAT#', 'reportsubheader'));
    486     columnHeaderRow.appendChild(getTableCellElement('no date', 'reportsubheader'));
    487     columnHeaderRow.appendChild(getTableCellElement('date', 'reportsubheader'));
    488     columnHeaderRow.appendChild(getTableCellElement('no date', 'reportsubheader'));
    489     columnHeaderRow.appendChild(getTableCellElement('date', 'reportsubheader'));
    490     columnHeaderRow.appendChild(getTableCellElement('no date', 'reportsubheader'));
    491     //columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
     513    columnHeaderRow.appendChild(getTableCellElement('(has PAT#)', 'reportsubheader'));
     514    columnHeaderRow.appendChild(getTableCellElement('(no PAT#)', 'reportsubheader'));
     515    columnHeaderRow.appendChild(getTableCellElement('(has date)', 'reportsubheader'));
     516    columnHeaderRow.appendChild(getTableCellElement('(has date)', 'reportsubheader'));
    492517    columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
    493518    columnHeaderRow.appendChild(getTableCellElement('Sum', 'reportsubheader'));
    494     //columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader'));
     519    columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader'));
    495520
    496521    // Build table     
     
    507532    sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary', 2));
    508533    // Get combined numbers for all sites for each period
     534    var noDateKey = 'noDate';
    509535    var sumKey = 'sumKey';
    510536    var statistics = report.statistics;
     
    512538    if (sitesCombined != null)
    513539    {
    514       //data = getJSONDataRightPadded(sitesCombined, 'yes', sumKey, numDecimals);
    515       //sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    516540      data = getJSONDataWithPercent(sitesCombined, 'yesPatient', sumKey, numDecimals);
    517541      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    518542      data = getJSONDataWithPercent(sitesCombined, 'yesNoPatient', sumKey, numDecimals);
    519543      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     544      data = getJSONDataWithPercent(sitesCombined, 'no', sumKey, numDecimals);
     545      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     546      data = getJSONDataWithPercent(sitesCombined, 'notAsked', sumKey, numDecimals);
     547      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     548      data = getJSONDataWithPercent(sitesCombined, noDateKey, sumKey, numDecimals);
     549      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     550    }
     551    // Add entry with total number of consents with chosen restrictions
     552    data = getJSONData(sitesCombined, sumKey);
     553    sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     554    // Add entry with total number of consents, regardless of restrictions
     555    var totalKey = 'totalKey';
     556    data = getJSONData(sitesCombined, totalKey);
     557    sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     558    reportTable.appendChild(sitesCombinedRow); 
     559
     560    return reportTable;
     561  }
     562 
     563  function createConsentCountUnknownDateTable(report)
     564  {
     565    var reportTable = getReportTable();
     566    var headerRow = document.createElement('tr');   
     567    var subHeaderRow = document.createElement('tr');
     568    var columnHeaderRow = document.createElement('tr');
     569   
     570    var numCols = 4;
     571    var numDecimals = 0;
     572    var headerText = '# Consent forms of different types for cases and blood samples, unknown consent date';
     573    headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+5)));
     574   
     575    // Subheader   
     576    subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 3));
     577   
     578    subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
     579    subHeaderRow.appendChild(getTableCellElement('No', 'reportsubheader'));
     580    subHeaderRow.appendChild(getTableCellElement('Not asked', 'reportsubheader'));
     581    subHeaderRow.appendChild(getTableCellElement('Missing', 'reportsubheader'));
     582    subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 2));
     583
     584    // Columnsheader   
     585    var siteHeader = getTableCellElement('Site', 'reportsubheader');     
     586    var startDateHeader = getTableCellElement('Start date','reportsubheader');
     587    var latestDateHeader = getTableCellElement('Latest date','reportsubheader');
     588    columnHeaderRow.appendChild(siteHeader);
     589    columnHeaderRow.appendChild(startDateHeader);
     590    columnHeaderRow.appendChild(latestDateHeader); 
     591   
     592    columnHeaderRow.appendChild(getTableCellElement('(no date)', 'reportsubheader'));
     593    columnHeaderRow.appendChild(getTableCellElement('(no date)', 'reportsubheader'));
     594    columnHeaderRow.appendChild(getTableCellElement('(no date)', 'reportsubheader'));
     595    columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
     596    columnHeaderRow.appendChild(getTableCellElement('Sum', 'reportsubheader'));
     597    columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader'));
     598
     599    // Build table     
     600    reportTable.appendChild(headerRow);
     601    reportTable.appendChild(subHeaderRow);
     602    reportTable.appendChild(columnHeaderRow);
     603         
     604    // Data rows     
     605    addDataRowsToConsentTableUnknownDate(report, reportTable);
     606     
     607    // Add a row with the combined numbers for all sites for each period
     608    var sitesCombinedRow = document.createElement('tr');
     609    sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary'));
     610    sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary', 2));
     611    // Get combined numbers for all sites for each period
     612    var sumKey = 'sumKey';
     613    var statistics = report.statistics;
     614    var sitesCombined = statistics.sitesCombinedKey;
     615    if (sitesCombined != null)
     616    {
    520617      data = getJSONDataWithPercent(sitesCombined, 'yesNoDate', sumKey, numDecimals);
    521       sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    522       data = getJSONDataWithPercent(sitesCombined, 'no', sumKey, numDecimals);
    523618      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    524619      data = getJSONDataWithPercent(sitesCombined, 'noNoDate', sumKey, numDecimals);
    525620      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    526       data = getJSONDataWithPercent(sitesCombined, 'notAsked', sumKey, numDecimals);
    527       sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    528621      data = getJSONDataWithPercent(sitesCombined, 'notAskedNoDate', sumKey, numDecimals);
    529622      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    530       //data = getJSONDataWithPercent(sitesCombined, 'other', sumKey, numDecimals);
    531       //sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    532623      data = getJSONDataWithPercent(sitesCombined, 'missing', sumKey, numDecimals);
    533624      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    534625    }
    535626    // Add entry with total number of consents with chosen restrictions
    536     data = getJSONData(sitesCombined, sumKey);
     627    var noDateKey = 'noDate';
     628    data = getJSONData(sitesCombined, noDateKey);
    537629    sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    538 /*
    539630    // Add entry with total number of consents, regardless of restrictions
     631    var totalKey = 'totalKey';
    540632    data = getJSONData(sitesCombined, totalKey);
    541633    sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    542 */
    543634    reportTable.appendChild(sitesCombinedRow); 
    544635
     
    546637  }
    547638 
     639  function addHyphensToDateString(yyyymmddStr)
     640  {
     641    var dateWithHyphensStr = '????-??-??';
     642    if (yyyymmddStr != null)
     643    {
     644      var yyyyStr = yyyymmddStr.substr(0,4);
     645      var mmStr   = yyyymmddStr.substr(4,2);
     646      var ddStr = yyyymmddStr.substr(6);
     647      dateWithHyphensStr = yyyyStr + '-' + mmStr + '-' + ddStr;
     648    }
     649    return dateWithHyphensStr;
     650  }
     651
    548652  function createConsentTablePatientsWithMultipleDates(report)
    549653  {
     
    645749      tableRow.appendChild(getTableCellElement(siteLatestDateStr, 'reportdata'));
    646750      //var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate());     
     751      var noDateKey = 'noDate';
    647752      var sumKey = 'sumKey';
     753      var totalKey = 'totalKey';
    648754      if (siteData != null)
    649755      {
    650         //data = getJSONDataWithPercent(siteData, 'yes', sumKey, numDecimals);
    651         //tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    652756        data = getJSONDataWithPercent(siteData, 'yesPatient', sumKey, numDecimals);
    653757        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    654758        data = getJSONDataWithPercent(siteData, 'yesNoPatient', sumKey, numDecimals);
    655759        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
     760        data = getJSONDataWithPercent(siteData, 'no', sumKey, numDecimals);
     761        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
     762        data = getJSONDataWithPercent(siteData, 'notAsked', sumKey, numDecimals);
     763        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
     764        data = getJSONDataWithPercent(siteData, noDateKey, sumKey, numDecimals);
     765        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
     766        // Add column with summed values for site
     767        var siteSum = getJSONData(siteData, sumKey, 0);
     768        tableRow.appendChild(getTableCellElement(siteSum, 'rowsummary'));
     769      }
     770      // Add column with total number of samples for site, regardless of creation date
     771      var siteTotal = getJSONData(siteData, totalKey, 0);
     772      tableRow.appendChild(getTableCellElement(siteTotal, 'rowsummary'));
     773      reportTable.appendChild(tableRow);
     774    }
     775  }
     776
     777  function addDataRowsToConsentTableUnknownDate(report, reportTable, numDecimals)
     778  {
     779    var sites = report.sites;   
     780    var statistics = report.statistics;
     781    unknownCreation = statistics.noDate;
     782    unknownSite = statistics.unknownSite;
     783    var siteOrderList = report.siteOrderListKey;
     784    for (var siteOrderIndex in siteOrderList)
     785    {
     786      var namePrefix = siteOrderList[siteOrderIndex];   
     787      if (!sites.hasOwnProperty(namePrefix)) continue;       
     788      var site = sites[namePrefix];
     789      var siteName = site.name;
     790      var year = site.startDate.substr(0,4);
     791      var month = site.startDate.substr(5,2);
     792      var date = site.startDate.substr(8,2);     
     793      var siteStartDate = new Date(year, month-1, date);
     794     
     795      var siteData = statistics[namePrefix];     
     796      var siteLatestDate = siteData['latestDateKey'];
     797      var siteLatestDateYear = siteLatestDate.substr(0,4);
     798      var siteLatestDateMonth = siteLatestDate.substr(4,2);
     799      var siteLatestDateDate = siteLatestDate.substr(6,2);
     800      var siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate;
     801      var tableRow = document.createElement('tr');
     802      var tableCol = getTableCellElement(siteName, 'rowtitle');
     803      tableRow.appendChild(tableCol);
     804      tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata'));
     805      tableRow.appendChild(getTableCellElement(siteLatestDateStr, 'reportdata'));
     806      //var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate());     
     807      var noDateKey = 'noDate';
     808      var sumKey = 'sumKey';
     809      var totalKey = 'totalKey';
     810      if (siteData != null)
     811      {
    656812        data = getJSONDataWithPercent(siteData, 'yesNoDate', sumKey, numDecimals);
    657         tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    658         data = getJSONDataWithPercent(siteData, 'no', sumKey, numDecimals);
    659813        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    660814        data = getJSONDataWithPercent(siteData, 'noNoDate', sumKey, numDecimals);
    661815        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    662         data = getJSONDataWithPercent(siteData, 'notAsked', sumKey, numDecimals);
    663         tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    664816        data = getJSONDataWithPercent(siteData, 'notAskedNoDate', sumKey, numDecimals);
    665817        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    666         //data = getJSONDataWithPercent(siteData, 'other', sumKey, numDecimals);
    667         //tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    668818        data = getJSONDataWithPercent(siteData, 'missing', sumKey, numDecimals);
    669819        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    670820        // Add column with summed values for site
    671         var siteSum = 0;
    672         if (siteData != null)
    673         {
    674           if (siteData[sumKey] != null)
    675           {
    676             siteSum = siteData[sumKey];
    677           }
    678         }
     821        var siteSum = getJSONData(siteData, noDateKey, 0);
    679822        tableRow.appendChild(getTableCellElement(siteSum, 'rowsummary'));
    680823      }
    681 /*
    682824      // Add column with total number of samples for site, regardless of creation date
    683       var siteTotal = 0;
    684       if (siteData != null)
    685       {
    686         var totalKey = 'totalKey';
    687         if (siteData[totalKey] != null)
    688         {
    689           siteTotal = siteData[totalKey];
    690         }
    691       }
     825      var siteTotal = getJSONData(siteData, totalKey, 0);
    692826      tableRow.appendChild(getTableCellElement(siteTotal, 'rowsummary'));
    693 */
    694827      reportTable.appendChild(tableRow);
    695828    }
     
    730863  function getJSONData(jsonObject, key)
    731864  {
    732     var data = '';
     865    var data = getJSONData(jsonObject, key, '');
     866    return data;
     867  }
     868
     869  function getJSONData(jsonObject, key, defaultChoice)
     870  {
     871    var data = defaultChoice;
    733872    if (jsonObject != null)
    734873    {
     
    738877      }
    739878    }
     879    /*
    740880    else
    741881    {
    742882      data = 'jsonObject==null';
    743883    }
     884    */
    744885    return data;
    745886  }
     
    11731314      </table>
    11741315     
    1175       <div id="sampleCountSection" style="display:none;">
     1316      <div id="itemCountSection" style="display:none;">
    11761317        <p></p>
    11771318        <!-- 2. Report parameters-->
     
    11931334              <td class="help">
    11941335                <span id="displayInterval.message" class="message" style="display: none;"></span>
    1195                 Define which period the report should cover. Empty fields will include all tubes.<br>
     1336                Define which period the report should cover. Empty fields will include all <text id="items01">items</text>.<br>
    11961337              </td>
    11971338            </tr>
    1198             <tr>         
    1199               <td valign="top" class="prompt">View type</td>
     1339            <tr>
     1340              <!--       
     1341              <td valign="top" class="prompt">View type subsection</td>
     1342              -->
     1343              <td valign="top" class="prompt">
     1344                <div id="viewTypeSubSection01" style="display:none;">
     1345                  View type subsection
     1346                </div>
     1347              </td>
    12001348              <td valign="top" class="input">
    1201                 <select name="viewtype">
    1202                   <option value="AUTO" selected="yes">Auto</option>
    1203                   <option value="WEEK">Week</option>
    1204                   <option value="MONTH">Month</option>
    1205                   <option value="QUARTER">Quarter</option>
    1206                   <option value="YEAR">Year</option>
    1207                 </select>
     1349                <div id="viewTypeSubSection02" style="display:none;">
     1350                  <select name="viewtype">
     1351                    <option value="AUTO" selected="yes">Auto</option>
     1352                    <option value="WEEK">Week</option>
     1353                    <option value="MONTH">Month</option>
     1354                    <option value="QUARTER">Quarter</option>
     1355                    <option value="YEAR">Year</option>
     1356                  </select>
     1357                </div>
    12081358              </td>
    12091359              <td valign="top" class="status" id="displayViewType.status"></td>
    12101360              <td class="help">
    1211                 <span id="displayViewType.message" class="message" style="display: none;"></span>
    1212                 Auto will adjust the report depending on the size of the period.
    1213                 <ul>
    1214                   <li>Period shorter then 3 months - specimens per week</li>
    1215                   <li>Period shorter then 13 months - specimens per month</li>
    1216                   <li>Period shorter then 3 year - specimens per quarter</li>
    1217                   <li>Period is 3 year or greater - specimens per year</li>
    1218                 </ul>                 
     1361                <div id="viewTypeSubSection04" style="display:none;">
     1362                  <span id="displayViewType.message" class="message" style="display: none;"></span>
     1363                  Auto will adjust the report depending on the size of the period.
     1364                  <ul>
     1365                    <li>Period shorter then 3 months - specimens per week</li>
     1366                    <li>Period shorter then 13 months - specimens per month</li>
     1367                    <li>Period shorter then 3 year - specimens per quarter</li>
     1368                    <li>Period is 3 year or greater - specimens per year</li>
     1369                  </ul>                 
     1370                </div>
    12191371              </td>
    12201372            </tr>
    1221             </table>
    1222           </td>
    1223         </tr>
    1224         </table>
    1225       </div>
    1226      
    1227       <div id="consentCountSection" style="display:none;">
    1228         <p></p>
    1229         <!-- 2. Report parameters-->
    1230         <table border="0" cellspacing="0" cellpadding="0" class="stepform">
    1231         <tr>
    1232           <td rowspan="3" class="stepno">2</td>
    1233           <td class="steptitle">Report parameters</td>
    1234         </tr>
    1235         <tr>
    1236           <td class="stepfields">
    1237             <table border="0" cellspacing="0" cellpadding="0" width="100%">           
    1238             <tr>
    1239               <td valign="top" class="prompt">No report parameters</td>
    1240               <td valign="top" class="input">
    1241               </td>
    1242               <td valign="top" class="status" id="displayInterval.status"></td>
    1243               <td class="help">
    1244                 <span id="displayInterval.message" class="message" style="display: none;"></span>
    1245                 Consent report will be generated irrespective of date for consent.<br>
    1246               </td>
    1247             </tr>
    12481373            </table>
    12491374          </td>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java

    r1737 r1738  
    122122      else if ("consentcount".equals(cmd))
    123123      {       
    124         json = createConsentCountReport(dc, json);
     124        String startDateParameter = Values.getString(req.getParameter("fdate"), null);
     125        String endDateParameter = Values.getString(req.getParameter("tdate"), null);
     126
     127        Date startDate = Reggie.CONVERTER_STRING_TO_DATE.convert(startDateParameter);
     128        Date endDate = Reggie.CONVERTER_STRING_TO_DATE.convert(endDateParameter);
     129       
     130        if (startDate == null)
     131        {
     132          // Get the when the first site started
     133          for (Site s : Site.getAllSites())
     134          {
     135            Date siteDate = Reggie.CONVERTER_STRING_TO_DATE.convert(s.getStartDate().replaceAll("-", ""));
     136            if (siteDate != null && (startDate == null || startDate.after(siteDate)))
     137            {
     138              startDate = siteDate;           
     139            }
     140          }
     141        }
     142        if (endDate == null)
     143        {
     144          // Get the date for today
     145          endDate = new Date();
     146        }
     147
     148        json = createConsentCountReport(dc, json, startDate, endDate);
    125149      }
    126150    }
     
    178202  }
    179203   
    180   private JSONObject createConsentCountReport(DbControl dc, JSONObject json)
     204  private JSONObject createConsentCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate)
    181205      throws ServletException, IOException
    182206  {
     
    231255    jsonStatistics = initializeJSONSiteData(jsonStatistics, otherKey);
    232256    jsonStatistics = initializeJSONSiteData(jsonStatistics, missingKey);
    233     //jsonStatistics = initializeJSONSiteData(jsonStatistics, sumKey);
    234     //jsonStatistics = initializeJSONSiteData(jsonStatistics, totalKey);
     257    jsonStatistics = initializeJSONSiteData(jsonStatistics, noDateKey);
     258    jsonStatistics = initializeJSONSiteData(jsonStatistics, sumKey);
     259    jsonStatistics = initializeJSONSiteData(jsonStatistics, totalKey);
    235260    // Initialize combined data to 0 for the different keys
    236261    jsonSitesCombined.put(yesKey, 0);
     
    244269    jsonSitesCombined.put(otherKey, 0);
    245270    jsonSitesCombined.put(missingKey, 0);
     271    jsonSitesCombined.put(noDateKey, 0);
    246272    jsonSitesCombined.put(sumKey, 0);
    247273    jsonSitesCombined.put(totalKey, 0);
     
    249275    jsonStatistics.put(noDateKey, 0);
    250276    jsonStatistics.put(duplicateKey, 0);
     277    Date latestDate = null;
    251278    // Create HashMap to keep track of processed dates for each patient
    252279    HashMap<String, Set<Date>>patientDateSetHashMap = new HashMap<String, Set<Date>>();
     
    279306        // Get consent date
    280307        Date consentDate = (Date) Annotationtype.CONSENT_DATE.getAnnotationValue(dc, manager, s);
    281         String key = missingKey;
     308        String key = null;
    282309        Boolean duplicate = false;
    283310        if (consent != null)
    284311        {
    285           if (consent.equals("Yes"))
    286           {
    287             key = yesKey;
     312          if (consentDate != null)
     313          {
    288314            // Check if a consent already exists for the same patient and date
    289             if (consentDate != null)
     315            // The parent is the 'Patient'
     316            BioMaterial patient = s.getParent();
     317            if (patient != null)
    290318            {
    291               // The parent is the 'Patient'
    292               BioMaterial patient = s.getParent();
    293               if (patient != null)
     319              // Store patient ID value
     320              jsonPatientnamePatientid = updateJSONItemnameItemid(jsonPatientnamePatientid, patient);
     321              String patientName = patient.getName();
     322              if (inStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate))
    294323              {
    295                 // Store patient ID value
    296                 jsonPatientnamePatientid = updateJSONItemnameItemid(jsonPatientnamePatientid, patient);
    297                 key = yesPatientKey;
    298                 String patientName = patient.getName();
    299                 if (inStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate))
     324                duplicate = true;
     325              }
     326              else
     327              {
     328                patientDateSetHashMap = updateStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate);
     329              }
     330            }
     331            if ((consentDate.after(startDate) || consentDate.equals(startDate)) &&
     332              (consentDate.before(endDate) || consentDate.equals(endDate)))
     333            {
     334              if (consent.equals("Yes"))
     335              {
     336                key = yesKey;
     337                if (patient != null)
    300338                {
    301                   duplicate = true;
     339                  key = yesPatientKey;
    302340                }
    303341                else
    304342                {
    305                   patientDateSetHashMap = updateStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate);
     343                  key = yesNoPatientKey;
    306344                }
     345              }
     346              else if (consent.equals("No"))
     347              {
     348                key = noKey;
     349              }
     350              else if (consent.equals("Not asked"))
     351              {
     352                key = notAskedKey;
    307353              }
    308354              else
    309355              {
    310                 key = yesNoPatientKey;
     356                key = otherKey;
    311357              }
     358              // Find out if current consent date is the latest so far.
     359              if (latestDate == null || latestDate.before(consentDate))
     360              {
     361                latestDate = consentDate;
     362              }
     363            }
     364          }
     365          else
     366          {
     367            if (consent.equals("Yes"))
     368            {
     369              key = yesNoDateKey;
     370            }
     371            else if (consent.equals("No"))
     372            {
     373              key = noNoDateKey;
     374            }
     375            else if (consent.equals("Not asked"))
     376            {
     377              key = notAskedNoDateKey;
    312378            }
    313379            else
    314380            {
    315               key = yesNoDateKey;
     381              key = otherKey;
    316382            }
    317383          }
    318           else if (consent.equals("No"))
    319           {
    320             key = noKey;
    321             // Check if consent date exists
    322             if (consentDate == null)
    323             {
    324               key = noNoDateKey;
    325             }
    326           }
    327           else if (consent.equals("Not asked"))
    328           {
    329             key = notAskedKey;
    330             // Check if consent date exists
    331             if (consentDate == null)
    332             {
    333               key = notAskedNoDateKey;
    334             }
    335           }
    336           else
    337           {
    338             key = otherKey;
    339           }
    340 
    341384          // Keep track of latest consent date for site
    342385          if (consentDate != null)
     
    349392          }
    350393        }
     394        else
     395        {
     396          key = missingKey;
     397        }
    351398        // Note that items with duplicate == false include missing consent items
    352399        if (!duplicate)
    353400        {
    354           // Update consent counters
    355           jsonSite = updateJSONObjectCounter(jsonSite, key);
    356           jsonSite = updateJSONObjectCounter(jsonSite, sumKey);
    357           jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, key);
    358           jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, sumKey);
     401          if (key != null)
     402          {
     403            // Update consent counters
     404            jsonSite = updateJSONObjectCounter(jsonSite, key);
     405            jsonSite = updateJSONObjectCounter(jsonSite, sumKey);
     406            jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, key);
     407            jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, sumKey);
     408          }
    359409          if (consentDate == null)
    360410          {
     411            // Include consents with unknown date
     412            jsonSite = updateJSONObjectCounter(jsonSite, noDateKey);
     413            jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, noDateKey);
    361414            jsonStatistics = updateJSONObjectCounter(jsonStatistics, noDateKey);
    362415          }
     416          // Increase the counter for total consents for the site, regardless of creation date
     417          jsonSite = updateJSONObjectCounter(jsonSite, totalKey);
     418
     419          // Increase the counter for total consents for all sites
     420          jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, totalKey);
    363421        }
    364422        else
     
    381439        jsonSite.put(latestDateKey, date2StringConverter.convert(siteLatestDate));
    382440    }
     441    // Add latest date for further transfer to other JSON object
     442    jsonStatistics.put(latestDateKey, date2StringConverter.convert(latestDate));
    383443    // Create JSONObject (patient, dates) for patients with multiple dates
    384444    JSONObject jsonPatientsWithMultipleDates = createJSONPatientsWithMultipleDates(patientDateSetHashMap);
     
    391451    //
    392452    jsonReport.put("statistics", jsonStatistics);       
     453    jsonReport.put("beginDate", date2StringConverter.convert(startDate));
     454    jsonReport.put("endDate", date2StringConverter.convert(endDate));
     455    // Transfer latest date from jsonStatistics to jsonReport
     456    String latestDateStr = (String) jsonStatistics.get("latestDateKey");
     457    jsonReport.put("latestDate", latestDateStr);
    393458    String siteOrder = alphabeticalOrder;
    394459    JSONObject jsonSiteOrderList = createJSONSiteOrderList(siteOrder);
Note: See TracChangeset for help on using the changeset viewer.