diff --git a/IRaCIS.Core.API/appsettings.Test_HIR.json b/IRaCIS.Core.API/appsettings.Test_HIR.json index 753880ed4..6ab387b43 100644 --- a/IRaCIS.Core.API/appsettings.Test_HIR.json +++ b/IRaCIS.Core.API/appsettings.Test_HIR.json @@ -35,7 +35,10 @@ "LoginMaxFailCount": 5, "LoginFailLockMinutes": 30, "AutoLoginOutMinutes": 120, - "AESKey": "HIR_System_AES_Key_Info" + "AESKey": "HIR_System_AES_Key_Info", + "CmoveIntervalMinutes": 1, + "CmoveInstanceIntervalMinutes": 1 + }, "SystemHospitalConfig": { "HospitalCode": "EI", diff --git a/IRaCIS.Core.API/appsettings.Uat_HIR.json b/IRaCIS.Core.API/appsettings.Uat_HIR.json index a5e771ef5..e3293cd39 100644 --- a/IRaCIS.Core.API/appsettings.Uat_HIR.json +++ b/IRaCIS.Core.API/appsettings.Uat_HIR.json @@ -34,7 +34,9 @@ "LoginMaxFailCount": 5, "LoginFailLockMinutes": 30, "AutoLoginOutMinutes": 120, - "AESKey": "HIR_System_AES_Key_Info" + "AESKey": "HIR_System_AES_Key_Info", + "CmoveIntervalMinutes": 1, + "CmoveInstanceIntervalMinutes": 1 }, "SystemHospitalConfig": { "HospitalCode": "EI", diff --git a/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs b/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs index 58f6db3f7..12011a2dc 100644 --- a/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs +++ b/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs @@ -38,6 +38,11 @@ public class ServiceVerifyConfigOption public string AESKey { get; set; } + + public int CmoveIntervalMinutes { get; set; } + + public int CmoveInstanceIntervalMinutes { get; set; } + } public class SystemEmailSendConfig @@ -68,7 +73,7 @@ public class SystemEmailSendConfig public bool IsOpenErrorNoticeEmail { get; set; } - public List ErrorNoticeEmailList { get; set; } =new List(); + public List ErrorNoticeEmailList { get; set; } = new List(); } public class SystemEmailSendConfigView diff --git a/IRaCIS.Core.Application/Helper/CacheHelper.cs b/IRaCIS.Core.Application/Helper/CacheHelper.cs index 3ef6b56ea..0941dfa9b 100644 --- a/IRaCIS.Core.Application/Helper/CacheHelper.cs +++ b/IRaCIS.Core.Application/Helper/CacheHelper.cs @@ -58,6 +58,9 @@ public static class CacheKeys /// public static string StartRestTime(Guid userId) => $"{userId}StartRestTime"; + + public static string CmoveStudyId(string studyIdStr) => $"CmoveStudyId:{studyIdStr}"; + } public static class CacheHelper diff --git a/IRaCIS.Core.Application/Service/Visit/PatientService.cs b/IRaCIS.Core.Application/Service/Visit/PatientService.cs index 0ea8f4b1b..a1e07941f 100644 --- a/IRaCIS.Core.Application/Service/Visit/PatientService.cs +++ b/IRaCIS.Core.Application/Service/Visit/PatientService.cs @@ -49,6 +49,7 @@ using System; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; using DocumentFormat.OpenXml.Vml.Office; using IRaCIS.Core.Infra.EFCore.Migrations; +using System.Dynamic; namespace IRaCIS.Application.Services @@ -65,7 +66,7 @@ namespace IRaCIS.Application.Services IRepository _SCPImageUploadRepository, IRepository _userRepository, ILogger _logger, - IDistributedLockProvider _distributedLockProvider, IMapper _mapper, IUserInfo _userInfo, IWebHostEnvironment _hostEnvironment, IStringLocalizer _localizer + IDistributedLockProvider _distributedLockProvider, IMapper _mapper, IUserInfo _userInfo, IWebHostEnvironment _hostEnvironment, IStringLocalizer _localizer, IFusionCache _fusionCache ) : BaseService @@ -3119,8 +3120,13 @@ namespace IRaCIS.Application.Services /// /// /// + /// + /// /// - public async Task CmoveStudyList(SCUCmoveCommand inCommand, [FromServices] IRepository _dicomAEReposiotry) + public async Task CmoveStudyList(SCUCmoveCommand inCommand, + [FromServices] IRepository _dicomAEReposiotry, + [FromServices] IRepository _scpInstanceRepository, + [FromServices] IOptionsMonitor _basicSystemConfigConfig) { var result = new List(); @@ -3163,12 +3169,22 @@ namespace IRaCIS.Application.Services foreach (var item in inCommand.StudyInstanceUIDList) { - var cmoveRequest = new DicomCMoveRequest(hirServer.CalledAE, item); + var cmoveConfig = _basicSystemConfigConfig.CurrentValue; + var exsitStudyId = await _fusionCache.GetOrDefaultAsync(CacheKeys.CmoveStudyId(item), null); - cmoveRequest.OnResponseReceived += responseDelegate; + var latestInstance = await _scpInstanceRepository.Where(t => t.StudyInstanceUid == item).OrderByDescending(t => t.CreateTime).FirstOrDefaultAsync(); + //缓存不存在当前检查,或者instance表最新的记录时间与当前时间之差超过1分钟(认为完成归档,可以重复拉取) + if (exsitStudyId == null && (latestInstance == null || latestInstance.CreateTime.AddMinutes(cmoveConfig.CmoveInstanceIntervalMinutes) > DateTime.Now)) + { + await _fusionCache.SetAsync(CacheKeys.CmoveStudyId(item), item, TimeSpan.FromMinutes(cmoveConfig.CmoveIntervalMinutes)); - cmoveRequestList.Add(cmoveRequest); + var cmoveRequest = new DicomCMoveRequest(hirServer.CalledAE, item); + + cmoveRequest.OnResponseReceived += responseDelegate; + + cmoveRequestList.Add(cmoveRequest); + } } await client.AddRequestsAsync(cmoveRequestList);