feat: support loop 2420E (#7405)
[openemr.git] / interface / patient_file / encounter / find_code_popup.php
blobe08a37bb4b2d35bd4904ce64aa034a4b6efa0fb9
1 <?php
3 /**
4 * find_code_popup.php
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2008-2014 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once('../../globals.php');
16 require_once($GLOBALS['srcdir'] . '/patient.inc.php');
17 require_once($GLOBALS['srcdir'] . '/csv_like_join.php');
18 require_once($GLOBALS['fileroot'] . '/custom/code_types.inc.php');
20 use OpenEMR\Common\Csrf\CsrfUtils;
21 use OpenEMR\Core\Header;
23 if (!empty($_POST)) {
24 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
25 CsrfUtils::csrfNotVerified();
29 $info_msg = "";
30 $codetype = $_REQUEST['codetype'] ?? '';
31 if (!empty($codetype)) {
32 $allowed_codes = split_csv_line($codetype);
33 } else {
34 $allowed_codes = array_keys($code_types);
37 $form_code_type = $_POST['form_code_type'] ?? '';
39 // Determine which code type will be selected by default.
40 $default = '';
41 if (!empty($form_code_type)) {
42 $default = $form_code_type;
43 // if they've submitted a code type we only want to use those.
44 $allowed_codes = [$default];
45 } elseif (!empty($allowed_codes) && count($allowed_codes) == 1) {
46 $default = $allowed_codes[0];
47 } elseif (!empty($_REQUEST['default'])) {
48 $default = $_REQUEST['default'];
49 $codetype = $default;
52 // This variable is used to store the html element
53 // of the target script where the selected code
54 // will be stored in.
55 $target_element = $_GET['target_element'] ?? null;
57 <!DOCTYPE html>
58 <html>
59 <head>
60 <title><?php echo xlt('Code Finder'); ?></title>
61 <?php Header::setupHeader('opener'); ?>
62 <script>
63 // Standard function
64 function selcode(codetype, code, selector, codedesc) {
65 if (opener.closed || !opener.set_related) {
66 alert(<?php echo xlj('The destination form was closed; I cannot act on your selection.'); ?>);
67 } else {
68 var msg = opener.set_related(codetype, code, selector, codedesc);
69 if (msg) alert(msg);
70 dlgclose();
71 return false;
75 // TBD: The following function is not necessary. See
76 // interface/forms/LBF/new.php for an alternative method that does not require it.
77 // Rod 2014-04-15
79 // Standard function with additional parameter to select which
80 // element on the target page to place the selected code into.
81 function selcode_target(codetype, code, selector, codedesc, target_element) {
82 if (opener.closed || !opener.set_related_target) {
83 alert(<?php echo xlj('The destination form was closed; I cannot act on your selection.'); ?>);
84 } else {
85 // opener.set_related_target(codetype, code, selector, codedesc, target_element);
86 var msg = opener.set_related(codetype, code, selector, codedesc);
87 if (msg) alert(msg);
89 dlgclose();
90 return false;
93 </script>
94 </head>
95 <?php
96 $focus = "document.theform.search_term.select();";
98 <body onload="<?php echo $focus; ?>">
99 <div class="container-fluid">
100 <?php
101 $string_target_element = "";
102 if (!empty($target_element)) {
103 $string_target_element = "?target_element=" . attr_url($target_element) . "&";
104 } else {
105 $string_target_element = "?";
108 <?php if (!empty($allowed_codes)) { ?>
109 <form class="form-inline" method='post' name='theform'
110 action='find_code_popup.php<?php echo $string_target_element ?>codetype=<?php echo attr_url($codetype) ?>'>
111 <?php } else { ?>
112 <form class="form-inline" method='post' name='theform'
113 action='find_code_popup.php<?php echo $string_target_element ?>'>
114 <?php } ?>
115 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
116 <div class="form-group">
117 <div class="input-group mt-1">
118 <?php
119 if (!empty($allowed_codes)) { ?>
120 <select class='form-control' name='form_code_type'>
121 <?php
122 foreach (array_keys($code_types) as $code) {
123 if (empty($code_types[$code]['label'])) {
124 continue;
126 $selected_attr = ($default == $code) ? " selected='selected'" : '';
128 <option value='<?php echo attr($code) ?>'<?php
129 echo $selected_attr ?>><?php echo xlt($code_types[$code]['label']) ?></option>
130 <?php } ?>
131 </select>
132 <?php
133 } else {
134 // No allowed types were specified, so show all.
135 echo "<select class='form-control' name='form_code_type'";
136 echo ">\n";
137 foreach ($code_types as $key => $value) {
138 if (empty($value['label'])) {
139 continue;
141 echo "<option value='" . attr($key) . "'";
142 if ($default == $key) {
143 echo " selected";
145 echo ">" . xlt($value['label']) . "</option>\n";
147 echo "<option value='PROD'";
148 if ($default == 'PROD') {
149 echo " selected";
151 echo ">" . xlt("Product") . "</option>\n";
152 echo "</select>\n";
155 </div>
156 <div class="input-group mt-1">
157 <input type='text' class='form-control' name='search_term' id="searchTerm"
158 value='<?php echo attr($_REQUEST['search_term'] ?? ''); ?>'
159 title='<?php echo xla('Any part of the desired code or its description'); ?>'
160 placeholder="<?php echo xla('Search for'); ?>" />
161 <div class="input-group-append">
162 <button type='submit' class='btn btn-primary btn-search'
163 name='bn_search' value='Search'></button>
164 <?php if (!empty($target_element)) { ?>
165 <button type='button' class='btn btn-primary btn-delete' value=''
166 onclick="selcode_target('', '', '', '',
167 <?php echo attr_js($target_element); ?>)"></button>
168 <?php } else { ?>
169 <button type='button' class='btn btn-danger btn-delete' value=''
170 onclick="selcode('', '', '', '')"></button>
171 <?php } ?>
172 </div>
173 </div>
174 </div>
175 <?php
176 if (!empty($_REQUEST['bn_search']) || !empty($_REQUEST['search_term'])) {
177 if (!$form_code_type) {
178 $form_code_type = $codetype;
181 <div class="table-responsive">
182 <table class='table table-striped table-responsive-sm'>
183 <thead>
184 <th class='font-weight-bold'><?php echo xlt('Code'); ?></th>
185 <th class='font-weight-bold'><?php echo xlt('Description'); ?></th>
186 </thead>
187 <tbody>
188 <?php
189 $search_term = $_REQUEST['search_term'];
190 $res = main_code_set_search($allowed_codes, $search_term);
191 if ($form_code_type == 'PROD') {
192 // Special case that displays search for products/drugs
193 while ($row = sqlFetchArray($res)) {
194 $drug_id = $row['drug_id'];
195 $selector = $row['selector'];
196 $desc = $row['name'];
197 $anchor = "<a href='' " .
198 "onclick='return selcode(\"PROD\", " .
199 attr_js($drug_id) . ", " . attr_js($selector) . ", " . attr_js($desc) . ")'>";
200 echo "<tr>";
201 echo "<td>$anchor" . text($drug_id . ":" . $selector) . "</a></td>\n";
202 echo "<td>$anchor" . text($desc) . "</a></td>\n";
203 echo "</tr>";
205 } else {
206 while ($row = sqlFetchArray($res)) { // Display normal search
207 $itercode = $row['code'];
208 $itertext = ucfirst(strtolower(trim($row['code_text'])));
209 $dynCodeType = $form_code_type ?: $codetype;
210 if (stripos($dynCodeType, 'VALUESET') !== false) {
211 $dynCodeType = $row['valueset_code_type'] ?? 'VALUESET';
213 if (!empty($target_element)) {
214 // add a 5th parameter to function to select the target element
215 // on the form for placing the code.
216 $anchor = "<a href='' " .
217 "onclick='return selcode_target(" . attr_js($dynCodeType) .
218 ", " . attr_js($itercode) . ", \"\", " . attr_js($itertext) .
219 ", " . attr_js($target_element) . ")'>";
220 } else {
221 $anchor = "<a href='' " .
222 "onclick='return selcode(" . attr_js($dynCodeType) .
223 ", " . attr_js($itercode) . ", \"\", " . attr_js($itertext) . ")'>";
225 echo " <tr>";
226 echo " <td>$anchor" . text($itercode) . "</a></td>\n";
227 echo " <td>$anchor" . text($itertext) . "</a></td>\n";
228 echo " </tr>";
232 </tbody>
233 </table>
234 </div>
235 <?php } ?>
236 </form>
237 </div>
238 </body>
239 </html>