Changeset 1732
- Timestamp:
- Nov 13, 2012, 4:15:41 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
r1683 r1732 270 270 <ul> 271 271 <li>Sample count report</li> 272 <li>Consent count report</li> 272 273 </ul> 273 274 </dd> -
extensions/net.sf.basedb.reggie/trunk/resources/samplereportgenerator.jsp
r1730 r1732 67 67 Main.show('sampleCountSection'); 68 68 } 69 else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'consentcount') 70 { 71 Main.show('consentCountSection'); 72 } 69 73 70 74 Main.show('gocreate'); … … 162 166 reportTable = createSampleCountReport(report); 163 167 } 168 else if ('consentcount' == reportType) 169 { 170 reportTable = createConsentCountReport(report); 171 } 164 172 } 165 173 else … … 177 185 if (unknownSite == null) unknownSite = 0; 178 186 if (unknownCreation == null) unknownCreation = 0; 179 summaryList.appendChild(getListElement(unknownSite + ' specimens registered to unknown sites.')); 180 summaryList.appendChild(getListElement(unknownCreation + ' specimens without creation date. These are included in the \'Total\' column.')); 187 if ('samplecount' == reportType) 188 { 189 summaryList.appendChild(getListElement(unknownSite + ' specimens registered to unknown sites.')); 190 summaryList.appendChild(getListElement(unknownCreation + ' specimens without creation date. These are included in the \'Total\' column.')); 191 } 192 else if ('consentcount' == reportType) 193 { 194 var numDuplicates = 0; 195 if (report != null) 196 { 197 var statistics = report.statistics; 198 numDuplicates = statistics.duplicateKey; 199 } 200 if (numDuplicates == null) 201 { 202 numDuplicates = 0; 203 } 204 summaryList.appendChild(getListElement(unknownSite + ' consents registered to unknown sites.')); 205 summaryList.appendChild(getListElement(unknownCreation + ' consents without known date.')); 206 summaryList.appendChild(getListElement(numDuplicates + ' duplicates ignored.')); 207 208 var patientsWithMultipleDates = statistics.patientsWithMultipleDatesKey; 209 var counter = 0; 210 for (var key in patientsWithMultipleDates) 211 { 212 counter++; 213 } 214 var patientsWithMultipleDatesText = counter + ' patients with multiple dates.'; 215 summaryList.appendChild(getListElement(patientsWithMultipleDatesText)); 216 } 181 217 cellElement.appendChild(summaryList); 218 if ('consentcount' == reportType) 219 { 220 // Add table with patients with consents with multiple dates 221 var multipleDatesTable = createConsentTablePatientsWithMultipleDates(report); 222 cellElement.appendChild(multipleDatesTable); 223 } 182 224 Main.show('gorestart'); 183 225 } … … 354 396 { 355 397 key = sortedKeyArray[arrayIndex]; 356 var data = getJ sonData(sitesCombined, key);398 var data = getJSONData(sitesCombined, key); 357 399 // Add entry with sample sum for site for selected time period 358 400 sitesCombinedRow.appendChild(getTableCellElement(data,'colsummary')); … … 371 413 } 372 414 373 function getJsonData(jsonObject, key) 415 function createConsentCountReport(report) 416 { 417 var reportTable = getReportTable(); 418 /* 419 var sdString = report.beginDate; 420 var edString = report.endDate; 421 var psdString = report.periodBeginDate; 422 var ldString = report.latestDate; 423 var startDate = new Date(); 424 startDate.setYear(sdString.substr(0,4)); 425 startDate.setMonth(sdString.substr(4,2)-1); 426 startDate.setDate(sdString.substr(6)); 427 var endDate = new Date(); 428 endDate.setYear(edString.substr(0,4)); 429 endDate.setMonth(edString.substr(4,2)-1); 430 endDate.setDate(edString.substr(6)); 431 var periodStartDate = new Date(); 432 periodStartDate.setYear(psdString.substr(0,4)); 433 periodStartDate.setMonth(psdString.substr(4,2)-1); 434 periodStartDate.setDate(psdString.substr(6)); 435 var latestDate; 436 if (ldString != null) 437 { 438 latestDate = new Date(); 439 latestDate.setYear(ldString.substr(0,4)); 440 latestDate.setMonth(ldString.substr(4,2)-1); 441 latestDate.setDate(ldString.substr(6)); 442 } 443 444 var viewType = report.viewType; 445 */ 446 447 var headerRow = document.createElement('tr'); 448 var subHeaderRow = document.createElement('tr'); 449 var columnHeaderRow = document.createElement('tr'); 450 451 var numCols = 8; 452 var numDecimals = 0; 453 var headerText = '# Consent forms of different types for cases and blood samples'; 454 headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+3))); 455 456 // Subheader 457 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader')); 458 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader')); 459 460 //subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader')); 461 subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader')); 462 subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader')); 463 subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader')); 464 subHeaderRow.appendChild(getTableCellElement('No', 'reportsubheader')); 465 subHeaderRow.appendChild(getTableCellElement('No', 'reportsubheader')); 466 subHeaderRow.appendChild(getTableCellElement('Not asked', 'reportsubheader')); 467 subHeaderRow.appendChild(getTableCellElement('Not asked', 'reportsubheader')); 468 //subHeaderRow.appendChild(getTableCellElement('Other', 'reportsubheader')); 469 subHeaderRow.appendChild(getTableCellElement('Missing', 'reportsubheader')); 470 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader')); 471 //subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader')); 472 473 // Columnsheader 474 var siteHeader = getTableCellElement('Site', 'reportsubheader'); 475 var startDateHeader = getTableCellElement('Start date','reportsubheader'); 476 columnHeaderRow.appendChild(siteHeader); 477 columnHeaderRow.appendChild(startDateHeader); 478 479 //columnHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader')); 480 columnHeaderRow.appendChild(getTableCellElement('date, PAT#', 'reportsubheader')); 481 columnHeaderRow.appendChild(getTableCellElement('date, no PAT#', 'reportsubheader')); 482 columnHeaderRow.appendChild(getTableCellElement('no date', 'reportsubheader')); 483 columnHeaderRow.appendChild(getTableCellElement('date', 'reportsubheader')); 484 columnHeaderRow.appendChild(getTableCellElement('no date', 'reportsubheader')); 485 columnHeaderRow.appendChild(getTableCellElement('date', 'reportsubheader')); 486 columnHeaderRow.appendChild(getTableCellElement('no date', 'reportsubheader')); 487 //columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader')); 488 columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader')); 489 columnHeaderRow.appendChild(getTableCellElement('Sum', 'reportsubheader')); 490 //columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader')); 491 492 // Build table 493 reportTable.appendChild(headerRow); 494 reportTable.appendChild(subHeaderRow); 495 reportTable.appendChild(columnHeaderRow); 496 497 // Data rows 498 addDataRowsToConsentTable(report, reportTable); 499 500 // Add a row with the combined numbers for all sites for each period 501 var sitesCombinedRow = document.createElement('tr'); 502 sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary')); 503 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary')); 504 // Get combined numbers for all sites for each period 505 var sumKey = 'sumKey'; 506 var statistics = report.statistics; 507 var sitesCombined = statistics.sitesCombinedKey; 508 if (sitesCombined != null) 509 { 510 //data = getJSONDataRightPadded(sitesCombined, 'yes', sumKey, numDecimals); 511 //sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 512 data = getJSONDataWithPercent(sitesCombined, 'yesPatient', sumKey, numDecimals); 513 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 514 data = getJSONDataWithPercent(sitesCombined, 'yesNoPatient', sumKey, numDecimals); 515 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 516 data = getJSONDataWithPercent(sitesCombined, 'yesNoDate', sumKey, numDecimals); 517 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 518 data = getJSONDataWithPercent(sitesCombined, 'no', sumKey, numDecimals); 519 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 520 data = getJSONDataWithPercent(sitesCombined, 'noNoDate', sumKey, numDecimals); 521 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 522 data = getJSONDataWithPercent(sitesCombined, 'notAsked', sumKey, numDecimals); 523 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 524 data = getJSONDataWithPercent(sitesCombined, 'notAskedNoDate', sumKey, numDecimals); 525 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 526 //data = getJSONDataWithPercent(sitesCombined, 'other', sumKey, numDecimals); 527 //sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 528 data = getJSONDataWithPercent(sitesCombined, 'missing', sumKey, numDecimals); 529 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 530 } 531 // Add entry with total number of consents with chosen restrictions 532 data = getJSONData(sitesCombined, sumKey); 533 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 534 /* 535 // Add entry with total number of consents, regardless of restrictions 536 data = getJSONData(sitesCombined, totalKey); 537 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 538 */ 539 reportTable.appendChild(sitesCombinedRow); 540 541 return reportTable; 542 } 543 544 function createConsentTablePatientsWithMultipleDates(report) 545 { 546 var multipleDatesTable = getReportTable(); 547 var headerRow = document.createElement('tr'); 548 var columnHeaderRow = document.createElement('tr'); 549 550 // Table header 551 var numCols = 3; 552 var headerText = 'Consent forms with multiple dates for same patient'; 553 headerRow.appendChild(getTableCellElement(headerText, 'reportheader', numCols)); 554 555 // Columnsheader 556 columnHeaderRow.appendChild(getTableCellElement('Patient ID', 'reportsubheader')); 557 columnHeaderRow.appendChild(getTableCellElement('Date 1', 'reportsubheader')); 558 columnHeaderRow.appendChild(getTableCellElement('Date 2', 'reportsubheader')); 559 560 // Build table 561 multipleDatesTable.appendChild(headerRow); 562 multipleDatesTable.appendChild(columnHeaderRow); 563 564 // Data rows 565 if (report != null) 566 { 567 var statistics = report.statistics; 568 var sessionId = statistics.sessionIdKey; 569 var patientsWithMultipleDates = statistics.patientsWithMultipleDatesKey; 570 var patientnamePatientid = statistics.patientnamePatientidKey; 571 for (var patientName in patientsWithMultipleDates) 572 { 573 var tableRow = document.createElement('tr'); 574 // Add patient name to table 575 var patientIdStr = patientnamePatientid[patientName]; 576 var columnCell = document.createElement('td'); 577 var patientLinkStr = createLinkStr(patientName, patientIdStr, 'BIOSOURCE', 'View this sample', sessionId); 578 var tableCol = createTableCellElementHtml(patientLinkStr, 'reportdata'); 579 tableRow.appendChild(tableCol); 580 // Add dates to table in chronological order 581 var dateSet = patientsWithMultipleDates[patientName]; 582 var dateStr1 = ''; 583 var dateStr2 = ''; 584 for (var key in dateSet) 585 { 586 var dateStr = dateSet[key]; 587 if (dateStr1 == '') 588 { 589 dateStr1 = dateStr; 590 } 591 else if (dateStr > dateStr1) 592 { 593 dateStr2 = dateStr; 594 } 595 else 596 { 597 dateStr2 = dateStr1; 598 dateStr1 = dateStr; 599 } 600 } 601 var dateCol = ''; 602 dateCol = getTableCellElement(dateStr1, 'reportdata'); 603 tableRow.appendChild(dateCol); 604 dateCol = getTableCellElement(dateStr2, 'reportdata'); 605 tableRow.appendChild(dateCol); 606 multipleDatesTable.appendChild(tableRow); 607 } 608 } 609 610 return multipleDatesTable; 611 } 612 613 function addDataRowsToConsentTable(report, reportTable, numDecimals) 614 { 615 var sites = report.sites; 616 var statistics = report.statistics; 617 unknownCreation = statistics.noDate; 618 unknownSite = statistics.unknownSite; 619 for (namePrefix in sites) 620 { 621 if (!sites.hasOwnProperty(namePrefix)) continue; 622 var site = sites[namePrefix]; 623 var siteName = site.name; 624 var year = site.startDate.substr(0,4); 625 var month = site.startDate.substr(5,2); 626 var date = site.startDate.substr(8,2); 627 var siteStartDate = new Date(year, month-1, date); 628 629 var siteData = statistics[namePrefix]; 630 var tableRow = document.createElement('tr'); 631 var tableCol = getTableCellElement(siteName, 'rowtitle'); 632 tableRow.appendChild(tableCol); 633 tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata')); 634 //var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate()); 635 var sumKey = 'sumKey'; 636 if (siteData != null) 637 { 638 //data = getJSONDataWithPercent(siteData, 'yes', sumKey, numDecimals); 639 //tableRow.appendChild(getTableCellElement(data, 'reportdata')); 640 data = getJSONDataWithPercent(siteData, 'yesPatient', sumKey, numDecimals); 641 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 642 data = getJSONDataWithPercent(siteData, 'yesNoPatient', sumKey, numDecimals); 643 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 644 data = getJSONDataWithPercent(siteData, 'yesNoDate', sumKey, numDecimals); 645 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 646 data = getJSONDataWithPercent(siteData, 'no', sumKey, numDecimals); 647 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 648 data = getJSONDataWithPercent(siteData, 'noNoDate', sumKey, numDecimals); 649 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 650 data = getJSONDataWithPercent(siteData, 'notAsked', sumKey, numDecimals); 651 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 652 data = getJSONDataWithPercent(siteData, 'notAskedNoDate', sumKey, numDecimals); 653 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 654 //data = getJSONDataWithPercent(siteData, 'other', sumKey, numDecimals); 655 //tableRow.appendChild(getTableCellElement(data, 'reportdata')); 656 data = getJSONDataWithPercent(siteData, 'missing', sumKey, numDecimals); 657 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 658 // Add column with summed values for site 659 var siteSum = 0; 660 if (siteData != null) 661 { 662 if (siteData[sumKey] != null) 663 { 664 siteSum = siteData[sumKey]; 665 } 666 } 667 tableRow.appendChild(getTableCellElement(siteSum, 'rowsummary')); 668 } 669 /* 670 // Add column with total number of samples for site, regardless of creation date 671 var siteTotal = 0; 672 if (siteData != null) 673 { 674 var totalKey = 'totalKey'; 675 if (siteData[totalKey] != null) 676 { 677 siteTotal = siteData[totalKey]; 678 } 679 } 680 tableRow.appendChild(getTableCellElement(siteTotal, 'rowsummary')); 681 */ 682 reportTable.appendChild(tableRow); 683 } 684 } 685 686 function createLinkStr(linkName, idStr, itemTypeStr, titleStr, sessionId) 687 { 688 var linkStr = '<span class="link" onclick="Main.itemOnClick(event, \'' + sessionId + '\', \'' + itemTypeStr + '\', ' + idStr + ', false)" title="' + titleStr + '">' + linkName + '</span>'; 689 return linkStr; 690 } 691 692 function createTableCellElementHtml(html, clazz, colspan, rowspan) 693 { 694 var htmlStr = new String(html); 695 var cellElement = document.createElement('td'); 696 cellElement.innerHTML = htmlStr; 697 cellElement.setAttribute('class', clazz); 698 if (colspan != null) cellElement.setAttribute('colspan', colspan); 699 if (rowspan != null) cellElement.setAttribute('rowspan', rowspan); 700 701 return cellElement; 702 } 703 704 function getJSONDataWithPercent(jsonObject, key, sumKey, numDecimals) 705 { 706 var dataNum = getJSONData(jsonObject, key); 707 var dataSum = getJSONData(jsonObject, sumKey); 708 var dataPct = '0'; 709 if (dataSum != null || dataSum != 0) 710 { 711 dataPct = 100*dataNum/dataSum; 712 dataPct = dataPct.toFixed(numDecimals); 713 } 714 var data = dataNum + ' (' + dataPct + '%)'; 715 return data; 716 } 717 718 function getJSONData(jsonObject, key) 374 719 { 375 720 var data = ''; … … 387 732 return data; 388 733 } 389 734 390 735 function addQuarterColumnHeaders(columnHeaderRow, startDate) 391 736 { … … 793 1138 <td class="input"> 794 1139 <select name="reporttype"> 795 <option value="samplecount">Sample count report</option> 1140 <option value="samplecount" selected="yes">Sample count report</option> 1141 <option value="consentcount">Consent count report</option> 796 1142 </select> 797 1143 </td> … … 859 1205 </div> 860 1206 1207 <div id="consentCountSection" style="display:none;"> 1208 <p></p> 1209 <!-- 2. Report parameters--> 1210 <table border="0" cellspacing="0" cellpadding="0" class="stepform"> 1211 <tr> 1212 <td rowspan="3" class="stepno">2</td> 1213 <td class="steptitle">Report parameters</td> 1214 </tr> 1215 <tr> 1216 <td class="stepfields"> 1217 <table border="0" cellspacing="0" cellpadding="0" width="100%"> 1218 <tr> 1219 <td valign="top" class="prompt">No report parameters</td> 1220 <td valign="top" class="input"> 1221 </td> 1222 <td valign="top" class="status" id="displayInterval.status"></td> 1223 <td class="help"> 1224 <span id="displayInterval.message" class="message" style="display: none;"></span> 1225 Consent report will be generated irrespective of date for consent.<br> 1226 </td> 1227 </tr> 1228 </table> 1229 </td> 1230 </tr> 1231 </table> 1232 </div> 1233 861 1234 <div id="reportSection" style="display:none;"> 862 1235 <p></p> -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java
r1731 r1732 6 6 import java.util.Date; 7 7 import java.util.GregorianCalendar; 8 import java.util.HashMap; 8 9 import java.util.ArrayList; 9 10 import java.util.List; 11 import java.util.HashSet; 12 import java.util.Set; 10 13 11 14 import javax.servlet.ServletException; … … 15 18 16 19 import net.sf.basedb.core.Application; 20 import net.sf.basedb.core.BioMaterial; 17 21 import net.sf.basedb.core.BioMaterialEvent; 18 22 import net.sf.basedb.core.DbControl; … … 23 27 import net.sf.basedb.core.query.Hql; 24 28 import net.sf.basedb.core.query.Orders; 29 import net.sf.basedb.core.query.Restrictions; 30 import net.sf.basedb.core.snapshot.SnapshotManager; 25 31 import net.sf.basedb.reggie.Reggie; 26 32 import net.sf.basedb.reggie.Site; 27 33 import net.sf.basedb.reggie.converter.DateToStringConverter; 34 import net.sf.basedb.reggie.dao.Annotationtype; 28 35 import net.sf.basedb.reggie.dao.Subtype; 29 36 import net.sf.basedb.util.Values; … … 107 114 json = createSampleCountReport(dc, json, startDate, endDate, viewType); 108 115 } 116 else if ("consentcount".equals(cmd)) 117 { 118 json = createConsentCountReport(dc, json); 119 } 109 120 } 110 121 catch (Throwable t) … … 158 169 } 159 170 171 private JSONObject createConsentCountReport(DbControl dc, JSONObject json) 172 throws ServletException, IOException 173 { 174 JSONObject jsonReport = new JSONObject(); 175 jsonReport.put("sites", getJSONSites()); 176 177 ItemQuery<Sample> sampleQuery = Sample.getQuery(); 178 sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true)); 179 // ...only include 'Case' or 'Blood' items 180 sampleQuery.restrict( 181 Restrictions.or( 182 Subtype.CASE.restriction(dc, null), 183 Subtype.BLOOD.restriction(dc, null) 184 )); 185 sampleQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); 186 sampleQuery.order(Orders.asc(Hql.property("name"))); 187 sampleQuery.order(Orders.asc(Hql.property("ce", "eventDate"))); 188 sampleQuery.setCacheResult(true); 189 //List<Sample> samples = sampleQuery.list(dc); 190 ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc); 191 // Use stored annotation snapshots for performance reasons 192 SnapshotManager manager = new SnapshotManager(); 193 194 JSONObject jsonStatistics = new JSONObject(); 195 JSONObject jsonSitesCombined = new JSONObject(); 196 String yesKey = "yes"; 197 String noKey = "no"; 198 String noNoDateKey = "noNoDate"; 199 String notAskedKey = "notAsked"; 200 String notAskedNoDateKey = "notAskedNoDate"; 201 String yesPatientKey = "yesPatient"; 202 String yesNoPatientKey = "yesNoPatient"; 203 String yesNoDateKey = "yesNoDate"; 204 String otherKey = "other"; 205 String missingKey = "missing"; 206 String sitesCombinedKey = "sitesCombinedKey"; 207 String sumKey = "sumKey"; 208 String totalKey = "totalKey"; 209 String noDateKey = "noDate"; 210 String duplicateKey = "duplicateKey"; 211 jsonStatistics.put(sitesCombinedKey, jsonSitesCombined); 212 // Initialize site data to 0 for the different keys 213 jsonStatistics = initializeJSONSiteData(jsonStatistics, yesKey); 214 jsonStatistics = initializeJSONSiteData(jsonStatistics, noKey); 215 jsonStatistics = initializeJSONSiteData(jsonStatistics, noNoDateKey); 216 jsonStatistics = initializeJSONSiteData(jsonStatistics, notAskedKey); 217 jsonStatistics = initializeJSONSiteData(jsonStatistics, notAskedNoDateKey); 218 jsonStatistics = initializeJSONSiteData(jsonStatistics, yesPatientKey); 219 jsonStatistics = initializeJSONSiteData(jsonStatistics, yesNoPatientKey); 220 jsonStatistics = initializeJSONSiteData(jsonStatistics, yesNoDateKey); 221 jsonStatistics = initializeJSONSiteData(jsonStatistics, otherKey); 222 jsonStatistics = initializeJSONSiteData(jsonStatistics, missingKey); 223 //jsonStatistics = initializeJSONSiteData(jsonStatistics, sumKey); 224 //jsonStatistics = initializeJSONSiteData(jsonStatistics, totalKey); 225 // Initialize combined data to 0 for the different keys 226 jsonSitesCombined.put(yesKey, 0); 227 jsonSitesCombined.put(noKey, 0); 228 jsonSitesCombined.put(noNoDateKey, 0); 229 jsonSitesCombined.put(notAskedKey, 0); 230 jsonSitesCombined.put(notAskedNoDateKey, 0); 231 jsonSitesCombined.put(yesPatientKey, 0); 232 jsonSitesCombined.put(yesNoPatientKey, 0); 233 jsonSitesCombined.put(yesNoDateKey, 0); 234 jsonSitesCombined.put(otherKey, 0); 235 jsonSitesCombined.put(missingKey, 0); 236 jsonSitesCombined.put(sumKey, 0); 237 jsonSitesCombined.put(totalKey, 0); 238 // Initialize other data to 0 for different keys 239 jsonStatistics.put(noDateKey, 0); 240 jsonStatistics.put(duplicateKey, 0); 241 // Create HashMap to keep track of processed dates for each patient 242 HashMap<String, Set<Date>>patientDateSetHashMap = new HashMap<String, Set<Date>>(); 243 JSONObject jsonPatientnamePatientid = new JSONObject(); 244 while (sampleIterator.hasNext()) 245 { 246 Sample s = sampleIterator.next(); 247 BioMaterialEvent creationEvent = s.getCreationEvent(); 248 Date creationDate = creationEvent.getEventDate(); 249 250 Site site = Site.findByCaseName(s.getName()); 251 if (site == Site.UNKNOWN) 252 { 253 String key = "unknownSite"; 254 jsonStatistics = updateJSONObjectCounter(jsonStatistics, key); 255 } 256 else 257 { 258 // Get site info 259 JSONObject jsonSite = (JSONObject)jsonStatistics.get(site.getPrefix()); 260 if (jsonSite == null) 261 { 262 jsonSite = new JSONObject(); 263 jsonStatistics.put(site.getPrefix(), jsonSite); 264 } 265 266 String consent = (String) Annotationtype.CONSENT.getAnnotationValue(dc, manager, s); 267 // Get consent date 268 Date consentDate = (Date) Annotationtype.CONSENT_DATE.getAnnotationValue(dc, manager, s); 269 String key = missingKey; 270 Boolean duplicate = false; 271 if (consent != null) 272 { 273 if (consent.equals("Yes")) 274 { 275 key = yesKey; 276 // Check if a consent already exists for the same patient and date 277 if (consentDate != null) 278 { 279 // The parent is the 'Patient' 280 BioMaterial patient = s.getParent(); 281 if (patient != null) 282 { 283 // Store patient ID value 284 jsonPatientnamePatientid = updateJSONItemnameItemid(jsonPatientnamePatientid, patient); 285 key = yesPatientKey; 286 String patientName = patient.getName(); 287 if (inStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate)) 288 { 289 duplicate = true; 290 } 291 else 292 { 293 patientDateSetHashMap = updateStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate); 294 } 295 } 296 else 297 { 298 key = yesNoPatientKey; 299 } 300 } 301 else 302 { 303 key = yesNoDateKey; 304 } 305 } 306 else if (consent.equals("No")) 307 { 308 key = noKey; 309 // Check if consent date exists 310 if (consentDate == null) 311 { 312 key = noNoDateKey; 313 } 314 } 315 else if (consent.equals("Not asked")) 316 { 317 key = notAskedKey; 318 // Check if consent date exists 319 if (consentDate == null) 320 { 321 key = notAskedNoDateKey; 322 } 323 } 324 else 325 { 326 key = otherKey; 327 } 328 } 329 // Note that items with duplicate == false include missing consent items 330 if (!duplicate) 331 { 332 // Update consent counters 333 jsonSite = updateJSONObjectCounter(jsonSite, key); 334 jsonSite = updateJSONObjectCounter(jsonSite, sumKey); 335 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, key); 336 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, sumKey); 337 if (consentDate == null) 338 { 339 jsonStatistics = updateJSONObjectCounter(jsonStatistics, noDateKey); 340 } 341 } 342 else 343 { 344 jsonStatistics = updateJSONObjectCounter(jsonStatistics, duplicateKey); 345 } 346 } 347 } 348 // Create JSONObject (patient, dates) for patients with multiple dates 349 JSONObject jsonPatientsWithMultipleDates = createJSONPatientsWithMultipleDates(patientDateSetHashMap); 350 String patientsWithMultipleDatesKey = "patientsWithMultipleDatesKey"; 351 jsonStatistics.put(patientsWithMultipleDatesKey, jsonPatientsWithMultipleDates); 352 String patientnamePatientidKey = "patientnamePatientidKey"; 353 jsonStatistics.put(patientnamePatientidKey, jsonPatientnamePatientid); 354 String sessionIdKey = "sessionIdKey"; 355 jsonStatistics.put(sessionIdKey, dc.getSessionControl().getId()); 356 // 357 jsonReport.put("statistics", jsonStatistics); 358 json.put("report", jsonReport); 359 return json; 360 } 361 362 private Boolean inStringDateSetHashMap(HashMap<String, Set<Date>> stringDateSetHashMap, String string, Date date) 363 { 364 Boolean inHashMap = false; 365 if (stringDateSetHashMap != null && string != null && !string.equals("") && date != null) 366 { 367 Set<Date> dateSet = stringDateSetHashMap.get(string); 368 if (dateSet != null) 369 { 370 for (Date d: dateSet) 371 { 372 if (date.equals(d)) 373 { 374 inHashMap = true; 375 break; 376 } 377 } 378 } 379 } 380 return inHashMap; 381 } 382 383 private JSONObject updateJSONItemnameItemid(JSONObject jsonObject, BioMaterial item) 384 { 385 // Increase the counter for current key for the site 386 if (jsonObject == null) 387 { 388 jsonObject = new JSONObject(); 389 } 390 if (item != null) 391 { 392 int itemId = item.getId(); 393 String itemIdStr = Integer.toString(itemId); 394 jsonObject.put(item.getName(), itemIdStr); 395 } 396 return jsonObject; 397 } 398 399 private HashMap<String, Set<Date>> updateStringDateSetHashMap(HashMap<String, Set<Date>> stringDateSetHashMap, String string, Date date) 400 { 401 if (stringDateSetHashMap == null) 402 { 403 stringDateSetHashMap = new HashMap<String, Set<Date>>(); 404 } 405 if (string != null && !string.equals("") && date != null) 406 { 407 Set<Date> dateSet = stringDateSetHashMap.get(string); 408 Boolean dateInSet = false; 409 if (dateSet != null) 410 { 411 for (Date d: dateSet) 412 { 413 if (date.equals(d)) 414 { 415 dateInSet = true; 416 break; 417 } 418 } 419 } 420 if (!dateInSet) 421 { 422 if (dateSet == null) 423 { 424 dateSet = new HashSet<Date>(); 425 } 426 dateSet.add(date); 427 stringDateSetHashMap.put(string, dateSet); 428 } 429 } 430 return stringDateSetHashMap; 431 } 432 433 private int numDatesInStringDateSetHashMap(HashMap<String, Set<Date>> stringDateSetHashMap) 434 { 435 int numDates = 0; 436 if (stringDateSetHashMap != null) 437 { 438 Set<String> stringSet = stringDateSetHashMap.keySet(); 439 if (stringSet != null) 440 { 441 for (String string: stringSet) 442 { 443 Set<Date> dateSet = stringDateSetHashMap.get(string); 444 if (dateSet != null) 445 { 446 numDates += dateSet.size(); 447 } 448 } 449 } 450 } 451 return numDates; 452 } 453 454 private Set<String> keysWithMultipleDates(HashMap<String, Set<Date>> stringDateSetHashMap) 455 { 456 Set<String> keysWithMultipleDatesSet = new HashSet<String>(); 457 if (stringDateSetHashMap != null) 458 { 459 Set<String> stringSet = stringDateSetHashMap.keySet(); 460 if (stringSet != null) 461 { 462 for (String string: stringSet) 463 { 464 Set<Date> dateSet = stringDateSetHashMap.get(string); 465 if (dateSet != null && dateSet.size() > 1) 466 { 467 keysWithMultipleDatesSet.add(string); 468 } 469 } 470 } 471 } 472 return keysWithMultipleDatesSet; 473 } 474 475 private JSONObject createJSONPatientsWithMultipleDates(HashMap<String, Set<Date>> stringDateSetHashMap) 476 { 477 JSONObject jsonPatientsWithMultipleDates = new JSONObject(); 478 if (stringDateSetHashMap != null) 479 { 480 Set<String> patientNameSet = stringDateSetHashMap.keySet(); 481 if (patientNameSet != null) 482 { 483 for (String patient: patientNameSet) 484 { 485 Set<Date> dateSet = stringDateSetHashMap.get(patient); 486 if (dateSet != null && dateSet.size() > 1) 487 { 488 // More than one date 489 JSONObject jsonMultipleDates = new JSONObject(); 490 int dateCounter = 0; 491 for (Date date: dateSet) 492 { 493 if (date != null) 494 { 495 DateToStringConverter converter = new DateToStringConverter(new SimpleDateFormat("yyyy-MM-dd")); 496 String dateStr = converter.convert(date); 497 jsonMultipleDates.put(dateCounter, dateStr); 498 dateCounter++; 499 } 500 } 501 jsonPatientsWithMultipleDates.put(patient, jsonMultipleDates); 502 } 503 } 504 } 505 } 506 return jsonPatientsWithMultipleDates; 507 } 508 160 509 private JSONObject createJSONStatistics(ItemResultIterator<Sample> sampleIterator, Date startDate, Date endDate, String viewType) 161 510 throws ServletException, IOException … … 239 588 private JSONObject updateJSONObjectCounter(JSONObject jsonObject, String key) 240 589 { 241 242 590 // Increase the counter for current key for the site 243 591 Integer counter = (Integer)jsonObject.get(key); … … 249 597 jsonObject.put(key, counter); 250 598 return jsonObject; 599 } 600 601 private JSONObject initializeJSONSiteData(JSONObject jsonSiteContainerObject, String key) 602 { 603 if (jsonSiteContainerObject == null) 604 { 605 jsonSiteContainerObject = new JSONObject(); 606 } 607 for (Site site: Site.getAllSites()) 608 { 609 // Get JSON site object 610 JSONObject jsonSite = (JSONObject)jsonSiteContainerObject.get(site.getPrefix()); 611 if (jsonSite == null) 612 { 613 jsonSite = new JSONObject(); 614 jsonSiteContainerObject.put(site.getPrefix(), jsonSite); 615 } 616 // Set site date for key to 0 617 jsonSite.put(key, 0); 618 } 619 return jsonSiteContainerObject; 251 620 } 252 621
Note: See TracChangeset
for help on using the changeset viewer.