Exemplo n.º 1
0
        public void DicomValidation_AddInvalidData()
        {
            var ds         = new DicomDataset();
            var invalidUid = "1.2.315.6666.008965..19187632.1";

            // trying to add this invalidUid should throw exception
            Assert.Throws <DicomValidationException>(() => ds.Add(DicomTag.StudyInstanceUID, invalidUid));

            ds.AutoValidate = false;
            // if AutoValidate is turned off, the invalidUid should be able to be added
            ds.Add(DicomTag.StudyInstanceUID, invalidUid);
            Assert.Equal(invalidUid, ds.GetSingleValue <string>(DicomTag.StudyInstanceUID));

            var tmpFile = Path.GetTempFileName();

            ds.Add(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage);
            ds.Add(DicomTag.SOPInstanceUID, DicomUIDGenerator.GenerateNew().UID);
            // save this invalid dicomdataset
            (new DicomFile(ds)).Save(tmpFile);

            // reading of this invalid dicomdataset should be possible
            var dsFile = DicomFile.Open(tmpFile);

            Assert.Equal(invalidUid, dsFile.Dataset.GetSingleValue <string>(DicomTag.StudyInstanceUID));

            // but the validation should still work
            Assert.Throws <DicomValidationException>(() => dsFile.Dataset.Validate());
        }
        public void Generate_MultipleInParallel_AllValuesUnique()
        {
            const int n    = 100000;
            var       uids = new string[n];

            Parallel.For(0, n, i => { uids[i] = DicomUIDGenerator.GenerateNew().UID; });
            Assert.Equal(n, uids.Distinct().Count());
        }
        public void Generate_SourceUidKnown_ReturnsMappedDestinationUid()
        {
            var source = DicomUIDGenerator.GenerateNew();

            var generator = new DicomUIDGenerator();
            var expected  = generator.Generate(source);
            var actual    = generator.Generate(source);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 4
0
        public void AnonymizeInPlace_SequenceToKeep_NestedDatasetsShouldBeParsed()
        {
            const string fileName      = "GH610.dcm";
            var          tag1          = DicomTag.ROIContourSequence;
            var          tag2          = DicomTag.ContourSequence;
            var          tag3          = DicomTag.ContourImageSequence;
            var          generatedUid1 = DicomUIDGenerator.GenerateNew();
            var          generatedUid2 = DicomUIDGenerator.GenerateNew();

#if NETFX_CORE
            var dataset = Dicom.Helpers.ApplicationContent.OpenDicomFileAsync($"Data/{fileName}").Result.Dataset;
#else
            var dataset = DicomFile.Open($"./Test Data/{fileName}").Dataset;
#endif
            dataset.Add(new DicomSequence(tag1, new DicomDataset(
                                              new DicomSequence(tag2, new DicomDataset(
                                                                    new DicomSequence(tag3,
                                                                                      new DicomDataset(
                                                                                          new DicomUniqueIdentifier(DicomTag.ReferencedSOPInstanceUID, generatedUid1.UID),
                                                                                          new DicomIntegerString(DicomTag.ReferencedFrameNumber, 1)
                                                                                          ),
                                                                                      new DicomDataset(
                                                                                          new DicomUniqueIdentifier(DicomTag.ReferencedSOPInstanceUID, generatedUid2.UID),
                                                                                          new DicomIntegerString(DicomTag.ReferencedFrameNumber, 2)
                                                                                          )
                                                                                      ))
                                                                ))
                                          ));

            var anonymizer = new DicomAnonymizer();
            anonymizer.AnonymizeInPlace(dataset);

            Assert.True(dataset.Contains(tag1));

            var sequence1 = dataset.Get <DicomSequence>(tag1);
            var sequence2 = sequence1.Items[0].Get <DicomSequence>(tag2);
            var sequence3 = sequence2.Items[0].Get <DicomSequence>(tag3);
            Assert.NotEqual(sequence3.Items[0].Get <DicomUID>(DicomTag.ReferencedSOPInstanceUID), sequence3.Items[1].Get <DicomUID>(DicomTag.ReferencedSOPInstanceUID));
            Assert.NotEqual(generatedUid1, sequence3.Items[0].Get <DicomUID>(DicomTag.ReferencedSOPInstanceUID));
            Assert.NotEqual(generatedUid2, sequence3.Items[1].Get <DicomUID>(DicomTag.ReferencedSOPInstanceUID));
            Assert.Equal(1, sequence3.Items[0].Get <int>(DicomTag.ReferencedFrameNumber));
            Assert.Equal(2, sequence3.Items[1].Get <int>(DicomTag.ReferencedFrameNumber));
        }
Exemplo n.º 5
0
        public static DicomUID Generate()
        {
            var generator = new DicomUIDGenerator();

            return(DicomUIDGenerator.GenerateNew());
        }