internal static CDA ToCDA(this DocumentReference documentReference) { var contentComponent = documentReference.GetFirstContentComponentWithData(); CDA cda = documentReference.ToThingBase <CDA>(); string xml = Encoding.UTF8.GetString(contentComponent.Attachment.Data); XPathDocument xpDoc = ThingBaseToFhirDocumentReference.GetXPathNavigatorFromXml(xml); cda.TypeSpecificData = xpDoc; return(cda); }
internal static File ToFile(this DocumentReference documentReference) { var contentComponent = documentReference.GetFirstContentComponentWithData(); File file = documentReference.ToThingBase <File>(); MethodInfo getBlobStoreMethod = file.GetType().GetMethod("GetBlobStore", BindingFlags.NonPublic | BindingFlags.Instance); Type healthRecordAccessorType = Type.GetType("Microsoft.HealthVault.Thing.HealthRecordAccessor, Microsoft.HealthVault"); var healthRecordAccessor = healthRecordAccessorType.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).First(constructor => constructor.GetParameters().Length == 0).Invoke(null); var blobStore = getBlobStoreMethod.Invoke(file, new object[] { healthRecordAccessor }); MethodInfo newBlob = blobStore.GetType().GetMethod("NewBlob", new Type[] { typeof(string), typeof(string) }); var attachment = contentComponent.Attachment; Blob blob = (Blob)newBlob.Invoke(blobStore, new object[] { string.Empty, attachment.ContentType }); blob.WriteInline(attachment.Data); file.ContentType = new CodableValue(attachment.ContentType); return(file); }