Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

4. Using the HealthVault Data Ecosystem ... > Extending HealthVault Data Types - Pg. 66

Extending HealthVault Data Types Applications frequently have to represent something that is not encapsulated by the data structure of the HealthVault data types. Out of the box, HealthVault provides a mechanism by which a data type can be extended. Every application can choose to write XML information in the extension tag within the common data section of a data type. It is recommended that applications distinguish their extension elements by using a unique source attribute on the extension element. In our example, let's assume we are extending the daily dietary intake type to add information on alcohol consumption. Creating a Type Extension We would like to track the amount of alcohol consumed in a simple element called "alcoholic-drinks". To simplify things further, we assume this element represents the number of alcoholic drinks including wine, beer, cocktails etc., and is normalized to mean average alcohol per unit. The first step is to write an alcoholic-drinks XML element within the extension tag using a unique source ( _appDailyAlcoholExtensionName ) in the extension element. Lines ­ in Example 4-9 show how one can do it in the .NET SDK. Example 4-9. Creating a type extension protected void Submit_Daily_Diet_Click(object sender, System.EventArgs e) { //Post Diet DietaryDailyIntake diet = new DietaryDailyIntake(); int totalCarbs; int.TryParse(Txt_DailyDietCarbs.Text, out totalCarbs); diet.TotalCarbohydrates.Kilograms = totalCarbs * 1000; diet.CommonData.Note = Txt_DailyDietNote.Text; //Adding extension data string drinks = Txt_DailyDietAlcohol.Text; HealthRecordItemExtension extension = new HealthRecordItemExtension(_appDailyAlcoholExtensionName); diet.CommonData.Extensions.Add(extension); XPathNavigator navigator = extension.ExtensionData.CreateNavigator(); navigator.InnerXml = @"<extension source=""" + _appDailyAlcoholExtensionName + @"""> <alcoholic-drinks>" + drinks + "</alcoholic-drinks>"; } PersonInfo.SelectedRecord.NewItem(diet); 66 | Chapter 4:Using the HealthVault Data Ecosystem for Self-Tracking