Ejemplo n.º 1
0
        public void GivenValidAndInvalidTags_WhenValidating_ThenShouldThrowException()
        {
            CustomTagEntry invalidEntry = DicomTag.PatientName.BuildCustomTagEntry();
            CustomTagEntry validEntry   = DicomTag.DeviceSerialNumber.BuildCustomTagEntry();

            Assert.Throws <CustomTagEntryValidationException>(() => _customTagEntryValidator.ValidateCustomTags(new CustomTagEntry[] { validEntry, invalidEntry }));
        }
Ejemplo n.º 2
0
        public async Task GivenValidInput_WhenAddCustomTagIsInvoked_ThenShouldSucceed()
        {
            DicomTag       tag   = DicomTag.DeviceSerialNumber;
            CustomTagEntry entry = tag.BuildCustomTagEntry();
            await _customTagService.AddCustomTagAsync(new CustomTagEntry[] { entry }, default);

            _customTagEntryValidator.ReceivedWithAnyArgs().ValidateCustomTags(default);
Ejemplo n.º 3
0
        /// <summary>
        /// Normalize custom tag entry before saving to CustomTagStore.
        /// </summary>
        /// <param name="customTagEntry">The custom tag entry.</param>
        /// <returns>Normalize custom tag entry.</returns>
        public static CustomTagEntry Normalize(this CustomTagEntry customTagEntry)
        {
            DicomTagParser dicomTagParser = new DicomTagParser();

            DicomTag[] tags;
            if (!dicomTagParser.TryParse(customTagEntry.Path, out tags, supportMultiple: false))
            {
                // not a valid dicom tag path
                throw new CustomTagEntryValidationException(
                          string.Format(CultureInfo.InvariantCulture, DicomCoreResource.InvalidCustomTag, customTagEntry));
            }

            DicomTag tag  = tags[0];
            string   path = tag.GetPath();
            string   vr   = customTagEntry.VR;

            // when VR is not specified for standard tag,
            if (!tag.IsPrivate && tag.DictionaryEntry != DicomDictionary.UnknownTag)
            {
                if (string.IsNullOrWhiteSpace(vr))
                {
                    vr = tag.GetDefaultVR()?.Code;
                }
            }

            vr = vr.ToUpperInvariant();

            return(new CustomTagEntry(path, vr, customTagEntry.Level, customTagEntry.Status));
        }
Ejemplo n.º 4
0
        public void GivenValidCustomTagEntry_WhenFormalizing_ThenShouldReturnSameEntry(CustomTagEntry entry)
        {
            CustomTagEntry normalized = entry.Normalize();

            Assert.Equal(entry.Path, normalized.Path);
            Assert.Equal(entry.VR, normalized.VR);
            Assert.Equal(entry.Level, normalized.Level);
        }
Ejemplo n.º 5
0
        public void GivenStandardTagWithoutVR_WhenFormalizing_ThenVRShouldBeFilled(string vr)
        {
            DicomTag       tag        = DicomTag.DeviceSerialNumber;
            CustomTagEntry entry      = new CustomTagEntry(tag.GetPath(), vr, CustomTagLevel.Instance, CustomTagStatus.Added);
            CustomTagEntry normalized = entry.Normalize();

            Assert.Equal(tag.GetDefaultVR().Code, normalized.VR);
        }
Ejemplo n.º 6
0
        public void GivenVROfLowerCase_WhenFormalizing_ThenVRShouldBeUpperCase()
        {
            DicomTag       tag        = DicomTag.DeviceLabel;
            CustomTagEntry entry      = new CustomTagEntry(tag.GetPath(), tag.GetDefaultVR().Code.ToLowerInvariant(), CustomTagLevel.Instance, CustomTagStatus.Added);
            CustomTagEntry normalized = entry.Normalize();

            Assert.Equal(entry.VR.ToUpperInvariant(), normalized.VR);
        }
Ejemplo n.º 7
0
        public void GivenStandardTagAsKeyword_WhenFormalizing_ThenVRShouldBeFilled()
        {
            DicomTag       tag          = DicomTag.DeviceSerialNumber;
            CustomTagEntry entry        = new CustomTagEntry(path: tag.DictionaryEntry.Keyword, tag.GetDefaultVR().Code, CustomTagLevel.Instance, CustomTagStatus.Added);
            string         expectedPath = tag.GetPath();
            CustomTagEntry normalized   = entry.Normalize();

            Assert.Equal(normalized.Path, expectedPath);
        }
Ejemplo n.º 8
0
        public void GivenStandardTagWithVR_WhenFormalizing_ThenVRShouldNotBeUpdated()
        {
            DicomTag       tag        = DicomTag.DeviceSerialNumber;
            string         vr         = DicomVR.CS.Code;
            CustomTagEntry entry      = new CustomTagEntry(tag.GetPath(), vr, CustomTagLevel.Instance, CustomTagStatus.Added);
            CustomTagEntry normalized = entry.Normalize();

            Assert.Equal(vr, normalized.VR);
        }
Ejemplo n.º 9
0
        [InlineData("12051003", DicomVRCode.OB)] // private tag
        public void GivenUnsupportedVR_WhenValidating_ThenShouldThrowException(string path, string vr)
        {
            CustomTagEntry entry = CreateCustomTagEntry(path, vr);

            Assert.Throws <CustomTagEntryValidationException>(() => { _customTagEntryValidator.ValidateCustomTags(new CustomTagEntry[] { entry }); });
        }
Ejemplo n.º 10
0
 public GetCustomTagResponse(CustomTagEntry customTagEntry)
 {
     CustomTag = customTagEntry;
 }
Ejemplo n.º 11
0
        public void GivenPrivateTagWithVR_WhenValidating_ThenShouldSucceed()
        {
            CustomTagEntry entry = CreateCustomTagEntry("12051003", DicomVRCode.AE);

            _customTagEntryValidator.ValidateCustomTags(new CustomTagEntry[] { entry });
        }
Ejemplo n.º 12
0
        public void GivenInvalidTag_WhenValidating_ThenShouldThrowException(string path)
        {
            CustomTagEntry entry = CreateCustomTagEntry(path, DicomVRCode.AE);

            Assert.Throws <CustomTagEntryValidationException>(() => { _customTagEntryValidator.ValidateCustomTags(new CustomTagEntry[] { entry }); });
        }
Ejemplo n.º 13
0
        public void GivenDuplicatedTag_WhenValidating_ThenShouldThrowException()
        {
            CustomTagEntry entry = DicomTag.PatientName.BuildCustomTagEntry();

            Assert.Throws <CustomTagEntryValidationException>(() => _customTagEntryValidator.ValidateCustomTags(new CustomTagEntry[] { entry, entry }));
        }
Ejemplo n.º 14
0
        public void GivenPrivateTagWithoutVR_WhenValidating_ThenShouldThrowException()
        {
            CustomTagEntry entry = CreateCustomTagEntry("12051003", string.Empty);

            Assert.Throws <CustomTagEntryValidationException>(() => _customTagEntryValidator.ValidateCustomTags(new CustomTagEntry[] { entry }));
        }
Ejemplo n.º 15
0
        public void GivenValidVR_WhenValidating_ThenShouldSucceed(string vr)
        {
            CustomTagEntry entry = CreateCustomTagEntry(DicomTag.DeviceSerialNumber.GetPath(), vr);

            _customTagEntryValidator.ValidateCustomTags(new CustomTagEntry[] { entry });
        }
        public void GivenStandardTagWithoutVR_WhenValidating_ThenShouldSucceed(string vr)
        {
            CustomTagEntry entry = new CustomTagEntry(DicomTag.DeviceSerialNumber.GetPath(), vr, CustomTagLevel.Instance);

            _customTagEntryValidator.ValidateCustomTags(new CustomTagEntry[] { entry });
        }
Ejemplo n.º 17
0
        [InlineData("CS")] // expected vr should be LO. CS is not acceptable
        public void GivenInvalidVR_WhenValidating_ThenShouldThrowException(string vr)
        {
            CustomTagEntry entry = CreateCustomTagEntry(DicomTag.DeviceSerialNumber.GetPath(), vr);

            Assert.Throws <CustomTagEntryValidationException>(() => { _customTagEntryValidator.ValidateCustomTags(new CustomTagEntry[] { entry }); });
        }
Ejemplo n.º 18
0
        public void GivenValidTag_WhenValidating_ThenShouldSucceed(string path)
        {
            CustomTagEntry entry = CreateCustomTagEntry(path, DicomVRCode.DS);

            _customTagEntryValidator.ValidateCustomTags(new CustomTagEntry[] { entry });
        }