Search in sources :

Example 66 with Library

use of org.hl7.fhir.r4b.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class RestFhirLibraryResolverIntegrationTest method resolveLibraryByCanonicalUrl_twice___returns_cached_data.

@Test
public void resolveLibraryByCanonicalUrl_twice___returns_cached_data() throws Exception {
    resolver = new CachingFhirResourceResolver<>(resolver);
    Library library = getLibrary("Test", DEFAULT_VERSION, "cql/basic/Test-1.0.0.cql");
    library.setUrl(TEST_URL);
    Library actual = runTest(TEST_URL, makeBundle(library));
    assertNotNull(actual);
    assertEquals(library.getUrl(), actual.getUrl());
    resolver.resolveByCanonicalUrl(TEST_URL);
    verify(1, getRequestedFor(urlMatching("/Library\\?url=.*")));
}
Also used : Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Example 67 with Library

use of org.hl7.fhir.r4b.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class RestFhirLibraryResolverIntegrationTest method resolveLibraryByCanonicalUrl___exception_when_multiple_library_found.

@Test(expected = IllegalArgumentException.class)
public void resolveLibraryByCanonicalUrl___exception_when_multiple_library_found() throws Exception {
    Library library1 = getLibrary("Test", DEFAULT_VERSION, "cql/basic/Test-1.0.0.cql");
    library1.setUrl(TEST_URL);
    Library library2 = getLibrary("Test", DEFAULT_VERSION, "cql/basic/Test-1.0.0.cql");
    library2.setUrl(TEST_URL);
    runTest(TEST_URL, makeBundle(library1, library2));
}
Also used : Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Example 68 with Library

use of org.hl7.fhir.r4b.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class MeasureEvaluationSeederTest method create_noLibraryOnMeasure.

@Test(expected = IllegalArgumentException.class)
public void create_noLibraryOnMeasure() {
    Measure measure = createMeasure();
    FhirResourceResolver<Library> libraryResolver = Mockito.mock(FhirResourceResolver.class);
    R4LibraryDependencyGatherer dependencyGatherer = Mockito.mock(R4LibraryDependencyGatherer.class);
    Mockito.when(dependencyGatherer.gatherForMeasure(measure)).thenReturn(Collections.emptyList());
    MeasureEvaluationSeeder seeder = new MeasureEvaluationSeeder(null, null, dependencyGatherer, libraryResolver);
    seeder.create(measure, periodStart, periodEnd, null, null);
}
Also used : Measure(org.hl7.fhir.r4.model.Measure) R4LibraryDependencyGatherer(com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer) Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Example 69 with Library

use of org.hl7.fhir.r4b.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class MeasureEvaluationSeederTest method create_fullContext.

@Test
public void create_fullContext() throws IOException {
    TerminologyProvider terminologyProvider = Mockito.mock(TerminologyProvider.class);
    CqlDataProvider dataProvider = Mockito.mock(CqlDataProvider.class);
    Map<String, CqlDataProvider> dataProviders = new HashMap<>();
    dataProviders.put(fhirUri, dataProvider);
    Measure measure = createMeasure();
    Library library = createLibrary("/cql/seeder/Test-1.0.0.xml");
    FhirResourceResolver<Library> libraryResolver = Mockito.mock(FhirResourceResolver.class);
    Mockito.when(libraryResolver.resolveByName(libraryName, libraryVersion)).thenReturn(library);
    R4LibraryDependencyGatherer dependencyGatherer = Mockito.mock(R4LibraryDependencyGatherer.class);
    Mockito.when(dependencyGatherer.gatherForMeasure(measure)).thenReturn(Collections.singletonList(library));
    MeasureEvaluationSeeder seeder = new MeasureEvaluationSeeder(terminologyProvider, dataProviders, dependencyGatherer, libraryResolver);
    seeder.enableExpressionCaching();
    IMeasureEvaluationSeed actual = seeder.create(measure, periodStart, periodEnd, productLine, null);
    Interval expectedInterval = createInterval();
    Assert.assertEquals(0, expectedInterval.compareTo(actual.getMeasurementPeriod()));
    Assert.assertSame(measure, actual.getMeasure());
    Assert.assertSame(dataProvider, actual.getDataProvider());
    // Attempt to validate the `Context` by looking for key fields under our control.
    Assert.assertSame(terminologyProvider, actual.getContext().resolveTerminologyProvider());
    Assert.assertEquals(productLine, actual.getContext().resolveParameterRef(null, "Product Line"));
    Assert.assertTrue(actual.getContext().isExpressionCachingEnabled());
    Assert.assertNotNull(actual.getContext().getDebugMap());
}
Also used : TerminologyProvider(org.opencds.cqf.cql.engine.terminology.TerminologyProvider) HashMap(java.util.HashMap) Measure(org.hl7.fhir.r4.model.Measure) R4LibraryDependencyGatherer(com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer) Library(org.hl7.fhir.r4.model.Library) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) Interval(org.opencds.cqf.cql.engine.runtime.Interval) Test(org.junit.Test)

