fixed based on pull request comments, added tests
This commit is contained in:
parent
989e9e7903
commit
6c41ded507
|
@ -158,15 +158,19 @@ public final class TerserUtil {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean equals(IBase theItem1, IBase theItem2){
|
private static Method getMethod(IBase item){
|
||||||
Method method = null;
|
Method method = null;
|
||||||
for (Method m : theItem1.getClass().getDeclaredMethods()) {
|
for (Method m : item.getClass().getDeclaredMethods()) {
|
||||||
if (m.getName().equals("equalsDeep")) {
|
if (m.getName().equals("equalsDeep")) {
|
||||||
method = m;
|
method = m;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Method m = method;
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean equals(IBase theItem1, IBase theItem2){
|
||||||
|
final Method m = getMethod(theItem1);
|
||||||
|
|
||||||
return equals(theItem1, theItem2, m);
|
return equals(theItem1, theItem2, m);
|
||||||
}
|
}
|
||||||
|
@ -183,18 +187,8 @@ public final class TerserUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean contains(IBase theItem, List<IBase> theItems) {
|
private static boolean contains(IBase theItem, List<IBase> theItems) {
|
||||||
Method method = null;
|
final Method m = getMethod(theItem);
|
||||||
for (Method m : theItem.getClass().getDeclaredMethods()) {
|
return theItems.stream().anyMatch(i -> equals(i, theItem, m));
|
||||||
if (m.getName().equals("equalsDeep")) {
|
|
||||||
method = m;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final Method m = method;
|
|
||||||
return theItems.stream().anyMatch(i -> {
|
|
||||||
return equals(i, theItem, m);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,27 +11,24 @@ import java.util.List;
|
||||||
public class ExtensionMatcher implements IMdmFieldMatcher{
|
public class ExtensionMatcher implements IMdmFieldMatcher{
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(FhirContext theFhirContext, IBase theLeftBase, IBase theRightBase, boolean theExact, String theIdentifierSystem) {
|
public boolean matches(FhirContext theFhirContext, IBase theLeftBase, IBase theRightBase, boolean theExact, String theIdentifierSystem) {
|
||||||
List<? extends IBaseExtension<?, ?>> leftExtension = null;
|
if (!(theLeftBase instanceof IBaseHasExtensions && theRightBase instanceof IBaseHasExtensions)){
|
||||||
List<? extends IBaseExtension<?, ?>> rightExtension = null;
|
|
||||||
if (theLeftBase instanceof IBaseHasExtensions && theRightBase instanceof IBaseHasExtensions){
|
|
||||||
leftExtension = ((IBaseHasExtensions) theLeftBase).getExtension();
|
|
||||||
rightExtension = ((IBaseHasExtensions) theRightBase).getExtension();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
List<? extends IBaseExtension<?, ?>> leftExtension = ((IBaseHasExtensions) theLeftBase).getExtension();
|
||||||
|
List<? extends IBaseExtension<?, ?>> rightExtension = ((IBaseHasExtensions) theRightBase).getExtension();
|
||||||
|
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
|
|
||||||
|
if (theIdentifierSystem != null) {
|
||||||
|
leftExtension.removeIf(iBaseExtension -> !iBaseExtension.getUrl().equals(theIdentifierSystem));
|
||||||
|
rightExtension.removeIf(iBaseExtension -> !iBaseExtension.getUrl().equals(theIdentifierSystem));
|
||||||
|
}
|
||||||
|
|
||||||
for (IBaseExtension leftExtensionValue : leftExtension) {
|
for (IBaseExtension leftExtensionValue : leftExtension) {
|
||||||
if (leftExtensionValue.getUrl().equals(theIdentifierSystem) || theIdentifierSystem == null) {
|
|
||||||
for (IBaseExtension rightExtensionValue : rightExtension) {
|
for (IBaseExtension rightExtensionValue : rightExtension) {
|
||||||
if (rightExtensionValue.getUrl().equals(theIdentifierSystem) || theIdentifierSystem == null) {
|
|
||||||
match |= ExtensionUtil.equals(leftExtensionValue, rightExtensionValue);
|
match |= ExtensionUtil.equals(leftExtensionValue, rightExtensionValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ca.uhn.fhir.mdm.rules.matcher;
|
||||||
|
|
||||||
|
|
||||||
import org.hl7.fhir.r4.model.IntegerType;
|
import org.hl7.fhir.r4.model.IntegerType;
|
||||||
|
import org.hl7.fhir.r4.model.Organization;
|
||||||
import org.hl7.fhir.r4.model.Patient;
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
import org.hl7.fhir.r4.model.StringType;
|
import org.hl7.fhir.r4.model.StringType;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -83,5 +84,12 @@ public class ExtensionMatcherR4Test extends BaseMatcherR4Test {
|
||||||
assertTrue(MdmMatcherEnum.EXTENSION_ANY_ORDER.match(ourFhirContext, patient1, patient2, false, null));
|
assertTrue(MdmMatcherEnum.EXTENSION_ANY_ORDER.match(ourFhirContext, patient1, patient2, false, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatientWithNoExtension(){
|
||||||
|
Patient patient1 = new Patient();
|
||||||
|
Patient patient2 = new Patient();
|
||||||
|
|
||||||
|
assertFalse(MdmMatcherEnum.EXTENSION_ANY_ORDER.match(ourFhirContext, patient1, patient2, false, null));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.hl7.fhir.r4.model.DateTimeType;
|
||||||
import org.hl7.fhir.r4.model.DateType;
|
import org.hl7.fhir.r4.model.DateType;
|
||||||
import org.hl7.fhir.r4.model.Enumerations;
|
import org.hl7.fhir.r4.model.Enumerations;
|
||||||
import org.hl7.fhir.r4.model.Extension;
|
import org.hl7.fhir.r4.model.Extension;
|
||||||
|
import org.hl7.fhir.r4.model.HumanName;
|
||||||
import org.hl7.fhir.r4.model.Identifier;
|
import org.hl7.fhir.r4.model.Identifier;
|
||||||
import org.hl7.fhir.r4.model.Patient;
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -237,4 +238,27 @@ class TerserUtilTest {
|
||||||
assertThat(p2.getName(), hasSize(1));
|
assertThat(p2.getName(), hasSize(1));
|
||||||
assertThat(p2.getName().get(0).getGiven(), hasSize(2));
|
assertThat(p2.getName().get(0).getGiven(), hasSize(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testEqualsFunction(){
|
||||||
|
Patient p1 = new Patient();
|
||||||
|
Patient p2 = new Patient();
|
||||||
|
|
||||||
|
p1.addName(new HumanName().setFamily("family").addGiven("asd"));
|
||||||
|
p2.addName(new HumanName().setFamily("family").addGiven("asd"));
|
||||||
|
|
||||||
|
assertTrue(TerserUtil.equals(p1, p2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testEqualsFunctionNotEqual(){
|
||||||
|
Patient p1 = new Patient();
|
||||||
|
Patient p2 = new Patient();
|
||||||
|
|
||||||
|
p1.addName(new HumanName().setFamily("family").addGiven("asd"));
|
||||||
|
p2.addName(new HumanName().setFamily("family").addGiven("asd1"));
|
||||||
|
|
||||||
|
assertFalse(TerserUtil.equals(p1, p2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue