HIR 对接第三方初步测试完毕
continuous-integration/drone/push Build is passing Details

Test_HIR_Net8
hang 2025-10-28 15:08:23 +08:00
parent 064e3836ca
commit aed778bbc6
5 changed files with 144 additions and 107 deletions

View File

@ -27,6 +27,7 @@ using FellowOakDicom.Imaging.Codec;
using FellowOakDicom.IO.Buffer;
using System.Diagnostics.CodeAnalysis;
using FellowOakDicom.Network.Client;
using MassTransit.Futures.Contracts;
namespace IRaCIS.Core.SCP.Service
{
@ -35,14 +36,7 @@ namespace IRaCIS.Core.SCP.Service
{
public bool IsSupportThirdService { get; set; }
public string ThirdSearchPacsAE { get; set; }
public string ThirdCallningAE { get; set; }
public string ThirdIP { get; set; }
public int THirdPort { get; set; }
public List<ThirdDestinationAE> ThirdDestinationAEList { get; set; }
public List<string> CalledAEList { get; set; }
@ -50,6 +44,15 @@ namespace IRaCIS.Core.SCP.Service
public string ServerPort { get; set; }
}
public class ThirdDestinationAE
{
public int Port { get; set; }
public string Name { get; set; }
public string IP { get; set; }
}
@ -120,9 +123,6 @@ namespace IRaCIS.Core.SCP.Service
Log.Logger.Warning($"接收到来自{association.CallingAE}的连接");
//_serviceProvider = (IServiceProvider)this.UserState;
//var tt = _injectServiceProvider;
var option = _serviceProvider.GetService<IOptionsMonitor<DicomSCPServiceOption>>().CurrentValue;
@ -174,6 +174,8 @@ namespace IRaCIS.Core.SCP.Service
public async Task OnReceiveAssociationReleaseRequestAsync()
{
if (_isCurrentThirdForward == false)
{
var _distributedLockProvider = _serviceProvider.GetService<IDistributedLockProvider>();
@ -191,6 +193,8 @@ namespace IRaCIS.Core.SCP.Service
Log.Logger.Information($"进入释放连接请求 {_releasedNormally}");
}
}
await SendAssociationReleaseResponseAsync();
}
@ -272,6 +276,8 @@ namespace IRaCIS.Core.SCP.Service
public async void OnConnectionClosed(Exception exception)
{
if (_isCurrentThirdForward == false)
{
var _studyRepository = _serviceProvider.GetService<IRepository<SCPStudy>>();
@ -292,7 +298,7 @@ namespace IRaCIS.Core.SCP.Service
await _studyRepository.SaveChangesAndClearAllTrackingAsync();
}
Log.Logger.Warning($"连接关闭 {_releasedNormally} {exception?.Message} {exception?.InnerException?.Message}");
}
@ -319,10 +325,12 @@ namespace IRaCIS.Core.SCP.Service
#region 判断是否转发第三方影像
if (DicomSCPServiceConfig.IsSupportThirdService)
{
var cmoveInfo = _cmoveStudyRepository.Where(t => t.StudyInstanceUIDList.Any(c => c == studyInstanceUid)).OrderByDescending(t => t.CreateTime).FirstOrDefault();
//确定是第三方请求
if (cmoveInfo != null && cmoveInfo.CallingAE == DicomSCPServiceConfig.ThirdCallningAE)
if (cmoveInfo != null && DicomSCPServiceConfig.ThirdDestinationAEList.Any(t => t.Name == cmoveInfo.DestinationAE))
{
_isCurrentThirdForward = true;
@ -331,19 +339,20 @@ namespace IRaCIS.Core.SCP.Service
try
{
// 克隆 Dataset 避免共享引用
var dsCopy = request.Dataset?.Clone();
var forwardRequest = new DicomCStoreRequest(dsCopy);
var findDestination = DicomSCPServiceConfig.ThirdDestinationAEList.FirstOrDefault(t => t.Name == cmoveInfo.DestinationAE);
var forwardRequest = new DicomCStoreRequest(request.File.Clone());
// 创建客户端连接到目标 PACS
var client = DicomClientFactory.Create(DicomSCPServiceConfig.ThirdIP, DicomSCPServiceConfig.THirdPort, false, DicomSCPServiceConfig.CalledAEList.First(), cmoveInfo.DestinationAE);
var client = DicomClientFactory.Create(findDestination.IP, findDestination.Port, false, DicomSCPServiceConfig.CalledAEList.First(), cmoveInfo.DestinationAE);
// 可以加入 OnResponseReceived 来处理目标 PACS 返回状态
forwardRequest.OnResponseReceived += (rq, rp) =>
{
Log.Logger.Information($"Forwarded C-STORE Response: {rq.SOPInstanceUID} {rp.Status}");
};
await client.AddRequestAsync(forwardRequest);
@ -357,6 +366,10 @@ namespace IRaCIS.Core.SCP.Service
return new DicomCStoreResponse(request, DicomStatus.Success);
}
}
#endregion

View File

@ -25,13 +25,26 @@
},
"DicomSCPServiceConfig": {
"IsSupportThirdService": true,
"ThirdSearchPacsAE": "ThirdCalledPacsAE",
"ThirdCallningAE": "ThirdCallningAE",
"ThirdIP": "192.168.3.15",
"THirdPort": 112,
"ThirdDestinationAEList": [
{
"Name": "LYAE",
"IP": "192.168.3.194",
"Port": "6000"
},
{
"Name": "HIRLAE",
"IP": "106.14.89.110",
"Port": "6000"
}
]
"CalledAEList": [
"HIRAE"
"HIRAE",
"STORESCP"
],
"ServerPort": 11112
"ServerPort": 11115
}
}

