示例#1
0
        [InlineData("012\n", ValidationErrorCode.InvalidCharacters)]                                                                // contains control character except Esc
        public void GivenInvalidLongString_WhenValidating_ThenShouldThrow(string value, ValidationErrorCode errorCode)
        {
            DicomElement element = new DicomLongString(DicomTag.WindowCenterWidthExplanation, value);
            var          ex      = Assert.Throws <ElementValidationException>(() => new LongStringValidation().Validate(element));

            Assert.Equal(ex.ErrorCode, errorCode);
        }
示例#2
0
        public async Task GivenValidAndInvalidTagValues_WhenValidate_ThenReturnedValidTagsAndStoredFailure()
        {
            DicomTag     tag1     = DicomTag.DeviceSerialNumber;
            DicomTag     tag2     = DicomTag.DeviceID;
            DicomDataset ds       = Samples.CreateRandomInstanceDataset();
            DicomElement element1 = new DicomLongString(tag1, "testvalue1");
            DicomElement element2 = new DicomLongString(tag2, "testvalue2");

            ds.Add(element1);
            ds.Add(element2);
            QueryTag queryTag1 = new QueryTag(new ExtendedQueryTagStoreEntry(1, tag1.GetPath(), tag1.GetDefaultVR().Code, null, QueryTagLevel.Instance, ExtendedQueryTagStatus.Ready, QueryStatus.Enabled, 0));
            QueryTag queryTag2 = new QueryTag(new ExtendedQueryTagStoreEntry(2, tag2.GetPath(), tag2.GetDefaultVR().Code, null, QueryTagLevel.Instance, ExtendedQueryTagStatus.Ready, QueryStatus.Enabled, 0));

            // Throw exception when validate element1
            var ex = ElementValidationExceptionFactory.CreateDateIsInvalidException("testname", "testvalue");

            _minimumValidator.When(x => x.Validate(element1))
            .Throw(ex);

            // only return querytag2
            long watermark      = 1;
            var  validQueryTags = await _datasetValidator.ValidateAsync(ds, watermark, new[] { queryTag1, queryTag2 });

            Assert.Single(validQueryTags);
            Assert.Same(queryTag2, validQueryTags.First());

            // error for querytag1 is logged
            await _tagErrorsService.Received(1)
            .AddExtendedQueryTagErrorAsync(queryTag1.ExtendedQueryTagStoreEntry.Key, ex.ErrorCode, 1, Arg.Any <CancellationToken>());
        }
示例#3
0
        public void GivenDicomTagWithDifferentVR_WhenGetSingleOrDefaultIsCalled_ThenShouldReturnNull()
        {
            DicomTag     tag        = DicomTag.AbortReason;
            DicomVR      expectedVR = DicomVR.CS;
            DicomElement element    = new DicomLongString(tag, "Value");

            _dicomDataset.Add(element);
            Assert.Null(_dicomDataset.GetSingleValueOrDefault <string>(tag, expectedVR));
        }
示例#4
0
        private string GetPatientId(DicomCFindRequest request)
        {
            // TODO: Get patientId from dataset.

            if (request.Dataset.Contains(PatientNumberTag))
            {
                DicomLongString dicomLongStringItem = request.Dataset.Get <DicomLongString>(PatientNumberTag);
            }

            return("dummy");
        }
		public void OnElement(IByteSource source, DicomTag tag, DicomVR vr, IByteBuffer data) {
			DicomElement element;
			switch (vr.Code) {
				case "AE": element = new DicomApplicationEntity(tag, data); break;
				case "AS": element = new DicomAgeString(tag, data); break;
				case "AT": element = new DicomAttributeTag(tag, data); break;
				case "CS": element = new DicomCodeString(tag, data); break;
				case "DA": element = new DicomDate(tag, data); break;
				case "DS": element = new DicomDecimalString(tag, data); break;
				case "DT": element = new DicomDateTime(tag, data); break;
				case "FD": element = new DicomFloatingPointDouble(tag, data); break;
				case "FL": element = new DicomFloatingPointSingle(tag, data); break;
				case "IS": element = new DicomIntegerString(tag, data); break;
				case "LO": element = new DicomLongString(tag, _encodings.Peek(), data); break;
				case "LT": element = new DicomLongText(tag, _encodings.Peek(), data); break;
				case "OB": element = new DicomOtherByte(tag, data); break;
				case "OD": element = new DicomOtherDouble(tag, data); break;
				case "OF": element = new DicomOtherFloat(tag, data); break;
				case "OW": element = new DicomOtherWord(tag, data); break;
				case "PN": element = new DicomPersonName(tag, _encodings.Peek(), data); break;
				case "SH": element = new DicomShortString(tag, _encodings.Peek(), data); break;
				case "SL": element = new DicomSignedLong(tag, data); break;
				case "SS": element = new DicomSignedShort(tag, data); break;
				case "ST": element = new DicomShortText(tag, _encodings.Peek(), data); break;
				case "TM": element = new DicomTime(tag, data); break;
				case "UC": element = new DicomUnlimitedCharacters(tag, _encodings.Peek(), data); break;
				case "UI": element = new DicomUniqueIdentifier(tag, data); break;
				case "UL": element = new DicomUnsignedLong(tag, data); break;
				case "UN": element = new DicomUnknown(tag, data); break;
				case "UR": element = new DicomUniversalResource(tag, _encodings.Peek(), data); break;
				case "US": element = new DicomUnsignedShort(tag, data); break;
				case "UT": element = new DicomUnlimitedText(tag, _encodings.Peek(), data); break;
				default:
					throw new DicomDataException("Unhandled VR in DICOM parser observer: {0}", vr.Code);
			}

			if (element.Tag == DicomTag.SpecificCharacterSet) {
				Encoding encoding = _encodings.Peek();
				if (element.Count > 0)
					encoding = DicomEncoding.GetEncoding(element.Get<string>(0));
				_encodings.Pop();
				_encodings.Push(encoding);
			}

			DicomDataset ds = _datasets.Peek();
			ds.Add(element);
		}
        /// <summary>
        /// Example *required* by the Anonymisation Engine
        /// </summary>
        /// <returns></returns>
        public static List <AnonExample> KeepItemExamples()
        {
            var output = new AnonExample();

            var value = "M";
            var item  = new DicomLongString(DicomTag.PatientSex, value);

            output.Input.Add(item + ": " + value);

            var dicomItem = KeepItem(null, null, item);

            AnonExample.InferOutput(item, dicomItem, output);

            return(new List <AnonExample> {
                output
            });
        }
