Example #1
0
        private void AddSequenceItemRow(AttributeList attributeList, int itemIndex, bool isBeginItem)
        {
            NewRow();


            //
            // Common cells.
            //

            if (this.displayCommonTag)
            {
                SetTagCellForDicomBeginOrEndSequenceItem(attributeList.LeadingDicomAttribute, itemIndex, isBeginItem, this.columnIndexCommonTag);
            }

            if (this.displayCommonName)
            {
                SetNameCellForDicomBeginOrEndSequenceItem(attributeList.LeadingDicomAttribute, itemIndex, isBeginItem, this.columnIndexCommonName);
            }


            //
            // Attribute specific cells.
            //

            for (int attributeIndex = 0; attributeIndex < attributeList.Count; attributeIndex++)
            {
                if (attributeList[attributeIndex] is DicomAttribute)
                {
                    DicomAttribute dicomAttribute = attributeList[attributeIndex] as DicomAttribute;

                    if ((dicomAttribute.ValidationRule.Flags & FlagsBase.Include_sequence_items) == FlagsBase.Include_sequence_items)
                    {
                        if (this.displayAttributeTag)
                        {
                            int columnIndex = (int)this.columnIndexAttributeTag[attributeIndex];

                            SetTagCellForDicomBeginOrEndSequenceItem(dicomAttribute, itemIndex, isBeginItem, columnIndex);
                        }

                        if (this.displayAttributeName)
                        {
                            int columnIndex = (int)this.columnIndexAttributeName[attributeIndex];

                            SetNameCellForDicomBeginOrEndSequenceItem(dicomAttribute, itemIndex, isBeginItem, columnIndex);
                        }

                        if (this.displayAttributePresent)
                        {
                            SetPresentCellForDicomBeginOrEndSequenceItem(attributeList, attributeIndex, itemIndex, isBeginItem);
                        }
                    }
                }
            }
        }
Example #2
0
        private void SetTagCellForHl7Attribute(AttributeList attributeList, int zeroBasedIndex)
        {
            int columnIndex = (int)this.columnIndexAttributeTag[zeroBasedIndex];

            Hl7Attribute hl7Attribute = attributeList[zeroBasedIndex] as Hl7Attribute;

            Dvtk.Hl7.Hl7Tag hl7Tag = hl7Attribute.ValidationRuleHl7Attribute.Hl7Tag;

            SetCellOK(columnIndex, hl7Tag.SegmentId.Id + "-" + hl7Tag.FieldIndex.ToString());

            if (this.displayFlags)
            {
                SetCellOK(columnIndex, "<br><i>Flags:</i>");
                SetCellOK(columnIndex, "<i>" + hl7Attribute.ValidationRule.FlagsString + "</i>");
            }
        }
Example #3
0
        // Precondition: DicomAttribute.
        private void SetPresentCellForDicomBeginOrEndSequenceItem(AttributeList attributeList, int zeroBasedAttributesIndex, int sequenceItemIndex, bool isBeginItem)
        {
            int columnIndex = (int)this.columnIndexAttributePresent[zeroBasedAttributesIndex];

            DicomAttribute dicomAttribute = attributeList[zeroBasedAttributesIndex] as DicomAttribute;

            String presentText = "";

            if (dicomAttribute.IsPresent)
            {
                if (dicomAttribute.AttributeOnly.VR == VR.SQ)
                {
                    if (sequenceItemIndex > dicomAttribute.AttributeOnly.ItemCount)
                    {
                        presentText = "-";
                    }
                    else
                    {
                        presentText = "+";
                    }
                }
                else
                {
                    presentText = "-";
                }
            }
            else
            {
                presentText = "-";
            }

            if (attributeList.DicomContainsCompareSequenceItemsErrors(sequenceItemIndex))
            {
                SetCellError(columnIndex, presentText);
            }
            else
            {
                SetCellOK(columnIndex, presentText);
            }
        }
Example #4
0
        public AttributeList GetNextAttributes(out TagSequence lowestTagSequence)
        {
            AttributeList nextAttributes = null;

            lowestTagSequence = DetermineLowestTagSequence();


            //
            // If unprocessed attributes still exist, create and fill the AttributeList to return.
            //

            if (lowestTagSequence != null)
            // Still attributes to process.
            {
                nextAttributes = DetermineNextAttributes(lowestTagSequence);
            }
            else
            // No more attributes left to process.
            {
                nextAttributes = null;
            }

            return(nextAttributes);
        }
Example #5
0
        private void AddSequenceItemRow(AttributeList attributeList, int itemIndex, bool isBeginItem)
        {
            NewRow();

            //
            // Common cells.
            //

            if (this.displayCommonTag)
            {
                SetTagCellForDicomBeginOrEndSequenceItem(attributeList.LeadingDicomAttribute, itemIndex, isBeginItem, this.columnIndexCommonTag);
            }

            if (this.displayCommonName)
            {
                SetNameCellForDicomBeginOrEndSequenceItem(attributeList.LeadingDicomAttribute, itemIndex, isBeginItem, this.columnIndexCommonName);
            }

            //
            // Attribute specific cells.
            //

            for (int attributeIndex = 0; attributeIndex < attributeList.Count; attributeIndex++)
            {
                if (attributeList[attributeIndex] is DicomAttribute)
                {
                    DicomAttribute dicomAttribute = attributeList[attributeIndex] as DicomAttribute;

                    if ((dicomAttribute.ValidationRule.Flags & FlagsBase.Include_sequence_items) == FlagsBase.Include_sequence_items)
                    {
                        if (this.displayAttributeTag)
                        {
                            int columnIndex = (int)this.columnIndexAttributeTag[attributeIndex];

                            SetTagCellForDicomBeginOrEndSequenceItem(dicomAttribute, itemIndex, isBeginItem, columnIndex);
                        }

                        if (this.displayAttributeName)
                        {
                            int columnIndex = (int)this.columnIndexAttributeName[attributeIndex];

                            SetNameCellForDicomBeginOrEndSequenceItem(dicomAttribute, itemIndex, isBeginItem, columnIndex);
                        }

                        if (this.displayAttributePresent)
                        {
                            SetPresentCellForDicomBeginOrEndSequenceItem(attributeList, attributeIndex, itemIndex, isBeginItem);
                        }
                    }
                }
            }
        }
Example #6
0
        private void AddSequenceAttributesContentInformation(AttributeList attributeList)
        {
            //
            // Determine the maximum amount of sequence items for all supplied sequence attributes
            // that have the include_sequence_items flag enabled.
            //

            int maxItemCount = attributeList.DicomMaxItemCount;

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

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

                AddSequenceItemRow(attributeList, itemIndex, true);

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

                AttributeCollections attributeCollections = new AttributeCollections();

                for (int attributeIndex = 0; attributeIndex < attributeList.Count; attributeIndex++)
                {
                    if (attributeList[attributeIndex] == null)
                    {
                        attributeCollections.AddNull();
                    }
                    else if (attributeList[attributeIndex] is Hl7Attribute)
                    {
                        attributeCollections.AddNull();
                    }
                    else if (attributeList[attributeIndex] is DicomAttribute)
                    {
                        DicomAttribute dicomAttribute = attributeList[attributeIndex] as DicomAttribute;

                        if ((dicomAttribute.ValidationRule.Flags & FlagsBase.Include_sequence_items) == FlagsBase.Include_sequence_items)
                        {
                            if (dicomAttribute.AttributeOnly is ValidAttribute)
                                // Attribute is valid attribute.
                            {
                                ValidAttribute validAttribute = dicomAttribute.AttributeOnly as ValidAttribute;

                                if (validAttribute.VR == VR.SQ)
                                    // Attribute is valid SQ attribute.
                                {
                                    if (validAttribute.ItemCount < itemIndex)
                                    {
                                        // Item index to high for actual item count.
                                        attributeCollections.Add(new DicomAttributeCollection(new SequenceItem(), dicomAttribute.ValidationRule.Flags));
                                    }
                                    else
                                        // Item exists.
                                    {
                                        attributeCollections.Add(new DicomAttributeCollection(validAttribute.GetItem(itemIndex), dicomAttribute.ValidationRule.Flags));
                                    }
                                }
                                else
                                    // Attribute is valid attribute but not a SQ attribute.
                                {
                                    attributeCollections.Add(new DicomAttributeCollection(new SequenceItem(), dicomAttribute.ValidationRule.Flags));
                                }
                            }
                            else
                                // Attribute does not exist.
                            {
                                attributeCollections.Add(new DicomAttributeCollection(new SequenceItem(), dicomAttribute.ValidationRule.Flags));
                            }
                        }
                        else
                            // Flags specify sequence items must not be included.
                        {
                            attributeCollections.AddNull();
                        }
                    }
                }

                AddAttributeCollectionsInformationUsingStaticDicomCompare(attributeCollections);

                //
                // Add end item row.
                //

                AddSequenceItemRow(attributeList, itemIndex, false);

            }
        }
