PSR2 fixes
[openemr.git] / library / options.inc.php
blobb6c783488aae0d3deb75fd75bd8f2aa9568a38ea
1 <?php
2 // Copyright (C) 2007-2017 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 // Documentation for layout_options.edit_options:
21 // A = Age as years or "xx month(s)"
22 // B = Gestational age as "xx week(s) y day(s)"
23 // C = Capitalize first letter of each word (text fields)
24 // D = Check for duplicates in New Patient form
25 // G = Graphable (for numeric fields in forms supporting historical data)
26 // H = Read-only field copied from static history (this is obsolete)
27 // L = Lab Order ("ord_lab") types only (address book)
28 // N = Show in New Patient form
29 // O = Procedure Order ("ord_*") types only (address book)
30 // P = Default to previous value when current value is not yet set
31 // R = Distributor types only (address book)
32 // T = Use description as default Text
33 // U = Capitalize all letters (text fields)
34 // V = Vendor types only (address book)
35 // 0 = Read Only - the input element's "disabled" property is set
36 // 1 = Write Once (not editable when not empty) (text fields)
37 // 2 = Show descriptions instead of codes for billing code input
39 require_once("user.inc");
40 require_once("patient.inc");
41 require_once("lists.inc");
42 require_once(dirname(dirname(__FILE__)) . "/custom/code_types.inc.php");
44 use OpenEMR\Services\FacilityService;
46 $facilityService = new FacilityService();
48 $date_init = "";
50 function get_pharmacies()
52 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
53 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
54 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
55 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
56 "AND p.type = 2 " .
57 "ORDER BY name, area_code, prefix, number");
60 function optionalAge($frow, $date, &$asof, $description = '')
62 $asof = '';
63 if (empty($date)) {
64 return '';
67 $date = substr($date, 0, 10);
68 if (isOption($frow['edit_options'], 'A') !== false) {
69 $format = 0;
70 } else if (isOption($frow['edit_options'], 'B') !== false) {
71 $format = 3;
72 } else {
73 return '';
76 if (isOption($frow['form_id'], 'LBF') === 0) {
77 $tmp = sqlQuery(
78 "SELECT date FROM form_encounter WHERE " .
79 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
80 array($GLOBALS['pid'], $GLOBALS['encounter'])
82 if (!empty($tmp['date'])) {
83 $asof = substr($tmp['date'], 0, 10);
86 if ($description === '') {
87 $prefix = ($format ? xl('Gest age') : xl('Age')) . ' ';
88 } else {
89 $prefix = $description . ' ';
91 return $prefix . oeFormatAge($date, $asof, $format);
94 // Function to generate a drop-list.
96 function generate_select_list(
97 $tag_name,
98 $list_id,
99 $currvalue,
100 $title,
101 $empty_name = ' ',
102 $class = '',
103 $onchange = '',
104 $tag_id = '',
105 $custom_attributes = null,
106 $multiple = false,
107 $backup_list = ''
109 $s = '';
111 $tag_name_esc = attr($tag_name);
113 if ($multiple) {
114 $tag_name_esc = $tag_name_esc . "[]";
117 $s .= "<select name='$tag_name_esc'";
119 if ($multiple) {
120 $s .= " multiple='multiple'";
123 $tag_id_esc = attr($tag_name);
125 if ($tag_id != '') {
126 $tag_id_esc = attr($tag_id);
129 $s .= " id='$tag_id_esc'";
131 if (!empty($class)) {
132 $class_esc = attr($class);
133 $s .= " class='form-control $class_esc'";
134 } else {
135 $s .= " class='form-control'";
138 if ($onchange) {
139 $s .= " onchange='$onchange'";
142 if ($custom_attributes != null && is_array($custom_attributes)) {
143 foreach ($custom_attributes as $attr => $val) {
144 if (isset($custom_attributes [$attr])) {
145 $s .= " " . attr($attr) . "='" . attr($val) . "'";
150 $selectTitle = attr($title);
151 $s .= " title='$selectTitle'>";
152 $selectEmptyName = xlt($empty_name);
153 if ($empty_name) {
154 $s .= "<option value=''>" . $selectEmptyName . "</option>";
157 // List order depends on language translation options.
158 // (Note we do not need to worry about the list order in the algorithm
159 // after the below code block since that is where searches for exceptions
160 // are done which include inactive items or items from a backup
161 // list; note these will always be shown at the bottom of the list no matter the
162 // chosen order.)
163 $lang_id = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
164 // sort by title
165 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) || !$GLOBALS['translate_lists']) {
166 // do not translate
167 if ($GLOBALS['gb_how_sort_list'] == '0') {
168 // order by seq
169 $order_by_sql = "seq, title";
170 } else { //$GLOBALS['gb_how_sort_list'] == '1'
171 // order by title
172 $order_by_sql = "title, seq";
175 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
176 } else {
177 // do translate
178 if ($GLOBALS['gb_how_sort_list'] == '0') {
179 // order by seq
180 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
181 } else { //$GLOBALS['gb_how_sort_list'] == '1'
182 // order by title
183 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
186 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
187 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
188 "FROM list_options AS lo " .
189 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
190 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
191 "ld.lang_id = ? " .
192 "WHERE lo.list_id = ? AND lo.activity=1 " .
193 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
196 $got_selected = false;
198 while ($lrow = sqlFetchArray($lres)) {
199 $selectedValues = explode("|", $currvalue);
201 $optionValue = attr($lrow ['option_id']);
202 $s .= "<option value='$optionValue'";
204 if ((strlen($currvalue) == 0 && $lrow ['is_default']) || (strlen($currvalue) > 0 && in_array($lrow ['option_id'], $selectedValues))) {
205 $s .= " selected";
206 $got_selected = true;
209 // Already has been translated above (if applicable), so do not need to use
210 // the xl_list_label() function here
211 $optionLabel = text($lrow ['title']);
212 $s .= ">$optionLabel</option>\n";
216 To show the inactive item in the list if the value is saved to database
218 if (!$got_selected && strlen($currvalue) > 0) {
219 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
220 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
221 $lrow_inactive = sqlFetchArray($lres_inactive);
222 if ($lrow_inactive['option_id']) {
223 $optionValue = htmlspecialchars($lrow_inactive['option_id'], ENT_QUOTES);
224 $s .= "<option value='$optionValue' selected>" . htmlspecialchars(xl_list_label($lrow_inactive['title']), ENT_NOQUOTES) . "</option>\n";
225 $got_selected = true;
229 if (!$got_selected && strlen($currvalue) > 0 && !$multiple) {
230 $list_id = $backup_list;
231 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
233 if ($lrow > 0 && !empty($backup_list)) {
234 $selected = text(xl_list_label($lrow ['title']));
235 $s .= "<option value='$currescaped' selected> $selected </option>";
236 $s .= "</select>";
237 } else {
238 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
239 $s .= "</select>";
240 $fontTitle = xlt('Please choose a valid selection from the list.');
241 $fontText = xlt('Fix this');
242 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
244 } 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 (isOption($frow['edit_options'], 'T') !== false) {
333 if (strlen($currescaped) == 0) {
334 $currescaped = $description;
337 // Description used in this way is not suitable as a title.
338 $description = '';
341 // added 5-2009 by BM to allow modification of the 'empty' text title field.
342 // Can pass $frow['empty_title'] with this variable, otherwise
343 // will default to 'Unassigned'.
344 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
345 // if make $frow['empty_title'] equal to 'SKIP'
346 $showEmpty = true;
347 if (isset($frow['empty_title'])) {
348 if ($frow['empty_title'] == "SKIP") {
349 //do not display an 'empty' choice
350 $showEmpty = false;
351 $empty_title = "Unassigned";
352 } else {
353 $empty_title = $frow['empty_title'];
355 } else {
356 $empty_title = "Unassigned";
359 $disabled = isOption($frow['edit_options'], '0') === false ? '' : 'disabled';
361 $lbfchange = (
362 strpos($frow['form_id'], 'LBF') === 0 ||
363 strpos($frow['form_id'], 'LBT') === 0 ||
364 $frow['form_id'] == 'DEM' ||
365 $frow['form_id'] == 'HIS'
366 ) ? "checkSkipConditions();" : "";
367 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
369 // generic single-selection list or Race and Ethnicity.
370 // These data types support backup lists.
371 if ($data_type == 1 || $data_type == 33) {
372 echo generate_select_list(
373 "form_$field_id",
374 $list_id,
375 $currvalue,
376 $description,
377 ($showEmpty ? $empty_title : ''),
379 $lbfchange,
381 ($disabled ? array('disabled' => 'disabled') : null),
382 false,
383 $backup_list
385 } // simple text field
386 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 (isOption($frow['edit_options'], 'C') !== false) {
405 $tmp .= "capitalizeMe(this);";
406 } else if (isOption($frow['edit_options'], 'U') !== false) {
407 $tmp .= "this.value = this.value.toUpperCase();";
410 if ($tmp) {
411 echo " onchange='$tmp'";
414 $tmp = htmlspecialchars($GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
415 // If mask is for use at save time, treat as no mask.
416 if (strpos($tmp, '^') !== false) {
417 $tmp = '';
419 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
420 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
421 echo " onblur='maskblur(this,\"$tmp\")'";
424 if (isOption($frow['edit_options'], '1') !== false && strlen($currescaped) > 0) {
425 echo " readonly";
428 if ($disabled) {
429 echo ' disabled';
432 echo " />";
433 } // long or multi-line text field
434 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 = isOption($frow['edit_options'], 'A') === false ? 3 : 0;
449 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
450 if ($agestr) {
451 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
454 $onchange_string = '';
455 if (!$disabled && $agestr) {
456 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') " .
457 "updateAgeString('$field_id','$age_asof_date', $age_format, '$description')\"";
459 if ($data_type == 4) {
460 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
461 if (!$modtmp) {
462 echo "<input type='text' size='10' class='datepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
463 " value='" . substr($currescaped, 0, 10) . "'";
464 } else {
465 echo "<input type='text' size='20' class='datetimepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
466 " value='" . substr($currescaped, 0, 20) . "'";
469 if (!$agestr) {
470 echo " title='$description'";
473 echo " $onchange_string $lbfonchange $disabled />";
475 // Optional display of age or gestational age.
476 if ($agestr) {
477 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
479 } // provider list, local providers only
480 else if ($data_type == 10) {
481 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
482 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
483 "AND authorized = 1 " .
484 "ORDER BY lname, fname");
485 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
486 echo "<option value=''>" . xlt($empty_title) . "</option>";
487 $got_selected = false;
488 while ($urow = sqlFetchArray($ures)) {
489 $uname = text($urow['fname'] . ' ' . $urow['lname']);
490 $optionId = attr($urow['id']);
491 echo "<option value='$optionId'";
492 if ($urow['id'] == $currvalue) {
493 echo " selected";
494 $got_selected = true;
497 echo ">$uname</option>";
500 if (!$got_selected && $currvalue) {
501 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
502 echo "</select>";
503 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
504 } else {
505 echo "</select>";
507 } // provider list, including address book entries with an NPI number
508 else if ($data_type == 11) {
509 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
510 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
511 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
512 "ORDER BY lname, fname");
513 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
514 echo " $lbfonchange $disabled>";
515 echo "<option value=''>" . xlt('Unassigned') . "</option>";
516 $got_selected = false;
517 while ($urow = sqlFetchArray($ures)) {
518 $uname = text($urow['fname'] . ' ' . $urow['lname']);
519 $optionId = attr($urow['id']);
520 echo "<option value='$optionId'";
521 if ($urow['id'] == $currvalue) {
522 echo " selected";
523 $got_selected = true;
526 echo ">$uname</option>";
529 if (!$got_selected && $currvalue) {
530 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
531 echo "</select>";
532 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
533 } else {
534 echo "</select>";
536 } // pharmacy list
537 else if ($data_type == 12) {
538 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
539 echo " $lbfonchange $disabled>";
540 echo "<option value='0'></option>";
541 $pres = get_pharmacies();
542 $got_selected = false;
543 while ($prow = sqlFetchArray($pres)) {
544 $key = $prow['id'];
545 $optionValue = htmlspecialchars($key, ENT_QUOTES);
546 $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
547 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
548 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
549 echo "<option value='$optionValue'";
550 if ($currvalue == $key) {
551 echo " selected";
552 $got_selected = true;
555 echo ">$optionLabel</option>";
558 if (!$got_selected && $currvalue) {
559 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
560 echo "</select>";
561 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
562 } else {
563 echo "</select>";
565 } // squads
566 else if ($data_type == 13) {
567 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
568 echo " $lbfonchange $disabled>";
569 echo "<option value=''>&nbsp;</option>";
570 $squads = acl_get_squads();
571 if ($squads) {
572 foreach ($squads as $key => $value) {
573 $optionValue = htmlspecialchars($key, ENT_QUOTES);
574 $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES);
575 echo "<option value='$optionValue'";
576 if ($currvalue == $key) {
577 echo " selected";
580 echo ">$optionLabel</option>\n";
584 echo "</select>";
585 } // Address book, preferring organization name if it exists and is not in
586 // parentheses, and excluding local users who are not providers.
587 // Supports "referred to" practitioners and facilities.
588 // Alternatively the letter L in edit_options means that abook_type
589 // must be "ord_lab", indicating types used with the procedure
590 // lab ordering system.
591 // Alternatively the letter O in edit_options means that abook_type
592 // must begin with "ord_", indicating types used with the procedure
593 // ordering system.
594 // Alternatively the letter V in edit_options means that abook_type
595 // must be "vendor", indicating the Vendor type.
596 // Alternatively the letter R in edit_options means that abook_type
597 // must be "dist", indicating the Distributor type.
598 else if ($data_type == 14) {
599 if (isOption($frow['edit_options'], 'L') !== false) {
600 $tmp = "abook_type = 'ord_lab'";
601 } else if (isOption($frow['edit_options'], 'O') !== false) {
602 $tmp = "abook_type LIKE 'ord\\_%'";
603 } else if (isOption($frow['edit_options'], 'V') !== false) {
604 $tmp = "abook_type LIKE 'vendor%'";
605 } else if (isOption($frow['edit_options'], 'R') !== false) {
606 $tmp = "abook_type LIKE 'dist'";
607 } else {
608 $tmp = "( username = '' OR authorized = 1 )";
611 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
612 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
613 "AND $tmp " .
614 "ORDER BY organization, lname, fname");
615 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
616 echo " $lbfonchange $disabled>";
617 echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES) . "</option>";
618 while ($urow = sqlFetchArray($ures)) {
619 $uname = $urow['organization'];
620 if (empty($uname) || substr($uname, 0, 1) == '(') {
621 $uname = $urow['lname'];
622 if ($urow['fname']) {
623 $uname .= ", " . $urow['fname'];
627 $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES);
628 $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES);
629 echo "<option value='$optionValue'";
630 // Failure to translate Local and External is not an error here;
631 // they are only used as internal flags and must not be translated!
632 $title = $urow['username'] ? 'Local' : 'External';
633 $optionTitle = htmlspecialchars($title, ENT_QUOTES);
634 echo " title='$optionTitle'";
635 if ($urow['id'] == $currvalue) {
636 echo " selected";
639 echo ">$optionLabel</option>";
642 echo "</select>";
643 } // A billing code. If description matches an existing code type then that type is used.
644 else if ($data_type == 15) {
645 $codetype = '';
646 if (!empty($frow['description']) && isset($code_types[$frow['description']])) {
647 $codetype = $frow['description'];
649 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
650 $maxlength = $frow['max_length'];
651 $string_maxlength = "";
652 // if max_length is set to zero, then do not set a maxlength
653 if ($maxlength) {
654 $string_maxlength = "maxlength='".attr($maxlength)."'";
658 if (isOption($frow['edit_options'], '2') !== false && substr($frow['form_id'], 0, 3) == 'LBF') {
659 // Option "2" generates a hidden input for the codes, and a matching visible field
660 // displaying their descriptions. First step is computing the description string.
661 $currdescstring = '';
662 if (!empty($currvalue)) {
663 $relcodes = explode(';', $currvalue);
664 foreach ($relcodes as $codestring) {
665 if ($codestring === '') {
666 continue;
669 $code_text = lookup_code_descriptions($codestring);
670 if ($currdescstring !== '') {
671 $currdescstring .= '; ';
674 if (!empty($code_text)) {
675 $currdescstring .= $code_text;
676 } else {
677 $currdescstring .= $codestring;
682 $currdescstring = attr($currdescstring);
684 echo "<input type='text'" .
685 " name='form_$field_id_esc'" .
686 " id='form_related_code'" .
687 " size='$fldlength'" .
688 " value='$currescaped'" .
689 " style='display:none'" .
690 " $lbfonchange readonly $disabled />";
691 // Extra readonly input field for optional display of code description(s).
692 echo "<input type='text'" .
693 " name='form_$field_id_esc" . "__desc'" .
694 " size='$fldlength'" .
695 " title='$description'" .
696 " value='$currdescstring'";
697 if (!$disabled) {
698 echo " onclick='sel_related(this,\"$codetype\")'";
701 echo "class='form-control'";
702 echo " readonly $disabled />";
703 } else {
704 echo "<input type='text'" .
705 " name='form_$field_id_esc'" .
706 " id='form_related_code'" .
707 " size='$fldlength'" .
708 " $string_maxlength" .
709 " title='$description'" .
710 " value='$currescaped'";
711 if (!$disabled) {
712 echo " onclick='sel_related(this,\"$codetype\")'";
715 echo "class='form-control'";
716 echo " $lbfonchange readonly $disabled />";
718 } // insurance company list
719 else if ($data_type == 16) {
720 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
721 echo "<option value='0'></option>";
722 $insprovs = getInsuranceProviders();
723 $got_selected = false;
724 foreach ($insprovs as $key => $ipname) {
725 $optionValue = htmlspecialchars($key, ENT_QUOTES);
726 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
727 echo "<option value='$optionValue'";
728 if ($currvalue == $key) {
729 echo " selected";
730 $got_selected = true;
733 echo ">$optionLabel</option>";
736 if (!$got_selected && $currvalue) {
737 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
738 echo "</select>";
739 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
740 } else {
741 echo "</select>";
743 } // issue types
744 else if ($data_type == 17) {
745 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
746 echo "<option value='0'></option>";
747 $got_selected = false;
748 foreach ($ISSUE_TYPES as $key => $value) {
749 $optionValue = htmlspecialchars($key, ENT_QUOTES);
750 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
751 echo "<option value='$optionValue'";
752 if ($currvalue == $key) {
753 echo " selected";
754 $got_selected = true;
757 echo ">$optionLabel</option>";
760 if (!$got_selected && strlen($currvalue) > 0) {
761 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
762 echo "</select>";
763 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
764 } else {
765 echo "</select>";
767 } // Visit categories.
768 else if ($data_type == 18) {
769 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
770 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
771 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'" .
772 " $lbfonchange $disabled>";
773 echo "<option value=''>" . xlt($empty_title) . "</option>";
774 $got_selected = false;
775 while ($crow = sqlFetchArray($cres)) {
776 $catid = $crow['pc_catid'];
777 if (($catid < 9 && $catid != 5) || $catid == 11) {
778 continue;
781 echo "<option value='" . attr($catid) . "'";
782 if ($catid == $currvalue) {
783 echo " selected";
784 $got_selected = true;
787 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
790 if (!$got_selected && $currvalue) {
791 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
792 echo "</select>";
793 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
794 } else {
795 echo "</select>";
797 } // a set of labeled checkboxes
798 else if ($data_type == 21) {
799 // If no list then it's a single checkbox and its value is "Yes" or empty.
800 if (!$list_id) {
801 echo "<input type='checkbox' name='form_{$field_id_esc}' " .
802 "id='form_{$field_id_esc}' value='Yes' $lbfonchange";
803 if ($currvalue) {
804 echo " checked";
806 echo " $disabled />";
807 } else {
808 // In this special case, fld_length is the number of columns generated.
809 $cols = max(1, $frow['fld_length']);
810 $avalue = explode('|', $currvalue);
811 $lres = sqlStatement("SELECT * FROM list_options " .
812 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
813 echo "<table cellpadding='0' cellspacing='0' width='100%' title='".attr($description)."'>";
814 $tdpct = (int) (100 / $cols);
815 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
816 $option_id = $lrow['option_id'];
817 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
818 // if ($count) echo "<br />";
819 if ($count % $cols == 0) {
820 if ($count) {
821 echo "</tr>";
823 echo "<tr>";
825 echo "<td width='" . attr($tdpct) . "%' nowrap>";
826 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
827 "id='form_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
828 if (in_array($option_id, $avalue)) {
829 echo " checked";
831 // Added 5-09 by BM - Translate label if applicable
832 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
833 echo "</td>";
835 if ($count) {
836 echo "</tr>";
837 if ($count > $cols) {
838 // Add some space after multiple rows of checkboxes.
839 $cols = htmlspecialchars($cols, ENT_QUOTES);
840 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
843 echo "</table>";
845 } // a set of labeled text input fields
846 else if ($data_type == 22) {
847 $tmp = explode('|', $currvalue);
848 $avalue = array();
849 foreach ($tmp as $value) {
850 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
851 $avalue[$matches[1]] = $matches[2];
855 $lres = sqlStatement("SELECT * FROM list_options " .
856 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
857 echo "<table cellpadding='0' cellspacing='0'>";
858 while ($lrow = sqlFetchArray($lres)) {
859 $option_id = $lrow['option_id'];
860 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
861 $maxlength = $frow['max_length'];
862 $string_maxlength = "";
863 // if max_length is set to zero, then do not set a maxlength
864 if ($maxlength) {
865 $string_maxlength = "maxlength='".attr($maxlength)."'";
868 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
870 // Added 5-09 by BM - Translate label if applicable
871 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
872 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
873 $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
874 echo "<td><input type='text'" .
875 " name='form_{$field_id_esc}[$option_id_esc]'" .
876 " id='form_{$field_id_esc}[$option_id_esc]'" .
877 " size='$fldlength'" .
878 " class='form-control'" .
879 " $string_maxlength" .
880 " value='$optionValue'";
881 echo " $lbfonchange $disabled /></td></tr>";
884 echo "</table>";
885 } // a set of exam results; 3 radio buttons and a text field:
886 else if ($data_type == 23) {
887 $tmp = explode('|', $currvalue);
888 $avalue = array();
889 foreach ($tmp as $value) {
890 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
891 $avalue[$matches[1]] = $matches[2];
895 $maxlength = $frow['max_length'];
896 $string_maxlength = "";
897 // if max_length is set to zero, then do not set a maxlength
898 if ($maxlength) {
899 $string_maxlength = "maxlength='".attr($maxlength)."'";
902 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
903 $lres = sqlStatement("SELECT * FROM list_options " .
904 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
905 echo "<table cellpadding='0' cellspacing='0'>";
906 echo "<tr><td>&nbsp;</td><td class='bold'>" .
907 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
908 "&nbsp;</td><td class='bold'>" .
909 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
910 "<td class='bold'>" .
911 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
912 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
913 while ($lrow = sqlFetchArray($lres)) {
914 $option_id = $lrow['option_id'];
915 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
916 $restype = substr($avalue[$option_id], 0, 1);
917 $resnote = substr($avalue[$option_id], 2);
919 // Added 5-09 by BM - Translate label if applicable
920 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
922 for ($i = 0; $i < 3; ++$i) {
923 $inputValue = htmlspecialchars($i, ENT_QUOTES);
924 echo "<td><input type='radio'" .
925 " name='radio_{$field_id_esc}[$option_id_esc]'" .
926 " id='radio_{$field_id_esc}[$option_id_esc]'" .
927 " value='$inputValue' $lbfonchange";
928 if ($restype === "$i") {
929 echo " checked";
932 echo " $disabled /></td>";
935 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
936 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
937 echo "<td><input type='text'" .
938 " name='form_{$field_id_esc}[$option_id_esc]'" .
939 " id='form_{$field_id_esc}[$option_id_esc]'" .
940 " size='$fldlength'" .
941 " $string_maxlength" .
942 " value='$resnote' $disabled /></td>";
943 echo "</tr>";
946 echo "</table>";
947 } // the list of active allergies for the current patient
948 // this is read-only!
949 else if ($data_type == 24) {
950 $query = "SELECT title, comments FROM lists WHERE " .
951 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
952 "ORDER BY begdate";
953 // echo "<!-- $query -->\n"; // debugging
954 $lres = sqlStatement($query, array($GLOBALS['pid']));
955 $count = 0;
956 while ($lrow = sqlFetchArray($lres)) {
957 if ($count++) {
958 echo "<br />";
961 echo htmlspecialchars($lrow['title'], ENT_NOQUOTES);
962 if ($lrow['comments']) {
963 echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
966 } // a set of labeled checkboxes, each with a text field:
967 else if ($data_type == 25) {
968 $tmp = explode('|', $currvalue);
969 $avalue = array();
970 foreach ($tmp as $value) {
971 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
972 $avalue[$matches[1]] = $matches[2];
976 $maxlength = $frow['max_length'];
977 $string_maxlength = "";
978 // if max_length is set to zero, then do not set a maxlength
979 if ($maxlength) {
980 $string_maxlength = "maxlength='".attr($maxlength)."'";
983 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
984 $lres = sqlStatement("SELECT * FROM list_options " .
985 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
986 echo "<table cellpadding='0' cellspacing='0'>";
987 while ($lrow = sqlFetchArray($lres)) {
988 $option_id = $lrow['option_id'];
989 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
990 $restype = substr($avalue[$option_id], 0, 1);
991 $resnote = substr($avalue[$option_id], 2);
993 // Added 5-09 by BM - Translate label if applicable
994 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
996 $option_id = htmlspecialchars($option_id, ENT_QUOTES);
997 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
998 " id='check_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
999 if ($restype) {
1000 echo " checked";
1003 echo " $disabled />&nbsp;</td>";
1004 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1005 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1006 echo "<td><input type='text'" .
1007 " name='form_{$field_id_esc}[$option_id_esc]'" .
1008 " id='form_{$field_id_esc}[$option_id_esc]'" .
1009 " size='$fldlength'" .
1010 " class='form-control' " .
1011 " $string_maxlength" .
1012 " value='$resnote' $disabled /></td>";
1013 echo "</tr>";
1016 echo "</table>";
1017 } // single-selection list with ability to add to it
1018 else if ($data_type == 26) {
1019 echo generate_select_list(
1020 "form_$field_id",
1021 $list_id,
1022 $currvalue,
1023 $description,
1024 ($showEmpty ? $empty_title : ''),
1025 'addtolistclass_'.$list_id,
1026 $lbfchange,
1028 ($disabled ? array('disabled' => 'disabled') : null),
1029 false,
1030 $backup_list
1032 // show the add button if user has access to correct list
1033 $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES);
1034 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
1035 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
1036 if (aco_exist('lists', $list_id)) {
1037 // a specific aco exist for this list, so ensure access
1038 if (acl_check('lists', $list_id)) {
1039 echo $outputAddButton;
1041 } else {
1042 // no specific aco exist for this list, so check for access to 'default' list
1043 if (acl_check('lists', 'default')) {
1044 echo $outputAddButton;
1047 } // a set of labeled radio buttons
1048 else if ($data_type == 27) {
1049 // In this special case, fld_length is the number of columns generated.
1050 $cols = max(1, $frow['fld_length']);
1051 $lres = sqlStatement("SELECT * FROM list_options " .
1052 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1053 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1054 $tdpct = (int) (100 / $cols);
1055 $got_selected = false;
1056 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1057 $option_id = $lrow['option_id'];
1058 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
1059 if ($count % $cols == 0) {
1060 if ($count) {
1061 echo "</tr>";
1064 echo "<tr>";
1067 echo "<td width='" . attr($tdpct) . "%'>";
1068 echo "<input type='radio' name='form_{$field_id_esc}' class='form-control' id='form_{$field_id_esc}[$option_id_esc]'" .
1069 " value='$option_id_esc' $lbfonchange";
1070 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1071 (strlen($currvalue) > 0 && $option_id == $currvalue)) {
1072 echo " checked";
1073 $got_selected = true;
1076 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1077 echo "</td>";
1080 if ($count) {
1081 echo "</tr>";
1082 if ($count > $cols) {
1083 // Add some space after multiple rows of radio buttons.
1084 $cols = htmlspecialchars($cols, ENT_QUOTES);
1085 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1089 echo "</table>";
1090 if (!$got_selected && strlen($currvalue) > 0) {
1091 $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES);
1092 $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES);
1093 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
1095 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1096 // VicarePlus :: A selection list box for smoking status:
1097 else if ($data_type == 28 || $data_type == 32) {
1098 $tmp = explode('|', $currvalue);
1099 switch (count($tmp)) {
1100 case "4":
1101 $resnote = $tmp[0];
1102 $restype = $tmp[1];
1103 $resdate = $tmp[2];
1104 $reslist = $tmp[3];
1105 break;
1106 case "3":
1107 $resnote = $tmp[0];
1108 $restype = $tmp[1];
1109 $resdate = $tmp[2];
1110 break;
1111 case "2":
1112 $resnote = $tmp[0];
1113 $restype = $tmp[1];
1114 $resdate = "";
1115 break;
1116 case "1":
1117 $resnote = $tmp[0];
1118 $resdate = $restype = "";
1119 break;
1120 default:
1121 $restype = $resdate = $resnote = "";
1122 break;
1125 $maxlength = $frow['max_length'];
1126 $string_maxlength = "";
1127 // if max_length is set to zero, then do not set a maxlength
1128 if ($maxlength) {
1129 $string_maxlength = "maxlength='".attr($maxlength)."'";
1132 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1134 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1135 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1136 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1137 echo "<table cellpadding='0' cellspacing='0'>";
1138 echo "<tr>";
1139 if ($data_type == 28) {
1140 // input text
1141 echo "<td><input type='text'" .
1142 " name='form_$field_id_esc'" .
1143 " id='form_$field_id_esc'" .
1144 " size='$fldlength'" .
1145 " $string_maxlength" .
1146 " value='$resnote' $disabled />&nbsp;</td>";
1147 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1148 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1149 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1150 } else if ($data_type == 32) {
1151 // input text
1152 echo "<tr><td><input type='text'" .
1153 " name='form_text_$field_id_esc'" .
1154 " id='form_text_$field_id_esc'" .
1155 " size='$fldlength'" .
1156 " class='form-control'" .
1157 " $string_maxlength" .
1158 " value='$resnote' $disabled />&nbsp;</td></tr>";
1159 echo "<td>";
1160 //Selection list for smoking status
1161 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1162 echo generate_select_list(
1163 "form_$field_id",
1164 $list_id,
1165 $reslist,
1166 $description,
1167 ($showEmpty ? $empty_title : ''),
1169 $onchange,
1171 ($disabled ? array('disabled' => 'disabled') : null)
1173 echo "</td>";
1174 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1177 // current
1178 echo "<td class='text' ><input type='radio'" .
1179 " name='radio_{$field_id_esc}'" .
1180 " id='radio_{$field_id_esc}[current]'" .
1181 " class='form-control'" .
1182 " value='current" . $field_id_esc . "' $lbfonchange";
1183 if ($restype == "current" . $field_id) {
1184 echo " checked";
1187 if ($data_type == 32) {
1188 echo " onClick='smoking_statusClicked(this)'";
1191 echo " />" . xlt('Current') . "&nbsp;</td>";
1192 // quit
1193 echo "<td class='text'><input type='radio'" .
1194 " name='radio_{$field_id_esc}'" .
1195 " id='radio_{$field_id_esc}[quit]'" .
1196 " class='form-control'" .
1197 " value='quit".$field_id_esc."' $lbfonchange";
1198 if ($restype == "quit" . $field_id) {
1199 echo " checked";
1202 if ($data_type == 32) {
1203 echo " onClick='smoking_statusClicked(this)'";
1206 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1207 // quit date
1208 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1209 " value='$resdate'" .
1210 " title='$description'" .
1211 " $disabled />";
1212 echo "&nbsp;</td>";
1213 // never
1214 echo "<td class='text'><input type='radio'" .
1215 " name='radio_{$field_id_esc}'" .
1216 " class='form-control'" .
1217 " id='radio_{$field_id_esc}[never]'" .
1218 " value='never" . $field_id_esc . "' $lbfonchange";
1219 if ($restype == "never" . $field_id) {
1220 echo " checked";
1223 if ($data_type == 32) {
1224 echo " onClick='smoking_statusClicked(this)'";
1227 echo " />" . xlt('Never') . "&nbsp;</td>";
1228 // Not Applicable
1229 echo "<td class='text'><input type='radio'" .
1230 " class='form-control' " .
1231 " name='radio_{$field_id}'" .
1232 " id='radio_{$field_id}[not_applicable]'" .
1233 " value='not_applicable" . $field_id . "' $lbfonchange";
1234 if ($restype == "not_applicable" . $field_id) {
1235 echo " checked";
1238 if ($data_type == 32) {
1239 echo " onClick='smoking_statusClicked(this)'";
1242 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1244 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1245 echo "<td class='text' ><div id='smoke_code'></div></td>";
1246 echo "</tr>";
1247 echo "</table>";
1248 } // static text. read-only, of course.
1249 else if ($data_type == 31) {
1250 echo parse_static_text($frow);
1251 } //$data_type == 33
1252 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1253 //$data_type == 33
1255 else if ($data_type == 34) {
1256 $arr = explode("|*|*|*|", $currvalue);
1257 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;'>";
1258 echo "<div id='form_{$field_id}_div' class='text-area' style='min-width:100pt'>" . $arr[0] . "</div>";
1259 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>";
1260 echo "</a>";
1261 } //facilities drop-down list
1262 else if ($data_type == 35) {
1263 if (empty($currvalue)) {
1264 $currvalue = 0;
1267 dropdown_facility(
1268 $selected = $currvalue,
1269 $name = "form_$field_id_esc",
1270 $allow_unspecified = true,
1271 $allow_allfacilities = false,
1272 $disabled,
1273 $lbfchange
1275 } //multiple select
1276 // supports backup list
1277 else if ($data_type == 36) {
1278 echo generate_select_list(
1279 "form_$field_id",
1280 $list_id,
1281 $currvalue,
1282 $description,
1283 $showEmpty ? $empty_title : '',
1285 $lbfchange,
1287 null,
1288 true,
1289 $backup_list
1291 } // Canvas and related elements for browser-side image drawing.
1292 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1293 else if ($data_type == 40) {
1294 // Unlike other field types, width and height are in pixels.
1295 $canWidth = intval($frow['fld_length']);
1296 $canHeight = intval($frow['fld_rows']);
1297 if (empty($currvalue)) {
1298 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1299 // If defined this is the filename of the default starting image.
1300 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1304 $mywidth = 50 + ($canWidth > 250 ? $canWidth : 250);
1305 $myheight = 31 + ($canHeight > 261 ? $canHeight : 261);
1306 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1307 // Hidden form field exists to send updated data to the server at submit time.
1308 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1309 // Hidden image exists to support initialization of the canvas.
1310 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1311 // $date_init is a misnomer but it's the place for browser-side setup logic.
1312 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1316 function generate_print_field($frow, $currvalue)
1318 global $rootdir, $date_init, $ISSUE_TYPES;
1320 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1322 $data_type = $frow['data_type'];
1323 $field_id = $frow['field_id'];
1324 $list_id = $frow['list_id'];
1325 $fld_length = $frow['fld_length'];
1326 $backup_list = $frow['list_backup_id'];
1328 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1330 // Can pass $frow['empty_title'] with this variable, otherwise
1331 // will default to 'Unassigned'.
1332 // If it is 'SKIP' then an empty text title is completely skipped.
1333 $showEmpty = true;
1334 if (isset($frow['empty_title'])) {
1335 if ($frow['empty_title'] == "SKIP") {
1336 //do not display an 'empty' choice
1337 $showEmpty = false;
1338 $empty_title = "Unassigned";
1339 } else {
1340 $empty_title = $frow['empty_title'];
1342 } else {
1343 $empty_title = "Unassigned";
1346 // generic single-selection list
1347 // Supports backup lists.
1348 if (false && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1349 if (empty($fld_length)) {
1350 if ($list_id == 'titles') {
1351 $fld_length = 3;
1352 } else {
1353 $fld_length = 10;
1357 $tmp = '';
1358 if ($currvalue) {
1359 $lrow = sqlQuery("SELECT title FROM list_options " .
1360 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1361 $tmp = xl_list_label($lrow['title']);
1362 if ($lrow == 0 && !empty($backup_list)) {
1363 // since primary list did not map, try to map to backup list
1364 $lrow = sqlQuery("SELECT title FROM list_options " .
1365 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1366 $tmp = xl_list_label($lrow['title']);
1369 if (empty($tmp)) {
1370 $tmp = "($currvalue)";
1374 /*****************************************************************
1375 echo "<input type='text'" .
1376 " size='$fld_length'" .
1377 " value='$tmp'" .
1378 " class='under'" .
1379 " />";
1380 *****************************************************************/
1381 if ($tmp === '') {
1382 $tmp = '&nbsp;';
1383 } else {
1384 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1387 echo $tmp;
1388 } // simple text field
1389 else if ($data_type == 2 || $data_type == 15) {
1390 /*****************************************************************
1391 echo "<input type='text'" .
1392 " size='$fld_length'" .
1393 " value='$currescaped'" .
1394 " class='under'" .
1395 " />";
1396 *****************************************************************/
1397 if ($currescaped === '') {
1398 $currescaped = '&nbsp;';
1401 echo $currescaped;
1402 } // long or multi-line text field
1403 else if ($data_type == 3) {
1404 $fldlength = htmlspecialchars($fld_length, ENT_QUOTES);
1405 $maxlength = htmlspecialchars($frow['fld_rows'], ENT_QUOTES);
1406 echo "<textarea" .
1407 " class='form-control' " .
1408 " cols='$fldlength'" .
1409 " rows='$maxlength'>" .
1410 $currescaped . "</textarea>";
1411 } // date
1412 else if ($data_type == 4) {
1413 $age_asof_date = '';
1414 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
1415 if ($currvalue === '') {
1416 echo '&nbsp;';
1417 } else {
1418 echo text(oeFormatShortDate($currvalue));
1419 if ($agestr) {
1420 echo "&nbsp;(" . text($agestr) . ")";
1423 } // provider list
1424 else if ($data_type == 10 || $data_type == 11) {
1425 $tmp = '';
1426 if ($currvalue) {
1427 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1428 "WHERE id = ?", array($currvalue));
1429 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1430 if (empty($tmp)) {
1431 $tmp = "($currvalue)";
1435 /*****************************************************************
1436 echo "<input type='text'" .
1437 " size='$fld_length'" .
1438 " value='$tmp'" .
1439 " class='under'" .
1440 " />";
1441 *****************************************************************/
1442 if ($tmp === '') {
1443 $tmp = '&nbsp;';
1444 } else {
1445 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1448 echo $tmp;
1449 } // pharmacy list
1450 else if ($data_type == 12) {
1451 $tmp = '';
1452 if ($currvalue) {
1453 $pres = get_pharmacies();
1454 while ($prow = sqlFetchArray($pres)) {
1455 $key = $prow['id'];
1456 if ($currvalue == $key) {
1457 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1458 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1459 $prow['line1'] . ' / ' . $prow['city'];
1463 if (empty($tmp)) {
1464 $tmp = "($currvalue)";
1468 /*****************************************************************
1469 echo "<input type='text'" .
1470 " size='$fld_length'" .
1471 " value='$tmp'" .
1472 " class='under'" .
1473 " />";
1474 *****************************************************************/
1475 if ($tmp === '') {
1476 $tmp = '&nbsp;';
1477 } else {
1478 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1481 echo $tmp;
1482 } // squads
1483 else if ($data_type == 13) {
1484 $tmp = '';
1485 if ($currvalue) {
1486 $squads = acl_get_squads();
1487 if ($squads) {
1488 foreach ($squads as $key => $value) {
1489 if ($currvalue == $key) {
1490 $tmp = $value[3];
1495 if (empty($tmp)) {
1496 $tmp = "($currvalue)";
1500 /*****************************************************************
1501 echo "<input type='text'" .
1502 " size='$fld_length'" .
1503 " value='$tmp'" .
1504 " class='under'" .
1505 " />";
1506 *****************************************************************/
1507 if ($tmp === '') {
1508 $tmp = '&nbsp;';
1509 } else {
1510 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1513 echo $tmp;
1514 } // Address book.
1515 else if ($data_type == 14) {
1516 $tmp = '';
1517 if ($currvalue) {
1518 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1519 "WHERE id = ?", array($currvalue));
1520 $uname = $urow['lname'];
1521 if ($urow['fname']) {
1522 $uname .= ", " . $urow['fname'];
1525 $tmp = $uname;
1526 if (empty($tmp)) {
1527 $tmp = "($currvalue)";
1531 /*****************************************************************
1532 echo "<input type='text'" .
1533 " size='$fld_length'" .
1534 " value='$tmp'" .
1535 " class='under'" .
1536 " />";
1537 *****************************************************************/
1538 if ($tmp === '') {
1539 $tmp = '&nbsp;';
1540 } else {
1541 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1544 echo $tmp;
1545 } // insurance company list
1546 else if ($data_type == 16) {
1547 $tmp = '';
1548 if ($currvalue) {
1549 $insprovs = getInsuranceProviders();
1550 foreach ($insprovs as $key => $ipname) {
1551 if ($currvalue == $key) {
1552 $tmp = $ipname;
1556 if (empty($tmp)) {
1557 $tmp = "($currvalue)";
1561 if ($tmp === '') {
1562 $tmp = '&nbsp;';
1563 } else {
1564 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1567 echo $tmp;
1568 } // issue types
1569 else if ($data_type == 17) {
1570 $tmp = '';
1571 if ($currvalue) {
1572 foreach ($ISSUE_TYPES as $key => $value) {
1573 if ($currvalue == $key) {
1574 $tmp = $value[1];
1578 if (empty($tmp)) {
1579 $tmp = "($currvalue)";
1583 if ($tmp === '') {
1584 $tmp = '&nbsp;';
1585 } else {
1586 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1589 echo $tmp;
1590 } // Visit categories.
1591 else if ($data_type == 18) {
1592 $tmp = '';
1593 if ($currvalue) {
1594 $crow = sqlQuery(
1595 "SELECT pc_catid, pc_catname " .
1596 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1597 array($currvalue)
1599 $tmp = xl_appt_category($crow['pc_catname']);
1600 if (empty($tmp)) {
1601 $tmp = "($currvalue)";
1605 if ($tmp === '') {
1606 $tmp = '&nbsp;';
1607 } else {
1608 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1611 echo $tmp;
1612 } // a single checkbox or set of labeled checkboxes
1613 else if ($data_type == 21) {
1614 if (!$list_id) {
1615 echo "<input type='checkbox'";
1616 if ($currvalue) {
1617 echo " checked";
1619 echo " />";
1620 } else {
1621 // In this special case, fld_length is the number of columns generated.
1622 $cols = max(1, $fld_length);
1623 $avalue = explode('|', $currvalue);
1624 $lres = sqlStatement("SELECT * FROM list_options " .
1625 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1626 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1627 $tdpct = (int) (100 / $cols);
1628 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1629 $option_id = $lrow['option_id'];
1630 if ($count % $cols == 0) {
1631 if ($count) {
1632 echo "</tr>";
1635 echo "<tr>";
1637 echo "<td width='" . attr($tdpct) . "%'>";
1638 echo "<input type='checkbox'";
1639 if (in_array($option_id, $avalue)) {
1640 echo " checked";
1642 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1643 echo "</td>";
1645 if ($count) {
1646 echo "</tr>";
1647 if ($count > $cols) {
1648 // Add some space after multiple rows of checkboxes.
1649 $cols = htmlspecialchars($cols, ENT_QUOTES);
1650 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1653 echo "</table>";
1655 } // a set of labeled text input fields
1656 else if ($data_type == 22) {
1657 $tmp = explode('|', $currvalue);
1658 $avalue = array();
1659 foreach ($tmp as $value) {
1660 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1661 $avalue[$matches[1]] = $matches[2];
1665 $lres = sqlStatement("SELECT * FROM list_options " .
1666 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1667 echo "<table cellpadding='0' cellspacing='0'>";
1668 while ($lrow = sqlFetchArray($lres)) {
1669 $option_id = $lrow['option_id'];
1670 $fldlength = empty($fld_length) ? 20 : $fld_length;
1671 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1672 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1673 $inputValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
1674 echo "<td><input type='text'" .
1675 " class='form-control' " .
1676 " size='$fldlength'" .
1677 " value='$inputValue'" .
1678 " class='under'" .
1679 " /></td></tr>";
1682 echo "</table>";
1683 } // a set of exam results; 3 radio buttons and a text field:
1684 else if ($data_type == 23) {
1685 $tmp = explode('|', $currvalue);
1686 $avalue = array();
1687 foreach ($tmp as $value) {
1688 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1689 $avalue[$matches[1]] = $matches[2];
1693 $fldlength = empty($fld_length) ? 20 : $fld_length;
1694 $lres = sqlStatement("SELECT * FROM list_options " .
1695 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1696 echo "<table cellpadding='0' cellspacing='0'>";
1697 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1698 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
1699 "&nbsp;</td><td class='bold'>" .
1700 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1701 "<td class='bold'>" .
1702 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1703 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1704 while ($lrow = sqlFetchArray($lres)) {
1705 $option_id = $lrow['option_id'];
1706 $restype = substr($avalue[$option_id], 0, 1);
1707 $resnote = substr($avalue[$option_id], 2);
1708 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1709 for ($i = 0; $i < 3; ++$i) {
1710 echo "<td><input type='radio'";
1711 if ($restype === "$i") {
1712 echo " checked";
1715 echo " /></td>";
1718 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1719 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1720 echo "<td><input type='text'" .
1721 " size='$fldlength'" .
1722 " value='$resnote'" .
1723 " class='under form-control' /></td>" .
1724 "</tr>";
1727 echo "</table>";
1728 } // the list of active allergies for the current patient
1729 // this is read-only!
1730 else if ($data_type == 24) {
1731 $query = "SELECT title, comments FROM lists WHERE " .
1732 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1733 "ORDER BY begdate";
1734 $lres = sqlStatement($query, array($GLOBALS['pid']));
1735 $count = 0;
1736 while ($lrow = sqlFetchArray($lres)) {
1737 if ($count++) {
1738 echo "<br />";
1741 echo htmlspecialchars($lrow['title'], ENT_QUOTES);
1742 if ($lrow['comments']) {
1743 echo htmlspecialchars(' (' . $lrow['comments'] . ')', ENT_QUOTES);
1746 } // a set of labeled checkboxes, each with a text field:
1747 else if ($data_type == 25) {
1748 $tmp = explode('|', $currvalue);
1749 $avalue = array();
1750 foreach ($tmp as $value) {
1751 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1752 $avalue[$matches[1]] = $matches[2];
1756 $fldlength = empty($fld_length) ? 20 : $fld_length;
1757 $lres = sqlStatement("SELECT * FROM list_options " .
1758 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1759 echo "<table cellpadding='0' cellspacing='0'>";
1760 while ($lrow = sqlFetchArray($lres)) {
1761 $option_id = $lrow['option_id'];
1762 $restype = substr($avalue[$option_id], 0, 1);
1763 $resnote = substr($avalue[$option_id], 2);
1764 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1765 echo "<td><input type='checkbox'";
1766 if ($restype) {
1767 echo " checked";
1770 echo " />&nbsp;</td>";
1771 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1772 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1773 echo "<td><input type='text'" .
1774 " size='$fldlength'" .
1775 " class='form-control' " .
1776 " value='$resnote'" .
1777 " class='under'" .
1778 " /></td>" .
1779 "</tr>";
1782 echo "</table>";
1783 } // a set of labeled radio buttons
1784 else if ($data_type == 27 || $data_type == 1 || $data_type == 26 || $data_type == 33) {
1785 // In this special case, fld_length is the number of columns generated.
1786 $cols = max(1, $frow['fld_length']);
1787 $lres = sqlStatement("SELECT * FROM list_options " .
1788 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1789 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1790 $tdpct = (int) (100 / $cols);
1791 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1792 $option_id = $lrow['option_id'];
1793 if ($count % $cols == 0) {
1794 if ($count) {
1795 echo "</tr>";
1798 echo "<tr>";
1800 echo "<td width='" . attr($tdpct) . "%'>";
1801 echo "<input type='radio'";
1802 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1803 // Do not use defaults for these printable forms.
1804 echo " checked";
1807 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1808 echo "</td>";
1811 if ($count) {
1812 echo "</tr>";
1813 if ($count > $cols) {
1814 // Add some space after multiple rows of radio buttons.
1815 $cols = htmlspecialchars($cols, ENT_QUOTES);
1816 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1820 echo "</table>";
1821 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1822 else if ($data_type == 28 || $data_type == 32) {
1823 $tmp = explode('|', $currvalue);
1824 switch (count($tmp)) {
1825 case "4":
1826 $resnote = $tmp[0];
1827 $restype = $tmp[1];
1828 $resdate = $tmp[2];
1829 $reslist = $tmp[3];
1830 break;
1831 case "3":
1832 $resnote = $tmp[0];
1833 $restype = $tmp[1];
1834 $resdate = $tmp[2];
1835 break;
1836 case "2":
1837 $resnote = $tmp[0];
1838 $restype = $tmp[1];
1839 $resdate = "";
1840 break;
1841 case "1":
1842 $resnote = $tmp[0];
1843 $resdate = $restype = "";
1844 break;
1845 default:
1846 $restype = $resdate = $resnote = "";
1847 break;
1850 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1851 echo "<table cellpadding='0' cellspacing='0'>";
1852 echo "<tr>";
1853 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1854 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1855 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1856 if ($data_type == 28) {
1857 echo "<td><input type='text'" .
1858 " size='$fldlength'" .
1859 " class='under'" .
1860 " value='$resnote' /></td>";
1861 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1862 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1863 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1864 } else if ($data_type == 32) {
1865 echo "<tr><td><input type='text'" .
1866 " size='$fldlength'" .
1867 " class='under form-control'" .
1868 " value='$resnote' /></td></tr>";
1869 $fldlength = 30;
1870 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
1871 echo "<td><input type='text'" .
1872 " size='$fldlength'" .
1873 " class='under form-control'" .
1874 " value='$smoking_status_title' /></td>";
1875 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1878 echo "<td><input type='radio' class='form-control'";
1879 if ($restype == "current".$field_id) {
1880 echo " checked";
1883 echo "/>".htmlspecialchars(xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1885 echo "<td><input type='radio' class='form-control'";
1886 if ($restype == "current".$field_id) {
1887 echo " checked";
1890 echo "/>".htmlspecialchars(xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1892 echo "<td><input type='text' size='6'" .
1893 " value='$resdate'" .
1894 " class='under form-control'" .
1895 " /></td>";
1897 echo "<td><input type='radio' class='form-control'";
1898 if ($restype == "current".$field_id) {
1899 echo " checked";
1902 echo " />".htmlspecialchars(xl('Never'), ENT_NOQUOTES)."</td>";
1904 echo "<td><input type='radio' class='form-control'";
1905 if ($restype == "not_applicable".$field_id) {
1906 echo " checked";
1909 echo " />".htmlspecialchars(xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1910 echo "</tr>";
1911 echo "</table>";
1912 } // static text. read-only, of course.
1913 else if ($data_type == 31) {
1914 echo parse_static_text($frow);
1915 } else if ($data_type == 34) {
1916 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;'>";
1917 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1918 echo "<div style='display:none'><textarea name='form_{$field_id}' class='form-control' id='form_{$field_id}' stye='display:none'></textarea></div>";
1919 echo "</a>";
1920 } //facilities drop-down list
1921 else if ($data_type == 35) {
1922 // In this special case, fld_length is the number of columns generated.
1923 $cols = max(1, $frow['fld_length']);
1924 $lres = sqlStatement("SELECT id, name FROM facility ORDER BY name");
1925 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1926 $tdpct = (int) (100 / $cols);
1927 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1928 $option_id = $lrow['id'];
1929 if ($count % $cols == 0) {
1930 if ($count) {
1931 echo "</tr>";
1933 echo "<tr>";
1935 echo "<td width='" . attr($tdpct) . "%'>";
1936 echo "<input type='radio'";
1937 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1938 // Do not use defaults for these printable forms.
1939 echo " checked";
1941 echo ">" . htmlspecialchars($lrow['name']);
1942 echo "</td>";
1944 if ($count) {
1945 echo "</tr>";
1946 if ($count > $cols) {
1947 // Add some space after multiple rows of radio buttons.
1948 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1951 echo "</table>";
1952 } //Multi-select
1953 // Supports backup lists.
1954 else if ($data_type == 36) {
1955 if (empty($fld_length)) {
1956 if ($list_id == 'titles') {
1957 $fld_length = 3;
1958 } else {
1959 $fld_length = 10;
1963 $tmp = '';
1965 $values_array = explode("|", $currvalue);
1967 $i=0;
1968 foreach ($values_array as $value) {
1969 if ($value) {
1970 $lrow = sqlQuery("SELECT title FROM list_options " .
1971 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1972 $tmp = xl_list_label($lrow['title']);
1973 if ($lrow == 0 && !empty($backup_list)) {
1974 // since primary list did not map, try to map to backup list
1975 $lrow = sqlQuery("SELECT title FROM list_options " .
1976 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1977 $tmp = xl_list_label($lrow['title']);
1980 if (empty($tmp)) {
1981 $tmp = "($value)";
1985 if ($tmp === '') {
1986 $tmp = '&nbsp;';
1987 } else {
1988 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1991 if ($i != 0 && $tmp != '&nbsp;') {
1992 echo ",";
1995 echo $tmp;
1996 $i++;
1998 } // Image from canvas drawing
1999 else if ($data_type == 40) {
2000 if ($currvalue) {
2001 echo "<img src='" . attr($currvalue) . "'>";
2006 function generate_display_field($frow, $currvalue)
2008 global $ISSUE_TYPES, $facilityService;
2010 $data_type = $frow['data_type'];
2011 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2012 $list_id = $frow['list_id'];
2013 $backup_list = isset($frow['list_backup_id']) ? $frow['list_backup_id'] : null;
2015 $s = '';
2017 // generic selection list or the generic selection list with add on the fly
2018 // feature
2019 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
2020 $lrow = sqlQuery("SELECT title FROM list_options " .
2021 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2022 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2023 //if there is no matching value in the corresponding lists check backup list
2024 // only supported in data types 1,26,33
2025 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2026 $lrow = sqlQuery("SELECT title FROM list_options " .
2027 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2028 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2030 } // simple text field
2031 else if ($data_type == 2) {
2032 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2033 } // long or multi-line text field
2034 else if ($data_type == 3) {
2035 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2036 } // date
2037 else if ($data_type == 4) {
2038 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
2039 $s = '';
2040 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2041 $age_asof_date = '';
2042 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
2043 if ($currvalue === '') {
2044 $s .= '&nbsp;';
2045 } else {
2046 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
2047 if (!$modtmp) {
2048 $s .= text(oeFormatShortDate($currvalue));
2049 } else {
2050 $s .= text(oeFormatDateTime($currvalue));
2052 if ($agestr) {
2053 $s .= "&nbsp;(" . text($agestr) . ")";
2056 } // provider
2057 else if ($data_type == 10 || $data_type == 11) {
2058 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2059 "WHERE id = ?", array($currvalue));
2060 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']), ENT_NOQUOTES);
2061 } // pharmacy list
2062 else if ($data_type == 12) {
2063 $pres = get_pharmacies();
2064 while ($prow = sqlFetchArray($pres)) {
2065 $key = $prow['id'];
2066 if ($currvalue == $key) {
2067 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
2068 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2069 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
2072 } // squads
2073 else if ($data_type == 13) {
2074 $squads = acl_get_squads();
2075 if ($squads) {
2076 foreach ($squads as $key => $value) {
2077 if ($currvalue == $key) {
2078 $s .= htmlspecialchars($value[3], ENT_NOQUOTES);
2082 } // address book
2083 else if ($data_type == 14) {
2084 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
2085 "WHERE id = ?", array($currvalue));
2086 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
2087 if ($urow['organization'] !="") {
2088 $uname = $urow['organization'];
2089 } else {
2090 $uname = $urow['lname'];
2091 if ($urow['fname']) {
2092 $uname .= ", " . $urow['fname'];
2096 $s = htmlspecialchars($uname, ENT_NOQUOTES);
2097 } // billing code
2098 else if ($data_type == 15) {
2099 $s = '';
2100 if (!empty($currvalue)) {
2101 $relcodes = explode(';', $currvalue);
2102 foreach ($relcodes as $codestring) {
2103 if ($codestring === '') {
2104 continue;
2106 $tmp = lookup_code_descriptions($codestring);
2107 if ($s !== '') {
2108 $s .= '; ';
2110 if (!empty($tmp)) {
2111 $s .= $tmp;
2112 } else {
2113 $s .= $codestring . ' (' . xl('not found') . ')';
2117 } // insurance company list
2118 else if ($data_type == 16) {
2119 $insprovs = getInsuranceProviders();
2120 foreach ($insprovs as $key => $ipname) {
2121 if ($currvalue == $key) {
2122 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
2125 } // issue types
2126 else if ($data_type == 17) {
2127 foreach ($ISSUE_TYPES as $key => $value) {
2128 if ($currvalue == $key) {
2129 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
2132 } // visit category
2133 else if ($data_type == 18) {
2134 $crow = sqlQuery(
2135 "SELECT pc_catid, pc_catname " .
2136 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2137 array($currvalue)
2139 $s = htmlspecialchars($crow['pc_catname'], ENT_NOQUOTES);
2140 } // a single checkbox or set of labeled checkboxes
2141 else if ($data_type == 21) {
2142 if (!$list_id) {
2143 $s .= $currvalue ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2144 } else {
2145 // In this special case, fld_length is the number of columns generated.
2146 $cols = max(1, $frow['fld_length']);
2147 $avalue = explode('|', $currvalue);
2148 $lres = sqlStatement("SELECT * FROM list_options " .
2149 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2150 $s .= "<table cellspacing='0' cellpadding='0'>";
2151 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2152 $option_id = $lrow['option_id'];
2153 $option_id_esc = text($option_id);
2154 if ($count % $cols == 0) {
2155 if ($count) {
2156 $s .= "</tr>";
2158 $s .= "<tr>";
2160 $s .= "<td nowrap>";
2161 $checked = in_array($option_id, $avalue);
2162 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2163 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2164 $s .= "</td>";
2166 if ($count) {
2167 $s .= "</tr>";
2169 $s .= "</table>";
2171 } // a set of labeled text input fields
2172 else if ($data_type == 22) {
2173 $tmp = explode('|', $currvalue);
2174 $avalue = array();
2175 foreach ($tmp as $value) {
2176 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2177 $avalue[$matches[1]] = $matches[2];
2181 $lres = sqlStatement("SELECT * FROM list_options " .
2182 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2183 $s .= "<table cellpadding='0' cellspacing='0'>";
2184 while ($lrow = sqlFetchArray($lres)) {
2185 $option_id = $lrow['option_id'];
2186 if (empty($avalue[$option_id])) {
2187 continue;
2190 // Added 5-09 by BM - Translate label if applicable
2191 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . ":&nbsp;</td>";
2193 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id], ENT_NOQUOTES) . "</td></tr>";
2196 $s .= "</table>";
2197 } // a set of exam results; 3 radio buttons and a text field:
2198 else if ($data_type == 23) {
2199 $tmp = explode('|', $currvalue);
2200 $avalue = array();
2201 foreach ($tmp as $value) {
2202 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2203 $avalue[$matches[1]] = $matches[2];
2207 $lres = sqlStatement("SELECT * FROM list_options " .
2208 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2209 $s .= "<table cellpadding='0' cellspacing='0'>";
2210 while ($lrow = sqlFetchArray($lres)) {
2211 $option_id = $lrow['option_id'];
2212 $restype = substr($avalue[$option_id], 0, 1);
2213 $resnote = substr($avalue[$option_id], 2);
2214 if (empty($restype) && empty($resnote)) {
2215 continue;
2218 // Added 5-09 by BM - Translate label if applicable
2219 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2221 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
2222 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2223 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2224 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2225 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2226 $s .= "</tr>";
2229 $s .= "</table>";
2230 } // the list of active allergies for the current patient
2231 else if ($data_type == 24) {
2232 $query = "SELECT title, comments FROM lists WHERE " .
2233 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2234 "ORDER BY begdate";
2235 // echo "<!-- $query -->\n"; // debugging
2236 $lres = sqlStatement($query, array($GLOBALS['pid']));
2237 $count = 0;
2238 while ($lrow = sqlFetchArray($lres)) {
2239 if ($count++) {
2240 $s .= "<br />";
2243 $s .= htmlspecialchars($lrow['title'], ENT_NOQUOTES);
2244 if ($lrow['comments']) {
2245 $s .= ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
2248 } // a set of labeled checkboxes, each with a text field:
2249 else if ($data_type == 25) {
2250 $tmp = explode('|', $currvalue);
2251 $avalue = array();
2252 foreach ($tmp as $value) {
2253 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2254 $avalue[$matches[1]] = $matches[2];
2258 $lres = sqlStatement("SELECT * FROM list_options " .
2259 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2260 $s .= "<table cellpadding='0' cellspacing='0'>";
2261 while ($lrow = sqlFetchArray($lres)) {
2262 $option_id = $lrow['option_id'];
2263 $restype = substr($avalue[$option_id], 0, 1);
2264 $resnote = substr($avalue[$option_id], 2);
2265 if (empty($restype) && empty($resnote)) {
2266 continue;
2269 // Added 5-09 by BM - Translate label if applicable
2270 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2272 $restype = $restype ? xl('Yes') : xl('No');
2273 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2274 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2275 $s .= "</tr>";
2278 $s .= "</table>";
2279 } // a set of labeled radio buttons
2280 else if ($data_type == 27) {
2281 // In this special case, fld_length is the number of columns generated.
2282 $cols = max(1, $frow['fld_length']);
2283 $lres = sqlStatement("SELECT * FROM list_options " .
2284 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2285 $s .= "<table cellspacing='0' cellpadding='0'>";
2286 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2287 $option_id = $lrow['option_id'];
2288 $option_id_esc = text($option_id);
2289 if ($count % $cols == 0) {
2290 if ($count) {
2291 $s .= "</tr>";
2293 $s .= "<tr>";
2295 $s .= "<td>";
2296 $checked = ((strlen($currvalue) == 0 && $lrow['is_default']) ||
2297 (strlen($currvalue) > 0 && $option_id == $currvalue));
2298 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2299 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2300 $s .= "</td>";
2302 if ($count) {
2303 $s .= "</tr>";
2305 $s .= "</table>";
2306 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2307 // VicarePlus :: A selection list for smoking status.
2308 else if ($data_type == 28 || $data_type == 32) {
2309 $tmp = explode('|', $currvalue);
2310 switch (count($tmp)) {
2311 case "4":
2312 $resnote = $tmp[0];
2313 $restype = $tmp[1];
2314 $resdate = $tmp[2];
2315 $reslist = $tmp[3];
2316 break;
2317 case "3":
2318 $resnote = $tmp[0];
2319 $restype = $tmp[1];
2320 $resdate = $tmp[2];
2321 break;
2322 case "2":
2323 $resnote = $tmp[0];
2324 $restype = $tmp[1];
2325 $resdate = "";
2326 break;
2327 case "1":
2328 $resnote = $tmp[0];
2329 $resdate = $restype = "";
2330 break;
2331 default:
2332 $restype = $resdate = $resnote = "";
2333 break;
2336 $s .= "<table cellpadding='0' cellspacing='0'>";
2338 $s .= "<tr>";
2339 $res = "";
2340 if ($restype == "current".$field_id) {
2341 $res = xl('Current');
2344 if ($restype == "quit".$field_id) {
2345 $res = xl('Quit');
2348 if ($restype == "never".$field_id) {
2349 $res = xl('Never');
2352 if ($restype == "not_applicable".$field_id) {
2353 $res = xl('N/A');
2356 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2357 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2358 if ($data_type == 28) {
2359 if (!empty($resnote)) {
2360 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2362 } //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2363 else if ($data_type == 32) {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2364 $smoke_codes = getSmokeCodes();
2365 if (!empty($reslist)) {
2366 if ($smoke_codes[$reslist]!="") {
2367 $code_desc = "( ".$smoke_codes[$reslist]." )";
2370 $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>";
2373 if (!empty($resnote)) {
2374 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2378 if (!empty($res)) {
2379 $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'), ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res, ENT_NOQUOTES) . "&nbsp;</td>";
2382 if ($restype == "quit".$field_id) {
2383 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate, ENT_NOQUOTES) . "&nbsp;</td>";
2386 $s .= "</tr>";
2387 $s .= "</table>";
2388 } // static text. read-only, of course.
2389 else if ($data_type == 31) {
2390 $s .= parse_static_text($frow);
2391 } else if ($data_type == 34) {
2392 $arr = explode("|*|*|*|", $currvalue);
2393 for ($i=0; $i<sizeof($arr); $i++) {
2394 $s.=$arr[$i];
2396 } // facility
2397 else if ($data_type == 35) {
2398 $urow = $facilityService->getById($currvalue);
2399 $s = htmlspecialchars($urow['name'], ENT_NOQUOTES);
2400 } // Multi select
2401 // Supports backup lists
2402 else if ($data_type == 36) {
2403 $values_array = explode("|", $currvalue);
2404 $i = 0;
2405 foreach ($values_array as $value) {
2406 $lrow = sqlQuery("SELECT title FROM list_options " .
2407 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2408 if ($lrow == 0 && !empty($backup_list)) {
2409 //use back up list
2410 $lrow = sqlQuery("SELECT title FROM list_options " .
2411 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2414 if ($i > 0) {
2415 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2416 } else {
2417 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2420 $i++;
2422 } // Image from canvas drawing
2423 else if ($data_type == 40) {
2424 if ($currvalue) {
2425 $s .= "<img src='" . attr($currvalue) . "'>";
2429 return $s;
2432 // Generate plain text versions of selected LBF field types.
2433 // Currently used by interface/patient_file/download_template.php and interface/main/finder/dynamic_finder_ajax.php.
2434 // More field types might need to be supported here in the future.
2436 function generate_plaintext_field($frow, $currvalue)
2438 global $ISSUE_TYPES;
2440 $data_type = $frow['data_type'];
2441 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2442 $list_id = $frow['list_id'];
2443 $backup_list = $frow['backup_list'];
2444 $s = '';
2446 // generic selection list or the generic selection list with add on the fly
2447 // feature, or radio buttons
2448 // Supports backup lists (for datatypes 1,26,33)
2449 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2450 $lrow = sqlQuery("SELECT title FROM list_options " .
2451 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2452 $s = xl_list_label($lrow['title']);
2453 //if there is no matching value in the corresponding lists check backup list
2454 // only supported in data types 1,26,33
2455 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2456 $lrow = sqlQuery("SELECT title FROM list_options " .
2457 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2458 $s = xl_list_label($lrow['title']);
2460 } // simple or long text field
2461 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2462 $s = $currvalue;
2463 } // date
2464 else if ($data_type == 4) {
2465 $s = oeFormatShortDate($currvalue);
2466 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2467 $age_asof_date = '';
2468 // Optional display of age or gestational age.
2469 $tmp = optionalAge($frow, $currvalue, $age_asof_date, $description);
2470 if ($tmp) {
2471 $s .= ' ' . $tmp;
2473 } // provider
2474 else if ($data_type == 10 || $data_type == 11) {
2475 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2476 "WHERE id = ?", array($currvalue));
2477 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2478 } // pharmacy list
2479 else if ($data_type == 12) {
2480 $pres = get_pharmacies();
2481 while ($prow = sqlFetchArray($pres)) {
2482 $key = $prow['id'];
2483 if ($currvalue == $key) {
2484 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2485 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2486 $prow['line1'] . ' / ' . $prow['city'];
2489 } // address book
2490 else if ($data_type == 14) {
2491 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2492 "WHERE id = ?", array($currvalue));
2493 $uname = $urow['lname'];
2494 if ($urow['fname']) {
2495 $uname .= ", " . $urow['fname'];
2498 $s = $uname;
2499 } // insurance company list
2500 else if ($data_type == 16) {
2501 $insprovs = getInsuranceProviders();
2502 foreach ($insprovs as $key => $ipname) {
2503 if ($currvalue == $key) {
2504 $s .= $ipname;
2507 } // issue type
2508 else if ($data_type == 17) {
2509 foreach ($ISSUE_TYPES as $key => $value) {
2510 if ($currvalue == $key) {
2511 $s .= $value[1];
2514 } // visit category
2515 else if ($data_type == 18) {
2516 $crow = sqlQuery(
2517 "SELECT pc_catid, pc_catname " .
2518 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2519 array($currvalue)
2521 $s = $crow['pc_catname'];
2522 } // a set of labeled checkboxes
2523 else if ($data_type == 21) {
2524 if (!$list_id) {
2525 $s .= $currvalue ? xlt('Yes') : xlt('No');
2526 } else {
2527 $avalue = explode('|', $currvalue);
2528 $lres = sqlStatement("SELECT * FROM list_options " .
2529 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2530 $count = 0;
2531 while ($lrow = sqlFetchArray($lres)) {
2532 $option_id = $lrow['option_id'];
2533 if (in_array($option_id, $avalue)) {
2534 if ($count++) {
2535 $s .= "; ";
2537 $s .= xl_list_label($lrow['title']);
2541 } // a set of labeled text input fields
2542 else if ($data_type == 22) {
2543 $tmp = explode('|', $currvalue);
2544 $avalue = array();
2545 foreach ($tmp as $value) {
2546 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2547 $avalue[$matches[1]] = $matches[2];
2551 $lres = sqlStatement("SELECT * FROM list_options " .
2552 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2553 while ($lrow = sqlFetchArray($lres)) {
2554 $option_id = $lrow['option_id'];
2555 if (empty($avalue[$option_id])) {
2556 continue;
2559 if ($s !== '') {
2560 $s .= '; ';
2563 $s .= xl_list_label($lrow['title']) . ': ';
2564 $s .= $avalue[$option_id];
2566 } // A set of exam results; 3 radio buttons and a text field.
2567 // This shows abnormal results only.
2568 else if ($data_type == 23) {
2569 $tmp = explode('|', $currvalue);
2570 $avalue = array();
2571 foreach ($tmp as $value) {
2572 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2573 $avalue[$matches[1]] = $matches[2];
2577 $lres = sqlStatement("SELECT * FROM list_options " .
2578 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2579 while ($lrow = sqlFetchArray($lres)) {
2580 $option_id = $lrow['option_id'];
2581 $restype = substr($avalue[$option_id], 0, 1);
2582 $resnote = substr($avalue[$option_id], 2);
2583 if (empty($restype) && empty($resnote)) {
2584 continue;
2587 if ($restype != '2') {
2588 continue; // show abnormal results only
2591 if ($s !== '') {
2592 $s .= '; ';
2595 $s .= xl_list_label($lrow['title']);
2596 if (!empty($resnote)) {
2597 $s .= ': ' . $resnote;
2600 } // the list of active allergies for the current patient
2601 else if ($data_type == 24) {
2602 $query = "SELECT title, comments FROM lists WHERE " .
2603 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2604 "ORDER BY begdate";
2605 $lres = sqlStatement($query, array($GLOBALS['pid']));
2606 $count = 0;
2607 while ($lrow = sqlFetchArray($lres)) {
2608 if ($count++) {
2609 $s .= "; ";
2612 $s .= $lrow['title'];
2613 if ($lrow['comments']) {
2614 $s .= ' (' . $lrow['comments'] . ')';
2617 } // a set of labeled checkboxes, each with a text field:
2618 else if ($data_type == 25) {
2619 $tmp = explode('|', $currvalue);
2620 $avalue = array();
2621 foreach ($tmp as $value) {
2622 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2623 $avalue[$matches[1]] = $matches[2];
2627 $lres = sqlStatement("SELECT * FROM list_options " .
2628 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2629 while ($lrow = sqlFetchArray($lres)) {
2630 $option_id = $lrow['option_id'];
2631 $restype = substr($avalue[$option_id], 0, 1);
2632 $resnote = substr($avalue[$option_id], 2);
2633 if (empty($restype) && empty($resnote)) {
2634 continue;
2637 if ($s !== '') {
2638 $s .= '; ';
2641 $s .= xl_list_label($lrow['title']);
2642 $restype = $restype ? xl('Yes') : xl('No');
2643 $s .= $restype;
2644 if ($resnote) {
2645 $s .= ' ' . $resnote;
2648 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2649 // VicarePlus :: A selection list for smoking status.
2650 else if ($data_type == 28 || $data_type == 32) {
2651 $tmp = explode('|', $currvalue);
2652 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2653 $restype = count($tmp) > 1 ? $tmp[1] : '';
2654 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2655 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2656 $res = "";
2657 if ($restype == "current" . $field_id) {
2658 $res = xl('Current');
2661 if ($restype == "quit" . $field_id) {
2662 $res = xl('Quit');
2665 if ($restype == "never" . $field_id) {
2666 $res = xl('Never');
2669 if ($restype == "not_applicable". $field_id) {
2670 $res = xl('N/A');
2673 if ($data_type == 28) {
2674 if (!empty($resnote)) {
2675 $s .= $resnote;
2677 } // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2678 else if ($data_type == 32) {
2679 if (!empty($reslist)) {
2680 $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
2683 if (!empty($resnote)) {
2684 $s .= ' ' . $resnote;
2688 if (!empty($res)) {
2689 if ($s !== '') {
2690 $s .= ' ';
2693 $s .= xl('Status') . ' ' . $res;
2696 if ($restype == "quit".$field_id) {
2697 if ($s !== '') {
2698 $s .= ' ';
2701 $s .= $resdate;
2703 } // Multi select
2704 // Supports backup lists
2705 else if ($data_type == 36) {
2706 $values_array = explode("|", $currvalue);
2708 $i = 0;
2709 foreach ($values_array as $value) {
2710 $lrow = sqlQuery("SELECT title FROM list_options " .
2711 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2713 if ($lrow == 0 && !empty($backup_list)) {
2714 //use back up list
2715 $lrow = sqlQuery("SELECT title FROM list_options " .
2716 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2719 if ($i > 0) {
2720 $s = $s . ", " . xl_list_label($lrow['title']);
2721 } else {
2722 $s = xl_list_label($lrow['title']);
2725 $i++;
2729 return $s;
2732 $CPR = 4; // cells per row of generic data
2733 $last_group = '';
2734 $cell_count = 0;
2735 $item_count = 0;
2737 function disp_end_cell()
2739 global $item_count, $cell_count;
2740 if ($item_count > 0) {
2741 echo "</td>";
2742 $item_count = 0;
2746 function disp_end_row()
2748 global $cell_count, $CPR;
2749 disp_end_cell();
2750 if ($cell_count > 0) {
2751 for (; $cell_count < $CPR;
2752 ++$cell_count) {
2753 echo "<td></td>";
2756 echo "</tr>\n";
2757 $cell_count = 0;
2761 function disp_end_group()
2763 global $last_group;
2764 if (strlen($last_group) > 0) {
2765 disp_end_row();
2769 // Accumulate action conditions into a JSON expression for the browser side.
2770 function accumActionConditions($field_id, &$condition_str, &$condarr)
2772 $conditions = empty($condarr) ? array() : unserialize($condarr);
2773 $action = 'skip';
2774 foreach ($conditions as $key => $condition) {
2775 if ($key === 'action') {
2776 // If specified this should be the first array item.
2777 if ($condition) {
2778 $action = $condition;
2780 continue;
2782 if (empty($condition['id'])) {
2783 continue;
2785 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2786 if ($condition_str) {
2787 $condition_str .= ",\n";
2789 $condition_str .= "{" .
2790 "target:'" . addslashes($field_id) . "', " .
2791 "action:'" . addslashes($action) . "', " .
2792 "id:'" . addslashes($condition['id']) . "', " .
2793 "itemid:'" . addslashes($condition['itemid']) . "', " .
2794 "operator:'" . addslashes($condition['operator']) . "', " .
2795 "value:'" . addslashes($condition['value']) . "', " .
2796 "andor:'" . addslashes($andor) . "'}";
2800 // This checks if the given field with the given value should have an action applied.
2801 // Originally the only action was skip, but now you can also set the field to a specified value.
2802 // It somewhat mirrors the checkSkipConditions function in options.js.php.
2803 // If you use this for multiple layouts in the same script, you should
2804 // clear $sk_layout_items before each layout.
2805 function isSkipped(&$frow, $currvalue)
2807 global $sk_layout_items;
2809 // Accumulate an array of the encountered fields and their values.
2810 // It is assumed that fields appear before they are tested by another field.
2811 // TBD: Bad assumption?
2812 $field_id = $frow['field_id'];
2813 if (!is_array($sk_layout_items)) {
2814 $sk_layout_items = array();
2816 $sk_layout_items[$field_id] = array('row' => $frow, 'value' => $currvalue);
2818 if (empty($frow['conditions'])) {
2819 return false;
2822 $skiprows = unserialize($frow['conditions']);
2823 $prevandor = '';
2824 $prevcond = false;
2825 $datatype = $frow['data_type'];
2826 $action = 'skip'; // default action if none specified
2828 foreach ($skiprows as $key => $skiprow) {
2829 // id referenced field id
2830 // itemid referenced array key if applicable
2831 // operator "eq", "ne", "se" or "ns"
2832 // value if eq or ne, some string to compare with
2833 // andor "and", "or" or empty
2835 if ($key === 'action') {
2836 // Action value is a string. It can be "skip", or "value=" followed by a value.
2837 $action = $skiprow;
2838 continue;
2841 if (empty($skiprow['id'])) {
2842 continue;
2845 $id = $skiprow['id'];
2846 if (!isset($sk_layout_items[$id])) {
2847 error_log("Function isSkipped() cannot find skip source field '$id'.");
2848 continue;
2850 $itemid = $skiprow['itemid'];
2851 $operator = $skiprow['operator'];
2852 $skipval = $skiprow['value'];
2853 $srcvalue = $sk_layout_items[$id]['value'];
2854 $src_datatype = $sk_layout_items[$id]['row']['data_type'];
2855 $src_list_id = $sk_layout_items[$id]['row']['list_id'];
2857 // Some data types use itemid and we have to dig for their value.
2858 if ($src_datatype == 21 && $src_list_id) { // array of checkboxes
2859 $tmp = explode('|', $srcvalue);
2860 $srcvalue = in_array($itemid, $tmp);
2861 } else if ($src_datatype == 22 || $src_datatype == 23 || $src_datatype == 25) {
2862 $tmp = explode('|', $srcvalue);
2863 $srcvalue = '';
2864 foreach ($tmp as $tmp2) {
2865 if (strpos($tmp2, "$itemid:") === 0) {
2866 if ($datatype == 22) {
2867 $srcvalue = substr($tmp2, strlen($itemid) + 1);
2868 } else {
2869 $srcvalue = substr($tmp2, strlen($itemid) + 1, 1);
2875 // Compute the result of the test for this condition row.
2876 // PHP's looseness with variable type conversion helps us here.
2877 $condition = false;
2878 if ($operator == 'eq') {
2879 $condition = $srcvalue == $skipval;
2880 } else if ($operator == 'ne') {
2881 $condition = $srcvalue != $skipval;
2882 } else if ($operator == 'se') {
2883 $condition = $srcvalue == true;
2884 } else if ($operator == 'ns') {
2885 $condition = $srcvalue != true;
2886 } else {
2887 error_log("Unknown skip operator '$operator' for field '$field_id'.");
2890 // Logic to accumulate multiple conditions for the same target.
2891 if ($prevandor == 'and') {
2892 $condition = $condition && $prevcond;
2893 } else if ($prevandor == 'or') {
2894 $condition = $condition || $prevcond;
2896 $prevandor = $skiprow['andor'];
2897 $prevcond = $condition;
2899 return $prevcond ? $action : '';
2902 // Load array of names of the given layout and its groups.
2903 function getLayoutProperties($formtype, &$grparr, $sel = "grp_title")
2905 if ($sel != '*' && strpos($sel, 'grp_group_id') === false) {
2906 $sel = "grp_group_id, $sel";
2908 $gres = sqlStatement("SELECT $sel FROM layout_group_properties WHERE grp_form_id = ? " .
2909 "ORDER BY grp_group_id", array($formtype));
2910 while ($grow = sqlFetchArray($gres)) {
2911 $grparr[$grow['grp_group_id']] = $grow;
2915 function display_layout_rows($formtype, $result1, $result2 = '')
2917 global $item_count, $cell_count, $last_group, $CPR;
2919 $grparr = array();
2920 getLayoutProperties($formtype, $grparr, '*');
2922 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
2924 $fres = sqlStatement("SELECT * FROM layout_options " .
2925 "WHERE form_id = ? AND uor > 0 " .
2926 "ORDER BY group_id, seq", array($formtype));
2928 while ($frow = sqlFetchArray($fres)) {
2929 $this_group = $frow['group_id'];
2930 $titlecols = $frow['titlecols'];
2931 $datacols = $frow['datacols'];
2932 $data_type = $frow['data_type'];
2933 $field_id = $frow['field_id'];
2934 $list_id = $frow['list_id'];
2935 $currvalue = '';
2937 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
2939 if ($formtype == 'DEM') {
2940 if (strpos($field_id, 'em_') === 0) {
2941 // Skip employer related fields, if it's disabled.
2942 if ($GLOBALS['omit_employers']) {
2943 continue;
2946 $tmp = substr($field_id, 3);
2947 if (isset($result2[$tmp])) {
2948 $currvalue = $result2[$tmp];
2950 } else {
2951 if (isset($result1[$field_id])) {
2952 $currvalue = $result1[$field_id];
2955 } else {
2956 if (isset($result1[$field_id])) {
2957 $currvalue = $result1[$field_id];
2961 // Handle a data category (group) change.
2962 if (strcmp($this_group, $last_group) != 0) {
2963 $group_name = $grparr[$this_group]['grp_title'];
2964 // totally skip generating the employer category, if it's disabled.
2965 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
2966 continue;
2969 disp_end_group();
2970 $last_group = $this_group;
2973 // filter out all the empty field data from the patient report.
2974 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2975 // Handle starting of a new row.
2976 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2977 disp_end_row();
2978 echo "<tr>";
2979 if ($group_name) {
2980 echo "<td class='groupname'>";
2981 echo text(xl_layout_label($group_name));
2982 $group_name = '';
2983 } else {
2984 echo "<td valign='top'>&nbsp;";
2987 echo "</td>";
2990 if ($item_count == 0 && $titlecols == 0) {
2991 $titlecols = 1;
2994 // Handle starting of a new label cell.
2995 if ($titlecols > 0) {
2996 disp_end_cell();
2997 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
2998 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
2999 echo "<td class='label_custom' colspan='$titlecols_esc' ";
3000 //if ($cell_count == 2) echo " style='padding-left:10pt'";
3001 echo ">";
3002 $cell_count += $titlecols;
3005 ++$item_count;
3007 // Added 5-09 by BM - Translate label if applicable
3008 if ($frow['title']) {
3009 $tmp = xl_layout_label($frow['title']);
3010 echo text($tmp);
3011 // Append colon only if label does not end with punctuation.
3012 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3013 echo ':';
3015 } else {
3016 echo "&nbsp;";
3019 // Handle starting of a new data cell.
3020 if ($datacols > 0) {
3021 disp_end_cell();
3022 //echo "<td class='text data' colspan='$datacols' valign='top'";
3023 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3024 echo "<td class='text data' colspan='$datacols_esc'";
3025 //if ($cell_count > 0) echo " style='padding-left:5pt'";
3026 echo ">";
3027 $cell_count += $datacols;
3030 ++$item_count;
3031 echo generate_display_field($frow, $currvalue);
3035 disp_end_group();
3038 function display_layout_tabs($formtype, $result1, $result2 = '')
3040 global $item_count, $cell_count, $last_group, $CPR;
3042 $grparr = array();
3043 getLayoutProperties($formtype, $grparr);
3045 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3046 "WHERE form_id = ? AND uor > 0 " .
3047 "ORDER BY group_id", array($formtype));
3049 $first = true;
3050 while ($frow = sqlFetchArray($fres)) {
3051 $this_group = $frow['group_id'];
3052 // $group_name = substr($this_group, 1);
3053 $group_name = $grparr[$this_group]['grp_title'];
3054 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3055 continue;
3058 <li <?php echo $first ? 'class="current"' : '' ?>>
3059 <a href="#" id="header_tab_<?php echo htmlspecialchars($group_name, ENT_QUOTES); ?>">
3060 <?php echo htmlspecialchars(xl_layout_label($group_name), ENT_NOQUOTES); ?></a>
3061 </li>
3062 <?php
3063 $first = false;
3067 function display_layout_tabs_data($formtype, $result1, $result2 = '')
3069 global $item_count, $cell_count, $last_group, $CPR;
3071 $grparr = array();
3072 getLayoutProperties($formtype, $grparr, '*');
3074 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3076 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3077 "WHERE form_id = ? AND uor > 0 " .
3078 "ORDER BY group_id", array($formtype));
3080 $first = true;
3081 while ($frow = sqlFetchArray($fres)) {
3082 $this_group = isset($frow['group_id']) ? $frow['group_id'] : "" ;
3084 if ($grparr[$this_group]['grp_columns'] === 'Employer' && $GLOBALS['omit_employers']) {
3085 continue;
3087 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3088 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : $grparr[$this_group]['grp_subtitle'];
3090 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3091 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3092 "ORDER BY seq", array($formtype, $this_group));
3095 <div class="tab <?php echo $first ? 'current' : '' ?>">
3096 <table border='0' cellpadding='0'>
3098 <?php
3099 while ($group_fields = sqlFetchArray($group_fields_query)) {
3100 $titlecols = $group_fields['titlecols'];
3101 $datacols = $group_fields['datacols'];
3102 $data_type = $group_fields['data_type'];
3103 $field_id = $group_fields['field_id'];
3104 $list_id = $group_fields['list_id'];
3105 $currvalue = '';
3106 $edit_options = $group_fields['edit_options'];
3108 if ($formtype == 'DEM') {
3109 if (strpos($field_id, 'em_') === 0) {
3110 // Skip employer related fields, if it's disabled.
3111 if ($GLOBALS['omit_employers']) {
3112 continue;
3115 $tmp = substr($field_id, 3);
3116 if (isset($result2[$tmp])) {
3117 $currvalue = $result2[$tmp];
3119 } else {
3120 if (isset($result1[$field_id])) {
3121 $currvalue = $result1[$field_id];
3124 } else {
3125 if (isset($result1[$field_id])) {
3126 $currvalue = $result1[$field_id];
3130 // Skip this field if action conditions call for that.
3131 // Note this also accumulates info for subsequent skip tests.
3132 $skip_this_field = isSkipped($group_fields, $currvalue) == 'skip';
3134 // Skip this field if its do-not-print option is set.
3135 if (isOption($edit_options, 'X') !== false) {
3136 $skip_this_field = true;
3139 // Handle a data category (group) change.
3140 if (strcmp($this_group, $last_group) != 0) {
3141 $group_name = $grparr[$this_group]['grp_title'];
3142 // totally skip generating the employer category, if it's disabled.
3143 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3144 continue;
3146 $last_group = $this_group;
3149 // Handle starting of a new row.
3150 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
3151 disp_end_row();
3152 if ($subtitle) {
3153 // Group subtitle exists and is not displayed yet.
3154 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3155 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3156 $subtitle = '';
3158 echo "<tr>";
3161 if ($item_count == 0 && $titlecols == 0) {
3162 $titlecols = 1;
3165 // Handle starting of a new label cell.
3166 if ($titlecols > 0) {
3167 disp_end_cell();
3168 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3169 $field_id_label = 'label_'.$group_fields['field_id'];
3170 echo "<td class='label_custom' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
3171 echo ">";
3172 $cell_count += $titlecols;
3175 ++$item_count;
3177 $field_id_label = 'label_'.$group_fields['field_id'];
3178 echo "<span id='".attr($field_id_label)."'>";
3179 if ($skip_this_field) {
3180 // No label because skipping
3181 } else if ($group_fields['title']) {
3182 $tmp = xl_layout_label($group_fields['title']);
3183 echo text($tmp);
3184 // Append colon only if label does not end with punctuation.
3185 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3186 echo ':';
3188 } else {
3189 echo "&nbsp;";
3191 echo "</span>";
3193 // Handle starting of a new data cell.
3194 if ($datacols > 0) {
3195 disp_end_cell();
3196 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3197 $field_id = 'text_'.$group_fields['field_id'];
3198 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
3199 if (!$skip_this_field && $data_type == 3) {
3200 // Textarea gets a light grey border.
3201 echo " style='border:1px solid #cccccc'";
3203 echo ">";
3204 $cell_count += $datacols;
3205 } else {
3206 $field_id = 'text_'.$group_fields['field_id'];
3207 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
3210 ++$item_count;
3211 if (!$skip_this_field) {
3212 echo generate_display_field($group_fields, $currvalue);
3216 disp_end_row();
3219 </table>
3220 </div>
3222 <?php
3224 $first = false;
3228 function display_layout_tabs_data_editable($formtype, $result1, $result2 = '')
3230 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
3232 $grparr = array();
3233 getLayoutProperties($formtype, $grparr, '*');
3235 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3237 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3238 "WHERE form_id = ? AND uor > 0 " .
3239 "ORDER BY group_id", array($formtype));
3241 $first = true;
3242 $condition_str = '';
3244 while ($frow = sqlFetchArray($fres)) {
3245 $this_group = $frow['group_id'];
3246 $group_name = $grparr[$this_group]['grp_title'];
3247 $group_name_esc = text($group_name);
3249 if ($grparr[$this_group]['grp_title'] === 'Employer' && $GLOBALS['omit_employers']) {
3250 continue;
3252 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3253 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : $grparr[$this_group]['grp_subtitle'];
3255 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3256 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3257 "ORDER BY seq", array($formtype, $this_group));
3260 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_', $group_name_esc)?>" >
3261 <table border='0' cellpadding='0'>
3263 <?php
3264 while ($group_fields = sqlFetchArray($group_fields_query)) {
3265 $titlecols = $group_fields['titlecols'];
3266 $datacols = $group_fields['datacols'];
3267 $data_type = $group_fields['data_type'];
3268 $field_id = $group_fields['field_id'];
3269 $list_id = $group_fields['list_id'];
3270 $backup_list = $group_fields['list_backup_id'];
3271 $currvalue = '';
3272 $action = 'skip';
3274 // Accumulate action conditions into a JSON expression for the browser side.
3275 accumActionConditions($field_id, $condition_str, $group_fields['conditions']);
3277 if ($formtype == 'DEM') {
3278 if (strpos($field_id, 'em_') === 0) {
3279 // Skip employer related fields, if it's disabled.
3280 if ($GLOBALS['omit_employers']) {
3281 continue;
3284 $tmp = substr($field_id, 3);
3285 if (isset($result2[$tmp])) {
3286 $currvalue = $result2[$tmp];
3288 } else {
3289 if (isset($result1[$field_id])) {
3290 $currvalue = $result1[$field_id];
3293 } else {
3294 if (isset($result1[$field_id])) {
3295 $currvalue = $result1[$field_id];
3299 // Handle a data category (group) change.
3300 if (strcmp($this_group, $last_group) != 0) {
3301 // totally skip generating the employer category, if it's disabled.
3302 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3303 continue;
3306 $last_group = $this_group;
3309 // Handle starting of a new row.
3310 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
3311 disp_end_row();
3312 if ($subtitle) {
3313 // Group subtitle exists and is not displayed yet.
3314 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3315 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3316 $subtitle = '';
3318 echo "<tr>";
3321 if ($item_count == 0 && $titlecols == 0) {
3322 $titlecols = 1;
3325 // Handle starting of a new label cell.
3326 if ($titlecols > 0) {
3327 disp_end_cell();
3328 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3329 $field_id_label = 'label_'.$group_fields['field_id'];
3330 echo "<td class='label_custom' colspan='$titlecols_esc'";
3331 // This ID is used by skip conditions.
3332 echo " id='label_id_" . attr($field_id) . "'";
3333 echo ">";
3334 $cell_count += $titlecols;
3337 ++$item_count;
3339 if ($group_fields['title']) {
3340 $tmp = xl_layout_label($group_fields['title']);
3341 echo text($tmp);
3342 // Append colon only if label does not end with punctuation.
3343 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3344 echo ':';
3346 } else {
3347 echo "&nbsp;";
3350 // Handle starting of a new data cell.
3351 if ($datacols > 0) {
3352 disp_end_cell();
3353 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3354 $field_id = 'text_'.$group_fields['field_id'];
3355 echo "<td class='text data' colspan='$datacols_esc'";
3356 // This ID is used by action conditions.
3357 echo " id='value_id_" . attr($field_id) . "'";
3358 echo ">";
3359 $cell_count += $datacols;
3362 ++$item_count;
3364 echo generate_form_field($group_fields, $currvalue);
3368 </table>
3369 </div>
3371 <?php
3373 $first = false;
3377 // From the currently posted HTML form, this gets the value of the
3378 // field corresponding to the provided layout_options table row.
3380 function get_layout_form_value($frow, $prefix = 'form_')
3382 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
3383 $data_type = $frow['data_type'];
3384 $field_id = $frow['field_id'];
3385 $value = '';
3386 if (isset($_POST["$prefix$field_id"])) {
3387 if ($data_type == 21) {
3388 if (!$frow['list_id']) {
3389 if (!empty($_POST["form_$field_id"])) {
3390 $value = xlt('Yes');
3392 } else {
3393 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
3394 // must be concatenated into a |-separated string.
3395 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3396 if (strlen($value)) {
3397 $value .= '|';
3399 $value .= $key;
3402 } else if ($data_type == 22) {
3403 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
3404 // into "key:value|key:value|...".
3405 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3406 $val = str_replace('|', ' ', $val);
3407 if (strlen($value)) {
3408 $value .= '|';
3411 $value .= "$key:$val";
3413 } else if ($data_type == 23) {
3414 // $_POST["$prefix$field_id"] is an array of text fields with companion
3415 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
3416 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3417 $restype = $_POST["radio_{$field_id}"][$key];
3418 if (empty($restype)) {
3419 $restype = '0';
3422 $val = str_replace('|', ' ', $val);
3423 if (strlen($value)) {
3424 $value .= '|';
3427 $value .= "$key:$restype:$val";
3429 } else if ($data_type == 25) {
3430 // $_POST["$prefix$field_id"] is an array of text fields with companion
3431 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
3432 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3433 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
3434 $val = str_replace('|', ' ', $val);
3435 if (strlen($value)) {
3436 $value .= '|';
3439 $value .= "$key:$restype:$val";
3441 } else if ($data_type == 28 || $data_type == 32) {
3442 // $_POST["$prefix$field_id"] is an date text fields with companion
3443 // radio buttons to be imploded into "notes|type|date".
3444 $restype = $_POST["radio_{$field_id}"];
3445 if (empty($restype)) {
3446 $restype = '0';
3449 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
3450 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3451 if ($data_type == 32) {
3452 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
3453 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3454 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
3455 $value = "$res_text_note|$restype|$resdate|$reslist";
3456 } else {
3457 $value = "$resnote|$restype|$resdate";
3459 } else if ($data_type == 36) {
3460 $value_array = $_POST["form_$field_id"];
3461 $i = 0;
3462 foreach ($value_array as $key => $valueofkey) {
3463 if ($i == 0) {
3464 $value = $valueofkey;
3465 } else {
3466 $value = $value . "|" . $valueofkey;
3469 $i++;
3471 } else {
3472 $value = $_POST["$prefix$field_id"];
3476 // Better to die than to silently truncate data!
3477 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength) {
3478 die(htmlspecialchars(xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
3479 ":<br />&nbsp;<br />".htmlspecialchars($value, ENT_NOQUOTES));
3482 return trim($value);
3485 // Generate JavaScript validation logic for the required fields.
3487 function generate_layout_validation($form_id)
3489 $fres = sqlStatement("SELECT * FROM layout_options " .
3490 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
3491 "ORDER BY group_id, seq", array($form_id));
3493 while ($frow = sqlFetchArray($fres)) {
3494 $data_type = $frow['data_type'];
3495 $field_id = $frow['field_id'];
3496 $fldtitle = $frow['title'];
3497 if (!$fldtitle) {
3498 $fldtitle = $frow['description'];
3501 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES);
3503 if ($data_type == 40) {
3504 $fldid = addslashes("form_$field_id");
3505 // Move canvas image data to its hidden form field so the server will get it.
3506 echo
3507 " var canfld = f['$fldid'];\n" .
3508 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
3509 continue;
3512 if ($frow['uor'] < 2) {
3513 continue;
3516 echo " if (f.$fldname && !f.$fldname.disabled) {\n";
3517 switch ($data_type) {
3518 case 1:
3519 case 11:
3520 case 12:
3521 case 13:
3522 case 14:
3523 case 26:
3524 echo
3525 " if (f.$fldname.selectedIndex <= 0) {\n" .
3526 " alert(\"" . addslashes(xl('Please choose a value for')) .
3527 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3528 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3529 " return false;\n" .
3530 " }\n";
3531 break;
3532 case 33:
3533 echo
3534 " if (f.$fldname.selectedIndex <= 0) {\n" .
3535 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3536 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3537 " }\n";
3538 break;
3539 case 27: // radio buttons
3540 echo
3541 " var i = 0;\n" .
3542 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
3543 " if (i >= f.$fldname.length) {\n" .
3544 " alert(\"" . addslashes(xl('Please choose a value for')) .
3545 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3546 " return false;\n" .
3547 " }\n";
3548 break;
3549 case 2:
3550 case 3:
3551 case 4:
3552 case 15:
3553 echo
3554 " if (trimlen(f.$fldname.value) == 0) {\n" .
3555 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3556 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
3557 " $('#" . $fldname . "').attr('style','background:red'); \n" .
3558 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3559 " } else { " .
3560 " $('#" . $fldname . "').attr('style',''); " .
3561 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
3562 " } \n";
3563 break;
3564 case 36: // multi select
3565 echo
3566 " var multi_select=f['$fldname"."[]']; \n " .
3567 " var multi_choice_made=false; \n".
3568 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
3569 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
3570 " } \n" .
3571 " if(!multi_choice_made)
3572 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3574 break;
3576 echo " }\n";
3581 * DROPDOWN FOR FACILITIES
3583 * build a dropdown with all facilities
3585 * @param string $selected - name of the currently selected facility
3586 * use '0' for "unspecified facility"
3587 * use '' for "All facilities" (the default)
3588 * @param string $name - the name/id for select form (defaults to "form_facility")
3589 * @param boolean $allow_unspecified - include an option for "unspecified" facility
3590 * defaults to true
3591 * @return void - just echo the html encoded string
3593 * Note: This should become a data-type at some point, according to Brady
3595 function dropdown_facility(
3596 $selected = '',
3597 $name = 'form_facility',
3598 $allow_unspecified = true,
3599 $allow_allfacilities = true,
3600 $disabled = '',
3601 $onchange = ''
3604 global $facilityService;
3606 $have_selected = false;
3607 $fres = $facilityService->getAll();
3609 $name = htmlspecialchars($name, ENT_QUOTES);
3610 echo " <select class='form-control' name='$name' id='$name'";
3611 if ($onchange) {
3612 echo " onchange='$onchange'";
3615 echo " $disabled>\n";
3617 if ($allow_allfacilities) {
3618 $option_value = '';
3619 $option_selected_attr = '';
3620 if ($selected == '') {
3621 $option_selected_attr = ' selected="selected"';
3622 $have_selected = true;
3625 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
3626 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3627 } elseif ($allow_unspecified) {
3628 $option_value = '0';
3629 $option_selected_attr = '';
3630 if ($selected == '0') {
3631 $option_selected_attr = ' selected="selected"';
3632 $have_selected = true;
3635 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
3636 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3639 foreach ($fres as $frow) {
3640 $facility_id = $frow['id'];
3641 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
3642 $option_selected_attr = '';
3643 if ($selected == $facility_id) {
3644 $option_selected_attr = ' selected="selected"';
3645 $have_selected = true;
3648 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
3649 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3652 if ($allow_unspecified && $allow_allfacilities) {
3653 $option_value = '0';
3654 $option_selected_attr = '';
3655 if ($selected == '0') {
3656 $option_selected_attr = ' selected="selected"';
3657 $have_selected = true;
3660 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
3661 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3664 if (!$have_selected) {
3665 $option_value = htmlspecialchars($selected, ENT_QUOTES);
3666 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
3667 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
3668 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
3671 echo " </select>\n";
3674 // Expand Collapse Widget
3675 // This forms the header and functionality component of the widget. The information that is displayed
3676 // then follows this function followed by a closing div tag
3678 // $title is the title of the section (already translated)
3679 // $label is identifier used in the tag id's and sql columns
3680 // $buttonLabel is the button label text (already translated)
3681 // $buttonLink is the button link information
3682 // $buttonClass is any additional needed class elements for the button tag
3683 // $linkMethod is the button link method ('javascript' vs 'html')
3684 // $bodyClass is to set class(es) of the body
3685 // $auth is a flag to decide whether to show the button
3686 // $fixedWidth is to flag whether width is fixed
3687 // $forceExpandAlways is a flag to force the widget to always be expanded
3689 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways = false)
3691 if ($fixedWidth) {
3692 echo "<div class='section-header'>";
3693 } else {
3694 echo "<div class='section-header-dynamic'>";
3697 echo "<table><tr>";
3698 if ($auth) {
3699 // show button, since authorized
3700 // first prepare class string
3701 if ($buttonClass) {
3702 $class_string = "css_button_small ".htmlspecialchars($buttonClass, ENT_NOQUOTES);
3703 } else {
3704 $class_string = "css_button_small";
3707 // next, create the link
3708 if ($linkMethod == "javascript") {
3709 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3710 } else {
3711 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3712 if (!isset($_SESSION['patient_portal_onsite']) && !isset($_SESSION['patient_portal_onsite_two'])) {
3713 // prevent an error from occuring when calling the function from the patient portal
3714 echo " onclick='top.restoreSession()'";
3718 echo "><span>" .
3719 htmlspecialchars($buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
3722 if ($forceExpandAlways) {
3723 // Special case to force the widget to always be expanded
3724 echo "<td><span class='text'><b>" . htmlspecialchars($title, ENT_NOQUOTES) . "</b></span>";
3725 $indicatorTag ="style='display:none'";
3728 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3729 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3730 htmlspecialchars($label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
3731 echo htmlspecialchars($title, ENT_NOQUOTES) . "</b></span>";
3733 if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3734 // collapse all entries in the patient portal
3735 $text = xl('expand');
3736 } else if (getUserSetting($label."_ps_expand")) {
3737 $text = xl('collapse');
3738 } else {
3739 $text = xl('expand');
3742 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
3743 "</span>)</a></td>";
3744 echo "</tr></table>";
3745 echo "</div>";
3746 if ($forceExpandAlways) {
3747 // Special case to force the widget to always be expanded
3748 $styling = "";
3749 } else if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3750 // collapse all entries in the patient portal
3751 $styling = "style='display:none'";
3752 } else if (getUserSetting($label."_ps_expand")) {
3753 $styling = "";
3754 } else {
3755 $styling = "style='display:none'";
3758 if ($bodyClass) {
3759 $styling .= " class='" . $bodyClass . "'";
3762 //next, create the first div tag to hold the information
3763 // note the code that calls this function will then place the ending div tag after the data
3764 echo "<div id='" . htmlspecialchars($label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
3767 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3768 function billing_facility($name, $select)
3770 global $facilityService;
3772 $fres = $facilityService->getAllBillingLocations();
3773 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' class='form-control' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3774 foreach ($fres as $facrow) {
3775 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3776 echo "<option value=".htmlspecialchars($facrow['id'], ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3779 echo "</select>";
3782 // Generic function to get the translated title value for a particular list option.
3784 function getListItemTitle($list, $option)
3786 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3787 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3788 if (empty($row['title'])) {
3789 return $option;
3792 return xl_list_label($row['title']);
3794 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3795 function getSmokeCodes()
3797 $smoking_codes_arr = array();
3798 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3799 while ($codes_row = sqlFetchArray($smoking_codes)) {
3800 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3803 return $smoking_codes_arr;
3806 // Get the current value for a layout based form field.
3807 // Depending on options this might come from lbf_data, patient_data,
3808 // form_encounter, shared_attributes or elsewhere.
3809 // Returns FALSE if the field ID is invalid (layout error).
3811 function lbf_current_value($frow, $formid, $encounter)
3813 global $pid;
3814 $formname = $frow['form_id'];
3815 $field_id = $frow['field_id'];
3816 $source = $frow['source'];
3817 $currvalue = '';
3818 $deffname = $formname . '_default_' . $field_id;
3819 if ($source == 'D' || $source == 'H') {
3820 // Get from patient_data, employer_data or history_data.
3821 if ($source == 'H') {
3822 $table = 'history_data';
3823 $orderby = 'ORDER BY date DESC LIMIT 1';
3824 } else if (strpos($field_id, 'em_') === 0) {
3825 $field_id = substr($field_id, 3);
3826 $table = 'employer_data';
3827 $orderby = 'ORDER BY date DESC LIMIT 1';
3828 } else {
3829 $table = 'patient_data';
3830 $orderby = '';
3833 // It is an error if the field does not exist, but don't crash.
3834 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3835 if (empty($tmp)) {
3836 return '*?*';
3839 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3840 if (isset($pdrow)) {
3841 $currvalue = $pdrow['field_value'];
3843 } else if ($source == 'E') {
3844 $sarow = false;
3845 if ($encounter) {
3846 // Get value from shared_attributes of the current encounter.
3847 $sarow = sqlQuery(
3848 "SELECT field_value FROM shared_attributes WHERE " .
3849 "pid = ? AND encounter = ? AND field_id = ?",
3850 array($pid, $encounter, $field_id)
3852 if (!empty($sarow)) {
3853 $currvalue = $sarow['field_value'];
3855 } else if ($formid) {
3856 // Get from shared_attributes of the encounter that this form is linked to.
3857 // Note the importance of having an index on forms.form_id.
3858 $sarow = sqlQuery(
3859 "SELECT sa.field_value " .
3860 "FROM forms AS f, shared_attributes AS sa WHERE " .
3861 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3862 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3863 array($formid, $formname, $field_id)
3865 if (!empty($sarow)) {
3866 $currvalue = $sarow['field_value'];
3868 } else {
3869 // New form and encounter not available, this should not happen.
3871 if (empty($sarow) && !$formid) {
3872 // New form, see if there is a custom default from a plugin.
3873 if (function_exists($deffname)) {
3874 $currvalue = call_user_func($deffname);
3877 } else if ($source == 'V') {
3878 if ($encounter) {
3879 // Get value from the current encounter's form_encounter.
3880 $ferow = sqlQuery(
3881 "SELECT * FROM form_encounter WHERE " .
3882 "pid = ? AND encounter = ?",
3883 array($pid, $encounter)
3885 if (isset($ferow[$field_id])) {
3886 $currvalue = $ferow[$field_id];
3888 } else if ($formid) {
3889 // Get value from the form_encounter that this form is linked to.
3890 $ferow = sqlQuery(
3891 "SELECT fe.* " .
3892 "FROM forms AS f, form_encounter AS fe WHERE " .
3893 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3894 "fe.pid = f.pid AND fe.encounter = f.encounter",
3895 array($formid, $formname)
3897 if (isset($ferow[$field_id])) {
3898 $currvalue = $ferow[$field_id];
3900 } else {
3901 // New form and encounter not available, this should not happen.
3903 } else if ($formid) {
3904 // This is a normal form field.
3905 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3906 "form_id = ? AND field_id = ?", array($formid, $field_id));
3907 if (!empty($ldrow)) {
3908 $currvalue = $ldrow['field_value'];
3910 } else {
3911 // New form, see if there is a custom default from a plugin.
3912 if (function_exists($deffname)) {
3913 $currvalue = call_user_func($deffname);
3917 return $currvalue;
3920 // This returns stuff that needs to go into the <head> section of a caller using
3921 // the drawable image field type in a form.
3922 // A TRUE argument makes the widget controls smaller.
3924 function lbf_canvas_head($small = true)
3926 $s = <<<EOD
3927 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3928 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3929 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3930 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3931 EOD;
3932 if ($small) {
3933 $s .= <<<EOD
3934 <style>
3935 /* Custom LiterallyCanvas styling.
3936 * This makes the widget 25% less tall and adjusts some other things accordingly.
3938 .literally {
3939 min-height:100%;min-width:300px; /* Was 400, unspecified */
3941 .literally .lc-picker .toolbar-button {
3942 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3944 .literally .color-well {
3945 font-size:8px;width:49px; /* Was 10, 60 */
3947 .literally .color-well-color-container {
3948 width:21px;height:21px; /* Was 28, 28 */
3950 .literally .lc-picker {
3951 width:50px; /* Was 61 */
3953 .literally .lc-drawing.with-gui {
3954 left:50px; /* Was 61 */
3956 .literally .lc-options {
3957 left:50px; /* Was 61 */
3959 .literally .color-picker-popup {
3960 left:49px;bottom:0px; /* Was 60, 31 */
3962 </style>
3963 EOD;
3966 return $s;
3970 * Test if modifier($test) is in array of options for data type.
3972 * @param json array $options or could be string of form "ABCU"
3973 * @param string $test
3974 * @return boolean
3976 function isOption($options, $test)
3978 if (empty($options) || !isset($test)) {
3979 return false; // why bother?
3981 if (strpos($options, ',') === false) { // could be string of char's or single element of json
3982 json_decode($options);
3983 if (is_string($options) && ! (json_last_error() === JSON_ERROR_NONE)) { // nope, it's string.
3984 $t = str_split(trim($options)); // very good chance it's legacy modifier string.
3985 $options = json_encode($t); // make it array.
3988 $options = json_decode($options);
3990 return !is_null($options) && in_array($test, $options, true) ? true : false; // finally!