Begin large rename

This commit is contained in:
Tadgh 2020-11-12 18:36:52 -05:00
parent a28e9e736a
commit e490011a1f
23 changed files with 198 additions and 202 deletions

View File

@ -22,7 +22,7 @@ package ca.uhn.fhir.jpa.empi.broker;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.empi.log.Logs; import ca.uhn.fhir.empi.log.Logs;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.empi.util.EmpiUtil; import ca.uhn.fhir.empi.util.EmpiUtil;
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;
@ -77,7 +77,7 @@ public class EmpiMessageHandler implements MessageHandler {
public void matchEmpiAndUpdateLinks(ResourceModifiedMessage theMsg) { public void matchEmpiAndUpdateLinks(ResourceModifiedMessage theMsg) {
String resourceType = theMsg.getId(myFhirContext).getResourceType(); String resourceType = theMsg.getId(myFhirContext).getResourceType();
validateResourceType(resourceType); validateResourceType(resourceType);
EmpiTransactionContext empiContext = createEmpiContext(theMsg, resourceType); MdmTransactionContext empiContext = createEmpiContext(theMsg, resourceType);
try { try {
switch (theMsg.getOperationType()) { switch (theMsg.getOperationType()) {
case CREATE: case CREATE:
@ -106,25 +106,25 @@ public class EmpiMessageHandler implements MessageHandler {
} }
} }
private EmpiTransactionContext createEmpiContext(ResourceModifiedMessage theMsg, String theResourceType) { private MdmTransactionContext createEmpiContext(ResourceModifiedMessage theMsg, String theResourceType) {
TransactionLogMessages transactionLogMessages = TransactionLogMessages.createFromTransactionGuid(theMsg.getTransactionId()); TransactionLogMessages transactionLogMessages = TransactionLogMessages.createFromTransactionGuid(theMsg.getTransactionId());
EmpiTransactionContext.OperationType empiOperation; MdmTransactionContext.OperationType empiOperation;
switch (theMsg.getOperationType()) { switch (theMsg.getOperationType()) {
case CREATE: case CREATE:
empiOperation = EmpiTransactionContext.OperationType.CREATE_RESOURCE; empiOperation = MdmTransactionContext.OperationType.CREATE_RESOURCE;
break; break;
case UPDATE: case UPDATE:
empiOperation = EmpiTransactionContext.OperationType.UPDATE_RESOURCE; empiOperation = MdmTransactionContext.OperationType.UPDATE_RESOURCE;
break; break;
case MANUALLY_TRIGGERED: case MANUALLY_TRIGGERED:
empiOperation = EmpiTransactionContext.OperationType.SUBMIT_RESOURCE_TO_EMPI; empiOperation = MdmTransactionContext.OperationType.SUBMIT_RESOURCE_TO_EMPI;
break; break;
case DELETE: case DELETE:
default: default:
ourLog.trace("Not creating an EmpiTransactionContext for {}", theMsg.getOperationType()); ourLog.trace("Not creating an EmpiTransactionContext for {}", theMsg.getOperationType());
throw new InvalidRequestException("We can't handle non-update/create operations in EMPI"); throw new InvalidRequestException("We can't handle non-update/create operations in EMPI");
} }
return new EmpiTransactionContext(transactionLogMessages, empiOperation, theResourceType); return new MdmTransactionContext(transactionLogMessages, empiOperation, theResourceType);
} }
private void validateResourceType(String theResourceType) { private void validateResourceType(String theResourceType) {
@ -133,24 +133,24 @@ public class EmpiMessageHandler implements MessageHandler {
} }
} }
private void handleCreatePatientOrPractitioner(ResourceModifiedMessage theMsg, EmpiTransactionContext theEmpiTransactionContext) { private void handleCreatePatientOrPractitioner(ResourceModifiedMessage theMsg, MdmTransactionContext theMdmTransactionContext) {
myEmpiMatchLinkSvc.updateEmpiLinksForEmpiTarget(getResourceFromPayload(theMsg), theEmpiTransactionContext); myEmpiMatchLinkSvc.updateEmpiLinksForEmpiTarget(getResourceFromPayload(theMsg), theMdmTransactionContext);
} }
private IAnyResource getResourceFromPayload(ResourceModifiedMessage theMsg) { private IAnyResource getResourceFromPayload(ResourceModifiedMessage theMsg) {
return (IAnyResource) theMsg.getNewPayload(myFhirContext); return (IAnyResource) theMsg.getNewPayload(myFhirContext);
} }
private void handleUpdatePatientOrPractitioner(ResourceModifiedMessage theMsg, EmpiTransactionContext theEmpiTransactionContext) { private void handleUpdatePatientOrPractitioner(ResourceModifiedMessage theMsg, MdmTransactionContext theMdmTransactionContext) {
myEmpiMatchLinkSvc.updateEmpiLinksForEmpiTarget(getResourceFromPayload(theMsg), theEmpiTransactionContext); myEmpiMatchLinkSvc.updateEmpiLinksForEmpiTarget(getResourceFromPayload(theMsg), theMdmTransactionContext);
} }
private void log(EmpiTransactionContext theEmpiContext, String theMessage) { private void log(MdmTransactionContext theEmpiContext, String theMessage) {
theEmpiContext.addTransactionLogMessage(theMessage); theEmpiContext.addTransactionLogMessage(theMessage);
ourLog.debug(theMessage); ourLog.debug(theMessage);
} }
private void log(EmpiTransactionContext theEmpiContext, String theMessage, Exception theException) { private void log(MdmTransactionContext theEmpiContext, String theMessage, Exception theException) {
theEmpiContext.addTransactionLogMessage(theMessage); theEmpiContext.addTransactionLogMessage(theMessage);
ourLog.error(theMessage, theException); ourLog.error(theMessage, theException);
} }

View File

@ -27,7 +27,7 @@ import ca.uhn.fhir.empi.api.IEmpiLinkQuerySvc;
import ca.uhn.fhir.empi.api.IEmpiLinkSvc; import ca.uhn.fhir.empi.api.IEmpiLinkSvc;
import ca.uhn.fhir.empi.api.IEmpiLinkUpdaterSvc; import ca.uhn.fhir.empi.api.IEmpiLinkUpdaterSvc;
import ca.uhn.fhir.empi.api.IEmpiMatchFinderSvc; import ca.uhn.fhir.empi.api.IEmpiMatchFinderSvc;
import ca.uhn.fhir.empi.api.IEmpiPersonMergerSvc; import ca.uhn.fhir.empi.api.IGoldenResourceMergerSvc;
import ca.uhn.fhir.empi.api.IEmpiSettings; import ca.uhn.fhir.empi.api.IEmpiSettings;
import ca.uhn.fhir.empi.log.Logs; import ca.uhn.fhir.empi.log.Logs;
import ca.uhn.fhir.empi.provider.EmpiControllerHelper; import ca.uhn.fhir.empi.provider.EmpiControllerHelper;
@ -52,7 +52,7 @@ import ca.uhn.fhir.jpa.empi.svc.EmpiLinkUpdaterSvcImpl;
import ca.uhn.fhir.jpa.empi.svc.EmpiMatchFinderSvcImpl; import ca.uhn.fhir.jpa.empi.svc.EmpiMatchFinderSvcImpl;
import ca.uhn.fhir.jpa.empi.svc.EmpiMatchLinkSvc; import ca.uhn.fhir.jpa.empi.svc.EmpiMatchLinkSvc;
import ca.uhn.fhir.jpa.empi.svc.EmpiPersonDeletingSvc; import ca.uhn.fhir.jpa.empi.svc.EmpiPersonDeletingSvc;
import ca.uhn.fhir.jpa.empi.svc.EmpiPersonMergerSvcImpl; import ca.uhn.fhir.jpa.empi.svc.GoldenResourceMergerSvcImpl;
import ca.uhn.fhir.jpa.empi.svc.EmpiResourceDaoSvc; import ca.uhn.fhir.jpa.empi.svc.EmpiResourceDaoSvc;
import ca.uhn.fhir.jpa.empi.svc.EmpiResourceFilteringSvc; import ca.uhn.fhir.jpa.empi.svc.EmpiResourceFilteringSvc;
import ca.uhn.fhir.jpa.empi.svc.candidate.EmpiCandidateSearchCriteriaBuilderSvc; import ca.uhn.fhir.jpa.empi.svc.candidate.EmpiCandidateSearchCriteriaBuilderSvc;
@ -157,8 +157,8 @@ public class EmpiConsumerConfig {
} }
@Bean @Bean
IEmpiPersonMergerSvc empiPersonMergerSvc() { IGoldenResourceMergerSvc empiPersonMergerSvc() {
return new EmpiPersonMergerSvcImpl(); return new GoldenResourceMergerSvcImpl();
} }

View File

@ -25,7 +25,7 @@ import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
import ca.uhn.fhir.empi.api.EmpiMatchOutcome; import ca.uhn.fhir.empi.api.EmpiMatchOutcome;
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.log.Logs; import ca.uhn.fhir.empi.log.Logs;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.jpa.dao.data.IEmpiLinkDao; import ca.uhn.fhir.jpa.dao.data.IEmpiLinkDao;
import ca.uhn.fhir.jpa.dao.index.IdHelperService; import ca.uhn.fhir.jpa.dao.index.IdHelperService;
import ca.uhn.fhir.jpa.entity.EmpiLink; import ca.uhn.fhir.jpa.entity.EmpiLink;
@ -60,7 +60,7 @@ public class EmpiLinkDaoSvc {
private FhirContext myFhirContext; private FhirContext myFhirContext;
@Transactional @Transactional
public EmpiLink createOrUpdateLinkEntity(IBaseResource theSourceResource, IBaseResource theTargetResource, EmpiMatchOutcome theMatchOutcome, EmpiLinkSourceEnum theLinkSource, @Nullable EmpiTransactionContext theEmpiTransactionContext) { public EmpiLink createOrUpdateLinkEntity(IBaseResource theSourceResource, IBaseResource theTargetResource, EmpiMatchOutcome theMatchOutcome, EmpiLinkSourceEnum theLinkSource, @Nullable MdmTransactionContext theMdmTransactionContext) {
Long sourceResourcePid = myIdHelperService.getPidOrNull(theSourceResource); Long sourceResourcePid = myIdHelperService.getPidOrNull(theSourceResource);
Long targetResourcePid = myIdHelperService.getPidOrNull(theTargetResource); Long targetResourcePid = myIdHelperService.getPidOrNull(theTargetResource);
@ -78,7 +78,7 @@ public class EmpiLinkDaoSvc {
} }
String message = String.format("Creating EmpiLink from %s to %s -> %s", theSourceResource.getIdElement().toUnqualifiedVersionless(), theTargetResource.getIdElement().toUnqualifiedVersionless(), theMatchOutcome); String message = String.format("Creating EmpiLink from %s to %s -> %s", theSourceResource.getIdElement().toUnqualifiedVersionless(), theTargetResource.getIdElement().toUnqualifiedVersionless(), theMatchOutcome);
theEmpiTransactionContext.addTransactionLogMessage(message); theMdmTransactionContext.addTransactionLogMessage(message);
ourLog.debug(message); ourLog.debug(message);
save(empiLink); save(empiLink);
return empiLink; return empiLink;

View File

@ -26,8 +26,8 @@ import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.api.IEmpiControllerSvc; import ca.uhn.fhir.empi.api.IEmpiControllerSvc;
import ca.uhn.fhir.empi.api.IEmpiLinkQuerySvc; import ca.uhn.fhir.empi.api.IEmpiLinkQuerySvc;
import ca.uhn.fhir.empi.api.IEmpiLinkUpdaterSvc; import ca.uhn.fhir.empi.api.IEmpiLinkUpdaterSvc;
import ca.uhn.fhir.empi.api.IEmpiPersonMergerSvc; import ca.uhn.fhir.empi.api.IGoldenResourceMergerSvc;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.empi.provider.EmpiControllerHelper; import ca.uhn.fhir.empi.provider.EmpiControllerHelper;
import ca.uhn.fhir.empi.provider.EmpiControllerUtil; import ca.uhn.fhir.empi.provider.EmpiControllerUtil;
import ca.uhn.fhir.rest.server.provider.ProviderConstants; import ca.uhn.fhir.rest.server.provider.ProviderConstants;
@ -47,25 +47,25 @@ public class EmpiControllerSvcImpl implements IEmpiControllerSvc {
@Autowired @Autowired
EmpiControllerHelper myEmpiControllerHelper; EmpiControllerHelper myEmpiControllerHelper;
@Autowired @Autowired
IEmpiPersonMergerSvc myEmpiPersonMergerSvc; IGoldenResourceMergerSvc myEmpiPersonMergerSvc;
@Autowired @Autowired
IEmpiLinkQuerySvc myEmpiLinkQuerySvc; IEmpiLinkQuerySvc myEmpiLinkQuerySvc;
@Autowired @Autowired
IEmpiLinkUpdaterSvc myIEmpiLinkUpdaterSvc; IEmpiLinkUpdaterSvc myIEmpiLinkUpdaterSvc;
@Override @Override
public IAnyResource mergeGoldenResources(String theFromPersonId, String theToPersonId, EmpiTransactionContext theEmpiTransactionContext) { public IAnyResource mergeGoldenResources(String theFromPersonId, String theToPersonId, MdmTransactionContext theMdmTransactionContext) {
IAnyResource fromPerson = myEmpiControllerHelper.getLatestPersonFromIdOrThrowException(ProviderConstants.MDM_MERGE_GR_FROM_GOLDEN_RESOURCE_ID, theFromPersonId); IAnyResource fromPerson = myEmpiControllerHelper.getLatestPersonFromIdOrThrowException(ProviderConstants.MDM_MERGE_GR_FROM_GOLDEN_RESOURCE_ID, theFromPersonId);
IAnyResource toPerson = myEmpiControllerHelper.getLatestPersonFromIdOrThrowException(ProviderConstants.MDM_MERGE_GR_TO_GOLDEN_RESOURCE_ID, theToPersonId); IAnyResource toPerson = myEmpiControllerHelper.getLatestPersonFromIdOrThrowException(ProviderConstants.MDM_MERGE_GR_TO_GOLDEN_RESOURCE_ID, theToPersonId);
myEmpiControllerHelper.validateMergeResources(fromPerson, toPerson); myEmpiControllerHelper.validateMergeResources(fromPerson, toPerson);
myEmpiControllerHelper.validateSameVersion(fromPerson, theFromPersonId); myEmpiControllerHelper.validateSameVersion(fromPerson, theFromPersonId);
myEmpiControllerHelper.validateSameVersion(toPerson, theToPersonId); myEmpiControllerHelper.validateSameVersion(toPerson, theToPersonId);
return myEmpiPersonMergerSvc.mergePersons(fromPerson, toPerson, theEmpiTransactionContext); return myEmpiPersonMergerSvc.mergeGoldenResources(fromPerson, toPerson, theMdmTransactionContext);
} }
@Override @Override
public Stream<EmpiLinkJson> queryLinks(@Nullable String thePersonId, @Nullable String theTargetId, @Nullable String theMatchResult, @Nullable String theLinkSource, EmpiTransactionContext theEmpiContext) { public Stream<EmpiLinkJson> queryLinks(@Nullable String thePersonId, @Nullable String theTargetId, @Nullable String theMatchResult, @Nullable String theLinkSource, MdmTransactionContext theEmpiContext) {
IIdType personId = EmpiControllerUtil.extractPersonIdDtOrNull(ProviderConstants.MDM_QUERY_LINKS_GOLDEN_RESOURCE_ID, thePersonId); IIdType personId = EmpiControllerUtil.extractPersonIdDtOrNull(ProviderConstants.MDM_QUERY_LINKS_GOLDEN_RESOURCE_ID, thePersonId);
IIdType targetId = EmpiControllerUtil.extractTargetIdDtOrNull(ProviderConstants.MDM_QUERY_LINKS_RESOURCE_ID, theTargetId); IIdType targetId = EmpiControllerUtil.extractTargetIdDtOrNull(ProviderConstants.MDM_QUERY_LINKS_RESOURCE_ID, theTargetId);
EmpiMatchResultEnum matchResult = EmpiControllerUtil.extractMatchResultOrNull(theMatchResult); EmpiMatchResultEnum matchResult = EmpiControllerUtil.extractMatchResultOrNull(theMatchResult);
@ -75,12 +75,12 @@ public class EmpiControllerSvcImpl implements IEmpiControllerSvc {
} }
@Override @Override
public Stream<EmpiLinkJson> getDuplicateGoldenResources(EmpiTransactionContext theEmpiContext) { public Stream<EmpiLinkJson> getDuplicateGoldenResources(MdmTransactionContext theEmpiContext) {
return myEmpiLinkQuerySvc.getDuplicatePersons(theEmpiContext); return myEmpiLinkQuerySvc.getDuplicatePersons(theEmpiContext);
} }
@Override @Override
public IAnyResource updateLink(String thePersonId, String theTargetId, String theMatchResult, EmpiTransactionContext theEmpiContext) { public IAnyResource updateLink(String thePersonId, String theTargetId, String theMatchResult, MdmTransactionContext theEmpiContext) {
EmpiMatchResultEnum matchResult = EmpiControllerUtil.extractMatchResultOrNull(theMatchResult); EmpiMatchResultEnum matchResult = EmpiControllerUtil.extractMatchResultOrNull(theMatchResult);
IAnyResource person = myEmpiControllerHelper.getLatestPersonFromIdOrThrowException(ProviderConstants.MDM_UPDATE_LINK_GOLDEN_RESOURCE_ID, thePersonId); IAnyResource person = myEmpiControllerHelper.getLatestPersonFromIdOrThrowException(ProviderConstants.MDM_UPDATE_LINK_GOLDEN_RESOURCE_ID, thePersonId);
IAnyResource target = myEmpiControllerHelper.getLatestTargetFromIdOrThrowException(ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, theTargetId); IAnyResource target = myEmpiControllerHelper.getLatestTargetFromIdOrThrowException(ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, theTargetId);
@ -91,7 +91,7 @@ public class EmpiControllerSvcImpl implements IEmpiControllerSvc {
} }
@Override @Override
public void notDuplicateGoldenResource(String thePersonId, String theTargetPersonId, EmpiTransactionContext theEmpiContext) { public void notDuplicateGoldenResource(String thePersonId, String theTargetPersonId, MdmTransactionContext theEmpiContext) {
IAnyResource person = myEmpiControllerHelper.getLatestPersonFromIdOrThrowException(ProviderConstants.MDM_UPDATE_LINK_GOLDEN_RESOURCE_ID, thePersonId); IAnyResource person = myEmpiControllerHelper.getLatestPersonFromIdOrThrowException(ProviderConstants.MDM_UPDATE_LINK_GOLDEN_RESOURCE_ID, thePersonId);
IAnyResource target = myEmpiControllerHelper.getLatestPersonFromIdOrThrowException(ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, theTargetPersonId); IAnyResource target = myEmpiControllerHelper.getLatestPersonFromIdOrThrowException(ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, theTargetPersonId);

View File

@ -26,7 +26,7 @@ import ca.uhn.fhir.empi.api.IEmpiLinkSvc;
import ca.uhn.fhir.empi.api.IEmpiSettings; import ca.uhn.fhir.empi.api.IEmpiSettings;
import ca.uhn.fhir.empi.log.Logs; import ca.uhn.fhir.empi.log.Logs;
import ca.uhn.fhir.empi.model.CanonicalEID; import ca.uhn.fhir.empi.model.CanonicalEID;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.empi.util.EIDHelper; import ca.uhn.fhir.empi.util.EIDHelper;
import ca.uhn.fhir.empi.util.PersonHelper; import ca.uhn.fhir.empi.util.PersonHelper;
import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc; import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc;
@ -61,7 +61,7 @@ public class EmpiEidUpdateService {
@Autowired @Autowired
private IEmpiSettings myEmpiSettings; private IEmpiSettings myEmpiSettings;
void handleEmpiUpdate(IAnyResource theResource, MatchedSourceResourceCandidate theMatchedSourceResourceCandidate, EmpiTransactionContext theEmpiTransactionContext) { void handleEmpiUpdate(IAnyResource theResource, MatchedSourceResourceCandidate theMatchedSourceResourceCandidate, MdmTransactionContext theMdmTransactionContext) {
EmpiUpdateContext updateContext = new EmpiUpdateContext(theMatchedSourceResourceCandidate, theResource); EmpiUpdateContext updateContext = new EmpiUpdateContext(theMatchedSourceResourceCandidate, theResource);
@ -71,34 +71,34 @@ public class EmpiEidUpdateService {
// myPersonHelper.updatePersonFromUpdatedEmpiTarget(updateContext.getMatchedPerson(), theResource, theEmpiTransactionContext); // myPersonHelper.updatePersonFromUpdatedEmpiTarget(updateContext.getMatchedPerson(), theResource, theEmpiTransactionContext);
if (!updateContext.isIncomingResourceHasAnEid() || updateContext.isHasEidsInCommon()) { if (!updateContext.isIncomingResourceHasAnEid() || updateContext.isHasEidsInCommon()) {
//update to patient that uses internal EIDs only. //update to patient that uses internal EIDs only.
myEmpiLinkSvc.updateLink(updateContext.getMatchedSourceResource(), theResource, theMatchedSourceResourceCandidate.getMatchResult(), EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(updateContext.getMatchedSourceResource(), theResource, theMatchedSourceResourceCandidate.getMatchResult(), EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
} else if (!updateContext.isHasEidsInCommon()) { } else if (!updateContext.isHasEidsInCommon()) {
handleNoEidsInCommon(theResource, theMatchedSourceResourceCandidate, theEmpiTransactionContext, updateContext); handleNoEidsInCommon(theResource, theMatchedSourceResourceCandidate, theMdmTransactionContext, updateContext);
} }
} else { } else {
//This is a new linking scenario. we have to break the existing link and link to the new person. For now, we create duplicate. //This is a new linking scenario. we have to break the existing link and link to the new person. For now, we create duplicate.
//updated patient has an EID that matches to a new candidate. Link them, and set the persons possible duplicates //updated patient has an EID that matches to a new candidate. Link them, and set the persons possible duplicates
linkToNewPersonAndFlagAsDuplicate(theResource, updateContext.getExistingPerson(), updateContext.getMatchedSourceResource(), theEmpiTransactionContext); linkToNewPersonAndFlagAsDuplicate(theResource, updateContext.getExistingPerson(), updateContext.getMatchedSourceResource(), theMdmTransactionContext);
} }
} }
private void handleNoEidsInCommon(IAnyResource theResource, MatchedSourceResourceCandidate theMatchedSourceResourceCandidate, EmpiTransactionContext theEmpiTransactionContext, EmpiUpdateContext theUpdateContext) { private void handleNoEidsInCommon(IAnyResource theResource, MatchedSourceResourceCandidate theMatchedSourceResourceCandidate, MdmTransactionContext theMdmTransactionContext, EmpiUpdateContext theUpdateContext) {
// the user is simply updating their EID. We propagate this change to the Person. // the user is simply updating their EID. We propagate this change to the Person.
//overwrite. No EIDS in common, but still same person. //overwrite. No EIDS in common, but still same person.
if (myEmpiSettings.isPreventMultipleEids()) { if (myEmpiSettings.isPreventMultipleEids()) {
if (myEmpiLinkDaoSvc.findEmpiMatchLinksBySource(theUpdateContext.getMatchedSourceResource()).size() <= 1) { // If there is only 0/1 link on the person, we can safely overwrite the EID. if (myEmpiLinkDaoSvc.findEmpiMatchLinksBySource(theUpdateContext.getMatchedSourceResource()).size() <= 1) { // If there is only 0/1 link on the person, we can safely overwrite the EID.
// if (myPersonHelper.getLinkCount(theUpdateContext.getMatchedSourceResource()) <= 1) { // If there is only 0/1 link on the person, we can safely overwrite the EID. // if (myPersonHelper.getLinkCount(theUpdateContext.getMatchedSourceResource()) <= 1) { // If there is only 0/1 link on the person, we can safely overwrite the EID.
handleExternalEidOverwrite(theUpdateContext.getMatchedSourceResource(), theResource, theEmpiTransactionContext); handleExternalEidOverwrite(theUpdateContext.getMatchedSourceResource(), theResource, theMdmTransactionContext);
} else { // If the person has multiple patients tied to it, we can't just overwrite the EID, so we split the person. } else { // If the person has multiple patients tied to it, we can't just overwrite the EID, so we split the person.
createNewPersonAndFlagAsDuplicate(theResource, theEmpiTransactionContext, theUpdateContext.getExistingPerson()); createNewPersonAndFlagAsDuplicate(theResource, theMdmTransactionContext, theUpdateContext.getExistingPerson());
} }
} else { } else {
myPersonHelper.handleExternalEidAddition(theUpdateContext.getMatchedSourceResource(), theResource, theEmpiTransactionContext); myPersonHelper.handleExternalEidAddition(theUpdateContext.getMatchedSourceResource(), theResource, theMdmTransactionContext);
} }
myEmpiLinkSvc.updateLink(theUpdateContext.getMatchedSourceResource(), theResource, theMatchedSourceResourceCandidate.getMatchResult(), EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(theUpdateContext.getMatchedSourceResource(), theResource, theMatchedSourceResourceCandidate.getMatchResult(), EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
} }
private void handleExternalEidOverwrite(IAnyResource thePerson, IAnyResource theResource, EmpiTransactionContext theEmpiTransactionContext) { private void handleExternalEidOverwrite(IAnyResource thePerson, IAnyResource theResource, MdmTransactionContext theMdmTransactionContext) {
List<CanonicalEID> eidFromResource = myEIDHelper.getExternalEid(theResource); List<CanonicalEID> eidFromResource = myEIDHelper.getExternalEid(theResource);
if (!eidFromResource.isEmpty()) { if (!eidFromResource.isEmpty()) {
myPersonHelper.overwriteExternalEids(thePerson, eidFromResource); myPersonHelper.overwriteExternalEids(thePerson, eidFromResource);
@ -109,24 +109,24 @@ public class EmpiEidUpdateService {
return theExistingMatchLink.getSourceResourcePid().equals(thePersonCandidate.getCandidatePersonPid().getIdAsLong()); return theExistingMatchLink.getSourceResourcePid().equals(thePersonCandidate.getCandidatePersonPid().getIdAsLong());
} }
private void createNewPersonAndFlagAsDuplicate(IAnyResource theResource, EmpiTransactionContext theEmpiTransactionContext, IAnyResource theOldPerson) { private void createNewPersonAndFlagAsDuplicate(IAnyResource theResource, MdmTransactionContext theMdmTransactionContext, IAnyResource theOldPerson) {
log(theEmpiTransactionContext, "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 newPerson = myPersonHelper.createSourceResourceFromEmpiTarget(theResource); IAnyResource newPerson = myPersonHelper.createSourceResourceFromEmpiTarget(theResource);
myEmpiLinkSvc.updateLink(newPerson, theResource, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(newPerson, theResource, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
myEmpiLinkSvc.updateLink(newPerson, theOldPerson, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(newPerson, theOldPerson, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
} }
private void linkToNewPersonAndFlagAsDuplicate(IAnyResource theResource, IAnyResource theOldPerson, IAnyResource theNewPerson, EmpiTransactionContext theEmpiTransactionContext) { private void linkToNewPersonAndFlagAsDuplicate(IAnyResource theResource, IAnyResource theOldPerson, IAnyResource theNewPerson, MdmTransactionContext theMdmTransactionContext) {
log(theEmpiTransactionContext, "Changing a match link!"); log(theMdmTransactionContext, "Changing a match link!");
myEmpiLinkSvc.deleteLink(theOldPerson, theResource, theEmpiTransactionContext); myEmpiLinkSvc.deleteLink(theOldPerson, theResource, theMdmTransactionContext);
myEmpiLinkSvc.updateLink(theNewPerson, theResource, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(theNewPerson, theResource, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
log(theEmpiTransactionContext, "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.");
myEmpiLinkSvc.updateLink(theNewPerson, theOldPerson, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(theNewPerson, theOldPerson, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
} }
private void log(EmpiTransactionContext theEmpiTransactionContext, String theMessage) { private void log(MdmTransactionContext theMdmTransactionContext, String theMessage) {
theEmpiTransactionContext.addTransactionLogMessage(theMessage); theMdmTransactionContext.addTransactionLogMessage(theMessage);
ourLog.debug(theMessage); ourLog.debug(theMessage);
} }

View File

@ -24,7 +24,7 @@ import ca.uhn.fhir.empi.api.EmpiLinkJson;
import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum; import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.api.IEmpiLinkQuerySvc; import ca.uhn.fhir.empi.api.IEmpiLinkQuerySvc;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.jpa.dao.index.IdHelperService; import ca.uhn.fhir.jpa.dao.index.IdHelperService;
import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc; import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc;
import ca.uhn.fhir.jpa.entity.EmpiLink; import ca.uhn.fhir.jpa.entity.EmpiLink;
@ -45,7 +45,7 @@ public class EmpiLinkQuerySvcImpl implements IEmpiLinkQuerySvc {
EmpiLinkDaoSvc myEmpiLinkDaoSvc; EmpiLinkDaoSvc myEmpiLinkDaoSvc;
@Override @Override
public Stream<EmpiLinkJson> queryLinks(IIdType thePersonId, IIdType theTargetId, EmpiMatchResultEnum theMatchResult, EmpiLinkSourceEnum theLinkSource, EmpiTransactionContext theEmpiContext) { public Stream<EmpiLinkJson> queryLinks(IIdType thePersonId, IIdType theTargetId, EmpiMatchResultEnum theMatchResult, EmpiLinkSourceEnum theLinkSource, MdmTransactionContext theEmpiContext) {
Example<EmpiLink> exampleLink = exampleLinkFromParameters(thePersonId, theTargetId, theMatchResult, theLinkSource); Example<EmpiLink> exampleLink = exampleLinkFromParameters(thePersonId, theTargetId, theMatchResult, theLinkSource);
return myEmpiLinkDaoSvc.findEmpiLinkByExample(exampleLink).stream() return myEmpiLinkDaoSvc.findEmpiLinkByExample(exampleLink).stream()
.filter(empiLink -> empiLink.getMatchResult() != EmpiMatchResultEnum.POSSIBLE_DUPLICATE) .filter(empiLink -> empiLink.getMatchResult() != EmpiMatchResultEnum.POSSIBLE_DUPLICATE)
@ -53,7 +53,7 @@ public class EmpiLinkQuerySvcImpl implements IEmpiLinkQuerySvc {
} }
@Override @Override
public Stream<EmpiLinkJson> getDuplicatePersons(EmpiTransactionContext theEmpiContext) { public Stream<EmpiLinkJson> getDuplicatePersons(MdmTransactionContext theEmpiContext) {
Example<EmpiLink> exampleLink = exampleLinkFromParameters(null, null, EmpiMatchResultEnum.POSSIBLE_DUPLICATE, null); Example<EmpiLink> exampleLink = exampleLinkFromParameters(null, null, EmpiMatchResultEnum.POSSIBLE_DUPLICATE, null);
return myEmpiLinkDaoSvc.findEmpiLinkByExample(exampleLink).stream().map(this::toJson); return myEmpiLinkDaoSvc.findEmpiLinkByExample(exampleLink).stream().map(this::toJson);
} }

View File

@ -26,7 +26,7 @@ import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.api.IEmpiLinkSvc; import ca.uhn.fhir.empi.api.IEmpiLinkSvc;
import ca.uhn.fhir.empi.log.Logs; import ca.uhn.fhir.empi.log.Logs;
import ca.uhn.fhir.empi.model.CanonicalIdentityAssuranceLevel; import ca.uhn.fhir.empi.model.CanonicalIdentityAssuranceLevel;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.empi.util.AssuranceLevelUtil; import ca.uhn.fhir.empi.util.AssuranceLevelUtil;
import ca.uhn.fhir.empi.util.PersonHelper; import ca.uhn.fhir.empi.util.PersonHelper;
import ca.uhn.fhir.jpa.dao.index.IdHelperService; import ca.uhn.fhir.jpa.dao.index.IdHelperService;
@ -42,9 +42,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
/** /**
* This class is in charge of managing EmpiLinks between Persons and target resources * This class is in charge of managing EmpiLinks between Persons and target resources
@ -64,11 +62,11 @@ public class EmpiLinkSvcImpl implements IEmpiLinkSvc {
@Override @Override
@Transactional @Transactional
public void updateLink(IAnyResource thePerson, IAnyResource theTarget, EmpiMatchOutcome theMatchOutcome, EmpiLinkSourceEnum theLinkSource, EmpiTransactionContext theEmpiTransactionContext) { public void updateLink(IAnyResource thePerson, IAnyResource theTarget, EmpiMatchOutcome theMatchOutcome, EmpiLinkSourceEnum theLinkSource, MdmTransactionContext theMdmTransactionContext) {
IIdType resourceId = theTarget.getIdElement().toUnqualifiedVersionless(); IIdType resourceId = theTarget.getIdElement().toUnqualifiedVersionless();
if (theMatchOutcome.isPossibleDuplicate() && personsLinkedAsNoMatch(thePerson, theTarget)) { if (theMatchOutcome.isPossibleDuplicate() && personsLinkedAsNoMatch(thePerson, theTarget)) {
log(theEmpiTransactionContext, thePerson.getIdElement().toUnqualifiedVersionless() + log(theMdmTransactionContext, thePerson.getIdElement().toUnqualifiedVersionless() +
" is linked as NO_MATCH with " + " is linked as NO_MATCH with " +
theTarget.getIdElement().toUnqualifiedVersionless() + theTarget.getIdElement().toUnqualifiedVersionless() +
" not linking as POSSIBLE_DUPLICATE."); " not linking as POSSIBLE_DUPLICATE.");
@ -90,8 +88,8 @@ public class EmpiLinkSvcImpl implements IEmpiLinkSvc {
// case POSSIBLE_DUPLICATE: // case POSSIBLE_DUPLICATE:
// break; // break;
// } // }
myEmpiResourceDaoSvc.upsertSourceResource(thePerson, theEmpiTransactionContext.getResourceType()); myEmpiResourceDaoSvc.upsertSourceResource(thePerson, theMdmTransactionContext.getResourceType());
createOrUpdateLinkEntity(thePerson, theTarget, theMatchOutcome, theLinkSource, theEmpiTransactionContext); createOrUpdateLinkEntity(thePerson, theTarget, theMatchOutcome, theLinkSource, theMdmTransactionContext);
} }
private boolean personsLinkedAsNoMatch(IAnyResource thePerson, IAnyResource theTarget) { private boolean personsLinkedAsNoMatch(IAnyResource thePerson, IAnyResource theTarget) {
@ -124,14 +122,14 @@ public class EmpiLinkSvcImpl implements IEmpiLinkSvc {
// } // }
@Override @Override
public void deleteLink(IAnyResource theSourceResource, IAnyResource theTargetResource, EmpiTransactionContext theEmpiTransactionContext) { public void deleteLink(IAnyResource theSourceResource, IAnyResource theTargetResource, MdmTransactionContext theMdmTransactionContext) {
// myPersonHelper.removeLink(theExistingPerson, theResource.getIdElement(), theEmpiTransactionContext); // myPersonHelper.removeLink(theExistingPerson, theResource.getIdElement(), theEmpiTransactionContext);
// myEmpiLinkDaoSvc.deleteEmpiLinks(theSourceResource, theTargetResource); // myEmpiLinkDaoSvc.deleteEmpiLinks(theSourceResource, theTargetResource);
Optional<EmpiLink> oEmpiLink = getEmpiLinkForPersonTargetPair(theSourceResource, theTargetResource); Optional<EmpiLink> oEmpiLink = getEmpiLinkForPersonTargetPair(theSourceResource, theTargetResource);
if (oEmpiLink.isPresent()) { if (oEmpiLink.isPresent()) {
EmpiLink empiLink = oEmpiLink.get(); EmpiLink empiLink = oEmpiLink.get();
log(theEmpiTransactionContext, "Deleting EmpiLink [" + theSourceResource.getIdElement().toVersionless() + " -> " + theTargetResource.getIdElement().toVersionless() + "] with result: " + empiLink.getMatchResult()); log(theMdmTransactionContext, "Deleting EmpiLink [" + theSourceResource.getIdElement().toVersionless() + " -> " + theTargetResource.getIdElement().toVersionless() + "] with result: " + empiLink.getMatchResult());
myEmpiLinkDaoSvc.deleteLink(empiLink); myEmpiLinkDaoSvc.deleteLink(empiLink);
} }
} }
@ -181,12 +179,12 @@ public class EmpiLinkSvcImpl implements IEmpiLinkSvc {
} }
} }
private void createOrUpdateLinkEntity(IBaseResource theSourceResource, IBaseResource theTargetResource, EmpiMatchOutcome theMatchOutcome, EmpiLinkSourceEnum theLinkSource, EmpiTransactionContext theEmpiTransactionContext) { private void createOrUpdateLinkEntity(IBaseResource theSourceResource, IBaseResource theTargetResource, EmpiMatchOutcome theMatchOutcome, EmpiLinkSourceEnum theLinkSource, MdmTransactionContext theMdmTransactionContext) {
myEmpiLinkDaoSvc.createOrUpdateLinkEntity(theSourceResource, theTargetResource, theMatchOutcome, theLinkSource, theEmpiTransactionContext); myEmpiLinkDaoSvc.createOrUpdateLinkEntity(theSourceResource, theTargetResource, theMatchOutcome, theLinkSource, theMdmTransactionContext);
} }
private void log(EmpiTransactionContext theEmpiTransactionContext, String theMessage) { private void log(MdmTransactionContext theMdmTransactionContext, String theMessage) {
theEmpiTransactionContext.addTransactionLogMessage(theMessage); theMdmTransactionContext.addTransactionLogMessage(theMessage);
ourLog.debug(theMessage); ourLog.debug(theMessage);
} }
} }

View File

@ -27,7 +27,7 @@ import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.api.IEmpiLinkSvc; import ca.uhn.fhir.empi.api.IEmpiLinkSvc;
import ca.uhn.fhir.empi.api.IEmpiLinkUpdaterSvc; import ca.uhn.fhir.empi.api.IEmpiLinkUpdaterSvc;
import ca.uhn.fhir.empi.log.Logs; import ca.uhn.fhir.empi.log.Logs;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.empi.util.EmpiUtil; import ca.uhn.fhir.empi.util.EmpiUtil;
import ca.uhn.fhir.jpa.dao.index.IdHelperService; import ca.uhn.fhir.jpa.dao.index.IdHelperService;
import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc; import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc;
@ -59,7 +59,7 @@ public class EmpiLinkUpdaterSvcImpl implements IEmpiLinkUpdaterSvc {
@Transactional @Transactional
@Override @Override
public IAnyResource updateLink(IAnyResource thePerson, IAnyResource theTarget, EmpiMatchResultEnum theMatchResult, EmpiTransactionContext theEmpiContext) { public IAnyResource updateLink(IAnyResource thePerson, IAnyResource theTarget, EmpiMatchResultEnum theMatchResult, MdmTransactionContext theEmpiContext) {
String targetType = myFhirContext.getResourceType(theTarget); String targetType = myFhirContext.getResourceType(theTarget);
validateUpdateLinkRequest(thePerson, theTarget, theMatchResult, targetType); validateUpdateLinkRequest(thePerson, theTarget, theMatchResult, targetType);
@ -115,7 +115,7 @@ public class EmpiLinkUpdaterSvcImpl implements IEmpiLinkUpdaterSvc {
@Transactional @Transactional
@Override @Override
public void notDuplicatePerson(IAnyResource thePerson, IAnyResource theTarget, EmpiTransactionContext theEmpiContext) { public void notDuplicatePerson(IAnyResource thePerson, IAnyResource theTarget, MdmTransactionContext theEmpiContext) {
validateNotDuplicatePersonRequest(thePerson, theTarget); validateNotDuplicatePersonRequest(thePerson, theTarget);
Long personId = myIdHelperService.getPidOrThrowException(thePerson); Long personId = myIdHelperService.getPidOrThrowException(thePerson);

View File

@ -24,7 +24,7 @@ import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
import ca.uhn.fhir.empi.api.EmpiMatchOutcome; import ca.uhn.fhir.empi.api.EmpiMatchOutcome;
import ca.uhn.fhir.empi.api.IEmpiLinkSvc; import ca.uhn.fhir.empi.api.IEmpiLinkSvc;
import ca.uhn.fhir.empi.log.Logs; import ca.uhn.fhir.empi.log.Logs;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.empi.util.EmpiUtil; import ca.uhn.fhir.empi.util.EmpiUtil;
import ca.uhn.fhir.empi.util.PersonHelper; import ca.uhn.fhir.empi.util.PersonHelper;
import ca.uhn.fhir.jpa.empi.svc.candidate.CandidateList; import ca.uhn.fhir.jpa.empi.svc.candidate.CandidateList;
@ -63,49 +63,49 @@ public class EmpiMatchLinkSvc {
* Does nothing if resource is determined to be not managed by EMPI. * Does nothing if resource is determined to be not managed by EMPI.
* *
* @param theResource the incoming EMPI target, which is either a Patient or Practitioner. * @param theResource the incoming EMPI target, which is either a Patient or Practitioner.
* @param theEmpiTransactionContext * @param theMdmTransactionContext
* @return an {@link TransactionLogMessages} which contains all informational messages related to EMPI processing of this resource. * @return an {@link TransactionLogMessages} which contains all informational messages related to EMPI processing of this resource.
*/ */
public EmpiTransactionContext updateEmpiLinksForEmpiTarget(IAnyResource theResource, EmpiTransactionContext theEmpiTransactionContext) { public MdmTransactionContext updateEmpiLinksForEmpiTarget(IAnyResource theResource, MdmTransactionContext theMdmTransactionContext) {
if (EmpiUtil.isEmpiAccessible(theResource)) { if (EmpiUtil.isEmpiAccessible(theResource)) {
return doEmpiUpdate(theResource, theEmpiTransactionContext); return doEmpiUpdate(theResource, theMdmTransactionContext);
} else { } else {
return null; return null;
} }
} }
private EmpiTransactionContext doEmpiUpdate(IAnyResource theResource, EmpiTransactionContext theEmpiTransactionContext) { private MdmTransactionContext doEmpiUpdate(IAnyResource theResource, MdmTransactionContext theMdmTransactionContext) {
CandidateList candidateList = myEmpiSourceResourceFindingSvc.findSourceResourceCandidates(theResource); CandidateList candidateList = myEmpiSourceResourceFindingSvc.findSourceResourceCandidates(theResource);
if (candidateList.isEmpty()) { if (candidateList.isEmpty()) {
handleEmpiWithNoCandidates(theResource, theEmpiTransactionContext); handleEmpiWithNoCandidates(theResource, theMdmTransactionContext);
} else if (candidateList.exactlyOneMatch()) { } else if (candidateList.exactlyOneMatch()) {
handleEmpiWithSingleCandidate(theResource, candidateList.getOnlyMatch(), theEmpiTransactionContext); handleEmpiWithSingleCandidate(theResource, candidateList.getOnlyMatch(), theMdmTransactionContext);
} else { } else {
handleEmpiWithMultipleCandidates(theResource, candidateList, theEmpiTransactionContext); handleEmpiWithMultipleCandidates(theResource, candidateList, theMdmTransactionContext);
} }
return theEmpiTransactionContext; return theMdmTransactionContext;
} }
private void handleEmpiWithMultipleCandidates(IAnyResource theResource, CandidateList theCandidateList, EmpiTransactionContext theEmpiTransactionContext) { private void handleEmpiWithMultipleCandidates(IAnyResource theResource, CandidateList theCandidateList, MdmTransactionContext theMdmTransactionContext) {
MatchedSourceResourceCandidate firstMatch = theCandidateList.getFirstMatch(); MatchedSourceResourceCandidate firstMatch = theCandidateList.getFirstMatch();
Long samplePersonPid = firstMatch.getCandidatePersonPid().getIdAsLong(); Long samplePersonPid = firstMatch.getCandidatePersonPid().getIdAsLong();
boolean allSamePerson = theCandidateList.stream() boolean allSamePerson = theCandidateList.stream()
.allMatch(candidate -> candidate.getCandidatePersonPid().getIdAsLong().equals(samplePersonPid)); .allMatch(candidate -> candidate.getCandidatePersonPid().getIdAsLong().equals(samplePersonPid));
if (allSamePerson) { if (allSamePerson) {
log(theEmpiTransactionContext, "EMPI received multiple match candidates, but they are all linked to the same person."); log(theMdmTransactionContext, "EMPI received multiple match candidates, but they are all linked to the same person.");
handleEmpiWithSingleCandidate(theResource, firstMatch, theEmpiTransactionContext); handleEmpiWithSingleCandidate(theResource, firstMatch, theMdmTransactionContext);
} else { } else {
log(theEmpiTransactionContext, "EMPI received multiple match candidates, that were linked to different Persons. Setting POSSIBLE_DUPLICATES and POSSIBLE_MATCHES."); log(theMdmTransactionContext, "EMPI received multiple match candidates, that were linked to different Persons. Setting POSSIBLE_DUPLICATES and POSSIBLE_MATCHES.");
//Set them all as POSSIBLE_MATCH //Set them all as POSSIBLE_MATCH
List<IAnyResource> persons = new ArrayList<>(); List<IAnyResource> persons = new ArrayList<>();
for (MatchedSourceResourceCandidate matchedSourceResourceCandidate : theCandidateList.getCandidates()) { for (MatchedSourceResourceCandidate matchedSourceResourceCandidate : theCandidateList.getCandidates()) {
IAnyResource person = myEmpiSourceResourceFindingSvc IAnyResource person = myEmpiSourceResourceFindingSvc
.getSourceResourceFromMatchedSourceResourceCandidate(matchedSourceResourceCandidate, theEmpiTransactionContext.getResourceType()); .getSourceResourceFromMatchedSourceResourceCandidate(matchedSourceResourceCandidate, theMdmTransactionContext.getResourceType());
EmpiMatchOutcome outcome = EmpiMatchOutcome.POSSIBLE_MATCH; EmpiMatchOutcome outcome = EmpiMatchOutcome.POSSIBLE_MATCH;
outcome.setEidMatch(theCandidateList.isEidMatch()); outcome.setEidMatch(theCandidateList.isEidMatch());
myEmpiLinkSvc.updateLink(person, theResource, outcome, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(person, theResource, outcome, EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
persons.add(person); persons.add(person);
} }
@ -115,51 +115,51 @@ public class EmpiMatchLinkSvc {
.forEach(possibleDuplicatePerson -> { .forEach(possibleDuplicatePerson -> {
EmpiMatchOutcome outcome = EmpiMatchOutcome.POSSIBLE_DUPLICATE; EmpiMatchOutcome outcome = EmpiMatchOutcome.POSSIBLE_DUPLICATE;
outcome.setEidMatch(theCandidateList.isEidMatch()); outcome.setEidMatch(theCandidateList.isEidMatch());
myEmpiLinkSvc.updateLink(firstPerson, possibleDuplicatePerson, outcome, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(firstPerson, possibleDuplicatePerson, outcome, EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
}); });
} }
} }
private void handleEmpiWithNoCandidates(IAnyResource theResource, EmpiTransactionContext theEmpiTransactionContext) { private void handleEmpiWithNoCandidates(IAnyResource theResource, MdmTransactionContext theMdmTransactionContext) {
log(theEmpiTransactionContext, String.format("There were no matched candidates for EMPI, creating a new %s.", theResource.getIdElement().getResourceType())); log(theMdmTransactionContext, String.format("There were no matched candidates for EMPI, creating a new %s.", theResource.getIdElement().getResourceType()));
IAnyResource newPerson = myPersonHelper.createSourceResourceFromEmpiTarget(theResource); IAnyResource newPerson = myPersonHelper.createSourceResourceFromEmpiTarget(theResource);
// TODO GGG :) // TODO GGG :)
// 1. Get the right helper // 1. Get the right helper
// 2. Create source resoruce for the EMPI target // 2. Create source resoruce for the EMPI target
// 3. UPDATE EMPI LINK TABLE // 3. UPDATE EMPI LINK TABLE
myEmpiLinkSvc.updateLink(newPerson, theResource, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(newPerson, theResource, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
} }
private void handleEmpiCreate(IAnyResource theTargetResource, MatchedSourceResourceCandidate thePersonCandidate, EmpiTransactionContext theEmpiTransactionContext) { private void handleEmpiCreate(IAnyResource theTargetResource, MatchedSourceResourceCandidate thePersonCandidate, MdmTransactionContext theMdmTransactionContext) {
log(theEmpiTransactionContext, "EMPI has narrowed down to one candidate for matching."); log(theMdmTransactionContext, "EMPI has narrowed down to one candidate for matching.");
IAnyResource sourceResource = myEmpiSourceResourceFindingSvc.getSourceResourceFromMatchedSourceResourceCandidate(thePersonCandidate, theEmpiTransactionContext.getResourceType()); IAnyResource sourceResource = myEmpiSourceResourceFindingSvc.getSourceResourceFromMatchedSourceResourceCandidate(thePersonCandidate, theMdmTransactionContext.getResourceType());
if (myPersonHelper.isPotentialDuplicate(sourceResource, theTargetResource)) { if (myPersonHelper.isPotentialDuplicate(sourceResource, theTargetResource)) {
log(theEmpiTransactionContext, "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 newSourceResource = myPersonHelper.createSourceResourceFromEmpiTarget(theTargetResource); IAnyResource newSourceResource = myPersonHelper.createSourceResourceFromEmpiTarget(theTargetResource);
myEmpiLinkSvc.updateLink(newSourceResource, theTargetResource, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(newSourceResource, theTargetResource, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
myEmpiLinkSvc.updateLink(newSourceResource, sourceResource, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(newSourceResource, sourceResource, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
} else { } else {
if (thePersonCandidate.isMatch()) { if (thePersonCandidate.isMatch()) {
myPersonHelper.handleExternalEidAddition(sourceResource, theTargetResource, theEmpiTransactionContext); myPersonHelper.handleExternalEidAddition(sourceResource, theTargetResource, theMdmTransactionContext);
// myPersonHelper.updatePersonFromNewlyCreatedEmpiTarget(person, theResource, theEmpiTransactionContext); // myPersonHelper.updatePersonFromNewlyCreatedEmpiTarget(person, theResource, theEmpiTransactionContext);
} }
myEmpiLinkSvc.updateLink(sourceResource, theTargetResource, thePersonCandidate.getMatchResult(), EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext); myEmpiLinkSvc.updateLink(sourceResource, theTargetResource, thePersonCandidate.getMatchResult(), EmpiLinkSourceEnum.AUTO, theMdmTransactionContext);
} }
} }
private void handleEmpiWithSingleCandidate(IAnyResource theResource, MatchedSourceResourceCandidate thePersonCandidate, EmpiTransactionContext theEmpiTransactionContext) { private void handleEmpiWithSingleCandidate(IAnyResource theResource, MatchedSourceResourceCandidate thePersonCandidate, MdmTransactionContext theMdmTransactionContext) {
log(theEmpiTransactionContext, "EMPI has narrowed down to one candidate for matching."); log(theMdmTransactionContext, "EMPI has narrowed down to one candidate for matching.");
if (theEmpiTransactionContext.getRestOperation().equals(EmpiTransactionContext.OperationType.UPDATE_RESOURCE)) { if (theMdmTransactionContext.getRestOperation().equals(MdmTransactionContext.OperationType.UPDATE_RESOURCE)) {
myEidUpdateService.handleEmpiUpdate(theResource, thePersonCandidate, theEmpiTransactionContext); myEidUpdateService.handleEmpiUpdate(theResource, thePersonCandidate, theMdmTransactionContext);
} else { } else {
handleEmpiCreate(theResource, thePersonCandidate, theEmpiTransactionContext); handleEmpiCreate(theResource, thePersonCandidate, theMdmTransactionContext);
} }
} }
private void log(EmpiTransactionContext theEmpiTransactionContext, String theMessage) { private void log(MdmTransactionContext theMdmTransactionContext, String theMessage) {
theEmpiTransactionContext.addTransactionLogMessage(theMessage); theMdmTransactionContext.addTransactionLogMessage(theMessage);
ourLog.debug(theMessage); ourLog.debug(theMessage);
} }
} }

View File

@ -23,9 +23,9 @@ package ca.uhn.fhir.jpa.empi.svc;
import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum; import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.api.IEmpiLinkSvc; import ca.uhn.fhir.empi.api.IEmpiLinkSvc;
import ca.uhn.fhir.empi.api.IEmpiPersonMergerSvc; import ca.uhn.fhir.empi.api.IGoldenResourceMergerSvc;
import ca.uhn.fhir.empi.log.Logs; import ca.uhn.fhir.empi.log.Logs;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.empi.util.PersonHelper; import ca.uhn.fhir.empi.util.PersonHelper;
import ca.uhn.fhir.jpa.dao.index.IdHelperService; import ca.uhn.fhir.jpa.dao.index.IdHelperService;
import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc; import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc;
@ -41,7 +41,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
@Service @Service
public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc { public class GoldenResourceMergerSvcImpl implements IGoldenResourceMergerSvc {
private static final Logger ourLog = Logs.getEmpiTroubleshootingLog(); private static final Logger ourLog = Logs.getEmpiTroubleshootingLog();
@Autowired @Autowired
@ -57,25 +57,26 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
@Override @Override
@Transactional @Transactional
public IAnyResource mergePersons(IAnyResource theFrom, IAnyResource theTo, EmpiTransactionContext theEmpiTransactionContext) { public IAnyResource mergeGoldenResources(IAnyResource theFromGoldenResource, IAnyResource theToGoldenResource, MdmTransactionContext theMdmTransactionContext) {
Long toPid = myIdHelperService.getPidOrThrowException(theTo); Long toGoldenResourcePid = myIdHelperService.getPidOrThrowException(theToGoldenResource);
// TODO NG - Revisit when merge rules are defined // TODO NG - Revisit when merge rules are defined
// myPersonHelper.mergeFields(theFrom, theTo); // myPersonHelper.mergeFields(theFrom, theTo);
mergeSourceResourceLinks(theFrom, theTo, toPid, theEmpiTransactionContext); mergeSourceResourceLinks(theFromGoldenResource, theToGoldenResource, toGoldenResourcePid, theMdmTransactionContext);
removeTargetLinks(theFrom, theTo, theEmpiTransactionContext);
refreshLinksAndUpdatePerson(theTo, theEmpiTransactionContext); removeTargetLinks(theFromGoldenResource, theToGoldenResource, theMdmTransactionContext);
Long fromPersonPid = myIdHelperService.getPidOrThrowException(theFrom); refreshLinksAndUpdatePerson(theToGoldenResource, theMdmTransactionContext);
addMergeLink(toPid, fromPersonPid);
myPersonHelper.deactivateResource(theFrom);
refreshLinksAndUpdatePerson(theFrom, theEmpiTransactionContext); Long fromGoldenResourcePid = myIdHelperService.getPidOrThrowException(theFromGoldenResource);
addMergeLink(toGoldenResourcePid, fromGoldenResourcePid, theMdmTransactionContext.getResourceType());
myPersonHelper.deactivateResource(theFromGoldenResource);
log(theEmpiTransactionContext, "Merged " + theFrom.getIdElement().toVersionless() + " into " + theTo.getIdElement().toVersionless()); refreshLinksAndUpdatePerson(theFromGoldenResource, theMdmTransactionContext);
return theTo;
log(theMdmTransactionContext, "Merged " + theFromGoldenResource.getIdElement().toVersionless() + " into " + theToGoldenResource.getIdElement().toVersionless());
return theToGoldenResource;
} }
/** /**
@ -83,36 +84,36 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
* *
* @param theFrom Target of the link * @param theFrom Target of the link
* @param theTo Source resource of the link * @param theTo Source resource of the link
* @param theEmpiTransactionContext Context to keep track of the deletions * @param theMdmTransactionContext Context to keep track of the deletions
*/ */
private void removeTargetLinks(IAnyResource theFrom, IAnyResource theTo, EmpiTransactionContext theEmpiTransactionContext) { private void removeTargetLinks(IAnyResource theFrom, IAnyResource theTo, MdmTransactionContext theMdmTransactionContext) {
List<EmpiLink> allLinksWithTheFromAsTarget = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theFrom); List<EmpiLink> allLinksWithTheFromAsTarget = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theFrom);
allLinksWithTheFromAsTarget allLinksWithTheFromAsTarget
.stream() .stream()
.filter(EmpiLink::isAuto) // only keep manual links .filter(EmpiLink::isAuto) // only keep manual links
.forEach(l -> { .forEach(l -> {
theEmpiTransactionContext.addTransactionLogMessage(String.format("Deleting link %s", l)); theMdmTransactionContext.addTransactionLogMessage(String.format("Deleting link %s", l));
myEmpiLinkDaoSvc.deleteLink(l); myEmpiLinkDaoSvc.deleteLink(l);
}); });
} }
private void addMergeLink(Long theSourceResourcePidAkaActive, Long theTargetResourcePidAkaDeactivated) { private void addMergeLink(Long theSourceResourcePidAkaActive, Long theTargetResourcePidAkaDeactivated, String theResourceType) {
EmpiLink empiLink = myEmpiLinkDaoSvc EmpiLink empiLink = myEmpiLinkDaoSvc
.getOrCreateEmpiLinkBySourceResourcePidAndTargetResourcePid(theSourceResourcePidAkaActive, theTargetResourcePidAkaDeactivated); .getOrCreateEmpiLinkBySourceResourcePidAndTargetResourcePid(theSourceResourcePidAkaActive, theTargetResourcePidAkaDeactivated);
empiLink empiLink
.setEmpiTargetType("Person") .setEmpiTargetType(theResourceType)
.setMatchResult(EmpiMatchResultEnum.REDIRECT) .setMatchResult(EmpiMatchResultEnum.REDIRECT)
.setLinkSource(EmpiLinkSourceEnum.MANUAL); .setLinkSource(EmpiLinkSourceEnum.MANUAL);
myEmpiLinkDaoSvc.save(empiLink); myEmpiLinkDaoSvc.save(empiLink);
} }
private void refreshLinksAndUpdatePerson(IAnyResource theToPerson, EmpiTransactionContext theEmpiTransactionContext) { private void refreshLinksAndUpdatePerson(IAnyResource theToPerson, MdmTransactionContext theMdmTransactionContext) {
// myEmpiLinkSvc.syncEmpiLinksToPersonLinks(theToPerson, theEmpiTransactionContext); // myEmpiLinkSvc.syncEmpiLinksToPersonLinks(theToPerson, theEmpiTransactionContext);
myEmpiResourceDaoSvc.upsertSourceResource(theToPerson, theEmpiTransactionContext.getResourceType()); myEmpiResourceDaoSvc.upsertSourceResource(theToPerson, theMdmTransactionContext.getResourceType());
} }
private void mergeSourceResourceLinks(IAnyResource theFromResource, IAnyResource theToResource, Long theToResourcePid, EmpiTransactionContext theEmpiTransactionContext) { private void mergeSourceResourceLinks(IAnyResource theFromResource, IAnyResource theToResource, Long theToResourcePid, MdmTransactionContext theMdmTransactionContext) {
List<EmpiLink> fromLinks = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theFromResource); // fromLinks - links going to theFromResource List<EmpiLink> fromLinks = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theFromResource); // fromLinks - links going to theFromResource
List<EmpiLink> toLinks = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theToResource); // toLinks - links going to theToResource List<EmpiLink> toLinks = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theToResource); // toLinks - links going to theToResource
@ -153,8 +154,8 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
.findFirst(); .findFirst();
} }
private void log(EmpiTransactionContext theEmpiTransactionContext, String theMessage) { private void log(MdmTransactionContext theMdmTransactionContext, String theMessage) {
theEmpiTransactionContext.addTransactionLogMessage(theMessage); theMdmTransactionContext.addTransactionLogMessage(theMessage);
ourLog.debug(theMessage); ourLog.debug(theMessage);
} }
} }

View File

@ -5,7 +5,7 @@ import ca.uhn.fhir.empi.api.EmpiConstants;
import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum; import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.api.IEmpiSettings; import ca.uhn.fhir.empi.api.IEmpiSettings;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.empi.rules.svc.EmpiResourceMatcherSvc; import ca.uhn.fhir.empi.rules.svc.EmpiResourceMatcherSvc;
import ca.uhn.fhir.empi.util.EIDHelper; import ca.uhn.fhir.empi.util.EIDHelper;
import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster;
@ -38,7 +38,6 @@ import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.ContactPoint; import org.hl7.fhir.r4.model.ContactPoint;
@ -338,17 +337,17 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
return theMedication; return theMedication;
} }
protected EmpiTransactionContext createContextForCreate(String theResourceType) { protected MdmTransactionContext createContextForCreate(String theResourceType) {
EmpiTransactionContext ctx = new EmpiTransactionContext(); MdmTransactionContext ctx = new MdmTransactionContext();
ctx.setRestOperation(EmpiTransactionContext.OperationType.CREATE_RESOURCE); ctx.setRestOperation(MdmTransactionContext.OperationType.CREATE_RESOURCE);
ctx.setResourceType(theResourceType); ctx.setResourceType(theResourceType);
ctx.setTransactionLogMessages(null); ctx.setTransactionLogMessages(null);
return ctx; return ctx;
} }
protected EmpiTransactionContext createContextForUpdate(String theResourceType) { protected MdmTransactionContext createContextForUpdate(String theResourceType) {
EmpiTransactionContext ctx = new EmpiTransactionContext(); MdmTransactionContext ctx = new MdmTransactionContext();
ctx.setRestOperation(EmpiTransactionContext.OperationType.UPDATE_RESOURCE); ctx.setRestOperation(MdmTransactionContext.OperationType.UPDATE_RESOURCE);
ctx.setTransactionLogMessages(null); ctx.setTransactionLogMessages(null);
ctx.setResourceType(theResourceType); ctx.setResourceType(theResourceType);
return ctx; return ctx;

View File

@ -3,8 +3,8 @@ package ca.uhn.fhir.jpa.empi.svc;
import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum; import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
import ca.uhn.fhir.empi.api.EmpiMatchOutcome; import ca.uhn.fhir.empi.api.EmpiMatchOutcome;
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.api.IEmpiPersonMergerSvc; import ca.uhn.fhir.empi.api.IGoldenResourceMergerSvc;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.interceptor.api.IInterceptorService; import ca.uhn.fhir.interceptor.api.IInterceptorService;
import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test; import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test;
import ca.uhn.fhir.jpa.empi.helper.EmpiLinkHelper; import ca.uhn.fhir.jpa.empi.helper.EmpiLinkHelper;
@ -46,7 +46,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
private static final EmpiMatchOutcome POSSIBLE_MATCH = new EmpiMatchOutcome(null, null).setMatchResultEnum(EmpiMatchResultEnum.POSSIBLE_MATCH); private static final EmpiMatchOutcome POSSIBLE_MATCH = new EmpiMatchOutcome(null, null).setMatchResultEnum(EmpiMatchResultEnum.POSSIBLE_MATCH);
@Autowired @Autowired
IEmpiPersonMergerSvc myEmpiPersonMergerSvc; IGoldenResourceMergerSvc myEmpiPersonMergerSvc;
@Autowired @Autowired
EmpiLinkHelper myEmpiLinkHelper; EmpiLinkHelper myEmpiLinkHelper;
@Autowired @Autowired
@ -102,7 +102,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
private Patient mergeSourcePatients() { private Patient mergeSourcePatients() {
assertEquals(0, redirectLinkCount()); assertEquals(0, redirectLinkCount());
Patient retval = (Patient) myEmpiPersonMergerSvc.mergePersons(myFromSourcePatient, myToSourcePatient, createEmpiContext()); Patient retval = (Patient) myEmpiPersonMergerSvc.mergeGoldenResources(myFromSourcePatient, myToSourcePatient, createEmpiContext());
assertEquals(1, redirectLinkCount()); assertEquals(1, redirectLinkCount());
return retval; return retval;
} }
@ -113,10 +113,10 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
return myEmpiLinkDao.findAll(example).size(); return myEmpiLinkDao.findAll(example).size();
} }
private EmpiTransactionContext createEmpiContext() { private MdmTransactionContext createEmpiContext() {
EmpiTransactionContext empiTransactionContext = new EmpiTransactionContext(TransactionLogMessages.createFromTransactionGuid(UUID.randomUUID().toString()), EmpiTransactionContext.OperationType.MERGE_PERSONS); MdmTransactionContext mdmTransactionContext = new MdmTransactionContext(TransactionLogMessages.createFromTransactionGuid(UUID.randomUUID().toString()), MdmTransactionContext.OperationType.MERGE_PERSONS);
empiTransactionContext.setResourceType("Patient"); mdmTransactionContext.setResourceType("Patient");
return empiTransactionContext; return mdmTransactionContext;
} }
@Test @Test

View File

@ -20,16 +20,16 @@ package ca.uhn.fhir.empi.api;
* #L% * #L%
*/ */
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.stream.Stream; import java.util.stream.Stream;
public interface IEmpiControllerSvc { public interface IEmpiControllerSvc {
Stream<EmpiLinkJson> queryLinks(@Nullable String thePersonId, @Nullable String theTargetId, @Nullable String theMatchResult, @Nullable String theLinkSource, EmpiTransactionContext theEmpiContext); Stream<EmpiLinkJson> queryLinks(@Nullable String thePersonId, @Nullable String theTargetId, @Nullable String theMatchResult, @Nullable String theLinkSource, MdmTransactionContext theEmpiContext);
Stream<EmpiLinkJson> getDuplicateGoldenResources(EmpiTransactionContext theEmpiContext); Stream<EmpiLinkJson> getDuplicateGoldenResources(MdmTransactionContext theEmpiContext);
void notDuplicateGoldenResource(String thePersonId, String theTargetPersonId, EmpiTransactionContext theEmpiContext); void notDuplicateGoldenResource(String thePersonId, String theTargetPersonId, MdmTransactionContext theEmpiContext);
IAnyResource mergeGoldenResources(String theFromPersonId, String theToPersonId, EmpiTransactionContext theEmpiTransactionContext); IAnyResource mergeGoldenResources(String theFromPersonId, String theToPersonId, MdmTransactionContext theMdmTransactionContext);
IAnyResource updateLink(String thePersonId, String theTargetId, String theMatchResult, EmpiTransactionContext theEmpiContext); IAnyResource updateLink(String thePersonId, String theTargetId, String theMatchResult, MdmTransactionContext theEmpiContext);
} }

View File

@ -20,7 +20,7 @@ package ca.uhn.fhir.empi.api;
* #L% * #L%
*/ */
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -29,6 +29,6 @@ import java.util.stream.Stream;
* This service supports the EMPI Operation providers for those services that return multiple empi links. * This service supports the EMPI Operation providers for those services that return multiple empi links.
*/ */
public interface IEmpiLinkQuerySvc { public interface IEmpiLinkQuerySvc {
Stream<EmpiLinkJson> queryLinks(IIdType thePersonId, IIdType theTargetId, EmpiMatchResultEnum theMatchResult, EmpiLinkSourceEnum theLinkSource, EmpiTransactionContext theEmpiContext); Stream<EmpiLinkJson> queryLinks(IIdType thePersonId, IIdType theTargetId, EmpiMatchResultEnum theMatchResult, EmpiLinkSourceEnum theLinkSource, MdmTransactionContext theEmpiContext);
Stream<EmpiLinkJson> getDuplicatePersons(EmpiTransactionContext theEmpiContext); Stream<EmpiLinkJson> getDuplicatePersons(MdmTransactionContext theEmpiContext);
} }

View File

@ -20,7 +20,7 @@ package ca.uhn.fhir.empi.api;
* #L% * #L%
*/ */
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
public interface IEmpiLinkSvc { public interface IEmpiLinkSvc {
@ -32,9 +32,9 @@ public interface IEmpiLinkSvc {
* @param theTargetResource the target resource, which is a Patient or Practitioner * @param theTargetResource the target resource, which is a Patient or Practitioner
* @param theMatchResult the current status of the match to set the link to. * @param theMatchResult the current status of the match to set the link to.
* @param theLinkSource MANUAL or AUTO: what caused the link. * @param theLinkSource MANUAL or AUTO: what caused the link.
* @param theEmpiTransactionContext * @param theMdmTransactionContext
*/ */
void updateLink(IAnyResource thePerson, IAnyResource theTargetResource, EmpiMatchOutcome theMatchResult, EmpiLinkSourceEnum theLinkSource, EmpiTransactionContext theEmpiTransactionContext); void updateLink(IAnyResource thePerson, IAnyResource theTargetResource, EmpiMatchOutcome theMatchResult, EmpiLinkSourceEnum theLinkSource, MdmTransactionContext theMdmTransactionContext);
// /** // /**
// * Replace Person.link values from what they should be based on EmpiLink values // * Replace Person.link values from what they should be based on EmpiLink values
@ -47,5 +47,5 @@ public interface IEmpiLinkSvc {
* @param theExistingPerson * @param theExistingPerson
* @param theResource * @param theResource
*/ */
void deleteLink(IAnyResource theExistingPerson, IAnyResource theResource, EmpiTransactionContext theEmpiTransactionContext); void deleteLink(IAnyResource theExistingPerson, IAnyResource theResource, MdmTransactionContext theMdmTransactionContext);
} }

View File

@ -20,10 +20,10 @@ package ca.uhn.fhir.empi.api;
* #L% * #L%
*/ */
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
public interface IEmpiLinkUpdaterSvc { public interface IEmpiLinkUpdaterSvc {
IAnyResource updateLink(IAnyResource thePerson, IAnyResource theTarget, EmpiMatchResultEnum theMatchResult, EmpiTransactionContext theEmpiContext); IAnyResource updateLink(IAnyResource thePerson, IAnyResource theTarget, EmpiMatchResultEnum theMatchResult, MdmTransactionContext theEmpiContext);
void notDuplicatePerson(IAnyResource thePerson, IAnyResource theTarget, EmpiTransactionContext theEmpiContext); void notDuplicatePerson(IAnyResource thePerson, IAnyResource theTarget, MdmTransactionContext theEmpiContext);
} }

View File

@ -20,16 +20,16 @@ package ca.uhn.fhir.empi.api;
* #L% * #L%
*/ */
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
public interface IEmpiPersonMergerSvc { public interface IGoldenResourceMergerSvc {
/** /**
* Move all links from the theFromPerson to theToPerson and then set active=false on theFromPerson. Merge all Person * Move all links from the theFromGoldenResource to theToGoldenResource and then set active=false on theFromGoldenResource. Merge all Person
* fields. * fields.
* @param theFromPerson the person we are merging from * @param theFromGoldenResource the person we are merging from
* @param theToPerson the person we are merging to * @param theToGoldenResource the person we are merging to
* @return updated theToPerson with the merged fields and links. * @return updated theToGoldenResource with the merged fields and links.
*/ */
IAnyResource mergePersons(IAnyResource theFromPerson, IAnyResource theToPerson, EmpiTransactionContext theEmpiTransactionContext); IAnyResource mergeGoldenResources(IAnyResource theFromGoldenResource, IAnyResource theToGoldenResource, MdmTransactionContext theMdmTransactionContext);
} }

View File

@ -22,7 +22,7 @@ package ca.uhn.fhir.empi.model;
import ca.uhn.fhir.rest.server.TransactionLogMessages; import ca.uhn.fhir.rest.server.TransactionLogMessages;
public class EmpiTransactionContext { public class MdmTransactionContext {
public enum OperationType { public enum OperationType {
CREATE_RESOURCE, CREATE_RESOURCE,
@ -48,15 +48,15 @@ public class EmpiTransactionContext {
return myTransactionLogMessages; return myTransactionLogMessages;
} }
public EmpiTransactionContext() { public MdmTransactionContext() {
} }
public EmpiTransactionContext(TransactionLogMessages theTransactionLogMessages, OperationType theRestOperation) { public MdmTransactionContext(TransactionLogMessages theTransactionLogMessages, OperationType theRestOperation) {
myTransactionLogMessages = theTransactionLogMessages; myTransactionLogMessages = theTransactionLogMessages;
myRestOperation = theRestOperation; myRestOperation = theRestOperation;
} }
public EmpiTransactionContext(TransactionLogMessages theTransactionLogMessages, OperationType theRestOperation, String theResourceType) { public MdmTransactionContext(TransactionLogMessages theTransactionLogMessages, OperationType theRestOperation, String theResourceType) {
this(theTransactionLogMessages, theRestOperation); this(theTransactionLogMessages, theRestOperation);
setResourceType(theResourceType); setResourceType(theResourceType);
} }

View File

@ -23,7 +23,7 @@ package ca.uhn.fhir.empi.provider;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.empi.api.EmpiLinkJson; import ca.uhn.fhir.empi.api.EmpiLinkJson;
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.TransactionLogMessages; import ca.uhn.fhir.rest.server.TransactionLogMessages;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -77,9 +77,9 @@ public abstract class BaseEmpiProvider {
validateNotNull(ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, theResourceId); validateNotNull(ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, theResourceId);
} }
protected EmpiTransactionContext createMdmContext(RequestDetails theRequestDetails, EmpiTransactionContext.OperationType theOperationType) { protected MdmTransactionContext createMdmContext(RequestDetails theRequestDetails, MdmTransactionContext.OperationType theOperationType) {
TransactionLogMessages transactionLogMessages = TransactionLogMessages.createFromTransactionGuid(theRequestDetails.getTransactionGuid()); TransactionLogMessages transactionLogMessages = TransactionLogMessages.createFromTransactionGuid(theRequestDetails.getTransactionGuid());
return new EmpiTransactionContext(transactionLogMessages, theOperationType); return new MdmTransactionContext(transactionLogMessages, theOperationType);
} }
protected String extractStringOrNull(IPrimitiveType<String> theString) { protected String extractStringOrNull(IPrimitiveType<String> theString) {

View File

@ -28,7 +28,7 @@ import ca.uhn.fhir.empi.api.IEmpiExpungeSvc;
import ca.uhn.fhir.empi.api.IEmpiMatchFinderSvc; import ca.uhn.fhir.empi.api.IEmpiMatchFinderSvc;
import ca.uhn.fhir.empi.api.IEmpiSubmitSvc; import ca.uhn.fhir.empi.api.IEmpiSubmitSvc;
import ca.uhn.fhir.empi.api.MatchedTarget; import ca.uhn.fhir.empi.api.MatchedTarget;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.OperationParam;
@ -115,7 +115,7 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
RequestDetails theRequestDetails) { RequestDetails theRequestDetails) {
validateMergeParameters(theFromPersonId, theToPersonId); validateMergeParameters(theFromPersonId, theToPersonId);
return (Person) myEmpiControllerSvc.mergeGoldenResources(theFromPersonId.getValue(), theToPersonId.getValue(), createMdmContext(theRequestDetails, EmpiTransactionContext.OperationType.MERGE_PERSONS)); return (Person) myEmpiControllerSvc.mergeGoldenResources(theFromPersonId.getValue(), theToPersonId.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.MERGE_PERSONS));
} }
@Operation(name = ProviderConstants.MDM_UPDATE_LINK, type = Person.class) @Operation(name = ProviderConstants.MDM_UPDATE_LINK, type = Person.class)
@ -126,7 +126,7 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
validateUpdateLinkParameters(thePersonId, theTargetId, theMatchResult); validateUpdateLinkParameters(thePersonId, theTargetId, theMatchResult);
return (Person) myEmpiControllerSvc.updateLink(thePersonId.getValue(), theTargetId.getValue(), theMatchResult.getValue(), createMdmContext(theRequestDetails, EmpiTransactionContext.OperationType.UPDATE_LINK)); return (Person) myEmpiControllerSvc.updateLink(thePersonId.getValue(), theTargetId.getValue(), theMatchResult.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.UPDATE_LINK));
} }
@Operation(name = ProviderConstants.MDM_QUERY_LINKS) @Operation(name = ProviderConstants.MDM_QUERY_LINKS)
@ -136,13 +136,13 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
@OperationParam(name=ProviderConstants.EMPI_QUERY_LINKS_MATCH_RESULT, min = 0, max = 1) StringType theLinkSource, @OperationParam(name=ProviderConstants.EMPI_QUERY_LINKS_MATCH_RESULT, min = 0, max = 1) StringType theLinkSource,
ServletRequestDetails theRequestDetails) { ServletRequestDetails theRequestDetails) {
Stream<EmpiLinkJson> empiLinkJson = myEmpiControllerSvc.queryLinks(extractStringOrNull(thePersonId), extractStringOrNull(theTargetId), extractStringOrNull(theMatchResult), extractStringOrNull(theLinkSource), createMdmContext(theRequestDetails, EmpiTransactionContext.OperationType.QUERY_LINKS)); Stream<EmpiLinkJson> empiLinkJson = myEmpiControllerSvc.queryLinks(extractStringOrNull(thePersonId), extractStringOrNull(theTargetId), extractStringOrNull(theMatchResult), extractStringOrNull(theLinkSource), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.QUERY_LINKS));
return (Parameters) parametersFromEmpiLinks(empiLinkJson, true); return (Parameters) parametersFromEmpiLinks(empiLinkJson, true);
} }
@Operation(name = ProviderConstants.MDM_DUPLICATE_GOLDEN_RESOURCES) @Operation(name = ProviderConstants.MDM_DUPLICATE_GOLDEN_RESOURCES)
public Parameters getDuplicatePersons(ServletRequestDetails theRequestDetails) { public Parameters getDuplicatePersons(ServletRequestDetails theRequestDetails) {
Stream<EmpiLinkJson> possibleDuplicates = myEmpiControllerSvc.getDuplicateGoldenResources(createMdmContext(theRequestDetails, EmpiTransactionContext.OperationType.QUERY_LINKS)); Stream<EmpiLinkJson> possibleDuplicates = myEmpiControllerSvc.getDuplicateGoldenResources(createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.QUERY_LINKS));
return (Parameters) parametersFromEmpiLinks(possibleDuplicates, false); return (Parameters) parametersFromEmpiLinks(possibleDuplicates, false);
} }
@ -153,7 +153,7 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
ServletRequestDetails theRequestDetails) { ServletRequestDetails theRequestDetails) {
validateNotDuplicateParameters(thePersonId, theTargetId); validateNotDuplicateParameters(thePersonId, theTargetId);
myEmpiControllerSvc.notDuplicateGoldenResource(thePersonId.getValue(), theTargetId.getValue(), createMdmContext(theRequestDetails, EmpiTransactionContext.OperationType.NOT_DUPLICATE)); myEmpiControllerSvc.notDuplicateGoldenResource(thePersonId.getValue(), theTargetId.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.NOT_DUPLICATE));
Parameters retval = (Parameters) ParametersUtil.newInstance(myFhirContext); Parameters retval = (Parameters) ParametersUtil.newInstance(myFhirContext);
ParametersUtil.addParameterToParametersBoolean(myFhirContext, retval, "success", true); ParametersUtil.addParameterToParametersBoolean(myFhirContext, retval, "success", true);

View File

@ -28,7 +28,7 @@ import ca.uhn.fhir.empi.api.IEmpiExpungeSvc;
import ca.uhn.fhir.empi.api.IEmpiMatchFinderSvc; import ca.uhn.fhir.empi.api.IEmpiMatchFinderSvc;
import ca.uhn.fhir.empi.api.IEmpiSubmitSvc; import ca.uhn.fhir.empi.api.IEmpiSubmitSvc;
import ca.uhn.fhir.empi.api.MatchedTarget; import ca.uhn.fhir.empi.api.MatchedTarget;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.OperationParam;
@ -150,7 +150,7 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
RequestDetails theRequestDetails) { RequestDetails theRequestDetails) {
validateMergeParameters(theFromGoldenResourceId, theToGoldenResourceId); validateMergeParameters(theFromGoldenResourceId, theToGoldenResourceId);
return myEmpiControllerSvc.mergeGoldenResources(theFromGoldenResourceId.getValue(), theToGoldenResourceId.getValue(), createMdmContext(theRequestDetails, EmpiTransactionContext.OperationType.MERGE_PERSONS)); return myEmpiControllerSvc.mergeGoldenResources(theFromGoldenResourceId.getValue(), theToGoldenResourceId.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.MERGE_PERSONS));
} }
@Operation(name = ProviderConstants.MDM_UPDATE_LINK) @Operation(name = ProviderConstants.MDM_UPDATE_LINK)
@ -161,7 +161,7 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
validateUpdateLinkParameters(theGoldenResourceId, theResourceId, theMatchResult); validateUpdateLinkParameters(theGoldenResourceId, theResourceId, theMatchResult);
return myEmpiControllerSvc.updateLink(theGoldenResourceId.getValueNotNull(), theResourceId.getValue(), theMatchResult.getValue(), createMdmContext(theRequestDetails, EmpiTransactionContext.OperationType.UPDATE_LINK)); return myEmpiControllerSvc.updateLink(theGoldenResourceId.getValueNotNull(), theResourceId.getValue(), theMatchResult.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.UPDATE_LINK));
} }
@Operation(name = ProviderConstants.MDM_CLEAR, returnParameters = { @Operation(name = ProviderConstants.MDM_CLEAR, returnParameters = {
@ -189,13 +189,13 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
@OperationParam(name=ProviderConstants.EMPI_QUERY_LINKS_LINK_SOURCE, min = 0, max = 1) StringType theLinkSource, @OperationParam(name=ProviderConstants.EMPI_QUERY_LINKS_LINK_SOURCE, min = 0, max = 1) StringType theLinkSource,
ServletRequestDetails theRequestDetails) { ServletRequestDetails theRequestDetails) {
Stream<EmpiLinkJson> empiLinkJson = myEmpiControllerSvc.queryLinks(extractStringOrNull(theGoldenResourceId), extractStringOrNull(theResourceId), extractStringOrNull(theMatchResult), extractStringOrNull(theLinkSource), createMdmContext(theRequestDetails, EmpiTransactionContext.OperationType.QUERY_LINKS)); Stream<EmpiLinkJson> empiLinkJson = myEmpiControllerSvc.queryLinks(extractStringOrNull(theGoldenResourceId), extractStringOrNull(theResourceId), extractStringOrNull(theMatchResult), extractStringOrNull(theLinkSource), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.QUERY_LINKS));
return (Parameters) parametersFromEmpiLinks(empiLinkJson, true); return (Parameters) parametersFromEmpiLinks(empiLinkJson, true);
} }
@Operation(name = ProviderConstants.MDM_DUPLICATE_GOLDEN_RESOURCES, idempotent = true) @Operation(name = ProviderConstants.MDM_DUPLICATE_GOLDEN_RESOURCES, idempotent = true)
public Parameters getDuplicateGoldenResources(ServletRequestDetails theRequestDetails) { public Parameters getDuplicateGoldenResources(ServletRequestDetails theRequestDetails) {
Stream<EmpiLinkJson> possibleDuplicates = myEmpiControllerSvc.getDuplicateGoldenResources(createMdmContext(theRequestDetails, EmpiTransactionContext.OperationType.DUPLICATE_GOLDEN_RESOURCES)); Stream<EmpiLinkJson> possibleDuplicates = myEmpiControllerSvc.getDuplicateGoldenResources(createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.DUPLICATE_GOLDEN_RESOURCES));
return (Parameters) parametersFromEmpiLinks(possibleDuplicates, false); return (Parameters) parametersFromEmpiLinks(possibleDuplicates, false);
} }
@ -205,7 +205,7 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
ServletRequestDetails theRequestDetails) { ServletRequestDetails theRequestDetails) {
validateNotDuplicateParameters(theGoldenResourceId, theResourceId); validateNotDuplicateParameters(theGoldenResourceId, theResourceId);
myEmpiControllerSvc.notDuplicateGoldenResource(theGoldenResourceId.getValue(), theResourceId.getValue(), createMdmContext(theRequestDetails, EmpiTransactionContext.OperationType.NOT_DUPLICATE)); myEmpiControllerSvc.notDuplicateGoldenResource(theGoldenResourceId.getValue(), theResourceId.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.NOT_DUPLICATE));
Parameters retval = (Parameters) ParametersUtil.newInstance(myFhirContext); Parameters retval = (Parameters) ParametersUtil.newInstance(myFhirContext);
ParametersUtil.addParameterToParametersBoolean(myFhirContext, retval, "success", true); ParametersUtil.addParameterToParametersBoolean(myFhirContext, retval, "success", true);

View File

@ -25,19 +25,17 @@ import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.empi.api.EmpiConstants;
import ca.uhn.fhir.empi.api.IEmpiLinkQuerySvc; import ca.uhn.fhir.empi.api.IEmpiLinkQuerySvc;
import ca.uhn.fhir.empi.api.IEmpiSettings; import ca.uhn.fhir.empi.api.IEmpiSettings;
import ca.uhn.fhir.empi.log.Logs; import ca.uhn.fhir.empi.log.Logs;
import ca.uhn.fhir.empi.model.CanonicalEID; import ca.uhn.fhir.empi.model.CanonicalEID;
import ca.uhn.fhir.empi.model.CanonicalIdentityAssuranceLevel; import ca.uhn.fhir.empi.model.CanonicalIdentityAssuranceLevel;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
import ca.uhn.fhir.fhirpath.IFhirPath; import ca.uhn.fhir.fhirpath.IFhirPath;
import ca.uhn.fhir.util.FhirTerser; import ca.uhn.fhir.util.FhirTerser;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseBackboneElement; import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
import org.hl7.fhir.instance.model.api.IBaseCoding;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.instance.model.api.IPrimitiveType;
@ -202,17 +200,17 @@ public class PersonHelper {
* @return the modified {@link IBaseResource} representing the person. * @return the modified {@link IBaseResource} representing the person.
*/ */
public IAnyResource updateSourceResourceExternalEidFromTargetResource(IAnyResource theSourceResource, IAnyResource public IAnyResource updateSourceResourceExternalEidFromTargetResource(IAnyResource theSourceResource, IAnyResource
theTargetResource, EmpiTransactionContext theEmpiTransactionContext) { theTargetResource, MdmTransactionContext theMdmTransactionContext) {
//This handles overwriting an automatically assigned EID if a patient that links is coming in with an official EID. //This handles overwriting an automatically assigned EID if a patient that links is coming in with an official EID.
List<CanonicalEID> incomingTargetEid = myEIDHelper.getExternalEid(theTargetResource); List<CanonicalEID> incomingTargetEid = myEIDHelper.getExternalEid(theTargetResource);
List<CanonicalEID> personOfficialEid = myEIDHelper.getExternalEid(theSourceResource); List<CanonicalEID> personOfficialEid = myEIDHelper.getExternalEid(theSourceResource);
if (!incomingTargetEid.isEmpty()) { if (!incomingTargetEid.isEmpty()) {
if (personOfficialEid.isEmpty() || !myEmpiConfig.isPreventMultipleEids()) { if (personOfficialEid.isEmpty() || !myEmpiConfig.isPreventMultipleEids()) {
log(theEmpiTransactionContext, "Incoming resource:" + theTargetResource.getIdElement().toUnqualifiedVersionless() + " + with EID " + incomingTargetEid.stream().map(CanonicalEID::toString).collect(Collectors.joining(",")) + " is applying this EIDs to its related Source Resource, as this Source Resource does not yet have an external EID"); log(theMdmTransactionContext, "Incoming resource:" + theTargetResource.getIdElement().toUnqualifiedVersionless() + " + with EID " + incomingTargetEid.stream().map(CanonicalEID::toString).collect(Collectors.joining(",")) + " is applying this EIDs to its related Source Resource, as this Source Resource does not yet have an external EID");
addCanonicalEidsToSourceResourceIfAbsent(theSourceResource, incomingTargetEid); addCanonicalEidsToSourceResourceIfAbsent(theSourceResource, incomingTargetEid);
} else if (!personOfficialEid.isEmpty() && myEIDHelper.eidMatchExists(personOfficialEid, incomingTargetEid)) { } else if (!personOfficialEid.isEmpty() && myEIDHelper.eidMatchExists(personOfficialEid, incomingTargetEid)) {
log(theEmpiTransactionContext, "incoming resource:" + theTargetResource.getIdElement().toVersionless() + " with EIDs " + incomingTargetEid.stream().map(CanonicalEID::toString).collect(Collectors.joining(",")) + " does not need to overwrite person, as this EID is already present"); log(theMdmTransactionContext, "incoming resource:" + theTargetResource.getIdElement().toVersionless() + " with EIDs " + incomingTargetEid.stream().map(CanonicalEID::toString).collect(Collectors.joining(",")) + " does not need to overwrite person, as this EID is already present");
} else { } else {
throw new IllegalArgumentException("This would create a duplicate person!"); throw new IllegalArgumentException("This would create a duplicate person!");
} }
@ -461,16 +459,16 @@ public class PersonHelper {
person.setLink(links); person.setLink(links);
} }
private void log(EmpiTransactionContext theEmpiTransactionContext, String theMessage) { private void log(MdmTransactionContext theMdmTransactionContext, String theMessage) {
theEmpiTransactionContext.addTransactionLogMessage(theMessage); theMdmTransactionContext.addTransactionLogMessage(theMessage);
ourLog.debug(theMessage); ourLog.debug(theMessage);
} }
public void handleExternalEidAddition(IAnyResource theSourceResource, IAnyResource theTargetResource, EmpiTransactionContext public void handleExternalEidAddition(IAnyResource theSourceResource, IAnyResource theTargetResource, MdmTransactionContext
theEmpiTransactionContext) { theMdmTransactionContext) {
List<CanonicalEID> eidFromResource = myEIDHelper.getExternalEid(theTargetResource); List<CanonicalEID> eidFromResource = myEIDHelper.getExternalEid(theTargetResource);
if (!eidFromResource.isEmpty()) { if (!eidFromResource.isEmpty()) {
updateSourceResourceExternalEidFromTargetResource(theSourceResource, theTargetResource, theEmpiTransactionContext); updateSourceResourceExternalEidFromTargetResource(theSourceResource, theTargetResource, theMdmTransactionContext);
} }
} }

View File

@ -1,10 +1,10 @@
package ca.uhn.fhir.empi.util; package ca.uhn.fhir.empi.util;
import ca.uhn.fhir.empi.model.EmpiTransactionContext; import ca.uhn.fhir.empi.model.MdmTransactionContext;
public class TestUtils { public class TestUtils {
public static EmpiTransactionContext createDummyContext() { public static MdmTransactionContext createDummyContext() {
EmpiTransactionContext context = new EmpiTransactionContext(); MdmTransactionContext context = new MdmTransactionContext();
return context; return context;
} }
} }