2017 icd10 external data load files
[openemr.git] / library / options.inc.php
blobd8276f37dc5c0a9cdc3e6a1fa78f7856a917310f
1 <?php
2 // Copyright (C) 2007-2014 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 // Documentation for layout_options.edit_options:
21 // A = Age as years or "xx month(s)"
22 // B = Gestational age as "xx week(s) y day(s)"
23 // C = Capitalize first letter of each word (text fields)
24 // D = Check for duplicates in New Patient form
25 // G = Graphable (for numeric fields in forms supporting historical data)
26 // H = Read-only field copied from static history (this is obsolete)
27 // L = Lab Order ("ord_lab") types only (address book)
28 // N = Show in New Patient form
29 // O = Procedure Order ("ord_*") types only (address book)
30 // P = Default to previous value when current value is not yet set
31 // R = Distributor types only (address book)
32 // T = Use description as default Text
33 // U = Capitalize all letters (text fields)
34 // V = Vendor types only (address book)
35 // 0 = Read Only - the input element's "disabled" property is set
36 // 1 = Write Once (not editable when not empty) (text fields)
37 // 2 = Show descriptions instead of codes for billing code input
39 require_once("formdata.inc.php");
40 require_once("formatting.inc.php");
41 require_once("user.inc");
42 require_once("patient.inc");
43 require_once("lists.inc");
44 require_once(dirname(dirname(__FILE__)) . "/custom/code_types.inc.php");
46 $date_init = "";
48 function get_pharmacies() {
49 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
50 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
51 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
52 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
53 "AND p.type = 2 " .
54 "ORDER BY name, area_code, prefix, number");
57 function optionalAge($frow, $date, &$asof) {
58 $asof = '';
59 if (empty($date)) return '';
60 $date = substr($date, 0, 10);
61 if (strpos($frow['edit_options'], 'A') !== FALSE) {
62 $format = 0;
64 else if (strpos($frow['edit_options'], 'B') !== FALSE) {
65 $format = 3;
67 else {
68 return '';
70 if (strpos($frow['form_id'], 'LBF') === 0) {
71 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
72 "pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
73 array($GLOBALS['pid'], $GLOBALS['encounter']));
74 if (!empty($tmp['date'])) $asof = substr($tmp['date'], 0, 10);
76 $prefix = ($format ? xl('Gest age') : xl('Age')) . ' ';
77 return $prefix . oeFormatAge($date, $asof, $format);
80 // Function to generate a drop-list.
82 function generate_select_list($tag_name, $list_id, $currvalue, $title, $empty_name = ' ', $class = '',
83 $onchange = '', $tag_id = '', $custom_attributes = null, $multiple = false, $backup_list = '') {
84 $s = '';
86 $tag_name_esc = attr($tag_name);
88 if ($multiple) {
89 $tag_name_esc = $tag_name_esc . "[]";
92 $s .= "<select name='$tag_name_esc'";
94 if ($multiple) {
95 $s .= " multiple='multiple'";
98 $tag_id_esc = attr( $tag_name );
100 if ($tag_id != '') {
101 $tag_id_esc = attr($tag_id);
104 $s .= " id='$tag_id_esc'";
106 if ($class) {
107 $class_esc = attr($class);
108 $s .= " class='$class_esc'";
110 if ($onchange) {
111 $s .= " onchange='$onchange'";
113 if ($custom_attributes != null && is_array ( $custom_attributes )) {
114 foreach ( $custom_attributes as $attr => $val ) {
115 if (isset ( $custom_attributes [$attr] )) {
116 $s .= " " . attr($attr) . "='" . attr($val) . "'";
120 $selectTitle = attr($title);
121 $s .= " title='$selectTitle'>";
122 $selectEmptyName = xlt($empty_name);
123 if ($empty_name)
124 $s .= "<option value=''>" . $selectEmptyName . "</option>";
125 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY seq, title", array($list_id));
126 $got_selected = FALSE;
128 while ( $lrow = sqlFetchArray ( $lres ) ) {
129 $selectedValues = explode ( "|", $currvalue );
131 $optionValue = attr($lrow ['option_id']);
132 $s .= "<option value='$optionValue'";
134 if ($multiple && (strlen ( $currvalue ) == 0 && $lrow ['is_default']) || (strlen ( $currvalue ) > 0 && in_array ( $lrow ['option_id'], $selectedValues ))) {
135 $s .= " selected";
136 $got_selected = TRUE;
139 $optionLabel = text(xl_list_label($lrow ['title']));
140 $s .= ">$optionLabel</option>\n";
144 To show the inactive item in the list if the value is saved to database
146 if (!$got_selected && strlen($currvalue) > 0)
148 $lres_inactive = sqlStatement("SELECT * FROM list_options " .
149 "WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
150 $lrow_inactive = sqlFetchArray($lres_inactive);
151 if($lrow_inactive['option_id']) {
152 $optionValue = htmlspecialchars( $lrow_inactive['option_id'], ENT_QUOTES);
153 $s .= "<option value='$optionValue' selected>" . htmlspecialchars( xl_list_label($lrow_inactive['title']), ENT_NOQUOTES) . "</option>\n";
154 $got_selected = TRUE;
158 if (!$got_selected && strlen ( $currvalue ) > 0 && !$multiple) {
159 $list_id = $backup_list;
160 $lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
162 if ($lrow > 0 && !empty($backup_list)) {
163 $selected = text(xl_list_label($lrow ['title']));
164 $s .= "<option value='$currescaped' selected> $selected </option>";
165 $s .= "</select>";
166 } else {
167 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
168 $s .= "</select>";
169 $fontTitle = xlt('Please choose a valid selection from the list.');
170 $fontText = xlt( 'Fix this' );
171 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
174 } else if (!$got_selected && strlen ( $currvalue ) > 0 && $multiple) {
175 //if not found in main list, display all selected values that exist in backup list
176 $list_id = $backup_list;
178 $lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? ORDER BY seq, title", array($list_id));
180 $got_selected_backup = FALSE;
181 if (!empty($backup_list)) {
182 while ( $lrow_backup = sqlFetchArray ( $lres_backup ) ) {
183 $selectedValues = explode ( "|", $currvalue );
185 $optionValue = attr($lrow ['option_id']);
187 if ($multiple && (strlen ( $currvalue ) == 0 && $lrow_backup ['is_default']) ||
188 (strlen ( $currvalue ) > 0 && in_array ( $lrow_backup ['option_id'], $selectedValues ))) {
189 $s .= "<option value='$optionValue'";
190 $s .= " selected";
191 $optionLabel = text(xl_list_label($lrow_backup ['title']));
192 $s .= ">$optionLabel</option>\n";
193 $got_selected_backup = TRUE;
197 if (!$got_selected_backup) {
198 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
199 $s .= "</select>";
200 $fontTitle = xlt('Please choose a valid selection from the list.');
201 $fontText = xlt( 'Fix this' );
202 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
206 else {
207 $s .= "</select>";
209 return $s;
213 // $frow is a row from the layout_options table.
214 // $currvalue is the current value, if any, of the associated item.
216 function generate_form_field($frow, $currvalue) {
217 global $rootdir, $date_init, $ISSUE_TYPES, $code_types,$condition_str;
219 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
221 $data_type = $frow['data_type'];
222 $field_id = $frow['field_id'];
223 $list_id = $frow['list_id'];
224 $backup_list = $frow['list_backup_id'];
225 $condition_str = get_conditions_str($condition_str,$frow);
227 // escaped variables to use in html
228 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
229 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
231 // Added 5-09 by BM - Translate description if applicable
232 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
234 // Support edit option T which assigns the (possibly very long) description as
235 // the default value.
236 if (strpos($frow['edit_options'], 'T') !== FALSE) {
237 if (strlen($currescaped) == 0) $currescaped = $description;
238 // Description used in this way is not suitable as a title.
239 $description = '';
242 // added 5-2009 by BM to allow modification of the 'empty' text title field.
243 // Can pass $frow['empty_title'] with this variable, otherwise
244 // will default to 'Unassigned'.
245 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
246 // if make $frow['empty_title'] equal to 'SKIP'
247 $showEmpty = true;
248 if (isset($frow['empty_title'])) {
249 if ($frow['empty_title'] == "SKIP") {
250 //do not display an 'empty' choice
251 $showEmpty = false;
252 $empty_title = "Unassigned";
254 else {
255 $empty_title = $frow['empty_title'];
258 else {
259 $empty_title = "Unassigned";
262 $disabled = strpos($frow['edit_options'], '0') === FALSE ? '' : 'disabled';
264 $lbfchange = (strpos($frow['form_id'], 'LBF') === 0 || strpos($frow['form_id'], 'LBT') === 0) ?
265 "checkSkipConditions();" : "";
266 $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
268 // generic single-selection list or Race and Ethnicity.
269 // These data types support backup lists.
270 if ($data_type == 1 || $data_type == 33) {
271 echo generate_select_list("form_$field_id", $list_id, $currvalue,
272 $description, ($showEmpty ? $empty_title : ''), '', $lbfchange, '',
273 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
276 // simple text field
277 else if ($data_type == 2) {
278 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
279 $maxlength = $frow['max_length'];
280 $string_maxlength = "";
281 // if max_length is set to zero, then do not set a maxlength
282 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
283 echo "<input type='text'" .
284 " name='form_$field_id_esc'" .
285 " id='form_$field_id_esc'" .
286 " size='$fldlength'" .
287 " $string_maxlength" .
288 " title='$description'" .
289 " value='$currescaped'";
290 $tmp = $lbfchange;
291 if (strpos($frow['edit_options'], 'C') !== FALSE)
292 $tmp .= "capitalizeMe(this);";
293 else if (strpos($frow['edit_options'], 'U') !== FALSE)
294 $tmp .= "this.value = this.value.toUpperCase();";
295 if ($tmp) echo " onchange='$tmp'";
296 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
297 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
298 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
299 echo " onblur='maskblur(this,\"$tmp\")'";
301 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
302 echo " readonly";
304 if ($disabled) echo ' disabled';
305 echo " />";
308 // long or multi-line text field
309 else if ($data_type == 3) {
310 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
311 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
312 echo "<textarea" .
313 " name='form_$field_id_esc'" .
314 " id='form_$field_id_esc'" .
315 " title='$description'" .
316 " cols='$textCols'" .
317 " rows='$textRows' $lbfonchange $disabled" .
318 ">" . $currescaped . "</textarea>";
321 // date
322 else if ($data_type == 4) {
323 $age_asof_date = ''; // optionalAge() sets this
324 $age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0;
325 $agestr = optionalAge($frow, $currvalue, $age_asof_date);
326 if ($agestr) {
327 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
329 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
330 " value='" . substr($currescaped, 0, 10) . "'";
331 if (!$agestr) echo " title='$description'";
332 echo " $lbfonchange onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
333 if (!$disabled) {
334 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
335 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
336 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
337 $date_init .= " Calendar.setup({" .
338 "inputField:'form_$field_id', " .
339 "ifFormat:'%Y-%m-%d', ";
340 if ($agestr) {
341 $date_init .= "onUpdate: function() {" .
342 "if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format);" .
343 "}, ";
345 $date_init .= "button:'img_$field_id'})\n";
347 // Optional display of age or gestational age.
348 if ($agestr) {
349 echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
353 // provider list, local providers only
354 else if ($data_type == 10) {
355 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
356 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
357 "AND authorized = 1 " .
358 "ORDER BY lname, fname");
359 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled>";
360 echo "<option value=''>" . xlt($empty_title) . "</option>";
361 $got_selected = false;
362 while ($urow = sqlFetchArray($ures)) {
363 $uname = text($urow['fname'] . ' ' . $urow['lname']);
364 $optionId = attr($urow['id']);
365 echo "<option value='$optionId'";
366 if ($urow['id'] == $currvalue) {
367 echo " selected";
368 $got_selected = true;
370 echo ">$uname</option>";
372 if (!$got_selected && $currvalue) {
373 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
374 echo "</select>";
375 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
377 else {
378 echo "</select>";
382 // provider list, including address book entries with an NPI number
383 else if ($data_type == 11) {
384 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
385 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
386 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
387 "ORDER BY lname, fname");
388 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
389 echo " $lbfonchange $disabled>";
390 echo "<option value=''>" . xlt('Unassigned') . "</option>";
391 $got_selected = false;
392 while ($urow = sqlFetchArray($ures)) {
393 $uname = text($urow['fname'] . ' ' . $urow['lname']);
394 $optionId = attr($urow['id']);
395 echo "<option value='$optionId'";
396 if ($urow['id'] == $currvalue) {
397 echo " selected";
398 $got_selected = true;
400 echo ">$uname</option>";
402 if (!$got_selected && $currvalue) {
403 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
404 echo "</select>";
405 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
407 else {
408 echo "</select>";
412 // pharmacy list
413 else if ($data_type == 12) {
414 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
415 echo " $lbfonchange $disabled>";
416 echo "<option value='0'></option>";
417 $pres = get_pharmacies();
418 $got_selected = false;
419 while ($prow = sqlFetchArray($pres)) {
420 $key = $prow['id'];
421 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
422 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
423 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
424 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
425 echo "<option value='$optionValue'";
426 if ($currvalue == $key) {
427 echo " selected";
428 $got_selected = true;
430 echo ">$optionLabel</option>";
432 if (!$got_selected && $currvalue) {
433 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
434 echo "</select>";
435 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
437 else {
438 echo "</select>";
442 // squads
443 else if ($data_type == 13) {
444 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
445 echo " $lbfonchange $disabled>";
446 echo "<option value=''>&nbsp;</option>";
447 $squads = acl_get_squads();
448 if ($squads) {
449 foreach ($squads as $key => $value) {
450 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
451 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
452 echo "<option value='$optionValue'";
453 if ($currvalue == $key) echo " selected";
454 echo ">$optionLabel</option>\n";
457 echo "</select>";
460 // Address book, preferring organization name if it exists and is not in
461 // parentheses, and excluding local users who are not providers.
462 // Supports "referred to" practitioners and facilities.
463 // Alternatively the letter L in edit_options means that abook_type
464 // must be "ord_lab", indicating types used with the procedure
465 // lab ordering system.
466 // Alternatively the letter O in edit_options means that abook_type
467 // must begin with "ord_", indicating types used with the procedure
468 // ordering system.
469 // Alternatively the letter V in edit_options means that abook_type
470 // must be "vendor", indicating the Vendor type.
471 // Alternatively the letter R in edit_options means that abook_type
472 // must be "dist", indicating the Distributor type.
473 else if ($data_type == 14) {
474 if (strpos($frow['edit_options'], 'L') !== FALSE)
475 $tmp = "abook_type = 'ord_lab'";
476 else if (strpos($frow['edit_options'], 'O') !== FALSE)
477 $tmp = "abook_type LIKE 'ord\\_%'";
478 else if (strpos($frow['edit_options'], 'V') !== FALSE)
479 $tmp = "abook_type LIKE 'vendor%'";
480 else if (strpos($frow['edit_options'], 'R') !== FALSE)
481 $tmp = "abook_type LIKE 'dist'";
482 else
483 $tmp = "( username = '' OR authorized = 1 )";
484 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
485 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
486 "AND $tmp " .
487 "ORDER BY organization, lname, fname");
488 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
489 echo " $lbfonchange $disabled>";
490 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
491 while ($urow = sqlFetchArray($ures)) {
492 $uname = $urow['organization'];
493 if (empty($uname) || substr($uname, 0, 1) == '(') {
494 $uname = $urow['lname'];
495 if ($urow['fname']) $uname .= ", " . $urow['fname'];
497 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
498 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
499 echo "<option value='$optionValue'";
500 $title = $urow['username'] ? xl('Local') : xl('External');
501 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
502 echo " title='$optionTitle'";
503 if ($urow['id'] == $currvalue) echo " selected";
504 echo ">$optionLabel</option>";
506 echo "</select>";
509 // A billing code. If description matches an existing code type then that type is used.
510 else if ($data_type == 15) {
511 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
512 $maxlength = $frow['max_length'];
513 $string_maxlength = "";
514 // if max_length is set to zero, then do not set a maxlength
515 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
517 if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
518 // Option "2" generates a hidden input for the codes, and a matching visible field
519 // displaying their descriptions. First step is computing the description string.
520 $currdescstring = '';
521 if (!empty($currvalue)) {
522 $relcodes = explode(';', $currvalue);
523 foreach ($relcodes as $codestring) {
524 if ($codestring === '') continue;
525 $code_text = lookup_code_descriptions($codestring);
526 if ($currdescstring !== '') $currdescstring .= '; ';
527 if (!empty($code_text)) {
528 $currdescstring .= $code_text;
530 else {
531 $currdescstring .= $codestring;
535 $currdescstring = attr($currdescstring);
537 echo "<input type='text'" .
538 " name='form_$field_id_esc'" .
539 " id='form_related_code'" .
540 " size='$fldlength'" .
541 " value='$currescaped'" .
542 " style='display:none'" .
543 " $lbfonchange readonly $disabled />";
544 // Extra readonly input field for optional display of code description(s).
545 echo "<input type='text'" .
546 " name='form_$field_id_esc" . "__desc'" .
547 " size='$fldlength'" .
548 " title='$description'" .
549 " value='$currdescstring'";
550 if (!$disabled) {
551 echo " onclick='sel_related(this,\"$codetype\")'";
553 echo " readonly $disabled />";
555 else {
556 echo "<input type='text'" .
557 " name='form_$field_id_esc'" .
558 " id='form_related_code'" .
559 " size='$fldlength'" .
560 " $string_maxlength" .
561 " title='$description'" .
562 " value='$currescaped'";
563 if (!$disabled) {
564 echo " onclick='sel_related(this,\"$codetype\")'";
566 echo " $lbfonchange readonly $disabled />";
570 // insurance company list
571 else if ($data_type == 16) {
572 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
573 echo "<option value='0'></option>";
574 $insprovs = getInsuranceProviders();
575 $got_selected = false;
576 foreach ($insprovs as $key => $ipname) {
577 $optionValue = htmlspecialchars($key, ENT_QUOTES);
578 $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
579 echo "<option value='$optionValue'";
580 if ($currvalue == $key) {
581 echo " selected";
582 $got_selected = true;
584 echo ">$optionLabel</option>";
586 if (!$got_selected && $currvalue) {
587 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
588 echo "</select>";
589 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
591 else {
592 echo "</select>";
596 // issue types
597 else if ($data_type == 17) {
598 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
599 echo "<option value='0'></option>";
600 $got_selected = false;
601 foreach ($ISSUE_TYPES as $key => $value) {
602 $optionValue = htmlspecialchars($key, ENT_QUOTES);
603 $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
604 echo "<option value='$optionValue'";
605 if ($currvalue == $key) {
606 echo " selected";
607 $got_selected = true;
609 echo ">$optionLabel</option>";
611 if (!$got_selected && strlen($currvalue) > 0) {
612 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
613 echo "</select>";
614 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
616 else {
617 echo "</select>";
621 // Visit categories.
622 else if ($data_type == 18) {
623 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
624 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
625 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
626 " $lbfonchange $disabled>";
627 echo "<option value=''>" . xlt($empty_title) . "</option>";
628 $got_selected = false;
629 while ($crow = sqlFetchArray($cres)) {
630 $catid = $crow['pc_catid'];
631 if (($catid < 9 && $catid != 5) || $catid == 11) continue;
632 echo "<option value='" . attr($catid) . "'";
633 if ($catid == $currvalue) {
634 echo " selected";
635 $got_selected = true;
637 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
639 if (!$got_selected && $currvalue) {
640 echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
641 echo "</select>";
642 echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
644 else {
645 echo "</select>";
649 // a set of labeled checkboxes
650 else if ($data_type == 21) {
651 // In this special case, fld_length is the number of columns generated.
652 $cols = max(1, $frow['fld_length']);
653 $avalue = explode('|', $currvalue);
654 $lres = sqlStatement("SELECT * FROM list_options " .
655 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
656 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
657 $tdpct = (int) (100 / $cols);
658 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
659 $option_id = $lrow['option_id'];
660 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
661 // if ($count) echo "<br />";
662 if ($count % $cols == 0) {
663 if ($count) echo "</tr>";
664 echo "<tr>";
666 echo "<td width='$tdpct%'>";
667 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
668 "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
669 if (in_array($option_id, $avalue)) echo " checked";
671 // Added 5-09 by BM - Translate label if applicable
672 echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
674 echo "</td>";
676 if ($count) {
677 echo "</tr>";
678 if ($count > $cols) {
679 // Add some space after multiple rows of checkboxes.
680 $cols = htmlspecialchars( $cols, ENT_QUOTES);
681 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
684 echo "</table>";
687 // a set of labeled text input fields
688 else if ($data_type == 22) {
689 $tmp = explode('|', $currvalue);
690 $avalue = array();
691 foreach ($tmp as $value) {
692 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
693 $avalue[$matches[1]] = $matches[2];
696 $lres = sqlStatement("SELECT * FROM list_options " .
697 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
698 echo "<table cellpadding='0' cellspacing='0'>";
699 while ($lrow = sqlFetchArray($lres)) {
700 $option_id = $lrow['option_id'];
701 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
702 $maxlength = $frow['max_length'];
703 $string_maxlength = "";
704 // if max_length is set to zero, then do not set a maxlength
705 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
706 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
708 // Added 5-09 by BM - Translate label if applicable
709 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
710 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
711 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
712 echo "<td><input type='text'" .
713 " name='form_{$field_id_esc}[$option_id_esc]'" .
714 " id='form_{$field_id_esc}[$option_id_esc]'" .
715 " size='$fldlength'" .
716 " $string_maxlength" .
717 " value='$optionValue'";
718 echo " $lbfonchange $disabled /></td></tr>";
720 echo "</table>";
723 // a set of exam results; 3 radio buttons and a text field:
724 else if ($data_type == 23) {
725 $tmp = explode('|', $currvalue);
726 $avalue = array();
727 foreach ($tmp as $value) {
728 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
729 $avalue[$matches[1]] = $matches[2];
732 $maxlength = $frow['max_length'];
733 $string_maxlength = "";
734 // if max_length is set to zero, then do not set a maxlength
735 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
736 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
737 $lres = sqlStatement("SELECT * FROM list_options " .
738 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
739 echo "<table cellpadding='0' cellspacing='0'>";
740 echo "<tr><td>&nbsp;</td><td class='bold'>" .
741 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
742 "&nbsp;</td><td class='bold'>" .
743 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
744 "<td class='bold'>" .
745 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
746 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
747 while ($lrow = sqlFetchArray($lres)) {
748 $option_id = $lrow['option_id'];
749 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
750 $restype = substr($avalue[$option_id], 0, 1);
751 $resnote = substr($avalue[$option_id], 2);
753 // Added 5-09 by BM - Translate label if applicable
754 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
756 for ($i = 0; $i < 3; ++$i) {
757 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
758 echo "<td><input type='radio'" .
759 " name='radio_{$field_id_esc}[$option_id_esc]'" .
760 " id='radio_{$field_id_esc}[$option_id_esc]'" .
761 " value='$inputValue' $lbfonchange";
762 if ($restype === "$i") echo " checked";
763 echo " $disabled /></td>";
765 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
766 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
767 echo "<td><input type='text'" .
768 " name='form_{$field_id_esc}[$option_id_esc]'" .
769 " id='form_{$field_id_esc}[$option_id_esc]'" .
770 " size='$fldlength'" .
771 " $string_maxlength" .
772 " value='$resnote' $disabled /></td>";
773 echo "</tr>";
775 echo "</table>";
778 // the list of active allergies for the current patient
779 // this is read-only!
780 else if ($data_type == 24) {
781 $query = "SELECT title, comments FROM lists WHERE " .
782 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
783 "ORDER BY begdate";
784 // echo "<!-- $query -->\n"; // debugging
785 $lres = sqlStatement($query, array($GLOBALS['pid']));
786 $count = 0;
787 while ($lrow = sqlFetchArray($lres)) {
788 if ($count++) echo "<br />";
789 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
790 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
794 // a set of labeled checkboxes, each with a text field:
795 else if ($data_type == 25) {
796 $tmp = explode('|', $currvalue);
797 $avalue = array();
798 foreach ($tmp as $value) {
799 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
800 $avalue[$matches[1]] = $matches[2];
803 $maxlength = $frow['max_length'];
804 $string_maxlength = "";
805 // if max_length is set to zero, then do not set a maxlength
806 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
807 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
808 $lres = sqlStatement("SELECT * FROM list_options " .
809 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
810 echo "<table cellpadding='0' cellspacing='0'>";
811 while ($lrow = sqlFetchArray($lres)) {
812 $option_id = $lrow['option_id'];
813 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
814 $restype = substr($avalue[$option_id], 0, 1);
815 $resnote = substr($avalue[$option_id], 2);
817 // Added 5-09 by BM - Translate label if applicable
818 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
820 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
821 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
822 " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
823 if ($restype) echo " checked";
824 echo " $disabled />&nbsp;</td>";
825 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
826 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
827 echo "<td><input type='text'" .
828 " name='form_{$field_id_esc}[$option_id_esc]'" .
829 " id='form_{$field_id_esc}[$option_id_esc]'" .
830 " size='$fldlength'" .
831 " $string_maxlength" .
832 " value='$resnote' $disabled /></td>";
833 echo "</tr>";
835 echo "</table>";
838 // single-selection list with ability to add to it
839 else if ($data_type == 26) {
840 echo generate_select_list("form_$field_id", $list_id, $currvalue,
841 $description, ($showEmpty ? $empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
842 ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
843 // show the add button if user has access to correct list
844 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
845 $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
846 $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
847 if (aco_exist('lists', $list_id)) {
848 // a specific aco exist for this list, so ensure access
849 if (acl_check('lists', $list_id)) echo $outputAddButton;
851 else {
852 // no specific aco exist for this list, so check for access to 'default' list
853 if (acl_check('lists', 'default')) echo $outputAddButton;
857 // a set of labeled radio buttons
858 else if ($data_type == 27) {
859 // In this special case, fld_length is the number of columns generated.
860 $cols = max(1, $frow['fld_length']);
861 $lres = sqlStatement("SELECT * FROM list_options " .
862 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
863 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
864 $tdpct = (int) (100 / $cols);
865 $got_selected = FALSE;
866 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
867 $option_id = $lrow['option_id'];
868 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
869 if ($count % $cols == 0) {
870 if ($count) echo "</tr>";
871 echo "<tr>";
873 echo "<td width='$tdpct%'>";
874 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
875 " value='$option_id_esc' $lbfonchange";
876 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
877 (strlen($currvalue) > 0 && $option_id == $currvalue))
879 echo " checked";
880 $got_selected = TRUE;
882 echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
883 echo "</td>";
885 if ($count) {
886 echo "</tr>";
887 if ($count > $cols) {
888 // Add some space after multiple rows of radio buttons.
889 $cols = htmlspecialchars($cols, ENT_QUOTES);
890 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
893 echo "</table>";
894 if (!$got_selected && strlen($currvalue) > 0) {
895 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
896 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
897 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
901 // special case for history of lifestyle status; 3 radio buttons and a date text field:
902 // VicarePlus :: A selection list box for smoking status:
903 else if ($data_type == 28 || $data_type == 32) {
904 $tmp = explode('|', $currvalue);
905 switch(count($tmp)) {
906 case "4": {
907 $resnote = $tmp[0];
908 $restype = $tmp[1];
909 $resdate = $tmp[2];
910 $reslist = $tmp[3];
911 } break;
912 case "3": {
913 $resnote = $tmp[0];
914 $restype = $tmp[1];
915 $resdate = $tmp[2];
916 } break;
917 case "2": {
918 $resnote = $tmp[0];
919 $restype = $tmp[1];
920 $resdate = "";
921 } break;
922 case "1": {
923 $resnote = $tmp[0];
924 $resdate = $restype = "";
925 } break;
926 default: {
927 $restype = $resdate = $resnote = "";
928 } break;
930 $maxlength = $frow['max_length'];
931 $string_maxlength = "";
932 // if max_length is set to zero, then do not set a maxlength
933 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
934 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
936 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
937 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
938 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
939 echo "<table cellpadding='0' cellspacing='0'>";
940 echo "<tr>";
941 if ($data_type == 28)
943 // input text
944 echo "<td><input type='text'" .
945 " name='form_$field_id_esc'" .
946 " id='form_$field_id_esc'" .
947 " size='$fldlength'" .
948 " $string_maxlength" .
949 " value='$resnote' $disabled />&nbsp;</td>";
950 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
951 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
952 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
954 else if($data_type == 32)
956 // input text
957 echo "<tr><td><input type='text'" .
958 " name='form_text_$field_id_esc'" .
959 " id='form_text_$field_id_esc'" .
960 " size='$fldlength'" .
961 " $string_maxlength" .
962 " value='$resnote' $disabled />&nbsp;</td></tr>";
963 echo "<td>";
964 //Selection list for smoking status
965 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
966 echo generate_select_list("form_$field_id", $list_id, $reslist,
967 $description, ($showEmpty ? $empty_title : ''), '', $onchange, '',
968 ($disabled ? array('disabled' => 'disabled') : null));
969 echo "</td>";
970 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
972 // current
973 echo "<td class='text' ><input type='radio'" .
974 " name='radio_{$field_id_esc}'" .
975 " id='radio_{$field_id_esc}[current]'" .
976 " value='current" . $field_id_esc . "' $lbfonchange";
977 if ($restype == "current" . $field_id) echo " checked";
978 if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
979 echo " />" . xlt('Current') . "&nbsp;</td>";
980 // quit
981 echo "<td class='text'><input type='radio'" .
982 " name='radio_{$field_id_esc}'" .
983 " id='radio_{$field_id_esc}[quit]'" .
984 " value='quit".$field_id_esc."' $lbfonchange";
985 if ($restype == "quit" . $field_id) echo " checked";
986 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
987 echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
988 // quit date
989 echo "<td class='text'><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
990 " value='$resdate'" .
991 " title='$description'" .
992 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
993 if (!$disabled) {
994 echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
995 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
996 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
997 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
999 echo "&nbsp;</td>";
1000 // never
1001 echo "<td class='text'><input type='radio'" .
1002 " name='radio_{$field_id_esc}'" .
1003 " id='radio_{$field_id_esc}[never]'" .
1004 " value='never" . $field_id_esc . "' $lbfonchange";
1005 if ($restype == "never" . $field_id) echo " checked";
1006 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1007 echo " />" . xlt('Never') . "&nbsp;</td>";
1008 // Not Applicable
1009 echo "<td class='text'><input type='radio'" .
1010 " name='radio_{$field_id}'" .
1011 " id='radio_{$field_id}[not_applicable]'" .
1012 " value='not_applicable" . $field_id . "' $lbfonchange";
1013 if ($restype == "not_applicable" . $field_id) echo " checked";
1014 if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
1015 echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
1017 //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1018 echo "<td class='text' ><div id='smoke_code'></div></td>";
1019 echo "</tr>";
1020 echo "</table>";
1023 // static text. read-only, of course.
1024 else if ($data_type == 31) {
1025 echo nl2br($frow['description']);
1028 //$data_type == 33
1029 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
1030 //$data_type == 33
1032 else if($data_type == 34){
1033 $arr = explode("|*|*|*|",$currvalue);
1034 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc,ENT_QUOTES)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1035 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
1036 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
1037 echo "</a>";
1040 //facilities drop-down list
1041 else if ($data_type == 35) {
1042 if (empty($currvalue)){
1043 $currvalue = 0;
1045 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
1046 $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
1049 //multiple select
1050 // supports backup list
1051 else if ($data_type == 36) {
1052 echo generate_select_list("form_$field_id", $list_id, $currvalue,
1053 $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);
1057 // Canvas and related elements for browser-side image drawing.
1058 // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
1059 else if ($data_type == 40) {
1060 // Unlike other field types, width and height are in pixels.
1061 $canWidth = intval($frow['fld_length']);
1062 $canHeight = intval($frow['fld_rows']);
1063 if (empty($currvalue)) {
1064 if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
1065 // If defined this is the filename of the default starting image.
1066 $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
1069 echo "<div id='form_$field_id_esc'></div>";
1070 // Hidden form field exists to send updated data to the server at submit time.
1071 echo "<input type='hidden' name='form_$field_id_esc' value='' />";
1072 // Hidden image exists to support initialization of the canvas.
1073 echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
1074 // $date_init is a misnomer but it's the place for browser-side setup logic.
1075 $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
1080 function generate_print_field($frow, $currvalue) {
1081 global $rootdir, $date_init, $ISSUE_TYPES;
1083 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
1085 $data_type = $frow['data_type'];
1086 $field_id = $frow['field_id'];
1087 $list_id = $frow['list_id'];
1088 $fld_length = $frow['fld_length'];
1089 $backup_list = $frow['list_backup_id'];
1091 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
1093 // Can pass $frow['empty_title'] with this variable, otherwise
1094 // will default to 'Unassigned'.
1095 // If it is 'SKIP' then an empty text title is completely skipped.
1096 $showEmpty = true;
1097 if (isset($frow['empty_title'])) {
1098 if ($frow['empty_title'] == "SKIP") {
1099 //do not display an 'empty' choice
1100 $showEmpty = false;
1101 $empty_title = "Unassigned";
1103 else {
1104 $empty_title = $frow['empty_title'];
1107 else {
1108 $empty_title = "Unassigned";
1111 // generic single-selection list
1112 // Supports backup lists.
1113 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
1114 if (empty($fld_length)) {
1115 if ($list_id == 'titles') {
1116 $fld_length = 3;
1117 } else {
1118 $fld_length = 10;
1121 $tmp = '';
1122 if ($currvalue) {
1123 $lrow = sqlQuery("SELECT title FROM list_options " .
1124 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
1125 $tmp = xl_list_label($lrow['title']);
1126 if ($lrow == 0 && !empty($backup_list)) {
1127 // since primary list did not map, try to map to backup list
1128 $lrow = sqlQuery("SELECT title FROM list_options " .
1129 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1130 $tmp = xl_list_label($lrow['title']);
1132 if (empty($tmp)) $tmp = "($currvalue)";
1134 /*****************************************************************
1135 echo "<input type='text'" .
1136 " size='$fld_length'" .
1137 " value='$tmp'" .
1138 " class='under'" .
1139 " />";
1140 *****************************************************************/
1141 if ($tmp === '') {
1142 $tmp = '&nbsp;';
1144 else {
1145 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1147 echo $tmp;
1150 // simple text field
1151 else if ($data_type == 2 || $data_type == 15) {
1152 /*****************************************************************
1153 echo "<input type='text'" .
1154 " size='$fld_length'" .
1155 " value='$currescaped'" .
1156 " class='under'" .
1157 " />";
1158 *****************************************************************/
1159 if ($currescaped === '') $currescaped = '&nbsp;';
1160 echo $currescaped;
1163 // long or multi-line text field
1164 else if ($data_type == 3) {
1165 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
1166 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
1167 echo "<textarea" .
1168 " cols='$fldlength'" .
1169 " rows='$maxlength'>" .
1170 $currescaped . "</textarea>";
1173 // date
1174 else if ($data_type == 4) {
1175 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1176 $agestr = optionalAge($frow, $currvalue,$asof);
1177 if ($agestr) {
1178 echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1180 if ($currvalue === '') {
1181 echo '&nbsp;';
1183 else {
1184 echo text(oeFormatShortDate($currvalue));
1186 // Optional display of age or gestational age.
1187 if ($agestr) {
1188 echo "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1192 // provider list
1193 else if ($data_type == 10 || $data_type == 11) {
1194 $tmp = '';
1195 if ($currvalue) {
1196 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1197 "WHERE id = ?", array($currvalue) );
1198 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
1199 if (empty($tmp)) $tmp = "($currvalue)";
1201 /*****************************************************************
1202 echo "<input type='text'" .
1203 " size='$fld_length'" .
1204 " value='$tmp'" .
1205 " class='under'" .
1206 " />";
1207 *****************************************************************/
1208 if ($tmp === '') { $tmp = '&nbsp;'; }
1209 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1210 echo $tmp;
1213 // pharmacy list
1214 else if ($data_type == 12) {
1215 $tmp = '';
1216 if ($currvalue) {
1217 $pres = get_pharmacies();
1218 while ($prow = sqlFetchArray($pres)) {
1219 $key = $prow['id'];
1220 if ($currvalue == $key) {
1221 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
1222 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1223 $prow['line1'] . ' / ' . $prow['city'];
1226 if (empty($tmp)) $tmp = "($currvalue)";
1228 /*****************************************************************
1229 echo "<input type='text'" .
1230 " size='$fld_length'" .
1231 " value='$tmp'" .
1232 " class='under'" .
1233 " />";
1234 *****************************************************************/
1235 if ($tmp === '') { $tmp = '&nbsp;'; }
1236 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1237 echo $tmp;
1240 // squads
1241 else if ($data_type == 13) {
1242 $tmp = '';
1243 if ($currvalue) {
1244 $squads = acl_get_squads();
1245 if ($squads) {
1246 foreach ($squads as $key => $value) {
1247 if ($currvalue == $key) {
1248 $tmp = $value[3];
1252 if (empty($tmp)) $tmp = "($currvalue)";
1254 /*****************************************************************
1255 echo "<input type='text'" .
1256 " size='$fld_length'" .
1257 " value='$tmp'" .
1258 " class='under'" .
1259 " />";
1260 *****************************************************************/
1261 if ($tmp === '') { $tmp = '&nbsp;'; }
1262 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1263 echo $tmp;
1266 // Address book.
1267 else if ($data_type == 14) {
1268 $tmp = '';
1269 if ($currvalue) {
1270 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1271 "WHERE id = ?", array($currvalue) );
1272 $uname = $urow['lname'];
1273 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1274 $tmp = $uname;
1275 if (empty($tmp)) $tmp = "($currvalue)";
1277 /*****************************************************************
1278 echo "<input type='text'" .
1279 " size='$fld_length'" .
1280 " value='$tmp'" .
1281 " class='under'" .
1282 " />";
1283 *****************************************************************/
1284 if ($tmp === '') { $tmp = '&nbsp;'; }
1285 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
1286 echo $tmp;
1289 // insurance company list
1290 else if ($data_type == 16) {
1291 $tmp = '';
1292 if ($currvalue) {
1293 $insprovs = getInsuranceProviders();
1294 foreach ($insprovs as $key => $ipname) {
1295 if ($currvalue == $key) {
1296 $tmp = $ipname;
1299 if (empty($tmp)) $tmp = "($currvalue)";
1301 if ($tmp === '') $tmp = '&nbsp;';
1302 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1303 echo $tmp;
1306 // issue types
1307 else if ($data_type == 17) {
1308 $tmp = '';
1309 if ($currvalue) {
1310 foreach ($ISSUE_TYPES as $key => $value) {
1311 if ($currvalue == $key) {
1312 $tmp = $value[1];
1315 if (empty($tmp)) $tmp = "($currvalue)";
1317 if ($tmp === '') $tmp = '&nbsp;';
1318 else $tmp = htmlspecialchars($tmp, ENT_QUOTES);
1319 echo $tmp;
1322 // Visit categories.
1323 else if ($data_type == 18) {
1324 $tmp = '';
1325 if ($currvalue) {
1326 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1327 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1328 array($currvalue));
1329 $tmp = xl_appt_category($crow['pc_catname']);
1330 if (empty($tmp)) $tmp = "($currvalue)";
1332 if ($tmp === '') { $tmp = '&nbsp;'; }
1333 else { $tmp = htmlspecialchars($tmp, ENT_QUOTES); }
1334 echo $tmp;
1337 // a set of labeled checkboxes
1338 else if ($data_type == 21) {
1339 // In this special case, fld_length is the number of columns generated.
1340 $cols = max(1, $fld_length);
1341 $avalue = explode('|', $currvalue);
1342 $lres = sqlStatement("SELECT * FROM list_options " .
1343 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1344 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1345 $tdpct = (int) (100 / $cols);
1346 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1347 $option_id = $lrow['option_id'];
1348 if ($count % $cols == 0) {
1349 if ($count) echo "</tr>";
1350 echo "<tr>";
1352 echo "<td width='$tdpct%'>";
1353 echo "<input type='checkbox'";
1354 if (in_array($option_id, $avalue)) echo " checked";
1355 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1356 echo "</td>";
1358 if ($count) {
1359 echo "</tr>";
1360 if ($count > $cols) {
1361 // Add some space after multiple rows of checkboxes.
1362 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1363 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1366 echo "</table>";
1369 // a set of labeled text input fields
1370 else if ($data_type == 22) {
1371 $tmp = explode('|', $currvalue);
1372 $avalue = array();
1373 foreach ($tmp as $value) {
1374 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1375 $avalue[$matches[1]] = $matches[2];
1378 $lres = sqlStatement("SELECT * FROM list_options " .
1379 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1380 echo "<table cellpadding='0' cellspacing='0'>";
1381 while ($lrow = sqlFetchArray($lres)) {
1382 $option_id = $lrow['option_id'];
1383 $fldlength = empty($fld_length) ? 20 : $fld_length;
1384 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1385 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1386 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1387 echo "<td><input type='text'" .
1388 " size='$fldlength'" .
1389 " value='$inputValue'" .
1390 " class='under'" .
1391 " /></td></tr>";
1393 echo "</table>";
1396 // a set of exam results; 3 radio buttons and a text field:
1397 else if ($data_type == 23) {
1398 $tmp = explode('|', $currvalue);
1399 $avalue = array();
1400 foreach ($tmp as $value) {
1401 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1402 $avalue[$matches[1]] = $matches[2];
1405 $fldlength = empty($fld_length) ? 20 : $fld_length;
1406 $lres = sqlStatement("SELECT * FROM list_options " .
1407 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1408 echo "<table cellpadding='0' cellspacing='0'>";
1409 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1410 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1411 "&nbsp;</td><td class='bold'>" .
1412 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1413 "<td class='bold'>" .
1414 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1415 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1416 while ($lrow = sqlFetchArray($lres)) {
1417 $option_id = $lrow['option_id'];
1418 $restype = substr($avalue[$option_id], 0, 1);
1419 $resnote = substr($avalue[$option_id], 2);
1420 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1421 for ($i = 0; $i < 3; ++$i) {
1422 echo "<td><input type='radio'";
1423 if ($restype === "$i") echo " checked";
1424 echo " /></td>";
1426 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1427 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1428 echo "<td><input type='text'" .
1429 " size='$fldlength'" .
1430 " value='$resnote'" .
1431 " class='under' /></td>" .
1432 "</tr>";
1434 echo "</table>";
1437 // the list of active allergies for the current patient
1438 // this is read-only!
1439 else if ($data_type == 24) {
1440 $query = "SELECT title, comments FROM lists WHERE " .
1441 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1442 "ORDER BY begdate";
1443 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1444 $count = 0;
1445 while ($lrow = sqlFetchArray($lres)) {
1446 if ($count++) echo "<br />";
1447 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1448 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1452 // a set of labeled checkboxes, each with a text field:
1453 else if ($data_type == 25) {
1454 $tmp = explode('|', $currvalue);
1455 $avalue = array();
1456 foreach ($tmp as $value) {
1457 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1458 $avalue[$matches[1]] = $matches[2];
1461 $fldlength = empty($fld_length) ? 20 : $fld_length;
1462 $lres = sqlStatement("SELECT * FROM list_options " .
1463 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1464 echo "<table cellpadding='0' cellspacing='0'>";
1465 while ($lrow = sqlFetchArray($lres)) {
1466 $option_id = $lrow['option_id'];
1467 $restype = substr($avalue[$option_id], 0, 1);
1468 $resnote = substr($avalue[$option_id], 2);
1469 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1470 echo "<td><input type='checkbox'";
1471 if ($restype) echo " checked";
1472 echo " />&nbsp;</td>";
1473 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1474 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1475 echo "<td><input type='text'" .
1476 " size='$fldlength'" .
1477 " value='$resnote'" .
1478 " class='under'" .
1479 " /></td>" .
1480 "</tr>";
1482 echo "</table>";
1485 // a set of labeled radio buttons
1486 else if ($data_type == 27) {
1487 // In this special case, fld_length is the number of columns generated.
1488 $cols = max(1, $frow['fld_length']);
1489 $lres = sqlStatement("SELECT * FROM list_options " .
1490 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1491 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1492 $tdpct = (int) (100 / $cols);
1493 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1494 $option_id = $lrow['option_id'];
1495 if ($count % $cols == 0) {
1496 if ($count) echo "</tr>";
1497 echo "<tr>";
1499 echo "<td width='$tdpct%'>";
1500 echo "<input type='radio'";
1501 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1502 (strlen($currvalue) > 0 && $option_id == $currvalue))
1504 echo " checked";
1506 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1507 echo "</td>";
1509 if ($count) {
1510 echo "</tr>";
1511 if ($count > $cols) {
1512 // Add some space after multiple rows of radio buttons.
1513 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1514 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1517 echo "</table>";
1520 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1521 else if ($data_type == 28 || $data_type == 32) {
1522 $tmp = explode('|', $currvalue);
1523 switch(count($tmp)) {
1524 case "4": {
1525 $resnote = $tmp[0];
1526 $restype = $tmp[1];
1527 $resdate = $tmp[2];
1528 $reslist = $tmp[3];
1529 } break;
1530 case "3": {
1531 $resnote = $tmp[0];
1532 $restype = $tmp[1];
1533 $resdate = $tmp[2];
1534 } break;
1535 case "2": {
1536 $resnote = $tmp[0];
1537 $restype = $tmp[1];
1538 $resdate = "";
1539 } break;
1540 case "1": {
1541 $resnote = $tmp[0];
1542 $resdate = $restype = "";
1543 } break;
1544 default: {
1545 $restype = $resdate = $resnote = "";
1546 } break;
1548 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1549 echo "<table cellpadding='0' cellspacing='0'>";
1550 echo "<tr>";
1551 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1552 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1553 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1554 if($data_type == 28)
1556 echo "<td><input type='text'" .
1557 " size='$fldlength'" .
1558 " class='under'" .
1559 " value='$resnote' /></td>";
1560 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1561 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1562 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1564 else if($data_type == 32)
1566 echo "<tr><td><input type='text'" .
1567 " size='$fldlength'" .
1568 " class='under'" .
1569 " value='$resnote' /></td></tr>";
1570 $fldlength = 30;
1571 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1572 echo "<td><input type='text'" .
1573 " size='$fldlength'" .
1574 " class='under'" .
1575 " value='$smoking_status_title' /></td>";
1576 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1578 echo "<td><input type='radio'";
1579 if ($restype == "current".$field_id) echo " checked";
1580 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1582 echo "<td><input type='radio'";
1583 if ($restype == "current".$field_id) echo " checked";
1584 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1586 echo "<td><input type='text' size='6'" .
1587 " value='$resdate'" .
1588 " class='under'" .
1589 " /></td>";
1591 echo "<td><input type='radio'";
1592 if ($restype == "current".$field_id) echo " checked";
1593 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1595 echo "<td><input type='radio'";
1596 if ($restype == "not_applicable".$field_id) echo " checked";
1597 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1598 echo "</tr>";
1599 echo "</table>";
1602 // static text. read-only, of course.
1603 else if ($data_type == 31) {
1604 echo nl2br($frow['description']);
1607 else if($data_type == 34){
1608 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;'>";
1609 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1610 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1611 echo "</a>";
1614 //facilities drop-down list
1615 else if ($data_type == 35) {
1616 if (empty($currvalue)){
1617 $currvalue = 0;
1619 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1622 //Multi-select
1623 // Supports backup lists.
1624 else if ($data_type == 36) {
1625 if (empty($fld_length)) {
1626 if ($list_id == 'titles') {
1627 $fld_length = 3;
1628 } else {
1629 $fld_length = 10;
1632 $tmp = '';
1634 $values_array = explode("|", $currvalue);
1636 $i=0;
1637 foreach($values_array as $value) {
1638 if ($value) {
1639 $lrow = sqlQuery("SELECT title FROM list_options " .
1640 "WHERE list_id = ? AND option_id = ?", array($list_id,$value));
1641 $tmp = xl_list_label($lrow['title']);
1642 if ($lrow == 0 && !empty($backup_list)) {
1643 // since primary list did not map, try to map to backup list
1644 $lrow = sqlQuery("SELECT title FROM list_options " .
1645 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue));
1646 $tmp = xl_list_label($lrow['title']);
1648 if (empty($tmp)) $tmp = "($value)";
1651 if ($tmp === '') {
1652 $tmp = '&nbsp;';
1654 else {
1655 $tmp = htmlspecialchars( $tmp, ENT_QUOTES);
1657 if ($i != 0 && $tmp != '&nbsp;') echo ",";
1658 echo $tmp;
1659 $i++;
1663 // Image from canvas drawing
1664 else if ($data_type == 40) {
1665 echo "<img src='" . attr($currvalue) . "'>";
1670 function generate_display_field($frow, $currvalue) {
1671 global $ISSUE_TYPES;
1673 $data_type = $frow['data_type'];
1674 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1675 $list_id = $frow['list_id'];
1676 $backup_list = $frow['list_backup_id'];
1678 $s = '';
1680 // generic selection list or the generic selection list with add on the fly
1681 // feature, or radio buttons
1682 // Supports backup lists for datatypes 1,26,33
1683 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1684 $lrow = sqlQuery("SELECT title FROM list_options " .
1685 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1686 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1687 //if there is no matching value in the corresponding lists check backup list
1688 // only supported in data types 1,26,33
1689 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
1690 $lrow = sqlQuery("SELECT title FROM list_options " .
1691 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
1692 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1696 // simple text field
1697 else if ($data_type == 2) {
1698 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1701 // long or multi-line text field
1702 else if ($data_type == 3) {
1703 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1706 // date
1707 else if ($data_type == 4) {
1708 $asof = ''; //not used here, but set to prevent a php warning when call optionalAge
1709 $s = '';
1710 $agestr = optionalAge($frow, $currvalue, $asof);
1711 if ($agestr) {
1712 $s .= "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
1714 if ($currvalue === '') {
1715 $s .= '&nbsp;';
1717 else {
1718 $s .= text(oeFormatShortDate($currvalue));
1720 // Optional display of age or gestational age.
1721 if ($agestr) {
1722 $s .= "</td></tr><tr><td class='text'>" . text($agestr) . "</td></tr></table>";
1726 // provider
1727 else if ($data_type == 10 || $data_type == 11) {
1728 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1729 "WHERE id = ?", array($currvalue) );
1730 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1733 // pharmacy list
1734 else if ($data_type == 12) {
1735 $pres = get_pharmacies();
1736 while ($prow = sqlFetchArray($pres)) {
1737 $key = $prow['id'];
1738 if ($currvalue == $key) {
1739 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1740 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1741 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1746 // squads
1747 else if ($data_type == 13) {
1748 $squads = acl_get_squads();
1749 if ($squads) {
1750 foreach ($squads as $key => $value) {
1751 if ($currvalue == $key) {
1752 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1758 // address book
1759 else if ($data_type == 14) {
1760 $urow = sqlQuery("SELECT fname, lname, specialty, organization FROM users " .
1761 "WHERE id = ?", array($currvalue));
1762 //ViSolve: To display the Organization Name if it exist. Else it will display the user name.
1763 if($urow['organization'] !=""){
1764 $uname = $urow['organization'];
1765 }else{
1766 $uname = $urow['lname'];
1767 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1769 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1772 // billing code
1773 else if ($data_type == 15) {
1774 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1777 // insurance company list
1778 else if ($data_type == 16) {
1779 $insprovs = getInsuranceProviders();
1780 foreach ($insprovs as $key => $ipname) {
1781 if ($currvalue == $key) {
1782 $s .= htmlspecialchars($ipname, ENT_NOQUOTES);
1787 // issue types
1788 else if ($data_type == 17) {
1789 foreach ($ISSUE_TYPES as $key => $value) {
1790 if ($currvalue == $key) {
1791 $s .= htmlspecialchars($value[1], ENT_NOQUOTES);
1796 // visit category
1797 else if ($data_type == 18) {
1798 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
1799 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
1800 array($currvalue));
1801 $s = htmlspecialchars($crow['pc_catname'],ENT_NOQUOTES);
1804 // a set of labeled checkboxes
1805 else if ($data_type == 21) {
1806 $avalue = explode('|', $currvalue);
1807 $lres = sqlStatement("SELECT * FROM list_options " .
1808 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1809 $count = 0;
1810 while ($lrow = sqlFetchArray($lres)) {
1811 $option_id = $lrow['option_id'];
1812 if (in_array($option_id, $avalue)) {
1813 if ($count++) $s .= "<br />";
1815 // Added 5-09 by BM - Translate label if applicable
1816 $s .= nl2br(htmlspecialchars(xl_list_label($lrow['title'])),ENT_NOQUOTES);
1822 // a set of labeled text input fields
1823 else if ($data_type == 22) {
1824 $tmp = explode('|', $currvalue);
1825 $avalue = array();
1826 foreach ($tmp as $value) {
1827 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1828 $avalue[$matches[1]] = $matches[2];
1831 $lres = sqlStatement("SELECT * FROM list_options " .
1832 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1833 $s .= "<table cellpadding='0' cellspacing='0'>";
1834 while ($lrow = sqlFetchArray($lres)) {
1835 $option_id = $lrow['option_id'];
1836 if (empty($avalue[$option_id])) continue;
1838 // Added 5-09 by BM - Translate label if applicable
1839 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1841 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1843 $s .= "</table>";
1846 // a set of exam results; 3 radio buttons and a text field:
1847 else if ($data_type == 23) {
1848 $tmp = explode('|', $currvalue);
1849 $avalue = array();
1850 foreach ($tmp as $value) {
1851 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1852 $avalue[$matches[1]] = $matches[2];
1855 $lres = sqlStatement("SELECT * FROM list_options " .
1856 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1857 $s .= "<table cellpadding='0' cellspacing='0'>";
1858 while ($lrow = sqlFetchArray($lres)) {
1859 $option_id = $lrow['option_id'];
1860 $restype = substr($avalue[$option_id], 0, 1);
1861 $resnote = substr($avalue[$option_id], 2);
1862 if (empty($restype) && empty($resnote)) continue;
1864 // Added 5-09 by BM - Translate label if applicable
1865 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1867 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1868 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1869 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1870 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1871 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1872 $s .= "</tr>";
1874 $s .= "</table>";
1877 // the list of active allergies for the current patient
1878 else if ($data_type == 24) {
1879 $query = "SELECT title, comments FROM lists WHERE " .
1880 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1881 "ORDER BY begdate";
1882 // echo "<!-- $query -->\n"; // debugging
1883 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1884 $count = 0;
1885 while ($lrow = sqlFetchArray($lres)) {
1886 if ($count++) $s .= "<br />";
1887 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1888 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1892 // a set of labeled checkboxes, each with a text field:
1893 else if ($data_type == 25) {
1894 $tmp = explode('|', $currvalue);
1895 $avalue = array();
1896 foreach ($tmp as $value) {
1897 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1898 $avalue[$matches[1]] = $matches[2];
1901 $lres = sqlStatement("SELECT * FROM list_options " .
1902 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1903 $s .= "<table cellpadding='0' cellspacing='0'>";
1904 while ($lrow = sqlFetchArray($lres)) {
1905 $option_id = $lrow['option_id'];
1906 $restype = substr($avalue[$option_id], 0, 1);
1907 $resnote = substr($avalue[$option_id], 2);
1908 if (empty($restype) && empty($resnote)) continue;
1910 // Added 5-09 by BM - Translate label if applicable
1911 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1913 $restype = $restype ? xl('Yes') : xl('No');
1914 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1915 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1916 $s .= "</tr>";
1918 $s .= "</table>";
1921 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1922 // VicarePlus :: A selection list for smoking status.
1923 else if ($data_type == 28 || $data_type == 32) {
1924 $tmp = explode('|', $currvalue);
1925 switch(count($tmp)) {
1926 case "4": {
1927 $resnote = $tmp[0];
1928 $restype = $tmp[1];
1929 $resdate = $tmp[2];
1930 $reslist = $tmp[3];
1931 } break;
1932 case "3": {
1933 $resnote = $tmp[0];
1934 $restype = $tmp[1];
1935 $resdate = $tmp[2];
1936 } break;
1937 case "2": {
1938 $resnote = $tmp[0];
1939 $restype = $tmp[1];
1940 $resdate = "";
1941 } break;
1942 case "1": {
1943 $resnote = $tmp[0];
1944 $resdate = $restype = "";
1945 } break;
1946 default: {
1947 $restype = $resdate = $resnote = "";
1948 } break;
1950 $s .= "<table cellpadding='0' cellspacing='0'>";
1952 $s .= "<tr>";
1953 $res = "";
1954 if ($restype == "current".$field_id) $res = xl('Current');
1955 if ($restype == "quit".$field_id) $res = xl('Quit');
1956 if ($restype == "never".$field_id) $res = xl('Never');
1957 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1958 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1959 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1960 if ($data_type == 28)
1962 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1964 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1965 else if ($data_type == 32)
1966 {//changes on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
1967 $smoke_codes = getSmokeCodes();
1968 if (!empty($reslist)) {
1969 if($smoke_codes[$reslist]!="")
1970 $code_desc = "( ".$smoke_codes[$reslist]." )";
1972 $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . "&nbsp;".text($code_desc)."&nbsp;&nbsp;&nbsp;&nbsp;</td>";}
1974 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1977 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1978 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1979 $s .= "</tr>";
1980 $s .= "</table>";
1983 // static text. read-only, of course.
1984 else if ($data_type == 31) {
1985 $s .= nl2br($frow['description']);
1988 else if($data_type == 34){
1989 $arr = explode("|*|*|*|",$currvalue);
1990 for($i=0;$i<sizeof($arr);$i++){
1991 $s.=$arr[$i];
1995 // facility
1996 else if ($data_type == 35) {
1997 $urow = sqlQuery("SELECT id, name FROM facility ".
1998 "WHERE id = ?", array($currvalue) );
1999 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
2002 // Multi select
2003 // Supports backup lists
2004 else if ($data_type == 36) {
2005 $values_array = explode("|", $currvalue);
2006 $i = 0;
2007 foreach($values_array as $value) {
2008 $lrow = sqlQuery("SELECT title FROM list_options " .
2009 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
2010 if ($lrow == 0 && !empty($backup_list)) {
2011 //use back up list
2012 $lrow = sqlQuery("SELECT title FROM list_options " .
2013 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
2015 if ($i > 0) {
2016 $s = $s . ", " . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2017 } else {
2018 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
2020 $i++;
2024 // Image from canvas drawing
2025 else if ($data_type == 40) {
2026 $s .= "<img src='" . attr($currvalue) . "'>";
2029 return $s;
2032 // Generate plain text versions of selected LBF field types.
2033 // Currently used by interface/patient_file/download_template.php.
2034 // More field types might need to be supported here in the future.
2036 function generate_plaintext_field($frow, $currvalue) {
2037 global $ISSUE_TYPES;
2039 $data_type = $frow['data_type'];
2040 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
2041 $list_id = $frow['list_id'];
2042 $backup_list = $frow['backup_list'];
2043 $s = '';
2045 // generic selection list or the generic selection list with add on the fly
2046 // feature, or radio buttons
2047 // Supports backup lists (for datatypes 1,26,33)
2048 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
2049 $lrow = sqlQuery("SELECT title FROM list_options " .
2050 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
2051 $s = xl_list_label($lrow['title']);
2052 //if there is no matching value in the corresponding lists check backup list
2053 // only supported in data types 1,26,33
2054 if ($lrow == 0 && !empty($backup_list) && ($data_type == 1 || $data_type == 26 || $data_type == 33)) {
2055 $lrow = sqlQuery("SELECT title FROM list_options " .
2056 "WHERE list_id = ? AND option_id = ?", array($backup_list,$currvalue) );
2057 $s = xl_list_label($lrow['title']);
2061 // simple or long text field
2062 else if ($data_type == 2 || $data_type == 3 || $data_type == 15) {
2063 $s = $currvalue;
2066 // date
2067 else if ($data_type == 4) {
2068 $s = oeFormatShortDate($currvalue);
2069 // Optional display of age or gestational age.
2070 $asof=''; //not used here, but set to prevent a php warning when call optionalAge
2071 $tmp = optionalAge($frow, $currvalue,$asof);
2072 if ($tmp) $s .= ' ' . $tmp;
2075 // provider
2076 else if ($data_type == 10 || $data_type == 11) {
2077 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2078 "WHERE id = ?", array($currvalue) );
2079 $s = ucwords($urow['fname'] . " " . $urow['lname']);
2082 // pharmacy list
2083 else if ($data_type == 12) {
2084 $pres = get_pharmacies();
2085 while ($prow = sqlFetchArray($pres)) {
2086 $key = $prow['id'];
2087 if ($currvalue == $key) {
2088 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
2089 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
2090 $prow['line1'] . ' / ' . $prow['city'];
2095 // address book
2096 else if ($data_type == 14) {
2097 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
2098 "WHERE id = ?", array($currvalue));
2099 $uname = $urow['lname'];
2100 if ($urow['fname']) $uname .= ", " . $urow['fname'];
2101 $s = $uname;
2104 // insurance company list
2105 else if ($data_type == 16) {
2106 $insprovs = getInsuranceProviders();
2107 foreach ($insprovs as $key => $ipname) {
2108 if ($currvalue == $key) {
2109 $s .= $ipname;
2114 // issue type
2115 else if ($data_type == 17) {
2116 foreach ($ISSUE_TYPES as $key => $value) {
2117 if ($currvalue == $key) {
2118 $s .= $value[1];
2123 // visit category
2124 else if ($data_type == 18) {
2125 $crow = sqlQuery("SELECT pc_catid, pc_catname " .
2126 "FROM openemr_postcalendar_categories WHERE pc_catid = ?",
2127 array($currvalue));
2128 $s = $crow['pc_catname'];
2131 // a set of labeled checkboxes
2132 else if ($data_type == 21) {
2133 $avalue = explode('|', $currvalue);
2134 $lres = sqlStatement("SELECT * FROM list_options " .
2135 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2136 $count = 0;
2137 while ($lrow = sqlFetchArray($lres)) {
2138 $option_id = $lrow['option_id'];
2139 if (in_array($option_id, $avalue)) {
2140 if ($count++) $s .= "; ";
2141 $s .= xl_list_label($lrow['title']);
2146 // a set of labeled text input fields
2147 else if ($data_type == 22) {
2148 $tmp = explode('|', $currvalue);
2149 $avalue = array();
2150 foreach ($tmp as $value) {
2151 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2152 $avalue[$matches[1]] = $matches[2];
2155 $lres = sqlStatement("SELECT * FROM list_options " .
2156 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2157 while ($lrow = sqlFetchArray($lres)) {
2158 $option_id = $lrow['option_id'];
2159 if (empty($avalue[$option_id])) continue;
2160 if ($s !== '') $s .= '; ';
2161 $s .= xl_list_label($lrow['title']) . ': ';
2162 $s .= $avalue[$option_id];
2166 // A set of exam results; 3 radio buttons and a text field.
2167 // This shows abnormal results only.
2168 else if ($data_type == 23) {
2169 $tmp = explode('|', $currvalue);
2170 $avalue = array();
2171 foreach ($tmp as $value) {
2172 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2173 $avalue[$matches[1]] = $matches[2];
2176 $lres = sqlStatement("SELECT * FROM list_options " .
2177 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
2178 while ($lrow = sqlFetchArray($lres)) {
2179 $option_id = $lrow['option_id'];
2180 $restype = substr($avalue[$option_id], 0, 1);
2181 $resnote = substr($avalue[$option_id], 2);
2182 if (empty($restype) && empty($resnote)) continue;
2183 if ($restype != '2') continue; // show abnormal results only
2184 if ($s !== '') $s .= '; ';
2185 $s .= xl_list_label($lrow['title']);
2186 if (!empty($resnote)) $s .= ': ' . $resnote;
2190 // the list of active allergies for the current patient
2191 else if ($data_type == 24) {
2192 $query = "SELECT title, comments FROM lists WHERE " .
2193 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
2194 "ORDER BY begdate";
2195 $lres = sqlStatement($query, array($GLOBALS['pid']));
2196 $count = 0;
2197 while ($lrow = sqlFetchArray($lres)) {
2198 if ($count++) $s .= "; ";
2199 $s .= $lrow['title'];
2200 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
2204 // a set of labeled checkboxes, each with a text field:
2205 else if ($data_type == 25) {
2206 $tmp = explode('|', $currvalue);
2207 $avalue = array();
2208 foreach ($tmp as $value) {
2209 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
2210 $avalue[$matches[1]] = $matches[2];
2213 $lres = sqlStatement("SELECT * FROM list_options " .
2214 "WHERE list_id = ? ORDER BY seq, title", array($list_id));
2215 while ($lrow = sqlFetchArray($lres)) {
2216 $option_id = $lrow['option_id'];
2217 $restype = substr($avalue[$option_id], 0, 1);
2218 $resnote = substr($avalue[$option_id], 2);
2219 if (empty($restype) && empty($resnote)) continue;
2220 if ($s !== '') $s .= '; ';
2221 $s .= xl_list_label($lrow['title']);
2222 $restype = $restype ? xl('Yes') : xl('No');
2223 $s .= $restype;
2224 if ($resnote) $s .= ' ' . $resnote;
2228 // special case for history of lifestyle status; 3 radio buttons and a date text field:
2229 // VicarePlus :: A selection list for smoking status.
2230 else if ($data_type == 28 || $data_type == 32) {
2231 $tmp = explode('|', $currvalue);
2232 $resnote = count($tmp) > 0 ? $tmp[0] : '';
2233 $restype = count($tmp) > 1 ? $tmp[1] : '';
2234 $resdate = count($tmp) > 2 ? $tmp[2] : '';
2235 $reslist = count($tmp) > 3 ? $tmp[3] : '';
2236 $res = "";
2237 if ($restype == "current" . $field_id) $res = xl('Current');
2238 if ($restype == "quit" . $field_id) $res = xl('Quit');
2239 if ($restype == "never" . $field_id) $res = xl('Never');
2240 if ($restype == "not_applicable". $field_id) $res = xl('N/A');
2242 if ($data_type == 28) {
2243 if (!empty($resnote)) $s .= $resnote;
2245 // Tobacco field has a listbox, text box, date field and 3 radio buttons.
2246 else if ($data_type == 32) {
2247 if (!empty($reslist)) $s .= generate_plaintext_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
2248 if (!empty($resnote)) $s .= ' ' . $resnote;
2250 if (!empty($res)) {
2251 if ($s !== '') $s .= ' ';
2252 $s .= xl('Status') . ' ' . $res;
2254 if ($restype == "quit".$field_id) {
2255 if ($s !== '') $s .= ' ';
2256 $s .= $resdate;
2260 // Multi select
2261 // Supports backup lists
2262 else if ($data_type == 36) {
2263 $values_array = explode("|", $currvalue);
2265 $i = 0;
2266 foreach($values_array as $value) {
2267 $lrow = sqlQuery("SELECT title FROM list_options " .
2268 "WHERE list_id = ? AND option_id = ?", array($list_id,$value) );
2270 if ($lrow == 0 && !empty($backup_list)) {
2271 //use back up list
2272 $lrow = sqlQuery("SELECT title FROM list_options " .
2273 "WHERE list_id = ? AND option_id = ?", array($backup_list,$value) );
2276 if ($i > 0) {
2277 $s = $s . ", " . xl_list_label($lrow['title']);
2278 } else {
2279 $s = xl_list_label($lrow['title']);
2282 $i++;
2286 return $s;
2289 $CPR = 4; // cells per row of generic data
2290 $last_group = '';
2291 $cell_count = 0;
2292 $item_count = 0;
2294 function disp_end_cell() {
2295 global $item_count, $cell_count;
2296 if ($item_count > 0) {
2297 echo "</td>";
2298 $item_count = 0;
2302 function disp_end_row() {
2303 global $cell_count, $CPR;
2304 disp_end_cell();
2305 if ($cell_count > 0) {
2306 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
2307 echo "</tr>\n";
2308 $cell_count = 0;
2312 function disp_end_group() {
2313 global $last_group;
2314 if (strlen($last_group) > 0) {
2315 disp_end_row();
2319 function display_layout_rows($formtype, $result1, $result2='') {
2320 global $item_count, $cell_count, $last_group, $CPR;
2322 $fres = sqlStatement("SELECT * FROM layout_options " .
2323 "WHERE form_id = ? AND uor > 0 " .
2324 "ORDER BY group_name, seq", array($formtype) );
2326 while ($frow = sqlFetchArray($fres)) {
2327 $this_group = $frow['group_name'];
2328 $titlecols = $frow['titlecols'];
2329 $datacols = $frow['datacols'];
2330 $data_type = $frow['data_type'];
2331 $field_id = $frow['field_id'];
2332 $list_id = $frow['list_id'];
2333 $currvalue = '';
2335 if ($formtype == 'DEM') {
2336 if (strpos($field_id, 'em_') === 0) {
2337 // Skip employer related fields, if it's disabled.
2338 if ($GLOBALS['omit_employers']) continue;
2339 $tmp = substr($field_id, 3);
2340 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2342 else {
2343 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2346 else {
2347 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2350 // Handle a data category (group) change.
2351 if (strcmp($this_group, $last_group) != 0) {
2352 $group_name = substr($this_group, 1);
2353 // totally skip generating the employer category, if it's disabled.
2354 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2355 disp_end_group();
2356 $last_group = $this_group;
2359 // filter out all the empty field data from the patient report.
2360 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
2361 // Handle starting of a new row.
2362 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2363 disp_end_row();
2364 echo "<tr>";
2365 if ($group_name) {
2366 echo "<td class='groupname'>";
2367 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
2368 //echo "<font color='#008800'>$group_name</font>";
2370 // Added 5-09 by BM - Translate label if applicable
2371 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
2373 $group_name = '';
2374 } else {
2375 //echo "<td class='' style='padding-right:5pt' valign='top'>";
2376 echo "<td valign='top'>&nbsp;";
2378 echo "</td>";
2381 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
2383 // Handle starting of a new label cell.
2384 if ($titlecols > 0) {
2385 disp_end_cell();
2386 //echo "<td class='label' colspan='$titlecols' valign='top'";
2387 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2388 echo "<td class='label' colspan='$titlecols_esc' ";
2389 //if ($cell_count == 2) echo " style='padding-left:10pt'";
2390 echo ">";
2391 $cell_count += $titlecols;
2393 ++$item_count;
2395 // Added 5-09 by BM - Translate label if applicable
2396 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2398 // Handle starting of a new data cell.
2399 if ($datacols > 0) {
2400 disp_end_cell();
2401 //echo "<td class='text data' colspan='$datacols' valign='top'";
2402 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2403 echo "<td class='text data' colspan='$datacols_esc'";
2404 //if ($cell_count > 0) echo " style='padding-left:5pt'";
2405 echo ">";
2406 $cell_count += $datacols;
2409 ++$item_count;
2410 echo generate_display_field($frow, $currvalue);
2414 disp_end_group();
2417 function display_layout_tabs($formtype, $result1, $result2='') {
2418 global $item_count, $cell_count, $last_group, $CPR;
2420 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2421 "WHERE form_id = ? AND uor > 0 " .
2422 "ORDER BY group_name, seq", array($formtype) );
2424 $first = true;
2425 while ($frow = sqlFetchArray($fres)) {
2426 $this_group = $frow['group_name'];
2427 $group_name = substr($this_group, 1);
2428 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2430 <li <?php echo $first ? 'class="current"' : '' ?>>
2431 <a href="#" id="header_tab_<?php echo str_replace(" ", "_",htmlspecialchars($group_name,ENT_QUOTES))?>">
2432 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
2433 </li>
2434 <?php
2435 $first = false;
2439 function display_layout_tabs_data($formtype, $result1, $result2='') {
2440 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2442 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2443 "WHERE form_id = ? AND uor > 0 " .
2444 "ORDER BY group_name, seq", array($formtype));
2446 $first = true;
2447 while ($frow = sqlFetchArray($fres)) {
2448 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
2449 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
2450 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
2451 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
2452 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
2453 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
2454 $currvalue = '';
2456 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2458 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2459 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2460 "ORDER BY seq", array($formtype, $this_group) );
2463 <div class="tab <?php echo $first ? 'current' : '' ?>">
2464 <table border='0' cellpadding='0'>
2466 <?php
2467 while ($group_fields = sqlFetchArray($group_fields_query)) {
2469 $titlecols = $group_fields['titlecols'];
2470 $datacols = $group_fields['datacols'];
2471 $data_type = $group_fields['data_type'];
2472 $field_id = $group_fields['field_id'];
2473 $list_id = $group_fields['list_id'];
2474 $currvalue = '';
2475 $condition_str = get_conditions_str($condition_str,$group_fields);
2478 if ($formtype == 'DEM') {
2479 if (strpos($field_id, 'em_') === 0) {
2480 // Skip employer related fields, if it's disabled.
2481 if ($GLOBALS['omit_employers']) continue;
2482 $tmp = substr($field_id, 3);
2483 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2485 else {
2486 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2489 else {
2490 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2493 // Handle a data category (group) change.
2494 if (strcmp($this_group, $last_group) != 0) {
2495 $group_name = substr($this_group, 1);
2496 // totally skip generating the employer category, if it's disabled.
2497 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2498 $last_group = $this_group;
2501 // Handle starting of a new row.
2502 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2503 disp_end_row();
2504 echo "<tr>";
2507 if ($item_count == 0 && $titlecols == 0) {
2508 $titlecols = 1;
2511 // Handle starting of a new label cell.
2512 if ($titlecols > 0) {
2513 disp_end_cell();
2514 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2515 $field_id_label = 'label_'.$group_fields['field_id'];
2516 echo "<td class='label' colspan='$titlecols_esc' id='$field_id_label'";
2517 echo ">";
2518 $cell_count += $titlecols;
2520 ++$item_count;
2522 $field_id_label = 'label_'.$group_fields['field_id'];
2523 echo "<span id='".$field_id_label."'>";
2524 // Added 5-09 by BM - Translate label if applicable
2525 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
2526 echo "</span>";
2528 // Handle starting of a new data cell.
2529 if ($datacols > 0) {
2530 disp_end_cell();
2531 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2532 $field_id = 'text_'.$group_fields['field_id'];
2533 echo "<td class='text data' colspan='$datacols_esc' id='$field_id' data-value='$currvalue'";
2534 echo ">";
2535 $cell_count += $datacols;
2536 } else {
2537 $field_id = 'text_'.$group_fields['field_id'];
2538 echo "<span id='".$field_id."' style='display:none'>$currvalue</span>";
2541 ++$item_count;
2542 echo generate_display_field($group_fields, $currvalue);
2545 disp_end_row();
2548 </table>
2549 </div>
2551 <?php
2553 $first = false;
2559 function get_conditions_str($condition_str,$frow){
2560 $conditions = empty($frow['conditions']) ? array() : unserialize($frow['conditions']);
2561 foreach ($conditions as $condition) {
2562 if (empty($condition['id'])) continue;
2563 $andor = empty($condition['andor']) ? '' : $condition['andor'];
2564 if ($condition_str) $condition_str .= ",\n";
2565 $condition_str .= "{" .
2566 "target:'" . addslashes($frow['field_id']) . "', " .
2567 "id:'" . addslashes($condition['id']) . "', " .
2568 "itemid:'" . addslashes($condition['itemid']) . "', " .
2569 "operator:'" . addslashes($condition['operator']) . "', " .
2570 "value:'" . addslashes($condition['value']) . "', " .
2571 "andor:'" . addslashes($andor) . "'}";
2573 return $condition_str;
2575 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
2576 global $item_count, $cell_count, $last_group, $CPR,$condition_str;
2578 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
2579 "WHERE form_id = ? AND uor > 0 " .
2580 "ORDER BY group_name, seq", array($formtype) );
2582 $first = true;
2583 while ($frow = sqlFetchArray($fres)) {
2584 $this_group = $frow['group_name'];
2585 $group_name = substr($this_group, 1);
2586 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
2587 $titlecols = $frow['titlecols'];
2588 $datacols = $frow['datacols'];
2589 $data_type = $frow['data_type'];
2590 $field_id = $frow['field_id'];
2591 $list_id = $frow['list_id'];
2592 $currvalue = '';
2594 if (substr($this_group,1,8) === 'Employer' && $GLOBALS['omit_employers']) continue;
2596 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
2597 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
2598 "ORDER BY seq", array($formtype,$this_group) );
2601 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo str_replace(' ', '_',$group_name_esc)?>" >
2602 <table border='0' cellpadding='0'>
2604 <?php
2605 while ($group_fields = sqlFetchArray($group_fields_query)) {
2607 $titlecols = $group_fields['titlecols'];
2608 $datacols = $group_fields['datacols'];
2609 $data_type = $group_fields['data_type'];
2610 $field_id = $group_fields['field_id'];
2611 $list_id = $group_fields['list_id'];
2612 $backup_list = $group_fields['list_backup_id'];
2613 $condition_str = get_conditions_str($condition_str,$group_fields);
2614 $currvalue = '';
2616 if ($formtype == 'DEM') {
2617 if (strpos($field_id, 'em_') === 0) {
2618 // Skip employer related fields, if it's disabled.
2619 if ($GLOBALS['omit_employers']) continue;
2620 $tmp = substr($field_id, 3);
2621 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
2623 else {
2624 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2627 else {
2628 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
2631 // Handle a data category (group) change.
2632 if (strcmp($this_group, $last_group) != 0) {
2633 $group_name = substr($this_group, 1);
2634 // totally skip generating the employer category, if it's disabled.
2635 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
2636 $last_group = $this_group;
2639 // Handle starting of a new row.
2640 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
2641 disp_end_row();
2642 echo "<tr>";
2645 if ($item_count == 0 && $titlecols == 0) {
2646 $titlecols = 1;
2649 // Handle starting of a new label cell.
2650 if ($titlecols > 0) {
2651 disp_end_cell();
2652 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
2653 $field_id_label = 'label_'.$group_fields['field_id'];
2654 echo "<td class='label' colspan='$titlecols_esc' id='$field_id_label' ";
2655 echo ">";
2656 $cell_count += $titlecols;
2658 ++$item_count;
2660 // Added 5-09 by BM - Translate label if applicable
2661 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
2663 // Handle starting of a new data cell.
2664 if ($datacols > 0) {
2665 disp_end_cell();
2666 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
2667 $field_id = 'text_'.$group_fields['field_id'];
2668 echo "<td class='text data' colspan='$datacols_esc' id='$field_id'";
2669 echo ">";
2670 $cell_count += $datacols;
2673 ++$item_count;
2675 echo generate_form_field($group_fields, $currvalue);
2679 </table>
2680 </div>
2682 <?php
2684 $first = false;
2689 // From the currently posted HTML form, this gets the value of the
2690 // field corresponding to the provided layout_options table row.
2692 function get_layout_form_value($frow, $prefix='form_') {
2693 // Bring in $sanitize_all_escapes variable, which will decide
2694 // the variable escaping method.
2695 global $sanitize_all_escapes;
2697 $maxlength = empty($frow['max_length']) ? 0 : intval($frow['max_length']);
2698 $data_type = $frow['data_type'];
2699 $field_id = $frow['field_id'];
2700 $value = '';
2701 if (isset($_POST["$prefix$field_id"])) {
2702 if ($data_type == 21) {
2703 // $_POST["$prefix$field_id"] is an array of checkboxes and its keys
2704 // must be concatenated into a |-separated string.
2705 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2706 if (strlen($value)) $value .= '|';
2707 $value .= $key;
2710 else if ($data_type == 22) {
2711 // $_POST["$prefix$field_id"] is an array of text fields to be imploded
2712 // into "key:value|key:value|...".
2713 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2714 $val = str_replace('|', ' ', $val);
2715 if (strlen($value)) $value .= '|';
2716 $value .= "$key:$val";
2719 else if ($data_type == 23) {
2720 // $_POST["$prefix$field_id"] is an array of text fields with companion
2721 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
2722 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2723 $restype = $_POST["radio_{$field_id}"][$key];
2724 if (empty($restype)) $restype = '0';
2725 $val = str_replace('|', ' ', $val);
2726 if (strlen($value)) $value .= '|';
2727 $value .= "$key:$restype:$val";
2730 else if ($data_type == 25) {
2731 // $_POST["$prefix$field_id"] is an array of text fields with companion
2732 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
2733 foreach ($_POST["$prefix$field_id"] as $key => $val) {
2734 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
2735 $val = str_replace('|', ' ', $val);
2736 if (strlen($value)) $value .= '|';
2737 $value .= "$key:$restype:$val";
2740 else if ($data_type == 28 || $data_type == 32) {
2741 // $_POST["$prefix$field_id"] is an date text fields with companion
2742 // radio buttons to be imploded into "notes|type|date".
2743 $restype = $_POST["radio_{$field_id}"];
2744 if (empty($restype)) $restype = '0';
2745 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
2746 $resnote = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2747 if ($data_type == 32)
2749 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
2750 $reslist = str_replace('|', ' ', $_POST["$prefix$field_id"]);
2751 $res_text_note = str_replace('|', ' ', $_POST["{$prefix}text_$field_id"]);
2752 $value = "$res_text_note|$restype|$resdate|$reslist";
2754 else
2755 $value = "$resnote|$restype|$resdate";
2757 else if ($data_type == 36) {
2758 $value_array = $_POST["form_$field_id"];
2759 $i = 0;
2760 foreach ($value_array as $key => $valueofkey) {
2761 if ($i == 0) {
2762 $value = $valueofkey;
2763 } else {
2764 $value = $value . "|" . $valueofkey;
2766 $i++;
2769 else {
2770 $value = $_POST["$prefix$field_id"];
2774 // Better to die than to silently truncate data!
2775 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2776 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2777 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2779 // Make sure the return value is quote-safe.
2780 if ($sanitize_all_escapes) {
2781 //escapes already removed and using binding/placemarks in sql calls
2782 // so only need to trim value
2783 return trim($value);
2785 else {
2786 //need to explicitly prepare value
2787 return formTrim($value);
2791 // Generate JavaScript validation logic for the required fields.
2793 function generate_layout_validation($form_id) {
2794 $fres = sqlStatement("SELECT * FROM layout_options " .
2795 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2796 "ORDER BY group_name, seq", array($form_id) );
2798 while ($frow = sqlFetchArray($fres)) {
2799 $data_type = $frow['data_type'];
2800 $field_id = $frow['field_id'];
2801 $fldtitle = $frow['title'];
2802 if (!$fldtitle) $fldtitle = $frow['description'];
2803 $fldname = htmlspecialchars("form_$field_id", ENT_QUOTES);
2805 if ($data_type == 40) {
2806 $fldid = addslashes("form_$field_id");
2807 // Move canvas image data to its hidden form field so the server will get it.
2808 echo
2809 " var canfld = f['$fldid'];\n" .
2810 " if (canfld) canfld.value = lbfCanvasGetData('$fldid');\n";
2811 continue;
2814 if ($frow['uor'] < 2) continue;
2816 switch($data_type) {
2817 case 1:
2818 case 11:
2819 case 12:
2820 case 13:
2821 case 14:
2822 case 26:
2823 case 33:
2824 echo
2825 " if (f.$fldname.selectedIndex <= 0) {\n" .
2826 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2827 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2828 " }\n";
2829 break;
2830 case 27: // radio buttons
2831 echo
2832 " var i = 0;\n" .
2833 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2834 " if (i >= f.$fldname.length) {\n" .
2835 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2836 " }\n";
2837 break;
2838 case 2:
2839 case 3:
2840 case 4:
2841 case 15:
2842 echo
2843 " if (trimlen(f.$fldname.value) == 0) {\n" .
2844 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2845 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2846 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2847 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2848 " } else { " .
2849 " $('#" . $fldname . "').attr('style',''); " .
2850 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2851 " } \n";
2852 break;
2853 case 36: // multi select
2854 echo
2855 " var multi_select=f['$fldname"."[]']; \n " .
2856 " var multi_choice_made=false; \n".
2857 " for (var options_index=0; options_index < multi_select.length; options_index++) { ".
2858 " multi_choice_made=multi_choice_made || multi_select.options[options_index].selected; \n".
2859 " } \n" .
2860 " if(!multi_choice_made)
2861 errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
2863 break;
2869 * DROPDOWN FOR FACILITIES
2871 * build a dropdown with all facilities
2873 * @param string $selected - name of the currently selected facility
2874 * use '0' for "unspecified facility"
2875 * use '' for "All facilities" (the default)
2876 * @param string $name - the name/id for select form (defaults to "form_facility")
2877 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2878 * defaults to true
2879 * @return void - just echo the html encoded string
2881 * Note: This should become a data-type at some point, according to Brady
2883 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true,
2884 $allow_allfacilities = true, $disabled='', $onchange='')
2886 $have_selected = false;
2887 $query = "SELECT id, name FROM facility ORDER BY name";
2888 $fres = sqlStatement($query);
2890 $name = htmlspecialchars($name, ENT_QUOTES);
2891 echo " <select name='$name' id='$name'";
2892 if ($onchange) echo " onchange='$onchange'";
2893 echo " $disabled>\n";
2895 if ($allow_allfacilities) {
2896 $option_value = '';
2897 $option_selected_attr = '';
2898 if ($selected == '') {
2899 $option_selected_attr = ' selected="selected"';
2900 $have_selected = true;
2902 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2903 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2904 } elseif ($allow_unspecified) {
2905 $option_value = '0';
2906 $option_selected_attr = '';
2907 if ( $selected == '0' ) {
2908 $option_selected_attr = ' selected="selected"';
2909 $have_selected = true;
2911 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2912 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2915 while ($frow = sqlFetchArray($fres)) {
2916 $facility_id = $frow['id'];
2917 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2918 $option_selected_attr = '';
2919 if ($selected == $facility_id) {
2920 $option_selected_attr = ' selected="selected"';
2921 $have_selected = true;
2923 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2924 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2927 if ($allow_unspecified && $allow_allfacilities) {
2928 $option_value = '0';
2929 $option_selected_attr = '';
2930 if ( $selected == '0' ) {
2931 $option_selected_attr = ' selected="selected"';
2932 $have_selected = true;
2934 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2935 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2938 if (!$have_selected) {
2939 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2940 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2941 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2942 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2944 echo " </select>\n";
2947 // Expand Collapse Widget
2948 // This forms the header and functionality component of the widget. The information that is displayed
2949 // then follows this function followed by a closing div tag
2951 // $title is the title of the section (already translated)
2952 // $label is identifier used in the tag id's and sql columns
2953 // $buttonLabel is the button label text (already translated)
2954 // $buttonLink is the button link information
2955 // $buttonClass is any additional needed class elements for the button tag
2956 // $linkMethod is the button link method ('javascript' vs 'html')
2957 // $bodyClass is to set class(es) of the body
2958 // $auth is a flag to decide whether to show the button
2959 // $fixedWidth is to flag whether width is fixed
2960 // $forceExpandAlways is a flag to force the widget to always be expanded
2962 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2963 if ($fixedWidth) {
2964 echo "<div class='section-header'>";
2966 else {
2967 echo "<div class='section-header-dynamic'>";
2969 echo "<table><tr>";
2970 if ($auth) {
2971 // show button, since authorized
2972 // first prepare class string
2973 if ($buttonClass) {
2974 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2976 else {
2977 $class_string = "css_button_small";
2979 // next, create the link
2980 if ($linkMethod == "javascript") {
2981 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2983 else {
2984 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2985 if (!isset($_SESSION['patient_portal_onsite'])) {
2986 // prevent an error from occuring when calling the function from the patient portal
2987 echo " onclick='top.restoreSession()'";
2990 if (!$GLOBALS['concurrent_layout']) {
2991 echo " target='Main'";
2993 echo "><span>" .
2994 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2996 if ($forceExpandAlways){
2997 // Special case to force the widget to always be expanded
2998 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2999 $indicatorTag ="style='display:none'";
3001 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
3002 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
3003 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
3004 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
3006 if (isset($_SESSION['patient_portal_onsite'])) {
3007 // collapse all entries in the patient portal
3008 $text = xl('expand');
3010 else if (getUserSetting($label."_ps_expand")) {
3011 $text = xl('collapse');
3013 else {
3014 $text = xl('expand');
3016 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
3017 "</span>)</a></td>";
3018 echo "</tr></table>";
3019 echo "</div>";
3020 if ($forceExpandAlways) {
3021 // Special case to force the widget to always be expanded
3022 $styling = "";
3024 else if (isset($_SESSION['patient_portal_onsite'])) {
3025 // collapse all entries in the patient portal
3026 $styling = "style='display:none'";
3028 else if (getUserSetting($label."_ps_expand")) {
3029 $styling = "";
3031 else {
3032 $styling = "style='display:none'";
3034 if ($bodyClass) {
3035 $styling .= " class='" . $bodyClass . "'";
3037 //next, create the first div tag to hold the information
3038 // note the code that calls this function will then place the ending div tag after the data
3039 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
3042 //billing_facility fuction will give the dropdown list which contain billing faciliies.
3043 function billing_facility($name,$select){
3044 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
3045 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
3046 while ($facrow = sqlFetchArray($qsql)) {
3047 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
3048 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
3050 echo "</select>";
3053 // Generic function to get the translated title value for a particular list option.
3055 function getListItemTitle($list, $option) {
3056 $row = sqlQuery("SELECT title FROM list_options WHERE " .
3057 "list_id = ? AND option_id = ?", array($list, $option));
3058 if (empty($row['title'])) return $option;
3059 return xl_list_label($row['title']);
3061 //Added on 5-jun-2k14 (regarding get the smoking code descriptions)
3062 function getSmokeCodes()
3064 $smoking_codes_arr = array();
3065 $smoking_codes = sqlStatement("SELECT option_id,codes FROM list_options WHERE list_id='smoking_status'");
3066 while($codes_row = sqlFetchArray($smoking_codes))
3068 $smoking_codes_arr[$codes_row['option_id']] = $codes_row['codes'];
3070 return $smoking_codes_arr;
3073 // Get the current value for a layout based form field.
3074 // Depending on options this might come from lbf_data, patient_data,
3075 // form_encounter, shared_attributes or elsewhere.
3076 // Returns FALSE if the field ID is invalid (layout error).
3078 function lbf_current_value($frow, $formid, $encounter) {
3079 global $pid;
3080 $formname = $frow['form_id'];
3081 $field_id = $frow['field_id'];
3082 $source = $frow['source'];
3083 $currvalue = '';
3084 $deffname = $formname . '_default_' . $field_id;
3085 if ($source == 'D' || $source == 'H') {
3086 // Get from patient_data, employer_data or history_data.
3087 if ($source == 'H') {
3088 $table = 'history_data';
3089 $orderby = 'ORDER BY date DESC LIMIT 1';
3091 else if (strpos($field_id, 'em_') === 0) {
3092 $field_id = substr($field_id, 3);
3093 $table = 'employer_data';
3094 $orderby = 'ORDER BY date DESC LIMIT 1';
3096 else {
3097 $table = 'patient_data';
3098 $orderby = '';
3100 // It is an error if the field does not exist, but don't crash.
3101 $tmp = sqlQuery("SHOW COLUMNS FROM $table WHERE Field = ?", array($field_id));
3102 if (empty($tmp)) return FALSE;
3103 $pdrow = sqlQuery("SELECT `$field_id` AS field_value FROM $table WHERE pid = ? $orderby", array($pid));
3104 if (isset($pdrow)) $currvalue = $pdrow['field_value'];
3106 else if ($source == 'E') {
3107 if ($encounter) {
3108 // Get value from shared_attributes of the current encounter.
3109 $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " .
3110 "pid = ? AND encounter = ? AND field_id = ?",
3111 array($pid, $encounter, $field_id));
3112 if (isset($sarow)) $currvalue = $sarow['field_value'];
3114 else if ($formid) {
3115 // Get from shared_attributes of the encounter that this form is linked to.
3116 // Note the importance of having an index on forms.form_id.
3117 $sarow = sqlQuery("SELECT sa.field_value " .
3118 "FROM forms AS f, shared_attributes AS sa WHERE " .
3119 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3120 "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?",
3121 array($formid, $formname, $field_id));
3122 if (!empty($sarow)) $currvalue = $sarow['field_value'];
3124 else {
3125 // New form and encounter not available, this should not happen.
3128 else if ($source == 'V') {
3129 if ($encounter) {
3130 // Get value from the current encounter's form_encounter.
3131 $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " .
3132 "pid = ? AND encounter = ?",
3133 array($pid, $encounter));
3134 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3136 else if ($formid) {
3137 // Get value from the form_encounter that this form is linked to.
3138 $ferow = sqlQuery("SELECT fe.* " .
3139 "FROM forms AS f, form_encounter AS fe WHERE " .
3140 "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " .
3141 "fe.pid = f.pid AND fe.encounter = f.encounter",
3142 array($formid, $formname));
3143 if (isset($ferow[$field_id])) $currvalue = $ferow[$field_id];
3145 else {
3146 // New form and encounter not available, this should not happen.
3149 else if ($formid) {
3150 // This is a normal form field.
3151 $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
3152 "form_id = ? AND field_id = ?", array($formid, $field_id) );
3153 if (!empty($ldrow)) $currvalue = $ldrow['field_value'];
3155 else {
3156 // New form, see if there is a custom default from a plugin.
3157 // This logic does not apply to shared attributes because they do not
3158 // have a "new form" concept.
3159 if (function_exists($deffname)) $currvalue = call_user_func($deffname);
3161 return $currvalue;
3164 // This returns stuff that needs to go into the <head> section of a caller using
3165 // the drawable image field type in a form.
3166 // A TRUE argument makes the widget 25% less tall.
3168 function lbf_canvas_head($small=FALSE) {
3169 $s = <<<EOD
3170 <link href="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/css/literallycanvas.css" rel="stylesheet" />
3171 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-with-addons.min.js"></script>
3172 <script src="{$GLOBALS['assets_static_relative']}/react-15-1-0/react-dom.min.js"></script>
3173 <script src="{$GLOBALS['assets_static_relative']}/literallycanvas-0-4-13/js/literallycanvas.min.js"></script>
3174 EOD;
3175 if ($small) $s .= <<<EOD
3176 <style>
3177 /* Custom LiterallyCanvas styling.
3178 * This makes the widget 25% less tall and adjusts some other things accordingly.
3180 .literally {
3181 min-height:292px;min-width:300px; /* Was 400, unspecified */
3183 .literally .lc-picker .toolbar-button {
3184 width:20px;height:20px;line-height:20px; /* Was 26, 26, 26 */
3186 .literally .color-well {
3187 font-size:8px;width:49px; /* Was 10, 60 */
3189 .literally .color-well-color-container {
3190 width:21px;height:21px; /* Was 28, 28 */
3192 .literally .lc-picker {
3193 width:50px; /* Was 61 */
3195 .literally .lc-drawing.with-gui {
3196 left:50px; /* Was 61 */
3198 .literally .lc-options {
3199 left:50px; /* Was 61 */
3201 .literally .color-picker-popup {
3202 left:49px;bottom:0px; /* Was 60, 31 */
3204 </style>
3205 EOD;
3206 return $s;