source: extensions/net.sf.basedb.labenv/trunk/resources/reports/labenvironmentdatabaseeventpopup.jsp @ 2486

Last change on this file since 2486 was 2486, checked in by olle, 9 years ago

Refs #592. Lab environment extension updated in JSP files by removing warning if no BASE project has been selected, since this is not necessary for the lab environment extension functionality:

  1. JSP files in resources/reports/ updated in HTML section by removal of warning if no BASE project has been selected:
    a. labenvironmentalarms.jsp
    b. labenvironmentdatabasedisplay.jsp
    c. labenvironmentdatabaseeventpopup.jsp
    d. labenvironmentdatabaseexport.jsp
    e. labenvironmentdatabasestatistics.jsp
    f. labsensorinfo.jsp
File size: 15.4 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.labenv.service");
18DbControl dc = null;
19try
20{
21  dc = sc.newDbControl();
22  final User user = User.getById(dc, sc.getLoggedInUserId());
23  %>
24<base:page type="popup" title="LabEnv">
25<base:head scripts="table.js,ajax.js" styles="table.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 = false;
34
35  window.onload = function()
36  {
37    // Create pop-up window from request parameter data
38    goCreate();
39  };
40
41  function getQueryParameter(parameterName)
42  {
43    var queryString = window.top.location.search.substring(1);
44    var parameterName = parameterName + "=";
45    if ( queryString.length > 0 )
46    {
47      begin = queryString.indexOf(parameterName);
48      if (begin != -1)
49      {
50        begin += parameterName.length;
51        end = queryString.indexOf("&" , begin);
52        if (end == -1)
53        {
54          end = queryString.length;
55        }
56        return unescape(queryString.substring(begin, end));
57      }
58    }
59    return "null";
60  }
61
62  function getStorageIntervalInSeconds()
63  {
64    var storageIntervalInSeconds = 0;
65    var labEnvDatabaseConfig = getLabEnvDatabaseConfig();
66    if (labEnvDatabaseConfig != null)
67    {
68      storageIntervalInSeconds = labEnvDatabaseConfig.storageIntervalInSeconds;
69    }
70    return storageIntervalInSeconds;
71  }
72
73  function getLabEnvDatabaseConfig()
74  {
75    // Get lab environment database configuration JSON object with AJAX
76    var frm = document.forms['labenv'];
77    var request = Ajax.getXmlHttpRequest();
78    var url = '../../labenv.jar/LabEnvironment.servlet?ID=<%=ID%>&cmd=GetLabEnvDatabaseConfig';
79    request.open("GET", url, false);
80    request.send(null);
81 
82    //if (debug) Main.debug(request.responseText);
83    //Main.debug(request.responseText);
84
85    var response = JSON.parse(request.responseText);
86    if (response.status != 'ok')
87    {
88      setFatalError(response.message);
89      return false;
90    }
91 
92    // Get lab environment database configuration information from the AJAX response
93    var labEnvDatabaseConfig = response.labEnvDatabaseConfig;
94
95    return labEnvDatabaseConfig;
96  }
97
98  var intervalIsValid = true;
99
100  function fetchSimpleDate(dateStr)
101  {
102    var simpleDateStr = dateStr;
103    if (simpleDateStr != null)
104    {
105      var blankIndex = simpleDateStr.indexOf(" ");
106      if (blankIndex >= 0)
107      {
108        // YYYYMMDD HHmm or YYYY-MM-DD HH:mm
109        // Cut off date string before first space
110        simpleDateStr = simpleDateStr.substr(0,blankIndex);
111      }
112      //alert("simpleDateStr = \"" + simpleDateStr + "\" after removing daytime");
113      // YYYYMMDD or YYYY-MM-DD
114      var hyphenIndex = simpleDateStr.indexOf("-");
115      //alert("simpleDateStr = \"" + simpleDateStr + "\" after removing daytime, hyphenIndex = " + hyphenIndex);
116      if (hyphenIndex >= 0)
117      {
118        // YYYY-MM-DD
119        // Cut off date string before first space
120        var yearStr = simpleDateStr.substr(0,4);
121        var monthStr = simpleDateStr.substr(5,2);
122        var dayStr = simpleDateStr.substr(8,2);
123        simpleDateStr = yearStr + monthStr + dayStr;
124        //alert("simpleDateStr = \"" + simpleDateStr + "\" after removing hyphens, yearStr = \"" + yearStr + "\" monthStr = \"" + monthStr + "\" dayStr = \"" + dayStr + "\"");
125      }
126    }
127    // Date in YYYYMMDD format
128    return simpleDateStr;
129  }
130
131  function goCreate()
132  {
133    if (!intervalIsValid) return;
134    var frm = document.forms['labenv'];   
135    var reportType = 'labenvironmentdailydisplay';   
136    Main.hide('gocreate');
137    var url = '../LabEnvironmentDisplay.servlet?ID=<%=ID%>&cmd='+reportType;   
138    var fromDate = null;
139    var chartVariant = null;
140    if (chartVariant == null)
141    {
142      chartVariant = 'http://givare1.onk.lu.se/';
143    }
144    var pageTitle = getQueryParameter('pageTitle');
145    var labSensorUrl = getQueryParameter('labSensorUrl');
146    var originDate = getQueryParameter('originDate');
147    originDate = fetchSimpleDate(originDate);
148    if (originDate != null)
149    {
150      fromDate = originDate;
151    }
152    if (labSensorUrl != null)
153    {
154      chartVariant = labSensorUrl;
155    }
156    if (pageTitle != null) url += '&pagetitle='+pageTitle;
157    if (fromDate != null) url += '&fdate='+fromDate;
158    if (chartVariant != null) url += '&cvariant='+chartVariant;
159
160    var request = Ajax.getXmlHttpRequest();
161    request.open("GET", url, true);
162    Ajax.setReadyStateHandler(request, onPlotGenerated);
163    request.send(null);
164  }
165 
166  function onPlotGenerated(request)
167  {
168    Main.show('reportSection');
169    var frm = document.forms['labenv'];   
170    var reportType = 'labenvironmentdailydisplay';   
171    if (debug) Main.debug(Main.encodeTags(request.responseText));
172    var response = JSON.parse(request.responseText); 
173    if (response.status != 'ok')
174    {
175      setFatalError(response.message);
176      return false;
177    }
178    var report = response.report;
179    var permissionDeniedForPatientName = report.permissionDeniedForPatientName;
180    var pageTitle = report.pageTitle;
181    if (pageTitle == null || pageTitle == '')
182    {
183      pageTitle = 'LabEnv';
184    }
185    // Print optional page title
186    var pageTitleElement = document.getElementById('pageTitleId');
187    pageTitleElement.innerHTML = pageTitle;
188    var reportTable;
189    var cellElement = document.getElementById('reportdiv');
190    if (report != null)
191    {
192      //alert("onPlotGenerated(): Inside plot block for labenvironmentdailydisplay");
193      var storageIntervalInSeconds = getStorageIntervalInSeconds();
194      var draw_area_wdt = 700;
195      var draw_area_hgt = 550;
196      var draw_scale_factor = 2;
197      var jsonStatisticsPlotArray = report.plotStatistics;
198      // Draw plots
199      setInnerHTML('reportdiv', '');
200      // Write optional page header
201      if (pageTitle != null && pageTitle != '')
202      {
203        // Print optional page headline
204        var headlineText = document.createElement('text');
205        headlineText.innerHTML = "<h2>" + pageTitle + "</h2><BR>";
206        cellElement.appendChild(headlineText);
207      }
208      for (var plotIndex in jsonStatisticsPlotArray)
209      {
210        //
211        // Get plot JSON data container with extra info and plot data
212        var plotJsonDataContainer = jsonStatisticsPlotArray[plotIndex];
213        // Get plot JSON extra info and plot data
214        var plotChartVariant = plotJsonDataContainer['chartVariant'];
215        var plotViewType = plotJsonDataContainer['viewType'];
216        var plotOptionalHeadline = plotJsonDataContainer['optionalHeadline'];
217        var boxPlotJsonData = plotJsonDataContainer['plotData'];
218        // Create plot from plot JSON data
219        if (plotOptionalHeadline != null && plotOptionalHeadline != '')
220        {
221          // Print optional headline
222          var headlineText = document.createElement('text');
223          headlineText.innerHTML = "<BR>" + plotOptionalHeadline + "<BR>";
224          cellElement.appendChild(headlineText);
225        }
226        var plotKey = plotChartVariant + '_' + plotViewType;
227        // Add plot
228        var canvasInTable = document.createElement('canvas');
229        canvasInTable.setAttribute('id', plotKey);
230        canvasInTable.setAttribute('width', draw_area_wdt * draw_scale_factor);
231        canvasInTable.setAttribute('height', draw_area_hgt * draw_scale_factor);
232        createGraphPlot(boxPlotJsonData, canvasInTable, draw_area_wdt, draw_area_hgt, draw_scale_factor, plotViewType, storageIntervalInSeconds);
233        cellElement.appendChild(canvasInTable);         
234        canvasInTable.addEventListener('mousemove', drawCanvasGuidelines, false);
235        canvasInTable.addEventListener('mouseleave', hideCanvasGuidelines, false);
236      }
237      // Print optional appended info
238      var appendedInfo = report.appendedInfo;
239      if (appendedInfo != null && appendedInfo != '')
240      {
241        // Print optional headline
242        var infoText = document.createElement('text');
243        infoText.innerHTML = "<BR>" + appendedInfo + "<BR>";
244        cellElement.appendChild(infoText);
245      }
246    }
247    else
248    {
249      var messageCell = getTableCellElement(document, '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('printButton');
257    Main.show('gorestart');   
258  }
259
260  function getJSONData(jsonObject, key)
261  {
262    var data = getJSONData(jsonObject, key, '');
263    return data;
264  }
265
266  function getJSONData(jsonObject, key, defaultChoice)
267  {
268    var data = defaultChoice;
269    if (jsonObject != null)
270    {
271      if (jsonObject[key] != null)
272      {
273        data = jsonObject[key];
274      }
275    }
276    return data;
277  }
278
279  function getReportTable()
280  {
281      var reportTable = document.createElement('table');
282      reportTable.setAttribute('class','reporttable');
283      reportTable.setAttribute('border','1');     
284      return reportTable;
285  }
286 
287  function getTableCellElement(topDocument, text, clazz, colspan, rowspan)
288  {
289    if (topDocument != null)
290    {
291      cellElement = topDocument.createElement('td');
292    }
293    var cellElement = topDocument.createElement('td');
294    text = new String(text);   
295    var textArray = text.split("\n");   
296    if (textArray.length > 1)
297    {
298      for (var i=0;i<textArray.length;i++)
299      {       
300        if (i>0)cellElement.appendChild(topDocument.createElement('br'));
301        cellElement.appendChild(topDocument.createTextNode(textArray[i]));
302      }     
303    }
304    else
305    {
306      cellElement.appendChild(topDocument.createTextNode(text));
307    }
308    cellElement.setAttribute('class', clazz);
309    if (colspan != null) cellElement.setAttribute('colspan', colspan);
310    if (rowspan != null) cellElement.setAttribute('rowspan', rowspan);
311   
312    return cellElement;
313  }
314 
315  /**
316   *  addHyphensToDateStr()
317   *
318   *  Adds hyphens to date string in yyyymmdd format to
319   *  get yyyy-mm-dd format. If input string already contains
320   *  hyphen(s), the input string is returned unchanged.
321   *  If input string is null or empty, '????-??-??' is returned.
322   *
323   *  @param dateStr String Input date string in yyyy-mm-dd or yyyymmdd format.
324   *  @return String Date string in yyyy-mm-dd format.
325   */
326  function addHyphensToDateString(dateStr)
327  {
328    var dateWithHyphensStr = '????-??-??';
329    if (dateStr != null && dateStr != '')
330    {
331      // Check if input string already contains hyphen
332      if (dateStr.indexOf("-") >= 0)
333      {
334        // Date already has hyphen(s)
335        dateWithHyphensStr = dateStr;
336      }
337      else
338      {
339        // Date in yyyymmdd format
340        var yearStr = dateStr.substr(0,4);
341        var monthStr = dateStr.substr(4,2);
342        var dayStr = dateStr.substr(6,2);     
343        dateWithHyphensStr = yearStr + '-' + monthStr + '-' + dayStr;
344      }
345    }
346    return dateWithHyphensStr;
347  }
348
349  /**
350   *  dateStrToDate()
351   *
352   *  Takes an input date string in yyyy-mm-dd or yyyymmdd format
353   *  and returns a date corresponding to the date string.
354   *  If input string is null or empty, null is returned.
355   *
356   *  @param dateStr String Input date string in yyyy-mm-dd or yyyymmdd format.
357   *  @return Date Date corresponding to input date string.
358   */
359  function dateStrToDate(dateStr)
360  {
361    var date = null;
362    if (dateStr != null && dateStr != '')
363    {
364      // Check if input string already contains hyphen
365      if (dateStr.indexOf("-") >= 0)
366      {
367        // Date in yyyy-mm-dd format
368        var yearStr = dateStr.substr(0,4);
369        var monthStr = dateStr.substr(5,2);
370        var dayStr = dateStr.substr(8,2);     
371        var date = new Date(parseInt(yearStr, 10), parseInt(monthStr, 10)-1, parseInt(dayStr, 10));
372      }
373      else
374      {
375        // Date in yyyymmdd format
376        var yearStr = dateStr.substr(0,4);
377        var monthStr = dateStr.substr(4,2);
378        var dayStr = dateStr.substr(6,2);     
379        var date = new Date(parseInt(yearStr, 10), parseInt(monthStr, 10)-1, parseInt(dayStr, 10));
380      }
381    }
382    return date;
383  }
384
385  function goPrint()
386  {
387    var printNote = '<b>Note!</b> For better printing set page orientation to <i>portrait</i>.';
388    printNote += ' Scale down to <i>90%</i> to fit 2 plots per page.';
389    openPrintWindow('<%=ID%>', 'reportcell', 'Lab environment ', 'portrait', printNote, '../');
390  }
391 
392  var xGuide;
393  var yGuide;
394 
395  function drawCanvasGuidelines(event)
396  {
397    if (!xGuide)
398    {
399      xGuide = document.getElementById('x-guide');
400      yGuide = document.getElementById('y-guide');
401    }
402    var canvas = event.target;
403    var centerX = event.clientX;
404    var centerY = event.clientY;
405    var canvasPos = Main.getElementPosition(canvas);
406    var startX = canvasPos.left+50;
407    var widthX = canvasPos.width-100;
408    var startY = canvasPos.top+80;
409    var heightY = canvasPos.height-160;
410    if (centerY < startY || centerY > startY+heightY)
411    {
412      // Hide when mouse is in the text area below or over the plot
413      yGuide.style.display = 'none';
414    }
415    else
416    {
417      yGuide.style.top = (centerY-2) + 'px';
418      yGuide.style.left = startX + 'px';
419      yGuide.style.width = widthX + 'px';
420      yGuide.style.display = 'block';
421    }
422    if (centerX < startX || centerX > startX + widthX)
423    {
424      // Hide when mouse is in the text area to the left or right of the plot
425      xGuide.style.display = 'none';
426    }
427    else
428    {
429      // Avoid drawing outside the avilable hight (causes an extra pair of scroll bars)
430      var yLimit = Main.getWindowHeight();
431      if (startY+heightY > yLimit)
432      {
433        heightY = yLimit-startY;
434      }
435      xGuide.style.top = startY + 'px';
436      xGuide.style.left = (centerX-2) + 'px';
437      xGuide.style.height = heightY + 'px';
438      xGuide.style.display = 'block';
439    }
440
441  }
442 
443  function hideCanvasGuidelines(event)
444  {
445    xGuide.style.display = 'none';
446    yGuide.style.display = 'none';
447  }
448  </script>
449 
450  <style>
451  canvas
452  {
453    width: 700px;
454    height: 550px;
455  }
456  </style>
457  <base:body onload="init()">
458    <p:path><p:pathelement 
459      title="" href="<%="./labenvironmentdatabaseeventpopup.jsp?ID="+ID%>" 
460      /><p:pathelement id="pageTitleId" title="Lab environment event display"
461      /></p:path>
462    <div id="x-guide" style="position: absolute; z-index: 99; display: none; background-color: #224488; width: 1px;"></div>
463    <div id="y-guide" style="position: absolute; z-index: 99; display: none; background-color: #224488; height: 1px;"></div>
464    <div class="content">
465 
466    <form name="labenv" onsubmit="return false;">
467      <div id="reportSection" style="display:block;">
468        <p></p>
469        <table border="0" cellspacing="0" cellpadding="0">
470        <tr>
471          <td id="reportcell">
472            <div id="reportdiv" style="text-align: center;">
473              <div class="loading" id="loading">
474              <table>
475              <tr>
476                <td><img src="../images/loading.gif"></td>
477                <td id="loading.msg">Generating report...</td>
478              </tr>
479              </table>
480              </div>
481            </div>
482          </td>
483        </tr>
484        </table>
485      </div> 
486    </form>
487    </div>
488
489  <base:buttongroup subclass="dialogbuttons">
490    <base:button onclick="goPrint();" image="<%=home+"/images/print.png"%>" title="Print&hellip;" />
491    <base:button onclick="window.close();" title="Cancel" /> 
492  </base:buttongroup>
493
494  </base:body>
495  </base:page>
496  <%
497}
498finally
499{
500  if (dc != null) dc.close();
501}
502%>
Note: See TracBrowser for help on using the repository browser.