Ejemplo n.º 1
0
 public DicomFile(DicomDataset dataset)
 {
     Dataset      = dataset;
     FileMetaInfo = new DicomFileMetaInformation(Dataset);
     Format       = DicomFileFormat.DICOM3;
     IsPartial    = false;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DicomFileMetaInformation"/> class.
        /// </summary>
        /// <param name="metaInfo">DICOM file meta information to be updated.</param>
        public DicomFileMetaInformation(DicomFileMetaInformation metaInfo)
        {
            this.Version = new byte[] { 0x00, 0x01 };

            if (metaInfo.Contains(DicomTag.MediaStorageSOPClassUID))
            {
                this.MediaStorageSOPClassUID = metaInfo.MediaStorageSOPClassUID;
            }
            if (metaInfo.Contains(DicomTag.MediaStorageSOPInstanceUID))
            {
                this.MediaStorageSOPInstanceUID = metaInfo.MediaStorageSOPInstanceUID;
            }
            if (metaInfo.Contains(DicomTag.TransferSyntaxUID))
            {
                this.TransferSyntax = metaInfo.TransferSyntax;
            }

            this.ImplementationClassUID    = DicomImplementation.ClassUID;
            this.ImplementationVersionName = DicomImplementation.Version;

            var aet = CreateSourceApplicationEntityTitle();

            if (aet != null)
            {
                this.SourceApplicationEntityTitle = aet;
            }
        }
Ejemplo n.º 3
0
        public void BeginSave(string fileName, AsyncCallback callback, object state)
        {
            if (Format == DicomFileFormat.ACRNEMA1 || Format == DicomFileFormat.ACRNEMA2)
            {
                throw new DicomFileException(this, "Unable to save ACR-NEMA file");
            }

            if (Format == DicomFileFormat.DICOM3NoFileMetaInfo)
            {
                // create file meta information from dataset
                FileMetaInfo = new DicomFileMetaInformation(Dataset);
            }

            File = new FileReference(fileName);
            File.Delete();

            OnSave();

            FileByteTarget target = new FileByteTarget(File);

            EventAsyncResult result = new EventAsyncResult(callback, state);

            DicomFileWriter writer = new DicomFileWriter(DicomWriteOptions.Default);

            writer.BeginWrite(target, FileMetaInfo, Dataset, OnWriteComplete, new Tuple <DicomFileWriter, EventAsyncResult>(writer, result));
        }
Ejemplo n.º 4
0
        public void Constructor_FromFileMetaInformation_ShouldNotThrow()
        {
            var metaInfo  = new DicomFileMetaInformation();
            var exception = Record.Exception(() => new DicomFileMetaInformation(metaInfo));

            Assert.Null(exception);
        }
Ejemplo n.º 5
0
 public DicomFile(DicomDataset dataset)
 {
     Dataset = dataset;
     FileMetaInfo = new DicomFileMetaInformation(Dataset);
     Format = DicomFileFormat.DICOM3;
     IsPartial = false;
 }
Ejemplo n.º 6
0
 public DicomFile()
 {
     FileMetaInfo = new DicomFileMetaInformation();
     Dataset = new DicomDataset();
     Format = DicomFileFormat.DICOM3;
     IsPartial = false;
 }
Ejemplo n.º 7
0
 public DicomFile()
 {
     FileMetaInfo = new DicomFileMetaInformation();
     Dataset      = new DicomDataset();
     Format       = DicomFileFormat.DICOM3;
     IsPartial    = false;
 }
Ejemplo n.º 8
0
        public void Invalid_UI_values_for_meta_information_should_throw_on_set_when_validation_is_enabled(string sopInstanceUid)
        {
            var metaInfo = new DicomFileMetaInformation()
            {
                ValidateItems = true
            };

            Assert.Throws <DicomValidationException>(() => metaInfo.MediaStorageSOPInstanceUID = new DicomUID(sopInstanceUid, "test", DicomUidType.SOPInstance));
        }
Ejemplo n.º 9
0
        public void SourceApplicationEntityTitle_GetterWhenAttributeIncluded_ReturnsValue()
        {
            var metaInfo =
                new DicomFileMetaInformation(
                    new DicomDataset(
                        new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage),
                        new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, "1.2.3")));

            var exception = Record.Exception(() => { Assert.NotNull(metaInfo.SourceApplicationEntityTitle); });
            Assert.Null(exception);
        }
