2245 lines
103 KiB
C#
2245 lines
103 KiB
C#
|
||
using IRaCIS.Application.Contracts;
|
||
using IRaCIS.Core.Application.Contracts;
|
||
using IRaCIS.Core.Application.Helper;
|
||
using IRaCIS.Core.Application.Service.Reading.Dto;
|
||
using IRaCIS.Core.Application.ViewModel;
|
||
using IRaCIS.Core.Domain.Models;
|
||
using IRaCIS.Core.Domain.Share;
|
||
using IRaCIS.Core.Infra.EFCore.Common;
|
||
using IRaCIS.Core.Infrastructure;
|
||
using MassTransit;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using Microsoft.Extensions.Options;
|
||
using MiniSoftware;
|
||
using System.Linq;
|
||
using System.Runtime.InteropServices;
|
||
|
||
namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||
{
|
||
|
||
[ApiExplorerSettings(GroupName = "Reading")]
|
||
public class RECIST1Point1CalculateService(IRepository<ReadingTableQuestionAnswer> _readingTableQuestionAnswerRepository,
|
||
IRepository<VisitTask> _visitTaskRepository,
|
||
IRepository<DicomInstance> _dicomInstanceRepository,
|
||
IRepository<ReadingQuestionCriterionTrial> _readingQuestionCriterionTrialRepository,
|
||
IRepository<ReadingTableQuestionTrial> _readingTableQuestionTrialRepository,
|
||
IRepository<ReadingTableAnswerRowInfo> _readingTableAnswerRowInfoRepository,
|
||
IRepository<ReadingQuestionTrial> _readingQuestionTrialRepository,
|
||
IRepository<ReadingGlobalTaskInfo> _readingGlobalTaskInfoRepository,
|
||
IRepository<OrganInfo> _organInfoRepository,
|
||
IRepository<SubjectVisit> _subjectVisitRepository,
|
||
IRepository<TumorAssessment_RECIST1Point1> _tumorAssessmentRepository,
|
||
IGeneralCalculateService _generalCalculateService,
|
||
IRepository<Subject> _subjectRepository,
|
||
IRepository<User> _userRepository,
|
||
IServiceProvider ServiceProvider,
|
||
IOptionsMonitor<SystemHospitalOption> _hospital,
|
||
IRepository<Dictionary> _dictionaryRepository,
|
||
IRepository<DicomStudy> _dicomStudyRepository,
|
||
IRepository<SubjectPatient> _subjectPatientRepository,
|
||
IRepository<ReadingTaskQuestionAnswer> _readingTaskQuestionAnswerRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, ICriterionCalculateService
|
||
{
|
||
|
||
/// <summary>
|
||
/// 获取阅片的计算数据
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<object> GetReadingCalculationData(GetReadingCalculationDataInDto inDto)
|
||
{
|
||
return new
|
||
{
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取肿瘤评估报告
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<Stream> DownLoadTumorEvaluationStream(DownLoadReadReportInDto inDto)
|
||
{
|
||
var downFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"wwwroot/ReadReoprtTemplate/downLoad/{inDto.DownLoadGuid}");
|
||
Directory.CreateDirectory(downFile);
|
||
|
||
var taskinfo = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId && x.ReadingCategory == ReadingCategory.Visit)
|
||
.Include(x => x.TrialReadingCriterion).FirstNotNullAsync();
|
||
var visitInfo = await _subjectVisitRepository.Where(x => x.Id == taskinfo.SourceSubjectVisitId).Include(x => x.StudyList).FirstNotNullAsync();
|
||
var subjectInfo = await _subjectRepository.Where(x => x.Id == taskinfo.SubjectId).Include(x => x.Trial).Include(x => x.SubjectPatientList).FirstNotNullAsync();
|
||
var subjectPatientList = await _subjectPatientRepository.Where(x => x.SubjectId == subjectInfo.Id).Include(x => x.Patient).ToListAsync();
|
||
var trialQuestion = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == taskinfo.TrialReadingCriterionId).ToListAsync();
|
||
var tableQuestion = await _readingTableQuestionTrialRepository.Where(x => x.ReadingQuestionTrial.ReadingQuestionCriterionTrialId == taskinfo.TrialReadingCriterionId).ToListAsync();
|
||
var dicotionCode = trialQuestion.Where(x => x.DictionaryCode != string.Empty).Select(x => x.DictionaryCode).Distinct().ToList();
|
||
dicotionCode.AddRange(tableQuestion.Where(x => x.DictionaryCode != string.Empty).Select(x => x.DictionaryCode).Distinct());
|
||
var dictionList = await _dictionaryRepository.Where(x => dicotionCode.Contains(x.Code)).Include(x => x.ChildList).ToListAsync();
|
||
var unitDictionary = await _dictionaryRepository.Where(x => x.Code == "ValueUnit").Include(x => x.ChildList).ToListAsync();
|
||
|
||
var relatedVisitTask = await ServiceProvider.GetService<IReadingImageTaskService>().GetRelatedVisitTask(new GetRelatedVisitTaskInDto()
|
||
{
|
||
VisitTaskId = inDto.VisitTaskId
|
||
});
|
||
|
||
var relatedTaskIds = relatedVisitTask.Item1.Select(x => x.VisitTaskId).ToList();
|
||
|
||
var answerList = await _readingTaskQuestionAnswerRepository.Where(x => relatedTaskIds.Contains(x.VisitTaskId)).Include(x => x.ReadingQuestionTrial).ToListAsync();
|
||
|
||
var rowinfoList = await _readingTableAnswerRowInfoRepository.Where(x => relatedTaskIds.Contains(x.VisitTaskId)).Include(x => x.VisitTask).Include(x => x.ReadingQuestionTrial).ToListAsync();
|
||
|
||
var instanceIdList = rowinfoList.Select(x => x.InstanceId).ToList();
|
||
var instanceList = await _dicomInstanceRepository.Where(x => instanceIdList.Contains(x.Id)).Include(x => x.DicomSerie.DicomStudy).ToListAsync();
|
||
|
||
var tableAnswerList = await _readingTableQuestionAnswerRepository.Where(x => relatedTaskIds.Contains(x.VisitTaskId)).Include(x => x.ReadingQuestionTrial).Include(x => x.ReadingTableQuestionTrial).ToListAsync();
|
||
var taskinfoList = await _visitTaskRepository.Where(x => relatedTaskIds.Contains(x.Id))
|
||
.Include(x => x.SourceSubjectVisit).Include(x => x.SourceSubjectVisit.StudyList)
|
||
.Include(x => x.DoctorUser).ToListAsync();
|
||
|
||
List<ExportVisitData> exportVisitDatas = taskinfoList
|
||
.Select(x => new ExportVisitData()
|
||
{
|
||
VisitName = x.SourceSubjectVisit.VisitName,
|
||
VisitNum = x.VisitTaskNum,
|
||
CheckDate = string.Join(",", x.SourceSubjectVisit.StudyList.Where(x => x.StudyTime != null).Select(x => x.StudyTime.Value.ToString("yyyy-MM-dd"))),
|
||
CheckInfoList = x.SourceSubjectVisit.StudyList.Select(x => new DicomStudyInfo()
|
||
{
|
||
BodyPartExamined = x.BodyPartExamined,
|
||
Modalities = x.Modalities
|
||
}).ToList(),
|
||
HaveNewLesion = _generalCalculateService.GetTaskanswer(answerList, dictionList, unitDictionary, x.Id, QuestionType.NewLesions),
|
||
TargetResult = _generalCalculateService.GetTaskanswer(answerList, dictionList, unitDictionary, x.Id, QuestionType.TargetLesion),
|
||
NoTargetResult = _generalCalculateService.GetTaskanswer(answerList, dictionList, unitDictionary, x.Id, QuestionType.NoTargetLesion),
|
||
OverallResult = _generalCalculateService.GetTaskanswer(answerList, dictionList, unitDictionary, x.Id, QuestionType.Tumor),
|
||
DoctorName = x.DoctorUser.LastName + x.DoctorUser.FirstName,
|
||
SignTime = x.SignTime?.ToString("yyyy-MM-dd HH:mm:ss"),
|
||
VisitTargetInfoList = getLesionInfo(LesionType.TargetLesion),
|
||
VisitNoTargetInfoList = getLesionInfo(LesionType.NonTargetLesions),
|
||
}).OrderBy(x=>x.VisitNum).ToList();
|
||
|
||
|
||
#region 两个函数
|
||
List<VisitLesionInfo> getLesionInfo(LesionType lesionType)
|
||
{
|
||
var targetFocus = rowinfoList.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.ReadingQuestionTrial.LesionType == lesionType).OrderBy(x => x.RowIndex).ToList();
|
||
|
||
|
||
var targetInfo = new List<VisitLesionInfo>();
|
||
|
||
int num = 1;
|
||
foreach (var item in targetFocus)
|
||
{
|
||
VisitLesionInfo target = new VisitLesionInfo
|
||
{
|
||
RowMark = rowinfoList.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.RowIndex == item.RowIndex && x.ReadingQuestionTrial.LesionType == lesionType).Select(x => x.RowMark).FirstIsNullReturnEmpty(),
|
||
Organ = _generalCalculateService.GetTaskTableAnswer(tableAnswerList, dictionList, unitDictionary, inDto.VisitTaskId, lesionType, QuestionMark.Organ, item.RowIndex),
|
||
Part = _generalCalculateService.GetTaskTableAnswer(tableAnswerList, dictionList, unitDictionary, inDto.VisitTaskId, lesionType, QuestionMark.Part, item.RowIndex),
|
||
Number = num,
|
||
StudyCode = instanceList.Where(x => x.Id == item.InstanceId).Select(x => x.DicomSerie.DicomStudy.Code).FirstOrDefault(),
|
||
RowId = item.Id,
|
||
SeriesNumber = instanceList.Where(x => x.Id == item.InstanceId).Select(x => x.DicomSerie.SeriesNumber).FirstOrDefault(),
|
||
InstanceNumber = instanceList.Where(x => x.Id == item.InstanceId).Select(x => x.InstanceNumber).FirstOrDefault(),
|
||
VisitLength = getStateInfo(item.VisitTaskId, item.RowIndex, lesionType),
|
||
};
|
||
targetInfo.Add(target);
|
||
num++;
|
||
}
|
||
if (lesionType == LesionType.TargetLesion)
|
||
{
|
||
for (int i = num; i <= 5; i++)
|
||
{
|
||
VisitLesionInfo target = new VisitLesionInfo
|
||
{
|
||
Number = i,
|
||
};
|
||
targetInfo.Add(target);
|
||
i++;
|
||
}
|
||
|
||
}
|
||
|
||
return targetInfo;
|
||
}
|
||
|
||
decimal getStateInfo(Guid visitTaskid, decimal item, LesionType lesionType)
|
||
{
|
||
// 非淋巴结取长径 淋巴结取长短径
|
||
var state = _generalCalculateService.GetTaskTableAnswer(tableAnswerList, dictionList, unitDictionary, visitTaskid, lesionType, QuestionMark.State, item);
|
||
var majorAxis = _generalCalculateService.GetTaskTableAnswer(tableAnswerList, dictionList, unitDictionary, visitTaskid, lesionType, QuestionMark.MajorAxis, item);
|
||
|
||
var isLymph = _generalCalculateService.GetTaskTableAnswer(tableAnswerList, dictionList, unitDictionary, visitTaskid, lesionType, QuestionMark.IsLymph, item);
|
||
var shortAxis = _generalCalculateService.GetTaskTableAnswer(tableAnswerList, dictionList, unitDictionary, visitTaskid, lesionType, QuestionMark.ShortAxis, item);
|
||
|
||
var result = string.Empty;
|
||
|
||
if (!majorAxis.IsNullOrEmpty())
|
||
{
|
||
result = majorAxis;
|
||
|
||
}
|
||
|
||
if (isLymph.EqEnum(YesOrNoOrNa.Yes) && !shortAxis.IsNullOrEmpty())
|
||
{
|
||
result = shortAxis;
|
||
}
|
||
|
||
return result.IsNullOrEmptyReturn0();
|
||
|
||
}
|
||
#endregion
|
||
|
||
var researchProgramNo = subjectInfo.Trial.ResearchProgramNo;
|
||
var subjectName = subjectInfo.ShortName;
|
||
var subjectCode = subjectPatientList.Select(x => x.Patient).OrderByDescending(x => x.CreateTime).Select(x => x.PatientIdStr).FirstIsNullReturnEmpty();
|
||
|
||
|
||
|
||
List<ExportTumorEvaluationInfo> resultdata = new List<ExportTumorEvaluationInfo>();
|
||
|
||
for (int i = 0; i < (int)Math.Ceiling((double)exportVisitDatas.Count() / 3); i++)
|
||
{
|
||
ExportTumorEvaluationInfo export = new ExportTumorEvaluationInfo
|
||
{
|
||
ResearchProgramNo = researchProgramNo,
|
||
SubjectName = subjectName,
|
||
SubjectCode = subjectCode,
|
||
VisitList= exportVisitDatas.Skip(i*3).Take(3).ToList(),
|
||
};
|
||
resultdata.Add(export);
|
||
}
|
||
|
||
var value = new
|
||
{
|
||
VisitList = resultdata
|
||
};
|
||
|
||
|
||
var templatePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"wwwroot/ReadReoprtTemplate/TumorEvaluation_RECIST1.1_CN_V1.docx");
|
||
var outputFilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"wwwroot/ReadReoprtTemplate/downLoad/{inDto.DownLoadGuid}.docx");
|
||
|
||
|
||
MiniWord.SaveAsByTemplate(outputFilePath, templatePath, value);
|
||
|
||
|
||
//// 获取文件夹中的所有文件路径
|
||
Directory.Delete(downFile, true);
|
||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||
{
|
||
Stream stream = _generalCalculateService.ReadAndReturnStream(outputFilePath);
|
||
return stream;
|
||
}
|
||
else
|
||
{
|
||
|
||
var pdfurl = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"wwwroot/ReadReoprtTemplate/downLoad");
|
||
FileConvertHelper.ConvertWordToPdf(outputFilePath, pdfurl);
|
||
Stream stream = _generalCalculateService.ReadAndReturnStream(pdfurl + $"/{inDto.DownLoadGuid}.pdf");
|
||
return stream;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 下载阅片报告
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<Stream> DownLoadReadReportStream(DownLoadReadReportInDto inDto)
|
||
{
|
||
var downFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"wwwroot/ReadReoprtTemplate/downLoad/{inDto.DownLoadGuid}");
|
||
Directory.CreateDirectory(downFile);
|
||
var taskinfo = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId && x.ReadingCategory == ReadingCategory.Visit)
|
||
.Include(x => x.TrialReadingCriterion).FirstNotNullAsync();
|
||
var visitInfo = await _subjectVisitRepository.Where(x => x.Id == taskinfo.SourceSubjectVisitId).Include(x => x.StudyList).FirstNotNullAsync();
|
||
var subjectInfo = await _subjectRepository.Where(x => x.Id == taskinfo.SubjectId).Include(x => x.SubjectPatientList).FirstNotNullAsync();
|
||
var doctor = await _userRepository.Where(x => x.Id == taskinfo.DoctorUserId).FirstOrDefaultAsync();
|
||
|
||
var trialQuestion = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == taskinfo.TrialReadingCriterionId).ToListAsync();
|
||
var tableQuestion = await _readingTableQuestionTrialRepository.Where(x => x.ReadingQuestionTrial.ReadingQuestionCriterionTrialId == taskinfo.TrialReadingCriterionId).ToListAsync();
|
||
var dicotionCode = trialQuestion.Where(x => x.DictionaryCode != string.Empty).Select(x => x.DictionaryCode).Distinct().ToList();
|
||
dicotionCode.AddRange(tableQuestion.Where(x => x.DictionaryCode != string.Empty).Select(x => x.DictionaryCode).Distinct());
|
||
var dictionList = await _dictionaryRepository.Where(x => dicotionCode.Contains(x.Code)).Include(x => x.ChildList).ToListAsync();
|
||
List<Guid> taskIds = new List<Guid>() { };
|
||
var relatedVisitTask = await ServiceProvider.GetService<IReadingImageTaskService>().GetRelatedVisitTask(new GetRelatedVisitTaskInDto()
|
||
{
|
||
VisitTaskId = inDto.VisitTaskId
|
||
});
|
||
|
||
var relatedCount = relatedVisitTask.Item1.Count();
|
||
|
||
if (relatedCount <= 3)
|
||
{
|
||
taskIds = relatedVisitTask.Item1.Select(x => x.VisitTaskId).ToList();
|
||
}
|
||
else
|
||
{
|
||
var count = relatedVisitTask.Item1.Count();
|
||
taskIds.Add(relatedVisitTask.Item1[0].VisitTaskId);
|
||
taskIds.Add(relatedVisitTask.Item1[count - 2].VisitTaskId);
|
||
taskIds.Add(relatedVisitTask.Item1[count - 1].VisitTaskId);
|
||
|
||
}
|
||
relatedVisitTask.Item1 = relatedVisitTask.Item1.Where(x => taskIds.Contains(x.VisitTaskId)).ToList();
|
||
// 所有访视问题的答案
|
||
var answerList = await _readingTaskQuestionAnswerRepository.Where(x => taskIds.Contains(x.VisitTaskId)).Include(x => x.ReadingQuestionTrial).ToListAsync();
|
||
|
||
// 单位字典
|
||
var unitDictionary = await _dictionaryRepository.Where(x => x.Code == "ValueUnit").Include(x => x.ChildList).ToListAsync();
|
||
var imageProblem = _generalCalculateService.GetTaskanswer(answerList, dictionList, unitDictionary, inDto.VisitTaskId, QuestionType.ImageQualityAssessment);
|
||
var rowinfoList = await _readingTableAnswerRowInfoRepository.Where(x => taskIds.Contains(x.VisitTaskId)).Include(x => x.VisitTask).Include(x => x.ReadingQuestionTrial).ToListAsync();
|
||
var tableAnswerList = await _readingTableQuestionAnswerRepository.Where(x => taskIds.Contains(x.VisitTaskId)).Include(x => x.ReadingQuestionTrial).Include(x => x.ReadingTableQuestionTrial).ToListAsync();
|
||
|
||
#region 获取各个病灶
|
||
List<Dictionary<string, object>> getLesionInfo(LesionType lesionType)
|
||
{
|
||
List<decimal> targetFocusNum = rowinfoList.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.ReadingQuestionTrial.LesionType == lesionType).Select(x => x.RowIndex).OrderBy(x => x).ToList();
|
||
|
||
List<Dictionary<string, object>> targetInfo = new List<Dictionary<string, object>>();
|
||
|
||
foreach (var item in targetFocusNum)
|
||
{
|
||
var bodyPartDescription = _generalCalculateService.GetTaskTableAnswer(tableAnswerList, dictionList, unitDictionary, inDto.VisitTaskId, lesionType, QuestionMark.BodyPartDescription, item);
|
||
Dictionary<string, object> target = new Dictionary<string, object>()
|
||
{
|
||
{ "RowMark",rowinfoList.Where(x=>x.VisitTaskId == inDto.VisitTaskId &&x.RowIndex==item && x.ReadingQuestionTrial.LesionType == lesionType).Select(x=>x.RowMark).FirstIsNullReturnEmpty() },
|
||
{ "Organ",_generalCalculateService.GetTaskTableAnswer(tableAnswerList,dictionList,unitDictionary,inDto.VisitTaskId,lesionType,QuestionMark.Organ,item)+":"+_generalCalculateService.GetTaskTableAnswer(tableAnswerList,dictionList,unitDictionary,inDto.VisitTaskId,lesionType,QuestionMark.Part,item)+ (bodyPartDescription==string.Empty?string.Empty:","+bodyPartDescription) },
|
||
{ "FirstVisit",getStateInfo(0,item, lesionType) },
|
||
{ "SecondVisit", relatedCount>=2?getStateInfo(1,item,lesionType):string.Empty },
|
||
{ "ThirdlyVisit", relatedCount>=3?getStateInfo(2,item,lesionType):string.Empty },
|
||
};
|
||
targetInfo.Add(target);
|
||
}
|
||
return targetInfo;
|
||
}
|
||
|
||
string getStateInfo(int index, decimal item, LesionType lesionType)
|
||
{
|
||
// 非淋巴结取长径 淋巴结取长短径
|
||
var state = _generalCalculateService.GetTaskTableAnswer(tableAnswerList, dictionList, unitDictionary, taskIds[index], lesionType, QuestionMark.State, item);
|
||
var majorAxis = _generalCalculateService.GetTaskTableAnswer(tableAnswerList, dictionList, unitDictionary, taskIds[index], lesionType, QuestionMark.MajorAxis, item);
|
||
|
||
var isLymph = _generalCalculateService.GetTaskTableAnswer(tableAnswerList, dictionList, unitDictionary, taskIds[index], lesionType, QuestionMark.IsLymph, item);
|
||
var shortAxis = _generalCalculateService.GetTaskTableAnswer(tableAnswerList, dictionList, unitDictionary, taskIds[index], lesionType, QuestionMark.ShortAxis, item);
|
||
|
||
var result = string.Empty;
|
||
|
||
if (!state.IsNullOrEmpty())
|
||
{
|
||
result = state;
|
||
|
||
}
|
||
|
||
if (!majorAxis.IsNullOrEmpty())
|
||
{
|
||
result += result == string.Empty ? $"L:{majorAxis}" : $",L:{majorAxis}";
|
||
}
|
||
|
||
if (isLymph.EqEnum(YesOrNoOrNa.Yes) && !shortAxis.IsNullOrEmpty())
|
||
{
|
||
result += result == string.Empty ? $"S:{shortAxis}" : $",S:{shortAxis}";
|
||
}
|
||
|
||
return result;
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
#region 外层问题处理
|
||
|
||
// 获取外层问题
|
||
List<Dictionary<string, object>> getQuestionAnswerList(List<ExportReportQuestion> exports)
|
||
{
|
||
List<Dictionary<string, object>> questionAnswerList = new List<Dictionary<string, object>>();
|
||
foreach (var item in exports)
|
||
{
|
||
Dictionary<string, object> questionAnswer = new Dictionary<string, object>()
|
||
{
|
||
{"Name",item.QuestionName },
|
||
{"FirstVisit", _generalCalculateService.GetTaskanswer(answerList,dictionList,unitDictionary,taskIds[0],item.QuestionType)},
|
||
{"SecondVisit", relatedCount>=2? _generalCalculateService.GetTaskanswer(answerList,dictionList,unitDictionary,taskIds[1],item.QuestionType):string.Empty },
|
||
{"ThirdlyVisit", relatedCount>=3? _generalCalculateService.GetTaskanswer(answerList,dictionList,unitDictionary,taskIds[2],item.QuestionType):string.Empty },
|
||
};
|
||
questionAnswerList.Add(questionAnswer);
|
||
}
|
||
return questionAnswerList;
|
||
}
|
||
|
||
#endregion
|
||
|
||
var studyInfo = (await _dicomStudyRepository.Where(x => x.SubjectVisitId == taskinfo.SourceSubjectVisitId).Select(x => new
|
||
{
|
||
|
||
x.Modalities,
|
||
x.StudyTime,
|
||
x.BodyPartExamined,
|
||
x.Description
|
||
|
||
}).OrderBy(x => x.StudyTime).ToListAsync()).Select(x => new Dictionary<string, object>() {
|
||
|
||
{ "Modalities",x.Modalities},
|
||
{ "StudyTime",x.StudyTime?.ToString("yyyy-MM-dd")},
|
||
{ "Description",x.Description},
|
||
{ "ImageProblem",imageProblem},
|
||
}).ToList();
|
||
|
||
|
||
var subjectPatientList = await _subjectPatientRepository.Where(x => x.SubjectId == subjectInfo.Id).Include(x => x.Patient).ToListAsync();
|
||
|
||
var assessmentResult = string.Empty;
|
||
if (visitInfo.IsBaseLine)
|
||
{
|
||
var existDisease = answerList.Where(x => x.ReadingQuestionTrial.QuestionType == QuestionType.ExistDisease).Select(x => x.Answer).FirstIsNullReturnEmpty().EqEnum(ExistDisease.No) ? "不" : string.Empty;
|
||
assessmentResult = $"{existDisease}存在疾病";
|
||
}
|
||
else
|
||
{
|
||
assessmentResult = $"整体肿瘤评估结果为{_generalCalculateService.GetTaskanswer(answerList, dictionList, unitDictionary, inDto.VisitTaskId, QuestionType.Tumor)}";
|
||
}
|
||
|
||
var value = new Dictionary<string, object>()
|
||
{
|
||
// { "Logo" ,await _generalCalculateService.GetWordPictureMaxWL(_options.CurrentValue.MinIO.viewEndpoint+_hospital.CurrentValue.HospitalLogoPath ,System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"wwwroot/ReadReoprtTemplate/downLoad/{inDto.DownLoadGuid}"),110,100) },
|
||
|
||
{ "HospitalName",_hospital.CurrentValue.HospitalName } ,// 医院名称
|
||
{ "SubjectName",subjectInfo.ShortName }, //患者姓名
|
||
{ "SubjectSex", subjectInfo.Sex==string.Empty?string.Empty: subjectInfo.Sex=="M"?"男":"女" }, //患者性别
|
||
{ "SubjectAge",subjectInfo.Age==null?string.Empty: subjectInfo.Age +"岁" }, //患者年龄
|
||
{ "SubjectCode",subjectPatientList.Select(x=>x.Patient).OrderByDescending(x=>x.CreateTime).Select(x=>x.PatientIdStr).FirstIsNullReturnEmpty() }, //患者编号
|
||
{ "VisitName",visitInfo.VisitName }, //访视名称
|
||
{ "LatestScanDate",visitInfo.StudyList.Min(x=>x.StudyTime)?.ToString("yyyy-MM-dd") }, //随访日期
|
||
{ "CriterionName",taskinfo.TrialReadingCriterion.CriterionName }, //评估标准
|
||
{ "AssessmentResult", assessmentResult }, //评估结果
|
||
{ "DoctorName",doctor.LastName + doctor.FirstName}, //医生姓名
|
||
{ "SignTime",taskinfo.SignTime?.ToString("yyyy-MM-dd HH:mm:ss") }, //签名时间
|
||
{ "StudyInfo",studyInfo }, // 检查信息
|
||
{ "FirstVisit", relatedVisitTask.Item1[0].TaskName},
|
||
{ "SecondVisit",relatedCount>=2?relatedVisitTask.Item1[1].TaskName:string.Empty},
|
||
{ "ThirdlyVisit", relatedCount>=3?relatedVisitTask.Item1[2].TaskName:string.Empty},
|
||
{ "TargetInfo", getLesionInfo(LesionType.TargetLesion)}, // 靶病灶
|
||
{ "NoTargetInfo", getLesionInfo(LesionType.NonTargetLesions)}, // 非把病灶
|
||
{ "NewTargetInfo", getLesionInfo(LesionType.NewLesions)},// 新病灶
|
||
{ "TargetImage", await _generalCalculateService.GetLesionPic(rowinfoList, LesionType.TargetLesion,inDto.DownLoadGuid)}, // 靶病灶图片
|
||
{ "NoTargetImage",await _generalCalculateService.GetLesionPic(rowinfoList, LesionType.NonTargetLesions,inDto.DownLoadGuid)}, // 非靶病灶图片
|
||
{ "NewImage", await _generalCalculateService.GetLesionPic(rowinfoList, LesionType.NewLesions,inDto.DownLoadGuid)}, // 新病灶图片
|
||
{ "Result",getQuestionAnswerList(new List<ExportReportQuestion>()
|
||
{ new ExportReportQuestion (){ QuestionName="靶病灶径线之和(SOD)",QuestionType=QuestionType.SOD},
|
||
new ExportReportQuestion (){ QuestionName="非淋巴结靶病灶长径之和",QuestionType=QuestionType.SumOfDiameter},
|
||
new ExportReportQuestion (){ QuestionName="与基线相比SOD变化量",QuestionType=QuestionType.SODChange},
|
||
new ExportReportQuestion (){ QuestionName="与基线相比SOD变化百分比",QuestionType=QuestionType.SODPercent},
|
||
new ExportReportQuestion (){ QuestionName="与最低点相比SOD变化量",QuestionType=QuestionType.LowestIncrease},
|
||
new ExportReportQuestion (){ QuestionName="与最低点相比SOD变化百分比",QuestionType=QuestionType.LowPercent},
|
||
new ExportReportQuestion (){ QuestionName="最低点访视",QuestionType=QuestionType.LowVisit},
|
||
})}, // 评估结果
|
||
{ "Curative",getQuestionAnswerList(new List<ExportReportQuestion>()
|
||
{ new ExportReportQuestion (){ QuestionName="靶病灶评估",QuestionType=QuestionType.TargetLesion},
|
||
new ExportReportQuestion (){ QuestionName="非靶病灶评估",QuestionType=QuestionType.NoTargetLesion},
|
||
new ExportReportQuestion (){ QuestionName="存在新病灶",QuestionType=QuestionType.NewLesions},
|
||
new ExportReportQuestion (){ QuestionName="存在疾病",QuestionType=QuestionType.ExistDisease},
|
||
new ExportReportQuestion (){ QuestionName="整体肿瘤评估",QuestionType=QuestionType.Tumor},
|
||
})}, // 疗效结果
|
||
|
||
{ "ReportNo",await _generalCalculateService.GetReportExportNo(taskinfo) } ,
|
||
};
|
||
|
||
value = _generalCalculateService.StringEmptyTurnedLine(value);
|
||
|
||
var templatePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"wwwroot/ReadReoprtTemplate/ReportTemplate_RECIST1.1_CN_V1.docx");
|
||
var outputFilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"wwwroot/ReadReoprtTemplate/downLoad/{inDto.DownLoadGuid}.docx");
|
||
|
||
|
||
MiniWord.SaveAsByTemplate(outputFilePath, templatePath, value);
|
||
|
||
|
||
//// 获取文件夹中的所有文件路径
|
||
Directory.Delete(downFile, true);
|
||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||
{
|
||
Stream stream = _generalCalculateService.ReadAndReturnStream(outputFilePath);
|
||
return stream;
|
||
}
|
||
else
|
||
{
|
||
|
||
var pdfurl = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"wwwroot/ReadReoprtTemplate/downLoad");
|
||
FileConvertHelper.ConvertWordToPdf(outputFilePath, pdfurl);
|
||
Stream stream = _generalCalculateService.ReadAndReturnStream(pdfurl + $"/{inDto.DownLoadGuid}.pdf");
|
||
return stream;
|
||
}
|
||
}
|
||
|
||
#region 临时对象 单个请求的生命周期 避免重复查询数据库
|
||
|
||
private List<VisitTaskAnswerInfo> visitTaskAnswerList;
|
||
|
||
/// <summary>
|
||
/// 获取Sod的值
|
||
/// </summary>
|
||
private decimal? sODData;
|
||
|
||
private string nAString = "NA";
|
||
#endregion
|
||
|
||
#region 删除病灶获取起始病灶序号
|
||
/// <summary>
|
||
/// 删除病灶获取起始病灶序号(RECIST1Point1 固定是1)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public async Task<int> GetDeleteLesionStatrIndex(DeleteReadingRowAnswerInDto inDto)
|
||
{
|
||
return 1;
|
||
}
|
||
#endregion
|
||
|
||
#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 && x.ShowQuestion != ShowQuestion.Hide).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();
|
||
result.LesionCountList = tableAnsweRowInfos.GroupBy(x => x.LesionType).Select(x => new LesionDto
|
||
{
|
||
LesionType = x.Key!.Value,
|
||
Count = x.ToList().Count()
|
||
}).ToList();
|
||
var answers = await _readingTaskQuestionAnswerRepository.Where(x => visitTaskIds.Contains(x.VisitTaskId)).ToListAsync();
|
||
var tableAnswers = await _readingTableQuestionAnswerRepository.Where(x => visitTaskIds.Contains(x.VisitTaskId)).ToListAsync();
|
||
var globalanswerList = await _readingGlobalTaskInfoRepository.Where(x => visitTaskIds.Contains(x.TaskId) && x.GlobalVisitTask.TaskState == TaskState.Effect && x.Answer != string.Empty).Select(x => new
|
||
{
|
||
x.TaskId,
|
||
x.GlobalVisitTask.VisitTaskNum,
|
||
x.QuestionId,
|
||
x.Answer
|
||
}).ToListAsync();
|
||
var alltableAnsweRowInfos = await _readingTableAnswerRowInfoRepository.Where(x => visitTaskIds.Contains(x.VisitTaskId)).ToListAsync();
|
||
var organIds = alltableAnsweRowInfos.Where(x => x.OrganInfoId != null).Select(x => x.OrganInfoId).Distinct().ToList();
|
||
var organInfos = await _organInfoRepository.Where(x => organIds.Contains(x.Id)).ToListAsync();
|
||
|
||
var needChangeType = new List<QuestionMark?>() {
|
||
QuestionMark.Organ,
|
||
QuestionMark.Location,
|
||
QuestionMark.Part,
|
||
};
|
||
|
||
// 第一级
|
||
|
||
#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,
|
||
GroupEnName = x.GroupEnName,
|
||
IsShowInDicom = x.IsShowInDicom,
|
||
Type = x.Type,
|
||
GroupId = x.GroupId,
|
||
QuestionType = x.QuestionType,
|
||
LesionType = x.LesionType,
|
||
QuestionGenre = x.QuestionGenre,
|
||
DataSource = x.DataSource,
|
||
DictionaryCode = x.DictionaryCode,
|
||
TypeValue = x.TypeValue,
|
||
QuestionName = x.QuestionName.LanguageName(x.QuestionEnName, _userInfo.IsEn_Us),
|
||
ShowOrder = x.ShowOrder,
|
||
ValueType = x.ValueType,
|
||
Unit = x.Unit,
|
||
CustomUnit = x.CustomUnit,
|
||
ReportLayType = ReportLayType.Group,
|
||
HighlightAnswer = x.HighlightAnswer,
|
||
HighlightAnswerList = x.HighlightAnswerList,
|
||
}).ToList();
|
||
|
||
// 分组
|
||
foreach (var item in questions)
|
||
{
|
||
item.Childrens = questionList.Where(x => x.GroupId == item.QuestionId).OrderBy(x => x.ShowOrder).Select(x => new ReadingReportDto()
|
||
{
|
||
GroupName = x.GroupName,
|
||
QuestionId = x.Id,
|
||
IsShowInDicom = x.IsShowInDicom,
|
||
GroupEnName = x.GroupEnName,
|
||
QuestionName = x.QuestionName.LanguageName(x.QuestionEnName, _userInfo.IsEn_Us),
|
||
LesionType = x.LesionType,
|
||
QuestionGenre = x.QuestionGenre,
|
||
DataSource = x.DataSource,
|
||
DictionaryCode = x.DictionaryCode,
|
||
Type = x.Type,
|
||
QuestionType = x.QuestionType,
|
||
TypeValue = x.TypeValue,
|
||
ShowOrder = x.ShowOrder,
|
||
OrderMark = x.OrderMark,
|
||
ValueType = x.ValueType,
|
||
Unit = x.Unit,
|
||
CustomUnit = x.CustomUnit,
|
||
ReportLayType = ReportLayType.Question,
|
||
HighlightAnswer = x.HighlightAnswer,
|
||
HighlightAnswerList = x.HighlightAnswerList,
|
||
}).ToList();
|
||
|
||
// 问题
|
||
foreach (var question in item.Childrens)
|
||
{
|
||
|
||
foreach (var task in taskInfoList)
|
||
{
|
||
var globalAnswer = globalanswerList.Where(x => x.TaskId == task.VisitTaskId && x.QuestionId == question.QuestionId).OrderByDescending(x => x.VisitTaskNum).FirstOrDefault();
|
||
|
||
var answer = answers.Where(x => x.VisitTaskId == task.VisitTaskId && x.ReadingQuestionTrialId == question.QuestionId).FirstOrDefault();
|
||
question.Answer.Add(new TaskQuestionAnswer()
|
||
{
|
||
Answer = answer == null ? string.Empty : answer.Answer,
|
||
IsGlobalChange = globalAnswer == null ? false : true,
|
||
GlobalChangeAnswer = globalAnswer == null ? string.Empty : globalAnswer.Answer,
|
||
TaskName = task.TaskName,
|
||
VisitTaskId = task.VisitTaskId,
|
||
|
||
});
|
||
}
|
||
|
||
// 构造表格行数据
|
||
|
||
|
||
var rowlist = tableAnsweRowInfos.Where(x => x.QuestionId == question.QuestionId).OrderBy(x => x.RowIndex).ToList();
|
||
|
||
|
||
question.Childrens = rowlist.Select(x => new ReadingReportDto()
|
||
{
|
||
QuestionName = question.OrderMark + x.RowIndex.GetLesionMark(),
|
||
SplitOrMergeLesionName = x.MergeName.IsNullOrEmpty() ? x.SplitName : x.MergeName,
|
||
SplitOrMergeType = x.SplitOrMergeType,
|
||
LesionType = question.LesionType,
|
||
IsShowInDicom = question.IsShowInDicom,
|
||
IsCanEditPosition = x.IsCanEditPosition,
|
||
RowIndex = x.RowIndex,
|
||
BlindName = x.BlindName,
|
||
ReportLayType = ReportLayType.Lesions,
|
||
}).ToList();
|
||
|
||
|
||
foreach (var row in question.Childrens)
|
||
{
|
||
// tableQuestion
|
||
row.Childrens = tableQuestionList.Where(x => x.ReadingQuestionId == question.QuestionId).Select(x => new ReadingReportDto()
|
||
{
|
||
QuestionName = x.QuestionName.LanguageName(x.QuestionEnName, _userInfo.IsEn_Us),
|
||
QuestionId = x.ReadingQuestionId,
|
||
TableQuestionId = x.Id,
|
||
Type = x.Type,
|
||
LesionType = question.LesionType,
|
||
TableQuestionType = x.TableQuestionType,
|
||
RowId = row.RowId,
|
||
IsShowInDicom = question.IsShowInDicom,
|
||
DataSource = x.DataSource,
|
||
DictionaryCode = x.DictionaryCode,
|
||
QuestionMark = x.QuestionMark,
|
||
TypeValue = x.TypeValue,
|
||
RowIndex = row.RowIndex,
|
||
ShowOrder = x.ShowOrder,
|
||
ValueType = x.ValueType,
|
||
Unit = x.Unit,
|
||
ReportLayType = ReportLayType.TableQuestion,
|
||
}).ToList();
|
||
|
||
|
||
foreach (var tableQuestion in row.Childrens)
|
||
{
|
||
foreach (var task in taskInfoList)
|
||
{
|
||
var rowinfo = alltableAnsweRowInfos.Where(x => x.VisitTaskId == task.VisitTaskId && x.QuestionId == tableQuestion.QuestionId && x.RowIndex == tableQuestion.RowIndex).FirstOrDefault();
|
||
var taskQuestionAnswer = 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,
|
||
};
|
||
if (rowinfo != null && rowinfo.OrganInfoId != null)
|
||
{
|
||
var organInfo = organInfos.Where(x => x.Id == rowinfo.OrganInfoId).FirstOrDefault();
|
||
|
||
|
||
if (organInfo != null && needChangeType.Contains(tableQuestion.QuestionMark))
|
||
{
|
||
if (_userInfo.IsEn_Us)
|
||
{
|
||
switch (tableQuestion.QuestionMark)
|
||
{
|
||
case QuestionMark.Organ:
|
||
taskQuestionAnswer.Answer = organInfo.TULOCEN;
|
||
|
||
break;
|
||
case QuestionMark.Location:
|
||
if (organInfo.IsCanEditPosition)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
taskQuestionAnswer.Answer = organInfo.TULATEN;
|
||
|
||
}
|
||
break;
|
||
case QuestionMark.Part:
|
||
|
||
taskQuestionAnswer.Answer = organInfo.PartEN;
|
||
|
||
break;
|
||
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
switch (tableQuestion.QuestionMark)
|
||
{
|
||
case QuestionMark.Organ:
|
||
taskQuestionAnswer.Answer = organInfo.TULOC;
|
||
break;
|
||
case QuestionMark.Location:
|
||
if (organInfo.IsCanEditPosition)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
taskQuestionAnswer.Answer = organInfo.TULAT;
|
||
|
||
}
|
||
break;
|
||
case QuestionMark.Part:
|
||
taskQuestionAnswer.Answer = organInfo.Part;
|
||
break;
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
tableQuestion.Answer.Add(taskQuestionAnswer);
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
};
|
||
}
|
||
#endregion
|
||
|
||
|
||
|
||
result.TaskQuestions = questions;
|
||
|
||
|
||
|
||
return result;
|
||
|
||
}
|
||
#endregion
|
||
|
||
/// <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>
|
||
/// 获取报告验证的信息(这里每个标准可能不一样 返回用object)
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<GetReportVerifyOutDto> GetReportVerify(GetReportVerifyInDto inDto)
|
||
{
|
||
return new GetReportVerifyOutDto()
|
||
{
|
||
TumorEvaluate = await this.GetReportTumor(inDto.VisitTaskId),
|
||
IsExistDisease = await this.GetReportIsExistDisease(inDto.VisitTaskId),
|
||
|
||
};
|
||
}
|
||
|
||
|
||
/// <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>()
|
||
{
|
||
//靶病灶径线之和(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},
|
||
|
||
//与整个访视期间SOD最低点相比增加的值(mm) //其他任务需要改
|
||
new ReadingCalculateData (){QuestionType=QuestionType.LowestIncrease,GetDecimalNullFun=GetLowestIncrease,/*ChangeAllTaskFun=ChangeAllLowestIncrease*/},
|
||
|
||
//与整个访视期间SOD最低点相比增加的百分比 //其他任务需要改
|
||
new ReadingCalculateData (){QuestionType=QuestionType.LowPercent,GetDecimalNullFun=GetLowPercent,/*ChangeAllTaskFun=ChangeAllLowPercent*/},
|
||
|
||
//整个访视期间SOD最低点访视名称 //其他任务需要改
|
||
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},
|
||
|
||
//是否存在疾病
|
||
new ReadingCalculateData (){QuestionType=QuestionType.ExistDisease,GetStringFun=GetIsExistDisease},
|
||
|
||
};
|
||
|
||
// 没有靶病灶只计算最后几个
|
||
if (inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).Sum(x => x.TableRowInfoList.Count()) == 0)
|
||
{
|
||
|
||
List<QuestionType> questionTypes = new List<QuestionType>()
|
||
{
|
||
QuestionType.TargetLesion,
|
||
QuestionType.NoTargetLesion,
|
||
QuestionType.NewLesions,
|
||
QuestionType.Tumor,
|
||
QuestionType.ExistDisease,
|
||
};
|
||
|
||
// 没有靶病灶就删除其他几个答案的值
|
||
var isNeedDeleteTypes = calculateList.Where(x => !questionTypes.Contains(x.QuestionType)).Select(x => x.QuestionType).ToList();
|
||
|
||
|
||
var isNeedDeleteIds = inDto.QuestionInfo.Where(x => x.QuestionType != null && isNeedDeleteTypes.Contains(x.QuestionType.Value)).Select(x => x.QuestionId).ToList();
|
||
|
||
await _readingTaskQuestionAnswerRepository.BatchUpdateNoTrackingAsync(x => x.VisitTaskId == inDto.VisitTaskId && isNeedDeleteIds.Contains(x.ReadingQuestionTrialId), x => new ReadingTaskQuestionAnswer
|
||
{
|
||
Answer = string.Empty
|
||
});
|
||
|
||
|
||
|
||
calculateList = calculateList.Where(x => questionTypes.Contains(x.QuestionType)).ToList();
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
if (calculateType != null)
|
||
{
|
||
calculateList = calculateList.Where(x => calculateType.Contains(x.QuestionType)).ToList();
|
||
}
|
||
|
||
var typeNAList = new List<QuestionType>
|
||
{
|
||
QuestionType.SODChange,
|
||
QuestionType.SODPercent,
|
||
QuestionType.LowestIncrease,
|
||
QuestionType.LowPercent,
|
||
};
|
||
|
||
foreach (var calculate in calculateList)
|
||
{
|
||
var item = inDto.QuestionInfo.FirstOrDefault(x => x.QuestionType == calculate.QuestionType);
|
||
|
||
if (item != null)
|
||
{
|
||
//计算答案
|
||
if (inDto.IsOnlyChangeAllTask == false)
|
||
{
|
||
|
||
#region 计算答案
|
||
if (calculate.GetDecimalFun != null)
|
||
{
|
||
item.Answer = (await calculate.GetDecimalFun(inDto)).ToString();
|
||
|
||
}
|
||
else if (calculate.GetDecimalNullFun != null)
|
||
{
|
||
var value = await calculate.GetDecimalNullFun(inDto);
|
||
if (value == null)
|
||
{
|
||
if (typeNAList.Contains(item.QuestionType ?? QuestionType.SOD))
|
||
{
|
||
item.Answer = nameof(YesOrNoOrNa.NA);
|
||
|
||
}
|
||
else
|
||
{
|
||
item.Answer = this.nAString;
|
||
|
||
}
|
||
|
||
}
|
||
else
|
||
|
||
{
|
||
item.Answer = value == null ? string.Empty : value.Value.ToString();
|
||
}
|
||
}
|
||
else if (calculate.GetStringFun != null)
|
||
{
|
||
item.Answer = await calculate.GetStringFun(inDto);
|
||
}
|
||
#endregion
|
||
// 修改修约小数位数
|
||
|
||
List<ValueOfType?> valueOfTypes = new List<ValueOfType?>() {
|
||
|
||
ValueOfType.Decimals,
|
||
ValueOfType.Percentage
|
||
};
|
||
|
||
if (inDto.DigitPlaces != -1)
|
||
{
|
||
try
|
||
{
|
||
|
||
if (valueOfTypes.Contains(item.ValueType))
|
||
{
|
||
item.Answer = decimal.Round(decimal.Parse(item.Answer ?? "0"), inDto.DigitPlaces).ToString("F" + inDto.DigitPlaces.ToString());
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|
||
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
|
||
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取报告整体整体评估
|
||
/// </summary>
|
||
/// <param name="visitTaskId"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetReportTumor(Guid visitTaskId)
|
||
{
|
||
return await GetTumor(await _generalCalculateService.GetReadingCalculateDto(visitTaskId));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取报告是否存在疾病
|
||
/// </summary>
|
||
/// <param name="visitTaskId"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetReportIsExistDisease(Guid visitTaskId)
|
||
{
|
||
return await GetIsExistDisease(await _generalCalculateService.GetReadingCalculateDto(visitTaskId));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 验证访视提交
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task VerifyVisitTaskQuestions(VerifyVisitTaskQuestionsInDto inDto)
|
||
{
|
||
|
||
if (await _readingTaskQuestionAnswerRepository.AnyAsync(x => x.ReadingQuestionTrial.QuestionType == QuestionType.ImageQualityAssessment && x.VisitTaskId == inDto.VisitTaskId && x.Answer == ImageQualityEvaluation.Abnormal.GetEnumInt()))
|
||
{
|
||
//影像质量不正常 验证
|
||
return;
|
||
}
|
||
|
||
var tableAnswerList = await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && (x.Answer == string.Empty || x.Answer == null)
|
||
&& x.ReadingTableQuestionTrial.QuestionMark == QuestionMark.State)
|
||
.Select(x => new
|
||
{
|
||
x.ReadingQuestionTrial.OrderMark,
|
||
x.RowIndex,
|
||
x.ReadingTableQuestionTrial.QuestionMark,
|
||
x.Answer,
|
||
}).ToListAsync();
|
||
|
||
// 错误信息
|
||
string errorMassage = string.Empty;
|
||
var rowAnswerList = await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && (x.MeasureData == string.Empty || x.MeasureData == null))
|
||
.Select(x => new
|
||
{
|
||
x.ReadingQuestionTrial.OrderMark,
|
||
x.RowIndex,
|
||
x.Id,
|
||
}).ToListAsync();
|
||
var unableEvaluateRowIds = await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.Answer == TargetState.UnableEvaluate.GetEnumInt()
|
||
&& x.ReadingTableQuestionTrial.QuestionMark == QuestionMark.State)
|
||
.Select(x => x.RowId).Distinct().ToListAsync();
|
||
|
||
|
||
List<string> measureDataList = rowAnswerList.Where(x => !unableEvaluateRowIds.Contains(x.Id)).Select(x => x.OrderMark + x.RowIndex.GetLesionMark()).ToList();
|
||
List<string> stateIsNullList = tableAnswerList.Select(x => x.OrderMark + x.RowIndex.GetLesionMark()).ToList();
|
||
List<string> allExists = measureDataList.Intersect(stateIsNullList).ToList();
|
||
// 取差
|
||
measureDataList = measureDataList.Except(allExists).ToList();
|
||
stateIsNullList = stateIsNullList.Except(allExists).ToList();
|
||
if (measureDataList.Count() > 0)
|
||
{
|
||
// 无标记
|
||
errorMassage += _localizer["ReadingCalculate_NoMarker", string.Join(',', measureDataList)] + ",";
|
||
}
|
||
|
||
if (tableAnswerList.Count > 0)
|
||
{
|
||
// 状态为空
|
||
errorMassage += _localizer["ReadingCalculate_StatusIsEmpty", string.Join(',', stateIsNullList)] + ",";
|
||
}
|
||
|
||
if (allExists.Count > 0)
|
||
{
|
||
// 未做标记且状态为空
|
||
errorMassage += _localizer["ReadingCalculate_NoMarkerEmpty", string.Join(',', stateIsNullList)] + ",";
|
||
}
|
||
|
||
|
||
if (errorMassage != string.Empty)
|
||
{
|
||
errorMassage = _localizer["ReadingCalculate_Questionable"] + errorMassage;
|
||
throw new BusinessValidationFailedException(errorMassage);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#region 将上一次的访视病灶添加到这一次
|
||
|
||
/// <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.IsAnalysisCreate == taskinfo.IsAnalysisCreate &&
|
||
x.ArmEnum == taskinfo.ArmEnum &&
|
||
x.IsSelfAnalysis == taskinfo.IsSelfAnalysis &&
|
||
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;
|
||
x.PicturePath = 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();
|
||
|
||
});
|
||
|
||
List<QuestionMark?> notNeedCopyMarks = new List<QuestionMark?>()
|
||
{
|
||
QuestionMark.MajorAxis,
|
||
QuestionMark.ShortAxis,
|
||
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,
|
||
});
|
||
|
||
|
||
|
||
|
||
var addList = _mapper.Map<List<ReadingTableAnswerRowInfo>>(tableRowAnswers);
|
||
|
||
await _readingTableAnswerRowInfoRepository.AddRangeAsync(addList);
|
||
await _readingTableQuestionAnswerRepository.AddRangeAsync(tableAnswers);
|
||
|
||
addList.ForEach(x =>
|
||
{
|
||
x.MergeRow = null;
|
||
x.SplitRow = null;
|
||
|
||
});
|
||
await _readingTableQuestionAnswerRepository.SaveChangesAsync();
|
||
|
||
}
|
||
}
|
||
|
||
return new AddTaskLesionAnswerFromLastTaskOutDto()
|
||
{
|
||
|
||
IsBaseLine = taskinfo.SourceSubjectVisitId == baseLineVisitId,
|
||
};
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 获取SOD
|
||
|
||
/// <summary>
|
||
/// 获取SOD
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 靶病灶径线之和(SOD)
|
||
/// 非淋巴结的长径 和淋巴结的短径
|
||
/// </remarks>
|
||
/// <returns></returns>
|
||
public async Task<decimal?> GetSODData(ReadingCalculateDto inDto)
|
||
{
|
||
if (sODData != null)
|
||
{
|
||
return sODData.Value;
|
||
}
|
||
|
||
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)
|
||
{
|
||
if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && x.Answer.EqEnum(YesOrNoOrNa.Yes)))
|
||
{
|
||
// 淋巴结的短径
|
||
result += (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.EqEnum(YesOrNoOrNa.No)))
|
||
{
|
||
// 非淋巴结的长径
|
||
result += item.TableQuestionList.Where(x => x.QuestionMark == QuestionMark.MajorAxis).Select(x => x.Answer).FirstOrDefault().IsNullOrEmptyReturn0();
|
||
}
|
||
}
|
||
|
||
sODData = result;
|
||
|
||
return sODData.Value;
|
||
|
||
|
||
|
||
}
|
||
#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();
|
||
|
||
if (tableQuestion.Count() == 0)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
decimal result = 0;
|
||
|
||
foreach (var item in tableQuestion)
|
||
{
|
||
if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && x.Answer.EqEnum(YesOrNoOrNa.No)))
|
||
{
|
||
// 非淋巴结的长径
|
||
result += 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)
|
||
{
|
||
|
||
var value = await GetSODData(inDto);
|
||
|
||
if (value == null || inDto.IsBaseLine)
|
||
{
|
||
return null;
|
||
}
|
||
return value.NullChange0() - await GetBaseLineSOD(inDto);
|
||
}
|
||
#endregion
|
||
|
||
#region 与基线访视相比SOD变化百分比
|
||
/// <summary>
|
||
/// 与基线访视相比SOD变化百分比
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<decimal?> GetSODPercent(ReadingCalculateDto inDto)
|
||
{
|
||
var thisSOD = await GetSODData(inDto);
|
||
|
||
if (thisSOD == null || inDto.IsBaseLine)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
var baseLineSOD = await GetBaseLineSOD(inDto);
|
||
|
||
if (baseLineSOD == 0)
|
||
{
|
||
return 100;
|
||
}
|
||
else
|
||
{
|
||
return (thisSOD.NullChange0() - baseLineSOD) * 100 / baseLineSOD;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 与整个访视期间SOD最低点相比增加的值(mm)
|
||
/// <summary>
|
||
/// 与整个访视期间SOD最低点相比增加的值(mm)
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <remarks>
|
||
/// 要更新之前的
|
||
/// </remarks>
|
||
/// <returns></returns>
|
||
public async Task<decimal?> GetLowestIncrease(ReadingCalculateDto inDto)
|
||
{
|
||
var value = await GetSODData(inDto);
|
||
if (value == null || inDto.IsBaseLine)
|
||
{
|
||
return null;
|
||
}
|
||
var decimalAnswerList = await GetLowSODVisit(inDto);
|
||
var minSOD = decimalAnswerList.OrderBy(x => x.SOD).Select(x => x.SOD).FirstOrDefault();
|
||
return value.NullChange0() - minSOD;
|
||
}
|
||
#endregion
|
||
|
||
#region 与整个访视期间SOD最低点相比增加的百分比
|
||
/// <summary>
|
||
/// 与整个访视期间SOD最低点相比增加的百分比
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <remarks>
|
||
/// 要更新之前的
|
||
/// </remarks>
|
||
/// <returns></returns>
|
||
public async Task<decimal?> GetLowPercent(ReadingCalculateDto inDto)
|
||
{
|
||
var thisSOD = await GetSODData(inDto);
|
||
if (thisSOD == null || inDto.IsBaseLine)
|
||
{
|
||
return null;
|
||
}
|
||
var decimalAnswerList = await GetLowSODVisit(inDto);
|
||
var minSOD = decimalAnswerList.OrderBy(x => x.SOD).Select(x => x.SOD).FirstOrDefault();
|
||
|
||
if (minSOD == 0)
|
||
{
|
||
return 100;
|
||
}
|
||
else
|
||
{
|
||
return (thisSOD.NullChange0() - minSOD) * 100 / minSOD;
|
||
}
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 整个访视期间SOD最低点访视名称
|
||
/// <summary>
|
||
/// 整个访视期间SOD最低点访视名称
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <remarks>
|
||
/// 要更新之前的
|
||
/// </remarks>
|
||
/// <returns></returns>
|
||
public async Task<string> GetLowVisit(ReadingCalculateDto inDto)
|
||
{
|
||
if (inDto.IsBaseLine)
|
||
{
|
||
return nameof(YesOrNoOrNa.NA);
|
||
}
|
||
var targetCount = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).SelectMany(x => x.TableRowInfoList).Count();
|
||
if (targetCount == 0)
|
||
{
|
||
return nameof(YesOrNoOrNa.NA);
|
||
}
|
||
|
||
var decimalAnswerList = await GetLowSODVisit(inDto);
|
||
return decimalAnswerList.OrderBy(x => x.SOD).Select(x => x.BlindName).FirstOrDefault() ?? string.Empty;
|
||
}
|
||
#endregion
|
||
|
||
#region 是否存在非淋巴结靶病灶
|
||
/// <summary>
|
||
/// 是否存在非淋巴结靶病灶
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetIsLymphTarget(ReadingCalculateDto inDto)
|
||
{
|
||
var result = IsLymph.No.GetEnumInt();
|
||
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.EqEnum(IsLymph.No)))
|
||
{
|
||
result = IsLymph.Yes.GetEnumInt();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
return result;
|
||
}
|
||
#endregion
|
||
|
||
#region 是否存在淋巴结靶病灶且该病灶比上一访视短径增加5MM以上
|
||
/// <summary>
|
||
/// 是否存在淋巴结靶病灶且该病灶比上一访视短径增加5MM以上
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetIsAddFive(ReadingCalculateDto inDto)
|
||
{
|
||
if (inDto.IsBaseLine)
|
||
{
|
||
return YesOrNoOrNa.NA.GetEnumInt();
|
||
}
|
||
var addFiveList = await GetIsAddFiveRowIndexs(inDto);
|
||
var isExists = addFiveList.Count() > 0 ? true : false;
|
||
|
||
return isExists ? YesOrNoOrNa.Yes.GetEnumInt() : YesOrNoOrNa.No.GetEnumInt();
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取存在淋巴结靶病灶且该病灶比上一访视短径增加5MM以上的病灶
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<List<decimal>> GetIsAddFiveRowIndexs(ReadingCalculateDto inDto)
|
||
{
|
||
List<decimal> result = new List<decimal>();
|
||
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).Include(x => x.ReadingTableQuestionTrial).ToListAsync();
|
||
var rowIndexs = lastQuestionAsnwer.Where(x => x.ReadingTableQuestionTrial.QuestionMark == QuestionMark.IsLymph && x.Answer.EqEnum(YesOrNoOrNa.Yes)).Select(x => x.RowIndex).Distinct().OrderBy(x => x).ToList();
|
||
var thisQuestionAsnwer = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).SelectMany(x => x.TableRowInfoList).ToList();
|
||
foreach (var item in rowIndexs)
|
||
{
|
||
var lastValue = 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 = thisRowData.Where(x => x.QuestionMark == QuestionMark.ShortAxis).Select(x => x.Answer).FirstOrDefault().IsNullOrEmptyReturn0();
|
||
|
||
if (thisValue - lastValue >= 5)
|
||
{
|
||
result.Add(item);
|
||
}
|
||
}
|
||
|
||
return result;
|
||
}
|
||
#endregion
|
||
|
||
#region 被评估为NE的单个靶病灶
|
||
/// <summary>
|
||
/// 被评估为NE的单个靶病灶
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetNETarget(ReadingCalculateDto inDto)
|
||
{
|
||
if (inDto.IsBaseLine)
|
||
{
|
||
return ExistOrNA.NA.GetEnumInt();
|
||
}
|
||
|
||
var result = inDto.QuestionInfo.Any(x => x.QuestionType == QuestionType.TargetLesion && x.Answer.EqEnum(TargetAssessment.NE));
|
||
|
||
return result ? ExistOrNA.Exist.GetEnumInt() : ExistOrNA.NotExist.GetEnumInt();
|
||
}
|
||
#endregion
|
||
|
||
#region 整体肿瘤评估
|
||
|
||
/// <summary>
|
||
/// 整体肿瘤评估
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetTumor(ReadingCalculateDto inDto)
|
||
{
|
||
|
||
if (inDto.IsBaseLine)
|
||
{
|
||
return OverallAssessment.NA.GetEnumInt();
|
||
}
|
||
|
||
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 == (TargetAssessment)int.Parse(targetLesion.IsNullOrEmpty() ? TargetAssessment.NA.GetEnumInt() : targetLesion) &&
|
||
x.NonTargetLesions == (NoTargetAssessment)int.Parse(noTargetLesion.IsNullOrEmpty() ? NoTargetAssessment.NA.GetEnumInt() : noTargetLesion) &&
|
||
x.NewLesion == (NewLesionAssessment)int.Parse(newLesions.IsNullOrEmpty() ? NewLesionAssessment.NA.GetEnumInt() : newLesions)).Select(x => x.OverallEfficacy).ToListAsync();
|
||
|
||
return result.Count == 0 ? OverallAssessment.NE.GetEnumInt() : result[0].GetEnumInt();
|
||
}
|
||
#endregion
|
||
|
||
#region 是否存在疾病
|
||
/// <summary>
|
||
/// 是否存在疾病
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetIsExistDisease(ReadingCalculateDto inDto)
|
||
{
|
||
if (!inDto.IsBaseLine)
|
||
{
|
||
return string.Empty;
|
||
}
|
||
|
||
var lesionCount = inDto.QuestionInfo.SelectMany(x => x.TableRowInfoList).Count();
|
||
|
||
return lesionCount > 0 ? ExistDisease.Yes.GetEnumInt() : ExistDisease.No.GetEnumInt();
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region 修改其他标准
|
||
|
||
#region 修改与整个访视期间SOD最低点相比增加的值(mm)
|
||
|
||
/// <summary>
|
||
/// 修改与整个访视期间SOD最低点相比增加的值(mm)
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task ChangeAllLowestIncrease(ChangeAllTaskDto inDto)
|
||
{
|
||
var visitTaskList = await GetVisitTaskAnswerList(inDto.calculateDto);
|
||
|
||
var lowSod = (await GetLowSODVisit(inDto.calculateDto)).Select(x => x.SOD).OrderBy(x => x).FirstOrDefault();
|
||
|
||
foreach (var item in visitTaskList.Where(x => x.VisitTaskId != inDto.calculateDto.BaseLineTaskId))
|
||
{
|
||
await _readingTaskQuestionAnswerRepository.BatchUpdateNoTrackingAsync(x => x.VisitTaskId == item.VisitTaskId && x.ReadingQuestionTrialId == inDto.QuestionId, x => new ReadingTaskQuestionAnswer()
|
||
{
|
||
Answer = (item.SOD - lowSod).ToString()
|
||
});
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
#region 修改整个访视期间SOD最低点相比增加的百分比
|
||
|
||
/// <summary>
|
||
/// 修改整个访视期间SOD最低点相比增加的百分比
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
//public async Task ChangeAllLowPercent(ChangeAllTaskDto inDto)
|
||
//{
|
||
// var visitTaskList = await GetVisitTaskAnswerList(inDto.calculateDto);
|
||
|
||
// var lowSod = (await GetLowSODVisit(inDto.calculateDto)).Select(x => x.SOD).OrderBy(x => x).FirstOrDefault();
|
||
|
||
// foreach (var item in visitTaskList.Where(x => x.VisitTaskId != inDto.calculateDto.BaseLineTaskId))
|
||
// {
|
||
// 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 == inDto.QuestionId, x => new ReadingTaskQuestionAnswer()
|
||
// {
|
||
// Answer = percent.ToString()
|
||
// });
|
||
// }
|
||
//}
|
||
|
||
#endregion
|
||
|
||
#region 修改最低方式点名称
|
||
/// <summary>
|
||
/// 修改最低方式点名称
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task ChangeAllLowVisitName(ChangeAllTaskDto inDto)
|
||
{
|
||
// 找到所有访视任务的Id
|
||
|
||
var visitTaskIds = await _visitTaskRepository.Where(x => x.IsAnalysisCreate == inDto.IsAnalysisCreate &&
|
||
x.ReadingCategory == ReadingCategory.Visit &&
|
||
x.TrialReadingCriterionId == inDto.calculateDto.TrialReadingCriterionId &&
|
||
x.TaskState == TaskState.Effect && x.ReadingTaskState == ReadingTaskState.HaveSigned && x.ArmEnum == inDto.calculateDto.ArmEnum).Select(x => x.Id).ToListAsync();
|
||
|
||
var answer = (await GetLowSODVisit(inDto.calculateDto)).OrderBy(x => x.SOD).Select(x => x.BlindName).FirstOrDefault();
|
||
visitTaskIds = visitTaskIds.Where(x => x != inDto.calculateDto.BaseLineTaskId).ToList();
|
||
await this.ChangeAllVisitTaskAnswer(visitTaskIds, inDto.QuestionId, answer);
|
||
|
||
}
|
||
#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 == inDto.IsAnalysisCreate && x.ArmEnum == inDto.ArmEnum))
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
// 先找到基线的任务
|
||
var baseLineTaskId = await _visitTaskRepository.Where(x => x.SubjectId == inDto.SubjectId && x.ReadingCategory == ReadingCategory.Visit
|
||
&& x.TrialReadingCriterionId == inDto.TrialReadingCriterionId &&
|
||
|
||
x.SourceSubjectVisit.IsBaseLine && x.TaskState == TaskState.Effect &&
|
||
x.IsAnalysisCreate == inDto.IsAnalysisCreate
|
||
&& x.ArmEnum == inDto.ArmEnum
|
||
&& x.IsSelfAnalysis == inDto.IsSelfAnalysis && x.ArmEnum == inDto.ArmEnum)
|
||
.Select(x => x.Id).FirstOrDefaultAsync();
|
||
|
||
|
||
var baseLineSOD = (await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == baseLineTaskId && x.ReadingQuestionTrial.QuestionType == QuestionType.SOD).Select(x => x.Answer).FirstOrDefaultAsync()).IsNullOrEmptyReturn0();
|
||
return baseLineSOD;
|
||
}
|
||
#endregion
|
||
|
||
|
||
/// <summary>
|
||
/// 获取最低方式
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<List<VisitTaskAnswerInfo>> GetLowSODVisit(ReadingCalculateDto inDto)
|
||
{
|
||
var taskAnswerList = await GetVisitTaskAnswerList(inDto);
|
||
|
||
taskAnswerList = taskAnswerList.Where(x => x.VisitTaskId != inDto.VisitTaskId).ToList();
|
||
|
||
var taskIds = taskAnswerList.Select(x => x.VisitTaskId).ToList();
|
||
|
||
// 排除无法评估
|
||
var unableEvaluateTaskIds = await _readingTableQuestionAnswerRepository.Where(x => taskIds.Contains(x.VisitTaskId) &&
|
||
x.ReadingTableQuestionTrial.QuestionMark == QuestionMark.State
|
||
&& x.ReadingQuestionTrial.LesionType == LesionType.TargetLesion
|
||
&& x.Answer == TargetState.UnableEvaluate.GetEnumInt()
|
||
)
|
||
.Select(x => x.VisitTaskId).Distinct().ToListAsync();
|
||
|
||
taskAnswerList = taskAnswerList.Where(x => !unableEvaluateTaskIds.Contains(x.VisitTaskId)).ToList();
|
||
return taskAnswerList.OrderBy(x => x.SOD).ToList();
|
||
}
|
||
|
||
#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.VisitTaskId != inDto.VisitTaskId && x.VisitTask.ReadingCategory == ReadingCategory.Visit
|
||
&& x.VisitTask.IsAnalysisCreate == inDto.IsAnalysisCreate
|
||
&& x.VisitTask.IsSelfAnalysis == inDto.IsSelfAnalysis
|
||
&& x.VisitTask.VisitTaskNum < inDto.VisitTaskNum
|
||
&& x.ReadingQuestionCriterionTrialId == inDto.TrialReadingCriterionId
|
||
&& x.SubjectId == inDto.SubjectId && x.VisitTask.ReadingTaskState == ReadingTaskState.HaveSigned && x.VisitTask.ArmEnum == inDto.ArmEnum && 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,
|
||
BlindName = x.VisitTask.TaskBlindName,
|
||
|
||
SOD = x.Answer.IsNullOrEmptyReturn0(),
|
||
}).ToListAsync();
|
||
|
||
// 这里是需要加上自己的 基线不用管
|
||
if (visitTaskAnswerList.Count > 0)
|
||
{
|
||
visitTaskAnswerList.Add(new VisitTaskAnswerInfo()
|
||
{
|
||
VisitTaskId = inDto.VisitTaskId,
|
||
BlindName = inDto.TaskBlindName,
|
||
QuestionId = visitTaskAnswerList[0].QuestionId,
|
||
VisitName = inDto.VisitName,
|
||
SOD = (await GetSODData(inDto)).ToString().IsNullOrEmptyReturn0(),
|
||
});
|
||
}
|
||
|
||
|
||
}
|
||
|
||
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.IsLostVisit && x.VisitNum < thisNum).OrderByDescending(x => x.VisitNum).Select(x => x.Id).FirstOrDefaultAsync();
|
||
|
||
// 找到访视任务Id
|
||
|
||
var LastVisitTaskId = await _visitTaskRepository.Where(x => x.ReadingCategory == ReadingCategory.Visit &&
|
||
x.TrialReadingCriterionId == inDto.TrialReadingCriterionId &&
|
||
x.TaskState == TaskState.Effect &&
|
||
x.IsAnalysisCreate == inDto.IsAnalysisCreate
|
||
&& x.SourceSubjectVisitId == lastVisitId && x.ArmEnum == inDto.ArmEnum).Select(x => x.Id).FirstOrDefaultAsync();
|
||
|
||
return LastVisitTaskId;
|
||
}
|
||
#endregion
|
||
|
||
#region 计算阅片问题 外层问题
|
||
|
||
#region 获取靶病灶评估
|
||
/// <summary>
|
||
/// 获取靶病灶评估
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <remarks>
|
||
/// 靶病灶疗效评估算法-20230306确认版本:
|
||
///if(基线没有靶病灶)
|
||
///{
|
||
/// 靶病灶疗效为 ND
|
||
///}else
|
||
///{
|
||
/// 初始化靶病灶疗效为 SD
|
||
///
|
||
/// if (与基线期SOD相比减小≥30 %)
|
||
/// {
|
||
/// 靶病灶疗效为 PR
|
||
///
|
||
/// }
|
||
///
|
||
///if (非淋巴结靶病灶长径之和 == 0 并且所有淋巴结靶病灶的短径 < 10且淋巴结非靶病灶全部消失)
|
||
/// {
|
||
/// 靶病灶疗效为 CR
|
||
///
|
||
/// }
|
||
///
|
||
///if (有被评估为NE的单个靶病灶)
|
||
/// {
|
||
/// 靶病灶疗效为 NE
|
||
///
|
||
/// }
|
||
///
|
||
///if (最低点SOD > 0)
|
||
///{
|
||
/// if(比整体访视期间最低点SOD增加≥20 % 且与整个访视期间最低点相比增加的值≥5 mm)
|
||
/// {
|
||
/// 靶病灶疗效为 PD
|
||
///
|
||
/// }
|
||
///}
|
||
///else
|
||
///{
|
||
/// //进入该分支最低点SOD=0
|
||
/// if (当前访视SOD > 0 且与整个访视期间最低点相比增加的值≥5 mm)
|
||
/// {
|
||
/// 靶病灶疗效为PD
|
||
///
|
||
/// }
|
||
///}
|
||
///
|
||
///if(上次访视点评估是CR)
|
||
/// {
|
||
/// if (当前访视点淋巴结病灶,至少一个淋巴结靶病灶短径≥10 mm 并且该淋巴结靶病灶短径绝对增加值≥5 mm)
|
||
/// {
|
||
/// 靶病灶疗效为 PD
|
||
///
|
||
/// }
|
||
/// if (当前访视点非淋巴结病灶至少一个非淋巴结靶病灶的长径>0 mm。)
|
||
/// {
|
||
/// 靶病灶疗效为 PD
|
||
///
|
||
/// }
|
||
///}
|
||
///}
|
||
/// </remarks>
|
||
/// <returns></returns>
|
||
public async Task<string> GetTargetLesionEvaluate(ReadingCalculateDto inDto)
|
||
{
|
||
var tableQuestion = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.TargetLesion).SelectMany(x => x.TableRowInfoList).ToList();
|
||
if (inDto.IsBaseLine)
|
||
{
|
||
return TargetAssessment.NA.GetEnumInt();
|
||
}
|
||
|
||
TargetLesionCalculateDto resultData = new TargetLesionCalculateDto()
|
||
{
|
||
|
||
|
||
// 是否存在靶病灶
|
||
ExistsTargetLesion = tableQuestion.Count() > 0,
|
||
|
||
// 最低SOD
|
||
LowSod = (await GetLowSODVisit(inDto)).Select(x => x.SOD).FirstOrDefault(),
|
||
|
||
// 当前Sod
|
||
PresentSod = (await GetSODData(inDto)) ?? 0,
|
||
|
||
//非淋巴结靶病灶长径之和 decimal
|
||
SumOfDiameter = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.SumOfDiameter).Sum(x => x.Answer.IsNullOrEmptyReturn0()),
|
||
|
||
//所有淋巴结靶病灶的短径小于10mm bool
|
||
DiameterLessThan10 = true,
|
||
|
||
// SOD变化百分比
|
||
SODPercent = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.SODPercent).Sum(x => x.Answer.IsNullOrEmptyReturn0()),
|
||
|
||
// SOD 百分比与基线期SOD相比减小≥30% bool
|
||
SODPercentBigger30 = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.SODPercent).Sum(x => x.Answer.IsNullOrEmptyReturn0()) <= -30,
|
||
|
||
// SOD 百分比 与基线期SOD相比减小<30% bool
|
||
SODPercentLess30 = 0 > inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.SODPercent).Sum(x => x.Answer.IsNullOrEmptyReturn0()) &&
|
||
|
||
inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.SODPercent).Sum(x => x.Answer.IsNullOrEmptyReturn0()) > -30,
|
||
|
||
// SOD 百分比 整体访视期间SOD最低点SOD相比增加<20%
|
||
LowSODPercentLess20 = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.LowPercent).Sum(x => x.Answer.IsNullOrEmptyReturn0()) < 20,
|
||
|
||
// SOD 百分比 比整体访视期间SOD最低点SOD增加≥20%
|
||
LowSODPercentBigger20 = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.LowPercent).Sum(x => x.Answer.IsNullOrEmptyReturn0()) >= 20,
|
||
|
||
// SOD 变化值 比整体访视期间SOD最低点SOD绝对增加值<5 mm
|
||
LowSODChangeLess5 = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.LowestIncrease).Sum(x => x.Answer.IsNullOrEmptyReturn0()) < 5,
|
||
|
||
// 比整体访视期间SOD最低点SOD绝对增加值≥5 mm
|
||
LowSODChangeBigger5 = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.LowestIncrease).Sum(x => x.Answer.IsNullOrEmptyReturn0()) >= 5,
|
||
|
||
// 被评估为NE的单个靶病灶 是否存在状态为不可评估的靶病灶
|
||
ExixtsNETargetLesion = tableQuestion.SelectMany(x => x.TableQuestionList).Any(x => x.QuestionMark == QuestionMark.State && x.Answer.EqEnum(TargetState.UnableEvaluate)),
|
||
|
||
//// 上次访视点整体肿瘤评估
|
||
LastTargetLesionEvaluate = string.Empty,
|
||
|
||
// 当前访视点非淋巴结病灶至少一个非淋巴结靶病灶的长径>0 mm
|
||
CurrentMajoreBigger0 = false,
|
||
|
||
// 当前访视点淋巴结病灶, 至少一个淋巴结靶病灶短径≥10 mm
|
||
CurrenShortBigger10 = false,
|
||
|
||
// 靶病灶短径增加值有5mm的Index
|
||
AddFiveIndexs = await GetIsAddFiveRowIndexs(inDto),
|
||
|
||
// 短径有10mm的Index
|
||
ShortBigger10Indexs = new List<decimal>(),
|
||
|
||
//淋巴结非靶病灶状态全部为消失
|
||
NonTargetStateIsLoss = true,
|
||
|
||
// 该淋巴结靶病灶短径绝对增加值≥5 mm
|
||
IsAddFive = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.IsAddFive && x.Answer.EqEnum(YesOrNoOrNa.Yes)).Count() > 0,
|
||
};
|
||
|
||
var nonTargetTableQuestion = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.NonTargetLesions).SelectMany(x => x.TableRowInfoList).ToList();
|
||
|
||
foreach (var item in nonTargetTableQuestion)
|
||
{
|
||
if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && x.Answer.EqEnum(YesOrNoOrNa.Yes)))
|
||
{
|
||
// 淋巴结非靶病灶状态全部为消失
|
||
resultData.NonTargetStateIsLoss = resultData.NonTargetStateIsLoss && item.TableQuestionList.Where(x => x.QuestionMark == QuestionMark.State).Select(x => x.Answer).FirstOrDefault() == NoTargetState.Loss.GetEnumInt();
|
||
}
|
||
}
|
||
|
||
|
||
foreach (var item in tableQuestion)
|
||
{
|
||
if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && x.Answer.EqEnum(YesOrNoOrNa.Yes)))
|
||
{
|
||
// 淋巴结的短径
|
||
resultData.DiameterLessThan10 = resultData.DiameterLessThan10 && (item.TableQuestionList.Where(x => x.QuestionMark == QuestionMark.ShortAxis).Select(x => x.Answer).FirstOrDefault()).IsNullOrEmptyReturn0() < 10;
|
||
|
||
var shortIsBigger10 = (item.TableQuestionList.Where(x => x.QuestionMark == QuestionMark.ShortAxis).Select(x => x.Answer).FirstOrDefault()).IsNullOrEmptyReturn0() >= 10;
|
||
resultData.CurrenShortBigger10 = resultData.CurrenShortBigger10 || shortIsBigger10;
|
||
|
||
if (shortIsBigger10)
|
||
{
|
||
resultData.ShortBigger10Indexs.Add(item.RowIndex);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
if (item.TableQuestionList.Any(x => x.QuestionMark == QuestionMark.IsLymph && !x.Answer.EqEnum(YesOrNoOrNa.Yes)))
|
||
{
|
||
// 当前访视点非淋巴结病灶至少一个非淋巴结靶病灶的长径
|
||
resultData.CurrentMajoreBigger0 = resultData.CurrentMajoreBigger0 || (item.TableQuestionList.Where(x => x.QuestionMark == QuestionMark.MajorAxis).Select(x => x.Answer).FirstOrDefault()).IsNullOrEmptyReturn0() > 0;
|
||
}
|
||
}
|
||
|
||
|
||
var lastVisitTaskId = await GetLastVisitTaskId(inDto);
|
||
var questionId = inDto.QuestionInfo.Where(x => x.QuestionType == QuestionType.Tumor).Select(x => x.QuestionId).FirstOrDefault();
|
||
resultData.LastTargetLesionEvaluate = (await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == lastVisitTaskId && x.ReadingQuestionTrialId == questionId)
|
||
.Select(x => x.Answer).FirstOrDefaultAsync()) ?? string.Empty;
|
||
|
||
TargetAssessment result = TargetAssessment.SD;
|
||
//if(基线没有靶病灶)
|
||
if (!resultData.ExistsTargetLesion)
|
||
{
|
||
// 靶病灶疗效为 ND
|
||
result = TargetAssessment.ND;
|
||
}
|
||
else
|
||
{
|
||
//初始化靶病灶疗效为 SD
|
||
result = TargetAssessment.SD;
|
||
|
||
//if (与基线期SOD相比减小≥30 %)
|
||
if (resultData.SODPercentBigger30)
|
||
{
|
||
//靶病灶疗效为 PR
|
||
result = TargetAssessment.PR;
|
||
}
|
||
//if (非淋巴结靶病灶长径之和 == 0 并且所有淋巴结靶病灶的短径 < 10且淋巴结非靶病灶全部消失)
|
||
if (resultData.SumOfDiameter == 0 && resultData.DiameterLessThan10 && resultData.NonTargetStateIsLoss)
|
||
{
|
||
//靶病灶疗效为 CR
|
||
result = TargetAssessment.CR;
|
||
}
|
||
// if (有被评估为NE的单个靶病灶)
|
||
if (resultData.ExixtsNETargetLesion)
|
||
{
|
||
// 靶病灶疗效为 NE
|
||
result = TargetAssessment.NE;
|
||
}
|
||
//if (最低点SOD > 0)
|
||
if (resultData.LowSod > 0)
|
||
{
|
||
// if(比整体访视期间最低点SOD增加≥20 % 且与整个访视期间最低点相比增加的值≥5 mm)
|
||
if (resultData.LowSODPercentBigger20 && resultData.LowSODChangeBigger5)
|
||
{
|
||
// 靶病灶疗效为 PD
|
||
result = TargetAssessment.PD;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//进入该分支最低点SOD=0
|
||
// if (当前访视SOD > 0 且与整个访视期间最低点相比增加的值≥5 mm)
|
||
if (resultData.PresentSod > 0 && resultData.LowSODChangeBigger5)
|
||
{
|
||
// 靶病灶疗效为PD
|
||
result = TargetAssessment.PD;
|
||
}
|
||
}
|
||
//if(上次访视点评估是CR)
|
||
if (resultData.LastTargetLesionEvaluate.EqEnum(TargetAssessment.CR))
|
||
{
|
||
//if (当前访视点淋巴结病灶,至少一个淋巴结靶病灶短径≥10 mm 并且该淋巴结靶病灶短径绝对增加值≥5 mm)
|
||
// 换句话说 就是 短径≥10 的病灶 和 短径增加值≥5的病灶 的交集数量大于0
|
||
if (resultData.ShortBigger10Indexs.Intersect(resultData.AddFiveIndexs).ToList().Count() > 0)
|
||
{
|
||
//靶病灶疗效为 PD
|
||
result = TargetAssessment.PD;
|
||
}
|
||
//if (当前访视点非淋巴结病灶至少一个非淋巴结靶病灶的长径>0 mm。)
|
||
if (resultData.CurrentMajoreBigger0)
|
||
{
|
||
//靶病灶疗效为 PD
|
||
result = TargetAssessment.PD;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#region 之前的逻辑 备注
|
||
//if (resultData.LastTargetLesionEvaluate.EqEnum(TargetAssessment.CR))
|
||
//{
|
||
// if (resultData.ExixtsNETargetLesion)
|
||
// {
|
||
// result = TargetAssessment.NE;
|
||
// }
|
||
// if (resultData.CurrenShortBigger10 && resultData.IsAddFive)
|
||
// {
|
||
// result = TargetAssessment.PD;
|
||
// }
|
||
// if (resultData.CurrentMajoreBigger0)
|
||
// {
|
||
// result = TargetAssessment.PD;
|
||
// }
|
||
//}
|
||
|
||
//else
|
||
//{
|
||
// if (resultData.LowSod != 0 && resultData.LowPercentBigger20 && resultData.LowChangeBigger5)
|
||
// {
|
||
// result = TargetAssessment.PD;
|
||
// }
|
||
// else
|
||
// {
|
||
// if (resultData.ExixtsNETargetLesion)
|
||
// {
|
||
// result = TargetAssessment.NE;
|
||
// }
|
||
// else
|
||
// {
|
||
// if (resultData.SODPercentBigger30)
|
||
// {
|
||
// if (resultData.LowPercentLess20 || resultData.LowChangeLess5)
|
||
// {
|
||
// result = TargetAssessment.PR;
|
||
// }
|
||
|
||
// if (resultData.SumOfDiameter == 0 && resultData.DiameterLessThan10 && resultData.NonTargetStateIsLoss)
|
||
// {
|
||
// result = TargetAssessment.CR;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
|
||
//}
|
||
#endregion
|
||
|
||
|
||
}
|
||
|
||
return result.GetEnumInt();
|
||
}
|
||
#endregion
|
||
|
||
#region 获取非靶病灶评估
|
||
|
||
/// <summary>
|
||
/// 获取非靶病灶评估
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetNoTargetLesionEvaluate(ReadingCalculateDto inDto)
|
||
{
|
||
|
||
NoTargetAssessment result = NoTargetAssessment.NN;
|
||
|
||
if (inDto.IsBaseLine)
|
||
{
|
||
return NoTargetAssessment.NA.GetEnumInt();
|
||
}
|
||
|
||
var tableRows = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.NonTargetLesions).SelectMany(x => x.TableRowInfoList).ToList();
|
||
|
||
var tableQuestions = tableRows.SelectMany(x => x.TableQuestionList).ToList();
|
||
|
||
//任意单个病灶 / 病灶组评估为“显著增大”
|
||
if (tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer.EqEnum(NoTargetState.Increase)))
|
||
{
|
||
result = NoTargetAssessment.PD;
|
||
}
|
||
// 任意单个病灶/病灶组评估为“无法评估”并且没有“显著增大”
|
||
else if (tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer.EqEnum(NoTargetState.UnableEvaluate)) &&
|
||
!tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer.EqEnum(NoTargetState.Increase))
|
||
)
|
||
{
|
||
result = NoTargetAssessment.NE;
|
||
}
|
||
// 所有单个病灶/病灶组评估为”存在”或者有些评估为“消失”有些评估为“存在”,且没有“显著增大”和“无法评估”的病灶
|
||
else if (tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer.EqEnum(NoTargetState.Exist))
|
||
&& !tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && (x.Answer.EqEnum(NoTargetState.Increase) || x.Answer.EqEnum(NoTargetState.UnableEvaluate)))
|
||
|
||
)
|
||
{
|
||
result = NoTargetAssessment.NN;
|
||
}
|
||
//所有单个病灶/病灶组状态评估状态为“消失”
|
||
else if (tableQuestions.Count(x => x.QuestionMark == QuestionMark.State && x.Answer.EqEnum(NoTargetState.Loss)) == tableQuestions.Count(x => x.QuestionMark == QuestionMark.State) && tableQuestions.Count(x => x.QuestionMark == QuestionMark.State) > 0)
|
||
{
|
||
result = NoTargetAssessment.CR;
|
||
}
|
||
|
||
// 基线时没有非靶病灶
|
||
else if (tableQuestions.Count() == 0)
|
||
{
|
||
result = NoTargetAssessment.ND;
|
||
}
|
||
else
|
||
{
|
||
return string.Empty;
|
||
}
|
||
|
||
return result.GetEnumInt();
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 获取新病灶评估
|
||
/// <summary>
|
||
/// 获取新病灶评估
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> GetNewLesionEvaluate(ReadingCalculateDto inDto)
|
||
{
|
||
|
||
NewLesionAssessment result = NewLesionAssessment.No;
|
||
if (inDto.IsBaseLine)
|
||
{
|
||
return NewLesionAssessment.NA.GetEnumInt();
|
||
}
|
||
|
||
var tableRows = inDto.QuestionInfo.Where(x => x.LesionType == LesionType.NewLesions).SelectMany(x => x.TableRowInfoList).ToList();
|
||
|
||
var tableQuestions = tableRows.SelectMany(x => x.TableQuestionList).ToList();
|
||
|
||
|
||
|
||
// 当前访视存在至少一个明确新病灶
|
||
if (tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer.EqEnum(NewLesionState.Exist)))
|
||
{
|
||
result = NewLesionAssessment.Yes;
|
||
}
|
||
//只要有任何一个新病灶状态为“无法评估”
|
||
else if (tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer.EqEnum(NewLesionState.UnableEvaluate)))
|
||
{
|
||
result = NewLesionAssessment.NE;
|
||
}
|
||
//当前访视不存在明确新病灶且存在至少一个疑似新病灶
|
||
else if (!tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer.EqEnum(NewLesionState.Exist)) &&
|
||
tableQuestions.Any(x => x.QuestionMark == QuestionMark.State && x.Answer.EqEnum(NewLesionState.Suspected))
|
||
)
|
||
{
|
||
result = NewLesionAssessment.Suspected;
|
||
}
|
||
|
||
|
||
else
|
||
{
|
||
result = NewLesionAssessment.No;
|
||
}
|
||
return result.GetEnumInt();
|
||
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
}
|
||
|
||
}
|