Esempio n. 1
0
        /// <summary>
        /// Make all DICOM attributes within a DICOM attribute sets ascending.
        /// </summary>
        public void DicomMakeAscending()
        {
            for (int index = 0; index < Count; index++)
            {
                AttributeCollectionBase attributeCollection = this[index] as DicomAttributeCollection;

                if (attributeCollection != null)
                {
                    if (attributeCollection is DicomAttributeCollection)
                    {
                        (attributeCollection as DicomAttributeCollection).AttributeSetOnly.MakeAscending(true);
                    }
                }
            }
        }
Esempio n. 2
0
        private TagSequence DetermineLowestTagSequence()
        {
            TagSequence lowestTagSequence = null;             // Lowest in this context means lowest LastTag.

            //
            // Determine what the lowest tag is.
            // If no more attribute exists anymore to process, this tag will be null.
            //

            for (int index = 0; index < this.attributeCollections.Count; index++)
            {
                int attributeSetIndex = (int)this.currentAttributeIndices[index];
                AttributeCollectionBase attributeCollectionBase = this.attributeCollections[index];

                if (attributeCollectionBase is DicomAttributeCollection)
                {
                    DicomAttributeCollection dicomAttributeCollection = attributeCollectionBase as DicomAttributeCollection;

                    if (attributeSetIndex < dicomAttributeCollection.AttributeSetOnly.Count)
                    // Still unprocessed attributes left in this dataset.
                    {
                        ValidAttribute attributeOnly = dicomAttributeCollection.AttributeSetOnly[attributeSetIndex] as ValidAttribute;

                        if (lowestTagSequence == null)
                        {
                            lowestTagSequence = attributeOnly.TagSequence;
                        }
                        else
                        {
                            if (attributeOnly.TagSequence.LastTag.AsUInt32 < lowestTagSequence.LastTag.AsUInt32)
                            {
                                lowestTagSequence = attributeOnly.TagSequence;
                            }
                        }
                    }
                }
            }

            return(lowestTagSequence);
        }
Esempio n. 3
0
        //
        // - Methods -
        //

        /// <summary>
        /// Get the next collection of attributes to compare to each other.
        /// If an attribute is not present, a null pointer is returned in the AttributeCollection.
        /// If all attributes have been compared, null is returned.
        /// </summary>
        /// <returns>The attributes to validate.</returns>
        ///



        private AttributeList DetermineNextAttributes(TagSequence lowestTagSequence)
        {
            AttributeList nextAttributes = new AttributeList();

            nextAttributes.CompareRule = new CompareRule();

            for (int index = 0; index < this.attributeCollections.Count; index++)
            {
                int attributeSetIndex = (int)this.currentAttributeIndices[index];
                AttributeCollectionBase attributeCollectionBase = this.attributeCollections[index];

                if (attributeCollectionBase == null)
                {
                    nextAttributes.Add(null);
                    nextAttributes.CompareRule.Add(null);
                }
                else if (attributeCollectionBase is Hl7AttributeCollection)
                {
                    nextAttributes.Add(null);
                    nextAttributes.CompareRule.Add(null);
                }
                else if (attributeCollectionBase is DicomAttributeCollection)
                {
                    DicomAttributeCollection dicomAttributeCollection = attributeCollectionBase as DicomAttributeCollection;

                    if (attributeSetIndex < dicomAttributeCollection.AttributeSetOnly.Count)
                    // Still unprocessed attributes left in this dataset.
                    {
                        ValidAttribute attributeOnly = dicomAttributeCollection.AttributeSetOnly[attributeSetIndex] as ValidAttribute;

                        if (attributeOnly.TagSequence.LastTag.AsUInt32 == lowestTagSequence.LastTag.AsUInt32)
                        {
                            // Add entry with existing attribute.
                            ValidationRuleDicomAttribute validationRuleDicomAttribute = new ValidationRuleDicomAttribute(lowestTagSequence.ToString(), dicomAttributeCollection.Flags);
                            nextAttributes.CompareRule.Add(validationRuleDicomAttribute);
                            DicomAttribute dicomAttribute = new DicomAttribute(attributeOnly, validationRuleDicomAttribute);
                            nextAttributes.Add(dicomAttribute);

                            // This attribute will be returned. Increase the attribute index.
                            this.currentAttributeIndices[index] = attributeSetIndex + 1;
                        }
                        else
                        {
                            // Add entry with non-existing attribute.
                            ValidationRuleDicomAttribute validationRuleDicomAttribute = new ValidationRuleDicomAttribute(lowestTagSequence.ToString(), dicomAttributeCollection.Flags);
                            DicomAttribute dicomAttribute = new DicomAttribute(new DvtkHighLevelInterface.Dicom.Other.InvalidAttribute(), validationRuleDicomAttribute);
                            nextAttributes.Add(dicomAttribute);
                        }
                    }
                    else
                    // No more unprocessed attributes left in this dataset.
                    {
                        // Add entry with non-existing attribute.
                        ValidationRuleDicomAttribute validationRuleDicomAttribute = new ValidationRuleDicomAttribute(lowestTagSequence.ToString(), dicomAttributeCollection.Flags);
                        DicomAttribute dicomAttribute = new DicomAttribute(new DvtkHighLevelInterface.Dicom.Other.InvalidAttribute(), validationRuleDicomAttribute);
                        nextAttributes.Add(dicomAttribute);
                    }
                }
            }

            return(nextAttributes);
        }
