Search in sources :

Example 1 with CapabilityStatement

use of org.hl7.fhir.r4.model.CapabilityStatement in project gpconnect-demonstrator by nhsconnect.

the class GpConnectServerCapabilityStatementProvider method getServerConformance.

@Override
public CapabilityStatement getServerConformance(HttpServletRequest theRequest) {
    final boolean FROM_JSON = true;
    CapabilityStatement capabilityStatement = null;
    if (!FROM_JSON) {
        // Get the automatically generated statement
        capabilityStatement = super.getServerConformance(theRequest);
        // added at 1.2.2 force overwrite the default entries which are not correct
        for (CapabilityStatement.CapabilityStatementRestComponent st : capabilityStatement.getRest()) {
            for (CapabilityStatement.CapabilityStatementRestOperationComponent operation : st.getOperation()) {
                String opPlusDollar = "$" + operation.getName();
                switch(opPlusDollar) {
                    case REGISTER_PATIENT_OPERATION_NAME:
                        operation.getDefinition().setReference(OD_GPC_REGISTER_PATIENT);
                        break;
                    case GET_STRUCTURED_RECORD_OPERATION_NAME:
                        operation.getDefinition().setReference(OD_GPC_GET_STRUCTURED_RECORD);
                        break;
                }
            }
        }
    } else {
        try {
            // 1.2.6 #316
            String interactionId = theRequest.getHeader(SSP_INTERACTIONID);
            String capabilityFile = null;
            switch(interactionId) {
                case REST_READ_STRUCTURED_METADATA:
                    capabilityFile = "structured_capability.json";
                    break;
                default:
                    capabilityFile = "capability.json";
            }
            // read a json capability file
            String capabilityJson = new String(Files.readAllBytes(Paths.get(FhirRequestGenericIntercepter.getConfigPath() + "/" + capabilityFile)));
            FhirContext ctx = FhirContext.forDstu3();
            capabilityStatement = (CapabilityStatement) ctx.newJsonParser().parseResource(capabilityJson);
        } catch (IOException ex) {
            return null;
        }
    }
    // And add additional required information
    capabilityStatement.setVersion(SystemVariable.VERSION);
    capabilityStatement.setDescription("This server implements the GP Connect API version " + SystemVariable.VERSION);
    capabilityStatement.setName("GP Connect");
    capabilityStatement.setCopyright("Copyright NHS Digital 2018");
    capabilityStatement.getSoftware().setReleaseDate(Date.valueOf(LocalDate.parse("2017-09-27")));
    return capabilityStatement;
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) CapabilityStatement(org.hl7.fhir.dstu3.model.CapabilityStatement) IOException(java.io.IOException)

Example 2 with CapabilityStatement

use of org.hl7.fhir.r4.model.CapabilityStatement in project beneficiary-fhir-data by CMSgov.

the class V2Server method configureServerInfoMetadata.

/**
 * Configures various metadata fields that will be included in this server's {@link
 * CapabilityStatement}.
 */
