24b5b175715d318fb96fcfdfc67aea455dd92559
[openemr.git] / interface / patient_file / encounter / find_code_popup.php
blob24b5b175715d318fb96fcfdfc67aea455dd92559
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 $fake_register_globals=false;
10 $sanitize_all_escapes=true;
12 require_once("../../globals.php");
13 require_once("$srcdir/patient.inc");
14 require_once("$srcdir/csv_like_join.php");
15 require_once("../../../custom/code_types.inc.php");
17 $info_msg = "";
18 $codetype = $_REQUEST['codetype'];
19 if (isset($codetype)) {
20 $allowed_codes = split_csv_line($codetype);
23 $form_code_type = $_POST['form_code_type'];
25 // This variable is used to store the html element
26 // of the target script where the selected code
27 // will be stored in.
28 $target_element = $_GET['target_element'];
30 <html>
31 <head>
32 <?php html_header_show(); ?>
33 <title><?php echo xlt('Code Finder'); ?></title>
34 <link rel="stylesheet" href='<?php echo attr($css_header) ?>' type='text/css'>
36 <style>
37 td { font-size:10pt; }
38 </style>
40 <script language="JavaScript">
42 // Standard function
43 function selcode(codetype, code, selector, codedesc) {
44 if (opener.closed || ! opener.set_related)
45 alert('<?php echo addslashes( xl('The destination form was closed; I cannot act on your selection.') ); ?>');
46 else
47 opener.set_related(codetype, code, selector, codedesc);
48 window.close();
49 return false;
52 // Standard function with additional parameter to select which
53 // element on the target page to place the selected code into.
54 function selcode_target(codetype, code, selector, codedesc, target_element) {
55 if (opener.closed || ! opener.set_related_target)
56 alert('<?php echo addslashes( xl('The destination form was closed; I cannot act on your selection.') ); ?>');
57 else
58 opener.set_related_target(codetype, code, selector, codedesc, target_element);
59 window.close();
60 return false;
63 </script>
65 </head>
67 <body class="body_top">
69 <?php
70 $string_target_element = "";
71 if (!empty($target_element)) {
72 $string_target_element = "?target_element=".attr($target_element)."&";
74 else {
75 $string_target_element = "?";
78 <?php if (isset($allowed_codes)) { ?>
79 <form method='post' name='theform' action='find_code_popup.php<?php echo $string_target_element ?>codetype=<?php echo attr($codetype) ?>'>
80 <?php } else { ?>
81 <form method='post' name='theform' action='find_code_popup.php<?php echo $string_target_element ?>'>
82 <?php } ?>
84 <center>
86 <table border='0' cellpadding='5' cellspacing='0'>
88 <tr>
89 <td height="1">
90 </td>
91 </tr>
93 <tr bgcolor='#ddddff'>
94 <td>
95 <b>
97 <?php
98 if (isset($allowed_codes)) {
99 if (count($allowed_codes) === 1) {
100 echo "<input type='text' name='form_code_type' value='" . attr($codetype) . "' size='5' readonly>\n";
101 } else {
103 <select name='form_code_type'>
104 <?php
105 foreach ($allowed_codes as $code) {
106 $selected_attr = ($form_code_type == $code) ? " selected='selected'" : '';
108 <option value='<?php echo attr($code) ?>'<?php echo $selected_attr?>><?php echo xlt($code_types[$code]['label']) ?></option>
109 <?php
112 </select>
113 <?php
116 else {
117 echo " <select name='form_code_type'";
118 echo ">\n";
119 foreach ($code_types as $key => $value) {
120 echo " <option value='" . attr($key) . "'";
121 if ($codetype == $key || $form_code_type == $key) echo " selected";
122 echo ">" . xlt($value['label']) . "</option>\n";
124 echo " <option value='PROD'";
125 if ($codetype == 'PROD' || $form_code_type == 'PROD') echo " selected";
126 echo ">" . xlt("Product") . "</option>\n";
127 echo " </select>&nbsp;&nbsp;\n";
131 <?php echo xlt('Search for:'); ?>
132 <input type='text' name='search_term' size='12' value='<?php echo attr($_REQUEST['search_term']); ?>'
133 title='<?php echo xla('Any part of the desired code or its description'); ?>' />
134 &nbsp;
135 <input type='submit' name='bn_search' value='<?php echo xla('Search'); ?>' />
136 &nbsp;&nbsp;&nbsp;
137 <?php if (!empty($target_element)) { ?>
138 <input type='button' value='<?php echo xla('Erase'); ?>' onclick="selcode_target('', '', '', '', '<?php echo addslashes($target_element); ?>')" />
139 <?php } else { ?>
140 <input type='button' value='<?php echo xla('Erase'); ?>' onclick="selcode('', '', '', '')" />
141 <?php } ?>
142 </b>
143 </td>
144 </tr>
146 <tr>
147 <td height="1">
148 </td>
149 </tr>
151 </table>
153 <?php if ($_REQUEST['bn_search']) { ?>
155 <table border='0'>
156 <tr>
157 <td><b><?php echo xlt('Code'); ?></b></td>
158 <td><b><?php echo xlt('Description'); ?></b></td>
159 </tr>
160 <?php
161 $search_term = $_REQUEST['search_term'];
162 $res = code_set_search($form_code_type,$search_term);
163 if ($form_code_type == 'PROD') { // Special case that displays search for products/drugs
164 while ($row = sqlFetchArray($res)) {
165 $drug_id = addslashes($row['drug_id']);
166 $selector = addslashes($row['selector']);
167 $desc = addslashes($row['name']);
168 $anchor = "<a href='' " .
169 "onclick='return selcode(\"PROD\", \"$drug_id\", \"$selector\", \"$desc\")'>";
170 echo " <tr>";
171 echo " <td>$anchor" . text($drug_id.":".$selector) . "</a></td>\n";
172 echo " <td>$anchor" . text($desc) . "</a></td>\n";
173 echo " </tr>";
176 else {
177 while ($row = sqlFetchArray($res)) { // Display normal search
178 $itercode = addslashes($row['code']);
179 $itertext = addslashes(trim($row['code_text']));
180 if (!empty($target_element)) {
181 // add a 5th parameter to function to select the target element on the form for placing the code.
182 $target_element = addslashes($target_element);
183 $anchor = "<a href='' " .
184 "onclick='return selcode_target(\"" . addslashes($form_code_type) . "\", \"$itercode\", \"\", \"$itertext\", \"$target_element\")'>";
186 else {
187 $anchor = "<a href='' " .
188 "onclick='return selcode(\"" . addslashes($form_code_type) . "\", \"$itercode\", \"\", \"$itertext\")'>";
190 echo " <tr>";
191 echo " <td>$anchor" . text($itercode) . "</a></td>\n";
192 echo " <td>$anchor" . text($itertext) . "</a></td>\n";
193 echo " </tr>";
197 </table>
199 <?php } ?>
201 </center>
202 </form>
203 </body>
204 </html>