HIR 对接第三方初步测试完毕
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
064e3836ca
commit
aed778bbc6
|
|
@ -27,6 +27,7 @@ using FellowOakDicom.Imaging.Codec;
|
||||||
using FellowOakDicom.IO.Buffer;
|
using FellowOakDicom.IO.Buffer;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using FellowOakDicom.Network.Client;
|
using FellowOakDicom.Network.Client;
|
||||||
|
using MassTransit.Futures.Contracts;
|
||||||
|
|
||||||
namespace IRaCIS.Core.SCP.Service
|
namespace IRaCIS.Core.SCP.Service
|
||||||
{
|
{
|
||||||
|
|
@ -35,14 +36,7 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
{
|
{
|
||||||
public bool IsSupportThirdService { get; set; }
|
public bool IsSupportThirdService { get; set; }
|
||||||
|
|
||||||
public string ThirdSearchPacsAE { get; set; }
|
public List<ThirdDestinationAE> ThirdDestinationAEList { get; set; }
|
||||||
|
|
||||||
public string ThirdCallningAE { get; set; }
|
|
||||||
|
|
||||||
public string ThirdIP { get; set; }
|
|
||||||
|
|
||||||
public int THirdPort { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<string> CalledAEList { get; set; }
|
public List<string> CalledAEList { get; set; }
|
||||||
|
|
@ -50,6 +44,15 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
public string ServerPort { get; set; }
|
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}的连接");
|
Log.Logger.Warning($"接收到来自{association.CallingAE}的连接");
|
||||||
|
|
||||||
//_serviceProvider = (IServiceProvider)this.UserState;
|
|
||||||
|
|
||||||
//var tt = _injectServiceProvider;
|
|
||||||
|
|
||||||
var option = _serviceProvider.GetService<IOptionsMonitor<DicomSCPServiceOption>>().CurrentValue;
|
var option = _serviceProvider.GetService<IOptionsMonitor<DicomSCPServiceOption>>().CurrentValue;
|
||||||
|
|
||||||
|
|
@ -174,6 +174,8 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
|
|
||||||
|
|
||||||
public async Task OnReceiveAssociationReleaseRequestAsync()
|
public async Task OnReceiveAssociationReleaseRequestAsync()
|
||||||
|
{
|
||||||
|
if (_isCurrentThirdForward == false)
|
||||||
{
|
{
|
||||||
var _distributedLockProvider = _serviceProvider.GetService<IDistributedLockProvider>();
|
var _distributedLockProvider = _serviceProvider.GetService<IDistributedLockProvider>();
|
||||||
|
|
||||||
|
|
@ -191,6 +193,8 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
|
|
||||||
Log.Logger.Information($"进入释放连接请求 {_releasedNormally}");
|
Log.Logger.Information($"进入释放连接请求 {_releasedNormally}");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
await SendAssociationReleaseResponseAsync();
|
await SendAssociationReleaseResponseAsync();
|
||||||
}
|
}
|
||||||
|
|
@ -272,6 +276,8 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
|
|
||||||
|
|
||||||
public async void OnConnectionClosed(Exception exception)
|
public async void OnConnectionClosed(Exception exception)
|
||||||
|
{
|
||||||
|
if (_isCurrentThirdForward == false)
|
||||||
{
|
{
|
||||||
var _studyRepository = _serviceProvider.GetService<IRepository<SCPStudy>>();
|
var _studyRepository = _serviceProvider.GetService<IRepository<SCPStudy>>();
|
||||||
|
|
||||||
|
|
@ -292,7 +298,7 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
|
|
||||||
|
|
||||||
await _studyRepository.SaveChangesAndClearAllTrackingAsync();
|
await _studyRepository.SaveChangesAndClearAllTrackingAsync();
|
||||||
|
}
|
||||||
|
|
||||||
Log.Logger.Warning($"连接关闭 {_releasedNormally} {exception?.Message} {exception?.InnerException?.Message}");
|
Log.Logger.Warning($"连接关闭 {_releasedNormally} {exception?.Message} {exception?.InnerException?.Message}");
|
||||||
}
|
}
|
||||||
|
|
@ -319,10 +325,12 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
|
|
||||||
#region 判断是否转发第三方影像
|
#region 判断是否转发第三方影像
|
||||||
|
|
||||||
|
if (DicomSCPServiceConfig.IsSupportThirdService)
|
||||||
|
{
|
||||||
var cmoveInfo = _cmoveStudyRepository.Where(t => t.StudyInstanceUIDList.Any(c => c == studyInstanceUid)).OrderByDescending(t => t.CreateTime).FirstOrDefault();
|
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;
|
_isCurrentThirdForward = true;
|
||||||
|
|
||||||
|
|
@ -331,19 +339,20 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
|
|
||||||
try
|
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
|
// 创建客户端连接到目标 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 返回状态
|
// 可以加入 OnResponseReceived 来处理目标 PACS 返回状态
|
||||||
forwardRequest.OnResponseReceived += (rq, rp) =>
|
forwardRequest.OnResponseReceived += (rq, rp) =>
|
||||||
{
|
{
|
||||||
Log.Logger.Information($"Forwarded C-STORE Response: {rq.SOPInstanceUID} {rp.Status}");
|
Log.Logger.Information($"Forwarded C-STORE Response: {rq.SOPInstanceUID} {rp.Status}");
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
await client.AddRequestAsync(forwardRequest);
|
await client.AddRequestAsync(forwardRequest);
|
||||||
|
|
@ -357,6 +366,10 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
|
|
||||||
return new DicomCStoreResponse(request, DicomStatus.Success);
|
return new DicomCStoreResponse(request, DicomStatus.Success);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,26 @@
|
||||||
},
|
},
|
||||||
"DicomSCPServiceConfig": {
|
"DicomSCPServiceConfig": {
|
||||||
"IsSupportThirdService": true,
|
"IsSupportThirdService": true,
|
||||||
"ThirdSearchPacsAE": "ThirdCalledPacsAE",
|
|
||||||
"ThirdCallningAE": "ThirdCallningAE",
|
"ThirdDestinationAEList": [
|
||||||
"ThirdIP": "192.168.3.15",
|
{
|
||||||
"THirdPort": 112,
|
"Name": "LYAE",
|
||||||
|
"IP": "192.168.3.194",
|
||||||
|
"Port": "6000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "HIRLAE",
|
||||||
|
"IP": "106.14.89.110",
|
||||||
|
"Port": "6000"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"CalledAEList": [
|
"CalledAEList": [
|
||||||
"HIRAE"
|
"HIRAE",
|
||||||
|
"STORESCP"
|
||||||
],
|
],
|
||||||
"ServerPort": 11112
|
"ServerPort": 11115
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -199,8 +199,7 @@ namespace IRaCIS.Core.API.HostService
|
||||||
|
|
||||||
|
|
||||||
// 异步发送到真实 PACS
|
// 异步发送到真实 PACS
|
||||||
_ = Task.Run(async () =>
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var client = DicomClientFactory.Create(find.IP, find.Port, false, hirClient.CalledAE, find.CalledAE);
|
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();
|
channel.Writer.Complete();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
//_ = Task.Run(async () =>
|
||||||
|
//{
|
||||||
|
|
||||||
|
//});
|
||||||
|
|
||||||
// 异步 yield 返回给上游
|
// 异步 yield 返回给上游
|
||||||
await foreach (var resp in channel.Reader.ReadAllAsync())
|
await foreach (var resp in channel.Reader.ReadAllAsync())
|
||||||
|
|
@ -263,6 +266,7 @@ namespace IRaCIS.Core.API.HostService
|
||||||
|
|
||||||
var channel = Channel.CreateUnbounded<DicomCMoveResponse>();
|
var channel = Channel.CreateUnbounded<DicomCMoveResponse>();
|
||||||
var clonedDataset = request.Dataset?.Clone() ?? new DicomDataset();
|
var clonedDataset = request.Dataset?.Clone() ?? new DicomDataset();
|
||||||
|
|
||||||
var forward = new DicomCMoveRequest(hirServer.CalledAE, studyInstanceUid)
|
var forward = new DicomCMoveRequest(hirServer.CalledAE, studyInstanceUid)
|
||||||
{
|
{
|
||||||
Dataset = clonedDataset
|
Dataset = clonedDataset
|
||||||
|
|
@ -281,6 +285,9 @@ namespace IRaCIS.Core.API.HostService
|
||||||
Completed = rp.Completed,
|
Completed = rp.Completed,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Logger.LogInformation($"Completed:{rp.Completed}");
|
||||||
|
|
||||||
channel.Writer.TryWrite(proxyResp);
|
channel.Writer.TryWrite(proxyResp);
|
||||||
|
|
||||||
if (!rp.Status.Equals(DicomStatus.Pending))
|
if (!rp.Status.Equals(DicomStatus.Pending))
|
||||||
|
|
@ -290,8 +297,6 @@ namespace IRaCIS.Core.API.HostService
|
||||||
};
|
};
|
||||||
|
|
||||||
// 异步发送到真实 PACS
|
// 异步发送到真实 PACS
|
||||||
_ = Task.Run(async () =>
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var client = DicomClientFactory.Create(find.IP, find.Port, false, hirClient.CalledAE, find.CalledAE);
|
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();
|
channel.Writer.Complete();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
//_ = Task.Run(async () =>
|
||||||
|
//{
|
||||||
|
|
||||||
|
//});
|
||||||
|
|
||||||
// 异步 yield 回上游
|
// 异步 yield 回上游
|
||||||
await foreach (var resp in channel.Reader.ReadAllAsync())
|
await foreach (var resp in channel.Reader.ReadAllAsync())
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,8 @@ builder.Services.AddControllers(options =>
|
||||||
})
|
})
|
||||||
.AddNewtonsoftJsonSetup(builder.Services); // NewtonsoftJson 序列化 处理
|
.AddNewtonsoftJsonSetup(builder.Services); // NewtonsoftJson 序列化 处理
|
||||||
|
|
||||||
|
builder.Services.AddOptions().Configure<DicomSCPServiceOption>(_configuration.GetSection("DicomSCPServiceConfig"));
|
||||||
|
|
||||||
// Panda动态WebApi + UnifiedApiResultFilter + 省掉控制器代码
|
// Panda动态WebApi + UnifiedApiResultFilter + 省掉控制器代码
|
||||||
builder.Services.AddDynamicWebApiSetup();
|
builder.Services.AddDynamicWebApiSetup();
|
||||||
//MinimalAPI
|
//MinimalAPI
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,8 @@
|
||||||
},
|
},
|
||||||
"DicomSCPServiceConfig": {
|
"DicomSCPServiceConfig": {
|
||||||
"IsSupportThirdService": true,
|
"IsSupportThirdService": true,
|
||||||
"ThirdSearchPacsAE": "ThirdCalledPacsAE",
|
"ThirdSearchPacsAE": "XCPACS",
|
||||||
"ThirdCallningAE": "ThirdCallningAE",
|
"ThirdCallningAE": "LYAE",
|
||||||
"CalledAEList": [
|
"CalledAEList": [
|
||||||
"HIRSCUAE",
|
"HIRSCUAE",
|
||||||
"HIRSCPAE"
|
"HIRSCPAE"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue