new datepicker in encounter
[openemr.git] / library / options.inc.php
blob0c4c9e8c49f2be0a4a9362050cb8d723a8f74c14
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("formatting.inc.php");
40 require_once("user.inc");
41 require_once("patient.inc");
42 require_once("lists.inc");
43 require_once(dirname(dirname(__FILE__)) . "/custom/code_types.inc.php");
45 $date_init = "";
47 function get_pharmacies() {
48 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
49 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
50 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
51 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
52 "AND p.type = 2 " .
53 "ORDER BY name, area_code, prefix, number");
56 function optionalAge($frow, $date, &$asof) {
57 $asof = '';
58 if (empty($date)) return '';
59 $date = substr($date, 0, 10);
60 if (strpos($frow['edit_options'], 'A') !== FALSE) {
61 $format = 0;
63 else if (strpos($frow['edit_options'], 'B') !== FALSE) {
64 $format = 3;
66 else {
67 return '';
69 if (strpos($frow['form_id'], 'LBF') === 0) {
70 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
71 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
72 array($GLOBALS['pid'], $GLOBALS['encounter']));
73 if (!empty($tmp['date'])) $asof = substr($tmp['date'], 0, 10);
75 $prefix = ($format ? xl('Gest age') : xl('Age')) . ' ';
76 return $prefix . oeFormatAge($date, $asof, $format);
79 // Function to generate a drop-list.
81 function generate_select_list($tag_name, $list_id, $currvalue, $title, $empty_name = ' ', $class = '',
82 $onchange = '', $tag_id = '', $custom_attributes = null, $multiple = false, $backup_list = '') {
83 $s = '';
85 $tag_name_esc = attr($tag_name);
87 if ($multiple) {
88 $tag_name_esc = $tag_name_esc . "[]";
91 $s .= "<select name='$tag_name_esc'";
93 if ($multiple) {
94 $s .= " multiple='multiple'";
97 $tag_id_esc = attr( $tag_name );
99 if ($tag_id != '') {
100 $tag_id_esc = attr($tag_id);
103 $s .= " id='$tag_id_esc'";
105 if ($class) {
106 $class_esc = attr($class);
107 $s .= " class='$class_esc'";
109 if ($onchange) {
110 $s .= " onchange='$onchange'";
112 if ($custom_attributes != null && is_array ( $custom_attributes )) {
113 foreach ( $custom_attributes as $attr => $val ) {
114 if (isset ( $custom_attributes [$attr] )) {
115 $s .= " " . attr($attr) . "='" . attr($val) . "'";
119 $selectTitle = attr($title);
120 $s .= " title='$selectTitle'>";
121 $selectEmptyName = xlt($empty_name);
122 if ($empty_name)
123 $s .= "<option value=''>" . $selectEmptyName . "</option>";
125 // List order depends on language translation options.
126 // (Note we do not need to worry about the list order in the algorithm
127 // after the below code block since that is where searches for exceptions
128 // are done which include inactive items or items from a backup
129 // list; note these will always be shown at the bottom of the list no matter the
130 // chosen order.)
131 $lang_id = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
132 // sort by title
133 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) || !$GLOBALS['translate_lists']) {
134 // do not translate
135 if ($GLOBALS['gb_how_sort_list'] == '0') {
136 // order by seq
137 $order_by_sql = "seq, title";
139 else { //$GLOBALS['gb_how_sort_list'] == '1'
140 // order by title
141 $order_by_sql = "title, seq";
143 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
145 else {
146 // do translate
147 if ($GLOBALS['gb_how_sort_list'] == '0') {
148 // order by seq
149 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
151 else { //$GLOBALS['gb_how_sort_list'] == '1'
152 // order by title
153 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
155 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
156 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
157 "FROM list_options AS lo " .
158 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
159 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
160 "ld.lang_id = ? " .
161 "WHERE lo.list_id = ? AND lo.activity=1 " .
162 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
164 $got_selected = FALSE;
166 while ( $lrow = sqlFetchArray ( $lres ) ) {
167 $selectedValues = explode ( "|", $currvalue );
169 $optionValue = attr($lrow ['option_id']);
170 $s .= "<option value='$optionValue'";
172 if ((strlen ( $currvalue ) == 0 && $lrow ['is_default']) || (strlen ( $currvalue ) > 0 && in_array ( $lrow ['option_id'], $selectedValues ))) {
173 $s .= " selected";
174 $got_selected = TRUE;
177 // Already has been translated above (if applicable), so do not need to use
178 // the xl_list_label() function here
179 $optionLabel = text($lrow ['title']);
180 $s .= ">$optionLabel</option>\n";
184 To show the inactive item in the list if the value is saved to database
186 if (!$got_selected && strlen($currvalue) > 0)
188 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
189 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
190 $lrow_inactive = sqlFetchArray($lres_inactive);
191 if($lrow_inactive['option_id']) {
192 $optionValue = htmlspecialchars( $lrow_inactive['option_id'], ENT_QUOTES);
193 $s .= "<option value='$optionValue' selected>" . htmlspecialchars( xl_list_label($lrow_inactive['title']), ENT_NOQUOTES) . "</option>\n";
194 $got_selected = TRUE;
198 if (!$got_selected && strlen ( $currvalue ) > 0 && !$multiple) {
199 $list_id = $backup_list;
200 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
202 if ($lrow > 0 && !empty($backup_list)) {
203 $selected = text(xl_list_label($lrow ['title']));
204 $s .= "<option value='$currescaped' selected> $selected </option>";
205 $s .= "</select>";
206 } else {
207 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
208 $s .= "</select>";
209 $fontTitle = xlt('Please choose a valid selection from the list.');
210 $fontText = xlt( 'Fix this' );
211 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
214 } else if (!$got_selected && strlen ( $currvalue ) > 0 && $multiple) {
215 //if not found in main list, display all selected values that exist in backup list
216 $list_id = $backup_list;
218 $got_selected_backup = FALSE;
219 if (!empty($backup_list)) {
220 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
221 while ( $lrow_backup = sqlFetchArray ( $lres_backup ) ) {
222 $selectedValues = explode ( "|", $currvalue );
224 $optionValue = attr($lrow_backup['option_id']);
226 if ( in_array($lrow_backup ['option_id'],$selectedValues)) {
227 $s .= "<option value='$optionValue'";
228 $s .= " selected";
229 $optionLabel = text(xl_list_label($lrow_backup ['title']));
230 $s .= ">$optionLabel</option>\n";
231 $got_selected_backup = TRUE;
235 if (!$got_selected_backup) {
236 $selectedValues = explode ( "|", $currvalue );
237 foreach ( $selectedValues as $selectedValue ) {
238 $s .= "<option value='" . attr($selectedValue) . "'";
239 $s .= " selected";
240 $s .= ">* " . text($selectedValue) . " *</option>\n";
242 $s .= "</select>";
243 $fontTitle = xlt('Please choose a valid selection from the list.');
244 $fontText = xlt( 'Fix this' );
245 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
249 else {
250 $s .= "</select>";
252 return $s;
256 // $frow is a row from the layout_options table.
257 // $currvalue is the current value, if any, of the associated item.
259 function generate_form_field($frow, $currvalue) {
260 global $rootdir, $date_init, $ISSUE_TYPES, $code_types,$condition_str;
262 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
264 $data_type = $frow['data_type'];
265 $field_id = $frow['field_id'];
266 $list_id = $frow['list_id'];
267 $backup_list = $frow['list_backup_id'];
268 $condition_str = get_conditions_str($condition_str,$frow);
270 // escaped variables to use in html
271 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
272 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
274 // Added 5-09 by BM - Translate description if applicable
275 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
277 // Support edit option T which assigns the (possibly very long) description as
278 // the default value.
279 if (strpos($frow['edit_options'], 'T') !== FALSE) {
280 if (strlen($currescaped) == 0) $currescaped = $description;
281 // Description used in this way is not suitable as a title.
282 $description = '';
285 // added 5-2009 by BM to allow modification of the 'empty' text title field.
286 // Can pass $frow['empty_title'] with this variable, otherwise
287 // will default to 'Unassigned'.
288 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
289 // if make $frow['empty_title'] equal to 'SKIP'
290 $showEmpty = true;
291 if (isset($frow['empty_title'])) {
292 if ($frow['empty_title'] == "SKIP") {
293 //do not display an 'empty' choice
294 $showEmpty = false;
295 $empty_title = "Unassigned";
297 else {
298 $empty_title = $frow['empty_title'];
301 else {
302 $empty_title = "Unassigned";
305 $disabled = strpos($frow['edit_options'], '0') === FALSE ? '' : 'disabled';
307 $lbfchange = (strpos($frow['form_id'], 'LBF') === 0 || strpos($frow['form_id'], 'LBT') === 0) ?
308 "checkSkipConditions();" : "";
309 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
311 // generic single-selection list or Race and Ethnicity.
312 // These data types support backup lists.
313 if ($data_type == 1 || $data_type == 33) {
314 echo generate_select_list("form_$field_id", $list_id, $currvalue,
315 $description, ($showEmpty ? $empty_title : ''), '', $lbfchange, '',
316 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
319 // simple text field
320 else if ($data_type == 2) {
321 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
322 $maxlength = $frow['max_length'];
323 $string_maxlength = "";
324 // if max_length is set to zero, then do not set a maxlength
325 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
326 echo "<input type='text'" .
327 " name='form_$field_id_esc'" .
328 " id='form_$field_id_esc'" .
329 " size='$fldlength'" .
330 " $string_maxlength" .
331 " title='$description'" .
332 " value='$currescaped'";
333 $tmp = $lbfchange;
334 if (strpos($frow['edit_options'], 'C') !== FALSE)
335 $tmp .= "capitalizeMe(this);";
336 else if (strpos($frow['edit_options'], 'U') !== FALSE)
337 $tmp .= "this.value = this.value.toUpperCase();";
338 if ($tmp) echo " onchange='$tmp'";
339 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
340 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
341 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
342 echo " onblur='maskblur(this,\"$tmp\")'";
344 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
345 echo " readonly";
347 if ($disabled) echo ' disabled';
348 echo " />";
351 // long or multi-line text field
352 else if ($data_type == 3) {
353 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
354 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
355 echo "<textarea" .
356 " name='form_$field_id_esc'" .
357 " id='form_$field_id_esc'" .
358 " title='$description'" .
359 " cols='$textCols'" .
360 " rows='$textRows' $lbfonchange $disabled" .
361 ">" . $currescaped . "</textarea>";
364 // date
365 else if ($data_type == 4) {
366 $age_asof_date = ''; // optionalAge() sets this
367 $age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0;
368 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
369 if ($agestr) {
370 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
372 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
373 " value='" . substr($currescaped, 0, 10) . "'";
374 if (!$agestr) echo " title='$description'";
375 echo " $lbfonchange onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
376 if (!$disabled) {
377 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
378 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
379 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
380 $date_init .= " Calendar.setup({" .
381 "inputField:'form_$field_id', " .
382 "ifFormat:'%Y-%m-%d', ";
383 if ($agestr) {
384 $date_init .= "onUpdate: function() {" .
385 "if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format);" .
386 "}, ";
388 $date_init .= "button:'img_$field_id'})\n";
390 // Optional display of age or gestational age.
391 if ($agestr) {
392 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
396 // provider list, local providers only
397 else if ($data_type == 10) {
398 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
399 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
400 "AND authorized = 1 " .
401 "ORDER BY lname, fname");
402 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled>";
403 echo "<option value=''>" . xlt($empty_title) . "</option>";
404 $got_selected = false;
405 while ($urow = sqlFetchArray($ures)) {
406 $uname = text($urow['fname'] . ' ' . $urow['lname']);
407 $optionId = attr($urow['id']);
408 echo "<option value='$optionId'";
409 if ($urow['id'] == $currvalue) {
410 echo " selected";
411 $got_selected = true;
413 echo ">$uname</option>";
415 if (!$got_selected && $currvalue) {
416 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
417 echo "</select>";
418 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
420 else {
421 echo "</select>";
425 // provider list, including address book entries with an NPI number
426 else if ($data_type == 11) {
427 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
428 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
429 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
430 "ORDER BY lname, fname");
431 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
432 echo " $lbfonchange $disabled>";
433 echo "<option value=''>" . xlt('Unassigned') . "</option>";
434 $got_selected = false;
435 while ($urow = sqlFetchArray($ures)) {
436 $uname = text($urow['fname'] . ' ' . $urow['lname']);
437 $optionId = attr($urow['id']);
438 echo "<option value='$optionId'";
439 if ($urow['id'] == $currvalue) {
440 echo " selected";
441 $got_selected = true;
443 echo ">$uname</option>";
445 if (!$got_selected && $currvalue) {
446 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
447 echo "</select>";
448 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
450 else {
451 echo "</select>";
455 // pharmacy list
456 else if ($data_type == 12) {
457 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
458 echo " $lbfonchange $disabled>";
459 echo "<option value='0'></option>";
460 $pres = get_pharmacies();
461 $got_selected = false;
462 while ($prow = sqlFetchArray($pres)) {
463 $key = $prow['id'];
464 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
465 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
466 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
467 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
468 echo "<option value='$optionValue'";
469 if ($currvalue == $key) {
470 echo " selected";
471 $got_selected = true;
473 echo ">$optionLabel</option>";
475 if (!$got_selected && $currvalue) {
476 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
477 echo "</select>";
478 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
480 else {
481 echo "</select>";
485 // squads
486 else if ($data_type == 13) {
487 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
488 echo " $lbfonchange $disabled>";
489 echo "<option value=''>&nbsp;</option>";
490 $squads = acl_get_squads();
491 if ($squads) {
492 foreach ($squads as $key => $value) {
493 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
494 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
495 echo "<option value='$optionValue'";
496 if ($currvalue == $key) echo " selected";
497 echo ">$optionLabel</option>\n";
500 echo "</select>";
503 // Address book, preferring organization name if it exists and is not in
504 // parentheses, and excluding local users who are not providers.
505 // Supports "referred to" practitioners and facilities.
506 // Alternatively the letter L in edit_options means that abook_type
507 // must be "ord_lab", indicating types used with the procedure
508 // lab ordering system.
509 // Alternatively the letter O in edit_options means that abook_type
510 // must begin with "ord_", indicating types used with the procedure
511 // ordering system.
512 // Alternatively the letter V in edit_options means that abook_type
513 // must be "vendor", indicating the Vendor type.
514 // Alternatively the letter R in edit_options means that abook_type
515 // must be "dist", indicating the Distributor type.
516 else if ($data_type == 14) {
517 if (strpos($frow['edit_options'], 'L') !== FALSE)
518 $tmp = "abook_type = 'ord_lab'";
519 else if (strpos($frow['edit_options'], 'O') !== FALSE)
520 $tmp = "abook_type LIKE 'ord\\_%'";
521 else if (strpos($frow['edit_options'], 'V') !== FALSE)
522 $tmp = "abook_type LIKE 'vendor%'";
523 else if (strpos($frow['edit_options'], 'R') !== FALSE)
524 $tmp = "abook_type LIKE 'dist'";
525 else
526 $tmp = "( username = '' OR authorized = 1 )";
527 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
528 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
529 "AND $tmp " .
530 "ORDER BY organization, lname, fname");
531 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
532 echo " $lbfonchange $disabled>";
533 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
534 while ($urow = sqlFetchArray($ures)) {
535 $uname = $urow['organization'];
536 if (empty($uname) || substr($uname, 0, 1) == '(') {
537 $uname = $urow['lname'];
538 if ($urow['fname']) $uname .= ", " . $urow['fname'];
540 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
541 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
542 echo "<option value='$optionValue'";
543 $title = $urow['username'] ? xl('Local') : xl('External');
544 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
545 echo " title='$optionTitle'";
546 if ($urow['id'] == $currvalue) echo " selected";
547 echo ">$optionLabel</option>";
549 echo "</select>";
552 // A billing code. If description matches an existing code type then that type is used.
553 else if ($data_type == 15) {
554 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
555 $maxlength = $frow['max_length'];
556 $string_maxlength = "";
557 // if max_length is set to zero, then do not set a maxlength
558 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
560 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
561 // Option "2" generates a hidden input for the codes, and a matching visible field
562 // displaying their descriptions. First step is computing the description string.
563 $currdescstring = '';
564 if (!empty($currvalue)) {
565 $relcodes = explode(';', $currvalue);
566 foreach ($relcodes as $codestring) {
567 if ($codestring === '') continue;
568 $code_text = lookup_code_descriptions($codestring);
569 if ($currdescstring !== '') $currdescstring .= '; ';
570 if (!empty($code_text)) {
571 $currdescstring .= $code_text;
573 else {
574 $currdescstring .= $codestring;
578 $currdescstring = attr($currdescstring);
580 echo "<input type='text'" .
581 " name='form_$field_id_esc'" .
582 " id='form_related_code'" .
583 " size='$fldlength'" .
584 " value='$currescaped'" .
585 " style='display:none'" .
586 " $lbfonchange readonly $disabled />";
587 // Extra readonly input field for optional display of code description(s).
588 echo "<input type='text'" .
589 " name='form_$field_id_esc" . "__desc'" .
590 " size='$fldlength'" .
591 " title='$description'" .
592 " value='$currdescstring'";
593 if (!$disabled) {
594 echo " onclick='sel_related(this,\"$codetype\")'";
596 echo " readonly $disabled />";
598 else {
599 echo "<input type='text'" .
600 " name='form_$field_id_esc'" .
601 " id='form_related_code'" .
602 " size='$fldlength'" .
603 " $string_maxlength" .
604 " title='$description'" .
605 " value='$currescaped'";
606 if (!$disabled) {
607 echo " onclick='sel_related(this,\"$codetype\")'";
609 echo " $lbfonchange readonly $disabled />";
613 // insurance company list
614 else if ($data_type == 16) {
615 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
616 echo "<option value='0'></option>";
617 $insprovs = getInsuranceProviders();
618 $got_selected = false;
619 foreach ($insprovs as $key => $ipname) {
620 $optionValue = htmlspecialchars($key, ENT_QUOTES);
621 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
622 echo "<option value='$optionValue'";
623 if ($currvalue == $key) {
624 echo " selected";
625 $got_selected = true;
627 echo ">$optionLabel</option>";
629 if (!$got_selected && $currvalue) {
630 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
631 echo "</select>";
632 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
634 else {
635 echo "</select>";
639 // issue types
640 else if ($data_type == 17) {
641 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
642 echo "<option value='0'></option>";
643 $got_selected = false;
644 foreach ($ISSUE_TYPES as $key => $value) {
645 $optionValue = htmlspecialchars($key, ENT_QUOTES);
646 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
647 echo "<option value='$optionValue'";
648 if ($currvalue == $key) {
649 echo " selected";
650 $got_selected = true;
652 echo ">$optionLabel</option>";
654 if (!$got_selected && strlen($currvalue) > 0) {
655 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
656 echo "</select>";
657 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
659 else {
660 echo "</select>";
664 // Visit categories.
665 else if ($data_type == 18) {
666 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
667 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
668 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
669 " $lbfonchange $disabled>";
670 echo "<option value=''>" . xlt($empty_title) . "</option>";
671 $got_selected = false;
672 while ($crow = sqlFetchArray($cres)) {
673 $catid = $crow['pc_catid'];
674 if (($catid < 9 && $catid != 5) || $catid == 11) continue;
675 echo "<option value='" . attr($catid) . "'";
676 if ($catid == $currvalue) {
677 echo " selected";
678 $got_selected = true;
680 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
682 if (!$got_selected && $currvalue) {
683 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
684 echo "</select>";
685 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
687 else {
688 echo "</select>";
692 // a set of labeled checkboxes
693 else if ($data_type == 21) {
694 // In this special case, fld_length is the number of columns generated.
695 $cols = max(1, $frow['fld_length']);
696 $avalue = explode('|', $currvalue);
697 $lres = sqlStatement("SELECT * FROM list_options " .
698 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
699 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
700 $tdpct = (int) (100 / $cols);
701 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
702 $option_id = $lrow['option_id'];
703 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
704 // if ($count) echo "<br />";
705 if ($count % $cols == 0) {
706 if ($count) echo "</tr>";
707 echo "<tr>";
709 echo "<td width='$tdpct%'>";
710 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
711 "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
712 if (in_array($option_id, $avalue)) echo " checked";
714 // Added 5-09 by BM - Translate label if applicable
715 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
717 echo "</td>";
719 if ($count) {
720 echo "</tr>";
721 if ($count > $cols) {
722 // Add some space after multiple rows of checkboxes.
723 $cols = htmlspecialchars( $cols, ENT_QUOTES);
724 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
727 echo "</table>";
730 // a set of labeled text input fields
731 else if ($data_type == 22) {
732 $tmp = explode('|', $currvalue);
733 $avalue = array();
734 foreach ($tmp as $value) {
735 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
736 $avalue[$matches[1]] = $matches[2];
739 $lres = sqlStatement("SELECT * FROM list_options " .
740 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
741 echo "<table cellpadding='0' cellspacing='0'>";
742 while ($lrow = sqlFetchArray($lres)) {
743 $option_id = $lrow['option_id'];
744 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
745 $maxlength = $frow['max_length'];
746 $string_maxlength = "";
747 // if max_length is set to zero, then do not set a maxlength
748 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
749 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
751 // Added 5-09 by BM - Translate label if applicable
752 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
753 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
754 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
755 echo "<td><input type='text'" .
756 " name='form_{$field_id_esc}[$option_id_esc]'" .
757 " id='form_{$field_id_esc}[$option_id_esc]'" .
758 " size='$fldlength'" .
759 " $string_maxlength" .
760 " value='$optionValue'";
761 echo " $lbfonchange $disabled /></td></tr>";
763 echo "</table>";
766 // a set of exam results; 3 radio buttons and a text field:
767 else if ($data_type == 23) {
768 $tmp = explode('|', $currvalue);
769 $avalue = array();
770 foreach ($tmp as $value) {
771 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
772 $avalue[$matches[1]] = $matches[2];
775 $maxlength = $frow['max_length'];
776 $string_maxlength = "";
777 // if max_length is set to zero, then do not set a maxlength
778 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
779 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
780 $lres = sqlStatement("SELECT * FROM list_options " .
781 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
782 echo "<table cellpadding='0' cellspacing='0'>";
783 echo "<tr><td>&nbsp;</td><td class='bold'>" .
784 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
785 "&nbsp;</td><td class='bold'>" .
786 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
787 "<td class='bold'>" .
788 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
789 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
790 while ($lrow = sqlFetchArray($lres)) {
791 $option_id = $lrow['option_id'];
792 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
793 $restype = substr($avalue[$option_id], 0, 1);
794 $resnote = substr($avalue[$option_id], 2);
796 // Added 5-09 by BM - Translate label if applicable
797 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
799 for ($i = 0; $i < 3; ++$i) {
800 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
801 echo "<td><input type='radio'" .
802 " name='radio_{$field_id_esc}[$option_id_esc]'" .
803 " id='radio_{$field_id_esc}[$option_id_esc]'" .
804 " value='$inputValue' $lbfonchange";
805 if ($restype === "$i") echo " checked";
806 echo " $disabled /></td>";
808 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
809 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
810 echo "<td><input type='text'" .
811 " name='form_{$field_id_esc}[$option_id_esc]'" .
812 " id='form_{$field_id_esc}[$option_id_esc]'" .
813 " size='$fldlength'" .
814 " $string_maxlength" .
815 " value='$resnote' $disabled /></td>";
816 echo "</tr>";
818 echo "</table>";
821 // the list of active allergies for the current patient
822 // this is read-only!
823 else if ($data_type == 24) {
824 $query = "SELECT title, comments FROM lists WHERE " .
825 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
826 "ORDER BY begdate";
827 // echo "<!-- $query -->\n"; // debugging
828 $lres = sqlStatement($query, array($GLOBALS['pid']));
829 $count = 0;
830 while ($lrow = sqlFetchArray($lres)) {
831 if ($count++) echo "<br />";
832 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
833 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
837 // a set of labeled checkboxes, each with a text field:
838 else if ($data_type == 25) {
839 $tmp = explode('|', $currvalue);
840 $avalue = array();
841 foreach ($tmp as $value) {
842 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
843 $avalue[$matches[1]] = $matches[2];
846 $maxlength = $frow['max_length'];
847 $string_maxlength = "";
848 // if max_length is set to zero, then do not set a maxlength
849 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
850 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
851 $lres = sqlStatement("SELECT * FROM list_options " .
852 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
853 echo "<table cellpadding='0' cellspacing='0'>";
854 while ($lrow = sqlFetchArray($lres)) {
855 $option_id = $lrow['option_id'];
856 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
857 $restype = substr($avalue[$option_id], 0, 1);
858 $resnote = substr($avalue[$option_id], 2);
860 // Added 5-09 by BM - Translate label if applicable
861 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
863 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
864 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
865 " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
866 if ($restype) echo " checked";
867 echo " $disabled />&nbsp;</td>";
868 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
869 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
870 echo "<td><input type='text'" .
871 " name='form_{$field_id_esc}[$option_id_esc]'" .
872 " id='form_{$field_id_esc}[$option_id_esc]'" .
873 " size='$fldlength'" .
874 " $string_maxlength" .
875 " value='$resnote' $disabled /></td>";
876 echo "</tr>";
878 echo "</table>";
881 // single-selection list with ability to add to it
882 else if ($data_type == 26) {
883 echo generate_select_list("form_$field_id", $list_id, $currvalue,
884 $description, ($showEmpty ? $empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
885 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
886 // show the add button if user has access to correct list
887 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
888 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
889 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
890 if (aco_exist('lists', $list_id)) {
891 // a specific aco exist for this list, so ensure access
892 if (acl_check('lists', $list_id)) echo $outputAddButton;
894 else {
895 // no specific aco exist for this list, so check for access to 'default' list
896 if (acl_check('lists', 'default')) echo $outputAddButton;
900 // a set of labeled radio buttons
901 else if ($data_type == 27) {
902 // In this special case, fld_length is the number of columns generated.
903 $cols = max(1, $frow['fld_length']);
904 $lres = sqlStatement("SELECT * FROM list_options " .
905 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
906 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
907 $tdpct = (int) (100 / $cols);
908 $got_selected = FALSE;
909 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
910 $option_id = $lrow['option_id'];
911 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
912 if ($count % $cols == 0) {
913 if ($count) echo "</tr>";
914 echo "<tr>";
916 echo "<td width='$tdpct%'>";
917 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
918 " value='$option_id_esc' $lbfonchange";
919 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
920 (strlen($currvalue) > 0 && $option_id == $currvalue))
922 echo " checked";
923 $got_selected = TRUE;
925 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
926 echo "</td>";
928 if ($count) {
929 echo "</tr>";
930 if ($count > $cols) {
931 // Add some space after multiple rows of radio buttons.
932 $cols = htmlspecialchars($cols, ENT_QUOTES);
933 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
936 echo "</table>";
937 if (!$got_selected && strlen($currvalue) > 0) {
938 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
939 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
940 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
944 // special case for history of lifestyle status; 3 radio buttons and a date text field:
945 // VicarePlus :: A selection list box for smoking status:
946 else if ($data_type == 28 || $data_type == 32) {
947 $tmp = explode('|', $currvalue);
948 switch(count($tmp)) {
949 case "4": {
950 $resnote = $tmp[0];
951 $restype = $tmp[1];
952 $resdate = $tmp[2];
953 $reslist = $tmp[3];
954 } break;
955 case "3": {
956 $resnote = $tmp[0];
957 $restype = $tmp[1];
958 $resdate = $tmp[2];
959 } break;
960 case "2": {
961 $resnote = $tmp[0];
962 $restype = $tmp[1];
963 $resdate = "";
964 } break;
965 case "1": {
966 $resnote = $tmp[0];
967 $resdate = $restype = "";
968 } break;
969 default: {
970 $restype = $resdate = $resnote = "";
971 } break;
973 $maxlength = $frow['max_length'];
974 $string_maxlength = "";
975 // if max_length is set to zero, then do not set a maxlength
976 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
977 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
979 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
980 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
981 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
982 echo "<table cellpadding='0' cellspacing='0'>";
983 echo "<tr>";
984 if ($data_type == 28)
986 // input text
987 echo "<td><input type='text'" .
988 " name='form_$field_id_esc'" .
989 " id='form_$field_id_esc'" .
990 " size='$fldlength'" .
991 " $string_maxlength" .
992 " value='$resnote' $disabled />&nbsp;</td>";
993 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
994 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
995 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
997 else if($data_type == 32)
999 // input text
1000 echo "<tr><td><input type='text'" .
1001 " name='form_text_$field_id_esc'" .
1002 " id='form_text_$field_id_esc'" .
1003 " size='$fldlength'" .
1004 " $string_maxlength" .
1005 " value='$resnote' $disabled />&nbsp;</td></tr>";
1006 echo "<td>";
1007 //Selection list for smoking status
1008 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1009 echo generate_select_list("form_$field_id", $list_id, $reslist,
1010 $description, ($showEmpty ? $empty_title : ''), '', $onchange, '',
1011 ($disabled ? array('disabled' => 'disabled') : null));
1012 echo "</td>";
1013 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1015 // current
1016 echo "<td class='text' ><input type='radio'" .
1017 " name='radio_{$field_id_esc}'" .
1018 " id='radio_{$field_id_esc}[current]'" .
1019 " value='current" . $field_id_esc . "' $lbfonchange";
1020 if ($restype == "current" . $field_id) echo " checked";
1021 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1022 echo " />" . xlt('Current') . "&nbsp;</td>";
1023 // quit
1024 echo "<td class='text'><input type='radio'" .
1025 " name='radio_{$field_id_esc}'" .
1026 " id='radio_{$field_id_esc}[quit]'" .
1027 " value='quit".$field_id_esc."' $lbfonchange";
1028 if ($restype == "quit" . $field_id) echo " checked";
1029 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1030 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1031 // quit date
1032 echo "<td class='text'><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
1033 " value='$resdate'" .
1034 " title='$description'" .
1035 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
1036 if (!$disabled) {
1037 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
1038 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
1039 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
1040 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
1042 echo "&nbsp;</td>";
1043 // never
1044 echo "<td class='text'><input type='radio'" .
1045 " name='radio_{$field_id_esc}'" .
1046 " id='radio_{$field_id_esc}[never]'" .
1047 " value='never" . $field_id_esc . "' $lbfonchange";
1048 if ($restype == "never" . $field_id) echo " checked";
1049 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1050 echo " />" . xlt('Never') . "&nbsp;</td>";
1051 // Not Applicable
1052 echo "<td class='text'><input type='radio'" .
1053 " name='radio_{$field_id}'" .
1054 " id='radio_{$field_id}[not_applicable]'" .
1055 " value='not_applicable" . $field_id . "' $lbfonchange";
1056 if ($restype == "not_applicable" . $field_id) echo " checked";
1057 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1058 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1060 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1061 echo "<td class='text' ><div id='smoke_code'></div></td>";
1062 echo "</tr>";
1063 echo "</table>";
1066 // static text. read-only, of course.
1067 else if ($data_type == 31) {
1068 echo nl2br($frow['description']);
1071 //$data_type == 33
1072 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1073 //$data_type == 33
1075 else if($data_type == 34){
1076 $arr = explode("|*|*|*|",$currvalue);
1077 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;'>";
1078 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
1079 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1080 echo "</a>";
1083 //facilities drop-down list
1084 else if ($data_type == 35) {
1085 if (empty($currvalue)){
1086 $currvalue = 0;
1088 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1089 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1092 //multiple select
1093 // supports backup list
1094 else if ($data_type == 36) {
1095 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1096 $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);
1100 // Canvas and related elements for browser-side image drawing.
1101 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1102 else if ($data_type == 40) {
1103 // Unlike other field types, width and height are in pixels.
1104 $canWidth = intval($frow['fld_length']);
1105 $canHeight = intval($frow['fld_rows']);
1106 if (empty($currvalue)) {
1107 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1108 // If defined this is the filename of the default starting image.
1109 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1112 echo "<div id='form_$field_id_esc'></div>";
1113 // Hidden form field exists to send updated data to the server at submit time.
1114 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1115 // Hidden image exists to support initialization of the canvas.
1116 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1117 // $date_init is a misnomer but it's the place for browser-side setup logic.
1118 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1123 function generate_print_field($frow, $currvalue) {
1124 global $rootdir, $date_init, $ISSUE_TYPES;
1126 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1128 $data_type = $frow['data_type'];
1129 $field_id = $frow['field_id'];
1130 $list_id = $frow['list_id'];
1131 $fld_length = $frow['fld_length'];
1132 $backup_list = $frow['list_backup_id'];
1134 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1136 // Can pass $frow['empty_title'] with this variable, otherwise
1137 // will default to 'Unassigned'.
1138 // If it is 'SKIP' then an empty text title is completely skipped.
1139 $showEmpty = true;
1140 if (isset($frow['empty_title'])) {
1141 if ($frow['empty_title'] == "SKIP") {
1142 //do not display an 'empty' choice
1143 $showEmpty = false;
1144 $empty_title = "Unassigned";
1146 else {
1147 $empty_title = $frow['empty_title'];
1150 else {
1151 $empty_title = "Unassigned";
1154 // generic single-selection list
1155 // Supports backup lists.
1156 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
1157 if (empty($fld_length)) {
1158 if ($list_id == 'titles') {
1159 $fld_length = 3;
1160 } else {
1161 $fld_length = 10;
1164 $tmp = '';
1165 if ($currvalue) {
1166 $lrow = sqlQuery("SELECT title FROM list_options " .
1167 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1168 $tmp = xl_list_label($lrow['title']);
1169 if ($lrow == 0 && !empty($backup_list)) {
1170 // since primary list did not map, try to map to backup list
1171 $lrow = sqlQuery("SELECT title FROM list_options " .
1172 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1173 $tmp = xl_list_label($lrow['title']);
1175 if (empty($tmp)) $tmp = "($currvalue)";
1177 /*****************************************************************
1178 echo "<input type='text'" .
1179 " size='$fld_length'" .
1180 " value='$tmp'" .
1181 " class='under'" .
1182 " />";
1183 *****************************************************************/
1184 if ($tmp === '') {
1185 $tmp = '&nbsp;';
1187 else {
1188 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1190 echo $tmp;
1193 // simple text field
1194 else if ($data_type == 2 || $data_type == 15) {
1195 /*****************************************************************
1196 echo "<input type='text'" .
1197 " size='$fld_length'" .
1198 " value='$currescaped'" .
1199 " class='under'" .
1200 " />";
1201 *****************************************************************/
1202 if ($currescaped === '') $currescaped = '&nbsp;';
1203 echo $currescaped;
1206 // long or multi-line text field
1207 else if ($data_type == 3) {
1208 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
1209 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
1210 echo "<textarea" .
1211 " cols='$fldlength'" .
1212 " rows='$maxlength'>" .
1213 $currescaped . "</textarea>";
1216 // date
1217 else if ($data_type == 4) {
1218 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1219 $agestr = optionalAge($frow, $currvalue,$asof);
1220 if ($agestr) {
1221 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1223 if ($currvalue === '') {
1224 echo '&nbsp;';
1226 else {
1227 echo text(oeFormatShortDate($currvalue));
1229 // Optional display of age or gestational age.
1230 if ($agestr) {
1231 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1235 // provider list
1236 else if ($data_type == 10 || $data_type == 11) {
1237 $tmp = '';
1238 if ($currvalue) {
1239 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1240 "WHERE id = ?", array($currvalue) );
1241 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1242 if (empty($tmp)) $tmp = "($currvalue)";
1244 /*****************************************************************
1245 echo "<input type='text'" .
1246 " size='$fld_length'" .
1247 " value='$tmp'" .
1248 " class='under'" .
1249 " />";
1250 *****************************************************************/
1251 if ($tmp === '') { $tmp = '&nbsp;'; }
1252 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1253 echo $tmp;
1256 // pharmacy list
1257 else if ($data_type == 12) {
1258 $tmp = '';
1259 if ($currvalue) {
1260 $pres = get_pharmacies();
1261 while ($prow = sqlFetchArray($pres)) {
1262 $key = $prow['id'];
1263 if ($currvalue == $key) {
1264 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1265 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1266 $prow['line1'] . ' / ' . $prow['city'];
1269 if (empty($tmp)) $tmp = "($currvalue)";
1271 /*****************************************************************
1272 echo "<input type='text'" .
1273 " size='$fld_length'" .
1274 " value='$tmp'" .
1275 " class='under'" .
1276 " />";
1277 *****************************************************************/
1278 if ($tmp === '') { $tmp = '&nbsp;'; }
1279 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1280 echo $tmp;
1283 // squads
1284 else if ($data_type == 13) {
1285 $tmp = '';
1286 if ($currvalue) {
1287 $squads = acl_get_squads();
1288 if ($squads) {
1289 foreach ($squads as $key => $value) {
1290 if ($currvalue == $key) {
1291 $tmp = $value[3];
1295 if (empty($tmp)) $tmp = "($currvalue)";
1297 /*****************************************************************
1298 echo "<input type='text'" .
1299 " size='$fld_length'" .
1300 " value='$tmp'" .
1301 " class='under'" .
1302 " />";
1303 *****************************************************************/
1304 if ($tmp === '') { $tmp = '&nbsp;'; }
1305 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1306 echo $tmp;
1309 // Address book.
1310 else if ($data_type == 14) {
1311 $tmp = '';
1312 if ($currvalue) {
1313 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1314 "WHERE id = ?", array($currvalue) );
1315 $uname = $urow['lname'];
1316 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1317 $tmp = $uname;
1318 if (empty($tmp)) $tmp = "($currvalue)";
1320 /*****************************************************************
1321 echo "<input type='text'" .
1322 " size='$fld_length'" .
1323 " value='$tmp'" .
1324 " class='under'" .
1325 " />";
1326 *****************************************************************/
1327 if ($tmp === '') { $tmp = '&nbsp;'; }
1328 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1329 echo $tmp;
1332 // insurance company list
1333 else if ($data_type == 16) {
1334 $tmp = '';
1335 if ($currvalue) {
1336 $insprovs = getInsuranceProviders();
1337 foreach ($insprovs as $key => $ipname) {
1338 if ($currvalue == $key) {
1339 $tmp = $ipname;
1342 if (empty($tmp)) $tmp = "($currvalue)";
1344 if ($tmp === '') $tmp = '&nbsp;';
1345 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1346 echo $tmp;
1349 // issue types
1350 else if ($data_type == 17) {
1351 $tmp = '';
1352 if ($currvalue) {
1353 foreach ($ISSUE_TYPES as $key => $value) {
1354 if ($currvalue == $key) {
1355 $tmp = $value[1];
1358 if (empty($tmp)) $tmp = "($currvalue)";
1360 if ($tmp === '') $tmp = '&nbsp;';
1361 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1362 echo $tmp;
1365 // Visit categories.
1366 else if ($data_type == 18) {
1367 $tmp = '';
1368 if ($currvalue) {
1369 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1370 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1371 array($currvalue));
1372 $tmp = xl_appt_category($crow['pc_catname']);
1373 if (empty($tmp)) $tmp = "($currvalue)";
1375 if ($tmp === '') { $tmp = '&nbsp;'; }
1376 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES); }
1377 echo $tmp;
1380 // a set of labeled checkboxes
1381 else if ($data_type == 21) {
1382 // In this special case, fld_length is the number of columns generated.
1383 $cols = max(1, $fld_length);
1384 $avalue = explode('|', $currvalue);
1385 $lres = sqlStatement("SELECT * FROM list_options " .
1386 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1387 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1388 $tdpct = (int) (100 / $cols);
1389 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1390 $option_id = $lrow['option_id'];
1391 if ($count % $cols == 0) {
1392 if ($count) echo "</tr>";
1393 echo "<tr>";
1395 echo "<td width='$tdpct%'>";
1396 echo "<input type='checkbox'";
1397 if (in_array($option_id, $avalue)) echo " checked";
1398 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1399 echo "</td>";
1401 if ($count) {
1402 echo "</tr>";
1403 if ($count > $cols) {
1404 // Add some space after multiple rows of checkboxes.
1405 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1406 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1409 echo "</table>";
1412 // a set of labeled text input fields
1413 else if ($data_type == 22) {
1414 $tmp = explode('|', $currvalue);
1415 $avalue = array();
1416 foreach ($tmp as $value) {
1417 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1418 $avalue[$matches[1]] = $matches[2];
1421 $lres = sqlStatement("SELECT * FROM list_options " .
1422 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1423 echo "<table cellpadding='0' cellspacing='0'>";
1424 while ($lrow = sqlFetchArray($lres)) {
1425 $option_id = $lrow['option_id'];
1426 $fldlength = empty($fld_length) ? 20 : $fld_length;
1427 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1428 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1429 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1430 echo "<td><input type='text'" .
1431 " size='$fldlength'" .
1432 " value='$inputValue'" .
1433 " class='under'" .
1434 " /></td></tr>";
1436 echo "</table>";
1439 // a set of exam results; 3 radio buttons and a text field:
1440 else if ($data_type == 23) {
1441 $tmp = explode('|', $currvalue);
1442 $avalue = array();
1443 foreach ($tmp as $value) {
1444 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1445 $avalue[$matches[1]] = $matches[2];
1448 $fldlength = empty($fld_length) ? 20 : $fld_length;
1449 $lres = sqlStatement("SELECT * FROM list_options " .
1450 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1451 echo "<table cellpadding='0' cellspacing='0'>";
1452 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1453 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1454 "&nbsp;</td><td class='bold'>" .
1455 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1456 "<td class='bold'>" .
1457 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1458 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1459 while ($lrow = sqlFetchArray($lres)) {
1460 $option_id = $lrow['option_id'];
1461 $restype = substr($avalue[$option_id], 0, 1);
1462 $resnote = substr($avalue[$option_id], 2);
1463 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1464 for ($i = 0; $i < 3; ++$i) {
1465 echo "<td><input type='radio'";
1466 if ($restype === "$i") echo " checked";
1467 echo " /></td>";
1469 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1470 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1471 echo "<td><input type='text'" .
1472 " size='$fldlength'" .
1473 " value='$resnote'" .
1474 " class='under' /></td>" .
1475 "</tr>";
1477 echo "</table>";
1480 // the list of active allergies for the current patient
1481 // this is read-only!
1482 else if ($data_type == 24) {
1483 $query = "SELECT title, comments FROM lists WHERE " .
1484 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1485 "ORDER BY begdate";
1486 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1487 $count = 0;
1488 while ($lrow = sqlFetchArray($lres)) {
1489 if ($count++) echo "<br />";
1490 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1491 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1495 // a set of labeled checkboxes, each with a text field:
1496 else if ($data_type == 25) {
1497 $tmp = explode('|', $currvalue);
1498 $avalue = array();
1499 foreach ($tmp as $value) {
1500 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1501 $avalue[$matches[1]] = $matches[2];
1504 $fldlength = empty($fld_length) ? 20 : $fld_length;
1505 $lres = sqlStatement("SELECT * FROM list_options " .
1506 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1507 echo "<table cellpadding='0' cellspacing='0'>";
1508 while ($lrow = sqlFetchArray($lres)) {
1509 $option_id = $lrow['option_id'];
1510 $restype = substr($avalue[$option_id], 0, 1);
1511 $resnote = substr($avalue[$option_id], 2);
1512 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1513 echo "<td><input type='checkbox'";
1514 if ($restype) echo " checked";
1515 echo " />&nbsp;</td>";
1516 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1517 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1518 echo "<td><input type='text'" .
1519 " size='$fldlength'" .
1520 " value='$resnote'" .
1521 " class='under'" .
1522 " /></td>" .
1523 "</tr>";
1525 echo "</table>";
1528 // a set of labeled radio buttons
1529 else if ($data_type == 27) {
1530 // In this special case, fld_length is the number of columns generated.
1531 $cols = max(1, $frow['fld_length']);
1532 $lres = sqlStatement("SELECT * FROM list_options " .
1533 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1534 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1535 $tdpct = (int) (100 / $cols);
1536 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1537 $option_id = $lrow['option_id'];
1538 if ($count % $cols == 0) {
1539 if ($count) echo "</tr>";
1540 echo "<tr>";
1542 echo "<td width='$tdpct%'>";
1543 echo "<input type='radio'";
1544 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1545 (strlen($currvalue) > 0 && $option_id == $currvalue))
1547 echo " checked";
1549 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1550 echo "</td>";
1552 if ($count) {
1553 echo "</tr>";
1554 if ($count > $cols) {
1555 // Add some space after multiple rows of radio buttons.
1556 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1557 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1560 echo "</table>";
1563 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1564 else if ($data_type == 28 || $data_type == 32) {
1565 $tmp = explode('|', $currvalue);
1566 switch(count($tmp)) {
1567 case "4": {
1568 $resnote = $tmp[0];
1569 $restype = $tmp[1];
1570 $resdate = $tmp[2];
1571 $reslist = $tmp[3];
1572 } break;
1573 case "3": {
1574 $resnote = $tmp[0];
1575 $restype = $tmp[1];
1576 $resdate = $tmp[2];
1577 } break;
1578 case "2": {
1579 $resnote = $tmp[0];
1580 $restype = $tmp[1];
1581 $resdate = "";
1582 } break;
1583 case "1": {
1584 $resnote = $tmp[0];
1585 $resdate = $restype = "";
1586 } break;
1587 default: {
1588 $restype = $resdate = $resnote = "";
1589 } break;
1591 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1592 echo "<table cellpadding='0' cellspacing='0'>";
1593 echo "<tr>";
1594 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1595 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1596 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1597 if($data_type == 28)
1599 echo "<td><input type='text'" .
1600 " size='$fldlength'" .
1601 " class='under'" .
1602 " value='$resnote' /></td>";
1603 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1604 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1605 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1607 else if($data_type == 32)
1609 echo "<tr><td><input type='text'" .
1610 " size='$fldlength'" .
1611 " class='under'" .
1612 " value='$resnote' /></td></tr>";
1613 $fldlength = 30;
1614 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1615 echo "<td><input type='text'" .
1616 " size='$fldlength'" .
1617 " class='under'" .
1618 " value='$smoking_status_title' /></td>";
1619 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1621 echo "<td><input type='radio'";
1622 if ($restype == "current".$field_id) echo " checked";
1623 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1625 echo "<td><input type='radio'";
1626 if ($restype == "current".$field_id) echo " checked";
1627 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1629 echo "<td><input type='text' size='6'" .
1630 " value='$resdate'" .
1631 " class='under'" .
1632 " /></td>";
1634 echo "<td><input type='radio'";
1635 if ($restype == "current".$field_id) echo " checked";
1636 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1638 echo "<td><input type='radio'";
1639 if ($restype == "not_applicable".$field_id) echo " checked";
1640 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1641 echo "</tr>";
1642 echo "</table>";
1645 // static text. read-only, of course.
1646 else if ($data_type == 31) {
1647 echo nl2br($frow['description']);
1650 else if($data_type == 34){
1651 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;'>";
1652 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1653 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1654 echo "</a>";
1657 //facilities drop-down list
1658 else if ($data_type == 35) {
1659 if (empty($currvalue)){
1660 $currvalue = 0;
1662 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1665 //Multi-select
1666 // Supports backup lists.
1667 else if ($data_type == 36) {
1668 if (empty($fld_length)) {
1669 if ($list_id == 'titles') {
1670 $fld_length = 3;
1671 } else {
1672 $fld_length = 10;
1675 $tmp = '';
1677 $values_array = explode("|", $currvalue);
1679 $i=0;
1680 foreach($values_array as $value) {
1681 if ($value) {
1682 $lrow = sqlQuery("SELECT title FROM list_options " .
1683 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1684 $tmp = xl_list_label($lrow['title']);
1685 if ($lrow == 0 && !empty($backup_list)) {
1686 // since primary list did not map, try to map to backup list
1687 $lrow = sqlQuery("SELECT title FROM list_options " .
1688 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1689 $tmp = xl_list_label($lrow['title']);
1691 if (empty($tmp)) $tmp = "($value)";
1694 if ($tmp === '') {
1695 $tmp = '&nbsp;';
1697 else {
1698 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1700 if ($i != 0 && $tmp != '&nbsp;') echo ",";
1701 echo $tmp;
1702 $i++;
1706 // Image from canvas drawing
1707 else if ($data_type == 40) {
1708 echo "<img src='" . attr($currvalue) . "'>";
1713 function generate_display_field($frow, $currvalue) {
1714 global $ISSUE_TYPES;
1716 $data_type = $frow['data_type'];
1717 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1718 $list_id = $frow['list_id'];
1719 $backup_list = isset($frow['list_backup_id']) ? $frow['list_backup_id'] : null;
1721 $s = '';
1723 // generic selection list or the generic selection list with add on the fly
1724 // feature, or radio buttons
1725 // Supports backup lists for datatypes 1,26,33
1726 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1727 $lrow = sqlQuery("SELECT title FROM list_options " .
1728 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
1729 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1730 //if there is no matching value in the corresponding lists check backup list
1731 // only supported in data types 1,26,33
1732 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1733 $lrow = sqlQuery("SELECT title FROM list_options " .
1734 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
1735 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1739 // simple text field
1740 else if ($data_type == 2) {
1741 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1744 // long or multi-line text field
1745 else if ($data_type == 3) {
1746 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1749 // date
1750 else if ($data_type == 4) {
1751 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1752 $s = '';
1753 $agestr = optionalAge($frow, $currvalue, $asof);
1754 if ($agestr) {
1755 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1757 if ($currvalue === '') {
1758 $s .= '&nbsp;';
1760 else {
1761 $s .= text(oeFormatShortDate($currvalue));
1763 // Optional display of age or gestational age.
1764 if ($agestr) {
1765 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1769 // provider
1770 else if ($data_type == 10 || $data_type == 11) {
1771 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1772 "WHERE id = ?", array($currvalue) );
1773 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1776 // pharmacy list
1777 else if ($data_type == 12) {
1778 $pres = get_pharmacies();
1779 while ($prow = sqlFetchArray($pres)) {
1780 $key = $prow['id'];
1781 if ($currvalue == $key) {
1782 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1783 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1784 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1789 // squads
1790 else if ($data_type == 13) {
1791 $squads = acl_get_squads();
1792 if ($squads) {
1793 foreach ($squads as $key => $value) {
1794 if ($currvalue == $key) {
1795 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1801 // address book
1802 else if ($data_type == 14) {
1803 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
1804 "WHERE id = ?", array($currvalue));
1805 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
1806 if($urow['organization'] !=""){
1807 $uname = $urow['organization'];
1808 }else{
1809 $uname = $urow['lname'];
1810 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1812 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1815 // billing code
1816 else if ($data_type == 15) {
1817 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1820 // insurance company list
1821 else if ($data_type == 16) {
1822 $insprovs = getInsuranceProviders();
1823 foreach ($insprovs as $key => $ipname) {
1824 if ($currvalue == $key) {
1825 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
1830 // issue types
1831 else if ($data_type == 17) {
1832 foreach ($ISSUE_TYPES as $key => $value) {
1833 if ($currvalue == $key) {
1834 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
1839 // visit category
1840 else if ($data_type == 18) {
1841 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1842 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1843 array($currvalue));
1844 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES);
1847 // a set of labeled checkboxes
1848 else if ($data_type == 21) {
1849 $avalue = explode('|', $currvalue);
1850 $lres = sqlStatement("SELECT * FROM list_options " .
1851 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1852 $count = 0;
1853 while ($lrow = sqlFetchArray($lres)) {
1854 $option_id = $lrow['option_id'];
1855 if (in_array($option_id, $avalue)) {
1856 if ($count++) $s .= "<br />";
1858 // Added 5-09 by BM - Translate label if applicable
1859 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES);
1865 // a set of labeled text input fields
1866 else if ($data_type == 22) {
1867 $tmp = explode('|', $currvalue);
1868 $avalue = array();
1869 foreach ($tmp as $value) {
1870 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1871 $avalue[$matches[1]] = $matches[2];
1874 $lres = sqlStatement("SELECT * FROM list_options " .
1875 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1876 $s .= "<table cellpadding='0' cellspacing='0'>";
1877 while ($lrow = sqlFetchArray($lres)) {
1878 $option_id = $lrow['option_id'];
1879 if (empty($avalue[$option_id])) continue;
1881 // Added 5-09 by BM - Translate label if applicable
1882 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1884 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1886 $s .= "</table>";
1889 // a set of exam results; 3 radio buttons and a text field:
1890 else if ($data_type == 23) {
1891 $tmp = explode('|', $currvalue);
1892 $avalue = array();
1893 foreach ($tmp as $value) {
1894 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1895 $avalue[$matches[1]] = $matches[2];
1898 $lres = sqlStatement("SELECT * FROM list_options " .
1899 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1900 $s .= "<table cellpadding='0' cellspacing='0'>";
1901 while ($lrow = sqlFetchArray($lres)) {
1902 $option_id = $lrow['option_id'];
1903 $restype = substr($avalue[$option_id], 0, 1);
1904 $resnote = substr($avalue[$option_id], 2);
1905 if (empty($restype) && empty($resnote)) continue;
1907 // Added 5-09 by BM - Translate label if applicable
1908 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1910 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1911 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1912 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1913 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1914 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1915 $s .= "</tr>";
1917 $s .= "</table>";
1920 // the list of active allergies for the current patient
1921 else if ($data_type == 24) {
1922 $query = "SELECT title, comments FROM lists WHERE " .
1923 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1924 "ORDER BY begdate";
1925 // echo "<!-- $query -->\n"; // debugging
1926 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1927 $count = 0;
1928 while ($lrow = sqlFetchArray($lres)) {
1929 if ($count++) $s .= "<br />";
1930 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1931 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1935 // a set of labeled checkboxes, each with a text field:
1936 else if ($data_type == 25) {
1937 $tmp = explode('|', $currvalue);
1938 $avalue = array();
1939 foreach ($tmp as $value) {
1940 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1941 $avalue[$matches[1]] = $matches[2];
1944 $lres = sqlStatement("SELECT * FROM list_options " .
1945 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1946 $s .= "<table cellpadding='0' cellspacing='0'>";
1947 while ($lrow = sqlFetchArray($lres)) {
1948 $option_id = $lrow['option_id'];
1949 $restype = substr($avalue[$option_id], 0, 1);
1950 $resnote = substr($avalue[$option_id], 2);
1951 if (empty($restype) && empty($resnote)) continue;
1953 // Added 5-09 by BM - Translate label if applicable
1954 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1956 $restype = $restype ? xl('Yes') : xl('No');
1957 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1958 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1959 $s .= "</tr>";
1961 $s .= "</table>";
1964 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1965 // VicarePlus :: A selection list for smoking status.
1966 else if ($data_type == 28 || $data_type == 32) {
1967 $tmp = explode('|', $currvalue);
1968 switch(count($tmp)) {
1969 case "4": {
1970 $resnote = $tmp[0];
1971 $restype = $tmp[1];
1972 $resdate = $tmp[2];
1973 $reslist = $tmp[3];
1974 } break;
1975 case "3": {
1976 $resnote = $tmp[0];
1977 $restype = $tmp[1];
1978 $resdate = $tmp[2];
1979 } break;
1980 case "2": {
1981 $resnote = $tmp[0];
1982 $restype = $tmp[1];
1983 $resdate = "";
1984 } break;
1985 case "1": {
1986 $resnote = $tmp[0];
1987 $resdate = $restype = "";
1988 } break;
1989 default: {
1990 $restype = $resdate = $resnote = "";
1991 } break;
1993 $s .= "<table cellpadding='0' cellspacing='0'>";
1995 $s .= "<tr>";
1996 $res = "";
1997 if ($restype == "current".$field_id) $res = xl('Current');
1998 if ($restype == "quit".$field_id) $res = xl('Quit');
1999 if ($restype == "never".$field_id) $res = xl('Never');
2000 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
2001 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2002 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2003 if ($data_type == 28)
2005 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2007 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2008 else if ($data_type == 32)
2009 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2010 $smoke_codes = getSmokeCodes();
2011 if (!empty($reslist)) {
2012 if($smoke_codes[$reslist]!="")
2013 $code_desc = "( ".$smoke_codes[$reslist]." )";
2015 $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>";}
2017 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2020 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
2021 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
2022 $s .= "</tr>";
2023 $s .= "</table>";
2026 // static text. read-only, of course.
2027 else if ($data_type == 31) {
2028 $s .= nl2br($frow['description']);
2031 else if($data_type == 34){
2032 $arr = explode("|*|*|*|",$currvalue);
2033 for($i=0;$i<sizeof($arr);$i++){
2034 $s.=$arr[$i];
2038 // facility
2039 else if ($data_type == 35) {
2040 $urow = sqlQuery("SELECT id, name FROM facility ".
2041 "WHERE id = ?", array($currvalue) );
2042 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
2045 // Multi select
2046 // Supports backup lists
2047 else if ($data_type == 36) {
2048 $values_array = explode("|", $currvalue);
2049 $i = 0;
2050 foreach($values_array as $value) {
2051 $lrow = sqlQuery("SELECT title FROM list_options " .
2052 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2053 if ($lrow == 0 && !empty($backup_list)) {
2054 //use back up list
2055 $lrow = sqlQuery("SELECT title FROM list_options " .
2056 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2058 if ($i > 0) {
2059 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2060 } else {
2061 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2063 $i++;
2067 // Image from canvas drawing
2068 else if ($data_type == 40) {
2069 $s .= "<img src='" . attr($currvalue) . "'>";
2072 return $s;
2075 // Generate plain text versions of selected LBF field types.
2076 // Currently used by interface/patient_file/download_template.php.
2077 // More field types might need to be supported here in the future.
2079 function generate_plaintext_field($frow, $currvalue) {
2080 global $ISSUE_TYPES;
2082 $data_type = $frow['data_type'];
2083 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2084 $list_id = $frow['list_id'];
2085 $backup_list = $frow['backup_list'];
2086 $s = '';
2088 // generic selection list or the generic selection list with add on the fly
2089 // feature, or radio buttons
2090 // Supports backup lists (for datatypes 1,26,33)
2091 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2092 $lrow = sqlQuery("SELECT title FROM list_options " .
2093 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
2094 $s = xl_list_label($lrow['title']);
2095 //if there is no matching value in the corresponding lists check backup list
2096 // only supported in data types 1,26,33
2097 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2098 $lrow = sqlQuery("SELECT title FROM list_options " .
2099 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
2100 $s = xl_list_label($lrow['title']);
2104 // simple or long text field
2105 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2106 $s = $currvalue;
2109 // date
2110 else if ($data_type == 4) {
2111 $s = oeFormatShortDate($currvalue);
2112 // Optional display of age or gestational age.
2113 $asof=''; //not used here, but set to prevent a php warning when call optionalAge
2114 $tmp = optionalAge($frow, $currvalue,$asof);
2115 if ($tmp) $s .= ' ' . $tmp;
2118 // provider
2119 else if ($data_type == 10 || $data_type == 11) {
2120 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2121 "WHERE id = ?", array($currvalue) );
2122 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2125 // pharmacy list
2126 else if ($data_type == 12) {
2127 $pres = get_pharmacies();
2128 while ($prow = sqlFetchArray($pres)) {
2129 $key = $prow['id'];
2130 if ($currvalue == $key) {
2131 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2132 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2133 $prow['line1'] . ' / ' . $prow['city'];
2138 // address book
2139 else if ($data_type == 14) {
2140 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2141 "WHERE id = ?", array($currvalue));
2142 $uname = $urow['lname'];
2143 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2144 $s = $uname;
2147 // insurance company list
2148 else if ($data_type == 16) {
2149 $insprovs = getInsuranceProviders();
2150 foreach ($insprovs as $key => $ipname) {
2151 if ($currvalue == $key) {
2152 $s .= $ipname;
2157 // issue type
2158 else if ($data_type == 17) {
2159 foreach ($ISSUE_TYPES as $key => $value) {
2160 if ($currvalue == $key) {
2161 $s .= $value[1];
2166 // visit category
2167 else if ($data_type == 18) {
2168 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2169 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2170 array($currvalue));
2171 $s = $crow['pc_catname'];
2174 // a set of labeled checkboxes
2175 else if ($data_type == 21) {
2176 $avalue = explode('|', $currvalue);
2177 $lres = sqlStatement("SELECT * FROM list_options " .
2178 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2179 $count = 0;
2180 while ($lrow = sqlFetchArray($lres)) {
2181 $option_id = $lrow['option_id'];
2182 if (in_array($option_id, $avalue)) {
2183 if ($count++) $s .= "; ";
2184 $s .= xl_list_label($lrow['title']);
2189 // a set of labeled text input fields
2190 else if ($data_type == 22) {
2191 $tmp = explode('|', $currvalue);
2192 $avalue = array();
2193 foreach ($tmp as $value) {
2194 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2195 $avalue[$matches[1]] = $matches[2];
2198 $lres = sqlStatement("SELECT * FROM list_options " .
2199 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2200 while ($lrow = sqlFetchArray($lres)) {
2201 $option_id = $lrow['option_id'];
2202 if (empty($avalue[$option_id])) continue;
2203 if ($s !== '') $s .= '; ';
2204 $s .= xl_list_label($lrow['title']) . ': ';
2205 $s .= $avalue[$option_id];
2209 // A set of exam results; 3 radio buttons and a text field.
2210 // This shows abnormal results only.
2211 else if ($data_type == 23) {
2212 $tmp = explode('|', $currvalue);
2213 $avalue = array();
2214 foreach ($tmp as $value) {
2215 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2216 $avalue[$matches[1]] = $matches[2];
2219 $lres = sqlStatement("SELECT * FROM list_options " .
2220 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2221 while ($lrow = sqlFetchArray($lres)) {
2222 $option_id = $lrow['option_id'];
2223 $restype = substr($avalue[$option_id], 0, 1);
2224 $resnote = substr($avalue[$option_id], 2);
2225 if (empty($restype) && empty($resnote)) continue;
2226 if ($restype != '2') continue; // show abnormal results only
2227 if ($s !== '') $s .= '; ';
2228 $s .= xl_list_label($lrow['title']);
2229 if (!empty($resnote)) $s .= ': ' . $resnote;
2233 // the list of active allergies for the current patient
2234 else if ($data_type == 24) {
2235 $query = "SELECT title, comments FROM lists WHERE " .
2236 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2237 "ORDER BY begdate";
2238 $lres = sqlStatement($query, array($GLOBALS['pid']));
2239 $count = 0;
2240 while ($lrow = sqlFetchArray($lres)) {
2241 if ($count++) $s .= "; ";
2242 $s .= $lrow['title'];
2243 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2247 // a set of labeled checkboxes, each with a text field:
2248 else if ($data_type == 25) {
2249 $tmp = explode('|', $currvalue);
2250 $avalue = array();
2251 foreach ($tmp as $value) {
2252 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2253 $avalue[$matches[1]] = $matches[2];
2256 $lres = sqlStatement("SELECT * FROM list_options " .
2257 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2258 while ($lrow = sqlFetchArray($lres)) {
2259 $option_id = $lrow['option_id'];
2260 $restype = substr($avalue[$option_id], 0, 1);
2261 $resnote = substr($avalue[$option_id], 2);
2262 if (empty($restype) && empty($resnote)) continue;
2263 if ($s !== '') $s .= '; ';
2264 $s .= xl_list_label($lrow['title']);
2265 $restype = $restype ? xl('Yes') : xl('No');
2266 $s .= $restype;
2267 if ($resnote) $s .= ' ' . $resnote;
2271 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2272 // VicarePlus :: A selection list for smoking status.
2273 else if ($data_type == 28 || $data_type == 32) {
2274 $tmp = explode('|', $currvalue);
2275 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2276 $restype = count($tmp) > 1 ? $tmp[1] : '';
2277 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2278 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2279 $res = "";
2280 if ($restype == "current" . $field_id) $res = xl('Current');
2281 if ($restype == "quit" . $field_id) $res = xl('Quit');
2282 if ($restype == "never" . $field_id) $res = xl('Never');
2283 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2285 if ($data_type == 28) {
2286 if (!empty($resnote)) $s .= $resnote;
2288 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2289 else if ($data_type == 32) {
2290 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2291 if (!empty($resnote)) $s .= ' ' . $resnote;
2293 if (!empty($res)) {
2294 if ($s !== '') $s .= ' ';
2295 $s .= xl('Status') . ' ' . $res;
2297 if ($restype == "quit".$field_id) {
2298 if ($s !== '') $s .= ' ';
2299 $s .= $resdate;
2303 // Multi select
2304 // Supports backup lists
2305 else if ($data_type == 36) {
2306 $values_array = explode("|", $currvalue);
2308 $i = 0;
2309 foreach($values_array as $value) {
2310 $lrow = sqlQuery("SELECT title FROM list_options " .
2311 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2313 if ($lrow == 0 && !empty($backup_list)) {
2314 //use back up list
2315 $lrow = sqlQuery("SELECT title FROM list_options " .
2316 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2319 if ($i > 0) {
2320 $s = $s . ", " . xl_list_label($lrow['title']);
2321 } else {
2322 $s = xl_list_label($lrow['title']);
2325 $i++;
2329 return $s;
2332 $CPR = 4; // cells per row of generic data
2333 $last_group = '';
2334 $cell_count = 0;
2335 $item_count = 0;
2337 function disp_end_cell() {
2338 global $item_count, $cell_count;
2339 if ($item_count > 0) {
2340 echo "</td>";
2341 $item_count = 0;
2345 function disp_end_row() {
2346 global $cell_count, $CPR;
2347 disp_end_cell();
2348 if ($cell_count > 0) {
2349 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
2350 echo "</tr>\n";
2351 $cell_count = 0;
2355 function disp_end_group() {
2356 global $last_group;
2357 if (strlen($last_group) > 0) {
2358 disp_end_row();
2362 function display_layout_rows($formtype, $result1, $result2='') {
2363 global $item_count, $cell_count, $last_group, $CPR;
2365 $fres = sqlStatement("SELECT * FROM layout_options " .
2366 "WHERE form_id = ? AND uor > 0 " .
2367 "ORDER BY group_name, seq", array($formtype) );
2369 while ($frow = sqlFetchArray($fres)) {
2370 $this_group = $frow['group_name'];
2371 $titlecols = $frow['titlecols'];
2372 $datacols = $frow['datacols'];
2373 $data_type = $frow['data_type'];
2374 $field_id = $frow['field_id'];
2375 $list_id = $frow['list_id'];
2376 $currvalue = '';
2378 if ($formtype == 'DEM') {
2379 if (strpos($field_id, 'em_') === 0) {
2380 // Skip employer related fields, if it's disabled.
2381 if ($GLOBALS['omit_employers']) continue;
2382 $tmp = substr($field_id, 3);
2383 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2385 else {
2386 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2389 else {
2390 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2393 // Handle a data category (group) change.
2394 if (strcmp($this_group, $last_group) != 0) {
2395 $group_name = substr($this_group, 1);
2396 // totally skip generating the employer category, if it's disabled.
2397 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2398 disp_end_group();
2399 $last_group = $this_group;
2402 // filter out all the empty field data from the patient report.
2403 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2404 // Handle starting of a new row.
2405 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2406 disp_end_row();
2407 echo "<tr>";
2408 if ($group_name) {
2409 echo "<td class='groupname'>";
2410 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2411 //echo "<font color='#008800'>$group_name</font>";
2413 // Added 5-09 by BM - Translate label if applicable
2414 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
2416 $group_name = '';
2417 } else {
2418 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2419 echo "<td valign='top'>&nbsp;";
2421 echo "</td>";
2424 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2426 // Handle starting of a new label cell.
2427 if ($titlecols > 0) {
2428 disp_end_cell();
2429 //echo "<td class='label' colspan='$titlecols' valign='top'";
2430 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2431 echo "<td class='label' colspan='$titlecols_esc' ";
2432 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2433 echo ">";
2434 $cell_count += $titlecols;
2436 ++$item_count;
2438 // Added 5-09 by BM - Translate label if applicable
2439 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2441 // Handle starting of a new data cell.
2442 if ($datacols > 0) {
2443 disp_end_cell();
2444 //echo "<td class='text data' colspan='$datacols' valign='top'";
2445 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2446 echo "<td class='text data' colspan='$datacols_esc'";
2447 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2448 echo ">";
2449 $cell_count += $datacols;
2452 ++$item_count;
2453 echo generate_display_field($frow, $currvalue);
2457 disp_end_group();
2460 function display_layout_tabs($formtype, $result1, $result2='') {
2461 global $item_count, $cell_count, $last_group, $CPR;
2463 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2464 "WHERE form_id = ? AND uor > 0 " .
2465 "ORDER BY group_name, seq", array($formtype) );
2467 $first = true;
2468 while ($frow = sqlFetchArray($fres)) {
2469 $this_group = $frow['group_name'];
2470 $group_name = substr($this_group, 1);
2471 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2473 <li <?php echo $first ? 'class="current"' : '' ?>>
2474 <a href="#" id="header_tab_<?php echo str_replace(" ", "_",htmlspecialchars($group_name,ENT_QUOTES))?>">
2475 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
2476 </li>
2477 <?php
2478 $first = false;
2482 function display_layout_tabs_data($formtype, $result1, $result2='') {
2483 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2485 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2486 "WHERE form_id = ? AND uor > 0 " .
2487 "ORDER BY group_name, seq", array($formtype));
2489 $first = true;
2490 while ($frow = sqlFetchArray($fres)) {
2491 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
2492 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
2493 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
2494 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
2495 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
2496 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
2497 $currvalue = '';
2499 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2501 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2502 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2503 "ORDER BY seq", array($formtype, $this_group) );
2506 <div class="tab <?php echo $first ? 'current' : '' ?>">
2507 <table border='0' cellpadding='0'>
2509 <?php
2510 while ($group_fields = sqlFetchArray($group_fields_query)) {
2512 $titlecols = $group_fields['titlecols'];
2513 $datacols = $group_fields['datacols'];
2514 $data_type = $group_fields['data_type'];
2515 $field_id = $group_fields['field_id'];
2516 $list_id = $group_fields['list_id'];
2517 $currvalue = '';
2518 $condition_str = get_conditions_str($condition_str,$group_fields);
2521 if ($formtype == 'DEM') {
2522 if (strpos($field_id, 'em_') === 0) {
2523 // Skip employer related fields, if it's disabled.
2524 if ($GLOBALS['omit_employers']) continue;
2525 $tmp = substr($field_id, 3);
2526 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2528 else {
2529 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2532 else {
2533 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2536 // Handle a data category (group) change.
2537 if (strcmp($this_group, $last_group) != 0) {
2538 $group_name = substr($this_group, 1);
2539 // totally skip generating the employer category, if it's disabled.
2540 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2541 $last_group = $this_group;
2544 // Handle starting of a new row.
2545 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2546 disp_end_row();
2547 echo "<tr>";
2550 if ($item_count == 0 && $titlecols == 0) {
2551 $titlecols = 1;
2554 // Handle starting of a new label cell.
2555 if ($titlecols > 0) {
2556 disp_end_cell();
2557 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2558 $field_id_label = 'label_'.$group_fields['field_id'];
2559 echo "<td class='label' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
2560 echo ">";
2561 $cell_count += $titlecols;
2563 ++$item_count;
2565 $field_id_label = 'label_'.$group_fields['field_id'];
2566 echo "<span id='".attr($field_id_label)."'>";
2567 // Added 5-09 by BM - Translate label if applicable
2568 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2569 echo "</span>";
2571 // Handle starting of a new data cell.
2572 if ($datacols > 0) {
2573 disp_end_cell();
2574 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2575 $field_id = 'text_'.$group_fields['field_id'];
2576 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
2577 echo ">";
2578 $cell_count += $datacols;
2579 } else {
2580 $field_id = 'text_'.$group_fields['field_id'];
2581 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
2584 ++$item_count;
2585 echo generate_display_field($group_fields, $currvalue);
2588 disp_end_row();
2591 </table>
2592 </div>
2594 <?php
2596 $first = false;
2602 function get_conditions_str($condition_str,$frow){
2603 $conditions = empty($frow['conditions']) ? array() : unserialize($frow['conditions']);
2604 foreach ($conditions as $condition) {
2605 if (empty($condition['id'])) continue;
2606 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2607 if ($condition_str) $condition_str .= ",\n";
2608 $condition_str .= "{" .
2609 "target:'" . addslashes($frow['field_id']) . "', " .
2610 "id:'" . addslashes($condition['id']) . "', " .
2611 "itemid:'" . addslashes($condition['itemid']) . "', " .
2612 "operator:'" . addslashes($condition['operator']) . "', " .
2613 "value:'" . addslashes($condition['value']) . "', " .
2614 "andor:'" . addslashes($andor) . "'}";
2616 return $condition_str;
2618 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2619 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2621 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2622 "WHERE form_id = ? AND uor > 0 " .
2623 "ORDER BY group_name, seq", array($formtype) );
2625 $first = true;
2626 while ($frow = sqlFetchArray($fres)) {
2627 $this_group = $frow['group_name'];
2628 $group_name = substr($this_group, 1);
2629 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
2630 $titlecols = $frow['titlecols'];
2631 $datacols = $frow['datacols'];
2632 $data_type = $frow['data_type'];
2633 $field_id = $frow['field_id'];
2634 $list_id = $frow['list_id'];
2635 $currvalue = '';
2637 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2639 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2640 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2641 "ORDER BY seq", array($formtype,$this_group) );
2644 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_',$group_name_esc)?>" >
2645 <table border='0' cellpadding='0'>
2647 <?php
2648 while ($group_fields = sqlFetchArray($group_fields_query)) {
2650 $titlecols = $group_fields['titlecols'];
2651 $datacols = $group_fields['datacols'];
2652 $data_type = $group_fields['data_type'];
2653 $field_id = $group_fields['field_id'];
2654 $list_id = $group_fields['list_id'];
2655 $backup_list = $group_fields['list_backup_id'];
2656 $condition_str = get_conditions_str($condition_str,$group_fields);
2657 $currvalue = '';
2659 if ($formtype == 'DEM') {
2660 if (strpos($field_id, 'em_') === 0) {
2661 // Skip employer related fields, if it's disabled.
2662 if ($GLOBALS['omit_employers']) continue;
2663 $tmp = substr($field_id, 3);
2664 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2666 else {
2667 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2670 else {
2671 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2674 // Handle a data category (group) change.
2675 if (strcmp($this_group, $last_group) != 0) {
2676 $group_name = substr($this_group, 1);
2677 // totally skip generating the employer category, if it's disabled.
2678 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2679 $last_group = $this_group;
2682 // Handle starting of a new row.
2683 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2684 disp_end_row();
2685 echo "<tr>";
2688 if ($item_count == 0 && $titlecols == 0) {
2689 $titlecols = 1;
2692 // Handle starting of a new label cell.
2693 if ($titlecols > 0) {
2694 disp_end_cell();
2695 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2696 $field_id_label = 'label_'.$group_fields['field_id'];
2697 echo "<td class='label' colspan='$titlecols_esc' id='$field_id_label' ";
2698 echo ">";
2699 $cell_count += $titlecols;
2701 ++$item_count;
2703 // Added 5-09 by BM - Translate label if applicable
2704 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
2706 // Handle starting of a new data cell.
2707 if ($datacols > 0) {
2708 disp_end_cell();
2709 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2710 $field_id = 'text_'.$group_fields['field_id'];
2711 echo "<td class='text data' colspan='$datacols_esc' id='$field_id'";
2712 echo ">";
2713 $cell_count += $datacols;
2716 ++$item_count;
2718 echo generate_form_field($group_fields, $currvalue);
2722 </table>
2723 </div>
2725 <?php
2727 $first = false;
2732 // From the currently posted HTML form, this gets the value of the
2733 // field corresponding to the provided layout_options table row.
2735 function get_layout_form_value($frow, $prefix='form_') {
2736 // Bring in $sanitize_all_escapes variable, which will decide
2737 // the variable escaping method.
2738 global $sanitize_all_escapes;
2740 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
2741 $data_type = $frow['data_type'];
2742 $field_id = $frow['field_id'];
2743 $value = '';
2744 if (isset($_POST["$prefix$field_id"])) {
2745 if ($data_type == 21) {
2746 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2747 // must be concatenated into a |-separated string.
2748 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2749 if (strlen($value)) $value .= '|';
2750 $value .= $key;
2753 else if ($data_type == 22) {
2754 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2755 // into "key:value|key:value|...".
2756 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2757 $val = str_replace('|', ' ', $val);
2758 if (strlen($value)) $value .= '|';
2759 $value .= "$key:$val";
2762 else if ($data_type == 23) {
2763 // $_POST["$prefix$field_id"] is an array of text fields with companion
2764 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2765 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2766 $restype = $_POST["radio_{$field_id}"][$key];
2767 if (empty($restype)) $restype = '0';
2768 $val = str_replace('|', ' ', $val);
2769 if (strlen($value)) $value .= '|';
2770 $value .= "$key:$restype:$val";
2773 else if ($data_type == 25) {
2774 // $_POST["$prefix$field_id"] is an array of text fields with companion
2775 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2776 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2777 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
2778 $val = str_replace('|', ' ', $val);
2779 if (strlen($value)) $value .= '|';
2780 $value .= "$key:$restype:$val";
2783 else if ($data_type == 28 || $data_type == 32) {
2784 // $_POST["$prefix$field_id"] is an date text fields with companion
2785 // radio buttons to be imploded into "notes|type|date".
2786 $restype = $_POST["radio_{$field_id}"];
2787 if (empty($restype)) $restype = '0';
2788 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2789 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2790 if ($data_type == 32)
2792 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2793 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2794 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2795 $value = "$res_text_note|$restype|$resdate|$reslist";
2797 else
2798 $value = "$resnote|$restype|$resdate";
2800 else if ($data_type == 36) {
2801 $value_array = $_POST["form_$field_id"];
2802 $i = 0;
2803 foreach ($value_array as $key => $valueofkey) {
2804 if ($i == 0) {
2805 $value = $valueofkey;
2806 } else {
2807 $value = $value . "|" . $valueofkey;
2809 $i++;
2812 else {
2813 $value = $_POST["$prefix$field_id"];
2817 // Better to die than to silently truncate data!
2818 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2819 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2820 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2822 // Make sure the return value is quote-safe.
2823 if ($sanitize_all_escapes) {
2824 //escapes already removed and using binding/placemarks in sql calls
2825 // so only need to trim value
2826 return trim($value);
2828 else {
2829 //need to explicitly prepare value
2830 return formTrim($value);
2834 // Generate JavaScript validation logic for the required fields.
2836 function generate_layout_validation($form_id) {
2837 $fres = sqlStatement("SELECT * FROM layout_options " .
2838 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2839 "ORDER BY group_name, seq", array($form_id) );
2841 while ($frow = sqlFetchArray($fres)) {
2842 $data_type = $frow['data_type'];
2843 $field_id = $frow['field_id'];
2844 $fldtitle = $frow['title'];
2845 if (!$fldtitle) $fldtitle = $frow['description'];
2846 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES);
2848 if ($data_type == 40) {
2849 $fldid = addslashes("form_$field_id");
2850 // Move canvas image data to its hidden form field so the server will get it.
2851 echo
2852 " var canfld = f['$fldid'];\n" .
2853 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
2854 continue;
2857 if ($frow['uor'] < 2) continue;
2859 switch($data_type) {
2860 case 1:
2861 case 11:
2862 case 12:
2863 case 13:
2864 case 14:
2865 case 26:
2866 case 33:
2867 echo
2868 " if (f.$fldname.selectedIndex <= 0) {\n" .
2869 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2870 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2871 " }\n";
2872 break;
2873 case 27: // radio buttons
2874 echo
2875 " var i = 0;\n" .
2876 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2877 " if (i >= f.$fldname.length) {\n" .
2878 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2879 " }\n";
2880 break;
2881 case 2:
2882 case 3:
2883 case 4:
2884 case 15:
2885 echo
2886 " if (trimlen(f.$fldname.value) == 0) {\n" .
2887 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2888 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2889 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2890 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2891 " } else { " .
2892 " $('#" . $fldname . "').attr('style',''); " .
2893 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2894 " } \n";
2895 break;
2896 case 36: // multi select
2897 echo
2898 " var multi_select=f['$fldname"."[]']; \n " .
2899 " var multi_choice_made=false; \n".
2900 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
2901 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
2902 " } \n" .
2903 " if(!multi_choice_made)
2904 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2906 break;
2912 * DROPDOWN FOR FACILITIES
2914 * build a dropdown with all facilities
2916 * @param string $selected - name of the currently selected facility
2917 * use '0' for "unspecified facility"
2918 * use '' for "All facilities" (the default)
2919 * @param string $name - the name/id for select form (defaults to "form_facility")
2920 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2921 * defaults to true
2922 * @return void - just echo the html encoded string
2924 * Note: This should become a data-type at some point, according to Brady
2926 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2927 $allow_allfacilities = true, $disabled='', $onchange='')
2929 $have_selected = false;
2930 $query = "SELECT id, name FROM facility ORDER BY name";
2931 $fres = sqlStatement($query);
2933 $name = htmlspecialchars($name, ENT_QUOTES);
2934 echo " <select name='$name' id='$name'";
2935 if ($onchange) echo " onchange='$onchange'";
2936 echo " $disabled>\n";
2938 if ($allow_allfacilities) {
2939 $option_value = '';
2940 $option_selected_attr = '';
2941 if ($selected == '') {
2942 $option_selected_attr = ' selected="selected"';
2943 $have_selected = true;
2945 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2946 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2947 } elseif ($allow_unspecified) {
2948 $option_value = '0';
2949 $option_selected_attr = '';
2950 if ( $selected == '0' ) {
2951 $option_selected_attr = ' selected="selected"';
2952 $have_selected = true;
2954 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2955 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2958 while ($frow = sqlFetchArray($fres)) {
2959 $facility_id = $frow['id'];
2960 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2961 $option_selected_attr = '';
2962 if ($selected == $facility_id) {
2963 $option_selected_attr = ' selected="selected"';
2964 $have_selected = true;
2966 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2967 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2970 if ($allow_unspecified && $allow_allfacilities) {
2971 $option_value = '0';
2972 $option_selected_attr = '';
2973 if ( $selected == '0' ) {
2974 $option_selected_attr = ' selected="selected"';
2975 $have_selected = true;
2977 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2978 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2981 if (!$have_selected) {
2982 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2983 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2984 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2985 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2987 echo " </select>\n";
2990 // Expand Collapse Widget
2991 // This forms the header and functionality component of the widget. The information that is displayed
2992 // then follows this function followed by a closing div tag
2994 // $title is the title of the section (already translated)
2995 // $label is identifier used in the tag id's and sql columns
2996 // $buttonLabel is the button label text (already translated)
2997 // $buttonLink is the button link information
2998 // $buttonClass is any additional needed class elements for the button tag
2999 // $linkMethod is the button link method ('javascript' vs 'html')
3000 // $bodyClass is to set class(es) of the body
3001 // $auth is a flag to decide whether to show the button
3002 // $fixedWidth is to flag whether width is fixed
3003 // $forceExpandAlways is a flag to force the widget to always be expanded
3005 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
3006 if ($fixedWidth) {
3007 echo "<div class='section-header'>";
3009 else {
3010 echo "<div class='section-header-dynamic'>";
3012 echo "<table><tr>";
3013 if ($auth) {
3014 // show button, since authorized
3015 // first prepare class string
3016 if ($buttonClass) {
3017 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
3019 else {
3020 $class_string = "css_button_small";
3022 // next, create the link
3023 if ($linkMethod == "javascript") {
3024 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3026 else {
3027 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3028 if (!isset($_SESSION['patient_portal_onsite'])) {
3029 // prevent an error from occuring when calling the function from the patient portal
3030 echo " onclick='top.restoreSession()'";
3033 echo "><span>" .
3034 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
3036 if ($forceExpandAlways){
3037 // Special case to force the widget to always be expanded
3038 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
3039 $indicatorTag ="style='display:none'";
3041 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3042 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3043 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
3044 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
3046 if (isset($_SESSION['patient_portal_onsite'])) {
3047 // collapse all entries in the patient portal
3048 $text = xl('expand');
3050 else if (getUserSetting($label."_ps_expand")) {
3051 $text = xl('collapse');
3053 else {
3054 $text = xl('expand');
3056 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
3057 "</span>)</a></td>";
3058 echo "</tr></table>";
3059 echo "</div>";
3060 if ($forceExpandAlways) {
3061 // Special case to force the widget to always be expanded
3062 $styling = "";
3064 else if (isset($_SESSION['patient_portal_onsite'])) {
3065 // collapse all entries in the patient portal
3066 $styling = "style='display:none'";
3068 else if (getUserSetting($label."_ps_expand")) {
3069 $styling = "";
3071 else {
3072 $styling = "style='display:none'";
3074 if ($bodyClass) {
3075 $styling .= " class='" . $bodyClass . "'";
3077 //next, create the first div tag to hold the information
3078 // note the code that calls this function will then place the ending div tag after the data
3079 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
3082 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3083 function billing_facility($name,$select){
3084 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
3085 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3086 while ($facrow = sqlFetchArray($qsql)) {
3087 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3088 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3090 echo "</select>";
3093 // Generic function to get the translated title value for a particular list option.
3095 function getListItemTitle($list, $option) {
3096 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3097 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3098 if (empty($row['title'])) return $option;
3099 return xl_list_label($row['title']);
3101 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3102 function getSmokeCodes()
3104 $smoking_codes_arr = array();
3105 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3106 while($codes_row = sqlFetchArray($smoking_codes))
3108 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3110 return $smoking_codes_arr;
3113 // Get the current value for a layout based form field.
3114 // Depending on options this might come from lbf_data, patient_data,
3115 // form_encounter, shared_attributes or elsewhere.
3116 // Returns FALSE if the field ID is invalid (layout error).
3118 function lbf_current_value($frow, $formid, $encounter) {
3119 global $pid;
3120 $formname = $frow['form_id'];
3121 $field_id = $frow['field_id'];
3122 $source = $frow['source'];
3123 $currvalue = '';
3124 $deffname = $formname . '_default_' . $field_id;
3125 if ($source == 'D' || $source == 'H') {
3126 // Get from patient_data, employer_data or history_data.
3127 if ($source == 'H') {
3128 $table = 'history_data';
3129 $orderby = 'ORDER BY date DESC LIMIT 1';
3131 else if (strpos($field_id, 'em_') === 0) {
3132 $field_id = substr($field_id, 3);
3133 $table = 'employer_data';
3134 $orderby = 'ORDER BY date DESC LIMIT 1';
3136 else {
3137 $table = 'patient_data';
3138 $orderby = '';
3140 // It is an error if the field does not exist, but don't crash.
3141 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3142 if (empty($tmp)) return FALSE;
3143 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3144 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3146 else if ($source == 'E') {
3147 if ($encounter) {
3148 // Get value from shared_attributes of the current encounter.
3149 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3150 "pid = ? AND encounter = ? AND field_id = ?",
3151 array($pid, $encounter, $field_id));
3152 if (isset($sarow)) $currvalue = $sarow['field_value'];
3154 else if ($formid) {
3155 // Get from shared_attributes of the encounter that this form is linked to.
3156 // Note the importance of having an index on forms.form_id.
3157 $sarow = sqlQuery("SELECT sa.field_value " .
3158 "FROM forms AS f, shared_attributes AS sa WHERE " .
3159 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3160 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3161 array($formid, $formname, $field_id));
3162 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3164 else {
3165 // New form and encounter not available, this should not happen.
3168 else if ($source == 'V') {
3169 if ($encounter) {
3170 // Get value from the current encounter's form_encounter.
3171 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3172 "pid = ? AND encounter = ?",
3173 array($pid, $encounter));
3174 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3176 else if ($formid) {
3177 // Get value from the form_encounter that this form is linked to.
3178 $ferow = sqlQuery("SELECT fe.* " .
3179 "FROM forms AS f, form_encounter AS fe WHERE " .
3180 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3181 "fe.pid = f.pid AND fe.encounter = f.encounter",
3182 array($formid, $formname));
3183 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3185 else {
3186 // New form and encounter not available, this should not happen.
3189 else if ($formid) {
3190 // This is a normal form field.
3191 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3192 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3193 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3195 else {
3196 // New form, see if there is a custom default from a plugin.
3197 // This logic does not apply to shared attributes because they do not
3198 // have a "new form" concept.
3199 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3201 return $currvalue;
3204 // This returns stuff that needs to go into the <head> section of a caller using
3205 // the drawable image field type in a form.
3206 // A TRUE argument makes the widget 25% less tall.
3208 function lbf_canvas_head($small=FALSE) {
3209 $s = <<<EOD
3210 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3211 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3212 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3213 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3214 EOD;
3215 if ($small) $s .= <<<EOD
3216 <style>
3217 /* Custom LiterallyCanvas styling.
3218 * This makes the widget 25% less tall and adjusts some other things accordingly.
3220 .literally {
3221 min-height:292px;min-width:300px; /* Was 400, unspecified */
3223 .literally .lc-picker .toolbar-button {
3224 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3226 .literally .color-well {
3227 font-size:8px;width:49px; /* Was 10, 60 */
3229 .literally .color-well-color-container {
3230 width:21px;height:21px; /* Was 28, 28 */
3232 .literally .lc-picker {
3233 width:50px; /* Was 61 */
3235 .literally .lc-drawing.with-gui {
3236 left:50px; /* Was 61 */
3238 .literally .lc-options {
3239 left:50px; /* Was 61 */
3241 .literally .color-picker-popup {
3242 left:49px;bottom:0px; /* Was 60, 31 */
3244 </style>
3245 EOD;
3246 return $s;