Search in sources :

Example 31 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project hapi-fhir-jpaserver-starter by hapifhir.

the class BaseJpaRestfulServer method initialize.

@SuppressWarnings("unchecked")
@Override
protected void initialize() throws ServletException {
    super.initialize();
    /*
     * Create a FhirContext object that uses the version of FHIR
     * specified in the properties file.
     */
    // Customize supported resource types
    List<String> supportedResourceTypes = appProperties.getSupported_resource_types();
    if (!supportedResourceTypes.isEmpty()) {
        if (!supportedResourceTypes.contains("SearchParameter")) {
            supportedResourceTypes.add("SearchParameter");
        }
        daoRegistry.setSupportedResourceTypes(supportedResourceTypes);
    }
    setFhirContext(fhirSystemDao.getContext());
    /*
     * Order matters - the MDM provider registers itself on the resourceProviderFactory - hence the loading must be done
     * ahead of provider registration
     */
    if (appProperties.getMdm_enabled())
        mdmProviderProvider.get().loadProvider();
    registerProviders(resourceProviderFactory.createProviders());
    registerProvider(jpaSystemProvider);
    /*
     * The conformance provider exports the supported resources, search parameters, etc for
     * this server. The JPA version adds resourceProviders counts to the exported statement, so it
     * is a nice addition.
     *
     * You can also create your own subclass of the conformance provider if you need to
     * provide further customization of your server's CapabilityStatement
     */
    FhirVersionEnum fhirVersion = fhirSystemDao.getContext().getVersion().getVersion();
    if (fhirVersion == FhirVersionEnum.DSTU2) {
        JpaConformanceProviderDstu2 confProvider = new JpaConformanceProviderDstu2(this, fhirSystemDao, daoConfig);
        confProvider.setImplementationDescription("HAPI FHIR DSTU2 Server");
        setServerConformanceProvider(confProvider);
    } else {
        if (fhirVersion == FhirVersionEnum.DSTU3) {
            JpaConformanceProviderDstu3 confProvider = new JpaConformanceProviderDstu3(this, fhirSystemDao, daoConfig, searchParamRegistry);
            confProvider.setImplementationDescription("HAPI FHIR DSTU3 Server");
            setServerConformanceProvider(confProvider);
        } else if (fhirVersion == FhirVersionEnum.R4) {
            JpaCapabilityStatementProvider confProvider = new JpaCapabilityStatementProvider(this, fhirSystemDao, daoConfig, searchParamRegistry, myValidationSupport);
            confProvider.setImplementationDescription("HAPI FHIR R4 Server");
            setServerConformanceProvider(confProvider);
        } else if (fhirVersion == FhirVersionEnum.R5) {
            JpaCapabilityStatementProvider confProvider = new JpaCapabilityStatementProvider(this, fhirSystemDao, daoConfig, searchParamRegistry, myValidationSupport);
            confProvider.setImplementationDescription("HAPI FHIR R5 Server");
            setServerConformanceProvider(confProvider);
        } else {
            throw new IllegalStateException();
        }
    }
    if (appProperties.getEtag_support_enabled() == false)
        setETagSupport(ETagSupportEnum.DISABLED);
    /*
     * This server tries to dynamically generate narratives
     */
    FhirContext ctx = getFhirContext();
    INarrativeGenerator theNarrativeGenerator = appProperties.getNarrative_enabled() ? new DefaultThymeleafNarrativeGenerator() : new NullNarrativeGenerator();
    ctx.setNarrativeGenerator(theNarrativeGenerator);
    /*
     * Default to JSON and pretty printing
     */
    setDefaultPrettyPrint(appProperties.getDefault_pretty_print());
    /*
     * Default encoding
     */
    setDefaultResponseEncoding(appProperties.getDefault_encoding());
    /*
     * This configures the server to page search results to and from
     * the database, instead of only paging them to memory. This may mean
     * a performance hit when performing searches that return lots of results,
     * but makes the server much more scalable.
     */
    setPagingProvider(databaseBackedPagingProvider);
    /*
     * This interceptor formats the output using nice colourful
     * HTML output when the request is detected to come from a
     * browser.
     */
    ResponseHighlighterInterceptor responseHighlighterInterceptor = new ResponseHighlighterInterceptor();
    this.registerInterceptor(responseHighlighterInterceptor);
    if (appProperties.getFhirpath_interceptor_enabled()) {
        registerInterceptor(new FhirPathFilterInterceptor());
    }
    /*
     * Add some logging for each request
     */
    LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
    loggingInterceptor.setLoggerName(appProperties.getLogger().getName());
    loggingInterceptor.setMessageFormat(appProperties.getLogger().getFormat());
    loggingInterceptor.setErrorMessageFormat(appProperties.getLogger().getError_format());
    loggingInterceptor.setLogExceptions(appProperties.getLogger().getLog_exceptions());
    this.registerInterceptor(loggingInterceptor);
    /*
     * If you are hosting this server at a specific DNS name, the server will try to
     * figure out the FHIR base URL based on what the web container tells it, but
     * this doesn't always work. If you are setting links in your search bundles that
     * just refer to "localhost", you might want to use a server address strategy:
     */
    String serverAddress = appProperties.getServer_address();
    if (!Strings.isNullOrEmpty(serverAddress)) {
        setServerAddressStrategy(new HardcodedServerAddressStrategy(serverAddress));
    } else if (appProperties.getUse_apache_address_strategy()) {
        boolean useHttps = appProperties.getUse_apache_address_strategy_https();
        setServerAddressStrategy(useHttps ? ApacheProxyAddressStrategy.forHttps() : ApacheProxyAddressStrategy.forHttp());
    } else {
        setServerAddressStrategy(new IncomingRequestAddressStrategy());
    }
    /*
     * If you are using DSTU3+, you may want to add a terminology uploader, which allows
     * uploading of external terminologies such as Snomed CT. Note that this uploader
     * does not have any security attached (any anonymous user may use it by default)
     * so it is a potential security vulnerability. Consider using an AuthorizationInterceptor
     * with this feature.
     */
    if (ctx.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) {
        // <-- ENABLED RIGHT NOW
        registerProvider(myApplicationContext.getBean(TerminologyUploaderProvider.class));
    }
    // manual triggering of a subscription delivery, enable this provider
    if (true) {
        // <-- ENABLED RIGHT NOW
        registerProvider(myApplicationContext.getBean(SubscriptionTriggeringProvider.class));
    }
    // to your specific needs
    if (appProperties.getCors() != null) {
        ourLog.info("CORS is enabled on this server");
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedHeader(HttpHeaders.ORIGIN);
        config.addAllowedHeader(HttpHeaders.ACCEPT);
        config.addAllowedHeader(HttpHeaders.CONTENT_TYPE);
        config.addAllowedHeader(HttpHeaders.AUTHORIZATION);
        config.addAllowedHeader(HttpHeaders.CACHE_CONTROL);
        config.addAllowedHeader("x-fhir-starter");
        config.addAllowedHeader("X-Requested-With");
        config.addAllowedHeader("Prefer");
        List<String> allAllowedCORSOrigins = appProperties.getCors().getAllowed_origin();
        allAllowedCORSOrigins.forEach(config::addAllowedOriginPattern);
        ourLog.info("CORS allows the following origins: " + String.join(", ", allAllowedCORSOrigins));
        config.addExposedHeader("Location");
        config.addExposedHeader("Content-Location");
        config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "HEAD"));
        config.setAllowCredentials(appProperties.getCors().getAllow_Credentials());
        // Create the interceptor and register it
        CorsInterceptor interceptor = new CorsInterceptor(config);
        registerInterceptor(interceptor);
    } else {
        ourLog.info("CORS is disabled on this server");
    }
    // will activate them and match results against them
    if (appProperties.getSubscription() != null) {
        // Subscription debug logging
        interceptorService.registerInterceptor(new SubscriptionDebugLogInterceptor());
    }
    if (appProperties.getAllow_cascading_deletes()) {
        CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(ctx, daoRegistry, interceptorBroadcaster);
        getInterceptorService().registerInterceptor(cascadingDeleteInterceptor);
    }
    // Binary Storage
    if (appProperties.getBinary_storage_enabled()) {
        getInterceptorService().registerInterceptor(binaryStorageInterceptor);
    }
    if (validatorModule != null) {
        if (appProperties.getValidation().getRequests_enabled()) {
            RequestValidatingInterceptor interceptor = new RequestValidatingInterceptor();
            interceptor.setFailOnSeverity(ResultSeverityEnum.ERROR);
            interceptor.setValidatorModules(Collections.singletonList(validatorModule));
            registerInterceptor(interceptor);
        }
        if (appProperties.getValidation().getResponses_enabled()) {
            ResponseValidatingInterceptor interceptor = new ResponseValidatingInterceptor();
            interceptor.setFailOnSeverity(ResultSeverityEnum.ERROR);
            interceptor.setValidatorModules(Collections.singletonList(validatorModule));
            registerInterceptor(interceptor);
        }
    }
    // GraphQL
    if (appProperties.getGraphql_enabled()) {
        if (fhirVersion.isEqualOrNewerThan(FhirVersionEnum.DSTU3)) {
            registerProvider(graphQLProvider.get());
        }
    }
    if (appProperties.getAllowed_bundle_types() != null) {
        daoConfig.setBundleTypesAllowedForStorage(appProperties.getAllowed_bundle_types().stream().map(BundleType::toCode).collect(Collectors.toSet()));
    }
    daoConfig.setDeferIndexingForCodesystemsOfSize(appProperties.getDefer_indexing_for_codesystems_of_size());
    if (appProperties.getOpenapi_enabled()) {
        registerInterceptor(new OpenApiInterceptor());
    }
    // Bulk Export
    if (appProperties.getBulk_export_enabled()) {
        registerProvider(bulkDataExportProvider);
    }
    // valueSet Operations i.e $expand
    registerProvider(myValueSetOperationProvider);
    // reindex Provider $reindex
    registerProvider(reindexProvider);
    // Partitioning
    if (appProperties.getPartitioning() != null) {
        registerInterceptor(new RequestTenantPartitionInterceptor());
        setTenantIdentificationStrategy(new UrlBaseTenantIdentificationStrategy());
        registerProviders(partitionManagementProvider);
    }
    if (appProperties.getClient_id_strategy() == DaoConfig.ClientIdStrategyEnum.ANY) {
        daoConfig.setResourceServerIdStrategy(DaoConfig.IdStrategyEnum.UUID);
        daoConfig.setResourceClientIdStrategy(appProperties.getClient_id_strategy());
    }
    // Parallel Batch GET execution settings
    daoConfig.setBundleBatchPoolSize(appProperties.getBundle_batch_pool_size());
    daoConfig.setBundleBatchPoolSize(appProperties.getBundle_batch_pool_max_size());
    if (appProperties.getImplementationGuides() != null) {
        Map<String, AppProperties.ImplementationGuide> guides = appProperties.getImplementationGuides();
        for (Map.Entry<String, AppProperties.ImplementationGuide> guide : guides.entrySet()) {
            PackageInstallationSpec packageInstallationSpec = new PackageInstallationSpec().setPackageUrl(guide.getValue().getUrl()).setName(guide.getValue().getName()).setVersion(guide.getValue().getVersion()).setInstallMode(PackageInstallationSpec.InstallModeEnum.STORE_AND_INSTALL);
            if (appProperties.getInstall_transitive_ig_dependencies()) {
                packageInstallationSpec.setFetchDependencies(true);
                packageInstallationSpec.setDependencyExcludes(ImmutableList.of("hl7.fhir.r2.core", "hl7.fhir.r3.core", "hl7.fhir.r4.core", "hl7.fhir.r5.core"));
            }
            packageInstallerSvc.install(packageInstallationSpec);
        }
    }
    if (factory != null) {
        interceptorService.registerInterceptor(factory.buildUsingStoredStructureDefinitions());
    }
    if (appProperties.getLastn_enabled()) {
        daoConfig.setLastNEnabled(true);
    }
    daoConfig.setStoreResourceInLuceneIndex(appProperties.getStore_resource_in_lucene_index_enabled());
    daoConfig.getModelConfig().setNormalizedQuantitySearchLevel(appProperties.getNormalized_quantity_search_level());
    daoConfig.getModelConfig().setIndexOnContainedResources(appProperties.getEnable_index_contained_resource());
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) SubscriptionDebugLogInterceptor(ca.uhn.fhir.jpa.subscription.util.SubscriptionDebugLogInterceptor) FhirVersionEnum(ca.uhn.fhir.context.FhirVersionEnum) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) DefaultThymeleafNarrativeGenerator(ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator) UrlBaseTenantIdentificationStrategy(ca.uhn.fhir.rest.server.tenant.UrlBaseTenantIdentificationStrategy) RequestTenantPartitionInterceptor(ca.uhn.fhir.rest.server.interceptor.partition.RequestTenantPartitionInterceptor) JpaConformanceProviderDstu3(ca.uhn.fhir.jpa.provider.dstu3.JpaConformanceProviderDstu3) CascadingDeleteInterceptor(ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor) INarrativeGenerator(ca.uhn.fhir.narrative.INarrativeGenerator) PackageInstallationSpec(ca.uhn.fhir.jpa.packages.PackageInstallationSpec) CorsConfiguration(org.springframework.web.cors.CorsConfiguration) NullNarrativeGenerator(ca.uhn.fhir.narrative2.NullNarrativeGenerator) OpenApiInterceptor(ca.uhn.fhir.rest.openapi.OpenApiInterceptor)

