public DicomDictionaryEntry(
            DicomTag tag,
            string name,
            string keyword,
            DicomVM vm,
            bool retired,
            params DicomVR[] vrs)
        {
            Tag = tag;

            if (string.IsNullOrEmpty(name?.Trim()))
            {
                Name = Tag.ToString();
            }
            else
            {
                Name = name;
            }

            if (string.IsNullOrEmpty(keyword?.Trim()))
            {
                Keyword = Name;
            }
            else
            {
                Keyword = keyword;
            }

            ValueMultiplicity    = vm;
            ValueRepresentations = vrs;
            IsRetired            = retired;
        }
Example #2
0
        public DicomDictionaryEntry(DicomTag tag, string name, string keyword, DicomVM vm, bool retired, params DicomVR[] vrs)
        {
            Tag = tag;

            if (String.IsNullOrWhiteSpace(name))
            {
                Name = Tag.ToString();
            }
            else
            {
                Name = name;
            }

            if (String.IsNullOrWhiteSpace(keyword))
            {
                Keyword = Name.Replace(" ", "");
            }
            else
            {
                Keyword = keyword;
            }

            ValueMultiplicity    = vm;
            ValueRepresentations = vrs;
            IsRetired            = retired;
        }
Example #3
0
        public void Parse_OneToNOrOne_InterpretedAsOneToN()
        {
            var actual = DicomVM.Parse("1-n or 1");

            Assert.Equal(1, actual.Minimum);
            Assert.Equal(int.MaxValue, actual.Maximum);
            Assert.Equal(1, actual.Multiplicity);
        }
