Changeset 1757


Ignore:
Timestamp:
Nov 28, 2012, 9:41:46 AM (9 years ago)
Author:
Nicklas Nordborg
Message:

Catching up on trunk revisions 1734 to 1756.

Location:
extensions/net.sf.basedb.reggie/branches/ticket-422
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/branches/ticket-422

  • extensions/net.sf.basedb.reggie/branches/ticket-422/.classpath

    r1745 r1757  
    66  <classpathentry kind="lib" path="lib/compile/json_simple-1.1.jar"/>
    77  <classpathentry kind="lib" path="lib/compile/jdom-1.1.2.jar"/>
    8   <classpathentry kind="lib" path="lib/compile/base-core-3.1.0.jar"/>
    9   <classpathentry kind="lib" path="lib/compile/base-webclient-3.1.0.jar"/>
    10   <classpathentry kind="lib" path="lib/compile/base-webservices-client-3.1.0.jar"/>
     8  <classpathentry kind="lib" path="lib/compile/base-core-3.2.0.jar"/>
     9  <classpathentry kind="lib" path="lib/compile/base-webclient-3.2.0.jar"/>
     10  <classpathentry kind="lib" path="lib/compile/base-webservices-client-3.2.0.jar"/>
    1111  <classpathentry kind="output" path=".build"/>
    1212</classpath>
  • extensions/net.sf.basedb.reggie/branches/ticket-422/META-INF/extensions.xml

    r1725 r1757  
    77      and samples.
    88    </description>
    9     <version>2.9-dev</version>
    10     <min-base-version>3.1.0</min-base-version>
     9    <version>2.10-dev</version>
     10    <min-base-version>3.2.0</min-base-version>
    1111    <copyright>BASE development team</copyright>
    1212    <email>basedb-users@lists.sourceforge.net</email>
  • extensions/net.sf.basedb.reggie/branches/ticket-422/README

    r1645 r1757  
    11== Requirements ==
    22
    3  1. BASE 3.1 or later.
     3 1. BASE 3.2 or later.
    44 
    55== Introduction ==
  • extensions/net.sf.basedb.reggie/branches/ticket-422/build.xml

    r1725 r1757  
    1010  <!-- variables used -->
    1111  <property name="name" value="reggie" />
    12   <property name="version" value="2.9-dev" />
     12  <property name="version" value="2.10-dev" />
    1313  <property name="src" location="src" description="Location of source files" />
    1414  <property name="build" location="build" description="Location of compiled files" />
     
    2222  <property name="javac.encoding" value="UTF-8" />
    2323  <property name="depend.base-version"
    24     value="3.1.0"
     24    value="3.2.0"
    2525    description="The BASE version that this project depends on."
    2626  />
  • extensions/net.sf.basedb.reggie/branches/ticket-422/resources/export_monthly_oplist.jsp

    r1721 r1757  
    4141  url += '&time=' + frm.time.value;
    4242  url += '&exportSubtype='+(frm.exportSubtype.checked ? 1 : 0);
     43  url += '&exportPatientId='+(frm.exportPatientId.checked ? 1 : 0);
    4344  if (preview)
    4445  {
     
    7273    {
    7374      var allLines = request.responseText.split('\n');
    74       var numLines = allLines.length - 1;
    75      
     75      var numCases = allLines.length - 2; // First line is a header line
     76     
     77      var html = '<tr><th>'+allLines[0].replace(/\t/g, '</th><th>')+'</th></tr>';
    7678      // Check last column for the 'Consent' value. All should be 'YES' for the export to be ok.
    7779      var numNoConsent = 0;
    7880      var numMissingConsent = 0;
    79       for (var i = 0 ; i < numLines; i++)
     81      for (var i = 1 ; i <= numCases; i++)
    8082      {
    8183        var line = allLines[i];
    82         var lastColIdx = line.lastIndexOf('\t');
    83         var lastCol = line.substr(lastColIdx+1);
    84        
    85         if (lastCol != 'YES')
     84        var cols = line.split(/\t/);
     85        var consent = cols[cols.length-1];
     86        var rowClass = '';
     87        if (consent != 'YES')
    8688        {
    87           if (lastCol == 'MISSING')
     89          rowClass = 'consent-warning';
     90          if (consent == 'MISSING')
    8891          {
    8992            numMissingConsent++;
     
    9396            numNoConsent++;
    9497          }
    95           allLines[i] = '<span class="consent-warning">'+line+'</span>';
    9698        }
     99        html += '<tr class="'+rowClass+'"><td>'+cols.join('</td><td>')+'</td></tr>';
    97100      }
    98101     
     
    105108      }
    106109     
    107       previewTitle.innerHTML = 'Operation dates - ' + frm.time[frm.time.selectedIndex].text + ' (' + numLines + ')';
    108       previewList.innerHTML = allLines.join('\n');
     110      previewTitle.innerHTML = 'Operation dates - ' + frm.time[frm.time.selectedIndex].text + ' (' + numCases + ')';
     111      previewList.innerHTML = '<table>'+html+'</table>';
    109112      Main.show('previewWrapper');
    110113    }
     
    128131{
    129132  position: absolute;
    130   top: 9em;
     133  top: 11em;
    131134  bottom: 1em;
    132135  left: 20px;
     
    155158}
    156159
     160#previewList th
     161{
     162  border-bottom: 1px dotted #A0A0A0;
     163}
     164
     165#previewList td, #previewList th
     166{
     167  text-align: left;
     168  padding-right: 2em;
     169  vertical-align: bottom;
     170}
     171
    157172.consent-warning
    158173{
    159   font-weight: bold;
    160174  color: #A00000;
    161175  background-color: #F8F8E8;
    162176}
    163177
    164 .consent-warning:after
    165 {
    166   content: url('images/warning_small.png');
    167   vertical-align: middle;
     178.consent-warning td:last-child
     179{
     180  background-image: url('images/warning_small.png');
     181  background-position: 95% 50%;
     182  background-repeat: no-repeat;
    168183}
    169184
     
    229244      </tr>
    230245     
    231       <tr>
     246      <tr style="vertical-align: top;">
    232247        <td class="prompt">Optional columns</td>
    233248        <td class="input">
    234249          <input type="checkbox" name="exportSubtype" value="1" id="exportSubtype">
    235           <label for="exportSubtype">Specimen/NoSpecimen</label>
     250          <label for="exportSubtype">Specimen/NoSpecimen</label><br>
     251          <input type="checkbox" name="exportPatientId" value="1" id="exportPatientId">
     252          <label for="exportPatientId">Patient ID</label>
    236253        </td>
    237254        <td class="help"><span id="subtype.message" class="message" style="display: none;"></span></td>
  • extensions/net.sf.basedb.reggie/branches/ticket-422/resources/index.jsp

    r1745 r1757  
    271271            <li>Sample count report</li>
    272272            <li>Consent count report</li>
     273            <li>Patient count report</li>
    273274            </ul>
    274275          </dd>
  • extensions/net.sf.basedb.reggie/branches/ticket-422/resources/samplereportgenerator.jsp

    r1732 r1757  
    6363    var frm = document.forms['reggie'];
    6464    frm.reporttype.disabled = true;
     65    // Hide sample type pop-up menu
     66    document.getElementById("sampleTypeSubSection01").style.display = 'none';
     67    document.getElementById("sampleTypeSubSection02").style.display = 'none';
     68    document.getElementById("sampleTypeSubSection04").style.display = 'none';
    6569    if (frm.reporttype[frm.reporttype.selectedIndex].value == 'samplecount')
    6670    {
    67       Main.show('sampleCountSection');
     71      // Set item name for report period text
     72      document.getElementById("items01").innerHTML="tubes";
     73      // Set item name for report time step text
     74      document.getElementById("items02").innerHTML="samples";
     75      document.getElementById("items03").innerHTML="samples";
     76      document.getElementById("items04").innerHTML="samples";
     77      document.getElementById("items05").innerHTML="samples";
     78      // Show view type pop-up menu
     79      document.getElementById("viewTypeSubSection01").style.display = 'block';
     80      document.getElementById("viewTypeSubSection02").style.display = 'block';
     81      document.getElementById("viewTypeSubSection04").style.display = 'block';
     82      // Show sample type pop-up menu
     83      document.getElementById("sampleTypeSubSection01").style.display = 'block';
     84      document.getElementById("sampleTypeSubSection02").style.display = 'block';
     85      document.getElementById("sampleTypeSubSection04").style.display = 'block';
    6886    }
    6987    else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'consentcount')
    7088    {
    71       Main.show('consentCountSection');
    72     }
     89      // Set item name for report period text
     90      document.getElementById("items01").innerHTML="consents";
     91      // Hide view type pop-up menu
     92      document.getElementById("viewTypeSubSection01").style.display = 'none';
     93      document.getElementById("viewTypeSubSection02").style.display = 'none';
     94      document.getElementById("viewTypeSubSection04").style.display = 'none';
     95    }
     96    else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'patientcount')
     97    {
     98      // Set item name for report period text
     99      document.getElementById("items01").innerHTML="patients";
     100      // Set item name for report time step text
     101      document.getElementById("items02").innerHTML="patients";
     102      document.getElementById("items03").innerHTML="patients";
     103      document.getElementById("items04").innerHTML="patients";
     104      document.getElementById("items05").innerHTML="patients";
     105      // Show view type pop-up menu
     106      document.getElementById("viewTypeSubSection01").style.display = 'block';
     107      document.getElementById("viewTypeSubSection02").style.display = 'block';
     108      document.getElementById("viewTypeSubSection04").style.display = 'block';
     109    }
     110    Main.show('itemCountSection');
    73111       
    74112    Main.show('gocreate');   
     
    132170    var cellElement = document.getElementById('reportcell');
    133171    var frm = document.forms['reggie'];   
     172    var reportType = frm.reporttype[frm.reporttype.selectedIndex].value;   
    134173    frm.fromdate.disabled = true;
    135174    frm.todate.disabled = true;
    136     frm.viewtype.disabled = true;
     175    var sampleType = frm.sampletype[frm.sampletype.selectedIndex].value;   
     176    if (reportType == 'samplecount')
     177    {
     178      frm.viewtype.disabled = true;
     179      frm.sampletype.disabled = true;
     180    }
     181    if (reportType == 'patientcount')
     182    {
     183      frm.viewtype.disabled = true;
     184    }
    137185    Main.hide('gocreate');
    138186    Main.show('reportSection');
    139     var reportType = frm.reporttype[frm.reporttype.selectedIndex].value;   
    140187    var url = 'SampleReport.servlet?ID=<%=ID%>&cmd='+reportType;   
    141188   
     189    if (frm.fromdate.value != null) url += '&fdate='+frm.fromdate.value;
     190    if (frm.todate.value != null) url += '&tdate='+frm.todate.value;
    142191    if (reportType == 'samplecount')
    143192    {     
    144       if (frm.fromdate.value != null) url += '&fdate='+frm.fromdate.value;
    145       if (frm.todate.value != null) url += '&tdate='+frm.todate.value;
    146193      if (frm.viewtype.value != null) url += '&vtype='+frm.viewtype.value;
    147     }
     194      if (frm.sampletype.value != null) url += '&stype='+frm.sampletype.value;
     195    }
     196    if (reportType == 'patientcount')
     197    {     
     198      if (frm.viewtype.value != null) url += '&vtype='+frm.viewtype.value;
     199    }
     200   
    148201    var request = Ajax.getXmlHttpRequest();
    149202    request.open("GET", url, false);
     
    164217      if ('samplecount' == reportType)
    165218      {     
    166         reportTable = createSampleCountReport(report);
     219        reportTable = createItemCountReport(report, reportType);
    167220      }
    168221      else if ('consentcount' == reportType)
    169222      {     
    170223        reportTable = createConsentCountReport(report);
     224      }
     225      if ('patientcount' == reportType)
     226      {     
     227        reportTable = createItemCountReport(report, reportType);
    171228      }
    172229    }
     
    182239    setInnerHTML('reportcell', '');
    183240    cellElement.appendChild(reportTable);
     241    // Optional extra tables
     242    if ('consentcount' == reportType)
     243    {
     244      var spacer = document.createElement('text');
     245      spacer.innerHTML = "<BR>";
     246      cellElement.appendChild(spacer);
     247      var unknownDateTable = createConsentCountUnknownDateTable(report);
     248      cellElement.appendChild(unknownDateTable);
     249    }
     250    // Summary list
    184251    var summaryList = document.createElement('ul');
    185252    if (unknownSite == null) unknownSite = 0;
    186253    if (unknownCreation == null) unknownCreation = 0;
    187254    if ('samplecount' == reportType)
    188     {     
    189       summaryList.appendChild(getListElement(unknownSite + ' specimens registered to unknown sites.'));
    190       summaryList.appendChild(getListElement(unknownCreation + ' specimens without creation date. These are included in the \'Total\' column.'));
     255    {
     256      var samples = 'specimens';
     257      if ('blood' == sampleType)
     258      {
     259        samples = 'blood samples';
     260      }
     261      summaryList.appendChild(getListElement(unknownSite + ' ' + samples + ' registered to unknown sites.'));
     262      summaryList.appendChild(getListElement(unknownCreation + ' ' + samples + ' without creation date. These are included in the \'Total\' column.'));
    191263    }
    192264    else if ('consentcount' == reportType)
     
    203275      }
    204276      summaryList.appendChild(getListElement(unknownSite + ' consents registered to unknown sites.'));
    205       summaryList.appendChild(getListElement(unknownCreation + ' consents without known date.'));
     277      summaryList.appendChild(getListElement(unknownCreation + ' consents without known date. These are included in the \'Total\' column.'));
    206278      summaryList.appendChild(getListElement(numDuplicates + ' duplicates ignored.'));
    207279
     
    215287      summaryList.appendChild(getListElement(patientsWithMultipleDatesText));
    216288    }
     289    else if ('patientcount' == reportType)
     290    {     
     291      summaryList.appendChild(getListElement(unknownSite + ' patients registered to unknown sites.'));
     292      summaryList.appendChild(getListElement(unknownCreation + ' patients without creation date. These are included in the \'Total\' column.'));
     293    }
    217294    cellElement.appendChild(summaryList);
    218295    if ('consentcount' == reportType)
     
    225302  }
    226303 
    227   function createSampleCountReport(report)
     304  function createItemCountReport(report, reportType)
    228305  {
    229306    var reportTable = getReportTable();
     
    254331   
    255332    var viewType = report.viewType;   
     333    var sampleType = report.sampleType;
    256334 
    257335    var headerRow = document.createElement('tr');   
     
    259337    var columnHeaderRow = document.createElement('tr');
    260338   
    261     var headerText = '# Specimen by ';
     339    var headerText = '# Items by ';
     340    if ('samplecount' == reportType)
     341    {
     342      headerText = '# Specimens by ';
     343      if ('blood' == sampleType)
     344      {
     345        headerText = '# Blood samples by ';
     346      }
     347    }
     348    else if ('patientcount' == reportType)
     349    {
     350      headerText = '# Patients by ';
     351    }
    262352    if (viewType == 'WEEK')
    263353    {
     
    280370    else if (viewType == 'QUARTER')
    281371    {
    282       //First year
     372      // First year (from start quarter to end of year)
    283373      numCols = 4 - Math.floor(periodStartDate.getMonth()/3);
     374      // Last year (from start of year to end quarter)
    284375      numCols += Math.floor(endDate.getMonth()/3)+1;
     376      // If first and last year is the same, subtract 4 quarters
     377      if (endDate.getFullYear() - periodStartDate.getFullYear() == 0)
     378      {
     379        numCols -= 4;
     380      }
     381      // Full years between start and end dates
    285382      if((endDate.getFullYear() - periodStartDate.getFullYear()) > 1)
    286383      {
     
    350447      headerText += latestDate.getDate();
    351448    }   
    352     headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+4)));
     449    headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+5)));
    353450   
    354451    // Sub headers
     
    356453    if (viewType != 'YEAR')
    357454    {
    358       subHeaderRowYear.appendChild(getTableCellElement('', 'reportsubheader', 2));
     455      subHeaderRowYear.appendChild(getTableCellElement('', 'reportsubheader', 3));
    359456      addYearSubHeaders(periodStartDate, endDate, subHeaderRowYear, viewType);     
    360457      subHeaderRowYear.appendChild(getTableCellElement('', 'reportsubheader', 2));
     
    364461    var siteHeader = getTableCellElement('Site', 'reportsubheader');     
    365462    var startDateHeader = getTableCellElement('Start date','reportsubheader');
     463    var latestDateHeader = getTableCellElement('Latest date','reportsubheader');
    366464    columnHeaderRow.appendChild(siteHeader);
    367465    columnHeaderRow.appendChild(startDateHeader);
     466    columnHeaderRow.appendChild(latestDateHeader); 
    368467   
    369468    if (viewType == 'MONTH') addMonthColumnHeaders(columnHeaderRow, periodStartDate);
     
    387486    var sitesCombinedRow = document.createElement('tr');
    388487    sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary'));
    389     sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary'));
     488    sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary', 2));
    390489    // Get combined numbers for all sites for each period
    391490    var statistics = report.statistics;
     
    396495    {
    397496      key = sortedKeyArray[arrayIndex];
    398       var data = getJSONData(sitesCombined, key);
     497      var data = getJSONData(sitesCombined, key, 0);
    399498      // Add entry with sample sum for site for selected time period
    400499      sitesCombinedRow.appendChild(getTableCellElement(data,'colsummary'));
    401500    }
    402501    // Get total number of samples for site for the selected time period
    403     var sum = statistics.sumKey;
     502    var sum = getJSONData(statistics, 'sumKey', 0);
    404503    // Add entry with total number of samples for site for the selected time period
    405504    sitesCombinedRow.appendChild(getTableCellElement(sum, 'colsummary'));
    406505    // Get total number of samples for all sites, regardless of creation date
    407     var total = statistics.totalKey;
     506    var total = getJSONData(statistics, 'totalKey', 0);
    408507    // Add entry with total number of samples for all sites, regardless of creation date
    409508    sitesCombinedRow.appendChild(getTableCellElement(total, 'colsummary'));
     
    416515  {
    417516    var reportTable = getReportTable();
    418 /*
    419517    var sdString = report.beginDate;
    420518    var edString = report.endDate;
     519/*
    421520    var psdString = report.periodBeginDate;
     521*/
    422522    var ldString = report.latestDate;
    423523    var startDate = new Date();
     
    429529    endDate.setMonth(edString.substr(4,2)-1);
    430530    endDate.setDate(edString.substr(6));
     531/*
    431532    var periodStartDate = new Date();
    432533    periodStartDate.setYear(psdString.substr(0,4));
    433534    periodStartDate.setMonth(psdString.substr(4,2)-1);
    434535    periodStartDate.setDate(psdString.substr(6));
     536*/
    435537    var latestDate;
    436538    if (ldString != null)
     
    441543      latestDate.setDate(ldString.substr(6));
    442544    }   
    443    
     545
     546/*   
    444547    var viewType = report.viewType;
    445548*/ 
     
    449552    var columnHeaderRow = document.createElement('tr');
    450553   
    451     var numCols = 8;
     554    var numCols = 5;
    452555    var numDecimals = 0;
    453556    var headerText = '# Consent forms of different types for cases and blood samples';
    454     headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+3)));
     557    var startDateStr = addHyphensToDateString(sdString);
     558    var endDateStr = addHyphensToDateString(edString);
     559    var latestDateStr = addHyphensToDateString(ldString);
     560    headerText += ' (betweeen ' + startDateStr + ' and ' + endDateStr + ')';
     561    if (latestDate != null)
     562    {
     563        headerText += '\nLast registration ' + latestDateStr;
     564    }
     565    headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+5)));
    455566   
    456567    // Subheader   
    457     subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
    458     subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
    459    
    460     //subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
    461     subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
     568    subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 3));
     569   
    462570    subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
    463571    subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
    464572    subHeaderRow.appendChild(getTableCellElement('No', 'reportsubheader'));
    465     subHeaderRow.appendChild(getTableCellElement('No', 'reportsubheader'));
    466573    subHeaderRow.appendChild(getTableCellElement('Not asked', 'reportsubheader'));
    467     subHeaderRow.appendChild(getTableCellElement('Not asked', 'reportsubheader'));
    468     //subHeaderRow.appendChild(getTableCellElement('Other', 'reportsubheader'));
    469     subHeaderRow.appendChild(getTableCellElement('Missing', 'reportsubheader'));
    470     subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
    471     //subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
     574    subHeaderRow.appendChild(getTableCellElement('Unknown date', 'reportsubheader'));
     575    subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 2));
    472576
    473577    // Columnsheader   
    474578    var siteHeader = getTableCellElement('Site', 'reportsubheader');     
    475579    var startDateHeader = getTableCellElement('Start date','reportsubheader');
     580    var latestDateHeader = getTableCellElement('Latest date','reportsubheader');
    476581    columnHeaderRow.appendChild(siteHeader);
    477582    columnHeaderRow.appendChild(startDateHeader);
    478    
    479     //columnHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
    480     columnHeaderRow.appendChild(getTableCellElement('date, PAT#', 'reportsubheader'));
    481     columnHeaderRow.appendChild(getTableCellElement('date, no PAT#', 'reportsubheader'));
    482     columnHeaderRow.appendChild(getTableCellElement('no date', 'reportsubheader'));
    483     columnHeaderRow.appendChild(getTableCellElement('date', 'reportsubheader'));
    484     columnHeaderRow.appendChild(getTableCellElement('no date', 'reportsubheader'));
    485     columnHeaderRow.appendChild(getTableCellElement('date', 'reportsubheader'));
    486     columnHeaderRow.appendChild(getTableCellElement('no date', 'reportsubheader'));
    487     //columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
     583    columnHeaderRow.appendChild(latestDateHeader); 
     584   
     585    columnHeaderRow.appendChild(getTableCellElement('(has PAT#)', 'reportsubheader'));
     586    columnHeaderRow.appendChild(getTableCellElement('(no PAT#)', 'reportsubheader'));
     587    columnHeaderRow.appendChild(getTableCellElement('(has date)', 'reportsubheader'));
     588    columnHeaderRow.appendChild(getTableCellElement('(has date)', 'reportsubheader'));
    488589    columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
    489590    columnHeaderRow.appendChild(getTableCellElement('Sum', 'reportsubheader'));
    490     //columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader'));
     591    columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader'));
    491592
    492593    // Build table     
     
    501602    var sitesCombinedRow = document.createElement('tr');
    502603    sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary'));
    503     sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary'));
     604    sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary', 2));
     605    // Get combined numbers for all sites for each period
     606    var noDateKey = 'noDate';
     607    var sumKey = 'sumKey';
     608    var statistics = report.statistics;
     609    var sitesCombined = statistics.sitesCombinedKey;
     610    if (sitesCombined != null)
     611    {
     612      data = getJSONDataWithPercent(sitesCombined, 'yesPatient', sumKey, numDecimals);
     613      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     614      data = getJSONDataWithPercent(sitesCombined, 'yesNoPatient', sumKey, numDecimals);
     615      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     616      data = getJSONDataWithPercent(sitesCombined, 'no', sumKey, numDecimals);
     617      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     618      data = getJSONDataWithPercent(sitesCombined, 'notAsked', sumKey, numDecimals);
     619      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     620      data = getJSONDataWithPercent(sitesCombined, noDateKey, sumKey, numDecimals);
     621      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     622    }
     623    // Add entry with total number of consents with chosen restrictions
     624    data = getJSONData(sitesCombined, sumKey, 0);
     625    sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     626    // Add entry with total number of consents, regardless of restrictions
     627    var totalKey = 'totalKey';
     628    data = getJSONData(sitesCombined, totalKey, 0);
     629    sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     630    reportTable.appendChild(sitesCombinedRow); 
     631
     632    return reportTable;
     633  }
     634 
     635  function createConsentCountUnknownDateTable(report)
     636  {
     637    var reportTable = getReportTable();
     638    var headerRow = document.createElement('tr');   
     639    var subHeaderRow = document.createElement('tr');
     640    var columnHeaderRow = document.createElement('tr');
     641   
     642    var numCols = 4;
     643    var numDecimals = 0;
     644    var headerText = '# Consent forms of different types for cases and blood samples, unknown consent date';
     645    headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+5)));
     646   
     647    // Subheader   
     648    subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 3));
     649   
     650    subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader'));
     651    subHeaderRow.appendChild(getTableCellElement('No', 'reportsubheader'));
     652    subHeaderRow.appendChild(getTableCellElement('Not asked', 'reportsubheader'));
     653    subHeaderRow.appendChild(getTableCellElement('Missing', 'reportsubheader'));
     654    subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 2));
     655
     656    // Columnsheader   
     657    var siteHeader = getTableCellElement('Site', 'reportsubheader');     
     658    var startDateHeader = getTableCellElement('Start date','reportsubheader');
     659    var latestDateHeader = getTableCellElement('Latest date','reportsubheader');
     660    columnHeaderRow.appendChild(siteHeader);
     661    columnHeaderRow.appendChild(startDateHeader);
     662    columnHeaderRow.appendChild(latestDateHeader); 
     663   
     664    columnHeaderRow.appendChild(getTableCellElement('(no date)', 'reportsubheader'));
     665    columnHeaderRow.appendChild(getTableCellElement('(no date)', 'reportsubheader'));
     666    columnHeaderRow.appendChild(getTableCellElement('(no date)', 'reportsubheader'));
     667    columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
     668    columnHeaderRow.appendChild(getTableCellElement('Sum', 'reportsubheader'));
     669    columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader'));
     670
     671    // Build table     
     672    reportTable.appendChild(headerRow);
     673    reportTable.appendChild(subHeaderRow);
     674    reportTable.appendChild(columnHeaderRow);
     675         
     676    // Data rows     
     677    addDataRowsToConsentTableUnknownDate(report, reportTable);
     678     
     679    // Add a row with the combined numbers for all sites for each period
     680    var sitesCombinedRow = document.createElement('tr');
     681    sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary'));
     682    sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary', 2));
    504683    // Get combined numbers for all sites for each period
    505684    var sumKey = 'sumKey';
     
    508687    if (sitesCombined != null)
    509688    {
    510       //data = getJSONDataRightPadded(sitesCombined, 'yes', sumKey, numDecimals);
    511       //sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    512       data = getJSONDataWithPercent(sitesCombined, 'yesPatient', sumKey, numDecimals);
    513       sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    514       data = getJSONDataWithPercent(sitesCombined, 'yesNoPatient', sumKey, numDecimals);
    515       sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    516689      data = getJSONDataWithPercent(sitesCombined, 'yesNoDate', sumKey, numDecimals);
    517       sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    518       data = getJSONDataWithPercent(sitesCombined, 'no', sumKey, numDecimals);
    519690      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    520691      data = getJSONDataWithPercent(sitesCombined, 'noNoDate', sumKey, numDecimals);
    521692      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    522       data = getJSONDataWithPercent(sitesCombined, 'notAsked', sumKey, numDecimals);
    523       sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    524693      data = getJSONDataWithPercent(sitesCombined, 'notAskedNoDate', sumKey, numDecimals);
    525694      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    526       //data = getJSONDataWithPercent(sitesCombined, 'other', sumKey, numDecimals);
    527       //sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    528695      data = getJSONDataWithPercent(sitesCombined, 'missing', sumKey, numDecimals);
    529696      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    530697    }
    531698    // Add entry with total number of consents with chosen restrictions
    532     data = getJSONData(sitesCombined, sumKey);
     699    var noDateKey = 'noDate';
     700    data = getJSONData(sitesCombined, noDateKey, 0);
    533701    sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    534 /*
    535702    // Add entry with total number of consents, regardless of restrictions
    536     data = getJSONData(sitesCombined, totalKey);
     703    var totalKey = 'totalKey';
     704    data = getJSONData(sitesCombined, totalKey, 0);
    537705    sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    538 */
    539706    reportTable.appendChild(sitesCombinedRow); 
    540707
     
    542709  }
    543710 
     711  function addHyphensToDateString(yyyymmddStr)
     712  {
     713    var dateWithHyphensStr = '????-??-??';
     714    if (yyyymmddStr != null)
     715    {
     716      var yyyyStr = yyyymmddStr.substr(0,4);
     717      var mmStr   = yyyymmddStr.substr(4,2);
     718      var ddStr = yyyymmddStr.substr(6);
     719      dateWithHyphensStr = yyyyStr + '-' + mmStr + '-' + ddStr;
     720    }
     721    return dateWithHyphensStr;
     722  }
     723
    544724  function createConsentTablePatientsWithMultipleDates(report)
    545725  {
     
    617797    unknownCreation = statistics.noDate;
    618798    unknownSite = statistics.unknownSite;
    619     for (namePrefix in sites)
    620     {
     799    var siteOrderList = report.siteOrderListKey;
     800    for (var siteOrderIndex in siteOrderList)
     801    {
     802      var namePrefix = siteOrderList[siteOrderIndex];   
    621803      if (!sites.hasOwnProperty(namePrefix)) continue;       
    622804      var site = sites[namePrefix];
     
    628810     
    629811      var siteData = statistics[namePrefix];     
     812      var siteLatestDate = siteData['latestDateKey'];
     813      var siteLatestDateYear = siteLatestDate.substr(0,4);
     814      var siteLatestDateMonth = siteLatestDate.substr(4,2);
     815      var siteLatestDateDate = siteLatestDate.substr(6,2);
     816      var siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate;
    630817      var tableRow = document.createElement('tr');
    631818      var tableCol = getTableCellElement(siteName, 'rowtitle');
    632819      tableRow.appendChild(tableCol);
    633820      tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata'));
     821      tableRow.appendChild(getTableCellElement(siteLatestDateStr, 'reportdata'));
    634822      //var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate());     
     823      var noDateKey = 'noDate';
    635824      var sumKey = 'sumKey';
     825      var totalKey = 'totalKey';
    636826      if (siteData != null)
    637827      {
    638         //data = getJSONDataWithPercent(siteData, 'yes', sumKey, numDecimals);
    639         //tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    640828        data = getJSONDataWithPercent(siteData, 'yesPatient', sumKey, numDecimals);
    641829        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    642830        data = getJSONDataWithPercent(siteData, 'yesNoPatient', sumKey, numDecimals);
    643831        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
     832        data = getJSONDataWithPercent(siteData, 'no', sumKey, numDecimals);
     833        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
     834        data = getJSONDataWithPercent(siteData, 'notAsked', sumKey, numDecimals);
     835        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
     836        data = getJSONDataWithPercent(siteData, noDateKey, sumKey, numDecimals);
     837        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
     838        // Add column with summed values for site
     839        var siteSum = getJSONData(siteData, sumKey, 0);
     840        tableRow.appendChild(getTableCellElement(siteSum, 'rowsummary'));
     841      }
     842      // Add column with total number of samples for site, regardless of creation date
     843      var siteTotal = getJSONData(siteData, totalKey, 0);
     844      tableRow.appendChild(getTableCellElement(siteTotal, 'rowsummary'));
     845      reportTable.appendChild(tableRow);
     846    }
     847  }
     848
     849  function addDataRowsToConsentTableUnknownDate(report, reportTable, numDecimals)
     850  {
     851    var sites = report.sites;   
     852    var statistics = report.statistics;
     853    unknownCreation = statistics.noDate;
     854    unknownSite = statistics.unknownSite;
     855    var siteOrderList = report.siteOrderListKey;
     856    for (var siteOrderIndex in siteOrderList)
     857    {
     858      var namePrefix = siteOrderList[siteOrderIndex];   
     859      if (!sites.hasOwnProperty(namePrefix)) continue;       
     860      var site = sites[namePrefix];
     861      var siteName = site.name;
     862      var year = site.startDate.substr(0,4);
     863      var month = site.startDate.substr(5,2);
     864      var date = site.startDate.substr(8,2);     
     865      var siteStartDate = new Date(year, month-1, date);
     866     
     867      var siteData = statistics[namePrefix];     
     868      var siteLatestDate = siteData['latestDateKey'];
     869      var siteLatestDateYear = siteLatestDate.substr(0,4);
     870      var siteLatestDateMonth = siteLatestDate.substr(4,2);
     871      var siteLatestDateDate = siteLatestDate.substr(6,2);
     872      var siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate;
     873      var tableRow = document.createElement('tr');
     874      var tableCol = getTableCellElement(siteName, 'rowtitle');
     875      tableRow.appendChild(tableCol);
     876      tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata'));
     877      tableRow.appendChild(getTableCellElement(siteLatestDateStr, 'reportdata'));
     878      //var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate());     
     879      var noDateKey = 'noDate';
     880      var sumKey = 'sumKey';
     881      var totalKey = 'totalKey';
     882      if (siteData != null)
     883      {
    644884        data = getJSONDataWithPercent(siteData, 'yesNoDate', sumKey, numDecimals);
    645         tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    646         data = getJSONDataWithPercent(siteData, 'no', sumKey, numDecimals);
    647885        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    648886        data = getJSONDataWithPercent(siteData, 'noNoDate', sumKey, numDecimals);
    649887        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    650         data = getJSONDataWithPercent(siteData, 'notAsked', sumKey, numDecimals);
    651         tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    652888        data = getJSONDataWithPercent(siteData, 'notAskedNoDate', sumKey, numDecimals);
    653889        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    654         //data = getJSONDataWithPercent(siteData, 'other', sumKey, numDecimals);
    655         //tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    656890        data = getJSONDataWithPercent(siteData, 'missing', sumKey, numDecimals);
    657891        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    658892        // Add column with summed values for site
    659         var siteSum = 0;
    660         if (siteData != null)
    661         {
    662           if (siteData[sumKey] != null)
    663           {
    664             siteSum = siteData[sumKey];
    665           }
    666         }
     893        var siteSum = getJSONData(siteData, noDateKey, 0);
    667894        tableRow.appendChild(getTableCellElement(siteSum, 'rowsummary'));
    668895      }
    669 /*
    670896      // Add column with total number of samples for site, regardless of creation date
    671       var siteTotal = 0;
    672       if (siteData != null)
    673       {
    674         var totalKey = 'totalKey';
    675         if (siteData[totalKey] != null)
    676         {
    677           siteTotal = siteData[totalKey];
    678         }
    679       }
     897      var siteTotal = getJSONData(siteData, totalKey, 0);
    680898      tableRow.appendChild(getTableCellElement(siteTotal, 'rowsummary'));
    681 */
    682899      reportTable.appendChild(tableRow);
    683900    }
     
    718935  function getJSONData(jsonObject, key)
    719936  {
    720     var data = '';
     937    var data = getJSONData(jsonObject, key, '');
     938    return data;
     939  }
     940
     941  function getJSONData(jsonObject, key, defaultChoice)
     942  {
     943    var data = defaultChoice;
    721944    if (jsonObject != null)
    722945    {
     
    726949      }
    727950    }
     951    /*
    728952    else
    729953    {
    730954      data = 'jsonObject==null';
    731955    }
     956    */
    732957    return data;
    733958  }
     
    8851110    unknownCreation = statistics.noDate;
    8861111    unknownSite = statistics.unknownSite;
    887     for (namePrefix in sites)
    888     {
    889       if (!sites.hasOwnProperty(namePrefix)) continue;       
     1112    var siteOrderList = report.siteOrderListKey;
     1113    for (var siteOrderIndex in siteOrderList)
     1114    {
     1115      var namePrefix = siteOrderList[siteOrderIndex];   
     1116      if (!sites.hasOwnProperty(namePrefix)) continue;
    8901117      var site = sites[namePrefix];
    891       var siteName = site.name;      
     1118      var siteName = site.name;   
    8921119      var year = site.startDate.substr(0,4);
    8931120      var month = site.startDate.substr(5,2);
     
    8951122      var siteStartDate = new Date(year, month-1, date);
    8961123     
    897       var siteData = statistics[namePrefix];     
     1124      var siteData = statistics[namePrefix];
     1125      var siteLatestDate = siteData['latestDateKey'];
     1126      var siteLatestDateStr = '????-??-??';
     1127      if (siteLatestDate != null)
     1128      {
     1129        var siteLatestDateYear = siteLatestDate.substr(0,4);
     1130        var siteLatestDateMonth = siteLatestDate.substr(4,2);
     1131        var siteLatestDateDate = siteLatestDate.substr(6,2);
     1132        siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate;
     1133      }
     1134/*
     1135      var siteLatestDateYear = siteLatestDate.substr(0,4);
     1136      var siteLatestDateMonth = siteLatestDate.substr(4,2);
     1137      var siteLatestDateDate = siteLatestDate.substr(6,2);
     1138      var siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate;
     1139*/
    8981140      var tableRow = document.createElement('tr');
    8991141      var tableCol = getTableCellElement(siteName, 'rowtitle');
    9001142      tableRow.appendChild(tableCol);
    9011143      tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata'));
     1144      tableRow.appendChild(getTableCellElement(siteLatestDateStr, 'reportdata'));
    9021145      var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate());     
    9031146      var columnCounter = 0;
     
    11401383                <option value="samplecount" selected="yes">Sample count report</option>
    11411384                <option value="consentcount">Consent count report</option>
     1385                <option value="patientcount">Patient count report</option>
    11421386              </select>
    11431387            </td>
     
    11531397      </table>
    11541398     
    1155       <div id="sampleCountSection" style="display:none;">
     1399      <div id="itemCountSection" style="display:none;">
    11561400        <p></p>
    11571401        <!-- 2. Report parameters-->
     
    11731417              <td class="help">
    11741418                <span id="displayInterval.message" class="message" style="display: none;"></span>
    1175                 Define which period the report should cover. Empty fields will include all tubes.<br>
     1419                Define which period the report should cover. Empty fields will include all <text id="items01">items</text>.<br>
    11761420              </td>
    11771421            </tr>
    1178             <tr>         
    1179               <td valign="top" class="prompt">View type</td>
     1422            <tr>
     1423              <td valign="top" class="prompt">
     1424                <div id="viewTypeSubSection01" style="display:none;">
     1425                  View type
     1426                </div>
     1427              </td>
    11801428              <td valign="top" class="input">
    1181                 <select name="viewtype">
    1182                   <option value="AUTO" selected="yes">Auto</option>
    1183                   <option value="WEEK">Week</option>
    1184                   <option value="MONTH">Month</option>
    1185                   <option value="QUARTER">Quarter</option>
    1186                   <option value="YEAR">Year</option>
    1187                 </select>
     1429                <div id="viewTypeSubSection02" style="display:none;">
     1430                  <select name="viewtype">
     1431                    <option value="AUTO" selected="yes">Auto</option>
     1432                    <option value="WEEK">Week</option>
     1433                    <option value="MONTH">Month</option>
     1434                    <option value="QUARTER">Quarter</option>
     1435                    <option value="YEAR">Year</option>
     1436                  </select>
     1437                </div>
    11881438              </td>
    11891439              <td valign="top" class="status" id="displayViewType.status"></td>
    11901440              <td class="help">
    1191                 <span id="displayViewType.message" class="message" style="display: none;"></span>
    1192                 Auto will adjust the report depending on the size of the period.
    1193                 <ul>
    1194                   <li>Period shorter then 3 months - specimens per week</li>
    1195                   <li>Period shorter then 13 months - specimens per month</li>
    1196                   <li>Period shorter then 3 year - specimens per quarter</li>
    1197                   <li>Period is 3 year or greater - specimens per year</li>
    1198                 </ul>                 
     1441                <div id="viewTypeSubSection04" style="display:none;">
     1442                  <span id="displayViewType.message" class="message" style="display: none;"></span>
     1443                  Auto will adjust the report depending on the size of the period.
     1444                  <ul>
     1445                    <li>Period shorter than 3 months - <text id="items02">items</text> per week</li>
     1446                    <li>Period shorter than 13 months - <text id="items03">items</text> per month</li>
     1447                    <li>Period shorter than 3 years - <text id="items04">items</text> per quarter</li>
     1448                    <li>Period is 3 years or greater - <text id="items05">items</text> per year</li>
     1449                  </ul>                 
     1450                </div>
    11991451              </td>
    12001452            </tr>
    1201             </table>
    1202           </td>
    1203         </tr>
    1204         </table>
    1205       </div>
    1206      
    1207       <div id="consentCountSection" style="display:none;">
    1208         <p></p>
    1209         <!-- 2. Report parameters-->
    1210         <table border="0" cellspacing="0" cellpadding="0" class="stepform">
    1211         <tr>
    1212           <td rowspan="3" class="stepno">2</td>
    1213           <td class="steptitle">Report parameters</td>
    1214         </tr>
    1215         <tr>
    1216           <td class="stepfields">
    1217             <table border="0" cellspacing="0" cellpadding="0" width="100%">           
    12181453            <tr>
    1219               <td valign="top" class="prompt">No report parameters</td>
     1454              <td valign="top" class="prompt">
     1455                <div id="sampleTypeSubSection01" style="display:none;">
     1456                  Sample type
     1457                </div>
     1458              </td>
    12201459              <td valign="top" class="input">
     1460                <div id="sampleTypeSubSection02" style="display:none;">
     1461                  <select name="sampletype">
     1462                    <option value="specimen" selected="yes">Specimen</option>
     1463                    <option value="blood">Blood</option>
     1464                  </select>
     1465                </div>
    12211466              </td>
    1222               <td valign="top" class="status" id="displayInterval.status"></td>
     1467              <td valign="top" class="status" id="displaySampleType.status"></td>
    12231468              <td class="help">
    1224                 <span id="displayInterval.message" class="message" style="display: none;"></span>
    1225                 Consent report will be generated irrespective of date for consent.<br>
     1469                <div id="sampleTypeSubSection04" style="display:none;">
     1470                  <span id="displaySampleType.message" class="message" style="display: none;"></span>
     1471                  Select sample type for report.
     1472                </div>
    12261473              </td>
    1227             </tr> 
     1474            </tr>
    12281475            </table>
    12291476          </td>
  • extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/Reggie.java

    r1725 r1757  
    3030    The current version of this package.
    3131  */
    32   public static final String VERSION = "2.9-dev";
     32  public static final String VERSION = "2.10-dev";
    3333
    3434 
  • extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/Site.java

    r1722 r1757  
    2020  public static final Site LUND         = new Site("11", "Lund", "2010-11-10", true);
    2121  public static final Site HELSINGBORG  = new Site("22", "Helsingborg", "2010-11-01", true);
    22   public static final Site HALMSTAD     = new Site("33", "Halmstad", "2010-10-01", false);
     22  public static final Site HALMSTAD     = new Site("33", "Halmstad", "2010-10-01", true);
    2323  public static final Site KRISTIANSTAD = new Site("44", "Kristianstad", "2010-09-15", true);
    24   public static final Site KARLSKRONA   = new Site("55", "Karlskrona", "2010-10-04", false);
    25   public static final Site VÄXJÖ        = new Site("66", "Växjö", "2010-10-01", false);
     24  public static final Site KARLSKRONA   = new Site("55", "Karlskrona", "2010-10-04", true);
     25  public static final Site VÄXJÖ        = new Site("66", "Växjö", "2010-10-01", true);
    2626  public static final Site MALMÖ        = new Site("77", "Malmö", "2010-08-30", true);
    2727 
  • extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/dao/Blood.java

    r1625 r1757  
    187187  }
    188188 
    189 
    190   public String getName()
    191   {
    192     return getSample().getName();
    193   }
    194  
    195189  /**
    196190    Verify that the patient has given their permission to participate in the
  • extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/plugins/CaliperRunParametersExporter.java

    r1610 r1757  
    233233   
    234234  }
     235  @Override
    235236  protected void end(boolean success)
    236237  {
    237238    this.dc = null;
    238239  }
     240  @Override
    239241  protected String getSuccessMessage()
    240242  {
  • extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/plugins/CaliperSampleNameExporter.java

    r1610 r1757  
    199199   
    200200  }
     201  @Override
    201202  protected void end(boolean success)
    202203  {
    203204    this.dc = null;
    204205  }
     206  @Override
    205207  protected String getSuccessMessage()
    206208  {
  • extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/servlet/BloodRegistrationServlet.java

    r1623 r1757  
    1717import net.sf.basedb.core.AnnotationType;
    1818import net.sf.basedb.core.Application;
     19import net.sf.basedb.core.BioMaterialEvent;
    1920import net.sf.basedb.core.BioSource;
    2021import net.sf.basedb.core.DbControl;
     
    195196        blood.setItemSubtype(Subtype.BLOOD.load(dc));
    196197        blood.setName(bloodName);
    197         blood.getCreationEvent().setSource(patient);
     198        BioMaterialEvent creationEvent = blood.getCreationEvent();
     199        creationEvent.setSource(patient);
    198200        dc.saveItem(blood);
    199201
     
    203205        String bloodSample = Values.getStringOrNull((String)jsonBlood.get("bloodSample"));
    204206       
    205         if (samplingDate != null) Annotationtype.BLOOD_SAMPLING_DATETIME.setAnnotationValue(dc, blood, samplingDate);
    206         if (freezerDate != null) Annotationtype.BLOOD_FREEZER_DATETIME.setAnnotationValue(dc, blood, freezerDate);
     207        creationEvent.setEventDate(samplingDate);
     208        Annotationtype.BLOOD_SAMPLING_DATETIME.setAnnotationValue(dc, blood, samplingDate);
     209        Annotationtype.BLOOD_FREEZER_DATETIME.setAnnotationValue(dc, blood, freezerDate);
    207210        Annotationtype.BLOOD_SERUM.setAnnotationValue(dc, blood, jsonBlood.get("serum"));
    208211        Annotationtype.BLOOD_SAMPLE.setAnnotationValue(dc, blood, bloodSample);
     
    237240        String bloodSample = Values.getStringOrNull((String)jsonBlood.get("bloodSample"));
    238241       
    239         if (samplingDate != null) Annotationtype.BLOOD_SAMPLING_DATETIME.setAnnotationValue(dc, blood, samplingDate);
    240         if (freezerDate != null) Annotationtype.BLOOD_FREEZER_DATETIME.setAnnotationValue(dc, blood, freezerDate);
     242        blood.getCreationEvent().setEventDate(samplingDate);
     243       
     244        Annotationtype.BLOOD_SAMPLING_DATETIME.setAnnotationValue(dc, blood, samplingDate);
     245        Annotationtype.BLOOD_FREEZER_DATETIME.setAnnotationValue(dc, blood, freezerDate);
    241246        Annotationtype.BLOOD_SERUM.setAnnotationValue(dc, blood, jsonBlood.get("serum"));
    242247        Annotationtype.BLOOD_SAMPLE.setAnnotationValue(dc, blood, bloodSample);
  • extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/servlet/ExportServlet.java

    r1721 r1757  
    6060      {
    6161        boolean exportSubtype = Values.getBoolean(req.getParameter("exportSubtype"));
     62        boolean exportPatientId = Values.getBoolean(req.getParameter("exportPatientId"));
    6263       
    6364        // This can be any time point in the desired month/year
     
    142143                  String opDate = dateFormat.format(s.getCreationEvent().getEventDate());
    143144                  String subtype = exportSubtype ? s.getItemSubtype().getName() : null;
     145                  String patientId = exportPatientId ? patient.getName() : null;
    144146                  String caseName = caseNamePattern.matcher(s.getName()).replaceFirst("");
    145                   opDates.add(new PersonalOpDate(pnr, opDate, site, laterality, subtype, caseName, consent));
     147                  opDates.add(new PersonalOpDate(pnr, opDate, site, laterality, subtype, caseName, consent, patientId));
    146148                }
    147149              }
     
    155157        resp.setCharacterEncoding("UTF-8");
    156158        PrintWriter os = resp.getWriter();
    157        
     159        os.write("PersonalNr\tScanBId\tOpDate\tLaterality\tSite");
     160        if (exportSubtype) os.write("\tSpecimen");
     161        if (exportPatientId) os.write("\tPatientId");
     162        os.write("\tConsent\n");
     163
    158164        for (PersonalOpDate pop : opDates)
    159165        {
     
    188194    private final String caseName;
    189195    private final String consent;
    190    
    191     PersonalOpDate(String pnr, String opDate, Site site, String laterality, String subtype, String caseName, String consent)
     196    private final String patientId;
     197   
     198    PersonalOpDate(String pnr, String opDate, Site site, String laterality, String subtype, String caseName, String consent, String patientId)
    192199    {
    193200      this.pnr = pnr;
     
    198205      this.caseName = caseName;
    199206      this.consent = consent;
     207      this.patientId = patientId;
    200208    }
    201209   
     
    203211    public String toString()
    204212    {
    205       return pnr + "\t" + caseName + "\t" + opDate + "\t" +
    206           (laterality == null ? "" : laterality) + "\t" +
    207           site.getName() +
    208           (subtype==null ? "" : "\t" + subtype) + "\t" +
    209           (consent == null ? "MISSING" : consent.toUpperCase());
     213      return pnr + "\t" + caseName + "\t" + opDate +
     214          "\t" + (laterality == null ? "" : laterality) +
     215          "\t" + site.getName() +
     216          (subtype==null ? "" : "\t" + subtype) +
     217          (patientId==null ? "" : "\t"+patientId)+
     218          "\t" + (consent == null ? "MISSING" : consent.toUpperCase());
    210219    }
    211220
  • extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java

    r1732 r1757  
    1010import java.util.List;
    1111import java.util.HashSet;
     12import java.util.Iterator;
    1213import java.util.Set;
     14import java.util.TreeMap;
    1315
    1416import javax.servlet.ServletException;
     
    2325import net.sf.basedb.core.ItemQuery;
    2426import net.sf.basedb.core.ItemResultIterator;
     27import net.sf.basedb.core.ItemSubtype;
     28import net.sf.basedb.core.MeasuredBioMaterial;
    2529import net.sf.basedb.core.Sample;
    2630import net.sf.basedb.core.SessionControl;
     
    5357  private static final int quarterViewLimit= 3;
    5458 
     59  private static final String alphabeticalOrder = "ALPHABETICAL_ORDER";
     60  private static final String namePrefixOrder = "NAME_PREFIX_ORDER";
     61  private static final String startDateOrder = "START_DATE_ORDER";
     62  private static final String nameLengthOrder = "NAME_LENGTH_ORDER";
     63
    5564  public SampleReportServlet()
    5665  {}
     
    111120          viewType = getViewType(startDate, endDate);
    112121        }
    113 
    114         json = createSampleCountReport(dc, json, startDate, endDate, viewType);
     122        String sampleType = "specimen";
     123        String sampleTypeParameter = Values.getString(req.getParameter("stype"), null);
     124        if (sampleTypeParameter != null)
     125        {
     126          sampleType = sampleTypeParameter;
     127        }
     128
     129        json = createSampleCountReport(dc, json, startDate, endDate, viewType, sampleType);
    115130      }
    116131      else if ("consentcount".equals(cmd))
    117132      {       
    118         json = createConsentCountReport(dc, json);
     133        String startDateParameter = Values.getString(req.getParameter("fdate"), null);
     134        String endDateParameter = Values.getString(req.getParameter("tdate"), null);
     135
     136        Date startDate = Reggie.CONVERTER_STRING_TO_DATE.convert(startDateParameter);
     137        Date endDate = Reggie.CONVERTER_STRING_TO_DATE.convert(endDateParameter);
     138       
     139        if (startDate == null)
     140        {
     141          // Get the when the first site started
     142          for (Site s : Site.getAllSites())
     143          {
     144            Date siteDate = Reggie.CONVERTER_STRING_TO_DATE.convert(s.getStartDate().replaceAll("-", ""));
     145            if (siteDate != null && (startDate == null || startDate.after(siteDate)))
     146            {
     147              startDate = siteDate;           
     148            }
     149          }
     150        }
     151        if (endDate == null)
     152        {
     153          // Get the date for today
     154          endDate = new Date();
     155        }
     156
     157        json = createConsentCountReport(dc, json, startDate, endDate);
     158      }
     159      else if ("patientcount".equals(cmd))
     160      {       
     161        String startDateParameter = Values.getString(req.getParameter("fdate"), null);
     162        String endDateParameter = Values.getString(req.getParameter("tdate"), null);
     163
     164        Date startDate = Reggie.CONVERTER_STRING_TO_DATE.convert(startDateParameter);
     165        Date endDate = Reggie.CONVERTER_STRING_TO_DATE.convert(endDateParameter);
     166       
     167        if (startDate == null)
     168        {
     169          // Get the when the first site started
     170          for (Site s : Site.getAllSites())
     171          {
     172            Date siteDate = Reggie.CONVERTER_STRING_TO_DATE.convert(s.getStartDate().replaceAll("-", ""));
     173            if (siteDate != null && (startDate == null || startDate.after(siteDate)))
     174            {
     175              startDate = siteDate;           
     176            }
     177          }
     178        }
     179        if (endDate == null)
     180        {
     181          // Get the date for today
     182          endDate = new Date();
     183        }
     184
     185        String viewType = null;
     186        String viewTypeParameter = Values.getString(req.getParameter("vtype"), null);
     187        if (viewTypeParameter != null && !viewTypeParameter.equals("AUTO"))
     188        {
     189          viewType = viewTypeParameter;
     190        }
     191        else
     192        {
     193          viewType = getViewType(startDate, endDate);
     194        }
     195
     196        json = createPatientCountReport(dc, json, startDate, endDate, viewType);
    119197      }
    120198    }
     
    134212  }
    135213 
    136   private JSONObject createSampleCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String viewType)
     214  @SuppressWarnings("unchecked")
     215  private JSONObject createSampleCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String viewType, String sampleType)
    137216    throws ServletException, IOException
    138217  {
     
    143222    ItemQuery<Sample> sampleQuery = Sample.getQuery();
    144223    sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true));
    145     Subtype.SPECIMEN.addFilter(dc, sampleQuery);
     224    if (sampleType.equals("blood"))
     225    {
     226      Subtype.BLOOD.addFilter(dc, sampleQuery);
     227    }
     228    else
     229    {
     230      Subtype.SPECIMEN.addFilter(dc, sampleQuery);
     231    }
     232    sampleQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     233    sampleQuery.order(Orders.asc(Hql.property("name")));
     234    sampleQuery.order(Orders.asc(Hql.property("ce", "eventDate")));
     235    sampleQuery.setCacheResult(true);
     236    ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc);       
     237    // Store samples that should be processed for report table in list
     238    List<Sample> sampleList = new ArrayList<Sample>();
     239    while (sampleIterator.hasNext())
     240    {
     241      Sample s = sampleIterator.next();
     242      sampleList.add(s);
     243    }
     244                 
     245    JSONObject jsonStatistics = createJSONStatistics(sampleList.iterator(), startDate, endDate, viewType);
     246    jsonReport.put("statistics", jsonStatistics);       
     247    if (viewType == null)
     248    {
     249      viewType = getViewType(startDate, endDate);
     250    }
     251    DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING;
     252    Date periodStartDate = calculatePeriodStartDate(startDate, viewType);
     253    jsonReport.put("viewType", viewType);
     254    jsonReport.put("sampleType", sampleType);
     255    jsonReport.put("beginDate", date2StringConverter.convert(startDate));
     256    jsonReport.put("endDate", date2StringConverter.convert(endDate));
     257    jsonReport.put("periodBeginDate", date2StringConverter.convert(periodStartDate));
     258    // Transfer latest date from jsonStatistics to jsonReport
     259    String latestDateStr = (String) jsonStatistics.get("latestDateKey");
     260    jsonReport.put("latestDate", latestDateStr);
     261    String siteOrder = alphabeticalOrder;
     262    JSONObject jsonSiteOrderList = createJSONSiteOrderList(siteOrder);
     263    jsonReport.put("siteOrderListKey", jsonSiteOrderList);
     264    json.put("report", jsonReport);
     265    return json;
     266  }
     267   
     268  @SuppressWarnings({ "unchecked", "rawtypes" })
     269  private JSONObject createPatientCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String viewType)
     270    throws ServletException, IOException
     271  {
     272    JSONObject jsonReport = new JSONObject();
     273    jsonReport.put("sites", getJSONSites());
     274   
     275    ItemQuery<Sample> sampleQuery = Sample.getQuery();
     276    sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true));
     277    // ...only include 'Specimen', 'No Specimen', or 'Blood' items
     278    sampleQuery.restrict(
     279      Restrictions.or(
     280        Subtype.SPECIMEN.restriction(dc, null),
     281        Subtype.NO_SPECIMEN.restriction(dc, null),
     282        Subtype.BLOOD.restriction(dc, null)
     283      ));
    146284    sampleQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    147285    sampleQuery.order(Orders.asc(Hql.property("name")));
     
    150288    ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc);       
    151289                 
    152     JSONObject jsonStatistics = createJSONStatistics(sampleIterator, startDate, endDate, viewType);
     290    // Store samples that should be processed for report table in list
     291    List<Sample> sampleList = new ArrayList<Sample>();
     292    // Create HashMap to keep track of sample with earliest date for each patient
     293    HashMap<String, Sample>patientSampleHashMap = new HashMap<String, Sample>();
     294    // Create HashMap to keep track of sample with unknown date for each patient
     295    HashMap<String, Sample>patientSampleNoDateHashMap = new HashMap<String, Sample>();
     296    // Find earliest sample dates for each patient
     297    ItemSubtype subtypeBlood = Subtype.BLOOD.load(dc);
     298    while (sampleIterator.hasNext())
     299    {
     300      Sample s = sampleIterator.next();
     301      BioMaterialEvent creationEvent = s.getCreationEvent();
     302      Date creationDate = creationEvent.getEventDate();
     303
     304      // Find patient id
     305      BioMaterial patient = null;
     306      if (s.getItemSubtype().equals(subtypeBlood))
     307      {
     308        // The parent is the 'Patient' for blood samples
     309        patient = s.getParent();
     310      }
     311      else
     312      {
     313        // The grandparent is the 'Patient' for specimens and no specimens
     314        MeasuredBioMaterial parent = (MeasuredBioMaterial) s.getParent();
     315        if (parent != null)
     316        {
     317          patient = parent.getParent();
     318        }
     319      }
     320      if (patient != null)
     321      {
     322        String patientName = patient.getName();
     323        if (creationDate != null)
     324        {
     325          patientSampleHashMap = updateStringEarliestSampleHashMap(patientSampleHashMap, patientName, s);
     326        }
     327        else
     328        {
     329          patientSampleNoDateHashMap.put(patientName, s);
     330        }
     331      }
     332    }
     333    // Create list of samples for report
     334    // Add sample with earliest date for patient
     335    for (String key: patientSampleHashMap.keySet())
     336    {
     337      if (key != null && !key.equals(""))
     338      {
     339        Sample s = patientSampleHashMap.get(key);
     340        // Include sample in list of samples for report
     341        sampleList.add(s);
     342      }
     343    }
     344    // Add sample with unknown date if no sample with date exists for patient
     345    for (String key: patientSampleNoDateHashMap.keySet())
     346    {
     347      if (key != null && !key.equals(""))
     348      {
     349        // If no sample with date exists for sample, include sample without date
     350        if (!patientSampleHashMap.containsKey(key))
     351        {
     352          Sample s = patientSampleNoDateHashMap.get(key);
     353          // Include sample in list of samples for report
     354          sampleList.add(s);
     355        }
     356      }
     357    }
     358
     359    JSONObject jsonStatistics = createJSONStatistics(sampleList.iterator(), startDate, endDate, viewType);
    153360    jsonReport.put("statistics", jsonStatistics);       
    154361    if (viewType == null)
     
    165372    String latestDateStr = (String) jsonStatistics.get("latestDateKey");
    166373    jsonReport.put("latestDate", latestDateStr);
     374    String siteOrder = alphabeticalOrder;
     375    JSONObject jsonSiteOrderList = createJSONSiteOrderList(siteOrder);
     376    jsonReport.put("siteOrderListKey", jsonSiteOrderList);
    167377    json.put("report", jsonReport);
    168378    return json;
    169379  }
    170380   
    171   private JSONObject createConsentCountReport(DbControl dc, JSONObject json)
     381  @SuppressWarnings({ "unchecked", "rawtypes" })
     382  private JSONObject createConsentCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate)
    172383      throws ServletException, IOException
    173384  {
     
    207418    String sumKey = "sumKey";
    208419    String totalKey = "totalKey";
     420    String latestDateKey = "latestDateKey";
    209421    String noDateKey = "noDate";
    210422    String duplicateKey = "duplicateKey";
     
    221433    jsonStatistics = initializeJSONSiteData(jsonStatistics, otherKey);
    222434    jsonStatistics = initializeJSONSiteData(jsonStatistics, missingKey);
    223     //jsonStatistics = initializeJSONSiteData(jsonStatistics, sumKey);
    224     //jsonStatistics = initializeJSONSiteData(jsonStatistics, totalKey);
     435    jsonStatistics = initializeJSONSiteData(jsonStatistics, noDateKey);
     436    jsonStatistics = initializeJSONSiteData(jsonStatistics, sumKey);
     437    jsonStatistics = initializeJSONSiteData(jsonStatistics, totalKey);
    225438    // Initialize combined data to 0 for the different keys
    226439    jsonSitesCombined.put(yesKey, 0);
     
    234447    jsonSitesCombined.put(otherKey, 0);
    235448    jsonSitesCombined.put(missingKey, 0);
     449    jsonSitesCombined.put(noDateKey, 0);
    236450    jsonSitesCombined.put(sumKey, 0);
    237451    jsonSitesCombined.put(totalKey, 0);
     
    239453    jsonStatistics.put(noDateKey, 0);
    240454    jsonStatistics.put(duplicateKey, 0);
     455    Date latestDate = null;
    241456    // Create HashMap to keep track of processed dates for each patient
    242457    HashMap<String, Set<Date>>patientDateSetHashMap = new HashMap<String, Set<Date>>();
    243458    JSONObject jsonPatientnamePatientid = new JSONObject();
     459    // Create HashMap to keep track of latest consent date for each site
     460    HashMap<String, Date> sitePrefixDateHashMap = new HashMap<String, Date>();
    244461    while (sampleIterator.hasNext())
    245462    {
    246463      Sample s = sampleIterator.next();
     464/*
    247465      BioMaterialEvent creationEvent = s.getCreationEvent();
    248466      Date creationDate = creationEvent.getEventDate();
     467*/
    249468             
    250469      Site site = Site.findByCaseName(s.getName());
     
    267486        // Get consent date
    268487        Date consentDate = (Date) Annotationtype.CONSENT_DATE.getAnnotationValue(dc, manager, s);
    269         String key = missingKey;
     488        String key = null;
    270489        Boolean duplicate = false;
    271490        if (consent != null)
    272491        {
    273           if (consent.equals("Yes"))
    274           {
    275             key = yesKey;
     492          if (consentDate != null)
     493          {
    276494            // Check if a consent already exists for the same patient and date
    277             if (consentDate != null)
     495            // The parent is the 'Patient'
     496            BioMaterial patient = s.getParent();
     497            if (patient != null)
    278498            {
    279               // The parent is the 'Patient'
    280               BioMaterial patient = s.getParent();
    281               if (patient != null)
     499              // Store patient ID value
     500              jsonPatientnamePatientid = updateJSONItemnameItemid(jsonPatientnamePatientid, patient);
     501              String patientName = patient.getName();
     502              if (inStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate))
    282503              {
    283                 // Store patient ID value
    284                 jsonPatientnamePatientid = updateJSONItemnameItemid(jsonPatientnamePatientid, patient);
    285                 key = yesPatientKey;
    286                 String patientName = patient.getName();
    287                 if (inStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate))
     504                duplicate = true;
     505              }
     506              else
     507              {
     508                patientDateSetHashMap = updateStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate);
     509              }
     510            }
     511            if ((consentDate.after(startDate) || consentDate.equals(startDate)) &&
     512              (consentDate.before(endDate) || consentDate.equals(endDate)))
     513            {
     514              if (consent.equals("Yes"))
     515              {
     516                key = yesKey;
     517                if (patient != null)
    288518                {
    289                   duplicate = true;
     519                  key = yesPatientKey;
    290520                }
    291521                else
    292522                {
    293                   patientDateSetHashMap = updateStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate);
     523                  key = yesNoPatientKey;
    294524                }
     525              }
     526              else if (consent.equals("No"))
     527              {
     528                key = noKey;
     529              }
     530              else if (consent.equals("Not asked"))
     531              {
     532                key = notAskedKey;
    295533              }
    296534              else
    297535              {
    298                 key = yesNoPatientKey;
     536                key = otherKey;
    299537              }
     538              // Find out if current consent date is the latest so far.
     539              if (latestDate == null || latestDate.before(consentDate))
     540              {
     541                latestDate = consentDate;
     542              }
     543            }
     544          }
     545          else
     546          {
     547            if (consent.equals("Yes"))
     548            {
     549              key = yesNoDateKey;
     550            }
     551            else if (consent.equals("No"))
     552            {
     553              key = noNoDateKey;
     554            }
     555            else if (consent.equals("Not asked"))
     556            {
     557              key = notAskedNoDateKey;
    300558            }
    301559            else
    302560            {
    303               key = yesNoDateKey;
     561              key = otherKey;
    304562            }
    305563          }
    306           else if (consent.equals("No"))
    307           {
    308             key = noKey;
    309             // Check if consent date exists
    310             if (consentDate == null)
     564          // Keep track of latest consent date for site
     565          if (consentDate != null)
     566          {
     567            Date siteLatestDate = sitePrefixDateHashMap.get(site.getPrefix());
     568            if (siteLatestDate == null || siteLatestDate.before(consentDate))
    311569            {
    312               key = noNoDateKey;
     570              sitePrefixDateHashMap.put(site.getPrefix(), consentDate);
    313571            }
    314572          }
    315           else if (consent.equals("Not asked"))
    316           {
    317             key = notAskedKey;
    318             // Check if consent date exists
    319             if (consentDate == null)
    320             {
    321               key = notAskedNoDateKey;
    322             }
    323           }
    324           else
    325           {
    326             key = otherKey;
    327           }
     573        }
     574        else
     575        {
     576          key = missingKey;
    328577        }
    329578        // Note that items with duplicate == false include missing consent items
    330579        if (!duplicate)
    331580        {
    332           // Update consent counters
    333           jsonSite = updateJSONObjectCounter(jsonSite, key);
    334           jsonSite = updateJSONObjectCounter(jsonSite, sumKey);
    335           jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, key);
    336           jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, sumKey);
     581          if (key != null)
     582          {
     583            // Update consent counters
     584            jsonSite = updateJSONObjectCounter(jsonSite, key);
     585            jsonSite = updateJSONObjectCounter(jsonSite, sumKey);
     586            jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, key);
     587            jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, sumKey);
     588          }
    337589          if (consentDate == null)
    338590          {
     591            // Include consents with unknown date
     592            jsonSite = updateJSONObjectCounter(jsonSite, noDateKey);
     593            jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, noDateKey);
    339594            jsonStatistics = updateJSONObjectCounter(jsonStatistics, noDateKey);
    340595          }
     596          // Increase the counter for total consents for the site, regardless of creation date
     597          jsonSite = updateJSONObjectCounter(jsonSite, totalKey);
     598
     599          // Increase the counter for total consents for all sites
     600          jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, totalKey);
    341601        }
    342602        else
     
    346606      }
    347607    }
     608    // Add latest consent date for site to site JSON object
     609    DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING;
     610    for (Site s: Site.getAllSites())
     611    {
     612        JSONObject jsonSite = (JSONObject) jsonStatistics.get(s.getPrefix());
     613        if (jsonSite == null)
     614        {
     615          jsonSite = new JSONObject();
     616          jsonStatistics.put(s.getPrefix(), jsonSite);
     617        }
     618        Date siteLatestDate = sitePrefixDateHashMap.get(s.getPrefix());
     619        jsonSite.put(latestDateKey, date2StringConverter.convert(siteLatestDate));
     620    }
     621    // Add latest date for further transfer to other JSON object
     622    jsonStatistics.put(latestDateKey, date2StringConverter.convert(latestDate));
    348623    // Create JSONObject (patient, dates) for patients with multiple dates
    349624    JSONObject jsonPatientsWithMultipleDates = createJSONPatientsWithMultipleDates(patientDateSetHashMap);
     
    356631    //
    357632    jsonReport.put("statistics", jsonStatistics);       
     633    jsonReport.put("beginDate", date2StringConverter.convert(startDate));
     634    jsonReport.put("endDate", date2StringConverter.convert(endDate));
     635    // Transfer latest date from jsonStatistics to jsonReport
     636    String latestDateStr = (String) jsonStatistics.get("latestDateKey");
     637    jsonReport.put("latestDate", latestDateStr);
     638    String siteOrder = alphabeticalOrder;
     639    JSONObject jsonSiteOrderList = createJSONSiteOrderList(siteOrder);
     640    jsonReport.put("siteOrderListKey", jsonSiteOrderList);
    358641    json.put("report", jsonReport);
    359642    return json;
     
    381664  }
    382665
     666  @SuppressWarnings({ "unchecked", "rawtypes" })
    383667  private JSONObject updateJSONItemnameItemid(JSONObject jsonObject, BioMaterial item)
    384668  {
     
    431715  }
    432716
    433   private int numDatesInStringDateSetHashMap(HashMap<String, Set<Date>> stringDateSetHashMap)
    434   {
    435     int numDates = 0;
    436     if (stringDateSetHashMap != null)
    437     {
    438       Set<String> stringSet = stringDateSetHashMap.keySet();
    439       if (stringSet != null)
    440       {
    441         for (String string: stringSet)
    442         {
    443           Set<Date> dateSet = stringDateSetHashMap.get(string);
    444           if (dateSet != null)
    445           {
    446             numDates += dateSet.size();
    447           }
    448         }
    449       }
    450     }
    451     return numDates;
    452   }
    453 
    454   private Set<String> keysWithMultipleDates(HashMap<String, Set<Date>> stringDateSetHashMap)
    455   {
    456     Set<String> keysWithMultipleDatesSet = new HashSet<String>();
    457     if (stringDateSetHashMap != null)
    458     {
    459       Set<String> stringSet = stringDateSetHashMap.keySet();
    460       if (stringSet != null)
    461       {
    462         for (String string: stringSet)
    463         {
    464           Set<Date> dateSet = stringDateSetHashMap.get(string);
    465           if (dateSet != null && dateSet.size() > 1)
    466           {
    467             keysWithMultipleDatesSet.add(string);
    468           }
    469         }
    470       }
    471     }
    472     return keysWithMultipleDatesSet;
    473   }
    474 
     717  private HashMap<String, Sample> updateStringEarliestSampleHashMap(HashMap<String, Sample> stringSampleHashMap, String string, Sample sample)
     718  {
     719    if (stringSampleHashMap == null)
     720    {
     721      stringSampleHashMap = new HashMap<String, Sample>();
     722    }
     723    if (string != null && !string.equals(""))
     724    {
     725      // Store the sample with the earliest date for the item defined by string
     726      Sample storedSample = stringSampleHashMap.get(string);
     727      Date sampleDate = null;
     728      Date storedSampleDate = null;
     729      if (sample != null)
     730      {
     731        BioMaterialEvent creationEvent = sample.getCreationEvent();
     732        sampleDate = creationEvent.getEventDate();
     733      }
     734      if (storedSample != null)
     735      {
     736        BioMaterialEvent creationEvent = storedSample.getCreationEvent();
     737        storedSampleDate = creationEvent.getEventDate();
     738      }
     739      if (sampleDate != null)
     740      {
     741        if (storedSampleDate != null)
     742        {
     743          if (sampleDate.before(storedSampleDate))
     744          {
     745            // New sample date earlier, store that sample for patient
     746            stringSampleHashMap.put(string, sample);
     747          }
     748        }
     749        else
     750        {
     751          // No stored sample; store new sample for patient
     752          stringSampleHashMap.put(string, sample);
     753        }
     754      }
     755    }
     756    return stringSampleHashMap;
     757  }
     758
     759  @SuppressWarnings("unchecked")
    475760  private JSONObject createJSONPatientsWithMultipleDates(HashMap<String, Set<Date>> stringDateSetHashMap)
    476761  {
     
    507792  }
    508793
    509   private JSONObject createJSONStatistics(ItemResultIterator<Sample> sampleIterator, Date startDate, Date endDate, String viewType)
     794  @SuppressWarnings("unchecked")
     795  private JSONObject createJSONStatistics(Iterator<Sample> sampleIterator, Date startDate, Date endDate, String viewType)
    510796    throws ServletException, IOException
    511797  {
     
    522808    String latestDateKey = "latestDateKey";
    523809    jsonStatistics.put(sitesCombinedKey, jsonSitesCombined);
     810    // Create HashMap to keep track of latest sample date for each site
     811    HashMap<String, Date> sitePrefixDateHashMap = new HashMap<String, Date>();
    524812    while (sampleIterator.hasNext())
    525813    {
     
    566854            }
    567855          }
     856
     857          // Keep track of latest sample date for site
     858          Date siteLatestDate = sitePrefixDateHashMap.get(site.getPrefix());
     859          if (siteLatestDate == null || siteLatestDate.before(creationDate))
     860          {
     861            sitePrefixDateHashMap.put(site.getPrefix(), creationDate);
     862          }
    568863        }
    569864        else
     
    580875      }
    581876    }
     877    // Add latest sample date for site to site JSON object
     878    DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING;
     879    for (Site s: Site.getAllSites())
     880    {
     881        JSONObject jsonSite = (JSONObject) jsonStatistics.get(s.getPrefix());
     882        if (jsonSite == null)
     883        {
     884          jsonSite = new JSONObject();
     885          jsonStatistics.put(s.getPrefix(), jsonSite);
     886        }
     887        Date siteLatestDate = sitePrefixDateHashMap.get(s.getPrefix());
     888        jsonSite.put(latestDateKey, date2StringConverter.convert(siteLatestDate));
     889    }
    582890    // Add latest date for further transfer to other JSON object
    583     DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING;
    584891    jsonStatistics.put(latestDateKey, date2StringConverter.convert(latestDate));
    585892    return jsonStatistics;       
    586893  }
    587894     
     895  @SuppressWarnings("unchecked")
    588896  private JSONObject updateJSONObjectCounter(JSONObject jsonObject, String key)
    589897  {
     
    599907  }
    600908
     909  @SuppressWarnings("unchecked")
    601910  private JSONObject initializeJSONSiteData(JSONObject jsonSiteContainerObject, String key)
    602911  {
     
    620929  }
    621930
     931  @SuppressWarnings("unchecked")
    622932  private JSONObject initializeJSONPeriodData(JSONObject jsonObject, Date startDate, Date endDate, Date dataStartDate, String viewType)
    623933  {
     
    644954    }
    645955    return jsonObject;
     956  }
     957
     958  /**
     959   *  Creates a JSONObject with order index as key and site prefix as value.
     960   *
     961   *  @param order String A string indicating desired order (null => alphabetical order)
     962   *  @return String A JSONObject with sort index as key and site prefix as value.
     963   */
     964  @SuppressWarnings("unchecked")
     965  private JSONObject createJSONSiteOrderList(String order)
     966  {
     967    JSONObject jsonSiteOrderList = new JSONObject();
     968    List<String> siteOrderedList = createSiteOrderedList(order);
     969    for (int i=0; i < siteOrderedList.size(); i++)
     970    {
     971      String namePrefix = siteOrderedList.get(i);
     972      jsonSiteOrderList.put(i, namePrefix);
     973    }
     974    return jsonSiteOrderList;
     975  }
     976
     977  /**
     978   *  Creates a list of site name prefixes sorted after specified order.
     979   *
     980   *  @param order String A string indicating desired order (null => alphabetical order)
     981   *  @return List<String> list of site name prefixes sorted after specified order.
     982   */
     983  @SuppressWarnings("rawtypes")
     984  private List<String> createSiteOrderedList(String order)
     985  {
     986    if (order == null || order.equals(""))
     987    {
     988      order = alphabeticalOrder;
     989    }
     990    TreeMap<Comparable, String> treeMap = new TreeMap<Comparable, String>();
     991    for (Site site: Site.getAllSites())
     992    {
     993      Comparable comparableObject = null;
     994      if (order.equals(alphabeticalOrder))
     995      {
     996        comparableObject = site.getName();
     997      }
     998      else if (order.equals(namePrefixOrder))
     999      {
     1000        comparableObject = site.getPrefix();
     1001      }
     1002      else if (order.equals(startDateOrder))
     1003      {
     1004        comparableObject = site.getStartDate();
     1005      }
     1006      else if (order.equals(nameLengthOrder))
     1007      {
     1008        comparableObject = site.getName().length();
     1009      }
     1010      treeMap.put(comparableObject, site.getPrefix());
     1011    }
     1012    List<String> list = new ArrayList<String>();
     1013    for (Comparable key: treeMap.keySet())
     1014    {
     1015      list.add(treeMap.get(key));
     1016    }
     1017    return list;
    6461018  }
    6471019
     
    7491121  }
    7501122
     1123  @SuppressWarnings("unused")
    7511124  private List<Date> createSortedPeriodStartDateList(Date startDate, Date endDate, String viewType)
    7521125  {
Note: See TracChangeset for help on using the changeset viewer.