private async Task <ThingCollection> GetPartialThingsAsync( IList <ThingKey> partialThings) { IThingClient thingClient = Connection.CreateThingClient(); ThingQuery query = new ThingQuery(); foreach (ThingKey key in partialThings) { query.ItemKeys.Add(key); } // Need to copy the view from the original filter query.View = Query.View; query.States = Query.States; query.CurrentVersionOnly = Query.CurrentVersionOnly; if (Query.OrderByClauses.Count > 0) { foreach (var orderByClause in Query.OrderByClauses) { query.OrderByClauses.Add(orderByClause); } } ThingCollection results = await thingClient.GetThingsAsync(Record.Id, query).ConfigureAwait(false); return(results); }
private async void SaveAndCloseAsync() { savingView.Hidden = false; int diastolic = 0; int systolic = 0; int pulse = 0; int.TryParse(diastolicTextField.Text, out diastolic); int.TryParse(systolicTextField.Text, out systolic); int.TryParse(pulseTextField.Text, out pulse); BloodPressure bp = new BloodPressure { Diastolic = diastolic, Systolic = systolic, Pulse = pulse, When = new HealthServiceDateTime(SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime) }; IThingClient thingClient = _connection.CreateThingClient(); PersonInfo personInfo = await _connection.GetPersonInfoAsync(); await thingClient.CreateNewThingsAsync(personInfo.SelectedRecord.Id, new List <BloodPressure> { bp }); Dismiss(); }
public async Task SimpleMedications() { IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration); IThingClient thingClient = connection.CreateThingClient(); PersonInfo personInfo = await connection.GetPersonInfoAsync(); HealthRecordInfo record = personInfo.SelectedRecord; await TestUtilities.RemoveAllThingsAsync <Medication>(thingClient, record.Id); var medication = new Medication { Name = new CodableValue("My med"), Dose = new GeneralMeasurement("2 tablets"), Strength = new GeneralMeasurement("200mg"), Frequency = new GeneralMeasurement("Twice per day"), Route = new CodableValue("By mouth", "po", new VocabularyKey("medication-routes", "wc", "2")) }; await thingClient.CreateNewThingsAsync(record.Id, new IThing[] { medication }); IReadOnlyCollection <Medication> medications = await thingClient.GetThingsAsync <Medication>(record.Id); Assert.AreEqual(1, medications.Count); Medication returnedMedication = medications.First(); Assert.AreEqual(medication.Dose.Display, returnedMedication.Dose.Display); Assert.AreEqual(medication.Strength.Display, returnedMedication.Strength.Display); Assert.AreEqual(medication.Frequency.Display, returnedMedication.Frequency.Display); Assert.AreEqual(medication.Route.Text, returnedMedication.Route.Text); }
// Store custom data in HealthVault private async void Set_CustomData_OnClick(object sender, RoutedEventArgs e) { PersonInfo personInfo = await _connection.GetPersonInfoAsync(); HealthRecordInfo recordInfo = personInfo.SelectedRecord; IThingClient thingClient = _connection.CreateThingClient(); await thingClient.CreateNewThingsAsync( recordInfo.Id, new List <CustomDataType> { new CustomDataType { StartTime = DateTime.Now.Ticks, EndTime = DateTime.Now.Ticks + 1200, Values = new List <double> { 1.8, 2.5, 2.6, 3.7 }, ApplicationId = AppId, SubtypeTag = CustomDataTypeSubtypeTag, Description = "CustomDataType" } }); OutputBlock.Text = "Created custom data type."; }
public async Task GetThingById() { IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration); IThingClient thingClient = connection.CreateThingClient(); PersonInfo personInfo = await connection.GetPersonInfoAsync(); HealthRecordInfo record = personInfo.SelectedRecord; await DeletePreviousThings(thingClient, record); LocalDateTime nowLocal = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime; var weight = new Weight( new HealthServiceDateTime(nowLocal), new WeightValue(81, new DisplayValue(81, "KG", "kg"))); await thingClient.CreateNewThingsAsync( record.Id, new List <IThing> { weight }); Weight remoteWeight = await thingClient.GetThingAsync <Weight>(record.Id, weight.Key.Id); Assert.IsNotNull(remoteWeight); Assert.AreEqual(weight.Key.Id, remoteWeight.Key.Id); Assert.AreEqual(weight.Value.Value, remoteWeight.Value.Value); }
private async void Add100BPs_OnClicked(object sender, EventArgs e) { OutputLabel.Text = "Adding 100 blood pressures..."; PersonInfo personInfo = await _connection.GetPersonInfoAsync(); HealthRecordInfo recordInfo = personInfo.SelectedRecord; IThingClient thingClient = _connection.CreateThingClient(); var random = new Random(); var pressures = new List <BloodPressure>(); for (int i = 0; i < 100; i++) { pressures.Add(new BloodPressure( new HealthServiceDateTime(SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime), random.Next(110, 130), random.Next(70, 90))); } await thingClient.CreateNewThingsAsync( recordInfo.Id, pressures); OutputLabel.Text = "Done adding blood pressures."; }
private async void ConnectToHealthVaultAsync(object sender, EventArgs eventArgs) { _statusView.Text = "Connecting..."; // create a configuration for our HealthVault application var configuration = GetPpeConfiguration(); try { // get a connection to HealthVault _connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(configuration); await _connection.AuthenticateAsync(); } catch (Exception e) { _statusView.Text = $"Error connecting... {e.ToString()}"; } // get a thing client _thingClient = _connection.CreateThingClient(); PersonInfo personInfo = await _connection.GetPersonInfoAsync(); // update visual state _connectionButton.Visibility = ViewStates.Gone; _controlsLayout.Visibility = ViewStates.Visible; _disconnectButton.Visibility = ViewStates.Visible; _statusView.Text = $"Hello {personInfo.Name}"; }
public async Task SimpleBloodPressure() { IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration); IThingClient thingClient = connection.CreateThingClient(); PersonInfo personInfo = await connection.GetPersonInfoAsync(); await TestUtilities.RemoveAllThingsAsync <BloodPressure>(thingClient, personInfo.SelectedRecord.Id); // Create a new blood pressure object with random values Random rand = new Random(); BloodPressure newBloodPressure = new BloodPressure { Diastolic = rand.Next(20, 100), Systolic = rand.Next(80, 120) }; // use our thing client to create the new blood pressure await thingClient.CreateNewThingsAsync(personInfo.SelectedRecord.Id, new List <BloodPressure> { newBloodPressure }); // use our thing client to get all things of type blood pressure IReadOnlyCollection <BloodPressure> bloodPressures = await thingClient.GetThingsAsync <BloodPressure>(personInfo.SelectedRecord.Id); Assert.AreEqual(1, bloodPressures.Count); BloodPressure bp = bloodPressures.First(); Assert.AreEqual(newBloodPressure.Systolic, bp.Systolic); Assert.AreEqual(newBloodPressure.Diastolic, bp.Diastolic); }
public async Task CreateNewThingsReturnsIds() { IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration); IThingClient thingClient = connection.CreateThingClient(); PersonInfo personInfo = await connection.GetPersonInfoAsync(); HealthRecordInfo record = personInfo.SelectedRecord; await DeletePreviousThings(thingClient, record); LocalDateTime nowLocal = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime; var bloodGlucose = new BloodGlucose( new HealthServiceDateTime(nowLocal), new BloodGlucoseMeasurement( 4.2, new DisplayValue(4.2, "mmol/L", "mmol-per-l")), new CodableValue("Whole blood", "wb", new VocabularyKey("glucose-measurement-type", "wc", "1"))); var weight = new Weight( new HealthServiceDateTime(nowLocal), new WeightValue(81, new DisplayValue(81, "KG", "kg"))); await thingClient.CreateNewThingsAsync( record.Id, new List <IThing> { bloodGlucose, weight, }); Assert.IsNotNull(bloodGlucose.Key, "Blood glucose was not assigned a key."); Assert.IsNotNull(weight.Key, "Weight was not assigned a key."); }
private async Task ConnectToHealthVaultAsync() { activityIndicator.StartAnimating(); UpdateTitle("Connecting..."); statusLabel.Text = ""; try { var configuration = GetPpeConfiguration(); _connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(configuration); await _connection.AuthenticateAsync(); _thingClient = _connection.CreateThingClient(); PersonInfo personInfo = await _connection.GetPersonInfoAsync(); connectButton.SetTitle("Disconnect", UIControlState.Normal); SetStatusLabelText(""); UpdateTitle(personInfo.Name); controlView.Hidden = false; } catch (Exception e) { UpdateTitle("Error"); SetStatusLabelText(e.ToString()); connectButton.SetTitle("Retry", UIControlState.Normal); } }
public override async Task OnNavigateToAsync() { await LoadAsync(async() => { var person = await _connection.GetPersonInfoAsync(); _thingClient = _connection.CreateThingClient(); HealthRecordInfo record = person.SelectedRecord; _recordId = record.Id; _basicInformation = (await _thingClient.GetThingsAsync <BasicV2>(_recordId)).FirstOrDefault(); _personalInformation = (await _thingClient.GetThingsAsync <Personal>(_recordId)).FirstOrDefault(); ImageSource profileImageSource = await GetImageAsync(); if (_personalInformation.BirthDate != null) { BirthDate = _personalInformation.BirthDate.ToDateTime(); } else { BirthDate = DateTime.Now; } FirstName = _personalInformation.Name?.First ?? string.Empty; LastName = _personalInformation.Name?.Last ?? string.Empty; GenderIndex = _basicInformation.Gender != null && _basicInformation.Gender.Value == Gender.Female ? 1 : 0; ImageSource = profileImageSource; await base.OnNavigateToAsync(); }); }
/// <summary> /// Obtains Weight objects from HealthVault /// </summary> /// <returns></returns> public override async Task Initialize(NavigationParams navParams) { //Save the connection so that we can reuse it for updates later _connection = navParams.Connection; HealthRecordInfo recordInfo = (await _connection.GetPersonInfoAsync()).SelectedRecord; IThingClient thingClient = _connection.CreateThingClient(); if (QueryTimeframe.SelectedIndex == (int)QueryTimeframeEnum.Default) { //Uses a simple query which specifies the Thing type as the only filter Items = await thingClient.GetThingsAsync <Weight>(recordInfo.Id); } else if (QueryTimeframe.SelectedIndex == (int)QueryTimeframeEnum.Last30d) { //In this mode, the app specifies a ThingQuery which can be used for functions like //filtering, or paging through values ThingQuery query = new ThingQuery() { EffectiveDateMin = DateTime.Now.AddDays(-30) }; Items = await thingClient.GetThingsAsync <Weight>(recordInfo.Id, query); } OnPropertyChanged("Items"); OnPropertyChanged("Latest"); return; }
private async Task <IThingClient> CreateThingClientAsync() { IOfflineHealthVaultConnection offlineHealthVaultConnection = await WebHealthVaultFactory.CreateOfflineConnectionAsync(OfflinePersonId, InstanceId); IThingClient thingClient = offlineHealthVaultConnection.CreateThingClient(); return(thingClient); }
public static async Task RemoveAllThingsAsync <T>(IThingClient thingClient, Guid recordId) where T : IThing { IReadOnlyCollection <T> things = await thingClient.GetThingsAsync <T>(recordId); if (things.Count > 0) { await thingClient.RemoveThingsAsync(recordId, things.ToList()); } }
private async Task RefreshAsync() { var person = await _connection.GetPersonInfoAsync(); IThingClient thingClient = _connection.CreateThingClient(); HealthRecordInfo record = person.SelectedRecord; IReadOnlyCollection <Weight> items = await thingClient.GetThingsAsync <Weight>(record.Id); RefreshPage(items); }
private async Task SaveAsync(Medication medication) { UpdateMedication(medication); IThingClient thingClient = _connection.CreateThingClient(); PersonInfo personInfo = await _connection.GetPersonInfoAsync(); await thingClient.UpdateThingsAsync(personInfo.SelectedRecord.Id, new Collection <Medication>() { medication }); await NavigationService.NavigateBackAsync(); }
/// <summary> /// Updates the BasicV2 thing with the content from the BasicInformation property. /// </summary> private async void UpdateThing() { HealthRecordInfo recordInfo = (await _connection.GetPersonInfoAsync()).SelectedRecord; IThingClient thingClient = _connection.CreateThingClient(); List <ThingBase> things = new List <ThingBase>(); things.Add(BasicInformation); await thingClient.UpdateThingsAsync(recordInfo.Id, things); }
public override async Task OnNavigateBackAsync() { var person = await _connection.GetPersonInfoAsync(); IThingClient thingClient = _connection.CreateThingClient(); HealthRecordInfo record = person.SelectedRecord; IReadOnlyCollection <Medication> items = await thingClient.GetThingsAsync <Medication>(record.Id); UpdateDisplay(items); await base.OnNavigateBackAsync(); }
// GET: HealthVault public async Task <ActionResult> Index() { IWebHealthVaultConnection webHealthVaultConnection = await WebHealthVaultFactory.CreateWebConnectionAsync(); PersonInfo personInfo = await webHealthVaultConnection.GetPersonInfoAsync(); IThingClient thingClient = webHealthVaultConnection.CreateThingClient(); IReadOnlyCollection <Weight> weights = await thingClient.GetThingsAsync <Weight>(personInfo.GetSelfRecord().Id); return(View(weights)); }
public async Task <ActionResult> CreateWeight() { IThingClient thingClient = await CreateThingClientAsync(); LocalDateTime nowLocal = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime; await thingClient.CreateNewThingsAsync(RecordId, new List <Weight> { new Weight(new HealthServiceDateTime(nowLocal), new WeightValue(10)) }); return(RedirectToAction("Index", new RouteValueDictionary())); }
// Get custom data from HealthVault private async void Get_CustomData_OnClick(object sender, RoutedEventArgs e) { PersonInfo personInfo = await _connection.GetPersonInfoAsync(); HealthRecordInfo recordInfo = personInfo.SelectedRecord; IThingClient thingClient = _connection.CreateThingClient(); IReadOnlyCollection <ApplicationSpecific> healthData = await thingClient.GetThingsAsync <ApplicationSpecific>(recordInfo.Id); if (healthData.Count == 0) { OutputBlock.Text = "No custom data found."; } else { List <CustomDataType> customDataTypes = new List <CustomDataType>(); foreach (ApplicationSpecific customDataType in healthData) { CustomDataType customData = new CustomDataType { Values = new List <double>() }; var appSpecificXml = customDataType?.ApplicationSpecificXml; if (appSpecificXml.Count <= 0) { continue; } XDocument doc = XDocument.Parse(appSpecificXml[0].CreateNavigator()?.OuterXml); foreach (XElement element in doc.Descendants(CustomDataTypeSubtypeTag)) { customData.StartTime = long.Parse(element.Attribute("StartTime").Value); customData.EndTime = long.Parse(element.Attribute("EndTime").Value); var array = element.Attribute("Values")?.Value.Split(','); if (array == null) { continue; } foreach (var entry in array) { double pressure = double.Parse(entry); customData.Values.Add(pressure); } customDataTypes.Add(customData); } } OutputBlock.Text = "Custom data found."; } }
/// <summary> /// Gets the latest BasicV2 object for this user. /// </summary> /// <param name="recordInfo"></param> /// <param name="thingClient"></param> /// <returns></returns> private async Task GetProfileAsync(HealthRecordInfo recordInfo, IThingClient thingClient) { BasicInformation = (await thingClient.GetThingsAsync <BasicV2>(recordInfo.Id)).FirstOrDefault <BasicV2>(); RecordInfo = recordInfo; //Binding against an enum from XAML isn't straightforward, so use this workaround instead. Gender.ItemsSource = System.Enum.GetValues(typeof(Gender)); OnPropertyChanged("RecordInfo"); OnPropertyChanged("BasicInformation"); }
public override async Task OnNavigateBackAsync() { await LoadAsync(async() => { IThingClient thingClient = _connection.CreateThingClient(); PersonInfo personInfo = await _connection.GetPersonInfoAsync(); _medication = await thingClient.GetThingAsync <Medication>(personInfo.SelectedRecord.Id, _medication.Key.Id); UpdateDisplay(); await base.OnNavigateBackAsync(); }); }
/// <summary> /// Retrieves the data model for this page. /// </summary> /// <returns></returns> public override async Task Initialize(NavigationParams navParams) { //Save the connection so we can make updates later. _connection = navParams.Connection; HealthRecordInfo recordInfo = (await _connection.GetPersonInfoAsync()).SelectedRecord; IThingClient thingClient = _connection.CreateThingClient(); GetProfileAsync(recordInfo, thingClient); GetPersonalImageAsync(recordInfo, thingClient); return; }
public async Task <ActionResult> CreateWeight() { IWebHealthVaultConnection webHealthVaultConnection = await WebHealthVaultFactory.CreateWebConnectionAsync(); PersonInfo personInfo = await webHealthVaultConnection.GetPersonInfoAsync(); IThingClient thingClient = webHealthVaultConnection.CreateThingClient(); LocalDateTime nowLocal = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime; await thingClient.CreateNewThingsAsync(personInfo.GetSelfRecord().Id, new List <Weight> { new Weight(new HealthServiceDateTime(nowLocal), new WeightValue(10)) }); return(RedirectToAction("Index", new RouteValueDictionary())); }
public async Task MultipleQueries() { IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration); IThingClient thingClient = connection.CreateThingClient(); PersonInfo personInfo = await connection.GetPersonInfoAsync(); HealthRecordInfo record = personInfo.SelectedRecord; await DeletePreviousThings(thingClient, record); LocalDateTime nowLocal = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime; var bloodGlucose = new BloodGlucose( new HealthServiceDateTime(nowLocal), new BloodGlucoseMeasurement( 4.2, new DisplayValue(4.2, "mmol/L", "mmol-per-l")), new CodableValue("Whole blood", "wb", new VocabularyKey("glucose-measurement-type", "wc", "1"))); var weight = new Weight( new HealthServiceDateTime(nowLocal), new WeightValue(81, new DisplayValue(81, "KG", "kg"))); await thingClient.CreateNewThingsAsync( record.Id, new List <IThing> { bloodGlucose, weight, }); var resultSet = await thingClient.GetThingsAsync(record.Id, new[] { new ThingQuery(BloodGlucose.TypeId), new ThingQuery(Weight.TypeId) }); Assert.AreEqual(2, resultSet.Count); var resultList = resultSet.ToList(); ThingCollection glucoseCollection = resultList[0]; var returnedBloodGlucose = (BloodGlucose)glucoseCollection.First(); Assert.AreEqual(bloodGlucose.Value.Value, returnedBloodGlucose.Value.Value); ThingCollection weightCollection = resultList[1]; var returnedWeight = (Weight)weightCollection.First(); Assert.AreEqual(weight.Value.Kilograms, returnedWeight.Value.Kilograms); }
/// <summary> /// Gets the user's PersonalImage Things and then calls GetAndSavePersonalImage to extract the blob, /// save to disk, then adds that path to the ImageSource property so the UX can find it. /// </summary> /// <param name="recordInfo"></param> /// <param name="thingClient"></param> /// <returns></returns> private async Task GetPersonalImageAsync(HealthRecordInfo recordInfo, IThingClient thingClient) { //Build query var query = new ThingQuery(new Guid[] { PersonalImage.TypeId }); query.View.Sections = ThingSections.Xml | ThingSections.BlobPayload | ThingSections.Signature; var things = await thingClient.GetThingsAsync(recordInfo.Id, query); if (things.Count > 0) { Windows.Storage.StorageFile file = await GetAndSavePersonalImage(recordInfo, things); ImageSource = file.Path; OnPropertyChanged("ImageSource"); } }
private static async Task DeletePreviousThings(IThingClient thingClient, HealthRecordInfo record) { var query = CreateMultiThingQuery(); var thingCollection = await thingClient.GetThingsAsync(record.Id, query); var thingsToDelete = new List <IThing>(); foreach (IThing thing in thingCollection) { thingsToDelete.Add(thing); } if (thingsToDelete.Count > 0) { await thingClient.RemoveThingsAsync(record.Id, thingsToDelete); } }
public async Task BasicInformationFields() { IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration); PersonInfo personInfo = await connection.GetPersonInfoAsync(); HealthRecordInfo record = personInfo.SelectedRecord; IThingClient thingClient = connection.CreateThingClient(); BasicV2 basicInfo = (await thingClient.GetThingsAsync <BasicV2>(record.Id)).First(); Assert.AreEqual("Redmond", basicInfo.City); Assert.AreEqual(1985, basicInfo.BirthYear); Assert.AreEqual(Gender.Male, basicInfo.Gender); Assert.AreEqual("98052", basicInfo.PostalCode); Assert.AreEqual("United States", basicInfo.Country.Text); Assert.AreEqual("Washington", basicInfo.StateOrProvince.Text); }
private async void SetBP_OnClick(object sender, RoutedEventArgs e) { PersonInfo personInfo = await _connection.GetPersonInfoAsync(); HealthRecordInfo recordInfo = personInfo.SelectedRecord; IThingClient thingClient = _connection.CreateThingClient(); LocalDateTime nowLocal = _clock.GetCurrentInstant().InZone(_dateTimeZoneProvider.GetSystemDefault()).LocalDateTime; await thingClient.CreateNewThingsAsync( recordInfo.Id, new List <BloodPressure> { new BloodPressure(new HealthServiceDateTime(nowLocal), 117, 70) }); OutputBlock.Text = "Created blood pressure."; }