Ejemplo n.º 1
0
        public void GivenConfigurationWithInvalidPath_WhenToTabularSource_NullValueShouldBeReturn()
        {
            BasicFhirElementTabularTransformer t = new BasicFhirElementTabularTransformer();
            Patient patient = new Patient()
            {
                Gender = AdministrativeGender.Male
            };

            patient.Address.Add(new Address()
            {
                City = "Shanghai"
            });
            ElementNode node = ElementNode.FromElement(patient.ToTypedElement());

            TabularMappingDefinition defination = new TabularMappingDefinition("Test");

            defination.Root.Children["invalid"] = new DefinitionNode();
            defination.Root.Children["invalid"].Children["invalid"] = new DefinitionNode(new ColumnDefinition("column1", "string"));
            Dictionary <string, (object, object)> result = t.ToTabular(node, defination);

            Assert.IsNull(result["column1"].Item1);
            Assert.AreEqual("string", result["column1"].Item2);
        }
Ejemplo n.º 2
0
        public void GivenColumnDefinitionWithDifferentTypes_WhenToTabularSource_ValueCanBeConvertedShouldBeReturn()
        {
            BasicFhirElementTabularTransformer t = new BasicFhirElementTabularTransformer();
            Patient patient = new Patient()
            {
                Gender = AdministrativeGender.Male
            };

            patient.Address.Add(new Address()
            {
                City = "Shanghai"
            });
            patient.BirthDate = "1974-12-25";
            patient.Telecom.Add(new ContactPoint()
            {
                Rank = 1
            });
            ElementNode node = ElementNode.FromElement(patient.ToTypedElement());

            TabularMappingDefinition defination = new TabularMappingDefinition("Test");

            defination.Root.Children["address"] = new DefinitionNode();
            defination.Root.Children["address"].Children["city"] = new DefinitionNode(new ColumnDefinition("column1", "string"));
            defination.Root.Children["birthDate"] = new DefinitionNode(new ColumnDefinition("column2", "date"));
            defination.Root.Children["telecom"]   = new DefinitionNode();
            defination.Root.Children["telecom"].Children["rank"] = new DefinitionNode(new ColumnDefinition("column3", "integer"));
            Dictionary <string, (object, object)> result = t.ToTabular(node, defination);

            Assert.AreEqual("Shanghai", result["column1"].Item1);
            Assert.AreEqual("string", result["column1"].Item2);

            Assert.AreEqual(DateTime.Parse("1974-12-25"), result["column2"].Item1);
            Assert.AreEqual("date", result["column2"].Item2);

            Assert.AreEqual(1, result["column3"].Item1);
            Assert.AreEqual("integer", result["column3"].Item2);
        }