updated procedure order ui
[openemr.git] / library / options.inc.php
bloba9438f364516f8242b329b502e99ad3732ca01b1
1 <?php
2 // Copyright (C) 2007-2016 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 // A = Age as years or "xx month(s)"
22 // B = Gestational age as "xx week(s) y day(s)"
23 // C = Capitalize first letter of each word (text fields)
24 // D = Check for duplicates in New Patient form
25 // G = Graphable (for numeric fields in forms supporting historical data)
26 // H = Read-only field copied from static history (this is obsolete)
27 // L = Lab Order ("ord_lab") types only (address book)
28 // N = Show in New Patient form
29 // O = Procedure Order ("ord_*") types only (address book)
30 // P = Default to previous value when current value is not yet set
31 // R = Distributor types only (address book)
32 // T = Use description as default Text
33 // U = Capitalize all letters (text fields)
34 // V = Vendor types only (address book)
35 // 0 = Read Only - the input element's "disabled" property is set
36 // 1 = Write Once (not editable when not empty) (text fields)
37 // 2 = Show descriptions instead of codes for billing code input
39 require_once("user.inc");
40 require_once("patient.inc");
41 require_once("lists.inc");
42 require_once(dirname(dirname(__FILE__)) . "/custom/code_types.inc.php");
44 $date_init = "";
46 function get_pharmacies() {
47 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
48 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
49 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
50 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
51 "AND p.type = 2 " .
52 "ORDER BY name, area_code, prefix, number");
55 function optionalAge($frow, $date, &$asof) {
56 $asof = '';
57 if (empty($date)) return '';
58 $date = substr($date, 0, 10);
59 if (strpos($frow['edit_options'], 'A') !== FALSE) {
60 $format = 0;
62 else if (strpos($frow['edit_options'], 'B') !== FALSE) {
63 $format = 3;
65 else {
66 return '';
68 if (strpos($frow['form_id'], 'LBF') === 0) {
69 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
70 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
71 array($GLOBALS['pid'], $GLOBALS['encounter']));
72 if (!empty($tmp['date'])) $asof = substr($tmp['date'], 0, 10);
74 $prefix = ($format ? xl('Gest age') : xl('Age')) . ' ';
75 return $prefix . oeFormatAge($date, $asof, $format);
78 // Function to generate a drop-list.
80 function generate_select_list($tag_name, $list_id, $currvalue, $title, $empty_name = ' ', $class = '',
81 $onchange = '', $tag_id = '', $custom_attributes = null, $multiple = false, $backup_list = '') {
82 $s = '';
84 $tag_name_esc = attr($tag_name);
86 if ($multiple) {
87 $tag_name_esc = $tag_name_esc . "[]";
90 $s .= "<select class='form-control' name='$tag_name_esc'";
92 if ($multiple) {
93 $s .= " multiple='multiple'";
96 $tag_id_esc = attr( $tag_name );
98 if ($tag_id != '') {
99 $tag_id_esc = attr($tag_id);
102 $s .= " id='$tag_id_esc'";
104 if ($class) {
105 $class_esc = attr($class);
106 $s .= " class='$class_esc'";
108 if ($onchange) {
109 $s .= " onchange='$onchange'";
111 if ($custom_attributes != null && is_array ( $custom_attributes )) {
112 foreach ( $custom_attributes as $attr => $val ) {
113 if (isset ( $custom_attributes [$attr] )) {
114 $s .= " " . attr($attr) . "='" . attr($val) . "'";
118 $selectTitle = attr($title);
119 $s .= " title='$selectTitle'>";
120 $selectEmptyName = xlt($empty_name);
121 if ($empty_name)
122 $s .= "<option value=''>" . $selectEmptyName . "</option>";
124 // List order depends on language translation options.
125 // (Note we do not need to worry about the list order in the algorithm
126 // after the below code block since that is where searches for exceptions
127 // are done which include inactive items or items from a backup
128 // list; note these will always be shown at the bottom of the list no matter the
129 // chosen order.)
130 $lang_id = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
131 // sort by title
132 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) || !$GLOBALS['translate_lists']) {
133 // do not translate
134 if ($GLOBALS['gb_how_sort_list'] == '0') {
135 // order by seq
136 $order_by_sql = "seq, title";
138 else { //$GLOBALS['gb_how_sort_list'] == '1'
139 // order by title
140 $order_by_sql = "title, seq";
142 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
144 else {
145 // do translate
146 if ($GLOBALS['gb_how_sort_list'] == '0') {
147 // order by seq
148 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
150 else { //$GLOBALS['gb_how_sort_list'] == '1'
151 // order by title
152 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
154 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
155 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
156 "FROM list_options AS lo " .
157 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
158 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
159 "ld.lang_id = ? " .
160 "WHERE lo.list_id = ? AND lo.activity=1 " .
161 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
163 $got_selected = FALSE;
165 while ( $lrow = sqlFetchArray ( $lres ) ) {
166 $selectedValues = explode ( "|", $currvalue );
168 $optionValue = attr($lrow ['option_id']);
169 $s .= "<option value='$optionValue'";
171 if ((strlen ( $currvalue ) == 0 && $lrow ['is_default']) || (strlen ( $currvalue ) > 0 && in_array ( $lrow ['option_id'], $selectedValues ))) {
172 $s .= " selected";
173 $got_selected = TRUE;
176 // Already has been translated above (if applicable), so do not need to use
177 // the xl_list_label() function here
178 $optionLabel = text($lrow ['title']);
179 $s .= ">$optionLabel</option>\n";
183 To show the inactive item in the list if the value is saved to database
185 if (!$got_selected && strlen($currvalue) > 0)
187 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
188 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
189 $lrow_inactive = sqlFetchArray($lres_inactive);
190 if($lrow_inactive['option_id']) {
191 $optionValue = htmlspecialchars( $lrow_inactive['option_id'], ENT_QUOTES);
192 $s .= "<option value='$optionValue' selected>" . htmlspecialchars( xl_list_label($lrow_inactive['title']), ENT_NOQUOTES) . "</option>\n";
193 $got_selected = TRUE;
197 if (!$got_selected && strlen ( $currvalue ) > 0 && !$multiple) {
198 $list_id = $backup_list;
199 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
201 if ($lrow > 0 && !empty($backup_list)) {
202 $selected = text(xl_list_label($lrow ['title']));
203 $s .= "<option value='$currescaped' selected> $selected </option>";
204 $s .= "</select>";
205 } else {
206 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
207 $s .= "</select>";
208 $fontTitle = xlt('Please choose a valid selection from the list.');
209 $fontText = xlt( 'Fix this' );
210 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
213 } else if (!$got_selected && strlen ( $currvalue ) > 0 && $multiple) {
214 //if not found in main list, display all selected values that exist in backup list
215 $list_id = $backup_list;
217 $got_selected_backup = FALSE;
218 if (!empty($backup_list)) {
219 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
220 while ( $lrow_backup = sqlFetchArray ( $lres_backup ) ) {
221 $selectedValues = explode ( "|", $currvalue );
223 $optionValue = attr($lrow_backup['option_id']);
225 if ( in_array($lrow_backup ['option_id'],$selectedValues)) {
226 $s .= "<option value='$optionValue'";
227 $s .= " selected";
228 $optionLabel = text(xl_list_label($lrow_backup ['title']));
229 $s .= ">$optionLabel</option>\n";
230 $got_selected_backup = TRUE;
234 if (!$got_selected_backup) {
235 $selectedValues = explode ( "|", $currvalue );
236 foreach ( $selectedValues as $selectedValue ) {
237 $s .= "<option value='" . attr($selectedValue) . "'";
238 $s .= " selected";
239 $s .= ">* " . text($selectedValue) . " *</option>\n";
241 $s .= "</select>";
242 $fontTitle = xlt('Please choose a valid selection from the list.');
243 $fontText = xlt( 'Fix this' );
244 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
248 else {
249 $s .= "</select>";
251 return $s;
255 // $frow is a row from the layout_options table.
256 // $currvalue is the current value, if any, of the associated item.
258 function generate_form_field($frow, $currvalue) {
259 global $rootdir, $date_init, $ISSUE_TYPES, $code_types,$condition_str;
261 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
263 $data_type = $frow['data_type'];
264 $field_id = $frow['field_id'];
265 $list_id = $frow['list_id'];
266 $backup_list = $frow['list_backup_id'];
267 $condition_str = get_conditions_str($condition_str,$frow);
269 // escaped variables to use in html
270 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
271 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
273 // Added 5-09 by BM - Translate description if applicable
274 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
276 // Support edit option T which assigns the (possibly very long) description as
277 // the default value.
278 if (strpos($frow['edit_options'], 'T') !== FALSE) {
279 if (strlen($currescaped) == 0) $currescaped = $description;
280 // Description used in this way is not suitable as a title.
281 $description = '';
284 // added 5-2009 by BM to allow modification of the 'empty' text title field.
285 // Can pass $frow['empty_title'] with this variable, otherwise
286 // will default to 'Unassigned'.
287 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
288 // if make $frow['empty_title'] equal to 'SKIP'
289 $showEmpty = true;
290 if (isset($frow['empty_title'])) {
291 if ($frow['empty_title'] == "SKIP") {
292 //do not display an 'empty' choice
293 $showEmpty = false;
294 $empty_title = "Unassigned";
296 else {
297 $empty_title = $frow['empty_title'];
300 else {
301 $empty_title = "Unassigned";
304 $disabled = strpos($frow['edit_options'], '0') === FALSE ? '' : 'disabled';
306 $lbfchange = (strpos($frow['form_id'], 'LBF') === 0 || strpos($frow['form_id'], 'LBT') === 0) ?
307 "checkSkipConditions();" : "";
308 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
310 // generic single-selection list or Race and Ethnicity.
311 // These data types support backup lists.
312 if ($data_type == 1 || $data_type == 33) {
313 echo generate_select_list("form_$field_id", $list_id, $currvalue,
314 $description, ($showEmpty ? $empty_title : ''), '', $lbfchange, '',
315 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
318 // simple text field
319 else if ($data_type == 2) {
320 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
321 $maxlength = $frow['max_length'];
322 $string_maxlength = "";
323 // if max_length is set to zero, then do not set a maxlength
324 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
325 echo "<input type='text'" .
326 " name='form_$field_id_esc'" .
327 " id='form_$field_id_esc'" .
328 " size='$fldlength'" .
329 " $string_maxlength" .
330 " title='$description'" .
331 " value='$currescaped'";
332 $tmp = $lbfchange;
333 if (strpos($frow['edit_options'], 'C') !== FALSE)
334 $tmp .= "capitalizeMe(this);";
335 else if (strpos($frow['edit_options'], 'U') !== FALSE)
336 $tmp .= "this.value = this.value.toUpperCase();";
337 if ($tmp) echo " onchange='$tmp'";
338 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
339 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
340 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
341 echo " onblur='maskblur(this,\"$tmp\")'";
343 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
344 echo " readonly";
346 if ($disabled) echo ' disabled';
347 echo " />";
350 // long or multi-line text field
351 else if ($data_type == 3) {
352 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
353 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
354 echo "<textarea" .
355 " name='form_$field_id_esc'" .
356 " id='form_$field_id_esc'" .
357 " title='$description'" .
358 " cols='$textCols'" .
359 " rows='$textRows' $lbfonchange $disabled" .
360 ">" . $currescaped . "</textarea>";
363 // date
364 else if ($data_type == 4) {
365 $age_asof_date = ''; // optionalAge() sets this
366 $age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0;
367 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
368 if ($agestr) {
369 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
372 $onchange_string = '';
373 if (!$disabled && $agestr) {
374 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format)\"";
377 echo "<input type='text' size='10' class='datepicker' name='form_$field_id_esc' id='form_$field_id_esc'" .
378 " value='" . substr($currescaped, 0, 10) . "'";
379 if (!$agestr) echo " title='$description'";
380 echo " $onchange_string $lbfonchange $disabled />";
382 // Optional display of age or gestational age.
383 if ($agestr) {
384 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
388 // provider list, local providers only
389 else if ($data_type == 10) {
390 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
391 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
392 "AND authorized = 1 " .
393 "ORDER BY lname, fname");
394 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
395 echo "<option value=''>" . xlt($empty_title) . "</option>";
396 $got_selected = false;
397 while ($urow = sqlFetchArray($ures)) {
398 $uname = text($urow['fname'] . ' ' . $urow['lname']);
399 $optionId = attr($urow['id']);
400 echo "<option value='$optionId'";
401 if ($urow['id'] == $currvalue) {
402 echo " selected";
403 $got_selected = true;
405 echo ">$uname</option>";
407 if (!$got_selected && $currvalue) {
408 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
409 echo "</select>";
410 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
412 else {
413 echo "</select>";
417 // provider list, including address book entries with an NPI number
418 else if ($data_type == 11) {
419 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
420 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
421 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
422 "ORDER BY lname, fname");
423 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
424 echo " $lbfonchange $disabled>";
425 echo "<option value=''>" . xlt('Unassigned') . "</option>";
426 $got_selected = false;
427 while ($urow = sqlFetchArray($ures)) {
428 $uname = text($urow['fname'] . ' ' . $urow['lname']);
429 $optionId = attr($urow['id']);
430 echo "<option value='$optionId'";
431 if ($urow['id'] == $currvalue) {
432 echo " selected";
433 $got_selected = true;
435 echo ">$uname</option>";
437 if (!$got_selected && $currvalue) {
438 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
439 echo "</select>";
440 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
442 else {
443 echo "</select>";
447 // pharmacy list
448 else if ($data_type == 12) {
449 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
450 echo " $lbfonchange $disabled>";
451 echo "<option value='0'></option>";
452 $pres = get_pharmacies();
453 $got_selected = false;
454 while ($prow = sqlFetchArray($pres)) {
455 $key = $prow['id'];
456 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
457 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
458 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
459 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
460 echo "<option value='$optionValue'";
461 if ($currvalue == $key) {
462 echo " selected";
463 $got_selected = true;
465 echo ">$optionLabel</option>";
467 if (!$got_selected && $currvalue) {
468 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
469 echo "</select>";
470 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
472 else {
473 echo "</select>";
477 // squads
478 else if ($data_type == 13) {
479 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
480 echo " $lbfonchange $disabled>";
481 echo "<option value=''>&nbsp;</option>";
482 $squads = acl_get_squads();
483 if ($squads) {
484 foreach ($squads as $key => $value) {
485 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
486 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
487 echo "<option value='$optionValue'";
488 if ($currvalue == $key) echo " selected";
489 echo ">$optionLabel</option>\n";
492 echo "</select>";
495 // Address book, preferring organization name if it exists and is not in
496 // parentheses, and excluding local users who are not providers.
497 // Supports "referred to" practitioners and facilities.
498 // Alternatively the letter L in edit_options means that abook_type
499 // must be "ord_lab", indicating types used with the procedure
500 // lab ordering system.
501 // Alternatively the letter O in edit_options means that abook_type
502 // must begin with "ord_", indicating types used with the procedure
503 // ordering system.
504 // Alternatively the letter V in edit_options means that abook_type
505 // must be "vendor", indicating the Vendor type.
506 // Alternatively the letter R in edit_options means that abook_type
507 // must be "dist", indicating the Distributor type.
508 else if ($data_type == 14) {
509 if (strpos($frow['edit_options'], 'L') !== FALSE)
510 $tmp = "abook_type = 'ord_lab'";
511 else if (strpos($frow['edit_options'], 'O') !== FALSE)
512 $tmp = "abook_type LIKE 'ord\\_%'";
513 else if (strpos($frow['edit_options'], 'V') !== FALSE)
514 $tmp = "abook_type LIKE 'vendor%'";
515 else if (strpos($frow['edit_options'], 'R') !== FALSE)
516 $tmp = "abook_type LIKE 'dist'";
517 else
518 $tmp = "( username = '' OR authorized = 1 )";
519 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
520 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
521 "AND $tmp " .
522 "ORDER BY organization, lname, fname");
523 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
524 echo " $lbfonchange $disabled>";
525 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
526 while ($urow = sqlFetchArray($ures)) {
527 $uname = $urow['organization'];
528 if (empty($uname) || substr($uname, 0, 1) == '(') {
529 $uname = $urow['lname'];
530 if ($urow['fname']) $uname .= ", " . $urow['fname'];
532 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
533 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
534 echo "<option value='$optionValue'";
535 $title = $urow['username'] ? xl('Local') : xl('External');
536 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
537 echo " title='$optionTitle'";
538 if ($urow['id'] == $currvalue) echo " selected";
539 echo ">$optionLabel</option>";
541 echo "</select>";
544 // A billing code. If description matches an existing code type then that type is used.
545 else if ($data_type == 15) {
546 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
547 $maxlength = $frow['max_length'];
548 $string_maxlength = "";
549 // if max_length is set to zero, then do not set a maxlength
550 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
552 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
553 // Option "2" generates a hidden input for the codes, and a matching visible field
554 // displaying their descriptions. First step is computing the description string.
555 $currdescstring = '';
556 if (!empty($currvalue)) {
557 $relcodes = explode(';', $currvalue);
558 foreach ($relcodes as $codestring) {
559 if ($codestring === '') continue;
560 $code_text = lookup_code_descriptions($codestring);
561 if ($currdescstring !== '') $currdescstring .= '; ';
562 if (!empty($code_text)) {
563 $currdescstring .= $code_text;
565 else {
566 $currdescstring .= $codestring;
570 $currdescstring = attr($currdescstring);
572 echo "<input type='text'" .
573 " name='form_$field_id_esc'" .
574 " id='form_related_code'" .
575 " size='$fldlength'" .
576 " value='$currescaped'" .
577 " style='display:none'" .
578 " $lbfonchange readonly $disabled />";
579 // Extra readonly input field for optional display of code description(s).
580 echo "<input type='text'" .
581 " name='form_$field_id_esc" . "__desc'" .
582 " size='$fldlength'" .
583 " title='$description'" .
584 " value='$currdescstring'";
585 if (!$disabled) {
586 echo " onclick='sel_related(this,\"$codetype\")'";
588 echo " readonly $disabled />";
590 else {
591 echo "<input type='text'" .
592 " name='form_$field_id_esc'" .
593 " id='form_related_code'" .
594 " size='$fldlength'" .
595 " $string_maxlength" .
596 " title='$description'" .
597 " value='$currescaped'";
598 if (!$disabled) {
599 echo " onclick='sel_related(this,\"$codetype\")'";
601 echo " $lbfonchange readonly $disabled />";
605 // insurance company list
606 else if ($data_type == 16) {
607 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
608 echo "<option value='0'></option>";
609 $insprovs = getInsuranceProviders();
610 $got_selected = false;
611 foreach ($insprovs as $key => $ipname) {
612 $optionValue = htmlspecialchars($key, ENT_QUOTES);
613 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
614 echo "<option value='$optionValue'";
615 if ($currvalue == $key) {
616 echo " selected";
617 $got_selected = true;
619 echo ">$optionLabel</option>";
621 if (!$got_selected && $currvalue) {
622 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
623 echo "</select>";
624 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
626 else {
627 echo "</select>";
631 // issue types
632 else if ($data_type == 17) {
633 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
634 echo "<option value='0'></option>";
635 $got_selected = false;
636 foreach ($ISSUE_TYPES as $key => $value) {
637 $optionValue = htmlspecialchars($key, ENT_QUOTES);
638 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
639 echo "<option value='$optionValue'";
640 if ($currvalue == $key) {
641 echo " selected";
642 $got_selected = true;
644 echo ">$optionLabel</option>";
646 if (!$got_selected && strlen($currvalue) > 0) {
647 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
648 echo "</select>";
649 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
651 else {
652 echo "</select>";
656 // Visit categories.
657 else if ($data_type == 18) {
658 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
659 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
660 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
661 " $lbfonchange $disabled>";
662 echo "<option value=''>" . xlt($empty_title) . "</option>";
663 $got_selected = false;
664 while ($crow = sqlFetchArray($cres)) {
665 $catid = $crow['pc_catid'];
666 if (($catid < 9 && $catid != 5) || $catid == 11) continue;
667 echo "<option value='" . attr($catid) . "'";
668 if ($catid == $currvalue) {
669 echo " selected";
670 $got_selected = true;
672 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
674 if (!$got_selected && $currvalue) {
675 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
676 echo "</select>";
677 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
679 else {
680 echo "</select>";
684 // a set of labeled checkboxes
685 else if ($data_type == 21) {
686 // In this special case, fld_length is the number of columns generated.
687 $cols = max(1, $frow['fld_length']);
688 $avalue = explode('|', $currvalue);
689 $lres = sqlStatement("SELECT * FROM list_options " .
690 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
691 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
692 $tdpct = (int) (100 / $cols);
693 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
694 $option_id = $lrow['option_id'];
695 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
696 // if ($count) echo "<br />";
697 if ($count % $cols == 0) {
698 if ($count) echo "</tr>";
699 echo "<tr>";
701 echo "<td width='$tdpct%'>";
702 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
703 "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
704 if (in_array($option_id, $avalue)) echo " checked";
706 // Added 5-09 by BM - Translate label if applicable
707 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
709 echo "</td>";
711 if ($count) {
712 echo "</tr>";
713 if ($count > $cols) {
714 // Add some space after multiple rows of checkboxes.
715 $cols = htmlspecialchars( $cols, ENT_QUOTES);
716 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
719 echo "</table>";
722 // a set of labeled text input fields
723 else if ($data_type == 22) {
724 $tmp = explode('|', $currvalue);
725 $avalue = array();
726 foreach ($tmp as $value) {
727 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
728 $avalue[$matches[1]] = $matches[2];
731 $lres = sqlStatement("SELECT * FROM list_options " .
732 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
733 echo "<table cellpadding='0' cellspacing='0'>";
734 while ($lrow = sqlFetchArray($lres)) {
735 $option_id = $lrow['option_id'];
736 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
737 $maxlength = $frow['max_length'];
738 $string_maxlength = "";
739 // if max_length is set to zero, then do not set a maxlength
740 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
741 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
743 // Added 5-09 by BM - Translate label if applicable
744 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
745 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
746 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
747 echo "<td><input type='text'" .
748 " name='form_{$field_id_esc}[$option_id_esc]'" .
749 " id='form_{$field_id_esc}[$option_id_esc]'" .
750 " size='$fldlength'" .
751 " $string_maxlength" .
752 " value='$optionValue'";
753 echo " $lbfonchange $disabled /></td></tr>";
755 echo "</table>";
758 // a set of exam results; 3 radio buttons and a text field:
759 else if ($data_type == 23) {
760 $tmp = explode('|', $currvalue);
761 $avalue = array();
762 foreach ($tmp as $value) {
763 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
764 $avalue[$matches[1]] = $matches[2];
767 $maxlength = $frow['max_length'];
768 $string_maxlength = "";
769 // if max_length is set to zero, then do not set a maxlength
770 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
771 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
772 $lres = sqlStatement("SELECT * FROM list_options " .
773 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
774 echo "<table cellpadding='0' cellspacing='0'>";
775 echo "<tr><td>&nbsp;</td><td class='bold'>" .
776 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
777 "&nbsp;</td><td class='bold'>" .
778 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
779 "<td class='bold'>" .
780 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
781 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
782 while ($lrow = sqlFetchArray($lres)) {
783 $option_id = $lrow['option_id'];
784 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
785 $restype = substr($avalue[$option_id], 0, 1);
786 $resnote = substr($avalue[$option_id], 2);
788 // Added 5-09 by BM - Translate label if applicable
789 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
791 for ($i = 0; $i < 3; ++$i) {
792 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
793 echo "<td><input type='radio'" .
794 " name='radio_{$field_id_esc}[$option_id_esc]'" .
795 " id='radio_{$field_id_esc}[$option_id_esc]'" .
796 " value='$inputValue' $lbfonchange";
797 if ($restype === "$i") echo " checked";
798 echo " $disabled /></td>";
800 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
801 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
802 echo "<td><input type='text'" .
803 " name='form_{$field_id_esc}[$option_id_esc]'" .
804 " id='form_{$field_id_esc}[$option_id_esc]'" .
805 " size='$fldlength'" .
806 " $string_maxlength" .
807 " value='$resnote' $disabled /></td>";
808 echo "</tr>";
810 echo "</table>";
813 // the list of active allergies for the current patient
814 // this is read-only!
815 else if ($data_type == 24) {
816 $query = "SELECT title, comments FROM lists WHERE " .
817 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
818 "ORDER BY begdate";
819 // echo "<!-- $query -->\n"; // debugging
820 $lres = sqlStatement($query, array($GLOBALS['pid']));
821 $count = 0;
822 while ($lrow = sqlFetchArray($lres)) {
823 if ($count++) echo "<br />";
824 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
825 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
829 // a set of labeled checkboxes, each with a text field:
830 else if ($data_type == 25) {
831 $tmp = explode('|', $currvalue);
832 $avalue = array();
833 foreach ($tmp as $value) {
834 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
835 $avalue[$matches[1]] = $matches[2];
838 $maxlength = $frow['max_length'];
839 $string_maxlength = "";
840 // if max_length is set to zero, then do not set a maxlength
841 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
842 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
843 $lres = sqlStatement("SELECT * FROM list_options " .
844 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
845 echo "<table cellpadding='0' cellspacing='0'>";
846 while ($lrow = sqlFetchArray($lres)) {
847 $option_id = $lrow['option_id'];
848 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
849 $restype = substr($avalue[$option_id], 0, 1);
850 $resnote = substr($avalue[$option_id], 2);
852 // Added 5-09 by BM - Translate label if applicable
853 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
855 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
856 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
857 " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
858 if ($restype) echo " checked";
859 echo " $disabled />&nbsp;</td>";
860 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
861 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
862 echo "<td><input type='text'" .
863 " name='form_{$field_id_esc}[$option_id_esc]'" .
864 " id='form_{$field_id_esc}[$option_id_esc]'" .
865 " size='$fldlength'" .
866 " $string_maxlength" .
867 " value='$resnote' $disabled /></td>";
868 echo "</tr>";
870 echo "</table>";
873 // single-selection list with ability to add to it
874 else if ($data_type == 26) {
875 echo generate_select_list("form_$field_id", $list_id, $currvalue,
876 $description, ($showEmpty ? $empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
877 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
878 // show the add button if user has access to correct list
879 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
880 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
881 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
882 if (aco_exist('lists', $list_id)) {
883 // a specific aco exist for this list, so ensure access
884 if (acl_check('lists', $list_id)) echo $outputAddButton;
886 else {
887 // no specific aco exist for this list, so check for access to 'default' list
888 if (acl_check('lists', 'default')) echo $outputAddButton;
892 // a set of labeled radio buttons
893 else if ($data_type == 27) {
894 // In this special case, fld_length is the number of columns generated.
895 $cols = max(1, $frow['fld_length']);
896 $lres = sqlStatement("SELECT * FROM list_options " .
897 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
898 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
899 $tdpct = (int) (100 / $cols);
900 $got_selected = FALSE;
901 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
902 $option_id = $lrow['option_id'];
903 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
904 if ($count % $cols == 0) {
905 if ($count) echo "</tr>";
906 echo "<tr>";
908 echo "<td width='$tdpct%'>";
909 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
910 " value='$option_id_esc' $lbfonchange";
911 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
912 (strlen($currvalue) > 0 && $option_id == $currvalue))
914 echo " checked";
915 $got_selected = TRUE;
917 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
918 echo "</td>";
920 if ($count) {
921 echo "</tr>";
922 if ($count > $cols) {
923 // Add some space after multiple rows of radio buttons.
924 $cols = htmlspecialchars($cols, ENT_QUOTES);
925 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
928 echo "</table>";
929 if (!$got_selected && strlen($currvalue) > 0) {
930 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
931 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
932 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
936 // special case for history of lifestyle status; 3 radio buttons and a date text field:
937 // VicarePlus :: A selection list box for smoking status:
938 else if ($data_type == 28 || $data_type == 32) {
939 $tmp = explode('|', $currvalue);
940 switch(count($tmp)) {
941 case "4": {
942 $resnote = $tmp[0];
943 $restype = $tmp[1];
944 $resdate = $tmp[2];
945 $reslist = $tmp[3];
946 } break;
947 case "3": {
948 $resnote = $tmp[0];
949 $restype = $tmp[1];
950 $resdate = $tmp[2];
951 } break;
952 case "2": {
953 $resnote = $tmp[0];
954 $restype = $tmp[1];
955 $resdate = "";
956 } break;
957 case "1": {
958 $resnote = $tmp[0];
959 $resdate = $restype = "";
960 } break;
961 default: {
962 $restype = $resdate = $resnote = "";
963 } break;
965 $maxlength = $frow['max_length'];
966 $string_maxlength = "";
967 // if max_length is set to zero, then do not set a maxlength
968 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
969 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
971 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
972 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
973 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
974 echo "<table cellpadding='0' cellspacing='0'>";
975 echo "<tr>";
976 if ($data_type == 28)
978 // input text
979 echo "<td><input type='text'" .
980 " name='form_$field_id_esc'" .
981 " id='form_$field_id_esc'" .
982 " size='$fldlength'" .
983 " $string_maxlength" .
984 " value='$resnote' $disabled />&nbsp;</td>";
985 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
986 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
987 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
989 else if($data_type == 32)
991 // input text
992 echo "<tr><td><input type='text'" .
993 " name='form_text_$field_id_esc'" .
994 " id='form_text_$field_id_esc'" .
995 " size='$fldlength'" .
996 " $string_maxlength" .
997 " value='$resnote' $disabled />&nbsp;</td></tr>";
998 echo "<td>";
999 //Selection list for smoking status
1000 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1001 echo generate_select_list("form_$field_id", $list_id, $reslist,
1002 $description, ($showEmpty ? $empty_title : ''), '', $onchange, '',
1003 ($disabled ? array('disabled' => 'disabled') : null));
1004 echo "</td>";
1005 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1007 // current
1008 echo "<td class='text' ><input type='radio'" .
1009 " name='radio_{$field_id_esc}'" .
1010 " id='radio_{$field_id_esc}[current]'" .
1011 " value='current" . $field_id_esc . "' $lbfonchange";
1012 if ($restype == "current" . $field_id) echo " checked";
1013 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1014 echo " />" . xlt('Current') . "&nbsp;</td>";
1015 // quit
1016 echo "<td class='text'><input type='radio'" .
1017 " name='radio_{$field_id_esc}'" .
1018 " id='radio_{$field_id_esc}[quit]'" .
1019 " value='quit".$field_id_esc."' $lbfonchange";
1020 if ($restype == "quit" . $field_id) echo " checked";
1021 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1022 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1023 // quit date
1024 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1025 " value='$resdate'" .
1026 " title='$description'" .
1027 " $disabled />";
1028 echo "&nbsp;</td>";
1029 // never
1030 echo "<td class='text'><input type='radio'" .
1031 " name='radio_{$field_id_esc}'" .
1032 " id='radio_{$field_id_esc}[never]'" .
1033 " value='never" . $field_id_esc . "' $lbfonchange";
1034 if ($restype == "never" . $field_id) echo " checked";
1035 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1036 echo " />" . xlt('Never') . "&nbsp;</td>";
1037 // Not Applicable
1038 echo "<td class='text'><input type='radio'" .
1039 " name='radio_{$field_id}'" .
1040 " id='radio_{$field_id}[not_applicable]'" .
1041 " value='not_applicable" . $field_id . "' $lbfonchange";
1042 if ($restype == "not_applicable" . $field_id) echo " checked";
1043 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1044 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1046 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1047 echo "<td class='text' ><div id='smoke_code'></div></td>";
1048 echo "</tr>";
1049 echo "</table>";
1052 // static text. read-only, of course.
1053 else if ($data_type == 31) {
1054 echo nl2br($frow['description']);
1057 //$data_type == 33
1058 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1059 //$data_type == 33
1061 else if($data_type == 34){
1062 $arr = explode("|*|*|*|",$currvalue);
1063 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;'>";
1064 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
1065 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1066 echo "</a>";
1069 //facilities drop-down list
1070 else if ($data_type == 35) {
1071 if (empty($currvalue)){
1072 $currvalue = 0;
1074 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1075 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1078 //multiple select
1079 // supports backup list
1080 else if ($data_type == 36) {
1081 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1082 $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);
1086 // Canvas and related elements for browser-side image drawing.
1087 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1088 else if ($data_type == 40) {
1089 // Unlike other field types, width and height are in pixels.
1090 $canWidth = intval($frow['fld_length']);
1091 $canHeight = intval($frow['fld_rows']);
1092 if (empty($currvalue)) {
1093 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1094 // If defined this is the filename of the default starting image.
1095 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1098 $mywidth = 50 + ($canWidth > 250 ? $canWidth : 250);
1099 $myheight = 31 + ($canHeight > 261 ? $canHeight : 261);
1100 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1101 // Hidden form field exists to send updated data to the server at submit time.
1102 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1103 // Hidden image exists to support initialization of the canvas.
1104 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1105 // $date_init is a misnomer but it's the place for browser-side setup logic.
1106 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1111 function generate_print_field($frow, $currvalue) {
1112 global $rootdir, $date_init, $ISSUE_TYPES;
1114 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1116 $data_type = $frow['data_type'];
1117 $field_id = $frow['field_id'];
1118 $list_id = $frow['list_id'];
1119 $fld_length = $frow['fld_length'];
1120 $backup_list = $frow['list_backup_id'];
1122 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1124 // Can pass $frow['empty_title'] with this variable, otherwise
1125 // will default to 'Unassigned'.
1126 // If it is 'SKIP' then an empty text title is completely skipped.
1127 $showEmpty = true;
1128 if (isset($frow['empty_title'])) {
1129 if ($frow['empty_title'] == "SKIP") {
1130 //do not display an 'empty' choice
1131 $showEmpty = false;
1132 $empty_title = "Unassigned";
1134 else {
1135 $empty_title = $frow['empty_title'];
1138 else {
1139 $empty_title = "Unassigned";
1142 // generic single-selection list
1143 // Supports backup lists.
1144 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
1145 if (empty($fld_length)) {
1146 if ($list_id == 'titles') {
1147 $fld_length = 3;
1148 } else {
1149 $fld_length = 10;
1152 $tmp = '';
1153 if ($currvalue) {
1154 $lrow = sqlQuery("SELECT title FROM list_options " .
1155 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1156 $tmp = xl_list_label($lrow['title']);
1157 if ($lrow == 0 && !empty($backup_list)) {
1158 // since primary list did not map, try to map to backup list
1159 $lrow = sqlQuery("SELECT title FROM list_options " .
1160 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1161 $tmp = xl_list_label($lrow['title']);
1163 if (empty($tmp)) $tmp = "($currvalue)";
1165 /*****************************************************************
1166 echo "<input type='text'" .
1167 " size='$fld_length'" .
1168 " value='$tmp'" .
1169 " class='under'" .
1170 " />";
1171 *****************************************************************/
1172 if ($tmp === '') {
1173 $tmp = '&nbsp;';
1175 else {
1176 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1178 echo $tmp;
1181 // simple text field
1182 else if ($data_type == 2 || $data_type == 15) {
1183 /*****************************************************************
1184 echo "<input type='text'" .
1185 " size='$fld_length'" .
1186 " value='$currescaped'" .
1187 " class='under'" .
1188 " />";
1189 *****************************************************************/
1190 if ($currescaped === '') $currescaped = '&nbsp;';
1191 echo $currescaped;
1194 // long or multi-line text field
1195 else if ($data_type == 3) {
1196 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
1197 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
1198 echo "<textarea" .
1199 " cols='$fldlength'" .
1200 " rows='$maxlength'>" .
1201 $currescaped . "</textarea>";
1204 // date
1205 else if ($data_type == 4) {
1206 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1207 $agestr = optionalAge($frow, $currvalue,$asof);
1208 if ($agestr) {
1209 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1211 if ($currvalue === '') {
1212 echo '&nbsp;';
1214 else {
1215 echo text(oeFormatShortDate($currvalue));
1217 // Optional display of age or gestational age.
1218 if ($agestr) {
1219 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1223 // provider list
1224 else if ($data_type == 10 || $data_type == 11) {
1225 $tmp = '';
1226 if ($currvalue) {
1227 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1228 "WHERE id = ?", array($currvalue) );
1229 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1230 if (empty($tmp)) $tmp = "($currvalue)";
1232 /*****************************************************************
1233 echo "<input type='text'" .
1234 " size='$fld_length'" .
1235 " value='$tmp'" .
1236 " class='under'" .
1237 " />";
1238 *****************************************************************/
1239 if ($tmp === '') { $tmp = '&nbsp;'; }
1240 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1241 echo $tmp;
1244 // pharmacy list
1245 else if ($data_type == 12) {
1246 $tmp = '';
1247 if ($currvalue) {
1248 $pres = get_pharmacies();
1249 while ($prow = sqlFetchArray($pres)) {
1250 $key = $prow['id'];
1251 if ($currvalue == $key) {
1252 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1253 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1254 $prow['line1'] . ' / ' . $prow['city'];
1257 if (empty($tmp)) $tmp = "($currvalue)";
1259 /*****************************************************************
1260 echo "<input type='text'" .
1261 " size='$fld_length'" .
1262 " value='$tmp'" .
1263 " class='under'" .
1264 " />";
1265 *****************************************************************/
1266 if ($tmp === '') { $tmp = '&nbsp;'; }
1267 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1268 echo $tmp;
1271 // squads
1272 else if ($data_type == 13) {
1273 $tmp = '';
1274 if ($currvalue) {
1275 $squads = acl_get_squads();
1276 if ($squads) {
1277 foreach ($squads as $key => $value) {
1278 if ($currvalue == $key) {
1279 $tmp = $value[3];
1283 if (empty($tmp)) $tmp = "($currvalue)";
1285 /*****************************************************************
1286 echo "<input type='text'" .
1287 " size='$fld_length'" .
1288 " value='$tmp'" .
1289 " class='under'" .
1290 " />";
1291 *****************************************************************/
1292 if ($tmp === '') { $tmp = '&nbsp;'; }
1293 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1294 echo $tmp;
1297 // Address book.
1298 else if ($data_type == 14) {
1299 $tmp = '';
1300 if ($currvalue) {
1301 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1302 "WHERE id = ?", array($currvalue) );
1303 $uname = $urow['lname'];
1304 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1305 $tmp = $uname;
1306 if (empty($tmp)) $tmp = "($currvalue)";
1308 /*****************************************************************
1309 echo "<input type='text'" .
1310 " size='$fld_length'" .
1311 " value='$tmp'" .
1312 " class='under'" .
1313 " />";
1314 *****************************************************************/
1315 if ($tmp === '') { $tmp = '&nbsp;'; }
1316 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1317 echo $tmp;
1320 // insurance company list
1321 else if ($data_type == 16) {
1322 $tmp = '';
1323 if ($currvalue) {
1324 $insprovs = getInsuranceProviders();
1325 foreach ($insprovs as $key => $ipname) {
1326 if ($currvalue == $key) {
1327 $tmp = $ipname;
1330 if (empty($tmp)) $tmp = "($currvalue)";
1332 if ($tmp === '') $tmp = '&nbsp;';
1333 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1334 echo $tmp;
1337 // issue types
1338 else if ($data_type == 17) {
1339 $tmp = '';
1340 if ($currvalue) {
1341 foreach ($ISSUE_TYPES as $key => $value) {
1342 if ($currvalue == $key) {
1343 $tmp = $value[1];
1346 if (empty($tmp)) $tmp = "($currvalue)";
1348 if ($tmp === '') $tmp = '&nbsp;';
1349 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1350 echo $tmp;
1353 // Visit categories.
1354 else if ($data_type == 18) {
1355 $tmp = '';
1356 if ($currvalue) {
1357 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1358 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1359 array($currvalue));
1360 $tmp = xl_appt_category($crow['pc_catname']);
1361 if (empty($tmp)) $tmp = "($currvalue)";
1363 if ($tmp === '') { $tmp = '&nbsp;'; }
1364 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES); }
1365 echo $tmp;
1368 // a set of labeled checkboxes
1369 else if ($data_type == 21) {
1370 // In this special case, fld_length is the number of columns generated.
1371 $cols = max(1, $fld_length);
1372 $avalue = explode('|', $currvalue);
1373 $lres = sqlStatement("SELECT * FROM list_options " .
1374 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1375 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1376 $tdpct = (int) (100 / $cols);
1377 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1378 $option_id = $lrow['option_id'];
1379 if ($count % $cols == 0) {
1380 if ($count) echo "</tr>";
1381 echo "<tr>";
1383 echo "<td width='$tdpct%'>";
1384 echo "<input type='checkbox'";
1385 if (in_array($option_id, $avalue)) echo " checked";
1386 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1387 echo "</td>";
1389 if ($count) {
1390 echo "</tr>";
1391 if ($count > $cols) {
1392 // Add some space after multiple rows of checkboxes.
1393 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1394 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1397 echo "</table>";
1400 // a set of labeled text input fields
1401 else if ($data_type == 22) {
1402 $tmp = explode('|', $currvalue);
1403 $avalue = array();
1404 foreach ($tmp as $value) {
1405 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1406 $avalue[$matches[1]] = $matches[2];
1409 $lres = sqlStatement("SELECT * FROM list_options " .
1410 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1411 echo "<table cellpadding='0' cellspacing='0'>";
1412 while ($lrow = sqlFetchArray($lres)) {
1413 $option_id = $lrow['option_id'];
1414 $fldlength = empty($fld_length) ? 20 : $fld_length;
1415 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1416 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1417 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1418 echo "<td><input type='text'" .
1419 " size='$fldlength'" .
1420 " value='$inputValue'" .
1421 " class='under'" .
1422 " /></td></tr>";
1424 echo "</table>";
1427 // a set of exam results; 3 radio buttons and a text field:
1428 else if ($data_type == 23) {
1429 $tmp = explode('|', $currvalue);
1430 $avalue = array();
1431 foreach ($tmp as $value) {
1432 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1433 $avalue[$matches[1]] = $matches[2];
1436 $fldlength = empty($fld_length) ? 20 : $fld_length;
1437 $lres = sqlStatement("SELECT * FROM list_options " .
1438 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1439 echo "<table cellpadding='0' cellspacing='0'>";
1440 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1441 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1442 "&nbsp;</td><td class='bold'>" .
1443 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1444 "<td class='bold'>" .
1445 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1446 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1447 while ($lrow = sqlFetchArray($lres)) {
1448 $option_id = $lrow['option_id'];
1449 $restype = substr($avalue[$option_id], 0, 1);
1450 $resnote = substr($avalue[$option_id], 2);
1451 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1452 for ($i = 0; $i < 3; ++$i) {
1453 echo "<td><input type='radio'";
1454 if ($restype === "$i") echo " checked";
1455 echo " /></td>";
1457 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1458 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1459 echo "<td><input type='text'" .
1460 " size='$fldlength'" .
1461 " value='$resnote'" .
1462 " class='under' /></td>" .
1463 "</tr>";
1465 echo "</table>";
1468 // the list of active allergies for the current patient
1469 // this is read-only!
1470 else if ($data_type == 24) {
1471 $query = "SELECT title, comments FROM lists WHERE " .
1472 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1473 "ORDER BY begdate";
1474 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1475 $count = 0;
1476 while ($lrow = sqlFetchArray($lres)) {
1477 if ($count++) echo "<br />";
1478 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1479 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1483 // a set of labeled checkboxes, each with a text field:
1484 else if ($data_type == 25) {
1485 $tmp = explode('|', $currvalue);
1486 $avalue = array();
1487 foreach ($tmp as $value) {
1488 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1489 $avalue[$matches[1]] = $matches[2];
1492 $fldlength = empty($fld_length) ? 20 : $fld_length;
1493 $lres = sqlStatement("SELECT * FROM list_options " .
1494 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1495 echo "<table cellpadding='0' cellspacing='0'>";
1496 while ($lrow = sqlFetchArray($lres)) {
1497 $option_id = $lrow['option_id'];
1498 $restype = substr($avalue[$option_id], 0, 1);
1499 $resnote = substr($avalue[$option_id], 2);
1500 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1501 echo "<td><input type='checkbox'";
1502 if ($restype) echo " checked";
1503 echo " />&nbsp;</td>";
1504 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1505 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1506 echo "<td><input type='text'" .
1507 " size='$fldlength'" .
1508 " value='$resnote'" .
1509 " class='under'" .
1510 " /></td>" .
1511 "</tr>";
1513 echo "</table>";
1516 // a set of labeled radio buttons
1517 else if ($data_type == 27) {
1518 // In this special case, fld_length is the number of columns generated.
1519 $cols = max(1, $frow['fld_length']);
1520 $lres = sqlStatement("SELECT * FROM list_options " .
1521 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1522 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1523 $tdpct = (int) (100 / $cols);
1524 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1525 $option_id = $lrow['option_id'];
1526 if ($count % $cols == 0) {
1527 if ($count) echo "</tr>";
1528 echo "<tr>";
1530 echo "<td width='$tdpct%'>";
1531 echo "<input type='radio'";
1532 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1533 (strlen($currvalue) > 0 && $option_id == $currvalue))
1535 echo " checked";
1537 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1538 echo "</td>";
1540 if ($count) {
1541 echo "</tr>";
1542 if ($count > $cols) {
1543 // Add some space after multiple rows of radio buttons.
1544 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1545 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1548 echo "</table>";
1551 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1552 else if ($data_type == 28 || $data_type == 32) {
1553 $tmp = explode('|', $currvalue);
1554 switch(count($tmp)) {
1555 case "4": {
1556 $resnote = $tmp[0];
1557 $restype = $tmp[1];
1558 $resdate = $tmp[2];
1559 $reslist = $tmp[3];
1560 } break;
1561 case "3": {
1562 $resnote = $tmp[0];
1563 $restype = $tmp[1];
1564 $resdate = $tmp[2];
1565 } break;
1566 case "2": {
1567 $resnote = $tmp[0];
1568 $restype = $tmp[1];
1569 $resdate = "";
1570 } break;
1571 case "1": {
1572 $resnote = $tmp[0];
1573 $resdate = $restype = "";
1574 } break;
1575 default: {
1576 $restype = $resdate = $resnote = "";
1577 } break;
1579 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1580 echo "<table cellpadding='0' cellspacing='0'>";
1581 echo "<tr>";
1582 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1583 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1584 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1585 if($data_type == 28)
1587 echo "<td><input type='text'" .
1588 " size='$fldlength'" .
1589 " class='under'" .
1590 " value='$resnote' /></td>";
1591 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1592 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1593 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1595 else if($data_type == 32)
1597 echo "<tr><td><input type='text'" .
1598 " size='$fldlength'" .
1599 " class='under'" .
1600 " value='$resnote' /></td></tr>";
1601 $fldlength = 30;
1602 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1603 echo "<td><input type='text'" .
1604 " size='$fldlength'" .
1605 " class='under'" .
1606 " value='$smoking_status_title' /></td>";
1607 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1609 echo "<td><input type='radio'";
1610 if ($restype == "current".$field_id) echo " checked";
1611 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1613 echo "<td><input type='radio'";
1614 if ($restype == "current".$field_id) echo " checked";
1615 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1617 echo "<td><input type='text' size='6'" .
1618 " value='$resdate'" .
1619 " class='under'" .
1620 " /></td>";
1622 echo "<td><input type='radio'";
1623 if ($restype == "current".$field_id) echo " checked";
1624 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1626 echo "<td><input type='radio'";
1627 if ($restype == "not_applicable".$field_id) echo " checked";
1628 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1629 echo "</tr>";
1630 echo "</table>";
1633 // static text. read-only, of course.
1634 else if ($data_type == 31) {
1635 echo nl2br($frow['description']);
1638 else if($data_type == 34){
1639 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;'>";
1640 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1641 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1642 echo "</a>";
1645 //facilities drop-down list
1646 else if ($data_type == 35) {
1647 if (empty($currvalue)){
1648 $currvalue = 0;
1650 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1653 //Multi-select
1654 // Supports backup lists.
1655 else if ($data_type == 36) {
1656 if (empty($fld_length)) {
1657 if ($list_id == 'titles') {
1658 $fld_length = 3;
1659 } else {
1660 $fld_length = 10;
1663 $tmp = '';
1665 $values_array = explode("|", $currvalue);
1667 $i=0;
1668 foreach($values_array as $value) {
1669 if ($value) {
1670 $lrow = sqlQuery("SELECT title FROM list_options " .
1671 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1672 $tmp = xl_list_label($lrow['title']);
1673 if ($lrow == 0 && !empty($backup_list)) {
1674 // since primary list did not map, try to map to backup list
1675 $lrow = sqlQuery("SELECT title FROM list_options " .
1676 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1677 $tmp = xl_list_label($lrow['title']);
1679 if (empty($tmp)) $tmp = "($value)";
1682 if ($tmp === '') {
1683 $tmp = '&nbsp;';
1685 else {
1686 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1688 if ($i != 0 && $tmp != '&nbsp;') echo ",";
1689 echo $tmp;
1690 $i++;
1694 // Image from canvas drawing
1695 else if ($data_type == 40) {
1696 echo "<img src='" . attr($currvalue) . "'>";
1701 function generate_display_field($frow, $currvalue) {
1702 global $ISSUE_TYPES;
1704 $data_type = $frow['data_type'];
1705 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1706 $list_id = $frow['list_id'];
1707 $backup_list = isset($frow['list_backup_id']) ? $frow['list_backup_id'] : null;
1709 $s = '';
1711 // generic selection list or the generic selection list with add on the fly
1712 // feature, or radio buttons
1713 // Supports backup lists for datatypes 1,26,33
1714 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1715 $lrow = sqlQuery("SELECT title FROM list_options " .
1716 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
1717 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1718 //if there is no matching value in the corresponding lists check backup list
1719 // only supported in data types 1,26,33
1720 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1721 $lrow = sqlQuery("SELECT title FROM list_options " .
1722 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
1723 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1727 // simple text field
1728 else if ($data_type == 2) {
1729 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1732 // long or multi-line text field
1733 else if ($data_type == 3) {
1734 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1737 // date
1738 else if ($data_type == 4) {
1739 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1740 $s = '';
1741 $agestr = optionalAge($frow, $currvalue, $asof);
1742 if ($agestr) {
1743 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1745 if ($currvalue === '') {
1746 $s .= '&nbsp;';
1748 else {
1749 $s .= text(oeFormatShortDate($currvalue));
1751 // Optional display of age or gestational age.
1752 if ($agestr) {
1753 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1757 // provider
1758 else if ($data_type == 10 || $data_type == 11) {
1759 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1760 "WHERE id = ?", array($currvalue) );
1761 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1764 // pharmacy list
1765 else if ($data_type == 12) {
1766 $pres = get_pharmacies();
1767 while ($prow = sqlFetchArray($pres)) {
1768 $key = $prow['id'];
1769 if ($currvalue == $key) {
1770 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1771 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1772 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1777 // squads
1778 else if ($data_type == 13) {
1779 $squads = acl_get_squads();
1780 if ($squads) {
1781 foreach ($squads as $key => $value) {
1782 if ($currvalue == $key) {
1783 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1789 // address book
1790 else if ($data_type == 14) {
1791 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
1792 "WHERE id = ?", array($currvalue));
1793 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
1794 if($urow['organization'] !=""){
1795 $uname = $urow['organization'];
1796 }else{
1797 $uname = $urow['lname'];
1798 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1800 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1803 // billing code
1804 else if ($data_type == 15) {
1805 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1808 // insurance company list
1809 else if ($data_type == 16) {
1810 $insprovs = getInsuranceProviders();
1811 foreach ($insprovs as $key => $ipname) {
1812 if ($currvalue == $key) {
1813 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
1818 // issue types
1819 else if ($data_type == 17) {
1820 foreach ($ISSUE_TYPES as $key => $value) {
1821 if ($currvalue == $key) {
1822 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
1827 // visit category
1828 else if ($data_type == 18) {
1829 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1830 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1831 array($currvalue));
1832 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES);
1835 // a set of labeled checkboxes
1836 else if ($data_type == 21) {
1837 $avalue = explode('|', $currvalue);
1838 $lres = sqlStatement("SELECT * FROM list_options " .
1839 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1840 $count = 0;
1841 while ($lrow = sqlFetchArray($lres)) {
1842 $option_id = $lrow['option_id'];
1843 if (in_array($option_id, $avalue)) {
1844 if ($count++) $s .= "<br />";
1846 // Added 5-09 by BM - Translate label if applicable
1847 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES);
1853 // a set of labeled text input fields
1854 else if ($data_type == 22) {
1855 $tmp = explode('|', $currvalue);
1856 $avalue = array();
1857 foreach ($tmp as $value) {
1858 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1859 $avalue[$matches[1]] = $matches[2];
1862 $lres = sqlStatement("SELECT * FROM list_options " .
1863 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1864 $s .= "<table cellpadding='0' cellspacing='0'>";
1865 while ($lrow = sqlFetchArray($lres)) {
1866 $option_id = $lrow['option_id'];
1867 if (empty($avalue[$option_id])) continue;
1869 // Added 5-09 by BM - Translate label if applicable
1870 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1872 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1874 $s .= "</table>";
1877 // a set of exam results; 3 radio buttons and a text field:
1878 else if ($data_type == 23) {
1879 $tmp = explode('|', $currvalue);
1880 $avalue = array();
1881 foreach ($tmp as $value) {
1882 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1883 $avalue[$matches[1]] = $matches[2];
1886 $lres = sqlStatement("SELECT * FROM list_options " .
1887 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1888 $s .= "<table cellpadding='0' cellspacing='0'>";
1889 while ($lrow = sqlFetchArray($lres)) {
1890 $option_id = $lrow['option_id'];
1891 $restype = substr($avalue[$option_id], 0, 1);
1892 $resnote = substr($avalue[$option_id], 2);
1893 if (empty($restype) && empty($resnote)) continue;
1895 // Added 5-09 by BM - Translate label if applicable
1896 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1898 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1899 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1900 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1901 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1902 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1903 $s .= "</tr>";
1905 $s .= "</table>";
1908 // the list of active allergies for the current patient
1909 else if ($data_type == 24) {
1910 $query = "SELECT title, comments FROM lists WHERE " .
1911 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1912 "ORDER BY begdate";
1913 // echo "<!-- $query -->\n"; // debugging
1914 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1915 $count = 0;
1916 while ($lrow = sqlFetchArray($lres)) {
1917 if ($count++) $s .= "<br />";
1918 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1919 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1923 // a set of labeled checkboxes, each with a text field:
1924 else if ($data_type == 25) {
1925 $tmp = explode('|', $currvalue);
1926 $avalue = array();
1927 foreach ($tmp as $value) {
1928 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1929 $avalue[$matches[1]] = $matches[2];
1932 $lres = sqlStatement("SELECT * FROM list_options " .
1933 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1934 $s .= "<table cellpadding='0' cellspacing='0'>";
1935 while ($lrow = sqlFetchArray($lres)) {
1936 $option_id = $lrow['option_id'];
1937 $restype = substr($avalue[$option_id], 0, 1);
1938 $resnote = substr($avalue[$option_id], 2);
1939 if (empty($restype) && empty($resnote)) continue;
1941 // Added 5-09 by BM - Translate label if applicable
1942 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1944 $restype = $restype ? xl('Yes') : xl('No');
1945 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1946 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1947 $s .= "</tr>";
1949 $s .= "</table>";
1952 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1953 // VicarePlus :: A selection list for smoking status.
1954 else if ($data_type == 28 || $data_type == 32) {
1955 $tmp = explode('|', $currvalue);
1956 switch(count($tmp)) {
1957 case "4": {
1958 $resnote = $tmp[0];
1959 $restype = $tmp[1];
1960 $resdate = $tmp[2];
1961 $reslist = $tmp[3];
1962 } break;
1963 case "3": {
1964 $resnote = $tmp[0];
1965 $restype = $tmp[1];
1966 $resdate = $tmp[2];
1967 } break;
1968 case "2": {
1969 $resnote = $tmp[0];
1970 $restype = $tmp[1];
1971 $resdate = "";
1972 } break;
1973 case "1": {
1974 $resnote = $tmp[0];
1975 $resdate = $restype = "";
1976 } break;
1977 default: {
1978 $restype = $resdate = $resnote = "";
1979 } break;
1981 $s .= "<table cellpadding='0' cellspacing='0'>";
1983 $s .= "<tr>";
1984 $res = "";
1985 if ($restype == "current".$field_id) $res = xl('Current');
1986 if ($restype == "quit".$field_id) $res = xl('Quit');
1987 if ($restype == "never".$field_id) $res = xl('Never');
1988 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1989 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1990 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1991 if ($data_type == 28)
1993 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1995 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1996 else if ($data_type == 32)
1997 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1998 $smoke_codes = getSmokeCodes();
1999 if (!empty($reslist)) {
2000 if($smoke_codes[$reslist]!="")
2001 $code_desc = "( ".$smoke_codes[$reslist]." )";
2003 $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . "&nbsp;".text($code_desc)."&nbsp;&nbsp;&nbsp;&nbsp;</td>";}
2005 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2008 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
2009 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
2010 $s .= "</tr>";
2011 $s .= "</table>";
2014 // static text. read-only, of course.
2015 else if ($data_type == 31) {
2016 $s .= nl2br($frow['description']);
2019 else if($data_type == 34){
2020 $arr = explode("|*|*|*|",$currvalue);
2021 for($i=0;$i<sizeof($arr);$i++){
2022 $s.=$arr[$i];
2026 // facility
2027 else if ($data_type == 35) {
2028 $urow = sqlQuery("SELECT id, name FROM facility ".
2029 "WHERE id = ?", array($currvalue) );
2030 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
2033 // Multi select
2034 // Supports backup lists
2035 else if ($data_type == 36) {
2036 $values_array = explode("|", $currvalue);
2037 $i = 0;
2038 foreach($values_array as $value) {
2039 $lrow = sqlQuery("SELECT title FROM list_options " .
2040 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2041 if ($lrow == 0 && !empty($backup_list)) {
2042 //use back up list
2043 $lrow = sqlQuery("SELECT title FROM list_options " .
2044 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2046 if ($i > 0) {
2047 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2048 } else {
2049 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2051 $i++;
2055 // Image from canvas drawing
2056 else if ($data_type == 40) {
2057 $s .= "<img src='" . attr($currvalue) . "'>";
2060 return $s;
2063 // Generate plain text versions of selected LBF field types.
2064 // Currently used by interface/patient_file/download_template.php.
2065 // More field types might need to be supported here in the future.
2067 function generate_plaintext_field($frow, $currvalue) {
2068 global $ISSUE_TYPES;
2070 $data_type = $frow['data_type'];
2071 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2072 $list_id = $frow['list_id'];
2073 $backup_list = $frow['backup_list'];
2074 $s = '';
2076 // generic selection list or the generic selection list with add on the fly
2077 // feature, or radio buttons
2078 // Supports backup lists (for datatypes 1,26,33)
2079 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2080 $lrow = sqlQuery("SELECT title FROM list_options " .
2081 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
2082 $s = xl_list_label($lrow['title']);
2083 //if there is no matching value in the corresponding lists check backup list
2084 // only supported in data types 1,26,33
2085 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2086 $lrow = sqlQuery("SELECT title FROM list_options " .
2087 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
2088 $s = xl_list_label($lrow['title']);
2092 // simple or long text field
2093 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2094 $s = $currvalue;
2097 // date
2098 else if ($data_type == 4) {
2099 $s = oeFormatShortDate($currvalue);
2100 // Optional display of age or gestational age.
2101 $asof=''; //not used here, but set to prevent a php warning when call optionalAge
2102 $tmp = optionalAge($frow, $currvalue,$asof);
2103 if ($tmp) $s .= ' ' . $tmp;
2106 // provider
2107 else if ($data_type == 10 || $data_type == 11) {
2108 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2109 "WHERE id = ?", array($currvalue) );
2110 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2113 // pharmacy list
2114 else if ($data_type == 12) {
2115 $pres = get_pharmacies();
2116 while ($prow = sqlFetchArray($pres)) {
2117 $key = $prow['id'];
2118 if ($currvalue == $key) {
2119 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2120 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2121 $prow['line1'] . ' / ' . $prow['city'];
2126 // address book
2127 else if ($data_type == 14) {
2128 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2129 "WHERE id = ?", array($currvalue));
2130 $uname = $urow['lname'];
2131 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2132 $s = $uname;
2135 // insurance company list
2136 else if ($data_type == 16) {
2137 $insprovs = getInsuranceProviders();
2138 foreach ($insprovs as $key => $ipname) {
2139 if ($currvalue == $key) {
2140 $s .= $ipname;
2145 // issue type
2146 else if ($data_type == 17) {
2147 foreach ($ISSUE_TYPES as $key => $value) {
2148 if ($currvalue == $key) {
2149 $s .= $value[1];
2154 // visit category
2155 else if ($data_type == 18) {
2156 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2157 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2158 array($currvalue));
2159 $s = $crow['pc_catname'];
2162 // a set of labeled checkboxes
2163 else if ($data_type == 21) {
2164 $avalue = explode('|', $currvalue);
2165 $lres = sqlStatement("SELECT * FROM list_options " .
2166 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2167 $count = 0;
2168 while ($lrow = sqlFetchArray($lres)) {
2169 $option_id = $lrow['option_id'];
2170 if (in_array($option_id, $avalue)) {
2171 if ($count++) $s .= "; ";
2172 $s .= xl_list_label($lrow['title']);
2177 // a set of labeled text input fields
2178 else if ($data_type == 22) {
2179 $tmp = explode('|', $currvalue);
2180 $avalue = array();
2181 foreach ($tmp as $value) {
2182 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2183 $avalue[$matches[1]] = $matches[2];
2186 $lres = sqlStatement("SELECT * FROM list_options " .
2187 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2188 while ($lrow = sqlFetchArray($lres)) {
2189 $option_id = $lrow['option_id'];
2190 if (empty($avalue[$option_id])) continue;
2191 if ($s !== '') $s .= '; ';
2192 $s .= xl_list_label($lrow['title']) . ': ';
2193 $s .= $avalue[$option_id];
2197 // A set of exam results; 3 radio buttons and a text field.
2198 // This shows abnormal results only.
2199 else if ($data_type == 23) {
2200 $tmp = explode('|', $currvalue);
2201 $avalue = array();
2202 foreach ($tmp as $value) {
2203 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2204 $avalue[$matches[1]] = $matches[2];
2207 $lres = sqlStatement("SELECT * FROM list_options " .
2208 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2209 while ($lrow = sqlFetchArray($lres)) {
2210 $option_id = $lrow['option_id'];
2211 $restype = substr($avalue[$option_id], 0, 1);
2212 $resnote = substr($avalue[$option_id], 2);
2213 if (empty($restype) && empty($resnote)) continue;
2214 if ($restype != '2') continue; // show abnormal results only
2215 if ($s !== '') $s .= '; ';
2216 $s .= xl_list_label($lrow['title']);
2217 if (!empty($resnote)) $s .= ': ' . $resnote;
2221 // the list of active allergies for the current patient
2222 else if ($data_type == 24) {
2223 $query = "SELECT title, comments FROM lists WHERE " .
2224 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2225 "ORDER BY begdate";
2226 $lres = sqlStatement($query, array($GLOBALS['pid']));
2227 $count = 0;
2228 while ($lrow = sqlFetchArray($lres)) {
2229 if ($count++) $s .= "; ";
2230 $s .= $lrow['title'];
2231 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2235 // a set of labeled checkboxes, each with a text field:
2236 else if ($data_type == 25) {
2237 $tmp = explode('|', $currvalue);
2238 $avalue = array();
2239 foreach ($tmp as $value) {
2240 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2241 $avalue[$matches[1]] = $matches[2];
2244 $lres = sqlStatement("SELECT * FROM list_options " .
2245 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2246 while ($lrow = sqlFetchArray($lres)) {
2247 $option_id = $lrow['option_id'];
2248 $restype = substr($avalue[$option_id], 0, 1);
2249 $resnote = substr($avalue[$option_id], 2);
2250 if (empty($restype) && empty($resnote)) continue;
2251 if ($s !== '') $s .= '; ';
2252 $s .= xl_list_label($lrow['title']);
2253 $restype = $restype ? xl('Yes') : xl('No');
2254 $s .= $restype;
2255 if ($resnote) $s .= ' ' . $resnote;
2259 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2260 // VicarePlus :: A selection list for smoking status.
2261 else if ($data_type == 28 || $data_type == 32) {
2262 $tmp = explode('|', $currvalue);
2263 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2264 $restype = count($tmp) > 1 ? $tmp[1] : '';
2265 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2266 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2267 $res = "";
2268 if ($restype == "current" . $field_id) $res = xl('Current');
2269 if ($restype == "quit" . $field_id) $res = xl('Quit');
2270 if ($restype == "never" . $field_id) $res = xl('Never');
2271 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2273 if ($data_type == 28) {
2274 if (!empty($resnote)) $s .= $resnote;
2276 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2277 else if ($data_type == 32) {
2278 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2279 if (!empty($resnote)) $s .= ' ' . $resnote;
2281 if (!empty($res)) {
2282 if ($s !== '') $s .= ' ';
2283 $s .= xl('Status') . ' ' . $res;
2285 if ($restype == "quit".$field_id) {
2286 if ($s !== '') $s .= ' ';
2287 $s .= $resdate;
2291 // Multi select
2292 // Supports backup lists
2293 else if ($data_type == 36) {
2294 $values_array = explode("|", $currvalue);
2296 $i = 0;
2297 foreach($values_array as $value) {
2298 $lrow = sqlQuery("SELECT title FROM list_options " .
2299 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2301 if ($lrow == 0 && !empty($backup_list)) {
2302 //use back up list
2303 $lrow = sqlQuery("SELECT title FROM list_options " .
2304 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2307 if ($i > 0) {
2308 $s = $s . ", " . xl_list_label($lrow['title']);
2309 } else {
2310 $s = xl_list_label($lrow['title']);
2313 $i++;
2317 return $s;
2320 $CPR = 4; // cells per row of generic data
2321 $last_group = '';
2322 $cell_count = 0;
2323 $item_count = 0;
2325 function disp_end_cell() {
2326 global $item_count, $cell_count;
2327 if ($item_count > 0) {
2328 echo "</td>";
2329 $item_count = 0;
2333 function disp_end_row() {
2334 global $cell_count, $CPR;
2335 disp_end_cell();
2336 if ($cell_count > 0) {
2337 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
2338 echo "</tr>\n";
2339 $cell_count = 0;
2343 function disp_end_group() {
2344 global $last_group;
2345 if (strlen($last_group) > 0) {
2346 disp_end_row();
2350 function display_layout_rows($formtype, $result1, $result2='') {
2351 global $item_count, $cell_count, $last_group, $CPR;
2353 $fres = sqlStatement("SELECT * FROM layout_options " .
2354 "WHERE form_id = ? AND uor > 0 " .
2355 "ORDER BY group_name, seq", array($formtype) );
2357 while ($frow = sqlFetchArray($fres)) {
2358 $this_group = $frow['group_name'];
2359 $titlecols = $frow['titlecols'];
2360 $datacols = $frow['datacols'];
2361 $data_type = $frow['data_type'];
2362 $field_id = $frow['field_id'];
2363 $list_id = $frow['list_id'];
2364 $currvalue = '';
2366 if ($formtype == 'DEM') {
2367 if (strpos($field_id, 'em_') === 0) {
2368 // Skip employer related fields, if it's disabled.
2369 if ($GLOBALS['omit_employers']) continue;
2370 $tmp = substr($field_id, 3);
2371 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2373 else {
2374 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2377 else {
2378 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2381 // Handle a data category (group) change.
2382 if (strcmp($this_group, $last_group) != 0) {
2383 $group_name = substr($this_group, 1);
2384 // totally skip generating the employer category, if it's disabled.
2385 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2386 disp_end_group();
2387 $last_group = $this_group;
2390 // filter out all the empty field data from the patient report.
2391 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2392 // Handle starting of a new row.
2393 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2394 disp_end_row();
2395 echo "<tr>";
2396 if ($group_name) {
2397 echo "<td class='groupname'>";
2398 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2399 //echo "<font color='#008800'>$group_name</font>";
2401 // Added 5-09 by BM - Translate label if applicable
2402 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
2404 $group_name = '';
2405 } else {
2406 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2407 echo "<td valign='top'>&nbsp;";
2409 echo "</td>";
2412 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2414 // Handle starting of a new label cell.
2415 if ($titlecols > 0) {
2416 disp_end_cell();
2417 //echo "<td class='label' colspan='$titlecols' valign='top'";
2418 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2419 echo "<td class='label' colspan='$titlecols_esc' ";
2420 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2421 echo ">";
2422 $cell_count += $titlecols;
2424 ++$item_count;
2426 // Added 5-09 by BM - Translate label if applicable
2427 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2429 // Handle starting of a new data cell.
2430 if ($datacols > 0) {
2431 disp_end_cell();
2432 //echo "<td class='text data' colspan='$datacols' valign='top'";
2433 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2434 echo "<td class='text data' colspan='$datacols_esc'";
2435 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2436 echo ">";
2437 $cell_count += $datacols;
2440 ++$item_count;
2441 echo generate_display_field($frow, $currvalue);
2445 disp_end_group();
2448 function display_layout_tabs($formtype, $result1, $result2='') {
2449 global $item_count, $cell_count, $last_group, $CPR;
2451 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2452 "WHERE form_id = ? AND uor > 0 " .
2453 "ORDER BY group_name, seq", array($formtype) );
2455 $first = true;
2456 while ($frow = sqlFetchArray($fres)) {
2457 $this_group = $frow['group_name'];
2458 $group_name = substr($this_group, 1);
2459 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2461 <li <?php echo $first ? 'class="current"' : '' ?>>
2462 <a href="#" id="header_tab_<?php echo str_replace(" ", "_",htmlspecialchars($group_name,ENT_QUOTES))?>">
2463 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
2464 </li>
2465 <?php
2466 $first = false;
2470 function display_layout_tabs_data($formtype, $result1, $result2='') {
2471 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2473 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2474 "WHERE form_id = ? AND uor > 0 " .
2475 "ORDER BY group_name, seq", array($formtype));
2477 $first = true;
2478 while ($frow = sqlFetchArray($fres)) {
2479 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
2480 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
2481 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
2482 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
2483 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
2484 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
2485 $currvalue = '';
2487 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2489 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2490 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2491 "ORDER BY seq", array($formtype, $this_group) );
2494 <div class="tab <?php echo $first ? 'current' : '' ?>">
2495 <table border='0' cellpadding='0'>
2497 <?php
2498 while ($group_fields = sqlFetchArray($group_fields_query)) {
2500 $titlecols = $group_fields['titlecols'];
2501 $datacols = $group_fields['datacols'];
2502 $data_type = $group_fields['data_type'];
2503 $field_id = $group_fields['field_id'];
2504 $list_id = $group_fields['list_id'];
2505 $currvalue = '';
2506 $condition_str = get_conditions_str($condition_str,$group_fields);
2509 if ($formtype == 'DEM') {
2510 if (strpos($field_id, 'em_') === 0) {
2511 // Skip employer related fields, if it's disabled.
2512 if ($GLOBALS['omit_employers']) continue;
2513 $tmp = substr($field_id, 3);
2514 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2516 else {
2517 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2520 else {
2521 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2524 // Handle a data category (group) change.
2525 if (strcmp($this_group, $last_group) != 0) {
2526 $group_name = substr($this_group, 1);
2527 // totally skip generating the employer category, if it's disabled.
2528 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2529 $last_group = $this_group;
2532 // Handle starting of a new row.
2533 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2534 disp_end_row();
2535 echo "<tr>";
2538 if ($item_count == 0 && $titlecols == 0) {
2539 $titlecols = 1;
2542 // Handle starting of a new label cell.
2543 if ($titlecols > 0) {
2544 disp_end_cell();
2545 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2546 $field_id_label = 'label_'.$group_fields['field_id'];
2547 echo "<td class='label' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
2548 echo ">";
2549 $cell_count += $titlecols;
2551 ++$item_count;
2553 $field_id_label = 'label_'.$group_fields['field_id'];
2554 echo "<span id='".attr($field_id_label)."'>";
2555 // Added 5-09 by BM - Translate label if applicable
2556 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2557 echo "</span>";
2559 // Handle starting of a new data cell.
2560 if ($datacols > 0) {
2561 disp_end_cell();
2562 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2563 $field_id = 'text_'.$group_fields['field_id'];
2564 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
2565 echo ">";
2566 $cell_count += $datacols;
2567 } else {
2568 $field_id = 'text_'.$group_fields['field_id'];
2569 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
2572 ++$item_count;
2573 echo generate_display_field($group_fields, $currvalue);
2576 disp_end_row();
2579 </table>
2580 </div>
2582 <?php
2584 $first = false;
2590 function get_conditions_str($condition_str,$frow){
2591 $conditions = empty($frow['conditions']) ? array() : unserialize($frow['conditions']);
2592 foreach ($conditions as $condition) {
2593 if (empty($condition['id'])) continue;
2594 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2595 if ($condition_str) $condition_str .= ",\n";
2596 $condition_str .= "{" .
2597 "target:'" . addslashes($frow['field_id']) . "', " .
2598 "id:'" . addslashes($condition['id']) . "', " .
2599 "itemid:'" . addslashes($condition['itemid']) . "', " .
2600 "operator:'" . addslashes($condition['operator']) . "', " .
2601 "value:'" . addslashes($condition['value']) . "', " .
2602 "andor:'" . addslashes($andor) . "'}";
2604 return $condition_str;
2606 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2607 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2609 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2610 "WHERE form_id = ? AND uor > 0 " .
2611 "ORDER BY group_name, seq", array($formtype) );
2613 $first = true;
2614 while ($frow = sqlFetchArray($fres)) {
2615 $this_group = $frow['group_name'];
2616 $group_name = substr($this_group, 1);
2617 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
2618 $titlecols = $frow['titlecols'];
2619 $datacols = $frow['datacols'];
2620 $data_type = $frow['data_type'];
2621 $field_id = $frow['field_id'];
2622 $list_id = $frow['list_id'];
2623 $currvalue = '';
2625 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2627 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2628 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2629 "ORDER BY seq", array($formtype,$this_group) );
2632 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_',$group_name_esc)?>" >
2633 <table border='0' cellpadding='0'>
2635 <?php
2636 while ($group_fields = sqlFetchArray($group_fields_query)) {
2638 $titlecols = $group_fields['titlecols'];
2639 $datacols = $group_fields['datacols'];
2640 $data_type = $group_fields['data_type'];
2641 $field_id = $group_fields['field_id'];
2642 $list_id = $group_fields['list_id'];
2643 $backup_list = $group_fields['list_backup_id'];
2644 $condition_str = get_conditions_str($condition_str,$group_fields);
2645 $currvalue = '';
2647 if ($formtype == 'DEM') {
2648 if (strpos($field_id, 'em_') === 0) {
2649 // Skip employer related fields, if it's disabled.
2650 if ($GLOBALS['omit_employers']) continue;
2651 $tmp = substr($field_id, 3);
2652 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2654 else {
2655 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2658 else {
2659 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2662 // Handle a data category (group) change.
2663 if (strcmp($this_group, $last_group) != 0) {
2664 $group_name = substr($this_group, 1);
2665 // totally skip generating the employer category, if it's disabled.
2666 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2667 $last_group = $this_group;
2670 // Handle starting of a new row.
2671 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2672 disp_end_row();
2673 echo "<tr>";
2676 if ($item_count == 0 && $titlecols == 0) {
2677 $titlecols = 1;
2680 // Handle starting of a new label cell.
2681 if ($titlecols > 0) {
2682 disp_end_cell();
2683 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2684 $field_id_label = 'label_'.$group_fields['field_id'];
2685 echo "<td class='label' colspan='$titlecols_esc' id='$field_id_label' ";
2686 echo ">";
2687 $cell_count += $titlecols;
2689 ++$item_count;
2691 // Added 5-09 by BM - Translate label if applicable
2692 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
2694 // Handle starting of a new data cell.
2695 if ($datacols > 0) {
2696 disp_end_cell();
2697 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2698 $field_id = 'text_'.$group_fields['field_id'];
2699 echo "<td class='text data' colspan='$datacols_esc' id='$field_id'";
2700 echo ">";
2701 $cell_count += $datacols;
2704 ++$item_count;
2706 echo generate_form_field($group_fields, $currvalue);
2710 </table>
2711 </div>
2713 <?php
2715 $first = false;
2720 // From the currently posted HTML form, this gets the value of the
2721 // field corresponding to the provided layout_options table row.
2723 function get_layout_form_value($frow, $prefix='form_') {
2724 // Bring in $sanitize_all_escapes variable, which will decide
2725 // the variable escaping method.
2726 global $sanitize_all_escapes;
2728 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
2729 $data_type = $frow['data_type'];
2730 $field_id = $frow['field_id'];
2731 $value = '';
2732 if (isset($_POST["$prefix$field_id"])) {
2733 if ($data_type == 21) {
2734 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2735 // must be concatenated into a |-separated string.
2736 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2737 if (strlen($value)) $value .= '|';
2738 $value .= $key;
2741 else if ($data_type == 22) {
2742 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2743 // into "key:value|key:value|...".
2744 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2745 $val = str_replace('|', ' ', $val);
2746 if (strlen($value)) $value .= '|';
2747 $value .= "$key:$val";
2750 else if ($data_type == 23) {
2751 // $_POST["$prefix$field_id"] is an array of text fields with companion
2752 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2753 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2754 $restype = $_POST["radio_{$field_id}"][$key];
2755 if (empty($restype)) $restype = '0';
2756 $val = str_replace('|', ' ', $val);
2757 if (strlen($value)) $value .= '|';
2758 $value .= "$key:$restype:$val";
2761 else if ($data_type == 25) {
2762 // $_POST["$prefix$field_id"] is an array of text fields with companion
2763 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2764 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2765 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
2766 $val = str_replace('|', ' ', $val);
2767 if (strlen($value)) $value .= '|';
2768 $value .= "$key:$restype:$val";
2771 else if ($data_type == 28 || $data_type == 32) {
2772 // $_POST["$prefix$field_id"] is an date text fields with companion
2773 // radio buttons to be imploded into "notes|type|date".
2774 $restype = $_POST["radio_{$field_id}"];
2775 if (empty($restype)) $restype = '0';
2776 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2777 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2778 if ($data_type == 32)
2780 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2781 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2782 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2783 $value = "$res_text_note|$restype|$resdate|$reslist";
2785 else
2786 $value = "$resnote|$restype|$resdate";
2788 else if ($data_type == 36) {
2789 $value_array = $_POST["form_$field_id"];
2790 $i = 0;
2791 foreach ($value_array as $key => $valueofkey) {
2792 if ($i == 0) {
2793 $value = $valueofkey;
2794 } else {
2795 $value = $value . "|" . $valueofkey;
2797 $i++;
2800 else {
2801 $value = $_POST["$prefix$field_id"];
2805 // Better to die than to silently truncate data!
2806 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2807 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2808 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2810 // Make sure the return value is quote-safe.
2811 if ($sanitize_all_escapes) {
2812 //escapes already removed and using binding/placemarks in sql calls
2813 // so only need to trim value
2814 return trim($value);
2816 else {
2817 //need to explicitly prepare value
2818 return formTrim($value);
2822 // Generate JavaScript validation logic for the required fields.
2824 function generate_layout_validation($form_id) {
2825 $fres = sqlStatement("SELECT * FROM layout_options " .
2826 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2827 "ORDER BY group_name, seq", array($form_id) );
2829 while ($frow = sqlFetchArray($fres)) {
2830 $data_type = $frow['data_type'];
2831 $field_id = $frow['field_id'];
2832 $fldtitle = $frow['title'];
2833 if (!$fldtitle) $fldtitle = $frow['description'];
2834 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES);
2836 if ($data_type == 40) {
2837 $fldid = addslashes("form_$field_id");
2838 // Move canvas image data to its hidden form field so the server will get it.
2839 echo
2840 " var canfld = f['$fldid'];\n" .
2841 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
2842 continue;
2845 if ($frow['uor'] < 2) continue;
2847 switch($data_type) {
2848 case 1:
2849 case 11:
2850 case 12:
2851 case 13:
2852 case 14:
2853 case 26:
2854 case 33:
2855 echo
2856 " if (f.$fldname.selectedIndex <= 0) {\n" .
2857 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2858 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2859 " }\n";
2860 break;
2861 case 27: // radio buttons
2862 echo
2863 " var i = 0;\n" .
2864 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2865 " if (i >= f.$fldname.length) {\n" .
2866 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2867 " }\n";
2868 break;
2869 case 2:
2870 case 3:
2871 case 4:
2872 case 15:
2873 echo
2874 " if (trimlen(f.$fldname.value) == 0) {\n" .
2875 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2876 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2877 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2878 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2879 " } else { " .
2880 " $('#" . $fldname . "').attr('style',''); " .
2881 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2882 " } \n";
2883 break;
2884 case 36: // multi select
2885 echo
2886 " var multi_select=f['$fldname"."[]']; \n " .
2887 " var multi_choice_made=false; \n".
2888 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
2889 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
2890 " } \n" .
2891 " if(!multi_choice_made)
2892 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2894 break;
2900 * DROPDOWN FOR FACILITIES
2902 * build a dropdown with all facilities
2904 * @param string $selected - name of the currently selected facility
2905 * use '0' for "unspecified facility"
2906 * use '' for "All facilities" (the default)
2907 * @param string $name - the name/id for select form (defaults to "form_facility")
2908 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2909 * defaults to true
2910 * @return void - just echo the html encoded string
2912 * Note: This should become a data-type at some point, according to Brady
2914 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2915 $allow_allfacilities = true, $disabled='', $onchange='')
2917 $have_selected = false;
2918 $query = "SELECT id, name FROM facility ORDER BY name";
2919 $fres = sqlStatement($query);
2921 $name = htmlspecialchars($name, ENT_QUOTES);
2922 echo " <select name='$name' id='$name'";
2923 if ($onchange) echo " onchange='$onchange'";
2924 echo " $disabled>\n";
2926 if ($allow_allfacilities) {
2927 $option_value = '';
2928 $option_selected_attr = '';
2929 if ($selected == '') {
2930 $option_selected_attr = ' selected="selected"';
2931 $have_selected = true;
2933 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2934 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2935 } elseif ($allow_unspecified) {
2936 $option_value = '0';
2937 $option_selected_attr = '';
2938 if ( $selected == '0' ) {
2939 $option_selected_attr = ' selected="selected"';
2940 $have_selected = true;
2942 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2943 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2946 while ($frow = sqlFetchArray($fres)) {
2947 $facility_id = $frow['id'];
2948 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2949 $option_selected_attr = '';
2950 if ($selected == $facility_id) {
2951 $option_selected_attr = ' selected="selected"';
2952 $have_selected = true;
2954 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2955 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2958 if ($allow_unspecified && $allow_allfacilities) {
2959 $option_value = '0';
2960 $option_selected_attr = '';
2961 if ( $selected == '0' ) {
2962 $option_selected_attr = ' selected="selected"';
2963 $have_selected = true;
2965 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2966 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2969 if (!$have_selected) {
2970 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2971 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2972 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2973 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2975 echo " </select>\n";
2978 // Expand Collapse Widget
2979 // This forms the header and functionality component of the widget. The information that is displayed
2980 // then follows this function followed by a closing div tag
2982 // $title is the title of the section (already translated)
2983 // $label is identifier used in the tag id's and sql columns
2984 // $buttonLabel is the button label text (already translated)
2985 // $buttonLink is the button link information
2986 // $buttonClass is any additional needed class elements for the button tag
2987 // $linkMethod is the button link method ('javascript' vs 'html')
2988 // $bodyClass is to set class(es) of the body
2989 // $auth is a flag to decide whether to show the button
2990 // $fixedWidth is to flag whether width is fixed
2991 // $forceExpandAlways is a flag to force the widget to always be expanded
2993 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2994 if ($fixedWidth) {
2995 echo "<div class='section-header'>";
2997 else {
2998 echo "<div class='section-header-dynamic'>";
3000 echo "<table><tr>";
3001 if ($auth) {
3002 // show button, since authorized
3003 // first prepare class string
3004 if ($buttonClass) {
3005 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
3007 else {
3008 $class_string = "css_button_small";
3010 // next, create the link
3011 if ($linkMethod == "javascript") {
3012 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3014 else {
3015 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3016 if (!isset($_SESSION['patient_portal_onsite']) && !isset($_SESSION['patient_portal_onsite_two']) ) {
3017 // prevent an error from occuring when calling the function from the patient portal
3018 echo " onclick='top.restoreSession()'";
3021 echo "><span>" .
3022 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
3024 if ($forceExpandAlways){
3025 // Special case to force the widget to always be expanded
3026 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
3027 $indicatorTag ="style='display:none'";
3029 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3030 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3031 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
3032 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
3034 if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3035 // collapse all entries in the patient portal
3036 $text = xl('expand');
3038 else if (getUserSetting($label."_ps_expand")) {
3039 $text = xl('collapse');
3041 else {
3042 $text = xl('expand');
3044 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
3045 "</span>)</a></td>";
3046 echo "</tr></table>";
3047 echo "</div>";
3048 if ($forceExpandAlways) {
3049 // Special case to force the widget to always be expanded
3050 $styling = "";
3052 else if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3053 // collapse all entries in the patient portal
3054 $styling = "style='display:none'";
3056 else if (getUserSetting($label."_ps_expand")) {
3057 $styling = "";
3059 else {
3060 $styling = "style='display:none'";
3062 if ($bodyClass) {
3063 $styling .= " class='" . $bodyClass . "'";
3065 //next, create the first div tag to hold the information
3066 // note the code that calls this function will then place the ending div tag after the data
3067 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
3070 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3071 function billing_facility($name,$select){
3072 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
3073 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3074 while ($facrow = sqlFetchArray($qsql)) {
3075 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3076 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3078 echo "</select>";
3081 // Generic function to get the translated title value for a particular list option.
3083 function getListItemTitle($list, $option) {
3084 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3085 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3086 if (empty($row['title'])) return $option;
3087 return xl_list_label($row['title']);
3089 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3090 function getSmokeCodes()
3092 $smoking_codes_arr = array();
3093 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3094 while($codes_row = sqlFetchArray($smoking_codes))
3096 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3098 return $smoking_codes_arr;
3101 // Get the current value for a layout based form field.
3102 // Depending on options this might come from lbf_data, patient_data,
3103 // form_encounter, shared_attributes or elsewhere.
3104 // Returns FALSE if the field ID is invalid (layout error).
3106 function lbf_current_value($frow, $formid, $encounter) {
3107 global $pid;
3108 $formname = $frow['form_id'];
3109 $field_id = $frow['field_id'];
3110 $source = $frow['source'];
3111 $currvalue = '';
3112 $deffname = $formname . '_default_' . $field_id;
3113 if ($source == 'D' || $source == 'H') {
3114 // Get from patient_data, employer_data or history_data.
3115 if ($source == 'H') {
3116 $table = 'history_data';
3117 $orderby = 'ORDER BY date DESC LIMIT 1';
3119 else if (strpos($field_id, 'em_') === 0) {
3120 $field_id = substr($field_id, 3);
3121 $table = 'employer_data';
3122 $orderby = 'ORDER BY date DESC LIMIT 1';
3124 else {
3125 $table = 'patient_data';
3126 $orderby = '';
3128 // It is an error if the field does not exist, but don't crash.
3129 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3130 if (empty($tmp)) return FALSE;
3131 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3132 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3134 else if ($source == 'E') {
3135 if ($encounter) {
3136 // Get value from shared_attributes of the current encounter.
3137 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3138 "pid = ? AND encounter = ? AND field_id = ?",
3139 array($pid, $encounter, $field_id));
3140 if (isset($sarow)) $currvalue = $sarow['field_value'];
3142 else if ($formid) {
3143 // Get from shared_attributes of the encounter that this form is linked to.
3144 // Note the importance of having an index on forms.form_id.
3145 $sarow = sqlQuery("SELECT sa.field_value " .
3146 "FROM forms AS f, shared_attributes AS sa WHERE " .
3147 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3148 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3149 array($formid, $formname, $field_id));
3150 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3152 else {
3153 // New form and encounter not available, this should not happen.
3156 else if ($source == 'V') {
3157 if ($encounter) {
3158 // Get value from the current encounter's form_encounter.
3159 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3160 "pid = ? AND encounter = ?",
3161 array($pid, $encounter));
3162 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3164 else if ($formid) {
3165 // Get value from the form_encounter that this form is linked to.
3166 $ferow = sqlQuery("SELECT fe.* " .
3167 "FROM forms AS f, form_encounter AS fe WHERE " .
3168 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3169 "fe.pid = f.pid AND fe.encounter = f.encounter",
3170 array($formid, $formname));
3171 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3173 else {
3174 // New form and encounter not available, this should not happen.
3177 else if ($formid) {
3178 // This is a normal form field.
3179 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3180 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3181 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3183 else {
3184 // New form, see if there is a custom default from a plugin.
3185 // This logic does not apply to shared attributes because they do not
3186 // have a "new form" concept.
3187 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3189 return $currvalue;
3192 // This returns stuff that needs to go into the <head> section of a caller using
3193 // the drawable image field type in a form.
3194 // A TRUE argument makes the widget controls smaller.
3196 function lbf_canvas_head($small=TRUE) {
3197 $s = <<<EOD
3198 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3199 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3200 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3201 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3202 EOD;
3203 if ($small) $s .= <<<EOD
3204 <style>
3205 /* Custom LiterallyCanvas styling.
3206 * This makes the widget 25% less tall and adjusts some other things accordingly.
3208 .literally {
3209 min-height:100%;min-width:300px; /* Was 400, unspecified */
3211 .literally .lc-picker .toolbar-button {
3212 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3214 .literally .color-well {
3215 font-size:8px;width:49px; /* Was 10, 60 */
3217 .literally .color-well-color-container {
3218 width:21px;height:21px; /* Was 28, 28 */
3220 .literally .lc-picker {
3221 width:50px; /* Was 61 */
3223 .literally .lc-drawing.with-gui {
3224 left:50px; /* Was 61 */
3226 .literally .lc-options {
3227 left:50px; /* Was 61 */
3229 .literally .color-picker-popup {
3230 left:49px;bottom:0px; /* Was 60, 31 */
3232 </style>
3233 EOD;
3234 return $s;