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");
19 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
24 $fstart = isset($_REQUEST['fstart']) ?
$_REQUEST['fstart'] +
0 : 0;
26 $searchcolor = empty($GLOBALS['layout_search_color']) ?
27 '#ffff55' : $GLOBALS['layout_search_color'];
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">
43 background
-color
: #ddddff;
47 #searchResultsHeader {
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 {
64 .srName
{ width
: 12%
; }
65 .srPhone
{ width
: 11%
; }
69 .srMisc
{ width
: 10%
; }
71 #searchResults table {
73 border
-collapse
: collapse
;
74 background
-color
: white
;
82 border
-bottom
: 1px solid
#eee;
87 background
-color
: <?php
echo attr($searchcolor); ?
>;
94 background
-color
: #336699;
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
;
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); ?>' />
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.
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();
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);
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";
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);
171 while ($row = sqlFetchArray($rez)) {
175 _set_patient_inc_count($MAXSHOW, count($result), $where, $sqlBindArraySpecial);
180 <table border
='0' cellpadding
='5' cellspacing
='0' width
='100%'>
185 <td
class='text' align
='center'>
186 <?php
if ($message) {
187 echo "<font color='red'><b>".text($message)."</b></font>\n";
190 <td
class='text' align
='right'>
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) {
199 <?php
if ($fstart) { ?
>
200 <a href
="javascript:submitList(-<?php echo attr($MAXSHOW); ?>)">
205 <?php
echo ($fstart +
1) . text(" - $fend of $count") ?
>
206 <?php
if ($count > $fend) { ?
>
208 <a href
="javascript:submitList(<?php echo attr($MAXSHOW); ?>)">
216 <div id
="searchResultsHeader" class="head">
219 <th
class="srID" ><?php
echo xlt('Hits');?
></th
>
220 <th
class="srName" ><?php
echo xlt('Name');?
></th
>
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";
241 <div id
="searchResults">
246 $pubpid_matched = false;
248 foreach ($result as $iter) {
249 $relevance = $iter['relevance'];
250 if ($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" : "";
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";
268 </div
> <!-- end searchResults DIV
-->
271 <?php
if ($pubpid_matched) { ?
>
272 <input type
='button' value
='<?php echo xla('Cancel
'); ?>'
273 onclick
='dlgclose();' />
275 <input type
='button' value
='<?php echo xla('Confirm Create
New Patient
'); ?>'
276 onclick
='dlgclose("srcConfirmSave", false);' />
280 <script language
="javascript">
282 // jQuery stuff to make the page a little easier to use
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
) {
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";
299 var parts
= objID
.split("~");
300 opener
.<?php
echo $target; ?
>.location
.href
= '<?php echo $newPage; ?>' + parts
[0];
305 var f
= opener
.document
.forms
[0];
306 <?php
if ($pubpid_matched) { ?
>
307 alert(<?php
echo xlj('A patient with this ID already exists.'); ?
>);
309 opener
.force_submit
= true;
310 f
.create
.value
= <?php
echo xlj('Confirm Create New Patient'); ?
>;
313 <?php
if (!count($result)) { ?
>
314 $
("<td><?php echo xlt('No matches were found.'); ?></td>").appendTo("#searchResults tr");