Multiple improvements from IPPF related to layouts. (#1081)
[openemr.git] / interface / patient_file / encounter / find_code_dynamic.php
blobd34219b1d3c57710e33b9b0bd91c6a3b35160390
1 <?php
2 /**
3 * Interactive code finder.
4 * For DataTables documentation see: http://legacy.datatables.net/
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @copyright Copyright (c) 2015-2017 Rod Roark <rod@sunsetsystems.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once('../../globals.php');
14 require_once($GLOBALS['srcdir'] . '/patient.inc');
15 require_once($GLOBALS['srcdir'] . '/csv_like_join.php');
16 require_once($GLOBALS['fileroot'] . '/custom/code_types.inc.php');
18 $info_msg = "";
20 // What we are picking from: codes, fields, lists or groups
21 $what = empty($_GET['what']) ? 'codes' : $_GET['what'];
23 // For what == codes
24 $codetype = empty($_GET['codetype']) ? '' : $_GET['codetype'];
25 if (!empty($codetype)) {
26 $allowed_codes = split_csv_line($codetype);
28 // This is the html element of the target script where the selected code will be stored.
29 $target_element = empty($_GET['target_element']) ? '' : $_GET['target_element'];
31 // For what == fields
32 $source = empty($_GET['source']) ? 'D' : $_GET['source'];
34 // For what == groups
35 $layout_id = empty($_GET['layout_id']) ? '' : $_GET['layout_id'];
37 <html>
38 <head>
39 <?php html_header_show(); ?>
40 <title><?php echo xlt('Code Finder'); ?></title>
41 <link rel="stylesheet" href='<?php echo attr($css_header) ?>' type='text/css'>
43 <style type="text/css">
44 </style>
46 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/datatables.net-dt-1-10-13/css/jquery.dataTables.min.css" type="text/css">
47 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/datatables.net-colreorder-dt-1-3-2/css/colReorder.dataTables.min.css" type="text/css">
49 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
50 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/datatables.net-1-10-13/js/jquery.dataTables.min.js"></script>
51 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
53 <script language="JavaScript">
55 var oTable;
57 // Keeps track of which items have been selected during this session.
58 var oChosenIDs = {};
60 $(document).ready(function() {
62 // Initializing the DataTable.
63 oTable = $('#my_data_table').dataTable({
64 "bProcessing": true,
65 // Next 2 lines invoke server side processing
66 "bServerSide": true,
67 "sAjaxSource": "find_code_dynamic_ajax.php",
68 // Vertical length options and their default
69 "aLengthMenu": [ 15, 25, 50, 100 ],
70 "iDisplayLength": 15,
71 // Specify a width for the first column.
72 "aoColumns": [{"sWidth":"10%"}, null],
73 // This callback function passes some form data on each call to the ajax handler.
74 "fnServerParams": function (aoData) {
75 aoData.push({"name": "what", "value": "<?php echo attr($what); ?>"});
76 <?php if ($what == 'codes') { ?>
77 aoData.push({"name": "codetype", "value": document.forms[0].form_code_type.value});
78 aoData.push({"name": "inactive", "value": (document.forms[0].form_include_inactive.checked ? 1 : 0)});
79 <?php } else if ($what == 'fields') { ?>
80 aoData.push({"name": "source", "value": "<?php echo attr($source); ?>"});
81 <?php } else if ($what == 'groups') { ?>
82 aoData.push({"name": "layout_id", "value": "<?php echo attr($layout_id); ?>"});
83 <?php } ?>
85 // Drawing a row, apply styling if it is previously selected.
86 "fnCreatedRow": function (nRow, aData, iDataIndex) {
87 if (oChosenIDs[nRow.id]) {
88 nRow.style.fontWeight = 'bold';
91 // Language strings are included so we can translate them
92 "oLanguage": {
93 "sSearch" : "<?php echo xla('Search for'); ?>:",
94 "sLengthMenu" : "<?php echo xla('Show') . ' _MENU_ ' . xla('entries'); ?>",
95 "sZeroRecords" : "<?php echo xla('No matching records found'); ?>",
96 "sInfo" : "<?php echo xla('Showing') . ' _START_ ' . xla('to{{range}}') . ' _END_ ' . xla('of') . ' _TOTAL_ ' . xla('entries'); ?>",
97 "sInfoEmpty" : "<?php echo xla('Nothing to show'); ?>",
98 "sInfoFiltered": "(<?php echo xla('filtered from') . ' _MAX_ ' . xla('total entries'); ?>)",
99 "oPaginate" : {
100 "sFirst" : "<?php echo xla('First'); ?>",
101 "sPrevious" : "<?php echo xla('Previous'); ?>",
102 "sNext" : "<?php echo xla('Next'); ?>",
103 "sLast" : "<?php echo xla('Last'); ?>"
108 // OnClick handler for the rows
109 $('#my_data_table').on('click', 'tbody tr', function () {
110 var jobj = JSON.parse(this.id.substring(4));
112 this.style.fontWeight = 'bold';
113 oChosenIDs[this.id] = 1;
115 <?php if ($what == 'codes') { ?>
116 // this.id is of the form "CID|jsonstring".
117 var codesel = jobj['code'].split('|');
118 selcode(jobj['codetype'], codesel[0], codesel[1], jobj['description']);
119 <?php } else if ($what == 'fields') { ?>
120 selectField(jobj);
121 <?php } else if ($what == 'lists') { ?>
122 SelectList(jobj);
123 <?php } else if ($what == 'groups') { ?>
124 SelectItem(jobj);
125 <?php } ?>
127 } );
129 <?php if ($what == 'codes') { ?>
130 // Initialize the selector of codes that can be deleted.
131 if (opener.get_related) {
132 var acodes = opener.get_related();
133 var sel = document.forms[0].form_delcodes;
134 if (acodes.length > 1) {
135 for (var i = 0; i < acodes.length; ++i) {
136 sel.options[sel.options.length] = new Option(acodes[i], acodes[i]);
139 else {
140 sel.style.display = 'none';
143 <?php } ?>
147 <?php if ($what == 'codes') { ?>
149 // Pass info back to the opener and close this window. Specific to billing/product codes.
150 function selcode(codetype, code, selector, codedesc) {
151 if (opener.closed || ! opener.set_related) {
152 alert('<?php echo xls('The destination form was closed; I cannot act on your selection.'); ?>');
154 else {
155 var msg = opener.set_related(codetype, code, selector, codedesc);
156 if (msg) alert(msg);
157 // window.close();
158 return false;
161 // Function to call the opener to delete all or one related code. Specific to billing/product codes.
162 function delcode() {
163 if (opener.closed || ! opener.del_related) {
164 alert('<?php echo xls('The destination form was closed; I cannot act on your selection.'); ?>');
166 else {
167 var sel = document.forms[0].form_delcodes;
168 opener.del_related(sel.value);
169 oChosenIDs = {};
170 oTable.fnDraw();
171 // window.close();
172 return false;
176 <?php } else if ($what == 'fields') { ?>
178 function selectField(jobj) {
179 if (opener.closed || ! opener.SetField) {
180 alert('The destination form was closed; I cannot act on your selection.');
182 else {
183 opener.SetField(jobj['field_id'], jobj['title'], jobj['data_type'], jobj['uor'], jobj['fld_length'],
184 jobj['max_length'], jobj['list_id'], jobj['titlecols'], jobj['datacols'], jobj['edit_options'],
185 jobj['description'], jobj['fld_rows']);
187 window.close();
188 return false;
190 function newField() {
191 return selectField({
192 "field_id" : document.forms[0].new_field_id.value,
193 "title" : '',
194 "data_type" : 2,
195 "uor" : 1,
196 "fld_length" : 10,
197 "max_length" : 255,
198 "list_id" : '',
199 "titlecols" : 1,
200 "datacols" : 3,
201 "edit_options": '',
202 "description" : '',
203 "fld_rows" : 0
207 <?php } else if ($what == 'lists') { ?>
209 function SelectList(jobj) {
210 if (opener.closed || ! opener.SetList)
211 alert('The destination form was closed; I cannot act on your selection.');
212 else
213 opener.SetList(jobj['code']);
214 window.close();
215 return false;
218 <?php } else if ($what == 'groups') { ?>
220 var SelectItem = function(jobj) {
221 if (opener.closed)
222 alert('The destination form was closed; I cannot act on your selection.');
223 else
224 opener.MoveFields(jobj['code']);
225 window.close();
226 return false;
229 <?php } ?>
231 </script>
233 </head>
235 <body class="body_top">
237 <?php
238 $string_target_element = empty($target_element) ? '?' : "?target_element=" . rawurlencode($target_element) . "&";
241 <form method='post' name='theform'>
243 <?php
244 echo "<p>\n";
245 if ($what == 'codes') {
246 if (isset($allowed_codes)) {
247 if (count($allowed_codes) == 1) {
248 echo "<input type='text' name='form_code_type' value='" . attr($codetype) . "' size='5' readonly>\n";
249 } else {
250 echo "<select name='form_code_type' onchange='oTable.fnDraw()'>\n";
251 foreach ($allowed_codes as $code) {
252 echo " <option value='" . attr($code) . "'>" . xlt($code_types[$code]['label']) . "</option>\n";
254 echo "</select>\n";
256 } else {
257 echo "<select name='form_code_type' onchange='oTable.fnDraw()'>\n";
258 foreach ($code_types as $key => $value) {
259 echo " <option value='" . attr($key) . "'";
260 echo ">" . xlt($value['label']) . "</option>\n";
262 echo " <option value='PROD'";
263 echo ">" . xlt("Product") . "</option>\n";
264 echo " </select>\n";
266 echo "&nbsp;&nbsp;\n";
267 echo "<input type='checkbox' name='form_include_inactive' value='1' onclick='oTable.fnDraw()' />" .
268 xlt('Include Inactive') . "\n";
269 echo "&nbsp;&nbsp;\n";
270 echo "<input type='button' value='" . xla('Delete') . "' onclick='delcode()' />\n";
271 echo "<select name='form_delcodes'>\n";
272 echo " <option value=''>" . xlt('All') . "</option>\n";
273 echo "</select>\n";
274 echo "&nbsp;&nbsp;\n";
275 echo "<input type='button' value='" . xla('Close') . "' onclick='window.close()' />\n";
277 if ($what == 'lists') {
278 echo "<input type='button' value='" . xla('Delete') . "' onclick='SelectList({\"code\":\"\"})' />\n";
280 echo "</p>\n";
283 <!-- Class "display" is defined in demo_table.css -->
284 <table cellpadding="0" cellspacing="0" border="0" class="display" id="my_data_table">
285 <thead>
286 <tr>
287 <th><?php echo xlt('Code'); ?></th>
288 <th><?php echo xlt('Description'); ?></th>
289 </tr>
290 </thead>
291 <tbody>
292 <tr>
293 <!-- Class "dataTables_empty" is defined in jquery.dataTables.css -->
294 <td colspan="2" class="dataTables_empty">...</td>
295 </tr>
296 </tbody>
297 </table>
299 <?php if ($what == 'fields' && $source == 'E') { ?>
300 <center>
302 <input type='text' name='new_field_id' size='20' />&nbsp;
303 <input type='button' value='<?php echo xla('Or create this new field ID') ?>' onclick='newField()' />
304 </p>
305 </center>
306 <?php } ?>
308 </form>
309 </body>
310 </html>