source: extensions/net.sf.basedb.reggie/tags/1.3/resources/consentform.jsp @ 1485

Last change on this file since 1485 was 1354, checked in by Nicklas Nordborg, 11 years ago

Fixes #307: Consent form registration

File size: 13.7 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.util.Values"
11%>
12<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
13<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
14<%
15final SessionControl sc = Base.getExistingSessionControl(request, true);
16final String ID = sc.getId();
17final float scale = Base.getScale(sc);
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="reggie.css">
27  <script language="JavaScript" src="reggie.js" type="text/javascript" charset="UTF-8"></script>
28
29<script language="JavaScript">
30
31var debug = false;
32var currentStep = 1;
33var caseIsValid = false;
34var consentDateIsValid = false;
35
36var consentToId = { "Yes": "consent.yes", "No" : "consent.no", "Not asked": "consent.notAsked" };
37
38var caseInfo = null;
39
40function init()
41{
42  var frm = document.forms['reggie'];
43  frm.caseName.focus();
44}
45
46function step1IsValid()
47{
48  var frm = document.forms['reggie'];
49  var caseName = frm.caseName.value;
50  if (caseName == '')
51  {
52    setInputStatus('case', 'Missing', 'invalid');
53    caseIsValid = false;
54  }
55  else
56  {
57    setInputStatus('case', '', 'valid');
58    caseIsValid = true;
59  }
60  return caseIsValid;
61}
62
63function step2IsValid()
64{
65  return consentDateIsValid;
66}
67
68function goNext(manual)
69{
70  setInnerHTML('gonext.message', '');
71  if (currentStep == 1)
72  {
73    if (step1IsValid()) gotoStep2();
74  }
75  else if (currentStep == 2)
76  {
77    if (step2IsValid()) gotoStep3();
78  }
79}
80
81
82function gotoStep2()
83{
84  // Check entered case and pnr with AJAX
85  var frm = document.forms['reggie'];
86 
87  frm.caseName.disabled = true;
88  currentStep = 2;
89 
90  var caseName = frm.caseName.value;
91  var request = Ajax.getXmlHttpRequest();
92  var url = 'ConsentForm.servlet?ID=<%=ID%>&cmd=GetCaseInfo';
93  url += '&caseName=' + caseName;
94  request.open("GET", url, false);
95  request.send(null);
96 
97  if (debug) Main.debug(request.responseText);
98  var response = JSON.parse(request.responseText);
99  if (response.status != 'ok')
100  {
101    setFatalError(response.message);
102    return false;
103  }
104 
105  Main.hide('gonext');
106  Main.show('consentSection');
107 
108  // Get case information from the AJAX response
109  caseInfo = response.caseInfo;
110
111  if (caseInfo.consentDate)
112  {
113    frm.consentDate.value = caseInfo.consentDate;
114  }
115  frm.consentDate.focus();
116
117 
118  // caseInfo.consent = 'No';
119  // caseInfo.id = 999;
120  // caseInfo.specimen = [ 1 ];
121   
122  if (caseInfo.consent)
123  {
124    // A consent has already been registered for this case
125    // We do not support updating this
126    enableConsentOption(consentToId[caseInfo.consent], true);
127    setInputStatus('consent', '"' + caseInfo.consent + '" has already been registered for this case. It is not possible to change with this wizard.', '');
128    Main.show('gorestart');
129    frm.consentDate.disabled = true;
130  }
131  else if (caseInfo.id)
132  {
133    // There is an existing case already registered
134    // This wizard will only allow 'Yes' option on the consent form
135    enableConsentOption('consent.yes', true);
136    setInputStatus('consent', 'This case is already exists.', 'valid');
137    Main.showInline('morehelp.yes');
138    Main.show('gocancel');
139    Main.show('goregister');
140  }
141  else if (caseInfo.specimen && caseInfo.specimen.length > 0)
142  {
143    // There is no existing case but there are specimen related to it
144    // This wizard can't be used until the "Personal registration wizard"
145    // has been completed for this case
146    setInputStatus('consent', 'Specimen tubes for this case already exists.', 'invalid');
147    Main.showInline('morehelp.specimen');
148    Main.show('gorestart');
149    frm.consentDate.disabled = true;
150  }
151  else
152  {
153    // We have no information about this case
154    // The wizard will only allow 'No' and 'Not asked' option on the consent form
155    enableConsentOption('consent.no', true);
156    enableConsentOption('consent.notAsked');
157    Main.showInline('morehelp.no');
158    Main.show('gocancel');
159    Main.show('goregister');
160  }
161
162}
163
164function goRegister()
165{
166  if (!step2IsValid()) return;
167 
168  var frm = document.forms['reggie'];
169  frm.otherReasonIfNotAsked.disabled = true;
170  frm.consentDate.disabled = true;
171  for (var i = 0; i < frm.consent.length; i++)
172  {
173    frm.consent[i].disabled = true;
174  }
175  for (var i = 0; i < frm.reasonIfNotAsked.length; i++)
176  {
177    frm.reasonIfNotAsked[i].disabled = true;
178  }
179 
180  Main.hide('goregister');
181  Main.hide('gocancel');
182
183  caseInfo.consentDate = frm.consentDate.value;
184  caseInfo.consent = Forms.getCheckedRadio(frm.consent).value;
185  if (caseInfo.consent == 'Not asked')
186  {
187    var selectedReasonIfNotAsked = Forms.getCheckedRadio(frm.reasonIfNotAsked);
188    if (selectedReasonIfNotAsked)
189    {
190      if (selectedReasonIfNotAsked.id == 'notAsked.other')
191      {
192        caseInfo.reasonIfNotAsked = frm.otherReasonIfNotAsked.value;
193      }
194      else
195      {
196        var label = document.getElementById(selectedReasonIfNotAsked.id + '.label');
197        caseInfo.reasonIfNotAsked = label.innerHTML;
198      }
199    }
200  }
201 
202  var submitInfo = new Object();
203  submitInfo.caseInfo = caseInfo;
204
205  if (debug) Main.debug(JSON.stringify(submitInfo));
206  var request = Ajax.getXmlHttpRequest();
207  var url = 'ConsentForm.servlet?ID=<%=ID%>&cmd=RegisterConsent';
208  request.open("POST", url, false);
209  request.setRequestHeader("Content-Type", "application/json");
210  request.send(JSON.stringify(submitInfo));
211
212  if (debug) Main.debug(request.responseText);
213 
214  var response = JSON.parse(request.responseText);
215  if (response.status != 'ok')
216  {
217    setFatalError(response.message);
218    return false;
219  }
220 
221  var msg = '<ul>';
222  for (var i = 0; i < response.messages.length; i++)
223  {
224    msg += '<li>' + response.messages[i];
225  }
226  msg += '</ul>';
227  setInnerHTML('done', msg);
228  Main.show('done');
229  Main.show('gorestart');
230}
231
232function enableConsentOption(optionId, checkIt)
233{
234  var option = document.getElementById(optionId); // The radio button
235  option.disabled = false;
236  if (checkIt) option.checked = true;
237  var label = document.getElementById(optionId + '.label'); // The label
238  Main.removeClass(label, 'disabled');
239}
240
241function consentDateOnChange()
242{
243  var frm = document.forms['reggie'];
244  consentDateIsValid = false;
245  setInputStatus('consentDate', '', '');
246 
247  var consentDate = frm.consentDate.value;
248 
249  if (consentDate == '')
250  {
251    setInputStatus('consentDate', 'Missing', 'invalid');
252    return;
253  }
254  else
255  {
256    if (!Dates.isDate(consentDate, 'yyyy-MM-dd'))
257    {
258      setInputStatus('consentDate', 'Not a valid date', 'invalid');
259      return;
260    }
261    setInputStatus('consentDate', '', 'valid');
262  }
263 
264  consentDateIsValid = true;
265}
266
267
268function consentOnChange()
269{
270  // If "Not asked" is selected we must enable the second question
271  var isAsked = !document.getElementById('consent.notAsked').checked;
272 
273  var frm = document.forms['reggie'];
274  var reasonIfNotAsked = frm.reasonIfNotAsked;
275  for (var i = 0; i < reasonIfNotAsked.length; i++)
276  {
277    reasonIfNotAsked[i].disabled = isAsked;
278    var label = document.getElementById(reasonIfNotAsked[i].id + '.label');
279    Main.addOrRemoveClass(label, 'disabled', isAsked);
280  }
281  frm.otherReasonIfNotAsked.disabled = isAsked;
282 
283}
284
285</script>
286<style>
287.disabled
288{
289  color: #999999;
290  font-style: italic;
291}
292</style>
293</base:head>
294<base:body onload="init()">
295
296  <p:path style="margin-top: 20px; margin-bottom: 10px;">
297    <p:pathelement title="Reggie" href="<%="index.jsp?ID="+ID%>" />
298    <p:pathelement title="Consent form registration" />
299  </p:path>
300
301  <%
302  if (sc.getActiveProjectId() == 0)
303  {
304    %>
305    <base:note type="warning" style="width: 800px; margin-left: 20px; margin-bottom: 20px; margin-right: 0px; font-weight: bold; color: #cc0000;">
306      No project has been selected. You may proceed with the registration but
307      created items will not be shared.
308    </base:note>
309    <%
310  }
311  %>
312
313  <form name="reggie" onsubmit="return false;">
314 
315  <!-- 1. Case + Personal number -->
316  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
317  <tr>
318    <td rowspan="3" class="stepno">1</td>
319    <td class="steptitle">Enter Case Name</td>
320  </tr>
321  <tr>
322    <td class="stepfields">
323      <table border="0" cellspacing="0" cellpadding="0" width="100%">
324      <tr>
325        <td class="prompt">Case name</td>
326        <td class="input"><input type="text" name="caseName" 
327          size="18" maxlength="12" onkeypress="doOnTabOrEnter(event, goNext)"></td>
328        <td class="status" id="case.status"></td>
329        <td class="help"><span id="case.message" class="message" style="display: none;"></span>The case (barcode) associated with the case.</td>
330      </tr>
331      </table>
332    </td>
333  </tr>
334  </table>
335
336  <!-- 2. Consent section -->
337  <div id="consentSection" style="display: none;">
338  <p>
339  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
340  <tr>
341    <td rowspan="2" class="stepno">2</td>
342    <td class="steptitle">Consent form</td>
343  </tr>
344  <tr>
345    <td class="stepfields">
346      <table border="0" cellspacing="0" cellpadding="0" width="100%">
347      <tr valign="top">
348        <td class="prompt">Date</td>
349        <td class="input" style="padding-left: 0px;">
350          <input type="text" name="consentDate" value="" size="12" maxlength="10"
351            onblur="consentDateOnChange()">
352        </td>
353        <td class="status" id="consentDate.status"></td>
354        <td class="help">
355          <span id="consentDate.message" class="message" style="display: none;"></span>(YYYY-MM-DD)
356        </td>
357      </tr>
358      <tr valign="top">
359        <td class="prompt">Consent</td>
360        <td class="input" style="padding-left: 0px;">
361          <input id="consent.no" type="radio" name="consent" value="No" disabled onchange="consentOnChange()">
362            <label id="consent.no.label" for="consent.no" class="disabled">No</label><br>
363          <input id="consent.yes" type="radio" name="consent" value="Yes" disabled onchange="consentOnChange()">
364            <label id="consent.yes.label" for="consent.yes" class="disabled">Yes</label><br>
365          <input id="consent.notAsked" type="radio" name="consent" value="Not asked" disabled onchange="consentOnChange()">
366            <label id="consent.notAsked.label" for="consent.notAsked" class="disabled">Not asked</label>
367        </td>
368        <td class="status" id="consent.status"></td>
369        <td class="help" rowspan="2">
370          <span id="consent.message" class="message" style="display: none;"></span>
371          <span id="morehelp.yes" style="display: none;">
372            <b>Yes</b> is the only option supported by this wizard. The other alternatives
373            may require manual deletion of already registered information.
374          </span>
375          <span id="morehelp.specimen" style="display: none;">
376            The <b>Personal information registration</b> wizard must be completed before a
377            <b>Yes</b> can be registered. The other alternatives may require manual
378            deletion of already registered information.
379          </span>
380          <span id="morehelp.no" style="display: none;">
381            The <b>Personal information registration</b> wizard must be completed for
382            this case before a <b>Yes</b> can be registered.
383          </span>
384        </td>
385      </tr>
386      <tr valign="top">
387        <td class="subprompt">Reason if not asked</td>
388        <td class="input">
389          <table border="0" cellpadding="0" cellspacing="0">
390          <tr valign="baseline">
391            <td><img src="../../images/joust/joinbottom.gif"></td>
392            <td><input id="notAsked.forgot" type="radio" name="reasonIfNotAsked" disabled></td>
393            <td><label id="notAsked.forgot.label" for="notAsked.forgot" class="disabled">Forgot to ask the patient</label></td>
394          </tr>
395         
396          <tr valign="baseline">
397            <td></td>
398            <td><input id="notAsked.language" type="radio" name="reasonIfNotAsked" disabled></td>
399            <td><label id="notAsked.language.label" for="notAsked.language" class="disabled">Language problems</label></td>
400          </tr>
401
402          <tr valign="baseline">
403            <td></td>
404            <td><input id="notAsked.condition" type="radio" name="reasonIfNotAsked" disabled></td>
405            <td><label id="notAsked.condition.label" for="notAsked.condition" class="disabled">Patient can't decide due to physical and/or mental condition</label></td>
406          </tr>
407
408          <tr valign="baseline">
409            <td></td>
410            <td><input id="notAsked.other" type="radio" name="reasonIfNotAsked" disabled></td>
411            <td><label id="notAsked.other.label" for="notAsked.other" class="disabled">Other:</label></td>
412          </tr>
413
414          <tr valign="baseline">
415            <td></td>
416            <td colspan="2">
417            <textarea name="otherReasonIfNotAsked" rows="3" cols="30" disabled
418              onfocus="document.forms['reggie'].reasonIfNotAsked[3].click()"></textarea>
419            </td>
420          </tr>
421          </table>
422
423        </td>
424        <td class="status" id="notAsked.status"></td>
425      </tr>
426      </table>
427    </td>
428  </tr>
429  </table>
430  </div>
431 
432  <div class="error" id="errorMessage" style="display: none; width: 800px; margin-left: 20px; margin-bottom: 0px;"></div>
433
434  <div id="done" class="success" style="display: none; width: 800px; margin-left: 20px; margin-top: 20px;"></div>
435
436  <table style="margin-left: 20px; margin-top: 10px;" class="navigation">
437  <tr>
438    <td><base:button id="gocancel" title="Cancel" onclick="goRestart(false)" style="display: none;"/></td>
439    <td><base:button id="gonext" title="Next" image="gonext.gif" onclick="goNext(true)"/></td>
440    <td><base:button id="goregister" title="Register" image="gonext.gif" onclick="goRegister()" style="display: none;"/></td>
441    <td><base:button id="gorestart" title="Restart" image="goback.gif" onclick="goRestart(true)" style="display: none;"/></td>
442    <td id="gonext.message" class="message"></td>
443  </tr>
444  </table>
445  </form>
446 
447</base:body>
448</base:page>
449<%
450}
451finally
452{
453  if (dc != null) dc.close();
454}
455%>
Note: See TracBrowser for help on using the repository browser.