Updated link expansion
This commit is contained in:
parent
4cfe11a221
commit
8670f107b5
|
@ -67,4 +67,13 @@ public interface IMdmLinkDao extends JpaRepository<MdmLink, Long> {
|
||||||
"AND ml.myMatchResult=:matchResult")
|
"AND ml.myMatchResult=:matchResult")
|
||||||
List<MdmPidTuple> expandPidsBySourcePidAndMatchResult(@Param("sourcePid") Long theSourcePid, @Param("matchResult") MdmMatchResultEnum theMdmMatchResultEnum);
|
List<MdmPidTuple> expandPidsBySourcePidAndMatchResult(@Param("sourcePid") Long theSourcePid, @Param("matchResult") MdmMatchResultEnum theMdmMatchResultEnum);
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT ml.myGoldenResourcePid as goldenPid, ml.mySourcePid as sourcePid " +
|
||||||
|
"FROM MdmLink ml " +
|
||||||
|
"INNER JOIN MdmLink ml2 " +
|
||||||
|
"ON ml.myGoldenResourcePid = ml2.myGoldenResourcePid " +
|
||||||
|
"WHERE (ml2.mySourcePid = :sourceOrGoldenPid OR ml2.myGoldenResourcePid = :sourceOrGoldenPid) " +
|
||||||
|
"AND ml2.myMatchResult=:matchResult " +
|
||||||
|
"AND ml.myMatchResult=:matchResult")
|
||||||
|
List<MdmPidTuple> expandPidsBySourceOrGoldenResourcePidAndMatchResult(@Param("sourceOrGoldenPid") Long theSourceOrGoldenPid, @Param("matchResult") MdmMatchResultEnum theMdmMatchResultEnum);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,19 @@ public class MdmLinkExpandSvc {
|
||||||
return expandMdmBySourceResourcePid(pidOrThrowException);
|
return expandMdmBySourceResourcePid(pidOrThrowException);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a resource ID of a source resource or golden resource, perform MDM expansion and return all the resource
|
||||||
|
* IDs of all resources that are MDM-Matched to this resource.
|
||||||
|
*
|
||||||
|
* @param theId The Resource ID of the resource to MDM-Expand
|
||||||
|
* @return A set of strings representing the FHIR ids of the expanded resources.
|
||||||
|
*/
|
||||||
|
public Set<String> expandMdmBySourceOrGoldenResourceId(IIdType theId) {
|
||||||
|
ourLog.debug("About to expand source resource with resource id {}", theId);
|
||||||
|
Long pidOrThrowException = myIdHelperService.getPidOrThrowException(theId);
|
||||||
|
return flatten(myMdmLinkDao.expandPidsBySourceOrGoldenResourcePidAndMatchResult(pidOrThrowException, MdmMatchResultEnum.MATCH));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a PID of a source resource, perform MDM expansion and return all the resource IDs of all resources that are
|
* Given a PID of a source resource, perform MDM expansion and return all the resource IDs of all resources that are
|
||||||
* MDM-Matched to this resource.
|
* MDM-Matched to this resource.
|
||||||
|
@ -81,14 +94,17 @@ public class MdmLinkExpandSvc {
|
||||||
*/
|
*/
|
||||||
public Set<String> expandMdmBySourceResourcePid(Long theSourceResourcePid) {
|
public Set<String> expandMdmBySourceResourcePid(Long theSourceResourcePid) {
|
||||||
ourLog.debug("About to expand source resource with PID {}", theSourceResourcePid);
|
ourLog.debug("About to expand source resource with PID {}", theSourceResourcePid);
|
||||||
List<IMdmLinkDao.MdmPidTuple> goldenPidSourcePidTuples = myMdmLinkDao.expandPidsBySourcePidAndMatchResult(theSourceResourcePid, MdmMatchResultEnum.MATCH);
|
return flatten(myMdmLinkDao.expandPidsBySourcePidAndMatchResult(theSourceResourcePid, MdmMatchResultEnum.MATCH));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Set<String> flatten(List<IMdmLinkDao.MdmPidTuple> thePidTuples) {
|
||||||
Set<Long> flattenedPids = new HashSet<>();
|
Set<Long> flattenedPids = new HashSet<>();
|
||||||
goldenPidSourcePidTuples.forEach(tuple -> {
|
thePidTuples.forEach(tuple -> {
|
||||||
flattenedPids.add(tuple.getSourcePid());
|
flattenedPids.add(tuple.getSourcePid());
|
||||||
flattenedPids.add(tuple.getGoldenPid());
|
flattenedPids.add(tuple.getGoldenPid());
|
||||||
});
|
});
|
||||||
Set<String> resourceIds = myIdHelperService.translatePidsToFhirResourceIds(flattenedPids);
|
Set<String> resourceIds = myIdHelperService.translatePidsToFhirResourceIds(flattenedPids);
|
||||||
ourLog.debug("Pid {} has been expanded to [{}]", theSourceResourcePid, String.join(",", resourceIds));
|
ourLog.debug("Expanded pids are [{}]", String.join(",", resourceIds));
|
||||||
return resourceIds;
|
return resourceIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,15 @@ public class MdmLinkDaoSvcTest extends BaseMdmR4Test {
|
||||||
|
|
||||||
assertThat(lists, hasSize(10));
|
assertThat(lists, hasSize(10));
|
||||||
|
|
||||||
|
lists.stream()
|
||||||
|
.forEach(tuple -> {
|
||||||
|
assertThat(tuple.getGoldenPid(), is(equalTo(golden.getIdElement().getIdPartAsLong())));
|
||||||
|
assertThat(tuple.getSourcePid(), is(in(expectedExpandedPids)));
|
||||||
|
});
|
||||||
|
|
||||||
|
lists = myMdmLinkDao.expandPidsBySourceOrGoldenResourcePidAndMatchResult(mdmLinks.get(0).getGoldenResourcePid(), MdmMatchResultEnum.MATCH);
|
||||||
|
assertThat(lists, hasSize(10));
|
||||||
|
|
||||||
lists.stream()
|
lists.stream()
|
||||||
.forEach(tuple -> {
|
.forEach(tuple -> {
|
||||||
assertThat(tuple.getGoldenPid(), is(equalTo(golden.getIdElement().getIdPartAsLong())));
|
assertThat(tuple.getGoldenPid(), is(equalTo(golden.getIdElement().getIdPartAsLong())));
|
||||||
|
|
|
@ -30,9 +30,21 @@ import java.util.Set;
|
||||||
|
|
||||||
public class MdmLinkChangeEvent implements IModelJson {
|
public class MdmLinkChangeEvent implements IModelJson {
|
||||||
|
|
||||||
@JsonProperty(value = "targetResourceId")
|
@JsonProperty(value = "matchResult")
|
||||||
|
private MdmMatchResultEnum myMdmMatchResult;
|
||||||
|
@JsonProperty(value = "linkSource")
|
||||||
|
private MdmLinkSourceEnum myMdmLinkSource;
|
||||||
|
@JsonProperty(value = "eidMatch")
|
||||||
|
private Boolean myEidMatch;
|
||||||
|
@JsonProperty(value = "newGoldenResource")
|
||||||
|
private Boolean myNewGoldenResource;
|
||||||
|
@JsonProperty(value = "score")
|
||||||
|
private Double myScore;
|
||||||
|
@JsonProperty(value = "ruleCount")
|
||||||
|
private Long myRuleCount;
|
||||||
|
@JsonProperty(value = "targetResourceId", required = true)
|
||||||
private String myTargetResourceId;
|
private String myTargetResourceId;
|
||||||
@JsonProperty(value = "goldenResourceId")
|
@JsonProperty(value = "goldenResourceId", required = true)
|
||||||
private String myGoldenResourceId;
|
private String myGoldenResourceId;
|
||||||
@JsonProperty(value = "duplicateResourceIds")
|
@JsonProperty(value = "duplicateResourceIds")
|
||||||
private Set<String> myDuplicateGoldenResourceIds = new HashSet<>();
|
private Set<String> myDuplicateGoldenResourceIds = new HashSet<>();
|
||||||
|
@ -88,10 +100,64 @@ public class MdmLinkChangeEvent implements IModelJson {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MdmMatchResultEnum getMdmMatchResult() {
|
||||||
|
return myMdmMatchResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMdmMatchResult(MdmMatchResultEnum theMdmMatchResult) {
|
||||||
|
myMdmMatchResult = theMdmMatchResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MdmLinkSourceEnum getMdmLinkSource() {
|
||||||
|
return myMdmLinkSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMdmLinkSource(MdmLinkSourceEnum theMdmLinkSource) {
|
||||||
|
myMdmLinkSource = theMdmLinkSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getEidMatch() {
|
||||||
|
return myEidMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEidMatch(Boolean theEidMatch) {
|
||||||
|
myEidMatch = theEidMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getNewGoldenResource() {
|
||||||
|
return myNewGoldenResource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewGoldenResource(Boolean theNewGoldenResource) {
|
||||||
|
myNewGoldenResource = theNewGoldenResource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getScore() {
|
||||||
|
return myScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScore(Double theScore) {
|
||||||
|
myScore = theScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getRuleCount() {
|
||||||
|
return myRuleCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRuleCount(Long theRuleCount) {
|
||||||
|
myRuleCount = theRuleCount;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "MdmLinkChangeEvent{" +
|
return "MdmLinkChangeEvent{" +
|
||||||
"myTargetResourceId='" + myTargetResourceId + '\'' +
|
"myMdmMatchResult=" + myMdmMatchResult +
|
||||||
|
", myMdmLinkSource=" + myMdmLinkSource +
|
||||||
|
", myEidMatch=" + myEidMatch +
|
||||||
|
", myNewGoldenResource=" + myNewGoldenResource +
|
||||||
|
", myScore=" + myScore +
|
||||||
|
", myRuleCount=" + myRuleCount +
|
||||||
|
", myTargetResourceId='" + myTargetResourceId + '\'' +
|
||||||
", myGoldenResourceId='" + myGoldenResourceId + '\'' +
|
", myGoldenResourceId='" + myGoldenResourceId + '\'' +
|
||||||
", myDuplicateGoldenResourceIds=" + myDuplicateGoldenResourceIds +
|
", myDuplicateGoldenResourceIds=" + myDuplicateGoldenResourceIds +
|
||||||
'}';
|
'}';
|
||||||
|
|
Loading…
Reference in New Issue