PHP warning fixes
[openemr.git] / library / options.inc.php
blob6ca7de199212f73c29fed3341101fcc24de6ccc8
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 = ? AND activity=1 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";
145 To show the inactive item in the list if the value is saved to database
147 if (!$got_selected && strlen($currvalue) > 0)
149 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
150 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
151 $lrow_inactive = sqlFetchArray($lres_inactive);
152 if($lrow_inactive['option_id']) {
153 $optionValue = htmlspecialchars( $lrow_inactive['option_id'], ENT_QUOTES);
154 $s .= "<option value='$optionValue' selected>" . htmlspecialchars( xl_list_label($lrow_inactive['title']), ENT_NOQUOTES) . "</option>\n";
155 $got_selected = TRUE;
159 if (!$got_selected && strlen ( $currvalue ) > 0 && !$multiple) {
160 $list_id = $backup_list;
161 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
163 if ($lrow > 0 && !empty($backup_list)) {
164 $selected = text(xl_list_label($lrow ['title']));
165 $s .= "<option value='$currescaped' selected> $selected </option>";
166 $s .= "</select>";
167 } else {
168 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
169 $s .= "</select>";
170 $fontTitle = xlt('Please choose a valid selection from the list.');
171 $fontText = xlt( 'Fix this' );
172 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
175 } else if (!$got_selected && strlen ( $currvalue ) > 0 && $multiple) {
176 //if not found in main list, display all selected values that exist in backup list
177 $list_id = $backup_list;
179 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? ORDER BY seq, title", array($list_id));
181 $got_selected_backup = FALSE;
182 if (!empty($backup_list)) {
183 while ( $lrow_backup = sqlFetchArray ( $lres_backup ) ) {
184 $selectedValues = explode ( "|", $currvalue );
186 $optionValue = attr($lrow ['option_id']);
188 if ($multiple && (strlen ( $currvalue ) == 0 && $lrow_backup ['is_default']) ||
189 (strlen ( $currvalue ) > 0 && in_array ( $lrow_backup ['option_id'], $selectedValues ))) {
190 $s .= "<option value='$optionValue'";
191 $s .= " selected";
192 $optionLabel = text(xl_list_label($lrow_backup ['title']));
193 $s .= ">$optionLabel</option>\n";
194 $got_selected_backup = TRUE;
198 if (!$got_selected_backup) {
199 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
200 $s .= "</select>";
201 $fontTitle = xlt('Please choose a valid selection from the list.');
202 $fontText = xlt( 'Fix this' );
203 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
207 else {
208 $s .= "</select>";
210 return $s;
214 // $frow is a row from the layout_options table.
215 // $currvalue is the current value, if any, of the associated item.
217 function generate_form_field($frow, $currvalue) {
218 global $rootdir, $date_init, $ISSUE_TYPES, $code_types;
220 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
222 $data_type = $frow['data_type'];
223 $field_id = $frow['field_id'];
224 $list_id = $frow['list_id'];
225 $backup_list = $frow['list_backup_id'];
227 // escaped variables to use in html
228 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
229 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
231 // Added 5-09 by BM - Translate description if applicable
232 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
234 // Support edit option T which assigns the (possibly very long) description as
235 // the default value.
236 if (strpos($frow['edit_options'], 'T') !== FALSE) {
237 if (strlen($currescaped) == 0) $currescaped = $description;
238 // Description used in this way is not suitable as a title.
239 $description = '';
242 // added 5-2009 by BM to allow modification of the 'empty' text title field.
243 // Can pass $frow['empty_title'] with this variable, otherwise
244 // will default to 'Unassigned'.
245 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
246 // if make $frow['empty_title'] equal to 'SKIP'
247 $showEmpty = true;
248 if (isset($frow['empty_title'])) {
249 if ($frow['empty_title'] == "SKIP") {
250 //do not display an 'empty' choice
251 $showEmpty = false;
252 $empty_title = "Unassigned";
254 else {
255 $empty_title = $frow['empty_title'];
258 else {
259 $empty_title = "Unassigned";
262 $disabled = strpos($frow['edit_options'], '0') === FALSE ? '' : 'disabled';
264 $lbfchange = (strpos($frow['form_id'], 'LBF') === 0 || strpos($frow['form_id'], 'LBT') === 0) ?
265 "checkSkipConditions();" : "";
266 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
268 // generic single-selection list or Race and Ethnicity.
269 // These data types support backup lists.
270 if ($data_type == 1 || $data_type == 33) {
271 echo generate_select_list("form_$field_id", $list_id, $currvalue,
272 $description, ($showEmpty ? $empty_title : ''), '', $lbfchange, '',
273 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
276 // simple text field
277 else if ($data_type == 2) {
278 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
279 $maxlength = $frow['max_length'];
280 $string_maxlength = "";
281 // if max_length is set to zero, then do not set a maxlength
282 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
283 echo "<input type='text'" .
284 " name='form_$field_id_esc'" .
285 " id='form_$field_id_esc'" .
286 " size='$fldlength'" .
287 " $string_maxlength" .
288 " title='$description'" .
289 " value='$currescaped'";
290 $tmp = $lbfchange;
291 if (strpos($frow['edit_options'], 'C') !== FALSE)
292 $tmp .= "capitalizeMe(this);";
293 else if (strpos($frow['edit_options'], 'U') !== FALSE)
294 $tmp .= "this.value = this.value.toUpperCase();";
295 if ($tmp) echo " onchange='$tmp'";
296 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
297 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
298 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
299 echo " onblur='maskblur(this,\"$tmp\")'";
301 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
302 echo " readonly";
304 if ($disabled) echo ' disabled';
305 echo " />";
308 // long or multi-line text field
309 else if ($data_type == 3) {
310 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
311 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
312 echo "<textarea" .
313 " name='form_$field_id_esc'" .
314 " id='form_$field_id_esc'" .
315 " title='$description'" .
316 " cols='$textCols'" .
317 " rows='$textRows' $lbfonchange $disabled" .
318 ">" . $currescaped . "</textarea>";
321 // date
322 else if ($data_type == 4) {
323 $age_asof_date = ''; // optionalAge() sets this
324 $age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0;
325 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
326 if ($agestr) {
327 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
329 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
330 " value='" . substr($currescaped, 0, 10) . "'";
331 if (!$agestr) echo " title='$description'";
332 echo " $lbfonchange onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
333 if (!$disabled) {
334 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
335 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
336 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
337 $date_init .= " Calendar.setup({" .
338 "inputField:'form_$field_id', " .
339 "ifFormat:'%Y-%m-%d', ";
340 if ($agestr) {
341 $date_init .= "onUpdate: function() {" .
342 "if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format);" .
343 "}, ";
345 $date_init .= "button:'img_$field_id'})\n";
347 // Optional display of age or gestational age.
348 if ($agestr) {
349 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
353 // provider list, local providers only
354 else if ($data_type == 10) {
355 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
356 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
357 "AND authorized = 1 " .
358 "ORDER BY lname, fname");
359 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled>";
360 echo "<option value=''>" . xlt($empty_title) . "</option>";
361 $got_selected = false;
362 while ($urow = sqlFetchArray($ures)) {
363 $uname = text($urow['fname'] . ' ' . $urow['lname']);
364 $optionId = attr($urow['id']);
365 echo "<option value='$optionId'";
366 if ($urow['id'] == $currvalue) {
367 echo " selected";
368 $got_selected = true;
370 echo ">$uname</option>";
372 if (!$got_selected && $currvalue) {
373 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
374 echo "</select>";
375 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
377 else {
378 echo "</select>";
382 // provider list, including address book entries with an NPI number
383 else if ($data_type == 11) {
384 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
385 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
386 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
387 "ORDER BY lname, fname");
388 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
389 echo " $lbfonchange $disabled>";
390 echo "<option value=''>" . xlt('Unassigned') . "</option>";
391 $got_selected = false;
392 while ($urow = sqlFetchArray($ures)) {
393 $uname = text($urow['fname'] . ' ' . $urow['lname']);
394 $optionId = attr($urow['id']);
395 echo "<option value='$optionId'";
396 if ($urow['id'] == $currvalue) {
397 echo " selected";
398 $got_selected = true;
400 echo ">$uname</option>";
402 if (!$got_selected && $currvalue) {
403 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
404 echo "</select>";
405 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
407 else {
408 echo "</select>";
412 // pharmacy list
413 else if ($data_type == 12) {
414 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
415 echo " $lbfonchange $disabled>";
416 echo "<option value='0'></option>";
417 $pres = get_pharmacies();
418 $got_selected = false;
419 while ($prow = sqlFetchArray($pres)) {
420 $key = $prow['id'];
421 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
422 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
423 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
424 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
425 echo "<option value='$optionValue'";
426 if ($currvalue == $key) {
427 echo " selected";
428 $got_selected = true;
430 echo ">$optionLabel</option>";
432 if (!$got_selected && $currvalue) {
433 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
434 echo "</select>";
435 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
437 else {
438 echo "</select>";
442 // squads
443 else if ($data_type == 13) {
444 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
445 echo " $lbfonchange $disabled>";
446 echo "<option value=''>&nbsp;</option>";
447 $squads = acl_get_squads();
448 if ($squads) {
449 foreach ($squads as $key => $value) {
450 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
451 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
452 echo "<option value='$optionValue'";
453 if ($currvalue == $key) echo " selected";
454 echo ">$optionLabel</option>\n";
457 echo "</select>";
460 // Address book, preferring organization name if it exists and is not in
461 // parentheses, and excluding local users who are not providers.
462 // Supports "referred to" practitioners and facilities.
463 // Alternatively the letter L in edit_options means that abook_type
464 // must be "ord_lab", indicating types used with the procedure
465 // lab ordering system.
466 // Alternatively the letter O in edit_options means that abook_type
467 // must begin with "ord_", indicating types used with the procedure
468 // ordering system.
469 // Alternatively the letter V in edit_options means that abook_type
470 // must be "vendor", indicating the Vendor type.
471 // Alternatively the letter R in edit_options means that abook_type
472 // must be "dist", indicating the Distributor type.
473 else if ($data_type == 14) {
474 if (strpos($frow['edit_options'], 'L') !== FALSE)
475 $tmp = "abook_type = 'ord_lab'";
476 else if (strpos($frow['edit_options'], 'O') !== FALSE)
477 $tmp = "abook_type LIKE 'ord\\_%'";
478 else if (strpos($frow['edit_options'], 'V') !== FALSE)
479 $tmp = "abook_type LIKE 'vendor%'";
480 else if (strpos($frow['edit_options'], 'R') !== FALSE)
481 $tmp = "abook_type LIKE 'dist'";
482 else
483 $tmp = "( username = '' OR authorized = 1 )";
484 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
485 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
486 "AND $tmp " .
487 "ORDER BY organization, lname, fname");
488 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
489 echo " $lbfonchange $disabled>";
490 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
491 while ($urow = sqlFetchArray($ures)) {
492 $uname = $urow['organization'];
493 if (empty($uname) || substr($uname, 0, 1) == '(') {
494 $uname = $urow['lname'];
495 if ($urow['fname']) $uname .= ", " . $urow['fname'];
497 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
498 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
499 echo "<option value='$optionValue'";
500 $title = $urow['username'] ? xl('Local') : xl('External');
501 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
502 echo " title='$optionTitle'";
503 if ($urow['id'] == $currvalue) echo " selected";
504 echo ">$optionLabel</option>";
506 echo "</select>";
509 // A billing code. If description matches an existing code type then that type is used.
510 else if ($data_type == 15) {
511 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
512 $maxlength = $frow['max_length'];
513 $string_maxlength = "";
514 // if max_length is set to zero, then do not set a maxlength
515 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
517 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
518 // Option "2" generates a hidden input for the codes, and a matching visible field
519 // displaying their descriptions. First step is computing the description string.
520 $currdescstring = '';
521 if (!empty($currvalue)) {
522 $relcodes = explode(';', $currvalue);
523 foreach ($relcodes as $codestring) {
524 if ($codestring === '') continue;
525 $code_text = lookup_code_descriptions($codestring);
526 if ($currdescstring !== '') $currdescstring .= '; ';
527 if (!empty($code_text)) {
528 $currdescstring .= $code_text;
530 else {
531 $currdescstring .= $codestring;
535 $currdescstring = attr($currdescstring);
537 echo "<input type='text'" .
538 " name='form_$field_id_esc'" .
539 " id='form_related_code'" .
540 " size='$fldlength'" .
541 " value='$currescaped'" .
542 " style='display:none'" .
543 " $lbfonchange readonly $disabled />";
544 // Extra readonly input field for optional display of code description(s).
545 echo "<input type='text'" .
546 " name='form_$field_id_esc" . "__desc'" .
547 " size='$fldlength'" .
548 " title='$description'" .
549 " value='$currdescstring'";
550 if (!$disabled) {
551 echo " onclick='sel_related(this,\"$codetype\")'";
553 echo " readonly $disabled />";
555 else {
556 echo "<input type='text'" .
557 " name='form_$field_id_esc'" .
558 " id='form_related_code'" .
559 " size='$fldlength'" .
560 " $string_maxlength" .
561 " title='$description'" .
562 " value='$currescaped'";
563 if (!$disabled) {
564 echo " onclick='sel_related(this,\"$codetype\")'";
566 echo " $lbfonchange readonly $disabled />";
570 // insurance company list
571 else if ($data_type == 16) {
572 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
573 echo "<option value='0'></option>";
574 $insprovs = getInsuranceProviders();
575 $got_selected = false;
576 foreach ($insprovs as $key => $ipname) {
577 $optionValue = htmlspecialchars($key, ENT_QUOTES);
578 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
579 echo "<option value='$optionValue'";
580 if ($currvalue == $key) {
581 echo " selected";
582 $got_selected = true;
584 echo ">$optionLabel</option>";
586 if (!$got_selected && $currvalue) {
587 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
588 echo "</select>";
589 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
591 else {
592 echo "</select>";
596 // issue types
597 else if ($data_type == 17) {
598 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
599 echo "<option value='0'></option>";
600 $got_selected = false;
601 foreach ($ISSUE_TYPES as $key => $value) {
602 $optionValue = htmlspecialchars($key, ENT_QUOTES);
603 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
604 echo "<option value='$optionValue'";
605 if ($currvalue == $key) {
606 echo " selected";
607 $got_selected = true;
609 echo ">$optionLabel</option>";
611 if (!$got_selected && strlen($currvalue) > 0) {
612 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
613 echo "</select>";
614 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
616 else {
617 echo "</select>";
621 // Visit categories.
622 else if ($data_type == 18) {
623 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
624 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
625 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
626 " $lbfonchange $disabled>";
627 echo "<option value=''>" . xlt($empty_title) . "</option>";
628 $got_selected = false;
629 while ($crow = sqlFetchArray($cres)) {
630 $catid = $crow['pc_catid'];
631 if (($catid < 9 && $catid != 5) || $catid == 11) continue;
632 echo "<option value='" . attr($catid) . "'";
633 if ($catid == $currvalue) {
634 echo " selected";
635 $got_selected = true;
637 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
639 if (!$got_selected && $currvalue) {
640 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
641 echo "</select>";
642 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
644 else {
645 echo "</select>";
649 // a set of labeled checkboxes
650 else if ($data_type == 21) {
651 // In this special case, fld_length is the number of columns generated.
652 $cols = max(1, $frow['fld_length']);
653 $avalue = explode('|', $currvalue);
654 $lres = sqlStatement("SELECT * FROM list_options " .
655 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
656 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
657 $tdpct = (int) (100 / $cols);
658 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
659 $option_id = $lrow['option_id'];
660 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
661 // if ($count) echo "<br />";
662 if ($count % $cols == 0) {
663 if ($count) echo "</tr>";
664 echo "<tr>";
666 echo "<td width='$tdpct%'>";
667 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
668 "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
669 if (in_array($option_id, $avalue)) echo " checked";
671 // Added 5-09 by BM - Translate label if applicable
672 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
674 echo "</td>";
676 if ($count) {
677 echo "</tr>";
678 if ($count > $cols) {
679 // Add some space after multiple rows of checkboxes.
680 $cols = htmlspecialchars( $cols, ENT_QUOTES);
681 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
684 echo "</table>";
687 // a set of labeled text input fields
688 else if ($data_type == 22) {
689 $tmp = explode('|', $currvalue);
690 $avalue = array();
691 foreach ($tmp as $value) {
692 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
693 $avalue[$matches[1]] = $matches[2];
696 $lres = sqlStatement("SELECT * FROM list_options " .
697 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
698 echo "<table cellpadding='0' cellspacing='0'>";
699 while ($lrow = sqlFetchArray($lres)) {
700 $option_id = $lrow['option_id'];
701 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
702 $maxlength = $frow['max_length'];
703 $string_maxlength = "";
704 // if max_length is set to zero, then do not set a maxlength
705 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
706 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
708 // Added 5-09 by BM - Translate label if applicable
709 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
710 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
711 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
712 echo "<td><input type='text'" .
713 " name='form_{$field_id_esc}[$option_id_esc]'" .
714 " id='form_{$field_id_esc}[$option_id_esc]'" .
715 " size='$fldlength'" .
716 " $string_maxlength" .
717 " value='$optionValue'";
718 echo " $lbfonchange $disabled /></td></tr>";
720 echo "</table>";
723 // a set of exam results; 3 radio buttons and a text field:
724 else if ($data_type == 23) {
725 $tmp = explode('|', $currvalue);
726 $avalue = array();
727 foreach ($tmp as $value) {
728 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
729 $avalue[$matches[1]] = $matches[2];
732 $maxlength = $frow['max_length'];
733 $string_maxlength = "";
734 // if max_length is set to zero, then do not set a maxlength
735 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
736 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
737 $lres = sqlStatement("SELECT * FROM list_options " .
738 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
739 echo "<table cellpadding='0' cellspacing='0'>";
740 echo "<tr><td>&nbsp;</td><td class='bold'>" .
741 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
742 "&nbsp;</td><td class='bold'>" .
743 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
744 "<td class='bold'>" .
745 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
746 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
747 while ($lrow = sqlFetchArray($lres)) {
748 $option_id = $lrow['option_id'];
749 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
750 $restype = substr($avalue[$option_id], 0, 1);
751 $resnote = substr($avalue[$option_id], 2);
753 // Added 5-09 by BM - Translate label if applicable
754 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
756 for ($i = 0; $i < 3; ++$i) {
757 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
758 echo "<td><input type='radio'" .
759 " name='radio_{$field_id_esc}[$option_id_esc]'" .
760 " id='radio_{$field_id_esc}[$option_id_esc]'" .
761 " value='$inputValue' $lbfonchange";
762 if ($restype === "$i") echo " checked";
763 echo " $disabled /></td>";
765 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
766 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
767 echo "<td><input type='text'" .
768 " name='form_{$field_id_esc}[$option_id_esc]'" .
769 " id='form_{$field_id_esc}[$option_id_esc]'" .
770 " size='$fldlength'" .
771 " $string_maxlength" .
772 " value='$resnote' $disabled /></td>";
773 echo "</tr>";
775 echo "</table>";
778 // the list of active allergies for the current patient
779 // this is read-only!
780 else if ($data_type == 24) {
781 $query = "SELECT title, comments FROM lists WHERE " .
782 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
783 "ORDER BY begdate";
784 // echo "<!-- $query -->\n"; // debugging
785 $lres = sqlStatement($query, array($GLOBALS['pid']));
786 $count = 0;
787 while ($lrow = sqlFetchArray($lres)) {
788 if ($count++) echo "<br />";
789 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
790 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
794 // a set of labeled checkboxes, each with a text field:
795 else if ($data_type == 25) {
796 $tmp = explode('|', $currvalue);
797 $avalue = array();
798 foreach ($tmp as $value) {
799 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
800 $avalue[$matches[1]] = $matches[2];
803 $maxlength = $frow['max_length'];
804 $string_maxlength = "";
805 // if max_length is set to zero, then do not set a maxlength
806 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
807 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
808 $lres = sqlStatement("SELECT * FROM list_options " .
809 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
810 echo "<table cellpadding='0' cellspacing='0'>";
811 while ($lrow = sqlFetchArray($lres)) {
812 $option_id = $lrow['option_id'];
813 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
814 $restype = substr($avalue[$option_id], 0, 1);
815 $resnote = substr($avalue[$option_id], 2);
817 // Added 5-09 by BM - Translate label if applicable
818 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
820 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
821 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
822 " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
823 if ($restype) echo " checked";
824 echo " $disabled />&nbsp;</td>";
825 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
826 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
827 echo "<td><input type='text'" .
828 " name='form_{$field_id_esc}[$option_id_esc]'" .
829 " id='form_{$field_id_esc}[$option_id_esc]'" .
830 " size='$fldlength'" .
831 " $string_maxlength" .
832 " value='$resnote' $disabled /></td>";
833 echo "</tr>";
835 echo "</table>";
838 // single-selection list with ability to add to it
839 else if ($data_type == 26) {
840 echo generate_select_list("form_$field_id", $list_id, $currvalue,
841 $description, ($showEmpty ? $empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
842 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
843 // show the add button if user has access to correct list
844 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
845 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
846 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
847 if (aco_exist('lists', $list_id)) {
848 // a specific aco exist for this list, so ensure access
849 if (acl_check('lists', $list_id)) echo $outputAddButton;
851 else {
852 // no specific aco exist for this list, so check for access to 'default' list
853 if (acl_check('lists', 'default')) echo $outputAddButton;
857 // a set of labeled radio buttons
858 else if ($data_type == 27) {
859 // In this special case, fld_length is the number of columns generated.
860 $cols = max(1, $frow['fld_length']);
861 $lres = sqlStatement("SELECT * FROM list_options " .
862 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
863 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
864 $tdpct = (int) (100 / $cols);
865 $got_selected = FALSE;
866 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
867 $option_id = $lrow['option_id'];
868 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
869 if ($count % $cols == 0) {
870 if ($count) echo "</tr>";
871 echo "<tr>";
873 echo "<td width='$tdpct%'>";
874 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
875 " value='$option_id_esc' $lbfonchange";
876 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
877 (strlen($currvalue) > 0 && $option_id == $currvalue))
879 echo " checked";
880 $got_selected = TRUE;
882 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
883 echo "</td>";
885 if ($count) {
886 echo "</tr>";
887 if ($count > $cols) {
888 // Add some space after multiple rows of radio buttons.
889 $cols = htmlspecialchars($cols, ENT_QUOTES);
890 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
893 echo "</table>";
894 if (!$got_selected && strlen($currvalue) > 0) {
895 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
896 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
897 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
901 // special case for history of lifestyle status; 3 radio buttons and a date text field:
902 // VicarePlus :: A selection list box for smoking status:
903 else if ($data_type == 28 || $data_type == 32) {
904 $tmp = explode('|', $currvalue);
905 switch(count($tmp)) {
906 case "4": {
907 $resnote = $tmp[0];
908 $restype = $tmp[1];
909 $resdate = $tmp[2];
910 $reslist = $tmp[3];
911 } break;
912 case "3": {
913 $resnote = $tmp[0];
914 $restype = $tmp[1];
915 $resdate = $tmp[2];
916 } break;
917 case "2": {
918 $resnote = $tmp[0];
919 $restype = $tmp[1];
920 $resdate = "";
921 } break;
922 case "1": {
923 $resnote = $tmp[0];
924 $resdate = $restype = "";
925 } break;
926 default: {
927 $restype = $resdate = $resnote = "";
928 } break;
930 $maxlength = $frow['max_length'];
931 $string_maxlength = "";
932 // if max_length is set to zero, then do not set a maxlength
933 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
934 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
936 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
937 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
938 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
939 echo "<table cellpadding='0' cellspacing='0'>";
940 echo "<tr>";
941 if ($data_type == 28)
943 // input text
944 echo "<td><input type='text'" .
945 " name='form_$field_id_esc'" .
946 " id='form_$field_id_esc'" .
947 " size='$fldlength'" .
948 " $string_maxlength" .
949 " value='$resnote' $disabled />&nbsp;</td>";
950 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
951 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
952 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
954 else if($data_type == 32)
956 // input text
957 echo "<tr><td><input type='text'" .
958 " name='form_text_$field_id_esc'" .
959 " id='form_text_$field_id_esc'" .
960 " size='$fldlength'" .
961 " $string_maxlength" .
962 " value='$resnote' $disabled />&nbsp;</td></tr>";
963 echo "<td>";
964 //Selection list for smoking status
965 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
966 echo generate_select_list("form_$field_id", $list_id, $reslist,
967 $description, ($showEmpty ? $empty_title : ''), '', $onchange, '',
968 ($disabled ? array('disabled' => 'disabled') : null));
969 echo "</td>";
970 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
972 // current
973 echo "<td class='text' ><input type='radio'" .
974 " name='radio_{$field_id_esc}'" .
975 " id='radio_{$field_id_esc}[current]'" .
976 " value='current" . $field_id_esc . "' $lbfonchange";
977 if ($restype == "current" . $field_id) echo " checked";
978 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
979 echo " />" . xlt('Current') . "&nbsp;</td>";
980 // quit
981 echo "<td class='text'><input type='radio'" .
982 " name='radio_{$field_id_esc}'" .
983 " id='radio_{$field_id_esc}[quit]'" .
984 " value='quit".$field_id_esc."' $lbfonchange";
985 if ($restype == "quit" . $field_id) echo " checked";
986 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
987 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
988 // quit date
989 echo "<td class='text'><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
990 " value='$resdate'" .
991 " title='$description'" .
992 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
993 if (!$disabled) {
994 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
995 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
996 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
997 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
999 echo "&nbsp;</td>";
1000 // never
1001 echo "<td class='text'><input type='radio'" .
1002 " name='radio_{$field_id_esc}'" .
1003 " id='radio_{$field_id_esc}[never]'" .
1004 " value='never" . $field_id_esc . "' $lbfonchange";
1005 if ($restype == "never" . $field_id) echo " checked";
1006 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1007 echo " />" . xlt('Never') . "&nbsp;</td>";
1008 // Not Applicable
1009 echo "<td class='text'><input type='radio'" .
1010 " name='radio_{$field_id}'" .
1011 " id='radio_{$field_id}[not_applicable]'" .
1012 " value='not_applicable" . $field_id . "' $lbfonchange";
1013 if ($restype == "not_applicable" . $field_id) echo " checked";
1014 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1015 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1017 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1018 echo "<td class='text' ><div id='smoke_code'></div></td>";
1019 echo "</tr>";
1020 echo "</table>";
1023 // static text. read-only, of course.
1024 else if ($data_type == 31) {
1025 echo nl2br($frow['description']);
1028 //$data_type == 33
1029 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1030 //$data_type == 33
1032 else if($data_type == 34){
1033 $arr = explode("|*|*|*|",$currvalue);
1034 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;'>";
1035 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
1036 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1037 echo "</a>";
1040 //facilities drop-down list
1041 else if ($data_type == 35) {
1042 if (empty($currvalue)){
1043 $currvalue = 0;
1045 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1046 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1049 //multiple select
1050 // supports backup list
1051 else if ($data_type == 36) {
1052 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1053 $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);
1058 function generate_print_field($frow, $currvalue) {
1059 global $rootdir, $date_init, $ISSUE_TYPES;
1061 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1063 $data_type = $frow['data_type'];
1064 $field_id = $frow['field_id'];
1065 $list_id = $frow['list_id'];
1066 $fld_length = $frow['fld_length'];
1067 $backup_list = $frow['list_backup_id'];
1069 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1071 // Can pass $frow['empty_title'] with this variable, otherwise
1072 // will default to 'Unassigned'.
1073 // If it is 'SKIP' then an empty text title is completely skipped.
1074 $showEmpty = true;
1075 if (isset($frow['empty_title'])) {
1076 if ($frow['empty_title'] == "SKIP") {
1077 //do not display an 'empty' choice
1078 $showEmpty = false;
1079 $empty_title = "Unassigned";
1081 else {
1082 $empty_title = $frow['empty_title'];
1085 else {
1086 $empty_title = "Unassigned";
1089 // generic single-selection list
1090 // Supports backup lists.
1091 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
1092 if (empty($fld_length)) {
1093 if ($list_id == 'titles') {
1094 $fld_length = 3;
1095 } else {
1096 $fld_length = 10;
1099 $tmp = '';
1100 if ($currvalue) {
1101 $lrow = sqlQuery("SELECT title FROM list_options " .
1102 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
1103 $tmp = xl_list_label($lrow['title']);
1104 if ($lrow == 0 && !empty($backup_list)) {
1105 // since primary list did not map, try to map to backup list
1106 $lrow = sqlQuery("SELECT title FROM list_options " .
1107 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1108 $tmp = xl_list_label($lrow['title']);
1110 if (empty($tmp)) $tmp = "($currvalue)";
1112 /*****************************************************************
1113 echo "<input type='text'" .
1114 " size='$fld_length'" .
1115 " value='$tmp'" .
1116 " class='under'" .
1117 " />";
1118 *****************************************************************/
1119 if ($tmp === '') {
1120 $tmp = '&nbsp;';
1122 else {
1123 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1125 echo $tmp;
1128 // simple text field
1129 else if ($data_type == 2 || $data_type == 15) {
1130 /*****************************************************************
1131 echo "<input type='text'" .
1132 " size='$fld_length'" .
1133 " value='$currescaped'" .
1134 " class='under'" .
1135 " />";
1136 *****************************************************************/
1137 if ($currescaped === '') $currescaped = '&nbsp;';
1138 echo $currescaped;
1141 // long or multi-line text field
1142 else if ($data_type == 3) {
1143 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
1144 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
1145 echo "<textarea" .
1146 " cols='$fldlength'" .
1147 " rows='$maxlength'>" .
1148 $currescaped . "</textarea>";
1151 // date
1152 else if ($data_type == 4) {
1153 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1154 $agestr = optionalAge($frow, $currvalue,$asof);
1155 if ($agestr) {
1156 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1158 if ($currvalue === '') {
1159 echo '&nbsp;';
1161 else {
1162 echo text(oeFormatShortDate($currvalue));
1164 // Optional display of age or gestational age.
1165 if ($agestr) {
1166 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1170 // provider list
1171 else if ($data_type == 10 || $data_type == 11) {
1172 $tmp = '';
1173 if ($currvalue) {
1174 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1175 "WHERE id = ?", array($currvalue) );
1176 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1177 if (empty($tmp)) $tmp = "($currvalue)";
1179 /*****************************************************************
1180 echo "<input type='text'" .
1181 " size='$fld_length'" .
1182 " value='$tmp'" .
1183 " class='under'" .
1184 " />";
1185 *****************************************************************/
1186 if ($tmp === '') { $tmp = '&nbsp;'; }
1187 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1188 echo $tmp;
1191 // pharmacy list
1192 else if ($data_type == 12) {
1193 $tmp = '';
1194 if ($currvalue) {
1195 $pres = get_pharmacies();
1196 while ($prow = sqlFetchArray($pres)) {
1197 $key = $prow['id'];
1198 if ($currvalue == $key) {
1199 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1200 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1201 $prow['line1'] . ' / ' . $prow['city'];
1204 if (empty($tmp)) $tmp = "($currvalue)";
1206 /*****************************************************************
1207 echo "<input type='text'" .
1208 " size='$fld_length'" .
1209 " value='$tmp'" .
1210 " class='under'" .
1211 " />";
1212 *****************************************************************/
1213 if ($tmp === '') { $tmp = '&nbsp;'; }
1214 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1215 echo $tmp;
1218 // squads
1219 else if ($data_type == 13) {
1220 $tmp = '';
1221 if ($currvalue) {
1222 $squads = acl_get_squads();
1223 if ($squads) {
1224 foreach ($squads as $key => $value) {
1225 if ($currvalue == $key) {
1226 $tmp = $value[3];
1230 if (empty($tmp)) $tmp = "($currvalue)";
1232 /*****************************************************************
1233 echo "<input type='text'" .
1234 " size='$fld_length'" .
1235 " value='$tmp'" .
1236 " class='under'" .
1237 " />";
1238 *****************************************************************/
1239 if ($tmp === '') { $tmp = '&nbsp;'; }
1240 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1241 echo $tmp;
1244 // Address book.
1245 else if ($data_type == 14) {
1246 $tmp = '';
1247 if ($currvalue) {
1248 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1249 "WHERE id = ?", array($currvalue) );
1250 $uname = $urow['lname'];
1251 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1252 $tmp = $uname;
1253 if (empty($tmp)) $tmp = "($currvalue)";
1255 /*****************************************************************
1256 echo "<input type='text'" .
1257 " size='$fld_length'" .
1258 " value='$tmp'" .
1259 " class='under'" .
1260 " />";
1261 *****************************************************************/
1262 if ($tmp === '') { $tmp = '&nbsp;'; }
1263 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1264 echo $tmp;
1267 // insurance company list
1268 else if ($data_type == 16) {
1269 $tmp = '';
1270 if ($currvalue) {
1271 $insprovs = getInsuranceProviders();
1272 foreach ($insprovs as $key => $ipname) {
1273 if ($currvalue == $key) {
1274 $tmp = $ipname;
1277 if (empty($tmp)) $tmp = "($currvalue)";
1279 if ($tmp === '') $tmp = '&nbsp;';
1280 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1281 echo $tmp;
1284 // issue types
1285 else if ($data_type == 17) {
1286 $tmp = '';
1287 if ($currvalue) {
1288 foreach ($ISSUE_TYPES as $key => $value) {
1289 if ($currvalue == $key) {
1290 $tmp = $value[1];
1293 if (empty($tmp)) $tmp = "($currvalue)";
1295 if ($tmp === '') $tmp = '&nbsp;';
1296 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1297 echo $tmp;
1300 // Visit categories.
1301 else if ($data_type == 18) {
1302 $tmp = '';
1303 if ($currvalue) {
1304 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1305 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1306 array($currvalue));
1307 $tmp = xl_appt_category($crow['pc_catname']);
1308 if (empty($tmp)) $tmp = "($currvalue)";
1310 if ($tmp === '') { $tmp = '&nbsp;'; }
1311 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES); }
1312 echo $tmp;
1315 // a set of labeled checkboxes
1316 else if ($data_type == 21) {
1317 // In this special case, fld_length is the number of columns generated.
1318 $cols = max(1, $fld_length);
1319 $avalue = explode('|', $currvalue);
1320 $lres = sqlStatement("SELECT * FROM list_options " .
1321 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1322 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1323 $tdpct = (int) (100 / $cols);
1324 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1325 $option_id = $lrow['option_id'];
1326 if ($count % $cols == 0) {
1327 if ($count) echo "</tr>";
1328 echo "<tr>";
1330 echo "<td width='$tdpct%'>";
1331 echo "<input type='checkbox'";
1332 if (in_array($option_id, $avalue)) echo " checked";
1333 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1334 echo "</td>";
1336 if ($count) {
1337 echo "</tr>";
1338 if ($count > $cols) {
1339 // Add some space after multiple rows of checkboxes.
1340 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1341 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1344 echo "</table>";
1347 // a set of labeled text input fields
1348 else if ($data_type == 22) {
1349 $tmp = explode('|', $currvalue);
1350 $avalue = array();
1351 foreach ($tmp as $value) {
1352 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1353 $avalue[$matches[1]] = $matches[2];
1356 $lres = sqlStatement("SELECT * FROM list_options " .
1357 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1358 echo "<table cellpadding='0' cellspacing='0'>";
1359 while ($lrow = sqlFetchArray($lres)) {
1360 $option_id = $lrow['option_id'];
1361 $fldlength = empty($fld_length) ? 20 : $fld_length;
1362 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1363 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1364 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1365 echo "<td><input type='text'" .
1366 " size='$fldlength'" .
1367 " value='$inputValue'" .
1368 " class='under'" .
1369 " /></td></tr>";
1371 echo "</table>";
1374 // a set of exam results; 3 radio buttons and a text field:
1375 else if ($data_type == 23) {
1376 $tmp = explode('|', $currvalue);
1377 $avalue = array();
1378 foreach ($tmp as $value) {
1379 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1380 $avalue[$matches[1]] = $matches[2];
1383 $fldlength = empty($fld_length) ? 20 : $fld_length;
1384 $lres = sqlStatement("SELECT * FROM list_options " .
1385 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1386 echo "<table cellpadding='0' cellspacing='0'>";
1387 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1388 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1389 "&nbsp;</td><td class='bold'>" .
1390 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1391 "<td class='bold'>" .
1392 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1393 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1394 while ($lrow = sqlFetchArray($lres)) {
1395 $option_id = $lrow['option_id'];
1396 $restype = substr($avalue[$option_id], 0, 1);
1397 $resnote = substr($avalue[$option_id], 2);
1398 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1399 for ($i = 0; $i < 3; ++$i) {
1400 echo "<td><input type='radio'";
1401 if ($restype === "$i") echo " checked";
1402 echo " /></td>";
1404 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1405 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1406 echo "<td><input type='text'" .
1407 " size='$fldlength'" .
1408 " value='$resnote'" .
1409 " class='under' /></td>" .
1410 "</tr>";
1412 echo "</table>";
1415 // the list of active allergies for the current patient
1416 // this is read-only!
1417 else if ($data_type == 24) {
1418 $query = "SELECT title, comments FROM lists WHERE " .
1419 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1420 "ORDER BY begdate";
1421 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1422 $count = 0;
1423 while ($lrow = sqlFetchArray($lres)) {
1424 if ($count++) echo "<br />";
1425 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1426 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1430 // a set of labeled checkboxes, each with a text field:
1431 else if ($data_type == 25) {
1432 $tmp = explode('|', $currvalue);
1433 $avalue = array();
1434 foreach ($tmp as $value) {
1435 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1436 $avalue[$matches[1]] = $matches[2];
1439 $fldlength = empty($fld_length) ? 20 : $fld_length;
1440 $lres = sqlStatement("SELECT * FROM list_options " .
1441 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1442 echo "<table cellpadding='0' cellspacing='0'>";
1443 while ($lrow = sqlFetchArray($lres)) {
1444 $option_id = $lrow['option_id'];
1445 $restype = substr($avalue[$option_id], 0, 1);
1446 $resnote = substr($avalue[$option_id], 2);
1447 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1448 echo "<td><input type='checkbox'";
1449 if ($restype) echo " checked";
1450 echo " />&nbsp;</td>";
1451 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1452 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1453 echo "<td><input type='text'" .
1454 " size='$fldlength'" .
1455 " value='$resnote'" .
1456 " class='under'" .
1457 " /></td>" .
1458 "</tr>";
1460 echo "</table>";
1463 // a set of labeled radio buttons
1464 else if ($data_type == 27) {
1465 // In this special case, fld_length is the number of columns generated.
1466 $cols = max(1, $frow['fld_length']);
1467 $lres = sqlStatement("SELECT * FROM list_options " .
1468 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1469 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1470 $tdpct = (int) (100 / $cols);
1471 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1472 $option_id = $lrow['option_id'];
1473 if ($count % $cols == 0) {
1474 if ($count) echo "</tr>";
1475 echo "<tr>";
1477 echo "<td width='$tdpct%'>";
1478 echo "<input type='radio'";
1479 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1480 (strlen($currvalue) > 0 && $option_id == $currvalue))
1482 echo " checked";
1484 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1485 echo "</td>";
1487 if ($count) {
1488 echo "</tr>";
1489 if ($count > $cols) {
1490 // Add some space after multiple rows of radio buttons.
1491 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1492 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1495 echo "</table>";
1498 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1499 else if ($data_type == 28 || $data_type == 32) {
1500 $tmp = explode('|', $currvalue);
1501 switch(count($tmp)) {
1502 case "4": {
1503 $resnote = $tmp[0];
1504 $restype = $tmp[1];
1505 $resdate = $tmp[2];
1506 $reslist = $tmp[3];
1507 } break;
1508 case "3": {
1509 $resnote = $tmp[0];
1510 $restype = $tmp[1];
1511 $resdate = $tmp[2];
1512 } break;
1513 case "2": {
1514 $resnote = $tmp[0];
1515 $restype = $tmp[1];
1516 $resdate = "";
1517 } break;
1518 case "1": {
1519 $resnote = $tmp[0];
1520 $resdate = $restype = "";
1521 } break;
1522 default: {
1523 $restype = $resdate = $resnote = "";
1524 } break;
1526 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1527 echo "<table cellpadding='0' cellspacing='0'>";
1528 echo "<tr>";
1529 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1530 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1531 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1532 if($data_type == 28)
1534 echo "<td><input type='text'" .
1535 " size='$fldlength'" .
1536 " class='under'" .
1537 " value='$resnote' /></td>";
1538 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1539 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1540 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1542 else if($data_type == 32)
1544 echo "<tr><td><input type='text'" .
1545 " size='$fldlength'" .
1546 " class='under'" .
1547 " value='$resnote' /></td></tr>";
1548 $fldlength = 30;
1549 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1550 echo "<td><input type='text'" .
1551 " size='$fldlength'" .
1552 " class='under'" .
1553 " value='$smoking_status_title' /></td>";
1554 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1556 echo "<td><input type='radio'";
1557 if ($restype == "current".$field_id) echo " checked";
1558 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1560 echo "<td><input type='radio'";
1561 if ($restype == "current".$field_id) echo " checked";
1562 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1564 echo "<td><input type='text' size='6'" .
1565 " value='$resdate'" .
1566 " class='under'" .
1567 " /></td>";
1569 echo "<td><input type='radio'";
1570 if ($restype == "current".$field_id) echo " checked";
1571 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1573 echo "<td><input type='radio'";
1574 if ($restype == "not_applicable".$field_id) echo " checked";
1575 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1576 echo "</tr>";
1577 echo "</table>";
1580 // static text. read-only, of course.
1581 else if ($data_type == 31) {
1582 echo nl2br($frow['description']);
1585 else if($data_type == 34){
1586 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;'>";
1587 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1588 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1589 echo "</a>";
1592 //facilities drop-down list
1593 else if ($data_type == 35) {
1594 if (empty($currvalue)){
1595 $currvalue = 0;
1597 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1600 //Multi-select
1601 // Supports backup lists.
1602 else if ($data_type == 36) {
1603 if (empty($fld_length)) {
1604 if ($list_id == 'titles') {
1605 $fld_length = 3;
1606 } else {
1607 $fld_length = 10;
1610 $tmp = '';
1612 $values_array = explode("|", $currvalue);
1614 $i=0;
1615 foreach($values_array as $value) {
1616 if ($value) {
1617 $lrow = sqlQuery("SELECT title FROM list_options " .
1618 "WHERE list_id = ? AND option_id = ?", array($list_id,$value));
1619 $tmp = xl_list_label($lrow['title']);
1620 if ($lrow == 0 && !empty($backup_list)) {
1621 // since primary list did not map, try to map to backup list
1622 $lrow = sqlQuery("SELECT title FROM list_options " .
1623 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1624 $tmp = xl_list_label($lrow['title']);
1626 if (empty($tmp)) $tmp = "($value)";
1629 if ($tmp === '') {
1630 $tmp = '&nbsp;';
1632 else {
1633 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1635 if ($i != 0 && $tmp != '&nbsp;') echo ",";
1636 echo $tmp;
1637 $i++;
1643 function generate_display_field($frow, $currvalue) {
1644 global $ISSUE_TYPES;
1646 $data_type = $frow['data_type'];
1647 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1648 $list_id = $frow['list_id'];
1649 $backup_list = $frow['list_backup_id'];
1651 $s = '';
1653 // generic selection list or the generic selection list with add on the fly
1654 // feature, or radio buttons
1655 // Supports backup lists for datatypes 1,26,33
1656 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1657 $lrow = sqlQuery("SELECT title FROM list_options " .
1658 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1659 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1660 //if there is no matching value in the corresponding lists check backup list
1661 // only supported in data types 1,26,33
1662 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1663 $lrow = sqlQuery("SELECT title FROM list_options " .
1664 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
1665 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1669 // simple text field
1670 else if ($data_type == 2) {
1671 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1674 // long or multi-line text field
1675 else if ($data_type == 3) {
1676 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1679 // date
1680 else if ($data_type == 4) {
1681 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1682 $s = '';
1683 $agestr = optionalAge($frow, $currvalue, $asof);
1684 if ($agestr) {
1685 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1687 if ($currvalue === '') {
1688 $s .= '&nbsp;';
1690 else {
1691 $s .= text(oeFormatShortDate($currvalue));
1693 // Optional display of age or gestational age.
1694 if ($agestr) {
1695 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1699 // provider
1700 else if ($data_type == 10 || $data_type == 11) {
1701 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1702 "WHERE id = ?", array($currvalue) );
1703 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1706 // pharmacy list
1707 else if ($data_type == 12) {
1708 $pres = get_pharmacies();
1709 while ($prow = sqlFetchArray($pres)) {
1710 $key = $prow['id'];
1711 if ($currvalue == $key) {
1712 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1713 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1714 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1719 // squads
1720 else if ($data_type == 13) {
1721 $squads = acl_get_squads();
1722 if ($squads) {
1723 foreach ($squads as $key => $value) {
1724 if ($currvalue == $key) {
1725 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1731 // address book
1732 else if ($data_type == 14) {
1733 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
1734 "WHERE id = ?", array($currvalue));
1735 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
1736 if($urow['organization'] !=""){
1737 $uname = $urow['organization'];
1738 }else{
1739 $uname = $urow['lname'];
1740 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1742 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1745 // billing code
1746 else if ($data_type == 15) {
1747 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1750 // insurance company list
1751 else if ($data_type == 16) {
1752 $insprovs = getInsuranceProviders();
1753 foreach ($insprovs as $key => $ipname) {
1754 if ($currvalue == $key) {
1755 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
1760 // issue types
1761 else if ($data_type == 17) {
1762 foreach ($ISSUE_TYPES as $key => $value) {
1763 if ($currvalue == $key) {
1764 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
1769 // visit category
1770 else if ($data_type == 18) {
1771 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1772 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1773 array($currvalue));
1774 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES);
1777 // a set of labeled checkboxes
1778 else if ($data_type == 21) {
1779 $avalue = explode('|', $currvalue);
1780 $lres = sqlStatement("SELECT * FROM list_options " .
1781 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1782 $count = 0;
1783 while ($lrow = sqlFetchArray($lres)) {
1784 $option_id = $lrow['option_id'];
1785 if (in_array($option_id, $avalue)) {
1786 if ($count++) $s .= "<br />";
1788 // Added 5-09 by BM - Translate label if applicable
1789 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES);
1795 // a set of labeled text input fields
1796 else if ($data_type == 22) {
1797 $tmp = explode('|', $currvalue);
1798 $avalue = array();
1799 foreach ($tmp as $value) {
1800 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1801 $avalue[$matches[1]] = $matches[2];
1804 $lres = sqlStatement("SELECT * FROM list_options " .
1805 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1806 $s .= "<table cellpadding='0' cellspacing='0'>";
1807 while ($lrow = sqlFetchArray($lres)) {
1808 $option_id = $lrow['option_id'];
1809 if (empty($avalue[$option_id])) continue;
1811 // Added 5-09 by BM - Translate label if applicable
1812 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1814 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1816 $s .= "</table>";
1819 // a set of exam results; 3 radio buttons and a text field:
1820 else if ($data_type == 23) {
1821 $tmp = explode('|', $currvalue);
1822 $avalue = array();
1823 foreach ($tmp as $value) {
1824 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1825 $avalue[$matches[1]] = $matches[2];
1828 $lres = sqlStatement("SELECT * FROM list_options " .
1829 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1830 $s .= "<table cellpadding='0' cellspacing='0'>";
1831 while ($lrow = sqlFetchArray($lres)) {
1832 $option_id = $lrow['option_id'];
1833 $restype = substr($avalue[$option_id], 0, 1);
1834 $resnote = substr($avalue[$option_id], 2);
1835 if (empty($restype) && empty($resnote)) continue;
1837 // Added 5-09 by BM - Translate label if applicable
1838 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1840 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1841 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1842 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1843 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1844 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1845 $s .= "</tr>";
1847 $s .= "</table>";
1850 // the list of active allergies for the current patient
1851 else if ($data_type == 24) {
1852 $query = "SELECT title, comments FROM lists WHERE " .
1853 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1854 "ORDER BY begdate";
1855 // echo "<!-- $query -->\n"; // debugging
1856 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1857 $count = 0;
1858 while ($lrow = sqlFetchArray($lres)) {
1859 if ($count++) $s .= "<br />";
1860 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1861 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1865 // a set of labeled checkboxes, each with a text field:
1866 else if ($data_type == 25) {
1867 $tmp = explode('|', $currvalue);
1868 $avalue = array();
1869 foreach ($tmp as $value) {
1870 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1871 $avalue[$matches[1]] = $matches[2];
1874 $lres = sqlStatement("SELECT * FROM list_options " .
1875 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1876 $s .= "<table cellpadding='0' cellspacing='0'>";
1877 while ($lrow = sqlFetchArray($lres)) {
1878 $option_id = $lrow['option_id'];
1879 $restype = substr($avalue[$option_id], 0, 1);
1880 $resnote = substr($avalue[$option_id], 2);
1881 if (empty($restype) && empty($resnote)) continue;
1883 // Added 5-09 by BM - Translate label if applicable
1884 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1886 $restype = $restype ? xl('Yes') : xl('No');
1887 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1888 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1889 $s .= "</tr>";
1891 $s .= "</table>";
1894 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1895 // VicarePlus :: A selection list for smoking status.
1896 else if ($data_type == 28 || $data_type == 32) {
1897 $tmp = explode('|', $currvalue);
1898 switch(count($tmp)) {
1899 case "4": {
1900 $resnote = $tmp[0];
1901 $restype = $tmp[1];
1902 $resdate = $tmp[2];
1903 $reslist = $tmp[3];
1904 } break;
1905 case "3": {
1906 $resnote = $tmp[0];
1907 $restype = $tmp[1];
1908 $resdate = $tmp[2];
1909 } break;
1910 case "2": {
1911 $resnote = $tmp[0];
1912 $restype = $tmp[1];
1913 $resdate = "";
1914 } break;
1915 case "1": {
1916 $resnote = $tmp[0];
1917 $resdate = $restype = "";
1918 } break;
1919 default: {
1920 $restype = $resdate = $resnote = "";
1921 } break;
1923 $s .= "<table cellpadding='0' cellspacing='0'>";
1925 $s .= "<tr>";
1926 $res = "";
1927 if ($restype == "current".$field_id) $res = xl('Current');
1928 if ($restype == "quit".$field_id) $res = xl('Quit');
1929 if ($restype == "never".$field_id) $res = xl('Never');
1930 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1931 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1932 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1933 if ($data_type == 28)
1935 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1937 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1938 else if ($data_type == 32)
1939 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1940 $smoke_codes = getSmokeCodes();
1941 if (!empty($reslist)) {
1942 if($smoke_codes[$reslist]!="")
1943 $code_desc = "( ".$smoke_codes[$reslist]." )";
1945 $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>";}
1947 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1950 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1951 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1952 $s .= "</tr>";
1953 $s .= "</table>";
1956 // static text. read-only, of course.
1957 else if ($data_type == 31) {
1958 $s .= nl2br($frow['description']);
1961 else if($data_type == 34){
1962 $arr = explode("|*|*|*|",$currvalue);
1963 for($i=0;$i<sizeof($arr);$i++){
1964 $s.=$arr[$i];
1968 // facility
1969 else if ($data_type == 35) {
1970 $urow = sqlQuery("SELECT id, name FROM facility ".
1971 "WHERE id = ?", array($currvalue) );
1972 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
1975 // Multi select
1976 // Supports backup lists
1977 else if ($data_type == 36) {
1978 $values_array = explode("|", $currvalue);
1980 $i = 0;
1981 foreach($values_array as $value) {
1982 $lrow = sqlQuery("SELECT title FROM list_options " .
1983 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
1985 if ($lrow == 0 && !empty($backup_list)) {
1986 //use back up list
1987 $lrow = sqlQuery("SELECT title FROM list_options " .
1988 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
1991 if ($i > 0) {
1992 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1993 } else {
1994 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1997 $i++;
2001 return $s;
2004 // Generate plain text versions of selected LBF field types.
2005 // Currently used by interface/patient_file/download_template.php.
2006 // More field types might need to be supported here in the future.
2008 function generate_plaintext_field($frow, $currvalue) {
2009 global $ISSUE_TYPES;
2011 $data_type = $frow['data_type'];
2012 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2013 $list_id = $frow['list_id'];
2014 $backup_list = $frow['backup_list'];
2015 $s = '';
2017 // generic selection list or the generic selection list with add on the fly
2018 // feature, or radio buttons
2019 // Supports backup lists (for datatypes 1,26,33)
2020 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2021 $lrow = sqlQuery("SELECT title FROM list_options " .
2022 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
2023 $s = xl_list_label($lrow['title']);
2024 //if there is no matching value in the corresponding lists check backup list
2025 // only supported in data types 1,26,33
2026 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2027 $lrow = sqlQuery("SELECT title FROM list_options " .
2028 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
2029 $s = xl_list_label($lrow['title']);
2033 // simple or long text field
2034 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2035 $s = $currvalue;
2038 // date
2039 else if ($data_type == 4) {
2040 $s = oeFormatShortDate($currvalue);
2041 // Optional display of age or gestational age.
2042 $asof=''; //not used here, but set to prevent a php warning when call optionalAge
2043 $tmp = optionalAge($frow, $currvalue,$asof);
2044 if ($tmp) $s .= ' ' . $tmp;
2047 // provider
2048 else if ($data_type == 10 || $data_type == 11) {
2049 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2050 "WHERE id = ?", array($currvalue) );
2051 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2054 // pharmacy list
2055 else if ($data_type == 12) {
2056 $pres = get_pharmacies();
2057 while ($prow = sqlFetchArray($pres)) {
2058 $key = $prow['id'];
2059 if ($currvalue == $key) {
2060 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2061 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2062 $prow['line1'] . ' / ' . $prow['city'];
2067 // address book
2068 else if ($data_type == 14) {
2069 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2070 "WHERE id = ?", array($currvalue));
2071 $uname = $urow['lname'];
2072 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2073 $s = $uname;
2076 // insurance company list
2077 else if ($data_type == 16) {
2078 $insprovs = getInsuranceProviders();
2079 foreach ($insprovs as $key => $ipname) {
2080 if ($currvalue == $key) {
2081 $s .= $ipname;
2086 // issue type
2087 else if ($data_type == 17) {
2088 foreach ($ISSUE_TYPES as $key => $value) {
2089 if ($currvalue == $key) {
2090 $s .= $value[1];
2095 // visit category
2096 else if ($data_type == 18) {
2097 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2098 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2099 array($currvalue));
2100 $s = $crow['pc_catname'];
2103 // a set of labeled checkboxes
2104 else if ($data_type == 21) {
2105 $avalue = explode('|', $currvalue);
2106 $lres = sqlStatement("SELECT * FROM list_options " .
2107 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2108 $count = 0;
2109 while ($lrow = sqlFetchArray($lres)) {
2110 $option_id = $lrow['option_id'];
2111 if (in_array($option_id, $avalue)) {
2112 if ($count++) $s .= "; ";
2113 $s .= xl_list_label($lrow['title']);
2118 // a set of labeled text input fields
2119 else if ($data_type == 22) {
2120 $tmp = explode('|', $currvalue);
2121 $avalue = array();
2122 foreach ($tmp as $value) {
2123 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2124 $avalue[$matches[1]] = $matches[2];
2127 $lres = sqlStatement("SELECT * FROM list_options " .
2128 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2129 while ($lrow = sqlFetchArray($lres)) {
2130 $option_id = $lrow['option_id'];
2131 if (empty($avalue[$option_id])) continue;
2132 if ($s !== '') $s .= '; ';
2133 $s .= xl_list_label($lrow['title']) . ': ';
2134 $s .= $avalue[$option_id];
2138 // A set of exam results; 3 radio buttons and a text field.
2139 // This shows abnormal results only.
2140 else if ($data_type == 23) {
2141 $tmp = explode('|', $currvalue);
2142 $avalue = array();
2143 foreach ($tmp as $value) {
2144 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2145 $avalue[$matches[1]] = $matches[2];
2148 $lres = sqlStatement("SELECT * FROM list_options " .
2149 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2150 while ($lrow = sqlFetchArray($lres)) {
2151 $option_id = $lrow['option_id'];
2152 $restype = substr($avalue[$option_id], 0, 1);
2153 $resnote = substr($avalue[$option_id], 2);
2154 if (empty($restype) && empty($resnote)) continue;
2155 if ($restype != '2') continue; // show abnormal results only
2156 if ($s !== '') $s .= '; ';
2157 $s .= xl_list_label($lrow['title']);
2158 if (!empty($resnote)) $s .= ': ' . $resnote;
2162 // the list of active allergies for the current patient
2163 else if ($data_type == 24) {
2164 $query = "SELECT title, comments FROM lists WHERE " .
2165 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2166 "ORDER BY begdate";
2167 $lres = sqlStatement($query, array($GLOBALS['pid']));
2168 $count = 0;
2169 while ($lrow = sqlFetchArray($lres)) {
2170 if ($count++) $s .= "; ";
2171 $s .= $lrow['title'];
2172 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2176 // a set of labeled checkboxes, each with a text field:
2177 else if ($data_type == 25) {
2178 $tmp = explode('|', $currvalue);
2179 $avalue = array();
2180 foreach ($tmp as $value) {
2181 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2182 $avalue[$matches[1]] = $matches[2];
2185 $lres = sqlStatement("SELECT * FROM list_options " .
2186 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2187 while ($lrow = sqlFetchArray($lres)) {
2188 $option_id = $lrow['option_id'];
2189 $restype = substr($avalue[$option_id], 0, 1);
2190 $resnote = substr($avalue[$option_id], 2);
2191 if (empty($restype) && empty($resnote)) continue;
2192 if ($s !== '') $s .= '; ';
2193 $s .= xl_list_label($lrow['title']);
2194 $restype = $restype ? xl('Yes') : xl('No');
2195 $s .= $restype;
2196 if ($resnote) $s .= ' ' . $resnote;
2200 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2201 // VicarePlus :: A selection list for smoking status.
2202 else if ($data_type == 28 || $data_type == 32) {
2203 $tmp = explode('|', $currvalue);
2204 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2205 $restype = count($tmp) > 1 ? $tmp[1] : '';
2206 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2207 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2208 $res = "";
2209 if ($restype == "current" . $field_id) $res = xl('Current');
2210 if ($restype == "quit" . $field_id) $res = xl('Quit');
2211 if ($restype == "never" . $field_id) $res = xl('Never');
2212 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2214 if ($data_type == 28) {
2215 if (!empty($resnote)) $s .= $resnote;
2217 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2218 else if ($data_type == 32) {
2219 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2220 if (!empty($resnote)) $s .= ' ' . $resnote;
2222 if (!empty($res)) {
2223 if ($s !== '') $s .= ' ';
2224 $s .= xl('Status') . ' ' . $res;
2226 if ($restype == "quit".$field_id) {
2227 if ($s !== '') $s .= ' ';
2228 $s .= $resdate;
2232 // Multi select
2233 // Supports backup lists
2234 else if ($data_type == 36) {
2235 $values_array = explode("|", $currvalue);
2237 $i = 0;
2238 foreach($values_array as $value) {
2239 $lrow = sqlQuery("SELECT title FROM list_options " .
2240 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
2242 if ($lrow == 0 && !empty($backup_list)) {
2243 //use back up list
2244 $lrow = sqlQuery("SELECT title FROM list_options " .
2245 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
2248 if ($i > 0) {
2249 $s = $s . ", " . xl_list_label($lrow['title']);
2250 } else {
2251 $s = xl_list_label($lrow['title']);
2254 $i++;
2258 return $s;
2261 $CPR = 4; // cells per row of generic data
2262 $last_group = '';
2263 $cell_count = 0;
2264 $item_count = 0;
2266 function disp_end_cell() {
2267 global $item_count, $cell_count;
2268 if ($item_count > 0) {
2269 echo "</td>";
2270 $item_count = 0;
2274 function disp_end_row() {
2275 global $cell_count, $CPR;
2276 disp_end_cell();
2277 if ($cell_count > 0) {
2278 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
2279 echo "</tr>\n";
2280 $cell_count = 0;
2284 function disp_end_group() {
2285 global $last_group;
2286 if (strlen($last_group) > 0) {
2287 disp_end_row();
2291 function display_layout_rows($formtype, $result1, $result2='') {
2292 global $item_count, $cell_count, $last_group, $CPR;
2294 $fres = sqlStatement("SELECT * FROM layout_options " .
2295 "WHERE form_id = ? AND uor > 0 " .
2296 "ORDER BY group_name, seq", array($formtype) );
2298 while ($frow = sqlFetchArray($fres)) {
2299 $this_group = $frow['group_name'];
2300 $titlecols = $frow['titlecols'];
2301 $datacols = $frow['datacols'];
2302 $data_type = $frow['data_type'];
2303 $field_id = $frow['field_id'];
2304 $list_id = $frow['list_id'];
2305 $currvalue = '';
2307 if ($formtype == 'DEM') {
2308 if ($GLOBALS['athletic_team']) {
2309 // Skip fitness level and return-to-play date because those appear
2310 // in a special display/update form on this page.
2311 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2313 if (strpos($field_id, 'em_') === 0) {
2314 // Skip employer related fields, if it's disabled.
2315 if ($GLOBALS['omit_employers']) continue;
2316 $tmp = substr($field_id, 3);
2317 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2319 else {
2320 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2323 else {
2324 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2327 // Handle a data category (group) change.
2328 if (strcmp($this_group, $last_group) != 0) {
2329 $group_name = substr($this_group, 1);
2330 // totally skip generating the employer category, if it's disabled.
2331 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2332 disp_end_group();
2333 $last_group = $this_group;
2336 // filter out all the empty field data from the patient report.
2337 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2338 // Handle starting of a new row.
2339 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2340 disp_end_row();
2341 echo "<tr>";
2342 if ($group_name) {
2343 echo "<td class='groupname'>";
2344 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2345 //echo "<font color='#008800'>$group_name</font>";
2347 // Added 5-09 by BM - Translate label if applicable
2348 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
2350 $group_name = '';
2351 } else {
2352 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2353 echo "<td valign='top'>&nbsp;";
2355 echo "</td>";
2358 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2360 // Handle starting of a new label cell.
2361 if ($titlecols > 0) {
2362 disp_end_cell();
2363 //echo "<td class='label' colspan='$titlecols' valign='top'";
2364 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2365 echo "<td class='label' colspan='$titlecols_esc' ";
2366 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2367 echo ">";
2368 $cell_count += $titlecols;
2370 ++$item_count;
2372 // Added 5-09 by BM - Translate label if applicable
2373 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2375 // Handle starting of a new data cell.
2376 if ($datacols > 0) {
2377 disp_end_cell();
2378 //echo "<td class='text data' colspan='$datacols' valign='top'";
2379 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2380 echo "<td class='text data' colspan='$datacols_esc'";
2381 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2382 echo ">";
2383 $cell_count += $datacols;
2386 ++$item_count;
2387 echo generate_display_field($frow, $currvalue);
2391 disp_end_group();
2394 function display_layout_tabs($formtype, $result1, $result2='') {
2395 global $item_count, $cell_count, $last_group, $CPR;
2397 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2398 "WHERE form_id = ? AND uor > 0 " .
2399 "ORDER BY group_name, seq", array($formtype) );
2401 $first = true;
2402 while ($frow = sqlFetchArray($fres)) {
2403 $this_group = $frow['group_name'];
2404 $group_name = substr($this_group, 1);
2405 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2407 <li <?php echo $first ? 'class="current"' : '' ?>>
2408 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
2409 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
2410 </li>
2411 <?php
2412 $first = false;
2416 function display_layout_tabs_data($formtype, $result1, $result2='') {
2417 global $item_count, $cell_count, $last_group, $CPR;
2419 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2420 "WHERE form_id = ? AND uor > 0 " .
2421 "ORDER BY group_name, seq", array($formtype));
2423 $first = true;
2424 while ($frow = sqlFetchArray($fres)) {
2425 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
2426 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
2427 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
2428 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
2429 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
2430 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
2431 $currvalue = '';
2433 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2435 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2436 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2437 "ORDER BY seq", array($formtype, $this_group) );
2440 <div class="tab <?php echo $first ? 'current' : '' ?>">
2441 <table border='0' cellpadding='0'>
2443 <?php
2444 while ($group_fields = sqlFetchArray($group_fields_query)) {
2446 $titlecols = $group_fields['titlecols'];
2447 $datacols = $group_fields['datacols'];
2448 $data_type = $group_fields['data_type'];
2449 $field_id = $group_fields['field_id'];
2450 $list_id = $group_fields['list_id'];
2451 $currvalue = '';
2453 if ($formtype == 'DEM') {
2454 if ($GLOBALS['athletic_team']) {
2455 // Skip fitness level and return-to-play date because those appear
2456 // in a special display/update form on this page.
2457 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2459 if (strpos($field_id, 'em_') === 0) {
2460 // Skip employer related fields, if it's disabled.
2461 if ($GLOBALS['omit_employers']) continue;
2462 $tmp = substr($field_id, 3);
2463 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2465 else {
2466 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2469 else {
2470 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2473 // Handle a data category (group) change.
2474 if (strcmp($this_group, $last_group) != 0) {
2475 $group_name = substr($this_group, 1);
2476 // totally skip generating the employer category, if it's disabled.
2477 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2478 $last_group = $this_group;
2481 // Handle starting of a new row.
2482 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2483 disp_end_row();
2484 echo "<tr>";
2487 if ($item_count == 0 && $titlecols == 0) {
2488 $titlecols = 1;
2491 // Handle starting of a new label cell.
2492 if ($titlecols > 0) {
2493 disp_end_cell();
2494 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2495 echo "<td class='label' colspan='$titlecols_esc' ";
2496 echo ">";
2497 $cell_count += $titlecols;
2499 ++$item_count;
2501 // Added 5-09 by BM - Translate label if applicable
2502 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2504 // Handle starting of a new data cell.
2505 if ($datacols > 0) {
2506 disp_end_cell();
2507 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2508 echo "<td class='text data' colspan='$datacols_esc'";
2509 echo ">";
2510 $cell_count += $datacols;
2513 ++$item_count;
2514 echo generate_display_field($group_fields, $currvalue);
2517 disp_end_row();
2520 </table>
2521 </div>
2523 <?php
2525 $first = false;
2531 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2532 global $item_count, $cell_count, $last_group, $CPR;
2534 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2535 "WHERE form_id = ? AND uor > 0 " .
2536 "ORDER BY group_name, seq", array($formtype) );
2538 $first = true;
2539 while ($frow = sqlFetchArray($fres)) {
2540 $this_group = $frow['group_name'];
2541 $group_name = substr($this_group, 1);
2542 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
2543 $titlecols = $frow['titlecols'];
2544 $datacols = $frow['datacols'];
2545 $data_type = $frow['data_type'];
2546 $field_id = $frow['field_id'];
2547 $list_id = $frow['list_id'];
2548 $currvalue = '';
2550 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2552 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2553 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2554 "ORDER BY seq", array($formtype,$this_group) );
2557 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
2558 <table border='0' cellpadding='0'>
2560 <?php
2561 while ($group_fields = sqlFetchArray($group_fields_query)) {
2563 $titlecols = $group_fields['titlecols'];
2564 $datacols = $group_fields['datacols'];
2565 $data_type = $group_fields['data_type'];
2566 $field_id = $group_fields['field_id'];
2567 $list_id = $group_fields['list_id'];
2568 $backup_list = $group_fields['list_backup_id'];
2569 $currvalue = '';
2571 if ($formtype == 'DEM') {
2572 if ($GLOBALS['athletic_team']) {
2573 // Skip fitness level and return-to-play date because those appear
2574 // in a special display/update form on this page.
2575 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2577 if (strpos($field_id, 'em_') === 0) {
2578 // Skip employer related fields, if it's disabled.
2579 if ($GLOBALS['omit_employers']) continue;
2580 $tmp = substr($field_id, 3);
2581 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2583 else {
2584 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2587 else {
2588 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2591 // Handle a data category (group) change.
2592 if (strcmp($this_group, $last_group) != 0) {
2593 $group_name = substr($this_group, 1);
2594 // totally skip generating the employer category, if it's disabled.
2595 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2596 $last_group = $this_group;
2599 // Handle starting of a new row.
2600 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2601 disp_end_row();
2602 echo "<tr>";
2605 if ($item_count == 0 && $titlecols == 0) {
2606 $titlecols = 1;
2609 // Handle starting of a new label cell.
2610 if ($titlecols > 0) {
2611 disp_end_cell();
2612 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2613 echo "<td class='label' colspan='$titlecols_esc' ";
2614 echo ">";
2615 $cell_count += $titlecols;
2617 ++$item_count;
2619 // Added 5-09 by BM - Translate label if applicable
2620 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
2622 // Handle starting of a new data cell.
2623 if ($datacols > 0) {
2624 disp_end_cell();
2625 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2626 echo "<td class='text data' colspan='$datacols_esc'";
2627 echo ">";
2628 $cell_count += $datacols;
2631 ++$item_count;
2633 echo generate_form_field($group_fields, $currvalue);
2637 </table>
2638 </div>
2640 <?php
2642 $first = false;
2647 // From the currently posted HTML form, this gets the value of the
2648 // field corresponding to the provided layout_options table row.
2650 function get_layout_form_value($frow, $prefix='form_') {
2651 // Bring in $sanitize_all_escapes variable, which will decide
2652 // the variable escaping method.
2653 global $sanitize_all_escapes;
2655 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
2656 $data_type = $frow['data_type'];
2657 $field_id = $frow['field_id'];
2658 $value = '';
2659 if (isset($_POST["$prefix$field_id"])) {
2660 if ($data_type == 21) {
2661 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2662 // must be concatenated into a |-separated string.
2663 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2664 if (strlen($value)) $value .= '|';
2665 $value .= $key;
2668 else if ($data_type == 22) {
2669 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2670 // into "key:value|key:value|...".
2671 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2672 $val = str_replace('|', ' ', $val);
2673 if (strlen($value)) $value .= '|';
2674 $value .= "$key:$val";
2677 else if ($data_type == 23) {
2678 // $_POST["$prefix$field_id"] is an array of text fields with companion
2679 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2680 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2681 $restype = $_POST["radio_{$field_id}"][$key];
2682 if (empty($restype)) $restype = '0';
2683 $val = str_replace('|', ' ', $val);
2684 if (strlen($value)) $value .= '|';
2685 $value .= "$key:$restype:$val";
2688 else if ($data_type == 25) {
2689 // $_POST["$prefix$field_id"] is an array of text fields with companion
2690 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2691 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2692 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
2693 $val = str_replace('|', ' ', $val);
2694 if (strlen($value)) $value .= '|';
2695 $value .= "$key:$restype:$val";
2698 else if ($data_type == 28 || $data_type == 32) {
2699 // $_POST["$prefix$field_id"] is an date text fields with companion
2700 // radio buttons to be imploded into "notes|type|date".
2701 $restype = $_POST["radio_{$field_id}"];
2702 if (empty($restype)) $restype = '0';
2703 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2704 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2705 if ($data_type == 32)
2707 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2708 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2709 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2710 $value = "$res_text_note|$restype|$resdate|$reslist";
2712 else
2713 $value = "$resnote|$restype|$resdate";
2715 else if ($data_type == 36) {
2716 $value_array = $_POST["form_$field_id"];
2717 $i = 0;
2718 foreach ($value_array as $key => $valueofkey) {
2719 if ($i == 0) {
2720 $value = $valueofkey;
2721 } else {
2722 $value = $value . "|" . $valueofkey;
2724 $i++;
2727 else {
2728 $value = $_POST["$prefix$field_id"];
2732 // Better to die than to silently truncate data!
2733 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2734 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2735 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2737 // Make sure the return value is quote-safe.
2738 if ($sanitize_all_escapes) {
2739 //escapes already removed and using binding/placemarks in sql calls
2740 // so only need to trim value
2741 return trim($value);
2743 else {
2744 //need to explicitly prepare value
2745 return formTrim($value);
2749 // Generate JavaScript validation logic for the required fields.
2751 function generate_layout_validation($form_id) {
2752 $fres = sqlStatement("SELECT * FROM layout_options " .
2753 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2754 "ORDER BY group_name, seq", array($form_id) );
2756 while ($frow = sqlFetchArray($fres)) {
2757 if ($frow['uor'] < 2) continue;
2758 $data_type = $frow['data_type'];
2759 $field_id = $frow['field_id'];
2760 $fldtitle = $frow['title'];
2761 if (!$fldtitle) $fldtitle = $frow['description'];
2762 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
2763 switch($data_type) {
2764 case 1:
2765 case 11:
2766 case 12:
2767 case 13:
2768 case 14:
2769 case 26:
2770 case 33:
2771 echo
2772 " if (f.$fldname.selectedIndex <= 0) {\n" .
2773 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2774 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2775 " }\n";
2776 break;
2777 case 27: // radio buttons
2778 echo
2779 " var i = 0;\n" .
2780 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2781 " if (i >= f.$fldname.length) {\n" .
2782 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2783 " }\n";
2784 break;
2785 case 2:
2786 case 3:
2787 case 4:
2788 case 15:
2789 echo
2790 " if (trimlen(f.$fldname.value) == 0) {\n" .
2791 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2792 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2793 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2794 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2795 " } else { " .
2796 " $('#" . $fldname . "').attr('style',''); " .
2797 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2798 " } \n";
2799 break;
2800 case 36: // multi select
2801 echo
2802 " var multi_select=f['$fldname"."[]']; \n " .
2803 " var multi_choice_made=false; \n".
2804 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
2805 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
2806 " } \n" .
2807 " if(!multi_choice_made)
2808 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2810 break;
2816 * DROPDOWN FOR FACILITIES
2818 * build a dropdown with all facilities
2820 * @param string $selected - name of the currently selected facility
2821 * use '0' for "unspecified facility"
2822 * use '' for "All facilities" (the default)
2823 * @param string $name - the name/id for select form (defaults to "form_facility")
2824 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2825 * defaults to true
2826 * @return void - just echo the html encoded string
2828 * Note: This should become a data-type at some point, according to Brady
2830 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2831 $allow_allfacilities = true, $disabled='', $onchange='')
2833 $have_selected = false;
2834 $query = "SELECT id, name FROM facility ORDER BY name";
2835 $fres = sqlStatement($query);
2837 $name = htmlspecialchars($name, ENT_QUOTES);
2838 echo " <select name='$name' id='$name'";
2839 if ($onchange) echo " onchange='$onchange'";
2840 echo " $disabled>\n";
2842 if ($allow_allfacilities) {
2843 $option_value = '';
2844 $option_selected_attr = '';
2845 if ($selected == '') {
2846 $option_selected_attr = ' selected="selected"';
2847 $have_selected = true;
2849 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2850 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2851 } elseif ($allow_unspecified) {
2852 $option_value = '0';
2853 $option_selected_attr = '';
2854 if ( $selected == '0' ) {
2855 $option_selected_attr = ' selected="selected"';
2856 $have_selected = true;
2858 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2859 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2862 while ($frow = sqlFetchArray($fres)) {
2863 $facility_id = $frow['id'];
2864 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2865 $option_selected_attr = '';
2866 if ($selected == $facility_id) {
2867 $option_selected_attr = ' selected="selected"';
2868 $have_selected = true;
2870 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2871 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2874 if ($allow_unspecified && $allow_allfacilities) {
2875 $option_value = '0';
2876 $option_selected_attr = '';
2877 if ( $selected == '0' ) {
2878 $option_selected_attr = ' selected="selected"';
2879 $have_selected = true;
2881 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2882 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2885 if (!$have_selected) {
2886 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2887 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2888 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2889 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2891 echo " </select>\n";
2894 // Expand Collapse Widget
2895 // This forms the header and functionality component of the widget. The information that is displayed
2896 // then follows this function followed by a closing div tag
2898 // $title is the title of the section (already translated)
2899 // $label is identifier used in the tag id's and sql columns
2900 // $buttonLabel is the button label text (already translated)
2901 // $buttonLink is the button link information
2902 // $buttonClass is any additional needed class elements for the button tag
2903 // $linkMethod is the button link method ('javascript' vs 'html')
2904 // $bodyClass is to set class(es) of the body
2905 // $auth is a flag to decide whether to show the button
2906 // $fixedWidth is to flag whether width is fixed
2907 // $forceExpandAlways is a flag to force the widget to always be expanded
2909 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2910 if ($fixedWidth) {
2911 echo "<div class='section-header'>";
2913 else {
2914 echo "<div class='section-header-dynamic'>";
2916 echo "<table><tr>";
2917 if ($auth) {
2918 // show button, since authorized
2919 // first prepare class string
2920 if ($buttonClass) {
2921 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2923 else {
2924 $class_string = "css_button_small";
2926 // next, create the link
2927 if ($linkMethod == "javascript") {
2928 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2930 else {
2931 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2932 if (!isset($_SESSION['patient_portal_onsite'])) {
2933 // prevent an error from occuring when calling the function from the patient portal
2934 echo " onclick='top.restoreSession()'";
2937 if (!$GLOBALS['concurrent_layout']) {
2938 echo " target='Main'";
2940 echo "><span>" .
2941 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2943 if ($forceExpandAlways){
2944 // Special case to force the widget to always be expanded
2945 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2946 $indicatorTag ="style='display:none'";
2948 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
2949 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2950 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
2951 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2953 if (isset($_SESSION['patient_portal_onsite'])) {
2954 // collapse all entries in the patient portal
2955 $text = xl('expand');
2957 else if (getUserSetting($label."_ps_expand")) {
2958 $text = xl('collapse');
2960 else {
2961 $text = xl('expand');
2963 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
2964 "</span>)</a></td>";
2965 echo "</tr></table>";
2966 echo "</div>";
2967 if ($forceExpandAlways) {
2968 // Special case to force the widget to always be expanded
2969 $styling = "";
2971 else if (isset($_SESSION['patient_portal_onsite'])) {
2972 // collapse all entries in the patient portal
2973 $styling = "style='display:none'";
2975 else if (getUserSetting($label."_ps_expand")) {
2976 $styling = "";
2978 else {
2979 $styling = "style='display:none'";
2981 if ($bodyClass) {
2982 $styling .= " class='" . $bodyClass . "'";
2984 //next, create the first div tag to hold the information
2985 // note the code that calls this function will then place the ending div tag after the data
2986 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
2989 //billing_facility fuction will give the dropdown list which contain billing faciliies.
2990 function billing_facility($name,$select){
2991 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
2992 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
2993 while ($facrow = sqlFetchArray($qsql)) {
2994 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
2995 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
2997 echo "</select>";
3000 // Generic function to get the translated title value for a particular list option.
3002 function getListItemTitle($list, $option) {
3003 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3004 "list_id = ? AND option_id = ?", array($list, $option));
3005 if (empty($row['title'])) return $option;
3006 return xl_list_label($row['title']);
3008 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3009 function getSmokeCodes()
3011 $smoking_codes_arr = array();
3012 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status'");
3013 while($codes_row = sqlFetchArray($smoking_codes))
3015 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3017 return $smoking_codes_arr;
3020 // Get the current value for a layout based form field.
3021 // Depending on options this might come from lbf_data, patient_data,
3022 // form_encounter, shared_attributes or elsewhere.
3023 // Returns FALSE if the field ID is invalid (layout error).
3025 function lbf_current_value($frow, $formid, $encounter) {
3026 global $pid;
3027 $formname = $frow['form_id'];
3028 $field_id = $frow['field_id'];
3029 $source = $frow['source'];
3030 $currvalue = '';
3031 $deffname = $formname . '_default_' . $field_id;
3032 if ($source == 'D' || $source == 'H') {
3033 // Get from patient_data, employer_data or history_data.
3034 if ($source == 'H') {
3035 $table = 'history_data';
3036 $orderby = 'ORDER BY date DESC LIMIT 1';
3038 else if (strpos($field_id, 'em_') === 0) {
3039 $field_id = substr($field_id, 3);
3040 $table = 'employer_data';
3041 $orderby = 'ORDER BY date DESC LIMIT 1';
3043 else {
3044 $table = 'patient_data';
3045 $orderby = '';
3047 // It is an error if the field does not exist, but don't crash.
3048 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3049 if (empty($tmp)) return FALSE;
3050 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3051 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3053 else if ($source == 'E') {
3054 if ($encounter) {
3055 // Get value from shared_attributes of the current encounter.
3056 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3057 "pid = ? AND encounter = ? AND field_id = ?",
3058 array($pid, $encounter, $field_id));
3059 if (isset($sarow)) $currvalue = $sarow['field_value'];
3061 else if ($formid) {
3062 // Get from shared_attributes of the encounter that this form is linked to.
3063 // Note the importance of having an index on forms.form_id.
3064 $sarow = sqlQuery("SELECT sa.field_value " .
3065 "FROM forms AS f, shared_attributes AS sa WHERE " .
3066 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3067 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3068 array($formid, $formname, $field_id));
3069 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3071 else {
3072 // New form and encounter not available, this should not happen.
3075 else if ($source == 'V') {
3076 if ($encounter) {
3077 // Get value from the current encounter's form_encounter.
3078 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3079 "pid = ? AND encounter = ?",
3080 array($pid, $encounter));
3081 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3083 else if ($formid) {
3084 // Get value from the form_encounter that this form is linked to.
3085 $ferow = sqlQuery("SELECT fe.* " .
3086 "FROM forms AS f, form_encounter AS fe WHERE " .
3087 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3088 "fe.pid = f.pid AND fe.encounter = f.encounter",
3089 array($formid, $formname));
3090 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3092 else {
3093 // New form and encounter not available, this should not happen.
3096 else if ($formid) {
3097 // This is a normal form field.
3098 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3099 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3100 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3102 else {
3103 // New form, see if there is a custom default from a plugin.
3104 // This logic does not apply to shared attributes because they do not
3105 // have a "new form" concept.
3106 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3108 return $currvalue;