Search in sources :

Example 11 with Attachment

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

the class CohortEngineRestHandler method getMeasureParameters.

@POST
@Path("/fhir/measure/identifier/{measure_identifier_value}/parameters")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(value = "Get measure parameters", notes = CohortEngineRestHandler.MEASURE_API_NOTES, response = MeasureParameterInfoList.class, authorizations = { @Authorization(value = "BasicAuth") }, responseContainer = "List", tags = { "FHIR Measures" })
@ApiImplicitParams({ @ApiImplicitParam(name = FHIR_DATA_SERVER_CONFIG_PART, value = CohortEngineRestHandler.EXAMPLE_DATA_SERVER_CONFIG_JSON, dataTypeClass = FhirServerConfig.class, required = true, paramType = "form", type = "file") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful Operation", response = MeasureParameterInfoList.class), @ApiResponse(code = 400, message = "Bad Request", response = ServiceErrorList.class), @ApiResponse(code = 500, message = "Server Error", response = ServiceErrorList.class) })
public Response getMeasureParameters(@ApiParam(value = ServiceBaseConstants.MINOR_VERSION_DESCRIPTION, required = true, defaultValue = ServiceBuildConstants.DATE) @QueryParam(CohortEngineRestHandler.VERSION) String version, @ApiParam(hidden = true, type = "file", required = true) IMultipartBody multipartBody, @ApiParam(value = CohortEngineRestHandler.MEASURE_IDENTIFIER_VALUE_DESC, required = true) @PathParam(CohortEngineRestHandler.MEASURE_IDENTIFIER_VALUE) String measureIdentifierValue, @ApiParam(value = CohortEngineRestHandler.MEASURE_IDENTIFIER_SYSTEM_DESC, required = false) @QueryParam(CohortEngineRestHandler.MEASURE_IDENTIFIER_SYSTEM) String measureIdentifierSystem, @ApiParam(value = CohortEngineRestHandler.MEASURE_VERSION_DESC, required = false) @QueryParam(CohortEngineRestHandler.MEASURE_VERSION) String measureVersion) {
    final String methodName = MethodNames.GET_MEASURE_PARAMETERS.getName();
    Response response = null;
    try {
        // Perform api setup
        Response errorResponse = ServiceBaseUtility.apiSetup(version, logger, methodName);
        if (errorResponse != null) {
            return errorResponse;
        }
        IAttachment dataSourceAttachment = multipartBody.getAttachment(FHIR_DATA_SERVER_CONFIG_PART);
        if (dataSourceAttachment == null) {
            throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", FHIR_DATA_SERVER_CONFIG_PART));
        }
        // deserialize the MeasuresEvaluation request
        ObjectMapper om = new ObjectMapper();
        FhirServerConfig fhirServerConfig = om.readValue(dataSourceAttachment.getDataHandler().getInputStream(), FhirServerConfig.class);
        // validate the contents of the fhirServerConfig
        validateBean(fhirServerConfig);
        // get the fhir client object used to call to FHIR
        FhirClientBuilder clientBuilder = FhirClientBuilderFactory.newInstance().newFhirClientBuilder();
        IGenericClient measureClient = clientBuilder.createFhirClient(fhirServerConfig);
        // build the identifier object which is used by the fhir client
        // to find the measure
        Identifier identifier = new Identifier().setValue(measureIdentifierValue).setSystem(measureIdentifierSystem);
        // resolve the measure, and return the parameter info for all the libraries linked to by the measure
        FhirResourceResolver<Measure> measureResolver = R4FhirServerResourceResolverFactory.createMeasureResolver(measureClient);
        List<MeasureParameterInfo> parameterInfoList = FHIRRestUtils.getParametersForMeasureIdentifier(measureResolver, identifier, measureVersion);
        // return the results
        MeasureParameterInfoList status = new MeasureParameterInfoList().measureParameterInfoList(parameterInfoList);
        response = Response.ok(status).build();
    } catch (Throwable e) {
        // map any exceptions caught into the proper REST error response objects
        return new CohortServiceExceptionMapper().toResponse(e);
    } finally {
        // Perform api cleanup
        Response errorResponse = ServiceBaseUtility.apiCleanup(logger, methodName);
        if (errorResponse != null) {
            response = errorResponse;
        }
    }
    return response;
}
Also used : MeasureParameterInfo(com.ibm.cohort.engine.api.service.model.MeasureParameterInfo) FhirClientBuilder(com.ibm.cohort.fhir.client.config.FhirClientBuilder) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) Identifier(org.hl7.fhir.r4.model.Identifier) Measure(org.hl7.fhir.r4.model.Measure) MeasureParameterInfoList(com.ibm.cohort.engine.api.service.model.MeasureParameterInfoList) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with Attachment

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

the class FhirTestBase method getLibrary.

protected Library getLibrary(String name, String version, String... attachmentData) throws Exception {
    if (attachmentData == null || attachmentData.length == 0 || (attachmentData.length > 2) && ((attachmentData.length % 2) != 0)) {
        fail("Invalid attachment data. Data must consist of one or more pairs of resource path and content-type strings");
    }
    List<String> pairs = new ArrayList<>(Arrays.asList(attachmentData));
    if (pairs.size() == 1) {
        pairs.add("text/cql");
    }
    List<Attachment> attachments = new ArrayList<>();
    for (int i = 0; i < pairs.size(); i += 2) {
        String resource = pairs.get(i);
        String contentType = pairs.get(i + 1);
        try (InputStream is = ClassLoader.getSystemResourceAsStream(resource)) {
            assertNotNull(String.format("No such resource %s found in classpath", resource), is);
            String text = IOUtils.toString(is, StandardCharsets.UTF_8);
            Attachment attachment = new Attachment();
            attachment.setContentType(contentType);
            attachment.setData(text.getBytes());
            attachments.add(attachment);
        }
    }
    Library library = new Library();
    library.setId("library-" + name + "-" + version);
    library.setName(name);
    library.setUrl(IBM_PREFIX + "/Library/" + name);
    library.setVersion(version);
    library.setContent(attachments);
    return library;
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Attachment(org.hl7.fhir.r4.model.Attachment) Library(org.hl7.fhir.r4.model.Library)

Example 13 with Attachment

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

the class R4ParameterDefinitionWithDefaultToCohortParameterConverterTest method testAttachment__shouldThrowException.

@Test(expected = UnsupportedFhirTypeException.class)
public void testAttachment__shouldThrowException() {
    ParameterDefinition parameterDefinition = getBaseParameterDefinition("Attachment");
    Attachment fhirValue = new Attachment();
    parameterDefinition.addExtension(CDMConstants.PARAMETER_DEFAULT_URL, fhirValue);
    R4ParameterDefinitionWithDefaultToCohortParameterConverter.toCohortParameter(parameterDefinition);
}
Also used : Attachment(org.hl7.fhir.r4.model.Attachment) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Test(org.junit.Test)

Example 14 with Attachment

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

the class R4TranslatingLibraryLoaderTest method withContent.

private void withContent(Library library, String resourcePath, String contentType) throws IOException {
    Attachment attachment = new Attachment();
    attachment.setContentType(contentType);
    attachment.setData(IOUtils.resourceToByteArray(resourcePath));
    library.addContent(attachment);
}
Also used : Attachment(org.hl7.fhir.r4.model.Attachment)

Example 15 with Attachment

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

the class GetScrService method buildDocumentReferenceContent.

private DocumentReferenceContentComponent buildDocumentReferenceContent(String nhsNumber, String scrId) {
    DocumentReferenceContentComponent content = new DocumentReferenceContentComponent();
    String attachmentUrl = String.format(ATTACHMENT_URL, getScrUrl(), scrId, nhsNumber);
    content.setAttachment(new Attachment().setUrl(attachmentUrl));
    return content;
}
Also used : Attachment(org.hl7.fhir.r4.model.Attachment) DocumentReferenceContentComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent)

Aggregations

Attachment (org.hl7.fhir.r4.model.Attachment)33 Reference (org.hl7.fhir.r4.model.Reference)17 ArrayList (java.util.ArrayList)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 Coding (org.hl7.fhir.r4.model.Coding)11 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)10 List (java.util.List)9 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)9 Observation (org.hl7.fhir.r4.model.Observation)9 Test (org.junit.jupiter.api.Test)9 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)8 Resource (org.hl7.fhir.r4.model.Resource)8 FhirContext (ca.uhn.fhir.context.FhirContext)5 HashMap (java.util.HashMap)5 Base64 (org.apache.commons.codec.binary.Base64)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)5 Extension (org.hl7.fhir.r4.model.Extension)5 Library (org.hl7.fhir.r4.model.Library)5