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;
}
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;
}
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());
}
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"));
}
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());
}
Aggregations