some portal work
[openemr.git] / library / options.inc.php
blob2702ac2484341ef125d7f25a52a93c6b228ebb15
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 state, city, 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 } elseif ($data_type == 2) { // simple text field
391 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
392 $maxlength = $frow['max_length'];
393 $string_maxlength = "";
394 // if max_length is set to zero, then do not set a maxlength
395 if ($maxlength) {
396 $string_maxlength = "maxlength='".attr($maxlength)."'";
399 echo "<input type='text'" .
400 " class='form-control'" .
401 " name='form_$field_id_esc'" .
402 " id='form_$field_id_esc'" .
403 " size='$fldlength'" .
404 " $string_maxlength" .
405 " title='$description'" .
406 " value='$currescaped'";
407 $tmp = $lbfchange;
408 if (isOption($frow['edit_options'], 'C') !== false) {
409 $tmp .= "capitalizeMe(this);";
410 } elseif (isOption($frow['edit_options'], 'U') !== false) {
411 $tmp .= "this.value = this.value.toUpperCase();";
414 if ($tmp) {
415 echo " onchange='$tmp'";
418 $tmp = htmlspecialchars($GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
419 // If mask is for use at save time, treat as no mask.
420 if (strpos($tmp, '^') !== false) {
421 $tmp = '';
423 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
424 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
425 echo " onblur='maskblur(this,\"$tmp\")'";
428 if (isOption($frow['edit_options'], '1') !== false && strlen($currescaped) > 0) {
429 echo " readonly";
432 if ($disabled) {
433 echo ' disabled';
436 echo " />";
437 } elseif ($data_type == 3) { // long or multi-line text field
438 $textCols = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
439 $textRows = htmlspecialchars($frow['fld_rows'], ENT_QUOTES);
440 echo "<textarea" .
441 " name='form_$field_id_esc'" .
442 " class='form-control'" .
443 " id='form_$field_id_esc'" .
444 " title='$description'" .
445 " cols='$textCols'" .
446 " rows='$textRows' $lbfonchange $disabled" .
447 ">" . $currescaped . "</textarea>";
448 } elseif ($data_type == 4) { // date
449 $age_asof_date = ''; // optionalAge() sets this
450 $age_format = isOption($frow['edit_options'], 'A') === false ? 3 : 0;
451 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
452 if ($agestr) {
453 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
456 $onchange_string = '';
457 if (!$disabled && $agestr) {
458 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') " .
459 "updateAgeString('$field_id','$age_asof_date', $age_format, '$description')\"";
461 if ($data_type == 4) {
462 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
463 if (!$modtmp) {
464 $dateValue = oeFormatShortDate(substr($currescaped, 0, 10));
465 echo "<input type='text' size='10' class='datepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
466 " value='" . attr($dateValue) ."'";
467 } else {
468 $dateValue = oeFormatDateTime(substr($currescaped, 0, 20), 0);
469 echo "<input type='text' size='20' class='datetimepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
470 " value='" . attr($dateValue) . "'";
473 if (!$agestr) {
474 echo " title='$description'";
477 // help chrome users avoid autocomplete interfere with datepicker widget display
478 if ($frow['field_id'] == 'DOB') {
479 echo " autocomplete='off' $onchange_string $lbfonchange $disabled />";
480 } else {
481 echo " $onchange_string $lbfonchange $disabled />";
484 // Optional display of age or gestational age.
485 if ($agestr) {
486 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
488 } elseif ($data_type == 10) { // provider list, local providers only
489 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
490 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
491 "AND authorized = 1 " .
492 "ORDER BY lname, fname");
493 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
494 echo "<option value=''>" . xlt($empty_title) . "</option>";
495 $got_selected = false;
496 while ($urow = sqlFetchArray($ures)) {
497 $uname = text($urow['fname'] . ' ' . $urow['lname']);
498 $optionId = attr($urow['id']);
499 echo "<option value='$optionId'";
500 if ($urow['id'] == $currvalue) {
501 echo " selected";
502 $got_selected = true;
505 echo ">$uname</option>";
508 if (!$got_selected && $currvalue) {
509 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
510 echo "</select>";
511 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
512 } else {
513 echo "</select>";
515 } elseif ($data_type == 11) { // provider list, including address book entries with an NPI number
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 } elseif ($data_type == 12) { // pharmacy list
544 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
545 echo " $lbfonchange $disabled>";
546 echo "<option value='0'></option>";
547 $pres = get_pharmacies();
548 $got_selected = false;
549 $zone ='';
550 while ($prow = sqlFetchArray($pres)) {
551 if ($zone != strtolower(trim($prow['city']))) {
552 if ($zone !='') {
553 echo "</optgroup>";
555 $zone = strtolower(trim($prow['city']));
556 echo "<optgroup label='".attr($prow['city'])."'>";
558 $key = $prow['id'];
559 $optionValue = htmlspecialchars($key, ENT_QUOTES);
560 $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
561 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
562 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
563 echo "<option value='$optionValue'";
564 if ($currvalue == $key) {
565 echo " selected";
566 $got_selected = true;
569 echo ">$optionLabel</option>";
572 if (!$got_selected && $currvalue) {
573 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
574 echo "</select>";
575 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
576 } else {
577 echo "</select>";
579 } elseif ($data_type == 13) { // squads
580 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
581 echo " $lbfonchange $disabled>";
582 echo "<option value=''>&nbsp;</option>";
583 $squads = acl_get_squads();
584 if ($squads) {
585 foreach ($squads as $key => $value) {
586 $optionValue = htmlspecialchars($key, ENT_QUOTES);
587 $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES);
588 echo "<option value='$optionValue'";
589 if ($currvalue == $key) {
590 echo " selected";
593 echo ">$optionLabel</option>\n";
597 echo "</select>";
598 } elseif ($data_type == 14) {
599 // Address book, preferring organization name if it exists and is not in
600 // parentheses, and excluding local users who are not providers.
601 // Supports "referred to" practitioners and facilities.
602 // Alternatively the letter L in edit_options means that abook_type
603 // must be "ord_lab", indicating types used with the procedure
604 // lab ordering system.
605 // Alternatively the letter O in edit_options means that abook_type
606 // must begin with "ord_", indicating types used with the procedure
607 // ordering system.
608 // Alternatively the letter V in edit_options means that abook_type
609 // must be "vendor", indicating the Vendor type.
610 // Alternatively the letter R in edit_options means that abook_type
611 // must be "dist", indicating the Distributor type.
613 if (isOption($frow['edit_options'], 'L') !== false) {
614 $tmp = "abook_type = 'ord_lab'";
615 } elseif (isOption($frow['edit_options'], 'O') !== false) {
616 $tmp = "abook_type LIKE 'ord\\_%'";
617 } elseif (isOption($frow['edit_options'], 'V') !== false) {
618 $tmp = "abook_type LIKE 'vendor%'";
619 } elseif (isOption($frow['edit_options'], 'R') !== false) {
620 $tmp = "abook_type LIKE 'dist'";
621 } else {
622 $tmp = "( username = '' OR authorized = 1 )";
625 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
626 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
627 "AND $tmp " .
628 "ORDER BY organization, lname, fname");
629 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
630 echo " $lbfonchange $disabled>";
631 echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES) . "</option>";
632 while ($urow = sqlFetchArray($ures)) {
633 $uname = $urow['organization'];
634 if (empty($uname) || substr($uname, 0, 1) == '(') {
635 $uname = $urow['lname'];
636 if ($urow['fname']) {
637 $uname .= ", " . $urow['fname'];
641 $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES);
642 $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES);
643 echo "<option value='$optionValue'";
644 // Failure to translate Local and External is not an error here;
645 // they are only used as internal flags and must not be translated!
646 $title = $urow['username'] ? 'Local' : 'External';
647 $optionTitle = htmlspecialchars($title, ENT_QUOTES);
648 echo " title='$optionTitle'";
649 if ($urow['id'] == $currvalue) {
650 echo " selected";
653 echo ">$optionLabel</option>";
656 echo "</select>";
657 } elseif ($data_type == 15) { // A billing code. If description matches an existing code type then that type is used.
658 $codetype = '';
659 if (!empty($frow['description']) && isset($code_types[$frow['description']])) {
660 $codetype = $frow['description'];
662 $fldlength = attr($frow['fld_length']);
663 $maxlength = $frow['max_length'];
664 $string_maxlength = "";
665 // if max_length is set to zero, then do not set a maxlength
666 if ($maxlength) {
667 $string_maxlength = "maxlength='".attr($maxlength)."'";
671 if (isOption($frow['edit_options'], '2') !== false && substr($frow['form_id'], 0, 3) == 'LBF') {
672 // Option "2" generates a hidden input for the codes, and a matching visible field
673 // displaying their descriptions. First step is computing the description string.
674 $currdescstring = '';
675 if (!empty($currvalue)) {
676 $relcodes = explode(';', $currvalue);
677 foreach ($relcodes as $codestring) {
678 if ($codestring === '') {
679 continue;
682 $code_text = lookup_code_descriptions($codestring);
683 if ($currdescstring !== '') {
684 $currdescstring .= '; ';
687 if (!empty($code_text)) {
688 $currdescstring .= $code_text;
689 } else {
690 $currdescstring .= $codestring;
695 $currdescstring = attr($currdescstring);
697 echo "<input type='text'" .
698 " name='form_$field_id_esc'" .
699 " id='form_related_code'" .
700 " size='$fldlength'" .
701 " value='$currescaped'" .
702 " style='display:none'" .
703 " $lbfonchange readonly $disabled />";
704 // Extra readonly input field for optional display of code description(s).
705 echo "<input type='text'" .
706 " name='form_$field_id_esc" . "__desc'" .
707 " size='$fldlength'" .
708 " title='$description'" .
709 " value='$currdescstring'";
710 if (!$disabled) {
711 echo " onclick='sel_related(this," . attr_js($codetype) . ")'";
714 echo "class='form-control'";
715 echo " readonly $disabled />";
716 } else {
717 echo "<input type='text'" .
718 " name='form_$field_id_esc'" .
719 " id='form_related_code'" .
720 " size='$fldlength'" .
721 " $string_maxlength" .
722 " title='$description'" .
723 " value='$currescaped'";
724 if (!$disabled) {
725 echo " onclick='sel_related(this," . attr_js($codetype) . ")'";
728 echo "class='form-control'";
729 echo " $lbfonchange readonly $disabled />";
731 } elseif ($data_type == 16) { // insurance company list
732 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
733 echo "<option value='0'></option>";
734 $insprovs = getInsuranceProviders();
735 $got_selected = false;
736 foreach ($insprovs as $key => $ipname) {
737 $optionValue = htmlspecialchars($key, ENT_QUOTES);
738 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
739 echo "<option value='$optionValue'";
740 if ($currvalue == $key) {
741 echo " selected";
742 $got_selected = true;
745 echo ">$optionLabel</option>";
748 if (!$got_selected && $currvalue) {
749 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
750 echo "</select>";
751 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
752 } else {
753 echo "</select>";
755 } elseif ($data_type == 17) { // issue types
756 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
757 echo "<option value='0'></option>";
758 $got_selected = false;
759 foreach ($ISSUE_TYPES as $key => $value) {
760 $optionValue = htmlspecialchars($key, ENT_QUOTES);
761 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
762 echo "<option value='$optionValue'";
763 if ($currvalue == $key) {
764 echo " selected";
765 $got_selected = true;
768 echo ">$optionLabel</option>";
771 if (!$got_selected && strlen($currvalue) > 0) {
772 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
773 echo "</select>";
774 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
775 } else {
776 echo "</select>";
778 } elseif ($data_type == 18) { // Visit categories.
779 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
780 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
781 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'" .
782 " $lbfonchange $disabled>";
783 echo "<option value=''>" . xlt($empty_title) . "</option>";
784 $got_selected = false;
785 while ($crow = sqlFetchArray($cres)) {
786 $catid = $crow['pc_catid'];
787 if (($catid < 9 && $catid != 5) || $catid == 11) {
788 continue;
791 echo "<option value='" . attr($catid) . "'";
792 if ($catid == $currvalue) {
793 echo " selected";
794 $got_selected = true;
797 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
800 if (!$got_selected && $currvalue) {
801 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
802 echo "</select>";
803 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
804 } else {
805 echo "</select>";
807 } elseif ($data_type == 21) { // a set of labeled checkboxes
808 // If no list then it's a single checkbox and its value is "Yes" or empty.
809 if (!$list_id) {
810 echo "<input type='checkbox' name='form_{$field_id_esc}' " .
811 "id='form_{$field_id_esc}' value='Yes' $lbfonchange";
812 if ($currvalue) {
813 echo " checked";
815 echo " $disabled />";
816 } else {
817 // In this special case, fld_length is the number of columns generated.
818 $cols = max(1, $frow['fld_length']);
819 $avalue = explode('|', $currvalue);
820 $lres = sqlStatement("SELECT * FROM list_options " .
821 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
822 echo "<table cellpadding='0' cellspacing='0' width='100%' title='".attr($description)."'>";
823 $tdpct = (int) (100 / $cols);
824 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
825 $option_id = $lrow['option_id'];
826 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
827 // if ($count) echo "<br />";
828 if ($count % $cols == 0) {
829 if ($count) {
830 echo "</tr>";
832 echo "<tr>";
834 echo "<td width='" . attr($tdpct) . "%' nowrap>";
835 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
836 "id='form_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
837 if (in_array($option_id, $avalue)) {
838 echo " checked";
840 // Added 5-09 by BM - Translate label if applicable
841 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
842 echo "</td>";
844 if ($count) {
845 echo "</tr>";
846 if ($count > $cols) {
847 // Add some space after multiple rows of checkboxes.
848 $cols = htmlspecialchars($cols, ENT_QUOTES);
849 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
852 echo "</table>";
854 } elseif ($data_type == 22) { // a set of labeled text input fields
855 $tmp = explode('|', $currvalue);
856 $avalue = array();
857 foreach ($tmp as $value) {
858 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
859 $avalue[$matches[1]] = $matches[2];
863 $lres = sqlStatement("SELECT * FROM list_options " .
864 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
865 echo "<table cellpadding='0' cellspacing='0'>";
866 while ($lrow = sqlFetchArray($lres)) {
867 $option_id = $lrow['option_id'];
868 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
869 $maxlength = $frow['max_length'];
870 $string_maxlength = "";
871 // if max_length is set to zero, then do not set a maxlength
872 if ($maxlength) {
873 $string_maxlength = "maxlength='".attr($maxlength)."'";
876 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
878 // Added 5-09 by BM - Translate label if applicable
879 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
880 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
881 $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
882 echo "<td><input type='text'" .
883 " name='form_{$field_id_esc}[$option_id_esc]'" .
884 " id='form_{$field_id_esc}[$option_id_esc]'" .
885 " size='$fldlength'" .
886 " class='form-control'" .
887 " $string_maxlength" .
888 " value='$optionValue'";
889 echo " $lbfonchange $disabled /></td></tr>";
892 echo "</table>";
893 } elseif ($data_type == 23) { // a set of exam results; 3 radio buttons and a text field:
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 } elseif ($data_type == 24) { // the list of active allergies for the current patient
955 // this is read-only!
956 $query = "SELECT title, comments FROM lists WHERE " .
957 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
958 "ORDER BY begdate";
959 // echo "<!-- $query -->\n"; // debugging
960 $lres = sqlStatement($query, array($GLOBALS['pid']));
961 $count = 0;
962 while ($lrow = sqlFetchArray($lres)) {
963 if ($count++) {
964 echo "<br />";
967 echo htmlspecialchars($lrow['title'], ENT_NOQUOTES);
968 if ($lrow['comments']) {
969 echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
972 } elseif ($data_type == 25) { // a set of labeled checkboxes, each with a text field:
973 $tmp = explode('|', $currvalue);
974 $avalue = array();
975 foreach ($tmp as $value) {
976 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
977 $avalue[$matches[1]] = $matches[2];
981 $maxlength = $frow['max_length'];
982 $string_maxlength = "";
983 // if max_length is set to zero, then do not set a maxlength
984 if ($maxlength) {
985 $string_maxlength = "maxlength='".attr($maxlength)."'";
988 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
989 $lres = sqlStatement("SELECT * FROM list_options " .
990 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
991 echo "<table cellpadding='0' cellspacing='0'>";
992 while ($lrow = sqlFetchArray($lres)) {
993 $option_id = $lrow['option_id'];
994 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
995 $restype = substr($avalue[$option_id], 0, 1);
996 $resnote = substr($avalue[$option_id], 2);
998 // Added 5-09 by BM - Translate label if applicable
999 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1001 $option_id = htmlspecialchars($option_id, ENT_QUOTES);
1002 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
1003 " id='check_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
1004 if ($restype) {
1005 echo " checked";
1008 echo " $disabled />&nbsp;</td>";
1009 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1010 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1011 echo "<td><input type='text'" .
1012 " name='form_{$field_id_esc}[$option_id_esc]'" .
1013 " id='form_{$field_id_esc}[$option_id_esc]'" .
1014 " size='$fldlength'" .
1015 " class='form-control' " .
1016 " $string_maxlength" .
1017 " value='$resnote' $disabled /></td>";
1018 echo "</tr>";
1021 echo "</table>";
1022 } elseif ($data_type == 26) { // single-selection list with ability to add to it
1023 echo generate_select_list(
1024 "form_$field_id",
1025 $list_id,
1026 $currvalue,
1027 $description,
1028 ($showEmpty ? $empty_title : ''),
1029 'addtolistclass_'.$list_id,
1030 $lbfchange,
1032 ($disabled ? array('disabled' => 'disabled') : null),
1033 false,
1034 $backup_list
1036 // show the add button if user has access to correct list
1037 $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES);
1038 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
1039 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
1040 if (aco_exist('lists', $list_id)) {
1041 // a specific aco exist for this list, so ensure access
1042 if (acl_check('lists', $list_id)) {
1043 echo $outputAddButton;
1045 } else {
1046 // no specific aco exist for this list, so check for access to 'default' list
1047 if (acl_check('lists', 'default')) {
1048 echo $outputAddButton;
1051 } elseif ($data_type == 27) { // a set of labeled radio buttons
1052 // In this special case, fld_length is the number of columns generated.
1053 $cols = max(1, $frow['fld_length']);
1054 // Support for edit option M.
1055 if (isOption($frow['edit_options'], 'M')) {
1056 ++$membership_group_number;
1059 $lres = sqlStatement("SELECT * FROM list_options " .
1060 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1061 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1062 $tdpct = (int) (100 / $cols);
1063 $got_selected = false;
1064 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1065 $option_id = $lrow['option_id'];
1066 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
1067 if ($count % $cols == 0) {
1068 if ($count) {
1069 echo "</tr>";
1071 echo "<tr>";
1073 echo "<td width='" . attr($tdpct) . "%'>";
1074 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
1075 " value='$option_id_esc' $lbfonchange";
1076 // Support for edit options M and m.
1077 if (isOption($frow['edit_options'], 'M')) {
1078 echo " class='form-control'";
1079 echo " onclick='checkGroupMembers(this, $membership_group_number);'";
1080 } else if (isOption($frow['edit_options'], 'm')) {
1081 echo " class='form-control lbf_memgroup_$membership_group_number'";
1082 } else {
1083 echo " class='form-control'";
1086 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1087 (strlen($currvalue) > 0 && $option_id == $currvalue)) {
1088 echo " checked";
1089 $got_selected = true;
1091 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1092 echo "</td>";
1095 if ($count) {
1096 echo "</tr>";
1097 if ($count > $cols) {
1098 // Add some space after multiple rows of radio buttons.
1099 $cols = htmlspecialchars($cols, ENT_QUOTES);
1100 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1104 echo "</table>";
1105 if (!$got_selected && strlen($currvalue) > 0) {
1106 $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES);
1107 $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES);
1108 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
1110 } elseif ($data_type == 28 || $data_type == 32) { // special case for history of lifestyle status; 3 radio buttons
1111 // and a date text field:
1112 // VicarePlus :: A selection list box for smoking status:
1113 $tmp = explode('|', $currvalue);
1114 switch (count($tmp)) {
1115 case "4":
1116 $resnote = $tmp[0];
1117 $restype = $tmp[1];
1118 $resdate = oeFormatShortDate($tmp[2]);
1119 $reslist = $tmp[3];
1120 break;
1121 case "3":
1122 $resnote = $tmp[0];
1123 $restype = $tmp[1];
1124 $resdate = oeFormatShortDate($tmp[2]);
1125 break;
1126 case "2":
1127 $resnote = $tmp[0];
1128 $restype = $tmp[1];
1129 $resdate = "";
1130 break;
1131 case "1":
1132 $resnote = $tmp[0];
1133 $resdate = $restype = "";
1134 break;
1135 default:
1136 $restype = $resdate = $resnote = "";
1137 break;
1140 $maxlength = $frow['max_length'];
1141 $string_maxlength = "";
1142 // if max_length is set to zero, then do not set a maxlength
1143 if ($maxlength) {
1144 $string_maxlength = "maxlength='".attr($maxlength)."'";
1147 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1149 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1150 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1151 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1152 echo "<table cellpadding='0' cellspacing='0'>";
1153 echo "<tr>";
1154 if ($data_type == 28) {
1155 // input text
1156 echo "<td><input type='text'" .
1157 " name='form_$field_id_esc'" .
1158 " id='form_$field_id_esc'" .
1159 " size='$fldlength'" .
1160 " $string_maxlength" .
1161 " value='$resnote' $disabled />&nbsp;</td>";
1162 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1163 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1164 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1165 } elseif ($data_type == 32) {
1166 // input text
1167 echo "<tr><td><input type='text'" .
1168 " name='form_text_$field_id_esc'" .
1169 " id='form_text_$field_id_esc'" .
1170 " size='$fldlength'" .
1171 " class='form-control'" .
1172 " $string_maxlength" .
1173 " value='$resnote' $disabled />&nbsp;</td></tr>";
1174 echo "<td>";
1175 //Selection list for smoking status
1176 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1177 echo generate_select_list(
1178 "form_$field_id",
1179 $list_id,
1180 $reslist,
1181 $description,
1182 ($showEmpty ? $empty_title : ''),
1184 $onchange,
1186 ($disabled ? array('disabled' => 'disabled') : null)
1188 echo "</td>";
1189 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1192 // current
1193 echo "<td class='text' ><input type='radio'" .
1194 " name='radio_{$field_id_esc}'" .
1195 " id='radio_{$field_id_esc}[current]'" .
1196 " class='form-control'" .
1197 " value='current" . $field_id_esc . "' $lbfonchange";
1198 if ($restype == "current" . $field_id) {
1199 echo " checked";
1202 if ($data_type == 32) {
1203 echo " onClick='smoking_statusClicked(this)'";
1206 echo " />" . xlt('Current') . "&nbsp;</td>";
1207 // quit
1208 echo "<td class='text'><input type='radio'" .
1209 " name='radio_{$field_id_esc}'" .
1210 " id='radio_{$field_id_esc}[quit]'" .
1211 " class='form-control'" .
1212 " value='quit".$field_id_esc."' $lbfonchange";
1213 if ($restype == "quit" . $field_id) {
1214 echo " checked";
1217 if ($data_type == 32) {
1218 echo " onClick='smoking_statusClicked(this)'";
1221 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1222 // quit date
1223 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1224 " value='$resdate'" .
1225 " title='$description'" .
1226 " $disabled />";
1227 echo "&nbsp;</td>";
1228 // never
1229 echo "<td class='text'><input type='radio'" .
1230 " name='radio_{$field_id_esc}'" .
1231 " class='form-control'" .
1232 " id='radio_{$field_id_esc}[never]'" .
1233 " value='never" . $field_id_esc . "' $lbfonchange";
1234 if ($restype == "never" . $field_id) {
1235 echo " checked";
1238 if ($data_type == 32) {
1239 echo " onClick='smoking_statusClicked(this)'";
1242 echo " />" . xlt('Never') . "&nbsp;</td>";
1243 // Not Applicable
1244 echo "<td class='text'><input type='radio'" .
1245 " class='form-control' " .
1246 " name='radio_{$field_id}'" .
1247 " id='radio_{$field_id}[not_applicable]'" .
1248 " value='not_applicable" . $field_id . "' $lbfonchange";
1249 if ($restype == "not_applicable" . $field_id) {
1250 echo " checked";
1253 if ($data_type == 32) {
1254 echo " onClick='smoking_statusClicked(this)'";
1257 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1259 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1260 echo "<td class='text' ><div id='smoke_code'></div></td>";
1261 echo "</tr>";
1262 echo "</table>";
1263 } elseif ($data_type == 31) { // static text. read-only, of course.
1264 echo parse_static_text($frow);
1265 } elseif ($data_type == 34) {
1266 // $data_type == 33
1267 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1268 // $data_type == 33
1270 $arr = explode("|*|*|*|", $currvalue);
1271 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;'>";
1272 echo "<div id='form_{$field_id}_div' class='text-area' style='min-width:100pt'>" . $arr[0] . "</div>";
1273 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>";
1274 echo "</a>";
1275 } elseif ($data_type == 35) { //facilities drop-down list
1276 if (empty($currvalue)) {
1277 $currvalue = 0;
1280 dropdown_facility(
1281 $selected = $currvalue,
1282 $name = "form_$field_id_esc",
1283 $allow_unspecified = true,
1284 $allow_allfacilities = false,
1285 $disabled,
1286 $lbfchange
1288 } elseif ($data_type == 36) { //multiple select, supports backup list
1289 echo generate_select_list(
1290 "form_$field_id",
1291 $list_id,
1292 $currvalue,
1293 $description,
1294 $showEmpty ? $empty_title : '',
1296 $lbfchange,
1298 null,
1299 true,
1300 $backup_list
1302 } elseif ($data_type == 40) { // Canvas and related elements for browser-side image drawing.
1303 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1304 // Unlike other field types, width and height are in pixels.
1305 $canWidth = intval($frow['fld_length']);
1306 $canHeight = intval($frow['fld_rows']);
1307 if (empty($currvalue)) {
1308 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1309 // If defined this is the filename of the default starting image.
1310 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1314 $mywidth = 50 + ($canWidth > 250 ? $canWidth : 250);
1315 $myheight = 31 + ($canHeight > 261 ? $canHeight : 261);
1316 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1317 // Hidden form field exists to send updated data to the server at submit time.
1318 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1319 // Hidden image exists to support initialization of the canvas.
1320 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1321 // $date_init is a misnomer but it's the place for browser-side setup logic.
1322 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1323 } elseif ($data_type == 41 || $data_type == 42) {
1324 $datatype = 'patient-signature';
1325 $cpid = $GLOBALS['pid'];
1326 $cuser = $_SESSION['authUserID'];
1327 if ($data_type == 42) {
1328 $datatype = 'admin-signature';
1330 echo "<input type='hidden' id='form_$field_id_esc' name='form_$field_id_esc' value='' />\n";
1331 echo "<img class='signature' id='form_{$field_id_esc}_img' title='$description'
1332 data-pid='$cpid' data-user='$cuser' data-type='$datatype'
1333 data-action='fetch_signature' alt='Get Signature' src='" . attr($currvalue) . "'>\n";
1337 function generate_print_field($frow, $currvalue)
1339 global $rootdir, $date_init, $ISSUE_TYPES;
1341 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1343 $data_type = $frow['data_type'];
1344 $field_id = $frow['field_id'];
1345 $list_id = $frow['list_id'];
1346 $fld_length = $frow['fld_length'];
1347 $backup_list = $frow['list_backup_id'];
1349 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1351 // Can pass $frow['empty_title'] with this variable, otherwise
1352 // will default to 'Unassigned'.
1353 // If it is 'SKIP' then an empty text title is completely skipped.
1354 $showEmpty = true;
1355 if (isset($frow['empty_title'])) {
1356 if ($frow['empty_title'] == "SKIP") {
1357 //do not display an 'empty' choice
1358 $showEmpty = false;
1359 $empty_title = "Unassigned";
1360 } else {
1361 $empty_title = $frow['empty_title'];
1363 } else {
1364 $empty_title = "Unassigned";
1367 // generic single-selection list
1368 // Supports backup lists.
1369 if (false && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1370 if (empty($fld_length)) {
1371 if ($list_id == 'titles') {
1372 $fld_length = 3;
1373 } else {
1374 $fld_length = 10;
1378 $tmp = '';
1379 if ($currvalue) {
1380 $lrow = sqlQuery("SELECT title FROM list_options " .
1381 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1382 $tmp = xl_list_label($lrow['title']);
1383 if ($lrow == 0 && !empty($backup_list)) {
1384 // since primary list did not map, try to map to backup list
1385 $lrow = sqlQuery("SELECT title FROM list_options " .
1386 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1387 $tmp = xl_list_label($lrow['title']);
1390 if (empty($tmp)) {
1391 $tmp = "($currvalue)";
1395 /*****************************************************************
1396 echo "<input type='text'" .
1397 " size='$fld_length'" .
1398 " value='$tmp'" .
1399 " class='under'" .
1400 " />";
1401 *****************************************************************/
1402 if ($tmp === '') {
1403 $tmp = '&nbsp;';
1404 } else {
1405 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1408 echo $tmp;
1409 } elseif ($data_type == 2 || $data_type == 15) { // simple text field
1410 /*****************************************************************
1411 echo "<input type='text'" .
1412 " size='$fld_length'" .
1413 " value='$currescaped'" .
1414 " class='under'" .
1415 " />";
1416 *****************************************************************/
1417 if ($currescaped === '') {
1418 $currescaped = '&nbsp;';
1421 echo $currescaped;
1422 } elseif ($data_type == 3) { // long or multi-line text field
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 } elseif ($data_type == 4) { // date
1431 $age_asof_date = '';
1432 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
1433 if ($currvalue === '') {
1434 echo '&nbsp;';
1435 } else {
1436 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
1437 if (!$modtmp) {
1438 echo text(oeFormatShortDate($currvalue));
1439 } else {
1440 echo text(oeFormatDateTime($currvalue));
1442 if ($agestr) {
1443 echo "&nbsp;(" . text($agestr) . ")";
1446 } elseif ($data_type == 10 || $data_type == 11) { // provider list
1447 $tmp = '';
1448 if ($currvalue) {
1449 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1450 "WHERE id = ?", array($currvalue));
1451 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1452 if (empty($tmp)) {
1453 $tmp = "($currvalue)";
1457 /*****************************************************************
1458 echo "<input type='text'" .
1459 " size='$fld_length'" .
1460 " value='$tmp'" .
1461 " class='under'" .
1462 " />";
1463 *****************************************************************/
1464 if ($tmp === '') {
1465 $tmp = '&nbsp;';
1466 } else {
1467 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1470 echo $tmp;
1471 } elseif ($data_type == 12) { // pharmacy list
1472 $tmp = '';
1473 if ($currvalue) {
1474 $pres = get_pharmacies();
1475 while ($prow = sqlFetchArray($pres)) {
1476 $key = $prow['id'];
1477 if ($currvalue == $key) {
1478 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1479 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1480 $prow['line1'] . ' / ' . $prow['city'];
1484 if (empty($tmp)) {
1485 $tmp = "($currvalue)";
1489 /*****************************************************************
1490 echo "<input type='text'" .
1491 " size='$fld_length'" .
1492 " value='$tmp'" .
1493 " class='under'" .
1494 " />";
1495 *****************************************************************/
1496 if ($tmp === '') {
1497 $tmp = '&nbsp;';
1498 } else {
1499 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1502 echo $tmp;
1503 } elseif ($data_type == 13) { // squads
1504 $tmp = '';
1505 if ($currvalue) {
1506 $squads = acl_get_squads();
1507 if ($squads) {
1508 foreach ($squads as $key => $value) {
1509 if ($currvalue == $key) {
1510 $tmp = $value[3];
1515 if (empty($tmp)) {
1516 $tmp = "($currvalue)";
1520 /*****************************************************************
1521 echo "<input type='text'" .
1522 " size='$fld_length'" .
1523 " value='$tmp'" .
1524 " class='under'" .
1525 " />";
1526 *****************************************************************/
1527 if ($tmp === '') {
1528 $tmp = '&nbsp;';
1529 } else {
1530 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1533 echo $tmp;
1534 } elseif ($data_type == 14) { // Address book.
1535 $tmp = '';
1536 if ($currvalue) {
1537 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1538 "WHERE id = ?", array($currvalue));
1539 $uname = $urow['lname'];
1540 if ($urow['fname']) {
1541 $uname .= ", " . $urow['fname'];
1544 $tmp = $uname;
1545 if (empty($tmp)) {
1546 $tmp = "($currvalue)";
1550 /*****************************************************************
1551 echo "<input type='text'" .
1552 " size='$fld_length'" .
1553 " value='$tmp'" .
1554 " class='under'" .
1555 " />";
1556 *****************************************************************/
1557 if ($tmp === '') {
1558 $tmp = '&nbsp;';
1559 } else {
1560 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1563 echo $tmp;
1564 } elseif ($data_type == 16) { // insurance company list
1565 $tmp = '';
1566 if ($currvalue) {
1567 $insprovs = getInsuranceProviders();
1568 foreach ($insprovs as $key => $ipname) {
1569 if ($currvalue == $key) {
1570 $tmp = $ipname;
1574 if (empty($tmp)) {
1575 $tmp = "($currvalue)";
1579 if ($tmp === '') {
1580 $tmp = '&nbsp;';
1581 } else {
1582 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1585 echo $tmp;
1586 } elseif ($data_type == 17) { // issue types
1587 $tmp = '';
1588 if ($currvalue) {
1589 foreach ($ISSUE_TYPES as $key => $value) {
1590 if ($currvalue == $key) {
1591 $tmp = $value[1];
1595 if (empty($tmp)) {
1596 $tmp = "($currvalue)";
1600 if ($tmp === '') {
1601 $tmp = '&nbsp;';
1602 } else {
1603 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1606 echo $tmp;
1607 } elseif ($data_type == 18) { // Visit categories.
1608 $tmp = '';
1609 if ($currvalue) {
1610 $crow = sqlQuery(
1611 "SELECT pc_catid, pc_catname " .
1612 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1613 array($currvalue)
1615 $tmp = xl_appt_category($crow['pc_catname']);
1616 if (empty($tmp)) {
1617 $tmp = "($currvalue)";
1621 if ($tmp === '') {
1622 $tmp = '&nbsp;';
1623 } else {
1624 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1627 echo $tmp;
1628 } elseif ($data_type == 21) { // a single checkbox or set of labeled checkboxes
1629 if (!$list_id) {
1630 echo "<input type='checkbox'";
1631 if ($currvalue) {
1632 echo " checked";
1634 echo " />";
1635 } else {
1636 // In this special case, fld_length is the number of columns generated.
1637 $cols = max(1, $fld_length);
1638 $avalue = explode('|', $currvalue);
1639 $lres = sqlStatement("SELECT * FROM list_options " .
1640 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1641 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1642 $tdpct = (int) (100 / $cols);
1643 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1644 $option_id = $lrow['option_id'];
1645 if ($count % $cols == 0) {
1646 if ($count) {
1647 echo "</tr>";
1650 echo "<tr>";
1652 echo "<td width='" . attr($tdpct) . "%' nowrap>";
1653 echo "<input type='checkbox'";
1654 if (in_array($option_id, $avalue)) {
1655 echo " checked";
1657 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1658 echo "</td>";
1660 if ($count) {
1661 echo "</tr>";
1662 if ($count > $cols) {
1663 // Add some space after multiple rows of checkboxes.
1664 $cols = htmlspecialchars($cols, ENT_QUOTES);
1665 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1668 echo "</table>";
1670 } elseif ($data_type == 22) { // a set of labeled text input fields
1671 $tmp = explode('|', $currvalue);
1672 $avalue = array();
1673 foreach ($tmp as $value) {
1674 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1675 $avalue[$matches[1]] = $matches[2];
1679 $lres = sqlStatement("SELECT * FROM list_options " .
1680 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1681 echo "<table cellpadding='0' cellspacing='0'>";
1682 while ($lrow = sqlFetchArray($lres)) {
1683 $option_id = $lrow['option_id'];
1684 $fldlength = empty($fld_length) ? 20 : $fld_length;
1685 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1686 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1687 $inputValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
1688 echo "<td><input type='text'" .
1689 " class='form-control' " .
1690 " size='$fldlength'" .
1691 " value='$inputValue'" .
1692 " class='under'" .
1693 " /></td></tr>";
1696 echo "</table>";
1697 } elseif ($data_type == 23) { // a set of exam results; 3 radio buttons and a text field:
1698 $tmp = explode('|', $currvalue);
1699 $avalue = array();
1700 foreach ($tmp as $value) {
1701 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1702 $avalue[$matches[1]] = $matches[2];
1706 $fldlength = empty($fld_length) ? 20 : $fld_length;
1707 $lres = sqlStatement("SELECT * FROM list_options " .
1708 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1709 echo "<table cellpadding='0' cellspacing='0'>";
1710 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1711 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
1712 "&nbsp;</td><td class='bold'>" .
1713 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1714 "<td class='bold'>" .
1715 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1716 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1717 while ($lrow = sqlFetchArray($lres)) {
1718 $option_id = $lrow['option_id'];
1719 $restype = substr($avalue[$option_id], 0, 1);
1720 $resnote = substr($avalue[$option_id], 2);
1721 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1722 for ($i = 0; $i < 3; ++$i) {
1723 echo "<td><input type='radio'";
1724 if ($restype === "$i") {
1725 echo " checked";
1728 echo " /></td>";
1731 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1732 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1733 echo "<td><input type='text'" .
1734 " size='$fldlength'" .
1735 " value='$resnote'" .
1736 " class='under form-control' /></td>" .
1737 "</tr>";
1740 echo "</table>";
1741 } elseif ($data_type == 24) { // the list of active allergies for the current patient
1742 // this is read-only!
1743 $query = "SELECT title, comments FROM lists WHERE " .
1744 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1745 "ORDER BY begdate";
1746 $lres = sqlStatement($query, array($GLOBALS['pid']));
1747 $count = 0;
1748 while ($lrow = sqlFetchArray($lres)) {
1749 if ($count++) {
1750 echo "<br />";
1753 echo htmlspecialchars($lrow['title'], ENT_QUOTES);
1754 if ($lrow['comments']) {
1755 echo htmlspecialchars(' (' . $lrow['comments'] . ')', ENT_QUOTES);
1758 } elseif ($data_type == 25) { // a set of labeled checkboxes, each with a text field:
1759 $tmp = explode('|', $currvalue);
1760 $avalue = array();
1761 foreach ($tmp as $value) {
1762 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1763 $avalue[$matches[1]] = $matches[2];
1767 $fldlength = empty($fld_length) ? 20 : $fld_length;
1768 $lres = sqlStatement("SELECT * FROM list_options " .
1769 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1770 echo "<table cellpadding='0' cellspacing='0'>";
1771 while ($lrow = sqlFetchArray($lres)) {
1772 $option_id = $lrow['option_id'];
1773 $restype = substr($avalue[$option_id], 0, 1);
1774 $resnote = substr($avalue[$option_id], 2);
1775 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1776 echo "<td><input type='checkbox'";
1777 if ($restype) {
1778 echo " checked";
1781 echo " />&nbsp;</td>";
1782 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1783 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1784 echo "<td><input type='text'" .
1785 " size='$fldlength'" .
1786 " class='form-control' " .
1787 " value='$resnote'" .
1788 " class='under'" .
1789 " /></td>" .
1790 "</tr>";
1793 echo "</table>";
1794 } elseif ($data_type == 27 || $data_type == 1 || $data_type == 26 || $data_type == 33) {
1795 // a set of labeled radio buttons
1796 // In this special case, fld_length is the number of columns generated.
1797 $cols = max(1, $frow['fld_length']);
1798 $lres = sqlStatement("SELECT * FROM list_options " .
1799 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1800 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1801 $tdpct = (int) (100 / $cols);
1802 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1803 $option_id = $lrow['option_id'];
1804 if ($count % $cols == 0) {
1805 if ($count) {
1806 echo "</tr>";
1809 echo "<tr>";
1811 echo "<td width='" . attr($tdpct) . "%' nowrap>";
1812 echo "<input type='radio'";
1813 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1814 // Do not use defaults for these printable forms.
1815 echo " checked";
1818 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1819 echo "</td>";
1822 if ($count) {
1823 echo "</tr>";
1824 if ($count > $cols) {
1825 // Add some space after multiple rows of radio buttons.
1826 $cols = htmlspecialchars($cols, ENT_QUOTES);
1827 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1831 echo "</table>";
1832 } elseif ($data_type == 28 || $data_type == 32) { // special case for history of lifestyle status; 3 radio buttons and a date text field:
1833 $tmp = explode('|', $currvalue);
1834 switch (count($tmp)) {
1835 case "4":
1836 $resnote = $tmp[0];
1837 $restype = $tmp[1];
1838 $resdate = oeFormatShortDate($tmp[2]) ;
1839 $reslist = $tmp[3];
1840 break;
1841 case "3":
1842 $resnote = $tmp[0];
1843 $restype = $tmp[1];
1844 $resdate = oeFormatShortDate($tmp[2]);
1845 break;
1846 case "2":
1847 $resnote = $tmp[0];
1848 $restype = $tmp[1];
1849 $resdate = "";
1850 break;
1851 case "1":
1852 $resnote = $tmp[0];
1853 $resdate = $restype = "";
1854 break;
1855 default:
1856 $restype = $resdate = $resnote = "";
1857 break;
1860 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1861 echo "<table cellpadding='0' cellspacing='0'>";
1862 echo "<tr>";
1863 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1864 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1865 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1866 if ($data_type == 28) {
1867 echo "<td><input type='text'" .
1868 " size='$fldlength'" .
1869 " class='under'" .
1870 " value='$resnote' /></td>";
1871 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1872 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1873 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1874 } elseif ($data_type == 32) {
1875 echo "<tr><td><input type='text'" .
1876 " size='$fldlength'" .
1877 " class='under form-control'" .
1878 " value='$resnote' /></td></tr>";
1879 $fldlength = 30;
1880 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
1881 echo "<td><input type='text'" .
1882 " size='$fldlength'" .
1883 " class='under form-control'" .
1884 " value='$smoking_status_title' /></td>";
1885 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1888 echo "<td><input type='radio' class='form-control'";
1889 if ($restype == "current".$field_id) {
1890 echo " checked";
1893 echo "/>".htmlspecialchars(xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1895 echo "<td><input type='radio' class='form-control'";
1896 if ($restype == "current".$field_id) {
1897 echo " checked";
1900 echo "/>".htmlspecialchars(xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1902 echo "<td><input type='text' size='6'" .
1903 " value='$resdate'" .
1904 " class='under form-control'" .
1905 " /></td>";
1907 echo "<td><input type='radio' class='form-control'";
1908 if ($restype == "current".$field_id) {
1909 echo " checked";
1912 echo " />".htmlspecialchars(xl('Never'), ENT_NOQUOTES)."</td>";
1914 echo "<td><input type='radio' class='form-control'";
1915 if ($restype == "not_applicable".$field_id) {
1916 echo " checked";
1919 echo " />".htmlspecialchars(xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1920 echo "</tr>";
1921 echo "</table>";
1922 } elseif ($data_type == 31) { // static text. read-only, of course.
1923 echo parse_static_text($frow);
1924 } elseif ($data_type == 34) {
1925 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;'>";
1926 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1927 echo "<div style='display:none'><textarea name='form_{$field_id}' class='form-control' id='form_{$field_id}' stye='display:none'></textarea></div>";
1928 echo "</a>";
1929 } elseif ($data_type == 35) { //facilities drop-down list
1930 // In this special case, fld_length is the number of columns generated.
1931 $cols = max(1, $frow['fld_length']);
1932 $lres = sqlStatement("SELECT id, name FROM facility ORDER BY name");
1933 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1934 $tdpct = (int) (100 / $cols);
1935 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1936 $option_id = $lrow['id'];
1937 if ($count % $cols == 0) {
1938 if ($count) {
1939 echo "</tr>";
1941 echo "<tr>";
1943 echo "<td width='" . attr($tdpct) . "%'>";
1944 echo "<input type='radio'";
1945 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1946 // Do not use defaults for these printable forms.
1947 echo " checked";
1949 echo ">" . htmlspecialchars($lrow['name']);
1950 echo "</td>";
1952 if ($count) {
1953 echo "</tr>";
1954 if ($count > $cols) {
1955 // Add some space after multiple rows of radio buttons.
1956 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1959 echo "</table>";
1960 } elseif ($data_type == 36) { //Multi-select. Supports backup lists.
1961 if (empty($fld_length)) {
1962 if ($list_id == 'titles') {
1963 $fld_length = 3;
1964 } else {
1965 $fld_length = 10;
1969 $tmp = '';
1971 $values_array = explode("|", $currvalue);
1973 $i=0;
1974 foreach ($values_array as $value) {
1975 if ($value) {
1976 $lrow = sqlQuery("SELECT title FROM list_options " .
1977 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1978 $tmp = xl_list_label($lrow['title']);
1979 if ($lrow == 0 && !empty($backup_list)) {
1980 // since primary list did not map, try to map to backup list
1981 $lrow = sqlQuery("SELECT title FROM list_options " .
1982 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1983 $tmp = xl_list_label($lrow['title']);
1986 if (empty($tmp)) {
1987 $tmp = "($value)";
1991 if ($tmp === '') {
1992 $tmp = '&nbsp;';
1993 } else {
1994 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1997 if ($i != 0 && $tmp != '&nbsp;') {
1998 echo ",";
2001 echo $tmp;
2002 $i++;
2004 } elseif ($data_type == 40) { // Image from canvas drawing
2005 if ($currvalue) {
2006 echo "<img src='" . attr($currvalue) . "'>";
2008 } elseif ($data_type == 41 || $data_type == 42) {
2009 if ($currvalue) {
2010 echo "<img style='height:70px;width:auto;' src='" . attr($currvalue) . "'>";
2015 function generate_display_field($frow, $currvalue)
2017 global $ISSUE_TYPES, $facilityService;
2019 $data_type = $frow['data_type'];
2020 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2021 $list_id = $frow['list_id'];
2022 $backup_list = isset($frow['list_backup_id']) ? $frow['list_backup_id'] : null;
2024 $s = '';
2026 // generic selection list or the generic selection list with add on the fly
2027 // feature
2028 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
2029 $lrow = sqlQuery("SELECT title FROM list_options " .
2030 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2031 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2032 //if there is no matching value in the corresponding lists check backup list
2033 // only supported in data types 1,26,33
2034 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2035 $lrow = sqlQuery("SELECT title FROM list_options " .
2036 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2037 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2039 // If match is not found in main and backup lists, return the key with exclamation mark
2040 if ($s == '') {
2041 $s = nl2br(text(xl_list_label($currvalue))).
2042 '<sup> <i class="fa fas fa-exclamation-circle ml-1"></i></sup>';
2044 } elseif ($data_type == 2) { // simple text field
2045 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2046 } elseif ($data_type == 3) { // long or multi-line text field
2047 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2048 } elseif ($data_type == 4) { // date
2049 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
2050 $s = '';
2051 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2052 $age_asof_date = '';
2053 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
2054 if ($currvalue === '') {
2055 $s .= '&nbsp;';
2056 } else {
2057 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
2058 if (!$modtmp) {
2059 $s .= text(oeFormatShortDate($currvalue));
2060 } else {
2061 $s .= text(oeFormatDateTime($currvalue));
2063 if ($agestr) {
2064 $s .= "&nbsp;(" . text($agestr) . ")";
2067 } elseif ($data_type == 10 || $data_type == 11) { // provider
2068 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2069 "WHERE id = ?", array($currvalue));
2070 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']), ENT_NOQUOTES);
2071 } elseif ($data_type == 12) { // pharmacy list
2072 $pres = get_pharmacies();
2073 while ($prow = sqlFetchArray($pres)) {
2074 $key = $prow['id'];
2075 if ($currvalue == $key) {
2076 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
2077 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2078 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
2081 } elseif ($data_type == 13) { // squads
2082 $squads = acl_get_squads();
2083 if ($squads) {
2084 foreach ($squads as $key => $value) {
2085 if ($currvalue == $key) {
2086 $s .= htmlspecialchars($value[3], ENT_NOQUOTES);
2090 } elseif ($data_type == 14) { // address book
2091 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
2092 "WHERE id = ?", array($currvalue));
2093 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
2094 if ($urow['organization'] !="") {
2095 $uname = $urow['organization'];
2096 } else {
2097 $uname = $urow['lname'];
2098 if ($urow['fname']) {
2099 $uname .= ", " . $urow['fname'];
2103 $s = htmlspecialchars($uname, ENT_NOQUOTES);
2104 } elseif ($data_type == 15) { // billing code
2105 $s = '';
2106 if (!empty($currvalue)) {
2107 $relcodes = explode(';', $currvalue);
2108 foreach ($relcodes as $codestring) {
2109 if ($codestring === '') {
2110 continue;
2112 $tmp = lookup_code_descriptions($codestring);
2113 if ($s !== '') {
2114 $s .= '; ';
2116 if (!empty($tmp)) {
2117 $s .= text($tmp);
2118 } else {
2119 $s .= text($codestring) . ' (' . xlt('not found') . ')';
2123 } elseif ($data_type == 16) { // insurance company list
2124 $insprovs = getInsuranceProviders();
2125 foreach ($insprovs as $key => $ipname) {
2126 if ($currvalue == $key) {
2127 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
2130 } elseif ($data_type == 17) { // issue types
2131 foreach ($ISSUE_TYPES as $key => $value) {
2132 if ($currvalue == $key) {
2133 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
2136 } elseif ($data_type == 18) { // visit category
2137 $crow = sqlQuery(
2138 "SELECT pc_catid, pc_catname " .
2139 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2140 array($currvalue)
2142 $s = htmlspecialchars($crow['pc_catname'], ENT_NOQUOTES);
2143 } elseif ($data_type == 21) { // a single checkbox or set of labeled checkboxes
2144 if (!$list_id) {
2145 $s .= $currvalue ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2146 } else {
2147 // In this special case, fld_length is the number of columns generated.
2148 $cols = max(1, $frow['fld_length']);
2149 $avalue = explode('|', $currvalue);
2150 $lres = sqlStatement("SELECT * FROM list_options " .
2151 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2152 $s .= "<table cellspacing='0' cellpadding='0'>";
2153 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2154 $option_id = $lrow['option_id'];
2155 $option_id_esc = text($option_id);
2156 if ($count % $cols == 0) {
2157 if ($count) {
2158 $s .= "</tr>";
2160 $s .= "<tr>";
2162 $s .= "<td nowrap>";
2163 $checked = in_array($option_id, $avalue);
2164 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2165 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2166 $s .= "</td>";
2168 if ($count) {
2169 $s .= "</tr>";
2171 $s .= "</table>";
2173 } elseif ($data_type == 22) { // a set of labeled text input fields
2174 $tmp = explode('|', $currvalue);
2175 $avalue = array();
2176 foreach ($tmp as $value) {
2177 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2178 $avalue[$matches[1]] = $matches[2];
2182 $lres = sqlStatement("SELECT * FROM list_options " .
2183 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2184 $s .= "<table cellpadding='0' cellspacing='0'>";
2185 while ($lrow = sqlFetchArray($lres)) {
2186 $option_id = $lrow['option_id'];
2187 if (empty($avalue[$option_id])) {
2188 continue;
2191 // Added 5-09 by BM - Translate label if applicable
2192 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . ":&nbsp;</td>";
2194 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id], ENT_NOQUOTES) . "</td></tr>";
2197 $s .= "</table>";
2198 } elseif ($data_type == 23) { // a set of exam results; 3 radio buttons and a text field:
2199 $tmp = explode('|', $currvalue);
2200 $avalue = array();
2201 foreach ($tmp as $value) {
2202 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2203 $avalue[$matches[1]] = $matches[2];
2207 $lres = sqlStatement("SELECT * FROM list_options " .
2208 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2209 $s .= "<table cellpadding='0' cellspacing='0'>";
2210 while ($lrow = sqlFetchArray($lres)) {
2211 $option_id = $lrow['option_id'];
2212 $restype = substr($avalue[$option_id], 0, 1);
2213 $resnote = substr($avalue[$option_id], 2);
2214 if (empty($restype) && empty($resnote)) {
2215 continue;
2218 // Added 5-09 by BM - Translate label if applicable
2219 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2221 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
2222 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2223 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2224 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2225 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2226 $s .= "</tr>";
2229 $s .= "</table>";
2230 } elseif ($data_type == 24) { // the list of active allergies for the current patient
2231 $query = "SELECT title, comments FROM lists WHERE " .
2232 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2233 "ORDER BY begdate";
2234 // echo "<!-- $query -->\n"; // debugging
2235 $lres = sqlStatement($query, array($GLOBALS['pid']));
2236 $count = 0;
2237 while ($lrow = sqlFetchArray($lres)) {
2238 if ($count++) {
2239 $s .= "<br />";
2242 $s .= htmlspecialchars($lrow['title'], ENT_NOQUOTES);
2243 if ($lrow['comments']) {
2244 $s .= ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
2247 } elseif ($data_type == 25) { // a set of labeled checkboxes, each with a text field:
2248 $tmp = explode('|', $currvalue);
2249 $avalue = array();
2250 foreach ($tmp as $value) {
2251 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2252 $avalue[$matches[1]] = $matches[2];
2256 $lres = sqlStatement("SELECT * FROM list_options " .
2257 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2258 $s .= "<table cellpadding='0' cellspacing='0'>";
2259 while ($lrow = sqlFetchArray($lres)) {
2260 $option_id = $lrow['option_id'];
2261 $restype = substr($avalue[$option_id], 0, 1);
2262 $resnote = substr($avalue[$option_id], 2);
2263 if (empty($restype) && empty($resnote)) {
2264 continue;
2267 // Added 5-09 by BM - Translate label if applicable
2268 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2270 $restype = $restype ? xl('Yes') : xl('No');
2271 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2272 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2273 $s .= "</tr>";
2276 $s .= "</table>";
2277 } elseif ($data_type == 27) { // a set of labeled radio buttons
2278 // In this special case, fld_length is the number of columns generated.
2279 $cols = max(1, $frow['fld_length']);
2280 $lres = sqlStatement("SELECT * FROM list_options " .
2281 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2282 $s .= "<table cellspacing='0' cellpadding='0'>";
2283 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2284 $option_id = $lrow['option_id'];
2285 $option_id_esc = text($option_id);
2286 if ($count % $cols == 0) {
2287 if ($count) {
2288 $s .= "</tr>";
2290 $s .= "<tr>";
2292 $s .= "<td nowrap>";
2293 $checked = ((strlen($currvalue) == 0 && $lrow['is_default']) ||
2294 (strlen($currvalue) > 0 && $option_id == $currvalue));
2295 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2296 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2297 $s .= "</td>";
2299 if ($count) {
2300 $s .= "</tr>";
2302 $s .= "</table>";
2303 } elseif ($data_type == 28 || $data_type == 32) { // special case for history of lifestyle status; 3 radio buttons
2304 // and a date text field:
2305 // VicarePlus :: A selection list for smoking status.
2306 $tmp = explode('|', $currvalue);
2307 switch (count($tmp)) {
2308 case "4":
2309 $resnote = $tmp[0];
2310 $restype = $tmp[1];
2311 $resdate = oeFormatShortDate($tmp[2]);
2312 $reslist = $tmp[3];
2313 break;
2314 case "3":
2315 $resnote = $tmp[0];
2316 $restype = $tmp[1];
2317 $resdate = oeFormatShortDate($tmp[2]);
2318 break;
2319 case "2":
2320 $resnote = $tmp[0];
2321 $restype = $tmp[1];
2322 $resdate = "";
2323 break;
2324 case "1":
2325 $resnote = $tmp[0];
2326 $resdate = $restype = "";
2327 break;
2328 default:
2329 $restype = $resdate = $resnote = "";
2330 break;
2333 $s .= "<table cellpadding='0' cellspacing='0'>";
2335 $s .= "<tr>";
2336 $res = "";
2337 if ($restype == "current".$field_id) {
2338 $res = xl('Current');
2341 if ($restype == "quit".$field_id) {
2342 $res = xl('Quit');
2345 if ($restype == "never".$field_id) {
2346 $res = xl('Never');
2349 if ($restype == "not_applicable".$field_id) {
2350 $res = xl('N/A');
2353 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2354 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2355 if ($data_type == 28) {
2356 if (!empty($resnote)) {
2357 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2359 } elseif ($data_type == 32) { //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2360 // changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2361 $smoke_codes = getSmokeCodes();
2362 if (!empty($reslist)) {
2363 if ($smoke_codes[$reslist]!="") {
2364 $code_desc = "( ".$smoke_codes[$reslist]." )";
2367 $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>";
2370 if (!empty($resnote)) {
2371 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2375 if (!empty($res)) {
2376 $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'), ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res, ENT_NOQUOTES) . "&nbsp;</td>";
2379 if ($restype == "quit".$field_id) {
2380 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate, ENT_NOQUOTES) . "&nbsp;</td>";
2383 $s .= "</tr>";
2384 $s .= "</table>";
2385 } elseif ($data_type == 31) { // static text. read-only, of course.
2386 $s .= parse_static_text($frow);
2387 } elseif ($data_type == 34) {
2388 $arr = explode("|*|*|*|", $currvalue);
2389 for ($i=0; $i<sizeof($arr); $i++) {
2390 $s.=$arr[$i];
2392 } elseif ($data_type == 35) { // facility
2393 $urow = $facilityService->getById($currvalue);
2394 $s = htmlspecialchars($urow['name'], ENT_NOQUOTES);
2395 } elseif ($data_type == 36) { // Multi select. Supports backup lists
2396 $values_array = explode("|", $currvalue);
2397 $i = 0;
2398 foreach ($values_array as $value) {
2399 $lrow = sqlQuery("SELECT title FROM list_options " .
2400 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2401 if ($lrow == 0 && !empty($backup_list)) {
2402 //use back up list
2403 $lrow = sqlQuery("SELECT title FROM list_options " .
2404 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2407 if ($i > 0) {
2408 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2409 } else {
2410 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2413 $i++;
2415 } elseif ($data_type == 40) { // Image from canvas drawing
2416 if ($currvalue) {
2417 $s .= "<img src='" . attr($currvalue) . "'>";
2419 } elseif ($data_type == 41 || $data_type == 42) {
2420 if ($currvalue) {
2421 $s .= "<img style='height:70px;width:auto;' src='" . attr($currvalue) . "'>";
2425 return $s;
2428 // Generate plain text versions of selected LBF field types.
2429 // Currently used by interface/patient_file/download_template.php and interface/main/finder/dynamic_finder_ajax.php.
2430 // More field types might need to be supported here in the future.
2432 function generate_plaintext_field($frow, $currvalue)
2434 global $ISSUE_TYPES;
2436 $data_type = $frow['data_type'];
2437 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2438 $list_id = $frow['list_id'];
2439 $backup_list = $frow['backup_list'];
2440 $s = '';
2442 // generic selection list or the generic selection list with add on the fly
2443 // feature, or radio buttons
2444 // Supports backup lists (for datatypes 1,26,33)
2445 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2446 $lrow = sqlQuery("SELECT title FROM list_options " .
2447 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2448 $s = xl_list_label($lrow['title']);
2449 //if there is no matching value in the corresponding lists check backup list
2450 // only supported in data types 1,26,33
2451 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2452 $lrow = sqlQuery("SELECT title FROM list_options " .
2453 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2454 $s = xl_list_label($lrow['title']);
2456 } elseif ($data_type == 2 || $data_type == 3 || $data_type == 15) { // simple or long text field
2457 $s = $currvalue;
2458 } elseif ($data_type == 4) { // date
2459 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
2460 if (!$modtmp) {
2461 $s = text(oeFormatShortDate($currvalue));
2462 } else {
2463 $s = text(oeFormatDateTime($currvalue));
2465 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2466 $age_asof_date = '';
2467 // Optional display of age or gestational age.
2468 $tmp = optionalAge($frow, $currvalue, $age_asof_date, $description);
2469 if ($tmp) {
2470 $s .= ' ' . $tmp;
2472 } elseif ($data_type == 10 || $data_type == 11) { // provider
2473 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2474 "WHERE id = ?", array($currvalue));
2475 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2476 } elseif ($data_type == 12) { // pharmacy list
2477 $pres = get_pharmacies();
2478 while ($prow = sqlFetchArray($pres)) {
2479 $key = $prow['id'];
2480 if ($currvalue == $key) {
2481 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2482 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2483 $prow['line1'] . ' / ' . $prow['city'];
2486 } elseif ($data_type == 14) { // address book
2487 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2488 "WHERE id = ?", array($currvalue));
2489 $uname = $urow['lname'];
2490 if ($urow['fname']) {
2491 $uname .= ", " . $urow['fname'];
2494 $s = $uname;
2495 } elseif ($data_type == 16) { // insurance company list
2496 $insprovs = getInsuranceProviders();
2497 foreach ($insprovs as $key => $ipname) {
2498 if ($currvalue == $key) {
2499 $s .= $ipname;
2502 } elseif ($data_type == 17) { // issue type
2503 foreach ($ISSUE_TYPES as $key => $value) {
2504 if ($currvalue == $key) {
2505 $s .= $value[1];
2508 } elseif ($data_type == 18) { // visit category
2509 $crow = sqlQuery(
2510 "SELECT pc_catid, pc_catname " .
2511 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2512 array($currvalue)
2514 $s = $crow['pc_catname'];
2515 } elseif ($data_type == 21) { // a set of labeled checkboxes
2516 if (!$list_id) {
2517 $s .= $currvalue ? xlt('Yes') : xlt('No');
2518 } else {
2519 $avalue = explode('|', $currvalue);
2520 $lres = sqlStatement("SELECT * FROM list_options " .
2521 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2522 $count = 0;
2523 while ($lrow = sqlFetchArray($lres)) {
2524 $option_id = $lrow['option_id'];
2525 if (in_array($option_id, $avalue)) {
2526 if ($count++) {
2527 $s .= "; ";
2529 $s .= xl_list_label($lrow['title']);
2533 } elseif ($data_type == 22) { // a set of labeled text input fields
2534 $tmp = explode('|', $currvalue);
2535 $avalue = array();
2536 foreach ($tmp as $value) {
2537 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2538 $avalue[$matches[1]] = $matches[2];
2542 $lres = sqlStatement("SELECT * FROM list_options " .
2543 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2544 while ($lrow = sqlFetchArray($lres)) {
2545 $option_id = $lrow['option_id'];
2546 if (empty($avalue[$option_id])) {
2547 continue;
2550 if ($s !== '') {
2551 $s .= '; ';
2554 $s .= xl_list_label($lrow['title']) . ': ';
2555 $s .= $avalue[$option_id];
2557 } elseif ($data_type == 23) { // A set of exam results; 3 radio buttons and a text field.
2558 // This shows abnormal results only.
2559 $tmp = explode('|', $currvalue);
2560 $avalue = array();
2561 foreach ($tmp as $value) {
2562 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2563 $avalue[$matches[1]] = $matches[2];
2567 $lres = sqlStatement("SELECT * FROM list_options " .
2568 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2569 while ($lrow = sqlFetchArray($lres)) {
2570 $option_id = $lrow['option_id'];
2571 $restype = substr($avalue[$option_id], 0, 1);
2572 $resnote = substr($avalue[$option_id], 2);
2573 if (empty($restype) && empty($resnote)) {
2574 continue;
2577 if ($restype != '2') {
2578 continue; // show abnormal results only
2581 if ($s !== '') {
2582 $s .= '; ';
2585 $s .= xl_list_label($lrow['title']);
2586 if (!empty($resnote)) {
2587 $s .= ': ' . $resnote;
2590 } elseif ($data_type == 24) { // the list of active allergies for the current patient
2591 $query = "SELECT title, comments FROM lists WHERE " .
2592 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2593 "ORDER BY begdate";
2594 $lres = sqlStatement($query, array($GLOBALS['pid']));
2595 $count = 0;
2596 while ($lrow = sqlFetchArray($lres)) {
2597 if ($count++) {
2598 $s .= "; ";
2601 $s .= $lrow['title'];
2602 if ($lrow['comments']) {
2603 $s .= ' (' . $lrow['comments'] . ')';
2606 } elseif ($data_type == 25) { // a set of labeled checkboxes, each with a text field:
2607 $tmp = explode('|', $currvalue);
2608 $avalue = array();
2609 foreach ($tmp as $value) {
2610 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2611 $avalue[$matches[1]] = $matches[2];
2615 $lres = sqlStatement("SELECT * FROM list_options " .
2616 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2617 while ($lrow = sqlFetchArray($lres)) {
2618 $option_id = $lrow['option_id'];
2619 $restype = substr($avalue[$option_id], 0, 1);
2620 $resnote = substr($avalue[$option_id], 2);
2621 if (empty($restype) && empty($resnote)) {
2622 continue;
2625 if ($s !== '') {
2626 $s .= '; ';
2629 $s .= xl_list_label($lrow['title']);
2630 $restype = $restype ? xl('Yes') : xl('No');
2631 $s .= $restype;
2632 if ($resnote) {
2633 $s .= ' ' . $resnote;
2636 } elseif ($data_type == 28 || $data_type == 32) { // special case for history of lifestyle status; 3 radio buttons and a date text field:
2637 // VicarePlus :: A selection list for smoking status.
2638 $tmp = explode('|', $currvalue);
2639 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2640 $restype = count($tmp) > 1 ? $tmp[1] : '';
2641 $resdate = count($tmp) > 2 ? oeFormatShortDate($tmp[2]) : '';
2642 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2643 $res = "";
2644 if ($restype == "current" . $field_id) {
2645 $res = xl('Current');
2648 if ($restype == "quit" . $field_id) {
2649 $res = xl('Quit');
2652 if ($restype == "never" . $field_id) {
2653 $res = xl('Never');
2656 if ($restype == "not_applicable". $field_id) {
2657 $res = xl('N/A');
2660 if ($data_type == 28) {
2661 if (!empty($resnote)) {
2662 $s .= $resnote;
2664 } elseif ($data_type == 32) { // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2665 if (!empty($reslist)) {
2666 $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
2669 if (!empty($resnote)) {
2670 $s .= ' ' . $resnote;
2674 if (!empty($res)) {
2675 if ($s !== '') {
2676 $s .= ' ';
2679 $s .= xl('Status') . ' ' . $res;
2682 if ($restype == "quit".$field_id) {
2683 if ($s !== '') {
2684 $s .= ' ';
2687 $s .= $resdate;
2689 } elseif ($data_type == 36) { // Multi select. Supports backup lists
2690 $values_array = explode("|", $currvalue);
2692 $i = 0;
2693 foreach ($values_array as $value) {
2694 $lrow = sqlQuery("SELECT title FROM list_options " .
2695 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2697 if ($lrow == 0 && !empty($backup_list)) {
2698 //use back up list
2699 $lrow = sqlQuery("SELECT title FROM list_options " .
2700 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2703 if ($i > 0) {
2704 $s = $s . ", " . xl_list_label($lrow['title']);
2705 } else {
2706 $s = xl_list_label($lrow['title']);
2709 $i++;
2713 return $s;
2716 $CPR = 4; // cells per row of generic data
2717 $last_group = '';
2718 $cell_count = 0;
2719 $item_count = 0;
2721 function disp_end_cell()
2723 global $item_count, $cell_count;
2724 if ($item_count > 0) {
2725 echo "</td>";
2726 $item_count = 0;
2730 function disp_end_row()
2732 global $cell_count, $CPR;
2733 disp_end_cell();
2734 if ($cell_count > 0) {
2735 for (; $cell_count < $CPR; ++$cell_count) {
2736 echo "<td></td>";
2739 echo "</tr>\n";
2740 $cell_count = 0;
2744 function disp_end_group()
2746 global $last_group;
2747 if (strlen($last_group) > 0) {
2748 disp_end_row();
2752 // Accumulate action conditions into a JSON expression for the browser side.
2753 function accumActionConditions($field_id, &$condition_str, &$condarr)
2755 $conditions = empty($condarr) ? array() : unserialize($condarr, ['allowed_classes' => false]);
2756 $action = 'skip';
2757 foreach ($conditions as $key => $condition) {
2758 if ($key === 'action') {
2759 // If specified this should be the first array item.
2760 if ($condition) {
2761 $action = $condition;
2763 continue;
2765 if (empty($condition['id'])) {
2766 continue;
2768 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2769 if ($condition_str) {
2770 $condition_str .= ",\n";
2772 $condition_str .= "{" .
2773 "target:" . js_escape($field_id) . ", " .
2774 "action:" . js_escape($action) . ", " .
2775 "id:" . js_escape($condition['id']) . ", " .
2776 "itemid:" . js_escape($condition['itemid']) . ", " .
2777 "operator:" . js_escape($condition['operator']) . ", " .
2778 "value:" . js_escape($condition['value']) . ", " .
2779 "andor:" . js_escape($andor) . "}";
2783 // This checks if the given field with the given value should have an action applied.
2784 // Originally the only action was skip, but now you can also set the field to a specified value.
2785 // It somewhat mirrors the checkSkipConditions function in options.js.php.
2786 // If you use this for multiple layouts in the same script, you should
2787 // clear $sk_layout_items before each layout.
2788 function isSkipped(&$frow, $currvalue)
2790 global $sk_layout_items;
2792 // Accumulate an array of the encountered fields and their values.
2793 // It is assumed that fields appear before they are tested by another field.
2794 // TBD: Bad assumption?
2795 $field_id = $frow['field_id'];
2796 if (!is_array($sk_layout_items)) {
2797 $sk_layout_items = array();
2799 $sk_layout_items[$field_id] = array('row' => $frow, 'value' => $currvalue);
2801 if (empty($frow['conditions'])) {
2802 return false;
2805 $skiprows = unserialize($frow['conditions'], ['allowed_classes' => false]);
2806 $prevandor = '';
2807 $prevcond = false;
2808 $datatype = $frow['data_type'];
2809 $action = 'skip'; // default action if none specified
2811 foreach ($skiprows as $key => $skiprow) {
2812 // id referenced field id
2813 // itemid referenced array key if applicable
2814 // operator "eq", "ne", "se" or "ns"
2815 // value if eq or ne, some string to compare with
2816 // andor "and", "or" or empty
2818 if ($key === 'action') {
2819 // Action value is a string. It can be "skip", or "value=" followed by a value.
2820 $action = $skiprow;
2821 continue;
2824 if (empty($skiprow['id'])) {
2825 continue;
2828 $id = $skiprow['id'];
2829 if (!isset($sk_layout_items[$id])) {
2830 error_log("Function isSkipped() cannot find skip source field '" . errorLogEscape($id) . "'.");
2831 continue;
2833 $itemid = $skiprow['itemid'];
2834 $operator = $skiprow['operator'];
2835 $skipval = $skiprow['value'];
2836 $srcvalue = $sk_layout_items[$id]['value'];
2837 $src_datatype = $sk_layout_items[$id]['row']['data_type'];
2838 $src_list_id = $sk_layout_items[$id]['row']['list_id'];
2840 // Some data types use itemid and we have to dig for their value.
2841 if ($src_datatype == 21 && $src_list_id) { // array of checkboxes
2842 $tmp = explode('|', $srcvalue);
2843 $srcvalue = in_array($itemid, $tmp);
2844 } elseif ($src_datatype == 22 || $src_datatype == 23 || $src_datatype == 25) {
2845 $tmp = explode('|', $srcvalue);
2846 $srcvalue = '';
2847 foreach ($tmp as $tmp2) {
2848 if (strpos($tmp2, "$itemid:") === 0) {
2849 if ($datatype == 22) {
2850 $srcvalue = substr($tmp2, strlen($itemid) + 1);
2851 } else {
2852 $srcvalue = substr($tmp2, strlen($itemid) + 1, 1);
2858 // Compute the result of the test for this condition row.
2859 // PHP's looseness with variable type conversion helps us here.
2860 $condition = false;
2861 if ($operator == 'eq') {
2862 $condition = $srcvalue == $skipval;
2863 } elseif ($operator == 'ne') {
2864 $condition = $srcvalue != $skipval;
2865 } elseif ($operator == 'se') {
2866 $condition = $srcvalue == true;
2867 } elseif ($operator == 'ns') {
2868 $condition = $srcvalue != true;
2869 } else {
2870 error_log("Unknown skip operator '" . errorLogEscape($operator) . "' for field '" . errorLogEscape($field_id) . "'.");
2873 // Logic to accumulate multiple conditions for the same target.
2874 if ($prevandor == 'and') {
2875 $condition = $condition && $prevcond;
2876 } elseif ($prevandor == 'or') {
2877 $condition = $condition || $prevcond;
2879 $prevandor = $skiprow['andor'];
2880 $prevcond = $condition;
2882 return $prevcond ? $action : '';
2885 // Load array of names of the given layout and its groups.
2886 function getLayoutProperties($formtype, &$grparr, $sel = "grp_title")
2888 if ($sel != '*' && strpos($sel, 'grp_group_id') === false) {
2889 $sel = "grp_group_id, $sel";
2891 $gres = sqlStatement("SELECT $sel FROM layout_group_properties WHERE grp_form_id = ? " .
2892 "ORDER BY grp_group_id", array($formtype));
2893 while ($grow = sqlFetchArray($gres)) {
2894 $grparr[$grow['grp_group_id']] = $grow;
2898 function display_layout_rows($formtype, $result1, $result2 = '')
2900 global $item_count, $cell_count, $last_group, $CPR;
2902 $grparr = array();
2903 getLayoutProperties($formtype, $grparr, '*');
2905 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
2907 $fres = sqlStatement("SELECT * FROM layout_options " .
2908 "WHERE form_id = ? AND uor > 0 " .
2909 "ORDER BY group_id, seq", array($formtype));
2911 while ($frow = sqlFetchArray($fres)) {
2912 $this_group = $frow['group_id'];
2913 $titlecols = $frow['titlecols'];
2914 $datacols = $frow['datacols'];
2915 $data_type = $frow['data_type'];
2916 $field_id = $frow['field_id'];
2917 $list_id = $frow['list_id'];
2918 $currvalue = '';
2919 $jump_new_row = isOption($frow['edit_options'], 'J');
2920 $prepend_blank_row = isOption($frow['edit_options'], 'K');
2922 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
2924 if ($formtype == 'DEM') {
2925 if (strpos($field_id, 'em_') === 0) {
2926 // Skip employer related fields, if it's disabled.
2927 if ($GLOBALS['omit_employers']) {
2928 continue;
2931 $tmp = substr($field_id, 3);
2932 if (isset($result2[$tmp])) {
2933 $currvalue = $result2[$tmp];
2935 } else {
2936 if (isset($result1[$field_id])) {
2937 $currvalue = $result1[$field_id];
2940 } else {
2941 if (isset($result1[$field_id])) {
2942 $currvalue = $result1[$field_id];
2946 // Handle a data category (group) change.
2947 if (strcmp($this_group, $last_group) != 0) {
2948 $group_name = $grparr[$this_group]['grp_title'];
2949 // totally skip generating the employer category, if it's disabled.
2950 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
2951 continue;
2954 disp_end_group();
2955 $last_group = $this_group;
2958 // filter out all the empty field data from the patient report.
2959 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2960 // Handle starting of a new row.
2961 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0 || $prepend_blank_row || $jump_new_row) {
2962 disp_end_row();
2963 if ($prepend_blank_row) {
2964 echo "<tr><td class='label' colspan='" . ($CPR + 1) . "'>&nbsp;</td></tr>\n";
2966 echo "<tr>";
2967 if ($group_name) {
2968 echo "<td class='groupname'>";
2969 echo text(xl_layout_label($group_name));
2970 $group_name = '';
2971 } else {
2972 echo "<td valign='top'>&nbsp;";
2975 echo "</td>";
2978 if ($item_count == 0 && $titlecols == 0) {
2979 $titlecols = 1;
2982 // Handle starting of a new label cell.
2983 if ($titlecols > 0) {
2984 disp_end_cell();
2985 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
2986 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
2987 echo "<td class='label_custom' colspan='$titlecols_esc' ";
2988 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2989 echo ">";
2990 $cell_count += $titlecols;
2993 ++$item_count;
2995 // Added 5-09 by BM - Translate label if applicable
2996 if ($frow['title']) {
2997 $tmp = xl_layout_label($frow['title']);
2998 echo text($tmp);
2999 // Append colon only if label does not end with punctuation.
3000 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3001 echo ':';
3003 } else {
3004 echo "&nbsp;";
3007 // Handle starting of a new data cell.
3008 if ($datacols > 0) {
3009 disp_end_cell();
3010 //echo "<td class='text data' colspan='$datacols' valign='top'";
3011 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3012 echo "<td class='text data' colspan='$datacols_esc'";
3013 //if ($cell_count > 0) echo " style='padding-left:5pt'";
3014 echo ">";
3015 $cell_count += $datacols;
3018 ++$item_count;
3019 echo generate_display_field($frow, $currvalue);
3023 disp_end_group();
3026 function display_layout_tabs($formtype, $result1, $result2 = '')
3028 global $item_count, $cell_count, $last_group, $CPR;
3030 $grparr = array();
3031 getLayoutProperties($formtype, $grparr);
3033 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3034 "WHERE form_id = ? AND uor > 0 " .
3035 "ORDER BY group_id", array($formtype));
3037 $first = true;
3038 while ($frow = sqlFetchArray($fres)) {
3039 $this_group = $frow['group_id'];
3040 // $group_name = substr($this_group, 1);
3041 $group_name = $grparr[$this_group]['grp_title'];
3042 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3043 continue;
3046 <li <?php echo $first ? 'class="current"' : '' ?>>
3047 <a href="#" id="header_tab_<?php echo attr($group_name); ?>">
3048 <?php echo text(xl_layout_label($group_name)); ?></a>
3049 </li>
3050 <?php
3051 $first = false;
3055 function display_layout_tabs_data($formtype, $result1, $result2 = '')
3057 global $item_count, $cell_count, $last_group, $CPR;
3059 $grparr = array();
3060 getLayoutProperties($formtype, $grparr, '*');
3062 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3064 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3065 "WHERE form_id = ? AND uor > 0 " .
3066 "ORDER BY group_id", array($formtype));
3068 $first = true;
3069 while ($frow = sqlFetchArray($fres)) {
3070 $this_group = isset($frow['group_id']) ? $frow['group_id'] : "" ;
3072 if ($grparr[$this_group]['grp_columns'] === 'Employer' && $GLOBALS['omit_employers']) {
3073 continue;
3075 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3076 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : xl_layout_label($grparr[$this_group]['grp_subtitle']);
3078 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3079 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3080 "ORDER BY seq", array($formtype, $this_group));
3083 <div class="tab <?php echo $first ? 'current' : '' ?>">
3084 <table border='0' cellpadding='0'>
3086 <?php
3087 while ($group_fields = sqlFetchArray($group_fields_query)) {
3088 $titlecols = $group_fields['titlecols'];
3089 $datacols = $group_fields['datacols'];
3090 $data_type = $group_fields['data_type'];
3091 $field_id = $group_fields['field_id'];
3092 $list_id = $group_fields['list_id'];
3093 $currvalue = '';
3094 $edit_options = $group_fields['edit_options'];
3095 $jump_new_row = isOption($edit_options, 'J');
3096 $prepend_blank_row = isOption($edit_options, 'K');
3098 if ($formtype == 'DEM') {
3099 if (strpos($field_id, 'em_') === 0) {
3100 // Skip employer related fields, if it's disabled.
3101 if ($GLOBALS['omit_employers']) {
3102 continue;
3105 $tmp = substr($field_id, 3);
3106 if (isset($result2[$tmp])) {
3107 $currvalue = $result2[$tmp];
3109 } else {
3110 if (isset($result1[$field_id])) {
3111 $currvalue = $result1[$field_id];
3114 } else {
3115 if (isset($result1[$field_id])) {
3116 $currvalue = $result1[$field_id];
3120 // Skip this field if action conditions call for that.
3121 // Note this also accumulates info for subsequent skip tests.
3122 $skip_this_field = isSkipped($group_fields, $currvalue) == 'skip';
3124 // Skip this field if its do-not-print option is set.
3125 if (isOption($edit_options, 'X') !== false) {
3126 $skip_this_field = true;
3129 // Handle a data category (group) change.
3130 if (strcmp($this_group, $last_group) != 0) {
3131 $group_name = $grparr[$this_group]['grp_title'];
3132 // totally skip generating the employer category, if it's disabled.
3133 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3134 continue;
3136 $last_group = $this_group;
3139 // Handle starting of a new row.
3140 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0 || $prepend_blank_row || $jump_new_row) {
3141 disp_end_row();
3142 if ($subtitle) {
3143 // Group subtitle exists and is not displayed yet.
3144 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3145 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3146 $subtitle = '';
3148 if ($prepend_blank_row) {
3149 echo "<tr><td class='label' colspan='$CPR'>&nbsp;</td></tr>\n";
3151 echo "<tr>";
3154 if ($item_count == 0 && $titlecols == 0) {
3155 $titlecols = 1;
3158 // Handle starting of a new label cell.
3159 if ($titlecols > 0) {
3160 disp_end_cell();
3161 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3162 $field_id_label = 'label_'.$group_fields['field_id'];
3163 echo "<td class='label_custom' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
3164 echo ">";
3165 $cell_count += $titlecols;
3168 ++$item_count;
3170 $field_id_label = 'label_'.$group_fields['field_id'];
3171 echo "<span id='".attr($field_id_label)."'>";
3172 if ($skip_this_field) {
3173 // No label because skipping
3174 } elseif ($group_fields['title']) {
3175 $tmp = xl_layout_label($group_fields['title']);
3176 echo text($tmp);
3177 // Append colon only if label does not end with punctuation.
3178 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3179 echo ':';
3181 } else {
3182 echo "&nbsp;";
3184 echo "</span>";
3186 // Handle starting of a new data cell.
3187 if ($datacols > 0) {
3188 disp_end_cell();
3189 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3190 $field_id = 'text_'.$group_fields['field_id'];
3191 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
3192 if (!$skip_this_field && $data_type == 3) {
3193 // Textarea gets a light grey border.
3194 echo " style='border:1px solid #cccccc'";
3196 echo ">";
3197 $cell_count += $datacols;
3198 } else {
3199 $field_id = 'text_'.$group_fields['field_id'];
3200 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
3203 ++$item_count;
3204 if (!$skip_this_field) {
3205 echo generate_display_field($group_fields, $currvalue);
3209 disp_end_row();
3212 </table>
3213 </div>
3215 <?php
3217 $first = false;
3221 function display_layout_tabs_data_editable($formtype, $result1, $result2 = '')
3223 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
3225 $grparr = array();
3226 getLayoutProperties($formtype, $grparr, '*');
3228 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3230 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3231 "WHERE form_id = ? AND uor > 0 " .
3232 "ORDER BY group_id", array($formtype));
3234 $first = true;
3235 $condition_str = '';
3237 while ($frow = sqlFetchArray($fres)) {
3238 $this_group = $frow['group_id'];
3239 $group_name = $grparr[$this_group]['grp_title'];
3240 $group_name_esc = text($group_name);
3242 if ($grparr[$this_group]['grp_title'] === 'Employer' && $GLOBALS['omit_employers']) {
3243 continue;
3245 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3246 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : xl_layout_label($grparr[$this_group]['grp_subtitle']);
3248 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3249 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3250 "ORDER BY seq", array($formtype, $this_group));
3253 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_', $group_name_esc)?>" >
3254 <table border='0' cellpadding='0'>
3256 <?php
3257 while ($group_fields = sqlFetchArray($group_fields_query)) {
3258 $titlecols = $group_fields['titlecols'];
3259 $datacols = $group_fields['datacols'];
3260 $data_type = $group_fields['data_type'];
3261 $field_id = $group_fields['field_id'];
3262 $list_id = $group_fields['list_id'];
3263 $backup_list = $group_fields['list_backup_id'];
3264 $currvalue = '';
3265 $action = 'skip';
3266 $jump_new_row = isOption($group_fields['edit_options'], 'J');
3267 $prepend_blank_row = isOption($group_fields['edit_options'], 'K');
3269 // Accumulate action conditions into a JSON expression for the browser side.
3270 accumActionConditions($field_id, $condition_str, $group_fields['conditions']);
3272 if ($formtype == 'DEM') {
3273 if (strpos($field_id, 'em_') === 0) {
3274 // Skip employer related fields, if it's disabled.
3275 if ($GLOBALS['omit_employers']) {
3276 continue;
3279 $tmp = substr($field_id, 3);
3280 if (isset($result2[$tmp])) {
3281 $currvalue = $result2[$tmp];
3283 } else {
3284 if (isset($result1[$field_id])) {
3285 $currvalue = $result1[$field_id];
3288 } else {
3289 if (isset($result1[$field_id])) {
3290 $currvalue = $result1[$field_id];
3294 // Handle a data category (group) change.
3295 if (strcmp($this_group, $last_group) != 0) {
3296 // totally skip generating the employer category, if it's disabled.
3297 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3298 continue;
3301 $last_group = $this_group;
3304 // Handle starting of a new row.
3305 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0 || $prepend_blank_row || $jump_new_row) {
3306 disp_end_row();
3307 if ($subtitle) {
3308 // Group subtitle exists and is not displayed yet.
3309 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3310 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3311 $subtitle = '';
3313 if ($prepend_blank_row) {
3314 echo "<tr><td class='label' colspan='$CPR'>&nbsp;</td></tr>\n";
3316 echo "<tr>";
3319 if ($item_count == 0 && $titlecols == 0) {
3320 $titlecols = 1;
3323 // Handle starting of a new label cell.
3324 if ($titlecols > 0) {
3325 disp_end_cell();
3326 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3327 $field_id_label = 'label_'.$group_fields['field_id'];
3328 echo "<td class='label_custom' colspan='$titlecols_esc'";
3329 // This ID is used by skip conditions.
3330 echo " id='label_id_" . attr($field_id) . "'";
3331 echo ">";
3332 $cell_count += $titlecols;
3335 ++$item_count;
3337 if ($group_fields['title']) {
3338 $tmp = xl_layout_label($group_fields['title']);
3339 echo text($tmp);
3340 // Append colon only if label does not end with punctuation.
3341 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3342 echo ':';
3344 } else {
3345 echo "&nbsp;";
3348 // Handle starting of a new data cell.
3349 if ($datacols > 0) {
3350 disp_end_cell();
3351 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3352 $field_id = 'text_'.$group_fields['field_id'];
3353 echo "<td class='text data' colspan='$datacols_esc'";
3354 // This ID is used by action conditions.
3355 echo " id='value_id_" . attr($field_id) . "'";
3356 echo ">";
3357 $cell_count += $datacols;
3360 ++$item_count;
3362 echo generate_form_field($group_fields, $currvalue);
3366 </table>
3367 </div>
3369 <?php
3371 $first = false;
3375 // From the currently posted HTML form, this gets the value of the
3376 // field corresponding to the provided layout_options table row.
3378 function get_layout_form_value($frow, $prefix = 'form_')
3380 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
3381 $data_type = $frow['data_type'];
3382 $field_id = $frow['field_id'];
3383 $value = '';
3384 if (isset($_POST["$prefix$field_id"])) {
3385 if ($data_type == 4) {
3386 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
3387 if (!$modtmp) {
3388 $value = DateToYYYYMMDD($_POST["$prefix$field_id"]);
3389 } else {
3390 $value = DateTimeToYYYYMMDDHHMMSS($_POST["$prefix$field_id"]);
3392 } elseif ($data_type == 21) {
3393 if (!$frow['list_id']) {
3394 if (!empty($_POST["form_$field_id"])) {
3395 $value = xlt('Yes');
3397 } else {
3398 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
3399 // must be concatenated into a |-separated string.
3400 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3401 if (strlen($value)) {
3402 $value .= '|';
3404 $value .= $key;
3407 } elseif ($data_type == 22) {
3408 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
3409 // into "key:value|key:value|...".
3410 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3411 $val = str_replace('|', ' ', $val);
3412 if (strlen($value)) {
3413 $value .= '|';
3416 $value .= "$key:$val";
3418 } elseif ($data_type == 23) {
3419 // $_POST["$prefix$field_id"] is an array of text fields with companion
3420 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
3421 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3422 $restype = $_POST["radio_{$field_id}"][$key];
3423 if (empty($restype)) {
3424 $restype = '0';
3427 $val = str_replace('|', ' ', $val);
3428 if (strlen($value)) {
3429 $value .= '|';
3432 $value .= "$key:$restype:$val";
3434 } elseif ($data_type == 25) {
3435 // $_POST["$prefix$field_id"] is an array of text fields with companion
3436 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
3437 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3438 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
3439 $val = str_replace('|', ' ', $val);
3440 if (strlen($value)) {
3441 $value .= '|';
3444 $value .= "$key:$restype:$val";
3446 } elseif ($data_type == 28 || $data_type == 32) {
3447 // $_POST["$prefix$field_id"] is an date text fields with companion
3448 // radio buttons to be imploded into "notes|type|date".
3449 $restype = $_POST["radio_{$field_id}"];
3450 if (empty($restype)) {
3451 $restype = '0';
3454 $resdate = DateToYYYYMMDD(str_replace('|', ' ', $_POST["date_$field_id"]));
3455 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3456 if ($data_type == 32) {
3457 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
3458 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3459 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
3460 $value = "$res_text_note|$restype|$resdate|$reslist";
3461 } else {
3462 $value = "$resnote|$restype|$resdate";
3464 } elseif ($data_type == 36) {
3465 $value_array = $_POST["form_$field_id"];
3466 $i = 0;
3467 foreach ($value_array as $key => $valueofkey) {
3468 if ($i == 0) {
3469 $value = $valueofkey;
3470 } else {
3471 $value = $value . "|" . $valueofkey;
3474 $i++;
3476 } else {
3477 $value = $_POST["$prefix$field_id"];
3481 // Better to die than to silently truncate data!
3482 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength) {
3483 die(htmlspecialchars(xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
3484 ":<br />&nbsp;<br />".htmlspecialchars($value, ENT_NOQUOTES));
3487 return trim($value);
3490 // Generate JavaScript validation logic for the required fields.
3492 function generate_layout_validation($form_id)
3494 $fres = sqlStatement("SELECT * FROM layout_options " .
3495 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
3496 "ORDER BY group_id, seq", array($form_id));
3498 while ($frow = sqlFetchArray($fres)) {
3499 $data_type = $frow['data_type'];
3500 $field_id = $frow['field_id'];
3501 $fldtitle = $frow['title'];
3502 if (!$fldtitle) {
3503 $fldtitle = $frow['description'];
3506 $fldname = attr("form_$field_id");
3508 if ($data_type == 40) {
3509 $fldid = "form_" . $field_id;
3510 // Move canvas image data to its hidden form field so the server will get it.
3511 echo
3512 " var canfld = f[" . js_escape($fldid) . "];\n" .
3513 " if (canfld) canfld.value = lbfCanvasGetData(" . js_escape($fldid) . ");\n";
3514 continue;
3516 if ($data_type == 41 || $data_type == 42) {
3517 $fldid = "form_" . $field_id;
3518 // Move canvas image data to its hidden form field so the server will get it.
3519 echo " lbfSetSignature(" . js_escape($fldid) . ");\n";
3520 continue;
3522 if ($frow['uor'] < 2) {
3523 continue;
3526 echo " if (f.$fldname && !f.$fldname.disabled) {\n";
3527 switch ($data_type) {
3528 case 1:
3529 case 11:
3530 case 12:
3531 case 13:
3532 case 14:
3533 case 26:
3534 echo
3535 " if (f.$fldname.selectedIndex <= 0) {\n" .
3536 " alert(" . xlj('Please choose a value for') . " + " .
3537 "\":\\n\" + " . js_escape(xl_layout_label($fldtitle)) . ");\n" .
3538 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3539 " return false;\n" .
3540 " }\n";
3541 break;
3542 case 33:
3543 echo
3544 " if (f.$fldname.selectedIndex <= 0) {\n" .
3545 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3546 " errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3547 " }\n";
3548 break;
3549 case 27: // radio buttons
3550 echo
3551 " var i = 0;\n" .
3552 " for (; i < f.$fldname.length; ++i) if (f.{$fldname}[i].checked) break;\n" .
3553 " if (i >= f.$fldname.length) {\n" .
3554 " alert(" . xlj('Please choose a value for') . " + " .
3555 "\":\\n\" + " . js_escape(xl_layout_label($fldtitle)) . ");\n" .
3556 " return false;\n" .
3557 " }\n";
3558 break;
3559 case 2:
3560 case 3:
3561 case 4:
3562 case 15:
3563 echo
3564 " if (trimlen(f.$fldname.value) == 0) {\n" .
3565 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3566 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
3567 " $('#" . $fldname . "').attr('style','background:red'); \n" .
3568 " errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3569 " } else { " .
3570 " $('#" . $fldname . "').attr('style',''); " .
3571 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
3572 " } \n";
3573 break;
3574 case 36: // multi select
3575 echo
3576 " var multi_select=f['$fldname"."[]']; \n " .
3577 " var multi_choice_made=false; \n".
3578 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
3579 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
3580 " } \n" .
3581 " if(!multi_choice_made)
3582 errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3584 break;
3586 echo " }\n";
3591 * DROPDOWN FOR FACILITIES
3593 * build a dropdown with all facilities
3595 * @param string $selected - name of the currently selected facility
3596 * use '0' for "unspecified facility"
3597 * use '' for "All facilities" (the default)
3598 * @param string $name - the name/id for select form (defaults to "form_facility")
3599 * @param boolean $allow_unspecified - include an option for "unspecified" facility
3600 * defaults to true
3601 * @return void - just echo the html encoded string
3603 * Note: This should become a data-type at some point, according to Brady
3605 function dropdown_facility(
3606 $selected = '',
3607 $name = 'form_facility',
3608 $allow_unspecified = true,
3609 $allow_allfacilities = true,
3610 $disabled = '',
3611 $onchange = ''
3614 global $facilityService;
3616 $have_selected = false;
3617 $fres = $facilityService->getAll();
3619 echo " <select class='form-control' name='" . attr($name) . "' id='" . attr($name) . "'";
3620 if ($onchange) {
3621 echo " onchange='$onchange'";
3624 echo " $disabled>\n";
3626 if ($allow_allfacilities) {
3627 $option_value = '';
3628 $option_selected_attr = '';
3629 if ($selected == '') {
3630 $option_selected_attr = ' selected="selected"';
3631 $have_selected = true;
3634 $option_content = '-- ' . xl('All Facilities') . ' --';
3635 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3636 } elseif ($allow_unspecified) {
3637 $option_value = '0';
3638 $option_selected_attr = '';
3639 if ($selected == '0') {
3640 $option_selected_attr = ' selected="selected"';
3641 $have_selected = true;
3644 $option_content = '-- ' . xl('Unspecified') . ' --';
3645 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3648 foreach ($fres as $frow) {
3649 $facility_id = $frow['id'];
3650 $option_value = $facility_id;
3651 $option_selected_attr = '';
3652 if ($selected == $facility_id) {
3653 $option_selected_attr = ' selected="selected"';
3654 $have_selected = true;
3657 $option_content = $frow['name'];
3658 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3661 if ($allow_unspecified && $allow_allfacilities) {
3662 $option_value = '0';
3663 $option_selected_attr = '';
3664 if ($selected == '0') {
3665 $option_selected_attr = ' selected="selected"';
3666 $have_selected = true;
3669 $option_content = '-- ' . xl('Unspecified') . ' --';
3670 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3673 if (!$have_selected) {
3674 $option_value = $selected;
3675 $option_label = '(' . xl('Do not change') . ')';
3676 $option_content = xl('Missing or Invalid');
3677 echo " <option value='" . attr($option_value) . "' label='" . attr($option_label) . "' selected='selected'>" . text($option_content) . "</option>\n";
3680 echo " </select>\n";
3683 // Expand Collapse Widget
3684 // This forms the header and functionality component of the widget. The information that is displayed
3685 // then follows this function followed by a closing div tag
3687 // $title is the title of the section (already translated)
3688 // $label is identifier used in the tag id's and sql columns
3689 // $buttonLabel is the button label text (already translated)
3690 // $buttonLink is the button link information
3691 // $buttonClass is any additional needed class elements for the button tag
3692 // $linkMethod is the button link method ('javascript' vs 'html')
3693 // $bodyClass is to set class(es) of the body
3694 // $auth is a flag to decide whether to show the button
3695 // $fixedWidth is to flag whether width is fixed
3696 // $forceExpandAlways is a flag to force the widget to always be expanded
3698 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways = false)
3700 if ($fixedWidth) {
3701 echo "<div class='section-header'>";
3702 } else {
3703 echo "<div class='section-header-dynamic'>";
3706 echo "<table><tr>";
3707 if ($auth) {
3708 // show button, since authorized
3709 // first prepare class string
3710 if ($buttonClass) {
3711 $class_string = "css_button_small " . $buttonClass;
3712 } else {
3713 $class_string = "css_button_small";
3716 // next, create the link
3717 if ($linkMethod == "javascript") {
3718 echo "<td><a class='" . attr($class_string) . "' href='javascript:;' onclick='" . $buttonLink . "'";
3719 } else {
3720 echo "<td><a class='" . attr($class_string) . "' href='" . $buttonLink . "'";
3721 if (!isset($_SESSION['patient_portal_onsite_two'])) {
3722 // prevent an error from occuring when calling the function from the patient portal
3723 echo " onclick='top.restoreSession()'";
3727 echo "><span>" .
3728 text($buttonLabel) . "</span></a></td>";
3731 if ($forceExpandAlways) {
3732 // Special case to force the widget to always be expanded
3733 echo "<td><span class='text'><b>" . text($title) . "</b></span>";
3734 $indicatorTag ="style='display:none'";
3737 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3738 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this," .
3739 attr_js($label."_ps_expand") . ")'><span class='text'><b>";
3740 echo text($title) . "</b></span>";
3742 if (isset($_SESSION['patient_portal_onsite_two'])) {
3743 // collapse all entries in the patient portal
3744 $text = xl('expand');
3745 } elseif (getUserSetting($label."_ps_expand")) {
3746 $text = xl('collapse');
3747 } else {
3748 $text = xl('expand');
3751 echo " (<span class='indicator'>" . text($text) .
3752 "</span>)</a></td>";
3753 echo "</tr></table>";
3754 echo "</div>";
3755 if ($forceExpandAlways) {
3756 // Special case to force the widget to always be expanded
3757 $styling = "";
3758 } elseif (isset($_SESSION['patient_portal_onsite_two'])) {
3759 // collapse all entries in the patient portal
3760 $styling = "style='display:none'";
3761 } elseif (getUserSetting($label."_ps_expand")) {
3762 $styling = "";
3763 } else {
3764 $styling = "style='display:none'";
3767 if ($bodyClass) {
3768 $styling .= " class='" . attr($bodyClass) . "'";
3771 //next, create the first div tag to hold the information
3772 // note the code that calls this function will then place the ending div tag after the data
3773 echo "<div id='" . attr($label) . "_ps_expand' " . $styling . ">";
3776 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3777 function billing_facility($name, $select)
3779 global $facilityService;
3781 $fres = $facilityService->getAllBillingLocations();
3782 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' class='form-control' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3783 foreach ($fres as $facrow) {
3784 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3785 echo "<option value=".htmlspecialchars($facrow['id'], ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3788 echo "</select>";
3791 // Generic function to get the translated title value for a particular list option.
3793 function getListItemTitle($list, $option)
3795 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3796 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3797 if (empty($row['title'])) {
3798 return $option;
3801 return xl_list_label($row['title']);
3804 //function to get the translated title value in Patient Transactions
3805 function getLayoutTitle($list, $option)
3807 $row = sqlQuery("SELECT grp_title FROM layout_group_properties " .
3808 "WHERE grp_mapping = ? AND grp_form_id = ? ", array($list, $option));
3810 if (empty($row['grp_title'])) {
3811 return $option;
3813 return xl_list_label($row['grp_title']);
3815 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3816 function getSmokeCodes()
3818 $smoking_codes_arr = array();
3819 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3820 while ($codes_row = sqlFetchArray($smoking_codes)) {
3821 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3824 return $smoking_codes_arr;
3827 // Get the current value for a layout based form field.
3828 // Depending on options this might come from lbf_data, patient_data,
3829 // form_encounter, shared_attributes or elsewhere.
3830 // Returns FALSE if the field ID is invalid (layout error).
3832 function lbf_current_value($frow, $formid, $encounter)
3834 global $pid;
3835 $formname = $frow['form_id'];
3836 $field_id = $frow['field_id'];
3837 $source = $frow['source'];
3838 $currvalue = '';
3839 $deffname = $formname . '_default_' . $field_id;
3840 if ($source == 'D' || $source == 'H') {
3841 // Get from patient_data, employer_data or history_data.
3842 if ($source == 'H') {
3843 $table = 'history_data';
3844 $orderby = 'ORDER BY date DESC LIMIT 1';
3845 } elseif (strpos($field_id, 'em_') === 0) {
3846 $field_id = substr($field_id, 3);
3847 $table = 'employer_data';
3848 $orderby = 'ORDER BY date DESC LIMIT 1';
3849 } else {
3850 $table = 'patient_data';
3851 $orderby = '';
3854 // It is an error if the field does not exist, but don't crash.
3855 $tmp = sqlQuery("SHOW COLUMNS FROM " . escape_table_name($table) . " WHERE Field = ?", array($field_id));
3856 if (empty($tmp)) {
3857 return '*?*';
3860 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM " . escape_table_name($table) . " WHERE pid = ? $orderby", array($pid));
3861 if (isset($pdrow)) {
3862 $currvalue = $pdrow['field_value'];
3864 } elseif ($source == 'E') {
3865 $sarow = false;
3866 if ($encounter) {
3867 // Get value from shared_attributes of the current encounter.
3868 $sarow = sqlQuery(
3869 "SELECT field_value FROM shared_attributes WHERE " .
3870 "pid = ? AND encounter = ? AND field_id = ?",
3871 array($pid, $encounter, $field_id)
3873 if (!empty($sarow)) {
3874 $currvalue = $sarow['field_value'];
3876 } elseif ($formid) {
3877 // Get from shared_attributes of the encounter that this form is linked to.
3878 // Note the importance of having an index on forms.form_id.
3879 $sarow = sqlQuery(
3880 "SELECT sa.field_value " .
3881 "FROM forms AS f, shared_attributes AS sa WHERE " .
3882 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3883 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3884 array($formid, $formname, $field_id)
3886 if (!empty($sarow)) {
3887 $currvalue = $sarow['field_value'];
3889 } else {
3890 // New form and encounter not available, this should not happen.
3892 if (empty($sarow) && !$formid) {
3893 // New form, see if there is a custom default from a plugin.
3894 if (function_exists($deffname)) {
3895 $currvalue = call_user_func($deffname);
3898 } elseif ($source == 'V') {
3899 if ($encounter) {
3900 // Get value from the current encounter's form_encounter.
3901 $ferow = sqlQuery(
3902 "SELECT * FROM form_encounter WHERE " .
3903 "pid = ? AND encounter = ?",
3904 array($pid, $encounter)
3906 if (isset($ferow[$field_id])) {
3907 $currvalue = $ferow[$field_id];
3909 } elseif ($formid) {
3910 // Get value from the form_encounter that this form is linked to.
3911 $ferow = sqlQuery(
3912 "SELECT fe.* " .
3913 "FROM forms AS f, form_encounter AS fe WHERE " .
3914 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3915 "fe.pid = f.pid AND fe.encounter = f.encounter",
3916 array($formid, $formname)
3918 if (isset($ferow[$field_id])) {
3919 $currvalue = $ferow[$field_id];
3921 } else {
3922 // New form and encounter not available, this should not happen.
3924 } elseif ($formid) {
3925 // This is a normal form field.
3926 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3927 "form_id = ? AND field_id = ?", array($formid, $field_id));
3928 if (!empty($ldrow)) {
3929 $currvalue = $ldrow['field_value'];
3931 } else {
3932 // New form, see if there is a custom default from a plugin.
3933 if (function_exists($deffname)) {
3934 $currvalue = call_user_func($deffname);
3938 return $currvalue;
3941 function signer_head()
3943 return <<<EOD
3944 <link href="{$GLOBALS['web_root']}/portal/sign/css/signer_modal.css?v={$GLOBALS['v_js_includes']}" rel="stylesheet"/>
3945 <script src="{$GLOBALS['web_root']}/portal/sign/assets/signature_pad.umd.js?v={$GLOBALS['v_js_includes']}"></script>
3946 <script src="{$GLOBALS['web_root']}/portal/sign/assets/signer_api.js?v={$GLOBALS['v_js_includes']}"></script>
3947 EOD;
3950 // This returns stuff that needs to go into the <head> section of a caller using
3951 // the drawable image field type in a form.
3952 // A TRUE argument makes the widget controls smaller.
3954 function lbf_canvas_head($small = true)
3956 $s = <<<EOD
3957 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas/css/literallycanvas.css" rel="stylesheet" />
3958 <script src="{$GLOBALS['assets_static_relative']}/react/build/react-with-addons.min.js"></script>
3959 <script src="{$GLOBALS['assets_static_relative']}/react/build/react-dom.min.js"></script>
3960 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas/js/literallycanvas.min.js"></script>
3961 EOD;
3962 if ($small) {
3963 $s .= <<<EOD
3964 <style>
3965 /* Custom LiterallyCanvas styling.
3966 * This makes the widget 25% less tall and adjusts some other things accordingly.
3968 .literally {
3969 min-height:100%;min-width:300px; /* Was 400, unspecified */
3971 .literally .lc-picker .toolbar-button {
3972 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3974 .literally .color-well {
3975 font-size:8px;width:49px; /* Was 10, 60 */
3977 .literally .color-well-color-container {
3978 width:21px;height:21px; /* Was 28, 28 */
3980 .literally .lc-picker {
3981 width:50px; /* Was 61 */
3983 .literally .lc-drawing.with-gui {
3984 left:50px; /* Was 61 */
3986 .literally .lc-options {
3987 left:50px; /* Was 61 */
3989 .literally .color-picker-popup {
3990 left:49px;bottom:0px; /* Was 60, 31 */
3992 </style>
3993 EOD;
3996 return $s;
4000 * Test if modifier($test) is in array of options for data type.
4002 * @param json array $options ["G","P","T"], ["G"] or could be legacy string with form "GPT", "G", "012"
4003 * @param string $test
4004 * @return boolean
4006 function isOption($options, $test)
4008 if (empty($options) || !isset($test) || $options == "null") {
4009 return false; // why bother?
4011 if (strpos($options, ',') === false) { // not json array of modifiers.
4012 // could be string of char's or single element of json ["RO"] or "TP" or "P" e.t.c.
4013 json_decode($options, true); // test if options json. json_last_error() will return JSON_ERROR_SYNTAX if not.
4014 // if of form ["RO"] (single modifier) means not legacy so continue on.
4015 if (is_string($options) && (json_last_error() !== JSON_ERROR_NONE)) { // nope, it's string.
4016 $t = str_split(trim($options)); // very good chance it's legacy modifier string.
4017 $options = json_encode($t); // make it json array to convert from legacy to new modifier json schema.
4021 $options = json_decode($options, true); // all should now be json
4023 return !is_null($options) && in_array($test, $options, true) ? true : false; // finally the truth!