Esempio n. 1
0
        public void FolderingTest()
        {
            string folder = Path.Combine(Tools.RootFolder, @"EK\Capture\Dicom\DicomToolKit\Test\Data\DicomDir");
            string path   = Path.Combine(folder, "FolderingTest");

            DicomDir dir = new DicomDir(path);

            dir.Empty();

            DirectoryInfo working = new DirectoryInfo(path);

            working = Directory.CreateDirectory(path);

            int n = 0;

            // add each test image to the DICOMDIR
            foreach (string file in Directory.GetFiles(folder, "*.dcm"))
            {
                dir.Add(file, @"parent\child");
                n++;
            }

            // write it out
            dir.Save();

            string temp = Path.Combine(path, @"parent\child");

            temp = Path.Combine(temp, String.Format("{0:00000000}", n));
            Assert.IsTrue(new FileInfo(temp).Exists);
        }
Esempio n. 2
0
 private void OnImageStored(object sender, ImageStoredEventArgs e)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new ImageStoredEventHandler(OnImageStored), new object[] { sender, e });
     }
     else
     {
         try
         {
             if (pacsmode)
             {
                 DataSet  dicom = e.DataSet;
                 DicomDir dir   = new DicomDir(".");
                 dir.Add(dicom);
                 dir.Save();
             }
             else
             {
                 NewBrowser(e.DataSet);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(Logging.Log(ex));
         }
     }
 }
Esempio n. 3
0
        public void ManualCreateTest()
        {
            lock (sentry)
            {
                string folder = Path.Combine(Tools.RootFolder, @"EK\Capture\Dicom\DicomToolKit\Test\Data\DicomDir");
                string path   = Path.Combine(folder, "ManualCreateTest");

                Directory.CreateDirectory(path);

                DicomDir dir = new DicomDir(path);
                dir.Empty();

                DateTime now = DateTime.Now;

                Patient patient = dir.NewPatient("Sadler^Michael", "12345");
                Study   study   = patient.NewStudy(now, now, Element.NewUid(), "1");
                Series  series  = study.NewSeries("CR", Element.NewUid());
                Image   image   = series.NewImage(Path.Combine(folder, "THGLUZ5J.dcm"));

                dir.Save();
                string before = Dump(dir, "before");

                dir = new DicomDir(path);
                string after = Dump(dir, "after");

                Assert.AreEqual(before, after, "before does not match after");
            }
        }
Esempio n. 4
0
        public static void OnImageStored(object sender, ImageStoredEventArgs e)
        {
            DataSet dicom = e.DataSet;

            DicomDir dir = new DicomDir(".");

            dir.Add(dicom);
            dir.Save();
        }
Esempio n. 5
0
        public void ManualExtraTagsTest()
        {
            string folder = Path.Combine(Tools.RootFolder, @"EK\Capture\Dicom\DicomToolKit\Test\Data\DicomDir");
            string path   = Path.Combine(folder, "ManualExtraTagsTest");

            DicomDir dir = new DicomDir(path);

            dir.Empty();

            DirectoryInfo working = new DirectoryInfo(path);

            working = Directory.CreateDirectory(path);

            int n = 0;

            // add each test image to the DICOMDIR
            foreach (string file in Directory.GetFiles(folder, "*.dcm"))
            {
                DataSet temp = new DataSet();
                temp.Read(file);

                // when you add an Image, you now get back a reference to the image
                Image image = dir.Add(temp, @"parent\child");

                // and you can apply some logic to add tags

                // either hard code them
                image.Elements.Set(t.InstanceNumber, n);
                // or add them if they exist in the original image
                if (temp.Contains(t.ImagePositionPatient))
                {
                    image.Elements.Add(temp[t.ImagePositionPatient]);
                }
                else
                {
                    image.Elements.Add(t.ImagePositionPatient, "1");
                }
                if (temp.Contains(t.ImageOrientationPatient))
                {
                    image.Elements.Add(temp[t.ImageOrientationPatient]);
                }
                else
                {
                    image.Elements.Add(t.ImageOrientationPatient, "2");
                }

                n++;
            }

            // write it out
            dir.Save();
        }
