added inventory list report
[openemr.git] / library / options.inc.php
blobccc066a450ff8bd4c5485117e6f65c2b57b609dc
1 <?php
3 $date_init = "";
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 " .
10 "AND p.type = 2 " .
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))
36 echo " selected";
37 $got_selected = TRUE;
39 echo ">" . $lrow['title'] . "</option>\n";
41 if (!$got_selected && strlen($currvalue) > 0) {
42 echo "<option value='$currescaped' selected>* $currescaped *</option>";
43 echo "</select>";
44 echo " <font color='red' title='Please choose a valid selection " .
45 "from the list'>Fix this!</font>";
47 else {
48 echo "</select>";
52 // simple text field
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)'";
62 echo " />";
65 // long or multi-line text field
66 else if ($data_type == 3) {
67 echo "<textarea" .
68 " name='form_$field_id'" .
69 " title='$description'" .
70 " cols='" . $frow['fld_length'] . "'" .
71 " rows='" . $frow['max_length'] . "'>" .
72 $currescaped . "</textarea>";
75 // date
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>";
101 echo "</select>";
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>";
118 echo "</select>";
121 // pharmacy list
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)) {
127 $key = $prow['id'];
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>";
134 echo "</select>";
137 // squads
138 else if ($data_type == 13) {
139 echo "<select name='form_$field_id' title='$description'>";
140 echo "<option value=''>&nbsp;</option>";
141 $squads = acl_get_squads();
142 if ($squads) {
143 foreach ($squads as $key => $value) {
144 echo "<option value='$key'";
145 if ($currvalue == $key) echo " selected";
146 echo ">" . $value[3] . "</option>\n";
149 echo "</select>";
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>";
169 echo "</select>";
172 // a set of labeled checkboxes
173 else if ($data_type == 21) {
174 $avalue = explode('|', $currvalue);
175 $lres = sqlStatement("SELECT * FROM list_options " .
176 "WHERE list_id = '$list_id' ORDER BY seq");
177 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
178 $option_id = $lrow['option_id'];
179 if ($count) echo "<br />";
180 echo "<input type='checkbox' name='form_{$field_id}[$option_id]' value='1'";
181 if (in_array($option_id, $avalue)) echo " checked";
182 echo ">" . $lrow['title'];
186 // a set of labeled text input fields
187 else if ($data_type == 22) {
188 $tmp = explode('|', $currvalue);
189 $avalue = array();
190 foreach ($tmp as $value) {
191 if (preg_match('/^(\w+?):(.*)$/', $value, $matches)) {
192 $avalue[$matches[1]] = $matches[2];
195 $lres = sqlStatement("SELECT * FROM list_options " .
196 "WHERE list_id = '$list_id' ORDER BY seq");
197 echo "<table cellpadding='0' cellspacing='0'>";
198 while ($lrow = sqlFetchArray($lres)) {
199 $option_id = $lrow['option_id'];
200 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
201 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
202 echo "<tr><td>" . $lrow['title'] . "&nbsp;</td>";
203 echo "<td><input type='text'" .
204 " name='form_{$field_id}[$option_id]'" .
205 " size='" . $frow['fld_length'] . "'" .
206 " maxlength='$maxlength'" .
207 " value='" . $avalue[$option_id] . "'";
208 echo " /></td></tr>";
210 echo "</table>";
213 // a set of exam results; 3 radio buttons and a text field:
214 else if ($data_type == 23) {
215 $tmp = explode('|', $currvalue);
216 $avalue = array();
217 foreach ($tmp as $value) {
218 if (preg_match('/^(\w+?):(.*)$/', $value, $matches)) {
219 $avalue[$matches[1]] = $matches[2];
222 $lres = sqlStatement("SELECT * FROM list_options " .
223 "WHERE list_id = '$list_id' ORDER BY seq");
224 echo "<table cellpadding='0' cellspacing='0'>";
225 echo "<tr><td>&nbsp;</td><td class='bold'>N/A&nbsp;</td><td class='bold'>Nor&nbsp;</td>" .
226 "<td class='bold'>Abn&nbsp;</td><td class='bold'>Date/Notes</td></tr>";
227 while ($lrow = sqlFetchArray($lres)) {
228 $option_id = $lrow['option_id'];
229 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
230 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
231 $restype = substr($avalue[$option_id], 0, 1);
232 $resnote = substr($avalue[$option_id], 2);
233 echo "<tr><td>" . $lrow['title'] . "&nbsp;</td>";
234 for ($i = 0; $i < 3; ++$i) {
235 echo "<td><input type='radio'" .
236 " name='radio_{$field_id}[$option_id]'" .
237 " value='$i'";
238 if ($restype === "$i") echo " checked";
239 echo " /></td>";
241 echo "<td><input type='text'" .
242 " name='form_{$field_id}[$option_id]'" .
243 " size='" . $frow['fld_length'] . "'" .
244 " maxlength='$maxlength'" .
245 " value='$resnote' /></td>";
246 echo "</tr>";
248 echo "</table>";
253 function generate_display_field($frow, $currvalue) {
254 $data_type = $frow['data_type'];
255 $field_id = $frow['field_id'];
256 $list_id = $frow['list_id'];
257 $s = '';
259 // generic selection list
260 if ($data_type == 1) {
261 $lrow = sqlQuery("SELECT title FROM list_options " .
262 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
263 $s = $lrow['title'];
266 // simple text field
267 else if ($data_type == 2) {
268 $s = $currvalue;
271 // long or multi-line text field
272 else if ($data_type == 3) {
273 $s = nl2br($currvalue);
276 // date
277 else if ($data_type == 4) {
278 $s = $currvalue;
281 // provider
282 else if ($data_type == 10 || $data_type == 11) {
283 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
284 "WHERE id = '$currvalue'");
285 $s = ucwords($urow['fname'] . " " . $urow['lname']);
288 // pharmacy list
289 else if ($data_type == 12) {
290 $pres = get_pharmacies();
291 while ($prow = sqlFetchArray($pres)) {
292 $key = $prow['id'];
293 if ($currvalue == $key) {
294 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
295 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
296 $prow['line1'] . ' / ' . $prow['city'];
301 // squads
302 else if ($data_type == 13) {
303 $squads = acl_get_squads();
304 if ($squads) {
305 foreach ($squads as $key => $value) {
306 if ($currvalue == $key) {
307 $s .= $value[3];
313 // address book
314 else if ($data_type == 14) {
315 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
316 "WHERE id = '$currvalue'");
317 $uname = $urow['lname'];
318 if ($urow['fname']) $uname .= ", " . $urow['fname'];
319 $s = $uname;
322 // a set of labeled checkboxes
323 else if ($data_type == 21) {
324 $avalue = explode('|', $currvalue);
325 $lres = sqlStatement("SELECT * FROM list_options " .
326 "WHERE list_id = '$list_id' ORDER BY seq");
327 $count = 0;
328 while ($lrow = sqlFetchArray($lres)) {
329 $option_id = $lrow['option_id'];
330 if (in_array($option_id, $avalue)) {
331 if ($count++) $s .= "<br />";
332 $s .= $lrow['title'];
337 // a set of labeled text input fields
338 else if ($data_type == 22) {
339 $tmp = explode('|', $currvalue);
340 $avalue = array();
341 foreach ($tmp as $value) {
342 if (preg_match('/^(\w+?):(.*)$/', $value, $matches)) {
343 $avalue[$matches[1]] = $matches[2];
346 $lres = sqlStatement("SELECT * FROM list_options " .
347 "WHERE list_id = '$list_id' ORDER BY seq");
348 $s .= "<table cellpadding='0' cellspacing='0'>";
349 while ($lrow = sqlFetchArray($lres)) {
350 $option_id = $lrow['option_id'];
351 if (empty($avalue[$option_id])) continue;
352 $s .= "<tr><td class='bold'>" . $lrow['title'] . ":&nbsp;</td>";
353 $s .= "<td class='text'>" . $avalue[$option_id] . "</td></tr>";
355 $s .= "</table>";
358 // a set of exam results; 3 radio buttons and a text field:
359 else if ($data_type == 23) {
360 $tmp = explode('|', $currvalue);
361 $avalue = array();
362 foreach ($tmp as $value) {
363 if (preg_match('/^(\w+?):(.*)$/', $value, $matches)) {
364 $avalue[$matches[1]] = $matches[2];
367 $lres = sqlStatement("SELECT * FROM list_options " .
368 "WHERE list_id = '$list_id' ORDER BY seq");
369 $s .= "<table cellpadding='0' cellspacing='0'>";
370 while ($lrow = sqlFetchArray($lres)) {
371 $option_id = $lrow['option_id'];
372 $restype = substr($avalue[$option_id], 0, 1);
373 $resnote = substr($avalue[$option_id], 2);
374 if (empty($restype) && empty($resnote)) continue;
375 $s .= "<tr><td class='bold'>" . $lrow['title'] . "&nbsp;</td>";
376 $restype = ($restype == '1') ? 'Normal' : (($restype == '2') ? 'Abnormal' : 'N/A');
377 $s .= "<td class='text'>$restype</td></tr>";
378 $s .= "<td class='text'>$resnote</td></tr>";
379 $s .= "</tr>";
381 $s .= "</table>";
384 return $s;