Changeset 1757 for extensions/net.sf.basedb.reggie/branches/ticket-422
- Timestamp:
- Nov 28, 2012, 9:41:46 AM (11 years ago)
- Location:
- extensions/net.sf.basedb.reggie/branches/ticket-422
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/net.sf.basedb.reggie/branches/ticket-422
- Property svn:mergeinfo changed
/extensions/net.sf.basedb.reggie/trunk (added) merged: 1735-1741,1743-1744,1747-1752,1754-1755
- Property svn:mergeinfo changed
-
extensions/net.sf.basedb.reggie/branches/ticket-422/.classpath
r1745 r1757 6 6 <classpathentry kind="lib" path="lib/compile/json_simple-1.1.jar"/> 7 7 <classpathentry kind="lib" path="lib/compile/jdom-1.1.2.jar"/> 8 <classpathentry kind="lib" path="lib/compile/base-core-3. 1.0.jar"/>9 <classpathentry kind="lib" path="lib/compile/base-webclient-3. 1.0.jar"/>10 <classpathentry kind="lib" path="lib/compile/base-webservices-client-3. 1.0.jar"/>8 <classpathentry kind="lib" path="lib/compile/base-core-3.2.0.jar"/> 9 <classpathentry kind="lib" path="lib/compile/base-webclient-3.2.0.jar"/> 10 <classpathentry kind="lib" path="lib/compile/base-webservices-client-3.2.0.jar"/> 11 11 <classpathentry kind="output" path=".build"/> 12 12 </classpath> -
extensions/net.sf.basedb.reggie/branches/ticket-422/META-INF/extensions.xml
r1725 r1757 7 7 and samples. 8 8 </description> 9 <version>2. 9-dev</version>10 <min-base-version>3. 1.0</min-base-version>9 <version>2.10-dev</version> 10 <min-base-version>3.2.0</min-base-version> 11 11 <copyright>BASE development team</copyright> 12 12 <email>basedb-users@lists.sourceforge.net</email> -
extensions/net.sf.basedb.reggie/branches/ticket-422/README
r1645 r1757 1 1 == Requirements == 2 2 3 1. BASE 3. 1or later.3 1. BASE 3.2 or later. 4 4 5 5 == Introduction == -
extensions/net.sf.basedb.reggie/branches/ticket-422/build.xml
r1725 r1757 10 10 <!-- variables used --> 11 11 <property name="name" value="reggie" /> 12 <property name="version" value="2. 9-dev" />12 <property name="version" value="2.10-dev" /> 13 13 <property name="src" location="src" description="Location of source files" /> 14 14 <property name="build" location="build" description="Location of compiled files" /> … … 22 22 <property name="javac.encoding" value="UTF-8" /> 23 23 <property name="depend.base-version" 24 value="3. 1.0"24 value="3.2.0" 25 25 description="The BASE version that this project depends on." 26 26 /> -
extensions/net.sf.basedb.reggie/branches/ticket-422/resources/export_monthly_oplist.jsp
r1721 r1757 41 41 url += '&time=' + frm.time.value; 42 42 url += '&exportSubtype='+(frm.exportSubtype.checked ? 1 : 0); 43 url += '&exportPatientId='+(frm.exportPatientId.checked ? 1 : 0); 43 44 if (preview) 44 45 { … … 72 73 { 73 74 var allLines = request.responseText.split('\n'); 74 var numLines = allLines.length - 1; 75 75 var numCases = allLines.length - 2; // First line is a header line 76 77 var html = '<tr><th>'+allLines[0].replace(/\t/g, '</th><th>')+'</th></tr>'; 76 78 // Check last column for the 'Consent' value. All should be 'YES' for the export to be ok. 77 79 var numNoConsent = 0; 78 80 var numMissingConsent = 0; 79 for (var i = 0 ; i < numLines; i++)81 for (var i = 1 ; i <= numCases; i++) 80 82 { 81 83 var line = allLines[i]; 82 var lastColIdx = line.lastIndexOf('\t');83 var lastCol = line.substr(lastColIdx+1);84 85 if ( lastCol!= 'YES')84 var cols = line.split(/\t/); 85 var consent = cols[cols.length-1]; 86 var rowClass = ''; 87 if (consent != 'YES') 86 88 { 87 if (lastCol == 'MISSING') 89 rowClass = 'consent-warning'; 90 if (consent == 'MISSING') 88 91 { 89 92 numMissingConsent++; … … 93 96 numNoConsent++; 94 97 } 95 allLines[i] = '<span class="consent-warning">'+line+'</span>';96 98 } 99 html += '<tr class="'+rowClass+'"><td>'+cols.join('</td><td>')+'</td></tr>'; 97 100 } 98 101 … … 105 108 } 106 109 107 previewTitle.innerHTML = 'Operation dates - ' + frm.time[frm.time.selectedIndex].text + ' (' + num Lines + ')';108 previewList.innerHTML = allLines.join('\n');110 previewTitle.innerHTML = 'Operation dates - ' + frm.time[frm.time.selectedIndex].text + ' (' + numCases + ')'; 111 previewList.innerHTML = '<table>'+html+'</table>'; 109 112 Main.show('previewWrapper'); 110 113 } … … 128 131 { 129 132 position: absolute; 130 top: 9em;133 top: 11em; 131 134 bottom: 1em; 132 135 left: 20px; … … 155 158 } 156 159 160 #previewList th 161 { 162 border-bottom: 1px dotted #A0A0A0; 163 } 164 165 #previewList td, #previewList th 166 { 167 text-align: left; 168 padding-right: 2em; 169 vertical-align: bottom; 170 } 171 157 172 .consent-warning 158 173 { 159 font-weight: bold;160 174 color: #A00000; 161 175 background-color: #F8F8E8; 162 176 } 163 177 164 .consent-warning:after 165 { 166 content: url('images/warning_small.png'); 167 vertical-align: middle; 178 .consent-warning td:last-child 179 { 180 background-image: url('images/warning_small.png'); 181 background-position: 95% 50%; 182 background-repeat: no-repeat; 168 183 } 169 184 … … 229 244 </tr> 230 245 231 <tr >246 <tr style="vertical-align: top;"> 232 247 <td class="prompt">Optional columns</td> 233 248 <td class="input"> 234 249 <input type="checkbox" name="exportSubtype" value="1" id="exportSubtype"> 235 <label for="exportSubtype">Specimen/NoSpecimen</label> 250 <label for="exportSubtype">Specimen/NoSpecimen</label><br> 251 <input type="checkbox" name="exportPatientId" value="1" id="exportPatientId"> 252 <label for="exportPatientId">Patient ID</label> 236 253 </td> 237 254 <td class="help"><span id="subtype.message" class="message" style="display: none;"></span></td> -
extensions/net.sf.basedb.reggie/branches/ticket-422/resources/index.jsp
r1745 r1757 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/branches/ticket-422/resources/samplereportgenerator.jsp
r1732 r1757 63 63 var frm = document.forms['reggie']; 64 64 frm.reporttype.disabled = true; 65 // Hide sample type pop-up menu 66 document.getElementById("sampleTypeSubSection01").style.display = 'none'; 67 document.getElementById("sampleTypeSubSection02").style.display = 'none'; 68 document.getElementById("sampleTypeSubSection04").style.display = 'none'; 65 69 if (frm.reporttype[frm.reporttype.selectedIndex].value == 'samplecount') 66 70 { 67 Main.show('sampleCountSection'); 71 // Set item name for report period text 72 document.getElementById("items01").innerHTML="tubes"; 73 // Set item name for report time step text 74 document.getElementById("items02").innerHTML="samples"; 75 document.getElementById("items03").innerHTML="samples"; 76 document.getElementById("items04").innerHTML="samples"; 77 document.getElementById("items05").innerHTML="samples"; 78 // Show view type pop-up menu 79 document.getElementById("viewTypeSubSection01").style.display = 'block'; 80 document.getElementById("viewTypeSubSection02").style.display = 'block'; 81 document.getElementById("viewTypeSubSection04").style.display = 'block'; 82 // Show sample type pop-up menu 83 document.getElementById("sampleTypeSubSection01").style.display = 'block'; 84 document.getElementById("sampleTypeSubSection02").style.display = 'block'; 85 document.getElementById("sampleTypeSubSection04").style.display = 'block'; 68 86 } 69 87 else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'consentcount') 70 88 { 71 Main.show('consentCountSection'); 72 } 89 // Set item name for report period text 90 document.getElementById("items01").innerHTML="consents"; 91 // Hide view type pop-up menu 92 document.getElementById("viewTypeSubSection01").style.display = 'none'; 93 document.getElementById("viewTypeSubSection02").style.display = 'none'; 94 document.getElementById("viewTypeSubSection04").style.display = 'none'; 95 } 96 else if (frm.reporttype[frm.reporttype.selectedIndex].value == 'patientcount') 97 { 98 // Set item name for report period text 99 document.getElementById("items01").innerHTML="patients"; 100 // Set item name for report time step text 101 document.getElementById("items02").innerHTML="patients"; 102 document.getElementById("items03").innerHTML="patients"; 103 document.getElementById("items04").innerHTML="patients"; 104 document.getElementById("items05").innerHTML="patients"; 105 // Show view type pop-up menu 106 document.getElementById("viewTypeSubSection01").style.display = 'block'; 107 document.getElementById("viewTypeSubSection02").style.display = 'block'; 108 document.getElementById("viewTypeSubSection04").style.display = 'block'; 109 } 110 Main.show('itemCountSection'); 73 111 74 112 Main.show('gocreate'); … … 132 170 var cellElement = document.getElementById('reportcell'); 133 171 var frm = document.forms['reggie']; 172 var reportType = frm.reporttype[frm.reporttype.selectedIndex].value; 134 173 frm.fromdate.disabled = true; 135 174 frm.todate.disabled = true; 136 frm.viewtype.disabled = true; 175 var sampleType = frm.sampletype[frm.sampletype.selectedIndex].value; 176 if (reportType == 'samplecount') 177 { 178 frm.viewtype.disabled = true; 179 frm.sampletype.disabled = true; 180 } 181 if (reportType == 'patientcount') 182 { 183 frm.viewtype.disabled = true; 184 } 137 185 Main.hide('gocreate'); 138 186 Main.show('reportSection'); 139 var reportType = frm.reporttype[frm.reporttype.selectedIndex].value;140 187 var url = 'SampleReport.servlet?ID=<%=ID%>&cmd='+reportType; 141 188 189 if (frm.fromdate.value != null) url += '&fdate='+frm.fromdate.value; 190 if (frm.todate.value != null) url += '&tdate='+frm.todate.value; 142 191 if (reportType == 'samplecount') 143 192 { 144 if (frm.fromdate.value != null) url += '&fdate='+frm.fromdate.value;145 if (frm.todate.value != null) url += '&tdate='+frm.todate.value;146 193 if (frm.viewtype.value != null) url += '&vtype='+frm.viewtype.value; 147 } 194 if (frm.sampletype.value != null) url += '&stype='+frm.sampletype.value; 195 } 196 if (reportType == 'patientcount') 197 { 198 if (frm.viewtype.value != null) url += '&vtype='+frm.viewtype.value; 199 } 200 148 201 var request = Ajax.getXmlHttpRequest(); 149 202 request.open("GET", url, false); … … 164 217 if ('samplecount' == reportType) 165 218 { 166 reportTable = create SampleCountReport(report);219 reportTable = createItemCountReport(report, reportType); 167 220 } 168 221 else if ('consentcount' == reportType) 169 222 { 170 223 reportTable = createConsentCountReport(report); 224 } 225 if ('patientcount' == reportType) 226 { 227 reportTable = createItemCountReport(report, reportType); 171 228 } 172 229 } … … 182 239 setInnerHTML('reportcell', ''); 183 240 cellElement.appendChild(reportTable); 241 // Optional extra tables 242 if ('consentcount' == reportType) 243 { 244 var spacer = document.createElement('text'); 245 spacer.innerHTML = "<BR>"; 246 cellElement.appendChild(spacer); 247 var unknownDateTable = createConsentCountUnknownDateTable(report); 248 cellElement.appendChild(unknownDateTable); 249 } 250 // Summary list 184 251 var summaryList = document.createElement('ul'); 185 252 if (unknownSite == null) unknownSite = 0; 186 253 if (unknownCreation == null) unknownCreation = 0; 187 254 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.')); 255 { 256 var samples = 'specimens'; 257 if ('blood' == sampleType) 258 { 259 samples = 'blood samples'; 260 } 261 summaryList.appendChild(getListElement(unknownSite + ' ' + samples + ' registered to unknown sites.')); 262 summaryList.appendChild(getListElement(unknownCreation + ' ' + samples + ' without creation date. These are included in the \'Total\' column.')); 191 263 } 192 264 else if ('consentcount' == reportType) … … 203 275 } 204 276 summaryList.appendChild(getListElement(unknownSite + ' consents registered to unknown sites.')); 205 summaryList.appendChild(getListElement(unknownCreation + ' consents without known date. '));277 summaryList.appendChild(getListElement(unknownCreation + ' consents without known date. These are included in the \'Total\' column.')); 206 278 summaryList.appendChild(getListElement(numDuplicates + ' duplicates ignored.')); 207 279 … … 215 287 summaryList.appendChild(getListElement(patientsWithMultipleDatesText)); 216 288 } 289 else if ('patientcount' == reportType) 290 { 291 summaryList.appendChild(getListElement(unknownSite + ' patients registered to unknown sites.')); 292 summaryList.appendChild(getListElement(unknownCreation + ' patients without creation date. These are included in the \'Total\' column.')); 293 } 217 294 cellElement.appendChild(summaryList); 218 295 if ('consentcount' == reportType) … … 225 302 } 226 303 227 function create SampleCountReport(report)304 function createItemCountReport(report, reportType) 228 305 { 229 306 var reportTable = getReportTable(); … … 254 331 255 332 var viewType = report.viewType; 333 var sampleType = report.sampleType; 256 334 257 335 var headerRow = document.createElement('tr'); … … 259 337 var columnHeaderRow = document.createElement('tr'); 260 338 261 var headerText = '# Specimen by '; 339 var headerText = '# Items by '; 340 if ('samplecount' == reportType) 341 { 342 headerText = '# Specimens by '; 343 if ('blood' == sampleType) 344 { 345 headerText = '# Blood samples by '; 346 } 347 } 348 else if ('patientcount' == reportType) 349 { 350 headerText = '# Patients by '; 351 } 262 352 if (viewType == 'WEEK') 263 353 { … … 280 370 else if (viewType == 'QUARTER') 281 371 { 282 // First year372 // First year (from start quarter to end of year) 283 373 numCols = 4 - Math.floor(periodStartDate.getMonth()/3); 374 // Last year (from start of year to end quarter) 284 375 numCols += Math.floor(endDate.getMonth()/3)+1; 376 // If first and last year is the same, subtract 4 quarters 377 if (endDate.getFullYear() - periodStartDate.getFullYear() == 0) 378 { 379 numCols -= 4; 380 } 381 // Full years between start and end dates 285 382 if((endDate.getFullYear() - periodStartDate.getFullYear()) > 1) 286 383 { … … 350 447 headerText += latestDate.getDate(); 351 448 } 352 headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+ 4)));449 headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+5))); 353 450 354 451 // Sub headers … … 356 453 if (viewType != 'YEAR') 357 454 { 358 subHeaderRowYear.appendChild(getTableCellElement('', 'reportsubheader', 2));455 subHeaderRowYear.appendChild(getTableCellElement('', 'reportsubheader', 3)); 359 456 addYearSubHeaders(periodStartDate, endDate, subHeaderRowYear, viewType); 360 457 subHeaderRowYear.appendChild(getTableCellElement('', 'reportsubheader', 2)); … … 364 461 var siteHeader = getTableCellElement('Site', 'reportsubheader'); 365 462 var startDateHeader = getTableCellElement('Start date','reportsubheader'); 463 var latestDateHeader = getTableCellElement('Latest date','reportsubheader'); 366 464 columnHeaderRow.appendChild(siteHeader); 367 465 columnHeaderRow.appendChild(startDateHeader); 466 columnHeaderRow.appendChild(latestDateHeader); 368 467 369 468 if (viewType == 'MONTH') addMonthColumnHeaders(columnHeaderRow, periodStartDate); … … 387 486 var sitesCombinedRow = document.createElement('tr'); 388 487 sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary')); 389 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary' ));488 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary', 2)); 390 489 // Get combined numbers for all sites for each period 391 490 var statistics = report.statistics; … … 396 495 { 397 496 key = sortedKeyArray[arrayIndex]; 398 var data = getJSONData(sitesCombined, key );497 var data = getJSONData(sitesCombined, key, 0); 399 498 // Add entry with sample sum for site for selected time period 400 499 sitesCombinedRow.appendChild(getTableCellElement(data,'colsummary')); 401 500 } 402 501 // Get total number of samples for site for the selected time period 403 var sum = statistics.sumKey;502 var sum = getJSONData(statistics, 'sumKey', 0); 404 503 // Add entry with total number of samples for site for the selected time period 405 504 sitesCombinedRow.appendChild(getTableCellElement(sum, 'colsummary')); 406 505 // Get total number of samples for all sites, regardless of creation date 407 var total = statistics.totalKey;506 var total = getJSONData(statistics, 'totalKey', 0); 408 507 // Add entry with total number of samples for all sites, regardless of creation date 409 508 sitesCombinedRow.appendChild(getTableCellElement(total, 'colsummary')); … … 416 515 { 417 516 var reportTable = getReportTable(); 418 /*419 517 var sdString = report.beginDate; 420 518 var edString = report.endDate; 519 /* 421 520 var psdString = report.periodBeginDate; 521 */ 422 522 var ldString = report.latestDate; 423 523 var startDate = new Date(); … … 429 529 endDate.setMonth(edString.substr(4,2)-1); 430 530 endDate.setDate(edString.substr(6)); 531 /* 431 532 var periodStartDate = new Date(); 432 533 periodStartDate.setYear(psdString.substr(0,4)); 433 534 periodStartDate.setMonth(psdString.substr(4,2)-1); 434 535 periodStartDate.setDate(psdString.substr(6)); 536 */ 435 537 var latestDate; 436 538 if (ldString != null) … … 441 543 latestDate.setDate(ldString.substr(6)); 442 544 } 443 545 546 /* 444 547 var viewType = report.viewType; 445 548 */ … … 449 552 var columnHeaderRow = document.createElement('tr'); 450 553 451 var numCols = 8;554 var numCols = 5; 452 555 var numDecimals = 0; 453 556 var headerText = '# Consent forms of different types for cases and blood samples'; 454 headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+3))); 557 var startDateStr = addHyphensToDateString(sdString); 558 var endDateStr = addHyphensToDateString(edString); 559 var latestDateStr = addHyphensToDateString(ldString); 560 headerText += ' (betweeen ' + startDateStr + ' and ' + endDateStr + ')'; 561 if (latestDate != null) 562 { 563 headerText += '\nLast registration ' + latestDateStr; 564 } 565 headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+5))); 455 566 456 567 // Subheader 457 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader')); 458 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader')); 459 460 //subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader')); 461 subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader')); 568 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 3)); 569 462 570 subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader')); 463 571 subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader')); 464 572 subHeaderRow.appendChild(getTableCellElement('No', 'reportsubheader')); 465 subHeaderRow.appendChild(getTableCellElement('No', 'reportsubheader'));466 573 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')); 574 subHeaderRow.appendChild(getTableCellElement('Unknown date', 'reportsubheader')); 575 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 2)); 472 576 473 577 // Columnsheader 474 578 var siteHeader = getTableCellElement('Site', 'reportsubheader'); 475 579 var startDateHeader = getTableCellElement('Start date','reportsubheader'); 580 var latestDateHeader = getTableCellElement('Latest date','reportsubheader'); 476 581 columnHeaderRow.appendChild(siteHeader); 477 582 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')); 583 columnHeaderRow.appendChild(latestDateHeader); 584 585 columnHeaderRow.appendChild(getTableCellElement('(has PAT#)', 'reportsubheader')); 586 columnHeaderRow.appendChild(getTableCellElement('(no PAT#)', 'reportsubheader')); 587 columnHeaderRow.appendChild(getTableCellElement('(has date)', 'reportsubheader')); 588 columnHeaderRow.appendChild(getTableCellElement('(has date)', 'reportsubheader')); 488 589 columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader')); 489 590 columnHeaderRow.appendChild(getTableCellElement('Sum', 'reportsubheader')); 490 //columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader'));591 columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader')); 491 592 492 593 // Build table … … 501 602 var sitesCombinedRow = document.createElement('tr'); 502 603 sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary')); 503 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary')); 604 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary', 2)); 605 // Get combined numbers for all sites for each period 606 var noDateKey = 'noDate'; 607 var sumKey = 'sumKey'; 608 var statistics = report.statistics; 609 var sitesCombined = statistics.sitesCombinedKey; 610 if (sitesCombined != null) 611 { 612 data = getJSONDataWithPercent(sitesCombined, 'yesPatient', sumKey, numDecimals); 613 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 614 data = getJSONDataWithPercent(sitesCombined, 'yesNoPatient', sumKey, numDecimals); 615 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 616 data = getJSONDataWithPercent(sitesCombined, 'no', sumKey, numDecimals); 617 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 618 data = getJSONDataWithPercent(sitesCombined, 'notAsked', sumKey, numDecimals); 619 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 620 data = getJSONDataWithPercent(sitesCombined, noDateKey, sumKey, numDecimals); 621 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 622 } 623 // Add entry with total number of consents with chosen restrictions 624 data = getJSONData(sitesCombined, sumKey, 0); 625 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 626 // Add entry with total number of consents, regardless of restrictions 627 var totalKey = 'totalKey'; 628 data = getJSONData(sitesCombined, totalKey, 0); 629 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 630 reportTable.appendChild(sitesCombinedRow); 631 632 return reportTable; 633 } 634 635 function createConsentCountUnknownDateTable(report) 636 { 637 var reportTable = getReportTable(); 638 var headerRow = document.createElement('tr'); 639 var subHeaderRow = document.createElement('tr'); 640 var columnHeaderRow = document.createElement('tr'); 641 642 var numCols = 4; 643 var numDecimals = 0; 644 var headerText = '# Consent forms of different types for cases and blood samples, unknown consent date'; 645 headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+5))); 646 647 // Subheader 648 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 3)); 649 650 subHeaderRow.appendChild(getTableCellElement('Yes', 'reportsubheader')); 651 subHeaderRow.appendChild(getTableCellElement('No', 'reportsubheader')); 652 subHeaderRow.appendChild(getTableCellElement('Not asked', 'reportsubheader')); 653 subHeaderRow.appendChild(getTableCellElement('Missing', 'reportsubheader')); 654 subHeaderRow.appendChild(getTableCellElement('', 'reportsubheader', 2)); 655 656 // Columnsheader 657 var siteHeader = getTableCellElement('Site', 'reportsubheader'); 658 var startDateHeader = getTableCellElement('Start date','reportsubheader'); 659 var latestDateHeader = getTableCellElement('Latest date','reportsubheader'); 660 columnHeaderRow.appendChild(siteHeader); 661 columnHeaderRow.appendChild(startDateHeader); 662 columnHeaderRow.appendChild(latestDateHeader); 663 664 columnHeaderRow.appendChild(getTableCellElement('(no date)', 'reportsubheader')); 665 columnHeaderRow.appendChild(getTableCellElement('(no date)', 'reportsubheader')); 666 columnHeaderRow.appendChild(getTableCellElement('(no date)', 'reportsubheader')); 667 columnHeaderRow.appendChild(getTableCellElement('', 'reportsubheader')); 668 columnHeaderRow.appendChild(getTableCellElement('Sum', 'reportsubheader')); 669 columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader')); 670 671 // Build table 672 reportTable.appendChild(headerRow); 673 reportTable.appendChild(subHeaderRow); 674 reportTable.appendChild(columnHeaderRow); 675 676 // Data rows 677 addDataRowsToConsentTableUnknownDate(report, reportTable); 678 679 // Add a row with the combined numbers for all sites for each period 680 var sitesCombinedRow = document.createElement('tr'); 681 sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary')); 682 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary', 2)); 504 683 // Get combined numbers for all sites for each period 505 684 var sumKey = 'sumKey'; … … 508 687 if (sitesCombined != null) 509 688 { 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 689 data = getJSONDataWithPercent(sitesCombined, 'yesNoDate', sumKey, numDecimals); 517 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));518 data = getJSONDataWithPercent(sitesCombined, 'no', sumKey, numDecimals);519 690 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 520 691 data = getJSONDataWithPercent(sitesCombined, 'noNoDate', sumKey, numDecimals); 521 692 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 522 data = getJSONDataWithPercent(sitesCombined, 'notAsked', sumKey, numDecimals);523 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));524 693 data = getJSONDataWithPercent(sitesCombined, 'notAskedNoDate', sumKey, numDecimals); 525 694 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 526 //data = getJSONDataWithPercent(sitesCombined, 'other', sumKey, numDecimals);527 //sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary'));528 695 data = getJSONDataWithPercent(sitesCombined, 'missing', sumKey, numDecimals); 529 696 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 530 697 } 531 698 // Add entry with total number of consents with chosen restrictions 532 data = getJSONData(sitesCombined, sumKey); 699 var noDateKey = 'noDate'; 700 data = getJSONData(sitesCombined, noDateKey, 0); 533 701 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 534 /*535 702 // Add entry with total number of consents, regardless of restrictions 536 data = getJSONData(sitesCombined, totalKey); 703 var totalKey = 'totalKey'; 704 data = getJSONData(sitesCombined, totalKey, 0); 537 705 sitesCombinedRow.appendChild(getTableCellElement(data, 'colsummary')); 538 */539 706 reportTable.appendChild(sitesCombinedRow); 540 707 … … 542 709 } 543 710 711 function addHyphensToDateString(yyyymmddStr) 712 { 713 var dateWithHyphensStr = '????-??-??'; 714 if (yyyymmddStr != null) 715 { 716 var yyyyStr = yyyymmddStr.substr(0,4); 717 var mmStr = yyyymmddStr.substr(4,2); 718 var ddStr = yyyymmddStr.substr(6); 719 dateWithHyphensStr = yyyyStr + '-' + mmStr + '-' + ddStr; 720 } 721 return dateWithHyphensStr; 722 } 723 544 724 function createConsentTablePatientsWithMultipleDates(report) 545 725 { … … 617 797 unknownCreation = statistics.noDate; 618 798 unknownSite = statistics.unknownSite; 619 for (namePrefix in sites) 620 { 799 var siteOrderList = report.siteOrderListKey; 800 for (var siteOrderIndex in siteOrderList) 801 { 802 var namePrefix = siteOrderList[siteOrderIndex]; 621 803 if (!sites.hasOwnProperty(namePrefix)) continue; 622 804 var site = sites[namePrefix]; … … 628 810 629 811 var siteData = statistics[namePrefix]; 812 var siteLatestDate = siteData['latestDateKey']; 813 var siteLatestDateYear = siteLatestDate.substr(0,4); 814 var siteLatestDateMonth = siteLatestDate.substr(4,2); 815 var siteLatestDateDate = siteLatestDate.substr(6,2); 816 var siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate; 630 817 var tableRow = document.createElement('tr'); 631 818 var tableCol = getTableCellElement(siteName, 'rowtitle'); 632 819 tableRow.appendChild(tableCol); 633 820 tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata')); 821 tableRow.appendChild(getTableCellElement(siteLatestDateStr, 'reportdata')); 634 822 //var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate()); 823 var noDateKey = 'noDate'; 635 824 var sumKey = 'sumKey'; 825 var totalKey = 'totalKey'; 636 826 if (siteData != null) 637 827 { 638 //data = getJSONDataWithPercent(siteData, 'yes', sumKey, numDecimals);639 //tableRow.appendChild(getTableCellElement(data, 'reportdata'));640 828 data = getJSONDataWithPercent(siteData, 'yesPatient', sumKey, numDecimals); 641 829 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 642 830 data = getJSONDataWithPercent(siteData, 'yesNoPatient', sumKey, numDecimals); 643 831 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 832 data = getJSONDataWithPercent(siteData, 'no', sumKey, numDecimals); 833 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 834 data = getJSONDataWithPercent(siteData, 'notAsked', sumKey, numDecimals); 835 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 836 data = getJSONDataWithPercent(siteData, noDateKey, sumKey, numDecimals); 837 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 838 // Add column with summed values for site 839 var siteSum = getJSONData(siteData, sumKey, 0); 840 tableRow.appendChild(getTableCellElement(siteSum, 'rowsummary')); 841 } 842 // Add column with total number of samples for site, regardless of creation date 843 var siteTotal = getJSONData(siteData, totalKey, 0); 844 tableRow.appendChild(getTableCellElement(siteTotal, 'rowsummary')); 845 reportTable.appendChild(tableRow); 846 } 847 } 848 849 function addDataRowsToConsentTableUnknownDate(report, reportTable, numDecimals) 850 { 851 var sites = report.sites; 852 var statistics = report.statistics; 853 unknownCreation = statistics.noDate; 854 unknownSite = statistics.unknownSite; 855 var siteOrderList = report.siteOrderListKey; 856 for (var siteOrderIndex in siteOrderList) 857 { 858 var namePrefix = siteOrderList[siteOrderIndex]; 859 if (!sites.hasOwnProperty(namePrefix)) continue; 860 var site = sites[namePrefix]; 861 var siteName = site.name; 862 var year = site.startDate.substr(0,4); 863 var month = site.startDate.substr(5,2); 864 var date = site.startDate.substr(8,2); 865 var siteStartDate = new Date(year, month-1, date); 866 867 var siteData = statistics[namePrefix]; 868 var siteLatestDate = siteData['latestDateKey']; 869 var siteLatestDateYear = siteLatestDate.substr(0,4); 870 var siteLatestDateMonth = siteLatestDate.substr(4,2); 871 var siteLatestDateDate = siteLatestDate.substr(6,2); 872 var siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate; 873 var tableRow = document.createElement('tr'); 874 var tableCol = getTableCellElement(siteName, 'rowtitle'); 875 tableRow.appendChild(tableCol); 876 tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata')); 877 tableRow.appendChild(getTableCellElement(siteLatestDateStr, 'reportdata')); 878 //var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate()); 879 var noDateKey = 'noDate'; 880 var sumKey = 'sumKey'; 881 var totalKey = 'totalKey'; 882 if (siteData != null) 883 { 644 884 data = getJSONDataWithPercent(siteData, 'yesNoDate', sumKey, numDecimals); 645 tableRow.appendChild(getTableCellElement(data, 'reportdata'));646 data = getJSONDataWithPercent(siteData, 'no', sumKey, numDecimals);647 885 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 648 886 data = getJSONDataWithPercent(siteData, 'noNoDate', sumKey, numDecimals); 649 887 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 650 data = getJSONDataWithPercent(siteData, 'notAsked', sumKey, numDecimals);651 tableRow.appendChild(getTableCellElement(data, 'reportdata'));652 888 data = getJSONDataWithPercent(siteData, 'notAskedNoDate', sumKey, numDecimals); 653 889 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 654 //data = getJSONDataWithPercent(siteData, 'other', sumKey, numDecimals);655 //tableRow.appendChild(getTableCellElement(data, 'reportdata'));656 890 data = getJSONDataWithPercent(siteData, 'missing', sumKey, numDecimals); 657 891 tableRow.appendChild(getTableCellElement(data, 'reportdata')); 658 892 // 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 } 893 var siteSum = getJSONData(siteData, noDateKey, 0); 667 894 tableRow.appendChild(getTableCellElement(siteSum, 'rowsummary')); 668 895 } 669 /*670 896 // 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 } 897 var siteTotal = getJSONData(siteData, totalKey, 0); 680 898 tableRow.appendChild(getTableCellElement(siteTotal, 'rowsummary')); 681 */682 899 reportTable.appendChild(tableRow); 683 900 } … … 718 935 function getJSONData(jsonObject, key) 719 936 { 720 var data = ''; 937 var data = getJSONData(jsonObject, key, ''); 938 return data; 939 } 940 941 function getJSONData(jsonObject, key, defaultChoice) 942 { 943 var data = defaultChoice; 721 944 if (jsonObject != null) 722 945 { … … 726 949 } 727 950 } 951 /* 728 952 else 729 953 { 730 954 data = 'jsonObject==null'; 731 955 } 956 */ 732 957 return data; 733 958 } … … 885 1110 unknownCreation = statistics.noDate; 886 1111 unknownSite = statistics.unknownSite; 887 for (namePrefix in sites) 888 { 889 if (!sites.hasOwnProperty(namePrefix)) continue; 1112 var siteOrderList = report.siteOrderListKey; 1113 for (var siteOrderIndex in siteOrderList) 1114 { 1115 var namePrefix = siteOrderList[siteOrderIndex]; 1116 if (!sites.hasOwnProperty(namePrefix)) continue; 890 1117 var site = sites[namePrefix]; 891 var siteName = site.name; 1118 var siteName = site.name; 892 1119 var year = site.startDate.substr(0,4); 893 1120 var month = site.startDate.substr(5,2); … … 895 1122 var siteStartDate = new Date(year, month-1, date); 896 1123 897 var siteData = statistics[namePrefix]; 1124 var siteData = statistics[namePrefix]; 1125 var siteLatestDate = siteData['latestDateKey']; 1126 var siteLatestDateStr = '????-??-??'; 1127 if (siteLatestDate != null) 1128 { 1129 var siteLatestDateYear = siteLatestDate.substr(0,4); 1130 var siteLatestDateMonth = siteLatestDate.substr(4,2); 1131 var siteLatestDateDate = siteLatestDate.substr(6,2); 1132 siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate; 1133 } 1134 /* 1135 var siteLatestDateYear = siteLatestDate.substr(0,4); 1136 var siteLatestDateMonth = siteLatestDate.substr(4,2); 1137 var siteLatestDateDate = siteLatestDate.substr(6,2); 1138 var siteLatestDateStr = siteLatestDateYear + '-' + siteLatestDateMonth + '-' + siteLatestDateDate; 1139 */ 898 1140 var tableRow = document.createElement('tr'); 899 1141 var tableCol = getTableCellElement(siteName, 'rowtitle'); 900 1142 tableRow.appendChild(tableCol); 901 1143 tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata')); 1144 tableRow.appendChild(getTableCellElement(siteLatestDateStr, 'reportdata')); 902 1145 var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate()); 903 1146 var columnCounter = 0; … … 1140 1383 <option value="samplecount" selected="yes">Sample count report</option> 1141 1384 <option value="consentcount">Consent count report</option> 1385 <option value="patientcount">Patient count report</option> 1142 1386 </select> 1143 1387 </td> … … 1153 1397 </table> 1154 1398 1155 <div id=" sampleCountSection" style="display:none;">1399 <div id="itemCountSection" style="display:none;"> 1156 1400 <p></p> 1157 1401 <!-- 2. Report parameters--> … … 1173 1417 <td class="help"> 1174 1418 <span id="displayInterval.message" class="message" style="display: none;"></span> 1175 Define which period the report should cover. Empty fields will include all tubes.<br>1419 Define which period the report should cover. Empty fields will include all <text id="items01">items</text>.<br> 1176 1420 </td> 1177 1421 </tr> 1178 <tr> 1179 <td valign="top" class="prompt">View type</td> 1422 <tr> 1423 <td valign="top" class="prompt"> 1424 <div id="viewTypeSubSection01" style="display:none;"> 1425 View type 1426 </div> 1427 </td> 1180 1428 <td valign="top" class="input"> 1181 <select name="viewtype"> 1182 <option value="AUTO" selected="yes">Auto</option> 1183 <option value="WEEK">Week</option> 1184 <option value="MONTH">Month</option> 1185 <option value="QUARTER">Quarter</option> 1186 <option value="YEAR">Year</option> 1187 </select> 1429 <div id="viewTypeSubSection02" style="display:none;"> 1430 <select name="viewtype"> 1431 <option value="AUTO" selected="yes">Auto</option> 1432 <option value="WEEK">Week</option> 1433 <option value="MONTH">Month</option> 1434 <option value="QUARTER">Quarter</option> 1435 <option value="YEAR">Year</option> 1436 </select> 1437 </div> 1188 1438 </td> 1189 1439 <td valign="top" class="status" id="displayViewType.status"></td> 1190 1440 <td class="help"> 1191 <span id="displayViewType.message" class="message" style="display: none;"></span> 1192 Auto will adjust the report depending on the size of the period. 1193 <ul> 1194 <li>Period shorter then 3 months - specimens per week</li> 1195 <li>Period shorter then 13 months - specimens per month</li> 1196 <li>Period shorter then 3 year - specimens per quarter</li> 1197 <li>Period is 3 year or greater - specimens per year</li> 1198 </ul> 1441 <div id="viewTypeSubSection04" style="display:none;"> 1442 <span id="displayViewType.message" class="message" style="display: none;"></span> 1443 Auto will adjust the report depending on the size of the period. 1444 <ul> 1445 <li>Period shorter than 3 months - <text id="items02">items</text> per week</li> 1446 <li>Period shorter than 13 months - <text id="items03">items</text> per month</li> 1447 <li>Period shorter than 3 years - <text id="items04">items</text> per quarter</li> 1448 <li>Period is 3 years or greater - <text id="items05">items</text> per year</li> 1449 </ul> 1450 </div> 1199 1451 </td> 1200 1452 </tr> 1201 </table>1202 </td>1203 </tr>1204 </table>1205 </div>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 1453 <tr> 1219 <td valign="top" class="prompt">No report parameters</td> 1454 <td valign="top" class="prompt"> 1455 <div id="sampleTypeSubSection01" style="display:none;"> 1456 Sample type 1457 </div> 1458 </td> 1220 1459 <td valign="top" class="input"> 1460 <div id="sampleTypeSubSection02" style="display:none;"> 1461 <select name="sampletype"> 1462 <option value="specimen" selected="yes">Specimen</option> 1463 <option value="blood">Blood</option> 1464 </select> 1465 </div> 1221 1466 </td> 1222 <td valign="top" class="status" id="display Interval.status"></td>1467 <td valign="top" class="status" id="displaySampleType.status"></td> 1223 1468 <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> 1469 <div id="sampleTypeSubSection04" style="display:none;"> 1470 <span id="displaySampleType.message" class="message" style="display: none;"></span> 1471 Select sample type for report. 1472 </div> 1226 1473 </td> 1227 </tr> 1474 </tr> 1228 1475 </table> 1229 1476 </td> -
extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/Reggie.java
r1725 r1757 30 30 The current version of this package. 31 31 */ 32 public static final String VERSION = "2. 9-dev";32 public static final String VERSION = "2.10-dev"; 33 33 34 34 -
extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/Site.java
r1722 r1757 20 20 public static final Site LUND = new Site("11", "Lund", "2010-11-10", true); 21 21 public static final Site HELSINGBORG = new Site("22", "Helsingborg", "2010-11-01", true); 22 public static final Site HALMSTAD = new Site("33", "Halmstad", "2010-10-01", false);22 public static final Site HALMSTAD = new Site("33", "Halmstad", "2010-10-01", true); 23 23 public static final Site KRISTIANSTAD = new Site("44", "Kristianstad", "2010-09-15", true); 24 public static final Site KARLSKRONA = new Site("55", "Karlskrona", "2010-10-04", false);25 public static final Site VÄXJÖ = new Site("66", "Växjö", "2010-10-01", false);24 public static final Site KARLSKRONA = new Site("55", "Karlskrona", "2010-10-04", true); 25 public static final Site VÄXJÖ = new Site("66", "Växjö", "2010-10-01", true); 26 26 public static final Site MALMÖ = new Site("77", "Malmö", "2010-08-30", true); 27 27 -
extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/dao/Blood.java
r1625 r1757 187 187 } 188 188 189 190 public String getName()191 {192 return getSample().getName();193 }194 195 189 /** 196 190 Verify that the patient has given their permission to participate in the -
extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/plugins/CaliperRunParametersExporter.java
r1610 r1757 233 233 234 234 } 235 @Override 235 236 protected void end(boolean success) 236 237 { 237 238 this.dc = null; 238 239 } 240 @Override 239 241 protected String getSuccessMessage() 240 242 { -
extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/plugins/CaliperSampleNameExporter.java
r1610 r1757 199 199 200 200 } 201 @Override 201 202 protected void end(boolean success) 202 203 { 203 204 this.dc = null; 204 205 } 206 @Override 205 207 protected String getSuccessMessage() 206 208 { -
extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/servlet/BloodRegistrationServlet.java
r1623 r1757 17 17 import net.sf.basedb.core.AnnotationType; 18 18 import net.sf.basedb.core.Application; 19 import net.sf.basedb.core.BioMaterialEvent; 19 20 import net.sf.basedb.core.BioSource; 20 21 import net.sf.basedb.core.DbControl; … … 195 196 blood.setItemSubtype(Subtype.BLOOD.load(dc)); 196 197 blood.setName(bloodName); 197 blood.getCreationEvent().setSource(patient); 198 BioMaterialEvent creationEvent = blood.getCreationEvent(); 199 creationEvent.setSource(patient); 198 200 dc.saveItem(blood); 199 201 … … 203 205 String bloodSample = Values.getStringOrNull((String)jsonBlood.get("bloodSample")); 204 206 205 if (samplingDate != null) Annotationtype.BLOOD_SAMPLING_DATETIME.setAnnotationValue(dc, blood, samplingDate); 206 if (freezerDate != null) Annotationtype.BLOOD_FREEZER_DATETIME.setAnnotationValue(dc, blood, freezerDate); 207 creationEvent.setEventDate(samplingDate); 208 Annotationtype.BLOOD_SAMPLING_DATETIME.setAnnotationValue(dc, blood, samplingDate); 209 Annotationtype.BLOOD_FREEZER_DATETIME.setAnnotationValue(dc, blood, freezerDate); 207 210 Annotationtype.BLOOD_SERUM.setAnnotationValue(dc, blood, jsonBlood.get("serum")); 208 211 Annotationtype.BLOOD_SAMPLE.setAnnotationValue(dc, blood, bloodSample); … … 237 240 String bloodSample = Values.getStringOrNull((String)jsonBlood.get("bloodSample")); 238 241 239 if (samplingDate != null) Annotationtype.BLOOD_SAMPLING_DATETIME.setAnnotationValue(dc, blood, samplingDate); 240 if (freezerDate != null) Annotationtype.BLOOD_FREEZER_DATETIME.setAnnotationValue(dc, blood, freezerDate); 242 blood.getCreationEvent().setEventDate(samplingDate); 243 244 Annotationtype.BLOOD_SAMPLING_DATETIME.setAnnotationValue(dc, blood, samplingDate); 245 Annotationtype.BLOOD_FREEZER_DATETIME.setAnnotationValue(dc, blood, freezerDate); 241 246 Annotationtype.BLOOD_SERUM.setAnnotationValue(dc, blood, jsonBlood.get("serum")); 242 247 Annotationtype.BLOOD_SAMPLE.setAnnotationValue(dc, blood, bloodSample); -
extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/servlet/ExportServlet.java
r1721 r1757 60 60 { 61 61 boolean exportSubtype = Values.getBoolean(req.getParameter("exportSubtype")); 62 boolean exportPatientId = Values.getBoolean(req.getParameter("exportPatientId")); 62 63 63 64 // This can be any time point in the desired month/year … … 142 143 String opDate = dateFormat.format(s.getCreationEvent().getEventDate()); 143 144 String subtype = exportSubtype ? s.getItemSubtype().getName() : null; 145 String patientId = exportPatientId ? patient.getName() : null; 144 146 String caseName = caseNamePattern.matcher(s.getName()).replaceFirst(""); 145 opDates.add(new PersonalOpDate(pnr, opDate, site, laterality, subtype, caseName, consent ));147 opDates.add(new PersonalOpDate(pnr, opDate, site, laterality, subtype, caseName, consent, patientId)); 146 148 } 147 149 } … … 155 157 resp.setCharacterEncoding("UTF-8"); 156 158 PrintWriter os = resp.getWriter(); 157 159 os.write("PersonalNr\tScanBId\tOpDate\tLaterality\tSite"); 160 if (exportSubtype) os.write("\tSpecimen"); 161 if (exportPatientId) os.write("\tPatientId"); 162 os.write("\tConsent\n"); 163 158 164 for (PersonalOpDate pop : opDates) 159 165 { … … 188 194 private final String caseName; 189 195 private final String consent; 190 191 PersonalOpDate(String pnr, String opDate, Site site, String laterality, String subtype, String caseName, String consent) 196 private final String patientId; 197 198 PersonalOpDate(String pnr, String opDate, Site site, String laterality, String subtype, String caseName, String consent, String patientId) 192 199 { 193 200 this.pnr = pnr; … … 198 205 this.caseName = caseName; 199 206 this.consent = consent; 207 this.patientId = patientId; 200 208 } 201 209 … … 203 211 public String toString() 204 212 { 205 return pnr + "\t" + caseName + "\t" + opDate + "\t" + 206 (laterality == null ? "" : laterality) + "\t" + 207 site.getName() + 208 (subtype==null ? "" : "\t" + subtype) + "\t" + 209 (consent == null ? "MISSING" : consent.toUpperCase()); 213 return pnr + "\t" + caseName + "\t" + opDate + 214 "\t" + (laterality == null ? "" : laterality) + 215 "\t" + site.getName() + 216 (subtype==null ? "" : "\t" + subtype) + 217 (patientId==null ? "" : "\t"+patientId)+ 218 "\t" + (consent == null ? "MISSING" : consent.toUpperCase()); 210 219 } 211 220 -
extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java
r1732 r1757 10 10 import java.util.List; 11 11 import java.util.HashSet; 12 import java.util.Iterator; 12 13 import java.util.Set; 14 import java.util.TreeMap; 13 15 14 16 import javax.servlet.ServletException; … … 23 25 import net.sf.basedb.core.ItemQuery; 24 26 import net.sf.basedb.core.ItemResultIterator; 27 import net.sf.basedb.core.ItemSubtype; 28 import net.sf.basedb.core.MeasuredBioMaterial; 25 29 import net.sf.basedb.core.Sample; 26 30 import net.sf.basedb.core.SessionControl; … … 53 57 private static final int quarterViewLimit= 3; 54 58 59 private static final String alphabeticalOrder = "ALPHABETICAL_ORDER"; 60 private static final String namePrefixOrder = "NAME_PREFIX_ORDER"; 61 private static final String startDateOrder = "START_DATE_ORDER"; 62 private static final String nameLengthOrder = "NAME_LENGTH_ORDER"; 63 55 64 public SampleReportServlet() 56 65 {} … … 111 120 viewType = getViewType(startDate, endDate); 112 121 } 113 114 json = createSampleCountReport(dc, json, startDate, endDate, viewType); 122 String sampleType = "specimen"; 123 String sampleTypeParameter = Values.getString(req.getParameter("stype"), null); 124 if (sampleTypeParameter != null) 125 { 126 sampleType = sampleTypeParameter; 127 } 128 129 json = createSampleCountReport(dc, json, startDate, endDate, viewType, sampleType); 115 130 } 116 131 else if ("consentcount".equals(cmd)) 117 132 { 118 json = createConsentCountReport(dc, json); 133 String startDateParameter = Values.getString(req.getParameter("fdate"), null); 134 String endDateParameter = Values.getString(req.getParameter("tdate"), null); 135 136 Date startDate = Reggie.CONVERTER_STRING_TO_DATE.convert(startDateParameter); 137 Date endDate = Reggie.CONVERTER_STRING_TO_DATE.convert(endDateParameter); 138 139 if (startDate == null) 140 { 141 // Get the when the first site started 142 for (Site s : Site.getAllSites()) 143 { 144 Date siteDate = Reggie.CONVERTER_STRING_TO_DATE.convert(s.getStartDate().replaceAll("-", "")); 145 if (siteDate != null && (startDate == null || startDate.after(siteDate))) 146 { 147 startDate = siteDate; 148 } 149 } 150 } 151 if (endDate == null) 152 { 153 // Get the date for today 154 endDate = new Date(); 155 } 156 157 json = createConsentCountReport(dc, json, startDate, endDate); 158 } 159 else if ("patientcount".equals(cmd)) 160 { 161 String startDateParameter = Values.getString(req.getParameter("fdate"), null); 162 String endDateParameter = Values.getString(req.getParameter("tdate"), null); 163 164 Date startDate = Reggie.CONVERTER_STRING_TO_DATE.convert(startDateParameter); 165 Date endDate = Reggie.CONVERTER_STRING_TO_DATE.convert(endDateParameter); 166 167 if (startDate == null) 168 { 169 // Get the when the first site started 170 for (Site s : Site.getAllSites()) 171 { 172 Date siteDate = Reggie.CONVERTER_STRING_TO_DATE.convert(s.getStartDate().replaceAll("-", "")); 173 if (siteDate != null && (startDate == null || startDate.after(siteDate))) 174 { 175 startDate = siteDate; 176 } 177 } 178 } 179 if (endDate == null) 180 { 181 // Get the date for today 182 endDate = new Date(); 183 } 184 185 String viewType = null; 186 String viewTypeParameter = Values.getString(req.getParameter("vtype"), null); 187 if (viewTypeParameter != null && !viewTypeParameter.equals("AUTO")) 188 { 189 viewType = viewTypeParameter; 190 } 191 else 192 { 193 viewType = getViewType(startDate, endDate); 194 } 195 196 json = createPatientCountReport(dc, json, startDate, endDate, viewType); 119 197 } 120 198 } … … 134 212 } 135 213 136 private JSONObject createSampleCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String viewType) 214 @SuppressWarnings("unchecked") 215 private JSONObject createSampleCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String viewType, String sampleType) 137 216 throws ServletException, IOException 138 217 { … … 143 222 ItemQuery<Sample> sampleQuery = Sample.getQuery(); 144 223 sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true)); 145 Subtype.SPECIMEN.addFilter(dc, sampleQuery); 224 if (sampleType.equals("blood")) 225 { 226 Subtype.BLOOD.addFilter(dc, sampleQuery); 227 } 228 else 229 { 230 Subtype.SPECIMEN.addFilter(dc, sampleQuery); 231 } 232 sampleQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); 233 sampleQuery.order(Orders.asc(Hql.property("name"))); 234 sampleQuery.order(Orders.asc(Hql.property("ce", "eventDate"))); 235 sampleQuery.setCacheResult(true); 236 ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc); 237 // Store samples that should be processed for report table in list 238 List<Sample> sampleList = new ArrayList<Sample>(); 239 while (sampleIterator.hasNext()) 240 { 241 Sample s = sampleIterator.next(); 242 sampleList.add(s); 243 } 244 245 JSONObject jsonStatistics = createJSONStatistics(sampleList.iterator(), startDate, endDate, viewType); 246 jsonReport.put("statistics", jsonStatistics); 247 if (viewType == null) 248 { 249 viewType = getViewType(startDate, endDate); 250 } 251 DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING; 252 Date periodStartDate = calculatePeriodStartDate(startDate, viewType); 253 jsonReport.put("viewType", viewType); 254 jsonReport.put("sampleType", sampleType); 255 jsonReport.put("beginDate", date2StringConverter.convert(startDate)); 256 jsonReport.put("endDate", date2StringConverter.convert(endDate)); 257 jsonReport.put("periodBeginDate", date2StringConverter.convert(periodStartDate)); 258 // Transfer latest date from jsonStatistics to jsonReport 259 String latestDateStr = (String) jsonStatistics.get("latestDateKey"); 260 jsonReport.put("latestDate", latestDateStr); 261 String siteOrder = alphabeticalOrder; 262 JSONObject jsonSiteOrderList = createJSONSiteOrderList(siteOrder); 263 jsonReport.put("siteOrderListKey", jsonSiteOrderList); 264 json.put("report", jsonReport); 265 return json; 266 } 267 268 @SuppressWarnings({ "unchecked", "rawtypes" }) 269 private JSONObject createPatientCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String viewType) 270 throws ServletException, IOException 271 { 272 JSONObject jsonReport = new JSONObject(); 273 jsonReport.put("sites", getJSONSites()); 274 275 ItemQuery<Sample> sampleQuery = Sample.getQuery(); 276 sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true)); 277 // ...only include 'Specimen', 'No Specimen', or 'Blood' items 278 sampleQuery.restrict( 279 Restrictions.or( 280 Subtype.SPECIMEN.restriction(dc, null), 281 Subtype.NO_SPECIMEN.restriction(dc, null), 282 Subtype.BLOOD.restriction(dc, null) 283 )); 146 284 sampleQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); 147 285 sampleQuery.order(Orders.asc(Hql.property("name"))); … … 150 288 ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc); 151 289 152 JSONObject jsonStatistics = createJSONStatistics(sampleIterator, startDate, endDate, viewType); 290 // Store samples that should be processed for report table in list 291 List<Sample> sampleList = new ArrayList<Sample>(); 292 // Create HashMap to keep track of sample with earliest date for each patient 293 HashMap<String, Sample>patientSampleHashMap = new HashMap<String, Sample>(); 294 // Create HashMap to keep track of sample with unknown date for each patient 295 HashMap<String, Sample>patientSampleNoDateHashMap = new HashMap<String, Sample>(); 296 // Find earliest sample dates for each patient 297 ItemSubtype subtypeBlood = Subtype.BLOOD.load(dc); 298 while (sampleIterator.hasNext()) 299 { 300 Sample s = sampleIterator.next(); 301 BioMaterialEvent creationEvent = s.getCreationEvent(); 302 Date creationDate = creationEvent.getEventDate(); 303 304 // Find patient id 305 BioMaterial patient = null; 306 if (s.getItemSubtype().equals(subtypeBlood)) 307 { 308 // The parent is the 'Patient' for blood samples 309 patient = s.getParent(); 310 } 311 else 312 { 313 // The grandparent is the 'Patient' for specimens and no specimens 314 MeasuredBioMaterial parent = (MeasuredBioMaterial) s.getParent(); 315 if (parent != null) 316 { 317 patient = parent.getParent(); 318 } 319 } 320 if (patient != null) 321 { 322 String patientName = patient.getName(); 323 if (creationDate != null) 324 { 325 patientSampleHashMap = updateStringEarliestSampleHashMap(patientSampleHashMap, patientName, s); 326 } 327 else 328 { 329 patientSampleNoDateHashMap.put(patientName, s); 330 } 331 } 332 } 333 // Create list of samples for report 334 // Add sample with earliest date for patient 335 for (String key: patientSampleHashMap.keySet()) 336 { 337 if (key != null && !key.equals("")) 338 { 339 Sample s = patientSampleHashMap.get(key); 340 // Include sample in list of samples for report 341 sampleList.add(s); 342 } 343 } 344 // Add sample with unknown date if no sample with date exists for patient 345 for (String key: patientSampleNoDateHashMap.keySet()) 346 { 347 if (key != null && !key.equals("")) 348 { 349 // If no sample with date exists for sample, include sample without date 350 if (!patientSampleHashMap.containsKey(key)) 351 { 352 Sample s = patientSampleNoDateHashMap.get(key); 353 // Include sample in list of samples for report 354 sampleList.add(s); 355 } 356 } 357 } 358 359 JSONObject jsonStatistics = createJSONStatistics(sampleList.iterator(), startDate, endDate, viewType); 153 360 jsonReport.put("statistics", jsonStatistics); 154 361 if (viewType == null) … … 165 372 String latestDateStr = (String) jsonStatistics.get("latestDateKey"); 166 373 jsonReport.put("latestDate", latestDateStr); 374 String siteOrder = alphabeticalOrder; 375 JSONObject jsonSiteOrderList = createJSONSiteOrderList(siteOrder); 376 jsonReport.put("siteOrderListKey", jsonSiteOrderList); 167 377 json.put("report", jsonReport); 168 378 return json; 169 379 } 170 380 171 private JSONObject createConsentCountReport(DbControl dc, JSONObject json) 381 @SuppressWarnings({ "unchecked", "rawtypes" }) 382 private JSONObject createConsentCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate) 172 383 throws ServletException, IOException 173 384 { … … 207 418 String sumKey = "sumKey"; 208 419 String totalKey = "totalKey"; 420 String latestDateKey = "latestDateKey"; 209 421 String noDateKey = "noDate"; 210 422 String duplicateKey = "duplicateKey"; … … 221 433 jsonStatistics = initializeJSONSiteData(jsonStatistics, otherKey); 222 434 jsonStatistics = initializeJSONSiteData(jsonStatistics, missingKey); 223 //jsonStatistics = initializeJSONSiteData(jsonStatistics, sumKey); 224 //jsonStatistics = initializeJSONSiteData(jsonStatistics, totalKey); 435 jsonStatistics = initializeJSONSiteData(jsonStatistics, noDateKey); 436 jsonStatistics = initializeJSONSiteData(jsonStatistics, sumKey); 437 jsonStatistics = initializeJSONSiteData(jsonStatistics, totalKey); 225 438 // Initialize combined data to 0 for the different keys 226 439 jsonSitesCombined.put(yesKey, 0); … … 234 447 jsonSitesCombined.put(otherKey, 0); 235 448 jsonSitesCombined.put(missingKey, 0); 449 jsonSitesCombined.put(noDateKey, 0); 236 450 jsonSitesCombined.put(sumKey, 0); 237 451 jsonSitesCombined.put(totalKey, 0); … … 239 453 jsonStatistics.put(noDateKey, 0); 240 454 jsonStatistics.put(duplicateKey, 0); 455 Date latestDate = null; 241 456 // Create HashMap to keep track of processed dates for each patient 242 457 HashMap<String, Set<Date>>patientDateSetHashMap = new HashMap<String, Set<Date>>(); 243 458 JSONObject jsonPatientnamePatientid = new JSONObject(); 459 // Create HashMap to keep track of latest consent date for each site 460 HashMap<String, Date> sitePrefixDateHashMap = new HashMap<String, Date>(); 244 461 while (sampleIterator.hasNext()) 245 462 { 246 463 Sample s = sampleIterator.next(); 464 /* 247 465 BioMaterialEvent creationEvent = s.getCreationEvent(); 248 466 Date creationDate = creationEvent.getEventDate(); 467 */ 249 468 250 469 Site site = Site.findByCaseName(s.getName()); … … 267 486 // Get consent date 268 487 Date consentDate = (Date) Annotationtype.CONSENT_DATE.getAnnotationValue(dc, manager, s); 269 String key = missingKey;488 String key = null; 270 489 Boolean duplicate = false; 271 490 if (consent != null) 272 491 { 273 if (consent.equals("Yes")) 274 { 275 key = yesKey; 492 if (consentDate != null) 493 { 276 494 // Check if a consent already exists for the same patient and date 277 if (consentDate != null) 495 // The parent is the 'Patient' 496 BioMaterial patient = s.getParent(); 497 if (patient != null) 278 498 { 279 // The parent is the 'Patient' 280 BioMaterial patient = s.getParent(); 281 if (patient != null) 499 // Store patient ID value 500 jsonPatientnamePatientid = updateJSONItemnameItemid(jsonPatientnamePatientid, patient); 501 String patientName = patient.getName(); 502 if (inStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate)) 282 503 { 283 // Store patient ID value 284 jsonPatientnamePatientid = updateJSONItemnameItemid(jsonPatientnamePatientid, patient); 285 key = yesPatientKey; 286 String patientName = patient.getName(); 287 if (inStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate)) 504 duplicate = true; 505 } 506 else 507 { 508 patientDateSetHashMap = updateStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate); 509 } 510 } 511 if ((consentDate.after(startDate) || consentDate.equals(startDate)) && 512 (consentDate.before(endDate) || consentDate.equals(endDate))) 513 { 514 if (consent.equals("Yes")) 515 { 516 key = yesKey; 517 if (patient != null) 288 518 { 289 duplicate = true;519 key = yesPatientKey; 290 520 } 291 521 else 292 522 { 293 patientDateSetHashMap = updateStringDateSetHashMap(patientDateSetHashMap, patientName, consentDate);523 key = yesNoPatientKey; 294 524 } 525 } 526 else if (consent.equals("No")) 527 { 528 key = noKey; 529 } 530 else if (consent.equals("Not asked")) 531 { 532 key = notAskedKey; 295 533 } 296 534 else 297 535 { 298 key = yesNoPatientKey;536 key = otherKey; 299 537 } 538 // Find out if current consent date is the latest so far. 539 if (latestDate == null || latestDate.before(consentDate)) 540 { 541 latestDate = consentDate; 542 } 543 } 544 } 545 else 546 { 547 if (consent.equals("Yes")) 548 { 549 key = yesNoDateKey; 550 } 551 else if (consent.equals("No")) 552 { 553 key = noNoDateKey; 554 } 555 else if (consent.equals("Not asked")) 556 { 557 key = notAskedNoDateKey; 300 558 } 301 559 else 302 560 { 303 key = yesNoDateKey;561 key = otherKey; 304 562 } 305 563 } 306 else if (consent.equals("No"))307 {308 key = noKey;309 // Check if consent date exists310 if ( consentDate == null)564 // Keep track of latest consent date for site 565 if (consentDate != null) 566 { 567 Date siteLatestDate = sitePrefixDateHashMap.get(site.getPrefix()); 568 if (siteLatestDate == null || siteLatestDate.before(consentDate)) 311 569 { 312 key = noNoDateKey;570 sitePrefixDateHashMap.put(site.getPrefix(), consentDate); 313 571 } 314 572 } 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 } 573 } 574 else 575 { 576 key = missingKey; 328 577 } 329 578 // Note that items with duplicate == false include missing consent items 330 579 if (!duplicate) 331 580 { 332 // Update consent counters 333 jsonSite = updateJSONObjectCounter(jsonSite, key); 334 jsonSite = updateJSONObjectCounter(jsonSite, sumKey); 335 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, key); 336 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, sumKey); 581 if (key != null) 582 { 583 // Update consent counters 584 jsonSite = updateJSONObjectCounter(jsonSite, key); 585 jsonSite = updateJSONObjectCounter(jsonSite, sumKey); 586 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, key); 587 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, sumKey); 588 } 337 589 if (consentDate == null) 338 590 { 591 // Include consents with unknown date 592 jsonSite = updateJSONObjectCounter(jsonSite, noDateKey); 593 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, noDateKey); 339 594 jsonStatistics = updateJSONObjectCounter(jsonStatistics, noDateKey); 340 595 } 596 // Increase the counter for total consents for the site, regardless of creation date 597 jsonSite = updateJSONObjectCounter(jsonSite, totalKey); 598 599 // Increase the counter for total consents for all sites 600 jsonSitesCombined = updateJSONObjectCounter(jsonSitesCombined, totalKey); 341 601 } 342 602 else … … 346 606 } 347 607 } 608 // Add latest consent date for site to site JSON object 609 DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING; 610 for (Site s: Site.getAllSites()) 611 { 612 JSONObject jsonSite = (JSONObject) jsonStatistics.get(s.getPrefix()); 613 if (jsonSite == null) 614 { 615 jsonSite = new JSONObject(); 616 jsonStatistics.put(s.getPrefix(), jsonSite); 617 } 618 Date siteLatestDate = sitePrefixDateHashMap.get(s.getPrefix()); 619 jsonSite.put(latestDateKey, date2StringConverter.convert(siteLatestDate)); 620 } 621 // Add latest date for further transfer to other JSON object 622 jsonStatistics.put(latestDateKey, date2StringConverter.convert(latestDate)); 348 623 // Create JSONObject (patient, dates) for patients with multiple dates 349 624 JSONObject jsonPatientsWithMultipleDates = createJSONPatientsWithMultipleDates(patientDateSetHashMap); … … 356 631 // 357 632 jsonReport.put("statistics", jsonStatistics); 633 jsonReport.put("beginDate", date2StringConverter.convert(startDate)); 634 jsonReport.put("endDate", date2StringConverter.convert(endDate)); 635 // Transfer latest date from jsonStatistics to jsonReport 636 String latestDateStr = (String) jsonStatistics.get("latestDateKey"); 637 jsonReport.put("latestDate", latestDateStr); 638 String siteOrder = alphabeticalOrder; 639 JSONObject jsonSiteOrderList = createJSONSiteOrderList(siteOrder); 640 jsonReport.put("siteOrderListKey", jsonSiteOrderList); 358 641 json.put("report", jsonReport); 359 642 return json; … … 381 664 } 382 665 666 @SuppressWarnings({ "unchecked", "rawtypes" }) 383 667 private JSONObject updateJSONItemnameItemid(JSONObject jsonObject, BioMaterial item) 384 668 { … … 431 715 } 432 716 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 717 private HashMap<String, Sample> updateStringEarliestSampleHashMap(HashMap<String, Sample> stringSampleHashMap, String string, Sample sample) 718 { 719 if (stringSampleHashMap == null) 720 { 721 stringSampleHashMap = new HashMap<String, Sample>(); 722 } 723 if (string != null && !string.equals("")) 724 { 725 // Store the sample with the earliest date for the item defined by string 726 Sample storedSample = stringSampleHashMap.get(string); 727 Date sampleDate = null; 728 Date storedSampleDate = null; 729 if (sample != null) 730 { 731 BioMaterialEvent creationEvent = sample.getCreationEvent(); 732 sampleDate = creationEvent.getEventDate(); 733 } 734 if (storedSample != null) 735 { 736 BioMaterialEvent creationEvent = storedSample.getCreationEvent(); 737 storedSampleDate = creationEvent.getEventDate(); 738 } 739 if (sampleDate != null) 740 { 741 if (storedSampleDate != null) 742 { 743 if (sampleDate.before(storedSampleDate)) 744 { 745 // New sample date earlier, store that sample for patient 746 stringSampleHashMap.put(string, sample); 747 } 748 } 749 else 750 { 751 // No stored sample; store new sample for patient 752 stringSampleHashMap.put(string, sample); 753 } 754 } 755 } 756 return stringSampleHashMap; 757 } 758 759 @SuppressWarnings("unchecked") 475 760 private JSONObject createJSONPatientsWithMultipleDates(HashMap<String, Set<Date>> stringDateSetHashMap) 476 761 { … … 507 792 } 508 793 509 private JSONObject createJSONStatistics(ItemResultIterator<Sample> sampleIterator, Date startDate, Date endDate, String viewType) 794 @SuppressWarnings("unchecked") 795 private JSONObject createJSONStatistics(Iterator<Sample> sampleIterator, Date startDate, Date endDate, String viewType) 510 796 throws ServletException, IOException 511 797 { … … 522 808 String latestDateKey = "latestDateKey"; 523 809 jsonStatistics.put(sitesCombinedKey, jsonSitesCombined); 810 // Create HashMap to keep track of latest sample date for each site 811 HashMap<String, Date> sitePrefixDateHashMap = new HashMap<String, Date>(); 524 812 while (sampleIterator.hasNext()) 525 813 { … … 566 854 } 567 855 } 856 857 // Keep track of latest sample date for site 858 Date siteLatestDate = sitePrefixDateHashMap.get(site.getPrefix()); 859 if (siteLatestDate == null || siteLatestDate.before(creationDate)) 860 { 861 sitePrefixDateHashMap.put(site.getPrefix(), creationDate); 862 } 568 863 } 569 864 else … … 580 875 } 581 876 } 877 // Add latest sample date for site to site JSON object 878 DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING; 879 for (Site s: Site.getAllSites()) 880 { 881 JSONObject jsonSite = (JSONObject) jsonStatistics.get(s.getPrefix()); 882 if (jsonSite == null) 883 { 884 jsonSite = new JSONObject(); 885 jsonStatistics.put(s.getPrefix(), jsonSite); 886 } 887 Date siteLatestDate = sitePrefixDateHashMap.get(s.getPrefix()); 888 jsonSite.put(latestDateKey, date2StringConverter.convert(siteLatestDate)); 889 } 582 890 // Add latest date for further transfer to other JSON object 583 DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING;584 891 jsonStatistics.put(latestDateKey, date2StringConverter.convert(latestDate)); 585 892 return jsonStatistics; 586 893 } 587 894 895 @SuppressWarnings("unchecked") 588 896 private JSONObject updateJSONObjectCounter(JSONObject jsonObject, String key) 589 897 { … … 599 907 } 600 908 909 @SuppressWarnings("unchecked") 601 910 private JSONObject initializeJSONSiteData(JSONObject jsonSiteContainerObject, String key) 602 911 { … … 620 929 } 621 930 931 @SuppressWarnings("unchecked") 622 932 private JSONObject initializeJSONPeriodData(JSONObject jsonObject, Date startDate, Date endDate, Date dataStartDate, String viewType) 623 933 { … … 644 954 } 645 955 return jsonObject; 956 } 957 958 /** 959 * Creates a JSONObject with order index as key and site prefix as value. 960 * 961 * @param order String A string indicating desired order (null => alphabetical order) 962 * @return String A JSONObject with sort index as key and site prefix as value. 963 */ 964 @SuppressWarnings("unchecked") 965 private JSONObject createJSONSiteOrderList(String order) 966 { 967 JSONObject jsonSiteOrderList = new JSONObject(); 968 List<String> siteOrderedList = createSiteOrderedList(order); 969 for (int i=0; i < siteOrderedList.size(); i++) 970 { 971 String namePrefix = siteOrderedList.get(i); 972 jsonSiteOrderList.put(i, namePrefix); 973 } 974 return jsonSiteOrderList; 975 } 976 977 /** 978 * Creates a list of site name prefixes sorted after specified order. 979 * 980 * @param order String A string indicating desired order (null => alphabetical order) 981 * @return List<String> list of site name prefixes sorted after specified order. 982 */ 983 @SuppressWarnings("rawtypes") 984 private List<String> createSiteOrderedList(String order) 985 { 986 if (order == null || order.equals("")) 987 { 988 order = alphabeticalOrder; 989 } 990 TreeMap<Comparable, String> treeMap = new TreeMap<Comparable, String>(); 991 for (Site site: Site.getAllSites()) 992 { 993 Comparable comparableObject = null; 994 if (order.equals(alphabeticalOrder)) 995 { 996 comparableObject = site.getName(); 997 } 998 else if (order.equals(namePrefixOrder)) 999 { 1000 comparableObject = site.getPrefix(); 1001 } 1002 else if (order.equals(startDateOrder)) 1003 { 1004 comparableObject = site.getStartDate(); 1005 } 1006 else if (order.equals(nameLengthOrder)) 1007 { 1008 comparableObject = site.getName().length(); 1009 } 1010 treeMap.put(comparableObject, site.getPrefix()); 1011 } 1012 List<String> list = new ArrayList<String>(); 1013 for (Comparable key: treeMap.keySet()) 1014 { 1015 list.add(treeMap.get(key)); 1016 } 1017 return list; 646 1018 } 647 1019 … … 749 1121 } 750 1122 1123 @SuppressWarnings("unused") 751 1124 private List<Date> createSortedPeriodStartDateList(Date startDate, Date endDate, String viewType) 752 1125 {
Note: See TracChangeset
for help on using the changeset viewer.