720 lines
25 KiB
C#
720 lines
25 KiB
C#
//--------------------------------------------------------------------
|
||
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||
// 生成时间 2022-08-22 09:33:24
|
||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||
//--------------------------------------------------------------------
|
||
|
||
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.Domain.Share;
|
||
using IRaCIS.Core.Infra.EFCore.Common;
|
||
using Microsoft.Extensions.Caching.Memory;
|
||
|
||
namespace IRaCIS.Core.Application.Service
|
||
{
|
||
/// <summary>
|
||
/// 阅片计算
|
||
/// </summary>
|
||
|
||
[ApiExplorerSettings(GroupName = "Reading")]
|
||
public class ReadingCalculateService : BaseService, IReadingCalculateService
|
||
{
|
||
private readonly IRepository<ReadingTableQuestionAnswer> _readingTableQuestionAnswerRepository;
|
||
private readonly IRepository<VisitTask> _visitTaskRepository;
|
||
private readonly IRepository<ReadingQuestionCriterionTrial> _readingQuestionCriterionTrialRepository;
|
||
private readonly IRepository<ReadingTableQuestionTrial> _readingTableQuestionTrialRepository;
|
||
private readonly IRepository<ReadingQuestionTrial> _readingQuestionTrialRepository;
|
||
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
|
||
private readonly IRepository<TumorAssessment> _tumorAssessmentRepository;
|
||
private readonly IRepository<ReadingTaskQuestionAnswer> _readingTaskQuestionAnswerRepository;
|
||
|
||
public ReadingCalculateService(
|
||
IRepository<ReadingTableQuestionAnswer> readingTableQuestionAnswerRepository,
|
||
IRepository<VisitTask> visitTaskRepository,
|
||
IRepository<ReadingQuestionCriterionTrial> readingQuestionCriterionTrialRepository,
|
||
IRepository<ReadingTableQuestionTrial> readingTableQuestionTrialRepository,
|
||
IRepository<ReadingQuestionTrial> readingQuestionTrialRepository,
|
||
IRepository<SubjectVisit> subjectVisitRepository,
|
||
IRepository<TumorAssessment> tumorAssessmentRepository,
|
||
IRepository<ReadingTaskQuestionAnswer> 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;
|
||
}
|
||
|
||
#region 临时对象 单个请求的生命周期 避免重复查询数据库
|
||
private List<VisitTaskAnswerInfo> visitTaskAnswerList;
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 计算任务
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
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<QuestionInfo> 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,
|
||
IsChangeOtherTask=inDto.IsChangeOtherTask,
|
||
TrialId=visitTask.TrialId,
|
||
DoctorUserId=visitTask.DoctorUserId,
|
||
};
|
||
await ReadingCalculate(readingData);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 自动计算
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
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 needFirstCalculateTypes = new List<QuestionType?>()
|
||
{
|
||
QuestionType.SOD,
|
||
};
|
||
|
||
var needFirstAddList = new List<ReadingTaskQuestionAnswer>();
|
||
|
||
foreach (var item in inDto.QuestionInfo.Where(x => needFirstCalculateTypes.Contains(x.QuestionType)))
|
||
{
|
||
switch (item.QuestionType)
|
||
{
|
||
// 靶病灶径线之和(SOD)
|
||
case QuestionType.SOD:
|
||
needFirstAddList.Add(new ReadingTaskQuestionAnswer()
|
||
{
|
||
Answer = (await GetSODData(inDto)).ToString(),
|
||
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<ReadingTaskQuestionAnswer>();
|
||
// 循环找要计算的值进行计算
|
||
foreach (var item in inDto.QuestionInfo.Where(x => x.QuestionType != null))
|
||
{
|
||
switch (item.QuestionType)
|
||
{
|
||
|
||
// 非淋巴结靶病灶长径之和
|
||
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:
|
||
|
||
if (!inDto.IsChangeOtherTask)
|
||
{
|
||
needAddList.Add(new ReadingTaskQuestionAnswer()
|
||
{
|
||
Answer = (await GetLowestIncrease(inDto)).ToString(),
|
||
ReadingQuestionTrialId = item.QuestionId,
|
||
});
|
||
}
|
||
else
|
||
{
|
||
await ChangeAllLowestIncrease(inDto, item.QuestionId);
|
||
}
|
||
|
||
|
||
break;
|
||
// 与整个访视期间最低点相比增加的百分比 其他任务需要改
|
||
case QuestionType.LowPercent:
|
||
|
||
if (!inDto.IsChangeOtherTask)
|
||
{
|
||
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();
|
||
if (!inDto.IsChangeOtherTask)
|
||
{
|
||
needAddList.Add(new ReadingTaskQuestionAnswer()
|
||
{
|
||
Answer = answer,
|
||
ReadingQuestionTrialId = item.QuestionId,
|
||
});
|
||
}
|
||
else
|
||
{
|
||
if (inDto.IsChangeOtherTask)
|
||
{
|
||
await this.ChangeAllVisitTaskAnswer(visitTaskIds, item.QuestionId, answer);
|
||
}
|
||
}
|
||
|
||
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();
|
||
}
|
||
|
||
|
||
#region 获取SOD
|
||
|
||
/// <summary>
|
||
/// 获取SOD
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 靶病灶径线之和(SOD)
|
||
/// 非淋巴结的长径 和淋巴结的短径
|
||
/// </remarks>
|
||
/// <returns></returns>
|
||
public async Task<decimal> GetSODData(ReadingCalculateDto inDto)
|
||
{
|
||
var tableQuestion = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).SelectMany(x => x.TableRowInfoList).ToList();
|
||
|
||
decimal result = 0;
|
||
|
||
foreach (var item in tableQuestion)
|
||
{
|
||
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()).IsNullOrEmptyReturn0());
|
||
}
|
||
|
||
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().IsNullOrEmptyReturn0());
|
||
}
|
||
}
|
||
|
||
|
||
return result;
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 非淋巴结靶病灶长径之和
|
||
/// <summary>
|
||
/// 非淋巴结靶病灶长径之和
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<decimal> GetSumOfDiameter(ReadingCalculateDto inDto)
|
||
{
|
||
var tableQuestion = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).SelectMany(x => x.TableRowInfoList).ToList();
|
||
|
||
decimal result = 0;
|
||
|
||
foreach (var item in tableQuestion)
|
||
{
|
||
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().IsNullOrEmptyReturn0());
|
||
}
|
||
}
|
||
|
||
|
||
return result;
|
||
}
|
||
#endregion
|
||
|
||
#region 与基线SOD相比变化量(mm)
|
||
/// <summary>
|
||
/// 与基线SOD相比变化量(mm)
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<decimal> GetSODChange(ReadingCalculateDto inDto)
|
||
{
|
||
return await GetSODData(inDto) - await GetBaseLineSOD(inDto);
|
||
}
|
||
#endregion
|
||
|
||
#region 与整个访视期间最低点相比增加的百分比
|
||
/// <summary>
|
||
/// 与整个访视期间最低点相比增加的百分比
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<decimal> GetSODPercent(ReadingCalculateDto inDto)
|
||
{
|
||
var thisSOD = await GetSODData(inDto);
|
||
var baseLineSOD = await GetBaseLineSOD(inDto);
|
||
|
||
if (baseLineSOD == 0)
|
||
{
|
||
return 100;
|
||
}
|
||
else
|
||
{
|
||
return decimal.Round(thisSOD * 100 / baseLineSOD, 2);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 与整个访视期间最低点相比增加的值(mm)
|
||
/// <summary>
|
||
/// 与整个访视期间最低点相比增加的值(mm)
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <remarks>
|
||
/// 要更新之前的
|
||
/// </remarks>
|
||
/// <returns></returns>
|
||
public async Task<decimal> GetLowestIncrease(ReadingCalculateDto inDto)
|
||
{
|
||
var decimalAnswerList = await GetVisitTaskAnswerList(inDto);
|
||
var minSOD = decimalAnswerList.OrderBy(x => x.SOD).Select(x => x.SOD).FirstOrDefault();
|
||
return await GetSODData(inDto) - minSOD;
|
||
}
|
||
#endregion
|
||
|
||
#region 与整个访视期间最低点相比增加的百分比
|
||
/// <summary>
|
||
/// 与整个访视期间最低点相比增加的百分比
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <remarks>
|
||
/// 要更新之前的
|
||
/// </remarks>
|
||
/// <returns></returns>
|
||
public async Task<decimal> GetLowPercent(ReadingCalculateDto inDto)
|
||
{
|
||
var thisSOD = await GetSODData(inDto);
|
||
var decimalAnswerList = await GetVisitTaskAnswerList(inDto);
|
||
var minSOD = decimalAnswerList.OrderBy(x => x.SOD).Select(x => x.SOD).FirstOrDefault();
|
||
|
||
if (minSOD == 0)
|
||
{
|
||
return 100;
|
||
}
|
||
else
|
||
{
|
||
return decimal.Round((thisSOD- minSOD) * 100 / minSOD, 2);
|
||
}
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 整个访视期间最低点访视名称
|
||
/// <summary>
|
||
/// 整个访视期间最低点访视名称
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <remarks>
|
||
/// 要更新之前的
|
||
/// </remarks>
|
||
/// <returns></returns>
|
||
public async Task<string> GetLowVisit(ReadingCalculateDto inDto)
|
||
{
|
||
var decimalAnswerList = await GetVisitTaskAnswerList(inDto);
|
||
return decimalAnswerList.OrderBy(x => x.SOD).Select(x => x.VisitName).FirstOrDefault() ?? string.Empty;
|
||
}
|
||
#endregion
|
||
|
||
#region 是否存在非淋巴结靶病灶
|
||
/// <summary>
|
||
/// 是否存在非淋巴结靶病灶
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetIsLymphTarget(ReadingCalculateDto inDto)
|
||
{
|
||
var tableQuestion = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).SelectMany(x => x.TableRowInfoList).ToList();
|
||
|
||
foreach (var item in tableQuestion)
|
||
{
|
||
if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && (x.Answer == "是" || x.Answer.ToLower() == "true".ToLower())))
|
||
{
|
||
return "是";
|
||
}
|
||
}
|
||
|
||
return "否";
|
||
}
|
||
#endregion
|
||
|
||
#region 是否存在淋巴结靶病灶且该病灶比上一访视短径增加5MM以上
|
||
/// <summary>
|
||
/// 是否存在淋巴结靶病灶且该病灶比上一访视短径增加5MM以上
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> 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 == "是" || 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();
|
||
|
||
var isExists = false;
|
||
foreach (var item in rowIndexs)
|
||
{
|
||
var lastValue = decimal.Parse(lastQuestionAsnwer.Where(x => x.RowIndex == item && x.ReadingTableQuestionTrial.QuestionMark == QuestionMark.ShortAxis).Select(x => x.Answer).FirstOrDefault().IsNullOrEmptyReturn0());
|
||
|
||
var thisRowData = thisQuestionAsnwer.Where(x => x.RowIndex == item).SelectMany(x => x.TableQuestionList).ToList();
|
||
var thisValue = decimal.Parse(thisRowData.Where(x => x.QuestionMark == QuestionMark.ShortAxis).Select(x => x.Answer).FirstOrDefault().IsNullOrEmptyReturn0());
|
||
|
||
if (thisValue - lastValue > 5)
|
||
{
|
||
isExists = true;
|
||
}
|
||
}
|
||
|
||
return isExists?"是":"否";
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 被评估为NE的单个靶病灶
|
||
/// <summary>
|
||
/// 被评估为NE的单个靶病灶
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetNETarget(ReadingCalculateDto inDto)
|
||
{
|
||
var result = inDto.QuestionInfo.Any(x => x.QuestionType == QuestionType.TargetLesion && x.Answer == "NE");
|
||
|
||
return result ? "有" : "无";
|
||
}
|
||
#endregion
|
||
|
||
#region 整体肿瘤评估
|
||
|
||
/// <summary>
|
||
/// 整体肿瘤评估
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetTumor(ReadingCalculateDto inDto)
|
||
{
|
||
var targetLesion = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.TargetLesion).Select(x => x.Answer).FirstOrDefault();
|
||
var noTargetLesion = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.NoTargetLesion).Select(x => x.Answer).FirstOrDefault();
|
||
var newLesions = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.NewLesions).Select(x => x.Answer).FirstOrDefault();
|
||
var result = await _tumorAssessmentRepository.Where(x => x.TargetLesion == targetLesion && x.NonTargetLesions == noTargetLesion && x.NewLesion == newLesions).Select(x => x.OverallEfficacy).FirstOrDefaultAsync();
|
||
|
||
return result ?? string.Empty;
|
||
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region 修改其他标准
|
||
|
||
#region 修改与整个访视期间最低点相比增加的值(mm)
|
||
|
||
/// <summary>
|
||
/// 修改与整个访视期间最低点相比增加的值(mm)
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <param name="questionId"></param>
|
||
/// <returns></returns>
|
||
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 修改整个访视期间最低点相比增加的百分比
|
||
|
||
/// <summary>
|
||
/// 修改整个访视期间最低点相比增加的百分比
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <param name="questionId"></param>
|
||
/// <returns></returns>
|
||
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 修改所有访视任务的答案
|
||
/// <summary>
|
||
/// 修改所有访视任务的答案
|
||
/// </summary>
|
||
/// <param name="visitTaskGuids"></param>
|
||
/// <param name="questionId"></param>
|
||
/// <param name="answer"></param>
|
||
/// <returns></returns>
|
||
private async Task ChangeAllVisitTaskAnswer(List<Guid> visitTaskGuids, Guid questionId, string answer)
|
||
{
|
||
await _readingTaskQuestionAnswerRepository.BatchUpdateNoTrackingAsync(x => visitTaskGuids.Contains(x.VisitTaskId) && x.ReadingQuestionTrialId == questionId, x => new ReadingTaskQuestionAnswer()
|
||
{
|
||
Answer = answer
|
||
});
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region 获取基线SOD
|
||
/// <summary>
|
||
/// 获取基线SOD
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
private async Task<decimal> GetBaseLineSOD(ReadingCalculateDto inDto)
|
||
{
|
||
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.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
|
||
|
||
#region 获取访视任务信息
|
||
/// <summary>
|
||
/// 获取访视任务信息
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<List<VisitTaskAnswerInfo>> 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();
|
||
|
||
}
|
||
|
||
return visitTaskAnswerList;
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 获取上一个访视任务Id
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private async Task<Guid> GetLastVisitTaskId(ReadingCalculateDto inDto)
|
||
{
|
||
// 拿到这一个访视
|
||
var thisNum = await _subjectVisitRepository.Where(x => x.Id == inDto.SubjectVisitId).Select(x => x.VisitNum).FirstOrDefaultAsync();
|
||
|
||
// 先找到上一个访视
|
||
var lastVisitId = await _subjectVisitRepository.Where(x => x.SubjectId == inDto.SubjectId && x.VisitNum < thisNum).OrderByDescending(x => x.VisitNum).Select(x => x.Id).FirstOrDefaultAsync();
|
||
|
||
// 找到访视任务Id
|
||
|
||
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;
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|