Esempio n. 6
0
        private void toolStripButton_OpenDicomDir_Click(object sender, EventArgs e)
        {
            var dicomDirPath = Path.Combine(dicomServiceWorker.StorageRootPath, toolStripComboBox_DicomDir.Text);

            if (!Directory.Exists(dicomDirPath))
            {
                Directory.CreateDirectory(dicomDirPath);
                var dicomDir = new DicomDir(dicomDirPath);
                dicomDir.Save();
            }

            LoadFile(Path.Combine(dicomDirPath, "DICOMDIR"));
            LoadAllDicomDir();
            RefreshControl();
        }
Esempio n. 7
0
        public static DicomDir Setup(string folder, string path)
        {
            DicomDir dir = new DicomDir(Path.Combine(folder, path));

            dir.Empty();

            // add each test image to the DICOMDIR
            foreach (string file in Directory.GetFiles(folder, "*.dcm"))
            {
                dir.Add(file);
            }

            // write it out
            dir.Save();

            return(dir);
        }
Esempio n. 8
0
        private long CreateDicomDirectory
        (
            CompositeInstanceDataSet dicomInstances,
            DirectoryInfo mediaDirectory,
            IDicomMediaProfileProcessor profileProcessor
        )
        {
            using (DicomDir dicomDir = new DicomDir(mediaDirectory.FullName))
            {
                List <string> createdFiles;


                createdFiles = ProcessDicomDir(mediaDirectory,
                                               dicomInstances,
                                               dicomDir,
                                               profileProcessor);

                dicomDir.SetFileSetId(mediaDirectory.Name);

                if (!string.IsNullOrEmpty(DescriptorFile))
                {
                    string descriptorFile;


                    descriptorFile = CopyDescriptorFile(mediaDirectory.FullName);

                    dicomDir.SetDescriptorFile(descriptorFile, DescriptorFileCharacterSet);

                    createdFiles.Add(descriptorFile);
                }

                profileProcessor.OnDicomDirCompleted(dicomDir.DataSet);

                dicomDir.Save( );

                createdFiles.Add(Path.Combine(mediaDirectory.FullName, "DICOMDIR"));

                return(GetFilesSize(createdFiles));
            }
        }
Esempio n. 9
0
        public void SaveToDicomDir(ReceivedDicomElements receivedDicomElements, string dicomDirName)
        {
            var message  = " -- DicomDir : " + dicomDirName + ", ";
            var hasError = true;

            try
            {
                if (receivedDicomElements.ImageSource == ImageSource.LocalDicomFile)
                {
                    message += "File : " + receivedDicomElements.FileName;
                }
                else
                {
                    message += string.Format("AeTitle : {0}, IpAddress : {1}", receivedDicomElements.CallingAeTitle, receivedDicomElements.IpAddress);
                }


                var dicomDirPath = Path.Combine(StorageRootPath, dicomDirName);
                var dicomDir     = new DicomDir(dicomDirPath);
                dicomDir.Add(receivedDicomElements.Elements);
                dicomDir.Save();
                receivedDicomElements.OnDicomDirSaved(dicomDirName);
                dicomServiceWorkerUser.OnDicomDirSaved(receivedDicomElements, dicomDirName);

                message  = "Save to dicom dir successfull!" + message;
                hasError = false;
            }
            catch (Exception ex)
            {
                message = "Save to dicom dir failed!" + message + "  " + ex.Message;
            }
            finally
            {
                dicomServiceWorkerUser.ShowMessage(message, hasError, false);
            }
        }
Esempio n. 10
0
        public void BaseQueryTest()
        {
            DicomDir dir = new DicomDir(".");

            DateTime now = DateTime.Now;

            // create a patient with two studies, each with one series,
            // the first series with one image, the second with two
            Patient patient = dir.NewPatient("Patient^Test", "10");
            Study   study   = patient.NewStudy(now, now, "10", "10");
            Series  series  = study.NewSeries("CR", "10");
            Image   image   = series.NewImage("10"); image.ReferencedSOPInstanceUIDinFile = "10";

            study  = patient.NewStudy(now, now, "20", "20");
            series = study.NewSeries("CR", "20");
            image  = series.NewImage("20"); image.ReferencedSOPInstanceUIDinFile = "20";
            image  = series.NewImage("30"); image.ReferencedSOPInstanceUIDinFile = "30";

            // create a patient with one study, containing two series,
            // the first series with two images, the second with one
            patient = dir.NewPatient("Subject^Test", "20");
            study   = patient.NewStudy(now, now, "30", "30");
            series  = study.NewSeries("DX", "30");
            image   = series.NewImage("40"); image.ReferencedSOPInstanceUIDinFile = "40";
            image   = series.NewImage("50"); image.ReferencedSOPInstanceUIDinFile = "50";
            series  = study.NewSeries("CR", "40");
            image   = series.NewImage("60"); image.ReferencedSOPInstanceUIDinFile = "60";

            // create a patient with a single study and series containing thrww images
            patient = dir.NewPatient("Patietn^Pink", "30");
            study   = patient.NewStudy(now, now, "40", "40");
            series  = study.NewSeries("MG", "50");
            image   = series.NewImage("70"); image.ReferencedSOPInstanceUIDinFile = "70";
            image   = series.NewImage("80"); image.ReferencedSOPInstanceUIDinFile = "80";
            image   = series.NewImage("90"); image.ReferencedSOPInstanceUIDinFile = "90";

            dir.Save();

            /*  P   ST  SE  IM
             *  10
             *      10
             *          10
             *              10
             *      20
             *          20
             *              20
             *              30
             *  20
             *      30
             *          30
             *              40
             *              50
             *          40
             *              60
             *  30
             *      40
             *          50
             *              70
             *              80
             *              90
             *
             */

            patient = new Patient();
            RecordCollection records = query("PATIENT", patient.Elements);

            Assert.AreEqual(3, records.Count);

            study   = new Study();
            records = query("STUDY", study.Elements);
            Assert.AreEqual(4, records.Count);

            series  = new Series();
            records = query("SERIES", series.Elements);
            Assert.AreEqual(5, records.Count);

            image   = new Image();
            records = query("IMAGE", image.Elements);
            Assert.AreEqual(9, records.Count);

            dir.Empty();
        }
Esempio n. 11
0
        public void BaseQueryTest()
        {
            DicomDir dir = new DicomDir(".");

            DateTime now = DateTime.Now;

            // create a patient with two studies, each with one series,
            // the first series with one image, the second with two
            Patient patient = dir.NewPatient("10", "10");
            Study   study   = patient.NewStudy(now, now, "10", "10");
            Series  series  = study.NewSeries("CR", "10");
            Image   image   = series.NewImage("10"); image.ReferencedSOPInstanceUIDinFile = "10";

            study  = patient.NewStudy(now, now, "20", "20");
            series = study.NewSeries("CR", "20");
            image  = series.NewImage("20"); image.ReferencedSOPInstanceUIDinFile = "20";
            image  = series.NewImage("30"); image.ReferencedSOPInstanceUIDinFile = "30";

            // create a patient with one study, containing two series,
            // the first series with two images, the second with one
            patient = dir.NewPatient("20", "20");
            study   = patient.NewStudy(now, now, "30", "30");
            series  = study.NewSeries("CR", "30");
            image   = series.NewImage("40"); image.ReferencedSOPInstanceUIDinFile = "40";
            image   = series.NewImage("50"); image.ReferencedSOPInstanceUIDinFile = "50";
            series  = study.NewSeries("CR", "40");
            image   = series.NewImage("60"); image.ReferencedSOPInstanceUIDinFile = "60";

            // create a patient with a single study and series containing thrww images
            patient = dir.NewPatient("30", "30");
            study   = patient.NewStudy(now, now, "40", "40");
            series  = study.NewSeries("CR", "50");
            image   = series.NewImage("70"); image.ReferencedSOPInstanceUIDinFile = "70";
            image   = series.NewImage("80"); image.ReferencedSOPInstanceUIDinFile = "80";
            image   = series.NewImage("90"); image.ReferencedSOPInstanceUIDinFile = "90";

            dir.Save();

            /*  P   ST  SE  IM
             *  10
             *      10
             *          10
             *              10
             *      20
             *          20
             *              20
             *              30
             *  20
             *      30
             *          30
             *              40
             *              50
             *          40
             *              60
             *  30
             *      40
             *          50
             *              70
             *              80
             *              90
             *
             */

            Assert.AreEqual("10,20,30", query("PATIENT", "10"));
            Assert.AreEqual("10", query("STUDY", "10"));
            Assert.AreEqual("10", query("SERIES", "10"));
            Assert.AreEqual("20,30", query("STUDY", "20"));
            Assert.AreEqual("20,30", query("SERIES", "20"));

            Assert.AreEqual("40,50,60", query("PATIENT", "20"));
            Assert.AreEqual("40,50,60", query("STUDY", "30"));
            Assert.AreEqual("40,50", query("SERIES", "30"));
            Assert.AreEqual("60", query("SERIES", "40"));

            Assert.AreEqual("70,80,90", query("PATIENT", "30"));
            Assert.AreEqual("70,80,90", query("STUDY", "40"));
            Assert.AreEqual("70,80,90", query("SERIES", "50"));

            Assert.AreEqual("10", query("IMAGE", "10"));
            Assert.AreEqual("20", query("IMAGE", "20"));
            Assert.AreEqual("30", query("IMAGE", "30"));
            Assert.AreEqual("40", query("IMAGE", "40"));
            Assert.AreEqual("50", query("IMAGE", "50"));
            Assert.AreEqual("60", query("IMAGE", "60"));
            Assert.AreEqual("70", query("IMAGE", "70"));
            Assert.AreEqual("80", query("IMAGE", "80"));
            Assert.AreEqual("90", query("IMAGE", "90"));

            dir.Empty();
        }