Example #4
0
        public static DicomVM Parse(string s)
        {
            try
            {
                DicomVM vm = null;
                if (_vm.TryGetValue(s, out vm))
                {
                    return(vm);
                }

                string[] parts = s.Split(new[] { "-", " ", "or" }, StringSplitOptions.RemoveEmptyEntries);

                if (parts.Length == 1)
                {
                    vm              = new DicomVM();
                    vm.Minimum      = int.Parse(parts[0]);
                    vm.Maximum      = vm.Minimum;
                    vm.Multiplicity = vm.Minimum;
                }
                else
                {
                    vm              = new DicomVM();
                    vm.Minimum      = int.Parse(parts[0]);
                    vm.Multiplicity = 1;

                    if (parts[1].IndexOf("n", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        vm.Maximum = int.MaxValue;
                        parts[1]   = parts[1].TrimEnd('n', 'N');

                        if (parts[1].Length > 0)
                        {
                            vm.Multiplicity = int.Parse(parts[1]);
                        }
                    }
                    else
                    {
                        vm.Maximum = int.Parse(parts[1]);
                    }
                }

                _vm.Add(s, vm);

                return(vm);
            }
            catch (Exception e)
            {
                throw new DicomDataException("Error parsing value multiplicty ['" + s + "']", e);
            }
        }
		public DicomDictionaryEntry(DicomTag tag, string name, string keyword, DicomVM vm, bool retired, params DicomVR[] vrs) {
			Tag = tag;

			if (String.IsNullOrWhiteSpace(name))
				Name = Tag.ToString();
			else
				Name = name;

			if (String.IsNullOrWhiteSpace(keyword))
				Keyword = Name;
			else
				Keyword = keyword;

			ValueMultiplicity = vm;
			ValueRepresentations = vrs;
			IsRetired = retired;
		}
Example #6
0
        public DicomDictionaryEntry(
            DicomMaskedTag tag,
            string name,
            string keyword,
            DicomVM vm,
            bool retired,
            params DicomVR[] vrs)
        {
            Tag = tag.Tag;
            MaskTag = tag;

            if (string.IsNullOrEmpty(name?.Trim())) Name = Tag.ToString();
            else Name = name;

            if (string.IsNullOrEmpty(keyword?.Trim())) Keyword = Name;
            else Keyword = keyword;

            ValueMultiplicity = vm;
            ValueRepresentations = vrs;
            IsRetired = retired;
        }
Example #7
0
        public static DicomVM Parse(string s)
        {
            try {
                DicomVM vm = null;
                if (_vm.TryGetValue(s, out vm))
                    return vm;

                string[] parts = s.Split('-');

                if (parts.Length == 1) {
                    vm = new DicomVM();
                    vm.Minimum = int.Parse(parts[0]);
                    vm.Maximum = vm.Minimum;
                    vm.Multiplicity = vm.Minimum;
                } else {
                    vm = new DicomVM();
                    vm.Minimum = int.Parse(parts[0]);
                    vm.Multiplicity = 1;

                    if (parts[1].EndsWith("n", StringComparison.InvariantCultureIgnoreCase)) {
                        vm.Maximum = int.MaxValue;
                        parts[1] = parts[1].TrimEnd('n', 'N');

                        if (parts[1].Length > 0)
                            vm.Multiplicity = int.Parse(parts[1]);
                    } else {
                        vm.Maximum = int.Parse(parts[1]);
                    }
                }

                _vm.Add(s, vm);

                return vm;
            } catch (Exception e) {
                throw new DicomDataException("Error parsing value multiplicty ['" + s + "']", e);
            }
        }
Example #8
0
        public static DicomVM Parse(string s)
        {
            try {
                DicomVM vm = null;
                if (_vm.TryGetValue(s, out vm))
                    return vm;

                string[] parts = s.Split('-');

                if (parts.Length == 1) {
                    vm = new DicomVM();
                    vm.Minimum = int.Parse(parts[0]);
                    vm.Maximum = vm.Minimum;
                    vm.Multiplicity = vm.Minimum;
                } else {
                    vm = new DicomVM();
                    vm.Minimum = int.Parse(parts[0]);
                    vm.Multiplicity = 1;

                    if (parts[1].EndsWith("n", StringComparison.InvariantCultureIgnoreCase)) {
                        vm.Maximum = int.MaxValue;
                        parts[1] = parts[1].TrimEnd('n', 'N');

                        if (parts[1].Length > 0)
                            vm.Multiplicity = int.Parse(parts[1]);
                    } else {
                        vm.Maximum = int.Parse(parts[1]);
                    }
                }

                _vm.Add(s, vm);

                return vm;
            } catch (Exception e) {
                throw new DicomDataException("Error parsing value multiplicty ['" + s + "']", e);
            }
        }
Example #9
0
        private static bool ParseVrValueFromString <T, TOut>(
            IEnumerable <T> values,
            DicomVM valueMultiplicity,
            Func <string, TOut> parser,
            out IEnumerable <TOut> parsedValues)
        {
            parsedValues = null;

            if (typeof(T) == typeof(string))
            {
                var stringValues = values.Cast <string>().ToArray();

                if (valueMultiplicity.Maximum > 1 && stringValues.Length == 1)
                {
                    stringValues = stringValues[0].Split('\\');
                }

                parsedValues = stringValues.Where(n => !string.IsNullOrEmpty(n?.Trim())).Select(parser);

                return(true);
            }

            return(false);
        }
Example #10
0
        public static DicomVM Parse(string s) {
            try {
                DicomVM vm = null;
                if (_vm.TryGetValue(s, out vm))
                    return vm;

                string[] parts = s.Split(new[] { "-", " ", "or" }, StringSplitOptions.RemoveEmptyEntries);

                if (parts.Length == 1) {
                    vm = new DicomVM();
                    vm.Minimum = int.Parse(parts[0]);
                    vm.Maximum = vm.Minimum;
                    vm.Multiplicity = vm.Minimum;
                } else {
                    vm = new DicomVM();
                    vm.Minimum = int.Parse(parts[0]);
                    vm.Multiplicity = 1;

                    if (parts[1].IndexOf("n", StringComparison.OrdinalIgnoreCase) >= 0) {
                        vm.Maximum = int.MaxValue;
                        parts[1] = parts[1].TrimEnd('n', 'N');

                        if (parts[1].Length > 0)
                            vm.Multiplicity = int.Parse(parts[1]);
                    } else {
                        vm.Maximum = int.Parse(parts[1]);
                    }
                }

                _vm.Add(s, vm);

                return vm;
            } catch (Exception e) {
                throw new DicomDataException("Error parsing value multiplicty ['" + s + "']", e);
            }
        }
Example #11
0
        private void ReadDictionaryXML()
        {
            DicomDictionary dict = _dict;

            XDocument xdoc = XDocument.Load(_stream);

            IEnumerable <XElement> xdicts;

            if (xdoc.Root.Name == "dictionaries")
            {
                xdicts = xdoc.Root.Elements("dictionary");
            }
            else
            {
                XElement xdict = xdoc.Element("dictionary");
                if (xdict == null)
                {
                    throw new DicomDataException("Expected <dictionary> root node in DICOM dictionary.");
                }

                List <XElement> dicts = new List <XElement>();
                dicts.Add(xdict);
                xdicts = dicts;
            }

            foreach (var xdict in xdicts)
            {
                XAttribute creator = xdict.Attribute("creator");
                if (creator != null && !String.IsNullOrEmpty(creator.Value))
                {
                    dict = _dict[_dict.GetPrivateCreator(creator.Value)];
                }
                else
                {
                    dict = _dict;
                }

                foreach (XElement xentry in xdict.Elements("tag"))
                {
                    string name = xentry.Value ?? "Unknown";

                    string keyword = String.Empty;
                    if (xentry.Attribute("keyword") != null)
                    {
                        keyword = xentry.Attribute("keyword").Value;
                    }

                    List <DicomVR> vrs = new List <DicomVR>();
                    XAttribute     xvr = xentry.Attribute("vr");
                    if (xvr != null && !String.IsNullOrEmpty(xvr.Value))
                    {
                        string[] vra = xvr.Value.Split('_', '/', '\\', ',', '|');
                        foreach (string vr in vra)
                        {
                            vrs.Add(DicomVR.Parse(vr));
                        }
                    }
                    else
                    {
                        vrs.Add(DicomVR.NONE);
                    }

                    DicomVM vm = DicomVM.Parse(xentry.Attribute("vm").Value);

                    bool       retired  = false;
                    XAttribute xretired = xentry.Attribute("retired");
                    if (xretired != null && !String.IsNullOrEmpty(xretired.Value) && Boolean.Parse(xretired.Value))
                    {
                        retired = true;
                    }

                    string group   = xentry.Attribute("group").Value;
                    string element = xentry.Attribute("element").Value;
                    if (group.ToLower().Contains("x") || element.ToLower().Contains("x"))
                    {
                        DicomMaskedTag tag = DicomMaskedTag.Parse(group, element);
                        tag.Tag.PrivateCreator = dict.PrivateCreator;
                        dict.Add(new DicomDictionaryEntry(tag, name, keyword, vm, retired, vrs.ToArray()));
                    }
                    else
                    {
                        DicomTag tag = DicomTag.Parse(group + "," + element);
                        tag.PrivateCreator = dict.PrivateCreator;
                        dict.Add(new DicomDictionaryEntry(tag, name, keyword, vm, retired, vrs.ToArray()));
                    }
                }
            }
        }