SENode CreateNode(ResourceMap.Node mapNode, Color color, bool linkFlag)
        {
            if (this.map.TryGetNode(mapNode.ResourceUrl, out var dummy) == false)
            {
                throw new Exception($"Referenced node {mapNode.ResourceUrl} not found in map");
            }

            String hRef = null;

            if (linkFlag)
            {
                String fragMapName = $"{mapNode.StructureName}-{mapNode.Name}.html";
                hRef = $"./{fragMapName}";
            }

            SENode node = new SENode(0, color, null, hRef);

            foreach (String titlePart in mapNode.MapName)
            {
                String s = titlePart.Trim();
                node.AddTextLine(s, hRef);
            }

            return(node);
        }
        SENodeGroup CreateNodes(String reportUrl)
        {
            ResourceMap.Node mapNode   = this.map.GetNode(reportUrl);
            SENodeGroup      rootGroup = new SENodeGroup("root", false);
            SENode           rootNode  = this.CreateResourceNode(mapNode, this.focusColor, null);

            rootGroup.AppendNode(rootNode);
            this.AddChildren(mapNode, rootGroup);
            return(rootGroup);
        }
예제 #3
0
        protected void DirectLink(SENodeGroup group,
                                  ResourceMap.Node mapNode,
                                  dynamic link)
        {
            String linkTargetUrl = link.LinkTarget.ToObject <String>();

            void CreateDirectNode(SENodeGroup g)
            {
                if (this.map.TryGetNode(linkTargetUrl, out ResourceMap.Node linkTargetNode) == true)
                {
                    SENode node = this.CreateResourceNode(linkTargetNode, link);
                    g.AppendNode(node);
                }
            }

            dynamic[] childMapLinks = new Object[0];

            ResourceMap.Node childMapNode = null;

            bool linkToLastGroup = false;

            if (ShowChildren(link))
            {
                if (this.map.TryGetNode(linkTargetUrl, out childMapNode) == true)
                {
                    childMapNode  = this.map.GetNode(linkTargetUrl);
                    childMapLinks = childMapNode.LinksByLinkType(this.linkTypes).ToArray();
                    if (childMapLinks.Length > 0)
                    {
                        linkToLastGroup = !this.DifferentChildren(this.previousChildLinks, childMapLinks);
                    }
                }
            }

            if ((linkToLastGroup) & (group.Children.Count() > 0))
            {
                SENodeGroup groupChild = group.Children.Last();
                CreateDirectNode(groupChild);
            }
            else
            {
                SENodeGroup groupChild = group.AppendChild("", this.showCardinality);
                CreateDirectNode(groupChild);
                if (ShowChildren(link))
                {
                    this.AddChildren(childMapNode,
                                     childMapLinks,
                                     groupChild);
                }
                this.previousChildLinks = childMapLinks;
            }
        }
        void GraphNode(FragmentNode fragmentNode)
        {
            SvgEditor   e             = new SvgEditor();
            SENodeGroup parentsGroup  = new SENodeGroup("parents", false);
            SENodeGroup focusGroup    = new SENodeGroup("focus", false);
            SENodeGroup childrenGroup = new SENodeGroup("children", false);

            parentsGroup.AppendChild(focusGroup);
            focusGroup.AppendChild(childrenGroup);

            {
                SENode node = this.CreateNode(fragmentNode.Focus, Color.Green, false);
                focusGroup.AppendNode(node);
            }

            foreach (ResourceMap.Node childNode in fragmentNode.Children)
            {
                SENode node = this.CreateNode(childNode, Color.LightBlue, true);
                childrenGroup.AppendNode(node);
            }

            foreach (ResourceMap.Node parentNode in fragmentNode.Parents)
            {
                SENode node = this.CreateNode(parentNode, Color.LightCyan, true);
                parentsGroup.AppendNode(node);
            }

            e.Render(parentsGroup, true);
            String svgName       = FragmentMapName(fragmentNode.Focus);
            String outputSvgPath = Path.Combine(this.graphicsDir, svgName);

            this.fc?.Mark(outputSvgPath);
            e.Save(outputSvgPath);

            this.fragmentsBlock
            .AppendLine($"<p>")
            .AppendLine($"Fragment Diagram {fragmentNode.Focus.Name}")
            .AppendLine($"</p>")
            .AppendLine($"<object data=\"{svgName}\" type=\"image/svg+xml\">")
            .AppendLine($"    <img src=\"{svgName}\" alt=\"{fragmentNode.Focus.Name}\"/>")
            .AppendLine($"</object>");
            ;
        }
예제 #5
0
        protected SENode CreateResourceNode(ResourceMap.Node mapNode,
                                            Color color,
                                            String[] annotations,
                                            bool linkFlag = true)
        {
            Debug.Assert(mapNode.MapName[0] != "TumorSatellite");
            String hRef = null;

            if (linkFlag)
            {
                hRef = this.HRef(mapNode);
            }
            SENode node = new SENode(0, color, annotations, hRef);

            foreach (String titlePart in mapNode.MapName)
            {
                String s = titlePart.Trim();
                node.AddTextLine(s, hRef);
            }

            return(node);
        }
예제 #6
0
 public void AppendNode(SENode node)
 {
     this.nodes.Add(node);
 }
예제 #7
0
        void Render(SvgGroup parentGroup,
                    SENode node,
                    float screenX,
                    float screenY,
                    out float width,
                    out float height)
        {
            const float CharMod = 0.7f;

            //Debug.Assert((this.RenderTestPoint == null) || node.AllText().Contains(RenderTestPoint) == false);
            height = node.TextLines.Count * this.LineHeight + 2 * this.BorderMargin;
            width  = node.Width * CharMod + 2 * this.BorderMargin;

            SvgGroup g = this.doc.AddGroup(parentGroup);

            g.Transform = $"translate({this.ToPx(screenX)} {this.ToPx(screenY)})";
            SvgRect square;

            if (node.HRef != null)
            {
                SvgHyperLink l = this.doc.AddHyperLink(g);
                l.Target = "_top";
                l.HRef   = node.HRef.ToString();
                square   = this.doc.AddRect(l);
            }
            else
            {
                square = this.doc.AddRect(g);
            }

            square.Stroke      = Color.Black;
            square.StrokeWidth = this.ToPx(this.BorderWidth);
            square.RX          = this.ToPx(this.RectRx);
            square.RY          = this.ToPx(this.RectRy);
            square.X           = "0";
            square.Y           = "0";
            square.Width       = this.ToPx(width);
            square.Height      = this.ToPx(height);
            square.Fill        = node.FillColor;

            float textX = this.BorderMargin;
            float textY = this.BorderMargin + 1;

            foreach (SEText line in node.TextLines)
            {
                SvgText t;
                if (line.HRef != null)
                {
                    SvgHyperLink l = this.doc.AddHyperLink(g);
                    l.HRef   = line.HRef;
                    l.Target = "_top";
                    if (line.Title != null)
                    {
                        SvgTitle title = this.doc.AddTitle(l);
                        title.Value = line.Title;
                    }

                    t = this.doc.AddText(l);
                }
                else
                {
                    t = this.doc.AddText(g);
                }

                t.X          = this.ToPx(width / 2);
                t.Y          = this.ToPx(textY);
                t.TextAnchor = "middle";
                t.Value      = line.Text;

                textY += this.LineHeight;
            }
        }
        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);
        }
예제 #9
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);
                }
            }
        }