Fixed missing check for optional "description" index
[openemr.git] / interface / de_identification_forms / find_code_popup.php
blobe225ee1963895c8718568e5743b0594a25971350
1 <?php
2 /********************************************************************************\
3 * Copyright (C) ViCarePlus, Visolve (vicareplus_engg@visolve.com) *
4 * *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 \********************************************************************************/
19 require_once("../globals.php");
20 require_once("$srcdir/patient.inc");
21 require_once("../../custom/code_types.inc.php");
23 $info_msg = "";
24 $codetype = $_REQUEST['codetype'];
25 $form_code_type = $_POST['form_code_type'];
27 <html>
28 <head>
29 <?php html_header_show(); ?>
30 <title><?php xl('Code Finder','e'); ?></title>
31 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
33 <style>
34 td { font-size:10pt; }
35 </style>
37 <script language="JavaScript">
38 //pass value selected to the parent window
39 function window_submit(chk)
41 var str;
42 var len=chk.length;
43 if (len==undefined && chk.checked==1)
45 if(!str)
46 str = chk.value;
47 else
48 str = "#"+chk.value;
50 else
52 for (pr = 0; pr < chk.length; pr++)
54 if(chk[pr].checked == 1)
56 if(!str)
57 str = chk[pr].value;
58 else
59 str = str+"#"+chk[pr].value;
63 if(!str)
64 alert('<?php echo xl("Select Diagnosis");?>');
65 if (opener.closed || ! opener.set_related)
66 alert("<?php echo xl('The destination form was closed');?>");
67 else
68 opener.set_related(str,"diagnosis");
70 window.close();
74 function window_close(chk)
76 window.close();
79 function chkbox_select_none(chk)
81 var len=chk.length;
82 if (len==undefined) {chk.checked=false;}
83 else
85 for (pr = 0; pr < chk.length; pr++)
87 chk[pr].checked=false;
92 function chkbox_select_all(chk)
94 var len=chk.length;
95 if (len==undefined) {chk.checked=true;}
96 else
98 for (pr = 0; pr < chk.length; pr++)
100 chk[pr].checked=true;
105 function check_search_str()
107 var search_str = document.getElementById('search_term').value;
108 if(search_str.length < 3)
110 alert('<?php echo xl("Search string should have at least three characters");?>');
111 return false;
113 top.restoreSession();
114 return true;
117 </script>
118 </head>
119 <body class="body_top">
120 <form method='post' name='theform' action='find_code_popup.php' onsubmit="return check_search_str();">
121 <center>
122 <input type="hidden" name="search_status" id="search_status" value=1;>
123 <table border='0' cellpadding='5' cellspacing='0'>
124 <tr>
125 <td height="1">
126 </td>
127 </tr>
128 <tr>
129 <td>
131 <?php
132 if ($codetype) {
133 echo "<input type='text' name='form_code_type' value='$codetype' size='5' readonly>\n";
135 else {
136 echo " <select name='form_code_type'";
137 echo ">\n";
138 foreach ($code_types as $key => $value) {
139 echo " <option value='$key'";
140 if ($codetype == $key || $form_code_type == $key) echo " selected";
141 echo ">$key</option>\n";
143 echo " <option value='PROD'";
144 if ($codetype == 'PROD' || $form_code_type == 'PROD') echo " selected";
145 echo ">Product</option>\n";
146 echo " </select>&nbsp;&nbsp;\n";
149 <?php xl('Search for','e'); ?>
150 <input type='text' name='search_term' id='search_term' size='12' value='<?php echo $_REQUEST['search_term']; ?>'
151 title='<?php xl('Any part of the desired code or its description','e'); ?>' />
152 &nbsp;
153 <input type='submit' name='bn_search' id='bn_search' value='<?php xl('Search','e'); ?>' />
154 </b>
155 </td>
156 </tr>
157 <tr>
158 <td height="1">
159 </td>
160 </tr>
161 </table>
162 </center>
163 </form>
164 <form method='post' name='select_diagonsis'>
165 <table border='0'>
166 <tr>
167 <td colspan="4">
168 <?php if ($_REQUEST['bn_search'])
170 $search_term = $_REQUEST['search_term'];
171 if ($form_code_type == 'PROD') {
172 $query = "SELECT dt.drug_id, dt.selector, d.name " .
173 "FROM drug_templates AS dt, drugs AS d WHERE " .
174 "( d.name LIKE '%$search_term%' OR " .
175 "dt.selector LIKE '%$search_term%' ) " .
176 "AND d.drug_id = dt.drug_id " .
177 "ORDER BY d.name, dt.selector, dt.drug_id";
178 $res = sqlStatement($query);
179 $row_count = 0;
180 while ($row = sqlFetchArray($res)) {
181 $row_count = $row_count + 1;
182 $drug_id = addslashes($row['drug_id']);
183 $selector = addslashes($row['selector']);
184 $desc = addslashes($row['name']);
186 <input type="checkbox" name="diagnosis[row_count]" value= "<?php echo $desc; ?>" > <?php echo $drug_id." ".$selector." ".$desc."</br>";
189 else {
190 $query = "SELECT count(*) as count FROM codes " .
191 "WHERE (code_text LIKE '%$search_term%' OR " .
192 "code LIKE '%$search_term%') " ;
193 $res = sqlStatement($query);
194 if ($row = sqlFetchArray($res))
196 $no_of_items = addslashes($row['count']);
197 if($no_of_items < 1)
200 <script language='JavaScript'>
201 alert("<?php echo xl('Search string does not match with list in database'); echo '\n'; echo xl('Please enter new search string');?>");
202 document.theform.search_term.value=" ";
203 document.theform.search_term.focus();
204 </script>
205 <?php
207 $query = "SELECT code_type, code, modifier, code_text FROM codes " .
208 "WHERE (code_text LIKE '%$search_term%' OR " .
209 "code LIKE '%$search_term%') " .
210 "ORDER BY code";
211 // echo "\n<!-- $query -->\n"; // debugging
212 $res = sqlStatement($query);
213 $row_count = 0;
214 while ($row = sqlFetchArray($res)) {
215 $row_count = $row_count + 1;
216 $itercode = addslashes($row['code']);
217 $itertext = addslashes(ucfirst(strtolower(trim($row['code_text']))));
219 <input type="checkbox" id="chkbox" value= "<?php echo $form_code_type.":".$itercode."-".$itertext; ?>" > <?php echo $itercode." ".$itertext."</br>";
224 </td>
225 </tr>
226 </table>
227 <center>
228 </br>
229 <input type='button' id='select_all' value='<?php xl('Select All','e'); ?>' onclick="chkbox_select_all(document.select_diagonsis.chkbox);"/>
231 <input type='button' id='unselect_all' value='<?php xl('Unselect All','e'); ?>' onclick="chkbox_select_none(document.select_diagonsis.chkbox);"/>
233 <input type='button' id='submit' value='<?php xl('Submit','e'); ?>' onclick="window_submit(document.select_diagonsis.chkbox);"/>
235 <input type='button' id='cancel' value='<?php xl('Cancel','e'); ?>' onclick="window_close();"/>
237 </center>
238 <?php } ?>
239 </form>
240 </body>
241 </html>