Changeset 2024


Ignore:
Timestamp:
Sep 20, 2013, 2:51:26 PM (8 years ago)
Author:
olle
Message:

Refs #505. Refs #449. Sample source reports updated to support follow-up blood samples.

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

Legend:

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

    r2000 r2024  
    7777    document.getElementById("sampleTypeSubSection02").style.display = 'none';
    7878    document.getElementById("sampleTypeSubSection04").style.display = 'none';
     79    // Hide table alternatives pop-up menu
     80    document.getElementById("tableAlternativesSubSection01").style.display = 'none';
     81    document.getElementById("tableAlternativesSubSection02").style.display = 'none';
     82    document.getElementById("tableAlternativesSubSection04").style.display = 'none';
     83    // Hide blood sample filter pop-up menu
     84    document.getElementById("bloodSampleFilterSubSection01").style.display = 'none';
     85    document.getElementById("bloodSampleFilterSubSection02").style.display = 'none';
     86    document.getElementById("bloodSampleFilterSubSection04").style.display = 'none';
    7987    if (frm.reporttype[frm.reporttype.selectedIndex].value == 'samplecount')
    8088    {
     
    98106      document.getElementById("sampleTypeSubSection02").style.display = 'block';
    99107      document.getElementById("sampleTypeSubSection04").style.display = 'block';
     108      // Show table alternatives pop-up menu
     109      document.getElementById("tableAlternativesSubSection01").style.display = 'block';
     110      document.getElementById("tableAlternativesSubSection02").style.display = 'block';
     111      document.getElementById("tableAlternativesSubSection04").style.display = 'block';
     112      document.getElementById("tableAlternativesSubSection04HelpText").innerHTML="Select table alternative for report (only used if sample type = \'Blood\').";
     113      frm.tablealternatives.disabled = true;
     114      // Show blood sample filter pop-up menu
     115      document.getElementById("bloodSampleFilterSubSection01").style.display = 'block';
     116      document.getElementById("bloodSampleFilterSubSection02").style.display = 'block';
     117      document.getElementById("bloodSampleFilterSubSection04").style.display = 'block';
     118      document.getElementById("bloodSampleFilterSubSection04HelpText").innerHTML="Select blood sample filter for report (only used if sample type = \'Blood\').";
     119      frm.bloodsamplefilter.disabled = true;
    100120    }
    101121    else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'consentcount')
     
    128148    else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'overviewreport')
    129149    {
     150/*
    130151      // Set parameters (report period) help text
    131152      document.getElementById("reportPeriodSubSection01").style.display = 'block';
     
    133154      document.getElementById("reportPeriodSubSection01Header").innerHTML="No report parameters";
    134155      document.getElementById("reportPeriodSubSection04HelpText").innerHTML="Overview report will be generated irrespective of date for items.";
     156*/
     157      // Show blood sample filter pop-up menu
     158      document.getElementById("bloodSampleFilterSubSection01").style.display = 'block';
     159      document.getElementById("bloodSampleFilterSubSection02").style.display = 'block';
     160      document.getElementById("bloodSampleFilterSubSection04").style.display = 'block';
     161      document.getElementById("bloodSampleFilterSubSection04HelpText").innerHTML="Select blood sample filter for report.";
     162      // Enable blood sample type filter menu
     163      frm.bloodsamplefilter.disabled = false;
    135164    }
    136165    else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'missingsampledatareport')
     
    140169      document.getElementById("sampleTypeSubSection02").style.display = 'block';
    141170      document.getElementById("sampleTypeSubSection04").style.display = 'block';
     171      // Show blood sample filter pop-up menu
     172      document.getElementById("bloodSampleFilterSubSection01").style.display = 'block';
     173      document.getElementById("bloodSampleFilterSubSection02").style.display = 'block';
     174      document.getElementById("bloodSampleFilterSubSection04").style.display = 'block';
     175      document.getElementById("bloodSampleFilterSubSection04HelpText").innerHTML="Select blood sample filter for report (only used if sample type = \'Blood\').";
     176      frm.bloodsamplefilter.disabled = true;
    142177    }
    143178    Main.show('itemCountSection');
     
    198233  }
    199234 
     235  function sampleTypeOnChange()
     236  {
     237    var frm = document.forms['reggie'];
     238    var reportType = frm.reporttype[frm.reporttype.selectedIndex].value;
     239    var sampleType = frm.sampletype[frm.sampletype.selectedIndex].value;
     240    var tableAlternatives = frm.tablealternatives[frm.tablealternatives.selectedIndex].value;
     241    if (sampleType == 'blood')
     242    {
     243      if (reportType == 'samplecount')
     244      {
     245        // Enable table alternatives menu
     246        frm.tablealternatives.disabled = false;
     247        // In principal this case should not exist when sample type has just been changed to 'blood'
     248        if (tableAlternatives == 'blood_sample_table_with_filter')
     249        {
     250          // Enable blood sample type filter menu
     251          frm.bloodsamplefilter.disabled = false;
     252        }
     253      }
     254      else
     255      {
     256        // Enable blood sample type filter menu
     257        frm.bloodsamplefilter.disabled = false;
     258      }
     259    }
     260    else
     261    {
     262      // Disable table alternatives menu and reset option
     263      frm.tablealternatives.selectedIndex = 0;
     264      frm.tablealternatives.disabled = true;
     265      // Disable blood sample type filter menu and reset option
     266      frm.bloodsamplefilter.selectedIndex = 0;
     267      frm.bloodsamplefilter.disabled = true;
     268    }
     269  }
     270
     271  function tableAlternativesOnChange()
     272  {
     273    var frm = document.forms['reggie'];
     274    var sampleType = frm.sampletype[frm.sampletype.selectedIndex].value;
     275    var tableAlternatives = frm.tablealternatives[frm.tablealternatives.selectedIndex].value;
     276    if (sampleType == 'blood' && tableAlternatives == 'blood_sample_table_with_filter')
     277    {
     278      // Enable blood sample type filter menu
     279      frm.bloodsamplefilter.disabled = false;
     280    }
     281    else
     282    {
     283      // Disable blood sample type filter menu and reset option
     284      frm.bloodsamplefilter.selectedIndex = 0;
     285      frm.bloodsamplefilter.disabled = true;
     286    }
     287  }
     288
    200289  function goCreate()
    201290  {
     
    211300      frm.viewtype.disabled = true;
    212301      frm.sampletype.disabled = true;
     302      frm.tablealternatives.disabled = true;
     303      frm.bloodsamplefilter.disabled = true;
    213304    }
    214305    else if (reportType == 'patientcount')
     
    216307      frm.viewtype.disabled = true;
    217308    }
     309    else if (reportType == 'overviewreport')
     310    {
     311      frm.bloodsamplefilter.disabled = true;
     312    }
    218313    else if (reportType == 'missingsampledatareport')
    219314    {
    220315      frm.sampletype.disabled = true;
     316      frm.bloodsamplefilter.disabled = true;
    221317    }
    222318    Main.hide('gocreate');
     
    230326      if (frm.viewtype.value != null) url += '&vtype='+frm.viewtype.value;
    231327      if (frm.sampletype.value != null) url += '&stype='+frm.sampletype.value;
     328      if (frm.tablealternatives.value != null) url += '&tablealternatives='+frm.tablealternatives.value;
     329      if (frm.bloodsamplefilter.value != null) url += '&bloodsamplefilter='+frm.bloodsamplefilter.value;
    232330    }
    233331    else if (reportType == 'patientcount')
     
    235333      if (frm.viewtype.value != null) url += '&vtype='+frm.viewtype.value;
    236334    }
     335    else if (reportType == 'overviewreport')
     336    {     
     337      if (frm.bloodsamplefilter.value != null) url += '&bloodsamplefilter='+frm.bloodsamplefilter.value;
     338    }
    237339    else if (reportType == 'missingsampledatareport')
    238340    {     
    239341      if (frm.sampletype.value != null) url += '&stype='+frm.sampletype.value;
     342      if (frm.bloodsamplefilter.value != null) url += '&bloodsamplefilter='+frm.bloodsamplefilter.value;
    240343    }
    241344   
     
    289392    setInnerHTML('reportcell', '');
    290393    cellElement.appendChild(reportTable);
     394    //
    291395    // Optional extra tables
    292     if ('consentcount' == reportType)
     396    if ('samplecount' == reportType)
     397    {     
     398      if ('blood' == sampleType && report.tableAlternatives == 'full_blood_sample_tables' && report != null)
     399      {
     400        var spacer0 = document.createElement('text');
     401        spacer0.innerHTML = "<BR>";
     402        cellElement.appendChild(spacer0);
     403        var spacer = document.createElement('text');
     404        spacer.innerHTML = "<BR>";
     405        cellElement.appendChild(spacer);
     406        // Follow-up
     407        cellElement.appendChild(spacer);
     408        var reportFollowUp = report.reportFollowUp;
     409        var reportFollowUpTable = createItemCountReport(reportFollowUp, reportType);
     410        cellElement.appendChild(reportFollowUpTable);
     411        // Not follow-up
     412        cellElement.appendChild(spacer);
     413        cellElement.appendChild(spacer);
     414        var reportNotFollowUp = report.reportNotFollowUp;
     415        var reportNotFollowUpTable = createItemCountReport(reportNotFollowUp, reportType);
     416        cellElement.appendChild(reportNotFollowUpTable);
     417        // Unknown
     418        cellElement.appendChild(spacer);
     419        cellElement.appendChild(spacer);
     420        var reportUnknown = report.reportUnknown;
     421        var reportUnknownTable = createItemCountReport(reportUnknown, reportType);
     422        cellElement.appendChild(reportUnknownTable);
     423        // PreNeo
     424        cellElement.appendChild(spacer);
     425        cellElement.appendChild(spacer);
     426        var reportPreNeo = report.reportPreNeo;
     427        var reportPreNeoTable = createItemCountReport(reportPreNeo, reportType);
     428        cellElement.appendChild(reportPreNeoTable);
     429        // PreOp
     430        cellElement.appendChild(spacer);
     431        cellElement.appendChild(spacer);
     432        var reportPreOp = report.reportPreOp;
     433        var reportPreOpTable = createItemCountReport(reportPreOp, reportType);
     434        cellElement.appendChild(reportPreOpTable);
     435        // FollowUp06
     436        cellElement.appendChild(spacer);
     437        cellElement.appendChild(spacer);
     438        var reportFollowUp06 = report.reportFollowUp06;
     439        var reportFollowUp06Table = createItemCountReport(reportFollowUp06, reportType);
     440        cellElement.appendChild(reportFollowUp06Table);
     441        // FollowUp12
     442        cellElement.appendChild(spacer);
     443        cellElement.appendChild(spacer);
     444        var reportFollowUp12 = report.reportFollowUp12;
     445        var reportFollowUp12Table = createItemCountReport(reportFollowUp12, reportType);
     446        cellElement.appendChild(reportFollowUp12Table);
     447        // FollowUp36
     448        cellElement.appendChild(spacer);
     449        cellElement.appendChild(spacer);
     450        var reportFollowUp36 = report.reportFollowUp36;
     451        var reportFollowUp36Table = createItemCountReport(reportFollowUp36, reportType);
     452        cellElement.appendChild(reportFollowUp36Table);
     453        //
     454        // Reset # of blood samples with unknown site or creation date to that for unfiltered report
     455        unknownCreation = report.statistics.noDate;
     456        unknownSite = report.statistics.unknownSite;
     457      }
     458    }
     459    else if ('consentcount' == reportType)
    293460    {
    294461      var spacer0 = document.createElement('text');
     
    369536      summaryList.appendChild(getListElement(numPatientsNoSamples + ' patients with no samples.'));
    370537      summaryList.appendChild(getListElement('Note: Consents of type "Yes" include consents without patient id (PAT#) or date.'));
     538      summaryList.appendChild(getListElement('Note: Data in column "Blood samples follow-up" are not affected by blood sample filter.'));
    371539    }
    372540    else if ('missingsampledatareport' == reportType)
     
    407575    var viewType = report.viewType;   
    408576    var sampleType = report.sampleType;
     577    var tableAlternatives = report.tableAlternatives;
     578    var bloodSampleFilter = report.bloodSampleFilter;
    409579 
    410580    var headerRow = document.createElement('tr');   
     
    426596      {
    427597        headerText = '# Blood samples by ';
     598        if (bloodSampleFilter != null && bloodSampleFilter != 'none')
     599        {
     600          bloodSampleFilterDisplayText = getBloodSampleFilterDisplayText(bloodSampleFilter);
     601          headerText = '# Blood samples of type \'' + bloodSampleFilterDisplayText + '\' by ';
     602        }
    428603      }
    429604    }
     
    808983  {
    809984    var reportTable = getReportTable();
     985    var bloodSampleFilter = report.bloodSampleFilter;
    810986    var sdString = report.beginDate;
    811987    var edString = report.endDate;
     
    820996    var columnHeaderRow = document.createElement('tr');
    821997   
    822     var numCols = 6;
     998    var numCols = 7;
    823999    var numDecimals = 0;
    8241000    var headerText = 'Number of items of different kinds';
     1001    if (bloodSampleFilter != null && bloodSampleFilter != 'none')
     1002    {
     1003      bloodSampleFilterDisplayText = getBloodSampleFilterDisplayText(bloodSampleFilter);
     1004      headerText += ', blood sample type = \'' + bloodSampleFilterDisplayText + '\'';
     1005    }
    8251006    var startDateStr = addHyphensToDateString(sdString);
    8261007    var endDateStr = addHyphensToDateString(edString);
     
    8381019    subHeaderRow.appendChild(getTableCellElement('Patients', 'reportsubheader'));
    8391020    subHeaderRow.appendChild(getTableCellElement('Blood', 'reportsubheader'));
     1021    subHeaderRow.appendChild(getTableCellElement('Blood', 'reportsubheader'));
    8401022    subHeaderRow.appendChild(getTableCellElement('Specimens', 'reportsubheader'));
    8411023    subHeaderRow.appendChild(getTableCellElement('No specimens', 'reportsubheader'));
    8421024    subHeaderRow.appendChild(getTableCellElement('Consents', 'reportsubheader'));
    8431025    subHeaderRow.appendChild(getTableCellElement('Consents', 'reportsubheader'));
     1026
     1027    // Subheader 2
     1028    subHeader2Row.appendChild(getTableCellElement('', 'reportsubheader', 3));
     1029   
     1030    subHeader2Row.appendChild(getTableCellElement('', 'reportsubheader'));
     1031    subHeader2Row.appendChild(getTableCellElement('samples', 'reportsubheader'));
     1032    subHeader2Row.appendChild(getTableCellElement('samples', 'reportsubheader'));
     1033    subHeader2Row.appendChild(getTableCellElement('', 'reportsubheader'));
     1034    subHeader2Row.appendChild(getTableCellElement('', 'reportsubheader'));
     1035    subHeader2Row.appendChild(getTableCellElement('(Yes)', 'reportsubheader'));
     1036    subHeader2Row.appendChild(getTableCellElement('missing', 'reportsubheader'));
    8441037
    8451038    // Columnsheader   
     
    8521045   
    8531046    columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
    854     columnHeaderRow.appendChild(getTableCellElement('samples', 'reportsubheader'));
     1047    columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
     1048    columnHeaderRow.appendChild(getTableCellElement('follow-up', 'reportsubheader'));
    8551049    columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
    8561050    columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
    857     columnHeaderRow.appendChild(getTableCellElement('(Yes)', 'reportsubheader'));
    858     columnHeaderRow.appendChild(getTableCellElement('missing', 'reportsubheader'));
     1051    columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
     1052    columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));
    8591053
    8601054    // Build table     
     
    8841078      data = getJSONData(sitesCombined, 'bloodSample');
    8851079      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     1080      data = getJSONData(sitesCombined, 'bloodSampleFollowUp');
     1081      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
    8861082      data = getJSONData(sitesCombined, 'specimen');
    8871083      sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));
     
    9011097  {
    9021098    var reportTable = getReportTable();
     1099    var bloodSampleFilter = report.bloodSampleFilter;
    9031100    var sdString = report.beginDate;
    9041101    var edString = report.endDate;
     
    9151112    var numDecimals = 0;
    9161113    var headerText = 'Patient records of different kinds';
     1114    if (bloodSampleFilter != null && bloodSampleFilter != 'none')
     1115    {
     1116      bloodSampleFilterDisplayText = getBloodSampleFilterDisplayText(bloodSampleFilter);
     1117      headerText += ', blood sample type = \'' + bloodSampleFilterDisplayText + '\'';
     1118    }
    9171119    var startDateStr = addHyphensToDateString(sdString);
    9181120    var endDateStr = addHyphensToDateString(edString);
     
    10291231
    10301232    var sampleType = report.sampleType;
     1233    var bloodSampleFilter = report.bloodSampleFilter;
    10311234    var permissionDeniedForPatientName = report.permissionDeniedForPatientName;
    10321235
     
    10581261    {
    10591262      headerText = 'Number of missing blood sample items of different kinds';
     1263      if (bloodSampleFilter != null && bloodSampleFilter != 'none')
     1264      {
     1265        bloodSampleFilterDisplayText = getBloodSampleFilterDisplayText(bloodSampleFilter);
     1266        headerText += ', blood sample type = \'' + bloodSampleFilterDisplayText + '\'';
     1267      }
    10601268    }
    10611269    var startDateStr = addHyphensToDateString(sdString);
     
    14281636        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    14291637        data = getJSONData(siteData, 'bloodSample');
     1638        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
     1639        data = getJSONData(siteData, 'bloodSampleFollowUp');
    14301640        tableRow.appendChild(getTableCellElement(data, 'reportdata'));
    14311641        data = getJSONData(siteData, 'specimen');
     
    21222332    var printNote = '<b>Note!</b> For better printing set page orientation to <i>landscape</i>.';
    21232333    openPrintWindow('<%=ID%>', 'reportcell', reportName, 'landscape', printNote, '../');
     2334  }
     2335
     2336  function getBloodSampleFilterDisplayText(bloodSampleFilter)
     2337  {
     2338    var bloodSampleFilterDisplayText = bloodSampleFilter;
     2339    if (bloodSampleFilter == 'followup')
     2340    {
     2341      bloodSampleFilterDisplayText = 'Follow-up';
     2342    }
     2343    else if (bloodSampleFilter == 'notfollowup')
     2344    {
     2345      bloodSampleFilterDisplayText = 'Not follow-up';
     2346    }
     2347    else if (bloodSampleFilter == '')
     2348    {
     2349      bloodSampleFilterDisplayText = 'unknown';
     2350    }
     2351    return bloodSampleFilterDisplayText;
    21242352  }
    21252353
     
    22512479              <td valign="top" class="input">
    22522480                <div id="sampleTypeSubSection02" style="display:none;">
    2253                   <select name="sampletype">
     2481                  <select name="sampletype" onChange="sampleTypeOnChange()">
    22542482                    <option value="specimen" selected="yes">Specimen</option>
    22552483                    <option value="nospecimen">No specimen</option>
     
    22632491                  <span id="displaySampleType.message" class="message" style="display: none;"></span>
    22642492                  Select sample type for report.
     2493                </div>
     2494              </td>
     2495            </tr>
     2496            <tr>
     2497              <td valign="top" class="prompt">
     2498                <div id="tableAlternativesSubSection01" style="display:none;">
     2499                  Table alternatives
     2500                </div>
     2501              </td>
     2502              <td valign="top" class="input">
     2503                <div id="tableAlternativesSubSection02" style="display:none;">
     2504                  <select name="tablealternatives" onChange="tableAlternativesOnChange()">
     2505                    <option value="full_blood_sample_tables" selected="yes">9 tables with different blood sample choices</option>
     2506                    <option value="blood_sample_table_with_filter">1 table with optional blood sample filter</option>
     2507                  </select>
     2508                </div>
     2509              </td>
     2510              <td valign="top" class="status" id="displayTableAlternatives.status"></td>
     2511              <td class="help">
     2512                <div id="tableAlternativesSubSection04" style="display:none;">
     2513                  <span id="displayTableAlternatives.message" class="message" style="display: none;"></span>
     2514                  <!--
     2515                  Select table alternative for report (only used if sample type = 'Blood').<br>
     2516                  -->
     2517                  <text id="tableAlternativesSubSection04HelpText">Parameter help text</text><br>
     2518                </div>
     2519              </td>
     2520            </tr>
     2521            <tr>
     2522              <td valign="top" class="prompt">
     2523                <div id="bloodSampleFilterSubSection01" style="display:none;">
     2524                  Blood sample filter
     2525                </div>
     2526              </td>
     2527              <td valign="top" class="input">
     2528                <div id="bloodSampleFilterSubSection02" style="display:none;">
     2529                  <select name="bloodsamplefilter">
     2530                    <option value="none" selected="yes">None</option>
     2531                    <option value="followup">Follow-up</option>
     2532                    <option value="notfollowup">Not follow-up</option>
     2533                    <option value="">unknown</option>
     2534                    <option value="PreNeo">PreNeo</option>
     2535                    <option value="PreOp">PreOp</option>
     2536                    <option value="FollowUp06">FollowUp06</option>
     2537                    <option value="FollowUp12">FollowUp12</option>
     2538                    <option value="FollowUp36">FollowUp36</option>
     2539                  </select>
     2540                </div>
     2541              </td>
     2542              <td valign="top" class="status" id="displayBloodSampleFilter.status"></td>
     2543              <td class="help">
     2544                <div id="bloodSampleFilterSubSection04" style="display:none;">
     2545                  <span id="displayBloodSampleFilter.message" class="message" style="display: none;"></span>
     2546                  <!--
     2547                  Select optional blood sample filter for report.<br>
     2548                  -->
     2549                  <text id="bloodSampleFilterSubSection04HelpText">Parameter help text</text><br>
    22652550                </div>
    22662551              </td>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java

    r2000 r2024  
    4747
    4848  private ReportTableUtilServlet tableUtil;
     49  private final static String TABLE_ALTERNATIVE_FULL = "full_blood_sample_tables";
     50  private final static String TABLE_ALTERNATIVE_BLOOD_FILTER = "blood_sample_table_with_filter";
     51  private final static String BLOOD_FILTER_NONE = "none";
     52  private final static String BLOOD_FILTER_FOLLOW_UP = "followup";
     53  private final static String BLOOD_FILTER_NOT_FOLLOW_UP = "notfollowup";
     54  private final static String BLOOD_FILTER_UNKNOWN = "";
     55  private final static String BLOOD_FILTER_PRENEO = "PreNeo";
     56  private final static String BLOOD_FILTER_PREOP = "PreOp";
     57  private final static String BLOOD_FILTER_FOLLOW_UP_06 = "FollowUp06";
     58  private final static String BLOOD_FILTER_FOLLOW_UP_12 = "FollowUp12";
     59  private final static String BLOOD_FILTER_FOLLOW_UP_36 = "FollowUp36";
    4960
    5061  public SampleReportServlet()
     
    115126          sampleType = sampleTypeParameter;
    116127        }
    117 
    118         json = createSampleCountReport(dc, json, startDate, endDate, viewType, sampleType);
     128        String tableAlternatives = TABLE_ALTERNATIVE_FULL;
     129        String tableAlternativesParameter = Values.getString(req.getParameter("tablealternatives"), null);
     130        if (tableAlternativesParameter != null)
     131        {
     132          tableAlternatives = tableAlternativesParameter;
     133        }
     134        String bloodSampleFilter = BLOOD_FILTER_NONE;
     135        String bloodSampleFilterParameter = Values.getString(req.getParameter("bloodsamplefilter"), null);
     136        if (bloodSampleFilterParameter != null)
     137        {
     138          bloodSampleFilter = bloodSampleFilterParameter;
     139        }
     140
     141        json = createSampleCountReport(dc, json, startDate, endDate, viewType, sampleType, tableAlternatives, bloodSampleFilter);
    119142      }
    120143      else if ("consentcount".equals(cmd))
     
    211234        }
    212235
    213         json = createOverviewReport(dc, json, startDate, endDate);
     236        String bloodSampleFilter = BLOOD_FILTER_NONE;
     237        String bloodSampleFilterParameter = Values.getString(req.getParameter("bloodsamplefilter"), null);
     238        if (bloodSampleFilterParameter != null)
     239        {
     240          bloodSampleFilter = bloodSampleFilterParameter;
     241        }
     242
     243        json = createOverviewReport(dc, json, startDate, endDate, bloodSampleFilter);
    214244      }
    215245      else if ("missingsampledatareport".equals(cmd))
     
    245275          sampleType = sampleTypeParameter;
    246276        }
    247 
    248         json = createMissingSampleDataReport(dc, json, startDate, endDate, sampleType);
     277        String bloodSampleFilter = BLOOD_FILTER_NONE;
     278        String bloodSampleFilterParameter = Values.getString(req.getParameter("bloodsamplefilter"), null);
     279        if (bloodSampleFilterParameter != null)
     280        {
     281          bloodSampleFilter = bloodSampleFilterParameter;
     282        }
     283
     284        json = createMissingSampleDataReport(dc, json, startDate, endDate, sampleType, bloodSampleFilter);
    249285      }
    250286    }
     
    265301 
    266302  @SuppressWarnings("unchecked")
    267   private JSONObject createSampleCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String viewType, String sampleType)
     303  private JSONObject createSampleCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String viewType, String sampleType, String tableAlternatives, String bloodSampleFilter)
    268304    throws ServletException, IOException
    269305  {
     
    291327    sampleQuery.setCacheResult(true);
    292328    ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc);       
     329    // Use stored annotation snapshots for performance reasons
     330    SnapshotManager manager = new SnapshotManager();       
    293331    // Store samples that should be processed for report table in list
    294     List<Sample> sampleList = new ArrayList<Sample>();
     332    List<Sample> rawSampleList = new ArrayList<Sample>();
    295333    while (sampleIterator.hasNext())
    296334    {
    297335      Sample s = sampleIterator.next();
    298       sampleList.add(s);
    299     }
    300                  
    301     JSONObject jsonStatistics = tableUtil.createJSONStatistics(sampleList.iterator(), startDate, endDate, viewType);
    302     jsonReport.put("statistics", jsonStatistics);       
     336      rawSampleList.add(s);
     337    }
     338    String latestDateStr = null;
     339    if (!sampleType.equals("blood") || tableAlternatives.equals(TABLE_ALTERNATIVE_BLOOD_FILTER))
     340    {
     341      List<Sample> sampleList = createSampleCountSampleList(dc, manager, rawSampleList, bloodSampleFilter);
     342     
     343      JSONObject jsonStatistics = tableUtil.createJSONStatistics(sampleList.iterator(), startDate, endDate, viewType);
     344
     345      jsonReport.put("statistics", jsonStatistics);
     346      latestDateStr = (String) jsonStatistics.get("latestDateKey");
     347    }
     348    else if (tableAlternatives.equals(TABLE_ALTERNATIVE_FULL))
     349    {
     350      // Get sample lists for different blood sample filters
     351      List<Sample> sampleListNone = createSampleCountSampleList(dc, manager, rawSampleList, BLOOD_FILTER_NONE);
     352     
     353      JSONObject jsonStatisticsNone = tableUtil.createJSONStatistics(sampleListNone.iterator(), startDate, endDate, viewType);
     354
     355      jsonReport.put("statistics", jsonStatisticsNone);
     356      latestDateStr = (String) jsonStatisticsNone.get("latestDateKey");
     357
     358      // Add extra JSON reports as child items to outer JSON report
     359      List<Sample> sampleListFollowUp = createSampleCountSampleList(dc, manager, rawSampleList, BLOOD_FILTER_FOLLOW_UP);
     360      List<Sample> sampleListNotFollowUp = createSampleCountSampleList(dc, manager, rawSampleList, BLOOD_FILTER_NOT_FOLLOW_UP);
     361      List<Sample> sampleListUnknown = createSampleCountSampleList(dc, manager, rawSampleList, BLOOD_FILTER_UNKNOWN);
     362      List<Sample> sampleListPreNeo = createSampleCountSampleList(dc, manager, rawSampleList, BLOOD_FILTER_PRENEO);
     363      List<Sample> sampleListPreOp = createSampleCountSampleList(dc, manager, rawSampleList, BLOOD_FILTER_PREOP);
     364      List<Sample> sampleListFollow06 = createSampleCountSampleList(dc, manager, rawSampleList, BLOOD_FILTER_FOLLOW_UP_06);
     365      List<Sample> sampleListFollow12 = createSampleCountSampleList(dc, manager, rawSampleList, BLOOD_FILTER_FOLLOW_UP_12);
     366      List<Sample> sampleListFollow36 = createSampleCountSampleList(dc, manager, rawSampleList, BLOOD_FILTER_FOLLOW_UP_36);
     367
     368      JSONObject jsonReportFollowUp = createSampleCountReport(sampleListFollowUp, startDate, endDate, viewType, sampleType, tableAlternatives, BLOOD_FILTER_FOLLOW_UP);
     369      JSONObject jsonReportNotFollowUp = createSampleCountReport(sampleListNotFollowUp, startDate, endDate, viewType, sampleType, tableAlternatives, BLOOD_FILTER_NOT_FOLLOW_UP);
     370      JSONObject jsonReportUnknown = createSampleCountReport(sampleListUnknown, startDate, endDate, viewType, sampleType, tableAlternatives, BLOOD_FILTER_UNKNOWN);
     371      JSONObject jsonReportPreNeo = createSampleCountReport(sampleListPreNeo, startDate, endDate, viewType, sampleType, tableAlternatives, BLOOD_FILTER_PRENEO);
     372      JSONObject jsonReportPreOp = createSampleCountReport(sampleListPreOp, startDate, endDate, viewType, sampleType, tableAlternatives, BLOOD_FILTER_PREOP);
     373      JSONObject jsonReportFollow06 = createSampleCountReport(sampleListFollow06, startDate, endDate, viewType, sampleType, tableAlternatives, BLOOD_FILTER_FOLLOW_UP_06);
     374      JSONObject jsonReportFollow12 = createSampleCountReport(sampleListFollow12, startDate, endDate, viewType, sampleType, tableAlternatives, BLOOD_FILTER_FOLLOW_UP_12);
     375      JSONObject jsonReportFollow36 = createSampleCountReport(sampleListFollow36, startDate, endDate, viewType, sampleType, tableAlternatives, BLOOD_FILTER_FOLLOW_UP_36);
     376
     377      jsonReport.put("reportFollowUp", jsonReportFollowUp);
     378      jsonReport.put("reportNotFollowUp", jsonReportNotFollowUp);
     379      jsonReport.put("reportUnknown", jsonReportUnknown);
     380      jsonReport.put("reportPreNeo", jsonReportPreNeo);
     381      jsonReport.put("reportPreOp", jsonReportPreOp);
     382      jsonReport.put("reportFollowUp06", jsonReportFollow06);
     383      jsonReport.put("reportFollowUp12", jsonReportFollow12);
     384      jsonReport.put("reportFollowUp36", jsonReportFollow36);
     385    }
    303386    if (viewType == null)
    304387    {
     
    309392    jsonReport.put("viewType", viewType);
    310393    jsonReport.put("sampleType", sampleType);
     394    jsonReport.put("tableAlternatives", tableAlternatives);
     395    jsonReport.put("bloodSampleFilter", bloodSampleFilter);       
    311396    jsonReport.put("beginDate", date2StringConverter.convert(startDate));
    312397    jsonReport.put("endDate", date2StringConverter.convert(endDate));
    313398    jsonReport.put("periodBeginDate", date2StringConverter.convert(periodStartDate));
    314399    // Transfer latest date from jsonStatistics to jsonReport
    315     String latestDateStr = (String) jsonStatistics.get("latestDateKey");
    316400    jsonReport.put("latestDate", latestDateStr);
    317401    String siteOrder = ReportTableUtilServlet.alphabeticalOrder;
     
    320404    json.put("report", jsonReport);
    321405    return json;
     406  }
     407   
     408  @SuppressWarnings("unchecked")
     409  private JSONObject createSampleCountReport(List<Sample> sampleList, Date startDate, Date endDate, String viewType, String sampleType, String tableAlternatives, String bloodSampleFilter)
     410    throws ServletException, IOException
     411  {
     412    JSONObject jsonReport = new JSONObject();
     413    jsonReport.put("sites", ReportTableUtilServlet.getJSONSites());
     414   
     415    String latestDateStr = null;
     416    JSONObject jsonStatistics = tableUtil.createJSONStatistics(sampleList.iterator(), startDate, endDate, viewType);
     417    jsonReport.put("statistics", jsonStatistics);
     418    latestDateStr = (String) jsonStatistics.get("latestDateKey");
     419    if (viewType == null)
     420    {
     421      viewType = tableUtil.getViewType(startDate, endDate);
     422    }
     423    DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING;
     424    Date periodStartDate = tableUtil.calculatePeriodStartDate(startDate, viewType);
     425    jsonReport.put("viewType", viewType);
     426    jsonReport.put("sampleType", sampleType);
     427    jsonReport.put("tableAlternatives", tableAlternatives);
     428    jsonReport.put("bloodSampleFilter", bloodSampleFilter);       
     429    jsonReport.put("beginDate", date2StringConverter.convert(startDate));
     430    jsonReport.put("endDate", date2StringConverter.convert(endDate));
     431    jsonReport.put("periodBeginDate", date2StringConverter.convert(periodStartDate));
     432    // Transfer latest date from jsonStatistics to jsonReport
     433    jsonReport.put("latestDate", latestDateStr);
     434    String siteOrder = ReportTableUtilServlet.alphabeticalOrder;
     435    JSONObject jsonSiteOrderList = tableUtil.createJSONSiteOrderList(siteOrder);
     436    jsonReport.put("siteOrderListKey", jsonSiteOrderList);
     437    return jsonReport;
     438  }
     439   
     440  private List<Sample> createSampleCountSampleList(DbControl dc, SnapshotManager manager, List<Sample> rawSampleList, String bloodSampleFilter)
     441    throws ServletException, IOException
     442  {
     443    ItemSubtype subtypeBlood = Subtype.BLOOD.load(dc);
     444    // Store samples that should be processed for report table in list
     445    List<Sample> sampleList = new ArrayList<Sample>();
     446    for (Sample s: rawSampleList)
     447    {
     448      // Optional blood sample filter
     449      if (bloodSampleFilter != null && !bloodSampleFilter.equals(BLOOD_FILTER_NONE))
     450      {
     451        if (s.getItemSubtype().equals(subtypeBlood))
     452        {
     453          // Get blood sample annotation
     454          String bloodSampleType = (String) Annotationtype.BLOOD_SAMPLE.getAnnotationValue(dc, manager, s);
     455          if (bloodSampleFilter.equals(BLOOD_FILTER_UNKNOWN))
     456          {
     457            // Blood sample type unknown (blood sample type == null should be included)
     458            if (bloodSampleType != null && !bloodSampleType.equals(bloodSampleFilter))
     459            {
     460              continue;
     461            }
     462          }
     463          else if (bloodSampleFilter.equals(BLOOD_FILTER_FOLLOW_UP))
     464          {
     465            // Follow-up blood sample type (blood sample type == null should not be included)
     466            if (bloodSampleType == null ||
     467                !(bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_06)
     468                || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_12)
     469                || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_36))
     470              )
     471            {
     472              continue;
     473            }
     474          }
     475          else if (bloodSampleFilter.equals(BLOOD_FILTER_NOT_FOLLOW_UP))
     476          {
     477            // Non-follow-up blood sample type (blood sample type == null should be included)
     478            if (bloodSampleType != null &&
     479                (bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_06)
     480                || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_12)
     481                || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_36))
     482              )
     483            {
     484              continue;
     485            }
     486          }
     487          else
     488          {
     489            // Specific blood sample type (blood sample type == null should not be included)
     490            if (bloodSampleType == null || !bloodSampleType.equals(bloodSampleFilter))
     491            {
     492              continue;
     493            }
     494          }
     495        }
     496      }     
     497      sampleList.add(s);
     498    }
     499    return sampleList;
    322500  }
    323501   
     
    768946
    769947  @SuppressWarnings({ "unchecked", "rawtypes" })
    770   private JSONObject createOverviewReport(DbControl dc, JSONObject json, Date startDate, Date endDate)
     948  private JSONObject createOverviewReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String bloodSampleFilter)
    771949      throws ServletException, IOException
    772950  {
     
    796974    String patientKey = "patient";
    797975    String bloodSampleKey = "bloodSample";
     976    String bloodSampleFollowUpKey = "bloodSampleFollowUp";
    798977    String specimenKey = "specimen";
    799978    String noSpecimenKey = "noSpecimen";
     
    816995    jsonStatistics = tableUtil.initializeJSONSiteData(jsonStatistics, patientKey);
    817996    jsonStatistics = tableUtil.initializeJSONSiteData(jsonStatistics, bloodSampleKey);
     997    jsonStatistics = tableUtil.initializeJSONSiteData(jsonStatistics, bloodSampleFollowUpKey);
    818998    jsonStatistics = tableUtil.initializeJSONSiteData(jsonStatistics, specimenKey);
    819999    jsonStatistics = tableUtil.initializeJSONSiteData(jsonStatistics, noSpecimenKey);
     
    8321012    jsonSitesCombined.put(patientKey, 0);
    8331013    jsonSitesCombined.put(bloodSampleKey, 0);
     1014    jsonSitesCombined.put(bloodSampleFollowUpKey, 0);
    8341015    jsonSitesCombined.put(specimenKey, 0);
    8351016    jsonSitesCombined.put(noSpecimenKey, 0);
     
    8731054      Date creationDate = creationEvent.getEventDate();
    8741055
     1056      // Update follow-up blood sample data before filtering for blood sample type
     1057      if (s.getItemSubtype().equals(subtypeBlood))
     1058      {
     1059        Site bloodSite = Site.findByCaseName(s.getName()); 
     1060        if (bloodSite != Site.UNKNOWN)
     1061        {
     1062          // Get blood site info           
     1063          JSONObject jsonSite = (JSONObject)jsonStatistics.get(bloodSite.getPrefix());
     1064          if (jsonSite == null)
     1065          {
     1066            jsonSite = new JSONObject();
     1067            jsonStatistics.put(bloodSite.getPrefix(), jsonSite);
     1068          }
     1069          // Get blood sample annotation
     1070          String bloodSampleType = (String) Annotationtype.BLOOD_SAMPLE.getAnnotationValue(dc, manager, s);
     1071          // Follow-up blood sample type (blood sample type == null should not be included)
     1072          if (bloodSampleType != null &&
     1073              (bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_06)
     1074              || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_12)
     1075              || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_36))
     1076            )
     1077          {
     1078            jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, bloodSampleFollowUpKey);
     1079            jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, bloodSampleFollowUpKey);
     1080          }
     1081        }
     1082      }
     1083
     1084      // Optional blood sample filter
     1085      if (bloodSampleFilter != null && !bloodSampleFilter.equals(BLOOD_FILTER_NONE))
     1086      {
     1087        if (s.getItemSubtype().equals(subtypeBlood))
     1088        {
     1089          // Get blood sample annotation
     1090          String bloodSampleType = (String) Annotationtype.BLOOD_SAMPLE.getAnnotationValue(dc, manager, s);
     1091          if (bloodSampleFilter.equals(BLOOD_FILTER_UNKNOWN))
     1092          {
     1093            // Blood sample type unknown (blood sample type == null should be included)
     1094            if (bloodSampleType != null && !bloodSampleType.equals(bloodSampleFilter))
     1095            {
     1096              continue;
     1097            }
     1098          }
     1099          else if (bloodSampleFilter.equals(BLOOD_FILTER_FOLLOW_UP))
     1100          {
     1101            // Follow-up blood sample type (blood sample type == null should not be included)
     1102            if (bloodSampleType == null ||
     1103                !(bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_06)
     1104                || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_12)
     1105                || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_36))
     1106              )
     1107            {
     1108              continue;
     1109            }
     1110          }
     1111          else if (bloodSampleFilter.equals(BLOOD_FILTER_NOT_FOLLOW_UP))
     1112          {
     1113            // Non-follow-up blood sample type (blood sample type == null should be included)
     1114            if (bloodSampleType != null &&
     1115                (bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_06)
     1116                || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_12)
     1117                || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_36))
     1118              )
     1119            {
     1120              continue;
     1121            }
     1122          }
     1123          else
     1124          {
     1125            // Specific blood sample type (blood sample type == null should not be included)
     1126            if (bloodSampleType == null || !bloodSampleType.equals(bloodSampleFilter))
     1127            {
     1128              continue;
     1129            }
     1130          }
     1131        }
     1132      }
     1133     
    8751134      // Find patient id
    8761135      BioMaterial patient = null;
     
    11751434    //
    11761435    jsonReport.put("statistics", jsonStatistics);       
     1436    jsonReport.put("bloodSampleFilter", bloodSampleFilter);       
    11771437    jsonReport.put("beginDate", date2StringConverter.convert(startDate));
    11781438    jsonReport.put("endDate", date2StringConverter.convert(endDate));
     
    11881448
    11891449  @SuppressWarnings({ "unchecked", "rawtypes" })
    1190   private JSONObject createMissingSampleDataReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String sampleType)
     1450  private JSONObject createMissingSampleDataReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String sampleType, String bloodSampleFilter)
    11911451      throws ServletException, IOException
    11921452  {
     
    12641524      Date creationDate = creationEvent.getEventDate();
    12651525
     1526      // If blood sample, check if blood sample filter has been selected
     1527      if (sampleType.equals("blood"))
     1528      {
     1529        // Optional blood sample filter
     1530        if (bloodSampleFilter != null && !bloodSampleFilter.equals(BLOOD_FILTER_NONE))
     1531        {
     1532          if (s.getItemSubtype().equals(subtypeBlood))
     1533          {
     1534            // Get blood sample annotation
     1535            String bloodSampleType = (String) Annotationtype.BLOOD_SAMPLE.getAnnotationValue(dc, manager, s);
     1536            if (bloodSampleFilter.equals(BLOOD_FILTER_UNKNOWN))
     1537            {
     1538              // Blood sample type unknown (blood sample type == null should be included)
     1539              if (bloodSampleType != null && !bloodSampleType.equals(bloodSampleFilter))
     1540              {
     1541                continue;
     1542              }
     1543            }
     1544            else if (bloodSampleFilter.equals(BLOOD_FILTER_FOLLOW_UP))
     1545            {
     1546              // Follow-up blood sample type (blood sample type == null should not be included)
     1547              if (bloodSampleType == null ||
     1548                  !(bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_06)
     1549                  || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_12)
     1550                  || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_36))
     1551                )
     1552              {
     1553                continue;
     1554              }
     1555            }
     1556            else if (bloodSampleFilter.equals(BLOOD_FILTER_NOT_FOLLOW_UP))
     1557            {
     1558              // Non-follow-up blood sample type (blood sample type == null should be included)
     1559              if (bloodSampleType != null &&
     1560                  (bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_06)
     1561                  || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_12)
     1562                  || bloodSampleType.equals(BLOOD_FILTER_FOLLOW_UP_36))
     1563                )
     1564              {
     1565                continue;
     1566              }
     1567            }
     1568            else
     1569            {
     1570              // Specific blood sample type (blood sample type == null should not be included)
     1571              if (bloodSampleType == null || !bloodSampleType.equals(bloodSampleFilter))
     1572              {
     1573                continue;
     1574              }
     1575            }
     1576          }
     1577        }
     1578      }
     1579
    12661580      // Find patient id
    12671581      BioMaterial patient = null;
     
    14611775    jsonReport.put("statistics", jsonStatistics);       
    14621776    jsonReport.put("sampleType", sampleType);
     1777    jsonReport.put("bloodSampleFilter", bloodSampleFilter);       
    14631778    jsonReport.put("beginDate", date2StringConverter.convert(startDate));
    14641779    jsonReport.put("endDate", date2StringConverter.convert(endDate));
Note: See TracChangeset for help on using the changeset viewer.