WIP after persistence checked

This commit is contained in:
Nick Goupinets 2021-08-04 16:33:59 -04:00
parent 2bc024fef9
commit 4be3334f6f
2 changed files with 27 additions and 5 deletions

View File

@ -138,7 +138,7 @@ public class FhirResourceDaoCodeSystemR4 extends BaseHapiFhirResourceDao<CodeSys
} }
@Override @Override
public ResourceTable 4updateEntity(RequestDetails theRequest, IBaseResource theResource, IBasePersistedResource theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, public ResourceTable updateEntity(RequestDetails theRequest, IBaseResource theResource, IBasePersistedResource theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing,
boolean theUpdateVersion, TransactionDetails theTransactionDetails, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { boolean theUpdateVersion, TransactionDetails theTransactionDetails, boolean theForceUpdate, boolean theCreateNewHistoryEntry) {
ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theTransactionDetails, theForceUpdate, theCreateNewHistoryEntry); ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theTransactionDetails, theForceUpdate, theCreateNewHistoryEntry);

View File

@ -24,11 +24,15 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.interceptor.api.HookParams; import ca.uhn.fhir.interceptor.api.HookParams;
import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster;
import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.jpa.mdm.dao.MdmLinkDaoSvc;
import ca.uhn.fhir.jpa.mdm.svc.MdmLinkSvcImpl;
import ca.uhn.fhir.jpa.mdm.svc.MdmMatchLinkSvc; import ca.uhn.fhir.jpa.mdm.svc.MdmMatchLinkSvc;
import ca.uhn.fhir.jpa.mdm.svc.MdmResourceFilteringSvc; import ca.uhn.fhir.jpa.mdm.svc.MdmResourceFilteringSvc;
import ca.uhn.fhir.jpa.mdm.svc.candidate.TooManyCandidatesException; import ca.uhn.fhir.jpa.mdm.svc.candidate.TooManyCandidatesException;
import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage;
import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage;
import ca.uhn.fhir.mdm.api.IMdmLinkSvc;
import ca.uhn.fhir.mdm.api.IMdmSettings; import ca.uhn.fhir.mdm.api.IMdmSettings;
import ca.uhn.fhir.mdm.api.MdmLinkChangeEvent; import ca.uhn.fhir.mdm.api.MdmLinkChangeEvent;
import ca.uhn.fhir.mdm.log.Logs; import ca.uhn.fhir.mdm.log.Logs;
@ -46,11 +50,15 @@ import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException; import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Optional;
@Service @Service
public class MdmMessageHandler implements MessageHandler { public class MdmMessageHandler implements MessageHandler {
private static final Logger ourLog = Logs.getMdmTroubleshootingLog(); private static final Logger ourLog = Logs.getMdmTroubleshootingLog();
@Autowired
private MdmLinkDaoSvc myMdmLinkDaoSvc;
@Autowired @Autowired
private MdmMatchLinkSvc myMdmMatchLinkSvc; private MdmMatchLinkSvc myMdmMatchLinkSvc;
@Autowired @Autowired
@ -106,12 +114,26 @@ public class MdmMessageHandler implements MessageHandler {
log(mdmContext, "Failure during MDM processing: " + e.getMessage(), e); log(mdmContext, "Failure during MDM processing: " + e.getMessage(), e);
mdmContext.addTransactionLogMessage(e.getMessage()); mdmContext.addTransactionLogMessage(e.getMessage());
} finally { } finally {
// Interceptor call: MDM_AFTER_PERSISTED_RESOURCE_CHECKED // Interceptor call: MDM_AFTER_PERSISTED_RESOURCE_CHECKED
IBaseResource targetResource = theMsg.getPayload(myFhirContext); IBaseResource targetResource = theMsg.getPayload(myFhirContext);
ResourceOperationMessage outgoingMsg = new ResourceOperationMessage(myFhirContext, targetResource, theMsg.getOperationType()); ResourceOperationMessage outgoingMsg = new ResourceOperationMessage(myFhirContext, targetResource, theMsg.getOperationType());
outgoingMsg.setTransactionId(theMsg.getTransactionId()); outgoingMsg.setTransactionId(theMsg.getTransactionId());
MdmLinkChangeEvent linkChangeEvent = mdmContext.getMdmLinkChangeEvent();
Optional<MdmLink> mdmLinkBySource = myMdmLinkDaoSvc.findMdmLinkBySource(targetResource);
if (!mdmLinkBySource.isPresent()) {
ourLog.warn("Unable to find link by source for {}", targetResource.getIdElement());
}
mdmLinkBySource.ifPresent(link -> {
linkChangeEvent.setMdmMatchResult(link.getMatchResult());
linkChangeEvent.setMdmLinkSource(link.getLinkSource());
linkChangeEvent.setEidMatch(link.isEidMatchPresent());
linkChangeEvent.setNewGoldenResource(link.getHadToCreateNewGoldenResource());
linkChangeEvent.setScore(link.getScore());
linkChangeEvent.setRuleCount(link.getRuleCount());
});
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())