5 function get_pharmacies() {
6 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
7 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
8 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
9 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
11 "ORDER BY name, area_code, prefix, number");
14 function generate_form_field($frow, $currvalue) {
15 global $rootdir, $date_init;
17 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
19 $data_type = $frow['data_type'];
20 $field_id = $frow['field_id'];
21 $list_id = $frow['list_id'];
22 $description = htmlspecialchars($frow['description'], ENT_QUOTES
);
24 // generic single-selection list
25 if ($data_type == 1) {
26 echo "<select name='form_$field_id' title='$description'>";
27 echo "<option value=''>" . xl('Unassigned') . "</option>";
28 $lres = sqlStatement("SELECT * FROM list_options " .
29 "WHERE list_id = '$list_id' ORDER BY seq");
30 $got_selected = FALSE;
31 while ($lrow = sqlFetchArray($lres)) {
32 echo "<option value='" . $lrow['option_id'] . "'";
33 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
34 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
39 echo ">" . $lrow['title'] . "</option>\n";
41 if (!$got_selected && strlen($currvalue) > 0) {
42 echo "<option value='$currescaped' selected>* $currescaped *</option>";
44 echo " <font color='red' title='Please choose a valid selection " .
45 "from the list'>Fix this!</font>";
53 else if ($data_type == 2) {
54 echo "<input type='text'" .
55 " name='form_$field_id'" .
56 " size='" . $frow['fld_length'] . "'" .
57 " maxlength='" . $frow['max_length'] . "'" .
58 " title='$description'" .
59 " value='$currescaped'";
60 if (strpos($frow['edit_options'], 'C') !== FALSE)
61 echo " onchange='capitalizeMe(this)'";
65 // long or multi-line text field
66 else if ($data_type == 3) {
68 " name='form_$field_id'" .
69 " title='$description'" .
70 " cols='" . $frow['fld_length'] . "'" .
71 " rows='" . $frow['max_length'] . "'>" .
72 $currescaped . "</textarea>";
76 else if ($data_type == 4) {
77 echo "<input type='text' size='10' name='form_$field_id' id='form_$field_id'" .
78 " value='$currescaped'" .
79 " title='$description'" .
80 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
81 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
82 " id='img_$field_id' border='0' alt='[?]' style='cursor:pointer'" .
83 " title='" . xl('Click here to choose a date') . "' />";
84 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
87 // provider list, local providers only
88 else if ($data_type == 10) {
89 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
90 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
91 "AND authorized = 1 " .
92 "ORDER BY lname, fname");
93 echo "<select name='form_$field_id' title='$description'>";
94 echo "<option value=''>" . xl('Unassigned') . "</option>";
95 while ($urow = sqlFetchArray($ures)) {
96 $uname = $urow['fname'] . ' ' . $urow['lname'];
97 echo "<option value='" . $urow['id'] . "'";
98 if ($urow['id'] == $currvalue) echo " selected";
99 echo ">$uname</option>";
104 // provider list, including address book entries with an NPI number
105 else if ($data_type == 11) {
106 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
107 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
108 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
109 "ORDER BY lname, fname");
110 echo "<select name='form_$field_id' title='$description'>";
111 echo "<option value=''>" . xl('Unassigned') . "</option>";
112 while ($urow = sqlFetchArray($ures)) {
113 $uname = $urow['fname'] . ' ' . $urow['lname'];
114 echo "<option value='" . $urow['id'] . "'";
115 if ($urow['id'] == $currvalue) echo " selected";
116 echo ">$uname</option>";
122 else if ($data_type == 12) {
123 echo "<select name='form_$field_id' title='$description'>";
124 echo "<option value='0'></option>";
125 $pres = get_pharmacies();
126 while ($prow = sqlFetchArray($pres)) {
128 echo "<option value='$key'";
129 if ($currvalue == $key) echo " selected";
130 echo '>' . $prow['name'] . ' ' . $prow['area_code'] . '-' .
131 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
132 $prow['line1'] . ' / ' . $prow['city'] . "</option>";
138 else if ($data_type == 13) {
139 echo "<select name='form_$field_id' title='$description'>";
140 echo "<option value=''> </option>";
141 $squads = acl_get_squads();
143 foreach ($squads as $key => $value) {
144 echo "<option value='$key'";
145 if ($currvalue == $key) echo " selected";
146 echo ">" . $value[3] . "</option>\n";
152 // address book, preferring organization name if it exists and is not in parentheses
153 else if ($data_type == 14) {
154 $ures = sqlStatement("SELECT id, fname, lname, organization FROM users " .
155 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
156 "ORDER BY organization, lname, fname");
157 echo "<select name='form_$field_id' title='$description'>";
158 echo "<option value=''>" . xl('Unassigned') . "</option>";
159 while ($urow = sqlFetchArray($ures)) {
160 $uname = $urow['organization'];
161 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
162 $uname = $urow['lname'];
163 if ($urow['fname']) $uname .= ", " . $urow['fname'];
165 echo "<option value='" . $urow['id'] . "'";
166 if ($urow['id'] == $currvalue) echo " selected";
167 echo ">$uname</option>";
172 // a billing code (only one of these allowed!)
173 else if ($data_type == 15) {
174 echo "<input type='text'" .
175 " name='form_$field_id'" .
176 " id='form_related_code'" .
177 " size='" . $frow['fld_length'] . "'" .
178 " maxlength='" . $frow['max_length'] . "'" .
179 " title='$description'" .
180 " value='$currescaped'" .
181 " onclick='sel_related()' readonly" .
185 // a set of labeled checkboxes
186 else if ($data_type == 21) {
187 $avalue = explode('|', $currvalue);
188 $lres = sqlStatement("SELECT * FROM list_options " .
189 "WHERE list_id = '$list_id' ORDER BY seq");
190 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
191 $option_id = $lrow['option_id'];
192 if ($count) echo "<br />";
193 echo "<input type='checkbox' name='form_{$field_id}[$option_id]' value='1'";
194 if (in_array($option_id, $avalue)) echo " checked";
195 echo ">" . $lrow['title'];
199 // a set of labeled text input fields
200 else if ($data_type == 22) {
201 $tmp = explode('|', $currvalue);
203 foreach ($tmp as $value) {
204 if (preg_match('/^(\w+?):(.*)$/', $value, $matches)) {
205 $avalue[$matches[1]] = $matches[2];
208 $lres = sqlStatement("SELECT * FROM list_options " .
209 "WHERE list_id = '$list_id' ORDER BY seq");
210 echo "<table cellpadding='0' cellspacing='0'>";
211 while ($lrow = sqlFetchArray($lres)) {
212 $option_id = $lrow['option_id'];
213 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
214 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
215 echo "<tr><td>" . $lrow['title'] . " </td>";
216 echo "<td><input type='text'" .
217 " name='form_{$field_id}[$option_id]'" .
218 " size='" . $frow['fld_length'] . "'" .
219 " maxlength='$maxlength'" .
220 " value='" . $avalue[$option_id] . "'";
221 echo " /></td></tr>";
226 // a set of exam results; 3 radio buttons and a text field:
227 else if ($data_type == 23) {
228 $tmp = explode('|', $currvalue);
230 foreach ($tmp as $value) {
231 if (preg_match('/^(\w+?):(.*)$/', $value, $matches)) {
232 $avalue[$matches[1]] = $matches[2];
235 $lres = sqlStatement("SELECT * FROM list_options " .
236 "WHERE list_id = '$list_id' ORDER BY seq");
237 echo "<table cellpadding='0' cellspacing='0'>";
238 echo "<tr><td> </td><td class='bold'>N/A </td><td class='bold'>Nor </td>" .
239 "<td class='bold'>Abn </td><td class='bold'>Date/Notes</td></tr>";
240 while ($lrow = sqlFetchArray($lres)) {
241 $option_id = $lrow['option_id'];
242 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
243 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
244 $restype = substr($avalue[$option_id], 0, 1);
245 $resnote = substr($avalue[$option_id], 2);
246 echo "<tr><td>" . $lrow['title'] . " </td>";
247 for ($i = 0; $i < 3; ++
$i) {
248 echo "<td><input type='radio'" .
249 " name='radio_{$field_id}[$option_id]'" .
251 if ($restype === "$i") echo " checked";
254 echo "<td><input type='text'" .
255 " name='form_{$field_id}[$option_id]'" .
256 " size='" . $frow['fld_length'] . "'" .
257 " maxlength='$maxlength'" .
258 " value='$resnote' /></td>";
264 // the list of active allergies for the current patient
265 // this is read-only!
266 else if ($data_type == 24) {
267 $query = "SELECT title, comments FROM lists WHERE " .
268 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
270 // echo "<!-- $query -->\n"; // debugging
271 $lres = sqlStatement($query);
273 while ($lrow = sqlFetchArray($lres)) {
274 if ($count++
) echo "<br />";
276 if ($lrow['comments']) echo ' (' . $lrow['comments'] . ')';
282 function generate_display_field($frow, $currvalue) {
283 $data_type = $frow['data_type'];
284 $field_id = $frow['field_id'];
285 $list_id = $frow['list_id'];
288 // generic selection list
289 if ($data_type == 1) {
290 $lrow = sqlQuery("SELECT title FROM list_options " .
291 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
296 else if ($data_type == 2) {
300 // long or multi-line text field
301 else if ($data_type == 3) {
302 $s = nl2br($currvalue);
306 else if ($data_type == 4) {
311 else if ($data_type == 10 ||
$data_type == 11) {
312 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
313 "WHERE id = '$currvalue'");
314 $s = ucwords($urow['fname'] . " " . $urow['lname']);
318 else if ($data_type == 12) {
319 $pres = get_pharmacies();
320 while ($prow = sqlFetchArray($pres)) {
322 if ($currvalue == $key) {
323 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
324 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
325 $prow['line1'] . ' / ' . $prow['city'];
331 else if ($data_type == 13) {
332 $squads = acl_get_squads();
334 foreach ($squads as $key => $value) {
335 if ($currvalue == $key) {
343 else if ($data_type == 14) {
344 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
345 "WHERE id = '$currvalue'");
346 $uname = $urow['lname'];
347 if ($urow['fname']) $uname .= ", " . $urow['fname'];
352 else if ($data_type == 15) {
356 // a set of labeled checkboxes
357 else if ($data_type == 21) {
358 $avalue = explode('|', $currvalue);
359 $lres = sqlStatement("SELECT * FROM list_options " .
360 "WHERE list_id = '$list_id' ORDER BY seq");
362 while ($lrow = sqlFetchArray($lres)) {
363 $option_id = $lrow['option_id'];
364 if (in_array($option_id, $avalue)) {
365 if ($count++
) $s .= "<br />";
366 $s .= $lrow['title'];
371 // a set of labeled text input fields
372 else if ($data_type == 22) {
373 $tmp = explode('|', $currvalue);
375 foreach ($tmp as $value) {
376 if (preg_match('/^(\w+?):(.*)$/', $value, $matches)) {
377 $avalue[$matches[1]] = $matches[2];
380 $lres = sqlStatement("SELECT * FROM list_options " .
381 "WHERE list_id = '$list_id' ORDER BY seq");
382 $s .= "<table cellpadding='0' cellspacing='0'>";
383 while ($lrow = sqlFetchArray($lres)) {
384 $option_id = $lrow['option_id'];
385 if (empty($avalue[$option_id])) continue;
386 $s .= "<tr><td class='bold' valign='top'>" . $lrow['title'] . ": </td>";
387 $s .= "<td class='text' valign='top'>" . $avalue[$option_id] . "</td></tr>";
392 // a set of exam results; 3 radio buttons and a text field:
393 else if ($data_type == 23) {
394 $tmp = explode('|', $currvalue);
396 foreach ($tmp as $value) {
397 if (preg_match('/^(\w+?):(.*)$/', $value, $matches)) {
398 $avalue[$matches[1]] = $matches[2];
401 $lres = sqlStatement("SELECT * FROM list_options " .
402 "WHERE list_id = '$list_id' ORDER BY seq");
403 $s .= "<table cellpadding='0' cellspacing='0'>";
404 while ($lrow = sqlFetchArray($lres)) {
405 $option_id = $lrow['option_id'];
406 $restype = substr($avalue[$option_id], 0, 1);
407 $resnote = substr($avalue[$option_id], 2);
408 if (empty($restype) && empty($resnote)) continue;
409 $s .= "<tr><td class='bold' valign='top'>" . $lrow['title'] . " </td>";
410 $restype = ($restype == '1') ?
'Normal' : (($restype == '2') ?
'Abnormal' : 'N/A');
411 $s .= "<td class='text' valign='top'>$restype</td></tr>";
412 $s .= "<td class='text' valign='top'>$resnote</td></tr>";
418 // the list of active allergies for the current patient
419 else if ($data_type == 24) {
420 $query = "SELECT title, comments FROM lists WHERE " .
421 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
423 // echo "<!-- $query -->\n"; // debugging
424 $lres = sqlStatement($query);
426 while ($lrow = sqlFetchArray($lres)) {
427 if ($count++
) $s .= "<br />";
428 $s .= $lrow['title'];
429 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
436 $CPR = 4; // cells per row of generic data
441 function disp_end_cell() {
442 global $item_count, $cell_count;
443 if ($item_count > 0) {
449 function disp_end_row() {
450 global $cell_count, $CPR;
452 if ($cell_count > 0) {
453 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
459 function disp_end_group() {
461 if (strlen($last_group) > 0) {
466 function display_layout_rows($formtype, $result1, $result2='') {
467 global $item_count, $cell_count, $last_group, $CPR;
469 $fres = sqlStatement("SELECT * FROM layout_options " .
470 "WHERE form_id = '$formtype' AND uor > 0 " .
471 "ORDER BY group_name, seq");
473 while ($frow = sqlFetchArray($fres)) {
474 $this_group = $frow['group_name'];
475 $titlecols = $frow['titlecols'];
476 $datacols = $frow['datacols'];
477 $data_type = $frow['data_type'];
478 $field_id = $frow['field_id'];
479 $list_id = $frow['list_id'];
482 if ($formtype == 'DEM') {
483 if ($GLOBALS['athletic_team']) {
484 // Skip fitness level and return-to-play date because those appear
485 // in a special display/update form on this page.
486 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
488 if (strpos($field_id, 'em_') === 0) {
489 $tmp = substr($field_id, 3);
490 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
493 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
497 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
500 // Handle a data category (group) change.
501 if (strcmp($this_group, $last_group) != 0) {
503 $group_name = substr($this_group, 1);
504 $last_group = $this_group;
507 // Handle starting of a new row.
508 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
510 echo " <tr><td class='bold' style='padding-right:5pt' valign='top'>";
512 echo "<font color='#008800'>$group_name</font>";
520 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
522 // Handle starting of a new label cell.
523 if ($titlecols > 0) {
525 echo "<td class='bold' colspan='$titlecols' valign='top'";
526 if ($cell_count == 2) echo " style='padding-left:10pt'";
528 $cell_count +
= $titlecols;
532 if ($frow['title']) echo $frow['title'] . ":"; else echo " ";
534 // Handle starting of a new data cell.
537 echo "<td colspan='$datacols' class='text' valign='top'";
538 if ($cell_count > 0) echo " style='padding-left:5pt'";
540 $cell_count +
= $datacols;
544 echo generate_display_field($frow, $currvalue);