2 /* Copyright (C) 2008-2014 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.
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');
19 $codetype = $_REQUEST['codetype'];
20 if (!empty($codetype)) {
21 $allowed_codes = split_csv_line($codetype);
24 $form_code_type = $_POST['form_code_type'];
26 // Determine which code type will be selected by default.
28 if (!empty($form_code_type)) {
29 $default = $form_code_type;
30 } else if (!empty($allowed_codes) && count($allowed_codes) == 1) {
31 $default = $allowed_codes[0];
32 } else if (!empty($_REQUEST['default'])) {
33 $default = $_REQUEST['default'];
36 // This variable is used to store the html element
37 // of the target script where the selected code
39 $target_element = $_GET['target_element'];
43 <?php
html_header_show(); ?
>
44 <title
><?php
echo xlt('Code Finder'); ?
></title
>
45 <link rel
="stylesheet" href
='<?php echo attr($css_header) ?>' type
='text/css'>
48 td
{ font
-size
:10pt
; }
50 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
52 <script language
="JavaScript">
55 function selcode(codetype
, code
, selector
, codedesc
) {
56 if (opener
.closed ||
! opener
.set_related
) {
57 alert('<?php echo xls('The destination form was closed
; I cannot act on your selection
.'); ?>');
60 var msg
= opener
.set_related(codetype
, code
, selector
, codedesc
);
67 // TBD: The following function is not necessary. See
68 // interface/forms/LBF/new.php for an alternative method that does not require it.
71 // Standard function with additional parameter to select which
72 // element on the target page to place the selected code into.
73 function selcode_target(codetype
, code
, selector
, codedesc
, target_element
) {
74 if (opener
.closed ||
! opener
.set_related_target
)
75 alert('<?php echo xls('The destination form was closed
; I cannot act on your selection
.'); ?>');
77 opener
.set_related_target(codetype
, code
, selector
, codedesc
, target_element
);
86 $focus = "document.theform.search_term.select();";
88 <body
class="body_top" OnLoad
="<?php echo $focus; ?>">
91 $string_target_element = "";
92 if (!empty($target_element)) {
93 $string_target_element = "?target_element=" . urlencode($target_element) . "&";
95 $string_target_element = "?";
98 <?php
if (!empty($allowed_codes)) { ?
>
99 <form method
='post' name
='theform' action
='find_code_popup.php<?php echo $string_target_element ?>codetype=<?php echo urlencode($codetype) ?>'>
101 <form method
='post' name
='theform' action
='find_code_popup.php<?php echo $string_target_element ?>'>
106 <table border
='0' cellpadding
='5' cellspacing
='0'>
113 <tr bgcolor
='#ddddff'>
118 if (!empty($allowed_codes)) {
119 if (count($allowed_codes) === 1) {
120 echo "<input type='text' name='form_code_type' value='" . attr($codetype) . "' size='5' readonly>\n";
123 <select name
='form_code_type'>
125 foreach ($allowed_codes as $code) {
126 $selected_attr = ($default == $code) ?
" selected='selected'" : '';
128 <option value
='<?php echo attr($code) ?>'<?php
echo $selected_attr ?
>><?php
echo xlt($code_types[$code]['label']) ?
></option
>
136 // No allowed types were specified, so show all.
137 echo " <select name='form_code_type'";
139 foreach ($code_types as $key => $value) {
140 echo " <option value='" . attr($key) . "'";
141 if ($default == $key) {
145 echo ">" . xlt($value['label']) . "</option>\n";
148 echo " <option value='PROD'";
149 if ($default == 'PROD') {
153 echo ">" . xlt("Product") . "</option>\n";
154 echo " </select> \n";
158 <?php
echo xlt('Search for:'); ?
>
159 <input type
='text' name
='search_term' size
='12' value
='<?php echo attr($_REQUEST['search_term
']); ?>'
160 title
='<?php echo xla('Any part of the desired code
or its description
'); ?>' />
162 <input type
='submit' name
='bn_search' value
='<?php echo xla('Search
'); ?>' />
164 <?php
if (!empty($target_element)) { ?
>
165 <input type
='button' value
='<?php echo xla('Erase
'); ?>' onclick
="selcode_target('', '', '', '', '<?php echo attr(addslashes($target_element)); ?>')" />
167 <input type
='button' value
='<?php echo xla('Erase
'); ?>' onclick
="selcode('', '', '', '')" />
181 if ($_REQUEST['bn_search'] ||
$_REQUEST['search_term']) {
182 if (!$form_code_type) {
183 $form_code_type = $codetype;
189 <td
><b
><?php
echo xlt('Code'); ?
></b
></td
>
190 <td
><b
><?php
echo xlt('Description'); ?
></b
></td
>
193 $search_term = $_REQUEST['search_term'];
194 $res = main_code_set_search($form_code_type, $search_term);
195 if ($form_code_type == 'PROD') { // Special case that displays search for products/drugs
196 while ($row = sqlFetchArray($res)) {
197 $drug_id = $row['drug_id'];
198 $selector = $row['selector'];
199 $desc = $row['name'];
200 $anchor = "<a href='' " .
201 "onclick='return selcode(\"PROD\", \"" . attr(addslashes($drug_id)) . "\", \"" . attr(addslashes($selector)) . "\", \"" . attr(addslashes($desc)) . "\")'>";
203 echo " <td>$anchor" . text($drug_id.":".$selector) . "</a></td>\n";
204 echo " <td>$anchor" . text($desc) . "</a></td>\n";
208 while ($row = sqlFetchArray($res)) { // Display normal search
209 $itercode = $row['code'];
210 $itertext = trim($row['code_text']);
211 if (!empty($target_element)) {
212 // add a 5th parameter to function to select the target element on the form for placing the code.
213 $anchor = "<a href='' " .
214 "onclick='return selcode_target(\"" . attr(addslashes($form_code_type)) . "\", \"" . attr(addslashes($itercode)) . "\", \"\", \"" . attr(addslashes($itertext)) . "\", \"" . attr(addslashes($target_element)) . "\")'>";
216 $anchor = "<a href='' " .
217 "onclick='return selcode(\"" . attr(addslashes($form_code_type)) . "\", \"" . attr(addslashes($itercode)) . "\", \"\", \"" . attr(addslashes($itertext)) . "\")'>";
221 echo " <td>$anchor" . text($itercode) . "</a></td>\n";
222 echo " <td>$anchor" . text($itertext) . "</a></td>\n";