/// <summary>
        /// Creates an instance of a HealthRecordInfo object using
        /// the specified XML.
        /// </summary>
        /// 
        /// <param name="connection">
        /// A connection for the current user.
        /// </param>
        /// 
        /// <param name="navigator">
        /// The XML containing the record information.
        /// </param>
        /// 
        /// <returns>
        /// A new instance of a HealthRecordInfo object populated with the
        /// record information.
        /// </returns>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="connection"/> or <paramref name="navigator"/> 
        /// parameter is <b>null</b>.
        /// </exception>
        /// 
        public static new HealthRecordInfo CreateFromXml(
            ApplicationConnection connection,
            XPathNavigator navigator)
        {
            Validator.ThrowIfArgumentNull(connection, "connection", "PersonInfoConnectionNull");
            Validator.ThrowIfArgumentNull(navigator, "navigator", "ParseXmlNavNull");

            HealthRecordInfo recordInfo = new HealthRecordInfo(connection);
            recordInfo.ParseXml(navigator);
            return recordInfo;
        }
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// 
 /// <param name="recordInfo">
 /// The record info object which is to be used as the source 
 /// for the data.
 /// </param>
 /// 
 internal HealthRecordInfo(HealthRecordInfo recordInfo)
     : this(recordInfo.Connection as AuthenticatedConnection, 
         recordInfo.Id)
 {
     if (recordInfo.IsUpdated)
     {
         _custodian = recordInfo.IsCustodian;
         _dateAuthorizationExpires = recordInfo.DateAuthorizationExpires;
         _name = recordInfo.Name;
         _relationshipType = recordInfo.RelationshipType;
         _relationshipName = recordInfo.RelationshipName;
         _displayName = recordInfo.DisplayName;
         _updated = true;
     }
 }
        /// <summary>
        /// Saves a HealthVault record image to blob storage for future use
        /// </summary>
        /// <param name="record"></param>
        public void SaveImageToBlobStorage(HealthRecordInfo record)
        {
            // get the items for the health record and set the type to personImage
            var collection = record.GetItemsByType(PersonalImage.TypeId, HealthRecordItemSections.All);

            PersonalImage image = null;
            if (collection.Count != 0)
            {
                // get the first item which is the image
                image = collection[0] as PersonalImage;

                // Create a stream to read the image into
                using (Stream currentImageStream = image.ReadImage())
                {
                    // Read the image
                    byte[] imageBytes = new byte[currentImageStream.Length];
                    currentImageStream.Read(imageBytes, 0, (int)currentImageStream.Length);

                    // create vars to access blob storage account
                    var account = CloudStorageAccount.Parse(ConnectionString);
                    var client = account.CreateCloudBlobClient();
                    var container = client.GetContainerReference(_containerName);
                    // if it does not exist create it
                    if (container.CreateIfNotExist())
                    {
                        // since it's new we want to change the persmissions of the container to be public
                        var p = new BlobContainerPermissions();
                        p.PublicAccess = BlobContainerPublicAccessType.Container;
                        container.SetPermissions(p);
                    }

                    // get a block blob reference
                    var item = container.GetBlockBlobReference(record.Id.ToString() + ".jpg");

                    // set the type to image
                    item.Properties.ContentType = "image\\jpeg";

                    // upload to blob storage
                    item.UploadByteArray(imageBytes);
                }
            }
        }
        /// <summary> 
        /// Sets the selected health record for the application.
        /// </summary>
        /// 
        /// <param name="activeRecord">
        /// The health record to set as the "active" record for the 
        /// application.
        /// </param>
        /// 
        /// <remarks>
        /// By setting the selected record, the HealthVault page framework will
        /// ensure that every page of the application will have the same 
        /// record selected by serializing the record information into the
        /// session, and deserializing it for each page.
        /// </remarks>
        /// 
        public void SetSelectedRecord(HealthRecordInfo activeRecord)
        {
            _personInfo.SelectedRecord = activeRecord;

            if (!_personInfo.AuthorizedRecords.ContainsKey(activeRecord.Id))
            {
                _personInfo.AuthorizedRecords.Add(activeRecord.Id, activeRecord);
            }
            WebApplicationUtilities.SavePersonInfoToCookie(Context, _personInfo);
        }
 /// <summary>
 /// Gets a health records image url in Azure blob storage
 /// </summary>
 /// <param name="record"></param>
 /// <returns></returns>
 public string GetImageUrl(HealthRecordInfo record)
 {
     return GetImageUrl(record.Id);
 }