From dadd5f3caf357be07340e2a5685c5e30462b9d05 Mon Sep 17 00:00:00 2001 From: Nick Goupinets Date: Fri, 13 Nov 2020 14:22:45 -0500 Subject: [PATCH] Resolved EmpiLinkSvcTest failures --- .../jpa/empi/svc/EmpiEidUpdateService.java | 2 - .../fhir/jpa/empi/svc/EmpiLinkSvcImpl.java | 5 +- .../ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java | 12 +++++ .../fhir/jpa/empi/svc/EmpiLinkSvcTest.java | 49 +++++++++++++++---- 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiEidUpdateService.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiEidUpdateService.java index 1a1ab7d5b4d..7c3bcb2d432 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiEidUpdateService.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiEidUpdateService.java @@ -62,9 +62,7 @@ public class EmpiEidUpdateService { private IEmpiSettings myEmpiSettings; void handleEmpiUpdate(IAnyResource theResource, MatchedSourceResourceCandidate theMatchedSourceResourceCandidate, MdmTransactionContext theMdmTransactionContext) { - EmpiUpdateContext updateContext = new EmpiUpdateContext(theMatchedSourceResourceCandidate, theResource); - if (updateContext.isRemainsMatchedToSamePerson()) { // Copy over any new external EIDs which don't already exist. // TODO NG - Eventually this call will use terser to clone data in, once the surviorship rules for copying data will be confirmed diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcImpl.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcImpl.java index c2854854d4e..79100f79a71 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcImpl.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcImpl.java @@ -72,8 +72,9 @@ public class EmpiLinkSvcImpl implements IEmpiLinkSvc { " not linking as POSSIBLE_DUPLICATE."); return; } -// EmpiMatchResultEnum matchResultEnum = theMatchOutcome.getMatchResultEnum(); -// validateRequestIsLegal(thePerson, theTarget, matchResultEnum, theLinkSource); + EmpiMatchResultEnum matchResultEnum = theMatchOutcome.getMatchResultEnum(); + validateRequestIsLegal(thePerson, theTarget, matchResultEnum, theLinkSource); + // switch (matchResultEnum) { // case MATCH: // myPersonHelper.addOrUpdateLink(thePerson, resourceId, AssuranceLevelUtil.getAssuranceLevel(matchResultEnum, theLinkSource), theEmpiTransactionContext); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java index 6e6f976a962..0d3d1f131e9 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java @@ -209,6 +209,10 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test { return buildPractitionerWithNameIdAndBirthday(theGivenName, theId, null); } + /** + * Use {@link #buildPatientWithNameAndId(String, String)} instead + */ + @Deprecated @Nonnull protected Patient buildSourcePaitentWithNameAndId(String theGivenName, String theId) { return buildSourcePatientWithNameIdAndBirthday(theGivenName, theId, null); @@ -243,6 +247,10 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test { return practitioner; } + /** + * Use {@link #buildPatientWithNameAndId(String, String)} instead. + */ + @Deprecated @Nonnull protected Patient buildSourcePatientWithNameIdAndBirthday(String theGivenName, String theId, Date theBirthday) { Patient patient = new Patient(); @@ -266,7 +274,11 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test { return buildPractitionerWithNameAndId(NAME_GIVEN_JANE, JANE_ID); } + /** + * Use {@link #buildJanePatient()} instead + */ @Nonnull + @Deprecated protected Patient buildJaneSourcePatient() { return buildSourcePaitentWithNameAndId(NAME_GIVEN_JANE, JANE_ID); } diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java index 35b4d3391f3..d5fc13c7883 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java @@ -4,9 +4,13 @@ import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum; import ca.uhn.fhir.empi.api.EmpiMatchOutcome; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import ca.uhn.fhir.empi.api.IEmpiLinkSvc; +import ca.uhn.fhir.empi.util.EIDHelper; import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test; import ca.uhn.fhir.jpa.entity.EmpiLink; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; +import org.assertj.core.util.Lists; +import org.hamcrest.Matchers; +import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Patient; import org.junit.jupiter.api.AfterEach; @@ -14,6 +18,9 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; @@ -48,21 +55,23 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test { assertLinkCount(0); Patient sourcePatient = createGoldenPatient(); IdType sourcePatientId = sourcePatient.getIdElement().toUnqualifiedVersionless(); - assertEquals(0, sourcePatient.getLink().size()); + // TODO NG should be ok to remove - assertEquals(0, sourcePatient.getLink().size()); Patient patient = createPatient(); { myEmpiLinkSvc.updateLink(sourcePatient, patient, POSSIBLE_MATCH, EmpiLinkSourceEnum.AUTO, createContextForCreate("Patient")); assertLinkCount(1); - Patient newSourcePatient = myPatientDao.read(sourcePatientId); - assertEquals(1, newSourcePatient.getLink().size()); + // TODO NG should be ok to remove + // Patient newSourcePatient = myPatientDao.read(sourcePatientId); + // assertEquals(1, newSourcePatient.getLink().size()); } { myEmpiLinkSvc.updateLink(sourcePatient, patient, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient")); assertLinkCount(1); - Patient newSourcePatient = myPatientDao.read(sourcePatientId); - assertEquals(0, newSourcePatient.getLink().size()); + // TODO NG should be ok to remove + // Patient newSourcePatient = myPatientDao.read(sourcePatientId); + // assertEquals(0, newSourcePatient.getLink().size()); } } @@ -138,7 +147,8 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test { @Test public void testAutomaticallyAddedNO_MATCHEmpiLinksAreNotAllowed() { - Patient sourcePatient = createGoldenPatient(buildJaneSourcePatient()); +// Patient sourcePatient = createGoldenPatient(buildJaneSourcePatient()); + Patient sourcePatient = createGoldenPatient(buildJanePatient()); Patient patient = createPatient(buildJanePatient()); // Test: it should be impossible to have a AUTO NO_MATCH record. The only NO_MATCH records in the system must be MANUAL. @@ -152,16 +162,35 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test { @Test public void testSyncDoesNotSyncNoMatchLinks() { - Patient sourcePatient = createGoldenPatient(buildJaneSourcePatient()); +// Patient sourcePatient = createGoldenPatient(buildJaneSourcePatient()); + Patient goldenPatient = createGoldenPatient(buildJanePatient()); Patient patient1 = createPatient(buildJanePatient()); Patient patient2 = createPatient(buildJanePatient()); assertEquals(0, myEmpiLinkDao.count()); - myEmpiLinkDaoSvc.createOrUpdateLinkEntity(sourcePatient, patient1, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient")); - myEmpiLinkDaoSvc.createOrUpdateLinkEntity(sourcePatient, patient2, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient")); + myEmpiLinkDaoSvc.createOrUpdateLinkEntity(goldenPatient, patient1, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient")); + myEmpiLinkDaoSvc.createOrUpdateLinkEntity(goldenPatient, patient2, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient")); // myEmpiLinkSvc.syncEmpiLinksToPersonLinks(sourcePatient, createContextForCreate("Patient")); - assertTrue(sourcePatient.hasLink()); + + List targets = myEmpiLinkDaoSvc.findEmpiLinksByGoldenResource(goldenPatient); + assertFalse(targets.isEmpty()); + assertEquals(2, targets.size()); + // TODO NG - OK? original assertTrue(goldenPatient.hasLink()); + //TODO GGG update this test once we decide what has to happen here. There is no more "syncing links" //assertEquals(patient1.getIdElement().toVersionless().getValue(), sourcePatient.getLinkFirstRep().getTarget().getReference()); + List actual = targets + .stream() + .map(link -> link.getTargetPid().toString()) + .collect(Collectors.toList()); + + List expected = Arrays.asList(patient1, patient2) + .stream().map(p -> p.getIdElement().toVersionless().getIdPart()) + .collect(Collectors.toList()); + + System.out.println(actual); + System.out.println(expected); + + assertThat(actual, Matchers.containsInAnyOrder(expected.toArray())); } }