Search in sources :

Example 11 with CqlEvaluationRequests

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

the class SparkCqlEvaluatorTest method testGetFilteredRequestsNoFilters.

@Test
public void testGetFilteredRequestsNoFilters() {
    CqlEvaluationRequests requests = new CqlEvaluationRequests();
    requests.setEvaluations(Arrays.asList(makeEvaluationRequest("context", "lib1", "1.0.0")));
    CqlEvaluationRequests actual = evaluator.getFilteredRequests(requests, null, null);
    assertEquals(1, actual.getEvaluations().size());
}
Also used : CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) Test(org.junit.Test)

Example 12 with CqlEvaluationRequests

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

the class ColumnRuleCreatorTest method testGetFiltersForContextOnlyJoinColumns.

@Test
public void testGetFiltersForContextOnlyJoinColumns() throws Exception {
    CqlToElmTranslator cqlTranslator = new CqlToElmTranslator();
    cqlTranslator.registerModelInfo(new File("src/test/resources/alltypes/modelinfo/alltypes-modelinfo-1.0.0.xml"));
    ObjectMapper mapper = new ObjectMapper();
    CqlEvaluationRequests requests = mapper.readValue(new File("src/test/resources/alltypes/metadata/join-only.json"), CqlEvaluationRequests.class);
    CqlLibraryProvider backingProvider = new ClasspathCqlLibraryProvider("alltypes.cql");
    TranslatingCqlLibraryProvider cqlLibraryProvider = new TranslatingCqlLibraryProvider(backingProvider, cqlTranslator);
    ColumnRuleCreator columnRuleCreator = new ColumnRuleCreator(requests.getEvaluations(), cqlTranslator, cqlLibraryProvider);
    ContextDefinitions definitions = mapper.readValue(new File("src/test/resources/alltypes/metadata/context-definitions-related-column.json"), ContextDefinitions.class);
    ContextDefinition context = definitions.getContextDefinitionByName("Patient");
    Map<String, Set<StringMatcher>> actual = columnRuleCreator.getDataRequirementsForContext(context);
    Map<String, Set<StringMatcher>> expected = new HashMap<>();
    expected.put("A", new HashSet<>(Arrays.asList(new EqualsStringMatcher(ContextRetriever.SOURCE_FACT_IDX), new EqualsStringMatcher("id_col"), new EqualsStringMatcher("pat_id"))));
    expected.put("B", new HashSet<>(Arrays.asList(new EqualsStringMatcher(ContextRetriever.SOURCE_FACT_IDX), new EqualsStringMatcher("string"), new EqualsStringMatcher(ContextRetriever.JOIN_CONTEXT_VALUE_IDX))));
    expected.put("C", new HashSet<>(Arrays.asList(new EqualsStringMatcher(ContextRetriever.SOURCE_FACT_IDX), new EqualsStringMatcher("pat_id"), new EqualsStringMatcher(ContextRetriever.JOIN_CONTEXT_VALUE_IDX))));
    assertEquals(expected, actual);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) HashMap(java.util.HashMap) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) EqualsStringMatcher(com.ibm.cohort.cql.util.EqualsStringMatcher) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 13 with CqlEvaluationRequests

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

the class ConfigurableOutputColumnNameEncoderTest method testOutputColumnsRepeatedInContextThrowsError.

