source: extensions/net.sf.basedb.reggie/trunk/resources/consentform.jsp @ 1538

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

References #354: Changes related to new GUI in BASE 3.1

This should fix most of the issues related to the GUI differences between BASE 3.0 and 3.1. Reggie should display just fine in both versions. This is solved by:

  • Including all icons needed by Reggie in the Reggie distribution. We don't have to worry about the GIF vs. PNG issue.
  • Mainly designing Reggie for BASE 3.1 and then applying an extra stylesheet with a minial set of styles to make Reggie also work in BASE 3.0. The style sheet is only used if Reggie is installed on a BASE 3.0 server so it should not interfere with BASE 3.1 and up.
File size: 16.8 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%>
13<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
14<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
15<%
16final SessionControl sc = Base.getExistingSessionControl(request, true);
17final String ID = sc.getId();
18final float scale = Base.getScale(sc);
19final String home = ExtensionsControl.getHomeUrl("net.sf.basedb.reggie");
20DbControl dc = null;
21try
22{
23  dc = sc.newDbControl();
24  final User user = User.getById(dc, sc.getLoggedInUserId());
25%>
26<base:page type="default" >
27<base:head scripts="ajax.js" styles="path.css">
28  <link rel="stylesheet" type="text/css" href="css/reggie.css">
29  <%
30  if (Application.getMajorVersion() == 3 && Application.getMinorVersion() == 0)
31  {
32    %>
33    <link rel="stylesheet" type="text/css" href="css/base30.css">
34    <%
35  }
36  %>
37  <script language="JavaScript" src="reggie.js" type="text/javascript" charset="UTF-8"></script>
38
39<script language="JavaScript">
40
41var debug = false;
42var currentStep = 1;
43var caseIsValid = false;
44var consentDateIsValid = false;
45
46var consentToId = { "Yes": "consent.yes", "No" : "consent.no", "Not asked": "consent.notAsked" };
47var patientInfo;
48
49function init()
50{
51  var frm = document.forms['reggie'];
52  frm.caseName.focus();
53}
54
55function step1IsValid()
56{
57  var frm = document.forms['reggie'];
58  var caseName = frm.caseName.value;
59  caseIsValid = false;
60  if (caseName == '')
61  {
62    setInputStatus('case', 'Missing', 'invalid');
63    frm.caseName.focus();
64  }
65  else if (!isValidCaseName(caseName))
66  {
67    setInputStatus('case', 'Only 7-digits name is allowed .', 'invalid');
68    frm.caseName.focus();
69  }
70  else
71  {
72    setInputStatus('case', '', 'valid');
73    caseIsValid = true;
74  }
75 
76  return caseIsValid;
77}
78
79function step2IsValid()
80{
81  return consentDateIsValid;
82}
83
84function goNextAuto()
85{
86  goNext(false);
87}
88
89function goNext(manual)
90{
91  setInnerHTML('gonext.message', '');
92  if (currentStep == 1)
93  {
94    if (step1IsValid()) gotoStep2();
95  }
96  else if (currentStep == 2)
97  {
98    if (step2IsValid()) gotoStep3();
99  }
100}
101
102
103function gotoStep2()
104{
105  // Check entered case and pnr with AJAX
106  var frm = document.forms['reggie'];
107 
108  frm.caseName.disabled = true;
109  currentStep = 2;
110 
111  var caseName = frm.caseName.value;
112  var request = Ajax.getXmlHttpRequest();
113  var url = 'ConsentForm.servlet?ID=<%=ID%>&cmd=GetCaseInfo';
114  url += '&caseName=' + caseName;
115  request.open("GET", url, false);
116  request.send(null);
117 
118  if (debug) Main.debug(request.responseText);
119  var response = JSON.parse(request.responseText);
120  if (response.status != 'ok')
121  {
122    setFatalError(response.message);
123    return false;
124  }
125 
126  Main.hide('gonext');
127  Main.show('consentSection');
128 
129  // Get case information from the AJAX response
130  patientInfo = response.patientInfo;
131  var caseInfo = response.caseInfo;
132  var specimenInfo = response.specimenInfo;
133 
134
135  if (caseInfo && caseInfo.consentDate)
136  {
137    frm.consentDate.value = caseInfo.consentDate;
138  }
139  frm.consentDate.focus();
140 
141  if (patientInfo)
142  {
143    var html = '';
144    var numEnabled = 0;
145    if (patientInfo.allCases)
146    {
147      for (var i = 0; i < patientInfo.allCases.length; i++)
148      {
149        var c = patientInfo.allCases[i];
150        var laterality = c.laterality ? ' ('+c.laterality+')' : '';
151        var disabled = '';
152        if (c.consent)
153        {
154          disabled = 'disabled';
155        }
156        else
157        {
158          numEnabled++;
159        }
160        html += '<input type="checkbox" name="case.'+c.id+'" id="case.'+c.id+'" checked ' + disabled +'>';
161        html += '<label for="case.'+c.id+'">Case: ' + c.name + laterality + '</label><br>';
162      }
163    }
164   
165    if (patientInfo.allBlood)
166    {
167      for (var i = 0; i < patientInfo.allBlood.length; i++)
168      {
169        var c = patientInfo.allBlood[i];
170        var disabled = '';
171        if (c.consent)
172        {
173          disabled = 'disabled';
174        }
175        else
176        {
177          numEnabled++;
178        }
179        html += '<input type="checkbox" name="blood.'+ c.id + '" id="blood.'+c.id+'" checked ' + disabled +'>';
180        html += '<label for="blood.'+c.id+'">Blood: ' + c.name + '</label><br>';
181      }
182    }
183   
184    document.getElementById('moreCases').innerHTML = html;
185   
186    if (numEnabled > 0)
187    {
188      enableConsentOption('consent.yes', true);
189      setInputStatus('consent', 'This patient already exists and has at least one case or blood sample with missing consent.', 'valid');
190      Main.showInline('morehelp.multiple');
191      Main.showInline('morehelp.yesonly');
192      Main.show('gocancel');
193      Main.show('goregister');
194    }
195    else
196    {
197      enableConsentOption('consent.yes', true);
198      setInputStatus('consent', '"Yes" has already been registered for all case and blood samples for this patient. It is not possible to change with this wizard.', '');
199      Main.show('gorestart');
200      frm.consentDate.disabled = true;
201    }
202    Main.show('moreCasesSection');
203  }
204  else if (caseInfo)
205  {
206    // A consent has already been registered for this case
207    // We do not support updating this
208    enableConsentOption(consentToId[caseInfo.consent], true);
209    setInputStatus('consent', '"' + caseInfo.consent + '" has already been registered for this case. It is not possible to change with this wizard.', '');
210    Main.show('gorestart');
211    frm.consentDate.disabled = true;
212  }
213  else if (specimenInfo)
214  {
215    // There is no existing case but there are specimen related to it
216    // This wizard will only allow 'Yes' option on the consent form
217    enableConsentOption('consent.yes', true);
218    setInputStatus('consent', 'Specimen tubes for this case already exists.', 'valid');
219    Main.showInline('morehelp.yesonly');
220    Main.show('gocancel');
221    Main.show('goregister');
222  }
223  else
224  {
225    // We have no information about this case -- but allow a consent to be registered in any case
226    enableConsentOption('consent.no', true);
227    enableConsentOption('consent.notAsked');
228    enableConsentOption('consent.yes');
229    Main.showInline('morehelp.any');
230    Main.show('gocancel');
231    Main.show('goregister');
232  }
233
234}
235
236function goRegister()
237{
238  if (!step2IsValid()) return;
239 
240  var frm = document.forms['reggie'];
241  frm.otherReasonIfNotAsked.disabled = true;
242  frm.consentDate.disabled = true;
243  for (var i = 0; i < frm.consent.length; i++)
244  {
245    frm.consent[i].disabled = true;
246  }
247  for (var i = 0; i < frm.reasonIfNotAsked.length; i++)
248  {
249    frm.reasonIfNotAsked[i].disabled = true;
250  }
251 
252  Main.hide('goregister');
253  Main.hide('gocancel');
254
255  var consentInfo = new Object();
256  consentInfo.caseName = frm.caseName.value;
257  consentInfo.consentDate = frm.consentDate.value;
258  consentInfo.consent = Forms.getCheckedRadio(frm.consent).value;
259  if (consentInfo.consent == 'Not asked')
260  {
261    var reasonIfNotAsked = '';
262    for (var i = 0; i < frm.reasonIfNotAsked.length; i++)
263    {
264      var option = frm.reasonIfNotAsked[i];
265      if (option.checked)
266      {
267        if (option.id == 'notAsked.other')
268        {
269          reasonIfNotAsked += frm.otherReasonIfNotAsked.value;
270        }
271        else
272        {
273          var label = document.getElementById(option.id + '.label');
274          reasonIfNotAsked += label.innerHTML + '\n';
275        }
276      }
277    }
278    consentInfo.reasonIfNotAsked = reasonIfNotAsked;
279  }
280 
281  if (patientInfo)
282  {
283    var selectedSamples = new Array();
284    if (patientInfo.allCases)
285    {
286      for (var i = 0; i < patientInfo.allCases.length; i++)
287      {
288        var c = patientInfo.allCases[i];
289        var chk = frm['case.'+c.id];
290        if (chk.checked && !chk.disabled) selectedSamples[selectedSamples.length] = c.id;
291      }
292    }
293   
294    if (patientInfo.allBlood)
295    {
296      for (var i = 0; i < patientInfo.allBlood.length; i++)
297      {
298        var c = patientInfo.allBlood[i];
299        var chk = frm['blood.'+c.id];
300        if (chk.checked && !chk.disabled) selectedSamples[selectedSamples.length] = c.id;
301      }
302    }
303    consentInfo.selectedSamples = selectedSamples;
304  }
305
306  var submitInfo = new Object();
307  submitInfo.consentInfo = consentInfo;
308 
309  if (debug) Main.debug(JSON.stringify(submitInfo));
310  var request = Ajax.getXmlHttpRequest();
311  var url = 'ConsentForm.servlet?ID=<%=ID%>&cmd=RegisterConsent';
312  request.open("POST", url, false);
313  request.setRequestHeader("Content-Type", "application/json");
314  request.send(JSON.stringify(submitInfo));
315
316  if (debug) Main.debug(request.responseText);
317 
318  var response = JSON.parse(request.responseText);
319  if (response.status != 'ok')
320  {
321    setFatalError(response.message);
322    return false;
323  }
324 
325  var msg = '<ul>';
326  for (var i = 0; i < response.messages.length; i++)
327  {
328    msg += '<li>' + response.messages[i];
329  }
330  msg += '</ul>';
331  setInnerHTML('done', msg);
332  Main.show('done');
333  Main.show('gorestart');
334}
335
336function enableConsentOption(optionId, checkIt)
337{
338  var option = document.getElementById(optionId); // The radio button
339  option.disabled = false;
340  if (checkIt) option.checked = true;
341  var label = document.getElementById(optionId + '.label'); // The label
342  Main.removeClass(label, 'disabled');
343}
344
345function consentDateOnChange()
346{
347  var frm = document.forms['reggie'];
348  consentDateIsValid = false;
349  setInputStatus('consentDate', '', '');
350 
351  var consentDate = frm.consentDate.value;
352 
353  if (consentDate == '')
354  {
355    setInputStatus('consentDate', 'Missing', 'warning');
356  }
357  else
358  {
359    // Auto-fill the date if it's only given with 4(MMdd) or 6(yyMMdd) digits.   
360    consentDate = autoFillDate(consentDate);
361    frm.consentDate.value = consentDate;
362 
363    if (!Dates.isDate(consentDate, 'yyyyMMdd'))
364    {
365      setInputStatus('consentDate', 'Not a valid date', 'invalid');
366      return;
367    }
368    setInputStatus('consentDate', '', 'valid');
369  }
370 
371  consentDateIsValid = true;
372}
373
374
375function consentOnChange()
376{
377  // If "Not asked" is selected we must enable the second question
378  var isAsked = !document.getElementById('consent.notAsked').checked;
379 
380  var frm = document.forms['reggie'];
381  var reasonIfNotAsked = frm.reasonIfNotAsked;
382  for (var i = 0; i < reasonIfNotAsked.length; i++)
383  {
384    reasonIfNotAsked[i].disabled = isAsked;
385    var label = document.getElementById(reasonIfNotAsked[i].id + '.label');
386    Main.addOrRemoveClass(label, 'disabled', isAsked);
387  }
388  frm.otherReasonIfNotAsked.disabled = isAsked;
389 
390}
391
392</script>
393<style>
394.disabled
395{
396  color: #999999;
397  font-style: italic;
398}
399</style>
400</base:head>
401<base:body onload="init()">
402
403  <p:path><p:pathelement 
404    title="Reggie" href="<%="index.jsp?ID="+ID%>" 
405    /><p:pathelement title="Consent form registration" 
406    /></p:path>
407
408  <div class="content">
409  <%
410  if (sc.getActiveProjectId() == 0)
411  {
412    %>
413    <div class="messagecontainer note" style="width: 800px; margin-left: 20px; margin-bottom: 20px; margin-right: 0px; font-weight: bold; color: #cc0000;">
414      No project has been selected. You may proceed with the registration but
415      created items will not be shared.
416    </div>
417    <%
418  }
419  %>
420
421  <form name="reggie" onsubmit="return false;">
422 
423  <!-- 1. Case + Personal number -->
424  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
425  <tr>
426    <td rowspan="3" class="stepno">1</td>
427    <td class="steptitle">Enter Case Name</td>
428  </tr>
429  <tr>
430    <td class="stepfields">
431      <table border="0" cellspacing="0" cellpadding="0" width="100%">
432      <tr>
433        <td class="prompt">Case name</td>
434        <td class="input"><input type="text" name="caseName" 
435          size="18" maxlength="12" onkeypress="doOnTabOrEnter(event, goNextAuto)"></td>
436        <td class="status" id="case.status"></td>
437        <td class="help"><span id="case.message" class="message" style="display: none;"></span>The 7-digit case (barcode) associated with the case.</td>
438      </tr>
439      </table>
440    </td>
441  </tr>
442  </table>
443
444  <!-- 2. Consent section -->
445  <div id="consentSection" style="display: none;">
446  <p>
447  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
448  <tr>
449    <td rowspan="2" class="stepno">2</td>
450    <td class="steptitle">Consent form</td>
451  </tr>
452  <tr>
453    <td class="stepfields">
454      <table border="0" cellspacing="0" cellpadding="0" width="100%">
455      <tr valign="top">
456        <td class="prompt">Date</td>
457        <td class="input" style="padding-left: 0px;">
458          <input type="text" name="consentDate" value="" size="12" maxlength="10"
459            onblur="consentDateOnChange()">
460        </td>
461        <td class="status" id="consentDate.status"></td>
462        <td class="help">
463          <span id="consentDate.message" class="message" style="display: none;"></span>(YYYYMMDD or MMDD)
464        </td>
465      </tr>
466      <tr valign="top">
467        <td class="prompt">Consent</td>
468        <td class="input" style="padding-left: 0px;">
469          <input id="consent.no" type="radio" name="consent" value="No" disabled onchange="consentOnChange()">
470            <label id="consent.no.label" for="consent.no" class="disabled">No</label><br>
471          <input id="consent.yes" type="radio" name="consent" value="Yes" disabled onchange="consentOnChange()">
472            <label id="consent.yes.label" for="consent.yes" class="disabled">Yes</label><br>
473          <div id="moreCasesSection" style="display: none;">
474            <table border="0" cellpadding="0" cellspacing="0">
475            <tr valign="baseline">
476              <td><img src="images/joinbottom.gif"></td>
477              <td id="moreCases"></td>
478            </tr>
479            </table>
480          </div>
481          <input id="consent.notAsked" type="radio" name="consent" value="Not asked" disabled onchange="consentOnChange()">
482            <label id="consent.notAsked.label" for="consent.notAsked" class="disabled">Not asked</label>
483        </td>
484        <td class="status" id="consent.status"></td>
485        <td class="help" rowspan="2">
486          <span id="consent.message" class="message" style="display: none;"></span>
487          <span id="morehelp.multiple" style="display:none;">
488            Select the cases and blood samples to register. Cases with
489            already existing consent can't be deselected.
490          </span>
491          <span id="morehelp.yesonly" style="display: none;">
492            <b>Yes</b> is the only option supported by this wizard. The other alternatives
493            may require manual deletion of already registered information.
494          </span>
495          <span id="morehelp.any" style="display: none;">
496            There is currently no information about this case.
497          </span>
498        </td>
499      </tr>
500      <tr valign="top">
501        <td class="subprompt">Reason if not asked</td>
502        <td class="input">
503          <table border="0" cellpadding="0" cellspacing="0">
504          <tr valign="baseline">
505            <td><img src="images/joinbottom.gif"></td>
506            <td><input id="notAsked.forgot" type="checkbox" name="reasonIfNotAsked" disabled></td>
507            <td><label id="notAsked.forgot.label" for="notAsked.forgot" class="disabled">Forgot to ask the patient</label></td>
508          </tr>
509         
510          <tr valign="baseline">
511            <td></td>
512            <td><input id="notAsked.language" type="checkbox" name="reasonIfNotAsked" disabled></td>
513            <td><label id="notAsked.language.label" for="notAsked.language" class="disabled">Language problems</label></td>
514          </tr>
515
516          <tr valign="baseline">
517            <td></td>
518            <td><input id="notAsked.condition" type="checkbox" name="reasonIfNotAsked" disabled></td>
519            <td><label id="notAsked.condition.label" for="notAsked.condition" class="disabled">Patient can't decide due to physical and/or mental condition</label></td>
520          </tr>
521
522          <tr valign="baseline">
523            <td></td>
524            <td><input id="notAsked.other" type="checkbox" name="reasonIfNotAsked" disabled></td>
525            <td><label id="notAsked.other.label" for="notAsked.other" class="disabled">Other:</label></td>
526          </tr>
527
528          <tr valign="baseline">
529            <td></td>
530            <td colspan="2">
531            <textarea name="otherReasonIfNotAsked" rows="3" cols="30" disabled
532              onfocus="document.forms['reggie'].reasonIfNotAsked[3].checked = true"></textarea>
533            </td>
534          </tr>
535          </table>
536
537        </td>
538        <td class="status" id="notAsked.status"></td>
539      </tr>
540      </table>
541    </td>
542  </tr>
543  </table>
544  </div>
545 
546  <div class="messagecontainer error" id="errorMessage" style="display: none; width: 800px; margin-left: 20px; margin-bottom: 0px;"></div>
547
548  <div id="done" class="success" style="display: none; width: 800px; margin-left: 20px; margin-top: 20px;"></div>
549
550  <table style="margin-left: 20px; margin-top: 10px;" class="navigation">
551  <tr>
552    <td><base:button id="gocancel" title="Cancel" onclick="goRestart(false)" style="display: none;"/></td>
553    <td><base:button id="gonext" title="Next" image="<%=home+"/images/gonext.png"%>" onclick="goNext(true)"/></td>
554    <td><base:button id="goregister" title="Register" image="<%=home+"/images/gonext.png"%>" onclick="goRegister()" style="display: none;"/></td>
555    <td><base:button id="gorestart" title="Restart" image="<%=home+"/images/goback.png"%>" onclick="goRestart(true)" style="display: none;"/></td>
556    <td id="gonext.message" class="message"></td>
557  </tr>
558  </table>
559  </form>
560  </div>
561 
562</base:body>
563</base:page>
564<%
565}
566finally
567{
568  if (dc != null) dc.close();
569}
570%>
Note: See TracBrowser for help on using the repository browser.