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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations