641 lines
28 KiB
C#
641 lines
28 KiB
C#
using IRaCIS.Core.Application.Service.Reading.Dto;
|
||
using IRaCIS.Core.Domain.Share;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using IRaCIS.Core.Domain.Models;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using IRaCIS.Core.Application.Interfaces;
|
||
using IRaCIS.Core.Application.ViewModel;
|
||
using Panda.DynamicWebApi.Attributes;
|
||
using IRaCIS.Core.Infra.EFCore.Common;
|
||
using Microsoft.Extensions.Caching.Memory;
|
||
|
||
using IRaCIS.Core.Infrastructure;
|
||
using MassTransit;
|
||
|
||
namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||
{
|
||
[ApiExplorerSettings(GroupName = "Reading")]
|
||
public class PCWG3CalculateService : BaseService, ICriterionCalculateService
|
||
{
|
||
private readonly IRepository<ReadingTableQuestionAnswer> _readingTableQuestionAnswerRepository;
|
||
private readonly IRepository<VisitTask> _visitTaskRepository;
|
||
private readonly IRepository<ReadingQuestionCriterionTrial> _readingQuestionCriterionTrialRepository;
|
||
private readonly IRepository<ReadingTableQuestionTrial> _readingTableQuestionTrialRepository;
|
||
private readonly IRepository<ReadingTableAnswerRowInfo> _readingTableAnswerRowInfoRepository;
|
||
private readonly IRepository<ReadingQuestionTrial> _readingQuestionTrialRepository;
|
||
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
|
||
private readonly IRepository<TumorAssessment> _tumorAssessmentRepository;
|
||
private readonly IGeneralCalculateService _generalCalculateService;
|
||
private readonly IRepository<ReadingTaskQuestionAnswer> _readingTaskQuestionAnswerRepository;
|
||
|
||
public PCWG3CalculateService(
|
||
IRepository<ReadingTableQuestionAnswer> readingTableQuestionAnswerRepository,
|
||
IRepository<VisitTask> visitTaskRepository,
|
||
IRepository<ReadingQuestionCriterionTrial> readingQuestionCriterionTrialRepository,
|
||
IRepository<ReadingTableQuestionTrial> readingTableQuestionTrialRepository,
|
||
IRepository<ReadingTableAnswerRowInfo> readingTableAnswerRowInfoRepository,
|
||
IRepository<ReadingQuestionTrial> readingQuestionTrialRepository,
|
||
IRepository<SubjectVisit> subjectVisitRepository,
|
||
IRepository<TumorAssessment> tumorAssessmentRepository,
|
||
IGeneralCalculateService generalCalculateService,
|
||
IRepository<ReadingTaskQuestionAnswer> readingTaskQuestionAnswerRepository
|
||
)
|
||
{
|
||
this._readingTableQuestionAnswerRepository = readingTableQuestionAnswerRepository;
|
||
this._visitTaskRepository = visitTaskRepository;
|
||
this._readingQuestionCriterionTrialRepository = readingQuestionCriterionTrialRepository;
|
||
this._readingTableQuestionTrialRepository = readingTableQuestionTrialRepository;
|
||
this._readingTableAnswerRowInfoRepository = readingTableAnswerRowInfoRepository;
|
||
this._readingQuestionTrialRepository = readingQuestionTrialRepository;
|
||
this._subjectVisitRepository = subjectVisitRepository;
|
||
this._tumorAssessmentRepository = tumorAssessmentRepository;
|
||
this._generalCalculateService = generalCalculateService;
|
||
this._readingTaskQuestionAnswerRepository = readingTaskQuestionAnswerRepository;
|
||
}
|
||
|
||
|
||
#region 获取阅片报告
|
||
/// <summary>
|
||
/// 获取阅片报告
|
||
/// </summary>
|
||
/// <param name="indto"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<GetReadingReportEvaluationOutDto> GetReadingReportEvaluation(GetReadingReportEvaluationInDto indto)
|
||
{
|
||
GetReadingReportEvaluationOutDto result = new GetReadingReportEvaluationOutDto();
|
||
|
||
result.CalculateResult = await this.GetReportVerify(new GetReportVerifyInDto()
|
||
{
|
||
VisitTaskId = indto.VisitTaskId
|
||
});
|
||
|
||
var visitTaskInfo = await _visitTaskRepository.Where(x => x.Id == indto.VisitTaskId).FirstNotNullAsync();
|
||
|
||
|
||
result.ReadingTaskState = visitTaskInfo.ReadingTaskState;
|
||
var taskInfoList = await _generalCalculateService.GetReadingReportTaskList(indto.VisitTaskId);
|
||
|
||
result.VisitTaskList = taskInfoList;
|
||
|
||
var visitTaskIds = taskInfoList.Select(x => x.VisitTaskId).ToList();
|
||
|
||
var criterionId = visitTaskInfo.TrialReadingCriterionId;
|
||
var questionList = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == criterionId)
|
||
.Where(x=>x.LesionType!=LesionType.AlwaysNewLesions&&x.LesionType!=LesionType.BaselineLesions)
|
||
.ToListAsync();
|
||
var tableQuestionList = await _readingTableQuestionTrialRepository.Where(x => x.TrialCriterionId == criterionId).OrderBy(x => x.ShowOrder).ToListAsync();
|
||
var tableAnsweRowInfos = await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == indto.VisitTaskId).ProjectTo<TableAnsweRowInfo>(_mapper.ConfigurationProvider).ToListAsync();
|
||
var answers = await _readingTaskQuestionAnswerRepository.Where(x => visitTaskIds.Contains(x.VisitTaskId)).ToListAsync();
|
||
var tableAnswers = await _readingTableQuestionAnswerRepository.Where(x => visitTaskIds.Contains(x.VisitTaskId)).ToListAsync();
|
||
|
||
|
||
// 新病灶
|
||
var questionNewLesions = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == visitTaskInfo.TrialReadingCriterionId && x.LesionType == LesionType.NewLesions).FirstNotNullAsync();
|
||
|
||
// 既往新病灶
|
||
var questionAlwaysLesions = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == visitTaskInfo.TrialReadingCriterionId && x.LesionType == LesionType.AlwaysNewLesions).FirstNotNullAsync();
|
||
|
||
foreach (var item in tableAnsweRowInfos)
|
||
{
|
||
if (item.QuestionId == questionAlwaysLesions.Id)
|
||
{
|
||
item.QuestionId = questionNewLesions.Id;
|
||
}
|
||
}
|
||
|
||
foreach (var item in answers)
|
||
{
|
||
if (item.ReadingQuestionTrialId == questionAlwaysLesions.Id)
|
||
{
|
||
item.ReadingQuestionTrialId = questionNewLesions.Id;
|
||
}
|
||
}
|
||
|
||
foreach (var item in tableAnswers)
|
||
{
|
||
if (item.QuestionId == questionAlwaysLesions.Id)
|
||
{
|
||
item.QuestionId = questionNewLesions.Id;
|
||
}
|
||
}
|
||
|
||
|
||
// 第一级 分组
|
||
|
||
#region 构造问题
|
||
List<ReadingReportDto> questions = questionList.Where(x => x.Type == ReadingQestionType.Group).OrderBy(x => x.ShowOrder).Select(x => new ReadingReportDto()
|
||
{
|
||
QuestionId = x.Id,
|
||
GroupName = x.GroupName,
|
||
IsShowInDicom = x.IsShowInDicom,
|
||
Type = x.Type,
|
||
QuestionType = x.QuestionType,
|
||
LesionType = x.LesionType,
|
||
QuestionGenre = x.QuestionGenre,
|
||
DictionaryCode = x.DictionaryCode,
|
||
TypeValue = x.TypeValue,
|
||
QuestionName = x.QuestionName,
|
||
ShowOrder = x.ShowOrder,
|
||
ValueType = x.ValueType,
|
||
Unit = x.Unit,
|
||
|
||
}).ToList();
|
||
|
||
// 分组
|
||
foreach (var item in questions)
|
||
{
|
||
// 问题
|
||
item.Childrens = questionList.Where(x => x.GroupName == item.GroupName && x.Type != ReadingQestionType.Group).OrderBy(x => x.ShowOrder).Select(x => new ReadingReportDto()
|
||
{
|
||
GroupName = x.GroupName,
|
||
QuestionId = x.Id,
|
||
IsShowInDicom = x.IsShowInDicom,
|
||
QuestionName = x.QuestionName,
|
||
LesionType = x.LesionType,
|
||
QuestionGenre = x.QuestionGenre,
|
||
DictionaryCode = x.DictionaryCode,
|
||
Type = x.Type,
|
||
QuestionType = x.QuestionType,
|
||
TypeValue = x.TypeValue,
|
||
ShowOrder = x.ShowOrder,
|
||
OrderMark = x.OrderMark,
|
||
ValueType = x.ValueType,
|
||
Unit = x.Unit,
|
||
|
||
}).ToList();
|
||
|
||
// 问题
|
||
foreach (var question in item.Childrens)
|
||
{
|
||
|
||
foreach (var task in taskInfoList)
|
||
{
|
||
|
||
question.Answer.Add(new TaskQuestionAnswer()
|
||
{
|
||
Answer = answers.Where(x => x.VisitTaskId == task.VisitTaskId && x.ReadingQuestionTrialId == question.QuestionId).Select(x => x.Answer).FirstIsNullReturnEmpty(),
|
||
TaskName = task.TaskName,
|
||
VisitTaskId = task.VisitTaskId,
|
||
});
|
||
}
|
||
|
||
// 构造表格行数据
|
||
|
||
|
||
var rowlist = tableAnsweRowInfos.Where(x => x.QuestionId == question.QuestionId).OrderBy(x => x.RowIndex).ToList();
|
||
|
||
|
||
question.Childrens = rowlist.OrderBy(x=>x.FristAddTaskNum).ThenBy(x=>x.RowIndex).Select(x => new ReadingReportDto()
|
||
{
|
||
QuestionName = question.OrderMark + x.RowIndex.GetLesionMark(),
|
||
SplitOrMergeLesionName = x.MergeName.IsNullOrEmpty() ? x.SplitName : x.MergeName,
|
||
SplitOrMergeType = x.SplitOrMergeType,
|
||
LesionType = question.LesionType,
|
||
IsCanEditPosition = x.IsCanEditPosition,
|
||
RowIndex = x.RowIndex,
|
||
BlindName = x.BlindName,
|
||
}).ToList();
|
||
|
||
|
||
foreach (var row in question.Childrens)
|
||
{
|
||
// tableQuestion
|
||
row.Childrens = tableQuestionList.Where(x => x.ReadingQuestionId == question.QuestionId).Select(x => new ReadingReportDto()
|
||
{
|
||
QuestionName = x.QuestionName,
|
||
QuestionId = x.ReadingQuestionId,
|
||
TableQuestionId = x.Id,
|
||
Type = x.Type,
|
||
LesionType = question.LesionType,
|
||
TableQuestionType = x.TableQuestionType,
|
||
DictionaryCode = x.DictionaryCode,
|
||
QuestionMark = x.QuestionMark,
|
||
TypeValue = x.TypeValue,
|
||
RowIndex = row.RowIndex,
|
||
ShowOrder = x.ShowOrder,
|
||
ValueType = x.ValueType,
|
||
Unit = x.Unit,
|
||
}).ToList();
|
||
|
||
|
||
foreach (var tableQuestion in row.Childrens)
|
||
{
|
||
foreach (var task in taskInfoList)
|
||
{
|
||
|
||
tableQuestion.Answer.Add(new TaskQuestionAnswer()
|
||
{
|
||
Answer = tableAnswers.Where(x => x.VisitTaskId == task.VisitTaskId && x.QuestionId == tableQuestion.QuestionId && x.RowIndex == tableQuestion.RowIndex && x.TableQuestionId == tableQuestion.TableQuestionId).Select(x => x.Answer).FirstIsNullReturnEmpty(),
|
||
TaskName = task.TaskName,
|
||
VisitTaskId = task.VisitTaskId,
|
||
});
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
};
|
||
}
|
||
#endregion
|
||
|
||
|
||
|
||
result.TaskQuestions = questions;
|
||
|
||
|
||
|
||
return result;
|
||
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 将上一次的病灶信息添加到这一次
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<AddTaskLesionAnswerFromLastTaskOutDto> AddTaskLesionAnswerFromLastTask(AddTaskLesionAnswerFromLastTaskInDto inDto)
|
||
{
|
||
|
||
var visitTaskId = inDto.VisitTaskId;
|
||
|
||
var taskinfo = await _visitTaskRepository.Where(x => x.Id == visitTaskId).FirstNotNullAsync();
|
||
|
||
var baseLineVisitId = await _subjectVisitRepository.Where(x => x.SubjectId == taskinfo.SubjectId && x.IsBaseLine).Select(x => x.Id).FirstOrDefaultAsync();
|
||
|
||
// 判断当前任务是否是基线
|
||
if (taskinfo.SourceSubjectVisitId != baseLineVisitId)
|
||
{
|
||
// 判断当前任务是是否有表格问题答案
|
||
if (!(await _readingTableQuestionAnswerRepository.AnyAsync(x => x.VisitTaskId == visitTaskId)))
|
||
{
|
||
var LastVisitTaskId = await _visitTaskRepository.Where(x => x.ReadingCategory == ReadingCategory.Visit &&
|
||
x.TrialReadingCriterionId == taskinfo.TrialReadingCriterionId &&
|
||
x.SubjectId == taskinfo.SubjectId && x.ReadingTaskState == ReadingTaskState.HaveSigned && x.VisitTaskNum < taskinfo.VisitTaskNum && x.TaskState == TaskState.Effect && x.ArmEnum == taskinfo.ArmEnum
|
||
).OrderByDescending(x => x.VisitTaskNum).Select(x => x.Id).FirstOrDefaultAsync();
|
||
|
||
var copyTableAnswers = await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == LastVisitTaskId
|
||
).Select(x => new CopyTableAnswerDto()
|
||
{
|
||
Answer = x.Answer,
|
||
QuestionId = x.QuestionId,
|
||
RowId = x.RowId,
|
||
QuestionMark = x.ReadingTableQuestionTrial.QuestionMark,
|
||
TableQuestionId = x.TableQuestionId,
|
||
RowIndex = x.RowIndex,
|
||
TrialId = x.TrialId
|
||
}).ToListAsync();
|
||
|
||
var tableRowAnswers = await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == LastVisitTaskId).ProjectTo<CopyTableAnswerRowInfo>(_mapper.ConfigurationProvider).ToListAsync();
|
||
|
||
tableRowAnswers.ForEach(x =>
|
||
{
|
||
x.VisitTaskId = visitTaskId;
|
||
x.IsCurrentTaskAdd = false;
|
||
x.Id = NewId.NextGuid();
|
||
x.SeriesId = null;
|
||
x.InstanceId = null;
|
||
x.MeasureData = string.Empty;
|
||
});
|
||
|
||
tableRowAnswers.ForEach(x =>
|
||
{
|
||
x.SplitRowId = tableRowAnswers.Where(y => y.OriginalId == x.SplitRowId).Select(y => y.Id).FirstOrDefault();
|
||
x.MergeRowId = tableRowAnswers.Where(y => y.OriginalId == x.MergeRowId).Select(y => y.Id).FirstOrDefault();
|
||
x.MergeRow = null;
|
||
x.SplitRow = null;
|
||
});
|
||
|
||
List<QuestionMark?> notNeedCopyMarks = new List<QuestionMark?>()
|
||
{
|
||
QuestionMark.State,
|
||
};
|
||
|
||
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,
|
||
RowId = tableRowAnswers.Where(y => y.OriginalId == x.RowId).Select(x => x.Id).FirstOrDefault(),
|
||
TableQuestionId = x.TableQuestionId,
|
||
TrialId = x.TrialId,
|
||
VisitTaskId = visitTaskId,
|
||
}).ToList();
|
||
|
||
|
||
try
|
||
{
|
||
var newLesionQuestion = await _readingQuestionTrialRepository.Where(x => x.LesionType == LesionType.NewLesions && x.ReadingQuestionCriterionTrialId == taskinfo.TrialReadingCriterionId).FirstNotNullAsync();
|
||
var alwaysNewLesionsQuestion = await _readingQuestionTrialRepository.Where(x => x.LesionType == LesionType.AlwaysNewLesions && x.ReadingQuestionCriterionTrialId == taskinfo.TrialReadingCriterionId).FirstNotNullAsync();
|
||
var newLesionTableQuestions = await _readingTableQuestionTrialRepository.Where(x => x.ReadingQuestionId == newLesionQuestion.Id).ToListAsync();
|
||
var alwaysNewLesionsTableQuestions = await _readingTableQuestionTrialRepository.Where(x => x.ReadingQuestionId == alwaysNewLesionsQuestion.Id).ToListAsync();
|
||
|
||
Dictionary<Guid, Guid> alwaysTableQuestionIdDic = new Dictionary<Guid, Guid>();
|
||
|
||
newLesionTableQuestions.ForEach(x =>
|
||
{
|
||
|
||
alwaysTableQuestionIdDic.Add(
|
||
x.Id,
|
||
alwaysNewLesionsTableQuestions.Where(y => y.QuestionName == x.QuestionName).Select(y => y.Id).FirstOrDefault()
|
||
);
|
||
});
|
||
|
||
var maxNewLesionsRowIndex = tableRowAnswers.Where(x => x.QuestionId == alwaysNewLesionsQuestion.Id).OrderByDescending(x => x.RowIndex).Select(x => x.RowIndex).FirstOrDefault();
|
||
maxNewLesionsRowIndex = Math.Floor(maxNewLesionsRowIndex);
|
||
|
||
|
||
foreach (var item in tableRowAnswers.Where(x => x.QuestionId == newLesionQuestion.Id).OrderBy(x=>x.RowIndex))
|
||
{
|
||
|
||
item.QuestionId = alwaysNewLesionsQuestion.Id;
|
||
|
||
|
||
foreach (var tableAnswer in tableAnswers.Where(y => y.RowId == item.Id))
|
||
{
|
||
tableAnswer.QuestionId = alwaysNewLesionsQuestion.Id;
|
||
tableAnswer.TableQuestionId = alwaysTableQuestionIdDic[tableAnswer.TableQuestionId];
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
throw new BusinessValidationFailedException($"PCWG3标准配置异常!");
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
await _visitTaskRepository.UpdatePartialFromQueryAsync(visitTaskId, x => new VisitTask()
|
||
{
|
||
ReadingTaskState = ReadingTaskState.Reading,
|
||
|
||
});
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
await _readingTableAnswerRowInfoRepository.AddRangeAsync(tableRowAnswers);
|
||
await _readingTableQuestionAnswerRepository.AddRangeAsync(tableAnswers);
|
||
await _readingTableQuestionAnswerRepository.SaveChangesAsync();
|
||
|
||
}
|
||
}
|
||
|
||
return new AddTaskLesionAnswerFromLastTaskOutDto()
|
||
{
|
||
|
||
IsBaseLine = taskinfo.SourceSubjectVisitId == baseLineVisitId,
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// 测试计算
|
||
/// </summary>
|
||
/// <param name="visitTaskId"></param>
|
||
/// <param name="type"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task TestCalculate(Guid visitTaskId, QuestionType type)
|
||
{
|
||
ReadingCalculateDto readingData = await _generalCalculateService.GetReadingCalculateDto(visitTaskId);
|
||
await ReadingCalculate(readingData, new List<QuestionType>() { type });
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计算任务
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task CalculateTask(CalculateTaskInDto inDto)
|
||
{
|
||
ReadingCalculateDto readingData = await _generalCalculateService.GetReadingCalculateDto(inDto.VisitTaskId);
|
||
readingData.IsChangeOtherTask = inDto.IsChangeOtherTask;
|
||
await ReadingCalculate(readingData);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 自动计算
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <param name="calculateType"></param>
|
||
/// <returns></returns>
|
||
public async Task ReadingCalculate(ReadingCalculateDto inDto, List<QuestionType> calculateType = null)
|
||
{
|
||
|
||
#region 计算 这里顺序非常重要 后面计算的值要依赖前面计算的结果
|
||
var needAddList = new List<ReadingTaskQuestionAnswer>();
|
||
|
||
|
||
List<ReadingCalculateData> calculateList = new List<ReadingCalculateData>()
|
||
{
|
||
// 基线病灶计数
|
||
new ReadingCalculateData (){QuestionType=QuestionType.BaseLineLesionsCount,GetIntFun=GetBaseLineLesionsCount},
|
||
|
||
// 新病灶计数
|
||
new ReadingCalculateData (){QuestionType=QuestionType.NewLesionsCount,GetIntFun=GetNewLesionsCount},
|
||
|
||
// 既往新病灶
|
||
new ReadingCalculateData (){QuestionType=QuestionType.AlwaysNewLesionsCount,GetIntFun=GetAlwaysNewLesionsCount},
|
||
|
||
// 自治疗后第二个访视点以来持续的新骨病变数量
|
||
new ReadingCalculateData (){QuestionType=QuestionType.NewBoneLesionsCount,GetIntFun=GetNewBoneLesionCount},
|
||
|
||
|
||
|
||
};
|
||
|
||
if (calculateType != null)
|
||
{
|
||
calculateList = calculateList.Where(x => calculateType.Contains(x.QuestionType)).ToList();
|
||
}
|
||
|
||
|
||
|
||
foreach (var calculate in calculateList)
|
||
{
|
||
var item = inDto.QuestionInfo.FirstOrDefault(x => x.QuestionType == calculate.QuestionType);
|
||
|
||
if (item != null)
|
||
{
|
||
//计算答案
|
||
if (inDto.IsOnlyChangeAllTask == false)
|
||
{
|
||
|
||
#region 计算答案
|
||
|
||
var value = await calculate.GetIntFun(inDto);
|
||
|
||
switch (calculate.QuestionType)
|
||
{
|
||
case QuestionType.NewLesionsCount:
|
||
if (inDto.VisitTaskNum >= 1)
|
||
{
|
||
item.Answer = value.ToString();
|
||
}
|
||
else
|
||
{
|
||
item.Answer = nameof(YesOrNoOrNa.NA);
|
||
}
|
||
break;
|
||
case QuestionType.AlwaysNewLesionsCount:
|
||
if (inDto.VisitTaskNum >= 2)
|
||
{
|
||
item.Answer = value.ToString();
|
||
}
|
||
else
|
||
{
|
||
item.Answer = nameof(YesOrNoOrNa.NA);
|
||
}
|
||
break;
|
||
case QuestionType.NewBoneLesionsCount:
|
||
if (inDto.VisitTaskNum >= 3)
|
||
{
|
||
item.Answer = value.ToString();
|
||
}
|
||
else
|
||
{
|
||
item.Answer = nameof(YesOrNoOrNa.NA);
|
||
}
|
||
break;
|
||
default:
|
||
item.Answer = value.ToString();
|
||
break;
|
||
}
|
||
|
||
#endregion
|
||
needAddList.Add(new ReadingTaskQuestionAnswer()
|
||
{
|
||
Answer = item.Answer,
|
||
ReadingQuestionTrialId = item.QuestionId,
|
||
});
|
||
}
|
||
|
||
// 修改全局
|
||
if (inDto.IsChangeOtherTask && calculate.ChangeAllTaskFun != null)
|
||
{
|
||
await calculate.ChangeAllTaskFun(new ChangeAllTaskDto()
|
||
{
|
||
calculateDto = inDto,
|
||
QuestionId = item.QuestionId,
|
||
});
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|
||
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();
|
||
#endregion
|
||
|
||
|
||
}
|
||
|
||
|
||
#region 基线病灶计数
|
||
/// <summary>
|
||
/// 基线病灶计数
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<int> GetBaseLineLesionsCount(ReadingCalculateDto inDto)
|
||
{
|
||
return inDto.QuestionInfo.Where(x => x.LesionType == LesionType.BaselineLesions).SelectMany(x => x.TableRowInfoList).Count();
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 新病灶计数
|
||
/// <summary>
|
||
/// 获取新病灶计数
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<int> GetNewLesionsCount(ReadingCalculateDto inDto)
|
||
{
|
||
return inDto.QuestionInfo.Where(x => x.LesionType == LesionType.NewLesions).SelectMany(x => x.TableRowInfoList)
|
||
.Where(x=>x.TableQuestionList.Any(y=>y.QuestionMark==QuestionMark.State&&y.Answer== EvaluationOfState.Exists.GetEnumInt()))
|
||
.Count();
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
#region 既往新病灶计数
|
||
/// <summary>
|
||
/// 既往新病灶计数
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<int> GetAlwaysNewLesionsCount(ReadingCalculateDto inDto)
|
||
{
|
||
return inDto.QuestionInfo.Where(x => x.LesionType == LesionType.AlwaysNewLesions).SelectMany(x => x.TableRowInfoList)
|
||
.Where(x => x.TableQuestionList.Any(y => y.QuestionMark == QuestionMark.State && y.Answer == EvaluationOfState.Exists.GetEnumInt()))
|
||
.Count();
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
#region 既往新病灶计数
|
||
/// <summary>
|
||
/// 自治疗后第二个访视点以来持续的新骨病变数量
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<int> GetNewBoneLesionCount(ReadingCalculateDto inDto)
|
||
{
|
||
if (inDto.VisitTaskNum < 3)
|
||
{
|
||
return 0;
|
||
}
|
||
var result= inDto.QuestionInfo.Where(x => x.LesionType == LesionType.AlwaysNewLesions).SelectMany(x => x.TableRowInfoList)
|
||
.Where(x =>x.FristAddTaskNum>=2&& x.TableQuestionList.Any(y => y.QuestionMark == QuestionMark.State && y.Answer == EvaluationOfState.Exists.GetEnumInt()))
|
||
.Count();
|
||
return result;
|
||
}
|
||
|
||
#endregion
|
||
|
||
public async Task<object> GetReportVerify(GetReportVerifyInDto inDto)
|
||
{
|
||
return new() {
|
||
|
||
};
|
||
}
|
||
|
||
public async Task VerifyVisitTaskQuestions(VerifyVisitTaskQuestionsInDto inDto)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|