Added Visolve suggestion to globals for Calendar default view type
[openemr.git] / library / options.inc.php
blob77e99f6de1965a717890f09d483dc5c17a755c4b
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 . "[]";
91 $s .= "<select name='$tag_name_esc'";
93 if ($multiple) {
94 $s .= " multiple='multiple'";
97 $tag_id_esc = $tag_name_esc;
98 if ($tag_id != '') {
99 $tag_id_esc = attr($tag_id);
102 if ($multiple) {
103 $tag_id_esc = $tag_id_esc . "[]";
105 $s .= " id='$tag_id_esc'";
107 if ($class) {
108 $class_esc = attr($class);
109 $s .= " class='$class_esc'";
111 if ($onchange) {
112 $s .= " onchange='$onchange'";
114 if ($custom_attributes != null && is_array ( $custom_attributes )) {
115 foreach ( $custom_attributes as $attr => $val ) {
116 if (isset ( $custom_attributes [$attr] )) {
117 $s .= " " . attr($attr) . "='" . attr($val) . "'";
121 $selectTitle = attr($title);
122 $s .= " title='$selectTitle'>";
123 $selectEmptyName = xlt($empty_name);
124 if ($empty_name)
125 $s .= "<option value=''>" . $selectEmptyName . "</option>";
126 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? ORDER BY seq, title", array($list_id));
127 $got_selected = FALSE;
129 while ( $lrow = sqlFetchArray ( $lres ) ) {
130 $selectedValues = explode ( "|", $currvalue );
132 $optionValue = attr($lrow ['option_id']);
133 $s .= "<option value='$optionValue'";
135 if ($multiple && (strlen ( $currvalue ) == 0 && $lrow ['is_default']) || (strlen ( $currvalue ) > 0 && in_array ( $lrow ['option_id'], $selectedValues ))) {
136 $s .= " selected";
137 $got_selected = TRUE;
140 $optionLabel = text(xl_list_label($lrow ['title']));
141 $s .= ">$optionLabel</option>\n";
144 if (!$got_selected && strlen ( $currvalue ) > 0 && !$multiple) {
145 $list_id = $backup_list;
146 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
148 if ($lrow > 0 && !empty($backup_list)) {
149 $selected = text(xl_list_label($lrow ['title']));
150 $s .= "<option value='$currescaped' selected> $selected </option>";
151 $s .= "</select>";
152 } else {
153 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
154 $s .= "</select>";
155 $fontTitle = xlt('Please choose a valid selection from the list.');
156 $fontText = xlt( 'Fix this' );
157 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
160 } else if (!$got_selected && strlen ( $currvalue ) > 0 && $multiple) {
161 //if not found in main list, display all selected values that exist in backup list
162 $list_id = $backup_list;
164 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? ORDER BY seq, title", array($list_id));
166 $got_selected_backup = FALSE;
167 if (!empty($backup_list)) {
168 while ( $lrow_backup = sqlFetchArray ( $lres_backup ) ) {
169 $selectedValues = explode ( "|", $currvalue );
171 $optionValue = attr($lrow ['option_id']);
173 if ($multiple && (strlen ( $currvalue ) == 0 && $lrow_backup ['is_default']) ||
174 (strlen ( $currvalue ) > 0 && in_array ( $lrow_backup ['option_id'], $selectedValues ))) {
175 $s .= "<option value='$optionValue'";
176 $s .= " selected";
177 $optionLabel = text(xl_list_label($lrow_backup ['title']));
178 $s .= ">$optionLabel</option>\n";
179 $got_selected_backup = TRUE;
183 if (!$got_selected_backup) {
184 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
185 $s .= "</select>";
186 $fontTitle = xlt('Please choose a valid selection from the list.');
187 $fontText = xlt( 'Fix this' );
188 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
192 else {
193 $s .= "</select>";
195 return $s;
199 // $frow is a row from the layout_options table.
200 // $currvalue is the current value, if any, of the associated item.
202 function generate_form_field($frow, $currvalue) {
203 global $rootdir, $date_init, $ISSUE_TYPES, $code_types;
205 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
207 $data_type = $frow['data_type'];
208 $field_id = $frow['field_id'];
209 $list_id = $frow['list_id'];
210 $backup_list = $frow['list_backup_id'];
212 // escaped variables to use in html
213 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
214 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
216 // Added 5-09 by BM - Translate description if applicable
217 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
219 // Support edit option T which assigns the (possibly very long) description as
220 // the default value.
221 if (strpos($frow['edit_options'], 'T') !== FALSE) {
222 if (strlen($currescaped) == 0) $currescaped = $description;
223 // Description used in this way is not suitable as a title.
224 $description = '';
227 // added 5-2009 by BM to allow modification of the 'empty' text title field.
228 // Can pass $frow['empty_title'] with this variable, otherwise
229 // will default to 'Unassigned'.
230 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
231 // if make $frow['empty_title'] equal to 'SKIP'
232 $showEmpty = true;
233 if (isset($frow['empty_title'])) {
234 if ($frow['empty_title'] == "SKIP") {
235 //do not display an 'empty' choice
236 $showEmpty = false;
237 $empty_title = "Unassigned";
239 else {
240 $empty_title = $frow['empty_title'];
243 else {
244 $empty_title = "Unassigned";
247 $disabled = strpos($frow['edit_options'], '0') === FALSE ? '' : 'disabled';
249 $lbfchange = strpos($frow['form_id'], 'LBF') === 0 ? "checkSkipConditions();" : "";
250 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
252 // generic single-selection list or Race and Ethnicity.
253 // These data types support backup lists.
254 if ($data_type == 1 || $data_type == 33) {
255 echo generate_select_list("form_$field_id", $list_id, $currvalue,
256 $description, ($showEmpty ? $empty_title : ''), '', $lbfchange, '',
257 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
260 // simple text field
261 else if ($data_type == 2) {
262 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
263 $maxlength = $frow['max_length'];
264 $string_maxlength = "";
265 // if max_length is set to zero, then do not set a maxlength
266 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
267 echo "<input type='text'" .
268 " name='form_$field_id_esc'" .
269 " id='form_$field_id_esc'" .
270 " size='$fldlength'" .
271 " $string_maxlength" .
272 " title='$description'" .
273 " value='$currescaped'";
274 $tmp = $lbfchange;
275 if (strpos($frow['edit_options'], 'C') !== FALSE)
276 $tmp .= "capitalizeMe(this);";
277 else if (strpos($frow['edit_options'], 'U') !== FALSE)
278 $tmp .= "this.value = this.value.toUpperCase();";
279 if ($tmp) echo " onchange='$tmp'";
280 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
281 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
282 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
283 echo " onblur='maskblur(this,\"$tmp\")'";
285 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
286 echo " readonly";
288 if ($disabled) echo ' disabled';
289 echo " />";
292 // long or multi-line text field
293 else if ($data_type == 3) {
294 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
295 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
296 echo "<textarea" .
297 " name='form_$field_id_esc'" .
298 " id='form_$field_id_esc'" .
299 " title='$description'" .
300 " cols='$textCols'" .
301 " rows='$textRows' $lbfonchange $disabled" .
302 ">" . $currescaped . "</textarea>";
305 // date
306 else if ($data_type == 4) {
307 $age_asof_date = ''; // optionalAge() sets this
308 $age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0;
309 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
310 if ($agestr) {
311 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
313 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
314 " value='" . substr($currescaped, 0, 10) . "'";
315 if (!$agestr) echo " title='$description'";
316 echo " $lbfonchange onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
317 if (!$disabled) {
318 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
319 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
320 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
321 $date_init .= " Calendar.setup({" .
322 "inputField:'form_$field_id', " .
323 "ifFormat:'%Y-%m-%d', ";
324 if ($agestr) {
325 $date_init .= "onUpdate: function() {" .
326 "if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format);" .
327 "}, ";
329 $date_init .= "button:'img_$field_id'})\n";
331 // Optional display of age or gestational age.
332 if ($agestr) {
333 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
337 // provider list, local providers only
338 else if ($data_type == 10) {
339 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
340 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
341 "AND authorized = 1 " .
342 "ORDER BY lname, fname");
343 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled>";
344 echo "<option value=''>" . xlt($empty_title) . "</option>";
345 $got_selected = false;
346 while ($urow = sqlFetchArray($ures)) {
347 $uname = text($urow['fname'] . ' ' . $urow['lname']);
348 $optionId = attr($urow['id']);
349 echo "<option value='$optionId'";
350 if ($urow['id'] == $currvalue) {
351 echo " selected";
352 $got_selected = true;
354 echo ">$uname</option>";
356 if (!$got_selected && $currvalue) {
357 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
358 echo "</select>";
359 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
361 else {
362 echo "</select>";
366 // provider list, including address book entries with an NPI number
367 else if ($data_type == 11) {
368 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
369 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
370 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
371 "ORDER BY lname, fname");
372 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
373 echo " $lbfonchange $disabled>";
374 echo "<option value=''>" . xlt('Unassigned') . "</option>";
375 $got_selected = false;
376 while ($urow = sqlFetchArray($ures)) {
377 $uname = text($urow['fname'] . ' ' . $urow['lname']);
378 $optionId = attr($urow['id']);
379 echo "<option value='$optionId'";
380 if ($urow['id'] == $currvalue) {
381 echo " selected";
382 $got_selected = true;
384 echo ">$uname</option>";
386 if (!$got_selected && $currvalue) {
387 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
388 echo "</select>";
389 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
391 else {
392 echo "</select>";
396 // pharmacy list
397 else if ($data_type == 12) {
398 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
399 echo " $lbfonchange $disabled>";
400 echo "<option value='0'></option>";
401 $pres = get_pharmacies();
402 $got_selected = false;
403 while ($prow = sqlFetchArray($pres)) {
404 $key = $prow['id'];
405 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
406 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
407 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
408 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
409 echo "<option value='$optionValue'";
410 if ($currvalue == $key) {
411 echo " selected";
412 $got_selected = true;
414 echo ">$optionLabel</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 // squads
427 else if ($data_type == 13) {
428 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
429 echo " $lbfonchange $disabled>";
430 echo "<option value=''>&nbsp;</option>";
431 $squads = acl_get_squads();
432 if ($squads) {
433 foreach ($squads as $key => $value) {
434 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
435 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
436 echo "<option value='$optionValue'";
437 if ($currvalue == $key) echo " selected";
438 echo ">$optionLabel</option>\n";
441 echo "</select>";
444 // Address book, preferring organization name if it exists and is not in
445 // parentheses, and excluding local users who are not providers.
446 // Supports "referred to" practitioners and facilities.
447 // Alternatively the letter L in edit_options means that abook_type
448 // must be "ord_lab", indicating types used with the procedure
449 // lab ordering system.
450 // Alternatively the letter O in edit_options means that abook_type
451 // must begin with "ord_", indicating types used with the procedure
452 // ordering system.
453 // Alternatively the letter V in edit_options means that abook_type
454 // must be "vendor", indicating the Vendor type.
455 // Alternatively the letter R in edit_options means that abook_type
456 // must be "dist", indicating the Distributor type.
457 else if ($data_type == 14) {
458 if (strpos($frow['edit_options'], 'L') !== FALSE)
459 $tmp = "abook_type = 'ord_lab'";
460 else if (strpos($frow['edit_options'], 'O') !== FALSE)
461 $tmp = "abook_type LIKE 'ord\\_%'";
462 else if (strpos($frow['edit_options'], 'V') !== FALSE)
463 $tmp = "abook_type LIKE 'vendor%'";
464 else if (strpos($frow['edit_options'], 'R') !== FALSE)
465 $tmp = "abook_type LIKE 'dist'";
466 else
467 $tmp = "( username = '' OR authorized = 1 )";
468 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
469 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
470 "AND $tmp " .
471 "ORDER BY organization, lname, fname");
472 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
473 echo " $lbfonchange $disabled>";
474 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
475 while ($urow = sqlFetchArray($ures)) {
476 $uname = $urow['organization'];
477 if (empty($uname) || substr($uname, 0, 1) == '(') {
478 $uname = $urow['lname'];
479 if ($urow['fname']) $uname .= ", " . $urow['fname'];
481 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
482 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
483 echo "<option value='$optionValue'";
484 $title = $urow['username'] ? xl('Local') : xl('External');
485 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
486 echo " title='$optionTitle'";
487 if ($urow['id'] == $currvalue) echo " selected";
488 echo ">$optionLabel</option>";
490 echo "</select>";
493 // A billing code. If description matches an existing code type then that type is used.
494 else if ($data_type == 15) {
495 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
496 $maxlength = $frow['max_length'];
497 $string_maxlength = "";
498 // if max_length is set to zero, then do not set a maxlength
499 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
501 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
502 // Option "2" generates a hidden input for the codes, and a matching visible field
503 // displaying their descriptions. First step is computing the description string.
504 $currdescstring = '';
505 if (!empty($currvalue)) {
506 $relcodes = explode(';', $currvalue);
507 foreach ($relcodes as $codestring) {
508 if ($codestring === '') continue;
509 $code_text = lookup_code_descriptions($codestring);
510 if ($currdescstring !== '') $currdescstring .= '; ';
511 if (!empty($code_text)) {
512 $currdescstring .= $code_text;
514 else {
515 $currdescstring .= $codestring;
519 $currdescstring = attr($currdescstring);
521 echo "<input type='text'" .
522 " name='form_$field_id_esc'" .
523 " id='form_related_code'" .
524 " size='$fldlength'" .
525 " value='$currescaped'" .
526 " style='display:none'" .
527 " $lbfonchange readonly $disabled />";
528 // Extra readonly input field for optional display of code description(s).
529 echo "<input type='text'" .
530 " name='form_$field_id_esc" . "__desc'" .
531 " size='$fldlength'" .
532 " title='$description'" .
533 " value='$currdescstring'";
534 if (!$disabled) {
535 echo " onclick='sel_related(this,\"$codetype\")'";
537 echo " readonly $disabled />";
539 else {
540 echo "<input type='text'" .
541 " name='form_$field_id_esc'" .
542 " id='form_related_code'" .
543 " size='$fldlength'" .
544 " $string_maxlength" .
545 " title='$description'" .
546 " value='$currescaped'";
547 if (!$disabled) {
548 echo " onclick='sel_related(this,\"$codetype\")'";
550 echo " $lbfonchange readonly $disabled />";
554 // insurance company list
555 else if ($data_type == 16) {
556 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
557 echo "<option value='0'></option>";
558 $insprovs = getInsuranceProviders();
559 $got_selected = false;
560 foreach ($insprovs as $key => $ipname) {
561 $optionValue = htmlspecialchars($key, ENT_QUOTES);
562 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
563 echo "<option value='$optionValue'";
564 if ($currvalue == $key) {
565 echo " selected";
566 $got_selected = true;
568 echo ">$optionLabel</option>";
570 if (!$got_selected && $currvalue) {
571 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
572 echo "</select>";
573 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
575 else {
576 echo "</select>";
580 // issue types
581 else if ($data_type == 17) {
582 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
583 echo "<option value='0'></option>";
584 $got_selected = false;
585 foreach ($ISSUE_TYPES as $key => $value) {
586 $optionValue = htmlspecialchars($key, ENT_QUOTES);
587 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
588 echo "<option value='$optionValue'";
589 if ($currvalue == $key) {
590 echo " selected";
591 $got_selected = true;
593 echo ">$optionLabel</option>";
595 if (!$got_selected && strlen($currvalue) > 0) {
596 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
597 echo "</select>";
598 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
600 else {
601 echo "</select>";
605 // Visit categories.
606 else if ($data_type == 18) {
607 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
608 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
609 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
610 " $lbfonchange $disabled>";
611 echo "<option value=''>" . xlt($empty_title) . "</option>";
612 $got_selected = false;
613 while ($crow = sqlFetchArray($cres)) {
614 $catid = $crow['pc_catid'];
615 if (($catid < 9 && $catid != 5) || $catid == 11) continue;
616 echo "<option value='" . attr($catid) . "'";
617 if ($catid == $currvalue) {
618 echo " selected";
619 $got_selected = true;
621 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
623 if (!$got_selected && $currvalue) {
624 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
625 echo "</select>";
626 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
628 else {
629 echo "</select>";
633 // a set of labeled checkboxes
634 else if ($data_type == 21) {
635 // In this special case, fld_length is the number of columns generated.
636 $cols = max(1, $frow['fld_length']);
637 $avalue = explode('|', $currvalue);
638 $lres = sqlStatement("SELECT * FROM list_options " .
639 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
640 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
641 $tdpct = (int) (100 / $cols);
642 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
643 $option_id = $lrow['option_id'];
644 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
645 // if ($count) echo "<br />";
646 if ($count % $cols == 0) {
647 if ($count) echo "</tr>";
648 echo "<tr>";
650 echo "<td width='$tdpct%'>";
651 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
652 "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
653 if (in_array($option_id, $avalue)) echo " checked";
655 // Added 5-09 by BM - Translate label if applicable
656 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
658 echo "</td>";
660 if ($count) {
661 echo "</tr>";
662 if ($count > $cols) {
663 // Add some space after multiple rows of checkboxes.
664 $cols = htmlspecialchars( $cols, ENT_QUOTES);
665 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
668 echo "</table>";
671 // a set of labeled text input fields
672 else if ($data_type == 22) {
673 $tmp = explode('|', $currvalue);
674 $avalue = array();
675 foreach ($tmp as $value) {
676 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
677 $avalue[$matches[1]] = $matches[2];
680 $lres = sqlStatement("SELECT * FROM list_options " .
681 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
682 echo "<table cellpadding='0' cellspacing='0'>";
683 while ($lrow = sqlFetchArray($lres)) {
684 $option_id = $lrow['option_id'];
685 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
686 $maxlength = $frow['max_length'];
687 $string_maxlength = "";
688 // if max_length is set to zero, then do not set a maxlength
689 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
690 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
692 // Added 5-09 by BM - Translate label if applicable
693 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
694 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
695 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
696 echo "<td><input type='text'" .
697 " name='form_{$field_id_esc}[$option_id_esc]'" .
698 " id='form_{$field_id_esc}[$option_id_esc]'" .
699 " size='$fldlength'" .
700 " $string_maxlength" .
701 " value='$optionValue'";
702 echo " $lbfonchange $disabled /></td></tr>";
704 echo "</table>";
707 // a set of exam results; 3 radio buttons and a text field:
708 else if ($data_type == 23) {
709 $tmp = explode('|', $currvalue);
710 $avalue = array();
711 foreach ($tmp as $value) {
712 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
713 $avalue[$matches[1]] = $matches[2];
716 $maxlength = $frow['max_length'];
717 $string_maxlength = "";
718 // if max_length is set to zero, then do not set a maxlength
719 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
720 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
721 $lres = sqlStatement("SELECT * FROM list_options " .
722 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
723 echo "<table cellpadding='0' cellspacing='0'>";
724 echo "<tr><td>&nbsp;</td><td class='bold'>" .
725 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
726 "&nbsp;</td><td class='bold'>" .
727 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
728 "<td class='bold'>" .
729 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
730 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
731 while ($lrow = sqlFetchArray($lres)) {
732 $option_id = $lrow['option_id'];
733 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
734 $restype = substr($avalue[$option_id], 0, 1);
735 $resnote = substr($avalue[$option_id], 2);
737 // Added 5-09 by BM - Translate label if applicable
738 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
740 for ($i = 0; $i < 3; ++$i) {
741 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
742 echo "<td><input type='radio'" .
743 " name='radio_{$field_id_esc}[$option_id_esc]'" .
744 " id='radio_{$field_id_esc}[$option_id_esc]'" .
745 " value='$inputValue' $lbfonchange";
746 if ($restype === "$i") echo " checked";
747 echo " $disabled /></td>";
749 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
750 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
751 echo "<td><input type='text'" .
752 " name='form_{$field_id_esc}[$option_id_esc]'" .
753 " id='form_{$field_id_esc}[$option_id_esc]'" .
754 " size='$fldlength'" .
755 " $string_maxlength" .
756 " value='$resnote' $disabled /></td>";
757 echo "</tr>";
759 echo "</table>";
762 // the list of active allergies for the current patient
763 // this is read-only!
764 else if ($data_type == 24) {
765 $query = "SELECT title, comments FROM lists WHERE " .
766 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
767 "ORDER BY begdate";
768 // echo "<!-- $query -->\n"; // debugging
769 $lres = sqlStatement($query, array($GLOBALS['pid']));
770 $count = 0;
771 while ($lrow = sqlFetchArray($lres)) {
772 if ($count++) echo "<br />";
773 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
774 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
778 // a set of labeled checkboxes, each with a text field:
779 else if ($data_type == 25) {
780 $tmp = explode('|', $currvalue);
781 $avalue = array();
782 foreach ($tmp as $value) {
783 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
784 $avalue[$matches[1]] = $matches[2];
787 $maxlength = $frow['max_length'];
788 $string_maxlength = "";
789 // if max_length is set to zero, then do not set a maxlength
790 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
791 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
792 $lres = sqlStatement("SELECT * FROM list_options " .
793 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
794 echo "<table cellpadding='0' cellspacing='0'>";
795 while ($lrow = sqlFetchArray($lres)) {
796 $option_id = $lrow['option_id'];
797 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
798 $restype = substr($avalue[$option_id], 0, 1);
799 $resnote = substr($avalue[$option_id], 2);
801 // Added 5-09 by BM - Translate label if applicable
802 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
804 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
805 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
806 " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
807 if ($restype) echo " checked";
808 echo " $disabled />&nbsp;</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 // single-selection list with ability to add to it
823 else if ($data_type == 26) {
824 echo generate_select_list("form_$field_id", $list_id, $currvalue,
825 $description, ($showEmpty ? $empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
826 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
827 // show the add button if user has access to correct list
828 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
829 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
830 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
831 if (aco_exist('lists', $list_id)) {
832 // a specific aco exist for this list, so ensure access
833 if (acl_check('lists', $list_id)) echo $outputAddButton;
835 else {
836 // no specific aco exist for this list, so check for access to 'default' list
837 if (acl_check('lists', 'default')) echo $outputAddButton;
841 // a set of labeled radio buttons
842 else if ($data_type == 27) {
843 // In this special case, fld_length is the number of columns generated.
844 $cols = max(1, $frow['fld_length']);
845 $lres = sqlStatement("SELECT * FROM list_options " .
846 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
847 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
848 $tdpct = (int) (100 / $cols);
849 $got_selected = FALSE;
850 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
851 $option_id = $lrow['option_id'];
852 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
853 if ($count % $cols == 0) {
854 if ($count) echo "</tr>";
855 echo "<tr>";
857 echo "<td width='$tdpct%'>";
858 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
859 " value='$option_id_esc' $lbfonchange";
860 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
861 (strlen($currvalue) > 0 && $option_id == $currvalue))
863 echo " checked";
864 $got_selected = TRUE;
866 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
867 echo "</td>";
869 if ($count) {
870 echo "</tr>";
871 if ($count > $cols) {
872 // Add some space after multiple rows of radio buttons.
873 $cols = htmlspecialchars($cols, ENT_QUOTES);
874 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
877 echo "</table>";
878 if (!$got_selected && strlen($currvalue) > 0) {
879 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
880 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
881 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
885 // special case for history of lifestyle status; 3 radio buttons and a date text field:
886 // VicarePlus :: A selection list box for smoking status:
887 else if ($data_type == 28 || $data_type == 32) {
888 $tmp = explode('|', $currvalue);
889 switch(count($tmp)) {
890 case "4": {
891 $resnote = $tmp[0];
892 $restype = $tmp[1];
893 $resdate = $tmp[2];
894 $reslist = $tmp[3];
895 } break;
896 case "3": {
897 $resnote = $tmp[0];
898 $restype = $tmp[1];
899 $resdate = $tmp[2];
900 } break;
901 case "2": {
902 $resnote = $tmp[0];
903 $restype = $tmp[1];
904 $resdate = "";
905 } break;
906 case "1": {
907 $resnote = $tmp[0];
908 $resdate = $restype = "";
909 } break;
910 default: {
911 $restype = $resdate = $resnote = "";
912 } break;
914 $maxlength = $frow['max_length'];
915 $string_maxlength = "";
916 // if max_length is set to zero, then do not set a maxlength
917 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
918 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
920 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
921 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
922 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
923 echo "<table cellpadding='0' cellspacing='0'>";
924 echo "<tr>";
925 if ($data_type == 28)
927 // input text
928 echo "<td><input type='text'" .
929 " name='form_$field_id_esc'" .
930 " id='form_$field_id_esc'" .
931 " size='$fldlength'" .
932 " $string_maxlength" .
933 " value='$resnote' $disabled />&nbsp;</td>";
934 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
935 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
936 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
938 else if($data_type == 32)
940 // input text
941 echo "<tr><td><input type='text'" .
942 " name='form_text_$field_id_esc'" .
943 " id='form_text_$field_id_esc'" .
944 " size='$fldlength'" .
945 " $string_maxlength" .
946 " value='$resnote' $disabled />&nbsp;</td></tr>";
947 echo "<td>";
948 //Selection list for smoking status
949 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
950 echo generate_select_list("form_$field_id", $list_id, $reslist,
951 $description, ($showEmpty ? $empty_title : ''), '', $onchange, '',
952 ($disabled ? array('disabled' => 'disabled') : null));
953 echo "</td>";
954 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
956 // current
957 echo "<td class='text' ><input type='radio'" .
958 " name='radio_{$field_id_esc}'" .
959 " id='radio_{$field_id_esc}[current]'" .
960 " value='current" . $field_id_esc . "' $lbfonchange";
961 if ($restype == "current" . $field_id) echo " checked";
962 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
963 echo " />" . xlt('Current') . "&nbsp;</td>";
964 // quit
965 echo "<td class='text'><input type='radio'" .
966 " name='radio_{$field_id_esc}'" .
967 " id='radio_{$field_id_esc}[quit]'" .
968 " value='quit".$field_id_esc."' $lbfonchange";
969 if ($restype == "quit" . $field_id) echo " checked";
970 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
971 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
972 // quit date
973 echo "<td class='text'><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
974 " value='$resdate'" .
975 " title='$description'" .
976 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
977 if (!$disabled) {
978 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
979 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
980 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
981 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
983 echo "&nbsp;</td>";
984 // never
985 echo "<td class='text'><input type='radio'" .
986 " name='radio_{$field_id_esc}'" .
987 " id='radio_{$field_id_esc}[never]'" .
988 " value='never" . $field_id_esc . "' $lbfonchange";
989 if ($restype == "never" . $field_id) echo " checked";
990 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
991 echo " />" . xlt('Never') . "&nbsp;</td>";
992 // Not Applicable
993 echo "<td class='text'><input type='radio'" .
994 " name='radio_{$field_id}'" .
995 " id='radio_{$field_id}[not_applicable]'" .
996 " value='not_applicable" . $field_id . "' $lbfonchange";
997 if ($restype == "not_applicable" . $field_id) echo " checked";
998 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
999 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1001 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1002 echo "<td class='text' ><div id='smoke_code'></div></td>";
1003 echo "</tr>";
1004 echo "</table>";
1007 // static text. read-only, of course.
1008 else if ($data_type == 31) {
1009 echo nl2br($frow['description']);
1012 //$data_type == 33
1013 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1014 //$data_type == 33
1016 else if($data_type == 34){
1017 $arr = explode("|*|*|*|",$currvalue);
1018 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;'>";
1019 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
1020 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1021 echo "</a>";
1024 //facilities drop-down list
1025 else if ($data_type == 35) {
1026 if (empty($currvalue)){
1027 $currvalue = 0;
1029 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1030 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1033 //multiple select
1034 // supports backup list
1035 else if ($data_type == 36) {
1036 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1037 $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);
1042 function generate_print_field($frow, $currvalue) {
1043 global $rootdir, $date_init, $ISSUE_TYPES;
1045 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1047 $data_type = $frow['data_type'];
1048 $field_id = $frow['field_id'];
1049 $list_id = $frow['list_id'];
1050 $fld_length = $frow['fld_length'];
1051 $backup_list = $frow['list_backup_id'];
1053 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1055 // Can pass $frow['empty_title'] with this variable, otherwise
1056 // will default to 'Unassigned'.
1057 // If it is 'SKIP' then an empty text title is completely skipped.
1058 $showEmpty = true;
1059 if (isset($frow['empty_title'])) {
1060 if ($frow['empty_title'] == "SKIP") {
1061 //do not display an 'empty' choice
1062 $showEmpty = false;
1063 $empty_title = "Unassigned";
1065 else {
1066 $empty_title = $frow['empty_title'];
1069 else {
1070 $empty_title = "Unassigned";
1073 // generic single-selection list
1074 // Supports backup lists.
1075 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
1076 if (empty($fld_length)) {
1077 if ($list_id == 'titles') {
1078 $fld_length = 3;
1079 } else {
1080 $fld_length = 10;
1083 $tmp = '';
1084 if ($currvalue) {
1085 $lrow = sqlQuery("SELECT title FROM list_options " .
1086 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
1087 $tmp = xl_list_label($lrow['title']);
1088 if ($lrow == 0 && !empty($backup_list)) {
1089 // since primary list did not map, try to map to backup list
1090 $lrow = sqlQuery("SELECT title FROM list_options " .
1091 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1092 $tmp = xl_list_label($lrow['title']);
1094 if (empty($tmp)) $tmp = "($currvalue)";
1096 /*****************************************************************
1097 echo "<input type='text'" .
1098 " size='$fld_length'" .
1099 " value='$tmp'" .
1100 " class='under'" .
1101 " />";
1102 *****************************************************************/
1103 if ($tmp === '') {
1104 $tmp = '&nbsp;';
1106 else {
1107 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1109 echo $tmp;
1112 // simple text field
1113 else if ($data_type == 2 || $data_type == 15) {
1114 /*****************************************************************
1115 echo "<input type='text'" .
1116 " size='$fld_length'" .
1117 " value='$currescaped'" .
1118 " class='under'" .
1119 " />";
1120 *****************************************************************/
1121 if ($currescaped === '') $currescaped = '&nbsp;';
1122 echo $currescaped;
1125 // long or multi-line text field
1126 else if ($data_type == 3) {
1127 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
1128 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
1129 echo "<textarea" .
1130 " cols='$fldlength'" .
1131 " rows='$maxlength'>" .
1132 $currescaped . "</textarea>";
1135 // date
1136 else if ($data_type == 4) {
1137 $agestr = optionalAge($frow, $currvalue);
1138 if ($agestr) {
1139 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1141 if ($currvalue === '') {
1142 echo '&nbsp;';
1144 else {
1145 echo text(oeFormatShortDate($currvalue));
1147 // Optional display of age or gestational age.
1148 if ($agestr) {
1149 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1153 // provider list
1154 else if ($data_type == 10 || $data_type == 11) {
1155 $tmp = '';
1156 if ($currvalue) {
1157 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1158 "WHERE id = ?", array($currvalue) );
1159 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1160 if (empty($tmp)) $tmp = "($currvalue)";
1162 /*****************************************************************
1163 echo "<input type='text'" .
1164 " size='$fld_length'" .
1165 " value='$tmp'" .
1166 " class='under'" .
1167 " />";
1168 *****************************************************************/
1169 if ($tmp === '') { $tmp = '&nbsp;'; }
1170 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1171 echo $tmp;
1174 // pharmacy list
1175 else if ($data_type == 12) {
1176 $tmp = '';
1177 if ($currvalue) {
1178 $pres = get_pharmacies();
1179 while ($prow = sqlFetchArray($pres)) {
1180 $key = $prow['id'];
1181 if ($currvalue == $key) {
1182 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1183 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1184 $prow['line1'] . ' / ' . $prow['city'];
1187 if (empty($tmp)) $tmp = "($currvalue)";
1189 /*****************************************************************
1190 echo "<input type='text'" .
1191 " size='$fld_length'" .
1192 " value='$tmp'" .
1193 " class='under'" .
1194 " />";
1195 *****************************************************************/
1196 if ($tmp === '') { $tmp = '&nbsp;'; }
1197 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1198 echo $tmp;
1201 // squads
1202 else if ($data_type == 13) {
1203 $tmp = '';
1204 if ($currvalue) {
1205 $squads = acl_get_squads();
1206 if ($squads) {
1207 foreach ($squads as $key => $value) {
1208 if ($currvalue == $key) {
1209 $tmp = $value[3];
1213 if (empty($tmp)) $tmp = "($currvalue)";
1215 /*****************************************************************
1216 echo "<input type='text'" .
1217 " size='$fld_length'" .
1218 " value='$tmp'" .
1219 " class='under'" .
1220 " />";
1221 *****************************************************************/
1222 if ($tmp === '') { $tmp = '&nbsp;'; }
1223 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1224 echo $tmp;
1227 // Address book.
1228 else if ($data_type == 14) {
1229 $tmp = '';
1230 if ($currvalue) {
1231 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1232 "WHERE id = ?", array($currvalue) );
1233 $uname = $urow['lname'];
1234 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1235 $tmp = $uname;
1236 if (empty($tmp)) $tmp = "($currvalue)";
1238 /*****************************************************************
1239 echo "<input type='text'" .
1240 " size='$fld_length'" .
1241 " value='$tmp'" .
1242 " class='under'" .
1243 " />";
1244 *****************************************************************/
1245 if ($tmp === '') { $tmp = '&nbsp;'; }
1246 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1247 echo $tmp;
1250 // insurance company list
1251 else if ($data_type == 16) {
1252 $tmp = '';
1253 if ($currvalue) {
1254 $insprovs = getInsuranceProviders();
1255 foreach ($insprovs as $key => $ipname) {
1256 if ($currvalue == $key) {
1257 $tmp = $ipname;
1260 if (empty($tmp)) $tmp = "($currvalue)";
1262 if ($tmp === '') $tmp = '&nbsp;';
1263 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1264 echo $tmp;
1267 // issue types
1268 else if ($data_type == 17) {
1269 $tmp = '';
1270 if ($currvalue) {
1271 foreach ($ISSUE_TYPES as $key => $value) {
1272 if ($currvalue == $key) {
1273 $tmp = $value[1];
1276 if (empty($tmp)) $tmp = "($currvalue)";
1278 if ($tmp === '') $tmp = '&nbsp;';
1279 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1280 echo $tmp;
1283 // Visit categories.
1284 else if ($data_type == 18) {
1285 $tmp = '';
1286 if ($currvalue) {
1287 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1288 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1289 array($currvalue));
1290 $tmp = xl_appt_category($crow['pc_catname']);
1291 if (empty($tmp)) $tmp = "($currvalue)";
1293 if ($tmp === '') { $tmp = '&nbsp;'; }
1294 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES); }
1295 echo $tmp;
1298 // a set of labeled checkboxes
1299 else if ($data_type == 21) {
1300 // In this special case, fld_length is the number of columns generated.
1301 $cols = max(1, $fld_length);
1302 $avalue = explode('|', $currvalue);
1303 $lres = sqlStatement("SELECT * FROM list_options " .
1304 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1305 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1306 $tdpct = (int) (100 / $cols);
1307 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1308 $option_id = $lrow['option_id'];
1309 if ($count % $cols == 0) {
1310 if ($count) echo "</tr>";
1311 echo "<tr>";
1313 echo "<td width='$tdpct%'>";
1314 echo "<input type='checkbox'";
1315 if (in_array($option_id, $avalue)) echo " checked";
1316 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1317 echo "</td>";
1319 if ($count) {
1320 echo "</tr>";
1321 if ($count > $cols) {
1322 // Add some space after multiple rows of checkboxes.
1323 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1324 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1327 echo "</table>";
1330 // a set of labeled text input fields
1331 else if ($data_type == 22) {
1332 $tmp = explode('|', $currvalue);
1333 $avalue = array();
1334 foreach ($tmp as $value) {
1335 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1336 $avalue[$matches[1]] = $matches[2];
1339 $lres = sqlStatement("SELECT * FROM list_options " .
1340 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1341 echo "<table cellpadding='0' cellspacing='0'>";
1342 while ($lrow = sqlFetchArray($lres)) {
1343 $option_id = $lrow['option_id'];
1344 $fldlength = empty($fld_length) ? 20 : $fld_length;
1345 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1346 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1347 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1348 echo "<td><input type='text'" .
1349 " size='$fldlength'" .
1350 " value='$inputValue'" .
1351 " class='under'" .
1352 " /></td></tr>";
1354 echo "</table>";
1357 // a set of exam results; 3 radio buttons and a text field:
1358 else if ($data_type == 23) {
1359 $tmp = explode('|', $currvalue);
1360 $avalue = array();
1361 foreach ($tmp as $value) {
1362 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1363 $avalue[$matches[1]] = $matches[2];
1366 $fldlength = empty($fld_length) ? 20 : $fld_length;
1367 $lres = sqlStatement("SELECT * FROM list_options " .
1368 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1369 echo "<table cellpadding='0' cellspacing='0'>";
1370 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1371 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1372 "&nbsp;</td><td class='bold'>" .
1373 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1374 "<td class='bold'>" .
1375 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1376 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1377 while ($lrow = sqlFetchArray($lres)) {
1378 $option_id = $lrow['option_id'];
1379 $restype = substr($avalue[$option_id], 0, 1);
1380 $resnote = substr($avalue[$option_id], 2);
1381 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1382 for ($i = 0; $i < 3; ++$i) {
1383 echo "<td><input type='radio'";
1384 if ($restype === "$i") echo " checked";
1385 echo " /></td>";
1387 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1388 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1389 echo "<td><input type='text'" .
1390 " size='$fldlength'" .
1391 " value='$resnote'" .
1392 " class='under' /></td>" .
1393 "</tr>";
1395 echo "</table>";
1398 // the list of active allergies for the current patient
1399 // this is read-only!
1400 else if ($data_type == 24) {
1401 $query = "SELECT title, comments FROM lists WHERE " .
1402 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1403 "ORDER BY begdate";
1404 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1405 $count = 0;
1406 while ($lrow = sqlFetchArray($lres)) {
1407 if ($count++) echo "<br />";
1408 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1409 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1413 // a set of labeled checkboxes, each with a text field:
1414 else if ($data_type == 25) {
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 $fldlength = empty($fld_length) ? 20 : $fld_length;
1423 $lres = sqlStatement("SELECT * FROM list_options " .
1424 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1425 echo "<table cellpadding='0' cellspacing='0'>";
1426 while ($lrow = sqlFetchArray($lres)) {
1427 $option_id = $lrow['option_id'];
1428 $restype = substr($avalue[$option_id], 0, 1);
1429 $resnote = substr($avalue[$option_id], 2);
1430 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1431 echo "<td><input type='checkbox'";
1432 if ($restype) echo " checked";
1433 echo " />&nbsp;</td>";
1434 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1435 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1436 echo "<td><input type='text'" .
1437 " size='$fldlength'" .
1438 " value='$resnote'" .
1439 " class='under'" .
1440 " /></td>" .
1441 "</tr>";
1443 echo "</table>";
1446 // a set of labeled radio buttons
1447 else if ($data_type == 27) {
1448 // In this special case, fld_length is the number of columns generated.
1449 $cols = max(1, $frow['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' width='100%'>";
1453 $tdpct = (int) (100 / $cols);
1454 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1455 $option_id = $lrow['option_id'];
1456 if ($count % $cols == 0) {
1457 if ($count) echo "</tr>";
1458 echo "<tr>";
1460 echo "<td width='$tdpct%'>";
1461 echo "<input type='radio'";
1462 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1463 (strlen($currvalue) > 0 && $option_id == $currvalue))
1465 echo " checked";
1467 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1468 echo "</td>";
1470 if ($count) {
1471 echo "</tr>";
1472 if ($count > $cols) {
1473 // Add some space after multiple rows of radio buttons.
1474 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1475 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1478 echo "</table>";
1481 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1482 else if ($data_type == 28 || $data_type == 32) {
1483 $tmp = explode('|', $currvalue);
1484 switch(count($tmp)) {
1485 case "4": {
1486 $resnote = $tmp[0];
1487 $restype = $tmp[1];
1488 $resdate = $tmp[2];
1489 $reslist = $tmp[3];
1490 } break;
1491 case "3": {
1492 $resnote = $tmp[0];
1493 $restype = $tmp[1];
1494 $resdate = $tmp[2];
1495 } break;
1496 case "2": {
1497 $resnote = $tmp[0];
1498 $restype = $tmp[1];
1499 $resdate = "";
1500 } break;
1501 case "1": {
1502 $resnote = $tmp[0];
1503 $resdate = $restype = "";
1504 } break;
1505 default: {
1506 $restype = $resdate = $resnote = "";
1507 } break;
1509 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1510 echo "<table cellpadding='0' cellspacing='0'>";
1511 echo "<tr>";
1512 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1513 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1514 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1515 if($data_type == 28)
1517 echo "<td><input type='text'" .
1518 " size='$fldlength'" .
1519 " class='under'" .
1520 " value='$resnote' /></td>";
1521 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1522 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1523 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1525 else if($data_type == 32)
1527 echo "<tr><td><input type='text'" .
1528 " size='$fldlength'" .
1529 " class='under'" .
1530 " value='$resnote' /></td></tr>";
1531 $fldlength = 30;
1532 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1533 echo "<td><input type='text'" .
1534 " size='$fldlength'" .
1535 " class='under'" .
1536 " value='$smoking_status_title' /></td>";
1537 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1539 echo "<td><input type='radio'";
1540 if ($restype == "current".$field_id) echo " checked";
1541 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1543 echo "<td><input type='radio'";
1544 if ($restype == "current".$field_id) echo " checked";
1545 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1547 echo "<td><input type='text' size='6'" .
1548 " value='$resdate'" .
1549 " class='under'" .
1550 " /></td>";
1552 echo "<td><input type='radio'";
1553 if ($restype == "current".$field_id) echo " checked";
1554 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1556 echo "<td><input type='radio'";
1557 if ($restype == "not_applicable".$field_id) echo " checked";
1558 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1559 echo "</tr>";
1560 echo "</table>";
1563 // static text. read-only, of course.
1564 else if ($data_type == 31) {
1565 echo nl2br($frow['description']);
1568 else if($data_type == 34){
1569 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;'>";
1570 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1571 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1572 echo "</a>";
1575 //facilities drop-down list
1576 else if ($data_type == 35) {
1577 if (empty($currvalue)){
1578 $currvalue = 0;
1580 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1583 //Multi-select
1584 // Supports backup lists.
1585 else if ($data_type == 36) {
1586 if (empty($fld_length)) {
1587 if ($list_id == 'titles') {
1588 $fld_length = 3;
1589 } else {
1590 $fld_length = 10;
1593 $tmp = '';
1595 $values_array = explode("|", $currvalue);
1597 $i=0;
1598 foreach($values_array as $value) {
1599 if ($value) {
1600 $lrow = sqlQuery("SELECT title FROM list_options " .
1601 "WHERE list_id = ? AND option_id = ?", array($list_id,$value));
1602 $tmp = xl_list_label($lrow['title']);
1603 if ($lrow == 0 && !empty($backup_list)) {
1604 // since primary list did not map, try to map to backup list
1605 $lrow = sqlQuery("SELECT title FROM list_options " .
1606 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1607 $tmp = xl_list_label($lrow['title']);
1609 if (empty($tmp)) $tmp = "($value)";
1612 if ($tmp === '') {
1613 $tmp = '&nbsp;';
1615 else {
1616 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1618 if ($i != 0 && $tmp != '&nbsp;') echo ",";
1619 echo $tmp;
1620 $i++;
1626 function generate_display_field($frow, $currvalue) {
1627 global $ISSUE_TYPES;
1629 $data_type = $frow['data_type'];
1630 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1631 $list_id = $frow['list_id'];
1632 $backup_list = $frow['list_backup_id'];
1634 $s = '';
1636 // generic selection list or the generic selection list with add on the fly
1637 // feature, or radio buttons
1638 // Supports backup lists for datatypes 1,26,33
1639 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1640 $lrow = sqlQuery("SELECT title FROM list_options " .
1641 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1642 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1643 //if there is no matching value in the corresponding lists check backup list
1644 // only supported in data types 1,26,33
1645 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1646 $lrow = sqlQuery("SELECT title FROM list_options " .
1647 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
1648 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1652 // simple text field
1653 else if ($data_type == 2) {
1654 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1657 // long or multi-line text field
1658 else if ($data_type == 3) {
1659 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1662 // date
1663 else if ($data_type == 4) {
1664 $s = '';
1665 $agestr = optionalAge($frow, $currvalue);
1666 if ($agestr) {
1667 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1669 if ($currvalue === '') {
1670 $s .= '&nbsp;';
1672 else {
1673 $s .= text(oeFormatShortDate($currvalue));
1675 // Optional display of age or gestational age.
1676 if ($agestr) {
1677 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1681 // provider
1682 else if ($data_type == 10 || $data_type == 11) {
1683 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1684 "WHERE id = ?", array($currvalue) );
1685 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1688 // pharmacy list
1689 else if ($data_type == 12) {
1690 $pres = get_pharmacies();
1691 while ($prow = sqlFetchArray($pres)) {
1692 $key = $prow['id'];
1693 if ($currvalue == $key) {
1694 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1695 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1696 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1701 // squads
1702 else if ($data_type == 13) {
1703 $squads = acl_get_squads();
1704 if ($squads) {
1705 foreach ($squads as $key => $value) {
1706 if ($currvalue == $key) {
1707 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1713 // address book
1714 else if ($data_type == 14) {
1715 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1716 "WHERE id = ?", array($currvalue));
1717 $uname = $urow['lname'];
1718 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1719 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1722 // billing code
1723 else if ($data_type == 15) {
1724 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1727 // insurance company list
1728 else if ($data_type == 16) {
1729 $insprovs = getInsuranceProviders();
1730 foreach ($insprovs as $key => $ipname) {
1731 if ($currvalue == $key) {
1732 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
1737 // issue types
1738 else if ($data_type == 17) {
1739 foreach ($ISSUE_TYPES as $key => $value) {
1740 if ($currvalue == $key) {
1741 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
1746 // visit category
1747 else if ($data_type == 18) {
1748 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1749 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1750 array($currvalue));
1751 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES);
1754 // a set of labeled checkboxes
1755 else if ($data_type == 21) {
1756 $avalue = explode('|', $currvalue);
1757 $lres = sqlStatement("SELECT * FROM list_options " .
1758 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1759 $count = 0;
1760 while ($lrow = sqlFetchArray($lres)) {
1761 $option_id = $lrow['option_id'];
1762 if (in_array($option_id, $avalue)) {
1763 if ($count++) $s .= "<br />";
1765 // Added 5-09 by BM - Translate label if applicable
1766 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES);
1772 // a set of labeled text input fields
1773 else if ($data_type == 22) {
1774 $tmp = explode('|', $currvalue);
1775 $avalue = array();
1776 foreach ($tmp as $value) {
1777 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1778 $avalue[$matches[1]] = $matches[2];
1781 $lres = sqlStatement("SELECT * FROM list_options " .
1782 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1783 $s .= "<table cellpadding='0' cellspacing='0'>";
1784 while ($lrow = sqlFetchArray($lres)) {
1785 $option_id = $lrow['option_id'];
1786 if (empty($avalue[$option_id])) continue;
1788 // Added 5-09 by BM - Translate label if applicable
1789 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1791 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1793 $s .= "</table>";
1796 // a set of exam results; 3 radio buttons and a text field:
1797 else if ($data_type == 23) {
1798 $tmp = explode('|', $currvalue);
1799 $avalue = array();
1800 foreach ($tmp as $value) {
1801 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1802 $avalue[$matches[1]] = $matches[2];
1805 $lres = sqlStatement("SELECT * FROM list_options " .
1806 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1807 $s .= "<table cellpadding='0' cellspacing='0'>";
1808 while ($lrow = sqlFetchArray($lres)) {
1809 $option_id = $lrow['option_id'];
1810 $restype = substr($avalue[$option_id], 0, 1);
1811 $resnote = substr($avalue[$option_id], 2);
1812 if (empty($restype) && empty($resnote)) continue;
1814 // Added 5-09 by BM - Translate label if applicable
1815 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1817 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1818 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1819 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1820 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1821 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1822 $s .= "</tr>";
1824 $s .= "</table>";
1827 // the list of active allergies for the current patient
1828 else if ($data_type == 24) {
1829 $query = "SELECT title, comments FROM lists WHERE " .
1830 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1831 "ORDER BY begdate";
1832 // echo "<!-- $query -->\n"; // debugging
1833 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1834 $count = 0;
1835 while ($lrow = sqlFetchArray($lres)) {
1836 if ($count++) $s .= "<br />";
1837 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1838 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1842 // a set of labeled checkboxes, each with a text field:
1843 else if ($data_type == 25) {
1844 $tmp = explode('|', $currvalue);
1845 $avalue = array();
1846 foreach ($tmp as $value) {
1847 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1848 $avalue[$matches[1]] = $matches[2];
1851 $lres = sqlStatement("SELECT * FROM list_options " .
1852 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1853 $s .= "<table cellpadding='0' cellspacing='0'>";
1854 while ($lrow = sqlFetchArray($lres)) {
1855 $option_id = $lrow['option_id'];
1856 $restype = substr($avalue[$option_id], 0, 1);
1857 $resnote = substr($avalue[$option_id], 2);
1858 if (empty($restype) && empty($resnote)) continue;
1860 // Added 5-09 by BM - Translate label if applicable
1861 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1863 $restype = $restype ? xl('Yes') : xl('No');
1864 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1865 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1866 $s .= "</tr>";
1868 $s .= "</table>";
1871 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1872 // VicarePlus :: A selection list for smoking status.
1873 else if ($data_type == 28 || $data_type == 32) {
1874 $tmp = explode('|', $currvalue);
1875 switch(count($tmp)) {
1876 case "4": {
1877 $resnote = $tmp[0];
1878 $restype = $tmp[1];
1879 $resdate = $tmp[2];
1880 $reslist = $tmp[3];
1881 } break;
1882 case "3": {
1883 $resnote = $tmp[0];
1884 $restype = $tmp[1];
1885 $resdate = $tmp[2];
1886 } break;
1887 case "2": {
1888 $resnote = $tmp[0];
1889 $restype = $tmp[1];
1890 $resdate = "";
1891 } break;
1892 case "1": {
1893 $resnote = $tmp[0];
1894 $resdate = $restype = "";
1895 } break;
1896 default: {
1897 $restype = $resdate = $resnote = "";
1898 } break;
1900 $s .= "<table cellpadding='0' cellspacing='0'>";
1902 $s .= "<tr>";
1903 $res = "";
1904 if ($restype == "current".$field_id) $res = xl('Current');
1905 if ($restype == "quit".$field_id) $res = xl('Quit');
1906 if ($restype == "never".$field_id) $res = xl('Never');
1907 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1908 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1909 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1910 if ($data_type == 28)
1912 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1914 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1915 else if ($data_type == 32)
1916 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1917 $smoke_codes = getSmokeCodes();
1918 if (!empty($reslist)) {
1919 if($smoke_codes[$reslist]!="")
1920 $code_desc = "( ".$smoke_codes[$reslist]." )";
1922 $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>";}
1924 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1927 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1928 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1929 $s .= "</tr>";
1930 $s .= "</table>";
1933 // static text. read-only, of course.
1934 else if ($data_type == 31) {
1935 $s .= nl2br($frow['description']);
1938 else if($data_type == 34){
1939 $arr = explode("|*|*|*|",$currvalue);
1940 for($i=0;$i<sizeof($arr);$i++){
1941 $s.=$arr[$i];
1945 // facility
1946 else if ($data_type == 35) {
1947 $urow = sqlQuery("SELECT id, name FROM facility ".
1948 "WHERE id = ?", array($currvalue) );
1949 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
1952 // Multi select
1953 // Supports backup lists
1954 else if ($data_type == 36) {
1955 $values_array = explode("|", $currvalue);
1957 $i = 0;
1958 foreach($values_array as $value) {
1959 $lrow = sqlQuery("SELECT title FROM list_options " .
1960 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
1962 if ($lrow == 0 && !empty($backup_list)) {
1963 //use back up list
1964 $lrow = sqlQuery("SELECT title FROM list_options " .
1965 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
1968 if ($i > 0) {
1969 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1970 } else {
1971 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1974 $i++;
1978 return $s;
1981 // Generate plain text versions of selected LBF field types.
1982 // Currently used by interface/patient_file/download_template.php.
1983 // More field types might need to be supported here in the future.
1985 function generate_plaintext_field($frow, $currvalue) {
1986 global $ISSUE_TYPES;
1988 $data_type = $frow['data_type'];
1989 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1990 $list_id = $frow['list_id'];
1991 $backup_list = $frow['backup_list'];
1992 $s = '';
1994 // generic selection list or the generic selection list with add on the fly
1995 // feature, or radio buttons
1996 // Supports backup lists (for datatypes 1,26,33)
1997 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1998 $lrow = sqlQuery("SELECT title FROM list_options " .
1999 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
2000 $s = xl_list_label($lrow['title']);
2001 //if there is no matching value in the corresponding lists check backup list
2002 // only supported in data types 1,26,33
2003 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2004 $lrow = sqlQuery("SELECT title FROM list_options " .
2005 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
2006 $s = xl_list_label($lrow['title']);
2010 // simple or long text field
2011 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2012 $s = $currvalue;
2015 // date
2016 else if ($data_type == 4) {
2017 $s = oeFormatShortDate($currvalue);
2018 // Optional display of age or gestational age.
2019 $tmp = optionalAge($frow, $currvalue);
2020 if ($tmp) $s .= ' ' . $tmp;
2023 // provider
2024 else if ($data_type == 10 || $data_type == 11) {
2025 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2026 "WHERE id = ?", array($currvalue) );
2027 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2030 // pharmacy list
2031 else if ($data_type == 12) {
2032 $pres = get_pharmacies();
2033 while ($prow = sqlFetchArray($pres)) {
2034 $key = $prow['id'];
2035 if ($currvalue == $key) {
2036 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2037 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2038 $prow['line1'] . ' / ' . $prow['city'];
2043 // address book
2044 else if ($data_type == 14) {
2045 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2046 "WHERE id = ?", array($currvalue));
2047 $uname = $urow['lname'];
2048 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2049 $s = $uname;
2052 // insurance company list
2053 else if ($data_type == 16) {
2054 $insprovs = getInsuranceProviders();
2055 foreach ($insprovs as $key => $ipname) {
2056 if ($currvalue == $key) {
2057 $s .= $ipname;
2062 // issue type
2063 else if ($data_type == 17) {
2064 foreach ($ISSUE_TYPES as $key => $value) {
2065 if ($currvalue == $key) {
2066 $s .= $value[1];
2071 // visit category
2072 else if ($data_type == 18) {
2073 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2074 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2075 array($currvalue));
2076 $s = $crow['pc_catname'];
2079 // a set of labeled checkboxes
2080 else if ($data_type == 21) {
2081 $avalue = explode('|', $currvalue);
2082 $lres = sqlStatement("SELECT * FROM list_options " .
2083 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2084 $count = 0;
2085 while ($lrow = sqlFetchArray($lres)) {
2086 $option_id = $lrow['option_id'];
2087 if (in_array($option_id, $avalue)) {
2088 if ($count++) $s .= "; ";
2089 $s .= xl_list_label($lrow['title']);
2094 // a set of labeled text input fields
2095 else if ($data_type == 22) {
2096 $tmp = explode('|', $currvalue);
2097 $avalue = array();
2098 foreach ($tmp as $value) {
2099 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2100 $avalue[$matches[1]] = $matches[2];
2103 $lres = sqlStatement("SELECT * FROM list_options " .
2104 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2105 while ($lrow = sqlFetchArray($lres)) {
2106 $option_id = $lrow['option_id'];
2107 if (empty($avalue[$option_id])) continue;
2108 if ($s !== '') $s .= '; ';
2109 $s .= xl_list_label($lrow['title']) . ': ';
2110 $s .= $avalue[$option_id];
2114 // A set of exam results; 3 radio buttons and a text field.
2115 // This shows abnormal results only.
2116 else if ($data_type == 23) {
2117 $tmp = explode('|', $currvalue);
2118 $avalue = array();
2119 foreach ($tmp as $value) {
2120 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2121 $avalue[$matches[1]] = $matches[2];
2124 $lres = sqlStatement("SELECT * FROM list_options " .
2125 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2126 while ($lrow = sqlFetchArray($lres)) {
2127 $option_id = $lrow['option_id'];
2128 $restype = substr($avalue[$option_id], 0, 1);
2129 $resnote = substr($avalue[$option_id], 2);
2130 if (empty($restype) && empty($resnote)) continue;
2131 if ($restype != '2') continue; // show abnormal results only
2132 if ($s !== '') $s .= '; ';
2133 $s .= xl_list_label($lrow['title']);
2134 if (!empty($resnote)) $s .= ': ' . $resnote;
2138 // the list of active allergies for the current patient
2139 else if ($data_type == 24) {
2140 $query = "SELECT title, comments FROM lists WHERE " .
2141 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2142 "ORDER BY begdate";
2143 $lres = sqlStatement($query, array($GLOBALS['pid']));
2144 $count = 0;
2145 while ($lrow = sqlFetchArray($lres)) {
2146 if ($count++) $s .= "; ";
2147 $s .= $lrow['title'];
2148 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2152 // a set of labeled checkboxes, each with a text field:
2153 else if ($data_type == 25) {
2154 $tmp = explode('|', $currvalue);
2155 $avalue = array();
2156 foreach ($tmp as $value) {
2157 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2158 $avalue[$matches[1]] = $matches[2];
2161 $lres = sqlStatement("SELECT * FROM list_options " .
2162 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2163 while ($lrow = sqlFetchArray($lres)) {
2164 $option_id = $lrow['option_id'];
2165 $restype = substr($avalue[$option_id], 0, 1);
2166 $resnote = substr($avalue[$option_id], 2);
2167 if (empty($restype) && empty($resnote)) continue;
2168 if ($s !== '') $s .= '; ';
2169 $s .= xl_list_label($lrow['title']);
2170 $restype = $restype ? xl('Yes') : xl('No');
2171 $s .= $restype;
2172 if ($resnote) $s .= ' ' . $resnote;
2176 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2177 // VicarePlus :: A selection list for smoking status.
2178 else if ($data_type == 28 || $data_type == 32) {
2179 $tmp = explode('|', $currvalue);
2180 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2181 $restype = count($tmp) > 1 ? $tmp[1] : '';
2182 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2183 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2184 $res = "";
2185 if ($restype == "current" . $field_id) $res = xl('Current');
2186 if ($restype == "quit" . $field_id) $res = xl('Quit');
2187 if ($restype == "never" . $field_id) $res = xl('Never');
2188 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2190 if ($data_type == 28) {
2191 if (!empty($resnote)) $s .= $resnote;
2193 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2194 else if ($data_type == 32) {
2195 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2196 if (!empty($resnote)) $s .= ' ' . $resnote;
2198 if (!empty($res)) {
2199 if ($s !== '') $s .= ' ';
2200 $s .= xl('Status') . ' ' . $res;
2202 if ($restype == "quit".$field_id) {
2203 if ($s !== '') $s .= ' ';
2204 $s .= $resdate;
2208 // Multi select
2209 // Supports backup lists
2210 else if ($data_type == 36) {
2211 $values_array = explode("|", $currvalue);
2213 $i = 0;
2214 foreach($values_array as $value) {
2215 $lrow = sqlQuery("SELECT title FROM list_options " .
2216 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
2218 if ($lrow == 0 && !empty($backup_list)) {
2219 //use back up list
2220 $lrow = sqlQuery("SELECT title FROM list_options " .
2221 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
2224 if ($i > 0) {
2225 $s = $s . ", " . xl_list_label($lrow['title']);
2226 } else {
2227 $s = xl_list_label($lrow['title']);
2230 $i++;
2234 return $s;
2237 $CPR = 4; // cells per row of generic data
2238 $last_group = '';
2239 $cell_count = 0;
2240 $item_count = 0;
2242 function disp_end_cell() {
2243 global $item_count, $cell_count;
2244 if ($item_count > 0) {
2245 echo "</td>";
2246 $item_count = 0;
2250 function disp_end_row() {
2251 global $cell_count, $CPR;
2252 disp_end_cell();
2253 if ($cell_count > 0) {
2254 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
2255 echo "</tr>\n";
2256 $cell_count = 0;
2260 function disp_end_group() {
2261 global $last_group;
2262 if (strlen($last_group) > 0) {
2263 disp_end_row();
2267 function display_layout_rows($formtype, $result1, $result2='') {
2268 global $item_count, $cell_count, $last_group, $CPR;
2270 $fres = sqlStatement("SELECT * FROM layout_options " .
2271 "WHERE form_id = ? AND uor > 0 " .
2272 "ORDER BY group_name, seq", array($formtype) );
2274 while ($frow = sqlFetchArray($fres)) {
2275 $this_group = $frow['group_name'];
2276 $titlecols = $frow['titlecols'];
2277 $datacols = $frow['datacols'];
2278 $data_type = $frow['data_type'];
2279 $field_id = $frow['field_id'];
2280 $list_id = $frow['list_id'];
2281 $currvalue = '';
2283 if ($formtype == 'DEM') {
2284 if ($GLOBALS['athletic_team']) {
2285 // Skip fitness level and return-to-play date because those appear
2286 // in a special display/update form on this page.
2287 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2289 if (strpos($field_id, 'em_') === 0) {
2290 // Skip employer related fields, if it's disabled.
2291 if ($GLOBALS['omit_employers']) continue;
2292 $tmp = substr($field_id, 3);
2293 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2295 else {
2296 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2299 else {
2300 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2303 // Handle a data category (group) change.
2304 if (strcmp($this_group, $last_group) != 0) {
2305 $group_name = substr($this_group, 1);
2306 // totally skip generating the employer category, if it's disabled.
2307 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2308 disp_end_group();
2309 $last_group = $this_group;
2312 // filter out all the empty field data from the patient report.
2313 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2314 // Handle starting of a new row.
2315 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2316 disp_end_row();
2317 echo "<tr>";
2318 if ($group_name) {
2319 echo "<td class='groupname'>";
2320 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2321 //echo "<font color='#008800'>$group_name</font>";
2323 // Added 5-09 by BM - Translate label if applicable
2324 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
2326 $group_name = '';
2327 } else {
2328 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2329 echo "<td valign='top'>&nbsp;";
2331 echo "</td>";
2334 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2336 // Handle starting of a new label cell.
2337 if ($titlecols > 0) {
2338 disp_end_cell();
2339 //echo "<td class='label' colspan='$titlecols' valign='top'";
2340 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2341 echo "<td class='label' colspan='$titlecols_esc' ";
2342 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2343 echo ">";
2344 $cell_count += $titlecols;
2346 ++$item_count;
2348 // Added 5-09 by BM - Translate label if applicable
2349 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2351 // Handle starting of a new data cell.
2352 if ($datacols > 0) {
2353 disp_end_cell();
2354 //echo "<td class='text data' colspan='$datacols' valign='top'";
2355 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2356 echo "<td class='text data' colspan='$datacols_esc'";
2357 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2358 echo ">";
2359 $cell_count += $datacols;
2362 ++$item_count;
2363 echo generate_display_field($frow, $currvalue);
2367 disp_end_group();
2370 function display_layout_tabs($formtype, $result1, $result2='') {
2371 global $item_count, $cell_count, $last_group, $CPR;
2373 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2374 "WHERE form_id = ? AND uor > 0 " .
2375 "ORDER BY group_name, seq", array($formtype) );
2377 $first = true;
2378 while ($frow = sqlFetchArray($fres)) {
2379 $this_group = $frow['group_name'];
2380 $group_name = substr($this_group, 1);
2381 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2383 <li <?php echo $first ? 'class="current"' : '' ?>>
2384 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
2385 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
2386 </li>
2387 <?php
2388 $first = false;
2392 function display_layout_tabs_data($formtype, $result1, $result2='') {
2393 global $item_count, $cell_count, $last_group, $CPR;
2395 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2396 "WHERE form_id = ? AND uor > 0 " .
2397 "ORDER BY group_name, seq", array($formtype));
2399 $first = true;
2400 while ($frow = sqlFetchArray($fres)) {
2401 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
2402 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
2403 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
2404 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
2405 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
2406 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
2407 $currvalue = '';
2409 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2411 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2412 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2413 "ORDER BY seq", array($formtype, $this_group) );
2416 <div class="tab <?php echo $first ? 'current' : '' ?>">
2417 <table border='0' cellpadding='0'>
2419 <?php
2420 while ($group_fields = sqlFetchArray($group_fields_query)) {
2422 $titlecols = $group_fields['titlecols'];
2423 $datacols = $group_fields['datacols'];
2424 $data_type = $group_fields['data_type'];
2425 $field_id = $group_fields['field_id'];
2426 $list_id = $group_fields['list_id'];
2427 $currvalue = '';
2429 if ($formtype == 'DEM') {
2430 if ($GLOBALS['athletic_team']) {
2431 // Skip fitness level and return-to-play date because those appear
2432 // in a special display/update form on this page.
2433 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2435 if (strpos($field_id, 'em_') === 0) {
2436 // Skip employer related fields, if it's disabled.
2437 if ($GLOBALS['omit_employers']) continue;
2438 $tmp = substr($field_id, 3);
2439 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2441 else {
2442 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2445 else {
2446 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2449 // Handle a data category (group) change.
2450 if (strcmp($this_group, $last_group) != 0) {
2451 $group_name = substr($this_group, 1);
2452 // totally skip generating the employer category, if it's disabled.
2453 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2454 $last_group = $this_group;
2457 // Handle starting of a new row.
2458 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2459 disp_end_row();
2460 echo "<tr>";
2463 if ($item_count == 0 && $titlecols == 0) {
2464 $titlecols = 1;
2467 // Handle starting of a new label cell.
2468 if ($titlecols > 0) {
2469 disp_end_cell();
2470 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2471 echo "<td class='label' colspan='$titlecols_esc' ";
2472 echo ">";
2473 $cell_count += $titlecols;
2475 ++$item_count;
2477 // Added 5-09 by BM - Translate label if applicable
2478 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2480 // Handle starting of a new data cell.
2481 if ($datacols > 0) {
2482 disp_end_cell();
2483 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2484 echo "<td class='text data' colspan='$datacols_esc'";
2485 echo ">";
2486 $cell_count += $datacols;
2489 ++$item_count;
2490 echo generate_display_field($group_fields, $currvalue);
2493 disp_end_row();
2496 </table>
2497 </div>
2499 <?php
2501 $first = false;
2507 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2508 global $item_count, $cell_count, $last_group, $CPR;
2510 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2511 "WHERE form_id = ? AND uor > 0 " .
2512 "ORDER BY group_name, seq", array($formtype) );
2514 $first = true;
2515 while ($frow = sqlFetchArray($fres)) {
2516 $this_group = $frow['group_name'];
2517 $group_name = substr($this_group, 1);
2518 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
2519 $titlecols = $frow['titlecols'];
2520 $datacols = $frow['datacols'];
2521 $data_type = $frow['data_type'];
2522 $field_id = $frow['field_id'];
2523 $list_id = $frow['list_id'];
2524 $currvalue = '';
2526 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2528 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2529 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2530 "ORDER BY seq", array($formtype,$this_group) );
2533 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
2534 <table border='0' cellpadding='0'>
2536 <?php
2537 while ($group_fields = sqlFetchArray($group_fields_query)) {
2539 $titlecols = $group_fields['titlecols'];
2540 $datacols = $group_fields['datacols'];
2541 $data_type = $group_fields['data_type'];
2542 $field_id = $group_fields['field_id'];
2543 $list_id = $group_fields['list_id'];
2544 $backup_list = $group_fields['list_backup_id'];
2545 $currvalue = '';
2547 if ($formtype == 'DEM') {
2548 if ($GLOBALS['athletic_team']) {
2549 // Skip fitness level and return-to-play date because those appear
2550 // in a special display/update form on this page.
2551 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2553 if (strpos($field_id, 'em_') === 0) {
2554 // Skip employer related fields, if it's disabled.
2555 if ($GLOBALS['omit_employers']) continue;
2556 $tmp = substr($field_id, 3);
2557 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2559 else {
2560 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2563 else {
2564 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2567 // Handle a data category (group) change.
2568 if (strcmp($this_group, $last_group) != 0) {
2569 $group_name = substr($this_group, 1);
2570 // totally skip generating the employer category, if it's disabled.
2571 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2572 $last_group = $this_group;
2575 // Handle starting of a new row.
2576 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2577 disp_end_row();
2578 echo "<tr>";
2581 if ($item_count == 0 && $titlecols == 0) {
2582 $titlecols = 1;
2585 // Handle starting of a new label cell.
2586 if ($titlecols > 0) {
2587 disp_end_cell();
2588 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2589 echo "<td class='label' colspan='$titlecols_esc' ";
2590 echo ">";
2591 $cell_count += $titlecols;
2593 ++$item_count;
2595 // Added 5-09 by BM - Translate label if applicable
2596 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
2598 // Handle starting of a new data cell.
2599 if ($datacols > 0) {
2600 disp_end_cell();
2601 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2602 echo "<td class='text data' colspan='$datacols_esc'";
2603 echo ">";
2604 $cell_count += $datacols;
2607 ++$item_count;
2609 echo generate_form_field($group_fields, $currvalue);
2613 </table>
2614 </div>
2616 <?php
2618 $first = false;
2623 // From the currently posted HTML form, this gets the value of the
2624 // field corresponding to the provided layout_options table row.
2626 function get_layout_form_value($frow, $prefix='form_') {
2627 // Bring in $sanitize_all_escapes variable, which will decide
2628 // the variable escaping method.
2629 global $sanitize_all_escapes;
2631 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
2632 $data_type = $frow['data_type'];
2633 $field_id = $frow['field_id'];
2634 $value = '';
2635 if (isset($_POST["$prefix$field_id"])) {
2636 if ($data_type == 21) {
2637 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2638 // must be concatenated into a |-separated string.
2639 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2640 if (strlen($value)) $value .= '|';
2641 $value .= $key;
2644 else if ($data_type == 22) {
2645 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2646 // into "key:value|key:value|...".
2647 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2648 $val = str_replace('|', ' ', $val);
2649 if (strlen($value)) $value .= '|';
2650 $value .= "$key:$val";
2653 else if ($data_type == 23) {
2654 // $_POST["$prefix$field_id"] is an array of text fields with companion
2655 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2656 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2657 $restype = $_POST["radio_{$field_id}"][$key];
2658 if (empty($restype)) $restype = '0';
2659 $val = str_replace('|', ' ', $val);
2660 if (strlen($value)) $value .= '|';
2661 $value .= "$key:$restype:$val";
2664 else if ($data_type == 25) {
2665 // $_POST["$prefix$field_id"] is an array of text fields with companion
2666 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2667 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2668 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
2669 $val = str_replace('|', ' ', $val);
2670 if (strlen($value)) $value .= '|';
2671 $value .= "$key:$restype:$val";
2674 else if ($data_type == 28 || $data_type == 32) {
2675 // $_POST["$prefix$field_id"] is an date text fields with companion
2676 // radio buttons to be imploded into "notes|type|date".
2677 $restype = $_POST["radio_{$field_id}"];
2678 if (empty($restype)) $restype = '0';
2679 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2680 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2681 if ($data_type == 32)
2683 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2684 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2685 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2686 $value = "$res_text_note|$restype|$resdate|$reslist";
2688 else
2689 $value = "$resnote|$restype|$resdate";
2691 else if ($data_type == 36) {
2692 $value_array = $_POST["form_$field_id"];
2693 $i = 0;
2694 foreach ($value_array as $key => $valueofkey) {
2695 if ($i == 0) {
2696 $value = $valueofkey;
2697 } else {
2698 $value = $value . "|" . $valueofkey;
2700 $i++;
2703 else {
2704 $value = $_POST["$prefix$field_id"];
2708 // Better to die than to silently truncate data!
2709 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2710 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2711 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2713 // Make sure the return value is quote-safe.
2714 if ($sanitize_all_escapes) {
2715 //escapes already removed and using binding/placemarks in sql calls
2716 // so only need to trim value
2717 return trim($value);
2719 else {
2720 //need to explicitly prepare value
2721 return formTrim($value);
2725 // Generate JavaScript validation logic for the required fields.
2727 function generate_layout_validation($form_id) {
2728 $fres = sqlStatement("SELECT * FROM layout_options " .
2729 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2730 "ORDER BY group_name, seq", array($form_id) );
2732 while ($frow = sqlFetchArray($fres)) {
2733 if ($frow['uor'] < 2) continue;
2734 $data_type = $frow['data_type'];
2735 $field_id = $frow['field_id'];
2736 $fldtitle = $frow['title'];
2737 if (!$fldtitle) $fldtitle = $frow['description'];
2738 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
2739 switch($data_type) {
2740 case 1:
2741 case 11:
2742 case 12:
2743 case 13:
2744 case 14:
2745 case 26:
2746 case 33:
2747 case 36:
2748 echo
2749 " if (f.$fldname.selectedIndex <= 0) {\n" .
2750 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2751 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2752 " }\n";
2753 break;
2754 case 27: // radio buttons
2755 echo
2756 " var i = 0;\n" .
2757 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2758 " if (i >= f.$fldname.length) {\n" .
2759 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2760 " }\n";
2761 break;
2762 case 2:
2763 case 3:
2764 case 4:
2765 case 15:
2766 echo
2767 " if (trimlen(f.$fldname.value) == 0) {\n" .
2768 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2769 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2770 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2771 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2772 " } else { " .
2773 " $('#" . $fldname . "').attr('style',''); " .
2774 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2775 " } \n";
2776 break;
2782 * DROPDOWN FOR FACILITIES
2784 * build a dropdown with all facilities
2786 * @param string $selected - name of the currently selected facility
2787 * use '0' for "unspecified facility"
2788 * use '' for "All facilities" (the default)
2789 * @param string $name - the name/id for select form (defaults to "form_facility")
2790 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2791 * defaults to true
2792 * @return void - just echo the html encoded string
2794 * Note: This should become a data-type at some point, according to Brady
2796 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2797 $allow_allfacilities = true, $disabled='', $onchange='')
2799 $have_selected = false;
2800 $query = "SELECT id, name FROM facility ORDER BY name";
2801 $fres = sqlStatement($query);
2803 $name = htmlspecialchars($name, ENT_QUOTES);
2804 echo " <select name='$name' id='$name'";
2805 if ($onchange) echo " onchange='$onchange'";
2806 echo " $disabled>\n";
2808 if ($allow_allfacilities) {
2809 $option_value = '';
2810 $option_selected_attr = '';
2811 if ($selected == '') {
2812 $option_selected_attr = ' selected="selected"';
2813 $have_selected = true;
2815 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2816 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2817 } elseif ($allow_unspecified) {
2818 $option_value = '0';
2819 $option_selected_attr = '';
2820 if ( $selected == '0' ) {
2821 $option_selected_attr = ' selected="selected"';
2822 $have_selected = true;
2824 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2825 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2828 while ($frow = sqlFetchArray($fres)) {
2829 $facility_id = $frow['id'];
2830 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2831 $option_selected_attr = '';
2832 if ($selected == $facility_id) {
2833 $option_selected_attr = ' selected="selected"';
2834 $have_selected = true;
2836 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2837 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2840 if ($allow_unspecified && $allow_allfacilities) {
2841 $option_value = '0';
2842 $option_selected_attr = '';
2843 if ( $selected == '0' ) {
2844 $option_selected_attr = ' selected="selected"';
2845 $have_selected = true;
2847 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2848 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2851 if (!$have_selected) {
2852 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2853 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2854 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2855 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2857 echo " </select>\n";
2860 // Expand Collapse Widget
2861 // This forms the header and functionality component of the widget. The information that is displayed
2862 // then follows this function followed by a closing div tag
2864 // $title is the title of the section (already translated)
2865 // $label is identifier used in the tag id's and sql columns
2866 // $buttonLabel is the button label text (already translated)
2867 // $buttonLink is the button link information
2868 // $buttonClass is any additional needed class elements for the button tag
2869 // $linkMethod is the button link method ('javascript' vs 'html')
2870 // $bodyClass is to set class(es) of the body
2871 // $auth is a flag to decide whether to show the button
2872 // $fixedWidth is to flag whether width is fixed
2873 // $forceExpandAlways is a flag to force the widget to always be expanded
2875 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2876 if ($fixedWidth) {
2877 echo "<div class='section-header'>";
2879 else {
2880 echo "<div class='section-header-dynamic'>";
2882 echo "<table><tr>";
2883 if ($auth) {
2884 // show button, since authorized
2885 // first prepare class string
2886 if ($buttonClass) {
2887 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2889 else {
2890 $class_string = "css_button_small";
2892 // next, create the link
2893 if ($linkMethod == "javascript") {
2894 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2896 else {
2897 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2898 if (!isset($_SESSION['patient_portal_onsite'])) {
2899 // prevent an error from occuring when calling the function from the patient portal
2900 echo " onclick='top.restoreSession()'";
2903 if (!$GLOBALS['concurrent_layout']) {
2904 echo " target='Main'";
2906 echo "><span>" .
2907 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2909 if ($forceExpandAlways){
2910 // Special case to force the widget to always be expanded
2911 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2912 $indicatorTag ="style='display:none'";
2914 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
2915 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2916 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
2917 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2919 if (isset($_SESSION['patient_portal_onsite'])) {
2920 // collapse all entries in the patient portal
2921 $text = xl('expand');
2923 else if (getUserSetting($label."_ps_expand")) {
2924 $text = xl('collapse');
2926 else {
2927 $text = xl('expand');
2929 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
2930 "</span>)</a></td>";
2931 echo "</tr></table>";
2932 echo "</div>";
2933 if ($forceExpandAlways) {
2934 // Special case to force the widget to always be expanded
2935 $styling = "";
2937 else if (isset($_SESSION['patient_portal_onsite'])) {
2938 // collapse all entries in the patient portal
2939 $styling = "style='display:none'";
2941 else if (getUserSetting($label."_ps_expand")) {
2942 $styling = "";
2944 else {
2945 $styling = "style='display:none'";
2947 if ($bodyClass) {
2948 $styling .= " class='" . $bodyClass . "'";
2950 //next, create the first div tag to hold the information
2951 // note the code that calls this function will then place the ending div tag after the data
2952 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
2955 //billing_facility fuction will give the dropdown list which contain billing faciliies.
2956 function billing_facility($name,$select){
2957 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
2958 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
2959 while ($facrow = sqlFetchArray($qsql)) {
2960 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
2961 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
2963 echo "</select>";
2966 // Generic function to get the translated title value for a particular list option.
2968 function getListItemTitle($list, $option) {
2969 $row = sqlQuery("SELECT title FROM list_options WHERE " .
2970 "list_id = ? AND option_id = ?", array($list, $option));
2971 if (empty($row['title'])) return $option;
2972 return xl_list_label($row['title']);
2974 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
2975 function getSmokeCodes()
2977 $smoking_codes_arr = array();
2978 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status'");
2979 while($codes_row = sqlFetchArray($smoking_codes))
2981 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
2983 return $smoking_codes_arr;
2986 // Get the current value for a layout based form field.
2987 // Depending on options this might come from lbf_data, patient_data,
2988 // form_encounter, shared_attributes or elsewhere.
2989 // Returns FALSE if the field ID is invalid (layout error).
2991 function lbf_current_value($frow, $formid, $encounter) {
2992 global $pid;
2993 $formname = $frow['form_id'];
2994 $field_id = $frow['field_id'];
2995 $source = $frow['source'];
2996 $currvalue = '';
2997 $deffname = $formname . '_default_' . $field_id;
2998 if ($source == 'D' || $source == 'H') {
2999 // Get from patient_data, employer_data or history_data.
3000 if ($source == 'H') {
3001 $table = 'history_data';
3002 $orderby = 'ORDER BY date DESC LIMIT 1';
3004 else if (strpos($field_id, 'em_') === 0) {
3005 $field_id = substr($field_id, 3);
3006 $table = 'employer_data';
3007 $orderby = 'ORDER BY date DESC LIMIT 1';
3009 else {
3010 $table = 'patient_data';
3011 $orderby = '';
3013 // It is an error if the field does not exist, but don't crash.
3014 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3015 if (empty($tmp)) return FALSE;
3016 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3017 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3019 else if ($source == 'E') {
3020 if ($encounter) {
3021 // Get value from shared_attributes of the current encounter.
3022 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3023 "pid = ? AND encounter = ? AND field_id = ?",
3024 array($pid, $encounter, $field_id));
3025 if (isset($sarow)) $currvalue = $sarow['field_value'];
3027 else if ($formid) {
3028 // Get from shared_attributes of the encounter that this form is linked to.
3029 // Note the importance of having an index on forms.form_id.
3030 $sarow = sqlQuery("SELECT sa.field_value " .
3031 "FROM forms AS f, shared_attributes AS sa WHERE " .
3032 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3033 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3034 array($formid, $formname, $field_id));
3035 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3037 else {
3038 // New form and encounter not available, this should not happen.
3041 else if ($source == 'V') {
3042 if ($encounter) {
3043 // Get value from the current encounter's form_encounter.
3044 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3045 "pid = ? AND encounter = ?",
3046 array($pid, $encounter));
3047 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3049 else if ($formid) {
3050 // Get value from the form_encounter that this form is linked to.
3051 $ferow = sqlQuery("SELECT fe.* " .
3052 "FROM forms AS f, form_encounter AS fe WHERE " .
3053 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3054 "fe.pid = f.pid AND fe.encounter = f.encounter",
3055 array($formid, $formname));
3056 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3058 else {
3059 // New form and encounter not available, this should not happen.
3062 else if ($formid) {
3063 // This is a normal form field.
3064 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3065 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3066 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3068 else {
3069 // New form, see if there is a custom default from a plugin.
3070 // This logic does not apply to shared attributes because they do not
3071 // have a "new form" concept.
3072 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3074 return $currvalue;