2 // Copyright (C) 2007-2017 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 // Documentation for layout_options.edit_options:
21 // A = Age as years or "xx month(s)"
22 // B = Gestational age as "xx week(s) y day(s)"
23 // C = Capitalize first letter of each word (text fields)
24 // D = Check for duplicates in New Patient form
25 // G = Graphable (for numeric fields in forms supporting historical data)
26 // H = Read-only field copied from static history (this is obsolete)
27 // L = Lab Order ("ord_lab") types only (address book)
28 // N = Show in New Patient form
29 // O = Procedure Order ("ord_*") types only (address book)
30 // P = Default to previous value when current value is not yet set
31 // R = Distributor types only (address book)
32 // T = Use description as default Text
33 // U = Capitalize all letters (text fields)
34 // V = Vendor types only (address book)
35 // 0 = Read Only - the input element's "disabled" property is set
36 // 1 = Write Once (not editable when not empty) (text fields)
37 // 2 = Show descriptions instead of codes for billing code input
39 require_once("user.inc");
40 require_once("patient.inc");
41 require_once("lists.inc");
42 require_once(dirname(dirname(__FILE__
)) . "/custom/code_types.inc.php");
44 use OpenEMR\Services\FacilityService
;
46 $facilityService = new FacilityService();
50 function get_pharmacies()
52 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
53 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
54 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
55 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
57 "ORDER BY name, area_code, prefix, number");
60 function optionalAge($frow, $date, &$asof, $description = '')
67 $date = substr($date, 0, 10);
68 if (strpos($frow['edit_options'], 'A') !== false) {
70 } else if (strpos($frow['edit_options'], 'B') !== false) {
76 if (strpos($frow['form_id'], 'LBF') === 0) {
78 "SELECT date FROM form_encounter WHERE " .
79 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
80 array($GLOBALS['pid'], $GLOBALS['encounter'])
82 if (!empty($tmp['date'])) {
83 $asof = substr($tmp['date'], 0, 10);
86 if ($description === '') {
87 $prefix = ($format ?
xl('Gest age') : xl('Age')) . ' ';
89 $prefix = $description . ' ';
91 return $prefix . oeFormatAge($date, $asof, $format);
94 // Function to generate a drop-list.
96 function generate_select_list(
105 $custom_attributes = null,
111 $tag_name_esc = attr($tag_name);
114 $tag_name_esc = $tag_name_esc . "[]";
117 $s .= "<select name='$tag_name_esc'";
120 $s .= " multiple='multiple'";
123 $tag_id_esc = attr($tag_name);
126 $tag_id_esc = attr($tag_id);
129 $s .= " id='$tag_id_esc'";
131 if (!empty($class)) {
132 $class_esc = attr($class);
133 $s .= " class='form-control $class_esc'";
135 $s .= " class='form-control'";
139 $s .= " onchange='$onchange'";
142 if ($custom_attributes != null && is_array($custom_attributes)) {
143 foreach ($custom_attributes as $attr => $val) {
144 if (isset($custom_attributes [$attr])) {
145 $s .= " " . attr($attr) . "='" . attr($val) . "'";
150 $selectTitle = attr($title);
151 $s .= " title='$selectTitle'>";
152 $selectEmptyName = xlt($empty_name);
154 $s .= "<option value=''>" . $selectEmptyName . "</option>";
157 // List order depends on language translation options.
158 // (Note we do not need to worry about the list order in the algorithm
159 // after the below code block since that is where searches for exceptions
160 // are done which include inactive items or items from a backup
161 // list; note these will always be shown at the bottom of the list no matter the
163 $lang_id = empty($_SESSION['language_choice']) ?
'1' : $_SESSION['language_choice'];
165 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) ||
!$GLOBALS['translate_lists']) {
167 if ($GLOBALS['gb_how_sort_list'] == '0') {
169 $order_by_sql = "seq, title";
170 } else { //$GLOBALS['gb_how_sort_list'] == '1'
172 $order_by_sql = "title, seq";
175 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
178 if ($GLOBALS['gb_how_sort_list'] == '0') {
180 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
181 } else { //$GLOBALS['gb_how_sort_list'] == '1'
183 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
186 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
187 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
188 "FROM list_options AS lo " .
189 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
190 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
192 "WHERE lo.list_id = ? AND lo.activity=1 " .
193 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
196 $got_selected = false;
198 while ($lrow = sqlFetchArray($lres)) {
199 $selectedValues = explode("|", $currvalue);
201 $optionValue = attr($lrow ['option_id']);
202 $s .= "<option value='$optionValue'";
204 if ((strlen($currvalue) == 0 && $lrow ['is_default']) ||
(strlen($currvalue) > 0 && in_array($lrow ['option_id'], $selectedValues))) {
206 $got_selected = true;
209 // Already has been translated above (if applicable), so do not need to use
210 // the xl_list_label() function here
211 $optionLabel = text($lrow ['title']);
212 $s .= ">$optionLabel</option>\n";
216 To show the inactive item in the list if the value is saved to database
218 if (!$got_selected && strlen($currvalue) > 0) {
219 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
220 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
221 $lrow_inactive = sqlFetchArray($lres_inactive);
222 if ($lrow_inactive['option_id']) {
223 $optionValue = htmlspecialchars($lrow_inactive['option_id'], ENT_QUOTES
);
224 $s .= "<option value='$optionValue' selected>" . htmlspecialchars(xl_list_label($lrow_inactive['title']), ENT_NOQUOTES
) . "</option>\n";
225 $got_selected = true;
229 if (!$got_selected && strlen($currvalue) > 0 && !$multiple) {
230 $list_id = $backup_list;
231 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
233 if ($lrow > 0 && !empty($backup_list)) {
234 $selected = text(xl_list_label($lrow ['title']));
235 $s .= "<option value='$currescaped' selected> $selected </option>";
238 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
240 $fontTitle = xlt('Please choose a valid selection from the list.');
241 $fontText = xlt('Fix this');
242 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
244 } else if (!$got_selected && strlen($currvalue) > 0 && $multiple) {
245 //if not found in main list, display all selected values that exist in backup list
246 $list_id = $backup_list;
248 $got_selected_backup = false;
249 if (!empty($backup_list)) {
250 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
251 while ($lrow_backup = sqlFetchArray($lres_backup)) {
252 $selectedValues = explode("|", $currvalue);
254 $optionValue = attr($lrow_backup['option_id']);
256 if (in_array($lrow_backup ['option_id'], $selectedValues)) {
257 $s .= "<option value='$optionValue'";
259 $optionLabel = text(xl_list_label($lrow_backup ['title']));
260 $s .= ">$optionLabel</option>\n";
261 $got_selected_backup = true;
266 if (!$got_selected_backup) {
267 $selectedValues = explode("|", $currvalue);
268 foreach ($selectedValues as $selectedValue) {
269 $s .= "<option value='" . attr($selectedValue) . "'";
271 $s .= ">* " . text($selectedValue) . " *</option>\n";
275 $fontTitle = xlt('Please choose a valid selection from the list.');
276 $fontText = xlt('Fix this');
277 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
286 // Parsing for data type 31, static text.
287 function parse_static_text($frow)
289 $tmp = $frow['description'];
290 // Translate if it does not look like HTML.
291 if (substr($tmp, 0, 1) != '<') {
292 $tmp = nl2br(xl_layout_label($tmp));
295 if ($frow['source'] == 'D' ||
$frow['source'] == 'H') {
296 // Source is demographics or history. This case supports value substitution.
297 while (preg_match('/^(.*?)\{(\w+)\}(.*)$/', $tmp, $matches)) {
300 $tmprow['field_id'] = $matches[2];
301 $s .= lbf_current_value($tmprow, 0, 0);
309 // $frow is a row from the layout_options table.
310 // $currvalue is the current value, if any, of the associated item.
312 function generate_form_field($frow, $currvalue)
314 global $rootdir, $date_init, $ISSUE_TYPES, $code_types;
316 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
318 $data_type = $frow['data_type'];
319 $field_id = $frow['field_id'];
320 $list_id = $frow['list_id'];
321 $backup_list = $frow['list_backup_id'];
323 // escaped variables to use in html
324 $field_id_esc= htmlspecialchars($field_id, ENT_QUOTES
);
325 $list_id_esc = htmlspecialchars($list_id, ENT_QUOTES
);
327 // Added 5-09 by BM - Translate description if applicable
328 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
330 // Support edit option T which assigns the (possibly very long) description as
331 // the default value.
332 if (strpos($frow['edit_options'], 'T') !== false) {
333 if (strlen($currescaped) == 0) {
334 $currescaped = $description;
337 // Description used in this way is not suitable as a title.
341 // added 5-2009 by BM to allow modification of the 'empty' text title field.
342 // Can pass $frow['empty_title'] with this variable, otherwise
343 // will default to 'Unassigned'.
344 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
345 // if make $frow['empty_title'] equal to 'SKIP'
347 if (isset($frow['empty_title'])) {
348 if ($frow['empty_title'] == "SKIP") {
349 //do not display an 'empty' choice
351 $empty_title = "Unassigned";
353 $empty_title = $frow['empty_title'];
356 $empty_title = "Unassigned";
359 $disabled = strpos($frow['edit_options'], '0') === false ?
'' : 'disabled';
362 strpos($frow['form_id'], 'LBF') === 0 ||
363 strpos($frow['form_id'], 'LBT') === 0 ||
364 $frow['form_id'] == 'DEM' ||
365 $frow['form_id'] == 'HIS'
366 ) ?
"checkSkipConditions();" : "";
367 $lbfonchange = $lbfchange ?
"onchange='$lbfchange'" : "";
369 // generic single-selection list or Race and Ethnicity.
370 // These data types support backup lists.
371 if ($data_type == 1 ||
$data_type == 33) {
372 echo generate_select_list(
377 ($showEmpty ?
$empty_title : ''),
381 ($disabled ?
array('disabled' => 'disabled') : null),
385 } // simple text field
386 else if ($data_type == 2) {
387 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES
);
388 $maxlength = $frow['max_length'];
389 $string_maxlength = "";
390 // if max_length is set to zero, then do not set a maxlength
392 $string_maxlength = "maxlength='".attr($maxlength)."'";
395 echo "<input type='text'" .
396 " class='form-control'" .
397 " name='form_$field_id_esc'" .
398 " id='form_$field_id_esc'" .
399 " size='$fldlength'" .
400 " $string_maxlength" .
401 " title='$description'" .
402 " value='$currescaped'";
404 if (strpos($frow['edit_options'], 'C') !== false) {
405 $tmp .= "capitalizeMe(this);";
406 } else if (strpos($frow['edit_options'], 'U') !== false) {
407 $tmp .= "this.value = this.value.toUpperCase();";
411 echo " onchange='$tmp'";
414 $tmp = htmlspecialchars($GLOBALS['gbl_mask_patient_id'], ENT_QUOTES
);
415 // If mask is for use at save time, treat as no mask.
416 if (strpos($tmp, '^') !== false) {
419 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
420 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
421 echo " onblur='maskblur(this,\"$tmp\")'";
424 if (strpos($frow['edit_options'], '1') !== false && strlen($currescaped) > 0) {
433 } // long or multi-line text field
434 else if ($data_type == 3) {
435 $textCols = htmlspecialchars($frow['fld_length'], ENT_QUOTES
);
436 $textRows = htmlspecialchars($frow['fld_rows'], ENT_QUOTES
);
438 " name='form_$field_id_esc'" .
439 " class='form-control'" .
440 " id='form_$field_id_esc'" .
441 " title='$description'" .
442 " cols='$textCols'" .
443 " rows='$textRows' $lbfonchange $disabled" .
444 ">" . $currescaped . "</textarea>";
446 else if ($data_type == 4) {
447 $age_asof_date = ''; // optionalAge() sets this
448 $age_format = strpos($frow['edit_options'], 'A') === false ?
3 : 0;
449 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
451 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
454 $onchange_string = '';
455 if (!$disabled && $agestr) {
456 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') " .
457 "updateAgeString('$field_id','$age_asof_date', $age_format, '$description')\"";
460 echo "<input type='text' size='10' class='datepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
461 " value='" . substr($currescaped, 0, 10) . "'";
463 echo " title='$description'";
466 echo " $onchange_string $lbfonchange $disabled />";
468 // Optional display of age or gestational age.
470 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
472 } // provider list, local providers only
473 else if ($data_type == 10) {
474 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
475 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
476 "AND authorized = 1 " .
477 "ORDER BY lname, fname");
478 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
479 echo "<option value=''>" . xlt($empty_title) . "</option>";
480 $got_selected = false;
481 while ($urow = sqlFetchArray($ures)) {
482 $uname = text($urow['fname'] . ' ' . $urow['lname']);
483 $optionId = attr($urow['id']);
484 echo "<option value='$optionId'";
485 if ($urow['id'] == $currvalue) {
487 $got_selected = true;
490 echo ">$uname</option>";
493 if (!$got_selected && $currvalue) {
494 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
496 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
500 } // provider list, including address book entries with an NPI number
501 else if ($data_type == 11) {
502 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
503 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
504 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
505 "ORDER BY lname, fname");
506 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
507 echo " $lbfonchange $disabled>";
508 echo "<option value=''>" . xlt('Unassigned') . "</option>";
509 $got_selected = false;
510 while ($urow = sqlFetchArray($ures)) {
511 $uname = text($urow['fname'] . ' ' . $urow['lname']);
512 $optionId = attr($urow['id']);
513 echo "<option value='$optionId'";
514 if ($urow['id'] == $currvalue) {
516 $got_selected = true;
519 echo ">$uname</option>";
522 if (!$got_selected && $currvalue) {
523 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
525 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
530 else if ($data_type == 12) {
531 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
532 echo " $lbfonchange $disabled>";
533 echo "<option value='0'></option>";
534 $pres = get_pharmacies();
535 $got_selected = false;
536 while ($prow = sqlFetchArray($pres)) {
538 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
539 $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
540 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
541 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
542 echo "<option value='$optionValue'";
543 if ($currvalue == $key) {
545 $got_selected = true;
548 echo ">$optionLabel</option>";
551 if (!$got_selected && $currvalue) {
552 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
554 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
559 else if ($data_type == 13) {
560 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
561 echo " $lbfonchange $disabled>";
562 echo "<option value=''> </option>";
563 $squads = acl_get_squads();
565 foreach ($squads as $key => $value) {
566 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
567 $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES
);
568 echo "<option value='$optionValue'";
569 if ($currvalue == $key) {
573 echo ">$optionLabel</option>\n";
578 } // Address book, preferring organization name if it exists and is not in
579 // parentheses, and excluding local users who are not providers.
580 // Supports "referred to" practitioners and facilities.
581 // Alternatively the letter L in edit_options means that abook_type
582 // must be "ord_lab", indicating types used with the procedure
583 // lab ordering system.
584 // Alternatively the letter O in edit_options means that abook_type
585 // must begin with "ord_", indicating types used with the procedure
587 // Alternatively the letter V in edit_options means that abook_type
588 // must be "vendor", indicating the Vendor type.
589 // Alternatively the letter R in edit_options means that abook_type
590 // must be "dist", indicating the Distributor type.
591 else if ($data_type == 14) {
592 if (strpos($frow['edit_options'], 'L') !== false) {
593 $tmp = "abook_type = 'ord_lab'";
594 } else if (strpos($frow['edit_options'], 'O') !== false) {
595 $tmp = "abook_type LIKE 'ord\\_%'";
596 } else if (strpos($frow['edit_options'], 'V') !== false) {
597 $tmp = "abook_type LIKE 'vendor%'";
598 } else if (strpos($frow['edit_options'], 'R') !== false) {
599 $tmp = "abook_type LIKE 'dist'";
601 $tmp = "( username = '' OR authorized = 1 )";
604 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
605 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
607 "ORDER BY organization, lname, fname");
608 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
609 echo " $lbfonchange $disabled>";
610 echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
611 while ($urow = sqlFetchArray($ures)) {
612 $uname = $urow['organization'];
613 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
614 $uname = $urow['lname'];
615 if ($urow['fname']) {
616 $uname .= ", " . $urow['fname'];
620 $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES
);
621 $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES
);
622 echo "<option value='$optionValue'";
623 // Failure to translate Local and External is not an error here;
624 // they are only used as internal flags and must not be translated!
625 $title = $urow['username'] ?
'Local' : 'External';
626 $optionTitle = htmlspecialchars($title, ENT_QUOTES
);
627 echo " title='$optionTitle'";
628 if ($urow['id'] == $currvalue) {
632 echo ">$optionLabel</option>";
636 } // A billing code. If description matches an existing code type then that type is used.
637 else if ($data_type == 15) {
639 if (!empty($frow['description']) && isset($code_types[$frow['description']])) {
640 $codetype = $frow['description'];
642 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES
);
643 $maxlength = $frow['max_length'];
644 $string_maxlength = "";
645 // if max_length is set to zero, then do not set a maxlength
647 $string_maxlength = "maxlength='".attr($maxlength)."'";
651 if (strpos($frow['edit_options'], '2') !== false && substr($frow['form_id'], 0, 3) == 'LBF') {
652 // Option "2" generates a hidden input for the codes, and a matching visible field
653 // displaying their descriptions. First step is computing the description string.
654 $currdescstring = '';
655 if (!empty($currvalue)) {
656 $relcodes = explode(';', $currvalue);
657 foreach ($relcodes as $codestring) {
658 if ($codestring === '') {
662 $code_text = lookup_code_descriptions($codestring);
663 if ($currdescstring !== '') {
664 $currdescstring .= '; ';
667 if (!empty($code_text)) {
668 $currdescstring .= $code_text;
670 $currdescstring .= $codestring;
675 $currdescstring = attr($currdescstring);
677 echo "<input type='text'" .
678 " name='form_$field_id_esc'" .
679 " id='form_related_code'" .
680 " size='$fldlength'" .
681 " value='$currescaped'" .
682 " style='display:none'" .
683 " $lbfonchange readonly $disabled />";
684 // Extra readonly input field for optional display of code description(s).
685 echo "<input type='text'" .
686 " name='form_$field_id_esc" . "__desc'" .
687 " size='$fldlength'" .
688 " title='$description'" .
689 " value='$currdescstring'";
691 echo " onclick='sel_related(this,\"$codetype\")'";
694 echo "class='form-control'";
695 echo " readonly $disabled />";
697 echo "<input type='text'" .
698 " name='form_$field_id_esc'" .
699 " id='form_related_code'" .
700 " size='$fldlength'" .
701 " $string_maxlength" .
702 " title='$description'" .
703 " value='$currescaped'";
705 echo " onclick='sel_related(this,\"$codetype\")'";
708 echo "class='form-control'";
709 echo " $lbfonchange readonly $disabled />";
711 } // insurance company list
712 else if ($data_type == 16) {
713 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
714 echo "<option value='0'></option>";
715 $insprovs = getInsuranceProviders();
716 $got_selected = false;
717 foreach ($insprovs as $key => $ipname) {
718 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
719 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES
);
720 echo "<option value='$optionValue'";
721 if ($currvalue == $key) {
723 $got_selected = true;
726 echo ">$optionLabel</option>";
729 if (!$got_selected && $currvalue) {
730 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
732 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
737 else if ($data_type == 17) {
738 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
739 echo "<option value='0'></option>";
740 $got_selected = false;
741 foreach ($ISSUE_TYPES as $key => $value) {
742 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
743 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES
);
744 echo "<option value='$optionValue'";
745 if ($currvalue == $key) {
747 $got_selected = true;
750 echo ">$optionLabel</option>";
753 if (!$got_selected && strlen($currvalue) > 0) {
754 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
756 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
760 } // Visit categories.
761 else if ($data_type == 18) {
762 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
763 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
764 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'" .
765 " $lbfonchange $disabled>";
766 echo "<option value=''>" . xlt($empty_title) . "</option>";
767 $got_selected = false;
768 while ($crow = sqlFetchArray($cres)) {
769 $catid = $crow['pc_catid'];
770 if (($catid < 9 && $catid != 5) ||
$catid == 11) {
774 echo "<option value='" . attr($catid) . "'";
775 if ($catid == $currvalue) {
777 $got_selected = true;
780 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
783 if (!$got_selected && $currvalue) {
784 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
786 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
790 } // a set of labeled checkboxes
791 else if ($data_type == 21) {
792 // If no list then it's a single checkbox and its value is "Yes" or empty.
794 echo "<input type='checkbox' name='form_{$field_id_esc}' " .
795 "id='form_{$field_id_esc}' value='Yes' $lbfonchange";
799 echo " $disabled />";
801 // In this special case, fld_length is the number of columns generated.
802 $cols = max(1, $frow['fld_length']);
803 $avalue = explode('|', $currvalue);
804 $lres = sqlStatement("SELECT * FROM list_options " .
805 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
806 echo "<table cellpadding='0' cellspacing='0' width='100%' title='".attr($description)."'>";
807 $tdpct = (int) (100 / $cols);
808 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
809 $option_id = $lrow['option_id'];
810 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
811 // if ($count) echo "<br />";
812 if ($count %
$cols == 0) {
818 echo "<td width='" . attr($tdpct) . "%' nowrap>";
819 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
820 "id='form_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
821 if (in_array($option_id, $avalue)) {
824 // Added 5-09 by BM - Translate label if applicable
825 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
830 if ($count > $cols) {
831 // Add some space after multiple rows of checkboxes.
832 $cols = htmlspecialchars($cols, ENT_QUOTES
);
833 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
838 } // a set of labeled text input fields
839 else if ($data_type == 22) {
840 $tmp = explode('|', $currvalue);
842 foreach ($tmp as $value) {
843 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
844 $avalue[$matches[1]] = $matches[2];
848 $lres = sqlStatement("SELECT * FROM list_options " .
849 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
850 echo "<table cellpadding='0' cellspacing='0'>";
851 while ($lrow = sqlFetchArray($lres)) {
852 $option_id = $lrow['option_id'];
853 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
854 $maxlength = $frow['max_length'];
855 $string_maxlength = "";
856 // if max_length is set to zero, then do not set a maxlength
858 $string_maxlength = "maxlength='".attr($maxlength)."'";
861 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
863 // Added 5-09 by BM - Translate label if applicable
864 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
865 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
866 $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES
);
867 echo "<td><input type='text'" .
868 " name='form_{$field_id_esc}[$option_id_esc]'" .
869 " id='form_{$field_id_esc}[$option_id_esc]'" .
870 " size='$fldlength'" .
871 " class='form-control'" .
872 " $string_maxlength" .
873 " value='$optionValue'";
874 echo " $lbfonchange $disabled /></td></tr>";
878 } // a set of exam results; 3 radio buttons and a text field:
879 else if ($data_type == 23) {
880 $tmp = explode('|', $currvalue);
882 foreach ($tmp as $value) {
883 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
884 $avalue[$matches[1]] = $matches[2];
888 $maxlength = $frow['max_length'];
889 $string_maxlength = "";
890 // if max_length is set to zero, then do not set a maxlength
892 $string_maxlength = "maxlength='".attr($maxlength)."'";
895 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
896 $lres = sqlStatement("SELECT * FROM list_options " .
897 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
898 echo "<table cellpadding='0' cellspacing='0'>";
899 echo "<tr><td> </td><td class='bold'>" .
900 htmlspecialchars(xl('N/A'), ENT_NOQUOTES
) .
901 " </td><td class='bold'>" .
902 htmlspecialchars(xl('Nor'), ENT_NOQUOTES
) . " </td>" .
903 "<td class='bold'>" .
904 htmlspecialchars(xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
905 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
906 while ($lrow = sqlFetchArray($lres)) {
907 $option_id = $lrow['option_id'];
908 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
909 $restype = substr($avalue[$option_id], 0, 1);
910 $resnote = substr($avalue[$option_id], 2);
912 // Added 5-09 by BM - Translate label if applicable
913 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
915 for ($i = 0; $i < 3; ++
$i) {
916 $inputValue = htmlspecialchars($i, ENT_QUOTES
);
917 echo "<td><input type='radio'" .
918 " name='radio_{$field_id_esc}[$option_id_esc]'" .
919 " id='radio_{$field_id_esc}[$option_id_esc]'" .
920 " value='$inputValue' $lbfonchange";
921 if ($restype === "$i") {
925 echo " $disabled /></td>";
928 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
929 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
930 echo "<td><input type='text'" .
931 " name='form_{$field_id_esc}[$option_id_esc]'" .
932 " id='form_{$field_id_esc}[$option_id_esc]'" .
933 " size='$fldlength'" .
934 " $string_maxlength" .
935 " value='$resnote' $disabled /></td>";
940 } // the list of active allergies for the current patient
941 // this is read-only!
942 else if ($data_type == 24) {
943 $query = "SELECT title, comments FROM lists WHERE " .
944 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
946 // echo "<!-- $query -->\n"; // debugging
947 $lres = sqlStatement($query, array($GLOBALS['pid']));
949 while ($lrow = sqlFetchArray($lres)) {
954 echo htmlspecialchars($lrow['title'], ENT_NOQUOTES
);
955 if ($lrow['comments']) {
956 echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES
) . ')';
959 } // a set of labeled checkboxes, each with a text field:
960 else if ($data_type == 25) {
961 $tmp = explode('|', $currvalue);
963 foreach ($tmp as $value) {
964 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
965 $avalue[$matches[1]] = $matches[2];
969 $maxlength = $frow['max_length'];
970 $string_maxlength = "";
971 // if max_length is set to zero, then do not set a maxlength
973 $string_maxlength = "maxlength='".attr($maxlength)."'";
976 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
977 $lres = sqlStatement("SELECT * FROM list_options " .
978 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
979 echo "<table cellpadding='0' cellspacing='0'>";
980 while ($lrow = sqlFetchArray($lres)) {
981 $option_id = $lrow['option_id'];
982 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
983 $restype = substr($avalue[$option_id], 0, 1);
984 $resnote = substr($avalue[$option_id], 2);
986 // Added 5-09 by BM - Translate label if applicable
987 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
989 $option_id = htmlspecialchars($option_id, ENT_QUOTES
);
990 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
991 " id='check_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
996 echo " $disabled /> </td>";
997 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
998 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
999 echo "<td><input type='text'" .
1000 " name='form_{$field_id_esc}[$option_id_esc]'" .
1001 " id='form_{$field_id_esc}[$option_id_esc]'" .
1002 " size='$fldlength'" .
1003 " class='form-control' " .
1004 " $string_maxlength" .
1005 " value='$resnote' $disabled /></td>";
1010 } // single-selection list with ability to add to it
1011 else if ($data_type == 26) {
1012 echo generate_select_list(
1017 ($showEmpty ?
$empty_title : ''),
1018 'addtolistclass_'.$list_id,
1021 ($disabled ?
array('disabled' => 'disabled') : null),
1025 // show the add button if user has access to correct list
1026 $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES
);
1027 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
1028 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
1029 if (aco_exist('lists', $list_id)) {
1030 // a specific aco exist for this list, so ensure access
1031 if (acl_check('lists', $list_id)) {
1032 echo $outputAddButton;
1035 // no specific aco exist for this list, so check for access to 'default' list
1036 if (acl_check('lists', 'default')) {
1037 echo $outputAddButton;
1040 } // a set of labeled radio buttons
1041 else if ($data_type == 27) {
1042 // In this special case, fld_length is the number of columns generated.
1043 $cols = max(1, $frow['fld_length']);
1044 $lres = sqlStatement("SELECT * FROM list_options " .
1045 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1046 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1047 $tdpct = (int) (100 / $cols);
1048 $got_selected = false;
1049 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1050 $option_id = $lrow['option_id'];
1051 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES
);
1052 if ($count %
$cols == 0) {
1060 echo "<td width='" . attr($tdpct) . "%'>";
1061 echo "<input type='radio' name='form_{$field_id_esc}' class='form-control' id='form_{$field_id_esc}[$option_id_esc]'" .
1062 " value='$option_id_esc' $lbfonchange";
1063 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1064 (strlen($currvalue) > 0 && $option_id == $currvalue)) {
1066 $got_selected = true;
1069 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
1075 if ($count > $cols) {
1076 // Add some space after multiple rows of radio buttons.
1077 $cols = htmlspecialchars($cols, ENT_QUOTES
);
1078 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1083 if (!$got_selected && strlen($currvalue) > 0) {
1084 $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES
);
1085 $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES
);
1086 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
1088 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1089 // VicarePlus :: A selection list box for smoking status:
1090 else if ($data_type == 28 ||
$data_type == 32) {
1091 $tmp = explode('|', $currvalue);
1092 switch (count($tmp)) {
1111 $resdate = $restype = "";
1114 $restype = $resdate = $resnote = "";
1118 $maxlength = $frow['max_length'];
1119 $string_maxlength = "";
1120 // if max_length is set to zero, then do not set a maxlength
1122 $string_maxlength = "maxlength='".attr($maxlength)."'";
1125 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1127 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1128 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1129 $resdate = htmlspecialchars($resdate, ENT_QUOTES
);
1130 echo "<table cellpadding='0' cellspacing='0'>";
1132 if ($data_type == 28) {
1134 echo "<td><input type='text'" .
1135 " name='form_$field_id_esc'" .
1136 " id='form_$field_id_esc'" .
1137 " size='$fldlength'" .
1138 " $string_maxlength" .
1139 " value='$resnote' $disabled /> </td>";
1140 echo "<td class='bold'> ".
1141 " ".
1142 htmlspecialchars(xl('Status'), ENT_NOQUOTES
).": </td>";
1143 } else if ($data_type == 32) {
1145 echo "<tr><td><input type='text'" .
1146 " name='form_text_$field_id_esc'" .
1147 " id='form_text_$field_id_esc'" .
1148 " size='$fldlength'" .
1149 " class='form-control'" .
1150 " $string_maxlength" .
1151 " value='$resnote' $disabled /> </td></tr>";
1153 //Selection list for smoking status
1154 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1155 echo generate_select_list(
1160 ($showEmpty ?
$empty_title : ''),
1164 ($disabled ?
array('disabled' => 'disabled') : null)
1167 echo "<td class='bold'> " . xlt('Status') . ": </td>";
1171 echo "<td class='text' ><input type='radio'" .
1172 " name='radio_{$field_id_esc}'" .
1173 " id='radio_{$field_id_esc}[current]'" .
1174 " class='form-control'" .
1175 " value='current" . $field_id_esc . "' $lbfonchange";
1176 if ($restype == "current" . $field_id) {
1180 if ($data_type == 32) {
1181 echo " onClick='smoking_statusClicked(this)'";
1184 echo " />" . xlt('Current') . " </td>";
1186 echo "<td class='text'><input type='radio'" .
1187 " name='radio_{$field_id_esc}'" .
1188 " id='radio_{$field_id_esc}[quit]'" .
1189 " class='form-control'" .
1190 " value='quit".$field_id_esc."' $lbfonchange";
1191 if ($restype == "quit" . $field_id) {
1195 if ($data_type == 32) {
1196 echo " onClick='smoking_statusClicked(this)'";
1199 echo " $disabled />" . xlt('Quit') . " </td>";
1201 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1202 " value='$resdate'" .
1203 " title='$description'" .
1207 echo "<td class='text'><input type='radio'" .
1208 " name='radio_{$field_id_esc}'" .
1209 " class='form-control'" .
1210 " id='radio_{$field_id_esc}[never]'" .
1211 " value='never" . $field_id_esc . "' $lbfonchange";
1212 if ($restype == "never" . $field_id) {
1216 if ($data_type == 32) {
1217 echo " onClick='smoking_statusClicked(this)'";
1220 echo " />" . xlt('Never') . " </td>";
1222 echo "<td class='text'><input type='radio'" .
1223 " class='form-control' " .
1224 " name='radio_{$field_id}'" .
1225 " id='radio_{$field_id}[not_applicable]'" .
1226 " value='not_applicable" . $field_id . "' $lbfonchange";
1227 if ($restype == "not_applicable" . $field_id) {
1231 if ($data_type == 32) {
1232 echo " onClick='smoking_statusClicked(this)'";
1235 echo " $disabled />" . xlt('N/A') . " </td>";
1237 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1238 echo "<td class='text' ><div id='smoke_code'></div></td>";
1241 } // static text. read-only, of course.
1242 else if ($data_type == 31) {
1243 echo parse_static_text($frow);
1244 } //$data_type == 33
1245 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1248 else if ($data_type == 34) {
1249 $arr = explode("|*|*|*|", $currvalue);
1250 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;'>";
1251 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0], ENT_QUOTES
)."</div>";
1252 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>";
1254 } //facilities drop-down list
1255 else if ($data_type == 35) {
1256 if (empty($currvalue)) {
1261 $selected = $currvalue,
1262 $name = "form_$field_id_esc",
1263 $allow_unspecified = true,
1264 $allow_allfacilities = false,
1269 // supports backup list
1270 else if ($data_type == 36) {
1271 echo generate_select_list(
1276 $showEmpty ?
$empty_title : '',
1284 } // Canvas and related elements for browser-side image drawing.
1285 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1286 else if ($data_type == 40) {
1287 // Unlike other field types, width and height are in pixels.
1288 $canWidth = intval($frow['fld_length']);
1289 $canHeight = intval($frow['fld_rows']);
1290 if (empty($currvalue)) {
1291 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1292 // If defined this is the filename of the default starting image.
1293 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1297 $mywidth = 50 +
($canWidth > 250 ?
$canWidth : 250);
1298 $myheight = 31 +
($canHeight > 261 ?
$canHeight : 261);
1299 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1300 // Hidden form field exists to send updated data to the server at submit time.
1301 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1302 // Hidden image exists to support initialization of the canvas.
1303 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1304 // $date_init is a misnomer but it's the place for browser-side setup logic.
1305 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1309 function generate_print_field($frow, $currvalue)
1311 global $rootdir, $date_init, $ISSUE_TYPES;
1313 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
1315 $data_type = $frow['data_type'];
1316 $field_id = $frow['field_id'];
1317 $list_id = $frow['list_id'];
1318 $fld_length = $frow['fld_length'];
1319 $backup_list = $frow['list_backup_id'];
1321 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
1323 // Can pass $frow['empty_title'] with this variable, otherwise
1324 // will default to 'Unassigned'.
1325 // If it is 'SKIP' then an empty text title is completely skipped.
1327 if (isset($frow['empty_title'])) {
1328 if ($frow['empty_title'] == "SKIP") {
1329 //do not display an 'empty' choice
1331 $empty_title = "Unassigned";
1333 $empty_title = $frow['empty_title'];
1336 $empty_title = "Unassigned";
1339 // generic single-selection list
1340 // Supports backup lists.
1341 if (false && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
1342 if (empty($fld_length)) {
1343 if ($list_id == 'titles') {
1352 $lrow = sqlQuery("SELECT title FROM list_options " .
1353 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1354 $tmp = xl_list_label($lrow['title']);
1355 if ($lrow == 0 && !empty($backup_list)) {
1356 // since primary list did not map, try to map to backup list
1357 $lrow = sqlQuery("SELECT title FROM list_options " .
1358 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1359 $tmp = xl_list_label($lrow['title']);
1363 $tmp = "($currvalue)";
1367 /*****************************************************************
1368 echo "<input type='text'" .
1369 " size='$fld_length'" .
1373 *****************************************************************/
1377 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1381 } // simple text field
1382 else if ($data_type == 2 ||
$data_type == 15) {
1383 /*****************************************************************
1384 echo "<input type='text'" .
1385 " size='$fld_length'" .
1386 " value='$currescaped'" .
1389 *****************************************************************/
1390 if ($currescaped === '') {
1391 $currescaped = ' ';
1395 } // long or multi-line text field
1396 else if ($data_type == 3) {
1397 $fldlength = htmlspecialchars($fld_length, ENT_QUOTES
);
1398 $maxlength = htmlspecialchars($frow['fld_rows'], ENT_QUOTES
);
1400 " class='form-control' " .
1401 " cols='$fldlength'" .
1402 " rows='$maxlength'>" .
1403 $currescaped . "</textarea>";
1405 else if ($data_type == 4) {
1406 $age_asof_date = '';
1407 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
1408 if ($currvalue === '') {
1411 echo text(oeFormatShortDate($currvalue));
1413 echo " (" . text($agestr) . ")";
1417 else if ($data_type == 10 ||
$data_type == 11) {
1420 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1421 "WHERE id = ?", array($currvalue));
1422 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1424 $tmp = "($currvalue)";
1428 /*****************************************************************
1429 echo "<input type='text'" .
1430 " size='$fld_length'" .
1434 *****************************************************************/
1438 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1443 else if ($data_type == 12) {
1446 $pres = get_pharmacies();
1447 while ($prow = sqlFetchArray($pres)) {
1449 if ($currvalue == $key) {
1450 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1451 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1452 $prow['line1'] . ' / ' . $prow['city'];
1457 $tmp = "($currvalue)";
1461 /*****************************************************************
1462 echo "<input type='text'" .
1463 " size='$fld_length'" .
1467 *****************************************************************/
1471 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1476 else if ($data_type == 13) {
1479 $squads = acl_get_squads();
1481 foreach ($squads as $key => $value) {
1482 if ($currvalue == $key) {
1489 $tmp = "($currvalue)";
1493 /*****************************************************************
1494 echo "<input type='text'" .
1495 " size='$fld_length'" .
1499 *****************************************************************/
1503 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1508 else if ($data_type == 14) {
1511 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1512 "WHERE id = ?", array($currvalue));
1513 $uname = $urow['lname'];
1514 if ($urow['fname']) {
1515 $uname .= ", " . $urow['fname'];
1520 $tmp = "($currvalue)";
1524 /*****************************************************************
1525 echo "<input type='text'" .
1526 " size='$fld_length'" .
1530 *****************************************************************/
1534 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1538 } // insurance company list
1539 else if ($data_type == 16) {
1542 $insprovs = getInsuranceProviders();
1543 foreach ($insprovs as $key => $ipname) {
1544 if ($currvalue == $key) {
1550 $tmp = "($currvalue)";
1557 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1562 else if ($data_type == 17) {
1565 foreach ($ISSUE_TYPES as $key => $value) {
1566 if ($currvalue == $key) {
1572 $tmp = "($currvalue)";
1579 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1583 } // Visit categories.
1584 else if ($data_type == 18) {
1588 "SELECT pc_catid, pc_catname " .
1589 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1592 $tmp = xl_appt_category($crow['pc_catname']);
1594 $tmp = "($currvalue)";
1601 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1605 } // a single checkbox or set of labeled checkboxes
1606 else if ($data_type == 21) {
1608 echo "<input type='checkbox'";
1614 // In this special case, fld_length is the number of columns generated.
1615 $cols = max(1, $fld_length);
1616 $avalue = explode('|', $currvalue);
1617 $lres = sqlStatement("SELECT * FROM list_options " .
1618 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1619 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1620 $tdpct = (int) (100 / $cols);
1621 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1622 $option_id = $lrow['option_id'];
1623 if ($count %
$cols == 0) {
1630 echo "<td width='" . attr($tdpct) . "%'>";
1631 echo "<input type='checkbox'";
1632 if (in_array($option_id, $avalue)) {
1635 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
1640 if ($count > $cols) {
1641 // Add some space after multiple rows of checkboxes.
1642 $cols = htmlspecialchars($cols, ENT_QUOTES
);
1643 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1648 } // a set of labeled text input fields
1649 else if ($data_type == 22) {
1650 $tmp = explode('|', $currvalue);
1652 foreach ($tmp as $value) {
1653 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1654 $avalue[$matches[1]] = $matches[2];
1658 $lres = sqlStatement("SELECT * FROM list_options " .
1659 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1660 echo "<table cellpadding='0' cellspacing='0'>";
1661 while ($lrow = sqlFetchArray($lres)) {
1662 $option_id = $lrow['option_id'];
1663 $fldlength = empty($fld_length) ?
20 : $fld_length;
1664 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1665 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1666 $inputValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES
);
1667 echo "<td><input type='text'" .
1668 " class='form-control' " .
1669 " size='$fldlength'" .
1670 " value='$inputValue'" .
1676 } // a set of exam results; 3 radio buttons and a text field:
1677 else if ($data_type == 23) {
1678 $tmp = explode('|', $currvalue);
1680 foreach ($tmp as $value) {
1681 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1682 $avalue[$matches[1]] = $matches[2];
1686 $fldlength = empty($fld_length) ?
20 : $fld_length;
1687 $lres = sqlStatement("SELECT * FROM list_options " .
1688 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1689 echo "<table cellpadding='0' cellspacing='0'>";
1690 echo "<tr><td> </td><td class='bold'>" .
1691 htmlspecialchars(xl('N/A'), ENT_NOQUOTES
) .
1692 " </td><td class='bold'>" .
1693 htmlspecialchars(xl('Nor'), ENT_NOQUOTES
) . " </td>" .
1694 "<td class='bold'>" .
1695 htmlspecialchars(xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
1696 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
1697 while ($lrow = sqlFetchArray($lres)) {
1698 $option_id = $lrow['option_id'];
1699 $restype = substr($avalue[$option_id], 0, 1);
1700 $resnote = substr($avalue[$option_id], 2);
1701 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1702 for ($i = 0; $i < 3; ++
$i) {
1703 echo "<td><input type='radio'";
1704 if ($restype === "$i") {
1711 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1712 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1713 echo "<td><input type='text'" .
1714 " size='$fldlength'" .
1715 " value='$resnote'" .
1716 " class='under form-control' /></td>" .
1721 } // the list of active allergies for the current patient
1722 // this is read-only!
1723 else if ($data_type == 24) {
1724 $query = "SELECT title, comments FROM lists WHERE " .
1725 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1727 $lres = sqlStatement($query, array($GLOBALS['pid']));
1729 while ($lrow = sqlFetchArray($lres)) {
1734 echo htmlspecialchars($lrow['title'], ENT_QUOTES
);
1735 if ($lrow['comments']) {
1736 echo htmlspecialchars(' (' . $lrow['comments'] . ')', ENT_QUOTES
);
1739 } // a set of labeled checkboxes, each with a text field:
1740 else if ($data_type == 25) {
1741 $tmp = explode('|', $currvalue);
1743 foreach ($tmp as $value) {
1744 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1745 $avalue[$matches[1]] = $matches[2];
1749 $fldlength = empty($fld_length) ?
20 : $fld_length;
1750 $lres = sqlStatement("SELECT * FROM list_options " .
1751 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1752 echo "<table cellpadding='0' cellspacing='0'>";
1753 while ($lrow = sqlFetchArray($lres)) {
1754 $option_id = $lrow['option_id'];
1755 $restype = substr($avalue[$option_id], 0, 1);
1756 $resnote = substr($avalue[$option_id], 2);
1757 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1758 echo "<td><input type='checkbox'";
1763 echo " /> </td>";
1764 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1765 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1766 echo "<td><input type='text'" .
1767 " size='$fldlength'" .
1768 " class='form-control' " .
1769 " value='$resnote'" .
1776 } // a set of labeled radio buttons
1777 else if ($data_type == 27 ||
$data_type == 1 ||
$data_type == 26 ||
$data_type == 33) {
1778 // In this special case, fld_length is the number of columns generated.
1779 $cols = max(1, $frow['fld_length']);
1780 $lres = sqlStatement("SELECT * FROM list_options " .
1781 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1782 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1783 $tdpct = (int) (100 / $cols);
1784 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1785 $option_id = $lrow['option_id'];
1786 if ($count %
$cols == 0) {
1793 echo "<td width='" . attr($tdpct) . "%'>";
1794 echo "<input type='radio'";
1795 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1796 // Do not use defaults for these printable forms.
1800 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
1806 if ($count > $cols) {
1807 // Add some space after multiple rows of radio buttons.
1808 $cols = htmlspecialchars($cols, ENT_QUOTES
);
1809 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1814 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1815 else if ($data_type == 28 ||
$data_type == 32) {
1816 $tmp = explode('|', $currvalue);
1817 switch (count($tmp)) {
1836 $resdate = $restype = "";
1839 $restype = $resdate = $resnote = "";
1843 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1844 echo "<table cellpadding='0' cellspacing='0'>";
1846 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES
);
1847 $resnote = htmlspecialchars($resnote, ENT_QUOTES
);
1848 $resdate = htmlspecialchars($resdate, ENT_QUOTES
);
1849 if ($data_type == 28) {
1850 echo "<td><input type='text'" .
1851 " size='$fldlength'" .
1853 " value='$resnote' /></td>";
1854 echo "<td class='bold'> ".
1855 " ".
1856 htmlspecialchars(xl('Status'), ENT_NOQUOTES
).": </td>";
1857 } else if ($data_type == 32) {
1858 echo "<tr><td><input type='text'" .
1859 " size='$fldlength'" .
1860 " class='under form-control'" .
1861 " value='$resnote' /></td></tr>";
1863 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
1864 echo "<td><input type='text'" .
1865 " size='$fldlength'" .
1866 " class='under form-control'" .
1867 " value='$smoking_status_title' /></td>";
1868 echo "<td class='bold'> ".htmlspecialchars(xl('Status'), ENT_NOQUOTES
).": </td>";
1871 echo "<td><input type='radio' class='form-control'";
1872 if ($restype == "current".$field_id) {
1876 echo "/>".htmlspecialchars(xl('Current'), ENT_NOQUOTES
)." </td>";
1878 echo "<td><input type='radio' class='form-control'";
1879 if ($restype == "current".$field_id) {
1883 echo "/>".htmlspecialchars(xl('Quit'), ENT_NOQUOTES
)." </td>";
1885 echo "<td><input type='text' size='6'" .
1886 " value='$resdate'" .
1887 " class='under form-control'" .
1890 echo "<td><input type='radio' class='form-control'";
1891 if ($restype == "current".$field_id) {
1895 echo " />".htmlspecialchars(xl('Never'), ENT_NOQUOTES
)."</td>";
1897 echo "<td><input type='radio' class='form-control'";
1898 if ($restype == "not_applicable".$field_id) {
1902 echo " />".htmlspecialchars(xl('N/A'), ENT_NOQUOTES
)." </td>";
1905 } // static text. read-only, of course.
1906 else if ($data_type == 31) {
1907 echo parse_static_text($frow);
1908 } else if ($data_type == 34) {
1909 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;'>";
1910 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1911 echo "<div style='display:none'><textarea name='form_{$field_id}' class='form-control' id='form_{$field_id}' stye='display:none'></textarea></div>";
1913 } //facilities drop-down list
1914 else if ($data_type == 35) {
1915 // In this special case, fld_length is the number of columns generated.
1916 $cols = max(1, $frow['fld_length']);
1917 $lres = sqlStatement("SELECT id, name FROM facility ORDER BY name");
1918 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1919 $tdpct = (int) (100 / $cols);
1920 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1921 $option_id = $lrow['id'];
1922 if ($count %
$cols == 0) {
1928 echo "<td width='" . attr($tdpct) . "%'>";
1929 echo "<input type='radio'";
1930 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1931 // Do not use defaults for these printable forms.
1934 echo ">" . htmlspecialchars($lrow['name']);
1939 if ($count > $cols) {
1940 // Add some space after multiple rows of radio buttons.
1941 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1946 // Supports backup lists.
1947 else if ($data_type == 36) {
1948 if (empty($fld_length)) {
1949 if ($list_id == 'titles') {
1958 $values_array = explode("|", $currvalue);
1961 foreach ($values_array as $value) {
1963 $lrow = sqlQuery("SELECT title FROM list_options " .
1964 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1965 $tmp = xl_list_label($lrow['title']);
1966 if ($lrow == 0 && !empty($backup_list)) {
1967 // since primary list did not map, try to map to backup list
1968 $lrow = sqlQuery("SELECT title FROM list_options " .
1969 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1970 $tmp = xl_list_label($lrow['title']);
1981 $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1984 if ($i != 0 && $tmp != ' ') {
1991 } // Image from canvas drawing
1992 else if ($data_type == 40) {
1994 echo "<img src='" . attr($currvalue) . "'>";
1999 function generate_display_field($frow, $currvalue)
2001 global $ISSUE_TYPES, $facilityService;
2003 $data_type = $frow['data_type'];
2004 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
2005 $list_id = $frow['list_id'];
2006 $backup_list = isset($frow['list_backup_id']) ?
$frow['list_backup_id'] : null;
2010 // generic selection list or the generic selection list with add on the fly
2012 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33) {
2013 $lrow = sqlQuery("SELECT title FROM list_options " .
2014 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2015 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2016 //if there is no matching value in the corresponding lists check backup list
2017 // only supported in data types 1,26,33
2018 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
2019 $lrow = sqlQuery("SELECT title FROM list_options " .
2020 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2021 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2023 } // simple text field
2024 else if ($data_type == 2) {
2025 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES
));
2026 } // long or multi-line text field
2027 else if ($data_type == 3) {
2028 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES
));
2030 else if ($data_type == 4) {
2031 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
2033 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
2034 $age_asof_date = '';
2035 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
2036 if ($currvalue === '') {
2039 $s .= text(oeFormatShortDate($currvalue));
2041 $s .= " (" . text($agestr) . ")";
2045 else if ($data_type == 10 ||
$data_type == 11) {
2046 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2047 "WHERE id = ?", array($currvalue));
2048 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']), ENT_NOQUOTES
);
2050 else if ($data_type == 12) {
2051 $pres = get_pharmacies();
2052 while ($prow = sqlFetchArray($pres)) {
2054 if ($currvalue == $key) {
2055 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
2056 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2057 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
2061 else if ($data_type == 13) {
2062 $squads = acl_get_squads();
2064 foreach ($squads as $key => $value) {
2065 if ($currvalue == $key) {
2066 $s .= htmlspecialchars($value[3], ENT_NOQUOTES
);
2071 else if ($data_type == 14) {
2072 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
2073 "WHERE id = ?", array($currvalue));
2074 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
2075 if ($urow['organization'] !="") {
2076 $uname = $urow['organization'];
2078 $uname = $urow['lname'];
2079 if ($urow['fname']) {
2080 $uname .= ", " . $urow['fname'];
2084 $s = htmlspecialchars($uname, ENT_NOQUOTES
);
2086 else if ($data_type == 15) {
2088 if (!empty($currvalue)) {
2089 $relcodes = explode(';', $currvalue);
2090 foreach ($relcodes as $codestring) {
2091 if ($codestring === '') {
2094 $tmp = lookup_code_descriptions($codestring);
2101 $s .= $codestring . ' (' . xl('not found') . ')';
2105 } // insurance company list
2106 else if ($data_type == 16) {
2107 $insprovs = getInsuranceProviders();
2108 foreach ($insprovs as $key => $ipname) {
2109 if ($currvalue == $key) {
2110 $s .= htmlspecialchars($ipname, ENT_NOQUOTES
);
2114 else if ($data_type == 17) {
2115 foreach ($ISSUE_TYPES as $key => $value) {
2116 if ($currvalue == $key) {
2117 $s .= htmlspecialchars($value[1], ENT_NOQUOTES
);
2121 else if ($data_type == 18) {
2123 "SELECT pc_catid, pc_catname " .
2124 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2127 $s = htmlspecialchars($crow['pc_catname'], ENT_NOQUOTES
);
2128 } // a single checkbox or set of labeled checkboxes
2129 else if ($data_type == 21) {
2131 $s .= $currvalue ?
'[ x ]' : '[ ]';
2133 // In this special case, fld_length is the number of columns generated.
2134 $cols = max(1, $frow['fld_length']);
2135 $avalue = explode('|', $currvalue);
2136 $lres = sqlStatement("SELECT * FROM list_options " .
2137 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2138 $s .= "<table cellspacing='0' cellpadding='0'>";
2139 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
2140 $option_id = $lrow['option_id'];
2141 $option_id_esc = text($option_id);
2142 if ($count %
$cols == 0) {
2148 $s .= "<td nowrap>";
2149 $checked = in_array($option_id, $avalue);
2150 $s .= $checked ?
'[ x ]' : '[ ]';
2151 $s .= ' ' . text(xl_list_label($lrow['title'])). ' ';
2159 } // a set of labeled text input fields
2160 else if ($data_type == 22) {
2161 $tmp = explode('|', $currvalue);
2163 foreach ($tmp as $value) {
2164 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2165 $avalue[$matches[1]] = $matches[2];
2169 $lres = sqlStatement("SELECT * FROM list_options " .
2170 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2171 $s .= "<table cellpadding='0' cellspacing='0'>";
2172 while ($lrow = sqlFetchArray($lres)) {
2173 $option_id = $lrow['option_id'];
2174 if (empty($avalue[$option_id])) {
2178 // Added 5-09 by BM - Translate label if applicable
2179 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . ": </td>";
2181 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id], ENT_NOQUOTES
) . "</td></tr>";
2185 } // a set of exam results; 3 radio buttons and a text field:
2186 else if ($data_type == 23) {
2187 $tmp = explode('|', $currvalue);
2189 foreach ($tmp as $value) {
2190 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2191 $avalue[$matches[1]] = $matches[2];
2195 $lres = sqlStatement("SELECT * FROM list_options " .
2196 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2197 $s .= "<table cellpadding='0' cellspacing='0'>";
2198 while ($lrow = sqlFetchArray($lres)) {
2199 $option_id = $lrow['option_id'];
2200 $restype = substr($avalue[$option_id], 0, 1);
2201 $resnote = substr($avalue[$option_id], 2);
2202 if (empty($restype) && empty($resnote)) {
2206 // Added 5-09 by BM - Translate label if applicable
2207 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
2209 $restype = ($restype == '1') ?
xl('Normal') : (($restype == '2') ?
xl('Abnormal') : xl('N/A'));
2210 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2211 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2212 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES
) . " </td>";
2213 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . "</td>";
2218 } // the list of active allergies for the current patient
2219 else if ($data_type == 24) {
2220 $query = "SELECT title, comments FROM lists WHERE " .
2221 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2223 // echo "<!-- $query -->\n"; // debugging
2224 $lres = sqlStatement($query, array($GLOBALS['pid']));
2226 while ($lrow = sqlFetchArray($lres)) {
2231 $s .= htmlspecialchars($lrow['title'], ENT_NOQUOTES
);
2232 if ($lrow['comments']) {
2233 $s .= ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES
) . ')';
2236 } // a set of labeled checkboxes, each with a text field:
2237 else if ($data_type == 25) {
2238 $tmp = explode('|', $currvalue);
2240 foreach ($tmp as $value) {
2241 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2242 $avalue[$matches[1]] = $matches[2];
2246 $lres = sqlStatement("SELECT * FROM list_options " .
2247 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2248 $s .= "<table cellpadding='0' cellspacing='0'>";
2249 while ($lrow = sqlFetchArray($lres)) {
2250 $option_id = $lrow['option_id'];
2251 $restype = substr($avalue[$option_id], 0, 1);
2252 $resnote = substr($avalue[$option_id], 2);
2253 if (empty($restype) && empty($resnote)) {
2257 // Added 5-09 by BM - Translate label if applicable
2258 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
2260 $restype = $restype ?
xl('Yes') : xl('No');
2261 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES
) . " </td>";
2262 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . "</td>";
2267 } // a set of labeled radio buttons
2268 else if ($data_type == 27) {
2269 // In this special case, fld_length is the number of columns generated.
2270 $cols = max(1, $frow['fld_length']);
2271 $lres = sqlStatement("SELECT * FROM list_options " .
2272 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2273 $s .= "<table cellspacing='0' cellpadding='0'>";
2274 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
2275 $option_id = $lrow['option_id'];
2276 $option_id_esc = text($option_id);
2277 if ($count %
$cols == 0) {
2284 $checked = ((strlen($currvalue) == 0 && $lrow['is_default']) ||
2285 (strlen($currvalue) > 0 && $option_id == $currvalue));
2286 $s .= $checked ?
'[ x ]' : '[ ]';
2287 $s .= ' ' . text(xl_list_label($lrow['title'])). ' ';
2294 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2295 // VicarePlus :: A selection list for smoking status.
2296 else if ($data_type == 28 ||
$data_type == 32) {
2297 $tmp = explode('|', $currvalue);
2298 switch (count($tmp)) {
2317 $resdate = $restype = "";
2320 $restype = $resdate = $resnote = "";
2324 $s .= "<table cellpadding='0' cellspacing='0'>";
2328 if ($restype == "current".$field_id) {
2329 $res = xl('Current');
2332 if ($restype == "quit".$field_id) {
2336 if ($restype == "never".$field_id) {
2340 if ($restype == "not_applicable".$field_id) {
2344 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2345 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2346 if ($data_type == 28) {
2347 if (!empty($resnote)) {
2348 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . " </td>";
2350 } //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2351 else if ($data_type == 32) {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2352 $smoke_codes = getSmokeCodes();
2353 if (!empty($reslist)) {
2354 if ($smoke_codes[$reslist]!="") {
2355 $code_desc = "( ".$smoke_codes[$reslist]." )";
2358 $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist) . " ".text($code_desc)." </td>";
2361 if (!empty($resnote)) {
2362 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES
) . " </td>";
2367 $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'), ENT_NOQUOTES
) . "</b>: " . htmlspecialchars($res, ENT_NOQUOTES
) . " </td>";
2370 if ($restype == "quit".$field_id) {
2371 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate, ENT_NOQUOTES
) . " </td>";
2376 } // static text. read-only, of course.
2377 else if ($data_type == 31) {
2378 $s .= parse_static_text($frow);
2379 } else if ($data_type == 34) {
2380 $arr = explode("|*|*|*|", $currvalue);
2381 for ($i=0; $i<sizeof($arr); $i++
) {
2385 else if ($data_type == 35) {
2386 $urow = $facilityService->getById($currvalue);
2387 $s = htmlspecialchars($urow['name'], ENT_NOQUOTES
);
2389 // Supports backup lists
2390 else if ($data_type == 36) {
2391 $values_array = explode("|", $currvalue);
2393 foreach ($values_array as $value) {
2394 $lrow = sqlQuery("SELECT title FROM list_options " .
2395 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2396 if ($lrow == 0 && !empty($backup_list)) {
2398 $lrow = sqlQuery("SELECT title FROM list_options " .
2399 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2403 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2405 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
2410 } // Image from canvas drawing
2411 else if ($data_type == 40) {
2413 $s .= "<img src='" . attr($currvalue) . "'>";
2420 // Generate plain text versions of selected LBF field types.
2421 // Currently used by interface/patient_file/download_template.php.
2422 // More field types might need to be supported here in the future.
2424 function generate_plaintext_field($frow, $currvalue)
2426 global $ISSUE_TYPES;
2428 $data_type = $frow['data_type'];
2429 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
2430 $list_id = $frow['list_id'];
2431 $backup_list = $frow['backup_list'];
2434 // generic selection list or the generic selection list with add on the fly
2435 // feature, or radio buttons
2436 // Supports backup lists (for datatypes 1,26,33)
2437 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27 ||
$data_type == 33) {
2438 $lrow = sqlQuery("SELECT title FROM list_options " .
2439 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2440 $s = xl_list_label($lrow['title']);
2441 //if there is no matching value in the corresponding lists check backup list
2442 // only supported in data types 1,26,33
2443 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
2444 $lrow = sqlQuery("SELECT title FROM list_options " .
2445 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2446 $s = xl_list_label($lrow['title']);
2448 } // simple or long text field
2449 else if ($data_type == 2 ||
$data_type == 3 ||
$data_type == 15) {
2452 else if ($data_type == 4) {
2453 $s = oeFormatShortDate($currvalue);
2454 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
2455 $age_asof_date = '';
2456 // Optional display of age or gestational age.
2457 $tmp = optionalAge($frow, $currvalue, $age_asof_date, $description);
2462 else if ($data_type == 10 ||
$data_type == 11) {
2463 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2464 "WHERE id = ?", array($currvalue));
2465 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2467 else if ($data_type == 12) {
2468 $pres = get_pharmacies();
2469 while ($prow = sqlFetchArray($pres)) {
2471 if ($currvalue == $key) {
2472 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2473 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2474 $prow['line1'] . ' / ' . $prow['city'];
2478 else if ($data_type == 14) {
2479 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2480 "WHERE id = ?", array($currvalue));
2481 $uname = $urow['lname'];
2482 if ($urow['fname']) {
2483 $uname .= ", " . $urow['fname'];
2487 } // insurance company list
2488 else if ($data_type == 16) {
2489 $insprovs = getInsuranceProviders();
2490 foreach ($insprovs as $key => $ipname) {
2491 if ($currvalue == $key) {
2496 else if ($data_type == 17) {
2497 foreach ($ISSUE_TYPES as $key => $value) {
2498 if ($currvalue == $key) {
2503 else if ($data_type == 18) {
2505 "SELECT pc_catid, pc_catname " .
2506 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2509 $s = $crow['pc_catname'];
2510 } // a set of labeled checkboxes
2511 else if ($data_type == 21) {
2513 $s .= $currvalue ?
xlt('Yes') : xlt('No');
2515 $avalue = explode('|', $currvalue);
2516 $lres = sqlStatement("SELECT * FROM list_options " .
2517 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2519 while ($lrow = sqlFetchArray($lres)) {
2520 $option_id = $lrow['option_id'];
2521 if (in_array($option_id, $avalue)) {
2525 $s .= xl_list_label($lrow['title']);
2529 } // a set of labeled text input fields
2530 else if ($data_type == 22) {
2531 $tmp = explode('|', $currvalue);
2533 foreach ($tmp as $value) {
2534 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2535 $avalue[$matches[1]] = $matches[2];
2539 $lres = sqlStatement("SELECT * FROM list_options " .
2540 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2541 while ($lrow = sqlFetchArray($lres)) {
2542 $option_id = $lrow['option_id'];
2543 if (empty($avalue[$option_id])) {
2551 $s .= xl_list_label($lrow['title']) . ': ';
2552 $s .= $avalue[$option_id];
2554 } // A set of exam results; 3 radio buttons and a text field.
2555 // This shows abnormal results only.
2556 else if ($data_type == 23) {
2557 $tmp = explode('|', $currvalue);
2559 foreach ($tmp as $value) {
2560 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2561 $avalue[$matches[1]] = $matches[2];
2565 $lres = sqlStatement("SELECT * FROM list_options " .
2566 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2567 while ($lrow = sqlFetchArray($lres)) {
2568 $option_id = $lrow['option_id'];
2569 $restype = substr($avalue[$option_id], 0, 1);
2570 $resnote = substr($avalue[$option_id], 2);
2571 if (empty($restype) && empty($resnote)) {
2575 if ($restype != '2') {
2576 continue; // show abnormal results only
2583 $s .= xl_list_label($lrow['title']);
2584 if (!empty($resnote)) {
2585 $s .= ': ' . $resnote;
2588 } // the list of active allergies for the current patient
2589 else if ($data_type == 24) {
2590 $query = "SELECT title, comments FROM lists WHERE " .
2591 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2593 $lres = sqlStatement($query, array($GLOBALS['pid']));
2595 while ($lrow = sqlFetchArray($lres)) {
2600 $s .= $lrow['title'];
2601 if ($lrow['comments']) {
2602 $s .= ' (' . $lrow['comments'] . ')';
2605 } // a set of labeled checkboxes, each with a text field:
2606 else if ($data_type == 25) {
2607 $tmp = explode('|', $currvalue);
2609 foreach ($tmp as $value) {
2610 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2611 $avalue[$matches[1]] = $matches[2];
2615 $lres = sqlStatement("SELECT * FROM list_options " .
2616 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2617 while ($lrow = sqlFetchArray($lres)) {
2618 $option_id = $lrow['option_id'];
2619 $restype = substr($avalue[$option_id], 0, 1);
2620 $resnote = substr($avalue[$option_id], 2);
2621 if (empty($restype) && empty($resnote)) {
2629 $s .= xl_list_label($lrow['title']);
2630 $restype = $restype ?
xl('Yes') : xl('No');
2633 $s .= ' ' . $resnote;
2636 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2637 // VicarePlus :: A selection list for smoking status.
2638 else if ($data_type == 28 ||
$data_type == 32) {
2639 $tmp = explode('|', $currvalue);
2640 $resnote = count($tmp) > 0 ?
$tmp[0] : '';
2641 $restype = count($tmp) > 1 ?
$tmp[1] : '';
2642 $resdate = count($tmp) > 2 ?
$tmp[2] : '';
2643 $reslist = count($tmp) > 3 ?
$tmp[3] : '';
2645 if ($restype == "current" . $field_id) {
2646 $res = xl('Current');
2649 if ($restype == "quit" . $field_id) {
2653 if ($restype == "never" . $field_id) {
2657 if ($restype == "not_applicable". $field_id) {
2661 if ($data_type == 28) {
2662 if (!empty($resnote)) {
2665 } // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2666 else if ($data_type == 32) {
2667 if (!empty($reslist)) {
2668 $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
2671 if (!empty($resnote)) {
2672 $s .= ' ' . $resnote;
2681 $s .= xl('Status') . ' ' . $res;
2684 if ($restype == "quit".$field_id) {
2692 // Supports backup lists
2693 else if ($data_type == 36) {
2694 $values_array = explode("|", $currvalue);
2697 foreach ($values_array as $value) {
2698 $lrow = sqlQuery("SELECT title FROM list_options " .
2699 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2701 if ($lrow == 0 && !empty($backup_list)) {
2703 $lrow = sqlQuery("SELECT title FROM list_options " .
2704 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2708 $s = $s . ", " . xl_list_label($lrow['title']);
2710 $s = xl_list_label($lrow['title']);
2720 $CPR = 4; // cells per row of generic data
2725 function disp_end_cell()
2727 global $item_count, $cell_count;
2728 if ($item_count > 0) {
2734 function disp_end_row()
2736 global $cell_count, $CPR;
2738 if ($cell_count > 0) {
2739 for (; $cell_count < $CPR;
2749 function disp_end_group()
2752 if (strlen($last_group) > 0) {
2757 // Accumulate action conditions into a JSON expression for the browser side.
2758 function accumActionConditions($field_id, &$condition_str, &$condarr)
2760 $conditions = empty($condarr) ?
array() : unserialize($condarr);
2762 foreach ($conditions as $key => $condition) {
2763 if ($key === 'action') {
2764 // If specified this should be the first array item.
2766 $action = $condition;
2770 if (empty($condition['id'])) {
2773 $andor = empty($condition['andor']) ?
'' : $condition['andor'];
2774 if ($condition_str) {
2775 $condition_str .= ",\n";
2777 $condition_str .= "{" .
2778 "target:'" . addslashes($field_id) . "', " .
2779 "action:'" . addslashes($action) . "', " .
2780 "id:'" . addslashes($condition['id']) . "', " .
2781 "itemid:'" . addslashes($condition['itemid']) . "', " .
2782 "operator:'" . addslashes($condition['operator']) . "', " .
2783 "value:'" . addslashes($condition['value']) . "', " .
2784 "andor:'" . addslashes($andor) . "'}";
2788 // This checks if the given field with the given value should have an action applied.
2789 // Originally the only action was skip, but now you can also set the field to a specified value.
2790 // It somewhat mirrors the checkSkipConditions function in options.js.php.
2791 // If you use this for multiple layouts in the same script, you should
2792 // clear $sk_layout_items before each layout.
2793 function isSkipped(&$frow, $currvalue)
2795 global $sk_layout_items;
2797 // Accumulate an array of the encountered fields and their values.
2798 // It is assumed that fields appear before they are tested by another field.
2799 // TBD: Bad assumption?
2800 $field_id = $frow['field_id'];
2801 if (!is_array($sk_layout_items)) {
2802 $sk_layout_items = array();
2804 $sk_layout_items[$field_id] = array('row' => $frow, 'value' => $currvalue);
2806 if (empty($frow['conditions'])) {
2810 $skiprows = unserialize($frow['conditions']);
2813 $datatype = $frow['data_type'];
2814 $action = 'skip'; // default action if none specified
2816 foreach ($skiprows as $key => $skiprow) {
2817 // id referenced field id
2818 // itemid referenced array key if applicable
2819 // operator "eq", "ne", "se" or "ns"
2820 // value if eq or ne, some string to compare with
2821 // andor "and", "or" or empty
2823 if ($key === 'action') {
2824 // Action value is a string. It can be "skip", or "value=" followed by a value.
2829 if (empty($skiprow['id'])) {
2833 $id = $skiprow['id'];
2834 if (!isset($sk_layout_items[$id])) {
2835 error_log("Function isSkipped() cannot find skip source field '$id'.");
2838 $itemid = $skiprow['itemid'];
2839 $operator = $skiprow['operator'];
2840 $skipval = $skiprow['value'];
2841 $srcvalue = $sk_layout_items[$id]['value'];
2842 $src_datatype = $sk_layout_items[$id]['row']['data_type'];
2843 $src_list_id = $sk_layout_items[$id]['row']['list_id'];
2845 // Some data types use itemid and we have to dig for their value.
2846 if ($src_datatype == 21 && $src_list_id) { // array of checkboxes
2847 $tmp = explode('|', $srcvalue);
2848 $srcvalue = in_array($itemid, $tmp);
2849 } else if ($src_datatype == 22 ||
$src_datatype == 23 ||
$src_datatype == 25) {
2850 $tmp = explode('|', $srcvalue);
2852 foreach ($tmp as $tmp2) {
2853 if (strpos($tmp2, "$itemid:") === 0) {
2854 if ($datatype == 22) {
2855 $srcvalue = substr($tmp2, strlen($itemid) +
1);
2857 $srcvalue = substr($tmp2, strlen($itemid) +
1, 1);
2863 // Compute the result of the test for this condition row.
2864 // PHP's looseness with variable type conversion helps us here.
2866 if ($operator == 'eq') {
2867 $condition = $srcvalue == $skipval;
2868 } else if ($operator == 'ne') {
2869 $condition = $srcvalue != $skipval;
2870 } else if ($operator == 'se') {
2871 $condition = $srcvalue == true;
2872 } else if ($operator == 'ns') {
2873 $condition = $srcvalue != true;
2875 error_log("Unknown skip operator '$operator' for field '$field_id'.");
2878 // Logic to accumulate multiple conditions for the same target.
2879 if ($prevandor == 'and') {
2880 $condition = $condition && $prevcond;
2881 } else if ($prevandor == 'or') {
2882 $condition = $condition ||
$prevcond;
2884 $prevandor = $skiprow['andor'];
2885 $prevcond = $condition;
2887 return $prevcond ?
$action : '';
2890 // Load array of names of the given layout and its groups.
2891 function getLayoutProperties($formtype, &$grparr, $sel = "grp_title")
2893 if ($sel != '*' && strpos($sel, 'grp_group_id') === false) {
2894 $sel = "grp_group_id, $sel";
2896 $gres = sqlStatement("SELECT $sel FROM layout_group_properties WHERE grp_form_id = ? " .
2897 "ORDER BY grp_group_id", array($formtype));
2898 while ($grow = sqlFetchArray($gres)) {
2899 $grparr[$grow['grp_group_id']] = $grow;
2903 function display_layout_rows($formtype, $result1, $result2 = '')
2905 global $item_count, $cell_count, $last_group, $CPR;
2908 getLayoutProperties($formtype, $grparr, '*');
2910 $TOPCPR = empty($grparr['']['grp_columns']) ?
4 : $grparr['']['grp_columns'];
2912 $fres = sqlStatement("SELECT * FROM layout_options " .
2913 "WHERE form_id = ? AND uor > 0 " .
2914 "ORDER BY group_id, seq", array($formtype));
2916 while ($frow = sqlFetchArray($fres)) {
2917 $this_group = $frow['group_id'];
2918 $titlecols = $frow['titlecols'];
2919 $datacols = $frow['datacols'];
2920 $data_type = $frow['data_type'];
2921 $field_id = $frow['field_id'];
2922 $list_id = $frow['list_id'];
2925 $CPR = empty($grparr[$this_group]['grp_columns']) ?
$TOPCPR : $grparr[$this_group]['grp_columns'];
2927 if ($formtype == 'DEM') {
2928 if (strpos($field_id, 'em_') === 0) {
2929 // Skip employer related fields, if it's disabled.
2930 if ($GLOBALS['omit_employers']) {
2934 $tmp = substr($field_id, 3);
2935 if (isset($result2[$tmp])) {
2936 $currvalue = $result2[$tmp];
2939 if (isset($result1[$field_id])) {
2940 $currvalue = $result1[$field_id];
2944 if (isset($result1[$field_id])) {
2945 $currvalue = $result1[$field_id];
2949 // Handle a data category (group) change.
2950 if (strcmp($this_group, $last_group) != 0) {
2951 $group_name = $grparr[$this_group]['grp_title'];
2952 // totally skip generating the employer category, if it's disabled.
2953 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
2958 $last_group = $this_group;
2961 // filter out all the empty field data from the patient report.
2962 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2963 // Handle starting of a new row.
2964 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
2968 echo "<td class='groupname'>";
2969 echo text(xl_layout_label($group_name));
2972 echo "<td valign='top'> ";
2978 if ($item_count == 0 && $titlecols == 0) {
2982 // Handle starting of a new label cell.
2983 if ($titlecols > 0) {
2985 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
2986 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES
);
2987 echo "<td class='label_custom' colspan='$titlecols_esc' ";
2988 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2990 $cell_count +
= $titlecols;
2995 // Added 5-09 by BM - Translate label if applicable
2996 if ($frow['title']) {
2997 $tmp = xl_layout_label($frow['title']);
2999 // Append colon only if label does not end with punctuation.
3000 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3007 // Handle starting of a new data cell.
3008 if ($datacols > 0) {
3010 //echo "<td class='text data' colspan='$datacols' valign='top'";
3011 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES
);
3012 echo "<td class='text data' colspan='$datacols_esc'";
3013 //if ($cell_count > 0) echo " style='padding-left:5pt'";
3015 $cell_count +
= $datacols;
3019 echo generate_display_field($frow, $currvalue);
3026 function display_layout_tabs($formtype, $result1, $result2 = '')
3028 global $item_count, $cell_count, $last_group, $CPR;
3031 getLayoutProperties($formtype, $grparr);
3033 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3034 "WHERE form_id = ? AND uor > 0 " .
3035 "ORDER BY group_id", array($formtype));
3038 while ($frow = sqlFetchArray($fres)) {
3039 $this_group = $frow['group_id'];
3040 // $group_name = substr($this_group, 1);
3041 $group_name = $grparr[$this_group]['grp_title'];
3042 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3046 <li
<?php
echo $first ?
'class="current"' : '' ?
>>
3047 <a href
="#" id
="header_tab_<?php echo htmlspecialchars($group_name, ENT_QUOTES); ?>">
3048 <?php
echo htmlspecialchars(xl_layout_label($group_name), ENT_NOQUOTES
); ?
></a
>
3055 function display_layout_tabs_data($formtype, $result1, $result2 = '')
3057 global $item_count, $cell_count, $last_group, $CPR;
3060 getLayoutProperties($formtype, $grparr, '*');
3062 $TOPCPR = empty($grparr['']['grp_columns']) ?
4 : $grparr['']['grp_columns'];
3064 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3065 "WHERE form_id = ? AND uor > 0 " .
3066 "ORDER BY group_id", array($formtype));
3069 while ($frow = sqlFetchArray($fres)) {
3070 $this_group = isset($frow['group_id']) ?
$frow['group_id'] : "" ;
3072 if ($grparr[$this_group]['grp_columns'] === 'Employer' && $GLOBALS['omit_employers']) {
3075 $CPR = empty($grparr[$this_group]['grp_columns']) ?
$TOPCPR : $grparr[$this_group]['grp_columns'];
3076 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ?
'' : $grparr[$this_group]['grp_subtitle'];
3078 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3079 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3080 "ORDER BY seq", array($formtype, $this_group));
3083 <div
class="tab <?php echo $first ? 'current' : '' ?>">
3084 <table border
='0' cellpadding
='0'>
3087 while ($group_fields = sqlFetchArray($group_fields_query)) {
3088 $titlecols = $group_fields['titlecols'];
3089 $datacols = $group_fields['datacols'];
3090 $data_type = $group_fields['data_type'];
3091 $field_id = $group_fields['field_id'];
3092 $list_id = $group_fields['list_id'];
3094 $edit_options = $group_fields['edit_options'];
3096 if ($formtype == 'DEM') {
3097 if (strpos($field_id, 'em_') === 0) {
3098 // Skip employer related fields, if it's disabled.
3099 if ($GLOBALS['omit_employers']) {
3103 $tmp = substr($field_id, 3);
3104 if (isset($result2[$tmp])) {
3105 $currvalue = $result2[$tmp];
3108 if (isset($result1[$field_id])) {
3109 $currvalue = $result1[$field_id];
3113 if (isset($result1[$field_id])) {
3114 $currvalue = $result1[$field_id];
3118 // Skip this field if action conditions call for that.
3119 // Note this also accumulates info for subsequent skip tests.
3120 $skip_this_field = isSkipped($group_fields, $currvalue) == 'skip';
3122 // Skip this field if its do-not-print option is set.
3123 if (strpos($edit_options, 'X') !== false) {
3124 $skip_this_field = true;
3127 // Handle a data category (group) change.
3128 if (strcmp($this_group, $last_group) != 0) {
3129 $group_name = $grparr[$this_group]['grp_title'];
3130 // totally skip generating the employer category, if it's disabled.
3131 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3134 $last_group = $this_group;
3137 // Handle starting of a new row.
3138 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
3141 // Group subtitle exists and is not displayed yet.
3142 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3143 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3149 if ($item_count == 0 && $titlecols == 0) {
3153 // Handle starting of a new label cell.
3154 if ($titlecols > 0) {
3156 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES
);
3157 $field_id_label = 'label_'.$group_fields['field_id'];
3158 echo "<td class='label_custom' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
3160 $cell_count +
= $titlecols;
3165 $field_id_label = 'label_'.$group_fields['field_id'];
3166 echo "<span id='".attr($field_id_label)."'>";
3167 if ($skip_this_field) {
3168 // No label because skipping
3169 } else if ($group_fields['title']) {
3170 $tmp = xl_layout_label($group_fields['title']);
3172 // Append colon only if label does not end with punctuation.
3173 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3181 // Handle starting of a new data cell.
3182 if ($datacols > 0) {
3184 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES
);
3185 $field_id = 'text_'.$group_fields['field_id'];
3186 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
3187 if (!$skip_this_field && $data_type == 3) {
3188 // Textarea gets a light grey border.
3189 echo " style='border:1px solid #cccccc'";
3192 $cell_count +
= $datacols;
3194 $field_id = 'text_'.$group_fields['field_id'];
3195 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
3199 if (!$skip_this_field) {
3200 echo generate_display_field($group_fields, $currvalue);
3216 function display_layout_tabs_data_editable($formtype, $result1, $result2 = '')
3218 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
3221 getLayoutProperties($formtype, $grparr, '*');
3223 $TOPCPR = empty($grparr['']['grp_columns']) ?
4 : $grparr['']['grp_columns'];
3225 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3226 "WHERE form_id = ? AND uor > 0 " .
3227 "ORDER BY group_id", array($formtype));
3230 $condition_str = '';
3232 while ($frow = sqlFetchArray($fres)) {
3233 $this_group = $frow['group_id'];
3234 $group_name = $grparr[$this_group]['grp_title'];
3235 $group_name_esc = text($group_name);
3237 if ($grparr[$this_group]['grp_title'] === 'Employer' && $GLOBALS['omit_employers']) {
3240 $CPR = empty($grparr[$this_group]['grp_columns']) ?
$TOPCPR : $grparr[$this_group]['grp_columns'];
3241 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ?
'' : $grparr[$this_group]['grp_subtitle'];
3243 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3244 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3245 "ORDER BY seq", array($formtype, $this_group));
3248 <div
class="tab <?php echo $first ? 'current' : '' ?>" id
="tab_<?php echo str_replace(' ', '_', $group_name_esc)?>" >
3249 <table border
='0' cellpadding
='0'>
3252 while ($group_fields = sqlFetchArray($group_fields_query)) {
3253 $titlecols = $group_fields['titlecols'];
3254 $datacols = $group_fields['datacols'];
3255 $data_type = $group_fields['data_type'];
3256 $field_id = $group_fields['field_id'];
3257 $list_id = $group_fields['list_id'];
3258 $backup_list = $group_fields['list_backup_id'];
3262 // Accumulate action conditions into a JSON expression for the browser side.
3263 accumActionConditions($field_id, $condition_str, $group_fields['conditions']);
3265 if ($formtype == 'DEM') {
3266 if (strpos($field_id, 'em_') === 0) {
3267 // Skip employer related fields, if it's disabled.
3268 if ($GLOBALS['omit_employers']) {
3272 $tmp = substr($field_id, 3);
3273 if (isset($result2[$tmp])) {
3274 $currvalue = $result2[$tmp];
3277 if (isset($result1[$field_id])) {
3278 $currvalue = $result1[$field_id];
3282 if (isset($result1[$field_id])) {
3283 $currvalue = $result1[$field_id];
3287 // Handle a data category (group) change.
3288 if (strcmp($this_group, $last_group) != 0) {
3289 // totally skip generating the employer category, if it's disabled.
3290 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3294 $last_group = $this_group;
3297 // Handle starting of a new row.
3298 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
3301 // Group subtitle exists and is not displayed yet.
3302 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3303 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3309 if ($item_count == 0 && $titlecols == 0) {
3313 // Handle starting of a new label cell.
3314 if ($titlecols > 0) {
3316 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES
);
3317 $field_id_label = 'label_'.$group_fields['field_id'];
3318 echo "<td class='label_custom' colspan='$titlecols_esc'";
3319 // This ID is used by skip conditions.
3320 echo " id='label_id_" . attr($field_id) . "'";
3322 $cell_count +
= $titlecols;
3327 if ($group_fields['title']) {
3328 $tmp = xl_layout_label($group_fields['title']);
3330 // Append colon only if label does not end with punctuation.
3331 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3338 // Handle starting of a new data cell.
3339 if ($datacols > 0) {
3341 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES
);
3342 $field_id = 'text_'.$group_fields['field_id'];
3343 echo "<td class='text data' colspan='$datacols_esc'";
3344 // This ID is used by action conditions.
3345 echo " id='value_id_" . attr($field_id) . "'";
3347 $cell_count +
= $datacols;
3352 echo generate_form_field($group_fields, $currvalue);
3365 // From the currently posted HTML form, this gets the value of the
3366 // field corresponding to the provided layout_options table row.
3368 function get_layout_form_value($frow, $prefix = 'form_')
3370 $maxlength = empty($frow['max_length']) ?
0 : intval($frow['max_length']);
3371 $data_type = $frow['data_type'];
3372 $field_id = $frow['field_id'];
3374 if (isset($_POST["$prefix$field_id"])) {
3375 if ($data_type == 21) {
3376 if (!$frow['list_id']) {
3377 if (!empty($_POST["form_$field_id"])) {
3378 $value = xlt('Yes');
3381 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
3382 // must be concatenated into a |-separated string.
3383 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3384 if (strlen($value)) {
3390 } else if ($data_type == 22) {
3391 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
3392 // into "key:value|key:value|...".
3393 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3394 $val = str_replace('|', ' ', $val);
3395 if (strlen($value)) {
3399 $value .= "$key:$val";
3401 } else if ($data_type == 23) {
3402 // $_POST["$prefix$field_id"] is an array of text fields with companion
3403 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
3404 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3405 $restype = $_POST["radio_{$field_id}"][$key];
3406 if (empty($restype)) {
3410 $val = str_replace('|', ' ', $val);
3411 if (strlen($value)) {
3415 $value .= "$key:$restype:$val";
3417 } else if ($data_type == 25) {
3418 // $_POST["$prefix$field_id"] is an array of text fields with companion
3419 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
3420 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3421 $restype = empty($_POST["check_{$field_id}"][$key]) ?
'0' : '1';
3422 $val = str_replace('|', ' ', $val);
3423 if (strlen($value)) {
3427 $value .= "$key:$restype:$val";
3429 } else if ($data_type == 28 ||
$data_type == 32) {
3430 // $_POST["$prefix$field_id"] is an date text fields with companion
3431 // radio buttons to be imploded into "notes|type|date".
3432 $restype = $_POST["radio_{$field_id}"];
3433 if (empty($restype)) {
3437 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
3438 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3439 if ($data_type == 32) {
3440 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
3441 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3442 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
3443 $value = "$res_text_note|$restype|$resdate|$reslist";
3445 $value = "$resnote|$restype|$resdate";
3447 } else if ($data_type == 36) {
3448 $value_array = $_POST["form_$field_id"];
3450 foreach ($value_array as $key => $valueofkey) {
3452 $value = $valueofkey;
3454 $value = $value . "|" . $valueofkey;
3460 $value = $_POST["$prefix$field_id"];
3464 // Better to die than to silently truncate data!
3465 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength) {
3466 die(htmlspecialchars(xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES
) .
3467 ":<br /> <br />".htmlspecialchars($value, ENT_NOQUOTES
));
3470 return trim($value);
3473 // Generate JavaScript validation logic for the required fields.
3475 function generate_layout_validation($form_id)
3477 $fres = sqlStatement("SELECT * FROM layout_options " .
3478 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
3479 "ORDER BY group_id, seq", array($form_id));
3481 while ($frow = sqlFetchArray($fres)) {
3482 $data_type = $frow['data_type'];
3483 $field_id = $frow['field_id'];
3484 $fldtitle = $frow['title'];
3486 $fldtitle = $frow['description'];
3489 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES
);
3491 if ($data_type == 40) {
3492 $fldid = addslashes("form_$field_id");
3493 // Move canvas image data to its hidden form field so the server will get it.
3495 " var canfld = f['$fldid'];\n" .
3496 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
3500 if ($frow['uor'] < 2) {
3504 echo " if (f.$fldname && !f.$fldname.disabled) {\n";
3505 switch ($data_type) {
3513 " if (f.$fldname.selectedIndex <= 0) {\n" .
3514 " alert(\"" . addslashes(xl('Please choose a value for')) .
3515 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3516 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3517 " return false;\n" .
3522 " if (f.$fldname.selectedIndex <= 0) {\n" .
3523 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3524 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3527 case 27: // radio buttons
3530 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
3531 " if (i >= f.$fldname.length) {\n" .
3532 " alert(\"" . addslashes(xl('Please choose a value for')) .
3533 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3534 " return false;\n" .
3542 " if (trimlen(f.$fldname.value) == 0) {\n" .
3543 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3544 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
3545 " $('#" . $fldname . "').attr('style','background:red'); \n" .
3546 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3548 " $('#" . $fldname . "').attr('style',''); " .
3549 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
3552 case 36: // multi select
3554 " var multi_select=f['$fldname"."[]']; \n " .
3555 " var multi_choice_made=false; \n".
3556 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
3557 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
3559 " if(!multi_choice_made)
3560 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3569 * DROPDOWN FOR FACILITIES
3571 * build a dropdown with all facilities
3573 * @param string $selected - name of the currently selected facility
3574 * use '0' for "unspecified facility"
3575 * use '' for "All facilities" (the default)
3576 * @param string $name - the name/id for select form (defaults to "form_facility")
3577 * @param boolean $allow_unspecified - include an option for "unspecified" facility
3579 * @return void - just echo the html encoded string
3581 * Note: This should become a data-type at some point, according to Brady
3583 function dropdown_facility(
3585 $name = 'form_facility',
3586 $allow_unspecified = true,
3587 $allow_allfacilities = true,
3592 global $facilityService;
3594 $have_selected = false;
3595 $fres = $facilityService->getAll();
3597 $name = htmlspecialchars($name, ENT_QUOTES
);
3598 echo " <select class='form-control' name='$name' id='$name'";
3600 echo " onchange='$onchange'";
3603 echo " $disabled>\n";
3605 if ($allow_allfacilities) {
3607 $option_selected_attr = '';
3608 if ($selected == '') {
3609 $option_selected_attr = ' selected="selected"';
3610 $have_selected = true;
3613 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES
);
3614 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3615 } elseif ($allow_unspecified) {
3616 $option_value = '0';
3617 $option_selected_attr = '';
3618 if ($selected == '0') {
3619 $option_selected_attr = ' selected="selected"';
3620 $have_selected = true;
3623 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
3624 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3627 foreach ($fres as $frow) {
3628 $facility_id = $frow['id'];
3629 $option_value = htmlspecialchars($facility_id, ENT_QUOTES
);
3630 $option_selected_attr = '';
3631 if ($selected == $facility_id) {
3632 $option_selected_attr = ' selected="selected"';
3633 $have_selected = true;
3636 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES
);
3637 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3640 if ($allow_unspecified && $allow_allfacilities) {
3641 $option_value = '0';
3642 $option_selected_attr = '';
3643 if ($selected == '0') {
3644 $option_selected_attr = ' selected="selected"';
3645 $have_selected = true;
3648 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
3649 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3652 if (!$have_selected) {
3653 $option_value = htmlspecialchars($selected, ENT_QUOTES
);
3654 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES
);
3655 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES
);
3656 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
3659 echo " </select>\n";
3662 // Expand Collapse Widget
3663 // This forms the header and functionality component of the widget. The information that is displayed
3664 // then follows this function followed by a closing div tag
3666 // $title is the title of the section (already translated)
3667 // $label is identifier used in the tag id's and sql columns
3668 // $buttonLabel is the button label text (already translated)
3669 // $buttonLink is the button link information
3670 // $buttonClass is any additional needed class elements for the button tag
3671 // $linkMethod is the button link method ('javascript' vs 'html')
3672 // $bodyClass is to set class(es) of the body
3673 // $auth is a flag to decide whether to show the button
3674 // $fixedWidth is to flag whether width is fixed
3675 // $forceExpandAlways is a flag to force the widget to always be expanded
3677 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways = false)
3680 echo "<div class='section-header'>";
3682 echo "<div class='section-header-dynamic'>";
3687 // show button, since authorized
3688 // first prepare class string
3690 $class_string = "css_button_small ".htmlspecialchars($buttonClass, ENT_NOQUOTES
);
3692 $class_string = "css_button_small";
3695 // next, create the link
3696 if ($linkMethod == "javascript") {
3697 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3699 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3700 if (!isset($_SESSION['patient_portal_onsite']) && !isset($_SESSION['patient_portal_onsite_two'])) {
3701 // prevent an error from occuring when calling the function from the patient portal
3702 echo " onclick='top.restoreSession()'";
3707 htmlspecialchars($buttonLabel, ENT_NOQUOTES
) . "</span></a></td>";
3710 if ($forceExpandAlways) {
3711 // Special case to force the widget to always be expanded
3712 echo "<td><span class='text'><b>" . htmlspecialchars($title, ENT_NOQUOTES
) . "</b></span>";
3713 $indicatorTag ="style='display:none'";
3716 $indicatorTag = isset($indicatorTag) ?
$indicatorTag : "";
3717 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3718 htmlspecialchars($label, ENT_QUOTES
) . "_ps_expand\")'><span class='text'><b>";
3719 echo htmlspecialchars($title, ENT_NOQUOTES
) . "</b></span>";
3721 if (isset($_SESSION['patient_portal_onsite']) ||
isset($_SESSION['patient_portal_onsite_two'])) {
3722 // collapse all entries in the patient portal
3723 $text = xl('expand');
3724 } else if (getUserSetting($label."_ps_expand")) {
3725 $text = xl('collapse');
3727 $text = xl('expand');
3730 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES
) .
3731 "</span>)</a></td>";
3732 echo "</tr></table>";
3734 if ($forceExpandAlways) {
3735 // Special case to force the widget to always be expanded
3737 } else if (isset($_SESSION['patient_portal_onsite']) ||
isset($_SESSION['patient_portal_onsite_two'])) {
3738 // collapse all entries in the patient portal
3739 $styling = "style='display:none'";
3740 } else if (getUserSetting($label."_ps_expand")) {
3743 $styling = "style='display:none'";
3747 $styling .= " class='" . $bodyClass . "'";
3750 //next, create the first div tag to hold the information
3751 // note the code that calls this function will then place the ending div tag after the data
3752 echo "<div id='" . htmlspecialchars($label, ENT_QUOTES
) . "_ps_expand' " . $styling . ">";
3755 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3756 function billing_facility($name, $select)
3758 global $facilityService;
3760 $fres = $facilityService->getAllBillingLocations();
3761 echo " <select id='".htmlspecialchars($name, ENT_QUOTES
)."' class='form-control' name='".htmlspecialchars($name, ENT_QUOTES
)."'>";
3762 foreach ($fres as $facrow) {
3763 $selected = ( $facrow['id'] == $select ) ?
'selected="selected"' : '' ;
3764 echo "<option value=".htmlspecialchars($facrow['id'], ENT_QUOTES
)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES
)."</option>";
3770 // Generic function to get the translated title value for a particular list option.
3772 function getListItemTitle($list, $option)
3774 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3775 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3776 if (empty($row['title'])) {
3780 return xl_list_label($row['title']);
3782 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3783 function getSmokeCodes()
3785 $smoking_codes_arr = array();
3786 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3787 while ($codes_row = sqlFetchArray($smoking_codes)) {
3788 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3791 return $smoking_codes_arr;
3794 // Get the current value for a layout based form field.
3795 // Depending on options this might come from lbf_data, patient_data,
3796 // form_encounter, shared_attributes or elsewhere.
3797 // Returns FALSE if the field ID is invalid (layout error).
3799 function lbf_current_value($frow, $formid, $encounter)
3802 $formname = $frow['form_id'];
3803 $field_id = $frow['field_id'];
3804 $source = $frow['source'];
3806 $deffname = $formname . '_default_' . $field_id;
3807 if ($source == 'D' ||
$source == 'H') {
3808 // Get from patient_data, employer_data or history_data.
3809 if ($source == 'H') {
3810 $table = 'history_data';
3811 $orderby = 'ORDER BY date DESC LIMIT 1';
3812 } else if (strpos($field_id, 'em_') === 0) {
3813 $field_id = substr($field_id, 3);
3814 $table = 'employer_data';
3815 $orderby = 'ORDER BY date DESC LIMIT 1';
3817 $table = 'patient_data';
3821 // It is an error if the field does not exist, but don't crash.
3822 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3827 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3828 if (isset($pdrow)) {
3829 $currvalue = $pdrow['field_value'];
3831 } else if ($source == 'E') {
3834 // Get value from shared_attributes of the current encounter.
3836 "SELECT field_value FROM shared_attributes WHERE " .
3837 "pid = ? AND encounter = ? AND field_id = ?",
3838 array($pid, $encounter, $field_id)
3840 if (!empty($sarow)) {
3841 $currvalue = $sarow['field_value'];
3843 } else if ($formid) {
3844 // Get from shared_attributes of the encounter that this form is linked to.
3845 // Note the importance of having an index on forms.form_id.
3847 "SELECT sa.field_value " .
3848 "FROM forms AS f, shared_attributes AS sa WHERE " .
3849 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3850 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3851 array($formid, $formname, $field_id)
3853 if (!empty($sarow)) {
3854 $currvalue = $sarow['field_value'];
3857 // New form and encounter not available, this should not happen.
3859 if (empty($sarow) && !$formid) {
3860 // New form, see if there is a custom default from a plugin.
3861 if (function_exists($deffname)) {
3862 $currvalue = call_user_func($deffname);
3865 } else if ($source == 'V') {
3867 // Get value from the current encounter's form_encounter.
3869 "SELECT * FROM form_encounter WHERE " .
3870 "pid = ? AND encounter = ?",
3871 array($pid, $encounter)
3873 if (isset($ferow[$field_id])) {
3874 $currvalue = $ferow[$field_id];
3876 } else if ($formid) {
3877 // Get value from the form_encounter that this form is linked to.
3880 "FROM forms AS f, form_encounter AS fe WHERE " .
3881 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3882 "fe.pid = f.pid AND fe.encounter = f.encounter",
3883 array($formid, $formname)
3885 if (isset($ferow[$field_id])) {
3886 $currvalue = $ferow[$field_id];
3889 // New form and encounter not available, this should not happen.
3891 } else if ($formid) {
3892 // This is a normal form field.
3893 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3894 "form_id = ? AND field_id = ?", array($formid, $field_id));
3895 if (!empty($ldrow)) {
3896 $currvalue = $ldrow['field_value'];
3899 // New form, see if there is a custom default from a plugin.
3900 if (function_exists($deffname)) {
3901 $currvalue = call_user_func($deffname);
3908 // This returns stuff that needs to go into the <head> section of a caller using
3909 // the drawable image field type in a form.
3910 // A TRUE argument makes the widget controls smaller.
3912 function lbf_canvas_head($small = true)
3915 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3916 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3917 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3918 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3923 /* Custom LiterallyCanvas styling.
3924 * This makes the widget 25% less tall and adjusts some other things accordingly.
3927 min-height:100%;min-width:300px; /* Was 400, unspecified */
3929 .literally .lc-picker .toolbar-button {
3930 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3932 .literally .color-well {
3933 font-size:8px;width:49px; /* Was 10, 60 */
3935 .literally .color-well-color-container {
3936 width:21px;height:21px; /* Was 28, 28 */
3938 .literally .lc-picker {
3939 width:50px; /* Was 61 */
3941 .literally .lc-drawing.with-gui {
3942 left:50px; /* Was 61 */
3944 .literally .lc-options {
3945 left:50px; /* Was 61 */
3947 .literally .color-picker-popup {
3948 left:49px;bottom:0px; /* Was 60, 31 */