Esempio n. 4
0
        //
        // - Methods -
        //

        /// <summary>
        /// Do a dynamic compare for the attribute sets supplied.
        ///
        /// Note that the parameters attributeSets, attributeSetDescriptions and each compareRule instance in
        /// the parameter compareRules must have the same size and have a size at least 2.
        /// </summary>
        /// <param name="tableDescription">Description of the table.</param>
        /// <param name="attributeCollections">The attribute sets to compare with each other.</param>
        /// <param name="attributeCollectionDescriptions">The descriptions of the attribute sets.</param>
        /// <param name="compareRules">
        /// Specifies which attributes with what tags should be compared with each other.
        /// Also specifies how the attributes should be compared with each other.
        /// </param>
        /// <returns>The results of the dynamic compare presented as a table (that may be converted to HTML).</returns>
        public CompareResults CompareAttributeCollections(String tableDescription, AttributeCollections attributeCollections, StringCollection attributeCollectionDescriptions, CompareRules compareRules)
        {
            //
            // Sanity check.
            //

            if (attributeCollections.Count < 2)
            {
                throw new System.Exception("Parameter attributeSets supplied to the method StaticCompare.CompareAttributeSets has size smaller than 2.");
            }

            if (attributeCollections.Count != attributeCollectionDescriptions.Count)
            {
                throw new System.Exception("Parameters attributeSets and attributeSetDescriptions supplied to the method StaticCompare.CompareAttributeSets have different size.");
            }

            for (int index = 0; index < compareRules.Count; index++)
            {
                CompareRule compareRule = compareRules[index];

                if (attributeCollections.Count != compareRule.Count)
                {
                    throw new System.Exception("Method StaticCompare.CompareAttributeSets: each CompareRule instance present in the parameter compareRules must have the same size as the parameter attributeCollections.");
                }
            }



            // Todo change taking the possibility of null into account for the attribute collections.

            //
            // Remove the attribute collections that are null and adjust the compare rules.
            //

            for (int index = attributeCollections.Count - 1; index >= 0; index--)
            {
                AttributeCollectionBase attributeCollection = attributeCollections[index];

                if (attributeCollection == null)
                {
                    // Clone the collections because we don't want to change the supplied collections.
                    attributeCollections = attributeCollections.Clone();
                    attributeCollections.RemoveAt(index);

                    StringCollection newAttributeCollectionDescriptions = new StringCollection();
                    foreach (String description in attributeCollectionDescriptions)
                    {
                        newAttributeCollectionDescriptions.Add(description);
                    }
                    attributeCollectionDescriptions = newAttributeCollectionDescriptions;
                    attributeCollectionDescriptions.RemoveAt(index);

#pragma warning disable 0618
                    CompareRules newCompareRules = new CompareRules();
#pragma warning restore 0618

                    for (int compareRuleIndex = 0; compareRuleIndex < compareRules.Count; compareRuleIndex++)
                    {
                        CompareRule compareRule = compareRules[compareRuleIndex].Clone();
                        compareRule.RemoveAt(index);
                        newCompareRules.Add(compareRule);
                    }

                    compareRules = newCompareRules;
                }
            }



            //
            // Do the actual compare.
            //

            this.compareResults = null;

            // Determine the index of the different columns in the table.
            int numberOfColumns = DetermineColumnIndices(attributeCollections);

            // To be able to compare correctly, we first make sure the attributes in all DicomAttributeCollections are ascending.
            attributeCollections.DicomMakeAscending();

            // Determine the table headers and comlumn widths.
            this.compareResults = CreateCompareResults(numberOfColumns, attributeCollections, tableDescription, attributeCollectionDescriptions);

            // Do the actual comparison.
            AddAttributeCollectionsInformationUsingDynamicCompare(attributeCollections, compareRules);

            if (this.differenceFound)
            {
                this.compareResults.DifferencesCount++;
                this.differenceFound = false;
            }

            return(this.compareResults);
        }
Esempio n. 5
0
        //
        // - Methods -
        //

        internal void Add(AttributeCollectionBase attributeCollection)
        {
            this.attributeCollections.Add(attributeCollection);
        }
Esempio n. 6
0
 //
 // - Methods -
 //
 internal void Add(AttributeCollectionBase attributeCollection)
 {
     this.attributeCollections.Add(attributeCollection);
 }