Support for the CMS Patient Portal.
[openemr.git] / library / options.inc.php
blob52f7e520155b8a523ab5de8dc1f52119d7e62817
1 <?php
2 // Copyright (C) 2007-2013 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 // Documentation for layout_options.edit_options:
21 // C = Capitalize first letter of each word (text fields)
22 // D = Check for duplicates in New Patient form
23 // G = Graphable (for numeric fields in forms supporting historical data)
24 // H = Read-only field copied from static history
25 // L = Lab Order ("ord_lab") types only (address book)
26 // N = Show in New Patient form
27 // O = Procedure Order ("ord_*") types only (address book)
28 // R = Distributor types only (address book)
29 // T = Use description as default Text
30 // U = Capitalize all letters (text fields)
31 // V = Vendor types only (address book)
32 // 1 = Write Once (not editable when not empty) (text fields)
34 require_once("formdata.inc.php");
35 require_once("formatting.inc.php");
36 require_once("user.inc");
37 require_once("patient.inc");
38 require_once("lists.inc");
40 $date_init = "";
42 function get_pharmacies() {
43 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
44 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
45 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
46 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
47 "AND p.type = 2 " .
48 "ORDER BY name, area_code, prefix, number");
51 // Function to generate a drop-list.
53 function generate_select_list($tag_name, $list_id, $currvalue, $title, $empty_name = ' ', $class = '',
54 $onchange = '', $tag_id = '', $custom_attributes = null, $multiple = false, $backup_list = '') {
55 $s = '';
57 $tag_name_esc = attr($tag_name);
59 if ($multiple) {
60 $tag_name_esc = $tag_name_esc . "[]";
62 $s .= "<select name='$tag_name_esc'";
64 if ($multiple) {
65 $s .= " multiple='multiple'";
68 $tag_id_esc = $tag_name_esc;
69 if ($tag_id != '') {
70 $tag_id_esc = attr($tag_id);
73 if ($multiple) {
74 $tag_id_esc = $tag_id_esc . "[]";
76 $s .= " id='$tag_id_esc'";
78 if ($class) {
79 $class_esc = attr($class);
80 $s .= " class='$class_esc'";
82 if ($onchange) {
83 $s .= " onchange='$onchange'";
85 if ($custom_attributes != null && is_array ( $custom_attributes )) {
86 foreach ( $custom_attributes as $attr => $val ) {
87 if (isset ( $custom_attributes [$attr] )) {
88 $s .= " " . attr($attr) . "='" . attr($val) . "'";
92 $selectTitle = attr($title);
93 $s .= " title='$selectTitle'>";
94 $selectEmptyName = xlt($empty_name);
95 if ($empty_name)
96 $s .= "<option value=''>" . $selectEmptyName . "</option>";
97 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? ORDER BY seq, title", array($list_id));
98 $got_selected = FALSE;
100 while ( $lrow = sqlFetchArray ( $lres ) ) {
101 $selectedValues = explode ( "|", $currvalue );
103 $optionValue = attr($lrow ['option_id']);
104 $s .= "<option value='$optionValue'";
106 if ($multiple && (strlen ( $currvalue ) == 0 && $lrow ['is_default']) || (strlen ( $currvalue ) > 0 && in_array ( $lrow ['option_id'], $selectedValues ))) {
107 $s .= " selected";
108 $got_selected = TRUE;
111 $optionLabel = text(xl_list_label($lrow ['title']));
112 $s .= ">$optionLabel</option>\n";
115 if (!$got_selected && strlen ( $currvalue ) > 0 && !$multiple) {
116 $list_id = $backup_list;
117 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
119 if ($lrow > 0 && !empty($backup_list)) {
120 $selected = text(xl_list_label($lrow ['title']));
121 $s .= "<option value='$currescaped' selected> $selected </option>";
122 $s .= "</select>";
123 } else {
124 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
125 $s .= "</select>";
126 $fontTitle = xlt('Please choose a valid selection from the list.');
127 $fontText = xlt( 'Fix this' );
128 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
131 } else if (!$got_selected && strlen ( $currvalue ) > 0 && $multiple) {
132 //if not found in main list, display all selected values that exist in backup list
133 $list_id = $backup_list;
135 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? ORDER BY seq, title", array($list_id));
137 $got_selected_backup = FALSE;
138 if (!empty($backup_list)) {
139 while ( $lrow_backup = sqlFetchArray ( $lres_backup ) ) {
140 $selectedValues = explode ( "|", $currvalue );
142 $optionValue = attr($lrow ['option_id']);
144 if ($multiple && (strlen ( $currvalue ) == 0 && $lrow_backup ['is_default']) ||
145 (strlen ( $currvalue ) > 0 && in_array ( $lrow_backup ['option_id'], $selectedValues ))) {
146 $s .= "<option value='$optionValue'";
147 $s .= " selected";
148 $optionLabel = text(xl_list_label($lrow_backup ['title']));
149 $s .= ">$optionLabel</option>\n";
150 $got_selected_backup = TRUE;
154 if (!$got_selected_backup) {
155 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
156 $s .= "</select>";
157 $fontTitle = xlt('Please choose a valid selection from the list.');
158 $fontText = xlt( 'Fix this' );
159 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
163 else {
164 $s .= "</select>";
166 return $s;
170 // $frow is a row from the layout_options table.
171 // $currvalue is the current value, if any, of the associated item.
173 function generate_form_field($frow, $currvalue) {
174 global $rootdir, $date_init, $ISSUE_TYPES;
176 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
178 $data_type = $frow['data_type'];
179 $field_id = $frow['field_id'];
180 $list_id = $frow['list_id'];
181 $backup_list = $frow['list_backup_id'];
183 // escaped variables to use in html
184 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
185 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
187 // Added 5-09 by BM - Translate description if applicable
188 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
190 // Support edit option T which assigns the (possibly very long) description as
191 // the default value.
192 if (strpos($frow['edit_options'], 'T') !== FALSE) {
193 if (strlen($currescaped) == 0) $currescaped = $description;
194 // Description used in this way is not suitable as a title.
195 $description = '';
198 // added 5-2009 by BM to allow modification of the 'empty' text title field.
199 // Can pass $frow['empty_title'] with this variable, otherwise
200 // will default to 'Unassigned'.
201 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
202 // if make $frow['empty_title'] equal to 'SKIP'
203 $showEmpty = true;
204 if (isset($frow['empty_title'])) {
205 if ($frow['empty_title'] == "SKIP") {
206 //do not display an 'empty' choice
207 $showEmpty = false;
208 $empty_title = "Unassigned";
210 else {
211 $empty_title = $frow['empty_title'];
214 else {
215 $empty_title = "Unassigned";
218 // generic single-selection list or Race and Ethnicity.
219 // These data types support backup lists.
220 if ($data_type == 1 || $data_type == 33) {
221 echo generate_select_list("form_$field_id", $list_id, $currvalue,
222 $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, false, $backup_list);
225 // simple text field
226 else if ($data_type == 2) {
227 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
228 $maxlength = $frow['max_length'];
229 $string_maxlength = "";
230 // if max_length is set to zero, then do not set a maxlength
231 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
232 echo "<input type='text'" .
233 " name='form_$field_id_esc'" .
234 " id='form_$field_id_esc'" .
235 " size='$fldlength'" .
236 " $string_maxlength" .
237 " title='$description'" .
238 " value='$currescaped'";
239 if (strpos($frow['edit_options'], 'C') !== FALSE)
240 echo " onchange='capitalizeMe(this)'";
241 else if (strpos($frow['edit_options'], 'U') !== FALSE)
242 echo " onchange='this.value = this.value.toUpperCase()'";
243 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
244 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
245 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
246 echo " onblur='maskblur(this,\"$tmp\")'";
248 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0)
249 echo " readonly";
250 echo " />";
253 // long or multi-line text field
254 else if ($data_type == 3) {
255 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
256 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
257 echo "<textarea" .
258 " name='form_$field_id_esc'" .
259 " id='form_$field_id_esc'" .
260 " title='$description'" .
261 " cols='$textCols'" .
262 " rows='$textRows'>" .
263 $currescaped . "</textarea>";
266 // date
267 else if ($data_type == 4) {
268 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
269 " value='$currescaped'" .
270 " title='$description'" .
271 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
272 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
273 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
274 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
275 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
278 // provider list, local providers only
279 else if ($data_type == 10) {
280 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
281 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
282 "AND authorized = 1 " .
283 "ORDER BY lname, fname");
284 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
285 echo "<option value=''>" . xlt($empty_title) . "</option>";
286 $got_selected = false;
287 while ($urow = sqlFetchArray($ures)) {
288 $uname = text($urow['fname'] . ' ' . $urow['lname']);
289 $optionId = attr($urow['id']);
290 echo "<option value='$optionId'";
291 if ($urow['id'] == $currvalue) {
292 echo " selected";
293 $got_selected = true;
295 echo ">$uname</option>";
297 if (!$got_selected && strlen($currvalue) > 0) {
298 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
299 echo "</select>";
300 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
302 else {
303 echo "</select>";
307 // provider list, including address book entries with an NPI number
308 else if ($data_type == 11) {
309 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
310 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
311 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
312 "ORDER BY lname, fname");
313 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
314 echo "<option value=''>" . xlt('Unassigned') . "</option>";
315 $got_selected = false;
316 while ($urow = sqlFetchArray($ures)) {
317 $uname = text($urow['fname'] . ' ' . $urow['lname']);
318 $optionId = attr($urow['id']);
319 echo "<option value='$optionId'";
320 if ($urow['id'] == $currvalue) {
321 echo " selected";
322 $got_selected = true;
324 echo ">$uname</option>";
326 if (!$got_selected && strlen($currvalue) > 0) {
327 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
328 echo "</select>";
329 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
331 else {
332 echo "</select>";
336 // pharmacy list
337 else if ($data_type == 12) {
338 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
339 echo "<option value='0'></option>";
340 $pres = get_pharmacies();
341 $got_selected = false;
342 while ($prow = sqlFetchArray($pres)) {
343 $key = $prow['id'];
344 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
345 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
346 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
347 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
348 echo "<option value='$optionValue'";
349 if ($currvalue == $key) {
350 echo " selected";
351 $got_selected = true;
353 echo ">$optionLabel</option>";
355 if (!$got_selected && strlen($currvalue) > 0) {
356 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
357 echo "</select>";
358 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
360 else {
361 echo "</select>";
365 // squads
366 else if ($data_type == 13) {
367 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
368 echo "<option value=''>&nbsp;</option>";
369 $squads = acl_get_squads();
370 if ($squads) {
371 foreach ($squads as $key => $value) {
372 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
373 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
374 echo "<option value='$optionValue'";
375 if ($currvalue == $key) echo " selected";
376 echo ">$optionLabel</option>\n";
379 echo "</select>";
382 // Address book, preferring organization name if it exists and is not in
383 // parentheses, and excluding local users who are not providers.
384 // Supports "referred to" practitioners and facilities.
385 // Alternatively the letter L in edit_options means that abook_type
386 // must be "ord_lab", indicating types used with the procedure
387 // lab ordering system.
388 // Alternatively the letter O in edit_options means that abook_type
389 // must begin with "ord_", indicating types used with the procedure
390 // ordering system.
391 // Alternatively the letter V in edit_options means that abook_type
392 // must be "vendor", indicating the Vendor type.
393 // Alternatively the letter R in edit_options means that abook_type
394 // must be "dist", indicating the Distributor type.
395 else if ($data_type == 14) {
396 if (strpos($frow['edit_options'], 'L') !== FALSE)
397 $tmp = "abook_type = 'ord_lab'";
398 else if (strpos($frow['edit_options'], 'O') !== FALSE)
399 $tmp = "abook_type LIKE 'ord\\_%'";
400 else if (strpos($frow['edit_options'], 'V') !== FALSE)
401 $tmp = "abook_type LIKE 'vendor%'";
402 else if (strpos($frow['edit_options'], 'R') !== FALSE)
403 $tmp = "abook_type LIKE 'dist'";
404 else
405 $tmp = "( username = '' OR authorized = 1 )";
406 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
407 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
408 "AND $tmp " .
409 "ORDER BY organization, lname, fname");
410 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
411 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
412 while ($urow = sqlFetchArray($ures)) {
413 $uname = $urow['organization'];
414 if (empty($uname) || substr($uname, 0, 1) == '(') {
415 $uname = $urow['lname'];
416 if ($urow['fname']) $uname .= ", " . $urow['fname'];
418 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
419 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
420 echo "<option value='$optionValue'";
421 $title = $urow['username'] ? xl('Local') : xl('External');
422 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
423 echo " title='$optionTitle'";
424 if ($urow['id'] == $currvalue) echo " selected";
425 echo ">$optionLabel</option>";
427 echo "</select>";
430 // a billing code
431 else if ($data_type == 15) {
432 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
433 $maxlength = $frow['max_length'];
434 $string_maxlength = "";
435 // if max_length is set to zero, then do not set a maxlength
436 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
437 echo "<input type='text'" .
438 " name='form_$field_id_esc'" .
439 " id='form_related_code'" .
440 " size='$fldlength'" .
441 " $string_maxlength" .
442 " title='$description'" .
443 " value='$currescaped'" .
444 " onclick='sel_related(this)' readonly" .
445 " />";
448 // insurance company list
449 else if ($data_type == 16) {
450 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
451 echo "<option value='0'></option>";
452 $insprovs = getInsuranceProviders();
453 $got_selected = false;
454 foreach ($insprovs as $key => $ipname) {
455 $optionValue = htmlspecialchars($key, ENT_QUOTES);
456 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
457 echo "<option value='$optionValue'";
458 if ($currvalue == $key) {
459 echo " selected";
460 $got_selected = true;
462 echo ">$optionLabel</option>";
464 if (!$got_selected && strlen($currvalue) > 0) {
465 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
466 echo "</select>";
467 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
469 else {
470 echo "</select>";
474 // issue types
475 else if ($data_type == 17) {
476 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
477 echo "<option value='0'></option>";
478 $got_selected = false;
479 foreach ($ISSUE_TYPES as $key => $value) {
480 $optionValue = htmlspecialchars($key, ENT_QUOTES);
481 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
482 echo "<option value='$optionValue'";
483 if ($currvalue == $key) {
484 echo " selected";
485 $got_selected = true;
487 echo ">$optionLabel</option>";
489 if (!$got_selected && strlen($currvalue) > 0) {
490 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
491 echo "</select>";
492 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
494 else {
495 echo "</select>";
499 // a set of labeled checkboxes
500 else if ($data_type == 21) {
501 // In this special case, fld_length is the number of columns generated.
502 $cols = max(1, $frow['fld_length']);
503 $avalue = explode('|', $currvalue);
504 $lres = sqlStatement("SELECT * FROM list_options " .
505 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
506 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
507 $tdpct = (int) (100 / $cols);
508 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
509 $option_id = $lrow['option_id'];
510 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
511 // if ($count) echo "<br />";
512 if ($count % $cols == 0) {
513 if ($count) echo "</tr>";
514 echo "<tr>";
516 echo "<td width='$tdpct%'>";
517 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
518 if (in_array($option_id, $avalue)) echo " checked";
520 // Added 5-09 by BM - Translate label if applicable
521 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
523 echo "</td>";
525 if ($count) {
526 echo "</tr>";
527 if ($count > $cols) {
528 // Add some space after multiple rows of checkboxes.
529 $cols = htmlspecialchars( $cols, ENT_QUOTES);
530 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
533 echo "</table>";
536 // a set of labeled text input fields
537 else if ($data_type == 22) {
538 $tmp = explode('|', $currvalue);
539 $avalue = array();
540 foreach ($tmp as $value) {
541 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
542 $avalue[$matches[1]] = $matches[2];
545 $lres = sqlStatement("SELECT * FROM list_options " .
546 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
547 echo "<table cellpadding='0' cellspacing='0'>";
548 while ($lrow = sqlFetchArray($lres)) {
549 $option_id = $lrow['option_id'];
550 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
551 $maxlength = $frow['max_length'];
552 $string_maxlength = "";
553 // if max_length is set to zero, then do not set a maxlength
554 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
555 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
557 // Added 5-09 by BM - Translate label if applicable
558 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
559 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
560 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
561 echo "<td><input type='text'" .
562 " name='form_{$field_id_esc}[$option_id_esc]'" .
563 " id='form_{$field_id_esc}[$option_id_esc]'" .
564 " size='$fldlength'" .
565 " $string_maxlength" .
566 " value='$optionValue'";
567 echo " /></td></tr>";
569 echo "</table>";
572 // a set of exam results; 3 radio buttons and a text field:
573 else if ($data_type == 23) {
574 $tmp = explode('|', $currvalue);
575 $avalue = array();
576 foreach ($tmp as $value) {
577 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
578 $avalue[$matches[1]] = $matches[2];
581 $maxlength = $frow['max_length'];
582 $string_maxlength = "";
583 // if max_length is set to zero, then do not set a maxlength
584 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
585 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
586 $lres = sqlStatement("SELECT * FROM list_options " .
587 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
588 echo "<table cellpadding='0' cellspacing='0'>";
589 echo "<tr><td>&nbsp;</td><td class='bold'>" .
590 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
591 "&nbsp;</td><td class='bold'>" .
592 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
593 "<td class='bold'>" .
594 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
595 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
596 while ($lrow = sqlFetchArray($lres)) {
597 $option_id = $lrow['option_id'];
598 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
599 $restype = substr($avalue[$option_id], 0, 1);
600 $resnote = substr($avalue[$option_id], 2);
602 // Added 5-09 by BM - Translate label if applicable
603 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
605 for ($i = 0; $i < 3; ++$i) {
606 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
607 echo "<td><input type='radio'" .
608 " name='radio_{$field_id_esc}[$option_id_esc]'" .
609 " id='radio_{$field_id_esc}[$option_id_esc]'" .
610 " value='$inputValue'";
611 if ($restype === "$i") echo " checked";
612 echo " /></td>";
614 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
615 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
616 echo "<td><input type='text'" .
617 " name='form_{$field_id_esc}[$option_id_esc]'" .
618 " id='form_{$field_id_esc}[$option_id_esc]'" .
619 " size='$fldlength'" .
620 " $string_maxlength" .
621 " value='$resnote' /></td>";
622 echo "</tr>";
624 echo "</table>";
627 // the list of active allergies for the current patient
628 // this is read-only!
629 else if ($data_type == 24) {
630 $query = "SELECT title, comments FROM lists WHERE " .
631 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
632 "ORDER BY begdate";
633 // echo "<!-- $query -->\n"; // debugging
634 $lres = sqlStatement($query, array($GLOBALS['pid']));
635 $count = 0;
636 while ($lrow = sqlFetchArray($lres)) {
637 if ($count++) echo "<br />";
638 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
639 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
643 // a set of labeled checkboxes, each with a text field:
644 else if ($data_type == 25) {
645 $tmp = explode('|', $currvalue);
646 $avalue = array();
647 foreach ($tmp as $value) {
648 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
649 $avalue[$matches[1]] = $matches[2];
652 $maxlength = $frow['max_length'];
653 $string_maxlength = "";
654 // if max_length is set to zero, then do not set a maxlength
655 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
656 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
657 $lres = sqlStatement("SELECT * FROM list_options " .
658 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
659 echo "<table cellpadding='0' cellspacing='0'>";
660 while ($lrow = sqlFetchArray($lres)) {
661 $option_id = $lrow['option_id'];
662 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
663 $restype = substr($avalue[$option_id], 0, 1);
664 $resnote = substr($avalue[$option_id], 2);
666 // Added 5-09 by BM - Translate label if applicable
667 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
669 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
670 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
671 if ($restype) echo " checked";
672 echo " />&nbsp;</td>";
673 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
674 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
675 echo "<td><input type='text'" .
676 " name='form_{$field_id_esc}[$option_id_esc]'" .
677 " id='form_{$field_id_esc}[$option_id_esc]'" .
678 " size='$fldlength'" .
679 " $string_maxlength" .
680 " value='$resnote' /></td>";
681 echo "</tr>";
683 echo "</table>";
686 // single-selection list with ability to add to it
687 else if ($data_type == 26) {
688 echo generate_select_list("form_$field_id", $list_id, $currvalue,
689 $description, $showEmpty ? $empty_title : '', 'addtolistclass_'.$list_id, $onchange, '', null, false, $backup_list);
691 // show the add button if user has access to correct list
692 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
693 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
694 if (aco_exist('lists', $list_id)) {
695 // a specific aco exist for this list, so ensure access
696 if (acl_check('lists', $list_id)) echo $outputAddButton;
698 else {
699 // no specific aco exist for this list, so check for access to 'default' list
700 if (acl_check('lists', 'default')) echo $outputAddButton;
704 // a set of labeled radio buttons
705 else if ($data_type == 27) {
706 // In this special case, fld_length is the number of columns generated.
707 $cols = max(1, $frow['fld_length']);
708 $lres = sqlStatement("SELECT * FROM list_options " .
709 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
710 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
711 $tdpct = (int) (100 / $cols);
712 $got_selected = FALSE;
713 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
714 $option_id = $lrow['option_id'];
715 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
716 if ($count % $cols == 0) {
717 if ($count) echo "</tr>";
718 echo "<tr>";
720 echo "<td width='$tdpct%'>";
721 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
722 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
723 (strlen($currvalue) > 0 && $option_id == $currvalue))
725 echo " checked";
726 $got_selected = TRUE;
728 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
729 echo "</td>";
731 if ($count) {
732 echo "</tr>";
733 if ($count > $cols) {
734 // Add some space after multiple rows of radio buttons.
735 $cols = htmlspecialchars( $cols, ENT_QUOTES);
736 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
739 echo "</table>";
740 if (!$got_selected && strlen($currvalue) > 0) {
741 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
742 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
743 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
747 // special case for history of lifestyle status; 3 radio buttons and a date text field:
748 // VicarePlus :: A selection list box for smoking status:
749 else if ($data_type == 28 || $data_type == 32) {
750 $tmp = explode('|', $currvalue);
751 switch(count($tmp)) {
752 case "4": {
753 $resnote = $tmp[0];
754 $restype = $tmp[1];
755 $resdate = $tmp[2];
756 $reslist = $tmp[3];
757 } break;
758 case "3": {
759 $resnote = $tmp[0];
760 $restype = $tmp[1];
761 $resdate = $tmp[2];
762 } break;
763 case "2": {
764 $resnote = $tmp[0];
765 $restype = $tmp[1];
766 $resdate = "";
767 } break;
768 case "1": {
769 $resnote = $tmp[0];
770 $resdate = $restype = "";
771 } break;
772 default: {
773 $restype = $resdate = $resnote = "";
774 } break;
776 $maxlength = $frow['max_length'];
777 $string_maxlength = "";
778 // if max_length is set to zero, then do not set a maxlength
779 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
780 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
782 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
783 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
784 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
785 echo "<table cellpadding='0' cellspacing='0'>";
786 echo "<tr>";
787 if ($data_type == 28)
789 // input text
790 echo "<td><input type='text'" .
791 " name='form_$field_id_esc'" .
792 " id='form_$field_id_esc'" .
793 " size='$fldlength'" .
794 " $string_maxlength" .
795 " value='$resnote' />&nbsp;</td>";
796 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
797 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
798 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
800 else if($data_type == 32)
802 // input text
803 echo "<tr><td><input type='text'" .
804 " name='form_text_$field_id_esc'" .
805 " id='form_text_$field_id_esc'" .
806 " size='$fldlength'" .
807 " $string_maxlength" .
808 " value='$resnote' />&nbsp;</td></tr>";
809 echo "<td>";
810 //Selection list for smoking status
811 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
812 echo generate_select_list("form_$field_id", $list_id, $reslist,
813 $description, $showEmpty ? $empty_title : '', '', $onchange)."</td>";
814 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
816 // current
817 echo "<td><input type='radio'" .
818 " name='radio_{$field_id_esc}'" .
819 " id='radio_{$field_id_esc}[current]'" .
820 " value='current".$field_id_esc."'";
821 if ($restype == "current".$field_id) echo " checked";
822 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
823 // quit
824 echo "<td><input type='radio'" .
825 " name='radio_{$field_id_esc}'" .
826 " id='radio_{$field_id_esc}[quit]'" .
827 " value='quit".$field_id_esc."'";
828 if ($restype == "quit".$field_id) echo " checked";
829 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
830 // quit date
831 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
832 " value='$resdate'" .
833 " title='$description'" .
834 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
835 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
836 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
837 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />&nbsp;</td>";
838 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
839 // never
840 echo "<td><input type='radio'" .
841 " name='radio_{$field_id_esc}'" .
842 " id='radio_{$field_id_esc}[never]'" .
843 " value='never".$field_id_esc."'";
844 if ($restype == "never".$field_id) echo " checked";
845 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."&nbsp;</td>";
846 // Not Applicable
847 echo "<td><input type='radio'" .
848 " name='radio_{$field_id}'" .
849 " id='radio_{$field_id}[not_applicable]'" .
850 " value='not_applicable".$field_id."'";
851 if ($restype == "not_applicable".$field_id) echo " checked";
852 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('N/A'), ENT_QUOTES)."&nbsp;</td>";
853 echo "</tr>";
854 echo "</table>";
857 // static text. read-only, of course.
858 else if ($data_type == 31) {
859 echo nl2br($frow['description']);
862 //$data_type == 33
863 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
864 //$data_type == 33
866 else if($data_type == 34){
867 $arr = explode("|*|*|*|",$currvalue);
868 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc,ENT_QUOTES)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
869 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
870 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'>".$currvalue."</textarea></div>";
871 echo "</a>";
874 //facilities drop-down list
875 else if ($data_type == 35) {
876 if (empty($currvalue)){
877 $currvalue = 0;
879 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
882 //multiple select
883 // supports backup list
884 else if ($data_type == 36) {
885 echo generate_select_list("form_$field_id", $list_id, $currvalue,
886 $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);
891 function generate_print_field($frow, $currvalue) {
892 global $rootdir, $date_init, $ISSUE_TYPES;
894 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
896 $data_type = $frow['data_type'];
897 $field_id = $frow['field_id'];
898 $list_id = $frow['list_id'];
899 $fld_length = $frow['fld_length'];
900 $backup_list = $frow['list_backup_id'];
902 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
904 // Can pass $frow['empty_title'] with this variable, otherwise
905 // will default to 'Unassigned'.
906 // If it is 'SKIP' then an empty text title is completely skipped.
907 $showEmpty = true;
908 if (isset($frow['empty_title'])) {
909 if ($frow['empty_title'] == "SKIP") {
910 //do not display an 'empty' choice
911 $showEmpty = false;
912 $empty_title = "Unassigned";
914 else {
915 $empty_title = $frow['empty_title'];
918 else {
919 $empty_title = "Unassigned";
922 // generic single-selection list
923 // Supports backup lists.
924 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
925 if (empty($fld_length)) {
926 if ($list_id == 'titles') {
927 $fld_length = 3;
928 } else {
929 $fld_length = 10;
932 $tmp = '';
933 if ($currvalue) {
934 $lrow = sqlQuery("SELECT title FROM list_options " .
935 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
936 $tmp = xl_list_label($lrow['title']);
937 if ($lrow == 0 && !empty($backup_list)) {
938 // since primary list did not map, try to map to backup list
939 $lrow = sqlQuery("SELECT title FROM list_options " .
940 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
941 $tmp = xl_list_label($lrow['title']);
943 if (empty($tmp)) $tmp = "($currvalue)";
945 /*****************************************************************
946 echo "<input type='text'" .
947 " size='$fld_length'" .
948 " value='$tmp'" .
949 " class='under'" .
950 " />";
951 *****************************************************************/
952 if ($tmp === '') {
953 $tmp = '&nbsp;';
955 else {
956 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
958 echo $tmp;
961 // simple text field
962 else if ($data_type == 2 || $data_type == 15) {
963 /*****************************************************************
964 echo "<input type='text'" .
965 " size='$fld_length'" .
966 " value='$currescaped'" .
967 " class='under'" .
968 " />";
969 *****************************************************************/
970 if ($currescaped === '') $currescaped = '&nbsp;';
971 echo $currescaped;
974 // long or multi-line text field
975 else if ($data_type == 3) {
976 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
977 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
978 echo "<textarea" .
979 " cols='$fldlength'" .
980 " rows='$maxlength'>" .
981 $currescaped . "</textarea>";
984 // date
985 else if ($data_type == 4) {
986 /*****************************************************************
987 echo "<input type='text' size='10'" .
988 " value='$currescaped'" .
989 " title='$description'" .
990 " class='under'" .
991 " />";
992 *****************************************************************/
993 if ($currvalue === '') { $tmp = oeFormatShortDate('&nbsp;'); }
994 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES); }
995 echo $tmp;
998 // provider list
999 else if ($data_type == 10 || $data_type == 11) {
1000 $tmp = '';
1001 if ($currvalue) {
1002 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1003 "WHERE id = ?", array($currvalue) );
1004 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1005 if (empty($tmp)) $tmp = "($currvalue)";
1007 /*****************************************************************
1008 echo "<input type='text'" .
1009 " size='$fld_length'" .
1010 " value='$tmp'" .
1011 " class='under'" .
1012 " />";
1013 *****************************************************************/
1014 if ($tmp === '') { $tmp = '&nbsp;'; }
1015 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1016 echo $tmp;
1019 // pharmacy list
1020 else if ($data_type == 12) {
1021 $tmp = '';
1022 if ($currvalue) {
1023 $pres = get_pharmacies();
1024 while ($prow = sqlFetchArray($pres)) {
1025 $key = $prow['id'];
1026 if ($currvalue == $key) {
1027 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1028 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1029 $prow['line1'] . ' / ' . $prow['city'];
1032 if (empty($tmp)) $tmp = "($currvalue)";
1034 /*****************************************************************
1035 echo "<input type='text'" .
1036 " size='$fld_length'" .
1037 " value='$tmp'" .
1038 " class='under'" .
1039 " />";
1040 *****************************************************************/
1041 if ($tmp === '') { $tmp = '&nbsp;'; }
1042 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1043 echo $tmp;
1046 // squads
1047 else if ($data_type == 13) {
1048 $tmp = '';
1049 if ($currvalue) {
1050 $squads = acl_get_squads();
1051 if ($squads) {
1052 foreach ($squads as $key => $value) {
1053 if ($currvalue == $key) {
1054 $tmp = $value[3];
1058 if (empty($tmp)) $tmp = "($currvalue)";
1060 /*****************************************************************
1061 echo "<input type='text'" .
1062 " size='$fld_length'" .
1063 " value='$tmp'" .
1064 " class='under'" .
1065 " />";
1066 *****************************************************************/
1067 if ($tmp === '') { $tmp = '&nbsp;'; }
1068 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1069 echo $tmp;
1072 // Address book.
1073 else if ($data_type == 14) {
1074 $tmp = '';
1075 if ($currvalue) {
1076 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1077 "WHERE id = ?", array($currvalue) );
1078 $uname = $urow['lname'];
1079 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1080 $tmp = $uname;
1081 if (empty($tmp)) $tmp = "($currvalue)";
1083 /*****************************************************************
1084 echo "<input type='text'" .
1085 " size='$fld_length'" .
1086 " value='$tmp'" .
1087 " class='under'" .
1088 " />";
1089 *****************************************************************/
1090 if ($tmp === '') { $tmp = '&nbsp;'; }
1091 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1092 echo $tmp;
1095 // insurance company list
1096 else if ($data_type == 16) {
1097 $tmp = '';
1098 if ($currvalue) {
1099 $insprovs = getInsuranceProviders();
1100 foreach ($insprovs as $key => $ipname) {
1101 if ($currvalue == $key) {
1102 $tmp = $ipname;
1105 if (empty($tmp)) $tmp = "($currvalue)";
1107 if ($tmp === '') $tmp = '&nbsp;';
1108 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1109 echo $tmp;
1112 // issue types
1113 else if ($data_type == 17) {
1114 $tmp = '';
1115 if ($currvalue) {
1116 foreach ($ISSUE_TYPES as $key => $value) {
1117 if ($currvalue == $key) {
1118 $tmp = $value[1];
1121 if (empty($tmp)) $tmp = "($currvalue)";
1123 if ($tmp === '') $tmp = '&nbsp;';
1124 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1125 echo $tmp;
1128 // a set of labeled checkboxes
1129 else if ($data_type == 21) {
1130 // In this special case, fld_length is the number of columns generated.
1131 $cols = max(1, $fld_length);
1132 $avalue = explode('|', $currvalue);
1133 $lres = sqlStatement("SELECT * FROM list_options " .
1134 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1135 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1136 $tdpct = (int) (100 / $cols);
1137 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1138 $option_id = $lrow['option_id'];
1139 if ($count % $cols == 0) {
1140 if ($count) echo "</tr>";
1141 echo "<tr>";
1143 echo "<td width='$tdpct%'>";
1144 echo "<input type='checkbox'";
1145 if (in_array($option_id, $avalue)) echo " checked";
1146 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1147 echo "</td>";
1149 if ($count) {
1150 echo "</tr>";
1151 if ($count > $cols) {
1152 // Add some space after multiple rows of checkboxes.
1153 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1154 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1157 echo "</table>";
1160 // a set of labeled text input fields
1161 else if ($data_type == 22) {
1162 $tmp = explode('|', $currvalue);
1163 $avalue = array();
1164 foreach ($tmp as $value) {
1165 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1166 $avalue[$matches[1]] = $matches[2];
1169 $lres = sqlStatement("SELECT * FROM list_options " .
1170 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1171 echo "<table cellpadding='0' cellspacing='0'>";
1172 while ($lrow = sqlFetchArray($lres)) {
1173 $option_id = $lrow['option_id'];
1174 $fldlength = empty($fld_length) ? 20 : $fld_length;
1175 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1176 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1177 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1178 echo "<td><input type='text'" .
1179 " size='$fldlength'" .
1180 " value='$inputValue'" .
1181 " class='under'" .
1182 " /></td></tr>";
1184 echo "</table>";
1187 // a set of exam results; 3 radio buttons and a text field:
1188 else if ($data_type == 23) {
1189 $tmp = explode('|', $currvalue);
1190 $avalue = array();
1191 foreach ($tmp as $value) {
1192 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1193 $avalue[$matches[1]] = $matches[2];
1196 $fldlength = empty($fld_length) ? 20 : $fld_length;
1197 $lres = sqlStatement("SELECT * FROM list_options " .
1198 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1199 echo "<table cellpadding='0' cellspacing='0'>";
1200 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1201 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1202 "&nbsp;</td><td class='bold'>" .
1203 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1204 "<td class='bold'>" .
1205 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1206 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1207 while ($lrow = sqlFetchArray($lres)) {
1208 $option_id = $lrow['option_id'];
1209 $restype = substr($avalue[$option_id], 0, 1);
1210 $resnote = substr($avalue[$option_id], 2);
1211 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1212 for ($i = 0; $i < 3; ++$i) {
1213 echo "<td><input type='radio'";
1214 if ($restype === "$i") echo " checked";
1215 echo " /></td>";
1217 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1218 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1219 echo "<td><input type='text'" .
1220 " size='$fldlength'" .
1221 " value='$resnote'" .
1222 " class='under' /></td>" .
1223 "</tr>";
1225 echo "</table>";
1228 // the list of active allergies for the current patient
1229 // this is read-only!
1230 else if ($data_type == 24) {
1231 $query = "SELECT title, comments FROM lists WHERE " .
1232 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1233 "ORDER BY begdate";
1234 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1235 $count = 0;
1236 while ($lrow = sqlFetchArray($lres)) {
1237 if ($count++) echo "<br />";
1238 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1239 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1243 // a set of labeled checkboxes, each with a text field:
1244 else if ($data_type == 25) {
1245 $tmp = explode('|', $currvalue);
1246 $avalue = array();
1247 foreach ($tmp as $value) {
1248 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1249 $avalue[$matches[1]] = $matches[2];
1252 $fldlength = empty($fld_length) ? 20 : $fld_length;
1253 $lres = sqlStatement("SELECT * FROM list_options " .
1254 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1255 echo "<table cellpadding='0' cellspacing='0'>";
1256 while ($lrow = sqlFetchArray($lres)) {
1257 $option_id = $lrow['option_id'];
1258 $restype = substr($avalue[$option_id], 0, 1);
1259 $resnote = substr($avalue[$option_id], 2);
1260 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1261 echo "<td><input type='checkbox'";
1262 if ($restype) echo " checked";
1263 echo " />&nbsp;</td>";
1264 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1265 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1266 echo "<td><input type='text'" .
1267 " size='$fldlength'" .
1268 " value='$resnote'" .
1269 " class='under'" .
1270 " /></td>" .
1271 "</tr>";
1273 echo "</table>";
1276 // a set of labeled radio buttons
1277 else if ($data_type == 27) {
1278 // In this special case, fld_length is the number of columns generated.
1279 $cols = max(1, $frow['fld_length']);
1280 $lres = sqlStatement("SELECT * FROM list_options " .
1281 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1282 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1283 $tdpct = (int) (100 / $cols);
1284 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1285 $option_id = $lrow['option_id'];
1286 if ($count % $cols == 0) {
1287 if ($count) echo "</tr>";
1288 echo "<tr>";
1290 echo "<td width='$tdpct%'>";
1291 echo "<input type='radio'";
1292 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1293 (strlen($currvalue) > 0 && $option_id == $currvalue))
1295 echo " checked";
1297 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1298 echo "</td>";
1300 if ($count) {
1301 echo "</tr>";
1302 if ($count > $cols) {
1303 // Add some space after multiple rows of radio buttons.
1304 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1305 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1308 echo "</table>";
1311 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1312 else if ($data_type == 28 || $data_type == 32) {
1313 $tmp = explode('|', $currvalue);
1314 switch(count($tmp)) {
1315 case "4": {
1316 $resnote = $tmp[0];
1317 $restype = $tmp[1];
1318 $resdate = $tmp[2];
1319 $reslist = $tmp[3];
1320 } break;
1321 case "3": {
1322 $resnote = $tmp[0];
1323 $restype = $tmp[1];
1324 $resdate = $tmp[2];
1325 } break;
1326 case "2": {
1327 $resnote = $tmp[0];
1328 $restype = $tmp[1];
1329 $resdate = "";
1330 } break;
1331 case "1": {
1332 $resnote = $tmp[0];
1333 $resdate = $restype = "";
1334 } break;
1335 default: {
1336 $restype = $resdate = $resnote = "";
1337 } break;
1339 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1340 echo "<table cellpadding='0' cellspacing='0'>";
1341 echo "<tr>";
1342 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1343 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1344 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1345 if($data_type == 28)
1347 echo "<td><input type='text'" .
1348 " size='$fldlength'" .
1349 " class='under'" .
1350 " value='$resnote' /></td>";
1351 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1352 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1353 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1355 else if($data_type == 32)
1357 echo "<tr><td><input type='text'" .
1358 " size='$fldlength'" .
1359 " class='under'" .
1360 " value='$resnote' /></td></tr>";
1361 $fldlength = 30;
1362 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1363 echo "<td><input type='text'" .
1364 " size='$fldlength'" .
1365 " class='under'" .
1366 " value='$smoking_status_title' /></td>";
1367 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1369 echo "<td><input type='radio'";
1370 if ($restype == "current".$field_id) echo " checked";
1371 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1373 echo "<td><input type='radio'";
1374 if ($restype == "current".$field_id) echo " checked";
1375 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1377 echo "<td><input type='text' size='6'" .
1378 " value='$resdate'" .
1379 " class='under'" .
1380 " /></td>";
1382 echo "<td><input type='radio'";
1383 if ($restype == "current".$field_id) echo " checked";
1384 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1386 echo "<td><input type='radio'";
1387 if ($restype == "not_applicable".$field_id) echo " checked";
1388 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1389 echo "</tr>";
1390 echo "</table>";
1393 // static text. read-only, of course.
1394 else if ($data_type == 31) {
1395 echo nl2br($frow['description']);
1398 else if($data_type == 34){
1399 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc,ENT_QUOTES)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1400 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1401 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1402 echo "</a>";
1405 //facilities drop-down list
1406 else if ($data_type == 35) {
1407 if (empty($currvalue)){
1408 $currvalue = 0;
1410 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1413 //Multi-select
1414 // Supports backup lists.
1415 else if ($data_type == 36) {
1416 if (empty($fld_length)) {
1417 if ($list_id == 'titles') {
1418 $fld_length = 3;
1419 } else {
1420 $fld_length = 10;
1423 $tmp = '';
1425 $values_array = explode("|", $currvalue);
1427 $i=0;
1428 foreach($values_array as $value) {
1429 if ($value) {
1430 $lrow = sqlQuery("SELECT title FROM list_options " .
1431 "WHERE list_id = ? AND option_id = ?", array($list_id,$value));
1432 $tmp = xl_list_label($lrow['title']);
1433 if ($lrow == 0 && !empty($backup_list)) {
1434 // since primary list did not map, try to map to backup list
1435 $lrow = sqlQuery("SELECT title FROM list_options " .
1436 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1437 $tmp = xl_list_label($lrow['title']);
1439 if (empty($tmp)) $tmp = "($value)";
1442 if ($tmp === '') {
1443 $tmp = '&nbsp;';
1445 else {
1446 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1448 if ($i != 0 && $tmp != '&nbsp;') echo ",";
1449 echo $tmp;
1450 $i++;
1456 function generate_display_field($frow, $currvalue) {
1457 global $ISSUE_TYPES;
1459 $data_type = $frow['data_type'];
1460 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1461 $list_id = $frow['list_id'];
1462 $backup_list = $frow['list_backup_id'];
1464 $s = '';
1466 // generic selection list or the generic selection list with add on the fly
1467 // feature, or radio buttons
1468 // Supports backup lists for datatypes 1,26,33
1469 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1470 $lrow = sqlQuery("SELECT title FROM list_options " .
1471 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1472 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1473 //if there is no matching value in the corresponding lists check backup list
1474 // only supported in data types 1,26,33
1475 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1476 $lrow = sqlQuery("SELECT title FROM list_options " .
1477 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
1478 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1482 // simple text field
1483 else if ($data_type == 2) {
1484 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1487 // long or multi-line text field
1488 else if ($data_type == 3) {
1489 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1492 // date
1493 else if ($data_type == 4) {
1494 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES);
1497 // provider
1498 else if ($data_type == 10 || $data_type == 11) {
1499 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1500 "WHERE id = ?", array($currvalue) );
1501 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1504 // pharmacy list
1505 else if ($data_type == 12) {
1506 $pres = get_pharmacies();
1507 while ($prow = sqlFetchArray($pres)) {
1508 $key = $prow['id'];
1509 if ($currvalue == $key) {
1510 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1511 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1512 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1517 // squads
1518 else if ($data_type == 13) {
1519 $squads = acl_get_squads();
1520 if ($squads) {
1521 foreach ($squads as $key => $value) {
1522 if ($currvalue == $key) {
1523 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1529 // address book
1530 else if ($data_type == 14) {
1531 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1532 "WHERE id = ?", array($currvalue));
1533 $uname = $urow['lname'];
1534 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1535 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1538 // billing code
1539 else if ($data_type == 15) {
1540 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1543 // insurance company list
1544 else if ($data_type == 16) {
1545 $insprovs = getInsuranceProviders();
1546 foreach ($insprovs as $key => $ipname) {
1547 if ($currvalue == $key) {
1548 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
1553 // issue types
1554 else if ($data_type == 17) {
1555 foreach ($ISSUE_TYPES as $key => $value) {
1556 if ($currvalue == $key) {
1557 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
1562 // a set of labeled checkboxes
1563 else if ($data_type == 21) {
1564 $avalue = explode('|', $currvalue);
1565 $lres = sqlStatement("SELECT * FROM list_options " .
1566 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1567 $count = 0;
1568 while ($lrow = sqlFetchArray($lres)) {
1569 $option_id = $lrow['option_id'];
1570 if (in_array($option_id, $avalue)) {
1571 if ($count++) $s .= "<br />";
1573 // Added 5-09 by BM - Translate label if applicable
1574 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1580 // a set of labeled text input fields
1581 else if ($data_type == 22) {
1582 $tmp = explode('|', $currvalue);
1583 $avalue = array();
1584 foreach ($tmp as $value) {
1585 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1586 $avalue[$matches[1]] = $matches[2];
1589 $lres = sqlStatement("SELECT * FROM list_options " .
1590 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1591 $s .= "<table cellpadding='0' cellspacing='0'>";
1592 while ($lrow = sqlFetchArray($lres)) {
1593 $option_id = $lrow['option_id'];
1594 if (empty($avalue[$option_id])) continue;
1596 // Added 5-09 by BM - Translate label if applicable
1597 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1599 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1601 $s .= "</table>";
1604 // a set of exam results; 3 radio buttons and a text field:
1605 else if ($data_type == 23) {
1606 $tmp = explode('|', $currvalue);
1607 $avalue = array();
1608 foreach ($tmp as $value) {
1609 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1610 $avalue[$matches[1]] = $matches[2];
1613 $lres = sqlStatement("SELECT * FROM list_options " .
1614 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1615 $s .= "<table cellpadding='0' cellspacing='0'>";
1616 while ($lrow = sqlFetchArray($lres)) {
1617 $option_id = $lrow['option_id'];
1618 $restype = substr($avalue[$option_id], 0, 1);
1619 $resnote = substr($avalue[$option_id], 2);
1620 if (empty($restype) && empty($resnote)) continue;
1622 // Added 5-09 by BM - Translate label if applicable
1623 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1625 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1626 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1627 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1628 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1629 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1630 $s .= "</tr>";
1632 $s .= "</table>";
1635 // the list of active allergies for the current patient
1636 else if ($data_type == 24) {
1637 $query = "SELECT title, comments FROM lists WHERE " .
1638 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1639 "ORDER BY begdate";
1640 // echo "<!-- $query -->\n"; // debugging
1641 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1642 $count = 0;
1643 while ($lrow = sqlFetchArray($lres)) {
1644 if ($count++) $s .= "<br />";
1645 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1646 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1650 // a set of labeled checkboxes, each with a text field:
1651 else if ($data_type == 25) {
1652 $tmp = explode('|', $currvalue);
1653 $avalue = array();
1654 foreach ($tmp as $value) {
1655 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1656 $avalue[$matches[1]] = $matches[2];
1659 $lres = sqlStatement("SELECT * FROM list_options " .
1660 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1661 $s .= "<table cellpadding='0' cellspacing='0'>";
1662 while ($lrow = sqlFetchArray($lres)) {
1663 $option_id = $lrow['option_id'];
1664 $restype = substr($avalue[$option_id], 0, 1);
1665 $resnote = substr($avalue[$option_id], 2);
1666 if (empty($restype) && empty($resnote)) continue;
1668 // Added 5-09 by BM - Translate label if applicable
1669 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1671 $restype = $restype ? xl('Yes') : xl('No');
1672 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1673 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1674 $s .= "</tr>";
1676 $s .= "</table>";
1679 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1680 // VicarePlus :: A selection list for smoking status.
1681 else if ($data_type == 28 || $data_type == 32) {
1682 $tmp = explode('|', $currvalue);
1683 switch(count($tmp)) {
1684 case "4": {
1685 $resnote = $tmp[0];
1686 $restype = $tmp[1];
1687 $resdate = $tmp[2];
1688 $reslist = $tmp[3];
1689 } break;
1690 case "3": {
1691 $resnote = $tmp[0];
1692 $restype = $tmp[1];
1693 $resdate = $tmp[2];
1694 } break;
1695 case "2": {
1696 $resnote = $tmp[0];
1697 $restype = $tmp[1];
1698 $resdate = "";
1699 } break;
1700 case "1": {
1701 $resnote = $tmp[0];
1702 $resdate = $restype = "";
1703 } break;
1704 default: {
1705 $restype = $resdate = $resnote = "";
1706 } break;
1708 $s .= "<table cellpadding='0' cellspacing='0'>";
1710 $s .= "<tr>";
1711 $res = "";
1712 if ($restype == "current".$field_id) $res = xl('Current');
1713 if ($restype == "quit".$field_id) $res = xl('Quit');
1714 if ($restype == "never".$field_id) $res = xl('Never');
1715 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1716 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1717 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1718 if ($data_type == 28)
1720 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1722 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1723 else if ($data_type == 32)
1725 if (!empty($reslist)) $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1726 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1729 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1730 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1731 $s .= "</tr>";
1732 $s .= "</table>";
1735 // static text. read-only, of course.
1736 else if ($data_type == 31) {
1737 $s .= nl2br($frow['description']);
1740 else if($data_type == 34){
1741 $arr = explode("|*|*|*|",$currvalue);
1742 for($i=0;$i<sizeof($arr);$i++){
1743 $s.=$arr[$i];
1747 // facility
1748 else if ($data_type == 35) {
1749 $urow = sqlQuery("SELECT id, name FROM facility ".
1750 "WHERE id = ?", array($currvalue) );
1751 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
1754 // Multi select
1755 // Supports backup lists
1756 else if ($data_type == 36) {
1757 $values_array = explode("|", $currvalue);
1759 $i = 0;
1760 foreach($values_array as $value) {
1761 $lrow = sqlQuery("SELECT title FROM list_options " .
1762 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
1764 if ($lrow == 0 && !empty($backup_list)) {
1765 //use back up list
1766 $lrow = sqlQuery("SELECT title FROM list_options " .
1767 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
1770 if ($i > 0) {
1771 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1772 } else {
1773 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1776 $i++;
1780 return $s;
1783 // Generate plain text versions of selected LBF field types.
1784 // Currently used by interface/patient_file/download_template.php.
1785 // More field types might need to be supported here in the future.
1787 function generate_plaintext_field($frow, $currvalue) {
1788 global $ISSUE_TYPES;
1790 $data_type = $frow['data_type'];
1791 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1792 $list_id = $frow['list_id'];
1793 $backup_list = $frow['backup_list'];
1794 $s = '';
1796 // generic selection list or the generic selection list with add on the fly
1797 // feature, or radio buttons
1798 // Supports backup lists (for datatypes 1,26,33)
1799 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1800 $lrow = sqlQuery("SELECT title FROM list_options " .
1801 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1802 $s = xl_list_label($lrow['title']);
1803 //if there is no matching value in the corresponding lists check backup list
1804 // only supported in data types 1,26,33
1805 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1806 $lrow = sqlQuery("SELECT title FROM list_options " .
1807 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
1808 $s = xl_list_label($lrow['title']);
1812 // simple or long text field
1813 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
1814 $s = $currvalue;
1817 // date
1818 else if ($data_type == 4) {
1819 $s = oeFormatShortDate($currvalue);
1822 // provider
1823 else if ($data_type == 10 || $data_type == 11) {
1824 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1825 "WHERE id = ?", array($currvalue) );
1826 $s = ucwords($urow['fname'] . " " . $urow['lname']);
1829 // pharmacy list
1830 else if ($data_type == 12) {
1831 $pres = get_pharmacies();
1832 while ($prow = sqlFetchArray($pres)) {
1833 $key = $prow['id'];
1834 if ($currvalue == $key) {
1835 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
1836 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1837 $prow['line1'] . ' / ' . $prow['city'];
1842 // address book
1843 else if ($data_type == 14) {
1844 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1845 "WHERE id = ?", array($currvalue));
1846 $uname = $urow['lname'];
1847 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1848 $s = $uname;
1851 // insurance company list
1852 else if ($data_type == 16) {
1853 $insprovs = getInsuranceProviders();
1854 foreach ($insprovs as $key => $ipname) {
1855 if ($currvalue == $key) {
1856 $s .= $ipname;
1861 // insurance company list
1862 else if ($data_type == 17) {
1863 foreach ($ISSUE_TYPES as $key => $value) {
1864 if ($currvalue == $key) {
1865 $s .= $value[1];
1870 // a set of labeled checkboxes
1871 else if ($data_type == 21) {
1872 $avalue = explode('|', $currvalue);
1873 $lres = sqlStatement("SELECT * FROM list_options " .
1874 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1875 $count = 0;
1876 while ($lrow = sqlFetchArray($lres)) {
1877 $option_id = $lrow['option_id'];
1878 if (in_array($option_id, $avalue)) {
1879 if ($count++) $s .= "; ";
1880 $s .= xl_list_label($lrow['title']);
1885 // a set of labeled text input fields
1886 else if ($data_type == 22) {
1887 $tmp = explode('|', $currvalue);
1888 $avalue = array();
1889 foreach ($tmp as $value) {
1890 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1891 $avalue[$matches[1]] = $matches[2];
1894 $lres = sqlStatement("SELECT * FROM list_options " .
1895 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1896 while ($lrow = sqlFetchArray($lres)) {
1897 $option_id = $lrow['option_id'];
1898 if (empty($avalue[$option_id])) continue;
1899 if ($s !== '') $s .= '; ';
1900 $s .= xl_list_label($lrow['title']) . ': ';
1901 $s .= $avalue[$option_id];
1905 // A set of exam results; 3 radio buttons and a text field.
1906 // This shows abnormal results only.
1907 else if ($data_type == 23) {
1908 $tmp = explode('|', $currvalue);
1909 $avalue = array();
1910 foreach ($tmp as $value) {
1911 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1912 $avalue[$matches[1]] = $matches[2];
1915 $lres = sqlStatement("SELECT * FROM list_options " .
1916 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1917 while ($lrow = sqlFetchArray($lres)) {
1918 $option_id = $lrow['option_id'];
1919 $restype = substr($avalue[$option_id], 0, 1);
1920 $resnote = substr($avalue[$option_id], 2);
1921 if (empty($restype) && empty($resnote)) continue;
1922 if ($restype != '2') continue; // show abnormal results only
1923 if ($s !== '') $s .= '; ';
1924 $s .= xl_list_label($lrow['title']);
1925 if (!empty($resnote)) $s .= ': ' . $resnote;
1929 // the list of active allergies for the current patient
1930 else if ($data_type == 24) {
1931 $query = "SELECT title, comments FROM lists WHERE " .
1932 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1933 "ORDER BY begdate";
1934 $lres = sqlStatement($query, array($GLOBALS['pid']));
1935 $count = 0;
1936 while ($lrow = sqlFetchArray($lres)) {
1937 if ($count++) $s .= "; ";
1938 $s .= $lrow['title'];
1939 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
1943 // a set of labeled checkboxes, each with a text field:
1944 else if ($data_type == 25) {
1945 $tmp = explode('|', $currvalue);
1946 $avalue = array();
1947 foreach ($tmp as $value) {
1948 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1949 $avalue[$matches[1]] = $matches[2];
1952 $lres = sqlStatement("SELECT * FROM list_options " .
1953 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
1954 while ($lrow = sqlFetchArray($lres)) {
1955 $option_id = $lrow['option_id'];
1956 $restype = substr($avalue[$option_id], 0, 1);
1957 $resnote = substr($avalue[$option_id], 2);
1958 if (empty($restype) && empty($resnote)) continue;
1959 if ($s !== '') $s .= '; ';
1960 $s .= xl_list_label($lrow['title']);
1961 $restype = $restype ? xl('Yes') : xl('No');
1962 $s .= $restype;
1963 if ($resnote) $s .= ' ' . $resnote;
1967 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1968 // VicarePlus :: A selection list for smoking status.
1969 else if ($data_type == 28 || $data_type == 32) {
1970 $tmp = explode('|', $currvalue);
1971 $resnote = count($tmp) > 0 ? $tmp[0] : '';
1972 $restype = count($tmp) > 1 ? $tmp[1] : '';
1973 $resdate = count($tmp) > 2 ? $tmp[2] : '';
1974 $reslist = count($tmp) > 3 ? $tmp[3] : '';
1975 $res = "";
1976 if ($restype == "current" . $field_id) $res = xl('Current');
1977 if ($restype == "quit" . $field_id) $res = xl('Quit');
1978 if ($restype == "never" . $field_id) $res = xl('Never');
1979 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
1981 if ($data_type == 28) {
1982 if (!empty($resnote)) $s .= $resnote;
1984 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
1985 else if ($data_type == 32) {
1986 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1987 if (!empty($resnote)) $s .= ' ' . $resnote;
1989 if (!empty($res)) {
1990 if ($s !== '') $s .= ' ';
1991 $s .= xl('Status') . ' ' . $res;
1993 if ($restype == "quit".$field_id) {
1994 if ($s !== '') $s .= ' ';
1995 $s .= $resdate;
1999 // Multi select
2000 // Supports backup lists
2001 else if ($data_type == 36) {
2002 $values_array = explode("|", $currvalue);
2004 $i = 0;
2005 foreach($values_array as $value) {
2006 $lrow = sqlQuery("SELECT title FROM list_options " .
2007 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
2009 if ($lrow == 0 && !empty($backup_list)) {
2010 //use back up list
2011 $lrow = sqlQuery("SELECT title FROM list_options " .
2012 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
2015 if ($i > 0) {
2016 $s = $s . ", " . xl_list_label($lrow['title']);
2017 } else {
2018 $s = xl_list_label($lrow['title']);
2021 $i++;
2025 return $s;
2028 $CPR = 4; // cells per row of generic data
2029 $last_group = '';
2030 $cell_count = 0;
2031 $item_count = 0;
2033 function disp_end_cell() {
2034 global $item_count, $cell_count;
2035 if ($item_count > 0) {
2036 echo "</td>";
2037 $item_count = 0;
2041 function disp_end_row() {
2042 global $cell_count, $CPR;
2043 disp_end_cell();
2044 if ($cell_count > 0) {
2045 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
2046 echo "</tr>\n";
2047 $cell_count = 0;
2051 function disp_end_group() {
2052 global $last_group;
2053 if (strlen($last_group) > 0) {
2054 disp_end_row();
2058 function display_layout_rows($formtype, $result1, $result2='') {
2059 global $item_count, $cell_count, $last_group, $CPR;
2061 $fres = sqlStatement("SELECT * FROM layout_options " .
2062 "WHERE form_id = ? AND uor > 0 " .
2063 "ORDER BY group_name, seq", array($formtype) );
2065 while ($frow = sqlFetchArray($fres)) {
2066 $this_group = $frow['group_name'];
2067 $titlecols = $frow['titlecols'];
2068 $datacols = $frow['datacols'];
2069 $data_type = $frow['data_type'];
2070 $field_id = $frow['field_id'];
2071 $list_id = $frow['list_id'];
2072 $currvalue = '';
2074 if ($formtype == 'DEM') {
2075 if ($GLOBALS['athletic_team']) {
2076 // Skip fitness level and return-to-play date because those appear
2077 // in a special display/update form on this page.
2078 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2080 if (strpos($field_id, 'em_') === 0) {
2081 // Skip employer related fields, if it's disabled.
2082 if ($GLOBALS['omit_employers']) continue;
2083 $tmp = substr($field_id, 3);
2084 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2086 else {
2087 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2090 else {
2091 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2094 // Handle a data category (group) change.
2095 if (strcmp($this_group, $last_group) != 0) {
2096 $group_name = substr($this_group, 1);
2097 // totally skip generating the employer category, if it's disabled.
2098 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2099 disp_end_group();
2100 $last_group = $this_group;
2103 // filter out all the empty field data from the patient report.
2104 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2105 // Handle starting of a new row.
2106 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2107 disp_end_row();
2108 echo "<tr>";
2109 if ($group_name) {
2110 echo "<td class='groupname'>";
2111 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2112 //echo "<font color='#008800'>$group_name</font>";
2114 // Added 5-09 by BM - Translate label if applicable
2115 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
2117 $group_name = '';
2118 } else {
2119 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2120 echo "<td valign='top'>&nbsp;";
2122 echo "</td>";
2125 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2127 // Handle starting of a new label cell.
2128 if ($titlecols > 0) {
2129 disp_end_cell();
2130 //echo "<td class='label' colspan='$titlecols' valign='top'";
2131 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2132 echo "<td class='label' colspan='$titlecols_esc' ";
2133 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2134 echo ">";
2135 $cell_count += $titlecols;
2137 ++$item_count;
2139 // Added 5-09 by BM - Translate label if applicable
2140 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2142 // Handle starting of a new data cell.
2143 if ($datacols > 0) {
2144 disp_end_cell();
2145 //echo "<td class='text data' colspan='$datacols' valign='top'";
2146 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2147 echo "<td class='text data' colspan='$datacols_esc'";
2148 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2149 echo ">";
2150 $cell_count += $datacols;
2153 ++$item_count;
2154 echo generate_display_field($frow, $currvalue);
2158 disp_end_group();
2161 function display_layout_tabs($formtype, $result1, $result2='') {
2162 global $item_count, $cell_count, $last_group, $CPR;
2164 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2165 "WHERE form_id = ? AND uor > 0 " .
2166 "ORDER BY group_name, seq", array($formtype) );
2168 $first = true;
2169 while ($frow = sqlFetchArray($fres)) {
2170 $this_group = $frow['group_name'];
2171 $group_name = substr($this_group, 1);
2173 <li <?php echo $first ? 'class="current"' : '' ?>>
2174 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
2175 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
2176 </li>
2177 <?php
2178 $first = false;
2182 function display_layout_tabs_data($formtype, $result1, $result2='') {
2183 global $item_count, $cell_count, $last_group, $CPR;
2185 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2186 "WHERE form_id = ? AND uor > 0 " .
2187 "ORDER BY group_name, seq", array($formtype));
2189 $first = true;
2190 while ($frow = sqlFetchArray($fres)) {
2191 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
2192 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
2193 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
2194 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
2195 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
2196 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
2197 $currvalue = '';
2199 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2200 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2201 "ORDER BY seq", array($formtype, $this_group) );
2204 <div class="tab <?php echo $first ? 'current' : '' ?>">
2205 <table border='0' cellpadding='0'>
2207 <?php
2208 while ($group_fields = sqlFetchArray($group_fields_query)) {
2210 $titlecols = $group_fields['titlecols'];
2211 $datacols = $group_fields['datacols'];
2212 $data_type = $group_fields['data_type'];
2213 $field_id = $group_fields['field_id'];
2214 $list_id = $group_fields['list_id'];
2215 $currvalue = '';
2217 if ($formtype == 'DEM') {
2218 if ($GLOBALS['athletic_team']) {
2219 // Skip fitness level and return-to-play date because those appear
2220 // in a special display/update form on this page.
2221 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2223 if (strpos($field_id, 'em_') === 0) {
2224 // Skip employer related fields, if it's disabled.
2225 if ($GLOBALS['omit_employers']) continue;
2226 $tmp = substr($field_id, 3);
2227 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2229 else {
2230 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2233 else {
2234 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2237 // Handle a data category (group) change.
2238 if (strcmp($this_group, $last_group) != 0) {
2239 $group_name = substr($this_group, 1);
2240 // totally skip generating the employer category, if it's disabled.
2241 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2242 $last_group = $this_group;
2245 // Handle starting of a new row.
2246 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2247 disp_end_row();
2248 echo "<tr>";
2251 if ($item_count == 0 && $titlecols == 0) {
2252 $titlecols = 1;
2255 // Handle starting of a new label cell.
2256 if ($titlecols > 0) {
2257 disp_end_cell();
2258 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2259 echo "<td class='label' colspan='$titlecols_esc' ";
2260 echo ">";
2261 $cell_count += $titlecols;
2263 ++$item_count;
2265 // Added 5-09 by BM - Translate label if applicable
2266 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2268 // Handle starting of a new data cell.
2269 if ($datacols > 0) {
2270 disp_end_cell();
2271 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2272 echo "<td class='text data' colspan='$datacols_esc'";
2273 echo ">";
2274 $cell_count += $datacols;
2277 ++$item_count;
2278 echo generate_display_field($group_fields, $currvalue);
2281 disp_end_row();
2284 </table>
2285 </div>
2287 <?php
2289 $first = false;
2295 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2296 global $item_count, $cell_count, $last_group, $CPR;
2298 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2299 "WHERE form_id = ? AND uor > 0 " .
2300 "ORDER BY group_name, seq", array($formtype) );
2302 $first = true;
2303 while ($frow = sqlFetchArray($fres)) {
2304 $this_group = $frow['group_name'];
2305 $group_name = substr($this_group, 1);
2306 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
2307 $titlecols = $frow['titlecols'];
2308 $datacols = $frow['datacols'];
2309 $data_type = $frow['data_type'];
2310 $field_id = $frow['field_id'];
2311 $list_id = $frow['list_id'];
2312 $currvalue = '';
2314 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2315 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2316 "ORDER BY seq", array($formtype,$this_group) );
2319 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
2320 <table border='0' cellpadding='0'>
2322 <?php
2323 while ($group_fields = sqlFetchArray($group_fields_query)) {
2325 $titlecols = $group_fields['titlecols'];
2326 $datacols = $group_fields['datacols'];
2327 $data_type = $group_fields['data_type'];
2328 $field_id = $group_fields['field_id'];
2329 $list_id = $group_fields['list_id'];
2330 $backup_list = $group_fields['list_backup_id'];
2331 $currvalue = '';
2333 if ($formtype == 'DEM') {
2334 if ($GLOBALS['athletic_team']) {
2335 // Skip fitness level and return-to-play date because those appear
2336 // in a special display/update form on this page.
2337 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2339 if (strpos($field_id, 'em_') === 0) {
2340 // Skip employer related fields, if it's disabled.
2341 if ($GLOBALS['omit_employers']) continue;
2342 $tmp = substr($field_id, 3);
2343 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2345 else {
2346 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2349 else {
2350 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2353 // Handle a data category (group) change.
2354 if (strcmp($this_group, $last_group) != 0) {
2355 $group_name = substr($this_group, 1);
2356 // totally skip generating the employer category, if it's disabled.
2357 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2358 $last_group = $this_group;
2361 // Handle starting of a new row.
2362 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2363 disp_end_row();
2364 echo "<tr>";
2367 if ($item_count == 0 && $titlecols == 0) {
2368 $titlecols = 1;
2371 // Handle starting of a new label cell.
2372 if ($titlecols > 0) {
2373 disp_end_cell();
2374 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2375 echo "<td class='label' colspan='$titlecols_esc' ";
2376 echo ">";
2377 $cell_count += $titlecols;
2379 ++$item_count;
2381 // Added 5-09 by BM - Translate label if applicable
2382 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
2384 // Handle starting of a new data cell.
2385 if ($datacols > 0) {
2386 disp_end_cell();
2387 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2388 echo "<td class='text data' colspan='$datacols_esc'";
2389 echo ">";
2390 $cell_count += $datacols;
2393 ++$item_count;
2395 echo generate_form_field($group_fields, $currvalue);
2399 </table>
2400 </div>
2402 <?php
2404 $first = false;
2409 // From the currently posted HTML form, this gets the value of the
2410 // field corresponding to the provided layout_options table row.
2412 function get_layout_form_value($frow, $prefix='form_') {
2413 // Bring in $sanitize_all_escapes variable, which will decide
2414 // the variable escaping method.
2415 global $sanitize_all_escapes;
2417 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
2418 $data_type = $frow['data_type'];
2419 $field_id = $frow['field_id'];
2420 $value = '';
2421 if (isset($_POST["$prefix$field_id"])) {
2422 if ($data_type == 21) {
2423 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2424 // must be concatenated into a |-separated string.
2425 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2426 if (strlen($value)) $value .= '|';
2427 $value .= $key;
2430 else if ($data_type == 22) {
2431 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2432 // into "key:value|key:value|...".
2433 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2434 $val = str_replace('|', ' ', $val);
2435 if (strlen($value)) $value .= '|';
2436 $value .= "$key:$val";
2439 else if ($data_type == 23) {
2440 // $_POST["$prefix$field_id"] is an array of text fields with companion
2441 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2442 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2443 $restype = $_POST["radio_{$field_id}"][$key];
2444 if (empty($restype)) $restype = '0';
2445 $val = str_replace('|', ' ', $val);
2446 if (strlen($value)) $value .= '|';
2447 $value .= "$key:$restype:$val";
2450 else if ($data_type == 25) {
2451 // $_POST["$prefix$field_id"] is an array of text fields with companion
2452 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2453 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2454 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
2455 $val = str_replace('|', ' ', $val);
2456 if (strlen($value)) $value .= '|';
2457 $value .= "$key:$restype:$val";
2460 else if ($data_type == 28 || $data_type == 32) {
2461 // $_POST["$prefix$field_id"] is an date text fields with companion
2462 // radio buttons to be imploded into "notes|type|date".
2463 $restype = $_POST["radio_{$field_id}"];
2464 if (empty($restype)) $restype = '0';
2465 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2466 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2467 if ($data_type == 32)
2469 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2470 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2471 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2472 $value = "$res_text_note|$restype|$resdate|$reslist";
2474 else
2475 $value = "$resnote|$restype|$resdate";
2477 else if ($data_type == 36) {
2478 $value_array = $_POST["form_$field_id"];
2479 $i = 0;
2480 foreach ($value_array as $key => $valueofkey) {
2481 if ($i == 0) {
2482 $value = $valueofkey;
2483 } else {
2484 $value = $value . "|" . $valueofkey;
2486 $i++;
2489 else {
2490 $value = $_POST["$prefix$field_id"];
2494 // Better to die than to silently truncate data!
2495 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2496 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2497 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2499 // Make sure the return value is quote-safe.
2500 if ($sanitize_all_escapes) {
2501 //escapes already removed and using binding/placemarks in sql calls
2502 // so only need to trim value
2503 return trim($value);
2505 else {
2506 //need to explicitly prepare value
2507 return formTrim($value);
2511 // Generate JavaScript validation logic for the required fields.
2513 function generate_layout_validation($form_id) {
2514 $fres = sqlStatement("SELECT * FROM layout_options " .
2515 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2516 "ORDER BY group_name, seq", array($form_id) );
2518 while ($frow = sqlFetchArray($fres)) {
2519 if ($frow['uor'] < 2) continue;
2520 $data_type = $frow['data_type'];
2521 $field_id = $frow['field_id'];
2522 $fldtitle = $frow['title'];
2523 if (!$fldtitle) $fldtitle = $frow['description'];
2524 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
2525 switch($data_type) {
2526 case 1:
2527 case 11:
2528 case 12:
2529 case 13:
2530 case 14:
2531 case 26:
2532 case 33:
2533 case 36:
2534 echo
2535 " if (f.$fldname.selectedIndex <= 0) {\n" .
2536 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2537 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2538 " }\n";
2539 break;
2540 case 27: // radio buttons
2541 echo
2542 " var i = 0;\n" .
2543 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2544 " if (i >= f.$fldname.length) {\n" .
2545 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2546 " }\n";
2547 break;
2548 case 2:
2549 case 3:
2550 case 4:
2551 case 15:
2552 echo
2553 " if (trimlen(f.$fldname.value) == 0) {\n" .
2554 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2555 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2556 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2557 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2558 " } else { " .
2559 " $('#" . $fldname . "').attr('style',''); " .
2560 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2561 " } \n";
2562 break;
2568 * DROPDOWN FOR FACILITIES
2570 * build a dropdown with all facilities
2572 * @param string $selected - name of the currently selected facility
2573 * use '0' for "unspecified facility"
2574 * use '' for "All facilities" (the default)
2575 * @param string $name - the name/id for select form (defaults to "form_facility")
2576 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2577 * defaults to true
2578 * @return void - just echo the html encoded string
2580 * Note: This should become a data-type at some point, according to Brady
2582 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true, $allow_allfacilities = true) {
2583 $have_selected = false;
2584 $query = "SELECT id, name FROM facility ORDER BY name";
2585 $fres = sqlStatement($query);
2587 $name = htmlspecialchars($name, ENT_QUOTES);
2588 echo " <select name=\"$name\" id=\"$name\">\n";
2590 if ($allow_allfacilities) {
2591 $option_value = '';
2592 $option_selected_attr = '';
2593 if ($selected == '') {
2594 $option_selected_attr = ' selected="selected"';
2595 $have_selected = true;
2597 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2598 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2599 } elseif ($allow_unspecified) {
2600 $option_value = '0';
2601 $option_selected_attr = '';
2602 if ( $selected == '0' ) {
2603 $option_selected_attr = ' selected="selected"';
2604 $have_selected = true;
2606 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2607 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2610 while ($frow = sqlFetchArray($fres)) {
2611 $facility_id = $frow['id'];
2612 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2613 $option_selected_attr = '';
2614 if ($selected == $facility_id) {
2615 $option_selected_attr = ' selected="selected"';
2616 $have_selected = true;
2618 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2619 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2622 if ($allow_unspecified && $allow_allfacilities) {
2623 $option_value = '0';
2624 $option_selected_attr = '';
2625 if ( $selected == '0' ) {
2626 $option_selected_attr = ' selected="selected"';
2627 $have_selected = true;
2629 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2630 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2633 if (!$have_selected) {
2634 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2635 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2636 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2637 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2639 echo " </select>\n";
2642 // Expand Collapse Widget
2643 // This forms the header and functionality component of the widget. The information that is displayed
2644 // then follows this function followed by a closing div tag
2646 // $title is the title of the section (already translated)
2647 // $label is identifier used in the tag id's and sql columns
2648 // $buttonLabel is the button label text (already translated)
2649 // $buttonLink is the button link information
2650 // $buttonClass is any additional needed class elements for the button tag
2651 // $linkMethod is the button link method ('javascript' vs 'html')
2652 // $bodyClass is to set class(es) of the body
2653 // $auth is a flag to decide whether to show the button
2654 // $fixedWidth is to flag whether width is fixed
2655 // $forceExpandAlways is a flag to force the widget to always be expanded
2657 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2658 if ($fixedWidth) {
2659 echo "<div class='section-header'>";
2661 else {
2662 echo "<div class='section-header-dynamic'>";
2664 echo "<table><tr>";
2665 if ($auth) {
2666 // show button, since authorized
2667 // first prepare class string
2668 if ($buttonClass) {
2669 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2671 else {
2672 $class_string = "css_button_small";
2674 // next, create the link
2675 if ($linkMethod == "javascript") {
2676 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2678 else {
2679 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2680 if (!isset($_SESSION['patient_portal_onsite'])) {
2681 // prevent an error from occuring when calling the function from the patient portal
2682 echo " onclick='top.restoreSession()'";
2685 if (!$GLOBALS['concurrent_layout']) {
2686 echo " target='Main'";
2688 echo "><span>" .
2689 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2691 if ($forceExpandAlways){
2692 // Special case to force the widget to always be expanded
2693 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2694 $indicatorTag ="style='display:none'";
2696 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
2697 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2698 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
2699 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2701 if (isset($_SESSION['patient_portal_onsite'])) {
2702 // collapse all entries in the patient portal
2703 $text = xl('expand');
2705 else if (getUserSetting($label."_ps_expand")) {
2706 $text = xl('collapse');
2708 else {
2709 $text = xl('expand');
2711 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
2712 "</span>)</a></td>";
2713 echo "</tr></table>";
2714 echo "</div>";
2715 if ($forceExpandAlways) {
2716 // Special case to force the widget to always be expanded
2717 $styling = "";
2719 else if (isset($_SESSION['patient_portal_onsite'])) {
2720 // collapse all entries in the patient portal
2721 $styling = "style='display:none'";
2723 else if (getUserSetting($label."_ps_expand")) {
2724 $styling = "";
2726 else {
2727 $styling = "style='display:none'";
2729 if ($bodyClass) {
2730 $styling .= " class='" . $bodyClass . "'";
2732 //next, create the first div tag to hold the information
2733 // note the code that calls this function will then place the ending div tag after the data
2734 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
2737 //billing_facility fuction will give the dropdown list which contain billing faciliies.
2738 function billing_facility($name,$select){
2739 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
2740 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
2741 while ($facrow = sqlFetchArray($qsql)) {
2742 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
2743 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
2745 echo "</select>";
2748 // Generic function to get the translated title value for a particular list option.
2750 function getListItemTitle($list, $option) {
2751 $row = sqlQuery("SELECT title FROM list_options WHERE " .
2752 "list_id = ? AND option_id = ?", array($list, $option));
2753 if (empty($row['title'])) return $option;
2754 return xl_list_label($row['title']);