POS default selection for encounter (#1088)
[openemr.git] / library / options.inc.php
blobe42d051a31ea1889a6ba4828435204c6b5ab6b83
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 (strpos($frow['edit_options'], 'A') !== false) {
69 $format = 0;
70 } else if (strpos($frow['edit_options'], 'B') !== false) {
71 $format = 3;
72 } else {
73 return '';
76 if (strpos($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 } else if (!$got_selected && strlen($currvalue) > 0 && $multiple) {
245 //if not found in main list, display all selected values that exist in backup list
246 $list_id = $backup_list;
248 $got_selected_backup = false;
249 if (!empty($backup_list)) {
250 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
251 while ($lrow_backup = sqlFetchArray($lres_backup)) {
252 $selectedValues = explode("|", $currvalue);
254 $optionValue = attr($lrow_backup['option_id']);
256 if (in_array($lrow_backup ['option_id'], $selectedValues)) {
257 $s .= "<option value='$optionValue'";
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 (strpos($frow['edit_options'], 'T') !== false) {
333 if (strlen($currescaped) == 0) {
334 $currescaped = $description;
337 // Description used in this way is not suitable as a title.
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 = strpos($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 else if ($data_type == 2) {
387 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
388 $maxlength = $frow['max_length'];
389 $string_maxlength = "";
390 // if max_length is set to zero, then do not set a maxlength
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 (strpos($frow['edit_options'], 'C') !== false) {
405 $tmp .= "capitalizeMe(this);";
406 } else if (strpos($frow['edit_options'], 'U') !== false) {
407 $tmp .= "this.value = this.value.toUpperCase();";
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 (strpos($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 else if ($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 else if ($data_type == 4) {
447 $age_asof_date = ''; // optionalAge() sets this
448 $age_format = strpos($frow['edit_options'], 'A') === false ? 3 : 0;
449 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
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')\"";
460 echo "<input type='text' size='10' class='datepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
461 " value='" . substr($currescaped, 0, 10) . "'";
462 if (!$agestr) {
463 echo " title='$description'";
466 echo " $onchange_string $lbfonchange $disabled />";
468 // Optional display of age or gestational age.
469 if ($agestr) {
470 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
472 } // provider list, local providers only
473 else if ($data_type == 10) {
474 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
475 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
476 "AND authorized = 1 " .
477 "ORDER BY lname, fname");
478 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
479 echo "<option value=''>" . xlt($empty_title) . "</option>";
480 $got_selected = false;
481 while ($urow = sqlFetchArray($ures)) {
482 $uname = text($urow['fname'] . ' ' . $urow['lname']);
483 $optionId = attr($urow['id']);
484 echo "<option value='$optionId'";
485 if ($urow['id'] == $currvalue) {
486 echo " selected";
487 $got_selected = true;
490 echo ">$uname</option>";
493 if (!$got_selected && $currvalue) {
494 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
495 echo "</select>";
496 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
497 } else {
498 echo "</select>";
500 } // provider list, including address book entries with an NPI number
501 else if ($data_type == 11) {
502 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
503 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
504 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
505 "ORDER BY lname, fname");
506 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
507 echo " $lbfonchange $disabled>";
508 echo "<option value=''>" . xlt('Unassigned') . "</option>";
509 $got_selected = false;
510 while ($urow = sqlFetchArray($ures)) {
511 $uname = text($urow['fname'] . ' ' . $urow['lname']);
512 $optionId = attr($urow['id']);
513 echo "<option value='$optionId'";
514 if ($urow['id'] == $currvalue) {
515 echo " selected";
516 $got_selected = true;
519 echo ">$uname</option>";
522 if (!$got_selected && $currvalue) {
523 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
524 echo "</select>";
525 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
526 } else {
527 echo "</select>";
529 } // pharmacy list
530 else if ($data_type == 12) {
531 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
532 echo " $lbfonchange $disabled>";
533 echo "<option value='0'></option>";
534 $pres = get_pharmacies();
535 $got_selected = false;
536 while ($prow = sqlFetchArray($pres)) {
537 $key = $prow['id'];
538 $optionValue = htmlspecialchars($key, ENT_QUOTES);
539 $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
540 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
541 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
542 echo "<option value='$optionValue'";
543 if ($currvalue == $key) {
544 echo " selected";
545 $got_selected = true;
548 echo ">$optionLabel</option>";
551 if (!$got_selected && $currvalue) {
552 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
553 echo "</select>";
554 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
555 } else {
556 echo "</select>";
558 } // squads
559 else if ($data_type == 13) {
560 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
561 echo " $lbfonchange $disabled>";
562 echo "<option value=''>&nbsp;</option>";
563 $squads = acl_get_squads();
564 if ($squads) {
565 foreach ($squads as $key => $value) {
566 $optionValue = htmlspecialchars($key, ENT_QUOTES);
567 $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES);
568 echo "<option value='$optionValue'";
569 if ($currvalue == $key) {
570 echo " selected";
573 echo ">$optionLabel</option>\n";
577 echo "</select>";
578 } // Address book, preferring organization name if it exists and is not in
579 // parentheses, and excluding local users who are not providers.
580 // Supports "referred to" practitioners and facilities.
581 // Alternatively the letter L in edit_options means that abook_type
582 // must be "ord_lab", indicating types used with the procedure
583 // lab ordering system.
584 // Alternatively the letter O in edit_options means that abook_type
585 // must begin with "ord_", indicating types used with the procedure
586 // ordering system.
587 // Alternatively the letter V in edit_options means that abook_type
588 // must be "vendor", indicating the Vendor type.
589 // Alternatively the letter R in edit_options means that abook_type
590 // must be "dist", indicating the Distributor type.
591 else if ($data_type == 14) {
592 if (strpos($frow['edit_options'], 'L') !== false) {
593 $tmp = "abook_type = 'ord_lab'";
594 } else if (strpos($frow['edit_options'], 'O') !== false) {
595 $tmp = "abook_type LIKE 'ord\\_%'";
596 } else if (strpos($frow['edit_options'], 'V') !== false) {
597 $tmp = "abook_type LIKE 'vendor%'";
598 } else if (strpos($frow['edit_options'], 'R') !== false) {
599 $tmp = "abook_type LIKE 'dist'";
600 } else {
601 $tmp = "( username = '' OR authorized = 1 )";
604 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
605 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
606 "AND $tmp " .
607 "ORDER BY organization, lname, fname");
608 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
609 echo " $lbfonchange $disabled>";
610 echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES) . "</option>";
611 while ($urow = sqlFetchArray($ures)) {
612 $uname = $urow['organization'];
613 if (empty($uname) || substr($uname, 0, 1) == '(') {
614 $uname = $urow['lname'];
615 if ($urow['fname']) {
616 $uname .= ", " . $urow['fname'];
620 $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES);
621 $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES);
622 echo "<option value='$optionValue'";
623 // Failure to translate Local and External is not an error here;
624 // they are only used as internal flags and must not be translated!
625 $title = $urow['username'] ? 'Local' : 'External';
626 $optionTitle = htmlspecialchars($title, ENT_QUOTES);
627 echo " title='$optionTitle'";
628 if ($urow['id'] == $currvalue) {
629 echo " selected";
632 echo ">$optionLabel</option>";
635 echo "</select>";
636 } // A billing code. If description matches an existing code type then that type is used.
637 else if ($data_type == 15) {
638 $codetype = '';
639 if (!empty($frow['description']) && isset($code_types[$frow['description']])) {
640 $codetype = $frow['description'];
642 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
643 $maxlength = $frow['max_length'];
644 $string_maxlength = "";
645 // if max_length is set to zero, then do not set a maxlength
646 if ($maxlength) {
647 $string_maxlength = "maxlength='".attr($maxlength)."'";
651 if (strpos($frow['edit_options'], '2') !== false && substr($frow['form_id'], 0, 3) == 'LBF') {
652 // Option "2" generates a hidden input for the codes, and a matching visible field
653 // displaying their descriptions. First step is computing the description string.
654 $currdescstring = '';
655 if (!empty($currvalue)) {
656 $relcodes = explode(';', $currvalue);
657 foreach ($relcodes as $codestring) {
658 if ($codestring === '') {
659 continue;
662 $code_text = lookup_code_descriptions($codestring);
663 if ($currdescstring !== '') {
664 $currdescstring .= '; ';
667 if (!empty($code_text)) {
668 $currdescstring .= $code_text;
669 } else {
670 $currdescstring .= $codestring;
675 $currdescstring = attr($currdescstring);
677 echo "<input type='text'" .
678 " name='form_$field_id_esc'" .
679 " id='form_related_code'" .
680 " size='$fldlength'" .
681 " value='$currescaped'" .
682 " style='display:none'" .
683 " $lbfonchange readonly $disabled />";
684 // Extra readonly input field for optional display of code description(s).
685 echo "<input type='text'" .
686 " name='form_$field_id_esc" . "__desc'" .
687 " size='$fldlength'" .
688 " title='$description'" .
689 " value='$currdescstring'";
690 if (!$disabled) {
691 echo " onclick='sel_related(this,\"$codetype\")'";
694 echo "class='form-control'";
695 echo " readonly $disabled />";
696 } else {
697 echo "<input type='text'" .
698 " name='form_$field_id_esc'" .
699 " id='form_related_code'" .
700 " size='$fldlength'" .
701 " $string_maxlength" .
702 " title='$description'" .
703 " value='$currescaped'";
704 if (!$disabled) {
705 echo " onclick='sel_related(this,\"$codetype\")'";
708 echo "class='form-control'";
709 echo " $lbfonchange readonly $disabled />";
711 } // insurance company list
712 else if ($data_type == 16) {
713 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
714 echo "<option value='0'></option>";
715 $insprovs = getInsuranceProviders();
716 $got_selected = false;
717 foreach ($insprovs as $key => $ipname) {
718 $optionValue = htmlspecialchars($key, ENT_QUOTES);
719 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
720 echo "<option value='$optionValue'";
721 if ($currvalue == $key) {
722 echo " selected";
723 $got_selected = true;
726 echo ">$optionLabel</option>";
729 if (!$got_selected && $currvalue) {
730 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
731 echo "</select>";
732 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
733 } else {
734 echo "</select>";
736 } // issue types
737 else if ($data_type == 17) {
738 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
739 echo "<option value='0'></option>";
740 $got_selected = false;
741 foreach ($ISSUE_TYPES as $key => $value) {
742 $optionValue = htmlspecialchars($key, ENT_QUOTES);
743 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
744 echo "<option value='$optionValue'";
745 if ($currvalue == $key) {
746 echo " selected";
747 $got_selected = true;
750 echo ">$optionLabel</option>";
753 if (!$got_selected && strlen($currvalue) > 0) {
754 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
755 echo "</select>";
756 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
757 } else {
758 echo "</select>";
760 } // Visit categories.
761 else if ($data_type == 18) {
762 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
763 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
764 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'" .
765 " $lbfonchange $disabled>";
766 echo "<option value=''>" . xlt($empty_title) . "</option>";
767 $got_selected = false;
768 while ($crow = sqlFetchArray($cres)) {
769 $catid = $crow['pc_catid'];
770 if (($catid < 9 && $catid != 5) || $catid == 11) {
771 continue;
774 echo "<option value='" . attr($catid) . "'";
775 if ($catid == $currvalue) {
776 echo " selected";
777 $got_selected = true;
780 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
783 if (!$got_selected && $currvalue) {
784 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
785 echo "</select>";
786 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
787 } else {
788 echo "</select>";
790 } // a set of labeled checkboxes
791 else if ($data_type == 21) {
792 // If no list then it's a single checkbox and its value is "Yes" or empty.
793 if (!$list_id) {
794 echo "<input type='checkbox' name='form_{$field_id_esc}' " .
795 "id='form_{$field_id_esc}' value='Yes' $lbfonchange";
796 if ($currvalue) {
797 echo " checked";
799 echo " $disabled />";
800 } else {
801 // In this special case, fld_length is the number of columns generated.
802 $cols = max(1, $frow['fld_length']);
803 $avalue = explode('|', $currvalue);
804 $lres = sqlStatement("SELECT * FROM list_options " .
805 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
806 echo "<table cellpadding='0' cellspacing='0' width='100%' title='".attr($description)."'>";
807 $tdpct = (int) (100 / $cols);
808 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
809 $option_id = $lrow['option_id'];
810 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
811 // if ($count) echo "<br />";
812 if ($count % $cols == 0) {
813 if ($count) {
814 echo "</tr>";
816 echo "<tr>";
818 echo "<td width='" . attr($tdpct) . "%' nowrap>";
819 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
820 "id='form_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
821 if (in_array($option_id, $avalue)) {
822 echo " checked";
824 // Added 5-09 by BM - Translate label if applicable
825 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
826 echo "</td>";
828 if ($count) {
829 echo "</tr>";
830 if ($count > $cols) {
831 // Add some space after multiple rows of checkboxes.
832 $cols = htmlspecialchars($cols, ENT_QUOTES);
833 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
836 echo "</table>";
838 } // a set of labeled text input fields
839 else if ($data_type == 22) {
840 $tmp = explode('|', $currvalue);
841 $avalue = array();
842 foreach ($tmp as $value) {
843 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
844 $avalue[$matches[1]] = $matches[2];
848 $lres = sqlStatement("SELECT * FROM list_options " .
849 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
850 echo "<table cellpadding='0' cellspacing='0'>";
851 while ($lrow = sqlFetchArray($lres)) {
852 $option_id = $lrow['option_id'];
853 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
854 $maxlength = $frow['max_length'];
855 $string_maxlength = "";
856 // if max_length is set to zero, then do not set a maxlength
857 if ($maxlength) {
858 $string_maxlength = "maxlength='".attr($maxlength)."'";
861 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
863 // Added 5-09 by BM - Translate label if applicable
864 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
865 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
866 $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
867 echo "<td><input type='text'" .
868 " name='form_{$field_id_esc}[$option_id_esc]'" .
869 " id='form_{$field_id_esc}[$option_id_esc]'" .
870 " size='$fldlength'" .
871 " class='form-control'" .
872 " $string_maxlength" .
873 " value='$optionValue'";
874 echo " $lbfonchange $disabled /></td></tr>";
877 echo "</table>";
878 } // a set of exam results; 3 radio buttons and a text field:
879 else if ($data_type == 23) {
880 $tmp = explode('|', $currvalue);
881 $avalue = array();
882 foreach ($tmp as $value) {
883 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
884 $avalue[$matches[1]] = $matches[2];
888 $maxlength = $frow['max_length'];
889 $string_maxlength = "";
890 // if max_length is set to zero, then do not set a maxlength
891 if ($maxlength) {
892 $string_maxlength = "maxlength='".attr($maxlength)."'";
895 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
896 $lres = sqlStatement("SELECT * FROM list_options " .
897 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
898 echo "<table cellpadding='0' cellspacing='0'>";
899 echo "<tr><td>&nbsp;</td><td class='bold'>" .
900 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
901 "&nbsp;</td><td class='bold'>" .
902 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
903 "<td class='bold'>" .
904 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
905 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
906 while ($lrow = sqlFetchArray($lres)) {
907 $option_id = $lrow['option_id'];
908 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
909 $restype = substr($avalue[$option_id], 0, 1);
910 $resnote = substr($avalue[$option_id], 2);
912 // Added 5-09 by BM - Translate label if applicable
913 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
915 for ($i = 0; $i < 3; ++$i) {
916 $inputValue = htmlspecialchars($i, ENT_QUOTES);
917 echo "<td><input type='radio'" .
918 " name='radio_{$field_id_esc}[$option_id_esc]'" .
919 " id='radio_{$field_id_esc}[$option_id_esc]'" .
920 " value='$inputValue' $lbfonchange";
921 if ($restype === "$i") {
922 echo " checked";
925 echo " $disabled /></td>";
928 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
929 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
930 echo "<td><input type='text'" .
931 " name='form_{$field_id_esc}[$option_id_esc]'" .
932 " id='form_{$field_id_esc}[$option_id_esc]'" .
933 " size='$fldlength'" .
934 " $string_maxlength" .
935 " value='$resnote' $disabled /></td>";
936 echo "</tr>";
939 echo "</table>";
940 } // the list of active allergies for the current patient
941 // this is read-only!
942 else if ($data_type == 24) {
943 $query = "SELECT title, comments FROM lists WHERE " .
944 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
945 "ORDER BY begdate";
946 // echo "<!-- $query -->\n"; // debugging
947 $lres = sqlStatement($query, array($GLOBALS['pid']));
948 $count = 0;
949 while ($lrow = sqlFetchArray($lres)) {
950 if ($count++) {
951 echo "<br />";
954 echo htmlspecialchars($lrow['title'], ENT_NOQUOTES);
955 if ($lrow['comments']) {
956 echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
959 } // a set of labeled checkboxes, each with a text field:
960 else if ($data_type == 25) {
961 $tmp = explode('|', $currvalue);
962 $avalue = array();
963 foreach ($tmp as $value) {
964 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
965 $avalue[$matches[1]] = $matches[2];
969 $maxlength = $frow['max_length'];
970 $string_maxlength = "";
971 // if max_length is set to zero, then do not set a maxlength
972 if ($maxlength) {
973 $string_maxlength = "maxlength='".attr($maxlength)."'";
976 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
977 $lres = sqlStatement("SELECT * FROM list_options " .
978 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
979 echo "<table cellpadding='0' cellspacing='0'>";
980 while ($lrow = sqlFetchArray($lres)) {
981 $option_id = $lrow['option_id'];
982 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
983 $restype = substr($avalue[$option_id], 0, 1);
984 $resnote = substr($avalue[$option_id], 2);
986 // Added 5-09 by BM - Translate label if applicable
987 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
989 $option_id = htmlspecialchars($option_id, ENT_QUOTES);
990 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
991 " id='check_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
992 if ($restype) {
993 echo " checked";
996 echo " $disabled />&nbsp;</td>";
997 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
998 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
999 echo "<td><input type='text'" .
1000 " name='form_{$field_id_esc}[$option_id_esc]'" .
1001 " id='form_{$field_id_esc}[$option_id_esc]'" .
1002 " size='$fldlength'" .
1003 " class='form-control' " .
1004 " $string_maxlength" .
1005 " value='$resnote' $disabled /></td>";
1006 echo "</tr>";
1009 echo "</table>";
1010 } // single-selection list with ability to add to it
1011 else if ($data_type == 26) {
1012 echo generate_select_list(
1013 "form_$field_id",
1014 $list_id,
1015 $currvalue,
1016 $description,
1017 ($showEmpty ? $empty_title : ''),
1018 'addtolistclass_'.$list_id,
1019 $lbfchange,
1021 ($disabled ? array('disabled' => 'disabled') : null),
1022 false,
1023 $backup_list
1025 // show the add button if user has access to correct list
1026 $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES);
1027 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
1028 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
1029 if (aco_exist('lists', $list_id)) {
1030 // a specific aco exist for this list, so ensure access
1031 if (acl_check('lists', $list_id)) {
1032 echo $outputAddButton;
1034 } else {
1035 // no specific aco exist for this list, so check for access to 'default' list
1036 if (acl_check('lists', 'default')) {
1037 echo $outputAddButton;
1040 } // a set of labeled radio buttons
1041 else if ($data_type == 27) {
1042 // In this special case, fld_length is the number of columns generated.
1043 $cols = max(1, $frow['fld_length']);
1044 $lres = sqlStatement("SELECT * FROM list_options " .
1045 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1046 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1047 $tdpct = (int) (100 / $cols);
1048 $got_selected = false;
1049 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1050 $option_id = $lrow['option_id'];
1051 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
1052 if ($count % $cols == 0) {
1053 if ($count) {
1054 echo "</tr>";
1057 echo "<tr>";
1060 echo "<td width='" . attr($tdpct) . "%'>";
1061 echo "<input type='radio' name='form_{$field_id_esc}' class='form-control' id='form_{$field_id_esc}[$option_id_esc]'" .
1062 " value='$option_id_esc' $lbfonchange";
1063 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1064 (strlen($currvalue) > 0 && $option_id == $currvalue)) {
1065 echo " checked";
1066 $got_selected = true;
1069 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1070 echo "</td>";
1073 if ($count) {
1074 echo "</tr>";
1075 if ($count > $cols) {
1076 // Add some space after multiple rows of radio buttons.
1077 $cols = htmlspecialchars($cols, ENT_QUOTES);
1078 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1082 echo "</table>";
1083 if (!$got_selected && strlen($currvalue) > 0) {
1084 $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES);
1085 $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES);
1086 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
1088 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1089 // VicarePlus :: A selection list box for smoking status:
1090 else if ($data_type == 28 || $data_type == 32) {
1091 $tmp = explode('|', $currvalue);
1092 switch (count($tmp)) {
1093 case "4":
1094 $resnote = $tmp[0];
1095 $restype = $tmp[1];
1096 $resdate = $tmp[2];
1097 $reslist = $tmp[3];
1098 break;
1099 case "3":
1100 $resnote = $tmp[0];
1101 $restype = $tmp[1];
1102 $resdate = $tmp[2];
1103 break;
1104 case "2":
1105 $resnote = $tmp[0];
1106 $restype = $tmp[1];
1107 $resdate = "";
1108 break;
1109 case "1":
1110 $resnote = $tmp[0];
1111 $resdate = $restype = "";
1112 break;
1113 default:
1114 $restype = $resdate = $resnote = "";
1115 break;
1118 $maxlength = $frow['max_length'];
1119 $string_maxlength = "";
1120 // if max_length is set to zero, then do not set a maxlength
1121 if ($maxlength) {
1122 $string_maxlength = "maxlength='".attr($maxlength)."'";
1125 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1127 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1128 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1129 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1130 echo "<table cellpadding='0' cellspacing='0'>";
1131 echo "<tr>";
1132 if ($data_type == 28) {
1133 // input text
1134 echo "<td><input type='text'" .
1135 " name='form_$field_id_esc'" .
1136 " id='form_$field_id_esc'" .
1137 " size='$fldlength'" .
1138 " $string_maxlength" .
1139 " value='$resnote' $disabled />&nbsp;</td>";
1140 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1141 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1142 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1143 } else if ($data_type == 32) {
1144 // input text
1145 echo "<tr><td><input type='text'" .
1146 " name='form_text_$field_id_esc'" .
1147 " id='form_text_$field_id_esc'" .
1148 " size='$fldlength'" .
1149 " class='form-control'" .
1150 " $string_maxlength" .
1151 " value='$resnote' $disabled />&nbsp;</td></tr>";
1152 echo "<td>";
1153 //Selection list for smoking status
1154 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1155 echo generate_select_list(
1156 "form_$field_id",
1157 $list_id,
1158 $reslist,
1159 $description,
1160 ($showEmpty ? $empty_title : ''),
1162 $onchange,
1164 ($disabled ? array('disabled' => 'disabled') : null)
1166 echo "</td>";
1167 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1170 // current
1171 echo "<td class='text' ><input type='radio'" .
1172 " name='radio_{$field_id_esc}'" .
1173 " id='radio_{$field_id_esc}[current]'" .
1174 " class='form-control'" .
1175 " value='current" . $field_id_esc . "' $lbfonchange";
1176 if ($restype == "current" . $field_id) {
1177 echo " checked";
1180 if ($data_type == 32) {
1181 echo " onClick='smoking_statusClicked(this)'";
1184 echo " />" . xlt('Current') . "&nbsp;</td>";
1185 // quit
1186 echo "<td class='text'><input type='radio'" .
1187 " name='radio_{$field_id_esc}'" .
1188 " id='radio_{$field_id_esc}[quit]'" .
1189 " class='form-control'" .
1190 " value='quit".$field_id_esc."' $lbfonchange";
1191 if ($restype == "quit" . $field_id) {
1192 echo " checked";
1195 if ($data_type == 32) {
1196 echo " onClick='smoking_statusClicked(this)'";
1199 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1200 // quit date
1201 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1202 " value='$resdate'" .
1203 " title='$description'" .
1204 " $disabled />";
1205 echo "&nbsp;</td>";
1206 // never
1207 echo "<td class='text'><input type='radio'" .
1208 " name='radio_{$field_id_esc}'" .
1209 " class='form-control'" .
1210 " id='radio_{$field_id_esc}[never]'" .
1211 " value='never" . $field_id_esc . "' $lbfonchange";
1212 if ($restype == "never" . $field_id) {
1213 echo " checked";
1216 if ($data_type == 32) {
1217 echo " onClick='smoking_statusClicked(this)'";
1220 echo " />" . xlt('Never') . "&nbsp;</td>";
1221 // Not Applicable
1222 echo "<td class='text'><input type='radio'" .
1223 " class='form-control' " .
1224 " name='radio_{$field_id}'" .
1225 " id='radio_{$field_id}[not_applicable]'" .
1226 " value='not_applicable" . $field_id . "' $lbfonchange";
1227 if ($restype == "not_applicable" . $field_id) {
1228 echo " checked";
1231 if ($data_type == 32) {
1232 echo " onClick='smoking_statusClicked(this)'";
1235 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1237 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1238 echo "<td class='text' ><div id='smoke_code'></div></td>";
1239 echo "</tr>";
1240 echo "</table>";
1241 } // static text. read-only, of course.
1242 else if ($data_type == 31) {
1243 echo parse_static_text($frow);
1244 } //$data_type == 33
1245 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1246 //$data_type == 33
1248 else if ($data_type == 34) {
1249 $arr = explode("|*|*|*|", $currvalue);
1250 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc, ENT_QUOTES)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1251 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0], ENT_QUOTES)."</div>";
1252 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' class='form-control' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1253 echo "</a>";
1254 } //facilities drop-down list
1255 else if ($data_type == 35) {
1256 if (empty($currvalue)) {
1257 $currvalue = 0;
1260 dropdown_facility(
1261 $selected = $currvalue,
1262 $name = "form_$field_id_esc",
1263 $allow_unspecified = true,
1264 $allow_allfacilities = false,
1265 $disabled,
1266 $lbfchange
1268 } //multiple select
1269 // supports backup list
1270 else if ($data_type == 36) {
1271 echo generate_select_list(
1272 "form_$field_id",
1273 $list_id,
1274 $currvalue,
1275 $description,
1276 $showEmpty ? $empty_title : '',
1278 $onchange,
1280 null,
1281 true,
1282 $backup_list
1284 } // Canvas and related elements for browser-side image drawing.
1285 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1286 else if ($data_type == 40) {
1287 // Unlike other field types, width and height are in pixels.
1288 $canWidth = intval($frow['fld_length']);
1289 $canHeight = intval($frow['fld_rows']);
1290 if (empty($currvalue)) {
1291 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1292 // If defined this is the filename of the default starting image.
1293 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1297 $mywidth = 50 + ($canWidth > 250 ? $canWidth : 250);
1298 $myheight = 31 + ($canHeight > 261 ? $canHeight : 261);
1299 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1300 // Hidden form field exists to send updated data to the server at submit time.
1301 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1302 // Hidden image exists to support initialization of the canvas.
1303 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1304 // $date_init is a misnomer but it's the place for browser-side setup logic.
1305 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1309 function generate_print_field($frow, $currvalue)
1311 global $rootdir, $date_init, $ISSUE_TYPES;
1313 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1315 $data_type = $frow['data_type'];
1316 $field_id = $frow['field_id'];
1317 $list_id = $frow['list_id'];
1318 $fld_length = $frow['fld_length'];
1319 $backup_list = $frow['list_backup_id'];
1321 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1323 // Can pass $frow['empty_title'] with this variable, otherwise
1324 // will default to 'Unassigned'.
1325 // If it is 'SKIP' then an empty text title is completely skipped.
1326 $showEmpty = true;
1327 if (isset($frow['empty_title'])) {
1328 if ($frow['empty_title'] == "SKIP") {
1329 //do not display an 'empty' choice
1330 $showEmpty = false;
1331 $empty_title = "Unassigned";
1332 } else {
1333 $empty_title = $frow['empty_title'];
1335 } else {
1336 $empty_title = "Unassigned";
1339 // generic single-selection list
1340 // Supports backup lists.
1341 if (false && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1342 if (empty($fld_length)) {
1343 if ($list_id == 'titles') {
1344 $fld_length = 3;
1345 } else {
1346 $fld_length = 10;
1350 $tmp = '';
1351 if ($currvalue) {
1352 $lrow = sqlQuery("SELECT title FROM list_options " .
1353 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1354 $tmp = xl_list_label($lrow['title']);
1355 if ($lrow == 0 && !empty($backup_list)) {
1356 // since primary list did not map, try to map to backup list
1357 $lrow = sqlQuery("SELECT title FROM list_options " .
1358 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1359 $tmp = xl_list_label($lrow['title']);
1362 if (empty($tmp)) {
1363 $tmp = "($currvalue)";
1367 /*****************************************************************
1368 echo "<input type='text'" .
1369 " size='$fld_length'" .
1370 " value='$tmp'" .
1371 " class='under'" .
1372 " />";
1373 *****************************************************************/
1374 if ($tmp === '') {
1375 $tmp = '&nbsp;';
1376 } else {
1377 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1380 echo $tmp;
1381 } // simple text field
1382 else if ($data_type == 2 || $data_type == 15) {
1383 /*****************************************************************
1384 echo "<input type='text'" .
1385 " size='$fld_length'" .
1386 " value='$currescaped'" .
1387 " class='under'" .
1388 " />";
1389 *****************************************************************/
1390 if ($currescaped === '') {
1391 $currescaped = '&nbsp;';
1394 echo $currescaped;
1395 } // long or multi-line text field
1396 else if ($data_type == 3) {
1397 $fldlength = htmlspecialchars($fld_length, ENT_QUOTES);
1398 $maxlength = htmlspecialchars($frow['fld_rows'], ENT_QUOTES);
1399 echo "<textarea" .
1400 " class='form-control' " .
1401 " cols='$fldlength'" .
1402 " rows='$maxlength'>" .
1403 $currescaped . "</textarea>";
1404 } // date
1405 else if ($data_type == 4) {
1406 $age_asof_date = '';
1407 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
1408 if ($currvalue === '') {
1409 echo '&nbsp;';
1410 } else {
1411 echo text(oeFormatShortDate($currvalue));
1412 if ($agestr) {
1413 echo "&nbsp;(" . text($agestr) . ")";
1416 } // provider list
1417 else if ($data_type == 10 || $data_type == 11) {
1418 $tmp = '';
1419 if ($currvalue) {
1420 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1421 "WHERE id = ?", array($currvalue));
1422 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1423 if (empty($tmp)) {
1424 $tmp = "($currvalue)";
1428 /*****************************************************************
1429 echo "<input type='text'" .
1430 " size='$fld_length'" .
1431 " value='$tmp'" .
1432 " class='under'" .
1433 " />";
1434 *****************************************************************/
1435 if ($tmp === '') {
1436 $tmp = '&nbsp;';
1437 } else {
1438 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1441 echo $tmp;
1442 } // pharmacy list
1443 else if ($data_type == 12) {
1444 $tmp = '';
1445 if ($currvalue) {
1446 $pres = get_pharmacies();
1447 while ($prow = sqlFetchArray($pres)) {
1448 $key = $prow['id'];
1449 if ($currvalue == $key) {
1450 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1451 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1452 $prow['line1'] . ' / ' . $prow['city'];
1456 if (empty($tmp)) {
1457 $tmp = "($currvalue)";
1461 /*****************************************************************
1462 echo "<input type='text'" .
1463 " size='$fld_length'" .
1464 " value='$tmp'" .
1465 " class='under'" .
1466 " />";
1467 *****************************************************************/
1468 if ($tmp === '') {
1469 $tmp = '&nbsp;';
1470 } else {
1471 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1474 echo $tmp;
1475 } // squads
1476 else if ($data_type == 13) {
1477 $tmp = '';
1478 if ($currvalue) {
1479 $squads = acl_get_squads();
1480 if ($squads) {
1481 foreach ($squads as $key => $value) {
1482 if ($currvalue == $key) {
1483 $tmp = $value[3];
1488 if (empty($tmp)) {
1489 $tmp = "($currvalue)";
1493 /*****************************************************************
1494 echo "<input type='text'" .
1495 " size='$fld_length'" .
1496 " value='$tmp'" .
1497 " class='under'" .
1498 " />";
1499 *****************************************************************/
1500 if ($tmp === '') {
1501 $tmp = '&nbsp;';
1502 } else {
1503 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1506 echo $tmp;
1507 } // Address book.
1508 else if ($data_type == 14) {
1509 $tmp = '';
1510 if ($currvalue) {
1511 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1512 "WHERE id = ?", array($currvalue));
1513 $uname = $urow['lname'];
1514 if ($urow['fname']) {
1515 $uname .= ", " . $urow['fname'];
1518 $tmp = $uname;
1519 if (empty($tmp)) {
1520 $tmp = "($currvalue)";
1524 /*****************************************************************
1525 echo "<input type='text'" .
1526 " size='$fld_length'" .
1527 " value='$tmp'" .
1528 " class='under'" .
1529 " />";
1530 *****************************************************************/
1531 if ($tmp === '') {
1532 $tmp = '&nbsp;';
1533 } else {
1534 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1537 echo $tmp;
1538 } // insurance company list
1539 else if ($data_type == 16) {
1540 $tmp = '';
1541 if ($currvalue) {
1542 $insprovs = getInsuranceProviders();
1543 foreach ($insprovs as $key => $ipname) {
1544 if ($currvalue == $key) {
1545 $tmp = $ipname;
1549 if (empty($tmp)) {
1550 $tmp = "($currvalue)";
1554 if ($tmp === '') {
1555 $tmp = '&nbsp;';
1556 } else {
1557 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1560 echo $tmp;
1561 } // issue types
1562 else if ($data_type == 17) {
1563 $tmp = '';
1564 if ($currvalue) {
1565 foreach ($ISSUE_TYPES as $key => $value) {
1566 if ($currvalue == $key) {
1567 $tmp = $value[1];
1571 if (empty($tmp)) {
1572 $tmp = "($currvalue)";
1576 if ($tmp === '') {
1577 $tmp = '&nbsp;';
1578 } else {
1579 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1582 echo $tmp;
1583 } // Visit categories.
1584 else if ($data_type == 18) {
1585 $tmp = '';
1586 if ($currvalue) {
1587 $crow = sqlQuery(
1588 "SELECT pc_catid, pc_catname " .
1589 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1590 array($currvalue)
1592 $tmp = xl_appt_category($crow['pc_catname']);
1593 if (empty($tmp)) {
1594 $tmp = "($currvalue)";
1598 if ($tmp === '') {
1599 $tmp = '&nbsp;';
1600 } else {
1601 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1604 echo $tmp;
1605 } // a single checkbox or set of labeled checkboxes
1606 else if ($data_type == 21) {
1607 if (!$list_id) {
1608 echo "<input type='checkbox'";
1609 if ($currvalue) {
1610 echo " checked";
1612 echo " />";
1613 } else {
1614 // In this special case, fld_length is the number of columns generated.
1615 $cols = max(1, $fld_length);
1616 $avalue = explode('|', $currvalue);
1617 $lres = sqlStatement("SELECT * FROM list_options " .
1618 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1619 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1620 $tdpct = (int) (100 / $cols);
1621 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1622 $option_id = $lrow['option_id'];
1623 if ($count % $cols == 0) {
1624 if ($count) {
1625 echo "</tr>";
1628 echo "<tr>";
1630 echo "<td width='" . attr($tdpct) . "%'>";
1631 echo "<input type='checkbox'";
1632 if (in_array($option_id, $avalue)) {
1633 echo " checked";
1635 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1636 echo "</td>";
1638 if ($count) {
1639 echo "</tr>";
1640 if ($count > $cols) {
1641 // Add some space after multiple rows of checkboxes.
1642 $cols = htmlspecialchars($cols, ENT_QUOTES);
1643 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1646 echo "</table>";
1648 } // a set of labeled text input fields
1649 else if ($data_type == 22) {
1650 $tmp = explode('|', $currvalue);
1651 $avalue = array();
1652 foreach ($tmp as $value) {
1653 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1654 $avalue[$matches[1]] = $matches[2];
1658 $lres = sqlStatement("SELECT * FROM list_options " .
1659 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1660 echo "<table cellpadding='0' cellspacing='0'>";
1661 while ($lrow = sqlFetchArray($lres)) {
1662 $option_id = $lrow['option_id'];
1663 $fldlength = empty($fld_length) ? 20 : $fld_length;
1664 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1665 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1666 $inputValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
1667 echo "<td><input type='text'" .
1668 " class='form-control' " .
1669 " size='$fldlength'" .
1670 " value='$inputValue'" .
1671 " class='under'" .
1672 " /></td></tr>";
1675 echo "</table>";
1676 } // a set of exam results; 3 radio buttons and a text field:
1677 else if ($data_type == 23) {
1678 $tmp = explode('|', $currvalue);
1679 $avalue = array();
1680 foreach ($tmp as $value) {
1681 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1682 $avalue[$matches[1]] = $matches[2];
1686 $fldlength = empty($fld_length) ? 20 : $fld_length;
1687 $lres = sqlStatement("SELECT * FROM list_options " .
1688 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1689 echo "<table cellpadding='0' cellspacing='0'>";
1690 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1691 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
1692 "&nbsp;</td><td class='bold'>" .
1693 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1694 "<td class='bold'>" .
1695 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1696 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1697 while ($lrow = sqlFetchArray($lres)) {
1698 $option_id = $lrow['option_id'];
1699 $restype = substr($avalue[$option_id], 0, 1);
1700 $resnote = substr($avalue[$option_id], 2);
1701 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1702 for ($i = 0; $i < 3; ++$i) {
1703 echo "<td><input type='radio'";
1704 if ($restype === "$i") {
1705 echo " checked";
1708 echo " /></td>";
1711 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1712 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1713 echo "<td><input type='text'" .
1714 " size='$fldlength'" .
1715 " value='$resnote'" .
1716 " class='under form-control' /></td>" .
1717 "</tr>";
1720 echo "</table>";
1721 } // the list of active allergies for the current patient
1722 // this is read-only!
1723 else if ($data_type == 24) {
1724 $query = "SELECT title, comments FROM lists WHERE " .
1725 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1726 "ORDER BY begdate";
1727 $lres = sqlStatement($query, array($GLOBALS['pid']));
1728 $count = 0;
1729 while ($lrow = sqlFetchArray($lres)) {
1730 if ($count++) {
1731 echo "<br />";
1734 echo htmlspecialchars($lrow['title'], ENT_QUOTES);
1735 if ($lrow['comments']) {
1736 echo htmlspecialchars(' (' . $lrow['comments'] . ')', ENT_QUOTES);
1739 } // a set of labeled checkboxes, each with a text field:
1740 else if ($data_type == 25) {
1741 $tmp = explode('|', $currvalue);
1742 $avalue = array();
1743 foreach ($tmp as $value) {
1744 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1745 $avalue[$matches[1]] = $matches[2];
1749 $fldlength = empty($fld_length) ? 20 : $fld_length;
1750 $lres = sqlStatement("SELECT * FROM list_options " .
1751 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1752 echo "<table cellpadding='0' cellspacing='0'>";
1753 while ($lrow = sqlFetchArray($lres)) {
1754 $option_id = $lrow['option_id'];
1755 $restype = substr($avalue[$option_id], 0, 1);
1756 $resnote = substr($avalue[$option_id], 2);
1757 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1758 echo "<td><input type='checkbox'";
1759 if ($restype) {
1760 echo " checked";
1763 echo " />&nbsp;</td>";
1764 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1765 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1766 echo "<td><input type='text'" .
1767 " size='$fldlength'" .
1768 " class='form-control' " .
1769 " value='$resnote'" .
1770 " class='under'" .
1771 " /></td>" .
1772 "</tr>";
1775 echo "</table>";
1776 } // a set of labeled radio buttons
1777 else if ($data_type == 27 || $data_type == 1 || $data_type == 26 || $data_type == 33) {
1778 // In this special case, fld_length is the number of columns generated.
1779 $cols = max(1, $frow['fld_length']);
1780 $lres = sqlStatement("SELECT * FROM list_options " .
1781 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1782 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1783 $tdpct = (int) (100 / $cols);
1784 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1785 $option_id = $lrow['option_id'];
1786 if ($count % $cols == 0) {
1787 if ($count) {
1788 echo "</tr>";
1791 echo "<tr>";
1793 echo "<td width='" . attr($tdpct) . "%'>";
1794 echo "<input type='radio'";
1795 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1796 // Do not use defaults for these printable forms.
1797 echo " checked";
1800 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1801 echo "</td>";
1804 if ($count) {
1805 echo "</tr>";
1806 if ($count > $cols) {
1807 // Add some space after multiple rows of radio buttons.
1808 $cols = htmlspecialchars($cols, ENT_QUOTES);
1809 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1813 echo "</table>";
1814 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1815 else if ($data_type == 28 || $data_type == 32) {
1816 $tmp = explode('|', $currvalue);
1817 switch (count($tmp)) {
1818 case "4":
1819 $resnote = $tmp[0];
1820 $restype = $tmp[1];
1821 $resdate = $tmp[2];
1822 $reslist = $tmp[3];
1823 break;
1824 case "3":
1825 $resnote = $tmp[0];
1826 $restype = $tmp[1];
1827 $resdate = $tmp[2];
1828 break;
1829 case "2":
1830 $resnote = $tmp[0];
1831 $restype = $tmp[1];
1832 $resdate = "";
1833 break;
1834 case "1":
1835 $resnote = $tmp[0];
1836 $resdate = $restype = "";
1837 break;
1838 default:
1839 $restype = $resdate = $resnote = "";
1840 break;
1843 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1844 echo "<table cellpadding='0' cellspacing='0'>";
1845 echo "<tr>";
1846 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1847 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1848 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1849 if ($data_type == 28) {
1850 echo "<td><input type='text'" .
1851 " size='$fldlength'" .
1852 " class='under'" .
1853 " value='$resnote' /></td>";
1854 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1855 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1856 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1857 } else if ($data_type == 32) {
1858 echo "<tr><td><input type='text'" .
1859 " size='$fldlength'" .
1860 " class='under form-control'" .
1861 " value='$resnote' /></td></tr>";
1862 $fldlength = 30;
1863 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
1864 echo "<td><input type='text'" .
1865 " size='$fldlength'" .
1866 " class='under form-control'" .
1867 " value='$smoking_status_title' /></td>";
1868 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1871 echo "<td><input type='radio' class='form-control'";
1872 if ($restype == "current".$field_id) {
1873 echo " checked";
1876 echo "/>".htmlspecialchars(xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1878 echo "<td><input type='radio' class='form-control'";
1879 if ($restype == "current".$field_id) {
1880 echo " checked";
1883 echo "/>".htmlspecialchars(xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1885 echo "<td><input type='text' size='6'" .
1886 " value='$resdate'" .
1887 " class='under form-control'" .
1888 " /></td>";
1890 echo "<td><input type='radio' class='form-control'";
1891 if ($restype == "current".$field_id) {
1892 echo " checked";
1895 echo " />".htmlspecialchars(xl('Never'), ENT_NOQUOTES)."</td>";
1897 echo "<td><input type='radio' class='form-control'";
1898 if ($restype == "not_applicable".$field_id) {
1899 echo " checked";
1902 echo " />".htmlspecialchars(xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1903 echo "</tr>";
1904 echo "</table>";
1905 } // static text. read-only, of course.
1906 else if ($data_type == 31) {
1907 echo parse_static_text($frow);
1908 } else if ($data_type == 34) {
1909 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc, ENT_QUOTES)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1910 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1911 echo "<div style='display:none'><textarea name='form_{$field_id}' class='form-control' id='form_{$field_id}' stye='display:none'></textarea></div>";
1912 echo "</a>";
1913 } //facilities drop-down list
1914 else if ($data_type == 35) {
1915 // In this special case, fld_length is the number of columns generated.
1916 $cols = max(1, $frow['fld_length']);
1917 $lres = sqlStatement("SELECT id, name FROM facility ORDER BY name");
1918 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1919 $tdpct = (int) (100 / $cols);
1920 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1921 $option_id = $lrow['id'];
1922 if ($count % $cols == 0) {
1923 if ($count) {
1924 echo "</tr>";
1926 echo "<tr>";
1928 echo "<td width='" . attr($tdpct) . "%'>";
1929 echo "<input type='radio'";
1930 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1931 // Do not use defaults for these printable forms.
1932 echo " checked";
1934 echo ">" . htmlspecialchars($lrow['name']);
1935 echo "</td>";
1937 if ($count) {
1938 echo "</tr>";
1939 if ($count > $cols) {
1940 // Add some space after multiple rows of radio buttons.
1941 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1944 echo "</table>";
1945 } //Multi-select
1946 // Supports backup lists.
1947 else if ($data_type == 36) {
1948 if (empty($fld_length)) {
1949 if ($list_id == 'titles') {
1950 $fld_length = 3;
1951 } else {
1952 $fld_length = 10;
1956 $tmp = '';
1958 $values_array = explode("|", $currvalue);
1960 $i=0;
1961 foreach ($values_array as $value) {
1962 if ($value) {
1963 $lrow = sqlQuery("SELECT title FROM list_options " .
1964 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1965 $tmp = xl_list_label($lrow['title']);
1966 if ($lrow == 0 && !empty($backup_list)) {
1967 // since primary list did not map, try to map to backup list
1968 $lrow = sqlQuery("SELECT title FROM list_options " .
1969 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1970 $tmp = xl_list_label($lrow['title']);
1973 if (empty($tmp)) {
1974 $tmp = "($value)";
1978 if ($tmp === '') {
1979 $tmp = '&nbsp;';
1980 } else {
1981 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1984 if ($i != 0 && $tmp != '&nbsp;') {
1985 echo ",";
1988 echo $tmp;
1989 $i++;
1991 } // Image from canvas drawing
1992 else if ($data_type == 40) {
1993 if ($currvalue) {
1994 echo "<img src='" . attr($currvalue) . "'>";
1999 function generate_display_field($frow, $currvalue)
2001 global $ISSUE_TYPES, $facilityService;
2003 $data_type = $frow['data_type'];
2004 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2005 $list_id = $frow['list_id'];
2006 $backup_list = isset($frow['list_backup_id']) ? $frow['list_backup_id'] : null;
2008 $s = '';
2010 // generic selection list or the generic selection list with add on the fly
2011 // feature
2012 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
2013 $lrow = sqlQuery("SELECT title FROM list_options " .
2014 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2015 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2016 //if there is no matching value in the corresponding lists check backup list
2017 // only supported in data types 1,26,33
2018 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2019 $lrow = sqlQuery("SELECT title FROM list_options " .
2020 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2021 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2023 } // simple text field
2024 else if ($data_type == 2) {
2025 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2026 } // long or multi-line text field
2027 else if ($data_type == 3) {
2028 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2029 } // date
2030 else if ($data_type == 4) {
2031 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
2032 $s = '';
2033 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2034 $age_asof_date = '';
2035 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
2036 if ($currvalue === '') {
2037 $s .= '&nbsp;';
2038 } else {
2039 $s .= text(oeFormatShortDate($currvalue));
2040 if ($agestr) {
2041 $s .= "&nbsp;(" . text($agestr) . ")";
2044 } // provider
2045 else if ($data_type == 10 || $data_type == 11) {
2046 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2047 "WHERE id = ?", array($currvalue));
2048 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']), ENT_NOQUOTES);
2049 } // pharmacy list
2050 else if ($data_type == 12) {
2051 $pres = get_pharmacies();
2052 while ($prow = sqlFetchArray($pres)) {
2053 $key = $prow['id'];
2054 if ($currvalue == $key) {
2055 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
2056 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2057 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
2060 } // squads
2061 else if ($data_type == 13) {
2062 $squads = acl_get_squads();
2063 if ($squads) {
2064 foreach ($squads as $key => $value) {
2065 if ($currvalue == $key) {
2066 $s .= htmlspecialchars($value[3], ENT_NOQUOTES);
2070 } // address book
2071 else if ($data_type == 14) {
2072 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
2073 "WHERE id = ?", array($currvalue));
2074 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
2075 if ($urow['organization'] !="") {
2076 $uname = $urow['organization'];
2077 } else {
2078 $uname = $urow['lname'];
2079 if ($urow['fname']) {
2080 $uname .= ", " . $urow['fname'];
2084 $s = htmlspecialchars($uname, ENT_NOQUOTES);
2085 } // billing code
2086 else if ($data_type == 15) {
2087 $s = '';
2088 if (!empty($currvalue)) {
2089 $relcodes = explode(';', $currvalue);
2090 foreach ($relcodes as $codestring) {
2091 if ($codestring === '') {
2092 continue;
2094 $tmp = lookup_code_descriptions($codestring);
2095 if ($s !== '') {
2096 $s .= '; ';
2098 if (!empty($tmp)) {
2099 $s .= $tmp;
2100 } else {
2101 $s .= $codestring . ' (' . xl('not found') . ')';
2105 } // insurance company list
2106 else if ($data_type == 16) {
2107 $insprovs = getInsuranceProviders();
2108 foreach ($insprovs as $key => $ipname) {
2109 if ($currvalue == $key) {
2110 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
2113 } // issue types
2114 else if ($data_type == 17) {
2115 foreach ($ISSUE_TYPES as $key => $value) {
2116 if ($currvalue == $key) {
2117 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
2120 } // visit category
2121 else if ($data_type == 18) {
2122 $crow = sqlQuery(
2123 "SELECT pc_catid, pc_catname " .
2124 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2125 array($currvalue)
2127 $s = htmlspecialchars($crow['pc_catname'], ENT_NOQUOTES);
2128 } // a single checkbox or set of labeled checkboxes
2129 else if ($data_type == 21) {
2130 if (!$list_id) {
2131 $s .= $currvalue ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2132 } else {
2133 // In this special case, fld_length is the number of columns generated.
2134 $cols = max(1, $frow['fld_length']);
2135 $avalue = explode('|', $currvalue);
2136 $lres = sqlStatement("SELECT * FROM list_options " .
2137 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2138 $s .= "<table cellspacing='0' cellpadding='0'>";
2139 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2140 $option_id = $lrow['option_id'];
2141 $option_id_esc = text($option_id);
2142 if ($count % $cols == 0) {
2143 if ($count) {
2144 $s .= "</tr>";
2146 $s .= "<tr>";
2148 $s .= "<td nowrap>";
2149 $checked = in_array($option_id, $avalue);
2150 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2151 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2152 $s .= "</td>";
2154 if ($count) {
2155 $s .= "</tr>";
2157 $s .= "</table>";
2159 } // a set of labeled text input fields
2160 else if ($data_type == 22) {
2161 $tmp = explode('|', $currvalue);
2162 $avalue = array();
2163 foreach ($tmp as $value) {
2164 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2165 $avalue[$matches[1]] = $matches[2];
2169 $lres = sqlStatement("SELECT * FROM list_options " .
2170 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2171 $s .= "<table cellpadding='0' cellspacing='0'>";
2172 while ($lrow = sqlFetchArray($lres)) {
2173 $option_id = $lrow['option_id'];
2174 if (empty($avalue[$option_id])) {
2175 continue;
2178 // Added 5-09 by BM - Translate label if applicable
2179 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . ":&nbsp;</td>";
2181 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id], ENT_NOQUOTES) . "</td></tr>";
2184 $s .= "</table>";
2185 } // a set of exam results; 3 radio buttons and a text field:
2186 else if ($data_type == 23) {
2187 $tmp = explode('|', $currvalue);
2188 $avalue = array();
2189 foreach ($tmp as $value) {
2190 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2191 $avalue[$matches[1]] = $matches[2];
2195 $lres = sqlStatement("SELECT * FROM list_options " .
2196 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2197 $s .= "<table cellpadding='0' cellspacing='0'>";
2198 while ($lrow = sqlFetchArray($lres)) {
2199 $option_id = $lrow['option_id'];
2200 $restype = substr($avalue[$option_id], 0, 1);
2201 $resnote = substr($avalue[$option_id], 2);
2202 if (empty($restype) && empty($resnote)) {
2203 continue;
2206 // Added 5-09 by BM - Translate label if applicable
2207 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2209 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
2210 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2211 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2212 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2213 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2214 $s .= "</tr>";
2217 $s .= "</table>";
2218 } // the list of active allergies for the current patient
2219 else if ($data_type == 24) {
2220 $query = "SELECT title, comments FROM lists WHERE " .
2221 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2222 "ORDER BY begdate";
2223 // echo "<!-- $query -->\n"; // debugging
2224 $lres = sqlStatement($query, array($GLOBALS['pid']));
2225 $count = 0;
2226 while ($lrow = sqlFetchArray($lres)) {
2227 if ($count++) {
2228 $s .= "<br />";
2231 $s .= htmlspecialchars($lrow['title'], ENT_NOQUOTES);
2232 if ($lrow['comments']) {
2233 $s .= ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
2236 } // a set of labeled checkboxes, each with a text field:
2237 else if ($data_type == 25) {
2238 $tmp = explode('|', $currvalue);
2239 $avalue = array();
2240 foreach ($tmp as $value) {
2241 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2242 $avalue[$matches[1]] = $matches[2];
2246 $lres = sqlStatement("SELECT * FROM list_options " .
2247 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2248 $s .= "<table cellpadding='0' cellspacing='0'>";
2249 while ($lrow = sqlFetchArray($lres)) {
2250 $option_id = $lrow['option_id'];
2251 $restype = substr($avalue[$option_id], 0, 1);
2252 $resnote = substr($avalue[$option_id], 2);
2253 if (empty($restype) && empty($resnote)) {
2254 continue;
2257 // Added 5-09 by BM - Translate label if applicable
2258 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2260 $restype = $restype ? xl('Yes') : xl('No');
2261 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2262 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2263 $s .= "</tr>";
2266 $s .= "</table>";
2267 } // a set of labeled radio buttons
2268 else if ($data_type == 27) {
2269 // In this special case, fld_length is the number of columns generated.
2270 $cols = max(1, $frow['fld_length']);
2271 $lres = sqlStatement("SELECT * FROM list_options " .
2272 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2273 $s .= "<table cellspacing='0' cellpadding='0'>";
2274 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2275 $option_id = $lrow['option_id'];
2276 $option_id_esc = text($option_id);
2277 if ($count % $cols == 0) {
2278 if ($count) {
2279 $s .= "</tr>";
2281 $s .= "<tr>";
2283 $s .= "<td>";
2284 $checked = ((strlen($currvalue) == 0 && $lrow['is_default']) ||
2285 (strlen($currvalue) > 0 && $option_id == $currvalue));
2286 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2287 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2288 $s .= "</td>";
2290 if ($count) {
2291 $s .= "</tr>";
2293 $s .= "</table>";
2294 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2295 // VicarePlus :: A selection list for smoking status.
2296 else if ($data_type == 28 || $data_type == 32) {
2297 $tmp = explode('|', $currvalue);
2298 switch (count($tmp)) {
2299 case "4":
2300 $resnote = $tmp[0];
2301 $restype = $tmp[1];
2302 $resdate = $tmp[2];
2303 $reslist = $tmp[3];
2304 break;
2305 case "3":
2306 $resnote = $tmp[0];
2307 $restype = $tmp[1];
2308 $resdate = $tmp[2];
2309 break;
2310 case "2":
2311 $resnote = $tmp[0];
2312 $restype = $tmp[1];
2313 $resdate = "";
2314 break;
2315 case "1":
2316 $resnote = $tmp[0];
2317 $resdate = $restype = "";
2318 break;
2319 default:
2320 $restype = $resdate = $resnote = "";
2321 break;
2324 $s .= "<table cellpadding='0' cellspacing='0'>";
2326 $s .= "<tr>";
2327 $res = "";
2328 if ($restype == "current".$field_id) {
2329 $res = xl('Current');
2332 if ($restype == "quit".$field_id) {
2333 $res = xl('Quit');
2336 if ($restype == "never".$field_id) {
2337 $res = xl('Never');
2340 if ($restype == "not_applicable".$field_id) {
2341 $res = xl('N/A');
2344 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2345 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2346 if ($data_type == 28) {
2347 if (!empty($resnote)) {
2348 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2350 } //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2351 else if ($data_type == 32) {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2352 $smoke_codes = getSmokeCodes();
2353 if (!empty($reslist)) {
2354 if ($smoke_codes[$reslist]!="") {
2355 $code_desc = "( ".$smoke_codes[$reslist]." )";
2358 $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist) . "&nbsp;".text($code_desc)."&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2361 if (!empty($resnote)) {
2362 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2366 if (!empty($res)) {
2367 $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'), ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res, ENT_NOQUOTES) . "&nbsp;</td>";
2370 if ($restype == "quit".$field_id) {
2371 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate, ENT_NOQUOTES) . "&nbsp;</td>";
2374 $s .= "</tr>";
2375 $s .= "</table>";
2376 } // static text. read-only, of course.
2377 else if ($data_type == 31) {
2378 $s .= parse_static_text($frow);
2379 } else if ($data_type == 34) {
2380 $arr = explode("|*|*|*|", $currvalue);
2381 for ($i=0; $i<sizeof($arr); $i++) {
2382 $s.=$arr[$i];
2384 } // facility
2385 else if ($data_type == 35) {
2386 $urow = $facilityService->getById($currvalue);
2387 $s = htmlspecialchars($urow['name'], ENT_NOQUOTES);
2388 } // Multi select
2389 // Supports backup lists
2390 else if ($data_type == 36) {
2391 $values_array = explode("|", $currvalue);
2392 $i = 0;
2393 foreach ($values_array as $value) {
2394 $lrow = sqlQuery("SELECT title FROM list_options " .
2395 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2396 if ($lrow == 0 && !empty($backup_list)) {
2397 //use back up list
2398 $lrow = sqlQuery("SELECT title FROM list_options " .
2399 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2402 if ($i > 0) {
2403 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2404 } else {
2405 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2408 $i++;
2410 } // Image from canvas drawing
2411 else if ($data_type == 40) {
2412 if ($currvalue) {
2413 $s .= "<img src='" . attr($currvalue) . "'>";
2417 return $s;
2420 // Generate plain text versions of selected LBF field types.
2421 // Currently used by interface/patient_file/download_template.php.
2422 // More field types might need to be supported here in the future.
2424 function generate_plaintext_field($frow, $currvalue)
2426 global $ISSUE_TYPES;
2428 $data_type = $frow['data_type'];
2429 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2430 $list_id = $frow['list_id'];
2431 $backup_list = $frow['backup_list'];
2432 $s = '';
2434 // generic selection list or the generic selection list with add on the fly
2435 // feature, or radio buttons
2436 // Supports backup lists (for datatypes 1,26,33)
2437 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2438 $lrow = sqlQuery("SELECT title FROM list_options " .
2439 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2440 $s = xl_list_label($lrow['title']);
2441 //if there is no matching value in the corresponding lists check backup list
2442 // only supported in data types 1,26,33
2443 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2444 $lrow = sqlQuery("SELECT title FROM list_options " .
2445 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2446 $s = xl_list_label($lrow['title']);
2448 } // simple or long text field
2449 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2450 $s = $currvalue;
2451 } // date
2452 else if ($data_type == 4) {
2453 $s = oeFormatShortDate($currvalue);
2454 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2455 $age_asof_date = '';
2456 // Optional display of age or gestational age.
2457 $tmp = optionalAge($frow, $currvalue, $age_asof_date, $description);
2458 if ($tmp) {
2459 $s .= ' ' . $tmp;
2461 } // provider
2462 else if ($data_type == 10 || $data_type == 11) {
2463 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2464 "WHERE id = ?", array($currvalue));
2465 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2466 } // pharmacy list
2467 else if ($data_type == 12) {
2468 $pres = get_pharmacies();
2469 while ($prow = sqlFetchArray($pres)) {
2470 $key = $prow['id'];
2471 if ($currvalue == $key) {
2472 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2473 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2474 $prow['line1'] . ' / ' . $prow['city'];
2477 } // address book
2478 else if ($data_type == 14) {
2479 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2480 "WHERE id = ?", array($currvalue));
2481 $uname = $urow['lname'];
2482 if ($urow['fname']) {
2483 $uname .= ", " . $urow['fname'];
2486 $s = $uname;
2487 } // insurance company list
2488 else if ($data_type == 16) {
2489 $insprovs = getInsuranceProviders();
2490 foreach ($insprovs as $key => $ipname) {
2491 if ($currvalue == $key) {
2492 $s .= $ipname;
2495 } // issue type
2496 else if ($data_type == 17) {
2497 foreach ($ISSUE_TYPES as $key => $value) {
2498 if ($currvalue == $key) {
2499 $s .= $value[1];
2502 } // visit category
2503 else if ($data_type == 18) {
2504 $crow = sqlQuery(
2505 "SELECT pc_catid, pc_catname " .
2506 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2507 array($currvalue)
2509 $s = $crow['pc_catname'];
2510 } // a set of labeled checkboxes
2511 else if ($data_type == 21) {
2512 if (!$list_id) {
2513 $s .= $currvalue ? xlt('Yes') : xlt('No');
2514 } else {
2515 $avalue = explode('|', $currvalue);
2516 $lres = sqlStatement("SELECT * FROM list_options " .
2517 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2518 $count = 0;
2519 while ($lrow = sqlFetchArray($lres)) {
2520 $option_id = $lrow['option_id'];
2521 if (in_array($option_id, $avalue)) {
2522 if ($count++) {
2523 $s .= "; ";
2525 $s .= xl_list_label($lrow['title']);
2529 } // a set of labeled text input fields
2530 else if ($data_type == 22) {
2531 $tmp = explode('|', $currvalue);
2532 $avalue = array();
2533 foreach ($tmp as $value) {
2534 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2535 $avalue[$matches[1]] = $matches[2];
2539 $lres = sqlStatement("SELECT * FROM list_options " .
2540 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2541 while ($lrow = sqlFetchArray($lres)) {
2542 $option_id = $lrow['option_id'];
2543 if (empty($avalue[$option_id])) {
2544 continue;
2547 if ($s !== '') {
2548 $s .= '; ';
2551 $s .= xl_list_label($lrow['title']) . ': ';
2552 $s .= $avalue[$option_id];
2554 } // A set of exam results; 3 radio buttons and a text field.
2555 // This shows abnormal results only.
2556 else if ($data_type == 23) {
2557 $tmp = explode('|', $currvalue);
2558 $avalue = array();
2559 foreach ($tmp as $value) {
2560 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2561 $avalue[$matches[1]] = $matches[2];
2565 $lres = sqlStatement("SELECT * FROM list_options " .
2566 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2567 while ($lrow = sqlFetchArray($lres)) {
2568 $option_id = $lrow['option_id'];
2569 $restype = substr($avalue[$option_id], 0, 1);
2570 $resnote = substr($avalue[$option_id], 2);
2571 if (empty($restype) && empty($resnote)) {
2572 continue;
2575 if ($restype != '2') {
2576 continue; // show abnormal results only
2579 if ($s !== '') {
2580 $s .= '; ';
2583 $s .= xl_list_label($lrow['title']);
2584 if (!empty($resnote)) {
2585 $s .= ': ' . $resnote;
2588 } // the list of active allergies for the current patient
2589 else if ($data_type == 24) {
2590 $query = "SELECT title, comments FROM lists WHERE " .
2591 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2592 "ORDER BY begdate";
2593 $lres = sqlStatement($query, array($GLOBALS['pid']));
2594 $count = 0;
2595 while ($lrow = sqlFetchArray($lres)) {
2596 if ($count++) {
2597 $s .= "; ";
2600 $s .= $lrow['title'];
2601 if ($lrow['comments']) {
2602 $s .= ' (' . $lrow['comments'] . ')';
2605 } // a set of labeled checkboxes, each with a text field:
2606 else if ($data_type == 25) {
2607 $tmp = explode('|', $currvalue);
2608 $avalue = array();
2609 foreach ($tmp as $value) {
2610 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2611 $avalue[$matches[1]] = $matches[2];
2615 $lres = sqlStatement("SELECT * FROM list_options " .
2616 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2617 while ($lrow = sqlFetchArray($lres)) {
2618 $option_id = $lrow['option_id'];
2619 $restype = substr($avalue[$option_id], 0, 1);
2620 $resnote = substr($avalue[$option_id], 2);
2621 if (empty($restype) && empty($resnote)) {
2622 continue;
2625 if ($s !== '') {
2626 $s .= '; ';
2629 $s .= xl_list_label($lrow['title']);
2630 $restype = $restype ? xl('Yes') : xl('No');
2631 $s .= $restype;
2632 if ($resnote) {
2633 $s .= ' ' . $resnote;
2636 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2637 // VicarePlus :: A selection list for smoking status.
2638 else if ($data_type == 28 || $data_type == 32) {
2639 $tmp = explode('|', $currvalue);
2640 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2641 $restype = count($tmp) > 1 ? $tmp[1] : '';
2642 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2643 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2644 $res = "";
2645 if ($restype == "current" . $field_id) {
2646 $res = xl('Current');
2649 if ($restype == "quit" . $field_id) {
2650 $res = xl('Quit');
2653 if ($restype == "never" . $field_id) {
2654 $res = xl('Never');
2657 if ($restype == "not_applicable". $field_id) {
2658 $res = xl('N/A');
2661 if ($data_type == 28) {
2662 if (!empty($resnote)) {
2663 $s .= $resnote;
2665 } // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2666 else if ($data_type == 32) {
2667 if (!empty($reslist)) {
2668 $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
2671 if (!empty($resnote)) {
2672 $s .= ' ' . $resnote;
2676 if (!empty($res)) {
2677 if ($s !== '') {
2678 $s .= ' ';
2681 $s .= xl('Status') . ' ' . $res;
2684 if ($restype == "quit".$field_id) {
2685 if ($s !== '') {
2686 $s .= ' ';
2689 $s .= $resdate;
2691 } // Multi select
2692 // Supports backup lists
2693 else if ($data_type == 36) {
2694 $values_array = explode("|", $currvalue);
2696 $i = 0;
2697 foreach ($values_array as $value) {
2698 $lrow = sqlQuery("SELECT title FROM list_options " .
2699 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2701 if ($lrow == 0 && !empty($backup_list)) {
2702 //use back up list
2703 $lrow = sqlQuery("SELECT title FROM list_options " .
2704 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2707 if ($i > 0) {
2708 $s = $s . ", " . xl_list_label($lrow['title']);
2709 } else {
2710 $s = xl_list_label($lrow['title']);
2713 $i++;
2717 return $s;
2720 $CPR = 4; // cells per row of generic data
2721 $last_group = '';
2722 $cell_count = 0;
2723 $item_count = 0;
2725 function disp_end_cell()
2727 global $item_count, $cell_count;
2728 if ($item_count > 0) {
2729 echo "</td>";
2730 $item_count = 0;
2734 function disp_end_row()
2736 global $cell_count, $CPR;
2737 disp_end_cell();
2738 if ($cell_count > 0) {
2739 for (; $cell_count < $CPR;
2740 ++$cell_count) {
2741 echo "<td></td>";
2744 echo "</tr>\n";
2745 $cell_count = 0;
2749 function disp_end_group()
2751 global $last_group;
2752 if (strlen($last_group) > 0) {
2753 disp_end_row();
2757 // Accumulate action conditions into a JSON expression for the browser side.
2758 function accumActionConditions($field_id, &$condition_str, &$condarr)
2760 $conditions = empty($condarr) ? array() : unserialize($condarr);
2761 $action = 'skip';
2762 foreach ($conditions as $key => $condition) {
2763 if ($key === 'action') {
2764 // If specified this should be the first array item.
2765 if ($condition) {
2766 $action = $condition;
2768 continue;
2770 if (empty($condition['id'])) {
2771 continue;
2773 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2774 if ($condition_str) {
2775 $condition_str .= ",\n";
2777 $condition_str .= "{" .
2778 "target:'" . addslashes($field_id) . "', " .
2779 "action:'" . addslashes($action) . "', " .
2780 "id:'" . addslashes($condition['id']) . "', " .
2781 "itemid:'" . addslashes($condition['itemid']) . "', " .
2782 "operator:'" . addslashes($condition['operator']) . "', " .
2783 "value:'" . addslashes($condition['value']) . "', " .
2784 "andor:'" . addslashes($andor) . "'}";
2788 // This checks if the given field with the given value should have an action applied.
2789 // Originally the only action was skip, but now you can also set the field to a specified value.
2790 // It somewhat mirrors the checkSkipConditions function in options.js.php.
2791 // If you use this for multiple layouts in the same script, you should
2792 // clear $sk_layout_items before each layout.
2793 function isSkipped(&$frow, $currvalue)
2795 global $sk_layout_items;
2797 // Accumulate an array of the encountered fields and their values.
2798 // It is assumed that fields appear before they are tested by another field.
2799 // TBD: Bad assumption?
2800 $field_id = $frow['field_id'];
2801 if (!is_array($sk_layout_items)) {
2802 $sk_layout_items = array();
2804 $sk_layout_items[$field_id] = array('row' => $frow, 'value' => $currvalue);
2806 if (empty($frow['conditions'])) {
2807 return false;
2810 $skiprows = unserialize($frow['conditions']);
2811 $prevandor = '';
2812 $prevcond = false;
2813 $datatype = $frow['data_type'];
2814 $action = 'skip'; // default action if none specified
2816 foreach ($skiprows as $key => $skiprow) {
2817 // id referenced field id
2818 // itemid referenced array key if applicable
2819 // operator "eq", "ne", "se" or "ns"
2820 // value if eq or ne, some string to compare with
2821 // andor "and", "or" or empty
2823 if ($key === 'action') {
2824 // Action value is a string. It can be "skip", or "value=" followed by a value.
2825 $action = $skiprow;
2826 continue;
2829 if (empty($skiprow['id'])) {
2830 continue;
2833 $id = $skiprow['id'];
2834 if (!isset($sk_layout_items[$id])) {
2835 error_log("Function isSkipped() cannot find skip source field '$id'.");
2836 continue;
2838 $itemid = $skiprow['itemid'];
2839 $operator = $skiprow['operator'];
2840 $skipval = $skiprow['value'];
2841 $srcvalue = $sk_layout_items[$id]['value'];
2842 $src_datatype = $sk_layout_items[$id]['row']['data_type'];
2843 $src_list_id = $sk_layout_items[$id]['row']['list_id'];
2845 // Some data types use itemid and we have to dig for their value.
2846 if ($src_datatype == 21 && $src_list_id) { // array of checkboxes
2847 $tmp = explode('|', $srcvalue);
2848 $srcvalue = in_array($itemid, $tmp);
2849 } else if ($src_datatype == 22 || $src_datatype == 23 || $src_datatype == 25) {
2850 $tmp = explode('|', $srcvalue);
2851 $srcvalue = '';
2852 foreach ($tmp as $tmp2) {
2853 if (strpos($tmp2, "$itemid:") === 0) {
2854 if ($datatype == 22) {
2855 $srcvalue = substr($tmp2, strlen($itemid) + 1);
2856 } else {
2857 $srcvalue = substr($tmp2, strlen($itemid) + 1, 1);
2863 // Compute the result of the test for this condition row.
2864 // PHP's looseness with variable type conversion helps us here.
2865 $condition = false;
2866 if ($operator == 'eq') {
2867 $condition = $srcvalue == $skipval;
2868 } else if ($operator == 'ne') {
2869 $condition = $srcvalue != $skipval;
2870 } else if ($operator == 'se') {
2871 $condition = $srcvalue == true;
2872 } else if ($operator == 'ns') {
2873 $condition = $srcvalue != true;
2874 } else {
2875 error_log("Unknown skip operator '$operator' for field '$field_id'.");
2878 // Logic to accumulate multiple conditions for the same target.
2879 if ($prevandor == 'and') {
2880 $condition = $condition && $prevcond;
2881 } else if ($prevandor == 'or') {
2882 $condition = $condition || $prevcond;
2884 $prevandor = $skiprow['andor'];
2885 $prevcond = $condition;
2887 return $prevcond ? $action : '';
2890 // Load array of names of the given layout and its groups.
2891 function getLayoutProperties($formtype, &$grparr, $sel = "grp_title")
2893 if ($sel != '*' && strpos($sel, 'grp_group_id') === false) {
2894 $sel = "grp_group_id, $sel";
2896 $gres = sqlStatement("SELECT $sel FROM layout_group_properties WHERE grp_form_id = ? " .
2897 "ORDER BY grp_group_id", array($formtype));
2898 while ($grow = sqlFetchArray($gres)) {
2899 $grparr[$grow['grp_group_id']] = $grow;
2903 function display_layout_rows($formtype, $result1, $result2 = '')
2905 global $item_count, $cell_count, $last_group, $CPR;
2907 $grparr = array();
2908 getLayoutProperties($formtype, $grparr, '*');
2910 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
2912 $fres = sqlStatement("SELECT * FROM layout_options " .
2913 "WHERE form_id = ? AND uor > 0 " .
2914 "ORDER BY group_id, seq", array($formtype));
2916 while ($frow = sqlFetchArray($fres)) {
2917 $this_group = $frow['group_id'];
2918 $titlecols = $frow['titlecols'];
2919 $datacols = $frow['datacols'];
2920 $data_type = $frow['data_type'];
2921 $field_id = $frow['field_id'];
2922 $list_id = $frow['list_id'];
2923 $currvalue = '';
2925 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
2927 if ($formtype == 'DEM') {
2928 if (strpos($field_id, 'em_') === 0) {
2929 // Skip employer related fields, if it's disabled.
2930 if ($GLOBALS['omit_employers']) {
2931 continue;
2934 $tmp = substr($field_id, 3);
2935 if (isset($result2[$tmp])) {
2936 $currvalue = $result2[$tmp];
2938 } else {
2939 if (isset($result1[$field_id])) {
2940 $currvalue = $result1[$field_id];
2943 } else {
2944 if (isset($result1[$field_id])) {
2945 $currvalue = $result1[$field_id];
2949 // Handle a data category (group) change.
2950 if (strcmp($this_group, $last_group) != 0) {
2951 $group_name = $grparr[$this_group]['grp_title'];
2952 // totally skip generating the employer category, if it's disabled.
2953 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
2954 continue;
2957 disp_end_group();
2958 $last_group = $this_group;
2961 // filter out all the empty field data from the patient report.
2962 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2963 // Handle starting of a new row.
2964 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2965 disp_end_row();
2966 echo "<tr>";
2967 if ($group_name) {
2968 echo "<td class='groupname'>";
2969 echo text(xl_layout_label($group_name));
2970 $group_name = '';
2971 } else {
2972 echo "<td valign='top'>&nbsp;";
2975 echo "</td>";
2978 if ($item_count == 0 && $titlecols == 0) {
2979 $titlecols = 1;
2982 // Handle starting of a new label cell.
2983 if ($titlecols > 0) {
2984 disp_end_cell();
2985 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
2986 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
2987 echo "<td class='label_custom' colspan='$titlecols_esc' ";
2988 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2989 echo ">";
2990 $cell_count += $titlecols;
2993 ++$item_count;
2995 // Added 5-09 by BM - Translate label if applicable
2996 if ($frow['title']) {
2997 $tmp = xl_layout_label($frow['title']);
2998 echo text($tmp);
2999 // Append colon only if label does not end with punctuation.
3000 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3001 echo ':';
3003 } else {
3004 echo "&nbsp;";
3007 // Handle starting of a new data cell.
3008 if ($datacols > 0) {
3009 disp_end_cell();
3010 //echo "<td class='text data' colspan='$datacols' valign='top'";
3011 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3012 echo "<td class='text data' colspan='$datacols_esc'";
3013 //if ($cell_count > 0) echo " style='padding-left:5pt'";
3014 echo ">";
3015 $cell_count += $datacols;
3018 ++$item_count;
3019 echo generate_display_field($frow, $currvalue);
3023 disp_end_group();
3026 function display_layout_tabs($formtype, $result1, $result2 = '')
3028 global $item_count, $cell_count, $last_group, $CPR;
3030 $grparr = array();
3031 getLayoutProperties($formtype, $grparr);
3033 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3034 "WHERE form_id = ? AND uor > 0 " .
3035 "ORDER BY group_id", array($formtype));
3037 $first = true;
3038 while ($frow = sqlFetchArray($fres)) {
3039 $this_group = $frow['group_id'];
3040 // $group_name = substr($this_group, 1);
3041 $group_name = $grparr[$this_group]['grp_title'];
3042 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3043 continue;
3046 <li <?php echo $first ? 'class="current"' : '' ?>>
3047 <a href="#" id="header_tab_<?php echo htmlspecialchars($group_name, ENT_QUOTES); ?>">
3048 <?php echo htmlspecialchars(xl_layout_label($group_name), ENT_NOQUOTES); ?></a>
3049 </li>
3050 <?php
3051 $first = false;
3055 function display_layout_tabs_data($formtype, $result1, $result2 = '')
3057 global $item_count, $cell_count, $last_group, $CPR;
3059 $grparr = array();
3060 getLayoutProperties($formtype, $grparr, '*');
3062 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3064 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3065 "WHERE form_id = ? AND uor > 0 " .
3066 "ORDER BY group_id", array($formtype));
3068 $first = true;
3069 while ($frow = sqlFetchArray($fres)) {
3070 $this_group = isset($frow['group_id']) ? $frow['group_id'] : "" ;
3072 if ($grparr[$this_group]['grp_columns'] === 'Employer' && $GLOBALS['omit_employers']) {
3073 continue;
3075 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3076 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : $grparr[$this_group]['grp_subtitle'];
3078 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3079 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3080 "ORDER BY seq", array($formtype, $this_group));
3083 <div class="tab <?php echo $first ? 'current' : '' ?>">
3084 <table border='0' cellpadding='0'>
3086 <?php
3087 while ($group_fields = sqlFetchArray($group_fields_query)) {
3088 $titlecols = $group_fields['titlecols'];
3089 $datacols = $group_fields['datacols'];
3090 $data_type = $group_fields['data_type'];
3091 $field_id = $group_fields['field_id'];
3092 $list_id = $group_fields['list_id'];
3093 $currvalue = '';
3094 $edit_options = $group_fields['edit_options'];
3096 if ($formtype == 'DEM') {
3097 if (strpos($field_id, 'em_') === 0) {
3098 // Skip employer related fields, if it's disabled.
3099 if ($GLOBALS['omit_employers']) {
3100 continue;
3103 $tmp = substr($field_id, 3);
3104 if (isset($result2[$tmp])) {
3105 $currvalue = $result2[$tmp];
3107 } else {
3108 if (isset($result1[$field_id])) {
3109 $currvalue = $result1[$field_id];
3112 } else {
3113 if (isset($result1[$field_id])) {
3114 $currvalue = $result1[$field_id];
3118 // Skip this field if action conditions call for that.
3119 // Note this also accumulates info for subsequent skip tests.
3120 $skip_this_field = isSkipped($group_fields, $currvalue) == 'skip';
3122 // Skip this field if its do-not-print option is set.
3123 if (strpos($edit_options, 'X') !== false) {
3124 $skip_this_field = true;
3127 // Handle a data category (group) change.
3128 if (strcmp($this_group, $last_group) != 0) {
3129 $group_name = $grparr[$this_group]['grp_title'];
3130 // totally skip generating the employer category, if it's disabled.
3131 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3132 continue;
3134 $last_group = $this_group;
3137 // Handle starting of a new row.
3138 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
3139 disp_end_row();
3140 if ($subtitle) {
3141 // Group subtitle exists and is not displayed yet.
3142 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3143 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3144 $subtitle = '';
3146 echo "<tr>";
3149 if ($item_count == 0 && $titlecols == 0) {
3150 $titlecols = 1;
3153 // Handle starting of a new label cell.
3154 if ($titlecols > 0) {
3155 disp_end_cell();
3156 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3157 $field_id_label = 'label_'.$group_fields['field_id'];
3158 echo "<td class='label_custom' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
3159 echo ">";
3160 $cell_count += $titlecols;
3163 ++$item_count;
3165 $field_id_label = 'label_'.$group_fields['field_id'];
3166 echo "<span id='".attr($field_id_label)."'>";
3167 if ($skip_this_field) {
3168 // No label because skipping
3169 } else if ($group_fields['title']) {
3170 $tmp = xl_layout_label($group_fields['title']);
3171 echo text($tmp);
3172 // Append colon only if label does not end with punctuation.
3173 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3174 echo ':';
3176 } else {
3177 echo "&nbsp;";
3179 echo "</span>";
3181 // Handle starting of a new data cell.
3182 if ($datacols > 0) {
3183 disp_end_cell();
3184 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3185 $field_id = 'text_'.$group_fields['field_id'];
3186 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
3187 if (!$skip_this_field && $data_type == 3) {
3188 // Textarea gets a light grey border.
3189 echo " style='border:1px solid #cccccc'";
3191 echo ">";
3192 $cell_count += $datacols;
3193 } else {
3194 $field_id = 'text_'.$group_fields['field_id'];
3195 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
3198 ++$item_count;
3199 if (!$skip_this_field) {
3200 echo generate_display_field($group_fields, $currvalue);
3204 disp_end_row();
3207 </table>
3208 </div>
3210 <?php
3212 $first = false;
3216 function display_layout_tabs_data_editable($formtype, $result1, $result2 = '')
3218 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
3220 $grparr = array();
3221 getLayoutProperties($formtype, $grparr, '*');
3223 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3225 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3226 "WHERE form_id = ? AND uor > 0 " .
3227 "ORDER BY group_id", array($formtype));
3229 $first = true;
3230 $condition_str = '';
3232 while ($frow = sqlFetchArray($fres)) {
3233 $this_group = $frow['group_id'];
3234 $group_name = $grparr[$this_group]['grp_title'];
3235 $group_name_esc = text($group_name);
3237 if ($grparr[$this_group]['grp_title'] === 'Employer' && $GLOBALS['omit_employers']) {
3238 continue;
3240 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3241 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : $grparr[$this_group]['grp_subtitle'];
3243 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3244 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3245 "ORDER BY seq", array($formtype, $this_group));
3248 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_', $group_name_esc)?>" >
3249 <table border='0' cellpadding='0'>
3251 <?php
3252 while ($group_fields = sqlFetchArray($group_fields_query)) {
3253 $titlecols = $group_fields['titlecols'];
3254 $datacols = $group_fields['datacols'];
3255 $data_type = $group_fields['data_type'];
3256 $field_id = $group_fields['field_id'];
3257 $list_id = $group_fields['list_id'];
3258 $backup_list = $group_fields['list_backup_id'];
3259 $currvalue = '';
3260 $action = 'skip';
3262 // Accumulate action conditions into a JSON expression for the browser side.
3263 accumActionConditions($field_id, $condition_str, $group_fields['conditions']);
3265 if ($formtype == 'DEM') {
3266 if (strpos($field_id, 'em_') === 0) {
3267 // Skip employer related fields, if it's disabled.
3268 if ($GLOBALS['omit_employers']) {
3269 continue;
3272 $tmp = substr($field_id, 3);
3273 if (isset($result2[$tmp])) {
3274 $currvalue = $result2[$tmp];
3276 } else {
3277 if (isset($result1[$field_id])) {
3278 $currvalue = $result1[$field_id];
3281 } else {
3282 if (isset($result1[$field_id])) {
3283 $currvalue = $result1[$field_id];
3287 // Handle a data category (group) change.
3288 if (strcmp($this_group, $last_group) != 0) {
3289 // totally skip generating the employer category, if it's disabled.
3290 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3291 continue;
3294 $last_group = $this_group;
3297 // Handle starting of a new row.
3298 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
3299 disp_end_row();
3300 if ($subtitle) {
3301 // Group subtitle exists and is not displayed yet.
3302 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3303 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3304 $subtitle = '';
3306 echo "<tr>";
3309 if ($item_count == 0 && $titlecols == 0) {
3310 $titlecols = 1;
3313 // Handle starting of a new label cell.
3314 if ($titlecols > 0) {
3315 disp_end_cell();
3316 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3317 $field_id_label = 'label_'.$group_fields['field_id'];
3318 echo "<td class='label_custom' colspan='$titlecols_esc'";
3319 // This ID is used by skip conditions.
3320 echo " id='label_id_" . attr($field_id) . "'";
3321 echo ">";
3322 $cell_count += $titlecols;
3325 ++$item_count;
3327 if ($group_fields['title']) {
3328 $tmp = xl_layout_label($group_fields['title']);
3329 echo text($tmp);
3330 // Append colon only if label does not end with punctuation.
3331 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3332 echo ':';
3334 } else {
3335 echo "&nbsp;";
3338 // Handle starting of a new data cell.
3339 if ($datacols > 0) {
3340 disp_end_cell();
3341 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3342 $field_id = 'text_'.$group_fields['field_id'];
3343 echo "<td class='text data' colspan='$datacols_esc'";
3344 // This ID is used by action conditions.
3345 echo " id='value_id_" . attr($field_id) . "'";
3346 echo ">";
3347 $cell_count += $datacols;
3350 ++$item_count;
3352 echo generate_form_field($group_fields, $currvalue);
3356 </table>
3357 </div>
3359 <?php
3361 $first = false;
3365 // From the currently posted HTML form, this gets the value of the
3366 // field corresponding to the provided layout_options table row.
3368 function get_layout_form_value($frow, $prefix = 'form_')
3370 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
3371 $data_type = $frow['data_type'];
3372 $field_id = $frow['field_id'];
3373 $value = '';
3374 if (isset($_POST["$prefix$field_id"])) {
3375 if ($data_type == 21) {
3376 if (!$frow['list_id']) {
3377 if (!empty($_POST["form_$field_id"])) {
3378 $value = xlt('Yes');
3380 } else {
3381 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
3382 // must be concatenated into a |-separated string.
3383 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3384 if (strlen($value)) {
3385 $value .= '|';
3387 $value .= $key;
3390 } else if ($data_type == 22) {
3391 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
3392 // into "key:value|key:value|...".
3393 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3394 $val = str_replace('|', ' ', $val);
3395 if (strlen($value)) {
3396 $value .= '|';
3399 $value .= "$key:$val";
3401 } else if ($data_type == 23) {
3402 // $_POST["$prefix$field_id"] is an array of text fields with companion
3403 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
3404 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3405 $restype = $_POST["radio_{$field_id}"][$key];
3406 if (empty($restype)) {
3407 $restype = '0';
3410 $val = str_replace('|', ' ', $val);
3411 if (strlen($value)) {
3412 $value .= '|';
3415 $value .= "$key:$restype:$val";
3417 } else if ($data_type == 25) {
3418 // $_POST["$prefix$field_id"] is an array of text fields with companion
3419 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
3420 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3421 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
3422 $val = str_replace('|', ' ', $val);
3423 if (strlen($value)) {
3424 $value .= '|';
3427 $value .= "$key:$restype:$val";
3429 } else if ($data_type == 28 || $data_type == 32) {
3430 // $_POST["$prefix$field_id"] is an date text fields with companion
3431 // radio buttons to be imploded into "notes|type|date".
3432 $restype = $_POST["radio_{$field_id}"];
3433 if (empty($restype)) {
3434 $restype = '0';
3437 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
3438 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3439 if ($data_type == 32) {
3440 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
3441 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3442 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
3443 $value = "$res_text_note|$restype|$resdate|$reslist";
3444 } else {
3445 $value = "$resnote|$restype|$resdate";
3447 } else if ($data_type == 36) {
3448 $value_array = $_POST["form_$field_id"];
3449 $i = 0;
3450 foreach ($value_array as $key => $valueofkey) {
3451 if ($i == 0) {
3452 $value = $valueofkey;
3453 } else {
3454 $value = $value . "|" . $valueofkey;
3457 $i++;
3459 } else {
3460 $value = $_POST["$prefix$field_id"];
3464 // Better to die than to silently truncate data!
3465 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength) {
3466 die(htmlspecialchars(xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
3467 ":<br />&nbsp;<br />".htmlspecialchars($value, ENT_NOQUOTES));
3470 return trim($value);
3473 // Generate JavaScript validation logic for the required fields.
3475 function generate_layout_validation($form_id)
3477 $fres = sqlStatement("SELECT * FROM layout_options " .
3478 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
3479 "ORDER BY group_id, seq", array($form_id));
3481 while ($frow = sqlFetchArray($fres)) {
3482 $data_type = $frow['data_type'];
3483 $field_id = $frow['field_id'];
3484 $fldtitle = $frow['title'];
3485 if (!$fldtitle) {
3486 $fldtitle = $frow['description'];
3489 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES);
3491 if ($data_type == 40) {
3492 $fldid = addslashes("form_$field_id");
3493 // Move canvas image data to its hidden form field so the server will get it.
3494 echo
3495 " var canfld = f['$fldid'];\n" .
3496 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
3497 continue;
3500 if ($frow['uor'] < 2) {
3501 continue;
3504 echo " if (f.$fldname && !f.$fldname.disabled) {\n";
3505 switch ($data_type) {
3506 case 1:
3507 case 11:
3508 case 12:
3509 case 13:
3510 case 14:
3511 case 26:
3512 echo
3513 " if (f.$fldname.selectedIndex <= 0) {\n" .
3514 " alert(\"" . addslashes(xl('Please choose a value for')) .
3515 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3516 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3517 " return false;\n" .
3518 " }\n";
3519 break;
3520 case 33:
3521 echo
3522 " if (f.$fldname.selectedIndex <= 0) {\n" .
3523 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3524 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3525 " }\n";
3526 break;
3527 case 27: // radio buttons
3528 echo
3529 " var i = 0;\n" .
3530 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
3531 " if (i >= f.$fldname.length) {\n" .
3532 " alert(\"" . addslashes(xl('Please choose a value for')) .
3533 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3534 " return false;\n" .
3535 " }\n";
3536 break;
3537 case 2:
3538 case 3:
3539 case 4:
3540 case 15:
3541 echo
3542 " if (trimlen(f.$fldname.value) == 0) {\n" .
3543 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3544 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
3545 " $('#" . $fldname . "').attr('style','background:red'); \n" .
3546 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3547 " } else { " .
3548 " $('#" . $fldname . "').attr('style',''); " .
3549 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
3550 " } \n";
3551 break;
3552 case 36: // multi select
3553 echo
3554 " var multi_select=f['$fldname"."[]']; \n " .
3555 " var multi_choice_made=false; \n".
3556 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
3557 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
3558 " } \n" .
3559 " if(!multi_choice_made)
3560 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3562 break;
3564 echo " }\n";
3569 * DROPDOWN FOR FACILITIES
3571 * build a dropdown with all facilities
3573 * @param string $selected - name of the currently selected facility
3574 * use '0' for "unspecified facility"
3575 * use '' for "All facilities" (the default)
3576 * @param string $name - the name/id for select form (defaults to "form_facility")
3577 * @param boolean $allow_unspecified - include an option for "unspecified" facility
3578 * defaults to true
3579 * @return void - just echo the html encoded string
3581 * Note: This should become a data-type at some point, according to Brady
3583 function dropdown_facility(
3584 $selected = '',
3585 $name = 'form_facility',
3586 $allow_unspecified = true,
3587 $allow_allfacilities = true,
3588 $disabled = '',
3589 $onchange = ''
3592 global $facilityService;
3594 $have_selected = false;
3595 $fres = $facilityService->getAll();
3597 $name = htmlspecialchars($name, ENT_QUOTES);
3598 echo " <select class='form-control' name='$name' id='$name'";
3599 if ($onchange) {
3600 echo " onchange='$onchange'";
3603 echo " $disabled>\n";
3605 if ($allow_allfacilities) {
3606 $option_value = '';
3607 $option_selected_attr = '';
3608 if ($selected == '') {
3609 $option_selected_attr = ' selected="selected"';
3610 $have_selected = true;
3613 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
3614 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3615 } elseif ($allow_unspecified) {
3616 $option_value = '0';
3617 $option_selected_attr = '';
3618 if ($selected == '0') {
3619 $option_selected_attr = ' selected="selected"';
3620 $have_selected = true;
3623 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
3624 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3627 foreach ($fres as $frow) {
3628 $facility_id = $frow['id'];
3629 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
3630 $option_selected_attr = '';
3631 if ($selected == $facility_id) {
3632 $option_selected_attr = ' selected="selected"';
3633 $have_selected = true;
3636 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
3637 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3640 if ($allow_unspecified && $allow_allfacilities) {
3641 $option_value = '0';
3642 $option_selected_attr = '';
3643 if ($selected == '0') {
3644 $option_selected_attr = ' selected="selected"';
3645 $have_selected = true;
3648 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
3649 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3652 if (!$have_selected) {
3653 $option_value = htmlspecialchars($selected, ENT_QUOTES);
3654 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
3655 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
3656 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
3659 echo " </select>\n";
3662 // Expand Collapse Widget
3663 // This forms the header and functionality component of the widget. The information that is displayed
3664 // then follows this function followed by a closing div tag
3666 // $title is the title of the section (already translated)
3667 // $label is identifier used in the tag id's and sql columns
3668 // $buttonLabel is the button label text (already translated)
3669 // $buttonLink is the button link information
3670 // $buttonClass is any additional needed class elements for the button tag
3671 // $linkMethod is the button link method ('javascript' vs 'html')
3672 // $bodyClass is to set class(es) of the body
3673 // $auth is a flag to decide whether to show the button
3674 // $fixedWidth is to flag whether width is fixed
3675 // $forceExpandAlways is a flag to force the widget to always be expanded
3677 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways = false)
3679 if ($fixedWidth) {
3680 echo "<div class='section-header'>";
3681 } else {
3682 echo "<div class='section-header-dynamic'>";
3685 echo "<table><tr>";
3686 if ($auth) {
3687 // show button, since authorized
3688 // first prepare class string
3689 if ($buttonClass) {
3690 $class_string = "css_button_small ".htmlspecialchars($buttonClass, ENT_NOQUOTES);
3691 } else {
3692 $class_string = "css_button_small";
3695 // next, create the link
3696 if ($linkMethod == "javascript") {
3697 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3698 } else {
3699 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3700 if (!isset($_SESSION['patient_portal_onsite']) && !isset($_SESSION['patient_portal_onsite_two'])) {
3701 // prevent an error from occuring when calling the function from the patient portal
3702 echo " onclick='top.restoreSession()'";
3706 echo "><span>" .
3707 htmlspecialchars($buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
3710 if ($forceExpandAlways) {
3711 // Special case to force the widget to always be expanded
3712 echo "<td><span class='text'><b>" . htmlspecialchars($title, ENT_NOQUOTES) . "</b></span>";
3713 $indicatorTag ="style='display:none'";
3716 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3717 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3718 htmlspecialchars($label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
3719 echo htmlspecialchars($title, ENT_NOQUOTES) . "</b></span>";
3721 if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3722 // collapse all entries in the patient portal
3723 $text = xl('expand');
3724 } else if (getUserSetting($label."_ps_expand")) {
3725 $text = xl('collapse');
3726 } else {
3727 $text = xl('expand');
3730 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
3731 "</span>)</a></td>";
3732 echo "</tr></table>";
3733 echo "</div>";
3734 if ($forceExpandAlways) {
3735 // Special case to force the widget to always be expanded
3736 $styling = "";
3737 } else if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3738 // collapse all entries in the patient portal
3739 $styling = "style='display:none'";
3740 } else if (getUserSetting($label."_ps_expand")) {
3741 $styling = "";
3742 } else {
3743 $styling = "style='display:none'";
3746 if ($bodyClass) {
3747 $styling .= " class='" . $bodyClass . "'";
3750 //next, create the first div tag to hold the information
3751 // note the code that calls this function will then place the ending div tag after the data
3752 echo "<div id='" . htmlspecialchars($label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
3755 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3756 function billing_facility($name, $select)
3758 global $facilityService;
3760 $fres = $facilityService->getAllBillingLocations();
3761 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' class='form-control' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3762 foreach ($fres as $facrow) {
3763 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3764 echo "<option value=".htmlspecialchars($facrow['id'], ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3767 echo "</select>";
3770 // Generic function to get the translated title value for a particular list option.
3772 function getListItemTitle($list, $option)
3774 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3775 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3776 if (empty($row['title'])) {
3777 return $option;
3780 return xl_list_label($row['title']);
3782 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3783 function getSmokeCodes()
3785 $smoking_codes_arr = array();
3786 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3787 while ($codes_row = sqlFetchArray($smoking_codes)) {
3788 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3791 return $smoking_codes_arr;
3794 // Get the current value for a layout based form field.
3795 // Depending on options this might come from lbf_data, patient_data,
3796 // form_encounter, shared_attributes or elsewhere.
3797 // Returns FALSE if the field ID is invalid (layout error).
3799 function lbf_current_value($frow, $formid, $encounter)
3801 global $pid;
3802 $formname = $frow['form_id'];
3803 $field_id = $frow['field_id'];
3804 $source = $frow['source'];
3805 $currvalue = '';
3806 $deffname = $formname . '_default_' . $field_id;
3807 if ($source == 'D' || $source == 'H') {
3808 // Get from patient_data, employer_data or history_data.
3809 if ($source == 'H') {
3810 $table = 'history_data';
3811 $orderby = 'ORDER BY date DESC LIMIT 1';
3812 } else if (strpos($field_id, 'em_') === 0) {
3813 $field_id = substr($field_id, 3);
3814 $table = 'employer_data';
3815 $orderby = 'ORDER BY date DESC LIMIT 1';
3816 } else {
3817 $table = 'patient_data';
3818 $orderby = '';
3821 // It is an error if the field does not exist, but don't crash.
3822 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3823 if (empty($tmp)) {
3824 return '*?*';
3827 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3828 if (isset($pdrow)) {
3829 $currvalue = $pdrow['field_value'];
3831 } else if ($source == 'E') {
3832 $sarow = false;
3833 if ($encounter) {
3834 // Get value from shared_attributes of the current encounter.
3835 $sarow = sqlQuery(
3836 "SELECT field_value FROM shared_attributes WHERE " .
3837 "pid = ? AND encounter = ? AND field_id = ?",
3838 array($pid, $encounter, $field_id)
3840 if (!empty($sarow)) {
3841 $currvalue = $sarow['field_value'];
3843 } else if ($formid) {
3844 // Get from shared_attributes of the encounter that this form is linked to.
3845 // Note the importance of having an index on forms.form_id.
3846 $sarow = sqlQuery(
3847 "SELECT sa.field_value " .
3848 "FROM forms AS f, shared_attributes AS sa WHERE " .
3849 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3850 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3851 array($formid, $formname, $field_id)
3853 if (!empty($sarow)) {
3854 $currvalue = $sarow['field_value'];
3856 } else {
3857 // New form and encounter not available, this should not happen.
3859 if (empty($sarow) && !$formid) {
3860 // New form, see if there is a custom default from a plugin.
3861 if (function_exists($deffname)) {
3862 $currvalue = call_user_func($deffname);
3865 } else if ($source == 'V') {
3866 if ($encounter) {
3867 // Get value from the current encounter's form_encounter.
3868 $ferow = sqlQuery(
3869 "SELECT * FROM form_encounter WHERE " .
3870 "pid = ? AND encounter = ?",
3871 array($pid, $encounter)
3873 if (isset($ferow[$field_id])) {
3874 $currvalue = $ferow[$field_id];
3876 } else if ($formid) {
3877 // Get value from the form_encounter that this form is linked to.
3878 $ferow = sqlQuery(
3879 "SELECT fe.* " .
3880 "FROM forms AS f, form_encounter AS fe WHERE " .
3881 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3882 "fe.pid = f.pid AND fe.encounter = f.encounter",
3883 array($formid, $formname)
3885 if (isset($ferow[$field_id])) {
3886 $currvalue = $ferow[$field_id];
3888 } else {
3889 // New form and encounter not available, this should not happen.
3891 } else if ($formid) {
3892 // This is a normal form field.
3893 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3894 "form_id = ? AND field_id = ?", array($formid, $field_id));
3895 if (!empty($ldrow)) {
3896 $currvalue = $ldrow['field_value'];
3898 } else {
3899 // New form, see if there is a custom default from a plugin.
3900 if (function_exists($deffname)) {
3901 $currvalue = call_user_func($deffname);
3905 return $currvalue;
3908 // This returns stuff that needs to go into the <head> section of a caller using
3909 // the drawable image field type in a form.
3910 // A TRUE argument makes the widget controls smaller.
3912 function lbf_canvas_head($small = true)
3914 $s = <<<EOD
3915 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3916 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3917 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3918 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3919 EOD;
3920 if ($small) {
3921 $s .= <<<EOD
3922 <style>
3923 /* Custom LiterallyCanvas styling.
3924 * This makes the widget 25% less tall and adjusts some other things accordingly.
3926 .literally {
3927 min-height:100%;min-width:300px; /* Was 400, unspecified */
3929 .literally .lc-picker .toolbar-button {
3930 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3932 .literally .color-well {
3933 font-size:8px;width:49px; /* Was 10, 60 */
3935 .literally .color-well-color-container {
3936 width:21px;height:21px; /* Was 28, 28 */
3938 .literally .lc-picker {
3939 width:50px; /* Was 61 */
3941 .literally .lc-drawing.with-gui {
3942 left:50px; /* Was 61 */
3944 .literally .lc-options {
3945 left:50px; /* Was 61 */
3947 .literally .color-picker-popup {
3948 left:49px;bottom:0px; /* Was 60, 31 */
3950 </style>
3951 EOD;
3954 return $s;