use of com.ibm.cohort.engine.measure.MeasureContext in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testEvaluateMeasureMoreThanOneFormOfId.
@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluateMeasureMoreThanOneFormOfId() 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", 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, new Identifier().setValue("identifier"));
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.measure.MeasureContext in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testEvaluateMeasureMissingMeasureId.
@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluateMeasureMissingMeasureId() throws Exception {
prepMocks();
PowerMockito.mockStatic(ServiceBaseUtility.class);
PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_MEASURE.getName())).thenReturn(null);
mockResponseClasses();
Patient patient = getPatient("patientId", AdministrativeGender.MALE, 40);
mockFhirResourceRetrieval("/metadata", getCapabilityStatement());
mockFhirResourceRetrieval(patient);
FhirServerConfig clientConfig = getFhirServerConfig();
MeasureContext measureContext = new MeasureContext("unknown");
MeasureEvaluation evaluationRequest = new MeasureEvaluation();
evaluationRequest.setDataServerConfig(clientConfig);
evaluationRequest.setPatientId(patient.getId());
evaluationRequest.setMeasureContext(measureContext);
// evaluationRequest.setEvidenceOptions(evidenceOptions);
// 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
ByteArrayInputStream zipIs = TestHelper.emptyZip();
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.measure.MeasureContext in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testEvaluatePatientListMeasureSuccess.
@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluatePatientListMeasureSuccess() throws Exception {
prepMocks();
PowerMockito.mockStatic(ServiceBaseUtility.class);
PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_PATIENT_LIST_MEASURE.getName())).thenReturn(null);
mockResponseClasses();
Library library = TestHelper.getTemplateLibrary();
Measure measure = TestHelper.getTemplateMeasure(library);
Patient patient1 = getPatient("patientId1", AdministrativeGender.MALE, 40);
Patient patient2 = getPatient("patientId2", AdministrativeGender.FEMALE, 40);
mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
mockFhirResourceRetrieval(patient1);
mockFhirResourceRetrieval(patient2);
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);
PatientListMeasureEvaluation request = new PatientListMeasureEvaluation();
request.setDataServerConfig(clientConfig);
ArrayList<String> patientIds = new ArrayList<>();
patientIds.add(patient1.getId());
patientIds.add(patient2.getId());
request.setPatientIds(patientIds);
request.setMeasureContext(measureContext);
request.setExpandValueSets(true);
request.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(request);
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.evaluatePatientListMeasure(mockRequestContext, VERSION, body);
assertEquals(mockResponse, loadResponse);
PowerMockito.verifyStatic(Response.class);
Response.status(Response.Status.OK);
}
use of com.ibm.cohort.engine.measure.MeasureContext in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluationTest method when_serialize_deserialize___properties_are_unchanged.
@Test
public void when_serialize_deserialize___properties_are_unchanged() throws Exception {
FhirServerConfig dataServerConfig = new FhirServerConfig();
dataServerConfig.setEndpoint("dataserver");
FhirServerConfig termServerConfig = new FhirServerConfig();
termServerConfig.setEndpoint("termserver");
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 ctx = new MeasureContext("measureId", parameterOverrides);
MeasureEvaluation evaluation = new MeasureEvaluation();
evaluation.setDataServerConfig(dataServerConfig);
evaluation.setTerminologyServerConfig(termServerConfig);
evaluation.setPatientId("patientId");
evaluation.setMeasureContext(ctx);
evaluation.setEvidenceOptions(new MeasureEvidenceOptions(false, MeasureEvidenceOptions.DefineReturnOptions.ALL));
ObjectMapper om = new ObjectMapper();
String serialized = om.writeValueAsString(evaluation);
MeasureEvaluation deserialized = om.readValue(serialized, MeasureEvaluation.class);
assertEquals(evaluation, deserialized);
}
Aggregations