use of com.ibm.cohort.cql.evaluation.parameters.Parameter 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);
}
use of com.ibm.cohort.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class DefaultVT method testPatientListMeasureEvaluation.
// 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 testPatientListMeasureEvaluation() throws Exception {
// You want -Denabled.dark.features=all in your Liberty jvm.options
Assume.assumeTrue(isServiceDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_PATIENT_LIST_MEASURE_EVALUATION));
final String RESOURCE = getUrlBase() + CohortServiceAPISpec.POST_PATIENT_LIST_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);
Map<String, Parameter> parameterOverrides = new HashMap<>();
parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
;
PatientListMeasureEvaluation requestData = new PatientListMeasureEvaluation();
requestData.setDataServerConfig(dataServerConfig);
requestData.setTerminologyServerConfig(termServerConfig);
// These patients are assumed to exist in the target FHIR server
List<String> patientIds = new ArrayList<>();
patientIds.add(VALID_PATIENT_ID);
patientIds.add(ANOTHER_VALID_PATIENT_ID);
requestData.setPatientIds(patientIds);
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, "patient_list_measure_evaluation_exp.json");
String actual = vr.extract().asString();
assertMeasureReportEquals(parser, expected, actual, true);
}
use of com.ibm.cohort.cql.evaluation.parameters.Parameter 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.cql.evaluation.parameters.Parameter 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.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class CqlEvaluatorIntegrationTest method testConditionDateRangeCriteriaMatched.
@Test
public void testConditionDateRangeCriteriaMatched() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse("2000-01-01");
Condition condition = new Condition();
condition.setId("condition");
condition.setSubject(new Reference("Patient/123"));
condition.setRecordedDate(date);
// Wiremock does not support request matching withQueryParam() function does not support
// the same parameter multiple times, so we do some regex work and try to make it
// somewhat order independent while still readable.
// @see https://github.com/tomakehurst/wiremock/issues/398
MappingBuilder builder = get(urlMatching("/Condition\\?(recorded-date=[lg]e.*&){2}subject=Patient%2F123&_format=json"));
mockFhirResourceRetrieval(builder, condition);
FhirServerConfig fhirConfig = getFhirServerConfig();
CqlEvaluator evaluator = setupTestFor(patient, fhirConfig, "cql.condition", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
Map<String, Parameter> parameters = new HashMap<>();
parameters.put("MeasurementPeriod", new IntervalParameter(new DatetimeParameter("1999-01-01T00:00:00-05:00"), true, new DatetimeParameter("2000-01-01T00:00:00-05:00"), false));
String expression = "ConditionInInterval";
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("TestDateQuery", "1.0.0"), parameters, newPatientContext("123"), Collections.singleton(expression));
Assert.assertEquals(1, actual.getExpressionResults().size());
List<Object> value = (List) actual.getExpressionResults().get(expression);
Assert.assertEquals(1, value.size());
assertFhirEquals(condition, (IBaseResource) value.get(0));
}
Aggregations