protected override void ProcessRecord() { HealthClientApplication clientApp = HvShellUtilities.GetClient(); ServiceInfo s = clientApp.ApplicationConnection.GetServiceDefinition(); WriteObject(s); }
public static HealthClientApplication GetClient() { HealthClientApplication clientApp = HealthClientApplication.Create( HvShellUtilities.GetClientId(), _HVPowerShellGuid, _HVShell, _HVPlatform); return(clientApp); }
protected override void ProcessRecord() { HealthClientApplication clientApp = HealthClientApplication.Create( Guid.NewGuid(), HVPowerShellGuid, HVShell, HVPlatform); // Verify the application instance. // Create a new instance if necessary. if (clientApp.GetApplicationInfo() == null) { // Create a new client instance. clientApp.StartApplicationCreationProcess(); // A new client instance always requests authorization from the // current user using the default browser. // Wait for the user to return from the shell. if (ShouldContinue("Is Auth done - (Y)?", "Is auth done?", ref _yesToAll, ref _noToAll)) { // Store the SODA client details StringBuilder data = new StringBuilder(); data.Append(clientApp.ApplicationId.ToString()); using (StreamWriter sw = new StreamWriter(HvShellUtilities.GetClientAppAuthFileNameFullPath())) { sw.Write((data)); } List <PersonInfo> authorizedPeople = new List <PersonInfo>(clientApp.ApplicationConnection.GetAuthorizedPeople()); WriteObject(authorizedPeople); } } }
public void DeProvision() { Guid tempPersonId = _personId; Guid tempRecordId = _recordId; // first reset local state so // that even if things fail after this // the next app launch will have fresh state _isProvisioned = false; _personId = Guid.Empty; _recordId = Guid.Empty; _applicationId = Guid.Empty; SaveUserSettings(); // attempt to remove authorization of application from server HealthClientAuthorizedConnection connection = HealthClientApplication.CreateAuthorizedConnection(tempPersonId); HealthRecordAccessor accessor = new HealthRecordAccessor(connection, tempRecordId); accessor.RemoveApplicationAuthorization(); // delete the local certificate _healthClientApplication.DeleteCertificate(); _healthClientApplication = null; }
/// <summary> /// Initializes the variables required for HVClient. /// </summary> private void Initialize() { // Read the master application id from config file // Master application should have been pre-created in HealthVault // In HealthVault pre-production environment, the master application // should have been created using Application Configuration Center _masterApplicationId = new Guid(ConfigurationSettings.AppSettings["ApplicationId"]); _isProvisioned = Properties.Settings.Default.IsProvisioned; if (_isProvisioned) { // Read the app, person, and record ID, along // with the instance ID if that app has already // been provisioned _applicationId = Properties.Settings.Default.ApplicationId; _personId = Properties.Settings.Default.PersonId; _recordId = Properties.Settings.Default.RecordGuid; string serviceInstanceId = Properties.Settings.Default.ServiceInstanceId; _serviceInstance = ServiceInfo.Current.ServiceInstances[serviceInstanceId]; _healthClientApplication = HealthClientApplication.Create(_applicationId, _masterApplicationId, _serviceInstance); } }
protected override void ProcessRecord() { HealthClientApplication clientApp = HvShellUtilities.GetClient(); List <PersonInfo> authorizedPeople = new List <PersonInfo>(clientApp.ApplicationConnection.GetAuthorizedPeople()); // Create an authorized connection for each person on the // list. HealthClientAuthorizedConnection authConnection = clientApp.CreateAuthorizedConnection( authorizedPeople[0].PersonId); // Use the authorized connection to read the user's default // health record. HealthRecordAccessor access = new HealthRecordAccessor( authConnection, authConnection.GetPersonInfo().GetSelfRecord().Id); // Search the health record for basic demographic // information. // Most user records contain an item of this type. HealthRecordSearcher search = access.CreateSearcher(); HealthRecordFilter filter = new HealthRecordFilter( HvShellUtilities.NameToTypeId(Type)); search.Filters.Add(filter); foreach (Object o in search.GetMatchingItems()[0]) { WriteObject(o); } }
/// <summary> /// Provisions the application. /// If application does not exist, it launches the application /// creation process. /// </summary> public void ProvisionApplication() { // generate a GUID that will be used for the application creation. _applicationId = Guid.NewGuid(); HealthClientApplication client = HealthClientApplication.Create(_applicationId, _masterApplicationId); client.StartApplicationCreationProcess(); // launch dialog box to wait MessageBox.Show("After completing application setup in browser, click OK"); // check if the app is provisioned now HealthServiceInstance instance = FindProvisionedServiceInstance(); if (instance == null) { MessageBox.Show("The application setup in your browser did not complete."); return; } _serviceInstance = instance; _healthClientApplication = client; // the app was provisioned _healthClientApplication = HealthClientApplication.Create( _applicationId, _masterApplicationId, _serviceInstance); // Get list of authorized people ApplicationConnection connection = HealthClientApplication.ApplicationConnection; List <PersonInfo> authorizedPeople = new List <PersonInfo>(connection.GetAuthorizedPeople()); if (authorizedPeople.Count == 0) { MessageBox.Show("No records were authorized. Application setup process did not complete."); return; } // save person ID, record ID, and service instance ID // assumption is the first person is the current person ID and there is only // one recordid for the person. For more persons and records, a selection // UI would need to be shown PersonInfo personInfo = authorizedPeople[0]; _personId = personInfo.PersonId; _recordId = personInfo.SelectedRecord.Id; _isProvisioned = true; SaveUserSettings(); MessageBox.Show("Application + " + _applicationId + " is now provisioned"); }
protected override void ProcessRecord() { HealthClientApplication clientApp = HvShellUtilities.GetClient(); if (clientApp.GetApplicationInfo() != null) { List <PersonInfo> authorizedPeople = new List <PersonInfo>(clientApp.ApplicationConnection.GetAuthorizedPeople()); WriteObject(authorizedPeople); } }
public void SetTemperatureOnHealthVault(double tempValue) { try { if (!_isProvisioned) { MessageBox.Show("Please provision application first"); return; } HealthClientAuthorizedConnection connection = HealthClientApplication.CreateAuthorizedConnection(PersonId); HealthRecordAccessor accessor = new HealthRecordAccessor(connection, RecordId); TemperatureMeasurement temperature = new TemperatureMeasurement(tempValue); VitalSigns vitalSign = new VitalSigns(); //generate random date DateTime startDate = new DateTime(2018, 1, 1); DateTime endDate = new DateTime(2018, 12, 30); TimeSpan timeSpan = endDate - startDate; var randomTest = new Random(); TimeSpan newSpan = new TimeSpan(0, randomTest.Next(0, (int)timeSpan.TotalMinutes), 0); DateTime newDate = startDate + newSpan; //set time now //vitalSign.When = new HealthServiceDateTime(DateTime.UtcNow); vitalSign.When = new HealthServiceDateTime(newDate); CodableValue codableValue = new CodableValue(); codableValue.Text = "celsius"; VitalSignsResultType vitalSignsResultType = new VitalSignsResultType(); vitalSignsResultType.Unit = codableValue; vitalSignsResultType.TextValue = "Temperature"; vitalSignsResultType.Title.Text = "Temperature"; vitalSignsResultType.Value = tempValue; vitalSign.VitalSignsResults.Add(vitalSignsResultType); accessor.NewItem(vitalSign); } catch (Exception ex) { throw; } }
protected override void ProcessRecord() { if (string.IsNullOrEmpty(ThingType)) { HealthClientApplication clientApp = HvShellUtilities.GetClient(); WriteObject(clientApp.ApplicationConnection.GetVocabulary("thing-types")); } else { WriteObject( ItemTypeManager.GetHealthRecordItemTypeDefinition( new Guid(ThingType), HvShellUtilities.GetClient().ApplicationConnection) ); } }
/// <summary> /// Creates a connection to HealthVault and sets weight data /// </summary> /// <param name="weightValue"></param> public void SetWeightOnHealthVault(double weightValue) { if (!_isProvisioned) { MessageBox.Show("Please provision application first"); return; } HealthClientAuthorizedConnection connection = HealthClientApplication.CreateAuthorizedConnection(PersonId); HealthRecordAccessor accessor = new HealthRecordAccessor(connection, RecordId); ItemTypes.Weight weight = new ItemTypes.Weight(); weight.Value = new WeightValue(weightValue); accessor.NewItem(weight); }
/// <summary> /// Finds the instance of the HealthVault web-service /// where the child application has been provisioned. /// </summary> private HealthServiceInstance FindProvisionedServiceInstance() { foreach (var instance in ServiceInfo.Current.ServiceInstances.Values) { var client = HealthClientApplication.Create( _applicationId, _masterApplicationId, instance.ShellUrl, instance.HealthServiceUrl); ApplicationInfo appInfo = client.GetApplicationInfo(); if (appInfo != null) { return(instance); } } return(null); }
/// <summary> /// Creates a connection to HealthVault and obtains weight data /// </summary> /// <returns></returns> public HealthRecordItemCollection GetWeightFromHealthVault() { if (!_isProvisioned) { MessageBox.Show("Please provision application first"); return(null); } HealthClientAuthorizedConnection connection = HealthClientApplication.CreateAuthorizedConnection(PersonId); HealthRecordAccessor accessor = new HealthRecordAccessor(connection, RecordId); HealthRecordSearcher searcher = accessor.CreateSearcher(); HealthRecordFilter filter = new HealthRecordFilter(ItemTypes.Weight.TypeId); searcher.Filters.Add(filter); HealthRecordItemCollection items = searcher.GetMatchingItems()[0]; return(items); }
protected override void ProcessRecord() { HealthClientApplication clientApp = HvShellUtilities.GetClient(); List <PersonInfo> authorizedPeople = new List <PersonInfo> (clientApp.ApplicationConnection.GetAuthorizedPeople()); // Create an authorized connection for each person on the // list. HealthClientAuthorizedConnection authConnection = clientApp.CreateAuthorizedConnection( authorizedPeople[0].PersonId); // Use the authorized connection to read the user's default // health record. HealthRecordAccessor access = new HealthRecordAccessor( authConnection, authConnection.GetPersonInfo().GetSelfRecord().Id); Weight weight = new Weight(); weight.Value = new WeightValue(Value / 2.2, new DisplayValue(Value, "pounds")); access.NewItem(weight); }
protected override void ProcessRecord() { HealthClientApplication clientApp = HvShellUtilities.GetClient(); List <PersonInfo> authorizedPeople = new List <PersonInfo> (clientApp.ApplicationConnection.GetAuthorizedPeople()); // Create an authorized connection for each person on the // list. HealthClientAuthorizedConnection authConnection = clientApp.CreateAuthorizedConnection( authorizedPeople[0].PersonId); // Use the authorized connection to read the user's default // health record. HealthRecordAccessor accessor = new HealthRecordAccessor( authConnection, authConnection.GetPersonInfo().GetSelfRecord().Id); HealthServiceRequest request = new HealthServiceRequest(accessor.Connection, "PutThings", 2, accessor); // Read the input file request.Parameters = System.IO.File.ReadAllText(Path.GetFullPath(FileName)); request.Execute(); }
protected override void ProcessRecord() { HealthClientApplication clientApp = HvShellUtilities.GetClient(); WriteObject(clientApp.ApplicationConnection.GetVocabularyKeys()); }
public PhrData GetData(PatientIdentifier p, Configuration c) { var clientApp = HealthClientApplication.Create(_clientId, _masterId, _shellUri, _platformUri); if (clientApp.GetApplicationInfo() == null) { // Create a new client instance. clientApp.StartApplicationCreationProcess(); return(null); } var ap = clientApp.ApplicationConnection.GetAuthorizedPeople().ToList(); var pi = clientApp.ApplicationConnection.GetAuthorizedPeople().FirstOrDefault(k => k.PersonId == p.InternalId); if (pi == null) { clientApp.StartUserAuthorizationProcess(); return(null); // not authorized; } var authConnection = clientApp.CreateAuthorizedConnection(pi.PersonId); var access = new HealthRecordAccessor(authConnection, authConnection.GetPersonInfo().GetSelfRecord().Id); var ret = new PhrData { Data = new List <DataUnit>(), Patient = p, Source = Source }; ret.Data.Add(new DataUnit { Datetime = DateTime.UtcNow, Name = "Name", OntologicName = "rdf:Name", Value = pi.Name }); var b = GetSingleValue <Basic>(Basic.TypeId, access); ret.Data.Add(new DataUnit { Datetime = b.EffectiveDate, Name = "Birth date", OntologicName = "rdf:BDate", Value = b.BirthYear }); var gender = b.Gender ?? Gender.Unknown; ret.Data.Add(new DataUnit { Datetime = b.EffectiveDate, Name = "Gender", OntologicName = "rdf:Gender", Value = gender == Gender.Male ? "male" : gender == Gender.Female ? "female" : "unknown" }); ret.Data.Add(new DataUnit { Datetime = b.EffectiveDate, Name = "Country", OntologicName = "rdf:Country", Value = b.Country }); var heights = GetValues <Height>(Height.TypeId, access); foreach (var h in heights) { ret.Data.Add(new DataUnit { Datetime = h.EffectiveDate, Name = "Height_meters", OntologicName = "rdf:Height", Value = h.Value.Meters }); } var weights = GetValues <Weight>(Weight.TypeId, access); foreach (var w in weights) { ret.Data.Add(new DataUnit { Datetime = w.EffectiveDate, Name = "weight_kg", OntologicName = "rdf:Height", Value = w.Value.Kilograms }); } return(ret); }