Пример #1
0
        private static void convertResourcePoco(string inputFile, string outputFile)
        {
            //TODO: call validation after reading
            if (inputFile.Contains("expansions.") || inputFile.Contains("profiles-resources") || inputFile.Contains("profiles-others") || inputFile.Contains("valuesets."))
            {
                return;
            }
            if (inputFile.EndsWith(".xml"))
            {
                var xml      = File.ReadAllText(inputFile);
                var resource = new FhirXmlParser().Parse <Resource>(xml);

                var r2 = resource.DeepCopy();
                Assert.IsTrue(resource.Matches(r2 as Resource), "Serialization of " + inputFile + " did not match output - Matches test");
                Assert.IsTrue(resource.IsExactly(r2 as Resource), "Serialization of " + inputFile + " did not match output - IsExactly test");
                Assert.IsFalse(resource.Matches(null), "Serialization of " + inputFile + " matched null - Matches test");
                Assert.IsFalse(resource.IsExactly(null), "Serialization of " + inputFile + " matched null - IsExactly test");

                var json = new FhirJsonSerializer().SerializeToString(resource);
                File.WriteAllText(outputFile, json);
            }
            else
            {
                var json     = File.ReadAllText(inputFile);
                var resource = new FhirJsonParser().Parse <Resource>(json);
                var xml      = new FhirXmlSerializer().SerializeToString(resource);
                File.WriteAllText(outputFile, xml);
            }
        }
Пример #2
0
        private void convertResource(string inputFile, string outputFile)
        {
            //TODO: call validation after reading

            if (inputFile.EndsWith(".xml"))
            {
                var xml      = File.ReadAllText(inputFile);
                var resource = new FhirXmlParser().Parse <Resource>(xml);

                var r2 = resource.DeepCopy();
                Assert.IsTrue(resource.Matches(r2 as Resource), "Serialization of " + inputFile + " did not match output - Matches test");
                Assert.IsTrue(resource.IsExactly(r2 as Resource), "Serialization of " + inputFile + " did not match output - IsExactly test");
                Assert.IsFalse(resource.Matches(null), "Serialization of " + inputFile + " matched null - Matches test");
                Assert.IsFalse(resource.IsExactly(null), "Serialization of " + inputFile + " matched null - IsExactly test");

                var json = FhirSerializer.SerializeResourceToJson(resource);
                File.WriteAllText(outputFile, json);
            }
            else
            {
                var json     = File.ReadAllText(inputFile);
                var resource = new FhirJsonParser().Parse <Resource>(json);
                var xml      = FhirSerializer.SerializeResourceToXml(resource);
                File.WriteAllText(outputFile, xml);
            }
        }
Пример #3
0
        private static void convertResourcePoco(string inputFile, string outputFile)
        {
            if (inputFile.EndsWith(".xml"))
            {
                var xml      = File.ReadAllText(inputFile);
                var resource = new FhirXmlParser(new ParserSettings {
                    PermissiveParsing = true
                }).Parse <Resource>(xml);

                var r2 = resource.DeepCopy();
                Assert.IsTrue(resource.Matches(r2 as Resource), "Serialization of " + inputFile + " did not match output - Matches test");
                Assert.IsTrue(resource.IsExactly(r2 as Resource), "Serialization of " + inputFile + " did not match output - IsExactly test");
                Assert.IsFalse(resource.Matches(null), "Serialization of " + inputFile + " matched null - Matches test");
                Assert.IsFalse(resource.IsExactly(null), "Serialization of " + inputFile + " matched null - IsExactly test");

                var json = new FhirJsonSerializer().SerializeToString(resource);
                File.WriteAllText(outputFile, json);
            }
            else
            {
                var json     = File.ReadAllText(inputFile);
                var resource = new FhirJsonParser(new ParserSettings {
                    PermissiveParsing = true
                }).Parse <Resource>(json);
                var xml = new FhirXmlSerializer().SerializeToString(resource);
                File.WriteAllText(outputFile, xml);
            }
        }
Пример #4
0
        public void CheckCompareDeepCopied()
        {
            string xml = ReadTestData("TestPatient.xml");

            var p  = new FhirXmlParser().Parse <Patient>(xml);
            var p2 = (Patient)p.DeepCopy();

            Assert.IsTrue(p2.IsExactly(p));
        }
        public void CheckCopyCarePlan()
        {
            string xml = File.ReadAllText(@"TestData\careplan-example-f201-renal.xml");

            var p    = new FhirXmlParser().Parse <CarePlan>(xml);
            var p2   = (CarePlan)p.DeepCopy();
            var xml2 = FhirSerializer.SerializeResourceToXml(p2);

            XmlAssert.AreSame(xml, xml2);
        }
        public void CheckCopyAllFields()
        {
            string xml = File.ReadAllText(@"TestData\TestPatient.xml");

            var p    = new FhirXmlParser().Parse <Patient>(xml);
            var p2   = (Patient)p.DeepCopy();
            var xml2 = FhirSerializer.SerializeResourceToXml(p2);

            XmlAssert.AreSame(xml, xml2);
        }
