From a15ded71408607f541e38a6991132ef59c85b5b6 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 29 Mar 2021 21:12:03 -0400 Subject: [PATCH] Interceptor now correctly intercepts at the right point --- .../java/ca/uhn/fhir/jpa/dao/data/IMdmLinkDao.java | 9 +++++++++ .../java/ca/uhn/fhir/jpa/dao/mdm/MdmLinkExpandSvc.java | 7 +++++-- .../MdmSearchExpandingInterceptorInterceptor.java | 10 ++++++---- .../r4/ResourceProviderCustomSearchParamR4Test.java | 2 ++ .../ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvcTest.java | 9 +++++---- .../jpa/mdm/interceptor/MdmStorageInterceptorIT.java | 3 +-- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IMdmLinkDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IMdmLinkDao.java index 53814c503b7..653c229727b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IMdmLinkDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IMdmLinkDao.java @@ -58,4 +58,13 @@ public interface IMdmLinkDao extends JpaRepository { Long getSourcePid(); } + @Query("SELECT ml.myGoldenResourcePid, ml.mySourcePid " + + "FROM MdmLink ml " + + "INNER JOIN MdmLink ml2 " + + "on ml.myGoldenResourcePid=ml2.myGoldenResourcePid " + + "WHERE ml2.mySourcePid=:sourcePid " + + "AND ml2.myMatchResult=:matchResult " + + "AND ml.myMatchResult=:matchResult") + List expandPidsBySourcePidAndMatchResult(@Param("sourcePid") Long theSourcePid, @Param("matchResult") MdmMatchResultEnum theMdmMatchResultEnum); + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/mdm/MdmLinkExpandSvc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/mdm/MdmLinkExpandSvc.java index a04e4c2f795..66af7f5a706 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/mdm/MdmLinkExpandSvc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/mdm/MdmLinkExpandSvc.java @@ -81,9 +81,12 @@ public class MdmLinkExpandSvc { */ public Set expandMdmBySourceResourcePid(Long theSourceResourcePid) { ourLog.debug("About to expand source resource with PID {}", theSourceResourcePid); - List> goldenPidSourcePidTuples = myMdmLinkDao.expandPidsBySourcePidAndMatchResult(theSourceResourcePid, MdmMatchResultEnum.MATCH); + List goldenPidSourcePidTuples = myMdmLinkDao.expandPidsBySourcePidAndMatchResult(theSourceResourcePid, MdmMatchResultEnum.MATCH); Set flattenedPids = new HashSet<>(); - goldenPidSourcePidTuples.forEach(flattenedPids::addAll); + goldenPidSourcePidTuples.forEach(tuple -> { + flattenedPids.add(tuple.getSourcePid()); + flattenedPids.add(tuple.getGoldenPid()); + }); Set resourceIds = myIdHelperService.translatePidsToFhirResourceIds(flattenedPids); ourLog.debug("Pid {} has been expanded to [{}]", theSourceResourcePid, String.join(",", resourceIds)); return resourceIds; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/MdmSearchExpandingInterceptorInterceptor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/MdmSearchExpandingInterceptorInterceptor.java index 04333b578a7..46052fc1d52 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/MdmSearchExpandingInterceptorInterceptor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/MdmSearchExpandingInterceptorInterceptor.java @@ -72,12 +72,14 @@ public class MdmSearchExpandingInterceptorInterceptor { System.out.println("zoop"); theSearchParameterMap.values().stream() .flatMap(Collection::stream) - .filter(queryParam -> queryParam instanceof ReferenceParam) - .filter(referenceParam -> ((ReferenceParam) referenceParam).isMdmExpand()) + .flatMap(Collection::stream) + .filter(param -> param instanceof ReferenceParam) .map(untypedParam -> (ReferenceParam)untypedParam) + .filter(ReferenceParam::isMdmExpand) .forEach(mdmReferenceParam -> { - System.out.println("zoop"); - System.out.println(mdmReferenceParam.toString()); + Set strings = myMdmLinkExpandSvc.expandMdmBySourceResourceId(new IdDt(mdmReferenceParam.getValue())); + System.out.println(String.join(",", strings)); + //TODO in AM, start here with a test that actually has an expansion to expand against. }); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java index 59b1d653154..3453eddc465 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java @@ -58,6 +58,8 @@ import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvcTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvcTest.java index cd3978133b8..ae034af6fa7 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvcTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvcTest.java @@ -1,5 +1,6 @@ package ca.uhn.fhir.jpa.mdm.dao; +import ca.uhn.fhir.jpa.dao.data.IMdmLinkDao; import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum; import ca.uhn.fhir.mdm.api.IMdmSettings; import ca.uhn.fhir.mdm.api.MdmMatchResultEnum; @@ -78,14 +79,14 @@ public class MdmLinkDaoSvcTest extends BaseMdmR4Test { List expectedExpandedPids = mdmLinks.stream().map(MdmLink::getSourcePid).collect(Collectors.toList()); //SUT - List> lists = myMdmLinkDao.expandPidsBySourcePidAndMatchResult(mdmLinks.get(0).getSourcePid(), MdmMatchResultEnum.MATCH); + List lists = myMdmLinkDao.expandPidsBySourcePidAndMatchResult(mdmLinks.get(0).getSourcePid(), MdmMatchResultEnum.MATCH); assertThat(lists, hasSize(10)); lists.stream() - .forEach(pair -> { - assertThat(pair.get(0), is(equalTo(golden.getIdElement().getIdPartAsLong()))); - assertThat(pair.get(1), is(in(expectedExpandedPids))); + .forEach(tuple -> { + assertThat(tuple.getGoldenPid(), is(equalTo(golden.getIdElement().getIdPartAsLong()))); + assertThat(tuple.getSourcePid(), is(in(expectedExpandedPids))); }); } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java index 051bf27c546..c06f0db2c7f 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java @@ -69,11 +69,10 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { @Test public void testSearchExpandingInterceptorWorks() { - SearchParameterMap subject = new SearchParameterMap("subject", new ReferenceParam("Patient/123").setMdmExpand(true)).setLoadSynchronous(false); + SearchParameterMap subject = new SearchParameterMap("subject", new ReferenceParam("Patient/123").setMdmExpand(true)).setLoadSynchronous(true); myObservationDao.search(subject); } - @Test public void testDeleteGoldenResourceDeletesLinks() throws InterruptedException { myMdmHelper.createWithLatch(buildPaulPatient());