Example #7
0
        private void AddAttributesInformation(AttributeList attributeList)
        {
            NewRow();

            //
            // Fill in the common information.
            //

            if (this.displayCommonTag)
            {
                SetTagCellForDicomAttribute(attributeList.LeadingDicomAttribute, this.columnIndexCommonTag);
            }

            if (this.displayCommonName)
            {
                SetNameCellForDicomAttribute(attributeList.LeadingDicomAttribute, this.columnIndexCommonName);
            }

            //
            // Fill in the information specific for each attribute.
            //

            for (int attributeIndex = 0; attributeIndex < attributeList.Count; attributeIndex++)
            {
                // Attribute Tag column.
                if (this.displayAttributeTag)
                {
                    if (attributeList[attributeIndex] is DicomAttribute)
                    {
                        DicomAttribute dicomAttribute = attributeList[attributeIndex] as DicomAttribute;

                        int columnIndex = (int)this.columnIndexAttributeTag[attributeIndex];

                        SetTagCellForDicomAttribute(dicomAttribute, columnIndex);
                    }
                    else if (attributeList[attributeIndex] is Hl7Attribute)
                    {
                        SetTagCellForHl7Attribute(attributeList, attributeIndex);
                    }
                }

                // Attribute Name column.
                if (this.displayAttributeName)
                {
                    if (attributeList[attributeIndex] is DicomAttribute)
                    {
                        DicomAttribute dicomAttribute = attributeList[attributeIndex] as DicomAttribute;

                        int columnIndex = (int)this.columnIndexAttributeName[attributeIndex];

                        SetNameCellForDicomAttribute(dicomAttribute, columnIndex);
                    }
                }

                // Attribute Present column.
                if (this.displayAttributePresent && (attributeList[attributeIndex] != null))
                {
                    SetPresentCellForAttribute(attributeList, attributeIndex);
                }

                // Attribute VR column.
                if (this.displayAttributeVR)
                {
                    if (attributeList[attributeIndex] is DicomAttribute)
                    {
                        SetVrCellForDicomAttribute(attributeList, attributeIndex);
                    }
                }

                // Attribute Values column.
                if (this.displayAttributeValues && (attributeList[attributeIndex] != null))
                {
                    SetValuesCellForAttribute(attributeList, attributeIndex);
                }
            }

            // Fill in the Comments.
            if (this.displayComments && (attributeList.CompareRule != null))
            {
                SetCommentsCell(attributeList.CompareRule);
            }

            //
            // If at least one attribute is a Dicom sequence attribute, do a comparison of the content.
            //

            if (attributeList.DicomContainsSequenceAttribute)
            {
                AddSequenceAttributesContentInformation(attributeList);
            }
        }
Example #8
0
        private void SetVrCellForDicomAttribute(AttributeList attributeList, int zeroBasedIndex)
        {
            int columnIndex = (int)this.columnIndexAttributeVR[zeroBasedIndex];

            DicomAttribute dicomAttribute = attributeList[zeroBasedIndex] as DicomAttribute;

            if (dicomAttribute.IsPresent)
            {
                bool containsError = false;

                if ((dicomAttribute.ValidationRule.Flags  & FlagsBase.Compare_VR) == FlagsBase.Compare_VR)
                {
                    if (attributeList.DicomContainsCompareVRErrors)
                    {
                        containsError = true;
                    }
                }

                if (containsError)
                {
                    SetCellError(columnIndex, dicomAttribute.AttributeOnly.VR.ToString());
                }
                else
                {
                    SetCellOK(columnIndex, dicomAttribute.AttributeOnly.VR.ToString());
                }
            }
        }
