Search in sources :

Example 86 with OperationOutcome

use of org.hl7.fhir.r4b.model.OperationOutcome in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchAllergyIdAsJson.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchAllergyIdAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.JSON).go();
    AllergyIntolerance allergy = readResponse(response);
    // update the existing record
    allergy.setId(UNKNOWN_ALLERGY_UUID);
    // send the update to the server
    response = put("/AllergyIntolerance/" + ALLERGY_UUID).jsonContent(toJson(allergy)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isBadRequest());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 87 with OperationOutcome

use of org.hl7.fhir.r4b.model.OperationOutcome in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchAllergyIdAsXML.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchAllergyIdAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.XML).go();
    AllergyIntolerance allergy = readResponse(response);
    // update the existing record
    allergy.setId(UNKNOWN_ALLERGY_UUID);
    // send the update to the server
    response = put("/AllergyIntolerance/" + ALLERGY_UUID).xmlContent(toXML(allergy)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isBadRequest());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 88 with OperationOutcome

use of org.hl7.fhir.r4b.model.OperationOutcome in project openmrs-module-fhir2 by openmrs.

the class BaseFhirR4IntegrationTest method describeOperationOutcome.

@Override
public void describeOperationOutcome(Description mismatchDescription, IBaseOperationOutcome baseOperationOutcome) {
    if (baseOperationOutcome instanceof OperationOutcome) {
        OperationOutcome operationOutcome = (OperationOutcome) baseOperationOutcome;
        if (operationOutcome.hasIssue()) {
            mismatchDescription.appendText(" with message ");
            mismatchDescription.appendValue(operationOutcome.getIssue().stream().map(OperationOutcome.OperationOutcomeIssueComponent::getDiagnostics).collect(Collectors.joining(". ")));
        }
    }
}
Also used : IBaseOperationOutcome(org.hl7.fhir.instance.model.api.IBaseOperationOutcome) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome)

Example 89 with OperationOutcome

use of org.hl7.fhir.r4b.model.OperationOutcome in project openmrs-module-fhir2 by openmrs.

the class ConditionFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenConditionNotFoundAsXML.

@Test
public void shouldReturnNotFoundWhenConditionNotFoundAsXML() throws Exception {
    MockHttpServletResponse response = get("/Condition/" + WRONG_CONDITION_UUID).accept(FhirMediaTypes.XML).go();
    assertThat(response, isNotFound());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 90 with OperationOutcome

use of org.hl7.fhir.r4b.model.OperationOutcome in project openmrs-module-fhir2 by openmrs.

the class ConditionFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentConditionAsJson.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentConditionAsJson() throws Exception {
    MockHttpServletResponse response = get("/Condition/" + CONDITION_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Condition condition = readResponse(response);
    condition.setId(WRONG_CONDITION_UUID);
    response = put("/Condition/" + WRONG_CONDITION_UUID).jsonContent(toJson(condition)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isNotFound());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)214 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)181 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)161 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)144 Test (org.junit.jupiter.api.Test)42 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)31 IOException (java.io.IOException)26 IBaseOperationOutcome (org.hl7.fhir.instance.model.api.IBaseOperationOutcome)24 OperationOutcomeIssueComponent (org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent)23 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)22 OperationOutcome (org.hl7.fhir.r5.model.OperationOutcome)20 IdType (org.hl7.fhir.dstu3.model.IdType)17 IdType (org.hl7.fhir.r4.model.IdType)17 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)15 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 URISyntaxException (java.net.URISyntaxException)13 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 Header (org.apache.http.Header)11