Exemple #1
0
        // 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);
        }
Exemple #3
0
        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);
        }
        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();
        }
Exemple #5
0
        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.";
        }
Exemple #6
0
        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.");
        }
        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()));
        }
        private async void CreateBloodPressure(object sender, EventArgs eventArgs)
        {
            // Create a new blood pressure object with random values
            Random        rand = new Random();
            BloodPressure bp   = new BloodPressure
            {
                Diastolic = rand.Next(20, 100),
                Systolic  = rand.Next(80, 120)
            };

            // use our thing client to creat the new blood pressure
            PersonInfo personInfo = await _connection.GetPersonInfoAsync();

            await _thingClient.CreateNewThingsAsync(personInfo.SelectedRecord.Id, new List <BloodPressure>() { bp });
        }
Exemple #10
0
        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);
        }
Exemple #12
0
        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.";
        }
Exemple #13
0
        public async Task SimpleWeights()
        {
            IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration);
            IThingClient thingClient = connection.CreateThingClient();
            PersonInfo   personInfo  = await connection.GetPersonInfoAsync();

            HealthRecordInfo record = personInfo.SelectedRecord;

            await TestUtilities.RemoveAllThingsAsync <Weight>(thingClient, record.Id);

            LocalDateTime nowLocal = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime;

            List <Weight> weightList = new List <Weight>();

            weightList.Add(new Weight(
                               new HealthServiceDateTime(nowLocal.PlusHours(-1)),
                               new WeightValue(81, new DisplayValue(81, "KG", "kg"))));

            weightList.Add(new Weight(
                               new HealthServiceDateTime(nowLocal),
                               new WeightValue(85, new DisplayValue(187, "LBS", "lb"))));

            await thingClient.CreateNewThingsAsync <Weight>(record.Id, weightList);

            IReadOnlyCollection <Weight> retrievedWeights = await thingClient.GetThingsAsync <Weight>(record.Id);

            Assert.AreEqual(2, retrievedWeights.Count);

            var    retrievedWeightsList = retrievedWeights.ToList();
            Weight firstWeight          = retrievedWeightsList[1];
            Weight secondWeight         = retrievedWeightsList[0];

            Assert.AreEqual(81, firstWeight.Value.Kilograms);
            Assert.AreEqual(81, firstWeight.Value.DisplayValue.Value);
            Assert.AreEqual("KG", firstWeight.Value.DisplayValue.Units);
            Assert.AreEqual("kg", firstWeight.Value.DisplayValue.UnitsCode);

            Assert.AreEqual(85, secondWeight.Value.Kilograms);
            Assert.AreEqual(187, secondWeight.Value.DisplayValue.Value);
            Assert.AreEqual("LBS", secondWeight.Value.DisplayValue.Units);
            Assert.AreEqual("lb", secondWeight.Value.DisplayValue.UnitsCode);
        }
Exemple #14
0
        /// <summary>
        /// Creates a new Weight object and publishes to HealthVault.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Add_Tapped(object sender, TappedRoutedEventArgs e)
        {
            const double kgToLbsFactor = 2.20462;
            double       value;
            double       kg;

            if (double.TryParse(NewWeight.Text, out value))
            {
                if (Units.SelectedIndex == 0)
                {
                    kg = value / kgToLbsFactor;
                }
                else
                {
                    kg = value;
                }

                LocalDateTime localNow = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime;

                List <Weight> list = new List <Weight>();
                list.Add(new Weight(
                             new HealthServiceDateTime(localNow),
                             new WeightValue(kg, new DisplayValue(value, (Units.SelectedValue as ComboBoxItem).Content.ToString()))));

                HealthRecordInfo recordInfo  = (await _connection.GetPersonInfoAsync()).SelectedRecord;
                IThingClient     thingClient = _connection.CreateThingClient();
                thingClient.CreateNewThingsAsync <Weight>(recordInfo.Id, list);

                Initialize(new NavigationParams()
                {
                    Connection = _connection
                });
                AddWeightPopup.IsOpen = false;
            }
            else // Show an error message.
            {
                ResourceLoader loader = new ResourceLoader();
                Windows.UI.Popups.MessageDialog messageDialog = new Windows.UI.Popups.MessageDialog(loader.GetString("InvalidWeight"));
                await messageDialog.ShowAsync();
            }
        }