Ejemplo n.º 10
0
        public void ImplementationVersionName_GetterWhenAttributeMissing_ReturnsNull()
        {
            var metaInfo =
                new DicomFileMetaInformation(
                    new DicomDataset(
                        new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage),
                        new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, "1.2.3")));
            metaInfo.Remove(DicomTag.ImplementationVersionName);

            var exception = Record.Exception(() => { Assert.Null(metaInfo.ImplementationVersionName); });
            Assert.Null(exception);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DicomFileMetaInformation"/> class.
        /// </summary>
        /// <param name="metaInfo">DICOM file meta information to be updated.</param>
        public DicomFileMetaInformation(DicomFileMetaInformation metaInfo)
        {
            this.Version = new byte[] { 0x00, 0x01 };

            if (metaInfo.Contains(DicomTag.MediaStorageSOPClassUID)) this.MediaStorageSOPClassUID = metaInfo.MediaStorageSOPClassUID;
            if (metaInfo.Contains(DicomTag.MediaStorageSOPInstanceUID)) this.MediaStorageSOPInstanceUID = metaInfo.MediaStorageSOPInstanceUID;
            if (metaInfo.Contains(DicomTag.TransferSyntaxUID)) this.TransferSyntax = metaInfo.TransferSyntax;

            this.ImplementationClassUID = DicomImplementation.ClassUID;
            this.ImplementationVersionName = DicomImplementation.Version;
            this.SourceApplicationEntityTitle = CreateSourceApplicationEntityTitle();
        }
Ejemplo n.º 12
0
        public void ImplementationVersionName_GetterWhenAttributeIncluded_ReturnsValue()
        {
            var metaInfo =
                new DicomFileMetaInformation(
                    new DicomDataset(
                        new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage),
                        new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, "1.2.3")));

            var exception = Record.Exception(() => { Assert.NotNull(metaInfo.ImplementationVersionName); });

            Assert.Null(exception);
        }
Ejemplo n.º 13
0
        public void SourceApplicationEntityTitle_GetterWhenAttributeAlreadyExists_ReturnsValue()
        {
            var metaInfo =
                new DicomFileMetaInformation(
                    new DicomDataset(
                        new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage),
                        new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, "1.2.3"))
                    .Add(DicomTag.SourceApplicationEntityTitle, "ABCDEFG"));

            var exception = Record.Exception(() => { Assert.Equal(metaInfo.SourceApplicationEntityTitle, "ABCDEFG"); });

            Assert.Null(exception);
        }
Ejemplo n.º 14
0
        public void Invalid_UI_values_for_meta_information_should_not_throw_on_creation(string sopInstanceUid)
        {
            var dataset = new DicomDataset
            {
                AutoValidate = false
            };

            dataset.Add(
                new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage),
                new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, sopInstanceUid));
            var metaInfo = new DicomFileMetaInformation(dataset);

            Assert.Equal(sopInstanceUid, metaInfo.MediaStorageSOPInstanceUID.UID);
        }
Ejemplo n.º 15
0
        public void SourceApplicationEntityTitle_GetterWhenAttributeMissing_ReturnsNull()
        {
            var metaInfo =
                new DicomFileMetaInformation(
                    new DicomDataset(
                        new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage),
                        new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, "1.2.3")));

            metaInfo.Remove(DicomTag.SourceApplicationEntityTitle);

            var exception = Record.Exception(() => { Assert.Null(metaInfo.SourceApplicationEntityTitle); });

            Assert.Null(exception);
        }
Ejemplo n.º 16
0
        public void Construction_sets_validation_to_dataset_value_using_dataset_constructor(bool validate)
        {
            var dataset = new DicomDataset {
                ValidateItems = validate
            };

            dataset.Add(
                new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage),
                new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, "1.2.3.456"));
            var metaInfo = new DicomFileMetaInformation(dataset);

            Assert.Equal(validate, metaInfo.AutoValidate);
            Assert.Equal(validate, metaInfo.ValidateItems);
            Assert.Equal("1.2.3.456", metaInfo.MediaStorageSOPInstanceUID.UID);
        }
