Flesh out tests
@@ -2,6 +2,8 @@ package ca.uhn.fhir.jpa.empi.provider;
import ca.uhn.fhir.jpa.entity.EmpiLink;
import ca.uhn.fhir.model.primitive.IdDt;
+import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
+import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.hl7.fhir.r4.model.Person;
import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.StringType;
@@ -15,19 +17,24 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.jupiter.api.Assertions.fail;
public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
protected Practitioner myPractitioner;
protected StringType myPractitionerId;
+ protected Person myPractitionerPerson;
+ protected StringType myPractitionerPersonId;
@BeforeEach
public void before() {
super.before();
myPractitioner = createPractitionerAndUpdateLinks(new Practitioner());
myPractitionerId = new StringType(myPractitioner.getIdElement().getValue());
+ myPractitionerPerson = getPersonFromTarget(myPractitioner);
+ myPractitionerPersonId = new StringType(myPractitionerPerson.getIdElement().getValue());
}
@Test
@@ -54,24 +61,36 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
public void testClearPatientLinks() {
assertLinkCount(2);
+ Person read = myPersonDao.read(new IdDt(myPersonId.getValueAsString()).toVersionless());
+ assertThat(read, is(notNullValue()));
myEmpiProviderR4.clearEmpiLinks(new StringType("patient"));
assertNoPatientLinksExist();
- Person read = myPersonDao.read(new IdDt(myPersonId.getValueAsString()).toVersionless());
- assertThat(read, is(equalTo(nullValue())));
+ try {
+ myPersonDao.read(new IdDt(myPersonId.getValueAsString()).toVersionless());
+ fail();
+ } catch (ResourceNotFoundException e) {}
+
}
@Test
public void testClearPractitionerLinks() {
assertLinkCount(2);
- myEmpiProviderR4.clearEmpiLinks(new StringType("patient"));
+ myEmpiProviderR4.clearEmpiLinks(new StringType("practitioner"));
assertNoPractitionerLinksExist();
+ try {
+ myPersonDao.read(new IdDt(myPractitionerPersonId.getValueAsString()).toVersionless());
+ fail();
+ } catch (ResourceNotFoundException e) {}
}
@Test
public void testClearInvalidTargetType() {
- myEmpiProviderR4.updateLink(myPersonId, myPatientId, MATCH_RESULT, myRequestDetails);
- Person person = myEmpiProviderR4.updateLink(myVersionlessPersonId, myPatientId, NO_MATCH_RESULT, myRequestDetails);
- assertThat(person.getLink(), hasSize(0));
+ try {
+ myEmpiProviderR4.clearEmpiLinks(new StringType("observation"));
+ fail();
+ } catch (InvalidRequestException e) {
+ assertThat(e.getMessage(), is(equalTo("$empi-clear does not support resource type: observation")));
+ }
}
