Search in sources :

Example 11 with Headers

use of com.jayway.restassured.response.Headers 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);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) HashMap(java.util.HashMap) MeasureEvaluation(com.ibm.cohort.engine.api.service.model.MeasureEvaluation) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) Headers(com.jayway.restassured.response.Headers) RequestSpecification(com.jayway.restassured.specification.RequestSpecification) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) MeasureContext(com.ibm.cohort.engine.measure.MeasureContext) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) Measure(org.hl7.fhir.r4.model.Measure) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) Library(org.hl7.fhir.r4.model.Library) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 12 with Headers

use of com.jayway.restassured.response.Headers in project quality-measure-and-cohort-service by Alvearie.

the class DefaultVT method testValueSetUpload.

@Test
public void testValueSetUpload() {
    final String RESOURCE = getUrlBase() + "/{version}/valueset";
    Assume.assumeTrue(isServiceDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_VALUE_SET_UPLOAD));
    // Create the metadata part of the request
    ObjectMapper om = new ObjectMapper();
    String fhirConfigjson = "";
    try {
        fhirConfigjson = om.writeValueAsString(dataServerConfig);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        fail();
    }
    RequestSpecification request = buildBaseRequest(new Headers()).param(CohortEngineRestHandler.VERSION, ServiceBuildConstants.DATE).queryParam(CohortEngineRestHandler.UPDATE_IF_EXISTS_PARM, false).multiPart(CohortEngineRestHandler.FHIR_DATA_SERVER_CONFIG_PART, fhirConfigjson, "application/json").multiPart(CohortEngineRestHandler.VALUE_SET_PART, new File("src/test/resources/2.16.840.1.113762.1.4.1114.7.xlsx"));
    ValidatableResponse response = request.post(RESOURCE, getServiceVersion()).then();
    runSuccessValidation(response, ContentType.JSON, HttpStatus.SC_CREATED);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) Headers(com.jayway.restassured.response.Headers) RequestSpecification(com.jayway.restassured.specification.RequestSpecification) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 13 with Headers

use of com.jayway.restassured.response.Headers 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);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) HashMap(java.util.HashMap) Headers(com.jayway.restassured.response.Headers) ArrayList(java.util.ArrayList) RequestSpecification(com.jayway.restassured.specification.RequestSpecification) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) MeasureContext(com.ibm.cohort.engine.measure.MeasureContext) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) Measure(org.hl7.fhir.r4.model.Measure) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) Library(org.hl7.fhir.r4.model.Library) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 14 with Headers

use of com.jayway.restassured.response.Headers 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 15 with Headers

use of com.jayway.restassured.response.Headers 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)

Aggregations

Headers (com.jayway.restassured.response.Headers)15 Test (org.junit.Test)15 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)14 RequestSpecification (com.jayway.restassured.specification.RequestSpecification)10 File (java.io.File)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 CohortEvaluation (com.ibm.cohort.engine.api.service.model.CohortEvaluation)4 Introspector (com.newrelic.agent.introspec.Introspector)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 FhirContext (ca.uhn.fhir.context.FhirContext)3 IParser (ca.uhn.fhir.parser.IParser)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)3 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)3 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)3 PatientListMeasureEvaluation (com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation)3 MeasureContext (com.ibm.cohort.engine.measure.MeasureContext)3 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3