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);