Search in sources :

Example 1 with MeasureParameterInfo

use of com.ibm.cohort.engine.api.service.model.MeasureParameterInfo 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 2 with MeasureParameterInfo

use of com.ibm.cohort.engine.api.service.model.MeasureParameterInfo 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 3 with MeasureParameterInfo

use of com.ibm.cohort.engine.api.service.model.MeasureParameterInfo in project quality-measure-and-cohort-service by Alvearie.

the class FHIRRestUtilsTest method testGetParametersForMeasureIdentifier.

/**
 * Test the successful building of a response.
 */
@Test
public void testGetParametersForMeasureIdentifier() {
    String idValue = "idValue";
    String idSystem = "idSystem";
    Identifier identifier = new Identifier().setValue(idValue).setSystem(idSystem);
    String version = "1.0.0";
    FhirResourceResolver<Measure> measureResolver = Mockito.mock(FhirResourceResolver.class);
    Mockito.when(measureResolver.resolveByIdentifier(idValue, idSystem, version)).thenReturn(createMeasure(testMeasureDef));
    List<MeasureParameterInfo> parameterInfoList = FHIRRestUtils.getParametersForMeasureIdentifier(measureResolver, identifier, version);
    MeasureParameterInfo expectedParamInfo = new MeasureParameterInfo();
    expectedParamInfo.setname("aName");
    expectedParamInfo.setUse("In");
    expectedParamInfo.setMax("1");
    expectedParamInfo.setMin(0);
    expectedParamInfo.setType("String");
    expectedParamInfo.setDocumentation(null);
    expectedParamInfo.defaultValue("42");
    assertThat(parameterInfoList, containsInAnyOrder(expectedParamInfo));
}
Also used : MeasureParameterInfo(com.ibm.cohort.engine.api.service.model.MeasureParameterInfo) Identifier(org.hl7.fhir.r4.model.Identifier) Measure(org.hl7.fhir.r4.model.Measure) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with MeasureParameterInfo

use of com.ibm.cohort.engine.api.service.model.MeasureParameterInfo in project quality-measure-and-cohort-service by Alvearie.

the class FHIRRestUtilsTest method testGetParametersWithDefaultsForMeasureId.

@Test
public void testGetParametersWithDefaultsForMeasureId() {
    String measureId = "measureId";
    FhirResourceResolver<Measure> measureResolver = Mockito.mock(FhirResourceResolver.class);
    Mockito.when(measureResolver.resolveById(measureId)).thenReturn(createMeasure(testMeasureDef));
    List<MeasureParameterInfo> parameterInfoList = FHIRRestUtils.getParametersForMeasureId(measureResolver, measureId);
    MeasureParameterInfo expectedParamInfo = new MeasureParameterInfo();
    expectedParamInfo.setname("aName");
    expectedParamInfo.setUse("In");
    expectedParamInfo.setMax("1");
    expectedParamInfo.setMin(0);
    expectedParamInfo.setType("String");
    expectedParamInfo.setDocumentation(null);
    expectedParamInfo.defaultValue("42");
    assertThat(parameterInfoList, containsInAnyOrder(expectedParamInfo));
}
Also used : MeasureParameterInfo(com.ibm.cohort.engine.api.service.model.MeasureParameterInfo) Measure(org.hl7.fhir.r4.model.Measure) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with MeasureParameterInfo

use of com.ibm.cohort.engine.api.service.model.MeasureParameterInfo in project quality-measure-and-cohort-service by Alvearie.

the class FHIRRestUtils method toMeasureParameterInfo.

private static MeasureParameterInfo toMeasureParameterInfo(ParameterDefinition parameterDefinition) {
    MeasureParameterInfo retVal = new MeasureParameterInfo();
    String defaultValue = complicatedTypes.contains(parameterDefinition.getType()) ? complicatedTypeValueConstructor(parameterDefinition) : null;
    retVal.name(parameterDefinition.getName()).type(parameterDefinition.getType()).min(parameterDefinition.getMin()).max(parameterDefinition.getMax()).documentation(parameterDefinition.getDocumentation());
    Optional.ofNullable(parameterDefinition.getUse()).map(ParameterUse::getDisplay).ifPresent(retVal::setUse);
    parameterDefinition.getExtension().stream().filter(MeasureEvaluationSeeder::isDefaultValue).findFirst().map(Extension::getValue).map(x -> {
        if (defaultValue != null) {
            return defaultValue;
        } else
            return x.toString();
    }).ifPresent(retVal::setDefaultValue);
    return retVal;
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Identifier(org.hl7.fhir.r4.model.Identifier) IBMFhirServerConfig(com.ibm.cohort.fhir.client.config.IBMFhirServerConfig) Range(org.hl7.fhir.r4.model.Range) Measure(org.hl7.fhir.r4.model.Measure) ArrayList(java.util.ArrayList) FhirContext(ca.uhn.fhir.context.FhirContext) FhirVersionEnum(ca.uhn.fhir.context.FhirVersionEnum) JsonNode(com.fasterxml.jackson.databind.JsonNode) Quantity(org.hl7.fhir.r4.model.Quantity) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) MeasureParameterInfo(com.ibm.cohort.engine.api.service.model.MeasureParameterInfo) FhirResourceResolver(com.ibm.cohort.cql.fhir.resolver.FhirResourceResolver) Patient(org.hl7.fhir.r4.model.Patient) IParser(ca.uhn.fhir.parser.IParser) ParameterUse(org.hl7.fhir.r4.model.ParameterDefinition.ParameterUse) Period(org.hl7.fhir.r4.model.Period) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultFhirClientBuilder(com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Collectors(java.util.stream.Collectors) Base64(java.util.Base64) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Optional(java.util.Optional) MeasureEvaluationSeeder(com.ibm.cohort.engine.measure.seed.MeasureEvaluationSeeder) Extension(org.hl7.fhir.r4.model.Extension) MeasureParameterInfo(com.ibm.cohort.engine.api.service.model.MeasureParameterInfo) MeasureEvaluationSeeder(com.ibm.cohort.engine.measure.seed.MeasureEvaluationSeeder)

Aggregations

MeasureParameterInfo (com.ibm.cohort.engine.api.service.model.MeasureParameterInfo)6 Measure (org.hl7.fhir.r4.model.Measure)6 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Identifier (org.hl7.fhir.r4.model.Identifier)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 MeasureParameterInfoList (com.ibm.cohort.engine.api.service.model.MeasureParameterInfoList)2 FhirClientBuilder (com.ibm.cohort.fhir.client.config.FhirClientBuilder)2 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)2 IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)2 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponse (io.swagger.annotations.ApiResponse)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2