123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using Vinno.vCloud.Common.Vid2;
- using Dicom;
- namespace VidProcessService.Utilities
- {
- public class VinnoExtendedDataGenerator
- {
- private readonly static List<VidTag> _uploadVidTags = new List<VidTag>()
- {
- new VidTag("0028","0030"),
- new VidTag("0018","602E"),
- new VidTag("0018","602C"),
- new VidTag("0018","6024"),
- new VidTag("0018","6026"),
- };
- public static VidExtendedData Generate(DicomDataset dataSet)
- {
- var dic = new Dictionary<VidTag, IVidValue>();
- var vidExtendedData = new VidExtendedData(dic);
- AddDicomItem(dic, dataSet);
- return vidExtendedData;
- }
- private static void AddDicomItem(Dictionary<VidTag, IVidValue> dic, DicomDataset dataSet)
- {
- foreach (var item in dataSet)
- {
- var vidTag = new VidTag($"{item.Tag.Group:x4}".ToUpper(), $"{item.Tag.Element:x4}".ToUpper());
- if (item is DicomStringElement element)
- {
- AddVidValue(dic, vidTag, new VidStringValueElement(element.Get<string>()));
- continue;
- }
- if (item is DicomValueElement<ushort> uShortElement)
- {
- AddVidValue(dic, vidTag, new VidUshortValueElement(uShortElement.Get<ushort>()));
- continue;
- }
- if (item is DicomValueElement<short> shortElement)
- {
- AddVidValue(dic, vidTag, new VidShortValueElement(shortElement.Get<short>()));
- continue;
- }
- if (item is DicomValueElement<long> longElement)
- {
- AddVidValue(dic, vidTag, new VidLongValueElement(longElement.Get<long>()));
- continue;
- }
- if (item is DicomValueElement<ulong> uLongElement)
- {
- AddVidValue(dic, vidTag, new VidUlongValueElement(uLongElement.Get<ulong>()));
- continue;
- }
- if (item is DicomValueElement<double> doubleElement)
- {
- AddVidValue(dic, vidTag, new VidDoubleValueElement(doubleElement.Get<double>()));
- continue;
- }
- if (item is DicomValueElement<int> intElement)
- {
- AddVidValue(dic, vidTag, new VidIntegerValueElement(intElement.Get<int>()));
- continue;
- }
- if (item is DicomValueElement<uint> uIntElement)
- {
- AddVidValue(dic, vidTag, new VidUintValueElement(uIntElement.Get<uint>()));
- continue;
- }
- if (item is DicomValueElement<byte> byteElement)
- {
- AddVidValue(dic, vidTag, new VidByteValueElement(byteElement.Get<byte>()));
- continue;
- }
- if (item is DicomSequence doDicomSequence)
- {
- foreach (var dataSetItem in doDicomSequence.Items)
- {
- AddDicomItem(dic, dataSetItem);
- }
- }
- }
- }
- private static void AddVidValue(Dictionary<VidTag, IVidValue> dic, VidTag vidTag, IVidValue vidValue)
- {
- var vidTagkey = dic.Keys.FirstOrDefault(v => v.Group == vidTag.Group && v.Element == vidTag.Element);
- if (vidTagkey == null)
- {
- if (_uploadVidTags?.Count > 0)
- {
- var uploadVidTag = _uploadVidTags.FirstOrDefault(v => v.Group == vidTag.Group && v.Element == vidTag.Element);
- if (uploadVidTag != null)
- {
- dic.Add(vidTag, vidValue);
- }
- }
- else
- {
- dic.Add(vidTag, vidValue);
- }
- }
- }
- }
- }
|