use of org.cqframework.cql.elm.execution.Library in project quality-measure-and-cohort-service by Alvearie.
the class CqlTranslationIntegrationTest method singleFile_withOptions__translatedSuccessfully.
@Test
public void singleFile_withOptions__translatedSuccessfully() {
CqlLibraryProvider backingLibraryProvider = new ClasspathCqlLibraryProvider("cql.basic");
CqlToElmTranslator translator = new CqlToElmTranslator();
Path modelInfo = Paths.get("src/test/resources/modelinfo/ig-with-target-modelinfo-0.0.1.xml");
translator.registerModelInfo(modelInfo.toFile());
CqlLibraryProvider translatingLibraryProvider = new TranslatingCqlLibraryProvider(backingLibraryProvider, translator, true);
LibraryLoader libraryLoader = new ProviderBasedLibraryLoader(translatingLibraryProvider);
VersionedIdentifier identifier = new VersionedIdentifier().withId("Test").withVersion("1.0.0");
Library library = libraryLoader.load(identifier);
Assert.assertEquals(identifier, library.getIdentifier());
Assert.assertEquals(2, library.getAnnotation().size());
Assert.assertEquals(4, library.getStatements().getDef().size());
}
use of org.cqframework.cql.elm.execution.Library 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 org.cqframework.cql.elm.execution.Library in project CRD by HL7-DaVinci.
the class CqlExecutionContextBuilder method getExecutionContext.
public static Context getExecutionContext(CqlRule cqlRule, HashMap<String, Resource> cqlParams, String baseUrl) {
ModelManager modelManager = new ModelManager();
LibraryManager libraryManager = new LibraryManager(modelManager);
libraryManager.getLibrarySourceLoader().clearProviders();
Library library = null;
LibraryLoader libraryLoader = null;
if (cqlRule.isPrecompiled()) {
// todo
} else {
libraryManager.getLibrarySourceLoader().registerProvider(cqlRule.getRawCqlLibrarySourceProvider(CQL_VERSION));
libraryLoader = new LocalLibraryLoader(libraryManager);
try {
library = CqlExecution.translate(cqlRule.getRawMainCqlLibrary(CQL_VERSION), libraryManager, modelManager);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
FhirContext fhirContext = FhirContext.forR4();
Context context = new Context(library);
context.registerLibraryLoader(libraryLoader);
context.setExpressionCaching(true);
R4FhirModelResolver modelResolver = new R4FhirModelResolver();
RestFhirRetrieveProvider retrieveProvider = new RestFhirRetrieveProvider(new SearchParameterResolver(fhirContext), fhirContext.newRestfulGenericClient("http://fhirtest.uhn.ca/baseR4"));
CompositeDataProvider provider = new CompositeDataProvider(modelResolver, retrieveProvider);
context.registerDataProvider("http://hl7.org/fhir", provider);
for (Map.Entry<String, org.hl7.fhir.r4.model.Resource> entry : cqlParams.entrySet()) {
context.setParameter(null, entry.getKey(), entry.getValue());
}
context.setParameter(null, "base_url", baseUrl);
return context;
}
use of org.cqframework.cql.elm.execution.Library in project quality-measure-and-cohort-service by Alvearie.
the class CDMMeasureEvaluationTest method setupTestDefineContext.
private CDMContext setupTestDefineContext(Map<VersionedIdentifier, Map<String, Object>> expectedResults) {
Library library = new Library();
CDMContext defineContext = new CDMContext(library);
for (Entry<VersionedIdentifier, Map<String, Object>> expectedLibraryResults : expectedResults.entrySet()) {
for (Entry<String, Object> defineResult : expectedLibraryResults.getValue().entrySet()) {
defineContext.addExpressionToCache(expectedLibraryResults.getKey(), defineResult.getKey(), defineResult.getValue());
}
}
return defineContext;
}
use of org.cqframework.cql.elm.execution.Library in project quality-measure-and-cohort-service by Alvearie.
the class R4TranslatingLibraryLoader method translateLibrary.
private String translateLibrary(String content, VersionedIdentifier libraryIdentifier) {
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResolutionProvider = new ResolverLibraryResolutionProvider<>(resolver);
LibrarySourceProvider<org.hl7.fhir.r4.model.Library, Attachment> librarySourceProvider = new LibrarySourceProvider<>(libraryResolutionProvider, org.hl7.fhir.r4.model.Library::getContent, Attachment::getContentType, Attachment::getData);
CqlLibrarySourceProvider cqlLibrarySourceProvider = new SourceProviderBasedCqlLibrarySourceProvider(librarySourceProvider);
CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setFormat(Format.CQL).setLibraryId(libraryIdentifier.getId()).setVersion(libraryIdentifier.getVersion());
CqlLibrary library = new CqlLibrary().setDescriptor(descriptor).setContent(content);
return translator.translate(library, cqlLibrarySourceProvider).getMainLibrary().getContent();
}
Aggregations