internationalization of the date widget, see feature request tracker item 2967294
[openemr.git] / interface / new / new_comprehensive.php
blob9b54030d6ba3de3df215d4cbc8cc0dafb23f41ae
1 <?php
2 // Copyright (C) 2009-2010 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/acl.inc");
11 require_once("$srcdir/options.inc.php");
12 require_once("$srcdir/patient.inc");
14 // Check authorization.
15 $thisauth = acl_check('patients', 'demo');
16 if ($thisauth != 'write' && $thisauth != 'addonly')
17 die("Adding demographics is not authorized.");
19 $CPR = 4; // cells per row
21 $searchcolor = empty($GLOBALS['layout_search_color']) ?
22 '#ffff55' : $GLOBALS['layout_search_color'];
24 $WITH_SEARCH = ($GLOBALS['full_new_patient_form'] === 1 || $GLOBALS['full_new_patient_form'] === 2);
25 $SHORT_FORM = ($GLOBALS['full_new_patient_form'] === 2 || $GLOBALS['full_new_patient_form'] === 3);
27 function getLayoutRes() {
28 global $SHORT_FORM;
29 return sqlStatement("SELECT * FROM layout_options " .
30 "WHERE form_id = 'DEM' AND uor > 0 AND field_id != '' " .
31 ($SHORT_FORM ? "AND edit_options LIKE '%N%' " : "") .
32 "ORDER BY group_name, seq");
35 // Determine layout field search treatment from its data type:
36 // 1 = text field
37 // 2 = select list
38 // 0 = not searchable
40 function getSearchClass($data_type) {
41 switch($data_type) {
42 case 1: // single-selection list
43 case 10: // local provider list
44 case 11: // provider list
45 case 12: // pharmacy list
46 case 13: // squads
47 case 14: // address book list
48 case 26: // single-selection list with add
49 return 2;
50 case 2: // text field
51 case 3: // textarea
52 case 4: // date
53 return 1;
55 return 0;
58 $fres = getLayoutRes();
60 <html>
61 <head>
62 <?php html_header_show(); ?>
64 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
66 <style>
67 body, td, input, select, textarea {
68 font-family: Arial, Helvetica, sans-serif;
69 font-size: 10pt;
72 body {
73 padding: 5pt 5pt 5pt 5pt;
76 div.section {
77 border: solid;
78 border-width: 1px;
79 border-color: #0000ff;
80 margin: 0 0 0 10pt;
81 padding: 5pt;
84 </style>
86 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
88 <script type="text/javascript" src="../../library/dialog.js"></script>
89 <script type="text/javascript" src="../../library/textformat.js"></script>
90 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
91 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
92 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
93 <script type="text/javascript" src="<?php echo $GLOBALS['webroot']; ?>/library/js/jquery.js"></script>
95 <SCRIPT LANGUAGE="JavaScript"><!--
97 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
99 // This may be changed to true by the AJAX search script.
100 var force_submit = false;
102 //code used from http://tech.irt.org/articles/js037/
103 function replace(string,text,by) {
104 // Replaces text with by in string
105 var strLength = string.length, txtLength = text.length;
106 if ((strLength == 0) || (txtLength == 0)) return string;
108 var i = string.indexOf(text);
109 if ((!i) && (text != string.substring(0,txtLength))) return string;
110 if (i == -1) return string;
112 var newstr = string.substring(0,i) + by;
114 if (i+txtLength < strLength)
115 newstr += replace(string.substring(i+txtLength,strLength),text,by);
117 return newstr;
120 function upperFirst(string,text) {
121 return replace(string,text,text.charAt(0).toUpperCase() + text.substring(1,text.length));
124 function checkNum () {
125 var re= new RegExp();
126 re = /^\d*\.?\d*$/;
127 str=document.forms[0].monthly_income.value;
128 if(re.exec(str))
130 }else{
131 alert("Please enter a dollar amount using only numbers and a decimal point.");
135 // This capitalizes the first letter of each word in the passed input
136 // element. It also strips out extraneous spaces.
137 function capitalizeMe(elem) {
138 var a = elem.value.split(' ');
139 var s = '';
140 for(var i = 0; i < a.length; ++i) {
141 if (a[i].length > 0) {
142 if (s.length > 0) s += ' ';
143 s += a[i].charAt(0).toUpperCase() + a[i].substring(1);
146 elem.value = s;
149 function divclick(cb, divid) {
150 var divstyle = document.getElementById(divid).style;
151 if (cb.checked) {
152 divstyle.display = 'block';
153 } else {
154 divstyle.display = 'none';
156 return true;
159 // Compute the length of a string without leading and trailing spaces.
160 function trimlen(s) {
161 var i = 0;
162 var j = s.length - 1;
163 for (; i <= j && s.charAt(i) == ' '; ++i);
164 for (; i <= j && s.charAt(j) == ' '; --j);
165 if (i > j) return 0;
166 return j + 1 - i;
169 function validate(f) {
170 <?php generate_layout_validation('DEM'); ?>
171 return true;
174 function toggleSearch(elem) {
175 var f = document.forms[0];
176 <?php if ($WITH_SEARCH) { ?>
177 // Toggle background color.
178 if (elem.style.backgroundColor == '')
179 elem.style.backgroundColor = '<?php echo $searchcolor; ?>';
180 else
181 elem.style.backgroundColor = '';
182 <?php } ?>
183 if (force_submit) {
184 force_submit = false;
185 f.create.value = '<?php xl('Create New Patient','e'); ?>';
187 return true;
190 // If a <select> list is dropped down, this is its name.
191 var open_sel_name = '';
193 function selClick(elem) {
194 if (open_sel_name == elem.name) {
195 open_sel_name = '';
197 else {
198 open_sel_name = elem.name;
199 toggleSearch(elem);
201 return true;
204 function selBlur(elem) {
205 if (open_sel_name == elem.name) {
206 open_sel_name = '';
208 return true;
211 // This invokes the patient search dialog.
212 function searchme() {
213 var f = document.forms[0];
214 var url = '../main/finder/patient_select.php?popup=1';
216 <?php
217 $lres = getLayoutRes();
219 while ($lrow = sqlFetchArray($lres)) {
220 $field_id = $lrow['field_id'];
221 if (strpos($field_id, 'em_') === 0) continue;
222 $data_type = $lrow['data_type'];
223 $fldname = "form_$field_id";
224 switch(getSearchClass($data_type)) {
225 case 1:
226 echo
227 " if (f.$fldname.style.backgroundColor != '' && trimlen(f.$fldname.value) > 0) {\n" .
228 " url += '&$field_id=' + escape(f.$fldname.value);\n" .
229 " }\n";
230 break;
231 case 2:
232 echo
233 " if (f.$fldname.style.backgroundColor != '' && f.$fldname.selectedIndex > 0) {\n" .
234 " url += '&$field_id=' + escape(f.$fldname.options[f.$fldname.selectedIndex].value);\n" .
235 " }\n";
236 break;
241 dlgopen(url, '_blank', 700, 500);
244 //-->
246 </script>
247 </head>
249 <body class="body_top">
251 <form action='new_comprehensive_save.php' method='post' onsubmit='return validate(this)'>
253 <span class='title'><?php xl('Search or Add Patient','e'); ?></span>
255 <table width='100%' cellpadding='0' cellspacing='8'>
256 <tr>
257 <td align='left' valign='top'>
258 <?php if ($SHORT_FORM) echo " <center>\n"; ?>
259 <?php
261 function end_cell() {
262 global $item_count, $cell_count;
263 if ($item_count > 0) {
264 echo "</td>";
265 $item_count = 0;
269 function end_row() {
270 global $cell_count, $CPR;
271 end_cell();
272 if ($cell_count > 0) {
273 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
274 echo "</tr>\n";
275 $cell_count = 0;
279 function end_group() {
280 global $last_group, $SHORT_FORM;
281 if (strlen($last_group) > 0) {
282 end_row();
283 echo " </table>\n";
284 if (!$SHORT_FORM) echo "</div>\n";
288 $last_group = '';
289 $cell_count = 0;
290 $item_count = 0;
291 $display_style = 'block';
292 $group_seq = 0; // this gives the DIV blocks unique IDs
294 while ($frow = sqlFetchArray($fres)) {
295 $this_group = $frow['group_name'];
296 $titlecols = $frow['titlecols'];
297 $datacols = $frow['datacols'];
298 $data_type = $frow['data_type'];
299 $field_id = $frow['field_id'];
300 $list_id = $frow['list_id'];
301 $currvalue = '';
303 if (strpos($field_id, 'em_') === 0) {
304 $tmp = substr($field_id, 3);
305 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
307 else {
308 if (isset($result[$field_id])) $currvalue = $result[$field_id];
311 // Handle a data category (group) change.
312 if (strcmp($this_group, $last_group) != 0) {
313 if (!$SHORT_FORM) {
314 end_group();
315 $group_seq++; // ID for DIV tags
316 $group_name = substr($this_group, 1);
317 if (strlen($last_group) > 0) echo "<br />";
318 echo "<span class='bold'><input type='checkbox' name='form_cb_$group_seq' id='form_cb_$group_seq' value='1' " .
319 "onclick='return divclick(this,\"div_$group_seq\");'";
320 if ($display_style == 'block') echo " checked";
322 // Modified 6-09 by BM - Translate if applicable
323 echo " /><b>" . xl_layout_label($group_name) . "</b></span>\n";
325 echo "<div id='div_$group_seq' class='section' style='display:$display_style;'>\n";
326 echo " <table border='0' cellpadding='0'>\n";
327 $display_style = 'none';
329 else if (strlen($last_group) == 0) {
330 echo " <table border='0' cellpadding='0'>\n";
332 $last_group = $this_group;
335 // Handle starting of a new row.
336 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
337 end_row();
338 echo " <tr>";
341 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
343 // Handle starting of a new label cell.
344 if ($titlecols > 0) {
345 end_cell();
346 echo "<td colspan='$titlecols'";
347 echo ($frow['uor'] == 2) ? " class='required'" : " class='bold'";
348 if ($cell_count == 2) echo " style='padding-left:10pt'";
349 echo ">";
350 $cell_count += $titlecols;
352 ++$item_count;
354 echo "<b>";
356 // Modified 6-09 by BM - Translate if applicable
357 if ($frow['title']) echo (xl_layout_label($frow['title']).":"); else echo "&nbsp;";
359 echo "</b>";
361 // Handle starting of a new data cell.
362 if ($datacols > 0) {
363 end_cell();
364 echo "<td colspan='$datacols' class='text'";
365 if ($cell_count > 0) echo " style='padding-left:5pt'";
366 echo ">";
367 $cell_count += $datacols;
370 ++$item_count;
371 generate_form_field($frow, $currvalue);
374 end_group();
377 <?php if (!$SHORT_FORM) echo " <center>\n"; ?>
378 <br />
379 <?php if ($WITH_SEARCH) { ?>
380 <input type="button" id="search" value=<?php xl('Search','e','\'','\''); ?>
381 style='background-color:<?php echo $searchcolor; ?>' />
382 &nbsp;&nbsp;
383 <?php } ?>
384 <input type="button" name='create' id="create" value=<?php xl('Create New Patient','e','\'','\''); ?> />
386 </center>
388 </td>
389 <td align='right' valign='top' width='1%' nowrap>
390 <!-- Image upload stuff was here but got moved. -->
391 </td>
392 </tr>
393 </table>
395 </form>
397 <!-- include support for the list-add selectbox feature -->
398 <?php include($GLOBALS['fileroot']."/library/options_listadd.inc"); ?>
400 </body>
402 <script language="JavaScript">
404 // fix inconsistently formatted phone numbers from the database
405 var f = document.forms[0];
406 if (f.form_phone_contact) phonekeyup(f.form_phone_contact,mypcc);
407 if (f.form_phone_home ) phonekeyup(f.form_phone_home ,mypcc);
408 if (f.form_phone_biz ) phonekeyup(f.form_phone_biz ,mypcc);
409 if (f.form_phone_cell ) phonekeyup(f.form_phone_cell ,mypcc);
411 <?php echo $date_init; ?>
413 // -=- jQuery makes life easier -=-
415 // var matches = 0; // number of patients that match the demographic information being entered
416 // var override = false; // flag that overrides the duplication warning
418 $(document).ready(function() {
420 $('#search').click(function() { searchme(); });
421 $('#create').click(function() { submitme(); });
423 var submitme = function() {
424 top.restoreSession();
425 var f = document.forms[0];
427 if (validate(f)) {
428 if (force_submit) {
429 // In this case dups were shown already and Save should just save.
430 f.submit();
431 return;
433 <?php
434 // D in edit_options indicates the field is used in duplication checking.
435 // This constructs a list of the names of those fields.
436 $mflist = "";
437 $mfres = sqlStatement("SELECT * FROM layout_options " .
438 "WHERE form_id = 'DEM' AND uor > 0 AND field_id != '' AND " .
439 "edit_options LIKE '%D%' " .
440 "ORDER BY group_name, seq");
441 while ($mfrow = sqlFetchArray($mfres)) {
442 $field_id = $mfrow['field_id'];
443 if (strpos($field_id, 'em_') === 0) continue;
444 if (!empty($mflist)) $mflist .= ",";
445 $mflist .= "'" . htmlentities($field_id) . "'";
448 // Build and invoke the URL to create the dup-checker dialog.
449 var url = 'new_search_popup.php';
450 var flds = new Array(<?php echo $mflist; ?>);
451 for (var i = 0; i < flds.length; ++i) {
452 var fval = $('#form_' + flds[i]).val();
453 if (fval && fval != '') {
454 url += (i == 0) ? '?' : '&';
455 url += 'mf_' + flds[i] + '=' + escape(fval);
458 dlgopen(url, '_blank', 700, 500);
460 } // end if validate
461 } // end function
463 // Set onclick/onfocus handlers for toggling background color.
464 <?php
465 $lres = getLayoutRes();
466 while ($lrow = sqlFetchArray($lres)) {
467 $field_id = $lrow['field_id'];
468 if (strpos($field_id, 'em_') === 0) continue;
469 switch(getSearchClass($lrow['data_type'])) {
470 case 1:
471 echo " \$('#form_$field_id').click(function() { toggleSearch(this); });\n";
472 break;
473 case 2:
474 echo " \$('#form_$field_id').click(function() { selClick(this); });\n";
475 echo " \$('#form_$field_id').blur(function() { selBlur(this); });\n";
476 break;
481 }); // end document.ready
483 </script>
485 </html>