Esempio n. 1
0
        private static void BuildIncludes(XmlNode node, Dictionary <string, Tag2> tags, Tag2 parent)
        {
            string depth = Depth(parent);
            //Console.WriteLine("{0}include {1}", depth, node.Attributes["name"].Value);

            string path = String.Format(@"dicom/*[@name='{0}']", node.Attributes["name"].Value);
            // navigate to another place in the document and iterate the elements and includes found there
            XmlNode include = node.OwnerDocument.SelectSingleNode(path);

            BuildElements(include.ChildNodes, tags, parent);

            //Console.WriteLine("{0}end", depth);
        }
Esempio n. 2
0
        private static void BuildElements(XmlNodeList nodes, Dictionary <string, Tag2> tags, Tag2 parent)
        {
            string depth = Depth(parent);

            // iterate the node of elements, expanding sequences and includes
            foreach (XmlNode node in nodes)
            {
                string key;
                bool   contains;
                switch (node.Name)
                {
                case "element":
                    key      = node.Attributes["tag"].Value.ToLower();
                    contains = tags.ContainsKey(key);
                    //Console.WriteLine("{0}{1}{2},{3} - {4} - {5}", depth, contains ? "*" : "", key, node.Attributes["vt"].Value, Dictionary.Instance[key].Description, (node.Attributes["dependency"] != null) ? node.Attributes["dependency"].Value : "");
                    // different modules may contain the same tag
                    if (!contains)
                    {
                        // if we have not seen this tag before, add it
                        Tag2 temp = new Tag2(Dictionary.Instance[key]);
                        temp.Parent = parent;
                        temp.VT     = node.Attributes["vt"].Value;
                        if (node.Attributes["dependency"] != null)
                        {
                            temp.Dependency = node.Attributes["dependency"].Value;
                        }
                        tags.Add(key, temp);
                    }
                    else
                    {
                        // otherwise we want to keep track of the lowest vt and associated dependency
                        Tag2   temp = tags[key];
                        string vt   = Min(temp.VT, node.Attributes["vt"].Value);
                        if (temp.VT != vt)
                        {
                            temp.VT = vt;
                            if (node.Attributes["dependency"] != null)
                            {
                                temp.Dependency = node.Attributes["dependency"].Value;
                            }
                        }
                        else if (temp.Dependency != String.Empty && node.Attributes["dependency"] != null && temp.Dependency != node.Attributes["dependency"].Value)
                        {
                            Logging.Log(LogLevel.Warning, "Multiple dependencies for {0}", key);
                        }
                    }
                    break;

                case "sequence":
                    key      = node.Attributes["tag"].Value.ToLower();
                    contains = tags.ContainsKey(key);
                    //Console.WriteLine("{0}{1}{2},{3} - {4} - {5}", depth, contains ? "*" : "", key, node.Attributes["vt"].Value, Dictionary.Instance[key].Description, (node.Attributes["dependency"] != null) ? node.Attributes["dependency"].Value : "");
                    if (!contains)
                    {
                        Tag2 temp = new Tag2(Dictionary.Instance[key]);
                        temp.Parent = parent;
                        temp.VT     = node.Attributes["vt"].Value;
                        if (node.Attributes["dependency"] != null)
                        {
                            temp.Dependency = node.Attributes["dependency"].Value;
                        }
                        tags.Add(key, temp);
                        BuildElements(node.ChildNodes, tags, temp);
                    }
                    //Console.WriteLine("{0}{1}end", depth, contains ? "*" : "");
                    break;

                case "include":
                    BuildIncludes(node, tags, parent);
                    break;
                }
            }
        }
Esempio n. 3
0
        public static bool Verify(Elements elements, string iod, Elements missing)
        {
            Dictionary <string, Tag2> tags = GetTags(iod);

            //Console.WriteLine("\n");

            bool   results = true;
            string ignore  = null;

            foreach (string key in tags.Keys)
            {
                Tag2 tag = tags[key];

                if (ignore != null)
                {
                    if (tag.ToString().StartsWith(ignore))
                    {
                        continue;
                    }
                    else
                    {
                        ignore = null;
                    }
                }

                bool exists = elements.Contains(key);
                switch (tag.VT)
                {
                case "1":
                case "1C":
                    if (tag.VT == "1C" && !Depends(elements, tag.Dependency))
                    {
                        if (tag.VR == "SQ")
                        {
                            ignore = key;
                        }
                        break;
                    }
                    // must exist and not be null
                    if (!exists || elements[key].Value == null)
                    {
                        if (missing != null)
                        {
                            missing.Add(key, null);
                        }
                        Logging.Log(LogLevel.Verbose, "Missing type {0} tag {1} {2}", tag.VT, key, tag.Description);
                        results = false;
                    }
                    break;

                case "2":
                case "2C":
                    if (tag.VT == "2C" && !Depends(elements, tag.Dependency))
                    {
                        break;
                    }
                    // must exist, but can be null
                    if (!exists)
                    {
                        if (assist)
                        {
                            // if it does not exist, we add it with a null value
                            elements.Add(key, null);
                        }
                        else
                        {
                            if (missing != null)
                            {
                                missing.Add(key, null);
                            }
                            Logging.Log(LogLevel.Verbose, "Missing type {0} tag {1} {2}", tag.VT, key, tag.Description);
                        }
                    }
                    break;

                // totally optional
                case "3":
                    // if an optional sequence does not exist, ignore its contents
                    if (!exists && tag.VR == "SQ")
                    {
                        ignore = key;
                    }
                    break;
                }
            }
            return(results);
        }