示例#7
0
        private static DicomItem CreateDicomItem(DicomTag tag, string vr, object data)
        {
            DicomItem item;

            switch (vr)
            {
            case "AE":
                item = new DicomApplicationEntity(tag, (string[])data);
                break;

            case "AS":
                item = new DicomAgeString(tag, (string[])data);
                break;

            case "AT":
                item = new DicomAttributeTag(tag, ((string[])data).Select(ParseTag).ToArray());
                break;

            case "CS":
                item = new DicomCodeString(tag, (string[])data);
                break;

            case "DA":
                item = new DicomDate(tag, (string[])data);
                break;

            case "DS":
                item = new DicomDecimalString(tag, (string[])data);
                break;

            case "DT":
                item = new DicomDateTime(tag, (string[])data);
                break;

            case "FD":
                item = new DicomFloatingPointDouble(tag, (double[])data);
                break;

            case "FL":
                item = new DicomFloatingPointSingle(tag, (float[])data);
                break;

            case "IS":
                item = new DicomIntegerString(tag, (int[])data);
                break;

            case "LO":
                item = new DicomLongString(tag, (string[])data);
                break;

            case "LT":
                item = new DicomLongText(tag, ((string[])data).Single());
                break;

            case "OB":
                item = new DicomOtherByte(tag, (IByteBuffer)data);
                break;

            case "OD":
                item = new DicomOtherDouble(tag, (IByteBuffer)data);
                break;

            case "OF":
                item = new DicomOtherFloat(tag, (IByteBuffer)data);
                break;

            case "OL":
                item = new DicomOtherLong(tag, (IByteBuffer)data);
                break;

            case "OW":
                item = new DicomOtherWord(tag, (IByteBuffer)data);
                break;

            case "PN":
                item = new DicomPersonName(tag, (string[])data);
                break;

            case "SH":
                item = new DicomShortString(tag, (string[])data);
                break;

            case "SL":
                item = new DicomSignedLong(tag, (int[])data);
                break;

            case "SS":
                item = new DicomSignedShort(tag, (short[])data);
                break;

            case "ST":
                item = new DicomShortText(tag, ((string[])data)[0]);
                break;

            case "SQ":
                item = new DicomSequence(tag, ((DicomDataset[])data));
                break;

            case "TM":
                item = new DicomTime(tag, (string[])data);
                break;

            case "UC":
                item = new DicomUnlimitedCharacters(tag, ((string[])data).SingleOrDefault());
                break;

            case "UI":
                item = new DicomUniqueIdentifier(tag, (string[])data);
                break;

            case "UL":
                item = new DicomUnsignedLong(tag, (uint[])data);
                break;

            case "UN":
                item = new DicomUnknown(tag, (IByteBuffer)data);
                break;

            case "UR":
                item = new DicomUniversalResource(tag, ((string[])data).Single());
                break;

            case "US":
                item = new DicomUnsignedShort(tag, (ushort[])data);
                break;

            case "UT":
                item = new DicomUnlimitedText(tag, ((string[])data).Single());
                break;

            default:
                throw new NotSupportedException("Unsupported value representation");
            }
            return(item);
        }
        public void OnElement(IByteSource source, DicomTag tag, DicomVR vr, IByteBuffer data)
        {
            DicomElement element;

            switch (vr.Code)
            {
            case "AE":
                element = new DicomApplicationEntity(tag, data);
                break;

            case "AS":
                element = new DicomAgeString(tag, data);
                break;

            case "AT":
                element = new DicomAttributeTag(tag, data);
                break;

            case "CS":
                element = new DicomCodeString(tag, data);
                break;

            case "DA":
                element = new DicomDate(tag, data);
                break;

            case "DS":
                element = new DicomDecimalString(tag, data);
                break;

            case "DT":
                element = new DicomDateTime(tag, data);
                break;

            case "FD":
                element = new DicomFloatingPointDouble(tag, data);
                break;

            case "FL":
                element = new DicomFloatingPointSingle(tag, data);
                break;

            case "IS":
                element = new DicomIntegerString(tag, data);
                break;

            case "LO":
                element = new DicomLongString(tag, _encodings.Peek(), data);
                break;

            case "LT":
                element = new DicomLongText(tag, _encodings.Peek(), data);
                break;

            case "OB":
                element = new DicomOtherByte(tag, data);
                break;

            case "OD":
                element = new DicomOtherDouble(tag, data);
                break;

            case "OF":
                element = new DicomOtherFloat(tag, data);
                break;

            case "OL":
                element = new DicomOtherLong(tag, data);
                break;

            case "OW":
                element = new DicomOtherWord(tag, data);
                break;

            case "PN":
                element = new DicomPersonName(tag, _encodings.Peek(), data);
                break;

            case "SH":
                element = new DicomShortString(tag, _encodings.Peek(), data);
                break;

            case "SL":
                element = new DicomSignedLong(tag, data);
                break;

            case "SS":
                element = new DicomSignedShort(tag, data);
                break;

            case "ST":
                element = new DicomShortText(tag, _encodings.Peek(), data);
                break;

            case "TM":
                element = new DicomTime(tag, data);
                break;

            case "UC":
                element = new DicomUnlimitedCharacters(tag, _encodings.Peek(), data);
                break;

            case "UI":
                element = new DicomUniqueIdentifier(tag, data);
                break;

            case "UL":
                element = new DicomUnsignedLong(tag, data);
                break;

            case "UN":
                element = new DicomUnknown(tag, data);
                break;

            case "UR":
                element = new DicomUniversalResource(tag, _encodings.Peek(), data);
                break;

            case "US":
                element = new DicomUnsignedShort(tag, data);
                break;

            case "UT":
                element = new DicomUnlimitedText(tag, _encodings.Peek(), data);
                break;

            default:
                throw new DicomDataException("Unhandled VR in DICOM parser observer: {0}", vr.Code);
            }

            if (element.Tag == DicomTag.SpecificCharacterSet)
            {
                Encoding encoding = _encodings.Peek();
                if (element.Count > 0)
                {
                    encoding = DicomEncoding.GetEncoding(element.Get <string>(0));
                }

                _encodings.Pop();
                _encodings.Push(encoding);
            }

            DicomDataset ds = _datasets.Peek();

            ds.AddOrUpdate(element);
        }
