use of org.cqframework.cql.elm.execution.IncludeDef in project quality-measure-and-cohort-service by Alvearie.
the class CqlContextFactory method registerExternalIncludes.
private void registerExternalIncludes(Context context, Library currentLibrary) {
Library.Includes includes = currentLibrary.getIncludes();
if (includes != null) {
for (IncludeDef include : includes.getDef()) {
VersionedIdentifier vid = new VersionedIdentifier().withId(include.getLocalIdentifier()).withVersion(include.getVersion());
context.registerExternalFunctionProvider(vid, this.externalFunctionProvider);
}
}
}
use of org.cqframework.cql.elm.execution.IncludeDef in project quality-measure-and-cohort-service by Alvearie.
the class CqlContextFactory method createContext.
/**
* Initialize a CQL context from the values associated with the provided
* CQL Context Key. This encapsulates the set of initializations that are
* static from run to run.
*
* @param contextKey container for stable context settings
* @return initialized CQL Context object
* @throws CqlLibraryDeserializationException if the specified library cannot be loaded
*/
protected Context createContext(ContextCacheKey contextKey) throws CqlLibraryDeserializationException {
LibraryLoader libraryLoader = new ProviderBasedLibraryLoader(contextKey.libraryProvider);
VersionedIdentifier vid = new VersionedIdentifier().withId(contextKey.topLevelLibraryIdentifier.getId()).withVersion(contextKey.topLevelLibraryIdentifier.getVersion());
Library entryPoint = libraryLoader.load(vid);
Context cqlContext;
if (contextKey.evaluationDateTime != null) {
cqlContext = new Context(entryPoint, contextKey.evaluationDateTime, new CqlSystemDataProvider());
} else {
cqlContext = new Context(entryPoint, new CqlSystemDataProvider());
}
cqlContext.registerExternalFunctionProvider(vid, this.externalFunctionProvider);
registerExternalIncludes(cqlContext, cqlContext.getCurrentLibrary());
cqlContext.registerLibraryLoader(libraryLoader);
cqlContext.registerTerminologyProvider(contextKey.terminologyProvider);
if (contextKey.parameters != null) {
Library library = cqlContext.getCurrentLibrary();
for (Map.Entry<String, Parameter> entry : contextKey.parameters.entrySet()) {
Object cqlValue = entry.getValue().toCqlType();
cqlContext.setParameter(library.getLocalId(), entry.getKey(), cqlValue);
}
if (library.getIncludes() != null && library.getIncludes().getDef() != null) {
for (IncludeDef def : library.getIncludes().getDef()) {
String name = def.getLocalIdentifier();
for (Map.Entry<String, Parameter> parameterValue : contextKey.parameters.entrySet()) {
Object cqlValue = parameterValue.getValue().toCqlType();
cqlContext.setParameter(name, parameterValue.getKey(), cqlValue);
}
}
}
}
return cqlContext;
}
Aggregations