コード例 #1
0
        void GraphNode(ResourceMap.Node focusNode)
        {
            if (focusNode.Name.Contains("Fragment", new StringComparison()) == true)
            {
                return;
            }
            //Debug.Assert(focusNode.Name != "SectionFindingsLeftBreast");

            SvgEditor   e             = new SvgEditor();
            SENodeGroup parentsGroup  = new SENodeGroup("parents", true);
            SENodeGroup focusGroup    = new SENodeGroup("focus", true);
            SENodeGroup childrenGroup = new SENodeGroup("children", true);

            parentsGroup.AppendChild(focusGroup);
            focusGroup.AppendChild(childrenGroup);
            {
                SENode node = this.CreateResourceNode(focusNode, Color.White, null, false);
                focusGroup.AppendNode(node);
            }
            {
                HashSet <String> alreadyLinkedResources = new HashSet <string>();

                void AddParent(dynamic link,
                               List <SENode> parents)
                {
                    String linkSource = link.LinkSource.ToObject <String>();

                    if (this.map.TryGetNode(linkSource, out ResourceMap.Node parentNode) == false)
                    {
                        throw new Exception($"Parent extension {linkSource} not found in map");
                    }
                    if (alreadyLinkedResources.Contains(parentNode.ResourceUrl) == true)
                    {
                        return;
                    }

                    if (this.map.TryGetNode(parentNode.ResourceUrl, out ResourceMap.Node parentMapNode) == false)
                    {
                        throw new Exception($"Resource '{parentNode.ResourceUrl}' not found!");
                    }

                    alreadyLinkedResources.Add(parentNode.ResourceUrl);
                    SENode node = this.CreateResourceNode(parentNode, this.ReferenceColor(parentMapNode),
                                                          new String[] { null, link.CardinalityLeft?.ToString() },
                                                          true);

                    parents.Add(node);
                }

                List <SENode> componentParents = new List <SENode>();
                List <SENode> extensionParents = new List <SENode>();
                List <SENode> valueSetParents  = new List <SENode>();
                List <SENode> targetParents    = new List <SENode>();

                foreach (dynamic link in this.map.TargetOrReferenceLinks(focusNode.ResourceUrl))
                {
                    switch (link.LinkType.ToObject <String>())
                    {
                    case "fragment":
                        break;

                    default:
                        AddParent(link, componentParents);
                        break;
                    }
                }

                parentsGroup.AppendNodes(targetParents);
                parentsGroup.AppendNodes(componentParents);
                parentsGroup.AppendNodes(valueSetParents);
                parentsGroup.AppendNodes(extensionParents);
            }
            {
                SENodeGroup targetChildren    = new SENodeGroup("A.Targets", true);
                SENodeGroup componentChildren = new SENodeGroup("B.Components", true);
                SENodeGroup extensionChildren = new SENodeGroup("C.Extensions", true);
                SENodeGroup valueSetChildren  = new SENodeGroup("D.ValueSets", true);

                childrenGroup.AppendChild(targetChildren);
                childrenGroup.AppendChild(componentChildren);
                childrenGroup.AppendChild(valueSetChildren);
                childrenGroup.AppendChild(extensionChildren);

                foreach (dynamic link in this.map.SourceLinks(focusNode.ResourceUrl))
                {
                    switch (link.LinkType.ToObject <String>())
                    {
                    case "fragment":
                        break;

                    case SVGGlobal.ComponentType:
                        MakeComponent(link, componentChildren);
                        break;

                    case SVGGlobal.ExtensionType:
                    {
                        String linkSource    = link.LinkSource.ToObject <String>();
                        String componentHRef = link.ComponentHRef.ToObject <String>()
                                               .Replace("{SDName}", linkSource.LastUriPart());

                        SENode node = new SENode(0,
                                                 LinkTypeColor(link),
                                                 new String[] { link.CardinalityLeft?.ToString() },
                                                 componentHRef);
                        node.AddTextLine(link.LocalName.ToObject <String>(), componentHRef);
                        node.AddTextLine("extension", componentHRef);

                        SENodeGroup nodeGroup = new SENodeGroup(node.AllText(), true);
                        extensionChildren.AppendChild(nodeGroup);
                        nodeGroup.AppendNode(node);

                        {
                            SENodeGroup extGroup = new SENodeGroup("extension", true);
                            nodeGroup.AppendChild(extGroup);
                            SENode extNode;
                            String extUrl = link.LinkTarget.ToObject <String>().Trim();
                            if (extUrl.ToLower().StartsWith(Global.BreastRadBaseUrl))
                            {
                                if (this.map.TryGetNode(extUrl, out ResourceMap.Node targetNode) == false)
                                {
                                    throw new Exception($"Component resource '{extUrl}' not found!");
                                }
                                extNode = this.CreateResourceNode(targetNode, this.ReferenceColor(targetNode),
                                                                  new String[] { link.CardinalityLeft?.ToString() },
                                                                  true);
                            }
                            else
                            {
                                String name = extUrl.LastUriPart()
                                              .TrimStart("StructureDefinition-")
                                              .TrimStart("ValueSet-")
                                              .TrimEnd(".html")
                                ;
                                extNode = new SENode(0,
                                                     this.fhirColor,
                                                     new String[] { link.CardinalityLeft?.ToString() },
                                                     extUrl);
                                extNode.AddTextLine(name, extUrl);
                            }

                            extGroup.AppendNode(extNode);
                        }
                    }
                    break;

                    case SVGGlobal.ValueSetType:
                    {
                        if (this.map.TryGetNode(link.LinkTarget.ToObject <String>().ToObject <String>(),
                                                out ResourceMap.Node childNode) == true)
                        {
                            SENode      node      = this.CreateResourceNode(childNode, link, true);
                            SENodeGroup nodeGroup = new SENodeGroup(node.AllText(), false);
                            valueSetChildren.AppendChild(nodeGroup);
                            nodeGroup.AppendNode(node);
                        }
                    }
                    break;

                    case SVGGlobal.TargetType:
                    {
                        if (this.map.TryGetNode(link.LinkTarget.ToObject <String>(),
                                                out ResourceMap.Node childNode) == false)
                        {
                            throw new Exception(
                                      $"Child target {link.LinkTarget.ToObject<String>()} not found in map");
                        }
                        SENode      node      = this.CreateResourceNode(childNode, link, true);
                        SENodeGroup nodeGroup = new SENodeGroup(node.AllText(), true);
                        targetChildren.AppendChild(nodeGroup);
                        nodeGroup.AppendNode(node);
                    }
                    break;

                    default:
                        throw new NotImplementedException($"Unknown link type {link.LinkType.ToObject<String>()}");
                    }
                }
            }

            //parentsGroup.Sort();
            e.Render(parentsGroup, true);
            String outputPath = Path.Combine(this.graphicsDir, FocusMapName(focusNode));

            this.fc?.Mark(outputPath);
            e.Save(outputPath);
        }
