3 * Patient matching and selection for the WordPress Patient Portal.
5 * LICENSE: 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.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
17 * @author Rod Roark <rod@sunsetsystems.com>
23 require_once("../globals.php");
24 require_once("$srcdir/patient.inc");
25 require_once("$srcdir/options.inc.php");
26 require_once("portal.inc.php");
28 $postid = intval($_REQUEST['postid']);
31 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
32 if ($result['errmsg']) {
33 die(text($result['errmsg']));
39 <?php
html_header_show(); ?
>
40 <link rel
=stylesheet href
="<?php echo $css_header; ?>" type
="text/css">
48 #searchResults table {
50 border
-collapse
: collapse
;
51 background
-color
: white
;
54 background
-color
: lightgrey
;
60 border
-bottom
: 1px solid
#eee;
66 background
-color
: #336699;
74 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/manual-added-packages/jquery-min-1-2-2/index.js"></script
>
75 <script language
="JavaScript">
77 $
(document
).ready(function(){
78 $
(".oneresult").mouseover(function() {$
(this
).addClass("highlight");});
79 $
(".oneresult").mouseout(function() {$
(this
).removeClass("highlight");});
82 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
84 function myRestoreSession() {
85 if (top
.restoreSession
) top
.restoreSession(); else opener
.top
.restoreSession();
89 function openPatient(ptid
) {
90 // This works whether we are a popup or in the OpenEMR frameset.
92 document
.location
.href
= 'patient_form.php?postid=<?php echo xls($postid); ?>&ptid=' + ptid
;
98 <body
class="body_top">
100 <form method
='post' action
='patient_select.php' onsubmit
='return myRestoreSession()'>
103 // print_r($result); // debugging
110 $cmsportal_login = trim($result['post']['user']);
111 if ($cmsportal_login !== '') {
112 $clsql .= " + ((cmsportal_login IS NOT NULL AND cmsportal_login = ?) * 100)";
113 $clarr[] = $cmsportal_login;
117 $fname = trim($result['fields']['fname']);
119 $clsql .= " + ((fname IS NOT NULL AND fname = ?) * 5)";
124 $lname = trim($result['fields']['lname']);
126 $clsql .= " + ((lname IS NOT NULL AND lname = ?) * 5)";
131 $dob = fixDate(trim($result['fields']['dob']), '');
133 $clsql .= " + ((DOB IS NOT NULL AND DOB = ?) * 5)";
137 // SSN match is worth a lot and we allow for matching on last 4 digits.
138 $ssn = preg_replace('/[^0-9]/', '', $result['fields']['ss']);
139 if (strlen($ssn) > 3) {
140 $clsql .= " + ((ss IS NOT NULL AND ss LIKE ?) * 10)";
144 // Zip code makes it unnecessary to match on city and state.
145 $zip = preg_replace('/[^0-9]/', '', $result['fields']['postal_code']);
146 $zip = substr($zip, 0, 5);
147 if (strlen($zip) == 5) {
148 $clsql .= " + ((postal_code IS NOT NULL AND postal_code LIKE ?) * 2)";
152 // This generates a REGEXP query that matches the first 2 words of the street address.
153 if (preg_match('/^\W*(\w+)\W+(\w+)/', $result['fields']['street'], $matches)) {
154 $clsql .= " + ((street IS NOT NULL AND street REGEXP '^[^[:alnum:]]*";
155 $clsql .= $matches[1];
156 $clsql .= "[^[:alnum:]]+";
157 $clsql .= $matches[2];
158 $clsql .= "[[:>:]]') * 2)";
161 $sql = "SELECT $clsql AS closeness, " .
162 "pid, cmsportal_login, fname, lname, mname, DOB, ss, postal_code, " .
163 "street, phone_biz, phone_home, phone_cell, phone_contact " .
164 "FROM patient_data " .
165 "ORDER BY closeness DESC, lname, fname LIMIT 10";
166 $res = sqlStatement($sql, $clarr);
168 // echo "<!-- $sql -->\n"; // debugging
170 $phone = $result['fields']['phone_biz'];
172 $phone = $result['fields']['phone_home'];
176 $phone = $result['fields']['phone_cell'];
180 $phone = $result['fields']['phone_contact'];
184 <div id
="searchResults">
187 <th
><?php
echo xlt('Portal ID'); ?
></th
>
188 <th
><?php
echo xlt('Name'); ?
></th
>
189 <th
><?php
echo xlt('Phone'); ?
></th
>
190 <th
><?php
echo xlt('SS'); ?
></th
>
191 <th
><?php
echo xlt('DOB'); ?
></th
>
192 <th
><?php
echo xlt('Address'); ?
></th
>
195 <th style
='font-weight:normal'><?php
echo text($result['post']['user']); ?
></th
>
196 <th style
='font-weight:normal'><?php
echo text("$lname, $fname"); ?
></th
>
197 <th style
='font-weight:normal'><?php
echo text($phone); ?
></th
>
198 <th style
='font-weight:normal'><?php
echo text($ssn); ?
></th
>
199 <th style
='font-weight:normal'><?php
echo text($dob); ?
></th
>
200 <th style
='font-weight:normal'><?php
echo text($result['fields']['street'] . ' ' . $zip); ?
></th
>
204 while ($row = sqlFetchArray($res)) {
205 if ($row['closeness'] == 0) {
209 if ($row['closeness'] >= 100) {
211 $login_pid = $row['pid'];
213 // We have a match on login name but this is not one, so ignore it.
214 if ($login_matches) {
219 $phone = $row['phone_biz'];
221 $phone = $row['phone_home'];
225 $phone = $row['phone_cell'];
229 $phone = $row['phone_contact'];
232 echo " <tr class='oneresult'";
233 echo " onclick=\"openPatient(" .
234 "'" . addslashes($row['pid']) . "'" .
237 if ($row['cmsportal_login'] !== '' && $result['post']['user'] !== $row['cmsportal_login']) {
238 echo " style='color:red' title='" . xla('Portal ID does not match request from portal!') . "'";
241 echo ">" . text($row['cmsportal_login']) . "</td>\n";
242 echo " <td>" . text($row['lname'] . ", " . $row['fname']) . "</td>\n";
243 echo " <td>" . text($phone) . "</td>\n";
244 echo " <td>" . text($row['ss']) . "</td>\n";
245 echo " <td>" . text($row['DOB']) . "</td>\n";
246 echo " <td>" . text($row['street'] . ' ' . $row['postal_code']) . "</td>\n";
255 if ($login_matches == 1) {
256 // There is exactly one match by portal login name, this must be it.
257 // There should not be more than one, but if there is then we will
258 // leave them onscreen and let the user choose.
259 echo "<script language='JavaScript'>\n";
260 echo "openPatient('" . addslashes($login_pid) . "');\n";
266 <input type
='button' value
='<?php echo xla('Add
New Patient
'); ?>' onclick
="openPatient(0)" />
268 <input type
='button' value
='<?php echo xla('Back
'); ?>' onclick
="myRestoreSession();location='list_requests.php'" />