Example #1
0
        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// <br></br>
        /// When the supplied attribute is a sequence attribute, return it.
        /// If it is not a sequence attribute or does not exist, return a dummy sequence
        /// attribute containing no items.
        /// </summary>
        /// <param name="attribute">The attribute.</param>
        /// <returns>A (dummy) sequence attribute.</returns>
        private Attribute ConvertToSequenceAttribute(Attribute attribute)
        {
            Attribute sequenceAttribute = null;

            if (attribute == null)
            // Attribute does not exist.
            {
                sequenceAttribute = this.dummyEmptySequenceAttribute;
            }
            else
            {
                if (attribute.VR == VR.SQ)
                // Attribute is a sequence attribute.
                {
                    sequenceAttribute = attribute;
                }
                else
                // Attribute is not a sequence attribute.
                {
                    sequenceAttribute = this.dummyEmptySequenceAttribute;
                }
            }

            return(sequenceAttribute);
        }
Example #2
0
        private void RandomizeDatasets()
        {
            // Read the DCM File
            DicomFile dcmFile = new DicomFile();

            dcmFile.Read(selectedDCMFile, this);

            // Randomize the dataset
            Random random = new Random((int)System.DateTime.Now.Ticks);

            WriteInformation("Sending randomized responses:\r\n");
            for (int i = 0; i < nrOfRandomRsps; i++)
            {
                DataSet randomDataset = null;
                randomDataset = dcmFile.DataSet.Clone();

                randomDataset.Randomize("@", random);

                Attribute patNameAttr = randomDataset["0x00100010"];
                string    patName     = patNameAttr.Values[0];

                Attribute patIDAttr = randomDataset["0x00100020"];
                string    patID     = patIDAttr.Values[0];

                WriteInformation(string.Format("Response:{0}\r\nPatient Name: {1}, Patient ID: {2}\r\n", i + 1, patName, patID));

                randomizedDatasets.Add(randomDataset);
            }
        }
Example #3
0
        //
        // - Constructors -
        //

        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// <br></br>
        /// Default constructor.
        /// </summary>
        public Compare()
        {
            // Add a dummy sequence attribute containing no sequence items.
            this.dummyDataSet = new DataSet();
            dummyDataSet.Set("0x00800080", VR.SQ);
            this.dummyEmptySequenceAttribute = dummyDataSet["0x00800080"];
        }