示例#9
0
        public async Task GivenValidExtendedQueryTags_WhenGoThroughEndToEndScenario_ThenShouldSucceed()
        {
            // Prepare 3 extended query tags.
            // One is private tag on Instance level
            // To add private tag, need to add identification code element at first.
            DicomTag identificationCodeTag = new DicomTag(0x0407, 0x0010);

            DicomElement identificationCodeElement = new DicomLongString(identificationCodeTag, PrivateCreatorName);

            DicomTag privateTag = new DicomTag(0x0407, 0x1001, PrivateCreatorName);
            AddExtendedQueryTagEntry privateQueryTag = new AddExtendedQueryTagEntry {
                Path = privateTag.GetPath(), VR = DicomVRCode.SS, Level = QueryTagLevel.Instance, PrivateCreator = privateTag.PrivateCreator.Creator
            };

            // One is standard tag on Series level
            DicomTag standardTagSeries = DicomTag.ManufacturerModelName;
            AddExtendedQueryTagEntry standardTagSeriesQueryTag = new AddExtendedQueryTagEntry {
                Path = standardTagSeries.GetPath(), VR = standardTagSeries.GetDefaultVR().Code, Level = QueryTagLevel.Series
            };

            // One is standard tag on Study level
            DicomTag standardTagStudy = DicomTag.PatientSex;
            AddExtendedQueryTagEntry standardTagStudyQueryTag = new AddExtendedQueryTagEntry {
                Path = standardTagStudy.GetPath(), VR = standardTagStudy.GetDefaultVR().Code, Level = QueryTagLevel.Study
            };

            AddExtendedQueryTagEntry[] queryTags = new AddExtendedQueryTagEntry[] { privateQueryTag, standardTagSeriesQueryTag, standardTagStudyQueryTag };

            // Create 3 test files on same studyUid.
            string studyUid     = TestUidGenerator.Generate();
            string seriesUid1   = TestUidGenerator.Generate();
            string seriesUid2   = TestUidGenerator.Generate();
            string instanceUid1 = TestUidGenerator.Generate();
            string instanceUid2 = TestUidGenerator.Generate();
            string instanceUid3 = TestUidGenerator.Generate();

            // One is on seriesUid1 and instanceUid1
            DicomDataset dataset1 = Samples.CreateRandomInstanceDataset(studyInstanceUid: studyUid, seriesInstanceUid: seriesUid1, sopInstanceUid: instanceUid1);

            dataset1.Add(identificationCodeElement);
            dataset1.AddOrUpdate(new DicomSignedShort(privateTag, 1));
            dataset1.Add(standardTagSeries, "ManufacturerModelName1");
            dataset1.Add(standardTagStudy, "0");

            // One is on seriesUid1 and instanceUid2
            DicomDataset dataset2 = Samples.CreateRandomInstanceDataset(studyInstanceUid: studyUid, seriesInstanceUid: seriesUid1, sopInstanceUid: instanceUid2);

            dataset2.Add(identificationCodeElement);
            dataset2.AddOrUpdate(new DicomSignedShort(privateTag, 2));
            dataset2.Add(standardTagSeries, "ManufacturerModelName2");
            dataset2.Add(standardTagStudy, "0");

            // One is on seriesUid2 and instanceUid3
            DicomDataset dataset3 = Samples.CreateRandomInstanceDataset(studyInstanceUid: studyUid, seriesInstanceUid: seriesUid2, sopInstanceUid: instanceUid3);

            dataset3.Add(identificationCodeElement);
            dataset3.AddOrUpdate(new DicomSignedShort(privateTag, 3));
            dataset3.Add(standardTagSeries, "ManufacturerModelName3");
            dataset3.Add(standardTagStudy, "1");
            try
            {
                // Add extended query tags

                await _client.AddExtendedQueryTagAsync(queryTags);

                try
                {
                    foreach (var queryTag in queryTags)
                    {
                        GetExtendedQueryTagEntry returnTag = await(await _client.GetExtendedQueryTagAsync(queryTag.Path)).GetValueAsync();
                        CompareExtendedQueryTagEntries(queryTag, returnTag);
                    }

                    // Upload test files
                    IEnumerable <DicomFile> dicomFiles = new DicomDataset[] { dataset1, dataset2, dataset3 }.Select(dataset => new DicomFile(dataset));

                    await _client.StoreAsync(dicomFiles, studyInstanceUid : string.Empty, cancellationToken : default);

                    // Query on instance for private tag
                    DicomWebAsyncEnumerableResponse <DicomDataset> queryInstanceResponse = await _client.QueryAsync(new Uri($"/instances?{privateTag.GetPath()}=3", UriKind.Relative), cancellationToken : default);

                    DicomDataset[] instanceResult = await queryInstanceResponse.ToArrayAsync();

                    Assert.Single(instanceResult);
                    Assert.Equal(instanceUid3, instanceResult[0].GetSingleValue <string>(DicomTag.SOPInstanceUID));

                    // Query on series for standardTagSeries
                    DicomWebAsyncEnumerableResponse <DicomDataset> querySeriesResponse = await _client.QueryAsync(new Uri($"/series?{standardTagSeries.GetPath()}=ManufacturerModelName2", UriKind.Relative), cancellationToken : default);

                    DicomDataset[] seriesResult = await querySeriesResponse.ToArrayAsync();

                    Assert.Single(seriesResult);
                    Assert.Equal(seriesUid1, seriesResult[0].GetSingleValue <string>(DicomTag.SeriesInstanceUID));

                    // Query on study for standardTagStudy
                    DicomWebAsyncEnumerableResponse <DicomDataset> queryStudyResponse = await _client.QueryAsync(new Uri($"/studies?{standardTagStudy.GetPath()}=1", UriKind.Relative), cancellationToken : default);

                    DicomDataset[] studyResult = await queryStudyResponse.ToArrayAsync();

                    Assert.Single(studyResult);
                    Assert.Equal(studyUid, seriesResult[0].GetSingleValue <string>(DicomTag.StudyInstanceUID));
                }
                finally
                {
                    await _client.DeleteStudyAsync(studyUid);
                }
            }
            finally
            {
                // Cleanup extended query tags, also verify GetExtendedQueryTagsAsync.
                var responseQueryTags = await(await _client.GetExtendedQueryTagsAsync()).GetValueAsync();
                foreach (var rTag in responseQueryTags)
                {
                    if (queryTags.Any(tag => tag.Path == rTag.Path))
                    {
                        await _client.DeleteExtendedQueryTagAsync(rTag.Path);
                    }
                }
            }
        }
