added cache clearing support for dialog.js (#411)
[openemr.git] / interface / orders / types_edit.php
blobfe4c9ecd32cca6f8130f53e6694b062704c7ffa8
1 <?php
2 // Copyright (C) 2010-2014 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/acl.inc");
11 require_once("$srcdir/options.inc.php");
12 require_once("$srcdir/formdata.inc.php");
14 $typeid = formData('typeid', 'R') + 0;
15 $parent = formData('parent', 'R') + 0;
17 $info_msg = "";
19 function QuotedOrNull($fld) {
20 $fld = formDataCore($fld,true);
21 if ($fld) return "'$fld'";
22 return "NULL";
25 function invalue($name) {
26 $fld = formData($name,"P",true);
27 return "'$fld'";
30 function rbinput($name, $value, $desc, $colname) {
31 global $row;
32 $ret = "<input type='radio' name='$name' value='$value'";
33 if ($row[$colname] == $value) $ret .= " checked";
34 $ret .= " />$desc";
35 return $ret;
38 function rbvalue($rbname) {
39 $tmp = $_POST[$rbname];
40 if (! $tmp) $tmp = '0';
41 return "'$tmp'";
44 function cbvalue($cbname) {
45 return empty($_POST[$cbname]) ? 0 : 1;
48 function recursiveDelete($typeid) {
49 $res = sqlStatement("SELECT procedure_type_id FROM " .
50 "procedure_type WHERE parent = '$typeid'");
51 while ($row = sqlFetchArray($res)) {
52 recursiveDelete($row['procedure_type_id']);
54 sqlStatement("DELETE FROM procedure_type WHERE " .
55 "procedure_type_id = '$typeid'");
59 <html>
60 <head>
61 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
62 <title><?php echo $typeid ? xlt('Edit') : xlt('Add New'); ?> <?php echo xlt('Order/Result Type'); ?></title>
63 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
65 <style>
66 td { font-size:10pt; }
68 .inputtext {
69 padding-left:2px;
70 padding-right:2px;
73 .button {
74 font-family:sans-serif;
75 font-size:9pt;
76 font-weight:bold;
79 .ordonly { }
80 .resonly { }
82 </style>
84 <script type="text/javascript" src="../../library/topdialog.js"></script>
85 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
86 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script>
88 <script language="JavaScript">
90 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
92 // The name of the form field for find-code popup results.
93 var rcvarname;
95 // This is for callback by the find-code popup.
96 // Appends to or erases the current list of related codes.
97 function set_related(codetype, code, selector, codedesc) {
98 var f = document.forms[0];
99 var s = f[rcvarname].value;
100 if (code) {
101 if (s.length > 0) s += ';';
102 s += codetype + ':' + code;
103 } else {
104 s = '';
106 f[rcvarname].value = s;
109 // This invokes the find-code popup.
110 function sel_related(varname) {
111 if (typeof varname == 'undefined') varname = 'form_related_code';
112 rcvarname = varname;
113 dlgopen('../patient_file/encounter/find_code_popup.php', '_blank', 500, 400);
116 // Show or hide sections depending on procedure type.
117 function proc_type_changed() {
118 var f = document.forms[0];
119 var pt = f.form_procedure_type;
120 var ix = pt.selectedIndex;
121 if (ix < 0) ix = 0;
122 var ptval = pt.options[ix].value;
123 var ptpfx = ptval.substring(0, 3);
124 $('.ordonly').hide();
125 $('.resonly').hide();
126 if (ptpfx == 'ord') $('.ordonly').show();
127 if (ptpfx == 'res'|| ptpfx == 'rec') $('.resonly').show();
130 $(document).ready(function() {
131 proc_type_changed();
134 </script>
136 </head>
138 <body class="body_top">
139 <?php
140 // If we are saving, then save and close the window.
142 if ($_POST['form_save']) {
144 $sets =
145 "name = " . invalue('form_name') . ", " .
146 "lab_id = " . invalue('form_lab_id') . ", " .
147 "procedure_code = " . invalue('form_procedure_code') . ", " .
148 "procedure_type = " . invalue('form_procedure_type') . ", " .
149 "body_site = " . invalue('form_body_site') . ", " .
150 "specimen = " . invalue('form_specimen') . ", " .
151 "route_admin = " . invalue('form_route_admin') . ", " .
152 "laterality = " . invalue('form_laterality') . ", " .
153 "description = " . invalue('form_description') . ", " .
154 "units = " . invalue('form_units') . ", " .
155 "`range` = " . invalue('form_range') . ", " .
156 "standard_code = " . invalue('form_standard_code') . ", " .
157 "related_code = " . invalue('form_related_code') . ", " .
158 "seq = " . invalue('form_seq');
160 if ($typeid) {
161 sqlStatement("UPDATE procedure_type SET $sets WHERE procedure_type_id = '$typeid'");
162 // Get parent ID so we can refresh the tree view.
163 $row = sqlQuery("SELECT parent FROM procedure_type WHERE " .
164 "procedure_type_id = '$typeid'");
165 $parent = $row['parent'];
166 } else {
167 $newid = sqlInsert("INSERT INTO procedure_type SET parent = '$parent', $sets");
168 // $newid is not really used in this script
172 else if ($_POST['form_delete']) {
174 if ($typeid) {
175 // Get parent ID so we can refresh the tree view after deleting.
176 $row = sqlQuery("SELECT parent FROM procedure_type WHERE " .
177 "procedure_type_id = '$typeid'");
178 $parent = $row['parent'];
179 recursiveDelete($typeid);
184 if ($_POST['form_save'] || $_POST['form_delete']) {
185 // Find out if this parent still has any children.
186 $trow = sqlQuery("SELECT procedure_type_id FROM procedure_type WHERE parent = '$parent' LIMIT 1");
187 $haskids = empty($trow['procedure_type_id']) ? 'false' : 'true';
188 // Close this window and redisplay the updated list.
189 echo "<script language='JavaScript'>\n";
190 if ($info_msg) echo " alert('$info_msg');\n";
191 echo " window.close();\n";
192 echo " if (opener.refreshFamily) opener.refreshFamily($parent,$haskids);\n";
193 echo "</script></body></html>\n";
194 exit();
197 if ($typeid) {
198 $row = sqlQuery("SELECT * FROM procedure_type WHERE procedure_type_id = '$typeid'");
201 <form method='post' name='theform'
202 action='types_edit.php?typeid=<?php echo $typeid ?>&parent=<?php echo $parent ?>'>
203 <!-- no restoreSession() on submit because session data are not relevant -->
205 <center>
207 <table border='0' width='100%'>
209 <tr>
210 <td width='1%' nowrap><b><?php echo xlt('Procedure Type'); ?>:</b></td>
211 <td>
212 <?php
213 echo generate_select_list('form_procedure_type', 'proc_type', $row['procedure_type'],
214 xl('The type of this entity'), ' ', '', 'proc_type_changed()');
216 </td>
217 </tr>
219 <tr>
220 <td nowrap><b><?php echo xlt('Name'); ?>:</b></td>
221 <td>
222 <input type='text' size='40' name='form_name' maxlength='63'
223 value='<?php echo htmlspecialchars($row['name'], ENT_QUOTES); ?>'
224 title='<?php echo xlt('Your name for this category, procedure or result'); ?>'
225 style='width:100%' class='inputtext' />
226 </td>
227 </tr>
229 <tr>
230 <td nowrap><b><?php echo xlt('Description'); ?>:</b></td>
231 <td>
232 <input type='text' size='40' name='form_description' maxlength='255'
233 value='<?php echo htmlspecialchars($row['description'], ENT_QUOTES); ?>'
234 title='<?php echo xlt('Description of this procedure or result code'); ?>'
235 style='width:100%' class='inputtext' />
236 </td>
237 </tr>
239 <tr>
240 <td nowrap><b><?php echo xlt('Sequence'); ?>:</b></td>
241 <td>
242 <input type='text' size='4' name='form_seq' maxlength='11'
243 value='<?php echo $row['seq'] + 0; ?>'
244 title='<?php echo xla('Relative ordering of this entity'); ?>'
245 class='inputtext' />
246 </td>
247 </tr>
249 <tr class='ordonly'>
250 <td width='1%' nowrap><b><?php echo xlt('Order From'); ?>:</b></td>
251 <td>
252 <select name='form_lab_id' title='<?php echo xla('The entity performing this procedure'); ?>'>
253 <?php
254 $ppres = sqlStatement("SELECT ppid, name FROM procedure_providers " .
255 "ORDER BY name, ppid");
256 while ($pprow = sqlFetchArray($ppres)) {
257 echo "<option value='" . attr($pprow['ppid']) . "'";
258 if ($pprow['ppid'] == $row['lab_id']) echo " selected";
259 echo ">" . text($pprow['name']) . "</option>";
262 </select>
263 </td>
264 </tr>
266 <tr class='ordonly resonly'>
267 <td nowrap><b><?php echo xlt('Identifying Code'); ?>:</b></td>
268 <td>
269 <input type='text' size='40' name='form_procedure_code' maxlength='31'
270 value='<?php echo htmlspecialchars($row['procedure_code'], ENT_QUOTES); ?>'
271 title='<?php echo xla('The vendor-specific code identifying this procedure or result'); ?>'
272 style='width:100%' class='inputtext' />
273 </td>
274 </tr>
276 <tr class='ordonly'>
277 <td nowrap><b><?php echo xlt('Standard Code'); ?>:</b></td>
278 <td>
279 <!--
280 <input type='text' size='50' name='form_standard_code'
281 value='<?php echo $row['standard_code'] ?>' onclick='sel_related("form_standard_code")'
282 title='<?php echo xla('Click to select an industry-standard code for this procedure'); ?>'
283 style='width:100%' readonly />
285 <input type='text' size='50' name='form_standard_code'
286 value='<?php echo attr($row['standard_code']); ?>'
287 title='<?php echo xla('Enter the LOINC code for this procedure'); ?>'
288 style='width:100%' />
289 </td>
290 </tr>
292 <tr class='ordonly'>
293 <td width='1%' nowrap><b><?php echo xlt('Body Site'); ?>:</b></td>
294 <td>
295 <?php
296 generate_form_field(array('data_type' => 1, 'field_id' => 'body_site',
297 'list_id' => 'proc_body_site',
298 'description' => xl('Body site, if applicable')), $row['body_site']);
300 </td>
301 </tr>
303 <tr class='ordonly'>
304 <td width='1%' nowrap><b><?php echo xlt('Specimen Type'); ?>:</b></td>
305 <td>
306 <?php
307 generate_form_field(array('data_type' => 1, 'field_id' => 'specimen',
308 'list_id' => 'proc_specimen',
309 'description' => xl('Specimen Type')),
310 $row['specimen']);
312 </td>
313 </tr>
315 <tr class='ordonly'>
316 <td width='1%' nowrap><b><?php echo xlt('Administer Via'); ?>:</b></td>
317 <td>
318 <?php
319 generate_form_field(array('data_type' => 1, 'field_id' => 'route_admin',
320 'list_id' => 'proc_route',
321 'description' => xl('Route of administration, if applicable')),
322 $row['route_admin']);
324 </td>
325 </tr>
327 <tr class='ordonly'>
328 <td width='1%' nowrap><b><?php echo xlt('Laterality'); ?>:</b></td>
329 <td>
330 <?php
331 generate_form_field(array('data_type' => 1, 'field_id' => 'laterality',
332 'list_id' => 'proc_lat',
333 'description' => xl('Laterality of this procedure, if applicable')),
334 $row['laterality']);
336 </td>
337 </tr>
339 <tr class='resonly'>
340 <td width='1%' nowrap><b><?php echo xlt('Default Units'); ?>:</b></td>
341 <td>
342 <?php
343 generate_form_field(array('data_type' => 1, 'field_id' => 'units',
344 'list_id' => 'proc_unit',
345 'description' => xl('Optional default units for manual entry of results')),
346 $row['units']);
348 </td>
349 </tr>
351 <tr class='resonly'>
352 <td nowrap><b><?php echo xlt('Default Range'); ?>:</b></td>
353 <td>
354 <input type='text' size='40' name='form_range' maxlength='255'
355 value='<?php echo htmlspecialchars($row['range'], ENT_QUOTES); ?>'
356 title='<?php echo xla('Optional default range for manual entry of results'); ?>'
357 style='width:100%' class='inputtext' />
358 </td>
359 </tr>
361 <tr class='resonly'>
362 <td nowrap><b><?php echo xlt('Followup Services'); ?>:</b></td>
363 <td>
364 <input type='text' size='50' name='form_related_code'
365 value='<?php echo $row['related_code'] ?>' onclick='sel_related("form_related_code")'
366 title='<?php echo xla('Click to select services to perform if this result is abnormal'); ?>'
367 style='width:100%' readonly />
368 </td>
369 </tr>
371 </table>
373 <br />
375 <input type='submit' name='form_save' value='<?php echo xla('Save'); ?>' />
377 <?php if ($typeid) { ?>
378 &nbsp;
379 <input type='submit' name='form_delete' value='<?php echo xla('Delete'); ?>' style='color:red' />
380 <?php } ?>
382 &nbsp;
383 <input type='button' value='<?php echo xla('Cancel'); ?>' onclick='window.close()' />
384 </p>
386 </center>
387 </form>
388 </body>
389 </html>