Search in sources :

Example 6 with R4LibraryDependencyGatherer

use of com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer in project quality-measure-and-cohort-service by Alvearie.

the class MeasureCLI method runWithArgs.

public MeasureEvaluator runWithArgs(String[] args, PrintStream out) throws IOException {
    MeasureEvaluator evaluator = null;
    Arguments arguments = new Arguments();
    Console console = new DefaultConsole(out);
    JCommander jc = JCommander.newBuilder().programName("measure-engine").console(console).addObject(arguments).build();
    jc.parse(args);
    if (arguments.isDisplayHelp) {
        jc.usage();
    } else {
        arguments.validate();
        readDataServerConfiguration(arguments);
        readTerminologyServerConfiguration(arguments);
        FhirClientBuilderFactory fhirClientBuilderFactory = getFhirClientBuilderFactory();
        IGenericClient dataServerClient = fhirClientBuilderFactory.newFhirClientBuilder().createFhirClient(dataServerConfig);
        IGenericClient terminologyServerClient = fhirClientBuilderFactory.newFhirClientBuilder().createFhirClient(terminologyServerConfig);
        String[] filters = (arguments.filters != null) ? arguments.filters.toArray(new String[arguments.filters.size()]) : null;
        IParser parser = getFhirContext().newJsonParser().setPrettyPrint(true);
        R4QualityMeasureResolverFactory resolverFactory = new R4QualityMeasureResolverFactory(parser);
        FhirResourceResolver<Library> libraryResolver;
        FhirResourceResolver<Measure> measureResolver;
        if (arguments.measureServerConfigFile != null && FileHelpers.isZip(arguments.measureServerConfigFile)) {
            R4QualityMeasureResolvers resolvers = resolverFactory.fromZipFile(arguments.measureServerConfigFile.toPath(), filters);
            libraryResolver = resolvers.getLibraryResolver();
            measureResolver = resolvers.getMeasureResolver();
        } else if (arguments.measureServerConfigFile != null && arguments.measureServerConfigFile.isDirectory()) {
            R4QualityMeasureResolvers resolvers = resolverFactory.fromDirectory(arguments.measureServerConfigFile.toPath(), filters);
            libraryResolver = resolvers.getLibraryResolver();
            measureResolver = resolvers.getMeasureResolver();
        } else {
            readMeasureServerConfiguration(arguments);
            IGenericClient measureServerClient = fhirClientBuilderFactory.newFhirClientBuilder().createFhirClient(measureServerConfig);
            libraryResolver = R4FhirServerResourceResolverFactory.createLibraryResolver(measureServerClient);
            measureResolver = R4FhirServerResourceResolverFactory.createMeasureResolver(measureServerClient);
        }
        List<MeasureContext> measureContexts;
        if (arguments.measureConfigurationFile != null) {
            measureContexts = MeasureContextProvider.getMeasureContexts(arguments.measureConfigurationFile);
        } else {
            measureContexts = MeasureContextProvider.getMeasureContexts(arguments.resourceId, arguments.parameters);
        }
        validateMeasureContexts(measureContexts);
        R4LibraryDependencyGatherer libraryDependencyGatherer = new R4LibraryDependencyGatherer(libraryResolver);
        CqlTerminologyProvider terminologyProvider = new R4RestFhirTerminologyProvider(terminologyServerClient);
        try (RetrieveCacheContext retrieveCacheContext = arguments.disableRetrieveCache ? null : new DefaultRetrieveCacheContext()) {
            Map<String, CqlDataProvider> dataProviders = R4DataProviderFactory.createDataProviderMap(dataServerClient, terminologyProvider, retrieveCacheContext, R4FhirModelResolverFactory.createCachingResolver(), !arguments.enableTerminologyOptimization, arguments.searchPageSize);
            evaluator = new MeasureEvaluator(measureResolver, libraryResolver, libraryDependencyGatherer, terminologyProvider, dataProviders);
            for (String contextId : arguments.contextIds) {
                out.println("Evaluating: " + contextId);
                // Reports only returned for measures where patient is in initial population
                List<MeasureReport> reports = evaluator.evaluatePatientMeasures(contextId, measureContexts, new MeasureEvidenceOptions(arguments.includeEvaluatedResources, arguments.defineReturnOption));
                for (MeasureReport report : reports) {
                    if (arguments.reportFormat == ReportFormat.TEXT) {
                        out.println("Result for " + report.getMeasure());
                        for (MeasureReport.MeasureReportGroupComponent group : report.getGroup()) {
                            for (MeasureReport.MeasureReportGroupPopulationComponent pop : group.getPopulation()) {
                                String popCode = pop.getCode().getCodingFirstRep().getCode();
                                if (pop.getId() != null) {
                                    popCode += "(" + pop.getId() + ")";
                                }
                                out.println(String.format("Population: %s = %d", popCode, pop.getCount()));
                            }
                        }
                    } else {
                        out.println(parser.encodeResourceToString(report));
                    }
                    out.println("---");
                }
                if (reports.isEmpty()) {
                    out.println("---");
                }
            }
        }
    }
    return evaluator;
}
Also used : DefaultConsole(com.beust.jcommander.internal.DefaultConsole) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) R4QualityMeasureResolverFactory(com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolverFactory) R4RestFhirTerminologyProvider(com.ibm.cohort.engine.terminology.R4RestFhirTerminologyProvider) DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) RetrieveCacheContext(com.ibm.cohort.engine.measure.cache.RetrieveCacheContext) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) MeasureContext(com.ibm.cohort.engine.measure.MeasureContext) JCommander(com.beust.jcommander.JCommander) Console(com.beust.jcommander.internal.Console) DefaultConsole(com.beust.jcommander.internal.DefaultConsole) Measure(org.hl7.fhir.r4.model.Measure) R4LibraryDependencyGatherer(com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) MeasureEvaluator(com.ibm.cohort.engine.measure.MeasureEvaluator) DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) FhirClientBuilderFactory(com.ibm.cohort.fhir.client.config.FhirClientBuilderFactory) R4QualityMeasureResolvers(com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolvers) Library(org.hl7.fhir.r4.model.Library) IParser(ca.uhn.fhir.parser.IParser)

