Updated identifier matcher to only match on non-empty values

This commit is contained in:
Nick Goupinets 2021-05-26 15:13:43 -04:00
parent af44b9c7a0
commit dc89a4abd7
2 changed files with 22 additions and 1 deletions

View File

@ -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();
}
}

View File

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