reordered themes in Header class to include bootstrap prior to main theme (#1193)
[openemr.git] / interface / new / new_search_popup.php
blob6847a4a08fd01c0e6a4e73ff454050b265964269
1 <?php
2 // Copyright (C) 2010, 2017 Rod Roark <rod@sunsetsystems.com>
3 // Some code was adapted from patient_select.php.
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
12 require_once("../globals.php");
13 require_once("$srcdir/patient.inc");
15 $fstart = $_REQUEST['fstart'] + 0;
17 $searchcolor = empty($GLOBALS['layout_search_color']) ?
18 '#ffff55' : $GLOBALS['layout_search_color'];
20 <html>
21 <head>
22 <?php html_header_show();?>
23 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
25 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
26 <style>
27 form {
28 padding: 0px;
29 margin: 0px;
31 #searchCriteria {
32 text-align: center;
33 width: 100%;
34 font-size: 0.8em;
35 background-color: #ddddff;
36 font-weight: bold;
37 padding: 3px;
39 #searchResultsHeader {
40 width: 100%;
41 background-color: lightgrey;
43 #searchResultsHeader table {
44 width: 96%; /* not 100% because the 'searchResults' table has a scrollbar */
45 border-collapse: collapse;
47 #searchResultsHeader th {
48 font-size: 0.7em;
50 #searchResults {
51 width: 100%;
52 height: 80%;
53 overflow: auto;
56 .srName { width: 12%; }
57 .srPhone { width: 11%; }
58 .srSS { width: 11%; }
59 .srDOB { width: 8%; }
60 .srID { width: 7%; }
61 .srMisc { width: 10%; }
63 #searchResults table {
64 width: 100%;
65 border-collapse: collapse;
66 background-color: white;
68 #searchResults tr {
69 cursor: hand;
70 cursor: pointer;
72 #searchResults td {
73 font-size: 0.7em;
74 border-bottom: 1px solid #eee;
76 .oneResult {
78 .topResult {
79 background-color: <?php echo htmlspecialchars($searchcolor, ENT_QUOTES); ?>;
81 .billing {
82 color: red;
83 font-weight: bold;
85 .highlight {
86 background-color: #336699;
87 color: white;
89 </style>
91 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script>
93 <script language="JavaScript">
95 // This is called when forward or backward paging is done.
97 function submitList(offset) {
98 var f = document.forms[0];
99 var i = parseInt(f.fstart.value) + offset;
100 if (i < 0) i = 0;
101 f.fstart.value = i;
102 f.submit();
105 </script>
107 </head>
108 <body class="body_top">
110 <form method='post' action='new_search_popup.php' name='theform'>
111 <input type='hidden' name='fstart' value='<?php echo htmlspecialchars($fstart, ENT_QUOTES); ?>' />
113 <?php
114 $MAXSHOW = 100; // maximum number of results to display at once
116 // Construct query and save search parameters as form fields.
117 // An interesting requirement is to sort on the number of matching fields.
119 $message = "";
120 $numfields = 0;
121 $relevance = "0";
122 // array to hold the sql parameters for binding
123 // Note in this special situation, there are two:
124 // 1. For the main sql statement - $sqlBindArray
125 // 2. For the _set_patient_inc_count function - $sqlBindArraySpecial
126 // (this only holds $where and not $relevance binded values)
127 $sqlBindArray = array();
128 $sqlBindArraySpecial = array();
129 $where = "1 = 0";
131 foreach ($_REQUEST as $key => $value) {
132 if (substr($key, 0, 3) != 'mf_') {
133 continue; // "match field"
136 $fldname = substr($key, 3);
137 // pubpid requires special treatment. Match on that is fatal.
138 if ($fldname == 'pubpid') {
139 $relevance .= " + 1000 * ( ".add_escape_custom($fldname)." LIKE ? )";
140 array_push($sqlBindArray, $value);
141 } else {
142 $relevance .= " + ( ".add_escape_custom($fldname)." LIKE ? )";
143 array_push($sqlBindArray, $value);
146 $where .= " OR ".add_escape_custom($fldname)." LIKE ?";
147 array_push($sqlBindArraySpecial, $value);
148 echo "<input type='hidden' name='".htmlspecialchars($key, ENT_QUOTES)."' value='".htmlspecialchars($value, ENT_QUOTES)."' />\n";
149 ++$numfields;
152 $sql = "SELECT *, ( $relevance ) AS relevance, " .
153 "DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS " .
154 "FROM patient_data WHERE $where " .
155 "ORDER BY relevance DESC, lname, fname, mname " .
156 "LIMIT ".add_escape_custom($fstart).", ".add_escape_custom($MAXSHOW)."";
158 $sqlBindArray = array_merge($sqlBindArray, $sqlBindArraySpecial);
159 $rez = sqlStatement($sql, $sqlBindArray);
160 $result = array();
161 while ($row = sqlFetchArray($rez)) {
162 $result[] = $row;
165 _set_patient_inc_count($MAXSHOW, count($result), $where, $sqlBindArraySpecial);
168 </form>
170 <table border='0' cellpadding='5' cellspacing='0' width='100%'>
171 <tr>
172 <td class='text'>
173 &nbsp;
174 </td>
175 <td class='text' align='center'>
176 <?php if ($message) {
177 echo "<font color='red'><b>".htmlspecialchars($message, ENT_NOQUOTES)."</b></font>\n";
178 } ?>
179 </td>
180 <td class='text' align='right'>
181 <?php
182 // Show start and end row number, and number of rows, with paging links.
183 $count = $GLOBALS['PATIENT_INC_COUNT'];
184 $fend = $fstart + $MAXSHOW;
185 if ($fend > $count) {
186 $fend = $count;
189 <?php if ($fstart) { ?>
190 <a href="javascript:submitList(-<?php echo $MAXSHOW ?>)">
191 &lt;&lt;
192 </a>
193 &nbsp;&nbsp;
194 <?php } ?>
195 <?php echo ($fstart + 1) . htmlspecialchars(" - $fend of $count", ENT_NOQUOTES) ?>
196 <?php if ($count > $fend) { ?>
197 &nbsp;&nbsp;
198 <a href="javascript:submitList(<?php echo $MAXSHOW ?>)">
199 &gt;&gt;
200 </a>
201 <?php } ?>
202 </td>
203 </tr>
204 </table>
206 <div id="searchResultsHeader" class="head">
207 <table>
208 <tr>
209 <th class="srID" ><?php echo htmlspecialchars(xl('Hits'), ENT_NOQUOTES);?></th>
210 <th class="srName" ><?php echo htmlspecialchars(xl('Name'), ENT_NOQUOTES);?></th>
211 <?php
212 // This gets address plus other fields that are mandatory, up to a limit of 5.
213 $extracols = array();
214 $tres = sqlStatement("SELECT field_id, title FROM layout_options " .
215 "WHERE form_id = 'DEM' AND field_id != '' AND " .
216 "( uor > 1 OR uor > 0 AND edit_options LIKE '%D%' ) AND " .
217 "field_id NOT LIKE 'title' AND " .
218 "field_id NOT LIKE '_name' " .
219 "ORDER BY group_id, seq, title LIMIT 9");
221 while ($trow = sqlFetchArray($tres)) {
222 $extracols[$trow['field_id']] = $trow['title'];
223 echo "<th class='srMisc'>" . htmlspecialchars(xl_layout_label($trow['title']), ENT_NOQUOTES) . "</th>\n";
227 </tr>
228 </table>
229 </div>
231 <div id="searchResults">
233 <table>
234 <tr>
235 <?php
236 $pubpid_matched = false;
237 if ($result) {
238 foreach ($result as $iter) {
239 $relevance = $iter['relevance'];
240 if ($relevance > 999) {
241 $relevance -= 999;
242 $pubpid_matched = true;
245 echo "<tr id='" . htmlspecialchars($iter['pid'], ENT_QUOTES) . "' class='oneresult";
246 // Highlight entries where all fields matched.
247 echo $numfields <= $iter['relevance'] ? " topresult" : "";
248 echo "'>";
249 echo "<td class='srID'>".htmlspecialchars($relevance, ENT_NOQUOTES)."</td>\n";
250 echo "<td class='srName'>" . htmlspecialchars($iter['lname'] . ", " . $iter['fname'], ENT_NOQUOTES) . "</td>\n";
251 foreach ($extracols as $field_id => $title) {
252 echo "<td class='srMisc'>" . htmlspecialchars($iter[$field_id], ENT_NOQUOTES) . "</td>\n";
257 </table>
258 </div> <!-- end searchResults DIV -->
260 <center>
261 <?php if ($pubpid_matched) { ?>
262 <input type='button' value='<?php echo htmlspecialchars(xl('Cancel'), ENT_QUOTES); ?>'
263 onclick='window.close();' />
264 <?php } else { ?>
265 <input type='button' value='<?php echo htmlspecialchars(xl('Confirm Create New Patient'), ENT_QUOTES); ?>'
266 onclick='opener.top.restoreSession();opener.document.forms[0].submit();window.close();' />
267 <?php } ?>
268 </center>
270 <script language="javascript">
272 // jQuery stuff to make the page a little easier to use
274 $(document).ready(function() {
275 $(".oneresult").mouseover(function() { $(this).addClass("highlight"); });
276 $(".oneresult").mouseout(function() { $(this).removeClass("highlight"); });
277 $(".oneresult").click(function() { SelectPatient(this); });
280 var SelectPatient = function (eObj) {
281 <?php
282 // The layout loads just the demographics frame here, which in turn
283 // will set the pid and load all the other frames.
284 $newPage = "../patient_file/summary/demographics.php?set_pid=";
285 $target = "document";
288 objID = eObj.id;
289 var parts = objID.split("~");
290 opener.<?php echo $target; ?>.location.href = '<?php echo $newPage; ?>' + parts[0];
291 window.close();
292 return true;
295 var f = opener.document.forms[0];
296 <?php if ($pubpid_matched) { ?>
297 alert('<?php echo htmlspecialchars(xl('A patient with this ID already exists.'), ENT_QUOTES); ?>')
298 <?php } else { ?>
299 opener.force_submit = true;
300 f.create.value = '<?php echo htmlspecialchars(xl('Confirm Create New Patient'), ENT_QUOTES); ?>';
301 <?php } ?>
303 <?php if (!count($result)) { ?>
304 $("<td><?php echo htmlspecialchars(xl('No matches were found.'), ENT_QUOTES); ?></td>").appendTo("#searchResults tr");
305 <?php } ?>
307 </script>
309 </body>
310 </html>