ongoing new datepicker project
[openemr.git] / interface / orders / patient_match_dialog.php
blob71e5735a7eb347ac4f7265b184a130a4bca0768e
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 $sanitize_all_escapes = true;
23 $fake_register_globals = false;
25 require_once("../globals.php");
26 require_once("$srcdir/patient.inc");
27 require_once("$srcdir/options.inc.php");
29 $form_key = $_REQUEST['key'];
30 $args = unserialize($form_key);
31 $form_ss = preg_replace('/[^0-9]/', '', $args['ss']);
32 $form_fname = $args['fname'];
33 $form_lname = $args['lname'];
34 $form_DOB = $args['DOB'];
36 <html>
37 <head>
38 <?php html_header_show(); ?>
39 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
40 <style>
42 #searchResults {
43 width: 100%;
44 height: 80%;
45 overflow: auto;
47 #searchResults table {
48 width: 96%;
49 border-collapse: collapse;
50 background-color: white;
52 #searchResults th {
53 background-color: lightgrey;
54 font-size: 0.7em;
55 text-align: left;
57 #searchResults td {
58 font-size: 0.7em;
59 border-bottom: 1px solid #eee;
60 cursor: hand;
61 cursor: pointer;
64 .highlight {
65 background-color: #336699;
66 color: white;
69 .oneResult {}
71 </style>
73 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script>
74 <script language="JavaScript">
76 $(document).ready(function(){
77 $(".oneresult").mouseover(function() {$(this).addClass("highlight");});
78 $(".oneresult").mouseout(function() {$(this).removeClass("highlight");});
79 });
81 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
83 function myRestoreSession() {
84 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
85 return true;
88 function openPatient(ptid) {
89 var f = opener.document.forms[0];
90 var ename = '<?php echo addslashes("select[$form_key]"); ?>';
91 if (f[ename]) {
92 f[ename].value = ptid;
93 window.close();
95 else {
96 alert('<?php echo xls('Form element not found'); ?>: ' + ename);
100 </script>
101 </head>
103 <body class="body_top">
104 <center>
105 <form method='post' action='patient_select.php' onsubmit='return myRestoreSession()'>
107 <?php
108 if ($form_key) {
109 $clarr = array();
110 $clsql = "0";
111 // First name.
112 if ($form_fname !== '') {
113 $clsql .= " + ((fname IS NOT NULL AND fname = ?) * 5)";
114 $clarr[] = $form_fname;
116 // Last name.
117 if ($form_lname !== '') {
118 $clsql .= " + ((lname IS NOT NULL AND lname = ?) * 5)";
119 $clarr[] = $form_lname;
121 // Birth date.
122 if ($form_DOB !== '') {
123 $clsql .= " + ((DOB IS NOT NULL AND DOB = ?) * 5)";
124 $clarr[] = $form_DOB;
126 // SSN match is worth a lot and we allow for matching on last 4 digits.
127 if (strlen($form_ss) > 3) {
128 $clsql .= " + ((ss IS NOT NULL AND ss LIKE ?) * 10)";
129 $clarr[] = "%$form_ss";
132 $sql = "SELECT $clsql AS closeness, " .
133 "pid, pubpid, fname, lname, mname, DOB, ss, postal_code, street, " .
134 "phone_biz, phone_home, phone_cell, phone_contact " .
135 "FROM patient_data " .
136 "ORDER BY closeness DESC, lname, fname LIMIT 10";
137 $res = sqlStatement($sql, $clarr);
140 <div id="searchResults">
141 <table>
142 <tr>
143 <th><?php echo xlt('Name' ); ?></th>
144 <th><?php echo xlt('Phone'); ?></th>
145 <th><?php echo xlt('SS' ); ?></th>
146 <th><?php echo xlt('DOB' ); ?></th>
147 <th><?php echo xlt('Address'); ?></th>
148 </tr>
149 <tr>
150 <th style='font-weight:normal'><?php echo text("$form_lname, $form_fname"); ?></th>
151 <th style='font-weight:normal'><?php echo '&nbsp;'; ?></th>
152 <th style='font-weight:normal'><?php echo text($form_ss); ?></th>
153 <th style='font-weight:normal'><?php echo text($form_DOB); ?></th>
154 <th style='font-weight:normal'><?php echo '&nbsp;'; ?></th>
155 </tr>
157 <?php
158 while ($row = sqlFetchArray($res)) {
159 if ($row['closeness'] == 0) continue;
161 $phone = $row['phone_biz'];
162 if (empty($phone)) $phone = $row['phone_home'];
163 if (empty($phone)) $phone = $row['phone_cell'];
164 if (empty($phone)) $phone = $row['phone_contact'];
166 echo " <tr class='oneresult'";
167 echo " onclick=\"openPatient(" .
168 "'" . addslashes($row['pid']) . "'" .
169 ")\">\n";
170 echo " <td>" . text($row['lname'] . ", " . $row['fname']) . "</td>\n";
171 echo " <td>" . text($phone ) . "</td>\n";
172 echo " <td>" . text($row['ss'] ) . "</td>\n";
173 echo " <td>" . text($row['DOB'] ) . "</td>\n";
174 echo " <td>" . text($row['street'] . ' ' . $row['postal_code']) . "</td>\n";
175 echo " </tr>\n";
178 </table>
179 </div>
180 <?php
185 <input type='button' value='<?php echo xla('Add New Patient'); ?>' onclick="openPatient(0)" />
186 &nbsp;
187 <input type='button' value='<?php echo xla('Cancel'); ?>' onclick="window.close()" />
188 </p>
190 </form>
191 </center>
192 </body>
193 </html>