Esempio n. 1
0
        //
        // - Methods -
        //

        /// <summary>
        /// Add a CompareRule the this object.
        /// <br></br><br></br>
        /// A check is performed if the compareRule is compatible with earlier added one.
        /// If it is not compatible, an exception is thrown.
        /// </summary>
        /// <param name="compareRule">The CompareRule instance to add.</param>
        public void Add(CompareRule compareRule)
        {
            if (compareRule.Count != this.typeOfAttributes.Length)
            {
                throw new System.ArgumentException("Number of validation rules in supplied CompareRule differs from number of supplied attribute types in the constructor.");
            }

            for (int index = 0; index < this.typeOfAttributes.Length; index++)
            {
                if (compareRule[index] != null)
                {
                    if (this.typeOfAttributes[index] == AttributeTypes.DicomAttribute)
                    {
                        if (compareRule[index].GetType().Name != "ValidationRuleDicomAttribute")
                        {
                            throw new System.ArgumentException("Validation rule in compare rule should be of type ValidationRuleDicomAttribute.");
                        }
                    }
                    else if (this.typeOfAttributes[index] == AttributeTypes.Hl7Attribute)
                    {
                        if (compareRule[index].GetType().Name != "ValidationRuleHl7Attribute")
                        {
                            throw new System.ArgumentException("Validation rule in compare rule should be of type ValidationRuleHl7Attribute.");
                        }
                    }
                    else
                    {
                        throw new System.Exception("Not supposed to get here.");
                    }
                }
            }

            this.compareRules.Add(compareRule);
        }
Esempio n. 2
0
        /// <summary>
        /// Clone this CompareRule instance.
        /// </summary>
        /// <returns>The cloned CompareRule instance.</returns>
        internal CompareRule Clone()
        {
            CompareRule clonedCompareRule = new CompareRule();

            clonedCompareRule.validationRules = this.validationRules.Clone() as ArrayList;

            return(clonedCompareRule);
        }
