use of com.ibm.cohort.engine.api.service.model.CohortEvaluation in project quality-measure-and-cohort-service by Alvearie.
the class DefaultVT method testCohortEvaluationFalse.
@Test
public void testCohortEvaluationFalse() {
final String RESOURCE = getUrlBase() + "/{version}/cohort-evaluation";
Assume.assumeTrue(isServiceDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_VALUE_SET_UPLOAD));
// Create the metadata part of the request
CohortEvaluation requestData = new CohortEvaluation();
requestData.setDataServerConfig(dataServerConfig);
requestData.setTerminologyServerConfig(dataServerConfig);
requestData.setDefineToRun("Male");
requestData.setEntrypoint("cql/basic/Test-1.0.0.cql");
requestData.setPatientIds(VALID_PATIENT_ID);
RequestSpecification request = buildBaseRequest(new Headers()).queryParam(CohortEngineRestHandler.VERSION, ServiceBuildConstants.DATE).multiPart(CohortEngineRestHandler.REQUEST_DATA_PART, requestData, "application/json").multiPart(CohortEngineRestHandler.CQL_DEFINITION, new File("src/test/resources/cql/zip/Test-1.0.0.zip"));
ValidatableResponse response = request.post(RESOURCE, getServiceVersion()).then();
ValidatableResponse vr = runSuccessValidation(response, ContentType.JSON, HttpStatus.SC_OK);
CohortResult actual = vr.extract().response().getBody().as(CohortResult.class);
CohortResult expected = new CohortResult(Collections.emptyList());
assertEquals(expected, actual);
}
use of com.ibm.cohort.engine.api.service.model.CohortEvaluation in project quality-measure-and-cohort-service by Alvearie.
the class DefaultVT method testCohortEvaluationList.
@Test
public void testCohortEvaluationList() {
final String RESOURCE = getUrlBase() + "/{version}/cohort-evaluation";
Assume.assumeTrue(isServiceDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_VALUE_SET_UPLOAD));
String SECOND_VALID_PATIENT_ID = "47c883bb-160a-7117-c5df-9344041ef048";
String patientInput = VALID_PATIENT_ID + "," + SECOND_VALID_PATIENT_ID;
// Create the metadata part of the request
CohortEvaluation requestData = new CohortEvaluation();
requestData.setDataServerConfig(dataServerConfig);
requestData.setTerminologyServerConfig(dataServerConfig);
requestData.setDefineToRun("Female");
requestData.setEntrypoint("cql/basic/Test-1.0.0.cql");
requestData.setPatientIds(patientInput);
requestData.setLoggingLevel(CqlDebug.TRACE);
RequestSpecification request = buildBaseRequest(new Headers()).queryParam(CohortEngineRestHandler.VERSION, ServiceBuildConstants.DATE).multiPart(CohortEngineRestHandler.REQUEST_DATA_PART, requestData, "application/json").multiPart(CohortEngineRestHandler.CQL_DEFINITION, new File("src/test/resources/cql/zip/Test-1.0.0.zip"));
ValidatableResponse response = request.post(RESOURCE, getServiceVersion()).then();
ValidatableResponse vr = runSuccessValidation(response, ContentType.JSON, HttpStatus.SC_OK);
String actual = vr.extract().response().getBody().prettyPrint();
String expected = "{\n \"result\": [\n \"" + VALID_PATIENT_ID + "\",\n \"" + SECOND_VALID_PATIENT_ID + "\"\n ]\n}";
assertEquals(expected, actual);
}
use of com.ibm.cohort.engine.api.service.model.CohortEvaluation in project quality-measure-and-cohort-service by Alvearie.
the class DefaultVT method testCohortEvaluationTrue.
@Test
public void testCohortEvaluationTrue() {
final String RESOURCE = getUrlBase() + "/{version}/cohort-evaluation";
Assume.assumeTrue(isServiceDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_VALUE_SET_UPLOAD));
// Create the metadata part of the request
CohortEvaluation requestData = new CohortEvaluation();
requestData.setDataServerConfig(dataServerConfig);
requestData.setTerminologyServerConfig(dataServerConfig);
requestData.setDefineToRun("Female");
requestData.setEntrypoint("Test-1.0.0.cql");
requestData.setPatientIds(VALID_PATIENT_ID);
RequestSpecification request = buildBaseRequest(new Headers()).queryParam(CohortEngineRestHandler.VERSION, ServiceBuildConstants.DATE).multiPart(CohortEngineRestHandler.REQUEST_DATA_PART, requestData, "application/json").multiPart(CohortEngineRestHandler.CQL_DEFINITION, new File("src/test/resources/cql/zip/Test-1.0.0.zip"));
ValidatableResponse response = request.post(RESOURCE, getServiceVersion()).then();
ValidatableResponse vr = runSuccessValidation(response, ContentType.JSON, HttpStatus.SC_OK);
CohortResult actual = vr.extract().response().getBody().as(CohortResult.class);
CohortResult expected = new CohortResult(Collections.singletonList(VALID_PATIENT_ID));
assertEquals(expected, actual);
}
use of com.ibm.cohort.engine.api.service.model.CohortEvaluation in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testCohortBadCQLDefinition.
@PrepareForTest({ Response.class, FHIRRestUtils.class })
@Test
public void testCohortBadCQLDefinition() throws Exception {
prepMocks();
mockResponseClasses();
mockFhirResourceRetrieval("/metadata", getCapabilityStatement());
Patient patient = getPatient("123", AdministrativeGender.FEMALE, 40);
mockFhirResourceRetrieval(patient);
PowerMockito.mockStatic(ServiceBaseUtility.class);
PowerMockito.mockStatic(FHIRRestUtils.class);
PowerMockito.mockStatic(DefaultFhirClientBuilder.class);
PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_COHORT.getName())).thenReturn(null);
PowerMockito.whenNew(DefaultFhirClientBuilder.class).withArguments(Mockito.any()).thenReturn(mockDefaultFhirClientBuilder);
// Create the ZIP part of the request
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
File tempFile = new File("src/test/resources/cql/basic/Test-bad-1.0.0.cql");
ZipEntry entry = new ZipEntry("cql/Test-bad-1.0.0.cql");
zos.putNextEntry(entry);
byte[] x = new byte[(int) tempFile.length()];
new FileInputStream(tempFile).read(x);
zos.write(x);
zos.closeEntry();
}
ByteArrayInputStream zipIs = new ByteArrayInputStream(baos.toByteArray());
IAttachment measurePart = mockAttachment(zipIs);
CohortEvaluation requestData = new CohortEvaluation();
FhirServerConfig serverConfig = getFhirServerConfig();
requestData.setDataServerConfig(serverConfig);
requestData.setTerminologyServerConfig(serverConfig);
requestData.setDefineToRun("Female");
requestData.setEntrypoint("Test-bad-1.0.0.cql");
requestData.setPatientIds("123");
requestData.setLoggingLevel(CqlDebug.TRACE);
ObjectMapper om = new ObjectMapper();
String json = om.writeValueAsString(requestData);
ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
IAttachment request = mockAttachment(jsonIs);
// Assemble them together into a reasonable facsimile of the real request
IMultipartBody body = getFhirConfigFileBody();
when(body.getAttachment(CohortEngineRestHandler.CQL_DEFINITION)).thenReturn(measurePart);
when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(request);
when(measurePart.getDataHandler().getName()).thenReturn("Test-bad_1.0.0_cql.zip");
when(measurePart.getHeader("Content-Disposition")).thenReturn("Test-bad_1.0.0_cql.zip");
Response loadResponse = restHandler.evaluateCohort(mockRequestContext, null, body);
assertNotNull(loadResponse);
PowerMockito.verifyStatic(Response.class);
Response.status(500);
PowerMockito.verifyStatic(ServiceBaseUtility.class);
ServiceBaseUtility.apiSetup(Mockito.isNull(), Mockito.any(), Mockito.anyString());
// verifyStatic must be called before each verification
PowerMockito.verifyStatic(ServiceBaseUtility.class);
ServiceBaseUtility.apiCleanup(Mockito.any(), Mockito.eq(MethodNames.EVALUATE_COHORT.getName()));
}
Aggregations