diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/batch/processors/GoldenResourceAnnotatingProcessor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/batch/processors/GoldenResourceAnnotatingProcessor.java index 2013cce4af7..0fb79d6505d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/batch/processors/GoldenResourceAnnotatingProcessor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/batch/processors/GoldenResourceAnnotatingProcessor.java @@ -117,8 +117,6 @@ public class GoldenResourceAnnotatingProcessor implements ItemProcessor extension = ExtensionUtil.getOrCreateExtension(iBaseResource, HapiExtensions.ASSOCIATED_GOLDEN_RESOURCE_EXTENSION_URL); if (!StringUtils.isBlank(goldenResourceId)) { ExtensionUtil.setExtension(myContext, extension, "reference", prefixPatient(goldenResourceId)); - } else { - ExtensionUtil.setExtension(myContext, extension, "string", "This patient has no matched golden resource."); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/job/GroupBulkItemReader.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/job/GroupBulkItemReader.java index a5515667469..cbd27398a49 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/job/GroupBulkItemReader.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/job/GroupBulkItemReader.java @@ -120,8 +120,11 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade if (myMdmEnabled) { IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId)); Long pidOrNull = myIdHelperService.getPidOrNull(group); - List> goldenPidSourcePidTuple = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH); - goldenPidSourcePidTuple.forEach(patientPidsToExport::addAll); + List goldenPidSourcePidTuple = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH); + goldenPidSourcePidTuple.forEach(tuple -> { + patientPidsToExport.add(tuple.getGoldenPid()); + patientPidsToExport.add(tuple.getSourcePid()); + }); populateMdmResourceCache(goldenPidSourcePidTuple); } List resourcePersistentIds = patientPidsToExport @@ -134,7 +137,7 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade /** * @param thePidTuples */ - private void populateMdmResourceCache(List> thePidTuples) { + private void populateMdmResourceCache(List thePidTuples) { if (myMdmExpansionCacheSvc.hasBeenPopulated()) { return; } @@ -144,9 +147,9 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade // patient/gold-2 -> [patient/3, patient/4] //} Map> goldenResourceToSourcePidMap = new HashMap<>(); - for (List goldenPidTargetPidTuple : thePidTuples) { - Long goldenPid = goldenPidTargetPidTuple.get(0); - Long sourcePid = goldenPidTargetPidTuple.get(1); + for (IMdmLinkDao.MdmPidTuple goldenPidTargetPidTuple : thePidTuples) { + Long goldenPid = goldenPidTargetPidTuple.getGoldenPid(); + Long sourcePid = goldenPidTargetPidTuple.getSourcePid(); if(!goldenResourceToSourcePidMap.containsKey(goldenPid)) { goldenResourceToSourcePidMap.put(goldenPid, new HashSet<>()); @@ -204,16 +207,19 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade //Attempt to perform MDM Expansion of membership if (myMdmEnabled) { - List> goldenPidTargetPidTuples = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH); + List goldenPidTargetPidTuples = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH); //Now lets translate these pids into resource IDs Set uniquePids = new HashSet<>(); - goldenPidTargetPidTuples.forEach(uniquePids::addAll); + goldenPidTargetPidTuples.forEach(tuple -> { + uniquePids.add(tuple.getGoldenPid()); + uniquePids.add(tuple.getSourcePid()); + }); Map> pidToForcedIdMap = myIdHelperService.translatePidsToForcedIds(uniquePids); Map> goldenResourceToSourcePidMap = new HashMap<>(); - for (List goldenPidTargetPidTuple : goldenPidTargetPidTuples) { - Long goldenPid = goldenPidTargetPidTuple.get(0); - Long sourcePid = goldenPidTargetPidTuple.get(1); + for (IMdmLinkDao.MdmPidTuple goldenPidTargetPidTuple : goldenPidTargetPidTuples) { + Long goldenPid = goldenPidTargetPidTuple.getGoldenPid(); + Long sourcePid = goldenPidTargetPidTuple.getSourcePid(); if(!goldenResourceToSourcePidMap.containsKey(goldenPid)) { goldenResourceToSourcePidMap.put(goldenPid, new HashSet<>()); 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 7ad98e46e11..53814c503b7 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 @@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.dao.data; import ca.uhn.fhir.mdm.api.MdmMatchResultEnum; import ca.uhn.fhir.jpa.entity.MdmLink; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -40,7 +41,7 @@ public interface IMdmLinkDao extends JpaRepository { @Query("DELETE FROM MdmLink f WHERE (myGoldenResourcePid = :pid OR mySourcePid = :pid) AND myMatchResult <> :matchResult") int deleteWithAnyReferenceToPidAndMatchResultNot(@Param("pid") Long thePid, @Param("matchResult") MdmMatchResultEnum theMatchResult); - @Query("SELECT ml2.myGoldenResourcePid, ml2.mySourcePid FROM MdmLink ml2 " + + @Query("SELECT ml2.myGoldenResourcePid as goldenPid, ml2.mySourcePid as sourcePid FROM MdmLink ml2 " + "WHERE ml2.myMatchResult=:matchResult " + "AND ml2.myGoldenResourcePid IN (" + "SELECT ml.myGoldenResourcePid FROM MdmLink ml " + @@ -50,5 +51,11 @@ public interface IMdmLinkDao extends JpaRepository { "AND hrl.mySourcePath='Group.member.entity' " + "AND hrl.myTargetResourceType='Patient'" + ")") - List> expandPidsFromGroupPidGivenMatchResult(@Param("groupPid") Long theGroupPid, @Param("matchResult") MdmMatchResultEnum theMdmMatchResultEnum); + List expandPidsFromGroupPidGivenMatchResult(@Param("groupPid") Long theGroupPid, @Param("matchResult") MdmMatchResultEnum theMdmMatchResultEnum); + + interface MdmPidTuple { + Long getGoldenPid(); + Long getSourcePid(); + } + }