use of com.ibm.cohort.cql.translation.CqlToElmTranslator in project quality-measure-and-cohort-service by Alvearie.
the class DataRowDataProviderTest method testEvaluateSuccess.
@Test
public void testEvaluateSuccess() throws Exception {
CqlLibraryProvider backingProvider = new ClasspathCqlLibraryProvider("cql");
CqlToElmTranslator translator = new CqlToElmTranslator();
try (Reader r = new FileReader(new File("src/test/resources/modelinfo/mock-modelinfo-1.0.0.xml"))) {
translator.registerModelInfo(r);
}
CqlLibraryProvider libraryProvider = new TranslatingCqlLibraryProvider(backingProvider, translator);
CqlVersionedIdentifier topLevelLibraryIdentifier = new CqlVersionedIdentifier("SampleLibrary", "1.0.0");
CqlTerminologyProvider terminologyProvider = new UnsupportedTerminologyProvider();
Map<String, Object> row = new HashMap<>();
row.put("id", "123");
row.put("gender", "female");
row.put("birthDate", new DateTime(OffsetDateTime.now()));
Map<String, Iterable<Object>> data = new HashMap<>();
data.put("Patient", Arrays.asList(new SimpleDataRow(row)));
DataRowRetrieveProvider retrieveProvider = new DataRowRetrieveProvider(data, terminologyProvider);
CqlDataProvider dataProvider = new CompositeCqlDataProvider(new DataRowModelResolver(SimpleDataRow.class), retrieveProvider);
CqlEvaluator evaluator = new CqlEvaluator().setLibraryProvider(libraryProvider).setTerminologyProvider(terminologyProvider).setDataProvider(dataProvider).setCacheContexts(false);
CqlEvaluationResult result = evaluator.evaluate(topLevelLibraryIdentifier);
assertEquals(2, result.getExpressionResults().size());
Object perDefineResult = result.getExpressionResults().get("IsFemale");
assertEquals(Boolean.TRUE, perDefineResult);
}
use of com.ibm.cohort.cql.translation.CqlToElmTranslator in project quality-measure-and-cohort-service by Alvearie.
the class MapCqlLibraryProviderZipIntegrationTest method testLibraryFoundInZipWithSearchPathsMissingError.
@Test(expected = IllegalArgumentException.class)
public void testLibraryFoundInZipWithSearchPathsMissingError() throws Exception {
MapCqlLibraryProviderFactory factory = new MapCqlLibraryProviderFactory();
CqlLibraryProvider provider = factory.fromZipFile(Paths.get("src/test/resources/cql/zip-structured/col_colorectal_cancer_screening_v1_0_0.zip"), "deploypackage");
CqlLibraryProvider fhirClasspathProvider = new ClasspathCqlLibraryProvider();
provider = new PriorityCqlLibraryProvider(provider, fhirClasspathProvider);
CqlToElmTranslator translator = new CqlToElmTranslator();
provider = new TranslatingCqlLibraryProvider(provider, translator, false);
LibraryLoader libraryLoader = new ProviderBasedLibraryLoader(provider);
VersionedIdentifier id = new VersionedIdentifier().withId("COL_InitialPop").withVersion("1.0.0");
libraryLoader.load(id);
}
use of com.ibm.cohort.cql.translation.CqlToElmTranslator in project quality-measure-and-cohort-service by Alvearie.
the class MapCqlLibraryProviderZipIntegrationTest method testLibraryFoundInZipWithSearchPathsSuccess.
@Test
public void testLibraryFoundInZipWithSearchPathsSuccess() throws Exception {
MapCqlLibraryProviderFactory factory = new MapCqlLibraryProviderFactory();
CqlLibraryProvider provider = factory.fromZipFile(Paths.get("src/test/resources/cql/zip-structured/col_colorectal_cancer_screening_v1_0_0.zip"), "CDSexport");
CqlLibraryProvider fhirClasspathProvider = new ClasspathCqlLibraryProvider();
provider = new PriorityCqlLibraryProvider(provider, fhirClasspathProvider);
CqlToElmTranslator translator = new CqlToElmTranslator();
provider = new TranslatingCqlLibraryProvider(provider, translator, false);
LibraryLoader libraryLoader = new ProviderBasedLibraryLoader(provider);
VersionedIdentifier id = new VersionedIdentifier().withId("COL_InitialPop").withVersion("1.0.0");
Library library = libraryLoader.load(id);
Assert.assertEquals("COL_InitialPop", library.getIdentifier().getId());
}
use of com.ibm.cohort.cql.translation.CqlToElmTranslator in project quality-measure-and-cohort-service by Alvearie.
the class SparkSchemaCreatorTest method setup.
@Before
public void setup() {
cqlTranslator = new CqlToElmTranslator();
cqlTranslator.registerModelInfo(new File("src/test/resources/output-validation/modelinfo/simple-all-types-model-info.xml"));
CqlLibraryProvider backingProvider = new ClasspathCqlLibraryProvider("output-validation.cql");
cqlLibraryProvider = new TranslatingCqlLibraryProvider(backingProvider, cqlTranslator);
outputColumnNameFactory = new DefaultSparkOutputColumnEncoder(".");
}
use of com.ibm.cohort.cql.translation.CqlToElmTranslator 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);
}
Aggregations