4 * Patient matching and selection dialog.
7 * @link https://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2013-2015 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
12 * @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.php");
17 require_once("$srcdir/options.inc.php");
19 use OpenEMR\Common\Csrf\CsrfUtils
;
20 use OpenEMR\Core\Header
;
22 $form_key = $_REQUEST['key'];
23 $args = unserialize($form_key, ['allowed_classes' => false]);
24 $form_ss = preg_replace('/[^0-9]/', '', $args['ss']);
25 $form_fname = $args['fname'];
26 $form_lname = $args['lname'];
27 $form_DOB = $args['DOB'];
32 <?php Header
::setupHeader(['opener']); ?
>
40 $
(".oneresult").mouseover(function () {
41 $
(this
).addClass("highlight");
43 $
(".oneresult").mouseout(function () {
44 $
(this
).removeClass("highlight");
48 function myRestoreSession() {
49 if (top
.restoreSession
) top
.restoreSession(); else opener
.top
.restoreSession();
53 function openPatient(ptid
) {
54 var f
= opener
.document
.forms
[0];
55 var ename
= <?php
echo js_escape("select[$form_key]"); ?
>;
57 f
[ename
].value
= ptid
;
61 alert(<?php
echo xlj('Form element not found'); ?
> +
': ' + ename
);
68 <body
class="body_top">
69 <form method
='post' action
='patient_select.php' onsubmit
='return myRestoreSession()'>
70 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
76 if ($form_fname !== '') {
77 $clsql .= " + ((fname IS NOT NULL AND fname = ?) * 5)";
78 $clarr[] = $form_fname;
82 if ($form_lname !== '') {
83 $clsql .= " + ((lname IS NOT NULL AND lname = ?) * 5)";
84 $clarr[] = $form_lname;
88 if ($form_DOB !== '') {
89 $clsql .= " + ((DOB IS NOT NULL AND DOB = ?) * 5)";
93 // SSN match is worth a lot and we allow for matching on last 4 digits.
94 if (strlen($form_ss) > 3) {
95 $clsql .= " + ((ss IS NOT NULL AND ss LIKE ?) * 10)";
96 $clarr[] = "%$form_ss";
99 $sql = "SELECT $clsql AS closeness, " .
100 "pid, pubpid, fname, lname, mname, DOB, ss, postal_code, street, " .
101 "phone_biz, phone_home, phone_cell, phone_contact, sex " .
102 "FROM patient_data " .
103 "ORDER BY closeness DESC, lname, fname LIMIT 10";
104 $res = sqlStatement($sql, $clarr);
107 <div id
="searchResults">
109 <table
class="table table-striped table-sm">
112 echo xlt('Matching for Patient') . ": " .
113 text("$form_lname, $form_fname") . text(" Dob = $form_DOB") .
114 " SS = " . text(($form_ss ?
$form_ss : "unk"))
118 <th
><?php
echo xlt('Name'); ?
></th
>
119 <th
><?php
echo xlt('DOB'); ?
></th
>
120 <th
><?php
echo xlt('Sex'); ?
></th
>
121 <th
><?php
echo xlt('Phone'); ?
></th
>
122 <th
><?php
echo xlt('SS'); ?
></th
>
123 <th
><?php
echo xlt('Address'); ?
></th
>
127 while ($row = sqlFetchArray($res)) {
128 if ($row['closeness'] == 0) {
132 $phone = $row['phone_biz'];
134 $phone = $row['phone_home'];
138 $phone = $row['phone_cell'];
142 $phone = $row['phone_contact'];
145 echo " <tr class='oneresult'";
146 echo " onclick=\"openPatient(" . attr_js($row['pid']) . ")\">\n";
147 echo " <td>" . text($row['lname'] . ", " . $row['fname']) . "</td>\n";
148 echo " <td>" . text($row['DOB']) . "</td>\n";
149 echo " <td>" . text(substr($row['sex'], 0, 1)) . "</td>\n";
150 echo " <td>" . text($phone) . "</td>\n";
151 echo " <td>" . text($row['ss']) . "</td>\n";
152 echo " <td>" . text($row['street'] . ' ' . $row['postal_code']) . "</td>\n";
163 <input type
='button' value
='<?php echo xla('Add
New Patient
'); ?>' onclick
="openPatient(0)"/>
164 <input type
='button' value
='<?php echo xla('Cancel
'); ?>' onclick
="window.close()"/>