示例#1
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);
        }