Пример #1
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (request.Headers.Authorization == null)
            {
                string accessToken = await _fitbitTokenService.GetAccessTokenAsync(_userContext.UserId);

                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            }

            return(await base.SendAsync(request, cancellationToken));
        }
Пример #2
0
        public async Task ProcessAsync(IEvent @event)
        {
            var providerUpdateEvent = (IntegrationProviderUpdateEvent)@event;

            _logger.Information(nameof(FitbitProviderUpdateEventHandler), providerUpdateEvent.Properties);

            FitbitUpdateNotification fitbitUpdate =
                ((JObject)providerUpdateEvent.Data.ProviderData)
                .ToObject <FitbitUpdateNotification>();

            string accessToken = await _fitbitTokenService.GetAccessTokenAsync(providerUpdateEvent.Data.UserId);

            ResourceContainer resource = await _fitbitClient.GetResourceAsync(
                ownerType : fitbitUpdate.OwnerType,
                ownerId : fitbitUpdate.OwnerId,
                collectionType : fitbitUpdate.CollectionType,
                date : fitbitUpdate.Date,
                accessToken : accessToken);

            if (resource.Body is null)
            {
                _logger.LogWarning($"Data mapping not supported: {JsonConvert.SerializeObject(resource)}");
                return;
            }

            await _fhirClient.EnsurePatientDeviceAsync(providerUpdateEvent.Data.UserId);

            IoMTModel iomtModel = new BodyWeight
            {
                Weight = resource.Body.Weight,
                MeasurementDateTime = fitbitUpdate.Date,
                DeviceId            = providerUpdateEvent.Data.UserId,
                PatientId           = providerUpdateEvent.Data.UserId
            };

            await _iomtDataPublisher.PublishAsync(iomtModel);
        }