Ejemplo n.º 17
0
		public void Save(Stream stream) {
			if (Format == DicomFileFormat.ACRNEMA1 || Format == DicomFileFormat.ACRNEMA2)
				throw new DicomFileException(this, "Unable to save ACR-NEMA file");

			if (Format == DicomFileFormat.DICOM3NoFileMetaInfo) {
				// create file meta information from dataset
				FileMetaInfo = new DicomFileMetaInformation(Dataset);
			}

			OnSave();

			using (var target = new StreamByteTarget(stream)) {
				DicomFileWriter writer = new DicomFileWriter(DicomWriteOptions.Default);
				writer.Write(target, FileMetaInfo, Dataset);
			}
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="DicomFileMetaInformation"/> class.
        /// </summary>
        /// <param name="metaInfo">DICOM file meta information to be updated.</param>
        public DicomFileMetaInformation(DicomFileMetaInformation metaInfo)
        {
            Version = new byte[] { 0x00, 0x01 };

            if (metaInfo.Contains(DicomTag.MediaStorageSOPClassUID))
            {
                MediaStorageSOPClassUID = metaInfo.MediaStorageSOPClassUID;
            }
            if (metaInfo.Contains(DicomTag.MediaStorageSOPInstanceUID))
            {
                MediaStorageSOPInstanceUID = metaInfo.MediaStorageSOPInstanceUID;
            }
            if (metaInfo.Contains(DicomTag.TransferSyntaxUID))
            {
                TransferSyntax = metaInfo.TransferSyntax;
            }

            ImplementationClassUID    = DicomImplementation.ClassUID;
            ImplementationVersionName = DicomImplementation.Version;

            var aet = CreateSourceApplicationEntityTitle();

            if (aet != null)
            {
                SourceApplicationEntityTitle = aet;
            }

            if (metaInfo.Contains(DicomTag.SendingApplicationEntityTitle))
            {
                SendingApplicationEntityTitle = metaInfo.SendingApplicationEntityTitle;
            }
            if (metaInfo.Contains(DicomTag.ReceivingApplicationEntityTitle))
            {
                ReceivingApplicationEntityTitle = metaInfo.ReceivingApplicationEntityTitle;
            }
            if (metaInfo.Contains(DicomTag.PrivateInformationCreatorUID))
            {
                PrivateInformationCreatorUID = metaInfo.PrivateInformationCreatorUID;
            }
            if (metaInfo.Contains(DicomTag.PrivateInformation))
            {
                PrivateInformation = metaInfo.PrivateInformation;
            }
        }
Ejemplo n.º 19
0
		public void Save(string fileName) {
			if (Format == DicomFileFormat.ACRNEMA1 || Format == DicomFileFormat.ACRNEMA2)
				throw new DicomFileException(this, "Unable to save ACR-NEMA file");

			if (Format == DicomFileFormat.DICOM3NoFileMetaInfo) {
				// create file meta information from dataset
				FileMetaInfo = new DicomFileMetaInformation(Dataset);
			}

			File = new FileReference(fileName);
			File.Delete();

			OnSave();

			using (var target = new FileByteTarget(File)) {
				DicomFileWriter writer = new DicomFileWriter(DicomWriteOptions.Default);
				writer.Write(target, FileMetaInfo, Dataset);
			}
		}
Ejemplo n.º 20
0
        public void Save(Stream stream)
        {
            if (Format == DicomFileFormat.ACRNEMA1 || Format == DicomFileFormat.ACRNEMA2)
            {
                throw new DicomFileException(this, "Unable to save ACR-NEMA file");
            }

            if (Format == DicomFileFormat.DICOM3NoFileMetaInfo)
            {
                // create file meta information from dataset
                FileMetaInfo = new DicomFileMetaInformation(Dataset);
            }

            OnSave();

            using (var target = new StreamByteTarget(stream)) {
                DicomFileWriter writer = new DicomFileWriter(DicomWriteOptions.Default);
                writer.Write(target, FileMetaInfo, Dataset);
            }
        }
Ejemplo n.º 21
0
        public void Save(string fileName)
        {
            if (Format == DicomFileFormat.ACRNEMA1 || Format == DicomFileFormat.ACRNEMA2)
            {
                throw new DicomFileException(this, "Unable to save ACR-NEMA file");
            }

            if (Format == DicomFileFormat.DICOM3NoFileMetaInfo)
            {
                // create file meta information from dataset
                FileMetaInfo = new DicomFileMetaInformation(Dataset);
            }

            File = new FileReference(fileName);
            File.Delete();

            using (var target = new FileByteTarget(File)) {
                DicomFileWriter writer = new DicomFileWriter(DicomWriteOptions.Default);
                writer.Write(target, FileMetaInfo, Dataset);
            }
        }
Ejemplo n.º 22
0
        public void Construction_sets_validation_to_false_copy_constructor(bool validate, string sopInstanceUid, bool expectedError)
        {
            DicomFileMetaInformation existing, metaInfo;
            var dataset = new DicomDataset {
                ValidateItems = validate
            };

            if (expectedError)
            {
                // we test the dataset as well here
                Assert.Throws <DicomValidationException>(() => dataset.Add(
                                                             new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage),
                                                             new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, sopInstanceUid)));

                // such that we can construct it
                dataset.ValidateItems = false;
                dataset.AddOrUpdate(
                    new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage),
                    new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, sopInstanceUid));
                dataset.ValidateItems = validate;

                Assert.Throws <DicomValidationException>(() => new DicomFileMetaInformation(dataset));

                return;
            }
            else
            {
                dataset.Add(
                    new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage),
                    new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, sopInstanceUid));
                existing = new DicomFileMetaInformation(dataset);
            }

            metaInfo = new DicomFileMetaInformation(existing);

            Assert.Equal(validate, metaInfo.ValidateItems);
            Assert.Equal(validate, metaInfo.AutoValidate);
            Assert.Equal(sopInstanceUid, metaInfo.MediaStorageSOPInstanceUID.UID);
        }
