Search in sources :

Example 16 with OperationOutcome

use of org.hl7.fhir.r5.model.OperationOutcome in project summary-care-record-api by NHSDigital.

the class ScrTest method verifyOperationOutcome.

private void verifyOperationOutcome(String responseBody, IssueType code, IssueSeverity severity) {
    var response = parser.parseResource(responseBody);
    assertThat(response).isInstanceOf(OperationOutcome.class);
    OperationOutcome operationOutcome = (OperationOutcome) response;
    assertThat(operationOutcome.getIssueFirstRep().getCode()).isEqualTo(code);
    assertThat(operationOutcome.getIssueFirstRep().getSeverity()).isEqualTo(severity);
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome)

Example 17 with OperationOutcome

use of org.hl7.fhir.r5.model.OperationOutcome in project summary-care-record-api by NHSDigital.

the class OperationOutcomeExceptionHandler method handleMethodArgumentTypeMismatch.

@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public ResponseEntity<Object> handleMethodArgumentTypeMismatch(MethodArgumentTypeMismatchException ex) {
    String responseMessage = String.format("Invalid value - %s in field '%s'", ex.getValue(), ex.getName());
    OperationOutcome operationOutcome = createOperationOutcome(VALUE, ERROR, responseMessage);
    return errorResponse(new HttpHeaders(), BAD_REQUEST, operationOutcome);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) OperationOutcomeUtils.createOperationOutcome(uk.nhs.adaptors.scr.utils.OperationOutcomeUtils.createOperationOutcome) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseEntityExceptionHandler(org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)

Example 18 with OperationOutcome

use of org.hl7.fhir.r5.model.OperationOutcome in project summary-care-record-api by NHSDigital.

the class OperationOutcomeExceptionHandler method handleAllExceptions.

@ExceptionHandler(Exception.class)
public ResponseEntity<Object> handleAllExceptions(Exception ex) {
    LOGGER.error("Error occurred: {}", ex.getMessage());
    OperationOutcome operationOutcome;
    HttpStatus httpStatus;
    if (ex instanceof OperationOutcomeError) {
        OperationOutcomeError error = (OperationOutcomeError) ex;
        operationOutcome = error.getOperationOutcome();
        httpStatus = error.getStatusCode();
    } else {
        operationOutcome = createOperationOutcome(EXCEPTION, ERROR, ex.getMessage());
        httpStatus = INTERNAL_SERVER_ERROR;
    }
    return errorResponse(new HttpHeaders(), httpStatus, operationOutcome);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpStatus(org.springframework.http.HttpStatus) OperationOutcomeUtils.createOperationOutcome(uk.nhs.adaptors.scr.utils.OperationOutcomeUtils.createOperationOutcome) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) OperationOutcomeError(uk.nhs.adaptors.scr.exceptions.OperationOutcomeError) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseEntityExceptionHandler(org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)

Example 19 with OperationOutcome

use of org.hl7.fhir.r5.model.OperationOutcome in project quality-measure-and-cohort-service by Alvearie.

the class MeasureImporterTest method testImportBundleFailure400.

@Test
public void testImportBundleFailure400() throws Exception {
    String expectedRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/simple_age_measure_v2_2_2-request.json")), StandardCharsets.UTF_8);
    OperationOutcome outcome = new OperationOutcome();
    outcome.getText().setDivAsString("<div>Something went wrong</div>");
    String expectedResponse = getFhirParser().encodeResourceToString(outcome);
    roundTripTest("src/test/resources/simple_age_measure_v2_2_2.zip", expectedRequest, expectedResponse, 400, 1);
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Test(org.junit.Test)

Example 20 with OperationOutcome

use of org.hl7.fhir.r5.model.OperationOutcome in project elexis-server by elexis.

the class ResourceProviderUtil method createResource.

/**
 * @param transformer
 * @param fhirObject
 * @param log
 * @return TODO Support conditional create http://hl7.org/fhir/http.html#ccreate
 */
protected <T extends BaseResource, U extends Identifiable> MethodOutcome createResource(IFhirTransformer<T, U> transformer, T fhirObject, Logger log) {
    Optional<U> created;
    try {
        created = transformer.createLocalObject(fhirObject);
        if (created.isPresent()) {
            Optional<T> updated = transformer.getFhirObject(created.get());
            if (updated.isPresent()) {
                MethodOutcome outcome = new MethodOutcome();
                outcome.setCreated(true);
                outcome.setId(updated.get().getIdElement());
                outcome.setResource(updated.get());
                return outcome;
            }
        }
    } catch (IFhirTransformerException e) {
        OperationOutcome opOutcome = generateOperationOutcome(e);
        throw new PreconditionFailedException(e.getMessage(), opOutcome);
    }
    log.warn("Object creation failed [{}]", fhirObject);
    throw new InternalErrorException("Creation failed");
}
Also used : IFhirTransformerException(ch.elexis.core.findings.util.fhir.IFhirTransformerException) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) PreconditionFailedException(ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome)

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