public static HealthRecordItemCollection GetHVItemsOffline(Guid personId, Guid recordGuid, DateTime? lastSync) { // Do the offline connection OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection(personId); offlineConn.RequestTimeoutSeconds = 180; //extending time to prevent time outs for accounts with large number of items offlineConn.Authenticate(); HealthRecordAccessor accessor = new HealthRecordAccessor(offlineConn, recordGuid); HealthRecordSearcher searcher = accessor.CreateSearcher(); HealthRecordFilter filter = new HealthRecordFilter(Exercise.TypeId, AerobicSession.TypeId); if (lastSync.HasValue) filter.UpdatedDateMin = (DateTime)lastSync; searcher.Filters.Add(filter); HealthRecordItemCollection items = null; try { items = searcher.GetMatchingItems()[0]; } catch (Exception err) { WlkMiTracer.Instance.Log("HVSync.cs:GetHVItemsOffline", WlkMiEvent.AppSync, WlkMiCat.Error, string.Format("Error for user {0} : {1} ", recordGuid.ToString(), err.ToString())); } return items; }
private string getGroupAverage(string tGroup, string thing) { int sumWt = 0; int sumAge = 0; ParticipantDAO dao = new ParticipantDAO(); ICollection<Participant> participantList = dao.GetTrialGroup(tGroup); foreach (var participant in participantList) { try { OfflineWebApplicationConnection conn = HVConnectionManager.CreateConnection(participant.HVPersonID); HealthRecordAccessor accessor = new HealthRecordAccessor(conn, participant.HVRecordID); HealthRecordSearcher search = accessor.CreateSearcher(); search.Filters.Add(new HealthRecordFilter(Weight.TypeId)); search.Filters.Add(new HealthRecordFilter(Basic.TypeId)); HealthRecordItemCollection items = null; items = search.GetMatchingItems()[0]; var firstStr = items[0].ToString(); var secStr = firstStr.Substring(0, firstStr.IndexOf(" ")); int intVal = Convert.ToInt32(secStr); sumWt = sumWt + intVal; items = search.GetMatchingItems()[1]; var age = items[0].ToString(); age = age.Substring(age.Length-4, 4); intVal = Convert.ToInt32(age); sumAge = sumAge + intVal; } catch (HealthServiceException ex) { String msg = String.Empty; if (ex is HealthServiceAccessDeniedException) msg = "The application may be trying to read user data from an anonymous connection.\n"; msg += ex.Error.ErrorInfo + "\n" + ex.Message.ToString(); Debug.WriteLine(msg); } } if (participantList.Count > 0) { if (thing == "Weight") return (sumWt / participantList.Count).ToString(); else if (thing == "Age") return (2013 - (sumAge / participantList.Count)).ToString(); } return "No participants in Group " + tGroup; }
private void DisplaySelectedParticipant(Participant participant) { lblPatientHeader.Text = participant.FullName; try { OfflineWebApplicationConnection conn = HVConnectionManager.CreateConnection(participant.HVPersonID); HealthRecordAccessor accessor = new HealthRecordAccessor(conn, participant.HVRecordID); HealthRecordSearcher search = accessor.CreateSearcher(); search.Filters.Add(new HealthRecordFilter(Basic.TypeId)); search.Filters.Add(new HealthRecordFilter(Condition.TypeId)); search.Filters.Add(new HealthRecordFilter(Procedure.TypeId)); search.Filters.Add(new HealthRecordFilter(Medication.TypeId)); HealthRecordItemCollection items = null; //Basic info = (Basic)items[0]; items = search.GetMatchingItems()[0]; //Debug.WriteLine(search.GetMatchingItemsRaw()); if (items.Count > 0) lblPatientBasic.Text = "Gender, Birth Year: " + items[0].ToString(); else lblPatientBasic.Text = "No Basic Info Available"; items = search.GetMatchingItems()[1]; if (items.Count > 0) lblPatientCondition.Text = "Condition: " + items[0].ToString(); else lblPatientCondition.Text = "No Weight Info Available"; items = search.GetMatchingItems()[2]; if (items.Count > 0) lblPatientProcedure.Text = "Procedure: " + items[0].ToString(); else lblPatientProcedure.Text = "No Weight Info Available"; items = search.GetMatchingItems()[3]; if (items.Count > 0) lblPatientMedication.Text = "Medications Prescribed: " + items[0].ToString(); else lblPatientMedication.Text = "No Medication Info Available"; } catch (HealthServiceException ex) { String msg = String.Empty; if (ex is HealthServiceAccessDeniedException) msg = "The application may be trying to read user data from an anonymous connection.\n"; msg += ex.Error.ErrorInfo + "\n" + ex.Message.ToString(); Debug.WriteLine(msg); } }
/// <summary> /// Fetch the <see cref="HealthRecordItem" /> instances that are specified /// in the ChangedItems collection. /// </summary> /// <remarks> /// After the operation has completed, see <see cref="HealthRecordItemChangedItem.Item" /> /// to use the fetched <see cref="HealthRecordItem" /> /// /// Items that have been removed from a record or are otherwise inaccessible will /// have a <see cref="HealthRecordItemChangedItem.Item" /> value of null. /// </remarks> /// /// <param name="applicationId">The application id to use.</param> /// <param name="healthServiceUrl">The health service URL to use.</param> /// /// <exception cref="ArgumentNullException"> /// The <paramref name="healthServiceUrl"/> parameter is <b>null</b>. /// </exception> public void GetItems(Guid applicationId, string healthServiceUrl) { Validator.ThrowIfArgumentNull(healthServiceUrl, "healthServiceUrl", "HealthServiceUrlNull"); if (ChangedItems.Count == 0) { return; } OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection( applicationId, healthServiceUrl, _personId); offlineConn.Authenticate(); HealthRecordAccessor accessor = new HealthRecordAccessor(offlineConn, _recordId); HealthRecordSearcher searcher = accessor.CreateSearcher(); HealthRecordFilter filter = new HealthRecordFilter(); searcher.Filters.Add(filter); Dictionary<Guid, HealthRecordItemChangedItem> changedLookup = new Dictionary<Guid, HealthRecordItemChangedItem>(ChangedItems.Count); foreach (HealthRecordItemChangedItem item in ChangedItems) { filter.ItemIds.Add(item.Id); changedLookup.Add(item.Id, item); } HealthRecordItemCollection things = searcher.GetMatchingItems()[0]; // Take the resultant items and put them back in the ChangedItems collection foreach (HealthRecordItem fetchedItem in things) { HealthRecordItemChangedItem item = changedLookup[fetchedItem.Key.Id]; item.Item = fetchedItem; } }
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(); search.Filters.Add(new HealthRecordFilter(HvShellUtilities.NameToTypeId(Type))); foreach (Object o in search.GetMatchingItems()) { WriteObject(o); } }
private XPathNavigator GetPartialThings( HealthRecordAccessor record, IList<HealthRecordItemKey> thingKeys, int currentThingKeyIndex, int numberOfFullThingsToRetrieve) { HealthRecordSearcher searcher = record.CreateSearcher(); HealthRecordFilter filter = new HealthRecordFilter(); for (int i = currentThingKeyIndex; i < thingKeys.Count && i < currentThingKeyIndex + numberOfFullThingsToRetrieve; i++) { filter.ItemKeys.Add(thingKeys[i]); } filter.View = this.Filter.View; filter.States = this.Filter.States; filter.CurrentVersionOnly = this.Filter.CurrentVersionOnly; searcher.Filters.Add(filter); return searcher.GetMatchingItemsRaw(); }
/// <summary> /// Fills in the data table with data from the HealthVault service /// starting at the specific index for the count specified. /// </summary> /// /// <param name="record"> /// The health record to get the data from. /// </param> /// /// <param name="startIndex"> /// The index to start retrieving full data from HealthVault. /// </param> /// /// <param name="count"> /// The count of full items to retrieve. /// </param> /// /// <remarks> /// This method makes a web-method call to the HealthVault service. /// /// The default <see cref="GetData(HealthRecordAccessor)"/> implementation /// fills the data with complete information for all items matching /// the filter. If the <see cref="HealthRecordItemDataTable"/> is being /// bound to a HealthServiceDataGrid or other such control that supports /// paging, this may not be the desired result as many calls to /// HealthVault may be required to fetch all the data. This overload /// of GetData allows the caller to specify the index and the count of /// the full items to retrieve to match the page that is currently visible. /// The <see cref="HealthRecordItemDataTable"/> will be filled with /// empty values except for the rows specified. /// </remarks> /// /// <exception cref="HealthServiceException"> /// An error occurred while accessing the HealthVault service. /// </exception> /// public void GetData( HealthRecordAccessor record, int startIndex, int count) { HealthRecordItemDataTableView effectiveView = this.ApplyEffectiveView(record.Connection); // Need to specify the type version to ensure that the columns match when the app // supports multiple versions. if (effectiveView == HealthRecordItemDataTableView.SingleTypeTable) { for (int index = 0; index < this.Filter.TypeIds.Count; ++index) { this.Filter.View.TypeVersionFormat.Add(this.Filter.TypeIds[index]); } } HealthRecordSearcher searcher = record.CreateSearcher(); searcher.Filters.Add(this.Filter); XPathNavigator nav = searcher.GetMatchingItemsRaw(); _hasData = true; XPathNavigator navFiltered = nav.SelectSingleNode("//group/filtered"); if (navFiltered != null) { _wasFiltered = navFiltered.ValueAsBoolean; } int numberOfFullThingsToRetrieve = AddRows(nav); List<HealthRecordItemKey> partialThingKeys = GetPartialThingKeys(nav); int thingIndex = numberOfFullThingsToRetrieve; int partialThingsCurrentIndex = 0; while (thingIndex < startIndex && partialThingsCurrentIndex < partialThingKeys.Count) { AddPartialThingRow(partialThingKeys[partialThingsCurrentIndex++]); ++thingIndex; } while (thingIndex < startIndex + count && partialThingsCurrentIndex < partialThingKeys.Count) { nav = GetPartialThings( record, partialThingKeys, partialThingsCurrentIndex, numberOfFullThingsToRetrieve); // Note, not all partial things may still exist when doing // the next query so AddRows may return less than // numberOfFullThingsToRetrieve. Just skip anything that is // missing. AddRows(nav); partialThingsCurrentIndex += numberOfFullThingsToRetrieve; thingIndex += numberOfFullThingsToRetrieve; } while (partialThingsCurrentIndex < partialThingKeys.Count) { AddPartialThingRow(partialThingKeys[partialThingsCurrentIndex++]); ++thingIndex; } }
public IEnumerable<HealthRecordItemCollection> getHalthVaultModuleItemCollection(string wcToken, List<HealthModel> _healthModel) { WebApplicationConnection connection = GetConnection(wcToken); Guid recordId = connection.GetPersonInfo().SelectedRecord.Id; HealthRecordAccessor accessor = new HealthRecordAccessor(connection, recordId); HealthRecordSearcher searcher = accessor.CreateSearcher(); var _types = from _type in _healthModel select new { typeName = _type.healthVaultModule.TypeIDs }; foreach (var _type in _types.ToList()) { HealthRecordFilter filter = new HealthRecordFilter(); switch (_type.typeName) { case "Contact": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Contact.TypeId); break; case "BasicV2": filter.TypeIds.Add(Microsoft.Health.ItemTypes.BasicV2.TypeId); break; case "Payer": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Payer.TypeId); break; case "Person": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Person.TypeId); break; case "Personal": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Personal.TypeId); break; case "AerobicProfile": filter.TypeIds.Add(Microsoft.Health.ItemTypes.AerobicProfile.TypeId); break; case "AerobicWeeklyGoal": filter.TypeIds.Add(Microsoft.Health.ItemTypes.AerobicWeeklyGoal.TypeId); break; case "AllergicEpisode": filter.TypeIds.Add(Microsoft.Health.ItemTypes.AllergicEpisode.TypeId); break; case "Allergy": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Allergy.TypeId); break; case "Annotation": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Annotation.TypeId); break; case "ApplicationDataReference": filter.TypeIds.Add(Microsoft.Health.ItemTypes.ApplicationDataReference.TypeId); break; case "ApplicationSpecific": filter.TypeIds.Add(Microsoft.Health.ItemTypes.ApplicationSpecific.TypeId); break; case "Appointment": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Appointment.TypeId); break; case "AsthmaInhaler": filter.TypeIds.Add(Microsoft.Health.ItemTypes.AsthmaInhaler.TypeId); break; case "AsthmaInhalerUse": filter.TypeIds.Add(Microsoft.Health.ItemTypes.AsthmaInhalerUse.TypeId); break; case "Basic": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Basic.TypeId); break; case "BloodGlucose": filter.TypeIds.Add(Microsoft.Health.ItemTypes.BloodGlucose.TypeId); break; case "BloodOxygenSaturation": filter.TypeIds.Add(Microsoft.Health.ItemTypes.BloodOxygenSaturation.TypeId); break; case "BloodPressure": filter.TypeIds.Add(Microsoft.Health.ItemTypes.BloodPressure.TypeId); break; case "BodyComposition": filter.TypeIds.Add(Microsoft.Health.ItemTypes.BodyComposition.TypeId); break; case "BodyDimension": filter.TypeIds.Add(Microsoft.Health.ItemTypes.BodyDimension.TypeId); break; case "CalorieGuideline": filter.TypeIds.Add(Microsoft.Health.ItemTypes.CalorieGuideline.TypeId); break; case "CardiacProfile": filter.TypeIds.Add(Microsoft.Health.ItemTypes.CardiacProfile.TypeId); break; case "CarePlan": filter.TypeIds.Add(Microsoft.Health.ItemTypes.CarePlan.TypeId); break; case "CCD": filter.TypeIds.Add(Microsoft.Health.ItemTypes.CCD.TypeId); break; case "CCR": filter.TypeIds.Add(Microsoft.Health.ItemTypes.CCR.TypeId); break; case "CDA": filter.TypeIds.Add(Microsoft.Health.ItemTypes.CDA.TypeId); break; case "CholesterolProfile": filter.TypeIds.Add(Microsoft.Health.ItemTypes.CholesterolProfile.TypeId); break; case "Comment": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Comment.TypeId); break; case "Concern": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Concern.TypeId); break; case "Condition": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Condition.TypeId); break; case "Contraindication": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Contraindication.TypeId); break; case "DailyMedicationUsage": filter.TypeIds.Add(Microsoft.Health.ItemTypes.DailyMedicationUsage.TypeId); break; case "Device": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Device.TypeId); break; case "DiabeticProfile": filter.TypeIds.Add(Microsoft.Health.ItemTypes.DiabeticProfile.TypeId); break; case "DietaryDailyIntake": filter.TypeIds.Add(Microsoft.Health.ItemTypes.DietaryDailyIntake.TypeId); break; case "Directive": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Directive.TypeId); break; case "DischargeSummary": filter.TypeIds.Add(Microsoft.Health.ItemTypes.DischargeSummary.TypeId); break; case "Emotion": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Emotion.TypeId); break; case "Encounter": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Encounter.TypeId); break; case "Exercise": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Exercise.TypeId); break; case "ExerciseSamples": filter.TypeIds.Add(Microsoft.Health.ItemTypes.ExerciseSamples.TypeId); break; case "ExplanationOfBenefits": filter.TypeIds.Add(Microsoft.Health.ItemTypes.ExplanationOfBenefits.TypeId); break; case "FamilyHistory": filter.TypeIds.Add(Microsoft.Health.ItemTypes.FamilyHistory.TypeId); break; case "FamilyHistoryCondition": filter.TypeIds.Add(Microsoft.Health.ItemTypes.FamilyHistoryCondition.TypeId); break; case "FamilyHistoryPerson": filter.TypeIds.Add(Microsoft.Health.ItemTypes.FamilyHistoryPerson.TypeId); break; case "FamilyHistoryV3": filter.TypeIds.Add(Microsoft.Health.ItemTypes.FamilyHistoryV3.TypeId); break; case "File": filter.TypeIds.Add(Microsoft.Health.ItemTypes.File.TypeId); break; case "GeneticSnpResults": filter.TypeIds.Add(Microsoft.Health.ItemTypes.GeneticSnpResults.TypeId); break; case "GroupMembership": filter.TypeIds.Add(Microsoft.Health.ItemTypes.GroupMembership.TypeId); break; case "GroupMembershipActivity": filter.TypeIds.Add(Microsoft.Health.ItemTypes.GroupMembershipActivity.TypeId); break; case "HbA1C": filter.TypeIds.Add(Microsoft.Health.ItemTypes.HbA1C.TypeId); break; case "HealthAssessment": filter.TypeIds.Add(Microsoft.Health.ItemTypes.HealthAssessment.TypeId); break; case "HealthcareProxy": filter.TypeIds.Add(Microsoft.Health.ItemTypes.HealthcareProxy.TypeId); break; case "HealthEvent": filter.TypeIds.Add(Microsoft.Health.ItemTypes.HealthEvent.TypeId); break; case "HealthJournalEntry": filter.TypeIds.Add(Microsoft.Health.ItemTypes.HealthJournalEntry.TypeId); break; case "HeartRate": filter.TypeIds.Add(Microsoft.Health.ItemTypes.HeartRate.TypeId); break; case "Height": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Height.TypeId); break; case "Immunization": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Immunization.TypeId); break; case "InsulinInjection": filter.TypeIds.Add(Microsoft.Health.ItemTypes.InsulinInjection.TypeId); break; case "InsulinInjectionUse": filter.TypeIds.Add(Microsoft.Health.ItemTypes.InsulinInjectionUse.TypeId); break; case "LabTestResults": filter.TypeIds.Add(Microsoft.Health.ItemTypes.LabTestResults.TypeId); break; case "LifeGoal": filter.TypeIds.Add(Microsoft.Health.ItemTypes.LifeGoal.TypeId); break; case "Link": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Link.TypeId); break; case "MedicalImageStudy": filter.TypeIds.Add(Microsoft.Health.ItemTypes.MedicalImageStudy.TypeId); break; case "MedicalImageStudyV2": filter.TypeIds.Add(Microsoft.Health.ItemTypes.MedicalImageStudyV2.TypeId); break; case "Medication": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Medication.TypeId); break; case "MedicationFill": filter.TypeIds.Add(Microsoft.Health.ItemTypes.MedicationFill.TypeId); break; case "Message": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Message.TypeId); break; case "MicrobiologyLabResults": filter.TypeIds.Add(Microsoft.Health.ItemTypes.MicrobiologyLabResults.TypeId); break; case "PapSession": filter.TypeIds.Add(Microsoft.Health.ItemTypes.PapSession.TypeId); break; case "PasswordProtectedPackage": filter.TypeIds.Add(Microsoft.Health.ItemTypes.PasswordProtectedPackage.TypeId); break; case "PeakFlow": filter.TypeIds.Add(Microsoft.Health.ItemTypes.PeakFlow.TypeId); break; case "PersonalImage": filter.TypeIds.Add(Microsoft.Health.ItemTypes.PersonalImage.TypeId); break; case "Pregnancy": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Pregnancy.TypeId); break; case "Problem": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Problem.TypeId); break; case "Procedure": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Procedure.TypeId); break; case "QuestionAnswer": filter.TypeIds.Add(Microsoft.Health.ItemTypes.QuestionAnswer.TypeId); break; case "RadiologyLabResults": filter.TypeIds.Add(Microsoft.Health.ItemTypes.RadiologyLabResults.TypeId); break; case "RespiratoryProfile": filter.TypeIds.Add(Microsoft.Health.ItemTypes.RespiratoryProfile.TypeId); break; case "SleepJournalAM": filter.TypeIds.Add(Microsoft.Health.ItemTypes.SleepJournalAM.TypeId); break; case "SleepJournalPM": filter.TypeIds.Add(Microsoft.Health.ItemTypes.SleepJournalPM.TypeId); break; case "Status": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Status.TypeId); break; case "VitalSigns": filter.TypeIds.Add(Microsoft.Health.ItemTypes.VitalSigns.TypeId); break; case "Weight": filter.TypeIds.Add(Microsoft.Health.ItemTypes.Weight.TypeId); break; case "WeightGoal": filter.TypeIds.Add(Microsoft.Health.ItemTypes.WeightGoal.TypeId); break; } searcher.Filters.Add(filter); } IEnumerable<HealthRecordItemCollection> _healthRecordCollection = searcher.GetMatchingItems(); return _healthRecordCollection; }
private void LoadUI() { lblPatientHeader.Text = selectedParticipant.FullName; OfflineWebApplicationConnection conn = HVConnectionManager.CreateConnection(selectedParticipant.HVPersonID); HealthRecordAccessor accessor = new HealthRecordAccessor(conn, selectedParticipant.HVRecordID); HealthRecordSearcher search = accessor.CreateSearcher(); search.Filters.Add(new HealthRecordFilter(Basic.TypeId)); search.Filters.Add(new HealthRecordFilter(Allergy.TypeId)); HealthRecordItemCollection items = null; lblBasic.Text = "Gender, Birth Year: "; items = search.GetMatchingItems()[0]; if (items.Count > 0) tbBasic.Text = items[0].ToString(); else tbBasic.Text = "No Basic Info Available"; lblAllergies.Text = "Allergies:"; items = search.GetMatchingItems()[1]; if (items.Count > 0) tbAllergies.Text = items[0].ToString(); else tbAllergies.Text = "No Allergies Info Available"; //foreach (Guid typeId in lblLabelDict.Keys) //{ // search.Filters.Add(new HealthRecordFilter(typeId)); //} //foreach (Guid TypeId in lblLabelDict.Keys) //{ // Label lbl = lblLabelDict[TypeId]; // lbl.Text = lblTextDict[TypeId]; // TextBox tb = tbDict[TypeId]; // try // { // HealthRecordItem item = search.GetSingleItem(TypeId, HealthRecordItemSections.All); // tb.Text = item.ToString(); // } // catch (Exception e) // { // Debug.WriteLine(e.Message); // tb.Text = "No info available"; // } //} }