Esempio n. 12
0
        private MemoryStream ExportToDICOMDIR(ref ZipFile zip, List <DicomDataSet> datasets, ExportOptions options)
        {
            DicomDir     dir;
            string       dirDestination = string.Empty;
            string       folderPath;
            MemoryStream zipStream = new MemoryStream();

            dirDestination = GetDestinationFolder();
            if (!Directory.Exists(dirDestination))
            {
                Directory.CreateDirectory(dirDestination);
            }
            dir        = new DicomDir(dirDestination);
            folderPath = Path.Combine(dirDestination, @"DICOM\");
            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            try
            {
                Dictionary <string, int> studies = new Dictionary <string, int>();
                Dictionary <string, int> series  = new Dictionary <string, int>();
                int nextStudy  = 0;
                int nextSeries = 0;

                ExportExtensions.ResetAnonymization();
                foreach (DicomDataSet dataset in datasets)
                {
                    string studyInstance  = dataset.GetValue <string>(DicomTag.StudyInstanceUID, string.Empty);
                    string seriesInstance = dataset.GetValue <string>(DicomTag.SeriesInstanceUID, string.Empty);
                    string sopInstance    = dataset.GetValue <string>(DicomTag.SOPInstanceUID, string.Empty);
                    string fileName       = sopInstance + ".dcm";
                    string path           = GetFolderName(studies, series, ref nextStudy, ref nextSeries, studyInstance, seriesInstance);
                    if (zip == null)
                    {
                        zip = new ZipFile();
                    }

                    if (options.FileFormat.ToLower() == "dicomzip" && !string.IsNullOrEmpty(options.DczPassword))
                    {
                        zip.Password = options.DczPassword;
                    }

                    if (options.Anonymize)
                    {
                        dataset.Anonymize();
                    }
                    dataset.Save(folderPath + fileName, DicomDataSetSaveFlags.MetaHeaderPresent);
                    zip.AddEntry(@"DICOM\" + fileName, dataset.ToStream());
                    dir.InsertDataSet(dataset, folderPath + fileName);
                }

                dir.Save();
                if (zip != null)
                {
                    zip.AddFile(dirDestination + "DICOMDIR", string.Empty);
                    if (options.IncludeViewer)
                    {
                        IncludeViewer(ref zip);
                    }
                    zip.Save(zipStream);
                    zip.Dispose();
                }
                zipStream.Position = 0;
            }
            finally
            {
                if (!string.IsNullOrEmpty(dirDestination))
                {
                    if (Directory.Exists(dirDestination))
                    {
                        Directory.Delete(dirDestination, true);
                    }
                }
            }
            return(zipStream);
        }