Search in sources :

Example 1 with R4QualityMeasureResolvers

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

the class CohortEngineRestHandler method createMeasureEvaluator.

private MeasureEvaluator createMeasureEvaluator(InputStream inputStream, FhirServerConfig dataServerConfig, FhirServerConfig terminologyServerConfig, Boolean expandValueSets, Integer searchPageSize, RetrieveCacheContext retrieveCacheContext, FhirContext fhirContext) throws IOException {
    FhirClientBuilder clientBuilder = FhirClientBuilderFactory.newInstance().newFhirClientBuilder(fhirContext);
    IGenericClient dataClient = clientBuilder.createFhirClient(dataServerConfig);
    IGenericClient terminologyClient = dataClient;
    if (terminologyServerConfig != null) {
        terminologyClient = clientBuilder.createFhirClient(terminologyServerConfig);
    }
    IParser parser = dataClient.getFhirContext().newJsonParser();
    String[] searchPaths = new String[] { "fhirResources", "fhirResources/libraries" };
    R4QualityMeasureResolverFactory resolverFactory = new R4QualityMeasureResolverFactory(parser);
    R4QualityMeasureResolvers resolvers = resolverFactory.fromZipStream(new ZipInputStream(inputStream), searchPaths);
    FhirResourceResolver<Library> libraryResolver = resolvers.getLibraryResolver();
    FhirResourceResolver<Measure> measureResolver = resolvers.getMeasureResolver();
    R4LibraryDependencyGatherer libraryDependencyGatherer = new R4LibraryDependencyGatherer(libraryResolver);
    CqlTerminologyProvider terminologyProvider = new R4RestFhirTerminologyProvider(terminologyClient);
    if (expandValueSets == null) {
        expandValueSets = R4DataProviderFactory.DEFAULT_IS_EXPAND_VALUE_SETS;
    }
    if (searchPageSize == null) {
        searchPageSize = R4DataProviderFactory.DEFAULT_PAGE_SIZE;
    }
    Map<String, CqlDataProvider> dataProviders = R4DataProviderFactory.createDataProviderMap(dataClient, terminologyProvider, retrieveCacheContext, R4FhirModelResolverFactory.createCachingResolver(), expandValueSets, searchPageSize);
    return new MeasureEvaluator(measureResolver, libraryResolver, libraryDependencyGatherer, terminologyProvider, dataProviders);
}
Also used : FhirClientBuilder(com.ibm.cohort.fhir.client.config.FhirClientBuilder) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) R4QualityMeasureResolverFactory(com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolverFactory) R4RestFhirTerminologyProvider(com.ibm.cohort.engine.terminology.R4RestFhirTerminologyProvider) MeasureEvaluator(com.ibm.cohort.engine.measure.MeasureEvaluator) ZipInputStream(java.util.zip.ZipInputStream) Measure(org.hl7.fhir.r4.model.Measure) R4QualityMeasureResolvers(com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolvers) 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) IParser(ca.uhn.fhir.parser.IParser)

Example 2 with R4QualityMeasureResolvers

use of com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolvers 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)

Aggregations

IParser (ca.uhn.fhir.parser.IParser)2 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)2 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)2 R4LibraryDependencyGatherer (com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer)2 R4QualityMeasureResolverFactory (com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolverFactory)2 R4QualityMeasureResolvers (com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolvers)2 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)2 MeasureEvaluator (com.ibm.cohort.engine.measure.MeasureEvaluator)2 R4RestFhirTerminologyProvider (com.ibm.cohort.engine.terminology.R4RestFhirTerminologyProvider)2 Library (org.hl7.fhir.r4.model.Library)2 Measure (org.hl7.fhir.r4.model.Measure)2 JCommander (com.beust.jcommander.JCommander)1 Console (com.beust.jcommander.internal.Console)1 DefaultConsole (com.beust.jcommander.internal.DefaultConsole)1 MeasureContext (com.ibm.cohort.engine.measure.MeasureContext)1 DefaultRetrieveCacheContext (com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext)1 RetrieveCacheContext (com.ibm.cohort.engine.measure.cache.RetrieveCacheContext)1 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)1 FhirClientBuilder (com.ibm.cohort.fhir.client.config.FhirClientBuilder)1 FhirClientBuilderFactory (com.ibm.cohort.fhir.client.config.FhirClientBuilderFactory)1