Changes to support a results-only lab interface.
[openemr.git] / interface / orders / patient_match_dialog.php
blob38935de4fac7e950dd79114cb2cedc274100477c
1 <?php
2 /**
3 * Patient matching and selection dialog.
5 * Copyright (C) 2012-2014 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/formdata.inc.php");
28 require_once("$srcdir/options.inc.php");
30 $form_key1 = $_REQUEST['key1'];
31 $form_key2 = $_REQUEST['key2'];
32 $form_ss = preg_replace('/[^0-9]/', '', $_REQUEST['ss']);
33 $form_fname = $_REQUEST['fname'];
34 $form_lname = $_REQUEST['lname'];
35 $form_DOB = $_REQUEST['DOB'];
38 <html>
39 <head>
40 <?php html_header_show(); ?>
41 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
42 <style>
44 #searchResults {
45 width: 100%;
46 height: 80%;
47 overflow: auto;
49 #searchResults table {
50 width: 96%;
51 border-collapse: collapse;
52 background-color: white;
54 #searchResults th {
55 background-color: lightgrey;
56 font-size: 0.7em;
57 text-align: left;
59 #searchResults td {
60 font-size: 0.7em;
61 border-bottom: 1px solid #eee;
62 cursor: hand;
63 cursor: pointer;
66 .highlight {
67 background-color: #336699;
68 color: white;
71 .oneResult {}
73 </style>
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");});
81 });
83 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
85 function myRestoreSession() {
86 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
87 return true;
90 function openPatient(ptid) {
91 var f = opener.document.forms[0];
92 var ename = '<?php echo addslashes("select[$form_key1][$form_key2]"); ?>';
93 if (f[ename]) {
94 f[ename].value = ptid;
95 window.close();
97 else {
98 alert('<?php echo xls('Form element not found'); ?>: ' + ename);
102 </script>
103 </head>
105 <body class="body_top">
106 <center>
107 <form method='post' action='patient_select.php' onsubmit='return myRestoreSession()'>
109 <?php
110 if ($form_key1) {
111 $clarr = array();
112 $clsql = "0";
113 // First name.
114 if ($form_fname !== '') {
115 $clsql .= " + ((fname IS NOT NULL AND fname = ?) * 5)";
116 $clarr[] = $form_fname;
118 // Last name.
119 if ($form_lname !== '') {
120 $clsql .= " + ((lname IS NOT NULL AND lname = ?) * 5)";
121 $clarr[] = $form_lname;
123 // Birth date.
124 if ($form_DOB !== '') {
125 $clsql .= " + ((DOB IS NOT NULL AND DOB = ?) * 5)";
126 $clarr[] = $form_DOB;
128 // SSN match is worth a lot and we allow for matching on last 4 digits.
129 if (strlen($form_ss) > 3) {
130 $clsql .= " + ((ss IS NOT NULL AND ss LIKE ?) * 10)";
131 $clarr[] = "%$form_ss";
134 $sql = "SELECT $clsql AS closeness, " .
135 "pid, pubpid, fname, lname, mname, DOB, ss, postal_code, street, " .
136 "phone_biz, phone_home, phone_cell, phone_contact " .
137 "FROM patient_data " .
138 "ORDER BY closeness DESC, lname, fname LIMIT 10";
139 $res = sqlStatement($sql, $clarr);
142 <div id="searchResults">
143 <table>
144 <tr>
145 <th><?php echo xlt('Name' ); ?></th>
146 <th><?php echo xlt('Phone'); ?></th>
147 <th><?php echo xlt('SS' ); ?></th>
148 <th><?php echo xlt('DOB' ); ?></th>
149 <th><?php echo xlt('Address'); ?></th>
150 </tr>
151 <tr>
152 <th style='font-weight:normal'><?php echo text("$form_lname, $form_fname"); ?></th>
153 <th style='font-weight:normal'><?php echo '&nbsp;'; ?></th>
154 <th style='font-weight:normal'><?php echo text($form_ss); ?></th>
155 <th style='font-weight:normal'><?php echo text($form_DOB); ?></th>
156 <th style='font-weight:normal'><?php echo '&nbsp;'; ?></th>
157 </tr>
159 <?php
160 while ($row = sqlFetchArray($res)) {
161 if ($row['closeness'] == 0) continue;
163 $phone = $row['phone_biz'];
164 if (empty($phone)) $phone = $row['phone_home'];
165 if (empty($phone)) $phone = $row['phone_cell'];
166 if (empty($phone)) $phone = $row['phone_contact'];
168 echo " <tr class='oneresult'";
169 echo " onclick=\"openPatient(" .
170 "'" . addslashes($row['pid']) . "'" .
171 ")\">\n";
172 echo " <td>" . text($row['lname'] . ", " . $row['fname']) . "</td>\n";
173 echo " <td>" . text($phone ) . "</td>\n";
174 echo " <td>" . text($row['ss'] ) . "</td>\n";
175 echo " <td>" . text($row['DOB'] ) . "</td>\n";
176 echo " <td>" . text($row['street'] . ' ' . $row['postal_code']) . "</td>\n";
177 echo " </tr>\n";
180 </table>
181 </div>
182 <?php
187 <input type='button' value='<?php echo xla('Add New Patient'); ?>' onclick="openPatient(0)" />
188 &nbsp;
189 <input type='button' value='<?php echo xla('Cancel'); ?>' onclick="window.close()" />
190 </p>
192 </form>
193 </center>
194 </body>
195 </html>