Example #9
0
        private void SetValuesCellForAttribute(AttributeList attributeList, int zeroBasedIndex)
        {
            int columnIndex = (int)this.columnIndexAttributeValues[zeroBasedIndex];

            AttributeBase attributebase = attributeList[zeroBasedIndex];

            if (attributebase.IsPresent)
            {
                bool isDicomSequenceAttribute = false;

                if (attributebase is DicomAttribute)
                {
                    if ((attributebase as DicomAttribute).AttributeOnly.VR == VR.SQ)
                    {
                        isDicomSequenceAttribute = true;
                    }
                }

                if (!isDicomSequenceAttribute)
                {
                    bool containsError = false;

                    String valuesString = attributebase.ValuesToString();

                    if ((attributebase.ValidationRule.Flags & FlagsBase.Compare_values) == FlagsBase.Compare_values)
                    {
                        if (attributeList.ContainsCompareValuesErrors)
                        {
                            containsError = true;
                        }
                    }

                    if ((attributebase.ValidationRule.Flags & FlagsBase.Values) == FlagsBase.Values)
                    {
                        if (valuesString.Length == 0)
                        {
                            containsError = true;
                        }
                    }

                    if ((attributebase.ValidationRule.Flags & FlagsBase.No_values) == FlagsBase.No_values)
                    {
                        if (valuesString.Length > 0)
                        {
                            containsError = true;
                        }
                    }

                    // If this is a Dicom attribute which is a group length, only compare when the compareGroupLength
                    // field is true.
                    if ((!this.displayGroupLength) && (attributebase is DicomAttribute))
                    {
                        DicomAttribute dicomAttribute = attributebase as DicomAttribute;

                        TagSequence tagSequence = new TagSequence(dicomAttribute.ValidationRuleDicomAttribute.TagSequenceString);

                        if (tagSequence.LastTag.ElementNumber == 0)
                        {
                            containsError = false;
                        }
                    }

                    // If the attribute contains no values, display this with the text "No values" in italic.
                    if (valuesString.Length == 0)
                    {
                        valuesString = "<i>No values</i>";
                    }

                    if (containsError)
                    {
                        SetCellError(columnIndex, valuesString);
                    }
                    else
                    {
                        SetCellOK(columnIndex, valuesString);
                    }
                }
                else
                    // Is Sequence attribute.
                {
                    if ((attributebase.ValidationRule.Flags & FlagsBase.Include_sequence_items) == 0)
                        // If sequence item will not be displayed.
                    {
                        SetCellOK(columnIndex, "<i>Items will not be displayed.</i>");
                    }
                }
            }
        }
Example #10
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);
        }
Example #11
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);
        }
