diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingTaskQuestionService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingTaskQuestionService.cs index 1af3c7979..e7d0f29e6 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingTaskQuestionService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingTaskQuestionService.cs @@ -47,33 +47,78 @@ namespace IRaCIS.Application.Services /// /// [HttpPost] - public async Task<(GetReadingTableQuestionOutDto, object)> GetTrialReadingQuestion(GetTrialReadingQuestionInDto inDto) + public async Task<(GetTrialReadingQuestionPageDto, object)> GetTrialReadingQuestion(GetTrialReadingQuestionInDto inDto) { + if (inDto.VisitTaskId != null) + { + //await AddDefaultValueToTask(inDto.VisitTaskId.Value); + } + + var result = new GetTrialReadingQuestionPageDto(); var readingTaskState = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Select(x => x.ReadingTaskState).FirstOrDefaultAsync(); + + + var qusetionList = await GetReadingAnswerView(inDto.ReadingQuestionCriterionTrialId, inDto.VisitTaskId); + var formType = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.ReadingQuestionCriterionTrialId).Select(x => x.FormType).FirstOrDefaultAsync(); + var groupList = new List(); + + var qusetionIds = qusetionList.Select(x => x.Id).ToList(); + var tableQuestionList = await _readingTableQuestionTrialRepository.Where(x => qusetionIds.Contains(x.ReadingQuestionId)) + .ProjectTo(_mapper.ConfigurationProvider,x=>new { + + isEn_Us=_userInfo.IsEn_Us + + }).OrderBy(x => x.ShowOrder).ToListAsync(); if (inDto.FormType != null) { formType = inDto.FormType.Value; } - var tableAnswers = await _readingTableQuestionAnswerRepository - .ProjectTo(_mapper.ConfigurationProvider) - .Where(x => x.VisitTaskId == inDto.VisitTaskId).ToListAsync(); - var tableAnsweRowInfos = await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); - - var organIds = tableAnsweRowInfos.Where(x => x.OrganInfoId != null).Select(x => x.OrganInfoId).Distinct().ToList(); - var organList = await _organInfoRepository.Where(x => organIds.Contains(x.Id)).ToListAsync(); - var result=await GetReadingTableQuestion(new GetReadingTableQuestionOrAnswerInDto() + if (formType == FormType.MultiplePage) { + qusetionList = qusetionList.Where(x => x.ReadingCriterionPageId != null).ToList(); + var readingCriterionPageIds = qusetionList.OrderBy(x => x.PageShowOrder).Select(x => x.ReadingCriterionPageId).Distinct().ToList(); + foreach (var item in readingCriterionPageIds) + { + var newPageQusetionList = qusetionList.Where(x => x.ReadingCriterionPageId == item).ToList(); + var firstData = newPageQusetionList.FirstOrDefault(); + var page = new GetTrialReadingQuestionOutDto() + { + PageName = firstData!.PageName, + IsPage = true, + IsPublicPage = firstData.IsPublicPage, + }; - TrialReadingCriterionId = inDto.ReadingQuestionCriterionTrialId, - TaskId = inDto.VisitTaskId, - TableAnswers = tableAnswers, - TableAnsweRowInfos = tableAnsweRowInfos, - OrganInfos = organList, - QuestionClassify = null, + var pageGroupList = newPageQusetionList.Where(x => x.Type == ReadingQestionType.Group || (x.ParentId == null && x.GroupName.IsNullOrEmpty())).ToList(); + pageGroupList.ForEach(x => + { + this.FindChildQuestion(x, newPageQusetionList, tableQuestionList); + }); - }); + page.Childrens = pageGroupList.Where(x => !(x.Type == ReadingQestionType.Group && x.Childrens.Count() == 0)).ToList(); + groupList.Add(page); + } + + result.PublicPage = groupList.Where(x => x.IsPublicPage!.Value).ToList(); + result.MultiPage = groupList.Where(x => !x.IsPublicPage!.Value).ToList(); + } + else + { + qusetionList = qusetionList.Where(x => x.ReadingCriterionPageId == null).ToList(); + + groupList = qusetionList.Where(x => x.Type == ReadingQestionType.Group || (x.ParentId == null && x.GroupId==null)).ToList(); + groupList.ForEach(x => + { + this.FindChildQuestion(x, qusetionList, tableQuestionList); + }); + + groupList = groupList.Where(x => !(x.Type == ReadingQestionType.Group && x.Childrens.Count() == 0)).ToList(); + + result.SinglePage = groupList; + + + } return (result, new