Changeset 1744
- Timestamp:
- Nov 27, 2012, 12:46:18 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
r1732 r1744 271 271 <li>Sample count report</li> 272 272 <li>Consent count report</li> 273 <li>Patient count report</li> 273 274 </ul> 274 275 </dd> -
extensions/net.sf.basedb.reggie/trunk/resources/samplereportgenerator.jsp
r1743 r1744 67 67 // Set item name for report period text 68 68 document.getElementById("items01").innerHTML="tubes"; 69 // Set item name for report time step text 70 document.getElementById("items02").innerHTML="specimens"; 71 document.getElementById("items03").innerHTML="specimens"; 72 document.getElementById("items04").innerHTML="specimens"; 73 document.getElementById("items05").innerHTML="specimens"; 69 74 // Show view type pop-up menu 70 75 document.getElementById("viewTypeSubSection01").style.display = 'block'; … … 80 85 document.getElementById("viewTypeSubSection02").style.display = 'none'; 81 86 document.getElementById("viewTypeSubSection04").style.display = 'none'; 87 } 88 else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'patientcount') 89 { 90 // Set item name for report period text 91 document.getElementById("items01").innerHTML="patients"; 92 // Set item name for report time step text 93 document.getElementById("items02").innerHTML="patients"; 94 document.getElementById("items03").innerHTML="patients"; 95 document.getElementById("items04").innerHTML="patients"; 96 document.getElementById("items05").innerHTML="patients"; 97 // Show view type pop-up menu 98 document.getElementById("viewTypeSubSection01").style.display = 'block'; 99 document.getElementById("viewTypeSubSection02").style.display = 'block'; 100 document.getElementById("viewTypeSubSection04").style.display = 'block'; 82 101 } 83 102 Main.show('itemCountSection'); … … 150 169 frm.viewtype.disabled = true; 151 170 } 171 if (reportType == 'patientcount') 172 { 173 frm.viewtype.disabled = true; 174 } 152 175 Main.hide('gocreate'); 153 176 Main.show('reportSection'); … … 160 183 if (frm.viewtype.value != null) url += '&vtype='+frm.viewtype.value; 161 184 } 185 if (reportType == 'patientcount') 186 { 187 if (frm.viewtype.value != null) url += '&vtype='+frm.viewtype.value; 188 } 162 189 163 190 var request = Ajax.getXmlHttpRequest(); … … 179 206 if ('samplecount' == reportType) 180 207 { 181 reportTable = create SampleCountReport(report);208 reportTable = createItemCountReport(report, reportType); 182 209 } 183 210 else if ('consentcount' == reportType) 184 211 { 185 212 reportTable = createConsentCountReport(report); 213 } 214 if ('patientcount' == reportType) 215 { 216 reportTable = createItemCountReport(report, reportType); 186 217 } 187 218 } … … 240 271 summaryList.appendChild(getListElement(patientsWithMultipleDatesText)); 241 272 } 273 else if ('patientcount' == reportType) 274 { 275 summaryList.appendChild(getListElement(unknownSite + ' patients registered to unknown sites.')); 276 summaryList.appendChild(getListElement(unknownCreation + ' patients without creation date. These are included in the \'Total\' column.')); 277 } 242 278 cellElement.appendChild(summaryList); 243 279 if ('consentcount' == reportType) … … 250 286 } 251 287 252 function create SampleCountReport(report)288 function createItemCountReport(report, reportType) 253 289 { 254 290 var reportTable = getReportTable(); … … 284 320 var columnHeaderRow = document.createElement('tr'); 285 321 286 var headerText = '# Specimen by '; 322 var headerText = '# Item by '; 323 if ('samplecount' == reportType) 324 { 325 headerText = '# Specimen by '; 326 } 327 else if ('patientcount' == reportType) 328 { 329 headerText = '# Patients by '; 330 } 287 331 if (viewType == 'WEEK') 288 332 { … … 435 479 } 436 480 // Get total number of samples for site for the selected time period 437 var sum = statistics.sumKey;481 var sum = getJSONData(statistics, 'sumKey', 0); 438 482 // Add entry with total number of samples for site for the selected time period 439 483 sitesCombinedRow.appendChild(getTableCellElement(sum, 'colsummary')); 440 484 // Get total number of samples for all sites, regardless of creation date 441 var total = statistics.totalKey;485 var total = getJSONData(statistics, 'totalKey', 0); 442 486 // Add entry with total number of samples for all sites, regardless of creation date 443 487 sitesCombinedRow.appendChild(getTableCellElement(total, 'colsummary')); … … 557 601 } 558 602 // Add entry with total number of consents with chosen restrictions 559 data = getJSONData(sitesCombined, sumKey );603 data = getJSONData(sitesCombined, sumKey, 0); 560 604 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 561 605 // Add entry with total number of consents, regardless of restrictions 562 606 var totalKey = 'totalKey'; 563 data = getJSONData(sitesCombined, totalKey );607 data = getJSONData(sitesCombined, totalKey, 0); 564 608 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 565 609 reportTable.appendChild(sitesCombinedRow); … … 633 677 // Add entry with total number of consents with chosen restrictions 634 678 var noDateKey = 'noDate'; 635 data = getJSONData(sitesCombined, noDateKey );679 data = getJSONData(sitesCombined, noDateKey, 0); 636 680 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 637 681 // Add entry with total number of consents, regardless of restrictions 638 682 var totalKey = 'totalKey'; 639 data = getJSONData(sitesCombined, totalKey );683 data = getJSONData(sitesCombined, totalKey, 0); 640 684 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 641 685 reportTable.appendChild(sitesCombinedRow); … … 1059 1103 var siteData = statistics[namePrefix]; 1060 1104 var siteLatestDate = siteData['latestDateKey']; 1105 var siteLatestDateStr = '????-??-??'; 1106 if (siteLatestDate != null) 1107 { 1108 var siteLatestDateYear = siteLatestDate.substr(0,4); 1109 var siteLatestDateMonth = siteLatestDate.substr(4,2); 1110 var siteLatestDateDate = siteLatestDate.substr(6,2); 1111 siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate; 1112 } 1113 /* 1061 1114 var siteLatestDateYear = siteLatestDate.substr(0,4); 1062 1115 var siteLatestDateMonth = siteLatestDate.substr(4,2); 1063 1116 var siteLatestDateDate = siteLatestDate.substr(6,2); 1064 1117 var siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate; 1118 */ 1065 1119 var tableRow = document.createElement('tr'); 1066 1120 var tableCol = getTableCellElement(siteName, 'rowtitle'); … … 1308 1362 <option value="samplecount" selected="yes">Sample count report</option> 1309 1363 <option value="consentcount">Consent count report</option> 1364 <option value="patientcount">Patient count report</option> 1310 1365 </select> 1311 1366 </td> … … 1370 1425 Auto will adjust the report depending on the size of the period. 1371 1426 <ul> 1372 <li>Period shorter then 3 months - specimensper week</li>1373 <li>Period shorter then 13 months - specimensper month</li>1374 <li>Period shorter then 3 year - specimensper quarter</li>1375 <li>Period is 3 year or greater - specimensper year</li>1427 <li>Period shorter then 3 months - <text id="items02">items</text> per week</li> 1428 <li>Period shorter then 13 months - <text id="items03">items</text> per month</li> 1429 <li>Period shorter then 3 year - <text id="items04">items</text> per quarter</li> 1430 <li>Period is 3 year or greater - <text id="items05">items</text> per year</li> 1376 1431 </ul> 1377 1432 </div> -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java
r1738 r1744 10 10 import java.util.List; 11 11 import java.util.HashSet; 12 import java.util.Iterator; 12 13 import java.util.Set; 13 14 import java.util.TreeMap; … … 24 25 import net.sf.basedb.core.ItemQuery; 25 26 import net.sf.basedb.core.ItemResultIterator; 27 import net.sf.basedb.core.ItemSubtype; 28 import net.sf.basedb.core.MeasuredBioMaterial; 26 29 import net.sf.basedb.core.Sample; 27 30 import net.sf.basedb.core.SessionControl; … … 148 151 json = createConsentCountReport(dc, json, startDate, endDate); 149 152 } 153 else if ("patientcount".equals(cmd)) 154 { 155 String startDateParameter = Values.getString(req.getParameter("fdate"), null); 156 String endDateParameter = Values.getString(req.getParameter("tdate"), null); 157 158 Date startDate = Reggie.CONVERTER_STRING_TO_DATE.convert(startDateParameter); 159 Date endDate = Reggie.CONVERTER_STRING_TO_DATE.convert(endDateParameter); 160 161 if (startDate == null) 162 { 163 // Get the when the first site started 164 for (Site s : Site.getAllSites()) 165 { 166 Date siteDate = Reggie.CONVERTER_STRING_TO_DATE.convert(s.getStartDate().replaceAll("-", "")); 167 if (siteDate != null && (startDate == null || startDate.after(siteDate))) 168 { 169 startDate = siteDate; 170 } 171 } 172 } 173 if (endDate == null) 174 { 175 // Get the date for today 176 endDate = new Date(); 177 } 178 179 String viewType = null; 180 String viewTypeParameter = Values.getString(req.getParameter("vtype"), null); 181 if (viewTypeParameter != null && !viewTypeParameter.equals("AUTO")) 182 { 183 viewType = viewTypeParameter; 184 } 185 else 186 { 187 viewType = getViewType(startDate, endDate); 188 } 189 190 json = createPatientCountReport(dc, json, startDate, endDate, viewType); 191 } 150 192 } 151 193 catch (Throwable t) … … 179 221 sampleQuery.setCacheResult(true); 180 222 ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc); 223 // Store samples that should be processed for report table in list 224 List<Sample> sampleList = new ArrayList<Sample>(); 225 while (sampleIterator.hasNext()) 226 { 227 Sample s = sampleIterator.next(); 228 sampleList.add(s); 229 } 181 230 182 JSONObject jsonStatistics = createJSONStatistics(sampleIterator, startDate, endDate, viewType); 231 JSONObject jsonStatistics = createJSONStatistics(sampleList.iterator(), startDate, endDate, viewType); 232 jsonReport.put("statistics", jsonStatistics); 233 if (viewType == null) 234 { 235 viewType = getViewType(startDate, endDate); 236 } 237 DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING; 238 Date periodStartDate = calculatePeriodStartDate(startDate, viewType); 239 jsonReport.put("viewType", viewType); 240 jsonReport.put("beginDate", date2StringConverter.convert(startDate)); 241 jsonReport.put("endDate", date2StringConverter.convert(endDate)); 242 jsonReport.put("periodBeginDate", date2StringConverter.convert(periodStartDate)); 243 // Transfer latest date from jsonStatistics to jsonReport 244 String latestDateStr = (String) jsonStatistics.get("latestDateKey"); 245 jsonReport.put("latestDate", latestDateStr); 246 String siteOrder = alphabeticalOrder; 247 JSONObject jsonSiteOrderList = createJSONSiteOrderList(siteOrder); 248 jsonReport.put("siteOrderListKey", jsonSiteOrderList); 249 json.put("report", jsonReport); 250 return json; 251 } 252 253 private JSONObject createPatientCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String viewType) 254 throws ServletException, IOException 255 { 256 JSONObject jsonReport = new JSONObject(); 257 jsonReport.put("sites", getJSONSites()); 258 259 ItemQuery<Sample> sampleQuery = Sample.getQuery(); 260 sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true)); 261 // ...only include 'Specimen', 'No Specimen', or 'Blood' items 262 sampleQuery.restrict( 263 Restrictions.or( 264 Subtype.SPECIMEN.restriction(dc, null), 265 Subtype.NO_SPECIMEN.restriction(dc, null), 266 Subtype.BLOOD.restriction(dc, null) 267 )); 268 sampleQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); 269 sampleQuery.order(Orders.asc(Hql.property("name"))); 270 sampleQuery.order(Orders.asc(Hql.property("ce", "eventDate"))); 271 sampleQuery.setCacheResult(true); 272 ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc); 273 274 // Store samples that should be processed for report table in list 275 List<Sample> sampleList = new ArrayList<Sample>(); 276 // Create HashMap to keep track of sample with earliest date for each patient 277 HashMap<String, Sample>patientSampleHashMap = new HashMap<String, Sample>(); 278 // Create HashMap to keep track of sample with unknown date for each patient 279 HashMap<String, Sample>patientSampleNoDateHashMap = new HashMap<String, Sample>(); 280 // Find earliest sample dates for each patient 281 ItemSubtype subtypeBlood = Subtype.BLOOD.load(dc); 282 while (sampleIterator.hasNext()) 283 { 284 Sample s = sampleIterator.next(); 285 BioMaterialEvent creationEvent = s.getCreationEvent(); 286 Date creationDate = creationEvent.getEventDate(); 287 288 // Find patient id 289 BioMaterial patient = null; 290 if (s.getItemSubtype().equals(subtypeBlood)) 291 { 292 // The parent is the 'Patient' for blood samples 293 patient = s.getParent(); 294 } 295 else 296 { 297 // The grandparent is the 'Patient' for specimens and no specimens 298 MeasuredBioMaterial parent = (MeasuredBioMaterial) s.getParent(); 299 if (parent != null) 300 { 301 patient = parent.getParent(); 302 } 303 } 304 if (patient != null) 305 { 306 String patientName = patient.getName(); 307 if (creationDate != null) 308 { 309 patientSampleHashMap = updateStringEarliestSampleHashMap(patientSampleHashMap, patientName, s); 310 } 311 else 312 { 313 patientSampleNoDateHashMap.put(patientName, s); 314 } 315 } 316 } 317 // Create list of samples for report 318 // Add sample with earliest date for patient 319 for (String key: patientSampleHashMap.keySet()) 320 { 321 if (key != null && !key.equals("")) 322 { 323 Sample s = patientSampleHashMap.get(key); 324 // Include sample in list of samples for report 325 sampleList.add(s); 326 } 327 } 328 // Add sample with unknown date if no sample with date exists for patient 329 for (String key: patientSampleNoDateHashMap.keySet()) 330 { 331 if (key != null && !key.equals("")) 332 { 333 // If no sample with date exists for sample, include sample without date 334 if (!patientSampleHashMap.containsKey(key)) 335 { 336 Sample s = patientSampleNoDateHashMap.get(key); 337 // Include sample in list of samples for report 338 sampleList.add(s); 339 } 340 } 341 } 342 343 JSONObject jsonStatistics = createJSONStatistics(sampleList.iterator(), startDate, endDate, viewType); 183 344 jsonReport.put("statistics", jsonStatistics); 184 345 if (viewType == null) … … 534 695 } 535 696 536 private int numDatesInStringDateSetHashMap(HashMap<String, Set<Date>> stringDateSetHashMap)537 { 538 i nt numDates = 0;539 if (stringDateSetHashMap != null)540 {541 Set<String> stringSet = stringDateSetHashMap.keySet();542 if (stringSet != null)543 544 for (String string: stringSet)545 {546 Set<Date> dateSet = stringDateSetHashMap.get(string);547 if (dateSet != null)548 {549 numDates += dateSet.size();550 }551 }552 } 553 }554 return numDates;555 }556 557 private Set<String> keysWithMultipleDates(HashMap<String, Set<Date>> stringDateSetHashMap)558 {559 Set<String> keysWithMultipleDatesSet = new HashSet<String>();560 if (stringDateSetHashMap!= null)561 {562 Set<String> stringSet = stringDateSetHashMap.keySet();563 if (stringSet != null)564 {565 for (String string: stringSet)566 {567 Set<Date> dateSet = stringDateSetHashMap.get(string);568 if (dateSet != null && dateSet.size() > 1)569 570 keysWithMultipleDatesSet.add(string);571 }572 } 573 } 574 } 575 return keysWithMultipleDatesSet;697 private HashMap<String, Sample> updateStringEarliestSampleHashMap(HashMap<String, Sample> stringSampleHashMap, String string, Sample sample) 698 { 699 if (stringSampleHashMap == null) 700 { 701 stringSampleHashMap = new HashMap<String, Sample>(); 702 } 703 if (string != null && !string.equals("")) 704 { 705 // Store the sample with the earliest date for the item defined by string 706 Sample storedSample = stringSampleHashMap.get(string); 707 Date sampleDate = null; 708 Date storedSampleDate = null; 709 if (sample != null) 710 { 711 BioMaterialEvent creationEvent = sample.getCreationEvent(); 712 sampleDate = creationEvent.getEventDate(); 713 } 714 if (storedSample != null) 715 { 716 BioMaterialEvent creationEvent = storedSample.getCreationEvent(); 717 storedSampleDate = creationEvent.getEventDate(); 718 } 719 if (sampleDate != null) 720 { 721 if (storedSampleDate != null) 722 { 723 if (sampleDate.before(storedSampleDate)) 724 { 725 // New sample date earlier, store that sample for patient 726 stringSampleHashMap.put(string, sample); 727 } 728 } 729 else 730 { 731 // No stored sample; store new sample for patient 732 stringSampleHashMap.put(string, sample); 733 } 734 } 735 } 736 return stringSampleHashMap; 576 737 } 577 738 … … 610 771 } 611 772 612 private JSONObject createJSONStatistics(Ite mResultIterator<Sample> sampleIterator, Date startDate, Date endDate, String viewType)773 private JSONObject createJSONStatistics(Iterator<Sample> sampleIterator, Date startDate, Date endDate, String viewType) 613 774 throws ServletException, IOException 614 775 {
Note: See TracChangeset
for help on using the changeset viewer.