Search in sources :

Example 16 with CqlToElmTranslator

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

the class BaseDataTypeRequirementsProcessorTest method runPatternTest.

protected Map<String, Set<StringMatcher>> runPatternTest(String cqlPath, String modelInfoPath, Set<String> expressions, Predicate<Path> libraryFilter) throws IOException {
    CqlToElmTranslator translator = createCqlTranslator(modelInfoPath);
    CqlLibraryProvider sourceProvider = createLibrarySourceProvider(cqlPath, translator);
    DataTypeRequirementsProcessor requirementsProcessor = new DataTypeRequirementsProcessor(translator);
    Map<String, Set<StringMatcher>> pathMatchersByDataType = new HashMap<>();
    if (libraryFilter == null) {
        libraryFilter = x -> true;
    }
    List<Path> paths = Files.list(Paths.get(cqlPath)).filter(libraryFilter).collect(Collectors.toList());
    for (Path path : paths) {
        System.out.println("Processing " + path.toString());
        CqlLibraryDescriptor cld = CqlLibraryHelpers.filenameToLibraryDescriptor(path.toString());
        Map<String, Set<StringMatcher>> newPaths = requirementsProcessor.getAnyColumnRequirementsByDataType(sourceProvider, cld);
        newPaths.forEach((key, value) -> {
            pathMatchersByDataType.merge(key, value, (prev, current) -> {
                prev.addAll(current);
                return prev;
            });
        });
    }
    // System.out.println(pathMatchersByDataType);
    return pathMatchersByDataType;
}
Also used : Path(java.nio.file.Path) Set(java.util.Set) HashMap(java.util.HashMap) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) 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) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor)

Example 17 with CqlToElmTranslator

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

the class BaseDataTypeRequirementsProcessorTest method runPathTest.

protected Map<String, Set<String>> runPathTest(String cqlPath, String modelInfoPath, Set<String> expressions, Predicate<Path> libraryFilter) throws IOException {
    CqlToElmTranslator translator = createCqlTranslator(modelInfoPath);
    CqlLibraryProvider sourceProvider = createLibrarySourceProvider(cqlPath, translator);
    DataTypeRequirementsProcessor requirementsProcessor = new DataTypeRequirementsProcessor(translator);
    Map<String, Set<String>> pathsByDataType = new HashMap<>();
    if (libraryFilter == null) {
        libraryFilter = x -> true;
    }
    List<Path> paths = Files.list(Paths.get(cqlPath)).filter(libraryFilter).collect(Collectors.toList());
    for (Path path : paths) {
        System.out.println("Processing " + path.toString());
        CqlLibraryDescriptor cld = CqlLibraryHelpers.filenameToLibraryDescriptor(path.toString());
        Map<String, Set<String>> newPaths = requirementsProcessor.getPathRequirementsByDataType(sourceProvider, cld, expressions);
        newPaths.forEach((key, value) -> {
            pathsByDataType.merge(key, value, (prev, current) -> {
                prev.addAll(current);
                return prev;
            });
        });
    }
    // System.out.println(pathsByDataType);
    return pathsByDataType;
}
Also used : Path(java.nio.file.Path) Set(java.util.Set) HashMap(java.util.HashMap) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) 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) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor)

Example 18 with CqlToElmTranslator

use of com.ibm.cohort.cql.translation.CqlToElmTranslator 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 19 with CqlToElmTranslator

use of com.ibm.cohort.cql.translation.CqlToElmTranslator 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 20 with CqlToElmTranslator

use of com.ibm.cohort.cql.translation.CqlToElmTranslator 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

CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)22 TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)18 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)14 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)13 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)9 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)9 PriorityCqlLibraryProvider (com.ibm.cohort.cql.library.PriorityCqlLibraryProvider)7 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)6 Set (java.util.Set)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 File (java.io.File)5 CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)4 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)4 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)4 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)4 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)4 LibraryLoader (org.opencds.cqf.cql.engine.execution.LibraryLoader)4 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)3