示例#10
0
        private static DicomItem CreateDicomItem(DicomTag tag, BsonValue data, DicomVR vr = null)
        {
            // Ok to throw an exception here - we should always be writing the VR into the Bson document if it's ambiguous
            if (vr == null)
            {
                vr = tag.DictionaryEntry.ValueRepresentations.Single();
            }

            DicomItem item;

            switch (vr.Code)
            {
            case "AE":
                item = new DicomApplicationEntity(tag, GetString(data));
                break;

            case "AS":
                item = new DicomAgeString(tag, GetString(data));
                break;

            case "AT":
                item = ParseAttributeTag(tag, data);
                break;

            case "CS":
                item = new DicomCodeString(tag, GetString(data));
                break;

            case "DA":
                item = new DicomDate(tag, GetString(data));
                break;

            case "DS":
                item = new DicomDecimalString(tag, GetString(data));
                break;

            case "DT":
                item = new DicomDateTime(tag, GetString(data));
                break;

            case "FD":
                item = new DicomFloatingPointDouble(tag, (double[])GetTypedArray <double>(data));
                break;

            case "FL":
                item = new DicomFloatingPointSingle(tag, (float[])GetTypedArray <float>(data));
                break;

            case "IS":
                item = new DicomIntegerString(tag, GetString(data));
                break;

            case "LO":
                item = new DicomLongString(tag, Encoding.UTF8, GetString(data));
                break;

            case "LT":
                item = new DicomLongText(tag, Encoding.UTF8, GetString(data));
                break;

            case "OB":
                item = data.IsBsonNull
                        ? new DicomOtherByte(tag)
                        : new DicomOtherByte(tag, data.AsByteArray);
                break;

            case "OD":
                item = new DicomOtherDouble(tag, (double[])GetTypedArray <double>(data));
                break;

            case "OF":
                item = new DicomOtherFloat(tag, (float[])GetTypedArray <float>(data));
                break;

            case "OL":
                item = new DicomOtherLong(tag, (uint[])GetTypedArray <uint>(data));
                break;

            case "OW":
                item = data.IsBsonNull
                        ? new DicomOtherWord(tag)
                        : new DicomOtherWord(tag, (ushort[])GetTypedArray <ushort>(data));
                break;

            case "PN":
                item = new DicomPersonName(tag, Encoding.UTF8, GetString(data));
                break;

            case "SH":
                item = new DicomShortString(tag, Encoding.UTF8, GetString(data));
                break;

            case "SL":
                item = new DicomSignedLong(tag, (int[])GetTypedArray <int>(data));
                break;

            case "SS":
                item = new DicomSignedShort(tag, (short[])GetTypedArray <short>(data));
                break;

            case "ST":
                item = new DicomShortText(tag, Encoding.UTF8, GetString(data));
                break;

            case "SQ":
                item = GetDicomSequence(tag, data);
                break;

            case "TM":
                item = new DicomTime(tag, GetString(data));
                break;

            case "UC":
                item = new DicomUnlimitedCharacters(tag, Encoding.UTF8, GetString(data));
                break;

            case "UI":
                item = new DicomUniqueIdentifier(tag, GetString(data));
                break;

            case "UL":
                item = new DicomUnsignedLong(tag, (uint[])GetTypedArray <uint>(data));
                break;

            case "UN":
                item = data.IsBsonNull
                        ? new DicomUnknown(tag)
                        : new DicomUnknown(tag, (byte[])GetTypedArray <byte>(data));
                break;

            case "UR":
                item = new DicomUniversalResource(tag, Encoding.UTF8, GetString(data));
                break;

            case "US":
                item = new DicomUnsignedShort(tag, (ushort[])GetTypedArray <ushort>(data));
                break;

            case "UT":
                item = new DicomUnlimitedText(tag, Encoding.UTF8, GetString(data));
                break;

            default:
                throw new NotSupportedException($"Unsupported value representation {vr}");
            }

            return(item);
        }