Example 32 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project cqf-ruler by DBCG.

the class ExpressionEvaluation method evaluateInContext.

/* Evaluates the given CQL expression in the context of the given resource */
/*
	 * If the resource has a library extension, or a library element, that library
	 * is loaded into the context for the expression
	 */
public Object evaluateInContext(DomainResource instance, String cql, Boolean aliasedExpression, String patientId, RequestDetails theRequest) {
    JpaFhirDal jpaFhirDal = jpaFhirDalFactory.create(theRequest);
    List<Reference> libraries = getLibraryReferences(instance, jpaFhirDal, theRequest);
    // String fhirVersion =
    // this.context.getVersion().getVersion().getFhirVersionString();
    String fhirVersion = "3.0.0";
    // temporary LibraryLoader to resolve library dependencies when building
    // includes
    LibraryLoader tempLibraryLoader = libraryLoaderFactory.create(new ArrayList<LibraryContentProvider>(Arrays.asList(jpaLibraryContentProviderFactory.create(theRequest))));
    String source = "";
    if (aliasedExpression) {
        if (libraries.size() != 1) {
            throw new RuntimeException("If an aliased expression is provided, there must be exactly one primary Library");
        }
        VersionedIdentifier vi = getVersionedIdentifierFromReference(libraries.get(0));
        // Still not the best way to build include, but at least checks dal for an
        // existing library
        // Check if id works for LibraryRetrieval
        org.cqframework.cql.elm.execution.Library executionLibrary = null;
        try {
            executionLibrary = tempLibraryLoader.load(vi);
        } catch (Exception e) {
        // log error
        }
        if (executionLibrary == null) {
            Library library = (Library) jpaFhirDal.read(new IdType("Library", vi.getId()));
            vi.setId(library.getName());
            if (library.getVersion() != null) {
                vi.setVersion(library.getVersion());
            }
        }
        // Provide the instance as the value of the '%context' parameter, as well as the
        // value of a parameter named the same as the resource
        // This enables expressions to access the resource by root, as well as through
        // the %context attribute
        source = String.format("library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", buildIncludes(tempLibraryLoader, jpaFhirDal, libraries), instance.fhirType(), instance.fhirType(), instance.fhirType(), vi.getId() + ".\"" + cql + "\"");
    // String source = String.format("library LocalLibrary using FHIR version '1.8'
    // include FHIRHelpers version '1.8' called FHIRHelpers %s parameter %s %s
    // parameter \"%%context\" %s define Expression: %s",
    // buildIncludes(libraries), instance.fhirType(), instance.fhirType(),
    // instance.fhirType(), cql);
    } else {
        // Provide the instance as the value of the '%context' parameter, as well as the
        // value of a parameter named the same as the resource
        // This enables expressions to access the resource by root, as well as through
        // the %context attribute
        source = String.format("library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", buildIncludes(tempLibraryLoader, jpaFhirDal, libraries), instance.fhirType(), instance.fhirType(), instance.fhirType(), cql);
    }
    LibraryLoader libraryLoader = libraryLoaderFactory.create(new ArrayList<LibraryContentProvider>(Arrays.asList(jpaLibraryContentProviderFactory.create(theRequest), new InMemoryLibraryContentProvider(Arrays.asList(source)))));
    // Remove LocalLibrary from cache first...
    VersionedIdentifier localLibraryIdentifier = new VersionedIdentifier().withId("LocalLibrary");
    globalLibraryCache.remove(localLibraryIdentifier);
    Context context = new Context(libraryLoader.load(localLibraryIdentifier));
    context.setDebugMap(getDebugMap());
    context.setParameter(null, instance.fhirType(), instance);
    context.setParameter(null, "%context", instance);
    context.setExpressionCaching(true);
    context.registerLibraryLoader(libraryLoader);
    context.setContextValue("Patient", patientId);
    TerminologyProvider terminologyProvider = jpaTerminologyProviderFactory.create(theRequest);
    context.registerTerminologyProvider(terminologyProvider);
    DataProvider dataProvider = jpaDataProviderFactory.create(theRequest, terminologyProvider);
    context.registerDataProvider("http://hl7.org/fhir", dataProvider);
    return context.resolveExpressionRef("Expression").evaluate(context);
}
Also used : Context(org.opencds.cqf.cql.engine.execution.Context) LibraryContentProvider(org.opencds.cqf.cql.evaluator.cql2elm.content.LibraryContentProvider) InMemoryLibraryContentProvider(org.opencds.cqf.cql.evaluator.cql2elm.content.InMemoryLibraryContentProvider) InMemoryLibraryContentProvider(org.opencds.cqf.cql.evaluator.cql2elm.content.InMemoryLibraryContentProvider) Reference(org.hl7.fhir.dstu3.model.Reference) JpaFhirDal(org.opencds.cqf.ruler.cql.JpaFhirDal) LibraryLoader(org.opencds.cqf.cql.engine.execution.LibraryLoader) IdType(org.hl7.fhir.dstu3.model.IdType) DataProvider(org.opencds.cqf.cql.engine.data.DataProvider) VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) TerminologyProvider(org.opencds.cqf.cql.engine.terminology.TerminologyProvider) Library(org.hl7.fhir.dstu3.model.Library)

