Partial removal of getPersonFromTarget

This commit is contained in:
Tadgh 2020-11-05 13:41:01 -05:00
parent 5797cd0682
commit 656b8aeba7
9 changed files with 70 additions and 81 deletions

View File

@ -9,6 +9,7 @@ import ca.uhn.fhir.empi.model.EmpiTransactionContext;
import ca.uhn.fhir.empi.rules.svc.EmpiResourceMatcherSvc; import ca.uhn.fhir.empi.rules.svc.EmpiResourceMatcherSvc;
import ca.uhn.fhir.empi.util.EIDHelper; import ca.uhn.fhir.empi.util.EIDHelper;
import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome; import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
import ca.uhn.fhir.jpa.dao.data.IEmpiLinkDao; import ca.uhn.fhir.jpa.dao.data.IEmpiLinkDao;
@ -110,6 +111,9 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
protected ServletRequestDetails myRequestDetails; protected ServletRequestDetails myRequestDetails;
@Autowired
private DaoRegistry myDaoRegistry;
@BeforeEach @BeforeEach
public void beforeSetRequestDetails() { public void beforeSetRequestDetails() {
myRequestDetails = new ServletRequestDetails(myInterceptorBroadcaster); myRequestDetails = new ServletRequestDetails(myInterceptorBroadcaster);
@ -269,11 +273,14 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
assertEquals(theExpectedCount, myEmpiLinkDao.count()); assertEquals(theExpectedCount, myEmpiLinkDao.count());
} }
protected Person getPersonFromTarget(IAnyResource theBaseResource) { protected IAnyResource getSourceResourceFromTargetResource(IAnyResource theBaseResource) {
String resourceType = theBaseResource.getIdElement().getResourceType();
IFhirResourceDao relevantDao = myDaoRegistry.getResourceDao(resourceType);
Optional<EmpiLink> matchedLinkForTargetPid = myEmpiLinkDaoSvc.getMatchedLinkForTargetPid(myIdHelperService.getPidOrNull(theBaseResource)); Optional<EmpiLink> matchedLinkForTargetPid = myEmpiLinkDaoSvc.getMatchedLinkForTargetPid(myIdHelperService.getPidOrNull(theBaseResource));
if (matchedLinkForTargetPid.isPresent()) { if (matchedLinkForTargetPid.isPresent()) {
Long personPid = matchedLinkForTargetPid.get().getSourceResourcePid(); Long sourceResourcePid = matchedLinkForTargetPid.get().getSourceResourcePid();
return (Person) myPersonDao.readByPid(new ResourcePersistentId(personPid)); return (IAnyResource) relevantDao.readByPid(new ResourcePersistentId(sourceResourcePid));
} else { } else {
return null; return null;
} }

View File

@ -13,6 +13,7 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.server.TransactionLogMessages; import ca.uhn.fhir.rest.server.TransactionLogMessages;
import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException; import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.Enumerations;
@ -207,7 +208,7 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test {
jane = addExternalEID(jane, "some_new_eid"); jane = addExternalEID(jane, "some_new_eid");
EmpiHelperR4.OutcomeAndLogMessageWrapper outcomeWrapper = myEmpiHelper.updateWithLatch(jane); EmpiHelperR4.OutcomeAndLogMessageWrapper outcomeWrapper = myEmpiHelper.updateWithLatch(jane);
Person person = getPersonFromTarget(jane); IAnyResource person = getSourceResourceFromTargetResource(jane);
List<CanonicalEID> externalEids = myEIDHelper.getExternalEid(person); List<CanonicalEID> externalEids = myEIDHelper.getExternalEid(person);
assertThat(externalEids, hasSize(1)); assertThat(externalEids, hasSize(1));
assertThat("some_new_eid", is(equalTo(externalEids.get(0).getValue()))); assertThat("some_new_eid", is(equalTo(externalEids.get(0).getValue())));

View File

@ -34,9 +34,15 @@ public abstract class BaseSourceResourceMatcher extends TypeSafeMatcher<IAnyReso
protected Long getMatchedResourcePidFromResource(IAnyResource theResource) { protected Long getMatchedResourcePidFromResource(IAnyResource theResource) {
Long retval; Long retval;
EmpiLink matchLink = getMatchedEmpiLink(theResource); 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. //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();
if (matchLink == null) {
retval = myIdHelperService.getPidOrNull(theResource);
myTargetType = "unkown";
} else {
retval = matchLink.getSourceResourcePid();
myTargetType = matchLink.getEmpiTargetType();
}
return retval; return retval;
} }

View File

@ -4,8 +4,8 @@ import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.entity.EmpiLink; import ca.uhn.fhir.jpa.entity.EmpiLink;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Person;
import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -27,7 +27,7 @@ public abstract class BaseLinkR4Test extends BaseProviderR4Test {
DaoConfig myDaoConfig; DaoConfig myDaoConfig;
protected Patient myPatient; protected Patient myPatient;
protected Person myPerson; protected IAnyResource myPerson;
protected EmpiLink myLink; protected EmpiLink myLink;
protected StringType myPatientId; protected StringType myPatientId;
protected StringType myPersonId; protected StringType myPersonId;
@ -41,7 +41,7 @@ public abstract class BaseLinkR4Test extends BaseProviderR4Test {
myPatient = createPatientAndUpdateLinks(buildPaulPatient()); myPatient = createPatientAndUpdateLinks(buildPaulPatient());
myPatientId = new StringType(myPatient.getIdElement().getValue()); myPatientId = new StringType(myPatient.getIdElement().getValue());
myPerson = getPersonFromTarget(myPatient); myPerson = getSourceResourceFromTargetResource(myPatient);
myPersonId = new StringType(myPerson.getIdElement().getValue()); myPersonId = new StringType(myPerson.getIdElement().getValue());
myVersionlessPersonId = new StringType(myPerson.getIdElement().toVersionless().getValue()); myVersionlessPersonId = new StringType(myPerson.getIdElement().toVersionless().getValue());

View File

@ -5,8 +5,8 @@ import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.test.concurrency.PointcutLatch; import ca.uhn.test.concurrency.PointcutLatch;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Person;
import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
@ -25,7 +25,7 @@ public class EmpiProviderBatchR4Test extends BaseLinkR4Test {
protected Practitioner myPractitioner; protected Practitioner myPractitioner;
protected StringType myPractitionerId; protected StringType myPractitionerId;
protected Person myPractitionerPerson; protected IAnyResource myPractitionerPerson;
protected StringType myPractitionerPersonId; protected StringType myPractitionerPersonId;
@Autowired @Autowired
@ -38,7 +38,7 @@ public class EmpiProviderBatchR4Test extends BaseLinkR4Test {
super.before(); super.before();
myPractitioner = createPractitionerAndUpdateLinks(buildPractitionerWithNameAndId("some_pract", "some_pract_id")); myPractitioner = createPractitionerAndUpdateLinks(buildPractitionerWithNameAndId("some_pract", "some_pract_id"));
myPractitionerId = new StringType(myPractitioner.getIdElement().getValue()); myPractitionerId = new StringType(myPractitioner.getIdElement().getValue());
myPractitionerPerson = getPersonFromTarget(myPractitioner); myPractitionerPerson = getSourceResourceFromTargetResource(myPractitioner);
myPractitionerPersonId = new StringType(myPractitionerPerson.getIdElement().getValue()); myPractitionerPersonId = new StringType(myPractitionerPerson.getIdElement().getValue());
myInterceptorService.registerAnonymousInterceptor(Pointcut.EMPI_AFTER_PERSISTED_RESOURCE_CHECKED, afterEmpiLatch); myInterceptorService.registerAnonymousInterceptor(Pointcut.EMPI_AFTER_PERSISTED_RESOURCE_CHECKED, afterEmpiLatch);
} }

View File

@ -6,11 +6,11 @@ import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Person; import org.hl7.fhir.r4.model.Person;
import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -29,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.fail;
public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test { public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
protected Practitioner myPractitioner; protected Practitioner myPractitioner;
protected StringType myPractitionerId; protected StringType myPractitionerId;
protected Person myPractitionerPerson; protected IAnyResource myPractitionerPerson;
protected StringType myPractitionerPersonId; protected StringType myPractitionerPersonId;
@BeforeEach @BeforeEach
@ -37,7 +37,7 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
super.before(); super.before();
myPractitioner = createPractitionerAndUpdateLinks(new Practitioner()); myPractitioner = createPractitionerAndUpdateLinks(new Practitioner());
myPractitionerId = new StringType(myPractitioner.getIdElement().getValue()); myPractitionerId = new StringType(myPractitioner.getIdElement().getValue());
myPractitionerPerson = getPersonFromTarget(myPractitioner); myPractitionerPerson = getSourceResourceFromTargetResource(myPractitioner);
myPractitionerPersonId = new StringType(myPractitionerPerson.getIdElement().getValue()); myPractitionerPersonId = new StringType(myPractitionerPerson.getIdElement().getValue());
} }
@ -81,11 +81,11 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
createPatientAndUpdateLinks(buildJanePatient()); createPatientAndUpdateLinks(buildJanePatient());
createPatientAndUpdateLinks(buildJanePatient()); createPatientAndUpdateLinks(buildJanePatient());
Patient patientAndUpdateLinks = createPatientAndUpdateLinks(buildJanePatient()); Patient patientAndUpdateLinks = createPatientAndUpdateLinks(buildJanePatient());
Person person = getPersonFromTarget(patientAndUpdateLinks); IAnyResource person = getSourceResourceFromTargetResource(patientAndUpdateLinks);
assertThat(person, is(notNullValue())); assertThat(person, is(notNullValue()));
myEmpiProviderR4.clearEmpiLinks(null, myRequestDetails); myEmpiProviderR4.clearEmpiLinks(null, myRequestDetails);
assertNoPatientLinksExist(); assertNoPatientLinksExist();
person = getPersonFromTarget(patientAndUpdateLinks); person = getSourceResourceFromTargetResource(patientAndUpdateLinks);
assertThat(person, is(nullValue())); assertThat(person, is(nullValue()));
} }
@ -95,8 +95,8 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
Patient patientAndUpdateLinks1 = createPatientAndUpdateLinks(buildJanePatient()); Patient patientAndUpdateLinks1 = createPatientAndUpdateLinks(buildJanePatient());
Patient patientAndUpdateLinks = createPatientAndUpdateLinks(buildPaulPatient()); Patient patientAndUpdateLinks = createPatientAndUpdateLinks(buildPaulPatient());
Person personFromTarget = getPersonFromTarget(patientAndUpdateLinks); IAnyResource personFromTarget = getSourceResourceFromTargetResource(patientAndUpdateLinks);
Person personFromTarget2 = getPersonFromTarget(patientAndUpdateLinks1); IAnyResource personFromTarget2 = getSourceResourceFromTargetResource(patientAndUpdateLinks1);
linkPersons(personFromTarget, personFromTarget2); linkPersons(personFromTarget, personFromTarget2);
//SUT //SUT
@ -113,9 +113,9 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
Patient patientAndUpdateLinks1 = createPatientAndUpdateLinks(buildJanePatient()); Patient patientAndUpdateLinks1 = createPatientAndUpdateLinks(buildJanePatient());
Patient patientAndUpdateLinks2 = createPatientAndUpdateLinks(buildFrankPatient()); Patient patientAndUpdateLinks2 = createPatientAndUpdateLinks(buildFrankPatient());
Person personFromTarget = getPersonFromTarget(patientAndUpdateLinks); IAnyResource personFromTarget = getSourceResourceFromTargetResource(patientAndUpdateLinks);
Person personFromTarget1 = getPersonFromTarget(patientAndUpdateLinks1); IAnyResource personFromTarget1 = getSourceResourceFromTargetResource(patientAndUpdateLinks1);
Person personFromTarget2 = getPersonFromTarget(patientAndUpdateLinks2); IAnyResource personFromTarget2 = getSourceResourceFromTargetResource(patientAndUpdateLinks2);
// A -> B -> C -> A linkages. // A -> B -> C -> A linkages.
linkPersons(personFromTarget, personFromTarget1); linkPersons(personFromTarget, personFromTarget1);
@ -130,12 +130,9 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
} }
private void linkPersons(Person theSourcePerson, Person theTargetPerson) { //TODO GGG
Person.PersonLinkComponent plc1 = new Person.PersonLinkComponent(); private void linkPersons(IAnyResource theSourcePerson, IAnyResource theTargetPerson) {
plc1.setAssurance(Person.IdentityAssuranceLevel.LEVEL2); throw new UnsupportedOperationException("We need to fix this!");
plc1.setTarget(new Reference(theTargetPerson.getIdElement().toUnqualifiedVersionless()));
theSourcePerson.getLink().add(plc1);
myPersonDao.update(theSourcePerson);
} }
@Test @Test