示例#11
0
        private static DicomItem CreateDicomItem(DicomTag tag, string vr, object data)
        {
            DicomItem item;

            switch (vr)
            {
            case "AE":
                item = new DicomApplicationEntity(tag, (string[])data);
                break;

            case "AS":
                item = new DicomAgeString(tag, (string[])data);
                break;

            case "AT":
                item = new DicomAttributeTag(tag, ((string[])data).Select(ParseTag).ToArray());
                break;

            case "CS":
                item = new DicomCodeString(tag, (string[])data);
                break;

            case "DA":
                item = new DicomDate(tag, (string[])data);
                break;

            case "DS":
                if (data is IByteBuffer dataBufferDS)
                {
                    item = new DicomDecimalString(tag, dataBufferDS);
                }
                else if (data is decimal[] dataAsNumbers)
                {
                    item = new DicomDecimalString(tag, dataAsNumbers);
                }
                else
                {
                    item = new DicomDecimalString(tag, (string[])data);
                }
                break;

            case "DT":
                item = new DicomDateTime(tag, (string[])data);
                break;

            case "FD":
                if (data is IByteBuffer dataBufferFD)
                {
                    item = new DicomFloatingPointDouble(tag, dataBufferFD);
                }
                else
                {
                    item = new DicomFloatingPointDouble(tag, (double[])data);
                }
                break;

            case "FL":
                if (data is IByteBuffer dataBufferFL)
                {
                    item = new DicomFloatingPointSingle(tag, dataBufferFL);
                }
                else
                {
                    item = new DicomFloatingPointSingle(tag, (float[])data);
                }
                break;

            case "IS":
                if (data is IByteBuffer dataBufferIS)
                {
                    item = new DicomIntegerString(tag, dataBufferIS);
                }
                else if (data is string[] dataAsStrings)
                {
                    item = new DicomIntegerString(tag, dataAsStrings);
                }
                else
                {
                    item = new DicomIntegerString(tag, (int[])data);
                }
                break;

            case "LO":
                item = new DicomLongString(tag, (string[])data);
                break;

            case "LT":
                if (data is IByteBuffer dataBufferLT)
                {
                    item = new DicomLongText(tag, _jsonTextEncodings, dataBufferLT);
                }
                else
                {
                    item = new DicomLongText(tag, data.AsStringArray().SingleOrEmpty());
                }
                break;

            case "OB":
                item = new DicomOtherByte(tag, (IByteBuffer)data);
                break;

            case "OD":
                item = new DicomOtherDouble(tag, (IByteBuffer)data);
                break;

            case "OF":
                item = new DicomOtherFloat(tag, (IByteBuffer)data);
                break;

            case "OL":
                item = new DicomOtherLong(tag, (IByteBuffer)data);
                break;

            case "OW":
                item = new DicomOtherWord(tag, (IByteBuffer)data);
                break;

            case "OV":
                item = new DicomOtherVeryLong(tag, (IByteBuffer)data);
                break;

            case "PN":
                item = new DicomPersonName(tag, (string[])data);
                break;

            case "SH":
                item = new DicomShortString(tag, (string[])data);
                break;

            case "SL":
                if (data is IByteBuffer dataBufferSL)
                {
                    item = new DicomSignedLong(tag, dataBufferSL);
                }
                else
                {
                    item = new DicomSignedLong(tag, (int[])data);
                }
                break;

            case "SQ":
                item = new DicomSequence(tag, ((DicomDataset[])data));
                break;

            case "SS":
                if (data is IByteBuffer dataBufferSS)
                {
                    item = new DicomSignedShort(tag, dataBufferSS);
                }
                else
                {
                    item = new DicomSignedShort(tag, (short[])data);
                }
                break;

            case "ST":
                if (data is IByteBuffer dataBufferST)
                {
                    item = new DicomShortText(tag, _jsonTextEncodings, dataBufferST);
                }
                else
                {
                    item = new DicomShortText(tag, data.AsStringArray().FirstOrEmpty());
                }
                break;

            case "SV":
                if (data is IByteBuffer dataBufferSV)
                {
                    item = new DicomSignedVeryLong(tag, dataBufferSV);
                }
                else if (data is string[] dataAsStrings)
                {
                    var dataAsLongs = dataAsStrings.Select(s => long.Parse(s)).ToArray();
                    item = new DicomSignedVeryLong(tag, dataAsLongs);
                }
                else
                {
                    item = new DicomSignedVeryLong(tag, (long[])data);
                }
                break;

            case "TM":
                item = new DicomTime(tag, (string[])data);
                break;

            case "UC":
                if (data is IByteBuffer dataBufferUC)
                {
                    item = new DicomUnlimitedCharacters(tag, _jsonTextEncodings, dataBufferUC);
                }
                else
                {
                    item = new DicomUnlimitedCharacters(tag, data.AsStringArray().SingleOrDefault());
                }
                break;

            case "UI":
                item = new DicomUniqueIdentifier(tag, (string[])data);
                break;

            case "UL":
                if (data is IByteBuffer dataBufferUL)
                {
                    item = new DicomUnsignedLong(tag, dataBufferUL);
                }
                else
                {
                    item = new DicomUnsignedLong(tag, (uint[])data);
                }
                break;

            case "UN":
                item = new DicomUnknown(tag, (IByteBuffer)data);
                break;

            case "UR":
                item = new DicomUniversalResource(tag, data.AsStringArray().SingleOrEmpty());
                break;

            case "US":
                if (data is IByteBuffer dataBufferUS)
                {
                    item = new DicomUnsignedShort(tag, dataBufferUS);
                }
                else
                {
                    item = new DicomUnsignedShort(tag, (ushort[])data);
                }
                break;

            case "UT":
                if (data is IByteBuffer dataBufferUT)
                {
                    item = new DicomUnlimitedText(tag, _jsonTextEncodings, dataBufferUT);
                }
                else
                {
                    item = new DicomUnlimitedText(tag, data.AsStringArray().SingleOrEmpty());
                }
                break;

            case "UV":
                if (data is IByteBuffer dataBufferUV)
                {
                    item = new DicomUnsignedVeryLong(tag, dataBufferUV);
                }
                else if (data is string[] dataAsStrings)
                {
                    var dataAsULongs = dataAsStrings.Select(s => ulong.Parse(s)).ToArray();
                    item = new DicomUnsignedVeryLong(tag, dataAsULongs);
                }
                else
                {
                    item = new DicomUnsignedVeryLong(tag, (ulong[])data);
                }
                break;

            default:
                throw new NotSupportedException("Unsupported value representation");
            }
            return(item);
        }