Option for showing description instead of codes in LBF Billing Code fields, and some...
[openemr.git] / interface / patient_file / encounter / find_code_popup.php
blobe592fa340b99bd3417d73c820f8082acb32cccf1
1 <?php
2 /* Copyright (C) 2008-2014 Rod Roark <rod@sunsetsystems.com>
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.
8 */
10 $fake_register_globals=false;
11 $sanitize_all_escapes=true;
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 = "";
19 $codetype = $_REQUEST['codetype'];
20 if (!empty($codetype)) {
21 $allowed_codes = split_csv_line($codetype);
24 $form_code_type = $_POST['form_code_type'];
26 // Determine which code type will be selected by default.
27 $default = '';
28 if (!empty($form_code_type)) {
29 $default = $form_code_type;
31 else if (!empty($allowed_codes) && count($allowed_codes) == 1) {
32 $default = $allowed_codes[0];
34 else if (!empty($_REQUEST['default'])) {
35 $default = $_REQUEST['default'];
38 // This variable is used to store the html element
39 // of the target script where the selected code
40 // will be stored in.
41 $target_element = $_GET['target_element'];
43 <html>
44 <head>
45 <?php html_header_show(); ?>
46 <title><?php echo xlt('Code Finder'); ?></title>
47 <link rel="stylesheet" href='<?php echo attr($css_header) ?>' type='text/css'>
49 <style>
50 td { font-size:10pt; }
51 </style>
53 <script language="JavaScript">
55 // Standard function
56 function selcode(codetype, code, selector, codedesc) {
57 if (opener.closed || ! opener.set_related) {
58 alert('<?php echo xls('The destination form was closed; I cannot act on your selection.'); ?>');
60 else {
61 var msg = opener.set_related(codetype, code, selector, codedesc);
62 if (msg) alert(msg);
63 window.close();
64 return false;
68 // TBD: The following function is not necessary. See
69 // interface/forms/LBF/new.php for an alternative method that does not require it.
70 // Rod 2014-04-15
72 // Standard function with additional parameter to select which
73 // element on the target page to place the selected code into.
74 function selcode_target(codetype, code, selector, codedesc, target_element) {
75 if (opener.closed || ! opener.set_related_target)
76 alert('<?php echo xls('The destination form was closed; I cannot act on your selection.'); ?>');
77 else
78 opener.set_related_target(codetype, code, selector, codedesc, target_element);
79 window.close();
80 return false;
83 </script>
85 </head>
87 <body class="body_top" OnLoad="document.theform.search_term.focus();">
89 <?php
90 $string_target_element = "";
91 if (!empty($target_element)) {
92 $string_target_element = "?target_element=" . urlencode($target_element) . "&";
94 else {
95 $string_target_element = "?";
98 <?php if (!empty($allowed_codes)) { ?>
99 <form method='post' name='theform' action='find_code_popup.php<?php echo $string_target_element ?>codetype=<?php echo urlencode($codetype) ?>'>
100 <?php } else { ?>
101 <form method='post' name='theform' action='find_code_popup.php<?php echo $string_target_element ?>'>
102 <?php } ?>
104 <center>
106 <table border='0' cellpadding='5' cellspacing='0'>
108 <tr>
109 <td height="1">
110 </td>
111 </tr>
113 <tr bgcolor='#ddddff'>
114 <td>
117 <?php
118 if (!empty($allowed_codes)) {
119 if (count($allowed_codes) === 1) {
120 echo "<input type='text' name='form_code_type' value='" . attr($codetype) . "' size='5' readonly>\n";
121 } else {
123 <select name='form_code_type'>
124 <?php
125 foreach ($allowed_codes as $code) {
126 $selected_attr = ($default == $code) ? " selected='selected'" : '';
128 <option value='<?php echo attr($code) ?>'<?php echo $selected_attr ?>><?php echo xlt($code_types[$code]['label']) ?></option>
129 <?php
132 </select>
133 <?php
136 else {
137 // No allowed types were specified, so show all.
138 echo " <select name='form_code_type'";
139 echo ">\n";
140 foreach ($code_types as $key => $value) {
141 echo " <option value='" . attr($key) . "'";
142 if ($default == $key) echo " selected";
143 echo ">" . xlt($value['label']) . "</option>\n";
145 echo " <option value='PROD'";
146 if ($default == 'PROD') echo " selected";
147 echo ">" . xlt("Product") . "</option>\n";
148 echo " </select>&nbsp;&nbsp;\n";
152 <?php echo xlt('Search for:'); ?>
153 <input type='text' name='search_term' size='12' value='<?php echo attr($_REQUEST['search_term']); ?>'
154 title='<?php echo xla('Any part of the desired code or its description'); ?>' />
155 &nbsp;
156 <input type='submit' name='bn_search' value='<?php echo xla('Search'); ?>' />
157 &nbsp;&nbsp;&nbsp;
158 <?php if (!empty($target_element)) { ?>
159 <input type='button' value='<?php echo xla('Erase'); ?>' onclick="selcode_target('', '', '', '', '<?php echo attr(addslashes($target_element)); ?>')" />
160 <?php } else { ?>
161 <input type='button' value='<?php echo xla('Erase'); ?>' onclick="selcode('', '', '', '')" />
162 <?php } ?>
163 </b>
164 </td>
165 </tr>
167 <tr>
168 <td height="1">
169 </td>
170 </tr>
172 </table>
174 <?php if ($_REQUEST['bn_search']) { ?>
176 <table border='0'>
177 <tr>
178 <td><b><?php echo xlt('Code'); ?></b></td>
179 <td><b><?php echo xlt('Description'); ?></b></td>
180 </tr>
181 <?php
182 $search_term = $_REQUEST['search_term'];
183 $res = main_code_set_search($form_code_type,$search_term);
184 if ($form_code_type == 'PROD') { // Special case that displays search for products/drugs
185 while ($row = sqlFetchArray($res)) {
186 $drug_id = $row['drug_id'];
187 $selector = $row['selector'];
188 $desc = $row['name'];
189 $anchor = "<a href='' " .
190 "onclick='return selcode(\"PROD\", \"" . attr(addslashes($drug_id)) . "\", \"" . attr(addslashes($selector)) . "\", \"" . attr(addslashes($desc)) . "\")'>";
191 echo " <tr>";
192 echo " <td>$anchor" . text($drug_id.":".$selector) . "</a></td>\n";
193 echo " <td>$anchor" . text($desc) . "</a></td>\n";
194 echo " </tr>";
197 else {
198 while ($row = sqlFetchArray($res)) { // Display normal search
199 $itercode = $row['code'];
200 $itertext = trim($row['code_text']);
201 if (!empty($target_element)) {
202 // add a 5th parameter to function to select the target element on the form for placing the code.
203 $anchor = "<a href='' " .
204 "onclick='return selcode_target(\"" . attr(addslashes($form_code_type)) . "\", \"" . attr(addslashes($itercode)) . "\", \"\", \"" . attr(addslashes($itertext)) . "\", \"" . attr(addslashes($target_element)) . "\")'>";
206 else {
207 $anchor = "<a href='' " .
208 "onclick='return selcode(\"" . attr(addslashes($form_code_type)) . "\", \"" . attr(addslashes($itercode)) . "\", \"\", \"" . attr(addslashes($itertext)) . "\")'>";
210 echo " <tr>";
211 echo " <td>$anchor" . text($itercode) . "</a></td>\n";
212 echo " <td>$anchor" . text($itertext) . "</a></td>\n";
213 echo " </tr>";
217 </table>
219 <?php } ?>
221 </center>
222 </form>
223 </body>
224 </html>