Search in sources :

Example 6 with CohortEvaluation

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);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) CohortEvaluation(com.ibm.cohort.engine.api.service.model.CohortEvaluation) Headers(com.jayway.restassured.response.Headers) CohortResult(com.ibm.cohort.engine.api.service.model.CohortResult) RequestSpecification(com.jayway.restassured.specification.RequestSpecification) File(java.io.File) Test(org.junit.Test)

Example 7 with CohortEvaluation

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);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) CohortEvaluation(com.ibm.cohort.engine.api.service.model.CohortEvaluation) Headers(com.jayway.restassured.response.Headers) RequestSpecification(com.jayway.restassured.specification.RequestSpecification) File(java.io.File) Test(org.junit.Test)

Example 8 with CohortEvaluation

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);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) CohortEvaluation(com.ibm.cohort.engine.api.service.model.CohortEvaluation) Headers(com.jayway.restassured.response.Headers) CohortResult(com.ibm.cohort.engine.api.service.model.CohortResult) RequestSpecification(com.jayway.restassured.specification.RequestSpecification) File(java.io.File) Test(org.junit.Test)

Example 9 with CohortEvaluation

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()));
}
Also used : CohortEvaluation(com.ibm.cohort.engine.api.service.model.CohortEvaluation) ZipEntry(java.util.zip.ZipEntry) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) FileInputStream(java.io.FileInputStream) Response(javax.ws.rs.core.Response) IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

CohortEvaluation (com.ibm.cohort.engine.api.service.model.CohortEvaluation)9 File (java.io.File)8 Test (org.junit.Test)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)5 IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)5 Response (javax.ws.rs.core.Response)5 IMultipartBody (com.ibm.websphere.jaxrs20.multipart.IMultipartBody)4 Headers (com.jayway.restassured.response.Headers)4 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)4 RequestSpecification (com.jayway.restassured.specification.RequestSpecification)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4 ZipEntry (java.util.zip.ZipEntry)4 ZipOutputStream (java.util.zip.ZipOutputStream)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 CohortResult (com.ibm.cohort.engine.api.service.model.CohortResult)3 Patient (org.hl7.fhir.r4.model.Patient)3 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)1