From b532ff775e9363d1dbd604a3dfe22a08412899e9 Mon Sep 17 00:00:00 2001 From: he <10978375@qq.com> Date: Tue, 30 Aug 2022 16:08:19 +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 | 20 +- .../Interface/IReadingCalculateService.cs | 8 +- .../Reading/ReadingCalculateService.cs | 208 +++++++++++++++++- .../Reading/ReadingImageTaskService.cs | 9 + IRaCIS.Core.Domain.Share/Reading/ReadEnum.cs | 6 +- 5 files changed, 227 insertions(+), 24 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs index cdbc2a392..6568424d9 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs @@ -8,6 +8,14 @@ using IRaCIS.Core.Domain.Share; using System.Collections.Generic; namespace IRaCIS.Core.Application.ViewModel { + + public class CalculateTaskInDto + { + public Guid VisitTaskId { get; set; } + + public bool IsChangeOtherTask { get; set; } + } + /// /// 阅片计算Dto /// @@ -18,6 +26,10 @@ namespace IRaCIS.Core.Application.ViewModel public Guid VisitTaskId { get; set; } + public Guid CriterionId { get; set; } + + public Guid TrialId { get; set; } + public Guid SubjectVisitId { get; set; } public List QuestionInfo { get; set; } = new List(); @@ -29,7 +41,6 @@ namespace IRaCIS.Core.Application.ViewModel public class QuestionInfo { - public Guid QuestionId { get; set; } /// @@ -37,7 +48,6 @@ namespace IRaCIS.Core.Application.ViewModel /// public string Answer { get; set; } - /// /// 病灶类型 /// @@ -45,11 +55,8 @@ namespace IRaCIS.Core.Application.ViewModel public QuestionType? QuestionType { get; set; } - - public List TableRowInfoList = new List(); - } @@ -72,6 +79,9 @@ namespace IRaCIS.Core.Application.ViewModel /// public Guid TableQuestionId { get; set; } + public Guid QuestionId { get; set; } + + public int RowIndex { get; set; } /// /// 问题标识 diff --git a/IRaCIS.Core.Application/Service/Reading/Interface/IReadingCalculateService.cs b/IRaCIS.Core.Application/Service/Reading/Interface/IReadingCalculateService.cs index a9244017a..aba474474 100644 --- a/IRaCIS.Core.Application/Service/Reading/Interface/IReadingCalculateService.cs +++ b/IRaCIS.Core.Application/Service/Reading/Interface/IReadingCalculateService.cs @@ -12,10 +12,6 @@ namespace IRaCIS.Core.Application.Interfaces /// public interface IReadingCalculateService { - - - - - - } + Task CalculateTask(CalculateTaskInDto inDto); + } } diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs index cef4dab3f..dde950bb2 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingCalculateService.cs @@ -22,7 +22,9 @@ namespace IRaCIS.Core.Application.Service { private readonly IRepository _readingTableQuestionAnswerRepository; private readonly IRepository _visitTaskRepository; + private readonly IRepository _readingQuestionCriterionTrialRepository; private readonly IRepository _readingTableQuestionTrialRepository; + private readonly IRepository _readingQuestionTrialRepository; private readonly IRepository _subjectVisitRepository; private readonly IRepository _tumorAssessmentRepository; private readonly IRepository _readingTaskQuestionAnswerRepository; @@ -30,18 +32,204 @@ namespace IRaCIS.Core.Application.Service public ReadingCalculateService( IRepository readingTableQuestionAnswerRepository, IRepository visitTaskRepository, - IRepository readingTableQuestionTrialRepository, + IRepository readingQuestionCriterionTrialRepository, + IRepository readingTableQuestionTrialRepository, + IRepository readingQuestionTrialRepository, + IRepository subjectVisitRepository, IRepository tumorAssessmentRepository, - IRepository ReadingTaskQuestionAnswerRepository + IRepository readingTaskQuestionAnswerRepository ) { this._readingTableQuestionAnswerRepository = readingTableQuestionAnswerRepository; this._visitTaskRepository = visitTaskRepository; + this._readingQuestionCriterionTrialRepository = readingQuestionCriterionTrialRepository; this._readingTableQuestionTrialRepository = readingTableQuestionTrialRepository; + this._readingQuestionTrialRepository = readingQuestionTrialRepository; this._subjectVisitRepository = subjectVisitRepository; this._tumorAssessmentRepository = tumorAssessmentRepository; - this._readingTaskQuestionAnswerRepository = ReadingTaskQuestionAnswerRepository; + this._readingTaskQuestionAnswerRepository = readingTaskQuestionAnswerRepository; + } + + /// + /// 计算任务 + /// + /// + /// + public async Task CalculateTask(CalculateTaskInDto inDto) + { + var visitTask = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).FirstNotNullAsync(); + var criterionId = await _readingQuestionCriterionTrialRepository.Where(x => x.TrialId == visitTask.TrialId && x.IsConfirm).Select(x => x.Id).FirstOrDefaultAsync(); + List questionInfos = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == criterionId).Select(x => new QuestionInfo() + { + LesionType=x.LesionType, + QuestionId=x.Id, + QuestionType=x.QuestionType, + }).ToListAsync(); + + var questionAnswers = await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId).Select(x => new + { + x.ReadingQuestionTrialId, + x.Answer + }).ToListAsync() ; + + var tableQuestion = await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId).Include(x=>x.ReadingTableQuestionTrial).Select(x => new TableQuestionInfo() + { + Answer = x.Answer, + QuestionMark = x.ReadingTableQuestionTrial.QuestionMark, + TableQuestionId = x.TableQuestionId, + QuestionId=x.QuestionId, + RowIndex=x.RowIndex, + }).ToListAsync(); + + foreach (var item in questionInfos) + { + item.Answer = questionAnswers.Where(y => y.ReadingQuestionTrialId == item.QuestionId).Select(x => x.Answer).FirstOrDefault() ?? string.Empty; + + var thisItemTableQuestions = tableQuestion.Where(x => x.QuestionId == item.QuestionId).ToList(); + + item.TableRowInfoList= thisItemTableQuestions.GroupBy(x=> new { x.RowIndex }) + .Select(g => new TableRowInfo() + { + RowIndex = g.Key.RowIndex, + TableQuestionList = g.ToList() + }).ToList(); + } + + ReadingCalculateDto readingData = new ReadingCalculateDto() + { + SubjectId = visitTask.SubjectId, + VisitTaskId = inDto.VisitTaskId, + SubjectVisitId = visitTask.SourceSubjectVisitId.Value, + QuestionInfo = questionInfos, + CriterionId= criterionId, + TrialId=visitTask.TrialId, + }; + await ReadingCalculate(readingData); + } + + + /// + /// 自动计算 + /// + /// + /// + public async Task ReadingCalculate(ReadingCalculateDto inDto) + { + + var needAddList = new List(); + foreach (var item in inDto.QuestionInfo) + { + switch (item.QuestionType) + { + // 靶病灶径线之和(SOD) + case QuestionType.SOD: + needAddList.Add(new ReadingTaskQuestionAnswer() + { + Answer = (await GetSODData(inDto)).ToString(), + ReadingQuestionTrialId=item.QuestionId, + }); + break; + // 非淋巴结靶病灶长径之和 + case QuestionType.SumOfDiameter: + needAddList.Add(new ReadingTaskQuestionAnswer() + { + 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: + needAddList.Add(new ReadingTaskQuestionAnswer() + { + Answer = (await GetLowestIncrease(inDto)).ToString(), + ReadingQuestionTrialId = item.QuestionId, + }); + break; + // 与整个访视期间最低点相比增加的百分比 其他任务需要改 + case QuestionType.LowPercent: + needAddList.Add(new ReadingTaskQuestionAnswer() + { + Answer = (await GetLowPercent(inDto)).ToString(), + ReadingQuestionTrialId = item.QuestionId, + }); + break; + // 整个访视期间最低点访视名称 其他任务需要改 + case QuestionType.LowVisit: + needAddList.Add(new ReadingTaskQuestionAnswer() + { + Answer = (await GetLowVisit(inDto)).ToString(), + ReadingQuestionTrialId = item.QuestionId, + }); + break; + // 是否存在非淋巴结靶病灶 + case QuestionType.IsLymphTarget: + needAddList.Add(new ReadingTaskQuestionAnswer() + { + Answer = await GetIsLymphTarget(inDto), + ReadingQuestionTrialId = 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(); + + await _readingTaskQuestionAnswerRepository.BatchDeleteNoTrackingAsync(x => questionIds.Contains(x.ReadingQuestionTrialId) && x.VisitTaskId == inDto.VisitTaskId); + needAddList.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(needAddList); + + await _readingTaskQuestionAnswerRepository.SaveChangesAsync(); } @@ -63,13 +251,13 @@ namespace IRaCIS.Core.Application.Service foreach (var item in tableQuestion) { - if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && x.Answer == "是")) + if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && (x.Answer == "是"||x.Answer.ToLower()=="true".ToLower()))) { // 淋巴结的短径 result += decimal.Parse(item.TableQuestionList.Where(x => x.QuestionMark == QuestionMark.ShortAxis).Select(x => x.Answer).FirstOrDefault() ?? "0"); } - if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && x.Answer == "否")) + if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && (x.Answer == "是" || x.Answer.ToLower() == "true".ToLower()))) { // 非淋巴结的长径 result += decimal.Parse(item.TableQuestionList.Where(x => x.QuestionMark == QuestionMark.MajorAxis).Select(x => x.Answer).FirstOrDefault() ?? "0"); @@ -97,7 +285,7 @@ namespace IRaCIS.Core.Application.Service foreach (var item in tableQuestion) { - if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && x.Answer == "否")) + if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && (x.Answer == "是" || x.Answer.ToLower() == "false".ToLower()))) { // 非淋巴结的长径 result += decimal.Parse(item.TableQuestionList.Where(x => x.QuestionMark == QuestionMark.MajorAxis).Select(x => x.Answer).FirstOrDefault() ?? "0"); @@ -216,7 +404,7 @@ namespace IRaCIS.Core.Application.Service foreach (var item in tableQuestion) { - if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && x.Answer == "是")) + if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && (x.Answer == "是" || x.Answer.ToLower() == "true".ToLower()))) { return "是"; } @@ -232,14 +420,14 @@ namespace IRaCIS.Core.Application.Service /// /// /// - public async Task GetIsAddFive(ReadingCalculateDto inDto) + public async Task GetIsAddFive(ReadingCalculateDto inDto) { var LastVisitTaskId = await this.GetLastVisitTaskId(inDto); var questionIds = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).Select(x => x.QuestionId).ToList(); var lastQuestionAsnwer = await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == LastVisitTaskId && questionIds.Contains(x.QuestionId)).Include(x=>x.ReadingQuestionTrial).ToListAsync(); - var rowIndexs = lastQuestionAsnwer.Where(x=>x.ReadingTableQuestionTrial.QuestionMark==QuestionMark.IsLymph&&x.Answer=="是").Select(x => x.RowIndex).Distinct().OrderBy(x => x).ToList(); + var rowIndexs = lastQuestionAsnwer.Where(x=>x.ReadingTableQuestionTrial.QuestionMark==QuestionMark.IsLymph&& (x.Answer == "是" || x.Answer.ToLower() == "true".ToLower())).Select(x => x.RowIndex).Distinct().OrderBy(x => x).ToList(); var thisQuestionAsnwer = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).SelectMany(x => x.TableRowInfoList).ToList(); @@ -257,7 +445,7 @@ namespace IRaCIS.Core.Application.Service } } - return isExists; + return isExists?"是":"否"; } #endregion diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs index 8049bd4db..f61a6cfa8 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs @@ -17,6 +17,7 @@ using IRaCIS.Core.Infrastructure; using Newtonsoft.Json; using IRaCIS.Core.Application.Service; using IRaCIS.Core.Application.ViewModel; +using IRaCIS.Core.Application.Interfaces; namespace IRaCIS.Application.Services { @@ -35,6 +36,7 @@ namespace IRaCIS.Application.Services private readonly IVisitTaskHelpeService _visitTaskHelpeService; private readonly IVisitTaskService _visitTaskService; private readonly IReadingClinicalDataService _readingClinicalDataService; + private readonly IReadingCalculateService _readingCalculateService; private readonly IRepository _subjectVisitRepository; private readonly IRepository _subjectRepository; private readonly IRepository _readingGlobalTaskInfoRepository; @@ -61,6 +63,7 @@ namespace IRaCIS.Application.Services IVisitTaskHelpeService visitTaskHelpeService, IVisitTaskService visitTaskService, IReadingClinicalDataService readingClinicalDataService, + IReadingCalculateService readingCalculateService, IRepository subjectVisitRepository, IRepository subjectRepository, IRepository readingGlobalTaskInfoRepository, @@ -86,6 +89,7 @@ namespace IRaCIS.Application.Services this._visitTaskHelpeService = visitTaskHelpeService; this._visitTaskService = visitTaskService; this._readingClinicalDataService = readingClinicalDataService; + this._readingCalculateService = readingCalculateService; this._subjectVisitRepository = subjectVisitRepository; this._subjectRepository = subjectRepository; this._readingGlobalTaskInfoRepository = readingGlobalTaskInfoRepository; @@ -1567,6 +1571,11 @@ namespace IRaCIS.Application.Services }); await _readingTableQuestionAnswerRepository.AddRangeAsync(answerList); await _readingTableQuestionAnswerRepository.SaveChangesAsync(); + await this._readingCalculateService.CalculateTask(new CalculateTaskInDto() + { + IsChangeOtherTask=false, + VisitTaskId=inDto.VisitTaskId, + }); return ResponseOutput.Ok(true); } diff --git a/IRaCIS.Core.Domain.Share/Reading/ReadEnum.cs b/IRaCIS.Core.Domain.Share/Reading/ReadEnum.cs index a1c98e246..78b8bc87b 100644 --- a/IRaCIS.Core.Domain.Share/Reading/ReadEnum.cs +++ b/IRaCIS.Core.Domain.Share/Reading/ReadEnum.cs @@ -271,17 +271,17 @@ namespace IRaCIS.Core.Domain.Share SODPercent = 3, /// - /// 与整个访视期间最低点相比增加的值(mm) + /// 与整个访视期间最低点相比增加的值(mm) 其他任务需要改 /// LowestIncrease = 4, /// - /// 与整个访视期间最低点相比增加的百分比 + /// 与整个访视期间最低点相比增加的百分比 其他任务需要改 /// LowPercent = 5, /// - /// 整个访视期间最低点访视名称 + /// 整个访视期间最低点访视名称 其他任务需要改 /// LowVisit = 6,