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.
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");
15 $codetype = $_REQUEST['codetype'];
16 if (isset($codetype)) {
17 $allowed_codes = split_csv_line($codetype);
20 $form_code_type = $_POST['form_code_type'];
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'>
29 td
{ font
-size
:10pt
; }
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.');
38 opener
.set_related(codetype
, code
, selector
, codedesc
);
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 ?>'>
52 <form method
='post' name
='theform' action
='find_code_popup.php'>
57 <table border
='0' cellpadding
='5' cellspacing
='0'>
64 <tr bgcolor
='#ddddff'>
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";
74 <select name
='form_code_type'>
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
>
90 echo " <select name='form_code_type'";
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> \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
'); ?>' />
108 <input type
='submit' name
='bn_search' value
='<?php xl('Search
','e
'); ?>' />
110 <input type
='button' value
='<?php xl('Erase
','e
'); ?>' onclick
="selcode('', '', '', '')" />
122 <?php
if ($_REQUEST['bn_search']) { ?
>
126 <td
><b
><?php
xl ('Code','e'); ?
></b
></td
>
127 <td
><b
><?php
xl ('Description','e'); ?
></b
></td
>
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\")'>";
146 echo " <td>$anchor$drug_id:$selector</a></td>\n";
147 echo " <td>$anchor$desc</a></td>\n";
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'] . "' " .
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\")'>";
165 echo " <td>$anchor$itercode</a></td>\n";
166 echo " <td>$anchor$itertext</a></td>\n";