From d751bca3ea6af5a5e6e83372d7ee11aa90453136 Mon Sep 17 00:00:00 2001 From: he <10978375@qq.com> Date: Wed, 7 Sep 2022 15:47:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Reading/Dto/ReadingCalculateViewModel.cs | 5 + .../Service/Reading/ReadModuleService.cs | 9 +- .../Reading/ReadingCalculateService.cs | 238 ++++++++++++++---- .../Reading/ReadingImageTaskService.cs | 9 +- 4 files changed, 205 insertions(+), 56 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs index c06ed3668..aa23def80 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs @@ -30,6 +30,8 @@ namespace IRaCIS.Core.Application.ViewModel public Guid TrialId { get; set; } + public Guid? DoctorUserId { get; set; } + public Guid SubjectVisitId { get; set; } public bool IsChangeOtherTask { get; set; } @@ -96,6 +98,9 @@ namespace IRaCIS.Core.Application.ViewModel public class VisitTaskAnswerInfo { + public Guid VisitTaskId { get; set; } + public Guid QuestionId { get; set; } + public string VisitName { get; set; } public decimal SOD { get; set; } diff --git a/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs b/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs index a0fd3071c..e9c38a484 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs @@ -353,7 +353,14 @@ namespace IRaCIS.Application.Services [HttpDelete("{readModuleId:guid}")] public async Task DeleteReadModule(Guid readModuleId) { - + + var readModule = await _readModuleRepository.Where(x => x.Id == readModuleId).FirstNotNullAsync(); + + if (readModule.ModuleType==ModuleTypeEnum.Global&&(await _readModuleRepository.AnyAsync(x=>x.ModuleType==ModuleTypeEnum.Oncology&&x.SubjectVisitId== readModule.SubjectVisitId))) + { + throw new BusinessValidationFailedException("当前访视存在肿瘤学阅片,请先删除肿瘤学阅片"); + } + if (await _visitTaskRepository.AnyAsync(x => readModuleId==x.SouceReadModuleId && x.ReadingTaskState == ReadingTaskState.HaveSigned && x.TaskState == TaskState.Effect)) { throw new BusinessValidationFailedException("当前阅片已生成任务并且阅片完成,操作失败。"); diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs index fbb7767f5..a81a67c29 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs @@ -11,6 +11,7 @@ using IRaCIS.Core.Application.ViewModel; using Panda.DynamicWebApi.Attributes; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infra.EFCore.Common; +using Microsoft.Extensions.Caching.Memory; namespace IRaCIS.Core.Application.Service { @@ -36,7 +37,6 @@ namespace IRaCIS.Core.Application.Service IRepository readingQuestionCriterionTrialRepository, IRepository readingTableQuestionTrialRepository, IRepository readingQuestionTrialRepository, - IRepository subjectVisitRepository, IRepository tumorAssessmentRepository, IRepository readingTaskQuestionAnswerRepository @@ -52,6 +52,10 @@ namespace IRaCIS.Core.Application.Service this._readingTaskQuestionAnswerRepository = readingTaskQuestionAnswerRepository; } + #region 临时对象 单个请求的生命周期 避免重复查询数据库 + private List visitTaskAnswerList; + #endregion + /// /// 计算任务 /// @@ -107,6 +111,7 @@ namespace IRaCIS.Core.Application.Service CriterionId= criterionId, IsChangeOtherTask=inDto.IsChangeOtherTask, TrialId=visitTask.TrialId, + DoctorUserId=visitTask.DoctorUserId, }; await ReadingCalculate(readingData); } @@ -122,21 +127,57 @@ namespace IRaCIS.Core.Application.Service // 找到所有访视任务的Id var visitTaskIds = await _visitTaskRepository.Where(x => !x.IsAnalysisCreate && x.ReadingCategory == ReadingCategory.Visit && - x.TaskState == TaskState.Effect && x.ReadingTaskState == ReadingTaskState.HaveSigned).Select(x => x.Id).ToListAsync(); + x.TaskState == TaskState.Effect && x.ReadingTaskState == ReadingTaskState.HaveSigned&&x.DoctorUserId==inDto.DoctorUserId).Select(x => x.Id).ToListAsync(); - var needAddList = new List(); - foreach (var item in inDto.QuestionInfo.Where(x => x.QuestionType != null)) + + #region 先计算 + // 先计算然后保存结果 因为计算的结果在下面的计算可能会用到 + var needFirstCalculateTypes = new List() + { + QuestionType.SOD, + }; + + var needFirstAddList = new List(); + + foreach (var item in inDto.QuestionInfo.Where(x => needFirstCalculateTypes.Contains(x.QuestionType))) { switch (item.QuestionType) { // 靶病灶径线之和(SOD) case QuestionType.SOD: - needAddList.Add(new ReadingTaskQuestionAnswer() + needFirstAddList.Add(new ReadingTaskQuestionAnswer() { Answer = (await GetSODData(inDto)).ToString(), - ReadingQuestionTrialId=item.QuestionId, + ReadingQuestionTrialId = item.QuestionId, }); break; + } + } + + + var needFirstAddIds = needFirstAddList.Select(x => x.ReadingQuestionTrialId).ToList(); + await _readingTaskQuestionAnswerRepository.BatchDeleteNoTrackingAsync(x => needFirstAddIds.Contains(x.ReadingQuestionTrialId) && x.VisitTaskId == inDto.VisitTaskId); + needFirstAddList.ForEach(x => + { + x.SubjectId = inDto.SubjectId; + x.ReadingQuestionCriterionTrialId = inDto.CriterionId; + x.VisitTaskId = inDto.VisitTaskId; + x.TrialId = inDto.TrialId; + x.SubjectId = inDto.SubjectId; + }); + + await _readingTaskQuestionAnswerRepository.AddRangeAsync(needFirstAddList); + + await _readingTaskQuestionAnswerRepository.SaveChangesAsync(); + #endregion + + var needAddList = new List(); + // 循环找要计算的值进行计算 + foreach (var item in inDto.QuestionInfo.Where(x => x.QuestionType != null)) + { + switch (item.QuestionType) + { + // 非淋巴结靶病灶长径之和 case QuestionType.SumOfDiameter: needAddList.Add(new ReadingTaskQuestionAnswer() @@ -163,32 +204,59 @@ namespace IRaCIS.Core.Application.Service break; // 与整个访视期间最低点相比增加的值(mm) 其他任务需要改 case QuestionType.LowestIncrease: - needAddList.Add(new ReadingTaskQuestionAnswer() + + if (!inDto.IsChangeOtherTask) { - Answer = (await GetLowestIncrease(inDto)).ToString(), - ReadingQuestionTrialId = item.QuestionId, - }); + needAddList.Add(new ReadingTaskQuestionAnswer() + { + Answer = (await GetLowestIncrease(inDto)).ToString(), + ReadingQuestionTrialId = item.QuestionId, + }); + } + else + { + await ChangeAllLowestIncrease(inDto, item.QuestionId); + } + + break; // 与整个访视期间最低点相比增加的百分比 其他任务需要改 case QuestionType.LowPercent: - needAddList.Add(new ReadingTaskQuestionAnswer() + + if (!inDto.IsChangeOtherTask) { - Answer = (await GetLowPercent(inDto)).ToString(), - ReadingQuestionTrialId = item.QuestionId, - }); + needAddList.Add(new ReadingTaskQuestionAnswer() + { + Answer = (await GetLowPercent(inDto)).ToString(), + ReadingQuestionTrialId = item.QuestionId, + }); + } + else + { + await ChangeAllLowPercent(inDto, item.QuestionId); + } + + break; // 整个访视期间最低点访视名称 其他任务需要改 case QuestionType.LowVisit: var answer = (await GetLowVisit(inDto)).ToString(); - needAddList.Add(new ReadingTaskQuestionAnswer() + if (!inDto.IsChangeOtherTask) { - Answer = answer, - ReadingQuestionTrialId = item.QuestionId, - }); - if (inDto.IsChangeOtherTask) - { - await this.ChangeAllVisitTaskAnswer(visitTaskIds, item.QuestionId, answer); + needAddList.Add(new ReadingTaskQuestionAnswer() + { + Answer = answer, + ReadingQuestionTrialId = item.QuestionId, + }); } + else + { + if (inDto.IsChangeOtherTask) + { + await this.ChangeAllVisitTaskAnswer(visitTaskIds, item.QuestionId, answer); + } + } + break; // 是否存在非淋巴结靶病灶 case QuestionType.IsLymphTarget: @@ -381,7 +449,7 @@ namespace IRaCIS.Core.Application.Service } else { - return decimal.Round(thisSOD * 100 / minSOD, 2); + return decimal.Round((thisSOD- minSOD) * 100 / minSOD, 2); } @@ -495,6 +563,68 @@ namespace IRaCIS.Core.Application.Service } #endregion + + #region 修改其他标准 + + #region 修改与整个访视期间最低点相比增加的值(mm) + + /// + /// 修改与整个访视期间最低点相比增加的值(mm) + /// + /// + /// + /// + public async Task ChangeAllLowestIncrease(ReadingCalculateDto inDto,Guid questionId) + { + var visitTaskList = await GetVisitTaskAnswerList(inDto); + var lowSod = visitTaskList.Select(x => x.SOD).OrderBy(x => x).FirstOrDefault(); + foreach (var item in visitTaskList) + { + await _readingTaskQuestionAnswerRepository.BatchUpdateNoTrackingAsync(x => x.VisitTaskId == item.VisitTaskId && x.ReadingQuestionTrialId == questionId, x => new ReadingTaskQuestionAnswer() + { + Answer = (item.SOD - lowSod).ToString() + }) ; + } + } + + #endregion + + + #region 修改整个访视期间最低点相比增加的百分比 + + /// + /// 修改整个访视期间最低点相比增加的百分比 + /// + /// + /// + /// + public async Task ChangeAllLowPercent(ReadingCalculateDto inDto, Guid questionId) + { + var visitTaskList = await GetVisitTaskAnswerList(inDto); + var lowSod = visitTaskList.Select(x => x.SOD).OrderBy(x => x).FirstOrDefault(); + foreach (var item in visitTaskList) + { + decimal percent = 0; + if (lowSod == 0) + { + percent= 100; + } + else + { + percent= decimal.Round((item.SOD - lowSod) * 100 / lowSod, 2); + } + + await _readingTaskQuestionAnswerRepository.BatchUpdateNoTrackingAsync(x => x.VisitTaskId == item.VisitTaskId && x.ReadingQuestionTrialId == questionId, x => new ReadingTaskQuestionAnswer() + { + Answer = percent.ToString() + }); + } + } + + #endregion + + #endregion + #region 通用方法 #region 修改所有访视任务的答案 @@ -523,53 +653,53 @@ namespace IRaCIS.Core.Application.Service /// private async Task GetBaseLineSOD(ReadingCalculateDto inDto) { - if (await _visitTaskRepository.AnyAsync(x => x.Id == inDto.VisitTaskId && x.SourceSubjectVisit.IsBaseLine&&!x.IsAnalysisCreate)) + if (await _visitTaskRepository.AnyAsync(x => x.Id == inDto.VisitTaskId && x.SourceSubjectVisit.IsBaseLine&&!x.IsAnalysisCreate&&x.DoctorUserId==inDto.DoctorUserId)) { return 0; } // 先找到基线的任务 var baseLineTaskId = await _visitTaskRepository.Where(x => x.SubjectId == inDto.SubjectId && x.ReadingCategory == ReadingCategory.Visit - && x.SourceSubjectVisit.IsBaseLine && x.TaskState == TaskState.Effect&&!x.IsAnalysisCreate) + && x.SourceSubjectVisit.IsBaseLine && x.TaskState == TaskState.Effect&&!x.IsAnalysisCreate&&x.DoctorUserId==inDto.DoctorUserId) .Select(x => x.Id).FirstOrDefaultAsync(); var baseLineSOD = decimal.Parse((await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == baseLineTaskId && x.ReadingQuestionTrial.QuestionType == QuestionType.SOD).Select(x => x.Answer).FirstOrDefaultAsync()).IsNullOrEmptyReturn0()); return baseLineSOD; } - #endregion + #endregion - #region 获取访视任务信息 - /// - /// 获取访视任务信息 - /// - /// - /// - private async Task> GetVisitTaskAnswerList(ReadingCalculateDto inDto) - { - var answerList = await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTask.ReadingCategory == ReadingCategory.Visit - && x.SubjectId == inDto.SubjectId && x.VisitTask.ReadingTaskState == ReadingTaskState.HaveSigned && x.VisitTask.TaskState == TaskState.Effect && x.ReadingQuestionTrial.QuestionType == QuestionType.SOD) - .Select(x => new - { - VisitName = x.VisitTask.SourceSubjectVisit.VisitName, - SOD = x.Answer - }).ToListAsync(); + #region 获取访视任务信息 + /// + /// 获取访视任务信息 + /// + /// + /// + public async Task> GetVisitTaskAnswerList(ReadingCalculateDto inDto) + { + if (visitTaskAnswerList == null) + { + visitTaskAnswerList = await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTask.ReadingCategory == ReadingCategory.Visit + && x.SubjectId == inDto.SubjectId && x.VisitTask.ReadingTaskState == ReadingTaskState.HaveSigned && x.VisitTask.TaskState == TaskState.Effect && x.ReadingQuestionTrial.QuestionType == QuestionType.SOD) + .Select(x => new VisitTaskAnswerInfo + { + VisitTaskId = x.VisitTaskId, + QuestionId = x.ReadingQuestionTrialId, + VisitName = x.VisitTask.SourceSubjectVisit.VisitName, + SOD = decimal.Parse(x.Answer.IsNullOrEmptyReturn0()), + }).ToListAsync(); - var decimalAnswerList = answerList.Select(x => new VisitTaskAnswerInfo - { - VisitName = x.VisitName, - SOD = decimal.Parse(x.SOD.IsNullOrEmptyReturn0()), - }).ToList(); + } - return decimalAnswerList; - } - #endregion + return visitTaskAnswerList; + } + #endregion - /// - /// 获取上一个访视任务Id - /// - /// - private async Task GetLastVisitTaskId(ReadingCalculateDto inDto) + /// + /// 获取上一个访视任务Id + /// + /// + private async Task GetLastVisitTaskId(ReadingCalculateDto inDto) { // 拿到这一个访视 var thisNum = await _subjectVisitRepository.Where(x => x.Id == inDto.SubjectVisitId).Select(x => x.VisitNum).FirstOrDefaultAsync(); @@ -579,7 +709,7 @@ namespace IRaCIS.Core.Application.Service // 找到访视任务Id - var LastVisitTaskId = await _visitTaskRepository.Where(x => x.ReadingCategory == ReadingCategory.Visit && x.TaskState == TaskState.Effect && !x.IsAnalysisCreate && x.SourceSubjectVisitId == lastVisitId).Select(x => x.Id).FirstOrDefaultAsync(); + var LastVisitTaskId = await _visitTaskRepository.Where(x => x.ReadingCategory == ReadingCategory.Visit && x.TaskState == TaskState.Effect && !x.IsAnalysisCreate && x.SourceSubjectVisitId == lastVisitId&&x.DoctorUserId==inDto.DoctorUserId).Select(x => x.Id).FirstOrDefaultAsync(); return LastVisitTaskId; } diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs index dbec164d7..bf01ac64f 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs @@ -1867,6 +1867,12 @@ namespace IRaCIS.Application.Services } } + var isCurrentTaskAddList = await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.QuestionId == inDto.QuestionId && x.TrialId == inDto.TrialId && x.RowIndex == inDto.RowIndex).Select(x => x.IsCurrentTaskAdd).ToListAsync(); + bool isCurrentTaskAdd = true; + if (isCurrentTaskAddList.Count() > 0) + { + isCurrentTaskAdd = isCurrentTaskAddList[0]; + } await _readingTableQuestionAnswerRepository.BatchDeleteNoTrackingAsync(x => x.VisitTaskId == inDto.VisitTaskId && x.QuestionId == inDto.QuestionId && x.TrialId == inDto.TrialId && x.RowIndex == inDto.RowIndex); @@ -1883,13 +1889,14 @@ namespace IRaCIS.Application.Services VisitTaskId = inDto.VisitTaskId }).ToList(); + await _readingTableAnswerRowInfoRepository.AddAsync(new ReadingTableAnswerRowInfo() { Id = NewId.NextGuid(), TrialId = inDto.TrialId, QuestionId = inDto.QuestionId, MeasureData = inDto.MeasureData, - IsCurrentTaskAdd=true, + IsCurrentTaskAdd= isCurrentTaskAdd, RowIndex = inDto.RowIndex, InstanceId=inDto.InstanceId, SeriesId=inDto.SeriesId,