diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java index afc6f6ff967..c9e45b4eacf 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java @@ -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; } diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvc.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvc.java index 60ae3ccfa1f..40b4f8b7406 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvc.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvc.java @@ -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 oExisting = getLinkBySourceResourcePidAndTargetResourcePid(theSourceResourcePid, theTargetResourcePid); + public MdmLink getOrCreateMdmLinkByGoldenResourcePidAndTargetResourcePid(Long theGoldenResourcePid, Long theTargetResourcePid) { + Optional 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 getLinkBySourceResourcePidAndTargetResourcePid(Long theSourceResourcePid, Long theTargetResourcePid) { - if (theTargetResourcePid == null || theSourceResourcePid == null) { + public Optional 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 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 findMdmMatchLinksBySource(IBaseResource theSourceResource) { - Long pid = myIdHelperService.getPidOrNull(theSourceResource); + public List findMdmMatchLinksBySource(IBaseResource theGoldenResource) { + Long pid = myIdHelperService.getPidOrNull(theGoldenResource); if (pid == null) { return Collections.emptyList(); } diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/GoldenResourceMergerSvcImpl.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/GoldenResourceMergerSvcImpl.java index eb97c26fe29..26afd39fc96 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/GoldenResourceMergerSvcImpl.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/GoldenResourceMergerSvcImpl.java @@ -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) diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmEidUpdateService.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmEidUpdateService.java index 87fb00897ea..6399066531e 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmEidUpdateService.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmEidUpdateService.java @@ -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 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; } diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcImpl.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcImpl.java index b57060c562b..b0f3bac1d32 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcImpl.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcImpl.java @@ -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 optionalMdmLink = getMdmLinkForGoldenResourceTargetPair(theSourceResource, theTargetResource); + public void deleteLink(IAnyResource theGoldenResource, IAnyResource theTargetResource, MdmTransactionContext theMdmTransactionContext) { + Optional 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) { diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImpl.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImpl.java index 6d4535c100e..a0f467e4e44 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImpl.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkUpdaterSvcImpl.java @@ -74,7 +74,7 @@ public class MdmLinkUpdaterSvcImpl implements IMdmLinkUpdaterSvc { Long goldenResourceId = myIdHelperService.getPidOrThrowException(theGoldenResource); Long targetId = myIdHelperService.getPidOrThrowException(theTarget); - Optional optionalMdmLink = myMdmLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(goldenResourceId, targetId); + Optional 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 oMdmLink = myMdmLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(personId, targetId); + Optional oMdmLink = myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndTargetResourcePid(personId, targetId); if (!oMdmLink.isPresent()) { throw new InvalidRequestException("No link exists between " + thePerson.getIdElement().toVersionless() + " and " + theTarget.getIdElement().toVersionless()); } diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvc.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvc.java index 620297a32eb..df6dcc36bad 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvc.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvc.java @@ -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 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); diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmResourceDaoSvc.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmResourceDaoSvc.java index 3b8317597e0..90adb256138 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmResourceDaoSvc.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmResourceDaoSvc.java @@ -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 diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/BaseCandidateFinder.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/BaseCandidateFinder.java index b5c7788b2ee..fcb45a9f022 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/BaseCandidateFinder.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/BaseCandidateFinder.java @@ -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 findMatchSourceResourceCandidates(IAnyResource theTarget); + protected abstract List findMatchGoldenResourceCandidates(IAnyResource theTarget); protected abstract CandidateStrategyEnum getStrategy(); } diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/CandidateList.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/CandidateList.java index af919aa1e11..e551ccd4b34 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/CandidateList.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/CandidateList.java @@ -27,7 +27,7 @@ import java.util.stream.Stream; public class CandidateList { private final CandidateStrategyEnum myStrategy; - private final List myList = new ArrayList<>(); + private final List myList = new ArrayList<>(); public CandidateList(CandidateStrategyEnum theStrategy) { myStrategy = theStrategy; @@ -41,9 +41,9 @@ public class CandidateList { return myList.isEmpty(); } - public void addAll(List theList) { myList.addAll(theList); } + public void addAll(List 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 stream() { + public Stream stream() { return myList.stream(); } - public List getCandidates() { + public List getCandidates() { return Collections.unmodifiableList(myList); } - public MatchedSourceResourceCandidate getFirstMatch() { + public MatchedGoldenResourceCandidate getFirstMatch() { return myList.get(0); } diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByEidSvc.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByEidSvc.java index 6ecf0b44deb..214bc66b4e8 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByEidSvc.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByEidSvc.java @@ -45,8 +45,8 @@ public class FindCandidateByEidSvc extends BaseCandidateFinder { @Autowired private MdmResourceDaoSvc myMdmResourceDaoSvc; - protected List findMatchSourceResourceCandidates(IAnyResource theBaseResource) { - List retval = new ArrayList<>(); + protected List findMatchGoldenResourceCandidates(IAnyResource theBaseResource) { + List retval = new ArrayList<>(); List 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); } diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByLinkSvc.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByLinkSvc.java index 9db6a8b9919..ed692d0090c 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByLinkSvc.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByLinkSvc.java @@ -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 findMatchSourceResourceCandidates(IAnyResource theTarget) { - List retval = new ArrayList<>(); + protected List findMatchGoldenResourceCandidates(IAnyResource theTarget) { + List 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; diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByScoreSvc.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByScoreSvc.java index f899026dd3a..b275338a20d 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByScoreSvc.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/FindCandidateByScoreSvc.java @@ -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 findMatchSourceResourceCandidates(IAnyResource theTarget) { - List retval = new ArrayList<>(); + protected List findMatchGoldenResourceCandidates(IAnyResource theTarget) { + List retval = new ArrayList<>(); List 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; diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/MatchedGoldenResourceCandidate.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/MatchedGoldenResourceCandidate.java index 80379ac1630..8f596e40c7a 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/MatchedGoldenResourceCandidate.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/MatchedGoldenResourceCandidate.java @@ -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() { diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/MdmGoldenResourceFindingSvc.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/MdmGoldenResourceFindingSvc.java index 87f122584cd..6907a3cfb8f 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/MdmGoldenResourceFindingSvc.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/candidate/MdmGoldenResourceFindingSvc.java @@ -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: *

* 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); } } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java index 3059b53efdf..f1f1c5e284c 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java @@ -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 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 sameSourceResourceAs(IAnyResource... theBaseResource) { - return IsSameSourceResourceAs.sameSourceResourceAs(myIdHelperService, myMdmLinkDaoSvc, theBaseResource); + protected Matcher sameGoldenResourceAs(IAnyResource... theBaseResource) { + return IsSameGoldenResourceAs.sameGoldenResourceAs(myIdHelperService, myMdmLinkDaoSvc, theBaseResource); } protected Matcher linkedTo(IAnyResource... theBaseResource) { diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/BaseGoldenResourceMatcher.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/BaseGoldenResourceMatcher.java index 72c152c4abf..1b5d345741c 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/BaseGoldenResourceMatcher.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/BaseGoldenResourceMatcher.java @@ -17,16 +17,16 @@ import java.util.Collection; import java.util.List; import java.util.stream.Collectors; -public abstract class BaseSourceResourceMatcher extends TypeSafeMatcher { +public abstract class BaseGoldenResourceMatcher extends TypeSafeMatcher { - 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 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 getPossibleMatchedSourceResourcePidsFromTarget(IAnyResource theBaseResource) { + protected List getPossibleMatchedGoldenResourcePidsFromTarget(IAnyResource theBaseResource) { return getMdmLinksForTarget(theBaseResource, MdmMatchResultEnum.POSSIBLE_MATCH).stream().map(MdmLink::getGoldenResourcePid).collect(Collectors.toList()); } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsLinkedTo.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsLinkedTo.java index f06713f06d9..3f6d441356d 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsLinkedTo.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsLinkedTo.java @@ -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 baseResourcePersonPids; private Long incomingResourcePersonPid; diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleDuplicateOf.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleDuplicateOf.java index 443baac8649..bdef27cdd11 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleDuplicateOf.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleDuplicateOf.java @@ -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. diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleLinkedTo.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleLinkedTo.java index dbb575e578b..9fdef9ae9e2 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleLinkedTo.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleLinkedTo.java @@ -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 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. diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleMatchWith.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleMatchWith.java index 0f2cb039e53..c924610be63 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleMatchWith.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsPossibleMatchWith.java @@ -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()); } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsSameGoldenResourceAs.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsSameGoldenResourceAs.java index ac76162ec55..16ddb5bd510 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsSameGoldenResourceAs.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/matcher/IsSameGoldenResourceAs.java @@ -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 sourceResourcePidsToMatch; - private Long incomingSourceResourcePid; + private List 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 sameSourceResourceAs(IdHelperService theIdHelperService, MdmLinkDaoSvc theMdmLinkDaoSvc, IAnyResource... theBaseResource) { - return new IsSameSourceResourceAs(theIdHelperService, theMdmLinkDaoSvc, theBaseResource); + public static Matcher sameGoldenResourceAs(IdHelperService theIdHelperService, MdmLinkDaoSvc theMdmLinkDaoSvc, IAnyResource... theBaseResource) { + return new IsSameGoldenResourceAs(theIdHelperService, theMdmLinkDaoSvc, theBaseResource); } } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderClearLinkR4Test.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderClearLinkR4Test.java index 7bae41b46f1..fe435a14baf 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderClearLinkR4Test.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderClearLinkR4Test.java @@ -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) {} } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMergePersonsR4Test.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMergePersonsR4Test.java index b0d3e35fa7f..dda6489de75 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMergePersonsR4Test.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMergePersonsR4Test.java @@ -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 redirect = fromSourcePatient.getIdentifier().stream().filter(theIdentifier -> theIdentifier.getSystem().equals("REDIRECT")).findFirst(); // assertThat(redirect.get().getValue(), is(equalTo(myToSourcePatient.getIdElement().toUnqualified().getValue()))); - List links = myMdmLinkDaoSvc.findMdmLinksByTarget(myFromSourcePatient); + List 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()); diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcTest.java index 6ed6c29a863..7d71b1b4a4e 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcTest.java @@ -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); diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcMultipleEidModeTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcMultipleEidModeTest.java index 2121eeeb920..d189a8c4017 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcMultipleEidModeTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcMultipleEidModeTest.java @@ -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 diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcTest.java index 6f5aa113609..42d331645a3 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcTest.java @@ -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 possibleDuplicates = myMdmLinkDaoSvc.getPossibleDuplicates(); assertThat(possibleDuplicates, hasSize(1)); diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmPersonMergerSvcTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmPersonMergerSvcTest.java index 976dd735d12..e3e6d7662b4 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmPersonMergerSvcTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmPersonMergerSvcTest.java @@ -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()); }