Merge pull request #1403 from bradymiller/matrix-israel-formatDate
[openemr.git] / library / options.inc.php
blob1b1b84c7123bd08bf4055413208576f654850c4f
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 $dateValue = oeFormatShortDate(substr($currescaped, 0, 10));
463 echo "<input type='text' size='10' class='datepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
464 " value='" . attr($dateValue) ."'";
465 } else {
466 $dateValue = oeFormatDateTime(substr($currescaped, 0, 20), 0);
467 echo "<input type='text' size='20' class='datetimepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
468 " value='" . attr($dateValue) . "'";
471 if (!$agestr) {
472 echo " title='$description'";
475 echo " $onchange_string $lbfonchange $disabled />";
477 // Optional display of age or gestational age.
478 if ($agestr) {
479 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
481 } // provider list, local providers only
482 else if ($data_type == 10) {
483 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
484 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
485 "AND authorized = 1 " .
486 "ORDER BY lname, fname");
487 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
488 echo "<option value=''>" . xlt($empty_title) . "</option>";
489 $got_selected = false;
490 while ($urow = sqlFetchArray($ures)) {
491 $uname = text($urow['fname'] . ' ' . $urow['lname']);
492 $optionId = attr($urow['id']);
493 echo "<option value='$optionId'";
494 if ($urow['id'] == $currvalue) {
495 echo " selected";
496 $got_selected = true;
499 echo ">$uname</option>";
502 if (!$got_selected && $currvalue) {
503 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
504 echo "</select>";
505 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
506 } else {
507 echo "</select>";
509 } // provider list, including address book entries with an NPI number
510 else if ($data_type == 11) {
511 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
512 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
513 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
514 "ORDER BY lname, fname");
515 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
516 echo " $lbfonchange $disabled>";
517 echo "<option value=''>" . xlt('Unassigned') . "</option>";
518 $got_selected = false;
519 while ($urow = sqlFetchArray($ures)) {
520 $uname = text($urow['fname'] . ' ' . $urow['lname']);
521 $optionId = attr($urow['id']);
522 echo "<option value='$optionId'";
523 if ($urow['id'] == $currvalue) {
524 echo " selected";
525 $got_selected = true;
528 echo ">$uname</option>";
531 if (!$got_selected && $currvalue) {
532 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
533 echo "</select>";
534 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
535 } else {
536 echo "</select>";
538 } // pharmacy list
539 else if ($data_type == 12) {
540 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
541 echo " $lbfonchange $disabled>";
542 echo "<option value='0'></option>";
543 $pres = get_pharmacies();
544 $got_selected = false;
545 while ($prow = sqlFetchArray($pres)) {
546 $key = $prow['id'];
547 $optionValue = htmlspecialchars($key, ENT_QUOTES);
548 $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
549 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
550 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
551 echo "<option value='$optionValue'";
552 if ($currvalue == $key) {
553 echo " selected";
554 $got_selected = true;
557 echo ">$optionLabel</option>";
560 if (!$got_selected && $currvalue) {
561 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
562 echo "</select>";
563 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
564 } else {
565 echo "</select>";
567 } // squads
568 else if ($data_type == 13) {
569 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
570 echo " $lbfonchange $disabled>";
571 echo "<option value=''>&nbsp;</option>";
572 $squads = acl_get_squads();
573 if ($squads) {
574 foreach ($squads as $key => $value) {
575 $optionValue = htmlspecialchars($key, ENT_QUOTES);
576 $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES);
577 echo "<option value='$optionValue'";
578 if ($currvalue == $key) {
579 echo " selected";
582 echo ">$optionLabel</option>\n";
586 echo "</select>";
587 } // Address book, preferring organization name if it exists and is not in
588 // parentheses, and excluding local users who are not providers.
589 // Supports "referred to" practitioners and facilities.
590 // Alternatively the letter L in edit_options means that abook_type
591 // must be "ord_lab", indicating types used with the procedure
592 // lab ordering system.
593 // Alternatively the letter O in edit_options means that abook_type
594 // must begin with "ord_", indicating types used with the procedure
595 // ordering system.
596 // Alternatively the letter V in edit_options means that abook_type
597 // must be "vendor", indicating the Vendor type.
598 // Alternatively the letter R in edit_options means that abook_type
599 // must be "dist", indicating the Distributor type.
600 else if ($data_type == 14) {
601 if (isOption($frow['edit_options'], 'L') !== false) {
602 $tmp = "abook_type = 'ord_lab'";
603 } else if (isOption($frow['edit_options'], 'O') !== false) {
604 $tmp = "abook_type LIKE 'ord\\_%'";
605 } else if (isOption($frow['edit_options'], 'V') !== false) {
606 $tmp = "abook_type LIKE 'vendor%'";
607 } else if (isOption($frow['edit_options'], 'R') !== false) {
608 $tmp = "abook_type LIKE 'dist'";
609 } else {
610 $tmp = "( username = '' OR authorized = 1 )";
613 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
614 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
615 "AND $tmp " .
616 "ORDER BY organization, lname, fname");
617 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
618 echo " $lbfonchange $disabled>";
619 echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES) . "</option>";
620 while ($urow = sqlFetchArray($ures)) {
621 $uname = $urow['organization'];
622 if (empty($uname) || substr($uname, 0, 1) == '(') {
623 $uname = $urow['lname'];
624 if ($urow['fname']) {
625 $uname .= ", " . $urow['fname'];
629 $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES);
630 $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES);
631 echo "<option value='$optionValue'";
632 // Failure to translate Local and External is not an error here;
633 // they are only used as internal flags and must not be translated!
634 $title = $urow['username'] ? 'Local' : 'External';
635 $optionTitle = htmlspecialchars($title, ENT_QUOTES);
636 echo " title='$optionTitle'";
637 if ($urow['id'] == $currvalue) {
638 echo " selected";
641 echo ">$optionLabel</option>";
644 echo "</select>";
645 } // A billing code. If description matches an existing code type then that type is used.
646 else if ($data_type == 15) {
647 $codetype = '';
648 if (!empty($frow['description']) && isset($code_types[$frow['description']])) {
649 $codetype = $frow['description'];
651 $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES);
652 $maxlength = $frow['max_length'];
653 $string_maxlength = "";
654 // if max_length is set to zero, then do not set a maxlength
655 if ($maxlength) {
656 $string_maxlength = "maxlength='".attr($maxlength)."'";
660 if (isOption($frow['edit_options'], '2') !== false && substr($frow['form_id'], 0, 3) == 'LBF') {
661 // Option "2" generates a hidden input for the codes, and a matching visible field
662 // displaying their descriptions. First step is computing the description string.
663 $currdescstring = '';
664 if (!empty($currvalue)) {
665 $relcodes = explode(';', $currvalue);
666 foreach ($relcodes as $codestring) {
667 if ($codestring === '') {
668 continue;
671 $code_text = lookup_code_descriptions($codestring);
672 if ($currdescstring !== '') {
673 $currdescstring .= '; ';
676 if (!empty($code_text)) {
677 $currdescstring .= $code_text;
678 } else {
679 $currdescstring .= $codestring;
684 $currdescstring = attr($currdescstring);
686 echo "<input type='text'" .
687 " name='form_$field_id_esc'" .
688 " id='form_related_code'" .
689 " size='$fldlength'" .
690 " value='$currescaped'" .
691 " style='display:none'" .
692 " $lbfonchange readonly $disabled />";
693 // Extra readonly input field for optional display of code description(s).
694 echo "<input type='text'" .
695 " name='form_$field_id_esc" . "__desc'" .
696 " size='$fldlength'" .
697 " title='$description'" .
698 " value='$currdescstring'";
699 if (!$disabled) {
700 echo " onclick='sel_related(this,\"$codetype\")'";
703 echo "class='form-control'";
704 echo " readonly $disabled />";
705 } else {
706 echo "<input type='text'" .
707 " name='form_$field_id_esc'" .
708 " id='form_related_code'" .
709 " size='$fldlength'" .
710 " $string_maxlength" .
711 " title='$description'" .
712 " value='$currescaped'";
713 if (!$disabled) {
714 echo " onclick='sel_related(this,\"$codetype\")'";
717 echo "class='form-control'";
718 echo " $lbfonchange readonly $disabled />";
720 } // insurance company list
721 else if ($data_type == 16) {
722 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
723 echo "<option value='0'></option>";
724 $insprovs = getInsuranceProviders();
725 $got_selected = false;
726 foreach ($insprovs as $key => $ipname) {
727 $optionValue = htmlspecialchars($key, ENT_QUOTES);
728 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
729 echo "<option value='$optionValue'";
730 if ($currvalue == $key) {
731 echo " selected";
732 $got_selected = true;
735 echo ">$optionLabel</option>";
738 if (!$got_selected && $currvalue) {
739 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
740 echo "</select>";
741 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
742 } else {
743 echo "</select>";
745 } // issue types
746 else if ($data_type == 17) {
747 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
748 echo "<option value='0'></option>";
749 $got_selected = false;
750 foreach ($ISSUE_TYPES as $key => $value) {
751 $optionValue = htmlspecialchars($key, ENT_QUOTES);
752 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
753 echo "<option value='$optionValue'";
754 if ($currvalue == $key) {
755 echo " selected";
756 $got_selected = true;
759 echo ">$optionLabel</option>";
762 if (!$got_selected && strlen($currvalue) > 0) {
763 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
764 echo "</select>";
765 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
766 } else {
767 echo "</select>";
769 } // Visit categories.
770 else if ($data_type == 18) {
771 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
772 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
773 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'" .
774 " $lbfonchange $disabled>";
775 echo "<option value=''>" . xlt($empty_title) . "</option>";
776 $got_selected = false;
777 while ($crow = sqlFetchArray($cres)) {
778 $catid = $crow['pc_catid'];
779 if (($catid < 9 && $catid != 5) || $catid == 11) {
780 continue;
783 echo "<option value='" . attr($catid) . "'";
784 if ($catid == $currvalue) {
785 echo " selected";
786 $got_selected = true;
789 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
792 if (!$got_selected && $currvalue) {
793 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
794 echo "</select>";
795 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
796 } else {
797 echo "</select>";
799 } // a set of labeled checkboxes
800 else if ($data_type == 21) {
801 // If no list then it's a single checkbox and its value is "Yes" or empty.
802 if (!$list_id) {
803 echo "<input type='checkbox' name='form_{$field_id_esc}' " .
804 "id='form_{$field_id_esc}' value='Yes' $lbfonchange";
805 if ($currvalue) {
806 echo " checked";
808 echo " $disabled />";
809 } else {
810 // In this special case, fld_length is the number of columns generated.
811 $cols = max(1, $frow['fld_length']);
812 $avalue = explode('|', $currvalue);
813 $lres = sqlStatement("SELECT * FROM list_options " .
814 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
815 echo "<table cellpadding='0' cellspacing='0' width='100%' title='".attr($description)."'>";
816 $tdpct = (int) (100 / $cols);
817 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
818 $option_id = $lrow['option_id'];
819 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
820 // if ($count) echo "<br />";
821 if ($count % $cols == 0) {
822 if ($count) {
823 echo "</tr>";
825 echo "<tr>";
827 echo "<td width='" . attr($tdpct) . "%' nowrap>";
828 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
829 "id='form_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
830 if (in_array($option_id, $avalue)) {
831 echo " checked";
833 // Added 5-09 by BM - Translate label if applicable
834 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
835 echo "</td>";
837 if ($count) {
838 echo "</tr>";
839 if ($count > $cols) {
840 // Add some space after multiple rows of checkboxes.
841 $cols = htmlspecialchars($cols, ENT_QUOTES);
842 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
845 echo "</table>";
847 } // a set of labeled text input fields
848 else if ($data_type == 22) {
849 $tmp = explode('|', $currvalue);
850 $avalue = array();
851 foreach ($tmp as $value) {
852 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
853 $avalue[$matches[1]] = $matches[2];
857 $lres = sqlStatement("SELECT * FROM list_options " .
858 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
859 echo "<table cellpadding='0' cellspacing='0'>";
860 while ($lrow = sqlFetchArray($lres)) {
861 $option_id = $lrow['option_id'];
862 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
863 $maxlength = $frow['max_length'];
864 $string_maxlength = "";
865 // if max_length is set to zero, then do not set a maxlength
866 if ($maxlength) {
867 $string_maxlength = "maxlength='".attr($maxlength)."'";
870 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
872 // Added 5-09 by BM - Translate label if applicable
873 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
874 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
875 $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
876 echo "<td><input type='text'" .
877 " name='form_{$field_id_esc}[$option_id_esc]'" .
878 " id='form_{$field_id_esc}[$option_id_esc]'" .
879 " size='$fldlength'" .
880 " class='form-control'" .
881 " $string_maxlength" .
882 " value='$optionValue'";
883 echo " $lbfonchange $disabled /></td></tr>";
886 echo "</table>";
887 } // a set of exam results; 3 radio buttons and a text field:
888 else if ($data_type == 23) {
889 $tmp = explode('|', $currvalue);
890 $avalue = array();
891 foreach ($tmp as $value) {
892 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
893 $avalue[$matches[1]] = $matches[2];
897 $maxlength = $frow['max_length'];
898 $string_maxlength = "";
899 // if max_length is set to zero, then do not set a maxlength
900 if ($maxlength) {
901 $string_maxlength = "maxlength='".attr($maxlength)."'";
904 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
905 $lres = sqlStatement("SELECT * FROM list_options " .
906 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
907 echo "<table cellpadding='0' cellspacing='0'>";
908 echo "<tr><td>&nbsp;</td><td class='bold'>" .
909 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
910 "&nbsp;</td><td class='bold'>" .
911 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
912 "<td class='bold'>" .
913 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
914 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
915 while ($lrow = sqlFetchArray($lres)) {
916 $option_id = $lrow['option_id'];
917 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
918 $restype = substr($avalue[$option_id], 0, 1);
919 $resnote = substr($avalue[$option_id], 2);
921 // Added 5-09 by BM - Translate label if applicable
922 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
924 for ($i = 0; $i < 3; ++$i) {
925 $inputValue = htmlspecialchars($i, ENT_QUOTES);
926 echo "<td><input type='radio'" .
927 " name='radio_{$field_id_esc}[$option_id_esc]'" .
928 " id='radio_{$field_id_esc}[$option_id_esc]'" .
929 " value='$inputValue' $lbfonchange";
930 if ($restype === "$i") {
931 echo " checked";
934 echo " $disabled /></td>";
937 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
938 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
939 echo "<td><input type='text'" .
940 " name='form_{$field_id_esc}[$option_id_esc]'" .
941 " id='form_{$field_id_esc}[$option_id_esc]'" .
942 " size='$fldlength'" .
943 " $string_maxlength" .
944 " value='$resnote' $disabled /></td>";
945 echo "</tr>";
948 echo "</table>";
949 } // the list of active allergies for the current patient
950 // this is read-only!
951 else if ($data_type == 24) {
952 $query = "SELECT title, comments FROM lists WHERE " .
953 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
954 "ORDER BY begdate";
955 // echo "<!-- $query -->\n"; // debugging
956 $lres = sqlStatement($query, array($GLOBALS['pid']));
957 $count = 0;
958 while ($lrow = sqlFetchArray($lres)) {
959 if ($count++) {
960 echo "<br />";
963 echo htmlspecialchars($lrow['title'], ENT_NOQUOTES);
964 if ($lrow['comments']) {
965 echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
968 } // a set of labeled checkboxes, each with a text field:
969 else if ($data_type == 25) {
970 $tmp = explode('|', $currvalue);
971 $avalue = array();
972 foreach ($tmp as $value) {
973 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
974 $avalue[$matches[1]] = $matches[2];
978 $maxlength = $frow['max_length'];
979 $string_maxlength = "";
980 // if max_length is set to zero, then do not set a maxlength
981 if ($maxlength) {
982 $string_maxlength = "maxlength='".attr($maxlength)."'";
985 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
986 $lres = sqlStatement("SELECT * FROM list_options " .
987 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
988 echo "<table cellpadding='0' cellspacing='0'>";
989 while ($lrow = sqlFetchArray($lres)) {
990 $option_id = $lrow['option_id'];
991 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
992 $restype = substr($avalue[$option_id], 0, 1);
993 $resnote = substr($avalue[$option_id], 2);
995 // Added 5-09 by BM - Translate label if applicable
996 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
998 $option_id = htmlspecialchars($option_id, ENT_QUOTES);
999 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
1000 " id='check_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
1001 if ($restype) {
1002 echo " checked";
1005 echo " $disabled />&nbsp;</td>";
1006 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1007 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1008 echo "<td><input type='text'" .
1009 " name='form_{$field_id_esc}[$option_id_esc]'" .
1010 " id='form_{$field_id_esc}[$option_id_esc]'" .
1011 " size='$fldlength'" .
1012 " class='form-control' " .
1013 " $string_maxlength" .
1014 " value='$resnote' $disabled /></td>";
1015 echo "</tr>";
1018 echo "</table>";
1019 } // single-selection list with ability to add to it
1020 else if ($data_type == 26) {
1021 echo generate_select_list(
1022 "form_$field_id",
1023 $list_id,
1024 $currvalue,
1025 $description,
1026 ($showEmpty ? $empty_title : ''),
1027 'addtolistclass_'.$list_id,
1028 $lbfchange,
1030 ($disabled ? array('disabled' => 'disabled') : null),
1031 false,
1032 $backup_list
1034 // show the add button if user has access to correct list
1035 $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES);
1036 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
1037 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
1038 if (aco_exist('lists', $list_id)) {
1039 // a specific aco exist for this list, so ensure access
1040 if (acl_check('lists', $list_id)) {
1041 echo $outputAddButton;
1043 } else {
1044 // no specific aco exist for this list, so check for access to 'default' list
1045 if (acl_check('lists', 'default')) {
1046 echo $outputAddButton;
1049 } // a set of labeled radio buttons
1050 else if ($data_type == 27) {
1051 // In this special case, fld_length is the number of columns generated.
1052 $cols = max(1, $frow['fld_length']);
1053 $lres = sqlStatement("SELECT * FROM list_options " .
1054 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1055 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1056 $tdpct = (int) (100 / $cols);
1057 $got_selected = false;
1058 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1059 $option_id = $lrow['option_id'];
1060 $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES);
1061 if ($count % $cols == 0) {
1062 if ($count) {
1063 echo "</tr>";
1066 echo "<tr>";
1069 echo "<td width='" . attr($tdpct) . "%'>";
1070 echo "<input type='radio' name='form_{$field_id_esc}' class='form-control' id='form_{$field_id_esc}[$option_id_esc]'" .
1071 " value='$option_id_esc' $lbfonchange";
1072 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1073 (strlen($currvalue) > 0 && $option_id == $currvalue)) {
1074 echo " checked";
1075 $got_selected = true;
1078 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1079 echo "</td>";
1082 if ($count) {
1083 echo "</tr>";
1084 if ($count > $cols) {
1085 // Add some space after multiple rows of radio buttons.
1086 $cols = htmlspecialchars($cols, ENT_QUOTES);
1087 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1091 echo "</table>";
1092 if (!$got_selected && strlen($currvalue) > 0) {
1093 $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES);
1094 $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES);
1095 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
1097 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1098 // VicarePlus :: A selection list box for smoking status:
1099 else if ($data_type == 28 || $data_type == 32) {
1100 $tmp = explode('|', $currvalue);
1101 switch (count($tmp)) {
1102 case "4":
1103 $resnote = $tmp[0];
1104 $restype = $tmp[1];
1105 $resdate = $tmp[2];
1106 $reslist = $tmp[3];
1107 break;
1108 case "3":
1109 $resnote = $tmp[0];
1110 $restype = $tmp[1];
1111 $resdate = $tmp[2];
1112 break;
1113 case "2":
1114 $resnote = $tmp[0];
1115 $restype = $tmp[1];
1116 $resdate = "";
1117 break;
1118 case "1":
1119 $resnote = $tmp[0];
1120 $resdate = $restype = "";
1121 break;
1122 default:
1123 $restype = $resdate = $resnote = "";
1124 break;
1127 $maxlength = $frow['max_length'];
1128 $string_maxlength = "";
1129 // if max_length is set to zero, then do not set a maxlength
1130 if ($maxlength) {
1131 $string_maxlength = "maxlength='".attr($maxlength)."'";
1134 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1136 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1137 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1138 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1139 echo "<table cellpadding='0' cellspacing='0'>";
1140 echo "<tr>";
1141 if ($data_type == 28) {
1142 // input text
1143 echo "<td><input type='text'" .
1144 " name='form_$field_id_esc'" .
1145 " id='form_$field_id_esc'" .
1146 " size='$fldlength'" .
1147 " $string_maxlength" .
1148 " value='$resnote' $disabled />&nbsp;</td>";
1149 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1150 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1151 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1152 } else if ($data_type == 32) {
1153 // input text
1154 echo "<tr><td><input type='text'" .
1155 " name='form_text_$field_id_esc'" .
1156 " id='form_text_$field_id_esc'" .
1157 " size='$fldlength'" .
1158 " class='form-control'" .
1159 " $string_maxlength" .
1160 " value='$resnote' $disabled />&nbsp;</td></tr>";
1161 echo "<td>";
1162 //Selection list for smoking status
1163 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1164 echo generate_select_list(
1165 "form_$field_id",
1166 $list_id,
1167 $reslist,
1168 $description,
1169 ($showEmpty ? $empty_title : ''),
1171 $onchange,
1173 ($disabled ? array('disabled' => 'disabled') : null)
1175 echo "</td>";
1176 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1179 // current
1180 echo "<td class='text' ><input type='radio'" .
1181 " name='radio_{$field_id_esc}'" .
1182 " id='radio_{$field_id_esc}[current]'" .
1183 " class='form-control'" .
1184 " value='current" . $field_id_esc . "' $lbfonchange";
1185 if ($restype == "current" . $field_id) {
1186 echo " checked";
1189 if ($data_type == 32) {
1190 echo " onClick='smoking_statusClicked(this)'";
1193 echo " />" . xlt('Current') . "&nbsp;</td>";
1194 // quit
1195 echo "<td class='text'><input type='radio'" .
1196 " name='radio_{$field_id_esc}'" .
1197 " id='radio_{$field_id_esc}[quit]'" .
1198 " class='form-control'" .
1199 " value='quit".$field_id_esc."' $lbfonchange";
1200 if ($restype == "quit" . $field_id) {
1201 echo " checked";
1204 if ($data_type == 32) {
1205 echo " onClick='smoking_statusClicked(this)'";
1208 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1209 // quit date
1210 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1211 " value='$resdate'" .
1212 " title='$description'" .
1213 " $disabled />";
1214 echo "&nbsp;</td>";
1215 // never
1216 echo "<td class='text'><input type='radio'" .
1217 " name='radio_{$field_id_esc}'" .
1218 " class='form-control'" .
1219 " id='radio_{$field_id_esc}[never]'" .
1220 " value='never" . $field_id_esc . "' $lbfonchange";
1221 if ($restype == "never" . $field_id) {
1222 echo " checked";
1225 if ($data_type == 32) {
1226 echo " onClick='smoking_statusClicked(this)'";
1229 echo " />" . xlt('Never') . "&nbsp;</td>";
1230 // Not Applicable
1231 echo "<td class='text'><input type='radio'" .
1232 " class='form-control' " .
1233 " name='radio_{$field_id}'" .
1234 " id='radio_{$field_id}[not_applicable]'" .
1235 " value='not_applicable" . $field_id . "' $lbfonchange";
1236 if ($restype == "not_applicable" . $field_id) {
1237 echo " checked";
1240 if ($data_type == 32) {
1241 echo " onClick='smoking_statusClicked(this)'";
1244 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1246 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1247 echo "<td class='text' ><div id='smoke_code'></div></td>";
1248 echo "</tr>";
1249 echo "</table>";
1250 } // static text. read-only, of course.
1251 else if ($data_type == 31) {
1252 echo parse_static_text($frow);
1253 } //$data_type == 33
1254 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1255 //$data_type == 33
1257 else if ($data_type == 34) {
1258 $arr = explode("|*|*|*|", $currvalue);
1259 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc, ENT_QUOTES)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1260 echo "<div id='form_{$field_id}_div' class='text-area' style='min-width:100pt'>" . $arr[0] . "</div>";
1261 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' class='form-control' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1262 echo "</a>";
1263 } //facilities drop-down list
1264 else if ($data_type == 35) {
1265 if (empty($currvalue)) {
1266 $currvalue = 0;
1269 dropdown_facility(
1270 $selected = $currvalue,
1271 $name = "form_$field_id_esc",
1272 $allow_unspecified = true,
1273 $allow_allfacilities = false,
1274 $disabled,
1275 $lbfchange
1277 } //multiple select
1278 // supports backup list
1279 else if ($data_type == 36) {
1280 echo generate_select_list(
1281 "form_$field_id",
1282 $list_id,
1283 $currvalue,
1284 $description,
1285 $showEmpty ? $empty_title : '',
1287 $lbfchange,
1289 null,
1290 true,
1291 $backup_list
1293 } // Canvas and related elements for browser-side image drawing.
1294 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1295 else if ($data_type == 40) {
1296 // Unlike other field types, width and height are in pixels.
1297 $canWidth = intval($frow['fld_length']);
1298 $canHeight = intval($frow['fld_rows']);
1299 if (empty($currvalue)) {
1300 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1301 // If defined this is the filename of the default starting image.
1302 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1306 $mywidth = 50 + ($canWidth > 250 ? $canWidth : 250);
1307 $myheight = 31 + ($canHeight > 261 ? $canHeight : 261);
1308 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1309 // Hidden form field exists to send updated data to the server at submit time.
1310 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1311 // Hidden image exists to support initialization of the canvas.
1312 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1313 // $date_init is a misnomer but it's the place for browser-side setup logic.
1314 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1318 function generate_print_field($frow, $currvalue)
1320 global $rootdir, $date_init, $ISSUE_TYPES;
1322 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1324 $data_type = $frow['data_type'];
1325 $field_id = $frow['field_id'];
1326 $list_id = $frow['list_id'];
1327 $fld_length = $frow['fld_length'];
1328 $backup_list = $frow['list_backup_id'];
1330 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1332 // Can pass $frow['empty_title'] with this variable, otherwise
1333 // will default to 'Unassigned'.
1334 // If it is 'SKIP' then an empty text title is completely skipped.
1335 $showEmpty = true;
1336 if (isset($frow['empty_title'])) {
1337 if ($frow['empty_title'] == "SKIP") {
1338 //do not display an 'empty' choice
1339 $showEmpty = false;
1340 $empty_title = "Unassigned";
1341 } else {
1342 $empty_title = $frow['empty_title'];
1344 } else {
1345 $empty_title = "Unassigned";
1348 // generic single-selection list
1349 // Supports backup lists.
1350 if (false && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1351 if (empty($fld_length)) {
1352 if ($list_id == 'titles') {
1353 $fld_length = 3;
1354 } else {
1355 $fld_length = 10;
1359 $tmp = '';
1360 if ($currvalue) {
1361 $lrow = sqlQuery("SELECT title FROM list_options " .
1362 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1363 $tmp = xl_list_label($lrow['title']);
1364 if ($lrow == 0 && !empty($backup_list)) {
1365 // since primary list did not map, try to map to backup list
1366 $lrow = sqlQuery("SELECT title FROM list_options " .
1367 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1368 $tmp = xl_list_label($lrow['title']);
1371 if (empty($tmp)) {
1372 $tmp = "($currvalue)";
1376 /*****************************************************************
1377 echo "<input type='text'" .
1378 " size='$fld_length'" .
1379 " value='$tmp'" .
1380 " class='under'" .
1381 " />";
1382 *****************************************************************/
1383 if ($tmp === '') {
1384 $tmp = '&nbsp;';
1385 } else {
1386 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1389 echo $tmp;
1390 } // simple text field
1391 else if ($data_type == 2 || $data_type == 15) {
1392 /*****************************************************************
1393 echo "<input type='text'" .
1394 " size='$fld_length'" .
1395 " value='$currescaped'" .
1396 " class='under'" .
1397 " />";
1398 *****************************************************************/
1399 if ($currescaped === '') {
1400 $currescaped = '&nbsp;';
1403 echo $currescaped;
1404 } // long or multi-line text field
1405 else if ($data_type == 3) {
1406 $fldlength = htmlspecialchars($fld_length, ENT_QUOTES);
1407 $maxlength = htmlspecialchars($frow['fld_rows'], ENT_QUOTES);
1408 echo "<textarea" .
1409 " class='form-control' " .
1410 " cols='$fldlength'" .
1411 " rows='$maxlength'>" .
1412 $currescaped . "</textarea>";
1413 } // date
1414 else if ($data_type == 4) {
1415 $age_asof_date = '';
1416 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
1417 if ($currvalue === '') {
1418 echo '&nbsp;';
1419 } else {
1420 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
1421 if (!$modtmp) {
1422 echo text(oeFormatShortDate($currvalue));
1423 } else {
1424 echo text(oeFormatDateTime($currvalue));
1426 if ($agestr) {
1427 echo "&nbsp;(" . text($agestr) . ")";
1430 } // provider list
1431 else if ($data_type == 10 || $data_type == 11) {
1432 $tmp = '';
1433 if ($currvalue) {
1434 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1435 "WHERE id = ?", array($currvalue));
1436 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1437 if (empty($tmp)) {
1438 $tmp = "($currvalue)";
1442 /*****************************************************************
1443 echo "<input type='text'" .
1444 " size='$fld_length'" .
1445 " value='$tmp'" .
1446 " class='under'" .
1447 " />";
1448 *****************************************************************/
1449 if ($tmp === '') {
1450 $tmp = '&nbsp;';
1451 } else {
1452 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1455 echo $tmp;
1456 } // pharmacy list
1457 else if ($data_type == 12) {
1458 $tmp = '';
1459 if ($currvalue) {
1460 $pres = get_pharmacies();
1461 while ($prow = sqlFetchArray($pres)) {
1462 $key = $prow['id'];
1463 if ($currvalue == $key) {
1464 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1465 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1466 $prow['line1'] . ' / ' . $prow['city'];
1470 if (empty($tmp)) {
1471 $tmp = "($currvalue)";
1475 /*****************************************************************
1476 echo "<input type='text'" .
1477 " size='$fld_length'" .
1478 " value='$tmp'" .
1479 " class='under'" .
1480 " />";
1481 *****************************************************************/
1482 if ($tmp === '') {
1483 $tmp = '&nbsp;';
1484 } else {
1485 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1488 echo $tmp;
1489 } // squads
1490 else if ($data_type == 13) {
1491 $tmp = '';
1492 if ($currvalue) {
1493 $squads = acl_get_squads();
1494 if ($squads) {
1495 foreach ($squads as $key => $value) {
1496 if ($currvalue == $key) {
1497 $tmp = $value[3];
1502 if (empty($tmp)) {
1503 $tmp = "($currvalue)";
1507 /*****************************************************************
1508 echo "<input type='text'" .
1509 " size='$fld_length'" .
1510 " value='$tmp'" .
1511 " class='under'" .
1512 " />";
1513 *****************************************************************/
1514 if ($tmp === '') {
1515 $tmp = '&nbsp;';
1516 } else {
1517 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1520 echo $tmp;
1521 } // Address book.
1522 else if ($data_type == 14) {
1523 $tmp = '';
1524 if ($currvalue) {
1525 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1526 "WHERE id = ?", array($currvalue));
1527 $uname = $urow['lname'];
1528 if ($urow['fname']) {
1529 $uname .= ", " . $urow['fname'];
1532 $tmp = $uname;
1533 if (empty($tmp)) {
1534 $tmp = "($currvalue)";
1538 /*****************************************************************
1539 echo "<input type='text'" .
1540 " size='$fld_length'" .
1541 " value='$tmp'" .
1542 " class='under'" .
1543 " />";
1544 *****************************************************************/
1545 if ($tmp === '') {
1546 $tmp = '&nbsp;';
1547 } else {
1548 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1551 echo $tmp;
1552 } // insurance company list
1553 else if ($data_type == 16) {
1554 $tmp = '';
1555 if ($currvalue) {
1556 $insprovs = getInsuranceProviders();
1557 foreach ($insprovs as $key => $ipname) {
1558 if ($currvalue == $key) {
1559 $tmp = $ipname;
1563 if (empty($tmp)) {
1564 $tmp = "($currvalue)";
1568 if ($tmp === '') {
1569 $tmp = '&nbsp;';
1570 } else {
1571 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1574 echo $tmp;
1575 } // issue types
1576 else if ($data_type == 17) {
1577 $tmp = '';
1578 if ($currvalue) {
1579 foreach ($ISSUE_TYPES as $key => $value) {
1580 if ($currvalue == $key) {
1581 $tmp = $value[1];
1585 if (empty($tmp)) {
1586 $tmp = "($currvalue)";
1590 if ($tmp === '') {
1591 $tmp = '&nbsp;';
1592 } else {
1593 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1596 echo $tmp;
1597 } // Visit categories.
1598 else if ($data_type == 18) {
1599 $tmp = '';
1600 if ($currvalue) {
1601 $crow = sqlQuery(
1602 "SELECT pc_catid, pc_catname " .
1603 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1604 array($currvalue)
1606 $tmp = xl_appt_category($crow['pc_catname']);
1607 if (empty($tmp)) {
1608 $tmp = "($currvalue)";
1612 if ($tmp === '') {
1613 $tmp = '&nbsp;';
1614 } else {
1615 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1618 echo $tmp;
1619 } // a single checkbox or set of labeled checkboxes
1620 else if ($data_type == 21) {
1621 if (!$list_id) {
1622 echo "<input type='checkbox'";
1623 if ($currvalue) {
1624 echo " checked";
1626 echo " />";
1627 } else {
1628 // In this special case, fld_length is the number of columns generated.
1629 $cols = max(1, $fld_length);
1630 $avalue = explode('|', $currvalue);
1631 $lres = sqlStatement("SELECT * FROM list_options " .
1632 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1633 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1634 $tdpct = (int) (100 / $cols);
1635 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1636 $option_id = $lrow['option_id'];
1637 if ($count % $cols == 0) {
1638 if ($count) {
1639 echo "</tr>";
1642 echo "<tr>";
1644 echo "<td width='" . attr($tdpct) . "%'>";
1645 echo "<input type='checkbox'";
1646 if (in_array($option_id, $avalue)) {
1647 echo " checked";
1649 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1650 echo "</td>";
1652 if ($count) {
1653 echo "</tr>";
1654 if ($count > $cols) {
1655 // Add some space after multiple rows of checkboxes.
1656 $cols = htmlspecialchars($cols, ENT_QUOTES);
1657 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1660 echo "</table>";
1662 } // a set of labeled text input fields
1663 else if ($data_type == 22) {
1664 $tmp = explode('|', $currvalue);
1665 $avalue = array();
1666 foreach ($tmp as $value) {
1667 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1668 $avalue[$matches[1]] = $matches[2];
1672 $lres = sqlStatement("SELECT * FROM list_options " .
1673 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1674 echo "<table cellpadding='0' cellspacing='0'>";
1675 while ($lrow = sqlFetchArray($lres)) {
1676 $option_id = $lrow['option_id'];
1677 $fldlength = empty($fld_length) ? 20 : $fld_length;
1678 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1679 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1680 $inputValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES);
1681 echo "<td><input type='text'" .
1682 " class='form-control' " .
1683 " size='$fldlength'" .
1684 " value='$inputValue'" .
1685 " class='under'" .
1686 " /></td></tr>";
1689 echo "</table>";
1690 } // a set of exam results; 3 radio buttons and a text field:
1691 else if ($data_type == 23) {
1692 $tmp = explode('|', $currvalue);
1693 $avalue = array();
1694 foreach ($tmp as $value) {
1695 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1696 $avalue[$matches[1]] = $matches[2];
1700 $fldlength = empty($fld_length) ? 20 : $fld_length;
1701 $lres = sqlStatement("SELECT * FROM list_options " .
1702 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1703 echo "<table cellpadding='0' cellspacing='0'>";
1704 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1705 htmlspecialchars(xl('N/A'), ENT_NOQUOTES) .
1706 "&nbsp;</td><td class='bold'>" .
1707 htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1708 "<td class='bold'>" .
1709 htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1710 htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1711 while ($lrow = sqlFetchArray($lres)) {
1712 $option_id = $lrow['option_id'];
1713 $restype = substr($avalue[$option_id], 0, 1);
1714 $resnote = substr($avalue[$option_id], 2);
1715 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1716 for ($i = 0; $i < 3; ++$i) {
1717 echo "<td><input type='radio'";
1718 if ($restype === "$i") {
1719 echo " checked";
1722 echo " /></td>";
1725 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1726 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1727 echo "<td><input type='text'" .
1728 " size='$fldlength'" .
1729 " value='$resnote'" .
1730 " class='under form-control' /></td>" .
1731 "</tr>";
1734 echo "</table>";
1735 } // the list of active allergies for the current patient
1736 // this is read-only!
1737 else if ($data_type == 24) {
1738 $query = "SELECT title, comments FROM lists WHERE " .
1739 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1740 "ORDER BY begdate";
1741 $lres = sqlStatement($query, array($GLOBALS['pid']));
1742 $count = 0;
1743 while ($lrow = sqlFetchArray($lres)) {
1744 if ($count++) {
1745 echo "<br />";
1748 echo htmlspecialchars($lrow['title'], ENT_QUOTES);
1749 if ($lrow['comments']) {
1750 echo htmlspecialchars(' (' . $lrow['comments'] . ')', ENT_QUOTES);
1753 } // a set of labeled checkboxes, each with a text field:
1754 else if ($data_type == 25) {
1755 $tmp = explode('|', $currvalue);
1756 $avalue = array();
1757 foreach ($tmp as $value) {
1758 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1759 $avalue[$matches[1]] = $matches[2];
1763 $fldlength = empty($fld_length) ? 20 : $fld_length;
1764 $lres = sqlStatement("SELECT * FROM list_options " .
1765 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1766 echo "<table cellpadding='0' cellspacing='0'>";
1767 while ($lrow = sqlFetchArray($lres)) {
1768 $option_id = $lrow['option_id'];
1769 $restype = substr($avalue[$option_id], 0, 1);
1770 $resnote = substr($avalue[$option_id], 2);
1771 echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1772 echo "<td><input type='checkbox'";
1773 if ($restype) {
1774 echo " checked";
1777 echo " />&nbsp;</td>";
1778 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1779 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1780 echo "<td><input type='text'" .
1781 " size='$fldlength'" .
1782 " class='form-control' " .
1783 " value='$resnote'" .
1784 " class='under'" .
1785 " /></td>" .
1786 "</tr>";
1789 echo "</table>";
1790 } // a set of labeled radio buttons
1791 else if ($data_type == 27 || $data_type == 1 || $data_type == 26 || $data_type == 33) {
1792 // In this special case, fld_length is the number of columns generated.
1793 $cols = max(1, $frow['fld_length']);
1794 $lres = sqlStatement("SELECT * FROM list_options " .
1795 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
1796 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1797 $tdpct = (int) (100 / $cols);
1798 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1799 $option_id = $lrow['option_id'];
1800 if ($count % $cols == 0) {
1801 if ($count) {
1802 echo "</tr>";
1805 echo "<tr>";
1807 echo "<td width='" . attr($tdpct) . "%'>";
1808 echo "<input type='radio'";
1809 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1810 // Do not use defaults for these printable forms.
1811 echo " checked";
1814 echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
1815 echo "</td>";
1818 if ($count) {
1819 echo "</tr>";
1820 if ($count > $cols) {
1821 // Add some space after multiple rows of radio buttons.
1822 $cols = htmlspecialchars($cols, ENT_QUOTES);
1823 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1827 echo "</table>";
1828 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
1829 else if ($data_type == 28 || $data_type == 32) {
1830 $tmp = explode('|', $currvalue);
1831 switch (count($tmp)) {
1832 case "4":
1833 $resnote = $tmp[0];
1834 $restype = $tmp[1];
1835 $resdate = $tmp[2];
1836 $reslist = $tmp[3];
1837 break;
1838 case "3":
1839 $resnote = $tmp[0];
1840 $restype = $tmp[1];
1841 $resdate = $tmp[2];
1842 break;
1843 case "2":
1844 $resnote = $tmp[0];
1845 $restype = $tmp[1];
1846 $resdate = "";
1847 break;
1848 case "1":
1849 $resnote = $tmp[0];
1850 $resdate = $restype = "";
1851 break;
1852 default:
1853 $restype = $resdate = $resnote = "";
1854 break;
1857 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1858 echo "<table cellpadding='0' cellspacing='0'>";
1859 echo "<tr>";
1860 $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
1861 $resnote = htmlspecialchars($resnote, ENT_QUOTES);
1862 $resdate = htmlspecialchars($resdate, ENT_QUOTES);
1863 if ($data_type == 28) {
1864 echo "<td><input type='text'" .
1865 " size='$fldlength'" .
1866 " class='under'" .
1867 " value='$resnote' /></td>";
1868 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1869 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1870 htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1871 } else if ($data_type == 32) {
1872 echo "<tr><td><input type='text'" .
1873 " size='$fldlength'" .
1874 " class='under form-control'" .
1875 " value='$resnote' /></td></tr>";
1876 $fldlength = 30;
1877 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
1878 echo "<td><input type='text'" .
1879 " size='$fldlength'" .
1880 " class='under form-control'" .
1881 " value='$smoking_status_title' /></td>";
1882 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars(xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1885 echo "<td><input type='radio' class='form-control'";
1886 if ($restype == "current".$field_id) {
1887 echo " checked";
1890 echo "/>".htmlspecialchars(xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1892 echo "<td><input type='radio' class='form-control'";
1893 if ($restype == "current".$field_id) {
1894 echo " checked";
1897 echo "/>".htmlspecialchars(xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1899 echo "<td><input type='text' size='6'" .
1900 " value='$resdate'" .
1901 " class='under form-control'" .
1902 " /></td>";
1904 echo "<td><input type='radio' class='form-control'";
1905 if ($restype == "current".$field_id) {
1906 echo " checked";
1909 echo " />".htmlspecialchars(xl('Never'), ENT_NOQUOTES)."</td>";
1911 echo "<td><input type='radio' class='form-control'";
1912 if ($restype == "not_applicable".$field_id) {
1913 echo " checked";
1916 echo " />".htmlspecialchars(xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1917 echo "</tr>";
1918 echo "</table>";
1919 } // static text. read-only, of course.
1920 else if ($data_type == 31) {
1921 echo parse_static_text($frow);
1922 } else if ($data_type == 34) {
1923 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc, ENT_QUOTES)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1924 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1925 echo "<div style='display:none'><textarea name='form_{$field_id}' class='form-control' id='form_{$field_id}' stye='display:none'></textarea></div>";
1926 echo "</a>";
1927 } //facilities drop-down list
1928 else if ($data_type == 35) {
1929 // In this special case, fld_length is the number of columns generated.
1930 $cols = max(1, $frow['fld_length']);
1931 $lres = sqlStatement("SELECT id, name FROM facility ORDER BY name");
1932 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1933 $tdpct = (int) (100 / $cols);
1934 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1935 $option_id = $lrow['id'];
1936 if ($count % $cols == 0) {
1937 if ($count) {
1938 echo "</tr>";
1940 echo "<tr>";
1942 echo "<td width='" . attr($tdpct) . "%'>";
1943 echo "<input type='radio'";
1944 if (strlen($currvalue) > 0 && $option_id == $currvalue) {
1945 // Do not use defaults for these printable forms.
1946 echo " checked";
1948 echo ">" . htmlspecialchars($lrow['name']);
1949 echo "</td>";
1951 if ($count) {
1952 echo "</tr>";
1953 if ($count > $cols) {
1954 // Add some space after multiple rows of radio buttons.
1955 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1958 echo "</table>";
1959 } //Multi-select
1960 // Supports backup lists.
1961 else if ($data_type == 36) {
1962 if (empty($fld_length)) {
1963 if ($list_id == 'titles') {
1964 $fld_length = 3;
1965 } else {
1966 $fld_length = 10;
1970 $tmp = '';
1972 $values_array = explode("|", $currvalue);
1974 $i=0;
1975 foreach ($values_array as $value) {
1976 if ($value) {
1977 $lrow = sqlQuery("SELECT title FROM list_options " .
1978 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1979 $tmp = xl_list_label($lrow['title']);
1980 if ($lrow == 0 && !empty($backup_list)) {
1981 // since primary list did not map, try to map to backup list
1982 $lrow = sqlQuery("SELECT title FROM list_options " .
1983 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1984 $tmp = xl_list_label($lrow['title']);
1987 if (empty($tmp)) {
1988 $tmp = "($value)";
1992 if ($tmp === '') {
1993 $tmp = '&nbsp;';
1994 } else {
1995 $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1998 if ($i != 0 && $tmp != '&nbsp;') {
1999 echo ",";
2002 echo $tmp;
2003 $i++;
2005 } // Image from canvas drawing
2006 else if ($data_type == 40) {
2007 if ($currvalue) {
2008 echo "<img src='" . attr($currvalue) . "'>";
2013 function generate_display_field($frow, $currvalue)
2015 global $ISSUE_TYPES, $facilityService;
2017 $data_type = $frow['data_type'];
2018 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2019 $list_id = $frow['list_id'];
2020 $backup_list = isset($frow['list_backup_id']) ? $frow['list_backup_id'] : null;
2022 $s = '';
2024 // generic selection list or the generic selection list with add on the fly
2025 // feature
2026 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
2027 $lrow = sqlQuery("SELECT title FROM list_options " .
2028 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2029 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2030 //if there is no matching value in the corresponding lists check backup list
2031 // only supported in data types 1,26,33
2032 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2033 $lrow = sqlQuery("SELECT title FROM list_options " .
2034 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2035 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2037 } // simple text field
2038 else if ($data_type == 2) {
2039 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2040 } // long or multi-line text field
2041 else if ($data_type == 3) {
2042 $s = nl2br(htmlspecialchars($currvalue, ENT_NOQUOTES));
2043 } // date
2044 else if ($data_type == 4) {
2045 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
2046 $s = '';
2047 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2048 $age_asof_date = '';
2049 $agestr = optionalAge($frow, $currvalue, $age_asof_date, $description);
2050 if ($currvalue === '') {
2051 $s .= '&nbsp;';
2052 } else {
2053 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
2054 if (!$modtmp) {
2055 $s .= text(oeFormatShortDate($currvalue));
2056 } else {
2057 $s .= text(oeFormatDateTime($currvalue));
2059 if ($agestr) {
2060 $s .= "&nbsp;(" . text($agestr) . ")";
2063 } // provider
2064 else if ($data_type == 10 || $data_type == 11) {
2065 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2066 "WHERE id = ?", array($currvalue));
2067 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']), ENT_NOQUOTES);
2068 } // pharmacy list
2069 else if ($data_type == 12) {
2070 $pres = get_pharmacies();
2071 while ($prow = sqlFetchArray($pres)) {
2072 $key = $prow['id'];
2073 if ($currvalue == $key) {
2074 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
2075 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2076 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
2079 } // squads
2080 else if ($data_type == 13) {
2081 $squads = acl_get_squads();
2082 if ($squads) {
2083 foreach ($squads as $key => $value) {
2084 if ($currvalue == $key) {
2085 $s .= htmlspecialchars($value[3], ENT_NOQUOTES);
2089 } // address book
2090 else if ($data_type == 14) {
2091 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
2092 "WHERE id = ?", array($currvalue));
2093 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
2094 if ($urow['organization'] !="") {
2095 $uname = $urow['organization'];
2096 } else {
2097 $uname = $urow['lname'];
2098 if ($urow['fname']) {
2099 $uname .= ", " . $urow['fname'];
2103 $s = htmlspecialchars($uname, ENT_NOQUOTES);
2104 } // billing code
2105 else if ($data_type == 15) {
2106 $s = '';
2107 if (!empty($currvalue)) {
2108 $relcodes = explode(';', $currvalue);
2109 foreach ($relcodes as $codestring) {
2110 if ($codestring === '') {
2111 continue;
2113 $tmp = lookup_code_descriptions($codestring);
2114 if ($s !== '') {
2115 $s .= '; ';
2117 if (!empty($tmp)) {
2118 $s .= $tmp;
2119 } else {
2120 $s .= $codestring . ' (' . xl('not found') . ')';
2124 } // insurance company list
2125 else if ($data_type == 16) {
2126 $insprovs = getInsuranceProviders();
2127 foreach ($insprovs as $key => $ipname) {
2128 if ($currvalue == $key) {
2129 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
2132 } // issue types
2133 else if ($data_type == 17) {
2134 foreach ($ISSUE_TYPES as $key => $value) {
2135 if ($currvalue == $key) {
2136 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
2139 } // visit category
2140 else if ($data_type == 18) {
2141 $crow = sqlQuery(
2142 "SELECT pc_catid, pc_catname " .
2143 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2144 array($currvalue)
2146 $s = htmlspecialchars($crow['pc_catname'], ENT_NOQUOTES);
2147 } // a single checkbox or set of labeled checkboxes
2148 else if ($data_type == 21) {
2149 if (!$list_id) {
2150 $s .= $currvalue ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2151 } else {
2152 // In this special case, fld_length is the number of columns generated.
2153 $cols = max(1, $frow['fld_length']);
2154 $avalue = explode('|', $currvalue);
2155 $lres = sqlStatement("SELECT * FROM list_options " .
2156 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2157 $s .= "<table cellspacing='0' cellpadding='0'>";
2158 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2159 $option_id = $lrow['option_id'];
2160 $option_id_esc = text($option_id);
2161 if ($count % $cols == 0) {
2162 if ($count) {
2163 $s .= "</tr>";
2165 $s .= "<tr>";
2167 $s .= "<td nowrap>";
2168 $checked = in_array($option_id, $avalue);
2169 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2170 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2171 $s .= "</td>";
2173 if ($count) {
2174 $s .= "</tr>";
2176 $s .= "</table>";
2178 } // a set of labeled text input fields
2179 else if ($data_type == 22) {
2180 $tmp = explode('|', $currvalue);
2181 $avalue = array();
2182 foreach ($tmp as $value) {
2183 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2184 $avalue[$matches[1]] = $matches[2];
2188 $lres = sqlStatement("SELECT * FROM list_options " .
2189 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2190 $s .= "<table cellpadding='0' cellspacing='0'>";
2191 while ($lrow = sqlFetchArray($lres)) {
2192 $option_id = $lrow['option_id'];
2193 if (empty($avalue[$option_id])) {
2194 continue;
2197 // Added 5-09 by BM - Translate label if applicable
2198 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . ":&nbsp;</td>";
2200 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id], ENT_NOQUOTES) . "</td></tr>";
2203 $s .= "</table>";
2204 } // a set of exam results; 3 radio buttons and a text field:
2205 else if ($data_type == 23) {
2206 $tmp = explode('|', $currvalue);
2207 $avalue = array();
2208 foreach ($tmp as $value) {
2209 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2210 $avalue[$matches[1]] = $matches[2];
2214 $lres = sqlStatement("SELECT * FROM list_options " .
2215 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2216 $s .= "<table cellpadding='0' cellspacing='0'>";
2217 while ($lrow = sqlFetchArray($lres)) {
2218 $option_id = $lrow['option_id'];
2219 $restype = substr($avalue[$option_id], 0, 1);
2220 $resnote = substr($avalue[$option_id], 2);
2221 if (empty($restype) && empty($resnote)) {
2222 continue;
2225 // Added 5-09 by BM - Translate label if applicable
2226 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2228 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
2229 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2230 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2231 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2232 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2233 $s .= "</tr>";
2236 $s .= "</table>";
2237 } // the list of active allergies for the current patient
2238 else if ($data_type == 24) {
2239 $query = "SELECT title, comments FROM lists WHERE " .
2240 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2241 "ORDER BY begdate";
2242 // echo "<!-- $query -->\n"; // debugging
2243 $lres = sqlStatement($query, array($GLOBALS['pid']));
2244 $count = 0;
2245 while ($lrow = sqlFetchArray($lres)) {
2246 if ($count++) {
2247 $s .= "<br />";
2250 $s .= htmlspecialchars($lrow['title'], ENT_NOQUOTES);
2251 if ($lrow['comments']) {
2252 $s .= ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')';
2255 } // a set of labeled checkboxes, each with a text field:
2256 else if ($data_type == 25) {
2257 $tmp = explode('|', $currvalue);
2258 $avalue = array();
2259 foreach ($tmp as $value) {
2260 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2261 $avalue[$matches[1]] = $matches[2];
2265 $lres = sqlStatement("SELECT * FROM list_options " .
2266 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2267 $s .= "<table cellpadding='0' cellspacing='0'>";
2268 while ($lrow = sqlFetchArray($lres)) {
2269 $option_id = $lrow['option_id'];
2270 $restype = substr($avalue[$option_id], 0, 1);
2271 $resnote = substr($avalue[$option_id], 2);
2272 if (empty($restype) && empty($resnote)) {
2273 continue;
2276 // Added 5-09 by BM - Translate label if applicable
2277 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
2279 $restype = $restype ? xl('Yes') : xl('No');
2280 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype, ENT_NOQUOTES) . "&nbsp;</td>";
2281 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "</td>";
2282 $s .= "</tr>";
2285 $s .= "</table>";
2286 } // a set of labeled radio buttons
2287 else if ($data_type == 27) {
2288 // In this special case, fld_length is the number of columns generated.
2289 $cols = max(1, $frow['fld_length']);
2290 $lres = sqlStatement("SELECT * FROM list_options " .
2291 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2292 $s .= "<table cellspacing='0' cellpadding='0'>";
2293 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
2294 $option_id = $lrow['option_id'];
2295 $option_id_esc = text($option_id);
2296 if ($count % $cols == 0) {
2297 if ($count) {
2298 $s .= "</tr>";
2300 $s .= "<tr>";
2302 $s .= "<td>";
2303 $checked = ((strlen($currvalue) == 0 && $lrow['is_default']) ||
2304 (strlen($currvalue) > 0 && $option_id == $currvalue));
2305 $s .= $checked ? '[ x ]' : '[ &nbsp;&nbsp; ]';
2306 $s .= '&nbsp;' . text(xl_list_label($lrow['title'])). '&nbsp;&nbsp;';
2307 $s .= "</td>";
2309 if ($count) {
2310 $s .= "</tr>";
2312 $s .= "</table>";
2313 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2314 // VicarePlus :: A selection list for smoking status.
2315 else if ($data_type == 28 || $data_type == 32) {
2316 $tmp = explode('|', $currvalue);
2317 switch (count($tmp)) {
2318 case "4":
2319 $resnote = $tmp[0];
2320 $restype = $tmp[1];
2321 $resdate = $tmp[2];
2322 $reslist = $tmp[3];
2323 break;
2324 case "3":
2325 $resnote = $tmp[0];
2326 $restype = $tmp[1];
2327 $resdate = $tmp[2];
2328 break;
2329 case "2":
2330 $resnote = $tmp[0];
2331 $restype = $tmp[1];
2332 $resdate = "";
2333 break;
2334 case "1":
2335 $resnote = $tmp[0];
2336 $resdate = $restype = "";
2337 break;
2338 default:
2339 $restype = $resdate = $resnote = "";
2340 break;
2343 $s .= "<table cellpadding='0' cellspacing='0'>";
2345 $s .= "<tr>";
2346 $res = "";
2347 if ($restype == "current".$field_id) {
2348 $res = xl('Current');
2351 if ($restype == "quit".$field_id) {
2352 $res = xl('Quit');
2355 if ($restype == "never".$field_id) {
2356 $res = xl('Never');
2359 if ($restype == "not_applicable".$field_id) {
2360 $res = xl('N/A');
2363 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2364 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2365 if ($data_type == 28) {
2366 if (!empty($resnote)) {
2367 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2369 } //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2370 else if ($data_type == 32) {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2371 $smoke_codes = getSmokeCodes();
2372 if (!empty($reslist)) {
2373 if ($smoke_codes[$reslist]!="") {
2374 $code_desc = "( ".$smoke_codes[$reslist]." )";
2377 $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>";
2380 if (!empty($resnote)) {
2381 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote, ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2385 if (!empty($res)) {
2386 $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'), ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res, ENT_NOQUOTES) . "&nbsp;</td>";
2389 if ($restype == "quit".$field_id) {
2390 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate, ENT_NOQUOTES) . "&nbsp;</td>";
2393 $s .= "</tr>";
2394 $s .= "</table>";
2395 } // static text. read-only, of course.
2396 else if ($data_type == 31) {
2397 $s .= parse_static_text($frow);
2398 } else if ($data_type == 34) {
2399 $arr = explode("|*|*|*|", $currvalue);
2400 for ($i=0; $i<sizeof($arr); $i++) {
2401 $s.=$arr[$i];
2403 } // facility
2404 else if ($data_type == 35) {
2405 $urow = $facilityService->getById($currvalue);
2406 $s = htmlspecialchars($urow['name'], ENT_NOQUOTES);
2407 } // Multi select
2408 // Supports backup lists
2409 else if ($data_type == 36) {
2410 $values_array = explode("|", $currvalue);
2411 $i = 0;
2412 foreach ($values_array as $value) {
2413 $lrow = sqlQuery("SELECT title FROM list_options " .
2414 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2415 if ($lrow == 0 && !empty($backup_list)) {
2416 //use back up list
2417 $lrow = sqlQuery("SELECT title FROM list_options " .
2418 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2421 if ($i > 0) {
2422 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2423 } else {
2424 $s = htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
2427 $i++;
2429 } // Image from canvas drawing
2430 else if ($data_type == 40) {
2431 if ($currvalue) {
2432 $s .= "<img src='" . attr($currvalue) . "'>";
2436 return $s;
2439 // Generate plain text versions of selected LBF field types.
2440 // Currently used by interface/patient_file/download_template.php and interface/main/finder/dynamic_finder_ajax.php.
2441 // More field types might need to be supported here in the future.
2443 function generate_plaintext_field($frow, $currvalue)
2445 global $ISSUE_TYPES;
2447 $data_type = $frow['data_type'];
2448 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2449 $list_id = $frow['list_id'];
2450 $backup_list = $frow['backup_list'];
2451 $s = '';
2453 // generic selection list or the generic selection list with add on the fly
2454 // feature, or radio buttons
2455 // Supports backup lists (for datatypes 1,26,33)
2456 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2457 $lrow = sqlQuery("SELECT title FROM list_options " .
2458 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
2459 $s = xl_list_label($lrow['title']);
2460 //if there is no matching value in the corresponding lists check backup list
2461 // only supported in data types 1,26,33
2462 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2463 $lrow = sqlQuery("SELECT title FROM list_options " .
2464 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
2465 $s = xl_list_label($lrow['title']);
2467 } // simple or long text field
2468 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2469 $s = $currvalue;
2470 } // date
2471 else if ($data_type == 4) {
2472 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
2473 if (!$modtmp) {
2474 $s = text(oeFormatShortDate($currvalue));
2475 } else {
2476 $s = text(oeFormatDateTime($currvalue));
2478 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
2479 $age_asof_date = '';
2480 // Optional display of age or gestational age.
2481 $tmp = optionalAge($frow, $currvalue, $age_asof_date, $description);
2482 if ($tmp) {
2483 $s .= ' ' . $tmp;
2485 } // provider
2486 else if ($data_type == 10 || $data_type == 11) {
2487 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2488 "WHERE id = ?", array($currvalue));
2489 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2490 } // pharmacy list
2491 else if ($data_type == 12) {
2492 $pres = get_pharmacies();
2493 while ($prow = sqlFetchArray($pres)) {
2494 $key = $prow['id'];
2495 if ($currvalue == $key) {
2496 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2497 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2498 $prow['line1'] . ' / ' . $prow['city'];
2501 } // address book
2502 else if ($data_type == 14) {
2503 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2504 "WHERE id = ?", array($currvalue));
2505 $uname = $urow['lname'];
2506 if ($urow['fname']) {
2507 $uname .= ", " . $urow['fname'];
2510 $s = $uname;
2511 } // insurance company list
2512 else if ($data_type == 16) {
2513 $insprovs = getInsuranceProviders();
2514 foreach ($insprovs as $key => $ipname) {
2515 if ($currvalue == $key) {
2516 $s .= $ipname;
2519 } // issue type
2520 else if ($data_type == 17) {
2521 foreach ($ISSUE_TYPES as $key => $value) {
2522 if ($currvalue == $key) {
2523 $s .= $value[1];
2526 } // visit category
2527 else if ($data_type == 18) {
2528 $crow = sqlQuery(
2529 "SELECT pc_catid, pc_catname " .
2530 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2531 array($currvalue)
2533 $s = $crow['pc_catname'];
2534 } // a set of labeled checkboxes
2535 else if ($data_type == 21) {
2536 if (!$list_id) {
2537 $s .= $currvalue ? xlt('Yes') : xlt('No');
2538 } else {
2539 $avalue = explode('|', $currvalue);
2540 $lres = sqlStatement("SELECT * FROM list_options " .
2541 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2542 $count = 0;
2543 while ($lrow = sqlFetchArray($lres)) {
2544 $option_id = $lrow['option_id'];
2545 if (in_array($option_id, $avalue)) {
2546 if ($count++) {
2547 $s .= "; ";
2549 $s .= xl_list_label($lrow['title']);
2553 } // a set of labeled text input fields
2554 else if ($data_type == 22) {
2555 $tmp = explode('|', $currvalue);
2556 $avalue = array();
2557 foreach ($tmp as $value) {
2558 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2559 $avalue[$matches[1]] = $matches[2];
2563 $lres = sqlStatement("SELECT * FROM list_options " .
2564 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2565 while ($lrow = sqlFetchArray($lres)) {
2566 $option_id = $lrow['option_id'];
2567 if (empty($avalue[$option_id])) {
2568 continue;
2571 if ($s !== '') {
2572 $s .= '; ';
2575 $s .= xl_list_label($lrow['title']) . ': ';
2576 $s .= $avalue[$option_id];
2578 } // A set of exam results; 3 radio buttons and a text field.
2579 // This shows abnormal results only.
2580 else if ($data_type == 23) {
2581 $tmp = explode('|', $currvalue);
2582 $avalue = array();
2583 foreach ($tmp as $value) {
2584 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2585 $avalue[$matches[1]] = $matches[2];
2589 $lres = sqlStatement("SELECT * FROM list_options " .
2590 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2591 while ($lrow = sqlFetchArray($lres)) {
2592 $option_id = $lrow['option_id'];
2593 $restype = substr($avalue[$option_id], 0, 1);
2594 $resnote = substr($avalue[$option_id], 2);
2595 if (empty($restype) && empty($resnote)) {
2596 continue;
2599 if ($restype != '2') {
2600 continue; // show abnormal results only
2603 if ($s !== '') {
2604 $s .= '; ';
2607 $s .= xl_list_label($lrow['title']);
2608 if (!empty($resnote)) {
2609 $s .= ': ' . $resnote;
2612 } // the list of active allergies for the current patient
2613 else if ($data_type == 24) {
2614 $query = "SELECT title, comments FROM lists WHERE " .
2615 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2616 "ORDER BY begdate";
2617 $lres = sqlStatement($query, array($GLOBALS['pid']));
2618 $count = 0;
2619 while ($lrow = sqlFetchArray($lres)) {
2620 if ($count++) {
2621 $s .= "; ";
2624 $s .= $lrow['title'];
2625 if ($lrow['comments']) {
2626 $s .= ' (' . $lrow['comments'] . ')';
2629 } // a set of labeled checkboxes, each with a text field:
2630 else if ($data_type == 25) {
2631 $tmp = explode('|', $currvalue);
2632 $avalue = array();
2633 foreach ($tmp as $value) {
2634 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2635 $avalue[$matches[1]] = $matches[2];
2639 $lres = sqlStatement("SELECT * FROM list_options " .
2640 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2641 while ($lrow = sqlFetchArray($lres)) {
2642 $option_id = $lrow['option_id'];
2643 $restype = substr($avalue[$option_id], 0, 1);
2644 $resnote = substr($avalue[$option_id], 2);
2645 if (empty($restype) && empty($resnote)) {
2646 continue;
2649 if ($s !== '') {
2650 $s .= '; ';
2653 $s .= xl_list_label($lrow['title']);
2654 $restype = $restype ? xl('Yes') : xl('No');
2655 $s .= $restype;
2656 if ($resnote) {
2657 $s .= ' ' . $resnote;
2660 } // special case for history of lifestyle status; 3 radio buttons and a date text field:
2661 // VicarePlus :: A selection list for smoking status.
2662 else if ($data_type == 28 || $data_type == 32) {
2663 $tmp = explode('|', $currvalue);
2664 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2665 $restype = count($tmp) > 1 ? $tmp[1] : '';
2666 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2667 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2668 $res = "";
2669 if ($restype == "current" . $field_id) {
2670 $res = xl('Current');
2673 if ($restype == "quit" . $field_id) {
2674 $res = xl('Quit');
2677 if ($restype == "never" . $field_id) {
2678 $res = xl('Never');
2681 if ($restype == "not_applicable". $field_id) {
2682 $res = xl('N/A');
2685 if ($data_type == 28) {
2686 if (!empty($resnote)) {
2687 $s .= $resnote;
2689 } // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2690 else if ($data_type == 32) {
2691 if (!empty($reslist)) {
2692 $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id), $reslist);
2695 if (!empty($resnote)) {
2696 $s .= ' ' . $resnote;
2700 if (!empty($res)) {
2701 if ($s !== '') {
2702 $s .= ' ';
2705 $s .= xl('Status') . ' ' . $res;
2708 if ($restype == "quit".$field_id) {
2709 if ($s !== '') {
2710 $s .= ' ';
2713 $s .= $resdate;
2715 } // Multi select
2716 // Supports backup lists
2717 else if ($data_type == 36) {
2718 $values_array = explode("|", $currvalue);
2720 $i = 0;
2721 foreach ($values_array as $value) {
2722 $lrow = sqlQuery("SELECT title FROM list_options " .
2723 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
2725 if ($lrow == 0 && !empty($backup_list)) {
2726 //use back up list
2727 $lrow = sqlQuery("SELECT title FROM list_options " .
2728 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value));
2731 if ($i > 0) {
2732 $s = $s . ", " . xl_list_label($lrow['title']);
2733 } else {
2734 $s = xl_list_label($lrow['title']);
2737 $i++;
2741 return $s;
2744 $CPR = 4; // cells per row of generic data
2745 $last_group = '';
2746 $cell_count = 0;
2747 $item_count = 0;
2749 function disp_end_cell()
2751 global $item_count, $cell_count;
2752 if ($item_count > 0) {
2753 echo "</td>";
2754 $item_count = 0;
2758 function disp_end_row()
2760 global $cell_count, $CPR;
2761 disp_end_cell();
2762 if ($cell_count > 0) {
2763 for (; $cell_count < $CPR;
2764 ++$cell_count) {
2765 echo "<td></td>";
2768 echo "</tr>\n";
2769 $cell_count = 0;
2773 function disp_end_group()
2775 global $last_group;
2776 if (strlen($last_group) > 0) {
2777 disp_end_row();
2781 // Accumulate action conditions into a JSON expression for the browser side.
2782 function accumActionConditions($field_id, &$condition_str, &$condarr)
2784 $conditions = empty($condarr) ? array() : unserialize($condarr);
2785 $action = 'skip';
2786 foreach ($conditions as $key => $condition) {
2787 if ($key === 'action') {
2788 // If specified this should be the first array item.
2789 if ($condition) {
2790 $action = $condition;
2792 continue;
2794 if (empty($condition['id'])) {
2795 continue;
2797 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2798 if ($condition_str) {
2799 $condition_str .= ",\n";
2801 $condition_str .= "{" .
2802 "target:'" . addslashes($field_id) . "', " .
2803 "action:'" . addslashes($action) . "', " .
2804 "id:'" . addslashes($condition['id']) . "', " .
2805 "itemid:'" . addslashes($condition['itemid']) . "', " .
2806 "operator:'" . addslashes($condition['operator']) . "', " .
2807 "value:'" . addslashes($condition['value']) . "', " .
2808 "andor:'" . addslashes($andor) . "'}";
2812 // This checks if the given field with the given value should have an action applied.
2813 // Originally the only action was skip, but now you can also set the field to a specified value.
2814 // It somewhat mirrors the checkSkipConditions function in options.js.php.
2815 // If you use this for multiple layouts in the same script, you should
2816 // clear $sk_layout_items before each layout.
2817 function isSkipped(&$frow, $currvalue)
2819 global $sk_layout_items;
2821 // Accumulate an array of the encountered fields and their values.
2822 // It is assumed that fields appear before they are tested by another field.
2823 // TBD: Bad assumption?
2824 $field_id = $frow['field_id'];
2825 if (!is_array($sk_layout_items)) {
2826 $sk_layout_items = array();
2828 $sk_layout_items[$field_id] = array('row' => $frow, 'value' => $currvalue);
2830 if (empty($frow['conditions'])) {
2831 return false;
2834 $skiprows = unserialize($frow['conditions']);
2835 $prevandor = '';
2836 $prevcond = false;
2837 $datatype = $frow['data_type'];
2838 $action = 'skip'; // default action if none specified
2840 foreach ($skiprows as $key => $skiprow) {
2841 // id referenced field id
2842 // itemid referenced array key if applicable
2843 // operator "eq", "ne", "se" or "ns"
2844 // value if eq or ne, some string to compare with
2845 // andor "and", "or" or empty
2847 if ($key === 'action') {
2848 // Action value is a string. It can be "skip", or "value=" followed by a value.
2849 $action = $skiprow;
2850 continue;
2853 if (empty($skiprow['id'])) {
2854 continue;
2857 $id = $skiprow['id'];
2858 if (!isset($sk_layout_items[$id])) {
2859 error_log("Function isSkipped() cannot find skip source field '$id'.");
2860 continue;
2862 $itemid = $skiprow['itemid'];
2863 $operator = $skiprow['operator'];
2864 $skipval = $skiprow['value'];
2865 $srcvalue = $sk_layout_items[$id]['value'];
2866 $src_datatype = $sk_layout_items[$id]['row']['data_type'];
2867 $src_list_id = $sk_layout_items[$id]['row']['list_id'];
2869 // Some data types use itemid and we have to dig for their value.
2870 if ($src_datatype == 21 && $src_list_id) { // array of checkboxes
2871 $tmp = explode('|', $srcvalue);
2872 $srcvalue = in_array($itemid, $tmp);
2873 } else if ($src_datatype == 22 || $src_datatype == 23 || $src_datatype == 25) {
2874 $tmp = explode('|', $srcvalue);
2875 $srcvalue = '';
2876 foreach ($tmp as $tmp2) {
2877 if (strpos($tmp2, "$itemid:") === 0) {
2878 if ($datatype == 22) {
2879 $srcvalue = substr($tmp2, strlen($itemid) + 1);
2880 } else {
2881 $srcvalue = substr($tmp2, strlen($itemid) + 1, 1);
2887 // Compute the result of the test for this condition row.
2888 // PHP's looseness with variable type conversion helps us here.
2889 $condition = false;
2890 if ($operator == 'eq') {
2891 $condition = $srcvalue == $skipval;
2892 } else if ($operator == 'ne') {
2893 $condition = $srcvalue != $skipval;
2894 } else if ($operator == 'se') {
2895 $condition = $srcvalue == true;
2896 } else if ($operator == 'ns') {
2897 $condition = $srcvalue != true;
2898 } else {
2899 error_log("Unknown skip operator '$operator' for field '$field_id'.");
2902 // Logic to accumulate multiple conditions for the same target.
2903 if ($prevandor == 'and') {
2904 $condition = $condition && $prevcond;
2905 } else if ($prevandor == 'or') {
2906 $condition = $condition || $prevcond;
2908 $prevandor = $skiprow['andor'];
2909 $prevcond = $condition;
2911 return $prevcond ? $action : '';
2914 // Load array of names of the given layout and its groups.
2915 function getLayoutProperties($formtype, &$grparr, $sel = "grp_title")
2917 if ($sel != '*' && strpos($sel, 'grp_group_id') === false) {
2918 $sel = "grp_group_id, $sel";
2920 $gres = sqlStatement("SELECT $sel FROM layout_group_properties WHERE grp_form_id = ? " .
2921 "ORDER BY grp_group_id", array($formtype));
2922 while ($grow = sqlFetchArray($gres)) {
2923 $grparr[$grow['grp_group_id']] = $grow;
2927 function display_layout_rows($formtype, $result1, $result2 = '')
2929 global $item_count, $cell_count, $last_group, $CPR;
2931 $grparr = array();
2932 getLayoutProperties($formtype, $grparr, '*');
2934 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
2936 $fres = sqlStatement("SELECT * FROM layout_options " .
2937 "WHERE form_id = ? AND uor > 0 " .
2938 "ORDER BY group_id, seq", array($formtype));
2940 while ($frow = sqlFetchArray($fres)) {
2941 $this_group = $frow['group_id'];
2942 $titlecols = $frow['titlecols'];
2943 $datacols = $frow['datacols'];
2944 $data_type = $frow['data_type'];
2945 $field_id = $frow['field_id'];
2946 $list_id = $frow['list_id'];
2947 $currvalue = '';
2949 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
2951 if ($formtype == 'DEM') {
2952 if (strpos($field_id, 'em_') === 0) {
2953 // Skip employer related fields, if it's disabled.
2954 if ($GLOBALS['omit_employers']) {
2955 continue;
2958 $tmp = substr($field_id, 3);
2959 if (isset($result2[$tmp])) {
2960 $currvalue = $result2[$tmp];
2962 } else {
2963 if (isset($result1[$field_id])) {
2964 $currvalue = $result1[$field_id];
2967 } else {
2968 if (isset($result1[$field_id])) {
2969 $currvalue = $result1[$field_id];
2973 // Handle a data category (group) change.
2974 if (strcmp($this_group, $last_group) != 0) {
2975 $group_name = $grparr[$this_group]['grp_title'];
2976 // totally skip generating the employer category, if it's disabled.
2977 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
2978 continue;
2981 disp_end_group();
2982 $last_group = $this_group;
2985 // filter out all the empty field data from the patient report.
2986 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2987 // Handle starting of a new row.
2988 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2989 disp_end_row();
2990 echo "<tr>";
2991 if ($group_name) {
2992 echo "<td class='groupname'>";
2993 echo text(xl_layout_label($group_name));
2994 $group_name = '';
2995 } else {
2996 echo "<td valign='top'>&nbsp;";
2999 echo "</td>";
3002 if ($item_count == 0 && $titlecols == 0) {
3003 $titlecols = 1;
3006 // Handle starting of a new label cell.
3007 if ($titlecols > 0) {
3008 disp_end_cell();
3009 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
3010 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3011 echo "<td class='label_custom' colspan='$titlecols_esc' ";
3012 //if ($cell_count == 2) echo " style='padding-left:10pt'";
3013 echo ">";
3014 $cell_count += $titlecols;
3017 ++$item_count;
3019 // Added 5-09 by BM - Translate label if applicable
3020 if ($frow['title']) {
3021 $tmp = xl_layout_label($frow['title']);
3022 echo text($tmp);
3023 // Append colon only if label does not end with punctuation.
3024 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3025 echo ':';
3027 } else {
3028 echo "&nbsp;";
3031 // Handle starting of a new data cell.
3032 if ($datacols > 0) {
3033 disp_end_cell();
3034 //echo "<td class='text data' colspan='$datacols' valign='top'";
3035 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3036 echo "<td class='text data' colspan='$datacols_esc'";
3037 //if ($cell_count > 0) echo " style='padding-left:5pt'";
3038 echo ">";
3039 $cell_count += $datacols;
3042 ++$item_count;
3043 echo generate_display_field($frow, $currvalue);
3047 disp_end_group();
3050 function display_layout_tabs($formtype, $result1, $result2 = '')
3052 global $item_count, $cell_count, $last_group, $CPR;
3054 $grparr = array();
3055 getLayoutProperties($formtype, $grparr);
3057 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3058 "WHERE form_id = ? AND uor > 0 " .
3059 "ORDER BY group_id", array($formtype));
3061 $first = true;
3062 while ($frow = sqlFetchArray($fres)) {
3063 $this_group = $frow['group_id'];
3064 // $group_name = substr($this_group, 1);
3065 $group_name = $grparr[$this_group]['grp_title'];
3066 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3067 continue;
3070 <li <?php echo $first ? 'class="current"' : '' ?>>
3071 <a href="#" id="header_tab_<?php echo htmlspecialchars($group_name, ENT_QUOTES); ?>">
3072 <?php echo htmlspecialchars(xl_layout_label($group_name), ENT_NOQUOTES); ?></a>
3073 </li>
3074 <?php
3075 $first = false;
3079 function display_layout_tabs_data($formtype, $result1, $result2 = '')
3081 global $item_count, $cell_count, $last_group, $CPR;
3083 $grparr = array();
3084 getLayoutProperties($formtype, $grparr, '*');
3086 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3088 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3089 "WHERE form_id = ? AND uor > 0 " .
3090 "ORDER BY group_id", array($formtype));
3092 $first = true;
3093 while ($frow = sqlFetchArray($fres)) {
3094 $this_group = isset($frow['group_id']) ? $frow['group_id'] : "" ;
3096 if ($grparr[$this_group]['grp_columns'] === 'Employer' && $GLOBALS['omit_employers']) {
3097 continue;
3099 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3100 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : $grparr[$this_group]['grp_subtitle'];
3102 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3103 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3104 "ORDER BY seq", array($formtype, $this_group));
3107 <div class="tab <?php echo $first ? 'current' : '' ?>">
3108 <table border='0' cellpadding='0'>
3110 <?php
3111 while ($group_fields = sqlFetchArray($group_fields_query)) {
3112 $titlecols = $group_fields['titlecols'];
3113 $datacols = $group_fields['datacols'];
3114 $data_type = $group_fields['data_type'];
3115 $field_id = $group_fields['field_id'];
3116 $list_id = $group_fields['list_id'];
3117 $currvalue = '';
3118 $edit_options = $group_fields['edit_options'];
3120 if ($formtype == 'DEM') {
3121 if (strpos($field_id, 'em_') === 0) {
3122 // Skip employer related fields, if it's disabled.
3123 if ($GLOBALS['omit_employers']) {
3124 continue;
3127 $tmp = substr($field_id, 3);
3128 if (isset($result2[$tmp])) {
3129 $currvalue = $result2[$tmp];
3131 } else {
3132 if (isset($result1[$field_id])) {
3133 $currvalue = $result1[$field_id];
3136 } else {
3137 if (isset($result1[$field_id])) {
3138 $currvalue = $result1[$field_id];
3142 // Skip this field if action conditions call for that.
3143 // Note this also accumulates info for subsequent skip tests.
3144 $skip_this_field = isSkipped($group_fields, $currvalue) == 'skip';
3146 // Skip this field if its do-not-print option is set.
3147 if (isOption($edit_options, 'X') !== false) {
3148 $skip_this_field = true;
3151 // Handle a data category (group) change.
3152 if (strcmp($this_group, $last_group) != 0) {
3153 $group_name = $grparr[$this_group]['grp_title'];
3154 // totally skip generating the employer category, if it's disabled.
3155 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3156 continue;
3158 $last_group = $this_group;
3161 // Handle starting of a new row.
3162 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
3163 disp_end_row();
3164 if ($subtitle) {
3165 // Group subtitle exists and is not displayed yet.
3166 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3167 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3168 $subtitle = '';
3170 echo "<tr>";
3173 if ($item_count == 0 && $titlecols == 0) {
3174 $titlecols = 1;
3177 // Handle starting of a new label cell.
3178 if ($titlecols > 0) {
3179 disp_end_cell();
3180 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3181 $field_id_label = 'label_'.$group_fields['field_id'];
3182 echo "<td class='label_custom' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
3183 echo ">";
3184 $cell_count += $titlecols;
3187 ++$item_count;
3189 $field_id_label = 'label_'.$group_fields['field_id'];
3190 echo "<span id='".attr($field_id_label)."'>";
3191 if ($skip_this_field) {
3192 // No label because skipping
3193 } else if ($group_fields['title']) {
3194 $tmp = xl_layout_label($group_fields['title']);
3195 echo text($tmp);
3196 // Append colon only if label does not end with punctuation.
3197 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3198 echo ':';
3200 } else {
3201 echo "&nbsp;";
3203 echo "</span>";
3205 // Handle starting of a new data cell.
3206 if ($datacols > 0) {
3207 disp_end_cell();
3208 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3209 $field_id = 'text_'.$group_fields['field_id'];
3210 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
3211 if (!$skip_this_field && $data_type == 3) {
3212 // Textarea gets a light grey border.
3213 echo " style='border:1px solid #cccccc'";
3215 echo ">";
3216 $cell_count += $datacols;
3217 } else {
3218 $field_id = 'text_'.$group_fields['field_id'];
3219 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
3222 ++$item_count;
3223 if (!$skip_this_field) {
3224 echo generate_display_field($group_fields, $currvalue);
3228 disp_end_row();
3231 </table>
3232 </div>
3234 <?php
3236 $first = false;
3240 function display_layout_tabs_data_editable($formtype, $result1, $result2 = '')
3242 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
3244 $grparr = array();
3245 getLayoutProperties($formtype, $grparr, '*');
3247 $TOPCPR = empty($grparr['']['grp_columns']) ? 4 : $grparr['']['grp_columns'];
3249 $fres = sqlStatement("SELECT distinct group_id FROM layout_options " .
3250 "WHERE form_id = ? AND uor > 0 " .
3251 "ORDER BY group_id", array($formtype));
3253 $first = true;
3254 $condition_str = '';
3256 while ($frow = sqlFetchArray($fres)) {
3257 $this_group = $frow['group_id'];
3258 $group_name = $grparr[$this_group]['grp_title'];
3259 $group_name_esc = text($group_name);
3261 if ($grparr[$this_group]['grp_title'] === 'Employer' && $GLOBALS['omit_employers']) {
3262 continue;
3264 $CPR = empty($grparr[$this_group]['grp_columns']) ? $TOPCPR : $grparr[$this_group]['grp_columns'];
3265 $subtitle = empty($grparr[$this_group]['grp_subtitle']) ? '' : $grparr[$this_group]['grp_subtitle'];
3267 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
3268 "WHERE form_id = ? AND uor > 0 AND group_id = ? " .
3269 "ORDER BY seq", array($formtype, $this_group));
3272 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_', $group_name_esc)?>" >
3273 <table border='0' cellpadding='0'>
3275 <?php
3276 while ($group_fields = sqlFetchArray($group_fields_query)) {
3277 $titlecols = $group_fields['titlecols'];
3278 $datacols = $group_fields['datacols'];
3279 $data_type = $group_fields['data_type'];
3280 $field_id = $group_fields['field_id'];
3281 $list_id = $group_fields['list_id'];
3282 $backup_list = $group_fields['list_backup_id'];
3283 $currvalue = '';
3284 $action = 'skip';
3286 // Accumulate action conditions into a JSON expression for the browser side.
3287 accumActionConditions($field_id, $condition_str, $group_fields['conditions']);
3289 if ($formtype == 'DEM') {
3290 if (strpos($field_id, 'em_') === 0) {
3291 // Skip employer related fields, if it's disabled.
3292 if ($GLOBALS['omit_employers']) {
3293 continue;
3296 $tmp = substr($field_id, 3);
3297 if (isset($result2[$tmp])) {
3298 $currvalue = $result2[$tmp];
3300 } else {
3301 if (isset($result1[$field_id])) {
3302 $currvalue = $result1[$field_id];
3305 } else {
3306 if (isset($result1[$field_id])) {
3307 $currvalue = $result1[$field_id];
3311 // Handle a data category (group) change.
3312 if (strcmp($this_group, $last_group) != 0) {
3313 // totally skip generating the employer category, if it's disabled.
3314 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) {
3315 continue;
3318 $last_group = $this_group;
3321 // Handle starting of a new row.
3322 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
3323 disp_end_row();
3324 if ($subtitle) {
3325 // Group subtitle exists and is not displayed yet.
3326 echo "<tr><td class='label' style='background-color:#dddddd;padding:3pt' colspan='$CPR'>" . text($subtitle) . "</td></tr>\n";
3327 echo "<tr><td class='label' style='height:4pt' colspan='$CPR'></td></tr>\n";
3328 $subtitle = '';
3330 echo "<tr>";
3333 if ($item_count == 0 && $titlecols == 0) {
3334 $titlecols = 1;
3337 // Handle starting of a new label cell.
3338 if ($titlecols > 0) {
3339 disp_end_cell();
3340 $titlecols_esc = htmlspecialchars($titlecols, ENT_QUOTES);
3341 $field_id_label = 'label_'.$group_fields['field_id'];
3342 echo "<td class='label_custom' colspan='$titlecols_esc'";
3343 // This ID is used by skip conditions.
3344 echo " id='label_id_" . attr($field_id) . "'";
3345 echo ">";
3346 $cell_count += $titlecols;
3349 ++$item_count;
3351 if ($group_fields['title']) {
3352 $tmp = xl_layout_label($group_fields['title']);
3353 echo text($tmp);
3354 // Append colon only if label does not end with punctuation.
3355 if (strpos('?!.,:-=', substr($tmp, -1, 1)) === false) {
3356 echo ':';
3358 } else {
3359 echo "&nbsp;";
3362 // Handle starting of a new data cell.
3363 if ($datacols > 0) {
3364 disp_end_cell();
3365 $datacols_esc = htmlspecialchars($datacols, ENT_QUOTES);
3366 $field_id = 'text_'.$group_fields['field_id'];
3367 echo "<td class='text data' colspan='$datacols_esc'";
3368 // This ID is used by action conditions.
3369 echo " id='value_id_" . attr($field_id) . "'";
3370 echo ">";
3371 $cell_count += $datacols;
3374 ++$item_count;
3376 echo generate_form_field($group_fields, $currvalue);
3380 </table>
3381 </div>
3383 <?php
3385 $first = false;
3389 // From the currently posted HTML form, this gets the value of the
3390 // field corresponding to the provided layout_options table row.
3392 function get_layout_form_value($frow, $prefix = 'form_')
3394 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
3395 $data_type = $frow['data_type'];
3396 $field_id = $frow['field_id'];
3397 $value = '';
3398 if (isset($_POST["$prefix$field_id"])) {
3399 if ($data_type == 4) {
3400 $modtmp = isOption($frow['edit_options'], 'F') === false ? 0 : 1;
3401 if (!$modtmp) {
3402 $value = DateToYYYYMMDD($_POST["$prefix$field_id"]);
3403 } else {
3404 $value = DateTimeToYYYYMMDDHHMMSS($_POST["$prefix$field_id"]);
3406 } else if ($data_type == 21) {
3407 if (!$frow['list_id']) {
3408 if (!empty($_POST["form_$field_id"])) {
3409 $value = xlt('Yes');
3411 } else {
3412 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
3413 // must be concatenated into a |-separated string.
3414 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3415 if (strlen($value)) {
3416 $value .= '|';
3418 $value .= $key;
3421 } else if ($data_type == 22) {
3422 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
3423 // into "key:value|key:value|...".
3424 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3425 $val = str_replace('|', ' ', $val);
3426 if (strlen($value)) {
3427 $value .= '|';
3430 $value .= "$key:$val";
3432 } else if ($data_type == 23) {
3433 // $_POST["$prefix$field_id"] is an array of text fields with companion
3434 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
3435 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3436 $restype = $_POST["radio_{$field_id}"][$key];
3437 if (empty($restype)) {
3438 $restype = '0';
3441 $val = str_replace('|', ' ', $val);
3442 if (strlen($value)) {
3443 $value .= '|';
3446 $value .= "$key:$restype:$val";
3448 } else if ($data_type == 25) {
3449 // $_POST["$prefix$field_id"] is an array of text fields with companion
3450 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
3451 foreach ($_POST["$prefix$field_id"] as $key => $val) {
3452 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
3453 $val = str_replace('|', ' ', $val);
3454 if (strlen($value)) {
3455 $value .= '|';
3458 $value .= "$key:$restype:$val";
3460 } else if ($data_type == 28 || $data_type == 32) {
3461 // $_POST["$prefix$field_id"] is an date text fields with companion
3462 // radio buttons to be imploded into "notes|type|date".
3463 $restype = $_POST["radio_{$field_id}"];
3464 if (empty($restype)) {
3465 $restype = '0';
3468 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
3469 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3470 if ($data_type == 32) {
3471 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
3472 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
3473 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
3474 $value = "$res_text_note|$restype|$resdate|$reslist";
3475 } else {
3476 $value = "$resnote|$restype|$resdate";
3478 } else if ($data_type == 36) {
3479 $value_array = $_POST["form_$field_id"];
3480 $i = 0;
3481 foreach ($value_array as $key => $valueofkey) {
3482 if ($i == 0) {
3483 $value = $valueofkey;
3484 } else {
3485 $value = $value . "|" . $valueofkey;
3488 $i++;
3490 } else {
3491 $value = $_POST["$prefix$field_id"];
3495 // Better to die than to silently truncate data!
3496 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength) {
3497 die(htmlspecialchars(xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
3498 ":<br />&nbsp;<br />".htmlspecialchars($value, ENT_NOQUOTES));
3501 return trim($value);
3504 // Generate JavaScript validation logic for the required fields.
3506 function generate_layout_validation($form_id)
3508 $fres = sqlStatement("SELECT * FROM layout_options " .
3509 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
3510 "ORDER BY group_id, seq", array($form_id));
3512 while ($frow = sqlFetchArray($fres)) {
3513 $data_type = $frow['data_type'];
3514 $field_id = $frow['field_id'];
3515 $fldtitle = $frow['title'];
3516 if (!$fldtitle) {
3517 $fldtitle = $frow['description'];
3520 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES);
3522 if ($data_type == 40) {
3523 $fldid = addslashes("form_$field_id");
3524 // Move canvas image data to its hidden form field so the server will get it.
3525 echo
3526 " var canfld = f['$fldid'];\n" .
3527 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
3528 continue;
3531 if ($frow['uor'] < 2) {
3532 continue;
3535 echo " if (f.$fldname && !f.$fldname.disabled) {\n";
3536 switch ($data_type) {
3537 case 1:
3538 case 11:
3539 case 12:
3540 case 13:
3541 case 14:
3542 case 26:
3543 echo
3544 " if (f.$fldname.selectedIndex <= 0) {\n" .
3545 " alert(\"" . addslashes(xl('Please choose a value for')) .
3546 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3547 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3548 " return false;\n" .
3549 " }\n";
3550 break;
3551 case 33:
3552 echo
3553 " if (f.$fldname.selectedIndex <= 0) {\n" .
3554 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3555 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3556 " }\n";
3557 break;
3558 case 27: // radio buttons
3559 echo
3560 " var i = 0;\n" .
3561 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
3562 " if (i >= f.$fldname.length) {\n" .
3563 " alert(\"" . addslashes(xl('Please choose a value for')) .
3564 ":\\n" . addslashes(xl_layout_label($fldtitle)) . "\");\n" .
3565 " return false;\n" .
3566 " }\n";
3567 break;
3568 case 2:
3569 case 3:
3570 case 4:
3571 case 15:
3572 echo
3573 " if (trimlen(f.$fldname.value) == 0) {\n" .
3574 " if (f.$fldname.focus) f.$fldname.focus();\n" .
3575 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
3576 " $('#" . $fldname . "').attr('style','background:red'); \n" .
3577 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3578 " } else { " .
3579 " $('#" . $fldname . "').attr('style',''); " .
3580 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
3581 " } \n";
3582 break;
3583 case 36: // multi select
3584 echo
3585 " var multi_select=f['$fldname"."[]']; \n " .
3586 " var multi_choice_made=false; \n".
3587 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
3588 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
3589 " } \n" .
3590 " if(!multi_choice_made)
3591 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
3593 break;
3595 echo " }\n";
3600 * DROPDOWN FOR FACILITIES
3602 * build a dropdown with all facilities
3604 * @param string $selected - name of the currently selected facility
3605 * use '0' for "unspecified facility"
3606 * use '' for "All facilities" (the default)
3607 * @param string $name - the name/id for select form (defaults to "form_facility")
3608 * @param boolean $allow_unspecified - include an option for "unspecified" facility
3609 * defaults to true
3610 * @return void - just echo the html encoded string
3612 * Note: This should become a data-type at some point, according to Brady
3614 function dropdown_facility(
3615 $selected = '',
3616 $name = 'form_facility',
3617 $allow_unspecified = true,
3618 $allow_allfacilities = true,
3619 $disabled = '',
3620 $onchange = ''
3623 global $facilityService;
3625 $have_selected = false;
3626 $fres = $facilityService->getAll();
3628 $name = htmlspecialchars($name, ENT_QUOTES);
3629 echo " <select class='form-control' name='$name' id='$name'";
3630 if ($onchange) {
3631 echo " onchange='$onchange'";
3634 echo " $disabled>\n";
3636 if ($allow_allfacilities) {
3637 $option_value = '';
3638 $option_selected_attr = '';
3639 if ($selected == '') {
3640 $option_selected_attr = ' selected="selected"';
3641 $have_selected = true;
3644 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
3645 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3646 } elseif ($allow_unspecified) {
3647 $option_value = '0';
3648 $option_selected_attr = '';
3649 if ($selected == '0') {
3650 $option_selected_attr = ' selected="selected"';
3651 $have_selected = true;
3654 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
3655 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3658 foreach ($fres as $frow) {
3659 $facility_id = $frow['id'];
3660 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
3661 $option_selected_attr = '';
3662 if ($selected == $facility_id) {
3663 $option_selected_attr = ' selected="selected"';
3664 $have_selected = true;
3667 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
3668 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3671 if ($allow_unspecified && $allow_allfacilities) {
3672 $option_value = '0';
3673 $option_selected_attr = '';
3674 if ($selected == '0') {
3675 $option_selected_attr = ' selected="selected"';
3676 $have_selected = true;
3679 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
3680 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
3683 if (!$have_selected) {
3684 $option_value = htmlspecialchars($selected, ENT_QUOTES);
3685 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
3686 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
3687 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
3690 echo " </select>\n";
3693 // Expand Collapse Widget
3694 // This forms the header and functionality component of the widget. The information that is displayed
3695 // then follows this function followed by a closing div tag
3697 // $title is the title of the section (already translated)
3698 // $label is identifier used in the tag id's and sql columns
3699 // $buttonLabel is the button label text (already translated)
3700 // $buttonLink is the button link information
3701 // $buttonClass is any additional needed class elements for the button tag
3702 // $linkMethod is the button link method ('javascript' vs 'html')
3703 // $bodyClass is to set class(es) of the body
3704 // $auth is a flag to decide whether to show the button
3705 // $fixedWidth is to flag whether width is fixed
3706 // $forceExpandAlways is a flag to force the widget to always be expanded
3708 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways = false)
3710 if ($fixedWidth) {
3711 echo "<div class='section-header'>";
3712 } else {
3713 echo "<div class='section-header-dynamic'>";
3716 echo "<table><tr>";
3717 if ($auth) {
3718 // show button, since authorized
3719 // first prepare class string
3720 if ($buttonClass) {
3721 $class_string = "css_button_small ".htmlspecialchars($buttonClass, ENT_NOQUOTES);
3722 } else {
3723 $class_string = "css_button_small";
3726 // next, create the link
3727 if ($linkMethod == "javascript") {
3728 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3729 } else {
3730 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3731 if (!isset($_SESSION['patient_portal_onsite']) && !isset($_SESSION['patient_portal_onsite_two'])) {
3732 // prevent an error from occuring when calling the function from the patient portal
3733 echo " onclick='top.restoreSession()'";
3737 echo "><span>" .
3738 htmlspecialchars($buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
3741 if ($forceExpandAlways) {
3742 // Special case to force the widget to always be expanded
3743 echo "<td><span class='text'><b>" . htmlspecialchars($title, ENT_NOQUOTES) . "</b></span>";
3744 $indicatorTag ="style='display:none'";
3747 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3748 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3749 htmlspecialchars($label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
3750 echo htmlspecialchars($title, ENT_NOQUOTES) . "</b></span>";
3752 if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3753 // collapse all entries in the patient portal
3754 $text = xl('expand');
3755 } else if (getUserSetting($label."_ps_expand")) {
3756 $text = xl('collapse');
3757 } else {
3758 $text = xl('expand');
3761 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
3762 "</span>)</a></td>";
3763 echo "</tr></table>";
3764 echo "</div>";
3765 if ($forceExpandAlways) {
3766 // Special case to force the widget to always be expanded
3767 $styling = "";
3768 } else if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3769 // collapse all entries in the patient portal
3770 $styling = "style='display:none'";
3771 } else if (getUserSetting($label."_ps_expand")) {
3772 $styling = "";
3773 } else {
3774 $styling = "style='display:none'";
3777 if ($bodyClass) {
3778 $styling .= " class='" . $bodyClass . "'";
3781 //next, create the first div tag to hold the information
3782 // note the code that calls this function will then place the ending div tag after the data
3783 echo "<div id='" . htmlspecialchars($label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
3786 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3787 function billing_facility($name, $select)
3789 global $facilityService;
3791 $fres = $facilityService->getAllBillingLocations();
3792 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' class='form-control' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3793 foreach ($fres as $facrow) {
3794 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3795 echo "<option value=".htmlspecialchars($facrow['id'], ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3798 echo "</select>";
3801 // Generic function to get the translated title value for a particular list option.
3803 function getListItemTitle($list, $option)
3805 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3806 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3807 if (empty($row['title'])) {
3808 return $option;
3811 return xl_list_label($row['title']);
3813 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3814 function getSmokeCodes()
3816 $smoking_codes_arr = array();
3817 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3818 while ($codes_row = sqlFetchArray($smoking_codes)) {
3819 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3822 return $smoking_codes_arr;
3825 // Get the current value for a layout based form field.
3826 // Depending on options this might come from lbf_data, patient_data,
3827 // form_encounter, shared_attributes or elsewhere.
3828 // Returns FALSE if the field ID is invalid (layout error).
3830 function lbf_current_value($frow, $formid, $encounter)
3832 global $pid;
3833 $formname = $frow['form_id'];
3834 $field_id = $frow['field_id'];
3835 $source = $frow['source'];
3836 $currvalue = '';
3837 $deffname = $formname . '_default_' . $field_id;
3838 if ($source == 'D' || $source == 'H') {
3839 // Get from patient_data, employer_data or history_data.
3840 if ($source == 'H') {
3841 $table = 'history_data';
3842 $orderby = 'ORDER BY date DESC LIMIT 1';
3843 } else if (strpos($field_id, 'em_') === 0) {
3844 $field_id = substr($field_id, 3);
3845 $table = 'employer_data';
3846 $orderby = 'ORDER BY date DESC LIMIT 1';
3847 } else {
3848 $table = 'patient_data';
3849 $orderby = '';
3852 // It is an error if the field does not exist, but don't crash.
3853 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3854 if (empty($tmp)) {
3855 return '*?*';
3858 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3859 if (isset($pdrow)) {
3860 $currvalue = $pdrow['field_value'];
3862 } else if ($source == 'E') {
3863 $sarow = false;
3864 if ($encounter) {
3865 // Get value from shared_attributes of the current encounter.
3866 $sarow = sqlQuery(
3867 "SELECT field_value FROM shared_attributes WHERE " .
3868 "pid = ? AND encounter = ? AND field_id = ?",
3869 array($pid, $encounter, $field_id)
3871 if (!empty($sarow)) {
3872 $currvalue = $sarow['field_value'];
3874 } else if ($formid) {
3875 // Get from shared_attributes of the encounter that this form is linked to.
3876 // Note the importance of having an index on forms.form_id.
3877 $sarow = sqlQuery(
3878 "SELECT sa.field_value " .
3879 "FROM forms AS f, shared_attributes AS sa WHERE " .
3880 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3881 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3882 array($formid, $formname, $field_id)
3884 if (!empty($sarow)) {
3885 $currvalue = $sarow['field_value'];
3887 } else {
3888 // New form and encounter not available, this should not happen.
3890 if (empty($sarow) && !$formid) {
3891 // New form, see if there is a custom default from a plugin.
3892 if (function_exists($deffname)) {
3893 $currvalue = call_user_func($deffname);
3896 } else if ($source == 'V') {
3897 if ($encounter) {
3898 // Get value from the current encounter's form_encounter.
3899 $ferow = sqlQuery(
3900 "SELECT * FROM form_encounter WHERE " .
3901 "pid = ? AND encounter = ?",
3902 array($pid, $encounter)
3904 if (isset($ferow[$field_id])) {
3905 $currvalue = $ferow[$field_id];
3907 } else if ($formid) {
3908 // Get value from the form_encounter that this form is linked to.
3909 $ferow = sqlQuery(
3910 "SELECT fe.* " .
3911 "FROM forms AS f, form_encounter AS fe WHERE " .
3912 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3913 "fe.pid = f.pid AND fe.encounter = f.encounter",
3914 array($formid, $formname)
3916 if (isset($ferow[$field_id])) {
3917 $currvalue = $ferow[$field_id];
3919 } else {
3920 // New form and encounter not available, this should not happen.
3922 } else if ($formid) {
3923 // This is a normal form field.
3924 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3925 "form_id = ? AND field_id = ?", array($formid, $field_id));
3926 if (!empty($ldrow)) {
3927 $currvalue = $ldrow['field_value'];
3929 } else {
3930 // New form, see if there is a custom default from a plugin.
3931 if (function_exists($deffname)) {
3932 $currvalue = call_user_func($deffname);
3936 return $currvalue;
3939 // This returns stuff that needs to go into the <head> section of a caller using
3940 // the drawable image field type in a form.
3941 // A TRUE argument makes the widget controls smaller.
3943 function lbf_canvas_head($small = true)
3945 $s = <<<EOD
3946 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3947 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3948 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3949 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3950 EOD;
3951 if ($small) {
3952 $s .= <<<EOD
3953 <style>
3954 /* Custom LiterallyCanvas styling.
3955 * This makes the widget 25% less tall and adjusts some other things accordingly.
3957 .literally {
3958 min-height:100%;min-width:300px; /* Was 400, unspecified */
3960 .literally .lc-picker .toolbar-button {
3961 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3963 .literally .color-well {
3964 font-size:8px;width:49px; /* Was 10, 60 */
3966 .literally .color-well-color-container {
3967 width:21px;height:21px; /* Was 28, 28 */
3969 .literally .lc-picker {
3970 width:50px; /* Was 61 */
3972 .literally .lc-drawing.with-gui {
3973 left:50px; /* Was 61 */
3975 .literally .lc-options {
3976 left:50px; /* Was 61 */
3978 .literally .color-picker-popup {
3979 left:49px;bottom:0px; /* Was 60, 31 */
3981 </style>
3982 EOD;
3985 return $s;
3989 * Test if modifier($test) is in array of options for data type.
3991 * @param json array $options or could be string of form "ABCU"
3992 * @param string $test
3993 * @return boolean
3995 function isOption($options, $test)
3997 if (empty($options) || !isset($test)) {
3998 return false; // why bother?
4000 if (strpos($options, ',') === false) { // could be string of char's or single element of json
4001 json_decode($options);
4002 if (is_string($options) && ! (json_last_error() === JSON_ERROR_NONE)) { // nope, it's string.
4003 $t = str_split(trim($options)); // very good chance it's legacy modifier string.
4004 $options = json_encode($t); // make it array.
4007 $options = json_decode($options);
4009 return !is_null($options) && in_array($test, $options, true) ? true : false; // finally!