Percent-based price levels (#2577)
[openemr.git] / library / options.inc.php
blob56f0c851099c96cf2e1f678c757b14a2bf5557e1
1 <?php
2 // Copyright (C) 2007-2019 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 // Documentation for layout_options.edit_options:
21 // A = Age as years or "xx month(s)"
22 // B = Gestational age as "xx week(s) y day(s)"
23 // C = Capitalize first letter of each word (text fields)
24 // D = Check for duplicates in New Patient form
25 // G = Graphable (for numeric fields in forms supporting historical data)
26 // H = Read-only field copied from static history (this is obsolete)
27 // J = Jump to Next Row
28 // K = Prepend Blank Row
29 // L = Lab Order ("ord_lab") types only (address book)
30 // M = Radio Group Master (currently for radio buttons only)
31 // m = Radio Group Member (currently for radio buttons only)
32 // N = Show in New Patient form
33 // O = Procedure Order ("ord_*") types only (address book)
34 // P = Default to previous value when current value is not yet set
35 // R = Distributor types only (address book)
36 // T = Use description as default Text
37 // U = Capitalize all letters (text fields)
38 // V = Vendor types only (address book)
39 // 0 = Read Only - the input element's "disabled" property is set
40 // 1 = Write Once (not editable when not empty) (text fields)
41 // 2 = Show descriptions instead of codes for billing code input
43 require_once("user.inc");
44 require_once("patient.inc");
45 require_once("lists.inc");
46 require_once(dirname(dirname(__FILE__)) . "/custom/code_types.inc.php");
48 use OpenEMR\Services\FacilityService;
50 $facilityService = new FacilityService();
52 $date_init = "";
53 $membership_group_number = 0;
55 function get_pharmacies()
57 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
58 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
59 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
60 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
61 "AND p.type = 2 " .
62 "ORDER BY state, city, name, area_code, prefix, number");
65 function optionalAge($frow, $date, &$asof, $description = '')
67 $asof = '';
68 if (empty($date)) {
69 return '';
72 $date = substr($date, 0, 10);
73 if (isOption($frow['edit_options'], 'A') !== false) {
74 $format = 0;
75 } elseif (isOption($frow['edit_options'], 'B') !== false) {
76 $format = 3;
77 } else {
78 return '';
81 if (isOption($frow['form_id'], 'LBF') === 0) {
82 $tmp = sqlQuery(
83 "SELECT date FROM form_encounter WHERE " .
84 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
85 array($GLOBALS['pid'], $GLOBALS['encounter'])
87 if (!empty($tmp['date'])) {
88 $asof = substr($tmp['date'], 0, 10);
91 if ($description === '') {
92 $prefix = ($format ? xl('Gest age') : xl('Age')) . ' ';
93 } else {
94 $prefix = $description . ' ';
96 return $prefix . oeFormatAge($date, $asof, $format);
99 // Function to generate a drop-list.
101 function generate_select_list(
102 $tag_name,
103 $list_id,
104 $currvalue,
105 $title,
106 $empty_name = ' ',
107 $class = '',
108 $onchange = '',
109 $tag_id = '',
110 $custom_attributes = null,
111 $multiple = false,
112 $backup_list = ''
114 $s = '';
116 $tag_name_esc = attr($tag_name);
118 if ($multiple) {
119 $tag_name_esc = $tag_name_esc . "[]";
122 $s .= "<select name='$tag_name_esc'";
124 if ($multiple) {
125 $s .= " multiple='multiple'";
128 $tag_id_esc = attr($tag_name);
130 if ($tag_id != '') {
131 $tag_id_esc = attr($tag_id);
134 $s .= " id='$tag_id_esc'";
136 if (!empty($class)) {
137 $class_esc = attr($class);
138 $s .= " class='form-control $class_esc'";
139 } else {
140 $s .= " class='form-control'";
143 if ($onchange) {
144 $s .= " onchange='$onchange'";
147 if ($custom_attributes != null && is_array($custom_attributes)) {
148 foreach ($custom_attributes as $attr => $val) {
149 if (isset($custom_attributes [$attr])) {
150 $s .= " " . attr($attr) . "='" . attr($val) . "'";
155 $selectTitle = attr($title);
156 $s .= " title='$selectTitle'>";
157 $selectEmptyName = xlt($empty_name);
158 if ($empty_name) {
159 $s .= "<option value=''>" . $selectEmptyName . "</option>";
162 // List order depends on language translation options.
163 // (Note we do not need to worry about the list order in the algorithm
164 // after the below code block since that is where searches for exceptions
165 // are done which include inactive items or items from a backup
166 // list; note these will always be shown at the bottom of the list no matter the
167 // chosen order.)
168 $lang_id = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
169 // sort by title
170 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) || !$GLOBALS['translate_lists']) {
171 // do not translate
172 if ($GLOBALS['gb_how_sort_list'] == '0') {
173 // order by seq
174 $order_by_sql = "seq, title";
175 } else { //$GLOBALS['gb_how_sort_list'] == '1'
176 // order by title
177 $order_by_sql = "title, seq";
180 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
181 } else {
182 // do translate
183 if ($GLOBALS['gb_how_sort_list'] == '0') {
184 // order by seq
185 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
186 } else { //$GLOBALS['gb_how_sort_list'] == '1'
187 // order by title
188 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
191 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
192 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
193 "FROM list_options AS lo " .
194 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
195 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
196 "ld.lang_id = ? " .
197 "WHERE lo.list_id = ? AND lo.activity=1 " .
198 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
201 $got_selected = false;
203 while ($lrow = sqlFetchArray($lres)) {
204 $selectedValues = explode("|", $currvalue);
206 $optionValue = attr($lrow ['option_id']);
207 $s .= "<option value='$optionValue'";
209 if ((strlen($currvalue) == 0 && $lrow ['is_default']) || (strlen($currvalue) > 0 && in_array($lrow ['option_id'], $selectedValues))) {
210 $s .= " selected";
211 $got_selected = true;
214 // Already has been translated above (if applicable), so do not need to use
215 // the xl_list_label() function here
216 $optionLabel = text($lrow ['title']);
217 $s .= ">$optionLabel</option>\n";
221 To show the inactive item in the list if the value is saved to database
223 if (!$got_selected && strlen($currvalue) > 0) {
224 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
225 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
226 $lrow_inactive = sqlFetchArray($lres_inactive);
227 if ($lrow_inactive['option_id']) {
228 $optionValue = htmlspecialchars($lrow_inactive['option_id'], ENT_QUOTES);
229 $s .= "<option value='$optionValue' selected>" . htmlspecialchars(xl_list_label($lrow_inactive['title']), ENT_NOQUOTES) . "</option>\n";
230 $got_selected = true;
234 if (!$got_selected && strlen($currvalue) > 0 && !$multiple) {
235 $list_id = $backup_list;
236 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
238 if ($lrow > 0 && !empty($backup_list)) {
239 $selected = text(xl_list_label($lrow ['title']));
240 $s .= "<option value='$currescaped' selected> $selected </option>";
241 $s .= "</select>";
242 } else {
243 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
244 $s .= "</select>";
245 $fontTitle = xlt('Please choose a valid selection from the list.');
246 $fontText = xlt('Fix this');
247 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
249 } elseif (!$got_selected && strlen($currvalue) > 0 && $multiple) {
250 //if not found in main list, display all selected values that exist in backup list
251 $list_id = $backup_list;
253 $got_selected_backup = false;
254 if (!empty($backup_list)) {
255 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
256 while ($lrow_backup = sqlFetchArray($lres_backup)) {
257 $selectedValues = explode("|", $currvalue);
259 $optionValue = attr($lrow_backup['option_id']);
261 if (in_array($lrow_backup ['option_id'], $selectedValues)) {
262 $s .= "<option value='$optionValue'";
263 $s .= " selected";
264 $optionLabel = text(xl_list_label($lrow_backup ['title']));
265 $s .= ">$optionLabel</option>\n";
266 $got_selected_backup = true;
271 if (!$got_selected_backup) {
272 $selectedValues = explode("|", $currvalue);
273 foreach ($selectedValues as $selectedValue) {
274 $s .= "<option value='" . attr($selectedValue) . "'";
275 $s .= " selected";
276 $s .= ">* " . text($selectedValue) . " *</option>\n";
279 $s .= "</select>";
280 $fontTitle = xlt('Please choose a valid selection from the list.');
281 $fontText = xlt('Fix this');
282 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
284 } else {
285 $s .= "</select>";
288 return $s;
291 // Parsing for data type 31, static text.
292 function parse_static_text($frow)
294 $tmp = $frow['description'];
295 // Translate if it does not look like HTML.
296 if (substr($tmp, 0, 1) != '<') {
297 $tmp = nl2br(xl_layout_label($tmp));
299 $s = '';
300 if ($frow['source'] == 'D' || $frow['source'] == 'H') {
301 // Source is demographics or history. This case supports value substitution.
302 while (preg_match('/^(.*?)\{(\w+)\}(.*)$/', $tmp, $matches)) {
303 $s .= $matches[1];
304 $tmprow = $frow;
305 $tmprow['field_id'] = $matches[2];
306 $s .= lbf_current_value($tmprow, 0, 0);
307 $tmp = $matches[3];
310 $s .= $tmp;
311 return $s;
314 // $frow is a row from the layout_options table.
315 // $currvalue is the current value, if any, of the associated item.
317 function generate_form_field($frow, $currvalue)
319 global $rootdir, $date_init, $ISSUE_TYPES, $code_types, $membership_group_number;
321 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
323 $data_type = $frow['data_type'];
324 $field_id = $frow['field_id'];
325 $list_id = $frow['list_id'];
326 $backup_list = $frow['list_backup_id'];
328 // escaped variables to use in html
329 $field_id_esc= htmlspecialchars($field_id, ENT_QUOTES);
330 $list_id_esc = htmlspecialchars($list_id, ENT_QUOTES);
332 // Added 5-09 by BM - Translate description if applicable
333 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
335 // Support edit option T which assigns the (possibly very long) description as
336 // the default value.
337 if (isOption($frow['edit_options'], 'T') !== false) {
338 if (strlen($currescaped) == 0) {
339 $currescaped = $description;
342 // Description used in this way is not suitable as a title.
343 $description = '';
346 // added 5-2009 by BM to allow modification of the 'empty' text title field.
347 // Can pass $frow['empty_title'] with this variable, otherwise
348 // will default to 'Unassigned'.
349 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
350 // if make $frow['empty_title'] equal to 'SKIP'
351 $showEmpty = true;
352 if (isset($frow['empty_title'])) {
353 if ($frow['empty_title'] == "SKIP") {
354 //do not display an 'empty' choice
355 $showEmpty = false;
356 $empty_title = "Unassigned";
357 } else {
358 $empty_title = $frow['empty_title'];
360 } else {
361 $empty_title = "Unassigned";
364 $disabled = isOption($frow['edit_options'], '0') === false ? '' : 'disabled';
366 $lbfchange = (
367 strpos($frow['form_id'], 'LBF') === 0 ||
368 strpos($frow['form_id'], 'LBT') === 0 ||
369 $frow['form_id'] == 'DEM' ||
370 $frow['form_id'] == 'HIS'
371 ) ? "checkSkipConditions();" : "";
372 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
374 // generic single-selection list or Race and Ethnicity.
375 // These data types support backup lists.
376 if ($data_type == 1 || $data_type == 33) {
377 echo generate_select_list(
378 "form_$field_id",
379 $list_id,
380 $currvalue,
381 $description,
382 ($showEmpty ? $empty_title : ''),
384 $lbfchange,
386 ($disabled ? array('disabled' => 'disabled') : null),
387 false,
388 $backup_list
390 } elseif ($data_type == 2) { // simple text field
391 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
392 $maxlength = $frow['max_length'];
393 $string_maxlength = "";
394 // if max_length is set to zero, then do not set a maxlength
395 if ($maxlength) {
396 $string_maxlength = "maxlength='".attr($maxlength)."'";
399 echo "<input type='text'" .
400 " class='form-control'" .
401 " name='form_$field_id_esc'" .
402 " id='form_$field_id_esc'" .
403 " size='$fldlength'" .
404 " $string_maxlength" .
405 " title='$description'" .
406 " value='$currescaped'";
407 $tmp = $lbfchange;
408 if (isOption($frow['edit_options'], 'C') !== false) {
409 $tmp .= "capitalizeMe(this);";
410 } elseif (isOption($frow['edit_options'], 'U') !== false) {
411 $tmp .= "this.value = this.value.toUpperCase();";
414 if ($tmp) {
415 echo " onchange='$tmp'";
418 $tmp = htmlspecialchars($GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
419 // If mask is for use at save time, treat as no mask.
420 if (strpos($tmp, '^') !== false) {
421 $tmp = '';
423 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
424 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
425 echo " onblur='maskblur(this,\"$tmp\")'";
428 if (isOption($frow['edit_options'], '1') !== false && strlen($currescaped) > 0) {
429 echo " readonly";
432 if ($disabled) {
433 echo ' disabled';
436 echo " />";
437 } elseif ($data_type == 3) { // long or multi-line text field
438 $textCols = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
439 $textRows = htmlspecialchars($frow['fld_rows'], ENT_QUOTES);
440 echo "<textarea" .
441 " name='form_$field_id_esc'" .
442 " class='form-control'" .
443 " id='form_$field_id_esc'" .
444 " title='$description'" .
445 " cols='$textCols'" .
446 " rows='$textRows' $lbfonchange $disabled" .
447 ">" . $currescaped . "</textarea>";
448 } elseif ($data_type == 4) { // date
449 $age_asof_date = ''; // optionalAge() sets this
450 $age_format = isOption($frow['edit_options'], 'A') === false ? 3 : 0;
451 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
452 if ($agestr) {
453 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
456 $onchange_string = '';
457 if (!$disabled && $agestr) {
458 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') " .
459 "updateAgeString('$field_id','$age_asof_date', $age_format, '$description')\"";
461 if ($data_type == 4) {
462 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
463 if (!$modtmp) {
464 $dateValue = oeFormatShortDate(substr($currescaped, 0, 10));
465 echo "<input type='text' size='10' class='datepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
466 " value='" . attr($dateValue) ."'";
467 } else {
468 $dateValue = oeFormatDateTime(substr($currescaped, 0, 20), 0);
469 echo "<input type='text' size='20' class='datetimepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
470 " value='" . attr($dateValue) . "'";
473 if (!$agestr) {
474 echo " title='$description'";
477 echo " $onchange_string $lbfonchange $disabled />";
479 // Optional display of age or gestational age.
480 if ($agestr) {
481 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
483 } elseif ($data_type == 10) { // provider list, local providers only
484 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
485 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
486 "AND authorized = 1 " .
487 "ORDER BY lname, fname");
488 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
489 echo "<option value=''>" . xlt($empty_title) . "</option>";
490 $got_selected = false;
491 while ($urow = sqlFetchArray($ures)) {
492 $uname = text($urow['fname'] . ' ' . $urow['lname']);
493 $optionId = attr($urow['id']);
494 echo "<option value='$optionId'";
495 if ($urow['id'] == $currvalue) {
496 echo " selected";
497 $got_selected = true;
500 echo ">$uname</option>";
503 if (!$got_selected && $currvalue) {
504 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
505 echo "</select>";
506 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
507 } else {
508 echo "</select>";
510 } elseif ($data_type == 11) { // provider list, including address book entries with an NPI number
511 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
512 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
513 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
514 "ORDER BY lname, fname");
515 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
516 echo " $lbfonchange $disabled>";
517 echo "<option value=''>" . xlt('Unassigned') . "</option>";
518 $got_selected = false;
519 while ($urow = sqlFetchArray($ures)) {
520 $uname = text($urow['fname'] . ' ' . $urow['lname']);
521 $optionId = attr($urow['id']);
522 echo "<option value='$optionId'";
523 if ($urow['id'] == $currvalue) {
524 echo " selected";
525 $got_selected = true;
528 echo ">$uname</option>";
531 if (!$got_selected && $currvalue) {
532 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
533 echo "</select>";
534 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
535 } else {
536 echo "</select>";
538 } elseif ($data_type == 12) { // pharmacy list
539 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
540 echo " $lbfonchange $disabled>";
541 echo "<option value='0'></option>";
542 $pres = get_pharmacies();
543 $got_selected = false;
544 $zone ='';
545 while ($prow = sqlFetchArray($pres)) {
546 if ($zone != strtolower(trim($prow['city']))) {
547 if ($zone !='') {
548 echo "</optgroup>";
550 $zone = strtolower(trim($prow['city']));
551 echo "<optgroup label='".attr($prow['city'])."'>";
553 $key = $prow['id'];
554 $optionValue = htmlspecialchars($key, ENT_QUOTES);
555 $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
556 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
557 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
558 echo "<option value='$optionValue'";
559 if ($currvalue == $key) {
560 echo " selected";
561 $got_selected = true;
564 echo ">$optionLabel</option>";
567 if (!$got_selected && $currvalue) {
568 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
569 echo "</select>";
570 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
571 } else {
572 echo "</select>";
574 } elseif ($data_type == 13) { // squads
575 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
576 echo " $lbfonchange $disabled>";
577 echo "<option value=''>&nbsp;</option>";
578 $squads = acl_get_squads();
579 if ($squads) {
580 foreach ($squads as $key => $value) {
581 $optionValue = htmlspecialchars($key, ENT_QUOTES);
582 $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES);
583 echo "<option value='$optionValue'";
584 if ($currvalue == $key) {
585 echo " selected";
588 echo ">$optionLabel</option>\n";
592 echo "</select>";
593 } elseif ($data_type == 14) {
594 // Address book, preferring organization name if it exists and is not in
595 // parentheses, and excluding local users who are not providers.
596 // Supports "referred to" practitioners and facilities.
597 // Alternatively the letter L in edit_options means that abook_type
598 // must be "ord_lab", indicating types used with the procedure
599 // lab ordering system.
600 // Alternatively the letter O in edit_options means that abook_type
601 // must begin with "ord_", indicating types used with the procedure
602 // ordering system.
603 // Alternatively the letter V in edit_options means that abook_type
604 // must be "vendor", indicating the Vendor type.
605 // Alternatively the letter R in edit_options means that abook_type
606 // must be "dist", indicating the Distributor type.
608 if (isOption($frow['edit_options'], 'L') !== false) {
609 $tmp = "abook_type = 'ord_lab'";
610 } elseif (isOption($frow['edit_options'], 'O') !== false) {
611 $tmp = "abook_type LIKE 'ord\\_%'";
612 } elseif (isOption($frow['edit_options'], 'V') !== false) {
613 $tmp = "abook_type LIKE 'vendor%'";
614 } elseif (isOption($frow['edit_options'], 'R') !== false) {
615 $tmp = "abook_type LIKE 'dist'";
616 } else {
617 $tmp = "( username = '' OR authorized = 1 )";
620 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
621 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
622 "AND $tmp " .
623 "ORDER BY organization, lname, fname");
624 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
625 echo " $lbfonchange $disabled>";
626 echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES) . "</option>";
627 while ($urow = sqlFetchArray($ures)) {
628 $uname = $urow['organization'];
629 if (empty($uname) || substr($uname, 0, 1) == '(') {
630 $uname = $urow['lname'];
631 if ($urow['fname']) {
632 $uname .= ", " . $urow['fname'];
636 $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES);
637 $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES);
638 echo "<option value='$optionValue'";
639 // Failure to translate Local and External is not an error here;
640 // they are only used as internal flags and must not be translated!
641 $title = $urow['username'] ? 'Local' : 'External';
642 $optionTitle = htmlspecialchars($title, ENT_QUOTES);
643 echo " title='$optionTitle'";
644 if ($urow['id'] == $currvalue) {
645 echo " selected";
648 echo ">$optionLabel</option>";
651 echo "</select>";
652 } elseif ($data_type == 15) { // A billing code. If description matches an existing code type then that type is used.
653 $codetype = '';
654 if (!empty($frow['description']) && isset($code_types[$frow['description']])) {
655 $codetype = $frow['description'];
657 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
658 $maxlength = $frow['max_length'];
659 $string_maxlength = "";
660 // if max_length is set to zero, then do not set a maxlength
661 if ($maxlength) {
662 $string_maxlength = "maxlength='".attr($maxlength)."'";
666 if (isOption($frow['edit_options'], '2') !== false && substr($frow['form_id'], 0, 3) == 'LBF') {
667 // Option "2" generates a hidden input for the codes, and a matching visible field
668 // displaying their descriptions. First step is computing the description string.
669 $currdescstring = '';
670 if (!empty($currvalue)) {
671 $relcodes = explode(';', $currvalue);
672 foreach ($relcodes as $codestring) {
673 if ($codestring === '') {
674 continue;
677 $code_text = lookup_code_descriptions($codestring);
678 if ($currdescstring !== '') {
679 $currdescstring .= '; ';
682 if (!empty($code_text)) {
683 $currdescstring .= $code_text;
684 } else {
685 $currdescstring .= $codestring;
690 $currdescstring = attr($currdescstring);
692 echo "<input type='text'" .
693 " name='form_$field_id_esc'" .
694 " id='form_related_code'" .
695 " size='$fldlength'" .
696 " value='$currescaped'" .
697 " style='display:none'" .
698 " $lbfonchange readonly $disabled />";
699 // Extra readonly input field for optional display of code description(s).
700 echo "<input type='text'" .
701 " name='form_$field_id_esc" . "__desc'" .
702 " size='$fldlength'" .
703 " title='$description'" .
704 " value='$currdescstring'";
705 if (!$disabled) {
706 echo " onclick='sel_related(this,\"$codetype\")'";
709 echo "class='form-control'";
710 echo " readonly $disabled />";
711 } else {
712 echo "<input type='text'" .
713 " name='form_$field_id_esc'" .
714 " id='form_related_code'" .
715 " size='$fldlength'" .
716 " $string_maxlength" .
717 " title='$description'" .
718 " value='$currescaped'";
719 if (!$disabled) {
720 echo " onclick='sel_related(this,\"$codetype\")'";
723 echo "class='form-control'";
724 echo " $lbfonchange readonly $disabled />";
726 } elseif ($data_type == 16) { // insurance company list
727 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
728 echo "<option value='0'></option>";
729 $insprovs = getInsuranceProviders();
730 $got_selected = false;
731 foreach ($insprovs as $key => $ipname) {
732 $optionValue = htmlspecialchars($key, ENT_QUOTES);
733 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
734 echo "<option value='$optionValue'";
735 if ($currvalue == $key) {
736 echo " selected";
737 $got_selected = true;
740 echo ">$optionLabel</option>";
743 if (!$got_selected && $currvalue) {
744 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
745 echo "</select>";
746 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
747 } else {
748 echo "</select>";
750 } elseif ($data_type == 17) { // issue types
751 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
752 echo "<option value='0'></option>";
753 $got_selected = false;
754 foreach ($ISSUE_TYPES as $key => $value) {
755 $optionValue = htmlspecialchars($key, ENT_QUOTES);
756 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
757 echo "<option value='$optionValue'";
758 if ($currvalue == $key) {
759 echo " selected";
760 $got_selected = true;
763 echo ">$optionLabel</option>";
766 if (!$got_selected && strlen($currvalue) > 0) {
767 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
768 echo "</select>";
769 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
770 } else {
771 echo "</select>";
773 } elseif ($data_type == 18) { // Visit categories.
774 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
775 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
776 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'" .
777 " $lbfonchange $disabled>";
778 echo "<option value=''>" . xlt($empty_title) . "</option>";
779 $got_selected = false;
780 while ($crow = sqlFetchArray($cres)) {
781 $catid = $crow['pc_catid'];
782 if (($catid < 9 && $catid != 5) || $catid == 11) {
783 continue;
786 echo "<option value='" . attr($catid) . "'";
787 if ($catid == $currvalue) {
788 echo " selected";
789 $got_selected = true;
792 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
795 if (!$got_selected && $currvalue) {
796 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
797 echo "</select>";
798 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
799 } else {
800 echo "</select>";
802 } elseif ($data_type == 21) { // a set of labeled checkboxes
803 // If no list then it's a single checkbox and its value is "Yes" or empty.
804 if (!$list_id) {
805 echo "<input type='checkbox' name='form_{$field_id_esc}' " .
806 "id='form_{$field_id_esc}' value='Yes' $lbfonchange";
807 if ($currvalue) {
808 echo " checked";
810 echo " $disabled />";
811 } else {
812 // In this special case, fld_length is the number of columns generated.
813 $cols = max(1, $frow['fld_length']);
814 $avalue = explode('|', $currvalue);
815 $lres = sqlStatement("SELECT * FROM list_options " .
816 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
817 echo "<table cellpadding='0' cellspacing='0' width='100%' title='".attr($description)."'>";
818 $tdpct = (int) (100 / $cols);
819 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
820 $option_id = $lrow['option_id'];
821 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
822 // if ($count) echo "<br />";
823 if ($count % $cols == 0) {
824 if ($count) {
825 echo "</tr>";
827 echo "<tr>";
829 echo "<td width='" . attr($tdpct) . "%' nowrap>";
830 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
831 "id='form_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
832 if (in_array($option_id, $avalue)) {
833 echo " checked";
835 // Added 5-09 by BM - Translate label if applicable
836 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
837 echo "</td>";
839 if ($count) {
840 echo "</tr>";
841 if ($count > $cols) {
842 // Add some space after multiple rows of checkboxes.
843 $cols = htmlspecialchars($cols, ENT_QUOTES);
844 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
847 echo "</table>";
849 } elseif ($data_type == 22) { // a set of labeled text input fields
850 $tmp = explode('|', $currvalue);
851 $avalue = array();
852 foreach ($tmp as $value) {
853 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
854 $avalue[$matches[1]] = $matches[2];
858 $lres = sqlStatement("SELECT * FROM list_options " .
859 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
860 echo "<table cellpadding='0' cellspacing='0'>";
861 while ($lrow = sqlFetchArray($lres)) {
862 $option_id = $lrow['option_id'];
863 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
864 $maxlength = $frow['max_length'];
865 $string_maxlength = "";
866 // if max_length is set to zero, then do not set a maxlength
867 if ($maxlength) {
868 $string_maxlength = "maxlength='".attr($maxlength)."'";
871 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
873 // Added 5-09 by BM - Translate label if applicable
874 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
875 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
876 $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
877 echo "<td><input type='text'" .
878 " name='form_{$field_id_esc}[$option_id_esc]'" .
879 " id='form_{$field_id_esc}[$option_id_esc]'" .
880 " size='$fldlength'" .
881 " class='form-control'" .
882 " $string_maxlength" .
883 " value='$optionValue'";
884 echo " $lbfonchange $disabled /></td></tr>";
887 echo "</table>";
888 } elseif ($data_type == 23) { // a set of exam results; 3 radio buttons and a text field:
889 $tmp = explode('|', $currvalue);
890 $avalue = array();
891 foreach ($tmp as $value) {
892 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
893 $avalue[$matches[1]] = $matches[2];
897 $maxlength = $frow['max_length'];
898 $string_maxlength = "";
899 // if max_length is set to zero, then do not set a maxlength
900 if ($maxlength) {
901 $string_maxlength = "maxlength='".attr($maxlength)."'";
904 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
905 $lres = sqlStatement("SELECT * FROM list_options " .
906 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
907 echo "<table cellpadding='0' cellspacing='0'>";
908 echo "<tr><td>&nbsp;</td><td class='bold'>" .
909 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
910 "&nbsp;</td><td class='bold'>" .
911 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
912 "<td class='bold'>" .
913 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
914 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
915 while ($lrow = sqlFetchArray($lres)) {
916 $option_id = $lrow['option_id'];
917 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
918 $restype = substr($avalue[$option_id], 0, 1);
919 $resnote = substr($avalue[$option_id], 2);
921 // Added 5-09 by BM - Translate label if applicable
922 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
924 for ($i = 0; $i < 3; ++$i) {
925 $inputValue = htmlspecialchars($i, ENT_QUOTES);
926 echo "<td><input type='radio'" .
927 " name='radio_{$field_id_esc}[$option_id_esc]'" .
928 " id='radio_{$field_id_esc}[$option_id_esc]'" .
929 " value='$inputValue' $lbfonchange";
930 if ($restype === "$i") {
931 echo " checked";
934 echo " $disabled /></td>";
937 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
938 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
939 echo "<td><input type='text'" .
940 " name='form_{$field_id_esc}[$option_id_esc]'" .
941 " id='form_{$field_id_esc}[$option_id_esc]'" .
942 " size='$fldlength'" .
943 " $string_maxlength" .
944 " value='$resnote' $disabled /></td>";
945 echo "</tr>";
948 echo "</table>";
949 } elseif ($data_type == 24) { // the list of active allergies for the current patient
950 // this is read-only!
951 $query = "SELECT title, comments FROM lists WHERE " .
952 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
953 "ORDER BY begdate";
954 // echo "<!-- $query -->\n"; // debugging
955 $lres = sqlStatement($query, array($GLOBALS['pid']));
956 $count = 0;
957 while ($lrow = sqlFetchArray($lres)) {
958 if ($count++) {
959 echo "<br />";
962 echo htmlspecialchars($lrow['title'], ENT_NOQUOTES);
963 if ($lrow['comments']) {
964 echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
967 } elseif ($data_type == 25) { // a set of labeled checkboxes, each with a text field:
968 $tmp = explode('|', $currvalue);
969 $avalue = array();
970 foreach ($tmp as $value) {
971 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
972 $avalue[$matches[1]] = $matches[2];
976 $maxlength = $frow['max_length'];
977 $string_maxlength = "";
978 // if max_length is set to zero, then do not set a maxlength
979 if ($maxlength) {
980 $string_maxlength = "maxlength='".attr($maxlength)."'";
983 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
984 $lres = sqlStatement("SELECT * FROM list_options " .
985 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
986 echo "<table cellpadding='0' cellspacing='0'>";
987 while ($lrow = sqlFetchArray($lres)) {
988 $option_id = $lrow['option_id'];
989 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
990 $restype = substr($avalue[$option_id], 0, 1);
991 $resnote = substr($avalue[$option_id], 2);
993 // Added 5-09 by BM - Translate label if applicable
994 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
996 $option_id = htmlspecialchars($option_id, ENT_QUOTES);
997 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
998 " id='check_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
999 if ($restype) {
1000 echo " checked";
1003 echo " $disabled />&nbsp;</td>";
1004 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1005 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1006 echo "<td><input type='text'" .
1007 " name='form_{$field_id_esc}[$option_id_esc]'" .
1008 " id='form_{$field_id_esc}[$option_id_esc]'" .
1009 " size='$fldlength'" .
1010 " class='form-control' " .
1011 " $string_maxlength" .
1012 " value='$resnote' $disabled /></td>";
1013 echo "</tr>";
1016 echo "</table>";
1017 } elseif ($data_type == 26) { // single-selection list with ability to add to it
1018 echo generate_select_list(
1019 "form_$field_id",
1020 $list_id,
1021 $currvalue,
1022 $description,
1023 ($showEmpty ? $empty_title : ''),
1024 'addtolistclass_'.$list_id,
1025 $lbfchange,
1027 ($disabled ? array('disabled' => 'disabled') : null),
1028 false,
1029 $backup_list
1031 // show the add button if user has access to correct list
1032 $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES);
1033 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
1034 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
1035 if (aco_exist('lists', $list_id)) {
1036 // a specific aco exist for this list, so ensure access
1037 if (acl_check('lists', $list_id)) {
1038 echo $outputAddButton;
1040 } else {
1041 // no specific aco exist for this list, so check for access to 'default' list
1042 if (acl_check('lists', 'default')) {
1043 echo $outputAddButton;
1046 } elseif ($data_type == 27) { // a set of labeled radio buttons
1047 // In this special case, fld_length is the number of columns generated.
1048 $cols = max(1, $frow['fld_length']);
1049 // Support for edit option M.
1050 if (isOption($frow['edit_options'], 'M')) {
1051 ++$membership_group_number;
1054 $lres = sqlStatement("SELECT * FROM list_options " .
1055 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1056 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1057 $tdpct = (int) (100 / $cols);
1058 $got_selected = false;
1059 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1060 $option_id = $lrow['option_id'];
1061 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
1062 if ($count % $cols == 0) {
1063 if ($count) {
1064 echo "</tr>";
1066 echo "<tr>";
1068 echo "<td width='" . attr($tdpct) . "%'>";
1069 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
1070 " value='$option_id_esc' $lbfonchange";
1071 // Support for edit options M and m.
1072 if (isOption($frow['edit_options'], 'M')) {
1073 echo " class='form-control'";
1074 echo " onclick='checkGroupMembers(this, $membership_group_number);'";
1075 } else if (isOption($frow['edit_options'], 'm')) {
1076 echo " class='form-control lbf_memgroup_$membership_group_number'";
1077 } else {
1078 echo " class='form-control'";
1081 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1082 (strlen($currvalue) > 0 && $option_id == $currvalue)) {
1083 echo " checked";
1084 $got_selected = true;
1086 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1087 echo "</td>";
1090 if ($count) {
1091 echo "</tr>";
1092 if ($count > $cols) {
1093 // Add some space after multiple rows of radio buttons.
1094 $cols = htmlspecialchars($cols, ENT_QUOTES);
1095 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1099 echo "</table>";
1100 if (!$got_selected && strlen($currvalue) > 0) {
1101 $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES);
1102 $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES);
1103 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
1105 } elseif ($data_type == 28 || $data_type == 32) { // special case for history of lifestyle status; 3 radio buttons
1106 // and a date text field:
1107 // VicarePlus :: A selection list box for smoking status:
1108 $tmp = explode('|', $currvalue);
1109 switch (count($tmp)) {
1110 case "4":
1111 $resnote = $tmp[0];
1112 $restype = $tmp[1];
1113 $resdate = oeFormatShortDate($tmp[2]);
1114 $reslist = $tmp[3];
1115 break;
1116 case "3":
1117 $resnote = $tmp[0];
1118 $restype = $tmp[1];
1119 $resdate = oeFormatShortDate($tmp[2]);
1120 break;
1121 case "2":
1122 $resnote = $tmp[0];
1123 $restype = $tmp[1];
1124 $resdate = "";
1125 break;
1126 case "1":
1127 $resnote = $tmp[0];
1128 $resdate = $restype = "";
1129 break;
1130 default:
1131 $restype = $resdate = $resnote = "";
1132 break;
1135 $maxlength = $frow['max_length'];
1136 $string_maxlength = "";
1137 // if max_length is set to zero, then do not set a maxlength
1138 if ($maxlength) {
1139 $string_maxlength = "maxlength='".attr($maxlength)."'";
1142 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1144 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1145 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1146 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1147 echo "<table cellpadding='0' cellspacing='0'>";
1148 echo "<tr>";
1149 if ($data_type == 28) {
1150 // input text
1151 echo "<td><input type='text'" .
1152 " name='form_$field_id_esc'" .
1153 " id='form_$field_id_esc'" .
1154 " size='$fldlength'" .
1155 " $string_maxlength" .
1156 " value='$resnote' $disabled />&nbsp;</td>";
1157 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1158 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1159 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1160 } elseif ($data_type == 32) {
1161 // input text
1162 echo "<tr><td><input type='text'" .
1163 " name='form_text_$field_id_esc'" .
1164 " id='form_text_$field_id_esc'" .
1165 " size='$fldlength'" .
1166 " class='form-control'" .
1167 " $string_maxlength" .
1168 " value='$resnote' $disabled />&nbsp;</td></tr>";
1169 echo "<td>";
1170 //Selection list for smoking status
1171 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1172 echo generate_select_list(
1173 "form_$field_id",
1174 $list_id,
1175 $reslist,
1176 $description,
1177 ($showEmpty ? $empty_title : ''),
1179 $onchange,
1181 ($disabled ? array('disabled' => 'disabled') : null)
1183 echo "</td>";
1184 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1187 // current
1188 echo "<td class='text' ><input type='radio'" .
1189 " name='radio_{$field_id_esc}'" .
1190 " id='radio_{$field_id_esc}[current]'" .
1191 " class='form-control'" .
1192 " value='current" . $field_id_esc . "' $lbfonchange";
1193 if ($restype == "current" . $field_id) {
1194 echo " checked";
1197 if ($data_type == 32) {
1198 echo " onClick='smoking_statusClicked(this)'";
1201 echo " />" . xlt('Current') . "&nbsp;</td>";
1202 // quit
1203 echo "<td class='text'><input type='radio'" .
1204 " name='radio_{$field_id_esc}'" .
1205 " id='radio_{$field_id_esc}[quit]'" .
1206 " class='form-control'" .
1207 " value='quit".$field_id_esc."' $lbfonchange";
1208 if ($restype == "quit" . $field_id) {
1209 echo " checked";
1212 if ($data_type == 32) {
1213 echo " onClick='smoking_statusClicked(this)'";
1216 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1217 // quit date
1218 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1219 " value='$resdate'" .
1220 " title='$description'" .
1221 " $disabled />";
1222 echo "&nbsp;</td>";
1223 // never
1224 echo "<td class='text'><input type='radio'" .
1225 " name='radio_{$field_id_esc}'" .
1226 " class='form-control'" .
1227 " id='radio_{$field_id_esc}[never]'" .
1228 " value='never" . $field_id_esc . "' $lbfonchange";
1229 if ($restype == "never" . $field_id) {
1230 echo " checked";
1233 if ($data_type == 32) {
1234 echo " onClick='smoking_statusClicked(this)'";
1237 echo " />" . xlt('Never') . "&nbsp;</td>";
1238 // Not Applicable
1239 echo "<td class='text'><input type='radio'" .
1240 " class='form-control' " .
1241 " name='radio_{$field_id}'" .
1242 " id='radio_{$field_id}[not_applicable]'" .
1243 " value='not_applicable" . $field_id . "' $lbfonchange";
1244 if ($restype == "not_applicable" . $field_id) {
1245 echo " checked";
1248 if ($data_type == 32) {
1249 echo " onClick='smoking_statusClicked(this)'";
1252 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1254 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1255 echo "<td class='text' ><div id='smoke_code'></div></td>";
1256 echo "</tr>";
1257 echo "</table>";
1258 } elseif ($data_type == 31) { // static text. read-only, of course.
1259 echo parse_static_text($frow);
1260 } elseif ($data_type == 34) {
1261 // $data_type == 33
1262 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1263 // $data_type == 33
1265 $arr = explode("|*|*|*|", $currvalue);
1266 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;'>";
1267 echo "<div id='form_{$field_id}_div' class='text-area' style='min-width:100pt'>" . $arr[0] . "</div>";
1268 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>";
1269 echo "</a>";
1270 } elseif ($data_type == 35) { //facilities drop-down list
1271 if (empty($currvalue)) {
1272 $currvalue = 0;
1275 dropdown_facility(
1276 $selected = $currvalue,
1277 $name = "form_$field_id_esc",
1278 $allow_unspecified = true,
1279 $allow_allfacilities = false,
1280 $disabled,
1281 $lbfchange
1283 } elseif ($data_type == 36) { //multiple select, supports backup list
1284 echo generate_select_list(
1285 "form_$field_id",
1286 $list_id,
1287 $currvalue,
1288 $description,
1289 $showEmpty ? $empty_title : '',
1291 $lbfchange,
1293 null,
1294 true,
1295 $backup_list
1297 } elseif ($data_type == 40) { // Canvas and related elements for browser-side image drawing.
1298 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1299 // Unlike other field types, width and height are in pixels.
1300 $canWidth = intval($frow['fld_length']);
1301 $canHeight = intval($frow['fld_rows']);
1302 if (empty($currvalue)) {
1303 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1304 // If defined this is the filename of the default starting image.
1305 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1309 $mywidth = 50 + ($canWidth > 250 ? $canWidth : 250);
1310 $myheight = 31 + ($canHeight > 261 ? $canHeight : 261);
1311 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1312 // Hidden form field exists to send updated data to the server at submit time.
1313 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1314 // Hidden image exists to support initialization of the canvas.
1315 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1316 // $date_init is a misnomer but it's the place for browser-side setup logic.
1317 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1318 } elseif ($data_type == 41 || $data_type == 42) {
1319 $datatype = 'patient-signature';
1320 $cpid = $GLOBALS['pid'];
1321 $cuser = $_SESSION['authUserID'];
1322 if ($data_type == 42) {
1323 $datatype = 'admin-signature';
1325 echo "<input type='hidden' id='form_$field_id_esc' name='form_$field_id_esc' value='' />\n";
1326 echo "<img class='signature' id='form_{$field_id_esc}_img' title='$description'
1327 data-pid='$cpid' data-user='$cuser' data-type='$datatype'
1328 data-action='fetch_signature' alt='Get Signature' src='" . attr($currvalue) . "'>\n";
1332 function generate_print_field($frow, $currvalue)
1334 global $rootdir, $date_init, $ISSUE_TYPES;
1336 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1338 $data_type = $frow['data_type'];
1339 $field_id = $frow['field_id'];
1340 $list_id = $frow['list_id'];
1341 $fld_length = $frow['fld_length'];
1342 $backup_list = $frow['list_backup_id'];
1344 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1346 // Can pass $frow['empty_title'] with this variable, otherwise
1347 // will default to 'Unassigned'.
1348 // If it is 'SKIP' then an empty text title is completely skipped.
1349 $showEmpty = true;
1350 if (isset($frow['empty_title'])) {
1351 if ($frow['empty_title'] == "SKIP") {
1352 //do not display an 'empty' choice
1353 $showEmpty = false;
1354 $empty_title = "Unassigned";
1355 } else {
1356 $empty_title = $frow['empty_title'];
1358 } else {
1359 $empty_title = "Unassigned";
1362 // generic single-selection list
1363 // Supports backup lists.
1364 if (false && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1365 if (empty($fld_length)) {
1366 if ($list_id == 'titles') {
1367 $fld_length = 3;
1368 } else {
1369 $fld_length = 10;
1373 $tmp = '';
1374 if ($currvalue) {
1375 $lrow = sqlQuery("SELECT title FROM list_options " .
1376 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1377 $tmp = xl_list_label($lrow['title']);
1378 if ($lrow == 0 && !empty($backup_list)) {
1379 // since primary list did not map, try to map to backup list
1380 $lrow = sqlQuery("SELECT title FROM list_options " .
1381 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1382 $tmp = xl_list_label($lrow['title']);
1385 if (empty($tmp)) {
1386 $tmp = "($currvalue)";
1390 /*****************************************************************
1391 echo "<input type='text'" .
1392 " size='$fld_length'" .
1393 " value='$tmp'" .
1394 " class='under'" .
1395 " />";
1396 *****************************************************************/
1397 if ($tmp === '') {
1398 $tmp = '&nbsp;';
1399 } else {
1400 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1403 echo $tmp;
1404 } elseif ($data_type == 2 || $data_type == 15) { // simple text field
1405 /*****************************************************************
1406 echo "<input type='text'" .
1407 " size='$fld_length'" .
1408 " value='$currescaped'" .
1409 " class='under'" .
1410 " />";
1411 *****************************************************************/
1412 if ($currescaped === '') {
1413 $currescaped = '&nbsp;';
1416 echo $currescaped;
1417 } elseif ($data_type == 3) { // long or multi-line text field
1418 $fldlength = htmlspecialchars($fld_length, ENT_QUOTES);
1419 $maxlength = htmlspecialchars($frow['fld_rows'], ENT_QUOTES);
1420 echo "<textarea" .
1421 " class='form-control' " .
1422 " cols='$fldlength'" .
1423 " rows='$maxlength'>" .
1424 $currescaped . "</textarea>";
1425 } elseif ($data_type == 4) { // date
1426 $age_asof_date = '';
1427 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
1428 if ($currvalue === '') {
1429 echo '&nbsp;';
1430 } else {
1431 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
1432 if (!$modtmp) {
1433 echo text(oeFormatShortDate($currvalue));
1434 } else {
1435 echo text(oeFormatDateTime($currvalue));
1437 if ($agestr) {
1438 echo "&nbsp;(" . text($agestr) . ")";
1441 } elseif ($data_type == 10 || $data_type == 11) { // provider list
1442 $tmp = '';
1443 if ($currvalue) {
1444 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1445 "WHERE id = ?", array($currvalue));
1446 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1447 if (empty($tmp)) {
1448 $tmp = "($currvalue)";
1452 /*****************************************************************
1453 echo "<input type='text'" .
1454 " size='$fld_length'" .
1455 " value='$tmp'" .
1456 " class='under'" .
1457 " />";
1458 *****************************************************************/
1459 if ($tmp === '') {
1460 $tmp = '&nbsp;';
1461 } else {
1462 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1465 echo $tmp;
1466 } elseif ($data_type == 12) { // pharmacy list
1467 $tmp = '';
1468 if ($currvalue) {
1469 $pres = get_pharmacies();
1470 while ($prow = sqlFetchArray($pres)) {
1471 $key = $prow['id'];
1472 if ($currvalue == $key) {
1473 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1474 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1475 $prow['line1'] . ' / ' . $prow['city'];
1479 if (empty($tmp)) {
1480 $tmp = "($currvalue)";
1484 /*****************************************************************
1485 echo "<input type='text'" .
1486 " size='$fld_length'" .
1487 " value='$tmp'" .
1488 " class='under'" .
1489 " />";
1490 *****************************************************************/
1491 if ($tmp === '') {
1492 $tmp = '&nbsp;';
1493 } else {
1494 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1497 echo $tmp;
1498 } elseif ($data_type == 13) { // squads
1499 $tmp = '';
1500 if ($currvalue) {
1501 $squads = acl_get_squads();
1502 if ($squads) {
1503 foreach ($squads as $key => $value) {
1504 if ($currvalue == $key) {
1505 $tmp = $value[3];
1510 if (empty($tmp)) {
1511 $tmp = "($currvalue)";
1515 /*****************************************************************
1516 echo "<input type='text'" .
1517 " size='$fld_length'" .
1518 " value='$tmp'" .
1519 " class='under'" .
1520 " />";
1521 *****************************************************************/
1522 if ($tmp === '') {
1523 $tmp = '&nbsp;';
1524 } else {
1525 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1528 echo $tmp;
1529 } elseif ($data_type == 14) { // Address book.
1530 $tmp = '';
1531 if ($currvalue) {
1532 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1533 "WHERE id = ?", array($currvalue));
1534 $uname = $urow['lname'];
1535 if ($urow['fname']) {
1536 $uname .= ", " . $urow['fname'];
1539 $tmp = $uname;
1540 if (empty($tmp)) {
1541 $tmp = "($currvalue)";
1545 /*****************************************************************
1546 echo "<input type='text'" .
1547 " size='$fld_length'" .
1548 " value='$tmp'" .
1549 " class='under'" .
1550 " />";
1551 *****************************************************************/
1552 if ($tmp === '') {
1553 $tmp = '&nbsp;';
1554 } else {
1555 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1558 echo $tmp;
1559 } elseif ($data_type == 16) { // insurance company list
1560 $tmp = '';
1561 if ($currvalue) {
1562 $insprovs = getInsuranceProviders();
1563 foreach ($insprovs as $key => $ipname) {
1564 if ($currvalue == $key) {
1565 $tmp = $ipname;
1569 if (empty($tmp)) {
1570 $tmp = "($currvalue)";
1574 if ($tmp === '') {
1575 $tmp = '&nbsp;';
1576 } else {
1577 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1580 echo $tmp;
1581 } elseif ($data_type == 17) { // issue types
1582 $tmp = '';
1583 if ($currvalue) {
1584 foreach ($ISSUE_TYPES as $key => $value) {
1585 if ($currvalue == $key) {
1586 $tmp = $value[1];
1590 if (empty($tmp)) {
1591 $tmp = "($currvalue)";
1595 if ($tmp === '') {
1596 $tmp = '&nbsp;';
1597 } else {
1598 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1601 echo $tmp;
1602 } elseif ($data_type == 18) { // Visit categories.
1603 $tmp = '';
1604 if ($currvalue) {
1605 $crow = sqlQuery(
1606 "SELECT pc_catid, pc_catname " .
1607 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1608 array($currvalue)
1610 $tmp = xl_appt_category($crow['pc_catname']);
1611 if (empty($tmp)) {
1612 $tmp = "($currvalue)";
1616 if ($tmp === '') {
1617 $tmp = '&nbsp;';
1618 } else {
1619 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1622 echo $tmp;
1623 } elseif ($data_type == 21) { // a single checkbox or set of labeled checkboxes
1624 if (!$list_id) {
1625 echo "<input type='checkbox'";
1626 if ($currvalue) {
1627 echo " checked";
1629 echo " />";
1630 } else {
1631 // In this special case, fld_length is the number of columns generated.
1632 $cols = max(1, $fld_length);
1633 $avalue = explode('|', $currvalue);
1634 $lres = sqlStatement("SELECT * FROM list_options " .
1635 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1636 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1637 $tdpct = (int) (100 / $cols);
1638 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1639 $option_id = $lrow['option_id'];
1640 if ($count % $cols == 0) {
1641 if ($count) {
1642 echo "</tr>";
1645 echo "<tr>";
1647 echo "<td width='" . attr($tdpct) . "%' nowrap>";
1648 echo "<input type='checkbox'";
1649 if (in_array($option_id, $avalue)) {
1650 echo " checked";
1652 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1653 echo "</td>";
1655 if ($count) {
1656 echo "</tr>";
1657 if ($count > $cols) {
1658 // Add some space after multiple rows of checkboxes.
1659 $cols = htmlspecialchars($cols, ENT_QUOTES);
1660 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1663 echo "</table>";
1665 } elseif ($data_type == 22) { // a set of labeled text input fields
1666 $tmp = explode('|', $currvalue);
1667 $avalue = array();
1668 foreach ($tmp as $value) {
1669 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1670 $avalue[$matches[1]] = $matches[2];
1674 $lres = sqlStatement("SELECT * FROM list_options " .
1675 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1676 echo "<table cellpadding='0' cellspacing='0'>";
1677 while ($lrow = sqlFetchArray($lres)) {
1678 $option_id = $lrow['option_id'];
1679 $fldlength = empty($fld_length) ? 20 : $fld_length;
1680 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1681 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1682 $inputValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
1683 echo "<td><input type='text'" .
1684 " class='form-control' " .
1685 " size='$fldlength'" .
1686 " value='$inputValue'" .
1687 " class='under'" .
1688 " /></td></tr>";
1691 echo "</table>";
1692 } elseif ($data_type == 23) { // a set of exam results; 3 radio buttons and a text field:
1693 $tmp = explode('|', $currvalue);
1694 $avalue = array();
1695 foreach ($tmp as $value) {
1696 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1697 $avalue[$matches[1]] = $matches[2];
1701 $fldlength = empty($fld_length) ? 20 : $fld_length;
1702 $lres = sqlStatement("SELECT * FROM list_options " .
1703 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1704 echo "<table cellpadding='0' cellspacing='0'>";
1705 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1706 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
1707 "&nbsp;</td><td class='bold'>" .
1708 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1709 "<td class='bold'>" .
1710 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1711 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1712 while ($lrow = sqlFetchArray($lres)) {
1713 $option_id = $lrow['option_id'];
1714 $restype = substr($avalue[$option_id], 0, 1);
1715 $resnote = substr($avalue[$option_id], 2);
1716 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1717 for ($i = 0; $i < 3; ++$i) {
1718 echo "<td><input type='radio'";
1719 if ($restype === "$i") {
1720 echo " checked";
1723 echo " /></td>";
1726 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1727 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1728 echo "<td><input type='text'" .
1729 " size='$fldlength'" .
1730 " value='$resnote'" .
1731 " class='under form-control' /></td>" .
1732 "</tr>";
1735 echo "</table>";
1736 } elseif ($data_type == 24) { // the list of active allergies for the current patient
1737 // this is read-only!
1738 $query = "SELECT title, comments FROM lists WHERE " .
1739 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1740 "ORDER BY begdate";
1741 $lres = sqlStatement($query, array($GLOBALS['pid']));
1742 $count = 0;
1743 while ($lrow = sqlFetchArray($lres)) {
1744 if ($count++) {
1745 echo "<br />";
1748 echo htmlspecialchars($lrow['title'], ENT_QUOTES);
1749 if ($lrow['comments']) {
1750 echo htmlspecialchars(' (' . $lrow['comments'] . ')', ENT_QUOTES);
1753 } elseif ($data_type == 25) { // a set of labeled checkboxes, each with a text field:
1754 $tmp = explode('|', $currvalue);
1755 $avalue = array();
1756 foreach ($tmp as $value) {
1757 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1758 $avalue[$matches[1]] = $matches[2];
1762 $fldlength = empty($fld_length) ? 20 : $fld_length;
1763 $lres = sqlStatement("SELECT * FROM list_options " .
1764 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1765 echo "<table cellpadding='0' cellspacing='0'>";
1766 while ($lrow = sqlFetchArray($lres)) {
1767 $option_id = $lrow['option_id'];
1768 $restype = substr($avalue[$option_id], 0, 1);
1769 $resnote = substr($avalue[$option_id], 2);
1770 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1771 echo "<td><input type='checkbox'";
1772 if ($restype) {
1773 echo " checked";
1776 echo " />&nbsp;</td>";
1777 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1778 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1779 echo "<td><input type='text'" .
1780 " size='$fldlength'" .
1781 " class='form-control' " .
1782 " value='$resnote'" .
1783 " class='under'" .
1784 " /></td>" .
1785 "</tr>";
1788 echo "</table>";
1789 } elseif ($data_type == 27 || $data_type == 1 || $data_type == 26 || $data_type == 33) {
1790 // a set of labeled radio buttons
1791 // In this special case, fld_length is the number of columns generated.
1792 $cols = max(1, $frow['fld_length']);
1793 $lres = sqlStatement("SELECT * FROM list_options " .
1794 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1795 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1796 $tdpct = (int) (100 / $cols);
1797 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1798 $option_id = $lrow['option_id'];
1799 if ($count % $cols == 0) {
1800 if ($count) {
1801 echo "</tr>";
1804 echo "<tr>";
1806 echo "<td width='" . attr($tdpct) . "%' nowrap>";
1807 echo "<input type='radio'";
1808 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1809 // Do not use defaults for these printable forms.
1810 echo " checked";
1813 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1814 echo "</td>";
1817 if ($count) {
1818 echo "</tr>";
1819 if ($count > $cols) {
1820 // Add some space after multiple rows of radio buttons.
1821 $cols = htmlspecialchars($cols, ENT_QUOTES);
1822 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1826 echo "</table>";
1827 } elseif ($data_type == 28 || $data_type == 32) { // special case for history of lifestyle status; 3 radio buttons and a date text field:
1828 $tmp = explode('|', $currvalue);
1829 switch (count($tmp)) {
1830 case "4":
1831 $resnote = $tmp[0];
1832 $restype = $tmp[1];
1833 $resdate = oeFormatShortDate($tmp[2]) ;
1834 $reslist = $tmp[3];
1835 break;
1836 case "3":
1837 $resnote = $tmp[0];
1838 $restype = $tmp[1];
1839 $resdate = oeFormatShortDate($tmp[2]);
1840 break;
1841 case "2":
1842 $resnote = $tmp[0];
1843 $restype = $tmp[1];
1844 $resdate = "";
1845 break;
1846 case "1":
1847 $resnote = $tmp[0];
1848 $resdate = $restype = "";
1849 break;
1850 default:
1851 $restype = $resdate = $resnote = "";
1852 break;
1855 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1856 echo "<table cellpadding='0' cellspacing='0'>";
1857 echo "<tr>";
1858 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1859 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1860 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1861 if ($data_type == 28) {
1862 echo "<td><input type='text'" .
1863 " size='$fldlength'" .
1864 " class='under'" .
1865 " value='$resnote' /></td>";
1866 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1867 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1868 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1869 } elseif ($data_type == 32) {
1870 echo "<tr><td><input type='text'" .
1871 " size='$fldlength'" .
1872 " class='under form-control'" .
1873 " value='$resnote' /></td></tr>";
1874 $fldlength = 30;
1875 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
1876 echo "<td><input type='text'" .
1877 " size='$fldlength'" .
1878 " class='under form-control'" .
1879 " value='$smoking_status_title' /></td>";
1880 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1883 echo "<td><input type='radio' class='form-control'";
1884 if ($restype == "current".$field_id) {
1885 echo " checked";
1888 echo "/>".htmlspecialchars(xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1890 echo "<td><input type='radio' class='form-control'";
1891 if ($restype == "current".$field_id) {
1892 echo " checked";
1895 echo "/>".htmlspecialchars(xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1897 echo "<td><input type='text' size='6'" .
1898 " value='$resdate'" .
1899 " class='under form-control'" .
1900 " /></td>";
1902 echo "<td><input type='radio' class='form-control'";
1903 if ($restype == "current".$field_id) {
1904 echo " checked";
1907 echo " />".htmlspecialchars(xl('Never'), ENT_NOQUOTES)."</td>";
1909 echo "<td><input type='radio' class='form-control'";
1910 if ($restype == "not_applicable".$field_id) {
1911 echo " checked";
1914 echo " />".htmlspecialchars(xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1915 echo "</tr>";
1916 echo "</table>";
1917 } elseif ($data_type == 31) { // static text. read-only, of course.
1918 echo parse_static_text($frow);
1919 } elseif ($data_type == 34) {
1920 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;'>";
1921 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1922 echo "<div style='display:none'><textarea name='form_{$field_id}' class='form-control' id='form_{$field_id}' stye='display:none'></textarea></div>";
1923 echo "</a>";
1924 } elseif ($data_type == 35) { //facilities drop-down list
1925 // In this special case, fld_length is the number of columns generated.
1926 $cols = max(1, $frow['fld_length']);
1927 $lres = sqlStatement("SELECT id, name FROM facility ORDER BY name");
1928 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1929 $tdpct = (int) (100 / $cols);
1930 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1931 $option_id = $lrow['id'];
1932 if ($count % $cols == 0) {
1933 if ($count) {
1934 echo "</tr>";
1936 echo "<tr>";
1938 echo "<td width='" . attr($tdpct) . "%'>";
1939 echo "<input type='radio'";
1940 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1941 // Do not use defaults for these printable forms.
1942 echo " checked";
1944 echo ">" . htmlspecialchars($lrow['name']);
1945 echo "</td>";
1947 if ($count) {
1948 echo "</tr>";
1949 if ($count > $cols) {
1950 // Add some space after multiple rows of radio buttons.
1951 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1954 echo "</table>";
1955 } elseif ($data_type == 36) { //Multi-select. Supports backup lists.
1956 if (empty($fld_length)) {
1957 if ($list_id == 'titles') {
1958 $fld_length = 3;
1959 } else {
1960 $fld_length = 10;
1964 $tmp = '';
1966 $values_array = explode("|", $currvalue);
1968 $i=0;
1969 foreach ($values_array as $value) {
1970 if ($value) {
1971 $lrow = sqlQuery("SELECT title FROM list_options " .
1972 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1973 $tmp = xl_list_label($lrow['title']);
1974 if ($lrow == 0 && !empty($backup_list)) {
1975 // since primary list did not map, try to map to backup list
1976 $lrow = sqlQuery("SELECT title FROM list_options " .
1977 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1978 $tmp = xl_list_label($lrow['title']);
1981 if (empty($tmp)) {
1982 $tmp = "($value)";
1986 if ($tmp === '') {
1987 $tmp = '&nbsp;';
1988 } else {
1989 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1992 if ($i != 0 && $tmp != '&nbsp;') {
1993 echo ",";
1996 echo $tmp;
1997 $i++;
1999 } elseif ($data_type == 40) { // Image from canvas drawing
2000 if ($currvalue) {
2001 echo "<img src='" . attr($currvalue) . "'>";
2003 } elseif ($data_type == 41 || $data_type == 42) {
2004 if ($currvalue) {
2005 echo "<img style='height:70px;width:auto;' src='" . attr($currvalue) . "'>";
2010 function generate_display_field($frow, $currvalue)
2012 global $ISSUE_TYPES, $facilityService;
2014 $data_type = $frow['data_type'];
2015 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2016 $list_id = $frow['list_id'];
2017 $backup_list = isset($frow['list_backup_id']) ? $frow['list_backup_id'] : null;
2019 $s = '';
2021 // generic selection list or the generic selection list with add on the fly
2022 // feature
2023 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
2024 $lrow = sqlQuery("SELECT title FROM list_options " .
2025 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2026 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2027 //if there is no matching value in the corresponding lists check backup list
2028 // only supported in data types 1,26,33
2029 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2030 $lrow = sqlQuery("SELECT title FROM list_options " .
2031 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2032 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2034 // If match is not found in main and backup lists, return the key with exclamation mark
2035 if ($s == '') {
2036 $s = nl2br(text(xl_list_label($currvalue))).
2037 '<sup> <i class="fa fas fa-exclamation-circle ml-1"></i></sup>';
2039 } elseif ($data_type == 2) { // simple text field
2040 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2041 } elseif ($data_type == 3) { // long or multi-line text field
2042 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2043 } elseif ($data_type == 4) { // date
2044 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
2045 $s = '';
2046 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2047 $age_asof_date = '';
2048 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
2049 if ($currvalue === '') {
2050 $s .= '&nbsp;';
2051 } else {
2052 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
2053 if (!$modtmp) {
2054 $s .= text(oeFormatShortDate($currvalue));
2055 } else {
2056 $s .= text(oeFormatDateTime($currvalue));
2058 if ($agestr) {
2059 $s .= "&nbsp;(" . text($agestr) . ")";
2062 } elseif ($data_type == 10 || $data_type == 11) { // provider
2063 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2064 "WHERE id = ?", array($currvalue));
2065 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']), ENT_NOQUOTES);
2066 } elseif ($data_type == 12) { // pharmacy list
2067 $pres = get_pharmacies();
2068 while ($prow = sqlFetchArray($pres)) {
2069 $key = $prow['id'];
2070 if ($currvalue == $key) {
2071 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
2072 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2073 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
2076 } elseif ($data_type == 13) { // squads
2077 $squads = acl_get_squads();
2078 if ($squads) {
2079 foreach ($squads as $key => $value) {
2080 if ($currvalue == $key) {
2081 $s .= htmlspecialchars($value[3], ENT_NOQUOTES);
2085 } elseif ($data_type == 14) { // address book
2086 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
2087 "WHERE id = ?", array($currvalue));
2088 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
2089 if ($urow['organization'] !="") {
2090 $uname = $urow['organization'];
2091 } else {
2092 $uname = $urow['lname'];
2093 if ($urow['fname']) {
2094 $uname .= ", " . $urow['fname'];
2098 $s = htmlspecialchars($uname, ENT_NOQUOTES);
2099 } elseif ($data_type == 15) { // billing code
2100 $s = '';
2101 if (!empty($currvalue)) {
2102 $relcodes = explode(';', $currvalue);
2103 foreach ($relcodes as $codestring) {
2104 if ($codestring === '') {
2105 continue;
2107 $tmp = lookup_code_descriptions($codestring);
2108 if ($s !== '') {
2109 $s .= '; ';
2111 if (!empty($tmp)) {
2112 $s .= $tmp;
2113 } else {
2114 $s .= $codestring . ' (' . xl('not found') . ')';
2118 } elseif ($data_type == 16) { // insurance company list
2119 $insprovs = getInsuranceProviders();
2120 foreach ($insprovs as $key => $ipname) {
2121 if ($currvalue == $key) {
2122 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
2125 } elseif ($data_type == 17) { // issue types
2126 foreach ($ISSUE_TYPES as $key => $value) {
2127 if ($currvalue == $key) {
2128 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
2131 } elseif ($data_type == 18) { // visit category
2132 $crow = sqlQuery(
2133 "SELECT pc_catid, pc_catname " .
2134 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2135 array($currvalue)
2137 $s = htmlspecialchars($crow['pc_catname'], ENT_NOQUOTES);
2138 } elseif ($data_type == 21) { // a single checkbox or set of labeled checkboxes
2139 if (!$list_id) {
2140 $s .= $currvalue ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2141 } else {
2142 // In this special case, fld_length is the number of columns generated.
2143 $cols = max(1, $frow['fld_length']);
2144 $avalue = explode('|', $currvalue);
2145 $lres = sqlStatement("SELECT * FROM list_options " .
2146 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2147 $s .= "<table cellspacing='0' cellpadding='0'>";
2148 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2149 $option_id = $lrow['option_id'];
2150 $option_id_esc = text($option_id);
2151 if ($count % $cols == 0) {
2152 if ($count) {
2153 $s .= "</tr>";
2155 $s .= "<tr>";
2157 $s .= "<td nowrap>";
2158 $checked = in_array($option_id, $avalue);
2159 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2160 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2161 $s .= "</td>";
2163 if ($count) {
2164 $s .= "</tr>";
2166 $s .= "</table>";
2168 } elseif ($data_type == 22) { // a set of labeled text input fields
2169 $tmp = explode('|', $currvalue);
2170 $avalue = array();
2171 foreach ($tmp as $value) {
2172 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2173 $avalue[$matches[1]] = $matches[2];
2177 $lres = sqlStatement("SELECT * FROM list_options " .
2178 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2179 $s .= "<table cellpadding='0' cellspacing='0'>";
2180 while ($lrow = sqlFetchArray($lres)) {
2181 $option_id = $lrow['option_id'];
2182 if (empty($avalue[$option_id])) {
2183 continue;
2186 // Added 5-09 by BM - Translate label if applicable
2187 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . ":&nbsp;</td>";
2189 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id], ENT_NOQUOTES) . "</td></tr>";
2192 $s .= "</table>";
2193 } elseif ($data_type == 23) { // a set of exam results; 3 radio buttons and a text field:
2194 $tmp = explode('|', $currvalue);
2195 $avalue = array();
2196 foreach ($tmp as $value) {
2197 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2198 $avalue[$matches[1]] = $matches[2];
2202 $lres = sqlStatement("SELECT * FROM list_options " .
2203 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2204 $s .= "<table cellpadding='0' cellspacing='0'>";
2205 while ($lrow = sqlFetchArray($lres)) {
2206 $option_id = $lrow['option_id'];
2207 $restype = substr($avalue[$option_id], 0, 1);
2208 $resnote = substr($avalue[$option_id], 2);
2209 if (empty($restype) && empty($resnote)) {
2210 continue;
2213 // Added 5-09 by BM - Translate label if applicable
2214 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2216 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
2217 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2218 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2219 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2220 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2221 $s .= "</tr>";
2224 $s .= "</table>";
2225 } elseif ($data_type == 24) { // the list of active allergies for the current patient
2226 $query = "SELECT title, comments FROM lists WHERE " .
2227 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2228 "ORDER BY begdate";
2229 // echo "<!-- $query -->\n"; // debugging
2230 $lres = sqlStatement($query, array($GLOBALS['pid']));
2231 $count = 0;
2232 while ($lrow = sqlFetchArray($lres)) {
2233 if ($count++) {
2234 $s .= "<br />";
2237 $s .= htmlspecialchars($lrow['title'], ENT_NOQUOTES);
2238 if ($lrow['comments']) {
2239 $s .= ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
2242 } elseif ($data_type == 25) { // a set of labeled checkboxes, each with a text field:
2243 $tmp = explode('|', $currvalue);
2244 $avalue = array();
2245 foreach ($tmp as $value) {
2246 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2247 $avalue[$matches[1]] = $matches[2];
2251 $lres = sqlStatement("SELECT * FROM list_options " .
2252 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2253 $s .= "<table cellpadding='0' cellspacing='0'>";
2254 while ($lrow = sqlFetchArray($lres)) {
2255 $option_id = $lrow['option_id'];
2256 $restype = substr($avalue[$option_id], 0, 1);
2257 $resnote = substr($avalue[$option_id], 2);
2258 if (empty($restype) && empty($resnote)) {
2259 continue;
2262 // Added 5-09 by BM - Translate label if applicable
2263 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2265 $restype = $restype ? xl('Yes') : xl('No');
2266 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2267 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2268 $s .= "</tr>";
2271 $s .= "</table>";
2272 } elseif ($data_type == 27) { // a set of labeled radio buttons
2273 // In this special case, fld_length is the number of columns generated.
2274 $cols = max(1, $frow['fld_length']);
2275 $lres = sqlStatement("SELECT * FROM list_options " .
2276 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2277 $s .= "<table cellspacing='0' cellpadding='0'>";
2278 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2279 $option_id = $lrow['option_id'];
2280 $option_id_esc = text($option_id);
2281 if ($count % $cols == 0) {
2282 if ($count) {
2283 $s .= "</tr>";
2285 $s .= "<tr>";
2287 $s .= "<td nowrap>";
2288 $checked = ((strlen($currvalue) == 0 && $lrow['is_default']) ||
2289 (strlen($currvalue) > 0 && $option_id == $currvalue));
2290 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2291 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2292 $s .= "</td>";
2294 if ($count) {
2295 $s .= "</tr>";
2297 $s .= "</table>";
2298 } elseif ($data_type == 28 || $data_type == 32) { // special case for history of lifestyle status; 3 radio buttons
2299 // and a date text field:
2300 // VicarePlus :: A selection list for smoking status.
2301 $tmp = explode('|', $currvalue);
2302 switch (count($tmp)) {
2303 case "4":
2304 $resnote = $tmp[0];
2305 $restype = $tmp[1];
2306 $resdate = oeFormatShortDate($tmp[2]);
2307 $reslist = $tmp[3];
2308 break;
2309 case "3":
2310 $resnote = $tmp[0];
2311 $restype = $tmp[1];
2312 $resdate = oeFormatShortDate($tmp[2]);
2313 break;
2314 case "2":
2315 $resnote = $tmp[0];
2316 $restype = $tmp[1];
2317 $resdate = "";
2318 break;
2319 case "1":
2320 $resnote = $tmp[0];
2321 $resdate = $restype = "";
2322 break;
2323 default:
2324 $restype = $resdate = $resnote = "";
2325 break;
2328 $s .= "<table cellpadding='0' cellspacing='0'>";
2330 $s .= "<tr>";
2331 $res = "";
2332 if ($restype == "current".$field_id) {
2333 $res = xl('Current');
2336 if ($restype == "quit".$field_id) {
2337 $res = xl('Quit');
2340 if ($restype == "never".$field_id) {
2341 $res = xl('Never');
2344 if ($restype == "not_applicable".$field_id) {
2345 $res = xl('N/A');
2348 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2349 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2350 if ($data_type == 28) {
2351 if (!empty($resnote)) {
2352 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2354 } elseif ($data_type == 32) { //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2355 // changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2356 $smoke_codes = getSmokeCodes();
2357 if (!empty($reslist)) {
2358 if ($smoke_codes[$reslist]!="") {
2359 $code_desc = "( ".$smoke_codes[$reslist]." )";
2362 $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist) . "&nbsp;".text($code_desc)."&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2365 if (!empty($resnote)) {
2366 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2370 if (!empty($res)) {
2371 $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'), ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res, ENT_NOQUOTES) . "&nbsp;</td>";
2374 if ($restype == "quit".$field_id) {
2375 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate, ENT_NOQUOTES) . "&nbsp;</td>";
2378 $s .= "</tr>";
2379 $s .= "</table>";
2380 } elseif ($data_type == 31) { // static text. read-only, of course.
2381 $s .= parse_static_text($frow);
2382 } elseif ($data_type == 34) {
2383 $arr = explode("|*|*|*|", $currvalue);
2384 for ($i=0; $i<sizeof($arr); $i++) {
2385 $s.=$arr[$i];
2387 } elseif ($data_type == 35) { // facility
2388 $urow = $facilityService->getById($currvalue);
2389 $s = htmlspecialchars($urow['name'], ENT_NOQUOTES);
2390 } elseif ($data_type == 36) { // Multi select. Supports backup lists
2391 $values_array = explode("|", $currvalue);
2392 $i = 0;
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)) {
2397 //use back up list
2398 $lrow = sqlQuery("SELECT title FROM list_options " .
2399 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2402 if ($i > 0) {
2403 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2404 } else {
2405 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2408 $i++;
2410 } elseif ($data_type == 40) { // Image from canvas drawing
2411 if ($currvalue) {
2412 $s .= "<img src='" . attr($currvalue) . "'>";
2414 } elseif ($data_type == 41 || $data_type == 42) {
2415 if ($currvalue) {
2416 $s .= "<img style='height:70px;width:auto;' src='" . attr($currvalue) . "'>";
2420 return $s;
2423 // Generate plain text versions of selected LBF field types.
2424 // Currently used by interface/patient_file/download_template.php and interface/main/finder/dynamic_finder_ajax.php.
2425 // More field types might need to be supported here in the future.
2427 function generate_plaintext_field($frow, $currvalue)
2429 global $ISSUE_TYPES;
2431 $data_type = $frow['data_type'];
2432 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2433 $list_id = $frow['list_id'];
2434 $backup_list = $frow['backup_list'];
2435 $s = '';
2437 // generic selection list or the generic selection list with add on the fly
2438 // feature, or radio buttons
2439 // Supports backup lists (for datatypes 1,26,33)
2440 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2441 $lrow = sqlQuery("SELECT title FROM list_options " .
2442 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2443 $s = xl_list_label($lrow['title']);
2444 //if there is no matching value in the corresponding lists check backup list
2445 // only supported in data types 1,26,33
2446 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2447 $lrow = sqlQuery("SELECT title FROM list_options " .
2448 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2449 $s = xl_list_label($lrow['title']);
2451 } elseif ($data_type == 2 || $data_type == 3 || $data_type == 15) { // simple or long text field
2452 $s = $currvalue;
2453 } elseif ($data_type == 4) { // date
2454 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
2455 if (!$modtmp) {
2456 $s = text(oeFormatShortDate($currvalue));
2457 } else {
2458 $s = text(oeFormatDateTime($currvalue));
2460 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2461 $age_asof_date = '';
2462 // Optional display of age or gestational age.
2463 $tmp = optionalAge($frow, $currvalue, $age_asof_date, $description);
2464 if ($tmp) {
2465 $s .= ' ' . $tmp;
2467 } elseif ($data_type == 10 || $data_type == 11) { // provider
2468 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2469 "WHERE id = ?", array($currvalue));
2470 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2471 } elseif ($data_type == 12) { // pharmacy list
2472 $pres = get_pharmacies();
2473 while ($prow = sqlFetchArray($pres)) {
2474 $key = $prow['id'];
2475 if ($currvalue == $key) {
2476 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2477 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2478 $prow['line1'] . ' / ' . $prow['city'];
2481 } elseif ($data_type == 14) { // address book
2482 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2483 "WHERE id = ?", array($currvalue));
2484 $uname = $urow['lname'];
2485 if ($urow['fname']) {
2486 $uname .= ", " . $urow['fname'];
2489 $s = $uname;
2490 } elseif ($data_type == 16) { // insurance company list
2491 $insprovs = getInsuranceProviders();
2492 foreach ($insprovs as $key => $ipname) {
2493 if ($currvalue == $key) {
2494 $s .= $ipname;
2497 } elseif ($data_type == 17) { // issue type
2498 foreach ($ISSUE_TYPES as $key => $value) {
2499 if ($currvalue == $key) {
2500 $s .= $value[1];
2503 } elseif ($data_type == 18) { // visit category
2504 $crow = sqlQuery(
2505 "SELECT pc_catid, pc_catname " .
2506 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2507 array($currvalue)
2509 $s = $crow['pc_catname'];
2510 } elseif ($data_type == 21) { // a set of labeled checkboxes
2511 if (!$list_id) {
2512 $s .= $currvalue ? xlt('Yes') : xlt('No');
2513 } else {
2514 $avalue = explode('|', $currvalue);
2515 $lres = sqlStatement("SELECT * FROM list_options " .
2516 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2517 $count = 0;
2518 while ($lrow = sqlFetchArray($lres)) {
2519 $option_id = $lrow['option_id'];
2520 if (in_array($option_id, $avalue)) {
2521 if ($count++) {
2522 $s .= "; ";
2524 $s .= xl_list_label($lrow['title']);
2528 } elseif ($data_type == 22) { // a set of labeled text input fields
2529 $tmp = explode('|', $currvalue);
2530 $avalue = array();
2531 foreach ($tmp as $value) {
2532 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2533 $avalue[$matches[1]] = $matches[2];
2537 $lres = sqlStatement("SELECT * FROM list_options " .
2538 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2539 while ($lrow = sqlFetchArray($lres)) {
2540 $option_id = $lrow['option_id'];
2541 if (empty($avalue[$option_id])) {
2542 continue;
2545 if ($s !== '') {
2546 $s .= '; ';
2549 $s .= xl_list_label($lrow['title']) . ': ';
2550 $s .= $avalue[$option_id];
2552 } elseif ($data_type == 23) { // A set of exam results; 3 radio buttons and a text field.
2553 // This shows abnormal results only.
2554 $tmp = explode('|', $currvalue);
2555 $avalue = array();
2556 foreach ($tmp as $value) {
2557 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2558 $avalue[$matches[1]] = $matches[2];
2562 $lres = sqlStatement("SELECT * FROM list_options " .
2563 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2564 while ($lrow = sqlFetchArray($lres)) {
2565 $option_id = $lrow['option_id'];
2566 $restype = substr($avalue[$option_id], 0, 1);
2567 $resnote = substr($avalue[$option_id], 2);
2568 if (empty($restype) && empty($resnote)) {
2569 continue;
2572 if ($restype != '2') {
2573 continue; // show abnormal results only
2576 if ($s !== '') {
2577 $s .= '; ';
2580 $s .= xl_list_label($lrow['title']);
2581 if (!empty($resnote)) {
2582 $s .= ': ' . $resnote;
2585 } elseif ($data_type == 24) { // the list of active allergies for the current patient
2586 $query = "SELECT title, comments FROM lists WHERE " .
2587 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2588 "ORDER BY begdate";
2589 $lres = sqlStatement($query, array($GLOBALS['pid']));
2590 $count = 0;
2591 while ($lrow = sqlFetchArray($lres)) {
2592 if ($count++) {
2593 $s .= "; ";
2596 $s .= $lrow['title'];
2597 if ($lrow['comments']) {
2598 $s .= ' (' . $lrow['comments'] . ')';
2601 } elseif ($data_type == 25) { // a set of labeled checkboxes, each with a text field:
2602 $tmp = explode('|', $currvalue);
2603 $avalue = array();
2604 foreach ($tmp as $value) {
2605 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2606 $avalue[$matches[1]] = $matches[2];
2610 $lres = sqlStatement("SELECT * FROM list_options " .
2611 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2612 while ($lrow = sqlFetchArray($lres)) {
2613 $option_id = $lrow['option_id'];
2614 $restype = substr($avalue[$option_id], 0, 1);
2615 $resnote = substr($avalue[$option_id], 2);
2616 if (empty($restype) && empty($resnote)) {
2617 continue;
2620 if ($s !== '') {
2621 $s .= '; ';
2624 $s .= xl_list_label($lrow['title']);
2625 $restype = $restype ? xl('Yes') : xl('No');
2626 $s .= $restype;
2627 if ($resnote) {
2628 $s .= ' ' . $resnote;
2631 } elseif ($data_type == 28 || $data_type == 32) { // special case for history of lifestyle status; 3 radio buttons and a date text field:
2632 // VicarePlus :: A selection list for smoking status.
2633 $tmp = explode('|', $currvalue);
2634 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2635 $restype = count($tmp) > 1 ? $tmp[1] : '';
2636 $resdate = count($tmp) > 2 ? oeFormatShortDate($tmp[2]) : '';
2637 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2638 $res = "";
2639 if ($restype == "current" . $field_id) {
2640 $res = xl('Current');
2643 if ($restype == "quit" . $field_id) {
2644 $res = xl('Quit');
2647 if ($restype == "never" . $field_id) {
2648 $res = xl('Never');
2651 if ($restype == "not_applicable". $field_id) {
2652 $res = xl('N/A');
2655 if ($data_type == 28) {
2656 if (!empty($resnote)) {
2657 $s .= $resnote;
2659 } elseif ($data_type == 32) { // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2660 if (!empty($reslist)) {
2661 $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
2664 if (!empty($resnote)) {
2665 $s .= ' ' . $resnote;
2669 if (!empty($res)) {
2670 if ($s !== '') {
2671 $s .= ' ';
2674 $s .= xl('Status') . ' ' . $res;
2677 if ($restype == "quit".$field_id) {
2678 if ($s !== '') {
2679 $s .= ' ';
2682 $s .= $resdate;
2684 } elseif ($data_type == 36) { // Multi select. Supports backup lists
2685 $values_array = explode("|", $currvalue);
2687 $i = 0;
2688 foreach ($values_array as $value) {
2689 $lrow = sqlQuery("SELECT title FROM list_options " .
2690 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2692 if ($lrow == 0 && !empty($backup_list)) {
2693 //use back up list
2694 $lrow = sqlQuery("SELECT title FROM list_options " .
2695 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2698 if ($i > 0) {
2699 $s = $s . ", " . xl_list_label($lrow['title']);
2700 } else {
2701 $s = xl_list_label($lrow['title']);
2704 $i++;
2708 return $s;
2711 $CPR = 4; // cells per row of generic data
2712 $last_group = '';
2713 $cell_count = 0;
2714 $item_count = 0;
2716 function disp_end_cell()
2718 global $item_count, $cell_count;
2719 if ($item_count > 0) {
2720 echo "</td>";
2721 $item_count = 0;
2725 function disp_end_row()
2727 global $cell_count, $CPR;
2728 disp_end_cell();
2729 if ($cell_count > 0) {
2730 for (; $cell_count < $CPR; ++$cell_count) {
2731 echo "<td></td>";
2734 echo "</tr>\n";
2735 $cell_count = 0;
2739 function disp_end_group()
2741 global $last_group;
2742 if (strlen($last_group) > 0) {
2743 disp_end_row();
2747 // Accumulate action conditions into a JSON expression for the browser side.
2748 function accumActionConditions($field_id, &$condition_str, &$condarr)
2750 $conditions = empty($condarr) ? array() : unserialize($condarr, ['allowed_classes' => false]);
2751 $action = 'skip';
2752 foreach ($conditions as $key => $condition) {
2753 if ($key === 'action') {
2754 // If specified this should be the first array item.
2755 if ($condition) {
2756 $action = $condition;
2758 continue;
2760 if (empty($condition['id'])) {
2761 continue;
2763 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2764 if ($condition_str) {
2765 $condition_str .= ",\n";
2767 $condition_str .= "{" .
2768 "target:" . js_escape($field_id) . ", " .
2769 "action:" . js_escape($action) . ", " .
2770 "id:" . js_escape($condition['id']) . ", " .
2771 "itemid:" . js_escape($condition['itemid']) . ", " .
2772 "operator:" . js_escape($condition['operator']) . ", " .
2773 "value:" . js_escape($condition['value']) . ", " .
2774 "andor:" . js_escape($andor) . "}";
2778 // This checks if the given field with the given value should have an action applied.
2779 // Originally the only action was skip, but now you can also set the field to a specified value.
2780 // It somewhat mirrors the checkSkipConditions function in options.js.php.
2781 // If you use this for multiple layouts in the same script, you should
2782 // clear $sk_layout_items before each layout.
2783 function isSkipped(&$frow, $currvalue)
2785 global $sk_layout_items;
2787 // Accumulate an array of the encountered fields and their values.
2788 // It is assumed that fields appear before they are tested by another field.
2789 // TBD: Bad assumption?
2790 $field_id = $frow['field_id'];
2791 if (!is_array($sk_layout_items)) {
2792 $sk_layout_items = array();
2794 $sk_layout_items[$field_id] = array('row' => $frow, 'value' => $currvalue);
2796 if (empty($frow['conditions'])) {
2797 return false;
2800 $skiprows = unserialize($frow['conditions'], ['allowed_classes' => false]);
2801 $prevandor = '';
2802 $prevcond = false;
2803 $datatype = $frow['data_type'];
2804 $action = 'skip'; // default action if none specified
2806 foreach ($skiprows as $key => $skiprow) {
2807 // id referenced field id
2808 // itemid referenced array key if applicable
2809 // operator "eq", "ne", "se" or "ns"
2810 // value if eq or ne, some string to compare with
2811 // andor "and", "or" or empty
2813 if ($key === 'action') {
2814 // Action value is a string. It can be "skip", or "value=" followed by a value.
2815 $action = $skiprow;
2816 continue;
2819 if (empty($skiprow['id'])) {
2820 continue;
2823 $id = $skiprow['id'];
2824 if (!isset($sk_layout_items[$id])) {
2825 error_log("Function isSkipped() cannot find skip source field '" . errorLogEscape($id) . "'.");
2826 continue;
2828 $itemid = $skiprow['itemid'];
2829 $operator = $skiprow['operator'];
2830 $skipval = $skiprow['value'];
2831 $srcvalue = $sk_layout_items[$id]['value'];
2832 $src_datatype = $sk_layout_items[$id]['row']['data_type'];
2833 $src_list_id = $sk_layout_items[$id]['row']['list_id'];
2835 // Some data types use itemid and we have to dig for their value.
2836 if ($src_datatype == 21 && $src_list_id) { // array of checkboxes
2837 $tmp = explode('|', $srcvalue);
2838 $srcvalue = in_array($itemid, $tmp);
2839 } elseif ($src_datatype == 22 || $src_datatype == 23 || $src_datatype == 25) {
2840 $tmp = explode('|', $srcvalue);
2841 $srcvalue = '';
2842 foreach ($tmp as $tmp2) {
2843 if (strpos($tmp2, "$itemid:") === 0) {
2844 if ($datatype == 22) {
2845 $srcvalue = substr($tmp2, strlen($itemid) + 1);
2846 } else {
2847 $srcvalue = substr($tmp2, strlen($itemid) + 1, 1);
2853 // Compute the result of the test for this condition row.
2854 // PHP's looseness with variable type conversion helps us here.
2855 $condition = false;
2856 if ($operator == 'eq') {
2857 $condition = $srcvalue == $skipval;
2858 } elseif ($operator == 'ne') {
2859 $condition = $srcvalue != $skipval;
2860 } elseif ($operator == 'se') {
2861 $condition = $srcvalue == true;
2862 } elseif ($operator == 'ns') {
2863 $condition = $srcvalue != true;
2864 } else {
2865 error_log("Unknown skip operator '" . errorLogEscape($operator) . "' for field '" . errorLogEscape($field_id) . "'.");
2868 // Logic to accumulate multiple conditions for the same target.
2869 if ($prevandor == 'and') {
2870 $condition = $condition && $prevcond;
2871 } elseif ($prevandor == 'or') {
2872 $condition = $condition || $prevcond;
2874 $prevandor = $skiprow['andor'];
2875 $prevcond = $condition;
2877 return $prevcond ? $action : '';
2880 // Load array of names of the given layout and its groups.
2881 function getLayoutProperties($formtype, &$grparr, $sel = "grp_title")
2883 if ($sel != '*' && strpos($sel, 'grp_group_id') === false) {
2884 $sel = "grp_group_id, $sel";
2886 $gres = sqlStatement("SELECT $sel FROM layout_group_properties WHERE grp_form_id = ? " .
2887 "ORDER BY grp_group_id", array($formtype));
2888 while ($grow = sqlFetchArray($gres)) {
2889 $grparr[$grow['grp_group_id']] = $grow;
2893 function display_layout_rows($formtype, $result1, $result2 = '')
2895 global $item_count, $cell_count, $last_group, $CPR;
2897 $grparr = array();
2898 getLayoutProperties($formtype, $grparr, '*');
2900 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
2902 $fres = sqlStatement("SELECT * FROM layout_options " .
2903 "WHERE form_id = ? AND uor > 0 " .
2904 "ORDER BY group_id, seq", array($formtype));
2906 while ($frow = sqlFetchArray($fres)) {
2907 $this_group = $frow['group_id'];
2908 $titlecols = $frow['titlecols'];
2909 $datacols = $frow['datacols'];
2910 $data_type = $frow['data_type'];
2911 $field_id = $frow['field_id'];
2912 $list_id = $frow['list_id'];
2913 $currvalue = '';
2914 $jump_new_row = isOption($frow['edit_options'], 'J');
2915 $prepend_blank_row = isOption($frow['edit_options'], 'K');
2917 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
2919 if ($formtype == 'DEM') {
2920 if (strpos($field_id, 'em_') === 0) {
2921 // Skip employer related fields, if it's disabled.
2922 if ($GLOBALS['omit_employers']) {
2923 continue;
2926 $tmp = substr($field_id, 3);
2927 if (isset($result2[$tmp])) {
2928 $currvalue = $result2[$tmp];
2930 } else {
2931 if (isset($result1[$field_id])) {
2932 $currvalue = $result1[$field_id];
2935 } else {
2936 if (isset($result1[$field_id])) {
2937 $currvalue = $result1[$field_id];
2941 // Handle a data category (group) change.
2942 if (strcmp($this_group, $last_group) != 0) {
2943 $group_name = $grparr[$this_group]['grp_title'];
2944 // totally skip generating the employer category, if it's disabled.
2945 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
2946 continue;
2949 disp_end_group();
2950 $last_group = $this_group;
2953 // filter out all the empty field data from the patient report.
2954 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2955 // Handle starting of a new row.
2956 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0 || $prepend_blank_row || $jump_new_row) {
2957 disp_end_row();
2958 if ($prepend_blank_row) {
2959 echo "<tr><td class='label' colspan='" . ($CPR + 1) . "'>&nbsp;</td></tr>\n";
2961 echo "<tr>";
2962 if ($group_name) {
2963 echo "<td class='groupname'>";
2964 echo text(xl_layout_label($group_name));
2965 $group_name = '';
2966 } else {
2967 echo "<td valign='top'>&nbsp;";
2970 echo "</td>";
2973 if ($item_count == 0 && $titlecols == 0) {
2974 $titlecols = 1;
2977 // Handle starting of a new label cell.
2978 if ($titlecols > 0) {
2979 disp_end_cell();
2980 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
2981 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
2982 echo "<td class='label_custom' colspan='$titlecols_esc' ";
2983 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2984 echo ">";
2985 $cell_count += $titlecols;
2988 ++$item_count;
2990 // Added 5-09 by BM - Translate label if applicable
2991 if ($frow['title']) {
2992 $tmp = xl_layout_label($frow['title']);
2993 echo text($tmp);
2994 // Append colon only if label does not end with punctuation.
2995 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
2996 echo ':';
2998 } else {
2999 echo "&nbsp;";
3002 // Handle starting of a new data cell.
3003 if ($datacols > 0) {
3004 disp_end_cell();
3005 //echo "<td class='text data' colspan='$datacols' valign='top'";
3006 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3007 echo "<td class='text data' colspan='$datacols_esc'";
3008 //if ($cell_count > 0) echo " style='padding-left:5pt'";
3009 echo ">";
3010 $cell_count += $datacols;
3013 ++$item_count;
3014 echo generate_display_field($frow, $currvalue);
3018 disp_end_group();
3021 function display_layout_tabs($formtype, $result1, $result2 = '')
3023 global $item_count, $cell_count, $last_group, $CPR;
3025 $grparr = array();
3026 getLayoutProperties($formtype, $grparr);
3028 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3029 "WHERE form_id = ? AND uor > 0 " .
3030 "ORDER BY group_id", array($formtype));
3032 $first = true;
3033 while ($frow = sqlFetchArray($fres)) {
3034 $this_group = $frow['group_id'];
3035 // $group_name = substr($this_group, 1);
3036 $group_name = $grparr[$this_group]['grp_title'];
3037 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3038 continue;
3041 <li <?php echo $first ? 'class="current"' : '' ?>>
3042 <a href="#" id="header_tab_<?php echo attr($group_name); ?>">
3043 <?php echo text(xl_layout_label($group_name)); ?></a>
3044 </li>
3045 <?php
3046 $first = false;
3050 function display_layout_tabs_data($formtype, $result1, $result2 = '')
3052 global $item_count, $cell_count, $last_group, $CPR;
3054 $grparr = array();
3055 getLayoutProperties($formtype, $grparr, '*');
3057 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3059 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3060 "WHERE form_id = ? AND uor > 0 " .
3061 "ORDER BY group_id", array($formtype));
3063 $first = true;
3064 while ($frow = sqlFetchArray($fres)) {
3065 $this_group = isset($frow['group_id']) ? $frow['group_id'] : "" ;
3067 if ($grparr[$this_group]['grp_columns'] === 'Employer' && $GLOBALS['omit_employers']) {
3068 continue;
3070 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3071 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : xl_layout_label($grparr[$this_group]['grp_subtitle']);
3073 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3074 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3075 "ORDER BY seq", array($formtype, $this_group));
3078 <div class="tab <?php echo $first ? 'current' : '' ?>">
3079 <table border='0' cellpadding='0'>
3081 <?php
3082 while ($group_fields = sqlFetchArray($group_fields_query)) {
3083 $titlecols = $group_fields['titlecols'];
3084 $datacols = $group_fields['datacols'];
3085 $data_type = $group_fields['data_type'];
3086 $field_id = $group_fields['field_id'];
3087 $list_id = $group_fields['list_id'];
3088 $currvalue = '';
3089 $edit_options = $group_fields['edit_options'];
3090 $jump_new_row = isOption($edit_options, 'J');
3091 $prepend_blank_row = isOption($edit_options, 'K');
3093 if ($formtype == 'DEM') {
3094 if (strpos($field_id, 'em_') === 0) {
3095 // Skip employer related fields, if it's disabled.
3096 if ($GLOBALS['omit_employers']) {
3097 continue;
3100 $tmp = substr($field_id, 3);
3101 if (isset($result2[$tmp])) {
3102 $currvalue = $result2[$tmp];
3104 } else {
3105 if (isset($result1[$field_id])) {
3106 $currvalue = $result1[$field_id];
3109 } else {
3110 if (isset($result1[$field_id])) {
3111 $currvalue = $result1[$field_id];
3115 // Skip this field if action conditions call for that.
3116 // Note this also accumulates info for subsequent skip tests.
3117 $skip_this_field = isSkipped($group_fields, $currvalue) == 'skip';
3119 // Skip this field if its do-not-print option is set.
3120 if (isOption($edit_options, 'X') !== false) {
3121 $skip_this_field = true;
3124 // Handle a data category (group) change.
3125 if (strcmp($this_group, $last_group) != 0) {
3126 $group_name = $grparr[$this_group]['grp_title'];
3127 // totally skip generating the employer category, if it's disabled.
3128 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3129 continue;
3131 $last_group = $this_group;
3134 // Handle starting of a new row.
3135 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0 || $prepend_blank_row || $jump_new_row) {
3136 disp_end_row();
3137 if ($subtitle) {
3138 // Group subtitle exists and is not displayed yet.
3139 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3140 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3141 $subtitle = '';
3143 if ($prepend_blank_row) {
3144 echo "<tr><td class='label' colspan='$CPR'>&nbsp;</td></tr>\n";
3146 echo "<tr>";
3149 if ($item_count == 0 && $titlecols == 0) {
3150 $titlecols = 1;
3153 // Handle starting of a new label cell.
3154 if ($titlecols > 0) {
3155 disp_end_cell();
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) . "'";
3159 echo ">";
3160 $cell_count += $titlecols;
3163 ++$item_count;
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 } elseif ($group_fields['title']) {
3170 $tmp = xl_layout_label($group_fields['title']);
3171 echo text($tmp);
3172 // Append colon only if label does not end with punctuation.
3173 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3174 echo ':';
3176 } else {
3177 echo "&nbsp;";
3179 echo "</span>";
3181 // Handle starting of a new data cell.
3182 if ($datacols > 0) {
3183 disp_end_cell();
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'";
3191 echo ">";
3192 $cell_count += $datacols;
3193 } else {
3194 $field_id = 'text_'.$group_fields['field_id'];
3195 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
3198 ++$item_count;
3199 if (!$skip_this_field) {
3200 echo generate_display_field($group_fields, $currvalue);
3204 disp_end_row();
3207 </table>
3208 </div>
3210 <?php
3212 $first = false;
3216 function display_layout_tabs_data_editable($formtype, $result1, $result2 = '')
3218 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
3220 $grparr = array();
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));
3229 $first = true;
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']) {
3238 continue;
3240 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3241 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : xl_layout_label($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'>
3251 <?php
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'];
3259 $currvalue = '';
3260 $action = 'skip';
3261 $jump_new_row = isOption($group_fields['edit_options'], 'J');
3262 $prepend_blank_row = isOption($group_fields['edit_options'], 'K');
3264 // Accumulate action conditions into a JSON expression for the browser side.
3265 accumActionConditions($field_id, $condition_str, $group_fields['conditions']);
3267 if ($formtype == 'DEM') {
3268 if (strpos($field_id, 'em_') === 0) {
3269 // Skip employer related fields, if it's disabled.
3270 if ($GLOBALS['omit_employers']) {
3271 continue;
3274 $tmp = substr($field_id, 3);
3275 if (isset($result2[$tmp])) {
3276 $currvalue = $result2[$tmp];
3278 } else {
3279 if (isset($result1[$field_id])) {
3280 $currvalue = $result1[$field_id];
3283 } else {
3284 if (isset($result1[$field_id])) {
3285 $currvalue = $result1[$field_id];
3289 // Handle a data category (group) change.
3290 if (strcmp($this_group, $last_group) != 0) {
3291 // totally skip generating the employer category, if it's disabled.
3292 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3293 continue;
3296 $last_group = $this_group;
3299 // Handle starting of a new row.
3300 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0 || $prepend_blank_row || $jump_new_row) {
3301 disp_end_row();
3302 if ($subtitle) {
3303 // Group subtitle exists and is not displayed yet.
3304 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3305 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3306 $subtitle = '';
3308 if ($prepend_blank_row) {
3309 echo "<tr><td class='label' colspan='$CPR'>&nbsp;</td></tr>\n";
3311 echo "<tr>";
3314 if ($item_count == 0 && $titlecols == 0) {
3315 $titlecols = 1;
3318 // Handle starting of a new label cell.
3319 if ($titlecols > 0) {
3320 disp_end_cell();
3321 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3322 $field_id_label = 'label_'.$group_fields['field_id'];
3323 echo "<td class='label_custom' colspan='$titlecols_esc'";
3324 // This ID is used by skip conditions.
3325 echo " id='label_id_" . attr($field_id) . "'";
3326 echo ">";
3327 $cell_count += $titlecols;
3330 ++$item_count;
3332 if ($group_fields['title']) {
3333 $tmp = xl_layout_label($group_fields['title']);
3334 echo text($tmp);
3335 // Append colon only if label does not end with punctuation.
3336 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3337 echo ':';
3339 } else {
3340 echo "&nbsp;";
3343 // Handle starting of a new data cell.
3344 if ($datacols > 0) {
3345 disp_end_cell();
3346 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3347 $field_id = 'text_'.$group_fields['field_id'];
3348 echo "<td class='text data' colspan='$datacols_esc'";
3349 // This ID is used by action conditions.
3350 echo " id='value_id_" . attr($field_id) . "'";
3351 echo ">";
3352 $cell_count += $datacols;
3355 ++$item_count;
3357 echo generate_form_field($group_fields, $currvalue);
3361 </table>
3362 </div>
3364 <?php
3366 $first = false;
3370 // From the currently posted HTML form, this gets the value of the
3371 // field corresponding to the provided layout_options table row.
3373 function get_layout_form_value($frow, $prefix = 'form_')
3375 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
3376 $data_type = $frow['data_type'];
3377 $field_id = $frow['field_id'];
3378 $value = '';
3379 if (isset($_POST["$prefix$field_id"])) {
3380 if ($data_type == 4) {
3381 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
3382 if (!$modtmp) {
3383 $value = DateToYYYYMMDD($_POST["$prefix$field_id"]);
3384 } else {
3385 $value = DateTimeToYYYYMMDDHHMMSS($_POST["$prefix$field_id"]);
3387 } elseif ($data_type == 21) {
3388 if (!$frow['list_id']) {
3389 if (!empty($_POST["form_$field_id"])) {
3390 $value = xlt('Yes');
3392 } else {
3393 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
3394 // must be concatenated into a |-separated string.
3395 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3396 if (strlen($value)) {
3397 $value .= '|';
3399 $value .= $key;
3402 } elseif ($data_type == 22) {
3403 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
3404 // into "key:value|key:value|...".
3405 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3406 $val = str_replace('|', ' ', $val);
3407 if (strlen($value)) {
3408 $value .= '|';
3411 $value .= "$key:$val";
3413 } elseif ($data_type == 23) {
3414 // $_POST["$prefix$field_id"] is an array of text fields with companion
3415 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
3416 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3417 $restype = $_POST["radio_{$field_id}"][$key];
3418 if (empty($restype)) {
3419 $restype = '0';
3422 $val = str_replace('|', ' ', $val);
3423 if (strlen($value)) {
3424 $value .= '|';
3427 $value .= "$key:$restype:$val";
3429 } elseif ($data_type == 25) {
3430 // $_POST["$prefix$field_id"] is an array of text fields with companion
3431 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
3432 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3433 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
3434 $val = str_replace('|', ' ', $val);
3435 if (strlen($value)) {
3436 $value .= '|';
3439 $value .= "$key:$restype:$val";
3441 } elseif ($data_type == 28 || $data_type == 32) {
3442 // $_POST["$prefix$field_id"] is an date text fields with companion
3443 // radio buttons to be imploded into "notes|type|date".
3444 $restype = $_POST["radio_{$field_id}"];
3445 if (empty($restype)) {
3446 $restype = '0';
3449 $resdate = DateToYYYYMMDD(str_replace('|', ' ', $_POST["date_$field_id"]));
3450 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3451 if ($data_type == 32) {
3452 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
3453 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3454 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
3455 $value = "$res_text_note|$restype|$resdate|$reslist";
3456 } else {
3457 $value = "$resnote|$restype|$resdate";
3459 } elseif ($data_type == 36) {
3460 $value_array = $_POST["form_$field_id"];
3461 $i = 0;
3462 foreach ($value_array as $key => $valueofkey) {
3463 if ($i == 0) {
3464 $value = $valueofkey;
3465 } else {
3466 $value = $value . "|" . $valueofkey;
3469 $i++;
3471 } else {
3472 $value = $_POST["$prefix$field_id"];
3476 // Better to die than to silently truncate data!
3477 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength) {
3478 die(htmlspecialchars(xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
3479 ":<br />&nbsp;<br />".htmlspecialchars($value, ENT_NOQUOTES));
3482 return trim($value);
3485 // Generate JavaScript validation logic for the required fields.
3487 function generate_layout_validation($form_id)
3489 $fres = sqlStatement("SELECT * FROM layout_options " .
3490 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
3491 "ORDER BY group_id, seq", array($form_id));
3493 while ($frow = sqlFetchArray($fres)) {
3494 $data_type = $frow['data_type'];
3495 $field_id = $frow['field_id'];
3496 $fldtitle = $frow['title'];
3497 if (!$fldtitle) {
3498 $fldtitle = $frow['description'];
3501 $fldname = attr("form_$field_id");
3503 if ($data_type == 40) {
3504 $fldid = "form_" . $field_id;
3505 // Move canvas image data to its hidden form field so the server will get it.
3506 echo
3507 " var canfld = f[" . js_escape($fldid) . "];\n" .
3508 " if (canfld) canfld.value = lbfCanvasGetData(" . js_escape($fldid) . ");\n";
3509 continue;
3511 if ($data_type == 41 || $data_type == 42) {
3512 $fldid = "form_" . $field_id;
3513 // Move canvas image data to its hidden form field so the server will get it.
3514 echo " lbfSetSignature(" . js_escape($fldid) . ");\n";
3515 continue;
3517 if ($frow['uor'] < 2) {
3518 continue;
3521 echo " if (f.$fldname && !f.$fldname.disabled) {\n";
3522 switch ($data_type) {
3523 case 1:
3524 case 11:
3525 case 12:
3526 case 13:
3527 case 14:
3528 case 26:
3529 echo
3530 " if (f.$fldname.selectedIndex <= 0) {\n" .
3531 " alert(" . xlj('Please choose a value for') . " + " .
3532 "\":\\n\" + " . js_escape(xl_layout_label($fldtitle)) . ");\n" .
3533 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3534 " return false;\n" .
3535 " }\n";
3536 break;
3537 case 33:
3538 echo
3539 " if (f.$fldname.selectedIndex <= 0) {\n" .
3540 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3541 " errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3542 " }\n";
3543 break;
3544 case 27: // radio buttons
3545 echo
3546 " var i = 0;\n" .
3547 " for (; i < f.$fldname.length; ++i) if (f.{$fldname}[i].checked) break;\n" .
3548 " if (i >= f.$fldname.length) {\n" .
3549 " alert(" . xlj('Please choose a value for') . " + " .
3550 "\":\\n\" + " . js_escape(xl_layout_label($fldtitle)) . ");\n" .
3551 " return false;\n" .
3552 " }\n";
3553 break;
3554 case 2:
3555 case 3:
3556 case 4:
3557 case 15:
3558 echo
3559 " if (trimlen(f.$fldname.value) == 0) {\n" .
3560 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3561 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
3562 " $('#" . $fldname . "').attr('style','background:red'); \n" .
3563 " errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3564 " } else { " .
3565 " $('#" . $fldname . "').attr('style',''); " .
3566 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
3567 " } \n";
3568 break;
3569 case 36: // multi select
3570 echo
3571 " var multi_select=f['$fldname"."[]']; \n " .
3572 " var multi_choice_made=false; \n".
3573 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
3574 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
3575 " } \n" .
3576 " if(!multi_choice_made)
3577 errMsgs[errMsgs.length] = " . js_escape(xl_layout_label($fldtitle)) . "; \n" .
3579 break;
3581 echo " }\n";
3586 * DROPDOWN FOR FACILITIES
3588 * build a dropdown with all facilities
3590 * @param string $selected - name of the currently selected facility
3591 * use '0' for "unspecified facility"
3592 * use '' for "All facilities" (the default)
3593 * @param string $name - the name/id for select form (defaults to "form_facility")
3594 * @param boolean $allow_unspecified - include an option for "unspecified" facility
3595 * defaults to true
3596 * @return void - just echo the html encoded string
3598 * Note: This should become a data-type at some point, according to Brady
3600 function dropdown_facility(
3601 $selected = '',
3602 $name = 'form_facility',
3603 $allow_unspecified = true,
3604 $allow_allfacilities = true,
3605 $disabled = '',
3606 $onchange = ''
3609 global $facilityService;
3611 $have_selected = false;
3612 $fres = $facilityService->getAll();
3614 echo " <select class='form-control' name='" . attr($name) . "' id='" . attr($name) . "'";
3615 if ($onchange) {
3616 echo " onchange='$onchange'";
3619 echo " $disabled>\n";
3621 if ($allow_allfacilities) {
3622 $option_value = '';
3623 $option_selected_attr = '';
3624 if ($selected == '') {
3625 $option_selected_attr = ' selected="selected"';
3626 $have_selected = true;
3629 $option_content = '-- ' . xl('All Facilities') . ' --';
3630 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3631 } elseif ($allow_unspecified) {
3632 $option_value = '0';
3633 $option_selected_attr = '';
3634 if ($selected == '0') {
3635 $option_selected_attr = ' selected="selected"';
3636 $have_selected = true;
3639 $option_content = '-- ' . xl('Unspecified') . ' --';
3640 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3643 foreach ($fres as $frow) {
3644 $facility_id = $frow['id'];
3645 $option_value = $facility_id;
3646 $option_selected_attr = '';
3647 if ($selected == $facility_id) {
3648 $option_selected_attr = ' selected="selected"';
3649 $have_selected = true;
3652 $option_content = $frow['name'];
3653 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3656 if ($allow_unspecified && $allow_allfacilities) {
3657 $option_value = '0';
3658 $option_selected_attr = '';
3659 if ($selected == '0') {
3660 $option_selected_attr = ' selected="selected"';
3661 $have_selected = true;
3664 $option_content = '-- ' . xl('Unspecified') . ' --';
3665 echo " <option value='" . attr($option_value) . "' $option_selected_attr>" . text($option_content) . "</option>\n";
3668 if (!$have_selected) {
3669 $option_value = $selected;
3670 $option_label = '(' . xl('Do not change') . ')';
3671 $option_content = xl('Missing or Invalid');
3672 echo " <option value='" . attr($option_value) . "' label='" . attr($option_label) . "' selected='selected'>" . text($option_content) . "</option>\n";
3675 echo " </select>\n";
3678 // Expand Collapse Widget
3679 // This forms the header and functionality component of the widget. The information that is displayed
3680 // then follows this function followed by a closing div tag
3682 // $title is the title of the section (already translated)
3683 // $label is identifier used in the tag id's and sql columns
3684 // $buttonLabel is the button label text (already translated)
3685 // $buttonLink is the button link information
3686 // $buttonClass is any additional needed class elements for the button tag
3687 // $linkMethod is the button link method ('javascript' vs 'html')
3688 // $bodyClass is to set class(es) of the body
3689 // $auth is a flag to decide whether to show the button
3690 // $fixedWidth is to flag whether width is fixed
3691 // $forceExpandAlways is a flag to force the widget to always be expanded
3693 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways = false)
3695 if ($fixedWidth) {
3696 echo "<div class='section-header'>";
3697 } else {
3698 echo "<div class='section-header-dynamic'>";
3701 echo "<table><tr>";
3702 if ($auth) {
3703 // show button, since authorized
3704 // first prepare class string
3705 if ($buttonClass) {
3706 $class_string = "css_button_small " . $buttonClass;
3707 } else {
3708 $class_string = "css_button_small";
3711 // next, create the link
3712 if ($linkMethod == "javascript") {
3713 echo "<td><a class='" . attr($class_string) . "' href='javascript:;' onclick='" . $buttonLink . "'";
3714 } else {
3715 echo "<td><a class='" . attr($class_string) . "' href='" . $buttonLink . "'";
3716 if (!isset($_SESSION['patient_portal_onsite_two'])) {
3717 // prevent an error from occuring when calling the function from the patient portal
3718 echo " onclick='top.restoreSession()'";
3722 echo "><span>" .
3723 text($buttonLabel) . "</span></a></td>";
3726 if ($forceExpandAlways) {
3727 // Special case to force the widget to always be expanded
3728 echo "<td><span class='text'><b>" . text($title) . "</b></span>";
3729 $indicatorTag ="style='display:none'";
3732 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3733 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this," .
3734 attr_js($label."_ps_expand") . ")'><span class='text'><b>";
3735 echo text($title) . "</b></span>";
3737 if (isset($_SESSION['patient_portal_onsite_two'])) {
3738 // collapse all entries in the patient portal
3739 $text = xl('expand');
3740 } elseif (getUserSetting($label."_ps_expand")) {
3741 $text = xl('collapse');
3742 } else {
3743 $text = xl('expand');
3746 echo " (<span class='indicator'>" . text($text) .
3747 "</span>)</a></td>";
3748 echo "</tr></table>";
3749 echo "</div>";
3750 if ($forceExpandAlways) {
3751 // Special case to force the widget to always be expanded
3752 $styling = "";
3753 } elseif (isset($_SESSION['patient_portal_onsite_two'])) {
3754 // collapse all entries in the patient portal
3755 $styling = "style='display:none'";
3756 } elseif (getUserSetting($label."_ps_expand")) {
3757 $styling = "";
3758 } else {
3759 $styling = "style='display:none'";
3762 if ($bodyClass) {
3763 $styling .= " class='" . attr($bodyClass) . "'";
3766 //next, create the first div tag to hold the information
3767 // note the code that calls this function will then place the ending div tag after the data
3768 echo "<div id='" . attr($label) . "_ps_expand' " . $styling . ">";
3771 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3772 function billing_facility($name, $select)
3774 global $facilityService;
3776 $fres = $facilityService->getAllBillingLocations();
3777 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' class='form-control' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3778 foreach ($fres as $facrow) {
3779 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3780 echo "<option value=".htmlspecialchars($facrow['id'], ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3783 echo "</select>";
3786 // Generic function to get the translated title value for a particular list option.
3788 function getListItemTitle($list, $option)
3790 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3791 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3792 if (empty($row['title'])) {
3793 return $option;
3796 return xl_list_label($row['title']);
3799 //function to get the translated title value in Patient Transactions
3800 function getLayoutTitle($list, $option)
3802 $row = sqlQuery("SELECT grp_title FROM layout_group_properties " .
3803 "WHERE grp_mapping = ? AND grp_form_id = ? ", array($list, $option));
3805 if (empty($row['grp_title'])) {
3806 return $option;
3808 return xl_list_label($row['grp_title']);
3810 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3811 function getSmokeCodes()
3813 $smoking_codes_arr = array();
3814 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3815 while ($codes_row = sqlFetchArray($smoking_codes)) {
3816 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3819 return $smoking_codes_arr;
3822 // Get the current value for a layout based form field.
3823 // Depending on options this might come from lbf_data, patient_data,
3824 // form_encounter, shared_attributes or elsewhere.
3825 // Returns FALSE if the field ID is invalid (layout error).
3827 function lbf_current_value($frow, $formid, $encounter)
3829 global $pid;
3830 $formname = $frow['form_id'];
3831 $field_id = $frow['field_id'];
3832 $source = $frow['source'];
3833 $currvalue = '';
3834 $deffname = $formname . '_default_' . $field_id;
3835 if ($source == 'D' || $source == 'H') {
3836 // Get from patient_data, employer_data or history_data.
3837 if ($source == 'H') {
3838 $table = 'history_data';
3839 $orderby = 'ORDER BY date DESC LIMIT 1';
3840 } elseif (strpos($field_id, 'em_') === 0) {
3841 $field_id = substr($field_id, 3);
3842 $table = 'employer_data';
3843 $orderby = 'ORDER BY date DESC LIMIT 1';
3844 } else {
3845 $table = 'patient_data';
3846 $orderby = '';
3849 // It is an error if the field does not exist, but don't crash.
3850 $tmp = sqlQuery("SHOW COLUMNS FROM " . escape_table_name($table) . " WHERE Field = ?", array($field_id));
3851 if (empty($tmp)) {
3852 return '*?*';
3855 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM " . escape_table_name($table) . " WHERE pid = ? $orderby", array($pid));
3856 if (isset($pdrow)) {
3857 $currvalue = $pdrow['field_value'];
3859 } elseif ($source == 'E') {
3860 $sarow = false;
3861 if ($encounter) {
3862 // Get value from shared_attributes of the current encounter.
3863 $sarow = sqlQuery(
3864 "SELECT field_value FROM shared_attributes WHERE " .
3865 "pid = ? AND encounter = ? AND field_id = ?",
3866 array($pid, $encounter, $field_id)
3868 if (!empty($sarow)) {
3869 $currvalue = $sarow['field_value'];
3871 } elseif ($formid) {
3872 // Get from shared_attributes of the encounter that this form is linked to.
3873 // Note the importance of having an index on forms.form_id.
3874 $sarow = sqlQuery(
3875 "SELECT sa.field_value " .
3876 "FROM forms AS f, shared_attributes AS sa WHERE " .
3877 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3878 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3879 array($formid, $formname, $field_id)
3881 if (!empty($sarow)) {
3882 $currvalue = $sarow['field_value'];
3884 } else {
3885 // New form and encounter not available, this should not happen.
3887 if (empty($sarow) && !$formid) {
3888 // New form, see if there is a custom default from a plugin.
3889 if (function_exists($deffname)) {
3890 $currvalue = call_user_func($deffname);
3893 } elseif ($source == 'V') {
3894 if ($encounter) {
3895 // Get value from the current encounter's form_encounter.
3896 $ferow = sqlQuery(
3897 "SELECT * FROM form_encounter WHERE " .
3898 "pid = ? AND encounter = ?",
3899 array($pid, $encounter)
3901 if (isset($ferow[$field_id])) {
3902 $currvalue = $ferow[$field_id];
3904 } elseif ($formid) {
3905 // Get value from the form_encounter that this form is linked to.
3906 $ferow = sqlQuery(
3907 "SELECT fe.* " .
3908 "FROM forms AS f, form_encounter AS fe WHERE " .
3909 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3910 "fe.pid = f.pid AND fe.encounter = f.encounter",
3911 array($formid, $formname)
3913 if (isset($ferow[$field_id])) {
3914 $currvalue = $ferow[$field_id];
3916 } else {
3917 // New form and encounter not available, this should not happen.
3919 } elseif ($formid) {
3920 // This is a normal form field.
3921 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3922 "form_id = ? AND field_id = ?", array($formid, $field_id));
3923 if (!empty($ldrow)) {
3924 $currvalue = $ldrow['field_value'];
3926 } else {
3927 // New form, see if there is a custom default from a plugin.
3928 if (function_exists($deffname)) {
3929 $currvalue = call_user_func($deffname);
3933 return $currvalue;
3936 function signer_head()
3938 return <<<EOD
3939 <link href="{$GLOBALS['web_root']}/portal/sign/css/signer_modal.css?v={$GLOBALS['v_js_includes']}" rel="stylesheet"/>
3940 <script src="{$GLOBALS['web_root']}/portal/sign/assets/signature_pad.umd.js?v={$GLOBALS['v_js_includes']}"></script>
3941 <script src="{$GLOBALS['web_root']}/portal/sign/assets/signer_api.js?v={$GLOBALS['v_js_includes']}"></script>
3942 EOD;
3945 // This returns stuff that needs to go into the <head> section of a caller using
3946 // the drawable image field type in a form.
3947 // A TRUE argument makes the widget controls smaller.
3949 function lbf_canvas_head($small = true)
3951 $s = <<<EOD
3952 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas/css/literallycanvas.css" rel="stylesheet" />
3953 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/build/react-with-addons.min.js"></script>
3954 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/build/react-dom.min.js"></script>
3955 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas/js/literallycanvas.min.js"></script>
3956 EOD;
3957 if ($small) {
3958 $s .= <<<EOD
3959 <style>
3960 /* Custom LiterallyCanvas styling.
3961 * This makes the widget 25% less tall and adjusts some other things accordingly.
3963 .literally {
3964 min-height:100%;min-width:300px; /* Was 400, unspecified */
3966 .literally .lc-picker .toolbar-button {
3967 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3969 .literally .color-well {
3970 font-size:8px;width:49px; /* Was 10, 60 */
3972 .literally .color-well-color-container {
3973 width:21px;height:21px; /* Was 28, 28 */
3975 .literally .lc-picker {
3976 width:50px; /* Was 61 */
3978 .literally .lc-drawing.with-gui {
3979 left:50px; /* Was 61 */
3981 .literally .lc-options {
3982 left:50px; /* Was 61 */
3984 .literally .color-picker-popup {
3985 left:49px;bottom:0px; /* Was 60, 31 */
3987 </style>
3988 EOD;
3991 return $s;
3995 * Test if modifier($test) is in array of options for data type.
3997 * @param json array $options ["G","P","T"], ["G"] or could be legacy string with form "GPT", "G", "012"
3998 * @param string $test
3999 * @return boolean
4001 function isOption($options, $test)
4003 if (empty($options) || !isset($test) || $options == "null") {
4004 return false; // why bother?
4006 if (strpos($options, ',') === false) { // not json array of modifiers.
4007 // could be string of char's or single element of json ["RO"] or "TP" or "P" e.t.c.
4008 json_decode($options, true); // test if options json. json_last_error() will return JSON_ERROR_SYNTAX if not.
4009 // if of form ["RO"] (single modifier) means not legacy so continue on.
4010 if (is_string($options) && (json_last_error() !== JSON_ERROR_NONE)) { // nope, it's string.
4011 $t = str_split(trim($options)); // very good chance it's legacy modifier string.
4012 $options = json_encode($t); // make it json array to convert from legacy to new modifier json schema.
4016 $options = json_decode($options, true); // all should now be json
4018 return !is_null($options) && in_array($test, $options, true) ? true : false; // finally the truth!