bug fix in find code popup if no parameter is given
[openemr.git] / interface / patient_file / encounter / find_code_popup.php
blob00ab5dd648bc8db652ec6719edbf3dd5c05cfd5d
1 <?php
2 // Copyright (C) 2008 Rod Roark <rod@sunsetsystems.com>
3 //
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.
9 require_once("../../globals.php");
10 require_once("$srcdir/patient.inc");
11 require_once("$srcdir/csv_like_join.php");
12 require_once("../../../custom/code_types.inc.php");
14 $info_msg = "";
15 $codetype = $_REQUEST['codetype'];
16 if (isset($codetype)) {
17 $allowed_codes = split_csv_line($codetype);
20 $form_code_type = $_POST['form_code_type'];
22 <html>
23 <head>
24 <?php html_header_show(); ?>
25 <title><?php xl('Code Finder','e'); ?></title>
26 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
28 <style>
29 td { font-size:10pt; }
30 </style>
32 <script language="JavaScript">
34 function selcode(codetype, code, selector, codedesc) {
35 if (opener.closed || ! opener.set_related)
36 alert('The destination form was closed; I cannot act on your selection.');
37 else
38 opener.set_related(codetype, code, selector, codedesc);
39 window.close();
40 return false;
43 </script>
45 </head>
47 <body class="body_top">
49 <?php if (isset($allowed_codes)) { ?>
50 <form method='post' name='theform' action='find_code_popup.php?codetype=<?php echo $codetype ?>'>
51 <?php } else { ?>
52 <form method='post' name='theform' action='find_code_popup.php'>
53 <?php } ?>
55 <center>
57 <table border='0' cellpadding='5' cellspacing='0'>
59 <tr>
60 <td height="1">
61 </td>
62 </tr>
64 <tr bgcolor='#ddddff'>
65 <td>
66 <b>
68 <?php
69 if (isset($allowed_codes)) {
70 if (count($allowed_codes) === 1) {
71 echo "<input type='text' name='form_code_type' value='$codetype' size='5' readonly>\n";
72 } else {
74 <select name='form_code_type'>
75 <?php
76 foreach ($allowed_codes as $code) {
77 $value = htmlspecialchars($code, ENT_QUOTES);
78 $selected_attr = ($form_code_type == $code) ? " selected='selected'" : '';
79 $text = htmlspecialchars($code, ENT_NOQUOTES);
81 <option value='<?php echo $value ?>'<?php echo $select_attr?>><?php echo $text ?></option>
82 <?php
85 </select>
86 <?php
89 else {
90 echo " <select name='form_code_type'";
91 echo ">\n";
92 foreach ($code_types as $key => $value) {
93 echo " <option value='$key'";
94 if ($codetype == $key || $form_code_type == $key) echo " selected";
95 echo ">$key</option>\n";
97 echo " <option value='PROD'";
98 if ($codetype == 'PROD' || $form_code_type == 'PROD') echo " selected";
99 echo ">Product</option>\n";
100 echo " </select>&nbsp;&nbsp;\n";
104 <?php xl('Search for:','e'); ?>
105 <input type='text' name='search_term' size='12' value='<?php echo $_REQUEST['search_term']; ?>'
106 title='<?php xl('Any part of the desired code or its description','e'); ?>' />
107 &nbsp;
108 <input type='submit' name='bn_search' value='<?php xl('Search','e'); ?>' />
109 &nbsp;&nbsp;&nbsp;
110 <input type='button' value='<?php xl('Erase','e'); ?>' onclick="selcode('', '', '', '')" />
111 </b>
112 </td>
113 </tr>
115 <tr>
116 <td height="1">
117 </td>
118 </tr>
120 </table>
122 <?php if ($_REQUEST['bn_search']) { ?>
124 <table border='0'>
125 <tr>
126 <td><b><?php xl ('Code','e'); ?></b></td>
127 <td><b><?php xl ('Description','e'); ?></b></td>
128 </tr>
129 <?php
130 $search_term = $_REQUEST['search_term'];
131 if ($form_code_type == 'PROD') {
132 $query = "SELECT dt.drug_id, dt.selector, d.name " .
133 "FROM drug_templates AS dt, drugs AS d WHERE " .
134 "( d.name LIKE '%$search_term%' OR " .
135 "dt.selector LIKE '%$search_term%' ) " .
136 "AND d.drug_id = dt.drug_id " .
137 "ORDER BY d.name, dt.selector, dt.drug_id";
138 $res = sqlStatement($query);
139 while ($row = sqlFetchArray($res)) {
140 $drug_id = addslashes($row['drug_id']);
141 $selector = addslashes($row['selector']);
142 $desc = addslashes($row['name']);
143 $anchor = "<a href='' " .
144 "onclick='return selcode(\"PROD\", \"$drug_id\", \"$selector\", \"$desc\")'>";
145 echo " <tr>";
146 echo " <td>$anchor$drug_id:$selector</a></td>\n";
147 echo " <td>$anchor$desc</a></td>\n";
148 echo " </tr>";
151 else {
152 $query = "SELECT code_type, code, modifier, code_text FROM codes " .
153 "WHERE (code_text LIKE '%$search_term%' OR " .
154 "code LIKE '%$search_term%') " .
155 "AND code_type = '" . $code_types[$form_code_type]['id'] . "' " .
156 "ORDER BY code";
157 // echo "\n<!-- $query -->\n"; // debugging
158 $res = sqlStatement($query);
159 while ($row = sqlFetchArray($res)) {
160 $itercode = addslashes($row['code']);
161 $itertext = addslashes(ucfirst(strtolower(trim($row['code_text']))));
162 $anchor = "<a href='' " .
163 "onclick='return selcode(\"$form_code_type\", \"$itercode\", \"\", \"$itertext\")'>";
164 echo " <tr>";
165 echo " <td>$anchor$itercode</a></td>\n";
166 echo " <td>$anchor$itertext</a></td>\n";
167 echo " </tr>";
171 </table>
173 <?php } ?>
175 </center>
176 </form>
177 </body>
178 </html>