Ejemplo n.º 23
0
        public void Construction_sets_validation_to_false_default_constructor()
        {
            var metaInfo = new DicomFileMetaInformation();

            Assert.False(metaInfo.ValidateItems);
        }
Ejemplo n.º 24
0
 public void Constructor_FromFileMetaInformation_ShouldNotThrow()
 {
     var metaInfo = new DicomFileMetaInformation();
     var exception = Record.Exception(() => new DicomFileMetaInformation(metaInfo));
     Assert.Null(exception);
 }
Ejemplo n.º 25
0
 public DicomFile()
 {
     FileMetaInfo = new DicomFileMetaInformation();
     Dataset      = new DicomDataset();
     Format       = DicomFileFormat.DICOM3;
 }
Ejemplo n.º 26
0
 public DicomFile()
 {
     FileMetaInfo = new DicomFileMetaInformation();
     Dataset      = new DicomDataset();
 }
Ejemplo n.º 27
0
 public DicomFile(DicomDataset dataset)
 {
     Dataset      = dataset;
     FileMetaInfo = new DicomFileMetaInformation(Dataset);
 }
Ejemplo n.º 28
0
		public DicomFile() {
			FileMetaInfo = new DicomFileMetaInformation();
			Dataset = new DicomDataset();
			Format = DicomFileFormat.DICOM3;
		}
Ejemplo n.º 29
0
		public void BeginSave(string fileName, AsyncCallback callback, object state) {
			if (Format == DicomFileFormat.ACRNEMA1 || Format == DicomFileFormat.ACRNEMA2)
				throw new DicomFileException(this, "Unable to save ACR-NEMA file");

			if (Format == DicomFileFormat.DICOM3NoFileMetaInfo) {
				// create file meta information from dataset
				FileMetaInfo = new DicomFileMetaInformation(Dataset);
			}

			File = new FileReference(fileName);
			File.Delete();

			OnSave();

			FileByteTarget target = new FileByteTarget(File);

			EventAsyncResult result = new EventAsyncResult(callback, state);

			DicomFileWriter writer = new DicomFileWriter(DicomWriteOptions.Default);
			writer.BeginWrite(target, FileMetaInfo, Dataset, OnWriteComplete, new Tuple<DicomFileWriter, EventAsyncResult>(writer, result));
		}