Search in sources :

Example 26 with VersionedIdentifier

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);
}
Also used : CDMContext(com.ibm.cohort.engine.cqfruler.CDMContext) Context(org.opencds.cqf.cql.engine.execution.Context) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) R4TranslatingLibraryLoader(com.ibm.cohort.cql.hapi.R4TranslatingLibraryLoader) LibraryLoader(org.opencds.cqf.cql.engine.execution.LibraryLoader) Triple(org.apache.commons.lang3.tuple.Triple) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) DataProvider(org.opencds.cqf.cql.engine.data.DataProvider) VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) Library(org.hl7.fhir.r4.model.Library) R4TranslatingLibraryLoader(com.ibm.cohort.cql.hapi.R4TranslatingLibraryLoader) Interval(org.opencds.cqf.cql.engine.runtime.Interval)

Example 27 with VersionedIdentifier

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;
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) CDMContext(com.ibm.cohort.engine.cqfruler.CDMContext) Library(org.cqframework.cql.elm.execution.Library) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 28 with VersionedIdentifier

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;
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) HashMap(java.util.HashMap) Patient(org.hl7.fhir.r4.model.Patient) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 29 with VersionedIdentifier

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());
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Example 30 with VersionedIdentifier

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());
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Aggregations

VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)40 Test (org.junit.Test)14 Library (org.hl7.fhir.r4.model.Library)13 LibraryLoader (org.opencds.cqf.cql.engine.execution.LibraryLoader)11 HashMap (java.util.HashMap)8 Map (java.util.Map)7 Library (org.cqframework.cql.elm.execution.Library)6 Context (org.opencds.cqf.cql.engine.execution.Context)6 TerminologyProvider (org.opencds.cqf.cql.engine.terminology.TerminologyProvider)5 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 Library (org.hl7.fhir.dstu3.model.Library)4 IdType (org.hl7.fhir.r4.model.IdType)4 FhirContext (ca.uhn.fhir.context.FhirContext)3 SystemRequestDetails (ca.uhn.fhir.jpa.partition.SystemRequestDetails)3 Operation (ca.uhn.fhir.rest.annotation.Operation)3 TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 BooleanType (org.hl7.fhir.r4.model.BooleanType)3