Add score to MDM links which match multiple candidates (#4329)
Co-authored-by: juan.marchionatto <juan.marchionatto@smilecdr.com>
This commit is contained in:
parent
daaa92fdbc
commit
8307264330
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
type: add
|
||||||
|
issue: 4327
|
||||||
|
title: "Before A MDM `POSSIBLE_MATCH` link generated together with a `POSSIBLE_DUPLICATE` Golden Resource was missing
|
||||||
|
the score value. this has been fixed."
|
|
@ -26,6 +26,7 @@ import ca.uhn.fhir.jpa.mdm.svc.candidate.MdmGoldenResourceFindingSvc;
|
||||||
import ca.uhn.fhir.mdm.api.IMdmLinkSvc;
|
import ca.uhn.fhir.mdm.api.IMdmLinkSvc;
|
||||||
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
|
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
|
||||||
import ca.uhn.fhir.mdm.api.MdmMatchOutcome;
|
import ca.uhn.fhir.mdm.api.MdmMatchOutcome;
|
||||||
|
import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
|
||||||
import ca.uhn.fhir.mdm.log.Logs;
|
import ca.uhn.fhir.mdm.log.Logs;
|
||||||
import ca.uhn.fhir.mdm.model.MdmTransactionContext;
|
import ca.uhn.fhir.mdm.model.MdmTransactionContext;
|
||||||
import ca.uhn.fhir.mdm.util.GoldenResourceHelper;
|
import ca.uhn.fhir.mdm.util.GoldenResourceHelper;
|
||||||
|
@ -108,7 +109,9 @@ public class MdmMatchLinkSvc {
|
||||||
for (MatchedGoldenResourceCandidate matchedGoldenResourceCandidate : theCandidateList.getCandidates()) {
|
for (MatchedGoldenResourceCandidate matchedGoldenResourceCandidate : theCandidateList.getCandidates()) {
|
||||||
IAnyResource goldenResource = myMdmGoldenResourceFindingSvc
|
IAnyResource goldenResource = myMdmGoldenResourceFindingSvc
|
||||||
.getGoldenResourceFromMatchedGoldenResourceCandidate(matchedGoldenResourceCandidate, theMdmTransactionContext.getResourceType());
|
.getGoldenResourceFromMatchedGoldenResourceCandidate(matchedGoldenResourceCandidate, theMdmTransactionContext.getResourceType());
|
||||||
MdmMatchOutcome outcome = MdmMatchOutcome.POSSIBLE_MATCH;
|
MdmMatchOutcome outcome = new MdmMatchOutcome(matchedGoldenResourceCandidate.getMatchResult().vector,
|
||||||
|
matchedGoldenResourceCandidate.getMatchResult().getNormalizedScore());
|
||||||
|
outcome.setMatchResultEnum(MdmMatchResultEnum.POSSIBLE_MATCH);
|
||||||
outcome.setEidMatch(theCandidateList.isEidMatch());
|
outcome.setEidMatch(theCandidateList.isEidMatch());
|
||||||
myMdmLinkSvc.updateLink(goldenResource, theResource, outcome, MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
|
myMdmLinkSvc.updateLink(goldenResource, theResource, outcome, MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
|
||||||
goldenResources.add(goldenResource);
|
goldenResources.add(goldenResource);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import ca.uhn.fhir.mdm.api.IMdmLinkUpdaterSvc;
|
||||||
import ca.uhn.fhir.mdm.api.MdmConstants;
|
import ca.uhn.fhir.mdm.api.MdmConstants;
|
||||||
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
|
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
|
||||||
import ca.uhn.fhir.mdm.api.MdmMatchOutcome;
|
import ca.uhn.fhir.mdm.api.MdmMatchOutcome;
|
||||||
|
import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
|
||||||
import ca.uhn.fhir.mdm.model.CanonicalEID;
|
import ca.uhn.fhir.mdm.model.CanonicalEID;
|
||||||
import ca.uhn.fhir.mdm.model.MdmTransactionContext;
|
import ca.uhn.fhir.mdm.model.MdmTransactionContext;
|
||||||
import ca.uhn.fhir.mdm.util.EIDHelper;
|
import ca.uhn.fhir.mdm.util.EIDHelper;
|
||||||
|
@ -47,6 +48,7 @@ import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
|
public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
|
||||||
|
@ -631,4 +633,36 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
|
||||||
assertThat(possibleDuplicates, hasSize(1));
|
assertThat(possibleDuplicates, hasSize(1));
|
||||||
assertThat(patient3, is(possibleDuplicateOf(patient1)));
|
assertThat(patient3, is(possibleDuplicateOf(patient1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWhen_POSSIBLE_MATCH_And_POSSIBLE_DUPLICATE_LinksCreated_ScorePopulatedOnPossibleMatchLinks() {
|
||||||
|
Patient janePatient = createPatientAndUpdateLinks(buildJanePatient());
|
||||||
|
Patient janePatient2 = createPatient(buildJanePatient());
|
||||||
|
|
||||||
|
//In a normal situation, janePatient2 would just match to jane patient, but here we need to hack it so they are their
|
||||||
|
//own individual GoldenResource for the purpose of this test.
|
||||||
|
IAnyResource goldenResource = myGoldenResourceHelper.createGoldenResourceFromMdmSourceResource(janePatient2,
|
||||||
|
new MdmTransactionContext(MdmTransactionContext.OperationType.CREATE_RESOURCE));
|
||||||
|
myMdmLinkSvc.updateLink(goldenResource, janePatient2, MdmMatchOutcome.NEW_GOLDEN_RESOURCE_MATCH,
|
||||||
|
MdmLinkSourceEnum.AUTO, createContextForCreate("Patient"));
|
||||||
|
assertThat(janePatient, is(not(sameGoldenResourceAs(janePatient2))));
|
||||||
|
|
||||||
|
//In theory, this will match both GoldenResources!
|
||||||
|
Patient incomingJanePatient = createPatientAndUpdateLinks(buildJanePatient());
|
||||||
|
|
||||||
|
//There should now be a single POSSIBLE_DUPLICATE link with
|
||||||
|
assertThat(janePatient, is(possibleDuplicateOf(janePatient2)));
|
||||||
|
|
||||||
|
//There should now be 2 POSSIBLE_MATCH links with this goldenResource.
|
||||||
|
assertThat(incomingJanePatient, is(possibleMatchWith(janePatient, janePatient2)));
|
||||||
|
|
||||||
|
// Ensure both links are POSSIBLE_MATCH and both have a score value
|
||||||
|
List<? extends IMdmLink> janetPatientLinks = runInTransaction(() -> myMdmLinkDaoSvc.findMdmLinksBySourceResource(incomingJanePatient));
|
||||||
|
assertEquals(2, janetPatientLinks.size());
|
||||||
|
janetPatientLinks.forEach( l -> {
|
||||||
|
assertEquals(MdmMatchResultEnum.POSSIBLE_MATCH, l.getMatchResult());
|
||||||
|
assertNotNull(l.getScore());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue