Highway to PSR2
[openemr.git] / interface / orders / types_edit.php
blob8b317e12a58aea8f87fccf0161c064422fa7b382
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)
20 $fld = formDataCore($fld, true);
21 if ($fld) {
22 return "'$fld'";
25 return "NULL";
28 function invalue($name)
30 $fld = formData($name, "P", true);
31 return "'$fld'";
34 function rbinput($name, $value, $desc, $colname)
36 global $row;
37 $ret = "<input type='radio' name='$name' value='$value'";
38 if ($row[$colname] == $value) {
39 $ret .= " checked";
42 $ret .= " />$desc";
43 return $ret;
46 function rbvalue($rbname)
48 $tmp = $_POST[$rbname];
49 if (! $tmp) {
50 $tmp = '0';
53 return "'$tmp'";
56 function cbvalue($cbname)
58 return empty($_POST[$cbname]) ? 0 : 1;
61 function recursiveDelete($typeid)
63 $res = sqlStatement("SELECT procedure_type_id FROM " .
64 "procedure_type WHERE parent = '$typeid'");
65 while ($row = sqlFetchArray($res)) {
66 recursiveDelete($row['procedure_type_id']);
69 sqlStatement("DELETE FROM procedure_type WHERE " .
70 "procedure_type_id = '$typeid'");
74 <html>
75 <head>
76 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
77 <title><?php echo $typeid ? xlt('Edit') : xlt('Add New'); ?> <?php echo xlt('Order/Result Type'); ?></title>
78 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
80 <style>
81 td { font-size:10pt; }
83 .inputtext {
84 padding-left:2px;
85 padding-right:2px;
88 .button {
89 font-family:sans-serif;
90 font-size:9pt;
91 font-weight:bold;
94 .ordonly { }
95 .resonly { }
97 </style>
99 <script type="text/javascript" src="../../library/topdialog.js"></script>
100 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
101 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script>
103 <script language="JavaScript">
105 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
107 // The name of the form field for find-code popup results.
108 var rcvarname;
110 // This is for callback by the find-code popup.
111 // Appends to or erases the current list of related codes.
112 function set_related(codetype, code, selector, codedesc) {
113 var f = document.forms[0];
114 var s = f[rcvarname].value;
115 if (code) {
116 if (s.length > 0) s += ';';
117 s += codetype + ':' + code;
118 } else {
119 s = '';
121 f[rcvarname].value = s;
124 // This invokes the find-code popup.
125 function sel_related(varname) {
126 if (typeof varname == 'undefined') varname = 'form_related_code';
127 rcvarname = varname;
128 dlgopen('../patient_file/encounter/find_code_popup.php', '_blank', 500, 400);
131 // Show or hide sections depending on procedure type.
132 function proc_type_changed() {
133 var f = document.forms[0];
134 var pt = f.form_procedure_type;
135 var ix = pt.selectedIndex;
136 if (ix < 0) ix = 0;
137 var ptval = pt.options[ix].value;
138 var ptpfx = ptval.substring(0, 3);
139 $('.ordonly').hide();
140 $('.resonly').hide();
141 if (ptpfx == 'ord') $('.ordonly').show();
142 if (ptpfx == 'res'|| ptpfx == 'rec') $('.resonly').show();
145 $(document).ready(function() {
146 proc_type_changed();
149 </script>
151 </head>
153 <body class="body_top">
154 <?php
155 // If we are saving, then save and close the window.
157 if ($_POST['form_save']) {
158 $sets =
159 "name = " . invalue('form_name') . ", " .
160 "lab_id = " . invalue('form_lab_id') . ", " .
161 "procedure_code = " . invalue('form_procedure_code') . ", " .
162 "procedure_type = " . invalue('form_procedure_type') . ", " .
163 "body_site = " . invalue('form_body_site') . ", " .
164 "specimen = " . invalue('form_specimen') . ", " .
165 "route_admin = " . invalue('form_route_admin') . ", " .
166 "laterality = " . invalue('form_laterality') . ", " .
167 "description = " . invalue('form_description') . ", " .
168 "units = " . invalue('form_units') . ", " .
169 "`range` = " . invalue('form_range') . ", " .
170 "standard_code = " . invalue('form_standard_code') . ", " .
171 "related_code = " . invalue('form_related_code') . ", " .
172 "seq = " . invalue('form_seq');
174 if ($typeid) {
175 sqlStatement("UPDATE procedure_type SET $sets WHERE procedure_type_id = '$typeid'");
176 // Get parent ID so we can refresh the tree view.
177 $row = sqlQuery("SELECT parent FROM procedure_type WHERE " .
178 "procedure_type_id = '$typeid'");
179 $parent = $row['parent'];
180 } else {
181 $newid = sqlInsert("INSERT INTO procedure_type SET parent = '$parent', $sets");
182 // $newid is not really used in this script
184 } else if ($_POST['form_delete']) {
185 if ($typeid) {
186 // Get parent ID so we can refresh the tree view after deleting.
187 $row = sqlQuery("SELECT parent FROM procedure_type WHERE " .
188 "procedure_type_id = '$typeid'");
189 $parent = $row['parent'];
190 recursiveDelete($typeid);
194 if ($_POST['form_save'] || $_POST['form_delete']) {
195 // Find out if this parent still has any children.
196 $trow = sqlQuery("SELECT procedure_type_id FROM procedure_type WHERE parent = '$parent' LIMIT 1");
197 $haskids = empty($trow['procedure_type_id']) ? 'false' : 'true';
198 // Close this window and redisplay the updated list.
199 echo "<script language='JavaScript'>\n";
200 if ($info_msg) {
201 echo " alert('$info_msg');\n";
204 echo " window.close();\n";
205 echo " if (opener.refreshFamily) opener.refreshFamily($parent,$haskids);\n";
206 echo "</script></body></html>\n";
207 exit();
210 if ($typeid) {
211 $row = sqlQuery("SELECT * FROM procedure_type WHERE procedure_type_id = '$typeid'");
214 <form method='post' name='theform'
215 action='types_edit.php?typeid=<?php echo $typeid ?>&parent=<?php echo $parent ?>'>
216 <!-- no restoreSession() on submit because session data are not relevant -->
218 <center>
220 <table border='0' width='100%'>
222 <tr>
223 <td width='1%' nowrap><b><?php echo xlt('Procedure Type'); ?>:</b></td>
224 <td>
225 <?php
226 echo generate_select_list(
227 'form_procedure_type',
228 'proc_type',
229 $row['procedure_type'],
230 xl('The type of this entity'),
231 ' ',
233 'proc_type_changed()'
236 </td>
237 </tr>
239 <tr>
240 <td nowrap><b><?php echo xlt('Name'); ?>:</b></td>
241 <td>
242 <input type='text' size='40' name='form_name' maxlength='63'
243 value='<?php echo htmlspecialchars($row['name'], ENT_QUOTES); ?>'
244 title='<?php echo xlt('Your name for this category, procedure or result'); ?>'
245 style='width:100%' class='inputtext' />
246 </td>
247 </tr>
249 <tr>
250 <td nowrap><b><?php echo xlt('Description'); ?>:</b></td>
251 <td>
252 <input type='text' size='40' name='form_description' maxlength='255'
253 value='<?php echo htmlspecialchars($row['description'], ENT_QUOTES); ?>'
254 title='<?php echo xlt('Description of this procedure or result code'); ?>'
255 style='width:100%' class='inputtext' />
256 </td>
257 </tr>
259 <tr>
260 <td nowrap><b><?php echo xlt('Sequence'); ?>:</b></td>
261 <td>
262 <input type='text' size='4' name='form_seq' maxlength='11'
263 value='<?php echo $row['seq'] + 0; ?>'
264 title='<?php echo xla('Relative ordering of this entity'); ?>'
265 class='inputtext' />
266 </td>
267 </tr>
269 <tr class='ordonly'>
270 <td width='1%' nowrap><b><?php echo xlt('Order From'); ?>:</b></td>
271 <td>
272 <select name='form_lab_id' title='<?php echo xla('The entity performing this procedure'); ?>'>
273 <?php
274 $ppres = sqlStatement("SELECT ppid, name FROM procedure_providers " .
275 "ORDER BY name, ppid");
276 while ($pprow = sqlFetchArray($ppres)) {
277 echo "<option value='" . attr($pprow['ppid']) . "'";
278 if ($pprow['ppid'] == $row['lab_id']) {
279 echo " selected";
282 echo ">" . text($pprow['name']) . "</option>";
285 </select>
286 </td>
287 </tr>
289 <tr class='ordonly resonly'>
290 <td nowrap><b><?php echo xlt('Identifying Code'); ?>:</b></td>
291 <td>
292 <input type='text' size='40' name='form_procedure_code' maxlength='31'
293 value='<?php echo htmlspecialchars($row['procedure_code'], ENT_QUOTES); ?>'
294 title='<?php echo xla('The vendor-specific code identifying this procedure or result'); ?>'
295 style='width:100%' class='inputtext' />
296 </td>
297 </tr>
299 <tr class='ordonly'>
300 <td nowrap><b><?php echo xlt('Standard Code'); ?>:</b></td>
301 <td>
302 <!--
303 <input type='text' size='50' name='form_standard_code'
304 value='<?php echo $row['standard_code'] ?>' onclick='sel_related("form_standard_code")'
305 title='<?php echo xla('Click to select an industry-standard code for this procedure'); ?>'
306 style='width:100%' readonly />
308 <input type='text' size='50' name='form_standard_code'
309 value='<?php echo attr($row['standard_code']); ?>'
310 title='<?php echo xla('Enter the LOINC code for this procedure'); ?>'
311 style='width:100%' />
312 </td>
313 </tr>
315 <tr class='ordonly'>
316 <td width='1%' nowrap><b><?php echo xlt('Body Site'); ?>:</b></td>
317 <td>
318 <?php
319 generate_form_field(array('data_type' => 1, 'field_id' => 'body_site',
320 'list_id' => 'proc_body_site',
321 'description' => xl('Body site, if applicable')), $row['body_site']);
323 </td>
324 </tr>
326 <tr class='ordonly'>
327 <td width='1%' nowrap><b><?php echo xlt('Specimen Type'); ?>:</b></td>
328 <td>
329 <?php
330 generate_form_field(
331 array('data_type' => 1, 'field_id' => 'specimen',
332 'list_id' => 'proc_specimen',
333 'description' => xl('Specimen Type')),
334 $row['specimen']
337 </td>
338 </tr>
340 <tr class='ordonly'>
341 <td width='1%' nowrap><b><?php echo xlt('Administer Via'); ?>:</b></td>
342 <td>
343 <?php
344 generate_form_field(
345 array('data_type' => 1, 'field_id' => 'route_admin',
346 'list_id' => 'proc_route',
347 'description' => xl('Route of administration, if applicable')),
348 $row['route_admin']
351 </td>
352 </tr>
354 <tr class='ordonly'>
355 <td width='1%' nowrap><b><?php echo xlt('Laterality'); ?>:</b></td>
356 <td>
357 <?php
358 generate_form_field(
359 array('data_type' => 1, 'field_id' => 'laterality',
360 'list_id' => 'proc_lat',
361 'description' => xl('Laterality of this procedure, if applicable')),
362 $row['laterality']
365 </td>
366 </tr>
368 <tr class='resonly'>
369 <td width='1%' nowrap><b><?php echo xlt('Default Units'); ?>:</b></td>
370 <td>
371 <?php
372 generate_form_field(
373 array('data_type' => 1, 'field_id' => 'units',
374 'list_id' => 'proc_unit',
375 'description' => xl('Optional default units for manual entry of results')),
376 $row['units']
379 </td>
380 </tr>
382 <tr class='resonly'>
383 <td nowrap><b><?php echo xlt('Default Range'); ?>:</b></td>
384 <td>
385 <input type='text' size='40' name='form_range' maxlength='255'
386 value='<?php echo htmlspecialchars($row['range'], ENT_QUOTES); ?>'
387 title='<?php echo xla('Optional default range for manual entry of results'); ?>'
388 style='width:100%' class='inputtext' />
389 </td>
390 </tr>
392 <tr class='resonly'>
393 <td nowrap><b><?php echo xlt('Followup Services'); ?>:</b></td>
394 <td>
395 <input type='text' size='50' name='form_related_code'
396 value='<?php echo $row['related_code'] ?>' onclick='sel_related("form_related_code")'
397 title='<?php echo xla('Click to select services to perform if this result is abnormal'); ?>'
398 style='width:100%' readonly />
399 </td>
400 </tr>
402 </table>
404 <br />
406 <input type='submit' name='form_save' value='<?php echo xla('Save'); ?>' />
408 <?php if ($typeid) { ?>
409 &nbsp;
410 <input type='submit' name='form_delete' value='<?php echo xla('Delete'); ?>' style='color:red' />
411 <?php } ?>
413 &nbsp;
414 <input type='button' value='<?php echo xla('Cancel'); ?>' onclick='window.close()' />
415 </p>
417 </center>
418 </form>
419 </body>
420 </html>