migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / orders / types_edit.php
blobe5c2998245a2691354deda8f0dc72520bf4efca6
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");
13 $typeid = formData('typeid', 'R') + 0;
14 $parent = formData('parent', 'R') + 0;
16 $info_msg = "";
18 function QuotedOrNull($fld) {
19 $fld = formDataCore($fld,true);
20 if ($fld) return "'$fld'";
21 return "NULL";
24 function invalue($name) {
25 $fld = formData($name,"P",true);
26 return "'$fld'";
29 function rbinput($name, $value, $desc, $colname) {
30 global $row;
31 $ret = "<input type='radio' name='$name' value='$value'";
32 if ($row[$colname] == $value) $ret .= " checked";
33 $ret .= " />$desc";
34 return $ret;
37 function rbvalue($rbname) {
38 $tmp = $_POST[$rbname];
39 if (! $tmp) $tmp = '0';
40 return "'$tmp'";
43 function cbvalue($cbname) {
44 return empty($_POST[$cbname]) ? 0 : 1;
47 function recursiveDelete($typeid) {
48 $res = sqlStatement("SELECT procedure_type_id FROM " .
49 "procedure_type WHERE parent = '$typeid'");
50 while ($row = sqlFetchArray($res)) {
51 recursiveDelete($row['procedure_type_id']);
53 sqlStatement("DELETE FROM procedure_type WHERE " .
54 "procedure_type_id = '$typeid'");
58 <html>
59 <head>
60 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
61 <title><?php echo $typeid ? xlt('Edit') : xlt('Add New'); ?> <?php echo xlt('Order/Result Type'); ?></title>
62 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
64 <style>
65 td { font-size:10pt; }
67 .inputtext {
68 padding-left:2px;
69 padding-right:2px;
72 .button {
73 font-family:sans-serif;
74 font-size:9pt;
75 font-weight:bold;
78 .ordonly { }
79 .resonly { }
81 </style>
83 <script type="text/javascript" src="../../library/topdialog.js"></script>
84 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
85 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script>
87 <script language="JavaScript">
89 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
91 // The name of the form field for find-code popup results.
92 var rcvarname;
94 // This is for callback by the find-code popup.
95 // Appends to or erases the current list of related codes.
96 function set_related(codetype, code, selector, codedesc) {
97 var f = document.forms[0];
98 var s = f[rcvarname].value;
99 if (code) {
100 if (s.length > 0) s += ';';
101 s += codetype + ':' + code;
102 } else {
103 s = '';
105 f[rcvarname].value = s;
108 // This invokes the find-code popup.
109 function sel_related(varname) {
110 if (typeof varname == 'undefined') varname = 'form_related_code';
111 rcvarname = varname;
112 dlgopen('../patient_file/encounter/find_code_popup.php', '_blank', 500, 400);
115 // Show or hide sections depending on procedure type.
116 function proc_type_changed() {
117 var f = document.forms[0];
118 var pt = f.form_procedure_type;
119 var ix = pt.selectedIndex;
120 if (ix < 0) ix = 0;
121 var ptval = pt.options[ix].value;
122 var ptpfx = ptval.substring(0, 3);
123 $('.ordonly').hide();
124 $('.resonly').hide();
125 if (ptpfx == 'ord') $('.ordonly').show();
126 if (ptpfx == 'res'|| ptpfx == 'rec') $('.resonly').show();
129 $(document).ready(function() {
130 proc_type_changed();
133 </script>
135 </head>
137 <body class="body_top">
138 <?php
139 // If we are saving, then save and close the window.
141 if ($_POST['form_save']) {
143 $sets =
144 "name = " . invalue('form_name') . ", " .
145 "lab_id = " . invalue('form_lab_id') . ", " .
146 "procedure_code = " . invalue('form_procedure_code') . ", " .
147 "procedure_type = " . invalue('form_procedure_type') . ", " .
148 "body_site = " . invalue('form_body_site') . ", " .
149 "specimen = " . invalue('form_specimen') . ", " .
150 "route_admin = " . invalue('form_route_admin') . ", " .
151 "laterality = " . invalue('form_laterality') . ", " .
152 "description = " . invalue('form_description') . ", " .
153 "units = " . invalue('form_units') . ", " .
154 "`range` = " . invalue('form_range') . ", " .
155 "standard_code = " . invalue('form_standard_code') . ", " .
156 "related_code = " . invalue('form_related_code') . ", " .
157 "seq = " . invalue('form_seq');
159 if ($typeid) {
160 sqlStatement("UPDATE procedure_type SET $sets WHERE procedure_type_id = '$typeid'");
161 // Get parent ID so we can refresh the tree view.
162 $row = sqlQuery("SELECT parent FROM procedure_type WHERE " .
163 "procedure_type_id = '$typeid'");
164 $parent = $row['parent'];
165 } else {
166 $newid = sqlInsert("INSERT INTO procedure_type SET parent = '$parent', $sets");
167 // $newid is not really used in this script
171 else if ($_POST['form_delete']) {
173 if ($typeid) {
174 // Get parent ID so we can refresh the tree view after deleting.
175 $row = sqlQuery("SELECT parent FROM procedure_type WHERE " .
176 "procedure_type_id = '$typeid'");
177 $parent = $row['parent'];
178 recursiveDelete($typeid);
183 if ($_POST['form_save'] || $_POST['form_delete']) {
184 // Find out if this parent still has any children.
185 $trow = sqlQuery("SELECT procedure_type_id FROM procedure_type WHERE parent = '$parent' LIMIT 1");
186 $haskids = empty($trow['procedure_type_id']) ? 'false' : 'true';
187 // Close this window and redisplay the updated list.
188 echo "<script language='JavaScript'>\n";
189 if ($info_msg) echo " alert('$info_msg');\n";
190 echo " window.close();\n";
191 echo " if (opener.refreshFamily) opener.refreshFamily($parent,$haskids);\n";
192 echo "</script></body></html>\n";
193 exit();
196 if ($typeid) {
197 $row = sqlQuery("SELECT * FROM procedure_type WHERE procedure_type_id = '$typeid'");
200 <form method='post' name='theform'
201 action='types_edit.php?typeid=<?php echo $typeid ?>&parent=<?php echo $parent ?>'>
202 <!-- no restoreSession() on submit because session data are not relevant -->
204 <center>
206 <table border='0' width='100%'>
208 <tr>
209 <td width='1%' nowrap><b><?php echo xlt('Procedure Type'); ?>:</b></td>
210 <td>
211 <?php
212 echo generate_select_list('form_procedure_type', 'proc_type', $row['procedure_type'],
213 xl('The type of this entity'), ' ', '', 'proc_type_changed()');
215 </td>
216 </tr>
218 <tr>
219 <td nowrap><b><?php echo xlt('Name'); ?>:</b></td>
220 <td>
221 <input type='text' size='40' name='form_name' maxlength='63'
222 value='<?php echo htmlspecialchars($row['name'], ENT_QUOTES); ?>'
223 title='<?php echo xlt('Your name for this category, procedure or result'); ?>'
224 style='width:100%' class='inputtext' />
225 </td>
226 </tr>
228 <tr>
229 <td nowrap><b><?php echo xlt('Description'); ?>:</b></td>
230 <td>
231 <input type='text' size='40' name='form_description' maxlength='255'
232 value='<?php echo htmlspecialchars($row['description'], ENT_QUOTES); ?>'
233 title='<?php echo xlt('Description of this procedure or result code'); ?>'
234 style='width:100%' class='inputtext' />
235 </td>
236 </tr>
238 <tr>
239 <td nowrap><b><?php echo xlt('Sequence'); ?>:</b></td>
240 <td>
241 <input type='text' size='4' name='form_seq' maxlength='11'
242 value='<?php echo $row['seq'] + 0; ?>'
243 title='<?php echo xla('Relative ordering of this entity'); ?>'
244 class='inputtext' />
245 </td>
246 </tr>
248 <tr class='ordonly'>
249 <td width='1%' nowrap><b><?php echo xlt('Order From'); ?>:</b></td>
250 <td>
251 <select name='form_lab_id' title='<?php echo xla('The entity performing this procedure'); ?>'>
252 <?php
253 $ppres = sqlStatement("SELECT ppid, name FROM procedure_providers " .
254 "ORDER BY name, ppid");
255 while ($pprow = sqlFetchArray($ppres)) {
256 echo "<option value='" . attr($pprow['ppid']) . "'";
257 if ($pprow['ppid'] == $row['lab_id']) echo " selected";
258 echo ">" . text($pprow['name']) . "</option>";
261 </select>
262 </td>
263 </tr>
265 <tr class='ordonly resonly'>
266 <td nowrap><b><?php echo xlt('Identifying Code'); ?>:</b></td>
267 <td>
268 <input type='text' size='40' name='form_procedure_code' maxlength='31'
269 value='<?php echo htmlspecialchars($row['procedure_code'], ENT_QUOTES); ?>'
270 title='<?php echo xla('The vendor-specific code identifying this procedure or result'); ?>'
271 style='width:100%' class='inputtext' />
272 </td>
273 </tr>
275 <tr class='ordonly'>
276 <td nowrap><b><?php echo xlt('Standard Code'); ?>:</b></td>
277 <td>
278 <!--
279 <input type='text' size='50' name='form_standard_code'
280 value='<?php echo $row['standard_code'] ?>' onclick='sel_related("form_standard_code")'
281 title='<?php echo xla('Click to select an industry-standard code for this procedure'); ?>'
282 style='width:100%' readonly />
284 <input type='text' size='50' name='form_standard_code'
285 value='<?php echo attr($row['standard_code']); ?>'
286 title='<?php echo xla('Enter the LOINC code for this procedure'); ?>'
287 style='width:100%' />
288 </td>
289 </tr>
291 <tr class='ordonly'>
292 <td width='1%' nowrap><b><?php echo xlt('Body Site'); ?>:</b></td>
293 <td>
294 <?php
295 generate_form_field(array('data_type' => 1, 'field_id' => 'body_site',
296 'list_id' => 'proc_body_site',
297 'description' => xl('Body site, if applicable')), $row['body_site']);
299 </td>
300 </tr>
302 <tr class='ordonly'>
303 <td width='1%' nowrap><b><?php echo xlt('Specimen Type'); ?>:</b></td>
304 <td>
305 <?php
306 generate_form_field(array('data_type' => 1, 'field_id' => 'specimen',
307 'list_id' => 'proc_specimen',
308 'description' => xl('Specimen Type')),
309 $row['specimen']);
311 </td>
312 </tr>
314 <tr class='ordonly'>
315 <td width='1%' nowrap><b><?php echo xlt('Administer Via'); ?>:</b></td>
316 <td>
317 <?php
318 generate_form_field(array('data_type' => 1, 'field_id' => 'route_admin',
319 'list_id' => 'proc_route',
320 'description' => xl('Route of administration, if applicable')),
321 $row['route_admin']);
323 </td>
324 </tr>
326 <tr class='ordonly'>
327 <td width='1%' nowrap><b><?php echo xlt('Laterality'); ?>:</b></td>
328 <td>
329 <?php
330 generate_form_field(array('data_type' => 1, 'field_id' => 'laterality',
331 'list_id' => 'proc_lat',
332 'description' => xl('Laterality of this procedure, if applicable')),
333 $row['laterality']);
335 </td>
336 </tr>
338 <tr class='resonly'>
339 <td width='1%' nowrap><b><?php echo xlt('Default Units'); ?>:</b></td>
340 <td>
341 <?php
342 generate_form_field(array('data_type' => 1, 'field_id' => 'units',
343 'list_id' => 'proc_unit',
344 'description' => xl('Optional default units for manual entry of results')),
345 $row['units']);
347 </td>
348 </tr>
350 <tr class='resonly'>
351 <td nowrap><b><?php echo xlt('Default Range'); ?>:</b></td>
352 <td>
353 <input type='text' size='40' name='form_range' maxlength='255'
354 value='<?php echo htmlspecialchars($row['range'], ENT_QUOTES); ?>'
355 title='<?php echo xla('Optional default range for manual entry of results'); ?>'
356 style='width:100%' class='inputtext' />
357 </td>
358 </tr>
360 <tr class='resonly'>
361 <td nowrap><b><?php echo xlt('Followup Services'); ?>:</b></td>
362 <td>
363 <input type='text' size='50' name='form_related_code'
364 value='<?php echo $row['related_code'] ?>' onclick='sel_related("form_related_code")'
365 title='<?php echo xla('Click to select services to perform if this result is abnormal'); ?>'
366 style='width:100%' readonly />
367 </td>
368 </tr>
370 </table>
372 <br />
374 <input type='submit' name='form_save' value='<?php echo xla('Save'); ?>' />
376 <?php if ($typeid) { ?>
377 &nbsp;
378 <input type='submit' name='form_delete' value='<?php echo xla('Delete'); ?>' style='color:red' />
379 <?php } ?>
381 &nbsp;
382 <input type='button' value='<?php echo xla('Cancel'); ?>' onclick='window.close()' />
383 </p>
385 </center>
386 </form>
387 </body>
388 </html>