source: extensions/net.sf.basedb.reggie/trunk/resources/scanbquartermonthreportgenerator.jsp @ 1843

Last change on this file since 1843 was 1843, checked in by olle, 7 years ago

Refs #461. Sample processing report is updated to allow appended text after the plot section:

  1. JSP file scanbquartermonthreportgenerator.jsp in reggie/resources/ updated by retrieving optional text to append from JSON object with key "appendedInfo".
  2. Java class/file ScanBQuarterMonthReportServlet.java in reggie/src/net/sf/basedb/reggie/servlet/ updated to add information on number of samples with negative or zero min to RNAlater value as appended info text. This appended info is only added if "min to RNAlater" is included in the selected chart data.


File size: 21.5 KB
Line 
1<%@ page
2  pageEncoding="UTF-8"
3  session="false"
4  import="net.sf.basedb.core.User"
5  import="net.sf.basedb.core.DbControl"
6  import="net.sf.basedb.core.SessionControl"
7  import="net.sf.basedb.core.Application"
8  import="net.sf.basedb.clients.web.Base" 
9  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
10%>
11<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
12<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
13<%
14final SessionControl sc = Base.getExistingSessionControl(request, true);
15final String ID = sc.getId();
16final float scale = Base.getScale(sc);
17final String home = ExtensionsControl.getHomeUrl("net.sf.basedb.reggie");
18DbControl dc = null;
19try
20{
21  dc = sc.newDbControl();
22  final User user = User.getById(dc, sc.getLoggedInUserId());
23  %>
24<base:page type="default" >
25<base:head scripts="ajax.js" styles="path.css">
26  <link rel="stylesheet" type="text/css" href="css/reggie.css">
27  <script language="JavaScript" src="reggie.js" type="text/javascript" charset="UTF-8"></script>
28  <script language="JavaScript" src="boxplot.js" type="text/javascript" charset="UTF-8"></script>
29   
30   
31  <script language="JavaScript">
32  var currentStep = 1;
33  var debug = true;
34/*
35  var numCols;
36  var unknownSite = 0;
37  var unknownCreation;
38  var numPatientsNoSamples = 0;
39  var debug01 = null;
40*/
41 
42  var intervalIsValid = true;
43 
44  function goNext()
45  {
46    if (currentStep == 1)
47    {
48      gotoStep2();
49    }
50  }
51 
52  function gotoStep2()
53  {
54    var frm = document.forms['reggie'];
55    frm.reporttype.disabled = true;
56    // Hide report period input fields
57    document.getElementById("reportPeriodSubSection01").style.display = 'none';
58    document.getElementById("reportPeriodSubSection02").style.display = 'none';
59    document.getElementById("reportPeriodSubSection04").style.display = 'none';
60    // Hide view type pop-up menu
61    document.getElementById("viewTypeSubSection01").style.display = 'none';
62    document.getElementById("viewTypeSubSection02").style.display = 'none';
63    document.getElementById("viewTypeSubSection04").style.display = 'none';
64    // Hide chart variant pop-up menu
65    document.getElementById("chartVariantSubSection01").style.display = 'none';
66    document.getElementById("chartVariantSubSection02").style.display = 'none';
67    document.getElementById("chartVariantSubSection04").style.display = 'none';
68    if (frm.reporttype[frm.reporttype.selectedIndex].value == 'scanbquartermonthreport')
69    {
70      // Show report period input fields
71      document.getElementById("reportPeriodSubSection01").style.display = 'block';
72      document.getElementById("reportPeriodSubSection02").style.display = 'block';
73      document.getElementById("reportPeriodSubSection04").style.display = 'block';
74      document.getElementById("reportPeriodSubSection01Header").innerHTML="Report period";
75      document.getElementById("reportPeriodSubSection04HelpText").innerHTML="Define which period the report should cover. Empty fields will include all items.";
76      // Set item name for report time step text
77      //document.getElementById("items02").innerHTML="samples";
78      document.getElementById("items03").innerHTML="samples";
79      document.getElementById("items04").innerHTML="samples";
80      document.getElementById("items05").innerHTML="samples";
81      // Show view type pop-up menu
82      document.getElementById("viewTypeSubSection01").style.display = 'block';
83      document.getElementById("viewTypeSubSection02").style.display = 'block';
84      document.getElementById("viewTypeSubSection04").style.display = 'block';
85      // Show chart data pop-up menu
86      document.getElementById("chartVariantSubSection01").style.display = 'block';
87      document.getElementById("chartVariantSubSection02").style.display = 'block';
88      document.getElementById("chartVariantSubSection04").style.display = 'block';
89    }
90    Main.show('itemCountSection');
91       
92    Main.show('gocreate');   
93    Main.hide('gonext');
94    frm.fromdate.focus();
95    currentStep = 2;
96  }
97 
98  function dateOnChange()
99  {
100    var frm = document.forms['reggie'];   
101    var fdate;
102    var tdate;
103   
104    intervalIsValid = false;
105    setInputStatus('displayInterval','','valid');
106    if (frm.fromdate.value != null && frm.fromdate.value != '')
107    {
108      frm.fromdate.value = autoFillDate(frm.fromdate.value);     
109      if (!Dates.isDate(frm.fromdate.value, 'yyyyMMdd'))
110      {
111        setInputStatus('displayInterval','Not a valid from-date', 'invalid');
112        return;
113      }
114      else
115      {
116        fdate = frm.fromdate.value;
117        fdate = new Date(fdate.substr(0,4), parseInt(fdate.substr(4,2), 10)-1, fdate.substr(6,2));
118      }
119    }
120   
121    if (frm.todate.value != null && frm.todate.value != '')
122    {
123      frm.todate.value = autoFillDate(frm.todate.value);
124      if (!Dates.isDate(frm.todate.value, 'yyyyMMdd'))
125      {
126        setInputStatus('displayInterval', 'Not a valid to-date', 'invalid');
127        return;
128      }
129      else
130      {
131        tdate = frm.todate.value;
132        tdate = new Date(tdate.substr(0,4), parseInt(tdate.substr(4,2), 10)-1, tdate.substr(6,2));
133      }
134    }
135   
136    if (tdate != null && fdate != null)
137    {
138      if (fdate > tdate)
139      {
140        setInputStatus('displayInterval', 'Invalid period', 'invalid')
141        return;
142      }     
143    }
144    intervalIsValid = true;
145  }
146 
147  function goCreate()
148  {
149    if (!intervalIsValid) return;
150    var cellElement = document.getElementById('reportcell');
151    var frm = document.forms['reggie'];   
152    var reportType = frm.reporttype[frm.reporttype.selectedIndex].value;   
153    frm.fromdate.disabled = true;
154    frm.todate.disabled = true;
155    var chartVariant = frm.chartvariant[frm.chartvariant.selectedIndex].value;   
156    if (reportType == 'scanbquartermonthreport')
157    {
158      frm.viewtype.disabled = true;
159      frm.chartvariant.disabled = true;
160    }
161    Main.hide('gocreate');
162    Main.show('reportSection');
163    var url = 'ScanBQuarterMonthReport.servlet?ID=<%=ID%>&cmd='+reportType;   
164   
165    if (frm.fromdate.value != null) url += '&fdate='+frm.fromdate.value;
166    if (frm.todate.value != null) url += '&tdate='+frm.todate.value;
167    if (reportType == 'scanbquartermonthreport')
168    {     
169      if (frm.viewtype.value != null) url += '&vtype='+frm.viewtype.value;
170      if (frm.chartvariant.value != null) url += '&cvariant='+frm.chartvariant.value;
171    }
172   
173    var request = Ajax.getXmlHttpRequest();
174    request.open("GET", url, false);
175    request.send(null);
176   
177    if (debug) Main.debug(request.responseText);   
178    var response = JSON.parse(request.responseText); 
179    if (response.status != 'ok')
180    {
181      setFatalError(response.message);
182      return false;
183    }
184    var report = response.report;
185    var permissionDeniedForPatientName = report.permissionDeniedForPatientName;
186    var reportTable;
187   
188    if (report != null)
189    {
190      if ('scanbquartermonthreport' == reportType)
191      {
192        var draw_area_wdt = 700;
193        var draw_area_hgt = 550;
194        var jsonStatisticsPlotArray = report.plotStatistics;
195        // Draw plots
196        setInnerHTML('reportcell', '');
197        for (var plotIndex in jsonStatisticsPlotArray)
198        {
199          //
200          // Get plot JSON data container with extra info and plot data
201          var plotJsonDataContainer = jsonStatisticsPlotArray[plotIndex];
202          // Get plot JSON extra info and plot data
203          var plotChartVariant = plotJsonDataContainer['chartVariant'];
204          var plotViewType = plotJsonDataContainer['viewType'];
205          var plotOptionalHeadline = plotJsonDataContainer['optionalHeadline'];
206          var boxPlotJsonData = plotJsonDataContainer['plotData'];
207          // Create plot from plot JSON data
208          var spacer = document.createElement('text');
209          spacer.innerHTML = "<BR>";
210          if (plotOptionalHeadline != null && plotOptionalHeadline != '')
211          {
212            // Print optional headline
213            var headlineText = document.createElement('text');
214            headlineText.innerHTML = "<BR>" + plotOptionalHeadline + "<BR>";
215            cellElement.appendChild(spacer);
216            cellElement.appendChild(headlineText);
217          }
218          var plotKey = plotChartVariant + '_' + plotViewType;
219/*
220          // Add plot key as debug text
221          var debugText = document.createElement('text');
222          debugText.innerHTML = "<BR>" + plotKey + "<BR>";
223          cellElement.appendChild(spacer);
224          cellElement.appendChild(debugText);
225*/
226          // Add plot
227          var canvasInTable = document.createElement('canvas');
228          canvasInTable.setAttribute('id', plotKey);
229          canvasInTable.setAttribute('width', draw_area_wdt);
230          canvasInTable.setAttribute('height', draw_area_hgt);
231          createBoxPlot(boxPlotJsonData, canvasInTable, draw_area_wdt, draw_area_hgt);
232          cellElement.appendChild(spacer);
233          cellElement.appendChild(canvasInTable);
234        }
235        // Print optional appended info
236        var appendedInfo = report.appendedInfo;
237        if (appendedInfo != null && appendedInfo != '')
238        {
239          // Print optional headline
240          var infoText = document.createElement('text');
241          infoText.innerHTML = "<BR>" + appendedInfo + "<BR>";
242          cellElement.appendChild(spacer);
243          cellElement.appendChild(infoText);
244        }
245      }
246    }
247    else
248    {
249      var messageCell = getTableCellElement('No values could be found during given period', 'reportheader');
250      var messageRow = document.createElement('tr');
251      messageRow.appendChild(messageCell);     
252      var messageTable = getReportTable();
253      messageTable.appendChild(messageRow);
254      reportTable = messageTable;     
255    }
256    Main.show('gorestart');   
257  }
258
259  function getJSONData(jsonObject, key)
260  {
261    var data = getJSONData(jsonObject, key, '');
262    return data;
263  }
264
265  function getJSONData(jsonObject, key, defaultChoice)
266  {
267    var data = defaultChoice;
268    if (jsonObject != null)
269    {
270      if (jsonObject[key] != null)
271      {
272        data = jsonObject[key];
273      }
274    }
275    return data;
276  }
277
278  function getReportTable()
279  {
280      var reportTable = document.createElement('table');
281      reportTable.setAttribute('class','reporttable');
282      reportTable.setAttribute('border','1');     
283      return reportTable;
284  }
285 
286  function getTableCellElement(text, clazz, colspan, rowspan)
287  {
288    var cellElement = document.createElement('td');
289    text = new String(text);   
290    var textArray = text.split("\n");   
291    if (textArray.length > 1)
292    {
293      for (var i=0;i<textArray.length;i++)
294      {       
295        if (i>0)cellElement.appendChild(document.createElement('br'));
296        cellElement.appendChild(document.createTextNode(textArray[i]));
297      }     
298    }
299    else
300    {
301      cellElement.appendChild(document.createTextNode(text));
302    }
303    cellElement.setAttribute('class', clazz);
304    if (colspan != null) cellElement.setAttribute('colspan', colspan);
305    if (rowspan != null) cellElement.setAttribute('rowspan', rowspan);
306   
307    return cellElement;
308  }
309 
310  function getListElement(itemText)
311  {
312    var listElement = document.createElement('li');
313    var textNode = document.createTextNode(itemText);
314    listElement.appendChild(textNode);
315    return listElement;
316  }
317
318  /**
319   *  addHyphensToDateStr()
320   *
321   *  Adds hyphens to date string in yyyymmdd format to
322   *  get yyyy-mm-dd format. If input string already contains
323   *  hyphen(s), the input string is returned unchanged.
324   *  If input string is null or empty, '????-??-??' is returned.
325   *
326   *  @param dateStr String Input date string in yyyy-mm-dd or yyyymmdd format.
327   *  @return String Date string in yyyy-mm-dd format.
328   */
329  function addHyphensToDateString(dateStr)
330  {
331    var dateWithHyphensStr = '????-??-??';
332    if (dateStr != null && dateStr != '')
333    {
334      // Check if input string already contains hyphen
335      if (dateStr.indexOf("-") >= 0)
336      {
337        // Date already has hyphen(s)
338        dateWithHyphensStr = dateStr;
339      }
340      else
341      {
342        // Date in yyyymmdd format
343        var yearStr = dateStr.substr(0,4);
344        var monthStr = dateStr.substr(4,2);
345        var dayStr = dateStr.substr(6,2);     
346        dateWithHyphensStr = yearStr + '-' + monthStr + '-' + dayStr;
347      }
348    }
349    return dateWithHyphensStr;
350  }
351
352  /**
353   *  dateStrToDate()
354   *
355   *  Takes an input date string in yyyy-mm-dd or yyyymmdd format
356   *  and returns a date corresponding to the date string.
357   *  If input string is null or empty, null is returned.
358   *
359   *  @param dateStr String Input date string in yyyy-mm-dd or yyyymmdd format.
360   *  @return Date Date corresponding to input date string.
361   */
362  function dateStrToDate(dateStr)
363  {
364    var date = null;
365    if (dateStr != null && dateStr != '')
366    {
367      // Check if input string already contains hyphen
368      if (dateStr.indexOf("-") >= 0)
369      {
370        // Date in yyyy-mm-dd format
371        var yearStr = dateStr.substr(0,4);
372        var monthStr = dateStr.substr(5,2);
373        var dayStr = dateStr.substr(8,2);     
374        var date = new Date(parseInt(yearStr, 10), parseInt(monthStr, 10)-1, parseInt(dayStr, 10));
375      }
376      else
377      {
378        // Date in yyyymmdd format
379        var yearStr = dateStr.substr(0,4);
380        var monthStr = dateStr.substr(4,2);
381        var dayStr = dateStr.substr(6,2);     
382        var date = new Date(parseInt(yearStr, 10), parseInt(monthStr, 10)-1, parseInt(dayStr, 10));
383      }
384    }
385    return date;
386  }
387
388  /*
389   *  Get the ISO week number for a given date
390   *
391   *  Based on code at http://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php
392   *
393   *  @param date String Input date to get ISO week number for.
394   *  @return int ISO week number for input date.
395   */
396  function getISOWeekNumber(date)
397  {
398    tmpDate = new Date(date);
399    tmpDate.setHours(0,0,0);
400    // Set to nearest Thursday: current date + 4 - current day number
401    // Make Sunday day number 7
402    tmpDate.setDate(tmpDate.getDate() + 4 - (tmpDate.getDay() || 7));
403    // Get first day of year
404    var yearStart = new Date(tmpDate.getFullYear(), 0, 1);
405    // Calculate full weeks to nearast Thursday (86400000 = 24*60*60*1000 number of ms in a day)
406    var weekNo = Math.ceil(( ( (tmpDate - yearStart) / 86400000) + 1)/7);
407    return weekNo;
408  }
409
410  </script>
411 
412 
413  </base:head>
414  <base:body onload="init()">
415    <p:path><p:pathelement 
416      title="Reggie" href="<%="index.jsp?ID="+ID%>" 
417      /><p:pathelement title="Sample processing report" 
418      /></p:path>
419    <div class="content">
420    <%
421    if (sc.getActiveProjectId() == 0)
422    {
423      %>
424      <div class="messagecontainer note" style="width: 950px; margin-left: 20px; margin-bottom: 20px; margin-right: 0px; font-weight: bold; color: #cc0000;">
425        No project has been selected. You may proceed with the report generation but
426        only your own items will be included in the report.
427      </div>
428      <%
429    }
430    %>
431 
432    <form name="reggie" onsubmit="return false;">
433      <!-- 1. Report type-->
434      <table border="0" cellspacing="0" cellpadding="0" class="stepform">
435      <tr>
436        <td rowspan="3" class="stepno">1</td>
437        <td class="steptitle">Report type</td>
438      </tr>
439      <tr>
440        <td class="stepfields">
441          <table border="0" cellspacing="0" cellpadding="0" width="100%">
442          <tr valign="top">
443            <td class="prompt">Report</td>
444            <td class="input">
445              <select name="reporttype">
446                <option value="scanbquartermonthreport" selected="yes">SCAN-B quarter/month report</option>
447              </select>
448            </td>
449            <td class="status" id="report.status"></td>
450            <td class="help">
451              <span id="report.message" class="message" style="display: none;"></span>
452              Select which report to generate.
453            </td>
454          </tr>
455          </table>
456        </td>
457      </tr>
458      </table>
459     
460      <div id="itemCountSection" style="display:none;">
461        <p></p>
462        <!-- 2. Report parameters-->
463        <table border="0" cellspacing="0" cellpadding="0" class="stepform">
464        <tr>
465          <td rowspan="3" class="stepno">2</td>
466          <td class="steptitle">Report parameters</td>
467        </tr>
468        <tr>
469          <td class="stepfields">
470            <table border="0" cellspacing="0" cellpadding="0" width="100%">           
471            <tr>
472              <td valign="top" class="prompt">
473                <div id="reportPeriodSubSection01" style="display:none;">
474                  <text id="reportPeriodSubSection01Header">Report period</text>
475                </div>
476              </td>
477              <td valign="top" class="input">
478                <div id="reportPeriodSubSection02" style="display:none;">
479                  From<input type="text" onChange="dateOnChange()" size=7 name="fromdate"/>&nbsp;
480                  To<input type="text" onChange="dateOnChange()" size=7 name="todate" />
481                </div>
482              </td>
483              <td valign="top" class="status" id="displayInterval.status"></td>
484              <td class="help">
485                <div id="reportPeriodSubSection04" style="display:none;">
486                  <span id="displayInterval.message" class="message" style="display: none;"></span>
487                  <!--
488                  Define which period the report should cover. Empty fields will include all <text id="items01">items</text>.<br>
489                  -->
490                  <text id="reportPeriodSubSection04HelpText">Parameter help text</text><br>
491                </div>
492              </td>
493            </tr> 
494            <tr>
495              <td valign="top" class="prompt">
496                <div id="viewTypeSubSection01" style="display:none;">
497                  View type
498                </div>
499              </td>
500              <td valign="top" class="input">
501                <div id="viewTypeSubSection02" style="display:none;">
502                  <select name="viewtype">
503                    <option value="QUARTERMONTH" selected="yes">Quarter + Month</option>
504                    <option value="AUTO">Auto</option>
505                    <option value="WEEK">Week</option>
506                    <option value="MONTH">Month</option>
507                    <option value="QUARTER">Quarter</option>
508                    <option value="YEAR">Year</option>
509                  </select>
510                </div>
511              </td>
512              <td valign="top" class="status" id="displayViewType.status"></td>
513              <td class="help">
514                <div id="viewTypeSubSection04" style="display:none;">
515                  <span id="displayViewType.message" class="message" style="display: none;"></span>
516                  Auto will adjust the report depending on the size of the period.
517                  <ul>
518                    <!--
519                    <li>Period shorter than 3 months - <text id="items02">items</text> per week</li>
520                    -->
521                    <li>Period shorter than 13 months - <text id="items03">items</text> per month</li>
522                    <li>Period shorter than 3 years - <text id="items04">items</text> per quarter</li>
523                    <li>Period is 3 years or greater - <text id="items05">items</text> per year</li>
524                  </ul>
525                </div>
526              </td>
527            </tr>
528            <tr>
529              <td valign="top" class="prompt">
530                <div id="chartVariantSubSection01" style="display:none;">
531                  Chart data
532                </div>
533              </td>
534              <td valign="top" class="input">
535                <div id="chartVariantSubSection02" style="display:none;">
536                  <select name="chartvariant">
537                    <option value="allcharts" selected="yes">All</option>
538                    <option value="originalquantitytissue">Original quantity tissue</option>
539                    <option value="quantitytissueused">Quantity tissue used for SCAN-B specimens</option>
540                    <option value="histologypiecequantity">Histology piece quantity</option>
541                    <option value="remainingquantityforscanbspecimen">Remaining quantity for SCAN-B specimens</option>
542                    <option value="originalquantitydna">Original quantity DNA for SCAN-B extractions</option>
543                    <option value="originalquantityrna">Original quantity RNA for SCAN-B extractions</option>
544                    <option value="dnayield">DNA yield</option>
545                    <option value="rnayield">RNA yield</option>
546                    <option value="dnayieldcorrected">DNA yield (corrected for only processing half of the lysate volume)</option>
547                    <option value="rnayieldcorrected">RNA yield (corrected for only processing half of the lysate volume)</option>
548                    <option value="rnaqc">RNA QC</option>
549                    <option value="minutestornalater">Min to RNAlater</option>
550                  </select>
551                </div>
552              </td>
553              <td valign="top" class="status" id="displaychartVariant.status"></td>
554              <td class="help">
555                <div id="chartVariantSubSection04" style="display:none;">
556                  <span id="displaychartVariant.message" class="message" style="display: none;"></span>
557                  Select what data to report.
558                </div>
559              </td>
560            </tr>
561            </table>
562          </td>
563        </tr>
564        </table>
565      </div>
566     
567      <div id="reportSection" style="display:none;">
568        <p></p>
569        <table border="0" cellspacing="0" cellpadding="0" class="stepform">
570        <tr>
571          <td rowspan="3" class="stepno">3</td>
572          <td class="steptitle">Generated report</td>
573        </tr>
574        <tr>
575          <td id="reportcell" class="stepfields">
576            <i>Generating report...</i>
577          </td>
578        </tr>
579        </table>
580        <div id="canvasDiv01" style="display: none;>
581          <canvas id="plot01" width="700" height="550">
582            <p>Your browser doesn't support canvas.</p>
583          </canvas>
584        </div>
585        <div id="canvasDiv02" style="display: none;>
586          <canvas id="plot02" width="700" height="550">
587            <p>Your browser doesn't support canvas.</p>
588          </canvas>
589        </div>
590        <div id="canvasDiv03" style="display: none;>
591          <canvas id="plot03" width="700" height="450">
592            <p>Your browser doesn't support canvas.</p>
593          </canvas>
594        </div>
595      </div> 
596     
597      <div class="messagecontainer error" id="errorMessage" style="display: none; width: 950px; margin-left: 20px; margin-bottom: 0px;"></div>   
598       
599      <table style="margin-left: 20px; margin-top: 10px;" class="navigation">
600        <tr>
601          <td><base:button id="gocancel" title="Cancel" onclick="goRestart(false)" style="display: none;"/></td>
602          <td><base:button id="gonext" title="Next" image="<%=home+"/images/gonext.png"%>" onclick="goNext(true)" /></td>
603          <td><base:button id="gocreate" title="Generate" image="<%=home+"/images/gonext.png"%>" onclick="goCreate()" style="display: none;"/></td>         
604          <td><base:button id="gorestart" title="Restart" image="<%=home+"/images/goback.png"%>" onclick="goRestart(true)" style="display: none;"/></td>
605          <td id="gonext.message" class="message"></td>
606        </tr>
607      </table>     
608    </form>
609    </div>
610   
611  </base:body>
612  </base:page>
613  <%
614}
615finally
616{
617  if (dc != null) dc.close();
618}
619%>
Note: See TracBrowser for help on using the repository browser.