Search in sources :

Example 21 with OperationOutcome

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

the class ResourceProviderUtil method updateResource.

protected <T extends BaseResource, U extends Identifiable> MethodOutcome updateResource(IdType theId, IFhirTransformer<T, U> transformer, T fhirObject, Logger log) {
    String versionId = theId.getVersionIdPart();
    Optional<U> localObject = transformer.getLocalObject(fhirObject);
    MethodOutcome outcome = new MethodOutcome();
    if (localObject.isPresent()) {
        if (versionId == null) {
            log.warn("Version agnostic update on {}", localObject.get());
        }
        if (versionId != null && !versionId.equals(localObject.get().getLastupdate().toString())) {
            throw new ResourceVersionConflictException("Expected version " + localObject.get().getLastupdate().toString());
        }
        try {
            transformer.updateLocalObject(fhirObject, localObject.get());
        } catch (IFhirTransformerException e) {
            OperationOutcome opOutcome = generateOperationOutcome(e);
            throw new PreconditionFailedException(e.getMessage(), opOutcome);
        }
        Optional<T> updatedObject = transformer.getFhirObject(localObject.get());
        if (updatedObject.isPresent()) {
            outcome.setId(updatedObject.get().getIdElement());
            outcome.setResource(updatedObject.get());
            return outcome;
        }
        log.warn("Object update failed [{}]", fhirObject);
        throw new InternalErrorException("Object update failed");
    } else {
        OperationOutcome issueOutcome = new OperationOutcome();
        issueOutcome.addIssue().setDiagnostics("No local object found");
        outcome.setOperationOutcome(issueOutcome);
    }
    return outcome;
}
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) ResourceVersionConflictException(ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome)

Example 22 with OperationOutcome

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

the class IContactSearchFilterQueryAdapter method generateOperationOutcome.

private OperationOutcome generateOperationOutcome(Exception e) {
    OperationOutcome opOutcome = new OperationOutcome();
    OperationOutcomeIssueComponent ooc = new OperationOutcomeIssueComponent();
    OperationOutcome.IssueSeverity severity = OperationOutcome.IssueSeverity.ERROR;
    ooc.setSeverity(severity);
    ooc.setCode(IssueType.PROCESSING);
    ooc.setDiagnostics("_filter parameter: " + e.getMessage());
    opOutcome.addIssue(ooc);
    return opOutcome;
}
Also used : OperationOutcomeIssueComponent(org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome)

Example 23 with OperationOutcome

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

the class IContactSearchFilterQueryAdapter method adapt.

public void adapt(IQuery<? extends IContact> query, StringAndListParam theFtFilter) {
    List<StringOrListParam> stringOrListParams = theFtFilter.getValuesAsQueryTokens();
    if (!stringOrListParams.isEmpty()) {
        List<StringParam> stringParams = stringOrListParams.get(0).getValuesAsQueryTokens();
        if (!stringParams.isEmpty()) {
            StringParam stringParam = stringParams.get(0);
            try {
                Filter filter = SearchFilterParser.parse(stringParam.getValue());
                handleFilter(query, filter, 1);
            } catch (FilterSyntaxException | IllegalArgumentException e) {
                OperationOutcome opOutcome = generateOperationOutcome(e);
                throw new PreconditionFailedException(e.getMessage(), opOutcome);
            }
        }
    }
}
Also used : Filter(es.fhir.rest.core.resources.util.SearchFilterParser.Filter) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) FilterSyntaxException(es.fhir.rest.core.resources.util.SearchFilterParser.FilterSyntaxException) PreconditionFailedException(ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException) StringParam(ca.uhn.fhir.rest.param.StringParam) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam)

Example 24 with OperationOutcome

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

the class AllergyIntoleranceFhirResourceProviderTest method deleteAllergyIntolerance_shouldDeleteRequestedAllergyIntolerance.

@Test
public void deleteAllergyIntolerance_shouldDeleteRequestedAllergyIntolerance() {
    when(service.delete(ALLERGY_UUID)).thenReturn(allergyIntolerance);
    OperationOutcome result = resourceProvider.deleteAllergy(new IdType().setValue(ALLERGY_UUID));
    assertThat(result, notNullValue());
    assertThat(result.getIssue(), notNullValue());
    assertThat(result.getIssueFirstRep().getSeverity(), equalTo(OperationOutcome.IssueSeverity.INFORMATION));
    assertThat(result.getIssueFirstRep().getDetails().getCodingFirstRep().getCode(), equalTo("MSG_DELETED"));
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) IdType(org.hl7.fhir.r4.model.IdType) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 25 with OperationOutcome

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

the class DiagnosticReportFhirResourceProviderTest method deleteDiagnosticReport_shouldDeleteRequestedDiagnosticReport.

@Test
public void deleteDiagnosticReport_shouldDeleteRequestedDiagnosticReport() {
    when(service.delete(UUID)).thenReturn(diagnosticReport);
    OperationOutcome result = resourceProvider.deleteDiagnosticReport(new IdType().setValue(UUID));
    assertThat(result, notNullValue());
    assertThat(result.getIssue(), notNullValue());
    assertThat(result.getIssueFirstRep().getSeverity(), equalTo(OperationOutcome.IssueSeverity.INFORMATION));
    assertThat(result.getIssueFirstRep().getDetails().getCodingFirstRep().getCode(), equalTo("MSG_DELETED"));
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) IdType(org.hl7.fhir.r4.model.IdType) 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