Fourth merge from Julia Longtin repository with conflict fix in interface/patient_fil...
[openemr.git] / interface / patient_file / encounter / find_code_popup.php
blobc26d3170d4aa638c812382d4b10e80a6ce8e44d0
1 <?php
2 /* Copyright (C) 2008 Rod Roark <rod@sunsetsystems.com>
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.
8 */
10 $fake_register_globals=false;
11 $sanitize_all_escapes=true;
13 require_once('../../globals.php');
14 require_once($GLOBALS['srcdir'].'/patient.inc');
15 require_once($GLOBALS['srcdir'].'/csv_like_join.php');
16 require_once($GLOBALS['fileroot'].'/custom/code_types.inc.php');
18 $info_msg = "";
19 $codetype = $_REQUEST['codetype'];
20 if (isset($codetype)) {
21 $allowed_codes = split_csv_line($codetype);
24 $form_code_type = $_POST['form_code_type'];
26 // This variable is used to store the html element
27 // of the target script where the selected code
28 // will be stored in.
29 $target_element = $_GET['target_element'];
31 <html>
32 <head>
33 <?php html_header_show(); ?>
34 <title><?php echo xlt('Code Finder'); ?></title>
35 <link rel="stylesheet" href='<?php echo attr($css_header) ?>' type='text/css'>
37 <style>
38 td { font-size:10pt; }
39 </style>
41 <script language="JavaScript">
43 // Standard function
44 function selcode(codetype, code, selector, codedesc) {
45 if (opener.closed || ! opener.set_related)
46 alert('<?php echo addslashes( xl('The destination form was closed; I cannot act on your selection.') ); ?>');
47 else
48 opener.set_related(codetype, code, selector, codedesc);
49 window.close();
50 return false;
53 // Standard function with additional parameter to select which
54 // element on the target page to place the selected code into.
55 function selcode_target(codetype, code, selector, codedesc, target_element) {
56 if (opener.closed || ! opener.set_related_target)
57 alert('<?php echo addslashes( xl('The destination form was closed; I cannot act on your selection.') ); ?>');
58 else
59 opener.set_related_target(codetype, code, selector, codedesc, target_element);
60 window.close();
61 return false;
64 </script>
66 </head>
68 <body class="body_top" OnLoad="document.theform.search_term.focus();">
70 <?php
71 $string_target_element = "";
72 if (!empty($target_element)) {
73 $string_target_element = "?target_element=".attr($target_element)."&";
75 else {
76 $string_target_element = "?";
79 <?php if (isset($allowed_codes)) { ?>
80 <form method='post' name='theform' action='find_code_popup.php<?php echo $string_target_element ?>codetype=<?php echo attr($codetype) ?>'>
81 <?php } else { ?>
82 <form method='post' name='theform' action='find_code_popup.php<?php echo $string_target_element ?>'>
83 <?php } ?>
85 <center>
87 <table border='0' cellpadding='5' cellspacing='0'>
89 <tr>
90 <td height="1">
91 </td>
92 </tr>
94 <tr bgcolor='#ddddff'>
95 <td>
96 <b>
98 <?php
99 if (isset($allowed_codes)) {
100 if (count($allowed_codes) === 1) {
101 echo "<input type='text' name='form_code_type' value='" . attr($codetype) . "' size='5' readonly>\n";
102 } else {
104 <select name='form_code_type'>
105 <?php
106 foreach ($allowed_codes as $code) {
107 $selected_attr = ($form_code_type == $code) ? " selected='selected'" : '';
109 <option value='<?php echo attr($code) ?>'<?php echo $selected_attr?>><?php echo xlt($code_types[$code]['label']) ?></option>
110 <?php
113 </select>
114 <?php
117 else {
118 echo " <select name='form_code_type'";
119 echo ">\n";
120 foreach ($code_types as $key => $value) {
121 echo " <option value='" . attr($key) . "'";
122 if ($codetype == $key || $form_code_type == $key) echo " selected";
123 echo ">" . xlt($value['label']) . "</option>\n";
125 echo " <option value='PROD'";
126 if ($codetype == 'PROD' || $form_code_type == 'PROD') echo " selected";
127 echo ">" . xlt("Product") . "</option>\n";
128 echo " </select>&nbsp;&nbsp;\n";
132 <?php echo xlt('Search for:'); ?>
133 <input type='text' name='search_term' size='12' value='<?php echo attr($_REQUEST['search_term']); ?>'
134 title='<?php echo xla('Any part of the desired code or its description'); ?>' />
135 &nbsp;
136 <input type='submit' name='bn_search' value='<?php echo xla('Search'); ?>' />
137 &nbsp;&nbsp;&nbsp;
138 <?php if (!empty($target_element)) { ?>
139 <input type='button' value='<?php echo xla('Erase'); ?>' onclick="selcode_target('', '', '', '', '<?php echo attr(addslashes($target_element)); ?>')" />
140 <?php } else { ?>
141 <input type='button' value='<?php echo xla('Erase'); ?>' onclick="selcode('', '', '', '')" />
142 <?php } ?>
143 </b>
144 </td>
145 </tr>
147 <tr>
148 <td height="1">
149 </td>
150 </tr>
152 </table>
154 <?php if ($_REQUEST['bn_search']) { ?>
156 <table border='0'>
157 <tr>
158 <td><b><?php echo xlt('Code'); ?></b></td>
159 <td><b><?php echo xlt('Description'); ?></b></td>
160 </tr>
161 <?php
162 $search_term = $_REQUEST['search_term'];
163 $res = main_code_set_search($form_code_type,$search_term);
164 if ($form_code_type == 'PROD') { // Special case that displays search for products/drugs
165 while ($row = sqlFetchArray($res)) {
166 $drug_id = $row['drug_id'];
167 $selector = $row['selector'];
168 $desc = $row['name'];
169 $anchor = "<a href='' " .
170 "onclick='return selcode(\"PROD\", \"" . attr(addslashes($drug_id)) . "\", \"" . attr(addslashes($selector)) . "\", \"" . attr(addslashes($desc)) . "\")'>";
171 echo " <tr>";
172 echo " <td>$anchor" . text($drug_id.":".$selector) . "</a></td>\n";
173 echo " <td>$anchor" . text($desc) . "</a></td>\n";
174 echo " </tr>";
177 else {
178 while ($row = sqlFetchArray($res)) { // Display normal search
179 $itercode = $row['code'];
180 $itertext = trim($row['code_text']);
181 if (!empty($target_element)) {
182 // add a 5th parameter to function to select the target element on the form for placing the code.
183 $anchor = "<a href='' " .
184 "onclick='return selcode_target(\"" . attr(addslashes($form_code_type)) . "\", \"" . attr(addslashes($itercode)) . "\", \"\", \"" . attr(addslashes($itertext)) . "\", \"" . attr(addslashes($target_element)) . "\")'>";
186 else {
187 $anchor = "<a href='' " .
188 "onclick='return selcode(\"" . attr(addslashes($form_code_type)) . "\", \"" . attr(addslashes($itercode)) . "\", \"\", \"" . attr(addslashes($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>