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'";
105 $class_esc = attr($class);
106 $s .= " class='$class_esc'";
109 $s .= " onchange='$onchange'";
111 if ($custom_attributes != null && is_array ( $custom_attributes )) {
112 foreach ( $custom_attributes as $attr => $val ) {
113 if (isset ( $custom_attributes [$attr] )) {
114 $s .= " " . attr($attr) . "='" . attr($val) . "'";
118 $selectTitle = attr($title);
119 $s .= " title='$selectTitle'>";
120 $selectEmptyName = xlt($empty_name);
122 $s .= "<option value=''>" . $selectEmptyName . "</option>";
124 // List order depends on language translation options.
125 // (Note we do not need to worry about the list order in the algorithm
126 // after the below code block since that is where searches for exceptions
127 // are done which include inactive items or items from a backup
128 // list; note these will always be shown at the bottom of the list no matter the
130 $lang_id = empty($_SESSION['language_choice']) ?
'1' : $_SESSION['language_choice'];
132 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) ||
!$GLOBALS['translate_lists']) {
134 if ($GLOBALS['gb_how_sort_list'] == '0') {
136 $order_by_sql = "seq, title";
138 else { //$GLOBALS['gb_how_sort_list'] == '1'
140 $order_by_sql = "title, seq";
142 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
146 if ($GLOBALS['gb_how_sort_list'] == '0') {
148 $order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
150 else { //$GLOBALS['gb_how_sort_list'] == '1'
152 $order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
154 $lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
155 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
156 "FROM list_options AS lo " .
157 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
158 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
160 "WHERE lo.list_id = ? AND lo.activity=1 " .
161 "ORDER BY " . $order_by_sql, array($lang_id, $list_id));
163 $got_selected = FALSE;
165 while ( $lrow = sqlFetchArray ( $lres ) ) {
166 $selectedValues = explode ( "|", $currvalue );
168 $optionValue = attr($lrow ['option_id']);
169 $s .= "<option value='$optionValue'";
171 if ((strlen ( $currvalue ) == 0 && $lrow ['is_default']) ||
(strlen ( $currvalue ) > 0 && in_array ( $lrow ['option_id'], $selectedValues ))) {
173 $got_selected = TRUE;
176 // Already has been translated above (if applicable), so do not need to use
177 // the xl_list_label() function here
178 $optionLabel = text($lrow ['title']);
179 $s .= ">$optionLabel</option>\n";
183 To show the inactive item in the list if the value is saved to database
185 if (!$got_selected && strlen($currvalue) > 0)
187 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
188 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
189 $lrow_inactive = sqlFetchArray($lres_inactive);
190 if($lrow_inactive['option_id']) {
191 $optionValue = htmlspecialchars( $lrow_inactive['option_id'], ENT_QUOTES
);
192 $s .= "<option value='$optionValue' selected>" . htmlspecialchars( xl_list_label($lrow_inactive['title']), ENT_NOQUOTES
) . "</option>\n";
193 $got_selected = TRUE;
197 if (!$got_selected && strlen ( $currvalue ) > 0 && !$multiple) {
198 $list_id = $backup_list;
199 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
201 if ($lrow > 0 && !empty($backup_list)) {
202 $selected = text(xl_list_label($lrow ['title']));
203 $s .= "<option value='$currescaped' selected> $selected </option>";
206 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
208 $fontTitle = xlt('Please choose a valid selection from the list.');
209 $fontText = xlt( 'Fix this' );
210 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
213 } else if (!$got_selected && strlen ( $currvalue ) > 0 && $multiple) {
214 //if not found in main list, display all selected values that exist in backup list
215 $list_id = $backup_list;
217 $got_selected_backup = FALSE;
218 if (!empty($backup_list)) {
219 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
220 while ( $lrow_backup = sqlFetchArray ( $lres_backup ) ) {
221 $selectedValues = explode ( "|", $currvalue );
223 $optionValue = attr($lrow_backup['option_id']);
225 if ( in_array($lrow_backup ['option_id'],$selectedValues)) {
226 $s .= "<option value='$optionValue'";
228 $optionLabel = text(xl_list_label($lrow_backup ['title']));
229 $s .= ">$optionLabel</option>\n";
230 $got_selected_backup = TRUE;
234 if (!$got_selected_backup) {
235 $selectedValues = explode ( "|", $currvalue );
236 foreach ( $selectedValues as $selectedValue ) {
237 $s .= "<option value='" . attr($selectedValue) . "'";
239 $s .= ">* " . text($selectedValue) . " *</option>\n";
242 $fontTitle = xlt('Please choose a valid selection from the list.');
243 $fontText = xlt( 'Fix this' );
244 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
255 // $frow is a row from the layout_options table.
256 // $currvalue is the current value, if any, of the associated item.
258 function generate_form_field($frow, $currvalue) {
259 global $rootdir, $date_init, $ISSUE_TYPES, $code_types,$condition_str;
261 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
263 $data_type = $frow['data_type'];
264 $field_id = $frow['field_id'];
265 $list_id = $frow['list_id'];
266 $backup_list = $frow['list_backup_id'];
267 $condition_str = get_conditions_str($condition_str,$frow);
269 // escaped variables to use in html
270 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES
);
271 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES
);
273 // Added 5-09 by BM - Translate description if applicable
274 $description = (isset($frow['description']) ?
htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
) : '');
276 // Support edit option T which assigns the (possibly very long) description as
277 // the default value.
278 if (strpos($frow['edit_options'], 'T') !== FALSE) {
279 if (strlen($currescaped) == 0) $currescaped = $description;
280 // Description used in this way is not suitable as a title.
284 // added 5-2009 by BM to allow modification of the 'empty' text title field.
285 // Can pass $frow['empty_title'] with this variable, otherwise
286 // will default to 'Unassigned'.
287 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
288 // if make $frow['empty_title'] equal to 'SKIP'
290 if (isset($frow['empty_title'])) {
291 if ($frow['empty_title'] == "SKIP") {
292 //do not display an 'empty' choice
294 $empty_title = "Unassigned";
297 $empty_title = $frow['empty_title'];
301 $empty_title = "Unassigned";
304 $disabled = strpos($frow['edit_options'], '0') === FALSE ?
'' : 'disabled';
306 $lbfchange = (strpos($frow['form_id'], 'LBF') === 0 ||
strpos($frow['form_id'], 'LBT') === 0) ?
307 "checkSkipConditions();" : "";
308 $lbfonchange = $lbfchange ?
"onchange='$lbfchange'" : "";
310 // generic single-selection list or Race and Ethnicity.
311 // These data types support backup lists.
312 if ($data_type == 1 ||
$data_type == 33) {
313 echo generate_select_list("form_$field_id", $list_id, $currvalue,
314 $description, ($showEmpty ?
$empty_title : ''), '', $lbfchange, '',
315 ($disabled ?
array('disabled' => 'disabled') : null), false, $backup_list);
319 else if ($data_type == 2) {
320 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
321 $maxlength = $frow['max_length'];
322 $string_maxlength = "";
323 // if max_length is set to zero, then do not set a maxlength
324 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
325 echo "<input type='text'" .
326 " name='form_$field_id_esc'" .
327 " id='form_$field_id_esc'" .
328 " size='$fldlength'" .
329 " $string_maxlength" .
330 " title='$description'" .
331 " value='$currescaped'";
333 if (strpos($frow['edit_options'], 'C') !== FALSE)
334 $tmp .= "capitalizeMe(this);";
335 else if (strpos($frow['edit_options'], 'U') !== FALSE)
336 $tmp .= "this.value = this.value.toUpperCase();";
337 if ($tmp) echo " onchange='$tmp'";
338 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES
);
339 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
340 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
341 echo " onblur='maskblur(this,\"$tmp\")'";
343 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
346 if ($disabled) echo ' disabled';
350 // long or multi-line text field
351 else if ($data_type == 3) {
352 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
353 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES
);
355 " name='form_$field_id_esc'" .
356 " id='form_$field_id_esc'" .
357 " title='$description'" .
358 " cols='$textCols'" .
359 " rows='$textRows' $lbfonchange $disabled" .
360 ">" . $currescaped . "</textarea>";
364 else if ($data_type == 4) {
365 $age_asof_date = ''; // optionalAge() sets this
366 $age_format = strpos($frow['edit_options'], 'A') === FALSE ?
3 : 0;
367 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
369 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
371 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
372 " value='" . substr($currescaped, 0, 10) . "'";
373 if (!$agestr) echo " title='$description'";
374 echo " $lbfonchange onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
376 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
377 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
378 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' />";
379 $date_init .= " Calendar.setup({" .
380 "inputField:'form_$field_id', " .
381 "ifFormat:'%Y-%m-%d', ";
383 $date_init .= "onUpdate: function() {" .
384 "if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format);" .
387 $date_init .= "button:'img_$field_id'})\n";
389 // Optional display of age or gestational age.
391 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
395 // provider list, local providers only
396 else if ($data_type == 10) {
397 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
398 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
399 "AND authorized = 1 " .
400 "ORDER BY lname, fname");
401 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled>";
402 echo "<option value=''>" . xlt($empty_title) . "</option>";
403 $got_selected = false;
404 while ($urow = sqlFetchArray($ures)) {
405 $uname = text($urow['fname'] . ' ' . $urow['lname']);
406 $optionId = attr($urow['id']);
407 echo "<option value='$optionId'";
408 if ($urow['id'] == $currvalue) {
410 $got_selected = true;
412 echo ">$uname</option>";
414 if (!$got_selected && $currvalue) {
415 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
417 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
424 // provider list, including address book entries with an NPI number
425 else if ($data_type == 11) {
426 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
427 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
428 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
429 "ORDER BY lname, fname");
430 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
431 echo " $lbfonchange $disabled>";
432 echo "<option value=''>" . xlt('Unassigned') . "</option>";
433 $got_selected = false;
434 while ($urow = sqlFetchArray($ures)) {
435 $uname = text($urow['fname'] . ' ' . $urow['lname']);
436 $optionId = attr($urow['id']);
437 echo "<option value='$optionId'";
438 if ($urow['id'] == $currvalue) {
440 $got_selected = true;
442 echo ">$uname</option>";
444 if (!$got_selected && $currvalue) {
445 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
447 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
455 else if ($data_type == 12) {
456 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
457 echo " $lbfonchange $disabled>";
458 echo "<option value='0'></option>";
459 $pres = get_pharmacies();
460 $got_selected = false;
461 while ($prow = sqlFetchArray($pres)) {
463 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
464 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
465 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
466 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
467 echo "<option value='$optionValue'";
468 if ($currvalue == $key) {
470 $got_selected = true;
472 echo ">$optionLabel</option>";
474 if (!$got_selected && $currvalue) {
475 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
477 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
485 else if ($data_type == 13) {
486 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
487 echo " $lbfonchange $disabled>";
488 echo "<option value=''> </option>";
489 $squads = acl_get_squads();
491 foreach ($squads as $key => $value) {
492 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
493 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES
);
494 echo "<option value='$optionValue'";
495 if ($currvalue == $key) echo " selected";
496 echo ">$optionLabel</option>\n";
502 // Address book, preferring organization name if it exists and is not in
503 // parentheses, and excluding local users who are not providers.
504 // Supports "referred to" practitioners and facilities.
505 // Alternatively the letter L in edit_options means that abook_type
506 // must be "ord_lab", indicating types used with the procedure
507 // lab ordering system.
508 // Alternatively the letter O in edit_options means that abook_type
509 // must begin with "ord_", indicating types used with the procedure
511 // Alternatively the letter V in edit_options means that abook_type
512 // must be "vendor", indicating the Vendor type.
513 // Alternatively the letter R in edit_options means that abook_type
514 // must be "dist", indicating the Distributor type.
515 else if ($data_type == 14) {
516 if (strpos($frow['edit_options'], 'L') !== FALSE)
517 $tmp = "abook_type = 'ord_lab'";
518 else if (strpos($frow['edit_options'], 'O') !== FALSE)
519 $tmp = "abook_type LIKE 'ord\\_%'";
520 else if (strpos($frow['edit_options'], 'V') !== FALSE)
521 $tmp = "abook_type LIKE 'vendor%'";
522 else if (strpos($frow['edit_options'], 'R') !== FALSE)
523 $tmp = "abook_type LIKE 'dist'";
525 $tmp = "( username = '' OR authorized = 1 )";
526 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
527 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
529 "ORDER BY organization, lname, fname");
530 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
531 echo " $lbfonchange $disabled>";
532 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
533 while ($urow = sqlFetchArray($ures)) {
534 $uname = $urow['organization'];
535 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
536 $uname = $urow['lname'];
537 if ($urow['fname']) $uname .= ", " . $urow['fname'];
539 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES
);
540 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES
);
541 echo "<option value='$optionValue'";
542 $title = $urow['username'] ?
xl('Local') : xl('External');
543 $optionTitle = htmlspecialchars( $title, ENT_QUOTES
);
544 echo " title='$optionTitle'";
545 if ($urow['id'] == $currvalue) echo " selected";
546 echo ">$optionLabel</option>";
551 // A billing code. If description matches an existing code type then that type is used.
552 else if ($data_type == 15) {
553 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
554 $maxlength = $frow['max_length'];
555 $string_maxlength = "";
556 // if max_length is set to zero, then do not set a maxlength
557 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
559 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
560 // Option "2" generates a hidden input for the codes, and a matching visible field
561 // displaying their descriptions. First step is computing the description string.
562 $currdescstring = '';
563 if (!empty($currvalue)) {
564 $relcodes = explode(';', $currvalue);
565 foreach ($relcodes as $codestring) {
566 if ($codestring === '') continue;
567 $code_text = lookup_code_descriptions($codestring);
568 if ($currdescstring !== '') $currdescstring .= '; ';
569 if (!empty($code_text)) {
570 $currdescstring .= $code_text;
573 $currdescstring .= $codestring;
577 $currdescstring = attr($currdescstring);
579 echo "<input type='text'" .
580 " name='form_$field_id_esc'" .
581 " id='form_related_code'" .
582 " size='$fldlength'" .
583 " value='$currescaped'" .
584 " style='display:none'" .
585 " $lbfonchange readonly $disabled />";
586 // Extra readonly input field for optional display of code description(s).
587 echo "<input type='text'" .
588 " name='form_$field_id_esc" . "__desc'" .
589 " size='$fldlength'" .
590 " title='$description'" .
591 " value='$currdescstring'";
593 echo " onclick='sel_related(this,\"$codetype\")'";
595 echo " readonly $disabled />";
598 echo "<input type='text'" .
599 " name='form_$field_id_esc'" .
600 " id='form_related_code'" .
601 " size='$fldlength'" .
602 " $string_maxlength" .
603 " title='$description'" .
604 " value='$currescaped'";
606 echo " onclick='sel_related(this,\"$codetype\")'";
608 echo " $lbfonchange readonly $disabled />";
612 // insurance company list
613 else if ($data_type == 16) {
614 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
615 echo "<option value='0'></option>";
616 $insprovs = getInsuranceProviders();
617 $got_selected = false;
618 foreach ($insprovs as $key => $ipname) {
619 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
620 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES
);
621 echo "<option value='$optionValue'";
622 if ($currvalue == $key) {
624 $got_selected = true;
626 echo ">$optionLabel</option>";
628 if (!$got_selected && $currvalue) {
629 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
631 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
639 else if ($data_type == 17) {
640 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
641 echo "<option value='0'></option>";
642 $got_selected = false;
643 foreach ($ISSUE_TYPES as $key => $value) {
644 $optionValue = htmlspecialchars($key, ENT_QUOTES
);
645 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES
);
646 echo "<option value='$optionValue'";
647 if ($currvalue == $key) {
649 $got_selected = true;
651 echo ">$optionLabel</option>";
653 if (!$got_selected && strlen($currvalue) > 0) {
654 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
656 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
664 else if ($data_type == 18) {
665 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
666 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
667 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
668 " $lbfonchange $disabled>";
669 echo "<option value=''>" . xlt($empty_title) . "</option>";
670 $got_selected = false;
671 while ($crow = sqlFetchArray($cres)) {
672 $catid = $crow['pc_catid'];
673 if (($catid < 9 && $catid != 5) ||
$catid == 11) continue;
674 echo "<option value='" . attr($catid) . "'";
675 if ($catid == $currvalue) {
677 $got_selected = true;
679 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
681 if (!$got_selected && $currvalue) {
682 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
684 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
691 // a set of labeled checkboxes
692 else if ($data_type == 21) {
693 // In this special case, fld_length is the number of columns generated.
694 $cols = max(1, $frow['fld_length']);
695 $avalue = explode('|', $currvalue);
696 $lres = sqlStatement("SELECT * FROM list_options " .
697 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
698 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
699 $tdpct = (int) (100 / $cols);
700 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
701 $option_id = $lrow['option_id'];
702 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
703 // if ($count) echo "<br />";
704 if ($count %
$cols == 0) {
705 if ($count) echo "</tr>";
708 echo "<td width='$tdpct%'>";
709 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
710 "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
711 if (in_array($option_id, $avalue)) echo " checked";
713 // Added 5-09 by BM - Translate label if applicable
714 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
720 if ($count > $cols) {
721 // Add some space after multiple rows of checkboxes.
722 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
723 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
729 // a set of labeled text input fields
730 else if ($data_type == 22) {
731 $tmp = explode('|', $currvalue);
733 foreach ($tmp as $value) {
734 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
735 $avalue[$matches[1]] = $matches[2];
738 $lres = sqlStatement("SELECT * FROM list_options " .
739 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
740 echo "<table cellpadding='0' cellspacing='0'>";
741 while ($lrow = sqlFetchArray($lres)) {
742 $option_id = $lrow['option_id'];
743 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
744 $maxlength = $frow['max_length'];
745 $string_maxlength = "";
746 // if max_length is set to zero, then do not set a maxlength
747 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
748 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
750 // Added 5-09 by BM - Translate label if applicable
751 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
752 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
753 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
754 echo "<td><input type='text'" .
755 " name='form_{$field_id_esc}[$option_id_esc]'" .
756 " id='form_{$field_id_esc}[$option_id_esc]'" .
757 " size='$fldlength'" .
758 " $string_maxlength" .
759 " value='$optionValue'";
760 echo " $lbfonchange $disabled /></td></tr>";
765 // a set of exam results; 3 radio buttons and a text field:
766 else if ($data_type == 23) {
767 $tmp = explode('|', $currvalue);
769 foreach ($tmp as $value) {
770 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
771 $avalue[$matches[1]] = $matches[2];
774 $maxlength = $frow['max_length'];
775 $string_maxlength = "";
776 // if max_length is set to zero, then do not set a maxlength
777 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
778 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
779 $lres = sqlStatement("SELECT * FROM list_options " .
780 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
781 echo "<table cellpadding='0' cellspacing='0'>";
782 echo "<tr><td> </td><td class='bold'>" .
783 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
784 " </td><td class='bold'>" .
785 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
786 "<td class='bold'>" .
787 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
788 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
789 while ($lrow = sqlFetchArray($lres)) {
790 $option_id = $lrow['option_id'];
791 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
792 $restype = substr($avalue[$option_id], 0, 1);
793 $resnote = substr($avalue[$option_id], 2);
795 // Added 5-09 by BM - Translate label if applicable
796 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
798 for ($i = 0; $i < 3; ++
$i) {
799 $inputValue = htmlspecialchars( $i, ENT_QUOTES
);
800 echo "<td><input type='radio'" .
801 " name='radio_{$field_id_esc}[$option_id_esc]'" .
802 " id='radio_{$field_id_esc}[$option_id_esc]'" .
803 " value='$inputValue' $lbfonchange";
804 if ($restype === "$i") echo " checked";
805 echo " $disabled /></td>";
807 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
808 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
809 echo "<td><input type='text'" .
810 " name='form_{$field_id_esc}[$option_id_esc]'" .
811 " id='form_{$field_id_esc}[$option_id_esc]'" .
812 " size='$fldlength'" .
813 " $string_maxlength" .
814 " value='$resnote' $disabled /></td>";
820 // the list of active allergies for the current patient
821 // this is read-only!
822 else if ($data_type == 24) {
823 $query = "SELECT title, comments FROM lists WHERE " .
824 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
826 // echo "<!-- $query -->\n"; // debugging
827 $lres = sqlStatement($query, array($GLOBALS['pid']));
829 while ($lrow = sqlFetchArray($lres)) {
830 if ($count++
) echo "<br />";
831 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES
);
832 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES
) . ')';
836 // a set of labeled checkboxes, each with a text field:
837 else if ($data_type == 25) {
838 $tmp = explode('|', $currvalue);
840 foreach ($tmp as $value) {
841 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
842 $avalue[$matches[1]] = $matches[2];
845 $maxlength = $frow['max_length'];
846 $string_maxlength = "";
847 // if max_length is set to zero, then do not set a maxlength
848 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
849 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
850 $lres = sqlStatement("SELECT * FROM list_options " .
851 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
852 echo "<table cellpadding='0' cellspacing='0'>";
853 while ($lrow = sqlFetchArray($lres)) {
854 $option_id = $lrow['option_id'];
855 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
856 $restype = substr($avalue[$option_id], 0, 1);
857 $resnote = substr($avalue[$option_id], 2);
859 // Added 5-09 by BM - Translate label if applicable
860 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
862 $option_id = htmlspecialchars( $option_id, ENT_QUOTES
);
863 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
864 " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
865 if ($restype) echo " checked";
866 echo " $disabled /> </td>";
867 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
868 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
869 echo "<td><input type='text'" .
870 " name='form_{$field_id_esc}[$option_id_esc]'" .
871 " id='form_{$field_id_esc}[$option_id_esc]'" .
872 " size='$fldlength'" .
873 " $string_maxlength" .
874 " value='$resnote' $disabled /></td>";
880 // single-selection list with ability to add to it
881 else if ($data_type == 26) {
882 echo generate_select_list("form_$field_id", $list_id, $currvalue,
883 $description, ($showEmpty ?
$empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
884 ($disabled ?
array('disabled' => 'disabled') : null), false, $backup_list);
885 // show the add button if user has access to correct list
886 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES
);
887 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
888 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
889 if (aco_exist('lists', $list_id)) {
890 // a specific aco exist for this list, so ensure access
891 if (acl_check('lists', $list_id)) echo $outputAddButton;
894 // no specific aco exist for this list, so check for access to 'default' list
895 if (acl_check('lists', 'default')) echo $outputAddButton;
899 // a set of labeled radio buttons
900 else if ($data_type == 27) {
901 // In this special case, fld_length is the number of columns generated.
902 $cols = max(1, $frow['fld_length']);
903 $lres = sqlStatement("SELECT * FROM list_options " .
904 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
905 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
906 $tdpct = (int) (100 / $cols);
907 $got_selected = FALSE;
908 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
909 $option_id = $lrow['option_id'];
910 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
911 if ($count %
$cols == 0) {
912 if ($count) echo "</tr>";
915 echo "<td width='$tdpct%'>";
916 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
917 " value='$option_id_esc' $lbfonchange";
918 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
919 (strlen($currvalue) > 0 && $option_id == $currvalue))
922 $got_selected = TRUE;
924 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES
);
929 if ($count > $cols) {
930 // Add some space after multiple rows of radio buttons.
931 $cols = htmlspecialchars($cols, ENT_QUOTES
);
932 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
936 if (!$got_selected && strlen($currvalue) > 0) {
937 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES
);
938 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
939 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
943 // special case for history of lifestyle status; 3 radio buttons and a date text field:
944 // VicarePlus :: A selection list box for smoking status:
945 else if ($data_type == 28 ||
$data_type == 32) {
946 $tmp = explode('|', $currvalue);
947 switch(count($tmp)) {
966 $resdate = $restype = "";
969 $restype = $resdate = $resnote = "";
972 $maxlength = $frow['max_length'];
973 $string_maxlength = "";
974 // if max_length is set to zero, then do not set a maxlength
975 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
976 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
978 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
979 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
980 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
981 echo "<table cellpadding='0' cellspacing='0'>";
983 if ($data_type == 28)
986 echo "<td><input type='text'" .
987 " name='form_$field_id_esc'" .
988 " id='form_$field_id_esc'" .
989 " size='$fldlength'" .
990 " $string_maxlength" .
991 " value='$resnote' $disabled /> </td>";
992 echo "<td class='bold'> ".
993 " ".
994 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
996 else if($data_type == 32)
999 echo "<tr><td><input type='text'" .
1000 " name='form_text_$field_id_esc'" .
1001 " id='form_text_$field_id_esc'" .
1002 " size='$fldlength'" .
1003 " $string_maxlength" .
1004 " value='$resnote' $disabled /> </td></tr>";
1006 //Selection list for smoking status
1007 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
1008 echo generate_select_list("form_$field_id", $list_id, $reslist,
1009 $description, ($showEmpty ?
$empty_title : ''), '', $onchange, '',
1010 ($disabled ?
array('disabled' => 'disabled') : null));
1012 echo "<td class='bold'> " . xlt('Status') . ": </td>";
1015 echo "<td class='text' ><input type='radio'" .
1016 " name='radio_{$field_id_esc}'" .
1017 " id='radio_{$field_id_esc}[current]'" .
1018 " value='current" . $field_id_esc . "' $lbfonchange";
1019 if ($restype == "current" . $field_id) echo " checked";
1020 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1021 echo " />" . xlt('Current') . " </td>";
1023 echo "<td class='text'><input type='radio'" .
1024 " name='radio_{$field_id_esc}'" .
1025 " id='radio_{$field_id_esc}[quit]'" .
1026 " value='quit".$field_id_esc."' $lbfonchange";
1027 if ($restype == "quit" . $field_id) echo " checked";
1028 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1029 echo " $disabled />" . xlt('Quit') . " </td>";
1031 echo "<td class='text'><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
1032 " value='$resdate'" .
1033 " title='$description'" .
1034 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
1036 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
1037 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
1038 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' />";
1039 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
1043 echo "<td class='text'><input type='radio'" .
1044 " name='radio_{$field_id_esc}'" .
1045 " id='radio_{$field_id_esc}[never]'" .
1046 " value='never" . $field_id_esc . "' $lbfonchange";
1047 if ($restype == "never" . $field_id) echo " checked";
1048 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1049 echo " />" . xlt('Never') . " </td>";
1051 echo "<td class='text'><input type='radio'" .
1052 " name='radio_{$field_id}'" .
1053 " id='radio_{$field_id}[not_applicable]'" .
1054 " value='not_applicable" . $field_id . "' $lbfonchange";
1055 if ($restype == "not_applicable" . $field_id) echo " checked";
1056 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1057 echo " $disabled />" . xlt('N/A') . " </td>";
1059 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1060 echo "<td class='text' ><div id='smoke_code'></div></td>";
1065 // static text. read-only, of course.
1066 else if ($data_type == 31) {
1067 echo nl2br($frow['description']);
1071 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1074 else if($data_type == 34){
1075 $arr = explode("|*|*|*|",$currvalue);
1076 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;'>";
1077 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES
)."</div>";
1078 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1082 //facilities drop-down list
1083 else if ($data_type == 35) {
1084 if (empty($currvalue)){
1087 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1088 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1092 // supports backup list
1093 else if ($data_type == 36) {
1094 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1095 $description, $showEmpty ?
$empty_title : '', '', $onchange, '', null, true, $backup_list);
1099 // Canvas and related elements for browser-side image drawing.
1100 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1101 else if ($data_type == 40) {
1102 // Unlike other field types, width and height are in pixels.
1103 $canWidth = intval($frow['fld_length']);
1104 $canHeight = intval($frow['fld_rows']);
1105 if (empty($currvalue)) {
1106 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1107 // If defined this is the filename of the default starting image.
1108 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1111 echo "<div id='form_$field_id_esc'></div>";
1112 // Hidden form field exists to send updated data to the server at submit time.
1113 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1114 // Hidden image exists to support initialization of the canvas.
1115 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1116 // $date_init is a misnomer but it's the place for browser-side setup logic.
1117 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1122 function generate_print_field($frow, $currvalue) {
1123 global $rootdir, $date_init, $ISSUE_TYPES;
1125 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
1127 $data_type = $frow['data_type'];
1128 $field_id = $frow['field_id'];
1129 $list_id = $frow['list_id'];
1130 $fld_length = $frow['fld_length'];
1131 $backup_list = $frow['list_backup_id'];
1133 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
1135 // Can pass $frow['empty_title'] with this variable, otherwise
1136 // will default to 'Unassigned'.
1137 // If it is 'SKIP' then an empty text title is completely skipped.
1139 if (isset($frow['empty_title'])) {
1140 if ($frow['empty_title'] == "SKIP") {
1141 //do not display an 'empty' choice
1143 $empty_title = "Unassigned";
1146 $empty_title = $frow['empty_title'];
1150 $empty_title = "Unassigned";
1153 // generic single-selection list
1154 // Supports backup lists.
1155 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33) {
1156 if (empty($fld_length)) {
1157 if ($list_id == 'titles') {
1165 $lrow = sqlQuery("SELECT title FROM list_options " .
1166 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue));
1167 $tmp = xl_list_label($lrow['title']);
1168 if ($lrow == 0 && !empty($backup_list)) {
1169 // since primary list did not map, try to map to backup list
1170 $lrow = sqlQuery("SELECT title FROM list_options " .
1171 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1172 $tmp = xl_list_label($lrow['title']);
1174 if (empty($tmp)) $tmp = "($currvalue)";
1176 /*****************************************************************
1177 echo "<input type='text'" .
1178 " size='$fld_length'" .
1182 *****************************************************************/
1187 $tmp = htmlspecialchars( $tmp, ENT_QUOTES
);
1192 // simple text field
1193 else if ($data_type == 2 ||
$data_type == 15) {
1194 /*****************************************************************
1195 echo "<input type='text'" .
1196 " size='$fld_length'" .
1197 " value='$currescaped'" .
1200 *****************************************************************/
1201 if ($currescaped === '') $currescaped = ' ';
1205 // long or multi-line text field
1206 else if ($data_type == 3) {
1207 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES
);
1208 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES
);
1210 " cols='$fldlength'" .
1211 " rows='$maxlength'>" .
1212 $currescaped . "</textarea>";
1216 else if ($data_type == 4) {
1217 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1218 $agestr = optionalAge($frow, $currvalue,$asof);
1220 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1222 if ($currvalue === '') {
1226 echo text(oeFormatShortDate($currvalue));
1228 // Optional display of age or gestational age.
1230 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1235 else if ($data_type == 10 ||
$data_type == 11) {
1238 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1239 "WHERE id = ?", array($currvalue) );
1240 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1241 if (empty($tmp)) $tmp = "($currvalue)";
1243 /*****************************************************************
1244 echo "<input type='text'" .
1245 " size='$fld_length'" .
1249 *****************************************************************/
1250 if ($tmp === '') { $tmp = ' '; }
1251 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1256 else if ($data_type == 12) {
1259 $pres = get_pharmacies();
1260 while ($prow = sqlFetchArray($pres)) {
1262 if ($currvalue == $key) {
1263 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1264 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1265 $prow['line1'] . ' / ' . $prow['city'];
1268 if (empty($tmp)) $tmp = "($currvalue)";
1270 /*****************************************************************
1271 echo "<input type='text'" .
1272 " size='$fld_length'" .
1276 *****************************************************************/
1277 if ($tmp === '') { $tmp = ' '; }
1278 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1283 else if ($data_type == 13) {
1286 $squads = acl_get_squads();
1288 foreach ($squads as $key => $value) {
1289 if ($currvalue == $key) {
1294 if (empty($tmp)) $tmp = "($currvalue)";
1296 /*****************************************************************
1297 echo "<input type='text'" .
1298 " size='$fld_length'" .
1302 *****************************************************************/
1303 if ($tmp === '') { $tmp = ' '; }
1304 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1309 else if ($data_type == 14) {
1312 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1313 "WHERE id = ?", array($currvalue) );
1314 $uname = $urow['lname'];
1315 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1317 if (empty($tmp)) $tmp = "($currvalue)";
1319 /*****************************************************************
1320 echo "<input type='text'" .
1321 " size='$fld_length'" .
1325 *****************************************************************/
1326 if ($tmp === '') { $tmp = ' '; }
1327 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
1331 // insurance company list
1332 else if ($data_type == 16) {
1335 $insprovs = getInsuranceProviders();
1336 foreach ($insprovs as $key => $ipname) {
1337 if ($currvalue == $key) {
1341 if (empty($tmp)) $tmp = "($currvalue)";
1343 if ($tmp === '') $tmp = ' ';
1344 else $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1349 else if ($data_type == 17) {
1352 foreach ($ISSUE_TYPES as $key => $value) {
1353 if ($currvalue == $key) {
1357 if (empty($tmp)) $tmp = "($currvalue)";
1359 if ($tmp === '') $tmp = ' ';
1360 else $tmp = htmlspecialchars($tmp, ENT_QUOTES
);
1364 // Visit categories.
1365 else if ($data_type == 18) {
1368 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1369 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1371 $tmp = xl_appt_category($crow['pc_catname']);
1372 if (empty($tmp)) $tmp = "($currvalue)";
1374 if ($tmp === '') { $tmp = ' '; }
1375 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES
); }
1379 // a set of labeled checkboxes
1380 else if ($data_type == 21) {
1381 // In this special case, fld_length is the number of columns generated.
1382 $cols = max(1, $fld_length);
1383 $avalue = explode('|', $currvalue);
1384 $lres = sqlStatement("SELECT * FROM list_options " .
1385 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1386 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1387 $tdpct = (int) (100 / $cols);
1388 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1389 $option_id = $lrow['option_id'];
1390 if ($count %
$cols == 0) {
1391 if ($count) echo "</tr>";
1394 echo "<td width='$tdpct%'>";
1395 echo "<input type='checkbox'";
1396 if (in_array($option_id, $avalue)) echo " checked";
1397 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
1402 if ($count > $cols) {
1403 // Add some space after multiple rows of checkboxes.
1404 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
1405 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1411 // a set of labeled text input fields
1412 else if ($data_type == 22) {
1413 $tmp = explode('|', $currvalue);
1415 foreach ($tmp as $value) {
1416 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1417 $avalue[$matches[1]] = $matches[2];
1420 $lres = sqlStatement("SELECT * FROM list_options " .
1421 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1422 echo "<table cellpadding='0' cellspacing='0'>";
1423 while ($lrow = sqlFetchArray($lres)) {
1424 $option_id = $lrow['option_id'];
1425 $fldlength = empty($fld_length) ?
20 : $fld_length;
1426 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1427 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1428 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
1429 echo "<td><input type='text'" .
1430 " size='$fldlength'" .
1431 " value='$inputValue'" .
1438 // a set of exam results; 3 radio buttons and a text field:
1439 else if ($data_type == 23) {
1440 $tmp = explode('|', $currvalue);
1442 foreach ($tmp as $value) {
1443 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1444 $avalue[$matches[1]] = $matches[2];
1447 $fldlength = empty($fld_length) ?
20 : $fld_length;
1448 $lres = sqlStatement("SELECT * FROM list_options " .
1449 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1450 echo "<table cellpadding='0' cellspacing='0'>";
1451 echo "<tr><td> </td><td class='bold'>" .
1452 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
1453 " </td><td class='bold'>" .
1454 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
1455 "<td class='bold'>" .
1456 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
1457 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
1458 while ($lrow = sqlFetchArray($lres)) {
1459 $option_id = $lrow['option_id'];
1460 $restype = substr($avalue[$option_id], 0, 1);
1461 $resnote = substr($avalue[$option_id], 2);
1462 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1463 for ($i = 0; $i < 3; ++
$i) {
1464 echo "<td><input type='radio'";
1465 if ($restype === "$i") echo " checked";
1468 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1469 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1470 echo "<td><input type='text'" .
1471 " size='$fldlength'" .
1472 " value='$resnote'" .
1473 " class='under' /></td>" .
1479 // the list of active allergies for the current patient
1480 // this is read-only!
1481 else if ($data_type == 24) {
1482 $query = "SELECT title, comments FROM lists WHERE " .
1483 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1485 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1487 while ($lrow = sqlFetchArray($lres)) {
1488 if ($count++
) echo "<br />";
1489 echo htmlspecialchars( $lrow['title'], ENT_QUOTES
);
1490 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES
);
1494 // a set of labeled checkboxes, each with a text field:
1495 else if ($data_type == 25) {
1496 $tmp = explode('|', $currvalue);
1498 foreach ($tmp as $value) {
1499 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1500 $avalue[$matches[1]] = $matches[2];
1503 $fldlength = empty($fld_length) ?
20 : $fld_length;
1504 $lres = sqlStatement("SELECT * FROM list_options " .
1505 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1506 echo "<table cellpadding='0' cellspacing='0'>";
1507 while ($lrow = sqlFetchArray($lres)) {
1508 $option_id = $lrow['option_id'];
1509 $restype = substr($avalue[$option_id], 0, 1);
1510 $resnote = substr($avalue[$option_id], 2);
1511 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1512 echo "<td><input type='checkbox'";
1513 if ($restype) echo " checked";
1514 echo " /> </td>";
1515 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1516 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1517 echo "<td><input type='text'" .
1518 " size='$fldlength'" .
1519 " value='$resnote'" .
1527 // a set of labeled radio buttons
1528 else if ($data_type == 27) {
1529 // In this special case, fld_length is the number of columns generated.
1530 $cols = max(1, $frow['fld_length']);
1531 $lres = sqlStatement("SELECT * FROM list_options " .
1532 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1533 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1534 $tdpct = (int) (100 / $cols);
1535 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1536 $option_id = $lrow['option_id'];
1537 if ($count %
$cols == 0) {
1538 if ($count) echo "</tr>";
1541 echo "<td width='$tdpct%'>";
1542 echo "<input type='radio'";
1543 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1544 (strlen($currvalue) > 0 && $option_id == $currvalue))
1548 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
1553 if ($count > $cols) {
1554 // Add some space after multiple rows of radio buttons.
1555 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
1556 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1562 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1563 else if ($data_type == 28 ||
$data_type == 32) {
1564 $tmp = explode('|', $currvalue);
1565 switch(count($tmp)) {
1584 $resdate = $restype = "";
1587 $restype = $resdate = $resnote = "";
1590 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1591 echo "<table cellpadding='0' cellspacing='0'>";
1593 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1594 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1595 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
1596 if($data_type == 28)
1598 echo "<td><input type='text'" .
1599 " size='$fldlength'" .
1601 " value='$resnote' /></td>";
1602 echo "<td class='bold'> ".
1603 " ".
1604 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1606 else if($data_type == 32)
1608 echo "<tr><td><input type='text'" .
1609 " size='$fldlength'" .
1611 " value='$resnote' /></td></tr>";
1613 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1614 echo "<td><input type='text'" .
1615 " size='$fldlength'" .
1617 " value='$smoking_status_title' /></td>";
1618 echo "<td class='bold'> ".htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1620 echo "<td><input type='radio'";
1621 if ($restype == "current".$field_id) echo " checked";
1622 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES
)." </td>";
1624 echo "<td><input type='radio'";
1625 if ($restype == "current".$field_id) echo " checked";
1626 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES
)." </td>";
1628 echo "<td><input type='text' size='6'" .
1629 " value='$resdate'" .
1633 echo "<td><input type='radio'";
1634 if ($restype == "current".$field_id) echo " checked";
1635 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES
)."</td>";
1637 echo "<td><input type='radio'";
1638 if ($restype == "not_applicable".$field_id) echo " checked";
1639 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES
)." </td>";
1644 // static text. read-only, of course.
1645 else if ($data_type == 31) {
1646 echo nl2br($frow['description']);
1649 else if($data_type == 34){
1650 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;'>";
1651 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1652 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1656 //facilities drop-down list
1657 else if ($data_type == 35) {
1658 if (empty($currvalue)){
1661 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1665 // Supports backup lists.
1666 else if ($data_type == 36) {
1667 if (empty($fld_length)) {
1668 if ($list_id == 'titles') {
1676 $values_array = explode("|", $currvalue);
1679 foreach($values_array as $value) {
1681 $lrow = sqlQuery("SELECT title FROM list_options " .
1682 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value));
1683 $tmp = xl_list_label($lrow['title']);
1684 if ($lrow == 0 && !empty($backup_list)) {
1685 // since primary list did not map, try to map to backup list
1686 $lrow = sqlQuery("SELECT title FROM list_options " .
1687 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue));
1688 $tmp = xl_list_label($lrow['title']);
1690 if (empty($tmp)) $tmp = "($value)";
1697 $tmp = htmlspecialchars( $tmp, ENT_QUOTES
);
1699 if ($i != 0 && $tmp != ' ') echo ",";
1705 // Image from canvas drawing
1706 else if ($data_type == 40) {
1707 echo "<img src='" . attr($currvalue) . "'>";
1712 function generate_display_field($frow, $currvalue) {
1713 global $ISSUE_TYPES;
1715 $data_type = $frow['data_type'];
1716 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
1717 $list_id = $frow['list_id'];
1718 $backup_list = isset($frow['list_backup_id']) ?
$frow['list_backup_id'] : null;
1722 // generic selection list or the generic selection list with add on the fly
1723 // feature, or radio buttons
1724 // Supports backup lists for datatypes 1,26,33
1725 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27 ||
$data_type == 33) {
1726 $lrow = sqlQuery("SELECT title FROM list_options " .
1727 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
1728 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1729 //if there is no matching value in the corresponding lists check backup list
1730 // only supported in data types 1,26,33
1731 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
1732 $lrow = sqlQuery("SELECT title FROM list_options " .
1733 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
1734 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1738 // simple text field
1739 else if ($data_type == 2) {
1740 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES
));
1743 // long or multi-line text field
1744 else if ($data_type == 3) {
1745 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES
));
1749 else if ($data_type == 4) {
1750 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1752 $agestr = optionalAge($frow, $currvalue, $asof);
1754 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1756 if ($currvalue === '') {
1760 $s .= text(oeFormatShortDate($currvalue));
1762 // Optional display of age or gestational age.
1764 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1769 else if ($data_type == 10 ||
$data_type == 11) {
1770 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1771 "WHERE id = ?", array($currvalue) );
1772 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES
);
1776 else if ($data_type == 12) {
1777 $pres = get_pharmacies();
1778 while ($prow = sqlFetchArray($pres)) {
1780 if ($currvalue == $key) {
1781 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1782 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1783 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES
);
1789 else if ($data_type == 13) {
1790 $squads = acl_get_squads();
1792 foreach ($squads as $key => $value) {
1793 if ($currvalue == $key) {
1794 $s .= htmlspecialchars($value[3],ENT_NOQUOTES
);
1801 else if ($data_type == 14) {
1802 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
1803 "WHERE id = ?", array($currvalue));
1804 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
1805 if($urow['organization'] !=""){
1806 $uname = $urow['organization'];
1808 $uname = $urow['lname'];
1809 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1811 $s = htmlspecialchars($uname,ENT_NOQUOTES
);
1815 else if ($data_type == 15) {
1816 $s = htmlspecialchars($currvalue,ENT_NOQUOTES
);
1819 // insurance company list
1820 else if ($data_type == 16) {
1821 $insprovs = getInsuranceProviders();
1822 foreach ($insprovs as $key => $ipname) {
1823 if ($currvalue == $key) {
1824 $s .= htmlspecialchars($ipname, ENT_NOQUOTES
);
1830 else if ($data_type == 17) {
1831 foreach ($ISSUE_TYPES as $key => $value) {
1832 if ($currvalue == $key) {
1833 $s .= htmlspecialchars($value[1], ENT_NOQUOTES
);
1839 else if ($data_type == 18) {
1840 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1841 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1843 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES
);
1846 // a set of labeled checkboxes
1847 else if ($data_type == 21) {
1848 $avalue = explode('|', $currvalue);
1849 $lres = sqlStatement("SELECT * FROM list_options " .
1850 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1852 while ($lrow = sqlFetchArray($lres)) {
1853 $option_id = $lrow['option_id'];
1854 if (in_array($option_id, $avalue)) {
1855 if ($count++
) $s .= "<br />";
1857 // Added 5-09 by BM - Translate label if applicable
1858 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES
);
1864 // a set of labeled text input fields
1865 else if ($data_type == 22) {
1866 $tmp = explode('|', $currvalue);
1868 foreach ($tmp as $value) {
1869 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1870 $avalue[$matches[1]] = $matches[2];
1873 $lres = sqlStatement("SELECT * FROM list_options " .
1874 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1875 $s .= "<table cellpadding='0' cellspacing='0'>";
1876 while ($lrow = sqlFetchArray($lres)) {
1877 $option_id = $lrow['option_id'];
1878 if (empty($avalue[$option_id])) continue;
1880 // Added 5-09 by BM - Translate label if applicable
1881 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . ": </td>";
1883 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES
) . "</td></tr>";
1888 // a set of exam results; 3 radio buttons and a text field:
1889 else if ($data_type == 23) {
1890 $tmp = explode('|', $currvalue);
1892 foreach ($tmp as $value) {
1893 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1894 $avalue[$matches[1]] = $matches[2];
1897 $lres = sqlStatement("SELECT * FROM list_options " .
1898 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1899 $s .= "<table cellpadding='0' cellspacing='0'>";
1900 while ($lrow = sqlFetchArray($lres)) {
1901 $option_id = $lrow['option_id'];
1902 $restype = substr($avalue[$option_id], 0, 1);
1903 $resnote = substr($avalue[$option_id], 2);
1904 if (empty($restype) && empty($resnote)) continue;
1906 // Added 5-09 by BM - Translate label if applicable
1907 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1909 $restype = ($restype == '1') ?
xl('Normal') : (($restype == '2') ?
xl('Abnormal') : xl('N/A'));
1910 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1911 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1912 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . " </td>";
1913 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td>";
1919 // the list of active allergies for the current patient
1920 else if ($data_type == 24) {
1921 $query = "SELECT title, comments FROM lists WHERE " .
1922 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1924 // echo "<!-- $query -->\n"; // debugging
1925 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1927 while ($lrow = sqlFetchArray($lres)) {
1928 if ($count++
) $s .= "<br />";
1929 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES
);
1930 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES
) . ')';
1934 // a set of labeled checkboxes, each with a text field:
1935 else if ($data_type == 25) {
1936 $tmp = explode('|', $currvalue);
1938 foreach ($tmp as $value) {
1939 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1940 $avalue[$matches[1]] = $matches[2];
1943 $lres = sqlStatement("SELECT * FROM list_options " .
1944 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
1945 $s .= "<table cellpadding='0' cellspacing='0'>";
1946 while ($lrow = sqlFetchArray($lres)) {
1947 $option_id = $lrow['option_id'];
1948 $restype = substr($avalue[$option_id], 0, 1);
1949 $resnote = substr($avalue[$option_id], 2);
1950 if (empty($restype) && empty($resnote)) continue;
1952 // Added 5-09 by BM - Translate label if applicable
1953 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1955 $restype = $restype ?
xl('Yes') : xl('No');
1956 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . "</td></tr>";
1957 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td></tr>";
1963 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1964 // VicarePlus :: A selection list for smoking status.
1965 else if ($data_type == 28 ||
$data_type == 32) {
1966 $tmp = explode('|', $currvalue);
1967 switch(count($tmp)) {
1986 $resdate = $restype = "";
1989 $restype = $resdate = $resnote = "";
1992 $s .= "<table cellpadding='0' cellspacing='0'>";
1996 if ($restype == "current".$field_id) $res = xl('Current');
1997 if ($restype == "quit".$field_id) $res = xl('Quit');
1998 if ($restype == "never".$field_id) $res = xl('Never');
1999 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
2000 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
2001 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
2002 if ($data_type == 28)
2004 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
2006 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
2007 else if ($data_type == 32)
2008 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
2009 $smoke_codes = getSmokeCodes();
2010 if (!empty($reslist)) {
2011 if($smoke_codes[$reslist]!="")
2012 $code_desc = "( ".$smoke_codes[$reslist]." )";
2014 $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . " ".text($code_desc)." </td>";}
2016 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
2019 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES
) . "</b>: " . htmlspecialchars($res,ENT_NOQUOTES
) . " </td>";
2020 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES
) . " </td>";
2025 // static text. read-only, of course.
2026 else if ($data_type == 31) {
2027 $s .= nl2br($frow['description']);
2030 else if($data_type == 34){
2031 $arr = explode("|*|*|*|",$currvalue);
2032 for($i=0;$i<sizeof($arr);$i++
){
2038 else if ($data_type == 35) {
2039 $urow = sqlQuery("SELECT id, name FROM facility ".
2040 "WHERE id = ?", array($currvalue) );
2041 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES
);
2045 // Supports backup lists
2046 else if ($data_type == 36) {
2047 $values_array = explode("|", $currvalue);
2049 foreach($values_array as $value) {
2050 $lrow = sqlQuery("SELECT title FROM list_options " .
2051 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2052 if ($lrow == 0 && !empty($backup_list)) {
2054 $lrow = sqlQuery("SELECT title FROM list_options " .
2055 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2058 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
2060 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
2066 // Image from canvas drawing
2067 else if ($data_type == 40) {
2068 $s .= "<img src='" . attr($currvalue) . "'>";
2074 // Generate plain text versions of selected LBF field types.
2075 // Currently used by interface/patient_file/download_template.php.
2076 // More field types might need to be supported here in the future.
2078 function generate_plaintext_field($frow, $currvalue) {
2079 global $ISSUE_TYPES;
2081 $data_type = $frow['data_type'];
2082 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
2083 $list_id = $frow['list_id'];
2084 $backup_list = $frow['backup_list'];
2087 // generic selection list or the generic selection list with add on the fly
2088 // feature, or radio buttons
2089 // Supports backup lists (for datatypes 1,26,33)
2090 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27 ||
$data_type == 33) {
2091 $lrow = sqlQuery("SELECT title FROM list_options " .
2092 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$currvalue) );
2093 $s = xl_list_label($lrow['title']);
2094 //if there is no matching value in the corresponding lists check backup list
2095 // only supported in data types 1,26,33
2096 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33)) {
2097 $lrow = sqlQuery("SELECT title FROM list_options " .
2098 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$currvalue) );
2099 $s = xl_list_label($lrow['title']);
2103 // simple or long text field
2104 else if ($data_type == 2 ||
$data_type == 3 ||
$data_type == 15) {
2109 else if ($data_type == 4) {
2110 $s = oeFormatShortDate($currvalue);
2111 // Optional display of age or gestational age.
2112 $asof=''; //not used here, but set to prevent a php warning when call optionalAge
2113 $tmp = optionalAge($frow, $currvalue,$asof);
2114 if ($tmp) $s .= ' ' . $tmp;
2118 else if ($data_type == 10 ||
$data_type == 11) {
2119 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2120 "WHERE id = ?", array($currvalue) );
2121 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2125 else if ($data_type == 12) {
2126 $pres = get_pharmacies();
2127 while ($prow = sqlFetchArray($pres)) {
2129 if ($currvalue == $key) {
2130 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2131 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2132 $prow['line1'] . ' / ' . $prow['city'];
2138 else if ($data_type == 14) {
2139 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2140 "WHERE id = ?", array($currvalue));
2141 $uname = $urow['lname'];
2142 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2146 // insurance company list
2147 else if ($data_type == 16) {
2148 $insprovs = getInsuranceProviders();
2149 foreach ($insprovs as $key => $ipname) {
2150 if ($currvalue == $key) {
2157 else if ($data_type == 17) {
2158 foreach ($ISSUE_TYPES as $key => $value) {
2159 if ($currvalue == $key) {
2166 else if ($data_type == 18) {
2167 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2168 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2170 $s = $crow['pc_catname'];
2173 // a set of labeled checkboxes
2174 else if ($data_type == 21) {
2175 $avalue = explode('|', $currvalue);
2176 $lres = sqlStatement("SELECT * FROM list_options " .
2177 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2179 while ($lrow = sqlFetchArray($lres)) {
2180 $option_id = $lrow['option_id'];
2181 if (in_array($option_id, $avalue)) {
2182 if ($count++
) $s .= "; ";
2183 $s .= xl_list_label($lrow['title']);
2188 // a set of labeled text input fields
2189 else if ($data_type == 22) {
2190 $tmp = explode('|', $currvalue);
2192 foreach ($tmp as $value) {
2193 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2194 $avalue[$matches[1]] = $matches[2];
2197 $lres = sqlStatement("SELECT * FROM list_options " .
2198 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2199 while ($lrow = sqlFetchArray($lres)) {
2200 $option_id = $lrow['option_id'];
2201 if (empty($avalue[$option_id])) continue;
2202 if ($s !== '') $s .= '; ';
2203 $s .= xl_list_label($lrow['title']) . ': ';
2204 $s .= $avalue[$option_id];
2208 // A set of exam results; 3 radio buttons and a text field.
2209 // This shows abnormal results only.
2210 else if ($data_type == 23) {
2211 $tmp = explode('|', $currvalue);
2213 foreach ($tmp as $value) {
2214 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2215 $avalue[$matches[1]] = $matches[2];
2218 $lres = sqlStatement("SELECT * FROM list_options " .
2219 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
2220 while ($lrow = sqlFetchArray($lres)) {
2221 $option_id = $lrow['option_id'];
2222 $restype = substr($avalue[$option_id], 0, 1);
2223 $resnote = substr($avalue[$option_id], 2);
2224 if (empty($restype) && empty($resnote)) continue;
2225 if ($restype != '2') continue; // show abnormal results only
2226 if ($s !== '') $s .= '; ';
2227 $s .= xl_list_label($lrow['title']);
2228 if (!empty($resnote)) $s .= ': ' . $resnote;
2232 // the list of active allergies for the current patient
2233 else if ($data_type == 24) {
2234 $query = "SELECT title, comments FROM lists WHERE " .
2235 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2237 $lres = sqlStatement($query, array($GLOBALS['pid']));
2239 while ($lrow = sqlFetchArray($lres)) {
2240 if ($count++
) $s .= "; ";
2241 $s .= $lrow['title'];
2242 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2246 // a set of labeled checkboxes, each with a text field:
2247 else if ($data_type == 25) {
2248 $tmp = explode('|', $currvalue);
2250 foreach ($tmp as $value) {
2251 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2252 $avalue[$matches[1]] = $matches[2];
2255 $lres = sqlStatement("SELECT * FROM list_options " .
2256 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
2257 while ($lrow = sqlFetchArray($lres)) {
2258 $option_id = $lrow['option_id'];
2259 $restype = substr($avalue[$option_id], 0, 1);
2260 $resnote = substr($avalue[$option_id], 2);
2261 if (empty($restype) && empty($resnote)) continue;
2262 if ($s !== '') $s .= '; ';
2263 $s .= xl_list_label($lrow['title']);
2264 $restype = $restype ?
xl('Yes') : xl('No');
2266 if ($resnote) $s .= ' ' . $resnote;
2270 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2271 // VicarePlus :: A selection list for smoking status.
2272 else if ($data_type == 28 ||
$data_type == 32) {
2273 $tmp = explode('|', $currvalue);
2274 $resnote = count($tmp) > 0 ?
$tmp[0] : '';
2275 $restype = count($tmp) > 1 ?
$tmp[1] : '';
2276 $resdate = count($tmp) > 2 ?
$tmp[2] : '';
2277 $reslist = count($tmp) > 3 ?
$tmp[3] : '';
2279 if ($restype == "current" . $field_id) $res = xl('Current');
2280 if ($restype == "quit" . $field_id) $res = xl('Quit');
2281 if ($restype == "never" . $field_id) $res = xl('Never');
2282 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2284 if ($data_type == 28) {
2285 if (!empty($resnote)) $s .= $resnote;
2287 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2288 else if ($data_type == 32) {
2289 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2290 if (!empty($resnote)) $s .= ' ' . $resnote;
2293 if ($s !== '') $s .= ' ';
2294 $s .= xl('Status') . ' ' . $res;
2296 if ($restype == "quit".$field_id) {
2297 if ($s !== '') $s .= ' ';
2303 // Supports backup lists
2304 else if ($data_type == 36) {
2305 $values_array = explode("|", $currvalue);
2308 foreach($values_array as $value) {
2309 $lrow = sqlQuery("SELECT title FROM list_options " .
2310 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($list_id,$value) );
2312 if ($lrow == 0 && !empty($backup_list)) {
2314 $lrow = sqlQuery("SELECT title FROM list_options " .
2315 "WHERE list_id = ? AND option_id = ? AND activity = 1", array($backup_list,$value) );
2319 $s = $s . ", " . xl_list_label($lrow['title']);
2321 $s = xl_list_label($lrow['title']);
2331 $CPR = 4; // cells per row of generic data
2336 function disp_end_cell() {
2337 global $item_count, $cell_count;
2338 if ($item_count > 0) {
2344 function disp_end_row() {
2345 global $cell_count, $CPR;
2347 if ($cell_count > 0) {
2348 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
2354 function disp_end_group() {
2356 if (strlen($last_group) > 0) {
2361 function display_layout_rows($formtype, $result1, $result2='') {
2362 global $item_count, $cell_count, $last_group, $CPR;
2364 $fres = sqlStatement("SELECT * FROM layout_options " .
2365 "WHERE form_id = ? AND uor > 0 " .
2366 "ORDER BY group_name, seq", array($formtype) );
2368 while ($frow = sqlFetchArray($fres)) {
2369 $this_group = $frow['group_name'];
2370 $titlecols = $frow['titlecols'];
2371 $datacols = $frow['datacols'];
2372 $data_type = $frow['data_type'];
2373 $field_id = $frow['field_id'];
2374 $list_id = $frow['list_id'];
2377 if ($formtype == 'DEM') {
2378 if (strpos($field_id, 'em_') === 0) {
2379 // Skip employer related fields, if it's disabled.
2380 if ($GLOBALS['omit_employers']) continue;
2381 $tmp = substr($field_id, 3);
2382 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2385 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2389 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2392 // Handle a data category (group) change.
2393 if (strcmp($this_group, $last_group) != 0) {
2394 $group_name = substr($this_group, 1);
2395 // totally skip generating the employer category, if it's disabled.
2396 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2398 $last_group = $this_group;
2401 // filter out all the empty field data from the patient report.
2402 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2403 // Handle starting of a new row.
2404 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
2408 echo "<td class='groupname'>";
2409 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2410 //echo "<font color='#008800'>$group_name</font>";
2412 // Added 5-09 by BM - Translate label if applicable
2413 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
);
2417 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2418 echo "<td valign='top'> ";
2423 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2425 // Handle starting of a new label cell.
2426 if ($titlecols > 0) {
2428 //echo "<td class='label' colspan='$titlecols' valign='top'";
2429 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
2430 echo "<td class='label' colspan='$titlecols_esc' ";
2431 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2433 $cell_count +
= $titlecols;
2437 // Added 5-09 by BM - Translate label if applicable
2438 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES
); else echo " ";
2440 // Handle starting of a new data cell.
2441 if ($datacols > 0) {
2443 //echo "<td class='text data' colspan='$datacols' valign='top'";
2444 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
2445 echo "<td class='text data' colspan='$datacols_esc'";
2446 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2448 $cell_count +
= $datacols;
2452 echo generate_display_field($frow, $currvalue);
2459 function display_layout_tabs($formtype, $result1, $result2='') {
2460 global $item_count, $cell_count, $last_group, $CPR;
2462 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2463 "WHERE form_id = ? AND uor > 0 " .
2464 "ORDER BY group_name, seq", array($formtype) );
2467 while ($frow = sqlFetchArray($fres)) {
2468 $this_group = $frow['group_name'];
2469 $group_name = substr($this_group, 1);
2470 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2472 <li
<?php
echo $first ?
'class="current"' : '' ?
>>
2473 <a href
="#" id
="header_tab_<?php echo str_replace(" ", "_
",htmlspecialchars($group_name,ENT_QUOTES))?>">
2474 <?php
echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
); ?
></a
>
2481 function display_layout_tabs_data($formtype, $result1, $result2='') {
2482 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2484 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2485 "WHERE form_id = ? AND uor > 0 " .
2486 "ORDER BY group_name, seq", array($formtype));
2489 while ($frow = sqlFetchArray($fres)) {
2490 $this_group = isset($frow['group_name']) ?
$frow['group_name'] : "" ;
2491 $titlecols = isset($frow['titlecols']) ?
$frow['titlecols'] : "";
2492 $datacols = isset($frow['datacols']) ?
$frow['datacols'] : "";
2493 $data_type = isset($frow['data_type']) ?
$frow['data_type'] : "";
2494 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : "";
2495 $list_id = isset($frow['list_id']) ?
$frow['list_id'] : "";
2498 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2500 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2501 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2502 "ORDER BY seq", array($formtype, $this_group) );
2505 <div
class="tab <?php echo $first ? 'current' : '' ?>">
2506 <table border
='0' cellpadding
='0'>
2509 while ($group_fields = sqlFetchArray($group_fields_query)) {
2511 $titlecols = $group_fields['titlecols'];
2512 $datacols = $group_fields['datacols'];
2513 $data_type = $group_fields['data_type'];
2514 $field_id = $group_fields['field_id'];
2515 $list_id = $group_fields['list_id'];
2517 $condition_str = get_conditions_str($condition_str,$group_fields);
2520 if ($formtype == 'DEM') {
2521 if (strpos($field_id, 'em_') === 0) {
2522 // Skip employer related fields, if it's disabled.
2523 if ($GLOBALS['omit_employers']) continue;
2524 $tmp = substr($field_id, 3);
2525 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2528 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2532 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2535 // Handle a data category (group) change.
2536 if (strcmp($this_group, $last_group) != 0) {
2537 $group_name = substr($this_group, 1);
2538 // totally skip generating the employer category, if it's disabled.
2539 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2540 $last_group = $this_group;
2543 // Handle starting of a new row.
2544 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
2549 if ($item_count == 0 && $titlecols == 0) {
2553 // Handle starting of a new label cell.
2554 if ($titlecols > 0) {
2556 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
2557 $field_id_label = 'label_'.$group_fields['field_id'];
2558 echo "<td class='label' colspan='$titlecols_esc' id='" . attr($field_id_label) . "'";
2560 $cell_count +
= $titlecols;
2564 $field_id_label = 'label_'.$group_fields['field_id'];
2565 echo "<span id='".attr($field_id_label)."'>";
2566 // Added 5-09 by BM - Translate label if applicable
2567 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES
); else echo " ";
2570 // Handle starting of a new data cell.
2571 if ($datacols > 0) {
2573 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
2574 $field_id = 'text_'.$group_fields['field_id'];
2575 echo "<td class='text data' colspan='$datacols_esc' id='" . attr($field_id) . "' data-value='" . attr($currvalue) . "'";
2577 $cell_count +
= $datacols;
2579 $field_id = 'text_'.$group_fields['field_id'];
2580 echo "<span id='".attr($field_id)."' style='display:none'>" . text($currvalue) . "</span>";
2584 echo generate_display_field($group_fields, $currvalue);
2601 function get_conditions_str($condition_str,$frow){
2602 $conditions = empty($frow['conditions']) ?
array() : unserialize($frow['conditions']);
2603 foreach ($conditions as $condition) {
2604 if (empty($condition['id'])) continue;
2605 $andor = empty($condition['andor']) ?
'' : $condition['andor'];
2606 if ($condition_str) $condition_str .= ",\n";
2607 $condition_str .= "{" .
2608 "target:'" . addslashes($frow['field_id']) . "', " .
2609 "id:'" . addslashes($condition['id']) . "', " .
2610 "itemid:'" . addslashes($condition['itemid']) . "', " .
2611 "operator:'" . addslashes($condition['operator']) . "', " .
2612 "value:'" . addslashes($condition['value']) . "', " .
2613 "andor:'" . addslashes($andor) . "'}";
2615 return $condition_str;
2617 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2618 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2620 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2621 "WHERE form_id = ? AND uor > 0 " .
2622 "ORDER BY group_name, seq", array($formtype) );
2625 while ($frow = sqlFetchArray($fres)) {
2626 $this_group = $frow['group_name'];
2627 $group_name = substr($this_group, 1);
2628 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES
);
2629 $titlecols = $frow['titlecols'];
2630 $datacols = $frow['datacols'];
2631 $data_type = $frow['data_type'];
2632 $field_id = $frow['field_id'];
2633 $list_id = $frow['list_id'];
2636 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2638 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2639 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2640 "ORDER BY seq", array($formtype,$this_group) );
2643 <div
class="tab <?php echo $first ? 'current' : '' ?>" id
="tab_<?php echo str_replace(' ', '_',$group_name_esc)?>" >
2644 <table border
='0' cellpadding
='0'>
2647 while ($group_fields = sqlFetchArray($group_fields_query)) {
2649 $titlecols = $group_fields['titlecols'];
2650 $datacols = $group_fields['datacols'];
2651 $data_type = $group_fields['data_type'];
2652 $field_id = $group_fields['field_id'];
2653 $list_id = $group_fields['list_id'];
2654 $backup_list = $group_fields['list_backup_id'];
2655 $condition_str = get_conditions_str($condition_str,$group_fields);
2658 if ($formtype == 'DEM') {
2659 if (strpos($field_id, 'em_') === 0) {
2660 // Skip employer related fields, if it's disabled.
2661 if ($GLOBALS['omit_employers']) continue;
2662 $tmp = substr($field_id, 3);
2663 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2666 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2670 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2673 // Handle a data category (group) change.
2674 if (strcmp($this_group, $last_group) != 0) {
2675 $group_name = substr($this_group, 1);
2676 // totally skip generating the employer category, if it's disabled.
2677 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2678 $last_group = $this_group;
2681 // Handle starting of a new row.
2682 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
2687 if ($item_count == 0 && $titlecols == 0) {
2691 // Handle starting of a new label cell.
2692 if ($titlecols > 0) {
2694 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
2695 $field_id_label = 'label_'.$group_fields['field_id'];
2696 echo "<td class='label' colspan='$titlecols_esc' id='$field_id_label' ";
2698 $cell_count +
= $titlecols;
2702 // Added 5-09 by BM - Translate label if applicable
2703 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES
).":"); else echo " ";
2705 // Handle starting of a new data cell.
2706 if ($datacols > 0) {
2708 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
2709 $field_id = 'text_'.$group_fields['field_id'];
2710 echo "<td class='text data' colspan='$datacols_esc' id='$field_id'";
2712 $cell_count +
= $datacols;
2717 echo generate_form_field($group_fields, $currvalue);
2731 // From the currently posted HTML form, this gets the value of the
2732 // field corresponding to the provided layout_options table row.
2734 function get_layout_form_value($frow, $prefix='form_') {
2735 // Bring in $sanitize_all_escapes variable, which will decide
2736 // the variable escaping method.
2737 global $sanitize_all_escapes;
2739 $maxlength = empty($frow['max_length']) ?
0 : intval($frow['max_length']);
2740 $data_type = $frow['data_type'];
2741 $field_id = $frow['field_id'];
2743 if (isset($_POST["$prefix$field_id"])) {
2744 if ($data_type == 21) {
2745 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2746 // must be concatenated into a |-separated string.
2747 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2748 if (strlen($value)) $value .= '|';
2752 else if ($data_type == 22) {
2753 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2754 // into "key:value|key:value|...".
2755 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2756 $val = str_replace('|', ' ', $val);
2757 if (strlen($value)) $value .= '|';
2758 $value .= "$key:$val";
2761 else if ($data_type == 23) {
2762 // $_POST["$prefix$field_id"] is an array of text fields with companion
2763 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2764 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2765 $restype = $_POST["radio_{$field_id}"][$key];
2766 if (empty($restype)) $restype = '0';
2767 $val = str_replace('|', ' ', $val);
2768 if (strlen($value)) $value .= '|';
2769 $value .= "$key:$restype:$val";
2772 else if ($data_type == 25) {
2773 // $_POST["$prefix$field_id"] is an array of text fields with companion
2774 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2775 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2776 $restype = empty($_POST["check_{$field_id}"][$key]) ?
'0' : '1';
2777 $val = str_replace('|', ' ', $val);
2778 if (strlen($value)) $value .= '|';
2779 $value .= "$key:$restype:$val";
2782 else if ($data_type == 28 ||
$data_type == 32) {
2783 // $_POST["$prefix$field_id"] is an date text fields with companion
2784 // radio buttons to be imploded into "notes|type|date".
2785 $restype = $_POST["radio_{$field_id}"];
2786 if (empty($restype)) $restype = '0';
2787 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2788 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2789 if ($data_type == 32)
2791 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2792 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2793 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2794 $value = "$res_text_note|$restype|$resdate|$reslist";
2797 $value = "$resnote|$restype|$resdate";
2799 else if ($data_type == 36) {
2800 $value_array = $_POST["form_$field_id"];
2802 foreach ($value_array as $key => $valueofkey) {
2804 $value = $valueofkey;
2806 $value = $value . "|" . $valueofkey;
2812 $value = $_POST["$prefix$field_id"];
2816 // Better to die than to silently truncate data!
2817 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2818 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES
) .
2819 ":<br /> <br />".htmlspecialchars( $value, ENT_NOQUOTES
));
2821 // Make sure the return value is quote-safe.
2822 if ($sanitize_all_escapes) {
2823 //escapes already removed and using binding/placemarks in sql calls
2824 // so only need to trim value
2825 return trim($value);
2828 //need to explicitly prepare value
2829 return formTrim($value);
2833 // Generate JavaScript validation logic for the required fields.
2835 function generate_layout_validation($form_id) {
2836 $fres = sqlStatement("SELECT * FROM layout_options " .
2837 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2838 "ORDER BY group_name, seq", array($form_id) );
2840 while ($frow = sqlFetchArray($fres)) {
2841 $data_type = $frow['data_type'];
2842 $field_id = $frow['field_id'];
2843 $fldtitle = $frow['title'];
2844 if (!$fldtitle) $fldtitle = $frow['description'];
2845 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES
);
2847 if ($data_type == 40) {
2848 $fldid = addslashes("form_$field_id");
2849 // Move canvas image data to its hidden form field so the server will get it.
2851 " var canfld = f['$fldid'];\n" .
2852 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
2856 if ($frow['uor'] < 2) continue;
2858 switch($data_type) {
2867 " if (f.$fldname.selectedIndex <= 0) {\n" .
2868 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2869 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2872 case 27: // radio buttons
2875 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2876 " if (i >= f.$fldname.length) {\n" .
2877 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2885 " if (trimlen(f.$fldname.value) == 0) {\n" .
2886 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2887 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2888 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2889 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2891 " $('#" . $fldname . "').attr('style',''); " .
2892 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2895 case 36: // multi select
2897 " var multi_select=f['$fldname"."[]']; \n " .
2898 " var multi_choice_made=false; \n".
2899 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
2900 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
2902 " if(!multi_choice_made)
2903 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2911 * DROPDOWN FOR FACILITIES
2913 * build a dropdown with all facilities
2915 * @param string $selected - name of the currently selected facility
2916 * use '0' for "unspecified facility"
2917 * use '' for "All facilities" (the default)
2918 * @param string $name - the name/id for select form (defaults to "form_facility")
2919 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2921 * @return void - just echo the html encoded string
2923 * Note: This should become a data-type at some point, according to Brady
2925 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2926 $allow_allfacilities = true, $disabled='', $onchange='')
2928 $have_selected = false;
2929 $query = "SELECT id, name FROM facility ORDER BY name";
2930 $fres = sqlStatement($query);
2932 $name = htmlspecialchars($name, ENT_QUOTES
);
2933 echo " <select name='$name' id='$name'";
2934 if ($onchange) echo " onchange='$onchange'";
2935 echo " $disabled>\n";
2937 if ($allow_allfacilities) {
2939 $option_selected_attr = '';
2940 if ($selected == '') {
2941 $option_selected_attr = ' selected="selected"';
2942 $have_selected = true;
2944 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES
);
2945 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2946 } elseif ($allow_unspecified) {
2947 $option_value = '0';
2948 $option_selected_attr = '';
2949 if ( $selected == '0' ) {
2950 $option_selected_attr = ' selected="selected"';
2951 $have_selected = true;
2953 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
2954 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2957 while ($frow = sqlFetchArray($fres)) {
2958 $facility_id = $frow['id'];
2959 $option_value = htmlspecialchars($facility_id, ENT_QUOTES
);
2960 $option_selected_attr = '';
2961 if ($selected == $facility_id) {
2962 $option_selected_attr = ' selected="selected"';
2963 $have_selected = true;
2965 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES
);
2966 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2969 if ($allow_unspecified && $allow_allfacilities) {
2970 $option_value = '0';
2971 $option_selected_attr = '';
2972 if ( $selected == '0' ) {
2973 $option_selected_attr = ' selected="selected"';
2974 $have_selected = true;
2976 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
2977 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2980 if (!$have_selected) {
2981 $option_value = htmlspecialchars($selected, ENT_QUOTES
);
2982 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES
);
2983 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES
);
2984 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2986 echo " </select>\n";
2989 // Expand Collapse Widget
2990 // This forms the header and functionality component of the widget. The information that is displayed
2991 // then follows this function followed by a closing div tag
2993 // $title is the title of the section (already translated)
2994 // $label is identifier used in the tag id's and sql columns
2995 // $buttonLabel is the button label text (already translated)
2996 // $buttonLink is the button link information
2997 // $buttonClass is any additional needed class elements for the button tag
2998 // $linkMethod is the button link method ('javascript' vs 'html')
2999 // $bodyClass is to set class(es) of the body
3000 // $auth is a flag to decide whether to show the button
3001 // $fixedWidth is to flag whether width is fixed
3002 // $forceExpandAlways is a flag to force the widget to always be expanded
3004 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
3006 echo "<div class='section-header'>";
3009 echo "<div class='section-header-dynamic'>";
3013 // show button, since authorized
3014 // first prepare class string
3016 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES
);
3019 $class_string = "css_button_small";
3021 // next, create the link
3022 if ($linkMethod == "javascript") {
3023 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
3026 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
3027 if (!isset($_SESSION['patient_portal_onsite'])) {
3028 // prevent an error from occuring when calling the function from the patient portal
3029 echo " onclick='top.restoreSession()'";
3033 htmlspecialchars( $buttonLabel, ENT_NOQUOTES
) . "</span></a></td>";
3035 if ($forceExpandAlways){
3036 // Special case to force the widget to always be expanded
3037 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES
) . "</b></span>";
3038 $indicatorTag ="style='display:none'";
3040 $indicatorTag = isset($indicatorTag) ?
$indicatorTag : "";
3041 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3042 htmlspecialchars( $label, ENT_QUOTES
) . "_ps_expand\")'><span class='text'><b>";
3043 echo htmlspecialchars( $title, ENT_NOQUOTES
) . "</b></span>";
3045 if (isset($_SESSION['patient_portal_onsite'])) {
3046 // collapse all entries in the patient portal
3047 $text = xl('expand');
3049 else if (getUserSetting($label."_ps_expand")) {
3050 $text = xl('collapse');
3053 $text = xl('expand');
3055 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES
) .
3056 "</span>)</a></td>";
3057 echo "</tr></table>";
3059 if ($forceExpandAlways) {
3060 // Special case to force the widget to always be expanded
3063 else if (isset($_SESSION['patient_portal_onsite'])) {
3064 // collapse all entries in the patient portal
3065 $styling = "style='display:none'";
3067 else if (getUserSetting($label."_ps_expand")) {
3071 $styling = "style='display:none'";
3074 $styling .= " class='" . $bodyClass . "'";
3076 //next, create the first div tag to hold the information
3077 // note the code that calls this function will then place the ending div tag after the data
3078 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES
) . "_ps_expand' " . $styling . ">";
3081 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3082 function billing_facility($name,$select){
3083 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
3084 echo " <select id='".htmlspecialchars($name, ENT_QUOTES
)."' name='".htmlspecialchars($name, ENT_QUOTES
)."'>";
3085 while ($facrow = sqlFetchArray($qsql)) {
3086 $selected = ( $facrow['id'] == $select ) ?
'selected="selected"' : '' ;
3087 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES
)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES
)."</option>";
3092 // Generic function to get the translated title value for a particular list option.
3094 function getListItemTitle($list, $option) {
3095 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3096 "list_id = ? AND option_id = ? AND activity = 1", array($list, $option));
3097 if (empty($row['title'])) return $option;
3098 return xl_list_label($row['title']);
3100 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3101 function getSmokeCodes()
3103 $smoking_codes_arr = array();
3104 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status' AND activity = 1");
3105 while($codes_row = sqlFetchArray($smoking_codes))
3107 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3109 return $smoking_codes_arr;
3112 // Get the current value for a layout based form field.
3113 // Depending on options this might come from lbf_data, patient_data,
3114 // form_encounter, shared_attributes or elsewhere.
3115 // Returns FALSE if the field ID is invalid (layout error).
3117 function lbf_current_value($frow, $formid, $encounter) {
3119 $formname = $frow['form_id'];
3120 $field_id = $frow['field_id'];
3121 $source = $frow['source'];
3123 $deffname = $formname . '_default_' . $field_id;
3124 if ($source == 'D' ||
$source == 'H') {
3125 // Get from patient_data, employer_data or history_data.
3126 if ($source == 'H') {
3127 $table = 'history_data';
3128 $orderby = 'ORDER BY date DESC LIMIT 1';
3130 else if (strpos($field_id, 'em_') === 0) {
3131 $field_id = substr($field_id, 3);
3132 $table = 'employer_data';
3133 $orderby = 'ORDER BY date DESC LIMIT 1';
3136 $table = 'patient_data';
3139 // It is an error if the field does not exist, but don't crash.
3140 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3141 if (empty($tmp)) return FALSE;
3142 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3143 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3145 else if ($source == 'E') {
3147 // Get value from shared_attributes of the current encounter.
3148 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3149 "pid = ? AND encounter = ? AND field_id = ?",
3150 array($pid, $encounter, $field_id));
3151 if (isset($sarow)) $currvalue = $sarow['field_value'];
3154 // Get from shared_attributes of the encounter that this form is linked to.
3155 // Note the importance of having an index on forms.form_id.
3156 $sarow = sqlQuery("SELECT sa.field_value " .
3157 "FROM forms AS f, shared_attributes AS sa WHERE " .
3158 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3159 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3160 array($formid, $formname, $field_id));
3161 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3164 // New form and encounter not available, this should not happen.
3167 else if ($source == 'V') {
3169 // Get value from the current encounter's form_encounter.
3170 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3171 "pid = ? AND encounter = ?",
3172 array($pid, $encounter));
3173 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3176 // Get value from the form_encounter that this form is linked to.
3177 $ferow = sqlQuery("SELECT fe.* " .
3178 "FROM forms AS f, form_encounter AS fe WHERE " .
3179 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3180 "fe.pid = f.pid AND fe.encounter = f.encounter",
3181 array($formid, $formname));
3182 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3185 // New form and encounter not available, this should not happen.
3189 // This is a normal form field.
3190 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3191 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3192 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3195 // New form, see if there is a custom default from a plugin.
3196 // This logic does not apply to shared attributes because they do not
3197 // have a "new form" concept.
3198 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3203 // This returns stuff that needs to go into the <head> section of a caller using
3204 // the drawable image field type in a form.
3205 // A TRUE argument makes the widget 25% less tall.
3207 function lbf_canvas_head($small=FALSE) {
3209 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3210 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3211 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3212 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3214 if ($small) $s .= <<<EOD
3216 /* Custom LiterallyCanvas styling.
3217 * This makes the widget 25% less tall and adjusts some other things accordingly.
3220 min-height:292px;min-width:300px; /* Was 400, unspecified */
3222 .literally .lc-picker .toolbar-button {
3223 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3225 .literally .color-well {
3226 font-size:8px;width:49px; /* Was 10, 60 */
3228 .literally .color-well-color-container {
3229 width:21px;height:21px; /* Was 28, 28 */
3231 .literally .lc-picker {
3232 width:50px; /* Was 61 */
3234 .literally .lc-drawing.with-gui {
3235 left:50px; /* Was 61 */
3237 .literally .lc-options {
3238 left:50px; /* Was 61 */
3240 .literally .color-picker-popup {
3241 left:49px;bottom:0px; /* Was 60, 31 */