use of com.ibm.cohort.cql.hapi.R4TranslatingLibraryLoader in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluationSeeder method create.
public IMeasureEvaluationSeed create(Measure measure, String periodStart, String periodEnd, String productLine, Map<String, Parameter> parameters) {
// Gather the primary library and all of its dependencies
List<Library> fhirLibraries = libraryDependencyGatherer.gatherForMeasure(measure);
if (CollectionUtils.isEmpty(fhirLibraries)) {
throw new IllegalArgumentException(String.format("No libraries were able to be loaded for %s", measure.getId()));
}
// the "primary" library is always the first library loaded for the measure
Library primaryFhirLibrary = fhirLibraries.get(0);
VersionedIdentifier libraryIdentifier = new VersionedIdentifier().withId(primaryFhirLibrary.getName()).withVersion(primaryFhirLibrary.getVersion());
LibraryLoader libraryLoader = new R4TranslatingLibraryLoader(libraryResolver, new CqlToElmTranslator());
org.cqframework.cql.elm.execution.Library primaryLibrary = libraryLoader.load(libraryIdentifier);
List<Triple<String, String, String>> usingDefs = UsingHelper.getUsingUrlAndVersion(primaryLibrary.getUsings());
if (usingDefs.size() > 1) {
throw new IllegalArgumentException("Evaluation of Measure using multiple Models is not supported at this time.");
}
// Per the above condition, we should only have one model per measure
String lastModelUri = usingDefs.get(usingDefs.size() - 1).getRight();
DataProvider dataProvider = dataProviders.get(lastModelUri);
Context context = createContext(primaryLibrary, lastModelUri, dataProvider, productLine, libraryLoader);
// fhir path: Measure.extension[measureParameter][].valueParameterDefinition.extension[defaultValue]
measure.getExtension().stream().filter(MeasureEvaluationSeeder::isMeasureParameter).map(parameter -> dataProvider.resolvePath(parameter, "valueParameterDefinition")).map(ParameterDefinition.class::cast).forEach(parameterDefinition -> setDefaultValue(context, parameterDefinition));
if (parameters != null) {
parameters.entrySet().stream().forEach(e -> context.setParameter(null, e.getKey(), e.getValue().toCqlType()));
}
// Set measurement period last to make sure we respect periodStart
// and periodEnd date boundaries for an execution.
Interval measurementPeriod = createMeasurePeriod(periodStart, periodEnd);
context.setParameter(null, MEASUREMENT_PERIOD, measurementPeriod);
return new CustomMeasureEvaluationSeed(measure, context, measurementPeriod, dataProvider);
}
Aggregations