예제 #1
0
        private void CreateTable()
        {
            StaticDicomCompare  compare      = new StaticDicomCompare();
            FlagsDicomAttribute flags        = FlagsDicomAttribute.Compare_values | FlagsDicomAttribute.Compare_present | FlagsDicomAttribute.Include_sequence_items;
            StringCollection    descriptions = new StringCollection();

            descriptions.Add("Src Dataset");
            descriptions.Add("Annonymized Dataset");
            CompareResults compareResults = compare.CompareAttributeSets("DataSet compare results", datasets, descriptions, flags);
            string         tableString    = compareResults.Table.ConvertToHtml();
            StreamWriter   writer         = new StreamWriter(resultFileName);

            if (utility.AnonymizationType)
            {
                writer.Write("<b><font size='3' color='#0000ff'>Anonymized DCM File (Basic)</font></b>");
            }
            else
            {
                writer.Write("<b><font size='3' color='#0000ff'>Anonymized DCM File (Complete)</font></b>");
            }

            writer.Write(tableString);
            writer.Write("<br/>");
            writer.Close();

            dvtkWebBrowser.Navigate(resultFileName);
        }
예제 #2
0
        public void Add_attributeSet_flags()
        {
            AttributeSet        attributeSet = null;
            FlagsDicomAttribute flags        = new FlagsDicomAttribute();
            int count = attributeCollections.Count;

            attributeCollections.Add(attributeSet, flags);
            Assert.That(count + 1, Is.EqualTo(attributeCollections.Count));
        }
예제 #3
0
        public void Add_attributeSet_flags()
        {
            AttributeSet attributeSet = null;
            FlagsDicomAttribute flags = new FlagsDicomAttribute();
            int count = attributeCollections.Count;

            attributeCollections.Add(attributeSet, flags);
            Assert.That(count + 1, Is.EqualTo(attributeCollections.Count));
        }
예제 #4
0
        //
        // - Properties -
        //
        //
        // - Methods -
        //
        /// <summary>
        /// Do a static compare for the attribute sets supplied.
        /// 
        /// Note that the parameters attributeSets, attributeSetDescriptions and compareFlagsForAttributeSets
        /// must have the same size and must be at least size 2.
        /// </summary>
        /// <param name="tableDescription">Description of the table.</param>
        /// <param name="attributeCollections">The attribute sets to compare with each other.</param>
        /// <param name="attributeCollectionDescriptions">The descriptions of the attribute sets.</param>
        /// <param name="flags">
        /// The compare flags that may be supplied. The following combination of flags may be supplied (using bitwise Or):
        /// - CompareFlags.None: when only supplying this flag, the attributes are only displayed and no compare is performed.
        /// - CompareFlags.Compare_present: a check is performed if all attributes with the same tag are present.
        /// - CompareFlags.Compare_values: a check is performed if all attributes with the same tag have the same values.
        /// - CompareFlags.Compare_VR: a check is performed if all attributes with the same tag have the same VR.
        /// </param>
        /// <returns>The results of the static compare presented as a table (that may be converted to HTML).</returns>
        public CompareResults CompareAttributeSets(String tableDescription, AttributeCollections attributeCollections, StringCollection attributeCollectionDescriptions, FlagsDicomAttribute flags)
        {
            CompareResults compareResults = null;

            for (int index = 0; index < attributeCollections.Count; index++)
            {
                (attributeCollections[index] as DicomAttributeCollection).Flags |= FlagsConvertor.ConvertToFlagsBase(flags);
            }

            compareResults = CompareAttributeSets(tableDescription, attributeCollections, attributeCollectionDescriptions);

            return(compareResults);
        }
예제 #5
0
        //
        // - Methods -
        //

        /// <summary>
        /// Convert FlagsDicomAttribute to FlagsBase.
        /// </summary>
        /// <param name="flagsDicomAttribute">The Dicom Attribute flags.</param>
        /// <returns>The base flags.</returns>
        public static FlagsBase ConvertToFlagsBase(FlagsDicomAttribute flagsDicomAttribute)
        {
            FlagsBase flags = FlagsBase.None;

            if ((flagsDicomAttribute & FlagsDicomAttribute.Compare_present) == FlagsDicomAttribute.Compare_present)
            {
                flags |= FlagsBase.Compare_present;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Compare_values) == FlagsDicomAttribute.Compare_values)
            {
                flags |= FlagsBase.Compare_values;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Present) == FlagsDicomAttribute.Present)
            {
                flags |= FlagsBase.Present;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Not_present) == FlagsDicomAttribute.Not_present)
            {
                flags |= FlagsBase.Not_present;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Compare_VR) == FlagsDicomAttribute.Compare_VR)
            {
                flags |= FlagsBase.Compare_VR;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Values) == FlagsDicomAttribute.Values)
            {
                flags |= FlagsBase.Values;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.No_values) == FlagsDicomAttribute.No_values)
            {
                flags |= FlagsBase.No_values;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Include_sequence_items) == FlagsDicomAttribute.Include_sequence_items)
            {
                flags |= FlagsBase.Include_sequence_items;
            }

            return(flags);
        }
예제 #6
0
        //
        // - Methods -
        //
        /// <summary>
        /// Convert FlagsDicomAttribute to FlagsBase.
        /// </summary>
        /// <param name="flagsDicomAttribute">The Dicom Attribute flags.</param>
        /// <returns>The base flags.</returns>
        public static FlagsBase ConvertToFlagsBase(FlagsDicomAttribute flagsDicomAttribute)
        {
            FlagsBase flags = FlagsBase.None;

            if ((flagsDicomAttribute & FlagsDicomAttribute.Compare_present) == FlagsDicomAttribute.Compare_present)
            {
                flags |= FlagsBase.Compare_present;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Compare_values) == FlagsDicomAttribute.Compare_values)
            {
                flags |= FlagsBase.Compare_values;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Present) == FlagsDicomAttribute.Present)
            {
                flags |= FlagsBase.Present;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Not_present) == FlagsDicomAttribute.Not_present)
            {
                flags |= FlagsBase.Not_present;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Compare_VR) == FlagsDicomAttribute.Compare_VR)
            {
                flags |= FlagsBase.Compare_VR;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Values) == FlagsDicomAttribute.Values)
            {
                flags |= FlagsBase.Values;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.No_values) == FlagsDicomAttribute.No_values)
            {
                flags |= FlagsBase.No_values;
            }

            if ((flagsDicomAttribute & FlagsDicomAttribute.Include_sequence_items) == FlagsDicomAttribute.Include_sequence_items)
            {
                flags |= FlagsBase.Include_sequence_items;
            }

            return(flags);
        }
예제 #7
0
        void CreateTableWithoutNav()
        {
            StaticDicomCompare  compare      = new StaticDicomCompare();
            FlagsDicomAttribute flags        = FlagsDicomAttribute.Compare_values | FlagsDicomAttribute.Compare_present | FlagsDicomAttribute.Include_sequence_items;
            StringCollection    descriptions = new StringCollection();

            descriptions.Add("Src Dataset");
            descriptions.Add("Annonymized Dataset");
            CompareResults compareResults = compare.CompareAttributeSets("DataSet compare results", datasets, descriptions, flags);

            StringBuilder tableString = new StringBuilder();

            tableString.Append("<left><font color='#0000ff' size = '4'>");
            tableString.Append(string.Format("Comparing the DICOM file {0} with anonymized file", resultFileName));
            tableString.Append("</font>");
            tableString.Append("</left>");
            tableString.Append("<br></br>");
            tableString.Append(compareResults.Table.ConvertToHtml());

            StreamWriter writer = new StreamWriter(initialDirectory + "\\" + resultFileName + "_" + counter.ToString() + ".html");

            writer.Write(tableString.ToString());
            writer.Close();
        }
예제 #8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="attributeSetOnly">The actual collection of Dicom Attributes.</param>
 /// <param name="flagsDicomAttribute">The flags used for this collection.</param>
 internal DicomAttributeCollection(DvtkHighLevelInterface.Dicom.Other.AttributeSet attributeSetOnly, FlagsDicomAttribute flagsDicomAttribute)
 {
     this.attributeSetOnly = attributeSetOnly;
     Flags = FlagsConvertor.ConvertToFlagsBase(flagsDicomAttribute);
 }
예제 #9
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="attributeSetOnly">The actual collection of Dicom Attributes.</param>
 /// <param name="flagsDicomAttribute">The flags used for this collection.</param>
 internal DicomAttributeCollection(DvtkHighLevelInterface.Dicom.Other.AttributeSet attributeSetOnly, FlagsDicomAttribute flagsDicomAttribute)
 {
     this.attributeSetOnly = attributeSetOnly;
     Flags = FlagsConvertor.ConvertToFlagsBase(flagsDicomAttribute);
 }
예제 #10
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tagSequenceString">TagSequenceString indicating the Dicom attribute to validate.</param>
        /// <param name="flagsDicomAttribute">The flag(s) indicating how to validate this Dicom Attribute.</param>
        public ValidationRuleDicomAttribute(String tagSequenceString, FlagsDicomAttribute flagsDicomAttribute)
        {
            this.tagSequenceString = tagSequenceString;

            Flags = FlagsConvertor.ConvertToFlagsBase(flagsDicomAttribute);
        }
예제 #11
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;
            }
        }
예제 #12
0
        //
        // - Properties -
        //



        //
        // - Methods -
        //



        /// <summary>
        /// Do a static compare for the attribute sets supplied.
        ///
        /// Note that the parameters attributeSets, attributeSetDescriptions and compareFlagsForAttributeSets
        /// must have the same size and must be at least size 2.
        /// </summary>
        /// <param name="tableDescription">Description of the table.</param>
        /// <param name="attributeCollections">The attribute sets to compare with each other.</param>
        /// <param name="attributeCollectionDescriptions">The descriptions of the attribute sets.</param>
        /// <param name="flags">
        /// The compare flags that may be supplied. The following combination of flags may be supplied (using bitwise Or):
        /// - CompareFlags.None: when only supplying this flag, the attributes are only displayed and no compare is performed.
        /// - CompareFlags.Compare_present: a check is performed if all attributes with the same tag are present.
        /// - CompareFlags.Compare_values: a check is performed if all attributes with the same tag have the same values.
        /// - CompareFlags.Compare_VR: a check is performed if all attributes with the same tag have the same VR.
        /// </param>
        /// <returns>The results of the static compare presented as a table (that may be converted to HTML).</returns>
        public CompareResults CompareAttributeSets(String tableDescription, AttributeCollections attributeCollections, StringCollection attributeCollectionDescriptions, FlagsDicomAttribute flags)
        {
            CompareResults compareResults = null;

            for (int index = 0; index < attributeCollections.Count; index++)
            {
                (attributeCollections[index] as DicomAttributeCollection).Flags |= FlagsConvertor.ConvertToFlagsBase(flags);
            }

            compareResults = CompareAttributeSets(tableDescription, attributeCollections, attributeCollectionDescriptions);

            return(compareResults);
        }
예제 #13
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tagSequenceString">TagSequenceString indicating the Dicom attribute to validate.</param>
        /// <param name="flagsDicomAttribute">The flag(s) indicating how to validate this Dicom Attribute.</param>
        public ValidationRuleDicomAttribute(String tagSequenceString, FlagsDicomAttribute flagsDicomAttribute)
        {
            this.tagSequenceString = tagSequenceString;

            Flags = FlagsConvertor.ConvertToFlagsBase(flagsDicomAttribute);
        }
예제 #14
0
        /// <summary>
        /// Compare the DICOM files in the two directories based on there being corresponding
        /// files in each directory with the same attribute value for the matching Tag.
        /// </summary>
        /// <param name="directory1">Full directory name of first directory.</param>
        /// <param name="directory2">Full directory name of second directory.</param>
        /// <param name="matchingTag">DICOM Tag value to match in a file in each directory.</param>
        /// <returns>Total number of differences between compared files.</returns>
        public int Compare(String directory1, String directory2, DvtkData.Dimse.Tag matchingTag)
        {
            int totalDifferences = 0;

            StreamWriter htmlOutput = null;

            try
            {
                // create the output file writer if necessary
                if (_htmlOutputFilename != String.Empty)
                {
                    htmlOutput = new StreamWriter(_htmlOutputFilename);
                }

                // compare all files in directory 1 with corresponding files in directory 2
                // - the files compared is based on them having the same attribute value for the
                // Tag given.
                DirectoryInfo directoryInfo = new DirectoryInfo(directory1);
                FileInfo[]    fileInfo      = directoryInfo.GetFiles();
                for (int i = 0; i < fileInfo.Length; i++)
                {
                    DataSet dataset1  = new DataSet();
                    String  filename1 = fileInfo[i].FullName;
                    dataset1.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(filename1);

                    // get the attribute value for the matching tag from this dataset
                    String valueToMatch = GetAttributeValueFromDataset(dataset1, matchingTag);
                    if (valueToMatch != String.Empty)
                    {
                        // try to find a dataset (file) containing the same value in directory 2
                        String  filename2 = String.Empty;
                        DataSet dataset2  = GetMatchingDatasetFromStoreDataDirectory(directory2, matchingTag, valueToMatch, out filename2);

                        // if a dataset is returned that contains the matching attribute value go on to compare all the attributes
                        // in both datasets with eachother
                        if (dataset2 != null)
                        {
                            // get a new compare instance and set the comparison flags
                            StaticDicomCompare  staticDicomCompare = new StaticDicomCompare();
                            FlagsDicomAttribute flags = FlagsDicomAttribute.Compare_values | FlagsDicomAttribute.Compare_present | FlagsDicomAttribute.Include_sequence_items;
                            if (_compareVr == false)
                            {
                                staticDicomCompare.DisplayAttributeVR = false;
                            }
                            else
                            {
                                flags |= FlagsDicomAttribute.Compare_VR;
                            }
                            staticDicomCompare.DisplayGroupLength = _displayGroupLength;

                            dataset1.UnVrDefinitionLookUpWhenReading = _unVrDefinitionLookUpWhenReading;
                            dataset2.UnVrDefinitionLookUpWhenReading = _unVrDefinitionLookUpWhenReading;

                            AttributeCollections datasets = new AttributeCollections();
                            datasets.Add(dataset1);
                            datasets.Add(dataset2);

                            StringCollection datasetDescriptions = new StringCollection();
                            datasetDescriptions.Add(filename1);
                            datasetDescriptions.Add(filename2);

                            String title = String.Format("Comparison Results with matching using Tag with {0}", matchingTag.ToString());
                            DvtkHighLevelInterface.Common.Compare.CompareResults datasetCompareResults = staticDicomCompare.CompareAttributeSets(title, datasets, datasetDescriptions, flags);
                            if (htmlOutput != null)
                            {
                                if (_includeDetailedResults == true)
                                {
                                    htmlOutput.WriteLine(datasetCompareResults.Table.ConvertToHtml());
                                }
                                else
                                {
                                    htmlOutput.WriteLine("<br />");
                                    String message = String.Format("Compared {0} with {1} - number of differences: {2}", filename1, filename2, datasetCompareResults.DifferencesCount);
                                    htmlOutput.WriteLine(message);
                                    htmlOutput.WriteLine("<br />");
                                }
                            }

                            // update the total differences counter
                            totalDifferences += datasetCompareResults.DifferencesCount;
                        }
                    }
                }
            }
            catch (System.Exception)
            {
            }
            if (htmlOutput != null)
            {
                htmlOutput.Flush();
                htmlOutput.Close();
            }
            return(totalDifferences);
        }
예제 #15
0
        /// <summary>
        /// Add an AttributeSet instance with specified flags to this collection.
        /// </summary>
        /// <param name="attributeSet">The attribute set.</param>
        /// <param name="flags">The flags.</param>
        public void Add(AttributeSet attributeSet, FlagsDicomAttribute flags)
        {
            DicomAttributeCollection dicomAttributeCollection = new DicomAttributeCollection(attributeSet, flags);

            Add(dicomAttributeCollection);
        }
예제 #16
0
        /// <summary>
        /// Add an AttributeSet instance with specified flags to this collection.
        /// </summary>
        /// <param name="attributeSet">The attribute set.</param>
        /// <param name="flags">The flags.</param>
        public void Add(AttributeSet attributeSet, FlagsDicomAttribute flags)
        {
            DicomAttributeCollection dicomAttributeCollection = new DicomAttributeCollection(attributeSet, flags);

            Add(dicomAttributeCollection);
        }