From 355ca22134a0d40cc2e26626978961c50825910c Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 18 Dec 2024 11:30:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=A2=E6=88=B7=E7=AB=AFpa?= =?UTF-8?q?cs=20ae=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Visit/DTO/PatientViewModel.cs | 2 + .../Service/Visit/PatientService.cs | 136 +++++++++++------- 2 files changed, 85 insertions(+), 53 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Visit/DTO/PatientViewModel.cs b/IRaCIS.Core.Application/Service/Visit/DTO/PatientViewModel.cs index 8972efa6b..bb57325dd 100644 --- a/IRaCIS.Core.Application/Service/Visit/DTO/PatientViewModel.cs +++ b/IRaCIS.Core.Application/Service/Visit/DTO/PatientViewModel.cs @@ -1008,6 +1008,8 @@ namespace IRaCIS.Application.Contracts public Guid PatientId { get; set; } + public string AccessionNumber { get; set; } + public DateTime? StudyTime { get; set; } public string Modalities { get; set; } = string.Empty; diff --git a/IRaCIS.Core.Application/Service/Visit/PatientService.cs b/IRaCIS.Core.Application/Service/Visit/PatientService.cs index 86abe90a6..e86bd1c4f 100644 --- a/IRaCIS.Core.Application/Service/Visit/PatientService.cs +++ b/IRaCIS.Core.Application/Service/Visit/PatientService.cs @@ -46,9 +46,9 @@ using FellowOakDicom.Network; using Microsoft.Extensions.Logging; using DocumentFormat.OpenXml.Wordprocessing; using System; -using Amazon.Runtime.Internal.Transform; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; + namespace IRaCIS.Application.Services { [ApiExplorerSettings(GroupName = "Trial")] @@ -685,6 +685,7 @@ namespace IRaCIS.Application.Services InstanceCount = scpStudy.InstanceCount, Modalities = scpStudy.Modalities, PatientId = scpStudy.PatientId, + AccessionNumber = scpStudy.AccessionNumber, SCPStudyId = scpStudy.Id, SeriesCount = scpStudy.SeriesCount, StudyTime = scpStudy.StudyTime, @@ -2827,7 +2828,7 @@ namespace IRaCIS.Application.Services #region 基础方法 - public static DicomCFindRequest CreateStudyRequest(SCUQuery inQuery, List modalityList) + public static DicomCFindRequest CreateStudyRequest(SCUQuery inQuery, string modality/*, List modalityList*/) { var request = new DicomCFindRequest(DicomQueryRetrieveLevel.Study); @@ -2862,7 +2863,7 @@ namespace IRaCIS.Application.Services //request.Dataset.AddOrUpdate(DicomTag.PatientID, "Test*"); - var modalityQuery = string.Join($"\\", (inQuery.ModalitiesInStudyList == null || inQuery.ModalitiesInStudyList?.Count == 0) ? modalityList : inQuery.ModalitiesInStudyList); + //var modalityQuery = string.Join($"\\", (inQuery.ModalitiesInStudyList == null || inQuery.ModalitiesInStudyList?.Count == 0) ? modalityList : inQuery.ModalitiesInStudyList); //病例号 request.Dataset.AddOrUpdate(DicomTag.PatientID, inQuery.PatientID.IsNullOrEmpty() ? "" : inQuery.PatientID); @@ -2874,7 +2875,7 @@ namespace IRaCIS.Application.Services request.Dataset.AddOrUpdate(DicomTag.StudyID, inQuery.StudyID.IsNullOrEmpty() ? "" : inQuery.StudyID); request.Dataset.AddOrUpdate(DicomTag.AccessionNumber, inQuery.StudyID.IsNullOrEmpty() ? "" : inQuery.AccessionNumber); - //request.Dataset.AddOrUpdate(DicomTag.ModalitiesInStudy, modalityQuery); + request.Dataset.AddOrUpdate(DicomTag.ModalitiesInStudy, modality); request.Dataset.AddOrUpdate(DicomTag.StudyDate, inQuery.StudyDate.IsNullOrEmpty() ? "" : inQuery.StudyDate); request.Dataset.AddOrUpdate(DicomTag.StudyTime, inQuery.StudyTime.IsNullOrEmpty() ? "" : inQuery.StudyTime); @@ -2931,6 +2932,12 @@ namespace IRaCIS.Application.Services var find = await _dicomAEReposiotry.FirstOrDefaultAsync(t => t.Id == inQuery.PacsDicomAEId); + var hirClient = await _dicomAEReposiotry.FirstOrDefaultAsync(t => t.PacsTypeEnum == PacsType.HIRClient); + + if (hirClient == null) + { + throw new BusinessValidationFailedException(_localizer["Patient_NoPacsClientAE"]); + } if (find != null) { @@ -2938,64 +2945,80 @@ namespace IRaCIS.Application.Services //var cts = new CancellationTokenSource(); //CancellationToken token = cts.Token; + var @lock = _distributedLockProvider.CreateLock($"CFind"); + + var maxStudyCount = find.MaxStudyCount > 0 ? find.MaxStudyCount : 50; - var client = DicomClientFactory.Create(find.IP, find.Port, false, "HIRSCUAE", find.CalledAE); + var client = DicomClientFactory.Create(find.IP, find.Port, false, hirClient.CalledAE, find.CalledAE); client.NegotiateAsyncOps(); - var request = CreateStudyRequest(inQuery, find.ModalityList); - request.OnResponseReceived += (req, response) => + DicomCFindRequest.ResponseDelegate responseDelegate = (req, response) => + { + + if (response.HasDataset) + { + using (@lock.Acquire()) + { + if (result.Count == maxStudyCount) + { + response.Status = DicomStatus.Cancel; + } + + var studyTime = response.Dataset.GetDateTime(DicomTag.StudyDate, DicomTag.StudyTime); + + DateOnly datePart = DateOnly.FromDateTime(studyTime); + TimeOnly timePart = TimeOnly.FromDateTime(studyTime); + + DateTime? birthDate = DateTime.ParseExact(response.Dataset?.GetSingleValueOrDefault(DicomTag.PatientBirthDate, ""), "yyyyMMdd", null); + // 格式化为你需要的日期格式,例如:yyyy-MM-dd + string formattedBirthDate = birthDate?.ToString("yyyy-MM-dd") ?? string.Empty; + + + result.Add(new SCUStudyView() + { + PatientID = response.Dataset?.GetSingleValueOrDefault(DicomTag.PatientID, ""), + PatientName = response.Dataset?.GetSingleValueOrDefault(DicomTag.PatientName, ""), + PatientSex = response.Dataset?.GetSingleValueOrDefault(DicomTag.PatientSex, ""), + PatientBirthDate = formattedBirthDate, + StudyID = response.Dataset?.GetSingleValueOrDefault(DicomTag.StudyID, ""), + AccessionNumber = response.Dataset?.GetSingleValueOrDefault(DicomTag.AccessionNumber, ""), + ModalitiesInStudy = response.Dataset?.GetSingleValueOrDefault(DicomTag.ModalitiesInStudy, ""), + StudyDate = datePart.ToString("yyyy-MM-dd"), + StudyTime = timePart.ToString("HH:mm:ss"), + BodyPartExamined = response.Dataset?.GetSingleValueOrDefault(DicomTag.BodyPartExamined, ""), + StudyDescription = response.Dataset?.GetSingleValueOrDefault(DicomTag.StudyDescription, ""), + StudyInstanceUID = response.Dataset?.GetSingleValueOrDefault(DicomTag.StudyInstanceUID, "") + }); + } + + + } + + }; + + + //看当前前端有没有传递modality,有的话以前端为准,没有的话以配置为准 构造同样数量的请求 + + var requestModalityList = (inQuery.ModalitiesInStudyList != null && inQuery.ModalitiesInStudyList.Count > 0) ? inQuery.ModalitiesInStudyList : find.ModalityList; + + requestModalityList = requestModalityList.Count == 0 ? new List() { "" } : requestModalityList; + + requestModalityList = new List() { "" }; + + var requestList = new List(); + foreach (var modality in requestModalityList) { + var request = CreateStudyRequest(inQuery, modality); + request.OnResponseReceived += responseDelegate; + requestList.Add(request); + } - if (response.HasDataset) - { - //var time= response.Dataset?.GetSingleValueOrDefault(DicomTag.StudyTime, "") - - var studyTime = response.Dataset.GetDateTime(DicomTag.StudyDate, DicomTag.StudyTime); - - DateOnly datePart = DateOnly.FromDateTime(studyTime); - TimeOnly timePart = TimeOnly.FromDateTime(studyTime); - - DateTime? birthDate = DateTime.ParseExact(response.Dataset?.GetSingleValueOrDefault(DicomTag.PatientBirthDate, ""), "yyyyMMdd", null); - // 格式化为你需要的日期格式,例如:yyyy-MM-dd - string formattedBirthDate = birthDate?.ToString("yyyy-MM-dd") ?? string.Empty; - - - result.Add(new SCUStudyView() - { - PatientID = response.Dataset?.GetSingleValueOrDefault(DicomTag.PatientID, ""), - PatientName = response.Dataset?.GetSingleValueOrDefault(DicomTag.PatientName, ""), - PatientSex = response.Dataset?.GetSingleValueOrDefault(DicomTag.PatientSex, ""), - PatientBirthDate = formattedBirthDate, - StudyID = response.Dataset?.GetSingleValueOrDefault(DicomTag.StudyID, ""), - AccessionNumber = response.Dataset?.GetSingleValueOrDefault(DicomTag.AccessionNumber, ""), - ModalitiesInStudy = response.Dataset?.GetSingleValueOrDefault(DicomTag.ModalitiesInStudy, ""), - StudyDate = datePart.ToString("yyyy-MM-dd"), - StudyTime = timePart.ToString("HH:mm:ss"), - BodyPartExamined = response.Dataset?.GetSingleValueOrDefault(DicomTag.BodyPartExamined, ""), - StudyDescription = response.Dataset?.GetSingleValueOrDefault(DicomTag.StudyDescription, ""), - StudyInstanceUID = response.Dataset?.GetSingleValueOrDefault(DicomTag.StudyInstanceUID, "") - }); - - if (result.Count == maxStudyCount) - { - - response.Status = DicomStatus.Cancel; - - } - } - - }; - - - await client.AddRequestAsync(request); - + await client.AddRequestsAsync(requestList); await client.SendAsync(); - - } var resultInstanceUidList = result.Select(t => t.StudyInstanceUID).ToList(); @@ -3049,18 +3072,25 @@ namespace IRaCIS.Application.Services var hirServer = await _dicomAEReposiotry.FirstOrDefaultAsync(t => t.PacsTypeEnum == PacsType.HIRServer); + var hirClient = await _dicomAEReposiotry.FirstOrDefaultAsync(t => t.PacsTypeEnum == PacsType.HIRClient); + if (hirServer == null) { //"未找到服务端AE配置,请核查后再拉取" return ResponseOutput.NotOk(_localizer["Patient_NoPacsAE"]); } + if (hirClient == null) + { + return ResponseOutput.NotOk(_localizer["Patient_NoPacsClientAE"]); + } + if (find != null) { var task = Task.Run(async () => { - var client = DicomClientFactory.Create(find.IP, find.Port, false, "HIRSCUAE", find.CalledAE); + var client = DicomClientFactory.Create(find.IP, find.Port, false, hirClient.CalledAE, find.CalledAE); client.NegotiateAsyncOps(); var cmoveRequestList = new List();