fix for attendance form
[openemr.git] / library / options.inc.php
blob82b223f808469ecab5435d62be1377b6dc1bcad2
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 " name='form_$field_id_esc'" .
333 " id='form_$field_id_esc'" .
334 " size='$fldlength'" .
335 " $string_maxlength" .
336 " title='$description'" .
337 " value='$currescaped'";
338 $tmp = $lbfchange;
339 if (strpos($frow['edit_options'], 'C') !== FALSE)
340 $tmp .= "capitalizeMe(this);";
341 else if (strpos($frow['edit_options'], 'U') !== FALSE)
342 $tmp .= "this.value = this.value.toUpperCase();";
343 if ($tmp) echo " onchange='$tmp'";
344 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
345 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
346 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
347 echo " onblur='maskblur(this,\"$tmp\")'";
349 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
350 echo " readonly";
352 if ($disabled) echo ' disabled';
353 echo " />";
356 // long or multi-line text field
357 else if ($data_type == 3) {
358 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
359 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
360 echo "<textarea" .
361 " name='form_$field_id_esc'" .
362 " id='form_$field_id_esc'" .
363 " title='$description'" .
364 " cols='$textCols'" .
365 " rows='$textRows' $lbfonchange $disabled" .
366 ">" . $currescaped . "</textarea>";
369 // date
370 else if ($data_type == 4) {
371 $age_asof_date = ''; // optionalAge() sets this
372 $age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0;
373 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
374 if ($agestr) {
375 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
378 $onchange_string = '';
379 if (!$disabled && $agestr) {
380 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format)\"";
383 echo "<input type='text' size='10' class='datepicker' name='form_$field_id_esc' id='form_$field_id_esc'" .
384 " value='" . substr($currescaped, 0, 10) . "'";
385 if (!$agestr) echo " title='$description'";
386 echo " $onchange_string $lbfonchange $disabled />";
388 // Optional display of age or gestational age.
389 if ($agestr) {
390 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
394 // provider list, local providers only
395 else if ($data_type == 10) {
396 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
397 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
398 "AND authorized = 1 " .
399 "ORDER BY lname, fname");
400 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
401 echo "<option value=''>" . xlt($empty_title) . "</option>";
402 $got_selected = false;
403 while ($urow = sqlFetchArray($ures)) {
404 $uname = text($urow['fname'] . ' ' . $urow['lname']);
405 $optionId = attr($urow['id']);
406 echo "<option value='$optionId'";
407 if ($urow['id'] == $currvalue) {
408 echo " selected";
409 $got_selected = true;
411 echo ">$uname</option>";
413 if (!$got_selected && $currvalue) {
414 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
415 echo "</select>";
416 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
418 else {
419 echo "</select>";
423 // provider list, including address book entries with an NPI number
424 else if ($data_type == 11) {
425 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
426 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
427 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
428 "ORDER BY lname, fname");
429 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
430 echo " $lbfonchange $disabled>";
431 echo "<option value=''>" . xlt('Unassigned') . "</option>";
432 $got_selected = false;
433 while ($urow = sqlFetchArray($ures)) {
434 $uname = text($urow['fname'] . ' ' . $urow['lname']);
435 $optionId = attr($urow['id']);
436 echo "<option value='$optionId'";
437 if ($urow['id'] == $currvalue) {
438 echo " selected";
439 $got_selected = true;
441 echo ">$uname</option>";
443 if (!$got_selected && $currvalue) {
444 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
445 echo "</select>";
446 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
448 else {
449 echo "</select>";
453 // pharmacy list
454 else if ($data_type == 12) {
455 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
456 echo " $lbfonchange $disabled>";
457 echo "<option value='0'></option>";
458 $pres = get_pharmacies();
459 $got_selected = false;
460 while ($prow = sqlFetchArray($pres)) {
461 $key = $prow['id'];
462 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
463 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
464 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
465 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
466 echo "<option value='$optionValue'";
467 if ($currvalue == $key) {
468 echo " selected";
469 $got_selected = true;
471 echo ">$optionLabel</option>";
473 if (!$got_selected && $currvalue) {
474 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
475 echo "</select>";
476 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
478 else {
479 echo "</select>";
483 // squads
484 else if ($data_type == 13) {
485 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
486 echo " $lbfonchange $disabled>";
487 echo "<option value=''>&nbsp;</option>";
488 $squads = acl_get_squads();
489 if ($squads) {
490 foreach ($squads as $key => $value) {
491 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
492 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
493 echo "<option value='$optionValue'";
494 if ($currvalue == $key) echo " selected";
495 echo ">$optionLabel</option>\n";
498 echo "</select>";
501 // Address book, preferring organization name if it exists and is not in
502 // parentheses, and excluding local users who are not providers.
503 // Supports "referred to" practitioners and facilities.
504 // Alternatively the letter L in edit_options means that abook_type
505 // must be "ord_lab", indicating types used with the procedure
506 // lab ordering system.
507 // Alternatively the letter O in edit_options means that abook_type
508 // must begin with "ord_", indicating types used with the procedure
509 // ordering system.
510 // Alternatively the letter V in edit_options means that abook_type
511 // must be "vendor", indicating the Vendor type.
512 // Alternatively the letter R in edit_options means that abook_type
513 // must be "dist", indicating the Distributor type.
514 else if ($data_type == 14) {
515 if (strpos($frow['edit_options'], 'L') !== FALSE)
516 $tmp = "abook_type = 'ord_lab'";
517 else if (strpos($frow['edit_options'], 'O') !== FALSE)
518 $tmp = "abook_type LIKE 'ord\\_%'";
519 else if (strpos($frow['edit_options'], 'V') !== FALSE)
520 $tmp = "abook_type LIKE 'vendor%'";
521 else if (strpos($frow['edit_options'], 'R') !== FALSE)
522 $tmp = "abook_type LIKE 'dist'";
523 else
524 $tmp = "( username = '' OR authorized = 1 )";
525 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
526 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
527 "AND $tmp " .
528 "ORDER BY organization, lname, fname");
529 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
530 echo " $lbfonchange $disabled>";
531 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
532 while ($urow = sqlFetchArray($ures)) {
533 $uname = $urow['organization'];
534 if (empty($uname) || substr($uname, 0, 1) == '(') {
535 $uname = $urow['lname'];
536 if ($urow['fname']) $uname .= ", " . $urow['fname'];
538 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
539 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
540 echo "<option value='$optionValue'";
541 $title = $urow['username'] ? xl('Local') : xl('External');
542 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
543 echo " title='$optionTitle'";
544 if ($urow['id'] == $currvalue) echo " selected";
545 echo ">$optionLabel</option>";
547 echo "</select>";
550 // A billing code. If description matches an existing code type then that type is used.
551 else if ($data_type == 15) {
552 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
553 $maxlength = $frow['max_length'];
554 $string_maxlength = "";
555 // if max_length is set to zero, then do not set a maxlength
556 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
558 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
559 // Option "2" generates a hidden input for the codes, and a matching visible field
560 // displaying their descriptions. First step is computing the description string.
561 $currdescstring = '';
562 if (!empty($currvalue)) {
563 $relcodes = explode(';', $currvalue);
564 foreach ($relcodes as $codestring) {
565 if ($codestring === '') continue;
566 $code_text = lookup_code_descriptions($codestring);
567 if ($currdescstring !== '') $currdescstring .= '; ';
568 if (!empty($code_text)) {
569 $currdescstring .= $code_text;
571 else {
572 $currdescstring .= $codestring;
576 $currdescstring = attr($currdescstring);
578 echo "<input type='text'" .
579 " name='form_$field_id_esc'" .
580 " id='form_related_code'" .
581 " size='$fldlength'" .
582 " value='$currescaped'" .
583 " style='display:none'" .
584 " $lbfonchange readonly $disabled />";
585 // Extra readonly input field for optional display of code description(s).
586 echo "<input type='text'" .
587 " name='form_$field_id_esc" . "__desc'" .
588 " size='$fldlength'" .
589 " title='$description'" .
590 " value='$currdescstring'";
591 if (!$disabled) {
592 echo " onclick='sel_related(this,\"$codetype\")'";
594 echo " readonly $disabled />";
596 else {
597 echo "<input type='text'" .
598 " name='form_$field_id_esc'" .
599 " id='form_related_code'" .
600 " size='$fldlength'" .
601 " $string_maxlength" .
602 " title='$description'" .
603 " value='$currescaped'";
604 if (!$disabled) {
605 echo " onclick='sel_related(this,\"$codetype\")'";
607 echo " $lbfonchange readonly $disabled />";
611 // insurance company list
612 else if ($data_type == 16) {
613 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
614 echo "<option value='0'></option>";
615 $insprovs = getInsuranceProviders();
616 $got_selected = false;
617 foreach ($insprovs as $key => $ipname) {
618 $optionValue = htmlspecialchars($key, ENT_QUOTES);
619 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
620 echo "<option value='$optionValue'";
621 if ($currvalue == $key) {
622 echo " selected";
623 $got_selected = true;
625 echo ">$optionLabel</option>";
627 if (!$got_selected && $currvalue) {
628 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
629 echo "</select>";
630 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
632 else {
633 echo "</select>";
637 // issue types
638 else if ($data_type == 17) {
639 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
640 echo "<option value='0'></option>";
641 $got_selected = false;
642 foreach ($ISSUE_TYPES as $key => $value) {
643 $optionValue = htmlspecialchars($key, ENT_QUOTES);
644 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
645 echo "<option value='$optionValue'";
646 if ($currvalue == $key) {
647 echo " selected";
648 $got_selected = true;
650 echo ">$optionLabel</option>";
652 if (!$got_selected && strlen($currvalue) > 0) {
653 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
654 echo "</select>";
655 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
657 else {
658 echo "</select>";
662 // Visit categories.
663 else if ($data_type == 18) {
664 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
665 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
666 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
667 " $lbfonchange $disabled>";
668 echo "<option value=''>" . xlt($empty_title) . "</option>";
669 $got_selected = false;
670 while ($crow = sqlFetchArray($cres)) {
671 $catid = $crow['pc_catid'];
672 if (($catid < 9 && $catid != 5) || $catid == 11) continue;
673 echo "<option value='" . attr($catid) . "'";
674 if ($catid == $currvalue) {
675 echo " selected";
676 $got_selected = true;
678 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
680 if (!$got_selected && $currvalue) {
681 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
682 echo "</select>";
683 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
685 else {
686 echo "</select>";
690 // a set of labeled checkboxes
691 else if ($data_type == 21) {
692 // In this special case, fld_length is the number of columns generated.
693 $cols = max(1, $frow['fld_length']);
694 $avalue = explode('|', $currvalue);
695 $lres = sqlStatement("SELECT * FROM list_options " .
696 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
697 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
698 $tdpct = (int) (100 / $cols);
699 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
700 $option_id = $lrow['option_id'];
701 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
702 // if ($count) echo "<br />";
703 if ($count % $cols == 0) {
704 if ($count) echo "</tr>";
705 echo "<tr>";
707 echo "<td width='$tdpct%'>";
708 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
709 "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
710 if (in_array($option_id, $avalue)) echo " checked";
712 // Added 5-09 by BM - Translate label if applicable
713 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
715 echo "</td>";
717 if ($count) {
718 echo "</tr>";
719 if ($count > $cols) {
720 // Add some space after multiple rows of checkboxes.
721 $cols = htmlspecialchars( $cols, ENT_QUOTES);
722 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
725 echo "</table>";
728 // a set of labeled text input fields
729 else if ($data_type == 22) {
730 $tmp = explode('|', $currvalue);
731 $avalue = array();
732 foreach ($tmp as $value) {
733 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
734 $avalue[$matches[1]] = $matches[2];
737 $lres = sqlStatement("SELECT * FROM list_options " .
738 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
739 echo "<table cellpadding='0' cellspacing='0'>";
740 while ($lrow = sqlFetchArray($lres)) {
741 $option_id = $lrow['option_id'];
742 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
743 $maxlength = $frow['max_length'];
744 $string_maxlength = "";
745 // if max_length is set to zero, then do not set a maxlength
746 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
747 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
749 // Added 5-09 by BM - Translate label if applicable
750 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
751 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
752 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
753 echo "<td><input type='text'" .
754 " name='form_{$field_id_esc}[$option_id_esc]'" .
755 " id='form_{$field_id_esc}[$option_id_esc]'" .
756 " size='$fldlength'" .
757 " $string_maxlength" .
758 " value='$optionValue'";
759 echo " $lbfonchange $disabled /></td></tr>";
761 echo "</table>";
764 // a set of exam results; 3 radio buttons and a text field:
765 else if ($data_type == 23) {
766 $tmp = explode('|', $currvalue);
767 $avalue = array();
768 foreach ($tmp as $value) {
769 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
770 $avalue[$matches[1]] = $matches[2];
773 $maxlength = $frow['max_length'];
774 $string_maxlength = "";
775 // if max_length is set to zero, then do not set a maxlength
776 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
777 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
778 $lres = sqlStatement("SELECT * FROM list_options " .
779 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
780 echo "<table cellpadding='0' cellspacing='0'>";
781 echo "<tr><td>&nbsp;</td><td class='bold'>" .
782 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
783 "&nbsp;</td><td class='bold'>" .
784 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
785 "<td class='bold'>" .
786 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
787 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
788 while ($lrow = sqlFetchArray($lres)) {
789 $option_id = $lrow['option_id'];
790 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
791 $restype = substr($avalue[$option_id], 0, 1);
792 $resnote = substr($avalue[$option_id], 2);
794 // Added 5-09 by BM - Translate label if applicable
795 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
797 for ($i = 0; $i < 3; ++$i) {
798 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
799 echo "<td><input type='radio'" .
800 " name='radio_{$field_id_esc}[$option_id_esc]'" .
801 " id='radio_{$field_id_esc}[$option_id_esc]'" .
802 " value='$inputValue' $lbfonchange";
803 if ($restype === "$i") echo " checked";
804 echo " $disabled /></td>";
806 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
807 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
808 echo "<td><input type='text'" .
809 " name='form_{$field_id_esc}[$option_id_esc]'" .
810 " id='form_{$field_id_esc}[$option_id_esc]'" .
811 " size='$fldlength'" .
812 " $string_maxlength" .
813 " value='$resnote' $disabled /></td>";
814 echo "</tr>";
816 echo "</table>";
819 // the list of active allergies for the current patient
820 // this is read-only!
821 else if ($data_type == 24) {
822 $query = "SELECT title, comments FROM lists WHERE " .
823 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
824 "ORDER BY begdate";
825 // echo "<!-- $query -->\n"; // debugging
826 $lres = sqlStatement($query, array($GLOBALS['pid']));
827 $count = 0;
828 while ($lrow = sqlFetchArray($lres)) {
829 if ($count++) echo "<br />";
830 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
831 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
835 // a set of labeled checkboxes, each with a text field:
836 else if ($data_type == 25) {
837 $tmp = explode('|', $currvalue);
838 $avalue = array();
839 foreach ($tmp as $value) {
840 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
841 $avalue[$matches[1]] = $matches[2];
844 $maxlength = $frow['max_length'];
845 $string_maxlength = "";
846 // if max_length is set to zero, then do not set a maxlength
847 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
848 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
849 $lres = sqlStatement("SELECT * FROM list_options " .
850 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
851 echo "<table cellpadding='0' cellspacing='0'>";
852 while ($lrow = sqlFetchArray($lres)) {
853 $option_id = $lrow['option_id'];
854 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
855 $restype = substr($avalue[$option_id], 0, 1);
856 $resnote = substr($avalue[$option_id], 2);
858 // Added 5-09 by BM - Translate label if applicable
859 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
861 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
862 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
863 " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
864 if ($restype) echo " checked";
865 echo " $disabled />&nbsp;</td>";
866 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
867 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
868 echo "<td><input type='text'" .
869 " name='form_{$field_id_esc}[$option_id_esc]'" .
870 " id='form_{$field_id_esc}[$option_id_esc]'" .
871 " size='$fldlength'" .
872 " $string_maxlength" .
873 " value='$resnote' $disabled /></td>";
874 echo "</tr>";
876 echo "</table>";
879 // single-selection list with ability to add to it
880 else if ($data_type == 26) {
881 echo generate_select_list("form_$field_id", $list_id, $currvalue,
882 $description, ($showEmpty ? $empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
883 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
884 // show the add button if user has access to correct list
885 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
886 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
887 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
888 if (aco_exist('lists', $list_id)) {
889 // a specific aco exist for this list, so ensure access
890 if (acl_check('lists', $list_id)) echo $outputAddButton;
892 else {
893 // no specific aco exist for this list, so check for access to 'default' list
894 if (acl_check('lists', 'default')) echo $outputAddButton;
898 // a set of labeled radio buttons
899 else if ($data_type == 27) {
900 // In this special case, fld_length is the number of columns generated.
901 $cols = max(1, $frow['fld_length']);
902 $lres = sqlStatement("SELECT * FROM list_options " .
903 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
904 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
905 $tdpct = (int) (100 / $cols);
906 $got_selected = FALSE;
907 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
908 $option_id = $lrow['option_id'];
909 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
910 if ($count % $cols == 0) {
911 if ($count) echo "</tr>";
912 echo "<tr>";
914 echo "<td width='$tdpct%'>";
915 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
916 " value='$option_id_esc' $lbfonchange";
917 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
918 (strlen($currvalue) > 0 && $option_id == $currvalue))
920 echo " checked";
921 $got_selected = TRUE;
923 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
924 echo "</td>";
926 if ($count) {
927 echo "</tr>";
928 if ($count > $cols) {
929 // Add some space after multiple rows of radio buttons.
930 $cols = htmlspecialchars($cols, ENT_QUOTES);
931 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
934 echo "</table>";
935 if (!$got_selected && strlen($currvalue) > 0) {
936 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
937 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
938 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
942 // special case for history of lifestyle status; 3 radio buttons and a date text field:
943 // VicarePlus :: A selection list box for smoking status:
944 else if ($data_type == 28 || $data_type == 32) {
945 $tmp = explode('|', $currvalue);
946 switch(count($tmp)) {
947 case "4": {
948 $resnote = $tmp[0];
949 $restype = $tmp[1];
950 $resdate = $tmp[2];
951 $reslist = $tmp[3];
952 } break;
953 case "3": {
954 $resnote = $tmp[0];
955 $restype = $tmp[1];
956 $resdate = $tmp[2];
957 } break;
958 case "2": {
959 $resnote = $tmp[0];
960 $restype = $tmp[1];
961 $resdate = "";
962 } break;
963 case "1": {
964 $resnote = $tmp[0];
965 $resdate = $restype = "";
966 } break;
967 default: {
968 $restype = $resdate = $resnote = "";
969 } break;
971 $maxlength = $frow['max_length'];
972 $string_maxlength = "";
973 // if max_length is set to zero, then do not set a maxlength
974 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
975 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
977 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
978 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
979 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
980 echo "<table cellpadding='0' cellspacing='0'>";
981 echo "<tr>";
982 if ($data_type == 28)
984 // input text
985 echo "<td><input type='text'" .
986 " name='form_$field_id_esc'" .
987 " id='form_$field_id_esc'" .
988 " size='$fldlength'" .
989 " $string_maxlength" .
990 " value='$resnote' $disabled />&nbsp;</td>";
991 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
992 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
993 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
995 else if($data_type == 32)
997 // input text
998 echo "<tr><td><input type='text'" .
999 " name='form_text_$field_id_esc'" .
1000 " id='form_text_$field_id_esc'" .
1001 " size='$fldlength'" .
1002 " $string_maxlength" .
1003 " value='$resnote' $disabled />&nbsp;</td></tr>";
1004 echo "<td>";
1005 //Selection list for smoking status
1006 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1007 echo generate_select_list("form_$field_id", $list_id, $reslist,
1008 $description, ($showEmpty ? $empty_title : ''), '', $onchange, '',
1009 ($disabled ? array('disabled' => 'disabled') : null));
1010 echo "</td>";
1011 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1013 // current
1014 echo "<td class='text' ><input type='radio'" .
1015 " name='radio_{$field_id_esc}'" .
1016 " id='radio_{$field_id_esc}[current]'" .
1017 " value='current" . $field_id_esc . "' $lbfonchange";
1018 if ($restype == "current" . $field_id) echo " checked";
1019 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1020 echo " />" . xlt('Current') . "&nbsp;</td>";
1021 // quit
1022 echo "<td class='text'><input type='radio'" .
1023 " name='radio_{$field_id_esc}'" .
1024 " id='radio_{$field_id_esc}[quit]'" .
1025 " value='quit".$field_id_esc."' $lbfonchange";
1026 if ($restype == "quit" . $field_id) echo " checked";
1027 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1028 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1029 // quit date
1030 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1031 " value='$resdate'" .
1032 " title='$description'" .
1033 " $disabled />";
1034 echo "&nbsp;</td>";
1035 // never
1036 echo "<td class='text'><input type='radio'" .
1037 " name='radio_{$field_id_esc}'" .
1038 " id='radio_{$field_id_esc}[never]'" .
1039 " value='never" . $field_id_esc . "' $lbfonchange";
1040 if ($restype == "never" . $field_id) echo " checked";
1041 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1042 echo " />" . xlt('Never') . "&nbsp;</td>";
1043 // Not Applicable
1044 echo "<td class='text'><input type='radio'" .
1045 " name='radio_{$field_id}'" .
1046 " id='radio_{$field_id}[not_applicable]'" .
1047 " value='not_applicable" . $field_id . "' $lbfonchange";
1048 if ($restype == "not_applicable" . $field_id) echo " checked";
1049 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1050 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1052 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1053 echo "<td class='text' ><div id='smoke_code'></div></td>";
1054 echo "</tr>";
1055 echo "</table>";
1058 // static text. read-only, of course.
1059 else if ($data_type == 31) {
1060 echo nl2br($frow['description']);
1063 //$data_type == 33
1064 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1065 //$data_type == 33
1067 else if($data_type == 34){
1068 $arr = explode("|*|*|*|",$currvalue);
1069 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;'>";
1070 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
1071 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1072 echo "</a>";
1075 //facilities drop-down list
1076 else if ($data_type == 35) {
1077 if (empty($currvalue)){
1078 $currvalue = 0;
1080 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1081 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1084 //multiple select
1085 // supports backup list
1086 else if ($data_type == 36) {
1087 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1088 $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);
1092 // Canvas and related elements for browser-side image drawing.
1093 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1094 else if ($data_type == 40) {
1095 // Unlike other field types, width and height are in pixels.
1096 $canWidth = intval($frow['fld_length']);
1097 $canHeight = intval($frow['fld_rows']);
1098 if (empty($currvalue)) {
1099 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1100 // If defined this is the filename of the default starting image.
1101 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1104 $mywidth = 50 + ($canWidth > 250 ? $canWidth : 250);
1105 $myheight = 31 + ($canHeight > 261 ? $canHeight : 261);
1106 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1107 // Hidden form field exists to send updated data to the server at submit time.
1108 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1109 // Hidden image exists to support initialization of the canvas.
1110 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1111 // $date_init is a misnomer but it's the place for browser-side setup logic.
1112 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1117 function generate_print_field($frow, $currvalue) {
1118 global $rootdir, $date_init, $ISSUE_TYPES;
1120 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1122 $data_type = $frow['data_type'];
1123 $field_id = $frow['field_id'];
1124 $list_id = $frow['list_id'];
1125 $fld_length = $frow['fld_length'];
1126 $backup_list = $frow['list_backup_id'];
1128 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1130 // Can pass $frow['empty_title'] with this variable, otherwise
1131 // will default to 'Unassigned'.
1132 // If it is 'SKIP' then an empty text title is completely skipped.
1133 $showEmpty = true;
1134 if (isset($frow['empty_title'])) {
1135 if ($frow['empty_title'] == "SKIP") {
1136 //do not display an 'empty' choice
1137 $showEmpty = false;
1138 $empty_title = "Unassigned";
1140 else {
1141 $empty_title = $frow['empty_title'];
1144 else {
1145 $empty_title = "Unassigned";
1148 // generic single-selection list
1149 // Supports backup lists.
1150 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
1151 if (empty($fld_length)) {
1152 if ($list_id == 'titles') {
1153 $fld_length = 3;
1154 } else {
1155 $fld_length = 10;
1158 $tmp = '';
1159 if ($currvalue) {
1160 $lrow = sqlQuery("SELECT title FROM list_options " .
1161 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1162 $tmp = xl_list_label($lrow['title']);
1163 if ($lrow == 0 && !empty($backup_list)) {
1164 // since primary list did not map, try to map to backup list
1165 $lrow = sqlQuery("SELECT title FROM list_options " .
1166 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1167 $tmp = xl_list_label($lrow['title']);
1169 if (empty($tmp)) $tmp = "($currvalue)";
1171 /*****************************************************************
1172 echo "<input type='text'" .
1173 " size='$fld_length'" .
1174 " value='$tmp'" .
1175 " class='under'" .
1176 " />";
1177 *****************************************************************/
1178 if ($tmp === '') {
1179 $tmp = '&nbsp;';
1181 else {
1182 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1184 echo $tmp;
1187 // simple text field
1188 else if ($data_type == 2 || $data_type == 15) {
1189 /*****************************************************************
1190 echo "<input type='text'" .
1191 " size='$fld_length'" .
1192 " value='$currescaped'" .
1193 " class='under'" .
1194 " />";
1195 *****************************************************************/
1196 if ($currescaped === '') $currescaped = '&nbsp;';
1197 echo $currescaped;
1200 // long or multi-line text field
1201 else if ($data_type == 3) {
1202 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
1203 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
1204 echo "<textarea" .
1205 " cols='$fldlength'" .
1206 " rows='$maxlength'>" .
1207 $currescaped . "</textarea>";
1210 // date
1211 else if ($data_type == 4) {
1212 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1213 $agestr = optionalAge($frow, $currvalue,$asof);
1214 if ($agestr) {
1215 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1217 if ($currvalue === '') {
1218 echo '&nbsp;';
1220 else {
1221 echo text(oeFormatShortDate($currvalue));
1223 // Optional display of age or gestational age.
1224 if ($agestr) {
1225 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1229 // provider list
1230 else if ($data_type == 10 || $data_type == 11) {
1231 $tmp = '';
1232 if ($currvalue) {
1233 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1234 "WHERE id = ?", array($currvalue) );
1235 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1236 if (empty($tmp)) $tmp = "($currvalue)";
1238 /*****************************************************************
1239 echo "<input type='text'" .
1240 " size='$fld_length'" .
1241 " value='$tmp'" .
1242 " class='under'" .
1243 " />";
1244 *****************************************************************/
1245 if ($tmp === '') { $tmp = '&nbsp;'; }
1246 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1247 echo $tmp;
1250 // pharmacy list
1251 else if ($data_type == 12) {
1252 $tmp = '';
1253 if ($currvalue) {
1254 $pres = get_pharmacies();
1255 while ($prow = sqlFetchArray($pres)) {
1256 $key = $prow['id'];
1257 if ($currvalue == $key) {
1258 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1259 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1260 $prow['line1'] . ' / ' . $prow['city'];
1263 if (empty($tmp)) $tmp = "($currvalue)";
1265 /*****************************************************************
1266 echo "<input type='text'" .
1267 " size='$fld_length'" .
1268 " value='$tmp'" .
1269 " class='under'" .
1270 " />";
1271 *****************************************************************/
1272 if ($tmp === '') { $tmp = '&nbsp;'; }
1273 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1274 echo $tmp;
1277 // squads
1278 else if ($data_type == 13) {
1279 $tmp = '';
1280 if ($currvalue) {
1281 $squads = acl_get_squads();
1282 if ($squads) {
1283 foreach ($squads as $key => $value) {
1284 if ($currvalue == $key) {
1285 $tmp = $value[3];
1289 if (empty($tmp)) $tmp = "($currvalue)";
1291 /*****************************************************************
1292 echo "<input type='text'" .
1293 " size='$fld_length'" .
1294 " value='$tmp'" .
1295 " class='under'" .
1296 " />";
1297 *****************************************************************/
1298 if ($tmp === '') { $tmp = '&nbsp;'; }
1299 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1300 echo $tmp;
1303 // Address book.
1304 else if ($data_type == 14) {
1305 $tmp = '';
1306 if ($currvalue) {
1307 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1308 "WHERE id = ?", array($currvalue) );
1309 $uname = $urow['lname'];
1310 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1311 $tmp = $uname;
1312 if (empty($tmp)) $tmp = "($currvalue)";
1314 /*****************************************************************
1315 echo "<input type='text'" .
1316 " size='$fld_length'" .
1317 " value='$tmp'" .
1318 " class='under'" .
1319 " />";
1320 *****************************************************************/
1321 if ($tmp === '') { $tmp = '&nbsp;'; }
1322 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1323 echo $tmp;
1326 // insurance company list
1327 else if ($data_type == 16) {
1328 $tmp = '';
1329 if ($currvalue) {
1330 $insprovs = getInsuranceProviders();
1331 foreach ($insprovs as $key => $ipname) {
1332 if ($currvalue == $key) {
1333 $tmp = $ipname;
1336 if (empty($tmp)) $tmp = "($currvalue)";
1338 if ($tmp === '') $tmp = '&nbsp;';
1339 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1340 echo $tmp;
1343 // issue types
1344 else if ($data_type == 17) {
1345 $tmp = '';
1346 if ($currvalue) {
1347 foreach ($ISSUE_TYPES as $key => $value) {
1348 if ($currvalue == $key) {
1349 $tmp = $value[1];
1352 if (empty($tmp)) $tmp = "($currvalue)";
1354 if ($tmp === '') $tmp = '&nbsp;';
1355 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1356 echo $tmp;
1359 // Visit categories.
1360 else if ($data_type == 18) {
1361 $tmp = '';
1362 if ($currvalue) {
1363 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1364 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1365 array($currvalue));
1366 $tmp = xl_appt_category($crow['pc_catname']);
1367 if (empty($tmp)) $tmp = "($currvalue)";
1369 if ($tmp === '') { $tmp = '&nbsp;'; }
1370 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES); }
1371 echo $tmp;
1374 // a set of labeled checkboxes
1375 else if ($data_type == 21) {
1376 // In this special case, fld_length is the number of columns generated.
1377 $cols = max(1, $fld_length);
1378 $avalue = explode('|', $currvalue);
1379 $lres = sqlStatement("SELECT * FROM list_options " .
1380 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1381 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1382 $tdpct = (int) (100 / $cols);
1383 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1384 $option_id = $lrow['option_id'];
1385 if ($count % $cols == 0) {
1386 if ($count) echo "</tr>";
1387 echo "<tr>";
1389 echo "<td width='$tdpct%'>";
1390 echo "<input type='checkbox'";
1391 if (in_array($option_id, $avalue)) echo " checked";
1392 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1393 echo "</td>";
1395 if ($count) {
1396 echo "</tr>";
1397 if ($count > $cols) {
1398 // Add some space after multiple rows of checkboxes.
1399 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1400 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1403 echo "</table>";
1406 // a set of labeled text input fields
1407 else if ($data_type == 22) {
1408 $tmp = explode('|', $currvalue);
1409 $avalue = array();
1410 foreach ($tmp as $value) {
1411 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1412 $avalue[$matches[1]] = $matches[2];
1415 $lres = sqlStatement("SELECT * FROM list_options " .
1416 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1417 echo "<table cellpadding='0' cellspacing='0'>";
1418 while ($lrow = sqlFetchArray($lres)) {
1419 $option_id = $lrow['option_id'];
1420 $fldlength = empty($fld_length) ? 20 : $fld_length;
1421 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1422 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1423 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1424 echo "<td><input type='text'" .
1425 " size='$fldlength'" .
1426 " value='$inputValue'" .
1427 " class='under'" .
1428 " /></td></tr>";
1430 echo "</table>";
1433 // a set of exam results; 3 radio buttons and a text field:
1434 else if ($data_type == 23) {
1435 $tmp = explode('|', $currvalue);
1436 $avalue = array();
1437 foreach ($tmp as $value) {
1438 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1439 $avalue[$matches[1]] = $matches[2];
1442 $fldlength = empty($fld_length) ? 20 : $fld_length;
1443 $lres = sqlStatement("SELECT * FROM list_options " .
1444 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1445 echo "<table cellpadding='0' cellspacing='0'>";
1446 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1447 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1448 "&nbsp;</td><td class='bold'>" .
1449 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1450 "<td class='bold'>" .
1451 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1452 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1453 while ($lrow = sqlFetchArray($lres)) {
1454 $option_id = $lrow['option_id'];
1455 $restype = substr($avalue[$option_id], 0, 1);
1456 $resnote = substr($avalue[$option_id], 2);
1457 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1458 for ($i = 0; $i < 3; ++$i) {
1459 echo "<td><input type='radio'";
1460 if ($restype === "$i") echo " checked";
1461 echo " /></td>";
1463 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1464 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1465 echo "<td><input type='text'" .
1466 " size='$fldlength'" .
1467 " value='$resnote'" .
1468 " class='under' /></td>" .
1469 "</tr>";
1471 echo "</table>";
1474 // the list of active allergies for the current patient
1475 // this is read-only!
1476 else if ($data_type == 24) {
1477 $query = "SELECT title, comments FROM lists WHERE " .
1478 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1479 "ORDER BY begdate";
1480 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1481 $count = 0;
1482 while ($lrow = sqlFetchArray($lres)) {
1483 if ($count++) echo "<br />";
1484 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1485 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1489 // a set of labeled checkboxes, each with a text field:
1490 else if ($data_type == 25) {
1491 $tmp = explode('|', $currvalue);
1492 $avalue = array();
1493 foreach ($tmp as $value) {
1494 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1495 $avalue[$matches[1]] = $matches[2];
1498 $fldlength = empty($fld_length) ? 20 : $fld_length;
1499 $lres = sqlStatement("SELECT * FROM list_options " .
1500 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1501 echo "<table cellpadding='0' cellspacing='0'>";
1502 while ($lrow = sqlFetchArray($lres)) {
1503 $option_id = $lrow['option_id'];
1504 $restype = substr($avalue[$option_id], 0, 1);
1505 $resnote = substr($avalue[$option_id], 2);
1506 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1507 echo "<td><input type='checkbox'";
1508 if ($restype) echo " checked";
1509 echo " />&nbsp;</td>";
1510 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1511 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1512 echo "<td><input type='text'" .
1513 " size='$fldlength'" .
1514 " value='$resnote'" .
1515 " class='under'" .
1516 " /></td>" .
1517 "</tr>";
1519 echo "</table>";
1522 // a set of labeled radio buttons
1523 else if ($data_type == 27) {
1524 // In this special case, fld_length is the number of columns generated.
1525 $cols = max(1, $frow['fld_length']);
1526 $lres = sqlStatement("SELECT * FROM list_options " .
1527 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1528 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1529 $tdpct = (int) (100 / $cols);
1530 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1531 $option_id = $lrow['option_id'];
1532 if ($count % $cols == 0) {
1533 if ($count) echo "</tr>";
1534 echo "<tr>";
1536 echo "<td width='$tdpct%'>";
1537 echo "<input type='radio'";
1538 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1539 (strlen($currvalue) > 0 && $option_id == $currvalue))
1541 echo " checked";
1543 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1544 echo "</td>";
1546 if ($count) {
1547 echo "</tr>";
1548 if ($count > $cols) {
1549 // Add some space after multiple rows of radio buttons.
1550 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1551 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1554 echo "</table>";
1557 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1558 else if ($data_type == 28 || $data_type == 32) {
1559 $tmp = explode('|', $currvalue);
1560 switch(count($tmp)) {
1561 case "4": {
1562 $resnote = $tmp[0];
1563 $restype = $tmp[1];
1564 $resdate = $tmp[2];
1565 $reslist = $tmp[3];
1566 } break;
1567 case "3": {
1568 $resnote = $tmp[0];
1569 $restype = $tmp[1];
1570 $resdate = $tmp[2];
1571 } break;
1572 case "2": {
1573 $resnote = $tmp[0];
1574 $restype = $tmp[1];
1575 $resdate = "";
1576 } break;
1577 case "1": {
1578 $resnote = $tmp[0];
1579 $resdate = $restype = "";
1580 } break;
1581 default: {
1582 $restype = $resdate = $resnote = "";
1583 } break;
1585 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1586 echo "<table cellpadding='0' cellspacing='0'>";
1587 echo "<tr>";
1588 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1589 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1590 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1591 if($data_type == 28)
1593 echo "<td><input type='text'" .
1594 " size='$fldlength'" .
1595 " class='under'" .
1596 " value='$resnote' /></td>";
1597 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1598 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1599 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1601 else if($data_type == 32)
1603 echo "<tr><td><input type='text'" .
1604 " size='$fldlength'" .
1605 " class='under'" .
1606 " value='$resnote' /></td></tr>";
1607 $fldlength = 30;
1608 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1609 echo "<td><input type='text'" .
1610 " size='$fldlength'" .
1611 " class='under'" .
1612 " value='$smoking_status_title' /></td>";
1613 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1615 echo "<td><input type='radio'";
1616 if ($restype == "current".$field_id) echo " checked";
1617 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1619 echo "<td><input type='radio'";
1620 if ($restype == "current".$field_id) echo " checked";
1621 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1623 echo "<td><input type='text' size='6'" .
1624 " value='$resdate'" .
1625 " class='under'" .
1626 " /></td>";
1628 echo "<td><input type='radio'";
1629 if ($restype == "current".$field_id) echo " checked";
1630 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1632 echo "<td><input type='radio'";
1633 if ($restype == "not_applicable".$field_id) echo " checked";
1634 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1635 echo "</tr>";
1636 echo "</table>";
1639 // static text. read-only, of course.
1640 else if ($data_type == 31) {
1641 echo nl2br($frow['description']);
1644 else if($data_type == 34){
1645 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;'>";
1646 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1647 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1648 echo "</a>";
1651 //facilities drop-down list
1652 else if ($data_type == 35) {
1653 if (empty($currvalue)){
1654 $currvalue = 0;
1656 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1659 //Multi-select
1660 // Supports backup lists.
1661 else if ($data_type == 36) {
1662 if (empty($fld_length)) {
1663 if ($list_id == 'titles') {
1664 $fld_length = 3;
1665 } else {
1666 $fld_length = 10;
1669 $tmp = '';
1671 $values_array = explode("|", $currvalue);
1673 $i=0;
1674 foreach($values_array as $value) {
1675 if ($value) {
1676 $lrow = sqlQuery("SELECT title FROM list_options " .
1677 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1678 $tmp = xl_list_label($lrow['title']);
1679 if ($lrow == 0 && !empty($backup_list)) {
1680 // since primary list did not map, try to map to backup list
1681 $lrow = sqlQuery("SELECT title FROM list_options " .
1682 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1683 $tmp = xl_list_label($lrow['title']);
1685 if (empty($tmp)) $tmp = "($value)";
1688 if ($tmp === '') {
1689 $tmp = '&nbsp;';
1691 else {
1692 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1694 if ($i != 0 && $tmp != '&nbsp;') echo ",";
1695 echo $tmp;
1696 $i++;
1700 // Image from canvas drawing
1701 else if ($data_type == 40) {
1702 echo "<img src='" . attr($currvalue) . "'>";
1707 function generate_display_field($frow, $currvalue) {
1708 global $ISSUE_TYPES, $facilityService;
1710 $data_type = $frow['data_type'];
1711 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1712 $list_id = $frow['list_id'];
1713 $backup_list = isset($frow['list_backup_id']) ? $frow['list_backup_id'] : null;
1715 $s = '';
1717 // generic selection list or the generic selection list with add on the fly
1718 // feature, or radio buttons
1719 // Supports backup lists for datatypes 1,26,33
1720 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1721 $lrow = sqlQuery("SELECT title FROM list_options " .
1722 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
1723 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1724 //if there is no matching value in the corresponding lists check backup list
1725 // only supported in data types 1,26,33
1726 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1727 $lrow = sqlQuery("SELECT title FROM list_options " .
1728 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
1729 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1733 // simple text field
1734 else if ($data_type == 2) {
1735 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1738 // long or multi-line text field
1739 else if ($data_type == 3) {
1740 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1743 // date
1744 else if ($data_type == 4) {
1745 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1746 $s = '';
1747 $agestr = optionalAge($frow, $currvalue, $asof);
1748 if ($agestr) {
1749 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1751 if ($currvalue === '') {
1752 $s .= '&nbsp;';
1754 else {
1755 $s .= text(oeFormatShortDate($currvalue));
1757 // Optional display of age or gestational age.
1758 if ($agestr) {
1759 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1763 // provider
1764 else if ($data_type == 10 || $data_type == 11) {
1765 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1766 "WHERE id = ?", array($currvalue) );
1767 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1770 // pharmacy list
1771 else if ($data_type == 12) {
1772 $pres = get_pharmacies();
1773 while ($prow = sqlFetchArray($pres)) {
1774 $key = $prow['id'];
1775 if ($currvalue == $key) {
1776 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1777 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1778 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1783 // squads
1784 else if ($data_type == 13) {
1785 $squads = acl_get_squads();
1786 if ($squads) {
1787 foreach ($squads as $key => $value) {
1788 if ($currvalue == $key) {
1789 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1795 // address book
1796 else if ($data_type == 14) {
1797 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
1798 "WHERE id = ?", array($currvalue));
1799 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
1800 if($urow['organization'] !=""){
1801 $uname = $urow['organization'];
1802 }else{
1803 $uname = $urow['lname'];
1804 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1806 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1809 // billing code
1810 else if ($data_type == 15) {
1811 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1814 // insurance company list
1815 else if ($data_type == 16) {
1816 $insprovs = getInsuranceProviders();
1817 foreach ($insprovs as $key => $ipname) {
1818 if ($currvalue == $key) {
1819 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
1824 // issue types
1825 else if ($data_type == 17) {
1826 foreach ($ISSUE_TYPES as $key => $value) {
1827 if ($currvalue == $key) {
1828 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
1833 // visit category
1834 else if ($data_type == 18) {
1835 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1836 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1837 array($currvalue));
1838 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES);
1841 // a set of labeled checkboxes
1842 else if ($data_type == 21) {
1843 $avalue = explode('|', $currvalue);
1844 $lres = sqlStatement("SELECT * FROM list_options " .
1845 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1846 $count = 0;
1847 while ($lrow = sqlFetchArray($lres)) {
1848 $option_id = $lrow['option_id'];
1849 if (in_array($option_id, $avalue)) {
1850 if ($count++) $s .= "<br />";
1852 // Added 5-09 by BM - Translate label if applicable
1853 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES);
1859 // a set of labeled text input fields
1860 else if ($data_type == 22) {
1861 $tmp = explode('|', $currvalue);
1862 $avalue = array();
1863 foreach ($tmp as $value) {
1864 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1865 $avalue[$matches[1]] = $matches[2];
1868 $lres = sqlStatement("SELECT * FROM list_options " .
1869 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1870 $s .= "<table cellpadding='0' cellspacing='0'>";
1871 while ($lrow = sqlFetchArray($lres)) {
1872 $option_id = $lrow['option_id'];
1873 if (empty($avalue[$option_id])) continue;
1875 // Added 5-09 by BM - Translate label if applicable
1876 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1878 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1880 $s .= "</table>";
1883 // a set of exam results; 3 radio buttons and a text field:
1884 else if ($data_type == 23) {
1885 $tmp = explode('|', $currvalue);
1886 $avalue = array();
1887 foreach ($tmp as $value) {
1888 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1889 $avalue[$matches[1]] = $matches[2];
1892 $lres = sqlStatement("SELECT * FROM list_options " .
1893 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1894 $s .= "<table cellpadding='0' cellspacing='0'>";
1895 while ($lrow = sqlFetchArray($lres)) {
1896 $option_id = $lrow['option_id'];
1897 $restype = substr($avalue[$option_id], 0, 1);
1898 $resnote = substr($avalue[$option_id], 2);
1899 if (empty($restype) && empty($resnote)) continue;
1901 // Added 5-09 by BM - Translate label if applicable
1902 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1904 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1905 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1906 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1907 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1908 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1909 $s .= "</tr>";
1911 $s .= "</table>";
1914 // the list of active allergies for the current patient
1915 else if ($data_type == 24) {
1916 $query = "SELECT title, comments FROM lists WHERE " .
1917 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1918 "ORDER BY begdate";
1919 // echo "<!-- $query -->\n"; // debugging
1920 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1921 $count = 0;
1922 while ($lrow = sqlFetchArray($lres)) {
1923 if ($count++) $s .= "<br />";
1924 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1925 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1929 // a set of labeled checkboxes, each with a text field:
1930 else if ($data_type == 25) {
1931 $tmp = explode('|', $currvalue);
1932 $avalue = array();
1933 foreach ($tmp as $value) {
1934 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1935 $avalue[$matches[1]] = $matches[2];
1938 $lres = sqlStatement("SELECT * FROM list_options " .
1939 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1940 $s .= "<table cellpadding='0' cellspacing='0'>";
1941 while ($lrow = sqlFetchArray($lres)) {
1942 $option_id = $lrow['option_id'];
1943 $restype = substr($avalue[$option_id], 0, 1);
1944 $resnote = substr($avalue[$option_id], 2);
1945 if (empty($restype) && empty($resnote)) continue;
1947 // Added 5-09 by BM - Translate label if applicable
1948 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1950 $restype = $restype ? xl('Yes') : xl('No');
1951 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1952 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1953 $s .= "</tr>";
1955 $s .= "</table>";
1958 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1959 // VicarePlus :: A selection list for smoking status.
1960 else if ($data_type == 28 || $data_type == 32) {
1961 $tmp = explode('|', $currvalue);
1962 switch(count($tmp)) {
1963 case "4": {
1964 $resnote = $tmp[0];
1965 $restype = $tmp[1];
1966 $resdate = $tmp[2];
1967 $reslist = $tmp[3];
1968 } break;
1969 case "3": {
1970 $resnote = $tmp[0];
1971 $restype = $tmp[1];
1972 $resdate = $tmp[2];
1973 } break;
1974 case "2": {
1975 $resnote = $tmp[0];
1976 $restype = $tmp[1];
1977 $resdate = "";
1978 } break;
1979 case "1": {
1980 $resnote = $tmp[0];
1981 $resdate = $restype = "";
1982 } break;
1983 default: {
1984 $restype = $resdate = $resnote = "";
1985 } break;
1987 $s .= "<table cellpadding='0' cellspacing='0'>";
1989 $s .= "<tr>";
1990 $res = "";
1991 if ($restype == "current".$field_id) $res = xl('Current');
1992 if ($restype == "quit".$field_id) $res = xl('Quit');
1993 if ($restype == "never".$field_id) $res = xl('Never');
1994 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1995 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1996 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1997 if ($data_type == 28)
1999 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2001 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2002 else if ($data_type == 32)
2003 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2004 $smoke_codes = getSmokeCodes();
2005 if (!empty($reslist)) {
2006 if($smoke_codes[$reslist]!="")
2007 $code_desc = "( ".$smoke_codes[$reslist]." )";
2009 $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>";}
2011 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2014 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
2015 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
2016 $s .= "</tr>";
2017 $s .= "</table>";
2020 // static text. read-only, of course.
2021 else if ($data_type == 31) {
2022 $s .= nl2br($frow['description']);
2025 else if($data_type == 34){
2026 $arr = explode("|*|*|*|",$currvalue);
2027 for($i=0;$i<sizeof($arr);$i++){
2028 $s.=$arr[$i];
2032 // facility
2033 else if ($data_type == 35) {
2034 $urow = $facilityService->getById($currvalue);
2035 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
2038 // Multi select
2039 // Supports backup lists
2040 else if ($data_type == 36) {
2041 $values_array = explode("|", $currvalue);
2042 $i = 0;
2043 foreach($values_array as $value) {
2044 $lrow = sqlQuery("SELECT title FROM list_options " .
2045 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2046 if ($lrow == 0 && !empty($backup_list)) {
2047 //use back up list
2048 $lrow = sqlQuery("SELECT title FROM list_options " .
2049 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2051 if ($i > 0) {
2052 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2053 } else {
2054 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2056 $i++;
2060 // Image from canvas drawing
2061 else if ($data_type == 40) {
2062 $s .= "<img src='" . attr($currvalue) . "'>";
2065 return $s;
2068 // Generate plain text versions of selected LBF field types.
2069 // Currently used by interface/patient_file/download_template.php.
2070 // More field types might need to be supported here in the future.
2072 function generate_plaintext_field($frow, $currvalue) {
2073 global $ISSUE_TYPES;
2075 $data_type = $frow['data_type'];
2076 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2077 $list_id = $frow['list_id'];
2078 $backup_list = $frow['backup_list'];
2079 $s = '';
2081 // generic selection list or the generic selection list with add on the fly
2082 // feature, or radio buttons
2083 // Supports backup lists (for datatypes 1,26,33)
2084 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2085 $lrow = sqlQuery("SELECT title FROM list_options " .
2086 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
2087 $s = xl_list_label($lrow['title']);
2088 //if there is no matching value in the corresponding lists check backup list
2089 // only supported in data types 1,26,33
2090 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2091 $lrow = sqlQuery("SELECT title FROM list_options " .
2092 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
2093 $s = xl_list_label($lrow['title']);
2097 // simple or long text field
2098 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2099 $s = $currvalue;
2102 // date
2103 else if ($data_type == 4) {
2104 $s = oeFormatShortDate($currvalue);
2105 // Optional display of age or gestational age.
2106 $asof=''; //not used here, but set to prevent a php warning when call optionalAge
2107 $tmp = optionalAge($frow, $currvalue,$asof);
2108 if ($tmp) $s .= ' ' . $tmp;
2111 // provider
2112 else if ($data_type == 10 || $data_type == 11) {
2113 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2114 "WHERE id = ?", array($currvalue) );
2115 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2118 // pharmacy list
2119 else if ($data_type == 12) {
2120 $pres = get_pharmacies();
2121 while ($prow = sqlFetchArray($pres)) {
2122 $key = $prow['id'];
2123 if ($currvalue == $key) {
2124 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2125 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2126 $prow['line1'] . ' / ' . $prow['city'];
2131 // address book
2132 else if ($data_type == 14) {
2133 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2134 "WHERE id = ?", array($currvalue));
2135 $uname = $urow['lname'];
2136 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2137 $s = $uname;
2140 // insurance company list
2141 else if ($data_type == 16) {
2142 $insprovs = getInsuranceProviders();
2143 foreach ($insprovs as $key => $ipname) {
2144 if ($currvalue == $key) {
2145 $s .= $ipname;
2150 // issue type
2151 else if ($data_type == 17) {
2152 foreach ($ISSUE_TYPES as $key => $value) {
2153 if ($currvalue == $key) {
2154 $s .= $value[1];
2159 // visit category
2160 else if ($data_type == 18) {
2161 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2162 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2163 array($currvalue));
2164 $s = $crow['pc_catname'];
2167 // a set of labeled checkboxes
2168 else if ($data_type == 21) {
2169 $avalue = explode('|', $currvalue);
2170 $lres = sqlStatement("SELECT * FROM list_options " .
2171 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2172 $count = 0;
2173 while ($lrow = sqlFetchArray($lres)) {
2174 $option_id = $lrow['option_id'];
2175 if (in_array($option_id, $avalue)) {
2176 if ($count++) $s .= "; ";
2177 $s .= xl_list_label($lrow['title']);
2182 // a set of labeled text input fields
2183 else if ($data_type == 22) {
2184 $tmp = explode('|', $currvalue);
2185 $avalue = array();
2186 foreach ($tmp as $value) {
2187 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2188 $avalue[$matches[1]] = $matches[2];
2191 $lres = sqlStatement("SELECT * FROM list_options " .
2192 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2193 while ($lrow = sqlFetchArray($lres)) {
2194 $option_id = $lrow['option_id'];
2195 if (empty($avalue[$option_id])) continue;
2196 if ($s !== '') $s .= '; ';
2197 $s .= xl_list_label($lrow['title']) . ': ';
2198 $s .= $avalue[$option_id];
2202 // A set of exam results; 3 radio buttons and a text field.
2203 // This shows abnormal results only.
2204 else if ($data_type == 23) {
2205 $tmp = explode('|', $currvalue);
2206 $avalue = array();
2207 foreach ($tmp as $value) {
2208 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2209 $avalue[$matches[1]] = $matches[2];
2212 $lres = sqlStatement("SELECT * FROM list_options " .
2213 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2214 while ($lrow = sqlFetchArray($lres)) {
2215 $option_id = $lrow['option_id'];
2216 $restype = substr($avalue[$option_id], 0, 1);
2217 $resnote = substr($avalue[$option_id], 2);
2218 if (empty($restype) && empty($resnote)) continue;
2219 if ($restype != '2') continue; // show abnormal results only
2220 if ($s !== '') $s .= '; ';
2221 $s .= xl_list_label($lrow['title']);
2222 if (!empty($resnote)) $s .= ': ' . $resnote;
2226 // the list of active allergies for the current patient
2227 else if ($data_type == 24) {
2228 $query = "SELECT title, comments FROM lists WHERE " .
2229 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2230 "ORDER BY begdate";
2231 $lres = sqlStatement($query, array($GLOBALS['pid']));
2232 $count = 0;
2233 while ($lrow = sqlFetchArray($lres)) {
2234 if ($count++) $s .= "; ";
2235 $s .= $lrow['title'];
2236 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2240 // a set of labeled checkboxes, each with a text field:
2241 else if ($data_type == 25) {
2242 $tmp = explode('|', $currvalue);
2243 $avalue = array();
2244 foreach ($tmp as $value) {
2245 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2246 $avalue[$matches[1]] = $matches[2];
2249 $lres = sqlStatement("SELECT * FROM list_options " .
2250 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2251 while ($lrow = sqlFetchArray($lres)) {
2252 $option_id = $lrow['option_id'];
2253 $restype = substr($avalue[$option_id], 0, 1);
2254 $resnote = substr($avalue[$option_id], 2);
2255 if (empty($restype) && empty($resnote)) continue;
2256 if ($s !== '') $s .= '; ';
2257 $s .= xl_list_label($lrow['title']);
2258 $restype = $restype ? xl('Yes') : xl('No');
2259 $s .= $restype;
2260 if ($resnote) $s .= ' ' . $resnote;
2264 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2265 // VicarePlus :: A selection list for smoking status.
2266 else if ($data_type == 28 || $data_type == 32) {
2267 $tmp = explode('|', $currvalue);
2268 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2269 $restype = count($tmp) > 1 ? $tmp[1] : '';
2270 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2271 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2272 $res = "";
2273 if ($restype == "current" . $field_id) $res = xl('Current');
2274 if ($restype == "quit" . $field_id) $res = xl('Quit');
2275 if ($restype == "never" . $field_id) $res = xl('Never');
2276 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2278 if ($data_type == 28) {
2279 if (!empty($resnote)) $s .= $resnote;
2281 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2282 else if ($data_type == 32) {
2283 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2284 if (!empty($resnote)) $s .= ' ' . $resnote;
2286 if (!empty($res)) {
2287 if ($s !== '') $s .= ' ';
2288 $s .= xl('Status') . ' ' . $res;
2290 if ($restype == "quit".$field_id) {
2291 if ($s !== '') $s .= ' ';
2292 $s .= $resdate;
2296 // Multi select
2297 // Supports backup lists
2298 else if ($data_type == 36) {
2299 $values_array = explode("|", $currvalue);
2301 $i = 0;
2302 foreach($values_array as $value) {
2303 $lrow = sqlQuery("SELECT title FROM list_options " .
2304 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2306 if ($lrow == 0 && !empty($backup_list)) {
2307 //use back up list
2308 $lrow = sqlQuery("SELECT title FROM list_options " .
2309 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2312 if ($i > 0) {
2313 $s = $s . ", " . xl_list_label($lrow['title']);
2314 } else {
2315 $s = xl_list_label($lrow['title']);
2318 $i++;
2322 return $s;
2325 $CPR = 4; // cells per row of generic data
2326 $last_group = '';
2327 $cell_count = 0;
2328 $item_count = 0;
2330 function disp_end_cell() {
2331 global $item_count, $cell_count;
2332 if ($item_count > 0) {
2333 echo "</td>";
2334 $item_count = 0;
2338 function disp_end_row() {
2339 global $cell_count, $CPR;
2340 disp_end_cell();
2341 if ($cell_count > 0) {
2342 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
2343 echo "</tr>\n";
2344 $cell_count = 0;
2348 function disp_end_group() {
2349 global $last_group;
2350 if (strlen($last_group) > 0) {
2351 disp_end_row();
2355 function display_layout_rows($formtype, $result1, $result2='') {
2356 global $item_count, $cell_count, $last_group, $CPR;
2358 $fres = sqlStatement("SELECT * FROM layout_options " .
2359 "WHERE form_id = ? AND uor > 0 " .
2360 "ORDER BY group_name, seq", array($formtype) );
2362 while ($frow = sqlFetchArray($fres)) {
2363 $this_group = $frow['group_name'];
2364 $titlecols = $frow['titlecols'];
2365 $datacols = $frow['datacols'];
2366 $data_type = $frow['data_type'];
2367 $field_id = $frow['field_id'];
2368 $list_id = $frow['list_id'];
2369 $currvalue = '';
2371 if ($formtype == 'DEM') {
2372 if (strpos($field_id, 'em_') === 0) {
2373 // Skip employer related fields, if it's disabled.
2374 if ($GLOBALS['omit_employers']) continue;
2375 $tmp = substr($field_id, 3);
2376 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2378 else {
2379 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2382 else {
2383 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2386 // Handle a data category (group) change.
2387 if (strcmp($this_group, $last_group) != 0) {
2388 $group_name = substr($this_group, 1);
2389 // totally skip generating the employer category, if it's disabled.
2390 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2391 disp_end_group();
2392 $last_group = $this_group;
2395 // filter out all the empty field data from the patient report.
2396 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2397 // Handle starting of a new row.
2398 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2399 disp_end_row();
2400 echo "<tr>";
2401 if ($group_name) {
2402 echo "<td class='groupname'>";
2403 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2404 //echo "<font color='#008800'>$group_name</font>";
2406 // Added 5-09 by BM - Translate label if applicable
2407 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
2409 $group_name = '';
2410 } else {
2411 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2412 echo "<td valign='top'>&nbsp;";
2414 echo "</td>";
2417 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2419 // Handle starting of a new label cell.
2420 if ($titlecols > 0) {
2421 disp_end_cell();
2422 //echo "<td class='label_custom' colspan='$titlecols' valign='top'";
2423 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2424 echo "<td class='label_custom' colspan='$titlecols_esc' ";
2425 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2426 echo ">";
2427 $cell_count += $titlecols;
2429 ++$item_count;
2431 // Added 5-09 by BM - Translate label if applicable
2432 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2434 // Handle starting of a new data cell.
2435 if ($datacols > 0) {
2436 disp_end_cell();
2437 //echo "<td class='text data' colspan='$datacols' valign='top'";
2438 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2439 echo "<td class='text data' colspan='$datacols_esc'";
2440 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2441 echo ">";
2442 $cell_count += $datacols;
2445 ++$item_count;
2446 echo generate_display_field($frow, $currvalue);
2450 disp_end_group();
2453 function display_layout_tabs($formtype, $result1, $result2='') {
2454 global $item_count, $cell_count, $last_group, $CPR;
2456 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2457 "WHERE form_id = ? AND uor > 0 " .
2458 "ORDER BY group_name, seq", array($formtype) );
2460 $first = true;
2461 while ($frow = sqlFetchArray($fres)) {
2462 $this_group = $frow['group_name'];
2463 $group_name = substr($this_group, 1);
2464 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2466 <li <?php echo $first ? 'class="current"' : '' ?>>
2467 <a href="#" id="header_tab_<?php echo str_replace(" ", "_",htmlspecialchars($group_name,ENT_QUOTES))?>">
2468 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
2469 </li>
2470 <?php
2471 $first = false;
2475 function display_layout_tabs_data($formtype, $result1, $result2='') {
2476 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2478 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2479 "WHERE form_id = ? AND uor > 0 " .
2480 "ORDER BY group_name, seq", array($formtype));
2482 $first = true;
2483 while ($frow = sqlFetchArray($fres)) {
2484 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
2485 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
2486 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
2487 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
2488 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
2489 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
2490 $currvalue = '';
2492 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2494 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2495 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2496 "ORDER BY seq", array($formtype, $this_group) );
2499 <div class="tab <?php echo $first ? 'current' : '' ?>">
2500 <table border='0' cellpadding='0'>
2502 <?php
2503 while ($group_fields = sqlFetchArray($group_fields_query)) {
2505 $titlecols = $group_fields['titlecols'];
2506 $datacols = $group_fields['datacols'];
2507 $data_type = $group_fields['data_type'];
2508 $field_id = $group_fields['field_id'];
2509 $list_id = $group_fields['list_id'];
2510 $currvalue = '';
2511 $condition_str = get_conditions_str($condition_str,$group_fields);
2514 if ($formtype == 'DEM') {
2515 if (strpos($field_id, 'em_') === 0) {
2516 // Skip employer related fields, if it's disabled.
2517 if ($GLOBALS['omit_employers']) continue;
2518 $tmp = substr($field_id, 3);
2519 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2521 else {
2522 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2525 else {
2526 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2529 // Handle a data category (group) change.
2530 if (strcmp($this_group, $last_group) != 0) {
2531 $group_name = substr($this_group, 1);
2532 // totally skip generating the employer category, if it's disabled.
2533 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2534 $last_group = $this_group;
2537 // Handle starting of a new row.
2538 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2539 disp_end_row();
2540 echo "<tr>";
2543 if ($item_count == 0 && $titlecols == 0) {
2544 $titlecols = 1;
2547 // Handle starting of a new label cell.
2548 if ($titlecols > 0) {
2549 disp_end_cell();
2550 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2551 $field_id_label = 'label_'.$group_fields['field_id'];
2552 echo "<td class='label_custom' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
2553 echo ">";
2554 $cell_count += $titlecols;
2556 ++$item_count;
2558 $field_id_label = 'label_'.$group_fields['field_id'];
2559 echo "<span id='".attr($field_id_label)."'>";
2560 // Added 5-09 by BM - Translate label if applicable
2561 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2562 echo "</span>";
2564 // Handle starting of a new data cell.
2565 if ($datacols > 0) {
2566 disp_end_cell();
2567 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2568 $field_id = 'text_'.$group_fields['field_id'];
2569 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
2570 echo ">";
2571 $cell_count += $datacols;
2572 } else {
2573 $field_id = 'text_'.$group_fields['field_id'];
2574 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
2577 ++$item_count;
2578 echo generate_display_field($group_fields, $currvalue);
2581 disp_end_row();
2584 </table>
2585 </div>
2587 <?php
2589 $first = false;
2595 function get_conditions_str($condition_str,$frow){
2596 $conditions = empty($frow['conditions']) ? array() : unserialize($frow['conditions']);
2597 foreach ($conditions as $condition) {
2598 if (empty($condition['id'])) continue;
2599 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2600 if ($condition_str) $condition_str .= ",\n";
2601 $condition_str .= "{" .
2602 "target:'" . addslashes($frow['field_id']) . "', " .
2603 "id:'" . addslashes($condition['id']) . "', " .
2604 "itemid:'" . addslashes($condition['itemid']) . "', " .
2605 "operator:'" . addslashes($condition['operator']) . "', " .
2606 "value:'" . addslashes($condition['value']) . "', " .
2607 "andor:'" . addslashes($andor) . "'}";
2609 return $condition_str;
2611 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2612 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2614 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2615 "WHERE form_id = ? AND uor > 0 " .
2616 "ORDER BY group_name, seq", array($formtype) );
2618 $first = true;
2619 while ($frow = sqlFetchArray($fres)) {
2620 $this_group = $frow['group_name'];
2621 $group_name = substr($this_group, 1);
2622 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
2623 $titlecols = $frow['titlecols'];
2624 $datacols = $frow['datacols'];
2625 $data_type = $frow['data_type'];
2626 $field_id = $frow['field_id'];
2627 $list_id = $frow['list_id'];
2628 $currvalue = '';
2630 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2632 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2633 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2634 "ORDER BY seq", array($formtype,$this_group) );
2637 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_',$group_name_esc)?>" >
2638 <table border='0' cellpadding='0'>
2640 <?php
2641 while ($group_fields = sqlFetchArray($group_fields_query)) {
2643 $titlecols = $group_fields['titlecols'];
2644 $datacols = $group_fields['datacols'];
2645 $data_type = $group_fields['data_type'];
2646 $field_id = $group_fields['field_id'];
2647 $list_id = $group_fields['list_id'];
2648 $backup_list = $group_fields['list_backup_id'];
2649 $condition_str = get_conditions_str($condition_str,$group_fields);
2650 $currvalue = '';
2652 if ($formtype == 'DEM') {
2653 if (strpos($field_id, 'em_') === 0) {
2654 // Skip employer related fields, if it's disabled.
2655 if ($GLOBALS['omit_employers']) continue;
2656 $tmp = substr($field_id, 3);
2657 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2659 else {
2660 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2663 else {
2664 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2667 // Handle a data category (group) change.
2668 if (strcmp($this_group, $last_group) != 0) {
2669 $group_name = substr($this_group, 1);
2670 // totally skip generating the employer category, if it's disabled.
2671 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2672 $last_group = $this_group;
2675 // Handle starting of a new row.
2676 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2677 disp_end_row();
2678 echo "<tr>";
2681 if ($item_count == 0 && $titlecols == 0) {
2682 $titlecols = 1;
2685 // Handle starting of a new label cell.
2686 if ($titlecols > 0) {
2687 disp_end_cell();
2688 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2689 $field_id_label = 'label_'.$group_fields['field_id'];
2690 echo "<td class='label_custom' colspan='$titlecols_esc' id='$field_id_label' ";
2691 echo ">";
2692 $cell_count += $titlecols;
2694 ++$item_count;
2696 // Added 5-09 by BM - Translate label if applicable
2697 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
2699 // Handle starting of a new data cell.
2700 if ($datacols > 0) {
2701 disp_end_cell();
2702 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2703 $field_id = 'text_'.$group_fields['field_id'];
2704 echo "<td class='text data' colspan='$datacols_esc' id='$field_id'";
2705 echo ">";
2706 $cell_count += $datacols;
2709 ++$item_count;
2711 echo generate_form_field($group_fields, $currvalue);
2715 </table>
2716 </div>
2718 <?php
2720 $first = false;
2725 // From the currently posted HTML form, this gets the value of the
2726 // field corresponding to the provided layout_options table row.
2728 function get_layout_form_value($frow, $prefix='form_') {
2730 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
2731 $data_type = $frow['data_type'];
2732 $field_id = $frow['field_id'];
2733 $value = '';
2734 if (isset($_POST["$prefix$field_id"])) {
2735 if ($data_type == 21) {
2736 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2737 // must be concatenated into a |-separated string.
2738 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2739 if (strlen($value)) $value .= '|';
2740 $value .= $key;
2743 else if ($data_type == 22) {
2744 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2745 // into "key:value|key:value|...".
2746 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2747 $val = str_replace('|', ' ', $val);
2748 if (strlen($value)) $value .= '|';
2749 $value .= "$key:$val";
2752 else if ($data_type == 23) {
2753 // $_POST["$prefix$field_id"] is an array of text fields with companion
2754 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2755 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2756 $restype = $_POST["radio_{$field_id}"][$key];
2757 if (empty($restype)) $restype = '0';
2758 $val = str_replace('|', ' ', $val);
2759 if (strlen($value)) $value .= '|';
2760 $value .= "$key:$restype:$val";
2763 else if ($data_type == 25) {
2764 // $_POST["$prefix$field_id"] is an array of text fields with companion
2765 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2766 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2767 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
2768 $val = str_replace('|', ' ', $val);
2769 if (strlen($value)) $value .= '|';
2770 $value .= "$key:$restype:$val";
2773 else if ($data_type == 28 || $data_type == 32) {
2774 // $_POST["$prefix$field_id"] is an date text fields with companion
2775 // radio buttons to be imploded into "notes|type|date".
2776 $restype = $_POST["radio_{$field_id}"];
2777 if (empty($restype)) $restype = '0';
2778 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2779 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2780 if ($data_type == 32)
2782 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2783 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2784 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2785 $value = "$res_text_note|$restype|$resdate|$reslist";
2787 else
2788 $value = "$resnote|$restype|$resdate";
2790 else if ($data_type == 36) {
2791 $value_array = $_POST["form_$field_id"];
2792 $i = 0;
2793 foreach ($value_array as $key => $valueofkey) {
2794 if ($i == 0) {
2795 $value = $valueofkey;
2796 } else {
2797 $value = $value . "|" . $valueofkey;
2799 $i++;
2802 else {
2803 $value = $_POST["$prefix$field_id"];
2807 // Better to die than to silently truncate data!
2808 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2809 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2810 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2812 return trim($value);
2815 // Generate JavaScript validation logic for the required fields.
2817 function generate_layout_validation($form_id) {
2818 $fres = sqlStatement("SELECT * FROM layout_options " .
2819 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2820 "ORDER BY group_name, seq", array($form_id) );
2822 while ($frow = sqlFetchArray($fres)) {
2823 $data_type = $frow['data_type'];
2824 $field_id = $frow['field_id'];
2825 $fldtitle = $frow['title'];
2826 if (!$fldtitle) $fldtitle = $frow['description'];
2827 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES);
2829 if ($data_type == 40) {
2830 $fldid = addslashes("form_$field_id");
2831 // Move canvas image data to its hidden form field so the server will get it.
2832 echo
2833 " var canfld = f['$fldid'];\n" .
2834 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
2835 continue;
2838 if ($frow['uor'] < 2) continue;
2840 switch($data_type) {
2841 case 1:
2842 case 11:
2843 case 12:
2844 case 13:
2845 case 14:
2846 case 26:
2847 case 33:
2848 echo
2849 " if (f.$fldname.selectedIndex <= 0) {\n" .
2850 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2851 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2852 " }\n";
2853 break;
2854 case 27: // radio buttons
2855 echo
2856 " var i = 0;\n" .
2857 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2858 " if (i >= f.$fldname.length) {\n" .
2859 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2860 " }\n";
2861 break;
2862 case 2:
2863 case 3:
2864 case 4:
2865 case 15:
2866 echo
2867 " if (trimlen(f.$fldname.value) == 0) {\n" .
2868 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2869 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2870 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2871 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2872 " } else { " .
2873 " $('#" . $fldname . "').attr('style',''); " .
2874 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2875 " } \n";
2876 break;
2877 case 36: // multi select
2878 echo
2879 " var multi_select=f['$fldname"."[]']; \n " .
2880 " var multi_choice_made=false; \n".
2881 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
2882 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
2883 " } \n" .
2884 " if(!multi_choice_made)
2885 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2887 break;
2893 * DROPDOWN FOR FACILITIES
2895 * build a dropdown with all facilities
2897 * @param string $selected - name of the currently selected facility
2898 * use '0' for "unspecified facility"
2899 * use '' for "All facilities" (the default)
2900 * @param string $name - the name/id for select form (defaults to "form_facility")
2901 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2902 * defaults to true
2903 * @return void - just echo the html encoded string
2905 * Note: This should become a data-type at some point, according to Brady
2907 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2908 $allow_allfacilities = true, $disabled='', $onchange='')
2910 global $facilityService;
2912 $have_selected = false;
2913 $fres = $facilityService->getAll();
2915 $name = htmlspecialchars($name, ENT_QUOTES);
2916 echo " <select class='form-control' name='$name' id='$name'";
2917 if ($onchange) echo " onchange='$onchange'";
2918 echo " $disabled>\n";
2920 if ($allow_allfacilities) {
2921 $option_value = '';
2922 $option_selected_attr = '';
2923 if ($selected == '') {
2924 $option_selected_attr = ' selected="selected"';
2925 $have_selected = true;
2927 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2928 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2929 } elseif ($allow_unspecified) {
2930 $option_value = '0';
2931 $option_selected_attr = '';
2932 if ( $selected == '0' ) {
2933 $option_selected_attr = ' selected="selected"';
2934 $have_selected = true;
2936 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2937 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2940 foreach($fres as $frow) {
2941 $facility_id = $frow['id'];
2942 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2943 $option_selected_attr = '';
2944 if ($selected == $facility_id) {
2945 $option_selected_attr = ' selected="selected"';
2946 $have_selected = true;
2948 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2949 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2952 if ($allow_unspecified && $allow_allfacilities) {
2953 $option_value = '0';
2954 $option_selected_attr = '';
2955 if ( $selected == '0' ) {
2956 $option_selected_attr = ' selected="selected"';
2957 $have_selected = true;
2959 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2960 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2963 if (!$have_selected) {
2964 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2965 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2966 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2967 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2969 echo " </select>\n";
2972 // Expand Collapse Widget
2973 // This forms the header and functionality component of the widget. The information that is displayed
2974 // then follows this function followed by a closing div tag
2976 // $title is the title of the section (already translated)
2977 // $label is identifier used in the tag id's and sql columns
2978 // $buttonLabel is the button label text (already translated)
2979 // $buttonLink is the button link information
2980 // $buttonClass is any additional needed class elements for the button tag
2981 // $linkMethod is the button link method ('javascript' vs 'html')
2982 // $bodyClass is to set class(es) of the body
2983 // $auth is a flag to decide whether to show the button
2984 // $fixedWidth is to flag whether width is fixed
2985 // $forceExpandAlways is a flag to force the widget to always be expanded
2987 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2988 if ($fixedWidth) {
2989 echo "<div class='section-header'>";
2991 else {
2992 echo "<div class='section-header-dynamic'>";
2994 echo "<table><tr>";
2995 if ($auth) {
2996 // show button, since authorized
2997 // first prepare class string
2998 if ($buttonClass) {
2999 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
3001 else {
3002 $class_string = "css_button_small";
3004 // next, create the link
3005 if ($linkMethod == "javascript") {
3006 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3008 else {
3009 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3010 if (!isset($_SESSION['patient_portal_onsite']) && !isset($_SESSION['patient_portal_onsite_two']) ) {
3011 // prevent an error from occuring when calling the function from the patient portal
3012 echo " onclick='top.restoreSession()'";
3015 echo "><span>" .
3016 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
3018 if ($forceExpandAlways){
3019 // Special case to force the widget to always be expanded
3020 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
3021 $indicatorTag ="style='display:none'";
3023 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3024 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3025 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
3026 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
3028 if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3029 // collapse all entries in the patient portal
3030 $text = xl('expand');
3032 else if (getUserSetting($label."_ps_expand")) {
3033 $text = xl('collapse');
3035 else {
3036 $text = xl('expand');
3038 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
3039 "</span>)</a></td>";
3040 echo "</tr></table>";
3041 echo "</div>";
3042 if ($forceExpandAlways) {
3043 // Special case to force the widget to always be expanded
3044 $styling = "";
3046 else if (isset($_SESSION['patient_portal_onsite']) || isset($_SESSION['patient_portal_onsite_two'])) {
3047 // collapse all entries in the patient portal
3048 $styling = "style='display:none'";
3050 else if (getUserSetting($label."_ps_expand")) {
3051 $styling = "";
3053 else {
3054 $styling = "style='display:none'";
3056 if ($bodyClass) {
3057 $styling .= " class='" . $bodyClass . "'";
3059 //next, create the first div tag to hold the information
3060 // note the code that calls this function will then place the ending div tag after the data
3061 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
3064 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3065 function billing_facility($name,$select){
3066 global $facilityService;
3068 $fres = $facilityService->getAllBillingLocations();
3069 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3070 foreach ($fres as $facrow) {
3071 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3072 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3074 echo "</select>";
3077 // Generic function to get the translated title value for a particular list option.
3079 function getListItemTitle($list, $option) {
3080 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3081 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3082 if (empty($row['title'])) return $option;
3083 return xl_list_label($row['title']);
3085 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3086 function getSmokeCodes()
3088 $smoking_codes_arr = array();
3089 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3090 while($codes_row = sqlFetchArray($smoking_codes))
3092 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3094 return $smoking_codes_arr;
3097 // Get the current value for a layout based form field.
3098 // Depending on options this might come from lbf_data, patient_data,
3099 // form_encounter, shared_attributes or elsewhere.
3100 // Returns FALSE if the field ID is invalid (layout error).
3102 function lbf_current_value($frow, $formid, $encounter) {
3103 global $pid;
3104 $formname = $frow['form_id'];
3105 $field_id = $frow['field_id'];
3106 $source = $frow['source'];
3107 $currvalue = '';
3108 $deffname = $formname . '_default_' . $field_id;
3109 if ($source == 'D' || $source == 'H') {
3110 // Get from patient_data, employer_data or history_data.
3111 if ($source == 'H') {
3112 $table = 'history_data';
3113 $orderby = 'ORDER BY date DESC LIMIT 1';
3115 else if (strpos($field_id, 'em_') === 0) {
3116 $field_id = substr($field_id, 3);
3117 $table = 'employer_data';
3118 $orderby = 'ORDER BY date DESC LIMIT 1';
3120 else {
3121 $table = 'patient_data';
3122 $orderby = '';
3124 // It is an error if the field does not exist, but don't crash.
3125 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3126 if (empty($tmp)) return FALSE;
3127 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3128 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3130 else if ($source == 'E') {
3131 if ($encounter) {
3132 // Get value from shared_attributes of the current encounter.
3133 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3134 "pid = ? AND encounter = ? AND field_id = ?",
3135 array($pid, $encounter, $field_id));
3136 if (isset($sarow)) $currvalue = $sarow['field_value'];
3138 else if ($formid) {
3139 // Get from shared_attributes of the encounter that this form is linked to.
3140 // Note the importance of having an index on forms.form_id.
3141 $sarow = sqlQuery("SELECT sa.field_value " .
3142 "FROM forms AS f, shared_attributes AS sa WHERE " .
3143 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3144 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3145 array($formid, $formname, $field_id));
3146 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3148 else {
3149 // New form and encounter not available, this should not happen.
3152 else if ($source == 'V') {
3153 if ($encounter) {
3154 // Get value from the current encounter's form_encounter.
3155 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3156 "pid = ? AND encounter = ?",
3157 array($pid, $encounter));
3158 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3160 else if ($formid) {
3161 // Get value from the form_encounter that this form is linked to.
3162 $ferow = sqlQuery("SELECT fe.* " .
3163 "FROM forms AS f, form_encounter AS fe WHERE " .
3164 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3165 "fe.pid = f.pid AND fe.encounter = f.encounter",
3166 array($formid, $formname));
3167 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3169 else {
3170 // New form and encounter not available, this should not happen.
3173 else if ($formid) {
3174 // This is a normal form field.
3175 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3176 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3177 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3179 else {
3180 // New form, see if there is a custom default from a plugin.
3181 // This logic does not apply to shared attributes because they do not
3182 // have a "new form" concept.
3183 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3185 return $currvalue;
3188 // This returns stuff that needs to go into the <head> section of a caller using
3189 // the drawable image field type in a form.
3190 // A TRUE argument makes the widget controls smaller.
3192 function lbf_canvas_head($small=TRUE) {
3193 $s = <<<EOD
3194 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3195 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3196 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3197 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3198 EOD;
3199 if ($small) $s .= <<<EOD
3200 <style>
3201 /* Custom LiterallyCanvas styling.
3202 * This makes the widget 25% less tall and adjusts some other things accordingly.
3204 .literally {
3205 min-height:100%;min-width:300px; /* Was 400, unspecified */
3207 .literally .lc-picker .toolbar-button {
3208 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3210 .literally .color-well {
3211 font-size:8px;width:49px; /* Was 10, 60 */
3213 .literally .color-well-color-container {
3214 width:21px;height:21px; /* Was 28, 28 */
3216 .literally .lc-picker {
3217 width:50px; /* Was 61 */
3219 .literally .lc-drawing.with-gui {
3220 left:50px; /* Was 61 */
3222 .literally .lc-options {
3223 left:50px; /* Was 61 */
3225 .literally .color-picker-popup {
3226 left:49px;bottom:0px; /* Was 60, 31 */
3228 </style>
3229 EOD;
3230 return $s;