@@ -22,7 +22,9 @@ namespace IRaCIS.Core.Application.Service
{
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 ;
@@ -30,18 +32,204 @@ namespace IRaCIS.Core.Application.Service
public ReadingCalculateService (
IRepository < ReadingTableQuestionAnswer > readingTableQuestionAnswerRepository ,
IRepository < VisitTask > visitTaskRepository ,
IRepository < ReadingTableQuestionTrial > readingTableQuestionTrialRepository ,
IRepository < ReadingQuestionCriterionTrial > readingQuestionCriterionTrialRepository ,
IRepository < ReadingTableQuestionTrial > readingTableQuestionTrialRepository ,
IRepository < ReadingQuestionTrial > readingQuestionTrialRepository ,
IRepository < SubjectVisit > subjectVisitRepository ,
IRepository < TumorAssessment > tumorAssessmentRepository ,
IRepository < ReadingTaskQuestionAnswer > ReadingTaskQuestionAnswerRepository
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 ;
this . _readingTaskQuestionAnswerRepository = readingTaskQuestionAnswerRepository ;
}
/// <summary>
/// 计算任务
/// </summary>
/// <param name="inDto"></param>
/// <returns></returns>
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 ,
TrialId = visitTask . TrialId ,
} ;
await ReadingCalculate ( readingData ) ;
}
/// <summary>
/// 自动计算
/// </summary>
/// <param name="inDto"></param>
/// <returns></returns>
public async Task ReadingCalculate ( ReadingCalculateDto inDto )
{
var needAddList = new List < ReadingTaskQuestionAnswer > ( ) ;
foreach ( var item in inDto . QuestionInfo )
{
switch ( item . QuestionType )
{
// 靶病灶径线之和(SOD)
case QuestionType . SOD :
needAddList . Add ( new ReadingTaskQuestionAnswer ( )
{
Answer = ( await GetSODData ( inDto ) ) . ToString ( ) ,
ReadingQuestionTrialId = item . QuestionId ,
} ) ;
break ;
// 非淋巴结靶病灶长径之和
case QuestionType . SumOfDiameter :
needAddList . Add ( new ReadingTaskQuestionAnswer ( )
{
Answer = ( await GetSumOfDiameter ( inDto ) ) . ToString ( ) ,
ReadingQuestionTrialId = item . QuestionId ,
} ) ;
break ;
// 与基线SOD相比变化量(mm)
case QuestionType . SODChange :
needAddList . Add ( new ReadingTaskQuestionAnswer ( )
{
Answer = ( await GetSODChange ( inDto ) ) . ToString ( ) ,
ReadingQuestionTrialId = item . QuestionId ,
} ) ;
break ;
// 与基线访视相比SOD变化百分比
case QuestionType . SODPercent :
needAddList . Add ( new ReadingTaskQuestionAnswer ( )
{
Answer = ( await GetSODPercent ( inDto ) ) . ToString ( ) ,
ReadingQuestionTrialId = item . QuestionId ,
} ) ;
break ;
// 与整个访视期间最低点相比增加的值(mm) 其他任务需要改
case QuestionType . LowestIncrease :
needAddList . Add ( new ReadingTaskQuestionAnswer ( )
{
Answer = ( await GetLowestIncrease ( inDto ) ) . ToString ( ) ,
ReadingQuestionTrialId = item . QuestionId ,
} ) ;
break ;
// 与整个访视期间最低点相比增加的百分比 其他任务需要改
case QuestionType . LowPercent :
needAddList . Add ( new ReadingTaskQuestionAnswer ( )
{
Answer = ( await GetLowPercent ( inDto ) ) . ToString ( ) ,
ReadingQuestionTrialId = item . QuestionId ,
} ) ;
break ;
// 整个访视期间最低点访视名称 其他任务需要改
case QuestionType . LowVisit :
needAddList . Add ( new ReadingTaskQuestionAnswer ( )
{
Answer = ( await GetLowVisit ( inDto ) ) . ToString ( ) ,
ReadingQuestionTrialId = item . QuestionId ,
} ) ;
break ;
// 是否存在非淋巴结靶病灶
case QuestionType . IsLymphTarget :
needAddList . Add ( new ReadingTaskQuestionAnswer ( )
{
Answer = await GetIsLymphTarget ( inDto ) ,
ReadingQuestionTrialId = item . QuestionId ,
} ) ;
break ;
// 是否存在淋巴结靶病灶且该病灶比上一访视短径增加5MM以上
case QuestionType . IsAddFive :
needAddList . Add ( new ReadingTaskQuestionAnswer ( )
{
Answer = await GetIsAddFive ( inDto ) ,
ReadingQuestionTrialId = item . QuestionId ,
} ) ;
break ;
// 被评估为NE的单个靶病灶
case QuestionType . NETarget :
needAddList . Add ( new ReadingTaskQuestionAnswer ( )
{
Answer = await GetNETarget ( inDto ) ,
ReadingQuestionTrialId = item . QuestionId ,
} ) ;
break ;
// 整体肿瘤评估
case QuestionType . Tumor :
needAddList . Add ( new ReadingTaskQuestionAnswer ( )
{
Answer = await GetTumor ( inDto ) ,
ReadingQuestionTrialId = item . QuestionId ,
} ) ;
break ;
}
}
var questionIds = needAddList . Select ( x = > x . ReadingQuestionTrialId ) . ToList ( ) ;
await _readingTaskQuestionAnswerRepository . BatchDeleteNoTrackingAsync ( x = > questionIds . Contains ( x . ReadingQuestionTrialId ) & & x . VisitTaskId = = inDto . VisitTaskId ) ;
needAddList . ForEach ( x = >
{
x . SubjectId = inDto . SubjectId ;
x . ReadingQuestionCriterionTrialId = inDto . CriterionId ;
x . VisitTaskId = inDto . VisitTaskId ;
x . TrialId = inDto . TrialId ;
x . SubjectId = inDto . SubjectId ;
} ) ;
await _readingTaskQuestionAnswerRepository . AddRangeAsync ( needAddList ) ;
await _readingTaskQuestionAnswerRepository . SaveChangesAsync ( ) ;
}
@@ -63,13 +251,13 @@ namespace IRaCIS.Core.Application.Service
foreach ( var item in tableQuestion )
{
if ( item . TableQuestionList . Any ( x = > x . QuestionMark = = QuestionMark . IsLymph & & x . Answer = = "是" ) )
if ( item . TableQuestionList . Any ( x = > x . QuestionMark = = QuestionMark . IsLymph & & ( x . Answer = = "是" | | x . Answer . ToLower ( ) = = "true" . ToLower ( ) ) ) )
{
// 淋巴结的短径
result + = decimal . Parse ( item . TableQuestionList . Where ( x = > x . QuestionMark = = QuestionMark . ShortAxis ) . Select ( x = > x . Answer ) . FirstOrDefault ( ) ? ? "0" ) ;
}
if ( item . TableQuestionList . Any ( x = > x . QuestionMark = = QuestionMark . IsLymph & & x . Answer = = "否" ) )
if ( item . TableQuestionList . Any ( x = > x . QuestionMark = = QuestionMark . IsLymph & & ( x . Answer = = "是" | | x . Answer . ToLower ( ) = = "true" . ToLower ( ) ) ) )
{
// 非淋巴结的长径
result + = decimal . Parse ( item . TableQuestionList . Where ( x = > x . QuestionMark = = QuestionMark . MajorAxis ) . Select ( x = > x . Answer ) . FirstOrDefault ( ) ? ? "0" ) ;
@@ -97,7 +285,7 @@ namespace IRaCIS.Core.Application.Service
foreach ( var item in tableQuestion )
{
if ( item . TableQuestionList . Any ( x = > x . QuestionMark = = QuestionMark . IsLymph & & x . Answer = = "否 " ) )
if ( item . TableQuestionList . Any ( x = > x . QuestionMark = = QuestionMark . IsLymph & & ( x . Answer = = "是 " | | x . Answer . ToLower ( ) = = "false" . ToLower ( ) ) ) )
{
// 非淋巴结的长径
result + = decimal . Parse ( item . TableQuestionList . Where ( x = > x . QuestionMark = = QuestionMark . MajorAxis ) . Select ( x = > x . Answer ) . FirstOrDefault ( ) ? ? "0" ) ;
@@ -216,7 +404,7 @@ namespace IRaCIS.Core.Application.Service
foreach ( var item in tableQuestion )
{
if ( item . TableQuestionList . Any ( x = > x . QuestionMark = = QuestionMark . IsLymph & & x . Answer = = "是" ) )
if ( item . TableQuestionList . Any ( x = > x . QuestionMark = = QuestionMark . IsLymph & & ( x . Answer = = "是" | | x . Answer . ToLower ( ) = = "true" . ToLower ( ) ) ) )
{
return "是" ;
}
@@ -232,14 +420,14 @@ namespace IRaCIS.Core.Application.Service
/// </summary>
/// <param name="inDto"></param>
/// <returns></returns>
public async Task < bool > GetIsAddFive ( ReadingCalculateDto inDto )
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 = = "是" ) . Select ( x = > x . RowIndex ) . Distinct ( ) . OrderBy ( x = > x ) . ToList ( ) ;
var rowIndexs = lastQuestionAsnwer . Where ( x = > x . ReadingTableQuestionTrial . QuestionMark = = QuestionMark . IsLymph & & ( x . Answer = = "是" | | x . Answer . ToLower ( ) = = "true" . ToLower ( ) ) ) . Select ( x = > x . RowIndex ) . Distinct ( ) . OrderBy ( x = > x ) . ToList ( ) ;
var thisQuestionAsnwer = inDto . QuestionInfo . Where ( x = > x . LesionType = = LesionType . TargetLesion ) . SelectMany ( x = > x . TableRowInfoList ) . ToList ( ) ;
@@ -257,7 +445,7 @@ namespace IRaCIS.Core.Application.Service
}
}
return isExists ;
return isExists ? "是" : "否" ;
}
#endregion