2 // Copyright (C) 2007-2009 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 // Functions for managing the lists and layouts
11 // Note: there are translation wrappers for the lists and layout labels
12 // at library/translation.inc.php. The functions are titled
13 // xl_list_label() and xl_layout_label() and are controlled by the
14 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
15 // flags in globals.php
17 require_once("formdata.inc.php");
21 function get_pharmacies() {
22 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
23 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
24 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
25 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
27 "ORDER BY name, area_code, prefix, number");
30 function generate_form_field($frow, $currvalue) {
31 global $rootdir, $date_init;
33 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
35 $data_type = $frow['data_type'];
36 $field_id = $frow['field_id'];
37 $list_id = $frow['list_id'];
39 // Added 5-09 by BM - Translate description if applicable
40 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
42 // added 5-2009 by BM to allow modification of the 'empty' text title field.
43 // Can pass $frow['empty_title'] with this variable, otherwise
44 // will default to 'Unassigned'.
45 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
46 // if make $frow['empty_title'] equal to 'SKIP'
48 if (isset($frow['empty_title'])) {
49 if ($frow['empty_title'] == "SKIP") {
50 //do not display an 'empty' choice
52 $empty_title = "Unassigned";
55 $empty_title = $frow['empty_title'];
59 $empty_title = "Unassigned";
62 // generic single-selection list
63 if ($data_type == 1) {
64 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
65 if ($showEmpty) echo "<option value=''>" . xl($empty_title) . "</option>";
66 $lres = sqlStatement("SELECT * FROM list_options " .
67 "WHERE list_id = '$list_id' ORDER BY seq, title");
68 $got_selected = FALSE;
69 while ($lrow = sqlFetchArray($lres)) {
70 echo "<option value='" . $lrow['option_id'] . "'";
71 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
72 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
78 // Added 5-09 by BM - Translate label if applicable
79 echo ">" . xl_list_label($lrow['title']) . "</option>\n";
82 if (!$got_selected && strlen($currvalue) > 0) {
83 echo "<option value='$currescaped' selected>* $currescaped *</option>";
85 echo " <font color='red' title='" . xl('Please choose a valid selection from the list.') . "'>" . xl('Fix this') . "!</font>";
93 else if ($data_type == 2) {
94 echo "<input type='text'" .
95 " name='form_$field_id'" .
96 " id='form_$field_id'" .
97 " size='" . $frow['fld_length'] . "'" .
98 " maxlength='" . $frow['max_length'] . "'" .
99 " title='$description'" .
100 " value='$currescaped'";
101 if (strpos($frow['edit_options'], 'C') !== FALSE)
102 echo " onchange='capitalizeMe(this)'";
106 // long or multi-line text field
107 else if ($data_type == 3) {
109 " name='form_$field_id'" .
110 " id='form_$field_id'" .
111 " title='$description'" .
112 " cols='" . $frow['fld_length'] . "'" .
113 " rows='" . $frow['max_length'] . "'>" .
114 $currescaped . "</textarea>";
118 else if ($data_type == 4) {
119 echo "<input type='text' size='10' name='form_$field_id' id='form_$field_id'" .
120 " value='$currescaped'" .
121 " title='$description'" .
122 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
123 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
124 " id='img_$field_id' border='0' alt='[?]' style='cursor:pointer'" .
125 " title='" . xl('Click here to choose a date') . "' />";
126 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
129 // provider list, local providers only
130 else if ($data_type == 10) {
131 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
132 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
133 "AND authorized = 1 " .
134 "ORDER BY lname, fname");
135 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
136 echo "<option value=''>" . xl('Unassigned') . "</option>";
137 while ($urow = sqlFetchArray($ures)) {
138 $uname = $urow['fname'] . ' ' . $urow['lname'];
139 echo "<option value='" . $urow['id'] . "'";
140 if ($urow['id'] == $currvalue) echo " selected";
141 echo ">$uname</option>";
146 // provider list, including address book entries with an NPI number
147 else if ($data_type == 11) {
148 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
149 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
150 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
151 "ORDER BY lname, fname");
152 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
153 echo "<option value=''>" . xl('Unassigned') . "</option>";
154 while ($urow = sqlFetchArray($ures)) {
155 $uname = $urow['fname'] . ' ' . $urow['lname'];
156 echo "<option value='" . $urow['id'] . "'";
157 if ($urow['id'] == $currvalue) echo " selected";
158 echo ">$uname</option>";
164 else if ($data_type == 12) {
165 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
166 echo "<option value='0'></option>";
167 $pres = get_pharmacies();
168 while ($prow = sqlFetchArray($pres)) {
170 echo "<option value='$key'";
171 if ($currvalue == $key) echo " selected";
172 echo '>' . $prow['name'] . ' ' . $prow['area_code'] . '-' .
173 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
174 $prow['line1'] . ' / ' . $prow['city'] . "</option>";
180 else if ($data_type == 13) {
181 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
182 echo "<option value=''> </option>";
183 $squads = acl_get_squads();
185 foreach ($squads as $key => $value) {
186 echo "<option value='$key'";
187 if ($currvalue == $key) echo " selected";
188 echo ">" . $value[3] . "</option>\n";
194 // Address book, preferring organization name if it exists and is not in
195 // parentheses, and excluding local users who are not providers.
196 // Supports "referred to" practitioners and facilities.
197 else if ($data_type == 14) {
198 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
199 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
200 "AND ( username = '' OR authorized = 1 ) " .
201 "ORDER BY organization, lname, fname");
202 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
203 echo "<option value=''>" . xl('Unassigned') . "</option>";
204 while ($urow = sqlFetchArray($ures)) {
205 $uname = $urow['organization'];
206 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
207 $uname = $urow['lname'];
208 if ($urow['fname']) $uname .= ", " . $urow['fname'];
210 echo "<option value='" . $urow['id'] . "'";
211 $title = $urow['username'] ?
xl('Local') : xl('External');
212 echo " title='$title'";
213 if ($urow['id'] == $currvalue) echo " selected";
214 echo ">$uname</option>";
219 // a billing code (only one of these allowed!)
220 else if ($data_type == 15) {
221 echo "<input type='text'" .
222 " name='form_$field_id'" .
223 " id='form_related_code'" .
224 " size='" . $frow['fld_length'] . "'" .
225 " maxlength='" . $frow['max_length'] . "'" .
226 " title='$description'" .
227 " value='$currescaped'" .
228 " onclick='sel_related()' readonly" .
232 // a set of labeled checkboxes
233 else if ($data_type == 21) {
234 // In this special case, fld_length is the number of columns generated.
235 $cols = max(1, $frow['fld_length']);
236 $avalue = explode('|', $currvalue);
237 $lres = sqlStatement("SELECT * FROM list_options " .
238 "WHERE list_id = '$list_id' ORDER BY seq, title");
239 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
240 $tdpct = (int) (100 / $cols);
241 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
242 $option_id = $lrow['option_id'];
243 // if ($count) echo "<br />";
244 if ($count %
$cols == 0) {
245 if ($count) echo "</tr>";
248 echo "<td width='$tdpct%'>";
249 echo "<input type='checkbox' name='form_{$field_id}[$option_id]' id='form_{$field_id}[$option_id]' value='1'";
250 if (in_array($option_id, $avalue)) echo " checked";
252 // Added 5-09 by BM - Translate label if applicable
253 echo ">" . xl_list_label($lrow['title']);
259 if ($count > $cols) {
260 // Add some space after multiple rows of checkboxes.
261 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
267 // a set of labeled text input fields
268 else if ($data_type == 22) {
269 $tmp = explode('|', $currvalue);
271 foreach ($tmp as $value) {
272 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
273 $avalue[$matches[1]] = $matches[2];
276 $lres = sqlStatement("SELECT * FROM list_options " .
277 "WHERE list_id = '$list_id' ORDER BY seq, title");
278 echo "<table cellpadding='0' cellspacing='0'>";
279 while ($lrow = sqlFetchArray($lres)) {
280 $option_id = $lrow['option_id'];
281 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
282 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
284 // Added 5-09 by BM - Translate label if applicable
285 echo "<tr><td>" . xl_list_label($lrow['title']) . " </td>";
287 echo "<td><input type='text'" .
288 " name='form_{$field_id}[$option_id]'" .
289 " id='form_{$field_id}[$option_id]'" .
290 " size='$fldlength'" .
291 " maxlength='$maxlength'" .
292 " value='" . $avalue[$option_id] . "'";
293 echo " /></td></tr>";
298 // a set of exam results; 3 radio buttons and a text field:
299 else if ($data_type == 23) {
300 $tmp = explode('|', $currvalue);
302 foreach ($tmp as $value) {
303 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
304 $avalue[$matches[1]] = $matches[2];
307 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
308 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
309 $lres = sqlStatement("SELECT * FROM list_options " .
310 "WHERE list_id = '$list_id' ORDER BY seq, title");
311 echo "<table cellpadding='0' cellspacing='0'>";
312 echo "<tr><td> </td><td class='bold'>" . xl('N/A') .
313 " </td><td class='bold'>" . xl('Nor') . " </td>" .
314 "<td class='bold'>" . xl('Abn') . " </td><td class='bold'>" .
315 xl('Date/Notes') . "</td></tr>";
316 while ($lrow = sqlFetchArray($lres)) {
317 $option_id = $lrow['option_id'];
318 $restype = substr($avalue[$option_id], 0, 1);
319 $resnote = substr($avalue[$option_id], 2);
321 // Added 5-09 by BM - Translate label if applicable
322 echo "<tr><td>" . xl_list_label($lrow['title']) . " </td>";
324 for ($i = 0; $i < 3; ++
$i) {
325 echo "<td><input type='radio'" .
326 " name='radio_{$field_id}[$option_id]'" .
327 " id='radio_{$field_id}[$option_id]'" .
329 if ($restype === "$i") echo " checked";
332 echo "<td><input type='text'" .
333 " name='form_{$field_id}[$option_id]'" .
334 " id='form_{$field_id}[$option_id]'" .
335 " size='$fldlength'" .
336 " maxlength='$maxlength'" .
337 " value='$resnote' /></td>";
343 // the list of active allergies for the current patient
344 // this is read-only!
345 else if ($data_type == 24) {
346 $query = "SELECT title, comments FROM lists WHERE " .
347 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
349 // echo "<!-- $query -->\n"; // debugging
350 $lres = sqlStatement($query);
352 while ($lrow = sqlFetchArray($lres)) {
353 if ($count++
) echo "<br />";
355 if ($lrow['comments']) echo ' (' . $lrow['comments'] . ')';
359 // a set of labeled checkboxes, each with a text field:
360 else if ($data_type == 25) {
361 $tmp = explode('|', $currvalue);
363 foreach ($tmp as $value) {
364 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
365 $avalue[$matches[1]] = $matches[2];
368 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
369 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
370 $lres = sqlStatement("SELECT * FROM list_options " .
371 "WHERE list_id = '$list_id' ORDER BY seq, title");
372 echo "<table cellpadding='0' cellspacing='0'>";
373 while ($lrow = sqlFetchArray($lres)) {
374 $option_id = $lrow['option_id'];
375 $restype = substr($avalue[$option_id], 0, 1);
376 $resnote = substr($avalue[$option_id], 2);
378 // Added 5-09 by BM - Translate label if applicable
379 echo "<tr><td>" . xl_list_label($lrow['title']) . " </td>";
381 echo "<td><input type='checkbox' name='check_{$field_id}[$option_id]' id='check_{$field_id}[$option_id]' value='1'";
382 if ($restype) echo " checked";
383 echo " /> </td>";
384 echo "<td><input type='text'" .
385 " name='form_{$field_id}[$option_id]'" .
386 " id='form_{$field_id}[$option_id]'" .
387 " size='$fldlength'" .
388 " maxlength='$maxlength'" .
389 " value='$resnote' /></td>";
395 // single-selection list with ability to add to it
396 else if ($data_type == 26) {
397 echo "<select class='addtolistclass_$list_id' name='form_$field_id' id='form_$field_id' title='$description'>";
398 if ($showEmpty) echo "<option value=''>" . xl($empty_title) . "</option>";
399 $lres = sqlStatement("SELECT * FROM list_options " .
400 "WHERE list_id = '$list_id' ORDER BY seq, title");
401 $got_selected = FALSE;
402 while ($lrow = sqlFetchArray($lres)) {
403 echo "<option value='" . $lrow['option_id'] . "'";
404 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
405 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
408 $got_selected = TRUE;
411 // Added 5-09 by BM - Translate label if applicable
412 echo ">" . xl_list_label($lrow['title']) . "</option>\n";
415 if (!$got_selected && strlen($currvalue) > 0) {
416 echo "<option value='$currescaped' selected>* $currescaped *</option>";
418 echo " <font color='red' title='" . xl('Please choose a valid selection from the list.') . "'>" . xl('Fix this') . "!</font>";
424 // show the add button if user has access to correct list
425 $outputAddButton = "<input type='button' id='addtolistid_".$list_id."' fieldid='form_".$field_id."' class='addtolist' value='" . xl('Add') . "'>";
426 if (aco_exist('lists', $list_id)) {
427 // a specific aco exist for this list, so ensure access
428 if (acl_check('lists', $list_id)) echo $outputAddButton;
431 // no specific aco exist for this list, so check for access to 'default' list
432 if (acl_check('lists', 'default')) echo $outputAddButton;
438 function generate_print_field($frow, $currvalue) {
439 global $rootdir, $date_init;
441 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
443 $data_type = $frow['data_type'];
444 $field_id = $frow['field_id'];
445 $list_id = $frow['list_id'];
446 $fld_length = $frow['fld_length'];
448 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
450 // Can pass $frow['empty_title'] with this variable, otherwise
451 // will default to 'Unassigned'.
452 // If it is 'SKIP' then an empty text title is completely skipped.
454 if (isset($frow['empty_title'])) {
455 if ($frow['empty_title'] == "SKIP") {
456 //do not display an 'empty' choice
458 $empty_title = "Unassigned";
461 $empty_title = $frow['empty_title'];
465 $empty_title = "Unassigned";
468 // generic single-selection list
469 if ($data_type == 1 ||
$data_type == 26) {
470 if (empty($fld_length)) {
471 if ($list_id == 'titles') {
479 $lrow = sqlQuery("SELECT title FROM list_options " .
480 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
481 $tmp = xl_list_label($lrow['title']);
482 if (empty($tmp)) $tmp = "($currvalue)";
484 /*****************************************************************
485 echo "<input type='text'" .
486 " size='$fld_length'" .
490 *****************************************************************/
491 if ($tmp === '') $tmp = ' ';
496 else if ($data_type == 2 ||
$data_type == 15) {
497 /*****************************************************************
498 echo "<input type='text'" .
499 " size='$fld_length'" .
500 " value='$currescaped'" .
503 *****************************************************************/
504 if ($currescaped === '') $currescaped = ' ';
508 // long or multi-line text field
509 else if ($data_type == 3) {
511 " cols='$fld_length'" .
512 " rows='" . $frow['max_length'] . "'>" .
513 $currescaped . "</textarea>";
517 else if ($data_type == 4) {
518 /*****************************************************************
519 echo "<input type='text' size='10'" .
520 " value='$currescaped'" .
521 " title='$description'" .
524 *****************************************************************/
525 if ($currescaped === '') $currescaped = ' ';
530 else if ($data_type == 10 ||
$data_type == 11) {
533 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
534 "WHERE id = '$currvalue'");
535 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
536 if (empty($tmp)) $tmp = "($currvalue)";
538 /*****************************************************************
539 echo "<input type='text'" .
540 " size='$fld_length'" .
544 *****************************************************************/
545 if ($tmp === '') $tmp = ' ';
550 else if ($data_type == 12) {
553 $pres = get_pharmacies();
554 while ($prow = sqlFetchArray($pres)) {
556 if ($currvalue == $key) {
557 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
558 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
559 $prow['line1'] . ' / ' . $prow['city'];
562 if (empty($tmp)) $tmp = "($currvalue)";
564 /*****************************************************************
565 echo "<input type='text'" .
566 " size='$fld_length'" .
570 *****************************************************************/
571 if ($tmp === '') $tmp = ' ';
576 else if ($data_type == 13) {
579 $squads = acl_get_squads();
581 foreach ($squads as $key => $value) {
582 if ($currvalue == $key) {
587 if (empty($tmp)) $tmp = "($currvalue)";
589 /*****************************************************************
590 echo "<input type='text'" .
591 " size='$fld_length'" .
595 *****************************************************************/
596 if ($tmp === '') $tmp = ' ';
601 else if ($data_type == 14) {
604 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
605 "WHERE id = '$currvalue'");
606 $uname = $urow['lname'];
607 if ($urow['fname']) $uname .= ", " . $urow['fname'];
609 if (empty($tmp)) $tmp = "($currvalue)";
611 /*****************************************************************
612 echo "<input type='text'" .
613 " size='$fld_length'" .
617 *****************************************************************/
618 if ($tmp === '') $tmp = ' ';
622 // a set of labeled checkboxes
623 else if ($data_type == 21) {
624 // In this special case, fld_length is the number of columns generated.
625 $cols = max(1, $fld_length);
626 $avalue = explode('|', $currvalue);
627 $lres = sqlStatement("SELECT * FROM list_options " .
628 "WHERE list_id = '$list_id' ORDER BY seq, title");
629 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
630 $tdpct = (int) (100 / $cols);
631 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
632 $option_id = $lrow['option_id'];
633 if ($count %
$cols == 0) {
634 if ($count) echo "</tr>";
637 echo "<td width='$tdpct%'>";
638 echo "<input type='checkbox'";
639 if (in_array($option_id, $avalue)) echo " checked";
640 echo ">" . xl_list_label($lrow['title']);
645 if ($count > $cols) {
646 // Add some space after multiple rows of checkboxes.
647 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
653 // a set of labeled text input fields
654 else if ($data_type == 22) {
655 $tmp = explode('|', $currvalue);
657 foreach ($tmp as $value) {
658 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
659 $avalue[$matches[1]] = $matches[2];
662 $lres = sqlStatement("SELECT * FROM list_options " .
663 "WHERE list_id = '$list_id' ORDER BY seq, title");
664 echo "<table cellpadding='0' cellspacing='0'>";
665 while ($lrow = sqlFetchArray($lres)) {
666 $option_id = $lrow['option_id'];
667 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
668 $fldlength = empty($fld_length) ?
20 : $fld_length;
669 echo "<tr><td>" . xl_list_label($lrow['title']) . " </td>";
670 echo "<td><input type='text'" .
671 " size='$fldlength'" .
672 " value='" . $avalue[$option_id] . "'" .
679 // a set of exam results; 3 radio buttons and a text field:
680 else if ($data_type == 23) {
681 $tmp = explode('|', $currvalue);
683 foreach ($tmp as $value) {
684 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
685 $avalue[$matches[1]] = $matches[2];
688 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
689 $fldlength = empty($fld_length) ?
20 : $fld_length;
690 $lres = sqlStatement("SELECT * FROM list_options " .
691 "WHERE list_id = '$list_id' ORDER BY seq, title");
692 echo "<table cellpadding='0' cellspacing='0'>";
693 echo "<tr><td> </td><td class='bold'>" . xl('N/A') .
694 " </td><td class='bold'>" . xl('Nor') . " </td>" .
695 "<td class='bold'>" . xl('Abn') . " </td><td class='bold'>" .
696 xl('Date/Notes') . "</td></tr>";
697 while ($lrow = sqlFetchArray($lres)) {
698 $option_id = $lrow['option_id'];
699 $restype = substr($avalue[$option_id], 0, 1);
700 $resnote = substr($avalue[$option_id], 2);
701 echo "<tr><td>" . xl_list_label($lrow['title']) . " </td>";
702 for ($i = 0; $i < 3; ++
$i) {
703 echo "<td><input type='radio'";
704 if ($restype === "$i") echo " checked";
707 echo "<td><input type='text'" .
708 " size='$fldlength'" .
709 " value='$resnote'" .
710 " class='under' /></td>" .
716 // the list of active allergies for the current patient
717 // this is read-only!
718 else if ($data_type == 24) {
719 $query = "SELECT title, comments FROM lists WHERE " .
720 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
722 $lres = sqlStatement($query);
724 while ($lrow = sqlFetchArray($lres)) {
725 if ($count++
) echo "<br />";
727 if ($lrow['comments']) echo ' (' . $lrow['comments'] . ')';
731 // a set of labeled checkboxes, each with a text field:
732 else if ($data_type == 25) {
733 $tmp = explode('|', $currvalue);
735 foreach ($tmp as $value) {
736 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
737 $avalue[$matches[1]] = $matches[2];
740 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
741 $fldlength = empty($fld_length) ?
20 : $fld_length;
742 $lres = sqlStatement("SELECT * FROM list_options " .
743 "WHERE list_id = '$list_id' ORDER BY seq, title");
744 echo "<table cellpadding='0' cellspacing='0'>";
745 while ($lrow = sqlFetchArray($lres)) {
746 $option_id = $lrow['option_id'];
747 $restype = substr($avalue[$option_id], 0, 1);
748 $resnote = substr($avalue[$option_id], 2);
749 echo "<tr><td>" . xl_list_label($lrow['title']) . " </td>";
750 echo "<td><input type='checkbox'";
751 if ($restype) echo " checked";
752 echo " /> </td>";
753 echo "<td><input type='text'" .
754 " size='$fldlength'" .
755 " value='$resnote'" .
765 function generate_display_field($frow, $currvalue) {
766 $data_type = $frow['data_type'];
767 $field_id = $frow['field_id'];
768 $list_id = $frow['list_id'];
771 // generic selection list or the generic selection list with add on the fly feature
772 if ($data_type == 1 ||
$data_type == 26) {
773 $lrow = sqlQuery("SELECT title FROM list_options " .
774 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
776 // Added 5-09 by BM - Translate label if applicable
777 $s = xl_list_label($lrow['title']);
782 else if ($data_type == 2) {
786 // long or multi-line text field
787 else if ($data_type == 3) {
788 $s = nl2br($currvalue);
792 else if ($data_type == 4) {
797 else if ($data_type == 10 ||
$data_type == 11) {
798 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
799 "WHERE id = '$currvalue'");
800 $s = ucwords($urow['fname'] . " " . $urow['lname']);
804 else if ($data_type == 12) {
805 $pres = get_pharmacies();
806 while ($prow = sqlFetchArray($pres)) {
808 if ($currvalue == $key) {
809 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
810 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
811 $prow['line1'] . ' / ' . $prow['city'];
817 else if ($data_type == 13) {
818 $squads = acl_get_squads();
820 foreach ($squads as $key => $value) {
821 if ($currvalue == $key) {
829 else if ($data_type == 14) {
830 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
831 "WHERE id = '$currvalue'");
832 $uname = $urow['lname'];
833 if ($urow['fname']) $uname .= ", " . $urow['fname'];
838 else if ($data_type == 15) {
842 // a set of labeled checkboxes
843 else if ($data_type == 21) {
844 $avalue = explode('|', $currvalue);
845 $lres = sqlStatement("SELECT * FROM list_options " .
846 "WHERE list_id = '$list_id' ORDER BY seq, title");
848 while ($lrow = sqlFetchArray($lres)) {
849 $option_id = $lrow['option_id'];
850 if (in_array($option_id, $avalue)) {
851 if ($count++
) $s .= "<br />";
853 // Added 5-09 by BM - Translate label if applicable
854 $s .= xl_list_label($lrow['title']);
860 // a set of labeled text input fields
861 else if ($data_type == 22) {
862 $tmp = explode('|', $currvalue);
864 foreach ($tmp as $value) {
865 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
866 $avalue[$matches[1]] = $matches[2];
869 $lres = sqlStatement("SELECT * FROM list_options " .
870 "WHERE list_id = '$list_id' ORDER BY seq, title");
871 $s .= "<table cellpadding='0' cellspacing='0'>";
872 while ($lrow = sqlFetchArray($lres)) {
873 $option_id = $lrow['option_id'];
874 if (empty($avalue[$option_id])) continue;
876 // Added 5-09 by BM - Translate label if applicable
877 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . ": </td>";
879 $s .= "<td class='text' valign='top'>" . $avalue[$option_id] . "</td></tr>";
884 // a set of exam results; 3 radio buttons and a text field:
885 else if ($data_type == 23) {
886 $tmp = explode('|', $currvalue);
888 foreach ($tmp as $value) {
889 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
890 $avalue[$matches[1]] = $matches[2];
893 $lres = sqlStatement("SELECT * FROM list_options " .
894 "WHERE list_id = '$list_id' ORDER BY seq, title");
895 $s .= "<table cellpadding='0' cellspacing='0'>";
896 while ($lrow = sqlFetchArray($lres)) {
897 $option_id = $lrow['option_id'];
898 $restype = substr($avalue[$option_id], 0, 1);
899 $resnote = substr($avalue[$option_id], 2);
900 if (empty($restype) && empty($resnote)) continue;
902 // Added 5-09 by BM - Translate label if applicable
903 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . " </td>";
905 $restype = ($restype == '1') ?
xl('Normal') : (($restype == '2') ?
xl('Abnormal') : xl('N/A'));
906 $s .= "<td class='text' valign='top'>$restype</td></tr>";
907 $s .= "<td class='text' valign='top'>$resnote</td></tr>";
913 // the list of active allergies for the current patient
914 else if ($data_type == 24) {
915 $query = "SELECT title, comments FROM lists WHERE " .
916 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
918 // echo "<!-- $query -->\n"; // debugging
919 $lres = sqlStatement($query);
921 while ($lrow = sqlFetchArray($lres)) {
922 if ($count++
) $s .= "<br />";
923 $s .= $lrow['title'];
924 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
928 // a set of labeled checkboxes, each with a text field:
929 else if ($data_type == 25) {
930 $tmp = explode('|', $currvalue);
932 foreach ($tmp as $value) {
933 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
934 $avalue[$matches[1]] = $matches[2];
937 $lres = sqlStatement("SELECT * FROM list_options " .
938 "WHERE list_id = '$list_id' ORDER BY seq, title");
939 $s .= "<table cellpadding='0' cellspacing='0'>";
940 while ($lrow = sqlFetchArray($lres)) {
941 $option_id = $lrow['option_id'];
942 $restype = substr($avalue[$option_id], 0, 1);
943 $resnote = substr($avalue[$option_id], 2);
944 if (empty($restype) && empty($resnote)) continue;
946 // Added 5-09 by BM - Translate label if applicable
947 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . " </td>";
949 $restype = $restype ?
xl('Yes') : xl('No');
950 $s .= "<td class='text' valign='top'>$restype</td></tr>";
951 $s .= "<td class='text' valign='top'>$resnote</td></tr>";
960 $CPR = 4; // cells per row of generic data
965 function disp_end_cell() {
966 global $item_count, $cell_count;
967 if ($item_count > 0) {
973 function disp_end_row() {
974 global $cell_count, $CPR;
976 if ($cell_count > 0) {
977 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
983 function disp_end_group() {
985 if (strlen($last_group) > 0) {
990 function display_layout_rows($formtype, $result1, $result2='') {
991 global $item_count, $cell_count, $last_group, $CPR;
993 $fres = sqlStatement("SELECT * FROM layout_options " .
994 "WHERE form_id = '$formtype' AND uor > 0 " .
995 "ORDER BY group_name, seq");
997 while ($frow = sqlFetchArray($fres)) {
998 $this_group = $frow['group_name'];
999 $titlecols = $frow['titlecols'];
1000 $datacols = $frow['datacols'];
1001 $data_type = $frow['data_type'];
1002 $field_id = $frow['field_id'];
1003 $list_id = $frow['list_id'];
1006 if ($formtype == 'DEM') {
1007 if ($GLOBALS['athletic_team']) {
1008 // Skip fitness level and return-to-play date because those appear
1009 // in a special display/update form on this page.
1010 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1012 if (strpos($field_id, 'em_') === 0) {
1013 // Skip employer related fields, if it's disabled.
1014 if ($GLOBALS['omit_employers']) continue;
1015 $tmp = substr($field_id, 3);
1016 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1019 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1023 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1026 // Handle a data category (group) change.
1027 if (strcmp($this_group, $last_group) != 0) {
1028 $group_name = substr($this_group, 1);
1029 // totally skip generating the employer category, if it's disabled.
1030 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1032 $last_group = $this_group;
1035 // Handle starting of a new row.
1036 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1040 echo "<td class='groupname'>";
1041 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1042 //echo "<font color='#008800'>$group_name</font>";
1044 // Added 5-09 by BM - Translate label if applicable
1045 echo (xl_layout_label($group_name));
1049 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1055 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1057 // Handle starting of a new label cell.
1058 if ($titlecols > 0) {
1060 //echo "<td class='label' colspan='$titlecols' valign='top'";
1061 echo "<td class='label' colspan='$titlecols' ";
1062 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1064 $cell_count +
= $titlecols;
1068 // Added 5-09 by BM - Translate label if applicable
1069 if ($frow['title']) echo (xl_layout_label($frow['title']).":"); else echo " ";
1071 // Handle starting of a new data cell.
1072 if ($datacols > 0) {
1074 //echo "<td class='text data' colspan='$datacols' valign='top'";
1075 echo "<td class='text data' colspan='$datacols'";
1076 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1078 $cell_count +
= $datacols;
1082 echo generate_display_field($frow, $currvalue);
1088 // From the currently posted HTML form, this gets the value of the
1089 // field corresponding to the provided layout_options table row.
1091 function get_layout_form_value($frow) {
1092 $data_type = $frow['data_type'];
1093 $field_id = $frow['field_id'];
1095 if (isset($_POST["form_$field_id"])) {
1096 if ($data_type == 21) {
1097 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1098 // must be concatenated into a |-separated string.
1099 foreach ($_POST["form_$field_id"] as $key => $val) {
1100 if (strlen($value)) $value .= '|';
1104 else if ($data_type == 22) {
1105 // $_POST["form_$field_id"] is an array of text fields to be imploded
1106 // into "key:value|key:value|...".
1107 foreach ($_POST["form_$field_id"] as $key => $val) {
1108 $val = str_replace('|', ' ', $val);
1109 if (strlen($value)) $value .= '|';
1110 $value .= "$key:$val";
1113 else if ($data_type == 23) {
1114 // $_POST["form_$field_id"] is an array of text fields with companion
1115 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1116 foreach ($_POST["form_$field_id"] as $key => $val) {
1117 $restype = $_POST["radio_{$field_id}"][$key];
1118 if (empty($restype)) $restype = '0';
1119 $val = str_replace('|', ' ', $val);
1120 if (strlen($value)) $value .= '|';
1121 $value .= "$key:$restype:$val";
1124 else if ($data_type == 25) {
1125 // $_POST["form_$field_id"] is an array of text fields with companion
1126 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1127 foreach ($_POST["form_$field_id"] as $key => $val) {
1128 $restype = empty($_POST["check_{$field_id}"][$key]) ?
'0' : '1';
1129 $val = str_replace('|', ' ', $val);
1130 if (strlen($value)) $value .= '|';
1131 $value .= "$key:$restype:$val";
1135 $value = $_POST["form_$field_id"];
1139 // Make sure the return value is quote-safe.
1140 return formTrim($value);
1143 // Generate JavaScript validation logic for the required fields.
1145 function generate_layout_validation($form_id) {
1146 $fres = sqlStatement("SELECT * FROM layout_options " .
1147 "WHERE form_id = '$form_id' AND uor > 0 AND field_id != '' " .
1148 "ORDER BY group_name, seq");
1150 while ($frow = sqlFetchArray($fres)) {
1151 if ($frow['uor'] < 2) continue;
1152 $data_type = $frow['data_type'];
1153 $field_id = $frow['field_id'];
1154 $fldtitle = $frow['title'];
1155 if (!$fldtitle) $fldtitle = $frow['description'];
1156 $fldname = "form_$field_id";
1157 switch($data_type) {
1164 " if (f.$fldname.selectedIndex <= 0) {\n" .
1165 " alert('" . xl('Please choose a value for','','',' ') .
1166 xl_layout_label($fldtitle) . "');\n" .
1167 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1168 " return false;\n" .
1176 " if (trimlen(f.$fldname.value) == 0) {\n" .
1177 " alert('" . xl('Please choose a value for','','',' ') .
1178 xl_layout_label($fldtitle) . "');\n" .
1179 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1180 " return false;\n" .