Esempio n. 1
0
        /// <summary>
        /// Adds a single attribute with the tag sequence string, VR and values specified.
        /// </summary>
        /// <remarks>
        /// Depending on the group number of the last tag in the tag sequence string, the attribute
        /// is set in the CommandSet or DataSet of this instance.
        /// <br></br><br></br>
        /// If an attribute already exists with this tag sequence string, it is removed first before it is
        /// again set.
        /// <br></br><br></br>
        /// If sequence items (each with a sequence item index) are specified in the tag sequence string,
        /// empty sequence items will be added automatically to avoid gaps in the sequence items of sequence
        /// attributes.
        /// </remarks>
        /// <param name="tagSequenceString">The tag sequence string that uniquely identifies the attribute.</param>
        /// <param name="vR">The VR of the attribute.</param>
        /// <param name="parameters">
        /// The values of the attribute. Do not use the DICOM delimeter '\' directly. Instead use
        /// multiple parameter arguments for this method when adding a single attribute with multiple values.
        /// </param>
        public void Set(String tagSequenceString, VR vR, params Object[] parameters)
        {
            TagSequence tagSequence = new TagSequence(tagSequenceString);

            Set(tagSequence, vR, parameters);
        }
Esempio n. 2
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. 3
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);
                }
            }
        }
