Onsite Patient Portal appointment display fix.
[openemr.git] / library / options.inc.php
blob4a447dccee201241dd190ab329624108b2eb71b3
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 $agestr = optionalAge($frow, $currvalue);
1154 if ($agestr) {
1155 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1157 if ($currvalue === '') {
1158 echo '&nbsp;';
1160 else {
1161 echo text(oeFormatShortDate($currvalue));
1163 // Optional display of age or gestational age.
1164 if ($agestr) {
1165 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1169 // provider list
1170 else if ($data_type == 10 || $data_type == 11) {
1171 $tmp = '';
1172 if ($currvalue) {
1173 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1174 "WHERE id = ?", array($currvalue) );
1175 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1176 if (empty($tmp)) $tmp = "($currvalue)";
1178 /*****************************************************************
1179 echo "<input type='text'" .
1180 " size='$fld_length'" .
1181 " value='$tmp'" .
1182 " class='under'" .
1183 " />";
1184 *****************************************************************/
1185 if ($tmp === '') { $tmp = '&nbsp;'; }
1186 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1187 echo $tmp;
1190 // pharmacy list
1191 else if ($data_type == 12) {
1192 $tmp = '';
1193 if ($currvalue) {
1194 $pres = get_pharmacies();
1195 while ($prow = sqlFetchArray($pres)) {
1196 $key = $prow['id'];
1197 if ($currvalue == $key) {
1198 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1199 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1200 $prow['line1'] . ' / ' . $prow['city'];
1203 if (empty($tmp)) $tmp = "($currvalue)";
1205 /*****************************************************************
1206 echo "<input type='text'" .
1207 " size='$fld_length'" .
1208 " value='$tmp'" .
1209 " class='under'" .
1210 " />";
1211 *****************************************************************/
1212 if ($tmp === '') { $tmp = '&nbsp;'; }
1213 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1214 echo $tmp;
1217 // squads
1218 else if ($data_type == 13) {
1219 $tmp = '';
1220 if ($currvalue) {
1221 $squads = acl_get_squads();
1222 if ($squads) {
1223 foreach ($squads as $key => $value) {
1224 if ($currvalue == $key) {
1225 $tmp = $value[3];
1229 if (empty($tmp)) $tmp = "($currvalue)";
1231 /*****************************************************************
1232 echo "<input type='text'" .
1233 " size='$fld_length'" .
1234 " value='$tmp'" .
1235 " class='under'" .
1236 " />";
1237 *****************************************************************/
1238 if ($tmp === '') { $tmp = '&nbsp;'; }
1239 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1240 echo $tmp;
1243 // Address book.
1244 else if ($data_type == 14) {
1245 $tmp = '';
1246 if ($currvalue) {
1247 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1248 "WHERE id = ?", array($currvalue) );
1249 $uname = $urow['lname'];
1250 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1251 $tmp = $uname;
1252 if (empty($tmp)) $tmp = "($currvalue)";
1254 /*****************************************************************
1255 echo "<input type='text'" .
1256 " size='$fld_length'" .
1257 " value='$tmp'" .
1258 " class='under'" .
1259 " />";
1260 *****************************************************************/
1261 if ($tmp === '') { $tmp = '&nbsp;'; }
1262 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1263 echo $tmp;
1266 // insurance company list
1267 else if ($data_type == 16) {
1268 $tmp = '';
1269 if ($currvalue) {
1270 $insprovs = getInsuranceProviders();
1271 foreach ($insprovs as $key => $ipname) {
1272 if ($currvalue == $key) {
1273 $tmp = $ipname;
1276 if (empty($tmp)) $tmp = "($currvalue)";
1278 if ($tmp === '') $tmp = '&nbsp;';
1279 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1280 echo $tmp;
1283 // issue types
1284 else if ($data_type == 17) {
1285 $tmp = '';
1286 if ($currvalue) {
1287 foreach ($ISSUE_TYPES as $key => $value) {
1288 if ($currvalue == $key) {
1289 $tmp = $value[1];
1292 if (empty($tmp)) $tmp = "($currvalue)";
1294 if ($tmp === '') $tmp = '&nbsp;';
1295 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1296 echo $tmp;
1299 // Visit categories.
1300 else if ($data_type == 18) {
1301 $tmp = '';
1302 if ($currvalue) {
1303 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1304 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1305 array($currvalue));
1306 $tmp = xl_appt_category($crow['pc_catname']);
1307 if (empty($tmp)) $tmp = "($currvalue)";
1309 if ($tmp === '') { $tmp = '&nbsp;'; }
1310 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES); }
1311 echo $tmp;
1314 // a set of labeled checkboxes
1315 else if ($data_type == 21) {
1316 // In this special case, fld_length is the number of columns generated.
1317 $cols = max(1, $fld_length);
1318 $avalue = explode('|', $currvalue);
1319 $lres = sqlStatement("SELECT * FROM list_options " .
1320 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1321 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1322 $tdpct = (int) (100 / $cols);
1323 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1324 $option_id = $lrow['option_id'];
1325 if ($count % $cols == 0) {
1326 if ($count) echo "</tr>";
1327 echo "<tr>";
1329 echo "<td width='$tdpct%'>";
1330 echo "<input type='checkbox'";
1331 if (in_array($option_id, $avalue)) echo " checked";
1332 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1333 echo "</td>";
1335 if ($count) {
1336 echo "</tr>";
1337 if ($count > $cols) {
1338 // Add some space after multiple rows of checkboxes.
1339 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1340 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1343 echo "</table>";
1346 // a set of labeled text input fields
1347 else if ($data_type == 22) {
1348 $tmp = explode('|', $currvalue);
1349 $avalue = array();
1350 foreach ($tmp as $value) {
1351 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1352 $avalue[$matches[1]] = $matches[2];
1355 $lres = sqlStatement("SELECT * FROM list_options " .
1356 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1357 echo "<table cellpadding='0' cellspacing='0'>";
1358 while ($lrow = sqlFetchArray($lres)) {
1359 $option_id = $lrow['option_id'];
1360 $fldlength = empty($fld_length) ? 20 : $fld_length;
1361 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1362 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1363 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1364 echo "<td><input type='text'" .
1365 " size='$fldlength'" .
1366 " value='$inputValue'" .
1367 " class='under'" .
1368 " /></td></tr>";
1370 echo "</table>";
1373 // a set of exam results; 3 radio buttons and a text field:
1374 else if ($data_type == 23) {
1375 $tmp = explode('|', $currvalue);
1376 $avalue = array();
1377 foreach ($tmp as $value) {
1378 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1379 $avalue[$matches[1]] = $matches[2];
1382 $fldlength = empty($fld_length) ? 20 : $fld_length;
1383 $lres = sqlStatement("SELECT * FROM list_options " .
1384 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1385 echo "<table cellpadding='0' cellspacing='0'>";
1386 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1387 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1388 "&nbsp;</td><td class='bold'>" .
1389 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1390 "<td class='bold'>" .
1391 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1392 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1393 while ($lrow = sqlFetchArray($lres)) {
1394 $option_id = $lrow['option_id'];
1395 $restype = substr($avalue[$option_id], 0, 1);
1396 $resnote = substr($avalue[$option_id], 2);
1397 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1398 for ($i = 0; $i < 3; ++$i) {
1399 echo "<td><input type='radio'";
1400 if ($restype === "$i") echo " checked";
1401 echo " /></td>";
1403 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1404 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1405 echo "<td><input type='text'" .
1406 " size='$fldlength'" .
1407 " value='$resnote'" .
1408 " class='under' /></td>" .
1409 "</tr>";
1411 echo "</table>";
1414 // the list of active allergies for the current patient
1415 // this is read-only!
1416 else if ($data_type == 24) {
1417 $query = "SELECT title, comments FROM lists WHERE " .
1418 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1419 "ORDER BY begdate";
1420 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1421 $count = 0;
1422 while ($lrow = sqlFetchArray($lres)) {
1423 if ($count++) echo "<br />";
1424 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1425 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1429 // a set of labeled checkboxes, each with a text field:
1430 else if ($data_type == 25) {
1431 $tmp = explode('|', $currvalue);
1432 $avalue = array();
1433 foreach ($tmp as $value) {
1434 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1435 $avalue[$matches[1]] = $matches[2];
1438 $fldlength = empty($fld_length) ? 20 : $fld_length;
1439 $lres = sqlStatement("SELECT * FROM list_options " .
1440 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1441 echo "<table cellpadding='0' cellspacing='0'>";
1442 while ($lrow = sqlFetchArray($lres)) {
1443 $option_id = $lrow['option_id'];
1444 $restype = substr($avalue[$option_id], 0, 1);
1445 $resnote = substr($avalue[$option_id], 2);
1446 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1447 echo "<td><input type='checkbox'";
1448 if ($restype) echo " checked";
1449 echo " />&nbsp;</td>";
1450 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1451 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1452 echo "<td><input type='text'" .
1453 " size='$fldlength'" .
1454 " value='$resnote'" .
1455 " class='under'" .
1456 " /></td>" .
1457 "</tr>";
1459 echo "</table>";
1462 // a set of labeled radio buttons
1463 else if ($data_type == 27) {
1464 // In this special case, fld_length is the number of columns generated.
1465 $cols = max(1, $frow['fld_length']);
1466 $lres = sqlStatement("SELECT * FROM list_options " .
1467 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1468 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1469 $tdpct = (int) (100 / $cols);
1470 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1471 $option_id = $lrow['option_id'];
1472 if ($count % $cols == 0) {
1473 if ($count) echo "</tr>";
1474 echo "<tr>";
1476 echo "<td width='$tdpct%'>";
1477 echo "<input type='radio'";
1478 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1479 (strlen($currvalue) > 0 && $option_id == $currvalue))
1481 echo " checked";
1483 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1484 echo "</td>";
1486 if ($count) {
1487 echo "</tr>";
1488 if ($count > $cols) {
1489 // Add some space after multiple rows of radio buttons.
1490 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1491 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1494 echo "</table>";
1497 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1498 else if ($data_type == 28 || $data_type == 32) {
1499 $tmp = explode('|', $currvalue);
1500 switch(count($tmp)) {
1501 case "4": {
1502 $resnote = $tmp[0];
1503 $restype = $tmp[1];
1504 $resdate = $tmp[2];
1505 $reslist = $tmp[3];
1506 } break;
1507 case "3": {
1508 $resnote = $tmp[0];
1509 $restype = $tmp[1];
1510 $resdate = $tmp[2];
1511 } break;
1512 case "2": {
1513 $resnote = $tmp[0];
1514 $restype = $tmp[1];
1515 $resdate = "";
1516 } break;
1517 case "1": {
1518 $resnote = $tmp[0];
1519 $resdate = $restype = "";
1520 } break;
1521 default: {
1522 $restype = $resdate = $resnote = "";
1523 } break;
1525 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1526 echo "<table cellpadding='0' cellspacing='0'>";
1527 echo "<tr>";
1528 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1529 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1530 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1531 if($data_type == 28)
1533 echo "<td><input type='text'" .
1534 " size='$fldlength'" .
1535 " class='under'" .
1536 " value='$resnote' /></td>";
1537 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1538 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1539 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1541 else if($data_type == 32)
1543 echo "<tr><td><input type='text'" .
1544 " size='$fldlength'" .
1545 " class='under'" .
1546 " value='$resnote' /></td></tr>";
1547 $fldlength = 30;
1548 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1549 echo "<td><input type='text'" .
1550 " size='$fldlength'" .
1551 " class='under'" .
1552 " value='$smoking_status_title' /></td>";
1553 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1555 echo "<td><input type='radio'";
1556 if ($restype == "current".$field_id) echo " checked";
1557 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1559 echo "<td><input type='radio'";
1560 if ($restype == "current".$field_id) echo " checked";
1561 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1563 echo "<td><input type='text' size='6'" .
1564 " value='$resdate'" .
1565 " class='under'" .
1566 " /></td>";
1568 echo "<td><input type='radio'";
1569 if ($restype == "current".$field_id) echo " checked";
1570 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1572 echo "<td><input type='radio'";
1573 if ($restype == "not_applicable".$field_id) echo " checked";
1574 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1575 echo "</tr>";
1576 echo "</table>";
1579 // static text. read-only, of course.
1580 else if ($data_type == 31) {
1581 echo nl2br($frow['description']);
1584 else if($data_type == 34){
1585 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;'>";
1586 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1587 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1588 echo "</a>";
1591 //facilities drop-down list
1592 else if ($data_type == 35) {
1593 if (empty($currvalue)){
1594 $currvalue = 0;
1596 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1599 //Multi-select
1600 // Supports backup lists.
1601 else if ($data_type == 36) {
1602 if (empty($fld_length)) {
1603 if ($list_id == 'titles') {
1604 $fld_length = 3;
1605 } else {
1606 $fld_length = 10;
1609 $tmp = '';
1611 $values_array = explode("|", $currvalue);
1613 $i=0;
1614 foreach($values_array as $value) {
1615 if ($value) {
1616 $lrow = sqlQuery("SELECT title FROM list_options " .
1617 "WHERE list_id = ? AND option_id = ?", array($list_id,$value));
1618 $tmp = xl_list_label($lrow['title']);
1619 if ($lrow == 0 && !empty($backup_list)) {
1620 // since primary list did not map, try to map to backup list
1621 $lrow = sqlQuery("SELECT title FROM list_options " .
1622 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1623 $tmp = xl_list_label($lrow['title']);
1625 if (empty($tmp)) $tmp = "($value)";
1628 if ($tmp === '') {
1629 $tmp = '&nbsp;';
1631 else {
1632 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1634 if ($i != 0 && $tmp != '&nbsp;') echo ",";
1635 echo $tmp;
1636 $i++;
1642 function generate_display_field($frow, $currvalue) {
1643 global $ISSUE_TYPES;
1645 $data_type = $frow['data_type'];
1646 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1647 $list_id = $frow['list_id'];
1648 $backup_list = $frow['list_backup_id'];
1650 $s = '';
1652 // generic selection list or the generic selection list with add on the fly
1653 // feature, or radio buttons
1654 // Supports backup lists for datatypes 1,26,33
1655 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1656 $lrow = sqlQuery("SELECT title FROM list_options " .
1657 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1658 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1659 //if there is no matching value in the corresponding lists check backup list
1660 // only supported in data types 1,26,33
1661 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1662 $lrow = sqlQuery("SELECT title FROM list_options " .
1663 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
1664 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1668 // simple text field
1669 else if ($data_type == 2) {
1670 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1673 // long or multi-line text field
1674 else if ($data_type == 3) {
1675 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1678 // date
1679 else if ($data_type == 4) {
1680 $s = '';
1681 $agestr = optionalAge($frow, $currvalue);
1682 if ($agestr) {
1683 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1685 if ($currvalue === '') {
1686 $s .= '&nbsp;';
1688 else {
1689 $s .= text(oeFormatShortDate($currvalue));
1691 // Optional display of age or gestational age.
1692 if ($agestr) {
1693 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1697 // provider
1698 else if ($data_type == 10 || $data_type == 11) {
1699 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1700 "WHERE id = ?", array($currvalue) );
1701 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1704 // pharmacy list
1705 else if ($data_type == 12) {
1706 $pres = get_pharmacies();
1707 while ($prow = sqlFetchArray($pres)) {
1708 $key = $prow['id'];
1709 if ($currvalue == $key) {
1710 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1711 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1712 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1717 // squads
1718 else if ($data_type == 13) {
1719 $squads = acl_get_squads();
1720 if ($squads) {
1721 foreach ($squads as $key => $value) {
1722 if ($currvalue == $key) {
1723 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1729 // address book
1730 else if ($data_type == 14) {
1731 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
1732 "WHERE id = ?", array($currvalue));
1733 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
1734 if($urow['organization'] !=""){
1735 $uname = $urow['organization'];
1736 }else{
1737 $uname = $urow['lname'];
1738 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1740 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1743 // billing code
1744 else if ($data_type == 15) {
1745 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1748 // insurance company list
1749 else if ($data_type == 16) {
1750 $insprovs = getInsuranceProviders();
1751 foreach ($insprovs as $key => $ipname) {
1752 if ($currvalue == $key) {
1753 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
1758 // issue types
1759 else if ($data_type == 17) {
1760 foreach ($ISSUE_TYPES as $key => $value) {
1761 if ($currvalue == $key) {
1762 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
1767 // visit category
1768 else if ($data_type == 18) {
1769 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1770 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1771 array($currvalue));
1772 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES);
1775 // a set of labeled checkboxes
1776 else if ($data_type == 21) {
1777 $avalue = explode('|', $currvalue);
1778 $lres = sqlStatement("SELECT * FROM list_options " .
1779 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1780 $count = 0;
1781 while ($lrow = sqlFetchArray($lres)) {
1782 $option_id = $lrow['option_id'];
1783 if (in_array($option_id, $avalue)) {
1784 if ($count++) $s .= "<br />";
1786 // Added 5-09 by BM - Translate label if applicable
1787 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES);
1793 // a set of labeled text input fields
1794 else if ($data_type == 22) {
1795 $tmp = explode('|', $currvalue);
1796 $avalue = array();
1797 foreach ($tmp as $value) {
1798 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1799 $avalue[$matches[1]] = $matches[2];
1802 $lres = sqlStatement("SELECT * FROM list_options " .
1803 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1804 $s .= "<table cellpadding='0' cellspacing='0'>";
1805 while ($lrow = sqlFetchArray($lres)) {
1806 $option_id = $lrow['option_id'];
1807 if (empty($avalue[$option_id])) continue;
1809 // Added 5-09 by BM - Translate label if applicable
1810 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1812 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1814 $s .= "</table>";
1817 // a set of exam results; 3 radio buttons and a text field:
1818 else if ($data_type == 23) {
1819 $tmp = explode('|', $currvalue);
1820 $avalue = array();
1821 foreach ($tmp as $value) {
1822 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1823 $avalue[$matches[1]] = $matches[2];
1826 $lres = sqlStatement("SELECT * FROM list_options " .
1827 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1828 $s .= "<table cellpadding='0' cellspacing='0'>";
1829 while ($lrow = sqlFetchArray($lres)) {
1830 $option_id = $lrow['option_id'];
1831 $restype = substr($avalue[$option_id], 0, 1);
1832 $resnote = substr($avalue[$option_id], 2);
1833 if (empty($restype) && empty($resnote)) continue;
1835 // Added 5-09 by BM - Translate label if applicable
1836 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1838 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1839 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1840 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1841 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1842 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1843 $s .= "</tr>";
1845 $s .= "</table>";
1848 // the list of active allergies for the current patient
1849 else if ($data_type == 24) {
1850 $query = "SELECT title, comments FROM lists WHERE " .
1851 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1852 "ORDER BY begdate";
1853 // echo "<!-- $query -->\n"; // debugging
1854 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1855 $count = 0;
1856 while ($lrow = sqlFetchArray($lres)) {
1857 if ($count++) $s .= "<br />";
1858 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1859 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1863 // a set of labeled checkboxes, each with a text field:
1864 else if ($data_type == 25) {
1865 $tmp = explode('|', $currvalue);
1866 $avalue = array();
1867 foreach ($tmp as $value) {
1868 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1869 $avalue[$matches[1]] = $matches[2];
1872 $lres = sqlStatement("SELECT * FROM list_options " .
1873 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1874 $s .= "<table cellpadding='0' cellspacing='0'>";
1875 while ($lrow = sqlFetchArray($lres)) {
1876 $option_id = $lrow['option_id'];
1877 $restype = substr($avalue[$option_id], 0, 1);
1878 $resnote = substr($avalue[$option_id], 2);
1879 if (empty($restype) && empty($resnote)) continue;
1881 // Added 5-09 by BM - Translate label if applicable
1882 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1884 $restype = $restype ? xl('Yes') : xl('No');
1885 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1886 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1887 $s .= "</tr>";
1889 $s .= "</table>";
1892 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1893 // VicarePlus :: A selection list for smoking status.
1894 else if ($data_type == 28 || $data_type == 32) {
1895 $tmp = explode('|', $currvalue);
1896 switch(count($tmp)) {
1897 case "4": {
1898 $resnote = $tmp[0];
1899 $restype = $tmp[1];
1900 $resdate = $tmp[2];
1901 $reslist = $tmp[3];
1902 } break;
1903 case "3": {
1904 $resnote = $tmp[0];
1905 $restype = $tmp[1];
1906 $resdate = $tmp[2];
1907 } break;
1908 case "2": {
1909 $resnote = $tmp[0];
1910 $restype = $tmp[1];
1911 $resdate = "";
1912 } break;
1913 case "1": {
1914 $resnote = $tmp[0];
1915 $resdate = $restype = "";
1916 } break;
1917 default: {
1918 $restype = $resdate = $resnote = "";
1919 } break;
1921 $s .= "<table cellpadding='0' cellspacing='0'>";
1923 $s .= "<tr>";
1924 $res = "";
1925 if ($restype == "current".$field_id) $res = xl('Current');
1926 if ($restype == "quit".$field_id) $res = xl('Quit');
1927 if ($restype == "never".$field_id) $res = xl('Never');
1928 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1929 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1930 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1931 if ($data_type == 28)
1933 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1935 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1936 else if ($data_type == 32)
1937 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1938 $smoke_codes = getSmokeCodes();
1939 if (!empty($reslist)) {
1940 if($smoke_codes[$reslist]!="")
1941 $code_desc = "( ".$smoke_codes[$reslist]." )";
1943 $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>";}
1945 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1948 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1949 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1950 $s .= "</tr>";
1951 $s .= "</table>";
1954 // static text. read-only, of course.
1955 else if ($data_type == 31) {
1956 $s .= nl2br($frow['description']);
1959 else if($data_type == 34){
1960 $arr = explode("|*|*|*|",$currvalue);
1961 for($i=0;$i<sizeof($arr);$i++){
1962 $s.=$arr[$i];
1966 // facility
1967 else if ($data_type == 35) {
1968 $urow = sqlQuery("SELECT id, name FROM facility ".
1969 "WHERE id = ?", array($currvalue) );
1970 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
1973 // Multi select
1974 // Supports backup lists
1975 else if ($data_type == 36) {
1976 $values_array = explode("|", $currvalue);
1978 $i = 0;
1979 foreach($values_array as $value) {
1980 $lrow = sqlQuery("SELECT title FROM list_options " .
1981 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
1983 if ($lrow == 0 && !empty($backup_list)) {
1984 //use back up list
1985 $lrow = sqlQuery("SELECT title FROM list_options " .
1986 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
1989 if ($i > 0) {
1990 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1991 } else {
1992 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1995 $i++;
1999 return $s;
2002 // Generate plain text versions of selected LBF field types.
2003 // Currently used by interface/patient_file/download_template.php.
2004 // More field types might need to be supported here in the future.
2006 function generate_plaintext_field($frow, $currvalue) {
2007 global $ISSUE_TYPES;
2009 $data_type = $frow['data_type'];
2010 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2011 $list_id = $frow['list_id'];
2012 $backup_list = $frow['backup_list'];
2013 $s = '';
2015 // generic selection list or the generic selection list with add on the fly
2016 // feature, or radio buttons
2017 // Supports backup lists (for datatypes 1,26,33)
2018 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2019 $lrow = sqlQuery("SELECT title FROM list_options " .
2020 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
2021 $s = xl_list_label($lrow['title']);
2022 //if there is no matching value in the corresponding lists check backup list
2023 // only supported in data types 1,26,33
2024 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2025 $lrow = sqlQuery("SELECT title FROM list_options " .
2026 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
2027 $s = xl_list_label($lrow['title']);
2031 // simple or long text field
2032 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2033 $s = $currvalue;
2036 // date
2037 else if ($data_type == 4) {
2038 $s = oeFormatShortDate($currvalue);
2039 // Optional display of age or gestational age.
2040 $tmp = optionalAge($frow, $currvalue);
2041 if ($tmp) $s .= ' ' . $tmp;
2044 // provider
2045 else if ($data_type == 10 || $data_type == 11) {
2046 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2047 "WHERE id = ?", array($currvalue) );
2048 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2051 // pharmacy list
2052 else if ($data_type == 12) {
2053 $pres = get_pharmacies();
2054 while ($prow = sqlFetchArray($pres)) {
2055 $key = $prow['id'];
2056 if ($currvalue == $key) {
2057 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2058 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2059 $prow['line1'] . ' / ' . $prow['city'];
2064 // address book
2065 else if ($data_type == 14) {
2066 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2067 "WHERE id = ?", array($currvalue));
2068 $uname = $urow['lname'];
2069 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2070 $s = $uname;
2073 // insurance company list
2074 else if ($data_type == 16) {
2075 $insprovs = getInsuranceProviders();
2076 foreach ($insprovs as $key => $ipname) {
2077 if ($currvalue == $key) {
2078 $s .= $ipname;
2083 // issue type
2084 else if ($data_type == 17) {
2085 foreach ($ISSUE_TYPES as $key => $value) {
2086 if ($currvalue == $key) {
2087 $s .= $value[1];
2092 // visit category
2093 else if ($data_type == 18) {
2094 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2095 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2096 array($currvalue));
2097 $s = $crow['pc_catname'];
2100 // a set of labeled checkboxes
2101 else if ($data_type == 21) {
2102 $avalue = explode('|', $currvalue);
2103 $lres = sqlStatement("SELECT * FROM list_options " .
2104 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2105 $count = 0;
2106 while ($lrow = sqlFetchArray($lres)) {
2107 $option_id = $lrow['option_id'];
2108 if (in_array($option_id, $avalue)) {
2109 if ($count++) $s .= "; ";
2110 $s .= xl_list_label($lrow['title']);
2115 // a set of labeled text input fields
2116 else if ($data_type == 22) {
2117 $tmp = explode('|', $currvalue);
2118 $avalue = array();
2119 foreach ($tmp as $value) {
2120 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2121 $avalue[$matches[1]] = $matches[2];
2124 $lres = sqlStatement("SELECT * FROM list_options " .
2125 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2126 while ($lrow = sqlFetchArray($lres)) {
2127 $option_id = $lrow['option_id'];
2128 if (empty($avalue[$option_id])) continue;
2129 if ($s !== '') $s .= '; ';
2130 $s .= xl_list_label($lrow['title']) . ': ';
2131 $s .= $avalue[$option_id];
2135 // A set of exam results; 3 radio buttons and a text field.
2136 // This shows abnormal results only.
2137 else if ($data_type == 23) {
2138 $tmp = explode('|', $currvalue);
2139 $avalue = array();
2140 foreach ($tmp as $value) {
2141 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2142 $avalue[$matches[1]] = $matches[2];
2145 $lres = sqlStatement("SELECT * FROM list_options " .
2146 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2147 while ($lrow = sqlFetchArray($lres)) {
2148 $option_id = $lrow['option_id'];
2149 $restype = substr($avalue[$option_id], 0, 1);
2150 $resnote = substr($avalue[$option_id], 2);
2151 if (empty($restype) && empty($resnote)) continue;
2152 if ($restype != '2') continue; // show abnormal results only
2153 if ($s !== '') $s .= '; ';
2154 $s .= xl_list_label($lrow['title']);
2155 if (!empty($resnote)) $s .= ': ' . $resnote;
2159 // the list of active allergies for the current patient
2160 else if ($data_type == 24) {
2161 $query = "SELECT title, comments FROM lists WHERE " .
2162 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2163 "ORDER BY begdate";
2164 $lres = sqlStatement($query, array($GLOBALS['pid']));
2165 $count = 0;
2166 while ($lrow = sqlFetchArray($lres)) {
2167 if ($count++) $s .= "; ";
2168 $s .= $lrow['title'];
2169 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2173 // a set of labeled checkboxes, each with a text field:
2174 else if ($data_type == 25) {
2175 $tmp = explode('|', $currvalue);
2176 $avalue = array();
2177 foreach ($tmp as $value) {
2178 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2179 $avalue[$matches[1]] = $matches[2];
2182 $lres = sqlStatement("SELECT * FROM list_options " .
2183 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2184 while ($lrow = sqlFetchArray($lres)) {
2185 $option_id = $lrow['option_id'];
2186 $restype = substr($avalue[$option_id], 0, 1);
2187 $resnote = substr($avalue[$option_id], 2);
2188 if (empty($restype) && empty($resnote)) continue;
2189 if ($s !== '') $s .= '; ';
2190 $s .= xl_list_label($lrow['title']);
2191 $restype = $restype ? xl('Yes') : xl('No');
2192 $s .= $restype;
2193 if ($resnote) $s .= ' ' . $resnote;
2197 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2198 // VicarePlus :: A selection list for smoking status.
2199 else if ($data_type == 28 || $data_type == 32) {
2200 $tmp = explode('|', $currvalue);
2201 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2202 $restype = count($tmp) > 1 ? $tmp[1] : '';
2203 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2204 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2205 $res = "";
2206 if ($restype == "current" . $field_id) $res = xl('Current');
2207 if ($restype == "quit" . $field_id) $res = xl('Quit');
2208 if ($restype == "never" . $field_id) $res = xl('Never');
2209 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2211 if ($data_type == 28) {
2212 if (!empty($resnote)) $s .= $resnote;
2214 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2215 else if ($data_type == 32) {
2216 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2217 if (!empty($resnote)) $s .= ' ' . $resnote;
2219 if (!empty($res)) {
2220 if ($s !== '') $s .= ' ';
2221 $s .= xl('Status') . ' ' . $res;
2223 if ($restype == "quit".$field_id) {
2224 if ($s !== '') $s .= ' ';
2225 $s .= $resdate;
2229 // Multi select
2230 // Supports backup lists
2231 else if ($data_type == 36) {
2232 $values_array = explode("|", $currvalue);
2234 $i = 0;
2235 foreach($values_array as $value) {
2236 $lrow = sqlQuery("SELECT title FROM list_options " .
2237 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
2239 if ($lrow == 0 && !empty($backup_list)) {
2240 //use back up list
2241 $lrow = sqlQuery("SELECT title FROM list_options " .
2242 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
2245 if ($i > 0) {
2246 $s = $s . ", " . xl_list_label($lrow['title']);
2247 } else {
2248 $s = xl_list_label($lrow['title']);
2251 $i++;
2255 return $s;
2258 $CPR = 4; // cells per row of generic data
2259 $last_group = '';
2260 $cell_count = 0;
2261 $item_count = 0;
2263 function disp_end_cell() {
2264 global $item_count, $cell_count;
2265 if ($item_count > 0) {
2266 echo "</td>";
2267 $item_count = 0;
2271 function disp_end_row() {
2272 global $cell_count, $CPR;
2273 disp_end_cell();
2274 if ($cell_count > 0) {
2275 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
2276 echo "</tr>\n";
2277 $cell_count = 0;
2281 function disp_end_group() {
2282 global $last_group;
2283 if (strlen($last_group) > 0) {
2284 disp_end_row();
2288 function display_layout_rows($formtype, $result1, $result2='') {
2289 global $item_count, $cell_count, $last_group, $CPR;
2291 $fres = sqlStatement("SELECT * FROM layout_options " .
2292 "WHERE form_id = ? AND uor > 0 " .
2293 "ORDER BY group_name, seq", array($formtype) );
2295 while ($frow = sqlFetchArray($fres)) {
2296 $this_group = $frow['group_name'];
2297 $titlecols = $frow['titlecols'];
2298 $datacols = $frow['datacols'];
2299 $data_type = $frow['data_type'];
2300 $field_id = $frow['field_id'];
2301 $list_id = $frow['list_id'];
2302 $currvalue = '';
2304 if ($formtype == 'DEM') {
2305 if ($GLOBALS['athletic_team']) {
2306 // Skip fitness level and return-to-play date because those appear
2307 // in a special display/update form on this page.
2308 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2310 if (strpos($field_id, 'em_') === 0) {
2311 // Skip employer related fields, if it's disabled.
2312 if ($GLOBALS['omit_employers']) continue;
2313 $tmp = substr($field_id, 3);
2314 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2316 else {
2317 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2320 else {
2321 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2324 // Handle a data category (group) change.
2325 if (strcmp($this_group, $last_group) != 0) {
2326 $group_name = substr($this_group, 1);
2327 // totally skip generating the employer category, if it's disabled.
2328 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2329 disp_end_group();
2330 $last_group = $this_group;
2333 // filter out all the empty field data from the patient report.
2334 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2335 // Handle starting of a new row.
2336 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2337 disp_end_row();
2338 echo "<tr>";
2339 if ($group_name) {
2340 echo "<td class='groupname'>";
2341 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2342 //echo "<font color='#008800'>$group_name</font>";
2344 // Added 5-09 by BM - Translate label if applicable
2345 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
2347 $group_name = '';
2348 } else {
2349 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2350 echo "<td valign='top'>&nbsp;";
2352 echo "</td>";
2355 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2357 // Handle starting of a new label cell.
2358 if ($titlecols > 0) {
2359 disp_end_cell();
2360 //echo "<td class='label' colspan='$titlecols' valign='top'";
2361 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2362 echo "<td class='label' colspan='$titlecols_esc' ";
2363 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2364 echo ">";
2365 $cell_count += $titlecols;
2367 ++$item_count;
2369 // Added 5-09 by BM - Translate label if applicable
2370 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2372 // Handle starting of a new data cell.
2373 if ($datacols > 0) {
2374 disp_end_cell();
2375 //echo "<td class='text data' colspan='$datacols' valign='top'";
2376 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2377 echo "<td class='text data' colspan='$datacols_esc'";
2378 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2379 echo ">";
2380 $cell_count += $datacols;
2383 ++$item_count;
2384 echo generate_display_field($frow, $currvalue);
2388 disp_end_group();
2391 function display_layout_tabs($formtype, $result1, $result2='') {
2392 global $item_count, $cell_count, $last_group, $CPR;
2394 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2395 "WHERE form_id = ? AND uor > 0 " .
2396 "ORDER BY group_name, seq", array($formtype) );
2398 $first = true;
2399 while ($frow = sqlFetchArray($fres)) {
2400 $this_group = $frow['group_name'];
2401 $group_name = substr($this_group, 1);
2402 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2404 <li <?php echo $first ? 'class="current"' : '' ?>>
2405 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
2406 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
2407 </li>
2408 <?php
2409 $first = false;
2413 function display_layout_tabs_data($formtype, $result1, $result2='') {
2414 global $item_count, $cell_count, $last_group, $CPR;
2416 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2417 "WHERE form_id = ? AND uor > 0 " .
2418 "ORDER BY group_name, seq", array($formtype));
2420 $first = true;
2421 while ($frow = sqlFetchArray($fres)) {
2422 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
2423 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
2424 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
2425 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
2426 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
2427 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
2428 $currvalue = '';
2430 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2432 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2433 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2434 "ORDER BY seq", array($formtype, $this_group) );
2437 <div class="tab <?php echo $first ? 'current' : '' ?>">
2438 <table border='0' cellpadding='0'>
2440 <?php
2441 while ($group_fields = sqlFetchArray($group_fields_query)) {
2443 $titlecols = $group_fields['titlecols'];
2444 $datacols = $group_fields['datacols'];
2445 $data_type = $group_fields['data_type'];
2446 $field_id = $group_fields['field_id'];
2447 $list_id = $group_fields['list_id'];
2448 $currvalue = '';
2450 if ($formtype == 'DEM') {
2451 if ($GLOBALS['athletic_team']) {
2452 // Skip fitness level and return-to-play date because those appear
2453 // in a special display/update form on this page.
2454 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2456 if (strpos($field_id, 'em_') === 0) {
2457 // Skip employer related fields, if it's disabled.
2458 if ($GLOBALS['omit_employers']) continue;
2459 $tmp = substr($field_id, 3);
2460 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2462 else {
2463 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2466 else {
2467 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2470 // Handle a data category (group) change.
2471 if (strcmp($this_group, $last_group) != 0) {
2472 $group_name = substr($this_group, 1);
2473 // totally skip generating the employer category, if it's disabled.
2474 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2475 $last_group = $this_group;
2478 // Handle starting of a new row.
2479 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2480 disp_end_row();
2481 echo "<tr>";
2484 if ($item_count == 0 && $titlecols == 0) {
2485 $titlecols = 1;
2488 // Handle starting of a new label cell.
2489 if ($titlecols > 0) {
2490 disp_end_cell();
2491 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2492 echo "<td class='label' colspan='$titlecols_esc' ";
2493 echo ">";
2494 $cell_count += $titlecols;
2496 ++$item_count;
2498 // Added 5-09 by BM - Translate label if applicable
2499 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2501 // Handle starting of a new data cell.
2502 if ($datacols > 0) {
2503 disp_end_cell();
2504 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2505 echo "<td class='text data' colspan='$datacols_esc'";
2506 echo ">";
2507 $cell_count += $datacols;
2510 ++$item_count;
2511 echo generate_display_field($group_fields, $currvalue);
2514 disp_end_row();
2517 </table>
2518 </div>
2520 <?php
2522 $first = false;
2528 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2529 global $item_count, $cell_count, $last_group, $CPR;
2531 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2532 "WHERE form_id = ? AND uor > 0 " .
2533 "ORDER BY group_name, seq", array($formtype) );
2535 $first = true;
2536 while ($frow = sqlFetchArray($fres)) {
2537 $this_group = $frow['group_name'];
2538 $group_name = substr($this_group, 1);
2539 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
2540 $titlecols = $frow['titlecols'];
2541 $datacols = $frow['datacols'];
2542 $data_type = $frow['data_type'];
2543 $field_id = $frow['field_id'];
2544 $list_id = $frow['list_id'];
2545 $currvalue = '';
2547 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2549 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2550 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2551 "ORDER BY seq", array($formtype,$this_group) );
2554 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
2555 <table border='0' cellpadding='0'>
2557 <?php
2558 while ($group_fields = sqlFetchArray($group_fields_query)) {
2560 $titlecols = $group_fields['titlecols'];
2561 $datacols = $group_fields['datacols'];
2562 $data_type = $group_fields['data_type'];
2563 $field_id = $group_fields['field_id'];
2564 $list_id = $group_fields['list_id'];
2565 $backup_list = $group_fields['list_backup_id'];
2566 $currvalue = '';
2568 if ($formtype == 'DEM') {
2569 if ($GLOBALS['athletic_team']) {
2570 // Skip fitness level and return-to-play date because those appear
2571 // in a special display/update form on this page.
2572 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2574 if (strpos($field_id, 'em_') === 0) {
2575 // Skip employer related fields, if it's disabled.
2576 if ($GLOBALS['omit_employers']) continue;
2577 $tmp = substr($field_id, 3);
2578 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2580 else {
2581 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2584 else {
2585 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2588 // Handle a data category (group) change.
2589 if (strcmp($this_group, $last_group) != 0) {
2590 $group_name = substr($this_group, 1);
2591 // totally skip generating the employer category, if it's disabled.
2592 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2593 $last_group = $this_group;
2596 // Handle starting of a new row.
2597 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2598 disp_end_row();
2599 echo "<tr>";
2602 if ($item_count == 0 && $titlecols == 0) {
2603 $titlecols = 1;
2606 // Handle starting of a new label cell.
2607 if ($titlecols > 0) {
2608 disp_end_cell();
2609 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2610 echo "<td class='label' colspan='$titlecols_esc' ";
2611 echo ">";
2612 $cell_count += $titlecols;
2614 ++$item_count;
2616 // Added 5-09 by BM - Translate label if applicable
2617 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
2619 // Handle starting of a new data cell.
2620 if ($datacols > 0) {
2621 disp_end_cell();
2622 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2623 echo "<td class='text data' colspan='$datacols_esc'";
2624 echo ">";
2625 $cell_count += $datacols;
2628 ++$item_count;
2630 echo generate_form_field($group_fields, $currvalue);
2634 </table>
2635 </div>
2637 <?php
2639 $first = false;
2644 // From the currently posted HTML form, this gets the value of the
2645 // field corresponding to the provided layout_options table row.
2647 function get_layout_form_value($frow, $prefix='form_') {
2648 // Bring in $sanitize_all_escapes variable, which will decide
2649 // the variable escaping method.
2650 global $sanitize_all_escapes;
2652 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
2653 $data_type = $frow['data_type'];
2654 $field_id = $frow['field_id'];
2655 $value = '';
2656 if (isset($_POST["$prefix$field_id"])) {
2657 if ($data_type == 21) {
2658 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2659 // must be concatenated into a |-separated string.
2660 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2661 if (strlen($value)) $value .= '|';
2662 $value .= $key;
2665 else if ($data_type == 22) {
2666 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2667 // into "key:value|key:value|...".
2668 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2669 $val = str_replace('|', ' ', $val);
2670 if (strlen($value)) $value .= '|';
2671 $value .= "$key:$val";
2674 else if ($data_type == 23) {
2675 // $_POST["$prefix$field_id"] is an array of text fields with companion
2676 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2677 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2678 $restype = $_POST["radio_{$field_id}"][$key];
2679 if (empty($restype)) $restype = '0';
2680 $val = str_replace('|', ' ', $val);
2681 if (strlen($value)) $value .= '|';
2682 $value .= "$key:$restype:$val";
2685 else if ($data_type == 25) {
2686 // $_POST["$prefix$field_id"] is an array of text fields with companion
2687 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2688 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2689 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
2690 $val = str_replace('|', ' ', $val);
2691 if (strlen($value)) $value .= '|';
2692 $value .= "$key:$restype:$val";
2695 else if ($data_type == 28 || $data_type == 32) {
2696 // $_POST["$prefix$field_id"] is an date text fields with companion
2697 // radio buttons to be imploded into "notes|type|date".
2698 $restype = $_POST["radio_{$field_id}"];
2699 if (empty($restype)) $restype = '0';
2700 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2701 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2702 if ($data_type == 32)
2704 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2705 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2706 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2707 $value = "$res_text_note|$restype|$resdate|$reslist";
2709 else
2710 $value = "$resnote|$restype|$resdate";
2712 else if ($data_type == 36) {
2713 $value_array = $_POST["form_$field_id"];
2714 $i = 0;
2715 foreach ($value_array as $key => $valueofkey) {
2716 if ($i == 0) {
2717 $value = $valueofkey;
2718 } else {
2719 $value = $value . "|" . $valueofkey;
2721 $i++;
2724 else {
2725 $value = $_POST["$prefix$field_id"];
2729 // Better to die than to silently truncate data!
2730 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2731 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2732 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2734 // Make sure the return value is quote-safe.
2735 if ($sanitize_all_escapes) {
2736 //escapes already removed and using binding/placemarks in sql calls
2737 // so only need to trim value
2738 return trim($value);
2740 else {
2741 //need to explicitly prepare value
2742 return formTrim($value);
2746 // Generate JavaScript validation logic for the required fields.
2748 function generate_layout_validation($form_id) {
2749 $fres = sqlStatement("SELECT * FROM layout_options " .
2750 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2751 "ORDER BY group_name, seq", array($form_id) );
2753 while ($frow = sqlFetchArray($fres)) {
2754 if ($frow['uor'] < 2) continue;
2755 $data_type = $frow['data_type'];
2756 $field_id = $frow['field_id'];
2757 $fldtitle = $frow['title'];
2758 if (!$fldtitle) $fldtitle = $frow['description'];
2759 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
2760 switch($data_type) {
2761 case 1:
2762 case 11:
2763 case 12:
2764 case 13:
2765 case 14:
2766 case 26:
2767 case 33:
2768 echo
2769 " if (f.$fldname.selectedIndex <= 0) {\n" .
2770 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2771 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2772 " }\n";
2773 break;
2774 case 27: // radio buttons
2775 echo
2776 " var i = 0;\n" .
2777 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2778 " if (i >= f.$fldname.length) {\n" .
2779 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2780 " }\n";
2781 break;
2782 case 2:
2783 case 3:
2784 case 4:
2785 case 15:
2786 echo
2787 " if (trimlen(f.$fldname.value) == 0) {\n" .
2788 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2789 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2790 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2791 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2792 " } else { " .
2793 " $('#" . $fldname . "').attr('style',''); " .
2794 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2795 " } \n";
2796 break;
2797 case 36: // multi select
2798 echo
2799 " var multi_select=f['$fldname"."[]']; \n " .
2800 " var multi_choice_made=false; \n".
2801 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
2802 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
2803 " } \n" .
2804 " if(!multi_choice_made)
2805 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2807 break;
2813 * DROPDOWN FOR FACILITIES
2815 * build a dropdown with all facilities
2817 * @param string $selected - name of the currently selected facility
2818 * use '0' for "unspecified facility"
2819 * use '' for "All facilities" (the default)
2820 * @param string $name - the name/id for select form (defaults to "form_facility")
2821 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2822 * defaults to true
2823 * @return void - just echo the html encoded string
2825 * Note: This should become a data-type at some point, according to Brady
2827 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2828 $allow_allfacilities = true, $disabled='', $onchange='')
2830 $have_selected = false;
2831 $query = "SELECT id, name FROM facility ORDER BY name";
2832 $fres = sqlStatement($query);
2834 $name = htmlspecialchars($name, ENT_QUOTES);
2835 echo " <select name='$name' id='$name'";
2836 if ($onchange) echo " onchange='$onchange'";
2837 echo " $disabled>\n";
2839 if ($allow_allfacilities) {
2840 $option_value = '';
2841 $option_selected_attr = '';
2842 if ($selected == '') {
2843 $option_selected_attr = ' selected="selected"';
2844 $have_selected = true;
2846 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2847 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2848 } elseif ($allow_unspecified) {
2849 $option_value = '0';
2850 $option_selected_attr = '';
2851 if ( $selected == '0' ) {
2852 $option_selected_attr = ' selected="selected"';
2853 $have_selected = true;
2855 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2856 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2859 while ($frow = sqlFetchArray($fres)) {
2860 $facility_id = $frow['id'];
2861 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2862 $option_selected_attr = '';
2863 if ($selected == $facility_id) {
2864 $option_selected_attr = ' selected="selected"';
2865 $have_selected = true;
2867 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2868 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2871 if ($allow_unspecified && $allow_allfacilities) {
2872 $option_value = '0';
2873 $option_selected_attr = '';
2874 if ( $selected == '0' ) {
2875 $option_selected_attr = ' selected="selected"';
2876 $have_selected = true;
2878 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2879 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2882 if (!$have_selected) {
2883 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2884 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2885 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2886 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2888 echo " </select>\n";
2891 // Expand Collapse Widget
2892 // This forms the header and functionality component of the widget. The information that is displayed
2893 // then follows this function followed by a closing div tag
2895 // $title is the title of the section (already translated)
2896 // $label is identifier used in the tag id's and sql columns
2897 // $buttonLabel is the button label text (already translated)
2898 // $buttonLink is the button link information
2899 // $buttonClass is any additional needed class elements for the button tag
2900 // $linkMethod is the button link method ('javascript' vs 'html')
2901 // $bodyClass is to set class(es) of the body
2902 // $auth is a flag to decide whether to show the button
2903 // $fixedWidth is to flag whether width is fixed
2904 // $forceExpandAlways is a flag to force the widget to always be expanded
2906 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2907 if ($fixedWidth) {
2908 echo "<div class='section-header'>";
2910 else {
2911 echo "<div class='section-header-dynamic'>";
2913 echo "<table><tr>";
2914 if ($auth) {
2915 // show button, since authorized
2916 // first prepare class string
2917 if ($buttonClass) {
2918 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2920 else {
2921 $class_string = "css_button_small";
2923 // next, create the link
2924 if ($linkMethod == "javascript") {
2925 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2927 else {
2928 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2929 if (!isset($_SESSION['patient_portal_onsite'])) {
2930 // prevent an error from occuring when calling the function from the patient portal
2931 echo " onclick='top.restoreSession()'";
2934 if (!$GLOBALS['concurrent_layout']) {
2935 echo " target='Main'";
2937 echo "><span>" .
2938 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2940 if ($forceExpandAlways){
2941 // Special case to force the widget to always be expanded
2942 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2943 $indicatorTag ="style='display:none'";
2945 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
2946 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2947 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
2948 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2950 if (isset($_SESSION['patient_portal_onsite'])) {
2951 // collapse all entries in the patient portal
2952 $text = xl('expand');
2954 else if (getUserSetting($label."_ps_expand")) {
2955 $text = xl('collapse');
2957 else {
2958 $text = xl('expand');
2960 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
2961 "</span>)</a></td>";
2962 echo "</tr></table>";
2963 echo "</div>";
2964 if ($forceExpandAlways) {
2965 // Special case to force the widget to always be expanded
2966 $styling = "";
2968 else if (isset($_SESSION['patient_portal_onsite'])) {
2969 // collapse all entries in the patient portal
2970 $styling = "style='display:none'";
2972 else if (getUserSetting($label."_ps_expand")) {
2973 $styling = "";
2975 else {
2976 $styling = "style='display:none'";
2978 if ($bodyClass) {
2979 $styling .= " class='" . $bodyClass . "'";
2981 //next, create the first div tag to hold the information
2982 // note the code that calls this function will then place the ending div tag after the data
2983 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
2986 //billing_facility fuction will give the dropdown list which contain billing faciliies.
2987 function billing_facility($name,$select){
2988 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
2989 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
2990 while ($facrow = sqlFetchArray($qsql)) {
2991 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
2992 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
2994 echo "</select>";
2997 // Generic function to get the translated title value for a particular list option.
2999 function getListItemTitle($list, $option) {
3000 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3001 "list_id = ? AND option_id = ?", array($list, $option));
3002 if (empty($row['title'])) return $option;
3003 return xl_list_label($row['title']);
3005 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3006 function getSmokeCodes()
3008 $smoking_codes_arr = array();
3009 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status'");
3010 while($codes_row = sqlFetchArray($smoking_codes))
3012 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3014 return $smoking_codes_arr;
3017 // Get the current value for a layout based form field.
3018 // Depending on options this might come from lbf_data, patient_data,
3019 // form_encounter, shared_attributes or elsewhere.
3020 // Returns FALSE if the field ID is invalid (layout error).
3022 function lbf_current_value($frow, $formid, $encounter) {
3023 global $pid;
3024 $formname = $frow['form_id'];
3025 $field_id = $frow['field_id'];
3026 $source = $frow['source'];
3027 $currvalue = '';
3028 $deffname = $formname . '_default_' . $field_id;
3029 if ($source == 'D' || $source == 'H') {
3030 // Get from patient_data, employer_data or history_data.
3031 if ($source == 'H') {
3032 $table = 'history_data';
3033 $orderby = 'ORDER BY date DESC LIMIT 1';
3035 else if (strpos($field_id, 'em_') === 0) {
3036 $field_id = substr($field_id, 3);
3037 $table = 'employer_data';
3038 $orderby = 'ORDER BY date DESC LIMIT 1';
3040 else {
3041 $table = 'patient_data';
3042 $orderby = '';
3044 // It is an error if the field does not exist, but don't crash.
3045 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3046 if (empty($tmp)) return FALSE;
3047 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3048 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3050 else if ($source == 'E') {
3051 if ($encounter) {
3052 // Get value from shared_attributes of the current encounter.
3053 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3054 "pid = ? AND encounter = ? AND field_id = ?",
3055 array($pid, $encounter, $field_id));
3056 if (isset($sarow)) $currvalue = $sarow['field_value'];
3058 else if ($formid) {
3059 // Get from shared_attributes of the encounter that this form is linked to.
3060 // Note the importance of having an index on forms.form_id.
3061 $sarow = sqlQuery("SELECT sa.field_value " .
3062 "FROM forms AS f, shared_attributes AS sa WHERE " .
3063 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3064 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3065 array($formid, $formname, $field_id));
3066 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3068 else {
3069 // New form and encounter not available, this should not happen.
3072 else if ($source == 'V') {
3073 if ($encounter) {
3074 // Get value from the current encounter's form_encounter.
3075 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3076 "pid = ? AND encounter = ?",
3077 array($pid, $encounter));
3078 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3080 else if ($formid) {
3081 // Get value from the form_encounter that this form is linked to.
3082 $ferow = sqlQuery("SELECT fe.* " .
3083 "FROM forms AS f, form_encounter AS fe WHERE " .
3084 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3085 "fe.pid = f.pid AND fe.encounter = f.encounter",
3086 array($formid, $formname));
3087 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3089 else {
3090 // New form and encounter not available, this should not happen.
3093 else if ($formid) {
3094 // This is a normal form field.
3095 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3096 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3097 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3099 else {
3100 // New form, see if there is a custom default from a plugin.
3101 // This logic does not apply to shared attributes because they do not
3102 // have a "new form" concept.
3103 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3105 return $currvalue;