From 5d6ede660be921ea2eb12c6223c9e1eafddb47f1 Mon Sep 17 00:00:00 2001 From: Nick Goupinets Date: Mon, 9 Nov 2020 11:07:58 -0500 Subject: [PATCH] Use case #3 testing --- hapi-fhir-jpaserver-empi/pom.xml | 10 +++++- .../fhir/jpa/empi/svc/EmpiResourceDaoSvc.java | 33 ++++--------------- .../svc/candidate/FindCandidateByEidSvc.java | 3 +- .../jpa/empi/svc/EmpiMatchLinkSvcTest.java | 29 ++++++++++++---- .../jpa/empi/svc/EmpiResourceDaoSvcTest.java | 4 +-- 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/hapi-fhir-jpaserver-empi/pom.xml b/hapi-fhir-jpaserver-empi/pom.xml index d5094d752b0..22c5a638c84 100644 --- a/hapi-fhir-jpaserver-empi/pom.xml +++ b/hapi-fhir-jpaserver-empi/pom.xml @@ -96,6 +96,14 @@ - + + org.apache.maven.plugins + maven-compiler-plugin + + 9 + 9 + + + diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvc.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvc.java index 8e6bcac76b4..035261fa853 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvc.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvc.java @@ -44,35 +44,14 @@ import java.util.stream.Collectors; @Service public class EmpiResourceDaoSvc { + private static final int MAX_MATCHING_PERSONS = 1000; + @Autowired DaoRegistry myDaoRegistry; @Autowired IEmpiSettings myEmpiConfig; - private IFhirResourceDao myPatientDao; - private IFhirResourceDao myPersonDao; - private IFhirResourceDao myPractitionerDao; - - @PostConstruct - public void postConstruct() { - myPatientDao = myDaoRegistry.getResourceDao("Patient"); - myPersonDao = myDaoRegistry.getResourceDao("Person"); - myPractitionerDao = myDaoRegistry.getResourceDao("Practitioner"); - } - - public IAnyResource readPatient(IIdType theId) { - return (IAnyResource) myPatientDao.read(theId); - } - - public IAnyResource readPerson(IIdType theId) { - return (IAnyResource) myPersonDao.read(theId); - } - - public IAnyResource readPractitioner(IIdType theId) { - return (IAnyResource) myPractitionerDao.read(theId); - } - public DaoMethodOutcome upsertSourceResource(IAnyResource theSourceResource, String theResourceType) { IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theResourceType); if (theSourceResource.getIdElement().hasIdPart()) { @@ -87,12 +66,14 @@ public class EmpiResourceDaoSvc { return (IAnyResource) resourceDao.readByPid(theSourceResourcePid); } - public Optional searchPersonByEid(String theEid) { + public Optional searchSourceResourceByEID(String theEid, String theResourceType) { SearchParameterMap map = new SearchParameterMap(); map.setLoadSynchronous(true); map.add("identifier", new TokenParam(myEmpiConfig.getEmpiRules().getEnterpriseEIDSystem(), theEid)); map.add("active", new TokenParam("true")); - IBundleProvider search = myPersonDao.search(map); + + IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theResourceType); + IBundleProvider search = resourceDao.search(map); // Could add the meta tag to the query, but it's probably more efficient to filter on it afterwards since in practice // it will always be present. @@ -111,7 +92,7 @@ public class EmpiResourceDaoSvc { list.get(0).getIdElement().getValue() + ", " + list.get(1).getIdElement().getValue() - ); + ); } else { return Optional.of((IAnyResource) list.get(0)); } diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/FindCandidateByEidSvc.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/FindCandidateByEidSvc.java index 776af48606f..498f804d8eb 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/FindCandidateByEidSvc.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/candidate/FindCandidateByEidSvc.java @@ -37,6 +37,7 @@ import java.util.Optional; @Service public class FindCandidateByEidSvc extends BaseCandidateFinder { + private static final Logger ourLog = Logs.getEmpiTroubleshootingLog(); @Autowired @@ -50,7 +51,7 @@ public class FindCandidateByEidSvc extends BaseCandidateFinder { List eidFromResource = myEIDHelper.getExternalEid(theBaseResource); if (!eidFromResource.isEmpty()) { for (CanonicalEID eid : eidFromResource) { - Optional oFoundPerson = myEmpiResourceDaoSvc.searchPersonByEid(eid.getValue()); + Optional oFoundPerson = myEmpiResourceDaoSvc.searchSourceResourceByEID(eid.getValue(), theBaseResource.getIdElement().getResourceType()); if (oFoundPerson.isPresent()) { IAnyResource foundPerson = oFoundPerson.get(); Long pidOrNull = myIdHelperService.getPidOrNull(foundPerson); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcTest.java index f4b9f2a8c16..db18cdaae95 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcTest.java @@ -221,20 +221,35 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { @Test public void testIncomingPatientWithEidMatchesAnotherPatientWithSameEIDAreLinked() { - // Use Case #3 + // Create Use Case #3 Patient patient1 = addExternalEID(buildJanePatient(), "uniqueid"); createPatientAndUpdateLinks(patient1); - // state is now > Patient/uniqueid[name=jane] <--> Patient/uniqueid[name=jane] - List eid = myEidHelper.getExternalEid(patient1); + // state is now > Patient/ID.JANE.123[name=jane & EID = uniqueid] <-- EMPI Link -- Patient/[name=jane & EDI = uniqueid & EMPI_MANAGED = true] + IBundleProvider bundle = myPatientDao.search(new SearchParameterMap()); + List resources = bundle.getResources(0, bundle.size()); + resources.forEach(r -> { + print(r); + assertFalse(myEidHelper.getExternalEid(r).isEmpty()); + }); + assertEquals(2, resources.size()); - Optional iAnyResource = myEmpiResourceDaoSvc.searchPersonByEid(eid.get(0).getValue()); - assertTrue(iAnyResource.isPresent()); - assertTrue(iAnyResource.get().equals(patient1)); + IBaseResource testPatient1 = resources.get(0); + IBaseResource testPatient2 = resources.get(1); + + assertThat((Patient) testPatient1, is(sameSourceResourceAs((Patient) testPatient2))); + + Optional empiLinkByTarget = myEmpiLinkDaoSvc.findEmpiLinkByTarget(patient1); + assertTrue(empiLinkByTarget.isPresent()); Patient patient2 = addExternalEID(buildPaulPatient(), "uniqueid"); createPatientAndUpdateLinks(patient2); - // state should be > Patient/uniqueid[name=jane] <--> Patient/uniqueid[name=jane] <--> Patient/uniqueid[name=paul] + // state should be > Patient/ID.JANE.123[name=jane & EID = uniqueid] <--> Patient/[name=jane & EDI = uniqueid] <--> Patient/[name=paul & EDI = uniqueid] + IBundleProvider search = myPatientDao.search(new SearchParameterMap()); + search.getResources(0, search.size()).forEach( r -> { + print(r); + } + ); assertThat(patient1, is(sameSourceResourceAs(patient2))); } diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvcTest.java index 35ebf5723ec..06eb1b534b1 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvcTest.java @@ -32,7 +32,7 @@ public class EmpiResourceDaoSvcTest extends BaseEmpiR4Test { badPerson.setActive(false); myPersonDao.update(badPerson); - Optional foundPerson = myResourceDaoSvc.searchPersonByEid(TEST_EID); + Optional foundPerson = myResourceDaoSvc.searchSourceResourceByEID(TEST_EID, "Person"); assertTrue(foundPerson.isPresent()); assertThat(foundPerson.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodPerson.getIdElement().toUnqualifiedVersionless().getValue())); } @@ -45,7 +45,7 @@ public class EmpiResourceDaoSvcTest extends BaseEmpiR4Test { Person badPerson = addExternalEID(createPerson(new Person(), false), TEST_EID); myPersonDao.update(badPerson); - Optional foundPerson = myResourceDaoSvc.searchPersonByEid(TEST_EID); + Optional foundPerson = myResourceDaoSvc.searchSourceResourceByEID(TEST_EID, "Person"); assertTrue(foundPerson.isPresent()); assertThat(foundPerson.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodPerson.getIdElement().toUnqualifiedVersionless().getValue())); }