source: extensions/net.sf.basedb.reggie/trunk/resources/persinfo.jsp @ 1286

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

References #291: Personal information registration

If one is careful it is now possible to register new patients and cases. Error handling is not fully working and may result in corrupted data. Several use cases are still not supported.

File size: 12.2 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<script language="JavaScript">
27
28var currentStep = 1;
29var pnrIsValid = false;
30var caseIsValid = false;
31
32var patientInfo = null;
33var caseInfo = null;
34
35function goNext()
36{
37  if (currentStep == 1)
38  {
39    if (pnrIsValid && caseIsValid) gotoStep2();
40  }
41  else if (currentStep == 2)
42  {
43    gotoStep3();
44  }
45}
46
47function caseNameOnChange()
48{
49  var frm = document.forms['reggie'];
50  var caseName = frm.caseName.value;
51  if (caseName == '')
52  {
53    setInputStatus('case', 'Missing', false);
54    return;
55  }
56  setInputStatus('case', '', true);
57  caseIsValid = true;
58}
59
60function personalNumberOnChange()
61{
62  var frm = document.forms['reggie'];
63  var pnr = frm.personalNumber.value;
64  pnrIsValid = false;
65 
66  if (pnr.length < 12)
67  {
68    setInputStatus('pnr', 'Too short', false);
69    return;
70  }
71 
72  if (!Dates.isDate(pnr.substring(0, 8), 'yyyyMMdd'))
73  {
74    setInputStatus('pnr', 'Not a valid date', false);
75    return;
76  }
77 
78  var sum = 0;
79  var factor = 2;
80  var x = '';
81  for (var i = 2; i < 11; i++)
82  {
83    var digit = parseInt(pnr.substr(i, 1));
84    var tmp = factor * digit;
85    x += '(' + factor + '*' + digit+')';
86    sum += tmp >= 10 ? tmp - 9: tmp;
87    factor = factor == 2 ? 1 : 2;
88  }
89 
90  var control = 10 - (sum % 10);
91  if (control != parseInt(pnr.substr(11, 1)))
92  {
93    setInputStatus('pnr', 'Invalid control digit', false);
94    return;
95  }
96 
97  setInputStatus('pnr', '', true);
98  pnrIsValid = true;
99 
100  if (caseIsValid) gotoStep2();
101}
102
103function gotoStep2()
104{
105  // Check entered case and pnr with AJAX
106  var frm = document.forms['reggie'];
107  frm.caseName.disabled = true;
108  frm.personalNumber.disabled = true;
109  currentStep = 2;
110 
111  var pnr = frm.personalNumber.value;
112  var caseName = frm.caseName.value;
113  var request = Ajax.getXmlHttpRequest();
114  var url = 'PersonalRegistration.servlet?ID=<%=ID%>&cmd=CheckPersonalNumberAndCaseName';
115  url += '&personalNumber=' + pnr;
116  url += '&caseName=' + caseName;
117  request.open("GET", url, false);
118  request.send(null);
119 
120  setInnerHTML('debug', request.responseText);
121 
122  var response = JSON.parse(request.responseText);
123  if (response.status != 'ok')
124  {
125    setFatalError(response.message);
126    return false;
127  }
128 
129  // Get biosource information from the AJAX response
130  patientInfo = response.patientInfo;
131  caseInfo = response.caseInfo;
132 
133  if (!patientInfo.id)
134  {
135    Main.show('newPatientSection');
136    frm.patientCode.value=patientInfo.name;
137    setInnerHTML('new.dateOfBirth', patientInfo.dateOfBirth);
138    setInnerHTML('new.gender', patientInfo.gender);
139    frm.familyName.focus();
140  }
141  else
142  {
143    Main.show('existingPatientSection');
144    setInnerHTML('existing.patientCode', patientInfo.name);
145    setInnerHTML('existing.familyName', patientInfo.familyName);
146    setInnerHTML('existing.allFirstNames', patientInfo.allFirstNames);
147    setInnerHTML('existing.dateOfBirth', patientInfo.dateOfBirth);
148    setInnerHTML('existing.gender', patientInfo.gender);
149   
150  }
151}
152
153function gotoStep3()
154{
155  // Check entered case and pnr with AJAX
156  var frm = document.forms['reggie'];
157  if (frm.familyName)
158  {
159    // Check form
160  }
161 
162  currentStep = 3;
163  if (!patientInfo.id)
164  {
165    frm.patientCode.disabled = true;
166    frm.familyName.disabled = true;
167    frm.allFirstNames.disabled = true;
168    patientInfo.familyName = frm.familyName.value;
169    patientInfo.allFirstNames = frm.allFirstNames.value;
170  }
171 
172  if (!patientInfo.cases || patientInfo.cases.length == 0)
173  {
174    Main.show('newCaseSection'); 
175  }
176 
177  if (!caseInfo.specimen || caseInfo.specimen.length == 0)
178  {
179    Main.show('reasonIfNoSpecimenSection');
180  }
181 
182  Main.hide('gonext');
183  Main.show('gocreate');
184}
185
186function goCreate()
187{
188  var frm = document.forms['reggie'];
189
190  caseInfo.laterality = Forms.getCheckedRadio(frm.laterality).value;
191  caseInfo.reasonIfNoSpecimen = frm.reasonIfNoSpecimen.value;
192 
193  var submitInfo = new Object();
194  submitInfo.patientInfo = patientInfo;
195  submitInfo.caseInfo = caseInfo;
196  alert(JSON.stringify(submitInfo));
197
198  var request = Ajax.getXmlHttpRequest();
199  var url = 'PersonalRegistration.servlet?ID=<%=ID%>&cmd=Create';
200  request.open("POST", url, false);
201  request.setRequestHeader("Content-Type", "application/json");
202  request.send(JSON.stringify(submitInfo));
203
204  setInnerHTML('debug', request.responseText);
205}
206
207
208function setInnerHTML(id, html)
209{
210  var tag = document.getElementById(id);
211  if (!tag) alert('No tag with id='+id);
212  tag.innerHTML = html;
213}
214
215function setInputStatus(prefix, message, isValid)
216{
217  var tag = document.getElementById(prefix + '.status');
218  Main.addClass(tag, isValid ? 'isvalid' : 'invalid');
219  Main.removeClass(tag, isValid ? 'invalid' : 'isvalid');
220 
221  setInnerHTML(prefix + '.message', message);
222}
223
224function setFatalError(message)
225{
226  setInnerHTML('errorMessage', message);
227  Main.show('errorMessage');
228  Main.hide('gonext');
229}
230</script>
231<style>
232
233.stepform
234{
235  border: 1px solid #999999;
236  width: 800px;
237  table-layout: fixed;
238}
239
240.stepno
241{
242  width: 20px;
243  font-size: 20px;
244  font-weight: bold;
245  color: #E0E0E0;
246  background: #555577;
247  vertical-align: top;
248  text-align: center;
249}
250
251.steptitle
252{
253  width: 780px;
254  color: #333377;
255  background: #E0E0E0;
256  font-weight: bold;
257  padding: 1px 4px 1px 4px;
258  border-bottom: 1px solid #999999;
259}
260
261.nextstep
262{
263  width: 780px;
264  color: #333377;
265  background: #E0E0E0;
266  font-weight: bold;
267  padding: 1px 4px 1px 4px;
268  border-top: 1px solid #999999;
269}
270
271.stepfields
272{
273  width: 780px;
274}
275
276.prompt
277{
278  width: 150px;
279  font-weight: bold;
280  padding: 1px 2px 1px 2px;
281}
282
283.input
284{
285  width: 150px;
286  padding: 1px 2px 1px 2px;
287}
288
289.status
290{
291  width: 30px;
292  padding: 1px 2px 1px 2px;
293}
294
295.help
296{
297  background: #e0e0e0;
298  width: 400px;
299  font-style: italic;
300  padding: 1px 2px 1px 2px;
301}
302
303.message
304{
305  color: #cc0000;
306  font-weight: bold;
307  padding-right: 6px;
308}
309
310.status.invalid:before
311{
312  content: url('../../images/error.gif');
313}
314.status.isvalid:before
315{
316  content: url('../../images/ok.gif');
317}
318
319</style>
320</base:head>
321<base:body>
322
323  <p:path>
324    <p:pathelement title="Reggie" href="<%="index.jsp?ID="+ID%>" />
325    <p:pathelement title="Personal information registration" />
326  </p:path>
327
328  <form name="reggie" onsubmit="return false;">
329 
330  <!-- 1. Case + Personal number -->
331  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
332  <tr>
333    <td rowspan="3" class="stepno">1</td>
334    <td class="steptitle">Enter Case Name and Personal Number</td>
335  </tr>
336  <tr>
337    <td class="stepfields">
338      <table border="0" cellspacing="0" cellpadding="0" width="100%">
339      <tr valign="top">
340        <td class="prompt">Case Name</td>
341        <td class="input"><input type="text" name="caseName" 
342          size="15" maxlength="12" onblur="caseNameOnChange()"></td>
343        <td class="status" id="case.status"></td>
344        <td class="help"><span id="case.message" class="message"></span>The case (barcode) associated with this patient.</td>
345      </tr>
346      <tr>
347        <td class="prompt">Personal Number</td>
348        <td class="input"><input type="text" name="personalNumber" 
349          size="15" maxlength="12" onkeyup="personalNumberOnChange()"></td>
350        <td class="status" id="pnr.status"></td>
351        <td class="help"><span id="pnr.message" class="message"></span>(YYYYMMDDZZZZ)</td>
352      </tr>
353      </table>
354    </td>
355  </tr>
356  </table>
357
358  <!-- 2. New patient registration -->
359  <div id="newPatientSection" style="display: none;">
360  <p>
361  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
362  <tr>
363    <td rowspan="2" class="stepno">2</td>
364    <td class="steptitle">New patient: Enter all names</td>
365  </tr>
366  <tr>
367    <td class="stepfields">
368      <table border="0" cellspacing="0" cellpadding="0" width="100%">
369      <tr>
370        <td class="prompt">Patient code</td>
371        <td class="input"><input type="text" name="patientCode" value="" size="12" maxlength="12"></td>
372        <td class="status"></td>
373        <td class="help"></td>
374      </tr>
375      <tr>
376        <td class="prompt">Family name</td>
377        <td class="input"><input type="text" name="familyName" 
378          size="30" maxlength="255"></td>
379        <td class="status"></td>
380        <td class="help">Keep hyphens, keep åäö, replace all special accented letters [e.g. éèü etc] with standard alphabet character.</td>
381      </tr>
382      <tr>
383        <td class="prompt">All first names</td>
384        <td class="input"><input type="text" name="allFirstNames" 
385          size="30" maxlength="255"></td>
386        <td class="status"></td>
387        <td class="help">Type all names, see FamilyName comment on valid characters.</td>
388      </tr>
389      <tr>
390        <td class="prompt">Gender</td>
391        <td class="input" id="new.gender"></td>
392        <td class="status"></td>
393        <td class="help"></td>
394      </tr>
395      <tr>
396        <td class="prompt">Date of birth</td>
397        <td class="input" id="new.dateOfBirth"></td>
398        <td class="status"></td>
399        <td class="help"></td>
400      </tr>
401      </table>
402    </td>
403  </tr>
404  </table>
405  </div>
406 
407  <!-- 2b. Existing patient -->
408  <div id="existingPatientSection" style="display: none;">
409  <p>
410  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
411  <tr>
412    <td rowspan="2" class="stepno">2</td>
413    <td class="steptitle">Existing patient: Verify names</td>
414  </tr>
415  <tr>
416    <td class="stepfields">
417      <table border="0" cellspacing="0" cellpadding="0" width="100%">
418      <tr>
419        <td class="prompt">Patient code</td>
420        <td class="input" id="existing.patientCode"></td>
421        <td class="status"></td>
422        <td class="help"></td>
423      </tr>
424      <tr>
425        <td class="prompt">Family name</td>
426        <td class="input" id="existing.familyName"></td>
427        <td class="status"></td>
428        <td class="help"></td>
429      </tr>
430      <tr>
431        <td class="prompt">All first names</td>
432        <td class="input" id="existing.allFirstNames"></td>
433        <td class="status"></td>
434        <td class="help"></td>
435      </tr>
436      <tr>
437        <td class="prompt">Gender</td>
438        <td class="input" id="existing.gender"></td>
439        <td class="status"></td>
440        <td class="help"></td>
441      </tr>
442      <tr>
443        <td class="prompt">Date of birth</td>
444        <td class="input" id="existing.dateOfBirth"></td>
445        <td class="status"></td>
446        <td class="help"></td>
447      </tr>
448      </table>
449    </td>
450  </tr>
451  </table>
452  </div>
453
454
455  <!-- 3. New case registration -->
456  <div id="newCaseSection" style="display: none;">
457  <p>
458  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
459  <tr>
460    <td rowspan="2" class="stepno">3</td>
461    <td class="steptitle">New case: Enter information</td>
462  </tr>
463  <tr>
464    <td class="stepfields">
465      <table border="0" cellspacing="0" cellpadding="0" width="100%">
466      <tr>
467        <td class="prompt">Laterality</td>
468        <td class="input">
469          <input type="radio" name="laterality" value="LEFT">LEFT
470          <input type="radio" name="laterality" value="RIGHT">RIGHT
471        </td>
472        <td class="status"></td>
473        <td class="help"></td>
474      </tr>
475      <tr id="reasonIfNoSpecimenSection" style="display: none;">
476        <td class="prompt">Reason if no specimen</td>
477        <td class="input"><input type="text" name="reasonIfNoSpecimen" value="" size="30" maxlength="200"></td>
478        <td class="status"></td>
479        <td class="help"></td>
480      </tr>
481      </table>
482    </td>
483  </tr>
484  </table>
485  </div>
486
487  <div class="error" id="errorMessage" style="display: none; width: 800px;">
488  </div>
489
490  <table>
491    <tr><td><base:button id="gonext" title="Next" image="gonext.gif" onclick="goNext()"/></td></tr>
492    <tr><td><base:button id="gocreate" title="Create" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td></tr>
493  </table>
494  </form>
495
496  <pre>
497  <div id="debug"></div>
498  </pre>
499 
500</base:body>
501</base:page>
502<%
503}
504finally
505{
506  if (dc != null) dc.close();
507}
508%>
Note: See TracBrowser for help on using the repository browser.