Пример #1
0
        /// <summary>
        /// Create both a Content Item instance and all its direct and indirect child Content Item instances.
        /// </summary>
        /// <param name="attributeSet">
        /// <param name="dataSet">
        /// The AttributeSet instance containing the DICOM attributes to construct this Content
        /// Item instance and its direct and indirect child Content Item instances with.
        /// </param>
        /// </param>
        /// <param name="parentContentItem">
        /// The parent Content Item instance.
        /// If no parent exists, supply null.
        /// </param>
        /// <param name="position">
        /// The ordinal position of the associated Sequence Item in it's contained Content Sequence.
        /// Item.
        /// </param>
        /// <returns>A Content Item instance.</returns>
        private static ContentItem CreateContentItems(AttributeSet attributeSet, ContentItem parentContentItem, uint position)
        {
            //
            // Create the single Content Item instance using the Attribute Set instance supplied.
            //

            ContentItem contentItem = CreateContentItem(attributeSet, parentContentItem, position);


            //
            // If existing, create its child Content Item instances.
            //

            DvtkHighLevelInterface.Dicom.Other.Attribute attribute = attributeSet["0x0040A730"]; // Content Sequence Attribute.

            if (attribute.Exists)
            {
                if (attribute.VR == VR.SQ)
                {
                    for (uint sequenceItemIndex = 1; sequenceItemIndex <= attribute.ItemCount; sequenceItemIndex++)
                    {
                        SequenceItem sequenceItem = attribute.GetItem(System.Convert.ToInt32(sequenceItemIndex));

                        ContentItem childContentItem = CreateContentItems(sequenceItem, contentItem, sequenceItemIndex);
                        contentItem.childContentItems.Add(childContentItem);
                    }
                }
            }

            return(contentItem);
        }
Пример #2
0
        /// <summary>
        /// Get all attributes that are refered to by this tag sequence.
        ///
        /// Precondition for the supplied TagSequence:
        /// All but the last tag contains an index.
        /// The last tag doesn't contain an index.
        /// </summary>
        /// <param name="tagSequence">The tag sequence.</param>
        /// <returns>The attributes.</returns>
        internal AttributeCollection GetAttributes(TagSequence tagSequence)
        {
            AttributeCollection attributeCollection = new AttributeCollection();

            Tag firstTag = (tagSequence.Tags[0]) as Tag;

            Attribute firstAttribute = GetAttribute(firstTag.AsUInt32);

            if (firstAttribute is InvalidAttribute)
            {
                // Do nothing, just return an empty set.
            }
            else
            {
                if (tagSequence.Tags.Count > 1)
                // Expecting a sequence attribute as first tag.
                {
                    if (firstAttribute.VR == VR.SQ)
                    {
                        int fromIndex = 0;
                        int toIndex   = 0;

                        if (firstTag.ContainsWildcardIndex)
                        {
                            fromIndex = 1;
                            toIndex   = firstAttribute.ItemCount;
                        }
                        else
                        {
                            fromIndex = firstTag.IndexNumber;
                            toIndex   = firstTag.IndexNumber;
                        }

                        TagSequence itemTagSequence = tagSequence.Clone();
                        itemTagSequence.Tags.RemoveAt(0);

                        for (int index = fromIndex; index <= toIndex; index++)
                        {
                            SequenceItem item = firstAttribute.GetItem(index);

                            AttributeCollection itemAttributeCollection = item.GetAttributes(itemTagSequence);

                            attributeCollection.AddRange(itemAttributeCollection);
                        }
                    }
                    else
                    {
                        // Do nothing, just return an empty set.
                    }
                }
                else
                // Expecting a non-sequence attribute as tag.
                {
                    attributeCollection.Add(firstAttribute);
                }
            }

            return(attributeCollection);
        }
