public async Task <IViewComponentResult> InvokeAsync(SampleDataTypes type) { var prms = this.GetParametersFromRequest(); try { var response = await agencySubjectQueryService.QueryAsync(type, prms); return(this.View(type.ToString(), response)); } catch (ProblemDetailsException <ProblemDetails> exception) { logger.LogError(exception, $"Error invoking query for subject {prms.Subject}"); return(this.View("ProblemDetails", exception.ProblemDetails)); } catch (Exception exception) { logger.LogError(exception, $"Error invoking query for subject {prms.Subject}"); return(this.View("Error", new ErrorViewModel() { RequestId = this.HttpContext.TraceIdentifier, Exception = exception })); } }
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"); }
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); }
private static IEnumerable <T> GetAttributesOn <T>(SampleDataTypes enumVal) where T : Attribute { var type = enumVal.GetType(); var memInfo = type.GetMember(enumVal.ToString()); var attributes = memInfo[0].GetCustomAttributes <T>(false); return(attributes); }
public IEnumerable <string> GetHealthQueryTypesFor(SampleDataTypes type) { var types = GetAttributesOn <SampleDataTypeAttribute>(type).SelectMany(s => s.TypeNames); if (types.Any()) { return(types); } return(new [] { type.ToString("G") }); }
public IEnumerable <ISampleModel> Map(IEnumerable <HealthSample> samples, SampleDataTypes type) { switch (type) { case SampleDataTypes.BloodPressure: return(BloodPressure(samples)); case SampleDataTypes.BodyMass: return(BodyMass(samples)); case SampleDataTypes.HeartRate: return(HeartRate(samples)); case SampleDataTypes.Height: return(Height(samples)); case SampleDataTypes.PhysicalActivity: return(PhysicalActivity(samples)); default: throw new NotSupportedException($"Unable to map samples for {type}"); } }
private string FirstType(SampleDataTypes sampleDataTypes) { return(sampleDataTypeMapper.GetHealthQueryTypesFor(sampleDataTypes).First()); }
public bool HasRequiredScopes(IEnumerable <string> scopes, SampleDataTypes type) { var sampleScopes = GetAttributesOn <RequiresScopeAttribute>(type).SelectMany(s => s.Scopes); return(sampleScopes.All(s => scopes.Contains(s))); }