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

            patient.Address.Add(new Address()
            {
                City = "Shanghai"
            });
            patient.Address.Add(new Address()
            {
                City = "Beijing"
            });

            ElementNode node = ElementNode.FromElement(patient.ToTypedElement());
            TabularMappingDefinition defination = new TabularMappingDefinition("Test");

            defination.Root.Children[""] = new DefinitionNode(new ColumnDefinition("column1", "string", "address.last()", null),
                                                              new ColumnDefinition("column2", "string", "address.first().city", null));
            Dictionary <string, (object, object)> result = t.ToTabular(node, defination);

            Assert.AreEqual("{\"city\":\"Beijing\"}", result["column1"].Item1);
            Assert.AreEqual("Shanghai", result["column2"].Item1);
        }
        public void GivenColumnWithMultiExpressionInSamePath_WhenResolveDefinitionNode_ResolveDefinitionNodesShouldBeReturn()
        {
            Dictionary <string, PropertiesGroup> propertiesGroups = new Dictionary <string, PropertiesGroup>();

            var properties = new List <Property>();

            properties.Add(new Property()
            {
                Name           = "TestName1",
                Path           = "",
                FhirExpression = "testExpression1"
            });
            properties.Add(new Property()
            {
                Name           = "TestName2",
                Path           = "",
                FhirExpression = "testExpression2"
            });
            TabularTable table = new TabularTable();

            table.Properties = properties;

            TabularMappingDefinition defination = BaseMappingDefinitionLoader.BuildMappingDefinition(table, propertiesGroups, 5);

            Assert.AreEqual("TestName1", defination.Root.ColumnDefinitions[0].Name);
            Assert.AreEqual("testExpression1", defination.Root.ColumnDefinitions[0].FhirExpression);
            Assert.AreEqual("TestName2", defination.Root.ColumnDefinitions[1].Name);
            Assert.AreEqual("testExpression2", defination.Root.ColumnDefinitions[1].FhirExpression);
        }
Exemplo n.º 3
0
        public void GivenAFhirResourceAndColumnDefinition_WhenToTabularSource_ValuesAndTypesShouldBeReturn()
        {
            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["address"] = new DefinitionNode(new ColumnDefinition("column1", "string"));
            defination.Root.Children["address"].Children["city"] = new DefinitionNode(new ColumnDefinition("column2", "string"));
            Dictionary <string, (object, object)> result = t.ToTabular(node, defination);

            Assert.AreEqual("{\"city\":\"Shanghai\"}", result["column1"].Item1);
            Assert.AreEqual("string", result["column1"].Item2);
            Assert.AreEqual("Shanghai", result["column2"].Item1);
            Assert.AreEqual("string", result["column2"].Item2);
        }
        public void Given2ColumnWithSamePath_WhenResolveDefinitionNode_2ResolveDefinitionNodesShouldBeReturn()
        {
            var properties = new List <Property>();

            properties.Add(new Property()
            {
                Name = "TestName1",
                Path = "test1.test2",
                Type = "string"
            });

            properties.Add(new Property()
            {
                Name = "TestName2",
                Path = "test1.test2",
                Type = "string"
            });
            TabularTable table = new TabularTable();

            table.Properties = properties;

            TabularMappingDefinition defination = BaseMappingDefinitionLoader.BuildMappingDefinition(table, new Dictionary <string, PropertiesGroup>(), 5);

            Assert.AreEqual(2, defination.Root.Children["test1"].Children["test2"].ColumnDefinitions.Count());
            Assert.AreEqual("Test1TestName1", defination.Root.Children["test1"].Children["test2"].ColumnDefinitions[0].Name);
            Assert.AreEqual("Test1TestName2", defination.Root.Children["test1"].Children["test2"].ColumnDefinitions[1].Name);
        }
        public void GivenColumnWithLongPathGroup_WhenResolveDefinitionNode_ResolveDefinitionNodesShouldBeReturn()
        {
            Dictionary <string, PropertiesGroup> propertiesGroups = new Dictionary <string, PropertiesGroup>();

            propertiesGroups["test"] = new PropertiesGroup()
            {
                PropertiesGroupName = "test",
                Properties          = new List <Property>()
                {
                    new Property()
                    {
                        Name = "p1", Type = "string", Path = "abc"
                    }
                }
            };
            var properties = new List <Property>();

            properties.Add(new Property()
            {
                Name            = "TestName",
                Path            = "test1.test2",
                PropertiesGroup = "test"
            });
            TabularTable table = new TabularTable();

            table.Properties = properties;

            TabularMappingDefinition defination = BaseMappingDefinitionLoader.BuildMappingDefinition(table, propertiesGroups, 5);

            Assert.AreEqual("Test1Test2p1", defination.Root.Children["test1"].Children["test2"].Children["abc"].ColumnDefinitions[0].Name);
        }
        public void GivenColumnWith2LongPath_WhenResolveDefinitionNode_MergedResolveDefinitionNodesShouldBeReturn()
        {
            Dictionary <string, PropertiesGroup> propertiesGroups = new Dictionary <string, PropertiesGroup>();

            var properties = new List <Property>();

            properties.Add(new Property()
            {
                Name = "TestName1",
                Path = "test1.test2"
            });
            properties.Add(new Property()
            {
                Name = "TestName2",
                Path = "test1.test3"
            });
            TabularTable table = new TabularTable();

            table.Properties = properties;

            TabularMappingDefinition defination = BaseMappingDefinitionLoader.BuildMappingDefinition(table, propertiesGroups, 5);

            Assert.AreEqual("Test1TestName1", defination.Root.Children["test1"].Children["test2"].ColumnDefinitions[0].Name);
            Assert.AreEqual("Test1TestName2", defination.Root.Children["test1"].Children["test3"].ColumnDefinitions[0].Name);
        }