Example 33 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project cqf-ruler by DBCG.

the class Server method initialize.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void initialize() throws ServletException {
    super.initialize();
    log.info("Loading metadata extenders from plugins");
    Map<String, MetadataExtender> extenders = myApplicationContext.getBeansOfType(MetadataExtender.class);
    for (MetadataExtender o : extenders.values()) {
        log.info("Found {} extender", o.getClass().getName());
    }
    FhirVersionEnum fhirVersion = fhirSystemDao.getContext().getVersion().getVersion();
    String implementationDescription = myServerProperties.getImplementation_description();
    if (fhirVersion == FhirVersionEnum.DSTU2) {
        List<MetadataExtender<Conformance>> extenderList = extenders.values().stream().map(x -> (MetadataExtender<Conformance>) x).collect(Collectors.toList());
        ExtensibleJpaConformanceProviderDstu2 confProvider = new ExtensibleJpaConformanceProviderDstu2(this, fhirSystemDao, daoConfig, extenderList);
        confProvider.setImplementationDescription(firstNonNull(implementationDescription, "CQF RULER DSTU2 Server"));
        setServerConformanceProvider(confProvider);
    } else {
        if (fhirVersion == FhirVersionEnum.DSTU3) {
            List<MetadataExtender<CapabilityStatement>> extenderList = extenders.values().stream().map(x -> (MetadataExtender<CapabilityStatement>) x).collect(Collectors.toList());
            ExtensibleJpaConformanceProviderDstu3 confProvider = new ExtensibleJpaConformanceProviderDstu3(this, fhirSystemDao, daoConfig, searchParamRegistry, extenderList);
            confProvider.setImplementationDescription(firstNonNull(implementationDescription, "CQF RULER DSTU3 Server"));
            setServerConformanceProvider(confProvider);
        } else if (fhirVersion == FhirVersionEnum.R4) {
            List<MetadataExtender<IBaseConformance>> extenderList = extenders.values().stream().map(x -> (MetadataExtender<IBaseConformance>) x).collect(Collectors.toList());
            ExtensibleJpaCapabilityStatementProvider confProvider = new ExtensibleJpaCapabilityStatementProvider(this, fhirSystemDao, daoConfig, searchParamRegistry, myValidationSupport, extenderList);
            confProvider.setImplementationDescription(firstNonNull(implementationDescription, "CQF RULER R4 Server"));
            setServerConformanceProvider(confProvider);
        } else if (fhirVersion == FhirVersionEnum.R5) {
            List<MetadataExtender<IBaseConformance>> extenderList = extenders.values().stream().map(x -> (MetadataExtender<IBaseConformance>) x).collect(Collectors.toList());
            ExtensibleJpaCapabilityStatementProvider confProvider = new ExtensibleJpaCapabilityStatementProvider(this, fhirSystemDao, daoConfig, searchParamRegistry, myValidationSupport, extenderList);
            confProvider.setImplementationDescription(firstNonNull(implementationDescription, "CQF RULER R5 Server"));
            setServerConformanceProvider(confProvider);
        } else {
            throw new IllegalStateException();
        }
    }
    log.info("Loading operation providers from plugins");
    Map<String, OperationProvider> providers = myApplicationContext.getBeansOfType(OperationProvider.class);
    for (OperationProvider o : providers.values()) {
        log.info("Registering {}", o.getClass().getName());
        this.registerProvider(o);
    }
    log.info("Loading interceptors from plugins");
    Map<String, Interceptor> interceptors = myApplicationContext.getBeansOfType(Interceptor.class);
    for (Interceptor o : interceptors.values()) {
        log.info("Registering {} interceptor", o.getClass().getName());
        this.registerInterceptor(o);
    }
}
Also used : ExtensibleJpaConformanceProviderDstu2(org.opencds.cqf.ruler.capability.ExtensibleJpaConformanceProviderDstu2) DaoConfig(ca.uhn.fhir.jpa.api.config.DaoConfig) ExtensibleJpaConformanceProviderDstu3(org.opencds.cqf.ruler.capability.ExtensibleJpaConformanceProviderDstu3) IValidationSupport(ca.uhn.fhir.context.support.IValidationSupport) ServletException(javax.servlet.ServletException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Interceptor(org.opencds.cqf.ruler.api.Interceptor) OperationProvider(org.opencds.cqf.ruler.api.OperationProvider) BaseJpaRestfulServer(org.opencds.cqf.ruler.external.BaseJpaRestfulServer) ISearchParamRegistry(ca.uhn.fhir.rest.server.util.ISearchParamRegistry) FhirVersionEnum(ca.uhn.fhir.context.FhirVersionEnum) Map(java.util.Map) Conformance(ca.uhn.fhir.model.dstu2.resource.Conformance) ServerProperties(org.opencds.cqf.ruler.config.ServerProperties) Logger(org.slf4j.Logger) IBaseConformance(org.hl7.fhir.instance.model.api.IBaseConformance) AppProperties(org.opencds.cqf.ruler.external.AppProperties) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) CapabilityStatement(org.hl7.fhir.dstu3.model.CapabilityStatement) IFhirSystemDao(ca.uhn.fhir.jpa.api.dao.IFhirSystemDao) MetadataExtender(org.opencds.cqf.ruler.api.MetadataExtender) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) ExtensibleJpaCapabilityStatementProvider(org.opencds.cqf.ruler.capability.ExtensibleJpaCapabilityStatementProvider) FhirVersionEnum(ca.uhn.fhir.context.FhirVersionEnum) ExtensibleJpaConformanceProviderDstu3(org.opencds.cqf.ruler.capability.ExtensibleJpaConformanceProviderDstu3) ExtensibleJpaConformanceProviderDstu2(org.opencds.cqf.ruler.capability.ExtensibleJpaConformanceProviderDstu2) ExtensibleJpaCapabilityStatementProvider(org.opencds.cqf.ruler.capability.ExtensibleJpaCapabilityStatementProvider) OperationProvider(org.opencds.cqf.ruler.api.OperationProvider) List(java.util.List) IBaseConformance(org.hl7.fhir.instance.model.api.IBaseConformance) Interceptor(org.opencds.cqf.ruler.api.Interceptor) MetadataExtender(org.opencds.cqf.ruler.api.MetadataExtender)

