diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 97d8edbb8..5c7e4e102 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -3974,6 +3974,16 @@ + + + 自定义病灶判断是否是同一个病灶 除了根据器官判断还需要根据复制前值的答案是否相等 + + + + + + + 标准和服务对应 @@ -10232,6 +10242,11 @@ 问题分类 + + + 问题分类 + + 评估结果 @@ -15015,6 +15030,13 @@ + + + 获取单个表格问题及答案 过滤问题 + + + + 获取自定义问题以及答案 diff --git a/IRaCIS.Core.Application/Service/ReadingCalculate/General/GeneralCalculateService.cs b/IRaCIS.Core.Application/Service/ReadingCalculate/General/GeneralCalculateService.cs index 831b93073..4f6fc942f 100644 --- a/IRaCIS.Core.Application/Service/ReadingCalculate/General/GeneralCalculateService.cs +++ b/IRaCIS.Core.Application/Service/ReadingCalculate/General/GeneralCalculateService.cs @@ -258,7 +258,8 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate if (historyTaskId != Guid.Empty) { - var historyTableRowList = await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == historyTaskId).ToListAsync(); + var criterionType = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == taskinfo.TrialReadingCriterionId).Select(x => x.CriterionType).FirstOrDefaultAsync(); + var historyTableRowList = await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == historyTaskId).Include(x => x.ReadingQuestionTrial).ToListAsync(); var historyTableAnswerList = await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == historyTaskId).ToListAsync(); @@ -278,7 +279,11 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate { continue; } - var historyRow = historyTableRowList.Where(x => + + // 自定义标准(SelfDefine)的病灶IdentityRowId不可靠 除了根据器官判断还需要根据复制前值的答案是否相等 优先用答案匹配 + var historyRow = historyTableRowList + .WhereIf(criterionType == CriterionType.SelfDefine,x => IsSameCustomRowAnswer(item, x, tableAnswerList, historyTableAnswerList)) + .Where(x => x.QuestionId == item.QuestionId && x.RowIndex == item.RowIndex && x.IdentityRowId == item.IdentityRowId && @@ -311,6 +316,77 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate } } + // 将失效任务在当前访视新增的病灶添加过来 + // 例如现在是访视三,把失效任务访视三中在访视三新增的病灶(FristAddTaskId == historyTaskId)添加过来 + var historyAddRowList = historyTableRowList.Where(x => x.FristAddTaskId == historyTaskId && x.SplitOrMergeType != SplitOrMergeType.Merged).ToList(); + var historyRowIdSet = historyTableRowList.Select(x => x.Id).ToHashSet(); + + foreach (var historyRow in historyAddRowList) + { + // 判断当前任务是否已经存在该病灶 失效任务新增的病灶IdentityRowId是新建的不会与当前任务重复 + bool isExist = tableRowList.Any(x => x.QuestionId == historyRow.QuestionId && x.IdentityRowId != null && x.IdentityRowId == historyRow.IdentityRowId); + + if (isExist) + { + continue; + } + + // 通过CopyTableAnswerRowInfo映射复制行字段 + var copyRow = _mapper.Map(historyRow); + copyRow.Id = NewId.NextGuid(); + copyRow.VisitTaskId = taskinfo.Id; + copyRow.MeasureData = historyRow.MeasureData.Replace(historyTaskId.ToString(), taskinfo.Id.ToString()); + copyRow.IsCurrentTaskAdd = true; + copyRow.FristAddTaskId = taskinfo.Id; + + var newRow = _mapper.Map(copyRow); + // CopyTableAnswerRowInfo没有Other和PET/CT融合字段 单独复制 + newRow.OtherMeasureData = historyRow.OtherMeasureData.Replace(historyTaskId.ToString(), taskinfo.Id.ToString()); + newRow.OtherInstanceId = historyRow.OtherInstanceId; + newRow.OtherSeriesId = historyRow.OtherSeriesId; + newRow.OtherStudyId = historyRow.OtherStudyId; + newRow.OtherMarkTool = historyRow.OtherMarkTool; + newRow.OtherPicturePath = historyRow.OtherPicturePath; + newRow.OtherNumberOfFrames = historyRow.OtherNumberOfFrames; + newRow.PTSeriesId = historyRow.PTSeriesId; + newRow.CTSeriesId = historyRow.CTSeriesId; + + tableRowList.Add(newRow); + if (!lesionRelationship.ContainsKey(historyRow.Id)) + { + lesionRelationship.Add(historyRow.Id, newRow.Id); + } + + // 复制该病灶的表格答案 + historyTableAnswerList.Where(x => x.RowId == historyRow.Id).ForEach(x => + { + tableAnswerList.Add(new ReadingTableQuestionAnswer() + { + Id = NewId.NextGuid(), + Answer = x.Answer, + QuestionId = x.QuestionId, + VisitTaskId = taskinfo.Id, + TrialId = x.TrialId, + RowIndex = x.RowIndex, + TableQuestionId = x.TableQuestionId, + RowId = newRow.Id, + }); + }); + } + + // 处理新增病灶的分割合并关系 新增病灶已经在tableRowList里 通过SplitRowId/MergeRowId是否指向失效任务的行来识别 + tableRowList.ForEach(x => + { + if (x.SplitRowId != null && historyRowIdSet.Contains(x.SplitRowId.Value)) + { + x.SplitRowId = lesionRelationship.ContainsKey(x.SplitRowId.Value) ? lesionRelationship[x.SplitRowId.Value] : (Guid?)null; + } + if (x.MergeRowId != null && historyRowIdSet.Contains(x.MergeRowId.Value)) + { + x.MergeRowId = lesionRelationship.ContainsKey(x.MergeRowId.Value) ? lesionRelationship[x.MergeRowId.Value] : (Guid?)null; + } + }); + // 复制外层问题 answerList.ForEach(x => { @@ -920,5 +996,31 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate }); return taskInfoList; } + + /// + /// 自定义病灶判断是否是同一个病灶 除了根据器官判断还需要根据复制前值的答案是否相等 + /// + /// + /// + /// + /// + /// + private bool IsSameCustomRowAnswer(ReadingTableAnswerRowInfo currentRow, ReadingTableAnswerRowInfo historyRow, + List currentAnswerList, List historyAnswerList) + { + // 复制前值的答案:即当前任务从上一次有效访视复制过来的答案,自定义阅片只有IsCopy的问题会复制值,非空的就是复制前值 + var currentAnswers = currentAnswerList.Where(x => x.RowId == currentRow.Id && !x.Answer.IsNullOrEmpty()) + .GroupBy(x => x.TableQuestionId).ToDictionary(x => x.Key, x => x.First().Answer); + var historyAnswers = historyAnswerList.Where(x => x.RowId == historyRow.Id && !x.Answer.IsNullOrEmpty()) + .GroupBy(x => x.TableQuestionId).ToDictionary(x => x.Key, x => x.First().Answer); + + // 没有复制前值可以比较时 只根据器官判断 + if (currentAnswers.Count == 0) + { + return true; + } + + return currentAnswers.All(x => historyAnswers.TryGetValue(x.Key, out var historyAnswer) && historyAnswer == x.Value); + } } }