Exemplo n.º 1
0
            /// <summary>
            /// Creates a new dispatcher for the channel
            /// </summary>
            public Dispatcher(Guid channelKey, Uri endpoint, IDictionary <String, String> settings)
            {
                this.Key      = channelKey;
                this.Endpoint = endpoint;
                this.Settings = settings;

                this.m_configuration = ApplicationServiceContext.Current.GetService <IConfigurationManager>()?.GetSection <FhirDispatcherConfigurationSection>()?.Targets.Find(o => o.Endpoint == endpoint.ToString());

                settings.TryGetValue("Content-Type", out string contentType);

                // The client for this object
                this.m_client = new FhirClient(this.Endpoint, new FhirClientSettings()
                {
                    ParserSettings = new Hl7.Fhir.Serialization.ParserSettings()
                    {
                        AllowUnrecognizedEnums = true,
                        PermissiveParsing      = true,
                        AcceptUnknownMembers   = true
                    },
                    PreferredFormat           = ContentType.GetResourceFormatFromFormatParam(contentType ?? "xml"),
                    PreferCompressedResponses = true,
                    VerifyFhirVersion         = false
                });

                foreach (var kv in this.Settings.Where(z => z.Key != "Content-Type" && !z.Key.StartsWith("$")))
                {
                    this.m_client.RequestHeaders.Add(kv.Key, kv.Value);
                }

                if (this.m_configuration?.Authenticator != null)
                {
                    var authenticator = this.m_configuration.Authenticator.Type.CreateInjected() as IFhirClientAuthenticator;
                    authenticator.AttachClient(this.m_client, this.m_configuration, settings);
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new audit dispatcher
        /// </summary>
        public FhirAuditDispatcher(IConfigurationManager configurationManager, IServiceManager serviceManager)
        {
            this.m_configuration = configurationManager.GetSection <FhirDispatcherConfigurationSection>().Targets.Find(o => o.Name.Equals("audit", StringComparison.OrdinalIgnoreCase));
            if (this.m_configuration == null)
            {
                throw new InvalidOperationException("Cannot find a dispatcher configuration named Audit");
            }

            // The client for this object
            this.m_client = new FhirClient(this.m_configuration.Endpoint, new FhirClientSettings()
            {
                ParserSettings = new Hl7.Fhir.Serialization.ParserSettings()
                {
                    AllowUnrecognizedEnums = true,
                    PermissiveParsing      = true
                },
                PreferredFormat           = ResourceFormat.Xml,
                PreferCompressedResponses = true,
                VerifyFhirVersion         = false
            });

            // Attach authenticator
            if (this.m_configuration.Authenticator?.Type != null)
            {
                this.m_authenticator = serviceManager.CreateInjected(this.m_configuration.Authenticator.Type) as IFhirClientAuthenticator;
                this.m_authenticator.AttachClient(this.m_client, this.m_configuration, null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Configure the feature
        /// </summary>
        public void Configure(SanteDBConfiguration configuration, IDictionary <string, string> settings)
        {
            var fhirConfiguration = configuration.GetSection <FhirDispatcherConfigurationSection>();

            if (fhirConfiguration == null)
            {
                fhirConfiguration = new FhirDispatcherConfigurationSection()
                {
                };
                configuration.AddSection(fhirConfiguration);
            }

            if (!settings.TryGetValue(EndpointSetting, out string endpoint))
            {
                throw new ArgumentNullException($"SDB_FHIR_AUDIT_EP is required");
            }
            var dispatcher = new FhirDispatcherTargetConfiguration();

            dispatcher.Name     = "audit";
            dispatcher.Endpoint = endpoint;

            if (settings.TryGetValue(UserSetting, out string user) && settings.TryGetValue(PasswordSetting, out string password))
            {
                dispatcher.UserName = user;
                dispatcher.Password = password;
            }

            if (settings.TryGetValue(AuthenticatorSetting, out string authenticator))
            {
                dispatcher.Authenticator = new TypeReferenceConfiguration(authenticator);
            }

            fhirConfiguration.Targets.Add(dispatcher);

            // Add services
            var serviceConfiguration = configuration.GetSection <ApplicationServiceContextConfigurationSection>().ServiceProviders;

            if (!serviceConfiguration.Any(s => s.Type == typeof(FhirAuditDispatcher)))
            {
                serviceConfiguration.Add(new TypeReferenceConfiguration(typeof(FhirAuditDispatcher)));
            }
        }