@Test
public void testOutputColumnsRepeatedInContextThrowsError() {
    CqlLibraryDescriptor libraryDescriptor1 = new CqlLibraryDescriptor();
    libraryDescriptor1.setLibraryId("lib1");
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    request.setDescriptor(libraryDescriptor1);
    request.setId(1);
    CqlExpressionConfiguration expressionConfiguration1 = new CqlExpressionConfiguration();
    expressionConfiguration1.setName("abcd");
    expressionConfiguration1.setOutputColumn("A1");
    CqlExpressionConfiguration expressionConfiguration2 = new CqlExpressionConfiguration();
    expressionConfiguration2.setName("efgh");
    expressionConfiguration2.setOutputColumn("A1");
    request.setExpressions(new HashSet<>(Arrays.asList(expressionConfiguration1, expressionConfiguration2)));
    request.setContextKey("context1");
    CqlEvaluationRequests evaluationRequests = new CqlEvaluationRequests();
    evaluationRequests.setEvaluations(Collections.singletonList(request));
    IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> ConfigurableOutputColumnNameEncoder.create(evaluationRequests, "|"));
    assertTrue(ex.getMessage().contains("Evaluation request contains duplicate outputColumn"));
}
Also used : CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlExpressionConfiguration(com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Example 14 with CqlEvaluationRequests

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

the class ConfigurableOutputColumnNameEncoderTest method testNamesForSingleContext.

@Test
public void testNamesForSingleContext() {
    CqlLibraryDescriptor libraryDescriptor1 = new CqlLibraryDescriptor();
    libraryDescriptor1.setLibraryId("lib1");
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    request.setDescriptor(libraryDescriptor1);
    request.setId(1);
    CqlExpressionConfiguration expressionConfiguration1 = new CqlExpressionConfiguration();
    expressionConfiguration1.setName("abcd");
    CqlExpressionConfiguration expressionConfiguration2 = new CqlExpressionConfiguration();
    expressionConfiguration2.setName("efgh");
    expressionConfiguration2.setOutputColumn("A2");
    request.setExpressions(new HashSet<>(Arrays.asList(expressionConfiguration1, expressionConfiguration2)));
    CqlLibraryDescriptor libraryDescriptor2 = new CqlLibraryDescriptor();
    libraryDescriptor2.setLibraryId("lib2");
    CqlEvaluationRequest request2 = new CqlEvaluationRequest();
    request2.setDescriptor(libraryDescriptor2);
    request2.setId(2);
    CqlExpressionConfiguration expressionConfiguration3 = new CqlExpressionConfiguration();
    expressionConfiguration3.setName("ijkl");
    expressionConfiguration3.setOutputColumn("A3");
    CqlExpressionConfiguration expressionConfiguration4 = new CqlExpressionConfiguration();
    expressionConfiguration4.setName("mnop");
    request2.setExpressions(new HashSet<>(Arrays.asList(expressionConfiguration3, expressionConfiguration4)));
    request.setContextKey("context1");
    request2.setContextKey("context1");
    CqlEvaluationRequests evaluationRequests = new CqlEvaluationRequests();
    evaluationRequests.setEvaluations(Arrays.asList(request, request2));
    ConfigurableOutputColumnNameEncoder nameEncoder = ConfigurableOutputColumnNameEncoder.create(evaluationRequests, "|");
    assertEquals("lib1|abcd", nameEncoder.getColumnName(request, "abcd"));
    assertEquals("A2", nameEncoder.getColumnName(request, "efgh"));
    assertEquals("A3", nameEncoder.getColumnName(request2, "ijkl"));
    assertEquals("lib2|mnop", nameEncoder.getColumnName(request2, "mnop"));
}
Also used : CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlExpressionConfiguration(com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Example 15 with CqlEvaluationRequests

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

the class SparkCqlEvaluator method getFilteredJobSpecificationWithIds.

/**
 * Read the job specification file, apply some filtering logic for the
 * given requests, and then assign unique ids to each remaining request.
 *
 * @return CqlEvaluationRequests object containing requests with optional
 *         filtering and overrides described in {@link #getFilteredRequests(CqlEvaluationRequests, Map, Collection)}.
 *         Each remaining CqlEvaluationRequest is assigned a unique integer id.
 *
 * @throws Exception if there was an error reading the job specification.
 */
public CqlEvaluationRequests getFilteredJobSpecificationWithIds() throws Exception {
    CqlEvaluationRequests filteredRequests = getFilteredRequests(getJobSpecification(), args.libraries, args.expressions);
    List<CqlEvaluationRequest> evaluations = filteredRequests.getEvaluations();
    if (evaluations != null && !evaluations.isEmpty()) {
        int i = 1;
        for (CqlEvaluationRequest evaluation : evaluations) {
            evaluation.setId(i);
            i++;
        }
        filteredRequests.setEvaluations(evaluations);
    }
    return filteredRequests;
}
Also used : CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)

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