Esempio n. 4
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>");
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// </summary>
        /// <param name="dicomAttributesToValidate">-</param>
        /// <param name="zeroBasedIndex">-</param>
        private void AddAttributeInformationForAttribute(DicomAttributesToValidate dicomAttributesToValidate, int zeroBasedIndex)
        {
            bool isAttributePresent = false;
            DicomAttributeToValidate dicomAttributeToValidate = dicomAttributesToValidate[zeroBasedIndex] as DicomAttributeToValidate;
            CompareFlags             compareFlags             = dicomAttributeToValidate.ValidationRuleDicomAttribute.CompareFlags;
            DicomAttributeFlags      dicomAttributeFlags      = dicomAttributeToValidate.ValidationRuleDicomAttribute.DicomAttributeFlags;

            if (dicomAttributeToValidate.Attribute is ValidAttribute)
            {
                isAttributePresent = true;
            }
            else
            {
                isAttributePresent = false;
            }

            // Attribute Tag column.
            if (this.displayAttributeTag)
            {
                if (isAttributePresent)
                {
                    if (dicomAttributeToValidate.ValidationRuleDicomAttribute.DisplayFullTagSequence)
                    {
                        ArrayList tags = (dicomAttributeToValidate.Attribute as ValidAttribute).TagSequence.Tags;

                        for (int tagIndex = 0; tagIndex < tags.Count; tagIndex++)
                        {
                            Tag tag = tags[tagIndex] as Tag;
                            if (tag.ContainsIndex)
                            {
                                SetCellOK((int)this.columnIndexAttributeTag[zeroBasedIndex], "".PadRight(tagIndex, '>') + tag.DicomNotation + "(" + tag.IndexNumber + ")");
                            }
                            else
                            {
                                SetCellOK((int)this.columnIndexAttributeTag[zeroBasedIndex], "".PadRight(tagIndex, '>') + tag.DicomNotation);
                            }
                        }
                    }
                    else
                    {
                        SetCellOK((int)this.columnIndexAttributeTag[zeroBasedIndex], ((ValidAttribute)dicomAttributeToValidate.Attribute).TagSequence.DicomNotation);
                    }
                }
                else
                {
                    if (dicomAttributeToValidate.ValidationRuleDicomAttribute.TagSequence == "")
                    {
                        SetCellNotApplicable((int)this.columnIndexAttributeTag[zeroBasedIndex]);
                    }
                    else
                    {
                        TagSequence tagSequence = new TagSequence(dicomAttributeToValidate.ValidationRuleDicomAttribute.TagSequence);
                        ArrayList   tags        = tagSequence.Tags;

                        for (int tagIndex = 0; tagIndex < tags.Count; tagIndex++)
                        {
                            Tag tag = tags[tagIndex] as Tag;
                            if (tag.ContainsIndex)
                            {
                                SetCellOK((int)this.columnIndexAttributeTag[zeroBasedIndex], "".PadRight(tagIndex, '>') + tag.DicomNotation + "(" + tag.IndexNumber + ")");
                            }
                            else
                            {
                                SetCellOK((int)this.columnIndexAttributeTag[zeroBasedIndex], "".PadRight(tagIndex, '>') + tag.DicomNotation);
                            }
                        }
                    }
                }
            }

            // Attribute Name column.
            if (this.displayAttributeName)
            {
                if (isAttributePresent)
                {
                    SetCellOK((int)this.columnIndexAttributeName[zeroBasedIndex], GetAttributeName(dicomAttributeToValidate.Attribute));
                }
                else
                {
                    if (dicomAttributeToValidate.ValidationRuleDicomAttribute.TagSequence == "")
                    {
                        SetCellNotApplicable((int)this.columnIndexAttributeName[zeroBasedIndex]);
                    }
                    else
                    {
                        SetCellOK((int)this.columnIndexAttributeName[zeroBasedIndex], "-");
                    }
                }
            }


            // Attribute Present column.
            if (this.displayAttributePresent)
            {
                if (dicomAttributeToValidate.ValidationRuleDicomAttribute.TagSequence == "")
                {
                    SetCellNotApplicable((int)this.columnIndexAttributePresent[zeroBasedIndex]);
                }
                else
                {
                    String presentString = "";
                    bool   containsError = false;

                    if (isAttributePresent)
                    {
                        presentString = "+";
                    }
                    else
                    {
                        presentString = "-";
                    }

                    if ((compareFlags & CompareFlags.Compare_present) == CompareFlags.Compare_present)
                    {
                        if (dicomAttributesToValidate.ContainsComparePresentErrors)
                        {
                            containsError = true;
                        }
                    }

                    if ((dicomAttributeFlags & DicomAttributeFlags.Present) == DicomAttributeFlags.Present)
                    {
                        if (!isAttributePresent)
                        {
                            containsError = true;
                        }
                    }

                    if ((dicomAttributeFlags & DicomAttributeFlags.Not_present) == DicomAttributeFlags.Not_present)
                    {
                        if (isAttributePresent)
                        {
                            containsError = true;
                        }
                    }

                    if (containsError)
                    {
                        SetCellError((int)this.columnIndexAttributePresent[zeroBasedIndex], presentString);
                    }
                    else
                    {
                        SetCellOK((int)this.columnIndexAttributePresent[zeroBasedIndex], presentString);
                    }
                }
            }

            // Attribute VR column.
            if (this.displayAttributeVR)
            {
                if (isAttributePresent)
                {
                    bool containsError = false;

                    if ((compareFlags & CompareFlags.Compare_VR) == CompareFlags.Compare_VR)
                    {
                        if (dicomAttributesToValidate.ContainsCompareVRErrors)
                        {
                            containsError = true;
                        }
                    }

                    if (containsError)
                    {
                        SetCellError((int)this.columnIndexAttributeVR[zeroBasedIndex], dicomAttributeToValidate.Attribute.VR.ToString());
                    }
                    else
                    {
                        SetCellOK((int)this.columnIndexAttributeVR[zeroBasedIndex], dicomAttributeToValidate.Attribute.VR.ToString());
                    }
                }
                else
                {
                    SetCellNotApplicable((int)this.columnIndexAttributeVR[zeroBasedIndex]);
                }
            }

            // Attribute Values column.
            if (this.displayAttributeValues)
            {
                int columnIndex = (int)this.columnIndexAttributeValues[zeroBasedIndex];

                if (isAttributePresent)
                {
                    if (dicomAttributeToValidate.Attribute.VR == VR.SQ)
                    {
                        SetCellNotApplicable(columnIndex);
                    }
                    else
                    {
                        bool containsError = false;

                        if ((compareFlags & CompareFlags.Compare_values) == CompareFlags.Compare_values)
                        {
                            if (dicomAttributesToValidate.ContainsCompareValuesErrors)
                            {
                                containsError = true;
                            }
                        }

                        if ((dicomAttributeFlags & DicomAttributeFlags.Values) == DicomAttributeFlags.Values)
                        {
                            if (dicomAttributeToValidate.Attribute.Values.Count == 0)
                            {
                                containsError = true;
                            }
                        }

                        if ((dicomAttributeFlags & DicomAttributeFlags.No_values) == DicomAttributeFlags.No_values)
                        {
                            if (dicomAttributeToValidate.Attribute.Values.Count > 0)
                            {
                                containsError = true;
                            }
                        }

                        if (containsError)
                        {
                            SetCellError(columnIndex, dicomAttributeToValidate.Attribute.Values.ToString());
                        }
                        else
                        {
                            SetCellOK(columnIndex, dicomAttributeToValidate.Attribute.Values.ToString());
                        }
                    }
                }
                else
                {
                    SetCellNotApplicable(columnIndex);
                }
            }
        }