View File

@ -5,6 +5,8 @@ import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.jpa.entity.EmpiLink; import ca.uhn.fhir.jpa.entity.EmpiLink;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.BooleanType; import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Parameters;
@ -68,8 +70,8 @@ public class EmpiProviderQueryLinkR4Test extends BaseLinkR4Test {
// Add a third patient // Add a third patient
Patient patient = createPatientAndUpdateLinks(buildJanePatient()); Patient patient = createPatientAndUpdateLinks(buildJanePatient());
IdType patientId = patient.getIdElement().toVersionless(); IdType patientId = patient.getIdElement().toVersionless();
Person person = getPersonFromTarget(patient); IAnyResource person = getSourceResourceFromTargetResource(patient);
IdType personId = person.getIdElement().toVersionless(); IIdType personId = person.getIdElement().toVersionless();
Parameters result = myEmpiProviderR4.queryLinks(null, null, null, myLinkSource, myRequestDetails); Parameters result = myEmpiProviderR4.queryLinks(null, null, null, myLinkSource, myRequestDetails);
ourLog.info(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(result)); ourLog.info(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(result));

View File

@ -5,9 +5,9 @@ import ca.uhn.fhir.empi.model.CanonicalEID;
import ca.uhn.fhir.empi.util.EIDHelper; import ca.uhn.fhir.empi.util.EIDHelper;
import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test; import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test;
import ca.uhn.fhir.jpa.entity.EmpiLink; import ca.uhn.fhir.jpa.entity.EmpiLink;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Identifier;
import org.hl7.fhir.r4.model.Patient; 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.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -50,7 +50,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
assertLinksCreatedNewResource(true); assertLinksCreatedNewResource(true);
assertLinksMatchedByEid(false); assertLinksMatchedByEid(false);
Person janePerson = getPersonFromTarget(patient); IAnyResource janePerson = getSourceResourceFromTargetResource(patient);
List<CanonicalEID> hapiEid = myEidHelper.getHapiEid(janePerson); List<CanonicalEID> hapiEid = myEidHelper.getHapiEid(janePerson);
String foundHapiEid = hapiEid.get(0).getValue(); String foundHapiEid = hapiEid.get(0).getValue();
@ -65,9 +65,9 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
//We want to make sure the patients were linked to the same person. //We want to make sure the patients were linked to the same person.
assertThat(patient, is(sameSourceResourceAs(janePatient))); assertThat(patient, is(sameSourceResourceAs(janePatient)));
Person person = getPersonFromTarget(patient); Patient sourcePatient = (Patient)getSourceResourceFromTargetResource(patient);
List<Identifier> identifier = person.getIdentifier(); List<Identifier> identifier = sourcePatient.getIdentifier();
//The collision should have kept the old identifier //The collision should have kept the old identifier
Identifier firstIdentifier = identifier.get(0); Identifier firstIdentifier = identifier.get(0);
@ -112,7 +112,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
addExternalEID(patient2, "id_6"); addExternalEID(patient2, "id_6");
//At this point, there should be 5 EIDs on the person //At this point, there should be 5 EIDs on the person
Person personFromTarget = getPersonFromTarget(patient2); Patient personFromTarget = (Patient)getSourceResourceFromTargetResource(patient2);
assertThat(personFromTarget.getIdentifier(), hasSize(5)); assertThat(personFromTarget.getIdentifier(), hasSize(5));
updatePatientAndUpdateLinks(patient2); updatePatientAndUpdateLinks(patient2);
@ -122,7 +122,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
assertThat(patient1, is(sameSourceResourceAs(patient2))); assertThat(patient1, is(sameSourceResourceAs(patient2)));
personFromTarget = getPersonFromTarget(patient2); personFromTarget = (Patient) getSourceResourceFromTargetResource(patient2);
assertThat(personFromTarget.getIdentifier(), hasSize(6)); assertThat(personFromTarget.getIdentifier(), hasSize(6));
} }
@ -149,7 +149,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test {
assertThat(possibleDuplicates, hasSize(1)); assertThat(possibleDuplicates, hasSize(1));
List<Long> duplicatePids = Stream.of(patient1, patient2) List<Long> duplicatePids = Stream.of(patient1, patient2)
.map(this::getPersonFromTarget) .map(this::getSourceResourceFromTargetResource)
.map(myIdHelperService::getPidOrNull) .map(myIdHelperService::getPidOrNull)
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@ -100,8 +100,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
@Test @Test
public void testWhenMatchOccursOnPersonThatHasBeenManuallyNOMATCHedThatItIsBlocked() { public void testWhenMatchOccursOnPersonThatHasBeenManuallyNOMATCHedThatItIsBlocked() {
Patient originalJane = createPatientAndUpdateLinks(buildJanePatient()); Patient originalJane = createPatientAndUpdateLinks(buildJanePatient());
IBundleProvider search = myPersonDao.search(new SearchParameterMap()); IAnyResource janePerson = getSourceResourceFromTargetResource(originalJane);
IAnyResource janePerson = (IAnyResource) search.getResources(0, 1).get(0);
//Create a manual NO_MATCH between janePerson and unmatchedJane. //Create a manual NO_MATCH between janePerson and unmatchedJane.
Patient unmatchedJane = createPatient(buildJanePatient()); Patient unmatchedJane = createPatient(buildJanePatient());
@ -196,7 +195,7 @@ public class EmpiMatchLinkSvcTest 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. // 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()); Patient patient = createPatientAndUpdateLinks(buildJanePatient());
Person janePerson = getPersonFromTarget(patient); IAnyResource janePerson = getSourceResourceFromTargetResource(patient);
List<CanonicalEID> hapiEid = myEidHelper.getHapiEid(janePerson); List<CanonicalEID> hapiEid = myEidHelper.getHapiEid(janePerson);
String foundHapiEid = hapiEid.get(0).getValue(); String foundHapiEid = hapiEid.get(0).getValue();
@ -206,9 +205,9 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
//We want to make sure the patients were linked to the same person. //We want to make sure the patients were linked to the same person.
assertThat(patient, is(sameSourceResourceAs(janePatient))); assertThat(patient, is(sameSourceResourceAs(janePatient)));
Person person = getPersonFromTarget(patient); Patient sourcePatient = (Patient)getSourceResourceFromTargetResource(patient);
List<Identifier> identifier = person.getIdentifier(); List<Identifier> identifier = sourcePatient.getIdentifier();
//The collision should have kept the old identifier //The collision should have kept the old identifier
Identifier firstIdentifier = identifier.get(0); Identifier firstIdentifier = identifier.get(0);
@ -264,7 +263,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
List<Long> duplicatePids = Stream.of(patient1, patient2) List<Long> duplicatePids = Stream.of(patient1, patient2)
.map(this::getPersonFromTarget) .map(this::getSourceResourceFromTargetResource)
.map(myIdHelperService::getPidOrNull) .map(myIdHelperService::getPidOrNull)
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -421,45 +420,22 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
assertThat(patient3, is(sameSourceResourceAs(patient))); assertThat(patient3, is(sameSourceResourceAs(patient)));
} }
@Test
public void testAutoMatchesGenerateAssuranceLevel3() {
Patient patient = createPatientAndUpdateLinks(buildJanePatient());
Person janePerson = getPersonFromTarget(patient);
Person.PersonLinkComponent linkFirstRep = janePerson.getLinkFirstRep();
assertThat(linkFirstRep.getTarget().getReference(), is(equalTo(patient.getIdElement().toVersionless().toString())));
assertThat(linkFirstRep.getAssurance(), is(equalTo(Person.IdentityAssuranceLevel.LEVEL2)));
}
@Test
public void testManualMatchesGenerateAssuranceLevel4() {
Patient patient = createPatientAndUpdateLinks(buildJanePatient());
Person janePerson = getPersonFromTarget(patient);
myEmpiLinkSvc.updateLink(janePerson, patient, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate());
janePerson = getPersonFromTarget(patient);
Person.PersonLinkComponent linkFirstRep = janePerson.getLinkFirstRep();
assertThat(linkFirstRep.getTarget().getReference(), is(equalTo(patient.getIdElement().toVersionless().toString())));
assertThat(linkFirstRep.getAssurance(), is(equalTo(Person.IdentityAssuranceLevel.LEVEL3)));
}
//Case #1 //Case #1
@Test @Test
public void testPatientUpdateOverwritesPersonDataOnChanges() { public void testPatientUpdateOverwritesPersonDataOnChanges() {
Patient janePatient = createPatientAndUpdateLinks(buildJanePatient()); Patient janePatient = createPatientAndUpdateLinks(buildJanePatient());
Person janePerson = getPersonFromTarget(janePatient); Patient janeSourcePatient = (Patient)getSourceResourceFromTargetResource(janePatient);
//Change Jane's name to paul. //Change Jane's name to paul.
Patient patient1 = buildPaulPatient(); Patient patient1 = buildPaulPatient();
patient1.setId(janePatient.getId()); patient1.setId(janePatient.getId());
Patient janePaulPatient = updatePatientAndUpdateLinks(patient1); Patient janePaulPatient = updatePatientAndUpdateLinks(patient1);
assertThat(janePerson, is(sameSourceResourceAs(janePaulPatient))); assertThat(janeSourcePatient, is(sameSourceResourceAs(janePaulPatient)));
//Ensure the related person was updated with new info. //Ensure the related person was updated with new info.
Person personFromTarget = getPersonFromTarget(janePaulPatient); Patient sourcePatientFromTarget = (Patient) t geetSourceResourceFromTargetResource(janePaulPatient);
HumanName nameFirstRep = personFromTarget.getNameFirstRep(); HumanName nameFirstRep = sourcePatientFromTarget.getNameFirstRep();
assertThat(nameFirstRep.getGivenAsSingleString(), is(equalToIgnoringCase("paul"))); assertThat(nameFirstRep.getGivenAsSingleString(), is(equalToIgnoringCase("paul")));
} }
@ -469,7 +445,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
paul.setGender(Enumerations.AdministrativeGender.MALE); paul.setGender(Enumerations.AdministrativeGender.MALE);
paul = createPatientAndUpdateLinks(paul); paul = createPatientAndUpdateLinks(paul);
Person personFromTarget = getPersonFromTarget(paul); Person personFromTarget = getSourceResourceFromTargetResource(paul);
assertThat(personFromTarget.getGender(), is(equalTo(Enumerations.AdministrativeGender.MALE))); assertThat(personFromTarget.getGender(), is(equalTo(Enumerations.AdministrativeGender.MALE)));
Patient paul2 = buildPaulPatient(); Patient paul2 = buildPaulPatient();
@ -479,7 +455,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
assertThat(paul2, is(sameSourceResourceAs(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. //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); Person paul2Person = getSourceResourceFromTargetResource(paul2);
assertThat(paul2Person.getGender(), is(equalTo(Enumerations.AdministrativeGender.MALE))); assertThat(paul2Person.getGender(), is(equalTo(Enumerations.AdministrativeGender.MALE)));
} }
@ -491,7 +467,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
paul.getBirthDateElement().setValueAsString(incorrectBirthdate); paul.getBirthDateElement().setValueAsString(incorrectBirthdate);
paul = createPatientAndUpdateLinks(paul); paul = createPatientAndUpdateLinks(paul);
Person personFromTarget = getPersonFromTarget(paul); Person personFromTarget = getSourceResourceFromTargetResource(paul);
assertThat(personFromTarget.getBirthDateElement().getValueAsString(), is(incorrectBirthdate)); assertThat(personFromTarget.getBirthDateElement().getValueAsString(), is(incorrectBirthdate));
String correctBirthdate = "1990-06-28"; String correctBirthdate = "1990-06-28";
@ -499,7 +475,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
paul = updatePatientAndUpdateLinks(paul); paul = updatePatientAndUpdateLinks(paul);
personFromTarget = getPersonFromTarget(paul); personFromTarget = getSourceResourceFromTargetResource(paul);
assertThat(personFromTarget.getBirthDateElement().getValueAsString(), is(equalTo(correctBirthdate))); assertThat(personFromTarget.getBirthDateElement().getValueAsString(), is(equalTo(correctBirthdate)));
assertLinkCount(1); assertLinkCount(1);
} }
@ -511,10 +487,10 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
String EID_2 = "456"; String EID_2 = "456";
Patient paul = createPatientAndUpdateLinks(addExternalEID(buildPaulPatient(), EID_1)); Patient paul = createPatientAndUpdateLinks(addExternalEID(buildPaulPatient(), EID_1));
Person originalPaulPerson = getPersonFromTarget(paul); Person originalPaulPerson = getSourceResourceFromTargetResource(paul);
Patient jane = createPatientAndUpdateLinks(addExternalEID(buildJanePatient(), EID_2)); Patient jane = createPatientAndUpdateLinks(addExternalEID(buildJanePatient(), EID_2));
Person originalJanePerson = getPersonFromTarget(jane); Person originalJanePerson = getSourceResourceFromTargetResource(jane);
clearExternalEIDs(paul); clearExternalEIDs(paul);
addExternalEID(paul, EID_2); addExternalEID(paul, EID_2);
@ -531,7 +507,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
String EID_2 = "456"; String EID_2 = "456";
Patient paul = createPatientAndUpdateLinks(addExternalEID(buildPaulPatient(), EID_1)); Patient paul = createPatientAndUpdateLinks(addExternalEID(buildPaulPatient(), EID_1));
Person originalPaulPerson = getPersonFromTarget(paul); Person originalPaulPerson = getSourceResourceFromTargetResource(paul);
String oldEid = myEidHelper.getExternalEid(originalPaulPerson).get(0).getValue(); String oldEid = myEidHelper.getExternalEid(originalPaulPerson).get(0).getValue();
assertThat(oldEid, is(equalTo(EID_1))); assertThat(oldEid, is(equalTo(EID_1)));
@ -542,7 +518,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
assertNoDuplicates(); assertNoDuplicates();
Person newlyFoundPaulPerson = getPersonFromTarget(paul); Person newlyFoundPaulPerson = getSourceResourceFromTargetResource(paul);
assertThat(originalPaulPerson, is(sameSourceResourceAs(newlyFoundPaulPerson))); assertThat(originalPaulPerson, is(sameSourceResourceAs(newlyFoundPaulPerson)));
String newEid = myEidHelper.getExternalEid(newlyFoundPaulPerson).get(0).getValue(); String newEid = myEidHelper.getExternalEid(newlyFoundPaulPerson).get(0).getValue();
assertThat(newEid, is(equalTo(EID_2))); assertThat(newEid, is(equalTo(EID_2)));
@ -597,12 +573,12 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
jane.setActive(true); jane.setActive(true);
Patient janePatient = createPatientAndUpdateLinks(jane); Patient janePatient = createPatientAndUpdateLinks(jane);
Person janePerson = getPersonFromTarget(janePatient); Person janePerson = getSourceResourceFromTargetResource(janePatient);
Patient paul = buildPaulPatient(); Patient paul = buildPaulPatient();
paul.setActive(true); paul.setActive(true);
Patient paulPatient = createPatientAndUpdateLinks(paul); Patient paulPatient = createPatientAndUpdateLinks(paul);
Person paulPerson = getPersonFromTarget(paulPatient); Person paulPerson = getSourceResourceFromTargetResource(paulPatient);
paulPatient.setBirthDate(jane.getBirthDate()); paulPatient.setBirthDate(jane.getBirthDate());
paulPatient.setName(jane.getName()); paulPatient.setName(jane.getName());
@ -610,7 +586,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
myEmpiMatchLinkSvc.updateEmpiLinksForEmpiTarget(paulPatient, createContextForUpdate()); myEmpiMatchLinkSvc.updateEmpiLinksForEmpiTarget(paulPatient, createContextForUpdate());
assertThat(paulPerson.getBirthDate(), is(nullValue())); assertThat(paulPerson.getBirthDate(), is(nullValue()));
paulPerson = getPersonFromTarget(paulPatient); paulPerson = getSourceResourceFromTargetResource(paulPatient);
assertThat(paulPerson.getBirthDate(), is(notNullValue())); assertThat(paulPerson.getBirthDate(), is(notNullValue()));
} }
} }