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);
|
IBaseExtension<?, ?> extension = ExtensionUtil.getOrCreateExtension(iBaseResource, HapiExtensions.ASSOCIATED_GOLDEN_RESOURCE_EXTENSION_URL);
|
||||||
if (!StringUtils.isBlank(goldenResourceId)) {
|
if (!StringUtils.isBlank(goldenResourceId)) {
|
||||||
ExtensionUtil.setExtension(myContext, extension, "reference", prefixPatient(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) {
|
if (myMdmEnabled) {
|
||||||
IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId));
|
IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId));
|
||||||
Long pidOrNull = myIdHelperService.getPidOrNull(group);
|
Long pidOrNull = myIdHelperService.getPidOrNull(group);
|
||||||
List<List<Long>> goldenPidSourcePidTuple = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH);
|
List<IMdmLinkDao.MdmPidTuple> goldenPidSourcePidTuple = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH);
|
||||||
goldenPidSourcePidTuple.forEach(patientPidsToExport::addAll);
|
goldenPidSourcePidTuple.forEach(tuple -> {
|
||||||
|
patientPidsToExport.add(tuple.getGoldenPid());
|
||||||
|
patientPidsToExport.add(tuple.getSourcePid());
|
||||||
|
});
|
||||||
populateMdmResourceCache(goldenPidSourcePidTuple);
|
populateMdmResourceCache(goldenPidSourcePidTuple);
|
||||||
}
|
}
|
||||||
List<ResourcePersistentId> resourcePersistentIds = patientPidsToExport
|
List<ResourcePersistentId> resourcePersistentIds = patientPidsToExport
|
||||||
|
@ -134,7 +137,7 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade
|
||||||
/**
|
/**
|
||||||
* @param thePidTuples
|
* @param thePidTuples
|
||||||
*/
|
*/
|
||||||
private void populateMdmResourceCache(List<List<Long>> thePidTuples) {
|
private void populateMdmResourceCache(List<IMdmLinkDao.MdmPidTuple> thePidTuples) {
|
||||||
if (myMdmExpansionCacheSvc.hasBeenPopulated()) {
|
if (myMdmExpansionCacheSvc.hasBeenPopulated()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -144,9 +147,9 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade
|
||||||
// patient/gold-2 -> [patient/3, patient/4]
|
// patient/gold-2 -> [patient/3, patient/4]
|
||||||
//}
|
//}
|
||||||
Map<Long, Set<Long>> goldenResourceToSourcePidMap = new HashMap<>();
|
Map<Long, Set<Long>> goldenResourceToSourcePidMap = new HashMap<>();
|
||||||
for (List<Long> goldenPidTargetPidTuple : thePidTuples) {
|
for (IMdmLinkDao.MdmPidTuple goldenPidTargetPidTuple : thePidTuples) {
|
||||||
Long goldenPid = goldenPidTargetPidTuple.get(0);
|
Long goldenPid = goldenPidTargetPidTuple.getGoldenPid();
|
||||||
Long sourcePid = goldenPidTargetPidTuple.get(1);
|
Long sourcePid = goldenPidTargetPidTuple.getSourcePid();
|
||||||
|
|
||||||
if(!goldenResourceToSourcePidMap.containsKey(goldenPid)) {
|
if(!goldenResourceToSourcePidMap.containsKey(goldenPid)) {
|
||||||
goldenResourceToSourcePidMap.put(goldenPid, new HashSet<>());
|
goldenResourceToSourcePidMap.put(goldenPid, new HashSet<>());
|
||||||
|
@ -204,16 +207,19 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade
|
||||||
|
|
||||||
//Attempt to perform MDM Expansion of membership
|
//Attempt to perform MDM Expansion of membership
|
||||||
if (myMdmEnabled) {
|
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
|
//Now lets translate these pids into resource IDs
|
||||||
Set<Long> uniquePids = new HashSet<>();
|
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, Optional<String>> pidToForcedIdMap = myIdHelperService.translatePidsToForcedIds(uniquePids);
|
||||||
|
|
||||||
Map<Long, Set<Long>> goldenResourceToSourcePidMap = new HashMap<>();
|
Map<Long, Set<Long>> goldenResourceToSourcePidMap = new HashMap<>();
|
||||||
for (List<Long> goldenPidTargetPidTuple : goldenPidTargetPidTuples) {
|
for (IMdmLinkDao.MdmPidTuple goldenPidTargetPidTuple : goldenPidTargetPidTuples) {
|
||||||
Long goldenPid = goldenPidTargetPidTuple.get(0);
|
Long goldenPid = goldenPidTargetPidTuple.getGoldenPid();
|
||||||
Long sourcePid = goldenPidTargetPidTuple.get(1);
|
Long sourcePid = goldenPidTargetPidTuple.getSourcePid();
|
||||||
|
|
||||||
if(!goldenResourceToSourcePidMap.containsKey(goldenPid)) {
|
if(!goldenResourceToSourcePidMap.containsKey(goldenPid)) {
|
||||||
goldenResourceToSourcePidMap.put(goldenPid, new HashSet<>());
|
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.mdm.api.MdmMatchResultEnum;
|
||||||
import ca.uhn.fhir.jpa.entity.MdmLink;
|
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.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Modifying;
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
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")
|
@Query("DELETE FROM MdmLink f WHERE (myGoldenResourcePid = :pid OR mySourcePid = :pid) AND myMatchResult <> :matchResult")
|
||||||
int deleteWithAnyReferenceToPidAndMatchResultNot(@Param("pid") Long thePid, @Param("matchResult") MdmMatchResultEnum theMatchResult);
|
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 " +
|
"WHERE ml2.myMatchResult=:matchResult " +
|
||||||
"AND ml2.myGoldenResourcePid IN (" +
|
"AND ml2.myGoldenResourcePid IN (" +
|
||||||
"SELECT ml.myGoldenResourcePid FROM MdmLink ml " +
|
"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.mySourcePath='Group.member.entity' " +
|
||||||
"AND hrl.myTargetResourceType='Patient'" +
|
"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