private void configureServerInfoMetadata() {
    setServerName(CAPABILITIES_SERVER_NAME);
    /*
     * Read in some of the project metadata from a Maven-filtered properties
     * file, which ensures that it's always up to date.
     */
    Properties projectProps = new Properties();
    try (InputStream projectPropsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("project.properties")) {
        projectProps.load(projectPropsStream);
        setImplementationDescription(projectProps.getProperty("project.id"));
        setServerVersion(projectProps.getProperty("project.version"));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    // Lightly customize the capability provider to set publisher name.
    ServerCapabilityStatementProvider capabilityStatementProvider = new ServerCapabilityStatementProvider();
    capabilityStatementProvider.setPublisher(CAPABILITIES_PUBLISHER);
    setServerConformanceProvider(capabilityStatementProvider);
}
Also used : InputStream(java.io.InputStream) ServerCapabilityStatementProvider(org.hl7.fhir.r4.hapi.rest.server.ServerCapabilityStatementProvider) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Properties(java.util.Properties)

Example 3 with CapabilityStatement

use of org.hl7.fhir.r4.model.CapabilityStatement in project kindling by HL7.

the class Publisher method addToResourceFeed.

private void addToResourceFeed(CapabilityStatement cs, Bundle dest) throws Exception {
    if (cs.getId() == null)
        throw new Exception("Resource has no id");
    if (ResourceUtilities.getById(dest, ResourceType.ValueSet, cs.getId()) != null)
        throw new Exception("Attempt to add duplicate Conformance " + cs.getId());
    if (!cs.hasText() || !cs.getText().hasDiv()) {
        RendererFactory.factory(cs, page.getRc().copy()).render(cs);
    }
    if (!cs.hasText() || cs.getText().getDiv() == null)
        System.out.println("WARNING: Example CapabilityStatement " + cs.getId() + " does not have any narrative");
    // Changed this from an exception to a warning because generateConformanceStatement doesn't produce narrative if
    // "register" is 'false'
    ResourceUtilities.meta(cs).setLastUpdated(page.getGenDate().getTime());
    if (!cs.getUrl().equals("http://hl7.org/fhir/" + cs.getResourceType().toString() + "/" + cs.getId()))
        throw new Exception("URL mismatch on CapabilityStatement");
    dest.getEntry().add(new BundleEntryComponent().setResource(cs).setFullUrl("http://hl7.org/fhir/" + cs.fhirType() + "/" + cs.getId()));
}
Also used : BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with CapabilityStatement

use of org.hl7.fhir.r4.model.CapabilityStatement in project cqf-ruler by DBCG.

the class OAuthProvider method extend.

@Override
public void extend(CapabilityStatement metadata) {
    metadata.getRestFirstRep().getSecurity().setCors(securityProperties.getOAuth().getSecurityCors());
    Extension securityExtension = metadata.getRestFirstRep().getSecurity().addExtension();
    securityExtension.setUrl(securityProperties.getOAuth().getSecurityUrl());
    // security.extension.extension
    Extension securityExtExt = securityExtension.addExtension();
    securityExtExt.setUrl(securityProperties.getOAuth().getSecurityExtAuthUrl());
    securityExtExt.setValue(new UriType(securityProperties.getOAuth().getSecurityExtAuthValueUri()));
    Extension securityTokenExt = securityExtension.addExtension();
    securityTokenExt.setUrl(securityProperties.getOAuth().getSecurityExtTokenUrl());
    securityTokenExt.setValue(new UriType(securityProperties.getOAuth().getSecurityExtTokenValueUri()));
    // security.extension.service
    Coding coding = new Coding();
    coding.setSystem(securityProperties.getOAuth().getServiceSystem());
    coding.setCode(securityProperties.getOAuth().getServiceCode());
    coding.setDisplay(securityProperties.getOAuth().getServiceDisplay());
    CodeableConcept codeConcept = new CodeableConcept();
    codeConcept.addCoding(coding);
    metadata.getRestFirstRep().getSecurity().getService().add(codeConcept);
// metadata.getRestFirstRep().getSecurity().getService() //how do we handle "text" on the sample not part of getService
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Coding(org.hl7.fhir.dstu3.model.Coding) UriType(org.hl7.fhir.dstu3.model.UriType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 5 with CapabilityStatement

use of org.hl7.fhir.r4.model.CapabilityStatement 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() && !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(valueSetOperationProvider);
    // 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) SubscriptionTriggeringProvider(ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider) CorsInterceptor(ca.uhn.fhir.rest.server.interceptor.CorsInterceptor) FhirPathFilterInterceptor(ca.uhn.fhir.rest.server.interceptor.FhirPathFilterInterceptor) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) ResponseHighlighterInterceptor(ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor) DefaultThymeleafNarrativeGenerator(ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator) TerminologyUploaderProvider(ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider) UrlBaseTenantIdentificationStrategy(ca.uhn.fhir.rest.server.tenant.UrlBaseTenantIdentificationStrategy) RequestValidatingInterceptor(ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor) JpaCapabilityStatementProvider(ca.uhn.fhir.jpa.provider.JpaCapabilityStatementProvider) RequestTenantPartitionInterceptor(ca.uhn.fhir.rest.server.interceptor.partition.RequestTenantPartitionInterceptor) JpaConformanceProviderDstu3(ca.uhn.fhir.jpa.provider.dstu3.JpaConformanceProviderDstu3) LoggingInterceptor(ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor) IncomingRequestAddressStrategy(ca.uhn.fhir.rest.server.IncomingRequestAddressStrategy) CascadingDeleteInterceptor(ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor) JpaConformanceProviderDstu2(ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2) INarrativeGenerator(ca.uhn.fhir.narrative.INarrativeGenerator) ResponseValidatingInterceptor(ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor) 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) Map(java.util.Map) HardcodedServerAddressStrategy(ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy)

Aggregations

CapabilityStatement (org.hl7.fhir.r4.model.CapabilityStatement)36 Test (org.junit.Test)24 Patient (org.hl7.fhir.r4.model.Patient)22 Library (org.hl7.fhir.r4.model.Library)20 Measure (org.hl7.fhir.r4.model.Measure)20 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)18 ArrayList (java.util.ArrayList)17 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)16 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)15 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)14 Date (java.util.Date)10 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)10 HashMap (java.util.HashMap)9 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)9 Coding (org.hl7.fhir.r4.model.Coding)9 StringType (org.hl7.fhir.r4.model.StringType)9 Map (java.util.Map)8 Extension (org.hl7.fhir.r4.model.Extension)8 IOException (java.io.IOException)6 List (java.util.List)6