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);
        }
        public void WhenHealthVaultCcrTransformedToFhirToHealthVault_ThenValuesEqual()
        {
            string inputCcrXmlRaw = SampleUtil.GetSampleContent("CCR.xml");

            XPathDocument xpDoc = DocumentReferenceHelper.GetXPathDocumentFromXml(inputCcrXmlRaw) ?? throw new Exception("Invalid XML");

            CCR inputCcr = new CCR();

            inputCcr.TypeSpecificData = xpDoc;

            var documentReference = inputCcr.ToFhir() as DocumentReference;

            var ccr = documentReference.ToHealthVault() as CCR;

            XPathDocument ccrXPathDoc = DocumentReferenceHelper.GetXPathDocumentFromXml(inputCcrXmlRaw) ?? throw new Exception("Invalid XML");

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

            Assert.IsNotNull(ccr);
            Assert.IsNotNull(ccr.TypeSpecificData);

            string ccrXml = DocumentReferenceHelper.GetXmlFromXPathNavigator(ccr.TypeSpecificData.CreateNavigator());

            Assert.AreEqual(inputCcrXml, ccrXml);
        }
        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);
        }