use of com.ibm.cohort.engine.api.service.model.MeasureEvaluation in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandler method evaluateMeasure.
@POST
@Path("/evaluation")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Evaluates a measure bundle for a single patient", notes = EVALUATION_API_NOTES, response = String.class, tags = { "Measure Evaluation" }, nickname = "evaluate_measure", extensions = { @Extension(properties = { @ExtensionProperty(name = DarkFeatureSwaggerFilter.DARK_FEATURE_NAME, value = CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION) }) })
@ApiImplicitParams({ // This is necessary for the dark launch feature
@ApiImplicitParam(access = DarkFeatureSwaggerFilter.DARK_FEATURE_CONTROLLED, paramType = "header", dataType = "string"), // These are necessary to create a proper view of the request body that is all wrapped up in the Liberty IMultipartBody parameter
@ApiImplicitParam(name = REQUEST_DATA_PART, value = EXAMPLE_REQUEST_DATA_JSON, dataTypeClass = MeasureEvaluation.class, required = true, paramType = "form", type = "file"), @ApiImplicitParam(name = MEASURE_PART, value = EXAMPLE_MEASURE_ZIP, dataTypeClass = File.class, required = true, paramType = "form", type = "file") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful Operation: This API returns the JSON representation of a FHIR MeasureReport. A full example can be found at https://www.hl7.org/fhir/measurereport-cms146-cat1-example.html"), @ApiResponse(code = 400, message = "Bad Request", response = ServiceErrorList.class), @ApiResponse(code = 500, message = "Server Error", response = ServiceErrorList.class) })
public Response evaluateMeasure(@Context HttpServletRequest request, @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 = MethodNames.EVALUATE_MEASURE.getName();
Response response = null;
// Error out if feature is not enabled
ServiceBaseUtility.isDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION);
try {
// Perform api setup
Response errorResponse = ServiceBaseUtility.apiSetup(version, logger, methodName);
if (errorResponse != null) {
return errorResponse;
}
if (multipartBody == null) {
throw new IllegalArgumentException("A multipart/form-data body is required");
}
IAttachment metadataAttachment = multipartBody.getAttachment(REQUEST_DATA_PART);
if (metadataAttachment == null) {
throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", REQUEST_DATA_PART));
}
IAttachment measureAttachment = multipartBody.getAttachment(MEASURE_PART);
if (measureAttachment == null) {
throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", MEASURE_PART));
}
// deserialize the MeasuresEvaluation request
ObjectMapper om = new ObjectMapper();
MeasureEvaluation evaluationRequest = om.readValue(metadataAttachment.getDataHandler().getInputStream(), MeasureEvaluation.class);
// validate the contents of the evaluationRequest
validateBean(evaluationRequest);
FhirContext fhirContext = FhirContext.forR4();
try (InputStream is = measureAttachment.getDataHandler().getInputStream();
RetrieveCacheContext retrieveCacheContext = new DefaultRetrieveCacheContext()) {
MeasureEvaluator evaluator = createMeasureEvaluator(is, evaluationRequest.getDataServerConfig(), evaluationRequest.getTerminologyServerConfig(), evaluationRequest.isExpandValueSets(), evaluationRequest.getSearchPageSize(), retrieveCacheContext, fhirContext);
MeasureReport report = evaluator.evaluatePatientMeasure(evaluationRequest.getPatientId(), evaluationRequest.getMeasureContext(), evaluationRequest.getEvidenceOptions());
// The default serializer gets into an infinite loop when trying to serialize MeasureReport, so we use the
// HAPI encoder instead.
IParser parser = fhirContext.newJsonParser();
ResponseBuilder responseBuilder = Response.status(Response.Status.OK).header("Content-Type", "application/json").entity(parser.encodeResourceToString(report));
response = responseBuilder.build();
}
} catch (Throwable e) {
// map any exceptions caught into the proper REST error response objects
response = 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.MeasureEvaluation in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testEvaluateMeasureMissingPatient.
@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluateMeasureMissingPatient() throws Exception {
prepMocks();
PowerMockito.mockStatic(ServiceBaseUtility.class);
PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_MEASURE.getName())).thenReturn(null);
mockResponseClasses();
Library library = TestHelper.getTemplateLibrary();
Measure measure = TestHelper.getTemplateMeasure(library);
Patient patient = getPatient("patientId", AdministrativeGender.MALE, 40);
mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
mockNotFound("/Patient/" + patient.getId() + "\\?_format=json");
FhirServerConfig clientConfig = getFhirServerConfig();
Map<String, Parameter> parameterOverrides = new HashMap<>();
parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
MeasureContext measureContext = new MeasureContext(measure.getId(), parameterOverrides);
MeasureEvaluation evaluationRequest = new MeasureEvaluation();
evaluationRequest.setDataServerConfig(clientConfig);
evaluationRequest.setPatientId(patient.getId());
evaluationRequest.setMeasureContext(measureContext);
// evaluationRequest.setEvidenceOptions(evidenceOptions);
FhirContext fhirContext = FhirContext.forR4();
IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
// Create the metadata part of the request
ObjectMapper om = new ObjectMapper();
String json = om.writeValueAsString(evaluationRequest);
ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
IAttachment rootPart = mockAttachment(jsonIs);
// Create the ZIP part of the request
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TestHelper.createMeasureArtifact(baos, parser, measure, library);
ByteArrayInputStream zipIs = new ByteArrayInputStream(baos.toByteArray());
IAttachment measurePart = mockAttachment(zipIs);
// Assemble them together into a reasonable facsimile of the real request
IMultipartBody body = mock(IMultipartBody.class);
when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(rootPart);
when(body.getAttachment(CohortEngineRestHandler.MEASURE_PART)).thenReturn(measurePart);
Response loadResponse = restHandler.evaluateMeasure(mockRequestContext, VERSION, body);
assertNotNull(loadResponse);
PowerMockito.verifyStatic(Response.class);
Response.status(400);
}
use of com.ibm.cohort.engine.api.service.model.MeasureEvaluation in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testEvaluateMeasureSuccess.
/**
* Test the successful building of a response.
*/
@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluateMeasureSuccess() throws Exception {
prepMocks();
PowerMockito.mockStatic(ServiceBaseUtility.class);
PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_MEASURE.getName())).thenReturn(null);
mockResponseClasses();
Library library = TestHelper.getTemplateLibrary();
Measure measure = TestHelper.getTemplateMeasure(library);
Patient patient = getPatient("patientId", AdministrativeGender.MALE, 40);
mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
mockFhirResourceRetrieval(patient);
FhirServerConfig clientConfig = getFhirServerConfig();
Map<String, Parameter> parameterOverrides = new HashMap<>();
parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
MeasureContext measureContext = new MeasureContext(measure.getId(), parameterOverrides);
MeasureEvaluation evaluationRequest = new MeasureEvaluation();
evaluationRequest.setDataServerConfig(clientConfig);
evaluationRequest.setPatientId(patient.getId());
evaluationRequest.setMeasureContext(measureContext);
// evaluationRequest.setEvidenceOptions(evidenceOptions);
evaluationRequest.setExpandValueSets(true);
evaluationRequest.setSearchPageSize(500);
FhirContext fhirContext = FhirContext.forR4();
IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
// Create the metadata part of the request
ObjectMapper om = new ObjectMapper();
String json = om.writeValueAsString(evaluationRequest);
ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
IAttachment rootPart = mockAttachment(jsonIs);
// Create the ZIP part of the request
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TestHelper.createMeasureArtifact(baos, parser, measure, library);
ByteArrayInputStream zipIs = new ByteArrayInputStream(baos.toByteArray());
IAttachment measurePart = mockAttachment(zipIs);
// Assemble them together into a reasonable facsimile of the real request
IMultipartBody body = mock(IMultipartBody.class);
when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(rootPart);
when(body.getAttachment(CohortEngineRestHandler.MEASURE_PART)).thenReturn(measurePart);
Response loadResponse = restHandler.evaluateMeasure(mockRequestContext, VERSION, body);
assertEquals(mockResponse, loadResponse);
PowerMockito.verifyStatic(Response.class);
Response.status(Response.Status.OK);
}
use of com.ibm.cohort.engine.api.service.model.MeasureEvaluation in project quality-measure-and-cohort-service by Alvearie.
the class DefaultVT method testMeasureEvaluationByMeasureIdentifier.
// to tag a specific test to be part of DVT (deployment verification test)
@Category(DVT.class)
@Test
public /**
* Test a successful measure evaluation using identifier and version as the lookup key
*/
void testMeasureEvaluationByMeasureIdentifier() throws Exception {
// You want -Denabled.dark.features=all in your Liberty jvm.options
Assume.assumeTrue(isServiceDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION));
final String RESOURCE = getUrlBase() + CohortServiceAPISpec.CREATE_DELETE_EVALUATION_PATH;
FhirContext fhirContext = FhirContext.forR4();
IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
Library library = TestHelper.getTemplateLibrary();
Identifier identifier = new Identifier().setValue("measure-identifier").setSystem("http://ibm.com/health/test");
Measure measure = TestHelper.getTemplateMeasure(library);
measure.setIdentifier(Arrays.asList(identifier));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TestHelper.createMeasureArtifact(baos, parser, measure, library);
// Files.write( baos.toByteArray(), new File("target/test_measure_v1_0_0.zip"));
Map<String, Parameter> parameterOverrides = new HashMap<>();
parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
MeasureEvaluation requestData = new MeasureEvaluation();
requestData.setDataServerConfig(dataServerConfig);
requestData.setTerminologyServerConfig(termServerConfig);
// This is a patient ID that is assumed to exist in the target FHIR server
requestData.setPatientId(VALID_PATIENT_ID);
requestData.setMeasureContext(new MeasureContext(null, parameterOverrides, new com.ibm.cohort.engine.measure.Identifier(identifier.getSystem(), identifier.getValue()), measure.getVersion()));
requestData.setEvidenceOptions(new MeasureEvidenceOptions(false, MeasureEvidenceOptions.DefineReturnOptions.NONE));
ObjectMapper om = new ObjectMapper();
System.out.println(om.writeValueAsString(requestData));
RequestSpecification request = buildBaseRequest(new Headers()).queryParam(CohortEngineRestHandler.VERSION, ServiceBuildConstants.DATE).multiPart(CohortEngineRestHandler.REQUEST_DATA_PART, requestData, "application/json").multiPart(CohortEngineRestHandler.MEASURE_PART, "test_measure_v1_0_0.zip", new ByteArrayInputStream(baos.toByteArray()));
ValidatableResponse response = request.post(RESOURCE, getServiceVersion()).then();
ValidatableResponse vr = runSuccessValidation(response, ContentType.JSON, HttpStatus.SC_OK);
String expected = getJsonFromFile(ServiceAPIGlobalSpec.EXP_FOLDER_TYPE, "measure_evaluation_exp.json");
String actual = vr.extract().asString();
assertMeasureReportEquals(parser, expected, actual, false);
}
use of com.ibm.cohort.engine.api.service.model.MeasureEvaluation in project quality-measure-and-cohort-service by Alvearie.
the class DefaultVT method testMeasureEvaluationByMeasureID.
// to tag a specific test to be part of DVT (deployment verification test)
@Category(DVT.class)
@Test
public /**
* Test a successful measure evaluation using Resource.id as the lookup key
*/
void testMeasureEvaluationByMeasureID() throws Exception {
// You want -Denabled.dark.features=all in your Liberty jvm.options
Assume.assumeTrue(isServiceDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION));
final String RESOURCE = getUrlBase() + CohortServiceAPISpec.CREATE_DELETE_EVALUATION_PATH;
FhirContext fhirContext = FhirContext.forR4();
IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
Library library = TestHelper.getTemplateLibrary();
Measure measure = TestHelper.getTemplateMeasure(library);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TestHelper.createMeasureArtifact(baos, parser, measure, library);
// Files.write( baos.toByteArray(), new File("target/test_measure_v1_0_0.zip"));
Map<String, Parameter> parameterOverrides = new HashMap<>();
parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
MeasureEvaluation requestData = new MeasureEvaluation();
requestData.setDataServerConfig(dataServerConfig);
requestData.setTerminologyServerConfig(termServerConfig);
// This is a patient ID that is assumed to exist in the target FHIR server
requestData.setPatientId(VALID_PATIENT_ID);
requestData.setMeasureContext(new MeasureContext(measure.getId(), parameterOverrides));
requestData.setEvidenceOptions(new MeasureEvidenceOptions(false, MeasureEvidenceOptions.DefineReturnOptions.NONE));
ObjectMapper om = new ObjectMapper();
System.out.println(om.writeValueAsString(requestData));
RequestSpecification request = buildBaseRequest(new Headers()).queryParam(CohortEngineRestHandler.VERSION, ServiceBuildConstants.DATE).multiPart(CohortEngineRestHandler.REQUEST_DATA_PART, requestData, "application/json").multiPart(CohortEngineRestHandler.MEASURE_PART, "test_measure_v1_0_0.zip", new ByteArrayInputStream(baos.toByteArray()));
ValidatableResponse response = request.post(RESOURCE, getServiceVersion()).then();
ValidatableResponse vr = runSuccessValidation(response, ContentType.JSON, HttpStatus.SC_OK);
String expected = getJsonFromFile(ServiceAPIGlobalSpec.EXP_FOLDER_TYPE, "measure_evaluation_exp.json");
String actual = vr.extract().asString();
assertMeasureReportEquals(parser, expected, actual, false);
}
Aggregations