continue refactor of providers
This commit is contained in:
parent
c55de80c6a
commit
d7974a6f1d
|
@ -83,8 +83,6 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
|
|||
@Autowired
|
||||
protected FhirContext myFhirContext;
|
||||
@Autowired
|
||||
protected IFhirResourceDao<Person> myPersonDao;
|
||||
@Autowired
|
||||
protected IFhirResourceDao<Patient> myPatientDao;
|
||||
@Autowired
|
||||
protected IFhirResourceDao<Practitioner> myPractitionerDao;
|
||||
|
@ -362,10 +360,10 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
|
|||
return IsMatchedToAPerson.matchedToAPerson(myIdHelperService, myEmpiLinkDaoSvc);
|
||||
}
|
||||
|
||||
protected Person getOnlyActivePerson() {
|
||||
protected Patient getOnlyActiveSourcePatient() {
|
||||
List<IBaseResource> resources = getAllActiveSourcePatients();
|
||||
assertEquals(1, resources.size());
|
||||
return (Person) resources.get(0);
|
||||
return (Patient) resources.get(0);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -12,7 +12,6 @@ import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
|||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.hl7.fhir.r4.model.Person;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -34,7 +33,7 @@ public class EmpiExpungeTest extends BaseEmpiR4Test {
|
|||
@Autowired
|
||||
IEmpiLinkDao myEmpiLinkDao;
|
||||
private ResourceTable myTargetEntity;
|
||||
private ResourceTable myPersonEntity;
|
||||
private ResourceTable mySourceEntity;
|
||||
private IdDt myTargetId;
|
||||
|
||||
@BeforeEach
|
||||
|
@ -43,12 +42,12 @@ public class EmpiExpungeTest extends BaseEmpiR4Test {
|
|||
|
||||
myTargetEntity = (ResourceTable) myPatientDao.create(new Patient()).getEntity();
|
||||
myTargetId = myTargetEntity.getIdDt().toVersionless();
|
||||
myPersonEntity = (ResourceTable) myPersonDao.create(new Person()).getEntity();
|
||||
mySourceEntity = (ResourceTable) myPatientDao.create(new Patient()).getEntity();
|
||||
|
||||
EmpiLink empiLink = myEmpiLinkDaoSvc.newEmpiLink();
|
||||
empiLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
|
||||
empiLink.setMatchResult(EmpiMatchResultEnum.MATCH);
|
||||
empiLink.setSourceResourcePid(myPersonEntity.getId());
|
||||
empiLink.setSourceResourcePid(mySourceEntity.getId());
|
||||
empiLink.setTargetPid(myTargetEntity.getId());
|
||||
saveLink(empiLink);
|
||||
}
|
||||
|
|
|
@ -68,18 +68,12 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test {
|
|||
assertLinkCount(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatePerson() {
|
||||
myPersonDao.create(new Person());
|
||||
assertLinkCount(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletePersonDeletesLinks() throws InterruptedException {
|
||||
myEmpiHelper.createWithLatch(buildPaulPatient());
|
||||
assertLinkCount(1);
|
||||
Person person = getOnlyActivePerson();
|
||||
myPersonDao.delete(person.getIdElement());
|
||||
Patient sourcePatient = getOnlyActiveSourcePatient();
|
||||
myPatientDao.delete(sourcePatient.getIdElement());
|
||||
assertLinkCount(0);
|
||||
}
|
||||
|
||||
|
@ -140,7 +134,8 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test {
|
|||
myEmpiHelper.createWithLatch(buildJanePatient());
|
||||
myEmpiHelper.createWithLatch(buildPaulPatient());
|
||||
|
||||
IBundleProvider search = myPersonDao.search(new SearchParameterMap().setLoadSynchronous(true));
|
||||
//TODO GGG MDM: this test is out of date, since we now are using golden record Patients
|
||||
IBundleProvider search = myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true));
|
||||
List<IBaseResource> resources = search.getResources(0, search.size());
|
||||
|
||||
for (IBaseResource person : resources) {
|
||||
|
@ -175,11 +170,11 @@ 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.getSourceResourcePid();
|
||||
Person empiPerson = (Person) myPersonDao.readByPid(new ResourcePersistentId(personPid));
|
||||
empiPerson.setGender(Enumerations.AdministrativeGender.MALE);
|
||||
Long sourcePatientPid = empiLink.getSourceResourcePid();
|
||||
Patient empiSourcePatient = (Patient) myPatientDao.readByPid(new ResourcePersistentId(sourcePatientPid));
|
||||
empiSourcePatient.setGender(Enumerations.AdministrativeGender.MALE);
|
||||
try {
|
||||
myEmpiHelper.doUpdateResource(empiPerson, true);
|
||||
myEmpiHelper.doUpdateResource(empiSourcePatient, true);
|
||||
fail();
|
||||
} catch (ForbiddenOperationException e) {
|
||||
assertEquals("Cannot create or modify Resources that are managed by EMPI.", e.getMessage());
|
||||
|
|
|
@ -27,10 +27,10 @@ public abstract class BaseLinkR4Test extends BaseProviderR4Test {
|
|||
DaoConfig myDaoConfig;
|
||||
|
||||
protected Patient myPatient;
|
||||
protected IAnyResource myPerson;
|
||||
protected IAnyResource mySourcePatient;
|
||||
protected EmpiLink myLink;
|
||||
protected StringType myPatientId;
|
||||
protected StringType myPersonId;
|
||||
protected StringType mySourcePatientId;
|
||||
protected StringType myVersionlessPersonId;
|
||||
|
||||
@Override
|
||||
|
@ -41,9 +41,9 @@ public abstract class BaseLinkR4Test extends BaseProviderR4Test {
|
|||
myPatient = createPatientAndUpdateLinks(buildPaulPatient());
|
||||
myPatientId = new StringType(myPatient.getIdElement().getValue());
|
||||
|
||||
myPerson = getSourceResourceFromTargetResource(myPatient);
|
||||
myPersonId = new StringType(myPerson.getIdElement().getValue());
|
||||
myVersionlessPersonId = new StringType(myPerson.getIdElement().toVersionless().getValue());
|
||||
mySourcePatient = getSourceResourceFromTargetResource(myPatient);
|
||||
mySourcePatientId = new StringType(mySourcePatient.getIdElement().getValue());
|
||||
myVersionlessPersonId = new StringType(mySourcePatient.getIdElement().toVersionless().getValue());
|
||||
|
||||
myLink = getOnlyPatientLink();
|
||||
// Tests require our initial link to be a POSSIBLE_MATCH
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
package ca.uhn.fhir.jpa.empi.provider;
|
||||
|
||||
import ca.uhn.fhir.empi.api.EmpiConstants;
|
||||
import ca.uhn.fhir.jpa.entity.EmpiLink;
|
||||
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
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.Patient;
|
||||
import org.hl7.fhir.r4.model.Person;
|
||||
import org.hl7.fhir.r4.model.Practitioner;
|
||||
import org.hl7.fhir.r4.model.StringType;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -29,16 +30,16 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
|
||||
protected Practitioner myPractitioner;
|
||||
protected StringType myPractitionerId;
|
||||
protected IAnyResource myPractitionerPerson;
|
||||
protected StringType myPractitionerPersonId;
|
||||
protected IAnyResource myPractitionerSourceResource;
|
||||
protected StringType myPractitionerSourceResourceId;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
super.before();
|
||||
myPractitioner = createPractitionerAndUpdateLinks(new Practitioner());
|
||||
myPractitionerId = new StringType(myPractitioner.getIdElement().getValue());
|
||||
myPractitionerPerson = getSourceResourceFromTargetResource(myPractitioner);
|
||||
myPractitionerPersonId = new StringType(myPractitionerPerson.getIdElement().getValue());
|
||||
myPractitionerSourceResource = getSourceResourceFromTargetResource(myPractitioner);
|
||||
myPractitionerSourceResourceId = new StringType(myPractitionerSourceResource.getIdElement().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -64,12 +65,12 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
|
|||
@Test
|
||||
public void testClearPatientLinks() {
|
||||
assertLinkCount(2);
|
||||
Person read = myPersonDao.read(new IdDt(myPersonId.getValueAsString()).toVersionless());
|
||||
Patient read = myPatientDao.read(new IdDt(mySourcePatientId.getValueAsString()).toVersionless());
|
||||
assertThat(read, is(notNullValue()));
|
||||
myEmpiProviderR4.clearEmpiLinks(new StringType("Patient"), myRequestDetails);
|
||||
assertNoPatientLinksExist();
|
||||
try {
|
||||
myPersonDao.read(new IdDt(myPersonId.getValueAsString()).toVersionless());
|
||||
myPatientDao.read(new IdDt(mySourcePatientId.getValueAsString()).toVersionless());
|
||||
fail();
|
||||
} catch (ResourceNotFoundException e) {}
|
||||
|
||||
|
@ -103,10 +104,18 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
|
|||
myEmpiProviderR4.clearEmpiLinks(null, myRequestDetails);
|
||||
|
||||
assertNoPatientLinksExist();
|
||||
IBundleProvider search = myPersonDao.search(new SearchParameterMap().setLoadSynchronous(true));
|
||||
IBundleProvider search = myPatientDao.search(buildSourceResourceParameterMap());
|
||||
assertThat(search.size(), is(equalTo(0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a SearchParameterMap which looks up Golden Records (Source resources).
|
||||
* @return
|
||||
*/
|
||||
private SearchParameterMap buildSourceResourceParameterMap() {
|
||||
return new SearchParameterMap().setLoadSynchronous(true).add("_tag", new TokenParam(EmpiConstants.SYSTEM_EMPI_MANAGED, EmpiConstants.CODE_HAPI_EMPI_MANAGED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersonsWithCircularReferenceCanBeCleared() {
|
||||
Patient patientAndUpdateLinks = createPatientAndUpdateLinks(buildPaulPatient());
|
||||
|
@ -125,12 +134,12 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
|
|||
//SUT
|
||||
Parameters parameters = myEmpiProviderR4.clearEmpiLinks(null, myRequestDetails);
|
||||
assertNoPatientLinksExist();
|
||||
IBundleProvider search = myPersonDao.search(new SearchParameterMap().setLoadSynchronous(true));
|
||||
IBundleProvider search = myPatientDao.search(buildSourceResourceParameterMap());
|
||||
assertThat(search.size(), is(equalTo(0)));
|
||||
|
||||
}
|
||||
|
||||
//TODO GGG
|
||||
//TODO GGG unclear if we actually need to reimplement this.
|
||||
private void linkPersons(IAnyResource theSourcePerson, IAnyResource theTargetPerson) {
|
||||
throw new UnsupportedOperationException("We need to fix this!");
|
||||
}
|
||||
|
@ -138,12 +147,12 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
|
|||
@Test
|
||||
public void testClearPractitionerLinks() {
|
||||
assertLinkCount(2);
|
||||
Person read = myPersonDao.read(new IdDt(myPractitionerPersonId.getValueAsString()).toVersionless());
|
||||
Practitioner read = myPractitionerDao.read(new IdDt(myPractitionerSourceResourceId.getValueAsString()).toVersionless());
|
||||
assertThat(read, is(notNullValue()));
|
||||
myEmpiProviderR4.clearEmpiLinks(new StringType("Practitioner"), myRequestDetails);
|
||||
assertNoPractitionerLinksExist();
|
||||
try {
|
||||
myPersonDao.read(new IdDt(myPractitionerPersonId.getValueAsString()).toVersionless());
|
||||
myPractitionerDao.read(new IdDt(myPractitionerSourceResourceId.getValueAsString()).toVersionless());
|
||||
fail();
|
||||
} catch (ResourceNotFoundException e) {}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
package ca.uhn.fhir.jpa.empi.provider;
|
||||
|
||||
import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
|
||||
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.Identifier;
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
@ -41,18 +39,22 @@ public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test {
|
|||
|
||||
@Test
|
||||
public void testMerge() {
|
||||
Person mergedPerson = myEmpiProviderR4.mergePersons(myFromSourcePatientId, myToSourcePatientId, myRequestDetails);
|
||||
assertEquals(myToSourcePatient.getIdElement(), mergedPerson.getIdElement());
|
||||
assertThat(mergedPerson, is(sameSourceResourceAs(myToSourcePatient)));
|
||||
//TODO GGG RP fix
|
||||
Person mergedSourcePatient = myEmpiProviderR4.mergePersons(myFromSourcePatientId, myToSourcePatientId, myRequestDetails);
|
||||
assertEquals(myToSourcePatient.getIdElement(), mergedSourcePatient.getIdElement());
|
||||
assertThat(mergedSourcePatient, is(sameSourceResourceAs(myToSourcePatient)));
|
||||
assertEquals(2, getAllSourcePatients().size());
|
||||
assertEquals(1, getAllActiveSourcePatients().size());
|
||||
|
||||
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 (myToSourcePatient.getIdElement().toUnqualifiedVersionless().getValue()));
|
||||
assertThat(links.get(0).getAssurance(), is (AssuranceLevelUtil.getAssuranceLevel(EmpiMatchResultEnum.REDIRECT, EmpiLinkSourceEnum.MANUAL).toR4()));
|
||||
Patient fromSourcePatient = myPatientDao.read(myFromSourcePatient.getIdElement().toUnqualifiedVersionless());
|
||||
assertThat(fromSourcePatient.getActive(), is(false));
|
||||
//TODO GGG eventually this will need to check a redirect... this is a hack which doesnt work
|
||||
Optional<Identifier> redirect = fromSourcePatient.getIdentifier().stream().filter(theIdentifier -> theIdentifier.getSystem().equals("REDIRECT")).findFirst();
|
||||
assertThat(redirect.get().getValue(), is(equalTo(myToSourcePatient.getIdElement().toUnqualified().getValue())));
|
||||
//List<Person.PersonLinkComponent> links = fromSourcePatient.getLink();
|
||||
//assertThat(links, hasSize(1));
|
||||
//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
|
||||
|
|
|
@ -56,12 +56,12 @@ public class EmpiProviderQueryLinkR4Test extends BaseLinkR4Test {
|
|||
@Test
|
||||
public void testQueryLinkOneMatch() {
|
||||
|
||||
Parameters result = myEmpiProviderR4.queryLinks(myPersonId, myPatientId, null, null, myRequestDetails);
|
||||
Parameters result = myEmpiProviderR4.queryLinks(mySourcePatientId, myPatientId, null, null, myRequestDetails);
|
||||
ourLog.info(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(result));
|
||||
List<Parameters.ParametersParameterComponent> list = result.getParameter();
|
||||
assertThat(list, hasSize(1));
|
||||
List<Parameters.ParametersParameterComponent> part = list.get(0).getPart();
|
||||
assertEmpiLink(7, part, myPersonId.getValue(), myPatientId.getValue(), EmpiMatchResultEnum.POSSIBLE_MATCH, "false", "true", null);
|
||||
assertEmpiLink(7, part, mySourcePatientId.getValue(), myPatientId.getValue(), EmpiMatchResultEnum.POSSIBLE_MATCH, "false", "true", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -25,7 +25,7 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
|||
@Test
|
||||
public void testUpdateLinkNoMatch() {
|
||||
assertLinkCount(1);
|
||||
myEmpiProviderR4.updateLink(myPersonId, myPatientId, NO_MATCH_RESULT, myRequestDetails);
|
||||
myEmpiProviderR4.updateLink(mySourcePatientId, myPatientId, NO_MATCH_RESULT, myRequestDetails);
|
||||
assertLinkCount(2);
|
||||
|
||||
List<EmpiLink> links = getPatientLinks();
|
||||
|
@ -39,7 +39,7 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
|||
@Test
|
||||
public void testUpdateLinkMatch() {
|
||||
assertLinkCount(1);
|
||||
myEmpiProviderR4.updateLink(myPersonId, myPatientId, MATCH_RESULT, myRequestDetails);
|
||||
myEmpiProviderR4.updateLink(mySourcePatientId, myPatientId, MATCH_RESULT, myRequestDetails);
|
||||
assertLinkCount(1);
|
||||
|
||||
List<EmpiLink> links = getPatientLinks();
|
||||
|
@ -49,9 +49,9 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
|||
|
||||
@Test
|
||||
public void testUpdateLinkTwiceFailsDueToWrongVersion() {
|
||||
myEmpiProviderR4.updateLink(myPersonId, myPatientId, MATCH_RESULT, myRequestDetails);
|
||||
myEmpiProviderR4.updateLink(mySourcePatientId, myPatientId, MATCH_RESULT, myRequestDetails);
|
||||
try {
|
||||
myEmpiProviderR4.updateLink(myPersonId, myPatientId, NO_MATCH_RESULT, myRequestDetails);
|
||||
myEmpiProviderR4.updateLink(mySourcePatientId, myPatientId, NO_MATCH_RESULT, myRequestDetails);
|
||||
fail();
|
||||
} catch (ResourceVersionConflictException e) {
|
||||
assertThat(e.getMessage(), matchesPattern("Requested resource Person/\\d+/_history/1 is not the latest version. Latest version is Person/\\d+/_history/2"));
|
||||
|
@ -60,16 +60,16 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
|||
|
||||
@Test
|
||||
public void testUpdateLinkTwiceWorksWhenNoVersionProvided() {
|
||||
myEmpiProviderR4.updateLink(myPersonId, myPatientId, MATCH_RESULT, myRequestDetails);
|
||||
myEmpiProviderR4.updateLink(mySourcePatientId, myPatientId, MATCH_RESULT, myRequestDetails);
|
||||
Person person = myEmpiProviderR4.updateLink(myVersionlessPersonId, myPatientId, NO_MATCH_RESULT, myRequestDetails);
|
||||
assertThat(person.getLink(), hasSize(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnlinkLink() {
|
||||
myEmpiProviderR4.updateLink(myPersonId, myPatientId, NO_MATCH_RESULT, myRequestDetails);
|
||||
myEmpiProviderR4.updateLink(mySourcePatientId, myPatientId, NO_MATCH_RESULT, myRequestDetails);
|
||||
try {
|
||||
myEmpiProviderR4.updateLink(myPersonId, myPatientId, MATCH_RESULT, myRequestDetails);
|
||||
myEmpiProviderR4.updateLink(mySourcePatientId, myPatientId, MATCH_RESULT, myRequestDetails);
|
||||
fail();
|
||||
} catch (ResourceVersionConflictException e) {
|
||||
assertThat(e.getMessage(), matchesPattern("Requested resource Person/\\d+/_history/1 is not the latest version. Latest version is Person/\\d+/_history/2"));
|
||||
|
@ -79,7 +79,7 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
|||
@Test
|
||||
public void testUpdateIllegalResultPM() {
|
||||
try {
|
||||
myEmpiProviderR4.updateLink(myPersonId, myPatientId, POSSIBLE_MATCH_RESULT, myRequestDetails);
|
||||
myEmpiProviderR4.updateLink(mySourcePatientId, myPatientId, POSSIBLE_MATCH_RESULT, myRequestDetails);
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("$empi-update-link illegal matchResult value 'POSSIBLE_MATCH'. Must be NO_MATCH or MATCH", e.getMessage());
|
||||
|
@ -89,7 +89,7 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
|||
@Test
|
||||
public void testUpdateIllegalResultPD() {
|
||||
try {
|
||||
myEmpiProviderR4.updateLink(myPersonId, myPatientId, POSSIBLE_DUPLICATE_RESULT, myRequestDetails);
|
||||
myEmpiProviderR4.updateLink(mySourcePatientId, myPatientId, POSSIBLE_DUPLICATE_RESULT, myRequestDetails);
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("$empi-update-link illegal matchResult value 'POSSIBLE_DUPLICATE'. Must be NO_MATCH or MATCH", e.getMessage());
|
||||
|
@ -109,7 +109,7 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
|||
@Test
|
||||
public void testUpdateIllegalSecondArg() {
|
||||
try {
|
||||
myEmpiProviderR4.updateLink(myPersonId, myPersonId, NO_MATCH_RESULT, myRequestDetails);
|
||||
myEmpiProviderR4.updateLink(mySourcePatientId, mySourcePatientId, NO_MATCH_RESULT, myRequestDetails);
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertThat(e.getMessage(), endsWith("must have form Patient/<id> or Practitioner/<id> where <id> is the id of the resource"));
|
||||
|
@ -133,7 +133,7 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
|||
patient.getMeta().addTag().setSystem(EmpiConstants.SYSTEM_EMPI_MANAGED).setCode(EmpiConstants.CODE_NO_EMPI_MANAGED);
|
||||
createPatient(patient);
|
||||
try {
|
||||
myEmpiProviderR4.updateLink(myPersonId, new StringType(patient.getIdElement().getValue()), NO_MATCH_RESULT, myRequestDetails);
|
||||
myEmpiProviderR4.updateLink(mySourcePatientId, new StringType(patient.getIdElement().getValue()), NO_MATCH_RESULT, myRequestDetails);
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("The target is marked with the " + EmpiConstants.CODE_NO_EMPI_MANAGED + " tag which means it may not be EMPI linked.", e.getMessage());
|
||||
|
|
|
@ -1,22 +1,10 @@
|
|||
package ca.uhn.fhir.jpa.empi.searchparam;
|
||||
|
||||
import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test;
|
||||
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class SearchParameterTest extends BaseEmpiR4Test {
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(SearchParameterTest.class);
|
||||
|
||||
|
@ -25,6 +13,11 @@ public class SearchParameterTest extends BaseEmpiR4Test {
|
|||
super.loadEmpiSearchParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO GGG MDM ask ken if we still need this search parameter.
|
||||
* The implementation this test tests will instead need to rely on MPI_LINK table?
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testCanFindPossibleMatches() {
|
||||
// Create a possible match
|
||||
|
@ -53,4 +46,5 @@ public class SearchParameterTest extends BaseEmpiR4Test {
|
|||
assertEquals(Person.IdentityAssuranceLevel.LEVEL2, links.get(0).getAssurance());
|
||||
assertEquals(Person.IdentityAssuranceLevel.LEVEL1, links.get(1).getAssurance());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.hl7.fhir.r4.model.Enumerations;
|
|||
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.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -94,16 +93,16 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
assertEquals(2, getAllSourcePatients().size());
|
||||
assertEquals(2, getAllActiveSourcePatients().size());
|
||||
|
||||
Person mergedPerson = mergePersons();
|
||||
assertEquals(myToSourcePatient.getIdElement(), mergedPerson.getIdElement());
|
||||
assertThat(mergedPerson, is(sameSourceResourceAs(mergedPerson)));
|
||||
Patient mergedSourcePatients = mergeSourcePatients();
|
||||
assertEquals(myToSourcePatient.getIdElement(), mergedSourcePatients.getIdElement());
|
||||
assertThat(mergedSourcePatients, is(sameSourceResourceAs(mergedSourcePatients)));
|
||||
assertEquals(2, getAllSourcePatients().size());
|
||||
assertEquals(1, getAllActiveSourcePatients().size());
|
||||
}
|
||||
|
||||
private Person mergePersons() {
|
||||
private Patient mergeSourcePatients() {
|
||||
assertEquals(0, redirectLinkCount());
|
||||
Person retval = (Person) myEmpiPersonMergerSvc.mergePersons(myFromSourcePatient, myToSourcePatient, createEmpiContext());
|
||||
Patient retval = (Patient) myEmpiPersonMergerSvc.mergePersons(myFromSourcePatient, myToSourcePatient, createEmpiContext());
|
||||
assertEquals(1, redirectLinkCount());
|
||||
return retval;
|
||||
}
|
||||
|
@ -129,7 +128,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
assertEquals(EmpiMatchResultEnum.POSSIBLE_DUPLICATE, foundLinks.get(0).getMatchResult());
|
||||
}
|
||||
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
|
||||
{
|
||||
List<EmpiLink> foundLinks = myEmpiLinkDao.findAll();
|
||||
|
@ -142,11 +141,11 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
public void fullFromEmptyTo() {
|
||||
populatePerson(myFromSourcePatient);
|
||||
|
||||
Person mergedPerson = mergePersons();
|
||||
HumanName returnedName = mergedPerson.getNameFirstRep();
|
||||
Patient mergedSourcePatient = mergeSourcePatients();
|
||||
HumanName returnedName = mergedSourcePatient.getNameFirstRep();
|
||||
assertEquals(GIVEN_NAME, returnedName.getGivenAsSingleString());
|
||||
assertEquals(FAMILY_NAME, returnedName.getFamily());
|
||||
assertEquals(POSTAL_CODE, mergedPerson.getAddressFirstRep().getPostalCode());
|
||||
assertEquals(POSTAL_CODE, mergedSourcePatient.getAddressFirstRep().getPostalCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -154,21 +153,21 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
myFromSourcePatient.getName().add(new HumanName().addGiven(BAD_GIVEN_NAME));
|
||||
populatePerson(myToSourcePatient);
|
||||
|
||||
Person mergedPerson = mergePersons();
|
||||
HumanName returnedName = mergedPerson.getNameFirstRep();
|
||||
Patient mergedSourcePatient = mergeSourcePatients();
|
||||
HumanName returnedName = mergedSourcePatient.getNameFirstRep();
|
||||
assertEquals(GIVEN_NAME, returnedName.getGivenAsSingleString());
|
||||
assertEquals(FAMILY_NAME, returnedName.getFamily());
|
||||
assertEquals(POSTAL_CODE, mergedPerson.getAddressFirstRep().getPostalCode());
|
||||
assertEquals(POSTAL_CODE, mergedSourcePatient.getAddressFirstRep().getPostalCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromLinkToNoLink() {
|
||||
createEmpiLink(myFromSourcePatient, myTargetPatient1);
|
||||
|
||||
Person mergedPerson = mergePersons();
|
||||
List<EmpiLink> links = getNonRedirectLinksByPerson(mergedPerson);
|
||||
Patient mergedSourcePatient = mergeSourcePatients();
|
||||
List<EmpiLink> links = getNonRedirectLinksByPerson(mergedSourcePatient);
|
||||
assertEquals(1, links.size());
|
||||
assertThat(mergedPerson, is(possibleLinkedTo(myTargetPatient1)));
|
||||
assertThat(mergedSourcePatient, is(possibleLinkedTo(myTargetPatient1)));
|
||||
assertEquals(1, myToSourcePatient.getLink().size());
|
||||
}
|
||||
|
||||
|
@ -176,10 +175,10 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
public void fromNoLinkToLink() {
|
||||
createEmpiLink(myToSourcePatient, myTargetPatient1);
|
||||
|
||||
Person mergedPerson = mergePersons();
|
||||
List<EmpiLink> links = getNonRedirectLinksByPerson(mergedPerson);
|
||||
Patient mergedSourcePatient = mergeSourcePatients();
|
||||
List<EmpiLink> links = getNonRedirectLinksByPerson(mergedSourcePatient);
|
||||
assertEquals(1, links.size());
|
||||
assertThat(mergedPerson, is(possibleLinkedTo(myTargetPatient1)));
|
||||
assertThat(mergedSourcePatient, is(possibleLinkedTo(myTargetPatient1)));
|
||||
assertEquals(1, myToSourcePatient.getLink().size());
|
||||
}
|
||||
|
||||
|
@ -192,7 +191,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
|
||||
createEmpiLink(myToSourcePatient, myTargetPatient1);
|
||||
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
List<EmpiLink> links = getNonRedirectLinksByPerson(myToSourcePatient);
|
||||
assertEquals(1, links.size());
|
||||
assertEquals(EmpiLinkSourceEnum.MANUAL, links.get(0).getLinkSource());
|
||||
|
@ -214,7 +213,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
|
||||
createEmpiLink(myToSourcePatient, myTargetPatient1);
|
||||
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
List<EmpiLink> links = getNonRedirectLinksByPerson(myToSourcePatient);
|
||||
assertEquals(1, links.size());
|
||||
assertEquals(EmpiLinkSourceEnum.MANUAL, links.get(0).getLinkSource());
|
||||
|
@ -229,7 +228,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
toLink.setMatchResult(EmpiMatchResultEnum.NO_MATCH);
|
||||
saveLink(toLink);
|
||||
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
List<EmpiLink> links = getNonRedirectLinksByPerson(myToSourcePatient);
|
||||
assertEquals(1, links.size());
|
||||
assertEquals(EmpiLinkSourceEnum.MANUAL, links.get(0).getLinkSource());
|
||||
|
@ -248,7 +247,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
saveLink(toLink);
|
||||
|
||||
try {
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("A MANUAL NO_MATCH link may not be merged into a MANUAL MATCH link for the same target", e.getMessage());
|
||||
|
@ -268,7 +267,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
saveLink(toLink);
|
||||
|
||||
try {
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("A MANUAL MATCH link may not be merged into a MANUAL NO_MATCH link for the same target", e.getMessage());
|
||||
|
@ -287,7 +286,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
toLink.setMatchResult(EmpiMatchResultEnum.MATCH);
|
||||
saveLink(toLink);
|
||||
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
assertEquals(1, myToSourcePatient.getLink().size());
|
||||
assertEquals(3, myEmpiLinkDao.count());
|
||||
}
|
||||
|
@ -299,7 +298,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
createEmpiLink(myFromSourcePatient, myTargetPatient3);
|
||||
createEmpiLink(myToSourcePatient, myTargetPatient1);
|
||||
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
myEmpiLinkHelper.logEmpiLinks();
|
||||
|
||||
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
||||
|
@ -313,7 +312,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
createEmpiLink(myToSourcePatient, myTargetPatient2);
|
||||
createEmpiLink(myToSourcePatient, myTargetPatient3);
|
||||
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
myEmpiLinkHelper.logEmpiLinks();
|
||||
|
||||
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
||||
|
@ -329,7 +328,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
createEmpiLink(myToSourcePatient, myTargetPatient2);
|
||||
createEmpiLink(myToSourcePatient, myTargetPatient3);
|
||||
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
myEmpiLinkHelper.logEmpiLinks();
|
||||
|
||||
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
||||
|
@ -343,7 +342,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
createEmpiLink(myToSourcePatient, myTargetPatient2);
|
||||
createEmpiLink(myToSourcePatient, myTargetPatient3);
|
||||
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
myEmpiLinkHelper.logEmpiLinks();
|
||||
|
||||
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
||||
|
@ -362,10 +361,10 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
assertThat(myToSourcePatient.getName(), hasSize(1));
|
||||
assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
||||
|
||||
Person mergedPerson = mergePersons();
|
||||
assertThat(mergedPerson.getName(), hasSize(2));
|
||||
assertThat(mergedPerson.getName().get(0).getGiven(), hasSize(2));
|
||||
assertThat(mergedPerson.getName().get(1).getGiven(), hasSize(2));
|
||||
Patient mergedSourcePatient = mergeSourcePatients();
|
||||
assertThat(mergedSourcePatient.getName(), hasSize(2));
|
||||
assertThat(mergedSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
||||
assertThat(mergedSourcePatient.getName().get(1).getGiven(), hasSize(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -380,7 +379,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
assertThat(myToSourcePatient.getName(), hasSize(1));
|
||||
assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
||||
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
assertThat(myToSourcePatient.getName(), hasSize(1));
|
||||
assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
||||
}
|
||||
|
@ -395,7 +394,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
|||
myToSourcePatient.addIdentifier().setValue("ccc");
|
||||
assertThat(myToSourcePatient.getIdentifier(), hasSize(2));
|
||||
|
||||
mergePersons();
|
||||
mergeSourcePatients();
|
||||
assertThat(myToSourcePatient.getIdentifier(), hasSize(3));
|
||||
}
|
||||
|
||||
|
|
|
@ -38,12 +38,10 @@ import ca.uhn.fhir.rest.server.provider.ProviderConstants;
|
|||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
||||
import ca.uhn.fhir.util.ParametersUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.CodeType;
|
||||
import org.hl7.fhir.r4.model.DecimalType;
|
||||
import org.hl7.fhir.r4.model.Extension;
|
||||
import org.hl7.fhir.r4.model.InstantType;
|
||||
import org.hl7.fhir.r4.model.IntegerType;
|
||||
import org.hl7.fhir.r4.model.Parameters;
|
||||
|
@ -54,7 +52,6 @@ import org.hl7.fhir.r4.model.Resource;
|
|||
import org.hl7.fhir.r4.model.StringType;
|
||||
import org.hl7.fhir.r4.model.codesystems.MatchGrade;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -126,6 +123,7 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
|
|||
return searchComponent;
|
||||
}
|
||||
|
||||
//TODO GGG ask ken, what is the best way to genericize this? Return Parameters??
|
||||
@Operation(name = ProviderConstants.EMPI_MERGE_PERSONS, type = Person.class)
|
||||
public Person mergePersons(@OperationParam(name=ProviderConstants.EMPI_MERGE_PERSONS_FROM_PERSON_ID, min = 1, max = 1) StringType theFromPersonId,
|
||||
@OperationParam(name=ProviderConstants.EMPI_MERGE_PERSONS_TO_PERSON_ID, min = 1, max = 1) StringType theToPersonId,
|
||||
|
|
Loading…
Reference in New Issue