Updated comments and added misc refactorings
This commit is contained in:
parent
91a961f9fd
commit
4e012236c2
|
@ -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<MdmLink> 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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -326,14 +326,14 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test {
|
|||
assertEquals(theExpectedCount, myMdmLinkDao.count());
|
||||
}
|
||||
|
||||
protected IAnyResource getGoldenResourceFromTargetResource(IAnyResource theBaseResource) {
|
||||
protected <T extends IAnyResource> T getGoldenResourceFromTargetResource(T theBaseResource) {
|
||||
String resourceType = theBaseResource.getIdElement().getResourceType();
|
||||
IFhirResourceDao relevantDao = myDaoRegistry.getResourceDao(resourceType);
|
||||
|
||||
Optional<MdmLink> 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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -96,7 +96,7 @@ public class MdmTransactionContext {
|
|||
this.myResourceType = myResourceType;
|
||||
}
|
||||
|
||||
public MdmLinkEvent getMdmLinkChangeEvent() {
|
||||
public MdmLinkEvent getMdmLinkEvent() {
|
||||
return myMdmLinkEvent;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue