1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.mpilib;
|
---|
6 |
|
---|
7 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
8 | import org.apache.commons.logging.Log;
|
---|
9 | import org.apache.commons.logging.LogFactory;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | *
|
---|
13 | * @author rayj
|
---|
14 | */
|
---|
15 | public class PatientMatcher {
|
---|
16 |
|
---|
17 | private static Log log = LogFactory.getLog(MiniMpi.class);
|
---|
18 |
|
---|
19 | public static boolean IsSearchMatchByIds(Patient possibleMatch, Patient searchParams) {
|
---|
20 | //i will call it a match if any one of the ids matches any other ids
|
---|
21 | //this is over simplified, but fine for now
|
---|
22 | boolean match = false;
|
---|
23 | for (Identifier searchParamIdentifier : searchParams.getIdentifiers()) {
|
---|
24 | for (Identifier possibleMatchIdentifier : possibleMatch.getIdentifiers()) {
|
---|
25 | match = match | IsSearchMatchbyId(searchParamIdentifier, possibleMatchIdentifier);
|
---|
26 | }
|
---|
27 | }
|
---|
28 | return match;
|
---|
29 | }
|
---|
30 |
|
---|
31 | public static boolean IsSearchMatchbyId(Identifier a, Identifier b) {
|
---|
32 | boolean match;
|
---|
33 | if (a == null) {
|
---|
34 | log.info("a is null");
|
---|
35 | }
|
---|
36 | if (a.getId() == null) {
|
---|
37 | log.info("a.getId() is null");
|
---|
38 | }
|
---|
39 | if (a.getOrganizationId() == null) {
|
---|
40 | log.info("a.getOrganizationId() is null");
|
---|
41 | }
|
---|
42 | if (b == null) {
|
---|
43 | log.info("b is null");
|
---|
44 | }
|
---|
45 | if (b.getId() == null) {
|
---|
46 | log.info("b.getId() is null");
|
---|
47 | }
|
---|
48 | if (b.getOrganizationId() == null) {
|
---|
49 | log.info("b.getOrganizationId() is null");
|
---|
50 | }
|
---|
51 | match = ((!a.getId().contentEquals("")) && (!b.getId().contentEquals(""))) && (a.getId().contentEquals(b.getId()) && a.getOrganizationId().contentEquals(b.getOrganizationId()));
|
---|
52 | return match;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public static boolean isPatientOptedInCriteriaMet(Patient possibleMatch){
|
---|
56 | return possibleMatch.isOptedIn();
|
---|
57 | }
|
---|
58 |
|
---|
59 | public static boolean IsSearchMatchByDemographics(Patient possibleMatch, Patient searchParams) {
|
---|
60 | boolean match = DoesNameMeetSearchCriteria(possibleMatch.getName(), searchParams.getName());
|
---|
61 | log.debug("[" + SerializePatient(searchParams) + "]==[" + SerializePatient(possibleMatch) + "] -> " + match);
|
---|
62 | return match;
|
---|
63 | }
|
---|
64 |
|
---|
65 | public static boolean IsMatchByDemographics(Patient patient, Patient possibleMatch) {
|
---|
66 | return IsSearchMatchByDemographics(patient, possibleMatch);
|
---|
67 | }
|
---|
68 |
|
---|
69 | private static boolean IsNameNullish(PersonName name) {
|
---|
70 | boolean result;
|
---|
71 | if (name == null) {
|
---|
72 | result = true;
|
---|
73 | } else {
|
---|
74 | result = (NullChecker.isNullish(name.getFirstName()) && NullChecker.isNullish(name.getLastName()));
|
---|
75 | }
|
---|
76 | return result;
|
---|
77 | }
|
---|
78 |
|
---|
79 | private static boolean DoesNameMeetSearchCriteria(PersonName name, PersonName searchName) {
|
---|
80 | boolean result;
|
---|
81 |
|
---|
82 | if (IsNameNullish(searchName)) {
|
---|
83 | log.info("search name nullish");
|
---|
84 | result = false;
|
---|
85 | } else {
|
---|
86 | result = DoesNamePartMeetSearchCriteria(name.getLastName(), searchName.getLastName()) && DoesNamePartMeetSearchCriteria(name.getFirstName(), searchName.getFirstName());
|
---|
87 | }
|
---|
88 | return result;
|
---|
89 | }
|
---|
90 |
|
---|
91 | private static boolean DoesNamePartMeetSearchCriteria(String namepart, String searchNamepart) {
|
---|
92 | boolean result;
|
---|
93 | if (NullChecker.isNullish(searchNamepart)) {
|
---|
94 | result = true;
|
---|
95 | } else if (NullChecker.isNullish(namepart)) {
|
---|
96 | result = false;
|
---|
97 | } else {
|
---|
98 | result = namepart.equalsIgnoreCase(searchNamepart);
|
---|
99 | }
|
---|
100 | log.info("DoesNamePartMeetSearchCriteria " + namepart + "=" + searchNamepart + " ->" + result);
|
---|
101 | return result;
|
---|
102 | }
|
---|
103 |
|
---|
104 | private static String SerializePatient(Patient patient) {
|
---|
105 | return patient.getName().getLastName() + "," + patient.getName().getFirstName();
|
---|
106 | }
|
---|
107 | }
|
---|