source: extensions/net.sf.basedb.reggie/trunk/resources/export_monthly_oplist.jsp @ 1721

Last change on this file since 1721 was 1721, checked in by Nicklas Nordborg, 9 years ago

Fixes #416: Check consent before exporting "monthly operation list"

This is now implemented as an extra column in the exported list. The HTML preview parses the export and automatically display a warning icon to cases that doesn't have an explicit 'YES'.

File size: 7.3 KB
Line 
1<%@ page
2  pageEncoding="UTF-8"
3  session="false"
4  import="net.sf.basedb.core.Application"
5  import="net.sf.basedb.core.User"
6  import="net.sf.basedb.core.DbControl"
7  import="net.sf.basedb.core.SessionControl"
8  import="net.sf.basedb.clients.web.Base"
9  import="net.sf.basedb.clients.web.util.HTML"
10  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
11  import="net.sf.basedb.util.Values"
12  import="net.sf.basedb.util.formatter.DateFormatter"
13  import="java.util.Calendar"
14  import="java.util.Locale"
15  import="java.text.SimpleDateFormat"
16%>
17<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
18<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
19<%
20final SessionControl sc = Base.getExistingSessionControl(request, true);
21final String ID = sc.getId();
22final float scale = Base.getScale(sc);
23final String home = ExtensionsControl.getHomeUrl("net.sf.basedb.reggie");
24DbControl dc = null;
25try
26{
27  dc = sc.newDbControl();
28  final User user = User.getById(dc, sc.getLoggedInUserId());
29%>
30<base:page type="default" >
31<base:head scripts="ajax.js" styles="path.css">
32  <link rel="stylesheet" type="text/css" href="css/reggie.css">
33  <script language="JavaScript" src="reggie.js" type="text/javascript" charset="UTF-8"></script>
34
35<script language="JavaScript">
36
37function goExport(preview)
38{
39  var frm = document.forms['reggie'];
40  var url = 'Export.servlet?ID=<%=ID%>&cmd=ExportMonthlyOpList';
41  url += '&time=' + frm.time.value;
42  url += '&exportSubtype='+(frm.exportSubtype.checked ? 1 : 0);
43  if (preview)
44  {
45    var previewTitle = document.getElementById('previewTitle');
46    var previewList = document.getElementById('previewList');
47   
48    Main.hide('previewWrapper');
49    previewTitle.innerHTML = 'Working...';
50    previewList.innerHTML = '';
51   
52    url += '&preview=1';
53    var request = Ajax.getXmlHttpRequest();
54   
55    try
56    {
57      showLoadingAnimation('Working...');
58      request.open("GET", url, false); 
59      request.send(null);
60    }
61    finally
62    {
63      hideLoadingAnimation();
64    }
65
66    if (request.status != 200)
67    {
68      Main.openPopup('', 'ErrorWindow', 800, 600);
69      Main.getWindow('ErrorWindow').document.write(request.responseText);
70    }
71    else
72    {
73      var allLines = request.responseText.split('\n');
74      var numLines = allLines.length - 1;
75     
76      // Check last column for the 'Consent' value. All should be 'YES' for the export to be ok.
77      var numNoConsent = 0;
78      var numMissingConsent = 0;
79      for (var i = 0 ; i < numLines; i++)
80      {
81        var line = allLines[i];
82        var lastColIdx = line.lastIndexOf('\t');
83        var lastCol = line.substr(lastColIdx+1);
84       
85        if (lastCol != 'YES')
86        {
87          if (lastCol == 'MISSING')
88          {
89            numMissingConsent++;
90          }
91          else
92          {
93            numNoConsent++;
94          }
95          allLines[i] = '<span class="consent-warning">'+line+'</span>';
96        }
97      }
98     
99      if (numMissingConsent > 0 || numNoConsent > 0)
100      {
101        var previewWarning = document.getElementById('previewWarning');
102        var warning = '<img src="images/warning.png" alt="!">';
103        warning += ' Found ' + (numNoConsent+numMissingConsent) + ' case(s) with denied or missing consent!';
104        previewWarning.innerHTML = warning;
105      }
106     
107      previewTitle.innerHTML = 'Operation dates - ' + frm.time[frm.time.selectedIndex].text + ' (' + numLines + ')';
108      previewList.innerHTML = allLines.join('\n');
109      Main.show('previewWrapper');
110    }
111  }
112  else
113  {
114    window.location = url;   
115  }
116 
117}
118
119</script>
120<style>
121
122.fullyear
123{
124  font-weight: bold;
125}
126
127#previewWrapper
128{
129  position: absolute;
130  top: 9em;
131  bottom: 1em;
132  left: 20px;
133  width: 950px;
134  overflow: visible;
135}
136
137#previewList
138{
139  position: absolute;
140  top: 1.5em;
141  bottom: 0px;
142  width: 950px;
143  overflow: auto;
144  white-space: pre;
145  font-family: monospace;
146  border: 1px dotted #A0A0A0;
147  border-radius: 4px;
148  background: #E8E8E8;
149  padding: 0.25em;
150}
151
152#previewTitle
153{
154  font-weight: bold;
155}
156
157.consent-warning
158{
159  font-weight: bold;
160  color: #A00000;
161  background-color: #F8F8E8;
162}
163
164.consent-warning:after
165{
166  content: url('images/warning_small.png');
167  vertical-align: middle;
168}
169
170</style>
171</base:head>
172<base:body onload="init()">
173
174  <p:path><p:pathelement 
175    title="Reggie" href="<%="index.jsp?ID="+ID%>" 
176    /><p:pathelement title="Export monthly operation list" 
177    /></p:path>
178
179  <div class="content">
180  <%
181  if (sc.getActiveProjectId() == 0)
182  {
183    %>
184    <div class="messagecontainer note" style="width: 950px; margin-left: 20px; margin-bottom: 20px; margin-right: 0px; font-weight: bold; color: #cc0000;">
185      No project has been selected. You may proceed with the export but
186      it may no include all items.
187    </div>
188    <%
189  }
190  %>
191  <form name="reggie" onsubmit="return false;">
192 
193  <!-- 1. Select month -->
194  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
195  <tr>
196    <td rowspan="3" class="stepno">1</td>
197    <td class="steptitle">Select month or year</td>
198  </tr>
199  <tr>
200    <td class="stepfields">
201      <table border="0" cellspacing="0" cellpadding="0" width="100%">
202      <tr>
203        <td class="prompt">Month/Year</td>
204        <td class="input">
205          <select name="time">
206          <%
207          Calendar month = Calendar.getInstance(Locale.ENGLISH);
208          DateFormatter monthly = new DateFormatter(new SimpleDateFormat("yyyy MMMM", Locale.ENGLISH));
209          DateFormatter yearly = new DateFormatter(new SimpleDateFormat("yyyy", Locale.ENGLISH));
210          int index = 0;
211          while (month.get(Calendar.YEAR) > 2009)
212          {
213            %>
214            <option value="<%=month.getTimeInMillis()%>" <%=index==1 ? "selected" : "" %>><%=monthly.format(month.getTime())%>
215            <%
216            if (month.get(Calendar.MONTH) == 0)
217            {
218              %>
219              <option class="fullyear" value="-<%=month.getTimeInMillis()%>"><%=yearly.format(month.getTime()) %> (all)
220              <%
221            }
222            index++;
223            month.add(Calendar.MONTH, -1);
224          }
225          %>
226          </select>
227        </td>
228        <td class="help"><span id="time.message" class="message" style="display: none;"></span></td>
229      </tr>
230     
231      <tr>
232        <td class="prompt">Optional columns</td>
233        <td class="input">
234          <input type="checkbox" name="exportSubtype" value="1" id="exportSubtype">
235          <label for="exportSubtype">Specimen/NoSpecimen</label>
236        </td>
237        <td class="help"><span id="subtype.message" class="message" style="display: none;"></span></td>
238      </tr>
239      </table>
240    </td>
241  </tr>
242  </table>
243
244  <div class="messagecontainer error" id="errorMessage" style="display: none; width: 950px; margin-left: 20px; margin-bottom: 0px;"></div>
245
246  <div id="done" class="success" style="display: none; width: 950px; margin-left: 20px; margin-top: 20px;"></div>
247
248  <table style="margin-left: 20px; margin-top: 10px;" class="navigation">
249  <tr>
250    <td><base:button id="gopreview" title="Preview" image="<%=home+"/images/export.png"%>" onclick="goExport(true)"/></td>
251    <td><base:button id="goexport" title="Download" image="<%=home+"/images/download.png"%>" onclick="goExport(false)"/></td>
252  </tr>
253  </table>
254  </form>
255 
256  <div class="loading" id="loading" style="display: none;"><table><tr><td><img src="images/loading.gif"></td><td id="loading.msg">Please wait...</td></tr></table></div>
257 
258  <div id="previewWrapper" style="display: none;">
259    <div>
260      <span id="previewTitle">Preview</span>
261      <span id="previewWarning"></span>
262    </div>
263    <div id="previewList"></div>
264  </div>
265 
266  </div>
267 
268</base:body>
269</base:page>
270<%
271}
272finally
273{
274  if (dc != null) dc.close();
275}
276%>
Note: See TracBrowser for help on using the repository browser.