Example 7 with R4LibraryDependencyGatherer

use of com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer in project quality-measure-and-cohort-service by Alvearie.

the class R4MeasureEvaluatorBuilder method build.

public MeasureEvaluator build() {
    if (clientContext == null) {
        throw new IllegalArgumentException("Client context not provided");
    }
    CqlTerminologyProvider terminologyProvider = new R4RestFhirTerminologyProvider(clientContext.getTerminologyClient());
    Map<String, CqlDataProvider> dataProviders = R4DataProviderFactory.createDataProviderMap(clientContext.getDataClient(), terminologyProvider, cacheContext, isCachingModelResolver ? new CachingModelResolverDecorator(modelResolver) : modelResolver, isExpandValueSets, pageSize);
    FhirResourceResolver<Measure> measureResolver = R4FhirServerResourceResolverFactory.createMeasureResolver(clientContext.getMeasureClient());
    FhirResourceResolver<Library> libraryResolver = R4FhirServerResourceResolverFactory.createLibraryResolver(clientContext.getLibraryClient());
    R4LibraryDependencyGatherer libraryDependencyGatherer = new R4LibraryDependencyGatherer(libraryResolver);
    return new MeasureEvaluator(measureResolver, libraryResolver, libraryDependencyGatherer, terminologyProvider, dataProviders);
}
Also used : CachingModelResolverDecorator(com.ibm.cohort.engine.r4.cache.CachingModelResolverDecorator) R4RestFhirTerminologyProvider(com.ibm.cohort.engine.terminology.R4RestFhirTerminologyProvider) Measure(org.hl7.fhir.r4.model.Measure) R4LibraryDependencyGatherer(com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer) Library(org.hl7.fhir.r4.model.Library) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider)

Example 8 with R4LibraryDependencyGatherer

use of com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer in project quality-measure-and-cohort-service by Alvearie.

the class MeasureEvaluationSeederTest method create_libraryWithMultipleModels.

@Test(expected = IllegalArgumentException.class)
public void create_libraryWithMultipleModels() throws IOException {
    Measure measure = createMeasure();
    FhirResourceResolver<Library> libraryResolver = Mockito.mock(FhirResourceResolver.class);
    R4LibraryDependencyGatherer dependencyGatherer = Mockito.mock(R4LibraryDependencyGatherer.class);
    Mockito.when(dependencyGatherer.gatherForMeasure(measure)).thenReturn(Collections.singletonList(createLibrary("/cql/seeder/MultipleUsings-1.0.0.xml")));
    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)

Aggregations

R4LibraryDependencyGatherer (com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer)8 Library (org.hl7.fhir.r4.model.Library)7 Measure (org.hl7.fhir.r4.model.Measure)7 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)6 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)4 R4RestFhirTerminologyProvider (com.ibm.cohort.engine.terminology.R4RestFhirTerminologyProvider)4 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 IParser (ca.uhn.fhir.parser.IParser)2 JCommander (com.beust.jcommander.JCommander)2 Console (com.beust.jcommander.internal.Console)2 DefaultConsole (com.beust.jcommander.internal.DefaultConsole)2 R4QualityMeasureResolverFactory (com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolverFactory)2 R4QualityMeasureResolvers (com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolvers)2 MeasureEvaluator (com.ibm.cohort.engine.measure.MeasureEvaluator)2 DefaultRetrieveCacheContext (com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext)2 RetrieveCacheContext (com.ibm.cohort.engine.measure.cache.RetrieveCacheContext)2 FhirClientBuilder (com.ibm.cohort.fhir.client.config.FhirClientBuilder)2 FhirClientBuilderFactory (com.ibm.cohort.fhir.client.config.FhirClientBuilderFactory)2