use of org.cqframework.cql.elm.execution.VersionedIdentifier 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);
}
use of org.cqframework.cql.elm.execution.VersionedIdentifier 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.VersionedIdentifier in project quality-measure-and-cohort-service by Alvearie.
the class CDMMeasureEvaluationTest method setupTestExpectedResultsContext.
private Map<VersionedIdentifier, Map<String, Object>> setupTestExpectedResultsContext() {
VersionedIdentifier libraryId1 = new VersionedIdentifier();
libraryId1.setId("LibraryName1");
libraryId1.setVersion(MeasureEvaluatorTest.DEFAULT_VERSION);
VersionedIdentifier libraryId2 = new VersionedIdentifier();
libraryId2.setId("LibraryName2");
libraryId2.setVersion(MeasureEvaluatorTest.DEFAULT_VERSION);
String define1 = "Define 1";
String define2 = "Define 2";
String define3 = "Define 3";
boolean boolVal1 = true;
boolean boolVal2 = false;
String stringVal = "Hello";
Patient patientRef = new Patient();
Map<VersionedIdentifier, Map<String, Object>> expectedResults = new HashMap<>();
Map<String, Object> library1ExpectedResults = Stream.of(new AbstractMap.SimpleEntry<>(define1, boolVal1), new AbstractMap.SimpleEntry<>(define2, boolVal2)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Map<String, Object> library2ExpectedResults = Stream.of(new AbstractMap.SimpleEntry<>(define1, patientRef), new AbstractMap.SimpleEntry<>(define2, stringVal), new AbstractMap.SimpleEntry<>(define3, boolVal1)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
expectedResults.put(libraryId1, library1ExpectedResults);
expectedResults.put(libraryId2, library2ExpectedResults);
return expectedResults;
}
use of org.cqframework.cql.elm.execution.VersionedIdentifier in project quality-measure-and-cohort-service by Alvearie.
the class R4TranslatingLibraryLoaderTest method load_validCqlAndElm.
@Test
public void load_validCqlAndElm() throws IOException {
Library library = new Library();
withIdentifiers(library, NAME, VERSION);
withContent(library, "/cql/basic/Test-1.0.0.xml", "application/elm+xml");
R4TranslatingLibraryLoader loader = getLoader(getLibraryResolver(NAME, VERSION, library));
VersionedIdentifier identifier = new VersionedIdentifier().withId(NAME).withVersion(VERSION);
org.cqframework.cql.elm.execution.Library actual = loader.load(identifier);
Assert.assertEquals(identifier, actual.getIdentifier());
Assert.assertEquals(4, actual.getStatements().getDef().size());
}
use of org.cqframework.cql.elm.execution.VersionedIdentifier in project quality-measure-and-cohort-service by Alvearie.
the class R4TranslatingLibraryLoaderTest method load_validElm.
@Test
public void load_validElm() throws IOException {
Library library = new Library();
withIdentifiers(library, NAME, VERSION);
withContent(library, "/cql/basic/Test-1.0.0.cql", "text/cql");
withContent(library, "/cql/basic/Test-1.0.0.xml", "application/elm+xml");
R4TranslatingLibraryLoader loader = getLoader(getLibraryResolver(NAME, VERSION, library));
VersionedIdentifier identifier = new VersionedIdentifier().withId(NAME).withVersion(VERSION);
org.cqframework.cql.elm.execution.Library actual = loader.load(identifier);
Assert.assertEquals(identifier, actual.getIdentifier());
Assert.assertEquals(4, actual.getStatements().getDef().size());
}
Aggregations