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 static HealthClientApplication GetClient() { HealthClientApplication clientApp = HealthClientApplication.Create( HvShellUtilities.GetClientId(), _HVPowerShellGuid, _HVShell, _HVPlatform); return(clientApp); }
/// <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); } }
/// <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"); }
/// <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); }
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); }