diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java index 9e16a1a88a8..7f176ac5e94 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java @@ -299,11 +299,9 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test { mergeGoldenPatients(); - assertResourceHasLinkCount(myToGoldenPatient, 3, (e) -> true); - assertResourceHasLinkCount(myFromGoldenPatient, 0, (e) -> true); + assertResourceHasLinkCount(myToGoldenPatient, 3); + assertResourceHasLinkCount(myFromGoldenPatient, 0); // TODO ENSURE PROPER LINK TYPES - // TODO MAKE IT MORE READABLE - assertEquals(3, myEmpiLinkDao.count()); } @@ -321,13 +319,10 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test { assertResourceHasAutoLinkCount(myToGoldenPatient, 3); } - private void assertResourceHasAutoLinkCount(IBaseResource theResource, int theCount) { - assertResourceHasLinkCount(theResource, theCount, EmpiLink::isAuto); - } - private void assertResourceHasLinkCount(IBaseResource theResource, int theCount, Predicate thePredicate) { + private void assertResourceHasLinkCount(IBaseResource theResource, int theCount) { List links = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theResource); - assertEquals(theCount, links.stream().filter(thePredicate).count()); + assertEquals(theCount, links.size()); } @Test @@ -344,6 +339,11 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test { assertResourceHasAutoLinkCount(myToGoldenPatient, 3); } + private void assertResourceHasAutoLinkCount(Patient myToGoldenPatient, int theCount) { + List links = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(myToGoldenPatient); + assertEquals(theCount, links.stream().filter(EmpiLink::isAuto).count()); + } + @Test public void from123To123() { createEmpiLink(myFromGoldenPatient, myTargetPatient1); diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/util/PrimitiveTypeComparingPredicateTest.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/util/PrimitiveTypeComparingPredicateTest.java index ff46be62495..a4e0b24744d 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/util/PrimitiveTypeComparingPredicateTest.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/util/PrimitiveTypeComparingPredicateTest.java @@ -1,11 +1,104 @@ package ca.uhn.fhir.empi.util; -import static org.junit.jupiter.api.Assertions.*; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.util.FhirTerser; +import org.hl7.fhir.instance.model.api.IBase; +import org.hl7.fhir.r4.model.Address; +import org.hl7.fhir.r4.model.BooleanType; +import org.hl7.fhir.r4.model.DateType; +import org.hl7.fhir.r4.model.Enumerations; +import org.hl7.fhir.r4.model.Identifier; +import org.hl7.fhir.r4.model.Patient; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class PrimitiveTypeComparingPredicateTest { - // TODO NG ADD TESTS - // compare identifiers - // compare something scary to show that it failed + private static FhirContext myFhirContext; + + private FhirTerser myTerser; + + private IBase myPositiveTest1; + + private IBase myPositiveTest2; + + private IBase myPositiveTest3; + + private IBase myNegativeTest; + + private PrimitiveTypeComparingPredicate cut = new PrimitiveTypeComparingPredicate(); + + @BeforeAll + public static void initContext() { + myFhirContext = FhirContext.forR4(); + } + + @BeforeEach + public void init() { + myTerser = myFhirContext.newTerser(); + + myPositiveTest1 = newPatient(); + myPositiveTest2 = newPatient(); + myPositiveTest3 = newPatient(); + + Patient patient = newPatient(); + patient.setActive(false); + patient.setMultipleBirth(new BooleanType(false)); + myNegativeTest = patient; + } + + private Patient newPatient() { + Patient patient; + patient = new Patient(); + patient.setActive(true); + patient.setGender(Enumerations.AdministrativeGender.FEMALE); + patient.setBirthDateElement(new DateType("1901-01-01")); + + Address address = new Address(); + address.addLine("Somwhere"); + address.setCity("Toronto"); + address.setCountry("Canada"); + patient.setAddress(Collections.singletonList(address)); + return patient; + } + + @Test + public void testNegativeMatchOnTheSameType() { + assertFalse(cut.test(myPositiveTest1, myNegativeTest)); + assertFalse(cut.test(myNegativeTest, myPositiveTest1)); + } + + @Test + public void testNegativeMatchOnDifferentTypes() { + Patient patient = newPatient(); + Identifier identifier = patient.addIdentifier(); + identifier.setValue("TEST_VALUE"); + assertFalse(cut.test(myNegativeTest, identifier)); + } + + @Test + public void testSymmetry() { + assertTrue(cut.test(myPositiveTest1, myPositiveTest2)); + assertTrue(cut.test(myPositiveTest2, myPositiveTest1)); + } + + @Test + public void testReflexivity() { + assertTrue(cut.test(myPositiveTest1, myPositiveTest1)); + } + + @Test + public void testTransitivity() { + assertTrue(cut.test(myPositiveTest1, myPositiveTest2)); + assertTrue(cut.test(myPositiveTest2, myPositiveTest3)); + assertTrue(cut.test(myPositiveTest1, myPositiveTest3)); + } + }