Ejemplo n.º 1
0
        public ElementDefinition GetAncestorElementDefinitionFromCurrent(ElementDefinition current)
        {
            foreach (StructureDefinition sd in _ancestors)
            {
                string searchPath = ReplacePathResourcePrefix(current.path.value, sd.GetRootPath());

                //if ((searchPath == "DomainResource.extension") || (searchPath == "Element.extension"))
                //    return null;

                ElementDefinition ancestorElement = sd
                                                    .differential
                                                    .element
                                                    .FirstOrDefault(t => t.path.value == searchPath);

                if (ancestorElement != null)
                {
                    return(ancestorElement);
                }

                if (!string.IsNullOrWhiteSpace(current.GetBasePath()))
                {
                    searchPath = ReplacePathResourcePrefix(current.GetBasePath(), sd.GetRootPath());

                    ancestorElement = sd
                                      .differential
                                      .element
                                      .Where(t => t.path.value.EndsWith("[x]"))
                                      .FirstOrDefault(t => t.path.value == searchPath);

                    if (ancestorElement != null)
                    {
                        return(ancestorElement);
                    }
                }
                else if (!string.IsNullOrWhiteSpace(current.GetReconstructedBasePath()))
                {
                    searchPath = ReplacePathResourcePrefix(current.GetReconstructedBasePath(), sd.GetRootPath());

                    ancestorElement = sd
                                      .differential
                                      .element
                                      .Where(t => t.path.value.EndsWith("[x]"))
                                      .FirstOrDefault(t => t.path.value == searchPath);

                    if (ancestorElement != null)
                    {
                        return(ancestorElement);
                    }
                }
            }

            return(null);
        }