Nation Notes module contributed by Z&H Healthcare.
[openemr.git] / library / options.inc.php
blob64e2dc22c67ff70bf369039416922a1981c845fd
1 <?php
2 // Copyright (C) 2007-2010 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 // C = Capitalize first letter of each word (text fields)
22 // D = Check for duplicates in New Patient form
23 // G = Graphable (for numeric fields in forms supporting historical data)
24 // H = Read-only field copied from static history
25 // L = Lab Order ("ord_lab") types only (address book)
26 // N = Show in New Patient form
27 // O = Procedure Order ("ord_*") types only (address book)
28 // R = Distributor types only (address book)
29 // U = Capitalize all letters (text fields)
30 // V = Vendor types only (address book)
31 // 1 = Write Once (not editable when not empty) (text fields)
33 require_once("formdata.inc.php");
34 require_once("formatting.inc.php");
35 require_once("user.inc");
37 $date_init = "";
39 function get_pharmacies() {
40 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
41 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
42 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
43 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
44 "AND p.type = 2 " .
45 "ORDER BY name, area_code, prefix, number");
48 // Function to generate a drop-list.
50 function generate_select_list($tag_name, $list_id, $currvalue, $title,
51 $empty_name=' ', $class='', $onchange='', $tag_id = '', $custom_attributes = null )
53 $s = '';
54 $tag_name_esc = htmlspecialchars( $tag_name, ENT_QUOTES);
55 $s .= "<select name='$tag_name_esc'";
56 $tag_id_esc = $tag_name_esc;
57 if ( $tag_id != '' ) {
58 $tag_id_esc = htmlspecialchars( $tag_id, ENT_QUOTES);
60 $s .= " id='$tag_id_esc'";
61 if ($class) $s .= " class='$class'";
62 if ($onchange) $s .= " onchange='$onchange'";
63 if ( $custom_attributes != null && is_array($custom_attributes) ) {
64 foreach ( $custom_attributes as $attr => $val ) {
65 if ( isset($custom_attributes[$attr] ) ) {
66 $s .= " ".htmlspecialchars( $attr, ENT_QUOTES)."='".htmlspecialchars( $val, ENT_QUOTES)."'";
70 $selectTitle = htmlspecialchars( $title, ENT_QUOTES);
71 $s .= " title='$selectTitle'>";
72 $selectEmptyName = htmlspecialchars( xl($empty_name), ENT_NOQUOTES);
73 if ($empty_name) $s .= "<option value=''>" . $selectEmptyName . "</option>";
74 $lres = sqlStatement("SELECT * FROM list_options " .
75 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
76 $got_selected = FALSE;
77 while ($lrow = sqlFetchArray($lres)) {
78 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
79 $s .= "<option value='$optionValue'";
80 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
81 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
83 $s .= " selected";
84 $got_selected = TRUE;
86 $optionLabel = htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
87 $s .= ">$optionLabel</option>\n";
89 if (!$got_selected && strlen($currvalue) > 0) {
90 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
91 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
92 $s .= "</select>";
93 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_QUOTES);
94 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
95 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
97 else {
98 $s .= "</select>";
100 return $s;
103 // $frow is a row from the layout_options table.
104 // $currvalue is the current value, if any, of the associated item.
106 function generate_form_field($frow, $currvalue) {
107 global $rootdir, $date_init;
109 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
111 $data_type = $frow['data_type'];
112 $field_id = $frow['field_id'];
113 $list_id = $frow['list_id'];
114 // escaped variables to use in html
115 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
116 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
118 // Added 5-09 by BM - Translate description if applicable
119 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
121 // added 5-2009 by BM to allow modification of the 'empty' text title field.
122 // Can pass $frow['empty_title'] with this variable, otherwise
123 // will default to 'Unassigned'.
124 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
125 // if make $frow['empty_title'] equal to 'SKIP'
126 $showEmpty = true;
127 if (isset($frow['empty_title'])) {
128 if ($frow['empty_title'] == "SKIP") {
129 //do not display an 'empty' choice
130 $showEmpty = false;
131 $empty_title = "Unassigned";
133 else {
134 $empty_title = $frow['empty_title'];
137 else {
138 $empty_title = "Unassigned";
141 // generic single-selection list
142 if ($data_type == 1) {
143 echo generate_select_list("form_$field_id", $list_id, $currvalue,
144 $description, $showEmpty ? $empty_title : '');
147 // simple text field
148 else if ($data_type == 2) {
149 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
150 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
151 echo "<input type='text'" .
152 " name='form_$field_id_esc'" .
153 " id='form_$field_id_esc'" .
154 " size='$fldlength'" .
155 " maxlength='$maxlength'" .
156 " title='$description'" .
157 " value='$currescaped'";
158 if (strpos($frow['edit_options'], 'C') !== FALSE)
159 echo " onchange='capitalizeMe(this)'";
160 else if (strpos($frow['edit_options'], 'U') !== FALSE)
161 echo " onchange='this.value = this.value.toUpperCase()'";
162 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
163 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
164 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
165 echo " onblur='maskblur(this,\"$tmp\")'";
167 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0)
168 echo " readonly";
169 echo " />";
172 // long or multi-line text field
173 else if ($data_type == 3) {
174 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
175 $textRows = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
176 echo "<textarea" .
177 " name='form_$field_id_esc'" .
178 " id='form_$field_id_esc'" .
179 " title='$description'" .
180 " cols='$textCols'" .
181 " rows='$textRows'>" .
182 $currescaped . "</textarea>";
185 // date
186 else if ($data_type == 4) {
187 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
188 " value='$currescaped'" .
189 " title='$description'" .
190 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
191 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
192 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
193 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
194 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
197 // provider list, local providers only
198 else if ($data_type == 10) {
199 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
200 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
201 "AND authorized = 1 " .
202 "ORDER BY lname, fname");
203 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
204 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
205 while ($urow = sqlFetchArray($ures)) {
206 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
207 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
208 echo "<option value='$optionId'";
209 if ($urow['id'] == $currvalue) echo " selected";
210 echo ">$uname</option>";
212 echo "</select>";
215 // provider list, including address book entries with an NPI number
216 else if ($data_type == 11) {
217 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
218 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
219 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
220 "ORDER BY lname, fname");
221 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
222 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
223 while ($urow = sqlFetchArray($ures)) {
224 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
225 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
226 echo "<option value='$optionId'";
227 if ($urow['id'] == $currvalue) echo " selected";
228 echo ">$uname</option>";
230 echo "</select>";
233 // pharmacy list
234 else if ($data_type == 12) {
235 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
236 echo "<option value='0'></option>";
237 $pres = get_pharmacies();
238 while ($prow = sqlFetchArray($pres)) {
239 $key = $prow['id'];
240 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
241 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
242 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
243 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
244 echo "<option value='$optionValue'";
245 if ($currvalue == $key) echo " selected";
246 echo ">$optionLabel</option>";
248 echo "</select>";
251 // squads
252 else if ($data_type == 13) {
253 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
254 echo "<option value=''>&nbsp;</option>";
255 $squads = acl_get_squads();
256 if ($squads) {
257 foreach ($squads as $key => $value) {
258 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
259 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
260 echo "<option value='$optionValue'";
261 if ($currvalue == $key) echo " selected";
262 echo ">$optionLabel</option>\n";
265 echo "</select>";
268 // Address book, preferring organization name if it exists and is not in
269 // parentheses, and excluding local users who are not providers.
270 // Supports "referred to" practitioners and facilities.
271 // Alternatively the letter L in edit_options means that abook_type
272 // must be "ord_lab", indicating types used with the procedure
273 // lab ordering system.
274 // Alternatively the letter O in edit_options means that abook_type
275 // must begin with "ord_", indicating types used with the procedure
276 // ordering system.
277 // Alternatively the letter V in edit_options means that abook_type
278 // must be "vendor", indicating the Vendor type.
279 // Alternatively the letter R in edit_options means that abook_type
280 // must be "dist", indicating the Distributor type.
281 else if ($data_type == 14) {
282 if (strpos($frow['edit_options'], 'L') !== FALSE)
283 $tmp = "abook_type = 'ord_lab'";
284 else if (strpos($frow['edit_options'], 'O') !== FALSE)
285 $tmp = "abook_type LIKE 'ord\\_%'";
286 else if (strpos($frow['edit_options'], 'V') !== FALSE)
287 $tmp = "abook_type LIKE 'vendor%'";
288 else if (strpos($frow['edit_options'], 'R') !== FALSE)
289 $tmp = "abook_type LIKE 'dist'";
290 else
291 $tmp = "( username = '' OR authorized = 1 )";
292 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
293 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
294 "AND $tmp " .
295 "ORDER BY organization, lname, fname");
296 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
297 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
298 while ($urow = sqlFetchArray($ures)) {
299 $uname = $urow['organization'];
300 if (empty($uname) || substr($uname, 0, 1) == '(') {
301 $uname = $urow['lname'];
302 if ($urow['fname']) $uname .= ", " . $urow['fname'];
304 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
305 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
306 echo "<option value='$optionValue'";
307 $title = $urow['username'] ? xl('Local') : xl('External');
308 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
309 echo " title='$optionTitle'";
310 if ($urow['id'] == $currvalue) echo " selected";
311 echo ">$optionLabel</option>";
313 echo "</select>";
316 // a billing code
317 else if ($data_type == 15) {
318 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
319 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
320 echo "<input type='text'" .
321 " name='form_$field_id_esc'" .
322 " id='form_related_code'" .
323 " size='$fldlength'" .
324 " maxlength='$maxlength'" .
325 " title='$description'" .
326 " value='$currescaped'" .
327 " onclick='sel_related(this)' readonly" .
328 " />";
331 // a set of labeled checkboxes
332 else if ($data_type == 21) {
333 // In this special case, fld_length is the number of columns generated.
334 $cols = max(1, $frow['fld_length']);
335 $avalue = explode('|', $currvalue);
336 $lres = sqlStatement("SELECT * FROM list_options " .
337 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
338 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
339 $tdpct = (int) (100 / $cols);
340 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
341 $option_id = $lrow['option_id'];
342 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
343 // if ($count) echo "<br />";
344 if ($count % $cols == 0) {
345 if ($count) echo "</tr>";
346 echo "<tr>";
348 echo "<td width='$tdpct%'>";
349 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
350 if (in_array($option_id, $avalue)) echo " checked";
352 // Added 5-09 by BM - Translate label if applicable
353 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
355 echo "</td>";
357 if ($count) {
358 echo "</tr>";
359 if ($count > $cols) {
360 // Add some space after multiple rows of checkboxes.
361 $cols = htmlspecialchars( $cols, ENT_QUOTES);
362 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
365 echo "</table>";
368 // a set of labeled text input fields
369 else if ($data_type == 22) {
370 $tmp = explode('|', $currvalue);
371 $avalue = array();
372 foreach ($tmp as $value) {
373 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
374 $avalue[$matches[1]] = $matches[2];
377 $lres = sqlStatement("SELECT * FROM list_options " .
378 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
379 echo "<table cellpadding='0' cellspacing='0'>";
380 while ($lrow = sqlFetchArray($lres)) {
381 $option_id = $lrow['option_id'];
382 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
383 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
384 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
386 // Added 5-09 by BM - Translate label if applicable
387 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
388 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
389 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
390 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
391 echo "<td><input type='text'" .
392 " name='form_{$field_id_esc}[$option_id_esc]'" .
393 " id='form_{$field_id_esc}[$option_id_esc]'" .
394 " size='$fldlength'" .
395 " maxlength='$maxlength'" .
396 " value='$optionValue'";
397 echo " /></td></tr>";
399 echo "</table>";
402 // a set of exam results; 3 radio buttons and a text field:
403 else if ($data_type == 23) {
404 $tmp = explode('|', $currvalue);
405 $avalue = array();
406 foreach ($tmp as $value) {
407 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
408 $avalue[$matches[1]] = $matches[2];
411 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
412 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
413 $lres = sqlStatement("SELECT * FROM list_options " .
414 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
415 echo "<table cellpadding='0' cellspacing='0'>";
416 echo "<tr><td>&nbsp;</td><td class='bold'>" .
417 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
418 "&nbsp;</td><td class='bold'>" .
419 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
420 "<td class='bold'>" .
421 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
422 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
423 while ($lrow = sqlFetchArray($lres)) {
424 $option_id = $lrow['option_id'];
425 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
426 $restype = substr($avalue[$option_id], 0, 1);
427 $resnote = substr($avalue[$option_id], 2);
429 // Added 5-09 by BM - Translate label if applicable
430 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
432 for ($i = 0; $i < 3; ++$i) {
433 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
434 echo "<td><input type='radio'" .
435 " name='radio_{$field_id_esc}[$option_id_esc]'" .
436 " id='radio_{$field_id_esc}[$option_id_esc]'" .
437 " value='$inputValue'";
438 if ($restype === "$i") echo " checked";
439 echo " /></td>";
441 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
442 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
443 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
444 echo "<td><input type='text'" .
445 " name='form_{$field_id_esc}[$option_id_esc]'" .
446 " id='form_{$field_id_esc}[$option_id_esc]'" .
447 " size='$fldlength'" .
448 " maxlength='$maxlength'" .
449 " value='$resnote' /></td>";
450 echo "</tr>";
452 echo "</table>";
455 // the list of active allergies for the current patient
456 // this is read-only!
457 else if ($data_type == 24) {
458 $query = "SELECT title, comments FROM lists WHERE " .
459 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
460 "ORDER BY begdate";
461 // echo "<!-- $query -->\n"; // debugging
462 $lres = sqlStatement($query, array($GLOBALS['pid']));
463 $count = 0;
464 while ($lrow = sqlFetchArray($lres)) {
465 if ($count++) echo "<br />";
466 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
467 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
471 // a set of labeled checkboxes, each with a text field:
472 else if ($data_type == 25) {
473 $tmp = explode('|', $currvalue);
474 $avalue = array();
475 foreach ($tmp as $value) {
476 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
477 $avalue[$matches[1]] = $matches[2];
480 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
481 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
482 $lres = sqlStatement("SELECT * FROM list_options " .
483 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
484 echo "<table cellpadding='0' cellspacing='0'>";
485 while ($lrow = sqlFetchArray($lres)) {
486 $option_id = $lrow['option_id'];
487 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
488 $restype = substr($avalue[$option_id], 0, 1);
489 $resnote = substr($avalue[$option_id], 2);
491 // Added 5-09 by BM - Translate label if applicable
492 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
494 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
495 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
496 if ($restype) echo " checked";
497 echo " />&nbsp;</td>";
498 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
499 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
500 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
501 echo "<td><input type='text'" .
502 " name='form_{$field_id_esc}[$option_id_esc]'" .
503 " id='form_{$field_id_esc}[$option_id_esc]'" .
504 " size='$fldlength'" .
505 " maxlength='$maxlength'" .
506 " value='$resnote' /></td>";
507 echo "</tr>";
509 echo "</table>";
512 // single-selection list with ability to add to it
513 else if ($data_type == 26) {
514 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
515 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
516 $lres = sqlStatement("SELECT * FROM list_options " .
517 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
518 $got_selected = FALSE;
519 while ($lrow = sqlFetchArray($lres)) {
520 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
521 echo "<option value='$optionValue'";
522 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
523 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
525 echo " selected";
526 $got_selected = TRUE;
528 // Added 5-09 by BM - Translate label if applicable
529 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
531 if (!$got_selected && strlen($currvalue) > 0) {
532 echo "<option value='$currescaped' selected>* $currescaped *</option>";
533 echo "</select>";
534 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
535 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
536 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
538 else {
539 echo "</select>";
541 // show the add button if user has access to correct list
542 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
543 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
544 if (aco_exist('lists', $list_id)) {
545 // a specific aco exist for this list, so ensure access
546 if (acl_check('lists', $list_id)) echo $outputAddButton;
548 else {
549 // no specific aco exist for this list, so check for access to 'default' list
550 if (acl_check('lists', 'default')) echo $outputAddButton;
554 // a set of labeled radio buttons
555 else if ($data_type == 27) {
556 // In this special case, fld_length is the number of columns generated.
557 $cols = max(1, $frow['fld_length']);
558 $lres = sqlStatement("SELECT * FROM list_options " .
559 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
560 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
561 $tdpct = (int) (100 / $cols);
562 $got_selected = FALSE;
563 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
564 $option_id = $lrow['option_id'];
565 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
566 if ($count % $cols == 0) {
567 if ($count) echo "</tr>";
568 echo "<tr>";
570 echo "<td width='$tdpct%'>";
571 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
572 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
573 (strlen($currvalue) > 0 && $option_id == $currvalue))
575 echo " checked";
576 $got_selected = TRUE;
578 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
579 echo "</td>";
581 if ($count) {
582 echo "</tr>";
583 if ($count > $cols) {
584 // Add some space after multiple rows of radio buttons.
585 $cols = htmlspecialchars( $cols, ENT_QUOTES);
586 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
589 echo "</table>";
590 if (!$got_selected && strlen($currvalue) > 0) {
591 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
592 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
593 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
597 // special case for history of lifestyle status; 3 radio buttons and a date text field:
598 // VicarePlus :: A selection list box for smoking status:
599 else if ($data_type == 28 || $data_type == 32) {
600 $tmp = explode('|', $currvalue);
601 switch(count($tmp)) {
602 case "4": {
603 $resnote = $tmp[0];
604 $restype = $tmp[1];
605 $resdate = $tmp[2];
606 $reslist = $tmp[3];
607 } break;
608 case "3": {
609 $resnote = $tmp[0];
610 $restype = $tmp[1];
611 $resdate = $tmp[2];
612 } break;
613 case "2": {
614 $resnote = $tmp[0];
615 $restype = $tmp[1];
616 $resdate = "";
617 } break;
618 case "1": {
619 $resnote = $tmp[0];
620 $resdate = $restype = "";
621 } break;
622 default: {
623 $restype = $resdate = $resnote = "";
624 } break;
626 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
627 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
629 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
630 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
631 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
632 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
633 echo "<table cellpadding='0' cellspacing='0'>";
634 echo "<tr>";
635 if ($data_type == 28)
637 // input text
638 echo "<td><input type='text'" .
639 " name='form_$field_id_esc'" .
640 " id='form_$field_id_esc'" .
641 " size='$fldlength'" .
642 " maxlength='$maxlength'" .
643 " value='$resnote' />&nbsp;</td>";
644 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
645 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
646 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
648 else if($data_type == 32)
650 // input text
651 echo "<tr><td><input type='text'" .
652 " name='form_text_$field_id_esc'" .
653 " id='form_text_$field_id_esc'" .
654 " size='$fldlength'" .
655 " maxlength='$maxlength'" .
656 " value='$resnote' />&nbsp;</td></tr>";
657 echo "<td>";
658 //Selection list for smoking status
659 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
660 echo generate_select_list("form_$field_id", $list_id, $reslist,
661 $description, $showEmpty ? $empty_title : '', '', $onchange)."</td>";
662 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
664 // current
665 echo "<td><input type='radio'" .
666 " name='radio_{$field_id_esc}'" .
667 " id='radio_{$field_id_esc}[current]'" .
668 " value='current".$field_id_esc."'";
669 if ($restype == "current".$field_id) echo " checked";
670 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
671 // quit
672 echo "<td><input type='radio'" .
673 " name='radio_{$field_id_esc}'" .
674 " id='radio_{$field_id_esc}[quit]'" .
675 " value='quit".$field_id_esc."'";
676 if ($restype == "quit".$field_id) echo " checked";
677 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
678 // quit date
679 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
680 " value='$resdate'" .
681 " title='$description'" .
682 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
683 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
684 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
685 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />&nbsp;</td>";
686 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
687 // never
688 echo "<td><input type='radio'" .
689 " name='radio_{$field_id_esc}'" .
690 " id='radio_{$field_id_esc}[never]'" .
691 " value='never".$field_id_esc."'";
692 if ($restype == "never".$field_id) echo " checked";
693 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."&nbsp;</td>";
694 // Not Applicable
695 echo "<td><input type='radio'" .
696 " name='radio_{$field_id}'" .
697 " id='radio_{$field_id}[not_applicable]'" .
698 " value='not_applicable".$field_id."'";
699 if ($restype == "not_applicable".$field_id) echo " checked";
700 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('N/A'), ENT_QUOTES)."&nbsp;</td>";
701 echo "</tr>";
702 echo "</table>";
705 // static text. read-only, of course.
706 else if ($data_type == 31) {
707 echo nl2br($frow['description']);
710 //VicarePlus :: A single selection list for Race and Ethnicity, which is specialized to check the 'ethrace' list if the entry does not exist in the list_id of the given list. At some point in the future (when able to input two lists via the layouts engine), this function could be expanded to allow using any list as a backup entry.
711 else if ($data_type == 33) {
712 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
713 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
714 $lres = sqlStatement("SELECT * FROM list_options " .
715 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
716 $got_selected = FALSE;
717 while ($lrow = sqlFetchArray($lres)) {
718 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
719 echo "<option value='$optionValue'";
720 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
721 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
723 echo " selected";
724 $got_selected = TRUE;
727 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
729 if (!$got_selected && strlen($currvalue) > 0)
731 //Check 'ethrace' list if the entry does not exist in the list_id of the given list(Race or Ethnicity).
732 $list_id='ethrace';
733 $lrow = sqlQuery("SELECT title FROM list_options " .
734 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
735 if ($lrow > 0)
737 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
738 echo "<option value='$currvalue' selected> $s </option>";
739 echo "</select>";
741 else
743 echo "<option value='$currescaped' selected>* $currescaped *</option>";
744 echo "</select>";
745 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
746 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
747 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
750 else {
751 echo "</select>";
754 else if($data_type == 34){
755 $arr = explode("|*|*|*|",$currvalue);
756 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;'>";
757 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
758 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'>".$currvalue."</textarea></div>";
759 echo "</a>";
764 function generate_print_field($frow, $currvalue) {
765 global $rootdir, $date_init;
767 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
769 $data_type = $frow['data_type'];
770 $field_id = $frow['field_id'];
771 $list_id = $frow['list_id'];
772 $fld_length = $frow['fld_length'];
774 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
776 // Can pass $frow['empty_title'] with this variable, otherwise
777 // will default to 'Unassigned'.
778 // If it is 'SKIP' then an empty text title is completely skipped.
779 $showEmpty = true;
780 if (isset($frow['empty_title'])) {
781 if ($frow['empty_title'] == "SKIP") {
782 //do not display an 'empty' choice
783 $showEmpty = false;
784 $empty_title = "Unassigned";
786 else {
787 $empty_title = $frow['empty_title'];
790 else {
791 $empty_title = "Unassigned";
794 // generic single-selection list
795 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
796 if (empty($fld_length)) {
797 if ($list_id == 'titles') {
798 $fld_length = 3;
799 } else {
800 $fld_length = 10;
803 $tmp = '';
804 if ($currvalue) {
805 $lrow = sqlQuery("SELECT title FROM list_options " .
806 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
807 $tmp = xl_list_label($lrow['title']);
808 if (empty($tmp)) $tmp = "($currvalue)";
810 /*****************************************************************
811 echo "<input type='text'" .
812 " size='$fld_length'" .
813 " value='$tmp'" .
814 " class='under'" .
815 " />";
816 *****************************************************************/
817 if ($tmp === '') { $tmp = '&nbsp;'; }
818 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
819 echo $tmp;
822 // simple text field
823 else if ($data_type == 2 || $data_type == 15) {
824 /*****************************************************************
825 echo "<input type='text'" .
826 " size='$fld_length'" .
827 " value='$currescaped'" .
828 " class='under'" .
829 " />";
830 *****************************************************************/
831 if ($currescaped === '') $currescaped = '&nbsp;';
832 echo $currescaped;
835 // long or multi-line text field
836 else if ($data_type == 3) {
837 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
838 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
839 echo "<textarea" .
840 " cols='$fldlength'" .
841 " rows='$maxlength'>" .
842 $currescaped . "</textarea>";
845 // date
846 else if ($data_type == 4) {
847 /*****************************************************************
848 echo "<input type='text' size='10'" .
849 " value='$currescaped'" .
850 " title='$description'" .
851 " class='under'" .
852 " />";
853 *****************************************************************/
854 if ($currvalue === '') { $tmp = oeFormatShortDate('&nbsp;'); }
855 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES); }
856 echo $tmp;
859 // provider list
860 else if ($data_type == 10 || $data_type == 11) {
861 $tmp = '';
862 if ($currvalue) {
863 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
864 "WHERE id = ?", array($currvalue) );
865 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
866 if (empty($tmp)) $tmp = "($currvalue)";
868 /*****************************************************************
869 echo "<input type='text'" .
870 " size='$fld_length'" .
871 " value='$tmp'" .
872 " class='under'" .
873 " />";
874 *****************************************************************/
875 if ($tmp === '') { $tmp = '&nbsp;'; }
876 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
877 echo $tmp;
880 // pharmacy list
881 else if ($data_type == 12) {
882 $tmp = '';
883 if ($currvalue) {
884 $pres = get_pharmacies();
885 while ($prow = sqlFetchArray($pres)) {
886 $key = $prow['id'];
887 if ($currvalue == $key) {
888 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
889 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
890 $prow['line1'] . ' / ' . $prow['city'];
893 if (empty($tmp)) $tmp = "($currvalue)";
895 /*****************************************************************
896 echo "<input type='text'" .
897 " size='$fld_length'" .
898 " value='$tmp'" .
899 " class='under'" .
900 " />";
901 *****************************************************************/
902 if ($tmp === '') { $tmp = '&nbsp;'; }
903 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
904 echo $tmp;
907 // squads
908 else if ($data_type == 13) {
909 $tmp = '';
910 if ($currvalue) {
911 $squads = acl_get_squads();
912 if ($squads) {
913 foreach ($squads as $key => $value) {
914 if ($currvalue == $key) {
915 $tmp = $value[3];
919 if (empty($tmp)) $tmp = "($currvalue)";
921 /*****************************************************************
922 echo "<input type='text'" .
923 " size='$fld_length'" .
924 " value='$tmp'" .
925 " class='under'" .
926 " />";
927 *****************************************************************/
928 if ($tmp === '') { $tmp = '&nbsp;'; }
929 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
930 echo $tmp;
933 // Address book.
934 else if ($data_type == 14) {
935 $tmp = '';
936 if ($currvalue) {
937 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
938 "WHERE id = ?", array($currvalue) );
939 $uname = $urow['lname'];
940 if ($urow['fname']) $uname .= ", " . $urow['fname'];
941 $tmp = $uname;
942 if (empty($tmp)) $tmp = "($currvalue)";
944 /*****************************************************************
945 echo "<input type='text'" .
946 " size='$fld_length'" .
947 " value='$tmp'" .
948 " class='under'" .
949 " />";
950 *****************************************************************/
951 if ($tmp === '') { $tmp = '&nbsp;'; }
952 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
953 echo $tmp;
956 // a set of labeled checkboxes
957 else if ($data_type == 21) {
958 // In this special case, fld_length is the number of columns generated.
959 $cols = max(1, $fld_length);
960 $avalue = explode('|', $currvalue);
961 $lres = sqlStatement("SELECT * FROM list_options " .
962 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
963 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
964 $tdpct = (int) (100 / $cols);
965 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
966 $option_id = $lrow['option_id'];
967 if ($count % $cols == 0) {
968 if ($count) echo "</tr>";
969 echo "<tr>";
971 echo "<td width='$tdpct%'>";
972 echo "<input type='checkbox'";
973 if (in_array($option_id, $avalue)) echo " checked";
974 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
975 echo "</td>";
977 if ($count) {
978 echo "</tr>";
979 if ($count > $cols) {
980 // Add some space after multiple rows of checkboxes.
981 $cols = htmlspecialchars( $cols, ENT_QUOTES);
982 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
985 echo "</table>";
988 // a set of labeled text input fields
989 else if ($data_type == 22) {
990 $tmp = explode('|', $currvalue);
991 $avalue = array();
992 foreach ($tmp as $value) {
993 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
994 $avalue[$matches[1]] = $matches[2];
997 $lres = sqlStatement("SELECT * FROM list_options " .
998 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
999 echo "<table cellpadding='0' cellspacing='0'>";
1000 while ($lrow = sqlFetchArray($lres)) {
1001 $option_id = $lrow['option_id'];
1002 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1003 $fldlength = empty($fld_length) ? 20 : $fld_length;
1004 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1005 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1006 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1007 echo "<td><input type='text'" .
1008 " size='$fldlength'" .
1009 " value='$inputValue'" .
1010 " class='under'" .
1011 " /></td></tr>";
1013 echo "</table>";
1016 // a set of exam results; 3 radio buttons and a text field:
1017 else if ($data_type == 23) {
1018 $tmp = explode('|', $currvalue);
1019 $avalue = array();
1020 foreach ($tmp as $value) {
1021 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1022 $avalue[$matches[1]] = $matches[2];
1025 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1026 $fldlength = empty($fld_length) ? 20 : $fld_length;
1027 $lres = sqlStatement("SELECT * FROM list_options " .
1028 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1029 echo "<table cellpadding='0' cellspacing='0'>";
1030 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1031 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1032 "&nbsp;</td><td class='bold'>" .
1033 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1034 "<td class='bold'>" .
1035 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1036 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1037 while ($lrow = sqlFetchArray($lres)) {
1038 $option_id = $lrow['option_id'];
1039 $restype = substr($avalue[$option_id], 0, 1);
1040 $resnote = substr($avalue[$option_id], 2);
1041 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1042 for ($i = 0; $i < 3; ++$i) {
1043 echo "<td><input type='radio'";
1044 if ($restype === "$i") echo " checked";
1045 echo " /></td>";
1047 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1048 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1049 echo "<td><input type='text'" .
1050 " size='$fldlength'" .
1051 " value='$resnote'" .
1052 " class='under' /></td>" .
1053 "</tr>";
1055 echo "</table>";
1058 // the list of active allergies for the current patient
1059 // this is read-only!
1060 else if ($data_type == 24) {
1061 $query = "SELECT title, comments FROM lists WHERE " .
1062 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1063 "ORDER BY begdate";
1064 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1065 $count = 0;
1066 while ($lrow = sqlFetchArray($lres)) {
1067 if ($count++) echo "<br />";
1068 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1069 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1073 // a set of labeled checkboxes, each with a text field:
1074 else if ($data_type == 25) {
1075 $tmp = explode('|', $currvalue);
1076 $avalue = array();
1077 foreach ($tmp as $value) {
1078 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1079 $avalue[$matches[1]] = $matches[2];
1082 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1083 $fldlength = empty($fld_length) ? 20 : $fld_length;
1084 $lres = sqlStatement("SELECT * FROM list_options " .
1085 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1086 echo "<table cellpadding='0' cellspacing='0'>";
1087 while ($lrow = sqlFetchArray($lres)) {
1088 $option_id = $lrow['option_id'];
1089 $restype = substr($avalue[$option_id], 0, 1);
1090 $resnote = substr($avalue[$option_id], 2);
1091 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1092 echo "<td><input type='checkbox'";
1093 if ($restype) echo " checked";
1094 echo " />&nbsp;</td>";
1095 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1096 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1097 echo "<td><input type='text'" .
1098 " size='$fldlength'" .
1099 " value='$resnote'" .
1100 " class='under'" .
1101 " /></td>" .
1102 "</tr>";
1104 echo "</table>";
1107 // a set of labeled radio buttons
1108 else if ($data_type == 27) {
1109 // In this special case, fld_length is the number of columns generated.
1110 $cols = max(1, $frow['fld_length']);
1111 $lres = sqlStatement("SELECT * FROM list_options " .
1112 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1113 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1114 $tdpct = (int) (100 / $cols);
1115 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1116 $option_id = $lrow['option_id'];
1117 if ($count % $cols == 0) {
1118 if ($count) echo "</tr>";
1119 echo "<tr>";
1121 echo "<td width='$tdpct%'>";
1122 echo "<input type='radio'";
1123 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1124 (strlen($currvalue) > 0 && $option_id == $currvalue))
1126 echo " checked";
1128 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1129 echo "</td>";
1131 if ($count) {
1132 echo "</tr>";
1133 if ($count > $cols) {
1134 // Add some space after multiple rows of radio buttons.
1135 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1136 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1139 echo "</table>";
1142 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1143 else if ($data_type == 28 || $data_type == 32) {
1144 $tmp = explode('|', $currvalue);
1145 switch(count($tmp)) {
1146 case "4": {
1147 $resnote = $tmp[0];
1148 $restype = $tmp[1];
1149 $resdate = $tmp[2];
1150 $reslist = $tmp[3];
1151 } break;
1152 case "3": {
1153 $resnote = $tmp[0];
1154 $restype = $tmp[1];
1155 $resdate = $tmp[2];
1156 } break;
1157 case "2": {
1158 $resnote = $tmp[0];
1159 $restype = $tmp[1];
1160 $resdate = "";
1161 } break;
1162 case "1": {
1163 $resnote = $tmp[0];
1164 $resdate = $restype = "";
1165 } break;
1166 default: {
1167 $restype = $resdate = $resnote = "";
1168 } break;
1170 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1171 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1172 echo "<table cellpadding='0' cellspacing='0'>";
1173 echo "<tr>";
1174 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1175 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1176 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1177 if($data_type == 28)
1179 echo "<td><input type='text'" .
1180 " size='$fldlength'" .
1181 " class='under'" .
1182 " value='$resnote' /></td>";
1183 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1184 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1185 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1187 else if($data_type == 32)
1189 echo "<tr><td><input type='text'" .
1190 " size='$fldlength'" .
1191 " class='under'" .
1192 " value='$resnote' /></td></tr>";
1193 $fldlength = 30;
1194 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1195 echo "<td><input type='text'" .
1196 " size='$fldlength'" .
1197 " class='under'" .
1198 " value='$smoking_status_title' /></td>";
1199 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1201 echo "<td><input type='radio'";
1202 if ($restype == "current".$field_id) echo " checked";
1203 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1205 echo "<td><input type='radio'";
1206 if ($restype == "current".$field_id) echo " checked";
1207 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1209 echo "<td><input type='text' size='6'" .
1210 " value='$resdate'" .
1211 " class='under'" .
1212 " /></td>";
1214 echo "<td><input type='radio'";
1215 if ($restype == "current".$field_id) echo " checked";
1216 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1218 echo "<td><input type='radio'";
1219 if ($restype == "not_applicable".$field_id) echo " checked";
1220 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1221 echo "</tr>";
1222 echo "</table>";
1225 // static text. read-only, of course.
1226 else if ($data_type == 31) {
1227 echo nl2br($frow['description']);
1230 else if($data_type == 34){
1231 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;'>";
1232 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1233 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1234 echo "</a>";
1239 function generate_display_field($frow, $currvalue) {
1240 $data_type = $frow['data_type'];
1241 $field_id = $frow['field_id'];
1242 $list_id = $frow['list_id'];
1243 $s = '';
1245 // generic selection list or the generic selection list with add on the fly
1246 // feature, or radio buttons
1247 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1248 $lrow = sqlQuery("SELECT title FROM list_options " .
1249 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1250 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1251 //For lists Race and Ethnicity if there is no matching value in the corresponding lists check ethrace list
1252 if ($lrow == 0 && $data_type == 33)
1254 $list_id='ethrace';
1255 $lrow_ethrace = sqlQuery("SELECT title FROM list_options " .
1256 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1257 $s = htmlspecialchars(xl_list_label($lrow_ethrace['title']),ENT_NOQUOTES);
1261 // simple text field
1262 else if ($data_type == 2) {
1263 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1266 // long or multi-line text field
1267 else if ($data_type == 3) {
1268 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1271 // date
1272 else if ($data_type == 4) {
1273 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES);
1276 // provider
1277 else if ($data_type == 10 || $data_type == 11) {
1278 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1279 "WHERE id = ?", array($currvalue) );
1280 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1283 // pharmacy list
1284 else if ($data_type == 12) {
1285 $pres = get_pharmacies();
1286 while ($prow = sqlFetchArray($pres)) {
1287 $key = $prow['id'];
1288 if ($currvalue == $key) {
1289 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1290 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1291 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1296 // squads
1297 else if ($data_type == 13) {
1298 $squads = acl_get_squads();
1299 if ($squads) {
1300 foreach ($squads as $key => $value) {
1301 if ($currvalue == $key) {
1302 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1308 // address book
1309 else if ($data_type == 14) {
1310 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1311 "WHERE id = ?", array($currvalue));
1312 $uname = $urow['lname'];
1313 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1314 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1317 // billing code
1318 else if ($data_type == 15) {
1319 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1322 // a set of labeled checkboxes
1323 else if ($data_type == 21) {
1324 $avalue = explode('|', $currvalue);
1325 $lres = sqlStatement("SELECT * FROM list_options " .
1326 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1327 $count = 0;
1328 while ($lrow = sqlFetchArray($lres)) {
1329 $option_id = $lrow['option_id'];
1330 if (in_array($option_id, $avalue)) {
1331 if ($count++) $s .= "<br />";
1333 // Added 5-09 by BM - Translate label if applicable
1334 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1340 // a set of labeled text input fields
1341 else if ($data_type == 22) {
1342 $tmp = explode('|', $currvalue);
1343 $avalue = array();
1344 foreach ($tmp as $value) {
1345 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1346 $avalue[$matches[1]] = $matches[2];
1349 $lres = sqlStatement("SELECT * FROM list_options " .
1350 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1351 $s .= "<table cellpadding='0' cellspacing='0'>";
1352 while ($lrow = sqlFetchArray($lres)) {
1353 $option_id = $lrow['option_id'];
1354 if (empty($avalue[$option_id])) continue;
1356 // Added 5-09 by BM - Translate label if applicable
1357 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1359 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1361 $s .= "</table>";
1364 // a set of exam results; 3 radio buttons and a text field:
1365 else if ($data_type == 23) {
1366 $tmp = explode('|', $currvalue);
1367 $avalue = array();
1368 foreach ($tmp as $value) {
1369 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1370 $avalue[$matches[1]] = $matches[2];
1373 $lres = sqlStatement("SELECT * FROM list_options " .
1374 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1375 $s .= "<table cellpadding='0' cellspacing='0'>";
1376 while ($lrow = sqlFetchArray($lres)) {
1377 $option_id = $lrow['option_id'];
1378 $restype = substr($avalue[$option_id], 0, 1);
1379 $resnote = substr($avalue[$option_id], 2);
1380 if (empty($restype) && empty($resnote)) continue;
1382 // Added 5-09 by BM - Translate label if applicable
1383 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1385 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1386 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1387 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1388 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1389 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1390 $s .= "</tr>";
1392 $s .= "</table>";
1395 // the list of active allergies for the current patient
1396 else if ($data_type == 24) {
1397 $query = "SELECT title, comments FROM lists WHERE " .
1398 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1399 "ORDER BY begdate";
1400 // echo "<!-- $query -->\n"; // debugging
1401 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1402 $count = 0;
1403 while ($lrow = sqlFetchArray($lres)) {
1404 if ($count++) $s .= "<br />";
1405 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1406 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1410 // a set of labeled checkboxes, each with a text field:
1411 else if ($data_type == 25) {
1412 $tmp = explode('|', $currvalue);
1413 $avalue = array();
1414 foreach ($tmp as $value) {
1415 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1416 $avalue[$matches[1]] = $matches[2];
1419 $lres = sqlStatement("SELECT * FROM list_options " .
1420 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1421 $s .= "<table cellpadding='0' cellspacing='0'>";
1422 while ($lrow = sqlFetchArray($lres)) {
1423 $option_id = $lrow['option_id'];
1424 $restype = substr($avalue[$option_id], 0, 1);
1425 $resnote = substr($avalue[$option_id], 2);
1426 if (empty($restype) && empty($resnote)) continue;
1428 // Added 5-09 by BM - Translate label if applicable
1429 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1431 $restype = $restype ? xl('Yes') : xl('No');
1432 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1433 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1434 $s .= "</tr>";
1436 $s .= "</table>";
1439 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1440 // VicarePlus :: A selection list for smoking status.
1441 else if ($data_type == 28 || $data_type == 32) {
1442 $tmp = explode('|', $currvalue);
1443 switch(count($tmp)) {
1444 case "4": {
1445 $resnote = $tmp[0];
1446 $restype = $tmp[1];
1447 $resdate = $tmp[2];
1448 $reslist = $tmp[3];
1449 } break;
1450 case "3": {
1451 $resnote = $tmp[0];
1452 $restype = $tmp[1];
1453 $resdate = $tmp[2];
1454 } break;
1455 case "2": {
1456 $resnote = $tmp[0];
1457 $restype = $tmp[1];
1458 $resdate = "";
1459 } break;
1460 case "1": {
1461 $resnote = $tmp[0];
1462 $resdate = $restype = "";
1463 } break;
1464 default: {
1465 $restype = $resdate = $resnote = "";
1466 } break;
1468 $s .= "<table cellpadding='0' cellspacing='0'>";
1470 $s .= "<tr>";
1471 $res = "";
1472 if ($restype == "current".$field_id) $res = xl('Current');
1473 if ($restype == "quit".$field_id) $res = xl('Quit');
1474 if ($restype == "never".$field_id) $res = xl('Never');
1475 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1476 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1477 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1478 if ($data_type == 28)
1480 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1482 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1483 else if ($data_type == 32)
1485 if (!empty($reslist)) $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1486 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1489 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1490 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1491 $s .= "</tr>";
1492 $s .= "</table>";
1495 // static text. read-only, of course.
1496 else if ($data_type == 31) {
1497 $s .= nl2br($frow['description']);
1500 else if($data_type == 34){
1501 $arr = explode("|*|*|*|",$currvalue);
1502 for($i=0;$i<sizeof($arr);$i++){
1503 $s.=$arr[$i];
1507 return $s;
1510 $CPR = 4; // cells per row of generic data
1511 $last_group = '';
1512 $cell_count = 0;
1513 $item_count = 0;
1515 function disp_end_cell() {
1516 global $item_count, $cell_count;
1517 if ($item_count > 0) {
1518 echo "</td>";
1519 $item_count = 0;
1523 function disp_end_row() {
1524 global $cell_count, $CPR;
1525 disp_end_cell();
1526 if ($cell_count > 0) {
1527 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1528 echo "</tr>\n";
1529 $cell_count = 0;
1533 function disp_end_group() {
1534 global $last_group;
1535 if (strlen($last_group) > 0) {
1536 disp_end_row();
1540 function display_layout_rows($formtype, $result1, $result2='') {
1541 global $item_count, $cell_count, $last_group, $CPR;
1543 $fres = sqlStatement("SELECT * FROM layout_options " .
1544 "WHERE form_id = ? AND uor > 0 " .
1545 "ORDER BY group_name, seq", array($formtype) );
1547 while ($frow = sqlFetchArray($fres)) {
1548 $this_group = $frow['group_name'];
1549 $titlecols = $frow['titlecols'];
1550 $datacols = $frow['datacols'];
1551 $data_type = $frow['data_type'];
1552 $field_id = $frow['field_id'];
1553 $list_id = $frow['list_id'];
1554 $currvalue = '';
1556 if ($formtype == 'DEM') {
1557 if ($GLOBALS['athletic_team']) {
1558 // Skip fitness level and return-to-play date because those appear
1559 // in a special display/update form on this page.
1560 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1562 if (strpos($field_id, 'em_') === 0) {
1563 // Skip employer related fields, if it's disabled.
1564 if ($GLOBALS['omit_employers']) continue;
1565 $tmp = substr($field_id, 3);
1566 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1568 else {
1569 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1572 else {
1573 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1576 // Handle a data category (group) change.
1577 if (strcmp($this_group, $last_group) != 0) {
1578 $group_name = substr($this_group, 1);
1579 // totally skip generating the employer category, if it's disabled.
1580 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1581 disp_end_group();
1582 $last_group = $this_group;
1585 // Handle starting of a new row.
1586 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1587 disp_end_row();
1588 echo "<tr>";
1589 if ($group_name) {
1590 echo "<td class='groupname'>";
1591 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1592 //echo "<font color='#008800'>$group_name</font>";
1594 // Added 5-09 by BM - Translate label if applicable
1595 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
1597 $group_name = '';
1598 } else {
1599 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1600 echo "<td valign='top'>&nbsp;";
1602 echo "</td>";
1605 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1607 // Handle starting of a new label cell.
1608 if ($titlecols > 0) {
1609 disp_end_cell();
1610 //echo "<td class='label' colspan='$titlecols' valign='top'";
1611 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1612 echo "<td class='label' colspan='$titlecols_esc' ";
1613 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1614 echo ">";
1615 $cell_count += $titlecols;
1617 ++$item_count;
1619 // Added 5-09 by BM - Translate label if applicable
1620 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1622 // Handle starting of a new data cell.
1623 if ($datacols > 0) {
1624 disp_end_cell();
1625 //echo "<td class='text data' colspan='$datacols' valign='top'";
1626 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1627 echo "<td class='text data' colspan='$datacols_esc'";
1628 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1629 echo ">";
1630 $cell_count += $datacols;
1633 ++$item_count;
1634 echo generate_display_field($frow, $currvalue);
1637 disp_end_group();
1640 function display_layout_tabs($formtype, $result1, $result2='') {
1641 global $item_count, $cell_count, $last_group, $CPR;
1643 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1644 "WHERE form_id = ? AND uor > 0 " .
1645 "ORDER BY group_name, seq", array($formtype) );
1647 $first = true;
1648 while ($frow = sqlFetchArray($fres)) {
1649 $this_group = $frow['group_name'];
1650 $group_name = substr($this_group, 1);
1652 <li <?php echo $first ? 'class="current"' : '' ?>>
1653 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
1654 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
1655 </li>
1656 <?php
1657 $first = false;
1661 function display_layout_tabs_data($formtype, $result1, $result2='') {
1662 global $item_count, $cell_count, $last_group, $CPR;
1664 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1665 "WHERE form_id = ? AND uor > 0 " .
1666 "ORDER BY group_name, seq", array($formtype));
1668 $first = true;
1669 while ($frow = sqlFetchArray($fres)) {
1670 $this_group = $frow['group_name'];
1671 $titlecols = $frow['titlecols'];
1672 $datacols = $frow['datacols'];
1673 $data_type = $frow['data_type'];
1674 $field_id = $frow['field_id'];
1675 $list_id = $frow['list_id'];
1676 $currvalue = '';
1678 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1679 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1680 "ORDER BY seq", array($formtype, $this_group) );
1683 <div class="tab <?php echo $first ? 'current' : '' ?>">
1684 <table border='0' cellpadding='0'>
1686 <?php
1687 while ($group_fields = sqlFetchArray($group_fields_query)) {
1689 $titlecols = $group_fields['titlecols'];
1690 $datacols = $group_fields['datacols'];
1691 $data_type = $group_fields['data_type'];
1692 $field_id = $group_fields['field_id'];
1693 $list_id = $group_fields['list_id'];
1694 $currvalue = '';
1696 if ($formtype == 'DEM') {
1697 if ($GLOBALS['athletic_team']) {
1698 // Skip fitness level and return-to-play date because those appear
1699 // in a special display/update form on this page.
1700 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1702 if (strpos($field_id, 'em_') === 0) {
1703 // Skip employer related fields, if it's disabled.
1704 if ($GLOBALS['omit_employers']) continue;
1705 $tmp = substr($field_id, 3);
1706 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1708 else {
1709 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1712 else {
1713 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1716 // Handle a data category (group) change.
1717 if (strcmp($this_group, $last_group) != 0) {
1718 $group_name = substr($this_group, 1);
1719 // totally skip generating the employer category, if it's disabled.
1720 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1721 $last_group = $this_group;
1724 // Handle starting of a new row.
1725 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1726 disp_end_row();
1727 echo "<tr>";
1730 if ($item_count == 0 && $titlecols == 0) {
1731 $titlecols = 1;
1734 // Handle starting of a new label cell.
1735 if ($titlecols > 0) {
1736 disp_end_cell();
1737 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1738 echo "<td class='label' colspan='$titlecols_esc' ";
1739 echo ">";
1740 $cell_count += $titlecols;
1742 ++$item_count;
1744 // Added 5-09 by BM - Translate label if applicable
1745 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1747 // Handle starting of a new data cell.
1748 if ($datacols > 0) {
1749 disp_end_cell();
1750 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1751 echo "<td class='text data' colspan='$datacols_esc'";
1752 echo ">";
1753 $cell_count += $datacols;
1756 ++$item_count;
1757 echo generate_display_field($group_fields, $currvalue);
1760 disp_end_row();
1763 </table>
1764 </div>
1766 <?php
1768 $first = false;
1774 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1775 global $item_count, $cell_count, $last_group, $CPR;
1777 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1778 "WHERE form_id = ? AND uor > 0 " .
1779 "ORDER BY group_name, seq", array($formtype) );
1781 $first = true;
1782 while ($frow = sqlFetchArray($fres)) {
1783 $this_group = $frow['group_name'];
1784 $group_name = substr($this_group, 1);
1785 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
1786 $titlecols = $frow['titlecols'];
1787 $datacols = $frow['datacols'];
1788 $data_type = $frow['data_type'];
1789 $field_id = $frow['field_id'];
1790 $list_id = $frow['list_id'];
1791 $currvalue = '';
1793 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1794 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1795 "ORDER BY seq", array($formtype,$this_group) );
1798 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
1799 <table border='0' cellpadding='0'>
1801 <?php
1802 while ($group_fields = sqlFetchArray($group_fields_query)) {
1804 $titlecols = $group_fields['titlecols'];
1805 $datacols = $group_fields['datacols'];
1806 $data_type = $group_fields['data_type'];
1807 $field_id = $group_fields['field_id'];
1808 $list_id = $group_fields['list_id'];
1809 $currvalue = '';
1811 if ($formtype == 'DEM') {
1812 if ($GLOBALS['athletic_team']) {
1813 // Skip fitness level and return-to-play date because those appear
1814 // in a special display/update form on this page.
1815 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1817 if (strpos($field_id, 'em_') === 0) {
1818 // Skip employer related fields, if it's disabled.
1819 if ($GLOBALS['omit_employers']) continue;
1820 $tmp = substr($field_id, 3);
1821 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1823 else {
1824 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1827 else {
1828 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1831 // Handle a data category (group) change.
1832 if (strcmp($this_group, $last_group) != 0) {
1833 $group_name = substr($this_group, 1);
1834 // totally skip generating the employer category, if it's disabled.
1835 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1836 $last_group = $this_group;
1839 // Handle starting of a new row.
1840 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1841 disp_end_row();
1842 echo "<tr>";
1845 if ($item_count == 0 && $titlecols == 0) {
1846 $titlecols = 1;
1849 // Handle starting of a new label cell.
1850 if ($titlecols > 0) {
1851 disp_end_cell();
1852 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1853 echo "<td class='label' colspan='$titlecols_esc' ";
1854 echo ">";
1855 $cell_count += $titlecols;
1857 ++$item_count;
1859 // Added 5-09 by BM - Translate label if applicable
1860 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
1862 // Handle starting of a new data cell.
1863 if ($datacols > 0) {
1864 disp_end_cell();
1865 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1866 echo "<td class='text data' colspan='$datacols_esc'";
1867 echo ">";
1868 $cell_count += $datacols;
1871 ++$item_count;
1872 echo generate_form_field($group_fields, $currvalue);
1876 </table>
1877 </div>
1879 <?php
1881 $first = false;
1886 // From the currently posted HTML form, this gets the value of the
1887 // field corresponding to the provided layout_options table row.
1889 function get_layout_form_value($frow, $maxlength=255) {
1890 // Bring in $sanitize_all_escapes variable, which will decide
1891 // the variable escaping method.
1892 global $sanitize_all_escapes;
1894 $data_type = $frow['data_type'];
1895 $field_id = $frow['field_id'];
1896 $value = '';
1897 if (isset($_POST["form_$field_id"])) {
1898 if ($data_type == 21) {
1899 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1900 // must be concatenated into a |-separated string.
1901 foreach ($_POST["form_$field_id"] as $key => $val) {
1902 if (strlen($value)) $value .= '|';
1903 $value .= $key;
1906 else if ($data_type == 22) {
1907 // $_POST["form_$field_id"] is an array of text fields to be imploded
1908 // into "key:value|key:value|...".
1909 foreach ($_POST["form_$field_id"] as $key => $val) {
1910 $val = str_replace('|', ' ', $val);
1911 if (strlen($value)) $value .= '|';
1912 $value .= "$key:$val";
1915 else if ($data_type == 23) {
1916 // $_POST["form_$field_id"] is an array of text fields with companion
1917 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1918 foreach ($_POST["form_$field_id"] as $key => $val) {
1919 $restype = $_POST["radio_{$field_id}"][$key];
1920 if (empty($restype)) $restype = '0';
1921 $val = str_replace('|', ' ', $val);
1922 if (strlen($value)) $value .= '|';
1923 $value .= "$key:$restype:$val";
1926 else if ($data_type == 25) {
1927 // $_POST["form_$field_id"] is an array of text fields with companion
1928 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1929 foreach ($_POST["form_$field_id"] as $key => $val) {
1930 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
1931 $val = str_replace('|', ' ', $val);
1932 if (strlen($value)) $value .= '|';
1933 $value .= "$key:$restype:$val";
1936 else if ($data_type == 28 || $data_type == 32) {
1937 // $_POST["form_$field_id"] is an date text fields with companion
1938 // radio buttons to be imploded into "notes|type|date".
1939 $restype = $_POST["radio_{$field_id}"];
1940 if (empty($restype)) $restype = '0';
1941 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1942 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1943 if ($data_type == 32)
1945 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
1946 $reslist = str_replace('|', ' ', $_POST["form_$field_id"]);
1947 $res_text_note = str_replace('|', ' ', $_POST["form_text_$field_id"]);
1948 $value = "$res_text_note|$restype|$resdate|$reslist";
1950 else
1951 $value = "$resnote|$restype|$resdate";
1953 else {
1954 $value = $_POST["form_$field_id"];
1958 // Better to die than to silently truncate data!
1959 if ($maxlength && ($data_type != 3 && $data_type != 34) && strlen($value) > $maxlength)
1960 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
1961 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
1963 // Make sure the return value is quote-safe.
1964 if ($sanitize_all_escapes) {
1965 //escapes already removed and using binding/placemarks in sql calls
1966 // so only need to trim value
1967 return trim($value);
1969 else {
1970 //need to explicitly prepare value
1971 return formTrim($value);
1975 // Generate JavaScript validation logic for the required fields.
1977 function generate_layout_validation($form_id) {
1978 $fres = sqlStatement("SELECT * FROM layout_options " .
1979 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
1980 "ORDER BY group_name, seq", array($form_id) );
1982 while ($frow = sqlFetchArray($fres)) {
1983 if ($frow['uor'] < 2) continue;
1984 $data_type = $frow['data_type'];
1985 $field_id = $frow['field_id'];
1986 $fldtitle = $frow['title'];
1987 if (!$fldtitle) $fldtitle = $frow['description'];
1988 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
1989 switch($data_type) {
1990 case 1:
1991 case 11:
1992 case 12:
1993 case 13:
1994 case 14:
1995 case 26:
1996 case 33:
1997 echo
1998 " if (f.$fldname.selectedIndex <= 0) {\n" .
1999 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2000 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2001 " }\n";
2002 break;
2003 case 27: // radio buttons
2004 echo
2005 " var i = 0;\n" .
2006 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2007 " if (i >= f.$fldname.length) {\n" .
2008 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2009 " }\n";
2010 break;
2011 case 2:
2012 case 3:
2013 case 4:
2014 case 15:
2015 echo
2016 " if (trimlen(f.$fldname.value) == 0) {\n" .
2017 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2018 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2019 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2020 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2021 " } else { " .
2022 " $('#" . $fldname . "').attr('style',''); " .
2023 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2024 " } \n";
2025 break;
2031 * DROPDOWN FOR FACILITIES
2033 * build a dropdown with all facilities
2035 * @param string $selected - name of the currently selected facility
2036 * use '0' for "unspecified facility"
2037 * use '' for "All facilities" (the default)
2038 * @param string $name - the name/id for select form (defaults to "form_facility")
2039 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2040 * defaults to true
2041 * @return void - just echo the html encoded string
2043 * Note: This should become a data-type at some point, according to Brady
2045 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true) {
2046 $have_selected = false;
2047 $query = "SELECT id, name FROM facility ORDER BY name";
2048 $fres = sqlStatement($query);
2050 $name = htmlspecialchars($name, ENT_QUOTES);
2051 echo " <select name=\"$name\">\n";
2053 $option_value = '';
2054 $option_selected_attr = '';
2055 if ($selected == '') {
2056 $option_selected_attr = ' selected="selected"';
2057 $have_selected = true;
2059 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2060 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2062 while ($frow = sqlFetchArray($fres)) {
2063 $facility_id = $frow['id'];
2064 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2065 $option_selected_attr = '';
2066 if ($selected == $facility_id) {
2067 $option_selected_attr = ' selected="selected"';
2068 $have_selected = true;
2070 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2071 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2074 if ($allow_unspecified) {
2075 $option_value = '0';
2076 $option_selected_attr = '';
2077 if ( $selected == '0' ) {
2078 $option_selected_attr = ' selected="selected"';
2079 $have_selected = true;
2081 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2082 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2085 if (!$have_selected) {
2086 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2087 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2088 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2089 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2091 echo " </select>\n";
2094 // Expand Collapse Widget
2095 // This forms the header and functionality component of the widget. The information that is displayed
2096 // then follows this function followed by a closing div tag
2098 // $title is the title of the section (already translated)
2099 // $label is identifier used in the tag id's and sql columns
2100 // $buttonLabel is the button label text (already translated)
2101 // $buttonLink is the button link information
2102 // $buttonClass is any additional needed class elements for the button tag
2103 // $linkMethod is the button link method ('javascript' vs 'html')
2104 // $bodyClass is to set class(es) of the body
2105 // $auth is a flag to decide whether to show the button
2106 // $fixedWidth is to flag whether width is fixed
2107 // $forceExpandAlways is a flag to force the widget to always be expanded
2109 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2110 if ($fixedWidth) {
2111 echo "<div class='section-header'>";
2113 else {
2114 echo "<div class='section-header-dynamic'>";
2116 echo "<table><tr>";
2117 if ($auth) {
2118 // show button, since authorized
2119 // first prepare class string
2120 if ($buttonClass) {
2121 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2123 else {
2124 $class_string = "css_button_small";
2126 // next, create the link
2127 if ($linkMethod == "javascript") {
2128 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2130 else {
2131 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2132 if (!isset($_SESSION['patient_portal_onsite'])) {
2133 // prevent an error from occuring when calling the function from the patient portal
2134 echo " onclick='top.restoreSession()'";
2137 if (!$GLOBALS['concurrent_layout']) {
2138 echo " target='Main'";
2140 echo "><span>" .
2141 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2143 if ($forceExpandAlways){
2144 // Special case to force the widget to always be expanded
2145 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2146 $indicatorTag ="style='display:none'";
2148 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2149 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
2150 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2152 if (isset($_SESSION['patient_portal_onsite'])) {
2153 // collapse all entries in the patient portal
2154 $text = xl('expand');
2156 else if (getUserSetting($label."_ps_expand")) {
2157 $text = xl('collapse');
2159 else {
2160 $text = xl('expand');
2162 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
2163 "</span>)</a></td>";
2164 echo "</tr></table>";
2165 echo "</div>";
2166 if ($forceExpandAlways) {
2167 // Special case to force the widget to always be expanded
2168 $styling = "";
2170 else if (isset($_SESSION['patient_portal_onsite'])) {
2171 // collapse all entries in the patient portal
2172 $styling = "style='display:none'";
2174 else if (getUserSetting($label."_ps_expand")) {
2175 $styling = "";
2177 else {
2178 $styling = "style='display:none'";
2180 if ($bodyClass) {
2181 $styling .= " class='" . $bodyClass . "'";
2183 //next, create the first div tag to hold the information
2184 // note the code that calls this function will then place the ending div tag after the data
2185 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
2188 //billing_facility fuction will give the dropdown list which contain billing faciliies.
2189 function billing_facility($name,$select){
2190 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
2191 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
2192 while ($facrow = sqlFetchArray($qsql)) {
2193 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
2194 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
2196 echo "</select>";