Use dynamic projection
This commit is contained in:
parent
002d3fcf3c
commit
c46617fefa
|
@ -117,8 +117,6 @@ public class GoldenResourceAnnotatingProcessor implements ItemProcessor<List<IBa
|
|||
IBaseExtension<?, ?> 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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<List<Long>> goldenPidSourcePidTuple = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH);
|
||||
goldenPidSourcePidTuple.forEach(patientPidsToExport::addAll);
|
||||
List<IMdmLinkDao.MdmPidTuple> goldenPidSourcePidTuple = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH);
|
||||
goldenPidSourcePidTuple.forEach(tuple -> {
|
||||
patientPidsToExport.add(tuple.getGoldenPid());
|
||||
patientPidsToExport.add(tuple.getSourcePid());
|
||||
});
|
||||
populateMdmResourceCache(goldenPidSourcePidTuple);
|
||||
}
|
||||
List<ResourcePersistentId> resourcePersistentIds = patientPidsToExport
|
||||
|
@ -134,7 +137,7 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade
|
|||
/**
|
||||
* @param thePidTuples
|
||||
*/
|
||||
private void populateMdmResourceCache(List<List<Long>> thePidTuples) {
|
||||
private void populateMdmResourceCache(List<IMdmLinkDao.MdmPidTuple> thePidTuples) {
|
||||
if (myMdmExpansionCacheSvc.hasBeenPopulated()) {
|
||||
return;
|
||||
}
|
||||
|
@ -144,9 +147,9 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade
|
|||
// patient/gold-2 -> [patient/3, patient/4]
|
||||
//}
|
||||
Map<Long, Set<Long>> goldenResourceToSourcePidMap = new HashMap<>();
|
||||
for (List<Long> 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<List<Long>> goldenPidTargetPidTuples = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH);
|
||||
List<IMdmLinkDao.MdmPidTuple> goldenPidTargetPidTuples = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH);
|
||||
//Now lets translate these pids into resource IDs
|
||||
Set<Long> uniquePids = new HashSet<>();
|
||||
goldenPidTargetPidTuples.forEach(uniquePids::addAll);
|
||||
goldenPidTargetPidTuples.forEach(tuple -> {
|
||||
uniquePids.add(tuple.getGoldenPid());
|
||||
uniquePids.add(tuple.getSourcePid());
|
||||
});
|
||||
Map<Long, Optional<String>> pidToForcedIdMap = myIdHelperService.translatePidsToForcedIds(uniquePids);
|
||||
|
||||
Map<Long, Set<Long>> goldenResourceToSourcePidMap = new HashMap<>();
|
||||
for (List<Long> 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<>());
|
||||
|
|
|
@ -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<MdmLink, Long> {
|
|||
@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<MdmLink, Long> {
|
|||
"AND hrl.mySourcePath='Group.member.entity' " +
|
||||
"AND hrl.myTargetResourceType='Patient'" +
|
||||
")")
|
||||
List<List<Long>> expandPidsFromGroupPidGivenMatchResult(@Param("groupPid") Long theGroupPid, @Param("matchResult") MdmMatchResultEnum theMdmMatchResultEnum);
|
||||
List<MdmPidTuple> expandPidsFromGroupPidGivenMatchResult(@Param("groupPid") Long theGroupPid, @Param("matchResult") MdmMatchResultEnum theMdmMatchResultEnum);
|
||||
|
||||
interface MdmPidTuple {
|
||||
Long getGoldenPid();
|
||||
Long getSourcePid();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue