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.");
        }
Esempio n. 2
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);
        }
        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);
        }
Esempio n. 4
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);
        }
        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();
        }
Esempio n. 6
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.";
        }
        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}";
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
        private async void Get_BP_OnClick(object sender, RoutedEventArgs e)
        {
            PersonInfo personInfo = await _connection.GetPersonInfoAsync();

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

            var bloodPressures = await thingClient.GetThingsAsync <BloodPressure>(recordInfo.Id);

            BloodPressure firstBloodPressure = bloodPressures.FirstOrDefault();

            if (firstBloodPressure == null)
            {
                OutputBlock.Text = "No blood pressures.";
            }
            else
            {
                OutputBlock.Text = firstBloodPressure.Systolic + "/" + firstBloodPressure.Diastolic;
            }
        }
        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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        private async void Connect_OnClicked(object sender, EventArgs e)
        {
            OutputLabel.Text = "Connecting...";

            var configuration = new HealthVaultConfiguration
            {
                MasterApplicationId = Guid.Parse("d6318dff-5352-4a10-a140-6c82c6536a3b")
            };

            _connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(configuration);

            await _connection.AuthenticateAsync();

            _thingClient = _connection.CreateThingClient();
            ConnectedButtons.IsVisible = true;

            OutputLabel.Text = "Connected.";
        }
        private async void LoadCollectionAsync()
        {
            activityIndicator.StartAnimating();
            messageLabel.Hidden = true;

            IThingClient thingClient = _connection.CreateThingClient();
            PersonInfo   personInfo  = await _connection.GetPersonInfoAsync();

            _collection = (IReadOnlyCollection <IThing>) await thingClient.GetThingsAsync <TThing>(personInfo.SelectedRecord.Id);

            activityIndicator.StopAnimating();

            collectionView.ReloadData();

            if (_collection.Count < 1)
            {
                messageLabel.Hidden = false;
            }
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
        public async Task UsingDatesInThingsQueryReturnProperly()
        {
            IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration);
            IThingClient thingClient = connection.CreateThingClient();
            PersonInfo   personInfo  = await connection.GetPersonInfoAsync();

            HealthRecordInfo record = personInfo.SelectedRecord;

            ThingQuery query = new ThingQuery(BloodGlucose.TypeId);
            var        now   = DateTime.UtcNow;

            query.CreatedDateMin    = Instant.FromDateTimeUtc(now.AddDays(-5));
            query.CreatedDateMax    = Instant.FromDateTimeUtc(now.AddDays(-4));
            query.UpdatedDateMin    = Instant.FromDateTimeUtc(now.AddDays(-3));
            query.UpdatedDateMax    = Instant.FromDateTimeUtc(now.AddDays(-2));
            query.UpdatedEndDateMin = LocalDateTime.FromDateTime(now.AddDays(-1));
            query.UpdatedEndDateMax = LocalDateTime.FromDateTime(now);

            var results = await thingClient.GetThingsAsync(record.Id, query);

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.Query);
            Assert.IsNotNull(results.Query.CreatedDateMin);
            Assert.AreEqual(results.Query.CreatedDateMin.Value.ToDateTimeUtc(), now.AddDays(-5));

            Assert.IsNotNull(results.Query.CreatedDateMax);
            Assert.AreEqual(results.Query.CreatedDateMax.Value.ToDateTimeUtc(), now.AddDays(-4));

            Assert.IsNotNull(results.Query.UpdatedDateMin);
            Assert.AreEqual(results.Query.UpdatedDateMin.Value.ToDateTimeUtc(), now.AddDays(-3));

            Assert.IsNotNull(results.Query.UpdatedDateMax);
            Assert.AreEqual(results.Query.UpdatedDateMax.Value.ToDateTimeUtc(), now.AddDays(-2));

            Assert.IsNotNull(results.Query.UpdatedEndDateMin);
            Assert.AreEqual(results.Query.UpdatedEndDateMin.Value, LocalDateTime.FromDateTime(now.AddDays(-1)));

            Assert.IsNotNull(results.Query.UpdatedEndDateMax);
            Assert.AreEqual(results.Query.UpdatedEndDateMax.Value, LocalDateTime.FromDateTime(now));
        }
        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);
        }