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