2 require_once("../../../interface/globals.php");
3 require_once("./Utils.php");
5 /* Use this code to identify duplicate patients in OpenEMR
8 $parameters = GetParameters();
10 // establish some defaults
11 if (! isset($parameters['sortby'])) { $parameters['sortby'] == "name"; }
12 if (! isset($parameters['limit'])) { $parameters['limit'] = 100; }
14 if (! isset($parameters['match_name']) &&
15 ! isset($parameters['match_dob']) &&
16 ! isset($parameters['match_sex']) &&
17 ! isset($parameters['match_ssn']))
19 $parameters['match_name'] = 'on';
20 $parameters['match_dob'] = 'on';
23 $oemrdb = $GLOBALS['dbh'];
28 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot']; ?>/library/js/jquery.js"></script
>
31 font
-family
: arial
, helvetica
, times
new roman
;
33 background
-color
: #eee;
36 border
: 1px solid
#eee;
37 background
-color
: white
;
42 border
-collapse
: collapse
;
44 .match_block table tr
{
47 .match_block table td
{
52 background
-color
: #99a;
56 background
-color
: #ffa;
65 <form name
="search_form" id
="search_form" method
="post" action
="index.php">
66 <input type
="hidden" name
="go" value
="Go">
68 <input type
="checkbox" name
="match_name" id
="match_name" <?php
if ($parameters['match_name']) echo "CHECKED"; ?
>>
69 <label
for="match_name">Name
</label
>
70 <input type
="checkbox" name
="match_dob" id
="match_dob" <?php
if ($parameters['match_dob']) echo "CHECKED"; ?
>>
71 <label
for="match_dob">DOB
</label
>
72 <input type
="checkbox" name
="match_sex" id
="match_sex" <?php
if ($parameters['match_sex']) echo "CHECKED"; ?
>>
73 <label
for="match_sex">Gender
</label
>
74 <input type
="checkbox" name
="match_ssn" id
="match_ssn" <?php
if ($parameters['match_ssn']) echo "CHECKED"; ?
>>
75 <label
for="match_ssn">SSN
</label
>
78 <input type
='radio' name
='sortby' value
='name' id
="name" <?php
if ($parameters['sortby']=='name') echo "CHECKED"; ?
>>
79 <label
for="name">Name
</label
>
80 <input type
='radio' name
='sortby' value
='dob' id
="dob" <?php
if ($parameters['sortby']=='dob') echo "CHECKED"; ?
>>
81 <label
for="dob">DOB
</label
>
82 <input type
='radio' name
='sortby' value
='sex' id
="sex" <?php
if ($parameters['sortby']=='sex') echo "CHECKED"; ?
>>
83 <label
for="sex">Gender
</label
>
84 <input type
='radio' name
='sortby' value
='ssn' id
="ssn" <?php
if ($parameters['sortby']=='ssn') echo "CHECKED"; ?
>>
85 <label
for="ssn">SSN
</label
>
87 Limit search to first
<input type
='textbox' size
='5' name
='limit' id
="limit" value
='<?php echo $parameters['limit
']; ?>'> records
88 <input type
="button" name
="do_search" id
="do_search" value
="Go">
91 <div id
="thebiglist" style
="height: 300px; overflow: auto; border: 1px solid blue;">
92 <form name
="resolve" id
="resolve" method
="POST" action
="dupcheck.php">
95 if ($parameters['go'] == "Go") {
96 // go and do the search
98 // counter that gathers duplicates into groups
101 // for EACH patient in OpenEMR find potential matches
102 $sqlstmt = "select id, pid, fname, lname, dob, sex, ss from patient_data";
103 switch ($parameters['sortby']) {
105 $orderby = " ORDER BY dob";
108 $orderby = " ORDER BY sex";
111 $orderby = " ORDER BY ss";
115 $orderby = " ORDER BY lname, fname";
118 $sqlstmt .= $orderby;
119 if ($parameters['limit']) {
120 $sqlstmt .= " LIMIT 0,".$parameters['limit'];
123 $qResults = mysql_query($sqlstmt, $oemrdb);
124 while ($row = mysql_fetch_assoc($qResults)) {
126 if ($dupelist[$row['id']] == 1) continue;
128 $sqlstmt = "select id, pid, fname, lname, dob, sex, ss ".
129 " from patient_data where ";
131 if ($parameters['match_name']) {
132 $sqlstmt .= $sqland . " fname='".$row['fname']."'";
134 $sqlstmt .= $sqland . " lname='".$row['lname']."'";
136 if ($parameters['match_sex']) {
137 $sqlstmt .= $sqland . " sex='".$row['sex']."'";
140 if ($parameters['match_ssn']) {
141 $sqlstmt .= $sqland . " ss='".$row['ss']."'";
144 if ($parameters['match_dob']) {
145 $sqlstmt .= $sqland . " dob='".$row['dob']."'";
148 $mResults = mysql_query($sqlstmt, $oemrdb);
150 if (! $mResults) continue;
151 if (mysql_num_rows($mResults) <= 1) continue;
154 echo "<div class='match_block' style='padding: 5px 0px 5px 0px;' id='dupediv".$dupecount."'>";
157 echo "<tr class='onerow' id='".$row['id']."' oemrid='".$row['id']."' dupecount='".$dupecount."' title='Merge duplicates into this record'>";
158 echo "<td>".$row['lname'].", ".$row['fname']."</td>";
159 echo "<td>".$row['dob']."</td>";
160 echo "<td>".$row['sex']."</td>";
161 echo "<td>".$row['ss']."</td>";
162 echo "<td><input type='button' value=' ? ' class='moreinfo' oemrid='".$row['pid']."' title='More info'></td>";
165 while ($mrow = mysql_fetch_assoc($mResults)) {
166 if ($row['id'] == $mrow['id']) continue;
167 echo "<tr class='onerow' id='".$mrow['id']."' oemrid='".$mrow['id']."' dupecount='".$dupecount."' title='Merge duplicates into this record'>";
168 echo "<td>".$mrow['lname'].", ".$mrow['fname']."</td>";
169 echo "<td>".$mrow['dob']."</td>";
170 echo "<td>".$mrow['sex']."</td>";
171 echo "<td>".$mrow['ss']."</td>";
172 echo "<td><input type='button' value=' ? ' class='moreinfo' oemrid='".$mrow['pid']."' title='More info'></td>";
174 // to keep the output clean let's not repeat IDs already tagged as dupes
175 $dupelist[$row['id']] = 1;
176 $dupelist[$mrow['id']] = 1;
186 </div
> <!-- end the big
list -->
187 <?php
if ($dupecount > 0) : ?
>
188 <div id
="dupecounter" style
='display:inline;'><?php
echo $dupecount; ?
></div
>
189  
;duplicates found
195 <script language
="javascript">
197 $
(document
).ready(function(){
199 // capture RETURN keypress
200 $
("#limit").keypress(function(evt
) { if (evt
.keyCode
== 13) $
("#do_search").click(); });
202 // perform the database search for duplicates
203 $
("#do_search").click(function() {
204 $
("#thebiglist").html("<p style='margin:10px;'><img src='<?php echo $GLOBALS['webroot']; ?>/interface/pic/ajax-loader.gif'> Searching ...</p>");
205 $
("#search_form").submit();
209 // pop up an OpenEMR window directly to the patient info
210 var moreinfoWin
= null;
211 $
(".moreinfo").click(function(evt
) {
212 if (moreinfoWin
) { moreinfoWin
.close(); }
213 moreinfoWin
= window
.open("<?php echo $GLOBALS['webroot']; ?>/interface/patient_file/patient_file.php?set_pid="+$
(this
).attr("oemrid"), "moreinfo");
214 evt
.stopPropagation();
217 // highlight the block of matching records
218 $
(".match_block").mouseover(function() { $
(this
).toggleClass("highlight_block"); });
219 $
(".match_block").mouseout(function() { $
(this
).toggleClass("highlight_block"); });
220 $
(".onerow").mouseover(function() { $
(this
).toggleClass("highlight"); });
221 $
(".onerow").mouseout(function() { $
(this
).toggleClass("highlight"); });
223 // begin the merge of a block into a single record
224 $
(".onerow").click(function() {
225 var dupecount
= $
(this
).attr("dupecount");
226 var masterid
= $
(this
).attr("oemrid");
227 var newurl
= "mergerecords.php?dupecount="+dupecount+
"&masterid="+masterid
;
228 $
("[dupecount="+dupecount+
"]").each(function (i
) {
229 if (this
.id
!= masterid
) { newurl +
= "&otherid[]="+this
.id
; }
231 // open a new window and show the merge results
232 moreinfoWin
= window
.open(newurl
, "mergewin");
236 function removedupe(dupeid
) {
237 // remove the merged records from the list of duplicates
238 $
("#dupediv"+dupeid
).remove();
239 // reduce the duplicate counter
240 var dcounter
= parseInt($
("#dupecounter").html());
241 $
("#dupecounter").html(dcounter
-1);