use of com.ibm.cohort.cql.terminology.UnsupportedTerminologyProvider 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.terminology.UnsupportedTerminologyProvider in project quality-measure-and-cohort-service by Alvearie.
the class CqlContextFactoryTest method testCreateContextSuccess.
@Test
public void testCreateContextSuccess() {
boolean expectedDebug = true;
ZonedDateTime expectedEvaluationDateTime = ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 11, 12, 13), ZoneId.of("America/New_York"));
PriorityCqlLibraryProvider libraryProvider = new PriorityCqlLibraryProvider(new ClasspathCqlLibraryProvider("cql", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH));
CqlToElmTranslator translator = new CqlToElmTranslator();
TranslatingCqlLibraryProvider translatingProvider = new TranslatingCqlLibraryProvider(libraryProvider, translator);
CqlVersionedIdentifier topLevelLibraryIdentifier = new CqlVersionedIdentifier("MyCQL", "1.0.0");
CqlTerminologyProvider terminologyProvider = new UnsupportedTerminologyProvider();
CqlDataProvider dataProvider = mock(CqlDataProvider.class);
Pair<String, String> contextData = Pair.of("Patient", "123");
Map<String, Parameter> expectedParams = new HashMap<>();
expectedParams.put("P1", new StringParameter("MyString"));
expectedParams.put("P2", new IntegerParameter(10));
CqlContextFactory cqlContextFactory = spy(CqlContextFactory.class);
Context context = cqlContextFactory.createContext(translatingProvider, topLevelLibraryIdentifier, terminologyProvider, dataProvider, expectedEvaluationDateTime, contextData, expectedParams, expectedDebug ? CqlDebug.DEBUG : CqlDebug.NONE);
assertEquals(expectedDebug, context.getDebugMap().getIsLoggingEnabled());
assertEquals(expectedEvaluationDateTime.toInstant(), context.getEvaluationDateTime().getDateTime().toZonedDateTime().toInstant());
context.enterContext(contextData.getKey());
assertEquals(contextData.getValue(), context.getCurrentContextValue());
assertEquals(topLevelLibraryIdentifier.getId(), context.getCurrentLibrary().getIdentifier().getId());
assertEquals(topLevelLibraryIdentifier.getVersion(), context.getCurrentLibrary().getIdentifier().getVersion());
for (Map.Entry<String, Parameter> entry : expectedParams.entrySet()) {
Object actualValue = context.resolveParameterRef(null, entry.getKey());
assertEquals(entry.getValue().toCqlType(), actualValue);
}
// Once more just to check that caching is working. Using a different data provider because that is
// how we will actually use it at runtime.
CqlDataProvider dataProvider2 = mock(CqlDataProvider.class);
cqlContextFactory.createContext(translatingProvider, topLevelLibraryIdentifier, terminologyProvider, dataProvider2, expectedEvaluationDateTime, contextData, expectedParams, expectedDebug ? CqlDebug.DEBUG : CqlDebug.NONE);
verify(cqlContextFactory, times(1)).createContext(any(ContextCacheKey.class));
}
Aggregations