Example #1
0
        private System.String GetAttributeValue(DvtkData.Dimse.Attribute attribute)
        {
            System.String attributeValue = System.String.Empty;
            if ((attribute == null) ||
                (attribute.Length == 0))
            {
                return(attributeValue);
            }

            switch (attribute.ValueRepresentation)
            {
            case VR.AE:
            {
                ApplicationEntity applicationEntity = (ApplicationEntity)attribute.DicomValue;
                attributeValue = applicationEntity.Values[0];
                break;
            }

            case VR.AS:
            {
                AgeString ageString = (AgeString)attribute.DicomValue;
                attributeValue = ageString.Values[0];
                break;
            }

            case VR.CS:
            {
                CodeString codeString = (CodeString)attribute.DicomValue;
                attributeValue = codeString.Values[0];
                break;
            }

            case VR.DA:
            {
                Date date = (Date)attribute.DicomValue;
                attributeValue = date.Values[0];
                break;
            }

            case VR.DS:
            {
                DecimalString decimalString = (DecimalString)attribute.DicomValue;
                attributeValue = decimalString.Values[0];
                break;
            }

            case VR.DT:
            {
                DvtkData.Dimse.DateTime dateTime = (DvtkData.Dimse.DateTime)attribute.DicomValue;
                attributeValue = dateTime.Values[0];
                break;
            }

            case VR.IS:
            {
                IntegerString integerString = (IntegerString)attribute.DicomValue;
                attributeValue = integerString.Values[0];
                break;
            }

            case VR.LO:
            {
                LongString longString = (LongString)attribute.DicomValue;
                attributeValue = longString.Values[0];
                break;
            }

            case VR.LT:
            {
                LongText longText = (LongText)attribute.DicomValue;
                attributeValue = longText.Value;
                break;
            }

            case VR.PN:
            {
                PersonName personName = (PersonName)attribute.DicomValue;
                attributeValue = personName.Values[0];
                break;
            }

            case VR.SH:
            {
                ShortString shortString = (ShortString)attribute.DicomValue;
                attributeValue = shortString.Values[0];
                break;
            }

            case VR.SQ:
            {
                // Special case looking for the SOP Class UID
                SequenceOfItems sequenceOfItems = (SequenceOfItems)attribute.DicomValue;
                if ((sequenceOfItems != null) &&
                    (sequenceOfItems.Sequence.Count == 1))
                {
                    // Special case looking for the SOP Class UID
                    SequenceItem item = sequenceOfItems.Sequence[0];
                    attribute      = item.GetAttribute(new Tag(0x0008, 0x1150));
                    attributeValue = GetAttributeValue(attribute);
                }
                break;
            }

            case VR.ST:
            {
                ShortText shortText = (ShortText)attribute.DicomValue;
                attributeValue = shortText.Value;
                break;
            }

            case VR.TM:
            {
                Time time = (Time)attribute.DicomValue;
                attributeValue = time.Values[0];
                break;
            }

            case VR.UI:
            {
                UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                attributeValue = uniqueIdentifier.Values[0];
                break;
            }

            default:
                break;
            }

            return(attributeValue);
        }
        /// <summary>
        /// This static function returns the Re-Construted value of the particular Dicom attribute.
        /// </summary>
        /// <param name="attribute">Dicom attribute contains tag vr and value</param>
        /// <returns>Returns the value of the Dicom attribute</returns>
        public static String GetDicomValue(DvtkData.Dimse.Attribute attribute)
        {
            String dumpString = "";

            if (attribute != null && attribute.Length != 0)
            {
                switch (attribute.ValueRepresentation)
                {
                case VR.AE:
                {
                    ApplicationEntity applicationEntity = (ApplicationEntity)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(applicationEntity.Values));
                    break;
                }

                case VR.AS:
                {
                    AgeString ageString = (AgeString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(ageString.Values));
                    break;
                }

                case VR.AT:
                {
                    AttributeTag attributeTag = (AttributeTag)attribute.DicomValue;
                    Console.WriteLine("{0}", GetValues(attributeTag.Values));
                    break;
                }

                case VR.CS:
                {
                    CodeString codeString = (CodeString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(codeString.Values));
                    break;
                }

                case VR.DA:
                {
                    Date date = (Date)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(date.Values));
                    break;
                }

                case VR.DS:
                {
                    DecimalString decimalString = (DecimalString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(decimalString.Values));
                    break;
                }

                case VR.DT:
                {
                    DvtkData.Dimse.DateTime dateTime = (DvtkData.Dimse.DateTime)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(dateTime.Values));
                    break;
                }

                case VR.FD:
                {
                    FloatingPointDouble floatingPointDouble = (FloatingPointDouble)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(floatingPointDouble.Values));
                    break;
                }

                case VR.FL:
                {
                    FloatingPointSingle floatingPointSingle = (FloatingPointSingle)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(floatingPointSingle.Values));
                    break;
                }

                case VR.IS:
                {
                    IntegerString integerString = (IntegerString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(integerString.Values));
                    break;
                }

                case VR.LO:
                {
                    LongString longString = (LongString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(longString.Values));
                    break;
                }

                case VR.LT:
                {
                    LongText longText = (LongText)attribute.DicomValue;
                    dumpString += String.Format("{0}", longText.Value);
                    break;
                }

                case VR.OB:
                {
                    OtherByteString otherByteString = (OtherByteString)attribute.DicomValue;
                    dumpString += String.Format("{0}", otherByteString.FileName);
                    break;
                }

                case VR.OF:
                {
                    OtherFloatString otherFloatString = (OtherFloatString)attribute.DicomValue;
                    dumpString += String.Format("{0}", otherFloatString.FileName);
                    break;
                }

                case VR.OW:
                {
                    OtherWordString otherWordString = (OtherWordString)attribute.DicomValue;
                    dumpString += String.Format("{0}", otherWordString.FileName);
                    break;
                }

                case VR.OV:
                {
                    OtherVeryLongString otherVeryLongString = (OtherVeryLongString)attribute.DicomValue;
                    dumpString += String.Format("{0}", otherVeryLongString.FileName);
                    break;
                }

                case VR.PN:
                {
                    PersonName personName = (PersonName)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(personName.Values));
                    break;
                }

                case VR.SH:
                {
                    ShortString shortString = (ShortString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(shortString.Values));
                    break;
                }

                case VR.SL:
                {
                    SignedLong signedLong = (SignedLong)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(signedLong.Values));
                    break;
                }

                case VR.SQ:
                {
                    //SequenceOfItems sequenceOfItems = (SequenceOfItems)attribute.DicomValue;
                    //int itemNumber = 1;
                    //dumpString += "\r\n";
                    //foreach (SequenceItem item in sequenceOfItems.Sequence)
                    //{
                    //    dumpString += String.Format("> Begin Item: {0}\r\n", itemNumber);
                    //    dumpString += item.Dump(prefix);
                    //    dumpString += prefix + String.Format("> End Item: {0}\r\n", itemNumber++);
                    //}
                    break;
                }

                case VR.SS:
                {
                    SignedShort signedShort = (SignedShort)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(signedShort.Values));
                    break;
                }

                case VR.ST:
                {
                    ShortText shortText = (ShortText)attribute.DicomValue;
                    dumpString += String.Format("{0}", shortText.Value);
                    break;
                }

                case VR.TM:
                {
                    Time time = (Time)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(time.Values));
                    break;
                }

                case VR.UI:
                {
                    UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(uniqueIdentifier.Values));
                    break;
                }

                case VR.UL:
                {
                    UnsignedLong unsignedLong = (UnsignedLong)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(unsignedLong.Values));
                    break;
                }

                case VR.UN:
                {
                    break;
                }

                case VR.US:
                {
                    UnsignedShort unsignedShort = (UnsignedShort)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(unsignedShort.Values));
                    break;
                }

                case VR.UT:
                {
                    break;
                }

                case VR.UR:
                {
                    break;
                }

                case VR.UC:
                {
                    break;
                }

                default:
                    dumpString += String.Format("\'  \'");
                    break;
                }
            }
            else
            {
                dumpString += String.Format("\'  \'");
            }


            return(dumpString);
        }
