Search in sources :

Example 16 with CqlEvaluationRequests

use of com.ibm.cohort.cql.evaluation.CqlEvaluationRequests in project quality-measure-and-cohort-service by Alvearie.

the class SparkCqlEvaluator method readJobSpecification.

/**
 * Deserialize CQL Job requests.
 *
 * @param path Path to CQL jobs file in JSON format
 * @return deserialized jobs object
 * @throws Exception when deserialization fails for any reason
 */
protected CqlEvaluationRequests readJobSpecification(String path) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    Path filePath = new Path(path);
    FileSystem fileSystem = filePath.getFileSystem(this.hadoopConfiguration.value());
    CqlEvaluationRequests requests;
    try (Reader r = new InputStreamReader(fileSystem.open(filePath))) {
        requests = mapper.readValue(r, CqlEvaluationRequests.class);
    }
    try (ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) {
        Validator validator = factory.getValidator();
        Set<ConstraintViolation<CqlEvaluationRequests>> violations = validator.validate(requests);
        if (!violations.isEmpty()) {
            StringBuffer sb = new StringBuffer();
            for (ConstraintViolation<CqlEvaluationRequests> violation : violations) {
                sb.append(System.lineSeparator()).append(violation.getPropertyPath().toString()).append(": ").append(violation.getMessage());
            }
            throw new IllegalArgumentException("Invalid Job Specification: " + sb.toString());
        }
    }
    return requests;
}
Also used : Path(org.apache.hadoop.fs.Path) InputStreamReader(java.io.InputStreamReader) ValidatorFactory(javax.validation.ValidatorFactory) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) FileSystem(org.apache.hadoop.fs.FileSystem) ConstraintViolation(javax.validation.ConstraintViolation) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Validator(javax.validation.Validator)

Example 17 with CqlEvaluationRequests

use of com.ibm.cohort.cql.evaluation.CqlEvaluationRequests in project quality-measure-and-cohort-service by Alvearie.

the class SparkCqlEvaluator method getJobSpecification.

public CqlEvaluationRequests getJobSpecification() throws Exception {
    CqlEvaluationRequests requests = jobSpecification.get();
    if (requests == null) {
        requests = readJobSpecification(args.jobSpecPath);
        jobSpecification.set(requests);
    }
    return requests;
}
Also used : CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)

Example 18 with CqlEvaluationRequests

use of com.ibm.cohort.cql.evaluation.CqlEvaluationRequests in project quality-measure-and-cohort-service by Alvearie.

the class SparkCqlEvaluatorTest method testGetFilteredRequestsFilterEvaluations.

@Test
public void testGetFilteredRequestsFilterEvaluations() {
    CqlEvaluationRequests requests = new CqlEvaluationRequests();
    CqlEvaluationRequest request = makeEvaluationRequest("context", "lib1", "1.0.0");
    request.setExpressionsByNames(new HashSet<>(Arrays.asList("cohortOrig", "expr1")));
    CqlEvaluationRequest request2 = makeEvaluationRequest("context", "lib2", "1.0.0");
    request2.setExpressionsByNames(new HashSet<>(Arrays.asList("cohortOrig", "expr2")));
    CqlEvaluationRequest request3 = makeEvaluationRequest("context", "lib3", "1.0.0");
    request3.setExpressionsByNames(new HashSet<>(Arrays.asList("cohortOrig")));
    List<CqlEvaluationRequest> evaluations = Arrays.asList(request, request2, request3);
    requests.setEvaluations(evaluations);
    Map<String, String> libs = new HashMap<String, String>() {

        {
            put("lib1", "1.0.0");
            put("lib2", "1.0.0");
            put("lib3", "1.0.0");
        }
    };
    Set<String> expressions = new HashSet<>(Arrays.asList("expr1", "expr2"));
    CqlEvaluationRequests actual = evaluator.getFilteredRequests(requests, libs, expressions);
    assertEquals(3, actual.getEvaluations().size());
    assertEquals(Collections.singleton("expr1"), actual.getEvaluations().get(0).getExpressionNames());
    assertEquals(Collections.singleton("expr2"), actual.getEvaluations().get(1).getExpressionNames());
    assertEquals(Collections.emptySet(), actual.getEvaluations().get(2).getExpressionNames());
}
Also used : HashMap(java.util.HashMap) CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with CqlEvaluationRequests

use of com.ibm.cohort.cql.evaluation.CqlEvaluationRequests in project quality-measure-and-cohort-service by Alvearie.

the class SparkCqlEvaluatorTest method testReadCqlJobsSuccess.

@Test
public void testReadCqlJobsSuccess() throws Exception {
    IntervalParameter measurementPeriod = new IntervalParameter();
    measurementPeriod.setStart(new DateParameter("2020-01-01")).setEnd(new DateParameter("2021-01-01"));
    IntegerParameter minimumAge = new IntegerParameter(17);
    evaluator.hadoopConfiguration = new SerializableConfiguration(SparkHadoopUtil.get().conf());
    CqlEvaluationRequests requests = evaluator.readJobSpecification("src/test/resources/simple-job/cql-jobs.json");
    assertNotNull(requests);
    assertEquals(measurementPeriod, requests.getGlobalParameters().get("Measurement Period"));
    assertEquals(1, requests.getEvaluations().size());
    assertEquals(minimumAge, requests.getEvaluations().get(0).getParameters().get("MinimumAge"));
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) SerializableConfiguration(org.apache.spark.util.SerializableConfiguration) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) Test(org.junit.Test)

Example 20 with CqlEvaluationRequests

use of com.ibm.cohort.cql.evaluation.CqlEvaluationRequests in project quality-measure-and-cohort-service by Alvearie.

the class SparkCqlEvaluatorTest method testGetFilteredRequestsNoEvaluationRequestsForLibraries.

@Test
public void testGetFilteredRequestsNoEvaluationRequestsForLibraries() {
    CqlEvaluationRequests requests = new CqlEvaluationRequests();
    CqlEvaluationRequest request = makeEvaluationRequest("context", "lib1", "1.0.0");
    request.setExpressionsByNames(new HashSet<>(Collections.singletonList("cohort")));
    CqlEvaluationRequest request2 = makeEvaluationRequest("context", "lib2", "1.0.0");
    request2.setExpressionsByNames(new HashSet<>(Collections.singletonList("cohort")));
    List<CqlEvaluationRequest> evaluations = Arrays.asList(request, request2);
    requests.setEvaluations(evaluations);
    Map<String, String> libs = new HashMap<String, String>() {

        {
            put("lib3", "1.0.0");
            put("lib4", "1.0.0");
        }
    };
    CqlEvaluationRequests actual = evaluator.getFilteredRequests(requests, libs, null);
    assertTrue(actual.getEvaluations().isEmpty());
}
Also used : HashMap(java.util.HashMap) CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) Test(org.junit.Test)

Aggregations

CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)34 Test (org.junit.Test)27 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)17 CqlEvaluationRequest (com.ibm.cohort.cql.evaluation.CqlEvaluationRequest)14 HashMap (java.util.HashMap)13 ContextDefinitions (com.ibm.cohort.cql.spark.aggregation.ContextDefinitions)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 File (java.io.File)9 CqlExpressionConfiguration (com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration)8 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)6 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)6 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)6 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)6 DecimalParameter (com.ibm.cohort.cql.evaluation.parameters.DecimalParameter)5 StringParameter (com.ibm.cohort.cql.evaluation.parameters.StringParameter)5 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)5 TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)5 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)4 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)4 Set (java.util.Set)4