修改HIR 匿名化逻辑
continuous-integration/drone/push Build is running
Details
continuous-integration/drone/push Build is running
Details
parent
c290515e22
commit
972b18e4df
|
|
@ -203,6 +203,7 @@ app.MapControllers();
|
||||||
Log.Logger = new LoggerConfiguration()
|
Log.Logger = new LoggerConfiguration()
|
||||||
//.MinimumLevel.Information()
|
//.MinimumLevel.Information()
|
||||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
|
||||||
|
.MinimumLevel.Override("ZiggyCreatures.Caching.Fusion", LogEventLevel.Warning)
|
||||||
.WriteTo.Console()
|
.WriteTo.Console()
|
||||||
.WriteTo.File($"{AppContext.BaseDirectory}Serilogs/.log", rollingInterval: RollingInterval.Day)
|
.WriteTo.File($"{AppContext.BaseDirectory}Serilogs/.log", rollingInterval: RollingInterval.Day)
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using ZiggyCreatures.Caching.Fusion;
|
||||||
|
|
||||||
namespace IRaCIS.Core.SCP.Service
|
namespace IRaCIS.Core.SCP.Service
|
||||||
{
|
{
|
||||||
|
|
@ -449,7 +450,8 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
var dicomArchiveService = _serviceProvider.GetService<IDicomArchiveService>();
|
var dicomArchiveService = _serviceProvider.GetService<IDicomArchiveService>();
|
||||||
var _seriesRepository = _serviceProvider.GetService<IRepository<SCPSeries>>();
|
var _seriesRepository = _serviceProvider.GetService<IRepository<SCPSeries>>();
|
||||||
var _studyGroupRepository = _serviceProvider.GetService<IRepository<SCPStudyHospitalGroup>>();
|
var _studyGroupRepository = _serviceProvider.GetService<IRepository<SCPStudyHospitalGroup>>();
|
||||||
|
var _fusionCache = _serviceProvider.GetService<IFusionCache>();
|
||||||
|
var _systemAnonymizationRepository = _serviceProvider.GetService<IRepository<SystemAnonymization>>();
|
||||||
|
|
||||||
|
|
||||||
var _distributedLockProvider = _serviceProvider.GetService<IDistributedLockProvider>();
|
var _distributedLockProvider = _serviceProvider.GetService<IDistributedLockProvider>();
|
||||||
|
|
@ -462,21 +464,77 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// 直接拿 Dataset(已经完整)
|
||||||
|
var dataset = request.Dataset;
|
||||||
|
|
||||||
using (MemoryStream ms = new MemoryStream())
|
#region 匿名化
|
||||||
|
|
||||||
|
|
||||||
|
var anonymizeList = await _fusionCache.GetOrSetAsync(CacheKeys.SystemAnonymization, _ => CacheHelper.GetSystemAnonymizationListAsync(_systemAnonymizationRepository), TimeSpan.FromDays(7));
|
||||||
|
|
||||||
|
|
||||||
|
var fixedFiledList = anonymizeList.Where(t => t.IsFixed).ToList();
|
||||||
|
|
||||||
|
var ircFiledList = anonymizeList.Where(t => t.IsFixed == false).ToList();
|
||||||
|
|
||||||
|
foreach (var item in fixedFiledList)
|
||||||
{
|
{
|
||||||
await request.File.SaveAsync(ms);
|
|
||||||
|
var dicomTag = new DicomTag(Convert.ToUInt16(item.Group, 16), Convert.ToUInt16(item.Element, 16));
|
||||||
|
|
||||||
|
dataset.AddOrUpdate(dicomTag, item.ReplaceValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var item in ircFiledList)
|
||||||
|
{
|
||||||
|
|
||||||
|
var dicomTag = new DicomTag(Convert.ToUInt16(item.Group, 16), Convert.ToUInt16(item.Element, 16));
|
||||||
|
|
||||||
|
if (dicomTag == DicomTag.ClinicalTrialProtocolID)
|
||||||
|
{
|
||||||
|
dataset.AddOrUpdate(DicomTag.ClinicalTrialProtocolID, "");
|
||||||
|
|
||||||
|
}
|
||||||
|
if (dicomTag == DicomTag.ClinicalTrialSiteID)
|
||||||
|
{
|
||||||
|
dataset.AddOrUpdate(DicomTag.ClinicalTrialSiteID, "");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dicomTag == DicomTag.ClinicalTrialSubjectID)
|
||||||
|
{
|
||||||
|
dataset.AddOrUpdate(DicomTag.ClinicalTrialSubjectID, "");
|
||||||
|
|
||||||
|
}
|
||||||
|
if (dicomTag == DicomTag.ClinicalTrialTimePointID)
|
||||||
|
{
|
||||||
|
dataset.AddOrUpdate(DicomTag.ClinicalTrialTimePointID, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
//if (dicomTag == DicomTag.PatientID)
|
||||||
|
//{
|
||||||
|
// var pid = dataset.GetSingleValueOrDefault(DicomTag.PatientID, string.Empty);
|
||||||
|
|
||||||
|
// dataset.AddOrUpdate(DicomTag.PatientID, trialSiteInfo.TrialCode + "_" + pid);
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
// 构造 DicomFile(不用 Open)
|
||||||
|
var dicomFile = new DicomFile(dataset);
|
||||||
|
|
||||||
|
|
||||||
#region 1帧拆成多个固定大小的,方便移动端浏览
|
#region 1帧拆成多个固定大小的,方便移动端浏览
|
||||||
|
|
||||||
// 回到开头,读取 dicom
|
|
||||||
ms.Position = 0;
|
|
||||||
var dicomFile = DicomFile.Open(ms);
|
|
||||||
|
|
||||||
var numberOfFrames = dicomFile.Dataset.GetSingleValueOrDefault(DicomTag.NumberOfFrames, 1);
|
var numberOfFrames = dicomFile.Dataset.GetSingleValueOrDefault(DicomTag.NumberOfFrames, 1);
|
||||||
|
|
||||||
//多帧处理逻辑
|
//多帧处理逻辑
|
||||||
if(numberOfFrames > 1)
|
if (numberOfFrames > 1)
|
||||||
{
|
{
|
||||||
//一定要有像素数据才处理
|
//一定要有像素数据才处理
|
||||||
var pixelData = DicomPixelData.Create(dicomFile.Dataset);
|
var pixelData = DicomPixelData.Create(dicomFile.Dataset);
|
||||||
|
|
@ -615,10 +673,6 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
dicomFile.Dataset.AddOrUpdate(newFragments);
|
dicomFile.Dataset.AddOrUpdate(newFragments);
|
||||||
|
|
||||||
|
|
||||||
// 重新保存 dicom 到流
|
|
||||||
ms.SetLength(0);
|
|
||||||
|
|
||||||
dicomFile.Save(ms);
|
|
||||||
}
|
}
|
||||||
//传递过来的就是拆分的,但是是没有偏移表的,我需要自己创建偏移表,不然生成缩略图失败
|
//传递过来的就是拆分的,但是是没有偏移表的,我需要自己创建偏移表,不然生成缩略图失败
|
||||||
else if (syntax.IsEncapsulated && fragmentCount > pixelData.NumberOfFrames && originOffsetTable.Count == 0)
|
else if (syntax.IsEncapsulated && fragmentCount > pixelData.NumberOfFrames && originOffsetTable.Count == 0)
|
||||||
|
|
@ -672,10 +726,7 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
frag.OffsetTable.AddRange(bot.ToArray());
|
frag.OffsetTable.AddRange(bot.ToArray());
|
||||||
|
|
||||||
|
|
||||||
// 重新保存 DICOM 到流
|
|
||||||
ms.SetLength(0);
|
|
||||||
|
|
||||||
dicomFile.Save(ms);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -685,22 +736,15 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
Log.Logger.Warning($"CallingAE:{Association.CallingAE} CalledAE:{Association.CalledAE} 处理多帧失败,上传原始文件:{mutiEx.ToString()}");
|
Log.Logger.Warning($"CallingAE:{Association.CallingAE} CalledAE:{Association.CalledAE} 处理多帧失败,上传原始文件:{mutiEx.ToString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region 本地测试
|
#region 本地测试
|
||||||
//// --- 保存到本地文件测试 ---
|
//// --- 保存到本地文件测试 ---
|
||||||
//var localPath = @"D:\TestDicom-5.dcm";
|
//var localPath = @"D:\TestDicom.dcm";
|
||||||
//using (var fs = new FileStream(localPath, FileMode.Create, FileAccess.Write))
|
//using (var fs = new FileStream(localPath, FileMode.Create, FileAccess.Write))
|
||||||
//{
|
//{
|
||||||
// ms.CopyTo(fs);
|
// ms.CopyTo(fs);
|
||||||
|
|
@ -709,7 +753,11 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
// 直接写入内存
|
||||||
|
await using var ms = new MemoryStream();
|
||||||
|
await dicomFile.SaveAsync(ms);
|
||||||
ms.Position = 0;
|
ms.Position = 0;
|
||||||
|
|
||||||
//irc 从路径最后一截取Guid
|
//irc 从路径最后一截取Guid
|
||||||
storeRelativePath = await ossService.UploadToOSSAsync(ms, ossFolderPath, instanceId.ToString(), false);
|
storeRelativePath = await ossService.UploadToOSSAsync(ms, ossFolderPath, instanceId.ToString(), false);
|
||||||
|
|
||||||
|
|
@ -828,7 +876,7 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
_upload.FileCount++;
|
_upload.FileCount++;
|
||||||
_upload.FileSize = _upload.FileSize + fileSize;
|
_upload.FileSize = _upload.FileSize + fileSize;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Log.Logger.Information($"CallingAE:{Association.CallingAE} CalledAE:{Association.CalledAE} {request.SOPInstanceUID} 上传完成 ");
|
Log.Logger.Information($"CallingAE:{Association.CallingAE} CalledAE:{Association.CalledAE} {request.SOPInstanceUID} 上传完成 ");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,7 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
public class DicomArchiveService(IRepository<SCPPatient> _patientRepository,
|
public class DicomArchiveService(IRepository<SCPPatient> _patientRepository,
|
||||||
IRepository<SCPStudy> _studyRepository,
|
IRepository<SCPStudy> _studyRepository,
|
||||||
IRepository<SCPSeries> _seriesRepository,
|
IRepository<SCPSeries> _seriesRepository,
|
||||||
IRepository<SCPInstance> _instanceRepository,
|
IRepository<SCPInstance> _instanceRepository
|
||||||
IDistributedLockProvider _distributedLockProvider,
|
|
||||||
IRepository<SystemAnonymization> _systemAnonymizationRepository,
|
|
||||||
IRepository<TrialSite> _trialSiteRepository,
|
|
||||||
IFusionCache _fusionCache
|
|
||||||
) : BaseService, IDicomArchiveService
|
) : BaseService, IDicomArchiveService
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -42,55 +38,6 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
{
|
{
|
||||||
var dataset = dicomFile.Dataset;
|
var dataset = dicomFile.Dataset;
|
||||||
|
|
||||||
#region 匿名化
|
|
||||||
|
|
||||||
var anonymizeList = await _fusionCache.GetOrSetAsync(CacheKeys.SystemAnonymization, _ => CacheHelper.GetSystemAnonymizationListAsync(_systemAnonymizationRepository), TimeSpan.FromDays(7));
|
|
||||||
|
|
||||||
|
|
||||||
var fixedFiledList = anonymizeList.Where(t => t.IsFixed).ToList();
|
|
||||||
|
|
||||||
var ircFiledList = anonymizeList.Where(t => t.IsFixed == false).ToList();
|
|
||||||
|
|
||||||
foreach (var item in fixedFiledList)
|
|
||||||
{
|
|
||||||
|
|
||||||
var dicomTag = new DicomTag(Convert.ToUInt16(item.Group, 16), Convert.ToUInt16(item.Element, 16));
|
|
||||||
|
|
||||||
dataset.AddOrUpdate(dicomTag, item.ReplaceValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var item in ircFiledList)
|
|
||||||
{
|
|
||||||
|
|
||||||
var dicomTag = new DicomTag(Convert.ToUInt16(item.Group, 16), Convert.ToUInt16(item.Element, 16));
|
|
||||||
|
|
||||||
if (dicomTag == DicomTag.ClinicalTrialProtocolID)
|
|
||||||
{
|
|
||||||
dataset.AddOrUpdate(dicomTag, "");
|
|
||||||
|
|
||||||
}
|
|
||||||
if (dicomTag == DicomTag.ClinicalTrialSiteID)
|
|
||||||
{
|
|
||||||
dataset.AddOrUpdate(dicomTag, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dicomTag == DicomTag.ClinicalTrialSubjectID)
|
|
||||||
{
|
|
||||||
dataset.AddOrUpdate(dicomTag, "");
|
|
||||||
|
|
||||||
}
|
|
||||||
if (dicomTag == DicomTag.ClinicalTrialTimePointID)
|
|
||||||
{
|
|
||||||
dataset.AddOrUpdate(dicomTag, "");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
string studyInstanceUid = dataset.GetString(DicomTag.StudyInstanceUID);
|
string studyInstanceUid = dataset.GetString(DicomTag.StudyInstanceUID);
|
||||||
string seriesInstanceUid = dataset.GetString(DicomTag.SeriesInstanceUID);
|
string seriesInstanceUid = dataset.GetString(DicomTag.SeriesInstanceUID);
|
||||||
string sopInstanceUid = dataset.GetString(DicomTag.SOPInstanceUID);
|
string sopInstanceUid = dataset.GetString(DicomTag.SOPInstanceUID);
|
||||||
|
|
@ -257,6 +204,7 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
findStudy.DicomStudyTime = dataset.GetSingleValueOrDefault(DicomTag.StudyTime, string.Empty);
|
findStudy.DicomStudyTime = dataset.GetSingleValueOrDefault(DicomTag.StudyTime, string.Empty);
|
||||||
findStudy.CalledAE = calledAE;
|
findStudy.CalledAE = calledAE;
|
||||||
findStudy.CallingAE = callingAE;
|
findStudy.CallingAE = callingAE;
|
||||||
|
findStudy.PatientIdStr = patientIdStr;
|
||||||
findStudy.PatientName = dataset.GetSingleValueOrDefault(DicomTag.PatientName, string.Empty);
|
findStudy.PatientName = dataset.GetSingleValueOrDefault(DicomTag.PatientName, string.Empty);
|
||||||
findStudy.PatientSex = dataset.GetSingleValueOrDefault(DicomTag.PatientSex, string.Empty);
|
findStudy.PatientSex = dataset.GetSingleValueOrDefault(DicomTag.PatientSex, string.Empty);
|
||||||
findStudy.PatientAge = dataset.GetSingleValueOrDefault(DicomTag.PatientAge, string.Empty);
|
findStudy.PatientAge = dataset.GetSingleValueOrDefault(DicomTag.PatientAge, string.Empty);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue