diff --git a/IRaCIS.Core.Application/Helper/OtherTool/DicomSortHelper.cs b/IRaCIS.Core.Application/Helper/OtherTool/DicomSortHelper.cs index 4bd94512d..08947e1fa 100644 --- a/IRaCIS.Core.Application/Helper/OtherTool/DicomSortHelper.cs +++ b/IRaCIS.Core.Application/Helper/OtherTool/DicomSortHelper.cs @@ -178,11 +178,10 @@ public static class DicomPixelMasker public static async Task MaskAsync( Stream input, IEnumerable regions, - DicomMaskOptions? options = null, - CancellationToken cancellationToken = default) + DicomMaskOptions? options = null) { var output = new MemoryStream(); - await MaskAsync(input, output, regions, options, cancellationToken).ConfigureAwait(false); + await MaskAsync(input, output, regions, options).ConfigureAwait(false); output.Position = 0; return output; } @@ -211,6 +210,7 @@ public static class DicomPixelMasker var workingDataset = workingFile.Dataset; var originalPhotometric = originalDataset.GetSingleValueOrDefault(DicomTag.PhotometricInterpretation, string.Empty); + Console.WriteLine($"Original Photometric={originalPhotometric}, Original TS={originalTs.UID.UID}"); var rows = workingDataset.GetSingleValue(DicomTag.Rows); diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 145e5913c..b58e2fb2b 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -2965,6 +2965,12 @@ + + + 标注遮盖影像 + + + 指定资源Id,渲染Dicom检查的Jpeg预览图像 Dicom检查的Id diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs index 6622be5fa..dc3bcccc4 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs @@ -1,4 +1,5 @@ using FellowOakDicom; +using IRaCIS.Core.Application.Helper; using IRaCIS.Core.Application.Service.ImageAndDoc.DTO; using IRaCIS.Core.Domain.Share; using Newtonsoft.Json; @@ -963,7 +964,7 @@ namespace IRaCIS.Core.Application.Contracts } - public class SubjectVisitMarkQuery:PageInput + public class SubjectVisitMarkQuery : PageInput { public Guid TrialId { get; set; } @@ -1047,4 +1048,15 @@ namespace IRaCIS.Core.Application.Contracts public List UploadStudyList { get; set; } } + + public class StudyMaskImageCommand + { + public Guid? SeriesId { get; set; } + + public List? InstanceIdList { get; set; } + + public List MaskRegionList { get; set; } + + + } } diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs index 110d5e0b1..c85d17a6c 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs @@ -7,6 +7,7 @@ using IRaCIS.Core.Infrastructure; using Medallion.Threading; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System.Drawing; using ZiggyCreatures.Caching.Fusion; namespace IRaCIS.Core.Application.Service.ImageAndDoc @@ -25,7 +26,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc IRepository _studyMonitorRepository, IRepository _systemAnonymizationRepository, IRepository _noneDicomStudyRepository, - IDistributedLockProvider _distributedLockProvider, + IDistributedLockProvider _distributedLockProvider, IOSSService _oSSService, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer, IFusionCache _fusionCache) : BaseService, IStudyService { @@ -66,6 +67,53 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc } + /// + /// 标注遮盖影像 + /// + /// + public async Task StudyMaskImage(StudyMaskImageCommand inCommand) + { + if (inCommand.SeriesId == null && inCommand.InstanceIdList == null) + { + return ResponseOutput.NotOk("SeriesId and InstanceIdList can not both be null"); + } + + var instancePathList = new List(); + + if (inCommand.SeriesId == null && inCommand.InstanceIdList != null) + { + instancePathList = await _dicomInstanceRepository.Where(t => inCommand.InstanceIdList.Contains(t.Id)).Select(t => t.Path).ToListAsync(); + + } + else + { + instancePathList = await _dicomInstanceRepository.Where(t => t.SeriesId == inCommand.SeriesId).Select(t => t.Path).ToListAsync(); + } + + foreach (var path in instancePathList) + { + try + { + var inputStream = await _oSSService.GetStreamFromOSSAsync(path); + + var outPutStream = await DicomPixelMasker.MaskAsync(inputStream, inCommand.MaskRegionList); + + var prefix = path.Substring(1, path.LastIndexOf('/') - 1); + await _oSSService.UploadToOSSAsync(outPutStream, prefix, $"MaskImage_{Path.GetFileName(path)}"); + } + catch (Exception ex) + { + + Log.Logger.Error(ex, $"StudyMaskImage Error for InstanceIdList Path:{path} {ex.Message}"); + } + + } + + return ResponseOutput.Ok(); + + + } + [TrialGlobalLimit("AfterStopCannNotOpt")] public async Task PreArchiveDicomStudy(PreArchiveDicomStudyCommand preArchiveStudyCommand) @@ -324,7 +372,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc } - + var @lock2 = _distributedLockProvider.CreateLock($"StudyCommit"); @@ -334,7 +382,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc await _dicomInstanceRepository.SaveChangesAsync(); } - await _fileUploadRecordRepository.BatchUpdateNoTrackingAsync(t => t.UploadBatchId == incommand.UploadBatchId, u => new FileUploadRecord() { StudyCode = findStudy.StudyCode }); + await _fileUploadRecordRepository.BatchUpdateNoTrackingAsync(t => t.UploadBatchId == incommand.UploadBatchId, u => new FileUploadRecord() { StudyCode = findStudy.StudyCode }); } catch (Exception ex) { @@ -437,7 +485,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc Id = t.Id, Bodypart = t.BodyPart, - BodyPartForEditOther=t.BodyPartForEditOther, + BodyPartForEditOther = t.BodyPartForEditOther, Modalities = t.Modality, diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 4539d1d72..7825aed6a 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -129,8 +129,8 @@ namespace IRaCIS.Core.Application.Service public async Task MaskImage() { - var sourceDir = @"D:\images"; - var targetDir = @"D:\images\after"; + var sourceDir = @"D:\images\11\像素匿名\隐私信息2&测量值\08\08017\基线(V1)\ST01371_1970-01-01_US\IMAGE"; + var targetDir = @"D:\images\11\像素匿名\隐私信息2&测量值\08\08017\基线(V1)\ST01371_1970-01-01_US\IMAGE\after"; Directory.CreateDirectory(targetDir); var regions = new[] @@ -138,7 +138,7 @@ namespace IRaCIS.Core.Application.Service new MaskRegion(0, 0, 200, 200) }; - foreach (var inputPath in Directory.EnumerateFiles(sourceDir, "*.dcm", SearchOption.TopDirectoryOnly)) + foreach (var inputPath in Directory.EnumerateFiles(sourceDir, "IM_*", SearchOption.TopDirectoryOnly)) { var relativePath = Path.GetRelativePath(sourceDir, inputPath); var outputPath = Path.Combine(targetDir, relativePath);