Example 34 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project cqf-ruler by DBCG.

the class FhirVersionsTest method testGetFhirVersionUnknownClass.

@Test
public void testGetFhirVersionUnknownClass() {
    Library library = new Library();
    FhirVersionEnum fhirVersion = FhirVersions.forClass(library.getClass());
    assertEquals(FhirVersionEnum.DSTU3, fhirVersion);
}
Also used : FhirVersionEnum(ca.uhn.fhir.context.FhirVersionEnum) Library(org.hl7.fhir.dstu3.model.Library) Test(org.junit.jupiter.api.Test)

Example 35 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project ab2d by CMSgov.

the class EndToEndBfdTests method testPatientEndpoint.

@ParameterizedTest
@MethodSource("getVersion")
public void testPatientEndpoint(FhirVersion version, String contract, int month, int year) {
    BFDClient.BFD_BULK_JOB_ID.set("TEST");
    log.info("Testing IDs for " + version.toString());
    List<PatientIdentifier> patientIds = new ArrayList<>();
    log.info(String.format("Do Request for %s for %02d/%04d", contract, month, year));
    IBaseBundle bundle = client.requestPartDEnrolleesFromServer(version, contract, month, year);
    assertNotNull(bundle);
    int numberOfBenes = BundleUtils.getEntries(bundle).size();
    patientIds.addAll(extractIds(bundle, version));
    log.info("Found: " + numberOfBenes + " benes");
    while (BundleUtils.getNextLink(bundle) != null) {
        log.info(String.format("Do Next Request for %s for %02d/%04d", contract, month, year));
        bundle = client.requestNextBundleFromServer(version, bundle);
        numberOfBenes += BundleUtils.getEntries(bundle).size();
        log.info("Found: " + numberOfBenes + " benes");
        patientIds.addAll(extractIds(bundle, version));
    }
    log.info("Contract: " + contract + " has " + numberOfBenes + " benes with " + patientIds.size() + " ids");
    assertTrue(patientIds.size() >= 1000);
    assertEquals(0, patientIds.size() % 1000);
    assertTrue(patientIds.size() >= (2 * numberOfBenes));
}
Also used : ArrayList(java.util.ArrayList) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) PatientIdentifier(gov.cms.ab2d.fhir.PatientIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ArrayList (java.util.ArrayList)10 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)9 JsonObject (com.google.gson.JsonObject)8 Date (java.util.Date)8 IOException (java.io.IOException)7 FhirContext (ca.uhn.fhir.context.FhirContext)6 JsonArray (com.google.gson.JsonArray)6 HashMap (java.util.HashMap)5 FhirVersionEnum (ca.uhn.fhir.context.FhirVersionEnum)4 IParser (ca.uhn.fhir.parser.IParser)4 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)4 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)4 JsonPrimitive (com.google.gson.JsonPrimitive)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 Bundle (org.hl7.fhir.r4.model.Bundle)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 CascadingDeleteInterceptor (ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor)2