Search in sources :

Example 6 with DefaultRetrieveCacheContext

use of com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandler method evaluatePatientListMeasure.

@POST
@Path("/evaluation-patient-list")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Evaluates a measure bundle for a list of patients", notes = EVALUATION_API_NOTES, response = String.class, tags = { "Measure Evaluation" }, extensions = { @Extension(properties = { @ExtensionProperty(name = DarkFeatureSwaggerFilter.DARK_FEATURE_NAME, value = CohortEngineRestConstants.DARK_LAUNCHED_PATIENT_LIST_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_PATIENT_LIST_MEASURE_REQUEST_DATA_JSON, dataTypeClass = PatientListMeasureEvaluation.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-cat2-example.html"), @ApiResponse(code = 400, message = "Bad Request", response = ServiceErrorList.class), @ApiResponse(code = 500, message = "Server Error", response = ServiceErrorList.class) })
public Response evaluatePatientListMeasure(@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_PATIENT_LIST_MEASURE.getName();
    Response response = null;
    // Error out if feature is not enabled
    ServiceBaseUtility.isDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_PATIENT_LIST_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 PatientListMeasureEvaluation request
        ObjectMapper om = new ObjectMapper();
        PatientListMeasureEvaluation evaluationRequest = om.readValue(metadataAttachment.getDataHandler().getInputStream(), PatientListMeasureEvaluation.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.evaluatePatientListMeasure(evaluationRequest.getPatientIds(), 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) 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) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) 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)

Example 7 with DefaultRetrieveCacheContext

use of com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext in project quality-measure-and-cohort-service by Alvearie.

the class R4MeasureEvaluatorBuilderTest method build_withExpandValueSetsFalse.

@Test
public void build_withExpandValueSetsFalse() throws Exception {
    try (RetrieveCacheContext cacheContext = new DefaultRetrieveCacheContext(new CaffeineConfiguration<>())) {
        MeasureEvaluator evaluator = new R4MeasureEvaluatorBuilder().withClientContext(clientContext).withRetrieveCacheContext(cacheContext).withExpandValueSets(false).build();
        validateMeasureEvaluator(evaluator);
    }
    verify(0, getRequestedFor(urlMatching("/ValueSet/Type2Diabetes/\\$expand.*")));
    verify(0, getRequestedFor(urlMatching("/Condition\\?code=" + DIABETES_CODESYSTEM + ".*")));
    verify(1, getRequestedFor(urlMatching("/Condition\\?code%3Ain=Type2Diabetes.*")));
}
Also used : DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) RetrieveCacheContext(com.ibm.cohort.engine.measure.cache.RetrieveCacheContext) DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) Test(org.junit.Test)

Example 8 with DefaultRetrieveCacheContext

use of com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext in project quality-measure-and-cohort-service by Alvearie.

the class R4MeasureEvaluatorBuilderTest method build_withPageSizeOverride_withExpandValueSetsTrue.

@Test
public void build_withPageSizeOverride_withExpandValueSetsTrue() throws Exception {
    try (RetrieveCacheContext cacheContext = new DefaultRetrieveCacheContext(new CaffeineConfiguration<>())) {
        MeasureEvaluator evaluator = new R4MeasureEvaluatorBuilder().withClientContext(clientContext).withRetrieveCacheContext(cacheContext).withExpandValueSets(true).withPageSize(500).build();
        validateMeasureEvaluator(evaluator);
    }
    verify(1, getRequestedFor(urlMatching("/ValueSet/Type2Diabetes/\\$expand.*")));
    verify(1, getRequestedFor(urlMatching("/Condition\\?code=" + DIABETES_CODESYSTEM + ".*_count=500&_format=json")));
    verify(0, getRequestedFor(urlMatching("/Condition\\?code%3Ain=Type2Diabetes.*_count=500&_format=json")));
}
Also used : DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) RetrieveCacheContext(com.ibm.cohort.engine.measure.cache.RetrieveCacheContext) DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) Test(org.junit.Test)

Example 9 with DefaultRetrieveCacheContext

use of com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext in project quality-measure-and-cohort-service by Alvearie.

the class R4MeasureEvaluatorBuilderTest method build_withCacheContext.

@Test
public void build_withCacheContext() throws Exception {
    try (RetrieveCacheContext cacheContext = new DefaultRetrieveCacheContext(new CaffeineConfiguration<>())) {
        MeasureEvaluator evaluator = new R4MeasureEvaluatorBuilder().withClientContext(clientContext).withRetrieveCacheContext(cacheContext).build();
        validateMeasureEvaluator(evaluator);
    }
    verify(1, getRequestedFor(urlMatching("/ValueSet/Type2Diabetes/.*")));
    verify(1, getRequestedFor(urlMatching("/Condition\\?code=" + DIABETES_CODESYSTEM + ".*")));
    verify(0, getRequestedFor(urlMatching("/Condition\\?code%3Ain=Type2Diabetes.*")));
}
Also used : DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) RetrieveCacheContext(com.ibm.cohort.engine.measure.cache.RetrieveCacheContext) DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) Test(org.junit.Test)

Example 10 with DefaultRetrieveCacheContext

use of com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext in project quality-measure-and-cohort-service by Alvearie.

the class R4DataProviderFactoryTest method createDataProviderMap_withCacheContext.

@Test
public void createDataProviderMap_withCacheContext() throws Exception {
    IGenericClient client = new Builder().withDefaultClient(getFhirServerConfig()).build().getDataClient();
    CqlTerminologyProvider terminologyProvider = new R4RestFhirTerminologyProvider(client);
    try (RetrieveCacheContext cacheContext = new DefaultRetrieveCacheContext(new CaffeineConfiguration<>())) {
        Map<String, CqlDataProvider> map = R4DataProviderFactory.createDataProviderMap(client, terminologyProvider, cacheContext);
        verifyDataProviderMap(map);
    }
}
Also used : IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Builder(com.ibm.cohort.engine.measure.FHIRClientContext.Builder) R4RestFhirTerminologyProvider(com.ibm.cohort.engine.terminology.R4RestFhirTerminologyProvider) DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) RetrieveCacheContext(com.ibm.cohort.engine.measure.cache.RetrieveCacheContext) DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) Test(org.junit.Test)

Aggregations

DefaultRetrieveCacheContext (com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext)10 RetrieveCacheContext (com.ibm.cohort.engine.measure.cache.RetrieveCacheContext)10 Test (org.junit.Test)5 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)4 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)4 R4RestFhirTerminologyProvider (com.ibm.cohort.engine.terminology.R4RestFhirTerminologyProvider)4 IParser (ca.uhn.fhir.parser.IParser)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)3 MeasureEvaluator (com.ibm.cohort.engine.measure.MeasureEvaluator)3 FhirClientBuilderFactory (com.ibm.cohort.fhir.client.config.FhirClientBuilderFactory)3 IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)3 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)3 ApiOperation (io.swagger.annotations.ApiOperation)3 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 JCommander (com.beust.jcommander.JCommander)2 Console (com.beust.jcommander.internal.Console)2 DefaultConsole (com.beust.jcommander.internal.DefaultConsole)2 R4LibraryDependencyGatherer (com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer)2