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 Type DetectHealthVaultTypeFromDocumentReference(DocumentReference documentReference) { var contentComponent = documentReference.GetFirstContentComponentWithData(); if (contentComponent.Attachment.ContentType == "text/xml" || contentComponent.Attachment.ContentType == "application/xml") { string xml = Encoding.UTF8.GetString(contentComponent.Attachment.Data); XPathDocument xpDoc; try { using (System.IO.TextReader txtReader = new System.IO.StringReader(xml)) { xpDoc = new XPathDocument(txtReader); } XPathNavigator xpNav = xpDoc.CreateNavigator(); xpNav.MoveToFirstChild(); do { if (xpNav.NodeType == XPathNodeType.Element) { switch (xpNav.Name) { case "ContinuityOfCareRecord": return(typeof(CCR)); case "ClinicalDocument": return(typeof(CDA)); } } } while (xpNav.MoveToNext()); } catch (XmlException) { } } return(typeof(File)); }
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); }