Interceptor now correctly intercepts at the right point

This commit is contained in:
Tadgh 2021-03-29 21:12:03 -04:00
parent ab143e34cb
commit a15ded7140
6 changed files with 28 additions and 12 deletions

View File

@ -58,4 +58,13 @@ public interface IMdmLinkDao extends JpaRepository<MdmLink, Long> {
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<MdmPidTuple> expandPidsBySourcePidAndMatchResult(@Param("sourcePid") Long theSourcePid, @Param("matchResult") MdmMatchResultEnum theMdmMatchResultEnum);
}

View File

@ -81,9 +81,12 @@ public class MdmLinkExpandSvc {
*/
public Set<String> expandMdmBySourceResourcePid(Long theSourceResourcePid) {
ourLog.debug("About to expand source resource with PID {}", theSourceResourcePid);
List<List<Long>> goldenPidSourcePidTuples = myMdmLinkDao.expandPidsBySourcePidAndMatchResult(theSourceResourcePid, MdmMatchResultEnum.MATCH);
List<IMdmLinkDao.MdmPidTuple> goldenPidSourcePidTuples = myMdmLinkDao.expandPidsBySourcePidAndMatchResult(theSourceResourcePid, MdmMatchResultEnum.MATCH);
Set<Long> flattenedPids = new HashSet<>();
goldenPidSourcePidTuples.forEach(flattenedPids::addAll);
goldenPidSourcePidTuples.forEach(tuple -> {
flattenedPids.add(tuple.getSourcePid());
flattenedPids.add(tuple.getGoldenPid());
});
Set<String> resourceIds = myIdHelperService.translatePidsToFhirResourceIds(flattenedPids);
ourLog.debug("Pid {} has been expanded to [{}]", theSourceResourcePid, String.join(",", resourceIds));
return resourceIds;

View File

@ -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<String> 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.
});
}
}

View File

@ -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;

View File

@ -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<Long> expectedExpandedPids = mdmLinks.stream().map(MdmLink::getSourcePid).collect(Collectors.toList());
//SUT
List<List<Long>> lists = myMdmLinkDao.expandPidsBySourcePidAndMatchResult(mdmLinks.get(0).getSourcePid(), MdmMatchResultEnum.MATCH);
List<IMdmLinkDao.MdmPidTuple> 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)));
});
}

View File

@ -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());