From 4e012236c21e3614bc2615ffed7bfe67c9c5ea01 Mon Sep 17 00:00:00 2001 From: Nick Goupinets Date: Fri, 27 Aug 2021 16:31:23 -0400 Subject: [PATCH] Updated comments and added misc refactorings --- .../fhir/jpa/mdm/broker/MdmMessageHandler.java | 4 ++-- .../fhir/jpa/mdm/svc/MdmEidUpdateService.java | 2 +- .../uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvc.java | 12 ++++++------ .../candidate/FindCandidateByExampleSvc.java | 10 +++++----- .../ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java | 4 ++-- .../interceptor/MdmStorageInterceptorIT.java | 18 ++++++++++++------ .../fhir/mdm/model/MdmTransactionContext.java | 2 +- 7 files changed, 29 insertions(+), 23 deletions(-) diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/broker/MdmMessageHandler.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/broker/MdmMessageHandler.java index 701f00b034b..6589d6b41e9 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/broker/MdmMessageHandler.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/broker/MdmMessageHandler.java @@ -119,7 +119,7 @@ public class MdmMessageHandler implements MessageHandler { ResourceOperationMessage outgoingMsg = new ResourceOperationMessage(myFhirContext, targetResource, theMsg.getOperationType()); outgoingMsg.setTransactionId(theMsg.getTransactionId()); - MdmLinkEvent linkChangeEvent = mdmContext.getMdmLinkChangeEvent(); + MdmLinkEvent linkChangeEvent = mdmContext.getMdmLinkEvent(); Optional mdmLinkBySource = myMdmLinkDaoSvc.findMdmLinkBySource(targetResource); if (!mdmLinkBySource.isPresent()) { ourLog.warn("Unable to find link by source for {}", targetResource.getIdElement()); @@ -129,7 +129,7 @@ public class MdmMessageHandler implements MessageHandler { HookParams params = new HookParams() .add(ResourceOperationMessage.class, outgoingMsg) .add(TransactionLogMessages.class, mdmContext.getTransactionLogMessages()) - .add(MdmLinkEvent.class, mdmContext.getMdmLinkChangeEvent()); + .add(MdmLinkEvent.class, mdmContext.getMdmLinkEvent()); myInterceptorBroadcaster.callHooks(Pointcut.MDM_AFTER_PERSISTED_RESOURCE_CHECKED, params); } diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmEidUpdateService.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmEidUpdateService.java index d23c27db9f1..2e035615200 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmEidUpdateService.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmEidUpdateService.java @@ -86,7 +86,7 @@ public class MdmEidUpdateService { myMdmResourceDaoSvc.upsertGoldenResource(updateContext.getMatchedGoldenResource(), theMdmTransactionContext.getResourceType()); } - theMdmTransactionContext.getMdmLinkChangeEvent().setGoldenResourceId(updateContext.getExistingGoldenResource()); + theMdmTransactionContext.getMdmLinkEvent().setGoldenResourceId(updateContext.getExistingGoldenResource()); } private void handleNoEidsInCommon(IAnyResource theResource, MatchedGoldenResourceCandidate theMatchedGoldenResourceCandidate, MdmTransactionContext theMdmTransactionContext, MdmUpdateContext theUpdateContext) { diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvc.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvc.java index e0f6b932557..ce285b58bac 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvc.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvc.java @@ -78,7 +78,7 @@ public class MdmMatchLinkSvc { private MdmTransactionContext doMdmUpdate(IAnyResource theResource, MdmTransactionContext theMdmTransactionContext) { CandidateList candidateList = myMdmGoldenResourceFindingSvc.findGoldenResourceCandidates(theResource); - theMdmTransactionContext.getMdmLinkChangeEvent().setTargetResourceId(theResource); + theMdmTransactionContext.getMdmLinkEvent().setTargetResourceId(theResource); if (candidateList.isEmpty()) { handleMdmWithNoCandidates(theResource, theMdmTransactionContext); @@ -114,14 +114,14 @@ public class MdmMatchLinkSvc { //Set all GoldenResources as POSSIBLE_DUPLICATE of the last GoldenResource. IAnyResource firstGoldenResource = goldenResources.get(0); - theMdmTransactionContext.getMdmLinkChangeEvent().setGoldenResourceId(firstGoldenResource); + theMdmTransactionContext.getMdmLinkEvent().setGoldenResourceId(firstGoldenResource); goldenResources.subList(1, goldenResources.size()) .forEach(possibleDuplicateGoldenResource -> { MdmMatchOutcome outcome = MdmMatchOutcome.POSSIBLE_DUPLICATE; outcome.setEidMatch(theCandidateList.isEidMatch()); myMdmLinkSvc.updateLink(firstGoldenResource, possibleDuplicateGoldenResource, outcome, MdmLinkSourceEnum.AUTO, theMdmTransactionContext); - theMdmTransactionContext.getMdmLinkChangeEvent().addDuplicateGoldenResourceId(possibleDuplicateGoldenResource); + theMdmTransactionContext.getMdmLinkEvent().addDuplicateGoldenResourceId(possibleDuplicateGoldenResource); }); } } @@ -135,7 +135,7 @@ public class MdmMatchLinkSvc { // 3. UPDATE MDM LINK TABLE myMdmLinkSvc.updateLink(newGoldenResource, theResource, MdmMatchOutcome.NEW_GOLDEN_RESOURCE_MATCH, MdmLinkSourceEnum.AUTO, theMdmTransactionContext); - theMdmTransactionContext.getMdmLinkChangeEvent().setGoldenResourceId(newGoldenResource); + theMdmTransactionContext.getMdmLinkEvent().setGoldenResourceId(newGoldenResource); } private void handleMdmCreate(IAnyResource theTargetResource, MatchedGoldenResourceCandidate theGoldenResourceCandidate, MdmTransactionContext theMdmTransactionContext) { @@ -145,7 +145,7 @@ public class MdmMatchLinkSvc { if (myGoldenResourceHelper.isPotentialDuplicate(goldenResource, theTargetResource)) { log(theMdmTransactionContext, "Duplicate detected based on the fact that both resources have different external EIDs."); IAnyResource newGoldenResource = myGoldenResourceHelper.createGoldenResourceFromMdmSourceResource(theTargetResource, theMdmTransactionContext); - theMdmTransactionContext.getMdmLinkChangeEvent().setGoldenResourceId(newGoldenResource); + theMdmTransactionContext.getMdmLinkEvent().setGoldenResourceId(newGoldenResource); myMdmLinkSvc.updateLink(newGoldenResource, theTargetResource, MdmMatchOutcome.NEW_GOLDEN_RESOURCE_MATCH, MdmLinkSourceEnum.AUTO, theMdmTransactionContext); myMdmLinkSvc.updateLink(newGoldenResource, goldenResource, MdmMatchOutcome.POSSIBLE_DUPLICATE, MdmLinkSourceEnum.AUTO, theMdmTransactionContext); @@ -155,7 +155,7 @@ public class MdmMatchLinkSvc { myEidUpdateService.applySurvivorshipRulesAndSaveGoldenResource(theTargetResource, goldenResource, theMdmTransactionContext); } - theMdmTransactionContext.getMdmLinkChangeEvent().setGoldenResourceId(goldenResource); + theMdmTransactionContext.getMdmLinkEvent().setGoldenResourceId(goldenResource); myMdmLinkSvc.updateLink(goldenResource, theTargetResource, theGoldenResourceCandidate.getMatchResult(), MdmLinkSourceEnum.AUTO, theMdmTransactionContext); } } diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByExampleSvc.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByExampleSvc.java index 43606a95818..5533c82667b 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByExampleSvc.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByExampleSvc.java @@ -54,9 +54,9 @@ public class FindCandidateByExampleSvc extends BaseCandidateFinder { private IMdmMatchFinderSvc myMdmMatchFinderSvc; /** - * Attempt to find matching Golden Resources by resolving them from similar Matching target resources, where target resource - * can be either Patient or Practitioner. Runs MDM logic over the existing target resources, then finds their - * entries in the MdmLink table, and returns all the matches found therein. + * Attempt to find matching Golden Resources by resolving them from similar Matching target resources. Runs MDM logic + * over the existing target resources, then finds their entries in the MdmLink table, and returns all the matches + * found therein. * * @param theTarget the {@link IBaseResource} which we want to find candidate Golden Resources for. * @return an Optional list of {@link MatchedGoldenResourceCandidate} indicating matches. @@ -69,8 +69,8 @@ public class FindCandidateByExampleSvc extends BaseCandidateFinder { List matchedCandidates = myMdmMatchFinderSvc.getMatchedTargets(myFhirContext.getResourceType(theTarget), theTarget); - //Convert all possible match targets to their equivalent Golden Resources by looking up in the MdmLink table, - //while ensuring that the matches aren't in our NO_MATCH list. + // Convert all possible match targets to their equivalent Golden Resources by looking up in the MdmLink table, + // while ensuring that the matches aren't in our NO_MATCH list. // The data flow is as follows -> // MatchedTargetCandidate -> Golden Resource -> MdmLink -> MatchedGoldenResourceCandidate matchedCandidates = matchedCandidates.stream().filter(mc -> mc.isMatch() || mc.isPossibleMatch()).collect(Collectors.toList()); diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java index 96115a95bf2..60936356c54 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java @@ -326,14 +326,14 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test { assertEquals(theExpectedCount, myMdmLinkDao.count()); } - protected IAnyResource getGoldenResourceFromTargetResource(IAnyResource theBaseResource) { + protected T getGoldenResourceFromTargetResource(T theBaseResource) { String resourceType = theBaseResource.getIdElement().getResourceType(); IFhirResourceDao relevantDao = myDaoRegistry.getResourceDao(resourceType); Optional matchedLinkForTargetPid = myMdmLinkDaoSvc.getMatchedLinkForSourcePid(myIdHelperService.getPidOrNull(theBaseResource)); if (matchedLinkForTargetPid.isPresent()) { Long goldenResourcePid = matchedLinkForTargetPid.get().getGoldenResourcePid(); - return (IAnyResource) relevantDao.readByPid(new ResourcePersistentId(goldenResourcePid)); + return (T) relevantDao.readByPid(new ResourcePersistentId(goldenResourcePid)); } else { return null; } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java index cd1518cbc59..330e1380bef 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java @@ -6,8 +6,12 @@ import ca.uhn.fhir.jpa.entity.MdmLink; import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test; import ca.uhn.fhir.jpa.mdm.helper.MdmHelperConfig; import ca.uhn.fhir.jpa.mdm.helper.MdmHelperR4; +import ca.uhn.fhir.jpa.mdm.svc.MdmLinkSvcImpl; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.mdm.api.IMdmLinkSvc; import ca.uhn.fhir.mdm.api.MdmLinkEvent; +import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum; +import ca.uhn.fhir.mdm.api.MdmMatchOutcome; import ca.uhn.fhir.mdm.model.CanonicalEID; import ca.uhn.fhir.mdm.model.MdmTransactionContext; import ca.uhn.fhir.mdm.rules.config.MdmSettings; @@ -68,6 +72,8 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { public MdmHelperR4 myMdmHelper; @Autowired private IdHelperService myIdHelperService; + @Autowired + private IMdmLinkSvc myMdmLinkSvc; @Test public void testCreatePractitioner() throws InterruptedException { @@ -105,17 +111,17 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { MdmTransactionContext ctx = createContextForCreate("Patient"); myMdmMatchLinkSvc.updateMdmLinksForMdmSource(patient1, ctx); - ourLog.info(ctx.getMdmLinkChangeEvent().toString()); - assertEquals(patient1.getIdElement().getValue(), ctx.getMdmLinkChangeEvent().getTargetResourceId()); - assertEquals(getLinkByTargetId(patient1).getGoldenResourcePid(), new IdDt(ctx.getMdmLinkChangeEvent().getGoldenResourceId()).getIdPartAsLong()); + ourLog.info(ctx.getMdmLinkEvent().toString()); + assertEquals(patient1.getIdElement().getValue(), ctx.getMdmLinkEvent().getTargetResourceId()); + assertEquals(getLinkByTargetId(patient1).getGoldenResourcePid(), new IdDt(ctx.getMdmLinkEvent().getGoldenResourceId()).getIdPartAsLong()); Patient patient2 = addExternalEID(buildJanePatient(), "eid-2"); myMdmHelper.createWithLatch(patient2); ctx = createContextForCreate("Patient"); myMdmMatchLinkSvc.updateMdmLinksForMdmSource(patient2, ctx); - ourLog.info(ctx.getMdmLinkChangeEvent().toString()); - assertEquals(patient2.getIdElement().getValue(), ctx.getMdmLinkChangeEvent().getTargetResourceId()); - assertEquals(getLinkByTargetId(patient2).getGoldenResourcePid(), new IdDt(ctx.getMdmLinkChangeEvent().getGoldenResourceId()).getIdPartAsLong()); + ourLog.info(ctx.getMdmLinkEvent().toString()); + assertEquals(patient2.getIdElement().getValue(), ctx.getMdmLinkEvent().getTargetResourceId()); + assertEquals(getLinkByTargetId(patient2).getGoldenResourcePid(), new IdDt(ctx.getMdmLinkEvent().getGoldenResourceId()).getIdPartAsLong()); } @Test diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmTransactionContext.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmTransactionContext.java index 9853918a9d7..4f13e7ac706 100644 --- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmTransactionContext.java +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmTransactionContext.java @@ -96,7 +96,7 @@ public class MdmTransactionContext { this.myResourceType = myResourceType; } - public MdmLinkEvent getMdmLinkChangeEvent() { + public MdmLinkEvent getMdmLinkEvent() { return myMdmLinkEvent; }