Changes to support electronic lab ordering and results.
[openemr.git] / interface / orders / types.php
blob1a4f7f96af21395e09807286a15c56b635f92be9
1 <?php
2 // Copyright (C) 2010-2012 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/formdata.inc.php");
13 // This script can be run either inside the OpenEMR frameset for order catalog
14 // maintenance, or as a popup window for selecting an item to order. In the
15 // popup case the GET variables 'popup' (a boolean) and 'order' (an optional
16 // item ID to select) will be provided, and maintenance may also be permitted.
18 $popup = empty($_GET['popup']) ? 0 : 1;
19 $order = formData('order', 'G') + 0;
20 $labid = formData('labid', 'G') + 0;
22 // If Save was clicked, set the result, close the window and exit.
24 if ($popup && $_POST['form_save']) {
25 $form_order = formData('form_order') + 0;
26 $ptrow = sqlQuery("SELECT name FROM procedure_type WHERE " .
27 "procedure_type_id = '$form_order'");
28 $name = addslashes($ptrow['name']);
30 <script language="JavaScript">
31 if (opener.closed || ! opener.set_proc_type) {
32 alert('<?php xl('The destination form was closed; I cannot act on your selection.','e'); ?>');
34 else {
35 opener.set_proc_type(<?php echo "$form_order, '$name'" ?>);
36 <?php
37 // This is to generate the "Questions at Order Entry" for the Procedure Order form.
38 // GET parms needed for this are: formid, formseq.
39 if (isset($_GET['formid'])) {
40 require_once("qoe.inc.php");
41 $qoe_init_javascript = '';
42 echo ' opener.set_proc_html("';
43 echo generate_qoe_html($form_order, intval($_GET['formid']), 0, intval($_GET['formseq']));
44 echo '", "' . $qoe_init_javascript . '");' . "\n";
48 window.close(); // comment out for debugging
49 </script>
50 <?php
51 exit();
53 // end Save logic
56 <html>
58 <head>
60 <title><?php xl('Order and Result Types','e'); ?></title>
62 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
64 <style type="text/css">
65 body {
66 font-family:sans-serif;
67 font-size:9pt;
68 font-weight:normal;
69 padding: 5px 3px 5px 3px;
71 #con0 table {
72 margin:0;
73 padding:0;
74 width:100%;
76 #con0 td {
77 padding:0pt;
78 font-family:sans-serif;
79 font-size:9pt;
81 .plusminus {
82 font-family:monospace;
83 font-size:10pt;
85 .haskids {
86 color:#0000dd;
87 cursor:pointer;
88 cursor:hand;
90 tr.head {
91 font-size:10pt;
92 background-color:#cccccc;
93 font-weight:bold;
95 tr.evenrow {
96 background-color:#ddddff;
98 tr.oddrow {
99 background-color:#ffffff;
102 .col1 {width:35%}
103 .col2 {width:8%}
104 .col3 {width:12%}
105 .col4 {width:35%}
106 .col5 {width:10%}
107 </style>
109 <script src="../../library/js/jquery-1.2.2.min.js" type="text/javascript"></script>
110 <?php if ($popup) { ?>
111 <script type="text/javascript" src="../../library/topdialog.js"></script>
112 <?php } ?>
113 <script type="text/javascript" src="../../library/dialog.js"></script>
115 <script language="JavaScript">
117 <?php if ($popup) require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
119 <?php
120 // Create array of IDs to pre-select, leaf to top.
121 echo "preopen = [";
122 echo $order > 0 ? $order : 0;
123 for ($parentid = $order; $parentid > 0;) {
124 $row = sqlQuery("SELECT parent FROM procedure_type WHERE procedure_type_id = '$parentid'");
125 $parentid = $row['parent'] + 0;
126 echo ", $parentid";
128 echo "];\n";
131 // initiate by loading the top-level nodes
132 $(document).ready(function(){
133 nextOpen();
136 // This is called repeatedly at initialization until all desired nodes
137 // have been opened.
138 function nextOpen() {
139 if (preopen.length) {
140 var thisid = preopen.pop();
141 if (thisid == 0 || preopen.length > 0) {
142 if (thisid > 0)
143 toggle(thisid);
144 else
145 $.getScript('types_ajax.php?id=' + thisid + '&order=<?php echo $order; ?>' + '&labid=<?php echo $labid; ?>');
147 else {
148 recolor();
151 else {
152 recolor();
156 // toggle expansion indicator from + to - or vice versa
157 function swapsign(td1, from, to) {
158 var s = td1.html();
159 var i = s.indexOf('>' + from + '<');
160 if (i >= 0) td1.html(s.substring(0,i+1) + to + s.substring(i+2));
163 // onclick handler to expand or collapse a node
164 function toggle(id) {
165 var td1 = $('#td' + id);
166 if (!td1.hasClass('haskids')) return;
167 if (td1.hasClass('isExpanded')) {
168 $('#con' + id).remove();
169 td1.removeClass('isExpanded');
170 swapsign(td1, '-', '+');
171 recolor();
173 else {
174 td1.parent().after('<tr class="outertr"><td colspan="5" id="con' + id + '" style="padding:0">Loading...</td></tr>');
175 td1.addClass('isExpanded');
176 swapsign(td1, '+', '-');
177 $.getScript('types_ajax.php?id=' + id + '&order=<?php echo $order; ?>' + '&labid=<?php echo $labid; ?>');
181 // Called by the edit window to refresh a given node's children
182 function refreshFamily(id, haskids) {
183 if (id) { // id == 0 means top level
184 var td1 = $('#td' + id);
185 if (td1.hasClass('isExpanded')) {
186 $('#con' + id).remove();
187 td1.removeClass('isExpanded');
188 swapsign(td1, '-', '+');
190 if (td1.hasClass('haskids') && !haskids) {
191 td1.removeClass('haskids');
192 // swapsign(td1, '+', '.');
193 swapsign(td1, '+', '|');
194 return;
196 if (!td1.hasClass('haskids') && haskids) {
197 td1.addClass('haskids');
198 // swapsign(td1, '.', '+');
199 swapsign(td1, '|', '+');
201 if (haskids) {
202 td1.parent().after('<tr class="outertr"><td colspan="5" id="con' + id + '" style="padding:0">Loading...</td></tr>');
203 td1.addClass('isExpanded');
204 swapsign(td1, '+', '-');
207 if (haskids)
208 $.getScript('types_ajax.php?id=' + id + '&order=<?php echo $order; ?>' + '&labid=<?php echo $labid; ?>');
209 else
210 recolor();
213 // edit a node
214 function enode(id) {
215 dlgopen('types_edit.php?parent=0&typeid=' + id, '_blank', 700, 550);
218 // add a node
219 function anode(id) {
220 dlgopen('types_edit.php?typeid=0&parent=' + id, '_blank', 700, 550);
223 // call this to alternate row colors when anything changes the number of rows
224 function recolor() {
225 var i = 0;
226 $('#con0 tr').each(function(index) {
227 // skip any row that contains other rows
228 if ($(this).hasClass('outertr')) return;
229 this.className = (i++ & 1) ? "evenrow" : "oddrow";
233 </script>
235 </head>
237 <body class="body_nav">
238 <center>
240 <h3 style='margin-top:0'><?php xl('Types of Orders and Results','e') ?></h3>
242 <form method='post' name='theform' action='types.php?popup=<?php echo $popup ?>&order=<?php
243 echo $order;
244 if (isset($_GET['formid' ])) echo '&formid=' . $_GET['formid'];
245 if (isset($_GET['formseq'])) echo '&formseq=' . $_GET['formseq'];
246 ?>'>
248 <table width='100%' cellspacing='0' cellpadding='0' border='0'>
249 <tr class='head'>
250 <th class='col1' align='left'>&nbsp;&nbsp;<?php xl('Name','e') ?></th>
251 <th class='col2' align='left'><?php xl('Order','e') ?></th>
252 <th class='col3' align='left'><?php xl('Code','e') ?></th>
253 <th class='col4' align='left'><?php xl('Description','e') ?></th>
254 <th class='col5' align='left'>&nbsp;</th>
255 </tr>
256 </table>
258 <div id="con0">
259 </div>
262 <?php if ($popup) { ?>
263 <input type='submit' name='form_save' value='<?php xl('Save','e'); ?>' />
264 &nbsp;
265 <input type='button' value=<?php xl('Cancel','e'); ?> onclick='window.close()' />
266 &nbsp;
267 <?php } ?>
268 <input type='button' value='<?php xl('Add Top Level','e'); ?>' onclick='anode(0)' />
269 </p>
271 </form>
273 </center>
275 </body>
276 </html>