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'])) {
12 $parameters['sortby'] = "name";
15 if (! isset($parameters['limit'])) {
16 $parameters['limit'] = 100;
19 if (! isset($parameters['match_name']) &&
20 ! isset($parameters['match_dob']) &&
21 ! isset($parameters['match_sex']) &&
22 ! isset($parameters['match_ssn'])) {
23 $parameters['match_name'] = 'on';
24 $parameters['match_dob'] = 'on';
27 $oemrdb = $GLOBALS['dbh'];
32 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script
>
35 font
-family
: arial
, helvetica
, times
new roman
;
37 background
-color
: #eee;
40 border
: 1px solid
#eee;
41 background
-color
: white
;
46 border
-collapse
: collapse
;
48 .match_block table tr
{
51 .match_block table td
{
56 background
-color
: #99a;
60 background
-color
: #ffa;
69 <form name
="search_form" id
="search_form" method
="post" action
="index.php">
70 <input type
="hidden" name
="go" value
="Go">
72 <input type
="checkbox" name
="match_name" id
="match_name" <?php
if ($parameters['match_name']) {
75 <label
for="match_name">Name
</label
>
76 <input type
="checkbox" name
="match_dob" id
="match_dob" <?php
if ($parameters['match_dob']) {
79 <label
for="match_dob">DOB
</label
>
80 <input type
="checkbox" name
="match_sex" id
="match_sex" <?php
if ($parameters['match_sex']) {
83 <label
for="match_sex">Gender
</label
>
84 <input type
="checkbox" name
="match_ssn" id
="match_ssn" <?php
if ($parameters['match_ssn']) {
87 <label
for="match_ssn">SSN
</label
>
90 <input type
='radio' name
='sortby' value
='name' id
="name" <?php
if ($parameters['sortby']=='name') {
93 <label
for="name">Name
</label
>
94 <input type
='radio' name
='sortby' value
='dob' id
="dob" <?php
if ($parameters['sortby']=='dob') {
97 <label
for="dob">DOB
</label
>
98 <input type
='radio' name
='sortby' value
='sex' id
="sex" <?php
if ($parameters['sortby']=='sex') {
101 <label
for="sex">Gender
</label
>
102 <input type
='radio' name
='sortby' value
='ssn' id
="ssn" <?php
if ($parameters['sortby']=='ssn') {
105 <label
for="ssn">SSN
</label
>
107 Limit search to first
<input type
='textbox' size
='5' name
='limit' id
="limit" value
='<?php echo $parameters['limit
']; ?>'> records
108 <input type
="button" name
="do_search" id
="do_search" value
="Go">
111 <div id
="thebiglist" style
="height: 300px; overflow: auto; border: 1px solid blue;">
112 <form name
="resolve" id
="resolve" method
="POST" action
="dupcheck.php">
115 if ($parameters['go'] == "Go") {
116 // go and do the search
118 // counter that gathers duplicates into groups
121 // for EACH patient in OpenEMR find potential matches
122 $sqlstmt = "select id, pid, fname, lname, dob, sex, ss from patient_data";
123 switch ($parameters['sortby']) {
125 $orderby = " ORDER BY dob";
128 $orderby = " ORDER BY sex";
131 $orderby = " ORDER BY ss";
135 $orderby = " ORDER BY lname, fname";
139 $sqlstmt .= $orderby;
140 if ($parameters['limit']) {
141 $sqlstmt .= " LIMIT 0,".$parameters['limit'];
144 $qResults = sqlStatement($sqlstmt);
145 while ($row = sqlFetchArray($qResults)) {
146 if ($dupelist[$row['id']] == 1) {
150 $sqlstmt = "select id, pid, fname, lname, dob, sex, ss ".
151 " from patient_data where ";
153 if ($parameters['match_name']) {
154 $sqlstmt .= $sqland . " fname='".$row['fname']."'";
156 $sqlstmt .= $sqland . " lname='".$row['lname']."'";
159 if ($parameters['match_sex']) {
160 $sqlstmt .= $sqland . " sex='".$row['sex']."'";
164 if ($parameters['match_ssn']) {
165 $sqlstmt .= $sqland . " ss='".$row['ss']."'";
169 if ($parameters['match_dob']) {
170 $sqlstmt .= $sqland . " dob='".$row['dob']."'";
174 $mResults = sqlStatement($sqlstmt);
180 if (sqlNumRows($mResults) <= 1) {
185 echo "<div class='match_block' style='padding: 5px 0px 5px 0px;' id='dupediv".$dupecount."'>";
188 echo "<tr class='onerow' id='".$row['id']."' oemrid='".$row['id']."' dupecount='".$dupecount."' title='Merge duplicates into this record'>";
189 echo "<td>".$row['lname'].", ".$row['fname']."</td>";
190 echo "<td>".$row['dob']."</td>";
191 echo "<td>".$row['sex']."</td>";
192 echo "<td>".$row['ss']."</td>";
193 echo "<td><input type='button' value=' ? ' class='moreinfo' oemrid='".$row['pid']."' title='More info'></td>";
196 while ($mrow = sqlFetchArray($mResults)) {
197 if ($row['id'] == $mrow['id']) {
201 echo "<tr class='onerow' id='".$mrow['id']."' oemrid='".$mrow['id']."' dupecount='".$dupecount."' title='Merge duplicates into this record'>";
202 echo "<td>".$mrow['lname'].", ".$mrow['fname']."</td>";
203 echo "<td>".$mrow['dob']."</td>";
204 echo "<td>".$mrow['sex']."</td>";
205 echo "<td>".$mrow['ss']."</td>";
206 echo "<td><input type='button' value=' ? ' class='moreinfo' oemrid='".$mrow['pid']."' title='More info'></td>";
208 // to keep the output clean let's not repeat IDs already tagged as dupes
209 $dupelist[$row['id']] = 1;
210 $dupelist[$mrow['id']] = 1;
221 </div
> <!-- end the big
list -->
222 <?php
if ($dupecount > 0) : ?
>
223 <div id
="dupecounter" style
='display:inline;'><?php
echo $dupecount; ?
></div
>
224  
;duplicates found
230 <script language
="javascript">
232 $
(document
).ready(function(){
234 // capture RETURN keypress
235 $
("#limit").keypress(function(evt
) { if (evt
.keyCode
== 13) $
("#do_search").click(); });
237 // perform the database search for duplicates
238 $
("#do_search").click(function() {
239 $
("#thebiglist").html("<p style='margin:10px;'><img src='<?php echo $GLOBALS['webroot']; ?>/interface/pic/ajax-loader.gif'> Searching ...</p>");
240 $
("#search_form").submit();
244 // pop up an OpenEMR window directly to the patient info
245 var moreinfoWin
= null;
246 $
(".moreinfo").click(function(evt
) {
247 if (moreinfoWin
) { moreinfoWin
.close(); }
248 moreinfoWin
= window
.open("<?php echo $GLOBALS['webroot']; ?>/interface/patient_file/patient_file.php?set_pid="+$
(this
).attr("oemrid"), "moreinfo");
249 evt
.stopPropagation();
252 // highlight the block of matching records
253 $
(".match_block").mouseover(function() { $
(this
).toggleClass("highlight_block"); });
254 $
(".match_block").mouseout(function() { $
(this
).toggleClass("highlight_block"); });
255 $
(".onerow").mouseover(function() { $
(this
).toggleClass("highlight"); });
256 $
(".onerow").mouseout(function() { $
(this
).toggleClass("highlight"); });
258 // begin the merge of a block into a single record
259 $
(".onerow").click(function() {
260 var dupecount
= $
(this
).attr("dupecount");
261 var masterid
= $
(this
).attr("oemrid");
262 var newurl
= "mergerecords.php?dupecount="+dupecount+
"&masterid="+masterid
;
263 $
("[dupecount="+dupecount+
"]").each(function (i
) {
264 if (this
.id
!= masterid
) { newurl +
= "&otherid[]="+this
.id
; }
266 // open a new window and show the merge results
267 moreinfoWin
= window
.open(newurl
, "mergewin");
271 function removedupe(dupeid
) {
272 // remove the merged records from the list of duplicates
273 $
("#dupediv"+dupeid
).remove();
274 // reduce the duplicate counter
275 var dcounter
= parseInt($
("#dupecounter").html());
276 $
("#dupecounter").html(dcounter
-1);