Internationalization: Translation Tables Update.
[openemr.git] / contrib / util / dupecheck / index.php
blob34042f0dd518bf0a024bd461a08192582c5b854e
1 <?php
2 require_once("../../../interface/globals.php");
3 require_once("./Utils.php");
5 /* Use this code to identify duplicate patients in OpenEMR
7 */
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'];
26 <html>
27 <head>
28 <script type="text/javascript" src="<?php echo $GLOBALS['webroot']; ?>/library/js/jquery.js"></script>
29 <style>
30 body {
31 font-family: arial, helvetica, times new roman;
32 font-size: 1em;
33 background-color: #eee;
35 .match_block {
36 border: 1px solid #eee;
37 background-color: white;
38 padding: 5px;
41 .match_block table {
42 border-collapse: collapse;
44 .match_block table tr {
45 cursor: pointer;
47 .match_block table td {
48 padding: 5px;
51 .highlight {
52 background-color: #99a;
53 color: white;
55 .highlight_block {
56 background-color: #ffa;
58 .bold {
59 font-weight: bold;
62 </style>
63 </head>
64 <body>
65 <form name="search_form" id="search_form" method="post" action="index.php">
66 <input type="hidden" name="go" value="Go">
67 Matching criteria:
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>
76 <br>
77 Order results by:
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>
86 <br>
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">
89 </form>
91 <div id="thebiglist" style="height: 300px; overflow: auto; border: 1px solid blue;">
92 <form name="resolve" id="resolve" method="POST" action="dupcheck.php">
94 <?php
95 if ($parameters['go'] == "Go") {
96 // go and do the search
98 // counter that gathers duplicates into groups
99 $dupecount = 0;
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']) {
104 case 'dob':
105 $orderby = " ORDER BY dob";
106 break;
107 case 'sex':
108 $orderby = " ORDER BY sex";
109 break;
110 case 'ssn':
111 $orderby = " ORDER BY ss";
112 break;
113 case 'name':
114 default:
115 $orderby = " ORDER BY lname, fname";
116 break;
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 ";
130 $sqland = "";
131 if ($parameters['match_name']) {
132 $sqlstmt .= $sqland . " fname='".$row['fname']."'";
133 $sqland = " AND ";
134 $sqlstmt .= $sqland . " lname='".$row['lname']."'";
136 if ($parameters['match_sex']) {
137 $sqlstmt .= $sqland . " sex='".$row['sex']."'";
138 $sqland = " AND ";
140 if ($parameters['match_ssn']) {
141 $sqlstmt .= $sqland . " ss='".$row['ss']."'";
142 $sqland = " AND ";
144 if ($parameters['match_dob']) {
145 $sqlstmt .= $sqland . " dob='".$row['dob']."'";
146 $sqland = " AND ";
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."'>";
155 echo "<table>";
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>";
163 echo "</tr>";
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>";
173 echo "</tr>";
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;
178 $dupecount++;
180 echo "</table>";
181 echo "</div>\n";
186 </div> <!-- end the big list -->
187 <?php if ($dupecount > 0) : ?>
188 <div id="dupecounter" style='display:inline;'><?php echo $dupecount; ?></div>
189 &nbsp;duplicates found
190 <?php endif; ?>
191 </form>
193 </body>
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();
206 return true;
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);
244 </script>
246 </html>