Search in sources :

Example 6 with Attachment

use of org.hl7.fhir.r4b.model.Attachment in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveDiagnosticReport.

private DiagnosticReport resolveDiagnosticReport(ActivityDefinition activityDefinition, String patientId) {
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.UNKNOWN);
    diagnosticReport.setSubject(new Reference(patientId));
    if (activityDefinition.hasCode()) {
        diagnosticReport.setCode(activityDefinition.getCode());
    } else {
        throw new ActivityDefinitionApplyException("Missing required ActivityDefinition.code property for DiagnosticReport");
    }
    if (activityDefinition.hasRelatedArtifact()) {
        List<Attachment> presentedFormAttachments = new ArrayList<>();
        for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
            Attachment attachment = new Attachment();
            if (artifact.hasUrl()) {
                attachment.setUrl(artifact.getUrl());
            }
            if (artifact.hasDisplay()) {
                attachment.setTitle(artifact.getDisplay());
            }
            presentedFormAttachments.add(attachment);
        }
        diagnosticReport.setPresentedForm(presentedFormAttachments);
    }
    return diagnosticReport;
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) Attachment(org.hl7.fhir.dstu3.model.Attachment) RelatedArtifact(org.hl7.fhir.dstu3.model.RelatedArtifact)

Example 7 with Attachment

use of org.hl7.fhir.r4b.model.Attachment in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveCommunication.

private Communication resolveCommunication(ActivityDefinition activityDefinition, String patientId) {
    Communication communication = new Communication();
    communication.setStatus(Communication.CommunicationStatus.UNKNOWN);
    communication.setSubject(new Reference(patientId));
    if (activityDefinition.hasCode()) {
        communication.setReasonCode(Collections.singletonList(activityDefinition.getCode()));
    }
    if (activityDefinition.hasRelatedArtifact()) {
        for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
            if (artifact.hasUrl()) {
                Attachment attachment = new Attachment().setUrl(artifact.getUrl());
                if (artifact.hasDisplay()) {
                    attachment.setTitle(artifact.getDisplay());
                }
                Communication.CommunicationPayloadComponent payload = new Communication.CommunicationPayloadComponent();
                payload.setContent(artifact.hasDisplay() ? attachment.setTitle(artifact.getDisplay()) : attachment);
                communication.setPayload(Collections.singletonList(payload));
            }
        // TODO - other relatedArtifact types
        }
    }
    return communication;
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) Attachment(org.hl7.fhir.dstu3.model.Attachment) RelatedArtifact(org.hl7.fhir.dstu3.model.RelatedArtifact) Communication(org.hl7.fhir.dstu3.model.Communication)

Example 8 with Attachment

use of org.hl7.fhir.r4b.model.Attachment in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveCommunication.

private Communication resolveCommunication(ActivityDefinition activityDefinition, String patientId) {
    Communication communication = new Communication();
    communication.setStatus(Communication.CommunicationStatus.UNKNOWN);
    communication.setSubject(new Reference(patientId));
    if (activityDefinition.hasCode()) {
        communication.setReasonCode(Collections.singletonList(activityDefinition.getCode()));
    }
    if (activityDefinition.hasRelatedArtifact()) {
        for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
            if (artifact.hasUrl()) {
                Attachment attachment = new Attachment().setUrl(artifact.getUrl());
                if (artifact.hasDisplay()) {
                    attachment.setTitle(artifact.getDisplay());
                }
                Communication.CommunicationPayloadComponent payload = new Communication.CommunicationPayloadComponent();
                payload.setContent(artifact.hasDisplay() ? attachment.setTitle(artifact.getDisplay()) : attachment);
                communication.setPayload(Collections.singletonList(payload));
            }
        // TODO - other relatedArtifact types
        }
    }
    return communication;
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) Attachment(org.hl7.fhir.r4.model.Attachment) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) Communication(org.hl7.fhir.r4.model.Communication)

Example 9 with Attachment

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

the class CohortEngineRestHandler method getMeasureParametersById.

@POST
@Path("/fhir/measure/{measure_id}/parameters")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(value = "Get measure parameters by id", notes = CohortEngineRestHandler.MEASURE_API_NOTES, response = MeasureParameterInfoList.class, nickname = "get_measure_parameters_by_id", 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 getMeasureParametersById(@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_ID_DESC, required = true) @PathParam(CohortEngineRestHandler.MEASURE_ID) String measureId) {
    final String methodName = MethodNames.GET_MEASURE_PARAMETERS_BY_ID.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);
        // 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.getParametersForMeasureId(measureResolver, measureId);
        // 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) 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 10 with Attachment

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