Example 70 with Library

use of org.hl7.fhir.r4b.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class MeasureEvaluationSeederTest method create_minimalContext.

@Test
public void create_minimalContext() throws IOException {
    TerminologyProvider terminologyProvider = Mockito.mock(TerminologyProvider.class);
    CqlDataProvider dataProvider = Mockito.mock(CqlDataProvider.class);
    Map<String, CqlDataProvider> dataProviders = new HashMap<>();
    dataProviders.put(fhirUri, dataProvider);
    Library library = createLibrary("/cql/seeder/Test-1.0.0.xml");
    FhirResourceResolver<Library> libraryResolver = Mockito.mock(FhirResourceResolver.class);
    Mockito.when(libraryResolver.resolveByName(libraryName, libraryVersion)).thenReturn(library);
    Measure measure = createMeasure();
    R4LibraryDependencyGatherer dependencyGatherer = Mockito.mock(R4LibraryDependencyGatherer.class);
    Mockito.when(dependencyGatherer.gatherForMeasure(measure)).thenReturn(Collections.singletonList(library));
    MeasureEvaluationSeeder seeder = new MeasureEvaluationSeeder(terminologyProvider, dataProviders, dependencyGatherer, libraryResolver);
    seeder.disableDebugLogging();
    IMeasureEvaluationSeed actual = seeder.create(measure, periodStart, periodEnd, null, null);
    Interval expectedInterval = createInterval();
    Assert.assertEquals(0, expectedInterval.compareTo(actual.getMeasurementPeriod()));
    Assert.assertSame(measure, actual.getMeasure());
    Assert.assertSame(dataProvider, actual.getDataProvider());
    // Attempt to validate the `Context` by looking for key fields under our control.
    Assert.assertSame(terminologyProvider, actual.getContext().resolveTerminologyProvider());
    Assert.assertThrows(NullPointerException.class, () -> actual.getContext().resolveParameterRef(null, "Product Line"));
    Assert.assertFalse(actual.getContext().isExpressionCachingEnabled());
    Assert.assertNull(actual.getContext().getDebugMap());
}
Also used : TerminologyProvider(org.opencds.cqf.cql.engine.terminology.TerminologyProvider) HashMap(java.util.HashMap) Measure(org.hl7.fhir.r4.model.Measure) R4LibraryDependencyGatherer(com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer) Library(org.hl7.fhir.r4.model.Library) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) Interval(org.opencds.cqf.cql.engine.runtime.Interval) Test(org.junit.Test)

Aggregations

Library (org.hl7.fhir.r4.model.Library)130 Test (org.junit.Test)85 Measure (org.hl7.fhir.r4.model.Measure)60 Patient (org.hl7.fhir.r4.model.Patient)41 HashMap (java.util.HashMap)36 Test (org.junit.jupiter.api.Test)34 ArrayList (java.util.ArrayList)32 Library (org.hl7.fhir.dstu3.model.Library)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 CapabilityStatement (org.hl7.fhir.r4.model.CapabilityStatement)21 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)21 StringType (org.hl7.fhir.r4.model.StringType)21 IOException (java.io.IOException)20 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)20 FhirContext (ca.uhn.fhir.context.FhirContext)19 IParser (ca.uhn.fhir.parser.IParser)19 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)19 Bundle (org.hl7.fhir.r4.model.Bundle)19 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)18