fixed main title in tabs layout
[openemr.git] / library / options.inc.php
blobedaf10e8b44fe1281137bade11f0de79fbf7afb9
1 <?php
2 // Copyright (C) 2007-2014 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("formdata.inc.php");
40 require_once("formatting.inc.php");
41 require_once("user.inc");
42 require_once("patient.inc");
43 require_once("lists.inc");
44 require_once(dirname(dirname(__FILE__)) . "/custom/code_types.inc.php");
46 $date_init = "";
48 function get_pharmacies() {
49 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
50 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
51 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
52 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
53 "AND p.type = 2 " .
54 "ORDER BY name, area_code, prefix, number");
57 function optionalAge($frow, $date, &$asof) {
58 $asof = '';
59 if (empty($date)) return '';
60 $date = substr($date, 0, 10);
61 if (strpos($frow['edit_options'], 'A') !== FALSE) {
62 $format = 0;
64 else if (strpos($frow['edit_options'], 'B') !== FALSE) {
65 $format = 3;
67 else {
68 return '';
70 if (strpos($frow['form_id'], 'LBF') === 0) {
71 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
72 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
73 array($GLOBALS['pid'], $GLOBALS['encounter']));
74 if (!empty($tmp['date'])) $asof = substr($tmp['date'], 0, 10);
76 $prefix = ($format ? xl('Gest age') : xl('Age')) . ' ';
77 return $prefix . oeFormatAge($date, $asof, $format);
80 // Function to generate a drop-list.
82 function generate_select_list($tag_name, $list_id, $currvalue, $title, $empty_name = ' ', $class = '',
83 $onchange = '', $tag_id = '', $custom_attributes = null, $multiple = false, $backup_list = '') {
84 $s = '';
86 $tag_name_esc = attr($tag_name);
88 if ($multiple) {
89 $tag_name_esc = $tag_name_esc . "[]";
92 $s .= "<select name='$tag_name_esc'";
94 if ($multiple) {
95 $s .= " multiple='multiple'";
98 $tag_id_esc = attr( $tag_name );
100 if ($tag_id != '') {
101 $tag_id_esc = attr($tag_id);
104 $s .= " id='$tag_id_esc'";
106 if ($class) {
107 $class_esc = attr($class);
108 $s .= " class='$class_esc'";
110 if ($onchange) {
111 $s .= " onchange='$onchange'";
113 if ($custom_attributes != null && is_array ( $custom_attributes )) {
114 foreach ( $custom_attributes as $attr => $val ) {
115 if (isset ( $custom_attributes [$attr] )) {
116 $s .= " " . attr($attr) . "='" . attr($val) . "'";
120 $selectTitle = attr($title);
121 $s .= " title='$selectTitle'>";
122 $selectEmptyName = xlt($empty_name);
123 if ($empty_name)
124 $s .= "<option value=''>" . $selectEmptyName . "</option>";
126 // List order depends on language translation options.
127 // (Note we do not need to worry about the list order in the algorithm
128 // after the below code block since that is where searches for exceptions
129 // are done which include inactive items or items from a backup
130 // list; note these will always be shown at the bottom of the list no matter the
131 // chosen order.)
132 $lang_id = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
133 // sort by title
134 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) || !$GLOBALS['translate_lists']) {
135 // do not translate
136 if ($GLOBALS['gb_how_sort_list'] == '0') {
137 // order by seq
138 $order_by_sql = "seq, title";
140 else { //$GLOBALS['gb_how_sort_list'] == '1'
141 // order by title
142 $order_by_sql = "title, seq";
144 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
146 else {
147 // do translate
148 if ($GLOBALS['gb_how_sort_list'] == '0') {
149 // order by seq
150 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
152 else { //$GLOBALS['gb_how_sort_list'] == '1'
153 // order by title
154 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
156 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
157 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
158 "FROM list_options AS lo " .
159 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
160 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
161 "ld.lang_id = ? " .
162 "WHERE lo.list_id = ? AND lo.activity=1 " .
163 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
165 $got_selected = FALSE;
167 while ( $lrow = sqlFetchArray ( $lres ) ) {
168 $selectedValues = explode ( "|", $currvalue );
170 $optionValue = attr($lrow ['option_id']);
171 $s .= "<option value='$optionValue'";
173 if ((strlen ( $currvalue ) == 0 && $lrow ['is_default']) || (strlen ( $currvalue ) > 0 && in_array ( $lrow ['option_id'], $selectedValues ))) {
174 $s .= " selected";
175 $got_selected = TRUE;
178 // Already has been translated above (if applicable), so do not need to use
179 // the xl_list_label() function here
180 $optionLabel = text($lrow ['title']);
181 $s .= ">$optionLabel</option>\n";
185 To show the inactive item in the list if the value is saved to database
187 if (!$got_selected && strlen($currvalue) > 0)
189 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
190 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
191 $lrow_inactive = sqlFetchArray($lres_inactive);
192 if($lrow_inactive['option_id']) {
193 $optionValue = htmlspecialchars( $lrow_inactive['option_id'], ENT_QUOTES);
194 $s .= "<option value='$optionValue' selected>" . htmlspecialchars( xl_list_label($lrow_inactive['title']), ENT_NOQUOTES) . "</option>\n";
195 $got_selected = TRUE;
199 if (!$got_selected && strlen ( $currvalue ) > 0 && !$multiple) {
200 $list_id = $backup_list;
201 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
203 if ($lrow > 0 && !empty($backup_list)) {
204 $selected = text(xl_list_label($lrow ['title']));
205 $s .= "<option value='$currescaped' selected> $selected </option>";
206 $s .= "</select>";
207 } else {
208 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
209 $s .= "</select>";
210 $fontTitle = xlt('Please choose a valid selection from the list.');
211 $fontText = xlt( 'Fix this' );
212 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
215 } else if (!$got_selected && strlen ( $currvalue ) > 0 && $multiple) {
216 //if not found in main list, display all selected values that exist in backup list
217 $list_id = $backup_list;
219 $got_selected_backup = FALSE;
220 if (!empty($backup_list)) {
221 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? ORDER BY seq, title", array($list_id));
222 while ( $lrow_backup = sqlFetchArray ( $lres_backup ) ) {
223 $selectedValues = explode ( "|", $currvalue );
225 $optionValue = attr($lrow_backup['option_id']);
227 if ( in_array($lrow_backup ['option_id'],$selectedValues)) {
228 $s .= "<option value='$optionValue'";
229 $s .= " selected";
230 $optionLabel = text(xl_list_label($lrow_backup ['title']));
231 $s .= ">$optionLabel</option>\n";
232 $got_selected_backup = TRUE;
236 if (!$got_selected_backup) {
237 $selectedValues = explode ( "|", $currvalue );
238 foreach ( $selectedValues as $selectedValue ) {
239 $s .= "<option value='" . attr($selectedValue) . "'";
240 $s .= " selected";
241 $s .= ">* " . text($selectedValue) . " *</option>\n";
243 $s .= "</select>";
244 $fontTitle = xlt('Please choose a valid selection from the list.');
245 $fontText = xlt( 'Fix this' );
246 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
250 else {
251 $s .= "</select>";
253 return $s;
257 // $frow is a row from the layout_options table.
258 // $currvalue is the current value, if any, of the associated item.
260 function generate_form_field($frow, $currvalue) {
261 global $rootdir, $date_init, $ISSUE_TYPES, $code_types,$condition_str;
263 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
265 $data_type = $frow['data_type'];
266 $field_id = $frow['field_id'];
267 $list_id = $frow['list_id'];
268 $backup_list = $frow['list_backup_id'];
269 $condition_str = get_conditions_str($condition_str,$frow);
271 // escaped variables to use in html
272 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
273 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
275 // Added 5-09 by BM - Translate description if applicable
276 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
278 // Support edit option T which assigns the (possibly very long) description as
279 // the default value.
280 if (strpos($frow['edit_options'], 'T') !== FALSE) {
281 if (strlen($currescaped) == 0) $currescaped = $description;
282 // Description used in this way is not suitable as a title.
283 $description = '';
286 // added 5-2009 by BM to allow modification of the 'empty' text title field.
287 // Can pass $frow['empty_title'] with this variable, otherwise
288 // will default to 'Unassigned'.
289 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
290 // if make $frow['empty_title'] equal to 'SKIP'
291 $showEmpty = true;
292 if (isset($frow['empty_title'])) {
293 if ($frow['empty_title'] == "SKIP") {
294 //do not display an 'empty' choice
295 $showEmpty = false;
296 $empty_title = "Unassigned";
298 else {
299 $empty_title = $frow['empty_title'];
302 else {
303 $empty_title = "Unassigned";
306 $disabled = strpos($frow['edit_options'], '0') === FALSE ? '' : 'disabled';
308 $lbfchange = (strpos($frow['form_id'], 'LBF') === 0 || strpos($frow['form_id'], 'LBT') === 0) ?
309 "checkSkipConditions();" : "";
310 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
312 // generic single-selection list or Race and Ethnicity.
313 // These data types support backup lists.
314 if ($data_type == 1 || $data_type == 33) {
315 echo generate_select_list("form_$field_id", $list_id, $currvalue,
316 $description, ($showEmpty ? $empty_title : ''), '', $lbfchange, '',
317 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
320 // simple text field
321 else if ($data_type == 2) {
322 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
323 $maxlength = $frow['max_length'];
324 $string_maxlength = "";
325 // if max_length is set to zero, then do not set a maxlength
326 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
327 echo "<input type='text'" .
328 " name='form_$field_id_esc'" .
329 " id='form_$field_id_esc'" .
330 " size='$fldlength'" .
331 " $string_maxlength" .
332 " title='$description'" .
333 " value='$currescaped'";
334 $tmp = $lbfchange;
335 if (strpos($frow['edit_options'], 'C') !== FALSE)
336 $tmp .= "capitalizeMe(this);";
337 else if (strpos($frow['edit_options'], 'U') !== FALSE)
338 $tmp .= "this.value = this.value.toUpperCase();";
339 if ($tmp) echo " onchange='$tmp'";
340 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
341 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
342 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
343 echo " onblur='maskblur(this,\"$tmp\")'";
345 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
346 echo " readonly";
348 if ($disabled) echo ' disabled';
349 echo " />";
352 // long or multi-line text field
353 else if ($data_type == 3) {
354 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
355 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
356 echo "<textarea" .
357 " name='form_$field_id_esc'" .
358 " id='form_$field_id_esc'" .
359 " title='$description'" .
360 " cols='$textCols'" .
361 " rows='$textRows' $lbfonchange $disabled" .
362 ">" . $currescaped . "</textarea>";
365 // date
366 else if ($data_type == 4) {
367 $age_asof_date = ''; // optionalAge() sets this
368 $age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0;
369 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
370 if ($agestr) {
371 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
373 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
374 " value='" . substr($currescaped, 0, 10) . "'";
375 if (!$agestr) echo " title='$description'";
376 echo " $lbfonchange onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
377 if (!$disabled) {
378 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
379 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
380 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
381 $date_init .= " Calendar.setup({" .
382 "inputField:'form_$field_id', " .
383 "ifFormat:'%Y-%m-%d', ";
384 if ($agestr) {
385 $date_init .= "onUpdate: function() {" .
386 "if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format);" .
387 "}, ";
389 $date_init .= "button:'img_$field_id'})\n";
391 // Optional display of age or gestational age.
392 if ($agestr) {
393 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
397 // provider list, local providers only
398 else if ($data_type == 10) {
399 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
400 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
401 "AND authorized = 1 " .
402 "ORDER BY lname, fname");
403 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled>";
404 echo "<option value=''>" . xlt($empty_title) . "</option>";
405 $got_selected = false;
406 while ($urow = sqlFetchArray($ures)) {
407 $uname = text($urow['fname'] . ' ' . $urow['lname']);
408 $optionId = attr($urow['id']);
409 echo "<option value='$optionId'";
410 if ($urow['id'] == $currvalue) {
411 echo " selected";
412 $got_selected = true;
414 echo ">$uname</option>";
416 if (!$got_selected && $currvalue) {
417 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
418 echo "</select>";
419 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
421 else {
422 echo "</select>";
426 // provider list, including address book entries with an NPI number
427 else if ($data_type == 11) {
428 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
429 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
430 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
431 "ORDER BY lname, fname");
432 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
433 echo " $lbfonchange $disabled>";
434 echo "<option value=''>" . xlt('Unassigned') . "</option>";
435 $got_selected = false;
436 while ($urow = sqlFetchArray($ures)) {
437 $uname = text($urow['fname'] . ' ' . $urow['lname']);
438 $optionId = attr($urow['id']);
439 echo "<option value='$optionId'";
440 if ($urow['id'] == $currvalue) {
441 echo " selected";
442 $got_selected = true;
444 echo ">$uname</option>";
446 if (!$got_selected && $currvalue) {
447 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
448 echo "</select>";
449 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
451 else {
452 echo "</select>";
456 // pharmacy list
457 else if ($data_type == 12) {
458 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
459 echo " $lbfonchange $disabled>";
460 echo "<option value='0'></option>";
461 $pres = get_pharmacies();
462 $got_selected = false;
463 while ($prow = sqlFetchArray($pres)) {
464 $key = $prow['id'];
465 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
466 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
467 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
468 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
469 echo "<option value='$optionValue'";
470 if ($currvalue == $key) {
471 echo " selected";
472 $got_selected = true;
474 echo ">$optionLabel</option>";
476 if (!$got_selected && $currvalue) {
477 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
478 echo "</select>";
479 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
481 else {
482 echo "</select>";
486 // squads
487 else if ($data_type == 13) {
488 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
489 echo " $lbfonchange $disabled>";
490 echo "<option value=''>&nbsp;</option>";
491 $squads = acl_get_squads();
492 if ($squads) {
493 foreach ($squads as $key => $value) {
494 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
495 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
496 echo "<option value='$optionValue'";
497 if ($currvalue == $key) echo " selected";
498 echo ">$optionLabel</option>\n";
501 echo "</select>";
504 // Address book, preferring organization name if it exists and is not in
505 // parentheses, and excluding local users who are not providers.
506 // Supports "referred to" practitioners and facilities.
507 // Alternatively the letter L in edit_options means that abook_type
508 // must be "ord_lab", indicating types used with the procedure
509 // lab ordering system.
510 // Alternatively the letter O in edit_options means that abook_type
511 // must begin with "ord_", indicating types used with the procedure
512 // ordering system.
513 // Alternatively the letter V in edit_options means that abook_type
514 // must be "vendor", indicating the Vendor type.
515 // Alternatively the letter R in edit_options means that abook_type
516 // must be "dist", indicating the Distributor type.
517 else if ($data_type == 14) {
518 if (strpos($frow['edit_options'], 'L') !== FALSE)
519 $tmp = "abook_type = 'ord_lab'";
520 else if (strpos($frow['edit_options'], 'O') !== FALSE)
521 $tmp = "abook_type LIKE 'ord\\_%'";
522 else if (strpos($frow['edit_options'], 'V') !== FALSE)
523 $tmp = "abook_type LIKE 'vendor%'";
524 else if (strpos($frow['edit_options'], 'R') !== FALSE)
525 $tmp = "abook_type LIKE 'dist'";
526 else
527 $tmp = "( username = '' OR authorized = 1 )";
528 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
529 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
530 "AND $tmp " .
531 "ORDER BY organization, lname, fname");
532 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
533 echo " $lbfonchange $disabled>";
534 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
535 while ($urow = sqlFetchArray($ures)) {
536 $uname = $urow['organization'];
537 if (empty($uname) || substr($uname, 0, 1) == '(') {
538 $uname = $urow['lname'];
539 if ($urow['fname']) $uname .= ", " . $urow['fname'];
541 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
542 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
543 echo "<option value='$optionValue'";
544 $title = $urow['username'] ? xl('Local') : xl('External');
545 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
546 echo " title='$optionTitle'";
547 if ($urow['id'] == $currvalue) echo " selected";
548 echo ">$optionLabel</option>";
550 echo "</select>";
553 // A billing code. If description matches an existing code type then that type is used.
554 else if ($data_type == 15) {
555 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
556 $maxlength = $frow['max_length'];
557 $string_maxlength = "";
558 // if max_length is set to zero, then do not set a maxlength
559 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
561 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
562 // Option "2" generates a hidden input for the codes, and a matching visible field
563 // displaying their descriptions. First step is computing the description string.
564 $currdescstring = '';
565 if (!empty($currvalue)) {
566 $relcodes = explode(';', $currvalue);
567 foreach ($relcodes as $codestring) {
568 if ($codestring === '') continue;
569 $code_text = lookup_code_descriptions($codestring);
570 if ($currdescstring !== '') $currdescstring .= '; ';
571 if (!empty($code_text)) {
572 $currdescstring .= $code_text;
574 else {
575 $currdescstring .= $codestring;
579 $currdescstring = attr($currdescstring);
581 echo "<input type='text'" .
582 " name='form_$field_id_esc'" .
583 " id='form_related_code'" .
584 " size='$fldlength'" .
585 " value='$currescaped'" .
586 " style='display:none'" .
587 " $lbfonchange readonly $disabled />";
588 // Extra readonly input field for optional display of code description(s).
589 echo "<input type='text'" .
590 " name='form_$field_id_esc" . "__desc'" .
591 " size='$fldlength'" .
592 " title='$description'" .
593 " value='$currdescstring'";
594 if (!$disabled) {
595 echo " onclick='sel_related(this,\"$codetype\")'";
597 echo " readonly $disabled />";
599 else {
600 echo "<input type='text'" .
601 " name='form_$field_id_esc'" .
602 " id='form_related_code'" .
603 " size='$fldlength'" .
604 " $string_maxlength" .
605 " title='$description'" .
606 " value='$currescaped'";
607 if (!$disabled) {
608 echo " onclick='sel_related(this,\"$codetype\")'";
610 echo " $lbfonchange readonly $disabled />";
614 // insurance company list
615 else if ($data_type == 16) {
616 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
617 echo "<option value='0'></option>";
618 $insprovs = getInsuranceProviders();
619 $got_selected = false;
620 foreach ($insprovs as $key => $ipname) {
621 $optionValue = htmlspecialchars($key, ENT_QUOTES);
622 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
623 echo "<option value='$optionValue'";
624 if ($currvalue == $key) {
625 echo " selected";
626 $got_selected = true;
628 echo ">$optionLabel</option>";
630 if (!$got_selected && $currvalue) {
631 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
632 echo "</select>";
633 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
635 else {
636 echo "</select>";
640 // issue types
641 else if ($data_type == 17) {
642 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
643 echo "<option value='0'></option>";
644 $got_selected = false;
645 foreach ($ISSUE_TYPES as $key => $value) {
646 $optionValue = htmlspecialchars($key, ENT_QUOTES);
647 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
648 echo "<option value='$optionValue'";
649 if ($currvalue == $key) {
650 echo " selected";
651 $got_selected = true;
653 echo ">$optionLabel</option>";
655 if (!$got_selected && strlen($currvalue) > 0) {
656 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
657 echo "</select>";
658 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
660 else {
661 echo "</select>";
665 // Visit categories.
666 else if ($data_type == 18) {
667 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
668 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
669 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
670 " $lbfonchange $disabled>";
671 echo "<option value=''>" . xlt($empty_title) . "</option>";
672 $got_selected = false;
673 while ($crow = sqlFetchArray($cres)) {
674 $catid = $crow['pc_catid'];
675 if (($catid < 9 && $catid != 5) || $catid == 11) continue;
676 echo "<option value='" . attr($catid) . "'";
677 if ($catid == $currvalue) {
678 echo " selected";
679 $got_selected = true;
681 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
683 if (!$got_selected && $currvalue) {
684 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
685 echo "</select>";
686 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
688 else {
689 echo "</select>";
693 // a set of labeled checkboxes
694 else if ($data_type == 21) {
695 // In this special case, fld_length is the number of columns generated.
696 $cols = max(1, $frow['fld_length']);
697 $avalue = explode('|', $currvalue);
698 $lres = sqlStatement("SELECT * FROM list_options " .
699 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
700 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
701 $tdpct = (int) (100 / $cols);
702 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
703 $option_id = $lrow['option_id'];
704 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
705 // if ($count) echo "<br />";
706 if ($count % $cols == 0) {
707 if ($count) echo "</tr>";
708 echo "<tr>";
710 echo "<td width='$tdpct%'>";
711 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
712 "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
713 if (in_array($option_id, $avalue)) echo " checked";
715 // Added 5-09 by BM - Translate label if applicable
716 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
718 echo "</td>";
720 if ($count) {
721 echo "</tr>";
722 if ($count > $cols) {
723 // Add some space after multiple rows of checkboxes.
724 $cols = htmlspecialchars( $cols, ENT_QUOTES);
725 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
728 echo "</table>";
731 // a set of labeled text input fields
732 else if ($data_type == 22) {
733 $tmp = explode('|', $currvalue);
734 $avalue = array();
735 foreach ($tmp as $value) {
736 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
737 $avalue[$matches[1]] = $matches[2];
740 $lres = sqlStatement("SELECT * FROM list_options " .
741 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
742 echo "<table cellpadding='0' cellspacing='0'>";
743 while ($lrow = sqlFetchArray($lres)) {
744 $option_id = $lrow['option_id'];
745 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
746 $maxlength = $frow['max_length'];
747 $string_maxlength = "";
748 // if max_length is set to zero, then do not set a maxlength
749 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
750 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
752 // Added 5-09 by BM - Translate label if applicable
753 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
754 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
755 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
756 echo "<td><input type='text'" .
757 " name='form_{$field_id_esc}[$option_id_esc]'" .
758 " id='form_{$field_id_esc}[$option_id_esc]'" .
759 " size='$fldlength'" .
760 " $string_maxlength" .
761 " value='$optionValue'";
762 echo " $lbfonchange $disabled /></td></tr>";
764 echo "</table>";
767 // a set of exam results; 3 radio buttons and a text field:
768 else if ($data_type == 23) {
769 $tmp = explode('|', $currvalue);
770 $avalue = array();
771 foreach ($tmp as $value) {
772 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
773 $avalue[$matches[1]] = $matches[2];
776 $maxlength = $frow['max_length'];
777 $string_maxlength = "";
778 // if max_length is set to zero, then do not set a maxlength
779 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
780 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
781 $lres = sqlStatement("SELECT * FROM list_options " .
782 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
783 echo "<table cellpadding='0' cellspacing='0'>";
784 echo "<tr><td>&nbsp;</td><td class='bold'>" .
785 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
786 "&nbsp;</td><td class='bold'>" .
787 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
788 "<td class='bold'>" .
789 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
790 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
791 while ($lrow = sqlFetchArray($lres)) {
792 $option_id = $lrow['option_id'];
793 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
794 $restype = substr($avalue[$option_id], 0, 1);
795 $resnote = substr($avalue[$option_id], 2);
797 // Added 5-09 by BM - Translate label if applicable
798 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
800 for ($i = 0; $i < 3; ++$i) {
801 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
802 echo "<td><input type='radio'" .
803 " name='radio_{$field_id_esc}[$option_id_esc]'" .
804 " id='radio_{$field_id_esc}[$option_id_esc]'" .
805 " value='$inputValue' $lbfonchange";
806 if ($restype === "$i") echo " checked";
807 echo " $disabled /></td>";
809 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
810 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
811 echo "<td><input type='text'" .
812 " name='form_{$field_id_esc}[$option_id_esc]'" .
813 " id='form_{$field_id_esc}[$option_id_esc]'" .
814 " size='$fldlength'" .
815 " $string_maxlength" .
816 " value='$resnote' $disabled /></td>";
817 echo "</tr>";
819 echo "</table>";
822 // the list of active allergies for the current patient
823 // this is read-only!
824 else if ($data_type == 24) {
825 $query = "SELECT title, comments FROM lists WHERE " .
826 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
827 "ORDER BY begdate";
828 // echo "<!-- $query -->\n"; // debugging
829 $lres = sqlStatement($query, array($GLOBALS['pid']));
830 $count = 0;
831 while ($lrow = sqlFetchArray($lres)) {
832 if ($count++) echo "<br />";
833 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
834 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
838 // a set of labeled checkboxes, each with a text field:
839 else if ($data_type == 25) {
840 $tmp = explode('|', $currvalue);
841 $avalue = array();
842 foreach ($tmp as $value) {
843 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
844 $avalue[$matches[1]] = $matches[2];
847 $maxlength = $frow['max_length'];
848 $string_maxlength = "";
849 // if max_length is set to zero, then do not set a maxlength
850 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
851 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
852 $lres = sqlStatement("SELECT * FROM list_options " .
853 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
854 echo "<table cellpadding='0' cellspacing='0'>";
855 while ($lrow = sqlFetchArray($lres)) {
856 $option_id = $lrow['option_id'];
857 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
858 $restype = substr($avalue[$option_id], 0, 1);
859 $resnote = substr($avalue[$option_id], 2);
861 // Added 5-09 by BM - Translate label if applicable
862 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
864 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
865 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
866 " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
867 if ($restype) echo " checked";
868 echo " $disabled />&nbsp;</td>";
869 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
870 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
871 echo "<td><input type='text'" .
872 " name='form_{$field_id_esc}[$option_id_esc]'" .
873 " id='form_{$field_id_esc}[$option_id_esc]'" .
874 " size='$fldlength'" .
875 " $string_maxlength" .
876 " value='$resnote' $disabled /></td>";
877 echo "</tr>";
879 echo "</table>";
882 // single-selection list with ability to add to it
883 else if ($data_type == 26) {
884 echo generate_select_list("form_$field_id", $list_id, $currvalue,
885 $description, ($showEmpty ? $empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
886 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
887 // show the add button if user has access to correct list
888 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
889 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
890 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
891 if (aco_exist('lists', $list_id)) {
892 // a specific aco exist for this list, so ensure access
893 if (acl_check('lists', $list_id)) echo $outputAddButton;
895 else {
896 // no specific aco exist for this list, so check for access to 'default' list
897 if (acl_check('lists', 'default')) echo $outputAddButton;
901 // a set of labeled radio buttons
902 else if ($data_type == 27) {
903 // In this special case, fld_length is the number of columns generated.
904 $cols = max(1, $frow['fld_length']);
905 $lres = sqlStatement("SELECT * FROM list_options " .
906 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
907 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
908 $tdpct = (int) (100 / $cols);
909 $got_selected = FALSE;
910 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
911 $option_id = $lrow['option_id'];
912 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
913 if ($count % $cols == 0) {
914 if ($count) echo "</tr>";
915 echo "<tr>";
917 echo "<td width='$tdpct%'>";
918 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
919 " value='$option_id_esc' $lbfonchange";
920 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
921 (strlen($currvalue) > 0 && $option_id == $currvalue))
923 echo " checked";
924 $got_selected = TRUE;
926 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
927 echo "</td>";
929 if ($count) {
930 echo "</tr>";
931 if ($count > $cols) {
932 // Add some space after multiple rows of radio buttons.
933 $cols = htmlspecialchars($cols, ENT_QUOTES);
934 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
937 echo "</table>";
938 if (!$got_selected && strlen($currvalue) > 0) {
939 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
940 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
941 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
945 // special case for history of lifestyle status; 3 radio buttons and a date text field:
946 // VicarePlus :: A selection list box for smoking status:
947 else if ($data_type == 28 || $data_type == 32) {
948 $tmp = explode('|', $currvalue);
949 switch(count($tmp)) {
950 case "4": {
951 $resnote = $tmp[0];
952 $restype = $tmp[1];
953 $resdate = $tmp[2];
954 $reslist = $tmp[3];
955 } break;
956 case "3": {
957 $resnote = $tmp[0];
958 $restype = $tmp[1];
959 $resdate = $tmp[2];
960 } break;
961 case "2": {
962 $resnote = $tmp[0];
963 $restype = $tmp[1];
964 $resdate = "";
965 } break;
966 case "1": {
967 $resnote = $tmp[0];
968 $resdate = $restype = "";
969 } break;
970 default: {
971 $restype = $resdate = $resnote = "";
972 } break;
974 $maxlength = $frow['max_length'];
975 $string_maxlength = "";
976 // if max_length is set to zero, then do not set a maxlength
977 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
978 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
980 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
981 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
982 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
983 echo "<table cellpadding='0' cellspacing='0'>";
984 echo "<tr>";
985 if ($data_type == 28)
987 // input text
988 echo "<td><input type='text'" .
989 " name='form_$field_id_esc'" .
990 " id='form_$field_id_esc'" .
991 " size='$fldlength'" .
992 " $string_maxlength" .
993 " value='$resnote' $disabled />&nbsp;</td>";
994 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
995 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
996 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
998 else if($data_type == 32)
1000 // input text
1001 echo "<tr><td><input type='text'" .
1002 " name='form_text_$field_id_esc'" .
1003 " id='form_text_$field_id_esc'" .
1004 " size='$fldlength'" .
1005 " $string_maxlength" .
1006 " value='$resnote' $disabled />&nbsp;</td></tr>";
1007 echo "<td>";
1008 //Selection list for smoking status
1009 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1010 echo generate_select_list("form_$field_id", $list_id, $reslist,
1011 $description, ($showEmpty ? $empty_title : ''), '', $onchange, '',
1012 ($disabled ? array('disabled' => 'disabled') : null));
1013 echo "</td>";
1014 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
1016 // current
1017 echo "<td class='text' ><input type='radio'" .
1018 " name='radio_{$field_id_esc}'" .
1019 " id='radio_{$field_id_esc}[current]'" .
1020 " value='current" . $field_id_esc . "' $lbfonchange";
1021 if ($restype == "current" . $field_id) echo " checked";
1022 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1023 echo " />" . xlt('Current') . "&nbsp;</td>";
1024 // quit
1025 echo "<td class='text'><input type='radio'" .
1026 " name='radio_{$field_id_esc}'" .
1027 " id='radio_{$field_id_esc}[quit]'" .
1028 " value='quit".$field_id_esc."' $lbfonchange";
1029 if ($restype == "quit" . $field_id) echo " checked";
1030 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1031 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
1032 // quit date
1033 echo "<td class='text'><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
1034 " value='$resdate'" .
1035 " title='$description'" .
1036 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
1037 if (!$disabled) {
1038 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
1039 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
1040 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
1041 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
1043 echo "&nbsp;</td>";
1044 // never
1045 echo "<td class='text'><input type='radio'" .
1046 " name='radio_{$field_id_esc}'" .
1047 " id='radio_{$field_id_esc}[never]'" .
1048 " value='never" . $field_id_esc . "' $lbfonchange";
1049 if ($restype == "never" . $field_id) echo " checked";
1050 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1051 echo " />" . xlt('Never') . "&nbsp;</td>";
1052 // Not Applicable
1053 echo "<td class='text'><input type='radio'" .
1054 " name='radio_{$field_id}'" .
1055 " id='radio_{$field_id}[not_applicable]'" .
1056 " value='not_applicable" . $field_id . "' $lbfonchange";
1057 if ($restype == "not_applicable" . $field_id) echo " checked";
1058 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1059 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1061 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1062 echo "<td class='text' ><div id='smoke_code'></div></td>";
1063 echo "</tr>";
1064 echo "</table>";
1067 // static text. read-only, of course.
1068 else if ($data_type == 31) {
1069 echo nl2br($frow['description']);
1072 //$data_type == 33
1073 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1074 //$data_type == 33
1076 else if($data_type == 34){
1077 $arr = explode("|*|*|*|",$currvalue);
1078 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;'>";
1079 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
1080 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1081 echo "</a>";
1084 //facilities drop-down list
1085 else if ($data_type == 35) {
1086 if (empty($currvalue)){
1087 $currvalue = 0;
1089 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1090 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1093 //multiple select
1094 // supports backup list
1095 else if ($data_type == 36) {
1096 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1097 $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);
1101 // Canvas and related elements for browser-side image drawing.
1102 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1103 else if ($data_type == 40) {
1104 // Unlike other field types, width and height are in pixels.
1105 $canWidth = intval($frow['fld_length']);
1106 $canHeight = intval($frow['fld_rows']);
1107 if (empty($currvalue)) {
1108 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1109 // If defined this is the filename of the default starting image.
1110 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1113 echo "<div id='form_$field_id_esc'></div>";
1114 // Hidden form field exists to send updated data to the server at submit time.
1115 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1116 // Hidden image exists to support initialization of the canvas.
1117 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1118 // $date_init is a misnomer but it's the place for browser-side setup logic.
1119 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1124 function generate_print_field($frow, $currvalue) {
1125 global $rootdir, $date_init, $ISSUE_TYPES;
1127 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1129 $data_type = $frow['data_type'];
1130 $field_id = $frow['field_id'];
1131 $list_id = $frow['list_id'];
1132 $fld_length = $frow['fld_length'];
1133 $backup_list = $frow['list_backup_id'];
1135 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1137 // Can pass $frow['empty_title'] with this variable, otherwise
1138 // will default to 'Unassigned'.
1139 // If it is 'SKIP' then an empty text title is completely skipped.
1140 $showEmpty = true;
1141 if (isset($frow['empty_title'])) {
1142 if ($frow['empty_title'] == "SKIP") {
1143 //do not display an 'empty' choice
1144 $showEmpty = false;
1145 $empty_title = "Unassigned";
1147 else {
1148 $empty_title = $frow['empty_title'];
1151 else {
1152 $empty_title = "Unassigned";
1155 // generic single-selection list
1156 // Supports backup lists.
1157 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
1158 if (empty($fld_length)) {
1159 if ($list_id == 'titles') {
1160 $fld_length = 3;
1161 } else {
1162 $fld_length = 10;
1165 $tmp = '';
1166 if ($currvalue) {
1167 $lrow = sqlQuery("SELECT title FROM list_options " .
1168 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
1169 $tmp = xl_list_label($lrow['title']);
1170 if ($lrow == 0 && !empty($backup_list)) {
1171 // since primary list did not map, try to map to backup list
1172 $lrow = sqlQuery("SELECT title FROM list_options " .
1173 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1174 $tmp = xl_list_label($lrow['title']);
1176 if (empty($tmp)) $tmp = "($currvalue)";
1178 /*****************************************************************
1179 echo "<input type='text'" .
1180 " size='$fld_length'" .
1181 " value='$tmp'" .
1182 " class='under'" .
1183 " />";
1184 *****************************************************************/
1185 if ($tmp === '') {
1186 $tmp = '&nbsp;';
1188 else {
1189 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1191 echo $tmp;
1194 // simple text field
1195 else if ($data_type == 2 || $data_type == 15) {
1196 /*****************************************************************
1197 echo "<input type='text'" .
1198 " size='$fld_length'" .
1199 " value='$currescaped'" .
1200 " class='under'" .
1201 " />";
1202 *****************************************************************/
1203 if ($currescaped === '') $currescaped = '&nbsp;';
1204 echo $currescaped;
1207 // long or multi-line text field
1208 else if ($data_type == 3) {
1209 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
1210 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
1211 echo "<textarea" .
1212 " cols='$fldlength'" .
1213 " rows='$maxlength'>" .
1214 $currescaped . "</textarea>";
1217 // date
1218 else if ($data_type == 4) {
1219 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1220 $agestr = optionalAge($frow, $currvalue,$asof);
1221 if ($agestr) {
1222 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1224 if ($currvalue === '') {
1225 echo '&nbsp;';
1227 else {
1228 echo text(oeFormatShortDate($currvalue));
1230 // Optional display of age or gestational age.
1231 if ($agestr) {
1232 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1236 // provider list
1237 else if ($data_type == 10 || $data_type == 11) {
1238 $tmp = '';
1239 if ($currvalue) {
1240 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1241 "WHERE id = ?", array($currvalue) );
1242 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1243 if (empty($tmp)) $tmp = "($currvalue)";
1245 /*****************************************************************
1246 echo "<input type='text'" .
1247 " size='$fld_length'" .
1248 " value='$tmp'" .
1249 " class='under'" .
1250 " />";
1251 *****************************************************************/
1252 if ($tmp === '') { $tmp = '&nbsp;'; }
1253 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1254 echo $tmp;
1257 // pharmacy list
1258 else if ($data_type == 12) {
1259 $tmp = '';
1260 if ($currvalue) {
1261 $pres = get_pharmacies();
1262 while ($prow = sqlFetchArray($pres)) {
1263 $key = $prow['id'];
1264 if ($currvalue == $key) {
1265 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1266 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1267 $prow['line1'] . ' / ' . $prow['city'];
1270 if (empty($tmp)) $tmp = "($currvalue)";
1272 /*****************************************************************
1273 echo "<input type='text'" .
1274 " size='$fld_length'" .
1275 " value='$tmp'" .
1276 " class='under'" .
1277 " />";
1278 *****************************************************************/
1279 if ($tmp === '') { $tmp = '&nbsp;'; }
1280 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1281 echo $tmp;
1284 // squads
1285 else if ($data_type == 13) {
1286 $tmp = '';
1287 if ($currvalue) {
1288 $squads = acl_get_squads();
1289 if ($squads) {
1290 foreach ($squads as $key => $value) {
1291 if ($currvalue == $key) {
1292 $tmp = $value[3];
1296 if (empty($tmp)) $tmp = "($currvalue)";
1298 /*****************************************************************
1299 echo "<input type='text'" .
1300 " size='$fld_length'" .
1301 " value='$tmp'" .
1302 " class='under'" .
1303 " />";
1304 *****************************************************************/
1305 if ($tmp === '') { $tmp = '&nbsp;'; }
1306 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1307 echo $tmp;
1310 // Address book.
1311 else if ($data_type == 14) {
1312 $tmp = '';
1313 if ($currvalue) {
1314 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1315 "WHERE id = ?", array($currvalue) );
1316 $uname = $urow['lname'];
1317 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1318 $tmp = $uname;
1319 if (empty($tmp)) $tmp = "($currvalue)";
1321 /*****************************************************************
1322 echo "<input type='text'" .
1323 " size='$fld_length'" .
1324 " value='$tmp'" .
1325 " class='under'" .
1326 " />";
1327 *****************************************************************/
1328 if ($tmp === '') { $tmp = '&nbsp;'; }
1329 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1330 echo $tmp;
1333 // insurance company list
1334 else if ($data_type == 16) {
1335 $tmp = '';
1336 if ($currvalue) {
1337 $insprovs = getInsuranceProviders();
1338 foreach ($insprovs as $key => $ipname) {
1339 if ($currvalue == $key) {
1340 $tmp = $ipname;
1343 if (empty($tmp)) $tmp = "($currvalue)";
1345 if ($tmp === '') $tmp = '&nbsp;';
1346 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1347 echo $tmp;
1350 // issue types
1351 else if ($data_type == 17) {
1352 $tmp = '';
1353 if ($currvalue) {
1354 foreach ($ISSUE_TYPES as $key => $value) {
1355 if ($currvalue == $key) {
1356 $tmp = $value[1];
1359 if (empty($tmp)) $tmp = "($currvalue)";
1361 if ($tmp === '') $tmp = '&nbsp;';
1362 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1363 echo $tmp;
1366 // Visit categories.
1367 else if ($data_type == 18) {
1368 $tmp = '';
1369 if ($currvalue) {
1370 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1371 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1372 array($currvalue));
1373 $tmp = xl_appt_category($crow['pc_catname']);
1374 if (empty($tmp)) $tmp = "($currvalue)";
1376 if ($tmp === '') { $tmp = '&nbsp;'; }
1377 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES); }
1378 echo $tmp;
1381 // a set of labeled checkboxes
1382 else if ($data_type == 21) {
1383 // In this special case, fld_length is the number of columns generated.
1384 $cols = max(1, $fld_length);
1385 $avalue = explode('|', $currvalue);
1386 $lres = sqlStatement("SELECT * FROM list_options " .
1387 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1388 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1389 $tdpct = (int) (100 / $cols);
1390 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1391 $option_id = $lrow['option_id'];
1392 if ($count % $cols == 0) {
1393 if ($count) echo "</tr>";
1394 echo "<tr>";
1396 echo "<td width='$tdpct%'>";
1397 echo "<input type='checkbox'";
1398 if (in_array($option_id, $avalue)) echo " checked";
1399 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1400 echo "</td>";
1402 if ($count) {
1403 echo "</tr>";
1404 if ($count > $cols) {
1405 // Add some space after multiple rows of checkboxes.
1406 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1407 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1410 echo "</table>";
1413 // a set of labeled text input fields
1414 else if ($data_type == 22) {
1415 $tmp = explode('|', $currvalue);
1416 $avalue = array();
1417 foreach ($tmp as $value) {
1418 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1419 $avalue[$matches[1]] = $matches[2];
1422 $lres = sqlStatement("SELECT * FROM list_options " .
1423 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1424 echo "<table cellpadding='0' cellspacing='0'>";
1425 while ($lrow = sqlFetchArray($lres)) {
1426 $option_id = $lrow['option_id'];
1427 $fldlength = empty($fld_length) ? 20 : $fld_length;
1428 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1429 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1430 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1431 echo "<td><input type='text'" .
1432 " size='$fldlength'" .
1433 " value='$inputValue'" .
1434 " class='under'" .
1435 " /></td></tr>";
1437 echo "</table>";
1440 // a set of exam results; 3 radio buttons and a text field:
1441 else if ($data_type == 23) {
1442 $tmp = explode('|', $currvalue);
1443 $avalue = array();
1444 foreach ($tmp as $value) {
1445 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1446 $avalue[$matches[1]] = $matches[2];
1449 $fldlength = empty($fld_length) ? 20 : $fld_length;
1450 $lres = sqlStatement("SELECT * FROM list_options " .
1451 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1452 echo "<table cellpadding='0' cellspacing='0'>";
1453 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1454 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1455 "&nbsp;</td><td class='bold'>" .
1456 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1457 "<td class='bold'>" .
1458 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1459 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1460 while ($lrow = sqlFetchArray($lres)) {
1461 $option_id = $lrow['option_id'];
1462 $restype = substr($avalue[$option_id], 0, 1);
1463 $resnote = substr($avalue[$option_id], 2);
1464 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1465 for ($i = 0; $i < 3; ++$i) {
1466 echo "<td><input type='radio'";
1467 if ($restype === "$i") echo " checked";
1468 echo " /></td>";
1470 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1471 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1472 echo "<td><input type='text'" .
1473 " size='$fldlength'" .
1474 " value='$resnote'" .
1475 " class='under' /></td>" .
1476 "</tr>";
1478 echo "</table>";
1481 // the list of active allergies for the current patient
1482 // this is read-only!
1483 else if ($data_type == 24) {
1484 $query = "SELECT title, comments FROM lists WHERE " .
1485 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1486 "ORDER BY begdate";
1487 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1488 $count = 0;
1489 while ($lrow = sqlFetchArray($lres)) {
1490 if ($count++) echo "<br />";
1491 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1492 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1496 // a set of labeled checkboxes, each with a text field:
1497 else if ($data_type == 25) {
1498 $tmp = explode('|', $currvalue);
1499 $avalue = array();
1500 foreach ($tmp as $value) {
1501 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1502 $avalue[$matches[1]] = $matches[2];
1505 $fldlength = empty($fld_length) ? 20 : $fld_length;
1506 $lres = sqlStatement("SELECT * FROM list_options " .
1507 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1508 echo "<table cellpadding='0' cellspacing='0'>";
1509 while ($lrow = sqlFetchArray($lres)) {
1510 $option_id = $lrow['option_id'];
1511 $restype = substr($avalue[$option_id], 0, 1);
1512 $resnote = substr($avalue[$option_id], 2);
1513 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1514 echo "<td><input type='checkbox'";
1515 if ($restype) echo " checked";
1516 echo " />&nbsp;</td>";
1517 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1518 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1519 echo "<td><input type='text'" .
1520 " size='$fldlength'" .
1521 " value='$resnote'" .
1522 " class='under'" .
1523 " /></td>" .
1524 "</tr>";
1526 echo "</table>";
1529 // a set of labeled radio buttons
1530 else if ($data_type == 27) {
1531 // In this special case, fld_length is the number of columns generated.
1532 $cols = max(1, $frow['fld_length']);
1533 $lres = sqlStatement("SELECT * FROM list_options " .
1534 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1535 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1536 $tdpct = (int) (100 / $cols);
1537 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1538 $option_id = $lrow['option_id'];
1539 if ($count % $cols == 0) {
1540 if ($count) echo "</tr>";
1541 echo "<tr>";
1543 echo "<td width='$tdpct%'>";
1544 echo "<input type='radio'";
1545 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1546 (strlen($currvalue) > 0 && $option_id == $currvalue))
1548 echo " checked";
1550 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1551 echo "</td>";
1553 if ($count) {
1554 echo "</tr>";
1555 if ($count > $cols) {
1556 // Add some space after multiple rows of radio buttons.
1557 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1558 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1561 echo "</table>";
1564 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1565 else if ($data_type == 28 || $data_type == 32) {
1566 $tmp = explode('|', $currvalue);
1567 switch(count($tmp)) {
1568 case "4": {
1569 $resnote = $tmp[0];
1570 $restype = $tmp[1];
1571 $resdate = $tmp[2];
1572 $reslist = $tmp[3];
1573 } break;
1574 case "3": {
1575 $resnote = $tmp[0];
1576 $restype = $tmp[1];
1577 $resdate = $tmp[2];
1578 } break;
1579 case "2": {
1580 $resnote = $tmp[0];
1581 $restype = $tmp[1];
1582 $resdate = "";
1583 } break;
1584 case "1": {
1585 $resnote = $tmp[0];
1586 $resdate = $restype = "";
1587 } break;
1588 default: {
1589 $restype = $resdate = $resnote = "";
1590 } break;
1592 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1593 echo "<table cellpadding='0' cellspacing='0'>";
1594 echo "<tr>";
1595 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1596 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1597 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1598 if($data_type == 28)
1600 echo "<td><input type='text'" .
1601 " size='$fldlength'" .
1602 " class='under'" .
1603 " value='$resnote' /></td>";
1604 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1605 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1606 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1608 else if($data_type == 32)
1610 echo "<tr><td><input type='text'" .
1611 " size='$fldlength'" .
1612 " class='under'" .
1613 " value='$resnote' /></td></tr>";
1614 $fldlength = 30;
1615 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1616 echo "<td><input type='text'" .
1617 " size='$fldlength'" .
1618 " class='under'" .
1619 " value='$smoking_status_title' /></td>";
1620 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1622 echo "<td><input type='radio'";
1623 if ($restype == "current".$field_id) echo " checked";
1624 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1626 echo "<td><input type='radio'";
1627 if ($restype == "current".$field_id) echo " checked";
1628 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1630 echo "<td><input type='text' size='6'" .
1631 " value='$resdate'" .
1632 " class='under'" .
1633 " /></td>";
1635 echo "<td><input type='radio'";
1636 if ($restype == "current".$field_id) echo " checked";
1637 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1639 echo "<td><input type='radio'";
1640 if ($restype == "not_applicable".$field_id) echo " checked";
1641 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1642 echo "</tr>";
1643 echo "</table>";
1646 // static text. read-only, of course.
1647 else if ($data_type == 31) {
1648 echo nl2br($frow['description']);
1651 else if($data_type == 34){
1652 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;'>";
1653 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1654 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1655 echo "</a>";
1658 //facilities drop-down list
1659 else if ($data_type == 35) {
1660 if (empty($currvalue)){
1661 $currvalue = 0;
1663 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1666 //Multi-select
1667 // Supports backup lists.
1668 else if ($data_type == 36) {
1669 if (empty($fld_length)) {
1670 if ($list_id == 'titles') {
1671 $fld_length = 3;
1672 } else {
1673 $fld_length = 10;
1676 $tmp = '';
1678 $values_array = explode("|", $currvalue);
1680 $i=0;
1681 foreach($values_array as $value) {
1682 if ($value) {
1683 $lrow = sqlQuery("SELECT title FROM list_options " .
1684 "WHERE list_id = ? AND option_id = ?", array($list_id,$value));
1685 $tmp = xl_list_label($lrow['title']);
1686 if ($lrow == 0 && !empty($backup_list)) {
1687 // since primary list did not map, try to map to backup list
1688 $lrow = sqlQuery("SELECT title FROM list_options " .
1689 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1690 $tmp = xl_list_label($lrow['title']);
1692 if (empty($tmp)) $tmp = "($value)";
1695 if ($tmp === '') {
1696 $tmp = '&nbsp;';
1698 else {
1699 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1701 if ($i != 0 && $tmp != '&nbsp;') echo ",";
1702 echo $tmp;
1703 $i++;
1707 // Image from canvas drawing
1708 else if ($data_type == 40) {
1709 echo "<img src='" . attr($currvalue) . "'>";
1714 function generate_display_field($frow, $currvalue) {
1715 global $ISSUE_TYPES;
1717 $data_type = $frow['data_type'];
1718 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1719 $list_id = $frow['list_id'];
1720 $backup_list = $frow['list_backup_id'];
1722 $s = '';
1724 // generic selection list or the generic selection list with add on the fly
1725 // feature, or radio buttons
1726 // Supports backup lists for datatypes 1,26,33
1727 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1728 $lrow = sqlQuery("SELECT title FROM list_options " .
1729 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1730 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1731 //if there is no matching value in the corresponding lists check backup list
1732 // only supported in data types 1,26,33
1733 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1734 $lrow = sqlQuery("SELECT title FROM list_options " .
1735 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
1736 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1740 // simple text field
1741 else if ($data_type == 2) {
1742 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1745 // long or multi-line text field
1746 else if ($data_type == 3) {
1747 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1750 // date
1751 else if ($data_type == 4) {
1752 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1753 $s = '';
1754 $agestr = optionalAge($frow, $currvalue, $asof);
1755 if ($agestr) {
1756 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1758 if ($currvalue === '') {
1759 $s .= '&nbsp;';
1761 else {
1762 $s .= text(oeFormatShortDate($currvalue));
1764 // Optional display of age or gestational age.
1765 if ($agestr) {
1766 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1770 // provider
1771 else if ($data_type == 10 || $data_type == 11) {
1772 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1773 "WHERE id = ?", array($currvalue) );
1774 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1777 // pharmacy list
1778 else if ($data_type == 12) {
1779 $pres = get_pharmacies();
1780 while ($prow = sqlFetchArray($pres)) {
1781 $key = $prow['id'];
1782 if ($currvalue == $key) {
1783 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1784 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1785 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1790 // squads
1791 else if ($data_type == 13) {
1792 $squads = acl_get_squads();
1793 if ($squads) {
1794 foreach ($squads as $key => $value) {
1795 if ($currvalue == $key) {
1796 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1802 // address book
1803 else if ($data_type == 14) {
1804 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
1805 "WHERE id = ?", array($currvalue));
1806 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
1807 if($urow['organization'] !=""){
1808 $uname = $urow['organization'];
1809 }else{
1810 $uname = $urow['lname'];
1811 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1813 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1816 // billing code
1817 else if ($data_type == 15) {
1818 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1821 // insurance company list
1822 else if ($data_type == 16) {
1823 $insprovs = getInsuranceProviders();
1824 foreach ($insprovs as $key => $ipname) {
1825 if ($currvalue == $key) {
1826 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
1831 // issue types
1832 else if ($data_type == 17) {
1833 foreach ($ISSUE_TYPES as $key => $value) {
1834 if ($currvalue == $key) {
1835 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
1840 // visit category
1841 else if ($data_type == 18) {
1842 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1843 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1844 array($currvalue));
1845 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES);
1848 // a set of labeled checkboxes
1849 else if ($data_type == 21) {
1850 $avalue = explode('|', $currvalue);
1851 $lres = sqlStatement("SELECT * FROM list_options " .
1852 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1853 $count = 0;
1854 while ($lrow = sqlFetchArray($lres)) {
1855 $option_id = $lrow['option_id'];
1856 if (in_array($option_id, $avalue)) {
1857 if ($count++) $s .= "<br />";
1859 // Added 5-09 by BM - Translate label if applicable
1860 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES);
1866 // a set of labeled text input fields
1867 else if ($data_type == 22) {
1868 $tmp = explode('|', $currvalue);
1869 $avalue = array();
1870 foreach ($tmp as $value) {
1871 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1872 $avalue[$matches[1]] = $matches[2];
1875 $lres = sqlStatement("SELECT * FROM list_options " .
1876 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1877 $s .= "<table cellpadding='0' cellspacing='0'>";
1878 while ($lrow = sqlFetchArray($lres)) {
1879 $option_id = $lrow['option_id'];
1880 if (empty($avalue[$option_id])) continue;
1882 // Added 5-09 by BM - Translate label if applicable
1883 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1885 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1887 $s .= "</table>";
1890 // a set of exam results; 3 radio buttons and a text field:
1891 else if ($data_type == 23) {
1892 $tmp = explode('|', $currvalue);
1893 $avalue = array();
1894 foreach ($tmp as $value) {
1895 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1896 $avalue[$matches[1]] = $matches[2];
1899 $lres = sqlStatement("SELECT * FROM list_options " .
1900 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1901 $s .= "<table cellpadding='0' cellspacing='0'>";
1902 while ($lrow = sqlFetchArray($lres)) {
1903 $option_id = $lrow['option_id'];
1904 $restype = substr($avalue[$option_id], 0, 1);
1905 $resnote = substr($avalue[$option_id], 2);
1906 if (empty($restype) && empty($resnote)) continue;
1908 // Added 5-09 by BM - Translate label if applicable
1909 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1911 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1912 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1913 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1914 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1915 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1916 $s .= "</tr>";
1918 $s .= "</table>";
1921 // the list of active allergies for the current patient
1922 else if ($data_type == 24) {
1923 $query = "SELECT title, comments FROM lists WHERE " .
1924 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1925 "ORDER BY begdate";
1926 // echo "<!-- $query -->\n"; // debugging
1927 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1928 $count = 0;
1929 while ($lrow = sqlFetchArray($lres)) {
1930 if ($count++) $s .= "<br />";
1931 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1932 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1936 // a set of labeled checkboxes, each with a text field:
1937 else if ($data_type == 25) {
1938 $tmp = explode('|', $currvalue);
1939 $avalue = array();
1940 foreach ($tmp as $value) {
1941 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1942 $avalue[$matches[1]] = $matches[2];
1945 $lres = sqlStatement("SELECT * FROM list_options " .
1946 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1947 $s .= "<table cellpadding='0' cellspacing='0'>";
1948 while ($lrow = sqlFetchArray($lres)) {
1949 $option_id = $lrow['option_id'];
1950 $restype = substr($avalue[$option_id], 0, 1);
1951 $resnote = substr($avalue[$option_id], 2);
1952 if (empty($restype) && empty($resnote)) continue;
1954 // Added 5-09 by BM - Translate label if applicable
1955 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1957 $restype = $restype ? xl('Yes') : xl('No');
1958 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1959 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1960 $s .= "</tr>";
1962 $s .= "</table>";
1965 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1966 // VicarePlus :: A selection list for smoking status.
1967 else if ($data_type == 28 || $data_type == 32) {
1968 $tmp = explode('|', $currvalue);
1969 switch(count($tmp)) {
1970 case "4": {
1971 $resnote = $tmp[0];
1972 $restype = $tmp[1];
1973 $resdate = $tmp[2];
1974 $reslist = $tmp[3];
1975 } break;
1976 case "3": {
1977 $resnote = $tmp[0];
1978 $restype = $tmp[1];
1979 $resdate = $tmp[2];
1980 } break;
1981 case "2": {
1982 $resnote = $tmp[0];
1983 $restype = $tmp[1];
1984 $resdate = "";
1985 } break;
1986 case "1": {
1987 $resnote = $tmp[0];
1988 $resdate = $restype = "";
1989 } break;
1990 default: {
1991 $restype = $resdate = $resnote = "";
1992 } break;
1994 $s .= "<table cellpadding='0' cellspacing='0'>";
1996 $s .= "<tr>";
1997 $res = "";
1998 if ($restype == "current".$field_id) $res = xl('Current');
1999 if ($restype == "quit".$field_id) $res = xl('Quit');
2000 if ($restype == "never".$field_id) $res = xl('Never');
2001 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
2002 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2003 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2004 if ($data_type == 28)
2006 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
2008 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2009 else if ($data_type == 32)
2010 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2011 $smoke_codes = getSmokeCodes();
2012 if (!empty($reslist)) {
2013 if($smoke_codes[$reslist]!="")
2014 $code_desc = "( ".$smoke_codes[$reslist]." )";
2016 $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>";}
2018 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
2021 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
2022 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
2023 $s .= "</tr>";
2024 $s .= "</table>";
2027 // static text. read-only, of course.
2028 else if ($data_type == 31) {
2029 $s .= nl2br($frow['description']);
2032 else if($data_type == 34){
2033 $arr = explode("|*|*|*|",$currvalue);
2034 for($i=0;$i<sizeof($arr);$i++){
2035 $s.=$arr[$i];
2039 // facility
2040 else if ($data_type == 35) {
2041 $urow = sqlQuery("SELECT id, name FROM facility ".
2042 "WHERE id = ?", array($currvalue) );
2043 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
2046 // Multi select
2047 // Supports backup lists
2048 else if ($data_type == 36) {
2049 $values_array = explode("|", $currvalue);
2050 $i = 0;
2051 foreach($values_array as $value) {
2052 $lrow = sqlQuery("SELECT title FROM list_options " .
2053 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
2054 if ($lrow == 0 && !empty($backup_list)) {
2055 //use back up list
2056 $lrow = sqlQuery("SELECT title FROM list_options " .
2057 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
2059 if ($i > 0) {
2060 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2061 } else {
2062 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2064 $i++;
2068 // Image from canvas drawing
2069 else if ($data_type == 40) {
2070 $s .= "<img src='" . attr($currvalue) . "'>";
2073 return $s;
2076 // Generate plain text versions of selected LBF field types.
2077 // Currently used by interface/patient_file/download_template.php.
2078 // More field types might need to be supported here in the future.
2080 function generate_plaintext_field($frow, $currvalue) {
2081 global $ISSUE_TYPES;
2083 $data_type = $frow['data_type'];
2084 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2085 $list_id = $frow['list_id'];
2086 $backup_list = $frow['backup_list'];
2087 $s = '';
2089 // generic selection list or the generic selection list with add on the fly
2090 // feature, or radio buttons
2091 // Supports backup lists (for datatypes 1,26,33)
2092 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2093 $lrow = sqlQuery("SELECT title FROM list_options " .
2094 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
2095 $s = xl_list_label($lrow['title']);
2096 //if there is no matching value in the corresponding lists check backup list
2097 // only supported in data types 1,26,33
2098 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2099 $lrow = sqlQuery("SELECT title FROM list_options " .
2100 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
2101 $s = xl_list_label($lrow['title']);
2105 // simple or long text field
2106 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2107 $s = $currvalue;
2110 // date
2111 else if ($data_type == 4) {
2112 $s = oeFormatShortDate($currvalue);
2113 // Optional display of age or gestational age.
2114 $asof=''; //not used here, but set to prevent a php warning when call optionalAge
2115 $tmp = optionalAge($frow, $currvalue,$asof);
2116 if ($tmp) $s .= ' ' . $tmp;
2119 // provider
2120 else if ($data_type == 10 || $data_type == 11) {
2121 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2122 "WHERE id = ?", array($currvalue) );
2123 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2126 // pharmacy list
2127 else if ($data_type == 12) {
2128 $pres = get_pharmacies();
2129 while ($prow = sqlFetchArray($pres)) {
2130 $key = $prow['id'];
2131 if ($currvalue == $key) {
2132 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2133 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2134 $prow['line1'] . ' / ' . $prow['city'];
2139 // address book
2140 else if ($data_type == 14) {
2141 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2142 "WHERE id = ?", array($currvalue));
2143 $uname = $urow['lname'];
2144 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2145 $s = $uname;
2148 // insurance company list
2149 else if ($data_type == 16) {
2150 $insprovs = getInsuranceProviders();
2151 foreach ($insprovs as $key => $ipname) {
2152 if ($currvalue == $key) {
2153 $s .= $ipname;
2158 // issue type
2159 else if ($data_type == 17) {
2160 foreach ($ISSUE_TYPES as $key => $value) {
2161 if ($currvalue == $key) {
2162 $s .= $value[1];
2167 // visit category
2168 else if ($data_type == 18) {
2169 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2170 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2171 array($currvalue));
2172 $s = $crow['pc_catname'];
2175 // a set of labeled checkboxes
2176 else if ($data_type == 21) {
2177 $avalue = explode('|', $currvalue);
2178 $lres = sqlStatement("SELECT * FROM list_options " .
2179 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2180 $count = 0;
2181 while ($lrow = sqlFetchArray($lres)) {
2182 $option_id = $lrow['option_id'];
2183 if (in_array($option_id, $avalue)) {
2184 if ($count++) $s .= "; ";
2185 $s .= xl_list_label($lrow['title']);
2190 // a set of labeled text input fields
2191 else if ($data_type == 22) {
2192 $tmp = explode('|', $currvalue);
2193 $avalue = array();
2194 foreach ($tmp as $value) {
2195 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2196 $avalue[$matches[1]] = $matches[2];
2199 $lres = sqlStatement("SELECT * FROM list_options " .
2200 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2201 while ($lrow = sqlFetchArray($lres)) {
2202 $option_id = $lrow['option_id'];
2203 if (empty($avalue[$option_id])) continue;
2204 if ($s !== '') $s .= '; ';
2205 $s .= xl_list_label($lrow['title']) . ': ';
2206 $s .= $avalue[$option_id];
2210 // A set of exam results; 3 radio buttons and a text field.
2211 // This shows abnormal results only.
2212 else if ($data_type == 23) {
2213 $tmp = explode('|', $currvalue);
2214 $avalue = array();
2215 foreach ($tmp as $value) {
2216 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2217 $avalue[$matches[1]] = $matches[2];
2220 $lres = sqlStatement("SELECT * FROM list_options " .
2221 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2222 while ($lrow = sqlFetchArray($lres)) {
2223 $option_id = $lrow['option_id'];
2224 $restype = substr($avalue[$option_id], 0, 1);
2225 $resnote = substr($avalue[$option_id], 2);
2226 if (empty($restype) && empty($resnote)) continue;
2227 if ($restype != '2') continue; // show abnormal results only
2228 if ($s !== '') $s .= '; ';
2229 $s .= xl_list_label($lrow['title']);
2230 if (!empty($resnote)) $s .= ': ' . $resnote;
2234 // the list of active allergies for the current patient
2235 else if ($data_type == 24) {
2236 $query = "SELECT title, comments FROM lists WHERE " .
2237 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2238 "ORDER BY begdate";
2239 $lres = sqlStatement($query, array($GLOBALS['pid']));
2240 $count = 0;
2241 while ($lrow = sqlFetchArray($lres)) {
2242 if ($count++) $s .= "; ";
2243 $s .= $lrow['title'];
2244 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2248 // a set of labeled checkboxes, each with a text field:
2249 else if ($data_type == 25) {
2250 $tmp = explode('|', $currvalue);
2251 $avalue = array();
2252 foreach ($tmp as $value) {
2253 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2254 $avalue[$matches[1]] = $matches[2];
2257 $lres = sqlStatement("SELECT * FROM list_options " .
2258 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2259 while ($lrow = sqlFetchArray($lres)) {
2260 $option_id = $lrow['option_id'];
2261 $restype = substr($avalue[$option_id], 0, 1);
2262 $resnote = substr($avalue[$option_id], 2);
2263 if (empty($restype) && empty($resnote)) continue;
2264 if ($s !== '') $s .= '; ';
2265 $s .= xl_list_label($lrow['title']);
2266 $restype = $restype ? xl('Yes') : xl('No');
2267 $s .= $restype;
2268 if ($resnote) $s .= ' ' . $resnote;
2272 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2273 // VicarePlus :: A selection list for smoking status.
2274 else if ($data_type == 28 || $data_type == 32) {
2275 $tmp = explode('|', $currvalue);
2276 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2277 $restype = count($tmp) > 1 ? $tmp[1] : '';
2278 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2279 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2280 $res = "";
2281 if ($restype == "current" . $field_id) $res = xl('Current');
2282 if ($restype == "quit" . $field_id) $res = xl('Quit');
2283 if ($restype == "never" . $field_id) $res = xl('Never');
2284 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2286 if ($data_type == 28) {
2287 if (!empty($resnote)) $s .= $resnote;
2289 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2290 else if ($data_type == 32) {
2291 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2292 if (!empty($resnote)) $s .= ' ' . $resnote;
2294 if (!empty($res)) {
2295 if ($s !== '') $s .= ' ';
2296 $s .= xl('Status') . ' ' . $res;
2298 if ($restype == "quit".$field_id) {
2299 if ($s !== '') $s .= ' ';
2300 $s .= $resdate;
2304 // Multi select
2305 // Supports backup lists
2306 else if ($data_type == 36) {
2307 $values_array = explode("|", $currvalue);
2309 $i = 0;
2310 foreach($values_array as $value) {
2311 $lrow = sqlQuery("SELECT title FROM list_options " .
2312 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
2314 if ($lrow == 0 && !empty($backup_list)) {
2315 //use back up list
2316 $lrow = sqlQuery("SELECT title FROM list_options " .
2317 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
2320 if ($i > 0) {
2321 $s = $s . ", " . xl_list_label($lrow['title']);
2322 } else {
2323 $s = xl_list_label($lrow['title']);
2326 $i++;
2330 return $s;
2333 $CPR = 4; // cells per row of generic data
2334 $last_group = '';
2335 $cell_count = 0;
2336 $item_count = 0;
2338 function disp_end_cell() {
2339 global $item_count, $cell_count;
2340 if ($item_count > 0) {
2341 echo "</td>";
2342 $item_count = 0;
2346 function disp_end_row() {
2347 global $cell_count, $CPR;
2348 disp_end_cell();
2349 if ($cell_count > 0) {
2350 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
2351 echo "</tr>\n";
2352 $cell_count = 0;
2356 function disp_end_group() {
2357 global $last_group;
2358 if (strlen($last_group) > 0) {
2359 disp_end_row();
2363 function display_layout_rows($formtype, $result1, $result2='') {
2364 global $item_count, $cell_count, $last_group, $CPR;
2366 $fres = sqlStatement("SELECT * FROM layout_options " .
2367 "WHERE form_id = ? AND uor > 0 " .
2368 "ORDER BY group_name, seq", array($formtype) );
2370 while ($frow = sqlFetchArray($fres)) {
2371 $this_group = $frow['group_name'];
2372 $titlecols = $frow['titlecols'];
2373 $datacols = $frow['datacols'];
2374 $data_type = $frow['data_type'];
2375 $field_id = $frow['field_id'];
2376 $list_id = $frow['list_id'];
2377 $currvalue = '';
2379 if ($formtype == 'DEM') {
2380 if (strpos($field_id, 'em_') === 0) {
2381 // Skip employer related fields, if it's disabled.
2382 if ($GLOBALS['omit_employers']) continue;
2383 $tmp = substr($field_id, 3);
2384 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2386 else {
2387 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2390 else {
2391 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2394 // Handle a data category (group) change.
2395 if (strcmp($this_group, $last_group) != 0) {
2396 $group_name = substr($this_group, 1);
2397 // totally skip generating the employer category, if it's disabled.
2398 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2399 disp_end_group();
2400 $last_group = $this_group;
2403 // filter out all the empty field data from the patient report.
2404 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2405 // Handle starting of a new row.
2406 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2407 disp_end_row();
2408 echo "<tr>";
2409 if ($group_name) {
2410 echo "<td class='groupname'>";
2411 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2412 //echo "<font color='#008800'>$group_name</font>";
2414 // Added 5-09 by BM - Translate label if applicable
2415 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
2417 $group_name = '';
2418 } else {
2419 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2420 echo "<td valign='top'>&nbsp;";
2422 echo "</td>";
2425 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2427 // Handle starting of a new label cell.
2428 if ($titlecols > 0) {
2429 disp_end_cell();
2430 //echo "<td class='label' colspan='$titlecols' valign='top'";
2431 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2432 echo "<td class='label' colspan='$titlecols_esc' ";
2433 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2434 echo ">";
2435 $cell_count += $titlecols;
2437 ++$item_count;
2439 // Added 5-09 by BM - Translate label if applicable
2440 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2442 // Handle starting of a new data cell.
2443 if ($datacols > 0) {
2444 disp_end_cell();
2445 //echo "<td class='text data' colspan='$datacols' valign='top'";
2446 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2447 echo "<td class='text data' colspan='$datacols_esc'";
2448 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2449 echo ">";
2450 $cell_count += $datacols;
2453 ++$item_count;
2454 echo generate_display_field($frow, $currvalue);
2458 disp_end_group();
2461 function display_layout_tabs($formtype, $result1, $result2='') {
2462 global $item_count, $cell_count, $last_group, $CPR;
2464 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2465 "WHERE form_id = ? AND uor > 0 " .
2466 "ORDER BY group_name, seq", array($formtype) );
2468 $first = true;
2469 while ($frow = sqlFetchArray($fres)) {
2470 $this_group = $frow['group_name'];
2471 $group_name = substr($this_group, 1);
2472 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2474 <li <?php echo $first ? 'class="current"' : '' ?>>
2475 <a href="#" id="header_tab_<?php echo str_replace(" ", "_",htmlspecialchars($group_name,ENT_QUOTES))?>">
2476 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
2477 </li>
2478 <?php
2479 $first = false;
2483 function display_layout_tabs_data($formtype, $result1, $result2='') {
2484 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2486 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2487 "WHERE form_id = ? AND uor > 0 " .
2488 "ORDER BY group_name, seq", array($formtype));
2490 $first = true;
2491 while ($frow = sqlFetchArray($fres)) {
2492 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
2493 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
2494 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
2495 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
2496 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
2497 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
2498 $currvalue = '';
2500 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2502 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2503 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2504 "ORDER BY seq", array($formtype, $this_group) );
2507 <div class="tab <?php echo $first ? 'current' : '' ?>">
2508 <table border='0' cellpadding='0'>
2510 <?php
2511 while ($group_fields = sqlFetchArray($group_fields_query)) {
2513 $titlecols = $group_fields['titlecols'];
2514 $datacols = $group_fields['datacols'];
2515 $data_type = $group_fields['data_type'];
2516 $field_id = $group_fields['field_id'];
2517 $list_id = $group_fields['list_id'];
2518 $currvalue = '';
2519 $condition_str = get_conditions_str($condition_str,$group_fields);
2522 if ($formtype == 'DEM') {
2523 if (strpos($field_id, 'em_') === 0) {
2524 // Skip employer related fields, if it's disabled.
2525 if ($GLOBALS['omit_employers']) continue;
2526 $tmp = substr($field_id, 3);
2527 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2529 else {
2530 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2533 else {
2534 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2537 // Handle a data category (group) change.
2538 if (strcmp($this_group, $last_group) != 0) {
2539 $group_name = substr($this_group, 1);
2540 // totally skip generating the employer category, if it's disabled.
2541 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2542 $last_group = $this_group;
2545 // Handle starting of a new row.
2546 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2547 disp_end_row();
2548 echo "<tr>";
2551 if ($item_count == 0 && $titlecols == 0) {
2552 $titlecols = 1;
2555 // Handle starting of a new label cell.
2556 if ($titlecols > 0) {
2557 disp_end_cell();
2558 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2559 $field_id_label = 'label_'.$group_fields['field_id'];
2560 echo "<td class='label' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
2561 echo ">";
2562 $cell_count += $titlecols;
2564 ++$item_count;
2566 $field_id_label = 'label_'.$group_fields['field_id'];
2567 echo "<span id='".attr($field_id_label)."'>";
2568 // Added 5-09 by BM - Translate label if applicable
2569 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2570 echo "</span>";
2572 // Handle starting of a new data cell.
2573 if ($datacols > 0) {
2574 disp_end_cell();
2575 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2576 $field_id = 'text_'.$group_fields['field_id'];
2577 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
2578 echo ">";
2579 $cell_count += $datacols;
2580 } else {
2581 $field_id = 'text_'.$group_fields['field_id'];
2582 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
2585 ++$item_count;
2586 echo generate_display_field($group_fields, $currvalue);
2589 disp_end_row();
2592 </table>
2593 </div>
2595 <?php
2597 $first = false;
2603 function get_conditions_str($condition_str,$frow){
2604 $conditions = empty($frow['conditions']) ? array() : unserialize($frow['conditions']);
2605 foreach ($conditions as $condition) {
2606 if (empty($condition['id'])) continue;
2607 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2608 if ($condition_str) $condition_str .= ",\n";
2609 $condition_str .= "{" .
2610 "target:'" . addslashes($frow['field_id']) . "', " .
2611 "id:'" . addslashes($condition['id']) . "', " .
2612 "itemid:'" . addslashes($condition['itemid']) . "', " .
2613 "operator:'" . addslashes($condition['operator']) . "', " .
2614 "value:'" . addslashes($condition['value']) . "', " .
2615 "andor:'" . addslashes($andor) . "'}";
2617 return $condition_str;
2619 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2620 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2622 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2623 "WHERE form_id = ? AND uor > 0 " .
2624 "ORDER BY group_name, seq", array($formtype) );
2626 $first = true;
2627 while ($frow = sqlFetchArray($fres)) {
2628 $this_group = $frow['group_name'];
2629 $group_name = substr($this_group, 1);
2630 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
2631 $titlecols = $frow['titlecols'];
2632 $datacols = $frow['datacols'];
2633 $data_type = $frow['data_type'];
2634 $field_id = $frow['field_id'];
2635 $list_id = $frow['list_id'];
2636 $currvalue = '';
2638 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2640 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2641 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2642 "ORDER BY seq", array($formtype,$this_group) );
2645 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_',$group_name_esc)?>" >
2646 <table border='0' cellpadding='0'>
2648 <?php
2649 while ($group_fields = sqlFetchArray($group_fields_query)) {
2651 $titlecols = $group_fields['titlecols'];
2652 $datacols = $group_fields['datacols'];
2653 $data_type = $group_fields['data_type'];
2654 $field_id = $group_fields['field_id'];
2655 $list_id = $group_fields['list_id'];
2656 $backup_list = $group_fields['list_backup_id'];
2657 $condition_str = get_conditions_str($condition_str,$group_fields);
2658 $currvalue = '';
2660 if ($formtype == 'DEM') {
2661 if (strpos($field_id, 'em_') === 0) {
2662 // Skip employer related fields, if it's disabled.
2663 if ($GLOBALS['omit_employers']) continue;
2664 $tmp = substr($field_id, 3);
2665 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2667 else {
2668 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2671 else {
2672 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2675 // Handle a data category (group) change.
2676 if (strcmp($this_group, $last_group) != 0) {
2677 $group_name = substr($this_group, 1);
2678 // totally skip generating the employer category, if it's disabled.
2679 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2680 $last_group = $this_group;
2683 // Handle starting of a new row.
2684 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2685 disp_end_row();
2686 echo "<tr>";
2689 if ($item_count == 0 && $titlecols == 0) {
2690 $titlecols = 1;
2693 // Handle starting of a new label cell.
2694 if ($titlecols > 0) {
2695 disp_end_cell();
2696 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2697 $field_id_label = 'label_'.$group_fields['field_id'];
2698 echo "<td class='label' colspan='$titlecols_esc' id='$field_id_label' ";
2699 echo ">";
2700 $cell_count += $titlecols;
2702 ++$item_count;
2704 // Added 5-09 by BM - Translate label if applicable
2705 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
2707 // Handle starting of a new data cell.
2708 if ($datacols > 0) {
2709 disp_end_cell();
2710 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2711 $field_id = 'text_'.$group_fields['field_id'];
2712 echo "<td class='text data' colspan='$datacols_esc' id='$field_id'";
2713 echo ">";
2714 $cell_count += $datacols;
2717 ++$item_count;
2719 echo generate_form_field($group_fields, $currvalue);
2723 </table>
2724 </div>
2726 <?php
2728 $first = false;
2733 // From the currently posted HTML form, this gets the value of the
2734 // field corresponding to the provided layout_options table row.
2736 function get_layout_form_value($frow, $prefix='form_') {
2737 // Bring in $sanitize_all_escapes variable, which will decide
2738 // the variable escaping method.
2739 global $sanitize_all_escapes;
2741 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
2742 $data_type = $frow['data_type'];
2743 $field_id = $frow['field_id'];
2744 $value = '';
2745 if (isset($_POST["$prefix$field_id"])) {
2746 if ($data_type == 21) {
2747 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2748 // must be concatenated into a |-separated string.
2749 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2750 if (strlen($value)) $value .= '|';
2751 $value .= $key;
2754 else if ($data_type == 22) {
2755 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2756 // into "key:value|key:value|...".
2757 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2758 $val = str_replace('|', ' ', $val);
2759 if (strlen($value)) $value .= '|';
2760 $value .= "$key:$val";
2763 else if ($data_type == 23) {
2764 // $_POST["$prefix$field_id"] is an array of text fields with companion
2765 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2766 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2767 $restype = $_POST["radio_{$field_id}"][$key];
2768 if (empty($restype)) $restype = '0';
2769 $val = str_replace('|', ' ', $val);
2770 if (strlen($value)) $value .= '|';
2771 $value .= "$key:$restype:$val";
2774 else if ($data_type == 25) {
2775 // $_POST["$prefix$field_id"] is an array of text fields with companion
2776 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2777 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2778 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
2779 $val = str_replace('|', ' ', $val);
2780 if (strlen($value)) $value .= '|';
2781 $value .= "$key:$restype:$val";
2784 else if ($data_type == 28 || $data_type == 32) {
2785 // $_POST["$prefix$field_id"] is an date text fields with companion
2786 // radio buttons to be imploded into "notes|type|date".
2787 $restype = $_POST["radio_{$field_id}"];
2788 if (empty($restype)) $restype = '0';
2789 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2790 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2791 if ($data_type == 32)
2793 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2794 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2795 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2796 $value = "$res_text_note|$restype|$resdate|$reslist";
2798 else
2799 $value = "$resnote|$restype|$resdate";
2801 else if ($data_type == 36) {
2802 $value_array = $_POST["form_$field_id"];
2803 $i = 0;
2804 foreach ($value_array as $key => $valueofkey) {
2805 if ($i == 0) {
2806 $value = $valueofkey;
2807 } else {
2808 $value = $value . "|" . $valueofkey;
2810 $i++;
2813 else {
2814 $value = $_POST["$prefix$field_id"];
2818 // Better to die than to silently truncate data!
2819 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2820 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2821 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2823 // Make sure the return value is quote-safe.
2824 if ($sanitize_all_escapes) {
2825 //escapes already removed and using binding/placemarks in sql calls
2826 // so only need to trim value
2827 return trim($value);
2829 else {
2830 //need to explicitly prepare value
2831 return formTrim($value);
2835 // Generate JavaScript validation logic for the required fields.
2837 function generate_layout_validation($form_id) {
2838 $fres = sqlStatement("SELECT * FROM layout_options " .
2839 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2840 "ORDER BY group_name, seq", array($form_id) );
2842 while ($frow = sqlFetchArray($fres)) {
2843 $data_type = $frow['data_type'];
2844 $field_id = $frow['field_id'];
2845 $fldtitle = $frow['title'];
2846 if (!$fldtitle) $fldtitle = $frow['description'];
2847 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES);
2849 if ($data_type == 40) {
2850 $fldid = addslashes("form_$field_id");
2851 // Move canvas image data to its hidden form field so the server will get it.
2852 echo
2853 " var canfld = f['$fldid'];\n" .
2854 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
2855 continue;
2858 if ($frow['uor'] < 2) continue;
2860 switch($data_type) {
2861 case 1:
2862 case 11:
2863 case 12:
2864 case 13:
2865 case 14:
2866 case 26:
2867 case 33:
2868 echo
2869 " if (f.$fldname.selectedIndex <= 0) {\n" .
2870 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2871 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2872 " }\n";
2873 break;
2874 case 27: // radio buttons
2875 echo
2876 " var i = 0;\n" .
2877 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2878 " if (i >= f.$fldname.length) {\n" .
2879 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2880 " }\n";
2881 break;
2882 case 2:
2883 case 3:
2884 case 4:
2885 case 15:
2886 echo
2887 " if (trimlen(f.$fldname.value) == 0) {\n" .
2888 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2889 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2890 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2891 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2892 " } else { " .
2893 " $('#" . $fldname . "').attr('style',''); " .
2894 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2895 " } \n";
2896 break;
2897 case 36: // multi select
2898 echo
2899 " var multi_select=f['$fldname"."[]']; \n " .
2900 " var multi_choice_made=false; \n".
2901 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
2902 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
2903 " } \n" .
2904 " if(!multi_choice_made)
2905 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2907 break;
2913 * DROPDOWN FOR FACILITIES
2915 * build a dropdown with all facilities
2917 * @param string $selected - name of the currently selected facility
2918 * use '0' for "unspecified facility"
2919 * use '' for "All facilities" (the default)
2920 * @param string $name - the name/id for select form (defaults to "form_facility")
2921 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2922 * defaults to true
2923 * @return void - just echo the html encoded string
2925 * Note: This should become a data-type at some point, according to Brady
2927 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2928 $allow_allfacilities = true, $disabled='', $onchange='')
2930 $have_selected = false;
2931 $query = "SELECT id, name FROM facility ORDER BY name";
2932 $fres = sqlStatement($query);
2934 $name = htmlspecialchars($name, ENT_QUOTES);
2935 echo " <select name='$name' id='$name'";
2936 if ($onchange) echo " onchange='$onchange'";
2937 echo " $disabled>\n";
2939 if ($allow_allfacilities) {
2940 $option_value = '';
2941 $option_selected_attr = '';
2942 if ($selected == '') {
2943 $option_selected_attr = ' selected="selected"';
2944 $have_selected = true;
2946 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2947 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2948 } elseif ($allow_unspecified) {
2949 $option_value = '0';
2950 $option_selected_attr = '';
2951 if ( $selected == '0' ) {
2952 $option_selected_attr = ' selected="selected"';
2953 $have_selected = true;
2955 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2956 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2959 while ($frow = sqlFetchArray($fres)) {
2960 $facility_id = $frow['id'];
2961 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2962 $option_selected_attr = '';
2963 if ($selected == $facility_id) {
2964 $option_selected_attr = ' selected="selected"';
2965 $have_selected = true;
2967 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2968 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2971 if ($allow_unspecified && $allow_allfacilities) {
2972 $option_value = '0';
2973 $option_selected_attr = '';
2974 if ( $selected == '0' ) {
2975 $option_selected_attr = ' selected="selected"';
2976 $have_selected = true;
2978 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2979 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2982 if (!$have_selected) {
2983 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2984 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2985 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2986 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2988 echo " </select>\n";
2991 // Expand Collapse Widget
2992 // This forms the header and functionality component of the widget. The information that is displayed
2993 // then follows this function followed by a closing div tag
2995 // $title is the title of the section (already translated)
2996 // $label is identifier used in the tag id's and sql columns
2997 // $buttonLabel is the button label text (already translated)
2998 // $buttonLink is the button link information
2999 // $buttonClass is any additional needed class elements for the button tag
3000 // $linkMethod is the button link method ('javascript' vs 'html')
3001 // $bodyClass is to set class(es) of the body
3002 // $auth is a flag to decide whether to show the button
3003 // $fixedWidth is to flag whether width is fixed
3004 // $forceExpandAlways is a flag to force the widget to always be expanded
3006 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
3007 if ($fixedWidth) {
3008 echo "<div class='section-header'>";
3010 else {
3011 echo "<div class='section-header-dynamic'>";
3013 echo "<table><tr>";
3014 if ($auth) {
3015 // show button, since authorized
3016 // first prepare class string
3017 if ($buttonClass) {
3018 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
3020 else {
3021 $class_string = "css_button_small";
3023 // next, create the link
3024 if ($linkMethod == "javascript") {
3025 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3027 else {
3028 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3029 if (!isset($_SESSION['patient_portal_onsite'])) {
3030 // prevent an error from occuring when calling the function from the patient portal
3031 echo " onclick='top.restoreSession()'";
3034 if (!$GLOBALS['concurrent_layout']) {
3035 echo " target='Main'";
3037 echo "><span>" .
3038 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
3040 if ($forceExpandAlways){
3041 // Special case to force the widget to always be expanded
3042 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
3043 $indicatorTag ="style='display:none'";
3045 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3046 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3047 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
3048 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
3050 if (isset($_SESSION['patient_portal_onsite'])) {
3051 // collapse all entries in the patient portal
3052 $text = xl('expand');
3054 else if (getUserSetting($label."_ps_expand")) {
3055 $text = xl('collapse');
3057 else {
3058 $text = xl('expand');
3060 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
3061 "</span>)</a></td>";
3062 echo "</tr></table>";
3063 echo "</div>";
3064 if ($forceExpandAlways) {
3065 // Special case to force the widget to always be expanded
3066 $styling = "";
3068 else if (isset($_SESSION['patient_portal_onsite'])) {
3069 // collapse all entries in the patient portal
3070 $styling = "style='display:none'";
3072 else if (getUserSetting($label."_ps_expand")) {
3073 $styling = "";
3075 else {
3076 $styling = "style='display:none'";
3078 if ($bodyClass) {
3079 $styling .= " class='" . $bodyClass . "'";
3081 //next, create the first div tag to hold the information
3082 // note the code that calls this function will then place the ending div tag after the data
3083 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
3086 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3087 function billing_facility($name,$select){
3088 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
3089 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3090 while ($facrow = sqlFetchArray($qsql)) {
3091 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3092 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3094 echo "</select>";
3097 // Generic function to get the translated title value for a particular list option.
3099 function getListItemTitle($list, $option) {
3100 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3101 "list_id = ? AND option_id = ?", array($list, $option));
3102 if (empty($row['title'])) return $option;
3103 return xl_list_label($row['title']);
3105 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3106 function getSmokeCodes()
3108 $smoking_codes_arr = array();
3109 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status'");
3110 while($codes_row = sqlFetchArray($smoking_codes))
3112 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3114 return $smoking_codes_arr;
3117 // Get the current value for a layout based form field.
3118 // Depending on options this might come from lbf_data, patient_data,
3119 // form_encounter, shared_attributes or elsewhere.
3120 // Returns FALSE if the field ID is invalid (layout error).
3122 function lbf_current_value($frow, $formid, $encounter) {
3123 global $pid;
3124 $formname = $frow['form_id'];
3125 $field_id = $frow['field_id'];
3126 $source = $frow['source'];
3127 $currvalue = '';
3128 $deffname = $formname . '_default_' . $field_id;
3129 if ($source == 'D' || $source == 'H') {
3130 // Get from patient_data, employer_data or history_data.
3131 if ($source == 'H') {
3132 $table = 'history_data';
3133 $orderby = 'ORDER BY date DESC LIMIT 1';
3135 else if (strpos($field_id, 'em_') === 0) {
3136 $field_id = substr($field_id, 3);
3137 $table = 'employer_data';
3138 $orderby = 'ORDER BY date DESC LIMIT 1';
3140 else {
3141 $table = 'patient_data';
3142 $orderby = '';
3144 // It is an error if the field does not exist, but don't crash.
3145 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3146 if (empty($tmp)) return FALSE;
3147 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3148 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3150 else if ($source == 'E') {
3151 if ($encounter) {
3152 // Get value from shared_attributes of the current encounter.
3153 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3154 "pid = ? AND encounter = ? AND field_id = ?",
3155 array($pid, $encounter, $field_id));
3156 if (isset($sarow)) $currvalue = $sarow['field_value'];
3158 else if ($formid) {
3159 // Get from shared_attributes of the encounter that this form is linked to.
3160 // Note the importance of having an index on forms.form_id.
3161 $sarow = sqlQuery("SELECT sa.field_value " .
3162 "FROM forms AS f, shared_attributes AS sa WHERE " .
3163 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3164 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3165 array($formid, $formname, $field_id));
3166 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3168 else {
3169 // New form and encounter not available, this should not happen.
3172 else if ($source == 'V') {
3173 if ($encounter) {
3174 // Get value from the current encounter's form_encounter.
3175 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3176 "pid = ? AND encounter = ?",
3177 array($pid, $encounter));
3178 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3180 else if ($formid) {
3181 // Get value from the form_encounter that this form is linked to.
3182 $ferow = sqlQuery("SELECT fe.* " .
3183 "FROM forms AS f, form_encounter AS fe WHERE " .
3184 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3185 "fe.pid = f.pid AND fe.encounter = f.encounter",
3186 array($formid, $formname));
3187 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3189 else {
3190 // New form and encounter not available, this should not happen.
3193 else if ($formid) {
3194 // This is a normal form field.
3195 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3196 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3197 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3199 else {
3200 // New form, see if there is a custom default from a plugin.
3201 // This logic does not apply to shared attributes because they do not
3202 // have a "new form" concept.
3203 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3205 return $currvalue;
3208 // This returns stuff that needs to go into the <head> section of a caller using
3209 // the drawable image field type in a form.
3210 // A TRUE argument makes the widget 25% less tall.
3212 function lbf_canvas_head($small=FALSE) {
3213 $s = <<<EOD
3214 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3215 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3216 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3217 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3218 EOD;
3219 if ($small) $s .= <<<EOD
3220 <style>
3221 /* Custom LiterallyCanvas styling.
3222 * This makes the widget 25% less tall and adjusts some other things accordingly.
3224 .literally {
3225 min-height:292px;min-width:300px; /* Was 400, unspecified */
3227 .literally .lc-picker .toolbar-button {
3228 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3230 .literally .color-well {
3231 font-size:8px;width:49px; /* Was 10, 60 */
3233 .literally .color-well-color-container {
3234 width:21px;height:21px; /* Was 28, 28 */
3236 .literally .lc-picker {
3237 width:50px; /* Was 61 */
3239 .literally .lc-drawing.with-gui {
3240 left:50px; /* Was 61 */
3242 .literally .lc-options {
3243 left:50px; /* Was 61 */
3245 .literally .color-picker-popup {
3246 left:49px;bottom:0px; /* Was 60, 31 */
3248 </style>
3249 EOD;
3250 return $s;