use of org.hl7.fhir.r4.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);
}
use of org.hl7.fhir.r4.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);
}
use of org.hl7.fhir.r4.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);
}
use of org.hl7.fhir.r4.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);
}
use of org.hl7.fhir.r4.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");
}
Aggregations