Пример #3
0
        internal virtual void Set <T>(TagSequence tagSequence, VR vR, T genericsParameter)
        {
            AttributeSet currentAttributeSetInLoop = this;

            for (int index = 0; index < tagSequence.Tags.Count; index++)
            {
                Tag tag = tagSequence[index];

                if (index < tagSequence.Tags.Count - 1)
                // If this is not the last tag from the TagSequence...
                {
                    Attribute attribute = currentAttributeSetInLoop.SetSequenceAttribute(tag);

                    currentAttributeSetInLoop = attribute.GetItem(tag.IndexNumber);
                }
                else
                // If this is the last tag from the TagSequence...
                {
                    Attribute attribute = currentAttributeSetInLoop.GetAttribute(tag.AsUInt32);

                    if (attribute is ValidAttribute)
                    {
                        attribute.Delete();
                    }

                    attribute = currentAttributeSetInLoop.Create(tag.AsUInt32, vR);


                    // The type of genericsParameter (generics type) is determined run-time.
                    // Maybe this is the reason for a direct call to attribute.Values.Add
                    // (has a overloaded method with params parameter) with the argument
                    // genericsParameter not to work. Needed to explicitly cast to a specfic type
                    // before calling the Add method.
                    if (genericsParameter is Values)
                    {
                        Values values = genericsParameter as Values;

                        attribute.Values.Add(values);
                    }
                    else if (genericsParameter is Byte[])
                    {
                        Byte[] value = genericsParameter as Byte[];

                        attribute.Values.Set(value);
                    }
                    else if (genericsParameter is Object[])
                    {
                        Object[] values = genericsParameter as Object[];

                        attribute.Values.Add(values);
                    }
                    else
                    {
                        throw new HliException("Not supposed to get here.");
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="sequenceItem">
        /// The SequenceItem instance containing the DICOM attributes to construct this instance with.
        /// </param>
        /// <param name="parentContentItem">The parent Content Item.</param>
        /// <param name="position">The ordinal position of the associated Sequence Item in it's contained Content Sequence Item.</param>
        public ContentItemWithValueTypeNum(AttributeSet attributeSet, ContentItem parentContentItem, uint position) :
            base(attributeSet, parentContentItem, position)
        {
            DvtkHighLevelInterface.Dicom.Other.Attribute attribute = attributeSet["0x0040A300"];

            if (attribute.Exists)
            {
                if (attribute.VR == VR.SQ)
                {
                    if (attribute.ItemCount > 0)
                    {
                        this.measuredValue = new MeasuredValue(attribute.GetItem(1));
                    }
                }
            }

            this.numericValueQualifier = ConceptCode.CreateConceptCode(attributeSet, "0x0040A301", numericValueQualifierContext);
        }
Пример #5
0
        //
        // - Methods -
        //

        /// <summary>
        /// Create a ConceptCode instance, if the specified Sequence Attribute is present in the
        /// supplied Attribute Set and the Sequence Attribute contains at least one Sequence Item.
        /// </summary>
        /// <param name="attributeSet">
        /// The Attribute Set in which the Sequence Attribute may be present.
        /// </param>
        /// <param name="tag">The Tag of the Sequence Attribute.</param>
        /// <returns>
        /// The created ConceptCode instance if the first Sequence Item exists.
        /// Null otherwise.
        /// </returns>
        internal static ConceptCode CreateConceptCode(AttributeSet attributeSet, String tag, string context)
        {
            ConceptCode conceptCode = null;

            DvtkHighLevelInterface.Dicom.Other.Attribute attribute = attributeSet[tag];

            if (attribute.Exists)
            {
                if (attribute.VR == VR.SQ)
                {
                    if (attribute.ItemCount > 0)
                    {
                        conceptCode = new ConceptCode(attribute.GetItem(1), context);
                    }
                }
            }

            return(conceptCode);
        }
Пример #6
0
        /// <summary>
        /// Make attributes in this AttributeSet ascending (Dicom compliant).
        /// </summary>
        /// <param name="recursive">
        /// When this is true, all attributes are made ascending resursively,
        /// i.e. all contained sequence items are also sorted.
        /// </param>
        public void MakeAscending(bool recursive)
        {
            this.dvtkDataAttributeSet.MakeAscending();

            if (recursive)
            {
                for (int index = 0; index < Count; index++)
                {
                    Attribute attribute = this[index];

                    if (attribute.VR == VR.SQ)
                    {
                        for (int sequenceItemIndex = 1; sequenceItemIndex <= attribute.ItemCount; sequenceItemIndex++)
                        {
                            attribute.GetItem(sequenceItemIndex).MakeAscending(true);
                        }
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// </summary>
        /// <param name="sequenceAttribute1">-</param>
        /// <param name="sequenceAttribute2">-</param>
        /// <param name="level">-</param>
        private void AddSequenceAttributesContentComparison(Attribute sequenceAttribute1, Attribute sequenceAttribute2, int level)
        {
            int maxItemCount = Math.Max(sequenceAttribute1.ItemCount, sequenceAttribute2.ItemCount);

            for (int itemIndex = 1; itemIndex <= maxItemCount; itemIndex++)
            {
                //
                // Get the two sequence items to compare. If one sequence item doesn't
                // exist for the itemIndex, use an empty sequence item.
                //

                SequenceItem sequenceItem1        = null;
                SequenceItem sequenceItem2        = null;
                bool         sequenceItem1Present = true;
                bool         sequenceItem2Present = true;


                if (itemIndex <= sequenceAttribute1.ItemCount)
                {
                    sequenceItem1        = sequenceAttribute1.GetItem(itemIndex);
                    sequenceItem1Present = true;
                }
                else
                {
                    sequenceItem1        = new SequenceItem();
                    sequenceItem1Present = false;
                }

                if (itemIndex <= sequenceAttribute2.ItemCount)
                {
                    sequenceItem2        = sequenceAttribute2.GetItem(itemIndex);
                    sequenceItem2Present = true;
                }
                else
                {
                    sequenceItem2        = new SequenceItem();
                    sequenceItem2Present = false;
                }


                //
                // Write the BEGIN ITEM row, compare the two sequence items and write the END ITEM row.
                //

                AddBeginOrEndSequenceItem(sequenceItem1Present, sequenceItem2Present, itemIndex, level + 1, true);

                AddAttributeSetsComparison(sequenceItem1, sequenceItem2, level + 1);

                AddBeginOrEndSequenceItem(sequenceItem1Present, sequenceItem2Present, itemIndex, level + 1, false);


                //
                // Update the differences count.
                //

                if ((!sequenceItem1Present) || (!sequenceItem2Present))
                {
                    this.differencesCount++;
                }
            }
        }
Пример #8
0
        private void AddSequenceAttributesContentInformation(DicomAttributesToValidate dicomAttributesToValidate, int oneBasedLevel)
        {
            //
            // Determine the maximum amount of sequence items for all supplied sequence attributes.
            //

            int maxItemCount = dicomAttributesToValidate.MaxItemCount;


            //
            // Fill the table with the information.
            //

            for (int itemIndex = 1; itemIndex <= maxItemCount; itemIndex++)
            {
                //
                // Add begin item row.
                //

                NewRow();

                AddCommonInformationForBeginOrEndSequenceItems(oneBasedLevel, true, itemIndex);

                for (int attributeIndex = 0; attributeIndex < dicomAttributesToValidate.Count; attributeIndex++)
                {
                    AddAttributeInformationForBeginOrEndSequenceItem(dicomAttributesToValidate, attributeIndex, itemIndex, true);
                }


                //
                // Add the comparison of attributes within the sequence items.
                //

                ArrayList sequenceItemsToCompare              = new ArrayList();
                ArrayList compareFlagsForSequenceItems        = new ArrayList();
                ArrayList dicomAttributeFlagsForSequenceItems = new ArrayList();
                ArrayList displaySequenceItems = new ArrayList();

                for (int attributeSetsIndex = 0; attributeSetsIndex < dicomAttributesToValidate.Count; attributeSetsIndex++)
                {
                    DicomAttributeToValidate dicomAttributeToValidate = dicomAttributesToValidate[attributeSetsIndex] as DicomAttributeToValidate;
                    Attribute attribute = dicomAttributeToValidate.Attribute;

                    if (attribute is ValidAttribute)
                    {
                        if (attribute.VR == VR.SQ)
                        {
                            if ((dicomAttributeToValidate.ValidationRuleDicomAttribute.DicomAttributeFlags & DicomAttributeFlags.Include_sequence_items) == DicomAttributeFlags.Include_sequence_items)
                            {
                                if (attribute.ItemCount < itemIndex)
                                {
                                    // Add empty sequence item.
                                    sequenceItemsToCompare.Add(new SequenceItem());
                                }
                                else
                                {
                                    sequenceItemsToCompare.Add(attribute.GetItem(itemIndex));
                                }
                            }
                            else
                            {
                                // Add empty sequence item.
                                sequenceItemsToCompare.Add(new SequenceItem());
                            }
                        }
                        else
                        {
                            // Add empty sequence item.
                            sequenceItemsToCompare.Add(new SequenceItem());
                        }
                    }
                    else
                    {
                        // Add empty sequence item.
                        sequenceItemsToCompare.Add(new SequenceItem());
                    }

                    compareFlagsForSequenceItems.Add(dicomAttributeToValidate.ValidationRuleDicomAttribute.CompareFlags);
                    dicomAttributeFlagsForSequenceItems.Add(dicomAttributeToValidate.ValidationRuleDicomAttribute.DicomAttributeFlags & DicomAttributeFlags.Include_sequence_items);

                    if (dicomAttributeToValidate.Display)
                    {
                        displaySequenceItems.Add(true);
                    }
                    else
                    {
                        displaySequenceItems.Add(false);
                    }
                }

                AddAttributeSetsInformationUsingStaticCompare(sequenceItemsToCompare, compareFlagsForSequenceItems, dicomAttributeFlagsForSequenceItems, displaySequenceItems);


                //
                // Add end item row.
                //

                NewRow();

                AddCommonInformationForBeginOrEndSequenceItems(oneBasedLevel, false, itemIndex);

                for (int attributeIndex = 0; attributeIndex < dicomAttributesToValidate.Count; attributeIndex++)
                {
                    AddAttributeInformationForBeginOrEndSequenceItem(dicomAttributesToValidate, attributeIndex, itemIndex, false);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// </summary>
        /// <param name="sequenceAttribute1">-</param>
        /// <param name="sequenceAttribute2">-</param>
        /// <param name="level">-</param>
        private void AddSequenceAttributesContentComparison(Attribute sequenceAttribute1, Attribute sequenceAttribute2, int level)
        {
            int maxItemCount = Math.Max(sequenceAttribute1.ItemCount, sequenceAttribute2.ItemCount);

            for (int itemIndex = 1; itemIndex <= maxItemCount; itemIndex++)
            {
                //
                // Get the two sequence items to compare. If one sequence item doesn't
                // exist for the itemIndex, use an empty sequence item.
                //

                SequenceItem sequenceItem1 = null;
                SequenceItem sequenceItem2 = null;
                bool sequenceItem1Present = true;
                bool sequenceItem2Present = true;

                if (itemIndex <= sequenceAttribute1.ItemCount)
                {
                    sequenceItem1 = sequenceAttribute1.GetItem(itemIndex);
                    sequenceItem1Present = true;
                }
                else
                {
                    sequenceItem1 = new SequenceItem();
                    sequenceItem1Present = false;
                }

                if (itemIndex <= sequenceAttribute2.ItemCount)
                {
                    sequenceItem2 = sequenceAttribute2.GetItem(itemIndex);
                    sequenceItem2Present = true;
                }
                else
                {
                    sequenceItem2 = new SequenceItem();
                    sequenceItem2Present = false;
                }

                //
                // Write the BEGIN ITEM row, compare the two sequence items and write the END ITEM row.
                //

                AddBeginOrEndSequenceItem(sequenceItem1Present, sequenceItem2Present, itemIndex, level + 1, true);

                AddAttributeSetsComparison(sequenceItem1, sequenceItem2, level + 1);

                AddBeginOrEndSequenceItem(sequenceItem1Present, sequenceItem2Present, itemIndex, level + 1, false);

                //
                // Update the differences count.
                //

                if ((!sequenceItem1Present) || (!sequenceItem2Present))
                {
                    this.differencesCount++;
                }
            }
        }