Search in sources :

Example 11 with TranslatingCqlLibraryProvider

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

the class ColumnRuleCreatorTest method testGetFiltersForContextWithMultiJoinColumns.

@Test
public void testGetFiltersForContextWithMultiJoinColumns() throws Exception {
    CqlToElmTranslator cqlTranslator = new CqlToElmTranslator();
    cqlTranslator.registerModelInfo(new File("src/test/resources/multiple-joins/modelinfo/omop-modelinfo-5.2.2.xml"));
    ObjectMapper mapper = new ObjectMapper();
    CqlEvaluationRequests requests = mapper.readValue(new File("src/test/resources/multiple-joins/metadata/cql-jobs.json"), CqlEvaluationRequests.class);
    TranslatingCqlLibraryProvider cqlLibraryProvider = new TranslatingCqlLibraryProvider(new ClasspathCqlLibraryProvider("multiple-joins.cql"), cqlTranslator);
    ColumnRuleCreator columnRuleCreator = new ColumnRuleCreator(requests.getEvaluations(), cqlTranslator, cqlLibraryProvider);
    ContextDefinitions definitions = mapper.readValue(new File("src/test/resources/multiple-joins/metadata/context-definitions.json"), ContextDefinitions.class);
    ContextDefinition context = definitions.getContextDefinitionByName("person");
    Map<String, Set<StringMatcher>> actual = columnRuleCreator.getDataRequirementsForContext(context);
    Map<String, Set<StringMatcher>> expected = new HashMap<>();
    expected.put("person", new HashSet<>(Arrays.asList(new EqualsStringMatcher(ContextRetriever.SOURCE_FACT_IDX), new EqualsStringMatcher("person_id"))));
    expected.put("vocabulary", new HashSet<>(Arrays.asList(new EqualsStringMatcher(ContextRetriever.SOURCE_FACT_IDX), new EqualsStringMatcher("vocabulary_id"), new EqualsStringMatcher("vocabulary_version"), new EqualsStringMatcher(ContextRetriever.JOIN_CONTEXT_VALUE_IDX))));
    expected.put("concept", new HashSet<>(Arrays.asList(new EqualsStringMatcher(ContextRetriever.SOURCE_FACT_IDX), new EqualsStringMatcher("concept_id"), new EqualsStringMatcher("concept_code"), new EqualsStringMatcher("concept_name"), new EqualsStringMatcher("vocabulary_id"), new EqualsStringMatcher(ContextRetriever.JOIN_CONTEXT_VALUE_IDX))));
    expected.put("observation", new HashSet<>(Arrays.asList(new EqualsStringMatcher(ContextRetriever.SOURCE_FACT_IDX), new EqualsStringMatcher("observation_concept_id"), new EqualsStringMatcher("person_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) 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 12 with TranslatingCqlLibraryProvider

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

the class BaseDataTypeRequirementsProcessorTest method createLibrarySourceProvider.

protected CqlLibraryProvider createLibrarySourceProvider(String cqlPath, CqlToElmTranslator translator) throws IOException {
    ClasspathCqlLibraryProvider cpBasedLp = new ClasspathCqlLibraryProvider();
    cpBasedLp.setSupportedFormats(Format.CQL);
    MapCqlLibraryProviderFactory dirProviderFactory = new MapCqlLibraryProviderFactory();
    CqlLibraryProvider dirBasedLp = dirProviderFactory.fromDirectory(Paths.get(cqlPath));
    PriorityCqlLibraryProvider lsp = new PriorityCqlLibraryProvider(dirBasedLp, cpBasedLp);
    CqlLibraryProvider sourceProvider = new TranslatingCqlLibraryProvider(lsp, translator);
    return sourceProvider;
}
Also used : TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) MapCqlLibraryProviderFactory(com.ibm.cohort.cql.library.MapCqlLibraryProviderFactory) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) PriorityCqlLibraryProvider(com.ibm.cohort.cql.library.PriorityCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) PriorityCqlLibraryProvider(com.ibm.cohort.cql.library.PriorityCqlLibraryProvider)

Example 13 with TranslatingCqlLibraryProvider

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

the class CqlEvaluatorTest method testEvaluationExpressionSet.

@Test
public void testEvaluationExpressionSet() {
    CqlLibraryDescriptor libraryDescriptor = new CqlLibraryDescriptor().setLibraryId("Sample").setVersion("1.0.0").setFormat(Format.CQL);
    CqlLibrary library = new CqlLibrary().setDescriptor(libraryDescriptor).setContent("library \"Sample\" version '1.0.0'\ndefine \"Something\":1<10\ndefine \"OtherThing\":10<1");
    CqlTerminologyProvider terminologyProvider = mock(CqlTerminologyProvider.class);
    CqlDataProvider dataProvider = mock(CqlDataProvider.class);
    CqlLibraryProvider libraryProvider = mock(CqlLibraryProvider.class);
    when(libraryProvider.getLibrary(libraryDescriptor)).thenReturn(library);
    CqlToElmTranslator translator = new CqlToElmTranslator();
    TranslatingCqlLibraryProvider translatingProvider = new TranslatingCqlLibraryProvider(libraryProvider, translator);
    CqlEvaluator evaluator = new CqlEvaluator().setTerminologyProvider(terminologyProvider).setDataProvider(dataProvider).setLibraryProvider(translatingProvider).setCacheContexts(false);
    CqlEvaluationResult result = evaluator.evaluate(libraryDescriptor.getVersionedIdentifier(), null, new HashSet<>(Collections.singletonList("OtherThing")));
    assertNotNull(result);
    assertEquals(1, result.getExpressionResults().size());
    assertEquals(false, result.getExpressionResults().get("OtherThing"));
}
Also used : CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) Test(org.junit.Test)

Example 14 with TranslatingCqlLibraryProvider

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

the class CqlEvaluatorTest method testSimpleEvaluation.

@Test
public void testSimpleEvaluation() {
    CqlLibraryDescriptor libraryDescriptor = new CqlLibraryDescriptor().setLibraryId("Sample").setVersion("1.0.0").setFormat(Format.CQL);
    CqlLibrary library = new CqlLibrary().setDescriptor(libraryDescriptor).setContent("library \"Sample\" version '1.0.0'\nparameter MinimumAge Integer\n\ndefine \"Something\":1<10\ndefine \"OtherThing\":10<1\ndefine EchoParam: MinimumAge");
    CqlTerminologyProvider terminologyProvider = mock(CqlTerminologyProvider.class);
    CqlDataProvider dataProvider = mock(CqlDataProvider.class);
    CqlLibraryProvider libraryProvider = mock(CqlLibraryProvider.class);
    when(libraryProvider.getLibrary(libraryDescriptor)).thenReturn(library);
    CqlToElmTranslator translator = new CqlToElmTranslator();
    TranslatingCqlLibraryProvider translatingProvider = new TranslatingCqlLibraryProvider(libraryProvider, translator);
    CqlEvaluator evaluator = new CqlEvaluator().setTerminologyProvider(terminologyProvider).setDataProvider(dataProvider).setLibraryProvider(translatingProvider).setCacheContexts(false);
    int expectedMinimumAge = 17;
    Map<String, Parameter> parameters = new HashMap<>();
    parameters.put("MinimumAge", new IntegerParameter(expectedMinimumAge));
    Pair<String, String> context = Pair.of("Patient", "123");
    CqlEvaluationResult result = evaluator.evaluate(libraryDescriptor.getVersionedIdentifier(), parameters, context);
    assertNotNull(result);
    assertEquals(3, result.getExpressionResults().size());
    assertEquals(true, result.getExpressionResults().get("Something"));
    assertEquals(expectedMinimumAge, result.getExpressionResults().get("EchoParam"));
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) HashMap(java.util.HashMap) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) Test(org.junit.Test)

Example 15 with TranslatingCqlLibraryProvider

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

the class CqlEvaluatorTest method testBatchEvaluation.

@Test
public void testBatchEvaluation() {
    CqlLibraryDescriptor libraryDescriptor = new CqlLibraryDescriptor().setLibraryId("Sample").setVersion("1.0.0").setFormat(Format.CQL);
    CqlLibrary library = new CqlLibrary().setDescriptor(libraryDescriptor).setContent("library \"Sample\" version '1.0.0'\nparameter MinimumAge Integer\n\ndefine \"Something\":1<10\ndefine \"OtherThing\":10<1\ndefine EchoParam: MinimumAge");
    CqlTerminologyProvider terminologyProvider = mock(CqlTerminologyProvider.class);
    CqlDataProvider dataProvider = mock(CqlDataProvider.class);
    CqlLibraryProvider libraryProvider = mock(CqlLibraryProvider.class);
    when(libraryProvider.getLibrary(libraryDescriptor)).thenReturn(library);
    CqlToElmTranslator translator = new CqlToElmTranslator();
    TranslatingCqlLibraryProvider translatingProvider = new TranslatingCqlLibraryProvider(libraryProvider, translator);
    CqlEvaluator evaluator = new CqlEvaluator().setTerminologyProvider(terminologyProvider).setDataProvider(dataProvider).setLibraryProvider(translatingProvider).setCacheContexts(false);
    String parameterName = "MinimumAge";
    int expectedMinimumAge = 17;
    int expectedGlobalMinimumAge = expectedMinimumAge + 10;
    Map<String, Parameter> parameters = new HashMap<>();
    parameters.put(parameterName, new IntegerParameter(expectedMinimumAge));
    Pair<String, String> context = Pair.of("Patient", "123");
    CqlExpressionConfiguration expressionConfiguration = new CqlExpressionConfiguration();
    expressionConfiguration.setName("Something");
    CqlExpressionConfiguration expressionConfiguration2 = new CqlExpressionConfiguration();
    expressionConfiguration2.setName("EchoParam");
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    request.setDescriptor(libraryDescriptor);
    request.setExpressions(Arrays.asList(expressionConfiguration, expressionConfiguration2).stream().collect(Collectors.toSet()));
    request.setParameters(parameters);
    request.setContextKey(context.getKey());
    request.setContextValue(context.getValue());
    CqlEvaluationRequests requests = new CqlEvaluationRequests();
    requests.setEvaluations(Arrays.asList(request));
    requests.setGlobalParameters(Collections.singletonMap(parameterName, new IntegerParameter(expectedGlobalMinimumAge)));
    // First do a full request with parameter override
    List<Pair<CqlEvaluationRequest, CqlEvaluationResult>> results = evaluator.evaluate(requests);
    assertEquals(1, results.size());
    CqlEvaluationResult result = results.get(0).getRight();
    assertNotNull(result);
    assertEquals(2, result.getExpressionResults().size());
    assertEquals(true, result.getExpressionResults().get("Something"));
    assertEquals(expectedMinimumAge, result.getExpressionResults().get("EchoParam"));
    // Now use the global parameter value instead
    request.getParameters().clear();
    results = evaluator.evaluate(requests);
    assertEquals(1, results.size());
    result = results.get(0).getRight();
    assertEquals(expectedGlobalMinimumAge, result.getExpressionResults().get("EchoParam"));
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) HashMap(java.util.HashMap) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Aggregations

TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)17 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)15 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)12 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)11 Test (org.junit.Test)11 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)8 HashMap (java.util.HashMap)8 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)7 PriorityCqlLibraryProvider (com.ibm.cohort.cql.library.PriorityCqlLibraryProvider)5 File (java.io.File)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)3 CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)3 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)3 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)3 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)3 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)3 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)3 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)3 MapCqlLibraryProviderFactory (com.ibm.cohort.cql.library.MapCqlLibraryProviderFactory)3