Search in sources :

Example 1 with EnhancedHealthCheckInput

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

the class CohortEngineRestStatusHandler method getHealthCheckEnhanced.

@POST
@Path("health_check_enhanced")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(value = "Get the status of the cohorting service and dependent downstream services", notes = CohortEngineRestStatusHandler.HEALTH_CHECK_ENHANCED_API_NOTES, response = EnhancedHealthCheckResults.class, nickname = "health_check_enhanced")
@ApiImplicitParams({ @ApiImplicitParam(name = CohortEngineRestStatusHandler.FHIR_SERVER_CONNECTION_CONFIG, value = CohortEngineRestStatusHandler.EXAMPLE_HEALTH_CHECK_DATA_SERVER_CONFIG_JSON, dataTypeClass = EnhancedHealthCheckInput.class, required = true, paramType = "form", type = "file") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful Operation", response = EnhancedHealthCheckResults.class), @ApiResponse(code = 400, message = "Bad Request", response = ServiceErrorList.class), @ApiResponse(code = 500, message = "Server Error", response = ServiceErrorList.class) })
public Response getHealthCheckEnhanced(@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 = CohortEngineRestStatusHandler.GET_HEALTH_CHECK_ENCHANCED;
    Response response = null;
    try {
        // Perform api setup
        Response errorResponse = ServiceBaseUtility.apiSetup(version, logger, methodName);
        if (errorResponse != null) {
            return errorResponse;
        }
        // initialize results object
        EnhancedHealthCheckResults results = new EnhancedHealthCheckResults();
        FhirServerConnectionStatusInfo dataServerConnectionResults = new FhirServerConnectionStatusInfo();
        dataServerConnectionResults.setServerConfigType(FhirServerConfigType.dataServerConfig);
        dataServerConnectionResults.setConnectionResults(FhirConnectionStatus.notAttempted);
        FhirServerConnectionStatusInfo terminologyServerConnectionResults = new FhirServerConnectionStatusInfo();
        terminologyServerConnectionResults.setServerConfigType(FhirServerConfigType.terminologyServerConfig);
        terminologyServerConnectionResults.setConnectionResults(FhirConnectionStatus.notAttempted);
        results.setDataServerConnectionResults(dataServerConnectionResults);
        results.setTerminologyServerConnectionResults(terminologyServerConnectionResults);
        IAttachment dataSourceAttachment = multipartBody.getAttachment(CohortEngineRestStatusHandler.FHIR_SERVER_CONNECTION_CONFIG);
        if (dataSourceAttachment == null) {
            throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", CohortEngineRestStatusHandler.FHIR_SERVER_CONNECTION_CONFIG));
        }
        // deserialize the request input
        ObjectMapper om = new ObjectMapper();
        EnhancedHealthCheckInput fhirServerConfigs = om.readValue(dataSourceAttachment.getDataHandler().getInputStream(), EnhancedHealthCheckInput.class);
        FhirServerConfig dataServerConfig = fhirServerConfigs.getDataServerConfig();
        FhirServerConfig terminologyServerConfig = fhirServerConfigs.getTerminologyServerConfig();
        // validate the contents of the dataServerConfig
        CohortEngineRestHandler.validateBean(dataServerConfig);
        // validate the contents of the terminologyServerConfig
        if (terminologyServerConfig != null) {
            CohortEngineRestHandler.validateBean(terminologyServerConfig);
        }
        // get the fhir client object used to call to FHIR
        FhirClientBuilder clientBuilder = FhirClientBuilderFactory.newInstance().newFhirClientBuilder();
        IGenericClient dataClient = clientBuilder.createFhirClient(fhirServerConfigs.getDataServerConfig());
        // try a simple patient search to validate the connection info
        try {
            // used count=0 to minimize response size
            dataClient.search().forResource(Patient.class).count(0).execute();
            dataServerConnectionResults.setConnectionResults(FhirConnectionStatus.success);
        } catch (Throwable ex) {
            dataServerConnectionResults.setConnectionResults(FhirConnectionStatus.failure);
            dataServerConnectionResults.setServiceErrorList(new CohortServiceExceptionMapper().toServiceErrorList(ex));
        }
        // try a simple valueset search to validate the connection info
        if (terminologyServerConfig != null) {
            IGenericClient terminologyClient = clientBuilder.createFhirClient(fhirServerConfigs.getTerminologyServerConfig());
            try {
                // used count=0 to minimize response size
                terminologyClient.search().forResource(ValueSet.class).count(0).execute();
                terminologyServerConnectionResults.setConnectionResults(FhirConnectionStatus.success);
            } catch (Throwable ex) {
                terminologyServerConnectionResults.setConnectionResults(FhirConnectionStatus.failure);
                terminologyServerConnectionResults.setServiceErrorList(new CohortServiceExceptionMapper().toServiceErrorList(ex));
            }
        }
        // return the results
        response = Response.ok(results).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 : FhirClientBuilder(com.ibm.cohort.fhir.client.config.FhirClientBuilder) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) EnhancedHealthCheckInput(com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckInput) FhirServerConnectionStatusInfo(com.ibm.cohort.engine.api.service.model.FhirServerConnectionStatusInfo) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) EnhancedHealthCheckResults(com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckResults) 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 EnhancedHealthCheckInput

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

the class CohortHandlerTestBase method getEnhancedHealthCheckInputConfigFileBody.

protected IMultipartBody getEnhancedHealthCheckInputConfigFileBody(boolean includeTerminologyServer) throws Exception {
    // Create the metadata part of the request
    ObjectMapper om = new ObjectMapper();
    EnhancedHealthCheckInput input = new EnhancedHealthCheckInput();
    input.setDataServerConfig(getFhirServerConfig());
    if (includeTerminologyServer) {
        input.setTerminologyServerConfig(getFhirServerConfig());
    }
    String json = om.writeValueAsString(input);
    ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
    IAttachment rootPart = mockAttachment(jsonIs);
    // Assemble them together into a reasonable facsimile of the real request
    IMultipartBody body = mock(IMultipartBody.class);
    when(body.getAttachment(CohortEngineRestStatusHandler.FHIR_SERVER_CONNECTION_CONFIG)).thenReturn(rootPart);
    return body;
}
Also used : IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) ByteArrayInputStream(java.io.ByteArrayInputStream) EnhancedHealthCheckInput(com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckInput) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 EnhancedHealthCheckInput (com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckInput)2 IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)2 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)1 EnhancedHealthCheckResults (com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckResults)1 FhirServerConnectionStatusInfo (com.ibm.cohort.engine.api.service.model.FhirServerConnectionStatusInfo)1 FhirClientBuilder (com.ibm.cohort.fhir.client.config.FhirClientBuilder)1 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)1 IMultipartBody (com.ibm.websphere.jaxrs20.multipart.IMultipartBody)1 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1