diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 405302d91..49d0f2e28 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -1295,6 +1295,16 @@ 阅片计算Dto + + + 是否修改其他任务 + + + + + 是否只改其他任务 + + 答案 @@ -3710,6 +3720,11 @@ 阅片计算 + + + 获取Sod的值 + + 计算任务 @@ -3827,20 +3842,25 @@ - + 修改与整个访视期间最低点相比增加的值(mm) - - + 修改整个访视期间最低点相比增加的百分比 - + + + + + 修改最低方式点名称 + + diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs index 3546e9cfa..6d0c58a6b 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs @@ -90,7 +90,6 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto /// public class ReadingCalculateDto { - public Guid SubjectId { get; set; } public Guid VisitTaskId { get; set; } @@ -103,7 +102,15 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto public Guid SubjectVisitId { get; set; } - public bool IsChangeOtherTask { get; set; } + /// + /// 是否修改其他任务 + /// + public bool IsChangeOtherTask { get; set; } = false; + + /// + /// 是否只改其他任务 + /// + public bool IsOnlyChangeAllTask { get; set; } = false; public List QuestionInfo { get; set; } = new List(); @@ -191,7 +198,11 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto { public QuestionType QuestionType { get; set; } - public Func> GetSingleDataFun { get; set; } + public Func> GetDecimalFun { get; set; } + + public Func> GetDecimalNullFun { get; set; } + + public Func> GetStringFun { get; set; } public Func ChangeAllTaskFun { get; set; } } diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs index 5030598ac..fc52cf7dd 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs @@ -13,6 +13,7 @@ using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infra.EFCore.Common; using Microsoft.Extensions.Caching.Memory; using IRaCIS.Core.Application.Service.Reading.Dto; +using IRaCIS.Core.Infrastructure; namespace IRaCIS.Core.Application.Service { @@ -54,7 +55,12 @@ namespace IRaCIS.Core.Application.Service } #region 临时对象 单个请求的生命周期 避免重复查询数据库 + private List visitTaskAnswerList; + + /// + /// 获取Sod的值 + /// private decimal? sODData; #endregion @@ -78,151 +84,112 @@ namespace IRaCIS.Core.Application.Service /// public async Task ReadingCalculate(ReadingCalculateDto inDto) { - // 找到所有访视任务的Id - - var visitTaskIds = await _visitTaskRepository.Where(x => !x.IsAnalysisCreate && x.ReadingCategory == ReadingCategory.Visit && - x.TaskState == TaskState.Effect && x.ReadingTaskState == ReadingTaskState.HaveSigned && x.DoctorUserId == inDto.DoctorUserId).Select(x => x.Id).ToListAsync(); - - - #region 计算 这里顺序非常重要 后面计算的值要依赖前面计算的结果 var needAddList = new List(); - // 循环找要计算的值进行计算 - foreach (var item in inDto.QuestionInfo.Where(x => x.QuestionType != null)) - { - - switch (item.QuestionType) + + + List calculateList = new List() + { + //靶病灶径线之和(SOD) + new ReadingCalculateData (){QuestionType=QuestionType.SOD,GetDecimalNullFun=GetSODData}, + + //非淋巴结靶病灶长径之和 + new ReadingCalculateData (){QuestionType=QuestionType.SumOfDiameter,GetDecimalNullFun=GetSumOfDiameter}, + + //与基线SOD相比变化量(mm) + new ReadingCalculateData (){QuestionType=QuestionType.SODChange,GetDecimalNullFun=GetSODChange}, + + //与基线访视相比SOD变化百分比 + new ReadingCalculateData (){QuestionType=QuestionType.SODPercent,GetDecimalNullFun=GetSODPercent}, + + //与整个访视期间最低点相比增加的值(mm) 其他任务需要改 + new ReadingCalculateData (){QuestionType=QuestionType.LowestIncrease,GetDecimalNullFun=GetLowestIncrease,ChangeAllTaskFun=ChangeAllLowestIncrease}, + + //与整个访视期间最低点相比增加的百分比 其他任务需要改 + new ReadingCalculateData (){QuestionType=QuestionType.LowPercent,GetDecimalNullFun=GetLowPercent,ChangeAllTaskFun=ChangeAllLowPercent}, + + //整个访视期间最低点访视名称 其他任务需要改 + new ReadingCalculateData (){QuestionType=QuestionType.LowVisit,GetStringFun=GetLowVisit,ChangeAllTaskFun=ChangeAllLowVisitName}, + + //是否存在非淋巴结靶病灶 + new ReadingCalculateData (){QuestionType=QuestionType.IsLymphTarget,GetStringFun=GetIsLymphTarget}, + + //是否存在淋巴结靶病灶且该病灶比上一访视短径增加5MM以上 + new ReadingCalculateData (){QuestionType=QuestionType.IsAddFive,GetStringFun=GetIsAddFive}, + + //被评估为NE的单个靶病灶 + new ReadingCalculateData (){QuestionType=QuestionType.NETarget,GetStringFun=GetNETarget}, + + //靶病灶评估 + new ReadingCalculateData (){QuestionType=QuestionType.TargetLesion,GetStringFun=GetTargetLesionEvaluate}, + + //非靶病灶评估 + new ReadingCalculateData (){QuestionType=QuestionType.NoTargetLesion,GetStringFun=GetNoTargetLesionEvaluate}, + + //是否存在新病灶 + new ReadingCalculateData (){QuestionType=QuestionType.NewLesions,GetStringFun=GetNewLesionEvaluate}, + + //整体肿瘤评估 + new ReadingCalculateData (){QuestionType=QuestionType.Tumor,GetStringFun=GetTumor}, + + }; + + + foreach (var calculate in calculateList) + { + var item=inDto.QuestionInfo.FirstOrDefault(x => x.QuestionType == calculate.QuestionType); + + if (item != null) { - // 靶病灶径线之和(SOD) - case QuestionType.SOD: - needAddList.Add(new ReadingTaskQuestionAnswer() - { - Answer = (await GetSODData(inDto)).ToString(), - ReadingQuestionTrialId = item.QuestionId, - }); - break; + //计算答案 + if(inDto.IsOnlyChangeAllTask==false) + { - // 非淋巴结靶病灶长径之和 - case QuestionType.SumOfDiameter: - needAddList.Add(new ReadingTaskQuestionAnswer() + #region 计算答案 + if (calculate.GetDecimalFun != null) { - Answer = (await GetSumOfDiameter(inDto)).ToString(), - ReadingQuestionTrialId = item.QuestionId, - }); - break; - // 与基线SOD相比变化量(mm) - case QuestionType.SODChange: - needAddList.Add(new ReadingTaskQuestionAnswer() - { - Answer = (await GetSODChange(inDto)).ToString(), - ReadingQuestionTrialId = item.QuestionId, - }); - break; - // 与基线访视相比SOD变化百分比 - case QuestionType.SODPercent: - needAddList.Add(new ReadingTaskQuestionAnswer() - { - Answer = (await GetSODPercent(inDto)).ToString(), - ReadingQuestionTrialId = item.QuestionId, - }); - break; - // 与整个访视期间最低点相比增加的值(mm) 其他任务需要改 - case QuestionType.LowestIncrease: + item.Answer = (await calculate.GetDecimalFun(inDto)).ToString(); - if (!inDto.IsChangeOtherTask) - { - needAddList.Add(new ReadingTaskQuestionAnswer() - { - Answer = (await GetLowestIncrease(inDto)).ToString(), - ReadingQuestionTrialId = item.QuestionId, - }); } - else + else if (calculate.GetDecimalNullFun != null) { - await ChangeAllLowestIncrease(new ChangeAllTaskDto() - { - calculateDto = inDto, - QuestionId = item.QuestionId, - }); - } - - - break; - // 与整个访视期间最低点相比增加的百分比 其他任务需要改 - case QuestionType.LowPercent: - - if (!inDto.IsChangeOtherTask) - { - needAddList.Add(new ReadingTaskQuestionAnswer() + var value = await calculate.GetDecimalNullFun(inDto); + if (value == null) { - Answer = (await GetLowPercent(inDto)).ToString(), - ReadingQuestionTrialId = item.QuestionId, - }); - } - else - { - await ChangeAllLowPercent(inDto, item.QuestionId); - } - - - break; - // 整个访视期间最低点访视名称 其他任务需要改 - case QuestionType.LowVisit: - var answer = (await GetLowVisit(inDto)).ToString(); - if (!inDto.IsChangeOtherTask) - { - needAddList.Add(new ReadingTaskQuestionAnswer() + item.Answer = string.Empty; + } + else + { - Answer = answer, - ReadingQuestionTrialId = item.QuestionId, - }); - } - else - { - if (inDto.IsChangeOtherTask) - { - await this.ChangeAllVisitTaskAnswer(visitTaskIds, item.QuestionId, answer); + item.Answer = value.ToString(); } } + else if (calculate.GetStringFun != null) + { + item.Answer = await calculate.GetStringFun(inDto); + } + #endregion + needAddList.Add(new ReadingTaskQuestionAnswer() + { + Answer = item.Answer, + ReadingQuestionTrialId = item.QuestionId, + }); + } - break; - // 是否存在非淋巴结靶病灶 - case QuestionType.IsLymphTarget: - needAddList.Add(new ReadingTaskQuestionAnswer() + // 修改全局 + if (inDto.IsChangeOtherTask && calculate.ChangeAllTaskFun != null) + { + await calculate.ChangeAllTaskFun(new ChangeAllTaskDto() { - Answer = await GetIsLymphTarget(inDto), - ReadingQuestionTrialId = item.QuestionId, + calculateDto = inDto, + QuestionId = item.QuestionId, }); - break; - // 是否存在淋巴结靶病灶且该病灶比上一访视短径增加5MM以上 - case QuestionType.IsAddFive: - needAddList.Add(new ReadingTaskQuestionAnswer() - { - Answer = await GetIsAddFive(inDto), - ReadingQuestionTrialId = item.QuestionId, - }); - break; + } - // 被评估为NE的单个靶病灶 - case QuestionType.NETarget: - needAddList.Add(new ReadingTaskQuestionAnswer() - { - Answer = await GetNETarget(inDto), - ReadingQuestionTrialId = item.QuestionId, - }); - break; - - // 整体肿瘤评估 - case QuestionType.Tumor: - needAddList.Add(new ReadingTaskQuestionAnswer() - { - Answer = await GetTumor(inDto), - ReadingQuestionTrialId = item.QuestionId, - }); - break; } - } + } + var questionIds = needAddList.Select(x => x.ReadingQuestionTrialId).ToList(); @@ -252,13 +219,12 @@ namespace IRaCIS.Core.Application.Service /// public async Task VerifyVisitTaskQuestions(VerifyVisitTaskQuestionsInDto inDto) { - await this.CalculateTask(new CalculateTaskInDto() - { - VisitTaskId = inDto.VisitTaskId, - IsChangeOtherTask = true - }); - visitTaskAnswerList = null; + ReadingCalculateDto data = await GetReadingCalculateDto(inDto.VisitTaskId); + data.IsChangeOtherTask = true; + data.IsOnlyChangeAllTask = true; + await ReadingCalculate(data); + VerifyVisitTaskQuestionsOutDto result = new VerifyVisitTaskQuestionsOutDto() { IsVerified=true, @@ -285,6 +251,10 @@ namespace IRaCIS.Core.Application.Service } } } + if (!result.ErrorMessage.IsNullOrEmpty()) + { + throw new BusinessValidationFailedException(result.ErrorMessage); + } return result; } @@ -362,7 +332,7 @@ namespace IRaCIS.Core.Application.Service /// 非淋巴结的长径 和淋巴结的短径 /// /// - public async Task GetSODData(ReadingCalculateDto inDto) + public async Task GetSODData(ReadingCalculateDto inDto) { if (sODData != null) { @@ -371,6 +341,11 @@ namespace IRaCIS.Core.Application.Service var tableQuestion = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).SelectMany(x => x.TableRowInfoList).ToList(); + if (tableQuestion.Count() == 0) + { + return null; + } + decimal result = 0; foreach (var item in tableQuestion) @@ -403,10 +378,15 @@ namespace IRaCIS.Core.Application.Service /// /// /// - public async Task GetSumOfDiameter(ReadingCalculateDto inDto) + public async Task GetSumOfDiameter(ReadingCalculateDto inDto) { var tableQuestion = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).SelectMany(x => x.TableRowInfoList).ToList(); + if (tableQuestion.Count() == 0) + { + return null; + } + decimal result = 0; foreach (var item in tableQuestion) @@ -429,9 +409,16 @@ namespace IRaCIS.Core.Application.Service /// /// /// - public async Task GetSODChange(ReadingCalculateDto inDto) + public async Task GetSODChange(ReadingCalculateDto inDto) { - return await GetSODData(inDto) - await GetBaseLineSOD(inDto); + + var value = await GetSODData(inDto); + + if (value == null) + { + return null; + } + return value.NullChange0() - await GetBaseLineSOD(inDto); } #endregion @@ -441,9 +428,15 @@ namespace IRaCIS.Core.Application.Service /// /// /// - public async Task GetSODPercent(ReadingCalculateDto inDto) + public async Task GetSODPercent(ReadingCalculateDto inDto) { var thisSOD = await GetSODData(inDto); + + if (thisSOD == null) + { + return null; + } + var baseLineSOD = await GetBaseLineSOD(inDto); if (baseLineSOD == 0) @@ -452,7 +445,7 @@ namespace IRaCIS.Core.Application.Service } else { - return decimal.Round(thisSOD * 100 / baseLineSOD, 2); + return decimal.Round(thisSOD.NullChange0() * 100 / baseLineSOD, 2); } } #endregion @@ -466,11 +459,16 @@ namespace IRaCIS.Core.Application.Service /// 要更新之前的 /// /// - public async Task GetLowestIncrease(ReadingCalculateDto inDto) + public async Task GetLowestIncrease(ReadingCalculateDto inDto) { + var value = await GetSODData(inDto); + if (value == null) + { + return null; + } var decimalAnswerList = await GetVisitTaskAnswerList(inDto); var minSOD = decimalAnswerList.OrderBy(x => x.SOD).Select(x => x.SOD).FirstOrDefault(); - return await GetSODData(inDto) - minSOD; + return value.NullChange0() - minSOD; } #endregion @@ -483,9 +481,13 @@ namespace IRaCIS.Core.Application.Service /// 要更新之前的 /// /// - public async Task GetLowPercent(ReadingCalculateDto inDto) + public async Task GetLowPercent(ReadingCalculateDto inDto) { var thisSOD = await GetSODData(inDto); + if (thisSOD == null) + { + return null; + } var decimalAnswerList = await GetVisitTaskAnswerList(inDto); var minSOD = decimalAnswerList.OrderBy(x => x.SOD).Select(x => x.SOD).FirstOrDefault(); @@ -495,7 +497,7 @@ namespace IRaCIS.Core.Application.Service } else { - return decimal.Round((thisSOD- minSOD) * 100 / minSOD, 2); + return decimal.Round((thisSOD.NullChange0()- minSOD) * 100 / minSOD, 2); } @@ -618,7 +620,6 @@ namespace IRaCIS.Core.Application.Service /// 修改与整个访视期间最低点相比增加的值(mm) /// /// - /// /// public async Task ChangeAllLowestIncrease(ChangeAllTaskDto inDto) { @@ -642,11 +643,10 @@ namespace IRaCIS.Core.Application.Service /// 修改整个访视期间最低点相比增加的百分比 /// /// - /// /// - public async Task ChangeAllLowPercent(ReadingCalculateDto inDto, Guid questionId) + public async Task ChangeAllLowPercent(ChangeAllTaskDto inDto) { - var visitTaskList = await GetVisitTaskAnswerList(inDto); + var visitTaskList = await GetVisitTaskAnswerList(inDto.calculateDto); var lowSod = visitTaskList.Select(x => x.SOD).OrderBy(x => x).FirstOrDefault(); foreach (var item in visitTaskList) { @@ -660,7 +660,7 @@ namespace IRaCIS.Core.Application.Service percent= decimal.Round((item.SOD - lowSod) * 100 / lowSod, 2); } - await _readingTaskQuestionAnswerRepository.BatchUpdateNoTrackingAsync(x => x.VisitTaskId == item.VisitTaskId && x.ReadingQuestionTrialId == questionId, x => new ReadingTaskQuestionAnswer() + await _readingTaskQuestionAnswerRepository.BatchUpdateNoTrackingAsync(x => x.VisitTaskId == item.VisitTaskId && x.ReadingQuestionTrialId == inDto.QuestionId, x => new ReadingTaskQuestionAnswer() { Answer = percent.ToString() }); @@ -669,6 +669,26 @@ namespace IRaCIS.Core.Application.Service #endregion + #region 修改最低方式点名称 + /// + /// 修改最低方式点名称 + /// + /// + /// + public async Task ChangeAllLowVisitName(ChangeAllTaskDto inDto) + { + // 找到所有访视任务的Id + + var visitTaskIds = await _visitTaskRepository.Where(x => !x.IsAnalysisCreate && x.ReadingCategory == ReadingCategory.Visit && + x.TaskState == TaskState.Effect && x.ReadingTaskState == ReadingTaskState.HaveSigned && x.DoctorUserId == inDto.calculateDto.DoctorUserId).Select(x => x.Id).ToListAsync(); + + var answer = (await GetLowVisit(inDto.calculateDto)).ToString(); + await this.ChangeAllVisitTaskAnswer(visitTaskIds, inDto.QuestionId, answer); + + } + #endregion + + #endregion #region 通用方法 @@ -772,6 +792,11 @@ namespace IRaCIS.Core.Application.Service public async Task GetTargetLesionEvaluate(ReadingCalculateDto inDto) { var tableQuestion = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).SelectMany(x => x.TableRowInfoList).ToList(); + + if (tableQuestion.Count() == 0) + { + return string.Empty; + } TargetLesionCalculateDto resultData = new TargetLesionCalculateDto() { //非淋巴结靶病灶长径之和 decimal @@ -911,8 +936,8 @@ namespace IRaCIS.Core.Application.Service var tableQuestions = tableRows.SelectMany(x => x.TableQuestionList).ToList(); - //任意单个病灶 / 病灶组评估为“显著增大” - if (tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer == "显著增大")) + //任意单个病灶 / 病灶组评估为“显著增大” + if (tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer == "显著增大")) { return "PD"; } @@ -964,9 +989,10 @@ namespace IRaCIS.Core.Application.Service var tableQuestions = tableRows.SelectMany(x => x.TableQuestionList).ToList(); + - // 当前访视存在至少一个明确新病灶 - if (tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer == "明确")) + // 当前访视存在至少一个明确新病灶 + if (tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer == "明确")) { return "是"; } diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs index bb9133e66..f55e15ad2 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs @@ -1851,9 +1851,21 @@ namespace IRaCIS.Application.Services /// /// [HttpPost] - public async Task VerifyVisitTaskQuestions(VerifyVisitTaskQuestionsInDto inDto) + public async Task VerifyVisitTaskQuestions(VerifyVisitTaskQuestionsInDto inDto) { - return await _readingCalculateService.VerifyVisitTaskQuestions(inDto); + List calculateList = new List() + { + + new ReadingCalculateData (){ + QuestionType=QuestionType.SOD, + + }, + + + }; + + await _readingCalculateService.VerifyVisitTaskQuestions(inDto); + return ResponseOutput.Ok(true); } /// diff --git a/IRaCIS.Core.Infra.EFCore/Common/ReadingCommon.cs b/IRaCIS.Core.Infra.EFCore/Common/ReadingCommon.cs index 39540633b..94e5178a0 100644 --- a/IRaCIS.Core.Infra.EFCore/Common/ReadingCommon.cs +++ b/IRaCIS.Core.Infra.EFCore/Common/ReadingCommon.cs @@ -38,6 +38,19 @@ namespace IRaCIS.Core.Infra.EFCore.Common } } + public static decimal NullChange0(this decimal? value) + { + if (value == null) + { + return 0; + + } + else + { + return value.Value; + } + } + public static decimal IsNullOrEmptyReturn0(this string value) { if (value == null || value == string.Empty)