Updated comments and added misc refactorings

This commit is contained in:
Nick Goupinets 2021-08-27 16:31:23 -04:00
parent 91a961f9fd
commit 4e012236c2
7 changed files with 29 additions and 23 deletions

View File

@ -119,7 +119,7 @@ public class MdmMessageHandler implements MessageHandler {
ResourceOperationMessage outgoingMsg = new ResourceOperationMessage(myFhirContext, targetResource, theMsg.getOperationType()); ResourceOperationMessage outgoingMsg = new ResourceOperationMessage(myFhirContext, targetResource, theMsg.getOperationType());
outgoingMsg.setTransactionId(theMsg.getTransactionId()); outgoingMsg.setTransactionId(theMsg.getTransactionId());
MdmLinkEvent linkChangeEvent = mdmContext.getMdmLinkChangeEvent(); MdmLinkEvent linkChangeEvent = mdmContext.getMdmLinkEvent();
Optional<MdmLink> mdmLinkBySource = myMdmLinkDaoSvc.findMdmLinkBySource(targetResource); Optional<MdmLink> mdmLinkBySource = myMdmLinkDaoSvc.findMdmLinkBySource(targetResource);
if (!mdmLinkBySource.isPresent()) { if (!mdmLinkBySource.isPresent()) {
ourLog.warn("Unable to find link by source for {}", targetResource.getIdElement()); ourLog.warn("Unable to find link by source for {}", targetResource.getIdElement());
@ -129,7 +129,7 @@ public class MdmMessageHandler implements MessageHandler {
HookParams params = new HookParams() HookParams params = new HookParams()
.add(ResourceOperationMessage.class, outgoingMsg) .add(ResourceOperationMessage.class, outgoingMsg)
.add(TransactionLogMessages.class, mdmContext.getTransactionLogMessages()) .add(TransactionLogMessages.class, mdmContext.getTransactionLogMessages())
.add(MdmLinkEvent.class, mdmContext.getMdmLinkChangeEvent()); .add(MdmLinkEvent.class, mdmContext.getMdmLinkEvent());
myInterceptorBroadcaster.callHooks(Pointcut.MDM_AFTER_PERSISTED_RESOURCE_CHECKED, params); myInterceptorBroadcaster.callHooks(Pointcut.MDM_AFTER_PERSISTED_RESOURCE_CHECKED, params);
} }

View File

@ -86,7 +86,7 @@ public class MdmEidUpdateService {
myMdmResourceDaoSvc.upsertGoldenResource(updateContext.getMatchedGoldenResource(), theMdmTransactionContext.getResourceType()); 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) { private void handleNoEidsInCommon(IAnyResource theResource, MatchedGoldenResourceCandidate theMatchedGoldenResourceCandidate, MdmTransactionContext theMdmTransactionContext, MdmUpdateContext theUpdateContext) {

View File

@ -78,7 +78,7 @@ public class MdmMatchLinkSvc {
private MdmTransactionContext doMdmUpdate(IAnyResource theResource, MdmTransactionContext theMdmTransactionContext) { private MdmTransactionContext doMdmUpdate(IAnyResource theResource, MdmTransactionContext theMdmTransactionContext) {
CandidateList candidateList = myMdmGoldenResourceFindingSvc.findGoldenResourceCandidates(theResource); CandidateList candidateList = myMdmGoldenResourceFindingSvc.findGoldenResourceCandidates(theResource);
theMdmTransactionContext.getMdmLinkChangeEvent().setTargetResourceId(theResource); theMdmTransactionContext.getMdmLinkEvent().setTargetResourceId(theResource);
if (candidateList.isEmpty()) { if (candidateList.isEmpty()) {
handleMdmWithNoCandidates(theResource, theMdmTransactionContext); handleMdmWithNoCandidates(theResource, theMdmTransactionContext);
@ -114,14 +114,14 @@ public class MdmMatchLinkSvc {
//Set all GoldenResources as POSSIBLE_DUPLICATE of the last GoldenResource. //Set all GoldenResources as POSSIBLE_DUPLICATE of the last GoldenResource.
IAnyResource firstGoldenResource = goldenResources.get(0); IAnyResource firstGoldenResource = goldenResources.get(0);
theMdmTransactionContext.getMdmLinkChangeEvent().setGoldenResourceId(firstGoldenResource); theMdmTransactionContext.getMdmLinkEvent().setGoldenResourceId(firstGoldenResource);
goldenResources.subList(1, goldenResources.size()) goldenResources.subList(1, goldenResources.size())
.forEach(possibleDuplicateGoldenResource -> { .forEach(possibleDuplicateGoldenResource -> {
MdmMatchOutcome outcome = MdmMatchOutcome.POSSIBLE_DUPLICATE; MdmMatchOutcome outcome = MdmMatchOutcome.POSSIBLE_DUPLICATE;
outcome.setEidMatch(theCandidateList.isEidMatch()); outcome.setEidMatch(theCandidateList.isEidMatch());
myMdmLinkSvc.updateLink(firstGoldenResource, possibleDuplicateGoldenResource, outcome, MdmLinkSourceEnum.AUTO, theMdmTransactionContext); 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 // 3. UPDATE MDM LINK TABLE
myMdmLinkSvc.updateLink(newGoldenResource, theResource, MdmMatchOutcome.NEW_GOLDEN_RESOURCE_MATCH, MdmLinkSourceEnum.AUTO, theMdmTransactionContext); 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) { private void handleMdmCreate(IAnyResource theTargetResource, MatchedGoldenResourceCandidate theGoldenResourceCandidate, MdmTransactionContext theMdmTransactionContext) {
@ -145,7 +145,7 @@ public class MdmMatchLinkSvc {
if (myGoldenResourceHelper.isPotentialDuplicate(goldenResource, theTargetResource)) { if (myGoldenResourceHelper.isPotentialDuplicate(goldenResource, theTargetResource)) {
log(theMdmTransactionContext, "Duplicate detected based on the fact that both resources have different external EIDs."); log(theMdmTransactionContext, "Duplicate detected based on the fact that both resources have different external EIDs.");
IAnyResource newGoldenResource = myGoldenResourceHelper.createGoldenResourceFromMdmSourceResource(theTargetResource, theMdmTransactionContext); 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, theTargetResource, MdmMatchOutcome.NEW_GOLDEN_RESOURCE_MATCH, MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
myMdmLinkSvc.updateLink(newGoldenResource, goldenResource, MdmMatchOutcome.POSSIBLE_DUPLICATE, 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); myEidUpdateService.applySurvivorshipRulesAndSaveGoldenResource(theTargetResource, goldenResource, theMdmTransactionContext);
} }
theMdmTransactionContext.getMdmLinkChangeEvent().setGoldenResourceId(goldenResource); theMdmTransactionContext.getMdmLinkEvent().setGoldenResourceId(goldenResource);
myMdmLinkSvc.updateLink(goldenResource, theTargetResource, theGoldenResourceCandidate.getMatchResult(), MdmLinkSourceEnum.AUTO, theMdmTransactionContext); myMdmLinkSvc.updateLink(goldenResource, theTargetResource, theGoldenResourceCandidate.getMatchResult(), MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
} }
} }

View File

@ -54,9 +54,9 @@ public class FindCandidateByExampleSvc extends BaseCandidateFinder {
private IMdmMatchFinderSvc myMdmMatchFinderSvc; private IMdmMatchFinderSvc myMdmMatchFinderSvc;
/** /**
* Attempt to find matching Golden Resources by resolving them from similar Matching target resources, where target resource * Attempt to find matching Golden Resources by resolving them from similar Matching target resources. Runs MDM logic
* can be either Patient or Practitioner. Runs MDM logic over the existing target resources, then finds their * over the existing target resources, then finds their entries in the MdmLink table, and returns all the matches
* entries in the MdmLink table, and returns all the matches found therein. * found therein.
* *
* @param theTarget the {@link IBaseResource} which we want to find candidate Golden Resources for. * @param theTarget the {@link IBaseResource} which we want to find candidate Golden Resources for.
* @return an Optional list of {@link MatchedGoldenResourceCandidate} indicating matches. * @return an Optional list of {@link MatchedGoldenResourceCandidate} indicating matches.
@ -69,8 +69,8 @@ public class FindCandidateByExampleSvc extends BaseCandidateFinder {
List<MatchedTarget> matchedCandidates = myMdmMatchFinderSvc.getMatchedTargets(myFhirContext.getResourceType(theTarget), theTarget); List<MatchedTarget> matchedCandidates = myMdmMatchFinderSvc.getMatchedTargets(myFhirContext.getResourceType(theTarget), theTarget);
//Convert all possible match targets to their equivalent Golden Resources by looking up in the MdmLink table, // 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. // while ensuring that the matches aren't in our NO_MATCH list.
// The data flow is as follows -> // The data flow is as follows ->
// MatchedTargetCandidate -> Golden Resource -> MdmLink -> MatchedGoldenResourceCandidate // MatchedTargetCandidate -> Golden Resource -> MdmLink -> MatchedGoldenResourceCandidate
matchedCandidates = matchedCandidates.stream().filter(mc -> mc.isMatch() || mc.isPossibleMatch()).collect(Collectors.toList()); matchedCandidates = matchedCandidates.stream().filter(mc -> mc.isMatch() || mc.isPossibleMatch()).collect(Collectors.toList());

View File

@ -326,14 +326,14 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test {
assertEquals(theExpectedCount, myMdmLinkDao.count()); assertEquals(theExpectedCount, myMdmLinkDao.count());
} }
protected IAnyResource getGoldenResourceFromTargetResource(IAnyResource theBaseResource) { protected <T extends IAnyResource> T getGoldenResourceFromTargetResource(T theBaseResource) {
String resourceType = theBaseResource.getIdElement().getResourceType(); String resourceType = theBaseResource.getIdElement().getResourceType();
IFhirResourceDao relevantDao = myDaoRegistry.getResourceDao(resourceType); IFhirResourceDao relevantDao = myDaoRegistry.getResourceDao(resourceType);
Optional<MdmLink> matchedLinkForTargetPid = myMdmLinkDaoSvc.getMatchedLinkForSourcePid(myIdHelperService.getPidOrNull(theBaseResource)); Optional<MdmLink> matchedLinkForTargetPid = myMdmLinkDaoSvc.getMatchedLinkForSourcePid(myIdHelperService.getPidOrNull(theBaseResource));
if (matchedLinkForTargetPid.isPresent()) { if (matchedLinkForTargetPid.isPresent()) {
Long goldenResourcePid = matchedLinkForTargetPid.get().getGoldenResourcePid(); Long goldenResourcePid = matchedLinkForTargetPid.get().getGoldenResourcePid();
return (IAnyResource) relevantDao.readByPid(new ResourcePersistentId(goldenResourcePid)); return (T) relevantDao.readByPid(new ResourcePersistentId(goldenResourcePid));
} else { } else {
return null; return null;
} }

View File

@ -6,8 +6,12 @@ import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test; import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test;
import ca.uhn.fhir.jpa.mdm.helper.MdmHelperConfig; import ca.uhn.fhir.jpa.mdm.helper.MdmHelperConfig;
import ca.uhn.fhir.jpa.mdm.helper.MdmHelperR4; 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.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.mdm.api.IMdmLinkSvc;
import ca.uhn.fhir.mdm.api.MdmLinkEvent; 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.CanonicalEID;
import ca.uhn.fhir.mdm.model.MdmTransactionContext; import ca.uhn.fhir.mdm.model.MdmTransactionContext;
import ca.uhn.fhir.mdm.rules.config.MdmSettings; import ca.uhn.fhir.mdm.rules.config.MdmSettings;
@ -68,6 +72,8 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test {
public MdmHelperR4 myMdmHelper; public MdmHelperR4 myMdmHelper;
@Autowired @Autowired
private IdHelperService myIdHelperService; private IdHelperService myIdHelperService;
@Autowired
private IMdmLinkSvc myMdmLinkSvc;
@Test @Test
public void testCreatePractitioner() throws InterruptedException { public void testCreatePractitioner() throws InterruptedException {
@ -105,17 +111,17 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test {
MdmTransactionContext ctx = createContextForCreate("Patient"); MdmTransactionContext ctx = createContextForCreate("Patient");
myMdmMatchLinkSvc.updateMdmLinksForMdmSource(patient1, ctx); myMdmMatchLinkSvc.updateMdmLinksForMdmSource(patient1, ctx);
ourLog.info(ctx.getMdmLinkChangeEvent().toString()); ourLog.info(ctx.getMdmLinkEvent().toString());
assertEquals(patient1.getIdElement().getValue(), ctx.getMdmLinkChangeEvent().getTargetResourceId()); assertEquals(patient1.getIdElement().getValue(), ctx.getMdmLinkEvent().getTargetResourceId());
assertEquals(getLinkByTargetId(patient1).getGoldenResourcePid(), new IdDt(ctx.getMdmLinkChangeEvent().getGoldenResourceId()).getIdPartAsLong()); assertEquals(getLinkByTargetId(patient1).getGoldenResourcePid(), new IdDt(ctx.getMdmLinkEvent().getGoldenResourceId()).getIdPartAsLong());
Patient patient2 = addExternalEID(buildJanePatient(), "eid-2"); Patient patient2 = addExternalEID(buildJanePatient(), "eid-2");
myMdmHelper.createWithLatch(patient2); myMdmHelper.createWithLatch(patient2);
ctx = createContextForCreate("Patient"); ctx = createContextForCreate("Patient");
myMdmMatchLinkSvc.updateMdmLinksForMdmSource(patient2, ctx); myMdmMatchLinkSvc.updateMdmLinksForMdmSource(patient2, ctx);
ourLog.info(ctx.getMdmLinkChangeEvent().toString()); ourLog.info(ctx.getMdmLinkEvent().toString());
assertEquals(patient2.getIdElement().getValue(), ctx.getMdmLinkChangeEvent().getTargetResourceId()); assertEquals(patient2.getIdElement().getValue(), ctx.getMdmLinkEvent().getTargetResourceId());
assertEquals(getLinkByTargetId(patient2).getGoldenResourcePid(), new IdDt(ctx.getMdmLinkChangeEvent().getGoldenResourceId()).getIdPartAsLong()); assertEquals(getLinkByTargetId(patient2).getGoldenResourcePid(), new IdDt(ctx.getMdmLinkEvent().getGoldenResourceId()).getIdPartAsLong());
} }
@Test @Test

View File

@ -96,7 +96,7 @@ public class MdmTransactionContext {
this.myResourceType = myResourceType; this.myResourceType = myResourceType;
} }
public MdmLinkEvent getMdmLinkChangeEvent() { public MdmLinkEvent getMdmLinkEvent() {
return myMdmLinkEvent; return myMdmLinkEvent;
} }