2 // Copyright (C) 2009-2010 Rod Roark <rod@sunsetsystems.com>
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() {
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:
40 function getSearchClass($data_type) {
42 case 1: // single-selection list
43 case 10: // local provider list
44 case 11: // provider list
45 case 12: // pharmacy list
47 case 14: // address book list
48 case 26: // single-selection list with add
58 $fres = getLayoutRes();
62 <?php
html_header_show(); ?
>
64 <link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
67 body
, td
, input
, select
, textarea
{
68 font
-family
: Arial
, Helvetica
, sans
-serif
;
73 padding
: 5pt
5pt
5pt
5pt
;
79 border
-color
: #0000ff;
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
);
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();
127 str
=document
.forms
[0].monthly_income
.value
;
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(' ');
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);
149 function divclick(cb
, divid
) {
150 var divstyle
= document
.getElementById(divid
).style
;
152 divstyle
.display
= 'block';
154 divstyle
.display
= 'none';
159 // Compute the length of a string without leading and trailing spaces.
160 function trimlen(s
) {
162 var j
= s
.length
- 1;
163 for (; i
<= j
&& s
.charAt(i
) == ' '; ++i
);
164 for (; i
<= j
&& s
.charAt(j
) == ' '; --j
);
169 function validate(f
) {
170 <?php
generate_layout_validation('DEM'); ?
>
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; ?>';
181 elem
.style
.backgroundColor
= '';
184 force_submit
= false;
185 f
.create
.value
= '<?php xl('Create
New Patient
','e
'); ?>';
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
) {
198 open_sel_name
= elem
.name
;
204 function selBlur(elem
) {
205 if (open_sel_name
== elem
.name
) {
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';
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)) {
227 " if (f.$fldname.style.backgroundColor != '' && trimlen(f.$fldname.value) > 0) {\n" .
228 " url += '&$field_id=' + escape(f.$fldname.value);\n" .
233 " if (f.$fldname.style.backgroundColor != '' && f.$fldname.selectedIndex > 0) {\n" .
234 " url += '&$field_id=' + escape(f.$fldname.options[f.$fldname.selectedIndex].value);\n" .
241 dlgopen(url
, '_blank', 700, 500);
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'>
257 <td align
='left' valign
='top'>
258 <?php
if ($SHORT_FORM) echo " <center>\n"; ?
>
261 function end_cell() {
262 global $item_count, $cell_count;
263 if ($item_count > 0) {
270 global $cell_count, $CPR;
272 if ($cell_count > 0) {
273 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
279 function end_group() {
280 global $last_group, $SHORT_FORM;
281 if (strlen($last_group) > 0) {
284 if (!$SHORT_FORM) echo "</div>\n";
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'];
303 if (strpos($field_id, 'em_') === 0) {
304 $tmp = substr($field_id, 3);
305 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
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) {
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) {
341 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
343 // Handle starting of a new label cell.
344 if ($titlecols > 0) {
346 echo "<td colspan='$titlecols'";
347 echo ($frow['uor'] == 2) ?
" class='required'" : " class='bold'";
348 if ($cell_count == 2) echo " style='padding-left:10pt'";
350 $cell_count +
= $titlecols;
356 // Modified 6-09 by BM - Translate if applicable
357 if ($frow['title']) echo (xl_layout_label($frow['title']).":"); else echo " ";
361 // Handle starting of a new data cell.
364 echo "<td colspan='$datacols' class='text'";
365 if ($cell_count > 0) echo " style='padding-left:5pt'";
367 $cell_count +
= $datacols;
371 generate_form_field($frow, $currvalue);
377 <?php
if (!$SHORT_FORM) echo " <center>\n"; ?
>
379 <?php
if ($WITH_SEARCH) { ?
>
380 <input type
="button" id
="search" value
=<?php
xl('Search','e','\'','\''); ?
>
381 style
='background-color:<?php echo $searchcolor; ?>' />
384 <input type
="button" name
='create' id
="create" value
=<?php
xl('Create New Patient','e','\'','\''); ?
> />
389 <td align
='right' valign
='top' width
='1%' nowrap
>
390 <!-- Image upload stuff was here but got moved
. -->
397 <!-- include support
for the
list-add selectbox feature
-->
398 <?php
include($GLOBALS['fileroot']."/library/options_listadd.inc"); ?
>
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];
429 // In this case dups were shown already and Save should just save.
434 // D in edit_options indicates the field is used in duplication checking.
435 // This constructs a list of the names of those fields.
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);
463 // Set onclick/onfocus handlers for toggling background color.
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'])) {
471 echo " \$('#form_$field_id').click(function() { toggleSearch(this); });\n";
474 echo " \$('#form_$field_id').click(function() { selClick(this); });\n";
475 echo " \$('#form_$field_id').blur(function() { selBlur(this); });\n";
481 }); // end document.ready