Converted deleter.php to standard security model, take 2.
[openemr.git] / library / options.inc.php
blobb359d92e230d4752c308b64fe1decae1cb4d1a12
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,$condition_str;
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'];
226 $condition_str = get_conditions_str($condition_str,$frow);
228 // escaped variables to use in html
229 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
230 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
232 // Added 5-09 by BM - Translate description if applicable
233 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
235 // Support edit option T which assigns the (possibly very long) description as
236 // the default value.
237 if (strpos($frow['edit_options'], 'T') !== FALSE) {
238 if (strlen($currescaped) == 0) $currescaped = $description;
239 // Description used in this way is not suitable as a title.
240 $description = '';
243 // added 5-2009 by BM to allow modification of the 'empty' text title field.
244 // Can pass $frow['empty_title'] with this variable, otherwise
245 // will default to 'Unassigned'.
246 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
247 // if make $frow['empty_title'] equal to 'SKIP'
248 $showEmpty = true;
249 if (isset($frow['empty_title'])) {
250 if ($frow['empty_title'] == "SKIP") {
251 //do not display an 'empty' choice
252 $showEmpty = false;
253 $empty_title = "Unassigned";
255 else {
256 $empty_title = $frow['empty_title'];
259 else {
260 $empty_title = "Unassigned";
263 $disabled = strpos($frow['edit_options'], '0') === FALSE ? '' : 'disabled';
265 $lbfchange = (strpos($frow['form_id'], 'LBF') === 0 || strpos($frow['form_id'], 'LBT') === 0) ?
266 "checkSkipConditions();" : "";
267 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
269 // generic single-selection list or Race and Ethnicity.
270 // These data types support backup lists.
271 if ($data_type == 1 || $data_type == 33) {
272 echo generate_select_list("form_$field_id", $list_id, $currvalue,
273 $description, ($showEmpty ? $empty_title : ''), '', $lbfchange, '',
274 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
277 // simple text field
278 else if ($data_type == 2) {
279 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
280 $maxlength = $frow['max_length'];
281 $string_maxlength = "";
282 // if max_length is set to zero, then do not set a maxlength
283 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
284 echo "<input type='text'" .
285 " name='form_$field_id_esc'" .
286 " id='form_$field_id_esc'" .
287 " size='$fldlength'" .
288 " $string_maxlength" .
289 " title='$description'" .
290 " value='$currescaped'";
291 $tmp = $lbfchange;
292 if (strpos($frow['edit_options'], 'C') !== FALSE)
293 $tmp .= "capitalizeMe(this);";
294 else if (strpos($frow['edit_options'], 'U') !== FALSE)
295 $tmp .= "this.value = this.value.toUpperCase();";
296 if ($tmp) echo " onchange='$tmp'";
297 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
298 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
299 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
300 echo " onblur='maskblur(this,\"$tmp\")'";
302 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
303 echo " readonly";
305 if ($disabled) echo ' disabled';
306 echo " />";
309 // long or multi-line text field
310 else if ($data_type == 3) {
311 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
312 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
313 echo "<textarea" .
314 " name='form_$field_id_esc'" .
315 " id='form_$field_id_esc'" .
316 " title='$description'" .
317 " cols='$textCols'" .
318 " rows='$textRows' $lbfonchange $disabled" .
319 ">" . $currescaped . "</textarea>";
322 // date
323 else if ($data_type == 4) {
324 $age_asof_date = ''; // optionalAge() sets this
325 $age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0;
326 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
327 if ($agestr) {
328 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
330 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
331 " value='" . substr($currescaped, 0, 10) . "'";
332 if (!$agestr) echo " title='$description'";
333 echo " $lbfonchange onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
334 if (!$disabled) {
335 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
336 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
337 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
338 $date_init .= " Calendar.setup({" .
339 "inputField:'form_$field_id', " .
340 "ifFormat:'%Y-%m-%d', ";
341 if ($agestr) {
342 $date_init .= "onUpdate: function() {" .
343 "if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format);" .
344 "}, ";
346 $date_init .= "button:'img_$field_id'})\n";
348 // Optional display of age or gestational age.
349 if ($agestr) {
350 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
354 // provider list, local providers only
355 else if ($data_type == 10) {
356 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
357 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
358 "AND authorized = 1 " .
359 "ORDER BY lname, fname");
360 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled>";
361 echo "<option value=''>" . xlt($empty_title) . "</option>";
362 $got_selected = false;
363 while ($urow = sqlFetchArray($ures)) {
364 $uname = text($urow['fname'] . ' ' . $urow['lname']);
365 $optionId = attr($urow['id']);
366 echo "<option value='$optionId'";
367 if ($urow['id'] == $currvalue) {
368 echo " selected";
369 $got_selected = true;
371 echo ">$uname</option>";
373 if (!$got_selected && $currvalue) {
374 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
375 echo "</select>";
376 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
378 else {
379 echo "</select>";
383 // provider list, including address book entries with an NPI number
384 else if ($data_type == 11) {
385 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
386 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
387 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
388 "ORDER BY lname, fname");
389 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
390 echo " $lbfonchange $disabled>";
391 echo "<option value=''>" . xlt('Unassigned') . "</option>";
392 $got_selected = false;
393 while ($urow = sqlFetchArray($ures)) {
394 $uname = text($urow['fname'] . ' ' . $urow['lname']);
395 $optionId = attr($urow['id']);
396 echo "<option value='$optionId'";
397 if ($urow['id'] == $currvalue) {
398 echo " selected";
399 $got_selected = true;
401 echo ">$uname</option>";
403 if (!$got_selected && $currvalue) {
404 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
405 echo "</select>";
406 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
408 else {
409 echo "</select>";
413 // pharmacy list
414 else if ($data_type == 12) {
415 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
416 echo " $lbfonchange $disabled>";
417 echo "<option value='0'></option>";
418 $pres = get_pharmacies();
419 $got_selected = false;
420 while ($prow = sqlFetchArray($pres)) {
421 $key = $prow['id'];
422 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
423 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
424 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
425 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
426 echo "<option value='$optionValue'";
427 if ($currvalue == $key) {
428 echo " selected";
429 $got_selected = true;
431 echo ">$optionLabel</option>";
433 if (!$got_selected && $currvalue) {
434 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
435 echo "</select>";
436 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
438 else {
439 echo "</select>";
443 // squads
444 else if ($data_type == 13) {
445 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
446 echo " $lbfonchange $disabled>";
447 echo "<option value=''>&nbsp;</option>";
448 $squads = acl_get_squads();
449 if ($squads) {
450 foreach ($squads as $key => $value) {
451 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
452 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
453 echo "<option value='$optionValue'";
454 if ($currvalue == $key) echo " selected";
455 echo ">$optionLabel</option>\n";
458 echo "</select>";
461 // Address book, preferring organization name if it exists and is not in
462 // parentheses, and excluding local users who are not providers.
463 // Supports "referred to" practitioners and facilities.
464 // Alternatively the letter L in edit_options means that abook_type
465 // must be "ord_lab", indicating types used with the procedure
466 // lab ordering system.
467 // Alternatively the letter O in edit_options means that abook_type
468 // must begin with "ord_", indicating types used with the procedure
469 // ordering system.
470 // Alternatively the letter V in edit_options means that abook_type
471 // must be "vendor", indicating the Vendor type.
472 // Alternatively the letter R in edit_options means that abook_type
473 // must be "dist", indicating the Distributor type.
474 else if ($data_type == 14) {
475 if (strpos($frow['edit_options'], 'L') !== FALSE)
476 $tmp = "abook_type = 'ord_lab'";
477 else if (strpos($frow['edit_options'], 'O') !== FALSE)
478 $tmp = "abook_type LIKE 'ord\\_%'";
479 else if (strpos($frow['edit_options'], 'V') !== FALSE)
480 $tmp = "abook_type LIKE 'vendor%'";
481 else if (strpos($frow['edit_options'], 'R') !== FALSE)
482 $tmp = "abook_type LIKE 'dist'";
483 else
484 $tmp = "( username = '' OR authorized = 1 )";
485 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
486 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
487 "AND $tmp " .
488 "ORDER BY organization, lname, fname");
489 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
490 echo " $lbfonchange $disabled>";
491 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
492 while ($urow = sqlFetchArray($ures)) {
493 $uname = $urow['organization'];
494 if (empty($uname) || substr($uname, 0, 1) == '(') {
495 $uname = $urow['lname'];
496 if ($urow['fname']) $uname .= ", " . $urow['fname'];
498 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
499 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
500 echo "<option value='$optionValue'";
501 $title = $urow['username'] ? xl('Local') : xl('External');
502 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
503 echo " title='$optionTitle'";
504 if ($urow['id'] == $currvalue) echo " selected";
505 echo ">$optionLabel</option>";
507 echo "</select>";
510 // A billing code. If description matches an existing code type then that type is used.
511 else if ($data_type == 15) {
512 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
513 $maxlength = $frow['max_length'];
514 $string_maxlength = "";
515 // if max_length is set to zero, then do not set a maxlength
516 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
518 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
519 // Option "2" generates a hidden input for the codes, and a matching visible field
520 // displaying their descriptions. First step is computing the description string.
521 $currdescstring = '';
522 if (!empty($currvalue)) {
523 $relcodes = explode(';', $currvalue);
524 foreach ($relcodes as $codestring) {
525 if ($codestring === '') continue;
526 $code_text = lookup_code_descriptions($codestring);
527 if ($currdescstring !== '') $currdescstring .= '; ';
528 if (!empty($code_text)) {
529 $currdescstring .= $code_text;
531 else {
532 $currdescstring .= $codestring;
536 $currdescstring = attr($currdescstring);
538 echo "<input type='text'" .
539 " name='form_$field_id_esc'" .
540 " id='form_related_code'" .
541 " size='$fldlength'" .
542 " value='$currescaped'" .
543 " style='display:none'" .
544 " $lbfonchange readonly $disabled />";
545 // Extra readonly input field for optional display of code description(s).
546 echo "<input type='text'" .
547 " name='form_$field_id_esc" . "__desc'" .
548 " size='$fldlength'" .
549 " title='$description'" .
550 " value='$currdescstring'";
551 if (!$disabled) {
552 echo " onclick='sel_related(this,\"$codetype\")'";
554 echo " readonly $disabled />";
556 else {
557 echo "<input type='text'" .
558 " name='form_$field_id_esc'" .
559 " id='form_related_code'" .
560 " size='$fldlength'" .
561 " $string_maxlength" .
562 " title='$description'" .
563 " value='$currescaped'";
564 if (!$disabled) {
565 echo " onclick='sel_related(this,\"$codetype\")'";
567 echo " $lbfonchange readonly $disabled />";
571 // insurance company list
572 else if ($data_type == 16) {
573 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
574 echo "<option value='0'></option>";
575 $insprovs = getInsuranceProviders();
576 $got_selected = false;
577 foreach ($insprovs as $key => $ipname) {
578 $optionValue = htmlspecialchars($key, ENT_QUOTES);
579 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
580 echo "<option value='$optionValue'";
581 if ($currvalue == $key) {
582 echo " selected";
583 $got_selected = true;
585 echo ">$optionLabel</option>";
587 if (!$got_selected && $currvalue) {
588 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
589 echo "</select>";
590 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
592 else {
593 echo "</select>";
597 // issue types
598 else if ($data_type == 17) {
599 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
600 echo "<option value='0'></option>";
601 $got_selected = false;
602 foreach ($ISSUE_TYPES as $key => $value) {
603 $optionValue = htmlspecialchars($key, ENT_QUOTES);
604 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
605 echo "<option value='$optionValue'";
606 if ($currvalue == $key) {
607 echo " selected";
608 $got_selected = true;
610 echo ">$optionLabel</option>";
612 if (!$got_selected && strlen($currvalue) > 0) {
613 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
614 echo "</select>";
615 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
617 else {
618 echo "</select>";
622 // Visit categories.
623 else if ($data_type == 18) {
624 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
625 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
626 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
627 " $lbfonchange $disabled>";
628 echo "<option value=''>" . xlt($empty_title) . "</option>";
629 $got_selected = false;
630 while ($crow = sqlFetchArray($cres)) {
631 $catid = $crow['pc_catid'];
632 if (($catid < 9 && $catid != 5) || $catid == 11) continue;
633 echo "<option value='" . attr($catid) . "'";
634 if ($catid == $currvalue) {
635 echo " selected";
636 $got_selected = true;
638 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
640 if (!$got_selected && $currvalue) {
641 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
642 echo "</select>";
643 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
645 else {
646 echo "</select>";
650 // a set of labeled checkboxes
651 else if ($data_type == 21) {
652 // In this special case, fld_length is the number of columns generated.
653 $cols = max(1, $frow['fld_length']);
654 $avalue = explode('|', $currvalue);
655 $lres = sqlStatement("SELECT * FROM list_options " .
656 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
657 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
658 $tdpct = (int) (100 / $cols);
659 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
660 $option_id = $lrow['option_id'];
661 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
662 // if ($count) echo "<br />";
663 if ($count % $cols == 0) {
664 if ($count) echo "</tr>";
665 echo "<tr>";
667 echo "<td width='$tdpct%'>";
668 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
669 "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
670 if (in_array($option_id, $avalue)) echo " checked";
672 // Added 5-09 by BM - Translate label if applicable
673 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
675 echo "</td>";
677 if ($count) {
678 echo "</tr>";
679 if ($count > $cols) {
680 // Add some space after multiple rows of checkboxes.
681 $cols = htmlspecialchars( $cols, ENT_QUOTES);
682 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
685 echo "</table>";
688 // a set of labeled text input fields
689 else if ($data_type == 22) {
690 $tmp = explode('|', $currvalue);
691 $avalue = array();
692 foreach ($tmp as $value) {
693 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
694 $avalue[$matches[1]] = $matches[2];
697 $lres = sqlStatement("SELECT * FROM list_options " .
698 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
699 echo "<table cellpadding='0' cellspacing='0'>";
700 while ($lrow = sqlFetchArray($lres)) {
701 $option_id = $lrow['option_id'];
702 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
703 $maxlength = $frow['max_length'];
704 $string_maxlength = "";
705 // if max_length is set to zero, then do not set a maxlength
706 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
707 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
709 // Added 5-09 by BM - Translate label if applicable
710 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
711 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
712 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
713 echo "<td><input type='text'" .
714 " name='form_{$field_id_esc}[$option_id_esc]'" .
715 " id='form_{$field_id_esc}[$option_id_esc]'" .
716 " size='$fldlength'" .
717 " $string_maxlength" .
718 " value='$optionValue'";
719 echo " $lbfonchange $disabled /></td></tr>";
721 echo "</table>";
724 // a set of exam results; 3 radio buttons and a text field:
725 else if ($data_type == 23) {
726 $tmp = explode('|', $currvalue);
727 $avalue = array();
728 foreach ($tmp as $value) {
729 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
730 $avalue[$matches[1]] = $matches[2];
733 $maxlength = $frow['max_length'];
734 $string_maxlength = "";
735 // if max_length is set to zero, then do not set a maxlength
736 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
737 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
738 $lres = sqlStatement("SELECT * FROM list_options " .
739 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
740 echo "<table cellpadding='0' cellspacing='0'>";
741 echo "<tr><td>&nbsp;</td><td class='bold'>" .
742 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
743 "&nbsp;</td><td class='bold'>" .
744 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
745 "<td class='bold'>" .
746 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
747 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
748 while ($lrow = sqlFetchArray($lres)) {
749 $option_id = $lrow['option_id'];
750 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
751 $restype = substr($avalue[$option_id], 0, 1);
752 $resnote = substr($avalue[$option_id], 2);
754 // Added 5-09 by BM - Translate label if applicable
755 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
757 for ($i = 0; $i < 3; ++$i) {
758 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
759 echo "<td><input type='radio'" .
760 " name='radio_{$field_id_esc}[$option_id_esc]'" .
761 " id='radio_{$field_id_esc}[$option_id_esc]'" .
762 " value='$inputValue' $lbfonchange";
763 if ($restype === "$i") echo " checked";
764 echo " $disabled /></td>";
766 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
767 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
768 echo "<td><input type='text'" .
769 " name='form_{$field_id_esc}[$option_id_esc]'" .
770 " id='form_{$field_id_esc}[$option_id_esc]'" .
771 " size='$fldlength'" .
772 " $string_maxlength" .
773 " value='$resnote' $disabled /></td>";
774 echo "</tr>";
776 echo "</table>";
779 // the list of active allergies for the current patient
780 // this is read-only!
781 else if ($data_type == 24) {
782 $query = "SELECT title, comments FROM lists WHERE " .
783 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
784 "ORDER BY begdate";
785 // echo "<!-- $query -->\n"; // debugging
786 $lres = sqlStatement($query, array($GLOBALS['pid']));
787 $count = 0;
788 while ($lrow = sqlFetchArray($lres)) {
789 if ($count++) echo "<br />";
790 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
791 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
795 // a set of labeled checkboxes, each with a text field:
796 else if ($data_type == 25) {
797 $tmp = explode('|', $currvalue);
798 $avalue = array();
799 foreach ($tmp as $value) {
800 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
801 $avalue[$matches[1]] = $matches[2];
804 $maxlength = $frow['max_length'];
805 $string_maxlength = "";
806 // if max_length is set to zero, then do not set a maxlength
807 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
808 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
809 $lres = sqlStatement("SELECT * FROM list_options " .
810 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
811 echo "<table cellpadding='0' cellspacing='0'>";
812 while ($lrow = sqlFetchArray($lres)) {
813 $option_id = $lrow['option_id'];
814 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
815 $restype = substr($avalue[$option_id], 0, 1);
816 $resnote = substr($avalue[$option_id], 2);
818 // Added 5-09 by BM - Translate label if applicable
819 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
821 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
822 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
823 " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
824 if ($restype) echo " checked";
825 echo " $disabled />&nbsp;</td>";
826 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
827 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
828 echo "<td><input type='text'" .
829 " name='form_{$field_id_esc}[$option_id_esc]'" .
830 " id='form_{$field_id_esc}[$option_id_esc]'" .
831 " size='$fldlength'" .
832 " $string_maxlength" .
833 " value='$resnote' $disabled /></td>";
834 echo "</tr>";
836 echo "</table>";
839 // single-selection list with ability to add to it
840 else if ($data_type == 26) {
841 echo generate_select_list("form_$field_id", $list_id, $currvalue,
842 $description, ($showEmpty ? $empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
843 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
844 // show the add button if user has access to correct list
845 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
846 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
847 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
848 if (aco_exist('lists', $list_id)) {
849 // a specific aco exist for this list, so ensure access
850 if (acl_check('lists', $list_id)) echo $outputAddButton;
852 else {
853 // no specific aco exist for this list, so check for access to 'default' list
854 if (acl_check('lists', 'default')) echo $outputAddButton;
858 // a set of labeled radio buttons
859 else if ($data_type == 27) {
860 // In this special case, fld_length is the number of columns generated.
861 $cols = max(1, $frow['fld_length']);
862 $lres = sqlStatement("SELECT * FROM list_options " .
863 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
864 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
865 $tdpct = (int) (100 / $cols);
866 $got_selected = FALSE;
867 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
868 $option_id = $lrow['option_id'];
869 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
870 if ($count % $cols == 0) {
871 if ($count) echo "</tr>";
872 echo "<tr>";
874 echo "<td width='$tdpct%'>";
875 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
876 " value='$option_id_esc' $lbfonchange";
877 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
878 (strlen($currvalue) > 0 && $option_id == $currvalue))
880 echo " checked";
881 $got_selected = TRUE;
883 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
884 echo "</td>";
886 if ($count) {
887 echo "</tr>";
888 if ($count > $cols) {
889 // Add some space after multiple rows of radio buttons.
890 $cols = htmlspecialchars($cols, ENT_QUOTES);
891 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
894 echo "</table>";
895 if (!$got_selected && strlen($currvalue) > 0) {
896 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
897 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
898 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
902 // special case for history of lifestyle status; 3 radio buttons and a date text field:
903 // VicarePlus :: A selection list box for smoking status:
904 else if ($data_type == 28 || $data_type == 32) {
905 $tmp = explode('|', $currvalue);
906 switch(count($tmp)) {
907 case "4": {
908 $resnote = $tmp[0];
909 $restype = $tmp[1];
910 $resdate = $tmp[2];
911 $reslist = $tmp[3];
912 } break;
913 case "3": {
914 $resnote = $tmp[0];
915 $restype = $tmp[1];
916 $resdate = $tmp[2];
917 } break;
918 case "2": {
919 $resnote = $tmp[0];
920 $restype = $tmp[1];
921 $resdate = "";
922 } break;
923 case "1": {
924 $resnote = $tmp[0];
925 $resdate = $restype = "";
926 } break;
927 default: {
928 $restype = $resdate = $resnote = "";
929 } break;
931 $maxlength = $frow['max_length'];
932 $string_maxlength = "";
933 // if max_length is set to zero, then do not set a maxlength
934 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
935 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
937 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
938 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
939 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
940 echo "<table cellpadding='0' cellspacing='0'>";
941 echo "<tr>";
942 if ($data_type == 28)
944 // input text
945 echo "<td><input type='text'" .
946 " name='form_$field_id_esc'" .
947 " id='form_$field_id_esc'" .
948 " size='$fldlength'" .
949 " $string_maxlength" .
950 " value='$resnote' $disabled />&nbsp;</td>";
951 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
952 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
953 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
955 else if($data_type == 32)
957 // input text
958 echo "<tr><td><input type='text'" .
959 " name='form_text_$field_id_esc'" .
960 " id='form_text_$field_id_esc'" .
961 " size='$fldlength'" .
962 " $string_maxlength" .
963 " value='$resnote' $disabled />&nbsp;</td></tr>";
964 echo "<td>";
965 //Selection list for smoking status
966 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
967 echo generate_select_list("form_$field_id", $list_id, $reslist,
968 $description, ($showEmpty ? $empty_title : ''), '', $onchange, '',
969 ($disabled ? array('disabled' => 'disabled') : null));
970 echo "</td>";
971 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
973 // current
974 echo "<td class='text' ><input type='radio'" .
975 " name='radio_{$field_id_esc}'" .
976 " id='radio_{$field_id_esc}[current]'" .
977 " value='current" . $field_id_esc . "' $lbfonchange";
978 if ($restype == "current" . $field_id) echo " checked";
979 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
980 echo " />" . xlt('Current') . "&nbsp;</td>";
981 // quit
982 echo "<td class='text'><input type='radio'" .
983 " name='radio_{$field_id_esc}'" .
984 " id='radio_{$field_id_esc}[quit]'" .
985 " value='quit".$field_id_esc."' $lbfonchange";
986 if ($restype == "quit" . $field_id) echo " checked";
987 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
988 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
989 // quit date
990 echo "<td class='text'><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
991 " value='$resdate'" .
992 " title='$description'" .
993 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
994 if (!$disabled) {
995 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
996 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
997 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
998 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
1000 echo "&nbsp;</td>";
1001 // never
1002 echo "<td class='text'><input type='radio'" .
1003 " name='radio_{$field_id_esc}'" .
1004 " id='radio_{$field_id_esc}[never]'" .
1005 " value='never" . $field_id_esc . "' $lbfonchange";
1006 if ($restype == "never" . $field_id) echo " checked";
1007 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1008 echo " />" . xlt('Never') . "&nbsp;</td>";
1009 // Not Applicable
1010 echo "<td class='text'><input type='radio'" .
1011 " name='radio_{$field_id}'" .
1012 " id='radio_{$field_id}[not_applicable]'" .
1013 " value='not_applicable" . $field_id . "' $lbfonchange";
1014 if ($restype == "not_applicable" . $field_id) echo " checked";
1015 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1016 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1018 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1019 echo "<td class='text' ><div id='smoke_code'></div></td>";
1020 echo "</tr>";
1021 echo "</table>";
1024 // static text. read-only, of course.
1025 else if ($data_type == 31) {
1026 echo nl2br($frow['description']);
1029 //$data_type == 33
1030 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1031 //$data_type == 33
1033 else if($data_type == 34){
1034 $arr = explode("|*|*|*|",$currvalue);
1035 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;'>";
1036 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
1037 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1038 echo "</a>";
1041 //facilities drop-down list
1042 else if ($data_type == 35) {
1043 if (empty($currvalue)){
1044 $currvalue = 0;
1046 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1047 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1050 //multiple select
1051 // supports backup list
1052 else if ($data_type == 36) {
1053 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1054 $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);
1059 function generate_print_field($frow, $currvalue) {
1060 global $rootdir, $date_init, $ISSUE_TYPES;
1062 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1064 $data_type = $frow['data_type'];
1065 $field_id = $frow['field_id'];
1066 $list_id = $frow['list_id'];
1067 $fld_length = $frow['fld_length'];
1068 $backup_list = $frow['list_backup_id'];
1070 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1072 // Can pass $frow['empty_title'] with this variable, otherwise
1073 // will default to 'Unassigned'.
1074 // If it is 'SKIP' then an empty text title is completely skipped.
1075 $showEmpty = true;
1076 if (isset($frow['empty_title'])) {
1077 if ($frow['empty_title'] == "SKIP") {
1078 //do not display an 'empty' choice
1079 $showEmpty = false;
1080 $empty_title = "Unassigned";
1082 else {
1083 $empty_title = $frow['empty_title'];
1086 else {
1087 $empty_title = "Unassigned";
1090 // generic single-selection list
1091 // Supports backup lists.
1092 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
1093 if (empty($fld_length)) {
1094 if ($list_id == 'titles') {
1095 $fld_length = 3;
1096 } else {
1097 $fld_length = 10;
1100 $tmp = '';
1101 if ($currvalue) {
1102 $lrow = sqlQuery("SELECT title FROM list_options " .
1103 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
1104 $tmp = xl_list_label($lrow['title']);
1105 if ($lrow == 0 && !empty($backup_list)) {
1106 // since primary list did not map, try to map to backup list
1107 $lrow = sqlQuery("SELECT title FROM list_options " .
1108 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1109 $tmp = xl_list_label($lrow['title']);
1111 if (empty($tmp)) $tmp = "($currvalue)";
1113 /*****************************************************************
1114 echo "<input type='text'" .
1115 " size='$fld_length'" .
1116 " value='$tmp'" .
1117 " class='under'" .
1118 " />";
1119 *****************************************************************/
1120 if ($tmp === '') {
1121 $tmp = '&nbsp;';
1123 else {
1124 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1126 echo $tmp;
1129 // simple text field
1130 else if ($data_type == 2 || $data_type == 15) {
1131 /*****************************************************************
1132 echo "<input type='text'" .
1133 " size='$fld_length'" .
1134 " value='$currescaped'" .
1135 " class='under'" .
1136 " />";
1137 *****************************************************************/
1138 if ($currescaped === '') $currescaped = '&nbsp;';
1139 echo $currescaped;
1142 // long or multi-line text field
1143 else if ($data_type == 3) {
1144 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
1145 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
1146 echo "<textarea" .
1147 " cols='$fldlength'" .
1148 " rows='$maxlength'>" .
1149 $currescaped . "</textarea>";
1152 // date
1153 else if ($data_type == 4) {
1154 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1155 $agestr = optionalAge($frow, $currvalue,$asof);
1156 if ($agestr) {
1157 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1159 if ($currvalue === '') {
1160 echo '&nbsp;';
1162 else {
1163 echo text(oeFormatShortDate($currvalue));
1165 // Optional display of age or gestational age.
1166 if ($agestr) {
1167 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1171 // provider list
1172 else if ($data_type == 10 || $data_type == 11) {
1173 $tmp = '';
1174 if ($currvalue) {
1175 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1176 "WHERE id = ?", array($currvalue) );
1177 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1178 if (empty($tmp)) $tmp = "($currvalue)";
1180 /*****************************************************************
1181 echo "<input type='text'" .
1182 " size='$fld_length'" .
1183 " value='$tmp'" .
1184 " class='under'" .
1185 " />";
1186 *****************************************************************/
1187 if ($tmp === '') { $tmp = '&nbsp;'; }
1188 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1189 echo $tmp;
1192 // pharmacy list
1193 else if ($data_type == 12) {
1194 $tmp = '';
1195 if ($currvalue) {
1196 $pres = get_pharmacies();
1197 while ($prow = sqlFetchArray($pres)) {
1198 $key = $prow['id'];
1199 if ($currvalue == $key) {
1200 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1201 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1202 $prow['line1'] . ' / ' . $prow['city'];
1205 if (empty($tmp)) $tmp = "($currvalue)";
1207 /*****************************************************************
1208 echo "<input type='text'" .
1209 " size='$fld_length'" .
1210 " value='$tmp'" .
1211 " class='under'" .
1212 " />";
1213 *****************************************************************/
1214 if ($tmp === '') { $tmp = '&nbsp;'; }
1215 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1216 echo $tmp;
1219 // squads
1220 else if ($data_type == 13) {
1221 $tmp = '';
1222 if ($currvalue) {
1223 $squads = acl_get_squads();
1224 if ($squads) {
1225 foreach ($squads as $key => $value) {
1226 if ($currvalue == $key) {
1227 $tmp = $value[3];
1231 if (empty($tmp)) $tmp = "($currvalue)";
1233 /*****************************************************************
1234 echo "<input type='text'" .
1235 " size='$fld_length'" .
1236 " value='$tmp'" .
1237 " class='under'" .
1238 " />";
1239 *****************************************************************/
1240 if ($tmp === '') { $tmp = '&nbsp;'; }
1241 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1242 echo $tmp;
1245 // Address book.
1246 else if ($data_type == 14) {
1247 $tmp = '';
1248 if ($currvalue) {
1249 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1250 "WHERE id = ?", array($currvalue) );
1251 $uname = $urow['lname'];
1252 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1253 $tmp = $uname;
1254 if (empty($tmp)) $tmp = "($currvalue)";
1256 /*****************************************************************
1257 echo "<input type='text'" .
1258 " size='$fld_length'" .
1259 " value='$tmp'" .
1260 " class='under'" .
1261 " />";
1262 *****************************************************************/
1263 if ($tmp === '') { $tmp = '&nbsp;'; }
1264 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1265 echo $tmp;
1268 // insurance company list
1269 else if ($data_type == 16) {
1270 $tmp = '';
1271 if ($currvalue) {
1272 $insprovs = getInsuranceProviders();
1273 foreach ($insprovs as $key => $ipname) {
1274 if ($currvalue == $key) {
1275 $tmp = $ipname;
1278 if (empty($tmp)) $tmp = "($currvalue)";
1280 if ($tmp === '') $tmp = '&nbsp;';
1281 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1282 echo $tmp;
1285 // issue types
1286 else if ($data_type == 17) {
1287 $tmp = '';
1288 if ($currvalue) {
1289 foreach ($ISSUE_TYPES as $key => $value) {
1290 if ($currvalue == $key) {
1291 $tmp = $value[1];
1294 if (empty($tmp)) $tmp = "($currvalue)";
1296 if ($tmp === '') $tmp = '&nbsp;';
1297 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1298 echo $tmp;
1301 // Visit categories.
1302 else if ($data_type == 18) {
1303 $tmp = '';
1304 if ($currvalue) {
1305 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1306 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1307 array($currvalue));
1308 $tmp = xl_appt_category($crow['pc_catname']);
1309 if (empty($tmp)) $tmp = "($currvalue)";
1311 if ($tmp === '') { $tmp = '&nbsp;'; }
1312 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES); }
1313 echo $tmp;
1316 // a set of labeled checkboxes
1317 else if ($data_type == 21) {
1318 // In this special case, fld_length is the number of columns generated.
1319 $cols = max(1, $fld_length);
1320 $avalue = explode('|', $currvalue);
1321 $lres = sqlStatement("SELECT * FROM list_options " .
1322 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1323 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1324 $tdpct = (int) (100 / $cols);
1325 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1326 $option_id = $lrow['option_id'];
1327 if ($count % $cols == 0) {
1328 if ($count) echo "</tr>";
1329 echo "<tr>";
1331 echo "<td width='$tdpct%'>";
1332 echo "<input type='checkbox'";
1333 if (in_array($option_id, $avalue)) echo " checked";
1334 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1335 echo "</td>";
1337 if ($count) {
1338 echo "</tr>";
1339 if ($count > $cols) {
1340 // Add some space after multiple rows of checkboxes.
1341 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1342 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1345 echo "</table>";
1348 // a set of labeled text input fields
1349 else if ($data_type == 22) {
1350 $tmp = explode('|', $currvalue);
1351 $avalue = array();
1352 foreach ($tmp as $value) {
1353 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1354 $avalue[$matches[1]] = $matches[2];
1357 $lres = sqlStatement("SELECT * FROM list_options " .
1358 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1359 echo "<table cellpadding='0' cellspacing='0'>";
1360 while ($lrow = sqlFetchArray($lres)) {
1361 $option_id = $lrow['option_id'];
1362 $fldlength = empty($fld_length) ? 20 : $fld_length;
1363 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1364 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1365 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1366 echo "<td><input type='text'" .
1367 " size='$fldlength'" .
1368 " value='$inputValue'" .
1369 " class='under'" .
1370 " /></td></tr>";
1372 echo "</table>";
1375 // a set of exam results; 3 radio buttons and a text field:
1376 else if ($data_type == 23) {
1377 $tmp = explode('|', $currvalue);
1378 $avalue = array();
1379 foreach ($tmp as $value) {
1380 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1381 $avalue[$matches[1]] = $matches[2];
1384 $fldlength = empty($fld_length) ? 20 : $fld_length;
1385 $lres = sqlStatement("SELECT * FROM list_options " .
1386 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1387 echo "<table cellpadding='0' cellspacing='0'>";
1388 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1389 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1390 "&nbsp;</td><td class='bold'>" .
1391 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1392 "<td class='bold'>" .
1393 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1394 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1395 while ($lrow = sqlFetchArray($lres)) {
1396 $option_id = $lrow['option_id'];
1397 $restype = substr($avalue[$option_id], 0, 1);
1398 $resnote = substr($avalue[$option_id], 2);
1399 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1400 for ($i = 0; $i < 3; ++$i) {
1401 echo "<td><input type='radio'";
1402 if ($restype === "$i") echo " checked";
1403 echo " /></td>";
1405 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1406 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1407 echo "<td><input type='text'" .
1408 " size='$fldlength'" .
1409 " value='$resnote'" .
1410 " class='under' /></td>" .
1411 "</tr>";
1413 echo "</table>";
1416 // the list of active allergies for the current patient
1417 // this is read-only!
1418 else if ($data_type == 24) {
1419 $query = "SELECT title, comments FROM lists WHERE " .
1420 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1421 "ORDER BY begdate";
1422 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1423 $count = 0;
1424 while ($lrow = sqlFetchArray($lres)) {
1425 if ($count++) echo "<br />";
1426 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1427 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1431 // a set of labeled checkboxes, each with a text field:
1432 else if ($data_type == 25) {
1433 $tmp = explode('|', $currvalue);
1434 $avalue = array();
1435 foreach ($tmp as $value) {
1436 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1437 $avalue[$matches[1]] = $matches[2];
1440 $fldlength = empty($fld_length) ? 20 : $fld_length;
1441 $lres = sqlStatement("SELECT * FROM list_options " .
1442 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1443 echo "<table cellpadding='0' cellspacing='0'>";
1444 while ($lrow = sqlFetchArray($lres)) {
1445 $option_id = $lrow['option_id'];
1446 $restype = substr($avalue[$option_id], 0, 1);
1447 $resnote = substr($avalue[$option_id], 2);
1448 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1449 echo "<td><input type='checkbox'";
1450 if ($restype) echo " checked";
1451 echo " />&nbsp;</td>";
1452 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1453 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1454 echo "<td><input type='text'" .
1455 " size='$fldlength'" .
1456 " value='$resnote'" .
1457 " class='under'" .
1458 " /></td>" .
1459 "</tr>";
1461 echo "</table>";
1464 // a set of labeled radio buttons
1465 else if ($data_type == 27) {
1466 // In this special case, fld_length is the number of columns generated.
1467 $cols = max(1, $frow['fld_length']);
1468 $lres = sqlStatement("SELECT * FROM list_options " .
1469 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1470 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1471 $tdpct = (int) (100 / $cols);
1472 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1473 $option_id = $lrow['option_id'];
1474 if ($count % $cols == 0) {
1475 if ($count) echo "</tr>";
1476 echo "<tr>";
1478 echo "<td width='$tdpct%'>";
1479 echo "<input type='radio'";
1480 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1481 (strlen($currvalue) > 0 && $option_id == $currvalue))
1483 echo " checked";
1485 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1486 echo "</td>";
1488 if ($count) {
1489 echo "</tr>";
1490 if ($count > $cols) {
1491 // Add some space after multiple rows of radio buttons.
1492 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1493 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1496 echo "</table>";
1499 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1500 else if ($data_type == 28 || $data_type == 32) {
1501 $tmp = explode('|', $currvalue);
1502 switch(count($tmp)) {
1503 case "4": {
1504 $resnote = $tmp[0];
1505 $restype = $tmp[1];
1506 $resdate = $tmp[2];
1507 $reslist = $tmp[3];
1508 } break;
1509 case "3": {
1510 $resnote = $tmp[0];
1511 $restype = $tmp[1];
1512 $resdate = $tmp[2];
1513 } break;
1514 case "2": {
1515 $resnote = $tmp[0];
1516 $restype = $tmp[1];
1517 $resdate = "";
1518 } break;
1519 case "1": {
1520 $resnote = $tmp[0];
1521 $resdate = $restype = "";
1522 } break;
1523 default: {
1524 $restype = $resdate = $resnote = "";
1525 } break;
1527 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1528 echo "<table cellpadding='0' cellspacing='0'>";
1529 echo "<tr>";
1530 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1531 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1532 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1533 if($data_type == 28)
1535 echo "<td><input type='text'" .
1536 " size='$fldlength'" .
1537 " class='under'" .
1538 " value='$resnote' /></td>";
1539 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1540 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1541 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1543 else if($data_type == 32)
1545 echo "<tr><td><input type='text'" .
1546 " size='$fldlength'" .
1547 " class='under'" .
1548 " value='$resnote' /></td></tr>";
1549 $fldlength = 30;
1550 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1551 echo "<td><input type='text'" .
1552 " size='$fldlength'" .
1553 " class='under'" .
1554 " value='$smoking_status_title' /></td>";
1555 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1557 echo "<td><input type='radio'";
1558 if ($restype == "current".$field_id) echo " checked";
1559 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1561 echo "<td><input type='radio'";
1562 if ($restype == "current".$field_id) echo " checked";
1563 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1565 echo "<td><input type='text' size='6'" .
1566 " value='$resdate'" .
1567 " class='under'" .
1568 " /></td>";
1570 echo "<td><input type='radio'";
1571 if ($restype == "current".$field_id) echo " checked";
1572 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1574 echo "<td><input type='radio'";
1575 if ($restype == "not_applicable".$field_id) echo " checked";
1576 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1577 echo "</tr>";
1578 echo "</table>";
1581 // static text. read-only, of course.
1582 else if ($data_type == 31) {
1583 echo nl2br($frow['description']);
1586 else if($data_type == 34){
1587 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;'>";
1588 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1589 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1590 echo "</a>";
1593 //facilities drop-down list
1594 else if ($data_type == 35) {
1595 if (empty($currvalue)){
1596 $currvalue = 0;
1598 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1601 //Multi-select
1602 // Supports backup lists.
1603 else if ($data_type == 36) {
1604 if (empty($fld_length)) {
1605 if ($list_id == 'titles') {
1606 $fld_length = 3;
1607 } else {
1608 $fld_length = 10;
1611 $tmp = '';
1613 $values_array = explode("|", $currvalue);
1615 $i=0;
1616 foreach($values_array as $value) {
1617 if ($value) {
1618 $lrow = sqlQuery("SELECT title FROM list_options " .
1619 "WHERE list_id = ? AND option_id = ?", array($list_id,$value));
1620 $tmp = xl_list_label($lrow['title']);
1621 if ($lrow == 0 && !empty($backup_list)) {
1622 // since primary list did not map, try to map to backup list
1623 $lrow = sqlQuery("SELECT title FROM list_options " .
1624 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1625 $tmp = xl_list_label($lrow['title']);
1627 if (empty($tmp)) $tmp = "($value)";
1630 if ($tmp === '') {
1631 $tmp = '&nbsp;';
1633 else {
1634 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1636 if ($i != 0 && $tmp != '&nbsp;') echo ",";
1637 echo $tmp;
1638 $i++;
1644 function generate_display_field($frow, $currvalue) {
1645 global $ISSUE_TYPES;
1647 $data_type = $frow['data_type'];
1648 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1649 $list_id = $frow['list_id'];
1650 $backup_list = $frow['list_backup_id'];
1652 $s = '';
1654 // generic selection list or the generic selection list with add on the fly
1655 // feature, or radio buttons
1656 // Supports backup lists for datatypes 1,26,33
1657 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1658 $lrow = sqlQuery("SELECT title FROM list_options " .
1659 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1660 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1661 //if there is no matching value in the corresponding lists check backup list
1662 // only supported in data types 1,26,33
1663 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1664 $lrow = sqlQuery("SELECT title FROM list_options " .
1665 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
1666 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1670 // simple text field
1671 else if ($data_type == 2) {
1672 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1675 // long or multi-line text field
1676 else if ($data_type == 3) {
1677 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1680 // date
1681 else if ($data_type == 4) {
1682 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1683 $s = '';
1684 $agestr = optionalAge($frow, $currvalue, $asof);
1685 if ($agestr) {
1686 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1688 if ($currvalue === '') {
1689 $s .= '&nbsp;';
1691 else {
1692 $s .= text(oeFormatShortDate($currvalue));
1694 // Optional display of age or gestational age.
1695 if ($agestr) {
1696 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1700 // provider
1701 else if ($data_type == 10 || $data_type == 11) {
1702 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1703 "WHERE id = ?", array($currvalue) );
1704 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1707 // pharmacy list
1708 else if ($data_type == 12) {
1709 $pres = get_pharmacies();
1710 while ($prow = sqlFetchArray($pres)) {
1711 $key = $prow['id'];
1712 if ($currvalue == $key) {
1713 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1714 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1715 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1720 // squads
1721 else if ($data_type == 13) {
1722 $squads = acl_get_squads();
1723 if ($squads) {
1724 foreach ($squads as $key => $value) {
1725 if ($currvalue == $key) {
1726 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1732 // address book
1733 else if ($data_type == 14) {
1734 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
1735 "WHERE id = ?", array($currvalue));
1736 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
1737 if($urow['organization'] !=""){
1738 $uname = $urow['organization'];
1739 }else{
1740 $uname = $urow['lname'];
1741 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1743 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1746 // billing code
1747 else if ($data_type == 15) {
1748 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1751 // insurance company list
1752 else if ($data_type == 16) {
1753 $insprovs = getInsuranceProviders();
1754 foreach ($insprovs as $key => $ipname) {
1755 if ($currvalue == $key) {
1756 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
1761 // issue types
1762 else if ($data_type == 17) {
1763 foreach ($ISSUE_TYPES as $key => $value) {
1764 if ($currvalue == $key) {
1765 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
1770 // visit category
1771 else if ($data_type == 18) {
1772 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1773 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1774 array($currvalue));
1775 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES);
1778 // a set of labeled checkboxes
1779 else if ($data_type == 21) {
1780 $avalue = explode('|', $currvalue);
1781 $lres = sqlStatement("SELECT * FROM list_options " .
1782 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1783 $count = 0;
1784 while ($lrow = sqlFetchArray($lres)) {
1785 $option_id = $lrow['option_id'];
1786 if (in_array($option_id, $avalue)) {
1787 if ($count++) $s .= "<br />";
1789 // Added 5-09 by BM - Translate label if applicable
1790 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES);
1796 // a set of labeled text input fields
1797 else if ($data_type == 22) {
1798 $tmp = explode('|', $currvalue);
1799 $avalue = array();
1800 foreach ($tmp as $value) {
1801 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1802 $avalue[$matches[1]] = $matches[2];
1805 $lres = sqlStatement("SELECT * FROM list_options " .
1806 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1807 $s .= "<table cellpadding='0' cellspacing='0'>";
1808 while ($lrow = sqlFetchArray($lres)) {
1809 $option_id = $lrow['option_id'];
1810 if (empty($avalue[$option_id])) continue;
1812 // Added 5-09 by BM - Translate label if applicable
1813 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1815 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1817 $s .= "</table>";
1820 // a set of exam results; 3 radio buttons and a text field:
1821 else if ($data_type == 23) {
1822 $tmp = explode('|', $currvalue);
1823 $avalue = array();
1824 foreach ($tmp as $value) {
1825 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1826 $avalue[$matches[1]] = $matches[2];
1829 $lres = sqlStatement("SELECT * FROM list_options " .
1830 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1831 $s .= "<table cellpadding='0' cellspacing='0'>";
1832 while ($lrow = sqlFetchArray($lres)) {
1833 $option_id = $lrow['option_id'];
1834 $restype = substr($avalue[$option_id], 0, 1);
1835 $resnote = substr($avalue[$option_id], 2);
1836 if (empty($restype) && empty($resnote)) continue;
1838 // Added 5-09 by BM - Translate label if applicable
1839 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1841 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1842 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1843 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1844 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1845 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1846 $s .= "</tr>";
1848 $s .= "</table>";
1851 // the list of active allergies for the current patient
1852 else if ($data_type == 24) {
1853 $query = "SELECT title, comments FROM lists WHERE " .
1854 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1855 "ORDER BY begdate";
1856 // echo "<!-- $query -->\n"; // debugging
1857 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1858 $count = 0;
1859 while ($lrow = sqlFetchArray($lres)) {
1860 if ($count++) $s .= "<br />";
1861 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1862 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1866 // a set of labeled checkboxes, each with a text field:
1867 else if ($data_type == 25) {
1868 $tmp = explode('|', $currvalue);
1869 $avalue = array();
1870 foreach ($tmp as $value) {
1871 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1872 $avalue[$matches[1]] = $matches[2];
1875 $lres = sqlStatement("SELECT * FROM list_options " .
1876 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1877 $s .= "<table cellpadding='0' cellspacing='0'>";
1878 while ($lrow = sqlFetchArray($lres)) {
1879 $option_id = $lrow['option_id'];
1880 $restype = substr($avalue[$option_id], 0, 1);
1881 $resnote = substr($avalue[$option_id], 2);
1882 if (empty($restype) && empty($resnote)) continue;
1884 // Added 5-09 by BM - Translate label if applicable
1885 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1887 $restype = $restype ? xl('Yes') : xl('No');
1888 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1889 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1890 $s .= "</tr>";
1892 $s .= "</table>";
1895 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1896 // VicarePlus :: A selection list for smoking status.
1897 else if ($data_type == 28 || $data_type == 32) {
1898 $tmp = explode('|', $currvalue);
1899 switch(count($tmp)) {
1900 case "4": {
1901 $resnote = $tmp[0];
1902 $restype = $tmp[1];
1903 $resdate = $tmp[2];
1904 $reslist = $tmp[3];
1905 } break;
1906 case "3": {
1907 $resnote = $tmp[0];
1908 $restype = $tmp[1];
1909 $resdate = $tmp[2];
1910 } break;
1911 case "2": {
1912 $resnote = $tmp[0];
1913 $restype = $tmp[1];
1914 $resdate = "";
1915 } break;
1916 case "1": {
1917 $resnote = $tmp[0];
1918 $resdate = $restype = "";
1919 } break;
1920 default: {
1921 $restype = $resdate = $resnote = "";
1922 } break;
1924 $s .= "<table cellpadding='0' cellspacing='0'>";
1926 $s .= "<tr>";
1927 $res = "";
1928 if ($restype == "current".$field_id) $res = xl('Current');
1929 if ($restype == "quit".$field_id) $res = xl('Quit');
1930 if ($restype == "never".$field_id) $res = xl('Never');
1931 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1932 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1933 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1934 if ($data_type == 28)
1936 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1938 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1939 else if ($data_type == 32)
1940 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1941 $smoke_codes = getSmokeCodes();
1942 if (!empty($reslist)) {
1943 if($smoke_codes[$reslist]!="")
1944 $code_desc = "( ".$smoke_codes[$reslist]." )";
1946 $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>";}
1948 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1951 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1952 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1953 $s .= "</tr>";
1954 $s .= "</table>";
1957 // static text. read-only, of course.
1958 else if ($data_type == 31) {
1959 $s .= nl2br($frow['description']);
1962 else if($data_type == 34){
1963 $arr = explode("|*|*|*|",$currvalue);
1964 for($i=0;$i<sizeof($arr);$i++){
1965 $s.=$arr[$i];
1969 // facility
1970 else if ($data_type == 35) {
1971 $urow = sqlQuery("SELECT id, name FROM facility ".
1972 "WHERE id = ?", array($currvalue) );
1973 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
1976 // Multi select
1977 // Supports backup lists
1978 else if ($data_type == 36) {
1979 $values_array = explode("|", $currvalue);
1981 $i = 0;
1982 foreach($values_array as $value) {
1983 $lrow = sqlQuery("SELECT title FROM list_options " .
1984 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
1986 if ($lrow == 0 && !empty($backup_list)) {
1987 //use back up list
1988 $lrow = sqlQuery("SELECT title FROM list_options " .
1989 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
1992 if ($i > 0) {
1993 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1994 } else {
1995 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1998 $i++;
2002 return $s;
2005 // Generate plain text versions of selected LBF field types.
2006 // Currently used by interface/patient_file/download_template.php.
2007 // More field types might need to be supported here in the future.
2009 function generate_plaintext_field($frow, $currvalue) {
2010 global $ISSUE_TYPES;
2012 $data_type = $frow['data_type'];
2013 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2014 $list_id = $frow['list_id'];
2015 $backup_list = $frow['backup_list'];
2016 $s = '';
2018 // generic selection list or the generic selection list with add on the fly
2019 // feature, or radio buttons
2020 // Supports backup lists (for datatypes 1,26,33)
2021 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2022 $lrow = sqlQuery("SELECT title FROM list_options " .
2023 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
2024 $s = xl_list_label($lrow['title']);
2025 //if there is no matching value in the corresponding lists check backup list
2026 // only supported in data types 1,26,33
2027 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2028 $lrow = sqlQuery("SELECT title FROM list_options " .
2029 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
2030 $s = xl_list_label($lrow['title']);
2034 // simple or long text field
2035 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2036 $s = $currvalue;
2039 // date
2040 else if ($data_type == 4) {
2041 $s = oeFormatShortDate($currvalue);
2042 // Optional display of age or gestational age.
2043 $asof=''; //not used here, but set to prevent a php warning when call optionalAge
2044 $tmp = optionalAge($frow, $currvalue,$asof);
2045 if ($tmp) $s .= ' ' . $tmp;
2048 // provider
2049 else if ($data_type == 10 || $data_type == 11) {
2050 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2051 "WHERE id = ?", array($currvalue) );
2052 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2055 // pharmacy list
2056 else if ($data_type == 12) {
2057 $pres = get_pharmacies();
2058 while ($prow = sqlFetchArray($pres)) {
2059 $key = $prow['id'];
2060 if ($currvalue == $key) {
2061 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2062 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2063 $prow['line1'] . ' / ' . $prow['city'];
2068 // address book
2069 else if ($data_type == 14) {
2070 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2071 "WHERE id = ?", array($currvalue));
2072 $uname = $urow['lname'];
2073 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2074 $s = $uname;
2077 // insurance company list
2078 else if ($data_type == 16) {
2079 $insprovs = getInsuranceProviders();
2080 foreach ($insprovs as $key => $ipname) {
2081 if ($currvalue == $key) {
2082 $s .= $ipname;
2087 // issue type
2088 else if ($data_type == 17) {
2089 foreach ($ISSUE_TYPES as $key => $value) {
2090 if ($currvalue == $key) {
2091 $s .= $value[1];
2096 // visit category
2097 else if ($data_type == 18) {
2098 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2099 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2100 array($currvalue));
2101 $s = $crow['pc_catname'];
2104 // a set of labeled checkboxes
2105 else if ($data_type == 21) {
2106 $avalue = explode('|', $currvalue);
2107 $lres = sqlStatement("SELECT * FROM list_options " .
2108 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2109 $count = 0;
2110 while ($lrow = sqlFetchArray($lres)) {
2111 $option_id = $lrow['option_id'];
2112 if (in_array($option_id, $avalue)) {
2113 if ($count++) $s .= "; ";
2114 $s .= xl_list_label($lrow['title']);
2119 // a set of labeled text input fields
2120 else if ($data_type == 22) {
2121 $tmp = explode('|', $currvalue);
2122 $avalue = array();
2123 foreach ($tmp as $value) {
2124 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2125 $avalue[$matches[1]] = $matches[2];
2128 $lres = sqlStatement("SELECT * FROM list_options " .
2129 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2130 while ($lrow = sqlFetchArray($lres)) {
2131 $option_id = $lrow['option_id'];
2132 if (empty($avalue[$option_id])) continue;
2133 if ($s !== '') $s .= '; ';
2134 $s .= xl_list_label($lrow['title']) . ': ';
2135 $s .= $avalue[$option_id];
2139 // A set of exam results; 3 radio buttons and a text field.
2140 // This shows abnormal results only.
2141 else if ($data_type == 23) {
2142 $tmp = explode('|', $currvalue);
2143 $avalue = array();
2144 foreach ($tmp as $value) {
2145 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2146 $avalue[$matches[1]] = $matches[2];
2149 $lres = sqlStatement("SELECT * FROM list_options " .
2150 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2151 while ($lrow = sqlFetchArray($lres)) {
2152 $option_id = $lrow['option_id'];
2153 $restype = substr($avalue[$option_id], 0, 1);
2154 $resnote = substr($avalue[$option_id], 2);
2155 if (empty($restype) && empty($resnote)) continue;
2156 if ($restype != '2') continue; // show abnormal results only
2157 if ($s !== '') $s .= '; ';
2158 $s .= xl_list_label($lrow['title']);
2159 if (!empty($resnote)) $s .= ': ' . $resnote;
2163 // the list of active allergies for the current patient
2164 else if ($data_type == 24) {
2165 $query = "SELECT title, comments FROM lists WHERE " .
2166 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2167 "ORDER BY begdate";
2168 $lres = sqlStatement($query, array($GLOBALS['pid']));
2169 $count = 0;
2170 while ($lrow = sqlFetchArray($lres)) {
2171 if ($count++) $s .= "; ";
2172 $s .= $lrow['title'];
2173 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2177 // a set of labeled checkboxes, each with a text field:
2178 else if ($data_type == 25) {
2179 $tmp = explode('|', $currvalue);
2180 $avalue = array();
2181 foreach ($tmp as $value) {
2182 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2183 $avalue[$matches[1]] = $matches[2];
2186 $lres = sqlStatement("SELECT * FROM list_options " .
2187 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2188 while ($lrow = sqlFetchArray($lres)) {
2189 $option_id = $lrow['option_id'];
2190 $restype = substr($avalue[$option_id], 0, 1);
2191 $resnote = substr($avalue[$option_id], 2);
2192 if (empty($restype) && empty($resnote)) continue;
2193 if ($s !== '') $s .= '; ';
2194 $s .= xl_list_label($lrow['title']);
2195 $restype = $restype ? xl('Yes') : xl('No');
2196 $s .= $restype;
2197 if ($resnote) $s .= ' ' . $resnote;
2201 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2202 // VicarePlus :: A selection list for smoking status.
2203 else if ($data_type == 28 || $data_type == 32) {
2204 $tmp = explode('|', $currvalue);
2205 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2206 $restype = count($tmp) > 1 ? $tmp[1] : '';
2207 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2208 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2209 $res = "";
2210 if ($restype == "current" . $field_id) $res = xl('Current');
2211 if ($restype == "quit" . $field_id) $res = xl('Quit');
2212 if ($restype == "never" . $field_id) $res = xl('Never');
2213 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2215 if ($data_type == 28) {
2216 if (!empty($resnote)) $s .= $resnote;
2218 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2219 else if ($data_type == 32) {
2220 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2221 if (!empty($resnote)) $s .= ' ' . $resnote;
2223 if (!empty($res)) {
2224 if ($s !== '') $s .= ' ';
2225 $s .= xl('Status') . ' ' . $res;
2227 if ($restype == "quit".$field_id) {
2228 if ($s !== '') $s .= ' ';
2229 $s .= $resdate;
2233 // Multi select
2234 // Supports backup lists
2235 else if ($data_type == 36) {
2236 $values_array = explode("|", $currvalue);
2238 $i = 0;
2239 foreach($values_array as $value) {
2240 $lrow = sqlQuery("SELECT title FROM list_options " .
2241 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
2243 if ($lrow == 0 && !empty($backup_list)) {
2244 //use back up list
2245 $lrow = sqlQuery("SELECT title FROM list_options " .
2246 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
2249 if ($i > 0) {
2250 $s = $s . ", " . xl_list_label($lrow['title']);
2251 } else {
2252 $s = xl_list_label($lrow['title']);
2255 $i++;
2259 return $s;
2262 $CPR = 4; // cells per row of generic data
2263 $last_group = '';
2264 $cell_count = 0;
2265 $item_count = 0;
2267 function disp_end_cell() {
2268 global $item_count, $cell_count;
2269 if ($item_count > 0) {
2270 echo "</td>";
2271 $item_count = 0;
2275 function disp_end_row() {
2276 global $cell_count, $CPR;
2277 disp_end_cell();
2278 if ($cell_count > 0) {
2279 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
2280 echo "</tr>\n";
2281 $cell_count = 0;
2285 function disp_end_group() {
2286 global $last_group;
2287 if (strlen($last_group) > 0) {
2288 disp_end_row();
2292 function display_layout_rows($formtype, $result1, $result2='') {
2293 global $item_count, $cell_count, $last_group, $CPR;
2295 $fres = sqlStatement("SELECT * FROM layout_options " .
2296 "WHERE form_id = ? AND uor > 0 " .
2297 "ORDER BY group_name, seq", array($formtype) );
2299 while ($frow = sqlFetchArray($fres)) {
2300 $this_group = $frow['group_name'];
2301 $titlecols = $frow['titlecols'];
2302 $datacols = $frow['datacols'];
2303 $data_type = $frow['data_type'];
2304 $field_id = $frow['field_id'];
2305 $list_id = $frow['list_id'];
2306 $currvalue = '';
2308 if ($formtype == 'DEM') {
2309 if ($GLOBALS['athletic_team']) {
2310 // Skip fitness level and return-to-play date because those appear
2311 // in a special display/update form on this page.
2312 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2314 if (strpos($field_id, 'em_') === 0) {
2315 // Skip employer related fields, if it's disabled.
2316 if ($GLOBALS['omit_employers']) continue;
2317 $tmp = substr($field_id, 3);
2318 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2320 else {
2321 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2324 else {
2325 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2328 // Handle a data category (group) change.
2329 if (strcmp($this_group, $last_group) != 0) {
2330 $group_name = substr($this_group, 1);
2331 // totally skip generating the employer category, if it's disabled.
2332 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2333 disp_end_group();
2334 $last_group = $this_group;
2337 // filter out all the empty field data from the patient report.
2338 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2339 // Handle starting of a new row.
2340 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2341 disp_end_row();
2342 echo "<tr>";
2343 if ($group_name) {
2344 echo "<td class='groupname'>";
2345 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2346 //echo "<font color='#008800'>$group_name</font>";
2348 // Added 5-09 by BM - Translate label if applicable
2349 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
2351 $group_name = '';
2352 } else {
2353 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2354 echo "<td valign='top'>&nbsp;";
2356 echo "</td>";
2359 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2361 // Handle starting of a new label cell.
2362 if ($titlecols > 0) {
2363 disp_end_cell();
2364 //echo "<td class='label' colspan='$titlecols' valign='top'";
2365 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2366 echo "<td class='label' colspan='$titlecols_esc' ";
2367 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2368 echo ">";
2369 $cell_count += $titlecols;
2371 ++$item_count;
2373 // Added 5-09 by BM - Translate label if applicable
2374 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2376 // Handle starting of a new data cell.
2377 if ($datacols > 0) {
2378 disp_end_cell();
2379 //echo "<td class='text data' colspan='$datacols' valign='top'";
2380 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2381 echo "<td class='text data' colspan='$datacols_esc'";
2382 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2383 echo ">";
2384 $cell_count += $datacols;
2387 ++$item_count;
2388 echo generate_display_field($frow, $currvalue);
2392 disp_end_group();
2395 function display_layout_tabs($formtype, $result1, $result2='') {
2396 global $item_count, $cell_count, $last_group, $CPR;
2398 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2399 "WHERE form_id = ? AND uor > 0 " .
2400 "ORDER BY group_name, seq", array($formtype) );
2402 $first = true;
2403 while ($frow = sqlFetchArray($fres)) {
2404 $this_group = $frow['group_name'];
2405 $group_name = substr($this_group, 1);
2406 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2408 <li <?php echo $first ? 'class="current"' : '' ?>>
2409 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
2410 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
2411 </li>
2412 <?php
2413 $first = false;
2417 function display_layout_tabs_data($formtype, $result1, $result2='') {
2418 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2420 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2421 "WHERE form_id = ? AND uor > 0 " .
2422 "ORDER BY group_name, seq", array($formtype));
2424 $first = true;
2425 while ($frow = sqlFetchArray($fres)) {
2426 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
2427 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
2428 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
2429 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
2430 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
2431 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
2432 $currvalue = '';
2434 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2436 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2437 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2438 "ORDER BY seq", array($formtype, $this_group) );
2441 <div class="tab <?php echo $first ? 'current' : '' ?>">
2442 <table border='0' cellpadding='0'>
2444 <?php
2445 while ($group_fields = sqlFetchArray($group_fields_query)) {
2447 $titlecols = $group_fields['titlecols'];
2448 $datacols = $group_fields['datacols'];
2449 $data_type = $group_fields['data_type'];
2450 $field_id = $group_fields['field_id'];
2451 $list_id = $group_fields['list_id'];
2452 $currvalue = '';
2453 $condition_str = get_conditions_str($condition_str,$group_fields);
2456 if ($formtype == 'DEM') {
2457 if ($GLOBALS['athletic_team']) {
2458 // Skip fitness level and return-to-play date because those appear
2459 // in a special display/update form on this page.
2460 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2462 if (strpos($field_id, 'em_') === 0) {
2463 // Skip employer related fields, if it's disabled.
2464 if ($GLOBALS['omit_employers']) continue;
2465 $tmp = substr($field_id, 3);
2466 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2468 else {
2469 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2472 else {
2473 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2476 // Handle a data category (group) change.
2477 if (strcmp($this_group, $last_group) != 0) {
2478 $group_name = substr($this_group, 1);
2479 // totally skip generating the employer category, if it's disabled.
2480 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2481 $last_group = $this_group;
2484 // Handle starting of a new row.
2485 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2486 disp_end_row();
2487 echo "<tr>";
2490 if ($item_count == 0 && $titlecols == 0) {
2491 $titlecols = 1;
2494 // Handle starting of a new label cell.
2495 if ($titlecols > 0) {
2496 disp_end_cell();
2497 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2498 $field_id_label = 'label_'.$group_fields['field_id'];
2499 echo "<td class='label' colspan='$titlecols_esc' id='$field_id_label'";
2500 echo ">";
2501 $cell_count += $titlecols;
2503 ++$item_count;
2505 $field_id_label = 'label_'.$group_fields['field_id'];
2506 echo "<span id='".$field_id_label."'>";
2507 // Added 5-09 by BM - Translate label if applicable
2508 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2509 echo "</span>";
2511 // Handle starting of a new data cell.
2512 if ($datacols > 0) {
2513 disp_end_cell();
2514 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2515 $field_id = 'text_'.$group_fields['field_id'];
2516 echo "<td class='text data' colspan='$datacols_esc' id='$field_id' data-value='$currvalue'";
2517 echo ">";
2518 $cell_count += $datacols;
2519 } else {
2520 $field_id = 'text_'.$group_fields['field_id'];
2521 echo "<span id='".$field_id."' style='display:none'>$currvalue</span>";
2524 ++$item_count;
2525 echo generate_display_field($group_fields, $currvalue);
2528 disp_end_row();
2531 </table>
2532 </div>
2534 <?php
2536 $first = false;
2542 function get_conditions_str($condition_str,$frow){
2543 $conditions = empty($frow['conditions']) ? array() : unserialize($frow['conditions']);
2544 foreach ($conditions as $condition) {
2545 if (empty($condition['id'])) continue;
2546 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2547 if ($condition_str) $condition_str .= ",\n";
2548 $condition_str .= "{" .
2549 "target:'" . addslashes($frow['field_id']) . "', " .
2550 "id:'" . addslashes($condition['id']) . "', " .
2551 "itemid:'" . addslashes($condition['itemid']) . "', " .
2552 "operator:'" . addslashes($condition['operator']) . "', " .
2553 "value:'" . addslashes($condition['value']) . "', " .
2554 "andor:'" . addslashes($andor) . "'}";
2556 return $condition_str;
2558 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2559 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2561 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2562 "WHERE form_id = ? AND uor > 0 " .
2563 "ORDER BY group_name, seq", array($formtype) );
2565 $first = true;
2566 while ($frow = sqlFetchArray($fres)) {
2567 $this_group = $frow['group_name'];
2568 $group_name = substr($this_group, 1);
2569 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
2570 $titlecols = $frow['titlecols'];
2571 $datacols = $frow['datacols'];
2572 $data_type = $frow['data_type'];
2573 $field_id = $frow['field_id'];
2574 $list_id = $frow['list_id'];
2575 $currvalue = '';
2577 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2579 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2580 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2581 "ORDER BY seq", array($formtype,$this_group) );
2584 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
2585 <table border='0' cellpadding='0'>
2587 <?php
2588 while ($group_fields = sqlFetchArray($group_fields_query)) {
2590 $titlecols = $group_fields['titlecols'];
2591 $datacols = $group_fields['datacols'];
2592 $data_type = $group_fields['data_type'];
2593 $field_id = $group_fields['field_id'];
2594 $list_id = $group_fields['list_id'];
2595 $backup_list = $group_fields['list_backup_id'];
2596 $condition_str = get_conditions_str($condition_str,$group_fields);
2597 $currvalue = '';
2599 if ($formtype == 'DEM') {
2600 if ($GLOBALS['athletic_team']) {
2601 // Skip fitness level and return-to-play date because those appear
2602 // in a special display/update form on this page.
2603 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
2605 if (strpos($field_id, 'em_') === 0) {
2606 // Skip employer related fields, if it's disabled.
2607 if ($GLOBALS['omit_employers']) continue;
2608 $tmp = substr($field_id, 3);
2609 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2611 else {
2612 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2615 else {
2616 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2619 // Handle a data category (group) change.
2620 if (strcmp($this_group, $last_group) != 0) {
2621 $group_name = substr($this_group, 1);
2622 // totally skip generating the employer category, if it's disabled.
2623 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2624 $last_group = $this_group;
2627 // Handle starting of a new row.
2628 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2629 disp_end_row();
2630 echo "<tr>";
2633 if ($item_count == 0 && $titlecols == 0) {
2634 $titlecols = 1;
2637 // Handle starting of a new label cell.
2638 if ($titlecols > 0) {
2639 disp_end_cell();
2640 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2641 $field_id_label = 'label_'.$group_fields['field_id'];
2642 echo "<td class='label' colspan='$titlecols_esc' id='$field_id_label' ";
2643 echo ">";
2644 $cell_count += $titlecols;
2646 ++$item_count;
2648 // Added 5-09 by BM - Translate label if applicable
2649 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
2651 // Handle starting of a new data cell.
2652 if ($datacols > 0) {
2653 disp_end_cell();
2654 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2655 $field_id = 'text_'.$group_fields['field_id'];
2656 echo "<td class='text data' colspan='$datacols_esc' id='$field_id'";
2657 echo ">";
2658 $cell_count += $datacols;
2661 ++$item_count;
2663 echo generate_form_field($group_fields, $currvalue);
2667 </table>
2668 </div>
2670 <?php
2672 $first = false;
2677 // From the currently posted HTML form, this gets the value of the
2678 // field corresponding to the provided layout_options table row.
2680 function get_layout_form_value($frow, $prefix='form_') {
2681 // Bring in $sanitize_all_escapes variable, which will decide
2682 // the variable escaping method.
2683 global $sanitize_all_escapes;
2685 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
2686 $data_type = $frow['data_type'];
2687 $field_id = $frow['field_id'];
2688 $value = '';
2689 if (isset($_POST["$prefix$field_id"])) {
2690 if ($data_type == 21) {
2691 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2692 // must be concatenated into a |-separated string.
2693 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2694 if (strlen($value)) $value .= '|';
2695 $value .= $key;
2698 else if ($data_type == 22) {
2699 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2700 // into "key:value|key:value|...".
2701 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2702 $val = str_replace('|', ' ', $val);
2703 if (strlen($value)) $value .= '|';
2704 $value .= "$key:$val";
2707 else if ($data_type == 23) {
2708 // $_POST["$prefix$field_id"] is an array of text fields with companion
2709 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2710 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2711 $restype = $_POST["radio_{$field_id}"][$key];
2712 if (empty($restype)) $restype = '0';
2713 $val = str_replace('|', ' ', $val);
2714 if (strlen($value)) $value .= '|';
2715 $value .= "$key:$restype:$val";
2718 else if ($data_type == 25) {
2719 // $_POST["$prefix$field_id"] is an array of text fields with companion
2720 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2721 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2722 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
2723 $val = str_replace('|', ' ', $val);
2724 if (strlen($value)) $value .= '|';
2725 $value .= "$key:$restype:$val";
2728 else if ($data_type == 28 || $data_type == 32) {
2729 // $_POST["$prefix$field_id"] is an date text fields with companion
2730 // radio buttons to be imploded into "notes|type|date".
2731 $restype = $_POST["radio_{$field_id}"];
2732 if (empty($restype)) $restype = '0';
2733 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2734 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2735 if ($data_type == 32)
2737 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2738 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2739 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2740 $value = "$res_text_note|$restype|$resdate|$reslist";
2742 else
2743 $value = "$resnote|$restype|$resdate";
2745 else if ($data_type == 36) {
2746 $value_array = $_POST["form_$field_id"];
2747 $i = 0;
2748 foreach ($value_array as $key => $valueofkey) {
2749 if ($i == 0) {
2750 $value = $valueofkey;
2751 } else {
2752 $value = $value . "|" . $valueofkey;
2754 $i++;
2757 else {
2758 $value = $_POST["$prefix$field_id"];
2762 // Better to die than to silently truncate data!
2763 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2764 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2765 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2767 // Make sure the return value is quote-safe.
2768 if ($sanitize_all_escapes) {
2769 //escapes already removed and using binding/placemarks in sql calls
2770 // so only need to trim value
2771 return trim($value);
2773 else {
2774 //need to explicitly prepare value
2775 return formTrim($value);
2779 // Generate JavaScript validation logic for the required fields.
2781 function generate_layout_validation($form_id) {
2782 $fres = sqlStatement("SELECT * FROM layout_options " .
2783 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2784 "ORDER BY group_name, seq", array($form_id) );
2786 while ($frow = sqlFetchArray($fres)) {
2787 if ($frow['uor'] < 2) continue;
2788 $data_type = $frow['data_type'];
2789 $field_id = $frow['field_id'];
2790 $fldtitle = $frow['title'];
2791 if (!$fldtitle) $fldtitle = $frow['description'];
2792 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
2793 switch($data_type) {
2794 case 1:
2795 case 11:
2796 case 12:
2797 case 13:
2798 case 14:
2799 case 26:
2800 case 33:
2801 echo
2802 " if (f.$fldname.selectedIndex <= 0) {\n" .
2803 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2804 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2805 " }\n";
2806 break;
2807 case 27: // radio buttons
2808 echo
2809 " var i = 0;\n" .
2810 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2811 " if (i >= f.$fldname.length) {\n" .
2812 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2813 " }\n";
2814 break;
2815 case 2:
2816 case 3:
2817 case 4:
2818 case 15:
2819 echo
2820 " if (trimlen(f.$fldname.value) == 0) {\n" .
2821 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2822 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2823 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2824 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2825 " } else { " .
2826 " $('#" . $fldname . "').attr('style',''); " .
2827 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2828 " } \n";
2829 break;
2830 case 36: // multi select
2831 echo
2832 " var multi_select=f['$fldname"."[]']; \n " .
2833 " var multi_choice_made=false; \n".
2834 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
2835 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
2836 " } \n" .
2837 " if(!multi_choice_made)
2838 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2840 break;
2846 * DROPDOWN FOR FACILITIES
2848 * build a dropdown with all facilities
2850 * @param string $selected - name of the currently selected facility
2851 * use '0' for "unspecified facility"
2852 * use '' for "All facilities" (the default)
2853 * @param string $name - the name/id for select form (defaults to "form_facility")
2854 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2855 * defaults to true
2856 * @return void - just echo the html encoded string
2858 * Note: This should become a data-type at some point, according to Brady
2860 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2861 $allow_allfacilities = true, $disabled='', $onchange='')
2863 $have_selected = false;
2864 $query = "SELECT id, name FROM facility ORDER BY name";
2865 $fres = sqlStatement($query);
2867 $name = htmlspecialchars($name, ENT_QUOTES);
2868 echo " <select name='$name' id='$name'";
2869 if ($onchange) echo " onchange='$onchange'";
2870 echo " $disabled>\n";
2872 if ($allow_allfacilities) {
2873 $option_value = '';
2874 $option_selected_attr = '';
2875 if ($selected == '') {
2876 $option_selected_attr = ' selected="selected"';
2877 $have_selected = true;
2879 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2880 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2881 } elseif ($allow_unspecified) {
2882 $option_value = '0';
2883 $option_selected_attr = '';
2884 if ( $selected == '0' ) {
2885 $option_selected_attr = ' selected="selected"';
2886 $have_selected = true;
2888 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2889 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2892 while ($frow = sqlFetchArray($fres)) {
2893 $facility_id = $frow['id'];
2894 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2895 $option_selected_attr = '';
2896 if ($selected == $facility_id) {
2897 $option_selected_attr = ' selected="selected"';
2898 $have_selected = true;
2900 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2901 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2904 if ($allow_unspecified && $allow_allfacilities) {
2905 $option_value = '0';
2906 $option_selected_attr = '';
2907 if ( $selected == '0' ) {
2908 $option_selected_attr = ' selected="selected"';
2909 $have_selected = true;
2911 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2912 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2915 if (!$have_selected) {
2916 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2917 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2918 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2919 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2921 echo " </select>\n";
2924 // Expand Collapse Widget
2925 // This forms the header and functionality component of the widget. The information that is displayed
2926 // then follows this function followed by a closing div tag
2928 // $title is the title of the section (already translated)
2929 // $label is identifier used in the tag id's and sql columns
2930 // $buttonLabel is the button label text (already translated)
2931 // $buttonLink is the button link information
2932 // $buttonClass is any additional needed class elements for the button tag
2933 // $linkMethod is the button link method ('javascript' vs 'html')
2934 // $bodyClass is to set class(es) of the body
2935 // $auth is a flag to decide whether to show the button
2936 // $fixedWidth is to flag whether width is fixed
2937 // $forceExpandAlways is a flag to force the widget to always be expanded
2939 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2940 if ($fixedWidth) {
2941 echo "<div class='section-header'>";
2943 else {
2944 echo "<div class='section-header-dynamic'>";
2946 echo "<table><tr>";
2947 if ($auth) {
2948 // show button, since authorized
2949 // first prepare class string
2950 if ($buttonClass) {
2951 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2953 else {
2954 $class_string = "css_button_small";
2956 // next, create the link
2957 if ($linkMethod == "javascript") {
2958 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2960 else {
2961 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2962 if (!isset($_SESSION['patient_portal_onsite'])) {
2963 // prevent an error from occuring when calling the function from the patient portal
2964 echo " onclick='top.restoreSession()'";
2967 if (!$GLOBALS['concurrent_layout']) {
2968 echo " target='Main'";
2970 echo "><span>" .
2971 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2973 if ($forceExpandAlways){
2974 // Special case to force the widget to always be expanded
2975 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2976 $indicatorTag ="style='display:none'";
2978 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
2979 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2980 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
2981 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2983 if (isset($_SESSION['patient_portal_onsite'])) {
2984 // collapse all entries in the patient portal
2985 $text = xl('expand');
2987 else if (getUserSetting($label."_ps_expand")) {
2988 $text = xl('collapse');
2990 else {
2991 $text = xl('expand');
2993 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
2994 "</span>)</a></td>";
2995 echo "</tr></table>";
2996 echo "</div>";
2997 if ($forceExpandAlways) {
2998 // Special case to force the widget to always be expanded
2999 $styling = "";
3001 else if (isset($_SESSION['patient_portal_onsite'])) {
3002 // collapse all entries in the patient portal
3003 $styling = "style='display:none'";
3005 else if (getUserSetting($label."_ps_expand")) {
3006 $styling = "";
3008 else {
3009 $styling = "style='display:none'";
3011 if ($bodyClass) {
3012 $styling .= " class='" . $bodyClass . "'";
3014 //next, create the first div tag to hold the information
3015 // note the code that calls this function will then place the ending div tag after the data
3016 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
3019 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3020 function billing_facility($name,$select){
3021 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
3022 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3023 while ($facrow = sqlFetchArray($qsql)) {
3024 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3025 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3027 echo "</select>";
3030 // Generic function to get the translated title value for a particular list option.
3032 function getListItemTitle($list, $option) {
3033 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3034 "list_id = ? AND option_id = ?", array($list, $option));
3035 if (empty($row['title'])) return $option;
3036 return xl_list_label($row['title']);
3038 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3039 function getSmokeCodes()
3041 $smoking_codes_arr = array();
3042 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status'");
3043 while($codes_row = sqlFetchArray($smoking_codes))
3045 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3047 return $smoking_codes_arr;
3050 // Get the current value for a layout based form field.
3051 // Depending on options this might come from lbf_data, patient_data,
3052 // form_encounter, shared_attributes or elsewhere.
3053 // Returns FALSE if the field ID is invalid (layout error).
3055 function lbf_current_value($frow, $formid, $encounter) {
3056 global $pid;
3057 $formname = $frow['form_id'];
3058 $field_id = $frow['field_id'];
3059 $source = $frow['source'];
3060 $currvalue = '';
3061 $deffname = $formname . '_default_' . $field_id;
3062 if ($source == 'D' || $source == 'H') {
3063 // Get from patient_data, employer_data or history_data.
3064 if ($source == 'H') {
3065 $table = 'history_data';
3066 $orderby = 'ORDER BY date DESC LIMIT 1';
3068 else if (strpos($field_id, 'em_') === 0) {
3069 $field_id = substr($field_id, 3);
3070 $table = 'employer_data';
3071 $orderby = 'ORDER BY date DESC LIMIT 1';
3073 else {
3074 $table = 'patient_data';
3075 $orderby = '';
3077 // It is an error if the field does not exist, but don't crash.
3078 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3079 if (empty($tmp)) return FALSE;
3080 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3081 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3083 else if ($source == 'E') {
3084 if ($encounter) {
3085 // Get value from shared_attributes of the current encounter.
3086 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3087 "pid = ? AND encounter = ? AND field_id = ?",
3088 array($pid, $encounter, $field_id));
3089 if (isset($sarow)) $currvalue = $sarow['field_value'];
3091 else if ($formid) {
3092 // Get from shared_attributes of the encounter that this form is linked to.
3093 // Note the importance of having an index on forms.form_id.
3094 $sarow = sqlQuery("SELECT sa.field_value " .
3095 "FROM forms AS f, shared_attributes AS sa WHERE " .
3096 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3097 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3098 array($formid, $formname, $field_id));
3099 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3101 else {
3102 // New form and encounter not available, this should not happen.
3105 else if ($source == 'V') {
3106 if ($encounter) {
3107 // Get value from the current encounter's form_encounter.
3108 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3109 "pid = ? AND encounter = ?",
3110 array($pid, $encounter));
3111 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3113 else if ($formid) {
3114 // Get value from the form_encounter that this form is linked to.
3115 $ferow = sqlQuery("SELECT fe.* " .
3116 "FROM forms AS f, form_encounter AS fe WHERE " .
3117 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3118 "fe.pid = f.pid AND fe.encounter = f.encounter",
3119 array($formid, $formname));
3120 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3122 else {
3123 // New form and encounter not available, this should not happen.
3126 else if ($formid) {
3127 // This is a normal form field.
3128 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3129 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3130 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3132 else {
3133 // New form, see if there is a custom default from a plugin.
3134 // This logic does not apply to shared attributes because they do not
3135 // have a "new form" concept.
3136 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3138 return $currvalue;