Tag documents to procedures (#4465)
[openemr.git] / interface / patient_file / encounter / search_code.php
blob14a946c672f0f93bb99397b230898ca668391d0a
1 <?php
3 /**
4 * search_code.php
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("../../globals.php");
14 require_once("../../../custom/code_types.inc.php");
16 use OpenEMR\Common\Csrf\CsrfUtils;
17 use OpenEMR\Core\Header;
19 //the maximum number of records to pull out with the search:
20 $M = 30;
22 //the number of records to display before starting a second column:
23 $N = 15;
25 $code_type = $_GET['type'];
28 <html>
29 <head>
30 <?php Header::setupHeader(); ?>
32 </head>
33 <body class="body_bottom">
34 <div id="patient_search_code">
36 <table class="table-borderless h-100" cellspacing='0' cellpadding='0'>
37 <tr>
39 <td class="align-top">
41 <form name="search_form" id="search_form" method="post" action="search_code.php?type=<?php echo attr_url($code_type); ?>">
42 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
44 <input type="hidden" name="mode" value="search" />
46 <span class="title"><?php echo text($code_type); ?> <?php echo xlt('Codes'); ?></span><br />
48 <input type="textbox" id="text" name="text" size="15" />
50 <input type='submit' id="submitbtn" name="submitbtn" value='<?php echo xla('Search'); ?>' />
51 <!-- TODO: Use BS4 classes here !-->
52 <div id="searchspinner" style="display: inline; visibility: hidden;"><img src="<?php echo $GLOBALS['webroot'] ?>/interface/pic/ajax-loader.gif"></div>
54 </form>
56 <?php
57 if (isset($_POST["mode"]) && $_POST["mode"] == "search" && $_POST["text"] == "") {
58 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
59 CsrfUtils::csrfNotVerified();
62 echo "<div id='resultsummary bg-success'>";
63 echo "Enter search criteria above</div>";
66 if (isset($_POST["mode"]) && $_POST["mode"] == "search" && $_POST["text"] != "") {
67 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
68 CsrfUtils::csrfNotVerified();
71 // $sql = "SELECT * FROM codes WHERE (code_text LIKE '%" . $_POST["text"] .
72 // "%' OR code LIKE '%" . $_POST["text"] . "%') AND code_type = '" .
73 // $code_types[$code_type]['id'] . "' ORDER BY code LIMIT " . ($M + 1);
75 // The above is obsolete now, fees come from the prices table:
76 $sql = "SELECT codes.*, prices.pr_price FROM codes " .
77 "LEFT OUTER JOIN patient_data ON patient_data.pid = ? " .
78 "LEFT OUTER JOIN prices ON prices.pr_id = codes.id AND " .
79 "prices.pr_selector = '' AND " .
80 "prices.pr_level = patient_data.pricelevel " .
81 "WHERE (code_text LIKE ? OR " .
82 "code LIKE ?) AND " .
83 "code_type = ? " .
84 "ORDER BY code " .
85 " LIMIT " . escape_limit(($M + 1)) .
86 "";
88 if ($res = sqlStatement($sql, array($pid, "%" . $_POST["text"] . "%", "%" . $_POST["text"] . "%", $code_types[$code_type]['id']))) {
89 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
90 $result[$iter] = $row;
93 echo "<div id='resultsummary bg-success'>";
94 if (count($result) > $M) {
95 echo "Showing the first " . text($M) . " results";
96 } elseif (count($result) == 0) {
97 echo "No results found";
98 } else {
99 echo "Showing all " . text(count($result)) . " results";
102 echo "</div>";
104 <div id="results">
105 <table>
106 <tr class='text'>
107 <td class='align-top'>
108 <?php
109 $count = 0;
110 $total = 0;
112 if ($result) {
113 foreach ($result as $iter) {
114 if ($count == $N) {
115 echo "</td><td class='align-top'>\n";
116 $count = 0;
119 echo "<div class='oneresult' style='padding: 3px 0 3px 0;'>";
120 echo "<a target='" . xla('Diagnosis') . "' href='diagnosis.php?mode=add" .
121 "&type=" . attr_url($code_type) .
122 "&code=" . attr_url($iter["code"]) .
123 "&modifier=" . attr_url($iter["modifier"]) .
124 "&units=" . attr_url($iter["units"]) .
125 // "&fee=" . attr_url($iter["fee"]) .
126 "&fee=" . attr_url($iter['pr_price']) .
127 "&text=" . attr_url($iter["code_text"]) .
128 "&csrf_token_form=" . attr_url(CsrfUtils::collectCsrfToken()) .
129 "' onclick='top.restoreSession()'>";
130 echo ucwords("<b>" . text(strtoupper($iter["code"])) . "&nbsp;" . text($iter['modifier']) .
131 "</b>" . " " . text(strtolower($iter["code_text"])));
132 echo "</a><br />\n";
133 echo "</div>";
135 $count++;
136 $total++;
138 if ($total == $M) {
139 echo "</span><span class='alert-custom'>" . xlt('Some codes were not displayed.') . "</span>\n";
140 break;
145 </td></tr></table>
146 </div>
147 <?php
152 </td>
153 </tr>
154 </table>
156 </div> <!-- end large outer patient_search_code DIV -->
157 </body>
159 <script>
161 // jQuery stuff to make the page a little easier to use
163 $(function () {
164 $("#text").trigger("focus");
165 $(".oneresult").on("mouseover", function() { $(this).toggleClass("highlight"); });
166 $(".oneresult").on("mouseout", function() { $(this).toggleClass("highlight"); });
167 //$(".oneresult").click(function() { SelectPatient(this); });
168 $("#search_form").on("submit", function() { SubmitForm(this); });
171 // show the 'searching...' status and submit the form
172 var SubmitForm = function(eObj) {
173 $("#submitbtn").attr("disabled", "true");
174 $("#submitbtn").css("disabled", "true");
175 $("#searchspinner").css("visibility", "visible");
176 return top.restoreSession();
179 </script>
181 </html>