Implemented duplicate patients management. (#4502)
[openemr.git] / library / dupscore.inc.php
blob6abd821e755b1b15658d5e17f49eefc616d6315b
1 <?php
3 /**
4 * Note this may be included by CLI scripts, so don't do anything web-specific here!
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @copyright Copyright (c) 2021 Rod Roark <rod@sunsetsystems.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 // The SQL returned by this function is an expression that computes the duplication
14 // score between two patient_data table rows p1 and p2.
16 function getDupScoreSQL()
18 return
19 // 5 First name
20 "5 * (SOUNDEX(p1.fname) = SOUNDEX(p2.fname)) + " .
21 // 3 Last name
22 "3 * (SOUNDEX(p1.lname) = SOUNDEX(p2.lname)) + " .
23 // 4 Any phone number
24 "4 * (" .
25 "(TRIM(p1.phone_home) != '' AND ( " .
26 "REPLACE(REPLACE(p1.phone_home, '-', ''), ' ', '') IN ( " .
27 "REPLACE(REPLACE(p2.phone_home, '-', ''), ' ', ''), " .
28 "REPLACE(REPLACE(p2.phone_biz , '-', ''), ' ', ''), " .
29 "REPLACE(REPLACE(p2.phone_cell, '-', ''), ' ', '')))) " .
30 "OR (TRIM(p1.phone_biz) != '' AND ( " .
31 "REPLACE(REPLACE(p1.phone_biz , '-', ''), ' ', '') IN ( " .
32 "REPLACE(REPLACE(p2.phone_biz , '-', ''), ' ', ''), " .
33 "REPLACE(REPLACE(p2.phone_cell, '-', ''), ' ', '')))) " .
34 "OR (TRIM(p1.phone_cell) != '' AND ( " .
35 "REPLACE(REPLACE(p1.phone_cell, '-', ''), ' ', '') = " .
36 "REPLACE(REPLACE(p2.phone_cell, '-', ''), ' ', ''))) " .
37 ") + " .
38 // 6 Birth date
39 "6 * (p1.DOB IS NOT NULL AND p2.DOB IS NOT NULL AND p1.DOB = p2.DOB) + " .
40 // 7 Email
41 "7 * (TRIM(p1.email) != '' AND TRIM(p1.email) = TRIM(p2.email)) + " .
42 // 15 Government ID
43 "15 * (TRIM(p1.ss) != '' AND TRIM(p1.ss) = TRIM(p2.ss))";