4745 one source record should create no match link with no errors when two golden records are possible matches (#4765)

* created failing test for issue

* remove unused code from IT

* Fixed an issue where marking a golden resource as no match would fail.

---------

Co-authored-by: Steven Li <steven@smilecdr.com>
This commit is contained in:
Whiteiguana 2023-04-24 14:38:40 -04:00 committed by GitHub
parent 9670150f20
commit b7bc630500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 4745
title: "Fixed an issue where a golden resource could not be chosen as no-match when another golden resource
was already chosen as a match."

View File

@ -118,8 +118,11 @@ public class MdmLinkUpdaterSvcImpl implements IMdmLinkUpdaterSvc {
myMdmResourceDaoSvc.upsertGoldenResource(theGoldenResource, theMdmContext.getResourceType());
if (theMatchResult == MdmMatchResultEnum.NO_MATCH) {
// Need to find a new Golden Resource to link this target to
myMdmMatchLinkSvc.updateMdmLinksForMdmSource(theSourceResource, theMdmContext);
// We need to return no match for when a Golden Resource has already been found elsewhere
if (myMdmLinkDaoSvc.getMdmLinksBySourcePidAndMatchResult(sourceResourceId, MdmMatchResultEnum.MATCH).isEmpty()) {
// Need to find a new Golden Resource to link this target to
myMdmMatchLinkSvc.updateMdmLinksForMdmSource(theSourceResource, theMdmContext);
}
}
return theGoldenResource;
}

View File

@ -3,7 +3,6 @@ package ca.uhn.fhir.jpa.mdm.svc;
import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.mdm.api.IMdmLink;
import ca.uhn.fhir.mdm.api.IMdmLinkUpdaterSvc;
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
@ -11,6 +10,7 @@ import ca.uhn.fhir.mdm.api.MdmMatchOutcome;
import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
import ca.uhn.fhir.mdm.model.MdmTransactionContext;
import ca.uhn.fhir.mdm.util.MessageHelper;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.Test;
@ -72,7 +72,26 @@ class MdmLinkUpdaterSvcImplIT extends BaseMdmR4Test {
assertEquals(expectedExceptionMessage, thrown.getMessage());
}
@Test
void testUpdateLinkToNoMatchWhenAnotherLinkToDifferentGoldenExistsShouldNotFail() throws Exception {
// create Patient A -> MATCH GR A
Patient patientA = createPatientFromJsonInputFile(Patient_A_JSON_PATH);
// create Patient B -> MATCH GR B
Patient patientB = createPatientFromJsonInputFile(Patient_B_JSON_PATH);
Patient goldenA = getGoldenFor(patientA);
Patient goldenB = getGoldenFor(patientB);
// create Patient C -> no MATCH link. Only POSSIBLE_MATCH GR A and POSSIBLE_MATCH GR B
Patient patientC = createPatientFromJsonInputFileWithPossibleMatches( List.of(goldenA, goldenB) );
MdmTransactionContext mdmTransactionContext = getPatientUpdateLinkContext();
// update POSSIBLE_MATCH Patient C -> GR A to MATCH (should work OK)
myMdmLinkUpdaterSvc.updateLink(goldenA, patientC, MdmMatchResultEnum.MATCH, mdmTransactionContext);
// update POSSIBLE_MATCH Patient C -> GR B to NO_MATCH (should work OK)
myMdmLinkUpdaterSvc.updateLink(goldenB, patientC, MdmMatchResultEnum.NO_MATCH, mdmTransactionContext);
}
private Patient createPatientFromJsonInputFileWithPossibleMatches(List<Patient> theGoldens) throws Exception {
Patient patient = createPatientFromJsonInputFile(Patient_C_JSON_PATH, false);