2 // Copyright (C) 2010, 2017 Rod Roark <rod@sunsetsystems.com>
3 // Some code was adapted from patient_select.php.
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'];
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">
35 background
-color
: #ddddff;
39 #searchResultsHeader {
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 {
56 .srName
{ width
: 12%
; }
57 .srPhone
{ width
: 11%
; }
61 .srMisc
{ width
: 10%
; }
63 #searchResults table {
65 border
-collapse
: collapse
;
66 background
-color
: white
;
74 border
-bottom
: 1px solid
#eee;
79 background
-color
: <?php
echo htmlspecialchars($searchcolor, ENT_QUOTES
); ?
>;
86 background
-color
: #336699;
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
;
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); ?>' />
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.
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();
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);
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";
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);
161 while ($row = sqlFetchArray($rez)) {
165 _set_patient_inc_count($MAXSHOW, count($result), $where, $sqlBindArraySpecial);
170 <table border
='0' cellpadding
='5' cellspacing
='0' width
='100%'>
175 <td
class='text' align
='center'>
176 <?php
if ($message) {
177 echo "<font color='red'><b>".htmlspecialchars($message, ENT_NOQUOTES
)."</b></font>\n";
180 <td
class='text' align
='right'>
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) {
189 <?php
if ($fstart) { ?
>
190 <a href
="javascript:submitList(-<?php echo $MAXSHOW ?>)">
195 <?php
echo ($fstart +
1) . htmlspecialchars(" - $fend of $count", ENT_NOQUOTES
) ?
>
196 <?php
if ($count > $fend) { ?
>
198 <a href
="javascript:submitList(<?php echo $MAXSHOW ?>)">
206 <div id
="searchResultsHeader" class="head">
209 <th
class="srID" ><?php
echo htmlspecialchars(xl('Hits'), ENT_NOQUOTES
);?
></th
>
210 <th
class="srName" ><?php
echo htmlspecialchars(xl('Name'), ENT_NOQUOTES
);?
></th
>
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";
231 <div id
="searchResults">
236 $pubpid_matched = false;
238 foreach ($result as $iter) {
239 $relevance = $iter['relevance'];
240 if ($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" : "";
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";
258 </div
> <!-- end searchResults DIV
-->
261 <?php
if ($pubpid_matched) { ?
>
262 <input type
='button' value
='<?php echo htmlspecialchars(xl('Cancel
'), ENT_QUOTES); ?>'
263 onclick
='window.close();' />
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();' />
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
) {
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";
289 var parts
= objID
.split("~");
290 opener
.<?php
echo $target; ?
>.location
.href
= '<?php echo $newPage; ?>' + parts
[0];
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); ?>')
299 opener
.force_submit
= true;
300 f
.create
.value
= '<?php echo htmlspecialchars(xl('Confirm Create
New Patient
'), ENT_QUOTES); ?>';
303 <?php
if (!count($result)) { ?
>
304 $
("<td><?php echo htmlspecialchars(xl('No matches were found.'), ENT_QUOTES); ?></td>").appendTo("#searchResults tr");