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

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

References #291: Personal information registration

Implemented first step with input fields for Case name and Personal number. The personal number is validated and when everything seems ok the second step with patient information is displayed. Existing patient information should be verified and for new patients some information needs to be entered. Functions for validating and going to the next step are not yet implemented.

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