|
|
|
@@ -109,67 +109,35 @@ namespace IRaCIS.Application.Services
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<PageOutput<PreviewTheReadingListOutDto>> GetPreviewTheReadingList(PreviewTheReadingListInDto inDto)
|
|
|
|
|
{
|
|
|
|
|
//if (await _readingPeriodPlanRepository.AnyAsync(x => x.ReadingPeriodSetId == inDto.ReadingPeriodSetId))
|
|
|
|
|
//{
|
|
|
|
|
// await _readingPeriodPlanRepository.DeleteFromQueryAsync(x => x.ReadingPeriodSetId == inDto.ReadingPeriodSetId);
|
|
|
|
|
// await _readingPeriodPlanRepository.SaveChangesAsync();
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var readSet = (await _readingPeriodSetRepository.Where(x => x.Id == inDto.ReadingPeriodSetId).Include(x => x.ReadingPeriodSites).FirstOrDefaultAsync()).IfNullThrowException();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var visitQuery = _subjectVisitRepository.Where(x => x.TrialId == inDto.TrialId && x.InPlan&&x.LatestScanDate!=null);
|
|
|
|
|
if (inDto.SiteIds.Count!=0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
visitQuery = visitQuery.Where(x => inDto.SiteIds.Contains(x.SiteId));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//var
|
|
|
|
|
var existsBubjectVisits = await _readModuleRepository.Where(y => y.ReadingSetType == inDto.ReadingSetType && y.TrialId == inDto.TrialId).Select(x => x.SubjectVisitId).ToListAsync();
|
|
|
|
|
visitQuery = visitQuery.Where(x => !existsBubjectVisits.Contains(x.Id))
|
|
|
|
|
var visitQuery = _subjectVisitRepository.Where(x => x.TrialId == inDto.TrialId && x.InPlan&&x.LatestScanDate!=null)
|
|
|
|
|
.WhereIf(inDto.SiteIds.Count != 0, x => inDto.SiteIds.Contains(x.SiteId));
|
|
|
|
|
var existsBubjectVisitsQuery= _readModuleRepository.Where(y => y.ReadingSetType == inDto.ReadingSetType && y.TrialId == inDto.TrialId).Select(x => x.SubjectVisitId);
|
|
|
|
|
visitQuery = visitQuery.Where(x => !existsBubjectVisitsQuery.Contains(x.Id))
|
|
|
|
|
.WhereIf(inDto.ExpirationDate != null, x => x.LatestScanDate <= inDto.ExpirationDate.Value)
|
|
|
|
|
.WhereIf(inDto.ExpirationVisitNum != null, x => x.VisitNum == inDto.ExpirationVisitNum);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var subjectIdlist = await visitQuery.OrderBy(x => x.SubjectId).Select(x => x.SubjectId).Distinct().Skip((inDto.PageIndex - 1) * inDto.PageSize).Take(inDto.PageSize).ToListAsync();
|
|
|
|
|
var totalCount = visitQuery.Select(x => x.SubjectId).Distinct().Count();
|
|
|
|
|
var visitlist= await visitQuery.Include(x=>x.Subject).Include(x=>x.TrialSite).Where(x => subjectIdlist.Contains(x.SubjectId)).ToListAsync();
|
|
|
|
|
var subjectVisits = visitlist.GroupBy(x => x.SubjectId).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
SubjectId = x.Key,
|
|
|
|
|
Visit = x.ToList()
|
|
|
|
|
Visits = x.ToList()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 这地方用分页报错
|
|
|
|
|
//var visitListQuery = visitQuery.GroupBy(x => x.SubjectId).Select(x => new
|
|
|
|
|
//{
|
|
|
|
|
// SubjectId = x.Key,
|
|
|
|
|
// Visit = x.ToList()
|
|
|
|
|
//});
|
|
|
|
|
// var subjectVisits = await visitListQuery.ToPagedListAsync(inDto.PageIndex, inDto.PageSize, inDto.SortField == null ? "SubjectId" : inDto.SortField,
|
|
|
|
|
// inDto.Asc);
|
|
|
|
|
|
|
|
|
|
List<SubjectVisit> visits = new List<SubjectVisit>();
|
|
|
|
|
subjectVisits.ForEach(x =>
|
|
|
|
|
{
|
|
|
|
|
var visit = x.Visit.OrderByDescending(x => x.VisitNum).FirstOrDefault();
|
|
|
|
|
var visit = x.Visits.OrderByDescending(x => x.VisitNum).FirstOrDefault();
|
|
|
|
|
if (visit != null)
|
|
|
|
|
{
|
|
|
|
|
visits.Add(visit);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PageOutput<PreviewTheReadingListOutDto> result = new PageOutput<PreviewTheReadingListOutDto>()
|
|
|
|
|
{
|
|
|
|
|
CurrentPageData = visits
|
|
|
|
|
//Where(x => _readModuleRepository.Where(y => y.ReadingSetType == readSet.ReadingSetType && x.Id == y.SubjectVisitId).Count() == 0)
|
|
|
|
|
.Select(x => new PreviewTheReadingListOutDto
|
|
|
|
|
{
|
|
|
|
|
ExpirationDate = inDto.ExpirationDate,
|
|
|
|
@@ -177,11 +145,9 @@ namespace IRaCIS.Application.Services
|
|
|
|
|
TrialSiteCode = x.TrialSite.TrialSiteCode,
|
|
|
|
|
LatestScanDate = x.LatestScanDate,
|
|
|
|
|
ReadingPeriodName = inDto.ReadingPeriodName,
|
|
|
|
|
//ReadingPeriodSetId = readSet.Id,
|
|
|
|
|
SubjectCode = x.Subject.Code,
|
|
|
|
|
SubjectId = x.SubjectId,
|
|
|
|
|
SubjectVisitName = x.VisitName,
|
|
|
|
|
//Remark= readset.Remark
|
|
|
|
|
}).ToList(),
|
|
|
|
|
PageSize = inDto.PageSize,
|
|
|
|
|
PageIndex = inDto.PageIndex,
|
|
|
|
@@ -238,7 +204,7 @@ namespace IRaCIS.Application.Services
|
|
|
|
|
EffectOfTime=x.ReadingPeriodSet.EffectOfTime,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return await plans.ToPagedListAsync(inDto.PageIndex, inDto.PageSize, inDto.SortField == null ? "SubjectId" : inDto.SortField,
|
|
|
|
|
return await plans.ToPagedListAsync(inDto.PageIndex, inDto.PageSize, inDto.SortField == null ? nameof(PreviewTheReadingListOutDto.SubjectId) : inDto.SortField,
|
|
|
|
|
inDto.Asc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -255,7 +221,7 @@ namespace IRaCIS.Application.Services
|
|
|
|
|
.WhereIf(query.TrialId!=null,x=>x.TrialId==query.TrialId)
|
|
|
|
|
.WhereIf(query.ReadingPeriodName != null, x => x.ReadingPeriodName.Contains(query.ReadingPeriodName))
|
|
|
|
|
.ProjectTo<ReadingPeriodSetView>(_mapper.ConfigurationProvider);
|
|
|
|
|
var pageList= await readQuery.ToPagedListAsync(query.PageIndex, query.PageSize, query.SortField == null ? "CreateTime" : query.SortField,
|
|
|
|
|
var pageList= await readQuery.ToPagedListAsync(query.PageIndex, query.PageSize, query.SortField == null ? nameof(ReadingPeriodSetView.CreateTime) : query.SortField,
|
|
|
|
|
query.Asc);
|
|
|
|
|
|
|
|
|
|
pageList.CurrentPageData.ForEach(x =>
|
|
|
|
@@ -275,9 +241,7 @@ namespace IRaCIS.Application.Services
|
|
|
|
|
[HttpPost("{id:guid}")]
|
|
|
|
|
public async Task<ReadingPeriodSetView> GetReadingPeriodSet(Guid id)
|
|
|
|
|
{
|
|
|
|
|
var data = await _readingPeriodSetRepository.AsQueryable().Include(x => x.ReadingPeriodSites).Where(x => x.Id == id).ProjectTo<ReadingPeriodSetView>(_mapper.ConfigurationProvider).FirstOrDefaultAsync();
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
|
|
return await _readingPeriodSetRepository.AsQueryable().Include(x => x.ReadingPeriodSites).Where(x => x.Id == id).ProjectTo<ReadingPeriodSetView>(_mapper.ConfigurationProvider).FirstOrDefaultAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@@ -288,19 +252,14 @@ namespace IRaCIS.Application.Services
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<List<GetReadingVisitListOutDto>> GetReadingVisitList(GetReadingVisitListInDto inDto)
|
|
|
|
|
{
|
|
|
|
|
var maxVisitnum = await _readingPeriodSetRepository.Where(x => x.TrialId == inDto.TrialId && x.ReadingSetType == inDto.ReadingSetType&&(x.IsTakeEffect== ReadingPeriodStatus.TakeEffect||x.IsTakeEffect==ReadingPeriodStatus.Revocation)).MaxAsync(x => x.ExpirationVisitNum)??0;
|
|
|
|
|
|
|
|
|
|
var thisVisitnum = await _readingPeriodSetRepository.Where(x => x.Id == inDto.ReadingPeriodSetId).Select(x => x.ExpirationVisitNum).FirstOrDefaultAsync() ?? -1;
|
|
|
|
|
|
|
|
|
|
//var visitStageIdList = await _readingPeriodSetRepository.Where(x => x.TrialId == inDto.TrialId && x.Id != inDto.ReadingPeriodSetId&&x.VisitStageId!=null&&x.ReadingSetType==inDto.ReadingSetType).Select(x => x.VisitStageId).ToListAsync();
|
|
|
|
|
List <GetReadingVisitListOutDto> result = await _visitStageRepository.Where(x => x.TrialId == inDto.TrialId ).Where(x=>x.VisitNum== thisVisitnum|| x.VisitNum >= maxVisitnum).Select(x => new GetReadingVisitListOutDto()
|
|
|
|
|
var maxVisitNum = await _readingPeriodSetRepository.Where(x => x.TrialId == inDto.TrialId && x.ReadingSetType == inDto.ReadingSetType&&(x.IsTakeEffect== ReadingPeriodStatus.TakeEffect||x.IsTakeEffect==ReadingPeriodStatus.Revocation)).MaxAsync(x => x.ExpirationVisitNum)??0;
|
|
|
|
|
var thisVisitNum = await _readingPeriodSetRepository.Where(x => x.Id == inDto.ReadingPeriodSetId).Select(x => x.ExpirationVisitNum).FirstOrDefaultAsync() ?? -1;
|
|
|
|
|
List <GetReadingVisitListOutDto> result = await _visitStageRepository.Where(x => x.TrialId == inDto.TrialId ).Where(x=>x.VisitNum== thisVisitNum || x.VisitNum >= maxVisitNum).Select(x => new GetReadingVisitListOutDto()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
VisitName = x.VisitName,
|
|
|
|
|
VisitNum = x.VisitNum,
|
|
|
|
|
VisitStageId = x.Id,
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -319,12 +278,10 @@ namespace IRaCIS.Application.Services
|
|
|
|
|
.Include(x => x.ReadingPeriodSet).Include(x=>x.SubjectVisit).ToList();
|
|
|
|
|
var needAddVisitIds = plans.Select(x => x.SubjectVisitId).ToList();
|
|
|
|
|
var repeatVisitNames = _readModuleRepository.Where(x => x.ReadingSetType == ReadingSetType.ImageReading && needAddVisitIds.Contains(x.SubjectVisitId)).Select(x =>x.Subject.Code+"的"+ x.SubjectVisit.VisitName).ToList();
|
|
|
|
|
|
|
|
|
|
if(repeatVisitNames.Count!=0)
|
|
|
|
|
{
|
|
|
|
|
return ResponseOutput.NotOk($"{string.Join(",", repeatVisitNames)}已经添加过阅片期,无法设置生效");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<ReadModule> readModules = new List<ReadModule>();
|
|
|
|
|
foreach (var item in plans)
|
|
|
|
|
{
|
|
|
|
@@ -370,7 +327,6 @@ namespace IRaCIS.Application.Services
|
|
|
|
|
[HttpDelete("{readingPeriodSetId:guid}")]
|
|
|
|
|
public async Task<IResponseOutput> DeleteReadingPeriodSet(Guid readingPeriodSetId)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var success = await _repository.BatchDeleteAsync<ReadingPeriodSet>(t => t.Id == readingPeriodSetId);
|
|
|
|
|
return ResponseOutput.Result(success);
|
|
|
|
|
}
|
|
|
|
|