2 // Copyright (C) 2007-2016 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("user.inc");
40 require_once("patient.inc");
41 require_once("lists.inc");
42 require_once(dirname(dirname(__FILE__
)) . "/custom/code_types.inc.php");
46 function get_pharmacies() {
47 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
48 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
49 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
50 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
52 "ORDER BY name, area_code, prefix, number");
55 function optionalAge($frow, $date, &$asof) {
57 if (empty($date)) return '';
58 $date = substr($date, 0, 10);
59 if (strpos($frow['edit_options'], 'A') !== FALSE) {
62 else if (strpos($frow['edit_options'], 'B') !== FALSE) {
68 if (strpos($frow['form_id'], 'LBF') === 0) {
69 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
70 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
71 array($GLOBALS['pid'], $GLOBALS['encounter']));
72 if (!empty($tmp['date'])) $asof = substr($tmp['date'], 0, 10);
74 $prefix = ($format ?
xl('Gest age') : xl('Age')) . ' ';
75 return $prefix . oeFormatAge($date, $asof, $format);
78 // Function to generate a drop-list.
80 function generate_select_list($tag_name, $list_id, $currvalue, $title, $empty_name = ' ', $class = '',
81 $onchange = '', $tag_id = '', $custom_attributes = null, $multiple = false, $backup_list = '') {
84 $tag_name_esc = attr($tag_name);
87 $tag_name_esc = $tag_name_esc . "[]";
90 $s .= "<select name='$tag_name_esc'";
93 $s .= " multiple='multiple'";
96 $tag_id_esc = attr( $tag_name );
99 $tag_id_esc = attr($tag_id);
102 $s .= " id='$tag_id_esc'";
104 if (!empty($class)) {
105 $class_esc = attr($class);
106 $s .= " class='form-control $class_esc'";
109 $s .= " class='form-control'";
113 $s .= " onchange='$onchange'";
115 if ($custom_attributes != null && is_array ( $custom_attributes )) {
116 foreach ( $custom_attributes as $attr => $val ) {
117 if (isset ( $custom_attributes [$attr] )) {
118 $s .= " " . attr($attr) . "='" . attr($val) . "'";
122 $selectTitle = attr($title);
123 $s .= " title='$selectTitle'>";
124 $selectEmptyName = xlt($empty_name);
126 $s .= "<option value=''>" . $selectEmptyName . "</option>";
128 // List order depends on language translation options.
129 // (Note we do not need to worry about the list order in the algorithm
130 // after the below code block since that is where searches for exceptions
131 // are done which include inactive items or items from a backup
132 // list; note these will always be shown at the bottom of the list no matter the
134 $lang_id = empty($_SESSION['language_choice']) ?
'1' : $_SESSION['language_choice'];
136 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) ||
!$GLOBALS['translate_lists']) {
138 if ($GLOBALS['gb_how_sort_list'] == '0') {
140 $order_by_sql = "seq, title";
142 else { //$GLOBALS['gb_how_sort_list'] == '1'
144 $order_by_sql = "title, seq";
146 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
150 if ($GLOBALS['gb_how_sort_list'] == '0') {
152 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
154 else { //$GLOBALS['gb_how_sort_list'] == '1'
156 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
158 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
159 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
160 "FROM list_options AS lo " .
161 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
162 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
164 "WHERE lo.list_id = ? AND lo.activity=1 " .
165 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
167 $got_selected = FALSE;
169 while ( $lrow = sqlFetchArray ( $lres ) ) {
170 $selectedValues = explode ( "|", $currvalue );
172 $optionValue = attr($lrow ['option_id']);
173 $s .= "<option value='$optionValue'";
175 if ((strlen ( $currvalue ) == 0 && $lrow ['is_default']) ||
(strlen ( $currvalue ) > 0 && in_array ( $lrow ['option_id'], $selectedValues ))) {
177 $got_selected = TRUE;
180 // Already has been translated above (if applicable), so do not need to use
181 // the xl_list_label() function here
182 $optionLabel = text($lrow ['title']);
183 $s .= ">$optionLabel</option>\n";
187 To show the inactive item in the list if the value is saved to database
189 if (!$got_selected && strlen($currvalue) > 0)
191 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
192 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
193 $lrow_inactive = sqlFetchArray($lres_inactive);
194 if($lrow_inactive['option_id']) {
195 $optionValue = htmlspecialchars( $lrow_inactive['option_id'], ENT_QUOTES
);
196 $s .= "<option value='$optionValue' selected>" . htmlspecialchars( xl_list_label($lrow_inactive['title']), ENT_NOQUOTES
) . "</option>\n";
197 $got_selected = TRUE;
201 if (!$got_selected && strlen ( $currvalue ) > 0 && !$multiple) {
202 $list_id = $backup_list;
203 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
205 if ($lrow > 0 && !empty($backup_list)) {
206 $selected = text(xl_list_label($lrow ['title']));
207 $s .= "<option value='$currescaped' selected> $selected </option>";
210 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
212 $fontTitle = xlt('Please choose a valid selection from the list.');
213 $fontText = xlt( 'Fix this' );
214 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
217 } else if (!$got_selected && strlen ( $currvalue ) > 0 && $multiple) {
218 //if not found in main list, display all selected values that exist in backup list
219 $list_id = $backup_list;
221 $got_selected_backup = FALSE;
222 if (!empty($backup_list)) {
223 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
224 while ( $lrow_backup = sqlFetchArray ( $lres_backup ) ) {
225 $selectedValues = explode ( "|", $currvalue );
227 $optionValue = attr($lrow_backup['option_id']);
229 if ( in_array($lrow_backup ['option_id'],$selectedValues)) {
230 $s .= "<option value='$optionValue'";
232 $optionLabel = text(xl_list_label($lrow_backup ['title']));
233 $s .= ">$optionLabel</option>\n";
234 $got_selected_backup = TRUE;
238 if (!$got_selected_backup) {
239 $selectedValues = explode ( "|", $currvalue );
240 foreach ( $selectedValues as $selectedValue ) {
241 $s .= "<option value='" . attr($selectedValue) . "'";
243 $s .= ">* " . text($selectedValue) . " *</option>\n";
246 $fontTitle = xlt('Please choose a valid selection from the list.');
247 $fontText = xlt( 'Fix this' );
248 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
259 // $frow is a row from the layout_options table.
260 // $currvalue is the current value, if any, of the associated item.
262 function generate_form_field($frow, $currvalue) {
263 global $rootdir, $date_init, $ISSUE_TYPES, $code_types,$condition_str;
265 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
267 $data_type = $frow['data_type'];
268 $field_id = $frow['field_id'];
269 $list_id = $frow['list_id'];
270 $backup_list = $frow['list_backup_id'];
271 $condition_str = get_conditions_str($condition_str,$frow);
273 // escaped variables to use in html
274 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES
);
275 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES
);
277 // Added 5-09 by BM - Translate description if applicable
278 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
280 // Support edit option T which assigns the (possibly very long) description as
281 // the default value.
282 if (strpos($frow['edit_options'], 'T') !== FALSE) {
283 if (strlen($currescaped) == 0) $currescaped = $description;
284 // Description used in this way is not suitable as a title.
288 // added 5-2009 by BM to allow modification of the 'empty' text title field.
289 // Can pass $frow['empty_title'] with this variable, otherwise
290 // will default to 'Unassigned'.
291 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
292 // if make $frow['empty_title'] equal to 'SKIP'
294 if (isset($frow['empty_title'])) {
295 if ($frow['empty_title'] == "SKIP") {
296 //do not display an 'empty' choice
298 $empty_title = "Unassigned";
301 $empty_title = $frow['empty_title'];
305 $empty_title = "Unassigned";
308 $disabled = strpos($frow['edit_options'], '0') === FALSE ?
'' : 'disabled';
310 $lbfchange = (strpos($frow['form_id'], 'LBF') === 0 ||
strpos($frow['form_id'], 'LBT') === 0) ?
311 "checkSkipConditions();" : "";
312 $lbfonchange = $lbfchange ?
"onchange='$lbfchange'" : "";
314 // generic single-selection list or Race and Ethnicity.
315 // These data types support backup lists.
316 if ($data_type == 1 ||
$data_type == 33) {
317 echo generate_select_list("form_$field_id", $list_id, $currvalue,
318 $description, ($showEmpty ?
$empty_title : ''), '', $lbfchange, '',
319 ($disabled ?
array('disabled' => 'disabled') : null), false, $backup_list);
323 else if ($data_type == 2) {
324 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
325 $maxlength = $frow['max_length'];
326 $string_maxlength = "";
327 // if max_length is set to zero, then do not set a maxlength
328 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
329 echo "<input type='text'" .
330 " name='form_$field_id_esc'" .
331 " id='form_$field_id_esc'" .
332 " size='$fldlength'" .
333 " $string_maxlength" .
334 " title='$description'" .
335 " value='$currescaped'";
337 if (strpos($frow['edit_options'], 'C') !== FALSE)
338 $tmp .= "capitalizeMe(this);";
339 else if (strpos($frow['edit_options'], 'U') !== FALSE)
340 $tmp .= "this.value = this.value.toUpperCase();";
341 if ($tmp) echo " onchange='$tmp'";
342 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES
);
343 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
344 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
345 echo " onblur='maskblur(this,\"$tmp\")'";
347 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
350 if ($disabled) echo ' disabled';
354 // long or multi-line text field
355 else if ($data_type == 3) {
356 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
357 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES
);
359 " name='form_$field_id_esc'" .
360 " id='form_$field_id_esc'" .
361 " title='$description'" .
362 " cols='$textCols'" .
363 " rows='$textRows' $lbfonchange $disabled" .
364 ">" . $currescaped . "</textarea>";
368 else if ($data_type == 4) {
369 $age_asof_date = ''; // optionalAge() sets this
370 $age_format = strpos($frow['edit_options'], 'A') === FALSE ?
3 : 0;
371 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
373 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
376 $onchange_string = '';
377 if (!$disabled && $agestr) {
378 $onchange_string = "onchange=\"if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format)\"";
381 echo "<input type='text' size='10' class='datepicker' name='form_$field_id_esc' id='form_$field_id_esc'" .
382 " value='" . substr($currescaped, 0, 10) . "'";
383 if (!$agestr) echo " title='$description'";
384 echo " $onchange_string $lbfonchange $disabled />";
386 // Optional display of age or gestational age.
388 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
392 // provider list, local providers only
393 else if ($data_type == 10) {
394 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
395 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
396 "AND authorized = 1 " .
397 "ORDER BY lname, fname");
398 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled class='form-control'>";
399 echo "<option value=''>" . xlt($empty_title) . "</option>";
400 $got_selected = false;
401 while ($urow = sqlFetchArray($ures)) {
402 $uname = text($urow['fname'] . ' ' . $urow['lname']);
403 $optionId = attr($urow['id']);
404 echo "<option value='$optionId'";
405 if ($urow['id'] == $currvalue) {
407 $got_selected = true;
409 echo ">$uname</option>";
411 if (!$got_selected && $currvalue) {
412 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
414 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
421 // provider list, including address book entries with an NPI number
422 else if ($data_type == 11) {
423 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
424 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
425 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
426 "ORDER BY lname, fname");
427 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
428 echo " $lbfonchange $disabled>";
429 echo "<option value=''>" . xlt('Unassigned') . "</option>";
430 $got_selected = false;
431 while ($urow = sqlFetchArray($ures)) {
432 $uname = text($urow['fname'] . ' ' . $urow['lname']);
433 $optionId = attr($urow['id']);
434 echo "<option value='$optionId'";
435 if ($urow['id'] == $currvalue) {
437 $got_selected = true;
439 echo ">$uname</option>";
441 if (!$got_selected && $currvalue) {
442 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
444 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
452 else if ($data_type == 12) {
453 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
454 echo " $lbfonchange $disabled>";
455 echo "<option value='0'></option>";
456 $pres = get_pharmacies();
457 $got_selected = false;
458 while ($prow = sqlFetchArray($pres)) {
460 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
461 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
462 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
463 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
464 echo "<option value='$optionValue'";
465 if ($currvalue == $key) {
467 $got_selected = true;
469 echo ">$optionLabel</option>";
471 if (!$got_selected && $currvalue) {
472 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
474 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
482 else if ($data_type == 13) {
483 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
484 echo " $lbfonchange $disabled>";
485 echo "<option value=''> </option>";
486 $squads = acl_get_squads();
488 foreach ($squads as $key => $value) {
489 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
490 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES
);
491 echo "<option value='$optionValue'";
492 if ($currvalue == $key) echo " selected";
493 echo ">$optionLabel</option>\n";
499 // Address book, preferring organization name if it exists and is not in
500 // parentheses, and excluding local users who are not providers.
501 // Supports "referred to" practitioners and facilities.
502 // Alternatively the letter L in edit_options means that abook_type
503 // must be "ord_lab", indicating types used with the procedure
504 // lab ordering system.
505 // Alternatively the letter O in edit_options means that abook_type
506 // must begin with "ord_", indicating types used with the procedure
508 // Alternatively the letter V in edit_options means that abook_type
509 // must be "vendor", indicating the Vendor type.
510 // Alternatively the letter R in edit_options means that abook_type
511 // must be "dist", indicating the Distributor type.
512 else if ($data_type == 14) {
513 if (strpos($frow['edit_options'], 'L') !== FALSE)
514 $tmp = "abook_type = 'ord_lab'";
515 else if (strpos($frow['edit_options'], 'O') !== FALSE)
516 $tmp = "abook_type LIKE 'ord\\_%'";
517 else if (strpos($frow['edit_options'], 'V') !== FALSE)
518 $tmp = "abook_type LIKE 'vendor%'";
519 else if (strpos($frow['edit_options'], 'R') !== FALSE)
520 $tmp = "abook_type LIKE 'dist'";
522 $tmp = "( username = '' OR authorized = 1 )";
523 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
524 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
526 "ORDER BY organization, lname, fname");
527 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
528 echo " $lbfonchange $disabled>";
529 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
530 while ($urow = sqlFetchArray($ures)) {
531 $uname = $urow['organization'];
532 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
533 $uname = $urow['lname'];
534 if ($urow['fname']) $uname .= ", " . $urow['fname'];
536 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES
);
537 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES
);
538 echo "<option value='$optionValue'";
539 $title = $urow['username'] ?
xl('Local') : xl('External');
540 $optionTitle = htmlspecialchars( $title, ENT_QUOTES
);
541 echo " title='$optionTitle'";
542 if ($urow['id'] == $currvalue) echo " selected";
543 echo ">$optionLabel</option>";
548 // A billing code. If description matches an existing code type then that type is used.
549 else if ($data_type == 15) {
550 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
551 $maxlength = $frow['max_length'];
552 $string_maxlength = "";
553 // if max_length is set to zero, then do not set a maxlength
554 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
556 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
557 // Option "2" generates a hidden input for the codes, and a matching visible field
558 // displaying their descriptions. First step is computing the description string.
559 $currdescstring = '';
560 if (!empty($currvalue)) {
561 $relcodes = explode(';', $currvalue);
562 foreach ($relcodes as $codestring) {
563 if ($codestring === '') continue;
564 $code_text = lookup_code_descriptions($codestring);
565 if ($currdescstring !== '') $currdescstring .= '; ';
566 if (!empty($code_text)) {
567 $currdescstring .= $code_text;
570 $currdescstring .= $codestring;
574 $currdescstring = attr($currdescstring);
576 echo "<input type='text'" .
577 " name='form_$field_id_esc'" .
578 " id='form_related_code'" .
579 " size='$fldlength'" .
580 " value='$currescaped'" .
581 " style='display:none'" .
582 " $lbfonchange readonly $disabled />";
583 // Extra readonly input field for optional display of code description(s).
584 echo "<input type='text'" .
585 " name='form_$field_id_esc" . "__desc'" .
586 " size='$fldlength'" .
587 " title='$description'" .
588 " value='$currdescstring'";
590 echo " onclick='sel_related(this,\"$codetype\")'";
592 echo " readonly $disabled />";
595 echo "<input type='text'" .
596 " name='form_$field_id_esc'" .
597 " id='form_related_code'" .
598 " size='$fldlength'" .
599 " $string_maxlength" .
600 " title='$description'" .
601 " value='$currescaped'";
603 echo " onclick='sel_related(this,\"$codetype\")'";
605 echo " $lbfonchange readonly $disabled />";
609 // insurance company list
610 else if ($data_type == 16) {
611 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
612 echo "<option value='0'></option>";
613 $insprovs = getInsuranceProviders();
614 $got_selected = false;
615 foreach ($insprovs as $key => $ipname) {
616 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
617 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES
);
618 echo "<option value='$optionValue'";
619 if ($currvalue == $key) {
621 $got_selected = true;
623 echo ">$optionLabel</option>";
625 if (!$got_selected && $currvalue) {
626 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
628 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
636 else if ($data_type == 17) {
637 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
638 echo "<option value='0'></option>";
639 $got_selected = false;
640 foreach ($ISSUE_TYPES as $key => $value) {
641 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
642 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES
);
643 echo "<option value='$optionValue'";
644 if ($currvalue == $key) {
646 $got_selected = true;
648 echo ">$optionLabel</option>";
650 if (!$got_selected && strlen($currvalue) > 0) {
651 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
653 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
661 else if ($data_type == 18) {
662 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
663 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
664 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
665 " $lbfonchange $disabled>";
666 echo "<option value=''>" . xlt($empty_title) . "</option>";
667 $got_selected = false;
668 while ($crow = sqlFetchArray($cres)) {
669 $catid = $crow['pc_catid'];
670 if (($catid < 9 && $catid != 5) ||
$catid == 11) continue;
671 echo "<option value='" . attr($catid) . "'";
672 if ($catid == $currvalue) {
674 $got_selected = true;
676 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
678 if (!$got_selected && $currvalue) {
679 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
681 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
688 // a set of labeled checkboxes
689 else if ($data_type == 21) {
690 // In this special case, fld_length is the number of columns generated.
691 $cols = max(1, $frow['fld_length']);
692 $avalue = explode('|', $currvalue);
693 $lres = sqlStatement("SELECT * FROM list_options " .
694 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
695 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
696 $tdpct = (int) (100 / $cols);
697 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
698 $option_id = $lrow['option_id'];
699 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
700 // if ($count) echo "<br />";
701 if ($count %
$cols == 0) {
702 if ($count) echo "</tr>";
705 echo "<td width='$tdpct%'>";
706 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
707 "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
708 if (in_array($option_id, $avalue)) echo " checked";
710 // Added 5-09 by BM - Translate label if applicable
711 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
717 if ($count > $cols) {
718 // Add some space after multiple rows of checkboxes.
719 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
720 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
726 // a set of labeled text input fields
727 else if ($data_type == 22) {
728 $tmp = explode('|', $currvalue);
730 foreach ($tmp as $value) {
731 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
732 $avalue[$matches[1]] = $matches[2];
735 $lres = sqlStatement("SELECT * FROM list_options " .
736 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
737 echo "<table cellpadding='0' cellspacing='0'>";
738 while ($lrow = sqlFetchArray($lres)) {
739 $option_id = $lrow['option_id'];
740 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
741 $maxlength = $frow['max_length'];
742 $string_maxlength = "";
743 // if max_length is set to zero, then do not set a maxlength
744 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
745 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
747 // Added 5-09 by BM - Translate label if applicable
748 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
749 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
750 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
751 echo "<td><input type='text'" .
752 " name='form_{$field_id_esc}[$option_id_esc]'" .
753 " id='form_{$field_id_esc}[$option_id_esc]'" .
754 " size='$fldlength'" .
755 " $string_maxlength" .
756 " value='$optionValue'";
757 echo " $lbfonchange $disabled /></td></tr>";
762 // a set of exam results; 3 radio buttons and a text field:
763 else if ($data_type == 23) {
764 $tmp = explode('|', $currvalue);
766 foreach ($tmp as $value) {
767 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
768 $avalue[$matches[1]] = $matches[2];
771 $maxlength = $frow['max_length'];
772 $string_maxlength = "";
773 // if max_length is set to zero, then do not set a maxlength
774 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
775 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
776 $lres = sqlStatement("SELECT * FROM list_options " .
777 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
778 echo "<table cellpadding='0' cellspacing='0'>";
779 echo "<tr><td> </td><td class='bold'>" .
780 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
781 " </td><td class='bold'>" .
782 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
783 "<td class='bold'>" .
784 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
785 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
786 while ($lrow = sqlFetchArray($lres)) {
787 $option_id = $lrow['option_id'];
788 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
789 $restype = substr($avalue[$option_id], 0, 1);
790 $resnote = substr($avalue[$option_id], 2);
792 // Added 5-09 by BM - Translate label if applicable
793 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
795 for ($i = 0; $i < 3; ++
$i) {
796 $inputValue = htmlspecialchars( $i, ENT_QUOTES
);
797 echo "<td><input type='radio'" .
798 " name='radio_{$field_id_esc}[$option_id_esc]'" .
799 " id='radio_{$field_id_esc}[$option_id_esc]'" .
800 " value='$inputValue' $lbfonchange";
801 if ($restype === "$i") echo " checked";
802 echo " $disabled /></td>";
804 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
805 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
806 echo "<td><input type='text'" .
807 " name='form_{$field_id_esc}[$option_id_esc]'" .
808 " id='form_{$field_id_esc}[$option_id_esc]'" .
809 " size='$fldlength'" .
810 " $string_maxlength" .
811 " value='$resnote' $disabled /></td>";
817 // the list of active allergies for the current patient
818 // this is read-only!
819 else if ($data_type == 24) {
820 $query = "SELECT title, comments FROM lists WHERE " .
821 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
823 // echo "<!-- $query -->\n"; // debugging
824 $lres = sqlStatement($query, array($GLOBALS['pid']));
826 while ($lrow = sqlFetchArray($lres)) {
827 if ($count++
) echo "<br />";
828 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES
);
829 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES
) . ')';
833 // a set of labeled checkboxes, each with a text field:
834 else if ($data_type == 25) {
835 $tmp = explode('|', $currvalue);
837 foreach ($tmp as $value) {
838 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
839 $avalue[$matches[1]] = $matches[2];
842 $maxlength = $frow['max_length'];
843 $string_maxlength = "";
844 // if max_length is set to zero, then do not set a maxlength
845 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
846 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
847 $lres = sqlStatement("SELECT * FROM list_options " .
848 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
849 echo "<table cellpadding='0' cellspacing='0'>";
850 while ($lrow = sqlFetchArray($lres)) {
851 $option_id = $lrow['option_id'];
852 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
853 $restype = substr($avalue[$option_id], 0, 1);
854 $resnote = substr($avalue[$option_id], 2);
856 // Added 5-09 by BM - Translate label if applicable
857 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
859 $option_id = htmlspecialchars( $option_id, ENT_QUOTES
);
860 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
861 " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
862 if ($restype) echo " checked";
863 echo " $disabled /> </td>";
864 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
865 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
866 echo "<td><input type='text'" .
867 " name='form_{$field_id_esc}[$option_id_esc]'" .
868 " id='form_{$field_id_esc}[$option_id_esc]'" .
869 " size='$fldlength'" .
870 " $string_maxlength" .
871 " value='$resnote' $disabled /></td>";
877 // single-selection list with ability to add to it
878 else if ($data_type == 26) {
879 echo generate_select_list("form_$field_id", $list_id, $currvalue,
880 $description, ($showEmpty ?
$empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
881 ($disabled ?
array('disabled' => 'disabled') : null), false, $backup_list);
882 // show the add button if user has access to correct list
883 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES
);
884 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
885 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
886 if (aco_exist('lists', $list_id)) {
887 // a specific aco exist for this list, so ensure access
888 if (acl_check('lists', $list_id)) echo $outputAddButton;
891 // no specific aco exist for this list, so check for access to 'default' list
892 if (acl_check('lists', 'default')) echo $outputAddButton;
896 // a set of labeled radio buttons
897 else if ($data_type == 27) {
898 // In this special case, fld_length is the number of columns generated.
899 $cols = max(1, $frow['fld_length']);
900 $lres = sqlStatement("SELECT * FROM list_options " .
901 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
902 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
903 $tdpct = (int) (100 / $cols);
904 $got_selected = FALSE;
905 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
906 $option_id = $lrow['option_id'];
907 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
908 if ($count %
$cols == 0) {
909 if ($count) echo "</tr>";
912 echo "<td width='$tdpct%'>";
913 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
914 " value='$option_id_esc' $lbfonchange";
915 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
916 (strlen($currvalue) > 0 && $option_id == $currvalue))
919 $got_selected = TRUE;
921 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
926 if ($count > $cols) {
927 // Add some space after multiple rows of radio buttons.
928 $cols = htmlspecialchars($cols, ENT_QUOTES
);
929 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
933 if (!$got_selected && strlen($currvalue) > 0) {
934 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES
);
935 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
936 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
940 // special case for history of lifestyle status; 3 radio buttons and a date text field:
941 // VicarePlus :: A selection list box for smoking status:
942 else if ($data_type == 28 ||
$data_type == 32) {
943 $tmp = explode('|', $currvalue);
944 switch(count($tmp)) {
963 $resdate = $restype = "";
966 $restype = $resdate = $resnote = "";
969 $maxlength = $frow['max_length'];
970 $string_maxlength = "";
971 // if max_length is set to zero, then do not set a maxlength
972 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
973 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
975 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
976 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
977 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
978 echo "<table cellpadding='0' cellspacing='0'>";
980 if ($data_type == 28)
983 echo "<td><input type='text'" .
984 " name='form_$field_id_esc'" .
985 " id='form_$field_id_esc'" .
986 " size='$fldlength'" .
987 " $string_maxlength" .
988 " value='$resnote' $disabled /> </td>";
989 echo "<td class='bold'> ".
990 " ".
991 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
993 else if($data_type == 32)
996 echo "<tr><td><input type='text'" .
997 " name='form_text_$field_id_esc'" .
998 " id='form_text_$field_id_esc'" .
999 " size='$fldlength'" .
1000 " $string_maxlength" .
1001 " value='$resnote' $disabled /> </td></tr>";
1003 //Selection list for smoking status
1004 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1005 echo generate_select_list("form_$field_id", $list_id, $reslist,
1006 $description, ($showEmpty ?
$empty_title : ''), '', $onchange, '',
1007 ($disabled ?
array('disabled' => 'disabled') : null));
1009 echo "<td class='bold'> " . xlt('Status') . ": </td>";
1012 echo "<td class='text' ><input type='radio'" .
1013 " name='radio_{$field_id_esc}'" .
1014 " id='radio_{$field_id_esc}[current]'" .
1015 " value='current" . $field_id_esc . "' $lbfonchange";
1016 if ($restype == "current" . $field_id) echo " checked";
1017 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1018 echo " />" . xlt('Current') . " </td>";
1020 echo "<td class='text'><input type='radio'" .
1021 " name='radio_{$field_id_esc}'" .
1022 " id='radio_{$field_id_esc}[quit]'" .
1023 " value='quit".$field_id_esc."' $lbfonchange";
1024 if ($restype == "quit" . $field_id) echo " checked";
1025 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1026 echo " $disabled />" . xlt('Quit') . " </td>";
1028 echo "<td class='text'><input type='text' size='6' class='datepicker' name='date_$field_id_esc' id='date_$field_id_esc'" .
1029 " value='$resdate'" .
1030 " title='$description'" .
1034 echo "<td class='text'><input type='radio'" .
1035 " name='radio_{$field_id_esc}'" .
1036 " id='radio_{$field_id_esc}[never]'" .
1037 " value='never" . $field_id_esc . "' $lbfonchange";
1038 if ($restype == "never" . $field_id) echo " checked";
1039 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1040 echo " />" . xlt('Never') . " </td>";
1042 echo "<td class='text'><input type='radio'" .
1043 " name='radio_{$field_id}'" .
1044 " id='radio_{$field_id}[not_applicable]'" .
1045 " value='not_applicable" . $field_id . "' $lbfonchange";
1046 if ($restype == "not_applicable" . $field_id) echo " checked";
1047 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1048 echo " $disabled />" . xlt('N/A') . " </td>";
1050 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1051 echo "<td class='text' ><div id='smoke_code'></div></td>";
1056 // static text. read-only, of course.
1057 else if ($data_type == 31) {
1058 echo nl2br($frow['description']);
1062 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1065 else if($data_type == 34){
1066 $arr = explode("|*|*|*|",$currvalue);
1067 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;'>";
1068 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES
)."</div>";
1069 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1073 //facilities drop-down list
1074 else if ($data_type == 35) {
1075 if (empty($currvalue)){
1078 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1079 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1083 // supports backup list
1084 else if ($data_type == 36) {
1085 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1086 $description, $showEmpty ?
$empty_title : '', '', $onchange, '', null, true, $backup_list);
1090 // Canvas and related elements for browser-side image drawing.
1091 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1092 else if ($data_type == 40) {
1093 // Unlike other field types, width and height are in pixels.
1094 $canWidth = intval($frow['fld_length']);
1095 $canHeight = intval($frow['fld_rows']);
1096 if (empty($currvalue)) {
1097 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1098 // If defined this is the filename of the default starting image.
1099 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1102 $mywidth = 50 +
($canWidth > 250 ?
$canWidth : 250);
1103 $myheight = 31 +
($canHeight > 261 ?
$canHeight : 261);
1104 echo "<div id='form_$field_id_esc' style='width:$mywidth; height:$myheight;'></div>";
1105 // Hidden form field exists to send updated data to the server at submit time.
1106 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1107 // Hidden image exists to support initialization of the canvas.
1108 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1109 // $date_init is a misnomer but it's the place for browser-side setup logic.
1110 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1115 function generate_print_field($frow, $currvalue) {
1116 global $rootdir, $date_init, $ISSUE_TYPES;
1118 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
1120 $data_type = $frow['data_type'];
1121 $field_id = $frow['field_id'];
1122 $list_id = $frow['list_id'];
1123 $fld_length = $frow['fld_length'];
1124 $backup_list = $frow['list_backup_id'];
1126 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
1128 // Can pass $frow['empty_title'] with this variable, otherwise
1129 // will default to 'Unassigned'.
1130 // If it is 'SKIP' then an empty text title is completely skipped.
1132 if (isset($frow['empty_title'])) {
1133 if ($frow['empty_title'] == "SKIP") {
1134 //do not display an 'empty' choice
1136 $empty_title = "Unassigned";
1139 $empty_title = $frow['empty_title'];
1143 $empty_title = "Unassigned";
1146 // generic single-selection list
1147 // Supports backup lists.
1148 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33) {
1149 if (empty($fld_length)) {
1150 if ($list_id == 'titles') {
1158 $lrow = sqlQuery("SELECT title FROM list_options " .
1159 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1160 $tmp = xl_list_label($lrow['title']);
1161 if ($lrow == 0 && !empty($backup_list)) {
1162 // since primary list did not map, try to map to backup list
1163 $lrow = sqlQuery("SELECT title FROM list_options " .
1164 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1165 $tmp = xl_list_label($lrow['title']);
1167 if (empty($tmp)) $tmp = "($currvalue)";
1169 /*****************************************************************
1170 echo "<input type='text'" .
1171 " size='$fld_length'" .
1175 *****************************************************************/
1180 $tmp = htmlspecialchars( $tmp, ENT_QUOTES
);
1185 // simple text field
1186 else if ($data_type == 2 ||
$data_type == 15) {
1187 /*****************************************************************
1188 echo "<input type='text'" .
1189 " size='$fld_length'" .
1190 " value='$currescaped'" .
1193 *****************************************************************/
1194 if ($currescaped === '') $currescaped = ' ';
1198 // long or multi-line text field
1199 else if ($data_type == 3) {
1200 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES
);
1201 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES
);
1203 " cols='$fldlength'" .
1204 " rows='$maxlength'>" .
1205 $currescaped . "</textarea>";
1209 else if ($data_type == 4) {
1210 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1211 $agestr = optionalAge($frow, $currvalue,$asof);
1213 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1215 if ($currvalue === '') {
1219 echo text(oeFormatShortDate($currvalue));
1221 // Optional display of age or gestational age.
1223 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1228 else if ($data_type == 10 ||
$data_type == 11) {
1231 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1232 "WHERE id = ?", array($currvalue) );
1233 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1234 if (empty($tmp)) $tmp = "($currvalue)";
1236 /*****************************************************************
1237 echo "<input type='text'" .
1238 " size='$fld_length'" .
1242 *****************************************************************/
1243 if ($tmp === '') { $tmp = ' '; }
1244 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1249 else if ($data_type == 12) {
1252 $pres = get_pharmacies();
1253 while ($prow = sqlFetchArray($pres)) {
1255 if ($currvalue == $key) {
1256 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1257 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1258 $prow['line1'] . ' / ' . $prow['city'];
1261 if (empty($tmp)) $tmp = "($currvalue)";
1263 /*****************************************************************
1264 echo "<input type='text'" .
1265 " size='$fld_length'" .
1269 *****************************************************************/
1270 if ($tmp === '') { $tmp = ' '; }
1271 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1276 else if ($data_type == 13) {
1279 $squads = acl_get_squads();
1281 foreach ($squads as $key => $value) {
1282 if ($currvalue == $key) {
1287 if (empty($tmp)) $tmp = "($currvalue)";
1289 /*****************************************************************
1290 echo "<input type='text'" .
1291 " size='$fld_length'" .
1295 *****************************************************************/
1296 if ($tmp === '') { $tmp = ' '; }
1297 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1302 else if ($data_type == 14) {
1305 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1306 "WHERE id = ?", array($currvalue) );
1307 $uname = $urow['lname'];
1308 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1310 if (empty($tmp)) $tmp = "($currvalue)";
1312 /*****************************************************************
1313 echo "<input type='text'" .
1314 " size='$fld_length'" .
1318 *****************************************************************/
1319 if ($tmp === '') { $tmp = ' '; }
1320 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1324 // insurance company list
1325 else if ($data_type == 16) {
1328 $insprovs = getInsuranceProviders();
1329 foreach ($insprovs as $key => $ipname) {
1330 if ($currvalue == $key) {
1334 if (empty($tmp)) $tmp = "($currvalue)";
1336 if ($tmp === '') $tmp = ' ';
1337 else $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1342 else if ($data_type == 17) {
1345 foreach ($ISSUE_TYPES as $key => $value) {
1346 if ($currvalue == $key) {
1350 if (empty($tmp)) $tmp = "($currvalue)";
1352 if ($tmp === '') $tmp = ' ';
1353 else $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1357 // Visit categories.
1358 else if ($data_type == 18) {
1361 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1362 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1364 $tmp = xl_appt_category($crow['pc_catname']);
1365 if (empty($tmp)) $tmp = "($currvalue)";
1367 if ($tmp === '') { $tmp = ' '; }
1368 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES
); }
1372 // a set of labeled checkboxes
1373 else if ($data_type == 21) {
1374 // In this special case, fld_length is the number of columns generated.
1375 $cols = max(1, $fld_length);
1376 $avalue = explode('|', $currvalue);
1377 $lres = sqlStatement("SELECT * FROM list_options " .
1378 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1379 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1380 $tdpct = (int) (100 / $cols);
1381 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1382 $option_id = $lrow['option_id'];
1383 if ($count %
$cols == 0) {
1384 if ($count) echo "</tr>";
1387 echo "<td width='$tdpct%'>";
1388 echo "<input type='checkbox'";
1389 if (in_array($option_id, $avalue)) echo " checked";
1390 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
1395 if ($count > $cols) {
1396 // Add some space after multiple rows of checkboxes.
1397 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
1398 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1404 // a set of labeled text input fields
1405 else if ($data_type == 22) {
1406 $tmp = explode('|', $currvalue);
1408 foreach ($tmp as $value) {
1409 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1410 $avalue[$matches[1]] = $matches[2];
1413 $lres = sqlStatement("SELECT * FROM list_options " .
1414 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1415 echo "<table cellpadding='0' cellspacing='0'>";
1416 while ($lrow = sqlFetchArray($lres)) {
1417 $option_id = $lrow['option_id'];
1418 $fldlength = empty($fld_length) ?
20 : $fld_length;
1419 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1420 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1421 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
1422 echo "<td><input type='text'" .
1423 " size='$fldlength'" .
1424 " value='$inputValue'" .
1431 // a set of exam results; 3 radio buttons and a text field:
1432 else if ($data_type == 23) {
1433 $tmp = explode('|', $currvalue);
1435 foreach ($tmp as $value) {
1436 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1437 $avalue[$matches[1]] = $matches[2];
1440 $fldlength = empty($fld_length) ?
20 : $fld_length;
1441 $lres = sqlStatement("SELECT * FROM list_options " .
1442 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1443 echo "<table cellpadding='0' cellspacing='0'>";
1444 echo "<tr><td> </td><td class='bold'>" .
1445 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
1446 " </td><td class='bold'>" .
1447 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
1448 "<td class='bold'>" .
1449 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
1450 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
1451 while ($lrow = sqlFetchArray($lres)) {
1452 $option_id = $lrow['option_id'];
1453 $restype = substr($avalue[$option_id], 0, 1);
1454 $resnote = substr($avalue[$option_id], 2);
1455 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1456 for ($i = 0; $i < 3; ++
$i) {
1457 echo "<td><input type='radio'";
1458 if ($restype === "$i") echo " checked";
1461 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1462 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1463 echo "<td><input type='text'" .
1464 " size='$fldlength'" .
1465 " value='$resnote'" .
1466 " class='under' /></td>" .
1472 // the list of active allergies for the current patient
1473 // this is read-only!
1474 else if ($data_type == 24) {
1475 $query = "SELECT title, comments FROM lists WHERE " .
1476 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1478 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1480 while ($lrow = sqlFetchArray($lres)) {
1481 if ($count++
) echo "<br />";
1482 echo htmlspecialchars( $lrow['title'], ENT_QUOTES
);
1483 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES
);
1487 // a set of labeled checkboxes, each with a text field:
1488 else if ($data_type == 25) {
1489 $tmp = explode('|', $currvalue);
1491 foreach ($tmp as $value) {
1492 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1493 $avalue[$matches[1]] = $matches[2];
1496 $fldlength = empty($fld_length) ?
20 : $fld_length;
1497 $lres = sqlStatement("SELECT * FROM list_options " .
1498 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1499 echo "<table cellpadding='0' cellspacing='0'>";
1500 while ($lrow = sqlFetchArray($lres)) {
1501 $option_id = $lrow['option_id'];
1502 $restype = substr($avalue[$option_id], 0, 1);
1503 $resnote = substr($avalue[$option_id], 2);
1504 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1505 echo "<td><input type='checkbox'";
1506 if ($restype) echo " checked";
1507 echo " /> </td>";
1508 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1509 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1510 echo "<td><input type='text'" .
1511 " size='$fldlength'" .
1512 " value='$resnote'" .
1520 // a set of labeled radio buttons
1521 else if ($data_type == 27) {
1522 // In this special case, fld_length is the number of columns generated.
1523 $cols = max(1, $frow['fld_length']);
1524 $lres = sqlStatement("SELECT * FROM list_options " .
1525 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1526 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1527 $tdpct = (int) (100 / $cols);
1528 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1529 $option_id = $lrow['option_id'];
1530 if ($count %
$cols == 0) {
1531 if ($count) echo "</tr>";
1534 echo "<td width='$tdpct%'>";
1535 echo "<input type='radio'";
1536 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1537 (strlen($currvalue) > 0 && $option_id == $currvalue))
1541 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
1546 if ($count > $cols) {
1547 // Add some space after multiple rows of radio buttons.
1548 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
1549 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1555 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1556 else if ($data_type == 28 ||
$data_type == 32) {
1557 $tmp = explode('|', $currvalue);
1558 switch(count($tmp)) {
1577 $resdate = $restype = "";
1580 $restype = $resdate = $resnote = "";
1583 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1584 echo "<table cellpadding='0' cellspacing='0'>";
1586 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1587 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1588 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
1589 if($data_type == 28)
1591 echo "<td><input type='text'" .
1592 " size='$fldlength'" .
1594 " value='$resnote' /></td>";
1595 echo "<td class='bold'> ".
1596 " ".
1597 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1599 else if($data_type == 32)
1601 echo "<tr><td><input type='text'" .
1602 " size='$fldlength'" .
1604 " value='$resnote' /></td></tr>";
1606 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1607 echo "<td><input type='text'" .
1608 " size='$fldlength'" .
1610 " value='$smoking_status_title' /></td>";
1611 echo "<td class='bold'> ".htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1613 echo "<td><input type='radio'";
1614 if ($restype == "current".$field_id) echo " checked";
1615 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES
)." </td>";
1617 echo "<td><input type='radio'";
1618 if ($restype == "current".$field_id) echo " checked";
1619 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES
)." </td>";
1621 echo "<td><input type='text' size='6'" .
1622 " value='$resdate'" .
1626 echo "<td><input type='radio'";
1627 if ($restype == "current".$field_id) echo " checked";
1628 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES
)."</td>";
1630 echo "<td><input type='radio'";
1631 if ($restype == "not_applicable".$field_id) echo " checked";
1632 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES
)." </td>";
1637 // static text. read-only, of course.
1638 else if ($data_type == 31) {
1639 echo nl2br($frow['description']);
1642 else if($data_type == 34){
1643 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;'>";
1644 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1645 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1649 //facilities drop-down list
1650 else if ($data_type == 35) {
1651 if (empty($currvalue)){
1654 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1658 // Supports backup lists.
1659 else if ($data_type == 36) {
1660 if (empty($fld_length)) {
1661 if ($list_id == 'titles') {
1669 $values_array = explode("|", $currvalue);
1672 foreach($values_array as $value) {
1674 $lrow = sqlQuery("SELECT title FROM list_options " .
1675 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1676 $tmp = xl_list_label($lrow['title']);
1677 if ($lrow == 0 && !empty($backup_list)) {
1678 // since primary list did not map, try to map to backup list
1679 $lrow = sqlQuery("SELECT title FROM list_options " .
1680 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1681 $tmp = xl_list_label($lrow['title']);
1683 if (empty($tmp)) $tmp = "($value)";
1690 $tmp = htmlspecialchars( $tmp, ENT_QUOTES
);
1692 if ($i != 0 && $tmp != ' ') echo ",";
1698 // Image from canvas drawing
1699 else if ($data_type == 40) {
1700 echo "<img src='" . attr($currvalue) . "'>";
1705 function generate_display_field($frow, $currvalue) {
1706 global $ISSUE_TYPES;
1708 $data_type = $frow['data_type'];
1709 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
1710 $list_id = $frow['list_id'];
1711 $backup_list = isset($frow['list_backup_id']) ?
$frow['list_backup_id'] : null;
1715 // generic selection list or the generic selection list with add on the fly
1716 // feature, or radio buttons
1717 // Supports backup lists for datatypes 1,26,33
1718 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27 ||
$data_type == 33) {
1719 $lrow = sqlQuery("SELECT title FROM list_options " .
1720 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
1721 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1722 //if there is no matching value in the corresponding lists check backup list
1723 // only supported in data types 1,26,33
1724 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
1725 $lrow = sqlQuery("SELECT title FROM list_options " .
1726 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
1727 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1731 // simple text field
1732 else if ($data_type == 2) {
1733 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES
));
1736 // long or multi-line text field
1737 else if ($data_type == 3) {
1738 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES
));
1742 else if ($data_type == 4) {
1743 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1745 $agestr = optionalAge($frow, $currvalue, $asof);
1747 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1749 if ($currvalue === '') {
1753 $s .= text(oeFormatShortDate($currvalue));
1755 // Optional display of age or gestational age.
1757 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1762 else if ($data_type == 10 ||
$data_type == 11) {
1763 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1764 "WHERE id = ?", array($currvalue) );
1765 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES
);
1769 else if ($data_type == 12) {
1770 $pres = get_pharmacies();
1771 while ($prow = sqlFetchArray($pres)) {
1773 if ($currvalue == $key) {
1774 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1775 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1776 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES
);
1782 else if ($data_type == 13) {
1783 $squads = acl_get_squads();
1785 foreach ($squads as $key => $value) {
1786 if ($currvalue == $key) {
1787 $s .= htmlspecialchars($value[3],ENT_NOQUOTES
);
1794 else if ($data_type == 14) {
1795 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
1796 "WHERE id = ?", array($currvalue));
1797 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
1798 if($urow['organization'] !=""){
1799 $uname = $urow['organization'];
1801 $uname = $urow['lname'];
1802 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1804 $s = htmlspecialchars($uname,ENT_NOQUOTES
);
1808 else if ($data_type == 15) {
1809 $s = htmlspecialchars($currvalue,ENT_NOQUOTES
);
1812 // insurance company list
1813 else if ($data_type == 16) {
1814 $insprovs = getInsuranceProviders();
1815 foreach ($insprovs as $key => $ipname) {
1816 if ($currvalue == $key) {
1817 $s .= htmlspecialchars($ipname, ENT_NOQUOTES
);
1823 else if ($data_type == 17) {
1824 foreach ($ISSUE_TYPES as $key => $value) {
1825 if ($currvalue == $key) {
1826 $s .= htmlspecialchars($value[1], ENT_NOQUOTES
);
1832 else if ($data_type == 18) {
1833 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1834 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1836 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES
);
1839 // a set of labeled checkboxes
1840 else if ($data_type == 21) {
1841 $avalue = explode('|', $currvalue);
1842 $lres = sqlStatement("SELECT * FROM list_options " .
1843 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1845 while ($lrow = sqlFetchArray($lres)) {
1846 $option_id = $lrow['option_id'];
1847 if (in_array($option_id, $avalue)) {
1848 if ($count++
) $s .= "<br />";
1850 // Added 5-09 by BM - Translate label if applicable
1851 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES
);
1857 // a set of labeled text input fields
1858 else if ($data_type == 22) {
1859 $tmp = explode('|', $currvalue);
1861 foreach ($tmp as $value) {
1862 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1863 $avalue[$matches[1]] = $matches[2];
1866 $lres = sqlStatement("SELECT * FROM list_options " .
1867 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1868 $s .= "<table cellpadding='0' cellspacing='0'>";
1869 while ($lrow = sqlFetchArray($lres)) {
1870 $option_id = $lrow['option_id'];
1871 if (empty($avalue[$option_id])) continue;
1873 // Added 5-09 by BM - Translate label if applicable
1874 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . ": </td>";
1876 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES
) . "</td></tr>";
1881 // a set of exam results; 3 radio buttons and a text field:
1882 else if ($data_type == 23) {
1883 $tmp = explode('|', $currvalue);
1885 foreach ($tmp as $value) {
1886 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1887 $avalue[$matches[1]] = $matches[2];
1890 $lres = sqlStatement("SELECT * FROM list_options " .
1891 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1892 $s .= "<table cellpadding='0' cellspacing='0'>";
1893 while ($lrow = sqlFetchArray($lres)) {
1894 $option_id = $lrow['option_id'];
1895 $restype = substr($avalue[$option_id], 0, 1);
1896 $resnote = substr($avalue[$option_id], 2);
1897 if (empty($restype) && empty($resnote)) continue;
1899 // Added 5-09 by BM - Translate label if applicable
1900 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1902 $restype = ($restype == '1') ?
xl('Normal') : (($restype == '2') ?
xl('Abnormal') : xl('N/A'));
1903 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1904 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1905 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . " </td>";
1906 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td>";
1912 // the list of active allergies for the current patient
1913 else if ($data_type == 24) {
1914 $query = "SELECT title, comments FROM lists WHERE " .
1915 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1917 // echo "<!-- $query -->\n"; // debugging
1918 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1920 while ($lrow = sqlFetchArray($lres)) {
1921 if ($count++
) $s .= "<br />";
1922 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES
);
1923 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES
) . ')';
1927 // a set of labeled checkboxes, each with a text field:
1928 else if ($data_type == 25) {
1929 $tmp = explode('|', $currvalue);
1931 foreach ($tmp as $value) {
1932 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1933 $avalue[$matches[1]] = $matches[2];
1936 $lres = sqlStatement("SELECT * FROM list_options " .
1937 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1938 $s .= "<table cellpadding='0' cellspacing='0'>";
1939 while ($lrow = sqlFetchArray($lres)) {
1940 $option_id = $lrow['option_id'];
1941 $restype = substr($avalue[$option_id], 0, 1);
1942 $resnote = substr($avalue[$option_id], 2);
1943 if (empty($restype) && empty($resnote)) continue;
1945 // Added 5-09 by BM - Translate label if applicable
1946 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1948 $restype = $restype ?
xl('Yes') : xl('No');
1949 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . "</td></tr>";
1950 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td></tr>";
1956 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1957 // VicarePlus :: A selection list for smoking status.
1958 else if ($data_type == 28 ||
$data_type == 32) {
1959 $tmp = explode('|', $currvalue);
1960 switch(count($tmp)) {
1979 $resdate = $restype = "";
1982 $restype = $resdate = $resnote = "";
1985 $s .= "<table cellpadding='0' cellspacing='0'>";
1989 if ($restype == "current".$field_id) $res = xl('Current');
1990 if ($restype == "quit".$field_id) $res = xl('Quit');
1991 if ($restype == "never".$field_id) $res = xl('Never');
1992 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1993 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1994 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1995 if ($data_type == 28)
1997 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
1999 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2000 else if ($data_type == 32)
2001 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2002 $smoke_codes = getSmokeCodes();
2003 if (!empty($reslist)) {
2004 if($smoke_codes[$reslist]!="")
2005 $code_desc = "( ".$smoke_codes[$reslist]." )";
2007 $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . " ".text($code_desc)." </td>";}
2009 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
2012 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES
) . "</b>: " . htmlspecialchars($res,ENT_NOQUOTES
) . " </td>";
2013 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES
) . " </td>";
2018 // static text. read-only, of course.
2019 else if ($data_type == 31) {
2020 $s .= nl2br($frow['description']);
2023 else if($data_type == 34){
2024 $arr = explode("|*|*|*|",$currvalue);
2025 for($i=0;$i<sizeof($arr);$i++
){
2031 else if ($data_type == 35) {
2032 $urow = sqlQuery("SELECT id, name FROM facility ".
2033 "WHERE id = ?", array($currvalue) );
2034 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES
);
2038 // Supports backup lists
2039 else if ($data_type == 36) {
2040 $values_array = explode("|", $currvalue);
2042 foreach($values_array as $value) {
2043 $lrow = sqlQuery("SELECT title FROM list_options " .
2044 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2045 if ($lrow == 0 && !empty($backup_list)) {
2047 $lrow = sqlQuery("SELECT title FROM list_options " .
2048 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2051 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
2053 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
2059 // Image from canvas drawing
2060 else if ($data_type == 40) {
2061 $s .= "<img src='" . attr($currvalue) . "'>";
2067 // Generate plain text versions of selected LBF field types.
2068 // Currently used by interface/patient_file/download_template.php.
2069 // More field types might need to be supported here in the future.
2071 function generate_plaintext_field($frow, $currvalue) {
2072 global $ISSUE_TYPES;
2074 $data_type = $frow['data_type'];
2075 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
2076 $list_id = $frow['list_id'];
2077 $backup_list = $frow['backup_list'];
2080 // generic selection list or the generic selection list with add on the fly
2081 // feature, or radio buttons
2082 // Supports backup lists (for datatypes 1,26,33)
2083 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27 ||
$data_type == 33) {
2084 $lrow = sqlQuery("SELECT title FROM list_options " .
2085 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
2086 $s = xl_list_label($lrow['title']);
2087 //if there is no matching value in the corresponding lists check backup list
2088 // only supported in data types 1,26,33
2089 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
2090 $lrow = sqlQuery("SELECT title FROM list_options " .
2091 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
2092 $s = xl_list_label($lrow['title']);
2096 // simple or long text field
2097 else if ($data_type == 2 ||
$data_type == 3 ||
$data_type == 15) {
2102 else if ($data_type == 4) {
2103 $s = oeFormatShortDate($currvalue);
2104 // Optional display of age or gestational age.
2105 $asof=''; //not used here, but set to prevent a php warning when call optionalAge
2106 $tmp = optionalAge($frow, $currvalue,$asof);
2107 if ($tmp) $s .= ' ' . $tmp;
2111 else if ($data_type == 10 ||
$data_type == 11) {
2112 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2113 "WHERE id = ?", array($currvalue) );
2114 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2118 else if ($data_type == 12) {
2119 $pres = get_pharmacies();
2120 while ($prow = sqlFetchArray($pres)) {
2122 if ($currvalue == $key) {
2123 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2124 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2125 $prow['line1'] . ' / ' . $prow['city'];
2131 else if ($data_type == 14) {
2132 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2133 "WHERE id = ?", array($currvalue));
2134 $uname = $urow['lname'];
2135 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2139 // insurance company list
2140 else if ($data_type == 16) {
2141 $insprovs = getInsuranceProviders();
2142 foreach ($insprovs as $key => $ipname) {
2143 if ($currvalue == $key) {
2150 else if ($data_type == 17) {
2151 foreach ($ISSUE_TYPES as $key => $value) {
2152 if ($currvalue == $key) {
2159 else if ($data_type == 18) {
2160 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2161 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2163 $s = $crow['pc_catname'];
2166 // a set of labeled checkboxes
2167 else if ($data_type == 21) {
2168 $avalue = explode('|', $currvalue);
2169 $lres = sqlStatement("SELECT * FROM list_options " .
2170 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2172 while ($lrow = sqlFetchArray($lres)) {
2173 $option_id = $lrow['option_id'];
2174 if (in_array($option_id, $avalue)) {
2175 if ($count++
) $s .= "; ";
2176 $s .= xl_list_label($lrow['title']);
2181 // a set of labeled text input fields
2182 else if ($data_type == 22) {
2183 $tmp = explode('|', $currvalue);
2185 foreach ($tmp as $value) {
2186 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2187 $avalue[$matches[1]] = $matches[2];
2190 $lres = sqlStatement("SELECT * FROM list_options " .
2191 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2192 while ($lrow = sqlFetchArray($lres)) {
2193 $option_id = $lrow['option_id'];
2194 if (empty($avalue[$option_id])) continue;
2195 if ($s !== '') $s .= '; ';
2196 $s .= xl_list_label($lrow['title']) . ': ';
2197 $s .= $avalue[$option_id];
2201 // A set of exam results; 3 radio buttons and a text field.
2202 // This shows abnormal results only.
2203 else if ($data_type == 23) {
2204 $tmp = explode('|', $currvalue);
2206 foreach ($tmp as $value) {
2207 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2208 $avalue[$matches[1]] = $matches[2];
2211 $lres = sqlStatement("SELECT * FROM list_options " .
2212 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2213 while ($lrow = sqlFetchArray($lres)) {
2214 $option_id = $lrow['option_id'];
2215 $restype = substr($avalue[$option_id], 0, 1);
2216 $resnote = substr($avalue[$option_id], 2);
2217 if (empty($restype) && empty($resnote)) continue;
2218 if ($restype != '2') continue; // show abnormal results only
2219 if ($s !== '') $s .= '; ';
2220 $s .= xl_list_label($lrow['title']);
2221 if (!empty($resnote)) $s .= ': ' . $resnote;
2225 // the list of active allergies for the current patient
2226 else if ($data_type == 24) {
2227 $query = "SELECT title, comments FROM lists WHERE " .
2228 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2230 $lres = sqlStatement($query, array($GLOBALS['pid']));
2232 while ($lrow = sqlFetchArray($lres)) {
2233 if ($count++
) $s .= "; ";
2234 $s .= $lrow['title'];
2235 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2239 // a set of labeled checkboxes, each with a text field:
2240 else if ($data_type == 25) {
2241 $tmp = explode('|', $currvalue);
2243 foreach ($tmp as $value) {
2244 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2245 $avalue[$matches[1]] = $matches[2];
2248 $lres = sqlStatement("SELECT * FROM list_options " .
2249 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2250 while ($lrow = sqlFetchArray($lres)) {
2251 $option_id = $lrow['option_id'];
2252 $restype = substr($avalue[$option_id], 0, 1);
2253 $resnote = substr($avalue[$option_id], 2);
2254 if (empty($restype) && empty($resnote)) continue;
2255 if ($s !== '') $s .= '; ';
2256 $s .= xl_list_label($lrow['title']);
2257 $restype = $restype ?
xl('Yes') : xl('No');
2259 if ($resnote) $s .= ' ' . $resnote;
2263 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2264 // VicarePlus :: A selection list for smoking status.
2265 else if ($data_type == 28 ||
$data_type == 32) {
2266 $tmp = explode('|', $currvalue);
2267 $resnote = count($tmp) > 0 ?
$tmp[0] : '';
2268 $restype = count($tmp) > 1 ?
$tmp[1] : '';
2269 $resdate = count($tmp) > 2 ?
$tmp[2] : '';
2270 $reslist = count($tmp) > 3 ?
$tmp[3] : '';
2272 if ($restype == "current" . $field_id) $res = xl('Current');
2273 if ($restype == "quit" . $field_id) $res = xl('Quit');
2274 if ($restype == "never" . $field_id) $res = xl('Never');
2275 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2277 if ($data_type == 28) {
2278 if (!empty($resnote)) $s .= $resnote;
2280 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2281 else if ($data_type == 32) {
2282 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2283 if (!empty($resnote)) $s .= ' ' . $resnote;
2286 if ($s !== '') $s .= ' ';
2287 $s .= xl('Status') . ' ' . $res;
2289 if ($restype == "quit".$field_id) {
2290 if ($s !== '') $s .= ' ';
2296 // Supports backup lists
2297 else if ($data_type == 36) {
2298 $values_array = explode("|", $currvalue);
2301 foreach($values_array as $value) {
2302 $lrow = sqlQuery("SELECT title FROM list_options " .
2303 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2305 if ($lrow == 0 && !empty($backup_list)) {
2307 $lrow = sqlQuery("SELECT title FROM list_options " .
2308 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2312 $s = $s . ", " . xl_list_label($lrow['title']);
2314 $s = xl_list_label($lrow['title']);
2324 $CPR = 4; // cells per row of generic data
2329 function disp_end_cell() {
2330 global $item_count, $cell_count;
2331 if ($item_count > 0) {
2337 function disp_end_row() {
2338 global $cell_count, $CPR;
2340 if ($cell_count > 0) {
2341 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
2347 function disp_end_group() {
2349 if (strlen($last_group) > 0) {
2354 function display_layout_rows($formtype, $result1, $result2='') {
2355 global $item_count, $cell_count, $last_group, $CPR;
2357 $fres = sqlStatement("SELECT * FROM layout_options " .
2358 "WHERE form_id = ? AND uor > 0 " .
2359 "ORDER BY group_name, seq", array($formtype) );
2361 while ($frow = sqlFetchArray($fres)) {
2362 $this_group = $frow['group_name'];
2363 $titlecols = $frow['titlecols'];
2364 $datacols = $frow['datacols'];
2365 $data_type = $frow['data_type'];
2366 $field_id = $frow['field_id'];
2367 $list_id = $frow['list_id'];
2370 if ($formtype == 'DEM') {
2371 if (strpos($field_id, 'em_') === 0) {
2372 // Skip employer related fields, if it's disabled.
2373 if ($GLOBALS['omit_employers']) continue;
2374 $tmp = substr($field_id, 3);
2375 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2378 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2382 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2385 // Handle a data category (group) change.
2386 if (strcmp($this_group, $last_group) != 0) {
2387 $group_name = substr($this_group, 1);
2388 // totally skip generating the employer category, if it's disabled.
2389 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2391 $last_group = $this_group;
2394 // filter out all the empty field data from the patient report.
2395 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2396 // Handle starting of a new row.
2397 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
2401 echo "<td class='groupname'>";
2402 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2403 //echo "<font color='#008800'>$group_name</font>";
2405 // Added 5-09 by BM - Translate label if applicable
2406 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
);
2410 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2411 echo "<td valign='top'> ";
2416 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2418 // Handle starting of a new label cell.
2419 if ($titlecols > 0) {
2421 //echo "<td class='label' colspan='$titlecols' valign='top'";
2422 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
2423 echo "<td class='label' colspan='$titlecols_esc' ";
2424 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2426 $cell_count +
= $titlecols;
2430 // Added 5-09 by BM - Translate label if applicable
2431 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES
); else echo " ";
2433 // Handle starting of a new data cell.
2434 if ($datacols > 0) {
2436 //echo "<td class='text data' colspan='$datacols' valign='top'";
2437 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
2438 echo "<td class='text data' colspan='$datacols_esc'";
2439 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2441 $cell_count +
= $datacols;
2445 echo generate_display_field($frow, $currvalue);
2452 function display_layout_tabs($formtype, $result1, $result2='') {
2453 global $item_count, $cell_count, $last_group, $CPR;
2455 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2456 "WHERE form_id = ? AND uor > 0 " .
2457 "ORDER BY group_name, seq", array($formtype) );
2460 while ($frow = sqlFetchArray($fres)) {
2461 $this_group = $frow['group_name'];
2462 $group_name = substr($this_group, 1);
2463 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2465 <li
<?php
echo $first ?
'class="current"' : '' ?
>>
2466 <a href
="#" id
="header_tab_<?php echo str_replace(" ", "_
",htmlspecialchars($group_name,ENT_QUOTES))?>">
2467 <?php
echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
); ?
></a
>
2474 function display_layout_tabs_data($formtype, $result1, $result2='') {
2475 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2477 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2478 "WHERE form_id = ? AND uor > 0 " .
2479 "ORDER BY group_name, seq", array($formtype));
2482 while ($frow = sqlFetchArray($fres)) {
2483 $this_group = isset($frow['group_name']) ?
$frow['group_name'] : "" ;
2484 $titlecols = isset($frow['titlecols']) ?
$frow['titlecols'] : "";
2485 $datacols = isset($frow['datacols']) ?
$frow['datacols'] : "";
2486 $data_type = isset($frow['data_type']) ?
$frow['data_type'] : "";
2487 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : "";
2488 $list_id = isset($frow['list_id']) ?
$frow['list_id'] : "";
2491 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2493 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2494 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2495 "ORDER BY seq", array($formtype, $this_group) );
2498 <div
class="tab <?php echo $first ? 'current' : '' ?>">
2499 <table border
='0' cellpadding
='0'>
2502 while ($group_fields = sqlFetchArray($group_fields_query)) {
2504 $titlecols = $group_fields['titlecols'];
2505 $datacols = $group_fields['datacols'];
2506 $data_type = $group_fields['data_type'];
2507 $field_id = $group_fields['field_id'];
2508 $list_id = $group_fields['list_id'];
2510 $condition_str = get_conditions_str($condition_str,$group_fields);
2513 if ($formtype == 'DEM') {
2514 if (strpos($field_id, 'em_') === 0) {
2515 // Skip employer related fields, if it's disabled.
2516 if ($GLOBALS['omit_employers']) continue;
2517 $tmp = substr($field_id, 3);
2518 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2521 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2525 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2528 // Handle a data category (group) change.
2529 if (strcmp($this_group, $last_group) != 0) {
2530 $group_name = substr($this_group, 1);
2531 // totally skip generating the employer category, if it's disabled.
2532 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2533 $last_group = $this_group;
2536 // Handle starting of a new row.
2537 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
2542 if ($item_count == 0 && $titlecols == 0) {
2546 // Handle starting of a new label cell.
2547 if ($titlecols > 0) {
2549 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
2550 $field_id_label = 'label_'.$group_fields['field_id'];
2551 echo "<td class='label' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
2553 $cell_count +
= $titlecols;
2557 $field_id_label = 'label_'.$group_fields['field_id'];
2558 echo "<span id='".attr($field_id_label)."'>";
2559 // Added 5-09 by BM - Translate label if applicable
2560 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES
); else echo " ";
2563 // Handle starting of a new data cell.
2564 if ($datacols > 0) {
2566 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
2567 $field_id = 'text_'.$group_fields['field_id'];
2568 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
2570 $cell_count +
= $datacols;
2572 $field_id = 'text_'.$group_fields['field_id'];
2573 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
2577 echo generate_display_field($group_fields, $currvalue);
2594 function get_conditions_str($condition_str,$frow){
2595 $conditions = empty($frow['conditions']) ?
array() : unserialize($frow['conditions']);
2596 foreach ($conditions as $condition) {
2597 if (empty($condition['id'])) continue;
2598 $andor = empty($condition['andor']) ?
'' : $condition['andor'];
2599 if ($condition_str) $condition_str .= ",\n";
2600 $condition_str .= "{" .
2601 "target:'" . addslashes($frow['field_id']) . "', " .
2602 "id:'" . addslashes($condition['id']) . "', " .
2603 "itemid:'" . addslashes($condition['itemid']) . "', " .
2604 "operator:'" . addslashes($condition['operator']) . "', " .
2605 "value:'" . addslashes($condition['value']) . "', " .
2606 "andor:'" . addslashes($andor) . "'}";
2608 return $condition_str;
2610 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2611 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2613 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2614 "WHERE form_id = ? AND uor > 0 " .
2615 "ORDER BY group_name, seq", array($formtype) );
2618 while ($frow = sqlFetchArray($fres)) {
2619 $this_group = $frow['group_name'];
2620 $group_name = substr($this_group, 1);
2621 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES
);
2622 $titlecols = $frow['titlecols'];
2623 $datacols = $frow['datacols'];
2624 $data_type = $frow['data_type'];
2625 $field_id = $frow['field_id'];
2626 $list_id = $frow['list_id'];
2629 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2631 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2632 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2633 "ORDER BY seq", array($formtype,$this_group) );
2636 <div
class="tab <?php echo $first ? 'current' : '' ?>" id
="tab_<?php echo str_replace(' ', '_',$group_name_esc)?>" >
2637 <table border
='0' cellpadding
='0'>
2640 while ($group_fields = sqlFetchArray($group_fields_query)) {
2642 $titlecols = $group_fields['titlecols'];
2643 $datacols = $group_fields['datacols'];
2644 $data_type = $group_fields['data_type'];
2645 $field_id = $group_fields['field_id'];
2646 $list_id = $group_fields['list_id'];
2647 $backup_list = $group_fields['list_backup_id'];
2648 $condition_str = get_conditions_str($condition_str,$group_fields);
2651 if ($formtype == 'DEM') {
2652 if (strpos($field_id, 'em_') === 0) {
2653 // Skip employer related fields, if it's disabled.
2654 if ($GLOBALS['omit_employers']) continue;
2655 $tmp = substr($field_id, 3);
2656 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2659 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2663 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2666 // Handle a data category (group) change.
2667 if (strcmp($this_group, $last_group) != 0) {
2668 $group_name = substr($this_group, 1);
2669 // totally skip generating the employer category, if it's disabled.
2670 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2671 $last_group = $this_group;
2674 // Handle starting of a new row.
2675 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
2680 if ($item_count == 0 && $titlecols == 0) {
2684 // Handle starting of a new label cell.
2685 if ($titlecols > 0) {
2687 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
2688 $field_id_label = 'label_'.$group_fields['field_id'];
2689 echo "<td class='label' colspan='$titlecols_esc' id='$field_id_label' ";
2691 $cell_count +
= $titlecols;
2695 // Added 5-09 by BM - Translate label if applicable
2696 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES
).":"); else echo " ";
2698 // Handle starting of a new data cell.
2699 if ($datacols > 0) {
2701 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
2702 $field_id = 'text_'.$group_fields['field_id'];
2703 echo "<td class='text data' colspan='$datacols_esc' id='$field_id'";
2705 $cell_count +
= $datacols;
2710 echo generate_form_field($group_fields, $currvalue);
2724 // From the currently posted HTML form, this gets the value of the
2725 // field corresponding to the provided layout_options table row.
2727 function get_layout_form_value($frow, $prefix='form_') {
2728 // Bring in $sanitize_all_escapes variable, which will decide
2729 // the variable escaping method.
2730 global $sanitize_all_escapes;
2732 $maxlength = empty($frow['max_length']) ?
0 : intval($frow['max_length']);
2733 $data_type = $frow['data_type'];
2734 $field_id = $frow['field_id'];
2736 if (isset($_POST["$prefix$field_id"])) {
2737 if ($data_type == 21) {
2738 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2739 // must be concatenated into a |-separated string.
2740 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2741 if (strlen($value)) $value .= '|';
2745 else if ($data_type == 22) {
2746 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2747 // into "key:value|key:value|...".
2748 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2749 $val = str_replace('|', ' ', $val);
2750 if (strlen($value)) $value .= '|';
2751 $value .= "$key:$val";
2754 else if ($data_type == 23) {
2755 // $_POST["$prefix$field_id"] is an array of text fields with companion
2756 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2757 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2758 $restype = $_POST["radio_{$field_id}"][$key];
2759 if (empty($restype)) $restype = '0';
2760 $val = str_replace('|', ' ', $val);
2761 if (strlen($value)) $value .= '|';
2762 $value .= "$key:$restype:$val";
2765 else if ($data_type == 25) {
2766 // $_POST["$prefix$field_id"] is an array of text fields with companion
2767 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2768 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2769 $restype = empty($_POST["check_{$field_id}"][$key]) ?
'0' : '1';
2770 $val = str_replace('|', ' ', $val);
2771 if (strlen($value)) $value .= '|';
2772 $value .= "$key:$restype:$val";
2775 else if ($data_type == 28 ||
$data_type == 32) {
2776 // $_POST["$prefix$field_id"] is an date text fields with companion
2777 // radio buttons to be imploded into "notes|type|date".
2778 $restype = $_POST["radio_{$field_id}"];
2779 if (empty($restype)) $restype = '0';
2780 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2781 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2782 if ($data_type == 32)
2784 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2785 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2786 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2787 $value = "$res_text_note|$restype|$resdate|$reslist";
2790 $value = "$resnote|$restype|$resdate";
2792 else if ($data_type == 36) {
2793 $value_array = $_POST["form_$field_id"];
2795 foreach ($value_array as $key => $valueofkey) {
2797 $value = $valueofkey;
2799 $value = $value . "|" . $valueofkey;
2805 $value = $_POST["$prefix$field_id"];
2809 // Better to die than to silently truncate data!
2810 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2811 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES
) .
2812 ":<br /> <br />".htmlspecialchars( $value, ENT_NOQUOTES
));
2814 // Make sure the return value is quote-safe.
2815 if ($sanitize_all_escapes) {
2816 //escapes already removed and using binding/placemarks in sql calls
2817 // so only need to trim value
2818 return trim($value);
2821 //need to explicitly prepare value
2822 return formTrim($value);
2826 // Generate JavaScript validation logic for the required fields.
2828 function generate_layout_validation($form_id) {
2829 $fres = sqlStatement("SELECT * FROM layout_options " .
2830 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2831 "ORDER BY group_name, seq", array($form_id) );
2833 while ($frow = sqlFetchArray($fres)) {
2834 $data_type = $frow['data_type'];
2835 $field_id = $frow['field_id'];
2836 $fldtitle = $frow['title'];
2837 if (!$fldtitle) $fldtitle = $frow['description'];
2838 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES
);
2840 if ($data_type == 40) {
2841 $fldid = addslashes("form_$field_id");
2842 // Move canvas image data to its hidden form field so the server will get it.
2844 " var canfld = f['$fldid'];\n" .
2845 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
2849 if ($frow['uor'] < 2) continue;
2851 switch($data_type) {
2860 " if (f.$fldname.selectedIndex <= 0) {\n" .
2861 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2862 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2865 case 27: // radio buttons
2868 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2869 " if (i >= f.$fldname.length) {\n" .
2870 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2878 " if (trimlen(f.$fldname.value) == 0) {\n" .
2879 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2880 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2881 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2882 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2884 " $('#" . $fldname . "').attr('style',''); " .
2885 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2888 case 36: // multi select
2890 " var multi_select=f['$fldname"."[]']; \n " .
2891 " var multi_choice_made=false; \n".
2892 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
2893 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
2895 " if(!multi_choice_made)
2896 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2904 * DROPDOWN FOR FACILITIES
2906 * build a dropdown with all facilities
2908 * @param string $selected - name of the currently selected facility
2909 * use '0' for "unspecified facility"
2910 * use '' for "All facilities" (the default)
2911 * @param string $name - the name/id for select form (defaults to "form_facility")
2912 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2914 * @return void - just echo the html encoded string
2916 * Note: This should become a data-type at some point, according to Brady
2918 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2919 $allow_allfacilities = true, $disabled='', $onchange='')
2921 $have_selected = false;
2922 $query = "SELECT id, name FROM facility ORDER BY name";
2923 $fres = sqlStatement($query);
2925 $name = htmlspecialchars($name, ENT_QUOTES
);
2926 echo " <select name='$name' id='$name'";
2927 if ($onchange) echo " onchange='$onchange'";
2928 echo " $disabled>\n";
2930 if ($allow_allfacilities) {
2932 $option_selected_attr = '';
2933 if ($selected == '') {
2934 $option_selected_attr = ' selected="selected"';
2935 $have_selected = true;
2937 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES
);
2938 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2939 } elseif ($allow_unspecified) {
2940 $option_value = '0';
2941 $option_selected_attr = '';
2942 if ( $selected == '0' ) {
2943 $option_selected_attr = ' selected="selected"';
2944 $have_selected = true;
2946 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
2947 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2950 while ($frow = sqlFetchArray($fres)) {
2951 $facility_id = $frow['id'];
2952 $option_value = htmlspecialchars($facility_id, ENT_QUOTES
);
2953 $option_selected_attr = '';
2954 if ($selected == $facility_id) {
2955 $option_selected_attr = ' selected="selected"';
2956 $have_selected = true;
2958 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES
);
2959 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2962 if ($allow_unspecified && $allow_allfacilities) {
2963 $option_value = '0';
2964 $option_selected_attr = '';
2965 if ( $selected == '0' ) {
2966 $option_selected_attr = ' selected="selected"';
2967 $have_selected = true;
2969 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
2970 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2973 if (!$have_selected) {
2974 $option_value = htmlspecialchars($selected, ENT_QUOTES
);
2975 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES
);
2976 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES
);
2977 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2979 echo " </select>\n";
2982 // Expand Collapse Widget
2983 // This forms the header and functionality component of the widget. The information that is displayed
2984 // then follows this function followed by a closing div tag
2986 // $title is the title of the section (already translated)
2987 // $label is identifier used in the tag id's and sql columns
2988 // $buttonLabel is the button label text (already translated)
2989 // $buttonLink is the button link information
2990 // $buttonClass is any additional needed class elements for the button tag
2991 // $linkMethod is the button link method ('javascript' vs 'html')
2992 // $bodyClass is to set class(es) of the body
2993 // $auth is a flag to decide whether to show the button
2994 // $fixedWidth is to flag whether width is fixed
2995 // $forceExpandAlways is a flag to force the widget to always be expanded
2997 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2999 echo "<div class='section-header'>";
3002 echo "<div class='section-header-dynamic'>";
3006 // show button, since authorized
3007 // first prepare class string
3009 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES
);
3012 $class_string = "css_button_small";
3014 // next, create the link
3015 if ($linkMethod == "javascript") {
3016 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3019 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3020 if (!isset($_SESSION['patient_portal_onsite']) && !isset($_SESSION['patient_portal_onsite_two']) ) {
3021 // prevent an error from occuring when calling the function from the patient portal
3022 echo " onclick='top.restoreSession()'";
3026 htmlspecialchars( $buttonLabel, ENT_NOQUOTES
) . "</span></a></td>";
3028 if ($forceExpandAlways){
3029 // Special case to force the widget to always be expanded
3030 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES
) . "</b></span>";
3031 $indicatorTag ="style='display:none'";
3033 $indicatorTag = isset($indicatorTag) ?
$indicatorTag : "";
3034 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3035 htmlspecialchars( $label, ENT_QUOTES
) . "_ps_expand\")'><span class='text'><b>";
3036 echo htmlspecialchars( $title, ENT_NOQUOTES
) . "</b></span>";
3038 if (isset($_SESSION['patient_portal_onsite']) ||
isset($_SESSION['patient_portal_onsite_two'])) {
3039 // collapse all entries in the patient portal
3040 $text = xl('expand');
3042 else if (getUserSetting($label."_ps_expand")) {
3043 $text = xl('collapse');
3046 $text = xl('expand');
3048 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES
) .
3049 "</span>)</a></td>";
3050 echo "</tr></table>";
3052 if ($forceExpandAlways) {
3053 // Special case to force the widget to always be expanded
3056 else if (isset($_SESSION['patient_portal_onsite']) ||
isset($_SESSION['patient_portal_onsite_two'])) {
3057 // collapse all entries in the patient portal
3058 $styling = "style='display:none'";
3060 else if (getUserSetting($label."_ps_expand")) {
3064 $styling = "style='display:none'";
3067 $styling .= " class='" . $bodyClass . "'";
3069 //next, create the first div tag to hold the information
3070 // note the code that calls this function will then place the ending div tag after the data
3071 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES
) . "_ps_expand' " . $styling . ">";
3074 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3075 function billing_facility($name,$select){
3076 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
3077 echo " <select id='".htmlspecialchars($name, ENT_QUOTES
)."' name='".htmlspecialchars($name, ENT_QUOTES
)."'>";
3078 while ($facrow = sqlFetchArray($qsql)) {
3079 $selected = ( $facrow['id'] == $select ) ?
'selected="selected"' : '' ;
3080 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES
)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES
)."</option>";
3085 // Generic function to get the translated title value for a particular list option.
3087 function getListItemTitle($list, $option) {
3088 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3089 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3090 if (empty($row['title'])) return $option;
3091 return xl_list_label($row['title']);
3093 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3094 function getSmokeCodes()
3096 $smoking_codes_arr = array();
3097 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3098 while($codes_row = sqlFetchArray($smoking_codes))
3100 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3102 return $smoking_codes_arr;
3105 // Get the current value for a layout based form field.
3106 // Depending on options this might come from lbf_data, patient_data,
3107 // form_encounter, shared_attributes or elsewhere.
3108 // Returns FALSE if the field ID is invalid (layout error).
3110 function lbf_current_value($frow, $formid, $encounter) {
3112 $formname = $frow['form_id'];
3113 $field_id = $frow['field_id'];
3114 $source = $frow['source'];
3116 $deffname = $formname . '_default_' . $field_id;
3117 if ($source == 'D' ||
$source == 'H') {
3118 // Get from patient_data, employer_data or history_data.
3119 if ($source == 'H') {
3120 $table = 'history_data';
3121 $orderby = 'ORDER BY date DESC LIMIT 1';
3123 else if (strpos($field_id, 'em_') === 0) {
3124 $field_id = substr($field_id, 3);
3125 $table = 'employer_data';
3126 $orderby = 'ORDER BY date DESC LIMIT 1';
3129 $table = 'patient_data';
3132 // It is an error if the field does not exist, but don't crash.
3133 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3134 if (empty($tmp)) return FALSE;
3135 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3136 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3138 else if ($source == 'E') {
3140 // Get value from shared_attributes of the current encounter.
3141 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3142 "pid = ? AND encounter = ? AND field_id = ?",
3143 array($pid, $encounter, $field_id));
3144 if (isset($sarow)) $currvalue = $sarow['field_value'];
3147 // Get from shared_attributes of the encounter that this form is linked to.
3148 // Note the importance of having an index on forms.form_id.
3149 $sarow = sqlQuery("SELECT sa.field_value " .
3150 "FROM forms AS f, shared_attributes AS sa WHERE " .
3151 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3152 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3153 array($formid, $formname, $field_id));
3154 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3157 // New form and encounter not available, this should not happen.
3160 else if ($source == 'V') {
3162 // Get value from the current encounter's form_encounter.
3163 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3164 "pid = ? AND encounter = ?",
3165 array($pid, $encounter));
3166 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3169 // Get value from the form_encounter that this form is linked to.
3170 $ferow = sqlQuery("SELECT fe.* " .
3171 "FROM forms AS f, form_encounter AS fe WHERE " .
3172 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3173 "fe.pid = f.pid AND fe.encounter = f.encounter",
3174 array($formid, $formname));
3175 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3178 // New form and encounter not available, this should not happen.
3182 // This is a normal form field.
3183 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3184 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3185 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3188 // New form, see if there is a custom default from a plugin.
3189 // This logic does not apply to shared attributes because they do not
3190 // have a "new form" concept.
3191 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3196 // This returns stuff that needs to go into the <head> section of a caller using
3197 // the drawable image field type in a form.
3198 // A TRUE argument makes the widget controls smaller.
3200 function lbf_canvas_head($small=TRUE) {
3202 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3203 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3204 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3205 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3207 if ($small) $s .= <<<EOD
3209 /* Custom LiterallyCanvas styling.
3210 * This makes the widget 25% less tall and adjusts some other things accordingly.
3213 min-height:100%;min-width:300px; /* Was 400, unspecified */
3215 .literally .lc-picker .toolbar-button {
3216 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3218 .literally .color-well {
3219 font-size:8px;width:49px; /* Was 10, 60 */
3221 .literally .color-well-color-container {
3222 width:21px;height:21px; /* Was 28, 28 */
3224 .literally .lc-picker {
3225 width:50px; /* Was 61 */
3227 .literally .lc-drawing.with-gui {
3228 left:50px; /* Was 61 */
3230 .literally .lc-options {
3231 left:50px; /* Was 61 */
3233 .literally .color-picker-popup {
3234 left:49px;bottom:0px; /* Was 60, 31 */