2 // Copyright (C) 2007-2017 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>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 // Documentation for layout_options.edit_options:
21 // A = Age as years or "xx month(s)"
22 // B = Gestational age as "xx week(s) y day(s)"
23 // C = Capitalize first letter of each word (text fields)
24 // D = Check for duplicates in New Patient form
25 // G = Graphable (for numeric fields in forms supporting historical data)
26 // H = Read-only field copied from static history (this is obsolete)
27 // L = Lab Order ("ord_lab") types only (address book)
28 // N = Show in New Patient form
29 // O = Procedure Order ("ord_*") types only (address book)
30 // P = Default to previous value when current value is not yet set
31 // R = Distributor types only (address book)
32 // T = Use description as default Text
33 // U = Capitalize all letters (text fields)
34 // V = Vendor types only (address book)
35 // 0 = Read Only - the input element's "disabled" property is set
36 // 1 = Write Once (not editable when not empty) (text fields)
37 // 2 = Show descriptions instead of codes for billing code input
39 require_once("user.inc");
40 require_once("patient.inc");
41 require_once("lists.inc");
42 require_once(dirname(dirname(__FILE__
)) . "/custom/code_types.inc.php");
44 use OpenEMR\Services\FacilityService
;
46 $facilityService = new FacilityService();
50 function get_pharmacies()
52 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
53 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
54 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
55 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
57 "ORDER BY name, area_code, prefix, number");
60 function optionalAge($frow, $date, &$asof, $description = '')
67 $date = substr($date, 0, 10);
68 if (isOption($frow['edit_options'], 'A') !== false) {
70 } else if (isOption($frow['edit_options'], 'B') !== false) {
76 if (isOption($frow['form_id'], 'LBF') === 0) {
78 "SELECT date FROM form_encounter WHERE " .
79 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
80 array($GLOBALS['pid'], $GLOBALS['encounter'])
82 if (!empty($tmp['date'])) {
83 $asof = substr($tmp['date'], 0, 10);
86 if ($description === '') {
87 $prefix = ($format ?
xl('Gest age') : xl('Age')) . ' ';
89 $prefix = $description . ' ';
91 return $prefix . oeFormatAge($date, $asof, $format);
94 // Function to generate a drop-list.
96 function generate_select_list(
105 $custom_attributes = null,
111 $tag_name_esc = attr($tag_name);
114 $tag_name_esc = $tag_name_esc . "[]";
117 $s .= "<select name='$tag_name_esc'";
120 $s .= " multiple='multiple'";
123 $tag_id_esc = attr($tag_name);
126 $tag_id_esc = attr($tag_id);
129 $s .= " id='$tag_id_esc'";
131 if (!empty($class)) {
132 $class_esc = attr($class);
133 $s .= " class='form-control $class_esc'";
135 $s .= " class='form-control'";
139 $s .= " onchange='$onchange'";
142 if ($custom_attributes != null && is_array($custom_attributes)) {
143 foreach ($custom_attributes as $attr => $val) {
144 if (isset($custom_attributes [$attr])) {
145 $s .= " " . attr($attr) . "='" . attr($val) . "'";
150 $selectTitle = attr($title);
151 $s .= " title='$selectTitle'>";
152 $selectEmptyName = xlt($empty_name);
154 $s .= "<option value=''>" . $selectEmptyName . "</option>";
157 // List order depends on language translation options.
158 // (Note we do not need to worry about the list order in the algorithm
159 // after the below code block since that is where searches for exceptions
160 // are done which include inactive items or items from a backup
161 // list; note these will always be shown at the bottom of the list no matter the
163 $lang_id = empty($_SESSION['language_choice']) ?
'1' : $_SESSION['language_choice'];
165 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) ||
!$GLOBALS['translate_lists']) {
167 if ($GLOBALS['gb_how_sort_list'] == '0') {
169 $order_by_sql = "seq, title";
170 } else { //$GLOBALS['gb_how_sort_list'] == '1'
172 $order_by_sql = "title, seq";
175 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
178 if ($GLOBALS['gb_how_sort_list'] == '0') {
180 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
181 } else { //$GLOBALS['gb_how_sort_list'] == '1'
183 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
186 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
187 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
188 "FROM list_options AS lo " .
189 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
190 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
192 "WHERE lo.list_id = ? AND lo.activity=1 " .
193 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
196 $got_selected = false;
198 while ($lrow = sqlFetchArray($lres)) {
199 $selectedValues = explode("|", $currvalue);
201 $optionValue = attr($lrow ['option_id']);
202 $s .= "<option value='$optionValue'";
204 if ((strlen($currvalue) == 0 && $lrow ['is_default']) ||
(strlen($currvalue) > 0 && in_array($lrow ['option_id'], $selectedValues))) {
206 $got_selected = true;
209 // Already has been translated above (if applicable), so do not need to use
210 // the xl_list_label() function here
211 $optionLabel = text($lrow ['title']);
212 $s .= ">$optionLabel</option>\n";
216 To show the inactive item in the list if the value is saved to database
218 if (!$got_selected && strlen($currvalue) > 0) {
219 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
220 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
221 $lrow_inactive = sqlFetchArray($lres_inactive);
222 if ($lrow_inactive['option_id']) {
223 $optionValue = htmlspecialchars($lrow_inactive['option_id'], ENT_QUOTES
);
224 $s .= "<option value='$optionValue' selected>" . htmlspecialchars(xl_list_label($lrow_inactive['title']), ENT_NOQUOTES
) . "</option>\n";
225 $got_selected = true;
229 if (!$got_selected && strlen($currvalue) > 0 && !$multiple) {
230 $list_id = $backup_list;
231 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
233 if ($lrow > 0 && !empty($backup_list)) {
234 $selected = text(xl_list_label($lrow ['title']));
235 $s .= "<option value='$currescaped' selected> $selected </option>";
238 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
240 $fontTitle = xlt('Please choose a valid selection from the list.');
241 $fontText = xlt('Fix this');
242 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
244 } else if (!$got_selected && strlen($currvalue) > 0 && $multiple) {
245 //if not found in main list, display all selected values that exist in backup list
246 $list_id = $backup_list;
248 $got_selected_backup = false;
249 if (!empty($backup_list)) {
250 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
251 while ($lrow_backup = sqlFetchArray($lres_backup)) {
252 $selectedValues = explode("|", $currvalue);
254 $optionValue = attr($lrow_backup['option_id']);
256 if (in_array($lrow_backup ['option_id'], $selectedValues)) {
257 $s .= "<option value='$optionValue'";
259 $optionLabel = text(xl_list_label($lrow_backup ['title']));
260 $s .= ">$optionLabel</option>\n";
261 $got_selected_backup = true;
266 if (!$got_selected_backup) {
267 $selectedValues = explode("|", $currvalue);
268 foreach ($selectedValues as $selectedValue) {
269 $s .= "<option value='" . attr($selectedValue) . "'";
271 $s .= ">* " . text($selectedValue) . " *</option>\n";
275 $fontTitle = xlt('Please choose a valid selection from the list.');
276 $fontText = xlt('Fix this');
277 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
286 // Parsing for data type 31, static text.
287 function parse_static_text($frow)
289 $tmp = $frow['description'];
290 // Translate if it does not look like HTML.
291 if (substr($tmp, 0, 1) != '<') {
292 $tmp = nl2br(xl_layout_label($tmp));
295 if ($frow['source'] == 'D' ||
$frow['source'] == 'H') {
296 // Source is demographics or history. This case supports value substitution.
297 while (preg_match('/^(.*?)\{(\w+)\}(.*)$/', $tmp, $matches)) {
300 $tmprow['field_id'] = $matches[2];
301 $s .= lbf_current_value($tmprow, 0, 0);
309 // $frow is a row from the layout_options table.
310 // $currvalue is the current value, if any, of the associated item.
312 function generate_form_field($frow, $currvalue)
314 global $rootdir, $date_init, $ISSUE_TYPES, $code_types;
316 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
318 $data_type = $frow['data_type'];
319 $field_id = $frow['field_id'];
320 $list_id = $frow['list_id'];
321 $backup_list = $frow['list_backup_id'];
323 // escaped variables to use in html
324 $field_id_esc= htmlspecialchars($field_id, ENT_QUOTES
);
325 $list_id_esc = htmlspecialchars($list_id, ENT_QUOTES
);
327 // Added 5-09 by BM - Translate description if applicable
328 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
330 // Support edit option T which assigns the (possibly very long) description as
331 // the default value.
332 if (isOption($frow['edit_options'], 'T') !== false) {
333 if (strlen($currescaped) == 0) {
334 $currescaped = $description;
337 // Description used in this way is not suitable as a title.
341 // added 5-2009 by BM to allow modification of the 'empty' text title field.
342 // Can pass $frow['empty_title'] with this variable, otherwise
343 // will default to 'Unassigned'.
344 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
345 // if make $frow['empty_title'] equal to 'SKIP'
347 if (isset($frow['empty_title'])) {
348 if ($frow['empty_title'] == "SKIP") {
349 //do not display an 'empty' choice
351 $empty_title = "Unassigned";
353 $empty_title = $frow['empty_title'];
356 $empty_title = "Unassigned";
359 $disabled = isOption($frow['edit_options'], '0') === false ?
'' : 'disabled';
362 strpos($frow['form_id'], 'LBF') === 0 ||
363 strpos($frow['form_id'], 'LBT') === 0 ||
364 $frow['form_id'] == 'DEM' ||
365 $frow['form_id'] == 'HIS'
366 ) ?
"checkSkipConditions();" : "";
367 $lbfonchange = $lbfchange ?
"onchange='$lbfchange'" : "";
369 // generic single-selection list or Race and Ethnicity.
370 // These data types support backup lists.
371 if ($data_type == 1 ||
$data_type == 33) {
372 echo generate_select_list(
377 ($showEmpty ?
$empty_title : ''),
381 ($disabled ?
array('disabled' => 'disabled') : null),
385 } // simple text field
386 else if ($data_type == 2) {
387 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES
);
388 $maxlength = $frow['max_length'];
389 $string_maxlength = "";
390 // if max_length is set to zero, then do not set a maxlength
392 $string_maxlength = "maxlength='".attr($maxlength)."'";
395 echo "<input type='text'" .
396 " class='form-control'" .
397 " name='form_$field_id_esc'" .
398 " id='form_$field_id_esc'" .
399 " size='$fldlength'" .
400 " $string_maxlength" .
401 " title='$description'" .
402 " value='$currescaped'";
404 if (isOption($frow['edit_options'], 'C') !== false) {
405 $tmp .= "capitalizeMe(this);";
406 } else if (isOption($frow['edit_options'], 'U') !== false) {
407 $tmp .= "this.value = this.value.toUpperCase();";
411 echo " onchange='$tmp'";
414 $tmp = htmlspecialchars($GLOBALS['gbl_mask_patient_id'], ENT_QUOTES
);
415 // If mask is for use at save time, treat as no mask.
416 if (strpos($tmp, '^') !== false) {
419 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
420 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
421 echo " onblur='maskblur(this,\"$tmp\")'";
424 if (isOption($frow['edit_options'], '1') !== false && strlen($currescaped) > 0) {
433 } // long or multi-line text field
434 else if ($data_type == 3) {
435 $textCols = htmlspecialchars($frow['fld_length'], ENT_QUOTES
);
436 $textRows = htmlspecialchars($frow['fld_rows'], ENT_QUOTES
);
438 " name='form_$field_id_esc'" .
439 " class='form-control'" .
440 " id='form_$field_id_esc'" .
441 " title='$description'" .
442 " cols='$textCols'" .
443 " rows='$textRows' $lbfonchange $disabled" .
444 ">" . $currescaped . "</textarea>";
446 else if ($data_type == 4) {
447 $age_asof_date = ''; // optionalAge() sets this
448 $age_format = isOption($frow['edit_options'], 'A') === false ?
3 : 0;
449 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
451 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
454 $onchange_string = '';
455 if (!$disabled && $agestr) {
456 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') " .
457 "updateAgeString('$field_id','$age_asof_date', $age_format, '$description')\"";
459 if ($data_type == 4) {
460 $modtmp = isOption($frow['edit_options'], 'F') === false ?
0 : 1;
462 echo "<input type='text' size='10' class='datepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
463 " value='" . substr($currescaped, 0, 10) . "'";
465 echo "<input type='text' size='20' class='datetimepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
466 " value='" . substr($currescaped, 0, 20) . "'";
470 echo " title='$description'";
473 echo " $onchange_string $lbfonchange $disabled />";
475 // Optional display of age or gestational age.
477 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
479 } // provider list, local providers only
480 else if ($data_type == 10) {
481 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
482 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
483 "AND authorized = 1 " .
484 "ORDER BY lname, fname");
485 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
486 echo "<option value=''>" . xlt($empty_title) . "</option>";
487 $got_selected = false;
488 while ($urow = sqlFetchArray($ures)) {
489 $uname = text($urow['fname'] . ' ' . $urow['lname']);
490 $optionId = attr($urow['id']);
491 echo "<option value='$optionId'";
492 if ($urow['id'] == $currvalue) {
494 $got_selected = true;
497 echo ">$uname</option>";
500 if (!$got_selected && $currvalue) {
501 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
503 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
507 } // provider list, including address book entries with an NPI number
508 else if ($data_type == 11) {
509 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
510 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
511 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
512 "ORDER BY lname, fname");
513 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
514 echo " $lbfonchange $disabled>";
515 echo "<option value=''>" . xlt('Unassigned') . "</option>";
516 $got_selected = false;
517 while ($urow = sqlFetchArray($ures)) {
518 $uname = text($urow['fname'] . ' ' . $urow['lname']);
519 $optionId = attr($urow['id']);
520 echo "<option value='$optionId'";
521 if ($urow['id'] == $currvalue) {
523 $got_selected = true;
526 echo ">$uname</option>";
529 if (!$got_selected && $currvalue) {
530 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
532 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
537 else if ($data_type == 12) {
538 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
539 echo " $lbfonchange $disabled>";
540 echo "<option value='0'></option>";
541 $pres = get_pharmacies();
542 $got_selected = false;
543 while ($prow = sqlFetchArray($pres)) {
545 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
546 $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
547 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
548 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
549 echo "<option value='$optionValue'";
550 if ($currvalue == $key) {
552 $got_selected = true;
555 echo ">$optionLabel</option>";
558 if (!$got_selected && $currvalue) {
559 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
561 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
566 else if ($data_type == 13) {
567 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
568 echo " $lbfonchange $disabled>";
569 echo "<option value=''> </option>";
570 $squads = acl_get_squads();
572 foreach ($squads as $key => $value) {
573 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
574 $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES
);
575 echo "<option value='$optionValue'";
576 if ($currvalue == $key) {
580 echo ">$optionLabel</option>\n";
585 } // Address book, preferring organization name if it exists and is not in
586 // parentheses, and excluding local users who are not providers.
587 // Supports "referred to" practitioners and facilities.
588 // Alternatively the letter L in edit_options means that abook_type
589 // must be "ord_lab", indicating types used with the procedure
590 // lab ordering system.
591 // Alternatively the letter O in edit_options means that abook_type
592 // must begin with "ord_", indicating types used with the procedure
594 // Alternatively the letter V in edit_options means that abook_type
595 // must be "vendor", indicating the Vendor type.
596 // Alternatively the letter R in edit_options means that abook_type
597 // must be "dist", indicating the Distributor type.
598 else if ($data_type == 14) {
599 if (isOption($frow['edit_options'], 'L') !== false) {
600 $tmp = "abook_type = 'ord_lab'";
601 } else if (isOption($frow['edit_options'], 'O') !== false) {
602 $tmp = "abook_type LIKE 'ord\\_%'";
603 } else if (isOption($frow['edit_options'], 'V') !== false) {
604 $tmp = "abook_type LIKE 'vendor%'";
605 } else if (isOption($frow['edit_options'], 'R') !== false) {
606 $tmp = "abook_type LIKE 'dist'";
608 $tmp = "( username = '' OR authorized = 1 )";
611 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
612 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
614 "ORDER BY organization, lname, fname");
615 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
616 echo " $lbfonchange $disabled>";
617 echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
618 while ($urow = sqlFetchArray($ures)) {
619 $uname = $urow['organization'];
620 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
621 $uname = $urow['lname'];
622 if ($urow['fname']) {
623 $uname .= ", " . $urow['fname'];
627 $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES
);
628 $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES
);
629 echo "<option value='$optionValue'";
630 // Failure to translate Local and External is not an error here;
631 // they are only used as internal flags and must not be translated!
632 $title = $urow['username'] ?
'Local' : 'External';
633 $optionTitle = htmlspecialchars($title, ENT_QUOTES
);
634 echo " title='$optionTitle'";
635 if ($urow['id'] == $currvalue) {
639 echo ">$optionLabel</option>";
643 } // A billing code. If description matches an existing code type then that type is used.
644 else if ($data_type == 15) {
646 if (!empty($frow['description']) && isset($code_types[$frow['description']])) {
647 $codetype = $frow['description'];
649 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES
);
650 $maxlength = $frow['max_length'];
651 $string_maxlength = "";
652 // if max_length is set to zero, then do not set a maxlength
654 $string_maxlength = "maxlength='".attr($maxlength)."'";
658 if (isOption($frow['edit_options'], '2') !== false && substr($frow['form_id'], 0, 3) == 'LBF') {
659 // Option "2" generates a hidden input for the codes, and a matching visible field
660 // displaying their descriptions. First step is computing the description string.
661 $currdescstring = '';
662 if (!empty($currvalue)) {
663 $relcodes = explode(';', $currvalue);
664 foreach ($relcodes as $codestring) {
665 if ($codestring === '') {
669 $code_text = lookup_code_descriptions($codestring);
670 if ($currdescstring !== '') {
671 $currdescstring .= '; ';
674 if (!empty($code_text)) {
675 $currdescstring .= $code_text;
677 $currdescstring .= $codestring;
682 $currdescstring = attr($currdescstring);
684 echo "<input type='text'" .
685 " name='form_$field_id_esc'" .
686 " id='form_related_code'" .
687 " size='$fldlength'" .
688 " value='$currescaped'" .
689 " style='display:none'" .
690 " $lbfonchange readonly $disabled />";
691 // Extra readonly input field for optional display of code description(s).
692 echo "<input type='text'" .
693 " name='form_$field_id_esc" . "__desc'" .
694 " size='$fldlength'" .
695 " title='$description'" .
696 " value='$currdescstring'";
698 echo " onclick='sel_related(this,\"$codetype\")'";
701 echo "class='form-control'";
702 echo " readonly $disabled />";
704 echo "<input type='text'" .
705 " name='form_$field_id_esc'" .
706 " id='form_related_code'" .
707 " size='$fldlength'" .
708 " $string_maxlength" .
709 " title='$description'" .
710 " value='$currescaped'";
712 echo " onclick='sel_related(this,\"$codetype\")'";
715 echo "class='form-control'";
716 echo " $lbfonchange readonly $disabled />";
718 } // insurance company list
719 else if ($data_type == 16) {
720 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
721 echo "<option value='0'></option>";
722 $insprovs = getInsuranceProviders();
723 $got_selected = false;
724 foreach ($insprovs as $key => $ipname) {
725 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
726 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES
);
727 echo "<option value='$optionValue'";
728 if ($currvalue == $key) {
730 $got_selected = true;
733 echo ">$optionLabel</option>";
736 if (!$got_selected && $currvalue) {
737 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
739 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
744 else if ($data_type == 17) {
745 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
746 echo "<option value='0'></option>";
747 $got_selected = false;
748 foreach ($ISSUE_TYPES as $key => $value) {
749 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
750 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES
);
751 echo "<option value='$optionValue'";
752 if ($currvalue == $key) {
754 $got_selected = true;
757 echo ">$optionLabel</option>";
760 if (!$got_selected && strlen($currvalue) > 0) {
761 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
763 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
767 } // Visit categories.
768 else if ($data_type == 18) {
769 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
770 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
771 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'" .
772 " $lbfonchange $disabled>";
773 echo "<option value=''>" . xlt($empty_title) . "</option>";
774 $got_selected = false;
775 while ($crow = sqlFetchArray($cres)) {
776 $catid = $crow['pc_catid'];
777 if (($catid < 9 && $catid != 5) ||
$catid == 11) {
781 echo "<option value='" . attr($catid) . "'";
782 if ($catid == $currvalue) {
784 $got_selected = true;
787 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
790 if (!$got_selected && $currvalue) {
791 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
793 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
797 } // a set of labeled checkboxes
798 else if ($data_type == 21) {
799 // If no list then it's a single checkbox and its value is "Yes" or empty.
801 echo "<input type='checkbox' name='form_{$field_id_esc}' " .
802 "id='form_{$field_id_esc}' value='Yes' $lbfonchange";
806 echo " $disabled />";
808 // In this special case, fld_length is the number of columns generated.
809 $cols = max(1, $frow['fld_length']);
810 $avalue = explode('|', $currvalue);
811 $lres = sqlStatement("SELECT * FROM list_options " .
812 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
813 echo "<table cellpadding='0' cellspacing='0' width='100%' title='".attr($description)."'>";
814 $tdpct = (int) (100 / $cols);
815 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
816 $option_id = $lrow['option_id'];
817 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
818 // if ($count) echo "<br />";
819 if ($count %
$cols == 0) {
825 echo "<td width='" . attr($tdpct) . "%' nowrap>";
826 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
827 "id='form_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
828 if (in_array($option_id, $avalue)) {
831 // Added 5-09 by BM - Translate label if applicable
832 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
837 if ($count > $cols) {
838 // Add some space after multiple rows of checkboxes.
839 $cols = htmlspecialchars($cols, ENT_QUOTES
);
840 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
845 } // a set of labeled text input fields
846 else if ($data_type == 22) {
847 $tmp = explode('|', $currvalue);
849 foreach ($tmp as $value) {
850 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
851 $avalue[$matches[1]] = $matches[2];
855 $lres = sqlStatement("SELECT * FROM list_options " .
856 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
857 echo "<table cellpadding='0' cellspacing='0'>";
858 while ($lrow = sqlFetchArray($lres)) {
859 $option_id = $lrow['option_id'];
860 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
861 $maxlength = $frow['max_length'];
862 $string_maxlength = "";
863 // if max_length is set to zero, then do not set a maxlength
865 $string_maxlength = "maxlength='".attr($maxlength)."'";
868 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
870 // Added 5-09 by BM - Translate label if applicable
871 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
872 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
873 $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES
);
874 echo "<td><input type='text'" .
875 " name='form_{$field_id_esc}[$option_id_esc]'" .
876 " id='form_{$field_id_esc}[$option_id_esc]'" .
877 " size='$fldlength'" .
878 " class='form-control'" .
879 " $string_maxlength" .
880 " value='$optionValue'";
881 echo " $lbfonchange $disabled /></td></tr>";
885 } // a set of exam results; 3 radio buttons and a text field:
886 else if ($data_type == 23) {
887 $tmp = explode('|', $currvalue);
889 foreach ($tmp as $value) {
890 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
891 $avalue[$matches[1]] = $matches[2];
895 $maxlength = $frow['max_length'];
896 $string_maxlength = "";
897 // if max_length is set to zero, then do not set a maxlength
899 $string_maxlength = "maxlength='".attr($maxlength)."'";
902 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
903 $lres = sqlStatement("SELECT * FROM list_options " .
904 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
905 echo "<table cellpadding='0' cellspacing='0'>";
906 echo "<tr><td> </td><td class='bold'>" .
907 htmlspecialchars(xl('N/A'), ENT_NOQUOTES
) .
908 " </td><td class='bold'>" .
909 htmlspecialchars(xl('Nor'), ENT_NOQUOTES
) . " </td>" .
910 "<td class='bold'>" .
911 htmlspecialchars(xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
912 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
913 while ($lrow = sqlFetchArray($lres)) {
914 $option_id = $lrow['option_id'];
915 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
916 $restype = substr($avalue[$option_id], 0, 1);
917 $resnote = substr($avalue[$option_id], 2);
919 // Added 5-09 by BM - Translate label if applicable
920 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
922 for ($i = 0; $i < 3; ++
$i) {
923 $inputValue = htmlspecialchars($i, ENT_QUOTES
);
924 echo "<td><input type='radio'" .
925 " name='radio_{$field_id_esc}[$option_id_esc]'" .
926 " id='radio_{$field_id_esc}[$option_id_esc]'" .
927 " value='$inputValue' $lbfonchange";
928 if ($restype === "$i") {
932 echo " $disabled /></td>";
935 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
936 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
937 echo "<td><input type='text'" .
938 " name='form_{$field_id_esc}[$option_id_esc]'" .
939 " id='form_{$field_id_esc}[$option_id_esc]'" .
940 " size='$fldlength'" .
941 " $string_maxlength" .
942 " value='$resnote' $disabled /></td>";
947 } // the list of active allergies for the current patient
948 // this is read-only!
949 else if ($data_type == 24) {
950 $query = "SELECT title, comments FROM lists WHERE " .
951 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
953 // echo "<!-- $query -->\n"; // debugging
954 $lres = sqlStatement($query, array($GLOBALS['pid']));
956 while ($lrow = sqlFetchArray($lres)) {
961 echo htmlspecialchars($lrow['title'], ENT_NOQUOTES
);
962 if ($lrow['comments']) {
963 echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES
) . ')';
966 } // a set of labeled checkboxes, each with a text field:
967 else if ($data_type == 25) {
968 $tmp = explode('|', $currvalue);
970 foreach ($tmp as $value) {
971 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
972 $avalue[$matches[1]] = $matches[2];
976 $maxlength = $frow['max_length'];
977 $string_maxlength = "";
978 // if max_length is set to zero, then do not set a maxlength
980 $string_maxlength = "maxlength='".attr($maxlength)."'";
983 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
984 $lres = sqlStatement("SELECT * FROM list_options " .
985 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
986 echo "<table cellpadding='0' cellspacing='0'>";
987 while ($lrow = sqlFetchArray($lres)) {
988 $option_id = $lrow['option_id'];
989 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
990 $restype = substr($avalue[$option_id], 0, 1);
991 $resnote = substr($avalue[$option_id], 2);
993 // Added 5-09 by BM - Translate label if applicable
994 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
996 $option_id = htmlspecialchars($option_id, ENT_QUOTES
);
997 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
998 " id='check_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
1003 echo " $disabled /> </td>";
1004 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1005 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1006 echo "<td><input type='text'" .
1007 " name='form_{$field_id_esc}[$option_id_esc]'" .
1008 " id='form_{$field_id_esc}[$option_id_esc]'" .
1009 " size='$fldlength'" .
1010 " class='form-control' " .
1011 " $string_maxlength" .
1012 " value='$resnote' $disabled /></td>";
1017 } // single-selection list with ability to add to it
1018 else if ($data_type == 26) {
1019 echo generate_select_list(
1024 ($showEmpty ?
$empty_title : ''),
1025 'addtolistclass_'.$list_id,
1028 ($disabled ?
array('disabled' => 'disabled') : null),
1032 // show the add button if user has access to correct list
1033 $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES
);
1034 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
1035 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
1036 if (aco_exist('lists', $list_id)) {
1037 // a specific aco exist for this list, so ensure access
1038 if (acl_check('lists', $list_id)) {
1039 echo $outputAddButton;
1042 // no specific aco exist for this list, so check for access to 'default' list
1043 if (acl_check('lists', 'default')) {
1044 echo $outputAddButton;
1047 } // a set of labeled radio buttons
1048 else if ($data_type == 27) {
1049 // In this special case, fld_length is the number of columns generated.
1050 $cols = max(1, $frow['fld_length']);
1051 $lres = sqlStatement("SELECT * FROM list_options " .
1052 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1053 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1054 $tdpct = (int) (100 / $cols);
1055 $got_selected = false;
1056 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1057 $option_id = $lrow['option_id'];
1058 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
1059 if ($count %
$cols == 0) {
1067 echo "<td width='" . attr($tdpct) . "%'>";
1068 echo "<input type='radio' name='form_{$field_id_esc}' class='form-control' id='form_{$field_id_esc}[$option_id_esc]'" .
1069 " value='$option_id_esc' $lbfonchange";
1070 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1071 (strlen($currvalue) > 0 && $option_id == $currvalue)) {
1073 $got_selected = true;
1076 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
1082 if ($count > $cols) {
1083 // Add some space after multiple rows of radio buttons.
1084 $cols = htmlspecialchars($cols, ENT_QUOTES
);
1085 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1090 if (!$got_selected && strlen($currvalue) > 0) {
1091 $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES
);
1092 $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES
);
1093 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
1095 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1096 // VicarePlus :: A selection list box for smoking status:
1097 else if ($data_type == 28 ||
$data_type == 32) {
1098 $tmp = explode('|', $currvalue);
1099 switch (count($tmp)) {
1118 $resdate = $restype = "";
1121 $restype = $resdate = $resnote = "";
1125 $maxlength = $frow['max_length'];
1126 $string_maxlength = "";
1127 // if max_length is set to zero, then do not set a maxlength
1129 $string_maxlength = "maxlength='".attr($maxlength)."'";
1132 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1134 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1135 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1136 $resdate = htmlspecialchars($resdate, ENT_QUOTES
);
1137 echo "<table cellpadding='0' cellspacing='0'>";
1139 if ($data_type == 28) {
1141 echo "<td><input type='text'" .
1142 " name='form_$field_id_esc'" .
1143 " id='form_$field_id_esc'" .
1144 " size='$fldlength'" .
1145 " $string_maxlength" .
1146 " value='$resnote' $disabled /> </td>";
1147 echo "<td class='bold'> ".
1148 " ".
1149 htmlspecialchars(xl('Status'), ENT_NOQUOTES
).": </td>";
1150 } else if ($data_type == 32) {
1152 echo "<tr><td><input type='text'" .
1153 " name='form_text_$field_id_esc'" .
1154 " id='form_text_$field_id_esc'" .
1155 " size='$fldlength'" .
1156 " class='form-control'" .
1157 " $string_maxlength" .
1158 " value='$resnote' $disabled /> </td></tr>";
1160 //Selection list for smoking status
1161 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1162 echo generate_select_list(
1167 ($showEmpty ?
$empty_title : ''),
1171 ($disabled ?
array('disabled' => 'disabled') : null)
1174 echo "<td class='bold'> " . xlt('Status') . ": </td>";
1178 echo "<td class='text' ><input type='radio'" .
1179 " name='radio_{$field_id_esc}'" .
1180 " id='radio_{$field_id_esc}[current]'" .
1181 " class='form-control'" .
1182 " value='current" . $field_id_esc . "' $lbfonchange";
1183 if ($restype == "current" . $field_id) {
1187 if ($data_type == 32) {
1188 echo " onClick='smoking_statusClicked(this)'";
1191 echo " />" . xlt('Current') . " </td>";
1193 echo "<td class='text'><input type='radio'" .
1194 " name='radio_{$field_id_esc}'" .
1195 " id='radio_{$field_id_esc}[quit]'" .
1196 " class='form-control'" .
1197 " value='quit".$field_id_esc."' $lbfonchange";
1198 if ($restype == "quit" . $field_id) {
1202 if ($data_type == 32) {
1203 echo " onClick='smoking_statusClicked(this)'";
1206 echo " $disabled />" . xlt('Quit') . " </td>";
1208 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1209 " value='$resdate'" .
1210 " title='$description'" .
1214 echo "<td class='text'><input type='radio'" .
1215 " name='radio_{$field_id_esc}'" .
1216 " class='form-control'" .
1217 " id='radio_{$field_id_esc}[never]'" .
1218 " value='never" . $field_id_esc . "' $lbfonchange";
1219 if ($restype == "never" . $field_id) {
1223 if ($data_type == 32) {
1224 echo " onClick='smoking_statusClicked(this)'";
1227 echo " />" . xlt('Never') . " </td>";
1229 echo "<td class='text'><input type='radio'" .
1230 " class='form-control' " .
1231 " name='radio_{$field_id}'" .
1232 " id='radio_{$field_id}[not_applicable]'" .
1233 " value='not_applicable" . $field_id . "' $lbfonchange";
1234 if ($restype == "not_applicable" . $field_id) {
1238 if ($data_type == 32) {
1239 echo " onClick='smoking_statusClicked(this)'";
1242 echo " $disabled />" . xlt('N/A') . " </td>";
1244 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1245 echo "<td class='text' ><div id='smoke_code'></div></td>";
1248 } // static text. read-only, of course.
1249 else if ($data_type == 31) {
1250 echo parse_static_text($frow);
1251 } //$data_type == 33
1252 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1255 else if ($data_type == 34) {
1256 $arr = explode("|*|*|*|", $currvalue);
1257 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;'>";
1258 echo "<div id='form_{$field_id}_div' class='text-area' style='min-width:100pt'>" . $arr[0] . "</div>";
1259 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>";
1261 } //facilities drop-down list
1262 else if ($data_type == 35) {
1263 if (empty($currvalue)) {
1268 $selected = $currvalue,
1269 $name = "form_$field_id_esc",
1270 $allow_unspecified = true,
1271 $allow_allfacilities = false,
1276 // supports backup list
1277 else if ($data_type == 36) {
1278 echo generate_select_list(
1283 $showEmpty ?
$empty_title : '',
1291 } // Canvas and related elements for browser-side image drawing.
1292 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1293 else if ($data_type == 40) {
1294 // Unlike other field types, width and height are in pixels.
1295 $canWidth = intval($frow['fld_length']);
1296 $canHeight = intval($frow['fld_rows']);
1297 if (empty($currvalue)) {
1298 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1299 // If defined this is the filename of the default starting image.
1300 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1304 $mywidth = 50 +
($canWidth > 250 ?
$canWidth : 250);
1305 $myheight = 31 +
($canHeight > 261 ?
$canHeight : 261);
1306 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1307 // Hidden form field exists to send updated data to the server at submit time.
1308 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1309 // Hidden image exists to support initialization of the canvas.
1310 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1311 // $date_init is a misnomer but it's the place for browser-side setup logic.
1312 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1316 function generate_print_field($frow, $currvalue)
1318 global $rootdir, $date_init, $ISSUE_TYPES;
1320 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
1322 $data_type = $frow['data_type'];
1323 $field_id = $frow['field_id'];
1324 $list_id = $frow['list_id'];
1325 $fld_length = $frow['fld_length'];
1326 $backup_list = $frow['list_backup_id'];
1328 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
1330 // Can pass $frow['empty_title'] with this variable, otherwise
1331 // will default to 'Unassigned'.
1332 // If it is 'SKIP' then an empty text title is completely skipped.
1334 if (isset($frow['empty_title'])) {
1335 if ($frow['empty_title'] == "SKIP") {
1336 //do not display an 'empty' choice
1338 $empty_title = "Unassigned";
1340 $empty_title = $frow['empty_title'];
1343 $empty_title = "Unassigned";
1346 // generic single-selection list
1347 // Supports backup lists.
1348 if (false && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
1349 if (empty($fld_length)) {
1350 if ($list_id == 'titles') {
1359 $lrow = sqlQuery("SELECT title FROM list_options " .
1360 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1361 $tmp = xl_list_label($lrow['title']);
1362 if ($lrow == 0 && !empty($backup_list)) {
1363 // since primary list did not map, try to map to backup list
1364 $lrow = sqlQuery("SELECT title FROM list_options " .
1365 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1366 $tmp = xl_list_label($lrow['title']);
1370 $tmp = "($currvalue)";
1374 /*****************************************************************
1375 echo "<input type='text'" .
1376 " size='$fld_length'" .
1380 *****************************************************************/
1384 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1388 } // simple text field
1389 else if ($data_type == 2 ||
$data_type == 15) {
1390 /*****************************************************************
1391 echo "<input type='text'" .
1392 " size='$fld_length'" .
1393 " value='$currescaped'" .
1396 *****************************************************************/
1397 if ($currescaped === '') {
1398 $currescaped = ' ';
1402 } // long or multi-line text field
1403 else if ($data_type == 3) {
1404 $fldlength = htmlspecialchars($fld_length, ENT_QUOTES
);
1405 $maxlength = htmlspecialchars($frow['fld_rows'], ENT_QUOTES
);
1407 " class='form-control' " .
1408 " cols='$fldlength'" .
1409 " rows='$maxlength'>" .
1410 $currescaped . "</textarea>";
1412 else if ($data_type == 4) {
1413 $age_asof_date = '';
1414 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
1415 if ($currvalue === '') {
1418 echo text(oeFormatShortDate($currvalue));
1420 echo " (" . text($agestr) . ")";
1424 else if ($data_type == 10 ||
$data_type == 11) {
1427 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1428 "WHERE id = ?", array($currvalue));
1429 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1431 $tmp = "($currvalue)";
1435 /*****************************************************************
1436 echo "<input type='text'" .
1437 " size='$fld_length'" .
1441 *****************************************************************/
1445 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1450 else if ($data_type == 12) {
1453 $pres = get_pharmacies();
1454 while ($prow = sqlFetchArray($pres)) {
1456 if ($currvalue == $key) {
1457 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1458 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1459 $prow['line1'] . ' / ' . $prow['city'];
1464 $tmp = "($currvalue)";
1468 /*****************************************************************
1469 echo "<input type='text'" .
1470 " size='$fld_length'" .
1474 *****************************************************************/
1478 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1483 else if ($data_type == 13) {
1486 $squads = acl_get_squads();
1488 foreach ($squads as $key => $value) {
1489 if ($currvalue == $key) {
1496 $tmp = "($currvalue)";
1500 /*****************************************************************
1501 echo "<input type='text'" .
1502 " size='$fld_length'" .
1506 *****************************************************************/
1510 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1515 else if ($data_type == 14) {
1518 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1519 "WHERE id = ?", array($currvalue));
1520 $uname = $urow['lname'];
1521 if ($urow['fname']) {
1522 $uname .= ", " . $urow['fname'];
1527 $tmp = "($currvalue)";
1531 /*****************************************************************
1532 echo "<input type='text'" .
1533 " size='$fld_length'" .
1537 *****************************************************************/
1541 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1545 } // insurance company list
1546 else if ($data_type == 16) {
1549 $insprovs = getInsuranceProviders();
1550 foreach ($insprovs as $key => $ipname) {
1551 if ($currvalue == $key) {
1557 $tmp = "($currvalue)";
1564 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1569 else if ($data_type == 17) {
1572 foreach ($ISSUE_TYPES as $key => $value) {
1573 if ($currvalue == $key) {
1579 $tmp = "($currvalue)";
1586 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1590 } // Visit categories.
1591 else if ($data_type == 18) {
1595 "SELECT pc_catid, pc_catname " .
1596 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1599 $tmp = xl_appt_category($crow['pc_catname']);
1601 $tmp = "($currvalue)";
1608 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1612 } // a single checkbox or set of labeled checkboxes
1613 else if ($data_type == 21) {
1615 echo "<input type='checkbox'";
1621 // In this special case, fld_length is the number of columns generated.
1622 $cols = max(1, $fld_length);
1623 $avalue = explode('|', $currvalue);
1624 $lres = sqlStatement("SELECT * FROM list_options " .
1625 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1626 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1627 $tdpct = (int) (100 / $cols);
1628 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1629 $option_id = $lrow['option_id'];
1630 if ($count %
$cols == 0) {
1637 echo "<td width='" . attr($tdpct) . "%'>";
1638 echo "<input type='checkbox'";
1639 if (in_array($option_id, $avalue)) {
1642 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
1647 if ($count > $cols) {
1648 // Add some space after multiple rows of checkboxes.
1649 $cols = htmlspecialchars($cols, ENT_QUOTES
);
1650 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1655 } // a set of labeled text input fields
1656 else if ($data_type == 22) {
1657 $tmp = explode('|', $currvalue);
1659 foreach ($tmp as $value) {
1660 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1661 $avalue[$matches[1]] = $matches[2];
1665 $lres = sqlStatement("SELECT * FROM list_options " .
1666 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1667 echo "<table cellpadding='0' cellspacing='0'>";
1668 while ($lrow = sqlFetchArray($lres)) {
1669 $option_id = $lrow['option_id'];
1670 $fldlength = empty($fld_length) ?
20 : $fld_length;
1671 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1672 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1673 $inputValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES
);
1674 echo "<td><input type='text'" .
1675 " class='form-control' " .
1676 " size='$fldlength'" .
1677 " value='$inputValue'" .
1683 } // a set of exam results; 3 radio buttons and a text field:
1684 else if ($data_type == 23) {
1685 $tmp = explode('|', $currvalue);
1687 foreach ($tmp as $value) {
1688 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1689 $avalue[$matches[1]] = $matches[2];
1693 $fldlength = empty($fld_length) ?
20 : $fld_length;
1694 $lres = sqlStatement("SELECT * FROM list_options " .
1695 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1696 echo "<table cellpadding='0' cellspacing='0'>";
1697 echo "<tr><td> </td><td class='bold'>" .
1698 htmlspecialchars(xl('N/A'), ENT_NOQUOTES
) .
1699 " </td><td class='bold'>" .
1700 htmlspecialchars(xl('Nor'), ENT_NOQUOTES
) . " </td>" .
1701 "<td class='bold'>" .
1702 htmlspecialchars(xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
1703 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
1704 while ($lrow = sqlFetchArray($lres)) {
1705 $option_id = $lrow['option_id'];
1706 $restype = substr($avalue[$option_id], 0, 1);
1707 $resnote = substr($avalue[$option_id], 2);
1708 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1709 for ($i = 0; $i < 3; ++
$i) {
1710 echo "<td><input type='radio'";
1711 if ($restype === "$i") {
1718 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1719 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1720 echo "<td><input type='text'" .
1721 " size='$fldlength'" .
1722 " value='$resnote'" .
1723 " class='under form-control' /></td>" .
1728 } // the list of active allergies for the current patient
1729 // this is read-only!
1730 else if ($data_type == 24) {
1731 $query = "SELECT title, comments FROM lists WHERE " .
1732 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1734 $lres = sqlStatement($query, array($GLOBALS['pid']));
1736 while ($lrow = sqlFetchArray($lres)) {
1741 echo htmlspecialchars($lrow['title'], ENT_QUOTES
);
1742 if ($lrow['comments']) {
1743 echo htmlspecialchars(' (' . $lrow['comments'] . ')', ENT_QUOTES
);
1746 } // a set of labeled checkboxes, each with a text field:
1747 else if ($data_type == 25) {
1748 $tmp = explode('|', $currvalue);
1750 foreach ($tmp as $value) {
1751 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1752 $avalue[$matches[1]] = $matches[2];
1756 $fldlength = empty($fld_length) ?
20 : $fld_length;
1757 $lres = sqlStatement("SELECT * FROM list_options " .
1758 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1759 echo "<table cellpadding='0' cellspacing='0'>";
1760 while ($lrow = sqlFetchArray($lres)) {
1761 $option_id = $lrow['option_id'];
1762 $restype = substr($avalue[$option_id], 0, 1);
1763 $resnote = substr($avalue[$option_id], 2);
1764 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1765 echo "<td><input type='checkbox'";
1770 echo " /> </td>";
1771 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1772 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1773 echo "<td><input type='text'" .
1774 " size='$fldlength'" .
1775 " class='form-control' " .
1776 " value='$resnote'" .
1783 } // a set of labeled radio buttons
1784 else if ($data_type == 27 ||
$data_type == 1 ||
$data_type == 26 ||
$data_type == 33) {
1785 // In this special case, fld_length is the number of columns generated.
1786 $cols = max(1, $frow['fld_length']);
1787 $lres = sqlStatement("SELECT * FROM list_options " .
1788 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1789 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1790 $tdpct = (int) (100 / $cols);
1791 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1792 $option_id = $lrow['option_id'];
1793 if ($count %
$cols == 0) {
1800 echo "<td width='" . attr($tdpct) . "%'>";
1801 echo "<input type='radio'";
1802 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1803 // Do not use defaults for these printable forms.
1807 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
1813 if ($count > $cols) {
1814 // Add some space after multiple rows of radio buttons.
1815 $cols = htmlspecialchars($cols, ENT_QUOTES
);
1816 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1821 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1822 else if ($data_type == 28 ||
$data_type == 32) {
1823 $tmp = explode('|', $currvalue);
1824 switch (count($tmp)) {
1843 $resdate = $restype = "";
1846 $restype = $resdate = $resnote = "";
1850 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1851 echo "<table cellpadding='0' cellspacing='0'>";
1853 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1854 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1855 $resdate = htmlspecialchars($resdate, ENT_QUOTES
);
1856 if ($data_type == 28) {
1857 echo "<td><input type='text'" .
1858 " size='$fldlength'" .
1860 " value='$resnote' /></td>";
1861 echo "<td class='bold'> ".
1862 " ".
1863 htmlspecialchars(xl('Status'), ENT_NOQUOTES
).": </td>";
1864 } else if ($data_type == 32) {
1865 echo "<tr><td><input type='text'" .
1866 " size='$fldlength'" .
1867 " class='under form-control'" .
1868 " value='$resnote' /></td></tr>";
1870 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
1871 echo "<td><input type='text'" .
1872 " size='$fldlength'" .
1873 " class='under form-control'" .
1874 " value='$smoking_status_title' /></td>";
1875 echo "<td class='bold'> ".htmlspecialchars(xl('Status'), ENT_NOQUOTES
).": </td>";
1878 echo "<td><input type='radio' class='form-control'";
1879 if ($restype == "current".$field_id) {
1883 echo "/>".htmlspecialchars(xl('Current'), ENT_NOQUOTES
)." </td>";
1885 echo "<td><input type='radio' class='form-control'";
1886 if ($restype == "current".$field_id) {
1890 echo "/>".htmlspecialchars(xl('Quit'), ENT_NOQUOTES
)." </td>";
1892 echo "<td><input type='text' size='6'" .
1893 " value='$resdate'" .
1894 " class='under form-control'" .
1897 echo "<td><input type='radio' class='form-control'";
1898 if ($restype == "current".$field_id) {
1902 echo " />".htmlspecialchars(xl('Never'), ENT_NOQUOTES
)."</td>";
1904 echo "<td><input type='radio' class='form-control'";
1905 if ($restype == "not_applicable".$field_id) {
1909 echo " />".htmlspecialchars(xl('N/A'), ENT_NOQUOTES
)." </td>";
1912 } // static text. read-only, of course.
1913 else if ($data_type == 31) {
1914 echo parse_static_text($frow);
1915 } else if ($data_type == 34) {
1916 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;'>";
1917 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1918 echo "<div style='display:none'><textarea name='form_{$field_id}' class='form-control' id='form_{$field_id}' stye='display:none'></textarea></div>";
1920 } //facilities drop-down list
1921 else if ($data_type == 35) {
1922 // In this special case, fld_length is the number of columns generated.
1923 $cols = max(1, $frow['fld_length']);
1924 $lres = sqlStatement("SELECT id, name FROM facility ORDER BY name");
1925 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1926 $tdpct = (int) (100 / $cols);
1927 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1928 $option_id = $lrow['id'];
1929 if ($count %
$cols == 0) {
1935 echo "<td width='" . attr($tdpct) . "%'>";
1936 echo "<input type='radio'";
1937 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1938 // Do not use defaults for these printable forms.
1941 echo ">" . htmlspecialchars($lrow['name']);
1946 if ($count > $cols) {
1947 // Add some space after multiple rows of radio buttons.
1948 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1953 // Supports backup lists.
1954 else if ($data_type == 36) {
1955 if (empty($fld_length)) {
1956 if ($list_id == 'titles') {
1965 $values_array = explode("|", $currvalue);
1968 foreach ($values_array as $value) {
1970 $lrow = sqlQuery("SELECT title FROM list_options " .
1971 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1972 $tmp = xl_list_label($lrow['title']);
1973 if ($lrow == 0 && !empty($backup_list)) {
1974 // since primary list did not map, try to map to backup list
1975 $lrow = sqlQuery("SELECT title FROM list_options " .
1976 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1977 $tmp = xl_list_label($lrow['title']);
1988 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1991 if ($i != 0 && $tmp != ' ') {
1998 } // Image from canvas drawing
1999 else if ($data_type == 40) {
2001 echo "<img src='" . attr($currvalue) . "'>";
2006 function generate_display_field($frow, $currvalue)
2008 global $ISSUE_TYPES, $facilityService;
2010 $data_type = $frow['data_type'];
2011 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
2012 $list_id = $frow['list_id'];
2013 $backup_list = isset($frow['list_backup_id']) ?
$frow['list_backup_id'] : null;
2017 // generic selection list or the generic selection list with add on the fly
2019 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33) {
2020 $lrow = sqlQuery("SELECT title FROM list_options " .
2021 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2022 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2023 //if there is no matching value in the corresponding lists check backup list
2024 // only supported in data types 1,26,33
2025 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
2026 $lrow = sqlQuery("SELECT title FROM list_options " .
2027 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2028 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2030 } // simple text field
2031 else if ($data_type == 2) {
2032 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES
));
2033 } // long or multi-line text field
2034 else if ($data_type == 3) {
2035 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES
));
2037 else if ($data_type == 4) {
2038 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
2040 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
2041 $age_asof_date = '';
2042 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
2043 if ($currvalue === '') {
2046 $modtmp = isOption($frow['edit_options'], 'F') === false ?
0 : 1;
2048 $s .= text(oeFormatShortDate($currvalue));
2050 $s .= text(oeFormatDateTime($currvalue));
2053 $s .= " (" . text($agestr) . ")";
2057 else if ($data_type == 10 ||
$data_type == 11) {
2058 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2059 "WHERE id = ?", array($currvalue));
2060 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']), ENT_NOQUOTES
);
2062 else if ($data_type == 12) {
2063 $pres = get_pharmacies();
2064 while ($prow = sqlFetchArray($pres)) {
2066 if ($currvalue == $key) {
2067 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
2068 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2069 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
2073 else if ($data_type == 13) {
2074 $squads = acl_get_squads();
2076 foreach ($squads as $key => $value) {
2077 if ($currvalue == $key) {
2078 $s .= htmlspecialchars($value[3], ENT_NOQUOTES
);
2083 else if ($data_type == 14) {
2084 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
2085 "WHERE id = ?", array($currvalue));
2086 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
2087 if ($urow['organization'] !="") {
2088 $uname = $urow['organization'];
2090 $uname = $urow['lname'];
2091 if ($urow['fname']) {
2092 $uname .= ", " . $urow['fname'];
2096 $s = htmlspecialchars($uname, ENT_NOQUOTES
);
2098 else if ($data_type == 15) {
2100 if (!empty($currvalue)) {
2101 $relcodes = explode(';', $currvalue);
2102 foreach ($relcodes as $codestring) {
2103 if ($codestring === '') {
2106 $tmp = lookup_code_descriptions($codestring);
2113 $s .= $codestring . ' (' . xl('not found') . ')';
2117 } // insurance company list
2118 else if ($data_type == 16) {
2119 $insprovs = getInsuranceProviders();
2120 foreach ($insprovs as $key => $ipname) {
2121 if ($currvalue == $key) {
2122 $s .= htmlspecialchars($ipname, ENT_NOQUOTES
);
2126 else if ($data_type == 17) {
2127 foreach ($ISSUE_TYPES as $key => $value) {
2128 if ($currvalue == $key) {
2129 $s .= htmlspecialchars($value[1], ENT_NOQUOTES
);
2133 else if ($data_type == 18) {
2135 "SELECT pc_catid, pc_catname " .
2136 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2139 $s = htmlspecialchars($crow['pc_catname'], ENT_NOQUOTES
);
2140 } // a single checkbox or set of labeled checkboxes
2141 else if ($data_type == 21) {
2143 $s .= $currvalue ?
'[ x ]' : '[ ]';
2145 // In this special case, fld_length is the number of columns generated.
2146 $cols = max(1, $frow['fld_length']);
2147 $avalue = explode('|', $currvalue);
2148 $lres = sqlStatement("SELECT * FROM list_options " .
2149 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2150 $s .= "<table cellspacing='0' cellpadding='0'>";
2151 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
2152 $option_id = $lrow['option_id'];
2153 $option_id_esc = text($option_id);
2154 if ($count %
$cols == 0) {
2160 $s .= "<td nowrap>";
2161 $checked = in_array($option_id, $avalue);
2162 $s .= $checked ?
'[ x ]' : '[ ]';
2163 $s .= ' ' . text(xl_list_label($lrow['title'])). ' ';
2171 } // a set of labeled text input fields
2172 else if ($data_type == 22) {
2173 $tmp = explode('|', $currvalue);
2175 foreach ($tmp as $value) {
2176 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2177 $avalue[$matches[1]] = $matches[2];
2181 $lres = sqlStatement("SELECT * FROM list_options " .
2182 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2183 $s .= "<table cellpadding='0' cellspacing='0'>";
2184 while ($lrow = sqlFetchArray($lres)) {
2185 $option_id = $lrow['option_id'];
2186 if (empty($avalue[$option_id])) {
2190 // Added 5-09 by BM - Translate label if applicable
2191 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . ": </td>";
2193 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id], ENT_NOQUOTES
) . "</td></tr>";
2197 } // a set of exam results; 3 radio buttons and a text field:
2198 else if ($data_type == 23) {
2199 $tmp = explode('|', $currvalue);
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)) {
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
) . " </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
) . " </td>";
2225 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . "</td>";
2230 } // the list of active allergies for the current patient
2231 else if ($data_type == 24) {
2232 $query = "SELECT title, comments FROM lists WHERE " .
2233 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2235 // echo "<!-- $query -->\n"; // debugging
2236 $lres = sqlStatement($query, array($GLOBALS['pid']));
2238 while ($lrow = sqlFetchArray($lres)) {
2243 $s .= htmlspecialchars($lrow['title'], ENT_NOQUOTES
);
2244 if ($lrow['comments']) {
2245 $s .= ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES
) . ')';
2248 } // a set of labeled checkboxes, each with a text field:
2249 else if ($data_type == 25) {
2250 $tmp = explode('|', $currvalue);
2252 foreach ($tmp as $value) {
2253 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2254 $avalue[$matches[1]] = $matches[2];
2258 $lres = sqlStatement("SELECT * FROM list_options " .
2259 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2260 $s .= "<table cellpadding='0' cellspacing='0'>";
2261 while ($lrow = sqlFetchArray($lres)) {
2262 $option_id = $lrow['option_id'];
2263 $restype = substr($avalue[$option_id], 0, 1);
2264 $resnote = substr($avalue[$option_id], 2);
2265 if (empty($restype) && empty($resnote)) {
2269 // Added 5-09 by BM - Translate label if applicable
2270 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
2272 $restype = $restype ?
xl('Yes') : xl('No');
2273 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES
) . " </td>";
2274 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . "</td>";
2279 } // a set of labeled radio buttons
2280 else if ($data_type == 27) {
2281 // In this special case, fld_length is the number of columns generated.
2282 $cols = max(1, $frow['fld_length']);
2283 $lres = sqlStatement("SELECT * FROM list_options " .
2284 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2285 $s .= "<table cellspacing='0' cellpadding='0'>";
2286 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
2287 $option_id = $lrow['option_id'];
2288 $option_id_esc = text($option_id);
2289 if ($count %
$cols == 0) {
2296 $checked = ((strlen($currvalue) == 0 && $lrow['is_default']) ||
2297 (strlen($currvalue) > 0 && $option_id == $currvalue));
2298 $s .= $checked ?
'[ x ]' : '[ ]';
2299 $s .= ' ' . text(xl_list_label($lrow['title'])). ' ';
2306 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2307 // VicarePlus :: A selection list for smoking status.
2308 else if ($data_type == 28 ||
$data_type == 32) {
2309 $tmp = explode('|', $currvalue);
2310 switch (count($tmp)) {
2329 $resdate = $restype = "";
2332 $restype = $resdate = $resnote = "";
2336 $s .= "<table cellpadding='0' cellspacing='0'>";
2340 if ($restype == "current".$field_id) {
2341 $res = xl('Current');
2344 if ($restype == "quit".$field_id) {
2348 if ($restype == "never".$field_id) {
2352 if ($restype == "not_applicable".$field_id) {
2356 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2357 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2358 if ($data_type == 28) {
2359 if (!empty($resnote)) {
2360 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . " </td>";
2362 } //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2363 else if ($data_type == 32) {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2364 $smoke_codes = getSmokeCodes();
2365 if (!empty($reslist)) {
2366 if ($smoke_codes[$reslist]!="") {
2367 $code_desc = "( ".$smoke_codes[$reslist]." )";
2370 $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist) . " ".text($code_desc)." </td>";
2373 if (!empty($resnote)) {
2374 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . " </td>";
2379 $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'), ENT_NOQUOTES
) . "</b>: " . htmlspecialchars($res, ENT_NOQUOTES
) . " </td>";
2382 if ($restype == "quit".$field_id) {
2383 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate, ENT_NOQUOTES
) . " </td>";
2388 } // static text. read-only, of course.
2389 else if ($data_type == 31) {
2390 $s .= parse_static_text($frow);
2391 } else if ($data_type == 34) {
2392 $arr = explode("|*|*|*|", $currvalue);
2393 for ($i=0; $i<sizeof($arr); $i++
) {
2397 else if ($data_type == 35) {
2398 $urow = $facilityService->getById($currvalue);
2399 $s = htmlspecialchars($urow['name'], ENT_NOQUOTES
);
2401 // Supports backup lists
2402 else if ($data_type == 36) {
2403 $values_array = explode("|", $currvalue);
2405 foreach ($values_array as $value) {
2406 $lrow = sqlQuery("SELECT title FROM list_options " .
2407 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2408 if ($lrow == 0 && !empty($backup_list)) {
2410 $lrow = sqlQuery("SELECT title FROM list_options " .
2411 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2415 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2417 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2422 } // Image from canvas drawing
2423 else if ($data_type == 40) {
2425 $s .= "<img src='" . attr($currvalue) . "'>";
2432 // Generate plain text versions of selected LBF field types.
2433 // Currently used by interface/patient_file/download_template.php and interface/main/finder/dynamic_finder_ajax.php.
2434 // More field types might need to be supported here in the future.
2436 function generate_plaintext_field($frow, $currvalue)
2438 global $ISSUE_TYPES;
2440 $data_type = $frow['data_type'];
2441 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
2442 $list_id = $frow['list_id'];
2443 $backup_list = $frow['backup_list'];
2446 // generic selection list or the generic selection list with add on the fly
2447 // feature, or radio buttons
2448 // Supports backup lists (for datatypes 1,26,33)
2449 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27 ||
$data_type == 33) {
2450 $lrow = sqlQuery("SELECT title FROM list_options " .
2451 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2452 $s = xl_list_label($lrow['title']);
2453 //if there is no matching value in the corresponding lists check backup list
2454 // only supported in data types 1,26,33
2455 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
2456 $lrow = sqlQuery("SELECT title FROM list_options " .
2457 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2458 $s = xl_list_label($lrow['title']);
2460 } // simple or long text field
2461 else if ($data_type == 2 ||
$data_type == 3 ||
$data_type == 15) {
2464 else if ($data_type == 4) {
2465 $s = oeFormatShortDate($currvalue);
2466 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
2467 $age_asof_date = '';
2468 // Optional display of age or gestational age.
2469 $tmp = optionalAge($frow, $currvalue, $age_asof_date, $description);
2474 else if ($data_type == 10 ||
$data_type == 11) {
2475 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2476 "WHERE id = ?", array($currvalue));
2477 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2479 else if ($data_type == 12) {
2480 $pres = get_pharmacies();
2481 while ($prow = sqlFetchArray($pres)) {
2483 if ($currvalue == $key) {
2484 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2485 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2486 $prow['line1'] . ' / ' . $prow['city'];
2490 else if ($data_type == 14) {
2491 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2492 "WHERE id = ?", array($currvalue));
2493 $uname = $urow['lname'];
2494 if ($urow['fname']) {
2495 $uname .= ", " . $urow['fname'];
2499 } // insurance company list
2500 else if ($data_type == 16) {
2501 $insprovs = getInsuranceProviders();
2502 foreach ($insprovs as $key => $ipname) {
2503 if ($currvalue == $key) {
2508 else if ($data_type == 17) {
2509 foreach ($ISSUE_TYPES as $key => $value) {
2510 if ($currvalue == $key) {
2515 else if ($data_type == 18) {
2517 "SELECT pc_catid, pc_catname " .
2518 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2521 $s = $crow['pc_catname'];
2522 } // a set of labeled checkboxes
2523 else if ($data_type == 21) {
2525 $s .= $currvalue ?
xlt('Yes') : xlt('No');
2527 $avalue = explode('|', $currvalue);
2528 $lres = sqlStatement("SELECT * FROM list_options " .
2529 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2531 while ($lrow = sqlFetchArray($lres)) {
2532 $option_id = $lrow['option_id'];
2533 if (in_array($option_id, $avalue)) {
2537 $s .= xl_list_label($lrow['title']);
2541 } // a set of labeled text input fields
2542 else if ($data_type == 22) {
2543 $tmp = explode('|', $currvalue);
2545 foreach ($tmp as $value) {
2546 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2547 $avalue[$matches[1]] = $matches[2];
2551 $lres = sqlStatement("SELECT * FROM list_options " .
2552 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2553 while ($lrow = sqlFetchArray($lres)) {
2554 $option_id = $lrow['option_id'];
2555 if (empty($avalue[$option_id])) {
2563 $s .= xl_list_label($lrow['title']) . ': ';
2564 $s .= $avalue[$option_id];
2566 } // A set of exam results; 3 radio buttons and a text field.
2567 // This shows abnormal results only.
2568 else if ($data_type == 23) {
2569 $tmp = explode('|', $currvalue);
2571 foreach ($tmp as $value) {
2572 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2573 $avalue[$matches[1]] = $matches[2];
2577 $lres = sqlStatement("SELECT * FROM list_options " .
2578 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2579 while ($lrow = sqlFetchArray($lres)) {
2580 $option_id = $lrow['option_id'];
2581 $restype = substr($avalue[$option_id], 0, 1);
2582 $resnote = substr($avalue[$option_id], 2);
2583 if (empty($restype) && empty($resnote)) {
2587 if ($restype != '2') {
2588 continue; // show abnormal results only
2595 $s .= xl_list_label($lrow['title']);
2596 if (!empty($resnote)) {
2597 $s .= ': ' . $resnote;
2600 } // the list of active allergies for the current patient
2601 else if ($data_type == 24) {
2602 $query = "SELECT title, comments FROM lists WHERE " .
2603 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2605 $lres = sqlStatement($query, array($GLOBALS['pid']));
2607 while ($lrow = sqlFetchArray($lres)) {
2612 $s .= $lrow['title'];
2613 if ($lrow['comments']) {
2614 $s .= ' (' . $lrow['comments'] . ')';
2617 } // a set of labeled checkboxes, each with a text field:
2618 else if ($data_type == 25) {
2619 $tmp = explode('|', $currvalue);
2621 foreach ($tmp as $value) {
2622 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2623 $avalue[$matches[1]] = $matches[2];
2627 $lres = sqlStatement("SELECT * FROM list_options " .
2628 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2629 while ($lrow = sqlFetchArray($lres)) {
2630 $option_id = $lrow['option_id'];
2631 $restype = substr($avalue[$option_id], 0, 1);
2632 $resnote = substr($avalue[$option_id], 2);
2633 if (empty($restype) && empty($resnote)) {
2641 $s .= xl_list_label($lrow['title']);
2642 $restype = $restype ?
xl('Yes') : xl('No');
2645 $s .= ' ' . $resnote;
2648 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2649 // VicarePlus :: A selection list for smoking status.
2650 else if ($data_type == 28 ||
$data_type == 32) {
2651 $tmp = explode('|', $currvalue);
2652 $resnote = count($tmp) > 0 ?
$tmp[0] : '';
2653 $restype = count($tmp) > 1 ?
$tmp[1] : '';
2654 $resdate = count($tmp) > 2 ?
$tmp[2] : '';
2655 $reslist = count($tmp) > 3 ?
$tmp[3] : '';
2657 if ($restype == "current" . $field_id) {
2658 $res = xl('Current');
2661 if ($restype == "quit" . $field_id) {
2665 if ($restype == "never" . $field_id) {
2669 if ($restype == "not_applicable". $field_id) {
2673 if ($data_type == 28) {
2674 if (!empty($resnote)) {
2677 } // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2678 else if ($data_type == 32) {
2679 if (!empty($reslist)) {
2680 $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
2683 if (!empty($resnote)) {
2684 $s .= ' ' . $resnote;
2693 $s .= xl('Status') . ' ' . $res;
2696 if ($restype == "quit".$field_id) {
2704 // Supports backup lists
2705 else if ($data_type == 36) {
2706 $values_array = explode("|", $currvalue);
2709 foreach ($values_array as $value) {
2710 $lrow = sqlQuery("SELECT title FROM list_options " .
2711 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2713 if ($lrow == 0 && !empty($backup_list)) {
2715 $lrow = sqlQuery("SELECT title FROM list_options " .
2716 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2720 $s = $s . ", " . xl_list_label($lrow['title']);
2722 $s = xl_list_label($lrow['title']);
2732 $CPR = 4; // cells per row of generic data
2737 function disp_end_cell()
2739 global $item_count, $cell_count;
2740 if ($item_count > 0) {
2746 function disp_end_row()
2748 global $cell_count, $CPR;
2750 if ($cell_count > 0) {
2751 for (; $cell_count < $CPR;
2761 function disp_end_group()
2764 if (strlen($last_group) > 0) {
2769 // Accumulate action conditions into a JSON expression for the browser side.
2770 function accumActionConditions($field_id, &$condition_str, &$condarr)
2772 $conditions = empty($condarr) ?
array() : unserialize($condarr);
2774 foreach ($conditions as $key => $condition) {
2775 if ($key === 'action') {
2776 // If specified this should be the first array item.
2778 $action = $condition;
2782 if (empty($condition['id'])) {
2785 $andor = empty($condition['andor']) ?
'' : $condition['andor'];
2786 if ($condition_str) {
2787 $condition_str .= ",\n";
2789 $condition_str .= "{" .
2790 "target:'" . addslashes($field_id) . "', " .
2791 "action:'" . addslashes($action) . "', " .
2792 "id:'" . addslashes($condition['id']) . "', " .
2793 "itemid:'" . addslashes($condition['itemid']) . "', " .
2794 "operator:'" . addslashes($condition['operator']) . "', " .
2795 "value:'" . addslashes($condition['value']) . "', " .
2796 "andor:'" . addslashes($andor) . "'}";
2800 // This checks if the given field with the given value should have an action applied.
2801 // Originally the only action was skip, but now you can also set the field to a specified value.
2802 // It somewhat mirrors the checkSkipConditions function in options.js.php.
2803 // If you use this for multiple layouts in the same script, you should
2804 // clear $sk_layout_items before each layout.
2805 function isSkipped(&$frow, $currvalue)
2807 global $sk_layout_items;
2809 // Accumulate an array of the encountered fields and their values.
2810 // It is assumed that fields appear before they are tested by another field.
2811 // TBD: Bad assumption?
2812 $field_id = $frow['field_id'];
2813 if (!is_array($sk_layout_items)) {
2814 $sk_layout_items = array();
2816 $sk_layout_items[$field_id] = array('row' => $frow, 'value' => $currvalue);
2818 if (empty($frow['conditions'])) {
2822 $skiprows = unserialize($frow['conditions']);
2825 $datatype = $frow['data_type'];
2826 $action = 'skip'; // default action if none specified
2828 foreach ($skiprows as $key => $skiprow) {
2829 // id referenced field id
2830 // itemid referenced array key if applicable
2831 // operator "eq", "ne", "se" or "ns"
2832 // value if eq or ne, some string to compare with
2833 // andor "and", "or" or empty
2835 if ($key === 'action') {
2836 // Action value is a string. It can be "skip", or "value=" followed by a value.
2841 if (empty($skiprow['id'])) {
2845 $id = $skiprow['id'];
2846 if (!isset($sk_layout_items[$id])) {
2847 error_log("Function isSkipped() cannot find skip source field '$id'.");
2850 $itemid = $skiprow['itemid'];
2851 $operator = $skiprow['operator'];
2852 $skipval = $skiprow['value'];
2853 $srcvalue = $sk_layout_items[$id]['value'];
2854 $src_datatype = $sk_layout_items[$id]['row']['data_type'];
2855 $src_list_id = $sk_layout_items[$id]['row']['list_id'];
2857 // Some data types use itemid and we have to dig for their value.
2858 if ($src_datatype == 21 && $src_list_id) { // array of checkboxes
2859 $tmp = explode('|', $srcvalue);
2860 $srcvalue = in_array($itemid, $tmp);
2861 } else if ($src_datatype == 22 ||
$src_datatype == 23 ||
$src_datatype == 25) {
2862 $tmp = explode('|', $srcvalue);
2864 foreach ($tmp as $tmp2) {
2865 if (strpos($tmp2, "$itemid:") === 0) {
2866 if ($datatype == 22) {
2867 $srcvalue = substr($tmp2, strlen($itemid) +
1);
2869 $srcvalue = substr($tmp2, strlen($itemid) +
1, 1);
2875 // Compute the result of the test for this condition row.
2876 // PHP's looseness with variable type conversion helps us here.
2878 if ($operator == 'eq') {
2879 $condition = $srcvalue == $skipval;
2880 } else if ($operator == 'ne') {
2881 $condition = $srcvalue != $skipval;
2882 } else if ($operator == 'se') {
2883 $condition = $srcvalue == true;
2884 } else if ($operator == 'ns') {
2885 $condition = $srcvalue != true;
2887 error_log("Unknown skip operator '$operator' for field '$field_id'.");
2890 // Logic to accumulate multiple conditions for the same target.
2891 if ($prevandor == 'and') {
2892 $condition = $condition && $prevcond;
2893 } else if ($prevandor == 'or') {
2894 $condition = $condition ||
$prevcond;
2896 $prevandor = $skiprow['andor'];
2897 $prevcond = $condition;
2899 return $prevcond ?
$action : '';
2902 // Load array of names of the given layout and its groups.
2903 function getLayoutProperties($formtype, &$grparr, $sel = "grp_title")
2905 if ($sel != '*' && strpos($sel, 'grp_group_id') === false) {
2906 $sel = "grp_group_id, $sel";
2908 $gres = sqlStatement("SELECT $sel FROM layout_group_properties WHERE grp_form_id = ? " .
2909 "ORDER BY grp_group_id", array($formtype));
2910 while ($grow = sqlFetchArray($gres)) {
2911 $grparr[$grow['grp_group_id']] = $grow;
2915 function display_layout_rows($formtype, $result1, $result2 = '')
2917 global $item_count, $cell_count, $last_group, $CPR;
2920 getLayoutProperties($formtype, $grparr, '*');
2922 $TOPCPR = empty($grparr['']['grp_columns']) ?
4 : $grparr['']['grp_columns'];
2924 $fres = sqlStatement("SELECT * FROM layout_options " .
2925 "WHERE form_id = ? AND uor > 0 " .
2926 "ORDER BY group_id, seq", array($formtype));
2928 while ($frow = sqlFetchArray($fres)) {
2929 $this_group = $frow['group_id'];
2930 $titlecols = $frow['titlecols'];
2931 $datacols = $frow['datacols'];
2932 $data_type = $frow['data_type'];
2933 $field_id = $frow['field_id'];
2934 $list_id = $frow['list_id'];
2937 $CPR = empty($grparr[$this_group]['grp_columns']) ?
$TOPCPR : $grparr[$this_group]['grp_columns'];
2939 if ($formtype == 'DEM') {
2940 if (strpos($field_id, 'em_') === 0) {
2941 // Skip employer related fields, if it's disabled.
2942 if ($GLOBALS['omit_employers']) {
2946 $tmp = substr($field_id, 3);
2947 if (isset($result2[$tmp])) {
2948 $currvalue = $result2[$tmp];
2951 if (isset($result1[$field_id])) {
2952 $currvalue = $result1[$field_id];
2956 if (isset($result1[$field_id])) {
2957 $currvalue = $result1[$field_id];
2961 // Handle a data category (group) change.
2962 if (strcmp($this_group, $last_group) != 0) {
2963 $group_name = $grparr[$this_group]['grp_title'];
2964 // totally skip generating the employer category, if it's disabled.
2965 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
2970 $last_group = $this_group;
2973 // filter out all the empty field data from the patient report.
2974 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2975 // Handle starting of a new row.
2976 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
2980 echo "<td class='groupname'>";
2981 echo text(xl_layout_label($group_name));
2984 echo "<td valign='top'> ";
2990 if ($item_count == 0 && $titlecols == 0) {
2994 // Handle starting of a new label cell.
2995 if ($titlecols > 0) {
2997 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
2998 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES
);
2999 echo "<td class='label_custom' colspan='$titlecols_esc' ";
3000 //if ($cell_count == 2) echo " style='padding-left:10pt'";
3002 $cell_count +
= $titlecols;
3007 // Added 5-09 by BM - Translate label if applicable
3008 if ($frow['title']) {
3009 $tmp = xl_layout_label($frow['title']);
3011 // Append colon only if label does not end with punctuation.
3012 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3019 // Handle starting of a new data cell.
3020 if ($datacols > 0) {
3022 //echo "<td class='text data' colspan='$datacols' valign='top'";
3023 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES
);
3024 echo "<td class='text data' colspan='$datacols_esc'";
3025 //if ($cell_count > 0) echo " style='padding-left:5pt'";
3027 $cell_count +
= $datacols;
3031 echo generate_display_field($frow, $currvalue);
3038 function display_layout_tabs($formtype, $result1, $result2 = '')
3040 global $item_count, $cell_count, $last_group, $CPR;
3043 getLayoutProperties($formtype, $grparr);
3045 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3046 "WHERE form_id = ? AND uor > 0 " .
3047 "ORDER BY group_id", array($formtype));
3050 while ($frow = sqlFetchArray($fres)) {
3051 $this_group = $frow['group_id'];
3052 // $group_name = substr($this_group, 1);
3053 $group_name = $grparr[$this_group]['grp_title'];
3054 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3058 <li
<?php
echo $first ?
'class="current"' : '' ?
>>
3059 <a href
="#" id
="header_tab_<?php echo htmlspecialchars($group_name, ENT_QUOTES); ?>">
3060 <?php
echo htmlspecialchars(xl_layout_label($group_name), ENT_NOQUOTES
); ?
></a
>
3067 function display_layout_tabs_data($formtype, $result1, $result2 = '')
3069 global $item_count, $cell_count, $last_group, $CPR;
3072 getLayoutProperties($formtype, $grparr, '*');
3074 $TOPCPR = empty($grparr['']['grp_columns']) ?
4 : $grparr['']['grp_columns'];
3076 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3077 "WHERE form_id = ? AND uor > 0 " .
3078 "ORDER BY group_id", array($formtype));
3081 while ($frow = sqlFetchArray($fres)) {
3082 $this_group = isset($frow['group_id']) ?
$frow['group_id'] : "" ;
3084 if ($grparr[$this_group]['grp_columns'] === 'Employer' && $GLOBALS['omit_employers']) {
3087 $CPR = empty($grparr[$this_group]['grp_columns']) ?
$TOPCPR : $grparr[$this_group]['grp_columns'];
3088 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ?
'' : $grparr[$this_group]['grp_subtitle'];
3090 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3091 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3092 "ORDER BY seq", array($formtype, $this_group));
3095 <div
class="tab <?php echo $first ? 'current' : '' ?>">
3096 <table border
='0' cellpadding
='0'>
3099 while ($group_fields = sqlFetchArray($group_fields_query)) {
3100 $titlecols = $group_fields['titlecols'];
3101 $datacols = $group_fields['datacols'];
3102 $data_type = $group_fields['data_type'];
3103 $field_id = $group_fields['field_id'];
3104 $list_id = $group_fields['list_id'];
3106 $edit_options = $group_fields['edit_options'];
3108 if ($formtype == 'DEM') {
3109 if (strpos($field_id, 'em_') === 0) {
3110 // Skip employer related fields, if it's disabled.
3111 if ($GLOBALS['omit_employers']) {
3115 $tmp = substr($field_id, 3);
3116 if (isset($result2[$tmp])) {
3117 $currvalue = $result2[$tmp];
3120 if (isset($result1[$field_id])) {
3121 $currvalue = $result1[$field_id];
3125 if (isset($result1[$field_id])) {
3126 $currvalue = $result1[$field_id];
3130 // Skip this field if action conditions call for that.
3131 // Note this also accumulates info for subsequent skip tests.
3132 $skip_this_field = isSkipped($group_fields, $currvalue) == 'skip';
3134 // Skip this field if its do-not-print option is set.
3135 if (isOption($edit_options, 'X') !== false) {
3136 $skip_this_field = true;
3139 // Handle a data category (group) change.
3140 if (strcmp($this_group, $last_group) != 0) {
3141 $group_name = $grparr[$this_group]['grp_title'];
3142 // totally skip generating the employer category, if it's disabled.
3143 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3146 $last_group = $this_group;
3149 // Handle starting of a new row.
3150 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
3153 // Group subtitle exists and is not displayed yet.
3154 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3155 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3161 if ($item_count == 0 && $titlecols == 0) {
3165 // Handle starting of a new label cell.
3166 if ($titlecols > 0) {
3168 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES
);
3169 $field_id_label = 'label_'.$group_fields['field_id'];
3170 echo "<td class='label_custom' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
3172 $cell_count +
= $titlecols;
3177 $field_id_label = 'label_'.$group_fields['field_id'];
3178 echo "<span id='".attr($field_id_label)."'>";
3179 if ($skip_this_field) {
3180 // No label because skipping
3181 } else if ($group_fields['title']) {
3182 $tmp = xl_layout_label($group_fields['title']);
3184 // Append colon only if label does not end with punctuation.
3185 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3193 // Handle starting of a new data cell.
3194 if ($datacols > 0) {
3196 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES
);
3197 $field_id = 'text_'.$group_fields['field_id'];
3198 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
3199 if (!$skip_this_field && $data_type == 3) {
3200 // Textarea gets a light grey border.
3201 echo " style='border:1px solid #cccccc'";
3204 $cell_count +
= $datacols;
3206 $field_id = 'text_'.$group_fields['field_id'];
3207 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
3211 if (!$skip_this_field) {
3212 echo generate_display_field($group_fields, $currvalue);
3228 function display_layout_tabs_data_editable($formtype, $result1, $result2 = '')
3230 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
3233 getLayoutProperties($formtype, $grparr, '*');
3235 $TOPCPR = empty($grparr['']['grp_columns']) ?
4 : $grparr['']['grp_columns'];
3237 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3238 "WHERE form_id = ? AND uor > 0 " .
3239 "ORDER BY group_id", array($formtype));
3242 $condition_str = '';
3244 while ($frow = sqlFetchArray($fres)) {
3245 $this_group = $frow['group_id'];
3246 $group_name = $grparr[$this_group]['grp_title'];
3247 $group_name_esc = text($group_name);
3249 if ($grparr[$this_group]['grp_title'] === 'Employer' && $GLOBALS['omit_employers']) {
3252 $CPR = empty($grparr[$this_group]['grp_columns']) ?
$TOPCPR : $grparr[$this_group]['grp_columns'];
3253 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ?
'' : $grparr[$this_group]['grp_subtitle'];
3255 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3256 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3257 "ORDER BY seq", array($formtype, $this_group));
3260 <div
class="tab <?php echo $first ? 'current' : '' ?>" id
="tab_<?php echo str_replace(' ', '_', $group_name_esc)?>" >
3261 <table border
='0' cellpadding
='0'>
3264 while ($group_fields = sqlFetchArray($group_fields_query)) {
3265 $titlecols = $group_fields['titlecols'];
3266 $datacols = $group_fields['datacols'];
3267 $data_type = $group_fields['data_type'];
3268 $field_id = $group_fields['field_id'];
3269 $list_id = $group_fields['list_id'];
3270 $backup_list = $group_fields['list_backup_id'];
3274 // Accumulate action conditions into a JSON expression for the browser side.
3275 accumActionConditions($field_id, $condition_str, $group_fields['conditions']);
3277 if ($formtype == 'DEM') {
3278 if (strpos($field_id, 'em_') === 0) {
3279 // Skip employer related fields, if it's disabled.
3280 if ($GLOBALS['omit_employers']) {
3284 $tmp = substr($field_id, 3);
3285 if (isset($result2[$tmp])) {
3286 $currvalue = $result2[$tmp];
3289 if (isset($result1[$field_id])) {
3290 $currvalue = $result1[$field_id];
3294 if (isset($result1[$field_id])) {
3295 $currvalue = $result1[$field_id];
3299 // Handle a data category (group) change.
3300 if (strcmp($this_group, $last_group) != 0) {
3301 // totally skip generating the employer category, if it's disabled.
3302 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3306 $last_group = $this_group;
3309 // Handle starting of a new row.
3310 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
3313 // Group subtitle exists and is not displayed yet.
3314 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3315 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3321 if ($item_count == 0 && $titlecols == 0) {
3325 // Handle starting of a new label cell.
3326 if ($titlecols > 0) {
3328 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES
);
3329 $field_id_label = 'label_'.$group_fields['field_id'];
3330 echo "<td class='label_custom' colspan='$titlecols_esc'";
3331 // This ID is used by skip conditions.
3332 echo " id='label_id_" . attr($field_id) . "'";
3334 $cell_count +
= $titlecols;
3339 if ($group_fields['title']) {
3340 $tmp = xl_layout_label($group_fields['title']);
3342 // Append colon only if label does not end with punctuation.
3343 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3350 // Handle starting of a new data cell.
3351 if ($datacols > 0) {
3353 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES
);
3354 $field_id = 'text_'.$group_fields['field_id'];
3355 echo "<td class='text data' colspan='$datacols_esc'";
3356 // This ID is used by action conditions.
3357 echo " id='value_id_" . attr($field_id) . "'";
3359 $cell_count +
= $datacols;
3364 echo generate_form_field($group_fields, $currvalue);
3377 // From the currently posted HTML form, this gets the value of the
3378 // field corresponding to the provided layout_options table row.
3380 function get_layout_form_value($frow, $prefix = 'form_')
3382 $maxlength = empty($frow['max_length']) ?
0 : intval($frow['max_length']);
3383 $data_type = $frow['data_type'];
3384 $field_id = $frow['field_id'];
3386 if (isset($_POST["$prefix$field_id"])) {
3387 if ($data_type == 21) {
3388 if (!$frow['list_id']) {
3389 if (!empty($_POST["form_$field_id"])) {
3390 $value = xlt('Yes');
3393 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
3394 // must be concatenated into a |-separated string.
3395 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3396 if (strlen($value)) {
3402 } else if ($data_type == 22) {
3403 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
3404 // into "key:value|key:value|...".
3405 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3406 $val = str_replace('|', ' ', $val);
3407 if (strlen($value)) {
3411 $value .= "$key:$val";
3413 } else if ($data_type == 23) {
3414 // $_POST["$prefix$field_id"] is an array of text fields with companion
3415 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
3416 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3417 $restype = $_POST["radio_{$field_id}"][$key];
3418 if (empty($restype)) {
3422 $val = str_replace('|', ' ', $val);
3423 if (strlen($value)) {
3427 $value .= "$key:$restype:$val";
3429 } else if ($data_type == 25) {
3430 // $_POST["$prefix$field_id"] is an array of text fields with companion
3431 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
3432 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3433 $restype = empty($_POST["check_{$field_id}"][$key]) ?
'0' : '1';
3434 $val = str_replace('|', ' ', $val);
3435 if (strlen($value)) {
3439 $value .= "$key:$restype:$val";
3441 } else if ($data_type == 28 ||
$data_type == 32) {
3442 // $_POST["$prefix$field_id"] is an date text fields with companion
3443 // radio buttons to be imploded into "notes|type|date".
3444 $restype = $_POST["radio_{$field_id}"];
3445 if (empty($restype)) {
3449 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
3450 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3451 if ($data_type == 32) {
3452 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
3453 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3454 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
3455 $value = "$res_text_note|$restype|$resdate|$reslist";
3457 $value = "$resnote|$restype|$resdate";
3459 } else if ($data_type == 36) {
3460 $value_array = $_POST["form_$field_id"];
3462 foreach ($value_array as $key => $valueofkey) {
3464 $value = $valueofkey;
3466 $value = $value . "|" . $valueofkey;
3472 $value = $_POST["$prefix$field_id"];
3476 // Better to die than to silently truncate data!
3477 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength) {
3478 die(htmlspecialchars(xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES
) .
3479 ":<br /> <br />".htmlspecialchars($value, ENT_NOQUOTES
));
3482 return trim($value);
3485 // Generate JavaScript validation logic for the required fields.
3487 function generate_layout_validation($form_id)
3489 $fres = sqlStatement("SELECT * FROM layout_options " .
3490 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
3491 "ORDER BY group_id, seq", array($form_id));
3493 while ($frow = sqlFetchArray($fres)) {
3494 $data_type = $frow['data_type'];
3495 $field_id = $frow['field_id'];
3496 $fldtitle = $frow['title'];
3498 $fldtitle = $frow['description'];
3501 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES
);
3503 if ($data_type == 40) {
3504 $fldid = addslashes("form_$field_id");
3505 // Move canvas image data to its hidden form field so the server will get it.
3507 " var canfld = f['$fldid'];\n" .
3508 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
3512 if ($frow['uor'] < 2) {
3516 echo " if (f.$fldname && !f.$fldname.disabled) {\n";
3517 switch ($data_type) {
3525 " if (f.$fldname.selectedIndex <= 0) {\n" .
3526 " alert(\"" . addslashes(xl('Please choose a value for')) .
3527 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3528 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3529 " return false;\n" .
3534 " if (f.$fldname.selectedIndex <= 0) {\n" .
3535 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3536 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3539 case 27: // radio buttons
3542 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
3543 " if (i >= f.$fldname.length) {\n" .
3544 " alert(\"" . addslashes(xl('Please choose a value for')) .
3545 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3546 " return false;\n" .
3554 " if (trimlen(f.$fldname.value) == 0) {\n" .
3555 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3556 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
3557 " $('#" . $fldname . "').attr('style','background:red'); \n" .
3558 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3560 " $('#" . $fldname . "').attr('style',''); " .
3561 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
3564 case 36: // multi select
3566 " var multi_select=f['$fldname"."[]']; \n " .
3567 " var multi_choice_made=false; \n".
3568 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
3569 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
3571 " if(!multi_choice_made)
3572 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3581 * DROPDOWN FOR FACILITIES
3583 * build a dropdown with all facilities
3585 * @param string $selected - name of the currently selected facility
3586 * use '0' for "unspecified facility"
3587 * use '' for "All facilities" (the default)
3588 * @param string $name - the name/id for select form (defaults to "form_facility")
3589 * @param boolean $allow_unspecified - include an option for "unspecified" facility
3591 * @return void - just echo the html encoded string
3593 * Note: This should become a data-type at some point, according to Brady
3595 function dropdown_facility(
3597 $name = 'form_facility',
3598 $allow_unspecified = true,
3599 $allow_allfacilities = true,
3604 global $facilityService;
3606 $have_selected = false;
3607 $fres = $facilityService->getAll();
3609 $name = htmlspecialchars($name, ENT_QUOTES
);
3610 echo " <select class='form-control' name='$name' id='$name'";
3612 echo " onchange='$onchange'";
3615 echo " $disabled>\n";
3617 if ($allow_allfacilities) {
3619 $option_selected_attr = '';
3620 if ($selected == '') {
3621 $option_selected_attr = ' selected="selected"';
3622 $have_selected = true;
3625 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES
);
3626 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3627 } elseif ($allow_unspecified) {
3628 $option_value = '0';
3629 $option_selected_attr = '';
3630 if ($selected == '0') {
3631 $option_selected_attr = ' selected="selected"';
3632 $have_selected = true;
3635 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
3636 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3639 foreach ($fres as $frow) {
3640 $facility_id = $frow['id'];
3641 $option_value = htmlspecialchars($facility_id, ENT_QUOTES
);
3642 $option_selected_attr = '';
3643 if ($selected == $facility_id) {
3644 $option_selected_attr = ' selected="selected"';
3645 $have_selected = true;
3648 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES
);
3649 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3652 if ($allow_unspecified && $allow_allfacilities) {
3653 $option_value = '0';
3654 $option_selected_attr = '';
3655 if ($selected == '0') {
3656 $option_selected_attr = ' selected="selected"';
3657 $have_selected = true;
3660 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
3661 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3664 if (!$have_selected) {
3665 $option_value = htmlspecialchars($selected, ENT_QUOTES
);
3666 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES
);
3667 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES
);
3668 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
3671 echo " </select>\n";
3674 // Expand Collapse Widget
3675 // This forms the header and functionality component of the widget. The information that is displayed
3676 // then follows this function followed by a closing div tag
3678 // $title is the title of the section (already translated)
3679 // $label is identifier used in the tag id's and sql columns
3680 // $buttonLabel is the button label text (already translated)
3681 // $buttonLink is the button link information
3682 // $buttonClass is any additional needed class elements for the button tag
3683 // $linkMethod is the button link method ('javascript' vs 'html')
3684 // $bodyClass is to set class(es) of the body
3685 // $auth is a flag to decide whether to show the button
3686 // $fixedWidth is to flag whether width is fixed
3687 // $forceExpandAlways is a flag to force the widget to always be expanded
3689 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways = false)
3692 echo "<div class='section-header'>";
3694 echo "<div class='section-header-dynamic'>";
3699 // show button, since authorized
3700 // first prepare class string
3702 $class_string = "css_button_small ".htmlspecialchars($buttonClass, ENT_NOQUOTES
);
3704 $class_string = "css_button_small";
3707 // next, create the link
3708 if ($linkMethod == "javascript") {
3709 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3711 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3712 if (!isset($_SESSION['patient_portal_onsite']) && !isset($_SESSION['patient_portal_onsite_two'])) {
3713 // prevent an error from occuring when calling the function from the patient portal
3714 echo " onclick='top.restoreSession()'";
3719 htmlspecialchars($buttonLabel, ENT_NOQUOTES
) . "</span></a></td>";
3722 if ($forceExpandAlways) {
3723 // Special case to force the widget to always be expanded
3724 echo "<td><span class='text'><b>" . htmlspecialchars($title, ENT_NOQUOTES
) . "</b></span>";
3725 $indicatorTag ="style='display:none'";
3728 $indicatorTag = isset($indicatorTag) ?
$indicatorTag : "";
3729 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3730 htmlspecialchars($label, ENT_QUOTES
) . "_ps_expand\")'><span class='text'><b>";
3731 echo htmlspecialchars($title, ENT_NOQUOTES
) . "</b></span>";
3733 if (isset($_SESSION['patient_portal_onsite']) ||
isset($_SESSION['patient_portal_onsite_two'])) {
3734 // collapse all entries in the patient portal
3735 $text = xl('expand');
3736 } else if (getUserSetting($label."_ps_expand")) {
3737 $text = xl('collapse');
3739 $text = xl('expand');
3742 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES
) .
3743 "</span>)</a></td>";
3744 echo "</tr></table>";
3746 if ($forceExpandAlways) {
3747 // Special case to force the widget to always be expanded
3749 } else if (isset($_SESSION['patient_portal_onsite']) ||
isset($_SESSION['patient_portal_onsite_two'])) {
3750 // collapse all entries in the patient portal
3751 $styling = "style='display:none'";
3752 } else if (getUserSetting($label."_ps_expand")) {
3755 $styling = "style='display:none'";
3759 $styling .= " class='" . $bodyClass . "'";
3762 //next, create the first div tag to hold the information
3763 // note the code that calls this function will then place the ending div tag after the data
3764 echo "<div id='" . htmlspecialchars($label, ENT_QUOTES
) . "_ps_expand' " . $styling . ">";
3767 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3768 function billing_facility($name, $select)
3770 global $facilityService;
3772 $fres = $facilityService->getAllBillingLocations();
3773 echo " <select id='".htmlspecialchars($name, ENT_QUOTES
)."' class='form-control' name='".htmlspecialchars($name, ENT_QUOTES
)."'>";
3774 foreach ($fres as $facrow) {
3775 $selected = ( $facrow['id'] == $select ) ?
'selected="selected"' : '' ;
3776 echo "<option value=".htmlspecialchars($facrow['id'], ENT_QUOTES
)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES
)."</option>";
3782 // Generic function to get the translated title value for a particular list option.
3784 function getListItemTitle($list, $option)
3786 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3787 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3788 if (empty($row['title'])) {
3792 return xl_list_label($row['title']);
3794 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3795 function getSmokeCodes()
3797 $smoking_codes_arr = array();
3798 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3799 while ($codes_row = sqlFetchArray($smoking_codes)) {
3800 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3803 return $smoking_codes_arr;
3806 // Get the current value for a layout based form field.
3807 // Depending on options this might come from lbf_data, patient_data,
3808 // form_encounter, shared_attributes or elsewhere.
3809 // Returns FALSE if the field ID is invalid (layout error).
3811 function lbf_current_value($frow, $formid, $encounter)
3814 $formname = $frow['form_id'];
3815 $field_id = $frow['field_id'];
3816 $source = $frow['source'];
3818 $deffname = $formname . '_default_' . $field_id;
3819 if ($source == 'D' ||
$source == 'H') {
3820 // Get from patient_data, employer_data or history_data.
3821 if ($source == 'H') {
3822 $table = 'history_data';
3823 $orderby = 'ORDER BY date DESC LIMIT 1';
3824 } else if (strpos($field_id, 'em_') === 0) {
3825 $field_id = substr($field_id, 3);
3826 $table = 'employer_data';
3827 $orderby = 'ORDER BY date DESC LIMIT 1';
3829 $table = 'patient_data';
3833 // It is an error if the field does not exist, but don't crash.
3834 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3839 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3840 if (isset($pdrow)) {
3841 $currvalue = $pdrow['field_value'];
3843 } else if ($source == 'E') {
3846 // Get value from shared_attributes of the current encounter.
3848 "SELECT field_value FROM shared_attributes WHERE " .
3849 "pid = ? AND encounter = ? AND field_id = ?",
3850 array($pid, $encounter, $field_id)
3852 if (!empty($sarow)) {
3853 $currvalue = $sarow['field_value'];
3855 } else if ($formid) {
3856 // Get from shared_attributes of the encounter that this form is linked to.
3857 // Note the importance of having an index on forms.form_id.
3859 "SELECT sa.field_value " .
3860 "FROM forms AS f, shared_attributes AS sa WHERE " .
3861 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3862 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3863 array($formid, $formname, $field_id)
3865 if (!empty($sarow)) {
3866 $currvalue = $sarow['field_value'];
3869 // New form and encounter not available, this should not happen.
3871 if (empty($sarow) && !$formid) {
3872 // New form, see if there is a custom default from a plugin.
3873 if (function_exists($deffname)) {
3874 $currvalue = call_user_func($deffname);
3877 } else if ($source == 'V') {
3879 // Get value from the current encounter's form_encounter.
3881 "SELECT * FROM form_encounter WHERE " .
3882 "pid = ? AND encounter = ?",
3883 array($pid, $encounter)
3885 if (isset($ferow[$field_id])) {
3886 $currvalue = $ferow[$field_id];
3888 } else if ($formid) {
3889 // Get value from the form_encounter that this form is linked to.
3892 "FROM forms AS f, form_encounter AS fe WHERE " .
3893 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3894 "fe.pid = f.pid AND fe.encounter = f.encounter",
3895 array($formid, $formname)
3897 if (isset($ferow[$field_id])) {
3898 $currvalue = $ferow[$field_id];
3901 // New form and encounter not available, this should not happen.
3903 } else if ($formid) {
3904 // This is a normal form field.
3905 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3906 "form_id = ? AND field_id = ?", array($formid, $field_id));
3907 if (!empty($ldrow)) {
3908 $currvalue = $ldrow['field_value'];
3911 // New form, see if there is a custom default from a plugin.
3912 if (function_exists($deffname)) {
3913 $currvalue = call_user_func($deffname);
3920 // This returns stuff that needs to go into the <head> section of a caller using
3921 // the drawable image field type in a form.
3922 // A TRUE argument makes the widget controls smaller.
3924 function lbf_canvas_head($small = true)
3927 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3928 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3929 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3930 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3935 /* Custom LiterallyCanvas styling.
3936 * This makes the widget 25% less tall and adjusts some other things accordingly.
3939 min-height:100%;min-width:300px; /* Was 400, unspecified */
3941 .literally .lc-picker .toolbar-button {
3942 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3944 .literally .color-well {
3945 font-size:8px;width:49px; /* Was 10, 60 */
3947 .literally .color-well-color-container {
3948 width:21px;height:21px; /* Was 28, 28 */
3950 .literally .lc-picker {
3951 width:50px; /* Was 61 */
3953 .literally .lc-drawing.with-gui {
3954 left:50px; /* Was 61 */
3956 .literally .lc-options {
3957 left:50px; /* Was 61 */
3959 .literally .color-picker-popup {
3960 left:49px;bottom:0px; /* Was 60, 31 */
3970 * Test if modifier($test) is in array of options for data type.
3972 * @param json array $options or could be string of form "ABCU"
3973 * @param string $test
3976 function isOption($options, $test)
3978 if (empty($options) ||
!isset($test)) {
3979 return false; // why bother?
3981 if (strpos($options, ',') === false) { // could be string of char's or single element of json
3982 json_decode($options);
3983 if (is_string($options) && ! (json_last_error() === JSON_ERROR_NONE
)) { // nope, it's string.
3984 $t = str_split(trim($options)); // very good chance it's legacy modifier string.
3985 $options = json_encode($t); // make it array.
3988 $options = json_decode($options);
3990 return !is_null($options) && in_array($test, $options, true) ?
true : false; // finally!