Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / interface / new / new_search_popup.php
blobdf18c3542a4f684e3bf1dd9d4e9f619def96eb3c
1 <?php
2 /**
3 * new_search_popup.php
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2010-2017 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/patient.inc");
18 if (!empty($_POST)) {
19 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
20 csrfNotVerified();
24 $fstart = isset($_REQUEST['fstart']) ? $_REQUEST['fstart'] + 0 : 0;
26 $searchcolor = empty($GLOBALS['layout_search_color']) ?
27 '#ffff55' : $GLOBALS['layout_search_color'];
29 <html>
30 <head>
31 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
33 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
34 <style>
35 form {
36 padding: 0px;
37 margin: 0px;
39 #searchCriteria {
40 text-align: center;
41 width: 100%;
42 font-size: 0.8em;
43 background-color: #ddddff;
44 font-weight: bold;
45 padding: 3px;
47 #searchResultsHeader {
48 width: 100%;
49 background-color: lightgrey;
51 #searchResultsHeader table {
52 width: 96%; /* not 100% because the 'searchResults' table has a scrollbar */
53 border-collapse: collapse;
55 #searchResultsHeader th {
56 font-size: 0.7em;
58 #searchResults {
59 width: 100%;
60 height: 80%;
61 overflow: auto;
64 .srName { width: 12%; }
65 .srPhone { width: 11%; }
66 .srSS { width: 11%; }
67 .srDOB { width: 8%; }
68 .srID { width: 7%; }
69 .srMisc { width: 10%; }
71 #searchResults table {
72 width: 100%;
73 border-collapse: collapse;
74 background-color: white;
76 #searchResults tr {
77 cursor: hand;
78 cursor: pointer;
80 #searchResults td {
81 font-size: 0.7em;
82 border-bottom: 1px solid #eee;
84 .oneResult {
86 .topResult {
87 background-color: <?php echo attr($searchcolor); ?>;
89 .billing {
90 color: red;
91 font-weight: bold;
93 .highlight {
94 background-color: #336699;
95 color: white;
97 </style>
99 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery/dist/jquery.min.js"></script>
101 <script language="JavaScript">
103 // This is called when forward or backward paging is done.
105 function submitList(offset) {
106 var f = document.forms[0];
107 var i = parseInt(f.fstart.value) + offset;
108 if (i < 0) i = 0;
109 f.fstart.value = i;
110 f.submit();
113 </script>
115 </head>
116 <body class="body_top">
118 <form method='post' action='new_search_popup.php' name='theform'>
119 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
121 <input type='hidden' name='fstart' value='<?php echo attr($fstart); ?>' />
123 <?php
124 $MAXSHOW = 100; // maximum number of results to display at once
126 // Construct query and save search parameters as form fields.
127 // An interesting requirement is to sort on the number of matching fields.
129 $message = "";
130 $numfields = 0;
131 $relevance = "0";
132 // array to hold the sql parameters for binding
133 // Note in this special situation, there are two:
134 // 1. For the main sql statement - $sqlBindArray
135 // 2. For the _set_patient_inc_count function - $sqlBindArraySpecial
136 // (this only holds $where and not $relevance binded values)
137 $sqlBindArray = array();
138 $sqlBindArraySpecial = array();
139 $where = "1 = 0";
141 foreach ($_REQUEST as $key => $value) {
142 if (substr($key, 0, 3) != 'mf_') {
143 continue; // "match field"
146 $fldname = substr($key, 3);
147 // pubpid requires special treatment. Match on that is fatal.
148 if ($fldname == 'pubpid') {
149 $relevance .= " + 1000 * ( ".add_escape_custom($fldname)." LIKE ? )";
150 array_push($sqlBindArray, $value);
151 } else {
152 $relevance .= " + ( ".add_escape_custom($fldname)." LIKE ? )";
153 array_push($sqlBindArray, $value);
156 $where .= " OR ".add_escape_custom($fldname)." LIKE ?";
157 array_push($sqlBindArraySpecial, $value);
158 echo "<input type='hidden' name='".attr($key)."' value='".attr($value)."' />\n";
159 ++$numfields;
162 $sql = "SELECT *, ( $relevance ) AS relevance, " .
163 "DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS " .
164 "FROM patient_data WHERE $where " .
165 "ORDER BY relevance DESC, lname, fname, mname " .
166 "LIMIT ".escape_limit($fstart).", ".escape_limit($MAXSHOW)."";
168 $sqlBindArray = array_merge($sqlBindArray, $sqlBindArraySpecial);
169 $rez = sqlStatement($sql, $sqlBindArray);
170 $result = array();
171 while ($row = sqlFetchArray($rez)) {
172 $result[] = $row;
175 _set_patient_inc_count($MAXSHOW, count($result), $where, $sqlBindArraySpecial);
178 </form>
180 <table border='0' cellpadding='5' cellspacing='0' width='100%'>
181 <tr>
182 <td class='text'>
183 &nbsp;
184 </td>
185 <td class='text' align='center'>
186 <?php if ($message) {
187 echo "<font color='red'><b>".text($message)."</b></font>\n";
188 } ?>
189 </td>
190 <td class='text' align='right'>
191 <?php
192 // Show start and end row number, and number of rows, with paging links.
193 $count = $GLOBALS['PATIENT_INC_COUNT'];
194 $fend = $fstart + $MAXSHOW;
195 if ($fend > $count) {
196 $fend = $count;
199 <?php if ($fstart) { ?>
200 <a href="javascript:submitList(-<?php echo attr($MAXSHOW); ?>)">
201 &lt;&lt;
202 </a>
203 &nbsp;&nbsp;
204 <?php } ?>
205 <?php echo ($fstart + 1) . text(" - $fend of $count") ?>
206 <?php if ($count > $fend) { ?>
207 &nbsp;&nbsp;
208 <a href="javascript:submitList(<?php echo attr($MAXSHOW); ?>)">
209 &gt;&gt;
210 </a>
211 <?php } ?>
212 </td>
213 </tr>
214 </table>
216 <div id="searchResultsHeader" class="head">
217 <table>
218 <tr>
219 <th class="srID" ><?php echo xlt('Hits');?></th>
220 <th class="srName" ><?php echo xlt('Name');?></th>
221 <?php
222 // This gets address plus other fields that are mandatory, up to a limit of 5.
223 $extracols = array();
224 $tres = sqlStatement("SELECT field_id, title FROM layout_options " .
225 "WHERE form_id = 'DEM' AND field_id != '' AND " .
226 "( uor > 1 OR uor > 0 AND edit_options LIKE '%D%' ) AND " .
227 "field_id NOT LIKE 'title' AND " .
228 "field_id NOT LIKE '_name' " .
229 "ORDER BY group_id, seq, title LIMIT 9");
231 while ($trow = sqlFetchArray($tres)) {
232 $extracols[$trow['field_id']] = $trow['title'];
233 echo "<th class='srMisc'>" . text(xl_layout_label($trow['title'])) . "</th>\n";
237 </tr>
238 </table>
239 </div>
241 <div id="searchResults">
243 <table>
244 <tr>
245 <?php
246 $pubpid_matched = false;
247 if ($result) {
248 foreach ($result as $iter) {
249 $relevance = $iter['relevance'];
250 if ($relevance > 999) {
251 $relevance -= 999;
252 $pubpid_matched = true;
255 echo "<tr id='" . attr($iter['pid']) . "' class='oneresult";
256 // Highlight entries where all fields matched.
257 echo $numfields <= $iter['relevance'] ? " topresult" : "";
258 echo "'>";
259 echo "<td class='srID'>" . text($relevance) . "</td>\n";
260 echo "<td class='srName'>" . text($iter['lname'] . ", " . $iter['fname']) . "</td>\n";
261 foreach ($extracols as $field_id => $title) {
262 echo "<td class='srMisc'>" . text($iter[$field_id]) . "</td>\n";
267 </table>
268 </div> <!-- end searchResults DIV -->
270 <center>
271 <?php if ($pubpid_matched) { ?>
272 <input type='button' value='<?php echo xla('Cancel'); ?>'
273 onclick='dlgclose();' />
274 <?php } else { ?>
275 <input type='button' value='<?php echo xla('Confirm Create New Patient'); ?>'
276 onclick='dlgclose("srcConfirmSave", false);' />
277 <?php } ?>
278 </center>
280 <script language="javascript">
282 // jQuery stuff to make the page a little easier to use
284 $(function() {
285 $(".oneresult").mouseover(function() { $(this).addClass("highlight"); });
286 $(".oneresult").mouseout(function() { $(this).removeClass("highlight"); });
287 $(".oneresult").click(function() { SelectPatient(this); });
290 var SelectPatient = function (eObj) {
291 <?php
292 // The layout loads just the demographics frame here, which in turn
293 // will set the pid and load all the other frames.
294 $newPage = "../patient_file/summary/demographics.php?set_pid=";
295 $target = "document";
298 objID = eObj.id;
299 var parts = objID.split("~");
300 opener.<?php echo $target; ?>.location.href = '<?php echo $newPage; ?>' + parts[0];
301 dlgclose();
302 return true;
305 var f = opener.document.forms[0];
306 <?php if ($pubpid_matched) { ?>
307 alert(<?php echo xlj('A patient with this ID already exists.'); ?>);
308 <?php } else { ?>
309 opener.force_submit = true;
310 f.create.value = <?php echo xlj('Confirm Create New Patient'); ?>;
311 <?php } ?>
313 <?php if (!count($result)) { ?>
314 $("<td><?php echo xlt('No matches were found.'); ?></td>").appendTo("#searchResults tr");
315 <?php } ?>
317 </script>
319 </body>
320 </html>