Exemplo n.º 1
0
        /// <summary>
        /// Get an attribute given the zero based index for this AttributeSet.
        /// </summary>
        public Attribute this[int zeroBasedIndex]
        {
            get
            {
                Attribute attribute = null;

                if ((zeroBasedIndex >= 0) && (zeroBasedIndex < Count))
                {
                    DvtkData.Dimse.Attribute dvtkDataAttribute = this.dvtkDataAttributeSet[zeroBasedIndex];

                    Tag tag = new Tag(dvtkDataAttribute.Tag.GroupNumber, dvtkDataAttribute.Tag.ElementNumber);

                    TagSequence attributeTagSequence = this.tagSequence.Clone();
                    attributeTagSequence.Add(tag);

                    attribute = new ValidAttribute(attributeTagSequence, dvtkDataAttribute, this);
                }
                else
                {
                    throw new System.Exception("Set with tag sequence \"" + this.tagSequence.ToString() + "\" contains " + this.Count.ToString() + "Index for attribute supplied is " + zeroBasedIndex.ToString() + ".");
                }

                return(attribute);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new Attribute in this AttributeSet containing no values.
        ///
        /// Precondition: this Attribute may not exist in the AttributeSet.
        /// </summary>
        /// <param name="tagAsUInt32"></param>
        /// <param name="vR"></param>
        internal ValidAttribute Create(UInt32 tagAsUInt32, VR vR)
        {
            TagSequence newTagSequence = this.tagSequence.Clone();

            newTagSequence.Add(new Tag(tagAsUInt32));

            DvtkData.Dimse.Attribute dvtkDataAttribute = new DvtkData.Dimse.Attribute(tagAsUInt32, (DvtkData.Dimse.VR)vR);
            this.dvtkDataAttributeSet.Add(dvtkDataAttribute);
            MakeAscending(false);

            ValidAttribute validAttribute = new ValidAttribute(newTagSequence, dvtkDataAttribute, this);

            return(validAttribute);
        }
Exemplo n.º 3
0
        internal void Set(Attribute attribute)
        {
            DvtkData.Dimse.Attribute dvtkDataAttribute = null;

            // First remove the (if exisiting) attribute(s).
            do
            {
                dvtkDataAttribute = this.dvtkDataAttributeSet.GetAttribute(attribute.TagAsUInt32);

                if (dvtkDataAttribute != null)
                {
                    this.dvtkDataAttributeSet.Remove(dvtkDataAttribute);
                }
            }while (dvtkDataAttribute != null);

            this.dvtkDataAttributeSet.Add(attribute.DvtkDataAttribute);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tagSequence">The tag sequence of the attribute.</param>
        /// <param name="dvtkDataAttribute">The encapsulated DvtkData attribute.</param>
        /// <param name="parentAttributeSet">The AttributeSet this instance is part of.</param>
        public ValidAttribute(TagSequence tagSequence, DvtkData.Dimse.Attribute dvtkDataAttribute, AttributeSet parentAttributeSet)
        {
            // Sanity check.
            if (dvtkDataAttribute == null)
            {
                throw new ArgumentException("Internal error: dvtkDataAttribute may not be null.");
            }

            // Sanity check.
            if (parentAttributeSet == null)
            {
                throw new ArgumentException("Internal error: parentAttributeSet may not be null.");
            }

            TagSequence = tagSequence;
            this.dvtkDataAttribute = dvtkDataAttribute;
            this.parentAttributeSet = parentAttributeSet;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tagSequence">The tag sequence of the attribute.</param>
        /// <param name="dvtkDataAttribute">The encapsulated DvtkData attribute.</param>
        /// <param name="parentAttributeSet">The AttributeSet this instance is part of.</param>
        public ValidAttribute(TagSequence tagSequence, DvtkData.Dimse.Attribute dvtkDataAttribute, AttributeSet parentAttributeSet)
        {
            // Sanity check.
            if (dvtkDataAttribute == null)
            {
                throw new ArgumentException("Internal error: dvtkDataAttribute may not be null.");
            }

            // Sanity check.
            if (parentAttributeSet == null)
            {
                throw new ArgumentException("Internal error: parentAttributeSet may not be null.");
            }

            TagSequence             = tagSequence;
            this.dvtkDataAttribute  = dvtkDataAttribute;
            this.parentAttributeSet = parentAttributeSet;
        }
Exemplo n.º 6
0
        private static void AddDicomAttribute(DvtkData.Dimse.AttributeSet dataset, DicomTagPath dicomTagPath, System.String dicomValue)
        {
            if (dicomTagPath.Next != null)
            {
                // Try to get the sequence identified by this Tag
                DvtkData.Dimse.Attribute sequenceAttribute = dataset.GetAttribute(dicomTagPath.Tag);
                if (sequenceAttribute == null)
                {
                    // Need to add the sequence
                    DvtkData.Dimse.SequenceItem item = new DvtkData.Dimse.SequenceItem();
                    dataset.AddAttribute(dicomTagPath.Tag.GroupNumber,
                                         dicomTagPath.Tag.ElementNumber,
                                         DvtkData.Dimse.VR.SQ, item);

                    // Get the newly added sequence
                    sequenceAttribute = dataset.GetAttribute(dicomTagPath.Tag);
                }

                // Get the contained item
                DvtkData.Dimse.SequenceOfItems sequenceOfItems = (DvtkData.Dimse.SequenceOfItems)sequenceAttribute.DicomValue;
                if (sequenceOfItems.Sequence.Count == 1)
                {
                    DvtkData.Dimse.SequenceItem item = sequenceOfItems.Sequence[0];

                    // Call recursively
                    AddDicomAttribute(item, dicomTagPath.Next, dicomValue);
                }
            }
            else
            {
                // Try to get the attribute identified by this Tag
                DvtkData.Dimse.Attribute attribute = dataset.GetAttribute(dicomTagPath.Tag);
                if (attribute != null)
                {
                    // If present - remove the attribute - we want to update the value
                    dataset.Remove(attribute);
                }

                // Add the new value
                dataset.AddAttribute(dicomTagPath.Tag.GroupNumber, dicomTagPath.Tag.ElementNumber, DicomTagVrLookup.GetVR(dicomTagPath.Tag), dicomValue);
            }
        }
Exemplo n.º 7
0
        // returns empty string if not found.
        public String GetSopClassUid()
        {
            String sopClassUid = String.Empty;

            // Try to get the SOP Class UID
            DvtkData.Dimse.Attribute sopClassUidAttribute = this.DvtkDataCommandSet.GetAttribute(DvtkData.Dimse.Tag.AFFECTED_SOP_CLASS_UID);

            if (sopClassUidAttribute == null)
            {
                sopClassUidAttribute = this.DvtkDataCommandSet.GetAttribute(DvtkData.Dimse.Tag.REQUESTED_SOP_CLASS_UID);
            }
            if (sopClassUidAttribute != null)
            {
                // Get the value of the SOP Class UID
                DvtkData.Dimse.UniqueIdentifier uniqueIdentifier = (DvtkData.Dimse.UniqueIdentifier)sopClassUidAttribute.DicomValue;
                sopClassUid = uniqueIdentifier.Values[0];
            }

            return(sopClassUid);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get an attribute given the tag as UInt32.
        /// </summary>
        internal Attribute GetAttribute(UInt32 tagAsUInt32)
        {
            Attribute attribute = null;

            TagSequence attributeTagSequence = this.tagSequence.Clone();

            attributeTagSequence.Add(new Tag(tagAsUInt32));

            DvtkData.Dimse.Attribute dvtkDataAttribute = this.dvtkDataAttributeSet.GetAttribute(tagAsUInt32);

            if (dvtkDataAttribute == null)
            {
                attribute = new InvalidAttribute(attributeTagSequence);
            }
            else
            {
                attribute = new ValidAttribute(attributeTagSequence, dvtkDataAttribute, this);
            }

            return(attribute);
        }
Exemplo n.º 9
0
        //
        // - Constructors -
        //

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tagSequence">The tag sequence (one or more tags seperated with an '/') of this attribue.</param>
        /// <param name="dvtkDataAttribute">The encapsulated DvtkData attribute</param>
        public UnknownAttribute(String tagSequence, DvtkData.Dimse.Attribute dvtkDataAttribute) : base(tagSequence, dvtkDataAttribute)
        {
        }
Exemplo n.º 10
0
        /// <summary>
        /// Get the attribute set this attribute belongs to.
        /// TODO!!: merge this code with GetAttribute method.
        /// </summary>
        /// <param name="tagSequence"></param>
        /// <returns></returns>
        internal AttributeSet GetAttributeSet(String tagSequence)
        {
            Tag[]     tags;
            Attribute attribute = null;

            tags = Tag.InterpretTagSequence(tagSequence);

            AttributeSet currentAttributeSet = this;
            String       currentTagSequence  = "";
            String       currentTagSequenceLastTagNoIndex = "";

            foreach (Tag tag in tags)
            {
                // Set the currentTagSequence.
                if (currentTagSequence == "")
                {
                    currentTagSequence = tag.TagAsString;
                    currentTagSequenceLastTagNoIndex = tag.TagWithoutIndex;
                }
                else
                {
                    currentTagSequence += "/" + tag.TagAsString;
                    currentTagSequenceLastTagNoIndex = currentTagSequence + "/" + tag.TagWithoutIndex;
                }

                // Create the correct Attribute object.
                DvtkData.Dimse.Attribute dvtkDataAttribute = currentAttributeSet.dvtkDataAttributeSet.GetAttribute(tag.TagAsUInt32);

                if (dvtkDataAttribute == null)
                {
                    attribute = null;
                    break;
                }
                else
                {
                    attribute = Attribute.GetAttribute(tagSequence, dvtkDataAttribute);
                }

                // If this tag contains an index, check that the attribute is a sequence attribute
                // and retrieve the correct attribute set from it.
                if (tag.ContainsIndex)
                {
                    if (attribute is SequenceAttribute)
                    {
                        SequenceAttribute sequenceAttribute = attribute as SequenceAttribute;

                        if (tag.Index > sequenceAttribute.ItemCount)
                        {
                            String errorText = "Sequence attribute with tag sequence " + currentTagSequenceLastTagNoIndex + " contains " + sequenceAttribute.ItemCount.ToString() + " items.";
                            errorText += "\r\nThe script however is expecting it to have an item with index " + tag.Index.ToString() + ".";

                            // InterfaceLogging.WriteError(errorText);
                            attribute = null;
                            break;
                        }
                        else
                        {
                            currentAttributeSet = sequenceAttribute.GetItem(tag.Index);
                        }
                    }
                    else
                    {
                        String errorText = "Attribute with tag sequence " + currentTagSequenceLastTagNoIndex + " is not a sequence attribute.";
                        errorText += "\r\nThe script however is expecting it because the tag sequence " + currentTagSequence + " contains an index.";

                        // InterfaceLogging.WriteError(errorText);
                        attribute = null;
                        break;
                    }
                }
            }

            return(currentAttributeSet);
        }
Exemplo n.º 11
0
        private void AddReferencedSopSequence(ReferencedSopItemCollection storageCommitItems,
            uint tag,
            DvtkData.Dimse.AttributeSet attributeSet,
            InstanceStateEnum newInstanceState)
        {
            ushort group = (ushort)(tag >> 16);
            ushort element = (ushort)(tag & 0x0000FFFF);
            DvtkData.Dimse.Tag tagValue = new DvtkData.Dimse.Tag(group, element);

            DvtkData.Dimse.Attribute referencedSopSequence = attributeSet.GetAttribute(tagValue);
            if (referencedSopSequence != null)
            {
                attributeSet.Remove(referencedSopSequence);
            }

            referencedSopSequence = new DvtkData.Dimse.Attribute(tag, DvtkData.Dimse.VR.SQ);
            DvtkData.Dimse.SequenceOfItems referencedSopSequenceOfItems = new DvtkData.Dimse.SequenceOfItems();
            referencedSopSequence.DicomValue = referencedSopSequenceOfItems;

            foreach (ReferencedSopItem referencedSopItem in storageCommitItems)
            {
                if ((referencedSopItem.InstanceState == InstanceStateEnum.InstanceStored) &&
                    (newInstanceState == InstanceStateEnum.InstanceStorageCommitRequested))
                {
                    DvtkData.Dimse.SequenceItem referencedSopSequenceItem = new DvtkData.Dimse.SequenceItem();
                    referencedSopSequenceItem.AddAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_CLASS_UID.GroupNumber,
                        DvtkData.Dimse.Tag.REFERENCED_SOP_CLASS_UID.ElementNumber,
                        DvtkData.Dimse.VR.UI, referencedSopItem.SopClassUid);
                    referencedSopSequenceItem.AddAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_INSTANCE_UID.GroupNumber,
                        DvtkData.Dimse.Tag.REFERENCED_SOP_INSTANCE_UID.ElementNumber,
                        DvtkData.Dimse.VR.UI, referencedSopItem.SopInstanceUid);
                    referencedSopItem.InstanceState = newInstanceState;
                    referencedSopSequenceOfItems.Sequence.Add(referencedSopSequenceItem);
                }
            }
            attributeSet.Add(referencedSopSequence);
        }