Example #4
0
        /// <summary>
        /// Gets the attribute that has the supplied tag sequence string.
        /// </summary>
        /// <param name="tagSequenceString"></param>
        /// <returns></returns>
        public Attribute this[String tagSequenceString]
        {
            get
            {
                Attribute attribute = null;

                TagSequence tagSequence = new TagSequence(tagSequenceString);

                if (!tagSequence.IsSingleAttributeMatching)
                {
                    throw new HliException(tagSequenceString.ToString() + " not valid for the index property.");
                }

                if (tagSequence.IsValidForCommandSet)
                {
                    attribute = this.CommandSet[tagSequence];
                }
                else if (tagSequence.IsValidForDataSet)
                {
                    attribute = this.DataSet[tagSequence];
                }
                else
                {
                    throw new HliException(tagSequenceString.ToString() + " not valid for a DicomMessage attribute.");
                }

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

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


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

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

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

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

            return(contentItem);
        }
Example #6
0
        private BaseCommonDataFormat CreateCommonDateFormat(AttributeBase attribute)
        {
            BaseCommonDataFormat commonDataFormat = new CommonStringFormat();

            switch (this.compareRule.CompareValueType)
            {
            case CompareValueTypes.Date:
                commonDataFormat = new CommonDateFormat();
                break;

            case CompareValueTypes.ID:
                commonDataFormat = new CommonIdFormat();
                break;

            case CompareValueTypes.Name:
                commonDataFormat = new CommonNameFormat();
                break;

            case CompareValueTypes.String:
                commonDataFormat = new CommonStringFormat();
                break;

            case CompareValueTypes.Time:
                commonDataFormat = new CommonTimeFormat();
                break;

            case CompareValueTypes.UID:
                commonDataFormat = new CommonUidFormat();
                break;

            default:
                // Do nothing.
                break;
            }

            if (attribute is DicomAttribute)
            {
                DvtkHighLevelInterface.Dicom.Other.Attribute dicomAttributeOnly = (attribute as DicomAttribute).AttributeOnly;

                if (dicomAttributeOnly.VM == 0)
                {
                    commonDataFormat.FromDicomFormat("");
                }
                else
                {
                    commonDataFormat.FromDicomFormat(dicomAttributeOnly.Values[0]);
                }
            }
            else if (attribute is Hl7Attribute)
            {
                commonDataFormat.FromHl7Format((attribute as Hl7Attribute).AttributeOnly);
            }
            else
            {
                throw new System.Exception("Not supposed to get here.");
            }

            return(commonDataFormat);
        }
Example #7
0
        public void this_zeroBasedIndex()
        {
            int    zeroBasedIndex;
            string attributeName;
            string values;

            // lower bound index exception
            try
            {
                zeroBasedIndex = -1;
                DvtkHighLevelInterface.Dicom.Other.Attribute attribute = fileMetaInformation[zeroBasedIndex];
            }
            catch (System.Exception)
            {
            }

            // valid index values {0|1|2}
            Assert.That(fileMetaInformation[0].GroupNumber, Is.EqualTo(2));
            Assert.That(fileMetaInformation[0].ElementNumber, Is.EqualTo(1));
            Assert.That(fileMetaInformation[0].TagSequenceString, Is.EqualTo("0x00020001"));
            Assert.That(fileMetaInformation[0].Name, Is.Empty);
            Assert.That(fileMetaInformation[0].ItemCount, Is.EqualTo(0));

            Assert.That(fileMetaInformation[1].GroupNumber, Is.EqualTo(2));
            Assert.That(fileMetaInformation[1].ElementNumber, Is.EqualTo(16));
            Assert.That(fileMetaInformation[1].TagSequenceString, Is.EqualTo("0x00020010"));
            Assert.That(fileMetaInformation[1].Name, Is.Empty);
            Assert.That(fileMetaInformation[1].ItemCount, Is.EqualTo(0));

            Assert.That(fileMetaInformation[2].GroupNumber, Is.EqualTo(2));
            Assert.That(fileMetaInformation[2].ElementNumber, Is.EqualTo(18));
            Assert.That(fileMetaInformation[2].TagSequenceString, Is.EqualTo("0x00020012"));
            Assert.That(fileMetaInformation[2].Name, Is.Empty);
            Assert.That(fileMetaInformation[2].ItemCount, Is.EqualTo(0));

            // upper bound index exception
            try
            {
                zeroBasedIndex = 3;
                DvtkHighLevelInterface.Dicom.Other.Attribute attribute = fileMetaInformation[zeroBasedIndex];
            }
            catch (System.Exception)
            {
            }

            // set existing tag properties
            values = "ILE";
            fileMetaInformation[1].Values[0] = values;
            Assert.That(fileMetaInformation[1].Values[0], Is.EqualTo(values));

            attributeName = "Transfer Syntax";
            fileMetaInformation[1].Name = attributeName;
            Assert.That(fileMetaInformation[1].Name, Is.EqualTo(attributeName));
        }
Example #8
0
        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// </summary>
        /// <param name="attribute">-</param>
        /// <returns>-</returns>
        private String GetAttributeName(Attribute attribute)
        {
            String name = "-";

            if ((attribute.Name != "") && !(attribute.Name.StartsWith(" : private mapped to")))
            {
                name = "\"" + attribute.Name + "\"";
            }

            return(name);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="sequenceItem">
        /// The SequenceItem instance containing the DICOM attributes to construct this instance with.
        /// </param>
        /// <param name="parentContentItem">The parent Content Item.</param>
        /// <param name="position">The ordinal position of the associated Sequence Item in it's contained Content Sequence Item.</param>
        public ContentItemWithValueTypeNum(AttributeSet attributeSet, ContentItem parentContentItem, uint position) :
            base(attributeSet, parentContentItem, position)
        {
            DvtkHighLevelInterface.Dicom.Other.Attribute attribute = attributeSet["0x0040A300"];

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

            this.numericValueQualifier = ConceptCode.CreateConceptCode(attributeSet, "0x0040A301", numericValueQualifierContext);
        }
Example #10
0
        //
        // - Methods -
        //

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

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

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

            return(conceptCode);
        }
Example #11
0
        /// <summary>
        /// Convert the first value of a specified attribute to a String.
        /// </summary>
        /// <param name="attributeSet">The Attribute Set containing the DICOM Attribute.</param>
        /// <param name="tag">The tag of the attribute.</param>
        /// <returns>
        /// If the associated DICOM attribute is not present, null is returned.
        /// If the associated DICOM attribute is present and has no values, "" is returned.
        /// If the associated DICOM attribute is present and has values, the first value is returned.
        /// </returns>
        public static String FirstAttributeValueToString(AttributeSet attributeSet, String tag)
        {
            String stringForFirstAttributeValue = null;

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

            if (attribute.Exists)
            {
                if (attribute.Values.Count == 0)
                {
                    stringForFirstAttributeValue = "";
                }
                else
                {
                    stringForFirstAttributeValue = Convert.ToTrimmedString(attribute.Values[0], attribute.VR);
                }
            }

            return(stringForFirstAttributeValue);
        }
Example #12
0
        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// <br></br>
        /// When the supplied attribute is a sequence attribute, return it.
        /// If it is not a sequence attribute or does not exist, return a dummy sequence
        /// attribute containing no items.
        /// </summary>
        /// <param name="attribute">The attribute.</param>
        /// <returns>A (dummy) sequence attribute.</returns>
        private Attribute ConvertToSequenceAttribute(Attribute attribute)
        {
            Attribute sequenceAttribute = null;

            if (attribute == null)
                // Attribute does not exist.
            {
                sequenceAttribute = this.dummyEmptySequenceAttribute;
            }
            else
            {
                if (attribute.VR == VR.SQ)
                    // Attribute is a sequence attribute.
                {
                    sequenceAttribute = attribute;
                }
                else
                    // Attribute is not a sequence attribute.
                {
                    sequenceAttribute = this.dummyEmptySequenceAttribute;
                }
            }

            return(sequenceAttribute);
        }
Example #13
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="attributeOnly">The attribute without the validation rule.</param>
 /// <param name="validationRuleDicomAttribute">The validation rule that needs to be applied to the attribute.</param>
 public DicomAttribute(DvtkHighLevelInterface.Dicom.Other.Attribute attributeOnly, ValidationRuleDicomAttribute validationRuleDicomAttribute) : base(validationRuleDicomAttribute)
 {
     this.attributeOnly = attributeOnly;
 }
Example #14
0
        protected override void Execute()
        {
            try
            {
                WriteHtmlInformation("<br />");
                WriteInformation(string.Format("Reading reference media file from {0}", DCMCompareForm.firstDCMFile));
                WriteHtmlInformation("<br />");

                // Read the DCM File
                DicomFile dcmFile = new DicomFile();

                DataSet refDataset = new DataSet();

                if ((DCMCompareForm.firstDCMFile.ToLower().IndexOf("dicomdir")) != -1)
                {
                    // Read the DICOMDIR dataset
                    refDataset.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(DCMCompareForm.firstDCMFile);
                }
                else
                {
                    dcmFile.Read(DCMCompareForm.firstDCMFile, this);
                    refDataset = dcmFile.DataSet;
                }

                refDataset.UnVrDefinitionLookUpWhenReading = false;

                FileMetaInformation refFMI = dcmFile.FileMetaInformation;

                WriteInformation(string.Format("Reading source media file from {0}", DCMCompareForm.secondDCMFile));
                WriteHtmlInformation("<br />");

                DataSet srcDataset = new DataSet();

                if ((DCMCompareForm.secondDCMFile.ToLower().IndexOf("dicomdir")) != -1)
                {
                    // Read the DICOMDIR dataset
                    srcDataset.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(DCMCompareForm.secondDCMFile);
                }
                else
                {
                    dcmFile.Read(DCMCompareForm.secondDCMFile, this);
                    srcDataset = dcmFile.DataSet;
                }

                srcDataset.UnVrDefinitionLookUpWhenReading = false;

                FileMetaInformation srcFMI = dcmFile.FileMetaInformation;

                // Now get the list of filtered attribute
                if (DCMCompareForm.attributesTagList.Count != 0)
                {
                    foreach (string filterAttr in DCMCompareForm.attributesTagList)
                    {
                        try
                        {
                            if (srcDataset.Exists(filterAttr))
                            {
                                srcDataset.Delete(filterAttr);
                            }
                            if (refDataset.Exists(filterAttr))
                            {
                                refDataset.Delete(filterAttr);
                            }
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(exception.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    DCMCompareForm.attributesTagList.Clear();
                }

                WriteInformation(string.Format("Comparing the Media files - {0} and {1}", DCMCompareForm.firstDCMFile, DCMCompareForm.secondDCMFile));
                WriteHtmlInformation("<br />");

                StaticDicomCompare staticDicomCompare = new StaticDicomCompare();

                //Determine the VR display based on Transfer syntax
                string srcTransferSyntax = "";
                string refTransferSyntax = "";

                if ((srcFMI != null) && srcFMI.Exists("0x00020010"))
                {
                    // Get the Transfer syntax
                    DvtkHighLevelInterface.Dicom.Other.Attribute tranferSyntaxAttr = srcFMI["0x00020010"];
                    srcTransferSyntax = tranferSyntaxAttr.Values[0];
                }
                else
                {
                    WriteHtmlInformation(string.Format("Couldn't retrieve the Transfer syntax from DCM File {0}", DCMCompareForm.secondDCMFile));
                    WriteHtmlInformation("<br />");
                }

                if ((refFMI != null) && refFMI.Exists("0x00020010"))
                {
                    // Get the Transfer syntax
                    DvtkHighLevelInterface.Dicom.Other.Attribute tranferSyntaxAttr = refFMI["0x00020010"];
                    refTransferSyntax = tranferSyntaxAttr.Values[0];
                }
                else
                {
                    WriteHtmlInformation(string.Format("Couldn't retrieve the Transfer syntax from DCM File {0}", DCMCompareForm.firstDCMFile));
                    WriteHtmlInformation("<br />");
                }

                FlagsDicomAttribute flags = FlagsDicomAttribute.Compare_values | FlagsDicomAttribute.Compare_present | FlagsDicomAttribute.Include_sequence_items;
                if ((srcTransferSyntax == "1.2.840.10008.1.2") ||
                    (refTransferSyntax == "1.2.840.10008.1.2"))
                {
                    staticDicomCompare.DisplayAttributeVR = false;
                }
                else
                {
                    flags |= FlagsDicomAttribute.Compare_VR;
                }

                //Check for group length attributes option
                if (DCMCompareForm.filterGroupLengthAttributes)
                {
                    /*for( int i=0; i < srcDataset.Count; i++ )
                     * {
                     *      HLI.Attribute attribute   = srcDataset[i];
                     *      if(attribute.ElementNumber == 0x0000)
                     *              srcDataset.Delete(DCMCompareForm.TagString(attribute.GroupNumber,attribute.ElementNumber));
                     * }
                     *
                     * for( int i=0; i < refDataset.Count; i++ )
                     * {
                     *      HLI.Attribute attribute   = refDataset[i];
                     *      if(attribute.ElementNumber == 0x0000)
                     *              refDataset.Delete(DCMCompareForm.TagString(attribute.GroupNumber,attribute.ElementNumber));
                     * }*/
                    staticDicomCompare.DisplayGroupLength = false;
                }

                int differences = 0;

                if ((refFMI != null) && (srcFMI != null))
                {
                    AttributeCollections fmis = new AttributeCollections();
                    fmis.Add(refFMI);
                    fmis.Add(srcFMI);

                    StringCollection fmiDescriptions = new StringCollection();
                    fmiDescriptions.Add("Ref FMI");
                    fmiDescriptions.Add("Src FMI");

                    HLIStaticCompare.CompareResults fmiCompareResults = staticDicomCompare.CompareAttributeSets("FMI compare results", fmis, fmiDescriptions, flags);
                    WriteHtmlInformation(fmiCompareResults.Table.ConvertToHtml());

                    differences          += fmiCompareResults.DifferencesCount;
                    NrOfValidationErrors += (uint)fmiCompareResults.DifferencesCount;
                }

                AttributeCollections datasets = new AttributeCollections();
                datasets.Add(refDataset);
                datasets.Add(srcDataset);

                StringCollection dsDescriptions = new StringCollection();
                dsDescriptions.Add("Ref Dataset");
                dsDescriptions.Add("Src Dataset");

                HLIStaticCompare.CompareResults dsCompareResults = staticDicomCompare.CompareAttributeSets("DataSet compare results", datasets, dsDescriptions, flags);

                WriteHtmlInformation(dsCompareResults.Table.ConvertToHtml());

                differences += dsCompareResults.DifferencesCount;

                WriteHtmlInformation("<b>");
                WriteInformation("Differences found: " + differences.ToString());
                WriteHtmlInformation("</b><br />");

                NrOfValidationErrors += (uint)dsCompareResults.DifferencesCount;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Example #15
0
        private bool HandleSubOperation(System.String moveDestinationAE, System.String dcmFilename, int subOperationIndex)
        {
            SCU storageScu = new SCU();

            storageScu.Initialize(DicomThread.ThreadManager);
            storageScu.Options.DeepCopyFrom(DicomThread.Options);

            storageScu.Options.Identifier = "StorageSubOperationAsScu";

            ////Check for Secure connection
            //if (DicomThread.Options.SecureConnection)
            //{
            //    storageScu.Options.SecureConnection = true;
            //    storageScu.Options.CertificateFilename = DicomThread.Options.CertificateFilename;
            //    storageScu.Options.CredentialsFilename = DicomThread.Options.CredentialsFilename;
            //}

            storageScu.Options.ResultsFileNameOnlyWithoutExtension = "StorageSubOperationAsScu" + subOperationIndex.ToString();
            storageScu.Options.ResultsDirectory = DicomThread.Options.ResultsDirectory;

            storageScu.Options.LocalAeTitle = DicomThread.Options.LocalAeTitle;
            storageScu.Options.LocalPort    = DicomThread.Options.LocalPort;
            if (IsHaveMoveDestinations)
            {
                storageScu.Options.RemoteAeTitle  = moveDestinationAE;
                storageScu.Options.RemotePort     = MoveDestiantions[MoveAEdetailsIndex].Port;
                storageScu.Options.RemoteHostName = MoveDestiantions[MoveAEdetailsIndex].IP;
            }
            else
            {
                storageScu.Options.RemoteAeTitle  = moveDestinationAE;
                storageScu.Options.RemotePort     = DicomThread.Options.RemotePort;
                storageScu.Options.RemoteHostName = DicomThread.Options.RemoteHostName;
            }

            storageScu.Options.DataDirectory = DicomThread.Options.DataDirectory;
            storageScu.Options.StorageMode   = Dvtk.Sessions.StorageMode.AsDataSet;

            // Read the DCM File
            DicomFile dcmFile = new DicomFile();

            dcmFile.Read(dcmFilename, storageScu);

            FileMetaInformation fMI = dcmFile.FileMetaInformation;

            // Get the transfer syntax and SOP class UID
            System.String transferSyntax = "1.2.840.10008.1.2";
            if ((fMI != null) && fMI.Exists("0x00020010"))
            {
                // Get the Transfer syntax
                DvtkHighLevelInterface.Dicom.Other.Attribute tranferSyntaxAttr = fMI["0x00020010"];
                transferSyntax = tranferSyntaxAttr.Values[0];
            }

            Values values = dcmFile.DataSet["0x00080016"].Values;

            System.String sopClassUid = values[0];

            PresentationContext presentationContext = new PresentationContext(sopClassUid,             // Abstract Syntax Name
                                                                              transferSyntax);         // Transfer Syntax Name(s)

            PresentationContext[] presentationContexts = new PresentationContext[1];
            presentationContexts[0] = presentationContext;

            DicomMessage storageMessage = new DicomMessage(DvtkData.Dimse.DimseCommand.CSTORERQ);

            storageMessage.DataSet.CloneFrom(dcmFile.DataSet);

            storageScu.Start();

            bool sendResult = storageScu.TriggerSendAssociationAndWait(storageMessage, presentationContexts);

            if (!sendResult)
            {
                WriteWarning("Association to move destination for Storage Sub-Operation is rejected.");
            }

            if (storageScu.HasExceptionOccured)
            {
                WriteError("Storage Sub-Operation As SCU Failed");
            }
            storageScu.Stop();

            DicomMessageCollection cStoreResponses = storageScu.Messages.DicomMessages.CStoreResponses;

            // Obtain the value of the C-STORE RSP.The value of this variable is used to determine the attributes of the C-MOVE RSP.
            foreach (DicomMessage cStoreRsp in cStoreResponses)
            {
                cStoreStatusVal = Int32.Parse(cStoreRsp.CommandSet.GetValues("0x00000900")[0]);
            }

            // Transform the sub results
            Xslt.StyleSheetFullFileName = DicomThread.Options.StyleSheetFullFileName;
            System.String htmlResultsFilename = Xslt.Transform(storageScu.Options.ResultsDirectory, storageScu.Options.ResultsFileNameOnly);

            // Make link to the sub-operation results file
            System.String message = System.String.Format("<a href=\"{0}\">Storage sub-operation {1} to AE Title \"{2}\"</a><br/>",
                                                         htmlResultsFilename,
                                                         subOperationIndex,
                                                         moveDestinationAE);
            DicomThread.WriteHtmlInformation(message);

            return(sendResult);
        }
Example #16
0
        /// <summary>
        ///     Get an attribute given the TagSequence.
        ///     The TagSequence supplied must be single attribute matching.
        ///
        ///     Test that invalid parameter values are handled properly.
        ///     Test that non-existing tags are handled properly.
        ///     Test that all existing tags are handled properly.
        /// </summary>
        // Removed until ticket 973 has been solved [Test].
        public void this_tagSequence()
        {
            String tagSequence;
            string attributeName;
            string values;

            // empty value exception
            tagSequence = "";
            try
            {
                DvtkHighLevelInterface.Dicom.Other.Attribute attribute = fileMetaInformation[tagSequence];
            }
            catch (DvtkHighLevelInterface.Common.Other.HliException)
            {
            }

            // invalid value exception
            tagSequence = "TransferSyntax";
            try
            {
                DvtkHighLevelInterface.Dicom.Other.Attribute attribute = fileMetaInformation[tagSequence];
            }
            catch (DvtkHighLevelInterface.Common.Other.HliException)
            {
            }

            // non-existing tag
            Assert.That(fileMetaInformation["0x00020000"].Exists, Is.False);
            Assert.That(fileMetaInformation["0x00020000"].GroupNumber, Is.EqualTo(2));
            Assert.That(fileMetaInformation["0x00020000"].ElementNumber, Is.EqualTo(0));
            Assert.That(fileMetaInformation["0x00020000"].TagSequenceString, Is.EqualTo("0x00020000"));
            Assert.That(fileMetaInformation["0x00020000"].VR, Is.EqualTo(VR.UN));
            Assert.That(fileMetaInformation["0x00020000"].VM, Is.EqualTo(0));
            Assert.That(fileMetaInformation["0x00020000"].Values[0], Is.Empty);
            Assert.That(fileMetaInformation["0x00020000"].Name, Is.Empty);
            Assert.That(fileMetaInformation["0x00020000"].ItemCount, Is.EqualTo(0));

            // existing tags
            Assert.That(fileMetaInformation["0x00020001"].Exists, Is.True);
            Assert.That(fileMetaInformation["0x00020001"].GroupNumber, Is.EqualTo(2));
            Assert.That(fileMetaInformation["0x00020001"].ElementNumber, Is.EqualTo(1));
            Assert.That(fileMetaInformation["0x00020001"].TagSequenceString, Is.EqualTo("0x00020001"));
            Assert.That(fileMetaInformation["0x00020001"].Name, Is.Empty);
            Assert.That(fileMetaInformation["0x00020001"].ItemCount, Is.EqualTo(0));

            Assert.That(fileMetaInformation["0x00020010"].Exists, Is.True);
            Assert.That(fileMetaInformation["0x00020010"].GroupNumber, Is.EqualTo(2));
            Assert.That(fileMetaInformation["0x00020010"].ElementNumber, Is.EqualTo(16));
            Assert.That(fileMetaInformation["0x00020010"].TagSequenceString, Is.EqualTo("0x00020010"));
            Assert.That(fileMetaInformation["0x00020010"].Name, Is.Empty);
            Assert.That(fileMetaInformation["0x00020010"].ItemCount, Is.EqualTo(0));

            Assert.That(fileMetaInformation["0x00020012"].Exists, Is.True);
            Assert.That(fileMetaInformation["0x00020012"].GroupNumber, Is.EqualTo(2));
            Assert.That(fileMetaInformation["0x00020012"].ElementNumber, Is.EqualTo(18));
            Assert.That(fileMetaInformation["0x00020012"].TagSequenceString, Is.EqualTo("0x00020012"));
            Assert.That(fileMetaInformation["0x00020012"].Name, Is.Empty);
            Assert.That(fileMetaInformation["0x00020012"].ItemCount, Is.EqualTo(0));

            // set non-existing tag properties
            values = "80";
            fileMetaInformation["0x00020000"].Values[0] = values;
            Assert.That(fileMetaInformation["0x00020000"].Values[0], Is.EqualTo(values));

            attributeName = "Group Length";
            fileMetaInformation["0x00020000"].Name = attributeName;
            Assert.That(fileMetaInformation["0x00020000"].Name, Is.EqualTo(attributeName));

            // set existing tag properties
            values = "ILE";
            fileMetaInformation["0x00020010"].Values[0] = values;
            Assert.That(fileMetaInformation["0x00020010"].Values[0], Is.EqualTo(values));

            attributeName = "Transfer Syntax";
            fileMetaInformation["0x00020010"].Name = attributeName;
            Assert.That(fileMetaInformation["0x00020010"].Name, Is.EqualTo(attributeName));
        }
Example #17
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 #18
0
        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// </summary>
        /// <param name="attribute">-</param>
        /// <returns>-</returns>
        private String GetAttributeName(Attribute attribute)
        {
            String name = "-";

            if ((attribute.Name != "") && !(attribute.Name.StartsWith(" : private mapped to")))
            {
                name = "\"" + attribute.Name + "\"";
            }

            return(name);
        }
Example #19
0
        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// </summary>
        /// <param name="sequenceAttribute1">-</param>
        /// <param name="sequenceAttribute2">-</param>
        /// <param name="level">-</param>
        private void AddSequenceAttributesContentComparison(Attribute sequenceAttribute1, Attribute sequenceAttribute2, int level)
        {
            int maxItemCount = Math.Max(sequenceAttribute1.ItemCount, sequenceAttribute2.ItemCount);

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

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

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

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

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

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

                AddAttributeSetsComparison(sequenceItem1, sequenceItem2, level + 1);

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

                //
                // Update the differences count.
                //

                if ((!sequenceItem1Present) || (!sequenceItem2Present))
                {
                    this.differencesCount++;
                }
            }
        }
Example #20
0
        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// </summary>
        /// <param name="sequenceAttribute1">-</param>
        /// <param name="sequenceAttribute2">-</param>
        /// <param name="level">-</param>
        private void AddSequenceAttributesContentComparison(Attribute sequenceAttribute1, Attribute sequenceAttribute2, int level)
        {
            int maxItemCount = Math.Max(sequenceAttribute1.ItemCount, sequenceAttribute2.ItemCount);

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

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


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

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


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

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

                AddAttributeSetsComparison(sequenceItem1, sequenceItem2, level + 1);

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


                //
                // Update the differences count.
                //

                if ((!sequenceItem1Present) || (!sequenceItem2Present))
                {
                    this.differencesCount++;
                }
            }
        }
Example #21
0
 //
 // - Constructors -
 //
 /// <summary>
 /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
 /// <br></br>
 /// Default constructor.
 /// </summary>
 public Compare()
 {
     // Add a dummy sequence attribute containing no sequence items.
     this.dummyDataSet = new DataSet();
     dummyDataSet.Set("0x00800080", VR.SQ);
     this.dummyEmptySequenceAttribute = dummyDataSet["0x00800080"];
 }
Example #22
0
        private void AddSequenceAttributesContentInformation(DicomAttributesToValidate dicomAttributesToValidate, int oneBasedLevel)
        {
            //
            // Determine the maximum amount of sequence items for all supplied sequence attributes.
            //

            int maxItemCount = dicomAttributesToValidate.MaxItemCount;


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

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

                NewRow();

                AddCommonInformationForBeginOrEndSequenceItems(oneBasedLevel, true, itemIndex);

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


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

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

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

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

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

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

                AddAttributeSetsInformationUsingStaticCompare(sequenceItemsToCompare, compareFlagsForSequenceItems, dicomAttributeFlagsForSequenceItems, displaySequenceItems);


                //
                // Add end item row.
                //

                NewRow();

                AddCommonInformationForBeginOrEndSequenceItems(oneBasedLevel, false, itemIndex);

                for (int attributeIndex = 0; attributeIndex < dicomAttributesToValidate.Count; attributeIndex++)
                {
                    AddAttributeInformationForBeginOrEndSequenceItem(dicomAttributesToValidate, attributeIndex, itemIndex, false);
                }
            }
        }
Example #23
0
 public void Add_attribute()
 {
     DvtkHighLevelInterface.Dicom.Other.Attribute attribute = null;
     fileMetaInformation.Add(attribute);
 }
Example #24
0
        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// <br></br>
        /// Add a row containing the result of comparing the two supplied attributes.
        /// </summary>
        /// <param name="attribute1">Attribute 1.</param>
        /// <param name="attribute2">Attribute 2.</param>
        /// <param name="level">-</param>
        private void AddAttributesComparison(ValidAttribute attribute1, ValidAttribute attribute2, int level)
        {
            table.NewRow();


            //
            // Fill in the general tag information.
            //

            ValidAttribute attribute = null;

            if (attribute1 != null)
            {
                attribute = attribute1;
            }
            else
            {
                attribute = attribute2;
            }

            String name = "-";

            if ((attribute.Name != "") && !(attribute.Name.StartsWith(" : private mapped to")))
            {
                name = "\"" + attribute.Name + "\"";
            }

            SetCellOK(this.columnIndexTag, attribute.TagSequence.DicomNotation, true);
            SetCellOK(this.columnIndexName, name, true);


            //
            // Fill in the information for the two attributes.
            //

            bool areEqual = true;

            areEqual = AddAttributeInformation(attribute1, attribute2, true);
            AddAttributeInformation(attribute2, attribute1, false);


            //
            // Find out if at least one of the attributes is a sequence attribute.
            //

            bool containsAtLeastOneSequenceAttribute = false;

            if (attribute1 != null)
            {
                if (attribute1.VR == VR.SQ)
                {
                    containsAtLeastOneSequenceAttribute = true;
                }
            }

            if (attribute2 != null)
            {
                if (attribute2.VR == VR.SQ)
                {
                    containsAtLeastOneSequenceAttribute = true;
                }
            }


            //
            // If at least one attribute is a sequence attribute, do a comparison of the content.
            // If the other attribute is null or is not a sequence attribute, use an
            // empty sequence attribute instead.
            //

            if (containsAtLeastOneSequenceAttribute)
            {
                Attribute sequenceAttribute1 = ConvertToSequenceAttribute(attribute1);
                Attribute sequenceAttribute2 = ConvertToSequenceAttribute(attribute2);

                AddSequenceAttributesContentComparison(sequenceAttribute1, sequenceAttribute2, level);
            }


            //
            // Update the differences count.
            //

            if (!areEqual)
            {
                this.differencesCount++;
            }
        }
Example #25
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="attributeOnly">The attribute without the validation rule.</param>
 /// <param name="validationRuleDicomAttribute">The validation rule that needs to be applied to the attribute.</param>
 public DicomAttribute(DvtkHighLevelInterface.Dicom.Other.Attribute attributeOnly, ValidationRuleDicomAttribute validationRuleDicomAttribute)
     : base(validationRuleDicomAttribute)
 {
     this.attributeOnly = attributeOnly;
 }