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);
        }
Exemple #2
0
 protected String HRef(ResourceMap.Node mapNode)
 {
     if (mapNode.ResourceUrl.StartsWith("http://hl7.org/fhir/StructureDefinition/"))
     {
         return(mapNode.ResourceUrl);
     }
     return($"./{mapNode.StructureName}-{mapNode.Name}.html");
 }
Exemple #3
0
 protected SENode CreateResourceNode(ResourceMap.Node mapNode,
                                     dynamic link,
                                     bool linkFlag = true)
 {
     return(CreateResourceNode(mapNode,
                               this.LinkTypeColor(link),
                               new String[] { link.CardinalityLeft?.ToString() },
                               linkFlag));
 }
        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);
        }
Exemple #5
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;
            }
        }
Exemple #6
0
        ResourceMap.Node CreateMapNode(DomainResource r)
        {
            String structureName = r.TypeName;
            String resourceUrl;
            String baseName = null;
            String title;

            switch (r)
            {
            case ValueSet vs:
                resourceUrl = vs.Url;
                title       = vs.Title;
                break;

            case StructureDefinition sd:
                resourceUrl = sd.Url;
                baseName    = sd.BaseDefinition.LastUriPart();
                title       = sd.Title;
                break;

            default:
                return(null);
            }

            string mapName = r.GetStringExtension(Global.ResourceMapNameUrl);

            if (String.IsNullOrEmpty(mapName) == true)
            {
                throw new Exception($"Mapname missing from {resourceUrl}");
            }
            String[] mapNameArray = mapName.Split('/');

            Extension isFragmentExtension = r.GetExtension(Global.IsFragmentExtensionUrl);

            ResourceMap.Node retVal = this.CreateMapNode(resourceUrl,
                                                         title,
                                                         mapNameArray,
                                                         structureName,
                                                         isFragmentExtension != null);

            foreach (Extension link in r.GetExtensions(Global.ResourceMapLinkUrl))
            {
                FhirString s = (FhirString)link.Value;

                dynamic mapLink = JObject.Parse(s.Value);
                mapLink.LinkSource = resourceUrl;
                this.links.Add(mapLink);
                retVal.AddLink(mapLink);
            }

            return(retVal);
        }
Exemple #7
0
        protected Color ReferenceColor(ResourceMap.Node refNode)
        {
            switch (refNode.StructureName)
            {
            case "StructureDefinition": return(this.targetColor);

            case "ValueSet": return(this.valueSetColor);

            case "Extension": return(this.extensionReferenceColor);

            default: throw new NotImplementedException();
            }
        }
        IEnumerable <dynamic> FragmentLinks(ResourceMap.Node n)
        {
            foreach (dynamic link in n.Links)
            {
                switch (link.LinkType.ToObject <String>())
                {
                case "fragment":
                    yield return(link);

                    break;
                }
            }
        }
 public void PatchStructDef(ResourceMap.Node node)
 {
     if (this.map.TryGetResource(node.ResourceUrl, out DomainResource resource) == false)
     {
         throw new Exception($"Resource {node.ResourceUrl} not found in map");
     }
     switch (resource)
     {
     case StructureDefinition sd:
         this.PatchStructDef(sd);
         break;
     }
 }
Exemple #10
0
        public void AddResource(String path,
                                VerifyDel verifyDel)
        {
            DomainResource domainResource;

            switch (Path.GetExtension(path).ToUpper(CultureInfo.InvariantCulture))
            {
            case ".XML":
            {
                FhirXmlParser parser = new FhirXmlParser();
                domainResource = parser.Parse <DomainResource>(File.ReadAllText(path));
                break;
            }

            case ".JSON":
            {
                FhirJsonParser parser = new FhirJsonParser();
                domainResource = parser.Parse <DomainResource>(File.ReadAllText(path));
                break;
            }

            default:
                throw new Exception($"Unknown extension for serialized fhir resource '{path}'");
            }

            if (verifyDel != null)
            {
                if (verifyDel(domainResource) == false)
                {
                    return;
                }
            }

            ResourceMap.Node node = this.CreateMapNode(domainResource);
            if (node == null)
            {
                return;
            }
            this.nodes.Add(node.ResourceUrl, node);
            this.resources.Add(domainResource.GetUrl(), domainResource);
        }
Exemple #11
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);
        }
Exemple #12
0
        protected void AddChildren(ResourceMap.Node mapNode,
                                   dynamic[] links,
                                   SENodeGroup group)
        {
            if (links.Length == 0)
            {
                return;
            }
            foreach (dynamic link in links)
            {
                switch (link.LinkType.ToObject <String>())
                {
                case SVGGlobal.ComponentType:
                    MakeComponent(link, group);
                    break;

                default:
                    DirectLink(group, mapNode, link);
                    break;
                }
            }
        }
        void LinkNodes()
        {
            foreach (ResourceMap.Node focusMapNode in this.selectedNodes)
            {
                if (this.fragmentNodes.TryGetValue(focusMapNode.Name, out FragmentNode fragmentFocusNode) == false)
                {
                    throw new Exception($"Internal error. Cant find Focus FragmentNode '{focusMapNode.Name}' ");
                }

                foreach (dynamic link in this.FragmentLinks(focusMapNode))
                {
                    ResourceMap.Node referencedMapNode = this.map.GetNode(link.LinkTarget.ToObject <String>());
                    fragmentFocusNode.Parents.Add(referencedMapNode);

                    if (this.fragmentNodes.TryGetValue(referencedMapNode.Name, out FragmentNode fragmentParentNode) ==
                        false)
                    {
                        throw new Exception($"Internal error. Cant find FragmentNode '{referencedMapNode.Name}' ");
                    }
                    fragmentParentNode.Children.Add(focusMapNode);
                }
            }
        }
Exemple #14
0
        public bool TryGetNode(String url, out ResourceMap.Node node)
        {
            if (this.nodes.TryGetValue(url, out node) == true)
            {
                return(true);
            }
            if (url.StartsWith("http://hl7.org/fhir/StructureDefinition"))
            {
                StructureDefinition fhirResource = ZipFhirSource.Source.ResolveByUri(url) as StructureDefinition;
                if (fhirResource != null)
                {
                    String name = fhirResource.Url.LastUriPart();
                    node = this.CreateMapNode(fhirResource.Url,
                                              name,
                                              new String[] { name },
                                              "StructureDefinition",
                                              false);

                    return(true);
                }
            }

            return(false);
        }
 public static String FragmentMapName(ResourceMap.Node mapNode) => $"Frag-{mapNode.Name}.svg";
        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);
        }
 String IntroName(ResourceMap.Node mapNode) => $"{mapNode.StructureName}-{mapNode.Name}-intro.xml";
 public static String FocusMapName(ResourceMap.Node mapNode) => $"Focus-{mapNode.Name}.svg";
Exemple #19
0
 /*
  * Add children. If two adjacent children have same children, then dont create each in a seperate
  * group. Have the two nodes point to the same group of children.
  */
 protected void AddChildren(ResourceMap.Node mapNode,
                            SENodeGroup group)
 {
     dynamic[] links = mapNode.LinksByLinkType(this.linkTypes).ToArray();
     this.AddChildren(mapNode, links, group);
 }