Exemplo n.º 7
0
        public void GivenATabularMappingDefinition_WhenGetSchema_AllColumnsShouldBeReturn()
        {
            TabularMappingDefinition defination = new TabularMappingDefinition("Test");

            defination.Root.Children["Test1"] = new DefinitionNode();
            defination.Root.Children["Test1"].Children["Test2"] = new DefinitionNode(new ColumnDefinition("name1", "type1"));
            defination.Root.Children["Test1"].Children["Test3"] = new DefinitionNode(new ColumnDefinition("name2", "type2"));
            defination.Root.Children["Test4"] = new DefinitionNode(new ColumnDefinition("name3", "type3"));

            List <(string, string)> columns = defination.Columns.ToList();

            Assert.IsTrue(columns.Any(c => c.Item1.Contains("name1")));
            Assert.IsTrue(columns.Any(c => c.Item1.Contains("name2")));
            Assert.IsTrue(columns.Any(c => c.Item1.Contains("name3")));
            Assert.IsTrue(columns.Any(c => c.Item1.Contains(ReservedColumnName.ResourceId)));
            Assert.AreEqual(4, columns.Count());
        }
        public void GivenDefinitionMoreThanMaxLevel_WhenResolveDefinitionNode_ResolveDefinitionNodesShouldBeReturn()
        {
            Dictionary <string, PropertiesGroup> propertiesGroups = new Dictionary <string, PropertiesGroup>();

            propertiesGroups["test1"] = new PropertiesGroup()
            {
                PropertiesGroupName = "test1",
                Properties          = new List <Property>()
                {
                    new Property()
                    {
                        Name = "p11", Type = "string", Path = "abc1"
                    },
                    new Property()
                    {
                        PropertiesGroup = "test1", Path = "abc2"
                    }
                }
            };

            var properties = new List <Property>();

            properties.Add(new Property()
            {
                Name            = "TestName",
                Path            = "test1",
                PropertiesGroup = "test1"
            });
            properties.Add(new Property()
            {
                Name = "p1",
                Path = "test",
                Type = "string"
            });
            TabularTable table = new TabularTable();

            table.Properties = properties;

            TabularMappingDefinition defination = BaseMappingDefinitionLoader.BuildMappingDefinition(table, propertiesGroups, 2);

            Assert.AreEqual(3, defination.Columns.Count());
        }
Exemplo n.º 9
0
        public void GivenColumnDefinitionWithFhirExpressionInRoot_WhenToTabularSource_EvaluatedValueShourlBeReturn()
        {
            BasicFhirElementTabularTransformer t = new BasicFhirElementTabularTransformer();
            Patient patient = new Patient()
            {
                Gender = AdministrativeGender.Male
            };

            patient.Id        = "TestId";
            patient.BirthDate = "1974-12-25";

            ElementNode node = ElementNode.FromElement(patient.ToTypedElement());
            TabularMappingDefinition defination = new TabularMappingDefinition("Test");

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

            Assert.AreEqual("TestId", result["column1"].Item1);
            Assert.AreEqual("1974-12-25", result["column2"].Item1);
        }
Exemplo n.º 10
0
        public void GivenUnrollPathConfiguration_WhenToTabularSource_MultipleItemsShouldBeReturn()
        {
            BasicFhirElementTabularTransformer t = new BasicFhirElementTabularTransformer();
            Patient patient = new Patient()
            {
                Gender = AdministrativeGender.Male
            };

            patient.Address.Add(new Address()
            {
                City = "Shanghai"
            });
            patient.Address.Add(new Address()
            {
                City = "Beijing"
            });
            patient.BirthDate = "1974-12-25";
            patient.Id        = "Test1";
            patient.Telecom.Add(new ContactPoint()
            {
                Rank = 1
            });

            TabularMappingDefinition defination = new TabularMappingDefinition("Test");

            defination.Unrollpath            = "Patient.address";
            defination.Root.Children["city"] = new DefinitionNode(new ColumnDefinition("column1", "string"));
            IEnumerable <Dictionary <string, (object, object)> > results = t.ToTabular(patient, defination);

            Assert.AreEqual(2, results.Count());

            foreach (var result in results)
            {
                Assert.AreEqual("Test1", result[ReservedColumnName.ResourceId].Item1);
                Assert.IsTrue(result.ContainsKey(ReservedColumnName.FhirPath));
                Assert.IsTrue(result.ContainsKey("column1"));
                Assert.IsTrue(!string.IsNullOrEmpty(result["column1"].Item1?.ToString()));
            }
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }