Esempio n. 1
0
 private static void convertResourceNav(string inputFile, string outputFile, IStructureDefinitionSummaryProvider provider)
 {
     //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 nav  = XmlParsingHelpers.ParseToTypedElement(xml, provider);
         var json = nav.ToJson();
         File.WriteAllText(outputFile, json);
     }
     else
     {
         var json = File.ReadAllText(inputFile);
         var nav  = JsonParsingHelpers.ParseToTypedElement(json, provider,
                                                           settings: new FhirJsonParsingSettings {
             AllowJsonComments = true
         });
         var xml = nav.ToXml();
         File.WriteAllText(outputFile, xml);
     }
 }
Esempio n. 2
0
        private void testSubtree(ITypedElement navXml, ITypedElement navJson, ITypedElement navPoco)
        {
            assertAreNavsEqual(navXml, navJson, navPoco);

            var navRtXml = JsonParsingHelpers.ParseToTypedElement(navXml.ToJson(), navXml.InstanceType,
                                                                  new PocoStructureDefinitionSummaryProvider(), navXml.Name);
            var navRtJson = navJson.ToPoco().ToTypedElement(navJson.Name);
            var navRtPoco = XmlParsingHelpers.ParseToTypedElement(navPoco.ToXml(), navPoco.InstanceType,
                                                                  new PocoStructureDefinitionSummaryProvider());

            assertAreNavsEqual(navRtXml, navRtJson, navRtPoco);
        }
        public void PingpongXml()
        {
            var tp = File.ReadAllText(Path.Combine("TestData", "fp-test-patient.xml"));
            // will allow whitespace and comments to come through
            var navXml = XmlParsingHelpers.ParseToTypedElement(tp, new PocoStructureDefinitionSummaryProvider());
            var json   = navXml.ToJson();

            var navJson = JsonParsingHelpers.ParseToTypedElement(json, new PocoStructureDefinitionSummaryProvider());
            var xml     = navJson.ToXml();

            XmlAssert.AreSame("fp-test-patient.xml", tp, xml, ignoreSchemaLocation: true);
        }
        public void PingpongJson()
        {
            var tp = File.ReadAllText(@"TestData\fp-test-patient.json");
            // will allow whitespace and comments to come through
            var navJson = JsonParsingHelpers.ParseToTypedElement(tp, new PocoStructureDefinitionSummaryProvider());
            var xml     = navJson.ToXml();

            var navXml = XmlParsingHelpers.ParseToTypedElement(xml, new PocoStructureDefinitionSummaryProvider());
            var json   = navXml.ToJson();

            JsonAssert.AreSame(tp, json);
        }
        public void CatchesComplexPrimitiveMismatch()
        {
            // First, use a simple value where a complex type was expected
            var tp      = "{ 'resourceType' : 'Patient', 'maritalStatus' : 'UNK' }";
            var navJson = JsonParsingHelpers.ParseToTypedElement(tp, new PocoStructureDefinitionSummaryProvider());
            var errors  = navJson.VisitAndCatch();

            Assert.IsTrue(errors.Single().Message.Contains("it cannot have a value"));

            // then, use a simple value where an array (of a complex type) was expected
            tp      = "{ 'resourceType' : 'Patient', 'name' : ['Ewout'] }";
            navJson = JsonParsingHelpers.ParseToTypedElement(tp, new PocoStructureDefinitionSummaryProvider());
            errors  = navJson.VisitAndCatch();
            Assert.IsTrue(errors.Single().Message.Contains("it cannot have a value"));
        }
        public void CatchesSingleValueForArray()
        {
            // Use a single element where an array was expected
            var tp      = "{ 'resourceType' : 'Patient', 'identifier' :  { 'value': 'AB60001' }}";
            var navJson = JsonParsingHelpers.ParseToTypedElement(tp, new PocoStructureDefinitionSummaryProvider());
            var errors  = navJson.VisitAndCatch();

            Assert.IsTrue(errors.Single().Message.Contains("an array must be used here"));

            // Use an array where a single value was expected
            tp      = "{ 'resourceType' : 'Patient', 'active' : [true,false] }";
            navJson = JsonParsingHelpers.ParseToTypedElement(tp, new PocoStructureDefinitionSummaryProvider());
            errors  = navJson.VisitAndCatch();
            Assert.IsTrue(errors.Single().Message.Contains("an array must not be used here"));
        }
        public void PingpongJson()
        {
            var tp = File.ReadAllText(Path.Combine("TestData", "fp-test-patient.json"));
            // will allow whitespace and comments to come through
            var navJson = JsonParsingHelpers.ParseToTypedElement(tp, new PocoStructureDefinitionSummaryProvider());
            var xml     = navJson.ToXml();

            var navXml = XmlParsingHelpers.ParseToTypedElement(xml, new PocoStructureDefinitionSummaryProvider());
            var json   = navXml.ToJson();

            List <string> errors = new List <string>();

            JsonAssert.AreSame(@"TestData\fp-test-patient.json", tp, json, errors);
            Console.WriteLine(String.Join("\r\n", errors));
            Assert.AreEqual(0, errors.Count, "Errors were encountered comparing converted content");
        }
