Renamed sourceResource to goldenResource

This commit is contained in:
Nick Goupinets 2020-11-27 16:53:47 -05:00
parent 36ce84335a
commit dc2a9e55c5
28 changed files with 210 additions and 217 deletions

View File

@ -157,10 +157,10 @@ public class MdmLink {
return this;
}
public MdmLink setGoldenResourcePid(Long theSourceResourcePid) {
setPersonPid(theSourceResourcePid);
public MdmLink setGoldenResourcePid(Long theGoldenResourcePid) {
setPersonPid(theGoldenResourcePid);
myGoldenResourcePid = theSourceResourcePid;
myGoldenResourcePid = theGoldenResourcePid;
return this;
}

View File

@ -60,11 +60,11 @@ public class MdmLinkDaoSvc {
private FhirContext myFhirContext;
@Transactional
public MdmLink createOrUpdateLinkEntity(IBaseResource theSourceResource, IBaseResource theTargetResource, MdmMatchOutcome theMatchOutcome, MdmLinkSourceEnum theLinkSource, @Nullable MdmTransactionContext theMdmTransactionContext) {
Long sourceResourcePid = myIdHelperService.getPidOrNull(theSourceResource);
public MdmLink createOrUpdateLinkEntity(IBaseResource theGoldenResource, IBaseResource theTargetResource, MdmMatchOutcome theMatchOutcome, MdmLinkSourceEnum theLinkSource, @Nullable MdmTransactionContext theMdmTransactionContext) {
Long goldenResourcePid = myIdHelperService.getPidOrNull(theGoldenResource);
Long targetResourcePid = myIdHelperService.getPidOrNull(theTargetResource);
MdmLink mdmLink = getOrCreateMdmLinkBySourceResourcePidAndTargetResourcePid(sourceResourcePid, targetResourcePid);
MdmLink mdmLink = getOrCreateMdmLinkByGoldenResourcePidAndTargetResourcePid(goldenResourcePid, targetResourcePid);
mdmLink.setLinkSource(theLinkSource);
mdmLink.setMatchResult(theMatchOutcome.getMatchResultEnum());
// Preserve these flags for link updates
@ -77,7 +77,7 @@ public class MdmLinkDaoSvc {
mdmLink.setScore(theMatchOutcome.score);
}
String message = String.format("Creating MdmLink from %s to %s -> %s", theSourceResource.getIdElement().toUnqualifiedVersionless(), theTargetResource.getIdElement().toUnqualifiedVersionless(), theMatchOutcome);
String message = String.format("Creating MdmLink from %s to %s -> %s", theGoldenResource.getIdElement().toUnqualifiedVersionless(), theTargetResource.getIdElement().toUnqualifiedVersionless(), theMatchOutcome);
theMdmTransactionContext.addTransactionLogMessage(message);
ourLog.debug(message);
save(mdmLink);
@ -85,26 +85,26 @@ public class MdmLinkDaoSvc {
}
@Nonnull
public MdmLink getOrCreateMdmLinkBySourceResourcePidAndTargetResourcePid(Long theSourceResourcePid, Long theTargetResourcePid) {
Optional<MdmLink> oExisting = getLinkBySourceResourcePidAndTargetResourcePid(theSourceResourcePid, theTargetResourcePid);
public MdmLink getOrCreateMdmLinkByGoldenResourcePidAndTargetResourcePid(Long theGoldenResourcePid, Long theTargetResourcePid) {
Optional<MdmLink> oExisting = getLinkByGoldenResourcePidAndTargetResourcePid(theGoldenResourcePid, theTargetResourcePid);
if (oExisting.isPresent()) {
return oExisting.get();
} else {
MdmLink newLink = myMdmLinkFactory.newMdmLink();
newLink.setGoldenResourcePid(theSourceResourcePid);
newLink.setPersonPid(theSourceResourcePid);
newLink.setGoldenResourcePid(theGoldenResourcePid);
newLink.setPersonPid(theGoldenResourcePid);
newLink.setTargetPid(theTargetResourcePid);
return newLink;
}
}
public Optional<MdmLink> getLinkBySourceResourcePidAndTargetResourcePid(Long theSourceResourcePid, Long theTargetResourcePid) {
if (theTargetResourcePid == null || theSourceResourcePid == null) {
public Optional<MdmLink> getLinkByGoldenResourcePidAndTargetResourcePid(Long theGoldenResourcePid, Long theTargetResourcePid) {
if (theTargetResourcePid == null || theGoldenResourcePid == null) {
return Optional.empty();
}
MdmLink link = myMdmLinkFactory.newMdmLink();
link.setTargetPid(theTargetResourcePid);
link.setGoldenResourcePid(theSourceResourcePid);
link.setGoldenResourcePid(theGoldenResourcePid);
Example<MdmLink> example = Example.of(link);
return myMdmLinkDao.findOne(example);
}
@ -309,14 +309,14 @@ public class MdmLinkDaoSvc {
}
/**
* Finds all {@link MdmLink} entities in which theSourceResource's PID is the source
* Finds all {@link MdmLink} entities in which theGoldenResource's PID is the source
* of the relationship.
*
* @param theSourceResource the source resource to find links for.
* @param theGoldenResource the source resource to find links for.
* @return all links for the source.
*/
public List<MdmLink> findMdmMatchLinksBySource(IBaseResource theSourceResource) {
Long pid = myIdHelperService.getPidOrNull(theSourceResource);
public List<MdmLink> findMdmMatchLinksBySource(IBaseResource theGoldenResource) {
Long pid = myIdHelperService.getPidOrNull(theGoldenResource);
if (pid == null) {
return Collections.emptyList();
}

View File

@ -80,7 +80,7 @@ public class GoldenResourceMergerSvcImpl implements IGoldenResourceMergerSvc {
myGoldenResourceHelper.deactivateResource(theFromGoldenResource);
//Save the deprecated resource.
myMdmResourceDaoSvc.upsertSourceResource(theFromGoldenResource, resourceType);
myMdmResourceDaoSvc.upsertGoldenResource(theFromGoldenResource, resourceType);
log(theMdmTransactionContext, "Merged " + theFromGoldenResource.getIdElement().toVersionless() + " into " + theToGoldenResource.getIdElement().toVersionless());
return theToGoldenResource;
@ -105,9 +105,9 @@ public class GoldenResourceMergerSvcImpl implements IGoldenResourceMergerSvc {
});
}
private void addMergeLink(Long theSourceResourcePidAkaActive, Long theTargetResourcePidAkaDeactivated, String theResourceType) {
private void addMergeLink(Long theGoldenResourcePidAkaActive, Long theTargetResourcePidAkaDeactivated, String theResourceType) {
MdmLink mdmLink = myMdmLinkDaoSvc
.getOrCreateMdmLinkBySourceResourcePidAndTargetResourcePid(theSourceResourcePidAkaActive, theTargetResourcePidAkaDeactivated);
.getOrCreateMdmLinkByGoldenResourcePidAndTargetResourcePid(theGoldenResourcePidAkaActive, theTargetResourcePidAkaDeactivated);
mdmLink
.setMdmTargetType(theResourceType)

View File

@ -31,7 +31,7 @@ import ca.uhn.fhir.mdm.util.EIDHelper;
import ca.uhn.fhir.mdm.util.GoldenResourceHelper;
import ca.uhn.fhir.jpa.mdm.dao.MdmLinkDaoSvc;
import ca.uhn.fhir.jpa.mdm.svc.candidate.MdmGoldenResourceFindingSvc;
import ca.uhn.fhir.jpa.mdm.svc.candidate.MatchedSourceResourceCandidate;
import ca.uhn.fhir.jpa.mdm.svc.candidate.MatchedGoldenResourceCandidate;
import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import org.hl7.fhir.instance.model.api.IAnyResource;
@ -62,39 +62,38 @@ public class MdmEidUpdateService {
@Autowired
private IMdmSettings myMdmSettings;
void handleMdmUpdate(IAnyResource theResource, MatchedSourceResourceCandidate theMatchedSourceResourceCandidate, MdmTransactionContext theMdmTransactionContext) {
MdmUpdateContext updateContext = new MdmUpdateContext(theMatchedSourceResourceCandidate, theResource);
void handleMdmUpdate(IAnyResource theResource, MatchedGoldenResourceCandidate theMatchedGoldenResourceCandidate, MdmTransactionContext theMdmTransactionContext) {
MdmUpdateContext updateContext = new MdmUpdateContext(theMatchedGoldenResourceCandidate, theResource);
if (updateContext.isRemainsMatchedToSamePerson()) {
// Copy over any new external EIDs which don't already exist.
// TODO NG - Eventually this call will use terser to clone data in, once the surviorship rules for copying data will be confirmed
// myPersonHelper.updatePersonFromUpdatedEmpiTarget(updateContext.getMatchedPerson(), theResource, theEmpiTransactionContext);
if (!updateContext.isIncomingResourceHasAnEid() || updateContext.isHasEidsInCommon()) {
//update to patient that uses internal EIDs only.
myMdmLinkSvc.updateLink(updateContext.getMatchedSourceResource(), theResource, theMatchedSourceResourceCandidate.getMatchResult(), MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
myMdmLinkSvc.updateLink(updateContext.getMatchedGoldenResource(), theResource, theMatchedGoldenResourceCandidate.getMatchResult(), MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
} else if (!updateContext.isHasEidsInCommon()) {
handleNoEidsInCommon(theResource, theMatchedSourceResourceCandidate, theMdmTransactionContext, updateContext);
handleNoEidsInCommon(theResource, theMatchedGoldenResourceCandidate, theMdmTransactionContext, updateContext);
}
} 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.
//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(), theMdmTransactionContext);
linkToNewPersonAndFlagAsDuplicate(theResource, updateContext.getExistingPerson(), updateContext.getMatchedGoldenResource(), theMdmTransactionContext);
}
}
private void handleNoEidsInCommon(IAnyResource theResource, MatchedSourceResourceCandidate theMatchedSourceResourceCandidate, MdmTransactionContext theMdmTransactionContext, MdmUpdateContext theUpdateContext) {
private void handleNoEidsInCommon(IAnyResource theResource, MatchedGoldenResourceCandidate theMatchedGoldenResourceCandidate, MdmTransactionContext theMdmTransactionContext, MdmUpdateContext theUpdateContext) {
// the user is simply updating their EID. We propagate this change to the Person.
//overwrite. No EIDS in common, but still same person.
if (myMdmSettings.isPreventMultipleEids()) {
if (myMdmLinkDaoSvc.findMdmMatchLinksBySource(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.
handleExternalEidOverwrite(theUpdateContext.getMatchedSourceResource(), theResource, theMdmTransactionContext);
if (myMdmLinkDaoSvc.findMdmMatchLinksBySource(theUpdateContext.getMatchedGoldenResource()).size() <= 1) { // If there is only 0/1 link on the person, we can safely overwrite the EID.
handleExternalEidOverwrite(theUpdateContext.getMatchedGoldenResource(), theResource, theMdmTransactionContext);
} else { // If the person has multiple patients tied to it, we can't just overwrite the EID, so we split the person.
createNewPersonAndFlagAsDuplicate(theResource, theMdmTransactionContext, theUpdateContext.getExistingPerson());
}
} else {
myGoldenResourceHelper.handleExternalEidAddition(theUpdateContext.getMatchedSourceResource(), theResource, theMdmTransactionContext);
myGoldenResourceHelper.handleExternalEidAddition(theUpdateContext.getMatchedGoldenResource(), theResource, theMdmTransactionContext);
}
myMdmLinkSvc.updateLink(theUpdateContext.getMatchedSourceResource(), theResource, theMatchedSourceResourceCandidate.getMatchResult(), MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
myMdmLinkSvc.updateLink(theUpdateContext.getMatchedGoldenResource(), theResource, theMatchedGoldenResourceCandidate.getMatchResult(), MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
}
private void handleExternalEidOverwrite(IAnyResource thePerson, IAnyResource theResource, MdmTransactionContext theMdmTransactionContext) {
@ -104,7 +103,7 @@ public class MdmEidUpdateService {
}
}
private boolean candidateIsSameAsMdmLinkPerson(MdmLink theExistingMatchLink, MatchedSourceResourceCandidate thePersonCandidate) {
private boolean candidateIsSameAsMdmLinkPerson(MdmLink theExistingMatchLink, MatchedGoldenResourceCandidate thePersonCandidate) {
return theExistingMatchLink.getGoldenResourcePid().equals(thePersonCandidate.getCandidatePersonPid().getIdAsLong());
}
@ -137,18 +136,17 @@ public class MdmEidUpdateService {
private final boolean myIncomingResourceHasAnEid;
private IAnyResource myExistingPerson;
private boolean myRemainsMatchedToSamePerson;
private final IAnyResource myMatchedGoldenResource;
public IAnyResource getMatchedSourceResource() {
return myMatchedSourceResource;
public IAnyResource getMatchedGoldenResource() {
return myMatchedGoldenResource;
}
private final IAnyResource myMatchedSourceResource;
MdmUpdateContext(MatchedSourceResourceCandidate theMatchedSourceResourceCandidate, IAnyResource theResource) {
MdmUpdateContext(MatchedGoldenResourceCandidate theMatchedGoldenResourceCandidate, IAnyResource theResource) {
final String resourceType = theResource.getIdElement().getResourceType();
myMatchedSourceResource = myMdmGoldenResourceFindingSvc.getSourceResourceFromMatchedSourceResourceCandidate(theMatchedSourceResourceCandidate, resourceType);
myMatchedGoldenResource = myMdmGoldenResourceFindingSvc.getGoldenResourceFromMatchedGoldenResourceCandidate(theMatchedGoldenResourceCandidate, resourceType);
myHasEidsInCommon = myEIDHelper.hasEidOverlap(myMatchedSourceResource, theResource);
myHasEidsInCommon = myEIDHelper.hasEidOverlap(myMatchedGoldenResource, theResource);
myIncomingResourceHasAnEid = !myEIDHelper.getExternalEid(theResource).isEmpty();
Optional<MdmLink> theExistingMatchLink = myMdmLinkDaoSvc.getMatchedLinkForTarget(theResource);
@ -157,8 +155,8 @@ public class MdmEidUpdateService {
if (theExistingMatchLink.isPresent()) {
MdmLink mdmLink = theExistingMatchLink.get();
Long existingPersonPid = mdmLink.getGoldenResourcePid();
myExistingPerson = myMdmResourceDaoSvc.readSourceResourceByPid(new ResourcePersistentId(existingPersonPid), resourceType);
myRemainsMatchedToSamePerson = candidateIsSameAsMdmLinkPerson(mdmLink, theMatchedSourceResourceCandidate);
myExistingPerson = myMdmResourceDaoSvc.readGoldenResourceByPid(new ResourcePersistentId(existingPersonPid), resourceType);
myRemainsMatchedToSamePerson = candidateIsSameAsMdmLinkPerson(mdmLink, theMatchedGoldenResourceCandidate);
} else {
myRemainsMatchedToSamePerson = false;
}

View File

@ -70,7 +70,7 @@ public class MdmLinkSvcImpl implements IMdmLinkSvc {
MdmMatchResultEnum matchResultEnum = theMatchOutcome.getMatchResultEnum();
validateRequestIsLegal(thePerson, theTarget, matchResultEnum, theLinkSource);
myMdmResourceDaoSvc.upsertSourceResource(thePerson, theMdmTransactionContext.getResourceType());
myMdmResourceDaoSvc.upsertGoldenResource(thePerson, theMdmTransactionContext.getResourceType());
createOrUpdateLinkEntity(thePerson, theTarget, theMatchOutcome, theLinkSource, theMdmTransactionContext);
}
@ -83,12 +83,11 @@ public class MdmLinkSvcImpl implements IMdmLinkSvc {
}
@Override
public void deleteLink(IAnyResource theSourceResource, IAnyResource theTargetResource, MdmTransactionContext theMdmTransactionContext) {
Optional<MdmLink> optionalMdmLink = getMdmLinkForGoldenResourceTargetPair(theSourceResource, theTargetResource);
public void deleteLink(IAnyResource theGoldenResource, IAnyResource theTargetResource, MdmTransactionContext theMdmTransactionContext) {
Optional<MdmLink> optionalMdmLink = getMdmLinkForGoldenResourceTargetPair(theGoldenResource, theTargetResource);
if (optionalMdmLink.isPresent()) {
MdmLink mdmLink = optionalMdmLink.get();
log(theMdmTransactionContext, "Deleting MdmLink [" + theSourceResource.getIdElement().toVersionless() + " -> " + theTargetResource.getIdElement().toVersionless() + "] with result: " + mdmLink.getMatchResult());
log(theMdmTransactionContext, "Deleting MdmLink [" + theGoldenResource.getIdElement().toVersionless() + " -> " + theTargetResource.getIdElement().toVersionless() + "] with result: " + mdmLink.getMatchResult());
myMdmLinkDaoSvc.deleteLink(mdmLink);
}
}
@ -125,15 +124,15 @@ public class MdmLinkSvcImpl implements IMdmLinkSvc {
if (thePerson.getIdElement().getIdPart() == null || theCandidate.getIdElement().getIdPart() == null) {
return Optional.empty();
} else {
return myMdmLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(
return myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndTargetResourcePid(
myIdHelperService.getPidOrNull(thePerson),
myIdHelperService.getPidOrNull(theCandidate)
);
}
}
private void createOrUpdateLinkEntity(IBaseResource theSourceResource, IBaseResource theTargetResource, MdmMatchOutcome theMatchOutcome, MdmLinkSourceEnum theLinkSource, MdmTransactionContext theMdmTransactionContext) {
myMdmLinkDaoSvc.createOrUpdateLinkEntity(theSourceResource, theTargetResource, theMatchOutcome, theLinkSource, theMdmTransactionContext);
private void createOrUpdateLinkEntity(IBaseResource theGoldenResource, IBaseResource theTargetResource, MdmMatchOutcome theMatchOutcome, MdmLinkSourceEnum theLinkSource, MdmTransactionContext theMdmTransactionContext) {
myMdmLinkDaoSvc.createOrUpdateLinkEntity(theGoldenResource, theTargetResource, theMatchOutcome, theLinkSource, theMdmTransactionContext);
}
private void log(MdmTransactionContext theMdmTransactionContext, String theMessage) {

View File

@ -74,7 +74,7 @@ public class MdmLinkUpdaterSvcImpl implements IMdmLinkUpdaterSvc {
Long goldenResourceId = myIdHelperService.getPidOrThrowException(theGoldenResource);
Long targetId = myIdHelperService.getPidOrThrowException(theTarget);
Optional<MdmLink> optionalMdmLink = myMdmLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(goldenResourceId, targetId);
Optional<MdmLink> optionalMdmLink = myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndTargetResourcePid(goldenResourceId, targetId);
if (!optionalMdmLink.isPresent()) {
throw new InvalidRequestException(myMessageHelper.getMessageForNoLink(theGoldenResource, theTarget));
}
@ -89,7 +89,7 @@ public class MdmLinkUpdaterSvcImpl implements IMdmLinkUpdaterSvc {
mdmLink.setMatchResult(theMatchResult);
mdmLink.setLinkSource(MdmLinkSourceEnum.MANUAL);
myMdmLinkDaoSvc.save(mdmLink);
myMdmResourceDaoSvc.upsertSourceResource(theGoldenResource, theMdmContext.getResourceType());
myMdmResourceDaoSvc.upsertGoldenResource(theGoldenResource, theMdmContext.getResourceType());
if (theMatchResult == MdmMatchResultEnum.NO_MATCH) {
// Need to find a new Person to link this target to
myMdmMatchLinkSvc.updateMdmLinksForMdmTarget(theTarget, theMdmContext);
@ -134,7 +134,7 @@ public class MdmLinkUpdaterSvcImpl implements IMdmLinkUpdaterSvc {
Long personId = myIdHelperService.getPidOrThrowException(thePerson);
Long targetId = myIdHelperService.getPidOrThrowException(theTarget);
Optional<MdmLink> oMdmLink = myMdmLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(personId, targetId);
Optional<MdmLink> oMdmLink = myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndTargetResourcePid(personId, targetId);
if (!oMdmLink.isPresent()) {
throw new InvalidRequestException("No link exists between " + thePerson.getIdElement().toVersionless() + " and " + theTarget.getIdElement().toVersionless());
}

View File

@ -29,7 +29,7 @@ import ca.uhn.fhir.mdm.util.MdmUtil;
import ca.uhn.fhir.mdm.util.GoldenResourceHelper;
import ca.uhn.fhir.jpa.mdm.svc.candidate.CandidateList;
import ca.uhn.fhir.jpa.mdm.svc.candidate.MdmGoldenResourceFindingSvc;
import ca.uhn.fhir.jpa.mdm.svc.candidate.MatchedSourceResourceCandidate;
import ca.uhn.fhir.jpa.mdm.svc.candidate.MatchedGoldenResourceCandidate;
import ca.uhn.fhir.rest.server.TransactionLogMessages;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.slf4j.Logger;
@ -75,7 +75,7 @@ public class MdmMatchLinkSvc {
}
private MdmTransactionContext doMdmUpdate(IAnyResource theResource, MdmTransactionContext theMdmTransactionContext) {
CandidateList candidateList = myMdmGoldenResourceFindingSvc.findSourceResourceCandidates(theResource);
CandidateList candidateList = myMdmGoldenResourceFindingSvc.findGoldenResourceCandidates(theResource);
if (candidateList.isEmpty()) {
handleMdmWithNoCandidates(theResource, theMdmTransactionContext);
@ -88,7 +88,7 @@ public class MdmMatchLinkSvc {
}
private void handleMdmWithMultipleCandidates(IAnyResource theResource, CandidateList theCandidateList, MdmTransactionContext theMdmTransactionContext) {
MatchedSourceResourceCandidate firstMatch = theCandidateList.getFirstMatch();
MatchedGoldenResourceCandidate firstMatch = theCandidateList.getFirstMatch();
Long samplePersonPid = firstMatch.getCandidatePersonPid().getIdAsLong();
boolean allSamePerson = theCandidateList.stream()
.allMatch(candidate -> candidate.getCandidatePersonPid().getIdAsLong().equals(samplePersonPid));
@ -100,9 +100,9 @@ public class MdmMatchLinkSvc {
log(theMdmTransactionContext, "MDM received multiple match candidates, that were linked to different Persons. Setting POSSIBLE_DUPLICATES and POSSIBLE_MATCHES.");
//Set them all as POSSIBLE_MATCH
List<IAnyResource> persons = new ArrayList<>();
for (MatchedSourceResourceCandidate matchedSourceResourceCandidate : theCandidateList.getCandidates()) {
for (MatchedGoldenResourceCandidate matchedGoldenResourceCandidate : theCandidateList.getCandidates()) {
IAnyResource person = myMdmGoldenResourceFindingSvc
.getSourceResourceFromMatchedSourceResourceCandidate(matchedSourceResourceCandidate, theMdmTransactionContext.getResourceType());
.getGoldenResourceFromMatchedGoldenResourceCandidate(matchedGoldenResourceCandidate, theMdmTransactionContext.getResourceType());
MdmMatchOutcome outcome = MdmMatchOutcome.POSSIBLE_MATCH;
outcome.setEidMatch(theCandidateList.isEidMatch());
myMdmLinkSvc.updateLink(person, theResource, outcome, MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
@ -131,25 +131,25 @@ public class MdmMatchLinkSvc {
myMdmLinkSvc.updateLink(newGoldenResource, theResource, MdmMatchOutcome.NEW_PERSON_MATCH, MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
}
private void handleMdmCreate(IAnyResource theTargetResource, MatchedSourceResourceCandidate thePersonCandidate, MdmTransactionContext theMdmTransactionContext) {
private void handleMdmCreate(IAnyResource theTargetResource, MatchedGoldenResourceCandidate thePersonCandidate, MdmTransactionContext theMdmTransactionContext) {
log(theMdmTransactionContext, "MDM has narrowed down to one candidate for matching.");
IAnyResource sourceResource = myMdmGoldenResourceFindingSvc.getSourceResourceFromMatchedSourceResourceCandidate(thePersonCandidate, theMdmTransactionContext.getResourceType());
IAnyResource golenResource = myMdmGoldenResourceFindingSvc.getGoldenResourceFromMatchedGoldenResourceCandidate(thePersonCandidate, theMdmTransactionContext.getResourceType());
if (myGoldenResourceHelper.isPotentialDuplicate(sourceResource, theTargetResource)) {
if (myGoldenResourceHelper.isPotentialDuplicate(golenResource, theTargetResource)) {
log(theMdmTransactionContext, "Duplicate detected based on the fact that both resources have different external EIDs.");
IAnyResource newSourceResource = myGoldenResourceHelper.createGoldenResourceFromMdmTarget(theTargetResource);
myMdmLinkSvc.updateLink(newSourceResource, theTargetResource, MdmMatchOutcome.NEW_PERSON_MATCH, MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
myMdmLinkSvc.updateLink(newSourceResource, sourceResource, MdmMatchOutcome.POSSIBLE_DUPLICATE, MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
IAnyResource newGoldenResource = myGoldenResourceHelper.createGoldenResourceFromMdmTarget(theTargetResource);
myMdmLinkSvc.updateLink(newGoldenResource, theTargetResource, MdmMatchOutcome.NEW_PERSON_MATCH, MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
myMdmLinkSvc.updateLink(newGoldenResource, golenResource, MdmMatchOutcome.POSSIBLE_DUPLICATE, MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
} else {
if (thePersonCandidate.isMatch()) {
myGoldenResourceHelper.handleExternalEidAddition(sourceResource, theTargetResource, theMdmTransactionContext);
myGoldenResourceHelper.handleExternalEidAddition(golenResource, theTargetResource, theMdmTransactionContext);
//TODO MDM GGG/NG: eventually we need to add survivorship rules of attributes here. Currently no data is copied over except EIDs.
}
myMdmLinkSvc.updateLink(sourceResource, theTargetResource, thePersonCandidate.getMatchResult(), MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
myMdmLinkSvc.updateLink(golenResource, theTargetResource, thePersonCandidate.getMatchResult(), MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
}
}
private void handleMdmWithSingleCandidate(IAnyResource theResource, MatchedSourceResourceCandidate thePersonCandidate, MdmTransactionContext theMdmTransactionContext) {
private void handleMdmWithSingleCandidate(IAnyResource theResource, MatchedGoldenResourceCandidate thePersonCandidate, MdmTransactionContext theMdmTransactionContext) {
log(theMdmTransactionContext, "MDM has narrowed down to one candidate for matching.");
if (theMdmTransactionContext.getRestOperation().equals(MdmTransactionContext.OperationType.UPDATE_RESOURCE)) {
myEidUpdateService.handleMdmUpdate(theResource, thePersonCandidate, theMdmTransactionContext);

View File

@ -50,12 +50,12 @@ public class MdmResourceDaoSvc {
@Autowired
IMdmSettings myMdmSettings;
public DaoMethodOutcome upsertSourceResource(IAnyResource theSourceResource, String theResourceType) {
public DaoMethodOutcome upsertGoldenResource(IAnyResource theGoldenResource, String theResourceType) {
IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theResourceType);
if (theSourceResource.getIdElement().hasIdPart()) {
return resourceDao.update(theSourceResource);
if (theGoldenResource.getIdElement().hasIdPart()) {
return resourceDao.update(theGoldenResource);
} else {
return resourceDao.create(theSourceResource);
return resourceDao.create(theGoldenResource);
}
}
@ -69,9 +69,9 @@ public class MdmResourceDaoSvc {
resourceDao.removeTag(theGoldenResource.getIdElement(), TagTypeEnum.TAG, MdmConstants.SYSTEM_GOLDEN_RECORD_STATUS, MdmConstants.CODE_GOLDEN_RECORD);
}
public IAnyResource readSourceResourceByPid(ResourcePersistentId theSourceResourcePid, String theResourceType) {
public IAnyResource readGoldenResourceByPid(ResourcePersistentId theGoldenResourcePid, String theResourceType) {
IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theResourceType);
return (IAnyResource) resourceDao.readByPid(theSourceResourcePid);
return (IAnyResource) resourceDao.readByPid(theGoldenResourcePid);
}
//TODO GGG MDM address this

View File

@ -35,11 +35,11 @@ public abstract class BaseCandidateFinder {
CandidateList findCandidates(IAnyResource theTarget) {
CandidateList candidateList = new CandidateList(getStrategy());
candidateList.addAll(findMatchSourceResourceCandidates(theTarget));
candidateList.addAll(findMatchGoldenResourceCandidates(theTarget));
return candidateList;
}
protected abstract List<MatchedSourceResourceCandidate> findMatchSourceResourceCandidates(IAnyResource theTarget);
protected abstract List<MatchedGoldenResourceCandidate> findMatchGoldenResourceCandidates(IAnyResource theTarget);
protected abstract CandidateStrategyEnum getStrategy();
}

View File

@ -27,7 +27,7 @@ import java.util.stream.Stream;
public class CandidateList {
private final CandidateStrategyEnum myStrategy;
private final List<MatchedSourceResourceCandidate> myList = new ArrayList<>();
private final List<MatchedGoldenResourceCandidate> myList = new ArrayList<>();
public CandidateList(CandidateStrategyEnum theStrategy) {
myStrategy = theStrategy;
@ -41,9 +41,9 @@ public class CandidateList {
return myList.isEmpty();
}
public void addAll(List<MatchedSourceResourceCandidate> theList) { myList.addAll(theList); }
public void addAll(List<MatchedGoldenResourceCandidate> theList) { myList.addAll(theList); }
public MatchedSourceResourceCandidate getOnlyMatch() {
public MatchedGoldenResourceCandidate getOnlyMatch() {
assert myList.size() == 1;
return myList.get(0);
}
@ -52,15 +52,15 @@ public class CandidateList {
return myList.size()== 1;
}
public Stream<MatchedSourceResourceCandidate> stream() {
public Stream<MatchedGoldenResourceCandidate> stream() {
return myList.stream();
}
public List<MatchedSourceResourceCandidate> getCandidates() {
public List<MatchedGoldenResourceCandidate> getCandidates() {
return Collections.unmodifiableList(myList);
}
public MatchedSourceResourceCandidate getFirstMatch() {
public MatchedGoldenResourceCandidate getFirstMatch() {
return myList.get(0);
}

View File

@ -45,8 +45,8 @@ public class FindCandidateByEidSvc extends BaseCandidateFinder {
@Autowired
private MdmResourceDaoSvc myMdmResourceDaoSvc;
protected List<MatchedSourceResourceCandidate> findMatchSourceResourceCandidates(IAnyResource theBaseResource) {
List<MatchedSourceResourceCandidate> retval = new ArrayList<>();
protected List<MatchedGoldenResourceCandidate> findMatchGoldenResourceCandidates(IAnyResource theBaseResource) {
List<MatchedGoldenResourceCandidate> retval = new ArrayList<>();
List<CanonicalEID> eidFromResource = myEIDHelper.getExternalEid(theBaseResource);
if (!eidFromResource.isEmpty()) {
@ -55,7 +55,7 @@ public class FindCandidateByEidSvc extends BaseCandidateFinder {
if (oFoundPerson.isPresent()) {
IAnyResource foundPerson = oFoundPerson.get();
Long pidOrNull = myIdHelperService.getPidOrNull(foundPerson);
MatchedSourceResourceCandidate mpc = new MatchedSourceResourceCandidate(new ResourcePersistentId(pidOrNull), MdmMatchOutcome.EID_MATCH);
MatchedGoldenResourceCandidate mpc = new MatchedGoldenResourceCandidate(new ResourcePersistentId(pidOrNull), MdmMatchOutcome.EID_MATCH);
ourLog.debug("Matched {} by EID {}", foundPerson.getIdElement(), eid);
retval.add(mpc);
}

View File

@ -39,11 +39,11 @@ public class FindCandidateByLinkSvc extends BaseCandidateFinder {
* Attempt to find a currently matching Person, based on the presence of an {@link MdmLink} entity.
*
* @param theTarget the {@link IAnyResource} that we want to find candidate Persons for.
* @return an Optional list of {@link MatchedSourceResourceCandidate} indicating matches.
* @return an Optional list of {@link MatchedGoldenResourceCandidate} indicating matches.
*/
@Override
protected List<MatchedSourceResourceCandidate> findMatchSourceResourceCandidates(IAnyResource theTarget) {
List<MatchedSourceResourceCandidate> retval = new ArrayList<>();
protected List<MatchedGoldenResourceCandidate> findMatchGoldenResourceCandidates(IAnyResource theTarget) {
List<MatchedGoldenResourceCandidate> retval = new ArrayList<>();
Long targetPid = myIdHelperService.getPidOrNull(theTarget);
if (targetPid != null) {
@ -51,7 +51,7 @@ public class FindCandidateByLinkSvc extends BaseCandidateFinder {
if (oLink.isPresent()) {
ResourcePersistentId personPid = new ResourcePersistentId(oLink.get().getGoldenResourcePid());
ourLog.debug("Resource previously linked. Using existing link.");
retval.add(new MatchedSourceResourceCandidate(personPid, oLink.get()));
retval.add(new MatchedGoldenResourceCandidate(personPid, oLink.get()));
}
}
return retval;

View File

@ -59,11 +59,11 @@ public class FindCandidateByScoreSvc extends BaseCandidateFinder {
* entries in the MdmLink table, and returns all the matches found therein.
*
* @param theTarget the {@link IBaseResource} which we want to find candidate Persons for.
* @return an Optional list of {@link MatchedSourceResourceCandidate} indicating matches.
* @return an Optional list of {@link MatchedGoldenResourceCandidate} indicating matches.
*/
@Override
protected List<MatchedSourceResourceCandidate> findMatchSourceResourceCandidates(IAnyResource theTarget) {
List<MatchedSourceResourceCandidate> retval = new ArrayList<>();
protected List<MatchedGoldenResourceCandidate> findMatchGoldenResourceCandidates(IAnyResource theTarget) {
List<MatchedGoldenResourceCandidate> retval = new ArrayList<>();
List<Long> personPidsToExclude = getNoMatchPersonPids(theTarget);
@ -86,7 +86,7 @@ public class FindCandidateByScoreSvc extends BaseCandidateFinder {
continue;
}
MatchedSourceResourceCandidate candidate = new MatchedSourceResourceCandidate(getResourcePersistentId(matchMdmLink.getGoldenResourcePid()), match.getMatchResult());
MatchedGoldenResourceCandidate candidate = new MatchedGoldenResourceCandidate(getResourcePersistentId(matchMdmLink.getGoldenResourcePid()), match.getMatchResult());
retval.add(candidate);
}
return retval;

View File

@ -24,23 +24,23 @@ import ca.uhn.fhir.mdm.api.MdmMatchOutcome;
import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
public class MatchedSourceResourceCandidate {
public class MatchedGoldenResourceCandidate {
private final ResourcePersistentId myCandidateSourceResourcePid;
private final ResourcePersistentId myCandidateGoldenResourcePid;
private final MdmMatchOutcome myMdmMatchOutcome;
public MatchedSourceResourceCandidate(ResourcePersistentId theCandidate, MdmMatchOutcome theMdmMatchOutcome) {
myCandidateSourceResourcePid = theCandidate;
public MatchedGoldenResourceCandidate(ResourcePersistentId theCandidate, MdmMatchOutcome theMdmMatchOutcome) {
myCandidateGoldenResourcePid = theCandidate;
myMdmMatchOutcome = theMdmMatchOutcome;
}
public MatchedSourceResourceCandidate(ResourcePersistentId thePersonPid, MdmLink theMdmLink) {
myCandidateSourceResourcePid = thePersonPid;
public MatchedGoldenResourceCandidate(ResourcePersistentId thePersonPid, MdmLink theMdmLink) {
myCandidateGoldenResourcePid = thePersonPid;
myMdmMatchOutcome = new MdmMatchOutcome(theMdmLink.getVector(), theMdmLink.getScore()).setMatchResultEnum(theMdmLink.getMatchResult());
}
public ResourcePersistentId getCandidatePersonPid() {
return myCandidateSourceResourcePid;
return myCandidateGoldenResourcePid;
}
public MdmMatchOutcome getMatchResult() {

View File

@ -47,7 +47,7 @@ public class MdmGoldenResourceFindingSvc {
private FindCandidateByScoreSvc myFindCandidateByScoreSvc;
/**
* Given an incoming IBaseResource, limited to Patient/Practitioner, return a list of {@link MatchedSourceResourceCandidate}
* Given an incoming IBaseResource, limited to Patient/Practitioner, return a list of {@link MatchedGoldenResourceCandidate}
* indicating possible candidates for a matching Person. Uses several separate methods for finding candidates:
* <p>
* 0. First, check the incoming Resource for an EID. If it is present, and we can find a Person with this EID, it automatically matches.
@ -58,26 +58,26 @@ public class MdmGoldenResourceFindingSvc {
* field matchers.
*
* @param theResource the {@link IBaseResource} we are attempting to find matching candidate Persons for.
* @return A list of {@link MatchedSourceResourceCandidate} indicating all potential Person matches.
* @return A list of {@link MatchedGoldenResourceCandidate} indicating all potential Person matches.
*/
public CandidateList findSourceResourceCandidates(IAnyResource theResource) {
CandidateList matchedSourceResourceCandidates = myFindCandidateByEidSvc.findCandidates(theResource);
public CandidateList findGoldenResourceCandidates(IAnyResource theResource) {
CandidateList matchedGoldenResourceCandidates = myFindCandidateByEidSvc.findCandidates(theResource);
if (matchedSourceResourceCandidates.isEmpty()) {
matchedSourceResourceCandidates = myFindCandidateByLinkSvc.findCandidates(theResource);
if (matchedGoldenResourceCandidates.isEmpty()) {
matchedGoldenResourceCandidates = myFindCandidateByLinkSvc.findCandidates(theResource);
}
if (matchedSourceResourceCandidates.isEmpty()) {
if (matchedGoldenResourceCandidates.isEmpty()) {
//OK, so we have not found any links in the MdmLink table with us as a target. Next, let's find
//possible Golden Resources matches by following MDM rules.
matchedSourceResourceCandidates = myFindCandidateByScoreSvc.findCandidates(theResource);
matchedGoldenResourceCandidates = myFindCandidateByScoreSvc.findCandidates(theResource);
}
return matchedSourceResourceCandidates;
return matchedGoldenResourceCandidates;
}
public IAnyResource getSourceResourceFromMatchedSourceResourceCandidate(MatchedSourceResourceCandidate theMatchedSourceResourceCandidate, String theResourceType) {
ResourcePersistentId personPid = theMatchedSourceResourceCandidate.getCandidatePersonPid();
return myMdmResourceDaoSvc.readSourceResourceByPid(personPid, theResourceType);
public IAnyResource getGoldenResourceFromMatchedGoldenResourceCandidate(MatchedGoldenResourceCandidate theMatchedGoldenResourceCandidate, String theResourceType) {
ResourcePersistentId personPid = theMatchedGoldenResourceCandidate.getCandidatePersonPid();
return myMdmResourceDaoSvc.readGoldenResourceByPid(personPid, theResourceType);
}
}

View File

@ -25,7 +25,7 @@ import ca.uhn.fhir.jpa.mdm.matcher.IsMatchedToAPerson;
import ca.uhn.fhir.jpa.mdm.matcher.IsPossibleDuplicateOf;
import ca.uhn.fhir.jpa.mdm.matcher.IsPossibleLinkedTo;
import ca.uhn.fhir.jpa.mdm.matcher.IsPossibleMatchWith;
import ca.uhn.fhir.jpa.mdm.matcher.IsSameSourceResourceAs;
import ca.uhn.fhir.jpa.mdm.matcher.IsSameGoldenResourceAs;
import ca.uhn.fhir.jpa.mdm.svc.MdmMatchLinkSvc;
import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
@ -316,8 +316,8 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test {
Optional<MdmLink> matchedLinkForTargetPid = myMdmLinkDaoSvc.getMatchedLinkForTargetPid(myIdHelperService.getPidOrNull(theBaseResource));
if (matchedLinkForTargetPid.isPresent()) {
Long sourceResourcePid = matchedLinkForTargetPid.get().getGoldenResourcePid();
return (IAnyResource) relevantDao.readByPid(new ResourcePersistentId(sourceResourcePid));
Long goldenResourcePid = matchedLinkForTargetPid.get().getGoldenResourcePid();
return (IAnyResource) relevantDao.readByPid(new ResourcePersistentId(goldenResourcePid));
} else {
return null;
}
@ -393,8 +393,8 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test {
return thePractitioner;
}
protected Matcher<IAnyResource> sameSourceResourceAs(IAnyResource... theBaseResource) {
return IsSameSourceResourceAs.sameSourceResourceAs(myIdHelperService, myMdmLinkDaoSvc, theBaseResource);
protected Matcher<IAnyResource> sameGoldenResourceAs(IAnyResource... theBaseResource) {
return IsSameGoldenResourceAs.sameGoldenResourceAs(myIdHelperService, myMdmLinkDaoSvc, theBaseResource);
}
protected Matcher<IAnyResource> linkedTo(IAnyResource... theBaseResource) {

View File

@ -17,16 +17,16 @@ import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public abstract class BaseSourceResourceMatcher extends TypeSafeMatcher<IAnyResource> {
public abstract class BaseGoldenResourceMatcher extends TypeSafeMatcher<IAnyResource> {
private static final Logger ourLog = LoggerFactory.getLogger(BaseSourceResourceMatcher.class);
private static final Logger ourLog = LoggerFactory.getLogger(BaseGoldenResourceMatcher.class);
protected IdHelperService myIdHelperService;
protected MdmLinkDaoSvc myMdmLinkDaoSvc;
protected Collection<IAnyResource> myBaseResources;
protected String myTargetType;
protected BaseSourceResourceMatcher(IdHelperService theIdHelperService, MdmLinkDaoSvc theMdmLinkDaoSvc, IAnyResource... theBaseResource) {
protected BaseGoldenResourceMatcher(IdHelperService theIdHelperService, MdmLinkDaoSvc theMdmLinkDaoSvc, IAnyResource... theBaseResource) {
myIdHelperService = theIdHelperService;
myMdmLinkDaoSvc = theMdmLinkDaoSvc;
myBaseResources = Arrays.stream(theBaseResource).collect(Collectors.toList());
@ -51,7 +51,7 @@ public abstract class BaseSourceResourceMatcher extends TypeSafeMatcher<IAnyReso
return retval;
}
protected List<Long> getPossibleMatchedSourceResourcePidsFromTarget(IAnyResource theBaseResource) {
protected List<Long> getPossibleMatchedGoldenResourcePidsFromTarget(IAnyResource theBaseResource) {
return getMdmLinksForTarget(theBaseResource, MdmMatchResultEnum.POSSIBLE_MATCH).stream().map(MdmLink::getGoldenResourcePid).collect(Collectors.toList());
}

View File

@ -14,7 +14,7 @@ import java.util.stream.Collectors;
* is linked to a set of patients/practitioners via a person.
*
*/
public class IsLinkedTo extends BaseSourceResourceMatcher {
public class IsLinkedTo extends BaseGoldenResourceMatcher {
private List<Long> baseResourcePersonPids;
private Long incomingResourcePersonPid;

View File

@ -12,7 +12,7 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class IsPossibleDuplicateOf extends BaseSourceResourceMatcher {
public class IsPossibleDuplicateOf extends BaseGoldenResourceMatcher {
/**
* Matcher with tells us if there is an MdmLink with between these two resources that are considered POSSIBLE DUPLICATE.
* For use only on persons.

View File

@ -14,7 +14,7 @@ import java.util.stream.Collectors;
* is linked to a set of patients/practitioners via a person.
*
*/
public class IsPossibleLinkedTo extends BaseSourceResourceMatcher {
public class IsPossibleLinkedTo extends BaseGoldenResourceMatcher {
private List<Long> baseResourcePersonPids;
private Long incomingResourcePersonPid;
@ -24,12 +24,12 @@ public class IsPossibleLinkedTo extends BaseSourceResourceMatcher {
}
@Override
protected boolean matchesSafely(IAnyResource theSourceResource) {
incomingResourcePersonPid = myIdHelperService.getPidOrNull(theSourceResource);
protected boolean matchesSafely(IAnyResource theGoldenResource) {
incomingResourcePersonPid = myIdHelperService.getPidOrNull(theGoldenResource);
//OK, lets grab all the person pids of the resources passed in via the constructor.
baseResourcePersonPids = myBaseResources.stream()
.flatMap(iBaseResource -> getPossibleMatchedSourceResourcePidsFromTarget(iBaseResource).stream())
.flatMap(iBaseResource -> getPossibleMatchedGoldenResourcePidsFromTarget(iBaseResource).stream())
.collect(Collectors.toList());
//The resources are linked if all person pids match the incoming person pid.

View File

@ -15,7 +15,7 @@ import java.util.stream.Collectors;
/**
* Matcher with tells us if there is an MdmLink with between these two resources that are considered POSSIBLE_MATCH
*/
public class IsPossibleMatchWith extends BaseSourceResourceMatcher {
public class IsPossibleMatchWith extends BaseGoldenResourceMatcher {
protected IsPossibleMatchWith(IdHelperService theIdHelperService, MdmLinkDaoSvc theMdmLinkDaoSvc, IAnyResource... theBaseResource) {
super(theIdHelperService, theMdmLinkDaoSvc, theBaseResource);
@ -32,7 +32,7 @@ public class IsPossibleMatchWith extends BaseSourceResourceMatcher {
if (personPidsToMatch.isEmpty()) {
personPidsToMatch = myBaseResources.stream()
.flatMap(iBaseResource -> getPossibleMatchedSourceResourcePidsFromTarget(iBaseResource).stream())
.flatMap(iBaseResource -> getPossibleMatchedGoldenResourcePidsFromTarget(iBaseResource).stream())
.collect(Collectors.toList());
}

View File

@ -9,38 +9,38 @@ import org.hl7.fhir.instance.model.api.IAnyResource;
import java.util.List;
import java.util.stream.Collectors;
public class IsSameSourceResourceAs extends BaseSourceResourceMatcher {
public class IsSameGoldenResourceAs extends BaseGoldenResourceMatcher {
private List<Long> sourceResourcePidsToMatch;
private Long incomingSourceResourcePid;
private List<Long> goldenResourcePidsToMatch;
private Long incomingGoldenResourcePid;
public IsSameSourceResourceAs(IdHelperService theIdHelperService, MdmLinkDaoSvc theMdmLinkDaoSvc, IAnyResource... theBaseResource) {
public IsSameGoldenResourceAs(IdHelperService theIdHelperService, MdmLinkDaoSvc theMdmLinkDaoSvc, IAnyResource... theBaseResource) {
super(theIdHelperService, theMdmLinkDaoSvc, theBaseResource);
}
@Override
protected boolean matchesSafely(IAnyResource theIncomingResource) {
incomingSourceResourcePid = getMatchedResourcePidFromResource(theIncomingResource);
sourceResourcePidsToMatch = myBaseResources.stream().map(this::getMatchedResourcePidFromResource).collect(Collectors.toList());
boolean allToCheckAreSame = sourceResourcePidsToMatch.stream().allMatch(pid -> pid.equals(sourceResourcePidsToMatch.get(0)));
incomingGoldenResourcePid = getMatchedResourcePidFromResource(theIncomingResource);
goldenResourcePidsToMatch = myBaseResources.stream().map(this::getMatchedResourcePidFromResource).collect(Collectors.toList());
boolean allToCheckAreSame = goldenResourcePidsToMatch.stream().allMatch(pid -> pid.equals(goldenResourcePidsToMatch.get(0)));
if (!allToCheckAreSame) {
throw new IllegalStateException("You wanted to do a source resource comparison, but the pool of source resources you submitted for checking don't match! We won't even check the incoming source resource against them.");
}
return sourceResourcePidsToMatch.contains(incomingSourceResourcePid);
return goldenResourcePidsToMatch.contains(incomingGoldenResourcePid);
}
@Override
public void describeTo(Description theDescription) {
theDescription.appendText(String.format(" %s linked to source resource %s/%s", myTargetType, myTargetType, sourceResourcePidsToMatch));
theDescription.appendText(String.format(" %s linked to source resource %s/%s", myTargetType, myTargetType, goldenResourcePidsToMatch));
}
@Override
protected void describeMismatchSafely(IAnyResource item, Description mismatchDescription) {
super.describeMismatchSafely(item, mismatchDescription);
mismatchDescription.appendText(String.format(" was actually linked to %s/%s", myTargetType, incomingSourceResourcePid));
mismatchDescription.appendText(String.format(" was actually linked to %s/%s", myTargetType, incomingGoldenResourcePid));
}
public static Matcher<IAnyResource> sameSourceResourceAs(IdHelperService theIdHelperService, MdmLinkDaoSvc theMdmLinkDaoSvc, IAnyResource... theBaseResource) {
return new IsSameSourceResourceAs(theIdHelperService, theMdmLinkDaoSvc, theBaseResource);
public static Matcher<IAnyResource> sameGoldenResourceAs(IdHelperService theIdHelperService, MdmLinkDaoSvc theMdmLinkDaoSvc, IAnyResource... theBaseResource) {
return new IsSameGoldenResourceAs(theIdHelperService, theMdmLinkDaoSvc, theBaseResource);
}
}

View File

@ -32,16 +32,16 @@ import static org.junit.jupiter.api.Assertions.fail;
public class MdmProviderClearLinkR4Test extends BaseLinkR4Test {
protected Practitioner myPractitioner;
protected StringType myPractitionerId;
protected IAnyResource myPractitionerSourceResource;
protected StringType myPractitionerSourceResourceId;
protected IAnyResource myPractitionerGoldenResource;
protected StringType myPractitionerGoldenResourceId;
@BeforeEach
public void before() {
super.before();
myPractitioner = createPractitionerAndUpdateLinks(new Practitioner());
myPractitionerId = new StringType(myPractitioner.getIdElement().getValue());
myPractitionerSourceResource = getGoldenResourceFromTargetResource(myPractitioner);
myPractitionerSourceResourceId = new StringType(myPractitionerSourceResource.getIdElement().getValue());
myPractitionerGoldenResource = getGoldenResourceFromTargetResource(myPractitioner);
myPractitionerGoldenResourceId = new StringType(myPractitionerGoldenResource.getIdElement().getValue());
}
@Test
@ -106,7 +106,7 @@ public class MdmProviderClearLinkR4Test extends BaseLinkR4Test {
myMdmProviderR4.clearMdmLinks(null, myRequestDetails);
assertNoPatientLinksExist();
IBundleProvider search = myPatientDao.search(buildSourceResourceParameterMap());
IBundleProvider search = myPatientDao.search(buildGoldenResourceParameterMap());
assertThat(search.size(), is(equalTo(0)));
}
@ -114,7 +114,7 @@ public class MdmProviderClearLinkR4Test extends BaseLinkR4Test {
* Build a SearchParameterMap which looks up Golden Records (Source resources).
* @return
*/
private SearchParameterMap buildSourceResourceParameterMap() {
private SearchParameterMap buildGoldenResourceParameterMap() {
return new SearchParameterMap().setLoadSynchronous(true).add("_tag", new TokenParam(MdmConstants.SYSTEM_MDM_MANAGED, MdmConstants.CODE_HAPI_MDM_MANAGED));
}
@ -139,7 +139,7 @@ public class MdmProviderClearLinkR4Test extends BaseLinkR4Test {
printLinks();
assertNoPatientLinksExist();
IBundleProvider search = myPatientDao.search(buildSourceResourceParameterMap());
IBundleProvider search = myPatientDao.search(buildGoldenResourceParameterMap());
assertThat(search.size(), is(equalTo(0)));
}
@ -154,12 +154,12 @@ public class MdmProviderClearLinkR4Test extends BaseLinkR4Test {
@Test
public void testClearPractitionerLinks() {
assertLinkCount(2);
Practitioner read = myPractitionerDao.read(new IdDt(myPractitionerSourceResourceId.getValueAsString()).toVersionless());
Practitioner read = myPractitionerDao.read(new IdDt(myPractitionerGoldenResourceId.getValueAsString()).toVersionless());
assertThat(read, is(notNullValue()));
myMdmProviderR4.clearMdmLinks(new StringType("Practitioner"), myRequestDetails);
assertNoPractitionerLinksExist();
try {
myPractitionerDao.read(new IdDt(myPractitionerSourceResourceId.getValueAsString()).toVersionless());
myPractitionerDao.read(new IdDt(myPractitionerGoldenResourceId.getValueAsString()).toVersionless());
fail();
} catch (ResourceNotFoundException e) {}
}

View File

@ -22,10 +22,10 @@ import static org.junit.jupiter.api.Assertions.fail;
public class MdmProviderMergePersonsR4Test extends BaseProviderR4Test {
private Patient myFromSourcePatient;
private StringType myFromSourcePatientId;
private Patient myToSourcePatient;
private StringType myToSourcePatientId;
private Patient myFromGoldenPatient;
private StringType myFromGoldenPatientId;
private Patient myToGoldenPatient;
private StringType myToGoldenPatientId;
@Override
@BeforeEach
@ -33,24 +33,24 @@ public class MdmProviderMergePersonsR4Test extends BaseProviderR4Test {
super.before();
super.loadMdmSearchParameters();
myFromSourcePatient = createGoldenPatient();
myFromSourcePatientId = new StringType(myFromSourcePatient.getIdElement().getValue());
myToSourcePatient = createGoldenPatient();
myToSourcePatientId = new StringType(myToSourcePatient.getIdElement().getValue());
myFromGoldenPatient = createGoldenPatient();
myFromGoldenPatientId = new StringType(myFromGoldenPatient.getIdElement().getValue());
myToGoldenPatient = createGoldenPatient();
myToGoldenPatientId = new StringType(myToGoldenPatient.getIdElement().getValue());
}
@Test
public void testMerge() {
Patient mergedSourcePatient = (Patient) myMdmProviderR4.mergeGoldenResources(myFromSourcePatientId,
myToSourcePatientId, myRequestDetails);
Patient mergedSourcePatient = (Patient) myMdmProviderR4.mergeGoldenResources(myFromGoldenPatientId,
myToGoldenPatientId, myRequestDetails);
assertTrue(MdmUtil.isGoldenRecord(myFromSourcePatient));
assertEquals(myToSourcePatient.getIdElement(), mergedSourcePatient.getIdElement());
assertThat(mergedSourcePatient, is(sameSourceResourceAs(myToSourcePatient)));
assertTrue(MdmUtil.isGoldenRecord(myFromGoldenPatient));
assertEquals(myToGoldenPatient.getIdElement(), mergedSourcePatient.getIdElement());
assertThat(mergedSourcePatient, is(sameGoldenResourceAs(myToGoldenPatient)));
assertEquals(1, getAllRedirectedGoldenPatients().size());
assertEquals(1, getAllGoldenPatients().size());
Patient fromSourcePatient = myPatientDao.read(myFromSourcePatient.getIdElement().toUnqualifiedVersionless());
Patient fromSourcePatient = myPatientDao.read(myFromGoldenPatient.getIdElement().toUnqualifiedVersionless());
assertThat(fromSourcePatient.getActive(), is(false));
assertTrue(MdmUtil.isGoldenRecordRedirected(fromSourcePatient));
@ -58,12 +58,12 @@ public class MdmProviderMergePersonsR4Test extends BaseProviderR4Test {
// Optional<Identifier> redirect = fromSourcePatient.getIdentifier().stream().filter(theIdentifier -> theIdentifier.getSystem().equals("REDIRECT")).findFirst();
// assertThat(redirect.get().getValue(), is(equalTo(myToSourcePatient.getIdElement().toUnqualified().getValue())));
List<MdmLink> links = myMdmLinkDaoSvc.findMdmLinksByTarget(myFromSourcePatient);
List<MdmLink> links = myMdmLinkDaoSvc.findMdmLinksByTarget(myFromGoldenPatient);
assertThat(links, hasSize(1));
MdmLink link = links.get(0);
assertEquals(link.getTargetPid(), myFromSourcePatient.getIdElement().toUnqualifiedVersionless().getIdPartAsLong());
assertEquals(link.getGoldenResourcePid(), myToSourcePatient.getIdElement().toUnqualifiedVersionless().getIdPartAsLong());
assertEquals(link.getTargetPid(), myFromGoldenPatient.getIdElement().toUnqualifiedVersionless().getIdPartAsLong());
assertEquals(link.getGoldenResourcePid(), myToGoldenPatient.getIdElement().toUnqualifiedVersionless().getIdPartAsLong());
assertEquals(link.getMatchResult(), MdmMatchResultEnum.REDIRECT);
assertEquals(link.getLinkSource(), MdmLinkSourceEnum.MANUAL);
}
@ -89,13 +89,13 @@ public class MdmProviderMergePersonsR4Test extends BaseProviderR4Test {
assertEquals("fromGoldenResourceId cannot be null", e.getMessage());
}
try {
myMdmProviderR4.mergeGoldenResources(null, myToSourcePatientId, myRequestDetails);
myMdmProviderR4.mergeGoldenResources(null, myToGoldenPatientId, myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertEquals("fromGoldenResourceId cannot be null", e.getMessage());
}
try {
myMdmProviderR4.mergeGoldenResources(myFromSourcePatientId, null, myRequestDetails);
myMdmProviderR4.mergeGoldenResources(myFromGoldenPatientId, null, myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertEquals("toGoldenResourceId cannot be null", e.getMessage());
@ -112,14 +112,14 @@ public class MdmProviderMergePersonsR4Test extends BaseProviderR4Test {
}
try {
myMdmProviderR4.mergeGoldenResources(new StringType("Person/abc"), myToSourcePatientId, myRequestDetails);
myMdmProviderR4.mergeGoldenResources(new StringType("Person/abc"), myToGoldenPatientId, myRequestDetails);
fail();
} catch (ResourceNotFoundException e) {
assertEquals("Resource Person/abc is not known", e.getMessage());
}
try {
myMdmProviderR4.mergeGoldenResources(myFromSourcePatientId, new StringType("Person/abc"), myRequestDetails);
myMdmProviderR4.mergeGoldenResources(myFromGoldenPatientId, new StringType("Person/abc"), myRequestDetails);
fail();
} catch (ResourceNotFoundException e) {
assertEquals("Resource Person/abc is not known", e.getMessage());

View File

@ -90,8 +90,8 @@ public class MdmLinkSvcTest extends BaseMdmR4Test {
Long goldenPatient1Pid = myIdHelperService.getPidOrNull(goldenPatient1);
Long goldenPatient2Pid = myIdHelperService.getPidOrNull(goldenPatient2);
assertFalse(myMdmLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(goldenPatient1Pid, goldenPatient2Pid).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(goldenPatient2Pid, goldenPatient1Pid).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndTargetResourcePid(goldenPatient1Pid, goldenPatient2Pid).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndTargetResourcePid(goldenPatient2Pid, goldenPatient1Pid).isPresent());
saveNoMatchLink(goldenPatient1Pid, goldenPatient2Pid);
@ -108,8 +108,8 @@ public class MdmLinkSvcTest extends BaseMdmR4Test {
Long goldenPatient1Pid = myIdHelperService.getPidOrNull(goldenPatient1);
Long goldenPatient2Pid = myIdHelperService.getPidOrNull(goldenPatient2);
assertFalse(myMdmLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(goldenPatient1Pid, goldenPatient2Pid).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(goldenPatient2Pid, goldenPatient1Pid).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndTargetResourcePid(goldenPatient1Pid, goldenPatient2Pid).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndTargetResourcePid(goldenPatient2Pid, goldenPatient1Pid).isPresent());
saveNoMatchLink(goldenPatient2Pid, goldenPatient1Pid);

View File

@ -63,7 +63,7 @@ public class MdmMatchLinkSvcMultipleEidModeTest extends BaseMdmR4Test {
assertLinksMatchedByEid(false, false);
//We want to make sure the patients were linked to the same person.
assertThat(patient, is(sameSourceResourceAs(janePatient)));
assertThat(patient, is(sameGoldenResourceAs(janePatient)));
Patient sourcePatient = (Patient) getGoldenResourceFromTargetResource(patient);
@ -106,7 +106,7 @@ public class MdmMatchLinkSvcMultipleEidModeTest extends BaseMdmR4Test {
assertLinksCreatedNewResource(true, false);
assertLinksMatchedByEid(false, true);
assertThat(patient1, is(sameSourceResourceAs(patient2)));
assertThat(patient1, is(sameGoldenResourceAs(patient2)));
clearExternalEIDs(patient2);
addExternalEID(patient2, "id_6");
@ -120,7 +120,7 @@ public class MdmMatchLinkSvcMultipleEidModeTest extends BaseMdmR4Test {
assertLinksCreatedNewResource(true, false);
assertLinksMatchedByEid(false, true);
assertThat(patient1, is(sameSourceResourceAs(patient2)));
assertThat(patient1, is(sameGoldenResourceAs(patient2)));
personFromTarget = (Patient) getGoldenResourceFromTargetResource(patient2);
assertThat(personFromTarget.getIdentifier(), hasSize(6));
@ -186,7 +186,7 @@ public class MdmMatchLinkSvcMultipleEidModeTest extends BaseMdmR4Test {
assertLinksMatchedByEid(false, false, true);
//Now, Patient 2 and 3 are linked, and the person has 2 eids.
assertThat(patient2, is(sameSourceResourceAs(patient3)));
assertThat(patient2, is(sameGoldenResourceAs(patient3)));
//Now lets change one of the EIDs on the second patient to one that matches our original patient.
//This should create a situation in which the incoming EIDs are matched to _two_ different persons. In this case, we want to

View File

@ -8,8 +8,6 @@ import ca.uhn.fhir.mdm.model.CanonicalEID;
import ca.uhn.fhir.mdm.util.EIDHelper;
import ca.uhn.fhir.mdm.util.MdmUtil;
import ca.uhn.fhir.mdm.util.GoldenResourceHelper;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.dao.data.IMdmLinkDao;
import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test;
import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
@ -91,7 +89,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
assertLinkCount(2);
assertThat(patient1, is(not(sameSourceResourceAs(patient2))));
assertThat(patient1, is(not(sameGoldenResourceAs(patient2))));
assertLinksMatchResult(MATCH, MATCH);
assertLinksCreatedNewResource(true, true);
@ -106,7 +104,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
Patient patient2 = createPatientAndUpdateLinks(buildJanePatient());
assertLinkCount(2);
assertThat(patient1, is(sameSourceResourceAs(patient2)));
assertThat(patient1, is(sameGoldenResourceAs(patient2)));
assertLinksMatchResult(MATCH, MATCH);
assertLinksCreatedNewResource(true, false);
assertLinksMatchedByEid(false, false);
@ -124,7 +122,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
//rerun MDM rules against unmatchedJane.
myMdmMatchLinkSvc.updateMdmLinksForMdmTarget(unmatchedJane, createContextForCreate("Patient"));
assertThat(unmatchedJane, is(not(sameSourceResourceAs(janePerson))));
assertThat(unmatchedJane, is(not(sameGoldenResourceAs(janePerson))));
assertThat(unmatchedJane, is(not(linkedTo(originalJane))));
assertLinksMatchResult(MATCH, NO_MATCH, MATCH);
@ -149,7 +147,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
//should cause a whole new Person to be created.
myMdmMatchLinkSvc.updateMdmLinksForMdmTarget(unmatchedPatient, createContextForCreate("Patient"));
assertThat(unmatchedPatient, is(not(sameSourceResourceAs(janePerson))));
assertThat(unmatchedPatient, is(not(sameGoldenResourceAs(janePerson))));
assertThat(unmatchedPatient, is(not(linkedTo(originalJane))));
assertLinksMatchResult(MATCH, NO_MATCH, MATCH);
@ -204,7 +202,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
public void testPatientMatchingAnotherPatientLinksToSamePerson() {
Patient janePatient = createPatientAndUpdateLinks(buildJanePatient());
Patient sameJanePatient = createPatientAndUpdateLinks(buildJanePatient());
assertThat(janePatient, is(sameSourceResourceAs(sameJanePatient)));
assertThat(janePatient, is(sameGoldenResourceAs(sameJanePatient)));
}
@Test
@ -220,7 +218,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
createPatientAndUpdateLinks(janePatient);
//We want to make sure the patients were linked to the same person.
assertThat(patient, is(sameSourceResourceAs(janePatient)));
assertThat(patient, is(sameGoldenResourceAs(janePatient)));
Patient sourcePatient = (Patient) getGoldenResourceFromTargetResource(patient);
@ -247,7 +245,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
patient2 = addExternalEID(patient2, "uniqueid");
createPatientAndUpdateLinks(patient2);
assertThat(patient1, is(sameSourceResourceAs(patient2)));
assertThat(patient1, is(sameGoldenResourceAs(patient2)));
}
@Test
@ -265,7 +263,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
addExternalEID(patient2, "id_1");
createPatientAndUpdateLinks(patient2);
assertThat(patient1, is(sameSourceResourceAs(patient2)));
assertThat(patient1, is(sameGoldenResourceAs(patient2)));
}
@Test
@ -307,7 +305,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
Practitioner janePractitioner = createPractitionerAndUpdateLinks(buildJanePractitioner());
assertLinkCount(2);
assertThat(janePatient, is(not(sameSourceResourceAs(janePractitioner))));
assertThat(janePatient, is(not(sameGoldenResourceAs(janePractitioner))));
}
@Test
@ -316,7 +314,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
Practitioner anotherJanePractitioner = createPractitionerAndUpdateLinks(buildJanePractitioner());
assertLinkCount(2);
assertThat(anotherJanePractitioner, is(sameSourceResourceAs(janePractitioner)));
assertThat(anotherJanePractitioner, is(sameGoldenResourceAs(janePractitioner)));
}
@Test
@ -341,10 +339,10 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
Patient janePatient2 = createPatientAndUpdateLinks(buildJanePatient());
assertLinkCount(2);
assertThat(janePatient, is(sameSourceResourceAs(janePatient2)));
assertThat(janePatient, is(sameGoldenResourceAs(janePatient2)));
Patient incomingJanePatient = createPatientAndUpdateLinks(buildJanePatient());
assertThat(incomingJanePatient, is(sameSourceResourceAs(janePatient, janePatient2)));
assertThat(incomingJanePatient, is(sameGoldenResourceAs(janePatient, janePatient2)));
assertThat(incomingJanePatient, is(linkedTo(janePatient, janePatient2)));
}
@ -361,7 +359,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
//own individual Persons for the purpose of this test.
IAnyResource person = myGoldenResourceHelper.createGoldenResourceFromMdmTarget(janePatient2);
myMdmLinkSvc.updateLink(person, janePatient2, MdmMatchOutcome.NEW_PERSON_MATCH, MdmLinkSourceEnum.AUTO, createContextForCreate("Patient"));
assertThat(janePatient, is(not(sameSourceResourceAs(janePatient2))));
assertThat(janePatient, is(not(sameGoldenResourceAs(janePatient2))));
//In theory, this will match both Persons!
Patient incomingJanePatient = createPatientAndUpdateLinks(buildJanePatient());
@ -383,7 +381,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
}
@Test
public void testWhenAllMatchResultsArePOSSIBLE_MATCHThattheyAreLinkedAndNoSourceResourceIsCreated() {
public void testWhenAllMatchResultsArePOSSIBLE_MATCHThattheyAreLinkedAndNoGoldenResourceIsCreated() {
/**
* CASE 4: Only POSSIBLE_MATCH outcomes -> In this case, mdm-link records are created with POSSIBLE_MATCH
* outcome and await manual assignment to either NO_MATCH or MATCHED. Person link is added.
@ -391,7 +389,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
Patient patient = buildJanePatient();
patient.getNameFirstRep().setFamily("familyone");
patient = createPatientAndUpdateLinks(patient);
assertThat(patient, is(sameSourceResourceAs(patient)));
assertThat(patient, is(sameGoldenResourceAs(patient)));
Patient patient2 = buildJanePatient();
patient2.getNameFirstRep().setFamily("pleasedonotmatchatall");
@ -431,7 +429,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
Patient patient = buildJanePatient();
patient.getNameFirstRep().setFamily("familyone");
patient = createPatientAndUpdateLinks(patient);
assertThat(patient, is(sameSourceResourceAs(patient)));
assertThat(patient, is(sameGoldenResourceAs(patient)));
Patient patient2 = buildJanePatient();
patient2.getNameFirstRep().setFamily("pleasedonotmatchatall");
@ -441,34 +439,32 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
patient3.getNameFirstRep().setFamily("familyone");
patient3 = createPatientAndUpdateLinks(patient3);
assertThat(patient2, is(not(sameSourceResourceAs(patient))));
assertThat(patient2, is(not(sameGoldenResourceAs(patient))));
assertThat(patient2, is(possibleMatchWith(patient)));
assertThat(patient3, is(sameSourceResourceAs(patient)));
assertThat(patient3, is(sameGoldenResourceAs(patient)));
}
@Test
public void testCreateSourceResourceFromMdmTarget() {
public void testCreateGoldenResourceFromMdmTarget() {
// Create Use Case #2 - adding patient with no EID
Patient janePatient = buildJanePatient();
Patient janeSourceResourcePatient = myGoldenResourceHelper.createGoldenResourceFromMdmTarget(janePatient);
Patient janeGoldenResourcePatient = myGoldenResourceHelper.createGoldenResourceFromMdmTarget(janePatient);
// golden record now contains HAPI-generated EID and HAPI tag
assertTrue(MdmUtil.isMdmManaged(janeSourceResourcePatient));
assertFalse(myEidHelper.getHapiEid(janeSourceResourcePatient).isEmpty());
assertTrue(MdmUtil.isMdmManaged(janeGoldenResourcePatient));
assertFalse(myEidHelper.getHapiEid(janeGoldenResourcePatient).isEmpty());
// original checks - verifies that EIDs are assigned
assertThat("Resource must not be identical", janePatient != janeSourceResourcePatient);
assertThat("Resource must not be identical", janePatient != janeGoldenResourcePatient);
assertFalse(janePatient.getIdentifier().isEmpty());
assertFalse(janeSourceResourcePatient.getIdentifier().isEmpty());
assertFalse(janeGoldenResourcePatient.getIdentifier().isEmpty());
// Identifier janeId = janePatient.getIdentifier().get(0);
// Identifier janeSourceResourceId = janeSourceResourcePatient.getIdentifier().get(0);
CanonicalEID janeId = myEidHelper.getHapiEid(janePatient).get(0);
CanonicalEID janeSourceResourceId = myEidHelper.getHapiEid(janeSourceResourcePatient).get(0);
CanonicalEID janeGoldenResourceId = myEidHelper.getHapiEid(janeGoldenResourcePatient).get(0);
// source and target EIDs must match, as target EID should be reset to the newly created EID
assertEquals(janeId.getValue(), janeSourceResourceId.getValue());
assertEquals(janeId.getSystem(), janeSourceResourceId.getSystem());
assertEquals(janeId.getValue(), janeGoldenResourceId.getValue());
assertEquals(janeId.getSystem(), janeGoldenResourceId.getSystem());
}
//Case #1
@ -482,7 +478,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
patient1.setId(janePatient.getId());
Patient janePaulPatient = updatePatientAndUpdateLinks(patient1);
assertThat(janeSourcePatient, is(sameSourceResourceAs(janePaulPatient)));
assertThat(janeSourcePatient, is(sameGoldenResourceAs(janePaulPatient)));
//Ensure the related person was updated with new info.
Patient sourcePatientFromTarget = (Patient) getGoldenResourceFromTargetResource(janePaulPatient);
@ -507,7 +503,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
paul2.setGender(Enumerations.AdministrativeGender.FEMALE);
paul2 = createPatientAndUpdateLinks(paul2);
assertThat(paul2, is(sameSourceResourceAs(paul)));
assertThat(paul2, is(sameGoldenResourceAs(paul)));
//Newly matched patients aren't allowed to overwrite Person Attributes unless they are empty, so gender should still be set to male.
Patient paul2Person = (Patient) getGoldenResourceFromTargetResource(paul2);
@ -554,7 +550,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
updatePatientAndUpdateLinks(paul);
assertThat(originalJanePatient, is(possibleDuplicateOf(originalPaulPatient)));
assertThat(jane, is(sameSourceResourceAs(paul)));
assertThat(jane, is(sameGoldenResourceAs(paul)));
}
@Test
@ -576,7 +572,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
assertNoDuplicates();
Patient newlyFoundPaulPatient = (Patient) getGoldenResourceFromTargetResource(paul);
assertThat(originalPaulPatient, is(sameSourceResourceAs(newlyFoundPaulPatient)));
assertThat(originalPaulPatient, is(sameGoldenResourceAs(newlyFoundPaulPatient)));
String newEid = myEidHelper.getExternalEid(newlyFoundPaulPatient).get(0).getValue();
assertThat(newEid, is(equalTo(EID_2)));
}
@ -602,7 +598,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
patient3 = createPatientAndUpdateLinks(patient3);
//Now, Patient 2 and 3 are linked, and the person has 2 eids.
assertThat(patient2, is(sameSourceResourceAs(patient3)));
assertThat(patient2, is(sameGoldenResourceAs(patient3)));
assertNoDuplicates();
// Person A -> {P1}
// Person B -> {P2, P3}
@ -615,7 +611,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test {
// Person B -> {P3}
// Possible duplicates A<->B
assertThat(patient2, is(sameSourceResourceAs(patient1)));
assertThat(patient2, is(sameGoldenResourceAs(patient1)));
List<MdmLink> possibleDuplicates = myMdmLinkDaoSvc.getPossibleDuplicates();
assertThat(possibleDuplicates, hasSize(1));

View File

@ -95,7 +95,7 @@ public class MdmPersonMergerSvcTest extends BaseMdmR4Test {
Patient mergedGoldenPatient = mergeGoldenPatients();
assertEquals(myToGoldenPatient.getIdElement(), mergedGoldenPatient.getIdElement());
assertThat(mergedGoldenPatient, is(sameSourceResourceAs(mergedGoldenPatient)));
assertThat(mergedGoldenPatient, is(sameGoldenResourceAs(mergedGoldenPatient)));
assertEquals(1, getAllGoldenPatients().size());
assertEquals(1, getAllRedirectedGoldenPatients().size());
}