コード例 #2
0
        protected void MakeComponent(dynamic link,
                                     SENodeGroup group)
        {
            // we never link components to previous child links, not should next item
            // link to this items children. Each component stands alone.
            this.previousChildLinks = new Object[0];
            String linkTargetUrl = link.LinkTarget.ToObject <String>();
            String linkSource    = link.LinkSource.ToObject <String>();
            String componentHRef = link.ComponentHRef.ToObject <String>().Replace("{SDName}", linkSource.LastUriPart());

            SENode node = new SENode(0,
                                     this.componentColor,
                                     new String[] { link.CardinalityLeft?.ToString(), link.CardinalityRight?.ToString() },
                                     componentHRef);

            node.AddTextLine(linkTargetUrl, componentHRef);

            String types = link.Types?.ToObject <String>();

            if (String.IsNullOrEmpty(types) == false)
            {
                node.AddTextLine(types, componentHRef);
            }
            SENodeGroup componentGroup = new SENodeGroup(node.AllText(), this.showCardinality);

            group.AppendChild(componentGroup);
            componentGroup.AppendNode(node);

            JArray references = (JArray)link.References;

            if (references != null)
            {
                SENodeGroup refGroup = new SENodeGroup("ref", true);
                componentGroup.AppendChild(refGroup);

                foreach (JValue item in references)
                {
                    String reference = item.ToObject <String>();
                    SENode refNode;
                    if (reference.ToLower().StartsWith(Global.BreastRadBaseUrl))
                    {
                        if (this.map.TryGetNode(reference, out ResourceMap.Node refMapNode) == false)
                        {
                            throw new Exception($"Component resource '{reference}' not found!");
                        }
                        refNode = this.CreateResourceNode(refMapNode,
                                                          this.ReferenceColor(refMapNode),
                                                          new String[0],
                                                          true);

                        if (ShowChildren(link))
                        {
                            var childMapNode = this.map.GetNode(reference);
                            this.AddChildren(childMapNode, refGroup);
                        }
                    }
                    else
                    {
                        refNode = new SENode(0,
                                             this.fhirColor,
                                             new String[0],
                                             reference);
                        refNode.AddTextLine(reference.LastUriPart(), reference);
                    }

                    refGroup.AppendNode(refNode);
                }
            }
        }