Esempio n. 8
0
        public void CompareXmlJsonParseOutcomes()
        {
            var tpXml   = File.ReadAllText(@"TestData\fp-test-patient.xml");
            var tpJson  = File.ReadAllText(@"TestData\fp-test-patient.json");
            var navXml  = getXmlNode(tpXml);
            var navJson = JsonParsingHelpers.ParseToTypedElement(tpJson, new PocoStructureDefinitionSummaryProvider());

            var compare = navXml.IsEqualTo(navJson);

            if (compare.Success == false)
            {
                Debug.WriteLine($"Difference in {compare.Details} at {compare.FailureLocation}");
                Assert.IsTrue(compare.Success);
            }
            Assert.IsTrue(compare.Success);
        }
        public void CompareXmlJsonParseOutcomes()
        {
            var tpXml  = File.ReadAllText(Path.Combine("TestData", "fp-test-patient.xml"));
            var tpJson = File.ReadAllText(Path.Combine("TestData", "fp-test-patient.json"));

            // If on a Unix platform replace \\r\\n in json strings to \\n.
            if (Environment.NewLine == "\n")
            {
                tpJson = tpJson.Replace(@"\r\n", @"\n");
            }
            var navXml  = getXmlNode(tpXml);
            var navJson = JsonParsingHelpers.ParseToTypedElement(tpJson, new PocoStructureDefinitionSummaryProvider());

            var compare = navXml.IsEqualTo(navJson);

            if (compare.Success == false)
            {
                Debug.WriteLine($"Difference in {compare.Details} at {compare.FailureLocation}");
                Assert.IsTrue(compare.Success);
            }
            Assert.IsTrue(compare.Success);
        }
Esempio n. 10
0
 private static void convertResourceNav(string inputFile, string outputFile, IStructureDefinitionSummaryProvider provider)
 {
     if (inputFile.EndsWith(".xml"))
     {
         var xml = File.ReadAllText(inputFile);
         var nav = XmlParsingHelpers.ParseToTypedElement(xml, provider, new FhirXmlParsingSettings {
             PermissiveParsing = true
         });
         var json = nav.ToJson();
         File.WriteAllText(outputFile, json);
     }
     else
     {
         var json = File.ReadAllText(inputFile);
         var nav  = JsonParsingHelpers.ParseToTypedElement(json, provider,
                                                           settings: new FhirJsonParsingSettings {
             AllowJsonComments = true, PermissiveParsing = true
         });
         var xml = nav.ToXml();
         File.WriteAllText(outputFile, xml);
     }
 }
 public ITypedElement getJsonNode(string json, FhirJsonParsingSettings settings = null)
 => JsonParsingHelpers.ParseToTypedElement(json, new PocoStructureDefinitionSummaryProvider(), settings: settings);