Example #12
0
        private void AddAttributesInformation(AttributeList attributeList)
        {
            NewRow();


            //
            // Fill in the common information.
            //

            if (this.displayCommonTag)
            {
                SetTagCellForDicomAttribute(attributeList.LeadingDicomAttribute, this.columnIndexCommonTag);
            }

            if (this.displayCommonName)
            {
                SetNameCellForDicomAttribute(attributeList.LeadingDicomAttribute, this.columnIndexCommonName);
            }


            //
            // Fill in the information specific for each attribute.
            //

            for (int attributeIndex = 0; attributeIndex < attributeList.Count; attributeIndex++)
            {
                // Attribute Tag column.
                if (this.displayAttributeTag)
                {
                    if (attributeList[attributeIndex] is DicomAttribute)
                    {
                        DicomAttribute dicomAttribute = attributeList[attributeIndex] as DicomAttribute;

                        int columnIndex = (int)this.columnIndexAttributeTag[attributeIndex];

                        SetTagCellForDicomAttribute(dicomAttribute, columnIndex);
                    }
                    else if (attributeList[attributeIndex] is Hl7Attribute)
                    {
                        SetTagCellForHl7Attribute(attributeList, attributeIndex);
                    }
                }

                // Attribute Name column.
                if (this.displayAttributeName)
                {
                    if (attributeList[attributeIndex] is DicomAttribute)
                    {
                        DicomAttribute dicomAttribute = attributeList[attributeIndex] as DicomAttribute;

                        int columnIndex = (int)this.columnIndexAttributeName[attributeIndex];

                        SetNameCellForDicomAttribute(dicomAttribute, columnIndex);
                    }
                }

                // Attribute Present column.
                if (this.displayAttributePresent && (attributeList[attributeIndex] != null))
                {
                    SetPresentCellForAttribute(attributeList, attributeIndex);
                }

                // Attribute VR column.
                if (this.displayAttributeVR)
                {
                    if (attributeList[attributeIndex] is DicomAttribute)
                    {
                        SetVrCellForDicomAttribute(attributeList, attributeIndex);
                    }
                }

                // Attribute Values column.
                if (this.displayAttributeValues && (attributeList[attributeIndex] != null))
                {
                    SetValuesCellForAttribute(attributeList, attributeIndex);
                }
            }


            // Fill in the Comments.
            if (this.displayComments && (attributeList.CompareRule != null))
            {
                SetCommentsCell(attributeList.CompareRule);
            }


            //
            // If at least one attribute is a Dicom sequence attribute, do a comparison of the content.
            //

            if (attributeList.DicomContainsSequenceAttribute)
            {
                AddSequenceAttributesContentInformation(attributeList);
            }
        }
Example #13
0
        private void SetValuesCellForAttribute(AttributeList attributeList, int zeroBasedIndex)
        {
            int columnIndex = (int)this.columnIndexAttributeValues[zeroBasedIndex];

            AttributeBase attributebase = attributeList[zeroBasedIndex];

            if (attributebase.IsPresent)
            {
                bool isDicomSequenceAttribute = false;

                if (attributebase is DicomAttribute)
                {
                    if ((attributebase as DicomAttribute).AttributeOnly.VR == VR.SQ)
                    {
                        isDicomSequenceAttribute = true;
                    }
                }

                if (!isDicomSequenceAttribute)
                {
                    bool containsError = false;

                    String valuesString = attributebase.ValuesToString();

                    if ((attributebase.ValidationRule.Flags & FlagsBase.Compare_values) == FlagsBase.Compare_values)
                    {
                        if (attributeList.ContainsCompareValuesErrors)
                        {
                            containsError = true;
                        }
                    }

                    if ((attributebase.ValidationRule.Flags & FlagsBase.Values) == FlagsBase.Values)
                    {
                        if (valuesString.Length == 0)
                        {
                            containsError = true;
                        }
                    }

                    if ((attributebase.ValidationRule.Flags & FlagsBase.No_values) == FlagsBase.No_values)
                    {
                        if (valuesString.Length > 0)
                        {
                            containsError = true;
                        }
                    }

                    // If this is a Dicom attribute which is a group length, only compare when the compareGroupLength
                    // field is true.
                    if ((!this.displayGroupLength) && (attributebase is DicomAttribute))
                    {
                        DicomAttribute dicomAttribute = attributebase as DicomAttribute;

                        TagSequence tagSequence = new TagSequence(dicomAttribute.ValidationRuleDicomAttribute.TagSequenceString);

                        if (tagSequence.LastTag.ElementNumber == 0)
                        {
                            containsError = false;
                        }
                    }

                    // If the attribute contains no values, display this with the text "No values" in italic.
                    if (valuesString.Length == 0)
                    {
                        valuesString = "<i>No values</i>";
                    }

                    if (containsError)
                    {
                        SetCellError(columnIndex, valuesString);
                    }
                    else
                    {
                        SetCellOK(columnIndex, valuesString);
                    }
                }
                else
                // Is Sequence attribute.
                {
                    if ((attributebase.ValidationRule.Flags & FlagsBase.Include_sequence_items) == 0)
                    // If sequence item will not be displayed.
                    {
                        SetCellOK(columnIndex, "<i>Items will not be displayed.</i>");
                    }
                }
            }
        }
