public void WhenHealthVaultCdaToFhirToHealthVault_ThenValuesEqual()
        {
            string inputCdaXmlRaw = SampleUtil.GetSampleContent("CDA.xml");

            XPathDocument xpDoc = DocumentReferenceHelper.GetXPathDocumentFromXml(inputCdaXmlRaw);

            CDA inputCda = new CDA();

            inputCda.TypeSpecificData = xpDoc;

            var documentReference = inputCda.ToFhir() as DocumentReference;

            var cda = documentReference.ToHealthVault() as CDA;

            XPathDocument cdaXPathDoc = DocumentReferenceHelper.GetXPathDocumentFromXml(inputCdaXmlRaw) ?? throw new Exception("Invalid XML");

            // XML gets generated using a common method in order to use in Assert.AreEqual
            string inputCdaXml = DocumentReferenceHelper.GetXmlFromXPathNavigator(cdaXPathDoc.CreateNavigator());

            Assert.IsNotNull(cda);
            Assert.IsNotNull(cda.TypeSpecificData);

            string cdaXml = DocumentReferenceHelper.GetXmlFromXPathNavigator(cda.TypeSpecificData.CreateNavigator());

            Assert.AreEqual(inputCdaXml, cdaXml);
        }
        public void WhenFhirCdaTransformedToHealthVault_ThenValuesEqual()
        {
            var json = SampleUtil.GetSampleContent("FhirCDA.json");

            var fhirParser        = new FhirJsonParser();
            var documentReference = fhirParser.Parse <DocumentReference>(json);

            string fhirAttachmentDataBase64Encoded = JObject.Parse(json)["content"][0]["attachment"]["data"].ToString();

            string fhirXmlRaw = Encoding.UTF8.GetString(Convert.FromBase64String(fhirAttachmentDataBase64Encoded));

            XPathDocument fhirXPathDoc = DocumentReferenceHelper.GetXPathDocumentFromXml(fhirXmlRaw) ?? throw new Exception("Invalid XML");

            // XML gets generated using a common method in order to use in Assert.AreEqual
            string fhirXml = DocumentReferenceHelper.GetXmlFromXPathNavigator(fhirXPathDoc.CreateNavigator());

            var cda = documentReference.ToHealthVault() as CDA;

            Assert.IsNotNull(cda);
            Assert.IsNotNull(cda.TypeSpecificData);

            string cdaXml = DocumentReferenceHelper.GetXmlFromXPathNavigator(cda.TypeSpecificData.CreateNavigator());

            Assert.AreEqual(fhirXml, cdaXml);
        }
        public void WhenHealthVaultCcrTransformedToFhir_ThenValuesEqual()
        {
            string        cdaXmlRaw = SampleUtil.GetSampleContent("CCR.xml");
            XPathDocument xpDoc     = DocumentReferenceHelper.GetXPathDocumentFromXml(cdaXmlRaw);

            CCR ccr = new CCR();

            ccr.TypeSpecificData = xpDoc;

            var documentReference = ccr.ToFhir() as DocumentReference;

            Assert.IsNotNull(documentReference);
            Assert.IsNotNull(documentReference.Type);
            Assert.AreEqual(documentReference.Content.Count, 1);
            Assert.IsNotNull(documentReference.Content[0].Attachment);
            Assert.IsNotNull(documentReference.Content[0].Attachment.Data);
            Assert.IsNotNull(documentReference.Content[0].Attachment.ContentType, "application/xml");

            string ccrXml = DocumentReferenceHelper.GetXmlFromXPathNavigator(ccr.TypeSpecificData.CreateNavigator());
            string ccrContentBase64Encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(ccrXml));

            string fhirAttachmentDataBase64Encoded = Convert.ToBase64String(documentReference.Content[0].Attachment.Data);

            Assert.AreEqual(fhirAttachmentDataBase64Encoded, ccrContentBase64Encoded);
        }
Exemplo n.º 4
0
        public void WhenHealthVaultCdaTransformedToFhir_ThenValuesEqual()
        {
            string cdaXmlRaw = SampleUtil.GetSampleContent("CDA.xml");

            XPathDocument xpDoc = DocumentReferenceHelper.GetXPathDocumentFromXml(cdaXmlRaw);

            Assert.IsNotNull(xpDoc);

            CDA cda = new CDA();

            cda.TypeSpecificData = xpDoc;

            var documentReference = cda.ToFhir() as DocumentReference;

            Assert.IsNotNull(documentReference);
            Assert.IsNotNull(documentReference.Type);
            Assert.AreEqual(documentReference.Content.Count, 1);
            Assert.IsNotNull(documentReference.Content[0].Attachment);
            Assert.IsNotNull(documentReference.Content[0].Attachment.Data);
            Assert.IsNotNull(documentReference.Content[0].Attachment.ContentType, "application/xml");

            string cdaXml = DocumentReferenceHelper.GetXmlFromXPathNavigator(cda.TypeSpecificData.CreateNavigator());
            string cdaContentBase64Encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(cdaXml));

            string fhirXmlRaw = Encoding.UTF8.GetString(documentReference.Content[0].Attachment.Data);

            XPathDocument fhirXPathDoc;

            using (TextReader txtReader = new StringReader(fhirXmlRaw))
            {
                fhirXPathDoc = new XPathDocument(txtReader);
            }

            string fhirXml = DocumentReferenceHelper.GetXmlFromXPathNavigator(xpDoc.CreateNavigator());
            string fhirAttachmentDataBase64Encoded = Convert.ToBase64String(documentReference.Content[0].Attachment.Data);

            Assert.AreEqual(fhirAttachmentDataBase64Encoded, cdaContentBase64Encoded);
        }
        public void WhenHealthVaultThingIsTransformedToFhirDocumentReference_ThenTypeAndStatusAndIndexedFieldsSet()
        {
            string        cdaXmlRaw = SampleUtil.GetSampleContent("CCR.xml");
            XPathDocument xpDoc     = DocumentReferenceHelper.GetXPathDocumentFromXml(cdaXmlRaw);

            CCR ccr = new CCR();

            ccr.TypeSpecificData = xpDoc;
            ccr.EffectiveDate    = new NodaTime.LocalDateTime(2016, 05, 09, 3, 36, 55);

            var documentReference = ccr.ToFhir() as DocumentReference;

            Assert.IsNotNull(documentReference);
            Assert.IsNotNull(documentReference.Type);
            Assert.IsNotNull(documentReference.Status);
            Assert.AreEqual(documentReference.Status, DocumentReferenceStatus.Current);
            Assert.IsNotNull(documentReference.Indexed);

            var indexed = documentReference.Indexed.Value;
            var indexedLocalDateTime = new NodaTime.LocalDateTime(indexed.Year, indexed.Month, indexed.Day, indexed.Hour, indexed.Minute, indexed.Second);

            Assert.AreEqual(indexedLocalDateTime, ccr.EffectiveDate.Value);
        }