Пример #7
0
        public void CheckMatchDeepCopied()
        {
            string xml = File.ReadAllText(@"TestData\TestPatient.xml");

            var p  = new FhirXmlParser().Parse <Patient>(xml);
            var p2 = (Patient)p.DeepCopy();

            Assert.IsTrue(p2.Matches(p));
            Assert.IsTrue(p.Matches(p2));
        }
Пример #8
0
        public void CheckCopyCarePlan()
        {
            string xml = ReadTestData(@"careplan-example-f201-renal.xml");

            var p    = new FhirXmlParser().Parse <CarePlan>(xml);
            var p2   = (CarePlan)p.DeepCopy();
            var xml2 = new FhirXmlSerializer().SerializeToString(p2);

            XmlAssert.AreSame("careplan-example-f201-renal.xml", xml, xml2);
        }
Пример #9
0
        public void CheckCopyAllFields()
        {
            string xml = ReadTestData("TestPatient.xml");

            var p    = new FhirXmlParser().Parse <Patient>(xml);
            var p2   = (Patient)p.DeepCopy();
            var xml2 = new FhirXmlSerializer().SerializeToString(p2);

            XmlAssert.AreSame("TestPatient.xml", xml, xml2);
        }
Пример #10
0
        public void CheckCompareListChanged()
        {
            string xml = ReadTestData("TestPatient.xml");

            var p  = new FhirXmlParser().Parse <Patient>(xml);
            var p2 = (Patient)p.DeepCopy();

            var rel = (CodeableConcept)p.Contact[0].Relationship[0].DeepCopy();

            p2.Contact[0].Relationship.Add(rel);

            Assert.IsFalse(p2.IsExactly(p));
        }
Пример #11
0
        public void CheckCompareListChanged()
        {
            string xml = File.ReadAllText(@"TestData\TestPatient.xml");

            var p  = new FhirXmlParser().Parse <Patient>(xml);
            var p2 = (Patient)p.DeepCopy();

            var rel = (CodeableConcept)p.Contact[0].Relationship[0].DeepCopy();

            p2.Contact[0].Relationship.Add(rel);

            Assert.IsTrue(p2.Matches(p));
            Assert.IsTrue(p2.Matches(p));
        }
Пример #12
0
        public void CheckComparePrimitiveChanged()
        {
            string xml = ReadTestData("TestPatient.xml");

            var p  = new FhirXmlParser().Parse <Patient>(xml);
            var p2 = (Patient)p.DeepCopy();

            p2.ActiveElement.Value = !p2.ActiveElement.Value;
            Assert.IsFalse(p2.IsExactly(p));
            p2.ActiveElement.Value = null;
            Assert.IsFalse(p2.IsExactly(p));

            p2.Contact[0].Relationship[0].Coding[0].System = "http://nu.nl/different";

            Assert.IsFalse(p2.IsExactly(p));
        }
Пример #13
0
        public void CheckCopyPerformance()
        {
            string xml = ReadTestData("TestPatient.xml");

            var p  = new FhirXmlParser().Parse <Patient>(xml);
            var sw = new Stopwatch();

            sw.Start();
            for (var loop = 0; loop < 1000; loop++)
            {
                p.DeepCopy();
            }
            sw.Stop();

            Console.WriteLine(sw.ElapsedMilliseconds);
        }
Пример #14
0
        public void CheckComparePrimitiveChanged()
        {
            string xml = File.ReadAllText(@"TestData\TestPatient.xml");

            var p  = new FhirXmlParser().Parse <Patient>(xml);
            var p2 = (Patient)p.DeepCopy();

            // If you set an element to null in the pattern, it need not be set in the source
            p2.Gender = null;
            Assert.IsFalse(p2.Matches(p));
            Assert.IsTrue(p.Matches(p2));

            // If both are null, we're fine
            p.Gender = null;
            Assert.IsTrue(p2.Matches(p));
            Assert.IsTrue(p.Matches(p2));

            p2.Contact[0].Relationship[0].Coding[0].System = "http://nu.nl/different";

            Assert.IsFalse(p2.Matches(p));
            Assert.IsFalse(p.Matches(p2));
        }