Пример #1
0
        /// <summary>
        ///     Reads string data and creates the appropriate DICOM element
        /// </summary>
        /// <param name="data">the string data as an object (fresh from the DICOM reader)</param>
        /// <param name="vr">the VR of the element to be generated</param>
        /// <returns>a concrete DICOM element that uses the interface IDICOMElement</returns>
        private static IDICOMElement ReadString(VR vr, Tag tag, object data, StringEncoding enc)
        {
            switch (vr)
            {
            case VR.AgeString:
                return(new AgeString(tag, DICOMString.Read(data as byte[], enc)));

            case VR.ApplicationEntity:
                return(new ApplicationEntity(tag, DICOMString.Read(data as byte[], enc)));

            case VR.CodeString:
                return(new CodeString()
                {
                    Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc)
                });

            case VR.Date:
                return(new Date(tag, DICOMString.Read(data as byte[], enc)));

            case VR.DateTime:
                return(new DateTime(tag, DICOMString.Read(data as byte[], enc)));

            case VR.DecimalString:
                return(new DecimalString(tag, DICOMString.Read(data as byte[], enc)));

            case VR.IntegerString:
                return(new IntegerString(tag, DICOMString.Read(data as byte[], enc)));

            case VR.LongString:
                return(new LongString(tag, DICOMString.Read(data as byte[], enc)));

            case VR.LongText:
                return(new LongText()
                {
                    Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc)
                });

            case VR.PersonName:
                return(new PersonName()
                {
                    Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc)
                });

            case VR.ShortString:
                return(new ShortString()
                {
                    Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc)
                });

            case VR.ShortText:
                return(new ShortText(tag, DICOMString.Read(data as byte[], enc)));

            case VR.Time:
                return(new Time(tag, DICOMString.Read(data as byte[], enc)));

            case VR.UnlimitedCharacter:
                return(new UnlimitedCharacter()
                {
                    Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc)
                });

            case VR.UnlimitedText:
                return(new UnlimitedText(tag, DICOMString.Read(data as byte[], enc)));

            case VR.UniqueIdentifier:
                return(new UniqueIdentifier(tag, DICOMString.Read(data as byte[], enc)));

            case VR.UniversalResourceId:
                return(new UniversalResourceId(tag, DICOMString.Read(data as byte[], enc)));

            default:
                return(new Unknown(tag, data as byte[]));
            }
        }
Пример #2
0
        /// <summary>
        ///     Reads string data and creates the appropriate DICOM element
        /// </summary>
        /// <param name="data">the string data as an object (fresh from the DICOM reader)</param>
        /// <param name="vr">the VR of the element to be generated</param>
        /// <returns>a concrete DICOM element that uses the interface IDICOMElement</returns>
        public static IDICOMElement ReadString(VR vr, Tag tag, object data, StringEncoding enc)
        {
            switch (vr)
            {
            case VR.AgeString:
                return(new AgeString(tag, DICOMString.Read(data as byte[], enc)));

            case VR.ApplicationEntity:
                return(new ApplicationEntity(tag, DICOMString.Read(data as byte[], enc)));

            case VR.CodeString:
                return(new CodeString()
                {
                    Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc)
                });

            case VR.Date:
                var dateData = DICOMString.Read(data as byte[], enc);
                if (dateData.Any(b => b == '-'))     // Range ('-')
                {
                    var parts = dateData.Split('-');
                    var dates = parts.Select(p => StringDataParser.ParseDate(p)).OrderBy(p => p).ToArray();
                    return(new Date(tag, dates)
                    {
                        IsRange = true
                    });
                }
                else
                {
                    return(new Date(tag, dateData));
                }

            case VR.DateTime:
                var dateTimeData = DICOMString.Read(data as byte[], enc);
                if (dateTimeData.Any(b => b == '-'))     // Range ('-')
                {
                    var parts = dateTimeData.Split('-');
                    var dates = parts.Select(p => StringDataParser.ParseDateTime(p)).OrderBy(p => p).ToArray();
                    return(new DateTime(tag, dates)
                    {
                        IsRange = true
                    });
                }
                else
                {
                    return(new DateTime(tag, dateTimeData));
                }

            case VR.DecimalString:
                return(new DecimalString(tag, DICOMString.Read(data as byte[], enc)));

            case VR.IntegerString:
                return(new IntegerString(tag, DICOMString.Read(data as byte[], enc)));

            case VR.LongString:
                return(new LongString(tag, DICOMString.Read(data as byte[], enc)));

            case VR.LongText:
                return(new LongText()
                {
                    Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc)
                });

            case VR.PersonName:
                return(new PersonName()
                {
                    Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc)
                });

            case VR.ShortString:
                return(new ShortString()
                {
                    Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc)
                });

            case VR.ShortText:
                return(new ShortText(tag, DICOMString.Read(data as byte[], enc)));

            case VR.Time:
                var timeData = DICOMString.Read(data as byte[], enc);
                if (timeData.Any(b => b == '-'))     // Range ('-')
                {
                    var parts = timeData.Split('-');
                    var dates = parts.Select(p => StringDataParser.ParseTime(p)).OrderBy(p => p).ToArray();
                    return(new Time(tag, dates)
                    {
                        IsRange = true
                    });
                }
                else
                {
                    return(new Time(tag, timeData));
                }

            case VR.UnlimitedCharacter:
                return(new UnlimitedCharacter()
                {
                    Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc)
                });

            case VR.UnlimitedText:
                return(new UnlimitedText(tag, DICOMString.Read(data as byte[], enc)));

            case VR.UniqueIdentifier:
                return(new UniqueIdentifier(tag, DICOMString.Read(data as byte[], enc)));

            case VR.UniversalResourceId:
                return(new UniversalResourceId(tag, DICOMString.Read(data as byte[], enc)));

            default:
                return(new Unknown(tag, data as byte[]));
            }
        }