Exemple #1
0
        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;
        }
Exemple #2
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);
        }
        public DicomDictionaryEntry(DicomMaskedTag tag, string name, string keyword, DicomVM vm, bool retired,
                                    params DicomVr[] vrs)
        {
            Tag = tag.Tag;
            MaskTag = tag;

            Name = string.IsNullOrWhiteSpace(name) ? Tag.ToString() : name;
            Keyword = string.IsNullOrWhiteSpace(keyword) ? Name : keyword;

            ValueMultiplicity = vm;
            ValueRepresentations = vrs;
            IsRetired = retired;
        }
Exemple #4
0
        public override DicomDictionaryEntry ParseRow(Dictionary <string, XElement> row)
        {
            if (row["Tag"].Value.ToLower() == "(no tag)")
            {
                return(null);
            }
            var    tag = DicomMaskedTag.Parse(row["Tag"].Value.ToLower());
            string name;
            string keyword;
            bool   retired;

            if (row.ContainsKey("Message Field"))
            {
                name    = row["Message Field"].Value;
                retired = Caption.Contains("Retired");
            }
            else
            {
                name    = row["Name"].Value;
                retired = row[""].Value.Contains("RET");
            }

            keyword = row["Keyword"].Value.Replace("\u200b", string.Empty);

            if (keyword.EndsWith("Retired"))
            {
                keyword = keyword.Substring(0, keyword.Length - "Retired".Length);
            }
            var     vrs = row["VR"].Value.Split(new[] { " or " }, StringSplitOptions.RemoveEmptyEntries).Where(vr => vr.ToLowerInvariant().Trim() != "see note").Select(DicomVR.Parse).ToArray();
            DicomVM vm  = null;

            if (!string.IsNullOrEmpty(row["VM"].Value))
            {
                vm = DicomVM.Parse(row["VM"].Value.Replace(" or 1", string.Empty));
            }

            //var dicos = row[""].Value.Contains("DICOS");
            //var diconde = row[""].Value.Contains("DICONDE");

            return(new DicomDictionaryEntry(tag, name, keyword, vm, retired, vrs));
        }
