public async Task <IEnumerable <ISampleModel> > QueryAsync(SampleDataTypes type, AgencySubjectQueryParameters parameters)
        {
            var request  = new AgencySubjectQueryTokenRequest(false, included: new[] { parameters.Subject });
            var response = await this.agencyApiClient.CreateQueryAsync(request);

            var agencyQueryToken = response.Value;

            if (string.IsNullOrWhiteSpace(agencyQueryToken))
            {
                throw new InvalidOperationException("Unable to complete health data query, unable to create query");
            }

            var dataRequest = new HealthDataQueryRequest(parameters.From, parameters.To, this.sampleDataTypeMapper.GetHealthQueryTypesFor(type).ToArray())
            {
                OrderDirection = HealthDataQueryRequest.OrderDirectionOptions.Descending,
                OrderProperty  = HealthDataQueryRequest.OrderPropertyOptions.EndDate
            };

            var healthDataQueryResponse =
                await this.healthDataClient.CreateQueryAsync(dataRequest, agencyQueryToken);

            if (healthDataQueryResponse.IsValid())
            {
                var data = await this.healthDataClient
                           .ExecuteQueryAsync(healthDataQueryResponse.QueryKey, parameters.Take, 0)
                           .ConfigureAwait(false);

                var model = this.sampleMapper.Map(data, type);

                return(model);
            }

            throw new InvalidOperationException("Unable to complete health data query, no query key was returned");
        }
示例#2
0
        public async Task <IActionResult> Index(HealthDataQueryRequest request)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(request));
            }

            try
            {
                var requestDateParams = new Dictionary <string, object>
                {
                    { "RangeOfStartDate", request.RangeOfStartDate },
                    { "RangeOfEndDate", request.RangeOfEndDate },
                    { "RangeOfCreationDate", request.RangeOfCreationDate }
                };

                var queryResult = await this.client.ExecuteQueryAsync(request.Types, requestDateParams);

                var model = queryResult.Datas.Select(s =>
                {
                    if (s?.CorrelationObjects?.Any() ?? false)
                    {
                        var reading = new BloodPressureSampleModel()
                        {
                            From      = s.DateRange.LowerBound,
                            Diastolic = s.CorrelationObjects.SingleOrDefault(x => x.Type == "blood_pressure_diastolic")
                                        .QuantityValue,
                            Systolic = s.CorrelationObjects.SingleOrDefault(x => x.Type == "blood_pressure_systolic")
                                       .QuantityValue
                        };
                        return(reading);
                    }

                    return(null);
                }).Where(s => s != null).OrderByDescending(s => s.From).ToList();

                return(View("QueryResults", model));
            }
            catch (HealthDataClientException exception)
            {
                return(this.View("ProblemDetails", exception.ProblemDetails));
            }
        }
示例#3
0
        public async Task <IActionResult> Index(HealthDataQueryRequest request)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(request));
            }

            try
            {
                // just ask for a new query key everytime since I would need to determine whether my query params were unchanged)
                var response = await this.client.CreateQueryAsync(request);

                // ask for data
                var data = await this.client.ExecuteQueryAsync(response.QueryKey, response.NumberOfResults * 2);

                var model = data.Select(s =>
                {
                    if (s?.CorrelationObjects?.Any() ?? false)
                    {
                        var reading = new BloodPressureSampleModel()
                        {
                            From      = s.DateRange.LowerBound,
                            Diastolic = s.CorrelationObjects.SingleOrDefault(x => x.Type == "blood_pressure_diastolic")
                                        .QuantityValue,
                            Systolic = s.CorrelationObjects.SingleOrDefault(x => x.Type == "blood_pressure_systolic")
                                       .QuantityValue
                        };
                        return(reading);
                    }

                    return(null);
                }).Where(s => s != null).OrderByDescending(s => s.From).ToList();

                return(View("QueryResults", model));
            }
            catch (HealthDataClientException exception)
            {
                return(this.View("ProblemDetails", exception.ProblemDetails));
            }
        }
示例#4
0
        public IActionResult Index()
        {
            var model = new HealthDataQueryRequest(DateTimeOffset.UtcNow.AddMonths(-2), DateTimeOffset.UtcNow, "blood_pressure", "blood_pressure_diastolic", "blood_pressure_systolic");

            return(View(model));
        }