composer package updates (#2370)
[openemr.git] / library / options.inc.php
blobd4fa3e054d79b1c6e20018d184cd67e401137d00
1 <?php
2 // Copyright (C) 2007-2019 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 // J = Jump to Next Row
28 // K = Prepend Blank Row
29 // L = Lab Order ("ord_lab") types only (address book)
30 // M = Radio Group Master (currently for radio buttons only)
31 // m = Radio Group Member (currently for radio buttons only)
32 // N = Show in New Patient form
33 // O = Procedure Order ("ord_*") types only (address book)
34 // P = Default to previous value when current value is not yet set
35 // R = Distributor types only (address book)
36 // T = Use description as default Text
37 // U = Capitalize all letters (text fields)
38 // V = Vendor types only (address book)
39 // 0 = Read Only - the input element's "disabled" property is set
40 // 1 = Write Once (not editable when not empty) (text fields)
41 // 2 = Show descriptions instead of codes for billing code input
43 require_once("user.inc");
44 require_once("patient.inc");
45 require_once("lists.inc");
46 require_once(dirname(dirname(__FILE__)) . "/custom/code_types.inc.php");
48 use OpenEMR\Services\FacilityService;
50 $facilityService = new FacilityService();
52 $date_init = "";
53 $membership_group_number = 0;
55 function get_pharmacies()
57 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
58 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
59 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
60 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
61 "AND p.type = 2 " .
62 "ORDER BY name, area_code, prefix, number");
65 function optionalAge($frow, $date, &$asof, $description = '')
67 $asof = '';
68 if (empty($date)) {
69 return '';
72 $date = substr($date, 0, 10);
73 if (isOption($frow['edit_options'], 'A') !== false) {
74 $format = 0;
75 } elseif (isOption($frow['edit_options'], 'B') !== false) {
76 $format = 3;
77 } else {
78 return '';
81 if (isOption($frow['form_id'], 'LBF') === 0) {
82 $tmp = sqlQuery(
83 "SELECT date FROM form_encounter WHERE " .
84 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
85 array($GLOBALS['pid'], $GLOBALS['encounter'])
87 if (!empty($tmp['date'])) {
88 $asof = substr($tmp['date'], 0, 10);
91 if ($description === '') {
92 $prefix = ($format ? xl('Gest age') : xl('Age')) . ' ';
93 } else {
94 $prefix = $description . ' ';
96 return $prefix . oeFormatAge($date, $asof, $format);
99 // Function to generate a drop-list.
101 function generate_select_list(
102 $tag_name,
103 $list_id,
104 $currvalue,
105 $title,
106 $empty_name = ' ',
107 $class = '',
108 $onchange = '',
109 $tag_id = '',
110 $custom_attributes = null,
111 $multiple = false,
112 $backup_list = ''
114 $s = '';
116 $tag_name_esc = attr($tag_name);
118 if ($multiple) {
119 $tag_name_esc = $tag_name_esc . "[]";
122 $s .= "<select name='$tag_name_esc'";
124 if ($multiple) {
125 $s .= " multiple='multiple'";
128 $tag_id_esc = attr($tag_name);
130 if ($tag_id != '') {
131 $tag_id_esc = attr($tag_id);
134 $s .= " id='$tag_id_esc'";
136 if (!empty($class)) {
137 $class_esc = attr($class);
138 $s .= " class='form-control $class_esc'";
139 } else {
140 $s .= " class='form-control'";
143 if ($onchange) {
144 $s .= " onchange='$onchange'";
147 if ($custom_attributes != null && is_array($custom_attributes)) {
148 foreach ($custom_attributes as $attr => $val) {
149 if (isset($custom_attributes [$attr])) {
150 $s .= " " . attr($attr) . "='" . attr($val) . "'";
155 $selectTitle = attr($title);
156 $s .= " title='$selectTitle'>";
157 $selectEmptyName = xlt($empty_name);
158 if ($empty_name) {
159 $s .= "<option value=''>" . $selectEmptyName . "</option>";
162 // List order depends on language translation options.
163 // (Note we do not need to worry about the list order in the algorithm
164 // after the below code block since that is where searches for exceptions
165 // are done which include inactive items or items from a backup
166 // list; note these will always be shown at the bottom of the list no matter the
167 // chosen order.)
168 $lang_id = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
169 // sort by title
170 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) || !$GLOBALS['translate_lists']) {
171 // do not translate
172 if ($GLOBALS['gb_how_sort_list'] == '0') {
173 // order by seq
174 $order_by_sql = "seq, title";
175 } else { //$GLOBALS['gb_how_sort_list'] == '1'
176 // order by title
177 $order_by_sql = "title, seq";
180 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
181 } else {
182 // do translate
183 if ($GLOBALS['gb_how_sort_list'] == '0') {
184 // order by seq
185 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
186 } else { //$GLOBALS['gb_how_sort_list'] == '1'
187 // order by title
188 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
191 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
192 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
193 "FROM list_options AS lo " .
194 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
195 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
196 "ld.lang_id = ? " .
197 "WHERE lo.list_id = ? AND lo.activity=1 " .
198 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
201 $got_selected = false;
203 while ($lrow = sqlFetchArray($lres)) {
204 $selectedValues = explode("|", $currvalue);
206 $optionValue = attr($lrow ['option_id']);
207 $s .= "<option value='$optionValue'";
209 if ((strlen($currvalue) == 0 && $lrow ['is_default']) || (strlen($currvalue) > 0 && in_array($lrow ['option_id'], $selectedValues))) {
210 $s .= " selected";
211 $got_selected = true;
214 // Already has been translated above (if applicable), so do not need to use
215 // the xl_list_label() function here
216 $optionLabel = text($lrow ['title']);
217 $s .= ">$optionLabel</option>\n";
221 To show the inactive item in the list if the value is saved to database
223 if (!$got_selected && strlen($currvalue) > 0) {
224 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
225 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
226 $lrow_inactive = sqlFetchArray($lres_inactive);
227 if ($lrow_inactive['option_id']) {
228 $optionValue = htmlspecialchars($lrow_inactive['option_id'], ENT_QUOTES);
229 $s .= "<option value='$optionValue' selected>" . htmlspecialchars(xl_list_label($lrow_inactive['title']), ENT_NOQUOTES) . "</option>\n";
230 $got_selected = true;
234 if (!$got_selected && strlen($currvalue) > 0 && !$multiple) {
235 $list_id = $backup_list;
236 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
238 if ($lrow > 0 && !empty($backup_list)) {
239 $selected = text(xl_list_label($lrow ['title']));
240 $s .= "<option value='$currescaped' selected> $selected </option>";
241 $s .= "</select>";
242 } else {
243 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
244 $s .= "</select>";
245 $fontTitle = xlt('Please choose a valid selection from the list.');
246 $fontText = xlt('Fix this');
247 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
249 } elseif (!$got_selected && strlen($currvalue) > 0 && $multiple) {
250 //if not found in main list, display all selected values that exist in backup list
251 $list_id = $backup_list;
253 $got_selected_backup = false;
254 if (!empty($backup_list)) {
255 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
256 while ($lrow_backup = sqlFetchArray($lres_backup)) {
257 $selectedValues = explode("|", $currvalue);
259 $optionValue = attr($lrow_backup['option_id']);
261 if (in_array($lrow_backup ['option_id'], $selectedValues)) {
262 $s .= "<option value='$optionValue'";
263 $s .= " selected";
264 $optionLabel = text(xl_list_label($lrow_backup ['title']));
265 $s .= ">$optionLabel</option>\n";
266 $got_selected_backup = true;
271 if (!$got_selected_backup) {
272 $selectedValues = explode("|", $currvalue);
273 foreach ($selectedValues as $selectedValue) {
274 $s .= "<option value='" . attr($selectedValue) . "'";
275 $s .= " selected";
276 $s .= ">* " . text($selectedValue) . " *</option>\n";
279 $s .= "</select>";
280 $fontTitle = xlt('Please choose a valid selection from the list.');
281 $fontText = xlt('Fix this');
282 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
284 } else {
285 $s .= "</select>";
288 return $s;
291 // Parsing for data type 31, static text.
292 function parse_static_text($frow)
294 $tmp = $frow['description'];
295 // Translate if it does not look like HTML.
296 if (substr($tmp, 0, 1) != '<') {
297 $tmp = nl2br(xl_layout_label($tmp));
299 $s = '';
300 if ($frow['source'] == 'D' || $frow['source'] == 'H') {
301 // Source is demographics or history. This case supports value substitution.
302 while (preg_match('/^(.*?)\{(\w+)\}(.*)$/', $tmp, $matches)) {
303 $s .= $matches[1];
304 $tmprow = $frow;
305 $tmprow['field_id'] = $matches[2];
306 $s .= lbf_current_value($tmprow, 0, 0);
307 $tmp = $matches[3];
310 $s .= $tmp;
311 return $s;
314 // $frow is a row from the layout_options table.
315 // $currvalue is the current value, if any, of the associated item.
317 function generate_form_field($frow, $currvalue)
319 global $rootdir, $date_init, $ISSUE_TYPES, $code_types, $membership_group_number;
321 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
323 $data_type = $frow['data_type'];
324 $field_id = $frow['field_id'];
325 $list_id = $frow['list_id'];
326 $backup_list = $frow['list_backup_id'];
328 // escaped variables to use in html
329 $field_id_esc= htmlspecialchars($field_id, ENT_QUOTES);
330 $list_id_esc = htmlspecialchars($list_id, ENT_QUOTES);
332 // Added 5-09 by BM - Translate description if applicable
333 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
335 // Support edit option T which assigns the (possibly very long) description as
336 // the default value.
337 if (isOption($frow['edit_options'], 'T') !== false) {
338 if (strlen($currescaped) == 0) {
339 $currescaped = $description;
342 // Description used in this way is not suitable as a title.
343 $description = '';
346 // added 5-2009 by BM to allow modification of the 'empty' text title field.
347 // Can pass $frow['empty_title'] with this variable, otherwise
348 // will default to 'Unassigned'.
349 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
350 // if make $frow['empty_title'] equal to 'SKIP'
351 $showEmpty = true;
352 if (isset($frow['empty_title'])) {
353 if ($frow['empty_title'] == "SKIP") {
354 //do not display an 'empty' choice
355 $showEmpty = false;
356 $empty_title = "Unassigned";
357 } else {
358 $empty_title = $frow['empty_title'];
360 } else {
361 $empty_title = "Unassigned";
364 $disabled = isOption($frow['edit_options'], '0') === false ? '' : 'disabled';
366 $lbfchange = (
367 strpos($frow['form_id'], 'LBF') === 0 ||
368 strpos($frow['form_id'], 'LBT') === 0 ||
369 $frow['form_id'] == 'DEM' ||
370 $frow['form_id'] == 'HIS'
371 ) ? "checkSkipConditions();" : "";
372 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
374 // generic single-selection list or Race and Ethnicity.
375 // These data types support backup lists.
376 if ($data_type == 1 || $data_type == 33) {
377 echo generate_select_list(
378 "form_$field_id",
379 $list_id,
380 $currvalue,
381 $description,
382 ($showEmpty ? $empty_title : ''),
384 $lbfchange,
386 ($disabled ? array('disabled' => 'disabled') : null),
387 false,
388 $backup_list
390 } // simple text field
391 elseif ($data_type == 2) {
392 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
393 $maxlength = $frow['max_length'];
394 $string_maxlength = "";
395 // if max_length is set to zero, then do not set a maxlength
396 if ($maxlength) {
397 $string_maxlength = "maxlength='".attr($maxlength)."'";
400 echo "<input type='text'" .
401 " class='form-control'" .
402 " name='form_$field_id_esc'" .
403 " id='form_$field_id_esc'" .
404 " size='$fldlength'" .
405 " $string_maxlength" .
406 " title='$description'" .
407 " value='$currescaped'";
408 $tmp = $lbfchange;
409 if (isOption($frow['edit_options'], 'C') !== false) {
410 $tmp .= "capitalizeMe(this);";
411 } elseif (isOption($frow['edit_options'], 'U') !== false) {
412 $tmp .= "this.value = this.value.toUpperCase();";
415 if ($tmp) {
416 echo " onchange='$tmp'";
419 $tmp = htmlspecialchars($GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
420 // If mask is for use at save time, treat as no mask.
421 if (strpos($tmp, '^') !== false) {
422 $tmp = '';
424 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
425 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
426 echo " onblur='maskblur(this,\"$tmp\")'";
429 if (isOption($frow['edit_options'], '1') !== false && strlen($currescaped) > 0) {
430 echo " readonly";
433 if ($disabled) {
434 echo ' disabled';
437 echo " />";
438 } // long or multi-line text field
439 elseif ($data_type == 3) {
440 $textCols = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
441 $textRows = htmlspecialchars($frow['fld_rows'], ENT_QUOTES);
442 echo "<textarea" .
443 " name='form_$field_id_esc'" .
444 " class='form-control'" .
445 " id='form_$field_id_esc'" .
446 " title='$description'" .
447 " cols='$textCols'" .
448 " rows='$textRows' $lbfonchange $disabled" .
449 ">" . $currescaped . "</textarea>";
450 } // date
451 elseif ($data_type == 4) {
452 $age_asof_date = ''; // optionalAge() sets this
453 $age_format = isOption($frow['edit_options'], 'A') === false ? 3 : 0;
454 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
455 if ($agestr) {
456 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
459 $onchange_string = '';
460 if (!$disabled && $agestr) {
461 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') " .
462 "updateAgeString('$field_id','$age_asof_date', $age_format, '$description')\"";
464 if ($data_type == 4) {
465 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
466 if (!$modtmp) {
467 $dateValue = oeFormatShortDate(substr($currescaped, 0, 10));
468 echo "<input type='text' size='10' class='datepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
469 " value='" . attr($dateValue) ."'";
470 } else {
471 $dateValue = oeFormatDateTime(substr($currescaped, 0, 20), 0);
472 echo "<input type='text' size='20' class='datetimepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
473 " value='" . attr($dateValue) . "'";
476 if (!$agestr) {
477 echo " title='$description'";
480 echo " $onchange_string $lbfonchange $disabled />";
482 // Optional display of age or gestational age.
483 if ($agestr) {
484 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
486 } // provider list, local providers only
487 elseif ($data_type == 10) {
488 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
489 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
490 "AND authorized = 1 " .
491 "ORDER BY lname, fname");
492 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
493 echo "<option value=''>" . xlt($empty_title) . "</option>";
494 $got_selected = false;
495 while ($urow = sqlFetchArray($ures)) {
496 $uname = text($urow['fname'] . ' ' . $urow['lname']);
497 $optionId = attr($urow['id']);
498 echo "<option value='$optionId'";
499 if ($urow['id'] == $currvalue) {
500 echo " selected";
501 $got_selected = true;
504 echo ">$uname</option>";
507 if (!$got_selected && $currvalue) {
508 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
509 echo "</select>";
510 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
511 } else {
512 echo "</select>";
514 } // provider list, including address book entries with an NPI number
515 elseif ($data_type == 11) {
516 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
517 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
518 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
519 "ORDER BY lname, fname");
520 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
521 echo " $lbfonchange $disabled>";
522 echo "<option value=''>" . xlt('Unassigned') . "</option>";
523 $got_selected = false;
524 while ($urow = sqlFetchArray($ures)) {
525 $uname = text($urow['fname'] . ' ' . $urow['lname']);
526 $optionId = attr($urow['id']);
527 echo "<option value='$optionId'";
528 if ($urow['id'] == $currvalue) {
529 echo " selected";
530 $got_selected = true;
533 echo ">$uname</option>";
536 if (!$got_selected && $currvalue) {
537 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
538 echo "</select>";
539 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
540 } else {
541 echo "</select>";
543 } // pharmacy list
544 elseif ($data_type == 12) {
545 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
546 echo " $lbfonchange $disabled>";
547 echo "<option value='0'></option>";
548 $pres = get_pharmacies();
549 $got_selected = false;
550 while ($prow = sqlFetchArray($pres)) {
551 $key = $prow['id'];
552 $optionValue = htmlspecialchars($key, ENT_QUOTES);
553 $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
554 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
555 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
556 echo "<option value='$optionValue'";
557 if ($currvalue == $key) {
558 echo " selected";
559 $got_selected = true;
562 echo ">$optionLabel</option>";
565 if (!$got_selected && $currvalue) {
566 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
567 echo "</select>";
568 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
569 } else {
570 echo "</select>";
572 } // squads
573 elseif ($data_type == 13) {
574 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
575 echo " $lbfonchange $disabled>";
576 echo "<option value=''>&nbsp;</option>";
577 $squads = acl_get_squads();
578 if ($squads) {
579 foreach ($squads as $key => $value) {
580 $optionValue = htmlspecialchars($key, ENT_QUOTES);
581 $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES);
582 echo "<option value='$optionValue'";
583 if ($currvalue == $key) {
584 echo " selected";
587 echo ">$optionLabel</option>\n";
591 echo "</select>";
592 } // Address book, preferring organization name if it exists and is not in
593 // parentheses, and excluding local users who are not providers.
594 // Supports "referred to" practitioners and facilities.
595 // Alternatively the letter L in edit_options means that abook_type
596 // must be "ord_lab", indicating types used with the procedure
597 // lab ordering system.
598 // Alternatively the letter O in edit_options means that abook_type
599 // must begin with "ord_", indicating types used with the procedure
600 // ordering system.
601 // Alternatively the letter V in edit_options means that abook_type
602 // must be "vendor", indicating the Vendor type.
603 // Alternatively the letter R in edit_options means that abook_type
604 // must be "dist", indicating the Distributor type.
605 elseif ($data_type == 14) {
606 if (isOption($frow['edit_options'], 'L') !== false) {
607 $tmp = "abook_type = 'ord_lab'";
608 } elseif (isOption($frow['edit_options'], 'O') !== false) {
609 $tmp = "abook_type LIKE 'ord\\_%'";
610 } elseif (isOption($frow['edit_options'], 'V') !== false) {
611 $tmp = "abook_type LIKE 'vendor%'";
612 } elseif (isOption($frow['edit_options'], 'R') !== false) {
613 $tmp = "abook_type LIKE 'dist'";
614 } else {
615 $tmp = "( username = '' OR authorized = 1 )";
618 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
619 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
620 "AND $tmp " .
621 "ORDER BY organization, lname, fname");
622 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
623 echo " $lbfonchange $disabled>";
624 echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES) . "</option>";
625 while ($urow = sqlFetchArray($ures)) {
626 $uname = $urow['organization'];
627 if (empty($uname) || substr($uname, 0, 1) == '(') {
628 $uname = $urow['lname'];
629 if ($urow['fname']) {
630 $uname .= ", " . $urow['fname'];
634 $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES);
635 $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES);
636 echo "<option value='$optionValue'";
637 // Failure to translate Local and External is not an error here;
638 // they are only used as internal flags and must not be translated!
639 $title = $urow['username'] ? 'Local' : 'External';
640 $optionTitle = htmlspecialchars($title, ENT_QUOTES);
641 echo " title='$optionTitle'";
642 if ($urow['id'] == $currvalue) {
643 echo " selected";
646 echo ">$optionLabel</option>";
649 echo "</select>";
650 } // A billing code. If description matches an existing code type then that type is used.
651 elseif ($data_type == 15) {
652 $codetype = '';
653 if (!empty($frow['description']) && isset($code_types[$frow['description']])) {
654 $codetype = $frow['description'];
656 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
657 $maxlength = $frow['max_length'];
658 $string_maxlength = "";
659 // if max_length is set to zero, then do not set a maxlength
660 if ($maxlength) {
661 $string_maxlength = "maxlength='".attr($maxlength)."'";
665 if (isOption($frow['edit_options'], '2') !== false && substr($frow['form_id'], 0, 3) == 'LBF') {
666 // Option "2" generates a hidden input for the codes, and a matching visible field
667 // displaying their descriptions. First step is computing the description string.
668 $currdescstring = '';
669 if (!empty($currvalue)) {
670 $relcodes = explode(';', $currvalue);
671 foreach ($relcodes as $codestring) {
672 if ($codestring === '') {
673 continue;
676 $code_text = lookup_code_descriptions($codestring);
677 if ($currdescstring !== '') {
678 $currdescstring .= '; ';
681 if (!empty($code_text)) {
682 $currdescstring .= $code_text;
683 } else {
684 $currdescstring .= $codestring;
689 $currdescstring = attr($currdescstring);
691 echo "<input type='text'" .
692 " name='form_$field_id_esc'" .
693 " id='form_related_code'" .
694 " size='$fldlength'" .
695 " value='$currescaped'" .
696 " style='display:none'" .
697 " $lbfonchange readonly $disabled />";
698 // Extra readonly input field for optional display of code description(s).
699 echo "<input type='text'" .
700 " name='form_$field_id_esc" . "__desc'" .
701 " size='$fldlength'" .
702 " title='$description'" .
703 " value='$currdescstring'";
704 if (!$disabled) {
705 echo " onclick='sel_related(this,\"$codetype\")'";
708 echo "class='form-control'";
709 echo " readonly $disabled />";
710 } else {
711 echo "<input type='text'" .
712 " name='form_$field_id_esc'" .
713 " id='form_related_code'" .
714 " size='$fldlength'" .
715 " $string_maxlength" .
716 " title='$description'" .
717 " value='$currescaped'";
718 if (!$disabled) {
719 echo " onclick='sel_related(this,\"$codetype\")'";
722 echo "class='form-control'";
723 echo " $lbfonchange readonly $disabled />";
725 } // insurance company list
726 elseif ($data_type == 16) {
727 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
728 echo "<option value='0'></option>";
729 $insprovs = getInsuranceProviders();
730 $got_selected = false;
731 foreach ($insprovs as $key => $ipname) {
732 $optionValue = htmlspecialchars($key, ENT_QUOTES);
733 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
734 echo "<option value='$optionValue'";
735 if ($currvalue == $key) {
736 echo " selected";
737 $got_selected = true;
740 echo ">$optionLabel</option>";
743 if (!$got_selected && $currvalue) {
744 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
745 echo "</select>";
746 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
747 } else {
748 echo "</select>";
750 } // issue types
751 elseif ($data_type == 17) {
752 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
753 echo "<option value='0'></option>";
754 $got_selected = false;
755 foreach ($ISSUE_TYPES as $key => $value) {
756 $optionValue = htmlspecialchars($key, ENT_QUOTES);
757 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
758 echo "<option value='$optionValue'";
759 if ($currvalue == $key) {
760 echo " selected";
761 $got_selected = true;
764 echo ">$optionLabel</option>";
767 if (!$got_selected && strlen($currvalue) > 0) {
768 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
769 echo "</select>";
770 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
771 } else {
772 echo "</select>";
774 } // Visit categories.
775 elseif ($data_type == 18) {
776 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
777 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
778 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'" .
779 " $lbfonchange $disabled>";
780 echo "<option value=''>" . xlt($empty_title) . "</option>";
781 $got_selected = false;
782 while ($crow = sqlFetchArray($cres)) {
783 $catid = $crow['pc_catid'];
784 if (($catid < 9 && $catid != 5) || $catid == 11) {
785 continue;
788 echo "<option value='" . attr($catid) . "'";
789 if ($catid == $currvalue) {
790 echo " selected";
791 $got_selected = true;
794 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
797 if (!$got_selected && $currvalue) {
798 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
799 echo "</select>";
800 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
801 } else {
802 echo "</select>";
804 } // a set of labeled checkboxes
805 elseif ($data_type == 21) {
806 // If no list then it's a single checkbox and its value is "Yes" or empty.
807 if (!$list_id) {
808 echo "<input type='checkbox' name='form_{$field_id_esc}' " .
809 "id='form_{$field_id_esc}' value='Yes' $lbfonchange";
810 if ($currvalue) {
811 echo " checked";
813 echo " $disabled />";
814 } else {
815 // In this special case, fld_length is the number of columns generated.
816 $cols = max(1, $frow['fld_length']);
817 $avalue = explode('|', $currvalue);
818 $lres = sqlStatement("SELECT * FROM list_options " .
819 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
820 echo "<table cellpadding='0' cellspacing='0' width='100%' title='".attr($description)."'>";
821 $tdpct = (int) (100 / $cols);
822 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
823 $option_id = $lrow['option_id'];
824 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
825 // if ($count) echo "<br />";
826 if ($count % $cols == 0) {
827 if ($count) {
828 echo "</tr>";
830 echo "<tr>";
832 echo "<td width='" . attr($tdpct) . "%' nowrap>";
833 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
834 "id='form_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
835 if (in_array($option_id, $avalue)) {
836 echo " checked";
838 // Added 5-09 by BM - Translate label if applicable
839 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
840 echo "</td>";
842 if ($count) {
843 echo "</tr>";
844 if ($count > $cols) {
845 // Add some space after multiple rows of checkboxes.
846 $cols = htmlspecialchars($cols, ENT_QUOTES);
847 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
850 echo "</table>";
852 } // a set of labeled text input fields
853 elseif ($data_type == 22) {
854 $tmp = explode('|', $currvalue);
855 $avalue = array();
856 foreach ($tmp as $value) {
857 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
858 $avalue[$matches[1]] = $matches[2];
862 $lres = sqlStatement("SELECT * FROM list_options " .
863 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
864 echo "<table cellpadding='0' cellspacing='0'>";
865 while ($lrow = sqlFetchArray($lres)) {
866 $option_id = $lrow['option_id'];
867 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
868 $maxlength = $frow['max_length'];
869 $string_maxlength = "";
870 // if max_length is set to zero, then do not set a maxlength
871 if ($maxlength) {
872 $string_maxlength = "maxlength='".attr($maxlength)."'";
875 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
877 // Added 5-09 by BM - Translate label if applicable
878 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
879 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
880 $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
881 echo "<td><input type='text'" .
882 " name='form_{$field_id_esc}[$option_id_esc]'" .
883 " id='form_{$field_id_esc}[$option_id_esc]'" .
884 " size='$fldlength'" .
885 " class='form-control'" .
886 " $string_maxlength" .
887 " value='$optionValue'";
888 echo " $lbfonchange $disabled /></td></tr>";
891 echo "</table>";
892 } // a set of exam results; 3 radio buttons and a text field:
893 elseif ($data_type == 23) {
894 $tmp = explode('|', $currvalue);
895 $avalue = array();
896 foreach ($tmp as $value) {
897 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
898 $avalue[$matches[1]] = $matches[2];
902 $maxlength = $frow['max_length'];
903 $string_maxlength = "";
904 // if max_length is set to zero, then do not set a maxlength
905 if ($maxlength) {
906 $string_maxlength = "maxlength='".attr($maxlength)."'";
909 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
910 $lres = sqlStatement("SELECT * FROM list_options " .
911 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
912 echo "<table cellpadding='0' cellspacing='0'>";
913 echo "<tr><td>&nbsp;</td><td class='bold'>" .
914 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
915 "&nbsp;</td><td class='bold'>" .
916 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
917 "<td class='bold'>" .
918 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
919 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
920 while ($lrow = sqlFetchArray($lres)) {
921 $option_id = $lrow['option_id'];
922 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
923 $restype = substr($avalue[$option_id], 0, 1);
924 $resnote = substr($avalue[$option_id], 2);
926 // Added 5-09 by BM - Translate label if applicable
927 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
929 for ($i = 0; $i < 3; ++$i) {
930 $inputValue = htmlspecialchars($i, ENT_QUOTES);
931 echo "<td><input type='radio'" .
932 " name='radio_{$field_id_esc}[$option_id_esc]'" .
933 " id='radio_{$field_id_esc}[$option_id_esc]'" .
934 " value='$inputValue' $lbfonchange";
935 if ($restype === "$i") {
936 echo " checked";
939 echo " $disabled /></td>";
942 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
943 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
944 echo "<td><input type='text'" .
945 " name='form_{$field_id_esc}[$option_id_esc]'" .
946 " id='form_{$field_id_esc}[$option_id_esc]'" .
947 " size='$fldlength'" .
948 " $string_maxlength" .
949 " value='$resnote' $disabled /></td>";
950 echo "</tr>";
953 echo "</table>";
954 } // the list of active allergies for the current patient
955 // this is read-only!
956 elseif ($data_type == 24) {
957 $query = "SELECT title, comments FROM lists WHERE " .
958 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
959 "ORDER BY begdate";
960 // echo "<!-- $query -->\n"; // debugging
961 $lres = sqlStatement($query, array($GLOBALS['pid']));
962 $count = 0;
963 while ($lrow = sqlFetchArray($lres)) {
964 if ($count++) {
965 echo "<br />";
968 echo htmlspecialchars($lrow['title'], ENT_NOQUOTES);
969 if ($lrow['comments']) {
970 echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
973 } // a set of labeled checkboxes, each with a text field:
974 elseif ($data_type == 25) {
975 $tmp = explode('|', $currvalue);
976 $avalue = array();
977 foreach ($tmp as $value) {
978 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
979 $avalue[$matches[1]] = $matches[2];
983 $maxlength = $frow['max_length'];
984 $string_maxlength = "";
985 // if max_length is set to zero, then do not set a maxlength
986 if ($maxlength) {
987 $string_maxlength = "maxlength='".attr($maxlength)."'";
990 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
991 $lres = sqlStatement("SELECT * FROM list_options " .
992 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
993 echo "<table cellpadding='0' cellspacing='0'>";
994 while ($lrow = sqlFetchArray($lres)) {
995 $option_id = $lrow['option_id'];
996 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
997 $restype = substr($avalue[$option_id], 0, 1);
998 $resnote = substr($avalue[$option_id], 2);
1000 // Added 5-09 by BM - Translate label if applicable
1001 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1003 $option_id = htmlspecialchars($option_id, ENT_QUOTES);
1004 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
1005 " id='check_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
1006 if ($restype) {
1007 echo " checked";
1010 echo " $disabled />&nbsp;</td>";
1011 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1012 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1013 echo "<td><input type='text'" .
1014 " name='form_{$field_id_esc}[$option_id_esc]'" .
1015 " id='form_{$field_id_esc}[$option_id_esc]'" .
1016 " size='$fldlength'" .
1017 " class='form-control' " .
1018 " $string_maxlength" .
1019 " value='$resnote' $disabled /></td>";
1020 echo "</tr>";
1023 echo "</table>";
1024 } // single-selection list with ability to add to it
1025 elseif ($data_type == 26) {
1026 echo generate_select_list(
1027 "form_$field_id",
1028 $list_id,
1029 $currvalue,
1030 $description,
1031 ($showEmpty ? $empty_title : ''),
1032 'addtolistclass_'.$list_id,
1033 $lbfchange,
1035 ($disabled ? array('disabled' => 'disabled') : null),
1036 false,
1037 $backup_list
1039 // show the add button if user has access to correct list
1040 $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES);
1041 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
1042 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
1043 if (aco_exist('lists', $list_id)) {
1044 // a specific aco exist for this list, so ensure access
1045 if (acl_check('lists', $list_id)) {
1046 echo $outputAddButton;
1048 } else {
1049 // no specific aco exist for this list, so check for access to 'default' list
1050 if (acl_check('lists', 'default')) {
1051 echo $outputAddButton;
1054 } // a set of labeled radio buttons
1055 elseif ($data_type == 27) {
1056 // In this special case, fld_length is the number of columns generated.
1057 $cols = max(1, $frow['fld_length']);
1058 // Support for edit option M.
1059 if (isOption($frow['edit_options'], 'M')) {
1060 ++$membership_group_number;
1063 $lres = sqlStatement("SELECT * FROM list_options " .
1064 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1065 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1066 $tdpct = (int) (100 / $cols);
1067 $got_selected = false;
1068 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1069 $option_id = $lrow['option_id'];
1070 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
1071 if ($count % $cols == 0) {
1072 if ($count) {
1073 echo "</tr>";
1075 echo "<tr>";
1077 echo "<td width='" . attr($tdpct) . "%'>";
1078 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
1079 " value='$option_id_esc' $lbfonchange";
1080 // Support for edit options M and m.
1081 if (isOption($frow['edit_options'], 'M')) {
1082 echo " class='form-control'";
1083 echo " onclick='checkGroupMembers(this, $membership_group_number);'";
1084 } else if (isOption($frow['edit_options'], 'm')) {
1085 echo " class='form-control lbf_memgroup_$membership_group_number'";
1086 } else {
1087 echo " class='form-control'";
1090 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1091 (strlen($currvalue) > 0 && $option_id == $currvalue)) {
1092 echo " checked";
1093 $got_selected = true;
1095 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1096 echo "</td>";
1099 if ($count) {
1100 echo "</tr>";
1101 if ($count > $cols) {
1102 // Add some space after multiple rows of radio buttons.
1103 $cols = htmlspecialchars($cols, ENT_QUOTES);
1104 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1108 echo "</table>";
1109 if (!$got_selected && strlen($currvalue) > 0) {
1110 $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES);
1111 $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES);
1112 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
1114 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1115 // VicarePlus :: A selection list box for smoking status:
1116 elseif ($data_type == 28 || $data_type == 32) {
1117 $tmp = explode('|', $currvalue);
1118 switch (count($tmp)) {
1119 case "4":
1120 $resnote = $tmp[0];
1121 $restype = $tmp[1];
1122 $resdate = oeFormatShortDate($tmp[2]);
1123 $reslist = $tmp[3];
1124 break;
1125 case "3":
1126 $resnote = $tmp[0];
1127 $restype = $tmp[1];
1128 $resdate = oeFormatShortDate($tmp[2]);
1129 break;
1130 case "2":
1131 $resnote = $tmp[0];
1132 $restype = $tmp[1];
1133 $resdate = "";
1134 break;
1135 case "1":
1136 $resnote = $tmp[0];
1137 $resdate = $restype = "";
1138 break;
1139 default:
1140 $restype = $resdate = $resnote = "";
1141 break;
1144 $maxlength = $frow['max_length'];
1145 $string_maxlength = "";
1146 // if max_length is set to zero, then do not set a maxlength
1147 if ($maxlength) {
1148 $string_maxlength = "maxlength='".attr($maxlength)."'";
1151 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1153 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1154 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1155 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1156 echo "<table cellpadding='0' cellspacing='0'>";
1157 echo "<tr>";
1158 if ($data_type == 28) {
1159 // input text
1160 echo "<td><input type='text'" .
1161 " name='form_$field_id_esc'" .
1162 " id='form_$field_id_esc'" .
1163 " size='$fldlength'" .
1164 " $string_maxlength" .
1165 " value='$resnote' $disabled />&nbsp;</td>";
1166 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1167 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1168 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1169 } elseif ($data_type == 32) {
1170 // input text
1171 echo "<tr><td><input type='text'" .
1172 " name='form_text_$field_id_esc'" .
1173 " id='form_text_$field_id_esc'" .
1174 " size='$fldlength'" .
1175 " class='form-control'" .
1176 " $string_maxlength" .
1177 " value='$resnote' $disabled />&nbsp;</td></tr>";
1178 echo "<td>";
1179 //Selection list for smoking status
1180 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1181 echo generate_select_list(
1182 "form_$field_id",
1183 $list_id,
1184 $reslist,
1185 $description,
1186 ($showEmpty ? $empty_title : ''),
1188 $onchange,
1190 ($disabled ? array('disabled' => 'disabled') : null)
1192 echo "</td>";
1193 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1196 // current
1197 echo "<td class='text' ><input type='radio'" .
1198 " name='radio_{$field_id_esc}'" .
1199 " id='radio_{$field_id_esc}[current]'" .
1200 " class='form-control'" .
1201 " value='current" . $field_id_esc . "' $lbfonchange";
1202 if ($restype == "current" . $field_id) {
1203 echo " checked";
1206 if ($data_type == 32) {
1207 echo " onClick='smoking_statusClicked(this)'";
1210 echo " />" . xlt('Current') . "&nbsp;</td>";
1211 // quit
1212 echo "<td class='text'><input type='radio'" .
1213 " name='radio_{$field_id_esc}'" .
1214 " id='radio_{$field_id_esc}[quit]'" .
1215 " class='form-control'" .
1216 " value='quit".$field_id_esc."' $lbfonchange";
1217 if ($restype == "quit" . $field_id) {
1218 echo " checked";
1221 if ($data_type == 32) {
1222 echo " onClick='smoking_statusClicked(this)'";
1225 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1226 // quit date
1227 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1228 " value='$resdate'" .
1229 " title='$description'" .
1230 " $disabled />";
1231 echo "&nbsp;</td>";
1232 // never
1233 echo "<td class='text'><input type='radio'" .
1234 " name='radio_{$field_id_esc}'" .
1235 " class='form-control'" .
1236 " id='radio_{$field_id_esc}[never]'" .
1237 " value='never" . $field_id_esc . "' $lbfonchange";
1238 if ($restype == "never" . $field_id) {
1239 echo " checked";
1242 if ($data_type == 32) {
1243 echo " onClick='smoking_statusClicked(this)'";
1246 echo " />" . xlt('Never') . "&nbsp;</td>";
1247 // Not Applicable
1248 echo "<td class='text'><input type='radio'" .
1249 " class='form-control' " .
1250 " name='radio_{$field_id}'" .
1251 " id='radio_{$field_id}[not_applicable]'" .
1252 " value='not_applicable" . $field_id . "' $lbfonchange";
1253 if ($restype == "not_applicable" . $field_id) {
1254 echo " checked";
1257 if ($data_type == 32) {
1258 echo " onClick='smoking_statusClicked(this)'";
1261 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1263 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1264 echo "<td class='text' ><div id='smoke_code'></div></td>";
1265 echo "</tr>";
1266 echo "</table>";
1267 } // static text. read-only, of course.
1268 elseif ($data_type == 31) {
1269 echo parse_static_text($frow);
1270 } //$data_type == 33
1271 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1272 //$data_type == 33
1274 elseif ($data_type == 34) {
1275 $arr = explode("|*|*|*|", $currvalue);
1276 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;'>";
1277 echo "<div id='form_{$field_id}_div' class='text-area' style='min-width:100pt'>" . $arr[0] . "</div>";
1278 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' class='form-control' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1279 echo "</a>";
1280 } //facilities drop-down list
1281 elseif ($data_type == 35) {
1282 if (empty($currvalue)) {
1283 $currvalue = 0;
1286 dropdown_facility(
1287 $selected = $currvalue,
1288 $name = "form_$field_id_esc",
1289 $allow_unspecified = true,
1290 $allow_allfacilities = false,
1291 $disabled,
1292 $lbfchange
1294 } //multiple select
1295 // supports backup list
1296 elseif ($data_type == 36) {
1297 echo generate_select_list(
1298 "form_$field_id",
1299 $list_id,
1300 $currvalue,
1301 $description,
1302 $showEmpty ? $empty_title : '',
1304 $lbfchange,
1306 null,
1307 true,
1308 $backup_list
1310 } // Canvas and related elements for browser-side image drawing.
1311 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1312 elseif ($data_type == 40) {
1313 // Unlike other field types, width and height are in pixels.
1314 $canWidth = intval($frow['fld_length']);
1315 $canHeight = intval($frow['fld_rows']);
1316 if (empty($currvalue)) {
1317 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1318 // If defined this is the filename of the default starting image.
1319 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1323 $mywidth = 50 + ($canWidth > 250 ? $canWidth : 250);
1324 $myheight = 31 + ($canHeight > 261 ? $canHeight : 261);
1325 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1326 // Hidden form field exists to send updated data to the server at submit time.
1327 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1328 // Hidden image exists to support initialization of the canvas.
1329 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1330 // $date_init is a misnomer but it's the place for browser-side setup logic.
1331 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1335 function generate_print_field($frow, $currvalue)
1337 global $rootdir, $date_init, $ISSUE_TYPES;
1339 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1341 $data_type = $frow['data_type'];
1342 $field_id = $frow['field_id'];
1343 $list_id = $frow['list_id'];
1344 $fld_length = $frow['fld_length'];
1345 $backup_list = $frow['list_backup_id'];
1347 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1349 // Can pass $frow['empty_title'] with this variable, otherwise
1350 // will default to 'Unassigned'.
1351 // If it is 'SKIP' then an empty text title is completely skipped.
1352 $showEmpty = true;
1353 if (isset($frow['empty_title'])) {
1354 if ($frow['empty_title'] == "SKIP") {
1355 //do not display an 'empty' choice
1356 $showEmpty = false;
1357 $empty_title = "Unassigned";
1358 } else {
1359 $empty_title = $frow['empty_title'];
1361 } else {
1362 $empty_title = "Unassigned";
1365 // generic single-selection list
1366 // Supports backup lists.
1367 if (false && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1368 if (empty($fld_length)) {
1369 if ($list_id == 'titles') {
1370 $fld_length = 3;
1371 } else {
1372 $fld_length = 10;
1376 $tmp = '';
1377 if ($currvalue) {
1378 $lrow = sqlQuery("SELECT title FROM list_options " .
1379 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1380 $tmp = xl_list_label($lrow['title']);
1381 if ($lrow == 0 && !empty($backup_list)) {
1382 // since primary list did not map, try to map to backup list
1383 $lrow = sqlQuery("SELECT title FROM list_options " .
1384 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1385 $tmp = xl_list_label($lrow['title']);
1388 if (empty($tmp)) {
1389 $tmp = "($currvalue)";
1393 /*****************************************************************
1394 echo "<input type='text'" .
1395 " size='$fld_length'" .
1396 " value='$tmp'" .
1397 " class='under'" .
1398 " />";
1399 *****************************************************************/
1400 if ($tmp === '') {
1401 $tmp = '&nbsp;';
1402 } else {
1403 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1406 echo $tmp;
1407 } // simple text field
1408 elseif ($data_type == 2 || $data_type == 15) {
1409 /*****************************************************************
1410 echo "<input type='text'" .
1411 " size='$fld_length'" .
1412 " value='$currescaped'" .
1413 " class='under'" .
1414 " />";
1415 *****************************************************************/
1416 if ($currescaped === '') {
1417 $currescaped = '&nbsp;';
1420 echo $currescaped;
1421 } // long or multi-line text field
1422 elseif ($data_type == 3) {
1423 $fldlength = htmlspecialchars($fld_length, ENT_QUOTES);
1424 $maxlength = htmlspecialchars($frow['fld_rows'], ENT_QUOTES);
1425 echo "<textarea" .
1426 " class='form-control' " .
1427 " cols='$fldlength'" .
1428 " rows='$maxlength'>" .
1429 $currescaped . "</textarea>";
1430 } // date
1431 elseif ($data_type == 4) {
1432 $age_asof_date = '';
1433 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
1434 if ($currvalue === '') {
1435 echo '&nbsp;';
1436 } else {
1437 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
1438 if (!$modtmp) {
1439 echo text(oeFormatShortDate($currvalue));
1440 } else {
1441 echo text(oeFormatDateTime($currvalue));
1443 if ($agestr) {
1444 echo "&nbsp;(" . text($agestr) . ")";
1447 } // provider list
1448 elseif ($data_type == 10 || $data_type == 11) {
1449 $tmp = '';
1450 if ($currvalue) {
1451 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1452 "WHERE id = ?", array($currvalue));
1453 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1454 if (empty($tmp)) {
1455 $tmp = "($currvalue)";
1459 /*****************************************************************
1460 echo "<input type='text'" .
1461 " size='$fld_length'" .
1462 " value='$tmp'" .
1463 " class='under'" .
1464 " />";
1465 *****************************************************************/
1466 if ($tmp === '') {
1467 $tmp = '&nbsp;';
1468 } else {
1469 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1472 echo $tmp;
1473 } // pharmacy list
1474 elseif ($data_type == 12) {
1475 $tmp = '';
1476 if ($currvalue) {
1477 $pres = get_pharmacies();
1478 while ($prow = sqlFetchArray($pres)) {
1479 $key = $prow['id'];
1480 if ($currvalue == $key) {
1481 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1482 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1483 $prow['line1'] . ' / ' . $prow['city'];
1487 if (empty($tmp)) {
1488 $tmp = "($currvalue)";
1492 /*****************************************************************
1493 echo "<input type='text'" .
1494 " size='$fld_length'" .
1495 " value='$tmp'" .
1496 " class='under'" .
1497 " />";
1498 *****************************************************************/
1499 if ($tmp === '') {
1500 $tmp = '&nbsp;';
1501 } else {
1502 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1505 echo $tmp;
1506 } // squads
1507 elseif ($data_type == 13) {
1508 $tmp = '';
1509 if ($currvalue) {
1510 $squads = acl_get_squads();
1511 if ($squads) {
1512 foreach ($squads as $key => $value) {
1513 if ($currvalue == $key) {
1514 $tmp = $value[3];
1519 if (empty($tmp)) {
1520 $tmp = "($currvalue)";
1524 /*****************************************************************
1525 echo "<input type='text'" .
1526 " size='$fld_length'" .
1527 " value='$tmp'" .
1528 " class='under'" .
1529 " />";
1530 *****************************************************************/
1531 if ($tmp === '') {
1532 $tmp = '&nbsp;';
1533 } else {
1534 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1537 echo $tmp;
1538 } // Address book.
1539 elseif ($data_type == 14) {
1540 $tmp = '';
1541 if ($currvalue) {
1542 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1543 "WHERE id = ?", array($currvalue));
1544 $uname = $urow['lname'];
1545 if ($urow['fname']) {
1546 $uname .= ", " . $urow['fname'];
1549 $tmp = $uname;
1550 if (empty($tmp)) {
1551 $tmp = "($currvalue)";
1555 /*****************************************************************
1556 echo "<input type='text'" .
1557 " size='$fld_length'" .
1558 " value='$tmp'" .
1559 " class='under'" .
1560 " />";
1561 *****************************************************************/
1562 if ($tmp === '') {
1563 $tmp = '&nbsp;';
1564 } else {
1565 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1568 echo $tmp;
1569 } // insurance company list
1570 elseif ($data_type == 16) {
1571 $tmp = '';
1572 if ($currvalue) {
1573 $insprovs = getInsuranceProviders();
1574 foreach ($insprovs as $key => $ipname) {
1575 if ($currvalue == $key) {
1576 $tmp = $ipname;
1580 if (empty($tmp)) {
1581 $tmp = "($currvalue)";
1585 if ($tmp === '') {
1586 $tmp = '&nbsp;';
1587 } else {
1588 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1591 echo $tmp;
1592 } // issue types
1593 elseif ($data_type == 17) {
1594 $tmp = '';
1595 if ($currvalue) {
1596 foreach ($ISSUE_TYPES as $key => $value) {
1597 if ($currvalue == $key) {
1598 $tmp = $value[1];
1602 if (empty($tmp)) {
1603 $tmp = "($currvalue)";
1607 if ($tmp === '') {
1608 $tmp = '&nbsp;';
1609 } else {
1610 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1613 echo $tmp;
1614 } // Visit categories.
1615 elseif ($data_type == 18) {
1616 $tmp = '';
1617 if ($currvalue) {
1618 $crow = sqlQuery(
1619 "SELECT pc_catid, pc_catname " .
1620 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1621 array($currvalue)
1623 $tmp = xl_appt_category($crow['pc_catname']);
1624 if (empty($tmp)) {
1625 $tmp = "($currvalue)";
1629 if ($tmp === '') {
1630 $tmp = '&nbsp;';
1631 } else {
1632 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1635 echo $tmp;
1636 } // a single checkbox or set of labeled checkboxes
1637 elseif ($data_type == 21) {
1638 if (!$list_id) {
1639 echo "<input type='checkbox'";
1640 if ($currvalue) {
1641 echo " checked";
1643 echo " />";
1644 } else {
1645 // In this special case, fld_length is the number of columns generated.
1646 $cols = max(1, $fld_length);
1647 $avalue = explode('|', $currvalue);
1648 $lres = sqlStatement("SELECT * FROM list_options " .
1649 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1650 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1651 $tdpct = (int) (100 / $cols);
1652 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1653 $option_id = $lrow['option_id'];
1654 if ($count % $cols == 0) {
1655 if ($count) {
1656 echo "</tr>";
1659 echo "<tr>";
1661 echo "<td width='" . attr($tdpct) . "%' nowrap>";
1662 echo "<input type='checkbox'";
1663 if (in_array($option_id, $avalue)) {
1664 echo " checked";
1666 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1667 echo "</td>";
1669 if ($count) {
1670 echo "</tr>";
1671 if ($count > $cols) {
1672 // Add some space after multiple rows of checkboxes.
1673 $cols = htmlspecialchars($cols, ENT_QUOTES);
1674 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1677 echo "</table>";
1679 } // a set of labeled text input fields
1680 elseif ($data_type == 22) {
1681 $tmp = explode('|', $currvalue);
1682 $avalue = array();
1683 foreach ($tmp as $value) {
1684 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1685 $avalue[$matches[1]] = $matches[2];
1689 $lres = sqlStatement("SELECT * FROM list_options " .
1690 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1691 echo "<table cellpadding='0' cellspacing='0'>";
1692 while ($lrow = sqlFetchArray($lres)) {
1693 $option_id = $lrow['option_id'];
1694 $fldlength = empty($fld_length) ? 20 : $fld_length;
1695 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1696 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1697 $inputValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
1698 echo "<td><input type='text'" .
1699 " class='form-control' " .
1700 " size='$fldlength'" .
1701 " value='$inputValue'" .
1702 " class='under'" .
1703 " /></td></tr>";
1706 echo "</table>";
1707 } // a set of exam results; 3 radio buttons and a text field:
1708 elseif ($data_type == 23) {
1709 $tmp = explode('|', $currvalue);
1710 $avalue = array();
1711 foreach ($tmp as $value) {
1712 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1713 $avalue[$matches[1]] = $matches[2];
1717 $fldlength = empty($fld_length) ? 20 : $fld_length;
1718 $lres = sqlStatement("SELECT * FROM list_options " .
1719 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1720 echo "<table cellpadding='0' cellspacing='0'>";
1721 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1722 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
1723 "&nbsp;</td><td class='bold'>" .
1724 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1725 "<td class='bold'>" .
1726 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1727 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1728 while ($lrow = sqlFetchArray($lres)) {
1729 $option_id = $lrow['option_id'];
1730 $restype = substr($avalue[$option_id], 0, 1);
1731 $resnote = substr($avalue[$option_id], 2);
1732 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1733 for ($i = 0; $i < 3; ++$i) {
1734 echo "<td><input type='radio'";
1735 if ($restype === "$i") {
1736 echo " checked";
1739 echo " /></td>";
1742 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1743 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1744 echo "<td><input type='text'" .
1745 " size='$fldlength'" .
1746 " value='$resnote'" .
1747 " class='under form-control' /></td>" .
1748 "</tr>";
1751 echo "</table>";
1752 } // the list of active allergies for the current patient
1753 // this is read-only!
1754 elseif ($data_type == 24) {
1755 $query = "SELECT title, comments FROM lists WHERE " .
1756 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1757 "ORDER BY begdate";
1758 $lres = sqlStatement($query, array($GLOBALS['pid']));
1759 $count = 0;
1760 while ($lrow = sqlFetchArray($lres)) {
1761 if ($count++) {
1762 echo "<br />";
1765 echo htmlspecialchars($lrow['title'], ENT_QUOTES);
1766 if ($lrow['comments']) {
1767 echo htmlspecialchars(' (' . $lrow['comments'] . ')', ENT_QUOTES);
1770 } // a set of labeled checkboxes, each with a text field:
1771 elseif ($data_type == 25) {
1772 $tmp = explode('|', $currvalue);
1773 $avalue = array();
1774 foreach ($tmp as $value) {
1775 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1776 $avalue[$matches[1]] = $matches[2];
1780 $fldlength = empty($fld_length) ? 20 : $fld_length;
1781 $lres = sqlStatement("SELECT * FROM list_options " .
1782 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1783 echo "<table cellpadding='0' cellspacing='0'>";
1784 while ($lrow = sqlFetchArray($lres)) {
1785 $option_id = $lrow['option_id'];
1786 $restype = substr($avalue[$option_id], 0, 1);
1787 $resnote = substr($avalue[$option_id], 2);
1788 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1789 echo "<td><input type='checkbox'";
1790 if ($restype) {
1791 echo " checked";
1794 echo " />&nbsp;</td>";
1795 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1796 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1797 echo "<td><input type='text'" .
1798 " size='$fldlength'" .
1799 " class='form-control' " .
1800 " value='$resnote'" .
1801 " class='under'" .
1802 " /></td>" .
1803 "</tr>";
1806 echo "</table>";
1807 } // a set of labeled radio buttons
1808 elseif ($data_type == 27 || $data_type == 1 || $data_type == 26 || $data_type == 33) {
1809 // In this special case, fld_length is the number of columns generated.
1810 $cols = max(1, $frow['fld_length']);
1811 $lres = sqlStatement("SELECT * FROM list_options " .
1812 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1813 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1814 $tdpct = (int) (100 / $cols);
1815 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1816 $option_id = $lrow['option_id'];
1817 if ($count % $cols == 0) {
1818 if ($count) {
1819 echo "</tr>";
1822 echo "<tr>";
1824 echo "<td width='" . attr($tdpct) . "%' nowrap>";
1825 echo "<input type='radio'";
1826 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1827 // Do not use defaults for these printable forms.
1828 echo " checked";
1831 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1832 echo "</td>";
1835 if ($count) {
1836 echo "</tr>";
1837 if ($count > $cols) {
1838 // Add some space after multiple rows of radio buttons.
1839 $cols = htmlspecialchars($cols, ENT_QUOTES);
1840 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1844 echo "</table>";
1845 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1846 elseif ($data_type == 28 || $data_type == 32) {
1847 $tmp = explode('|', $currvalue);
1848 switch (count($tmp)) {
1849 case "4":
1850 $resnote = $tmp[0];
1851 $restype = $tmp[1];
1852 $resdate = oeFormatShortDate($tmp[2]) ;
1853 $reslist = $tmp[3];
1854 break;
1855 case "3":
1856 $resnote = $tmp[0];
1857 $restype = $tmp[1];
1858 $resdate = oeFormatShortDate($tmp[2]);
1859 break;
1860 case "2":
1861 $resnote = $tmp[0];
1862 $restype = $tmp[1];
1863 $resdate = "";
1864 break;
1865 case "1":
1866 $resnote = $tmp[0];
1867 $resdate = $restype = "";
1868 break;
1869 default:
1870 $restype = $resdate = $resnote = "";
1871 break;
1874 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1875 echo "<table cellpadding='0' cellspacing='0'>";
1876 echo "<tr>";
1877 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1878 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1879 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1880 if ($data_type == 28) {
1881 echo "<td><input type='text'" .
1882 " size='$fldlength'" .
1883 " class='under'" .
1884 " value='$resnote' /></td>";
1885 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1886 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1887 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1888 } elseif ($data_type == 32) {
1889 echo "<tr><td><input type='text'" .
1890 " size='$fldlength'" .
1891 " class='under form-control'" .
1892 " value='$resnote' /></td></tr>";
1893 $fldlength = 30;
1894 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
1895 echo "<td><input type='text'" .
1896 " size='$fldlength'" .
1897 " class='under form-control'" .
1898 " value='$smoking_status_title' /></td>";
1899 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1902 echo "<td><input type='radio' class='form-control'";
1903 if ($restype == "current".$field_id) {
1904 echo " checked";
1907 echo "/>".htmlspecialchars(xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1909 echo "<td><input type='radio' class='form-control'";
1910 if ($restype == "current".$field_id) {
1911 echo " checked";
1914 echo "/>".htmlspecialchars(xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1916 echo "<td><input type='text' size='6'" .
1917 " value='$resdate'" .
1918 " class='under form-control'" .
1919 " /></td>";
1921 echo "<td><input type='radio' class='form-control'";
1922 if ($restype == "current".$field_id) {
1923 echo " checked";
1926 echo " />".htmlspecialchars(xl('Never'), ENT_NOQUOTES)."</td>";
1928 echo "<td><input type='radio' class='form-control'";
1929 if ($restype == "not_applicable".$field_id) {
1930 echo " checked";
1933 echo " />".htmlspecialchars(xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1934 echo "</tr>";
1935 echo "</table>";
1936 } // static text. read-only, of course.
1937 elseif ($data_type == 31) {
1938 echo parse_static_text($frow);
1939 } elseif ($data_type == 34) {
1940 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;'>";
1941 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1942 echo "<div style='display:none'><textarea name='form_{$field_id}' class='form-control' id='form_{$field_id}' stye='display:none'></textarea></div>";
1943 echo "</a>";
1944 } //facilities drop-down list
1945 elseif ($data_type == 35) {
1946 // In this special case, fld_length is the number of columns generated.
1947 $cols = max(1, $frow['fld_length']);
1948 $lres = sqlStatement("SELECT id, name FROM facility ORDER BY name");
1949 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1950 $tdpct = (int) (100 / $cols);
1951 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1952 $option_id = $lrow['id'];
1953 if ($count % $cols == 0) {
1954 if ($count) {
1955 echo "</tr>";
1957 echo "<tr>";
1959 echo "<td width='" . attr($tdpct) . "%'>";
1960 echo "<input type='radio'";
1961 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1962 // Do not use defaults for these printable forms.
1963 echo " checked";
1965 echo ">" . htmlspecialchars($lrow['name']);
1966 echo "</td>";
1968 if ($count) {
1969 echo "</tr>";
1970 if ($count > $cols) {
1971 // Add some space after multiple rows of radio buttons.
1972 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1975 echo "</table>";
1976 } //Multi-select
1977 // Supports backup lists.
1978 elseif ($data_type == 36) {
1979 if (empty($fld_length)) {
1980 if ($list_id == 'titles') {
1981 $fld_length = 3;
1982 } else {
1983 $fld_length = 10;
1987 $tmp = '';
1989 $values_array = explode("|", $currvalue);
1991 $i=0;
1992 foreach ($values_array as $value) {
1993 if ($value) {
1994 $lrow = sqlQuery("SELECT title FROM list_options " .
1995 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1996 $tmp = xl_list_label($lrow['title']);
1997 if ($lrow == 0 && !empty($backup_list)) {
1998 // since primary list did not map, try to map to backup list
1999 $lrow = sqlQuery("SELECT title FROM list_options " .
2000 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2001 $tmp = xl_list_label($lrow['title']);
2004 if (empty($tmp)) {
2005 $tmp = "($value)";
2009 if ($tmp === '') {
2010 $tmp = '&nbsp;';
2011 } else {
2012 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
2015 if ($i != 0 && $tmp != '&nbsp;') {
2016 echo ",";
2019 echo $tmp;
2020 $i++;
2022 } // Image from canvas drawing
2023 elseif ($data_type == 40) {
2024 if ($currvalue) {
2025 echo "<img src='" . attr($currvalue) . "'>";
2030 function generate_display_field($frow, $currvalue)
2032 global $ISSUE_TYPES, $facilityService;
2034 $data_type = $frow['data_type'];
2035 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2036 $list_id = $frow['list_id'];
2037 $backup_list = isset($frow['list_backup_id']) ? $frow['list_backup_id'] : null;
2039 $s = '';
2041 // generic selection list or the generic selection list with add on the fly
2042 // feature
2043 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
2044 $lrow = sqlQuery("SELECT title FROM list_options " .
2045 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2046 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2047 //if there is no matching value in the corresponding lists check backup list
2048 // only supported in data types 1,26,33
2049 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2050 $lrow = sqlQuery("SELECT title FROM list_options " .
2051 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2052 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2054 // If match is not found in main and backup lists, return the key with exclamation mark
2055 if ($s == '') {
2056 $s = nl2br(text(xl_list_label($currvalue))).
2057 '<sup> <i class="fa fas fa-exclamation-circle ml-1"></i></sup>';
2059 } // simple text field
2060 elseif ($data_type == 2) {
2061 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2062 } // long or multi-line text field
2063 elseif ($data_type == 3) {
2064 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2065 } // date
2066 elseif ($data_type == 4) {
2067 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
2068 $s = '';
2069 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2070 $age_asof_date = '';
2071 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
2072 if ($currvalue === '') {
2073 $s .= '&nbsp;';
2074 } else {
2075 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
2076 if (!$modtmp) {
2077 $s .= text(oeFormatShortDate($currvalue));
2078 } else {
2079 $s .= text(oeFormatDateTime($currvalue));
2081 if ($agestr) {
2082 $s .= "&nbsp;(" . text($agestr) . ")";
2085 } // provider
2086 elseif ($data_type == 10 || $data_type == 11) {
2087 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2088 "WHERE id = ?", array($currvalue));
2089 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']), ENT_NOQUOTES);
2090 } // pharmacy list
2091 elseif ($data_type == 12) {
2092 $pres = get_pharmacies();
2093 while ($prow = sqlFetchArray($pres)) {
2094 $key = $prow['id'];
2095 if ($currvalue == $key) {
2096 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
2097 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2098 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
2101 } // squads
2102 elseif ($data_type == 13) {
2103 $squads = acl_get_squads();
2104 if ($squads) {
2105 foreach ($squads as $key => $value) {
2106 if ($currvalue == $key) {
2107 $s .= htmlspecialchars($value[3], ENT_NOQUOTES);
2111 } // address book
2112 elseif ($data_type == 14) {
2113 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
2114 "WHERE id = ?", array($currvalue));
2115 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
2116 if ($urow['organization'] !="") {
2117 $uname = $urow['organization'];
2118 } else {
2119 $uname = $urow['lname'];
2120 if ($urow['fname']) {
2121 $uname .= ", " . $urow['fname'];
2125 $s = htmlspecialchars($uname, ENT_NOQUOTES);
2126 } // billing code
2127 elseif ($data_type == 15) {
2128 $s = '';
2129 if (!empty($currvalue)) {
2130 $relcodes = explode(';', $currvalue);
2131 foreach ($relcodes as $codestring) {
2132 if ($codestring === '') {
2133 continue;
2135 $tmp = lookup_code_descriptions($codestring);
2136 if ($s !== '') {
2137 $s .= '; ';
2139 if (!empty($tmp)) {
2140 $s .= $tmp;
2141 } else {
2142 $s .= $codestring . ' (' . xl('not found') . ')';
2146 } // insurance company list
2147 elseif ($data_type == 16) {
2148 $insprovs = getInsuranceProviders();
2149 foreach ($insprovs as $key => $ipname) {
2150 if ($currvalue == $key) {
2151 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
2154 } // issue types
2155 elseif ($data_type == 17) {
2156 foreach ($ISSUE_TYPES as $key => $value) {
2157 if ($currvalue == $key) {
2158 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
2161 } // visit category
2162 elseif ($data_type == 18) {
2163 $crow = sqlQuery(
2164 "SELECT pc_catid, pc_catname " .
2165 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2166 array($currvalue)
2168 $s = htmlspecialchars($crow['pc_catname'], ENT_NOQUOTES);
2169 } // a single checkbox or set of labeled checkboxes
2170 elseif ($data_type == 21) {
2171 if (!$list_id) {
2172 $s .= $currvalue ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2173 } else {
2174 // In this special case, fld_length is the number of columns generated.
2175 $cols = max(1, $frow['fld_length']);
2176 $avalue = explode('|', $currvalue);
2177 $lres = sqlStatement("SELECT * FROM list_options " .
2178 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2179 $s .= "<table cellspacing='0' cellpadding='0'>";
2180 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2181 $option_id = $lrow['option_id'];
2182 $option_id_esc = text($option_id);
2183 if ($count % $cols == 0) {
2184 if ($count) {
2185 $s .= "</tr>";
2187 $s .= "<tr>";
2189 $s .= "<td nowrap>";
2190 $checked = in_array($option_id, $avalue);
2191 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2192 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2193 $s .= "</td>";
2195 if ($count) {
2196 $s .= "</tr>";
2198 $s .= "</table>";
2200 } // a set of labeled text input fields
2201 elseif ($data_type == 22) {
2202 $tmp = explode('|', $currvalue);
2203 $avalue = array();
2204 foreach ($tmp as $value) {
2205 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2206 $avalue[$matches[1]] = $matches[2];
2210 $lres = sqlStatement("SELECT * FROM list_options " .
2211 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2212 $s .= "<table cellpadding='0' cellspacing='0'>";
2213 while ($lrow = sqlFetchArray($lres)) {
2214 $option_id = $lrow['option_id'];
2215 if (empty($avalue[$option_id])) {
2216 continue;
2219 // Added 5-09 by BM - Translate label if applicable
2220 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . ":&nbsp;</td>";
2222 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id], ENT_NOQUOTES) . "</td></tr>";
2225 $s .= "</table>";
2226 } // a set of exam results; 3 radio buttons and a text field:
2227 elseif ($data_type == 23) {
2228 $tmp = explode('|', $currvalue);
2229 $avalue = array();
2230 foreach ($tmp as $value) {
2231 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2232 $avalue[$matches[1]] = $matches[2];
2236 $lres = sqlStatement("SELECT * FROM list_options " .
2237 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2238 $s .= "<table cellpadding='0' cellspacing='0'>";
2239 while ($lrow = sqlFetchArray($lres)) {
2240 $option_id = $lrow['option_id'];
2241 $restype = substr($avalue[$option_id], 0, 1);
2242 $resnote = substr($avalue[$option_id], 2);
2243 if (empty($restype) && empty($resnote)) {
2244 continue;
2247 // Added 5-09 by BM - Translate label if applicable
2248 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2250 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
2251 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2252 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2253 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2254 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2255 $s .= "</tr>";
2258 $s .= "</table>";
2259 } // the list of active allergies for the current patient
2260 elseif ($data_type == 24) {
2261 $query = "SELECT title, comments FROM lists WHERE " .
2262 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2263 "ORDER BY begdate";
2264 // echo "<!-- $query -->\n"; // debugging
2265 $lres = sqlStatement($query, array($GLOBALS['pid']));
2266 $count = 0;
2267 while ($lrow = sqlFetchArray($lres)) {
2268 if ($count++) {
2269 $s .= "<br />";
2272 $s .= htmlspecialchars($lrow['title'], ENT_NOQUOTES);
2273 if ($lrow['comments']) {
2274 $s .= ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
2277 } // a set of labeled checkboxes, each with a text field:
2278 elseif ($data_type == 25) {
2279 $tmp = explode('|', $currvalue);
2280 $avalue = array();
2281 foreach ($tmp as $value) {
2282 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2283 $avalue[$matches[1]] = $matches[2];
2287 $lres = sqlStatement("SELECT * FROM list_options " .
2288 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2289 $s .= "<table cellpadding='0' cellspacing='0'>";
2290 while ($lrow = sqlFetchArray($lres)) {
2291 $option_id = $lrow['option_id'];
2292 $restype = substr($avalue[$option_id], 0, 1);
2293 $resnote = substr($avalue[$option_id], 2);
2294 if (empty($restype) && empty($resnote)) {
2295 continue;
2298 // Added 5-09 by BM - Translate label if applicable
2299 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2301 $restype = $restype ? xl('Yes') : xl('No');
2302 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2303 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2304 $s .= "</tr>";
2307 $s .= "</table>";
2308 } // a set of labeled radio buttons
2309 elseif ($data_type == 27) {
2310 // In this special case, fld_length is the number of columns generated.
2311 $cols = max(1, $frow['fld_length']);
2312 $lres = sqlStatement("SELECT * FROM list_options " .
2313 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2314 $s .= "<table cellspacing='0' cellpadding='0'>";
2315 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2316 $option_id = $lrow['option_id'];
2317 $option_id_esc = text($option_id);
2318 if ($count % $cols == 0) {
2319 if ($count) {
2320 $s .= "</tr>";
2322 $s .= "<tr>";
2324 $s .= "<td nowrap>";
2325 $checked = ((strlen($currvalue) == 0 && $lrow['is_default']) ||
2326 (strlen($currvalue) > 0 && $option_id == $currvalue));
2327 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2328 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2329 $s .= "</td>";
2331 if ($count) {
2332 $s .= "</tr>";
2334 $s .= "</table>";
2335 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2336 // VicarePlus :: A selection list for smoking status.
2337 elseif ($data_type == 28 || $data_type == 32) {
2338 $tmp = explode('|', $currvalue);
2339 switch (count($tmp)) {
2340 case "4":
2341 $resnote = $tmp[0];
2342 $restype = $tmp[1];
2343 $resdate = oeFormatShortDate($tmp[2]);
2344 $reslist = $tmp[3];
2345 break;
2346 case "3":
2347 $resnote = $tmp[0];
2348 $restype = $tmp[1];
2349 $resdate = oeFormatShortDate($tmp[2]);
2350 break;
2351 case "2":
2352 $resnote = $tmp[0];
2353 $restype = $tmp[1];
2354 $resdate = "";
2355 break;
2356 case "1":
2357 $resnote = $tmp[0];
2358 $resdate = $restype = "";
2359 break;
2360 default:
2361 $restype = $resdate = $resnote = "";
2362 break;
2365 $s .= "<table cellpadding='0' cellspacing='0'>";
2367 $s .= "<tr>";
2368 $res = "";
2369 if ($restype == "current".$field_id) {
2370 $res = xl('Current');
2373 if ($restype == "quit".$field_id) {
2374 $res = xl('Quit');
2377 if ($restype == "never".$field_id) {
2378 $res = xl('Never');
2381 if ($restype == "not_applicable".$field_id) {
2382 $res = xl('N/A');
2385 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2386 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2387 if ($data_type == 28) {
2388 if (!empty($resnote)) {
2389 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2391 } //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2392 elseif ($data_type == 32) {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2393 $smoke_codes = getSmokeCodes();
2394 if (!empty($reslist)) {
2395 if ($smoke_codes[$reslist]!="") {
2396 $code_desc = "( ".$smoke_codes[$reslist]." )";
2399 $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>";
2402 if (!empty($resnote)) {
2403 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2407 if (!empty($res)) {
2408 $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'), ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res, ENT_NOQUOTES) . "&nbsp;</td>";
2411 if ($restype == "quit".$field_id) {
2412 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate, ENT_NOQUOTES) . "&nbsp;</td>";
2415 $s .= "</tr>";
2416 $s .= "</table>";
2417 } // static text. read-only, of course.
2418 elseif ($data_type == 31) {
2419 $s .= parse_static_text($frow);
2420 } elseif ($data_type == 34) {
2421 $arr = explode("|*|*|*|", $currvalue);
2422 for ($i=0; $i<sizeof($arr); $i++) {
2423 $s.=$arr[$i];
2425 } // facility
2426 elseif ($data_type == 35) {
2427 $urow = $facilityService->getById($currvalue);
2428 $s = htmlspecialchars($urow['name'], ENT_NOQUOTES);
2429 } // Multi select
2430 // Supports backup lists
2431 elseif ($data_type == 36) {
2432 $values_array = explode("|", $currvalue);
2433 $i = 0;
2434 foreach ($values_array as $value) {
2435 $lrow = sqlQuery("SELECT title FROM list_options " .
2436 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2437 if ($lrow == 0 && !empty($backup_list)) {
2438 //use back up list
2439 $lrow = sqlQuery("SELECT title FROM list_options " .
2440 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2443 if ($i > 0) {
2444 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2445 } else {
2446 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2449 $i++;
2451 } // Image from canvas drawing
2452 elseif ($data_type == 40) {
2453 if ($currvalue) {
2454 $s .= "<img src='" . attr($currvalue) . "'>";
2458 return $s;
2461 // Generate plain text versions of selected LBF field types.
2462 // Currently used by interface/patient_file/download_template.php and interface/main/finder/dynamic_finder_ajax.php.
2463 // More field types might need to be supported here in the future.
2465 function generate_plaintext_field($frow, $currvalue)
2467 global $ISSUE_TYPES;
2469 $data_type = $frow['data_type'];
2470 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2471 $list_id = $frow['list_id'];
2472 $backup_list = $frow['backup_list'];
2473 $s = '';
2475 // generic selection list or the generic selection list with add on the fly
2476 // feature, or radio buttons
2477 // Supports backup lists (for datatypes 1,26,33)
2478 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2479 $lrow = sqlQuery("SELECT title FROM list_options " .
2480 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2481 $s = xl_list_label($lrow['title']);
2482 //if there is no matching value in the corresponding lists check backup list
2483 // only supported in data types 1,26,33
2484 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2485 $lrow = sqlQuery("SELECT title FROM list_options " .
2486 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2487 $s = xl_list_label($lrow['title']);
2489 } // simple or long text field
2490 elseif ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2491 $s = $currvalue;
2492 } // date
2493 elseif ($data_type == 4) {
2494 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
2495 if (!$modtmp) {
2496 $s = text(oeFormatShortDate($currvalue));
2497 } else {
2498 $s = text(oeFormatDateTime($currvalue));
2500 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2501 $age_asof_date = '';
2502 // Optional display of age or gestational age.
2503 $tmp = optionalAge($frow, $currvalue, $age_asof_date, $description);
2504 if ($tmp) {
2505 $s .= ' ' . $tmp;
2507 } // provider
2508 elseif ($data_type == 10 || $data_type == 11) {
2509 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2510 "WHERE id = ?", array($currvalue));
2511 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2512 } // pharmacy list
2513 elseif ($data_type == 12) {
2514 $pres = get_pharmacies();
2515 while ($prow = sqlFetchArray($pres)) {
2516 $key = $prow['id'];
2517 if ($currvalue == $key) {
2518 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2519 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2520 $prow['line1'] . ' / ' . $prow['city'];
2523 } // address book
2524 elseif ($data_type == 14) {
2525 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2526 "WHERE id = ?", array($currvalue));
2527 $uname = $urow['lname'];
2528 if ($urow['fname']) {
2529 $uname .= ", " . $urow['fname'];
2532 $s = $uname;
2533 } // insurance company list
2534 elseif ($data_type == 16) {
2535 $insprovs = getInsuranceProviders();
2536 foreach ($insprovs as $key => $ipname) {
2537 if ($currvalue == $key) {
2538 $s .= $ipname;
2541 } // issue type
2542 elseif ($data_type == 17) {
2543 foreach ($ISSUE_TYPES as $key => $value) {
2544 if ($currvalue == $key) {
2545 $s .= $value[1];
2548 } // visit category
2549 elseif ($data_type == 18) {
2550 $crow = sqlQuery(
2551 "SELECT pc_catid, pc_catname " .
2552 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2553 array($currvalue)
2555 $s = $crow['pc_catname'];
2556 } // a set of labeled checkboxes
2557 elseif ($data_type == 21) {
2558 if (!$list_id) {
2559 $s .= $currvalue ? xlt('Yes') : xlt('No');
2560 } else {
2561 $avalue = explode('|', $currvalue);
2562 $lres = sqlStatement("SELECT * FROM list_options " .
2563 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2564 $count = 0;
2565 while ($lrow = sqlFetchArray($lres)) {
2566 $option_id = $lrow['option_id'];
2567 if (in_array($option_id, $avalue)) {
2568 if ($count++) {
2569 $s .= "; ";
2571 $s .= xl_list_label($lrow['title']);
2575 } // a set of labeled text input fields
2576 elseif ($data_type == 22) {
2577 $tmp = explode('|', $currvalue);
2578 $avalue = array();
2579 foreach ($tmp as $value) {
2580 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2581 $avalue[$matches[1]] = $matches[2];
2585 $lres = sqlStatement("SELECT * FROM list_options " .
2586 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2587 while ($lrow = sqlFetchArray($lres)) {
2588 $option_id = $lrow['option_id'];
2589 if (empty($avalue[$option_id])) {
2590 continue;
2593 if ($s !== '') {
2594 $s .= '; ';
2597 $s .= xl_list_label($lrow['title']) . ': ';
2598 $s .= $avalue[$option_id];
2600 } // A set of exam results; 3 radio buttons and a text field.
2601 // This shows abnormal results only.
2602 elseif ($data_type == 23) {
2603 $tmp = explode('|', $currvalue);
2604 $avalue = array();
2605 foreach ($tmp as $value) {
2606 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2607 $avalue[$matches[1]] = $matches[2];
2611 $lres = sqlStatement("SELECT * FROM list_options " .
2612 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2613 while ($lrow = sqlFetchArray($lres)) {
2614 $option_id = $lrow['option_id'];
2615 $restype = substr($avalue[$option_id], 0, 1);
2616 $resnote = substr($avalue[$option_id], 2);
2617 if (empty($restype) && empty($resnote)) {
2618 continue;
2621 if ($restype != '2') {
2622 continue; // show abnormal results only
2625 if ($s !== '') {
2626 $s .= '; ';
2629 $s .= xl_list_label($lrow['title']);
2630 if (!empty($resnote)) {
2631 $s .= ': ' . $resnote;
2634 } // the list of active allergies for the current patient
2635 elseif ($data_type == 24) {
2636 $query = "SELECT title, comments FROM lists WHERE " .
2637 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2638 "ORDER BY begdate";
2639 $lres = sqlStatement($query, array($GLOBALS['pid']));
2640 $count = 0;
2641 while ($lrow = sqlFetchArray($lres)) {
2642 if ($count++) {
2643 $s .= "; ";
2646 $s .= $lrow['title'];
2647 if ($lrow['comments']) {
2648 $s .= ' (' . $lrow['comments'] . ')';
2651 } // a set of labeled checkboxes, each with a text field:
2652 elseif ($data_type == 25) {
2653 $tmp = explode('|', $currvalue);
2654 $avalue = array();
2655 foreach ($tmp as $value) {
2656 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2657 $avalue[$matches[1]] = $matches[2];
2661 $lres = sqlStatement("SELECT * FROM list_options " .
2662 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2663 while ($lrow = sqlFetchArray($lres)) {
2664 $option_id = $lrow['option_id'];
2665 $restype = substr($avalue[$option_id], 0, 1);
2666 $resnote = substr($avalue[$option_id], 2);
2667 if (empty($restype) && empty($resnote)) {
2668 continue;
2671 if ($s !== '') {
2672 $s .= '; ';
2675 $s .= xl_list_label($lrow['title']);
2676 $restype = $restype ? xl('Yes') : xl('No');
2677 $s .= $restype;
2678 if ($resnote) {
2679 $s .= ' ' . $resnote;
2682 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2683 // VicarePlus :: A selection list for smoking status.
2684 elseif ($data_type == 28 || $data_type == 32) {
2685 $tmp = explode('|', $currvalue);
2686 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2687 $restype = count($tmp) > 1 ? $tmp[1] : '';
2688 $resdate = count($tmp) > 2 ? oeFormatShortDate($tmp[2]) : '';
2689 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2690 $res = "";
2691 if ($restype == "current" . $field_id) {
2692 $res = xl('Current');
2695 if ($restype == "quit" . $field_id) {
2696 $res = xl('Quit');
2699 if ($restype == "never" . $field_id) {
2700 $res = xl('Never');
2703 if ($restype == "not_applicable". $field_id) {
2704 $res = xl('N/A');
2707 if ($data_type == 28) {
2708 if (!empty($resnote)) {
2709 $s .= $resnote;
2711 } // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2712 elseif ($data_type == 32) {
2713 if (!empty($reslist)) {
2714 $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
2717 if (!empty($resnote)) {
2718 $s .= ' ' . $resnote;
2722 if (!empty($res)) {
2723 if ($s !== '') {
2724 $s .= ' ';
2727 $s .= xl('Status') . ' ' . $res;
2730 if ($restype == "quit".$field_id) {
2731 if ($s !== '') {
2732 $s .= ' ';
2735 $s .= $resdate;
2737 } // Multi select
2738 // Supports backup lists
2739 elseif ($data_type == 36) {
2740 $values_array = explode("|", $currvalue);
2742 $i = 0;
2743 foreach ($values_array as $value) {
2744 $lrow = sqlQuery("SELECT title FROM list_options " .
2745 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2747 if ($lrow == 0 && !empty($backup_list)) {
2748 //use back up list
2749 $lrow = sqlQuery("SELECT title FROM list_options " .
2750 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2753 if ($i > 0) {
2754 $s = $s . ", " . xl_list_label($lrow['title']);
2755 } else {
2756 $s = xl_list_label($lrow['title']);
2759 $i++;
2763 return $s;
2766 $CPR = 4; // cells per row of generic data
2767 $last_group = '';
2768 $cell_count = 0;
2769 $item_count = 0;
2771 function disp_end_cell()
2773 global $item_count, $cell_count;
2774 if ($item_count > 0) {
2775 echo "</td>";
2776 $item_count = 0;
2780 function disp_end_row()
2782 global $cell_count, $CPR;
2783 disp_end_cell();
2784 if ($cell_count > 0) {
2785 for (; $cell_count < $CPR;
2786 ++$cell_count) {
2787 echo "<td></td>";
2790 echo "</tr>\n";
2791 $cell_count = 0;
2795 function disp_end_group()
2797 global $last_group;
2798 if (strlen($last_group) > 0) {
2799 disp_end_row();
2803 // Accumulate action conditions into a JSON expression for the browser side.
2804 function accumActionConditions($field_id, &$condition_str, &$condarr)
2806 $conditions = empty($condarr) ? array() : unserialize($condarr);
2807 $action = 'skip';
2808 foreach ($conditions as $key => $condition) {
2809 if ($key === 'action') {
2810 // If specified this should be the first array item.
2811 if ($condition) {
2812 $action = $condition;
2814 continue;
2816 if (empty($condition['id'])) {
2817 continue;
2819 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2820 if ($condition_str) {
2821 $condition_str .= ",\n";
2823 $condition_str .= "{" .
2824 "target:" . js_escape($field_id) . ", " .
2825 "action:" . js_escape($action) . ", " .
2826 "id:" . js_escape($condition['id']) . ", " .
2827 "itemid:" . js_escape($condition['itemid']) . ", " .
2828 "operator:" . js_escape($condition['operator']) . ", " .
2829 "value:" . js_escape($condition['value']) . ", " .
2830 "andor:" . js_escape($andor) . "}";
2834 // This checks if the given field with the given value should have an action applied.
2835 // Originally the only action was skip, but now you can also set the field to a specified value.
2836 // It somewhat mirrors the checkSkipConditions function in options.js.php.
2837 // If you use this for multiple layouts in the same script, you should
2838 // clear $sk_layout_items before each layout.
2839 function isSkipped(&$frow, $currvalue)
2841 global $sk_layout_items;
2843 // Accumulate an array of the encountered fields and their values.
2844 // It is assumed that fields appear before they are tested by another field.
2845 // TBD: Bad assumption?
2846 $field_id = $frow['field_id'];
2847 if (!is_array($sk_layout_items)) {
2848 $sk_layout_items = array();
2850 $sk_layout_items[$field_id] = array('row' => $frow, 'value' => $currvalue);
2852 if (empty($frow['conditions'])) {
2853 return false;
2856 $skiprows = unserialize($frow['conditions']);
2857 $prevandor = '';
2858 $prevcond = false;
2859 $datatype = $frow['data_type'];
2860 $action = 'skip'; // default action if none specified
2862 foreach ($skiprows as $key => $skiprow) {
2863 // id referenced field id
2864 // itemid referenced array key if applicable
2865 // operator "eq", "ne", "se" or "ns"
2866 // value if eq or ne, some string to compare with
2867 // andor "and", "or" or empty
2869 if ($key === 'action') {
2870 // Action value is a string. It can be "skip", or "value=" followed by a value.
2871 $action = $skiprow;
2872 continue;
2875 if (empty($skiprow['id'])) {
2876 continue;
2879 $id = $skiprow['id'];
2880 if (!isset($sk_layout_items[$id])) {
2881 error_log("Function isSkipped() cannot find skip source field '$id'.");
2882 continue;
2884 $itemid = $skiprow['itemid'];
2885 $operator = $skiprow['operator'];
2886 $skipval = $skiprow['value'];
2887 $srcvalue = $sk_layout_items[$id]['value'];
2888 $src_datatype = $sk_layout_items[$id]['row']['data_type'];
2889 $src_list_id = $sk_layout_items[$id]['row']['list_id'];
2891 // Some data types use itemid and we have to dig for their value.
2892 if ($src_datatype == 21 && $src_list_id) { // array of checkboxes
2893 $tmp = explode('|', $srcvalue);
2894 $srcvalue = in_array($itemid, $tmp);
2895 } elseif ($src_datatype == 22 || $src_datatype == 23 || $src_datatype == 25) {
2896 $tmp = explode('|', $srcvalue);
2897 $srcvalue = '';
2898 foreach ($tmp as $tmp2) {
2899 if (strpos($tmp2, "$itemid:") === 0) {
2900 if ($datatype == 22) {
2901 $srcvalue = substr($tmp2, strlen($itemid) + 1);
2902 } else {
2903 $srcvalue = substr($tmp2, strlen($itemid) + 1, 1);
2909 // Compute the result of the test for this condition row.
2910 // PHP's looseness with variable type conversion helps us here.
2911 $condition = false;
2912 if ($operator == 'eq') {
2913 $condition = $srcvalue == $skipval;
2914 } elseif ($operator == 'ne') {
2915 $condition = $srcvalue != $skipval;
2916 } elseif ($operator == 'se') {
2917 $condition = $srcvalue == true;
2918 } elseif ($operator == 'ns') {
2919 $condition = $srcvalue != true;
2920 } else {
2921 error_log("Unknown skip operator '$operator' for field '$field_id'.");
2924 // Logic to accumulate multiple conditions for the same target.
2925 if ($prevandor == 'and') {
2926 $condition = $condition && $prevcond;
2927 } elseif ($prevandor == 'or') {
2928 $condition = $condition || $prevcond;
2930 $prevandor = $skiprow['andor'];
2931 $prevcond = $condition;
2933 return $prevcond ? $action : '';
2936 // Load array of names of the given layout and its groups.
2937 function getLayoutProperties($formtype, &$grparr, $sel = "grp_title")
2939 if ($sel != '*' && strpos($sel, 'grp_group_id') === false) {
2940 $sel = "grp_group_id, $sel";
2942 $gres = sqlStatement("SELECT $sel FROM layout_group_properties WHERE grp_form_id = ? " .
2943 "ORDER BY grp_group_id", array($formtype));
2944 while ($grow = sqlFetchArray($gres)) {
2945 $grparr[$grow['grp_group_id']] = $grow;
2949 function display_layout_rows($formtype, $result1, $result2 = '')
2951 global $item_count, $cell_count, $last_group, $CPR;
2953 $grparr = array();
2954 getLayoutProperties($formtype, $grparr, '*');
2956 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
2958 $fres = sqlStatement("SELECT * FROM layout_options " .
2959 "WHERE form_id = ? AND uor > 0 " .
2960 "ORDER BY group_id, seq", array($formtype));
2962 while ($frow = sqlFetchArray($fres)) {
2963 $this_group = $frow['group_id'];
2964 $titlecols = $frow['titlecols'];
2965 $datacols = $frow['datacols'];
2966 $data_type = $frow['data_type'];
2967 $field_id = $frow['field_id'];
2968 $list_id = $frow['list_id'];
2969 $currvalue = '';
2970 $jump_new_row = isOption($frow['edit_options'], 'J');
2971 $prepend_blank_row = isOption($frow['edit_options'], 'K');
2973 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
2975 if ($formtype == 'DEM') {
2976 if (strpos($field_id, 'em_') === 0) {
2977 // Skip employer related fields, if it's disabled.
2978 if ($GLOBALS['omit_employers']) {
2979 continue;
2982 $tmp = substr($field_id, 3);
2983 if (isset($result2[$tmp])) {
2984 $currvalue = $result2[$tmp];
2986 } else {
2987 if (isset($result1[$field_id])) {
2988 $currvalue = $result1[$field_id];
2991 } else {
2992 if (isset($result1[$field_id])) {
2993 $currvalue = $result1[$field_id];
2997 // Handle a data category (group) change.
2998 if (strcmp($this_group, $last_group) != 0) {
2999 $group_name = $grparr[$this_group]['grp_title'];
3000 // totally skip generating the employer category, if it's disabled.
3001 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3002 continue;
3005 disp_end_group();
3006 $last_group = $this_group;
3009 // filter out all the empty field data from the patient report.
3010 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
3011 // Handle starting of a new row.
3012 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0 || $prepend_blank_row || $jump_new_row) {
3013 disp_end_row();
3014 if ($prepend_blank_row) {
3015 echo "<tr><td class='label' colspan='" . ($CPR + 1) . "'>&nbsp;</td></tr>\n";
3017 echo "<tr>";
3018 if ($group_name) {
3019 echo "<td class='groupname'>";
3020 echo text(xl_layout_label($group_name));
3021 $group_name = '';
3022 } else {
3023 echo "<td valign='top'>&nbsp;";
3026 echo "</td>";
3029 if ($item_count == 0 && $titlecols == 0) {
3030 $titlecols = 1;
3033 // Handle starting of a new label cell.
3034 if ($titlecols > 0) {
3035 disp_end_cell();
3036 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
3037 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3038 echo "<td class='label_custom' colspan='$titlecols_esc' ";
3039 //if ($cell_count == 2) echo " style='padding-left:10pt'";
3040 echo ">";
3041 $cell_count += $titlecols;
3044 ++$item_count;
3046 // Added 5-09 by BM - Translate label if applicable
3047 if ($frow['title']) {
3048 $tmp = xl_layout_label($frow['title']);
3049 echo text($tmp);
3050 // Append colon only if label does not end with punctuation.
3051 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3052 echo ':';
3054 } else {
3055 echo "&nbsp;";
3058 // Handle starting of a new data cell.
3059 if ($datacols > 0) {
3060 disp_end_cell();
3061 //echo "<td class='text data' colspan='$datacols' valign='top'";
3062 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3063 echo "<td class='text data' colspan='$datacols_esc'";
3064 //if ($cell_count > 0) echo " style='padding-left:5pt'";
3065 echo ">";
3066 $cell_count += $datacols;
3069 ++$item_count;
3070 echo generate_display_field($frow, $currvalue);
3074 disp_end_group();
3077 function display_layout_tabs($formtype, $result1, $result2 = '')
3079 global $item_count, $cell_count, $last_group, $CPR;
3081 $grparr = array();
3082 getLayoutProperties($formtype, $grparr);
3084 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3085 "WHERE form_id = ? AND uor > 0 " .
3086 "ORDER BY group_id", array($formtype));
3088 $first = true;
3089 while ($frow = sqlFetchArray($fres)) {
3090 $this_group = $frow['group_id'];
3091 // $group_name = substr($this_group, 1);
3092 $group_name = $grparr[$this_group]['grp_title'];
3093 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3094 continue;
3097 <li <?php echo $first ? 'class="current"' : '' ?>>
3098 <a href="#" id="header_tab_<?php echo attr($group_name); ?>">
3099 <?php echo text(xl_layout_label($group_name)); ?></a>
3100 </li>
3101 <?php
3102 $first = false;
3106 function display_layout_tabs_data($formtype, $result1, $result2 = '')
3108 global $item_count, $cell_count, $last_group, $CPR;
3110 $grparr = array();
3111 getLayoutProperties($formtype, $grparr, '*');
3113 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3115 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3116 "WHERE form_id = ? AND uor > 0 " .
3117 "ORDER BY group_id", array($formtype));
3119 $first = true;
3120 while ($frow = sqlFetchArray($fres)) {
3121 $this_group = isset($frow['group_id']) ? $frow['group_id'] : "" ;
3123 if ($grparr[$this_group]['grp_columns'] === 'Employer' && $GLOBALS['omit_employers']) {
3124 continue;
3126 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3127 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : xl_layout_label($grparr[$this_group]['grp_subtitle']);
3129 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3130 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3131 "ORDER BY seq", array($formtype, $this_group));
3134 <div class="tab <?php echo $first ? 'current' : '' ?>">
3135 <table border='0' cellpadding='0'>
3137 <?php
3138 while ($group_fields = sqlFetchArray($group_fields_query)) {
3139 $titlecols = $group_fields['titlecols'];
3140 $datacols = $group_fields['datacols'];
3141 $data_type = $group_fields['data_type'];
3142 $field_id = $group_fields['field_id'];
3143 $list_id = $group_fields['list_id'];
3144 $currvalue = '';
3145 $edit_options = $group_fields['edit_options'];
3146 $jump_new_row = isOption($edit_options, 'J');
3147 $prepend_blank_row = isOption($edit_options, 'K');
3149 if ($formtype == 'DEM') {
3150 if (strpos($field_id, 'em_') === 0) {
3151 // Skip employer related fields, if it's disabled.
3152 if ($GLOBALS['omit_employers']) {
3153 continue;
3156 $tmp = substr($field_id, 3);
3157 if (isset($result2[$tmp])) {
3158 $currvalue = $result2[$tmp];
3160 } else {
3161 if (isset($result1[$field_id])) {
3162 $currvalue = $result1[$field_id];
3165 } else {
3166 if (isset($result1[$field_id])) {
3167 $currvalue = $result1[$field_id];
3171 // Skip this field if action conditions call for that.
3172 // Note this also accumulates info for subsequent skip tests.
3173 $skip_this_field = isSkipped($group_fields, $currvalue) == 'skip';
3175 // Skip this field if its do-not-print option is set.
3176 if (isOption($edit_options, 'X') !== false) {
3177 $skip_this_field = true;
3180 // Handle a data category (group) change.
3181 if (strcmp($this_group, $last_group) != 0) {
3182 $group_name = $grparr[$this_group]['grp_title'];
3183 // totally skip generating the employer category, if it's disabled.
3184 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3185 continue;
3187 $last_group = $this_group;
3190 // Handle starting of a new row.
3191 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0 || $prepend_blank_row || $jump_new_row) {
3192 disp_end_row();
3193 if ($subtitle) {
3194 // Group subtitle exists and is not displayed yet.
3195 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3196 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3197 $subtitle = '';
3199 if ($prepend_blank_row) {
3200 echo "<tr><td class='label' colspan='$CPR'>&nbsp;</td></tr>\n";
3202 echo "<tr>";
3205 if ($item_count == 0 && $titlecols == 0) {
3206 $titlecols = 1;
3209 // Handle starting of a new label cell.
3210 if ($titlecols > 0) {
3211 disp_end_cell();
3212 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3213 $field_id_label = 'label_'.$group_fields['field_id'];
3214 echo "<td class='label_custom' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
3215 echo ">";
3216 $cell_count += $titlecols;
3219 ++$item_count;
3221 $field_id_label = 'label_'.$group_fields['field_id'];
3222 echo "<span id='".attr($field_id_label)."'>";
3223 if ($skip_this_field) {
3224 // No label because skipping
3225 } elseif ($group_fields['title']) {
3226 $tmp = xl_layout_label($group_fields['title']);
3227 echo text($tmp);
3228 // Append colon only if label does not end with punctuation.
3229 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3230 echo ':';
3232 } else {
3233 echo "&nbsp;";
3235 echo "</span>";
3237 // Handle starting of a new data cell.
3238 if ($datacols > 0) {
3239 disp_end_cell();
3240 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3241 $field_id = 'text_'.$group_fields['field_id'];
3242 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
3243 if (!$skip_this_field && $data_type == 3) {
3244 // Textarea gets a light grey border.
3245 echo " style='border:1px solid #cccccc'";
3247 echo ">";
3248 $cell_count += $datacols;
3249 } else {
3250 $field_id = 'text_'.$group_fields['field_id'];
3251 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
3254 ++$item_count;
3255 if (!$skip_this_field) {
3256 echo generate_display_field($group_fields, $currvalue);
3260 disp_end_row();
3263 </table>
3264 </div>
3266 <?php
3268 $first = false;
3272 function display_layout_tabs_data_editable($formtype, $result1, $result2 = '')
3274 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
3276 $grparr = array();
3277 getLayoutProperties($formtype, $grparr, '*');
3279 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3281 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3282 "WHERE form_id = ? AND uor > 0 " .
3283 "ORDER BY group_id", array($formtype));
3285 $first = true;
3286 $condition_str = '';
3288 while ($frow = sqlFetchArray($fres)) {
3289 $this_group = $frow['group_id'];
3290 $group_name = $grparr[$this_group]['grp_title'];
3291 $group_name_esc = text($group_name);
3293 if ($grparr[$this_group]['grp_title'] === 'Employer' && $GLOBALS['omit_employers']) {
3294 continue;
3296 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3297 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : xl_layout_label($grparr[$this_group]['grp_subtitle']);
3299 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3300 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3301 "ORDER BY seq", array($formtype, $this_group));
3304 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_', $group_name_esc)?>" >
3305 <table border='0' cellpadding='0'>
3307 <?php
3308 while ($group_fields = sqlFetchArray($group_fields_query)) {
3309 $titlecols = $group_fields['titlecols'];
3310 $datacols = $group_fields['datacols'];
3311 $data_type = $group_fields['data_type'];
3312 $field_id = $group_fields['field_id'];
3313 $list_id = $group_fields['list_id'];
3314 $backup_list = $group_fields['list_backup_id'];
3315 $currvalue = '';
3316 $action = 'skip';
3317 $jump_new_row = isOption($group_fields['edit_options'], 'J');
3318 $prepend_blank_row = isOption($group_fields['edit_options'], 'K');
3320 // Accumulate action conditions into a JSON expression for the browser side.
3321 accumActionConditions($field_id, $condition_str, $group_fields['conditions']);
3323 if ($formtype == 'DEM') {
3324 if (strpos($field_id, 'em_') === 0) {
3325 // Skip employer related fields, if it's disabled.
3326 if ($GLOBALS['omit_employers']) {
3327 continue;
3330 $tmp = substr($field_id, 3);
3331 if (isset($result2[$tmp])) {
3332 $currvalue = $result2[$tmp];
3334 } else {
3335 if (isset($result1[$field_id])) {
3336 $currvalue = $result1[$field_id];
3339 } else {
3340 if (isset($result1[$field_id])) {
3341 $currvalue = $result1[$field_id];
3345 // Handle a data category (group) change.
3346 if (strcmp($this_group, $last_group) != 0) {
3347 // totally skip generating the employer category, if it's disabled.
3348 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3349 continue;
3352 $last_group = $this_group;
3355 // Handle starting of a new row.
3356 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0 || $prepend_blank_row || $jump_new_row) {
3357 disp_end_row();
3358 if ($subtitle) {
3359 // Group subtitle exists and is not displayed yet.
3360 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3361 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3362 $subtitle = '';
3364 if ($prepend_blank_row) {
3365 echo "<tr><td class='label' colspan='$CPR'>&nbsp;</td></tr>\n";
3367 echo "<tr>";
3370 if ($item_count == 0 && $titlecols == 0) {
3371 $titlecols = 1;
3374 // Handle starting of a new label cell.
3375 if ($titlecols > 0) {
3376 disp_end_cell();
3377 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3378 $field_id_label = 'label_'.$group_fields['field_id'];
3379 echo "<td class='label_custom' colspan='$titlecols_esc'";
3380 // This ID is used by skip conditions.
3381 echo " id='label_id_" . attr($field_id) . "'";
3382 echo ">";
3383 $cell_count += $titlecols;
3386 ++$item_count;
3388 if ($group_fields['title']) {
3389 $tmp = xl_layout_label($group_fields['title']);
3390 echo text($tmp);
3391 // Append colon only if label does not end with punctuation.
3392 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3393 echo ':';
3395 } else {
3396 echo "&nbsp;";
3399 // Handle starting of a new data cell.
3400 if ($datacols > 0) {
3401 disp_end_cell();
3402 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3403 $field_id = 'text_'.$group_fields['field_id'];
3404 echo "<td class='text data' colspan='$datacols_esc'";
3405 // This ID is used by action conditions.
3406 echo " id='value_id_" . attr($field_id) . "'";
3407 echo ">";
3408 $cell_count += $datacols;
3411 ++$item_count;
3413 echo generate_form_field($group_fields, $currvalue);
3417 </table>
3418 </div>
3420 <?php
3422 $first = false;
3426 // From the currently posted HTML form, this gets the value of the
3427 // field corresponding to the provided layout_options table row.
3429 function get_layout_form_value($frow, $prefix = 'form_')
3431 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
3432 $data_type = $frow['data_type'];
3433 $field_id = $frow['field_id'];
3434 $value = '';
3435 if (isset($_POST["$prefix$field_id"])) {
3436 if ($data_type == 4) {
3437 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
3438 if (!$modtmp) {
3439 $value = DateToYYYYMMDD($_POST["$prefix$field_id"]);
3440 } else {
3441 $value = DateTimeToYYYYMMDDHHMMSS($_POST["$prefix$field_id"]);
3443 } elseif ($data_type == 21) {
3444 if (!$frow['list_id']) {
3445 if (!empty($_POST["form_$field_id"])) {
3446 $value = xlt('Yes');
3448 } else {
3449 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
3450 // must be concatenated into a |-separated string.
3451 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3452 if (strlen($value)) {
3453 $value .= '|';
3455 $value .= $key;
3458 } elseif ($data_type == 22) {
3459 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
3460 // into "key:value|key:value|...".
3461 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3462 $val = str_replace('|', ' ', $val);
3463 if (strlen($value)) {
3464 $value .= '|';
3467 $value .= "$key:$val";
3469 } elseif ($data_type == 23) {
3470 // $_POST["$prefix$field_id"] is an array of text fields with companion
3471 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
3472 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3473 $restype = $_POST["radio_{$field_id}"][$key];
3474 if (empty($restype)) {
3475 $restype = '0';
3478 $val = str_replace('|', ' ', $val);
3479 if (strlen($value)) {
3480 $value .= '|';
3483 $value .= "$key:$restype:$val";
3485 } elseif ($data_type == 25) {
3486 // $_POST["$prefix$field_id"] is an array of text fields with companion
3487 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
3488 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3489 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
3490 $val = str_replace('|', ' ', $val);
3491 if (strlen($value)) {
3492 $value .= '|';
3495 $value .= "$key:$restype:$val";
3497 } elseif ($data_type == 28 || $data_type == 32) {
3498 // $_POST["$prefix$field_id"] is an date text fields with companion
3499 // radio buttons to be imploded into "notes|type|date".
3500 $restype = $_POST["radio_{$field_id}"];
3501 if (empty($restype)) {
3502 $restype = '0';
3505 $resdate = DateToYYYYMMDD(str_replace('|', ' ', $_POST["date_$field_id"]));
3506 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3507 if ($data_type == 32) {
3508 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
3509 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3510 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
3511 $value = "$res_text_note|$restype|$resdate|$reslist";
3512 } else {
3513 $value = "$resnote|$restype|$resdate";
3515 } elseif ($data_type == 36) {
3516 $value_array = $_POST["form_$field_id"];
3517 $i = 0;
3518 foreach ($value_array as $key => $valueofkey) {
3519 if ($i == 0) {
3520 $value = $valueofkey;
3521 } else {
3522 $value = $value . "|" . $valueofkey;
3525 $i++;
3527 } else {
3528 $value = $_POST["$prefix$field_id"];
3532 // Better to die than to silently truncate data!
3533 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength) {
3534 die(htmlspecialchars(xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
3535 ":<br />&nbsp;<br />".htmlspecialchars($value, ENT_NOQUOTES));
3538 return trim($value);
3541 // Generate JavaScript validation logic for the required fields.
3543 function generate_layout_validation($form_id)
3545 $fres = sqlStatement("SELECT * FROM layout_options " .
3546 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
3547 "ORDER BY group_id, seq", array($form_id));
3549 while ($frow = sqlFetchArray($fres)) {
3550 $data_type = $frow['data_type'];
3551 $field_id = $frow['field_id'];
3552 $fldtitle = $frow['title'];
3553 if (!$fldtitle) {
3554 $fldtitle = $frow['description'];
3557 $fldname = attr("form_$field_id");
3559 if ($data_type == 40) {
3560 $fldid = "form_" . $field_id;
3561 // Move canvas image data to its hidden form field so the server will get it.
3562 echo
3563 " var canfld = f[" . js_escape($fldid) . "];\n" .
3564 " if (canfld) canfld.value = lbfCanvasGetData(" . js_escape($fldid) . ");\n";
3565 continue;
3568 if ($frow['uor'] < 2) {
3569 continue;
3572 echo " if (f.$fldname && !f.$fldname.disabled) {\n";
3573 switch ($data_type) {
3574 case 1:
3575 case 11:
3576 case 12:
3577 case 13:
3578 case 14:
3579 case 26:
3580 echo
3581 " if (f.$fldname.selectedIndex <= 0) {\n" .
3582 " alert(" . xlj('Please choose a value for') . " + " .
3583 "\":\\n\" + " . js_escape(xl_layout_label($fldtitle)) . ");\n" .
3584 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3585 " return false;\n" .
3586 " }\n";
3587 break;
3588 case 33:
3589 echo
3590 " if (f.$fldname.selectedIndex <= 0) {\n" .
3591 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3592 " errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3593 " }\n";
3594 break;
3595 case 27: // radio buttons
3596 echo
3597 " var i = 0;\n" .
3598 " for (; i < f.$fldname.length; ++i) if (f.{$fldname}[i].checked) break;\n" .
3599 " if (i >= f.$fldname.length) {\n" .
3600 " alert(" . xlj('Please choose a value for') . " + " .
3601 "\":\\n\" + " . js_escape(xl_layout_label($fldtitle)) . ");\n" .
3602 " return false;\n" .
3603 " }\n";
3604 break;
3605 case 2:
3606 case 3:
3607 case 4:
3608 case 15:
3609 echo
3610 " if (trimlen(f.$fldname.value) == 0) {\n" .
3611 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3612 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
3613 " $('#" . $fldname . "').attr('style','background:red'); \n" .
3614 " errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3615 " } else { " .
3616 " $('#" . $fldname . "').attr('style',''); " .
3617 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
3618 " } \n";
3619 break;
3620 case 36: // multi select
3621 echo
3622 " var multi_select=f['$fldname"."[]']; \n " .
3623 " var multi_choice_made=false; \n".
3624 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
3625 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
3626 " } \n" .
3627 " if(!multi_choice_made)
3628 errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3630 break;
3632 echo " }\n";
3637 * DROPDOWN FOR FACILITIES
3639 * build a dropdown with all facilities
3641 * @param string $selected - name of the currently selected facility
3642 * use '0' for "unspecified facility"
3643 * use '' for "All facilities" (the default)
3644 * @param string $name - the name/id for select form (defaults to "form_facility")
3645 * @param boolean $allow_unspecified - include an option for "unspecified" facility
3646 * defaults to true
3647 * @return void - just echo the html encoded string
3649 * Note: This should become a data-type at some point, according to Brady
3651 function dropdown_facility(
3652 $selected = '',
3653 $name = 'form_facility',
3654 $allow_unspecified = true,
3655 $allow_allfacilities = true,
3656 $disabled = '',
3657 $onchange = ''
3660 global $facilityService;
3662 $have_selected = false;
3663 $fres = $facilityService->getAll();
3665 echo " <select class='form-control' name='" . attr($name) . "' id='" . attr($name) . "'";
3666 if ($onchange) {
3667 echo " onchange='$onchange'";
3670 echo " $disabled>\n";
3672 if ($allow_allfacilities) {
3673 $option_value = '';
3674 $option_selected_attr = '';
3675 if ($selected == '') {
3676 $option_selected_attr = ' selected="selected"';
3677 $have_selected = true;
3680 $option_content = '-- ' . xl('All Facilities') . ' --';
3681 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3682 } elseif ($allow_unspecified) {
3683 $option_value = '0';
3684 $option_selected_attr = '';
3685 if ($selected == '0') {
3686 $option_selected_attr = ' selected="selected"';
3687 $have_selected = true;
3690 $option_content = '-- ' . xl('Unspecified') . ' --';
3691 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3694 foreach ($fres as $frow) {
3695 $facility_id = $frow['id'];
3696 $option_value = $facility_id;
3697 $option_selected_attr = '';
3698 if ($selected == $facility_id) {
3699 $option_selected_attr = ' selected="selected"';
3700 $have_selected = true;
3703 $option_content = $frow['name'];
3704 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3707 if ($allow_unspecified && $allow_allfacilities) {
3708 $option_value = '0';
3709 $option_selected_attr = '';
3710 if ($selected == '0') {
3711 $option_selected_attr = ' selected="selected"';
3712 $have_selected = true;
3715 $option_content = '-- ' . xl('Unspecified') . ' --';
3716 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3719 if (!$have_selected) {
3720 $option_value = $selected;
3721 $option_label = '(' . xl('Do not change') . ')';
3722 $option_content = xl('Missing or Invalid');
3723 echo " <option value='" . attr($option_value) . "' label='" . attr($option_label) . "' selected='selected'>" . text($option_content) . "</option>\n";
3726 echo " </select>\n";
3729 // Expand Collapse Widget
3730 // This forms the header and functionality component of the widget. The information that is displayed
3731 // then follows this function followed by a closing div tag
3733 // $title is the title of the section (already translated)
3734 // $label is identifier used in the tag id's and sql columns
3735 // $buttonLabel is the button label text (already translated)
3736 // $buttonLink is the button link information
3737 // $buttonClass is any additional needed class elements for the button tag
3738 // $linkMethod is the button link method ('javascript' vs 'html')
3739 // $bodyClass is to set class(es) of the body
3740 // $auth is a flag to decide whether to show the button
3741 // $fixedWidth is to flag whether width is fixed
3742 // $forceExpandAlways is a flag to force the widget to always be expanded
3744 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways = false)
3746 if ($fixedWidth) {
3747 echo "<div class='section-header'>";
3748 } else {
3749 echo "<div class='section-header-dynamic'>";
3752 echo "<table><tr>";
3753 if ($auth) {
3754 // show button, since authorized
3755 // first prepare class string
3756 if ($buttonClass) {
3757 $class_string = "css_button_small " . $buttonClass;
3758 } else {
3759 $class_string = "css_button_small";
3762 // next, create the link
3763 if ($linkMethod == "javascript") {
3764 echo "<td><a class='" . attr($class_string) . "' href='javascript:;' onclick='" . $buttonLink . "'";
3765 } else {
3766 echo "<td><a class='" . attr($class_string) . "' href='" . $buttonLink . "'";
3767 if (!isset($_SESSION['patient_portal_onsite_two'])) {
3768 // prevent an error from occuring when calling the function from the patient portal
3769 echo " onclick='top.restoreSession()'";
3773 echo "><span>" .
3774 text($buttonLabel) . "</span></a></td>";
3777 if ($forceExpandAlways) {
3778 // Special case to force the widget to always be expanded
3779 echo "<td><span class='text'><b>" . text($title) . "</b></span>";
3780 $indicatorTag ="style='display:none'";
3783 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3784 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this," .
3785 attr_js($label."_ps_expand") . ")'><span class='text'><b>";
3786 echo text($title) . "</b></span>";
3788 if (isset($_SESSION['patient_portal_onsite_two'])) {
3789 // collapse all entries in the patient portal
3790 $text = xl('expand');
3791 } elseif (getUserSetting($label."_ps_expand")) {
3792 $text = xl('collapse');
3793 } else {
3794 $text = xl('expand');
3797 echo " (<span class='indicator'>" . text($text) .
3798 "</span>)</a></td>";
3799 echo "</tr></table>";
3800 echo "</div>";
3801 if ($forceExpandAlways) {
3802 // Special case to force the widget to always be expanded
3803 $styling = "";
3804 } elseif (isset($_SESSION['patient_portal_onsite_two'])) {
3805 // collapse all entries in the patient portal
3806 $styling = "style='display:none'";
3807 } elseif (getUserSetting($label."_ps_expand")) {
3808 $styling = "";
3809 } else {
3810 $styling = "style='display:none'";
3813 if ($bodyClass) {
3814 $styling .= " class='" . attr($bodyClass) . "'";
3817 //next, create the first div tag to hold the information
3818 // note the code that calls this function will then place the ending div tag after the data
3819 echo "<div id='" . attr($label) . "_ps_expand' " . $styling . ">";
3822 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3823 function billing_facility($name, $select)
3825 global $facilityService;
3827 $fres = $facilityService->getAllBillingLocations();
3828 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' class='form-control' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3829 foreach ($fres as $facrow) {
3830 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3831 echo "<option value=".htmlspecialchars($facrow['id'], ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3834 echo "</select>";
3837 // Generic function to get the translated title value for a particular list option.
3839 function getListItemTitle($list, $option)
3841 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3842 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3843 if (empty($row['title'])) {
3844 return $option;
3847 return xl_list_label($row['title']);
3850 //function to get the translated title value in Patient Transactions
3851 function getLayoutTitle($list, $option)
3853 $row = sqlQuery("SELECT grp_title FROM layout_group_properties " .
3854 "WHERE grp_mapping = ? AND grp_form_id = ? ", array($list, $option));
3856 if (empty($row['grp_title'])) {
3857 return $option;
3859 return xl_list_label($row['grp_title']);
3861 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3862 function getSmokeCodes()
3864 $smoking_codes_arr = array();
3865 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3866 while ($codes_row = sqlFetchArray($smoking_codes)) {
3867 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3870 return $smoking_codes_arr;
3873 // Get the current value for a layout based form field.
3874 // Depending on options this might come from lbf_data, patient_data,
3875 // form_encounter, shared_attributes or elsewhere.
3876 // Returns FALSE if the field ID is invalid (layout error).
3878 function lbf_current_value($frow, $formid, $encounter)
3880 global $pid;
3881 $formname = $frow['form_id'];
3882 $field_id = $frow['field_id'];
3883 $source = $frow['source'];
3884 $currvalue = '';
3885 $deffname = $formname . '_default_' . $field_id;
3886 if ($source == 'D' || $source == 'H') {
3887 // Get from patient_data, employer_data or history_data.
3888 if ($source == 'H') {
3889 $table = 'history_data';
3890 $orderby = 'ORDER BY date DESC LIMIT 1';
3891 } elseif (strpos($field_id, 'em_') === 0) {
3892 $field_id = substr($field_id, 3);
3893 $table = 'employer_data';
3894 $orderby = 'ORDER BY date DESC LIMIT 1';
3895 } else {
3896 $table = 'patient_data';
3897 $orderby = '';
3900 // It is an error if the field does not exist, but don't crash.
3901 $tmp = sqlQuery("SHOW COLUMNS FROM " . escape_table_name($table) . " WHERE Field = ?", array($field_id));
3902 if (empty($tmp)) {
3903 return '*?*';
3906 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM " . escape_table_name($table) . " WHERE pid = ? $orderby", array($pid));
3907 if (isset($pdrow)) {
3908 $currvalue = $pdrow['field_value'];
3910 } elseif ($source == 'E') {
3911 $sarow = false;
3912 if ($encounter) {
3913 // Get value from shared_attributes of the current encounter.
3914 $sarow = sqlQuery(
3915 "SELECT field_value FROM shared_attributes WHERE " .
3916 "pid = ? AND encounter = ? AND field_id = ?",
3917 array($pid, $encounter, $field_id)
3919 if (!empty($sarow)) {
3920 $currvalue = $sarow['field_value'];
3922 } elseif ($formid) {
3923 // Get from shared_attributes of the encounter that this form is linked to.
3924 // Note the importance of having an index on forms.form_id.
3925 $sarow = sqlQuery(
3926 "SELECT sa.field_value " .
3927 "FROM forms AS f, shared_attributes AS sa WHERE " .
3928 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3929 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3930 array($formid, $formname, $field_id)
3932 if (!empty($sarow)) {
3933 $currvalue = $sarow['field_value'];
3935 } else {
3936 // New form and encounter not available, this should not happen.
3938 if (empty($sarow) && !$formid) {
3939 // New form, see if there is a custom default from a plugin.
3940 if (function_exists($deffname)) {
3941 $currvalue = call_user_func($deffname);
3944 } elseif ($source == 'V') {
3945 if ($encounter) {
3946 // Get value from the current encounter's form_encounter.
3947 $ferow = sqlQuery(
3948 "SELECT * FROM form_encounter WHERE " .
3949 "pid = ? AND encounter = ?",
3950 array($pid, $encounter)
3952 if (isset($ferow[$field_id])) {
3953 $currvalue = $ferow[$field_id];
3955 } elseif ($formid) {
3956 // Get value from the form_encounter that this form is linked to.
3957 $ferow = sqlQuery(
3958 "SELECT fe.* " .
3959 "FROM forms AS f, form_encounter AS fe WHERE " .
3960 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3961 "fe.pid = f.pid AND fe.encounter = f.encounter",
3962 array($formid, $formname)
3964 if (isset($ferow[$field_id])) {
3965 $currvalue = $ferow[$field_id];
3967 } else {
3968 // New form and encounter not available, this should not happen.
3970 } elseif ($formid) {
3971 // This is a normal form field.
3972 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3973 "form_id = ? AND field_id = ?", array($formid, $field_id));
3974 if (!empty($ldrow)) {
3975 $currvalue = $ldrow['field_value'];
3977 } else {
3978 // New form, see if there is a custom default from a plugin.
3979 if (function_exists($deffname)) {
3980 $currvalue = call_user_func($deffname);
3984 return $currvalue;
3987 // This returns stuff that needs to go into the <head> section of a caller using
3988 // the drawable image field type in a form.
3989 // A TRUE argument makes the widget controls smaller.
3991 function lbf_canvas_head($small = true)
3993 $s = <<<EOD
3994 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas/css/literallycanvas.css" rel="stylesheet" />
3995 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/build/react-with-addons.min.js"></script>
3996 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/build/react-dom.min.js"></script>
3997 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas/js/literallycanvas.min.js"></script>
3998 EOD;
3999 if ($small) {
4000 $s .= <<<EOD
4001 <style>
4002 /* Custom LiterallyCanvas styling.
4003 * This makes the widget 25% less tall and adjusts some other things accordingly.
4005 .literally {
4006 min-height:100%;min-width:300px; /* Was 400, unspecified */
4008 .literally .lc-picker .toolbar-button {
4009 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
4011 .literally .color-well {
4012 font-size:8px;width:49px; /* Was 10, 60 */
4014 .literally .color-well-color-container {
4015 width:21px;height:21px; /* Was 28, 28 */
4017 .literally .lc-picker {
4018 width:50px; /* Was 61 */
4020 .literally .lc-drawing.with-gui {
4021 left:50px; /* Was 61 */
4023 .literally .lc-options {
4024 left:50px; /* Was 61 */
4026 .literally .color-picker-popup {
4027 left:49px;bottom:0px; /* Was 60, 31 */
4029 </style>
4030 EOD;
4033 return $s;
4037 * Test if modifier($test) is in array of options for data type.
4039 * @param json array $options ["G","P","T"], ["G"] or could be legacy string with form "GPT", "G", "012"
4040 * @param string $test
4041 * @return boolean
4043 function isOption($options, $test)
4045 if (empty($options) || !isset($test) || $options == "null") {
4046 return false; // why bother?
4048 if (strpos($options, ',') === false) { // not json array of modifiers.
4049 // could be string of char's or single element of json ["RO"] or "TP" or "P" e.t.c.
4050 json_decode($options, true); // test if options json. json_last_error() will return JSON_ERROR_SYNTAX if not.
4051 // if of form ["RO"] (single modifier) means not legacy so continue on.
4052 if (is_string($options) && (json_last_error() !== JSON_ERROR_NONE)) { // nope, it's string.
4053 $t = str_split(trim($options)); // very good chance it's legacy modifier string.
4054 $options = json_encode($t); // make it json array to convert from legacy to new modifier json schema.
4058 $options = json_decode($options, true); // all should now be json
4060 return !is_null($options) && in_array($test, $options, true) ? true : false; // finally the truth!