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
;
24 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
25 CsrfUtils
::csrfNotVerified();
30 $codetype = $_REQUEST['codetype'] ??
'';
31 if (!empty($codetype)) {
32 $allowed_codes = split_csv_line($codetype);
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.
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'];
52 // This variable is used to store the html element
53 // of the target script where the selected code
55 $target_element = $_GET['target_element'] ??
null;
60 <title
><?php
echo xlt('Code Finder'); ?
></title
>
61 <?php Header
::setupHeader('opener'); ?
>
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.'); ?
>);
68 var msg
= opener
.set_related(codetype
, code
, selector
, codedesc
);
75 // TBD: The following function is not necessary. See
76 // interface/forms/LBF/new.php for an alternative method that does not require it.
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.'); ?
>);
85 // opener.set_related_target(codetype, code, selector, codedesc, target_element);
86 var msg
= opener
.set_related(codetype
, code
, selector
, codedesc
);
96 $focus = "document.theform.search_term.select();";
98 <body onload
="<?php echo $focus; ?>">
99 <div
class="container-fluid">
101 $string_target_element = "";
102 if (!empty($target_element)) {
103 $string_target_element = "?target_element=" . attr_url($target_element) . "&";
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) ?>'>
112 <form
class="form-inline" method
='post' name
='theform'
113 action
='find_code_popup.php<?php echo $string_target_element ?>'>
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">
119 if (!empty($allowed_codes)) { ?
>
120 <select
class='form-control' name
='form_code_type'>
122 foreach (array_keys($code_types) as $code) {
123 if (empty($code_types[$code]['label'])) {
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
>
134 // No allowed types were specified, so show all.
135 echo "<select class='form-control' name='form_code_type'";
137 foreach ($code_types as $key => $value) {
138 if (empty($value['label'])) {
141 echo "<option value='" . attr($key) . "'";
142 if ($default == $key) {
145 echo ">" . xlt($value['label']) . "</option>\n";
147 echo "<option value='PROD'";
148 if ($default == 'PROD') {
151 echo ">" . xlt("Product") . "</option>\n";
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
>
169 <button type
='button' class='btn btn-danger btn-delete' value
=''
170 onclick
="selcode('', '', '', '')"></button
>
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'>
184 <th
class='font-weight-bold'><?php
echo xlt('Code'); ?
></th
>
185 <th
class='font-weight-bold'><?php
echo xlt('Description'); ?
></th
>
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) . ")'>";
201 echo "<td>$anchor" . text($drug_id . ":" . $selector) . "</a></td>\n";
202 echo "<td>$anchor" . text($desc) . "</a></td>\n";
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) . ")'>";
221 $anchor = "<a href='' " .
222 "onclick='return selcode(" . attr_js($dynCodeType) .
223 ", " . attr_js($itercode) . ", \"\", " . attr_js($itertext) . ")'>";
226 echo " <td>$anchor" . text($itercode) . "</a></td>\n";
227 echo " <td>$anchor" . text($itertext) . "</a></td>\n";