private static DefinitionNode NavigateOrCreateDefinitionNode(DefinitionNode root, string path) { foreach (string name in SplitPropertyPath(path)) { if (!root.Children.ContainsKey(name)) { root.Children[name] = new DefinitionNode(); } root = root.Children[name]; } return(root); }
private static void ResolveDefinitionNode(DefinitionNode current, List <Property> properties, Dictionary <string, PropertiesGroup> propertiesGroups, LinkedList <string> paths, HashSet <string> columns, int maxDepth) { if (properties == null || properties.Count() == 0 || maxDepth <= 0) { return; } foreach (Property p in properties) { DefinitionNode pNode = NavigateOrCreateDefinitionNode(current, p.Path); var subPaths = SplitPropertyPath(p.Path); foreach (var subPath in subPaths) { paths.AddLast(subPath); } if (string.IsNullOrEmpty(p.PropertiesGroup)) { string camelCasePaths = string.Join("", paths.Where(path => !string.IsNullOrEmpty(path)) .SkipLast(1) .Select(path => path.Substring(0, 1).ToUpper() + path.Substring(1))); string columnName = camelCasePaths + p.Name; pNode.ColumnDefinitions.Add(new ColumnDefinition(columnName, p.Type, p.FhirExpression, null)); columns.Add(columnName); } else { ResolveDefinitionNode(pNode, propertiesGroups[p.PropertiesGroup].Properties, propertiesGroups, paths, columns, maxDepth - 1); } foreach (var subPath in subPaths) { paths.RemoveLast(); } } }
private IEnumerable <(string name, object valueObj, object typeObj)> ToTabularInternal(ElementNode fhirRoot, DefinitionNode definationRoot) { foreach (ColumnDefinition column in definationRoot.ColumnDefinitions) { if (!string.IsNullOrEmpty(column.Type)) { ElementNode valueNode = fhirRoot; if (!string.IsNullOrEmpty(column.FhirExpression)) { var valueFromExpression = fhirRoot.Select(column.FhirExpression).FirstOrDefault(); valueFromExpression = valueFromExpression ?? ElementNode.ForPrimitive(string.Empty); valueNode = ElementNode.FromElement(ElementNode.FromElement(valueFromExpression)); } (object valueObj, object typeObj) = ConvertElementNode(valueNode, column.Type); yield return(column.Name, valueObj, typeObj); } } foreach (var(propertyName, definationNode) in definationRoot.Children) { var fhirChildNode = fhirRoot; if (fhirRoot != null && !string.IsNullOrEmpty(propertyName)) { fhirChildNode = fhirRoot[propertyName]?.FirstOrDefault(); } foreach (var subResult in ToTabularInternal(fhirChildNode, definationNode)) { yield return(subResult); } } }