Exemple #15
0
        private async Task AddWeightAsync()
        {
            try
            {
                bool   isMetric = UnitsPickerIndex == 1;
                double weightNumber;
                if (!double.TryParse(WeightValue, out weightNumber))
                {
                    return;
                }

                double kilograms;
                if (isMetric)
                {
                    kilograms = weightNumber;
                }
                else
                {
                    kilograms = weightNumber / WeightViewModel.KgToLbsFactor;
                }

                List <Weight> weightList = new List <Weight>();
                weightList.Add(new Weight(
                                   new HealthServiceDateTime(SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime),
                                   new WeightValue(kilograms, new DisplayValue(weightNumber, isMetric ? "kg" : "lbs"))));

                IThingClient thingClient = _connection.CreateThingClient();
                var          person      = await _connection.GetPersonInfoAsync();

                await thingClient.CreateNewThingsAsync <Weight>(person.SelectedRecord.Id, weightList);

                await NavigationService.NavigateBackAsync();
            }
            catch (Exception exception)
            {
                await DisplayAlertAsync(StringResource.ErrorDialogTitle, exception.ToString());
            }
        }
Exemple #16
0
        private async void Set_Height_OnClick(object sender, RoutedEventArgs e)
        {
            PersonInfo personInfo = await _connection.GetPersonInfoAsync();

            HealthRecordInfo recordInfo  = personInfo.SelectedRecord;
            IThingClient     thingClient = _connection.CreateThingClient();

            Random rand       = new Random();
            double minHeight  = 1.53;
            double maxHeight  = 1.83;
            double range      = maxHeight - minHeight;
            double randHeight = Math.Round((minHeight + rand.NextDouble() * range), 2);

            LocalDateTime nowLocal = _clock.GetCurrentInstant().InZone(_dateTimeZoneProvider.GetSystemDefault()).LocalDateTime;

            await thingClient.CreateNewThingsAsync(
                recordInfo.Id,
                new List <Height>
            {
                new Height(new HealthServiceDateTime(nowLocal), new Length(randHeight))
            });

            OutputBlock.Text = "Created height.";
        }
        public async Task MultipleThingTypes()
        {
            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")));

            var bloodPressure1 = new BloodPressure
            {
                EffectiveDate = nowLocal,
                Systolic      = 110,
                Diastolic     = 90,
            };

            var bloodPressure2 = new BloodPressure
            {
                EffectiveDate = nowLocal.PlusHours(-1),
                Systolic      = 111,
                Diastolic     = 91,
            };

            var cholesterolProfile = new CholesterolProfileV2
            {
                When         = new HealthServiceDateTime(nowLocal),
                LDL          = new ConcentrationMeasurement(110),
                HDL          = new ConcentrationMeasurement(65),
                Triglyceride = new ConcentrationMeasurement(140)
            };

            var labTestResult = new LabTestResults(new LabTestResultGroup[] { new LabTestResultGroup(new CodableValue("test")) });

            var immunization = new Immunization(new CodableValue("diphtheria, tetanus toxoids and acellular pertussis vaccine", "DTaP", new VocabularyKey("immunizations", "wc", "1")));

            var procedure = new Procedure(new CodableValue("A surgery"));

            var allergy = new Allergy(new CodableValue("Pollen"));

            var condition = new Condition(new CodableValue("Diseased"));

            await thingClient.CreateNewThingsAsync(
                record.Id,
                new List <IThing>
            {
                bloodGlucose,
                weight,
                bloodPressure1,
                bloodPressure2,
                cholesterolProfile,
                labTestResult,
                immunization,
                procedure,
                allergy,
                condition
            });

            var             query           = CreateMultiThingQuery();
            ThingCollection thingCollection = await thingClient.GetThingsAsync(record.Id, query);

            Assert.AreEqual(10, thingCollection.Count);

            var returnedBloodGlucose = (BloodGlucose)thingCollection.First(t => t.TypeId == BloodGlucose.TypeId);

            Assert.AreEqual(bloodGlucose.Value.Value, returnedBloodGlucose.Value.Value);

            var returnedWeight = (Weight)thingCollection.First(t => t.TypeId == Weight.TypeId);

            Assert.AreEqual(weight.Value.Kilograms, returnedWeight.Value.Kilograms);

            var returnedBloodPressures = thingCollection.Where(t => t.TypeId == BloodPressure.TypeId).Cast <BloodPressure>().ToList();

            Assert.AreEqual(2, returnedBloodPressures.Count);

            Assert.AreEqual(bloodPressure1.Systolic, returnedBloodPressures[0].Systolic);
        }