2 // Copyright (C) 2007-2019 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 // Documentation for layout_options.edit_options:
21 // A = Age as years or "xx month(s)"
22 // B = Gestational age as "xx week(s) y day(s)"
23 // C = Capitalize first letter of each word (text fields)
24 // D = Check for duplicates in New Patient form
25 // G = Graphable (for numeric fields in forms supporting historical data)
26 // H = Read-only field copied from static history (this is obsolete)
27 // J = Jump to Next Row
28 // K = Prepend Blank Row
29 // L = Lab Order ("ord_lab") types only (address book)
30 // M = Radio Group Master (currently for radio buttons only)
31 // m = Radio Group Member (currently for radio buttons only)
32 // N = Show in New Patient form
33 // O = Procedure Order ("ord_*") types only (address book)
34 // P = Default to previous value when current value is not yet set
35 // R = Distributor types only (address book)
36 // T = Use description as default Text
37 // U = Capitalize all letters (text fields)
38 // V = Vendor types only (address book)
39 // 0 = Read Only - the input element's "disabled" property is set
40 // 1 = Write Once (not editable when not empty) (text fields)
41 // 2 = Show descriptions instead of codes for billing code input
43 require_once("user.inc");
44 require_once("patient.inc");
45 require_once("lists.inc");
46 require_once(dirname(dirname(__FILE__
)) . "/custom/code_types.inc.php");
48 use OpenEMR\Services\FacilityService
;
50 $facilityService = new FacilityService();
53 $membership_group_number = 0;
55 function get_pharmacies()
57 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
58 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
59 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
60 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
62 "ORDER BY name, area_code, prefix, number");
65 function optionalAge($frow, $date, &$asof, $description = '')
72 $date = substr($date, 0, 10);
73 if (isOption($frow['edit_options'], 'A') !== false) {
75 } elseif (isOption($frow['edit_options'], 'B') !== false) {
81 if (isOption($frow['form_id'], 'LBF') === 0) {
83 "SELECT date FROM form_encounter WHERE " .
84 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
85 array($GLOBALS['pid'], $GLOBALS['encounter'])
87 if (!empty($tmp['date'])) {
88 $asof = substr($tmp['date'], 0, 10);
91 if ($description === '') {
92 $prefix = ($format ?
xl('Gest age') : xl('Age')) . ' ';
94 $prefix = $description . ' ';
96 return $prefix . oeFormatAge($date, $asof, $format);
99 // Function to generate a drop-list.
101 function generate_select_list(
110 $custom_attributes = null,
116 $tag_name_esc = attr($tag_name);
119 $tag_name_esc = $tag_name_esc . "[]";
122 $s .= "<select name='$tag_name_esc'";
125 $s .= " multiple='multiple'";
128 $tag_id_esc = attr($tag_name);
131 $tag_id_esc = attr($tag_id);
134 $s .= " id='$tag_id_esc'";
136 if (!empty($class)) {
137 $class_esc = attr($class);
138 $s .= " class='form-control $class_esc'";
140 $s .= " class='form-control'";
144 $s .= " onchange='$onchange'";
147 if ($custom_attributes != null && is_array($custom_attributes)) {
148 foreach ($custom_attributes as $attr => $val) {
149 if (isset($custom_attributes [$attr])) {
150 $s .= " " . attr($attr) . "='" . attr($val) . "'";
155 $selectTitle = attr($title);
156 $s .= " title='$selectTitle'>";
157 $selectEmptyName = xlt($empty_name);
159 $s .= "<option value=''>" . $selectEmptyName . "</option>";
162 // List order depends on language translation options.
163 // (Note we do not need to worry about the list order in the algorithm
164 // after the below code block since that is where searches for exceptions
165 // are done which include inactive items or items from a backup
166 // list; note these will always be shown at the bottom of the list no matter the
168 $lang_id = empty($_SESSION['language_choice']) ?
'1' : $_SESSION['language_choice'];
170 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) ||
!$GLOBALS['translate_lists']) {
172 if ($GLOBALS['gb_how_sort_list'] == '0') {
174 $order_by_sql = "seq, title";
175 } else { //$GLOBALS['gb_how_sort_list'] == '1'
177 $order_by_sql = "title, seq";
180 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
183 if ($GLOBALS['gb_how_sort_list'] == '0') {
185 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
186 } else { //$GLOBALS['gb_how_sort_list'] == '1'
188 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
191 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
192 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
193 "FROM list_options AS lo " .
194 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
195 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
197 "WHERE lo.list_id = ? AND lo.activity=1 " .
198 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
201 $got_selected = false;
203 while ($lrow = sqlFetchArray($lres)) {
204 $selectedValues = explode("|", $currvalue);
206 $optionValue = attr($lrow ['option_id']);
207 $s .= "<option value='$optionValue'";
209 if ((strlen($currvalue) == 0 && $lrow ['is_default']) ||
(strlen($currvalue) > 0 && in_array($lrow ['option_id'], $selectedValues))) {
211 $got_selected = true;
214 // Already has been translated above (if applicable), so do not need to use
215 // the xl_list_label() function here
216 $optionLabel = text($lrow ['title']);
217 $s .= ">$optionLabel</option>\n";
221 To show the inactive item in the list if the value is saved to database
223 if (!$got_selected && strlen($currvalue) > 0) {
224 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
225 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
226 $lrow_inactive = sqlFetchArray($lres_inactive);
227 if ($lrow_inactive['option_id']) {
228 $optionValue = htmlspecialchars($lrow_inactive['option_id'], ENT_QUOTES
);
229 $s .= "<option value='$optionValue' selected>" . htmlspecialchars(xl_list_label($lrow_inactive['title']), ENT_NOQUOTES
) . "</option>\n";
230 $got_selected = true;
234 if (!$got_selected && strlen($currvalue) > 0 && !$multiple) {
235 $list_id = $backup_list;
236 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
238 if ($lrow > 0 && !empty($backup_list)) {
239 $selected = text(xl_list_label($lrow ['title']));
240 $s .= "<option value='$currescaped' selected> $selected </option>";
243 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
245 $fontTitle = xlt('Please choose a valid selection from the list.');
246 $fontText = xlt('Fix this');
247 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
249 } elseif (!$got_selected && strlen($currvalue) > 0 && $multiple) {
250 //if not found in main list, display all selected values that exist in backup list
251 $list_id = $backup_list;
253 $got_selected_backup = false;
254 if (!empty($backup_list)) {
255 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
256 while ($lrow_backup = sqlFetchArray($lres_backup)) {
257 $selectedValues = explode("|", $currvalue);
259 $optionValue = attr($lrow_backup['option_id']);
261 if (in_array($lrow_backup ['option_id'], $selectedValues)) {
262 $s .= "<option value='$optionValue'";
264 $optionLabel = text(xl_list_label($lrow_backup ['title']));
265 $s .= ">$optionLabel</option>\n";
266 $got_selected_backup = true;
271 if (!$got_selected_backup) {
272 $selectedValues = explode("|", $currvalue);
273 foreach ($selectedValues as $selectedValue) {
274 $s .= "<option value='" . attr($selectedValue) . "'";
276 $s .= ">* " . text($selectedValue) . " *</option>\n";
280 $fontTitle = xlt('Please choose a valid selection from the list.');
281 $fontText = xlt('Fix this');
282 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
291 // Parsing for data type 31, static text.
292 function parse_static_text($frow)
294 $tmp = $frow['description'];
295 // Translate if it does not look like HTML.
296 if (substr($tmp, 0, 1) != '<') {
297 $tmp = nl2br(xl_layout_label($tmp));
300 if ($frow['source'] == 'D' ||
$frow['source'] == 'H') {
301 // Source is demographics or history. This case supports value substitution.
302 while (preg_match('/^(.*?)\{(\w+)\}(.*)$/', $tmp, $matches)) {
305 $tmprow['field_id'] = $matches[2];
306 $s .= lbf_current_value($tmprow, 0, 0);
314 // $frow is a row from the layout_options table.
315 // $currvalue is the current value, if any, of the associated item.
317 function generate_form_field($frow, $currvalue)
319 global $rootdir, $date_init, $ISSUE_TYPES, $code_types, $membership_group_number;
321 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
323 $data_type = $frow['data_type'];
324 $field_id = $frow['field_id'];
325 $list_id = $frow['list_id'];
326 $backup_list = $frow['list_backup_id'];
328 // escaped variables to use in html
329 $field_id_esc= htmlspecialchars($field_id, ENT_QUOTES
);
330 $list_id_esc = htmlspecialchars($list_id, ENT_QUOTES
);
332 // Added 5-09 by BM - Translate description if applicable
333 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
335 // Support edit option T which assigns the (possibly very long) description as
336 // the default value.
337 if (isOption($frow['edit_options'], 'T') !== false) {
338 if (strlen($currescaped) == 0) {
339 $currescaped = $description;
342 // Description used in this way is not suitable as a title.
346 // added 5-2009 by BM to allow modification of the 'empty' text title field.
347 // Can pass $frow['empty_title'] with this variable, otherwise
348 // will default to 'Unassigned'.
349 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
350 // if make $frow['empty_title'] equal to 'SKIP'
352 if (isset($frow['empty_title'])) {
353 if ($frow['empty_title'] == "SKIP") {
354 //do not display an 'empty' choice
356 $empty_title = "Unassigned";
358 $empty_title = $frow['empty_title'];
361 $empty_title = "Unassigned";
364 $disabled = isOption($frow['edit_options'], '0') === false ?
'' : 'disabled';
367 strpos($frow['form_id'], 'LBF') === 0 ||
368 strpos($frow['form_id'], 'LBT') === 0 ||
369 $frow['form_id'] == 'DEM' ||
370 $frow['form_id'] == 'HIS'
371 ) ?
"checkSkipConditions();" : "";
372 $lbfonchange = $lbfchange ?
"onchange='$lbfchange'" : "";
374 // generic single-selection list or Race and Ethnicity.
375 // These data types support backup lists.
376 if ($data_type == 1 ||
$data_type == 33) {
377 echo generate_select_list(
382 ($showEmpty ?
$empty_title : ''),
386 ($disabled ?
array('disabled' => 'disabled') : null),
390 } // simple text field
391 elseif ($data_type == 2) {
392 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES
);
393 $maxlength = $frow['max_length'];
394 $string_maxlength = "";
395 // if max_length is set to zero, then do not set a maxlength
397 $string_maxlength = "maxlength='".attr($maxlength)."'";
400 echo "<input type='text'" .
401 " class='form-control'" .
402 " name='form_$field_id_esc'" .
403 " id='form_$field_id_esc'" .
404 " size='$fldlength'" .
405 " $string_maxlength" .
406 " title='$description'" .
407 " value='$currescaped'";
409 if (isOption($frow['edit_options'], 'C') !== false) {
410 $tmp .= "capitalizeMe(this);";
411 } elseif (isOption($frow['edit_options'], 'U') !== false) {
412 $tmp .= "this.value = this.value.toUpperCase();";
416 echo " onchange='$tmp'";
419 $tmp = htmlspecialchars($GLOBALS['gbl_mask_patient_id'], ENT_QUOTES
);
420 // If mask is for use at save time, treat as no mask.
421 if (strpos($tmp, '^') !== false) {
424 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
425 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
426 echo " onblur='maskblur(this,\"$tmp\")'";
429 if (isOption($frow['edit_options'], '1') !== false && strlen($currescaped) > 0) {
438 } // long or multi-line text field
439 elseif ($data_type == 3) {
440 $textCols = htmlspecialchars($frow['fld_length'], ENT_QUOTES
);
441 $textRows = htmlspecialchars($frow['fld_rows'], ENT_QUOTES
);
443 " name='form_$field_id_esc'" .
444 " class='form-control'" .
445 " id='form_$field_id_esc'" .
446 " title='$description'" .
447 " cols='$textCols'" .
448 " rows='$textRows' $lbfonchange $disabled" .
449 ">" . $currescaped . "</textarea>";
451 elseif ($data_type == 4) {
452 $age_asof_date = ''; // optionalAge() sets this
453 $age_format = isOption($frow['edit_options'], 'A') === false ?
3 : 0;
454 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
456 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
459 $onchange_string = '';
460 if (!$disabled && $agestr) {
461 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') " .
462 "updateAgeString('$field_id','$age_asof_date', $age_format, '$description')\"";
464 if ($data_type == 4) {
465 $modtmp = isOption($frow['edit_options'], 'F') === false ?
0 : 1;
467 $dateValue = oeFormatShortDate(substr($currescaped, 0, 10));
468 echo "<input type='text' size='10' class='datepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
469 " value='" . attr($dateValue) ."'";
471 $dateValue = oeFormatDateTime(substr($currescaped, 0, 20), 0);
472 echo "<input type='text' size='20' class='datetimepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
473 " value='" . attr($dateValue) . "'";
477 echo " title='$description'";
480 echo " $onchange_string $lbfonchange $disabled />";
482 // Optional display of age or gestational age.
484 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
486 } // provider list, local providers only
487 elseif ($data_type == 10) {
488 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
489 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
490 "AND authorized = 1 " .
491 "ORDER BY lname, fname");
492 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
493 echo "<option value=''>" . xlt($empty_title) . "</option>";
494 $got_selected = false;
495 while ($urow = sqlFetchArray($ures)) {
496 $uname = text($urow['fname'] . ' ' . $urow['lname']);
497 $optionId = attr($urow['id']);
498 echo "<option value='$optionId'";
499 if ($urow['id'] == $currvalue) {
501 $got_selected = true;
504 echo ">$uname</option>";
507 if (!$got_selected && $currvalue) {
508 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
510 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
514 } // provider list, including address book entries with an NPI number
515 elseif ($data_type == 11) {
516 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
517 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
518 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
519 "ORDER BY lname, fname");
520 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
521 echo " $lbfonchange $disabled>";
522 echo "<option value=''>" . xlt('Unassigned') . "</option>";
523 $got_selected = false;
524 while ($urow = sqlFetchArray($ures)) {
525 $uname = text($urow['fname'] . ' ' . $urow['lname']);
526 $optionId = attr($urow['id']);
527 echo "<option value='$optionId'";
528 if ($urow['id'] == $currvalue) {
530 $got_selected = true;
533 echo ">$uname</option>";
536 if (!$got_selected && $currvalue) {
537 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
539 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
544 elseif ($data_type == 12) {
545 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
546 echo " $lbfonchange $disabled>";
547 echo "<option value='0'></option>";
548 $pres = get_pharmacies();
549 $got_selected = false;
550 while ($prow = sqlFetchArray($pres)) {
552 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
553 $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
554 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
555 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
556 echo "<option value='$optionValue'";
557 if ($currvalue == $key) {
559 $got_selected = true;
562 echo ">$optionLabel</option>";
565 if (!$got_selected && $currvalue) {
566 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
568 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
573 elseif ($data_type == 13) {
574 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
575 echo " $lbfonchange $disabled>";
576 echo "<option value=''> </option>";
577 $squads = acl_get_squads();
579 foreach ($squads as $key => $value) {
580 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
581 $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES
);
582 echo "<option value='$optionValue'";
583 if ($currvalue == $key) {
587 echo ">$optionLabel</option>\n";
592 } // Address book, preferring organization name if it exists and is not in
593 // parentheses, and excluding local users who are not providers.
594 // Supports "referred to" practitioners and facilities.
595 // Alternatively the letter L in edit_options means that abook_type
596 // must be "ord_lab", indicating types used with the procedure
597 // lab ordering system.
598 // Alternatively the letter O in edit_options means that abook_type
599 // must begin with "ord_", indicating types used with the procedure
601 // Alternatively the letter V in edit_options means that abook_type
602 // must be "vendor", indicating the Vendor type.
603 // Alternatively the letter R in edit_options means that abook_type
604 // must be "dist", indicating the Distributor type.
605 elseif ($data_type == 14) {
606 if (isOption($frow['edit_options'], 'L') !== false) {
607 $tmp = "abook_type = 'ord_lab'";
608 } elseif (isOption($frow['edit_options'], 'O') !== false) {
609 $tmp = "abook_type LIKE 'ord\\_%'";
610 } elseif (isOption($frow['edit_options'], 'V') !== false) {
611 $tmp = "abook_type LIKE 'vendor%'";
612 } elseif (isOption($frow['edit_options'], 'R') !== false) {
613 $tmp = "abook_type LIKE 'dist'";
615 $tmp = "( username = '' OR authorized = 1 )";
618 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
619 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
621 "ORDER BY organization, lname, fname");
622 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
623 echo " $lbfonchange $disabled>";
624 echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
625 while ($urow = sqlFetchArray($ures)) {
626 $uname = $urow['organization'];
627 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
628 $uname = $urow['lname'];
629 if ($urow['fname']) {
630 $uname .= ", " . $urow['fname'];
634 $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES
);
635 $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES
);
636 echo "<option value='$optionValue'";
637 // Failure to translate Local and External is not an error here;
638 // they are only used as internal flags and must not be translated!
639 $title = $urow['username'] ?
'Local' : 'External';
640 $optionTitle = htmlspecialchars($title, ENT_QUOTES
);
641 echo " title='$optionTitle'";
642 if ($urow['id'] == $currvalue) {
646 echo ">$optionLabel</option>";
650 } // A billing code. If description matches an existing code type then that type is used.
651 elseif ($data_type == 15) {
653 if (!empty($frow['description']) && isset($code_types[$frow['description']])) {
654 $codetype = $frow['description'];
656 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES
);
657 $maxlength = $frow['max_length'];
658 $string_maxlength = "";
659 // if max_length is set to zero, then do not set a maxlength
661 $string_maxlength = "maxlength='".attr($maxlength)."'";
665 if (isOption($frow['edit_options'], '2') !== false && substr($frow['form_id'], 0, 3) == 'LBF') {
666 // Option "2" generates a hidden input for the codes, and a matching visible field
667 // displaying their descriptions. First step is computing the description string.
668 $currdescstring = '';
669 if (!empty($currvalue)) {
670 $relcodes = explode(';', $currvalue);
671 foreach ($relcodes as $codestring) {
672 if ($codestring === '') {
676 $code_text = lookup_code_descriptions($codestring);
677 if ($currdescstring !== '') {
678 $currdescstring .= '; ';
681 if (!empty($code_text)) {
682 $currdescstring .= $code_text;
684 $currdescstring .= $codestring;
689 $currdescstring = attr($currdescstring);
691 echo "<input type='text'" .
692 " name='form_$field_id_esc'" .
693 " id='form_related_code'" .
694 " size='$fldlength'" .
695 " value='$currescaped'" .
696 " style='display:none'" .
697 " $lbfonchange readonly $disabled />";
698 // Extra readonly input field for optional display of code description(s).
699 echo "<input type='text'" .
700 " name='form_$field_id_esc" . "__desc'" .
701 " size='$fldlength'" .
702 " title='$description'" .
703 " value='$currdescstring'";
705 echo " onclick='sel_related(this,\"$codetype\")'";
708 echo "class='form-control'";
709 echo " readonly $disabled />";
711 echo "<input type='text'" .
712 " name='form_$field_id_esc'" .
713 " id='form_related_code'" .
714 " size='$fldlength'" .
715 " $string_maxlength" .
716 " title='$description'" .
717 " value='$currescaped'";
719 echo " onclick='sel_related(this,\"$codetype\")'";
722 echo "class='form-control'";
723 echo " $lbfonchange readonly $disabled />";
725 } // insurance company list
726 elseif ($data_type == 16) {
727 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
728 echo "<option value='0'></option>";
729 $insprovs = getInsuranceProviders();
730 $got_selected = false;
731 foreach ($insprovs as $key => $ipname) {
732 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
733 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES
);
734 echo "<option value='$optionValue'";
735 if ($currvalue == $key) {
737 $got_selected = true;
740 echo ">$optionLabel</option>";
743 if (!$got_selected && $currvalue) {
744 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
746 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
751 elseif ($data_type == 17) {
752 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
753 echo "<option value='0'></option>";
754 $got_selected = false;
755 foreach ($ISSUE_TYPES as $key => $value) {
756 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
757 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES
);
758 echo "<option value='$optionValue'";
759 if ($currvalue == $key) {
761 $got_selected = true;
764 echo ">$optionLabel</option>";
767 if (!$got_selected && strlen($currvalue) > 0) {
768 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
770 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
774 } // Visit categories.
775 elseif ($data_type == 18) {
776 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
777 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
778 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'" .
779 " $lbfonchange $disabled>";
780 echo "<option value=''>" . xlt($empty_title) . "</option>";
781 $got_selected = false;
782 while ($crow = sqlFetchArray($cres)) {
783 $catid = $crow['pc_catid'];
784 if (($catid < 9 && $catid != 5) ||
$catid == 11) {
788 echo "<option value='" . attr($catid) . "'";
789 if ($catid == $currvalue) {
791 $got_selected = true;
794 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
797 if (!$got_selected && $currvalue) {
798 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
800 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
804 } // a set of labeled checkboxes
805 elseif ($data_type == 21) {
806 // If no list then it's a single checkbox and its value is "Yes" or empty.
808 echo "<input type='checkbox' name='form_{$field_id_esc}' " .
809 "id='form_{$field_id_esc}' value='Yes' $lbfonchange";
813 echo " $disabled />";
815 // In this special case, fld_length is the number of columns generated.
816 $cols = max(1, $frow['fld_length']);
817 $avalue = explode('|', $currvalue);
818 $lres = sqlStatement("SELECT * FROM list_options " .
819 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
820 echo "<table cellpadding='0' cellspacing='0' width='100%' title='".attr($description)."'>";
821 $tdpct = (int) (100 / $cols);
822 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
823 $option_id = $lrow['option_id'];
824 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
825 // if ($count) echo "<br />";
826 if ($count %
$cols == 0) {
832 echo "<td width='" . attr($tdpct) . "%' nowrap>";
833 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
834 "id='form_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
835 if (in_array($option_id, $avalue)) {
838 // Added 5-09 by BM - Translate label if applicable
839 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
844 if ($count > $cols) {
845 // Add some space after multiple rows of checkboxes.
846 $cols = htmlspecialchars($cols, ENT_QUOTES
);
847 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
852 } // a set of labeled text input fields
853 elseif ($data_type == 22) {
854 $tmp = explode('|', $currvalue);
856 foreach ($tmp as $value) {
857 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
858 $avalue[$matches[1]] = $matches[2];
862 $lres = sqlStatement("SELECT * FROM list_options " .
863 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
864 echo "<table cellpadding='0' cellspacing='0'>";
865 while ($lrow = sqlFetchArray($lres)) {
866 $option_id = $lrow['option_id'];
867 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
868 $maxlength = $frow['max_length'];
869 $string_maxlength = "";
870 // if max_length is set to zero, then do not set a maxlength
872 $string_maxlength = "maxlength='".attr($maxlength)."'";
875 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
877 // Added 5-09 by BM - Translate label if applicable
878 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
879 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
880 $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES
);
881 echo "<td><input type='text'" .
882 " name='form_{$field_id_esc}[$option_id_esc]'" .
883 " id='form_{$field_id_esc}[$option_id_esc]'" .
884 " size='$fldlength'" .
885 " class='form-control'" .
886 " $string_maxlength" .
887 " value='$optionValue'";
888 echo " $lbfonchange $disabled /></td></tr>";
892 } // a set of exam results; 3 radio buttons and a text field:
893 elseif ($data_type == 23) {
894 $tmp = explode('|', $currvalue);
896 foreach ($tmp as $value) {
897 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
898 $avalue[$matches[1]] = $matches[2];
902 $maxlength = $frow['max_length'];
903 $string_maxlength = "";
904 // if max_length is set to zero, then do not set a maxlength
906 $string_maxlength = "maxlength='".attr($maxlength)."'";
909 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
910 $lres = sqlStatement("SELECT * FROM list_options " .
911 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
912 echo "<table cellpadding='0' cellspacing='0'>";
913 echo "<tr><td> </td><td class='bold'>" .
914 htmlspecialchars(xl('N/A'), ENT_NOQUOTES
) .
915 " </td><td class='bold'>" .
916 htmlspecialchars(xl('Nor'), ENT_NOQUOTES
) . " </td>" .
917 "<td class='bold'>" .
918 htmlspecialchars(xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
919 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
920 while ($lrow = sqlFetchArray($lres)) {
921 $option_id = $lrow['option_id'];
922 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
923 $restype = substr($avalue[$option_id], 0, 1);
924 $resnote = substr($avalue[$option_id], 2);
926 // Added 5-09 by BM - Translate label if applicable
927 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
929 for ($i = 0; $i < 3; ++
$i) {
930 $inputValue = htmlspecialchars($i, ENT_QUOTES
);
931 echo "<td><input type='radio'" .
932 " name='radio_{$field_id_esc}[$option_id_esc]'" .
933 " id='radio_{$field_id_esc}[$option_id_esc]'" .
934 " value='$inputValue' $lbfonchange";
935 if ($restype === "$i") {
939 echo " $disabled /></td>";
942 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
943 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
944 echo "<td><input type='text'" .
945 " name='form_{$field_id_esc}[$option_id_esc]'" .
946 " id='form_{$field_id_esc}[$option_id_esc]'" .
947 " size='$fldlength'" .
948 " $string_maxlength" .
949 " value='$resnote' $disabled /></td>";
954 } // the list of active allergies for the current patient
955 // this is read-only!
956 elseif ($data_type == 24) {
957 $query = "SELECT title, comments FROM lists WHERE " .
958 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
960 // echo "<!-- $query -->\n"; // debugging
961 $lres = sqlStatement($query, array($GLOBALS['pid']));
963 while ($lrow = sqlFetchArray($lres)) {
968 echo htmlspecialchars($lrow['title'], ENT_NOQUOTES
);
969 if ($lrow['comments']) {
970 echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES
) . ')';
973 } // a set of labeled checkboxes, each with a text field:
974 elseif ($data_type == 25) {
975 $tmp = explode('|', $currvalue);
977 foreach ($tmp as $value) {
978 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
979 $avalue[$matches[1]] = $matches[2];
983 $maxlength = $frow['max_length'];
984 $string_maxlength = "";
985 // if max_length is set to zero, then do not set a maxlength
987 $string_maxlength = "maxlength='".attr($maxlength)."'";
990 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
991 $lres = sqlStatement("SELECT * FROM list_options " .
992 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
993 echo "<table cellpadding='0' cellspacing='0'>";
994 while ($lrow = sqlFetchArray($lres)) {
995 $option_id = $lrow['option_id'];
996 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
997 $restype = substr($avalue[$option_id], 0, 1);
998 $resnote = substr($avalue[$option_id], 2);
1000 // Added 5-09 by BM - Translate label if applicable
1001 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1003 $option_id = htmlspecialchars($option_id, ENT_QUOTES
);
1004 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
1005 " id='check_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
1010 echo " $disabled /> </td>";
1011 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1012 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1013 echo "<td><input type='text'" .
1014 " name='form_{$field_id_esc}[$option_id_esc]'" .
1015 " id='form_{$field_id_esc}[$option_id_esc]'" .
1016 " size='$fldlength'" .
1017 " class='form-control' " .
1018 " $string_maxlength" .
1019 " value='$resnote' $disabled /></td>";
1024 } // single-selection list with ability to add to it
1025 elseif ($data_type == 26) {
1026 echo generate_select_list(
1031 ($showEmpty ?
$empty_title : ''),
1032 'addtolistclass_'.$list_id,
1035 ($disabled ?
array('disabled' => 'disabled') : null),
1039 // show the add button if user has access to correct list
1040 $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES
);
1041 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
1042 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
1043 if (aco_exist('lists', $list_id)) {
1044 // a specific aco exist for this list, so ensure access
1045 if (acl_check('lists', $list_id)) {
1046 echo $outputAddButton;
1049 // no specific aco exist for this list, so check for access to 'default' list
1050 if (acl_check('lists', 'default')) {
1051 echo $outputAddButton;
1054 } // a set of labeled radio buttons
1055 elseif ($data_type == 27) {
1056 // In this special case, fld_length is the number of columns generated.
1057 $cols = max(1, $frow['fld_length']);
1058 // Support for edit option M.
1059 if (isOption($frow['edit_options'], 'M')) {
1060 ++
$membership_group_number;
1063 $lres = sqlStatement("SELECT * FROM list_options " .
1064 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1065 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1066 $tdpct = (int) (100 / $cols);
1067 $got_selected = false;
1068 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1069 $option_id = $lrow['option_id'];
1070 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
1071 if ($count %
$cols == 0) {
1077 echo "<td width='" . attr($tdpct) . "%'>";
1078 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
1079 " value='$option_id_esc' $lbfonchange";
1080 // Support for edit options M and m.
1081 if (isOption($frow['edit_options'], 'M')) {
1082 echo " class='form-control'";
1083 echo " onclick='checkGroupMembers(this, $membership_group_number);'";
1084 } else if (isOption($frow['edit_options'], 'm')) {
1085 echo " class='form-control lbf_memgroup_$membership_group_number'";
1087 echo " class='form-control'";
1090 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1091 (strlen($currvalue) > 0 && $option_id == $currvalue)) {
1093 $got_selected = true;
1095 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
1101 if ($count > $cols) {
1102 // Add some space after multiple rows of radio buttons.
1103 $cols = htmlspecialchars($cols, ENT_QUOTES
);
1104 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1109 if (!$got_selected && strlen($currvalue) > 0) {
1110 $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES
);
1111 $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES
);
1112 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
1114 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1115 // VicarePlus :: A selection list box for smoking status:
1116 elseif ($data_type == 28 ||
$data_type == 32) {
1117 $tmp = explode('|', $currvalue);
1118 switch (count($tmp)) {
1122 $resdate = oeFormatShortDate($tmp[2]);
1128 $resdate = oeFormatShortDate($tmp[2]);
1137 $resdate = $restype = "";
1140 $restype = $resdate = $resnote = "";
1144 $maxlength = $frow['max_length'];
1145 $string_maxlength = "";
1146 // if max_length is set to zero, then do not set a maxlength
1148 $string_maxlength = "maxlength='".attr($maxlength)."'";
1151 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1153 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1154 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1155 $resdate = htmlspecialchars($resdate, ENT_QUOTES
);
1156 echo "<table cellpadding='0' cellspacing='0'>";
1158 if ($data_type == 28) {
1160 echo "<td><input type='text'" .
1161 " name='form_$field_id_esc'" .
1162 " id='form_$field_id_esc'" .
1163 " size='$fldlength'" .
1164 " $string_maxlength" .
1165 " value='$resnote' $disabled /> </td>";
1166 echo "<td class='bold'> ".
1167 " ".
1168 htmlspecialchars(xl('Status'), ENT_NOQUOTES
).": </td>";
1169 } elseif ($data_type == 32) {
1171 echo "<tr><td><input type='text'" .
1172 " name='form_text_$field_id_esc'" .
1173 " id='form_text_$field_id_esc'" .
1174 " size='$fldlength'" .
1175 " class='form-control'" .
1176 " $string_maxlength" .
1177 " value='$resnote' $disabled /> </td></tr>";
1179 //Selection list for smoking status
1180 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1181 echo generate_select_list(
1186 ($showEmpty ?
$empty_title : ''),
1190 ($disabled ?
array('disabled' => 'disabled') : null)
1193 echo "<td class='bold'> " . xlt('Status') . ": </td>";
1197 echo "<td class='text' ><input type='radio'" .
1198 " name='radio_{$field_id_esc}'" .
1199 " id='radio_{$field_id_esc}[current]'" .
1200 " class='form-control'" .
1201 " value='current" . $field_id_esc . "' $lbfonchange";
1202 if ($restype == "current" . $field_id) {
1206 if ($data_type == 32) {
1207 echo " onClick='smoking_statusClicked(this)'";
1210 echo " />" . xlt('Current') . " </td>";
1212 echo "<td class='text'><input type='radio'" .
1213 " name='radio_{$field_id_esc}'" .
1214 " id='radio_{$field_id_esc}[quit]'" .
1215 " class='form-control'" .
1216 " value='quit".$field_id_esc."' $lbfonchange";
1217 if ($restype == "quit" . $field_id) {
1221 if ($data_type == 32) {
1222 echo " onClick='smoking_statusClicked(this)'";
1225 echo " $disabled />" . xlt('Quit') . " </td>";
1227 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1228 " value='$resdate'" .
1229 " title='$description'" .
1233 echo "<td class='text'><input type='radio'" .
1234 " name='radio_{$field_id_esc}'" .
1235 " class='form-control'" .
1236 " id='radio_{$field_id_esc}[never]'" .
1237 " value='never" . $field_id_esc . "' $lbfonchange";
1238 if ($restype == "never" . $field_id) {
1242 if ($data_type == 32) {
1243 echo " onClick='smoking_statusClicked(this)'";
1246 echo " />" . xlt('Never') . " </td>";
1248 echo "<td class='text'><input type='radio'" .
1249 " class='form-control' " .
1250 " name='radio_{$field_id}'" .
1251 " id='radio_{$field_id}[not_applicable]'" .
1252 " value='not_applicable" . $field_id . "' $lbfonchange";
1253 if ($restype == "not_applicable" . $field_id) {
1257 if ($data_type == 32) {
1258 echo " onClick='smoking_statusClicked(this)'";
1261 echo " $disabled />" . xlt('N/A') . " </td>";
1263 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1264 echo "<td class='text' ><div id='smoke_code'></div></td>";
1267 } // static text. read-only, of course.
1268 elseif ($data_type == 31) {
1269 echo parse_static_text($frow);
1270 } //$data_type == 33
1271 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1274 elseif ($data_type == 34) {
1275 $arr = explode("|*|*|*|", $currvalue);
1276 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc, ENT_QUOTES
)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1277 echo "<div id='form_{$field_id}_div' class='text-area' style='min-width:100pt'>" . $arr[0] . "</div>";
1278 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' class='form-control' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1280 } //facilities drop-down list
1281 elseif ($data_type == 35) {
1282 if (empty($currvalue)) {
1287 $selected = $currvalue,
1288 $name = "form_$field_id_esc",
1289 $allow_unspecified = true,
1290 $allow_allfacilities = false,
1295 // supports backup list
1296 elseif ($data_type == 36) {
1297 echo generate_select_list(
1302 $showEmpty ?
$empty_title : '',
1310 } // Canvas and related elements for browser-side image drawing.
1311 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1312 elseif ($data_type == 40) {
1313 // Unlike other field types, width and height are in pixels.
1314 $canWidth = intval($frow['fld_length']);
1315 $canHeight = intval($frow['fld_rows']);
1316 if (empty($currvalue)) {
1317 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1318 // If defined this is the filename of the default starting image.
1319 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1323 $mywidth = 50 +
($canWidth > 250 ?
$canWidth : 250);
1324 $myheight = 31 +
($canHeight > 261 ?
$canHeight : 261);
1325 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1326 // Hidden form field exists to send updated data to the server at submit time.
1327 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1328 // Hidden image exists to support initialization of the canvas.
1329 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1330 // $date_init is a misnomer but it's the place for browser-side setup logic.
1331 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1335 function generate_print_field($frow, $currvalue)
1337 global $rootdir, $date_init, $ISSUE_TYPES;
1339 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
1341 $data_type = $frow['data_type'];
1342 $field_id = $frow['field_id'];
1343 $list_id = $frow['list_id'];
1344 $fld_length = $frow['fld_length'];
1345 $backup_list = $frow['list_backup_id'];
1347 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
1349 // Can pass $frow['empty_title'] with this variable, otherwise
1350 // will default to 'Unassigned'.
1351 // If it is 'SKIP' then an empty text title is completely skipped.
1353 if (isset($frow['empty_title'])) {
1354 if ($frow['empty_title'] == "SKIP") {
1355 //do not display an 'empty' choice
1357 $empty_title = "Unassigned";
1359 $empty_title = $frow['empty_title'];
1362 $empty_title = "Unassigned";
1365 // generic single-selection list
1366 // Supports backup lists.
1367 if (false && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
1368 if (empty($fld_length)) {
1369 if ($list_id == 'titles') {
1378 $lrow = sqlQuery("SELECT title FROM list_options " .
1379 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1380 $tmp = xl_list_label($lrow['title']);
1381 if ($lrow == 0 && !empty($backup_list)) {
1382 // since primary list did not map, try to map to backup list
1383 $lrow = sqlQuery("SELECT title FROM list_options " .
1384 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1385 $tmp = xl_list_label($lrow['title']);
1389 $tmp = "($currvalue)";
1393 /*****************************************************************
1394 echo "<input type='text'" .
1395 " size='$fld_length'" .
1399 *****************************************************************/
1403 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1407 } // simple text field
1408 elseif ($data_type == 2 ||
$data_type == 15) {
1409 /*****************************************************************
1410 echo "<input type='text'" .
1411 " size='$fld_length'" .
1412 " value='$currescaped'" .
1415 *****************************************************************/
1416 if ($currescaped === '') {
1417 $currescaped = ' ';
1421 } // long or multi-line text field
1422 elseif ($data_type == 3) {
1423 $fldlength = htmlspecialchars($fld_length, ENT_QUOTES
);
1424 $maxlength = htmlspecialchars($frow['fld_rows'], ENT_QUOTES
);
1426 " class='form-control' " .
1427 " cols='$fldlength'" .
1428 " rows='$maxlength'>" .
1429 $currescaped . "</textarea>";
1431 elseif ($data_type == 4) {
1432 $age_asof_date = '';
1433 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
1434 if ($currvalue === '') {
1437 $modtmp = isOption($frow['edit_options'], 'F') === false ?
0 : 1;
1439 echo text(oeFormatShortDate($currvalue));
1441 echo text(oeFormatDateTime($currvalue));
1444 echo " (" . text($agestr) . ")";
1448 elseif ($data_type == 10 ||
$data_type == 11) {
1451 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1452 "WHERE id = ?", array($currvalue));
1453 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1455 $tmp = "($currvalue)";
1459 /*****************************************************************
1460 echo "<input type='text'" .
1461 " size='$fld_length'" .
1465 *****************************************************************/
1469 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1474 elseif ($data_type == 12) {
1477 $pres = get_pharmacies();
1478 while ($prow = sqlFetchArray($pres)) {
1480 if ($currvalue == $key) {
1481 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1482 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1483 $prow['line1'] . ' / ' . $prow['city'];
1488 $tmp = "($currvalue)";
1492 /*****************************************************************
1493 echo "<input type='text'" .
1494 " size='$fld_length'" .
1498 *****************************************************************/
1502 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1507 elseif ($data_type == 13) {
1510 $squads = acl_get_squads();
1512 foreach ($squads as $key => $value) {
1513 if ($currvalue == $key) {
1520 $tmp = "($currvalue)";
1524 /*****************************************************************
1525 echo "<input type='text'" .
1526 " size='$fld_length'" .
1530 *****************************************************************/
1534 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1539 elseif ($data_type == 14) {
1542 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1543 "WHERE id = ?", array($currvalue));
1544 $uname = $urow['lname'];
1545 if ($urow['fname']) {
1546 $uname .= ", " . $urow['fname'];
1551 $tmp = "($currvalue)";
1555 /*****************************************************************
1556 echo "<input type='text'" .
1557 " size='$fld_length'" .
1561 *****************************************************************/
1565 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1569 } // insurance company list
1570 elseif ($data_type == 16) {
1573 $insprovs = getInsuranceProviders();
1574 foreach ($insprovs as $key => $ipname) {
1575 if ($currvalue == $key) {
1581 $tmp = "($currvalue)";
1588 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1593 elseif ($data_type == 17) {
1596 foreach ($ISSUE_TYPES as $key => $value) {
1597 if ($currvalue == $key) {
1603 $tmp = "($currvalue)";
1610 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1614 } // Visit categories.
1615 elseif ($data_type == 18) {
1619 "SELECT pc_catid, pc_catname " .
1620 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1623 $tmp = xl_appt_category($crow['pc_catname']);
1625 $tmp = "($currvalue)";
1632 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1636 } // a single checkbox or set of labeled checkboxes
1637 elseif ($data_type == 21) {
1639 echo "<input type='checkbox'";
1645 // In this special case, fld_length is the number of columns generated.
1646 $cols = max(1, $fld_length);
1647 $avalue = explode('|', $currvalue);
1648 $lres = sqlStatement("SELECT * FROM list_options " .
1649 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1650 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1651 $tdpct = (int) (100 / $cols);
1652 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1653 $option_id = $lrow['option_id'];
1654 if ($count %
$cols == 0) {
1661 echo "<td width='" . attr($tdpct) . "%' nowrap>";
1662 echo "<input type='checkbox'";
1663 if (in_array($option_id, $avalue)) {
1666 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
1671 if ($count > $cols) {
1672 // Add some space after multiple rows of checkboxes.
1673 $cols = htmlspecialchars($cols, ENT_QUOTES
);
1674 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1679 } // a set of labeled text input fields
1680 elseif ($data_type == 22) {
1681 $tmp = explode('|', $currvalue);
1683 foreach ($tmp as $value) {
1684 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1685 $avalue[$matches[1]] = $matches[2];
1689 $lres = sqlStatement("SELECT * FROM list_options " .
1690 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1691 echo "<table cellpadding='0' cellspacing='0'>";
1692 while ($lrow = sqlFetchArray($lres)) {
1693 $option_id = $lrow['option_id'];
1694 $fldlength = empty($fld_length) ?
20 : $fld_length;
1695 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1696 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1697 $inputValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES
);
1698 echo "<td><input type='text'" .
1699 " class='form-control' " .
1700 " size='$fldlength'" .
1701 " value='$inputValue'" .
1707 } // a set of exam results; 3 radio buttons and a text field:
1708 elseif ($data_type == 23) {
1709 $tmp = explode('|', $currvalue);
1711 foreach ($tmp as $value) {
1712 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1713 $avalue[$matches[1]] = $matches[2];
1717 $fldlength = empty($fld_length) ?
20 : $fld_length;
1718 $lres = sqlStatement("SELECT * FROM list_options " .
1719 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1720 echo "<table cellpadding='0' cellspacing='0'>";
1721 echo "<tr><td> </td><td class='bold'>" .
1722 htmlspecialchars(xl('N/A'), ENT_NOQUOTES
) .
1723 " </td><td class='bold'>" .
1724 htmlspecialchars(xl('Nor'), ENT_NOQUOTES
) . " </td>" .
1725 "<td class='bold'>" .
1726 htmlspecialchars(xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
1727 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
1728 while ($lrow = sqlFetchArray($lres)) {
1729 $option_id = $lrow['option_id'];
1730 $restype = substr($avalue[$option_id], 0, 1);
1731 $resnote = substr($avalue[$option_id], 2);
1732 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1733 for ($i = 0; $i < 3; ++
$i) {
1734 echo "<td><input type='radio'";
1735 if ($restype === "$i") {
1742 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1743 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1744 echo "<td><input type='text'" .
1745 " size='$fldlength'" .
1746 " value='$resnote'" .
1747 " class='under form-control' /></td>" .
1752 } // the list of active allergies for the current patient
1753 // this is read-only!
1754 elseif ($data_type == 24) {
1755 $query = "SELECT title, comments FROM lists WHERE " .
1756 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1758 $lres = sqlStatement($query, array($GLOBALS['pid']));
1760 while ($lrow = sqlFetchArray($lres)) {
1765 echo htmlspecialchars($lrow['title'], ENT_QUOTES
);
1766 if ($lrow['comments']) {
1767 echo htmlspecialchars(' (' . $lrow['comments'] . ')', ENT_QUOTES
);
1770 } // a set of labeled checkboxes, each with a text field:
1771 elseif ($data_type == 25) {
1772 $tmp = explode('|', $currvalue);
1774 foreach ($tmp as $value) {
1775 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1776 $avalue[$matches[1]] = $matches[2];
1780 $fldlength = empty($fld_length) ?
20 : $fld_length;
1781 $lres = sqlStatement("SELECT * FROM list_options " .
1782 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1783 echo "<table cellpadding='0' cellspacing='0'>";
1784 while ($lrow = sqlFetchArray($lres)) {
1785 $option_id = $lrow['option_id'];
1786 $restype = substr($avalue[$option_id], 0, 1);
1787 $resnote = substr($avalue[$option_id], 2);
1788 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1789 echo "<td><input type='checkbox'";
1794 echo " /> </td>";
1795 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1796 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1797 echo "<td><input type='text'" .
1798 " size='$fldlength'" .
1799 " class='form-control' " .
1800 " value='$resnote'" .
1807 } // a set of labeled radio buttons
1808 elseif ($data_type == 27 ||
$data_type == 1 ||
$data_type == 26 ||
$data_type == 33) {
1809 // In this special case, fld_length is the number of columns generated.
1810 $cols = max(1, $frow['fld_length']);
1811 $lres = sqlStatement("SELECT * FROM list_options " .
1812 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1813 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1814 $tdpct = (int) (100 / $cols);
1815 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1816 $option_id = $lrow['option_id'];
1817 if ($count %
$cols == 0) {
1824 echo "<td width='" . attr($tdpct) . "%' nowrap>";
1825 echo "<input type='radio'";
1826 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1827 // Do not use defaults for these printable forms.
1831 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
1837 if ($count > $cols) {
1838 // Add some space after multiple rows of radio buttons.
1839 $cols = htmlspecialchars($cols, ENT_QUOTES
);
1840 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1845 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1846 elseif ($data_type == 28 ||
$data_type == 32) {
1847 $tmp = explode('|', $currvalue);
1848 switch (count($tmp)) {
1852 $resdate = oeFormatShortDate($tmp[2]) ;
1858 $resdate = oeFormatShortDate($tmp[2]);
1867 $resdate = $restype = "";
1870 $restype = $resdate = $resnote = "";
1874 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1875 echo "<table cellpadding='0' cellspacing='0'>";
1877 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1878 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1879 $resdate = htmlspecialchars($resdate, ENT_QUOTES
);
1880 if ($data_type == 28) {
1881 echo "<td><input type='text'" .
1882 " size='$fldlength'" .
1884 " value='$resnote' /></td>";
1885 echo "<td class='bold'> ".
1886 " ".
1887 htmlspecialchars(xl('Status'), ENT_NOQUOTES
).": </td>";
1888 } elseif ($data_type == 32) {
1889 echo "<tr><td><input type='text'" .
1890 " size='$fldlength'" .
1891 " class='under form-control'" .
1892 " value='$resnote' /></td></tr>";
1894 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
1895 echo "<td><input type='text'" .
1896 " size='$fldlength'" .
1897 " class='under form-control'" .
1898 " value='$smoking_status_title' /></td>";
1899 echo "<td class='bold'> ".htmlspecialchars(xl('Status'), ENT_NOQUOTES
).": </td>";
1902 echo "<td><input type='radio' class='form-control'";
1903 if ($restype == "current".$field_id) {
1907 echo "/>".htmlspecialchars(xl('Current'), ENT_NOQUOTES
)." </td>";
1909 echo "<td><input type='radio' class='form-control'";
1910 if ($restype == "current".$field_id) {
1914 echo "/>".htmlspecialchars(xl('Quit'), ENT_NOQUOTES
)." </td>";
1916 echo "<td><input type='text' size='6'" .
1917 " value='$resdate'" .
1918 " class='under form-control'" .
1921 echo "<td><input type='radio' class='form-control'";
1922 if ($restype == "current".$field_id) {
1926 echo " />".htmlspecialchars(xl('Never'), ENT_NOQUOTES
)."</td>";
1928 echo "<td><input type='radio' class='form-control'";
1929 if ($restype == "not_applicable".$field_id) {
1933 echo " />".htmlspecialchars(xl('N/A'), ENT_NOQUOTES
)." </td>";
1936 } // static text. read-only, of course.
1937 elseif ($data_type == 31) {
1938 echo parse_static_text($frow);
1939 } elseif ($data_type == 34) {
1940 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc, ENT_QUOTES
)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1941 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1942 echo "<div style='display:none'><textarea name='form_{$field_id}' class='form-control' id='form_{$field_id}' stye='display:none'></textarea></div>";
1944 } //facilities drop-down list
1945 elseif ($data_type == 35) {
1946 // In this special case, fld_length is the number of columns generated.
1947 $cols = max(1, $frow['fld_length']);
1948 $lres = sqlStatement("SELECT id, name FROM facility ORDER BY name");
1949 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1950 $tdpct = (int) (100 / $cols);
1951 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1952 $option_id = $lrow['id'];
1953 if ($count %
$cols == 0) {
1959 echo "<td width='" . attr($tdpct) . "%'>";
1960 echo "<input type='radio'";
1961 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1962 // Do not use defaults for these printable forms.
1965 echo ">" . htmlspecialchars($lrow['name']);
1970 if ($count > $cols) {
1971 // Add some space after multiple rows of radio buttons.
1972 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1977 // Supports backup lists.
1978 elseif ($data_type == 36) {
1979 if (empty($fld_length)) {
1980 if ($list_id == 'titles') {
1989 $values_array = explode("|", $currvalue);
1992 foreach ($values_array as $value) {
1994 $lrow = sqlQuery("SELECT title FROM list_options " .
1995 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1996 $tmp = xl_list_label($lrow['title']);
1997 if ($lrow == 0 && !empty($backup_list)) {
1998 // since primary list did not map, try to map to backup list
1999 $lrow = sqlQuery("SELECT title FROM list_options " .
2000 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2001 $tmp = xl_list_label($lrow['title']);
2012 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
2015 if ($i != 0 && $tmp != ' ') {
2022 } // Image from canvas drawing
2023 elseif ($data_type == 40) {
2025 echo "<img src='" . attr($currvalue) . "'>";
2030 function generate_display_field($frow, $currvalue)
2032 global $ISSUE_TYPES, $facilityService;
2034 $data_type = $frow['data_type'];
2035 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
2036 $list_id = $frow['list_id'];
2037 $backup_list = isset($frow['list_backup_id']) ?
$frow['list_backup_id'] : null;
2041 // generic selection list or the generic selection list with add on the fly
2043 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33) {
2044 $lrow = sqlQuery("SELECT title FROM list_options " .
2045 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2046 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2047 //if there is no matching value in the corresponding lists check backup list
2048 // only supported in data types 1,26,33
2049 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
2050 $lrow = sqlQuery("SELECT title FROM list_options " .
2051 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2052 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2054 // If match is not found in main and backup lists, return the key with exclamation mark
2056 $s = nl2br(text(xl_list_label($currvalue))).
2057 '<sup> <i class="fa fas fa-exclamation-circle ml-1"></i></sup>';
2059 } // simple text field
2060 elseif ($data_type == 2) {
2061 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES
));
2062 } // long or multi-line text field
2063 elseif ($data_type == 3) {
2064 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES
));
2066 elseif ($data_type == 4) {
2067 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
2069 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
2070 $age_asof_date = '';
2071 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
2072 if ($currvalue === '') {
2075 $modtmp = isOption($frow['edit_options'], 'F') === false ?
0 : 1;
2077 $s .= text(oeFormatShortDate($currvalue));
2079 $s .= text(oeFormatDateTime($currvalue));
2082 $s .= " (" . text($agestr) . ")";
2086 elseif ($data_type == 10 ||
$data_type == 11) {
2087 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2088 "WHERE id = ?", array($currvalue));
2089 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']), ENT_NOQUOTES
);
2091 elseif ($data_type == 12) {
2092 $pres = get_pharmacies();
2093 while ($prow = sqlFetchArray($pres)) {
2095 if ($currvalue == $key) {
2096 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
2097 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2098 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
2102 elseif ($data_type == 13) {
2103 $squads = acl_get_squads();
2105 foreach ($squads as $key => $value) {
2106 if ($currvalue == $key) {
2107 $s .= htmlspecialchars($value[3], ENT_NOQUOTES
);
2112 elseif ($data_type == 14) {
2113 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
2114 "WHERE id = ?", array($currvalue));
2115 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
2116 if ($urow['organization'] !="") {
2117 $uname = $urow['organization'];
2119 $uname = $urow['lname'];
2120 if ($urow['fname']) {
2121 $uname .= ", " . $urow['fname'];
2125 $s = htmlspecialchars($uname, ENT_NOQUOTES
);
2127 elseif ($data_type == 15) {
2129 if (!empty($currvalue)) {
2130 $relcodes = explode(';', $currvalue);
2131 foreach ($relcodes as $codestring) {
2132 if ($codestring === '') {
2135 $tmp = lookup_code_descriptions($codestring);
2142 $s .= $codestring . ' (' . xl('not found') . ')';
2146 } // insurance company list
2147 elseif ($data_type == 16) {
2148 $insprovs = getInsuranceProviders();
2149 foreach ($insprovs as $key => $ipname) {
2150 if ($currvalue == $key) {
2151 $s .= htmlspecialchars($ipname, ENT_NOQUOTES
);
2155 elseif ($data_type == 17) {
2156 foreach ($ISSUE_TYPES as $key => $value) {
2157 if ($currvalue == $key) {
2158 $s .= htmlspecialchars($value[1], ENT_NOQUOTES
);
2162 elseif ($data_type == 18) {
2164 "SELECT pc_catid, pc_catname " .
2165 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2168 $s = htmlspecialchars($crow['pc_catname'], ENT_NOQUOTES
);
2169 } // a single checkbox or set of labeled checkboxes
2170 elseif ($data_type == 21) {
2172 $s .= $currvalue ?
'[ x ]' : '[ ]';
2174 // In this special case, fld_length is the number of columns generated.
2175 $cols = max(1, $frow['fld_length']);
2176 $avalue = explode('|', $currvalue);
2177 $lres = sqlStatement("SELECT * FROM list_options " .
2178 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2179 $s .= "<table cellspacing='0' cellpadding='0'>";
2180 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
2181 $option_id = $lrow['option_id'];
2182 $option_id_esc = text($option_id);
2183 if ($count %
$cols == 0) {
2189 $s .= "<td nowrap>";
2190 $checked = in_array($option_id, $avalue);
2191 $s .= $checked ?
'[ x ]' : '[ ]';
2192 $s .= ' ' . text(xl_list_label($lrow['title'])). ' ';
2200 } // a set of labeled text input fields
2201 elseif ($data_type == 22) {
2202 $tmp = explode('|', $currvalue);
2204 foreach ($tmp as $value) {
2205 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2206 $avalue[$matches[1]] = $matches[2];
2210 $lres = sqlStatement("SELECT * FROM list_options " .
2211 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2212 $s .= "<table cellpadding='0' cellspacing='0'>";
2213 while ($lrow = sqlFetchArray($lres)) {
2214 $option_id = $lrow['option_id'];
2215 if (empty($avalue[$option_id])) {
2219 // Added 5-09 by BM - Translate label if applicable
2220 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . ": </td>";
2222 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id], ENT_NOQUOTES
) . "</td></tr>";
2226 } // a set of exam results; 3 radio buttons and a text field:
2227 elseif ($data_type == 23) {
2228 $tmp = explode('|', $currvalue);
2230 foreach ($tmp as $value) {
2231 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2232 $avalue[$matches[1]] = $matches[2];
2236 $lres = sqlStatement("SELECT * FROM list_options " .
2237 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2238 $s .= "<table cellpadding='0' cellspacing='0'>";
2239 while ($lrow = sqlFetchArray($lres)) {
2240 $option_id = $lrow['option_id'];
2241 $restype = substr($avalue[$option_id], 0, 1);
2242 $resnote = substr($avalue[$option_id], 2);
2243 if (empty($restype) && empty($resnote)) {
2247 // Added 5-09 by BM - Translate label if applicable
2248 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
2250 $restype = ($restype == '1') ?
xl('Normal') : (($restype == '2') ?
xl('Abnormal') : xl('N/A'));
2251 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2252 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2253 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES
) . " </td>";
2254 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . "</td>";
2259 } // the list of active allergies for the current patient
2260 elseif ($data_type == 24) {
2261 $query = "SELECT title, comments FROM lists WHERE " .
2262 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2264 // echo "<!-- $query -->\n"; // debugging
2265 $lres = sqlStatement($query, array($GLOBALS['pid']));
2267 while ($lrow = sqlFetchArray($lres)) {
2272 $s .= htmlspecialchars($lrow['title'], ENT_NOQUOTES
);
2273 if ($lrow['comments']) {
2274 $s .= ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES
) . ')';
2277 } // a set of labeled checkboxes, each with a text field:
2278 elseif ($data_type == 25) {
2279 $tmp = explode('|', $currvalue);
2281 foreach ($tmp as $value) {
2282 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2283 $avalue[$matches[1]] = $matches[2];
2287 $lres = sqlStatement("SELECT * FROM list_options " .
2288 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2289 $s .= "<table cellpadding='0' cellspacing='0'>";
2290 while ($lrow = sqlFetchArray($lres)) {
2291 $option_id = $lrow['option_id'];
2292 $restype = substr($avalue[$option_id], 0, 1);
2293 $resnote = substr($avalue[$option_id], 2);
2294 if (empty($restype) && empty($resnote)) {
2298 // Added 5-09 by BM - Translate label if applicable
2299 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
2301 $restype = $restype ?
xl('Yes') : xl('No');
2302 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES
) . " </td>";
2303 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . "</td>";
2308 } // a set of labeled radio buttons
2309 elseif ($data_type == 27) {
2310 // In this special case, fld_length is the number of columns generated.
2311 $cols = max(1, $frow['fld_length']);
2312 $lres = sqlStatement("SELECT * FROM list_options " .
2313 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2314 $s .= "<table cellspacing='0' cellpadding='0'>";
2315 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
2316 $option_id = $lrow['option_id'];
2317 $option_id_esc = text($option_id);
2318 if ($count %
$cols == 0) {
2324 $s .= "<td nowrap>";
2325 $checked = ((strlen($currvalue) == 0 && $lrow['is_default']) ||
2326 (strlen($currvalue) > 0 && $option_id == $currvalue));
2327 $s .= $checked ?
'[ x ]' : '[ ]';
2328 $s .= ' ' . text(xl_list_label($lrow['title'])). ' ';
2335 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2336 // VicarePlus :: A selection list for smoking status.
2337 elseif ($data_type == 28 ||
$data_type == 32) {
2338 $tmp = explode('|', $currvalue);
2339 switch (count($tmp)) {
2343 $resdate = oeFormatShortDate($tmp[2]);
2349 $resdate = oeFormatShortDate($tmp[2]);
2358 $resdate = $restype = "";
2361 $restype = $resdate = $resnote = "";
2365 $s .= "<table cellpadding='0' cellspacing='0'>";
2369 if ($restype == "current".$field_id) {
2370 $res = xl('Current');
2373 if ($restype == "quit".$field_id) {
2377 if ($restype == "never".$field_id) {
2381 if ($restype == "not_applicable".$field_id) {
2385 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2386 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2387 if ($data_type == 28) {
2388 if (!empty($resnote)) {
2389 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . " </td>";
2391 } //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2392 elseif ($data_type == 32) {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2393 $smoke_codes = getSmokeCodes();
2394 if (!empty($reslist)) {
2395 if ($smoke_codes[$reslist]!="") {
2396 $code_desc = "( ".$smoke_codes[$reslist]." )";
2399 $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist) . " ".text($code_desc)." </td>";
2402 if (!empty($resnote)) {
2403 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . " </td>";
2408 $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'), ENT_NOQUOTES
) . "</b>: " . htmlspecialchars($res, ENT_NOQUOTES
) . " </td>";
2411 if ($restype == "quit".$field_id) {
2412 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate, ENT_NOQUOTES
) . " </td>";
2417 } // static text. read-only, of course.
2418 elseif ($data_type == 31) {
2419 $s .= parse_static_text($frow);
2420 } elseif ($data_type == 34) {
2421 $arr = explode("|*|*|*|", $currvalue);
2422 for ($i=0; $i<sizeof($arr); $i++
) {
2426 elseif ($data_type == 35) {
2427 $urow = $facilityService->getById($currvalue);
2428 $s = htmlspecialchars($urow['name'], ENT_NOQUOTES
);
2430 // Supports backup lists
2431 elseif ($data_type == 36) {
2432 $values_array = explode("|", $currvalue);
2434 foreach ($values_array as $value) {
2435 $lrow = sqlQuery("SELECT title FROM list_options " .
2436 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2437 if ($lrow == 0 && !empty($backup_list)) {
2439 $lrow = sqlQuery("SELECT title FROM list_options " .
2440 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2444 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2446 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2451 } // Image from canvas drawing
2452 elseif ($data_type == 40) {
2454 $s .= "<img src='" . attr($currvalue) . "'>";
2461 // Generate plain text versions of selected LBF field types.
2462 // Currently used by interface/patient_file/download_template.php and interface/main/finder/dynamic_finder_ajax.php.
2463 // More field types might need to be supported here in the future.
2465 function generate_plaintext_field($frow, $currvalue)
2467 global $ISSUE_TYPES;
2469 $data_type = $frow['data_type'];
2470 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
2471 $list_id = $frow['list_id'];
2472 $backup_list = $frow['backup_list'];
2475 // generic selection list or the generic selection list with add on the fly
2476 // feature, or radio buttons
2477 // Supports backup lists (for datatypes 1,26,33)
2478 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27 ||
$data_type == 33) {
2479 $lrow = sqlQuery("SELECT title FROM list_options " .
2480 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2481 $s = xl_list_label($lrow['title']);
2482 //if there is no matching value in the corresponding lists check backup list
2483 // only supported in data types 1,26,33
2484 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
2485 $lrow = sqlQuery("SELECT title FROM list_options " .
2486 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2487 $s = xl_list_label($lrow['title']);
2489 } // simple or long text field
2490 elseif ($data_type == 2 ||
$data_type == 3 ||
$data_type == 15) {
2493 elseif ($data_type == 4) {
2494 $modtmp = isOption($frow['edit_options'], 'F') === false ?
0 : 1;
2496 $s = text(oeFormatShortDate($currvalue));
2498 $s = text(oeFormatDateTime($currvalue));
2500 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
2501 $age_asof_date = '';
2502 // Optional display of age or gestational age.
2503 $tmp = optionalAge($frow, $currvalue, $age_asof_date, $description);
2508 elseif ($data_type == 10 ||
$data_type == 11) {
2509 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2510 "WHERE id = ?", array($currvalue));
2511 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2513 elseif ($data_type == 12) {
2514 $pres = get_pharmacies();
2515 while ($prow = sqlFetchArray($pres)) {
2517 if ($currvalue == $key) {
2518 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2519 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2520 $prow['line1'] . ' / ' . $prow['city'];
2524 elseif ($data_type == 14) {
2525 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2526 "WHERE id = ?", array($currvalue));
2527 $uname = $urow['lname'];
2528 if ($urow['fname']) {
2529 $uname .= ", " . $urow['fname'];
2533 } // insurance company list
2534 elseif ($data_type == 16) {
2535 $insprovs = getInsuranceProviders();
2536 foreach ($insprovs as $key => $ipname) {
2537 if ($currvalue == $key) {
2542 elseif ($data_type == 17) {
2543 foreach ($ISSUE_TYPES as $key => $value) {
2544 if ($currvalue == $key) {
2549 elseif ($data_type == 18) {
2551 "SELECT pc_catid, pc_catname " .
2552 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2555 $s = $crow['pc_catname'];
2556 } // a set of labeled checkboxes
2557 elseif ($data_type == 21) {
2559 $s .= $currvalue ?
xlt('Yes') : xlt('No');
2561 $avalue = explode('|', $currvalue);
2562 $lres = sqlStatement("SELECT * FROM list_options " .
2563 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2565 while ($lrow = sqlFetchArray($lres)) {
2566 $option_id = $lrow['option_id'];
2567 if (in_array($option_id, $avalue)) {
2571 $s .= xl_list_label($lrow['title']);
2575 } // a set of labeled text input fields
2576 elseif ($data_type == 22) {
2577 $tmp = explode('|', $currvalue);
2579 foreach ($tmp as $value) {
2580 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2581 $avalue[$matches[1]] = $matches[2];
2585 $lres = sqlStatement("SELECT * FROM list_options " .
2586 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2587 while ($lrow = sqlFetchArray($lres)) {
2588 $option_id = $lrow['option_id'];
2589 if (empty($avalue[$option_id])) {
2597 $s .= xl_list_label($lrow['title']) . ': ';
2598 $s .= $avalue[$option_id];
2600 } // A set of exam results; 3 radio buttons and a text field.
2601 // This shows abnormal results only.
2602 elseif ($data_type == 23) {
2603 $tmp = explode('|', $currvalue);
2605 foreach ($tmp as $value) {
2606 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2607 $avalue[$matches[1]] = $matches[2];
2611 $lres = sqlStatement("SELECT * FROM list_options " .
2612 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2613 while ($lrow = sqlFetchArray($lres)) {
2614 $option_id = $lrow['option_id'];
2615 $restype = substr($avalue[$option_id], 0, 1);
2616 $resnote = substr($avalue[$option_id], 2);
2617 if (empty($restype) && empty($resnote)) {
2621 if ($restype != '2') {
2622 continue; // show abnormal results only
2629 $s .= xl_list_label($lrow['title']);
2630 if (!empty($resnote)) {
2631 $s .= ': ' . $resnote;
2634 } // the list of active allergies for the current patient
2635 elseif ($data_type == 24) {
2636 $query = "SELECT title, comments FROM lists WHERE " .
2637 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2639 $lres = sqlStatement($query, array($GLOBALS['pid']));
2641 while ($lrow = sqlFetchArray($lres)) {
2646 $s .= $lrow['title'];
2647 if ($lrow['comments']) {
2648 $s .= ' (' . $lrow['comments'] . ')';
2651 } // a set of labeled checkboxes, each with a text field:
2652 elseif ($data_type == 25) {
2653 $tmp = explode('|', $currvalue);
2655 foreach ($tmp as $value) {
2656 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2657 $avalue[$matches[1]] = $matches[2];
2661 $lres = sqlStatement("SELECT * FROM list_options " .
2662 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2663 while ($lrow = sqlFetchArray($lres)) {
2664 $option_id = $lrow['option_id'];
2665 $restype = substr($avalue[$option_id], 0, 1);
2666 $resnote = substr($avalue[$option_id], 2);
2667 if (empty($restype) && empty($resnote)) {
2675 $s .= xl_list_label($lrow['title']);
2676 $restype = $restype ?
xl('Yes') : xl('No');
2679 $s .= ' ' . $resnote;
2682 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2683 // VicarePlus :: A selection list for smoking status.
2684 elseif ($data_type == 28 ||
$data_type == 32) {
2685 $tmp = explode('|', $currvalue);
2686 $resnote = count($tmp) > 0 ?
$tmp[0] : '';
2687 $restype = count($tmp) > 1 ?
$tmp[1] : '';
2688 $resdate = count($tmp) > 2 ?
oeFormatShortDate($tmp[2]) : '';
2689 $reslist = count($tmp) > 3 ?
$tmp[3] : '';
2691 if ($restype == "current" . $field_id) {
2692 $res = xl('Current');
2695 if ($restype == "quit" . $field_id) {
2699 if ($restype == "never" . $field_id) {
2703 if ($restype == "not_applicable". $field_id) {
2707 if ($data_type == 28) {
2708 if (!empty($resnote)) {
2711 } // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2712 elseif ($data_type == 32) {
2713 if (!empty($reslist)) {
2714 $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
2717 if (!empty($resnote)) {
2718 $s .= ' ' . $resnote;
2727 $s .= xl('Status') . ' ' . $res;
2730 if ($restype == "quit".$field_id) {
2738 // Supports backup lists
2739 elseif ($data_type == 36) {
2740 $values_array = explode("|", $currvalue);
2743 foreach ($values_array as $value) {
2744 $lrow = sqlQuery("SELECT title FROM list_options " .
2745 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2747 if ($lrow == 0 && !empty($backup_list)) {
2749 $lrow = sqlQuery("SELECT title FROM list_options " .
2750 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2754 $s = $s . ", " . xl_list_label($lrow['title']);
2756 $s = xl_list_label($lrow['title']);
2766 $CPR = 4; // cells per row of generic data
2771 function disp_end_cell()
2773 global $item_count, $cell_count;
2774 if ($item_count > 0) {
2780 function disp_end_row()
2782 global $cell_count, $CPR;
2784 if ($cell_count > 0) {
2785 for (; $cell_count < $CPR;
2795 function disp_end_group()
2798 if (strlen($last_group) > 0) {
2803 // Accumulate action conditions into a JSON expression for the browser side.
2804 function accumActionConditions($field_id, &$condition_str, &$condarr)
2806 $conditions = empty($condarr) ?
array() : unserialize($condarr);
2808 foreach ($conditions as $key => $condition) {
2809 if ($key === 'action') {
2810 // If specified this should be the first array item.
2812 $action = $condition;
2816 if (empty($condition['id'])) {
2819 $andor = empty($condition['andor']) ?
'' : $condition['andor'];
2820 if ($condition_str) {
2821 $condition_str .= ",\n";
2823 $condition_str .= "{" .
2824 "target:" . js_escape($field_id) . ", " .
2825 "action:" . js_escape($action) . ", " .
2826 "id:" . js_escape($condition['id']) . ", " .
2827 "itemid:" . js_escape($condition['itemid']) . ", " .
2828 "operator:" . js_escape($condition['operator']) . ", " .
2829 "value:" . js_escape($condition['value']) . ", " .
2830 "andor:" . js_escape($andor) . "}";
2834 // This checks if the given field with the given value should have an action applied.
2835 // Originally the only action was skip, but now you can also set the field to a specified value.
2836 // It somewhat mirrors the checkSkipConditions function in options.js.php.
2837 // If you use this for multiple layouts in the same script, you should
2838 // clear $sk_layout_items before each layout.
2839 function isSkipped(&$frow, $currvalue)
2841 global $sk_layout_items;
2843 // Accumulate an array of the encountered fields and their values.
2844 // It is assumed that fields appear before they are tested by another field.
2845 // TBD: Bad assumption?
2846 $field_id = $frow['field_id'];
2847 if (!is_array($sk_layout_items)) {
2848 $sk_layout_items = array();
2850 $sk_layout_items[$field_id] = array('row' => $frow, 'value' => $currvalue);
2852 if (empty($frow['conditions'])) {
2856 $skiprows = unserialize($frow['conditions']);
2859 $datatype = $frow['data_type'];
2860 $action = 'skip'; // default action if none specified
2862 foreach ($skiprows as $key => $skiprow) {
2863 // id referenced field id
2864 // itemid referenced array key if applicable
2865 // operator "eq", "ne", "se" or "ns"
2866 // value if eq or ne, some string to compare with
2867 // andor "and", "or" or empty
2869 if ($key === 'action') {
2870 // Action value is a string. It can be "skip", or "value=" followed by a value.
2875 if (empty($skiprow['id'])) {
2879 $id = $skiprow['id'];
2880 if (!isset($sk_layout_items[$id])) {
2881 error_log("Function isSkipped() cannot find skip source field '$id'.");
2884 $itemid = $skiprow['itemid'];
2885 $operator = $skiprow['operator'];
2886 $skipval = $skiprow['value'];
2887 $srcvalue = $sk_layout_items[$id]['value'];
2888 $src_datatype = $sk_layout_items[$id]['row']['data_type'];
2889 $src_list_id = $sk_layout_items[$id]['row']['list_id'];
2891 // Some data types use itemid and we have to dig for their value.
2892 if ($src_datatype == 21 && $src_list_id) { // array of checkboxes
2893 $tmp = explode('|', $srcvalue);
2894 $srcvalue = in_array($itemid, $tmp);
2895 } elseif ($src_datatype == 22 ||
$src_datatype == 23 ||
$src_datatype == 25) {
2896 $tmp = explode('|', $srcvalue);
2898 foreach ($tmp as $tmp2) {
2899 if (strpos($tmp2, "$itemid:") === 0) {
2900 if ($datatype == 22) {
2901 $srcvalue = substr($tmp2, strlen($itemid) +
1);
2903 $srcvalue = substr($tmp2, strlen($itemid) +
1, 1);
2909 // Compute the result of the test for this condition row.
2910 // PHP's looseness with variable type conversion helps us here.
2912 if ($operator == 'eq') {
2913 $condition = $srcvalue == $skipval;
2914 } elseif ($operator == 'ne') {
2915 $condition = $srcvalue != $skipval;
2916 } elseif ($operator == 'se') {
2917 $condition = $srcvalue == true;
2918 } elseif ($operator == 'ns') {
2919 $condition = $srcvalue != true;
2921 error_log("Unknown skip operator '$operator' for field '$field_id'.");
2924 // Logic to accumulate multiple conditions for the same target.
2925 if ($prevandor == 'and') {
2926 $condition = $condition && $prevcond;
2927 } elseif ($prevandor == 'or') {
2928 $condition = $condition ||
$prevcond;
2930 $prevandor = $skiprow['andor'];
2931 $prevcond = $condition;
2933 return $prevcond ?
$action : '';
2936 // Load array of names of the given layout and its groups.
2937 function getLayoutProperties($formtype, &$grparr, $sel = "grp_title")
2939 if ($sel != '*' && strpos($sel, 'grp_group_id') === false) {
2940 $sel = "grp_group_id, $sel";
2942 $gres = sqlStatement("SELECT $sel FROM layout_group_properties WHERE grp_form_id = ? " .
2943 "ORDER BY grp_group_id", array($formtype));
2944 while ($grow = sqlFetchArray($gres)) {
2945 $grparr[$grow['grp_group_id']] = $grow;
2949 function display_layout_rows($formtype, $result1, $result2 = '')
2951 global $item_count, $cell_count, $last_group, $CPR;
2954 getLayoutProperties($formtype, $grparr, '*');
2956 $TOPCPR = empty($grparr['']['grp_columns']) ?
4 : $grparr['']['grp_columns'];
2958 $fres = sqlStatement("SELECT * FROM layout_options " .
2959 "WHERE form_id = ? AND uor > 0 " .
2960 "ORDER BY group_id, seq", array($formtype));
2962 while ($frow = sqlFetchArray($fres)) {
2963 $this_group = $frow['group_id'];
2964 $titlecols = $frow['titlecols'];
2965 $datacols = $frow['datacols'];
2966 $data_type = $frow['data_type'];
2967 $field_id = $frow['field_id'];
2968 $list_id = $frow['list_id'];
2970 $jump_new_row = isOption($frow['edit_options'], 'J');
2971 $prepend_blank_row = isOption($frow['edit_options'], 'K');
2973 $CPR = empty($grparr[$this_group]['grp_columns']) ?
$TOPCPR : $grparr[$this_group]['grp_columns'];
2975 if ($formtype == 'DEM') {
2976 if (strpos($field_id, 'em_') === 0) {
2977 // Skip employer related fields, if it's disabled.
2978 if ($GLOBALS['omit_employers']) {
2982 $tmp = substr($field_id, 3);
2983 if (isset($result2[$tmp])) {
2984 $currvalue = $result2[$tmp];
2987 if (isset($result1[$field_id])) {
2988 $currvalue = $result1[$field_id];
2992 if (isset($result1[$field_id])) {
2993 $currvalue = $result1[$field_id];
2997 // Handle a data category (group) change.
2998 if (strcmp($this_group, $last_group) != 0) {
2999 $group_name = $grparr[$this_group]['grp_title'];
3000 // totally skip generating the employer category, if it's disabled.
3001 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3006 $last_group = $this_group;
3009 // filter out all the empty field data from the patient report.
3010 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
3011 // Handle starting of a new row.
3012 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0 ||
$prepend_blank_row ||
$jump_new_row) {
3014 if ($prepend_blank_row) {
3015 echo "<tr><td class='label' colspan='" . ($CPR +
1) . "'> </td></tr>\n";
3019 echo "<td class='groupname'>";
3020 echo text(xl_layout_label($group_name));
3023 echo "<td valign='top'> ";
3029 if ($item_count == 0 && $titlecols == 0) {
3033 // Handle starting of a new label cell.
3034 if ($titlecols > 0) {
3036 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
3037 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES
);
3038 echo "<td class='label_custom' colspan='$titlecols_esc' ";
3039 //if ($cell_count == 2) echo " style='padding-left:10pt'";
3041 $cell_count +
= $titlecols;
3046 // Added 5-09 by BM - Translate label if applicable
3047 if ($frow['title']) {
3048 $tmp = xl_layout_label($frow['title']);
3050 // Append colon only if label does not end with punctuation.
3051 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3058 // Handle starting of a new data cell.
3059 if ($datacols > 0) {
3061 //echo "<td class='text data' colspan='$datacols' valign='top'";
3062 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES
);
3063 echo "<td class='text data' colspan='$datacols_esc'";
3064 //if ($cell_count > 0) echo " style='padding-left:5pt'";
3066 $cell_count +
= $datacols;
3070 echo generate_display_field($frow, $currvalue);
3077 function display_layout_tabs($formtype, $result1, $result2 = '')
3079 global $item_count, $cell_count, $last_group, $CPR;
3082 getLayoutProperties($formtype, $grparr);
3084 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3085 "WHERE form_id = ? AND uor > 0 " .
3086 "ORDER BY group_id", array($formtype));
3089 while ($frow = sqlFetchArray($fres)) {
3090 $this_group = $frow['group_id'];
3091 // $group_name = substr($this_group, 1);
3092 $group_name = $grparr[$this_group]['grp_title'];
3093 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3097 <li
<?php
echo $first ?
'class="current"' : '' ?
>>
3098 <a href
="#" id
="header_tab_<?php echo attr($group_name); ?>">
3099 <?php
echo text(xl_layout_label($group_name)); ?
></a
>
3106 function display_layout_tabs_data($formtype, $result1, $result2 = '')
3108 global $item_count, $cell_count, $last_group, $CPR;
3111 getLayoutProperties($formtype, $grparr, '*');
3113 $TOPCPR = empty($grparr['']['grp_columns']) ?
4 : $grparr['']['grp_columns'];
3115 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3116 "WHERE form_id = ? AND uor > 0 " .
3117 "ORDER BY group_id", array($formtype));
3120 while ($frow = sqlFetchArray($fres)) {
3121 $this_group = isset($frow['group_id']) ?
$frow['group_id'] : "" ;
3123 if ($grparr[$this_group]['grp_columns'] === 'Employer' && $GLOBALS['omit_employers']) {
3126 $CPR = empty($grparr[$this_group]['grp_columns']) ?
$TOPCPR : $grparr[$this_group]['grp_columns'];
3127 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ?
'' : xl_layout_label($grparr[$this_group]['grp_subtitle']);
3129 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3130 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3131 "ORDER BY seq", array($formtype, $this_group));
3134 <div
class="tab <?php echo $first ? 'current' : '' ?>">
3135 <table border
='0' cellpadding
='0'>
3138 while ($group_fields = sqlFetchArray($group_fields_query)) {
3139 $titlecols = $group_fields['titlecols'];
3140 $datacols = $group_fields['datacols'];
3141 $data_type = $group_fields['data_type'];
3142 $field_id = $group_fields['field_id'];
3143 $list_id = $group_fields['list_id'];
3145 $edit_options = $group_fields['edit_options'];
3146 $jump_new_row = isOption($edit_options, 'J');
3147 $prepend_blank_row = isOption($edit_options, 'K');
3149 if ($formtype == 'DEM') {
3150 if (strpos($field_id, 'em_') === 0) {
3151 // Skip employer related fields, if it's disabled.
3152 if ($GLOBALS['omit_employers']) {
3156 $tmp = substr($field_id, 3);
3157 if (isset($result2[$tmp])) {
3158 $currvalue = $result2[$tmp];
3161 if (isset($result1[$field_id])) {
3162 $currvalue = $result1[$field_id];
3166 if (isset($result1[$field_id])) {
3167 $currvalue = $result1[$field_id];
3171 // Skip this field if action conditions call for that.
3172 // Note this also accumulates info for subsequent skip tests.
3173 $skip_this_field = isSkipped($group_fields, $currvalue) == 'skip';
3175 // Skip this field if its do-not-print option is set.
3176 if (isOption($edit_options, 'X') !== false) {
3177 $skip_this_field = true;
3180 // Handle a data category (group) change.
3181 if (strcmp($this_group, $last_group) != 0) {
3182 $group_name = $grparr[$this_group]['grp_title'];
3183 // totally skip generating the employer category, if it's disabled.
3184 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3187 $last_group = $this_group;
3190 // Handle starting of a new row.
3191 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0 ||
$prepend_blank_row ||
$jump_new_row) {
3194 // Group subtitle exists and is not displayed yet.
3195 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3196 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3199 if ($prepend_blank_row) {
3200 echo "<tr><td class='label' colspan='$CPR'> </td></tr>\n";
3205 if ($item_count == 0 && $titlecols == 0) {
3209 // Handle starting of a new label cell.
3210 if ($titlecols > 0) {
3212 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES
);
3213 $field_id_label = 'label_'.$group_fields['field_id'];
3214 echo "<td class='label_custom' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
3216 $cell_count +
= $titlecols;
3221 $field_id_label = 'label_'.$group_fields['field_id'];
3222 echo "<span id='".attr($field_id_label)."'>";
3223 if ($skip_this_field) {
3224 // No label because skipping
3225 } elseif ($group_fields['title']) {
3226 $tmp = xl_layout_label($group_fields['title']);
3228 // Append colon only if label does not end with punctuation.
3229 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3237 // Handle starting of a new data cell.
3238 if ($datacols > 0) {
3240 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES
);
3241 $field_id = 'text_'.$group_fields['field_id'];
3242 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
3243 if (!$skip_this_field && $data_type == 3) {
3244 // Textarea gets a light grey border.
3245 echo " style='border:1px solid #cccccc'";
3248 $cell_count +
= $datacols;
3250 $field_id = 'text_'.$group_fields['field_id'];
3251 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
3255 if (!$skip_this_field) {
3256 echo generate_display_field($group_fields, $currvalue);
3272 function display_layout_tabs_data_editable($formtype, $result1, $result2 = '')
3274 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
3277 getLayoutProperties($formtype, $grparr, '*');
3279 $TOPCPR = empty($grparr['']['grp_columns']) ?
4 : $grparr['']['grp_columns'];
3281 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3282 "WHERE form_id = ? AND uor > 0 " .
3283 "ORDER BY group_id", array($formtype));
3286 $condition_str = '';
3288 while ($frow = sqlFetchArray($fres)) {
3289 $this_group = $frow['group_id'];
3290 $group_name = $grparr[$this_group]['grp_title'];
3291 $group_name_esc = text($group_name);
3293 if ($grparr[$this_group]['grp_title'] === 'Employer' && $GLOBALS['omit_employers']) {
3296 $CPR = empty($grparr[$this_group]['grp_columns']) ?
$TOPCPR : $grparr[$this_group]['grp_columns'];
3297 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ?
'' : xl_layout_label($grparr[$this_group]['grp_subtitle']);
3299 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3300 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3301 "ORDER BY seq", array($formtype, $this_group));
3304 <div
class="tab <?php echo $first ? 'current' : '' ?>" id
="tab_<?php echo str_replace(' ', '_', $group_name_esc)?>" >
3305 <table border
='0' cellpadding
='0'>
3308 while ($group_fields = sqlFetchArray($group_fields_query)) {
3309 $titlecols = $group_fields['titlecols'];
3310 $datacols = $group_fields['datacols'];
3311 $data_type = $group_fields['data_type'];
3312 $field_id = $group_fields['field_id'];
3313 $list_id = $group_fields['list_id'];
3314 $backup_list = $group_fields['list_backup_id'];
3317 $jump_new_row = isOption($group_fields['edit_options'], 'J');
3318 $prepend_blank_row = isOption($group_fields['edit_options'], 'K');
3320 // Accumulate action conditions into a JSON expression for the browser side.
3321 accumActionConditions($field_id, $condition_str, $group_fields['conditions']);
3323 if ($formtype == 'DEM') {
3324 if (strpos($field_id, 'em_') === 0) {
3325 // Skip employer related fields, if it's disabled.
3326 if ($GLOBALS['omit_employers']) {
3330 $tmp = substr($field_id, 3);
3331 if (isset($result2[$tmp])) {
3332 $currvalue = $result2[$tmp];
3335 if (isset($result1[$field_id])) {
3336 $currvalue = $result1[$field_id];
3340 if (isset($result1[$field_id])) {
3341 $currvalue = $result1[$field_id];
3345 // Handle a data category (group) change.
3346 if (strcmp($this_group, $last_group) != 0) {
3347 // totally skip generating the employer category, if it's disabled.
3348 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3352 $last_group = $this_group;
3355 // Handle starting of a new row.
3356 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0 ||
$prepend_blank_row ||
$jump_new_row) {
3359 // Group subtitle exists and is not displayed yet.
3360 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3361 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3364 if ($prepend_blank_row) {
3365 echo "<tr><td class='label' colspan='$CPR'> </td></tr>\n";
3370 if ($item_count == 0 && $titlecols == 0) {
3374 // Handle starting of a new label cell.
3375 if ($titlecols > 0) {
3377 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES
);
3378 $field_id_label = 'label_'.$group_fields['field_id'];
3379 echo "<td class='label_custom' colspan='$titlecols_esc'";
3380 // This ID is used by skip conditions.
3381 echo " id='label_id_" . attr($field_id) . "'";
3383 $cell_count +
= $titlecols;
3388 if ($group_fields['title']) {
3389 $tmp = xl_layout_label($group_fields['title']);
3391 // Append colon only if label does not end with punctuation.
3392 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3399 // Handle starting of a new data cell.
3400 if ($datacols > 0) {
3402 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES
);
3403 $field_id = 'text_'.$group_fields['field_id'];
3404 echo "<td class='text data' colspan='$datacols_esc'";
3405 // This ID is used by action conditions.
3406 echo " id='value_id_" . attr($field_id) . "'";
3408 $cell_count +
= $datacols;
3413 echo generate_form_field($group_fields, $currvalue);
3426 // From the currently posted HTML form, this gets the value of the
3427 // field corresponding to the provided layout_options table row.
3429 function get_layout_form_value($frow, $prefix = 'form_')
3431 $maxlength = empty($frow['max_length']) ?
0 : intval($frow['max_length']);
3432 $data_type = $frow['data_type'];
3433 $field_id = $frow['field_id'];
3435 if (isset($_POST["$prefix$field_id"])) {
3436 if ($data_type == 4) {
3437 $modtmp = isOption($frow['edit_options'], 'F') === false ?
0 : 1;
3439 $value = DateToYYYYMMDD($_POST["$prefix$field_id"]);
3441 $value = DateTimeToYYYYMMDDHHMMSS($_POST["$prefix$field_id"]);
3443 } elseif ($data_type == 21) {
3444 if (!$frow['list_id']) {
3445 if (!empty($_POST["form_$field_id"])) {
3446 $value = xlt('Yes');
3449 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
3450 // must be concatenated into a |-separated string.
3451 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3452 if (strlen($value)) {
3458 } elseif ($data_type == 22) {
3459 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
3460 // into "key:value|key:value|...".
3461 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3462 $val = str_replace('|', ' ', $val);
3463 if (strlen($value)) {
3467 $value .= "$key:$val";
3469 } elseif ($data_type == 23) {
3470 // $_POST["$prefix$field_id"] is an array of text fields with companion
3471 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
3472 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3473 $restype = $_POST["radio_{$field_id}"][$key];
3474 if (empty($restype)) {
3478 $val = str_replace('|', ' ', $val);
3479 if (strlen($value)) {
3483 $value .= "$key:$restype:$val";
3485 } elseif ($data_type == 25) {
3486 // $_POST["$prefix$field_id"] is an array of text fields with companion
3487 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
3488 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3489 $restype = empty($_POST["check_{$field_id}"][$key]) ?
'0' : '1';
3490 $val = str_replace('|', ' ', $val);
3491 if (strlen($value)) {
3495 $value .= "$key:$restype:$val";
3497 } elseif ($data_type == 28 ||
$data_type == 32) {
3498 // $_POST["$prefix$field_id"] is an date text fields with companion
3499 // radio buttons to be imploded into "notes|type|date".
3500 $restype = $_POST["radio_{$field_id}"];
3501 if (empty($restype)) {
3505 $resdate = DateToYYYYMMDD(str_replace('|', ' ', $_POST["date_$field_id"]));
3506 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3507 if ($data_type == 32) {
3508 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
3509 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3510 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
3511 $value = "$res_text_note|$restype|$resdate|$reslist";
3513 $value = "$resnote|$restype|$resdate";
3515 } elseif ($data_type == 36) {
3516 $value_array = $_POST["form_$field_id"];
3518 foreach ($value_array as $key => $valueofkey) {
3520 $value = $valueofkey;
3522 $value = $value . "|" . $valueofkey;
3528 $value = $_POST["$prefix$field_id"];
3532 // Better to die than to silently truncate data!
3533 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength) {
3534 die(htmlspecialchars(xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES
) .
3535 ":<br /> <br />".htmlspecialchars($value, ENT_NOQUOTES
));
3538 return trim($value);
3541 // Generate JavaScript validation logic for the required fields.
3543 function generate_layout_validation($form_id)
3545 $fres = sqlStatement("SELECT * FROM layout_options " .
3546 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
3547 "ORDER BY group_id, seq", array($form_id));
3549 while ($frow = sqlFetchArray($fres)) {
3550 $data_type = $frow['data_type'];
3551 $field_id = $frow['field_id'];
3552 $fldtitle = $frow['title'];
3554 $fldtitle = $frow['description'];
3557 $fldname = attr("form_$field_id");
3559 if ($data_type == 40) {
3560 $fldid = "form_" . $field_id;
3561 // Move canvas image data to its hidden form field so the server will get it.
3563 " var canfld = f[" . js_escape($fldid) . "];\n" .
3564 " if (canfld) canfld.value = lbfCanvasGetData(" . js_escape($fldid) . ");\n";
3568 if ($frow['uor'] < 2) {
3572 echo " if (f.$fldname && !f.$fldname.disabled) {\n";
3573 switch ($data_type) {
3581 " if (f.$fldname.selectedIndex <= 0) {\n" .
3582 " alert(" . xlj('Please choose a value for') . " + " .
3583 "\":\\n\" + " . js_escape(xl_layout_label($fldtitle)) . ");\n" .
3584 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3585 " return false;\n" .
3590 " if (f.$fldname.selectedIndex <= 0) {\n" .
3591 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3592 " errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3595 case 27: // radio buttons
3598 " for (; i < f.$fldname.length; ++i) if (f.{$fldname}[i].checked) break;\n" .
3599 " if (i >= f.$fldname.length) {\n" .
3600 " alert(" . xlj('Please choose a value for') . " + " .
3601 "\":\\n\" + " . js_escape(xl_layout_label($fldtitle)) . ");\n" .
3602 " return false;\n" .
3610 " if (trimlen(f.$fldname.value) == 0) {\n" .
3611 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3612 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
3613 " $('#" . $fldname . "').attr('style','background:red'); \n" .
3614 " errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3616 " $('#" . $fldname . "').attr('style',''); " .
3617 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
3620 case 36: // multi select
3622 " var multi_select=f['$fldname"."[]']; \n " .
3623 " var multi_choice_made=false; \n".
3624 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
3625 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
3627 " if(!multi_choice_made)
3628 errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3637 * DROPDOWN FOR FACILITIES
3639 * build a dropdown with all facilities
3641 * @param string $selected - name of the currently selected facility
3642 * use '0' for "unspecified facility"
3643 * use '' for "All facilities" (the default)
3644 * @param string $name - the name/id for select form (defaults to "form_facility")
3645 * @param boolean $allow_unspecified - include an option for "unspecified" facility
3647 * @return void - just echo the html encoded string
3649 * Note: This should become a data-type at some point, according to Brady
3651 function dropdown_facility(
3653 $name = 'form_facility',
3654 $allow_unspecified = true,
3655 $allow_allfacilities = true,
3660 global $facilityService;
3662 $have_selected = false;
3663 $fres = $facilityService->getAll();
3665 echo " <select class='form-control' name='" . attr($name) . "' id='" . attr($name) . "'";
3667 echo " onchange='$onchange'";
3670 echo " $disabled>\n";
3672 if ($allow_allfacilities) {
3674 $option_selected_attr = '';
3675 if ($selected == '') {
3676 $option_selected_attr = ' selected="selected"';
3677 $have_selected = true;
3680 $option_content = '-- ' . xl('All Facilities') . ' --';
3681 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3682 } elseif ($allow_unspecified) {
3683 $option_value = '0';
3684 $option_selected_attr = '';
3685 if ($selected == '0') {
3686 $option_selected_attr = ' selected="selected"';
3687 $have_selected = true;
3690 $option_content = '-- ' . xl('Unspecified') . ' --';
3691 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3694 foreach ($fres as $frow) {
3695 $facility_id = $frow['id'];
3696 $option_value = $facility_id;
3697 $option_selected_attr = '';
3698 if ($selected == $facility_id) {
3699 $option_selected_attr = ' selected="selected"';
3700 $have_selected = true;
3703 $option_content = $frow['name'];
3704 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3707 if ($allow_unspecified && $allow_allfacilities) {
3708 $option_value = '0';
3709 $option_selected_attr = '';
3710 if ($selected == '0') {
3711 $option_selected_attr = ' selected="selected"';
3712 $have_selected = true;
3715 $option_content = '-- ' . xl('Unspecified') . ' --';
3716 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3719 if (!$have_selected) {
3720 $option_value = $selected;
3721 $option_label = '(' . xl('Do not change') . ')';
3722 $option_content = xl('Missing or Invalid');
3723 echo " <option value='" . attr($option_value) . "' label='" . attr($option_label) . "' selected='selected'>" . text($option_content) . "</option>\n";
3726 echo " </select>\n";
3729 // Expand Collapse Widget
3730 // This forms the header and functionality component of the widget. The information that is displayed
3731 // then follows this function followed by a closing div tag
3733 // $title is the title of the section (already translated)
3734 // $label is identifier used in the tag id's and sql columns
3735 // $buttonLabel is the button label text (already translated)
3736 // $buttonLink is the button link information
3737 // $buttonClass is any additional needed class elements for the button tag
3738 // $linkMethod is the button link method ('javascript' vs 'html')
3739 // $bodyClass is to set class(es) of the body
3740 // $auth is a flag to decide whether to show the button
3741 // $fixedWidth is to flag whether width is fixed
3742 // $forceExpandAlways is a flag to force the widget to always be expanded
3744 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways = false)
3747 echo "<div class='section-header'>";
3749 echo "<div class='section-header-dynamic'>";
3754 // show button, since authorized
3755 // first prepare class string
3757 $class_string = "css_button_small " . $buttonClass;
3759 $class_string = "css_button_small";
3762 // next, create the link
3763 if ($linkMethod == "javascript") {
3764 echo "<td><a class='" . attr($class_string) . "' href='javascript:;' onclick='" . $buttonLink . "'";
3766 echo "<td><a class='" . attr($class_string) . "' href='" . $buttonLink . "'";
3767 if (!isset($_SESSION['patient_portal_onsite_two'])) {
3768 // prevent an error from occuring when calling the function from the patient portal
3769 echo " onclick='top.restoreSession()'";
3774 text($buttonLabel) . "</span></a></td>";
3777 if ($forceExpandAlways) {
3778 // Special case to force the widget to always be expanded
3779 echo "<td><span class='text'><b>" . text($title) . "</b></span>";
3780 $indicatorTag ="style='display:none'";
3783 $indicatorTag = isset($indicatorTag) ?
$indicatorTag : "";
3784 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this," .
3785 attr_js($label."_ps_expand") . ")'><span class='text'><b>";
3786 echo text($title) . "</b></span>";
3788 if (isset($_SESSION['patient_portal_onsite_two'])) {
3789 // collapse all entries in the patient portal
3790 $text = xl('expand');
3791 } elseif (getUserSetting($label."_ps_expand")) {
3792 $text = xl('collapse');
3794 $text = xl('expand');
3797 echo " (<span class='indicator'>" . text($text) .
3798 "</span>)</a></td>";
3799 echo "</tr></table>";
3801 if ($forceExpandAlways) {
3802 // Special case to force the widget to always be expanded
3804 } elseif (isset($_SESSION['patient_portal_onsite_two'])) {
3805 // collapse all entries in the patient portal
3806 $styling = "style='display:none'";
3807 } elseif (getUserSetting($label."_ps_expand")) {
3810 $styling = "style='display:none'";
3814 $styling .= " class='" . attr($bodyClass) . "'";
3817 //next, create the first div tag to hold the information
3818 // note the code that calls this function will then place the ending div tag after the data
3819 echo "<div id='" . attr($label) . "_ps_expand' " . $styling . ">";
3822 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3823 function billing_facility($name, $select)
3825 global $facilityService;
3827 $fres = $facilityService->getAllBillingLocations();
3828 echo " <select id='".htmlspecialchars($name, ENT_QUOTES
)."' class='form-control' name='".htmlspecialchars($name, ENT_QUOTES
)."'>";
3829 foreach ($fres as $facrow) {
3830 $selected = ( $facrow['id'] == $select ) ?
'selected="selected"' : '' ;
3831 echo "<option value=".htmlspecialchars($facrow['id'], ENT_QUOTES
)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES
)."</option>";
3837 // Generic function to get the translated title value for a particular list option.
3839 function getListItemTitle($list, $option)
3841 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3842 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3843 if (empty($row['title'])) {
3847 return xl_list_label($row['title']);
3850 //function to get the translated title value in Patient Transactions
3851 function getLayoutTitle($list, $option)
3853 $row = sqlQuery("SELECT grp_title FROM layout_group_properties " .
3854 "WHERE grp_mapping = ? AND grp_form_id = ? ", array($list, $option));
3856 if (empty($row['grp_title'])) {
3859 return xl_list_label($row['grp_title']);
3861 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3862 function getSmokeCodes()
3864 $smoking_codes_arr = array();
3865 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3866 while ($codes_row = sqlFetchArray($smoking_codes)) {
3867 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3870 return $smoking_codes_arr;
3873 // Get the current value for a layout based form field.
3874 // Depending on options this might come from lbf_data, patient_data,
3875 // form_encounter, shared_attributes or elsewhere.
3876 // Returns FALSE if the field ID is invalid (layout error).
3878 function lbf_current_value($frow, $formid, $encounter)
3881 $formname = $frow['form_id'];
3882 $field_id = $frow['field_id'];
3883 $source = $frow['source'];
3885 $deffname = $formname . '_default_' . $field_id;
3886 if ($source == 'D' ||
$source == 'H') {
3887 // Get from patient_data, employer_data or history_data.
3888 if ($source == 'H') {
3889 $table = 'history_data';
3890 $orderby = 'ORDER BY date DESC LIMIT 1';
3891 } elseif (strpos($field_id, 'em_') === 0) {
3892 $field_id = substr($field_id, 3);
3893 $table = 'employer_data';
3894 $orderby = 'ORDER BY date DESC LIMIT 1';
3896 $table = 'patient_data';
3900 // It is an error if the field does not exist, but don't crash.
3901 $tmp = sqlQuery("SHOW COLUMNS FROM " . escape_table_name($table) . " WHERE Field = ?", array($field_id));
3906 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM " . escape_table_name($table) . " WHERE pid = ? $orderby", array($pid));
3907 if (isset($pdrow)) {
3908 $currvalue = $pdrow['field_value'];
3910 } elseif ($source == 'E') {
3913 // Get value from shared_attributes of the current encounter.
3915 "SELECT field_value FROM shared_attributes WHERE " .
3916 "pid = ? AND encounter = ? AND field_id = ?",
3917 array($pid, $encounter, $field_id)
3919 if (!empty($sarow)) {
3920 $currvalue = $sarow['field_value'];
3922 } elseif ($formid) {
3923 // Get from shared_attributes of the encounter that this form is linked to.
3924 // Note the importance of having an index on forms.form_id.
3926 "SELECT sa.field_value " .
3927 "FROM forms AS f, shared_attributes AS sa WHERE " .
3928 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3929 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3930 array($formid, $formname, $field_id)
3932 if (!empty($sarow)) {
3933 $currvalue = $sarow['field_value'];
3936 // New form and encounter not available, this should not happen.
3938 if (empty($sarow) && !$formid) {
3939 // New form, see if there is a custom default from a plugin.
3940 if (function_exists($deffname)) {
3941 $currvalue = call_user_func($deffname);
3944 } elseif ($source == 'V') {
3946 // Get value from the current encounter's form_encounter.
3948 "SELECT * FROM form_encounter WHERE " .
3949 "pid = ? AND encounter = ?",
3950 array($pid, $encounter)
3952 if (isset($ferow[$field_id])) {
3953 $currvalue = $ferow[$field_id];
3955 } elseif ($formid) {
3956 // Get value from the form_encounter that this form is linked to.
3959 "FROM forms AS f, form_encounter AS fe WHERE " .
3960 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3961 "fe.pid = f.pid AND fe.encounter = f.encounter",
3962 array($formid, $formname)
3964 if (isset($ferow[$field_id])) {
3965 $currvalue = $ferow[$field_id];
3968 // New form and encounter not available, this should not happen.
3970 } elseif ($formid) {
3971 // This is a normal form field.
3972 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3973 "form_id = ? AND field_id = ?", array($formid, $field_id));
3974 if (!empty($ldrow)) {
3975 $currvalue = $ldrow['field_value'];
3978 // New form, see if there is a custom default from a plugin.
3979 if (function_exists($deffname)) {
3980 $currvalue = call_user_func($deffname);
3987 // This returns stuff that needs to go into the <head> section of a caller using
3988 // the drawable image field type in a form.
3989 // A TRUE argument makes the widget controls smaller.
3991 function lbf_canvas_head($small = true)
3994 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas/css/literallycanvas.css" rel="stylesheet" />
3995 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/build/react-with-addons.min.js"></script>
3996 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/build/react-dom.min.js"></script>
3997 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas/js/literallycanvas.min.js"></script>
4002 /* Custom LiterallyCanvas styling.
4003 * This makes the widget 25% less tall and adjusts some other things accordingly.
4006 min-height:100%;min-width:300px; /* Was 400, unspecified */
4008 .literally .lc-picker .toolbar-button {
4009 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
4011 .literally .color-well {
4012 font-size:8px;width:49px; /* Was 10, 60 */
4014 .literally .color-well-color-container {
4015 width:21px;height:21px; /* Was 28, 28 */
4017 .literally .lc-picker {
4018 width:50px; /* Was 61 */
4020 .literally .lc-drawing.with-gui {
4021 left:50px; /* Was 61 */
4023 .literally .lc-options {
4024 left:50px; /* Was 61 */
4026 .literally .color-picker-popup {
4027 left:49px;bottom:0px; /* Was 60, 31 */
4037 * Test if modifier($test) is in array of options for data type.
4039 * @param json array $options ["G","P","T"], ["G"] or could be legacy string with form "GPT", "G", "012"
4040 * @param string $test
4043 function isOption($options, $test)
4045 if (empty($options) ||
!isset($test) ||
$options == "null") {
4046 return false; // why bother?
4048 if (strpos($options, ',') === false) { // not json array of modifiers.
4049 // could be string of char's or single element of json ["RO"] or "TP" or "P" e.t.c.
4050 json_decode($options, true); // test if options json. json_last_error() will return JSON_ERROR_SYNTAX if not.
4051 // if of form ["RO"] (single modifier) means not legacy so continue on.
4052 if (is_string($options) && (json_last_error() !== JSON_ERROR_NONE
)) { // nope, it's string.
4053 $t = str_split(trim($options)); // very good chance it's legacy modifier string.
4054 $options = json_encode($t); // make it json array to convert from legacy to new modifier json schema.
4058 $options = json_decode($options, true); // all should now be json
4060 return !is_null($options) && in_array($test, $options, true) ?
true : false; // finally the truth!