* Add source_resource_id column
* Add source_resource columm Still need to depracate the old columns. Reworked a Matcher to ignore Person
This commit is contained in:
parent
ef2041d89d
commit
5797cd0682
|
@ -60,6 +60,13 @@ public class EmpiLink {
|
|||
@Column(name = "PID")
|
||||
private Long myId;
|
||||
|
||||
@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
|
||||
@JoinColumn(name = "SOURCE_RESOURCE_PID", referencedColumnName = "RES_ID", foreignKey = @ForeignKey(name = "FK_EMPI_LINK_SOURCE_RESOURCE"), insertable=false, updatable=false, nullable=false)
|
||||
private ResourceTable mySourceResource;
|
||||
|
||||
@Column(name = "SOURCE_RESOURCE_PID", nullable=false)
|
||||
private Long mySourceResourcePid;
|
||||
|
||||
@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
|
||||
@JoinColumn(name = "PERSON_PID", referencedColumnName = "RES_ID", foreignKey = @ForeignKey(name = "FK_EMPI_LINK_PERSON"), insertable=false, updatable=false, nullable=false)
|
||||
private ResourceTable myPerson;
|
||||
|
@ -99,7 +106,7 @@ public class EmpiLink {
|
|||
|
||||
/** This link created a new person **/
|
||||
@Column(name = "NEW_PERSON")
|
||||
private Boolean myNewPerson;
|
||||
private Boolean myHadToCreateNewResource;
|
||||
|
||||
@Column(name = "VECTOR")
|
||||
private Long myVector;
|
||||
|
@ -107,6 +114,10 @@ public class EmpiLink {
|
|||
@Column(name = "SCORE")
|
||||
private Double myScore;
|
||||
|
||||
//TODO GGG GL-1340
|
||||
@Column(name = "RULE_COUNT")
|
||||
private Long myRuleCount;
|
||||
|
||||
public EmpiLink() {}
|
||||
|
||||
public EmpiLink(String theVersion) {
|
||||
|
@ -125,18 +136,18 @@ public class EmpiLink {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ResourceTable getPerson() {
|
||||
return myPerson;
|
||||
public ResourceTable getSourceResource() {
|
||||
return mySourceResource;
|
||||
}
|
||||
|
||||
public EmpiLink setPerson(ResourceTable thePerson) {
|
||||
myPerson = thePerson;
|
||||
myPersonPid = thePerson.getId();
|
||||
public EmpiLink setSourceResource(ResourceTable theSourceResource) {
|
||||
mySourceResource = theSourceResource;
|
||||
mySourceResourcePid = theSourceResource.getId();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Long getPersonPid() {
|
||||
return myPersonPid;
|
||||
public Long getSourceResourcePid() {
|
||||
return mySourceResourcePid;
|
||||
}
|
||||
|
||||
public EmpiLink setPersonPid(Long thePersonPid) {
|
||||
|
@ -144,6 +155,11 @@ public class EmpiLink {
|
|||
return this;
|
||||
}
|
||||
|
||||
public EmpiLink setSourceResourcePid(Long theSourceResourcePid) {
|
||||
mySourceResourcePid = theSourceResourcePid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceTable getTarget() {
|
||||
return myTarget;
|
||||
}
|
||||
|
@ -267,16 +283,12 @@ public class EmpiLink {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Boolean getNewPerson() {
|
||||
return myNewPerson;
|
||||
public boolean getHadToCreateNewResource() {
|
||||
return myHadToCreateNewResource != null && myHadToCreateNewResource;
|
||||
}
|
||||
|
||||
public boolean isNewPerson() {
|
||||
return myNewPerson != null && myNewPerson;
|
||||
}
|
||||
|
||||
public EmpiLink setNewPerson(Boolean theNewPerson) {
|
||||
myNewPerson = theNewPerson;
|
||||
public EmpiLink setHadToCreateNewResource(Boolean theHadToCreateNewResource) {
|
||||
myHadToCreateNewResource = theHadToCreateNewResource;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -289,13 +301,13 @@ public class EmpiLink {
|
|||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("myId", myId)
|
||||
.append("myPersonPid", myPersonPid)
|
||||
.append("myPersonPid", mySourceResourcePid)
|
||||
.append("myTargetPid", myTargetPid)
|
||||
.append("myEmpiTargetType", myEmpiTargetType)
|
||||
.append("myMatchResult", myMatchResult)
|
||||
.append("myLinkSource", myLinkSource)
|
||||
.append("myEidMatch", myEidMatch)
|
||||
.append("myNewPerson", myNewPerson)
|
||||
.append("myNewPerson", myHadToCreateNewResource)
|
||||
.append("myScore", myScore)
|
||||
.toString();
|
||||
}
|
||||
|
@ -303,4 +315,12 @@ public class EmpiLink {
|
|||
public String getEmpiTargetType() {
|
||||
return myEmpiTargetType;
|
||||
}
|
||||
|
||||
public Long getRuleCount() {
|
||||
return myRuleCount;
|
||||
}
|
||||
|
||||
public void setRuleCount(Long theRuleCount) {
|
||||
myRuleCount = theRuleCount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class EmpiLinkDaoSvc {
|
|||
empiLink.setMatchResult(theMatchOutcome.getMatchResultEnum());
|
||||
// Preserve these flags for link updates
|
||||
empiLink.setEidMatch(theMatchOutcome.isEidMatch() | empiLink.isEidMatch());
|
||||
empiLink.setNewPerson(theMatchOutcome.isNewPerson() | empiLink.isNewPerson());
|
||||
empiLink.setHadToCreateNewResource(theMatchOutcome.isNewPerson() | empiLink.getHadToCreateNewResource());
|
||||
empiLink.setEmpiTargetType(myFhirContext.getResourceType(theTarget));
|
||||
if (empiLink.getScore() != null) {
|
||||
empiLink.setScore(Math.max(theMatchOutcome.score, empiLink.getScore()));
|
||||
|
@ -90,6 +90,7 @@ public class EmpiLinkDaoSvc {
|
|||
return oExisting.get();
|
||||
} else {
|
||||
EmpiLink newLink = myEmpiLinkFactory.newEmpiLink();
|
||||
newLink.setSourceResourcePid(thePersonPid);
|
||||
newLink.setPersonPid(thePersonPid);
|
||||
newLink.setTargetPid(theResourcePid);
|
||||
return newLink;
|
||||
|
@ -103,7 +104,7 @@ public class EmpiLinkDaoSvc {
|
|||
}
|
||||
EmpiLink link = myEmpiLinkFactory.newEmpiLink();
|
||||
link.setTargetPid(theTargetPid);
|
||||
link.setPersonPid(thePersonPid);
|
||||
link.setSourceResourcePid(thePersonPid);
|
||||
Example<EmpiLink> example = Example.of(link);
|
||||
return myEmpiLinkDao.findOne(example);
|
||||
}
|
||||
|
@ -170,7 +171,7 @@ public class EmpiLinkDaoSvc {
|
|||
*/
|
||||
public Optional<EmpiLink> getEmpiLinksByPersonPidTargetPidAndMatchResult(Long thePersonPid, Long theTargetPid, EmpiMatchResultEnum theMatchResult) {
|
||||
EmpiLink exampleLink = myEmpiLinkFactory.newEmpiLink();
|
||||
exampleLink.setPersonPid(thePersonPid);
|
||||
exampleLink.setSourceResourcePid(thePersonPid);
|
||||
exampleLink.setTargetPid(theTargetPid);
|
||||
exampleLink.setMatchResult(theMatchResult);
|
||||
Example<EmpiLink> example = Example.of(exampleLink);
|
||||
|
@ -222,7 +223,7 @@ public class EmpiLinkDaoSvc {
|
|||
if (pid == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
EmpiLink exampleLink = myEmpiLinkFactory.newEmpiLink().setPersonPid(pid);
|
||||
EmpiLink exampleLink = myEmpiLinkFactory.newEmpiLink().setSourceResourcePid(pid);
|
||||
Example<EmpiLink> example = Example.of(exampleLink);
|
||||
return myEmpiLinkDao.findAll(example);
|
||||
}
|
||||
|
@ -239,7 +240,7 @@ public class EmpiLinkDaoSvc {
|
|||
}
|
||||
|
||||
private List<Long> deleteEmpiLinksAndReturnPersonPids(List<EmpiLink> theLinks) {
|
||||
Set<Long> persons = theLinks.stream().map(EmpiLink::getPersonPid).collect(Collectors.toSet());
|
||||
Set<Long> persons = theLinks.stream().map(EmpiLink::getSourceResourcePid).collect(Collectors.toSet());
|
||||
persons.addAll(theLinks.stream().filter(link -> "Person".equals(link.getEmpiTargetType())).map(EmpiLink::getTargetPid).collect(Collectors.toSet()));
|
||||
ourLog.info("Deleting {} EMPI link records...", theLinks.size());
|
||||
myEmpiLinkDao.deleteAll(theLinks);
|
||||
|
|
|
@ -103,7 +103,7 @@ public class EmpiEidUpdateService {
|
|||
}
|
||||
|
||||
private boolean candidateIsSameAsEmpiLinkPerson(EmpiLink theExistingMatchLink, MatchedPersonCandidate thePersonCandidate) {
|
||||
return theExistingMatchLink.getPersonPid().equals(thePersonCandidate.getCandidatePersonPid().getIdAsLong());
|
||||
return theExistingMatchLink.getSourceResourcePid().equals(thePersonCandidate.getCandidatePersonPid().getIdAsLong());
|
||||
}
|
||||
|
||||
private void createNewPersonAndFlagAsDuplicate(IAnyResource theResource, EmpiTransactionContext theEmpiTransactionContext, IAnyResource theOldPerson) {
|
||||
|
@ -151,7 +151,7 @@ public class EmpiEidUpdateService {
|
|||
myExistingPerson = null;
|
||||
|
||||
if (theExistingMatchLink.isPresent()) {
|
||||
Long existingPersonPid = theExistingMatchLink.get().getPersonPid();
|
||||
Long existingPersonPid = theExistingMatchLink.get().getSourceResourcePid();
|
||||
myExistingPerson = myEmpiResourceDaoSvc.readPersonByPid(new ResourcePersistentId(existingPersonPid));
|
||||
myRemainsMatchedToSamePerson = candidateIsSameAsEmpiLinkPerson(theExistingMatchLink.get(), theMatchedPersonCandidate);
|
||||
} else {
|
||||
|
|
|
@ -52,8 +52,6 @@ public class EmpiLinkQuerySvcImpl implements IEmpiLinkQuerySvc {
|
|||
.map(this::toJson);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Stream<EmpiLinkJson> getDuplicatePersons(EmpiTransactionContext theEmpiContext) {
|
||||
Example<EmpiLink> exampleLink = exampleLinkFromParameters(null, null, EmpiMatchResultEnum.POSSIBLE_DUPLICATE, null);
|
||||
|
@ -64,13 +62,13 @@ public class EmpiLinkQuerySvcImpl implements IEmpiLinkQuerySvc {
|
|||
EmpiLinkJson retval = new EmpiLinkJson();
|
||||
String targetId = myIdHelperService.resourceIdFromPidOrThrowException(theLink.getTargetPid()).toVersionless().getValue();
|
||||
retval.setTargetId(targetId);
|
||||
String personId = myIdHelperService.resourceIdFromPidOrThrowException(theLink.getPersonPid()).toVersionless().getValue();
|
||||
String personId = myIdHelperService.resourceIdFromPidOrThrowException(theLink.getSourceResourcePid()).toVersionless().getValue();
|
||||
retval.setPersonId(personId);
|
||||
retval.setCreated(theLink.getCreated());
|
||||
retval.setEidMatch(theLink.getEidMatch());
|
||||
retval.setLinkSource(theLink.getLinkSource());
|
||||
retval.setMatchResult(theLink.getMatchResult());
|
||||
retval.setNewPerson(theLink.getNewPerson());
|
||||
retval.setNewPerson(theLink.getHadToCreateNewResource());
|
||||
retval.setScore(theLink.getScore());
|
||||
retval.setUpdated(theLink.getUpdated());
|
||||
retval.setVector(theLink.getVector());
|
||||
|
@ -81,7 +79,7 @@ public class EmpiLinkQuerySvcImpl implements IEmpiLinkQuerySvc {
|
|||
private Example<EmpiLink> exampleLinkFromParameters(IIdType thePersonId, IIdType theTargetId, EmpiMatchResultEnum theMatchResult, EmpiLinkSourceEnum theLinkSource) {
|
||||
EmpiLink empiLink = myEmpiLinkDaoSvc.newEmpiLink();
|
||||
if (thePersonId != null) {
|
||||
empiLink.setPersonPid(myIdHelperService.getPidOrThrowException(thePersonId));
|
||||
empiLink.setSourceResourcePid(myIdHelperService.getPidOrThrowException(thePersonId));
|
||||
}
|
||||
if (theTargetId != null) {
|
||||
empiLink.setTargetPid(myIdHelperService.getPidOrThrowException(theTargetId));
|
||||
|
|
|
@ -116,7 +116,7 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
|
|||
}
|
||||
}
|
||||
// The original links didn't contain this target, so move it over to the toPerson
|
||||
fromLink.setPersonPid(theToPersonPid);
|
||||
fromLink.setSourceResourcePid(theToPersonPid);
|
||||
ourLog.trace("Saving link {}", fromLink);
|
||||
myEmpiLinkDaoSvc.save(fromLink);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class FindCandidateByLinkSvc extends BaseCandidateFinder {
|
|||
if (targetPid != null) {
|
||||
Optional<EmpiLink> oLink = myEmpiLinkDaoSvc.getMatchedLinkForTargetPid(targetPid);
|
||||
if (oLink.isPresent()) {
|
||||
ResourcePersistentId personPid = new ResourcePersistentId(oLink.get().getPersonPid());
|
||||
ResourcePersistentId personPid = new ResourcePersistentId(oLink.get().getSourceResourcePid());
|
||||
ourLog.debug("Resource previously linked. Using existing link.");
|
||||
retval.add(new MatchedPersonCandidate(personPid, oLink.get()));
|
||||
}
|
||||
|
|
|
@ -82,12 +82,12 @@ public class FindCandidateByScoreSvc extends BaseCandidateFinder {
|
|||
}
|
||||
|
||||
EmpiLink matchEmpiLink = optMatchEmpiLink.get();
|
||||
if (personPidsToExclude.contains(matchEmpiLink.getPersonPid())) {
|
||||
ourLog.info("Skipping EMPI on candidate person with PID {} due to manual NO_MATCH", matchEmpiLink.getPersonPid());
|
||||
if (personPidsToExclude.contains(matchEmpiLink.getSourceResourcePid())) {
|
||||
ourLog.info("Skipping EMPI on candidate person with PID {} due to manual NO_MATCH", matchEmpiLink.getSourceResourcePid());
|
||||
continue;
|
||||
}
|
||||
|
||||
MatchedPersonCandidate candidate = new MatchedPersonCandidate(getResourcePersistentId(matchEmpiLink.getPersonPid()), match.getMatchResult());
|
||||
MatchedPersonCandidate candidate = new MatchedPersonCandidate(getResourcePersistentId(matchEmpiLink.getSourceResourcePid()), match.getMatchResult());
|
||||
retval.add(candidate);
|
||||
}
|
||||
return retval;
|
||||
|
@ -97,7 +97,7 @@ public class FindCandidateByScoreSvc extends BaseCandidateFinder {
|
|||
Long targetPid = myIdHelperService.getPidOrNull(theBaseResource);
|
||||
return myEmpiLinkDaoSvc.getEmpiLinksByTargetPidAndMatchResult(targetPid, EmpiMatchResultEnum.NO_MATCH)
|
||||
.stream()
|
||||
.map(EmpiLink::getPersonPid)
|
||||
.map(EmpiLink::getSourceResourcePid)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import ca.uhn.fhir.jpa.empi.matcher.IsMatchedToAPerson;
|
|||
import ca.uhn.fhir.jpa.empi.matcher.IsPossibleDuplicateOf;
|
||||
import ca.uhn.fhir.jpa.empi.matcher.IsPossibleLinkedTo;
|
||||
import ca.uhn.fhir.jpa.empi.matcher.IsPossibleMatchWith;
|
||||
import ca.uhn.fhir.jpa.empi.matcher.IsSamePersonAs;
|
||||
import ca.uhn.fhir.jpa.empi.matcher.IsSameSourceResourceAs;
|
||||
import ca.uhn.fhir.jpa.empi.svc.EmpiMatchLinkSvc;
|
||||
import ca.uhn.fhir.jpa.entity.EmpiLink;
|
||||
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
||||
|
@ -272,7 +272,7 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
|
|||
protected Person getPersonFromTarget(IAnyResource theBaseResource) {
|
||||
Optional<EmpiLink> matchedLinkForTargetPid = myEmpiLinkDaoSvc.getMatchedLinkForTargetPid(myIdHelperService.getPidOrNull(theBaseResource));
|
||||
if (matchedLinkForTargetPid.isPresent()) {
|
||||
Long personPid = matchedLinkForTargetPid.get().getPersonPid();
|
||||
Long personPid = matchedLinkForTargetPid.get().getSourceResourcePid();
|
||||
return (Person) myPersonDao.readByPid(new ResourcePersistentId(personPid));
|
||||
} else {
|
||||
return null;
|
||||
|
@ -280,7 +280,7 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
|
|||
}
|
||||
|
||||
protected Person getPersonFromEmpiLink(EmpiLink theEmpiLink) {
|
||||
return (Person) myPersonDao.readByPid(new ResourcePersistentId(theEmpiLink.getPersonPid()));
|
||||
return (Person) myPersonDao.readByPid(new ResourcePersistentId(theEmpiLink.getSourceResourcePid()));
|
||||
}
|
||||
|
||||
protected Patient addExternalEID(Patient thePatient, String theEID) {
|
||||
|
@ -332,8 +332,8 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
|
|||
return thePractitioner;
|
||||
}
|
||||
|
||||
protected Matcher<IAnyResource> samePersonAs(IAnyResource... theBaseResource) {
|
||||
return IsSamePersonAs.samePersonAs(myIdHelperService, myEmpiLinkDaoSvc, theBaseResource);
|
||||
protected Matcher<IAnyResource> sameSourceResourceAs(IAnyResource... theBaseResource) {
|
||||
return IsSameSourceResourceAs.sameSourceResourceAs(myIdHelperService, myEmpiLinkDaoSvc, theBaseResource);
|
||||
}
|
||||
|
||||
protected Matcher<IAnyResource> linkedTo(IAnyResource... theBaseResource) {
|
||||
|
@ -391,7 +391,7 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
|
|||
EmpiLink empiLink = myEmpiLinkDaoSvc.newEmpiLink();
|
||||
empiLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
|
||||
empiLink.setMatchResult(EmpiMatchResultEnum.MATCH);
|
||||
empiLink.setPersonPid(myIdHelperService.getPidOrNull(person));
|
||||
empiLink.setSourceResourcePid(myIdHelperService.getPidOrNull(person));
|
||||
empiLink.setTargetPid(myIdHelperService.getPidOrNull(patient));
|
||||
return empiLink;
|
||||
}
|
||||
|
@ -413,8 +413,8 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
|
|||
assertFields(EmpiLink::getMatchResult, theExpectedValues);
|
||||
}
|
||||
|
||||
protected void assertLinksNewPerson(Boolean... theExpectedValues) {
|
||||
assertFields(EmpiLink::getNewPerson, theExpectedValues);
|
||||
protected void assertLinksCreatedNewResource(Boolean... theExpectedValues) {
|
||||
assertFields(EmpiLink::getHadToCreateNewResource, theExpectedValues);
|
||||
}
|
||||
|
||||
protected void assertLinksMatchedByEid(Boolean... theExpectedValues) {
|
||||
|
|
|
@ -23,7 +23,7 @@ public class EmpiLinkHelper {
|
|||
List<EmpiLink> links = myEmpiLinkDao.findAll();
|
||||
ourLog.info("All EMPI Links:");
|
||||
for (EmpiLink link : links) {
|
||||
IdDt personId = link.getPerson().getIdDt().toVersionless();
|
||||
IdDt personId = link.getSourceResource().getIdDt().toVersionless();
|
||||
IdDt targetId = link.getTarget().getIdDt().toVersionless();
|
||||
ourLog.info("{}: {}, {}, {}, {}", link.getId(), personId, targetId, link.getMatchResult(), link.getLinkSource());
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class EmpiExpungeTest extends BaseEmpiR4Test {
|
|||
EmpiLink empiLink = myEmpiLinkDaoSvc.newEmpiLink();
|
||||
empiLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
|
||||
empiLink.setMatchResult(EmpiMatchResultEnum.MATCH);
|
||||
empiLink.setPersonPid(myPersonEntity.getId());
|
||||
empiLink.setSourceResourcePid(myPersonEntity.getId());
|
||||
empiLink.setTargetPid(myTargetEntity.getId());
|
||||
saveLink(empiLink);
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test {
|
|||
|
||||
//Updating a Person who was created via EMPI should fail.
|
||||
EmpiLink empiLink = myEmpiLinkDaoSvc.getMatchedLinkForTargetPid(myIdHelperService.getPidOrNull(patient)).get();
|
||||
Long personPid = empiLink.getPersonPid();
|
||||
Long personPid = empiLink.getSourceResourcePid();
|
||||
Person empiPerson = (Person) myPersonDao.readByPid(new ResourcePersistentId(personPid));
|
||||
empiPerson.setGender(Enumerations.AdministrativeGender.MALE);
|
||||
try {
|
||||
|
|
|
@ -16,40 +16,32 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class BasePersonMatcher extends TypeSafeMatcher<IAnyResource> {
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(BasePersonMatcher.class);
|
||||
public abstract class BaseSourceResourceMatcher extends TypeSafeMatcher<IAnyResource> {
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(BaseSourceResourceMatcher.class);
|
||||
|
||||
protected IdHelperService myIdHelperService;
|
||||
protected EmpiLinkDaoSvc myEmpiLinkDaoSvc;
|
||||
protected Collection<IAnyResource> myBaseResources;
|
||||
protected String myTargetType;
|
||||
|
||||
protected BasePersonMatcher(IdHelperService theIdHelperService, EmpiLinkDaoSvc theEmpiLinkDaoSvc, IAnyResource... theBaseResource) {
|
||||
protected BaseSourceResourceMatcher(IdHelperService theIdHelperService, EmpiLinkDaoSvc theEmpiLinkDaoSvc, IAnyResource... theBaseResource) {
|
||||
myIdHelperService = theIdHelperService;
|
||||
myEmpiLinkDaoSvc = theEmpiLinkDaoSvc;
|
||||
myBaseResources = Arrays.stream(theBaseResource).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Long getMatchedPersonPidFromResource(IAnyResource theResource) {
|
||||
protected Long getMatchedResourcePidFromResource(IAnyResource theResource) {
|
||||
Long retval;
|
||||
if (isPatientOrPractitioner(theResource)) {
|
||||
EmpiLink matchLink = getMatchedEmpiLink(theResource);
|
||||
retval = matchLink == null ? null : matchLink.getPersonPid();
|
||||
} else if (isPerson(theResource)) {
|
||||
retval = myIdHelperService.getPidOrNull(theResource);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Resources of type " + theResource.getIdElement().getResourceType() + " cannot be persons!");
|
||||
}
|
||||
EmpiLink matchLink = getMatchedEmpiLink(theResource);
|
||||
myTargetType = matchLink.getEmpiTargetType();
|
||||
//TODO if this is already a golden record resource, we can just use its PID instead of doing a lookup.
|
||||
retval = matchLink == null ? null : matchLink.getSourceResourcePid();
|
||||
return retval;
|
||||
}
|
||||
|
||||
protected List<Long> getPossibleMatchedPersonPidsFromTarget(IAnyResource theBaseResource) {
|
||||
return getEmpiLinksForTarget(theBaseResource, EmpiMatchResultEnum.POSSIBLE_MATCH).stream().map(EmpiLink::getPersonPid).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected boolean isPatientOrPractitioner(IAnyResource theResource) {
|
||||
String resourceType = theResource.getIdElement().getResourceType();
|
||||
return (resourceType.equalsIgnoreCase("Patient") || resourceType.equalsIgnoreCase("Practitioner"));
|
||||
protected List<Long> getPossibleMatchedSourceResourcePidsFromTarget(IAnyResource theBaseResource) {
|
||||
return getEmpiLinksForTarget(theBaseResource, EmpiMatchResultEnum.POSSIBLE_MATCH).stream().map(EmpiLink::getSourceResourcePid).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected EmpiLink getMatchedEmpiLink(IAnyResource thePatientOrPractitionerResource) {
|
||||
|
@ -63,10 +55,6 @@ public abstract class BasePersonMatcher extends TypeSafeMatcher<IAnyResource> {
|
|||
}
|
||||
}
|
||||
|
||||
protected boolean isPerson(IAnyResource theIncomingResource) {
|
||||
return (theIncomingResource.getIdElement().getResourceType().equalsIgnoreCase("Person"));
|
||||
}
|
||||
|
||||
protected List<EmpiLink> getEmpiLinksForTarget(IAnyResource thePatientOrPractitionerResource, EmpiMatchResultEnum theMatchResult) {
|
||||
Long pidOrNull = myIdHelperService.getPidOrNull(thePatientOrPractitionerResource);
|
||||
List<EmpiLink> matchLinkForTarget = myEmpiLinkDaoSvc.getEmpiLinksByTargetPidAndMatchResult(pidOrNull, theMatchResult);
|
|
@ -14,7 +14,7 @@ import java.util.stream.Collectors;
|
|||
* is linked to a set of patients/practitioners via a person.
|
||||
*
|
||||
*/
|
||||
public class IsLinkedTo extends BasePersonMatcher {
|
||||
public class IsLinkedTo extends BaseSourceResourceMatcher {
|
||||
|
||||
private List<Long> baseResourcePersonPids;
|
||||
private Long incomingResourcePersonPid;
|
||||
|
@ -26,11 +26,11 @@ public class IsLinkedTo extends BasePersonMatcher {
|
|||
|
||||
@Override
|
||||
protected boolean matchesSafely(IAnyResource theIncomingResource) {
|
||||
incomingResourcePersonPid = getMatchedPersonPidFromResource(theIncomingResource);
|
||||
incomingResourcePersonPid = getMatchedResourcePidFromResource(theIncomingResource);
|
||||
|
||||
//OK, lets grab all the person pids of the resources passed in via the constructor.
|
||||
baseResourcePersonPids = myBaseResources.stream()
|
||||
.map(this::getMatchedPersonPidFromResource)
|
||||
.map(this::getMatchedResourcePidFromResource)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//The resources are linked if all person pids match the incoming person pid.
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class IsPossibleDuplicateOf extends BasePersonMatcher {
|
||||
public class IsPossibleDuplicateOf extends BaseSourceResourceMatcher {
|
||||
/**
|
||||
* Matcher with tells us if there is an EmpiLink with between these two resources that are considered POSSIBLE DUPLICATE.
|
||||
* For use only on persons.
|
||||
|
@ -26,10 +26,10 @@ public class IsPossibleDuplicateOf extends BasePersonMatcher {
|
|||
@Override
|
||||
protected boolean matchesSafely(IAnyResource theIncomingResource) {
|
||||
|
||||
incomingPersonPid = getMatchedPersonPidFromResource(theIncomingResource);
|
||||
incomingPersonPid = getMatchedResourcePidFromResource(theIncomingResource);
|
||||
|
||||
List<Long> personPidsToMatch = myBaseResources.stream()
|
||||
.map(this::getMatchedPersonPidFromResource)
|
||||
.map(this::getMatchedResourcePidFromResource)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.stream.Collectors;
|
|||
* is linked to a set of patients/practitioners via a person.
|
||||
*
|
||||
*/
|
||||
public class IsPossibleLinkedTo extends BasePersonMatcher {
|
||||
public class IsPossibleLinkedTo extends BaseSourceResourceMatcher {
|
||||
|
||||
private List<Long> baseResourcePersonPids;
|
||||
private Long incomingResourcePersonPid;
|
||||
|
@ -29,7 +29,7 @@ public class IsPossibleLinkedTo extends BasePersonMatcher {
|
|||
|
||||
//OK, lets grab all the person pids of the resources passed in via the constructor.
|
||||
baseResourcePersonPids = myBaseResources.stream()
|
||||
.flatMap(iBaseResource -> getPossibleMatchedPersonPidsFromTarget(iBaseResource).stream())
|
||||
.flatMap(iBaseResource -> getPossibleMatchedSourceResourcePidsFromTarget(iBaseResource).stream())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//The resources are linked if all person pids match the incoming person pid.
|
||||
|
|
|
@ -15,7 +15,7 @@ import java.util.stream.Collectors;
|
|||
/**
|
||||
* Matcher with tells us if there is an EmpiLink with between these two resources that are considered POSSIBLE_MATCH
|
||||
*/
|
||||
public class IsPossibleMatchWith extends BasePersonMatcher {
|
||||
public class IsPossibleMatchWith extends BaseSourceResourceMatcher {
|
||||
|
||||
protected IsPossibleMatchWith(IdHelperService theIdHelperService, EmpiLinkDaoSvc theEmpiLinkDaoSvc, IAnyResource... theBaseResource) {
|
||||
super(theIdHelperService, theEmpiLinkDaoSvc, theBaseResource);
|
||||
|
@ -26,17 +26,17 @@ public class IsPossibleMatchWith extends BasePersonMatcher {
|
|||
List<EmpiLink> empiLinks = getEmpiLinksForTarget(theIncomingResource, EmpiMatchResultEnum.POSSIBLE_MATCH);
|
||||
|
||||
List<Long> personPidsToMatch = myBaseResources.stream()
|
||||
.map(this::getMatchedPersonPidFromResource)
|
||||
.map(this::getMatchedResourcePidFromResource)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (personPidsToMatch.isEmpty()) {
|
||||
personPidsToMatch = myBaseResources.stream()
|
||||
.flatMap(iBaseResource -> getPossibleMatchedPersonPidsFromTarget(iBaseResource).stream())
|
||||
.flatMap(iBaseResource -> getPossibleMatchedSourceResourcePidsFromTarget(iBaseResource).stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<Long> empiLinkSourcePersonPids = empiLinks.stream().map(EmpiLink::getPersonPid).collect(Collectors.toList());
|
||||
List<Long> empiLinkSourcePersonPids = empiLinks.stream().map(EmpiLink::getSourceResourcePid).collect(Collectors.toList());
|
||||
|
||||
return empiLinkSourcePersonPids.containsAll(personPidsToMatch);
|
||||
}
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
package ca.uhn.fhir.jpa.empi.matcher;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.index.IdHelperService;
|
||||
import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class IsSamePersonAs extends BasePersonMatcher {
|
||||
|
||||
private List<Long> personPidsToMatch;
|
||||
private Long incomingPersonPid;
|
||||
|
||||
public IsSamePersonAs(IdHelperService theIdHelperService, EmpiLinkDaoSvc theEmpiLinkDaoSvc, IAnyResource... theBaseResource) {
|
||||
super(theIdHelperService, theEmpiLinkDaoSvc, theBaseResource);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchesSafely(IAnyResource theIncomingResource) {
|
||||
incomingPersonPid = getMatchedPersonPidFromResource(theIncomingResource);
|
||||
personPidsToMatch = myBaseResources.stream().map(this::getMatchedPersonPidFromResource).collect(Collectors.toList());
|
||||
boolean allToCheckAreSame = personPidsToMatch.stream().allMatch(pid -> pid.equals(personPidsToMatch.get(0)));
|
||||
if (!allToCheckAreSame) {
|
||||
throw new IllegalStateException("You wanted to do a person comparison, but the pool of persons you submitted for checking don't match! We won't even check the incoming person against them.");
|
||||
}
|
||||
return personPidsToMatch.contains(incomingPersonPid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description theDescription) {
|
||||
theDescription.appendText("patient/practitioner linked to Person/" + personPidsToMatch);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void describeMismatchSafely(IAnyResource item, Description mismatchDescription) {
|
||||
super.describeMismatchSafely(item, mismatchDescription);
|
||||
mismatchDescription.appendText(" was actually linked to Person/" + incomingPersonPid);
|
||||
}
|
||||
|
||||
public static Matcher<IAnyResource> samePersonAs(IdHelperService theIdHelperService, EmpiLinkDaoSvc theEmpiLinkDaoSvc, IAnyResource... theBaseResource) {
|
||||
return new IsSamePersonAs(theIdHelperService, theEmpiLinkDaoSvc, theBaseResource);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package ca.uhn.fhir.jpa.empi.matcher;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.index.IdHelperService;
|
||||
import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class IsSameSourceResourceAs extends BaseSourceResourceMatcher {
|
||||
|
||||
private List<Long> sourceResourcePidsToMatch;
|
||||
private Long incomingSourceResourcePid;
|
||||
|
||||
public IsSameSourceResourceAs(IdHelperService theIdHelperService, EmpiLinkDaoSvc theEmpiLinkDaoSvc, IAnyResource... theBaseResource) {
|
||||
super(theIdHelperService, theEmpiLinkDaoSvc, 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)));
|
||||
if (!allToCheckAreSame) {
|
||||
throw new IllegalStateException("You wanted to do a source resource comparison, but the pool of persons you submitted for checking don't match! We won't even check the incoming person against them.");
|
||||
}
|
||||
return sourceResourcePidsToMatch.contains(incomingSourceResourcePid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description theDescription) {
|
||||
theDescription.appendText(String.format(" %s linked to source resource %s/%s", myTargetType, myTargetType, sourceResourcePidsToMatch));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void describeMismatchSafely(IAnyResource item, Description mismatchDescription) {
|
||||
super.describeMismatchSafely(item, mismatchDescription);
|
||||
mismatchDescription.appendText(String.format(" was actually linked to %s/%s", myTargetType, incomingSourceResourcePid));
|
||||
}
|
||||
|
||||
public static Matcher<IAnyResource> sameSourceResourceAs(IdHelperService theIdHelperService, EmpiLinkDaoSvc theEmpiLinkDaoSvc, IAnyResource... theBaseResource) {
|
||||
return new IsSameSourceResourceAs(theIdHelperService, theEmpiLinkDaoSvc, theBaseResource);
|
||||
}
|
||||
}
|
|
@ -42,7 +42,7 @@ public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test {
|
|||
public void testMerge() {
|
||||
Person mergedPerson = myEmpiProviderR4.mergePersons(myFromPersonId, myToPersonId, myRequestDetails);
|
||||
assertEquals(myToPerson.getIdElement(), mergedPerson.getIdElement());
|
||||
assertThat(mergedPerson, is(samePersonAs(myToPerson)));
|
||||
assertThat(mergedPerson, is(sameSourceResourceAs(myToPerson)));
|
||||
assertEquals(2, getAllPersons().size());
|
||||
assertEquals(1, getAllActivePersons().size());
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public class EmpiProviderQueryLinkR4Test extends BaseLinkR4Test {
|
|||
myPerson2Id = new StringType(person2.getIdElement().toVersionless().getValue());
|
||||
Long person2Pid = myIdHelperService.getPidOrNull(person2);
|
||||
|
||||
EmpiLink possibleDuplicateEmpiLink = myEmpiLinkDaoSvc.newEmpiLink().setPersonPid(person1Pid).setTargetPid(person2Pid).setMatchResult(EmpiMatchResultEnum.POSSIBLE_DUPLICATE).setLinkSource(EmpiLinkSourceEnum.AUTO);
|
||||
EmpiLink possibleDuplicateEmpiLink = myEmpiLinkDaoSvc.newEmpiLink().setSourceResourcePid(person1Pid).setTargetPid(person2Pid).setMatchResult(EmpiMatchResultEnum.POSSIBLE_DUPLICATE).setLinkSource(EmpiLinkSourceEnum.AUTO);
|
||||
saveLink(possibleDuplicateEmpiLink);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
|||
assertEquals(EmpiMatchResultEnum.NO_MATCH, links.get(0).getMatchResult());
|
||||
assertEquals(EmpiLinkSourceEnum.AUTO, links.get(1).getLinkSource());
|
||||
assertEquals(EmpiMatchResultEnum.MATCH, links.get(1).getMatchResult());
|
||||
assertNotEquals(links.get(0).getPersonPid(), links.get(1).getPersonPid());
|
||||
assertNotEquals(links.get(0).getSourceResourcePid(), links.get(1).getSourceResourcePid());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -116,7 +116,7 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test {
|
|||
|
||||
private void saveNoMatchLink(Long thePersonPid, Long theTargetPid) {
|
||||
EmpiLink noMatchLink = myEmpiLinkDaoSvc.newEmpiLink()
|
||||
.setPersonPid(thePersonPid)
|
||||
.setSourceResourcePid(thePersonPid)
|
||||
.setTargetPid(theTargetPid)
|
||||
.setLinkSource(EmpiLinkSourceEnum.MANUAL)
|
||||
.setMatchResult(EmpiMatchResultEnum.NO_MATCH);
|
||||
|
|
|
@ -47,7 +47,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
|
|||
// Existing Person with system-assigned EID found linked from matched Patient. incoming Patient has EID. Replace Person system-assigned EID with Patient EID.
|
||||
Patient patient = createPatientAndUpdateLinks(buildJanePatient());
|
||||
assertLinksMatchResult(MATCH);
|
||||
assertLinksNewPerson(true);
|
||||
assertLinksCreatedNewResource(true);
|
||||
assertLinksMatchedByEid(false);
|
||||
|
||||
Person janePerson = getPersonFromTarget(patient);
|
||||
|
@ -59,11 +59,11 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
|
|||
addExternalEID(janePatient, "67890");
|
||||
createPatientAndUpdateLinks(janePatient);
|
||||
assertLinksMatchResult(MATCH, MATCH);
|
||||
assertLinksNewPerson(true, false);
|
||||
assertLinksCreatedNewResource(true, false);
|
||||
assertLinksMatchedByEid(false, false);
|
||||
|
||||
//We want to make sure the patients were linked to the same person.
|
||||
assertThat(patient, is(samePersonAs(janePatient)));
|
||||
assertThat(patient, is(sameSourceResourceAs(janePatient)));
|
||||
|
||||
Person person = getPersonFromTarget(patient);
|
||||
|
||||
|
@ -95,7 +95,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
|
|||
addExternalEID(patient1, "id_4");
|
||||
createPatientAndUpdateLinks(patient1);
|
||||
assertLinksMatchResult(MATCH);
|
||||
assertLinksNewPerson(true);
|
||||
assertLinksCreatedNewResource(true);
|
||||
assertLinksMatchedByEid(false);
|
||||
|
||||
Patient patient2 = buildPaulPatient();
|
||||
|
@ -103,10 +103,10 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
|
|||
addExternalEID(patient2, "id_1");
|
||||
patient2 = createPatientAndUpdateLinks(patient2);
|
||||
assertLinksMatchResult(MATCH, MATCH);
|
||||
assertLinksNewPerson(true, false);
|
||||
assertLinksCreatedNewResource(true, false);
|
||||
assertLinksMatchedByEid(false, true);
|
||||
|
||||
assertThat(patient1, is(samePersonAs(patient2)));
|
||||
assertThat(patient1, is(sameSourceResourceAs(patient2)));
|
||||
|
||||
clearExternalEIDs(patient2);
|
||||
addExternalEID(patient2, "id_6");
|
||||
|
@ -117,10 +117,10 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
|
|||
|
||||
updatePatientAndUpdateLinks(patient2);
|
||||
assertLinksMatchResult(MATCH, MATCH);
|
||||
assertLinksNewPerson(true, false);
|
||||
assertLinksCreatedNewResource(true, false);
|
||||
assertLinksMatchedByEid(false, true);
|
||||
|
||||
assertThat(patient1, is(samePersonAs(patient2)));
|
||||
assertThat(patient1, is(sameSourceResourceAs(patient2)));
|
||||
|
||||
personFromTarget = getPersonFromTarget(patient2);
|
||||
assertThat(personFromTarget.getIdentifier(), hasSize(6));
|
||||
|
@ -134,7 +134,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
|
|||
addExternalEID(patient1, "eid-11");
|
||||
patient1 = createPatientAndUpdateLinks(patient1);
|
||||
assertLinksMatchResult(MATCH);
|
||||
assertLinksNewPerson(true);
|
||||
assertLinksCreatedNewResource(true);
|
||||
assertLinksMatchedByEid(false);
|
||||
|
||||
Patient patient2 = buildJanePatient();
|
||||
|
@ -142,7 +142,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
|
|||
addExternalEID(patient2, "eid-22");
|
||||
patient2 = createPatientAndUpdateLinks(patient2);
|
||||
assertLinksMatchResult(MATCH, MATCH, POSSIBLE_DUPLICATE);
|
||||
assertLinksNewPerson(true, true, false);
|
||||
assertLinksCreatedNewResource(true, true, false);
|
||||
assertLinksMatchedByEid(false, false, true);
|
||||
|
||||
List<EmpiLink> possibleDuplicates = myEmpiLinkDaoSvc.getPossibleDuplicates();
|
||||
|
@ -155,7 +155,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
|
|||
|
||||
//The two Persons related to the patients should both show up in the only existing POSSIBLE_DUPLICATE EmpiLink.
|
||||
EmpiLink empiLink = possibleDuplicates.get(0);
|
||||
assertThat(empiLink.getPersonPid(), is(in(duplicatePids)));
|
||||
assertThat(empiLink.getSourceResourcePid(), is(in(duplicatePids)));
|
||||
assertThat(empiLink.getTargetPid(), is(in(duplicatePids)));
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
|
|||
addExternalEID(patient1, "eid-11");
|
||||
patient1 = createPatientAndUpdateLinks(patient1);
|
||||
assertLinksMatchResult(MATCH);
|
||||
assertLinksNewPerson(true);
|
||||
assertLinksCreatedNewResource(true);
|
||||
assertLinksMatchedByEid(false);
|
||||
|
||||
Patient patient2 = buildPaulPatient();
|
||||
|
@ -175,18 +175,18 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
|
|||
addExternalEID(patient2, "eid-22");
|
||||
patient2 = createPatientAndUpdateLinks(patient2);
|
||||
assertLinksMatchResult(MATCH, MATCH);
|
||||
assertLinksNewPerson(true, true);
|
||||
assertLinksCreatedNewResource(true, true);
|
||||
assertLinksMatchedByEid(false, false);
|
||||
|
||||
Patient patient3 = buildPaulPatient();
|
||||
addExternalEID(patient3, "eid-22");
|
||||
patient3 = createPatientAndUpdateLinks(patient3);
|
||||
assertLinksMatchResult(MATCH, MATCH, MATCH);
|
||||
assertLinksNewPerson(true, true, false);
|
||||
assertLinksCreatedNewResource(true, true, false);
|
||||
assertLinksMatchedByEid(false, false, true);
|
||||
|
||||
//Now, Patient 2 and 3 are linked, and the person has 2 eids.
|
||||
assertThat(patient2, is(samePersonAs(patient3)));
|
||||
assertThat(patient2, is(sameSourceResourceAs(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
|
||||
|
@ -197,7 +197,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
|
|||
patient2 = updatePatientAndUpdateLinks(patient2);
|
||||
logAllLinks();
|
||||
assertLinksMatchResult(MATCH, POSSIBLE_MATCH, MATCH, POSSIBLE_MATCH, POSSIBLE_DUPLICATE);
|
||||
assertLinksNewPerson(true, true, false, false, false);
|
||||
assertLinksCreatedNewResource(true, true, false, false, false);
|
||||
assertLinksMatchedByEid(false, true, true, true, true);
|
||||
|
||||
assertThat(patient2, is(not(matchedToAPerson())));
|
||||
|
|
|
@ -41,6 +41,8 @@ import static org.hamcrest.Matchers.hasSize;
|
|||
import static org.hamcrest.Matchers.in;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
|
@ -63,19 +65,21 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
createPatientAndUpdateLinks(buildJanePatient());
|
||||
assertLinkCount(1);
|
||||
assertLinksMatchResult(MATCH);
|
||||
assertLinksNewPerson(true);
|
||||
assertLinksCreatedNewResource(true);
|
||||
assertLinksMatchedByEid(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddPatientLinksToNewPersonIfNoMatch() {
|
||||
public void testAddPatientLinksToNewlyCreatedResourceIfNoMatch() {
|
||||
Patient patient1 = createPatientAndUpdateLinks(buildJanePatient());
|
||||
Patient patient2 = createPatientAndUpdateLinks(buildPaulPatient());
|
||||
|
||||
assertLinkCount(2);
|
||||
assertThat(patient1, is(not(samePersonAs(patient2))));
|
||||
|
||||
assertThat(patient1, is(not(sameSourceResourceAs(patient2))));
|
||||
|
||||
assertLinksMatchResult(MATCH, MATCH);
|
||||
assertLinksNewPerson(true, true);
|
||||
assertLinksCreatedNewResource(true, true);
|
||||
assertLinksMatchedByEid(false, false);
|
||||
}
|
||||
|
||||
|
@ -87,9 +91,9 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
Patient patient2 = createPatientAndUpdateLinks(buildJanePatient());
|
||||
assertLinkCount(2);
|
||||
|
||||
assertThat(patient1, is(samePersonAs(patient2)));
|
||||
assertThat(patient1, is(sameSourceResourceAs(patient2)));
|
||||
assertLinksMatchResult(MATCH, MATCH);
|
||||
assertLinksNewPerson(true, false);
|
||||
assertLinksCreatedNewResource(true, false);
|
||||
assertLinksMatchedByEid(false, false);
|
||||
}
|
||||
|
||||
|
@ -106,11 +110,11 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
//rerun EMPI rules against unmatchedJane.
|
||||
myEmpiMatchLinkSvc.updateEmpiLinksForEmpiTarget(unmatchedJane, createContextForCreate());
|
||||
|
||||
assertThat(unmatchedJane, is(not(samePersonAs(janePerson))));
|
||||
assertThat(unmatchedJane, is(not(sameSourceResourceAs(janePerson))));
|
||||
assertThat(unmatchedJane, is(not(linkedTo(originalJane))));
|
||||
|
||||
assertLinksMatchResult(MATCH, NO_MATCH, MATCH);
|
||||
assertLinksNewPerson(true, false, true);
|
||||
assertLinksCreatedNewResource(true, false, true);
|
||||
assertLinksMatchedByEid(false, false, false);
|
||||
}
|
||||
|
||||
|
@ -130,11 +134,11 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
//should cause a whole new Person to be created.
|
||||
myEmpiMatchLinkSvc.updateEmpiLinksForEmpiTarget(unmatchedPatient, createContextForCreate());
|
||||
|
||||
assertThat(unmatchedPatient, is(not(samePersonAs(janePerson))));
|
||||
assertThat(unmatchedPatient, is(not(sameSourceResourceAs(janePerson))));
|
||||
assertThat(unmatchedPatient, is(not(linkedTo(originalJane))));
|
||||
|
||||
assertLinksMatchResult(MATCH, NO_MATCH, MATCH);
|
||||
assertLinksNewPerson(true, false, true);
|
||||
assertLinksCreatedNewResource(true, false, true);
|
||||
assertLinksMatchedByEid(false, false, false);
|
||||
}
|
||||
|
||||
|
@ -184,7 +188,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
public void testPatientMatchingAnotherPatientLinksToSamePerson() {
|
||||
Patient janePatient = createPatientAndUpdateLinks(buildJanePatient());
|
||||
Patient sameJanePatient = createPatientAndUpdateLinks(buildJanePatient());
|
||||
assertThat(janePatient, is(samePersonAs(sameJanePatient)));
|
||||
assertThat(janePatient, is(sameSourceResourceAs(sameJanePatient)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -200,7 +204,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
createPatientAndUpdateLinks(janePatient);
|
||||
|
||||
//We want to make sure the patients were linked to the same person.
|
||||
assertThat(patient, is(samePersonAs(janePatient)));
|
||||
assertThat(patient, is(sameSourceResourceAs(janePatient)));
|
||||
|
||||
Person person = getPersonFromTarget(patient);
|
||||
|
||||
|
@ -225,7 +229,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
Patient patient2 = addExternalEID(buildPaulPatient(), "uniqueid");
|
||||
createPatientAndUpdateLinks(patient2);
|
||||
|
||||
assertThat(patient1, is(samePersonAs(patient2)));
|
||||
assertThat(patient1, is(sameSourceResourceAs(patient2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -243,7 +247,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
addExternalEID(patient2, "id_1");
|
||||
createPatientAndUpdateLinks(patient2);
|
||||
|
||||
assertThat(patient1, is(samePersonAs(patient2)));
|
||||
assertThat(patient1, is(sameSourceResourceAs(patient2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -266,7 +270,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
|
||||
//The two Persons related to the patients should both show up in the only existing POSSIBLE_DUPLICATE EmpiLink.
|
||||
EmpiLink empiLink = possibleDuplicates.get(0);
|
||||
assertThat(empiLink.getPersonPid(), is(in(duplicatePids)));
|
||||
assertThat(empiLink.getSourceResourcePid(), is(in(duplicatePids)));
|
||||
assertThat(empiLink.getTargetPid(), is(in(duplicatePids)));
|
||||
}
|
||||
|
||||
|
@ -285,7 +289,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
Practitioner janePractitioner = createPractitionerAndUpdateLinks(buildJanePractitioner());
|
||||
|
||||
assertLinkCount(2);
|
||||
assertThat(janePatient, is(not(samePersonAs(janePractitioner))));
|
||||
assertThat(janePatient, is(not(sameSourceResourceAs(janePractitioner))));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -294,7 +298,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
Practitioner anotherJanePractitioner = createPractitionerAndUpdateLinks(buildJanePractitioner());
|
||||
|
||||
assertLinkCount(2);
|
||||
assertThat(anotherJanePractitioner, is(samePersonAs(janePractitioner)));
|
||||
assertThat(anotherJanePractitioner, is(sameSourceResourceAs(janePractitioner)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -319,10 +323,10 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
Patient janePatient2 = createPatientAndUpdateLinks(buildJanePatient());
|
||||
|
||||
assertLinkCount(2);
|
||||
assertThat(janePatient, is(samePersonAs(janePatient2)));
|
||||
assertThat(janePatient, is(sameSourceResourceAs(janePatient2)));
|
||||
|
||||
Patient incomingJanePatient = createPatientAndUpdateLinks(buildJanePatient());
|
||||
assertThat(incomingJanePatient, is(samePersonAs(janePatient, janePatient2)));
|
||||
assertThat(incomingJanePatient, is(sameSourceResourceAs(janePatient, janePatient2)));
|
||||
assertThat(incomingJanePatient, is(linkedTo(janePatient, janePatient2)));
|
||||
}
|
||||
|
||||
|
@ -340,7 +344,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
//own individual Persons for the purpose of this test.
|
||||
IAnyResource person = myPersonHelper.createPersonFromEmpiTarget(janePatient2);
|
||||
myEmpiLinkSvc.updateLink(person, janePatient2, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, createContextForCreate());
|
||||
assertThat(janePatient, is(not(samePersonAs(janePatient2))));
|
||||
assertThat(janePatient, is(not(sameSourceResourceAs(janePatient2))));
|
||||
|
||||
//In theory, this will match both Persons!
|
||||
Patient incomingJanePatient = createPatientAndUpdateLinks(buildJanePatient());
|
||||
|
@ -357,7 +361,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
|
||||
logAllLinks();
|
||||
assertLinksMatchResult(MATCH, MATCH, POSSIBLE_MATCH, POSSIBLE_MATCH, POSSIBLE_DUPLICATE);
|
||||
assertLinksNewPerson(true, true, false, false, false);
|
||||
assertLinksCreatedNewResource(true, true, false, false, false);
|
||||
assertLinksMatchedByEid(false, false, false, false, false);
|
||||
}
|
||||
|
||||
|
@ -370,7 +374,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
Patient patient = buildJanePatient();
|
||||
patient.getNameFirstRep().setFamily("familyone");
|
||||
patient = createPatientAndUpdateLinks(patient);
|
||||
assertThat(patient, is(samePersonAs(patient)));
|
||||
assertThat(patient, is(sameSourceResourceAs(patient)));
|
||||
|
||||
Patient patient2 = buildJanePatient();
|
||||
patient2.getNameFirstRep().setFamily("pleasedonotmatchatall");
|
||||
|
@ -393,7 +397,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
assertEquals(Person.IdentityAssuranceLevel.LEVEL1, person.getLink().get(2).getAssurance());
|
||||
|
||||
assertLinksMatchResult(MATCH, POSSIBLE_MATCH, POSSIBLE_MATCH);
|
||||
assertLinksNewPerson(true, false, false);
|
||||
assertLinksCreatedNewResource(true, false, false);
|
||||
assertLinksMatchedByEid(false, false, false);
|
||||
}
|
||||
|
||||
|
@ -402,7 +406,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
Patient patient = buildJanePatient();
|
||||
patient.getNameFirstRep().setFamily("familyone");
|
||||
patient = createPatientAndUpdateLinks(patient);
|
||||
assertThat(patient, is(samePersonAs(patient)));
|
||||
assertThat(patient, is(sameSourceResourceAs(patient)));
|
||||
|
||||
Patient patient2 = buildJanePatient();
|
||||
patient2.getNameFirstRep().setFamily("pleasedonotmatchatall");
|
||||
|
@ -412,9 +416,9 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
patient3.getNameFirstRep().setFamily("familyone");
|
||||
patient3 = createPatientAndUpdateLinks(patient3);
|
||||
|
||||
assertThat(patient2, is(not(samePersonAs(patient))));
|
||||
assertThat(patient2, is(not(sameSourceResourceAs(patient))));
|
||||
assertThat(patient2, is(possibleMatchWith(patient)));
|
||||
assertThat(patient3, is(samePersonAs(patient)));
|
||||
assertThat(patient3, is(sameSourceResourceAs(patient)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -451,7 +455,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
patient1.setId(janePatient.getId());
|
||||
Patient janePaulPatient = updatePatientAndUpdateLinks(patient1);
|
||||
|
||||
assertThat(janePerson, is(samePersonAs(janePaulPatient)));
|
||||
assertThat(janePerson, is(sameSourceResourceAs(janePaulPatient)));
|
||||
|
||||
//Ensure the related person was updated with new info.
|
||||
Person personFromTarget = getPersonFromTarget(janePaulPatient);
|
||||
|
@ -472,7 +476,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
paul2.setGender(Enumerations.AdministrativeGender.FEMALE);
|
||||
paul2 = createPatientAndUpdateLinks(paul2);
|
||||
|
||||
assertThat(paul2, is(samePersonAs(paul)));
|
||||
assertThat(paul2, is(sameSourceResourceAs(paul)));
|
||||
|
||||
//Newly matched patients aren't allowed to overwrite Person Attributes unless they are empty, so gender should still be set to male.
|
||||
Person paul2Person = getPersonFromTarget(paul2);
|
||||
|
@ -517,7 +521,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
updatePatientAndUpdateLinks(paul);
|
||||
|
||||
assertThat(originalJanePerson, is(possibleDuplicateOf(originalPaulPerson)));
|
||||
assertThat(jane, is(samePersonAs(paul)));
|
||||
assertThat(jane, is(sameSourceResourceAs(paul)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -539,7 +543,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
assertNoDuplicates();
|
||||
|
||||
Person newlyFoundPaulPerson = getPersonFromTarget(paul);
|
||||
assertThat(originalPaulPerson, is(samePersonAs(newlyFoundPaulPerson)));
|
||||
assertThat(originalPaulPerson, is(sameSourceResourceAs(newlyFoundPaulPerson)));
|
||||
String newEid = myEidHelper.getExternalEid(newlyFoundPaulPerson).get(0).getValue();
|
||||
assertThat(newEid, is(equalTo(EID_2)));
|
||||
}
|
||||
|
@ -565,7 +569,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
patient3 = createPatientAndUpdateLinks(patient3);
|
||||
|
||||
//Now, Patient 2 and 3 are linked, and the person has 2 eids.
|
||||
assertThat(patient2, is(samePersonAs(patient3)));
|
||||
assertThat(patient2, is(sameSourceResourceAs(patient3)));
|
||||
assertNoDuplicates();
|
||||
// Person A -> {P1}
|
||||
// Person B -> {P2, P3}
|
||||
|
@ -578,11 +582,35 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
|
|||
// Person B -> {P3}
|
||||
// Possible duplicates A<->B
|
||||
|
||||
assertThat(patient2, is(samePersonAs(patient1)));
|
||||
assertThat(patient2, is(sameSourceResourceAs(patient1)));
|
||||
|
||||
List<EmpiLink> possibleDuplicates = myEmpiLinkDaoSvc.getPossibleDuplicates();
|
||||
assertThat(possibleDuplicates, hasSize(1));
|
||||
assertThat(patient3, is(possibleDuplicateOf(patient1)));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatientUpdatesCauseCandidateSearchToContainExistingLinksAndNewFinds() {
|
||||
Date today = new Date();
|
||||
Patient jane = buildJaneWithBirthday(today);
|
||||
|
||||
jane.setActive(true);
|
||||
Patient janePatient = createPatientAndUpdateLinks(jane);
|
||||
Person janePerson = getPersonFromTarget(janePatient);
|
||||
|
||||
Patient paul = buildPaulPatient();
|
||||
paul.setActive(true);
|
||||
Patient paulPatient = createPatientAndUpdateLinks(paul);
|
||||
Person paulPerson = getPersonFromTarget(paulPatient);
|
||||
|
||||
paulPatient.setBirthDate(jane.getBirthDate());
|
||||
paulPatient.setName(jane.getName());
|
||||
|
||||
|
||||
myEmpiMatchLinkSvc.updateEmpiLinksForEmpiTarget(paulPatient, createContextForUpdate());
|
||||
assertThat(paulPerson.getBirthDate(), is(nullValue()));
|
||||
paulPerson = getPersonFromTarget(paulPatient);
|
||||
assertThat(paulPerson.getBirthDate(), is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
|
||||
Person mergedPerson = mergePersons();
|
||||
assertEquals(myToPerson.getIdElement(), mergedPerson.getIdElement());
|
||||
assertThat(mergedPerson, is(samePersonAs(mergedPerson)));
|
||||
assertThat(mergedPerson, is(sameSourceResourceAs(mergedPerson)));
|
||||
assertEquals(2, getAllPersons().size());
|
||||
assertEquals(1, getAllActivePersons().size());
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
|
||||
@Test
|
||||
public void mergeRemovesPossibleDuplicatesLink() {
|
||||
EmpiLink empiLink = myEmpiLinkDaoSvc.newEmpiLink().setPersonPid(myToPersonPid).setTargetPid(myFromPersonPid).setMatchResult(EmpiMatchResultEnum.POSSIBLE_DUPLICATE).setLinkSource(EmpiLinkSourceEnum.AUTO);
|
||||
EmpiLink empiLink = myEmpiLinkDaoSvc.newEmpiLink().setSourceResourcePid(myToPersonPid).setTargetPid(myFromPersonPid).setMatchResult(EmpiMatchResultEnum.POSSIBLE_DUPLICATE).setLinkSource(EmpiLinkSourceEnum.AUTO);
|
||||
saveLink(empiLink);
|
||||
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue