Esempio n. 1
0
        /// <summary>
        /// Load a DICOMDIR
        /// </summary>
        /// <param name="filename"></param>
        public void Load(string filename)
        {
            try
            {
                _dir = new DicomDirectory(_aeTitle);

                _dir.Load(filename);


                // Show a simple traversal
                foreach (DirectoryRecordSequenceItem patientRecord in _dir.RootDirectoryRecordCollection)
                {
                    PatientRecords++;
                    foreach (DirectoryRecordSequenceItem studyRecord in patientRecord.LowerLevelDirectoryRecordCollection)
                    {
                        StudyRecords++;
                        foreach (DirectoryRecordSequenceItem seriesRecord in studyRecord.LowerLevelDirectoryRecordCollection)
                        {
                            SeriesRecords++;
                            foreach (DirectoryRecordSequenceItem instanceRecord in seriesRecord.LowerLevelDirectoryRecordCollection)
                            {
                                InstanceRecords++;
                            }
                        }
                    }
                }

                Platform.Log(LogLevel.Info, "Loaded DICOMDIR with {0} Patient Records, {1} Study Records, {2} Series Records, and {3} Image Records",
                             PatientRecords, StudyRecords, SeriesRecords, InstanceRecords);
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception reading DICOMDIR: {0}", filename);
            }
        }
        public void CreateDicomdirTest()
        {
            DicomFile file = new DicomFile("CreateFileTest.dcm");

            SetupMR(file.DataSet);
            SetupMetaInfo(file);

            DicomDirectory writer    = new DicomDirectory("");
            int            fileCount = 1;

            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            file = new DicomFile("CreateXaFileTest.dcm");
            SetupMultiframeXA(file.DataSet, 256, 256, 10);
            SetupMetaInfo(file);
            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            DicomFile newfile = new DicomFile("test2.dcm");

            SetupKoForImage(newfile.DataSet, file.DataSet);
            SetupMetaInfo(newfile);
            writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

            IList <DicomAttributeCollection> seriesList = SetupMRSeries(2, 2, DicomUid.GenerateUid().UID);

            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                fileCount++;
                SetupMetaInfo(file);

                writer.AddFile(file, String.Format("DIR001\\FILE{0}", fileCount));
            }

            writer.FileSetId = "TestDicomdir";
            writer.Save("DICOMDIR");


            DicomDirectory reader = new DicomDirectory("");

            reader.Load("DICOMDIR");


            string failureReason;

            Assert.IsTrue(Compare(writer.RootDirectoryRecord, reader.RootDirectoryRecord, out failureReason), failureReason);
        }
Esempio n. 3
0
        public static DicomDirFileSet Load(string filename)
        {
            var dicomDirectory = new DicomDirectory(String.Empty);

            dicomDirectory.Load(filename);

            var directoryName = Path.GetDirectoryName(filename);

            DicomDirFileSet tmp = new DicomDirFileSet(dicomDirectory.FileSetId);

            foreach (var item in dicomDirectory.RootDirectoryRecordCollection)
            {
                if (item.DirectoryRecordType != DirectoryRecordType.Patient)
                {
                    throw new InvalidOperationException();
                }

                foreach (var subItem in item.LowerLevelDirectoryRecordCollection)
                {
                    if (subItem.DirectoryRecordType == DirectoryRecordType.Study)
                    {
                        try
                        {
                            tmp.Studies.Add(new LocalStudy(subItem, tmp, directoryName));
                        }
                        catch (Exception)
                        {
                            // TODO
                            Platform.Log(LogLevel.Warn, "invaild data when load dicom dir");
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
            }

            return(tmp);
        }
Esempio n. 4
0
		/// <summary>
		/// Load a DICOMDIR
		/// </summary>
		/// <param name="filename"></param>
		public void Load(string filename)
		{
			try
			{
				_dir = new DicomDirectory(_aeTitle);

				_dir.Load(filename);


				// Show a simple traversal
				foreach (DirectoryRecordSequenceItem patientRecord in _dir.RootDirectoryRecordCollection)
				{
					PatientRecords++;
					foreach (DirectoryRecordSequenceItem studyRecord in patientRecord.LowerLevelDirectoryRecordCollection)
					{
						StudyRecords++;
						foreach (DirectoryRecordSequenceItem seriesRecord in studyRecord.LowerLevelDirectoryRecordCollection)
						{
							SeriesRecords++;
							foreach (DirectoryRecordSequenceItem instanceRecord in seriesRecord.LowerLevelDirectoryRecordCollection)
							{
								InstanceRecords++;
							}
						}
					}
				}

				Logger.LogInfo("Loaded DICOMDIR with {0} Patient Records, {1} Study Records, {2} Series Records, and {3} Image Records",
					PatientRecords,StudyRecords,SeriesRecords,InstanceRecords);

			}
			catch (Exception e)
			{
				Logger.LogErrorException(e, "Unexpected exception reading DICOMDIR: {0}", filename);
			}
		}
		public void CreateDicomdirTest()
		{
			DicomFile file = new DicomFile("CreateFileTest.dcm");

			SetupMR(file.DataSet);
			SetupMetaInfo(file);

			DicomDirectory writer = new DicomDirectory("");
			int fileCount = 1;

			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			file = new DicomFile("CreateXaFileTest.dcm");
			SetupMultiframeXA(file.DataSet, 256, 256, 10);
			SetupMetaInfo(file);
			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			DicomFile newfile = new DicomFile("test2.dcm");
			SetupKoForImage(newfile.DataSet, file.DataSet);
			SetupMetaInfo(newfile);
			writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

			IList<DicomAttributeCollection> seriesList = SetupMRSeries(2, 2, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				fileCount++;
				SetupMetaInfo(file);

				writer.AddFile(file, String.Format("DIR001\\FILE{0}", fileCount));
			}

			writer.FileSetId = "TestDicomdir";
			writer.Save("DICOMDIR");


			DicomDirectory reader = new DicomDirectory("");

			reader.Load("DICOMDIR");


			string failureReason;
			Assert.IsTrue(Compare(writer.RootDirectoryRecord, reader.RootDirectoryRecord, out failureReason), failureReason);
		}
		public void ComparisonTest()
		{
			DicomDirectory writer = new DicomDirectory("DICOMDIR");

			int fileCount = 1;

			DicomFile file = new DicomFile("CreateFileTest.dcm");
			SetupMR(file.DataSet);
			SetupMetaInfo(file);
			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			file = new DicomFile("CreateFileTest.dcm");
			SetupMR(file.DataSet);
			SetupMetaInfo(file);
			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			DicomFile newfile = new DicomFile("test2.dcm");
			SetupKoForImage(newfile.DataSet, file.DataSet);
			SetupMetaInfo(newfile);
			writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

			file = new DicomFile("CreateXaFileTest.dcm");
			SetupMultiframeXA(file.DataSet, 128, 128, 4);
			SetupMetaInfo(file);
			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			newfile = new DicomFile("test2.dcm");
			SetupKoForImage(newfile.DataSet, file.DataSet);
			SetupMetaInfo(newfile);
			writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));


			file = new DicomFile("CreateXaFileTest.dcm");
			SetupMultiframeXA(file.DataSet, 64, 64, 4);
			SetupMetaInfo(file);
			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			newfile = new DicomFile("test2.dcm");
			SetupKoForImage(newfile.DataSet, file.DataSet);
			SetupMetaInfo(newfile);
			writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

			IList<DicomAttributeCollection> seriesList = SetupMRSeries(3, 1, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
			}

			seriesList = SetupMRSeries(4, 4, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

				file = new DicomFile("test2.dcm");
				SetupKoForImage(file.DataSet, collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
			}

			seriesList = SetupMRSeries(10, 1, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

				file = new DicomFile("test2.dcm");
				SetupKoForImage(file.DataSet, collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
			}

			seriesList = SetupMRSeries(4, 3, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
			}

			writer.FileSetId = "TestDicomdir";
			writer.Save("DICOMDIR");


			DicomDirectory reader = new DicomDirectory("DICOMDIR");
			reader.Load("DICOMDIR");


			string failureReason;
			Assert.IsTrue(Compare(writer.RootDirectoryRecord, reader.RootDirectoryRecord, out failureReason), failureReason);

			// Test Append
			// Add a few more files to the file read in, then rewrite and read and compare
			seriesList = SetupMRSeries(4, 4, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				SetupMetaInfo(file);
				reader.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

				file = new DicomFile("test2.dcm");
				SetupKoForImage(file.DataSet, collection);
				SetupMetaInfo(file);
				reader.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
			}

			reader.FileSetId = "TestDicomdir";
			reader.Save("DICOMDIR");


			DicomDirectory reader2 = new DicomDirectory("DICOMDIR");
			reader2.Load("DICOMDIR");


			Assert.IsTrue(Compare(reader.RootDirectoryRecord, reader2.RootDirectoryRecord, out failureReason), failureReason);
		}
        public void ComparisonTest()
        {
            DicomDirectory writer = new DicomDirectory("DICOMDIR");

            int fileCount = 1;

            DicomFile file = new DicomFile("CreateFileTest.dcm");

            SetupMR(file.DataSet);
            SetupMetaInfo(file);
            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            file = new DicomFile("CreateFileTest.dcm");
            SetupMR(file.DataSet);
            SetupMetaInfo(file);
            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            DicomFile newfile = new DicomFile("test2.dcm");

            SetupKoForImage(newfile.DataSet, file.DataSet);
            SetupMetaInfo(newfile);
            writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

            file = new DicomFile("CreateXaFileTest.dcm");
            SetupMultiframeXA(file.DataSet, 128, 128, 4);
            SetupMetaInfo(file);
            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            newfile = new DicomFile("test2.dcm");
            SetupKoForImage(newfile.DataSet, file.DataSet);
            SetupMetaInfo(newfile);
            writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));


            file = new DicomFile("CreateXaFileTest.dcm");
            SetupMultiframeXA(file.DataSet, 64, 64, 4);
            SetupMetaInfo(file);
            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            newfile = new DicomFile("test2.dcm");
            SetupKoForImage(newfile.DataSet, file.DataSet);
            SetupMetaInfo(newfile);
            writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

            IList <DicomAttributeCollection> seriesList = SetupMRSeries(3, 1, DicomUid.GenerateUid().UID);

            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
            }

            seriesList = SetupMRSeries(4, 4, DicomUid.GenerateUid().UID);
            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

                file = new DicomFile("test2.dcm");
                SetupKoForImage(file.DataSet, collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
            }

            seriesList = SetupMRSeries(10, 1, DicomUid.GenerateUid().UID);
            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

                file = new DicomFile("test2.dcm");
                SetupKoForImage(file.DataSet, collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
            }

            seriesList = SetupMRSeries(4, 3, DicomUid.GenerateUid().UID);
            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
            }

            writer.FileSetId = "TestDicomdir";
            writer.Save("DICOMDIR");


            DicomDirectory reader = new DicomDirectory("DICOMDIR");

            reader.Load("DICOMDIR");


            string failureReason;

            Assert.IsTrue(Compare(writer.RootDirectoryRecord, reader.RootDirectoryRecord, out failureReason), failureReason);

            // Test Append
            // Add a few more files to the file read in, then rewrite and read and compare
            seriesList = SetupMRSeries(4, 4, DicomUid.GenerateUid().UID);
            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                SetupMetaInfo(file);
                reader.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

                file = new DicomFile("test2.dcm");
                SetupKoForImage(file.DataSet, collection);
                SetupMetaInfo(file);
                reader.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
            }

            reader.FileSetId = "TestDicomdir";
            reader.Save("DICOMDIR");


            DicomDirectory reader2 = new DicomDirectory("DICOMDIR");

            reader2.Load("DICOMDIR");


            Assert.IsTrue(Compare(reader.RootDirectoryRecord, reader2.RootDirectoryRecord, out failureReason), failureReason);
        }