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");
        }
Esempio n. 2
0
        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, agency-query-token is missing");
            }

            var requestDateParams = new Dictionary <string, object>
            {
                { "RangeOfStartDate", new HealthSample.HealthSampleDateRange(parameters.From, parameters.To) },
            };

            var queryResult = await this.healthDataClient.ExecuteQueryAsync(
                agencyQueryToken,
                this.sampleDataTypeMapper.GetHealthQueryTypesFor(type).ToArray(),
                requestDateParams,
                HealthDataQueryRequest.OrderPropertyOptions.EndDate,
                HealthDataQueryRequest.OrderDirectionOptions.Descending,
                parameters.Take)
                              .ConfigureAwait(false);

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

            return(model);
        }