bug fix march continued (#1921)
[openemr.git] / interface / de_identification_forms / find_code_popup.php
blobc7c5cb1bbaa7b400a6944d4156aeff9137a1ca02
1 <?php
2 /**
3 * find_code_popup.php
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Visolve <vicareplus_engg@visolve.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) ViCarePlus, Visolve <vicareplus_engg@visolve.com>
10 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/patient.inc");
17 require_once("../../custom/code_types.inc.php");
19 $info_msg = "";
20 $codetype = $_REQUEST['codetype'];
21 $form_code_type = $_POST['form_code_type'];
23 <html>
24 <head>
25 <?php html_header_show(); ?>
26 <title><?php echo xlt('Code Finder'); ?></title>
27 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
29 <style>
30 td { font-size:10pt; }
31 </style>
33 <script language="JavaScript">
34 //pass value selected to the parent window
35 function window_submit(chk)
37 var str;
38 var len=chk.length;
39 if (len==undefined && chk.checked==1)
41 if(!str)
42 str = chk.value;
43 else
44 str = "#"+chk.value;
46 else
48 for (pr = 0; pr < chk.length; pr++)
50 if(chk[pr].checked == 1)
52 if(!str)
53 str = chk[pr].value;
54 else
55 str = str+"#"+chk[pr].value;
59 if(!str)
60 alert('<?php echo xls("Select Diagnosis");?>');
61 if (opener.closed || ! opener.set_related)
62 alert("<?php echo xls('The destination form was closed');?>");
63 else
64 opener.set_related(str,"diagnosis");
66 window.close();
70 function window_close(chk)
72 window.close();
75 function chkbox_select_none(chk)
77 var len=chk.length;
78 if (len==undefined) {chk.checked=false;}
79 else
81 for (pr = 0; pr < chk.length; pr++)
83 chk[pr].checked=false;
88 function chkbox_select_all(chk)
90 var len=chk.length;
91 if (len==undefined) {chk.checked=true;}
92 else
94 for (pr = 0; pr < chk.length; pr++)
96 chk[pr].checked=true;
101 function check_search_str()
103 var search_str = document.getElementById('search_term').value;
104 if(search_str.length < 3)
106 alert('<?php echo xls("Search string should have at least three characters");?>');
107 return false;
109 top.restoreSession();
110 return true;
113 </script>
114 </head>
115 <body class="body_top">
116 <form method='post' name='theform' action='find_code_popup.php' onsubmit="return check_search_str();">
117 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
118 <center>
119 <input type="hidden" name="search_status" id="search_status" value=1;>
120 <table border='0' cellpadding='5' cellspacing='0'>
121 <tr>
122 <td height="1">
123 </td>
124 </tr>
125 <tr>
126 <td>
128 <?php
129 if ($codetype) {
130 echo "<input type='text' name='form_code_type' value='" . attr($codetype) . "' size='5' readonly>\n";
131 } else {
132 echo " <select name='form_code_type'";
133 echo ">\n";
134 foreach ($code_types as $key => $value) {
135 echo " <option value='" . attr($key) . "'";
136 if ($codetype == $key || $form_code_type == $key) {
137 echo " selected";
140 echo ">" . text($key) . "</option>\n";
143 echo " <option value='PROD'";
144 if ($codetype == 'PROD' || $form_code_type == 'PROD') {
145 echo " selected";
148 echo ">Product</option>\n";
149 echo " </select>&nbsp;&nbsp;\n";
152 <?php echo xlt('Search for'); ?>
153 <input type='text' name='search_term' id='search_term' size='12' value='<?php echo attr($_REQUEST['search_term']); ?>'
154 title='<?php xla('Any part of the desired code or its description'); ?>' />
155 &nbsp;
156 <input type='submit' name='bn_search' id='bn_search' value='<?php echo xla('Search'); ?>' />
157 </b>
158 </td>
159 </tr>
160 <tr>
161 <td height="1">
162 </td>
163 </tr>
164 </table>
165 </center>
166 </form>
167 <form method='post' name='select_diagonsis'>
168 <table border='0'>
169 <tr>
170 <td colspan="4">
171 <?php if ($_REQUEST['bn_search']) {
172 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
173 csrfNotVerified();
176 $search_term = $_REQUEST['search_term'];
177 if ($form_code_type == 'PROD') {
178 $query = "SELECT dt.drug_id, dt.selector, d.name " .
179 "FROM drug_templates AS dt, drugs AS d WHERE " .
180 "( d.name LIKE ? OR " .
181 "dt.selector LIKE ? ) " .
182 "AND d.drug_id = dt.drug_id " .
183 "ORDER BY d.name, dt.selector, dt.drug_id";
184 $res = sqlStatement($query, array('%'.$search_term.'%', '%'.$search_term.'%'));
185 $row_count = 0;
186 while ($row = sqlFetchArray($res)) {
187 $row_count = $row_count + 1;
188 $drug_id = $row['drug_id'];
189 $selector = $row['selector'];
190 $desc = $row['name'];
192 <input type="checkbox" name="diagnosis[row_count]" value="<?php echo attr($desc); ?>" > <?php echo text($drug_id) . " " . text($selector) . " " . text($desc) . "</br>";
194 } else {
195 $query = "SELECT count(*) as count FROM codes " .
196 "WHERE (code_text LIKE ? OR " .
197 "code LIKE ?) " ;
198 $res = sqlStatement($query, array('%'.$search_term.'%', '%'.$search_term.'%'));
199 if ($row = sqlFetchArray($res)) {
200 $no_of_items = $row['count'];
201 if ($no_of_items < 1) {
203 <script language='JavaScript'>
204 alert("<?php echo xls('Search string does not match with list in database');
205 echo '\n';
206 echo xls('Please enter new search string');?>");
207 document.theform.search_term.value=" ";
208 document.theform.search_term.focus();
209 </script>
210 <?php
213 $query = "SELECT code_type, code, modifier, code_text FROM codes " .
214 "WHERE (code_text LIKE ? OR " .
215 "code LIKE ?) " .
216 "ORDER BY code";
217 // echo "\n<!-- $query -->\n"; // debugging
218 $res = sqlStatement($query, array('%'.$search_term.'%', '%'.$search_term.'%'));
219 $row_count = 0;
220 while ($row = sqlFetchArray($res)) {
221 $row_count = $row_count + 1;
222 $itercode = $row['code'];
223 $itertext = ucfirst(strtolower(trim($row['code_text'])));
225 <input type="checkbox" id="chkbox" value= "<?php echo attr($form_code_type) . ":" . attr($itercode) . "-" . attr($itertext); ?>" > <?php echo text($itercode) . " " . text($itertext) . "</br>";
230 </td>
231 </tr>
232 </table>
233 <center>
234 </br>
235 <input type='button' id='select_all' value='<?php echo xla('Select All'); ?>' onclick="chkbox_select_all(document.select_diagonsis.chkbox);"/>
237 <input type='button' id='unselect_all' value='<?php echo xla('Unselect All'); ?>' onclick="chkbox_select_none(document.select_diagonsis.chkbox);"/>
239 <input type='button' id='submit' value='<?php echo xla('Submit'); ?>' onclick="window_submit(document.select_diagonsis.chkbox);"/>
241 <input type='button' id='cancel' value='<?php echo xla('Cancel'); ?>' onclick="window_close();"/>
243 </center>
244 <?php } ?>
245 </form>
246 </body>
247 </html>