Esempio n. 3
0
        private void SetCommentsCell(CompareRule compareRule)
        {
            if (compareRule.ConditionText.Length > 0)
            {
                SetCellOK(this.columnIndexComments, "<i><b><font color=\"#6699cc\">" + compareRule.ConditionText + "</font></b></i>");
            }

            if (this.displayCompareValueType && this.displayAttributeValues)
            {
                SetCellOK(this.columnIndexComments, "<i>" + "Compare value type: " + compareRule.CompareValueType.ToString() + "</i>");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Clone this CompareRule instance.
        /// </summary>
        /// <returns>The cloned CompareRule instance.</returns>
        internal CompareRule Clone()
        {
            CompareRule clonedCompareRule = new CompareRule();
            clonedCompareRule.validationRules = this.validationRules.Clone() as ArrayList;

            return(clonedCompareRule);
        }
Esempio n. 5
0
        private void SetCommentsCell(CompareRule compareRule)
        {
            if (compareRule.ConditionText.Length > 0)
            {
                SetCellOK(this.columnIndexComments, "<i><b><font color=\"#6699cc\">" + compareRule.ConditionText + "</font></b></i>");
            }

            if (this.displayCompareValueType && this.displayAttributeValues)
            {
                SetCellOK(this.columnIndexComments, "<i>" + "Compare value type: " + compareRule.CompareValueType.ToString() + "</i>");
            }
        }
Esempio n. 6
0
 public void TearDown()
 {
     this.compareRule = null;
 }
Esempio n. 7
0
 public void SetUp()
 {
     this.compareRule = new CompareRule();
 }
Esempio n. 8
0
        /// <summary>
        /// Get the next list 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 compare.</returns>



        public AttributeList GetNextAttributes()
        {
            AttributeList nextAttributes = null;

            if (this.compareRulesIndex >= this.compareRules.Count)
            {
                nextAttributes = null;
            }
            else
            {
                nextAttributes = new AttributeList();

                CompareRule compareRule = this.compareRules[this.compareRulesIndex] as CompareRule;

                nextAttributes.CompareRule = compareRule;

                // Use the attributeCollectionsIndex to iterate through both the attributeCollections and compareRule.
                for (int validationRuleListIndex = 0; validationRuleListIndex < compareRule.Count; validationRuleListIndex++)
                {
                    ValidationRuleBase validationRule = compareRule[validationRuleListIndex];

                    if (validationRule is ValidationRuleDicomAttribute)
                    {
                        ValidationRuleDicomAttribute validationRuleDicomAttribute = validationRule as ValidationRuleDicomAttribute;
                        DicomAttributeCollection     dicomAttributeCollection     = this.attributeCollections[validationRuleListIndex] as DicomAttributeCollection;

                        DicomAttribute dicomAttribute = null;

                        if (validationRuleDicomAttribute == null)
                        // If nothing needs to be validated.
                        {
                            dicomAttribute = null;
                        }
                        else
                        {
                            DvtkHighLevelInterface.Dicom.Other.Attribute dicomAttributeOnly = null;

                            if (dicomAttributeCollection.AttributeSetOnly.Exists(validationRuleDicomAttribute.TagSequenceString))
                            {
                                dicomAttributeOnly = dicomAttributeCollection.AttributeSetOnly[validationRuleDicomAttribute.TagSequenceString];
                            }
                            else
                            {
                                dicomAttributeOnly = new InvalidAttribute();
                            }

                            // Merge the validation flags from the validation rule and the attribute collection.
                            ValidationRuleDicomAttribute mergedValidationRuleDicomAttribute = new ValidationRuleDicomAttribute(validationRuleDicomAttribute.TagSequenceString, validationRuleDicomAttribute.Flags | dicomAttributeCollection.Flags);

                            dicomAttribute = new DicomAttribute(dicomAttributeOnly, mergedValidationRuleDicomAttribute);

                            dicomAttribute.DisplayFullTagSequence = true;
                        }

                        nextAttributes.Add(dicomAttribute);
                    }
                    else if (validationRule is ValidationRuleHl7Attribute)
                    {
                        ValidationRuleHl7Attribute validationRuleHl7Attribute = validationRule as ValidationRuleHl7Attribute;
                        Hl7AttributeCollection     hl7AttributeCollection     = this.attributeCollections[validationRuleListIndex] as Hl7AttributeCollection;

                        Hl7Attribute hl7Attribute = null;

                        if (validationRuleHl7Attribute == null)
                        // If nothing needs to be validated.
                        {
                            hl7Attribute = null;
                        }
                        else
                        {
                            // Merge the validation flags from the validation rule and the attribute collection.
                            ValidationRuleHl7Attribute mergedValidationRuleHl7Attribute = new ValidationRuleHl7Attribute(validationRuleHl7Attribute.Hl7Tag, validationRuleHl7Attribute.Flags | hl7AttributeCollection.Flags);

                            hl7Attribute = new Hl7Attribute(hl7AttributeCollection.Hl7MessageOnly.Value(validationRuleHl7Attribute.Hl7Tag), mergedValidationRuleHl7Attribute);
                        }

                        nextAttributes.Add(hl7Attribute);
                    }
                    else
                    {
                        nextAttributes.Add(null);
                    }
                }

                this.compareRulesIndex++;
            }

            return(nextAttributes);
        }
Esempio n. 9
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. 10
0
 public void TearDown()
 {
     this.compareRule = null;
 }
Esempio n. 11
0
 public void SetUp()
 {
     this.compareRule = new CompareRule();
 }
Esempio n. 12
0
        //
        // - Methods -
        //
        /// <summary>
        /// Add a CompareRule the this object.
        /// <br></br><br></br>
        /// A check is performed if the compareRule is compatible with earlier added one.
        /// If it is not compatible, an exception is thrown.
        /// </summary>
        /// <param name="compareRule">The CompareRule instance to add.</param>
        public void Add(CompareRule compareRule)
        {
            if (compareRule.Count != this.typeOfAttributes.Length)
            {
                throw new System.ArgumentException("Number of validation rules in supplied CompareRule differs from number of supplied attribute types in the constructor.");
            }

            for (int index = 0; index < this.typeOfAttributes.Length; index++)
            {
                if (compareRule[index] != null)
                {
                    if (this.typeOfAttributes[index] == AttributeTypes.DicomAttribute)
                    {
                        if (compareRule[index].GetType().Name != "ValidationRuleDicomAttribute")
                        {
                            throw new System.ArgumentException("Validation rule in compare rule should be of type ValidationRuleDicomAttribute.");
                        }
                    }
                    else if (this.typeOfAttributes[index] == AttributeTypes.Hl7Attribute)
                    {
                        if (compareRule[index].GetType().Name != "ValidationRuleHl7Attribute")
                        {
                            throw new System.ArgumentException("Validation rule in compare rule should be of type ValidationRuleHl7Attribute.");
                        }
                    }
                    else
                    {
                        throw new System.Exception("Not supposed to get here.");
                    }
                }
            }

            this.compareRules.Add(compareRule);
        }