Changeset 1765
- Timestamp:
- Dec 3, 2012, 4:40:40 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
r1764 r1765 272 272 <li>Consent count report</li> 273 273 <li>Patient count report</li> 274 <li>Overview report</li> 274 275 </ul> 275 276 </dd> -
extensions/net.sf.basedb.reggie/trunk/resources/samplereportgenerator.jsp
r1764 r1765 34 34 var unknownSite = 0; 35 35 var unknownCreation; 36 var numPatientsNoSamples = 0; 36 37 37 38 var month=new Array(12); … … 63 64 var frm = document.forms['reggie']; 64 65 frm.reporttype.disabled = true; 66 // Hide report period input fields 67 document.getElementById("reportPeriodSubSection02").style.display = 'none'; 65 68 // Hide sample type pop-up menu 66 69 document.getElementById("sampleTypeSubSection01").style.display = 'none'; … … 69 72 if (frm.reporttype[frm.reporttype.selectedIndex].value == 'samplecount') 70 73 { 71 // Set item name for report period text 72 document.getElementById("items01").innerHTML="tubes"; 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."; 73 78 // Set item name for report time step text 74 79 document.getElementById("items02").innerHTML="samples"; … … 87 92 else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'consentcount') 88 93 { 89 // Set item name for report period text 90 document.getElementById("items01").innerHTML="consents"; 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."; 91 98 // Hide view type pop-up menu 92 99 document.getElementById("viewTypeSubSection01").style.display = 'none'; … … 96 103 else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'patientcount') 97 104 { 98 // Set item name for report period text 99 document.getElementById("items01").innerHTML="patients"; 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."; 100 109 // Set item name for report time step text 101 110 document.getElementById("items02").innerHTML="patients"; … … 108 117 document.getElementById("viewTypeSubSection04").style.display = 'block'; 109 118 } 119 else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'overviewreport') 120 { 121 // Set parameters (report period) help text 122 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 menu 125 document.getElementById("viewTypeSubSection01").style.display = 'none'; 126 document.getElementById("viewTypeSubSection02").style.display = 'none'; 127 document.getElementById("viewTypeSubSection04").style.display = 'none'; 128 } 110 129 Main.show('itemCountSection'); 111 130 … … 223 242 reportTable = createConsentCountReport(report); 224 243 } 225 if ('patientcount' == reportType)244 else if ('patientcount' == reportType) 226 245 { 227 246 reportTable = createItemCountReport(report, reportType); 247 } 248 else if ('overviewreport' == reportType) 249 { 250 reportTable = createOverviewReport(report); 228 251 } 229 252 } … … 248 271 cellElement.appendChild(unknownDateTable); 249 272 } 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 } 250 281 // Summary list 251 282 var summaryList = document.createElement('ul'); … … 288 319 } 289 320 else if ('patientcount' == reportType) 290 { 321 { 291 322 summaryList.appendChild(getListElement(unknownSite + ' patients registered to unknown sites.')); 292 323 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.')); 293 330 } 294 331 cellElement.appendChild(summaryList); … … 677 714 addDataRowsToConsentTableUnknownDate(report, reportTable); 678 715 679 // Add a row with the combined numbers for all sites for each period716 // Add a row with the combined numbers for all sites 680 717 var sitesCombinedRow = document.createElement('tr'); 681 718 sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary')); 682 719 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary', 2)); 683 // Get combined numbers for all sites for each period720 // Get combined numbers for all sites 684 721 var sumKey = 'sumKey'; 685 722 var statistics = report.statistics; … … 704 741 data = getJSONData(sitesCombined, totalKey, 0); 705 742 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 // Subheader 790 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 // Columnsheader 800 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 table 815 reportTable.appendChild(headerRow); 816 reportTable.appendChild(subHeaderRow); 817 reportTable.appendChild(subHeader2Row); 818 reportTable.appendChild(columnHeaderRow); 819 820 // Data rows 821 addDataRowsToOverviewTable(report, reportTable); 822 823 // Add a row with the combined numbers for all sites for each period 824 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 period 828 var noDateKey = 'noDate'; 829 var sumKey = 'sumKey'; 830 var statistics = report.statistics; 831 // Get values for use in summary section 832 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 // Subheader 900 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 2 913 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 // Columnsheader 926 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 table 945 reportTable.appendChild(headerRow); 946 reportTable.appendChild(subHeaderRow); 947 reportTable.appendChild(subHeader2Row); 948 reportTable.appendChild(columnHeaderRow); 949 950 // Data rows 951 addDataRowsToOverviewPatientDetailedTable(report, reportTable); 952 953 // Add a row with the combined numbers for all sites 954 var sitesCombinedRow = document.createElement('tr'); 955 sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary')); 956 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary')); 957 // Get combined numbers for all sites 958 var noDateKey = 'noDate'; 959 var sumKey = 'sumKey'; 960 var statistics = report.statistics; 961 // Get values for use in summary section 962 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 } 706 985 reportTable.appendChild(sitesCombinedRow); 707 986 … … 897 1176 var siteTotal = getJSONData(siteData, totalKey, 0); 898 1177 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 } 899 1292 reportTable.appendChild(tableRow); 900 1293 } … … 1384 1777 <option value="consentcount">Consent count report</option> 1385 1778 <option value="patientcount">Patient count report</option> 1779 <option value="overviewreport">Overview report</option> 1386 1780 </select> 1387 1781 </td> … … 1409 1803 <table border="0" cellspacing="0" cellpadding="0" width="100%"> 1410 1804 <tr> 1411 <td valign="top" class="prompt">Report period</td> 1805 <td valign="top" class="prompt"> 1806 <text id="reportPeriodSubSection01Header">Report period</text> 1807 </td> 1412 1808 <td valign="top" class="input"> 1413 From<input type="text" onChange="dateOnChange()" size=7 name="fromdate"/> 1414 To<input type="text" onChange="dateOnChange()" size=7 name="todate" /> 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> 1415 1813 </td> 1416 1814 <td valign="top" class="status" id="displayInterval.status"></td> 1417 1815 <td class="help"> 1418 1816 <span id="displayInterval.message" class="message" style="display: none;"></span> 1817 <!-- 1419 1818 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> 1420 1821 </td> 1421 1822 </tr> -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java
r1764 r1765 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 started 209 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 today 221 endDate = new Date(); 222 } 223 224 json = createOverviewReport(dc, json, startDate, endDate); 197 225 } 198 226 } … … 643 671 } 644 672 673 @SuppressWarnings({ "unchecked", "rawtypes" }) 674 private JSONObject createOverviewReport(DbControl dc, JSONObject json, Date startDate, Date endDate) 675 throws ServletException, IOException 676 { 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' items 683 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 reasons 696 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 keys 720 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 keys 734 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 keys 749 jsonStatistics.put(duplicateKey, 0); 750 Date latestDate = null; 751 // Create HashMap to keep track of processed dates for each patient 752 HashMap<String, Set<Date>>patientDateSetHashMap = new HashMap<String, Set<Date>>(); 753 //JSONObject jsonPatientnamePatientid = new JSONObject(); 754 // HashMap of patient id's and site prefixes 755 HashMap<String, String> patientHashMap = new HashMap<String, String>(); 756 // Set of patient id's for patients with blood samples 757 Set<String> patientsWithBloodSamplesSet = new HashSet<String>(); 758 // Set of patient id's for patients with specimens 759 Set<String> patientsWithSpecimensSet = new HashSet<String>(); 760 // Set of patient id's for patients with no specimens 761 Set<String> patientsWithNoSpecimensSet = new HashSet<String>(); 762 // Create HashMap to keep track of latest item date for each site 763 HashMap<String, Date> sitePrefixDateHashMap = new HashMap<String, Date>(); 764 // Get item subtype constants for later use 765 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 id 777 BioMaterial patient = null; 778 if (s.getItemSubtype().equals(subtypeBlood)) 779 { 780 // The parent is the 'Patient' for blood samples and cases 781 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 specimens 786 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 consents 794 Site site = Site.findByCaseName(s.getName()); 795 if (site == Site.UNKNOWN) 796 { 797 String key = "unknownSite"; 798 jsonStatistics = updateJSONObjectCounter(jsonStatistics, key); 799 } 800 else 801 { 802 // Get site info 803 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 processing 811 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 site 818 patientHashMap.put(patientId, site.getPrefix()); 819 820 if (s.getItemSubtype().equals(subtypeSpecimen)) 821 { 822 // Add patient to patients with specimens set 823 patientsWithSpecimensSet.add(patientId); 824 } 825 826 if (s.getItemSubtype().equals(subtypeNoSpecimen)) 827 { 828 // Add patient to patients with no specimens set 829 patientsWithNoSpecimensSet.add(patientId); 830 } 831 832 if (s.getItemSubtype().equals(subtypeBlood)) 833 { 834 // Add patient to patients with blood samples set 835 patientsWithBloodSamplesSet.add(patientId); 836 } 837 } 838 } 839 840 // Update specimen data 841 if (s.getItemSubtype().equals(subtypeSpecimen)) 842 { 843 jsonSite = updateJSONObjectCounter(jsonSite, specimenKey); 844 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, specimenKey); 845 } 846 // Update no specimen data 847 if (s.getItemSubtype().equals(subtypeNoSpecimen)) 848 { 849 jsonSite = updateJSONObjectCounter(jsonSite, noSpecimenKey); 850 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, noSpecimenKey); 851 } 852 // Update blood sample data 853 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 site 860 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 far 868 if (latestDate == null || latestDate.before(creationDate)) 869 { 870 latestDate = creationDate; 871 } 872 } 873 874 // Process consents 875 String consent = null; 876 Date consentDate = null; 877 if (s.getItemSubtype().equals(subtypeBlood) || s.getItemSubtype().equals(subtypeCase)) 878 { 879 // Get consent 880 consent = (String) Annotationtype.CONSENT.getAnnotationValue(dc, manager, s); 881 // Get consent date 882 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 cases 891 patient = s.getParent(); 892 893 // Check if a consent already exists for the same patient and date 894 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 else 904 { 905 patientDateSetHashMap = updateStringDateSetHashMap(patientDateSetHashMap, patientId, consentDate); 906 } 907 } 908 } 909 } 910 // Count approved consents, including consents without patient id (PAT#) or date 911 if (consent.equals("Yes")) 912 { 913 key = consentYesKey; 914 if (consentDate != null) 915 { 916 // Keep track of latest item date for site 917 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 far 923 if (latestDate == null || latestDate.before(consentDate)) 924 { 925 latestDate = consentDate; 926 } 927 } 928 } 929 } 930 else 931 { 932 key = consentMissingKey; 933 } 934 // Note that items with duplicate == false include missing consent items 935 if (!duplicate) 936 { 937 if (key != null) 938 { 939 // Update consent counters 940 jsonSite = updateJSONObjectCounter(jsonSite, key); 941 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, key); 942 } 943 } 944 else 945 { 946 jsonStatistics = updateJSONObjectCounter(jsonStatistics, duplicateKey); 947 } 948 } 949 } 950 } 951 952 // Process patients 953 for (String patId: patientHashMap.keySet()) 954 { 955 if (patId != null && !patId.equals("")) 956 { 957 // Get site info 958 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 data 966 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 samples 975 jsonSite = updateJSONObjectCounter(jsonSite, patientBloodSampleAndSpecimenAndNoSpecimenKey); 976 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientBloodSampleAndSpecimenAndNoSpecimenKey); 977 } 978 else 979 { 980 // Patient with both specimens and no specimens 981 jsonSite = updateJSONObjectCounter(jsonSite, patientSpecimenAndNoSpecimenKey); 982 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientSpecimenAndNoSpecimenKey); 983 } 984 } 985 else 986 { 987 if (patientsWithBloodSamplesSet.contains(patId)) 988 { 989 // Patient with both specimens and blood samples 990 jsonSite = updateJSONObjectCounter(jsonSite, patientBloodSampleAndSpecimenKey); 991 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientBloodSampleAndSpecimenKey); 992 } 993 else 994 { 995 // Patient with specimens only 996 jsonSite = updateJSONObjectCounter(jsonSite, patientSpecimenOnlyKey); 997 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientSpecimenOnlyKey); 998 } 999 } 1000 } 1001 else 1002 { 1003 if (patientsWithNoSpecimensSet.contains(patId)) 1004 { 1005 if (patientsWithBloodSamplesSet.contains(patId)) 1006 { 1007 // Patient with both blood samples and no specimens 1008 jsonSite = updateJSONObjectCounter(jsonSite, patientBloodSampleAndNoSpecimenKey); 1009 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientBloodSampleAndNoSpecimenKey); 1010 } 1011 else 1012 { 1013 // Patient with no specimens only 1014 jsonSite = updateJSONObjectCounter(jsonSite, patientNoSpecimenOnlyKey); 1015 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientNoSpecimenOnlyKey); 1016 } 1017 } 1018 else 1019 { 1020 if (patientsWithBloodSamplesSet.contains(patId)) 1021 { 1022 // Patient with blood samples only 1023 jsonSite = updateJSONObjectCounter(jsonSite, patientBloodSampleOnlyKey); 1024 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientBloodSampleOnlyKey); 1025 } 1026 else 1027 { 1028 // Patient with no sample 1029 jsonSite = updateJSONObjectCounter(jsonSite, patientNoSamplesKey); 1030 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, patientNoSamplesKey); 1031 } 1032 } 1033 } 1034 // Update summed patient data 1035 jsonSite = updateJSONObjectCounter(jsonSite, sumKey); 1036 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, sumKey); 1037 } 1038 } 1039 1040 // Add latest item date for site to site JSON object 1041 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 object 1054 jsonStatistics.put(latestDateKey, date2StringConverter.convert(latestDate)); 1055 // Add number of patients with no samples 1056 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 specimens 1063 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 specimens 1070 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 jsonReport 1081 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 645 1090 private Boolean inStringDateSetHashMap(HashMap<String, Set<Date>> stringDateSetHashMap, String string, Date date) 646 1091 {
Note: See TracChangeset
for help on using the changeset viewer.