Example #14
0
        private void SetPresentCellForAttribute(AttributeList attributeList, int zeroBasedIndex)
        {
            int columnIndex = (int)this.columnIndexAttributePresent[zeroBasedIndex];

            AttributeBase attributebase = attributeList[zeroBasedIndex];

            if (attributebase != null)
            {
                String presentString = "";
                bool   containsError = false;

                if (attributebase.IsPresent)
                {
                    presentString = "+";
                }
                else
                {
                    presentString = "-";
                }

                if ((attributebase.ValidationRule.Flags & FlagsBase.Compare_present) == FlagsBase.Compare_present)
                {
                    if (attributeList.ContainsComparePresentErrors)
                    {
                        containsError = true;
                    }
                }

                if ((attributebase.ValidationRule.Flags & FlagsBase.Present) == FlagsBase.Present)
                {
                    if (!attributebase.IsPresent)
                    {
                        containsError = true;
                    }
                }

                if ((attributebase.ValidationRule.Flags & FlagsBase.Not_present) == FlagsBase.Not_present)
                {
                    if (attributebase.IsPresent)
                    {
                        containsError = true;
                    }
                }

                // If this is a Dicom attribute which is a group length, only compare when the compareGroupLength
                // field is true.
                if ((!this.displayGroupLength) && (attributebase is DicomAttribute))
                {
                    DicomAttribute dicomAttribute = attributebase as DicomAttribute;

                    TagSequence tagSequence = new TagSequence(dicomAttribute.ValidationRuleDicomAttribute.TagSequenceString);

                    if (tagSequence.LastTag.ElementNumber == 0)
                    {
                        containsError = false;
                    }
                }

                if (containsError)
                {
                    SetCellError(columnIndex, presentString);
                }
                else
                {
                    SetCellOK(columnIndex, presentString);
                }
            }
        }
Example #15
0
        private void AddSequenceAttributesContentInformation(AttributeList attributeList)
        {
            //
            // Determine the maximum amount of sequence items for all supplied sequence attributes
            // that have the include_sequence_items flag enabled.
            //

            int maxItemCount = attributeList.DicomMaxItemCount;


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

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

                AddSequenceItemRow(attributeList, itemIndex, true);


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

                AttributeCollections attributeCollections = new AttributeCollections();

                for (int attributeIndex = 0; attributeIndex < attributeList.Count; attributeIndex++)
                {
                    if (attributeList[attributeIndex] == null)
                    {
                        attributeCollections.AddNull();
                    }
                    else if (attributeList[attributeIndex] is Hl7Attribute)
                    {
                        attributeCollections.AddNull();
                    }
                    else if (attributeList[attributeIndex] is DicomAttribute)
                    {
                        DicomAttribute dicomAttribute = attributeList[attributeIndex] as DicomAttribute;

                        if ((dicomAttribute.ValidationRule.Flags & FlagsBase.Include_sequence_items) == FlagsBase.Include_sequence_items)
                        {
                            if (dicomAttribute.AttributeOnly is ValidAttribute)
                            // Attribute is valid attribute.
                            {
                                ValidAttribute validAttribute = dicomAttribute.AttributeOnly as ValidAttribute;

                                if (validAttribute.VR == VR.SQ)
                                // Attribute is valid SQ attribute.
                                {
                                    if (validAttribute.ItemCount < itemIndex)
                                    {
                                        // Item index to high for actual item count.
                                        attributeCollections.Add(new DicomAttributeCollection(new SequenceItem(), dicomAttribute.ValidationRule.Flags));
                                    }
                                    else
                                    // Item exists.
                                    {
                                        attributeCollections.Add(new DicomAttributeCollection(validAttribute.GetItem(itemIndex), dicomAttribute.ValidationRule.Flags));
                                    }
                                }
                                else
                                // Attribute is valid attribute but not a SQ attribute.
                                {
                                    attributeCollections.Add(new DicomAttributeCollection(new SequenceItem(), dicomAttribute.ValidationRule.Flags));
                                }
                            }
                            else
                            // Attribute does not exist.
                            {
                                attributeCollections.Add(new DicomAttributeCollection(new SequenceItem(), dicomAttribute.ValidationRule.Flags));
                            }
                        }
                        else
                        // Flags specify sequence items must not be included.
                        {
                            attributeCollections.AddNull();
                        }
                    }
                }

                AddAttributeCollectionsInformationUsingStaticDicomCompare(attributeCollections);


                //
                // Add end item row.
                //

                AddSequenceItemRow(attributeList, itemIndex, false);
            }
        }
