Changeset 1764
- Timestamp:
- Dec 3, 2012, 4:33:47 PM (10 years ago)
- Location:
- extensions/net.sf.basedb.reggie/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/net.sf.basedb.reggie/trunk/resources/index.jsp
r1763 r1764 272 272 <li>Consent count report</li> 273 273 <li>Patient count report</li> 274 <li>Overview report</li>275 274 </ul> 276 275 </dd> -
extensions/net.sf.basedb.reggie/trunk/resources/samplereportgenerator.jsp
r1763 r1764 34 34 var unknownSite = 0; 35 35 var unknownCreation; 36 var numPatientsNoSamples = 0;37 36 38 37 var month=new Array(12); … … 64 63 var frm = document.forms['reggie']; 65 64 frm.reporttype.disabled = true; 66 // Hide report period input fields67 document.getElementById("reportPeriodSubSection02").style.display = 'none';68 65 // Hide sample type pop-up menu 69 66 document.getElementById("sampleTypeSubSection01").style.display = 'none'; … … 72 69 if (frm.reporttype[frm.reporttype.selectedIndex].value == 'samplecount') 73 70 { 74 // Show report period input fields 75 document.getElementById("reportPeriodSubSection01Header").innerHTML="Report period"; 76 document.getElementById("reportPeriodSubSection02").style.display = 'block'; 77 document.getElementById("reportPeriodSubSection04HelpText").innerHTML="Define which period the report should cover. Empty fields will include all tubes."; 71 // Set item name for report period text 72 document.getElementById("items01").innerHTML="tubes"; 78 73 // Set item name for report time step text 79 74 document.getElementById("items02").innerHTML="samples"; … … 92 87 else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'consentcount') 93 88 { 94 // Show report period input fields 95 document.getElementById("reportPeriodSubSection01Header").innerHTML="Report period"; 96 document.getElementById("reportPeriodSubSection02").style.display = 'block'; 97 document.getElementById("reportPeriodSubSection04HelpText").innerHTML="Define which period the report should cover. Empty fields will include all consents."; 89 // Set item name for report period text 90 document.getElementById("items01").innerHTML="consents"; 98 91 // Hide view type pop-up menu 99 92 document.getElementById("viewTypeSubSection01").style.display = 'none'; … … 103 96 else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'patientcount') 104 97 { 105 // Show report period input fields 106 document.getElementById("reportPeriodSubSection01Header").innerHTML="Report period"; 107 document.getElementById("reportPeriodSubSection02").style.display = 'block'; 108 document.getElementById("reportPeriodSubSection04HelpText").innerHTML="Define which period the report should cover. Empty fields will include all patients."; 98 // Set item name for report period text 99 document.getElementById("items01").innerHTML="patients"; 109 100 // Set item name for report time step text 110 101 document.getElementById("items02").innerHTML="patients"; … … 117 108 document.getElementById("viewTypeSubSection04").style.display = 'block'; 118 109 } 119 else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'overviewreport')120 {121 // Set parameters (report period) help text122 document.getElementById("reportPeriodSubSection01Header").innerHTML="No report parameters";123 document.getElementById("reportPeriodSubSection04HelpText").innerHTML="Overview report will be generated irrespective of date for items.";124 // Hide view type pop-up menu125 document.getElementById("viewTypeSubSection01").style.display = 'none';126 document.getElementById("viewTypeSubSection02").style.display = 'none';127 document.getElementById("viewTypeSubSection04").style.display = 'none';128 }129 110 Main.show('itemCountSection'); 130 111 … … 242 223 reportTable = createConsentCountReport(report); 243 224 } 244 elseif ('patientcount' == reportType)225 if ('patientcount' == reportType) 245 226 { 246 227 reportTable = createItemCountReport(report, reportType); 247 }248 else if ('overviewreport' == reportType)249 {250 reportTable = createOverviewReport(report);251 228 } 252 229 } … … 271 248 cellElement.appendChild(unknownDateTable); 272 249 } 273 else if ('overviewreport' == reportType)274 {275 var spacer = document.createElement('text');276 spacer.innerHTML = "<BR>";277 cellElement.appendChild(spacer);278 var patientDetailedTable = createOverviewPatientDetailedTable(report);279 cellElement.appendChild(patientDetailedTable);280 }281 250 // Summary list 282 251 var summaryList = document.createElement('ul'); … … 319 288 } 320 289 else if ('patientcount' == reportType) 321 { 290 { 322 291 summaryList.appendChild(getListElement(unknownSite + ' patients registered to unknown sites.')); 323 292 summaryList.appendChild(getListElement(unknownCreation + ' patients without creation date. These are included in the \'Total\' column.')); 324 }325 else if ('overviewreport' == reportType)326 {327 summaryList.appendChild(getListElement(unknownSite + ' patients registered to unknown sites.'));328 summaryList.appendChild(getListElement(numPatientsNoSamples + ' patients with no samples.'));329 summaryList.appendChild(getListElement('Note: Consents of type "Yes" include consents without patient id (PAT#) or date.'));330 293 } 331 294 cellElement.appendChild(summaryList); … … 714 677 addDataRowsToConsentTableUnknownDate(report, reportTable); 715 678 716 // Add a row with the combined numbers for all sites 679 // Add a row with the combined numbers for all sites for each period 717 680 var sitesCombinedRow = document.createElement('tr'); 718 681 sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary')); 719 682 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary', 2)); 720 // Get combined numbers for all sites 683 // Get combined numbers for all sites for each period 721 684 var sumKey = 'sumKey'; 722 685 var statistics = report.statistics; … … 741 704 data = getJSONData(sitesCombined, totalKey, 0); 742 705 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 743 reportTable.appendChild(sitesCombinedRow);744 745 return reportTable;746 }747 748 function createOverviewReport(report)749 {750 var reportTable = getReportTable();751 var sdString = report.beginDate;752 var edString = report.endDate;753 var ldString = report.latestDate;754 var startDate = new Date();755 startDate.setYear(sdString.substr(0,4));756 startDate.setMonth(sdString.substr(4,2)-1);757 startDate.setDate(sdString.substr(6));758 var endDate = new Date();759 endDate.setYear(edString.substr(0,4));760 endDate.setMonth(edString.substr(4,2)-1);761 endDate.setDate(edString.substr(6));762 var latestDate;763 if (ldString != null)764 {765 latestDate = new Date();766 latestDate.setYear(ldString.substr(0,4));767 latestDate.setMonth(ldString.substr(4,2)-1);768 latestDate.setDate(ldString.substr(6));769 }770 771 var headerRow = document.createElement('tr');772 var subHeaderRow = document.createElement('tr');773 var subHeader2Row = document.createElement('tr');774 var columnHeaderRow = document.createElement('tr');775 776 var numCols = 6;777 var numDecimals = 0;778 var headerText = 'Number of items of different kinds';779 var startDateStr = addHyphensToDateString(sdString);780 var endDateStr = addHyphensToDateString(edString);781 var latestDateStr = addHyphensToDateString(ldString);782 headerText += ' (betweeen ' + startDateStr + ' and ' + endDateStr + ')';783 if (latestDate != null)784 {785 headerText += '\nLast registration ' + latestDateStr;786 }787 headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+3)));788 789 // Subheader790 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 3));791 792 subHeaderRow.appendChild(getTableCellElement('Patients', 'reportsubheader'));793 subHeaderRow.appendChild(getTableCellElement('Blood', 'reportsubheader'));794 subHeaderRow.appendChild(getTableCellElement('Specimens', 'reportsubheader'));795 subHeaderRow.appendChild(getTableCellElement('No specimens', 'reportsubheader'));796 subHeaderRow.appendChild(getTableCellElement('Consents', 'reportsubheader'));797 subHeaderRow.appendChild(getTableCellElement('Consents', 'reportsubheader'));798 799 // Columnsheader800 var siteHeader = getTableCellElement('Site', 'reportsubheader');801 var startDateHeader = getTableCellElement('Start date','reportsubheader');802 var latestDateHeader = getTableCellElement('Latest date','reportsubheader');803 columnHeaderRow.appendChild(siteHeader);804 columnHeaderRow.appendChild(startDateHeader);805 columnHeaderRow.appendChild(latestDateHeader);806 807 columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));808 columnHeaderRow.appendChild(getTableCellElement('samples', 'reportsubheader'));809 columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));810 columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));811 columnHeaderRow.appendChild(getTableCellElement('(Yes)', 'reportsubheader'));812 columnHeaderRow.appendChild(getTableCellElement('missing', 'reportsubheader'));813 814 // Build table815 reportTable.appendChild(headerRow);816 reportTable.appendChild(subHeaderRow);817 reportTable.appendChild(subHeader2Row);818 reportTable.appendChild(columnHeaderRow);819 820 // Data rows821 addDataRowsToOverviewTable(report, reportTable);822 823 // Add a row with the combined numbers for all sites for each period824 var sitesCombinedRow = document.createElement('tr');825 sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary'));826 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary', 2));827 // Get combined numbers for all sites for each period828 var noDateKey = 'noDate';829 var sumKey = 'sumKey';830 var statistics = report.statistics;831 // Get values for use in summary section832 numPatientsNoSamples = statistics.patientNoSamples;833 var sitesCombined = statistics.sitesCombinedKey;834 if (sitesCombined != null)835 {836 data = getJSONData(sitesCombined, 'patient');837 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));838 data = getJSONData(sitesCombined, 'bloodSample');839 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));840 data = getJSONData(sitesCombined, 'specimen');841 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));842 data = getJSONData(sitesCombined, 'noSpecimen');843 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));844 data = getJSONData(sitesCombined, 'consentYes');845 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));846 data = getJSONData(sitesCombined, 'consentMissing');847 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));848 }849 reportTable.appendChild(sitesCombinedRow);850 851 return reportTable;852 }853 854 function createOverviewPatientDetailedTable(report)855 {856 var reportTable = getReportTable();857 var sdString = report.beginDate;858 var edString = report.endDate;859 var ldString = report.latestDate;860 var startDate = new Date();861 startDate.setYear(sdString.substr(0,4));862 startDate.setMonth(sdString.substr(4,2)-1);863 startDate.setDate(sdString.substr(6));864 /*865 var endDate = new Date();866 endDate.setYear(edString.substr(0,4));867 endDate.setMonth(edString.substr(4,2)-1);868 endDate.setDate(edString.substr(6));869 */870 var latestDate;871 if (ldString != null)872 {873 latestDate = new Date();874 latestDate.setYear(ldString.substr(0,4));875 latestDate.setMonth(ldString.substr(4,2)-1);876 latestDate.setDate(ldString.substr(6));877 }878 879 var headerRow = document.createElement('tr');880 var subHeaderRow = document.createElement('tr');881 var subHeader2Row = document.createElement('tr');882 var columnHeaderRow = document.createElement('tr');883 884 var numCols = 8;885 var numDecimals = 0;886 var headerText = 'Patient records of different kinds';887 var startDateStr = addHyphensToDateString(sdString);888 var endDateStr = addHyphensToDateString(edString);889 var latestDateStr = addHyphensToDateString(ldString);890 headerText += ' (betweeen ' + startDateStr + ' and ' + endDateStr + ')';891 /*892 if (latestDate != null)893 {894 headerText += '\nLast registration ' + latestDateStr;895 }896 */897 headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+2)));898 899 // Subheader900 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 2));901 902 subHeaderRow.appendChild(getTableCellElement('Patients', 'reportsubheader'));903 subHeaderRow.appendChild(getTableCellElement('Patients', 'reportsubheader'));904 subHeaderRow.appendChild(getTableCellElement('Patients', 'reportsubheader'));905 subHeaderRow.appendChild(getTableCellElement('Patients', 'reportsubheader'));906 subHeaderRow.appendChild(getTableCellElement('Patients', 'reportsubheader'));907 subHeaderRow.appendChild(getTableCellElement('Patients', 'reportsubheader'));908 subHeaderRow.appendChild(getTableCellElement('Patients', 'reportsubheader'));909 //subHeaderRow.appendChild(getTableCellElement('Patients', 'reportsubheader'));910 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));911 912 // Subheader 2913 subHeader2Row.appendChild(getTableCellElement('', 'reportsubheader', 2));914 915 subHeader2Row.appendChild(getTableCellElement('(blood', 'reportsubheader'));916 subHeader2Row.appendChild(getTableCellElement('(spec.', 'reportsubheader'));917 subHeader2Row.appendChild(getTableCellElement('(no spec.', 'reportsubheader'));918 subHeader2Row.appendChild(getTableCellElement('(blood and', 'reportsubheader'));919 subHeader2Row.appendChild(getTableCellElement('(blood and', 'reportsubheader'));920 subHeader2Row.appendChild(getTableCellElement('(spec. and', 'reportsubheader'));921 subHeader2Row.appendChild(getTableCellElement('(blood, spec.,', 'reportsubheader'));922 //subHeader2Row.appendChild(getTableCellElement('(no samples)', 'reportsubheader'));923 subHeader2Row.appendChild(getTableCellElement('', 'reportsubheader'));924 925 // Columnsheader926 var siteHeader = getTableCellElement('Site', 'reportsubheader');927 var startDateHeader = getTableCellElement('Start date','reportsubheader');928 //var latestDateHeader = getTableCellElement('Latest date','reportsubheader');929 columnHeaderRow.appendChild(siteHeader);930 columnHeaderRow.appendChild(startDateHeader);931 //columnHeaderRow.appendChild(latestDateHeader);932 933 columnHeaderRow.appendChild(getTableCellElement('only)', 'reportsubheader'));934 columnHeaderRow.appendChild(getTableCellElement('only)', 'reportsubheader'));935 columnHeaderRow.appendChild(getTableCellElement('only)', 'reportsubheader'));936 columnHeaderRow.appendChild(getTableCellElement('specimens)', 'reportsubheader'));937 columnHeaderRow.appendChild(getTableCellElement('no spec.)', 'reportsubheader'));938 columnHeaderRow.appendChild(getTableCellElement('no spec.)', 'reportsubheader'));939 columnHeaderRow.appendChild(getTableCellElement('and no spec.)', 'reportsubheader'));940 //columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader'));941 942 columnHeaderRow.appendChild(getTableCellElement('Sum', 'reportsubheader'));943 944 // Build table945 reportTable.appendChild(headerRow);946 reportTable.appendChild(subHeaderRow);947 reportTable.appendChild(subHeader2Row);948 reportTable.appendChild(columnHeaderRow);949 950 // Data rows951 addDataRowsToOverviewPatientDetailedTable(report, reportTable);952 953 // Add a row with the combined numbers for all sites954 var sitesCombinedRow = document.createElement('tr');955 sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary'));956 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary'));957 // Get combined numbers for all sites958 var noDateKey = 'noDate';959 var sumKey = 'sumKey';960 var statistics = report.statistics;961 // Get values for use in summary section962 numPatientsNoSamples = statistics.patientNoSamples;963 var sitesCombined = statistics.sitesCombinedKey;964 if (sitesCombined != null)965 {966 data = getJSONData(sitesCombined, 'patientBloodSampleOnly');967 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));968 data = getJSONData(sitesCombined, 'patientSpecimenOnly');969 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));970 data = getJSONData(sitesCombined, 'patientNoSpecimenOnly');971 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));972 data = getJSONData(sitesCombined, 'patientBloodSampleAndSpecimen');973 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));974 data = getJSONData(sitesCombined, 'patientBloodSampleAndNoSpecimen');975 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));976 data = getJSONData(sitesCombined, 'patientSpecimenAndNoSpecimen');977 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));978 data = getJSONData(sitesCombined, 'patientBloodSampleAndSpecimenAndNoSpecimen');979 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));980 //data = getJSONData(sitesCombined, 'patientNoSamples');981 //sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));982 data = getJSONData(sitesCombined, 'sumKey');983 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));984 }985 706 reportTable.appendChild(sitesCombinedRow); 986 707 … … 1176 897 var siteTotal = getJSONData(siteData, totalKey, 0); 1177 898 tableRow.appendChild(getTableCellElement(siteTotal, 'rowsummary')); 1178 reportTable.appendChild(tableRow);1179 }1180 }1181 1182 function addDataRowsToOverviewTable(report, reportTable)1183 {1184 var sites = report.sites;1185 var statistics = report.statistics;1186 unknownCreation = statistics.noDate;1187 unknownSite = statistics.unknownSite;1188 var siteOrderList = report.siteOrderListKey;1189 for (var siteOrderIndex in siteOrderList)1190 {1191 var namePrefix = siteOrderList[siteOrderIndex];1192 if (!sites.hasOwnProperty(namePrefix)) continue;1193 var site = sites[namePrefix];1194 var siteName = site.name;1195 var year = site.startDate.substr(0,4);1196 var month = site.startDate.substr(5,2);1197 var date = site.startDate.substr(8,2);1198 var siteStartDate = new Date(year, month-1, date);1199 1200 var siteData = statistics[namePrefix];1201 var siteLatestDate = siteData['latestDateKey'];1202 var siteLatestDateYear = siteLatestDate.substr(0,4);1203 var siteLatestDateMonth = siteLatestDate.substr(4,2);1204 var siteLatestDateDate = siteLatestDate.substr(6,2);1205 var siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate;1206 var tableRow = document.createElement('tr');1207 var tableCol = getTableCellElement(siteName, 'rowtitle');1208 tableRow.appendChild(tableCol);1209 tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata'));1210 tableRow.appendChild(getTableCellElement(siteLatestDateStr, 'reportdata'));1211 //var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate());1212 var noDateKey = 'noDate';1213 var sumKey = 'sumKey';1214 var totalKey = 'totalKey';1215 if (siteData != null)1216 {1217 data = getJSONData(siteData, 'patient');1218 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1219 data = getJSONData(siteData, 'bloodSample');1220 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1221 data = getJSONData(siteData, 'specimen');1222 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1223 data = getJSONData(siteData, 'noSpecimen');1224 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1225 data = getJSONData(siteData, 'consentYes');1226 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1227 data = getJSONData(siteData, 'consentMissing');1228 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1229 }1230 reportTable.appendChild(tableRow);1231 }1232 }1233 1234 function addDataRowsToOverviewPatientDetailedTable(report, reportTable)1235 {1236 var sites = report.sites;1237 var statistics = report.statistics;1238 unknownCreation = statistics.noDate;1239 unknownSite = statistics.unknownSite;1240 var siteOrderList = report.siteOrderListKey;1241 for (var siteOrderIndex in siteOrderList)1242 {1243 var namePrefix = siteOrderList[siteOrderIndex];1244 if (!sites.hasOwnProperty(namePrefix)) continue;1245 var site = sites[namePrefix];1246 var siteName = site.name;1247 var year = site.startDate.substr(0,4);1248 var month = site.startDate.substr(5,2);1249 var date = site.startDate.substr(8,2);1250 var siteStartDate = new Date(year, month-1, date);1251 1252 var siteData = statistics[namePrefix];1253 /*1254 var siteLatestDate = siteData['latestDateKey'];1255 var siteLatestDateYear = siteLatestDate.substr(0,4);1256 var siteLatestDateMonth = siteLatestDate.substr(4,2);1257 var siteLatestDateDate = siteLatestDate.substr(6,2);1258 var siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate;1259 */1260 var tableRow = document.createElement('tr');1261 var tableCol = getTableCellElement(siteName, 'rowtitle');1262 tableRow.appendChild(tableCol);1263 tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata'));1264 /*1265 tableRow.appendChild(getTableCellElement(siteLatestDateStr, 'reportdata'));1266 */1267 //var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate());1268 var noDateKey = 'noDate';1269 var sumKey = 'sumKey';1270 var totalKey = 'totalKey';1271 if (siteData != null)1272 {1273 data = getJSONData(siteData, 'patientBloodSampleOnly');1274 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1275 data = getJSONData(siteData, 'patientSpecimenOnly');1276 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1277 data = getJSONData(siteData, 'patientNoSpecimenOnly');1278 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1279 data = getJSONData(siteData, 'patientBloodSampleAndSpecimen');1280 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1281 data = getJSONData(siteData, 'patientBloodSampleAndNoSpecimen');1282 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1283 data = getJSONData(siteData, 'patientSpecimenAndNoSpecimen');1284 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1285 data = getJSONData(siteData, 'patientBloodSampleAndSpecimenAndNoSpecimen');1286 tableRow.appendChild(getTableCellElement(data, 'reportdata'));1287 //data = getJSONData(siteData, 'patientNoSamples');1288 //tableRow.appendChild(getTableCellElement(data, 'reportdata'));1289 data = getJSONData(siteData, 'sumKey');1290 tableRow.appendChild(getTableCellElement(data, 'rowsummary'));1291 }1292 899 reportTable.appendChild(tableRow); 1293 900 } … … 1777 1384 <option value="consentcount">Consent count report</option> 1778 1385 <option value="patientcount">Patient count report</option> 1779 <option value="overviewreport">Overview report</option>1780 1386 </select> 1781 1387 </td> … … 1803 1409 <table border="0" cellspacing="0" cellpadding="0" width="100%"> 1804 1410 <tr> 1805 <td valign="top" class="prompt"> 1806 <text id="reportPeriodSubSection01Header">Report period</text> 1807 </td> 1411 <td valign="top" class="prompt">Report period</td> 1808 1412 <td valign="top" class="input"> 1809 <div id="reportPeriodSubSection02" style="display:none;"> 1810 From<input type="text" onChange="dateOnChange()" size=7 name="fromdate"/> 1811 To<input type="text" onChange="dateOnChange()" size=7 name="todate" /> 1812 </div> 1413 From<input type="text" onChange="dateOnChange()" size=7 name="fromdate"/> 1414 To<input type="text" onChange="dateOnChange()" size=7 name="todate" /> 1813 1415 </td> 1814 1416 <td valign="top" class="status" id="displayInterval.status"></td> 1815 1417 <td class="help"> 1816 1418 <span id="displayInterval.message" class="message" style="display: none;"></span> 1817 <!--1818 1419 Define which period the report should cover. Empty fields will include all <text id="items01">items</text>.<br> 1819 -->1820 <text id="reportPeriodSubSection04HelpText">Parameter help text</text><br>1821 1420 </td> 1822 1421 </tr> -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java
r1763 r1764 195 195 196 196 json = createPatientCountReport(dc, json, startDate, endDate, viewType); 197 }198 else if ("overviewreport".equals(cmd))199 {200 String startDateParameter = Values.getString(req.getParameter("fdate"), null);201 String endDateParameter = Values.getString(req.getParameter("tdate"), null);202 203 Date startDate = Reggie.CONVERTER_STRING_TO_DATE.convert(startDateParameter);204 Date endDate = Reggie.CONVERTER_STRING_TO_DATE.convert(endDateParameter);205 206 if (startDate == null)207 {208 // Get the when the first site started209 for (Site s : Site.getAllSites())210 {211 Date siteDate = Reggie.CONVERTER_STRING_TO_DATE.convert(s.getStartDate().replaceAll("-", ""));212 if (siteDate != null && (startDate == null || startDate.after(siteDate)))213 {214 startDate = siteDate;215 }216 }217 }218 if (endDate == null)219 {220 // Get the date for today221 endDate = new Date();222 }223 224 json = createOverviewReport(dc, json, startDate, endDate);225 197 } 226 198 } … … 671 643 } 672 644 673 @SuppressWarnings({ "unchecked", "rawtypes" })674 private JSONObject createOverviewReport(DbControl dc, JSONObject json, Date startDate, Date endDate)675 throws ServletException, IOException676 {677 JSONObject jsonReport = new JSONObject();678 jsonReport.put("sites", getJSONSites());679 680 ItemQuery<Sample> sampleQuery = Sample.getQuery();681 sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true));682 // ...only include 'Specimen', 'No Specimen', 'Blood', or 'Case' items683 sampleQuery.restrict(684 Restrictions.or(685 Subtype.SPECIMEN.restriction(dc, null),686 Subtype.NO_SPECIMEN.restriction(dc, null),687 Subtype.BLOOD.restriction(dc, null),688 Subtype.CASE.restriction(dc, null)689 ));690 sampleQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);691 sampleQuery.order(Orders.asc(Hql.property("name")));692 sampleQuery.order(Orders.asc(Hql.property("ce", "eventDate")));693 sampleQuery.setCacheResult(true);694 ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc);695 // Use stored annotation snapshots for performance reasons696 SnapshotManager manager = new SnapshotManager();697 698 JSONObject jsonStatistics = new JSONObject();699 JSONObject jsonSitesCombined = new JSONObject();700 String patientKey = "patient";701 String bloodSampleKey = "bloodSample";702 String specimenKey = "specimen";703 String noSpecimenKey = "noSpecimen";704 String patientBloodSampleOnlyKey = "patientBloodSampleOnly";705 String patientSpecimenOnlyKey = "patientSpecimenOnly";706 String patientNoSpecimenOnlyKey = "patientNoSpecimenOnly";707 String patientBloodSampleAndSpecimenKey = "patientBloodSampleAndSpecimen";708 String patientBloodSampleAndNoSpecimenKey = "patientBloodSampleAndNoSpecimen";709 String patientSpecimenAndNoSpecimenKey = "patientSpecimenAndNoSpecimen";710 String patientBloodSampleAndSpecimenAndNoSpecimenKey = "patientBloodSampleAndSpecimenAndNoSpecimen";711 String patientNoSamplesKey = "patientNoSamples";712 String consentYesKey = "consentYes";713 String consentMissingKey = "consentMissing";714 String sitesCombinedKey = "sitesCombinedKey";715 String sumKey = "sumKey";716 String latestDateKey = "latestDateKey";717 String duplicateKey = "duplicateKey";718 jsonStatistics.put(sitesCombinedKey, jsonSitesCombined);719 // Initialize site data to 0 for the different keys720 jsonStatistics = initializeJSONSiteData(jsonStatistics, patientKey);721 jsonStatistics = initializeJSONSiteData(jsonStatistics, bloodSampleKey);722 jsonStatistics = initializeJSONSiteData(jsonStatistics, specimenKey);723 jsonStatistics = initializeJSONSiteData(jsonStatistics, noSpecimenKey);724 jsonStatistics = initializeJSONSiteData(jsonStatistics, patientBloodSampleOnlyKey);725 jsonStatistics = initializeJSONSiteData(jsonStatistics, patientSpecimenOnlyKey);726 jsonStatistics = initializeJSONSiteData(jsonStatistics, patientNoSpecimenOnlyKey);727 jsonStatistics = initializeJSONSiteData(jsonStatistics, patientBloodSampleAndSpecimenKey);728 jsonStatistics = initializeJSONSiteData(jsonStatistics, patientBloodSampleAndNoSpecimenKey);729 jsonStatistics = initializeJSONSiteData(jsonStatistics, patientSpecimenAndNoSpecimenKey);730 jsonStatistics = initializeJSONSiteData(jsonStatistics, patientBloodSampleAndSpecimenAndNoSpecimenKey);731 jsonStatistics = initializeJSONSiteData(jsonStatistics, consentYesKey);732 jsonStatistics = initializeJSONSiteData(jsonStatistics, consentMissingKey);733 // Initialize combined data to 0 for the different keys734 jsonSitesCombined.put(patientKey, 0);735 jsonSitesCombined.put(bloodSampleKey, 0);736 jsonSitesCombined.put(specimenKey, 0);737 jsonSitesCombined.put(noSpecimenKey, 0);738 jsonSitesCombined.put(patientBloodSampleOnlyKey, 0);739 jsonSitesCombined.put(patientSpecimenOnlyKey, 0);740 jsonSitesCombined.put(patientNoSpecimenOnlyKey, 0);741 jsonSitesCombined.put(patientBloodSampleAndSpecimenKey, 0);742 jsonSitesCombined.put(patientBloodSampleAndNoSpecimenKey, 0);743 jsonSitesCombined.put(patientSpecimenAndNoSpecimenKey, 0);744 jsonSitesCombined.put(patientBloodSampleAndSpecimenAndNoSpecimenKey, 0);745 jsonSitesCombined.put(consentYesKey, 0);746 jsonSitesCombined.put(consentMissingKey, 0);747 jsonSitesCombined.put(patientNoSamplesKey, 0);748 // Initialize other data to 0 for different keys749 jsonStatistics.put(duplicateKey, 0);750 Date latestDate = null;751 // Create HashMap to keep track of processed dates for each patient752 HashMap<String, Set<Date>>patientDateSetHashMap = new HashMap<String, Set<Date>>();753 //JSONObject jsonPatientnamePatientid = new JSONObject();754 // HashMap of patient id's and site prefixes755 HashMap<String, String> patientHashMap = new HashMap<String, String>();756 // Set of patient id's for patients with blood samples757 Set<String> patientsWithBloodSamplesSet = new HashSet<String>();758 // Set of patient id's for patients with specimens759 Set<String> patientsWithSpecimensSet = new HashSet<String>();760 // Set of patient id's for patients with no specimens761 Set<String> patientsWithNoSpecimensSet = new HashSet<String>();762 // Create HashMap to keep track of latest item date for each site763 HashMap<String, Date> sitePrefixDateHashMap = new HashMap<String, Date>();764 // Get item subtype constants for later use765 ItemSubtype subtypeSpecimen = Subtype.SPECIMEN.load(dc);766 ItemSubtype subtypeNoSpecimen = Subtype.NO_SPECIMEN.load(dc);767 ItemSubtype subtypeBlood = Subtype.BLOOD.load(dc);768 ItemSubtype subtypeCase = Subtype.CASE.load(dc);769 //770 while (sampleIterator != null && sampleIterator.hasNext())771 {772 Sample s = sampleIterator.next();773 BioMaterialEvent creationEvent = s.getCreationEvent();774 Date creationDate = creationEvent.getEventDate();775 776 // Find patient id777 BioMaterial patient = null;778 if (s.getItemSubtype().equals(subtypeBlood))779 {780 // The parent is the 'Patient' for blood samples and cases781 patient = s.getParent();782 }783 else if (s.getItemSubtype().equals(subtypeSpecimen) || s.getItemSubtype().equals(subtypeNoSpecimen))784 {785 // The grandparent is the 'Patient' for specimens and no specimens786 MeasuredBioMaterial parent = (MeasuredBioMaterial) s.getParent();787 if (parent != null)788 {789 patient = parent.getParent();790 }791 }792 793 // Update statistics for specimens, blood samples, and consents794 Site site = Site.findByCaseName(s.getName());795 if (site == Site.UNKNOWN)796 {797 String key = "unknownSite";798 jsonStatistics = updateJSONObjectCounter(jsonStatistics, key);799 }800 else801 {802 // Get site info803 JSONObject jsonSite = (JSONObject)jsonStatistics.get(site.getPrefix());804 if (jsonSite == null)805 {806 jsonSite = new JSONObject();807 jsonStatistics.put(site.getPrefix(), jsonSite);808 }809 810 // Store patient data for later processing811 String patientId = null;812 if (patient != null)813 {814 patientId = patient.getName();815 if (patientId != null && !patientId.equals(""))816 {817 // Add patient id to patient HashMap for site818 patientHashMap.put(patientId, site.getPrefix());819 820 if (s.getItemSubtype().equals(subtypeSpecimen))821 {822 // Add patient to patients with specimens set823 patientsWithSpecimensSet.add(patientId);824 }825 826 if (s.getItemSubtype().equals(subtypeNoSpecimen))827 {828 // Add patient to patients with no specimens set829 patientsWithNoSpecimensSet.add(patientId);830 }831 832 if (s.getItemSubtype().equals(subtypeBlood))833 {834 // Add patient to patients with blood samples set835 patientsWithBloodSamplesSet.add(patientId);836 }837 }838 }839 840 // Update specimen data841 if (s.getItemSubtype().equals(subtypeSpecimen))842 {843 jsonSite = updateJSONObjectCounter(jsonSite, specimenKey);844 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, specimenKey);845 }846 // Update no specimen data847 if (s.getItemSubtype().equals(subtypeNoSpecimen))848 {849 jsonSite = updateJSONObjectCounter(jsonSite, noSpecimenKey);850 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, noSpecimenKey);851 }852 // Update blood sample data853 if (s.getItemSubtype().equals(subtypeBlood))854 {855 jsonSite = updateJSONObjectCounter(jsonSite, bloodSampleKey);856 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, bloodSampleKey);857 }858 859 // Keep track of latest item date for site860 if (creationDate != null)861 {862 Date siteLatestDate = sitePrefixDateHashMap.get(site.getPrefix());863 if (siteLatestDate == null || siteLatestDate.before(creationDate))864 {865 sitePrefixDateHashMap.put(site.getPrefix(), creationDate);866 }867 // Keep track of latest item date so far868 if (latestDate == null || latestDate.before(creationDate))869 {870 latestDate = creationDate;871 }872 }873 874 // Process consents875 String consent = null;876 Date consentDate = null;877 if (s.getItemSubtype().equals(subtypeBlood) || s.getItemSubtype().equals(subtypeCase))878 {879 // Get consent880 consent = (String) Annotationtype.CONSENT.getAnnotationValue(dc, manager, s);881 // Get consent date882 consentDate = (Date) Annotationtype.CONSENT_DATE.getAnnotationValue(dc, manager, s);883 884 String key = null;885 Boolean duplicate = false;886 if (consent != null)887 {888 if (consentDate != null)889 {890 // The parent is the 'Patient' for blood samples and cases891 patient = s.getParent();892 893 // Check if a consent already exists for the same patient and date894 if (patient != null)895 {896 patientId = patient.getName();897 if (patientId != null && !patientId.equals(""))898 {899 if (inStringDateSetHashMap(patientDateSetHashMap, patientId, consentDate))900 {901 duplicate = true;902 }903 else904 {905 patientDateSetHashMap = updateStringDateSetHashMap(patientDateSetHashMap, patientId, consentDate);906 }907 }908 }909 }910 // Count approved consents, including consents without patient id (PAT#) or date911 if (consent.equals("Yes"))912 {913 key = consentYesKey;914 if (consentDate != null)915 {916 // Keep track of latest item date for site917 Date siteLatestDate = sitePrefixDateHashMap.get(site.getPrefix());918 if (siteLatestDate == null || siteLatestDate.before(consentDate))919 {920 sitePrefixDateHashMap.put(site.getPrefix(), consentDate);921 }922 // Keep track of latest item date so far923 if (latestDate == null || latestDate.before(consentDate))924 {925 latestDate = consentDate;926 }927 }928 }929 }930 else931 {932 key = consentMissingKey;933 }934 // Note that items with duplicate == false include missing consent items935 if (!duplicate)936 {937 if (key != null)938 {939 // Update consent counters940 jsonSite = updateJSONObjectCounter(jsonSite, key);941 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, key);942 }943 }944 else945 {946 jsonStatistics = updateJSONObjectCounter(jsonStatistics, duplicateKey);947 }948 }949 }950 }951 952 // Process patients953 for (String patId: patientHashMap.keySet())954 {955 if (patId != null && !patId.equals(""))956 {957 // Get site info958 String sitePrefix = patientHashMap.get(patId);959 JSONObject jsonSite = (JSONObject)jsonStatistics.get(sitePrefix);960 if (jsonSite == null)961 {962 jsonSite = new JSONObject();963 jsonStatistics.put(sitePrefix, jsonSite);964 }965 // Update patient data966 jsonSite = updateJSONObjectCounter(jsonSite, patientKey);967 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientKey);968 if (patientsWithSpecimensSet.contains(patId))969 {970 if (patientsWithNoSpecimensSet.contains(patId))971 {972 if (patientsWithBloodSamplesSet.contains(patId))973 {974 // Patient with both specimens, no specimens, and blood samples975 jsonSite = updateJSONObjectCounter(jsonSite, patientBloodSampleAndSpecimenAndNoSpecimenKey);976 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientBloodSampleAndSpecimenAndNoSpecimenKey);977 }978 else979 {980 // Patient with both specimens and no specimens981 jsonSite = updateJSONObjectCounter(jsonSite, patientSpecimenAndNoSpecimenKey);982 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientSpecimenAndNoSpecimenKey);983 }984 }985 else986 {987 if (patientsWithBloodSamplesSet.contains(patId))988 {989 // Patient with both specimens and blood samples990 jsonSite = updateJSONObjectCounter(jsonSite, patientBloodSampleAndSpecimenKey);991 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientBloodSampleAndSpecimenKey);992 }993 else994 {995 // Patient with specimens only996 jsonSite = updateJSONObjectCounter(jsonSite, patientSpecimenOnlyKey);997 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientSpecimenOnlyKey);998 }999 }1000 }1001 else1002 {1003 if (patientsWithNoSpecimensSet.contains(patId))1004 {1005 if (patientsWithBloodSamplesSet.contains(patId))1006 {1007 // Patient with both blood samples and no specimens1008 jsonSite = updateJSONObjectCounter(jsonSite, patientBloodSampleAndNoSpecimenKey);1009 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientBloodSampleAndNoSpecimenKey);1010 }1011 else1012 {1013 // Patient with no specimens only1014 jsonSite = updateJSONObjectCounter(jsonSite, patientNoSpecimenOnlyKey);1015 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientNoSpecimenOnlyKey);1016 }1017 }1018 else1019 {1020 if (patientsWithBloodSamplesSet.contains(patId))1021 {1022 // Patient with blood samples only1023 jsonSite = updateJSONObjectCounter(jsonSite, patientBloodSampleOnlyKey);1024 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientBloodSampleOnlyKey);1025 }1026 else1027 {1028 // Patient with no sample1029 jsonSite = updateJSONObjectCounter(jsonSite, patientNoSamplesKey);1030 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientNoSamplesKey);1031 }1032 }1033 }1034 // Update summed patient data1035 jsonSite = updateJSONObjectCounter(jsonSite, sumKey);1036 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, sumKey);1037 }1038 }1039 1040 // Add latest item date for site to site JSON object1041 DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING;1042 for (Site s: Site.getAllSites())1043 {1044 JSONObject jsonSite = (JSONObject) jsonStatistics.get(s.getPrefix());1045 if (jsonSite == null)1046 {1047 jsonSite = new JSONObject();1048 jsonStatistics.put(s.getPrefix(), jsonSite);1049 }1050 Date siteLatestDate = sitePrefixDateHashMap.get(s.getPrefix());1051 jsonSite.put(latestDateKey, date2StringConverter.convert(siteLatestDate));1052 }1053 // Add latest date for further transfer to other JSON object1054 jsonStatistics.put(latestDateKey, date2StringConverter.convert(latestDate));1055 // Add number of patients with no samples1056 Integer numPatientsNoSamples = (Integer) jsonSitesCombined.get(patientNoSamplesKey);1057 if (numPatientsNoSamples == null)1058 {1059 numPatientsNoSamples = 0;1060 }1061 jsonStatistics.put(patientNoSamplesKey, numPatientsNoSamples);1062 // Add number of patients with both specimens and no specimens1063 Integer numPatientsSpecimensAndNoSpecimens = (Integer) jsonSitesCombined.get(patientSpecimenAndNoSpecimenKey);1064 if (numPatientsSpecimensAndNoSpecimens == null)1065 {1066 numPatientsSpecimensAndNoSpecimens = 0;1067 }1068 jsonStatistics.put(patientSpecimenAndNoSpecimenKey, numPatientsSpecimensAndNoSpecimens);1069 // Add number of patients with both blood samples, specimens, and no specimens1070 Integer numPatientsBloodSamplesAndSpecimensAndNoSpecimens = (Integer) jsonSitesCombined.get(patientBloodSampleAndSpecimenAndNoSpecimenKey);1071 if (numPatientsBloodSamplesAndSpecimensAndNoSpecimens == null)1072 {1073 numPatientsBloodSamplesAndSpecimensAndNoSpecimens = 0;1074 }1075 jsonStatistics.put(patientBloodSampleAndSpecimenAndNoSpecimenKey, numPatientsBloodSamplesAndSpecimensAndNoSpecimens);1076 //1077 jsonReport.put("statistics", jsonStatistics);1078 jsonReport.put("beginDate", date2StringConverter.convert(startDate));1079 jsonReport.put("endDate", date2StringConverter.convert(endDate));1080 // Transfer latest date from jsonStatistics to jsonReport1081 String latestDateStr = (String) jsonStatistics.get("latestDateKey");1082 jsonReport.put("latestDate", latestDateStr);1083 String siteOrder = alphabeticalOrder;1084 JSONObject jsonSiteOrderList = createJSONSiteOrderList(siteOrder);1085 jsonReport.put("siteOrderListKey", jsonSiteOrderList);1086 json.put("report", jsonReport);1087 return json;1088 }1089 1090 645 private Boolean inStringDateSetHashMap(HashMap<String, Set<Date>> stringDateSetHashMap, String string, Date date) 1091 646 {
Note: See TracChangeset
for help on using the changeset viewer.