diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingImageTaskViewModel.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingImageTaskViewModel.cs index 35824b4a4..91f19e283 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingImageTaskViewModel.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingImageTaskViewModel.cs @@ -202,6 +202,34 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto public Guid TrialId { get; set; } } + public class CopyTableAnswerDto + { + public int RowIndex { get; set; } + + /// + /// 问题标识 + /// + public QuestionMark? QuestionMark { get; set; } + + + /// + /// 问题Id + /// + + public Guid QuestionId { get; set; } + + /// + /// 表格问题Id + /// + public Guid TableQuestionId { get; set; } + + /// + /// 项目Id + /// + public Guid TrialId { get; set; } + + public string Answer { get; set; } + } public class GetReadingReportEvaluationInDto { public Guid VisitTaskId { get; set; } @@ -211,6 +239,9 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto public class GetReadingQuestionAndAnswerOutDto { + + public bool IsBaseLineTask { get; set; } + public List SinglePage { get; set; } public List MultiPage { get; set; } diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs index 09ac78d17..215d11e78 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs @@ -212,6 +212,73 @@ namespace IRaCIS.Application.Services } + /// + /// 添加基线表格数据到其他任务 + /// + /// + /// + + private async Task AddBaseLineAnswerToOtherTask(Guid visitTaskId) + { + var taskinfo = await _visitTaskRepository.Where(x => x.Id == visitTaskId).FirstNotNullAsync(); + + var baseLineVisitId = await _subjectVisitRepository.Where(x => x.SubjectId == taskinfo.SourceSubjectVisitId && x.IsBaseLine).Select(x => x.Id).FirstOrDefaultAsync(); + + // 判断当前任务是否是基线 + if (taskinfo.SourceSubjectVisitId != baseLineVisitId) + { + // 判断当前任务是是否有表格问题答案 + if (!(await _readingTableQuestionAnswerRepository.AnyAsync(x => x.VisitTaskId == visitTaskId))) + { + // 找到基线的任务Id + var baseLineTaskId = await _visitTaskRepository.Where(x => x.SourceSubjectVisitId == baseLineVisitId && x.TaskState == TaskState.Effect).Select(x => x.Id).FirstOrDefaultAsync(); + + var copyTableAnswers =await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == baseLineVisitId).Select(x=> new CopyTableAnswerDto() { + Answer=x.Answer, + QuestionId=x.QuestionId, + QuestionMark=x.ReadingTableQuestionTrial.QuestionMark, + TableQuestionId=x.TableQuestionId, + RowIndex=x.RowIndex, + TrialId=x.TrialId + }).ToListAsync(); + + var tableRowAnswers=await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == baseLineVisitId).Select(x=> new ReadingTableAnswerRowInfo() { + Id = NewId.NextGuid(), + IsCurrentTaskAdd=false, + QuestionId=x.QuestionId, + RowIndex=x.RowIndex, + TrialId=x.TrialId, + VisitTaskId=visitTaskId + }).ToListAsync(); + + List notNeedCopyMarks = new List() + { + QuestionMark.MajorAxis, + QuestionMark.ShortAxis, + }; + + var tableAnswers = copyTableAnswers.Select(x => new ReadingTableQuestionAnswer + { + Id = NewId.NextGuid(), + Answer = notNeedCopyMarks.Contains(x.QuestionMark) ? string.Empty : x.Answer, + QuestionId = x.QuestionId, + RowIndex = x.RowIndex, + TableQuestionId = x.TableQuestionId, + TrialId = x.TrialId, + VisitTaskId = visitTaskId, + }); + + await _readingTableAnswerRowInfoRepository.AddRangeAsync(tableRowAnswers); + await _readingTableQuestionAnswerRepository.AddRangeAsync(tableAnswers); + await _readingTableQuestionAnswerRepository.SaveChangesAsync(); + + } + } + + return taskinfo.SourceSubjectVisitId == baseLineVisitId; + + } + /// /// 获取阅片报告 /// @@ -381,11 +448,14 @@ namespace IRaCIS.Application.Services public async Task<(GetReadingQuestionAndAnswerOutDto,object)> GetReadingQuestionAndAnswer(GetReadingQuestionAndAnswerInDto inDto) { + var result = new GetReadingQuestionAndAnswerOutDto(); + result.IsBaseLineTask= await this.AddBaseLineAnswerToOtherTask(inDto.VisitTaskId); + var readingTaskState = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Select(x => x.ReadingTaskState).FirstOrDefaultAsync(); var criterion = await _readingQuestionCriterionTrialRepository.Where(x => x.TrialId == inDto.TrialId && x.IsConfirm).FirstNotNullAsync(); - var result = new GetReadingQuestionAndAnswerOutDto(); + #region 获取问题及答案 @@ -473,6 +543,8 @@ namespace IRaCIS.Application.Services } + + /// /// 获取子元素 /// @@ -516,7 +588,7 @@ namespace IRaCIS.Application.Services var thisAnswer = tableAnswers.Where(x => x.QuestionId == item.Id).ToList(); var orders = thisAnswer.Select(x => x.RowIndex).Distinct().OrderBy(x => x).ToList(); item.TableQuestions.Answers = new List>(); - orders.ForEach(x => + orders.ForEach(async x => { Dictionary answers = new Dictionary(); var rowAnswer = thisAnswer.Where(y => y.RowIndex == x).OrderBy(y => y.ShowOrder).ToList(); @@ -531,6 +603,8 @@ namespace IRaCIS.Application.Services answers.Add("RowIndex", x.ToString()); answers.Add("InstanceId", rowInfo == null ? string.Empty : rowInfo.InstanceId.ToString()); answers.Add("SeriesId", rowInfo == null ? string.Empty : rowInfo.SeriesId.ToString()); + answers.Add("IsCurrentTaskAdd", rowInfo == null ? false.ToString() : rowInfo.IsCurrentTaskAdd.ToString()); + item.TableQuestions.Answers.Add(answers); }); @@ -1794,6 +1868,7 @@ namespace IRaCIS.Application.Services TrialId = inDto.TrialId, QuestionId = inDto.QuestionId, MeasureData = inDto.MeasureData, + IsCurrentTaskAdd=true, RowIndex = inDto.RowIndex, InstanceId=inDto.InstanceId, SeriesId=inDto.SeriesId, diff --git a/IRaCIS.Core.Domain/Reading/ReadingTableAnswerRowInfo.cs b/IRaCIS.Core.Domain/Reading/ReadingTableAnswerRowInfo.cs index 83514767f..907572ab4 100644 --- a/IRaCIS.Core.Domain/Reading/ReadingTableAnswerRowInfo.cs +++ b/IRaCIS.Core.Domain/Reading/ReadingTableAnswerRowInfo.cs @@ -55,10 +55,15 @@ namespace IRaCIS.Core.Domain.Models /// CreateTime /// public DateTime CreateTime { get; set; } - + /// - /// CreateUserId - /// + /// 是否是当前任务添加 + /// + public bool IsCurrentTaskAdd { get; set; } = false; + + /// + /// CreateUserId + /// public Guid CreateUserId { get; set; } [ForeignKey("QuestionId")]