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 = $_REQUEST['fstart'] +
0;
26 $searchcolor = empty($GLOBALS['layout_search_color']) ?
27 '#ffff55' : $GLOBALS['layout_search_color'];
31 <?php
html_header_show();?
>
32 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
34 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
44 background
-color
: #ddddff;
48 #searchResultsHeader {
50 background
-color
: lightgrey
;
52 #searchResultsHeader table {
53 width
: 96%
; /* not 100% because the 'searchResults' table has a scrollbar */
54 border
-collapse
: collapse
;
56 #searchResultsHeader th {
65 .srName
{ width
: 12%
; }
66 .srPhone
{ width
: 11%
; }
70 .srMisc
{ width
: 10%
; }
72 #searchResults table {
74 border
-collapse
: collapse
;
75 background
-color
: white
;
83 border
-bottom
: 1px solid
#eee;
88 background
-color
: <?php
echo attr($searchcolor); ?
>;
95 background
-color
: #336699;
100 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery/dist/jquery.min.js"></script
>
102 <script language
="JavaScript">
104 // This is called when forward or backward paging is done.
106 function submitList(offset
) {
107 var f
= document
.forms
[0];
108 var i
= parseInt(f
.fstart
.value
) + offset
;
117 <body
class="body_top">
119 <form method
='post' action
='new_search_popup.php' name
='theform'>
120 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(collectCsrfToken()); ?>" />
122 <input type
='hidden' name
='fstart' value
='<?php echo attr($fstart); ?>' />
125 $MAXSHOW = 100; // maximum number of results to display at once
127 // Construct query and save search parameters as form fields.
128 // An interesting requirement is to sort on the number of matching fields.
133 // array to hold the sql parameters for binding
134 // Note in this special situation, there are two:
135 // 1. For the main sql statement - $sqlBindArray
136 // 2. For the _set_patient_inc_count function - $sqlBindArraySpecial
137 // (this only holds $where and not $relevance binded values)
138 $sqlBindArray = array();
139 $sqlBindArraySpecial = array();
142 foreach ($_REQUEST as $key => $value) {
143 if (substr($key, 0, 3) != 'mf_') {
144 continue; // "match field"
147 $fldname = substr($key, 3);
148 // pubpid requires special treatment. Match on that is fatal.
149 if ($fldname == 'pubpid') {
150 $relevance .= " + 1000 * ( ".add_escape_custom($fldname)." LIKE ? )";
151 array_push($sqlBindArray, $value);
153 $relevance .= " + ( ".add_escape_custom($fldname)." LIKE ? )";
154 array_push($sqlBindArray, $value);
157 $where .= " OR ".add_escape_custom($fldname)." LIKE ?";
158 array_push($sqlBindArraySpecial, $value);
159 echo "<input type='hidden' name='".attr($key)."' value='".attr($value)."' />\n";
163 $sql = "SELECT *, ( $relevance ) AS relevance, " .
164 "DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS " .
165 "FROM patient_data WHERE $where " .
166 "ORDER BY relevance DESC, lname, fname, mname " .
167 "LIMIT ".escape_limit($fstart).", ".escape_limit($MAXSHOW)."";
169 $sqlBindArray = array_merge($sqlBindArray, $sqlBindArraySpecial);
170 $rez = sqlStatement($sql, $sqlBindArray);
172 while ($row = sqlFetchArray($rez)) {
176 _set_patient_inc_count($MAXSHOW, count($result), $where, $sqlBindArraySpecial);
181 <table border
='0' cellpadding
='5' cellspacing
='0' width
='100%'>
186 <td
class='text' align
='center'>
187 <?php
if ($message) {
188 echo "<font color='red'><b>".text($message)."</b></font>\n";
191 <td
class='text' align
='right'>
193 // Show start and end row number, and number of rows, with paging links.
194 $count = $GLOBALS['PATIENT_INC_COUNT'];
195 $fend = $fstart +
$MAXSHOW;
196 if ($fend > $count) {
200 <?php
if ($fstart) { ?
>
201 <a href
="javascript:submitList(-<?php echo attr($MAXSHOW); ?>)">
206 <?php
echo ($fstart +
1) . text(" - $fend of $count") ?
>
207 <?php
if ($count > $fend) { ?
>
209 <a href
="javascript:submitList(<?php echo attr($MAXSHOW); ?>)">
217 <div id
="searchResultsHeader" class="head">
220 <th
class="srID" ><?php
echo xlt('Hits');?
></th
>
221 <th
class="srName" ><?php
echo xlt('Name');?
></th
>
223 // This gets address plus other fields that are mandatory, up to a limit of 5.
224 $extracols = array();
225 $tres = sqlStatement("SELECT field_id, title FROM layout_options " .
226 "WHERE form_id = 'DEM' AND field_id != '' AND " .
227 "( uor > 1 OR uor > 0 AND edit_options LIKE '%D%' ) AND " .
228 "field_id NOT LIKE 'title' AND " .
229 "field_id NOT LIKE '_name' " .
230 "ORDER BY group_id, seq, title LIMIT 9");
232 while ($trow = sqlFetchArray($tres)) {
233 $extracols[$trow['field_id']] = $trow['title'];
234 echo "<th class='srMisc'>" . text(xl_layout_label($trow['title'])) . "</th>\n";
242 <div id
="searchResults">
247 $pubpid_matched = false;
249 foreach ($result as $iter) {
250 $relevance = $iter['relevance'];
251 if ($relevance > 999) {
253 $pubpid_matched = true;
256 echo "<tr id='" . attr($iter['pid']) . "' class='oneresult";
257 // Highlight entries where all fields matched.
258 echo $numfields <= $iter['relevance'] ?
" topresult" : "";
260 echo "<td class='srID'>" . text($relevance) . "</td>\n";
261 echo "<td class='srName'>" . text($iter['lname'] . ", " . $iter['fname']) . "</td>\n";
262 foreach ($extracols as $field_id => $title) {
263 echo "<td class='srMisc'>" . text($iter[$field_id]) . "</td>\n";
269 </div
> <!-- end searchResults DIV
-->
272 <?php
if ($pubpid_matched) { ?
>
273 <input type
='button' value
='<?php echo xla('Cancel
'); ?>'
274 onclick
='dlgclose();' />
276 <input type
='button' value
='<?php echo xla('Confirm Create
New Patient
'); ?>'
277 onclick
='dlgclose("srcConfirmSave", false);' />
281 <script language
="javascript">
283 // jQuery stuff to make the page a little easier to use
285 $
(document
).ready(function() {
286 $
(".oneresult").mouseover(function() { $
(this
).addClass("highlight"); });
287 $
(".oneresult").mouseout(function() { $
(this
).removeClass("highlight"); });
288 $
(".oneresult").click(function() { SelectPatient(this
); });
291 var SelectPatient
= function (eObj
) {
293 // The layout loads just the demographics frame here, which in turn
294 // will set the pid and load all the other frames.
295 $newPage = "../patient_file/summary/demographics.php?set_pid=";
296 $target = "document";
300 var parts
= objID
.split("~");
301 opener
.<?php
echo $target; ?
>.location
.href
= '<?php echo $newPage; ?>' + parts
[0];
306 var f
= opener
.document
.forms
[0];
307 <?php
if ($pubpid_matched) { ?
>
308 alert(<?php
echo xlj('A patient with this ID already exists.'); ?
>);
310 opener
.force_submit
= true;
311 f
.create
.value
= <?php
echo xlj('Confirm Create New Patient'); ?
>;
314 <?php
if (!count($result)) { ?
>
315 $
("<td><?php echo xlt('No matches were found.'); ?></td>").appendTo("#searchResults tr");