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>
20 $sanitize_all_escapes = true;
21 $fake_register_globals = false;
23 require_once("../globals.php");
24 require_once("$srcdir/patient.inc");
25 require_once("$srcdir/formdata.inc.php");
26 require_once("$srcdir/options.inc.php");
27 require_once("portal.inc.php");
29 $postid = intval($_REQUEST['postid']);
32 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
33 if ($result['errmsg']) {
34 die(text($result['errmsg']));
40 <?php
html_header_show(); ?
>
41 <link rel
=stylesheet href
="<?php echo $css_header; ?>" type
="text/css">
49 #searchResults table {
51 border
-collapse
: collapse
;
52 background
-color
: white
;
55 background
-color
: lightgrey
;
61 border
-bottom
: 1px solid
#eee;
67 background
-color
: #336699;
75 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.2.2.min.js"></script
>
76 <script language
="JavaScript">
78 $
(document
).ready(function(){
79 $
(".oneresult").mouseover(function() {$
(this
).addClass("highlight");});
80 $
(".oneresult").mouseout(function() {$
(this
).removeClass("highlight");});
83 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
85 function myRestoreSession() {
86 if (top
.restoreSession
) top
.restoreSession(); else opener
.top
.restoreSession();
90 function openPatient(ptid
) {
91 // This works whether we are a popup or in the OpenEMR frameset.
93 document
.location
.href
= 'patient_form.php?postid=<?php echo xls($postid); ?>&ptid=' + ptid
;
99 <body
class="body_top">
101 <form method
='post' action
='patient_select.php' onsubmit
='return myRestoreSession()'>
104 // print_r($result); // debugging
111 $cmsportal_login = trim($result['post']['user']);
112 if ($cmsportal_login !== '') {
113 $clsql .= " + ((cmsportal_login IS NOT NULL AND cmsportal_login = ?) * 100)";
114 $clarr[] = $cmsportal_login;
117 $fname = trim($result['fields']['fname']);
119 $clsql .= " + ((fname IS NOT NULL AND fname = ?) * 5)";
123 $lname = trim($result['fields']['lname']);
125 $clsql .= " + ((lname IS NOT NULL AND lname = ?) * 5)";
129 $dob = fixDate(trim($result['fields']['dob']), '');
131 $clsql .= " + ((DOB IS NOT NULL AND DOB = ?) * 5)";
134 // SSN match is worth a lot and we allow for matching on last 4 digits.
135 $ssn = preg_replace('/[^0-9]/', '', $result['fields']['ss']);
136 if (strlen($ssn) > 3) {
137 $clsql .= " + ((ss IS NOT NULL AND ss LIKE ?) * 10)";
140 // Zip code makes it unnecessary to match on city and state.
141 $zip = preg_replace('/[^0-9]/', '', $result['fields']['postal_code']);
142 $zip = substr($zip, 0, 5);
143 if (strlen($zip) == 5) {
144 $clsql .= " + ((postal_code IS NOT NULL AND postal_code LIKE ?) * 2)";
147 // This generates a REGEXP query that matches the first 2 words of the street address.
148 if (preg_match('/^\W*(\w+)\W+(\w+)/', $result['fields']['street'], $matches)) {
149 $clsql .= " + ((street IS NOT NULL AND street REGEXP '^[^[:alnum:]]*";
150 $clsql .= $matches[1];
151 $clsql .= "[^[:alnum:]]+";
152 $clsql .= $matches[2];
153 $clsql .= "[[:>:]]') * 2)";
156 $sql = "SELECT $clsql AS closeness, " .
157 "pid, cmsportal_login, fname, lname, mname, DOB, ss, postal_code, " .
158 "street, phone_biz, phone_home, phone_cell, phone_contact " .
159 "FROM patient_data " .
160 "ORDER BY closeness DESC, lname, fname LIMIT 10";
161 $res = sqlStatement($sql, $clarr);
163 // echo "<!-- $sql -->\n"; // debugging
165 $phone = $result['fields']['phone_biz'];
166 if (empty($phone)) $phone = $result['fields']['phone_home'];
167 if (empty($phone)) $phone = $result['fields']['phone_cell'];
168 if (empty($phone)) $phone = $result['fields']['phone_contact'];
171 <div id
="searchResults">
174 <th
><?php
echo xlt('Portal ID'); ?
></th
>
175 <th
><?php
echo xlt('Name' ); ?
></th
>
176 <th
><?php
echo xlt('Phone' ); ?
></th
>
177 <th
><?php
echo xlt('SS' ); ?
></th
>
178 <th
><?php
echo xlt('DOB' ); ?
></th
>
179 <th
><?php
echo xlt('Address' ); ?
></th
>
182 <th style
='font-weight:normal'><?php
echo text($result['post']['user']); ?
></th
>
183 <th style
='font-weight:normal'><?php
echo text("$lname, $fname"); ?
></th
>
184 <th style
='font-weight:normal'><?php
echo text($phone); ?
></th
>
185 <th style
='font-weight:normal'><?php
echo text($ssn ); ?
></th
>
186 <th style
='font-weight:normal'><?php
echo text($dob ); ?
></th
>
187 <th style
='font-weight:normal'><?php
echo text($result['fields']['street'] . ' ' . $zip); ?
></th
>
191 while ($row = sqlFetchArray($res)) {
192 if ($row['closeness'] == 0) continue;
193 if ($row['closeness'] >= 100) {
195 $login_pid = $row['pid'];
198 // We have a match on login name but this is not one, so ignore it.
199 if ($login_matches) continue;
201 $phone = $row['phone_biz'];
202 if (empty($phone)) $phone = $row['phone_home'];
203 if (empty($phone)) $phone = $row['phone_cell'];
204 if (empty($phone)) $phone = $row['phone_contact'];
206 echo " <tr class='oneresult'";
207 echo " onclick=\"openPatient(" .
208 "'" . addslashes($row['pid']) . "'" .
211 if ($row['cmsportal_login'] !== '' && $result['post']['user'] !== $row['cmsportal_login']) {
212 echo " style='color:red' title='" . xla('Portal ID does not match request from portal!') . "'";
214 echo ">" . text($row['cmsportal_login']) . "</td>\n";
215 echo " <td>" . text($row['lname'] . ", " . $row['fname'] ) . "</td>\n";
216 echo " <td>" . text($phone ) . "</td>\n";
217 echo " <td>" . text($row['ss'] ) . "</td>\n";
218 echo " <td>" . text($row['DOB'] ) . "</td>\n";
219 echo " <td>" . text($row['street'] . ' ' . $row['postal_code']) . "</td>\n";
227 if ($login_matches == 1) {
228 // There is exactly one match by portal login name, this must be it.
229 // There should not be more than one, but if there is then we will
230 // leave them onscreen and let the user choose.
231 echo "<script language='JavaScript'>\n";
232 echo "openPatient('" . addslashes($login_pid) . "');\n";
238 <input type
='button' value
='<?php echo xla('Add
New Patient
'); ?>' onclick
="openPatient(0)" />
240 <input type
='button' value
='<?php echo xla('Back
'); ?>' onclick
="myRestoreSession();location='list_requests.php'" />