Merge pull request #852 from bradymiller/dygraphs_2
[openemr.git] / library / options.inc.php
blob0b5bd6a34a883a42e97b1bc2449ba8f2e8cedd70
1 <?php
2 // Copyright (C) 2007-2016 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 $facilityService = new \services\FacilityService();
46 $date_init = "";
48 function get_pharmacies() {
49 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
50 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
51 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
52 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
53 "AND p.type = 2 " .
54 "ORDER BY name, area_code, prefix, number");
57 function optionalAge($frow, $date, &$asof) {
58 $asof = '';
59 if (empty($date)) return '';
60 $date = substr($date, 0, 10);
61 if (strpos($frow['edit_options'], 'A') !== FALSE) {
62 $format = 0;
64 else if (strpos($frow['edit_options'], 'B') !== FALSE) {
65 $format = 3;
67 else {
68 return '';
70 if (strpos($frow['form_id'], 'LBF') === 0) {
71 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
72 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
73 array($GLOBALS['pid'], $GLOBALS['encounter']));
74 if (!empty($tmp['date'])) $asof = substr($tmp['date'], 0, 10);
76 $prefix = ($format ? xl('Gest age') : xl('Age')) . ' ';
77 return $prefix . oeFormatAge($date, $asof, $format);
80 // Function to generate a drop-list.
82 function generate_select_list($tag_name, $list_id, $currvalue, $title, $empty_name = ' ', $class = '',
83 $onchange = '', $tag_id = '', $custom_attributes = null, $multiple = false, $backup_list = '') {
84 $s = '';
86 $tag_name_esc = attr($tag_name);
88 if ($multiple) {
89 $tag_name_esc = $tag_name_esc . "[]";
92 $s .= "<select name='$tag_name_esc'";
94 if ($multiple) {
95 $s .= " multiple='multiple'";
98 $tag_id_esc = attr( $tag_name );
100 if ($tag_id != '') {
101 $tag_id_esc = attr($tag_id);
104 $s .= " id='$tag_id_esc'";
106 if (!empty($class)) {
107 $class_esc = attr($class);
108 $s .= " class='form-control $class_esc'";
110 else {
111 $s .= " class='form-control'";
114 if ($onchange) {
115 $s .= " onchange='$onchange'";
117 if ($custom_attributes != null && is_array ( $custom_attributes )) {
118 foreach ( $custom_attributes as $attr => $val ) {
119 if (isset ( $custom_attributes [$attr] )) {
120 $s .= " " . attr($attr) . "='" . attr($val) . "'";
124 $selectTitle = attr($title);
125 $s .= " title='$selectTitle'>";
126 $selectEmptyName = xlt($empty_name);
127 if ($empty_name)
128 $s .= "<option value=''>" . $selectEmptyName . "</option>";
130 // List order depends on language translation options.
131 // (Note we do not need to worry about the list order in the algorithm
132 // after the below code block since that is where searches for exceptions
133 // are done which include inactive items or items from a backup
134 // list; note these will always be shown at the bottom of the list no matter the
135 // chosen order.)
136 $lang_id = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
137 // sort by title
138 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) || !$GLOBALS['translate_lists']) {
139 // do not translate
140 if ($GLOBALS['gb_how_sort_list'] == '0') {
141 // order by seq
142 $order_by_sql = "seq, title";
144 else { //$GLOBALS['gb_how_sort_list'] == '1'
145 // order by title
146 $order_by_sql = "title, seq";
148 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
150 else {
151 // do translate
152 if ($GLOBALS['gb_how_sort_list'] == '0') {
153 // order by seq
154 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
156 else { //$GLOBALS['gb_how_sort_list'] == '1'
157 // order by title
158 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
160 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
161 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
162 "FROM list_options AS lo " .
163 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
164 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
165 "ld.lang_id = ? " .
166 "WHERE lo.list_id = ? AND lo.activity=1 " .
167 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
169 $got_selected = FALSE;
171 while ( $lrow = sqlFetchArray ( $lres ) ) {
172 $selectedValues = explode ( "|", $currvalue );
174 $optionValue = attr($lrow ['option_id']);
175 $s .= "<option value='$optionValue'";
177 if ((strlen ( $currvalue ) == 0 && $lrow ['is_default']) || (strlen ( $currvalue ) > 0 && in_array ( $lrow ['option_id'], $selectedValues ))) {
178 $s .= " selected";
179 $got_selected = TRUE;
182 // Already has been translated above (if applicable), so do not need to use
183 // the xl_list_label() function here
184 $optionLabel = text($lrow ['title']);
185 $s .= ">$optionLabel</option>\n";
189 To show the inactive item in the list if the value is saved to database
191 if (!$got_selected && strlen($currvalue) > 0)
193 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
194 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
195 $lrow_inactive = sqlFetchArray($lres_inactive);
196 if($lrow_inactive['option_id']) {
197 $optionValue = htmlspecialchars( $lrow_inactive['option_id'], ENT_QUOTES);
198 $s .= "<option value='$optionValue' selected>" . htmlspecialchars( xl_list_label($lrow_inactive['title']), ENT_NOQUOTES) . "</option>\n";
199 $got_selected = TRUE;
203 if (!$got_selected && strlen ( $currvalue ) > 0 && !$multiple) {
204 $list_id = $backup_list;
205 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
207 if ($lrow > 0 && !empty($backup_list)) {
208 $selected = text(xl_list_label($lrow ['title']));
209 $s .= "<option value='$currescaped' selected> $selected </option>";
210 $s .= "</select>";
211 } else {
212 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
213 $s .= "</select>";
214 $fontTitle = xlt('Please choose a valid selection from the list.');
215 $fontText = xlt( 'Fix this' );
216 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
219 } else if (!$got_selected && strlen ( $currvalue ) > 0 && $multiple) {
220 //if not found in main list, display all selected values that exist in backup list
221 $list_id = $backup_list;
223 $got_selected_backup = FALSE;
224 if (!empty($backup_list)) {
225 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
226 while ( $lrow_backup = sqlFetchArray ( $lres_backup ) ) {
227 $selectedValues = explode ( "|", $currvalue );
229 $optionValue = attr($lrow_backup['option_id']);
231 if ( in_array($lrow_backup ['option_id'],$selectedValues)) {
232 $s .= "<option value='$optionValue'";
233 $s .= " selected";
234 $optionLabel = text(xl_list_label($lrow_backup ['title']));
235 $s .= ">$optionLabel</option>\n";
236 $got_selected_backup = TRUE;
240 if (!$got_selected_backup) {
241 $selectedValues = explode ( "|", $currvalue );
242 foreach ( $selectedValues as $selectedValue ) {
243 $s .= "<option value='" . attr($selectedValue) . "'";
244 $s .= " selected";
245 $s .= ">* " . text($selectedValue) . " *</option>\n";
247 $s .= "</select>";
248 $fontTitle = xlt('Please choose a valid selection from the list.');
249 $fontText = xlt( 'Fix this' );
250 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
254 else {
255 $s .= "</select>";
257 return $s;
261 // $frow is a row from the layout_options table.
262 // $currvalue is the current value, if any, of the associated item.
264 function generate_form_field($frow, $currvalue) {
265 global $rootdir, $date_init, $ISSUE_TYPES, $code_types,$condition_str;
267 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
269 $data_type = $frow['data_type'];
270 $field_id = $frow['field_id'];
271 $list_id = $frow['list_id'];
272 $backup_list = $frow['list_backup_id'];
273 $condition_str = get_conditions_str($condition_str,$frow);
275 // escaped variables to use in html
276 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
277 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
279 // Added 5-09 by BM - Translate description if applicable
280 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
282 // Support edit option T which assigns the (possibly very long) description as
283 // the default value.
284 if (strpos($frow['edit_options'], 'T') !== FALSE) {
285 if (strlen($currescaped) == 0) $currescaped = $description;
286 // Description used in this way is not suitable as a title.
287 $description = '';
290 // added 5-2009 by BM to allow modification of the 'empty' text title field.
291 // Can pass $frow['empty_title'] with this variable, otherwise
292 // will default to 'Unassigned'.
293 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
294 // if make $frow['empty_title'] equal to 'SKIP'
295 $showEmpty = true;
296 if (isset($frow['empty_title'])) {
297 if ($frow['empty_title'] == "SKIP") {
298 //do not display an 'empty' choice
299 $showEmpty = false;
300 $empty_title = "Unassigned";
302 else {
303 $empty_title = $frow['empty_title'];
306 else {
307 $empty_title = "Unassigned";
310 $disabled = strpos($frow['edit_options'], '0') === FALSE ? '' : 'disabled';
312 $lbfchange = (strpos($frow['form_id'], 'LBF') === 0 || strpos($frow['form_id'], 'LBT') === 0) ?
313 "checkSkipConditions();" : "";
314 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
316 // generic single-selection list or Race and Ethnicity.
317 // These data types support backup lists.
318 if ($data_type == 1 || $data_type == 33) {
319 echo generate_select_list("form_$field_id", $list_id, $currvalue,
320 $description, ($showEmpty ? $empty_title : ''), '', $lbfchange, '',
321 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
324 // simple text field
325 else if ($data_type == 2) {
326 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
327 $maxlength = $frow['max_length'];
328 $string_maxlength = "";
329 // if max_length is set to zero, then do not set a maxlength
330 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
331 echo "<input type='text'" .
332 " class='form-control'" .
333 " name='form_$field_id_esc'" .
334 " id='form_$field_id_esc'" .
335 " size='$fldlength'" .
336 " $string_maxlength" .
337 " title='$description'" .
338 " value='$currescaped'";
339 $tmp = $lbfchange;
340 if (strpos($frow['edit_options'], 'C') !== FALSE)
341 $tmp .= "capitalizeMe(this);";
342 else if (strpos($frow['edit_options'], 'U') !== FALSE)
343 $tmp .= "this.value = this.value.toUpperCase();";
344 if ($tmp) echo " onchange='$tmp'";
345 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
346 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
347 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
348 echo " onblur='maskblur(this,\"$tmp\")'";
350 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
351 echo " readonly";
353 if ($disabled) echo ' disabled';
354 echo " />";
357 // long or multi-line text field
358 else if ($data_type == 3) {
359 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
360 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
361 echo "<textarea" .
362 " name='form_$field_id_esc'" .
363 " class='form-control'" .
364 " id='form_$field_id_esc'" .
365 " title='$description'" .
366 " cols='$textCols'" .
367 " rows='$textRows' $lbfonchange $disabled" .
368 ">" . $currescaped . "</textarea>";
371 // date
372 else if ($data_type == 4) {
373 $age_asof_date = ''; // optionalAge() sets this
374 $age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0;
375 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
376 if ($agestr) {
377 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
380 $onchange_string = '';
381 if (!$disabled && $agestr) {
382 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format)\"";
385 echo "<input type='text' size='10' class='datepicker form-control' name='form_$field_id_esc' id='form_$field_id_esc'" .
386 " value='" . substr($currescaped, 0, 10) . "'";
387 if (!$agestr) echo " title='$description'";
388 echo " $onchange_string $lbfonchange $disabled />";
390 // Optional display of age or gestational age.
391 if ($agestr) {
392 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
396 // provider list, local providers only
397 else if ($data_type == 10) {
398 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
399 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
400 "AND authorized = 1 " .
401 "ORDER BY lname, fname");
402 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
403 echo "<option value=''>" . xlt($empty_title) . "</option>";
404 $got_selected = false;
405 while ($urow = sqlFetchArray($ures)) {
406 $uname = text($urow['fname'] . ' ' . $urow['lname']);
407 $optionId = attr($urow['id']);
408 echo "<option value='$optionId'";
409 if ($urow['id'] == $currvalue) {
410 echo " selected";
411 $got_selected = true;
413 echo ">$uname</option>";
415 if (!$got_selected && $currvalue) {
416 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
417 echo "</select>";
418 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
420 else {
421 echo "</select>";
425 // provider list, including address book entries with an NPI number
426 else if ($data_type == 11) {
427 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
428 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
429 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
430 "ORDER BY lname, fname");
431 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
432 echo " $lbfonchange $disabled>";
433 echo "<option value=''>" . xlt('Unassigned') . "</option>";
434 $got_selected = false;
435 while ($urow = sqlFetchArray($ures)) {
436 $uname = text($urow['fname'] . ' ' . $urow['lname']);
437 $optionId = attr($urow['id']);
438 echo "<option value='$optionId'";
439 if ($urow['id'] == $currvalue) {
440 echo " selected";
441 $got_selected = true;
443 echo ">$uname</option>";
445 if (!$got_selected && $currvalue) {
446 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
447 echo "</select>";
448 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
450 else {
451 echo "</select>";
455 // pharmacy list
456 else if ($data_type == 12) {
457 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
458 echo " $lbfonchange $disabled>";
459 echo "<option value='0'></option>";
460 $pres = get_pharmacies();
461 $got_selected = false;
462 while ($prow = sqlFetchArray($pres)) {
463 $key = $prow['id'];
464 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
465 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
466 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
467 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
468 echo "<option value='$optionValue'";
469 if ($currvalue == $key) {
470 echo " selected";
471 $got_selected = true;
473 echo ">$optionLabel</option>";
475 if (!$got_selected && $currvalue) {
476 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
477 echo "</select>";
478 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
480 else {
481 echo "</select>";
485 // squads
486 else if ($data_type == 13) {
487 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
488 echo " $lbfonchange $disabled>";
489 echo "<option value=''>&nbsp;</option>";
490 $squads = acl_get_squads();
491 if ($squads) {
492 foreach ($squads as $key => $value) {
493 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
494 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
495 echo "<option value='$optionValue'";
496 if ($currvalue == $key) echo " selected";
497 echo ">$optionLabel</option>\n";
500 echo "</select>";
503 // Address book, preferring organization name if it exists and is not in
504 // parentheses, and excluding local users who are not providers.
505 // Supports "referred to" practitioners and facilities.
506 // Alternatively the letter L in edit_options means that abook_type
507 // must be "ord_lab", indicating types used with the procedure
508 // lab ordering system.
509 // Alternatively the letter O in edit_options means that abook_type
510 // must begin with "ord_", indicating types used with the procedure
511 // ordering system.
512 // Alternatively the letter V in edit_options means that abook_type
513 // must be "vendor", indicating the Vendor type.
514 // Alternatively the letter R in edit_options means that abook_type
515 // must be "dist", indicating the Distributor type.
516 else if ($data_type == 14) {
517 if (strpos($frow['edit_options'], 'L') !== FALSE)
518 $tmp = "abook_type = 'ord_lab'";
519 else if (strpos($frow['edit_options'], 'O') !== FALSE)
520 $tmp = "abook_type LIKE 'ord\\_%'";
521 else if (strpos($frow['edit_options'], 'V') !== FALSE)
522 $tmp = "abook_type LIKE 'vendor%'";
523 else if (strpos($frow['edit_options'], 'R') !== FALSE)
524 $tmp = "abook_type LIKE 'dist'";
525 else
526 $tmp = "( username = '' OR authorized = 1 )";
527 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
528 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
529 "AND $tmp " .
530 "ORDER BY organization, lname, fname");
531 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' class='form-control'";
532 echo " $lbfonchange $disabled>";
533 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
534 while ($urow = sqlFetchArray($ures)) {
535 $uname = $urow['organization'];
536 if (empty($uname) || substr($uname, 0, 1) == '(') {
537 $uname = $urow['lname'];
538 if ($urow['fname']) $uname .= ", " . $urow['fname'];
540 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
541 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
542 echo "<option value='$optionValue'";
543 $title = $urow['username'] ? xl('Local') : xl('External');
544 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
545 echo " title='$optionTitle'";
546 if ($urow['id'] == $currvalue) echo " selected";
547 echo ">$optionLabel</option>";
549 echo "</select>";
552 // A billing code. If description matches an existing code type then that type is used.
553 else if ($data_type == 15) {
554 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
555 $maxlength = $frow['max_length'];
556 $string_maxlength = "";
557 // if max_length is set to zero, then do not set a maxlength
558 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
560 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
561 // Option "2" generates a hidden input for the codes, and a matching visible field
562 // displaying their descriptions. First step is computing the description string.
563 $currdescstring = '';
564 if (!empty($currvalue)) {
565 $relcodes = explode(';', $currvalue);
566 foreach ($relcodes as $codestring) {
567 if ($codestring === '') continue;
568 $code_text = lookup_code_descriptions($codestring);
569 if ($currdescstring !== '') $currdescstring .= '; ';
570 if (!empty($code_text)) {
571 $currdescstring .= $code_text;
573 else {
574 $currdescstring .= $codestring;
578 $currdescstring = attr($currdescstring);
580 echo "<input type='text'" .
581 " name='form_$field_id_esc'" .
582 " id='form_related_code'" .
583 " size='$fldlength'" .
584 " value='$currescaped'" .
585 " style='display:none'" .
586 " $lbfonchange readonly $disabled />";
587 // Extra readonly input field for optional display of code description(s).
588 echo "<input type='text'" .
589 " name='form_$field_id_esc" . "__desc'" .
590 " size='$fldlength'" .
591 " title='$description'" .
592 " value='$currdescstring'";
593 if (!$disabled) {
594 echo " onclick='sel_related(this,\"$codetype\")'";
596 echo "class='form-control'";
597 echo " readonly $disabled />";
599 else {
600 echo "<input type='text'" .
601 " name='form_$field_id_esc'" .
602 " id='form_related_code'" .
603 " size='$fldlength'" .
604 " $string_maxlength" .
605 " title='$description'" .
606 " value='$currescaped'";
607 if (!$disabled) {
608 echo " onclick='sel_related(this,\"$codetype\")'";
610 echo "class='form-control'";
611 echo " $lbfonchange readonly $disabled />";
615 // insurance company list
616 else if ($data_type == 16) {
617 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
618 echo "<option value='0'></option>";
619 $insprovs = getInsuranceProviders();
620 $got_selected = false;
621 foreach ($insprovs as $key => $ipname) {
622 $optionValue = htmlspecialchars($key, ENT_QUOTES);
623 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
624 echo "<option value='$optionValue'";
625 if ($currvalue == $key) {
626 echo " selected";
627 $got_selected = true;
629 echo ">$optionLabel</option>";
631 if (!$got_selected && $currvalue) {
632 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
633 echo "</select>";
634 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
636 else {
637 echo "</select>";
641 // issue types
642 else if ($data_type == 17) {
643 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'>";
644 echo "<option value='0'></option>";
645 $got_selected = false;
646 foreach ($ISSUE_TYPES as $key => $value) {
647 $optionValue = htmlspecialchars($key, ENT_QUOTES);
648 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
649 echo "<option value='$optionValue'";
650 if ($currvalue == $key) {
651 echo " selected";
652 $got_selected = true;
654 echo ">$optionLabel</option>";
656 if (!$got_selected && strlen($currvalue) > 0) {
657 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
658 echo "</select>";
659 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
661 else {
662 echo "</select>";
666 // Visit categories.
667 else if ($data_type == 18) {
668 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
669 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
670 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' class='form-control' title='$description'" .
671 " $lbfonchange $disabled>";
672 echo "<option value=''>" . xlt($empty_title) . "</option>";
673 $got_selected = false;
674 while ($crow = sqlFetchArray($cres)) {
675 $catid = $crow['pc_catid'];
676 if (($catid < 9 && $catid != 5) || $catid == 11) continue;
677 echo "<option value='" . attr($catid) . "'";
678 if ($catid == $currvalue) {
679 echo " selected";
680 $got_selected = true;
682 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
684 if (!$got_selected && $currvalue) {
685 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
686 echo "</select>";
687 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
689 else {
690 echo "</select>";
694 // a set of labeled checkboxes
695 else if ($data_type == 21) {
696 // In this special case, fld_length is the number of columns generated.
697 $cols = max(1, $frow['fld_length']);
698 $avalue = explode('|', $currvalue);
699 $lres = sqlStatement("SELECT * FROM list_options " .
700 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
701 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
702 $tdpct = (int) (100 / $cols);
703 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
704 $option_id = $lrow['option_id'];
705 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
706 // if ($count) echo "<br />";
707 if ($count % $cols == 0) {
708 if ($count) echo "</tr>";
709 echo "<tr>";
711 echo "<td width='$tdpct%'>";
712 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
713 "id='form_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
714 if (in_array($option_id, $avalue)) echo " checked";
716 // Added 5-09 by BM - Translate label if applicable
717 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
719 echo "</td>";
721 if ($count) {
722 echo "</tr>";
723 if ($count > $cols) {
724 // Add some space after multiple rows of checkboxes.
725 $cols = htmlspecialchars( $cols, ENT_QUOTES);
726 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
729 echo "</table>";
732 // a set of labeled text input fields
733 else if ($data_type == 22) {
734 $tmp = explode('|', $currvalue);
735 $avalue = array();
736 foreach ($tmp as $value) {
737 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
738 $avalue[$matches[1]] = $matches[2];
741 $lres = sqlStatement("SELECT * FROM list_options " .
742 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
743 echo "<table cellpadding='0' cellspacing='0'>";
744 while ($lrow = sqlFetchArray($lres)) {
745 $option_id = $lrow['option_id'];
746 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
747 $maxlength = $frow['max_length'];
748 $string_maxlength = "";
749 // if max_length is set to zero, then do not set a maxlength
750 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
751 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
753 // Added 5-09 by BM - Translate label if applicable
754 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
755 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
756 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
757 echo "<td><input type='text'" .
758 " name='form_{$field_id_esc}[$option_id_esc]'" .
759 " id='form_{$field_id_esc}[$option_id_esc]'" .
760 " size='$fldlength'" .
761 " class='form-control'" .
762 " $string_maxlength" .
763 " value='$optionValue'";
764 echo " $lbfonchange $disabled /></td></tr>";
766 echo "</table>";
769 // a set of exam results; 3 radio buttons and a text field:
770 else if ($data_type == 23) {
771 $tmp = explode('|', $currvalue);
772 $avalue = array();
773 foreach ($tmp as $value) {
774 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
775 $avalue[$matches[1]] = $matches[2];
778 $maxlength = $frow['max_length'];
779 $string_maxlength = "";
780 // if max_length is set to zero, then do not set a maxlength
781 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
782 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
783 $lres = sqlStatement("SELECT * FROM list_options " .
784 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
785 echo "<table cellpadding='0' cellspacing='0'>";
786 echo "<tr><td>&nbsp;</td><td class='bold'>" .
787 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
788 "&nbsp;</td><td class='bold'>" .
789 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
790 "<td class='bold'>" .
791 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
792 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
793 while ($lrow = sqlFetchArray($lres)) {
794 $option_id = $lrow['option_id'];
795 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
796 $restype = substr($avalue[$option_id], 0, 1);
797 $resnote = substr($avalue[$option_id], 2);
799 // Added 5-09 by BM - Translate label if applicable
800 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
802 for ($i = 0; $i < 3; ++$i) {
803 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
804 echo "<td><input type='radio'" .
805 " name='radio_{$field_id_esc}[$option_id_esc]'" .
806 " id='radio_{$field_id_esc}[$option_id_esc]'" .
807 " value='$inputValue' $lbfonchange";
808 if ($restype === "$i") echo " checked";
809 echo " $disabled /></td>";
811 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
812 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
813 echo "<td><input type='text'" .
814 " name='form_{$field_id_esc}[$option_id_esc]'" .
815 " id='form_{$field_id_esc}[$option_id_esc]'" .
816 " size='$fldlength'" .
817 " $string_maxlength" .
818 " value='$resnote' $disabled /></td>";
819 echo "</tr>";
821 echo "</table>";
824 // the list of active allergies for the current patient
825 // this is read-only!
826 else if ($data_type == 24) {
827 $query = "SELECT title, comments FROM lists WHERE " .
828 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
829 "ORDER BY begdate";
830 // echo "<!-- $query -->\n"; // debugging
831 $lres = sqlStatement($query, array($GLOBALS['pid']));
832 $count = 0;
833 while ($lrow = sqlFetchArray($lres)) {
834 if ($count++) echo "<br />";
835 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
836 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
840 // a set of labeled checkboxes, each with a text field:
841 else if ($data_type == 25) {
842 $tmp = explode('|', $currvalue);
843 $avalue = array();
844 foreach ($tmp as $value) {
845 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
846 $avalue[$matches[1]] = $matches[2];
849 $maxlength = $frow['max_length'];
850 $string_maxlength = "";
851 // if max_length is set to zero, then do not set a maxlength
852 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
853 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
854 $lres = sqlStatement("SELECT * FROM list_options " .
855 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
856 echo "<table cellpadding='0' cellspacing='0'>";
857 while ($lrow = sqlFetchArray($lres)) {
858 $option_id = $lrow['option_id'];
859 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
860 $restype = substr($avalue[$option_id], 0, 1);
861 $resnote = substr($avalue[$option_id], 2);
863 // Added 5-09 by BM - Translate label if applicable
864 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
866 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
867 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
868 " id='check_{$field_id_esc}[$option_id_esc]' class='form-control' value='1' $lbfonchange";
869 if ($restype) echo " checked";
870 echo " $disabled />&nbsp;</td>";
871 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
872 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
873 echo "<td><input type='text'" .
874 " name='form_{$field_id_esc}[$option_id_esc]'" .
875 " id='form_{$field_id_esc}[$option_id_esc]'" .
876 " size='$fldlength'" .
877 " class='form-control' " .
878 " $string_maxlength" .
879 " value='$resnote' $disabled /></td>";
880 echo "</tr>";
882 echo "</table>";
885 // single-selection list with ability to add to it
886 else if ($data_type == 26) {
887 echo generate_select_list("form_$field_id", $list_id, $currvalue,
888 $description, ($showEmpty ? $empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
889 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
890 // show the add button if user has access to correct list
891 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
892 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
893 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
894 if (aco_exist('lists', $list_id)) {
895 // a specific aco exist for this list, so ensure access
896 if (acl_check('lists', $list_id)) echo $outputAddButton;
898 else {
899 // no specific aco exist for this list, so check for access to 'default' list
900 if (acl_check('lists', 'default')) echo $outputAddButton;
904 // a set of labeled radio buttons
905 else if ($data_type == 27) {
906 // In this special case, fld_length is the number of columns generated.
907 $cols = max(1, $frow['fld_length']);
908 $lres = sqlStatement("SELECT * FROM list_options " .
909 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
910 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
911 $tdpct = (int) (100 / $cols);
912 $got_selected = FALSE;
913 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
914 $option_id = $lrow['option_id'];
915 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
916 if ($count % $cols == 0) {
917 if ($count) echo "</tr>";
918 echo "<tr>";
920 echo "<td width='$tdpct%'>";
921 echo "<input type='radio' name='form_{$field_id_esc}' class='form-control' id='form_{$field_id_esc}[$option_id_esc]'" .
922 " value='$option_id_esc' $lbfonchange";
923 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
924 (strlen($currvalue) > 0 && $option_id == $currvalue))
926 echo " checked";
927 $got_selected = TRUE;
929 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
930 echo "</td>";
932 if ($count) {
933 echo "</tr>";
934 if ($count > $cols) {
935 // Add some space after multiple rows of radio buttons.
936 $cols = htmlspecialchars($cols, ENT_QUOTES);
937 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
940 echo "</table>";
941 if (!$got_selected && strlen($currvalue) > 0) {
942 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
943 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
944 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
948 // special case for history of lifestyle status; 3 radio buttons and a date text field:
949 // VicarePlus :: A selection list box for smoking status:
950 else if ($data_type == 28 || $data_type == 32) {
951 $tmp = explode('|', $currvalue);
952 switch(count($tmp)) {
953 case "4": {
954 $resnote = $tmp[0];
955 $restype = $tmp[1];
956 $resdate = $tmp[2];
957 $reslist = $tmp[3];
958 } break;
959 case "3": {
960 $resnote = $tmp[0];
961 $restype = $tmp[1];
962 $resdate = $tmp[2];
963 } break;
964 case "2": {
965 $resnote = $tmp[0];
966 $restype = $tmp[1];
967 $resdate = "";
968 } break;
969 case "1": {
970 $resnote = $tmp[0];
971 $resdate = $restype = "";
972 } break;
973 default: {
974 $restype = $resdate = $resnote = "";
975 } break;
977 $maxlength = $frow['max_length'];
978 $string_maxlength = "";
979 // if max_length is set to zero, then do not set a maxlength
980 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
981 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
983 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
984 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
985 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
986 echo "<table cellpadding='0' cellspacing='0'>";
987 echo "<tr>";
988 if ($data_type == 28)
990 // input text
991 echo "<td><input type='text'" .
992 " name='form_$field_id_esc'" .
993 " id='form_$field_id_esc'" .
994 " size='$fldlength'" .
995 " $string_maxlength" .
996 " value='$resnote' $disabled />&nbsp;</td>";
997 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
998 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
999 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1001 else if($data_type == 32)
1003 // input text
1004 echo "<tr><td><input type='text'" .
1005 " name='form_text_$field_id_esc'" .
1006 " id='form_text_$field_id_esc'" .
1007 " size='$fldlength'" .
1008 " class='form-control'" .
1009 " $string_maxlength" .
1010 " value='$resnote' $disabled />&nbsp;</td></tr>";
1011 echo "<td>";
1012 //Selection list for smoking status
1013 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1014 echo generate_select_list("form_$field_id", $list_id, $reslist,
1015 $description, ($showEmpty ? $empty_title : ''), '', $onchange, '',
1016 ($disabled ? array('disabled' => 'disabled') : null));
1017 echo "</td>";
1018 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1020 // current
1021 echo "<td class='text' ><input type='radio'" .
1022 " name='radio_{$field_id_esc}'" .
1023 " id='radio_{$field_id_esc}[current]'" .
1024 " class='form-control'" .
1025 " value='current" . $field_id_esc . "' $lbfonchange";
1026 if ($restype == "current" . $field_id) echo " checked";
1027 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1028 echo " />" . xlt('Current') . "&nbsp;</td>";
1029 // quit
1030 echo "<td class='text'><input type='radio'" .
1031 " name='radio_{$field_id_esc}'" .
1032 " id='radio_{$field_id_esc}[quit]'" .
1033 " class='form-control'" .
1034 " value='quit".$field_id_esc."' $lbfonchange";
1035 if ($restype == "quit" . $field_id) echo " checked";
1036 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1037 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1038 // quit date
1039 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1040 " value='$resdate'" .
1041 " title='$description'" .
1042 " $disabled />";
1043 echo "&nbsp;</td>";
1044 // never
1045 echo "<td class='text'><input type='radio'" .
1046 " name='radio_{$field_id_esc}'" .
1047 " class='form-control'" .
1048 " id='radio_{$field_id_esc}[never]'" .
1049 " value='never" . $field_id_esc . "' $lbfonchange";
1050 if ($restype == "never" . $field_id) echo " checked";
1051 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1052 echo " />" . xlt('Never') . "&nbsp;</td>";
1053 // Not Applicable
1054 echo "<td class='text'><input type='radio'" .
1055 " class='form-control' " .
1056 " name='radio_{$field_id}'" .
1057 " id='radio_{$field_id}[not_applicable]'" .
1058 " value='not_applicable" . $field_id . "' $lbfonchange";
1059 if ($restype == "not_applicable" . $field_id) echo " checked";
1060 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1061 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1063 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1064 echo "<td class='text' ><div id='smoke_code'></div></td>";
1065 echo "</tr>";
1066 echo "</table>";
1069 // static text. read-only, of course.
1070 else if ($data_type == 31) {
1071 echo nl2br($frow['description']);
1074 //$data_type == 33
1075 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1076 //$data_type == 33
1078 else if($data_type == 34){
1079 $arr = explode("|*|*|*|",$currvalue);
1080 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;'>";
1081 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
1082 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>";
1083 echo "</a>";
1086 //facilities drop-down list
1087 else if ($data_type == 35) {
1088 if (empty($currvalue)){
1089 $currvalue = 0;
1091 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1092 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1095 //multiple select
1096 // supports backup list
1097 else if ($data_type == 36) {
1098 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1099 $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);
1103 // Canvas and related elements for browser-side image drawing.
1104 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1105 else if ($data_type == 40) {
1106 // Unlike other field types, width and height are in pixels.
1107 $canWidth = intval($frow['fld_length']);
1108 $canHeight = intval($frow['fld_rows']);
1109 if (empty($currvalue)) {
1110 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1111 // If defined this is the filename of the default starting image.
1112 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1115 $mywidth = 50 + ($canWidth > 250 ? $canWidth : 250);
1116 $myheight = 31 + ($canHeight > 261 ? $canHeight : 261);
1117 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1118 // Hidden form field exists to send updated data to the server at submit time.
1119 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1120 // Hidden image exists to support initialization of the canvas.
1121 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1122 // $date_init is a misnomer but it's the place for browser-side setup logic.
1123 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1128 function generate_print_field($frow, $currvalue) {
1129 global $rootdir, $date_init, $ISSUE_TYPES;
1131 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1133 $data_type = $frow['data_type'];
1134 $field_id = $frow['field_id'];
1135 $list_id = $frow['list_id'];
1136 $fld_length = $frow['fld_length'];
1137 $backup_list = $frow['list_backup_id'];
1139 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1141 // Can pass $frow['empty_title'] with this variable, otherwise
1142 // will default to 'Unassigned'.
1143 // If it is 'SKIP' then an empty text title is completely skipped.
1144 $showEmpty = true;
1145 if (isset($frow['empty_title'])) {
1146 if ($frow['empty_title'] == "SKIP") {
1147 //do not display an 'empty' choice
1148 $showEmpty = false;
1149 $empty_title = "Unassigned";
1151 else {
1152 $empty_title = $frow['empty_title'];
1155 else {
1156 $empty_title = "Unassigned";
1159 // generic single-selection list
1160 // Supports backup lists.
1161 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
1162 if (empty($fld_length)) {
1163 if ($list_id == 'titles') {
1164 $fld_length = 3;
1165 } else {
1166 $fld_length = 10;
1169 $tmp = '';
1170 if ($currvalue) {
1171 $lrow = sqlQuery("SELECT title FROM list_options " .
1172 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1173 $tmp = xl_list_label($lrow['title']);
1174 if ($lrow == 0 && !empty($backup_list)) {
1175 // since primary list did not map, try to map to backup list
1176 $lrow = sqlQuery("SELECT title FROM list_options " .
1177 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1178 $tmp = xl_list_label($lrow['title']);
1180 if (empty($tmp)) $tmp = "($currvalue)";
1182 /*****************************************************************
1183 echo "<input type='text'" .
1184 " size='$fld_length'" .
1185 " value='$tmp'" .
1186 " class='under'" .
1187 " />";
1188 *****************************************************************/
1189 if ($tmp === '') {
1190 $tmp = '&nbsp;';
1192 else {
1193 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1195 echo $tmp;
1198 // simple text field
1199 else if ($data_type == 2 || $data_type == 15) {
1200 /*****************************************************************
1201 echo "<input type='text'" .
1202 " size='$fld_length'" .
1203 " value='$currescaped'" .
1204 " class='under'" .
1205 " />";
1206 *****************************************************************/
1207 if ($currescaped === '') $currescaped = '&nbsp;';
1208 echo $currescaped;
1211 // long or multi-line text field
1212 else if ($data_type == 3) {
1213 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
1214 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
1215 echo "<textarea" .
1216 " class='form-control' " .
1217 " cols='$fldlength'" .
1218 " rows='$maxlength'>" .
1219 $currescaped . "</textarea>";
1222 // date
1223 else if ($data_type == 4) {
1224 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1225 $agestr = optionalAge($frow, $currvalue,$asof);
1226 if ($agestr) {
1227 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1229 if ($currvalue === '') {
1230 echo '&nbsp;';
1232 else {
1233 echo text(oeFormatShortDate($currvalue));
1235 // Optional display of age or gestational age.
1236 if ($agestr) {
1237 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1241 // provider list
1242 else if ($data_type == 10 || $data_type == 11) {
1243 $tmp = '';
1244 if ($currvalue) {
1245 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1246 "WHERE id = ?", array($currvalue) );
1247 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1248 if (empty($tmp)) $tmp = "($currvalue)";
1250 /*****************************************************************
1251 echo "<input type='text'" .
1252 " size='$fld_length'" .
1253 " value='$tmp'" .
1254 " class='under'" .
1255 " />";
1256 *****************************************************************/
1257 if ($tmp === '') { $tmp = '&nbsp;'; }
1258 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1259 echo $tmp;
1262 // pharmacy list
1263 else if ($data_type == 12) {
1264 $tmp = '';
1265 if ($currvalue) {
1266 $pres = get_pharmacies();
1267 while ($prow = sqlFetchArray($pres)) {
1268 $key = $prow['id'];
1269 if ($currvalue == $key) {
1270 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1271 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1272 $prow['line1'] . ' / ' . $prow['city'];
1275 if (empty($tmp)) $tmp = "($currvalue)";
1277 /*****************************************************************
1278 echo "<input type='text'" .
1279 " size='$fld_length'" .
1280 " value='$tmp'" .
1281 " class='under'" .
1282 " />";
1283 *****************************************************************/
1284 if ($tmp === '') { $tmp = '&nbsp;'; }
1285 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1286 echo $tmp;
1289 // squads
1290 else if ($data_type == 13) {
1291 $tmp = '';
1292 if ($currvalue) {
1293 $squads = acl_get_squads();
1294 if ($squads) {
1295 foreach ($squads as $key => $value) {
1296 if ($currvalue == $key) {
1297 $tmp = $value[3];
1301 if (empty($tmp)) $tmp = "($currvalue)";
1303 /*****************************************************************
1304 echo "<input type='text'" .
1305 " size='$fld_length'" .
1306 " value='$tmp'" .
1307 " class='under'" .
1308 " />";
1309 *****************************************************************/
1310 if ($tmp === '') { $tmp = '&nbsp;'; }
1311 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1312 echo $tmp;
1315 // Address book.
1316 else if ($data_type == 14) {
1317 $tmp = '';
1318 if ($currvalue) {
1319 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1320 "WHERE id = ?", array($currvalue) );
1321 $uname = $urow['lname'];
1322 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1323 $tmp = $uname;
1324 if (empty($tmp)) $tmp = "($currvalue)";
1326 /*****************************************************************
1327 echo "<input type='text'" .
1328 " size='$fld_length'" .
1329 " value='$tmp'" .
1330 " class='under'" .
1331 " />";
1332 *****************************************************************/
1333 if ($tmp === '') { $tmp = '&nbsp;'; }
1334 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1335 echo $tmp;
1338 // insurance company list
1339 else if ($data_type == 16) {
1340 $tmp = '';
1341 if ($currvalue) {
1342 $insprovs = getInsuranceProviders();
1343 foreach ($insprovs as $key => $ipname) {
1344 if ($currvalue == $key) {
1345 $tmp = $ipname;
1348 if (empty($tmp)) $tmp = "($currvalue)";
1350 if ($tmp === '') $tmp = '&nbsp;';
1351 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1352 echo $tmp;
1355 // issue types
1356 else if ($data_type == 17) {
1357 $tmp = '';
1358 if ($currvalue) {
1359 foreach ($ISSUE_TYPES as $key => $value) {
1360 if ($currvalue == $key) {
1361 $tmp = $value[1];
1364 if (empty($tmp)) $tmp = "($currvalue)";
1366 if ($tmp === '') $tmp = '&nbsp;';
1367 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1368 echo $tmp;
1371 // Visit categories.
1372 else if ($data_type == 18) {
1373 $tmp = '';
1374 if ($currvalue) {
1375 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1376 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1377 array($currvalue));
1378 $tmp = xl_appt_category($crow['pc_catname']);
1379 if (empty($tmp)) $tmp = "($currvalue)";
1381 if ($tmp === '') { $tmp = '&nbsp;'; }
1382 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES); }
1383 echo $tmp;
1386 // a set of labeled checkboxes
1387 else if ($data_type == 21) {
1388 // In this special case, fld_length is the number of columns generated.
1389 $cols = max(1, $fld_length);
1390 $avalue = explode('|', $currvalue);
1391 $lres = sqlStatement("SELECT * FROM list_options " .
1392 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1393 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1394 $tdpct = (int) (100 / $cols);
1395 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1396 $option_id = $lrow['option_id'];
1397 if ($count % $cols == 0) {
1398 if ($count) echo "</tr>";
1399 echo "<tr>";
1401 echo "<td width='$tdpct%'>";
1402 echo "<input type='checkbox'";
1403 if (in_array($option_id, $avalue)) echo " checked";
1404 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1405 echo "</td>";
1407 if ($count) {
1408 echo "</tr>";
1409 if ($count > $cols) {
1410 // Add some space after multiple rows of checkboxes.
1411 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1412 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1415 echo "</table>";
1418 // a set of labeled text input fields
1419 else if ($data_type == 22) {
1420 $tmp = explode('|', $currvalue);
1421 $avalue = array();
1422 foreach ($tmp as $value) {
1423 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1424 $avalue[$matches[1]] = $matches[2];
1427 $lres = sqlStatement("SELECT * FROM list_options " .
1428 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1429 echo "<table cellpadding='0' cellspacing='0'>";
1430 while ($lrow = sqlFetchArray($lres)) {
1431 $option_id = $lrow['option_id'];
1432 $fldlength = empty($fld_length) ? 20 : $fld_length;
1433 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1434 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1435 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1436 echo "<td><input type='text'" .
1437 " class='form-control' " .
1438 " size='$fldlength'" .
1439 " value='$inputValue'" .
1440 " class='under'" .
1441 " /></td></tr>";
1443 echo "</table>";
1446 // a set of exam results; 3 radio buttons and a text field:
1447 else if ($data_type == 23) {
1448 $tmp = explode('|', $currvalue);
1449 $avalue = array();
1450 foreach ($tmp as $value) {
1451 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1452 $avalue[$matches[1]] = $matches[2];
1455 $fldlength = empty($fld_length) ? 20 : $fld_length;
1456 $lres = sqlStatement("SELECT * FROM list_options " .
1457 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1458 echo "<table cellpadding='0' cellspacing='0'>";
1459 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1460 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1461 "&nbsp;</td><td class='bold'>" .
1462 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1463 "<td class='bold'>" .
1464 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1465 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1466 while ($lrow = sqlFetchArray($lres)) {
1467 $option_id = $lrow['option_id'];
1468 $restype = substr($avalue[$option_id], 0, 1);
1469 $resnote = substr($avalue[$option_id], 2);
1470 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1471 for ($i = 0; $i < 3; ++$i) {
1472 echo "<td><input type='radio'";
1473 if ($restype === "$i") echo " checked";
1474 echo " /></td>";
1476 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1477 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1478 echo "<td><input type='text'" .
1479 " size='$fldlength'" .
1480 " value='$resnote'" .
1481 " class='under form-control' /></td>" .
1482 "</tr>";
1484 echo "</table>";
1487 // the list of active allergies for the current patient
1488 // this is read-only!
1489 else if ($data_type == 24) {
1490 $query = "SELECT title, comments FROM lists WHERE " .
1491 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1492 "ORDER BY begdate";
1493 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1494 $count = 0;
1495 while ($lrow = sqlFetchArray($lres)) {
1496 if ($count++) echo "<br />";
1497 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1498 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1502 // a set of labeled checkboxes, each with a text field:
1503 else if ($data_type == 25) {
1504 $tmp = explode('|', $currvalue);
1505 $avalue = array();
1506 foreach ($tmp as $value) {
1507 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1508 $avalue[$matches[1]] = $matches[2];
1511 $fldlength = empty($fld_length) ? 20 : $fld_length;
1512 $lres = sqlStatement("SELECT * FROM list_options " .
1513 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1514 echo "<table cellpadding='0' cellspacing='0'>";
1515 while ($lrow = sqlFetchArray($lres)) {
1516 $option_id = $lrow['option_id'];
1517 $restype = substr($avalue[$option_id], 0, 1);
1518 $resnote = substr($avalue[$option_id], 2);
1519 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1520 echo "<td><input type='checkbox'";
1521 if ($restype) echo " checked";
1522 echo " />&nbsp;</td>";
1523 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1524 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1525 echo "<td><input type='text'" .
1526 " size='$fldlength'" .
1527 " class='form-control' " .
1528 " value='$resnote'" .
1529 " class='under'" .
1530 " /></td>" .
1531 "</tr>";
1533 echo "</table>";
1536 // a set of labeled radio buttons
1537 else if ($data_type == 27) {
1538 // In this special case, fld_length is the number of columns generated.
1539 $cols = max(1, $frow['fld_length']);
1540 $lres = sqlStatement("SELECT * FROM list_options " .
1541 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1542 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1543 $tdpct = (int) (100 / $cols);
1544 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1545 $option_id = $lrow['option_id'];
1546 if ($count % $cols == 0) {
1547 if ($count) echo "</tr>";
1548 echo "<tr>";
1550 echo "<td width='$tdpct%'>";
1551 echo "<input type='radio'";
1552 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1553 (strlen($currvalue) > 0 && $option_id == $currvalue))
1555 echo " checked";
1557 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1558 echo "</td>";
1560 if ($count) {
1561 echo "</tr>";
1562 if ($count > $cols) {
1563 // Add some space after multiple rows of radio buttons.
1564 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1565 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1568 echo "</table>";
1571 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1572 else if ($data_type == 28 || $data_type == 32) {
1573 $tmp = explode('|', $currvalue);
1574 switch(count($tmp)) {
1575 case "4": {
1576 $resnote = $tmp[0];
1577 $restype = $tmp[1];
1578 $resdate = $tmp[2];
1579 $reslist = $tmp[3];
1580 } break;
1581 case "3": {
1582 $resnote = $tmp[0];
1583 $restype = $tmp[1];
1584 $resdate = $tmp[2];
1585 } break;
1586 case "2": {
1587 $resnote = $tmp[0];
1588 $restype = $tmp[1];
1589 $resdate = "";
1590 } break;
1591 case "1": {
1592 $resnote = $tmp[0];
1593 $resdate = $restype = "";
1594 } break;
1595 default: {
1596 $restype = $resdate = $resnote = "";
1597 } break;
1599 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1600 echo "<table cellpadding='0' cellspacing='0'>";
1601 echo "<tr>";
1602 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1603 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1604 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1605 if($data_type == 28)
1607 echo "<td><input type='text'" .
1608 " size='$fldlength'" .
1609 " class='under'" .
1610 " value='$resnote' /></td>";
1611 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1612 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1613 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1615 else if($data_type == 32)
1617 echo "<tr><td><input type='text'" .
1618 " size='$fldlength'" .
1619 " class='under form-control'" .
1620 " value='$resnote' /></td></tr>";
1621 $fldlength = 30;
1622 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1623 echo "<td><input type='text'" .
1624 " size='$fldlength'" .
1625 " class='under form-control'" .
1626 " value='$smoking_status_title' /></td>";
1627 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1629 echo "<td><input type='radio' class='form-control'";
1630 if ($restype == "current".$field_id) echo " checked";
1631 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1633 echo "<td><input type='radio' class='form-control'";
1634 if ($restype == "current".$field_id) echo " checked";
1635 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1637 echo "<td><input type='text' size='6'" .
1638 " value='$resdate'" .
1639 " class='under form-control'" .
1640 " /></td>";
1642 echo "<td><input type='radio' class='form-control'";
1643 if ($restype == "current".$field_id) echo " checked";
1644 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1646 echo "<td><input type='radio' class='form-control'";
1647 if ($restype == "not_applicable".$field_id) echo " checked";
1648 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1649 echo "</tr>";
1650 echo "</table>";
1653 // static text. read-only, of course.
1654 else if ($data_type == 31) {
1655 echo nl2br($frow['description']);
1658 else if($data_type == 34){
1659 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;'>";
1660 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1661 echo "<div style='display:none'><textarea name='form_{$field_id}' class='form-control' id='form_{$field_id}' stye='display:none'></textarea></div>";
1662 echo "</a>";
1665 //facilities drop-down list
1666 else if ($data_type == 35) {
1667 if (empty($currvalue)){
1668 $currvalue = 0;
1670 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1673 //Multi-select
1674 // Supports backup lists.
1675 else if ($data_type == 36) {
1676 if (empty($fld_length)) {
1677 if ($list_id == 'titles') {
1678 $fld_length = 3;
1679 } else {
1680 $fld_length = 10;
1683 $tmp = '';
1685 $values_array = explode("|", $currvalue);
1687 $i=0;
1688 foreach($values_array as $value) {
1689 if ($value) {
1690 $lrow = sqlQuery("SELECT title FROM list_options " .
1691 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1692 $tmp = xl_list_label($lrow['title']);
1693 if ($lrow == 0 && !empty($backup_list)) {
1694 // since primary list did not map, try to map to backup list
1695 $lrow = sqlQuery("SELECT title FROM list_options " .
1696 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1697 $tmp = xl_list_label($lrow['title']);
1699 if (empty($tmp)) $tmp = "($value)";
1702 if ($tmp === '') {
1703 $tmp = '&nbsp;';
1705 else {
1706 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1708 if ($i != 0 && $tmp != '&nbsp;') echo ",";
1709 echo $tmp;
1710 $i++;
1714 // Image from canvas drawing
1715 else if ($data_type == 40) {
1716 echo "<img src='" . attr($currvalue) . "'>";
1721 function generate_display_field($frow, $currvalue) {
1722 global $ISSUE_TYPES, $facilityService;
1724 $data_type = $frow['data_type'];
1725 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1726 $list_id = $frow['list_id'];
1727 $backup_list = isset($frow['list_backup_id']) ? $frow['list_backup_id'] : null;
1729 $s = '';
1731 // generic selection list or the generic selection list with add on the fly
1732 // feature, or radio buttons
1733 // Supports backup lists for datatypes 1,26,33
1734 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1735 $lrow = sqlQuery("SELECT title FROM list_options " .
1736 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
1737 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1738 //if there is no matching value in the corresponding lists check backup list
1739 // only supported in data types 1,26,33
1740 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1741 $lrow = sqlQuery("SELECT title FROM list_options " .
1742 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
1743 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1747 // simple text field
1748 else if ($data_type == 2) {
1749 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1752 // long or multi-line text field
1753 else if ($data_type == 3) {
1754 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1757 // date
1758 else if ($data_type == 4) {
1759 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1760 $s = '';
1761 $agestr = optionalAge($frow, $currvalue, $asof);
1762 if ($agestr) {
1763 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1765 if ($currvalue === '') {
1766 $s .= '&nbsp;';
1768 else {
1769 $s .= text(oeFormatShortDate($currvalue));
1771 // Optional display of age or gestational age.
1772 if ($agestr) {
1773 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1777 // provider
1778 else if ($data_type == 10 || $data_type == 11) {
1779 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1780 "WHERE id = ?", array($currvalue) );
1781 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1784 // pharmacy list
1785 else if ($data_type == 12) {
1786 $pres = get_pharmacies();
1787 while ($prow = sqlFetchArray($pres)) {
1788 $key = $prow['id'];
1789 if ($currvalue == $key) {
1790 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1791 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1792 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1797 // squads
1798 else if ($data_type == 13) {
1799 $squads = acl_get_squads();
1800 if ($squads) {
1801 foreach ($squads as $key => $value) {
1802 if ($currvalue == $key) {
1803 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1809 // address book
1810 else if ($data_type == 14) {
1811 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
1812 "WHERE id = ?", array($currvalue));
1813 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
1814 if($urow['organization'] !=""){
1815 $uname = $urow['organization'];
1816 }else{
1817 $uname = $urow['lname'];
1818 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1820 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1823 // billing code
1824 else if ($data_type == 15) {
1825 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1828 // insurance company list
1829 else if ($data_type == 16) {
1830 $insprovs = getInsuranceProviders();
1831 foreach ($insprovs as $key => $ipname) {
1832 if ($currvalue == $key) {
1833 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
1838 // issue types
1839 else if ($data_type == 17) {
1840 foreach ($ISSUE_TYPES as $key => $value) {
1841 if ($currvalue == $key) {
1842 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
1847 // visit category
1848 else if ($data_type == 18) {
1849 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1850 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1851 array($currvalue));
1852 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES);
1855 // a set of labeled checkboxes
1856 else if ($data_type == 21) {
1857 $avalue = explode('|', $currvalue);
1858 $lres = sqlStatement("SELECT * FROM list_options " .
1859 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1860 $count = 0;
1861 while ($lrow = sqlFetchArray($lres)) {
1862 $option_id = $lrow['option_id'];
1863 if (in_array($option_id, $avalue)) {
1864 if ($count++) $s .= "<br />";
1866 // Added 5-09 by BM - Translate label if applicable
1867 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES);
1873 // a set of labeled text input fields
1874 else if ($data_type == 22) {
1875 $tmp = explode('|', $currvalue);
1876 $avalue = array();
1877 foreach ($tmp as $value) {
1878 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1879 $avalue[$matches[1]] = $matches[2];
1882 $lres = sqlStatement("SELECT * FROM list_options " .
1883 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1884 $s .= "<table cellpadding='0' cellspacing='0'>";
1885 while ($lrow = sqlFetchArray($lres)) {
1886 $option_id = $lrow['option_id'];
1887 if (empty($avalue[$option_id])) continue;
1889 // Added 5-09 by BM - Translate label if applicable
1890 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1892 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1894 $s .= "</table>";
1897 // a set of exam results; 3 radio buttons and a text field:
1898 else if ($data_type == 23) {
1899 $tmp = explode('|', $currvalue);
1900 $avalue = array();
1901 foreach ($tmp as $value) {
1902 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1903 $avalue[$matches[1]] = $matches[2];
1906 $lres = sqlStatement("SELECT * FROM list_options " .
1907 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1908 $s .= "<table cellpadding='0' cellspacing='0'>";
1909 while ($lrow = sqlFetchArray($lres)) {
1910 $option_id = $lrow['option_id'];
1911 $restype = substr($avalue[$option_id], 0, 1);
1912 $resnote = substr($avalue[$option_id], 2);
1913 if (empty($restype) && empty($resnote)) continue;
1915 // Added 5-09 by BM - Translate label if applicable
1916 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1918 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1919 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1920 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1921 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1922 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1923 $s .= "</tr>";
1925 $s .= "</table>";
1928 // the list of active allergies for the current patient
1929 else if ($data_type == 24) {
1930 $query = "SELECT title, comments FROM lists WHERE " .
1931 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1932 "ORDER BY begdate";
1933 // echo "<!-- $query -->\n"; // debugging
1934 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1935 $count = 0;
1936 while ($lrow = sqlFetchArray($lres)) {
1937 if ($count++) $s .= "<br />";
1938 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1939 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1943 // a set of labeled checkboxes, each with a text field:
1944 else if ($data_type == 25) {
1945 $tmp = explode('|', $currvalue);
1946 $avalue = array();
1947 foreach ($tmp as $value) {
1948 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1949 $avalue[$matches[1]] = $matches[2];
1952 $lres = sqlStatement("SELECT * FROM list_options " .
1953 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1954 $s .= "<table cellpadding='0' cellspacing='0'>";
1955 while ($lrow = sqlFetchArray($lres)) {
1956 $option_id = $lrow['option_id'];
1957 $restype = substr($avalue[$option_id], 0, 1);
1958 $resnote = substr($avalue[$option_id], 2);
1959 if (empty($restype) && empty($resnote)) continue;
1961 // Added 5-09 by BM - Translate label if applicable
1962 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1964 $restype = $restype ? xl('Yes') : xl('No');
1965 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1966 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1967 $s .= "</tr>";
1969 $s .= "</table>";
1972 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1973 // VicarePlus :: A selection list for smoking status.
1974 else if ($data_type == 28 || $data_type == 32) {
1975 $tmp = explode('|', $currvalue);
1976 switch(count($tmp)) {
1977 case "4": {
1978 $resnote = $tmp[0];
1979 $restype = $tmp[1];
1980 $resdate = $tmp[2];
1981 $reslist = $tmp[3];
1982 } break;
1983 case "3": {
1984 $resnote = $tmp[0];
1985 $restype = $tmp[1];
1986 $resdate = $tmp[2];
1987 } break;
1988 case "2": {
1989 $resnote = $tmp[0];
1990 $restype = $tmp[1];
1991 $resdate = "";
1992 } break;
1993 case "1": {
1994 $resnote = $tmp[0];
1995 $resdate = $restype = "";
1996 } break;
1997 default: {
1998 $restype = $resdate = $resnote = "";
1999 } break;
2001 $s .= "<table cellpadding='0' cellspacing='0'>";
2003 $s .= "<tr>";
2004 $res = "";
2005 if ($restype == "current".$field_id) $res = xl('Current');
2006 if ($restype == "quit".$field_id) $res = xl('Quit');
2007 if ($restype == "never".$field_id) $res = xl('Never');
2008 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
2009 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2010 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2011 if ($data_type == 28)
2013 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2015 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2016 else if ($data_type == 32)
2017 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2018 $smoke_codes = getSmokeCodes();
2019 if (!empty($reslist)) {
2020 if($smoke_codes[$reslist]!="")
2021 $code_desc = "( ".$smoke_codes[$reslist]." )";
2023 $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>";}
2025 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2028 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
2029 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
2030 $s .= "</tr>";
2031 $s .= "</table>";
2034 // static text. read-only, of course.
2035 else if ($data_type == 31) {
2036 $s .= nl2br($frow['description']);
2039 else if($data_type == 34){
2040 $arr = explode("|*|*|*|",$currvalue);
2041 for($i=0;$i<sizeof($arr);$i++){
2042 $s.=$arr[$i];
2046 // facility
2047 else if ($data_type == 35) {
2048 $urow = $facilityService->getById($currvalue);
2049 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
2052 // Multi select
2053 // Supports backup lists
2054 else if ($data_type == 36) {
2055 $values_array = explode("|", $currvalue);
2056 $i = 0;
2057 foreach($values_array as $value) {
2058 $lrow = sqlQuery("SELECT title FROM list_options " .
2059 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2060 if ($lrow == 0 && !empty($backup_list)) {
2061 //use back up list
2062 $lrow = sqlQuery("SELECT title FROM list_options " .
2063 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2065 if ($i > 0) {
2066 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2067 } else {
2068 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2070 $i++;
2074 // Image from canvas drawing
2075 else if ($data_type == 40) {
2076 $s .= "<img src='" . attr($currvalue) . "'>";
2079 return $s;
2082 // Generate plain text versions of selected LBF field types.
2083 // Currently used by interface/patient_file/download_template.php.
2084 // More field types might need to be supported here in the future.
2086 function generate_plaintext_field($frow, $currvalue) {
2087 global $ISSUE_TYPES;
2089 $data_type = $frow['data_type'];
2090 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2091 $list_id = $frow['list_id'];
2092 $backup_list = $frow['backup_list'];
2093 $s = '';
2095 // generic selection list or the generic selection list with add on the fly
2096 // feature, or radio buttons
2097 // Supports backup lists (for datatypes 1,26,33)
2098 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2099 $lrow = sqlQuery("SELECT title FROM list_options " .
2100 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
2101 $s = xl_list_label($lrow['title']);
2102 //if there is no matching value in the corresponding lists check backup list
2103 // only supported in data types 1,26,33
2104 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2105 $lrow = sqlQuery("SELECT title FROM list_options " .
2106 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
2107 $s = xl_list_label($lrow['title']);
2111 // simple or long text field
2112 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2113 $s = $currvalue;
2116 // date
2117 else if ($data_type == 4) {
2118 $s = oeFormatShortDate($currvalue);
2119 // Optional display of age or gestational age.
2120 $asof=''; //not used here, but set to prevent a php warning when call optionalAge
2121 $tmp = optionalAge($frow, $currvalue,$asof);
2122 if ($tmp) $s .= ' ' . $tmp;
2125 // provider
2126 else if ($data_type == 10 || $data_type == 11) {
2127 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2128 "WHERE id = ?", array($currvalue) );
2129 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2132 // pharmacy list
2133 else if ($data_type == 12) {
2134 $pres = get_pharmacies();
2135 while ($prow = sqlFetchArray($pres)) {
2136 $key = $prow['id'];
2137 if ($currvalue == $key) {
2138 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2139 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2140 $prow['line1'] . ' / ' . $prow['city'];
2145 // address book
2146 else if ($data_type == 14) {
2147 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2148 "WHERE id = ?", array($currvalue));
2149 $uname = $urow['lname'];
2150 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2151 $s = $uname;
2154 // insurance company list
2155 else if ($data_type == 16) {
2156 $insprovs = getInsuranceProviders();
2157 foreach ($insprovs as $key => $ipname) {
2158 if ($currvalue == $key) {
2159 $s .= $ipname;
2164 // issue type
2165 else if ($data_type == 17) {
2166 foreach ($ISSUE_TYPES as $key => $value) {
2167 if ($currvalue == $key) {
2168 $s .= $value[1];
2173 // visit category
2174 else if ($data_type == 18) {
2175 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2176 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2177 array($currvalue));
2178 $s = $crow['pc_catname'];
2181 // a set of labeled checkboxes
2182 else if ($data_type == 21) {
2183 $avalue = explode('|', $currvalue);
2184 $lres = sqlStatement("SELECT * FROM list_options " .
2185 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2186 $count = 0;
2187 while ($lrow = sqlFetchArray($lres)) {
2188 $option_id = $lrow['option_id'];
2189 if (in_array($option_id, $avalue)) {
2190 if ($count++) $s .= "; ";
2191 $s .= xl_list_label($lrow['title']);
2196 // a set of labeled text input fields
2197 else if ($data_type == 22) {
2198 $tmp = explode('|', $currvalue);
2199 $avalue = array();
2200 foreach ($tmp as $value) {
2201 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2202 $avalue[$matches[1]] = $matches[2];
2205 $lres = sqlStatement("SELECT * FROM list_options " .
2206 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2207 while ($lrow = sqlFetchArray($lres)) {
2208 $option_id = $lrow['option_id'];
2209 if (empty($avalue[$option_id])) continue;
2210 if ($s !== '') $s .= '; ';
2211 $s .= xl_list_label($lrow['title']) . ': ';
2212 $s .= $avalue[$option_id];
2216 // A set of exam results; 3 radio buttons and a text field.
2217 // This shows abnormal results only.
2218 else if ($data_type == 23) {
2219 $tmp = explode('|', $currvalue);
2220 $avalue = array();
2221 foreach ($tmp as $value) {
2222 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2223 $avalue[$matches[1]] = $matches[2];
2226 $lres = sqlStatement("SELECT * FROM list_options " .
2227 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2228 while ($lrow = sqlFetchArray($lres)) {
2229 $option_id = $lrow['option_id'];
2230 $restype = substr($avalue[$option_id], 0, 1);
2231 $resnote = substr($avalue[$option_id], 2);
2232 if (empty($restype) && empty($resnote)) continue;
2233 if ($restype != '2') continue; // show abnormal results only
2234 if ($s !== '') $s .= '; ';
2235 $s .= xl_list_label($lrow['title']);
2236 if (!empty($resnote)) $s .= ': ' . $resnote;
2240 // the list of active allergies for the current patient
2241 else if ($data_type == 24) {
2242 $query = "SELECT title, comments FROM lists WHERE " .
2243 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2244 "ORDER BY begdate";
2245 $lres = sqlStatement($query, array($GLOBALS['pid']));
2246 $count = 0;
2247 while ($lrow = sqlFetchArray($lres)) {
2248 if ($count++) $s .= "; ";
2249 $s .= $lrow['title'];
2250 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2254 // a set of labeled checkboxes, each with a text field:
2255 else if ($data_type == 25) {
2256 $tmp = explode('|', $currvalue);
2257 $avalue = array();
2258 foreach ($tmp as $value) {
2259 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2260 $avalue[$matches[1]] = $matches[2];
2263 $lres = sqlStatement("SELECT * FROM list_options " .
2264 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2265 while ($lrow = sqlFetchArray($lres)) {
2266 $option_id = $lrow['option_id'];
2267 $restype = substr($avalue[$option_id], 0, 1);
2268 $resnote = substr($avalue[$option_id], 2);
2269 if (empty($restype) && empty($resnote)) continue;
2270 if ($s !== '') $s .= '; ';
2271 $s .= xl_list_label($lrow['title']);
2272 $restype = $restype ? xl('Yes') : xl('No');
2273 $s .= $restype;
2274 if ($resnote) $s .= ' ' . $resnote;
2278 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2279 // VicarePlus :: A selection list for smoking status.
2280 else if ($data_type == 28 || $data_type == 32) {
2281 $tmp = explode('|', $currvalue);
2282 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2283 $restype = count($tmp) > 1 ? $tmp[1] : '';
2284 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2285 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2286 $res = "";
2287 if ($restype == "current" . $field_id) $res = xl('Current');
2288 if ($restype == "quit" . $field_id) $res = xl('Quit');
2289 if ($restype == "never" . $field_id) $res = xl('Never');
2290 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2292 if ($data_type == 28) {
2293 if (!empty($resnote)) $s .= $resnote;
2295 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2296 else if ($data_type == 32) {
2297 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2298 if (!empty($resnote)) $s .= ' ' . $resnote;
2300 if (!empty($res)) {
2301 if ($s !== '') $s .= ' ';
2302 $s .= xl('Status') . ' ' . $res;
2304 if ($restype == "quit".$field_id) {
2305 if ($s !== '') $s .= ' ';
2306 $s .= $resdate;
2310 // Multi select
2311 // Supports backup lists
2312 else if ($data_type == 36) {
2313 $values_array = explode("|", $currvalue);
2315 $i = 0;
2316 foreach($values_array as $value) {
2317 $lrow = sqlQuery("SELECT title FROM list_options " .
2318 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2320 if ($lrow == 0 && !empty($backup_list)) {
2321 //use back up list
2322 $lrow = sqlQuery("SELECT title FROM list_options " .
2323 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2326 if ($i > 0) {
2327 $s = $s . ", " . xl_list_label($lrow['title']);
2328 } else {
2329 $s = xl_list_label($lrow['title']);
2332 $i++;
2336 return $s;
2339 $CPR = 4; // cells per row of generic data
2340 $last_group = '';
2341 $cell_count = 0;
2342 $item_count = 0;
2344 function disp_end_cell() {
2345 global $item_count, $cell_count;
2346 if ($item_count > 0) {
2347 echo "</td>";
2348 $item_count = 0;
2352 function disp_end_row() {
2353 global $cell_count, $CPR;
2354 disp_end_cell();
2355 if ($cell_count > 0) {
2356 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
2357 echo "</tr>\n";
2358 $cell_count = 0;
2362 function disp_end_group() {
2363 global $last_group;
2364 if (strlen($last_group) > 0) {
2365 disp_end_row();
2369 function display_layout_rows($formtype, $result1, $result2='') {
2370 global $item_count, $cell_count, $last_group, $CPR;
2372 $fres = sqlStatement("SELECT * FROM layout_options " .
2373 "WHERE form_id = ? AND uor > 0 " .
2374 "ORDER BY group_name, seq", array($formtype) );
2376 while ($frow = sqlFetchArray($fres)) {
2377 $this_group = $frow['group_name'];
2378 $titlecols = $frow['titlecols'];
2379 $datacols = $frow['datacols'];
2380 $data_type = $frow['data_type'];
2381 $field_id = $frow['field_id'];
2382 $list_id = $frow['list_id'];
2383 $currvalue = '';
2385 if ($formtype == 'DEM') {
2386 if (strpos($field_id, 'em_') === 0) {
2387 // Skip employer related fields, if it's disabled.
2388 if ($GLOBALS['omit_employers']) continue;
2389 $tmp = substr($field_id, 3);
2390 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2392 else {
2393 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2396 else {
2397 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2400 // Handle a data category (group) change.
2401 if (strcmp($this_group, $last_group) != 0) {
2402 $group_name = substr($this_group, 1);
2403 // totally skip generating the employer category, if it's disabled.
2404 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2405 disp_end_group();
2406 $last_group = $this_group;
2409 // filter out all the empty field data from the patient report.
2410 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2411 // Handle starting of a new row.
2412 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2413 disp_end_row();
2414 echo "<tr>";
2415 if ($group_name) {
2416 echo "<td class='groupname'>";
2417 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2418 //echo "<font color='#008800'>$group_name</font>";
2420 // Added 5-09 by BM - Translate label if applicable
2421 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
2423 $group_name = '';
2424 } else {
2425 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2426 echo "<td valign='top'>&nbsp;";
2428 echo "</td>";
2431 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2433 // Handle starting of a new label cell.
2434 if ($titlecols > 0) {
2435 disp_end_cell();
2436 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
2437 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2438 echo "<td class='label_custom' colspan='$titlecols_esc' ";
2439 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2440 echo ">";
2441 $cell_count += $titlecols;
2443 ++$item_count;
2445 // Added 5-09 by BM - Translate label if applicable
2446 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2448 // Handle starting of a new data cell.
2449 if ($datacols > 0) {
2450 disp_end_cell();
2451 //echo "<td class='text data' colspan='$datacols' valign='top'";
2452 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2453 echo "<td class='text data' colspan='$datacols_esc'";
2454 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2455 echo ">";
2456 $cell_count += $datacols;
2459 ++$item_count;
2460 echo generate_display_field($frow, $currvalue);
2464 disp_end_group();
2467 function display_layout_tabs($formtype, $result1, $result2='') {
2468 global $item_count, $cell_count, $last_group, $CPR;
2470 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2471 "WHERE form_id = ? AND uor > 0 " .
2472 "ORDER BY group_name, seq", array($formtype) );
2474 $first = true;
2475 while ($frow = sqlFetchArray($fres)) {
2476 $this_group = $frow['group_name'];
2477 $group_name = substr($this_group, 1);
2478 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2480 <li <?php echo $first ? 'class="current"' : '' ?>>
2481 <a href="#" id="header_tab_<?php echo str_replace(" ", "_",htmlspecialchars($group_name,ENT_QUOTES))?>">
2482 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
2483 </li>
2484 <?php
2485 $first = false;
2489 function display_layout_tabs_data($formtype, $result1, $result2='') {
2490 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2492 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2493 "WHERE form_id = ? AND uor > 0 " .
2494 "ORDER BY group_name, seq", array($formtype));
2496 $first = true;
2497 while ($frow = sqlFetchArray($fres)) {
2498 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
2499 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
2500 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
2501 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
2502 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
2503 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
2504 $currvalue = '';
2506 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2508 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2509 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2510 "ORDER BY seq", array($formtype, $this_group) );
2513 <div class="tab <?php echo $first ? 'current' : '' ?>">
2514 <table border='0' cellpadding='0'>
2516 <?php
2517 while ($group_fields = sqlFetchArray($group_fields_query)) {
2519 $titlecols = $group_fields['titlecols'];
2520 $datacols = $group_fields['datacols'];
2521 $data_type = $group_fields['data_type'];
2522 $field_id = $group_fields['field_id'];
2523 $list_id = $group_fields['list_id'];
2524 $currvalue = '';
2525 $condition_str = get_conditions_str($condition_str,$group_fields);
2528 if ($formtype == 'DEM') {
2529 if (strpos($field_id, 'em_') === 0) {
2530 // Skip employer related fields, if it's disabled.
2531 if ($GLOBALS['omit_employers']) continue;
2532 $tmp = substr($field_id, 3);
2533 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2535 else {
2536 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2539 else {
2540 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2543 // Handle a data category (group) change.
2544 if (strcmp($this_group, $last_group) != 0) {
2545 $group_name = substr($this_group, 1);
2546 // totally skip generating the employer category, if it's disabled.
2547 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2548 $last_group = $this_group;
2551 // Handle starting of a new row.
2552 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2553 disp_end_row();
2554 echo "<tr>";
2557 if ($item_count == 0 && $titlecols == 0) {
2558 $titlecols = 1;
2561 // Handle starting of a new label cell.
2562 if ($titlecols > 0) {
2563 disp_end_cell();
2564 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2565 $field_id_label = 'label_'.$group_fields['field_id'];
2566 echo "<td class='label_custom' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
2567 echo ">";
2568 $cell_count += $titlecols;
2570 ++$item_count;
2572 $field_id_label = 'label_'.$group_fields['field_id'];
2573 echo "<span id='".attr($field_id_label)."'>";
2574 // Added 5-09 by BM - Translate label if applicable
2575 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2576 echo "</span>";
2578 // Handle starting of a new data cell.
2579 if ($datacols > 0) {
2580 disp_end_cell();
2581 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2582 $field_id = 'text_'.$group_fields['field_id'];
2583 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
2584 echo ">";
2585 $cell_count += $datacols;
2586 } else {
2587 $field_id = 'text_'.$group_fields['field_id'];
2588 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
2591 ++$item_count;
2592 echo generate_display_field($group_fields, $currvalue);
2595 disp_end_row();
2598 </table>
2599 </div>
2601 <?php
2603 $first = false;
2609 function get_conditions_str($condition_str,$frow){
2610 $conditions = empty($frow['conditions']) ? array() : unserialize($frow['conditions']);
2611 foreach ($conditions as $condition) {
2612 if (empty($condition['id'])) continue;
2613 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2614 if ($condition_str) $condition_str .= ",\n";
2615 $condition_str .= "{" .
2616 "target:'" . addslashes($frow['field_id']) . "', " .
2617 "id:'" . addslashes($condition['id']) . "', " .
2618 "itemid:'" . addslashes($condition['itemid']) . "', " .
2619 "operator:'" . addslashes($condition['operator']) . "', " .
2620 "value:'" . addslashes($condition['value']) . "', " .
2621 "andor:'" . addslashes($andor) . "'}";
2623 return $condition_str;
2625 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2626 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2628 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2629 "WHERE form_id = ? AND uor > 0 " .
2630 "ORDER BY group_name, seq", array($formtype) );
2632 $first = true;
2633 while ($frow = sqlFetchArray($fres)) {
2634 $this_group = $frow['group_name'];
2635 $group_name = substr($this_group, 1);
2636 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
2637 $titlecols = $frow['titlecols'];
2638 $datacols = $frow['datacols'];
2639 $data_type = $frow['data_type'];
2640 $field_id = $frow['field_id'];
2641 $list_id = $frow['list_id'];
2642 $currvalue = '';
2644 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2646 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2647 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2648 "ORDER BY seq", array($formtype,$this_group) );
2651 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_',$group_name_esc)?>" >
2652 <table border='0' cellpadding='0'>
2654 <?php
2655 while ($group_fields = sqlFetchArray($group_fields_query)) {
2657 $titlecols = $group_fields['titlecols'];
2658 $datacols = $group_fields['datacols'];
2659 $data_type = $group_fields['data_type'];
2660 $field_id = $group_fields['field_id'];
2661 $list_id = $group_fields['list_id'];
2662 $backup_list = $group_fields['list_backup_id'];
2663 $condition_str = get_conditions_str($condition_str,$group_fields);
2664 $currvalue = '';
2666 if ($formtype == 'DEM') {
2667 if (strpos($field_id, 'em_') === 0) {
2668 // Skip employer related fields, if it's disabled.
2669 if ($GLOBALS['omit_employers']) continue;
2670 $tmp = substr($field_id, 3);
2671 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2673 else {
2674 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2677 else {
2678 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2681 // Handle a data category (group) change.
2682 if (strcmp($this_group, $last_group) != 0) {
2683 $group_name = substr($this_group, 1);
2684 // totally skip generating the employer category, if it's disabled.
2685 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2686 $last_group = $this_group;
2689 // Handle starting of a new row.
2690 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2691 disp_end_row();
2692 echo "<tr>";
2695 if ($item_count == 0 && $titlecols == 0) {
2696 $titlecols = 1;
2699 // Handle starting of a new label cell.
2700 if ($titlecols > 0) {
2701 disp_end_cell();
2702 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2703 $field_id_label = 'label_'.$group_fields['field_id'];
2704 echo "<td class='label_custom' colspan='$titlecols_esc' id='$field_id_label' ";
2705 echo ">";
2706 $cell_count += $titlecols;
2708 ++$item_count;
2710 // Added 5-09 by BM - Translate label if applicable
2711 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
2713 // Handle starting of a new data cell.
2714 if ($datacols > 0) {
2715 disp_end_cell();
2716 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2717 $field_id = 'text_'.$group_fields['field_id'];
2718 echo "<td class='text data' colspan='$datacols_esc' id='$field_id'";
2719 echo ">";
2720 $cell_count += $datacols;
2723 ++$item_count;
2725 echo generate_form_field($group_fields, $currvalue);
2729 </table>
2730 </div>
2732 <?php
2734 $first = false;
2739 // From the currently posted HTML form, this gets the value of the
2740 // field corresponding to the provided layout_options table row.
2742 function get_layout_form_value($frow, $prefix='form_') {
2744 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
2745 $data_type = $frow['data_type'];
2746 $field_id = $frow['field_id'];
2747 $value = '';
2748 if (isset($_POST["$prefix$field_id"])) {
2749 if ($data_type == 21) {
2750 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2751 // must be concatenated into a |-separated string.
2752 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2753 if (strlen($value)) $value .= '|';
2754 $value .= $key;
2757 else if ($data_type == 22) {
2758 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2759 // into "key:value|key:value|...".
2760 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2761 $val = str_replace('|', ' ', $val);
2762 if (strlen($value)) $value .= '|';
2763 $value .= "$key:$val";
2766 else if ($data_type == 23) {
2767 // $_POST["$prefix$field_id"] is an array of text fields with companion
2768 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2769 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2770 $restype = $_POST["radio_{$field_id}"][$key];
2771 if (empty($restype)) $restype = '0';
2772 $val = str_replace('|', ' ', $val);
2773 if (strlen($value)) $value .= '|';
2774 $value .= "$key:$restype:$val";
2777 else if ($data_type == 25) {
2778 // $_POST["$prefix$field_id"] is an array of text fields with companion
2779 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2780 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2781 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
2782 $val = str_replace('|', ' ', $val);
2783 if (strlen($value)) $value .= '|';
2784 $value .= "$key:$restype:$val";
2787 else if ($data_type == 28 || $data_type == 32) {
2788 // $_POST["$prefix$field_id"] is an date text fields with companion
2789 // radio buttons to be imploded into "notes|type|date".
2790 $restype = $_POST["radio_{$field_id}"];
2791 if (empty($restype)) $restype = '0';
2792 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2793 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2794 if ($data_type == 32)
2796 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2797 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2798 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2799 $value = "$res_text_note|$restype|$resdate|$reslist";
2801 else
2802 $value = "$resnote|$restype|$resdate";
2804 else if ($data_type == 36) {
2805 $value_array = $_POST["form_$field_id"];
2806 $i = 0;
2807 foreach ($value_array as $key => $valueofkey) {
2808 if ($i == 0) {
2809 $value = $valueofkey;
2810 } else {
2811 $value = $value . "|" . $valueofkey;
2813 $i++;
2816 else {
2817 $value = $_POST["$prefix$field_id"];
2821 // Better to die than to silently truncate data!
2822 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2823 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2824 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2826 return trim($value);
2829 // Generate JavaScript validation logic for the required fields.
2831 function generate_layout_validation($form_id) {
2832 $fres = sqlStatement("SELECT * FROM layout_options " .
2833 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2834 "ORDER BY group_name, seq", array($form_id) );
2836 while ($frow = sqlFetchArray($fres)) {
2837 $data_type = $frow['data_type'];
2838 $field_id = $frow['field_id'];
2839 $fldtitle = $frow['title'];
2840 if (!$fldtitle) $fldtitle = $frow['description'];
2841 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES);
2843 if ($data_type == 40) {
2844 $fldid = addslashes("form_$field_id");
2845 // Move canvas image data to its hidden form field so the server will get it.
2846 echo
2847 " var canfld = f['$fldid'];\n" .
2848 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
2849 continue;
2852 if ($frow['uor'] < 2) continue;
2854 switch($data_type) {
2855 case 1:
2856 case 11:
2857 case 12:
2858 case 13:
2859 case 14:
2860 case 26:
2861 case 33:
2862 echo
2863 " if (f.$fldname.selectedIndex <= 0) {\n" .
2864 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2865 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2866 " }\n";
2867 break;
2868 case 27: // radio buttons
2869 echo
2870 " var i = 0;\n" .
2871 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2872 " if (i >= f.$fldname.length) {\n" .
2873 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2874 " }\n";
2875 break;
2876 case 2:
2877 case 3:
2878 case 4:
2879 case 15:
2880 echo
2881 " if (trimlen(f.$fldname.value) == 0) {\n" .
2882 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2883 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2884 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2885 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2886 " } else { " .
2887 " $('#" . $fldname . "').attr('style',''); " .
2888 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2889 " } \n";
2890 break;
2891 case 36: // multi select
2892 echo
2893 " var multi_select=f['$fldname"."[]']; \n " .
2894 " var multi_choice_made=false; \n".
2895 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
2896 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
2897 " } \n" .
2898 " if(!multi_choice_made)
2899 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2901 break;
2907 * DROPDOWN FOR FACILITIES
2909 * build a dropdown with all facilities
2911 * @param string $selected - name of the currently selected facility
2912 * use '0' for "unspecified facility"
2913 * use '' for "All facilities" (the default)
2914 * @param string $name - the name/id for select form (defaults to "form_facility")
2915 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2916 * defaults to true
2917 * @return void - just echo the html encoded string
2919 * Note: This should become a data-type at some point, according to Brady
2921 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2922 $allow_allfacilities = true, $disabled='', $onchange='')
2924 global $facilityService;
2926 $have_selected = false;
2927 $fres = $facilityService->getAll();
2929 $name = htmlspecialchars($name, ENT_QUOTES);
2930 echo " <select class='form-control' name='$name' id='$name'";
2931 if ($onchange) echo " onchange='$onchange'";
2932 echo " $disabled>\n";
2934 if ($allow_allfacilities) {
2935 $option_value = '';
2936 $option_selected_attr = '';
2937 if ($selected == '') {
2938 $option_selected_attr = ' selected="selected"';
2939 $have_selected = true;
2941 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2942 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2943 } elseif ($allow_unspecified) {
2944 $option_value = '0';
2945 $option_selected_attr = '';
2946 if ( $selected == '0' ) {
2947 $option_selected_attr = ' selected="selected"';
2948 $have_selected = true;
2950 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2951 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2954 foreach($fres as $frow) {
2955 $facility_id = $frow['id'];
2956 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2957 $option_selected_attr = '';
2958 if ($selected == $facility_id) {
2959 $option_selected_attr = ' selected="selected"';
2960 $have_selected = true;
2962 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2963 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2966 if ($allow_unspecified && $allow_allfacilities) {
2967 $option_value = '0';
2968 $option_selected_attr = '';
2969 if ( $selected == '0' ) {
2970 $option_selected_attr = ' selected="selected"';
2971 $have_selected = true;
2973 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2974 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2977 if (!$have_selected) {
2978 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2979 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2980 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2981 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2983 echo " </select>\n";
2986 // Expand Collapse Widget
2987 // This forms the header and functionality component of the widget. The information that is displayed
2988 // then follows this function followed by a closing div tag
2990 // $title is the title of the section (already translated)
2991 // $label is identifier used in the tag id's and sql columns
2992 // $buttonLabel is the button label text (already translated)
2993 // $buttonLink is the button link information
2994 // $buttonClass is any additional needed class elements for the button tag
2995 // $linkMethod is the button link method ('javascript' vs 'html')
2996 // $bodyClass is to set class(es) of the body
2997 // $auth is a flag to decide whether to show the button
2998 // $fixedWidth is to flag whether width is fixed
2999 // $forceExpandAlways is a flag to force the widget to always be expanded
3001 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
3002 if ($fixedWidth) {
3003 echo "<div class='section-header'>";
3005 else {
3006 echo "<div class='section-header-dynamic'>";
3008 echo "<table><tr>";
3009 if ($auth) {
3010 // show button, since authorized
3011 // first prepare class string
3012 if ($buttonClass) {
3013 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
3015 else {
3016 $class_string = "css_button_small";
3018 // next, create the link
3019 if ($linkMethod == "javascript") {
3020 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3022 else {
3023 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3024 if (!isset($_SESSION['patient_portal_onsite']) && !isset($_SESSION['patient_portal_onsite_two']) ) {
3025 // prevent an error from occuring when calling the function from the patient portal
3026 echo " onclick='top.restoreSession()'";
3029 echo "><span>" .
3030 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
3032 if ($forceExpandAlways){
3033 // Special case to force the widget to always be expanded
3034 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
3035 $indicatorTag ="style='display:none'";
3037 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3038 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3039 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
3040 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
3042 if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3043 // collapse all entries in the patient portal
3044 $text = xl('expand');
3046 else if (getUserSetting($label."_ps_expand")) {
3047 $text = xl('collapse');
3049 else {
3050 $text = xl('expand');
3052 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
3053 "</span>)</a></td>";
3054 echo "</tr></table>";
3055 echo "</div>";
3056 if ($forceExpandAlways) {
3057 // Special case to force the widget to always be expanded
3058 $styling = "";
3060 else if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3061 // collapse all entries in the patient portal
3062 $styling = "style='display:none'";
3064 else if (getUserSetting($label."_ps_expand")) {
3065 $styling = "";
3067 else {
3068 $styling = "style='display:none'";
3070 if ($bodyClass) {
3071 $styling .= " class='" . $bodyClass . "'";
3073 //next, create the first div tag to hold the information
3074 // note the code that calls this function will then place the ending div tag after the data
3075 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
3078 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3079 function billing_facility($name,$select){
3080 global $facilityService;
3082 $fres = $facilityService->getAllBillingLocations();
3083 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' class='form-control' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3084 foreach ($fres as $facrow) {
3085 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3086 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3088 echo "</select>";
3091 // Generic function to get the translated title value for a particular list option.
3093 function getListItemTitle($list, $option) {
3094 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3095 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3096 if (empty($row['title'])) return $option;
3097 return xl_list_label($row['title']);
3099 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3100 function getSmokeCodes()
3102 $smoking_codes_arr = array();
3103 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3104 while($codes_row = sqlFetchArray($smoking_codes))
3106 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3108 return $smoking_codes_arr;
3111 // Get the current value for a layout based form field.
3112 // Depending on options this might come from lbf_data, patient_data,
3113 // form_encounter, shared_attributes or elsewhere.
3114 // Returns FALSE if the field ID is invalid (layout error).
3116 function lbf_current_value($frow, $formid, $encounter) {
3117 global $pid;
3118 $formname = $frow['form_id'];
3119 $field_id = $frow['field_id'];
3120 $source = $frow['source'];
3121 $currvalue = '';
3122 $deffname = $formname . '_default_' . $field_id;
3123 if ($source == 'D' || $source == 'H') {
3124 // Get from patient_data, employer_data or history_data.
3125 if ($source == 'H') {
3126 $table = 'history_data';
3127 $orderby = 'ORDER BY date DESC LIMIT 1';
3129 else if (strpos($field_id, 'em_') === 0) {
3130 $field_id = substr($field_id, 3);
3131 $table = 'employer_data';
3132 $orderby = 'ORDER BY date DESC LIMIT 1';
3134 else {
3135 $table = 'patient_data';
3136 $orderby = '';
3138 // It is an error if the field does not exist, but don't crash.
3139 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3140 if (empty($tmp)) return FALSE;
3141 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3142 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3144 else if ($source == 'E') {
3145 if ($encounter) {
3146 // Get value from shared_attributes of the current encounter.
3147 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3148 "pid = ? AND encounter = ? AND field_id = ?",
3149 array($pid, $encounter, $field_id));
3150 if (isset($sarow)) $currvalue = $sarow['field_value'];
3152 else if ($formid) {
3153 // Get from shared_attributes of the encounter that this form is linked to.
3154 // Note the importance of having an index on forms.form_id.
3155 $sarow = sqlQuery("SELECT sa.field_value " .
3156 "FROM forms AS f, shared_attributes AS sa WHERE " .
3157 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3158 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3159 array($formid, $formname, $field_id));
3160 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3162 else {
3163 // New form and encounter not available, this should not happen.
3166 else if ($source == 'V') {
3167 if ($encounter) {
3168 // Get value from the current encounter's form_encounter.
3169 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3170 "pid = ? AND encounter = ?",
3171 array($pid, $encounter));
3172 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3174 else if ($formid) {
3175 // Get value from the form_encounter that this form is linked to.
3176 $ferow = sqlQuery("SELECT fe.* " .
3177 "FROM forms AS f, form_encounter AS fe WHERE " .
3178 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3179 "fe.pid = f.pid AND fe.encounter = f.encounter",
3180 array($formid, $formname));
3181 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3183 else {
3184 // New form and encounter not available, this should not happen.
3187 else if ($formid) {
3188 // This is a normal form field.
3189 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3190 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3191 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3193 else {
3194 // New form, see if there is a custom default from a plugin.
3195 // This logic does not apply to shared attributes because they do not
3196 // have a "new form" concept.
3197 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3199 return $currvalue;
3202 // This returns stuff that needs to go into the <head> section of a caller using
3203 // the drawable image field type in a form.
3204 // A TRUE argument makes the widget controls smaller.
3206 function lbf_canvas_head($small=TRUE) {
3207 $s = <<<EOD
3208 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3209 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3210 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3211 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3212 EOD;
3213 if ($small) $s .= <<<EOD
3214 <style>
3215 /* Custom LiterallyCanvas styling.
3216 * This makes the widget 25% less tall and adjusts some other things accordingly.
3218 .literally {
3219 min-height:100%;min-width:300px; /* Was 400, unspecified */
3221 .literally .lc-picker .toolbar-button {
3222 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3224 .literally .color-well {
3225 font-size:8px;width:49px; /* Was 10, 60 */
3227 .literally .color-well-color-container {
3228 width:21px;height:21px; /* Was 28, 28 */
3230 .literally .lc-picker {
3231 width:50px; /* Was 61 */
3233 .literally .lc-drawing.with-gui {
3234 left:50px; /* Was 61 */
3236 .literally .lc-options {
3237 left:50px; /* Was 61 */
3239 .literally .color-picker-popup {
3240 left:49px;bottom:0px; /* Was 60, 31 */
3242 </style>
3243 EOD;
3244 return $s;