Display fix: width in manila for demographics (#1909)
[openemr.git] / library / options.inc.php
blob1aaa6c7c079f55d5e1d825232b1e1b98a687b4be
1 <?php
2 // Copyright (C) 2007-2017 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
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 // L = Lab Order ("ord_lab") types only (address book)
28 // N = Show in New Patient form
29 // O = Procedure Order ("ord_*") types only (address book)
30 // P = Default to previous value when current value is not yet set
31 // R = Distributor types only (address book)
32 // T = Use description as default Text
33 // U = Capitalize all letters (text fields)
34 // V = Vendor types only (address book)
35 // 0 = Read Only - the input element's "disabled" property is set
36 // 1 = Write Once (not editable when not empty) (text fields)
37 // 2 = Show descriptions instead of codes for billing code input
39 require_once("user.inc");
40 require_once("patient.inc");
41 require_once("lists.inc");
42 require_once(dirname(dirname(__FILE__)) . "/custom/code_types.inc.php");
44 use OpenEMR\Services\FacilityService;
46 $facilityService = new FacilityService();
48 $date_init = "";
50 function get_pharmacies()
52 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
53 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
54 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
55 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
56 "AND p.type = 2 " .
57 "ORDER BY name, area_code, prefix, number");
60 function optionalAge($frow, $date, &$asof, $description = '')
62 $asof = '';
63 if (empty($date)) {
64 return '';
67 $date = substr($date, 0, 10);
68 if (isOption($frow['edit_options'], 'A') !== false) {
69 $format = 0;
70 } elseif (isOption($frow['edit_options'], 'B') !== false) {
71 $format = 3;
72 } else {
73 return '';
76 if (isOption($frow['form_id'], 'LBF') === 0) {
77 $tmp = sqlQuery(
78 "SELECT date FROM form_encounter WHERE " .
79 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
80 array($GLOBALS['pid'], $GLOBALS['encounter'])
82 if (!empty($tmp['date'])) {
83 $asof = substr($tmp['date'], 0, 10);
86 if ($description === '') {
87 $prefix = ($format ? xl('Gest age') : xl('Age')) . ' ';
88 } else {
89 $prefix = $description . ' ';
91 return $prefix . oeFormatAge($date, $asof, $format);
94 // Function to generate a drop-list.
96 function generate_select_list(
97 $tag_name,
98 $list_id,
99 $currvalue,
100 $title,
101 $empty_name = ' ',
102 $class = '',
103 $onchange = '',
104 $tag_id = '',
105 $custom_attributes = null,
106 $multiple = false,
107 $backup_list = ''
109 $s = '';
111 $tag_name_esc = attr($tag_name);
113 if ($multiple) {
114 $tag_name_esc = $tag_name_esc . "[]";
117 $s .= "<select name='$tag_name_esc'";
119 if ($multiple) {
120 $s .= " multiple='multiple'";
123 $tag_id_esc = attr($tag_name);
125 if ($tag_id != '') {
126 $tag_id_esc = attr($tag_id);
129 $s .= " id='$tag_id_esc'";
131 if (!empty($class)) {
132 $class_esc = attr($class);
133 $s .= " class='form-control $class_esc'";
134 } else {
135 $s .= " class='form-control'";
138 if ($onchange) {
139 $s .= " onchange='$onchange'";
142 if ($custom_attributes != null && is_array($custom_attributes)) {
143 foreach ($custom_attributes as $attr => $val) {
144 if (isset($custom_attributes [$attr])) {
145 $s .= " " . attr($attr) . "='" . attr($val) . "'";
150 $selectTitle = attr($title);
151 $s .= " title='$selectTitle'>";
152 $selectEmptyName = xlt($empty_name);
153 if ($empty_name) {
154 $s .= "<option value=''>" . $selectEmptyName . "</option>";
157 // List order depends on language translation options.
158 // (Note we do not need to worry about the list order in the algorithm
159 // after the below code block since that is where searches for exceptions
160 // are done which include inactive items or items from a backup
161 // list; note these will always be shown at the bottom of the list no matter the
162 // chosen order.)
163 $lang_id = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
164 // sort by title
165 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) || !$GLOBALS['translate_lists']) {
166 // do not translate
167 if ($GLOBALS['gb_how_sort_list'] == '0') {
168 // order by seq
169 $order_by_sql = "seq, title";
170 } else { //$GLOBALS['gb_how_sort_list'] == '1'
171 // order by title
172 $order_by_sql = "title, seq";
175 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
176 } else {
177 // do translate
178 if ($GLOBALS['gb_how_sort_list'] == '0') {
179 // order by seq
180 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
181 } else { //$GLOBALS['gb_how_sort_list'] == '1'
182 // order by title
183 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
186 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
187 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
188 "FROM list_options AS lo " .
189 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
190 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
191 "ld.lang_id = ? " .
192 "WHERE lo.list_id = ? AND lo.activity=1 " .
193 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
196 $got_selected = false;
198 while ($lrow = sqlFetchArray($lres)) {
199 $selectedValues = explode("|", $currvalue);
201 $optionValue = attr($lrow ['option_id']);
202 $s .= "<option value='$optionValue'";
204 if ((strlen($currvalue) == 0 && $lrow ['is_default']) || (strlen($currvalue) > 0 && in_array($lrow ['option_id'], $selectedValues))) {
205 $s .= " selected";
206 $got_selected = true;
209 // Already has been translated above (if applicable), so do not need to use
210 // the xl_list_label() function here
211 $optionLabel = text($lrow ['title']);
212 $s .= ">$optionLabel</option>\n";
216 To show the inactive item in the list if the value is saved to database
218 if (!$got_selected && strlen($currvalue) > 0) {
219 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
220 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
221 $lrow_inactive = sqlFetchArray($lres_inactive);
222 if ($lrow_inactive['option_id']) {
223 $optionValue = htmlspecialchars($lrow_inactive['option_id'], ENT_QUOTES);
224 $s .= "<option value='$optionValue' selected>" . htmlspecialchars(xl_list_label($lrow_inactive['title']), ENT_NOQUOTES) . "</option>\n";
225 $got_selected = true;
229 if (!$got_selected && strlen($currvalue) > 0 && !$multiple) {
230 $list_id = $backup_list;
231 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
233 if ($lrow > 0 && !empty($backup_list)) {
234 $selected = text(xl_list_label($lrow ['title']));
235 $s .= "<option value='$currescaped' selected> $selected </option>";
236 $s .= "</select>";
237 } else {
238 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
239 $s .= "</select>";
240 $fontTitle = xlt('Please choose a valid selection from the list.');
241 $fontText = xlt('Fix this');
242 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
244 } elseif (!$got_selected && strlen($currvalue) > 0 && $multiple) {
245 //if not found in main list, display all selected values that exist in backup list
246 $list_id = $backup_list;
248 $got_selected_backup = false;
249 if (!empty($backup_list)) {
250 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
251 while ($lrow_backup = sqlFetchArray($lres_backup)) {
252 $selectedValues = explode("|", $currvalue);
254 $optionValue = attr($lrow_backup['option_id']);
256 if (in_array($lrow_backup ['option_id'], $selectedValues)) {
257 $s .= "<option value='$optionValue'";
258 $s .= " selected";
259 $optionLabel = text(xl_list_label($lrow_backup ['title']));
260 $s .= ">$optionLabel</option>\n";
261 $got_selected_backup = true;
266 if (!$got_selected_backup) {
267 $selectedValues = explode("|", $currvalue);
268 foreach ($selectedValues as $selectedValue) {
269 $s .= "<option value='" . attr($selectedValue) . "'";
270 $s .= " selected";
271 $s .= ">* " . text($selectedValue) . " *</option>\n";
274 $s .= "</select>";
275 $fontTitle = xlt('Please choose a valid selection from the list.');
276 $fontText = xlt('Fix this');
277 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
279 } else {
280 $s .= "</select>";
283 return $s;
286 // Parsing for data type 31, static text.
287 function parse_static_text($frow)
289 $tmp = $frow['description'];
290 // Translate if it does not look like HTML.
291 if (substr($tmp, 0, 1) != '<') {
292 $tmp = nl2br(xl_layout_label($tmp));
294 $s = '';
295 if ($frow['source'] == 'D' || $frow['source'] == 'H') {
296 // Source is demographics or history. This case supports value substitution.
297 while (preg_match('/^(.*?)\{(\w+)\}(.*)$/', $tmp, $matches)) {
298 $s .= $matches[1];
299 $tmprow = $frow;
300 $tmprow['field_id'] = $matches[2];
301 $s .= lbf_current_value($tmprow, 0, 0);
302 $tmp = $matches[3];
305 $s .= $tmp;
306 return $s;
309 // $frow is a row from the layout_options table.
310 // $currvalue is the current value, if any, of the associated item.
312 function generate_form_field($frow, $currvalue)
314 global $rootdir, $date_init, $ISSUE_TYPES, $code_types;
316 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
318 $data_type = $frow['data_type'];
319 $field_id = $frow['field_id'];
320 $list_id = $frow['list_id'];
321 $backup_list = $frow['list_backup_id'];
323 // escaped variables to use in html
324 $field_id_esc= htmlspecialchars($field_id, ENT_QUOTES);
325 $list_id_esc = htmlspecialchars($list_id, ENT_QUOTES);
327 // Added 5-09 by BM - Translate description if applicable
328 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
330 // Support edit option T which assigns the (possibly very long) description as
331 // the default value.
332 if (isOption($frow['edit_options'], 'T') !== false) {
333 if (strlen($currescaped) == 0) {
334 $currescaped = $description;
337 // Description used in this way is not suitable as a title.
338 $description = '';
341 // added 5-2009 by BM to allow modification of the 'empty' text title field.
342 // Can pass $frow['empty_title'] with this variable, otherwise
343 // will default to 'Unassigned'.
344 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
345 // if make $frow['empty_title'] equal to 'SKIP'
346 $showEmpty = true;
347 if (isset($frow['empty_title'])) {
348 if ($frow['empty_title'] == "SKIP") {
349 //do not display an 'empty' choice
350 $showEmpty = false;
351 $empty_title = "Unassigned";
352 } else {
353 $empty_title = $frow['empty_title'];
355 } else {
356 $empty_title = "Unassigned";
359 $disabled = isOption($frow['edit_options'], '0') === false ? '' : 'disabled';
361 $lbfchange = (
362 strpos($frow['form_id'], 'LBF') === 0 ||
363 strpos($frow['form_id'], 'LBT') === 0 ||
364 $frow['form_id'] == 'DEM' ||
365 $frow['form_id'] == 'HIS'
366 ) ? "checkSkipConditions();" : "";
367 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
369 // generic single-selection list or Race and Ethnicity.
370 // These data types support backup lists.
371 if ($data_type == 1 || $data_type == 33) {
372 echo generate_select_list(
373 "form_$field_id",
374 $list_id,
375 $currvalue,
376 $description,
377 ($showEmpty ? $empty_title : ''),
379 $lbfchange,
381 ($disabled ? array('disabled' => 'disabled') : null),
382 false,
383 $backup_list
385 } // simple text field
386 elseif ($data_type == 2) {
387 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
388 $maxlength = $frow['max_length'];
389 $string_maxlength = "";
390 // if max_length is set to zero, then do not set a maxlength
391 if ($maxlength) {
392 $string_maxlength = "maxlength='".attr($maxlength)."'";
395 echo "<input type='text'" .
396 " class='form-control'" .
397 " name='form_$field_id_esc'" .
398 " id='form_$field_id_esc'" .
399 " size='$fldlength'" .
400 " $string_maxlength" .
401 " title='$description'" .
402 " value='$currescaped'";
403 $tmp = $lbfchange;
404 if (isOption($frow['edit_options'], 'C') !== false) {
405 $tmp .= "capitalizeMe(this);";
406 } elseif (isOption($frow['edit_options'], 'U') !== false) {
407 $tmp .= "this.value = this.value.toUpperCase();";
410 if ($tmp) {
411 echo " onchange='$tmp'";
414 $tmp = htmlspecialchars($GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
415 // If mask is for use at save time, treat as no mask.
416 if (strpos($tmp, '^') !== false) {
417 $tmp = '';
419 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
420 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
421 echo " onblur='maskblur(this,\"$tmp\")'";
424 if (isOption($frow['edit_options'], '1') !== false && strlen($currescaped) > 0) {
425 echo " readonly";
428 if ($disabled) {
429 echo ' disabled';
432 echo " />";
433 } // long or multi-line text field
434 elseif ($data_type == 3) {
435 $textCols = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
436 $textRows = htmlspecialchars($frow['fld_rows'], ENT_QUOTES);
437 echo "<textarea" .
438 " name='form_$field_id_esc'" .
439 " class='form-control'" .
440 " id='form_$field_id_esc'" .
441 " title='$description'" .
442 " cols='$textCols'" .
443 " rows='$textRows' $lbfonchange $disabled" .
444 ">" . $currescaped . "</textarea>";
445 } // date
446 elseif ($data_type == 4) {
447 $age_asof_date = ''; // optionalAge() sets this
448 $age_format = isOption($frow['edit_options'], 'A') === false ? 3 : 0;
449 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
450 if ($agestr) {
451 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
454 $onchange_string = '';
455 if (!$disabled && $agestr) {
456 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') " .
457 "updateAgeString('$field_id','$age_asof_date', $age_format, '$description')\"";
459 if ($data_type == 4) {
460 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
461 if (!$modtmp) {
462 $dateValue = oeFormatShortDate(substr($currescaped, 0, 10));
463 echo "<input type='text' size='10' class='datepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
464 " value='" . attr($dateValue) ."'";
465 } else {
466 $dateValue = oeFormatDateTime(substr($currescaped, 0, 20), 0);
467 echo "<input type='text' size='20' class='datetimepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
468 " value='" . attr($dateValue) . "'";
471 if (!$agestr) {
472 echo " title='$description'";
475 echo " $onchange_string $lbfonchange $disabled />";
477 // Optional display of age or gestational age.
478 if ($agestr) {
479 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
481 } // provider list, local providers only
482 elseif ($data_type == 10) {
483 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
484 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
485 "AND authorized = 1 " .
486 "ORDER BY lname, fname");
487 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
488 echo "<option value=''>" . xlt($empty_title) . "</option>";
489 $got_selected = false;
490 while ($urow = sqlFetchArray($ures)) {
491 $uname = text($urow['fname'] . ' ' . $urow['lname']);
492 $optionId = attr($urow['id']);
493 echo "<option value='$optionId'";
494 if ($urow['id'] == $currvalue) {
495 echo " selected";
496 $got_selected = true;
499 echo ">$uname</option>";
502 if (!$got_selected && $currvalue) {
503 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
504 echo "</select>";
505 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
506 } else {
507 echo "</select>";
509 } // provider list, including address book entries with an NPI number
510 elseif ($data_type == 11) {
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 } // pharmacy list
539 elseif ($data_type == 12) {
540 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
541 echo " $lbfonchange $disabled>";
542 echo "<option value='0'></option>";
543 $pres = get_pharmacies();
544 $got_selected = false;
545 while ($prow = sqlFetchArray($pres)) {
546 $key = $prow['id'];
547 $optionValue = htmlspecialchars($key, ENT_QUOTES);
548 $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
549 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
550 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
551 echo "<option value='$optionValue'";
552 if ($currvalue == $key) {
553 echo " selected";
554 $got_selected = true;
557 echo ">$optionLabel</option>";
560 if (!$got_selected && $currvalue) {
561 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
562 echo "</select>";
563 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
564 } else {
565 echo "</select>";
567 } // squads
568 elseif ($data_type == 13) {
569 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
570 echo " $lbfonchange $disabled>";
571 echo "<option value=''>&nbsp;</option>";
572 $squads = acl_get_squads();
573 if ($squads) {
574 foreach ($squads as $key => $value) {
575 $optionValue = htmlspecialchars($key, ENT_QUOTES);
576 $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES);
577 echo "<option value='$optionValue'";
578 if ($currvalue == $key) {
579 echo " selected";
582 echo ">$optionLabel</option>\n";
586 echo "</select>";
587 } // Address book, preferring organization name if it exists and is not in
588 // parentheses, and excluding local users who are not providers.
589 // Supports "referred to" practitioners and facilities.
590 // Alternatively the letter L in edit_options means that abook_type
591 // must be "ord_lab", indicating types used with the procedure
592 // lab ordering system.
593 // Alternatively the letter O in edit_options means that abook_type
594 // must begin with "ord_", indicating types used with the procedure
595 // ordering system.
596 // Alternatively the letter V in edit_options means that abook_type
597 // must be "vendor", indicating the Vendor type.
598 // Alternatively the letter R in edit_options means that abook_type
599 // must be "dist", indicating the Distributor type.
600 elseif ($data_type == 14) {
601 if (isOption($frow['edit_options'], 'L') !== false) {
602 $tmp = "abook_type = 'ord_lab'";
603 } elseif (isOption($frow['edit_options'], 'O') !== false) {
604 $tmp = "abook_type LIKE 'ord\\_%'";
605 } elseif (isOption($frow['edit_options'], 'V') !== false) {
606 $tmp = "abook_type LIKE 'vendor%'";
607 } elseif (isOption($frow['edit_options'], 'R') !== false) {
608 $tmp = "abook_type LIKE 'dist'";
609 } else {
610 $tmp = "( username = '' OR authorized = 1 )";
613 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
614 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
615 "AND $tmp " .
616 "ORDER BY organization, lname, fname");
617 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
618 echo " $lbfonchange $disabled>";
619 echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES) . "</option>";
620 while ($urow = sqlFetchArray($ures)) {
621 $uname = $urow['organization'];
622 if (empty($uname) || substr($uname, 0, 1) == '(') {
623 $uname = $urow['lname'];
624 if ($urow['fname']) {
625 $uname .= ", " . $urow['fname'];
629 $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES);
630 $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES);
631 echo "<option value='$optionValue'";
632 // Failure to translate Local and External is not an error here;
633 // they are only used as internal flags and must not be translated!
634 $title = $urow['username'] ? 'Local' : 'External';
635 $optionTitle = htmlspecialchars($title, ENT_QUOTES);
636 echo " title='$optionTitle'";
637 if ($urow['id'] == $currvalue) {
638 echo " selected";
641 echo ">$optionLabel</option>";
644 echo "</select>";
645 } // A billing code. If description matches an existing code type then that type is used.
646 elseif ($data_type == 15) {
647 $codetype = '';
648 if (!empty($frow['description']) && isset($code_types[$frow['description']])) {
649 $codetype = $frow['description'];
651 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
652 $maxlength = $frow['max_length'];
653 $string_maxlength = "";
654 // if max_length is set to zero, then do not set a maxlength
655 if ($maxlength) {
656 $string_maxlength = "maxlength='".attr($maxlength)."'";
660 if (isOption($frow['edit_options'], '2') !== false && substr($frow['form_id'], 0, 3) == 'LBF') {
661 // Option "2" generates a hidden input for the codes, and a matching visible field
662 // displaying their descriptions. First step is computing the description string.
663 $currdescstring = '';
664 if (!empty($currvalue)) {
665 $relcodes = explode(';', $currvalue);
666 foreach ($relcodes as $codestring) {
667 if ($codestring === '') {
668 continue;
671 $code_text = lookup_code_descriptions($codestring);
672 if ($currdescstring !== '') {
673 $currdescstring .= '; ';
676 if (!empty($code_text)) {
677 $currdescstring .= $code_text;
678 } else {
679 $currdescstring .= $codestring;
684 $currdescstring = attr($currdescstring);
686 echo "<input type='text'" .
687 " name='form_$field_id_esc'" .
688 " id='form_related_code'" .
689 " size='$fldlength'" .
690 " value='$currescaped'" .
691 " style='display:none'" .
692 " $lbfonchange readonly $disabled />";
693 // Extra readonly input field for optional display of code description(s).
694 echo "<input type='text'" .
695 " name='form_$field_id_esc" . "__desc'" .
696 " size='$fldlength'" .
697 " title='$description'" .
698 " value='$currdescstring'";
699 if (!$disabled) {
700 echo " onclick='sel_related(this,\"$codetype\")'";
703 echo "class='form-control'";
704 echo " readonly $disabled />";
705 } else {
706 echo "<input type='text'" .
707 " name='form_$field_id_esc'" .
708 " id='form_related_code'" .
709 " size='$fldlength'" .
710 " $string_maxlength" .
711 " title='$description'" .
712 " value='$currescaped'";
713 if (!$disabled) {
714 echo " onclick='sel_related(this,\"$codetype\")'";
717 echo "class='form-control'";
718 echo " $lbfonchange readonly $disabled />";
720 } // insurance company list
721 elseif ($data_type == 16) {
722 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
723 echo "<option value='0'></option>";
724 $insprovs = getInsuranceProviders();
725 $got_selected = false;
726 foreach ($insprovs as $key => $ipname) {
727 $optionValue = htmlspecialchars($key, ENT_QUOTES);
728 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
729 echo "<option value='$optionValue'";
730 if ($currvalue == $key) {
731 echo " selected";
732 $got_selected = true;
735 echo ">$optionLabel</option>";
738 if (!$got_selected && $currvalue) {
739 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
740 echo "</select>";
741 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
742 } else {
743 echo "</select>";
745 } // issue types
746 elseif ($data_type == 17) {
747 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
748 echo "<option value='0'></option>";
749 $got_selected = false;
750 foreach ($ISSUE_TYPES as $key => $value) {
751 $optionValue = htmlspecialchars($key, ENT_QUOTES);
752 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
753 echo "<option value='$optionValue'";
754 if ($currvalue == $key) {
755 echo " selected";
756 $got_selected = true;
759 echo ">$optionLabel</option>";
762 if (!$got_selected && strlen($currvalue) > 0) {
763 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
764 echo "</select>";
765 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
766 } else {
767 echo "</select>";
769 } // Visit categories.
770 elseif ($data_type == 18) {
771 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
772 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
773 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'" .
774 " $lbfonchange $disabled>";
775 echo "<option value=''>" . xlt($empty_title) . "</option>";
776 $got_selected = false;
777 while ($crow = sqlFetchArray($cres)) {
778 $catid = $crow['pc_catid'];
779 if (($catid < 9 && $catid != 5) || $catid == 11) {
780 continue;
783 echo "<option value='" . attr($catid) . "'";
784 if ($catid == $currvalue) {
785 echo " selected";
786 $got_selected = true;
789 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
792 if (!$got_selected && $currvalue) {
793 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
794 echo "</select>";
795 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
796 } else {
797 echo "</select>";
799 } // a set of labeled checkboxes
800 elseif ($data_type == 21) {
801 // If no list then it's a single checkbox and its value is "Yes" or empty.
802 if (!$list_id) {
803 echo "<input type='checkbox' name='form_{$field_id_esc}' " .
804 "id='form_{$field_id_esc}' value='Yes' $lbfonchange";
805 if ($currvalue) {
806 echo " checked";
808 echo " $disabled />";
809 } else {
810 // In this special case, fld_length is the number of columns generated.
811 $cols = max(1, $frow['fld_length']);
812 $avalue = explode('|', $currvalue);
813 $lres = sqlStatement("SELECT * FROM list_options " .
814 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
815 echo "<table cellpadding='0' cellspacing='0' width='100%' title='".attr($description)."'>";
816 $tdpct = (int) (100 / $cols);
817 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
818 $option_id = $lrow['option_id'];
819 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
820 // if ($count) echo "<br />";
821 if ($count % $cols == 0) {
822 if ($count) {
823 echo "</tr>";
825 echo "<tr>";
827 echo "<td width='" . attr($tdpct) . "%' nowrap>";
828 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
829 "id='form_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
830 if (in_array($option_id, $avalue)) {
831 echo " checked";
833 // Added 5-09 by BM - Translate label if applicable
834 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
835 echo "</td>";
837 if ($count) {
838 echo "</tr>";
839 if ($count > $cols) {
840 // Add some space after multiple rows of checkboxes.
841 $cols = htmlspecialchars($cols, ENT_QUOTES);
842 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
845 echo "</table>";
847 } // a set of labeled text input fields
848 elseif ($data_type == 22) {
849 $tmp = explode('|', $currvalue);
850 $avalue = array();
851 foreach ($tmp as $value) {
852 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
853 $avalue[$matches[1]] = $matches[2];
857 $lres = sqlStatement("SELECT * FROM list_options " .
858 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
859 echo "<table cellpadding='0' cellspacing='0'>";
860 while ($lrow = sqlFetchArray($lres)) {
861 $option_id = $lrow['option_id'];
862 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
863 $maxlength = $frow['max_length'];
864 $string_maxlength = "";
865 // if max_length is set to zero, then do not set a maxlength
866 if ($maxlength) {
867 $string_maxlength = "maxlength='".attr($maxlength)."'";
870 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
872 // Added 5-09 by BM - Translate label if applicable
873 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
874 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
875 $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
876 echo "<td><input type='text'" .
877 " name='form_{$field_id_esc}[$option_id_esc]'" .
878 " id='form_{$field_id_esc}[$option_id_esc]'" .
879 " size='$fldlength'" .
880 " class='form-control'" .
881 " $string_maxlength" .
882 " value='$optionValue'";
883 echo " $lbfonchange $disabled /></td></tr>";
886 echo "</table>";
887 } // a set of exam results; 3 radio buttons and a text field:
888 elseif ($data_type == 23) {
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 } // the list of active allergies for the current patient
950 // this is read-only!
951 elseif ($data_type == 24) {
952 $query = "SELECT title, comments FROM lists WHERE " .
953 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
954 "ORDER BY begdate";
955 // echo "<!-- $query -->\n"; // debugging
956 $lres = sqlStatement($query, array($GLOBALS['pid']));
957 $count = 0;
958 while ($lrow = sqlFetchArray($lres)) {
959 if ($count++) {
960 echo "<br />";
963 echo htmlspecialchars($lrow['title'], ENT_NOQUOTES);
964 if ($lrow['comments']) {
965 echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
968 } // a set of labeled checkboxes, each with a text field:
969 elseif ($data_type == 25) {
970 $tmp = explode('|', $currvalue);
971 $avalue = array();
972 foreach ($tmp as $value) {
973 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
974 $avalue[$matches[1]] = $matches[2];
978 $maxlength = $frow['max_length'];
979 $string_maxlength = "";
980 // if max_length is set to zero, then do not set a maxlength
981 if ($maxlength) {
982 $string_maxlength = "maxlength='".attr($maxlength)."'";
985 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
986 $lres = sqlStatement("SELECT * FROM list_options " .
987 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
988 echo "<table cellpadding='0' cellspacing='0'>";
989 while ($lrow = sqlFetchArray($lres)) {
990 $option_id = $lrow['option_id'];
991 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
992 $restype = substr($avalue[$option_id], 0, 1);
993 $resnote = substr($avalue[$option_id], 2);
995 // Added 5-09 by BM - Translate label if applicable
996 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
998 $option_id = htmlspecialchars($option_id, ENT_QUOTES);
999 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
1000 " id='check_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
1001 if ($restype) {
1002 echo " checked";
1005 echo " $disabled />&nbsp;</td>";
1006 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1007 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1008 echo "<td><input type='text'" .
1009 " name='form_{$field_id_esc}[$option_id_esc]'" .
1010 " id='form_{$field_id_esc}[$option_id_esc]'" .
1011 " size='$fldlength'" .
1012 " class='form-control' " .
1013 " $string_maxlength" .
1014 " value='$resnote' $disabled /></td>";
1015 echo "</tr>";
1018 echo "</table>";
1019 } // single-selection list with ability to add to it
1020 elseif ($data_type == 26) {
1021 echo generate_select_list(
1022 "form_$field_id",
1023 $list_id,
1024 $currvalue,
1025 $description,
1026 ($showEmpty ? $empty_title : ''),
1027 'addtolistclass_'.$list_id,
1028 $lbfchange,
1030 ($disabled ? array('disabled' => 'disabled') : null),
1031 false,
1032 $backup_list
1034 // show the add button if user has access to correct list
1035 $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES);
1036 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
1037 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
1038 if (aco_exist('lists', $list_id)) {
1039 // a specific aco exist for this list, so ensure access
1040 if (acl_check('lists', $list_id)) {
1041 echo $outputAddButton;
1043 } else {
1044 // no specific aco exist for this list, so check for access to 'default' list
1045 if (acl_check('lists', 'default')) {
1046 echo $outputAddButton;
1049 } // a set of labeled radio buttons
1050 elseif ($data_type == 27) {
1051 // In this special case, fld_length is the number of columns generated.
1052 $cols = max(1, $frow['fld_length']);
1053 $lres = sqlStatement("SELECT * FROM list_options " .
1054 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1055 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1056 $tdpct = (int) (100 / $cols);
1057 $got_selected = false;
1058 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1059 $option_id = $lrow['option_id'];
1060 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
1061 if ($count % $cols == 0) {
1062 if ($count) {
1063 echo "</tr>";
1066 echo "<tr>";
1069 echo "<td width='" . attr($tdpct) . "%'>";
1070 echo "<input type='radio' name='form_{$field_id_esc}' class='form-control' id='form_{$field_id_esc}[$option_id_esc]'" .
1071 " value='$option_id_esc' $lbfonchange";
1072 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1073 (strlen($currvalue) > 0 && $option_id == $currvalue)) {
1074 echo " checked";
1075 $got_selected = true;
1078 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1079 echo "</td>";
1082 if ($count) {
1083 echo "</tr>";
1084 if ($count > $cols) {
1085 // Add some space after multiple rows of radio buttons.
1086 $cols = htmlspecialchars($cols, ENT_QUOTES);
1087 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1091 echo "</table>";
1092 if (!$got_selected && strlen($currvalue) > 0) {
1093 $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES);
1094 $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES);
1095 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
1097 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1098 // VicarePlus :: A selection list box for smoking status:
1099 elseif ($data_type == 28 || $data_type == 32) {
1100 $tmp = explode('|', $currvalue);
1101 switch (count($tmp)) {
1102 case "4":
1103 $resnote = $tmp[0];
1104 $restype = $tmp[1];
1105 $resdate = oeFormatShortDate($tmp[2]);
1106 $reslist = $tmp[3];
1107 break;
1108 case "3":
1109 $resnote = $tmp[0];
1110 $restype = $tmp[1];
1111 $resdate = oeFormatShortDate($tmp[2]);
1112 break;
1113 case "2":
1114 $resnote = $tmp[0];
1115 $restype = $tmp[1];
1116 $resdate = "";
1117 break;
1118 case "1":
1119 $resnote = $tmp[0];
1120 $resdate = $restype = "";
1121 break;
1122 default:
1123 $restype = $resdate = $resnote = "";
1124 break;
1127 $maxlength = $frow['max_length'];
1128 $string_maxlength = "";
1129 // if max_length is set to zero, then do not set a maxlength
1130 if ($maxlength) {
1131 $string_maxlength = "maxlength='".attr($maxlength)."'";
1134 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1136 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1137 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1138 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1139 echo "<table cellpadding='0' cellspacing='0'>";
1140 echo "<tr>";
1141 if ($data_type == 28) {
1142 // input text
1143 echo "<td><input type='text'" .
1144 " name='form_$field_id_esc'" .
1145 " id='form_$field_id_esc'" .
1146 " size='$fldlength'" .
1147 " $string_maxlength" .
1148 " value='$resnote' $disabled />&nbsp;</td>";
1149 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1150 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1151 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1152 } elseif ($data_type == 32) {
1153 // input text
1154 echo "<tr><td><input type='text'" .
1155 " name='form_text_$field_id_esc'" .
1156 " id='form_text_$field_id_esc'" .
1157 " size='$fldlength'" .
1158 " class='form-control'" .
1159 " $string_maxlength" .
1160 " value='$resnote' $disabled />&nbsp;</td></tr>";
1161 echo "<td>";
1162 //Selection list for smoking status
1163 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1164 echo generate_select_list(
1165 "form_$field_id",
1166 $list_id,
1167 $reslist,
1168 $description,
1169 ($showEmpty ? $empty_title : ''),
1171 $onchange,
1173 ($disabled ? array('disabled' => 'disabled') : null)
1175 echo "</td>";
1176 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1179 // current
1180 echo "<td class='text' ><input type='radio'" .
1181 " name='radio_{$field_id_esc}'" .
1182 " id='radio_{$field_id_esc}[current]'" .
1183 " class='form-control'" .
1184 " value='current" . $field_id_esc . "' $lbfonchange";
1185 if ($restype == "current" . $field_id) {
1186 echo " checked";
1189 if ($data_type == 32) {
1190 echo " onClick='smoking_statusClicked(this)'";
1193 echo " />" . xlt('Current') . "&nbsp;</td>";
1194 // quit
1195 echo "<td class='text'><input type='radio'" .
1196 " name='radio_{$field_id_esc}'" .
1197 " id='radio_{$field_id_esc}[quit]'" .
1198 " class='form-control'" .
1199 " value='quit".$field_id_esc."' $lbfonchange";
1200 if ($restype == "quit" . $field_id) {
1201 echo " checked";
1204 if ($data_type == 32) {
1205 echo " onClick='smoking_statusClicked(this)'";
1208 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1209 // quit date
1210 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1211 " value='$resdate'" .
1212 " title='$description'" .
1213 " $disabled />";
1214 echo "&nbsp;</td>";
1215 // never
1216 echo "<td class='text'><input type='radio'" .
1217 " name='radio_{$field_id_esc}'" .
1218 " class='form-control'" .
1219 " id='radio_{$field_id_esc}[never]'" .
1220 " value='never" . $field_id_esc . "' $lbfonchange";
1221 if ($restype == "never" . $field_id) {
1222 echo " checked";
1225 if ($data_type == 32) {
1226 echo " onClick='smoking_statusClicked(this)'";
1229 echo " />" . xlt('Never') . "&nbsp;</td>";
1230 // Not Applicable
1231 echo "<td class='text'><input type='radio'" .
1232 " class='form-control' " .
1233 " name='radio_{$field_id}'" .
1234 " id='radio_{$field_id}[not_applicable]'" .
1235 " value='not_applicable" . $field_id . "' $lbfonchange";
1236 if ($restype == "not_applicable" . $field_id) {
1237 echo " checked";
1240 if ($data_type == 32) {
1241 echo " onClick='smoking_statusClicked(this)'";
1244 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1246 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1247 echo "<td class='text' ><div id='smoke_code'></div></td>";
1248 echo "</tr>";
1249 echo "</table>";
1250 } // static text. read-only, of course.
1251 elseif ($data_type == 31) {
1252 echo parse_static_text($frow);
1253 } //$data_type == 33
1254 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1255 //$data_type == 33
1257 elseif ($data_type == 34) {
1258 $arr = explode("|*|*|*|", $currvalue);
1259 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;'>";
1260 echo "<div id='form_{$field_id}_div' class='text-area' style='min-width:100pt'>" . $arr[0] . "</div>";
1261 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>";
1262 echo "</a>";
1263 } //facilities drop-down list
1264 elseif ($data_type == 35) {
1265 if (empty($currvalue)) {
1266 $currvalue = 0;
1269 dropdown_facility(
1270 $selected = $currvalue,
1271 $name = "form_$field_id_esc",
1272 $allow_unspecified = true,
1273 $allow_allfacilities = false,
1274 $disabled,
1275 $lbfchange
1277 } //multiple select
1278 // supports backup list
1279 elseif ($data_type == 36) {
1280 echo generate_select_list(
1281 "form_$field_id",
1282 $list_id,
1283 $currvalue,
1284 $description,
1285 $showEmpty ? $empty_title : '',
1287 $lbfchange,
1289 null,
1290 true,
1291 $backup_list
1293 } // Canvas and related elements for browser-side image drawing.
1294 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1295 elseif ($data_type == 40) {
1296 // Unlike other field types, width and height are in pixels.
1297 $canWidth = intval($frow['fld_length']);
1298 $canHeight = intval($frow['fld_rows']);
1299 if (empty($currvalue)) {
1300 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1301 // If defined this is the filename of the default starting image.
1302 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1306 $mywidth = 50 + ($canWidth > 250 ? $canWidth : 250);
1307 $myheight = 31 + ($canHeight > 261 ? $canHeight : 261);
1308 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1309 // Hidden form field exists to send updated data to the server at submit time.
1310 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1311 // Hidden image exists to support initialization of the canvas.
1312 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1313 // $date_init is a misnomer but it's the place for browser-side setup logic.
1314 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1318 function generate_print_field($frow, $currvalue)
1320 global $rootdir, $date_init, $ISSUE_TYPES;
1322 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1324 $data_type = $frow['data_type'];
1325 $field_id = $frow['field_id'];
1326 $list_id = $frow['list_id'];
1327 $fld_length = $frow['fld_length'];
1328 $backup_list = $frow['list_backup_id'];
1330 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1332 // Can pass $frow['empty_title'] with this variable, otherwise
1333 // will default to 'Unassigned'.
1334 // If it is 'SKIP' then an empty text title is completely skipped.
1335 $showEmpty = true;
1336 if (isset($frow['empty_title'])) {
1337 if ($frow['empty_title'] == "SKIP") {
1338 //do not display an 'empty' choice
1339 $showEmpty = false;
1340 $empty_title = "Unassigned";
1341 } else {
1342 $empty_title = $frow['empty_title'];
1344 } else {
1345 $empty_title = "Unassigned";
1348 // generic single-selection list
1349 // Supports backup lists.
1350 if (false && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1351 if (empty($fld_length)) {
1352 if ($list_id == 'titles') {
1353 $fld_length = 3;
1354 } else {
1355 $fld_length = 10;
1359 $tmp = '';
1360 if ($currvalue) {
1361 $lrow = sqlQuery("SELECT title FROM list_options " .
1362 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1363 $tmp = xl_list_label($lrow['title']);
1364 if ($lrow == 0 && !empty($backup_list)) {
1365 // since primary list did not map, try to map to backup list
1366 $lrow = sqlQuery("SELECT title FROM list_options " .
1367 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1368 $tmp = xl_list_label($lrow['title']);
1371 if (empty($tmp)) {
1372 $tmp = "($currvalue)";
1376 /*****************************************************************
1377 echo "<input type='text'" .
1378 " size='$fld_length'" .
1379 " value='$tmp'" .
1380 " class='under'" .
1381 " />";
1382 *****************************************************************/
1383 if ($tmp === '') {
1384 $tmp = '&nbsp;';
1385 } else {
1386 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1389 echo $tmp;
1390 } // simple text field
1391 elseif ($data_type == 2 || $data_type == 15) {
1392 /*****************************************************************
1393 echo "<input type='text'" .
1394 " size='$fld_length'" .
1395 " value='$currescaped'" .
1396 " class='under'" .
1397 " />";
1398 *****************************************************************/
1399 if ($currescaped === '') {
1400 $currescaped = '&nbsp;';
1403 echo $currescaped;
1404 } // long or multi-line text field
1405 elseif ($data_type == 3) {
1406 $fldlength = htmlspecialchars($fld_length, ENT_QUOTES);
1407 $maxlength = htmlspecialchars($frow['fld_rows'], ENT_QUOTES);
1408 echo "<textarea" .
1409 " class='form-control' " .
1410 " cols='$fldlength'" .
1411 " rows='$maxlength'>" .
1412 $currescaped . "</textarea>";
1413 } // date
1414 elseif ($data_type == 4) {
1415 $age_asof_date = '';
1416 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
1417 if ($currvalue === '') {
1418 echo '&nbsp;';
1419 } else {
1420 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
1421 if (!$modtmp) {
1422 echo text(oeFormatShortDate($currvalue));
1423 } else {
1424 echo text(oeFormatDateTime($currvalue));
1426 if ($agestr) {
1427 echo "&nbsp;(" . text($agestr) . ")";
1430 } // provider list
1431 elseif ($data_type == 10 || $data_type == 11) {
1432 $tmp = '';
1433 if ($currvalue) {
1434 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1435 "WHERE id = ?", array($currvalue));
1436 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1437 if (empty($tmp)) {
1438 $tmp = "($currvalue)";
1442 /*****************************************************************
1443 echo "<input type='text'" .
1444 " size='$fld_length'" .
1445 " value='$tmp'" .
1446 " class='under'" .
1447 " />";
1448 *****************************************************************/
1449 if ($tmp === '') {
1450 $tmp = '&nbsp;';
1451 } else {
1452 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1455 echo $tmp;
1456 } // pharmacy list
1457 elseif ($data_type == 12) {
1458 $tmp = '';
1459 if ($currvalue) {
1460 $pres = get_pharmacies();
1461 while ($prow = sqlFetchArray($pres)) {
1462 $key = $prow['id'];
1463 if ($currvalue == $key) {
1464 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1465 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1466 $prow['line1'] . ' / ' . $prow['city'];
1470 if (empty($tmp)) {
1471 $tmp = "($currvalue)";
1475 /*****************************************************************
1476 echo "<input type='text'" .
1477 " size='$fld_length'" .
1478 " value='$tmp'" .
1479 " class='under'" .
1480 " />";
1481 *****************************************************************/
1482 if ($tmp === '') {
1483 $tmp = '&nbsp;';
1484 } else {
1485 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1488 echo $tmp;
1489 } // squads
1490 elseif ($data_type == 13) {
1491 $tmp = '';
1492 if ($currvalue) {
1493 $squads = acl_get_squads();
1494 if ($squads) {
1495 foreach ($squads as $key => $value) {
1496 if ($currvalue == $key) {
1497 $tmp = $value[3];
1502 if (empty($tmp)) {
1503 $tmp = "($currvalue)";
1507 /*****************************************************************
1508 echo "<input type='text'" .
1509 " size='$fld_length'" .
1510 " value='$tmp'" .
1511 " class='under'" .
1512 " />";
1513 *****************************************************************/
1514 if ($tmp === '') {
1515 $tmp = '&nbsp;';
1516 } else {
1517 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1520 echo $tmp;
1521 } // Address book.
1522 elseif ($data_type == 14) {
1523 $tmp = '';
1524 if ($currvalue) {
1525 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1526 "WHERE id = ?", array($currvalue));
1527 $uname = $urow['lname'];
1528 if ($urow['fname']) {
1529 $uname .= ", " . $urow['fname'];
1532 $tmp = $uname;
1533 if (empty($tmp)) {
1534 $tmp = "($currvalue)";
1538 /*****************************************************************
1539 echo "<input type='text'" .
1540 " size='$fld_length'" .
1541 " value='$tmp'" .
1542 " class='under'" .
1543 " />";
1544 *****************************************************************/
1545 if ($tmp === '') {
1546 $tmp = '&nbsp;';
1547 } else {
1548 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1551 echo $tmp;
1552 } // insurance company list
1553 elseif ($data_type == 16) {
1554 $tmp = '';
1555 if ($currvalue) {
1556 $insprovs = getInsuranceProviders();
1557 foreach ($insprovs as $key => $ipname) {
1558 if ($currvalue == $key) {
1559 $tmp = $ipname;
1563 if (empty($tmp)) {
1564 $tmp = "($currvalue)";
1568 if ($tmp === '') {
1569 $tmp = '&nbsp;';
1570 } else {
1571 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1574 echo $tmp;
1575 } // issue types
1576 elseif ($data_type == 17) {
1577 $tmp = '';
1578 if ($currvalue) {
1579 foreach ($ISSUE_TYPES as $key => $value) {
1580 if ($currvalue == $key) {
1581 $tmp = $value[1];
1585 if (empty($tmp)) {
1586 $tmp = "($currvalue)";
1590 if ($tmp === '') {
1591 $tmp = '&nbsp;';
1592 } else {
1593 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1596 echo $tmp;
1597 } // Visit categories.
1598 elseif ($data_type == 18) {
1599 $tmp = '';
1600 if ($currvalue) {
1601 $crow = sqlQuery(
1602 "SELECT pc_catid, pc_catname " .
1603 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1604 array($currvalue)
1606 $tmp = xl_appt_category($crow['pc_catname']);
1607 if (empty($tmp)) {
1608 $tmp = "($currvalue)";
1612 if ($tmp === '') {
1613 $tmp = '&nbsp;';
1614 } else {
1615 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1618 echo $tmp;
1619 } // a single checkbox or set of labeled checkboxes
1620 elseif ($data_type == 21) {
1621 if (!$list_id) {
1622 echo "<input type='checkbox'";
1623 if ($currvalue) {
1624 echo " checked";
1626 echo " />";
1627 } else {
1628 // In this special case, fld_length is the number of columns generated.
1629 $cols = max(1, $fld_length);
1630 $avalue = explode('|', $currvalue);
1631 $lres = sqlStatement("SELECT * FROM list_options " .
1632 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1633 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1634 $tdpct = (int) (100 / $cols);
1635 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1636 $option_id = $lrow['option_id'];
1637 if ($count % $cols == 0) {
1638 if ($count) {
1639 echo "</tr>";
1642 echo "<tr>";
1644 echo "<td width='" . attr($tdpct) . "%'>";
1645 echo "<input type='checkbox'";
1646 if (in_array($option_id, $avalue)) {
1647 echo " checked";
1649 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1650 echo "</td>";
1652 if ($count) {
1653 echo "</tr>";
1654 if ($count > $cols) {
1655 // Add some space after multiple rows of checkboxes.
1656 $cols = htmlspecialchars($cols, ENT_QUOTES);
1657 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1660 echo "</table>";
1662 } // a set of labeled text input fields
1663 elseif ($data_type == 22) {
1664 $tmp = explode('|', $currvalue);
1665 $avalue = array();
1666 foreach ($tmp as $value) {
1667 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1668 $avalue[$matches[1]] = $matches[2];
1672 $lres = sqlStatement("SELECT * FROM list_options " .
1673 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1674 echo "<table cellpadding='0' cellspacing='0'>";
1675 while ($lrow = sqlFetchArray($lres)) {
1676 $option_id = $lrow['option_id'];
1677 $fldlength = empty($fld_length) ? 20 : $fld_length;
1678 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1679 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1680 $inputValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
1681 echo "<td><input type='text'" .
1682 " class='form-control' " .
1683 " size='$fldlength'" .
1684 " value='$inputValue'" .
1685 " class='under'" .
1686 " /></td></tr>";
1689 echo "</table>";
1690 } // a set of exam results; 3 radio buttons and a text field:
1691 elseif ($data_type == 23) {
1692 $tmp = explode('|', $currvalue);
1693 $avalue = array();
1694 foreach ($tmp as $value) {
1695 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1696 $avalue[$matches[1]] = $matches[2];
1700 $fldlength = empty($fld_length) ? 20 : $fld_length;
1701 $lres = sqlStatement("SELECT * FROM list_options " .
1702 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1703 echo "<table cellpadding='0' cellspacing='0'>";
1704 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1705 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
1706 "&nbsp;</td><td class='bold'>" .
1707 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1708 "<td class='bold'>" .
1709 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1710 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1711 while ($lrow = sqlFetchArray($lres)) {
1712 $option_id = $lrow['option_id'];
1713 $restype = substr($avalue[$option_id], 0, 1);
1714 $resnote = substr($avalue[$option_id], 2);
1715 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1716 for ($i = 0; $i < 3; ++$i) {
1717 echo "<td><input type='radio'";
1718 if ($restype === "$i") {
1719 echo " checked";
1722 echo " /></td>";
1725 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1726 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1727 echo "<td><input type='text'" .
1728 " size='$fldlength'" .
1729 " value='$resnote'" .
1730 " class='under form-control' /></td>" .
1731 "</tr>";
1734 echo "</table>";
1735 } // the list of active allergies for the current patient
1736 // this is read-only!
1737 elseif ($data_type == 24) {
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 } // a set of labeled checkboxes, each with a text field:
1754 elseif ($data_type == 25) {
1755 $tmp = explode('|', $currvalue);
1756 $avalue = array();
1757 foreach ($tmp as $value) {
1758 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1759 $avalue[$matches[1]] = $matches[2];
1763 $fldlength = empty($fld_length) ? 20 : $fld_length;
1764 $lres = sqlStatement("SELECT * FROM list_options " .
1765 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1766 echo "<table cellpadding='0' cellspacing='0'>";
1767 while ($lrow = sqlFetchArray($lres)) {
1768 $option_id = $lrow['option_id'];
1769 $restype = substr($avalue[$option_id], 0, 1);
1770 $resnote = substr($avalue[$option_id], 2);
1771 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1772 echo "<td><input type='checkbox'";
1773 if ($restype) {
1774 echo " checked";
1777 echo " />&nbsp;</td>";
1778 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1779 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1780 echo "<td><input type='text'" .
1781 " size='$fldlength'" .
1782 " class='form-control' " .
1783 " value='$resnote'" .
1784 " class='under'" .
1785 " /></td>" .
1786 "</tr>";
1789 echo "</table>";
1790 } // a set of labeled radio buttons
1791 elseif ($data_type == 27 || $data_type == 1 || $data_type == 26 || $data_type == 33) {
1792 // In this special case, fld_length is the number of columns generated.
1793 $cols = max(1, $frow['fld_length']);
1794 $lres = sqlStatement("SELECT * FROM list_options " .
1795 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1796 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1797 $tdpct = (int) (100 / $cols);
1798 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1799 $option_id = $lrow['option_id'];
1800 if ($count % $cols == 0) {
1801 if ($count) {
1802 echo "</tr>";
1805 echo "<tr>";
1807 echo "<td width='" . attr($tdpct) . "%'>";
1808 echo "<input type='radio'";
1809 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1810 // Do not use defaults for these printable forms.
1811 echo " checked";
1814 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1815 echo "</td>";
1818 if ($count) {
1819 echo "</tr>";
1820 if ($count > $cols) {
1821 // Add some space after multiple rows of radio buttons.
1822 $cols = htmlspecialchars($cols, ENT_QUOTES);
1823 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1827 echo "</table>";
1828 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1829 elseif ($data_type == 28 || $data_type == 32) {
1830 $tmp = explode('|', $currvalue);
1831 switch (count($tmp)) {
1832 case "4":
1833 $resnote = $tmp[0];
1834 $restype = $tmp[1];
1835 $resdate = oeFormatShortDate($tmp[2]) ;
1836 $reslist = $tmp[3];
1837 break;
1838 case "3":
1839 $resnote = $tmp[0];
1840 $restype = $tmp[1];
1841 $resdate = oeFormatShortDate($tmp[2]);
1842 break;
1843 case "2":
1844 $resnote = $tmp[0];
1845 $restype = $tmp[1];
1846 $resdate = "";
1847 break;
1848 case "1":
1849 $resnote = $tmp[0];
1850 $resdate = $restype = "";
1851 break;
1852 default:
1853 $restype = $resdate = $resnote = "";
1854 break;
1857 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1858 echo "<table cellpadding='0' cellspacing='0'>";
1859 echo "<tr>";
1860 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1861 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1862 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1863 if ($data_type == 28) {
1864 echo "<td><input type='text'" .
1865 " size='$fldlength'" .
1866 " class='under'" .
1867 " value='$resnote' /></td>";
1868 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1869 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1870 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1871 } elseif ($data_type == 32) {
1872 echo "<tr><td><input type='text'" .
1873 " size='$fldlength'" .
1874 " class='under form-control'" .
1875 " value='$resnote' /></td></tr>";
1876 $fldlength = 30;
1877 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
1878 echo "<td><input type='text'" .
1879 " size='$fldlength'" .
1880 " class='under form-control'" .
1881 " value='$smoking_status_title' /></td>";
1882 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1885 echo "<td><input type='radio' class='form-control'";
1886 if ($restype == "current".$field_id) {
1887 echo " checked";
1890 echo "/>".htmlspecialchars(xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1892 echo "<td><input type='radio' class='form-control'";
1893 if ($restype == "current".$field_id) {
1894 echo " checked";
1897 echo "/>".htmlspecialchars(xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1899 echo "<td><input type='text' size='6'" .
1900 " value='$resdate'" .
1901 " class='under form-control'" .
1902 " /></td>";
1904 echo "<td><input type='radio' class='form-control'";
1905 if ($restype == "current".$field_id) {
1906 echo " checked";
1909 echo " />".htmlspecialchars(xl('Never'), ENT_NOQUOTES)."</td>";
1911 echo "<td><input type='radio' class='form-control'";
1912 if ($restype == "not_applicable".$field_id) {
1913 echo " checked";
1916 echo " />".htmlspecialchars(xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1917 echo "</tr>";
1918 echo "</table>";
1919 } // static text. read-only, of course.
1920 elseif ($data_type == 31) {
1921 echo parse_static_text($frow);
1922 } elseif ($data_type == 34) {
1923 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;'>";
1924 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1925 echo "<div style='display:none'><textarea name='form_{$field_id}' class='form-control' id='form_{$field_id}' stye='display:none'></textarea></div>";
1926 echo "</a>";
1927 } //facilities drop-down list
1928 elseif ($data_type == 35) {
1929 // In this special case, fld_length is the number of columns generated.
1930 $cols = max(1, $frow['fld_length']);
1931 $lres = sqlStatement("SELECT id, name FROM facility ORDER BY name");
1932 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1933 $tdpct = (int) (100 / $cols);
1934 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1935 $option_id = $lrow['id'];
1936 if ($count % $cols == 0) {
1937 if ($count) {
1938 echo "</tr>";
1940 echo "<tr>";
1942 echo "<td width='" . attr($tdpct) . "%'>";
1943 echo "<input type='radio'";
1944 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1945 // Do not use defaults for these printable forms.
1946 echo " checked";
1948 echo ">" . htmlspecialchars($lrow['name']);
1949 echo "</td>";
1951 if ($count) {
1952 echo "</tr>";
1953 if ($count > $cols) {
1954 // Add some space after multiple rows of radio buttons.
1955 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1958 echo "</table>";
1959 } //Multi-select
1960 // Supports backup lists.
1961 elseif ($data_type == 36) {
1962 if (empty($fld_length)) {
1963 if ($list_id == 'titles') {
1964 $fld_length = 3;
1965 } else {
1966 $fld_length = 10;
1970 $tmp = '';
1972 $values_array = explode("|", $currvalue);
1974 $i=0;
1975 foreach ($values_array as $value) {
1976 if ($value) {
1977 $lrow = sqlQuery("SELECT title FROM list_options " .
1978 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1979 $tmp = xl_list_label($lrow['title']);
1980 if ($lrow == 0 && !empty($backup_list)) {
1981 // since primary list did not map, try to map to backup list
1982 $lrow = sqlQuery("SELECT title FROM list_options " .
1983 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1984 $tmp = xl_list_label($lrow['title']);
1987 if (empty($tmp)) {
1988 $tmp = "($value)";
1992 if ($tmp === '') {
1993 $tmp = '&nbsp;';
1994 } else {
1995 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1998 if ($i != 0 && $tmp != '&nbsp;') {
1999 echo ",";
2002 echo $tmp;
2003 $i++;
2005 } // Image from canvas drawing
2006 elseif ($data_type == 40) {
2007 if ($currvalue) {
2008 echo "<img src='" . attr($currvalue) . "'>";
2013 function generate_display_field($frow, $currvalue)
2015 global $ISSUE_TYPES, $facilityService;
2017 $data_type = $frow['data_type'];
2018 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2019 $list_id = $frow['list_id'];
2020 $backup_list = isset($frow['list_backup_id']) ? $frow['list_backup_id'] : null;
2022 $s = '';
2024 // generic selection list or the generic selection list with add on the fly
2025 // feature
2026 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
2027 $lrow = sqlQuery("SELECT title FROM list_options " .
2028 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2029 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2030 //if there is no matching value in the corresponding lists check backup list
2031 // only supported in data types 1,26,33
2032 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2033 $lrow = sqlQuery("SELECT title FROM list_options " .
2034 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2035 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2037 // If match is not found in main and backup lists, return the key with exclamation mark
2038 if ($s == '') {
2039 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES)).
2040 '<sup> <i class="fa fas fa-exclamation-circle ml-1"></i></sup>';
2042 } // simple text field
2043 elseif ($data_type == 2) {
2044 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2045 } // long or multi-line text field
2046 elseif ($data_type == 3) {
2047 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2048 } // date
2049 elseif ($data_type == 4) {
2050 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
2051 $s = '';
2052 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2053 $age_asof_date = '';
2054 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
2055 if ($currvalue === '') {
2056 $s .= '&nbsp;';
2057 } else {
2058 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
2059 if (!$modtmp) {
2060 $s .= text(oeFormatShortDate($currvalue));
2061 } else {
2062 $s .= text(oeFormatDateTime($currvalue));
2064 if ($agestr) {
2065 $s .= "&nbsp;(" . text($agestr) . ")";
2068 } // provider
2069 elseif ($data_type == 10 || $data_type == 11) {
2070 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2071 "WHERE id = ?", array($currvalue));
2072 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']), ENT_NOQUOTES);
2073 } // pharmacy list
2074 elseif ($data_type == 12) {
2075 $pres = get_pharmacies();
2076 while ($prow = sqlFetchArray($pres)) {
2077 $key = $prow['id'];
2078 if ($currvalue == $key) {
2079 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
2080 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2081 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
2084 } // squads
2085 elseif ($data_type == 13) {
2086 $squads = acl_get_squads();
2087 if ($squads) {
2088 foreach ($squads as $key => $value) {
2089 if ($currvalue == $key) {
2090 $s .= htmlspecialchars($value[3], ENT_NOQUOTES);
2094 } // address book
2095 elseif ($data_type == 14) {
2096 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
2097 "WHERE id = ?", array($currvalue));
2098 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
2099 if ($urow['organization'] !="") {
2100 $uname = $urow['organization'];
2101 } else {
2102 $uname = $urow['lname'];
2103 if ($urow['fname']) {
2104 $uname .= ", " . $urow['fname'];
2108 $s = htmlspecialchars($uname, ENT_NOQUOTES);
2109 } // billing code
2110 elseif ($data_type == 15) {
2111 $s = '';
2112 if (!empty($currvalue)) {
2113 $relcodes = explode(';', $currvalue);
2114 foreach ($relcodes as $codestring) {
2115 if ($codestring === '') {
2116 continue;
2118 $tmp = lookup_code_descriptions($codestring);
2119 if ($s !== '') {
2120 $s .= '; ';
2122 if (!empty($tmp)) {
2123 $s .= $tmp;
2124 } else {
2125 $s .= $codestring . ' (' . xl('not found') . ')';
2129 } // insurance company list
2130 elseif ($data_type == 16) {
2131 $insprovs = getInsuranceProviders();
2132 foreach ($insprovs as $key => $ipname) {
2133 if ($currvalue == $key) {
2134 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
2137 } // issue types
2138 elseif ($data_type == 17) {
2139 foreach ($ISSUE_TYPES as $key => $value) {
2140 if ($currvalue == $key) {
2141 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
2144 } // visit category
2145 elseif ($data_type == 18) {
2146 $crow = sqlQuery(
2147 "SELECT pc_catid, pc_catname " .
2148 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2149 array($currvalue)
2151 $s = htmlspecialchars($crow['pc_catname'], ENT_NOQUOTES);
2152 } // a single checkbox or set of labeled checkboxes
2153 elseif ($data_type == 21) {
2154 if (!$list_id) {
2155 $s .= $currvalue ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2156 } else {
2157 // In this special case, fld_length is the number of columns generated.
2158 $cols = max(1, $frow['fld_length']);
2159 $avalue = explode('|', $currvalue);
2160 $lres = sqlStatement("SELECT * FROM list_options " .
2161 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2162 $s .= "<table cellspacing='0' cellpadding='0'>";
2163 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2164 $option_id = $lrow['option_id'];
2165 $option_id_esc = text($option_id);
2166 if ($count % $cols == 0) {
2167 if ($count) {
2168 $s .= "</tr>";
2170 $s .= "<tr>";
2172 $s .= "<td nowrap>";
2173 $checked = in_array($option_id, $avalue);
2174 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2175 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2176 $s .= "</td>";
2178 if ($count) {
2179 $s .= "</tr>";
2181 $s .= "</table>";
2183 } // a set of labeled text input fields
2184 elseif ($data_type == 22) {
2185 $tmp = explode('|', $currvalue);
2186 $avalue = array();
2187 foreach ($tmp as $value) {
2188 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2189 $avalue[$matches[1]] = $matches[2];
2193 $lres = sqlStatement("SELECT * FROM list_options " .
2194 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2195 $s .= "<table cellpadding='0' cellspacing='0'>";
2196 while ($lrow = sqlFetchArray($lres)) {
2197 $option_id = $lrow['option_id'];
2198 if (empty($avalue[$option_id])) {
2199 continue;
2202 // Added 5-09 by BM - Translate label if applicable
2203 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . ":&nbsp;</td>";
2205 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id], ENT_NOQUOTES) . "</td></tr>";
2208 $s .= "</table>";
2209 } // a set of exam results; 3 radio buttons and a text field:
2210 elseif ($data_type == 23) {
2211 $tmp = explode('|', $currvalue);
2212 $avalue = array();
2213 foreach ($tmp as $value) {
2214 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2215 $avalue[$matches[1]] = $matches[2];
2219 $lres = sqlStatement("SELECT * FROM list_options " .
2220 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2221 $s .= "<table cellpadding='0' cellspacing='0'>";
2222 while ($lrow = sqlFetchArray($lres)) {
2223 $option_id = $lrow['option_id'];
2224 $restype = substr($avalue[$option_id], 0, 1);
2225 $resnote = substr($avalue[$option_id], 2);
2226 if (empty($restype) && empty($resnote)) {
2227 continue;
2230 // Added 5-09 by BM - Translate label if applicable
2231 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2233 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
2234 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2235 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2236 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2237 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2238 $s .= "</tr>";
2241 $s .= "</table>";
2242 } // the list of active allergies for the current patient
2243 elseif ($data_type == 24) {
2244 $query = "SELECT title, comments FROM lists WHERE " .
2245 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2246 "ORDER BY begdate";
2247 // echo "<!-- $query -->\n"; // debugging
2248 $lres = sqlStatement($query, array($GLOBALS['pid']));
2249 $count = 0;
2250 while ($lrow = sqlFetchArray($lres)) {
2251 if ($count++) {
2252 $s .= "<br />";
2255 $s .= htmlspecialchars($lrow['title'], ENT_NOQUOTES);
2256 if ($lrow['comments']) {
2257 $s .= ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
2260 } // a set of labeled checkboxes, each with a text field:
2261 elseif ($data_type == 25) {
2262 $tmp = explode('|', $currvalue);
2263 $avalue = array();
2264 foreach ($tmp as $value) {
2265 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2266 $avalue[$matches[1]] = $matches[2];
2270 $lres = sqlStatement("SELECT * FROM list_options " .
2271 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2272 $s .= "<table cellpadding='0' cellspacing='0'>";
2273 while ($lrow = sqlFetchArray($lres)) {
2274 $option_id = $lrow['option_id'];
2275 $restype = substr($avalue[$option_id], 0, 1);
2276 $resnote = substr($avalue[$option_id], 2);
2277 if (empty($restype) && empty($resnote)) {
2278 continue;
2281 // Added 5-09 by BM - Translate label if applicable
2282 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2284 $restype = $restype ? xl('Yes') : xl('No');
2285 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2286 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2287 $s .= "</tr>";
2290 $s .= "</table>";
2291 } // a set of labeled radio buttons
2292 elseif ($data_type == 27) {
2293 // In this special case, fld_length is the number of columns generated.
2294 $cols = max(1, $frow['fld_length']);
2295 $lres = sqlStatement("SELECT * FROM list_options " .
2296 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2297 $s .= "<table cellspacing='0' cellpadding='0'>";
2298 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2299 $option_id = $lrow['option_id'];
2300 $option_id_esc = text($option_id);
2301 if ($count % $cols == 0) {
2302 if ($count) {
2303 $s .= "</tr>";
2305 $s .= "<tr>";
2307 $s .= "<td>";
2308 $checked = ((strlen($currvalue) == 0 && $lrow['is_default']) ||
2309 (strlen($currvalue) > 0 && $option_id == $currvalue));
2310 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2311 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2312 $s .= "</td>";
2314 if ($count) {
2315 $s .= "</tr>";
2317 $s .= "</table>";
2318 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2319 // VicarePlus :: A selection list for smoking status.
2320 elseif ($data_type == 28 || $data_type == 32) {
2321 $tmp = explode('|', $currvalue);
2322 switch (count($tmp)) {
2323 case "4":
2324 $resnote = $tmp[0];
2325 $restype = $tmp[1];
2326 $resdate = oeFormatShortDate($tmp[2]);
2327 $reslist = $tmp[3];
2328 break;
2329 case "3":
2330 $resnote = $tmp[0];
2331 $restype = $tmp[1];
2332 $resdate = oeFormatShortDate($tmp[2]);
2333 break;
2334 case "2":
2335 $resnote = $tmp[0];
2336 $restype = $tmp[1];
2337 $resdate = "";
2338 break;
2339 case "1":
2340 $resnote = $tmp[0];
2341 $resdate = $restype = "";
2342 break;
2343 default:
2344 $restype = $resdate = $resnote = "";
2345 break;
2348 $s .= "<table cellpadding='0' cellspacing='0'>";
2350 $s .= "<tr>";
2351 $res = "";
2352 if ($restype == "current".$field_id) {
2353 $res = xl('Current');
2356 if ($restype == "quit".$field_id) {
2357 $res = xl('Quit');
2360 if ($restype == "never".$field_id) {
2361 $res = xl('Never');
2364 if ($restype == "not_applicable".$field_id) {
2365 $res = xl('N/A');
2368 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2369 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2370 if ($data_type == 28) {
2371 if (!empty($resnote)) {
2372 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2374 } //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2375 elseif ($data_type == 32) {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2376 $smoke_codes = getSmokeCodes();
2377 if (!empty($reslist)) {
2378 if ($smoke_codes[$reslist]!="") {
2379 $code_desc = "( ".$smoke_codes[$reslist]." )";
2382 $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>";
2385 if (!empty($resnote)) {
2386 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2390 if (!empty($res)) {
2391 $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'), ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res, ENT_NOQUOTES) . "&nbsp;</td>";
2394 if ($restype == "quit".$field_id) {
2395 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate, ENT_NOQUOTES) . "&nbsp;</td>";
2398 $s .= "</tr>";
2399 $s .= "</table>";
2400 } // static text. read-only, of course.
2401 elseif ($data_type == 31) {
2402 $s .= parse_static_text($frow);
2403 } elseif ($data_type == 34) {
2404 $arr = explode("|*|*|*|", $currvalue);
2405 for ($i=0; $i<sizeof($arr); $i++) {
2406 $s.=$arr[$i];
2408 } // facility
2409 elseif ($data_type == 35) {
2410 $urow = $facilityService->getById($currvalue);
2411 $s = htmlspecialchars($urow['name'], ENT_NOQUOTES);
2412 } // Multi select
2413 // Supports backup lists
2414 elseif ($data_type == 36) {
2415 $values_array = explode("|", $currvalue);
2416 $i = 0;
2417 foreach ($values_array as $value) {
2418 $lrow = sqlQuery("SELECT title FROM list_options " .
2419 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2420 if ($lrow == 0 && !empty($backup_list)) {
2421 //use back up list
2422 $lrow = sqlQuery("SELECT title FROM list_options " .
2423 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2426 if ($i > 0) {
2427 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2428 } else {
2429 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2432 $i++;
2434 } // Image from canvas drawing
2435 elseif ($data_type == 40) {
2436 if ($currvalue) {
2437 $s .= "<img src='" . attr($currvalue) . "'>";
2441 return $s;
2444 // Generate plain text versions of selected LBF field types.
2445 // Currently used by interface/patient_file/download_template.php and interface/main/finder/dynamic_finder_ajax.php.
2446 // More field types might need to be supported here in the future.
2448 function generate_plaintext_field($frow, $currvalue)
2450 global $ISSUE_TYPES;
2452 $data_type = $frow['data_type'];
2453 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2454 $list_id = $frow['list_id'];
2455 $backup_list = $frow['backup_list'];
2456 $s = '';
2458 // generic selection list or the generic selection list with add on the fly
2459 // feature, or radio buttons
2460 // Supports backup lists (for datatypes 1,26,33)
2461 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2462 $lrow = sqlQuery("SELECT title FROM list_options " .
2463 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2464 $s = xl_list_label($lrow['title']);
2465 //if there is no matching value in the corresponding lists check backup list
2466 // only supported in data types 1,26,33
2467 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2468 $lrow = sqlQuery("SELECT title FROM list_options " .
2469 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2470 $s = xl_list_label($lrow['title']);
2472 } // simple or long text field
2473 elseif ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2474 $s = $currvalue;
2475 } // date
2476 elseif ($data_type == 4) {
2477 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
2478 if (!$modtmp) {
2479 $s = text(oeFormatShortDate($currvalue));
2480 } else {
2481 $s = text(oeFormatDateTime($currvalue));
2483 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2484 $age_asof_date = '';
2485 // Optional display of age or gestational age.
2486 $tmp = optionalAge($frow, $currvalue, $age_asof_date, $description);
2487 if ($tmp) {
2488 $s .= ' ' . $tmp;
2490 } // provider
2491 elseif ($data_type == 10 || $data_type == 11) {
2492 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2493 "WHERE id = ?", array($currvalue));
2494 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2495 } // pharmacy list
2496 elseif ($data_type == 12) {
2497 $pres = get_pharmacies();
2498 while ($prow = sqlFetchArray($pres)) {
2499 $key = $prow['id'];
2500 if ($currvalue == $key) {
2501 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2502 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2503 $prow['line1'] . ' / ' . $prow['city'];
2506 } // address book
2507 elseif ($data_type == 14) {
2508 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2509 "WHERE id = ?", array($currvalue));
2510 $uname = $urow['lname'];
2511 if ($urow['fname']) {
2512 $uname .= ", " . $urow['fname'];
2515 $s = $uname;
2516 } // insurance company list
2517 elseif ($data_type == 16) {
2518 $insprovs = getInsuranceProviders();
2519 foreach ($insprovs as $key => $ipname) {
2520 if ($currvalue == $key) {
2521 $s .= $ipname;
2524 } // issue type
2525 elseif ($data_type == 17) {
2526 foreach ($ISSUE_TYPES as $key => $value) {
2527 if ($currvalue == $key) {
2528 $s .= $value[1];
2531 } // visit category
2532 elseif ($data_type == 18) {
2533 $crow = sqlQuery(
2534 "SELECT pc_catid, pc_catname " .
2535 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2536 array($currvalue)
2538 $s = $crow['pc_catname'];
2539 } // a set of labeled checkboxes
2540 elseif ($data_type == 21) {
2541 if (!$list_id) {
2542 $s .= $currvalue ? xlt('Yes') : xlt('No');
2543 } else {
2544 $avalue = explode('|', $currvalue);
2545 $lres = sqlStatement("SELECT * FROM list_options " .
2546 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2547 $count = 0;
2548 while ($lrow = sqlFetchArray($lres)) {
2549 $option_id = $lrow['option_id'];
2550 if (in_array($option_id, $avalue)) {
2551 if ($count++) {
2552 $s .= "; ";
2554 $s .= xl_list_label($lrow['title']);
2558 } // a set of labeled text input fields
2559 elseif ($data_type == 22) {
2560 $tmp = explode('|', $currvalue);
2561 $avalue = array();
2562 foreach ($tmp as $value) {
2563 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2564 $avalue[$matches[1]] = $matches[2];
2568 $lres = sqlStatement("SELECT * FROM list_options " .
2569 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2570 while ($lrow = sqlFetchArray($lres)) {
2571 $option_id = $lrow['option_id'];
2572 if (empty($avalue[$option_id])) {
2573 continue;
2576 if ($s !== '') {
2577 $s .= '; ';
2580 $s .= xl_list_label($lrow['title']) . ': ';
2581 $s .= $avalue[$option_id];
2583 } // A set of exam results; 3 radio buttons and a text field.
2584 // This shows abnormal results only.
2585 elseif ($data_type == 23) {
2586 $tmp = explode('|', $currvalue);
2587 $avalue = array();
2588 foreach ($tmp as $value) {
2589 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2590 $avalue[$matches[1]] = $matches[2];
2594 $lres = sqlStatement("SELECT * FROM list_options " .
2595 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2596 while ($lrow = sqlFetchArray($lres)) {
2597 $option_id = $lrow['option_id'];
2598 $restype = substr($avalue[$option_id], 0, 1);
2599 $resnote = substr($avalue[$option_id], 2);
2600 if (empty($restype) && empty($resnote)) {
2601 continue;
2604 if ($restype != '2') {
2605 continue; // show abnormal results only
2608 if ($s !== '') {
2609 $s .= '; ';
2612 $s .= xl_list_label($lrow['title']);
2613 if (!empty($resnote)) {
2614 $s .= ': ' . $resnote;
2617 } // the list of active allergies for the current patient
2618 elseif ($data_type == 24) {
2619 $query = "SELECT title, comments FROM lists WHERE " .
2620 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2621 "ORDER BY begdate";
2622 $lres = sqlStatement($query, array($GLOBALS['pid']));
2623 $count = 0;
2624 while ($lrow = sqlFetchArray($lres)) {
2625 if ($count++) {
2626 $s .= "; ";
2629 $s .= $lrow['title'];
2630 if ($lrow['comments']) {
2631 $s .= ' (' . $lrow['comments'] . ')';
2634 } // a set of labeled checkboxes, each with a text field:
2635 elseif ($data_type == 25) {
2636 $tmp = explode('|', $currvalue);
2637 $avalue = array();
2638 foreach ($tmp as $value) {
2639 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2640 $avalue[$matches[1]] = $matches[2];
2644 $lres = sqlStatement("SELECT * FROM list_options " .
2645 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2646 while ($lrow = sqlFetchArray($lres)) {
2647 $option_id = $lrow['option_id'];
2648 $restype = substr($avalue[$option_id], 0, 1);
2649 $resnote = substr($avalue[$option_id], 2);
2650 if (empty($restype) && empty($resnote)) {
2651 continue;
2654 if ($s !== '') {
2655 $s .= '; ';
2658 $s .= xl_list_label($lrow['title']);
2659 $restype = $restype ? xl('Yes') : xl('No');
2660 $s .= $restype;
2661 if ($resnote) {
2662 $s .= ' ' . $resnote;
2665 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2666 // VicarePlus :: A selection list for smoking status.
2667 elseif ($data_type == 28 || $data_type == 32) {
2668 $tmp = explode('|', $currvalue);
2669 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2670 $restype = count($tmp) > 1 ? $tmp[1] : '';
2671 $resdate = count($tmp) > 2 ? oeFormatShortDate($tmp[2]) : '';
2672 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2673 $res = "";
2674 if ($restype == "current" . $field_id) {
2675 $res = xl('Current');
2678 if ($restype == "quit" . $field_id) {
2679 $res = xl('Quit');
2682 if ($restype == "never" . $field_id) {
2683 $res = xl('Never');
2686 if ($restype == "not_applicable". $field_id) {
2687 $res = xl('N/A');
2690 if ($data_type == 28) {
2691 if (!empty($resnote)) {
2692 $s .= $resnote;
2694 } // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2695 elseif ($data_type == 32) {
2696 if (!empty($reslist)) {
2697 $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
2700 if (!empty($resnote)) {
2701 $s .= ' ' . $resnote;
2705 if (!empty($res)) {
2706 if ($s !== '') {
2707 $s .= ' ';
2710 $s .= xl('Status') . ' ' . $res;
2713 if ($restype == "quit".$field_id) {
2714 if ($s !== '') {
2715 $s .= ' ';
2718 $s .= $resdate;
2720 } // Multi select
2721 // Supports backup lists
2722 elseif ($data_type == 36) {
2723 $values_array = explode("|", $currvalue);
2725 $i = 0;
2726 foreach ($values_array as $value) {
2727 $lrow = sqlQuery("SELECT title FROM list_options " .
2728 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2730 if ($lrow == 0 && !empty($backup_list)) {
2731 //use back up list
2732 $lrow = sqlQuery("SELECT title FROM list_options " .
2733 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2736 if ($i > 0) {
2737 $s = $s . ", " . xl_list_label($lrow['title']);
2738 } else {
2739 $s = xl_list_label($lrow['title']);
2742 $i++;
2746 return $s;
2749 $CPR = 4; // cells per row of generic data
2750 $last_group = '';
2751 $cell_count = 0;
2752 $item_count = 0;
2754 function disp_end_cell()
2756 global $item_count, $cell_count;
2757 if ($item_count > 0) {
2758 echo "</td>";
2759 $item_count = 0;
2763 function disp_end_row()
2765 global $cell_count, $CPR;
2766 disp_end_cell();
2767 if ($cell_count > 0) {
2768 for (; $cell_count < $CPR;
2769 ++$cell_count) {
2770 echo "<td></td>";
2773 echo "</tr>\n";
2774 $cell_count = 0;
2778 function disp_end_group()
2780 global $last_group;
2781 if (strlen($last_group) > 0) {
2782 disp_end_row();
2786 // Accumulate action conditions into a JSON expression for the browser side.
2787 function accumActionConditions($field_id, &$condition_str, &$condarr)
2789 $conditions = empty($condarr) ? array() : unserialize($condarr);
2790 $action = 'skip';
2791 foreach ($conditions as $key => $condition) {
2792 if ($key === 'action') {
2793 // If specified this should be the first array item.
2794 if ($condition) {
2795 $action = $condition;
2797 continue;
2799 if (empty($condition['id'])) {
2800 continue;
2802 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2803 if ($condition_str) {
2804 $condition_str .= ",\n";
2806 $condition_str .= "{" .
2807 "target:'" . addslashes($field_id) . "', " .
2808 "action:'" . addslashes($action) . "', " .
2809 "id:'" . addslashes($condition['id']) . "', " .
2810 "itemid:'" . addslashes($condition['itemid']) . "', " .
2811 "operator:'" . addslashes($condition['operator']) . "', " .
2812 "value:'" . addslashes($condition['value']) . "', " .
2813 "andor:'" . addslashes($andor) . "'}";
2817 // This checks if the given field with the given value should have an action applied.
2818 // Originally the only action was skip, but now you can also set the field to a specified value.
2819 // It somewhat mirrors the checkSkipConditions function in options.js.php.
2820 // If you use this for multiple layouts in the same script, you should
2821 // clear $sk_layout_items before each layout.
2822 function isSkipped(&$frow, $currvalue)
2824 global $sk_layout_items;
2826 // Accumulate an array of the encountered fields and their values.
2827 // It is assumed that fields appear before they are tested by another field.
2828 // TBD: Bad assumption?
2829 $field_id = $frow['field_id'];
2830 if (!is_array($sk_layout_items)) {
2831 $sk_layout_items = array();
2833 $sk_layout_items[$field_id] = array('row' => $frow, 'value' => $currvalue);
2835 if (empty($frow['conditions'])) {
2836 return false;
2839 $skiprows = unserialize($frow['conditions']);
2840 $prevandor = '';
2841 $prevcond = false;
2842 $datatype = $frow['data_type'];
2843 $action = 'skip'; // default action if none specified
2845 foreach ($skiprows as $key => $skiprow) {
2846 // id referenced field id
2847 // itemid referenced array key if applicable
2848 // operator "eq", "ne", "se" or "ns"
2849 // value if eq or ne, some string to compare with
2850 // andor "and", "or" or empty
2852 if ($key === 'action') {
2853 // Action value is a string. It can be "skip", or "value=" followed by a value.
2854 $action = $skiprow;
2855 continue;
2858 if (empty($skiprow['id'])) {
2859 continue;
2862 $id = $skiprow['id'];
2863 if (!isset($sk_layout_items[$id])) {
2864 error_log("Function isSkipped() cannot find skip source field '$id'.");
2865 continue;
2867 $itemid = $skiprow['itemid'];
2868 $operator = $skiprow['operator'];
2869 $skipval = $skiprow['value'];
2870 $srcvalue = $sk_layout_items[$id]['value'];
2871 $src_datatype = $sk_layout_items[$id]['row']['data_type'];
2872 $src_list_id = $sk_layout_items[$id]['row']['list_id'];
2874 // Some data types use itemid and we have to dig for their value.
2875 if ($src_datatype == 21 && $src_list_id) { // array of checkboxes
2876 $tmp = explode('|', $srcvalue);
2877 $srcvalue = in_array($itemid, $tmp);
2878 } elseif ($src_datatype == 22 || $src_datatype == 23 || $src_datatype == 25) {
2879 $tmp = explode('|', $srcvalue);
2880 $srcvalue = '';
2881 foreach ($tmp as $tmp2) {
2882 if (strpos($tmp2, "$itemid:") === 0) {
2883 if ($datatype == 22) {
2884 $srcvalue = substr($tmp2, strlen($itemid) + 1);
2885 } else {
2886 $srcvalue = substr($tmp2, strlen($itemid) + 1, 1);
2892 // Compute the result of the test for this condition row.
2893 // PHP's looseness with variable type conversion helps us here.
2894 $condition = false;
2895 if ($operator == 'eq') {
2896 $condition = $srcvalue == $skipval;
2897 } elseif ($operator == 'ne') {
2898 $condition = $srcvalue != $skipval;
2899 } elseif ($operator == 'se') {
2900 $condition = $srcvalue == true;
2901 } elseif ($operator == 'ns') {
2902 $condition = $srcvalue != true;
2903 } else {
2904 error_log("Unknown skip operator '$operator' for field '$field_id'.");
2907 // Logic to accumulate multiple conditions for the same target.
2908 if ($prevandor == 'and') {
2909 $condition = $condition && $prevcond;
2910 } elseif ($prevandor == 'or') {
2911 $condition = $condition || $prevcond;
2913 $prevandor = $skiprow['andor'];
2914 $prevcond = $condition;
2916 return $prevcond ? $action : '';
2919 // Load array of names of the given layout and its groups.
2920 function getLayoutProperties($formtype, &$grparr, $sel = "grp_title")
2922 if ($sel != '*' && strpos($sel, 'grp_group_id') === false) {
2923 $sel = "grp_group_id, $sel";
2925 $gres = sqlStatement("SELECT $sel FROM layout_group_properties WHERE grp_form_id = ? " .
2926 "ORDER BY grp_group_id", array($formtype));
2927 while ($grow = sqlFetchArray($gres)) {
2928 $grparr[$grow['grp_group_id']] = $grow;
2932 function display_layout_rows($formtype, $result1, $result2 = '')
2934 global $item_count, $cell_count, $last_group, $CPR;
2936 $grparr = array();
2937 getLayoutProperties($formtype, $grparr, '*');
2939 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
2941 $fres = sqlStatement("SELECT * FROM layout_options " .
2942 "WHERE form_id = ? AND uor > 0 " .
2943 "ORDER BY group_id, seq", array($formtype));
2945 while ($frow = sqlFetchArray($fres)) {
2946 $this_group = $frow['group_id'];
2947 $titlecols = $frow['titlecols'];
2948 $datacols = $frow['datacols'];
2949 $data_type = $frow['data_type'];
2950 $field_id = $frow['field_id'];
2951 $list_id = $frow['list_id'];
2952 $currvalue = '';
2954 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
2956 if ($formtype == 'DEM') {
2957 if (strpos($field_id, 'em_') === 0) {
2958 // Skip employer related fields, if it's disabled.
2959 if ($GLOBALS['omit_employers']) {
2960 continue;
2963 $tmp = substr($field_id, 3);
2964 if (isset($result2[$tmp])) {
2965 $currvalue = $result2[$tmp];
2967 } else {
2968 if (isset($result1[$field_id])) {
2969 $currvalue = $result1[$field_id];
2972 } else {
2973 if (isset($result1[$field_id])) {
2974 $currvalue = $result1[$field_id];
2978 // Handle a data category (group) change.
2979 if (strcmp($this_group, $last_group) != 0) {
2980 $group_name = $grparr[$this_group]['grp_title'];
2981 // totally skip generating the employer category, if it's disabled.
2982 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
2983 continue;
2986 disp_end_group();
2987 $last_group = $this_group;
2990 // filter out all the empty field data from the patient report.
2991 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2992 // Handle starting of a new row.
2993 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2994 disp_end_row();
2995 echo "<tr>";
2996 if ($group_name) {
2997 echo "<td class='groupname'>";
2998 echo text(xl_layout_label($group_name));
2999 $group_name = '';
3000 } else {
3001 echo "<td valign='top'>&nbsp;";
3004 echo "</td>";
3007 if ($item_count == 0 && $titlecols == 0) {
3008 $titlecols = 1;
3011 // Handle starting of a new label cell.
3012 if ($titlecols > 0) {
3013 disp_end_cell();
3014 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
3015 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3016 echo "<td class='label_custom' colspan='$titlecols_esc' ";
3017 //if ($cell_count == 2) echo " style='padding-left:10pt'";
3018 echo ">";
3019 $cell_count += $titlecols;
3022 ++$item_count;
3024 // Added 5-09 by BM - Translate label if applicable
3025 if ($frow['title']) {
3026 $tmp = xl_layout_label($frow['title']);
3027 echo text($tmp);
3028 // Append colon only if label does not end with punctuation.
3029 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3030 echo ':';
3032 } else {
3033 echo "&nbsp;";
3036 // Handle starting of a new data cell.
3037 if ($datacols > 0) {
3038 disp_end_cell();
3039 //echo "<td class='text data' colspan='$datacols' valign='top'";
3040 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3041 echo "<td class='text data' colspan='$datacols_esc'";
3042 //if ($cell_count > 0) echo " style='padding-left:5pt'";
3043 echo ">";
3044 $cell_count += $datacols;
3047 ++$item_count;
3048 echo generate_display_field($frow, $currvalue);
3052 disp_end_group();
3055 function display_layout_tabs($formtype, $result1, $result2 = '')
3057 global $item_count, $cell_count, $last_group, $CPR;
3059 $grparr = array();
3060 getLayoutProperties($formtype, $grparr);
3062 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3063 "WHERE form_id = ? AND uor > 0 " .
3064 "ORDER BY group_id", array($formtype));
3066 $first = true;
3067 while ($frow = sqlFetchArray($fres)) {
3068 $this_group = $frow['group_id'];
3069 // $group_name = substr($this_group, 1);
3070 $group_name = $grparr[$this_group]['grp_title'];
3071 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3072 continue;
3075 <li <?php echo $first ? 'class="current"' : '' ?>>
3076 <a href="#" id="header_tab_<?php echo htmlspecialchars($group_name, ENT_QUOTES); ?>">
3077 <?php echo htmlspecialchars(xl_layout_label($group_name), ENT_NOQUOTES); ?></a>
3078 </li>
3079 <?php
3080 $first = false;
3084 function display_layout_tabs_data($formtype, $result1, $result2 = '')
3086 global $item_count, $cell_count, $last_group, $CPR;
3088 $grparr = array();
3089 getLayoutProperties($formtype, $grparr, '*');
3091 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3093 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3094 "WHERE form_id = ? AND uor > 0 " .
3095 "ORDER BY group_id", array($formtype));
3097 $first = true;
3098 while ($frow = sqlFetchArray($fres)) {
3099 $this_group = isset($frow['group_id']) ? $frow['group_id'] : "" ;
3101 if ($grparr[$this_group]['grp_columns'] === 'Employer' && $GLOBALS['omit_employers']) {
3102 continue;
3104 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3105 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : $grparr[$this_group]['grp_subtitle'];
3107 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3108 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3109 "ORDER BY seq", array($formtype, $this_group));
3112 <div class="tab <?php echo $first ? 'current' : '' ?>">
3113 <table border='0' cellpadding='0'>
3115 <?php
3116 while ($group_fields = sqlFetchArray($group_fields_query)) {
3117 $titlecols = $group_fields['titlecols'];
3118 $datacols = $group_fields['datacols'];
3119 $data_type = $group_fields['data_type'];
3120 $field_id = $group_fields['field_id'];
3121 $list_id = $group_fields['list_id'];
3122 $currvalue = '';
3123 $edit_options = $group_fields['edit_options'];
3125 if ($formtype == 'DEM') {
3126 if (strpos($field_id, 'em_') === 0) {
3127 // Skip employer related fields, if it's disabled.
3128 if ($GLOBALS['omit_employers']) {
3129 continue;
3132 $tmp = substr($field_id, 3);
3133 if (isset($result2[$tmp])) {
3134 $currvalue = $result2[$tmp];
3136 } else {
3137 if (isset($result1[$field_id])) {
3138 $currvalue = $result1[$field_id];
3141 } else {
3142 if (isset($result1[$field_id])) {
3143 $currvalue = $result1[$field_id];
3147 // Skip this field if action conditions call for that.
3148 // Note this also accumulates info for subsequent skip tests.
3149 $skip_this_field = isSkipped($group_fields, $currvalue) == 'skip';
3151 // Skip this field if its do-not-print option is set.
3152 if (isOption($edit_options, 'X') !== false) {
3153 $skip_this_field = true;
3156 // Handle a data category (group) change.
3157 if (strcmp($this_group, $last_group) != 0) {
3158 $group_name = $grparr[$this_group]['grp_title'];
3159 // totally skip generating the employer category, if it's disabled.
3160 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3161 continue;
3163 $last_group = $this_group;
3166 // Handle starting of a new row.
3167 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
3168 disp_end_row();
3169 if ($subtitle) {
3170 // Group subtitle exists and is not displayed yet.
3171 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3172 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3173 $subtitle = '';
3175 echo "<tr>";
3178 if ($item_count == 0 && $titlecols == 0) {
3179 $titlecols = 1;
3182 // Handle starting of a new label cell.
3183 if ($titlecols > 0) {
3184 disp_end_cell();
3185 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3186 $field_id_label = 'label_'.$group_fields['field_id'];
3187 echo "<td class='label_custom' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
3188 echo ">";
3189 $cell_count += $titlecols;
3192 ++$item_count;
3194 $field_id_label = 'label_'.$group_fields['field_id'];
3195 echo "<span id='".attr($field_id_label)."'>";
3196 if ($skip_this_field) {
3197 // No label because skipping
3198 } elseif ($group_fields['title']) {
3199 $tmp = xl_layout_label($group_fields['title']);
3200 echo text($tmp);
3201 // Append colon only if label does not end with punctuation.
3202 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3203 echo ':';
3205 } else {
3206 echo "&nbsp;";
3208 echo "</span>";
3210 // Handle starting of a new data cell.
3211 if ($datacols > 0) {
3212 disp_end_cell();
3213 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3214 $field_id = 'text_'.$group_fields['field_id'];
3215 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
3216 if (!$skip_this_field && $data_type == 3) {
3217 // Textarea gets a light grey border.
3218 echo " style='border:1px solid #cccccc'";
3220 echo ">";
3221 $cell_count += $datacols;
3222 } else {
3223 $field_id = 'text_'.$group_fields['field_id'];
3224 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
3227 ++$item_count;
3228 if (!$skip_this_field) {
3229 echo generate_display_field($group_fields, $currvalue);
3233 disp_end_row();
3236 </table>
3237 </div>
3239 <?php
3241 $first = false;
3245 function display_layout_tabs_data_editable($formtype, $result1, $result2 = '')
3247 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
3249 $grparr = array();
3250 getLayoutProperties($formtype, $grparr, '*');
3252 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3254 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3255 "WHERE form_id = ? AND uor > 0 " .
3256 "ORDER BY group_id", array($formtype));
3258 $first = true;
3259 $condition_str = '';
3261 while ($frow = sqlFetchArray($fres)) {
3262 $this_group = $frow['group_id'];
3263 $group_name = $grparr[$this_group]['grp_title'];
3264 $group_name_esc = text($group_name);
3266 if ($grparr[$this_group]['grp_title'] === 'Employer' && $GLOBALS['omit_employers']) {
3267 continue;
3269 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3270 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : $grparr[$this_group]['grp_subtitle'];
3272 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3273 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3274 "ORDER BY seq", array($formtype, $this_group));
3277 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_', $group_name_esc)?>" >
3278 <table border='0' cellpadding='0'>
3280 <?php
3281 while ($group_fields = sqlFetchArray($group_fields_query)) {
3282 $titlecols = $group_fields['titlecols'];
3283 $datacols = $group_fields['datacols'];
3284 $data_type = $group_fields['data_type'];
3285 $field_id = $group_fields['field_id'];
3286 $list_id = $group_fields['list_id'];
3287 $backup_list = $group_fields['list_backup_id'];
3288 $currvalue = '';
3289 $action = 'skip';
3291 // Accumulate action conditions into a JSON expression for the browser side.
3292 accumActionConditions($field_id, $condition_str, $group_fields['conditions']);
3294 if ($formtype == 'DEM') {
3295 if (strpos($field_id, 'em_') === 0) {
3296 // Skip employer related fields, if it's disabled.
3297 if ($GLOBALS['omit_employers']) {
3298 continue;
3301 $tmp = substr($field_id, 3);
3302 if (isset($result2[$tmp])) {
3303 $currvalue = $result2[$tmp];
3305 } else {
3306 if (isset($result1[$field_id])) {
3307 $currvalue = $result1[$field_id];
3310 } else {
3311 if (isset($result1[$field_id])) {
3312 $currvalue = $result1[$field_id];
3316 // Handle a data category (group) change.
3317 if (strcmp($this_group, $last_group) != 0) {
3318 // totally skip generating the employer category, if it's disabled.
3319 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3320 continue;
3323 $last_group = $this_group;
3326 // Handle starting of a new row.
3327 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
3328 disp_end_row();
3329 if ($subtitle) {
3330 // Group subtitle exists and is not displayed yet.
3331 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3332 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3333 $subtitle = '';
3335 echo "<tr>";
3338 if ($item_count == 0 && $titlecols == 0) {
3339 $titlecols = 1;
3342 // Handle starting of a new label cell.
3343 if ($titlecols > 0) {
3344 disp_end_cell();
3345 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3346 $field_id_label = 'label_'.$group_fields['field_id'];
3347 echo "<td class='label_custom' colspan='$titlecols_esc'";
3348 // This ID is used by skip conditions.
3349 echo " id='label_id_" . attr($field_id) . "'";
3350 echo ">";
3351 $cell_count += $titlecols;
3354 ++$item_count;
3356 if ($group_fields['title']) {
3357 $tmp = xl_layout_label($group_fields['title']);
3358 echo text($tmp);
3359 // Append colon only if label does not end with punctuation.
3360 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3361 echo ':';
3363 } else {
3364 echo "&nbsp;";
3367 // Handle starting of a new data cell.
3368 if ($datacols > 0) {
3369 disp_end_cell();
3370 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3371 $field_id = 'text_'.$group_fields['field_id'];
3372 echo "<td class='text data' colspan='$datacols_esc'";
3373 // This ID is used by action conditions.
3374 echo " id='value_id_" . attr($field_id) . "'";
3375 echo ">";
3376 $cell_count += $datacols;
3379 ++$item_count;
3381 echo generate_form_field($group_fields, $currvalue);
3385 </table>
3386 </div>
3388 <?php
3390 $first = false;
3394 // From the currently posted HTML form, this gets the value of the
3395 // field corresponding to the provided layout_options table row.
3397 function get_layout_form_value($frow, $prefix = 'form_')
3399 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
3400 $data_type = $frow['data_type'];
3401 $field_id = $frow['field_id'];
3402 $value = '';
3403 if (isset($_POST["$prefix$field_id"])) {
3404 if ($data_type == 4) {
3405 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
3406 if (!$modtmp) {
3407 $value = DateToYYYYMMDD($_POST["$prefix$field_id"]);
3408 } else {
3409 $value = DateTimeToYYYYMMDDHHMMSS($_POST["$prefix$field_id"]);
3411 } elseif ($data_type == 21) {
3412 if (!$frow['list_id']) {
3413 if (!empty($_POST["form_$field_id"])) {
3414 $value = xlt('Yes');
3416 } else {
3417 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
3418 // must be concatenated into a |-separated string.
3419 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3420 if (strlen($value)) {
3421 $value .= '|';
3423 $value .= $key;
3426 } elseif ($data_type == 22) {
3427 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
3428 // into "key:value|key:value|...".
3429 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3430 $val = str_replace('|', ' ', $val);
3431 if (strlen($value)) {
3432 $value .= '|';
3435 $value .= "$key:$val";
3437 } elseif ($data_type == 23) {
3438 // $_POST["$prefix$field_id"] is an array of text fields with companion
3439 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
3440 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3441 $restype = $_POST["radio_{$field_id}"][$key];
3442 if (empty($restype)) {
3443 $restype = '0';
3446 $val = str_replace('|', ' ', $val);
3447 if (strlen($value)) {
3448 $value .= '|';
3451 $value .= "$key:$restype:$val";
3453 } elseif ($data_type == 25) {
3454 // $_POST["$prefix$field_id"] is an array of text fields with companion
3455 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
3456 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3457 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
3458 $val = str_replace('|', ' ', $val);
3459 if (strlen($value)) {
3460 $value .= '|';
3463 $value .= "$key:$restype:$val";
3465 } elseif ($data_type == 28 || $data_type == 32) {
3466 // $_POST["$prefix$field_id"] is an date text fields with companion
3467 // radio buttons to be imploded into "notes|type|date".
3468 $restype = $_POST["radio_{$field_id}"];
3469 if (empty($restype)) {
3470 $restype = '0';
3473 $resdate = DateToYYYYMMDD(str_replace('|', ' ', $_POST["date_$field_id"]));
3474 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3475 if ($data_type == 32) {
3476 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
3477 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3478 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
3479 $value = "$res_text_note|$restype|$resdate|$reslist";
3480 } else {
3481 $value = "$resnote|$restype|$resdate";
3483 } elseif ($data_type == 36) {
3484 $value_array = $_POST["form_$field_id"];
3485 $i = 0;
3486 foreach ($value_array as $key => $valueofkey) {
3487 if ($i == 0) {
3488 $value = $valueofkey;
3489 } else {
3490 $value = $value . "|" . $valueofkey;
3493 $i++;
3495 } else {
3496 $value = $_POST["$prefix$field_id"];
3500 // Better to die than to silently truncate data!
3501 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength) {
3502 die(htmlspecialchars(xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
3503 ":<br />&nbsp;<br />".htmlspecialchars($value, ENT_NOQUOTES));
3506 return trim($value);
3509 // Generate JavaScript validation logic for the required fields.
3511 function generate_layout_validation($form_id)
3513 $fres = sqlStatement("SELECT * FROM layout_options " .
3514 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
3515 "ORDER BY group_id, seq", array($form_id));
3517 while ($frow = sqlFetchArray($fres)) {
3518 $data_type = $frow['data_type'];
3519 $field_id = $frow['field_id'];
3520 $fldtitle = $frow['title'];
3521 if (!$fldtitle) {
3522 $fldtitle = $frow['description'];
3525 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES);
3527 if ($data_type == 40) {
3528 $fldid = addslashes("form_$field_id");
3529 // Move canvas image data to its hidden form field so the server will get it.
3530 echo
3531 " var canfld = f['$fldid'];\n" .
3532 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
3533 continue;
3536 if ($frow['uor'] < 2) {
3537 continue;
3540 echo " if (f.$fldname && !f.$fldname.disabled) {\n";
3541 switch ($data_type) {
3542 case 1:
3543 case 11:
3544 case 12:
3545 case 13:
3546 case 14:
3547 case 26:
3548 echo
3549 " if (f.$fldname.selectedIndex <= 0) {\n" .
3550 " alert(\"" . addslashes(xl('Please choose a value for')) .
3551 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3552 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3553 " return false;\n" .
3554 " }\n";
3555 break;
3556 case 33:
3557 echo
3558 " if (f.$fldname.selectedIndex <= 0) {\n" .
3559 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3560 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3561 " }\n";
3562 break;
3563 case 27: // radio buttons
3564 echo
3565 " var i = 0;\n" .
3566 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
3567 " if (i >= f.$fldname.length) {\n" .
3568 " alert(\"" . addslashes(xl('Please choose a value for')) .
3569 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3570 " return false;\n" .
3571 " }\n";
3572 break;
3573 case 2:
3574 case 3:
3575 case 4:
3576 case 15:
3577 echo
3578 " if (trimlen(f.$fldname.value) == 0) {\n" .
3579 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3580 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
3581 " $('#" . $fldname . "').attr('style','background:red'); \n" .
3582 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3583 " } else { " .
3584 " $('#" . $fldname . "').attr('style',''); " .
3585 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
3586 " } \n";
3587 break;
3588 case 36: // multi select
3589 echo
3590 " var multi_select=f['$fldname"."[]']; \n " .
3591 " var multi_choice_made=false; \n".
3592 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
3593 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
3594 " } \n" .
3595 " if(!multi_choice_made)
3596 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3598 break;
3600 echo " }\n";
3605 * DROPDOWN FOR FACILITIES
3607 * build a dropdown with all facilities
3609 * @param string $selected - name of the currently selected facility
3610 * use '0' for "unspecified facility"
3611 * use '' for "All facilities" (the default)
3612 * @param string $name - the name/id for select form (defaults to "form_facility")
3613 * @param boolean $allow_unspecified - include an option for "unspecified" facility
3614 * defaults to true
3615 * @return void - just echo the html encoded string
3617 * Note: This should become a data-type at some point, according to Brady
3619 function dropdown_facility(
3620 $selected = '',
3621 $name = 'form_facility',
3622 $allow_unspecified = true,
3623 $allow_allfacilities = true,
3624 $disabled = '',
3625 $onchange = ''
3628 global $facilityService;
3630 $have_selected = false;
3631 $fres = $facilityService->getAll();
3633 $name = htmlspecialchars($name, ENT_QUOTES);
3634 echo " <select class='form-control' name='$name' id='$name'";
3635 if ($onchange) {
3636 echo " onchange='$onchange'";
3639 echo " $disabled>\n";
3641 if ($allow_allfacilities) {
3642 $option_value = '';
3643 $option_selected_attr = '';
3644 if ($selected == '') {
3645 $option_selected_attr = ' selected="selected"';
3646 $have_selected = true;
3649 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
3650 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3651 } elseif ($allow_unspecified) {
3652 $option_value = '0';
3653 $option_selected_attr = '';
3654 if ($selected == '0') {
3655 $option_selected_attr = ' selected="selected"';
3656 $have_selected = true;
3659 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
3660 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3663 foreach ($fres as $frow) {
3664 $facility_id = $frow['id'];
3665 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
3666 $option_selected_attr = '';
3667 if ($selected == $facility_id) {
3668 $option_selected_attr = ' selected="selected"';
3669 $have_selected = true;
3672 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
3673 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3676 if ($allow_unspecified && $allow_allfacilities) {
3677 $option_value = '0';
3678 $option_selected_attr = '';
3679 if ($selected == '0') {
3680 $option_selected_attr = ' selected="selected"';
3681 $have_selected = true;
3684 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
3685 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3688 if (!$have_selected) {
3689 $option_value = htmlspecialchars($selected, ENT_QUOTES);
3690 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
3691 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
3692 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
3695 echo " </select>\n";
3698 // Expand Collapse Widget
3699 // This forms the header and functionality component of the widget. The information that is displayed
3700 // then follows this function followed by a closing div tag
3702 // $title is the title of the section (already translated)
3703 // $label is identifier used in the tag id's and sql columns
3704 // $buttonLabel is the button label text (already translated)
3705 // $buttonLink is the button link information
3706 // $buttonClass is any additional needed class elements for the button tag
3707 // $linkMethod is the button link method ('javascript' vs 'html')
3708 // $bodyClass is to set class(es) of the body
3709 // $auth is a flag to decide whether to show the button
3710 // $fixedWidth is to flag whether width is fixed
3711 // $forceExpandAlways is a flag to force the widget to always be expanded
3713 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways = false)
3715 if ($fixedWidth) {
3716 echo "<div class='section-header'>";
3717 } else {
3718 echo "<div class='section-header-dynamic'>";
3721 echo "<table><tr>";
3722 if ($auth) {
3723 // show button, since authorized
3724 // first prepare class string
3725 if ($buttonClass) {
3726 $class_string = "css_button_small ".htmlspecialchars($buttonClass, ENT_NOQUOTES);
3727 } else {
3728 $class_string = "css_button_small";
3731 // next, create the link
3732 if ($linkMethod == "javascript") {
3733 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3734 } else {
3735 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3736 if (!isset($_SESSION['patient_portal_onsite']) && !isset($_SESSION['patient_portal_onsite_two'])) {
3737 // prevent an error from occuring when calling the function from the patient portal
3738 echo " onclick='top.restoreSession()'";
3742 echo "><span>" .
3743 htmlspecialchars($buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
3746 if ($forceExpandAlways) {
3747 // Special case to force the widget to always be expanded
3748 echo "<td><span class='text'><b>" . htmlspecialchars($title, ENT_NOQUOTES) . "</b></span>";
3749 $indicatorTag ="style='display:none'";
3752 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3753 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3754 htmlspecialchars($label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
3755 echo htmlspecialchars($title, ENT_NOQUOTES) . "</b></span>";
3757 if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3758 // collapse all entries in the patient portal
3759 $text = xl('expand');
3760 } elseif (getUserSetting($label."_ps_expand")) {
3761 $text = xl('collapse');
3762 } else {
3763 $text = xl('expand');
3766 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
3767 "</span>)</a></td>";
3768 echo "</tr></table>";
3769 echo "</div>";
3770 if ($forceExpandAlways) {
3771 // Special case to force the widget to always be expanded
3772 $styling = "";
3773 } elseif (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3774 // collapse all entries in the patient portal
3775 $styling = "style='display:none'";
3776 } elseif (getUserSetting($label."_ps_expand")) {
3777 $styling = "";
3778 } else {
3779 $styling = "style='display:none'";
3782 if ($bodyClass) {
3783 $styling .= " class='" . $bodyClass . "'";
3786 //next, create the first div tag to hold the information
3787 // note the code that calls this function will then place the ending div tag after the data
3788 echo "<div id='" . htmlspecialchars($label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
3791 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3792 function billing_facility($name, $select)
3794 global $facilityService;
3796 $fres = $facilityService->getAllBillingLocations();
3797 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' class='form-control' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3798 foreach ($fres as $facrow) {
3799 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3800 echo "<option value=".htmlspecialchars($facrow['id'], ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3803 echo "</select>";
3806 // Generic function to get the translated title value for a particular list option.
3808 function getListItemTitle($list, $option)
3810 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3811 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3812 if (empty($row['title'])) {
3813 return $option;
3816 return xl_list_label($row['title']);
3819 //function to get the translated title value in Patient Transactions
3820 function getLayoutTitle($list, $option)
3822 $row = sqlQuery("SELECT grp_title FROM layout_group_properties " .
3823 "WHERE grp_mapping = ? AND grp_form_id = ? ", array($list, $option));
3825 if (empty($row['grp_title'])) {
3826 return $option;
3828 return xl_list_label($row['grp_title']);
3830 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3831 function getSmokeCodes()
3833 $smoking_codes_arr = array();
3834 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3835 while ($codes_row = sqlFetchArray($smoking_codes)) {
3836 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3839 return $smoking_codes_arr;
3842 // Get the current value for a layout based form field.
3843 // Depending on options this might come from lbf_data, patient_data,
3844 // form_encounter, shared_attributes or elsewhere.
3845 // Returns FALSE if the field ID is invalid (layout error).
3847 function lbf_current_value($frow, $formid, $encounter)
3849 global $pid;
3850 $formname = $frow['form_id'];
3851 $field_id = $frow['field_id'];
3852 $source = $frow['source'];
3853 $currvalue = '';
3854 $deffname = $formname . '_default_' . $field_id;
3855 if ($source == 'D' || $source == 'H') {
3856 // Get from patient_data, employer_data or history_data.
3857 if ($source == 'H') {
3858 $table = 'history_data';
3859 $orderby = 'ORDER BY date DESC LIMIT 1';
3860 } elseif (strpos($field_id, 'em_') === 0) {
3861 $field_id = substr($field_id, 3);
3862 $table = 'employer_data';
3863 $orderby = 'ORDER BY date DESC LIMIT 1';
3864 } else {
3865 $table = 'patient_data';
3866 $orderby = '';
3869 // It is an error if the field does not exist, but don't crash.
3870 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3871 if (empty($tmp)) {
3872 return '*?*';
3875 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3876 if (isset($pdrow)) {
3877 $currvalue = $pdrow['field_value'];
3879 } elseif ($source == 'E') {
3880 $sarow = false;
3881 if ($encounter) {
3882 // Get value from shared_attributes of the current encounter.
3883 $sarow = sqlQuery(
3884 "SELECT field_value FROM shared_attributes WHERE " .
3885 "pid = ? AND encounter = ? AND field_id = ?",
3886 array($pid, $encounter, $field_id)
3888 if (!empty($sarow)) {
3889 $currvalue = $sarow['field_value'];
3891 } elseif ($formid) {
3892 // Get from shared_attributes of the encounter that this form is linked to.
3893 // Note the importance of having an index on forms.form_id.
3894 $sarow = sqlQuery(
3895 "SELECT sa.field_value " .
3896 "FROM forms AS f, shared_attributes AS sa WHERE " .
3897 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3898 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3899 array($formid, $formname, $field_id)
3901 if (!empty($sarow)) {
3902 $currvalue = $sarow['field_value'];
3904 } else {
3905 // New form and encounter not available, this should not happen.
3907 if (empty($sarow) && !$formid) {
3908 // New form, see if there is a custom default from a plugin.
3909 if (function_exists($deffname)) {
3910 $currvalue = call_user_func($deffname);
3913 } elseif ($source == 'V') {
3914 if ($encounter) {
3915 // Get value from the current encounter's form_encounter.
3916 $ferow = sqlQuery(
3917 "SELECT * FROM form_encounter WHERE " .
3918 "pid = ? AND encounter = ?",
3919 array($pid, $encounter)
3921 if (isset($ferow[$field_id])) {
3922 $currvalue = $ferow[$field_id];
3924 } elseif ($formid) {
3925 // Get value from the form_encounter that this form is linked to.
3926 $ferow = sqlQuery(
3927 "SELECT fe.* " .
3928 "FROM forms AS f, form_encounter AS fe WHERE " .
3929 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3930 "fe.pid = f.pid AND fe.encounter = f.encounter",
3931 array($formid, $formname)
3933 if (isset($ferow[$field_id])) {
3934 $currvalue = $ferow[$field_id];
3936 } else {
3937 // New form and encounter not available, this should not happen.
3939 } elseif ($formid) {
3940 // This is a normal form field.
3941 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3942 "form_id = ? AND field_id = ?", array($formid, $field_id));
3943 if (!empty($ldrow)) {
3944 $currvalue = $ldrow['field_value'];
3946 } else {
3947 // New form, see if there is a custom default from a plugin.
3948 if (function_exists($deffname)) {
3949 $currvalue = call_user_func($deffname);
3953 return $currvalue;
3956 // This returns stuff that needs to go into the <head> section of a caller using
3957 // the drawable image field type in a form.
3958 // A TRUE argument makes the widget controls smaller.
3960 function lbf_canvas_head($small = true)
3962 $s = <<<EOD
3963 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas/css/literallycanvas.css" rel="stylesheet" />
3964 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/build/react-with-addons.min.js"></script>
3965 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/build/react-dom.min.js"></script>
3966 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas/js/literallycanvas.min.js"></script>
3967 EOD;
3968 if ($small) {
3969 $s .= <<<EOD
3970 <style>
3971 /* Custom LiterallyCanvas styling.
3972 * This makes the widget 25% less tall and adjusts some other things accordingly.
3974 .literally {
3975 min-height:100%;min-width:300px; /* Was 400, unspecified */
3977 .literally .lc-picker .toolbar-button {
3978 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3980 .literally .color-well {
3981 font-size:8px;width:49px; /* Was 10, 60 */
3983 .literally .color-well-color-container {
3984 width:21px;height:21px; /* Was 28, 28 */
3986 .literally .lc-picker {
3987 width:50px; /* Was 61 */
3989 .literally .lc-drawing.with-gui {
3990 left:50px; /* Was 61 */
3992 .literally .lc-options {
3993 left:50px; /* Was 61 */
3995 .literally .color-picker-popup {
3996 left:49px;bottom:0px; /* Was 60, 31 */
3998 </style>
3999 EOD;
4002 return $s;
4006 * Test if modifier($test) is in array of options for data type.
4008 * @param json array $options or could be string of form "ABCU"
4009 * @param string $test
4010 * @return boolean
4012 function isOption($options, $test)
4014 if (empty($options) || !isset($test)) {
4015 return false; // why bother?
4017 if (strpos($options, ',') === false) { // could be string of char's or single element of json
4018 json_decode($options);
4019 if (is_string($options) && ! (json_last_error() === JSON_ERROR_NONE)) { // nope, it's string.
4020 $t = str_split(trim($options)); // very good chance it's legacy modifier string.
4021 $options = json_encode($t); // make it array.
4024 $options = json_decode($options);
4026 return !is_null($options) && in_array($test, $options, true) ? true : false; // finally!