Example #3
0
        //
        // - Methods -
        //

        /// <summary>
        /// Get the values from this attribute.
        /// </summary>
        /// <returns>The values.</returns>
        public ValidValues GetValues()
        {
            ValidValues validValues = null;

            switch (dvtkDataAttribute.ValueRepresentation)
            {
            case VR.AE:                     // Application Entity
                DvtkData.Dimse.ApplicationEntity theApplicationEntity = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.ApplicationEntity;
                validValues = new ValidValues(this.tagSequence, theApplicationEntity.Values);
                break;

            case VR.AS:                     // Age String
                DvtkData.Dimse.AgeString theAgeString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.AgeString;
                validValues = new ValidValues(this.tagSequence, theAgeString.Values);
                break;

            case VR.AT:                     // Attribute Tag
                DvtkData.Dimse.AttributeTag theAttributeTag = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.AttributeTag;
                validValues = new ValidValues(this.tagSequence, theAttributeTag.Values);
                break;

            case VR.CS:                     // Code String
                DvtkData.Dimse.CodeString theCodeString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.CodeString;
                validValues = new ValidValues(this.tagSequence, theCodeString.Values);
                break;

            case VR.DA:                     // Date
                DvtkData.Dimse.Date theDate = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.Date;
                validValues = new ValidValues(this.tagSequence, theDate.Values);
                break;

            case VR.DS:                     // Decimal String
                DvtkData.Dimse.DecimalString theDecimalString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.DecimalString;
                validValues = new ValidValues(this.tagSequence, theDecimalString.Values);
                break;

            case VR.DT:                     // Date Time
                DvtkData.Dimse.DateTime theDateTime = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.DateTime;
                validValues = new ValidValues(this.tagSequence, theDateTime.Values);
                break;

            case VR.FD:                     // Floating Point Double
                DvtkData.Dimse.FloatingPointDouble theFloatingPointDouble = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.FloatingPointDouble;
                validValues = new ValidValues(this.tagSequence, theFloatingPointDouble.Values);
                break;

            case VR.FL:                     // Floating Point Single
                DvtkData.Dimse.FloatingPointSingle theFloatingPointSingle = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.FloatingPointSingle;
                validValues = new ValidValues(this.tagSequence, theFloatingPointSingle.Values);
                break;

            case VR.IS:                     // Integer String
                DvtkData.Dimse.IntegerString theIntegerString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.IntegerString;
                validValues = new ValidValues(this.tagSequence, theIntegerString.Values);
                break;

            case VR.LO:                     // Long String
                DvtkData.Dimse.LongString theLongString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.LongString;
                validValues = new ValidValues(this.tagSequence, theLongString.Values);
                break;

            case VR.LT:                     // Long Text
                DvtkData.Dimse.LongText theLongText = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.LongText;
                validValues = new ValidValues(this.tagSequence, theLongText.Value);
                break;

            case VR.PN:                     // Person Name
                DvtkData.Dimse.PersonName thePersonName = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.PersonName;
                validValues = new ValidValues(this.tagSequence, thePersonName.Values);
                break;

            case VR.SH:                     // Short String
                DvtkData.Dimse.ShortString theShortString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.ShortString;
                validValues = new ValidValues(this.tagSequence, theShortString.Values);
                break;

            case VR.SL:                     // Signed Long
                DvtkData.Dimse.SignedLong theSignedLong = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.SignedLong;
                validValues = new ValidValues(this.tagSequence, theSignedLong.Values);
                break;

            case VR.SS:                     // Signed Short
                DvtkData.Dimse.SignedShort theSignedShort = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.SignedShort;
                validValues = new ValidValues(this.tagSequence, theSignedShort.Values);
                break;

            case VR.ST:                     // Short Text
                DvtkData.Dimse.ShortText theShortText = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.ShortText;
                validValues = new ValidValues(this.tagSequence, theShortText.Value);
                break;

            case VR.TM:                     // Time
                DvtkData.Dimse.Time theTime = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.Time;
                validValues = new ValidValues(this.tagSequence, theTime.Values);
                break;

            case VR.UI:                     // Unique Identifier (UID)
                DvtkData.Dimse.UniqueIdentifier theUniqueIdentifier = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.UniqueIdentifier;
                validValues = new ValidValues(this.tagSequence, theUniqueIdentifier.Values);
                break;

            case VR.UL:                     // Unsigned Long
                DvtkData.Dimse.UnsignedLong theUnsignedLong = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.UnsignedLong;
                validValues = new ValidValues(this.tagSequence, theUnsignedLong.Values);
                break;

            case VR.US:                     // Unsigned Short
                DvtkData.Dimse.UnsignedShort theUnsignedShort = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.UnsignedShort;
                validValues = new ValidValues(this.tagSequence, theUnsignedShort.Values);
                break;

            case VR.UT:                     // Unlimited Text
                DvtkData.Dimse.UnlimitedText theUnlimitedText = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.UnlimitedText;
                validValues = new ValidValues(this.tagSequence, theUnlimitedText.Value);
                break;

            default:
                DvtkHighLevelInterfaceException.Throw("VR " + dvtkDataAttribute.ValueRepresentation.ToString() + " is not handled by class SimpleAttribute.");
                break;
            }

            return(validValues);
        }