diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingImageTaskService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingImageTaskService.cs index d366160b..053e3986 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingImageTaskService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingImageTaskService.cs @@ -1290,42 +1290,80 @@ namespace IRaCIS.Application.Services QuestionMark.Organ, }; + + Dictionary errorMsgDic = new Dictionary() + { + {CriterionType.RECIST1Pointt1, _localizer["ReadingImage_Maxlesion", item.MaxRowCount.Value]}, + }; + string msg = string.Empty; foreach (var item in tableQuestions) { var answer = inDto.AnswerList.Where(x => x.TableQuestionId == item.Id).Select(x => x.Answer).FirstOrDefault(); if (!answer.IsNullOrEmpty()) { var rowCount = 0; - if (questionMarks.Contains(item.QuestionMark)) + if ((item.QuestionMark == QuestionMark.Part|| item.QuestionMark == QuestionMark.Organ) &&inDto.OrganInfoId!=null) { - rowCount = await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.QuestionId == inDto.QuestionId && ((x.RowIndex % 1) == 0) && x.OrganInfoId == inDto.OrganInfoId && x.OrganInfoId != null && x.RowIndex != inDto.RowIndex).CountAsync(); + var organIds= await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.QuestionId == inDto.QuestionId && ((x.RowIndex % 1) == 0) && x.OrganInfoId != null && x.RowIndex != inDto.RowIndex).Select(x=>x.OrganInfoId).ToListAsync(); + organIds.Add(inDto.OrganInfoId); + + var orginInfos = await _organInfoRepository.Where(x => organIds.Contains(x.Id)).ToListAsync(); + + if (item.QuestionMark == QuestionMark.Part) + { + rowCount = orginInfos.Select(x => x.Part).Distinct().Count(); + } + else + { + rowCount = orginInfos.Select(x => x.TULOC).Distinct().Count(); + } + + if (rowCount > item.MaxRowCount.Value) + { + if (rowCount > item.MaxRowCount.Value ) + { + + + try + { + msg = errorMsgDic[criterionInfo.CriterionType]; + } + catch (Exception) + { + + msg = _localizer["ReadingImage_Maximum", item.QuestionName.LanguageName(item.QuestionEnName, _userInfo.IsEn_Us), item.MaxRowCount.Value, item.MaxRowCount.Value]; + } + + throw new BusinessValidationFailedException(msg); + } + } + } + else { rowCount = await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.TableQuestionId == item.Id && ((x.RowIndex % 1) == 0) && x.Answer == answer && x.RowIndex != inDto.RowIndex).CountAsync(); + + if (rowCount > item.MaxRowCount.Value - 1) + { + + + try + { + msg = errorMsgDic[criterionInfo.CriterionType]; + } + catch (Exception) + { + + msg = _localizer["ReadingImage_Maximum", item.QuestionName.LanguageName(item.QuestionEnName, _userInfo.IsEn_Us), item.MaxRowCount.Value, rowCount]; + } + + throw new BusinessValidationFailedException(msg); + } } - if (rowCount > item.MaxRowCount.Value - 1) - { - - Dictionary errorMsgDic = new Dictionary() - { - {CriterionType.RECIST1Pointt1, _localizer["ReadingImage_Maxlesion", item.MaxRowCount.Value]}, - }; - string msg = string.Empty; - try - { - msg = errorMsgDic[criterionInfo.CriterionType]; - } - catch (Exception) - { - - msg = _localizer["ReadingImage_Maximum", item.QuestionName.LanguageName(item.QuestionEnName, _userInfo.IsEn_Us), item.MaxRowCount.Value, rowCount] ; - } - - throw new BusinessValidationFailedException(msg); - } + } } }