Search in sources :

Example 1 with EnhancedHealthCheckResults

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

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

the class CohortEngineRestStatusHandlerTest method testEnhancedHealthCheckFailed.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class, DefaultFhirClientBuilder.class })
@Test
public /**
 * Test the service returns a failure when trying to connect to data and terminology servers
 */
void testEnhancedHealthCheckFailed() throws Exception {
    prepMocks(false);
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, CohortEngineRestStatusHandler.GET_HEALTH_CHECK_ENCHANCED)).thenReturn(null);
    CapabilityStatement metadata = getCapabilityStatement();
    mockFhirResourceRetrieval("/metadata?_format=json", metadata);
    // return null to cause exception
    mockFhirResourceRetrieval("/Patient?_format=json", null);
    mockFhirResourceRetrieval("/ValueSet?_format=json", null);
    Response response = cerSH.getHealthCheckEnhanced(VERSION, getEnhancedHealthCheckInputConfigFileBody(true));
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    assertEquals(((EnhancedHealthCheckResults) response.getEntity()).getDataServerConnectionResults().getConnectionResults(), FhirConnectionStatus.failure);
    assertEquals(((EnhancedHealthCheckResults) response.getEntity()).getTerminologyServerConnectionResults().getConnectionResults(), FhirConnectionStatus.failure);
}
Also used : Response(javax.ws.rs.core.Response) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) EnhancedHealthCheckResults(com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckResults) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with EnhancedHealthCheckResults

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

the class CohortEngineRestStatusHandlerTest method testEnhancedHealthCheckFailNoTermServer.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class, DefaultFhirClientBuilder.class })
@Test
public /**
 * Test a failure connecting to data server and no terminology server provided
 */
void testEnhancedHealthCheckFailNoTermServer() throws Exception {
    prepMocks(false);
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, CohortEngineRestStatusHandler.GET_HEALTH_CHECK_ENCHANCED)).thenReturn(null);
    CapabilityStatement metadata = getCapabilityStatement();
    mockFhirResourceRetrieval("/metadata?_format=json", metadata);
    mockFhirResourceRetrieval("/Patient?_format=json", null);
    Response response = cerSH.getHealthCheckEnhanced(VERSION, getEnhancedHealthCheckInputConfigFileBody(false));
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    assertEquals(((EnhancedHealthCheckResults) response.getEntity()).getDataServerConnectionResults().getConnectionResults(), FhirConnectionStatus.failure);
    assertEquals(((EnhancedHealthCheckResults) response.getEntity()).getTerminologyServerConnectionResults().getConnectionResults(), FhirConnectionStatus.notAttempted);
}
Also used : Response(javax.ws.rs.core.Response) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) EnhancedHealthCheckResults(com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckResults) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with EnhancedHealthCheckResults

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

the class CohortEngineRestStatusHandlerTest method testEnhancedHealthCheckOK.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class, DefaultFhirClientBuilder.class })
@Test
public /**
 * Test the setting of service status to OK.
 */
void testEnhancedHealthCheckOK() throws Exception {
    prepMocks(false);
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, CohortEngineRestStatusHandler.GET_HEALTH_CHECK_ENCHANCED)).thenReturn(null);
    CapabilityStatement metadata = getCapabilityStatement();
    mockFhirResourceRetrieval("/metadata?_format=json", metadata);
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
    mockFhirResourceRetrieval("/Patient?_format=json", patient);
    // don't need to return a valueset since we only care that the call returns something
    mockFhirResourceRetrieval("/ValueSet?_format=json", patient);
    Response response = cerSH.getHealthCheckEnhanced(VERSION, getEnhancedHealthCheckInputConfigFileBody(true));
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    assertEquals(((EnhancedHealthCheckResults) response.getEntity()).getDataServerConnectionResults().getConnectionResults(), FhirConnectionStatus.success);
    assertEquals(((EnhancedHealthCheckResults) response.getEntity()).getTerminologyServerConnectionResults().getConnectionResults(), FhirConnectionStatus.success);
}
Also used : Response(javax.ws.rs.core.Response) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Patient(org.hl7.fhir.r4.model.Patient) EnhancedHealthCheckResults(com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckResults) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with EnhancedHealthCheckResults

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

the class CohortEngineRestStatusHandlerTest method testEnhancedHealthCheckOKNoTermServer.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class, DefaultFhirClientBuilder.class })
@Test
public void testEnhancedHealthCheckOKNoTermServer() throws Exception {
    prepMocks(false);
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, CohortEngineRestStatusHandler.GET_HEALTH_CHECK_ENCHANCED)).thenReturn(null);
    CapabilityStatement metadata = getCapabilityStatement();
    mockFhirResourceRetrieval("/metadata?_format=json", metadata);
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
    mockFhirResourceRetrieval("/Patient?_format=json", patient);
    Response response = cerSH.getHealthCheckEnhanced(VERSION, getEnhancedHealthCheckInputConfigFileBody(false));
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    assertEquals(((EnhancedHealthCheckResults) response.getEntity()).getDataServerConnectionResults().getConnectionResults(), FhirConnectionStatus.success);
    assertEquals(((EnhancedHealthCheckResults) response.getEntity()).getTerminologyServerConnectionResults().getConnectionResults(), FhirConnectionStatus.notAttempted);
}
Also used : Response(javax.ws.rs.core.Response) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Patient(org.hl7.fhir.r4.model.Patient) EnhancedHealthCheckResults(com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckResults) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

EnhancedHealthCheckResults (com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckResults)5 Response (javax.ws.rs.core.Response)5 CapabilityStatement (org.hl7.fhir.r4.model.CapabilityStatement)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Patient (org.hl7.fhir.r4.model.Patient)2 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 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