From dc89a4abd7271c820ff86dcf5ff1e0d78e3333dc Mon Sep 17 00:00:00 2001 From: Nick Goupinets Date: Wed, 26 May 2021 15:13:43 -0400 Subject: [PATCH] Updated identifier matcher to only match on non-empty values --- .../fhir/mdm/rules/matcher/IdentifierMatcher.java | 12 +++++++++++- .../mdm/rules/matcher/IdentifierMatcherR4Test.java | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/matcher/IdentifierMatcher.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/matcher/IdentifierMatcher.java index 40fcc4fe03d..66dcf389b8a 100644 --- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/matcher/IdentifierMatcher.java +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/matcher/IdentifierMatcher.java @@ -23,11 +23,11 @@ package ca.uhn.fhir.mdm.rules.matcher; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.mdm.util.CanonicalIdentifier; import ca.uhn.fhir.mdm.util.IdentifierUtil; +import ca.uhn.fhir.model.primitive.StringDt; import org.hl7.fhir.instance.model.api.IBase; public class IdentifierMatcher implements IMdmFieldMatcher { /** - * * @return true if the two fhir identifiers are the same. If @param theIdentifierSystem is not null, then the * matcher only returns true if the identifier systems also match this system. * @throws UnsupportedOperationException if either Base is not an Identifier instance @@ -41,6 +41,16 @@ public class IdentifierMatcher implements IMdmFieldMatcher { } } CanonicalIdentifier right = IdentifierUtil.identifierDtFromIdentifier(theRightBase); + if (isEmpty(left.getValueElement()) || isEmpty(right.getValueElement())) { + return false; + } return left.equals(right); } + + private boolean isEmpty(StringDt theValue) { + if (theValue == null) { + return true; + } + return theValue.isEmpty(); + } } diff --git a/hapi-fhir-server-mdm/src/test/java/ca/uhn/fhir/mdm/rules/matcher/IdentifierMatcherR4Test.java b/hapi-fhir-server-mdm/src/test/java/ca/uhn/fhir/mdm/rules/matcher/IdentifierMatcherR4Test.java index 5e6758af0a0..66666446f8a 100644 --- a/hapi-fhir-server-mdm/src/test/java/ca/uhn/fhir/mdm/rules/matcher/IdentifierMatcherR4Test.java +++ b/hapi-fhir-server-mdm/src/test/java/ca/uhn/fhir/mdm/rules/matcher/IdentifierMatcherR4Test.java @@ -46,6 +46,17 @@ public class IdentifierMatcherR4Test extends BaseMatcherR4Test { assertFalse(fieldMatch.match(ourFhirContext, rightNoValue, left).match); } + @Test + public void testIdentifierMatchWithNoValues() { + Identifier left = new Identifier().setSystem(MATCHING_SYSTEM); + Identifier right = new Identifier().setSystem(MATCHING_SYSTEM); + + MdmMatcherJson matcher = new MdmMatcherJson().setAlgorithm(MdmMatcherEnum.IDENTIFIER).setIdentifierSystem(MATCHING_SYSTEM); + MdmFieldMatchJson fieldMatch = new MdmFieldMatchJson().setMatcher(matcher); + + assertFalse(fieldMatch.match(ourFhirContext, left, right).match); + } + @Test public void testIdentifierNamedSystemMatch() { Identifier left = new Identifier().setSystem(MATCHING_SYSTEM).setValue(MATCHING_VALUE);