View File

@ -199,8 +199,7 @@ namespace IRaCIS.Core.API.HostService
// 异步发送到真实 PACS
_ = Task.Run(async () =>
{
try
{
var client = DicomClientFactory.Create(find.IP, find.Port, false, hirClient.CalledAE, find.CalledAE);
@ -215,7 +214,11 @@ namespace IRaCIS.Core.API.HostService
{
channel.Writer.Complete();
}
});
//_ = Task.Run(async () =>
//{
//});
// 异步 yield 返回给上游
await foreach (var resp in channel.Reader.ReadAllAsync())
@ -263,6 +266,7 @@ namespace IRaCIS.Core.API.HostService
var channel = Channel.CreateUnbounded<DicomCMoveResponse>();
var clonedDataset = request.Dataset?.Clone() ?? new DicomDataset();
var forward = new DicomCMoveRequest(hirServer.CalledAE, studyInstanceUid)
{
Dataset = clonedDataset
@ -281,6 +285,9 @@ namespace IRaCIS.Core.API.HostService
Completed = rp.Completed,
};
Logger.LogInformation($"Completed:{rp.Completed}");
channel.Writer.TryWrite(proxyResp);
if (!rp.Status.Equals(DicomStatus.Pending))
@ -290,8 +297,6 @@ namespace IRaCIS.Core.API.HostService
};
// 异步发送到真实 PACS
_ = Task.Run(async () =>
{
try
{
var client = DicomClientFactory.Create(find.IP, find.Port, false, hirClient.CalledAE, find.CalledAE);
@ -306,7 +311,11 @@ namespace IRaCIS.Core.API.HostService
{
channel.Writer.Complete();
}
});
//_ = Task.Run(async () =>
//{
//});
// 异步 yield 回上游
await foreach (var resp in channel.Reader.ReadAllAsync())

View File

@ -103,6 +103,8 @@ builder.Services.AddControllers(options =>
})
.AddNewtonsoftJsonSetup(builder.Services); // NewtonsoftJson 序列化 处理
builder.Services.AddOptions().Configure<DicomSCPServiceOption>(_configuration.GetSection("DicomSCPServiceConfig"));
// Panda动态WebApi + UnifiedApiResultFilter + 省掉控制器代码
builder.Services.AddDynamicWebApiSetup();
//MinimalAPI

View File

@ -56,8 +56,8 @@
},
"DicomSCPServiceConfig": {
"IsSupportThirdService": true,
"ThirdSearchPacsAE": "ThirdCalledPacsAE",
"ThirdCallningAE": "ThirdCallningAE",
"ThirdSearchPacsAE": "XCPACS",
"ThirdCallningAE": "LYAE",
"CalledAEList": [
"HIRSCUAE",
"HIRSCPAE"