示例#1
0
        public JobMetadataBuilder Build(bool uploadMetadata, IReadOnlyList <string> dicomTags, IReadOnlyList <string> files)
        {
            Guard.Against.Null(files, nameof(files));

            var metadata = new JobMetadataBuilder();

            metadata.AddInstanceCount(files.Count);

            if (!uploadMetadata || dicomTags.IsNullOrEmpty())
            {
                return(metadata);
            }
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var dicomTagsToExtract = ConvertToDicomTags(dicomTags);
            var uniqueBags         = ExtractValues(dicomTagsToExtract, files);

            foreach (var tag in uniqueBags.Keys)
            {
                AddToMetadataDictionary(metadata, tag, uniqueBags[tag].ToList());
            }

            stopwatch.Stop();
            _logger.Log(LogLevel.Debug, $"Metadata built with {dicomTags.Count} DICOM tags and {files.Count} files in {stopwatch.ElapsedMilliseconds}ms.");
            return(metadata);
        }
示例#2
0
        private void AddToMetadataDictionary(JobMetadataBuilder metadata, DicomTag dicomTag, IList <string> values)
        {
            Guard.Against.Null(metadata, nameof(metadata));
            Guard.Against.Null(values, nameof(values));

            if (values.Count() == 0)
            {
                return;
            }
            else if (values.Count() == 1)
            {
                metadata.Add($"{dicomTag.Group:X4}{dicomTag.Element:X4}", values.First());
            }
            else
            {
                for (var i = 0; i < values.Count(); i++)
                {
                    metadata.Add($"{dicomTag.Group:X4}{dicomTag.Element:X4}-{i}", values.ElementAt(i));
                }
            }
        }