Example #16
0
        private void SetPresentCellForAttribute(AttributeList attributeList, int zeroBasedIndex)
        {
            int columnIndex = (int)this.columnIndexAttributePresent[zeroBasedIndex];

            AttributeBase attributebase = attributeList[zeroBasedIndex];

            if (attributebase != null)
            {
                String presentString = "";
                bool containsError = false;

                if (attributebase.IsPresent)
                {
                    presentString = "+";
                }
                else
                {
                    presentString = "-";
                }

                if ((attributebase.ValidationRule.Flags & FlagsBase.Compare_present) == FlagsBase.Compare_present)
                {
                    if (attributeList.ContainsComparePresentErrors)
                    {
                        containsError = true;
                    }
                }

                if ((attributebase.ValidationRule.Flags & FlagsBase.Present) == FlagsBase.Present)
                {
                    if (!attributebase.IsPresent)
                    {
                        containsError = true;
                    }
                }

                if ((attributebase.ValidationRule.Flags & FlagsBase.Not_present) == FlagsBase.Not_present)
                {
                    if (attributebase.IsPresent)
                    {
                        containsError = true;
                    }
                }

                // If this is a Dicom attribute which is a group length, only compare when the compareGroupLength
                // field is true.
                if ((!this.displayGroupLength) && (attributebase is DicomAttribute))
                {
                    DicomAttribute dicomAttribute = attributebase as DicomAttribute;

                    TagSequence tagSequence = new TagSequence(dicomAttribute.ValidationRuleDicomAttribute.TagSequenceString);

                    if (tagSequence.LastTag.ElementNumber == 0)
                    {
                        containsError = false;
                    }
                }

                if (containsError)
                {
                    SetCellError(columnIndex, presentString);
                }
                else
                {
                    SetCellOK(columnIndex, presentString);
                }
            }
        }
Example #17
0
        // Precondition: DicomAttribute.
        private void SetPresentCellForDicomBeginOrEndSequenceItem(AttributeList attributeList, int zeroBasedAttributesIndex, int sequenceItemIndex, bool isBeginItem)
        {
            int columnIndex = (int)this.columnIndexAttributePresent[zeroBasedAttributesIndex];

            DicomAttribute dicomAttribute = attributeList[zeroBasedAttributesIndex] as DicomAttribute;

            String presentText = "";

            if (dicomAttribute.IsPresent)
            {
                if (dicomAttribute.AttributeOnly.VR == VR.SQ)
                {
                    if (sequenceItemIndex > dicomAttribute.AttributeOnly.ItemCount)
                    {
                        presentText = "-";
                    }
                    else
                    {
                        presentText = "+";
                    }
                }
                else
                {
                    presentText = "-";
                }
            }
            else
            {
                presentText = "-";
            }

            if (attributeList.DicomContainsCompareSequenceItemsErrors(sequenceItemIndex))
            {
                SetCellError(columnIndex, presentText);
            }
            else
            {
                SetCellOK(columnIndex, presentText);
            }
        }
Example #18
0
        private void SetTagCellForHl7Attribute(AttributeList attributeList, int zeroBasedIndex)
        {
            int columnIndex = (int)this.columnIndexAttributeTag[zeroBasedIndex];

            Hl7Attribute hl7Attribute = attributeList[zeroBasedIndex] as Hl7Attribute;

            Dvtk.Hl7.Hl7Tag hl7Tag = hl7Attribute.ValidationRuleHl7Attribute.Hl7Tag;

            SetCellOK(columnIndex, hl7Tag.SegmentId.Id + "-" + hl7Tag.FieldIndex.ToString());

            if (this.displayFlags)
            {
                SetCellOK(columnIndex, "<br><i>Flags:</i>");
                SetCellOK(columnIndex, "<i>" + hl7Attribute.ValidationRule.FlagsString + "</i>");
            }
        }
        //
        // - 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);
        }
Example #20
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);
        }