diff --git a/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs b/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs index 006a6ee74..4208d46a8 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadModuleService.cs @@ -378,7 +378,9 @@ namespace IRaCIS.Application.Services public async Task> GetSubjectReadVisitList(GetSubjectReadVisitsInDto inDto) { - var maxReadVisitNum = await _readModuleRepository.Where(x => x.SubjectId == inDto.SubjectId && x.ModuleType != ModuleTypeEnum.Global).MaxAsync(x => x.VisitNum); + var maxReadVisit = await _readModuleRepository.Where(x => x.SubjectId == inDto.SubjectId&&x.ReadingSetType==inDto.ReadingSetType && x.ModuleType != ModuleTypeEnum.Global).OrderByDescending(x=>x.VisitNum).FirstOrDefaultAsync(); + + var maxReadVisitNum= maxReadVisit==null?0:maxReadVisit.VisitNum; var visitQuery = _subjectVisitRepository.Where(x => x.SubjectId == inDto.SubjectId && x.LatestScanDate != null); @@ -386,7 +388,7 @@ namespace IRaCIS.Application.Services var readModulequery = _readModuleRepository.AsQueryable(); - var resultlist= await visitQuery.WhereIf(finalVisitNum != null&& finalVisitNum!=0, x => x.VisitNum < finalVisitNum) + var resultlist= await visitQuery.WhereIf(finalVisitNum != null&& finalVisitNum!=0, x => x.VisitNum <= finalVisitNum) .Where(x=>x.VisitNum>= maxReadVisitNum) .Where(x => readModulequery.Where(y => y.SubjectVisitId == x.Id && y.ReadingSetType == inDto.ReadingSetType).Count() == 0).OrderBy(x => finalVisitNum) .Select(x => new GetSubjectReadVisitsOutDto()