From b7bc6305002a6040ea4ba6fbe2f520cd2ebc791d Mon Sep 17 00:00:00 2001 From: Whiteiguana <63868200+Whiteiguana@users.noreply.github.com> Date: Mon, 24 Apr 2023 14:38:40 -0400 Subject: [PATCH] 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 --- ...o-golden-records-are-possible-matches.yaml | 5 +++++ .../jpa/mdm/svc/MdmLinkUpdaterSvcImpl.java | 7 +++++-- .../jpa/mdm/svc/MdmLinkUpdaterSvcImplIT.java | 21 ++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4745-one-source-record-should-create-no-match-link-with-no-errors-when-two-golden-records-are-possible-matches.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4745-one-source-record-should-create-no-match-link-with-no-errors-when-two-golden-records-are-possible-matches.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4745-one-source-record-should-create-no-match-link-with-no-errors-when-two-golden-records-are-possible-matches.yaml new file mode 100644 index 00000000000..e007b32c463 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4745-one-source-record-should-create-no-match-link-with-no-errors-when-two-golden-records-are-possible-matches.yaml @@ -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." diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImpl.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImpl.java index 132ee28000f..9e9c79a476e 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImpl.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImpl.java @@ -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; } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImplIT.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImplIT.java index 2e5650ad1ad..69060502dc0 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImplIT.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImplIT.java @@ -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 theGoldens) throws Exception { Patient patient = createPatientFromJsonInputFile(Patient_C_JSON_PATH, false);