bug fix march continued (#1921)
[openemr.git] / interface / orders / patient_match_dialog.php
blob8a41333dc9987f0d2b795fc9e114cb1d8e09b815
1 <?php
2 /**
3 * Patient matching and selection dialog.
5 * Copyright (C) 2012-2015 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Rod Roark <rod@sunsetsystems.com>
22 require_once("../globals.php");
23 require_once("$srcdir/patient.inc");
24 require_once("$srcdir/options.inc.php");
26 use OpenEMR\Core\Header;
28 $form_key = $_REQUEST['key'];
29 $args = unserialize($form_key);
30 $form_ss = preg_replace('/[^0-9]/', '', $args['ss']);
31 $form_fname = $args['fname'];
32 $form_lname = $args['lname'];
33 $form_DOB = $args['DOB'];
35 <!DOCTYPE html>
36 <html>
37 <head>
38 <?php Header::setupHeader(['opener']); ?>
39 <style>
40 .oneResult {
42 </style>
43 <script language="JavaScript">
45 $(document).ready(function () {
46 $(".oneresult").mouseover(function () {
47 $(this).addClass("highlight");
48 });
49 $(".oneresult").mouseout(function () {
50 $(this).removeClass("highlight");
51 });
52 });
54 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
56 function myRestoreSession() {
57 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
58 return true;
61 function openPatient(ptid) {
62 var f = opener.document.forms[0];
63 var ename = '<?php echo addslashes("select[$form_key]"); ?>';
64 if (f[ename]) {
65 f[ename].value = ptid;
66 window.close();
68 else {
69 alert('<?php echo xls('Form element not found'); ?>: ' + ename);
73 </script>
74 </head>
76 <body class="body_top">
77 <form method='post' action='patient_select.php' onsubmit='return myRestoreSession()'>
78 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
79 <?php
80 if ($form_key) {
81 $clarr = array();
82 $clsql = "0";
83 // First name.
84 if ($form_fname !== '') {
85 $clsql .= " + ((fname IS NOT NULL AND fname = ?) * 5)";
86 $clarr[] = $form_fname;
89 // Last name.
90 if ($form_lname !== '') {
91 $clsql .= " + ((lname IS NOT NULL AND lname = ?) * 5)";
92 $clarr[] = $form_lname;
95 // Birth date.
96 if ($form_DOB !== '') {
97 $clsql .= " + ((DOB IS NOT NULL AND DOB = ?) * 5)";
98 $clarr[] = $form_DOB;
101 // SSN match is worth a lot and we allow for matching on last 4 digits.
102 if (strlen($form_ss) > 3) {
103 $clsql .= " + ((ss IS NOT NULL AND ss LIKE ?) * 10)";
104 $clarr[] = "%$form_ss";
107 $sql = "SELECT $clsql AS closeness, " .
108 "pid, pubpid, fname, lname, mname, DOB, ss, postal_code, street, " .
109 "phone_biz, phone_home, phone_cell, phone_contact " .
110 "FROM patient_data " .
111 "ORDER BY closeness DESC, lname, fname LIMIT 10";
112 $res = sqlStatement($sql, $clarr);
115 <div id="searchResults">
117 <table class="table table-striped table-condensed">
118 <h5>
119 <?php
120 echo xlt('Matching for Patient') . ": " .
121 text("$form_lname, $form_fname") . text(" Dob = $form_DOB") .
122 " SS = " . text(($form_ss ? $form_ss : "unk"))
124 </h5>
125 <tr>
126 <th><?php echo xlt('Name'); ?></th>
127 <th><?php echo xlt('Phone'); ?></th>
128 <th><?php echo xlt('SS'); ?></th>
129 <th><?php echo xlt('DOB'); ?></th>
130 <th><?php echo xlt('Address'); ?></th>
131 </tr>
133 <?php
134 while ($row = sqlFetchArray($res)) {
135 if ($row['closeness'] == 0) {
136 continue;
139 $phone = $row['phone_biz'];
140 if (empty($phone)) {
141 $phone = $row['phone_home'];
144 if (empty($phone)) {
145 $phone = $row['phone_cell'];
148 if (empty($phone)) {
149 $phone = $row['phone_contact'];
152 echo " <tr class='oneresult'";
153 echo " onclick=\"openPatient(" .
154 "'" . addslashes($row['pid']) . "'" .
155 ")\">\n";
156 echo " <td>" . text($row['lname'] . ", " . $row['fname']) . "</td>\n";
157 echo " <td>" . text($phone) . "</td>\n";
158 echo " <td>" . text($row['ss']) . "</td>\n";
159 echo " <td>" . text($row['DOB']) . "</td>\n";
160 echo " <td>" . text($row['street'] . ' ' . $row['postal_code']) . "</td>\n";
161 echo " </tr>\n";
164 </table>
165 </div>
166 <?php
171 <input type='button' value='<?php echo xla('Add New Patient'); ?>' onclick="openPatient(0)"/>
172 <input type='button' value='<?php echo xla('Cancel'); ?>' onclick="window.close()"/>
173 </p>
175 </form>
176 </center>
177 </body>
178 </html>