Search in sources :

Example 1 with FhirServerConnectionStatusInfo

use of com.ibm.cohort.engine.api.service.model.FhirServerConnectionStatusInfo 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)

Aggregations

IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 EnhancedHealthCheckInput (com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckInput)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 IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)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 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