the class CohortEngineRestHandler method evaluateMeasure.

@POST
@Path("/evaluation")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Evaluates a measure bundle for a single patient", notes = EVALUATION_API_NOTES, response = String.class, tags = { "Measure Evaluation" }, nickname = "evaluate_measure", extensions = { @Extension(properties = { @ExtensionProperty(name = DarkFeatureSwaggerFilter.DARK_FEATURE_NAME, value = CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION) }) })
@ApiImplicitParams({ // This is necessary for the dark launch feature
@ApiImplicitParam(access = DarkFeatureSwaggerFilter.DARK_FEATURE_CONTROLLED, paramType = "header", dataType = "string"), // These are necessary to create a proper view of the request body that is all wrapped up in the Liberty IMultipartBody parameter
@ApiImplicitParam(name = REQUEST_DATA_PART, value = EXAMPLE_REQUEST_DATA_JSON, dataTypeClass = MeasureEvaluation.class, required = true, paramType = "form", type = "file"), @ApiImplicitParam(name = MEASURE_PART, value = EXAMPLE_MEASURE_ZIP, dataTypeClass = File.class, required = true, paramType = "form", type = "file") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful Operation: This API returns the JSON representation of a FHIR MeasureReport. A full example can be found at https://www.hl7.org/fhir/measurereport-cms146-cat1-example.html"), @ApiResponse(code = 400, message = "Bad Request", response = ServiceErrorList.class), @ApiResponse(code = 500, message = "Server Error", response = ServiceErrorList.class) })
public Response evaluateMeasure(@Context HttpServletRequest request, @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) {
    final String methodName = MethodNames.EVALUATE_MEASURE.getName();
    Response response = null;
    // Error out if feature is not enabled
    ServiceBaseUtility.isDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION);
    try {
        // Perform api setup
        Response errorResponse = ServiceBaseUtility.apiSetup(version, logger, methodName);
        if (errorResponse != null) {
            return errorResponse;
        }
        if (multipartBody == null) {
            throw new IllegalArgumentException("A multipart/form-data body is required");
        }
        IAttachment metadataAttachment = multipartBody.getAttachment(REQUEST_DATA_PART);
        if (metadataAttachment == null) {
            throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", REQUEST_DATA_PART));
        }
        IAttachment measureAttachment = multipartBody.getAttachment(MEASURE_PART);
        if (measureAttachment == null) {
            throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", MEASURE_PART));
        }
        // deserialize the MeasuresEvaluation request
        ObjectMapper om = new ObjectMapper();
        MeasureEvaluation evaluationRequest = om.readValue(metadataAttachment.getDataHandler().getInputStream(), MeasureEvaluation.class);
        // validate the contents of the evaluationRequest
        validateBean(evaluationRequest);
        FhirContext fhirContext = FhirContext.forR4();
        try (InputStream is = measureAttachment.getDataHandler().getInputStream();
            RetrieveCacheContext retrieveCacheContext = new DefaultRetrieveCacheContext()) {
            MeasureEvaluator evaluator = createMeasureEvaluator(is, evaluationRequest.getDataServerConfig(), evaluationRequest.getTerminologyServerConfig(), evaluationRequest.isExpandValueSets(), evaluationRequest.getSearchPageSize(), retrieveCacheContext, fhirContext);
            MeasureReport report = evaluator.evaluatePatientMeasure(evaluationRequest.getPatientId(), evaluationRequest.getMeasureContext(), evaluationRequest.getEvidenceOptions());
            // The default serializer gets into an infinite loop when trying to serialize MeasureReport, so we use the
            // HAPI encoder instead.
            IParser parser = fhirContext.newJsonParser();
            ResponseBuilder responseBuilder = Response.status(Response.Status.OK).header("Content-Type", "application/json").entity(parser.encodeResourceToString(report));
            response = responseBuilder.build();
        }
    } catch (Throwable e) {
        // map any exceptions caught into the proper REST error response objects
        response = new CohortServiceExceptionMapper().toResponse(e);
    } finally {
        // Perform api cleanup
        Response errorResponse = ServiceBaseUtility.apiCleanup(logger, methodName);
        if (errorResponse != null) {
            response = errorResponse;
        }
    }
    return response;
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) MeasureEvaluation(com.ibm.cohort.engine.api.service.model.MeasureEvaluation) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) RetrieveCacheContext(com.ibm.cohort.engine.measure.cache.RetrieveCacheContext) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) MeasureEvaluator(com.ibm.cohort.engine.measure.MeasureEvaluator) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser) Path(javax.ws.rs.Path) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

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