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>
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");
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 " .
54 "ORDER BY name, area_code, prefix, number");
57 function optionalAge($frow, $date, &$asof) {
59 if (empty($date)) return '';
60 $date = substr($date, 0, 10);
61 if (strpos($frow['edit_options'], 'A') !== FALSE) {
64 else if (strpos($frow['edit_options'], 'B') !== FALSE) {
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 = '') {
86 $tag_name_esc = attr($tag_name);
89 $tag_name_esc = $tag_name_esc . "[]";
91 $s .= "<select name='$tag_name_esc'";
94 $s .= " multiple='multiple'";
97 $tag_id_esc = $tag_name_esc;
99 $tag_id_esc = attr($tag_id);
103 $tag_id_esc = $tag_id_esc . "[]";
105 $s .= " id='$tag_id_esc'";
108 $class_esc = attr($class);
109 $s .= " class='$class_esc'";
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);
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 ))) {
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>";
168 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
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'";
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>";
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>";
214 // $frow is a row from the layout_options table.
215 // $currvalue is the current value, if any, of the associated item.
217 function generate_form_field($frow, $currvalue) {
218 global $rootdir, $date_init, $ISSUE_TYPES, $code_types;
220 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
222 $data_type = $frow['data_type'];
223 $field_id = $frow['field_id'];
224 $list_id = $frow['list_id'];
225 $backup_list = $frow['list_backup_id'];
227 // escaped variables to use in html
228 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES
);
229 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES
);
231 // Added 5-09 by BM - Translate description if applicable
232 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
234 // Support edit option T which assigns the (possibly very long) description as
235 // the default value.
236 if (strpos($frow['edit_options'], 'T') !== FALSE) {
237 if (strlen($currescaped) == 0) $currescaped = $description;
238 // Description used in this way is not suitable as a title.
242 // added 5-2009 by BM to allow modification of the 'empty' text title field.
243 // Can pass $frow['empty_title'] with this variable, otherwise
244 // will default to 'Unassigned'.
245 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
246 // if make $frow['empty_title'] equal to 'SKIP'
248 if (isset($frow['empty_title'])) {
249 if ($frow['empty_title'] == "SKIP") {
250 //do not display an 'empty' choice
252 $empty_title = "Unassigned";
255 $empty_title = $frow['empty_title'];
259 $empty_title = "Unassigned";
262 $disabled = strpos($frow['edit_options'], '0') === FALSE ?
'' : 'disabled';
264 $lbfchange = (strpos($frow['form_id'], 'LBF') === 0 ||
strpos($frow['form_id'], 'LBT') === 0) ?
265 "checkSkipConditions();" : "";
266 $lbfonchange = $lbfchange ?
"onchange='$lbfchange'" : "";
268 // generic single-selection list or Race and Ethnicity.
269 // These data types support backup lists.
270 if ($data_type == 1 ||
$data_type == 33) {
271 echo generate_select_list("form_$field_id", $list_id, $currvalue,
272 $description, ($showEmpty ?
$empty_title : ''), '', $lbfchange, '',
273 ($disabled ?
array('disabled' => 'disabled') : null), false, $backup_list);
277 else if ($data_type == 2) {
278 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
279 $maxlength = $frow['max_length'];
280 $string_maxlength = "";
281 // if max_length is set to zero, then do not set a maxlength
282 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
283 echo "<input type='text'" .
284 " name='form_$field_id_esc'" .
285 " id='form_$field_id_esc'" .
286 " size='$fldlength'" .
287 " $string_maxlength" .
288 " title='$description'" .
289 " value='$currescaped'";
291 if (strpos($frow['edit_options'], 'C') !== FALSE)
292 $tmp .= "capitalizeMe(this);";
293 else if (strpos($frow['edit_options'], 'U') !== FALSE)
294 $tmp .= "this.value = this.value.toUpperCase();";
295 if ($tmp) echo " onchange='$tmp'";
296 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES
);
297 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
298 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
299 echo " onblur='maskblur(this,\"$tmp\")'";
301 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
304 if ($disabled) echo ' disabled';
308 // long or multi-line text field
309 else if ($data_type == 3) {
310 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
311 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES
);
313 " name='form_$field_id_esc'" .
314 " id='form_$field_id_esc'" .
315 " title='$description'" .
316 " cols='$textCols'" .
317 " rows='$textRows' $lbfonchange $disabled" .
318 ">" . $currescaped . "</textarea>";
322 else if ($data_type == 4) {
323 $age_asof_date = ''; // optionalAge() sets this
324 $age_format = strpos($frow['edit_options'], 'A') === FALSE ?
3 : 0;
325 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
327 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
329 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
330 " value='" . substr($currescaped, 0, 10) . "'";
331 if (!$agestr) echo " title='$description'";
332 echo " $lbfonchange onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
334 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
335 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
336 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' />";
337 $date_init .= " Calendar.setup({" .
338 "inputField:'form_$field_id', " .
339 "ifFormat:'%Y-%m-%d', ";
341 $date_init .= "onUpdate: function() {" .
342 "if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format);" .
345 $date_init .= "button:'img_$field_id'})\n";
347 // Optional display of age or gestational age.
349 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
353 // provider list, local providers only
354 else if ($data_type == 10) {
355 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
356 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
357 "AND authorized = 1 " .
358 "ORDER BY lname, fname");
359 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled>";
360 echo "<option value=''>" . xlt($empty_title) . "</option>";
361 $got_selected = false;
362 while ($urow = sqlFetchArray($ures)) {
363 $uname = text($urow['fname'] . ' ' . $urow['lname']);
364 $optionId = attr($urow['id']);
365 echo "<option value='$optionId'";
366 if ($urow['id'] == $currvalue) {
368 $got_selected = true;
370 echo ">$uname</option>";
372 if (!$got_selected && $currvalue) {
373 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
375 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
382 // provider list, including address book entries with an NPI number
383 else if ($data_type == 11) {
384 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
385 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
386 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
387 "ORDER BY lname, fname");
388 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
389 echo " $lbfonchange $disabled>";
390 echo "<option value=''>" . xlt('Unassigned') . "</option>";
391 $got_selected = false;
392 while ($urow = sqlFetchArray($ures)) {
393 $uname = text($urow['fname'] . ' ' . $urow['lname']);
394 $optionId = attr($urow['id']);
395 echo "<option value='$optionId'";
396 if ($urow['id'] == $currvalue) {
398 $got_selected = true;
400 echo ">$uname</option>";
402 if (!$got_selected && $currvalue) {
403 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
405 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
413 else if ($data_type == 12) {
414 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
415 echo " $lbfonchange $disabled>";
416 echo "<option value='0'></option>";
417 $pres = get_pharmacies();
418 $got_selected = false;
419 while ($prow = sqlFetchArray($pres)) {
421 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
422 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
423 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
424 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
425 echo "<option value='$optionValue'";
426 if ($currvalue == $key) {
428 $got_selected = true;
430 echo ">$optionLabel</option>";
432 if (!$got_selected && $currvalue) {
433 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
435 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
443 else if ($data_type == 13) {
444 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
445 echo " $lbfonchange $disabled>";
446 echo "<option value=''> </option>";
447 $squads = acl_get_squads();
449 foreach ($squads as $key => $value) {
450 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
451 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES
);
452 echo "<option value='$optionValue'";
453 if ($currvalue == $key) echo " selected";
454 echo ">$optionLabel</option>\n";
460 // Address book, preferring organization name if it exists and is not in
461 // parentheses, and excluding local users who are not providers.
462 // Supports "referred to" practitioners and facilities.
463 // Alternatively the letter L in edit_options means that abook_type
464 // must be "ord_lab", indicating types used with the procedure
465 // lab ordering system.
466 // Alternatively the letter O in edit_options means that abook_type
467 // must begin with "ord_", indicating types used with the procedure
469 // Alternatively the letter V in edit_options means that abook_type
470 // must be "vendor", indicating the Vendor type.
471 // Alternatively the letter R in edit_options means that abook_type
472 // must be "dist", indicating the Distributor type.
473 else if ($data_type == 14) {
474 if (strpos($frow['edit_options'], 'L') !== FALSE)
475 $tmp = "abook_type = 'ord_lab'";
476 else if (strpos($frow['edit_options'], 'O') !== FALSE)
477 $tmp = "abook_type LIKE 'ord\\_%'";
478 else if (strpos($frow['edit_options'], 'V') !== FALSE)
479 $tmp = "abook_type LIKE 'vendor%'";
480 else if (strpos($frow['edit_options'], 'R') !== FALSE)
481 $tmp = "abook_type LIKE 'dist'";
483 $tmp = "( username = '' OR authorized = 1 )";
484 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
485 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
487 "ORDER BY organization, lname, fname");
488 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
489 echo " $lbfonchange $disabled>";
490 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
491 while ($urow = sqlFetchArray($ures)) {
492 $uname = $urow['organization'];
493 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
494 $uname = $urow['lname'];
495 if ($urow['fname']) $uname .= ", " . $urow['fname'];
497 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES
);
498 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES
);
499 echo "<option value='$optionValue'";
500 $title = $urow['username'] ?
xl('Local') : xl('External');
501 $optionTitle = htmlspecialchars( $title, ENT_QUOTES
);
502 echo " title='$optionTitle'";
503 if ($urow['id'] == $currvalue) echo " selected";
504 echo ">$optionLabel</option>";
509 // A billing code. If description matches an existing code type then that type is used.
510 else if ($data_type == 15) {
511 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
512 $maxlength = $frow['max_length'];
513 $string_maxlength = "";
514 // if max_length is set to zero, then do not set a maxlength
515 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
517 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
518 // Option "2" generates a hidden input for the codes, and a matching visible field
519 // displaying their descriptions. First step is computing the description string.
520 $currdescstring = '';
521 if (!empty($currvalue)) {
522 $relcodes = explode(';', $currvalue);
523 foreach ($relcodes as $codestring) {
524 if ($codestring === '') continue;
525 $code_text = lookup_code_descriptions($codestring);
526 if ($currdescstring !== '') $currdescstring .= '; ';
527 if (!empty($code_text)) {
528 $currdescstring .= $code_text;
531 $currdescstring .= $codestring;
535 $currdescstring = attr($currdescstring);
537 echo "<input type='text'" .
538 " name='form_$field_id_esc'" .
539 " id='form_related_code'" .
540 " size='$fldlength'" .
541 " value='$currescaped'" .
542 " style='display:none'" .
543 " $lbfonchange readonly $disabled />";
544 // Extra readonly input field for optional display of code description(s).
545 echo "<input type='text'" .
546 " name='form_$field_id_esc" . "__desc'" .
547 " size='$fldlength'" .
548 " title='$description'" .
549 " value='$currdescstring'";
551 echo " onclick='sel_related(this,\"$codetype\")'";
553 echo " readonly $disabled />";
556 echo "<input type='text'" .
557 " name='form_$field_id_esc'" .
558 " id='form_related_code'" .
559 " size='$fldlength'" .
560 " $string_maxlength" .
561 " title='$description'" .
562 " value='$currescaped'";
564 echo " onclick='sel_related(this,\"$codetype\")'";
566 echo " $lbfonchange readonly $disabled />";
570 // insurance company list
571 else if ($data_type == 16) {
572 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
573 echo "<option value='0'></option>";
574 $insprovs = getInsuranceProviders();
575 $got_selected = false;
576 foreach ($insprovs as $key => $ipname) {
577 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
578 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES
);
579 echo "<option value='$optionValue'";
580 if ($currvalue == $key) {
582 $got_selected = true;
584 echo ">$optionLabel</option>";
586 if (!$got_selected && $currvalue) {
587 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
589 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
597 else if ($data_type == 17) {
598 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
599 echo "<option value='0'></option>";
600 $got_selected = false;
601 foreach ($ISSUE_TYPES as $key => $value) {
602 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
603 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES
);
604 echo "<option value='$optionValue'";
605 if ($currvalue == $key) {
607 $got_selected = true;
609 echo ">$optionLabel</option>";
611 if (!$got_selected && strlen($currvalue) > 0) {
612 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
614 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
622 else if ($data_type == 18) {
623 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
624 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
625 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
626 " $lbfonchange $disabled>";
627 echo "<option value=''>" . xlt($empty_title) . "</option>";
628 $got_selected = false;
629 while ($crow = sqlFetchArray($cres)) {
630 $catid = $crow['pc_catid'];
631 if (($catid < 9 && $catid != 5) ||
$catid == 11) continue;
632 echo "<option value='" . attr($catid) . "'";
633 if ($catid == $currvalue) {
635 $got_selected = true;
637 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
639 if (!$got_selected && $currvalue) {
640 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
642 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
649 // a set of labeled checkboxes
650 else if ($data_type == 21) {
651 // In this special case, fld_length is the number of columns generated.
652 $cols = max(1, $frow['fld_length']);
653 $avalue = explode('|', $currvalue);
654 $lres = sqlStatement("SELECT * FROM list_options " .
655 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
656 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
657 $tdpct = (int) (100 / $cols);
658 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
659 $option_id = $lrow['option_id'];
660 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
661 // if ($count) echo "<br />";
662 if ($count %
$cols == 0) {
663 if ($count) echo "</tr>";
666 echo "<td width='$tdpct%'>";
667 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
668 "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
669 if (in_array($option_id, $avalue)) echo " checked";
671 // Added 5-09 by BM - Translate label if applicable
672 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
678 if ($count > $cols) {
679 // Add some space after multiple rows of checkboxes.
680 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
681 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
687 // a set of labeled text input fields
688 else if ($data_type == 22) {
689 $tmp = explode('|', $currvalue);
691 foreach ($tmp as $value) {
692 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
693 $avalue[$matches[1]] = $matches[2];
696 $lres = sqlStatement("SELECT * FROM list_options " .
697 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
698 echo "<table cellpadding='0' cellspacing='0'>";
699 while ($lrow = sqlFetchArray($lres)) {
700 $option_id = $lrow['option_id'];
701 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
702 $maxlength = $frow['max_length'];
703 $string_maxlength = "";
704 // if max_length is set to zero, then do not set a maxlength
705 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
706 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
708 // Added 5-09 by BM - Translate label if applicable
709 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
710 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
711 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
712 echo "<td><input type='text'" .
713 " name='form_{$field_id_esc}[$option_id_esc]'" .
714 " id='form_{$field_id_esc}[$option_id_esc]'" .
715 " size='$fldlength'" .
716 " $string_maxlength" .
717 " value='$optionValue'";
718 echo " $lbfonchange $disabled /></td></tr>";
723 // a set of exam results; 3 radio buttons and a text field:
724 else if ($data_type == 23) {
725 $tmp = explode('|', $currvalue);
727 foreach ($tmp as $value) {
728 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
729 $avalue[$matches[1]] = $matches[2];
732 $maxlength = $frow['max_length'];
733 $string_maxlength = "";
734 // if max_length is set to zero, then do not set a maxlength
735 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
736 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
737 $lres = sqlStatement("SELECT * FROM list_options " .
738 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
739 echo "<table cellpadding='0' cellspacing='0'>";
740 echo "<tr><td> </td><td class='bold'>" .
741 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
742 " </td><td class='bold'>" .
743 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
744 "<td class='bold'>" .
745 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
746 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
747 while ($lrow = sqlFetchArray($lres)) {
748 $option_id = $lrow['option_id'];
749 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
750 $restype = substr($avalue[$option_id], 0, 1);
751 $resnote = substr($avalue[$option_id], 2);
753 // Added 5-09 by BM - Translate label if applicable
754 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
756 for ($i = 0; $i < 3; ++
$i) {
757 $inputValue = htmlspecialchars( $i, ENT_QUOTES
);
758 echo "<td><input type='radio'" .
759 " name='radio_{$field_id_esc}[$option_id_esc]'" .
760 " id='radio_{$field_id_esc}[$option_id_esc]'" .
761 " value='$inputValue' $lbfonchange";
762 if ($restype === "$i") echo " checked";
763 echo " $disabled /></td>";
765 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
766 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
767 echo "<td><input type='text'" .
768 " name='form_{$field_id_esc}[$option_id_esc]'" .
769 " id='form_{$field_id_esc}[$option_id_esc]'" .
770 " size='$fldlength'" .
771 " $string_maxlength" .
772 " value='$resnote' $disabled /></td>";
778 // the list of active allergies for the current patient
779 // this is read-only!
780 else if ($data_type == 24) {
781 $query = "SELECT title, comments FROM lists WHERE " .
782 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
784 // echo "<!-- $query -->\n"; // debugging
785 $lres = sqlStatement($query, array($GLOBALS['pid']));
787 while ($lrow = sqlFetchArray($lres)) {
788 if ($count++
) echo "<br />";
789 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES
);
790 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES
) . ')';
794 // a set of labeled checkboxes, each with a text field:
795 else if ($data_type == 25) {
796 $tmp = explode('|', $currvalue);
798 foreach ($tmp as $value) {
799 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
800 $avalue[$matches[1]] = $matches[2];
803 $maxlength = $frow['max_length'];
804 $string_maxlength = "";
805 // if max_length is set to zero, then do not set a maxlength
806 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
807 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
808 $lres = sqlStatement("SELECT * FROM list_options " .
809 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
810 echo "<table cellpadding='0' cellspacing='0'>";
811 while ($lrow = sqlFetchArray($lres)) {
812 $option_id = $lrow['option_id'];
813 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
814 $restype = substr($avalue[$option_id], 0, 1);
815 $resnote = substr($avalue[$option_id], 2);
817 // Added 5-09 by BM - Translate label if applicable
818 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
820 $option_id = htmlspecialchars( $option_id, ENT_QUOTES
);
821 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
822 " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
823 if ($restype) echo " checked";
824 echo " $disabled /> </td>";
825 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
826 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
827 echo "<td><input type='text'" .
828 " name='form_{$field_id_esc}[$option_id_esc]'" .
829 " id='form_{$field_id_esc}[$option_id_esc]'" .
830 " size='$fldlength'" .
831 " $string_maxlength" .
832 " value='$resnote' $disabled /></td>";
838 // single-selection list with ability to add to it
839 else if ($data_type == 26) {
840 echo generate_select_list("form_$field_id", $list_id, $currvalue,
841 $description, ($showEmpty ?
$empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
842 ($disabled ?
array('disabled' => 'disabled') : null), false, $backup_list);
843 // show the add button if user has access to correct list
844 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES
);
845 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
846 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
847 if (aco_exist('lists', $list_id)) {
848 // a specific aco exist for this list, so ensure access
849 if (acl_check('lists', $list_id)) echo $outputAddButton;
852 // no specific aco exist for this list, so check for access to 'default' list
853 if (acl_check('lists', 'default')) echo $outputAddButton;
857 // a set of labeled radio buttons
858 else if ($data_type == 27) {
859 // In this special case, fld_length is the number of columns generated.
860 $cols = max(1, $frow['fld_length']);
861 $lres = sqlStatement("SELECT * FROM list_options " .
862 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
863 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
864 $tdpct = (int) (100 / $cols);
865 $got_selected = FALSE;
866 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
867 $option_id = $lrow['option_id'];
868 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
869 if ($count %
$cols == 0) {
870 if ($count) echo "</tr>";
873 echo "<td width='$tdpct%'>";
874 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
875 " value='$option_id_esc' $lbfonchange";
876 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
877 (strlen($currvalue) > 0 && $option_id == $currvalue))
880 $got_selected = TRUE;
882 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
887 if ($count > $cols) {
888 // Add some space after multiple rows of radio buttons.
889 $cols = htmlspecialchars($cols, ENT_QUOTES
);
890 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
894 if (!$got_selected && strlen($currvalue) > 0) {
895 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES
);
896 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
897 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
901 // special case for history of lifestyle status; 3 radio buttons and a date text field:
902 // VicarePlus :: A selection list box for smoking status:
903 else if ($data_type == 28 ||
$data_type == 32) {
904 $tmp = explode('|', $currvalue);
905 switch(count($tmp)) {
924 $resdate = $restype = "";
927 $restype = $resdate = $resnote = "";
930 $maxlength = $frow['max_length'];
931 $string_maxlength = "";
932 // if max_length is set to zero, then do not set a maxlength
933 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
934 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
936 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
937 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
938 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
939 echo "<table cellpadding='0' cellspacing='0'>";
941 if ($data_type == 28)
944 echo "<td><input type='text'" .
945 " name='form_$field_id_esc'" .
946 " id='form_$field_id_esc'" .
947 " size='$fldlength'" .
948 " $string_maxlength" .
949 " value='$resnote' $disabled /> </td>";
950 echo "<td class='bold'> ".
951 " ".
952 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
954 else if($data_type == 32)
957 echo "<tr><td><input type='text'" .
958 " name='form_text_$field_id_esc'" .
959 " id='form_text_$field_id_esc'" .
960 " size='$fldlength'" .
961 " $string_maxlength" .
962 " value='$resnote' $disabled /> </td></tr>";
964 //Selection list for smoking status
965 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
966 echo generate_select_list("form_$field_id", $list_id, $reslist,
967 $description, ($showEmpty ?
$empty_title : ''), '', $onchange, '',
968 ($disabled ?
array('disabled' => 'disabled') : null));
970 echo "<td class='bold'> " . xlt('Status') . ": </td>";
973 echo "<td class='text' ><input type='radio'" .
974 " name='radio_{$field_id_esc}'" .
975 " id='radio_{$field_id_esc}[current]'" .
976 " value='current" . $field_id_esc . "' $lbfonchange";
977 if ($restype == "current" . $field_id) echo " checked";
978 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
979 echo " />" . xlt('Current') . " </td>";
981 echo "<td class='text'><input type='radio'" .
982 " name='radio_{$field_id_esc}'" .
983 " id='radio_{$field_id_esc}[quit]'" .
984 " value='quit".$field_id_esc."' $lbfonchange";
985 if ($restype == "quit" . $field_id) echo " checked";
986 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
987 echo " $disabled />" . xlt('Quit') . " </td>";
989 echo "<td class='text'><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
990 " value='$resdate'" .
991 " title='$description'" .
992 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
994 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
995 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
996 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' />";
997 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
1001 echo "<td class='text'><input type='radio'" .
1002 " name='radio_{$field_id_esc}'" .
1003 " id='radio_{$field_id_esc}[never]'" .
1004 " value='never" . $field_id_esc . "' $lbfonchange";
1005 if ($restype == "never" . $field_id) echo " checked";
1006 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1007 echo " />" . xlt('Never') . " </td>";
1009 echo "<td class='text'><input type='radio'" .
1010 " name='radio_{$field_id}'" .
1011 " id='radio_{$field_id}[not_applicable]'" .
1012 " value='not_applicable" . $field_id . "' $lbfonchange";
1013 if ($restype == "not_applicable" . $field_id) echo " checked";
1014 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1015 echo " $disabled />" . xlt('N/A') . " </td>";
1017 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1018 echo "<td class='text' ><div id='smoke_code'></div></td>";
1023 // static text. read-only, of course.
1024 else if ($data_type == 31) {
1025 echo nl2br($frow['description']);
1029 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1032 else if($data_type == 34){
1033 $arr = explode("|*|*|*|",$currvalue);
1034 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc,ENT_QUOTES
)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1035 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES
)."</div>";
1036 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1040 //facilities drop-down list
1041 else if ($data_type == 35) {
1042 if (empty($currvalue)){
1045 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1046 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1050 // supports backup list
1051 else if ($data_type == 36) {
1052 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1053 $description, $showEmpty ?
$empty_title : '', '', $onchange, '', null, true, $backup_list);
1058 function generate_print_field($frow, $currvalue) {
1059 global $rootdir, $date_init, $ISSUE_TYPES;
1061 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
1063 $data_type = $frow['data_type'];
1064 $field_id = $frow['field_id'];
1065 $list_id = $frow['list_id'];
1066 $fld_length = $frow['fld_length'];
1067 $backup_list = $frow['list_backup_id'];
1069 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
1071 // Can pass $frow['empty_title'] with this variable, otherwise
1072 // will default to 'Unassigned'.
1073 // If it is 'SKIP' then an empty text title is completely skipped.
1075 if (isset($frow['empty_title'])) {
1076 if ($frow['empty_title'] == "SKIP") {
1077 //do not display an 'empty' choice
1079 $empty_title = "Unassigned";
1082 $empty_title = $frow['empty_title'];
1086 $empty_title = "Unassigned";
1089 // generic single-selection list
1090 // Supports backup lists.
1091 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33) {
1092 if (empty($fld_length)) {
1093 if ($list_id == 'titles') {
1101 $lrow = sqlQuery("SELECT title FROM list_options " .
1102 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
1103 $tmp = xl_list_label($lrow['title']);
1104 if ($lrow == 0 && !empty($backup_list)) {
1105 // since primary list did not map, try to map to backup list
1106 $lrow = sqlQuery("SELECT title FROM list_options " .
1107 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1108 $tmp = xl_list_label($lrow['title']);
1110 if (empty($tmp)) $tmp = "($currvalue)";
1112 /*****************************************************************
1113 echo "<input type='text'" .
1114 " size='$fld_length'" .
1118 *****************************************************************/
1123 $tmp = htmlspecialchars( $tmp, ENT_QUOTES
);
1128 // simple text field
1129 else if ($data_type == 2 ||
$data_type == 15) {
1130 /*****************************************************************
1131 echo "<input type='text'" .
1132 " size='$fld_length'" .
1133 " value='$currescaped'" .
1136 *****************************************************************/
1137 if ($currescaped === '') $currescaped = ' ';
1141 // long or multi-line text field
1142 else if ($data_type == 3) {
1143 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES
);
1144 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES
);
1146 " cols='$fldlength'" .
1147 " rows='$maxlength'>" .
1148 $currescaped . "</textarea>";
1152 else if ($data_type == 4) {
1153 $agestr = optionalAge($frow, $currvalue);
1155 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1157 if ($currvalue === '') {
1161 echo text(oeFormatShortDate($currvalue));
1163 // Optional display of age or gestational age.
1165 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1170 else if ($data_type == 10 ||
$data_type == 11) {
1173 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1174 "WHERE id = ?", array($currvalue) );
1175 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1176 if (empty($tmp)) $tmp = "($currvalue)";
1178 /*****************************************************************
1179 echo "<input type='text'" .
1180 " size='$fld_length'" .
1184 *****************************************************************/
1185 if ($tmp === '') { $tmp = ' '; }
1186 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1191 else if ($data_type == 12) {
1194 $pres = get_pharmacies();
1195 while ($prow = sqlFetchArray($pres)) {
1197 if ($currvalue == $key) {
1198 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1199 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1200 $prow['line1'] . ' / ' . $prow['city'];
1203 if (empty($tmp)) $tmp = "($currvalue)";
1205 /*****************************************************************
1206 echo "<input type='text'" .
1207 " size='$fld_length'" .
1211 *****************************************************************/
1212 if ($tmp === '') { $tmp = ' '; }
1213 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1218 else if ($data_type == 13) {
1221 $squads = acl_get_squads();
1223 foreach ($squads as $key => $value) {
1224 if ($currvalue == $key) {
1229 if (empty($tmp)) $tmp = "($currvalue)";
1231 /*****************************************************************
1232 echo "<input type='text'" .
1233 " size='$fld_length'" .
1237 *****************************************************************/
1238 if ($tmp === '') { $tmp = ' '; }
1239 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1244 else if ($data_type == 14) {
1247 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1248 "WHERE id = ?", array($currvalue) );
1249 $uname = $urow['lname'];
1250 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1252 if (empty($tmp)) $tmp = "($currvalue)";
1254 /*****************************************************************
1255 echo "<input type='text'" .
1256 " size='$fld_length'" .
1260 *****************************************************************/
1261 if ($tmp === '') { $tmp = ' '; }
1262 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1266 // insurance company list
1267 else if ($data_type == 16) {
1270 $insprovs = getInsuranceProviders();
1271 foreach ($insprovs as $key => $ipname) {
1272 if ($currvalue == $key) {
1276 if (empty($tmp)) $tmp = "($currvalue)";
1278 if ($tmp === '') $tmp = ' ';
1279 else $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1284 else if ($data_type == 17) {
1287 foreach ($ISSUE_TYPES as $key => $value) {
1288 if ($currvalue == $key) {
1292 if (empty($tmp)) $tmp = "($currvalue)";
1294 if ($tmp === '') $tmp = ' ';
1295 else $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1299 // Visit categories.
1300 else if ($data_type == 18) {
1303 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1304 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1306 $tmp = xl_appt_category($crow['pc_catname']);
1307 if (empty($tmp)) $tmp = "($currvalue)";
1309 if ($tmp === '') { $tmp = ' '; }
1310 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES
); }
1314 // a set of labeled checkboxes
1315 else if ($data_type == 21) {
1316 // In this special case, fld_length is the number of columns generated.
1317 $cols = max(1, $fld_length);
1318 $avalue = explode('|', $currvalue);
1319 $lres = sqlStatement("SELECT * FROM list_options " .
1320 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1321 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1322 $tdpct = (int) (100 / $cols);
1323 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1324 $option_id = $lrow['option_id'];
1325 if ($count %
$cols == 0) {
1326 if ($count) echo "</tr>";
1329 echo "<td width='$tdpct%'>";
1330 echo "<input type='checkbox'";
1331 if (in_array($option_id, $avalue)) echo " checked";
1332 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
1337 if ($count > $cols) {
1338 // Add some space after multiple rows of checkboxes.
1339 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
1340 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1346 // a set of labeled text input fields
1347 else if ($data_type == 22) {
1348 $tmp = explode('|', $currvalue);
1350 foreach ($tmp as $value) {
1351 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1352 $avalue[$matches[1]] = $matches[2];
1355 $lres = sqlStatement("SELECT * FROM list_options " .
1356 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1357 echo "<table cellpadding='0' cellspacing='0'>";
1358 while ($lrow = sqlFetchArray($lres)) {
1359 $option_id = $lrow['option_id'];
1360 $fldlength = empty($fld_length) ?
20 : $fld_length;
1361 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1362 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1363 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
1364 echo "<td><input type='text'" .
1365 " size='$fldlength'" .
1366 " value='$inputValue'" .
1373 // a set of exam results; 3 radio buttons and a text field:
1374 else if ($data_type == 23) {
1375 $tmp = explode('|', $currvalue);
1377 foreach ($tmp as $value) {
1378 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1379 $avalue[$matches[1]] = $matches[2];
1382 $fldlength = empty($fld_length) ?
20 : $fld_length;
1383 $lres = sqlStatement("SELECT * FROM list_options " .
1384 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1385 echo "<table cellpadding='0' cellspacing='0'>";
1386 echo "<tr><td> </td><td class='bold'>" .
1387 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
1388 " </td><td class='bold'>" .
1389 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
1390 "<td class='bold'>" .
1391 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
1392 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
1393 while ($lrow = sqlFetchArray($lres)) {
1394 $option_id = $lrow['option_id'];
1395 $restype = substr($avalue[$option_id], 0, 1);
1396 $resnote = substr($avalue[$option_id], 2);
1397 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1398 for ($i = 0; $i < 3; ++
$i) {
1399 echo "<td><input type='radio'";
1400 if ($restype === "$i") echo " checked";
1403 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1404 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1405 echo "<td><input type='text'" .
1406 " size='$fldlength'" .
1407 " value='$resnote'" .
1408 " class='under' /></td>" .
1414 // the list of active allergies for the current patient
1415 // this is read-only!
1416 else if ($data_type == 24) {
1417 $query = "SELECT title, comments FROM lists WHERE " .
1418 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1420 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1422 while ($lrow = sqlFetchArray($lres)) {
1423 if ($count++
) echo "<br />";
1424 echo htmlspecialchars( $lrow['title'], ENT_QUOTES
);
1425 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES
);
1429 // a set of labeled checkboxes, each with a text field:
1430 else if ($data_type == 25) {
1431 $tmp = explode('|', $currvalue);
1433 foreach ($tmp as $value) {
1434 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1435 $avalue[$matches[1]] = $matches[2];
1438 $fldlength = empty($fld_length) ?
20 : $fld_length;
1439 $lres = sqlStatement("SELECT * FROM list_options " .
1440 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1441 echo "<table cellpadding='0' cellspacing='0'>";
1442 while ($lrow = sqlFetchArray($lres)) {
1443 $option_id = $lrow['option_id'];
1444 $restype = substr($avalue[$option_id], 0, 1);
1445 $resnote = substr($avalue[$option_id], 2);
1446 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1447 echo "<td><input type='checkbox'";
1448 if ($restype) echo " checked";
1449 echo " /> </td>";
1450 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1451 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1452 echo "<td><input type='text'" .
1453 " size='$fldlength'" .
1454 " value='$resnote'" .
1462 // a set of labeled radio buttons
1463 else if ($data_type == 27) {
1464 // In this special case, fld_length is the number of columns generated.
1465 $cols = max(1, $frow['fld_length']);
1466 $lres = sqlStatement("SELECT * FROM list_options " .
1467 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1468 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1469 $tdpct = (int) (100 / $cols);
1470 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1471 $option_id = $lrow['option_id'];
1472 if ($count %
$cols == 0) {
1473 if ($count) echo "</tr>";
1476 echo "<td width='$tdpct%'>";
1477 echo "<input type='radio'";
1478 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1479 (strlen($currvalue) > 0 && $option_id == $currvalue))
1483 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
1488 if ($count > $cols) {
1489 // Add some space after multiple rows of radio buttons.
1490 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
1491 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1497 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1498 else if ($data_type == 28 ||
$data_type == 32) {
1499 $tmp = explode('|', $currvalue);
1500 switch(count($tmp)) {
1519 $resdate = $restype = "";
1522 $restype = $resdate = $resnote = "";
1525 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1526 echo "<table cellpadding='0' cellspacing='0'>";
1528 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1529 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1530 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
1531 if($data_type == 28)
1533 echo "<td><input type='text'" .
1534 " size='$fldlength'" .
1536 " value='$resnote' /></td>";
1537 echo "<td class='bold'> ".
1538 " ".
1539 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1541 else if($data_type == 32)
1543 echo "<tr><td><input type='text'" .
1544 " size='$fldlength'" .
1546 " value='$resnote' /></td></tr>";
1548 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1549 echo "<td><input type='text'" .
1550 " size='$fldlength'" .
1552 " value='$smoking_status_title' /></td>";
1553 echo "<td class='bold'> ".htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1555 echo "<td><input type='radio'";
1556 if ($restype == "current".$field_id) echo " checked";
1557 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES
)." </td>";
1559 echo "<td><input type='radio'";
1560 if ($restype == "current".$field_id) echo " checked";
1561 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES
)." </td>";
1563 echo "<td><input type='text' size='6'" .
1564 " value='$resdate'" .
1568 echo "<td><input type='radio'";
1569 if ($restype == "current".$field_id) echo " checked";
1570 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES
)."</td>";
1572 echo "<td><input type='radio'";
1573 if ($restype == "not_applicable".$field_id) echo " checked";
1574 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES
)." </td>";
1579 // static text. read-only, of course.
1580 else if ($data_type == 31) {
1581 echo nl2br($frow['description']);
1584 else if($data_type == 34){
1585 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc,ENT_QUOTES
)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1586 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1587 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1591 //facilities drop-down list
1592 else if ($data_type == 35) {
1593 if (empty($currvalue)){
1596 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1600 // Supports backup lists.
1601 else if ($data_type == 36) {
1602 if (empty($fld_length)) {
1603 if ($list_id == 'titles') {
1611 $values_array = explode("|", $currvalue);
1614 foreach($values_array as $value) {
1616 $lrow = sqlQuery("SELECT title FROM list_options " .
1617 "WHERE list_id = ? AND option_id = ?", array($list_id,$value));
1618 $tmp = xl_list_label($lrow['title']);
1619 if ($lrow == 0 && !empty($backup_list)) {
1620 // since primary list did not map, try to map to backup list
1621 $lrow = sqlQuery("SELECT title FROM list_options " .
1622 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1623 $tmp = xl_list_label($lrow['title']);
1625 if (empty($tmp)) $tmp = "($value)";
1632 $tmp = htmlspecialchars( $tmp, ENT_QUOTES
);
1634 if ($i != 0 && $tmp != ' ') echo ",";
1642 function generate_display_field($frow, $currvalue) {
1643 global $ISSUE_TYPES;
1645 $data_type = $frow['data_type'];
1646 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
1647 $list_id = $frow['list_id'];
1648 $backup_list = $frow['list_backup_id'];
1652 // generic selection list or the generic selection list with add on the fly
1653 // feature, or radio buttons
1654 // Supports backup lists for datatypes 1,26,33
1655 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27 ||
$data_type == 33) {
1656 $lrow = sqlQuery("SELECT title FROM list_options " .
1657 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1658 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1659 //if there is no matching value in the corresponding lists check backup list
1660 // only supported in data types 1,26,33
1661 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
1662 $lrow = sqlQuery("SELECT title FROM list_options " .
1663 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
1664 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1668 // simple text field
1669 else if ($data_type == 2) {
1670 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES
));
1673 // long or multi-line text field
1674 else if ($data_type == 3) {
1675 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES
));
1679 else if ($data_type == 4) {
1681 $agestr = optionalAge($frow, $currvalue);
1683 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1685 if ($currvalue === '') {
1689 $s .= text(oeFormatShortDate($currvalue));
1691 // Optional display of age or gestational age.
1693 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1698 else if ($data_type == 10 ||
$data_type == 11) {
1699 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1700 "WHERE id = ?", array($currvalue) );
1701 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES
);
1705 else if ($data_type == 12) {
1706 $pres = get_pharmacies();
1707 while ($prow = sqlFetchArray($pres)) {
1709 if ($currvalue == $key) {
1710 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1711 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1712 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES
);
1718 else if ($data_type == 13) {
1719 $squads = acl_get_squads();
1721 foreach ($squads as $key => $value) {
1722 if ($currvalue == $key) {
1723 $s .= htmlspecialchars($value[3],ENT_NOQUOTES
);
1730 else if ($data_type == 14) {
1731 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1732 "WHERE id = ?", array($currvalue));
1733 $uname = $urow['lname'];
1734 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1735 $s = htmlspecialchars($uname,ENT_NOQUOTES
);
1739 else if ($data_type == 15) {
1740 $s = htmlspecialchars($currvalue,ENT_NOQUOTES
);
1743 // insurance company list
1744 else if ($data_type == 16) {
1745 $insprovs = getInsuranceProviders();
1746 foreach ($insprovs as $key => $ipname) {
1747 if ($currvalue == $key) {
1748 $s .= htmlspecialchars($ipname, ENT_NOQUOTES
);
1754 else if ($data_type == 17) {
1755 foreach ($ISSUE_TYPES as $key => $value) {
1756 if ($currvalue == $key) {
1757 $s .= htmlspecialchars($value[1], ENT_NOQUOTES
);
1763 else if ($data_type == 18) {
1764 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1765 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1767 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES
);
1770 // a set of labeled checkboxes
1771 else if ($data_type == 21) {
1772 $avalue = explode('|', $currvalue);
1773 $lres = sqlStatement("SELECT * FROM list_options " .
1774 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1776 while ($lrow = sqlFetchArray($lres)) {
1777 $option_id = $lrow['option_id'];
1778 if (in_array($option_id, $avalue)) {
1779 if ($count++
) $s .= "<br />";
1781 // Added 5-09 by BM - Translate label if applicable
1782 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES
);
1788 // a set of labeled text input fields
1789 else if ($data_type == 22) {
1790 $tmp = explode('|', $currvalue);
1792 foreach ($tmp as $value) {
1793 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1794 $avalue[$matches[1]] = $matches[2];
1797 $lres = sqlStatement("SELECT * FROM list_options " .
1798 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1799 $s .= "<table cellpadding='0' cellspacing='0'>";
1800 while ($lrow = sqlFetchArray($lres)) {
1801 $option_id = $lrow['option_id'];
1802 if (empty($avalue[$option_id])) continue;
1804 // Added 5-09 by BM - Translate label if applicable
1805 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . ": </td>";
1807 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES
) . "</td></tr>";
1812 // a set of exam results; 3 radio buttons and a text field:
1813 else if ($data_type == 23) {
1814 $tmp = explode('|', $currvalue);
1816 foreach ($tmp as $value) {
1817 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1818 $avalue[$matches[1]] = $matches[2];
1821 $lres = sqlStatement("SELECT * FROM list_options " .
1822 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1823 $s .= "<table cellpadding='0' cellspacing='0'>";
1824 while ($lrow = sqlFetchArray($lres)) {
1825 $option_id = $lrow['option_id'];
1826 $restype = substr($avalue[$option_id], 0, 1);
1827 $resnote = substr($avalue[$option_id], 2);
1828 if (empty($restype) && empty($resnote)) continue;
1830 // Added 5-09 by BM - Translate label if applicable
1831 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1833 $restype = ($restype == '1') ?
xl('Normal') : (($restype == '2') ?
xl('Abnormal') : xl('N/A'));
1834 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1835 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1836 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . " </td>";
1837 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td>";
1843 // the list of active allergies for the current patient
1844 else if ($data_type == 24) {
1845 $query = "SELECT title, comments FROM lists WHERE " .
1846 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1848 // echo "<!-- $query -->\n"; // debugging
1849 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1851 while ($lrow = sqlFetchArray($lres)) {
1852 if ($count++
) $s .= "<br />";
1853 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES
);
1854 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES
) . ')';
1858 // a set of labeled checkboxes, each with a text field:
1859 else if ($data_type == 25) {
1860 $tmp = explode('|', $currvalue);
1862 foreach ($tmp as $value) {
1863 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1864 $avalue[$matches[1]] = $matches[2];
1867 $lres = sqlStatement("SELECT * FROM list_options " .
1868 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1869 $s .= "<table cellpadding='0' cellspacing='0'>";
1870 while ($lrow = sqlFetchArray($lres)) {
1871 $option_id = $lrow['option_id'];
1872 $restype = substr($avalue[$option_id], 0, 1);
1873 $resnote = substr($avalue[$option_id], 2);
1874 if (empty($restype) && empty($resnote)) continue;
1876 // Added 5-09 by BM - Translate label if applicable
1877 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1879 $restype = $restype ?
xl('Yes') : xl('No');
1880 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . "</td></tr>";
1881 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td></tr>";
1887 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1888 // VicarePlus :: A selection list for smoking status.
1889 else if ($data_type == 28 ||
$data_type == 32) {
1890 $tmp = explode('|', $currvalue);
1891 switch(count($tmp)) {
1910 $resdate = $restype = "";
1913 $restype = $resdate = $resnote = "";
1916 $s .= "<table cellpadding='0' cellspacing='0'>";
1920 if ($restype == "current".$field_id) $res = xl('Current');
1921 if ($restype == "quit".$field_id) $res = xl('Quit');
1922 if ($restype == "never".$field_id) $res = xl('Never');
1923 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1924 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1925 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1926 if ($data_type == 28)
1928 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
1930 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1931 else if ($data_type == 32)
1932 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1933 $smoke_codes = getSmokeCodes();
1934 if (!empty($reslist)) {
1935 if($smoke_codes[$reslist]!="")
1936 $code_desc = "( ".$smoke_codes[$reslist]." )";
1938 $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . " ".text($code_desc)." </td>";}
1940 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
1943 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES
) . "</b>: " . htmlspecialchars($res,ENT_NOQUOTES
) . " </td>";
1944 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES
) . " </td>";
1949 // static text. read-only, of course.
1950 else if ($data_type == 31) {
1951 $s .= nl2br($frow['description']);
1954 else if($data_type == 34){
1955 $arr = explode("|*|*|*|",$currvalue);
1956 for($i=0;$i<sizeof($arr);$i++
){
1962 else if ($data_type == 35) {
1963 $urow = sqlQuery("SELECT id, name FROM facility ".
1964 "WHERE id = ?", array($currvalue) );
1965 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES
);
1969 // Supports backup lists
1970 else if ($data_type == 36) {
1971 $values_array = explode("|", $currvalue);
1974 foreach($values_array as $value) {
1975 $lrow = sqlQuery("SELECT title FROM list_options " .
1976 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
1978 if ($lrow == 0 && !empty($backup_list)) {
1980 $lrow = sqlQuery("SELECT title FROM list_options " .
1981 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
1985 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1987 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1997 // Generate plain text versions of selected LBF field types.
1998 // Currently used by interface/patient_file/download_template.php.
1999 // More field types might need to be supported here in the future.
2001 function generate_plaintext_field($frow, $currvalue) {
2002 global $ISSUE_TYPES;
2004 $data_type = $frow['data_type'];
2005 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
2006 $list_id = $frow['list_id'];
2007 $backup_list = $frow['backup_list'];
2010 // generic selection list or the generic selection list with add on the fly
2011 // feature, or radio buttons
2012 // Supports backup lists (for datatypes 1,26,33)
2013 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27 ||
$data_type == 33) {
2014 $lrow = sqlQuery("SELECT title FROM list_options " .
2015 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
2016 $s = xl_list_label($lrow['title']);
2017 //if there is no matching value in the corresponding lists check backup list
2018 // only supported in data types 1,26,33
2019 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
2020 $lrow = sqlQuery("SELECT title FROM list_options " .
2021 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
2022 $s = xl_list_label($lrow['title']);
2026 // simple or long text field
2027 else if ($data_type == 2 ||
$data_type == 3 ||
$data_type == 15) {
2032 else if ($data_type == 4) {
2033 $s = oeFormatShortDate($currvalue);
2034 // Optional display of age or gestational age.
2035 $tmp = optionalAge($frow, $currvalue);
2036 if ($tmp) $s .= ' ' . $tmp;
2040 else if ($data_type == 10 ||
$data_type == 11) {
2041 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2042 "WHERE id = ?", array($currvalue) );
2043 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2047 else if ($data_type == 12) {
2048 $pres = get_pharmacies();
2049 while ($prow = sqlFetchArray($pres)) {
2051 if ($currvalue == $key) {
2052 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2053 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2054 $prow['line1'] . ' / ' . $prow['city'];
2060 else if ($data_type == 14) {
2061 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2062 "WHERE id = ?", array($currvalue));
2063 $uname = $urow['lname'];
2064 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2068 // insurance company list
2069 else if ($data_type == 16) {
2070 $insprovs = getInsuranceProviders();
2071 foreach ($insprovs as $key => $ipname) {
2072 if ($currvalue == $key) {
2079 else if ($data_type == 17) {
2080 foreach ($ISSUE_TYPES as $key => $value) {
2081 if ($currvalue == $key) {
2088 else if ($data_type == 18) {
2089 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2090 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2092 $s = $crow['pc_catname'];
2095 // a set of labeled checkboxes
2096 else if ($data_type == 21) {
2097 $avalue = explode('|', $currvalue);
2098 $lres = sqlStatement("SELECT * FROM list_options " .
2099 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2101 while ($lrow = sqlFetchArray($lres)) {
2102 $option_id = $lrow['option_id'];
2103 if (in_array($option_id, $avalue)) {
2104 if ($count++
) $s .= "; ";
2105 $s .= xl_list_label($lrow['title']);
2110 // a set of labeled text input fields
2111 else if ($data_type == 22) {
2112 $tmp = explode('|', $currvalue);
2114 foreach ($tmp as $value) {
2115 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2116 $avalue[$matches[1]] = $matches[2];
2119 $lres = sqlStatement("SELECT * FROM list_options " .
2120 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2121 while ($lrow = sqlFetchArray($lres)) {
2122 $option_id = $lrow['option_id'];
2123 if (empty($avalue[$option_id])) continue;
2124 if ($s !== '') $s .= '; ';
2125 $s .= xl_list_label($lrow['title']) . ': ';
2126 $s .= $avalue[$option_id];
2130 // A set of exam results; 3 radio buttons and a text field.
2131 // This shows abnormal results only.
2132 else if ($data_type == 23) {
2133 $tmp = explode('|', $currvalue);
2135 foreach ($tmp as $value) {
2136 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2137 $avalue[$matches[1]] = $matches[2];
2140 $lres = sqlStatement("SELECT * FROM list_options " .
2141 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2142 while ($lrow = sqlFetchArray($lres)) {
2143 $option_id = $lrow['option_id'];
2144 $restype = substr($avalue[$option_id], 0, 1);
2145 $resnote = substr($avalue[$option_id], 2);
2146 if (empty($restype) && empty($resnote)) continue;
2147 if ($restype != '2') continue; // show abnormal results only
2148 if ($s !== '') $s .= '; ';
2149 $s .= xl_list_label($lrow['title']);
2150 if (!empty($resnote)) $s .= ': ' . $resnote;
2154 // the list of active allergies for the current patient
2155 else if ($data_type == 24) {
2156 $query = "SELECT title, comments FROM lists WHERE " .
2157 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2159 $lres = sqlStatement($query, array($GLOBALS['pid']));
2161 while ($lrow = sqlFetchArray($lres)) {
2162 if ($count++
) $s .= "; ";
2163 $s .= $lrow['title'];
2164 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2168 // a set of labeled checkboxes, each with a text field:
2169 else if ($data_type == 25) {
2170 $tmp = explode('|', $currvalue);
2172 foreach ($tmp as $value) {
2173 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2174 $avalue[$matches[1]] = $matches[2];
2177 $lres = sqlStatement("SELECT * FROM list_options " .
2178 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2179 while ($lrow = sqlFetchArray($lres)) {
2180 $option_id = $lrow['option_id'];
2181 $restype = substr($avalue[$option_id], 0, 1);
2182 $resnote = substr($avalue[$option_id], 2);
2183 if (empty($restype) && empty($resnote)) continue;
2184 if ($s !== '') $s .= '; ';
2185 $s .= xl_list_label($lrow['title']);
2186 $restype = $restype ?
xl('Yes') : xl('No');
2188 if ($resnote) $s .= ' ' . $resnote;
2192 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2193 // VicarePlus :: A selection list for smoking status.
2194 else if ($data_type == 28 ||
$data_type == 32) {
2195 $tmp = explode('|', $currvalue);
2196 $resnote = count($tmp) > 0 ?
$tmp[0] : '';
2197 $restype = count($tmp) > 1 ?
$tmp[1] : '';
2198 $resdate = count($tmp) > 2 ?
$tmp[2] : '';
2199 $reslist = count($tmp) > 3 ?
$tmp[3] : '';
2201 if ($restype == "current" . $field_id) $res = xl('Current');
2202 if ($restype == "quit" . $field_id) $res = xl('Quit');
2203 if ($restype == "never" . $field_id) $res = xl('Never');
2204 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2206 if ($data_type == 28) {
2207 if (!empty($resnote)) $s .= $resnote;
2209 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2210 else if ($data_type == 32) {
2211 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2212 if (!empty($resnote)) $s .= ' ' . $resnote;
2215 if ($s !== '') $s .= ' ';
2216 $s .= xl('Status') . ' ' . $res;
2218 if ($restype == "quit".$field_id) {
2219 if ($s !== '') $s .= ' ';
2225 // Supports backup lists
2226 else if ($data_type == 36) {
2227 $values_array = explode("|", $currvalue);
2230 foreach($values_array as $value) {
2231 $lrow = sqlQuery("SELECT title FROM list_options " .
2232 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
2234 if ($lrow == 0 && !empty($backup_list)) {
2236 $lrow = sqlQuery("SELECT title FROM list_options " .
2237 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
2241 $s = $s . ", " . xl_list_label($lrow['title']);
2243 $s = xl_list_label($lrow['title']);
2253 $CPR = 4; // cells per row of generic data
2258 function disp_end_cell() {
2259 global $item_count, $cell_count;
2260 if ($item_count > 0) {
2266 function disp_end_row() {
2267 global $cell_count, $CPR;
2269 if ($cell_count > 0) {
2270 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
2276 function disp_end_group() {
2278 if (strlen($last_group) > 0) {
2283 function display_layout_rows($formtype, $result1, $result2='') {
2284 global $item_count, $cell_count, $last_group, $CPR;
2286 $fres = sqlStatement("SELECT * FROM layout_options " .
2287 "WHERE form_id = ? AND uor > 0 " .
2288 "ORDER BY group_name, seq", array($formtype) );
2290 while ($frow = sqlFetchArray($fres)) {
2291 $this_group = $frow['group_name'];
2292 $titlecols = $frow['titlecols'];
2293 $datacols = $frow['datacols'];
2294 $data_type = $frow['data_type'];
2295 $field_id = $frow['field_id'];
2296 $list_id = $frow['list_id'];
2299 if ($formtype == 'DEM') {
2300 if ($GLOBALS['athletic_team']) {
2301 // Skip fitness level and return-to-play date because those appear
2302 // in a special display/update form on this page.
2303 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
2305 if (strpos($field_id, 'em_') === 0) {
2306 // Skip employer related fields, if it's disabled.
2307 if ($GLOBALS['omit_employers']) continue;
2308 $tmp = substr($field_id, 3);
2309 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2312 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2316 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2319 // Handle a data category (group) change.
2320 if (strcmp($this_group, $last_group) != 0) {
2321 $group_name = substr($this_group, 1);
2322 // totally skip generating the employer category, if it's disabled.
2323 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2325 $last_group = $this_group;
2328 // filter out all the empty field data from the patient report.
2329 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2330 // Handle starting of a new row.
2331 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
2335 echo "<td class='groupname'>";
2336 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2337 //echo "<font color='#008800'>$group_name</font>";
2339 // Added 5-09 by BM - Translate label if applicable
2340 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
);
2344 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2345 echo "<td valign='top'> ";
2350 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2352 // Handle starting of a new label cell.
2353 if ($titlecols > 0) {
2355 //echo "<td class='label' colspan='$titlecols' valign='top'";
2356 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
2357 echo "<td class='label' colspan='$titlecols_esc' ";
2358 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2360 $cell_count +
= $titlecols;
2364 // Added 5-09 by BM - Translate label if applicable
2365 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES
); else echo " ";
2367 // Handle starting of a new data cell.
2368 if ($datacols > 0) {
2370 //echo "<td class='text data' colspan='$datacols' valign='top'";
2371 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
2372 echo "<td class='text data' colspan='$datacols_esc'";
2373 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2375 $cell_count +
= $datacols;
2379 echo generate_display_field($frow, $currvalue);
2386 function display_layout_tabs($formtype, $result1, $result2='') {
2387 global $item_count, $cell_count, $last_group, $CPR;
2389 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2390 "WHERE form_id = ? AND uor > 0 " .
2391 "ORDER BY group_name, seq", array($formtype) );
2394 while ($frow = sqlFetchArray($fres)) {
2395 $this_group = $frow['group_name'];
2396 $group_name = substr($this_group, 1);
2397 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2399 <li
<?php
echo $first ?
'class="current"' : '' ?
>>
2400 <a href
="/play/javascript-tabbed-navigation/" id
="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES
)."?>">
2401 <?php
echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
); ?
></a
>
2408 function display_layout_tabs_data($formtype, $result1, $result2='') {
2409 global $item_count, $cell_count, $last_group, $CPR;
2411 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2412 "WHERE form_id = ? AND uor > 0 " .
2413 "ORDER BY group_name, seq", array($formtype));
2416 while ($frow = sqlFetchArray($fres)) {
2417 $this_group = isset($frow['group_name']) ?
$frow['group_name'] : "" ;
2418 $titlecols = isset($frow['titlecols']) ?
$frow['titlecols'] : "";
2419 $datacols = isset($frow['datacols']) ?
$frow['datacols'] : "";
2420 $data_type = isset($frow['data_type']) ?
$frow['data_type'] : "";
2421 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : "";
2422 $list_id = isset($frow['list_id']) ?
$frow['list_id'] : "";
2425 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2427 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2428 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2429 "ORDER BY seq", array($formtype, $this_group) );
2432 <div
class="tab <?php echo $first ? 'current' : '' ?>">
2433 <table border
='0' cellpadding
='0'>
2436 while ($group_fields = sqlFetchArray($group_fields_query)) {
2438 $titlecols = $group_fields['titlecols'];
2439 $datacols = $group_fields['datacols'];
2440 $data_type = $group_fields['data_type'];
2441 $field_id = $group_fields['field_id'];
2442 $list_id = $group_fields['list_id'];
2445 if ($formtype == 'DEM') {
2446 if ($GLOBALS['athletic_team']) {
2447 // Skip fitness level and return-to-play date because those appear
2448 // in a special display/update form on this page.
2449 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
2451 if (strpos($field_id, 'em_') === 0) {
2452 // Skip employer related fields, if it's disabled.
2453 if ($GLOBALS['omit_employers']) continue;
2454 $tmp = substr($field_id, 3);
2455 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2458 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2462 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2465 // Handle a data category (group) change.
2466 if (strcmp($this_group, $last_group) != 0) {
2467 $group_name = substr($this_group, 1);
2468 // totally skip generating the employer category, if it's disabled.
2469 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2470 $last_group = $this_group;
2473 // Handle starting of a new row.
2474 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
2479 if ($item_count == 0 && $titlecols == 0) {
2483 // Handle starting of a new label cell.
2484 if ($titlecols > 0) {
2486 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
2487 echo "<td class='label' colspan='$titlecols_esc' ";
2489 $cell_count +
= $titlecols;
2493 // Added 5-09 by BM - Translate label if applicable
2494 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES
); else echo " ";
2496 // Handle starting of a new data cell.
2497 if ($datacols > 0) {
2499 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
2500 echo "<td class='text data' colspan='$datacols_esc'";
2502 $cell_count +
= $datacols;
2506 echo generate_display_field($group_fields, $currvalue);
2523 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2524 global $item_count, $cell_count, $last_group, $CPR;
2526 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2527 "WHERE form_id = ? AND uor > 0 " .
2528 "ORDER BY group_name, seq", array($formtype) );
2531 while ($frow = sqlFetchArray($fres)) {
2532 $this_group = $frow['group_name'];
2533 $group_name = substr($this_group, 1);
2534 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES
);
2535 $titlecols = $frow['titlecols'];
2536 $datacols = $frow['datacols'];
2537 $data_type = $frow['data_type'];
2538 $field_id = $frow['field_id'];
2539 $list_id = $frow['list_id'];
2542 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2544 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2545 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2546 "ORDER BY seq", array($formtype,$this_group) );
2549 <div
class="tab <?php echo $first ? 'current' : '' ?>" id
="tab_<?php echo $group_name_esc?>" >
2550 <table border
='0' cellpadding
='0'>
2553 while ($group_fields = sqlFetchArray($group_fields_query)) {
2555 $titlecols = $group_fields['titlecols'];
2556 $datacols = $group_fields['datacols'];
2557 $data_type = $group_fields['data_type'];
2558 $field_id = $group_fields['field_id'];
2559 $list_id = $group_fields['list_id'];
2560 $backup_list = $group_fields['list_backup_id'];
2563 if ($formtype == 'DEM') {
2564 if ($GLOBALS['athletic_team']) {
2565 // Skip fitness level and return-to-play date because those appear
2566 // in a special display/update form on this page.
2567 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
2569 if (strpos($field_id, 'em_') === 0) {
2570 // Skip employer related fields, if it's disabled.
2571 if ($GLOBALS['omit_employers']) continue;
2572 $tmp = substr($field_id, 3);
2573 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2576 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2580 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2583 // Handle a data category (group) change.
2584 if (strcmp($this_group, $last_group) != 0) {
2585 $group_name = substr($this_group, 1);
2586 // totally skip generating the employer category, if it's disabled.
2587 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2588 $last_group = $this_group;
2591 // Handle starting of a new row.
2592 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
2597 if ($item_count == 0 && $titlecols == 0) {
2601 // Handle starting of a new label cell.
2602 if ($titlecols > 0) {
2604 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
2605 echo "<td class='label' colspan='$titlecols_esc' ";
2607 $cell_count +
= $titlecols;
2611 // Added 5-09 by BM - Translate label if applicable
2612 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES
).":"); else echo " ";
2614 // Handle starting of a new data cell.
2615 if ($datacols > 0) {
2617 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
2618 echo "<td class='text data' colspan='$datacols_esc'";
2620 $cell_count +
= $datacols;
2625 echo generate_form_field($group_fields, $currvalue);
2639 // From the currently posted HTML form, this gets the value of the
2640 // field corresponding to the provided layout_options table row.
2642 function get_layout_form_value($frow, $prefix='form_') {
2643 // Bring in $sanitize_all_escapes variable, which will decide
2644 // the variable escaping method.
2645 global $sanitize_all_escapes;
2647 $maxlength = empty($frow['max_length']) ?
0 : intval($frow['max_length']);
2648 $data_type = $frow['data_type'];
2649 $field_id = $frow['field_id'];
2651 if (isset($_POST["$prefix$field_id"])) {
2652 if ($data_type == 21) {
2653 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2654 // must be concatenated into a |-separated string.
2655 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2656 if (strlen($value)) $value .= '|';
2660 else if ($data_type == 22) {
2661 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2662 // into "key:value|key:value|...".
2663 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2664 $val = str_replace('|', ' ', $val);
2665 if (strlen($value)) $value .= '|';
2666 $value .= "$key:$val";
2669 else if ($data_type == 23) {
2670 // $_POST["$prefix$field_id"] is an array of text fields with companion
2671 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2672 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2673 $restype = $_POST["radio_{$field_id}"][$key];
2674 if (empty($restype)) $restype = '0';
2675 $val = str_replace('|', ' ', $val);
2676 if (strlen($value)) $value .= '|';
2677 $value .= "$key:$restype:$val";
2680 else if ($data_type == 25) {
2681 // $_POST["$prefix$field_id"] is an array of text fields with companion
2682 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2683 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2684 $restype = empty($_POST["check_{$field_id}"][$key]) ?
'0' : '1';
2685 $val = str_replace('|', ' ', $val);
2686 if (strlen($value)) $value .= '|';
2687 $value .= "$key:$restype:$val";
2690 else if ($data_type == 28 ||
$data_type == 32) {
2691 // $_POST["$prefix$field_id"] is an date text fields with companion
2692 // radio buttons to be imploded into "notes|type|date".
2693 $restype = $_POST["radio_{$field_id}"];
2694 if (empty($restype)) $restype = '0';
2695 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2696 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2697 if ($data_type == 32)
2699 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2700 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2701 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2702 $value = "$res_text_note|$restype|$resdate|$reslist";
2705 $value = "$resnote|$restype|$resdate";
2707 else if ($data_type == 36) {
2708 $value_array = $_POST["form_$field_id"];
2710 foreach ($value_array as $key => $valueofkey) {
2712 $value = $valueofkey;
2714 $value = $value . "|" . $valueofkey;
2720 $value = $_POST["$prefix$field_id"];
2724 // Better to die than to silently truncate data!
2725 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2726 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES
) .
2727 ":<br /> <br />".htmlspecialchars( $value, ENT_NOQUOTES
));
2729 // Make sure the return value is quote-safe.
2730 if ($sanitize_all_escapes) {
2731 //escapes already removed and using binding/placemarks in sql calls
2732 // so only need to trim value
2733 return trim($value);
2736 //need to explicitly prepare value
2737 return formTrim($value);
2741 // Generate JavaScript validation logic for the required fields.
2743 function generate_layout_validation($form_id) {
2744 $fres = sqlStatement("SELECT * FROM layout_options " .
2745 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2746 "ORDER BY group_name, seq", array($form_id) );
2748 while ($frow = sqlFetchArray($fres)) {
2749 if ($frow['uor'] < 2) continue;
2750 $data_type = $frow['data_type'];
2751 $field_id = $frow['field_id'];
2752 $fldtitle = $frow['title'];
2753 if (!$fldtitle) $fldtitle = $frow['description'];
2754 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES
);
2755 switch($data_type) {
2765 " if (f.$fldname.selectedIndex <= 0) {\n" .
2766 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2767 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
2770 case 27: // radio buttons
2773 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2774 " if (i >= f.$fldname.length) {\n" .
2775 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
2783 " if (trimlen(f.$fldname.value) == 0) {\n" .
2784 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2785 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2786 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2787 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
2789 " $('#" . $fldname . "').attr('style',''); " .
2790 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2798 * DROPDOWN FOR FACILITIES
2800 * build a dropdown with all facilities
2802 * @param string $selected - name of the currently selected facility
2803 * use '0' for "unspecified facility"
2804 * use '' for "All facilities" (the default)
2805 * @param string $name - the name/id for select form (defaults to "form_facility")
2806 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2808 * @return void - just echo the html encoded string
2810 * Note: This should become a data-type at some point, according to Brady
2812 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2813 $allow_allfacilities = true, $disabled='', $onchange='')
2815 $have_selected = false;
2816 $query = "SELECT id, name FROM facility ORDER BY name";
2817 $fres = sqlStatement($query);
2819 $name = htmlspecialchars($name, ENT_QUOTES
);
2820 echo " <select name='$name' id='$name'";
2821 if ($onchange) echo " onchange='$onchange'";
2822 echo " $disabled>\n";
2824 if ($allow_allfacilities) {
2826 $option_selected_attr = '';
2827 if ($selected == '') {
2828 $option_selected_attr = ' selected="selected"';
2829 $have_selected = true;
2831 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES
);
2832 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2833 } elseif ($allow_unspecified) {
2834 $option_value = '0';
2835 $option_selected_attr = '';
2836 if ( $selected == '0' ) {
2837 $option_selected_attr = ' selected="selected"';
2838 $have_selected = true;
2840 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
2841 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2844 while ($frow = sqlFetchArray($fres)) {
2845 $facility_id = $frow['id'];
2846 $option_value = htmlspecialchars($facility_id, ENT_QUOTES
);
2847 $option_selected_attr = '';
2848 if ($selected == $facility_id) {
2849 $option_selected_attr = ' selected="selected"';
2850 $have_selected = true;
2852 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES
);
2853 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2856 if ($allow_unspecified && $allow_allfacilities) {
2857 $option_value = '0';
2858 $option_selected_attr = '';
2859 if ( $selected == '0' ) {
2860 $option_selected_attr = ' selected="selected"';
2861 $have_selected = true;
2863 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
2864 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2867 if (!$have_selected) {
2868 $option_value = htmlspecialchars($selected, ENT_QUOTES
);
2869 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES
);
2870 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES
);
2871 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2873 echo " </select>\n";
2876 // Expand Collapse Widget
2877 // This forms the header and functionality component of the widget. The information that is displayed
2878 // then follows this function followed by a closing div tag
2880 // $title is the title of the section (already translated)
2881 // $label is identifier used in the tag id's and sql columns
2882 // $buttonLabel is the button label text (already translated)
2883 // $buttonLink is the button link information
2884 // $buttonClass is any additional needed class elements for the button tag
2885 // $linkMethod is the button link method ('javascript' vs 'html')
2886 // $bodyClass is to set class(es) of the body
2887 // $auth is a flag to decide whether to show the button
2888 // $fixedWidth is to flag whether width is fixed
2889 // $forceExpandAlways is a flag to force the widget to always be expanded
2891 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2893 echo "<div class='section-header'>";
2896 echo "<div class='section-header-dynamic'>";
2900 // show button, since authorized
2901 // first prepare class string
2903 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES
);
2906 $class_string = "css_button_small";
2908 // next, create the link
2909 if ($linkMethod == "javascript") {
2910 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2913 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2914 if (!isset($_SESSION['patient_portal_onsite'])) {
2915 // prevent an error from occuring when calling the function from the patient portal
2916 echo " onclick='top.restoreSession()'";
2919 if (!$GLOBALS['concurrent_layout']) {
2920 echo " target='Main'";
2923 htmlspecialchars( $buttonLabel, ENT_NOQUOTES
) . "</span></a></td>";
2925 if ($forceExpandAlways){
2926 // Special case to force the widget to always be expanded
2927 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES
) . "</b></span>";
2928 $indicatorTag ="style='display:none'";
2930 $indicatorTag = isset($indicatorTag) ?
$indicatorTag : "";
2931 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2932 htmlspecialchars( $label, ENT_QUOTES
) . "_ps_expand\")'><span class='text'><b>";
2933 echo htmlspecialchars( $title, ENT_NOQUOTES
) . "</b></span>";
2935 if (isset($_SESSION['patient_portal_onsite'])) {
2936 // collapse all entries in the patient portal
2937 $text = xl('expand');
2939 else if (getUserSetting($label."_ps_expand")) {
2940 $text = xl('collapse');
2943 $text = xl('expand');
2945 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES
) .
2946 "</span>)</a></td>";
2947 echo "</tr></table>";
2949 if ($forceExpandAlways) {
2950 // Special case to force the widget to always be expanded
2953 else if (isset($_SESSION['patient_portal_onsite'])) {
2954 // collapse all entries in the patient portal
2955 $styling = "style='display:none'";
2957 else if (getUserSetting($label."_ps_expand")) {
2961 $styling = "style='display:none'";
2964 $styling .= " class='" . $bodyClass . "'";
2966 //next, create the first div tag to hold the information
2967 // note the code that calls this function will then place the ending div tag after the data
2968 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES
) . "_ps_expand' " . $styling . ">";
2971 //billing_facility fuction will give the dropdown list which contain billing faciliies.
2972 function billing_facility($name,$select){
2973 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
2974 echo " <select id='".htmlspecialchars($name, ENT_QUOTES
)."' name='".htmlspecialchars($name, ENT_QUOTES
)."'>";
2975 while ($facrow = sqlFetchArray($qsql)) {
2976 $selected = ( $facrow['id'] == $select ) ?
'selected="selected"' : '' ;
2977 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES
)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES
)."</option>";
2982 // Generic function to get the translated title value for a particular list option.
2984 function getListItemTitle($list, $option) {
2985 $row = sqlQuery("SELECT title FROM list_options WHERE " .
2986 "list_id = ? AND option_id = ?", array($list, $option));
2987 if (empty($row['title'])) return $option;
2988 return xl_list_label($row['title']);
2990 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
2991 function getSmokeCodes()
2993 $smoking_codes_arr = array();
2994 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status'");
2995 while($codes_row = sqlFetchArray($smoking_codes))
2997 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
2999 return $smoking_codes_arr;
3002 // Get the current value for a layout based form field.
3003 // Depending on options this might come from lbf_data, patient_data,
3004 // form_encounter, shared_attributes or elsewhere.
3005 // Returns FALSE if the field ID is invalid (layout error).
3007 function lbf_current_value($frow, $formid, $encounter) {
3009 $formname = $frow['form_id'];
3010 $field_id = $frow['field_id'];
3011 $source = $frow['source'];
3013 $deffname = $formname . '_default_' . $field_id;
3014 if ($source == 'D' ||
$source == 'H') {
3015 // Get from patient_data, employer_data or history_data.
3016 if ($source == 'H') {
3017 $table = 'history_data';
3018 $orderby = 'ORDER BY date DESC LIMIT 1';
3020 else if (strpos($field_id, 'em_') === 0) {
3021 $field_id = substr($field_id, 3);
3022 $table = 'employer_data';
3023 $orderby = 'ORDER BY date DESC LIMIT 1';
3026 $table = 'patient_data';
3029 // It is an error if the field does not exist, but don't crash.
3030 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3031 if (empty($tmp)) return FALSE;
3032 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3033 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3035 else if ($source == 'E') {
3037 // Get value from shared_attributes of the current encounter.
3038 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3039 "pid = ? AND encounter = ? AND field_id = ?",
3040 array($pid, $encounter, $field_id));
3041 if (isset($sarow)) $currvalue = $sarow['field_value'];
3044 // Get from shared_attributes of the encounter that this form is linked to.
3045 // Note the importance of having an index on forms.form_id.
3046 $sarow = sqlQuery("SELECT sa.field_value " .
3047 "FROM forms AS f, shared_attributes AS sa WHERE " .
3048 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3049 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3050 array($formid, $formname, $field_id));
3051 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3054 // New form and encounter not available, this should not happen.
3057 else if ($source == 'V') {
3059 // Get value from the current encounter's form_encounter.
3060 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3061 "pid = ? AND encounter = ?",
3062 array($pid, $encounter));
3063 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3066 // Get value from the form_encounter that this form is linked to.
3067 $ferow = sqlQuery("SELECT fe.* " .
3068 "FROM forms AS f, form_encounter AS fe WHERE " .
3069 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3070 "fe.pid = f.pid AND fe.encounter = f.encounter",
3071 array($formid, $formname));
3072 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3075 // New form and encounter not available, this should not happen.
3079 // This is a normal form field.
3080 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3081 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3082 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3085 // New form, see if there is a custom default from a plugin.
3086 // This logic does not apply to shared attributes because they do not
3087 // have a "new form" concept.
3088 if (function_exists($deffname)) $currvalue = call_user_func($deffname);