Highway to PSR2
[openemr.git] / interface / patient_file / encounter / find_code_popup.php
blob2da65e14fc0e124c41ed4c48d07bf46af1f0f8d5
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 */
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;
30 } else if (!empty($allowed_codes) && count($allowed_codes) == 1) {
31 $default = $allowed_codes[0];
32 } else if (!empty($_REQUEST['default'])) {
33 $default = $_REQUEST['default'];
36 // This variable is used to store the html element
37 // of the target script where the selected code
38 // will be stored in.
39 $target_element = $_GET['target_element'];
41 <html>
42 <head>
43 <?php html_header_show(); ?>
44 <title><?php echo xlt('Code Finder'); ?></title>
45 <link rel="stylesheet" href='<?php echo attr($css_header) ?>' type='text/css'>
47 <style>
48 td { font-size:10pt; }
49 </style>
50 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
52 <script language="JavaScript">
54 // Standard function
55 function selcode(codetype, code, selector, codedesc) {
56 if (opener.closed || ! opener.set_related) {
57 alert('<?php echo xls('The destination form was closed; I cannot act on your selection.'); ?>');
59 else {
60 var msg = opener.set_related(codetype, code, selector, codedesc);
61 if (msg) alert(msg);
62 window.close();
63 return false;
67 // TBD: The following function is not necessary. See
68 // interface/forms/LBF/new.php for an alternative method that does not require it.
69 // Rod 2014-04-15
71 // Standard function with additional parameter to select which
72 // element on the target page to place the selected code into.
73 function selcode_target(codetype, code, selector, codedesc, target_element) {
74 if (opener.closed || ! opener.set_related_target)
75 alert('<?php echo xls('The destination form was closed; I cannot act on your selection.'); ?>');
76 else
77 opener.set_related_target(codetype, code, selector, codedesc, target_element);
78 window.close();
79 return false;
82 </script>
84 </head>
85 <?php
86 $focus = "document.theform.search_term.select();";
88 <body class="body_top" OnLoad="<?php echo $focus; ?>">
90 <?php
91 $string_target_element = "";
92 if (!empty($target_element)) {
93 $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
135 } else {
136 // No allowed types were specified, so show all.
137 echo " <select name='form_code_type'";
138 echo ">\n";
139 foreach ($code_types as $key => $value) {
140 echo " <option value='" . attr($key) . "'";
141 if ($default == $key) {
142 echo " selected";
145 echo ">" . xlt($value['label']) . "</option>\n";
148 echo " <option value='PROD'";
149 if ($default == 'PROD') {
150 echo " selected";
153 echo ">" . xlt("Product") . "</option>\n";
154 echo " </select>&nbsp;&nbsp;\n";
158 <?php echo xlt('Search for:'); ?>
159 <input type='text' name='search_term' size='12' value='<?php echo attr($_REQUEST['search_term']); ?>'
160 title='<?php echo xla('Any part of the desired code or its description'); ?>' />
161 &nbsp;
162 <input type='submit' name='bn_search' value='<?php echo xla('Search'); ?>' />
163 &nbsp;&nbsp;&nbsp;
164 <?php if (!empty($target_element)) { ?>
165 <input type='button' value='<?php echo xla('Erase'); ?>' onclick="selcode_target('', '', '', '', '<?php echo attr(addslashes($target_element)); ?>')" />
166 <?php } else { ?>
167 <input type='button' value='<?php echo xla('Erase'); ?>' onclick="selcode('', '', '', '')" />
168 <?php } ?>
169 </b>
170 </td>
171 </tr>
173 <tr>
174 <td height="1">
175 </td>
176 </tr>
178 </table>
180 <?php
181 if ($_REQUEST['bn_search'] || $_REQUEST['search_term']) {
182 if (!$form_code_type) {
183 $form_code_type = $codetype;
187 <table border='0'>
188 <tr>
189 <td><b><?php echo xlt('Code'); ?></b></td>
190 <td><b><?php echo xlt('Description'); ?></b></td>
191 </tr>
192 <?php
193 $search_term = $_REQUEST['search_term'];
194 $res = main_code_set_search($form_code_type, $search_term);
195 if ($form_code_type == 'PROD') { // Special case that displays search for products/drugs
196 while ($row = sqlFetchArray($res)) {
197 $drug_id = $row['drug_id'];
198 $selector = $row['selector'];
199 $desc = $row['name'];
200 $anchor = "<a href='' " .
201 "onclick='return selcode(\"PROD\", \"" . attr(addslashes($drug_id)) . "\", \"" . attr(addslashes($selector)) . "\", \"" . attr(addslashes($desc)) . "\")'>";
202 echo " <tr>";
203 echo " <td>$anchor" . text($drug_id.":".$selector) . "</a></td>\n";
204 echo " <td>$anchor" . text($desc) . "</a></td>\n";
205 echo " </tr>";
207 } else {
208 while ($row = sqlFetchArray($res)) { // Display normal search
209 $itercode = $row['code'];
210 $itertext = trim($row['code_text']);
211 if (!empty($target_element)) {
212 // add a 5th parameter to function to select the target element on the form for placing the code.
213 $anchor = "<a href='' " .
214 "onclick='return selcode_target(\"" . attr(addslashes($form_code_type)) . "\", \"" . attr(addslashes($itercode)) . "\", \"\", \"" . attr(addslashes($itertext)) . "\", \"" . attr(addslashes($target_element)) . "\")'>";
215 } else {
216 $anchor = "<a href='' " .
217 "onclick='return selcode(\"" . attr(addslashes($form_code_type)) . "\", \"" . attr(addslashes($itercode)) . "\", \"\", \"" . attr(addslashes($itertext)) . "\")'>";
220 echo " <tr>";
221 echo " <td>$anchor" . text($itercode) . "</a></td>\n";
222 echo " <td>$anchor" . text($itertext) . "</a></td>\n";
223 echo " </tr>";
227 </table>
229 <?php } ?>
231 </center>
232 </form>
233 </body>
234 </html>