Exemple #5
0
        /// <inheritdoc cref="GetNaturalTypeForVr(DicomVR[], DicomVM)"/>
        public static DatabaseTypeRequest GetNaturalTypeForVr(DicomVR dicomVr, DicomVM valueMultiplicity)
        {
            var decimalSize = new DecimalSize(19, 19);

            //if it's an array just use a big string to represent it
            if (valueMultiplicity.Maximum > 1)
            {
                return(new DatabaseTypeRequest(typeof(string), int.MaxValue));
            }

            if (dicomVr == DicomVR.AE)
            {
                return(new DatabaseTypeRequest(typeof(string), 16));
            }

            if (dicomVr == DicomVR.AS)
            {
                return(new DatabaseTypeRequest(typeof(string), 4));
            }

            //Attribute Tag (DicomItem)
            if (dicomVr == DicomVR.AT)
            {
                return(new DatabaseTypeRequest(typeof(string), 4));
            }

            if (dicomVr == DicomVR.CS)
            {
                return(new DatabaseTypeRequest(typeof(string), 16));
            }

            if (dicomVr == DicomVR.DA)
            {
                return(new DatabaseTypeRequest(typeof(DateTime)));
            }

            if (dicomVr == DicomVR.DS)
            {
                return(new DatabaseTypeRequest(typeof(decimal), null, decimalSize)); //16 bytes maximum but representation is a string...
            }
            if (dicomVr == DicomVR.DT)
            {
                return(new DatabaseTypeRequest(typeof(DateTime)));
            }

            if (dicomVr == DicomVR.FD)
            {
                return(new DatabaseTypeRequest(typeof(double), null, decimalSize));
            }

            if (dicomVr == DicomVR.FL)
            {
                return(new DatabaseTypeRequest(typeof(float), null, decimalSize));
            }

            if (dicomVr == DicomVR.IS)
            {
                return(new DatabaseTypeRequest(typeof(int), null));
            }

            if (dicomVr == DicomVR.LO)
            {
                return(new DatabaseTypeRequest(typeof(string), 64));
            }

            if (dicomVr == DicomVR.LT)
            {
                return(new DatabaseTypeRequest(typeof(string), 10240));
            }

            if (dicomVr == DicomVR.OB)
            {
                return(new DatabaseTypeRequest(typeof(byte[])));
            }

            if (dicomVr == DicomVR.OD)
            {
                return(new DatabaseTypeRequest(typeof(double)));
            }

            if (dicomVr == DicomVR.OF)
            {
                return(new DatabaseTypeRequest(typeof(float), null, decimalSize));
            }

            if (dicomVr == DicomVR.OL)
            {
                return(new DatabaseTypeRequest(typeof(uint)));
            }

            if (dicomVr == DicomVR.OW)
            {
                return(new DatabaseTypeRequest(typeof(ushort)));
            }

            if (dicomVr == DicomVR.PN)
            {
                return(new DatabaseTypeRequest(typeof(string), 320)); //64 characters but up to 5?
            }
            if (dicomVr == DicomVR.SH)
            {
                return(new DatabaseTypeRequest(typeof(string), 16));
            }

            if (dicomVr == DicomVR.SL)
            {
                return(new DatabaseTypeRequest(typeof(int)));
            }

            if (dicomVr == DicomVR.SQ)
            {
                return(new DatabaseTypeRequest(typeof(string), int.MaxValue));
            }

            if (dicomVr == DicomVR.SS)
            {
                return(new DatabaseTypeRequest(typeof(short)));
            }

            if (dicomVr == DicomVR.ST)
            {
                return(new DatabaseTypeRequest(typeof(string), int.MaxValue));
            }

            if (dicomVr == DicomVR.TM)
            {
                return(new DatabaseTypeRequest(typeof(TimeSpan)));
            }

            if (dicomVr == DicomVR.UC)                                  //unlimited characters
            {
                return(new DatabaseTypeRequest(typeof(string), 10240)); //will be varchar max etc anyway
            }
            if (dicomVr == DicomVR.UI)
            {
                return(new DatabaseTypeRequest(typeof(string), 64));
            }

            if (dicomVr == DicomVR.UL)
            {
                return(new DatabaseTypeRequest(typeof(uint)));
            }

            if (dicomVr == DicomVR.UN)
            {
                return(new DatabaseTypeRequest(typeof(string), 10240));
            }

            if (dicomVr == DicomVR.UR)
            {
                return(new DatabaseTypeRequest(typeof(string), int.MaxValue));//url
            }
            if (dicomVr == DicomVR.US)
            {
                return(new DatabaseTypeRequest(typeof(ushort)));
            }

            if (dicomVr == DicomVR.UT)
            {
                return(new DatabaseTypeRequest(typeof(string), 10240));
            }

            throw new ArgumentOutOfRangeException("Invalid value representation:" + dicomVr);
        }
Exemple #6
0
        /// <summary>
        /// Returns a <see cref="DatabaseTypeRequest"/> for describing the datatype and length that should be used to represent the given dicom representation.
        /// If <paramref name="valueMultiplicity"/> allows multiple elements then string max is returned.
        /// </summary>
        /// <param name="valueRepresentations"></param>
        /// <param name="valueMultiplicity"></param>
        /// <returns></returns>
        public static DatabaseTypeRequest GetNaturalTypeForVr(DicomVR[] valueRepresentations, DicomVM valueMultiplicity)
        {
            //maximum lengths are defined by http://dicom.nema.org/dicom/2013/output/chtml/part05/sect_6.2.html  in bytes... lets err on the side of caution and say it is not unicode so 1 byte = 1 character
            List <DatabaseTypeRequest> vrs = valueRepresentations
                                             .Select(dicomVr => GetNaturalTypeForVr(dicomVr, valueMultiplicity))
                                             .ToList();

            return(vrs.Count == 1 ? vrs[0] : Conflate(vrs));
        }