Begin refactor of provider tests

This commit is contained in:
Tadgh 2020-11-09 16:14:02 -05:00
parent 06446ae0bf
commit 9e82602be9
10 changed files with 221 additions and 224 deletions

View File

@ -217,7 +217,7 @@ public class EmpiLinkDaoSvc {
*
* @return A list of all {@link EmpiLink} entities in which thePersonResource is the source Person.
*/
public List<EmpiLink> findEmpiLinksByPerson(IBaseResource thePersonResource) {
public List<EmpiLink> findEmpiLinksBySourceResource(IBaseResource thePersonResource) {
Long pid = myIdHelperService.getPidOrNull(thePersonResource);
if (pid == null) {
return Collections.emptyList();

View File

@ -107,7 +107,7 @@ public class EmpiLinkSvcImpl implements IEmpiLinkSvc {
public void syncEmpiLinksToPersonLinks(IAnyResource thePersonResource, EmpiTransactionContext theEmpiTransactionContext) {
int origLinkCount = myPersonHelper.getLinkCount(thePersonResource);
List<EmpiLink> empiLinks = myEmpiLinkDaoSvc.findEmpiLinksByPerson(thePersonResource);
List<EmpiLink> empiLinks = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(thePersonResource);
List<IBaseBackboneElement> newLinks = empiLinks.stream()
.filter(link -> link.isMatch() || link.isPossibleMatch() || link.isRedirect())

View File

@ -89,8 +89,8 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
}
private void mergeLinks(IAnyResource theFromPerson, IAnyResource theToPerson, Long theToPersonPid, EmpiTransactionContext theEmpiTransactionContext) {
List<EmpiLink> fromLinks = myEmpiLinkDaoSvc.findEmpiLinksByPerson(theFromPerson);
List<EmpiLink> toLinks = myEmpiLinkDaoSvc.findEmpiLinksByPerson(theToPerson);
List<EmpiLink> fromLinks = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theFromPerson);
List<EmpiLink> toLinks = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theToPerson);
// For each incomingLink, either ignore it, move it, or replace the original one

View File

@ -132,12 +132,12 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
}
@Nonnull
protected Person createUnmanagedPerson() {
return createSourceResourcePatient(new Person(), false);
protected Patient createUnmanagedSourceResource() {
return createSourceResourcePatient(new Patient(), false);
}
@Nonnull
protected Person createSourceResourcePatient() {
protected Patient createSourceResourcePatient() {
return createSourceResourcePatient(new Patient(), true);
}
@ -147,20 +147,20 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
}
@Nonnull
protected Person createSourceResourcePatient(Person thePerson) {
return createSourceResourcePatient(thePerson, true);
protected Patient createSourceResourcePatient(Patient theSourceResourcePatient) {
return createSourceResourcePatient(theSourceResourcePatient, true);
}
@Nonnull
protected Person createSourceResourcePatient(Patient theSourceResourcePatient, boolean theEmpiManaged) {
protected Patient createSourceResourcePatient(Patient theSourceResourcePatient, boolean theEmpiManaged) {
if (theEmpiManaged) {
theSourceResourcePatient.getMeta().addTag().setSystem(EmpiConstants.SYSTEM_EMPI_MANAGED).setCode(EmpiConstants.CODE_HAPI_EMPI_MANAGED);
theSourceResourcePatient.setActive(true);
}
DaoMethodOutcome outcome = myPatientDao.create(theSourceResourcePatient);
Person person = (Person) outcome.getResource();
person.setId(outcome.getId());
return person;
Patient patient = (Patient) outcome.getResource();
patient.setId(outcome.getId());
return patient;
}
@Nonnull
@ -194,8 +194,8 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
}
@Nonnull
protected Person buildPersonWithNameAndId(String theGivenName, String theId) {
return buildPersonWithNameIdAndBirthday(theGivenName, theId, null);
protected Patient buildSourcePaitentWithNameAndId(String theGivenName, String theId) {
return buildSourcePatientWithNameIdAndBirthday(theGivenName, theId, null);
}
@ -228,16 +228,16 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
}
@Nonnull
protected Person buildPersonWithNameIdAndBirthday(String theGivenName, String theId, Date theBirthday) {
Person person = new Person();
person.addName().addGiven(theGivenName);
person.addName().setFamily(TEST_NAME_FAMILY);
person.addIdentifier().setSystem(TEST_ID_SYSTEM).setValue(theId);
person.setBirthDate(theBirthday);
protected Patient buildSourcePatientWithNameIdAndBirthday(String theGivenName, String theId, Date theBirthday) {
Patient patient = new Patient();
patient.addName().addGiven(theGivenName);
patient.addName().setFamily(TEST_NAME_FAMILY);
patient.addIdentifier().setSystem(TEST_ID_SYSTEM).setValue(theId);
patient.setBirthDate(theBirthday);
DateType dateType = new DateType(theBirthday);
dateType.setPrecision(TemporalPrecisionEnum.DAY);
person.setBirthDateElement(dateType);
return person;
patient.setBirthDateElement(dateType);
return patient;
}
@Nonnull
@ -251,8 +251,8 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
}
@Nonnull
protected Person buildJanePerson() {
return buildPersonWithNameAndId(NAME_GIVEN_JANE, JANE_ID);
protected Patient buildJaneSourcePatient() {
return buildSourcePaitentWithNameAndId(NAME_GIVEN_JANE, JANE_ID);
}
@Nonnull
@ -297,11 +297,6 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
return thePatient;
}
protected Person addExternalEID(Person thePerson, String theEID) {
thePerson.addIdentifier().setSystem(myEmpiConfig.getEmpiRules().getEnterpriseEIDSystem()).setValue(theEID);
return thePerson;
}
protected Patient clearExternalEIDs(Patient thePatient) {
thePatient.getIdentifier().removeIf(theIdentifier -> theIdentifier.getSystem().equalsIgnoreCase(myEmpiConfig.getEmpiRules().getEnterpriseEIDSystem()));
return thePatient;
@ -368,41 +363,43 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
}
protected Person getOnlyActivePerson() {
List<IBaseResource> resources = getAllActivePersons();
List<IBaseResource> resources = getAllActiveSourcePatients();
assertEquals(1, resources.size());
return (Person) resources.get(0);
}
@Nonnull
protected List<IBaseResource> getAllActivePersons() {
return getAllPersons(true);
protected List<IBaseResource> getAllActiveSourcePatients() {
return getAllSourcePatients(true);
}
@Nonnull
protected List<IBaseResource> getAllPersons() {
return getAllPersons(false);
protected List<IBaseResource> getAllSourcePatients() {
return getAllSourcePatients(false);
}
@Nonnull
private List<IBaseResource> getAllPersons(boolean theOnlyActive) {
private List<IBaseResource> getAllSourcePatients(boolean theOnlyActive) {
SearchParameterMap map = new SearchParameterMap();
map.setLoadSynchronous(true);
//TODO GGG ensure that this tag search works effectively.
map.add("_tag", new TokenParam(EmpiConstants.SYSTEM_EMPI_MANAGED, EmpiConstants.CODE_HAPI_EMPI_MANAGED));
if (theOnlyActive) {
map.add("active", new TokenParam().setValue("true"));
}
IBundleProvider bundle = myPersonDao.search(map);
IBundleProvider bundle = myPatientDao.search(map);
return bundle.getResources(0, 999);
}
@Nonnull
protected EmpiLink createResourcesAndBuildTestEmpiLink() {
Person person = createSourceResourcePatient();
Patient sourcePatient = createSourceResourcePatient();
Patient patient = createPatient();
EmpiLink empiLink = myEmpiLinkDaoSvc.newEmpiLink();
empiLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
empiLink.setMatchResult(EmpiMatchResultEnum.MATCH);
empiLink.setSourceResourcePid(myIdHelperService.getPidOrNull(person));
empiLink.setSourceResourcePid(myIdHelperService.getPidOrNull(sourcePatient));
empiLink.setTargetPid(myIdHelperService.getPidOrNull(patient));
return empiLink;
}

View File

@ -5,6 +5,7 @@ import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.util.AssuranceLevelUtil;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Person;
import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.BeforeEach;
@ -21,10 +22,10 @@ import static org.junit.jupiter.api.Assertions.fail;
public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test {
private Person myFromPerson;
private StringType myFromPersonId;
private Person myToPerson;
private StringType myToPersonId;
private Patient myFromSourcePatient;
private StringType myFromSourcePatientId;
private Patient myToSourcePatient;
private StringType myToSourcePatientId;
@Override
@BeforeEach
@ -32,32 +33,32 @@ public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test {
super.before();
super.loadEmpiSearchParameters();
myFromPerson = createSourceResourcePatient();
myFromPersonId = new StringType(myFromPerson.getIdElement().getValue());
myToPerson = createSourceResourcePatient();
myToPersonId = new StringType(myToPerson.getIdElement().getValue());
myFromSourcePatient = createSourceResourcePatient();
myFromSourcePatientId = new StringType(myFromSourcePatient.getIdElement().getValue());
myToSourcePatient = createSourceResourcePatient();
myToSourcePatientId = new StringType(myToSourcePatient.getIdElement().getValue());
}
@Test
public void testMerge() {
Person mergedPerson = myEmpiProviderR4.mergePersons(myFromPersonId, myToPersonId, myRequestDetails);
assertEquals(myToPerson.getIdElement(), mergedPerson.getIdElement());
assertThat(mergedPerson, is(sameSourceResourceAs(myToPerson)));
assertEquals(2, getAllPersons().size());
assertEquals(1, getAllActivePersons().size());
Person mergedPerson = myEmpiProviderR4.mergePersons(myFromSourcePatientId, myToSourcePatientId, myRequestDetails);
assertEquals(myToSourcePatient.getIdElement(), mergedPerson.getIdElement());
assertThat(mergedPerson, is(sameSourceResourceAs(myToSourcePatient)));
assertEquals(2, getAllSourcePatients().size());
assertEquals(1, getAllActiveSourcePatients().size());
Person fromPerson = myPersonDao.read(myFromPerson.getIdElement().toUnqualifiedVersionless());
Person fromPerson = myPersonDao.read(myFromSourcePatient.getIdElement().toUnqualifiedVersionless());
assertThat(fromPerson.getActive(), is(false));
List<Person.PersonLinkComponent> links = fromPerson.getLink();
assertThat(links, hasSize(1));
assertThat(links.get(0).getTarget().getReference(), is (myToPerson.getIdElement().toUnqualifiedVersionless().getValue()));
assertThat(links.get(0).getTarget().getReference(), is (myToSourcePatient.getIdElement().toUnqualifiedVersionless().getValue()));
assertThat(links.get(0).getAssurance(), is (AssuranceLevelUtil.getAssuranceLevel(EmpiMatchResultEnum.REDIRECT, EmpiLinkSourceEnum.MANUAL).toR4()));
}
@Test
public void testUnmanagedMerge() {
StringType fromPersonId = new StringType(createUnmanagedPerson().getIdElement().getValue());
StringType toPersonId = new StringType(createUnmanagedPerson().getIdElement().getValue());
StringType fromPersonId = new StringType(createUnmanagedSourceResource().getIdElement().getValue());
StringType toPersonId = new StringType(createUnmanagedSourceResource().getIdElement().getValue());
try {
myEmpiProviderR4.mergePersons(fromPersonId, toPersonId, myRequestDetails);
fail();
@ -88,13 +89,13 @@ public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test {
assertEquals("fromPersonId cannot be null", e.getMessage());
}
try {
myEmpiProviderR4.mergePersons(null, myToPersonId, myRequestDetails);
myEmpiProviderR4.mergePersons(null, myToSourcePatientId, myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertEquals("fromPersonId cannot be null", e.getMessage());
}
try {
myEmpiProviderR4.mergePersons(myFromPersonId, null, myRequestDetails);
myEmpiProviderR4.mergePersons(myFromSourcePatientId, null, myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertEquals("toPersonId cannot be null", e.getMessage());
@ -110,7 +111,7 @@ public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test {
assertThat(e.getMessage(), endsWith(" must have form Person/<id> where <id> is the id of the person"));
}
try {
myEmpiProviderR4.mergePersons(myFromPersonId, new StringType("Patient/2"), myRequestDetails);
myEmpiProviderR4.mergePersons(myFromSourcePatientId, new StringType("Patient/2"), myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), endsWith(" must have form Person/<id> where <id> is the id of the person"));
@ -122,13 +123,13 @@ public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test {
assertEquals("fromPersonId must be different from toPersonId", e.getMessage());
}
try {
myEmpiProviderR4.mergePersons(new StringType("Person/abc"), myToPersonId, myRequestDetails);
myEmpiProviderR4.mergePersons(new StringType("Person/abc"), myToSourcePatientId, myRequestDetails);
fail();
} catch (ResourceNotFoundException e) {
assertEquals("Resource Person/abc is not known", e.getMessage());
}
try {
myEmpiProviderR4.mergePersons(myFromPersonId, new StringType("Person/abc"), myRequestDetails);
myEmpiProviderR4.mergePersons(myFromSourcePatientId, new StringType("Person/abc"), myRequestDetails);
fail();
} catch (ResourceNotFoundException e) {
assertEquals("Resource Person/abc is not known", e.getMessage());

View File

@ -11,7 +11,6 @@ import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Person;
import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -43,14 +42,14 @@ public class EmpiProviderQueryLinkR4Test extends BaseLinkR4Test {
// Add a possible duplicate
myLinkSource = new StringType(EmpiLinkSourceEnum.AUTO.name());
Person person1 = createSourceResourcePatient();
myPerson1Id = new StringType(person1.getIdElement().toVersionless().getValue());
Long person1Pid = myIdHelperService.getPidOrNull(person1);
Person person2 = createSourceResourcePatient();
myPerson2Id = new StringType(person2.getIdElement().toVersionless().getValue());
Long person2Pid = myIdHelperService.getPidOrNull(person2);
Patient sourcePatient1 = createSourceResourcePatient();
myPerson1Id = new StringType(sourcePatient1.getIdElement().toVersionless().getValue());
Long sourcePatient1Pid = myIdHelperService.getPidOrNull(sourcePatient1);
Patient sourcePatient2 = createSourceResourcePatient();
myPerson2Id = new StringType(sourcePatient2.getIdElement().toVersionless().getValue());
Long sourcePatient2Pid = myIdHelperService.getPidOrNull(sourcePatient2);
EmpiLink possibleDuplicateEmpiLink = myEmpiLinkDaoSvc.newEmpiLink().setSourceResourcePid(person1Pid).setTargetPid(person2Pid).setMatchResult(EmpiMatchResultEnum.POSSIBLE_DUPLICATE).setLinkSource(EmpiLinkSourceEnum.AUTO);
EmpiLink possibleDuplicateEmpiLink = myEmpiLinkDaoSvc.newEmpiLink().setSourceResourcePid(sourcePatient1Pid).setTargetPid(sourcePatient2Pid).setMatchResult(EmpiMatchResultEnum.POSSIBLE_DUPLICATE).setLinkSource(EmpiLinkSourceEnum.AUTO);
saveLink(possibleDuplicateEmpiLink);
}

View File

@ -118,12 +118,12 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
@Test
public void testUpdateStrangePerson() {
Person person = createUnmanagedPerson();
Patient person = createUnmanagedSourceResource();
try {
myEmpiProviderR4.updateLink(new StringType(person.getIdElement().getValue()), myPatientId, NO_MATCH_RESULT, myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertEquals("Only EMPI Managed Person resources may be updated via this operation. The Person resource provided is not tagged as managed by hapi-empi", e.getMessage());
assertEquals("Only EMPI Managed Person resources may be updated via this operation. The Source Resource provided is not tagged as managed by hapi-empi", e.getMessage());
}
}

View File

@ -47,20 +47,20 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test {
@Test
public void testCreateRemoveLink() {
assertLinkCount(0);
Person person = createSourceResourcePatient();
IdType personId = person.getIdElement().toUnqualifiedVersionless();
assertEquals(0, person.getLink().size());
Patient sourcePatient = createSourceResourcePatient();
IdType personId = sourcePatient.getIdElement().toUnqualifiedVersionless();
assertEquals(0, sourcePatient.getLink().size());
Patient patient = createPatient();
{
myEmpiLinkSvc.updateLink(person, patient, POSSIBLE_MATCH, EmpiLinkSourceEnum.AUTO, createContextForCreate("Patient"));
myEmpiLinkSvc.updateLink(sourcePatient, patient, POSSIBLE_MATCH, EmpiLinkSourceEnum.AUTO, createContextForCreate("Patient"));
assertLinkCount(1);
Person newPerson = myPersonDao.read(personId);
assertEquals(1, newPerson.getLink().size());
}
{
myEmpiLinkSvc.updateLink(person, patient, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
myEmpiLinkSvc.updateLink(sourcePatient, patient, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
assertLinkCount(1);
Person newPerson = myPersonDao.read(personId);
assertEquals(0, newPerson.getLink().size());
@ -71,46 +71,46 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test {
@Test
public void testPossibleDuplicate() {
assertLinkCount(0);
Person person = createSourceResourcePatient();
Person target = createSourceResourcePatient();
Patient sourcePatient1 = createSourceResourcePatient();
Patient sourcePatient2 = createSourceResourcePatient();
// TODO NOT VALID
myEmpiLinkSvc.updateLink(person, target, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, createContextForCreate("Person"));
myEmpiLinkSvc.updateLink(sourcePatient1, sourcePatient2, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, createContextForCreate("Patient"));
assertLinkCount(1);
}
@Test
public void testNoMatchBlocksPossibleDuplicate() {
assertLinkCount(0);
Person person = createSourceResourcePatient();
Person target = createSourceResourcePatient();
Patient sourcePatient1 = createSourceResourcePatient();
Patient sourcePatient2 = createSourceResourcePatient();
Long personPid = myIdHelperService.getPidOrNull(person);
Long targetPid = myIdHelperService.getPidOrNull(target);
assertFalse(myEmpiLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(personPid, targetPid).isPresent());
assertFalse(myEmpiLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(targetPid, personPid).isPresent());
Long sourcePatient1Pid = myIdHelperService.getPidOrNull(sourcePatient1);
Long sourcePatient2Pid = myIdHelperService.getPidOrNull(sourcePatient2);
assertFalse(myEmpiLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(sourcePatient1Pid, sourcePatient2Pid).isPresent());
assertFalse(myEmpiLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(sourcePatient2Pid, sourcePatient1Pid).isPresent());
saveNoMatchLink(personPid, targetPid);
saveNoMatchLink(sourcePatient1Pid, sourcePatient2Pid);
myEmpiLinkSvc.updateLink(person, target, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, createContextForCreate("Person"));
assertFalse(myEmpiLinkDaoSvc.getEmpiLinksByPersonPidTargetPidAndMatchResult(personPid, targetPid, EmpiMatchResultEnum.POSSIBLE_DUPLICATE).isPresent());
myEmpiLinkSvc.updateLink(sourcePatient1, sourcePatient2, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, createContextForCreate("Person"));
assertFalse(myEmpiLinkDaoSvc.getEmpiLinksByPersonPidTargetPidAndMatchResult(sourcePatient1Pid, sourcePatient2Pid, EmpiMatchResultEnum.POSSIBLE_DUPLICATE).isPresent());
assertLinkCount(1);
}
@Test
public void testNoMatchBlocksPossibleDuplicateReversed() {
assertLinkCount(0);
Person person = createSourceResourcePatient();
Person target = createSourceResourcePatient();
Patient sourcePatient1 = createSourceResourcePatient();
Patient sourcePatient2 = createSourceResourcePatient();
Long personPid = myIdHelperService.getPidOrNull(person);
Long targetPid = myIdHelperService.getPidOrNull(target);
assertFalse(myEmpiLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(personPid, targetPid).isPresent());
assertFalse(myEmpiLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(targetPid, personPid).isPresent());
Long sourcePatient1Pid = myIdHelperService.getPidOrNull(sourcePatient1);
Long sourcePatient2Pid = myIdHelperService.getPidOrNull(sourcePatient2);
assertFalse(myEmpiLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(sourcePatient1Pid, sourcePatient2Pid).isPresent());
assertFalse(myEmpiLinkDaoSvc.getLinkBySourceResourcePidAndTargetResourcePid(sourcePatient2Pid, sourcePatient1Pid).isPresent());
saveNoMatchLink(targetPid, personPid);
saveNoMatchLink(sourcePatient2Pid, sourcePatient1Pid);
myEmpiLinkSvc.updateLink(person, target, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, createContextForCreate("Person"));
assertFalse(myEmpiLinkDaoSvc.getEmpiLinksByPersonPidTargetPidAndMatchResult(personPid, targetPid, EmpiMatchResultEnum.POSSIBLE_DUPLICATE).isPresent());
myEmpiLinkSvc.updateLink(sourcePatient1, sourcePatient2, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, createContextForCreate("Person"));
assertFalse(myEmpiLinkDaoSvc.getEmpiLinksByPersonPidTargetPidAndMatchResult(sourcePatient1Pid, sourcePatient2Pid, EmpiMatchResultEnum.POSSIBLE_DUPLICATE).isPresent());
assertLinkCount(1);
}
@ -125,12 +125,12 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test {
@Test
public void testManualEmpiLinksCannotBeModifiedBySystem() {
Person person = createSourceResourcePatient(buildJanePerson());
Patient sourcePatient = createSourceResourcePatient(buildJaneSourcePatient());
Patient patient = createPatient(buildJanePatient());
myEmpiLinkSvc.updateLink(person, patient, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
myEmpiLinkSvc.updateLink(sourcePatient, patient, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
try {
myEmpiLinkSvc.updateLink(person, patient, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, null);
myEmpiLinkSvc.updateLink(sourcePatient, patient, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, null);
fail();
} catch (InternalErrorException e) {
assertThat(e.getMessage(), is(equalTo("EMPI system is not allowed to modify links on manually created links")));
@ -139,12 +139,12 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test {
@Test
public void testAutomaticallyAddedNO_MATCHEmpiLinksAreNotAllowed() {
Person person = createSourceResourcePatient(buildJanePerson());
Patient sourcePatient = createSourceResourcePatient(buildJaneSourcePatient());
Patient patient = createPatient(buildJanePatient());
// Test: it should be impossible to have a AUTO NO_MATCH record. The only NO_MATCH records in the system must be MANUAL.
try {
myEmpiLinkSvc.updateLink(person, patient, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.AUTO, null);
myEmpiLinkSvc.updateLink(sourcePatient, patient, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.AUTO, null);
fail();
} catch (InternalErrorException e) {
assertThat(e.getMessage(), is(equalTo("EMPI system is not allowed to automatically NO_MATCH a resource")));
@ -153,15 +153,16 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test {
@Test
public void testSyncDoesNotSyncNoMatchLinks() {
Person person = createSourceResourcePatient(buildJanePerson());
Patient sourcePatient = createSourceResourcePatient(buildJaneSourcePatient());
Patient patient1 = createPatient(buildJanePatient());
Patient patient2 = createPatient(buildJanePatient());
assertEquals(0, myEmpiLinkDao.count());
myEmpiLinkDaoSvc.createOrUpdateLinkEntity(person, patient1, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
myEmpiLinkDaoSvc.createOrUpdateLinkEntity(person, patient2, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
myEmpiLinkSvc.syncEmpiLinksToPersonLinks(person, createContextForCreate("Patient"));
assertTrue(person.hasLink());
assertEquals(patient1.getIdElement().toVersionless().getValue(), person.getLinkFirstRep().getTarget().getReference());
myEmpiLinkDaoSvc.createOrUpdateLinkEntity(sourcePatient, patient1, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
myEmpiLinkDaoSvc.createOrUpdateLinkEntity(sourcePatient, patient2, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
myEmpiLinkSvc.syncEmpiLinksToPersonLinks(sourcePatient, createContextForCreate("Patient"));
assertTrue(sourcePatient.hasLink());
//TODO GGG update this test once we decide what has to happen here. There is no more "syncing links"
//assertEquals(patient1.getIdElement().toVersionless().getValue(), sourcePatient.getLinkFirstRep().getTarget().getReference());
}
}

View File

@ -19,7 +19,6 @@ import org.hl7.fhir.r4.model.HumanName;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Person;
import org.hl7.fhir.r4.model.Reference;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -54,10 +53,10 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
@Autowired
IInterceptorService myInterceptorService;
private Person myFromPerson;
private Person myToPerson;
private Long myFromPersonPid;
private Long myToPersonPid;
private Patient myFromSourcePatient;
private Patient myToSourcePatient;
private Long myFromSourcePatientPid;
private Long myToSourcePatientPid;
private Patient myTargetPatient1;
private Patient myTargetPatient2;
private Patient myTargetPatient3;
@ -66,12 +65,12 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
public void before() {
super.loadEmpiSearchParameters();
myFromPerson = createSourceResourcePatient();
IdType fromPersonId = myFromPerson.getIdElement().toUnqualifiedVersionless();
myFromPersonPid = myIdHelperService.getPidOrThrowException(fromPersonId);
myToPerson = createSourceResourcePatient();
IdType toPersonId = myToPerson.getIdElement().toUnqualifiedVersionless();
myToPersonPid = myIdHelperService.getPidOrThrowException(toPersonId);
myFromSourcePatient = createSourceResourcePatient();
IdType fromSourcePatientId = myFromSourcePatient.getIdElement().toUnqualifiedVersionless();
myFromSourcePatientPid = myIdHelperService.getPidOrThrowException(fromSourcePatientId);
myToSourcePatient = createSourceResourcePatient();
IdType toSourcePatientId = myToSourcePatient.getIdElement().toUnqualifiedVersionless();
myToSourcePatientPid = myIdHelperService.getPidOrThrowException(toSourcePatientId);
myTargetPatient1 = createPatient();
@ -92,19 +91,19 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
@Test
public void emptyMerge() {
assertEquals(2, getAllPersons().size());
assertEquals(2, getAllActivePersons().size());
assertEquals(2, getAllSourcePatients().size());
assertEquals(2, getAllActiveSourcePatients().size());
Person mergedPerson = mergePersons();
assertEquals(myToPerson.getIdElement(), mergedPerson.getIdElement());
assertEquals(myToSourcePatient.getIdElement(), mergedPerson.getIdElement());
assertThat(mergedPerson, is(sameSourceResourceAs(mergedPerson)));
assertEquals(2, getAllPersons().size());
assertEquals(1, getAllActivePersons().size());
assertEquals(2, getAllSourcePatients().size());
assertEquals(1, getAllActiveSourcePatients().size());
}
private Person mergePersons() {
assertEquals(0, redirectLinkCount());
Person retval = (Person) myEmpiPersonMergerSvc.mergePersons(myFromPerson, myToPerson, createEmpiContext());
Person retval = (Person) myEmpiPersonMergerSvc.mergePersons(myFromSourcePatient, myToSourcePatient, createEmpiContext());
assertEquals(1, redirectLinkCount());
return retval;
}
@ -121,7 +120,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
@Test
public void mergeRemovesPossibleDuplicatesLink() {
EmpiLink empiLink = myEmpiLinkDaoSvc.newEmpiLink().setSourceResourcePid(myToPersonPid).setTargetPid(myFromPersonPid).setMatchResult(EmpiMatchResultEnum.POSSIBLE_DUPLICATE).setLinkSource(EmpiLinkSourceEnum.AUTO);
EmpiLink empiLink = myEmpiLinkDaoSvc.newEmpiLink().setSourceResourcePid(myToSourcePatientPid).setTargetPid(myFromSourcePatientPid).setMatchResult(EmpiMatchResultEnum.POSSIBLE_DUPLICATE).setLinkSource(EmpiLinkSourceEnum.AUTO);
saveLink(empiLink);
{
@ -141,7 +140,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
@Test
public void fullFromEmptyTo() {
populatePerson(myFromPerson);
populatePerson(myFromSourcePatient);
Person mergedPerson = mergePersons();
HumanName returnedName = mergedPerson.getNameFirstRep();
@ -152,8 +151,8 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
@Test
public void emptyFromFullTo() {
myFromPerson.getName().add(new HumanName().addGiven(BAD_GIVEN_NAME));
populatePerson(myToPerson);
myFromSourcePatient.getName().add(new HumanName().addGiven(BAD_GIVEN_NAME));
populatePerson(myToSourcePatient);
Person mergedPerson = mergePersons();
HumanName returnedName = mergedPerson.getNameFirstRep();
@ -164,86 +163,86 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
@Test
public void fromLinkToNoLink() {
createEmpiLink(myFromPerson, myTargetPatient1);
createEmpiLink(myFromSourcePatient, myTargetPatient1);
Person mergedPerson = mergePersons();
List<EmpiLink> links = getNonRedirectLinksByPerson(mergedPerson);
assertEquals(1, links.size());
assertThat(mergedPerson, is(possibleLinkedTo(myTargetPatient1)));
assertEquals(1, myToPerson.getLink().size());
assertEquals(1, myToSourcePatient.getLink().size());
}
@Test
public void fromNoLinkToLink() {
createEmpiLink(myToPerson, myTargetPatient1);
createEmpiLink(myToSourcePatient, myTargetPatient1);
Person mergedPerson = mergePersons();
List<EmpiLink> links = getNonRedirectLinksByPerson(mergedPerson);
assertEquals(1, links.size());
assertThat(mergedPerson, is(possibleLinkedTo(myTargetPatient1)));
assertEquals(1, myToPerson.getLink().size());
assertEquals(1, myToSourcePatient.getLink().size());
}
@Test
public void fromManualLinkOverridesAutoToLink() {
EmpiLink fromLink = createEmpiLink(myFromPerson, myTargetPatient1);
EmpiLink fromLink = createEmpiLink(myFromSourcePatient, myTargetPatient1);
fromLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
fromLink.setMatchResult(EmpiMatchResultEnum.MATCH);
saveLink(fromLink);
createEmpiLink(myToPerson, myTargetPatient1);
createEmpiLink(myToSourcePatient, myTargetPatient1);
mergePersons();
List<EmpiLink> links = getNonRedirectLinksByPerson(myToPerson);
List<EmpiLink> links = getNonRedirectLinksByPerson(myToSourcePatient);
assertEquals(1, links.size());
assertEquals(EmpiLinkSourceEnum.MANUAL, links.get(0).getLinkSource());
}
private List<EmpiLink> getNonRedirectLinksByPerson(Person thePerson) {
return myEmpiLinkDaoSvc.findEmpiLinksByPerson(thePerson).stream()
private List<EmpiLink> getNonRedirectLinksByPerson(Patient theSourcePatient) {
return myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theSourcePatient).stream()
.filter(link -> !link.isRedirect())
.collect(Collectors.toList());
}
@Test
public void fromManualNoMatchLinkOverridesAutoToLink() {
EmpiLink fromLink = createEmpiLink(myFromPerson, myTargetPatient1);
EmpiLink fromLink = createEmpiLink(myFromSourcePatient, myTargetPatient1);
fromLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
fromLink.setMatchResult(EmpiMatchResultEnum.NO_MATCH);
saveLink(fromLink);
createEmpiLink(myToPerson, myTargetPatient1);
createEmpiLink(myToSourcePatient, myTargetPatient1);
mergePersons();
List<EmpiLink> links = getNonRedirectLinksByPerson(myToPerson);
List<EmpiLink> links = getNonRedirectLinksByPerson(myToSourcePatient);
assertEquals(1, links.size());
assertEquals(EmpiLinkSourceEnum.MANUAL, links.get(0).getLinkSource());
}
@Test
public void fromManualAutoMatchLinkNoOverridesManualToLink() {
createEmpiLink(myFromPerson, myTargetPatient1);
createEmpiLink(myFromSourcePatient, myTargetPatient1);
EmpiLink toLink = createEmpiLink(myToPerson, myTargetPatient1);
EmpiLink toLink = createEmpiLink(myToSourcePatient, myTargetPatient1);
toLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
toLink.setMatchResult(EmpiMatchResultEnum.NO_MATCH);
saveLink(toLink);
mergePersons();
List<EmpiLink> links = getNonRedirectLinksByPerson(myToPerson);
List<EmpiLink> links = getNonRedirectLinksByPerson(myToSourcePatient);
assertEquals(1, links.size());
assertEquals(EmpiLinkSourceEnum.MANUAL, links.get(0).getLinkSource());
}
@Test
public void fromNoMatchMergeToManualMatchIsError() {
EmpiLink fromLink = createEmpiLink(myFromPerson, myTargetPatient1);
EmpiLink fromLink = createEmpiLink(myFromSourcePatient, myTargetPatient1);
fromLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
fromLink.setMatchResult(EmpiMatchResultEnum.NO_MATCH);
saveLink(fromLink);
EmpiLink toLink = createEmpiLink(myToPerson, myTargetPatient1);
EmpiLink toLink = createEmpiLink(myToSourcePatient, myTargetPatient1);
toLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
toLink.setMatchResult(EmpiMatchResultEnum.MATCH);
saveLink(toLink);
@ -258,12 +257,12 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
@Test
public void fromMatchMergeToManualNoMatchIsError() {
EmpiLink fromLink = createEmpiLink(myFromPerson, myTargetPatient1);
EmpiLink fromLink = createEmpiLink(myFromSourcePatient, myTargetPatient1);
fromLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
fromLink.setMatchResult(EmpiMatchResultEnum.MATCH);
saveLink(fromLink);
EmpiLink toLink = createEmpiLink(myToPerson, myTargetPatient1);
EmpiLink toLink = createEmpiLink(myToSourcePatient, myTargetPatient1);
toLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
toLink.setMatchResult(EmpiMatchResultEnum.NO_MATCH);
saveLink(toLink);
@ -278,90 +277,90 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
@Test
public void fromNoMatchMergeToManualMatchDifferentPatientIsOk() {
EmpiLink fromLink = createEmpiLink(myFromPerson, myTargetPatient1);
EmpiLink fromLink = createEmpiLink(myFromSourcePatient, myTargetPatient1);
fromLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
fromLink.setMatchResult(EmpiMatchResultEnum.NO_MATCH);
saveLink(fromLink);
EmpiLink toLink = createEmpiLink(myToPerson, myTargetPatient2);
EmpiLink toLink = createEmpiLink(myToSourcePatient, myTargetPatient2);
toLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
toLink.setMatchResult(EmpiMatchResultEnum.MATCH);
saveLink(toLink);
mergePersons();
assertEquals(1, myToPerson.getLink().size());
assertEquals(1, myToSourcePatient.getLink().size());
assertEquals(3, myEmpiLinkDao.count());
}
@Test
public void from123To1() {
createEmpiLink(myFromPerson, myTargetPatient1);
createEmpiLink(myFromPerson, myTargetPatient2);
createEmpiLink(myFromPerson, myTargetPatient3);
createEmpiLink(myToPerson, myTargetPatient1);
createEmpiLink(myFromSourcePatient, myTargetPatient1);
createEmpiLink(myFromSourcePatient, myTargetPatient2);
createEmpiLink(myFromSourcePatient, myTargetPatient3);
createEmpiLink(myToSourcePatient, myTargetPatient1);
mergePersons();
myEmpiLinkHelper.logEmpiLinks();
assertThat(myToPerson, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
assertEquals(3, myToPerson.getLink().size());
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
assertEquals(3, myToSourcePatient.getLink().size());
}
@Test
public void from1To123() {
createEmpiLink(myFromPerson, myTargetPatient1);
createEmpiLink(myToPerson, myTargetPatient1);
createEmpiLink(myToPerson, myTargetPatient2);
createEmpiLink(myToPerson, myTargetPatient3);
createEmpiLink(myFromSourcePatient, myTargetPatient1);
createEmpiLink(myToSourcePatient, myTargetPatient1);
createEmpiLink(myToSourcePatient, myTargetPatient2);
createEmpiLink(myToSourcePatient, myTargetPatient3);
mergePersons();
myEmpiLinkHelper.logEmpiLinks();
assertThat(myToPerson, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
assertEquals(3, myToPerson.getLink().size());
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
assertEquals(3, myToSourcePatient.getLink().size());
}
@Test
public void from123To123() {
createEmpiLink(myFromPerson, myTargetPatient1);
createEmpiLink(myFromPerson, myTargetPatient2);
createEmpiLink(myFromPerson, myTargetPatient3);
createEmpiLink(myToPerson, myTargetPatient1);
createEmpiLink(myToPerson, myTargetPatient2);
createEmpiLink(myToPerson, myTargetPatient3);
createEmpiLink(myFromSourcePatient, myTargetPatient1);
createEmpiLink(myFromSourcePatient, myTargetPatient2);
createEmpiLink(myFromSourcePatient, myTargetPatient3);
createEmpiLink(myToSourcePatient, myTargetPatient1);
createEmpiLink(myToSourcePatient, myTargetPatient2);
createEmpiLink(myToSourcePatient, myTargetPatient3);
mergePersons();
myEmpiLinkHelper.logEmpiLinks();
assertThat(myToPerson, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
assertEquals(3, myToPerson.getLink().size());
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
assertEquals(3, myToSourcePatient.getLink().size());
}
@Test
public void from12To23() {
createEmpiLink(myFromPerson, myTargetPatient1);
createEmpiLink(myFromPerson, myTargetPatient2);
createEmpiLink(myToPerson, myTargetPatient2);
createEmpiLink(myToPerson, myTargetPatient3);
createEmpiLink(myFromSourcePatient, myTargetPatient1);
createEmpiLink(myFromSourcePatient, myTargetPatient2);
createEmpiLink(myToSourcePatient, myTargetPatient2);
createEmpiLink(myToSourcePatient, myTargetPatient3);
mergePersons();
myEmpiLinkHelper.logEmpiLinks();
assertThat(myToPerson, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
assertEquals(3, myToPerson.getLink().size());
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
assertEquals(3, myToSourcePatient.getLink().size());
}
@Test
public void testMergeNames() {
myFromPerson.addName().addGiven("Jim");
myFromPerson.getNameFirstRep().addGiven("George");
assertThat(myFromPerson.getName(), hasSize(1));
assertThat(myFromPerson.getName().get(0).getGiven(), hasSize(2));
myFromSourcePatient.addName().addGiven("Jim");
myFromSourcePatient.getNameFirstRep().addGiven("George");
assertThat(myFromSourcePatient.getName(), hasSize(1));
assertThat(myFromSourcePatient.getName().get(0).getGiven(), hasSize(2));
myToPerson.addName().addGiven("Jeff");
myToPerson.getNameFirstRep().addGiven("George");
assertThat(myToPerson.getName(), hasSize(1));
assertThat(myToPerson.getName().get(0).getGiven(), hasSize(2));
myToSourcePatient.addName().addGiven("Jeff");
myToSourcePatient.getNameFirstRep().addGiven("George");
assertThat(myToSourcePatient.getName(), hasSize(1));
assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
Person mergedPerson = mergePersons();
assertThat(mergedPerson.getName(), hasSize(2));
@ -371,44 +370,45 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
@Test
public void testMergeNamesAllSame() {
myFromPerson.addName().addGiven("Jim");
myFromPerson.getNameFirstRep().addGiven("George");
assertThat(myFromPerson.getName(), hasSize(1));
assertThat(myFromPerson.getName().get(0).getGiven(), hasSize(2));
myFromSourcePatient.addName().addGiven("Jim");
myFromSourcePatient.getNameFirstRep().addGiven("George");
assertThat(myFromSourcePatient.getName(), hasSize(1));
assertThat(myFromSourcePatient.getName().get(0).getGiven(), hasSize(2));
myToPerson.addName().addGiven("Jim");
myToPerson.getNameFirstRep().addGiven("George");
assertThat(myToPerson.getName(), hasSize(1));
assertThat(myToPerson.getName().get(0).getGiven(), hasSize(2));
myToSourcePatient.addName().addGiven("Jim");
myToSourcePatient.getNameFirstRep().addGiven("George");
assertThat(myToSourcePatient.getName(), hasSize(1));
assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
mergePersons();
assertThat(myToPerson.getName(), hasSize(1));
assertThat(myToPerson.getName().get(0).getGiven(), hasSize(2));
assertThat(myToSourcePatient.getName(), hasSize(1));
assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
}
@Test
public void testMergeIdentities() {
myFromPerson.addIdentifier().setValue("aaa");
myFromPerson.addIdentifier().setValue("bbb");
assertThat(myFromPerson.getIdentifier(), hasSize(2));
myFromSourcePatient.addIdentifier().setValue("aaa");
myFromSourcePatient.addIdentifier().setValue("bbb");
assertThat(myFromSourcePatient.getIdentifier(), hasSize(2));
myToPerson.addIdentifier().setValue("aaa");
myToPerson.addIdentifier().setValue("ccc");
assertThat(myToPerson.getIdentifier(), hasSize(2));
myToSourcePatient.addIdentifier().setValue("aaa");
myToSourcePatient.addIdentifier().setValue("ccc");
assertThat(myToSourcePatient.getIdentifier(), hasSize(2));
mergePersons();
assertThat(myToPerson.getIdentifier(), hasSize(3));
assertThat(myToSourcePatient.getIdentifier(), hasSize(3));
}
private EmpiLink createEmpiLink(Person thePerson, Patient theTargetPatient) {
thePerson.addLink().setTarget(new Reference(theTargetPatient));
return myEmpiLinkDaoSvc.createOrUpdateLinkEntity(thePerson, theTargetPatient, POSSIBLE_MATCH, EmpiLinkSourceEnum.AUTO, createContextForCreate("Patient"));
private EmpiLink createEmpiLink(Patient theSourcePatient, Patient theTargetPatient) {
//TODO GGG Ensure theis comment can be safely removed
//theSourcePatient.addLink().setTarget(new Reference(theTargetPatient));
return myEmpiLinkDaoSvc.createOrUpdateLinkEntity(theSourcePatient, theTargetPatient, POSSIBLE_MATCH, EmpiLinkSourceEnum.AUTO, createContextForCreate("Patient"));
}
private void populatePerson(Person thePerson) {
thePerson.addName(new HumanName().addGiven(GIVEN_NAME).setFamily(FAMILY_NAME));
thePerson.setGender(Enumerations.AdministrativeGender.FEMALE);
thePerson.setBirthDateElement(new DateType("1981-01-01"));
private void populatePerson(Patient theSourcePatient) {
theSourcePatient.addName(new HumanName().addGiven(GIVEN_NAME).setFamily(FAMILY_NAME));
theSourcePatient.setGender(Enumerations.AdministrativeGender.FEMALE);
theSourcePatient.setBirthDateElement(new DateType("1981-01-01"));
Address address = new Address();
address.addLine("622 College St");
address.addLine("Suite 401");
@ -416,6 +416,6 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
address.setCity("Toronto");
address.setCountry("Canada");
address.setPostalCode(POSTAL_CODE);
thePerson.setAddress(Collections.singletonList(address));
theSourcePatient.setAddress(Collections.singletonList(address));
}
}

View File

@ -3,7 +3,6 @@ package ca.uhn.fhir.jpa.empi.svc;
import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Person;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@ -26,28 +25,28 @@ public class EmpiResourceDaoSvcTest extends BaseEmpiR4Test {
@Test
public void testSearchPersonByEidExcludesInactive() {
Person goodPerson = addExternalEID(createSourceResourcePatient(), TEST_EID);
myPersonDao.update(goodPerson);
Patient goodSourcePatient = addExternalEID(createSourceResourcePatient(), TEST_EID);
myPatientDao.update(goodSourcePatient);
Person badPerson = addExternalEID(createSourceResourcePatient(), TEST_EID);
badPerson.setActive(false);
myPersonDao.update(badPerson);
Patient badSourcePatient = addExternalEID(createSourceResourcePatient(), TEST_EID);
badSourcePatient.setActive(false);
myPatientDao.update(badSourcePatient);
Optional<IAnyResource> foundPerson = myResourceDaoSvc.searchSourceResourceByEID(TEST_EID, "Person");
assertTrue(foundPerson.isPresent());
assertThat(foundPerson.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodPerson.getIdElement().toUnqualifiedVersionless().getValue()));
assertThat(foundPerson.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodSourcePatient.getIdElement().toUnqualifiedVersionless().getValue()));
}
@Test
public void testSearchPersonByEidExcludesNonEmpiManaged() {
Person goodPerson = addExternalEID(createSourceResourcePatient(), TEST_EID);
myPersonDao.update(goodPerson);
Patient goodSourcePatient = addExternalEID(createSourceResourcePatient(), TEST_EID);
myPatientDao.update(goodSourcePatient);
Person badPerson = addExternalEID(createSourceResourcePatient(new Patient(), false), TEST_EID);
myPersonDao.update(badPerson);
Patient badSourcePatient = addExternalEID(createSourceResourcePatient(new Patient(), false), TEST_EID);
myPatientDao.update(badSourcePatient);
Optional<IAnyResource> foundPerson = myResourceDaoSvc.searchSourceResourceByEID(TEST_EID, "Person");
assertTrue(foundPerson.isPresent());
assertThat(foundPerson.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodPerson.getIdElement().toUnqualifiedVersionless().getValue()));
Optional<IAnyResource> foundSourcePatient = myResourceDaoSvc.searchSourceResourceByEID(TEST_EID, "Patient");
assertTrue(foundSourcePatient.isPresent());
assertThat(foundSourcePatient.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodSourcePatient.getIdElement().toUnqualifiedVersionless().getValue()));
}
}