diff --git a/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs b/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs index a6c36b728..c121a814b 100644 --- a/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs +++ b/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs @@ -162,7 +162,9 @@ namespace IRaCIS.Core.Application.ViewModel //public String TrialSiteCode { get; set; } = String.Empty; //public Guid TrialId { get; set; } - public Guid? SubjectId { get; set; } + public int Index { get; set; } = 0; + + public Guid SubjectId { get; set; } public string SubjectCode { get; set; } = String.Empty; public bool IsUrgent => UnReadTaskList.Any(t => t.IsUrgent); @@ -180,7 +182,15 @@ namespace IRaCIS.Core.Application.ViewModel { public Guid Id { get; set; } + public ReadingCategory ReadingCategory { get; set; } public bool IsUrgent { get; set; } + + public decimal VisitNum { get; set; } + + public string TaskBlindName { get; set; } + + + public Guid? VisistId { get; set; } public DateTime? SuggesteFinishedTime { get; set; } } diff --git a/IRaCIS.Core.Application/Service/Allocation/Interface/IVisitTaskService.cs b/IRaCIS.Core.Application/Service/Allocation/Interface/IVisitTaskService.cs index db79af969..58fc73fc1 100644 --- a/IRaCIS.Core.Application/Service/Allocation/Interface/IVisitTaskService.cs +++ b/IRaCIS.Core.Application/Service/Allocation/Interface/IVisitTaskService.cs @@ -15,5 +15,7 @@ namespace IRaCIS.Core.Application.Service Task ApplyReReading(ApplyReReadingCommand applyReReadingCommand); Task ConfirmReReading(ConfirmReReadingCommand agreeReReadingCommand, [FromServices] IVisitTaskHelpeService _visitTaskCommonService); + + (int, IOrderedQueryable) GetOrderReadingIQueryable(Guid trialId); } } \ No newline at end of file diff --git a/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs b/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs index 37a0686d9..68a168ca2 100644 --- a/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs +++ b/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs @@ -987,7 +987,7 @@ namespace IRaCIS.Core.Application.Service.Allocation /// /// /// - public (int,IOrderedQueryable?) GetOrderReadingIQueryable(Guid trialId) + public (int,IOrderedQueryable) GetOrderReadingIQueryable(Guid trialId) { var visitGroupQuery = _visitTaskRepository.Where(x => x.TrialId == trialId && x.DoctorUserId == _userInfo.Id) .Where(x => !x.Subject.IsDeleted) @@ -1001,8 +1001,16 @@ namespace IRaCIS.Core.Application.Service.Allocation UnReadTaskCount = x.Where(y => y.ReReadingApplyState != ReReadingApplyState.HaveApplyed).Count(), ExistReadingApply = x.Any(y => y.ReReadingApplyState == ReReadingApplyState.HaveApplyed), UnReadTaskList = x.Where(y => y.ReReadingApplyState != ReReadingApplyState.HaveApplyed).OrderBy(x=>x.VisitTaskNum) - .Select(u => new IRUnreadTaskView() { Id = u.Id, IsUrgent = u.IsUrgent, SuggesteFinishedTime = u.SuggesteFinishedTime }).ToList(), - }).Where(x => x.UnReadTaskCount > 0).OrderBy(x => x.SubjectId); + .Select(u => new IRUnreadTaskView() { + Id = u.Id, + IsUrgent = u.IsUrgent, + VisitNum=u.VisitTaskNum, + TaskBlindName =u.TaskBlindName, + VisistId=u.SourceSubjectVisitId, + SuggesteFinishedTime = u.SuggesteFinishedTime, + ReadingCategory=u.ReadingCategory, + }).ToList(), + }).OrderBy(x => x.SubjectId); diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs index 8ac9c47d4..da538361c 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingImageTaskService.cs @@ -31,6 +31,7 @@ namespace IRaCIS.Application.Services private readonly IRepository _visitTaskRepository; private readonly IRepository _trialRepository; private readonly IVisitTaskHelpeService _visitTaskHelpeService; + private readonly IVisitTaskService _visitTaskService; private readonly IReadingClinicalDataService _readingClinicalDataService; private readonly IRepository _subjectVisitRepository; private readonly IRepository _subjectRepository; @@ -49,6 +50,7 @@ namespace IRaCIS.Application.Services IRepository visitTaskRepository, IRepository TrialRepository, IVisitTaskHelpeService visitTaskHelpeService, + IVisitTaskService visitTaskService, IReadingClinicalDataService readingClinicalDataService, IRepository subjectVisitRepository, IRepository subjectRepository, @@ -66,6 +68,7 @@ namespace IRaCIS.Application.Services this._visitTaskRepository = visitTaskRepository; this._trialRepository = TrialRepository; this._visitTaskHelpeService = visitTaskHelpeService; + this._visitTaskService = visitTaskService; this._readingClinicalDataService = readingClinicalDataService; this._subjectVisitRepository = subjectVisitRepository; this._subjectRepository = subjectRepository; @@ -253,39 +256,65 @@ namespace IRaCIS.Application.Services } else if (inDto.SubjectId != null) { - var subjectList = await _subjectRepository.Where(t => t.TrialId == inDto.TrialId) - .Select(s => new SubjectTask() - { - SubjectId = s.Id, - UnReadTaskCount = s.SubjectVisitTaskList.Count(t => t.ReadingTaskState != ReadingTaskState.HaveSigned && t.DoctorUserId == _userInfo.Id && t.TaskState == TaskState.Effect), - }).OrderBy(x => x.SubjectId).ToListAsync(); - subjectList = subjectList.Select((x, index) => new SubjectTask() + #region 之前的 + //var subjectList = await _subjectRepository.Where(t => t.TrialId == inDto.TrialId) + + //.Select(s => new SubjectTask() + //{ + // SubjectId = s.Id, + // UnReadTaskCount = s.SubjectVisitTaskList.Count(t => t.ReadingTaskState != ReadingTaskState.HaveSigned && t.DoctorUserId == _userInfo.Id && t.TaskState == TaskState.Effect), + //}).OrderBy(x => x.SubjectId).ToListAsync(); + //subjectList = subjectList.Select((x, index) => new SubjectTask() + //{ + // Index = index, + // SubjectId = x.SubjectId, + // UnReadTaskCount = x.UnReadTaskCount, + //}).ToList(); + + + //var subjectIndex = subjectList.Where(x => x.SubjectId == inDto.SubjectId).Select(x => x.Index).FirstOrDefault(); + //var newSubjectId = subjectList.Where(x => x.Index >= subjectIndex && x.UnReadTaskCount != 0).Select(x => x.SubjectId).FirstOrDefault(); + + //var taskquery = _visitTaskRepository.Where(x => x.TrialId == inDto.TrialId && x.ReadingTaskState != ReadingTaskState.HaveSigned && x.SubjectId == newSubjectId && x.DoctorUserId == _userInfo.Id && x.TaskState == TaskState.Effect).Select(x => new GetReadingTaskDto() + //{ + // VisitTaskId = x.Id, + // TaskBlindName = x.TaskBlindName, + // ReadingCategory = x.ReadingCategory, + // VisistId = x.SourceSubjectVisitId != null ? x.SourceSubjectVisitId.Value : x.ReadModule == null ? default(Guid) : x.ReadModule.SubjectVisitId, + // VisitNum = x.VisitTaskNum, + //}).OrderBy(x => x.VisitNum).ThenBy(x => x.ReadingCategory); + #endregion + + var subjectTaskList = await _visitTaskService.GetOrderReadingIQueryable(inDto.TrialId).Item2.ToListAsync(); + + var index = 0; + subjectTaskList.ForEach(x => { - Index = index, - SubjectId = x.SubjectId, - UnReadTaskCount = x.UnReadTaskCount, - }).ToList(); + x.Index = index; + index++; + }); + var subjectIndex = subjectTaskList.Where(x => x.SubjectId == inDto.SubjectId).Select(x => x.Index).FirstOrDefault(); - var subjectIndex = subjectList.Where(x => x.SubjectId == inDto.SubjectId).Select(x => x.Index).FirstOrDefault(); - var newSubjectId = subjectList.Where(x => x.Index >= subjectIndex && x.UnReadTaskCount != 0).Select(x => x.SubjectId).FirstOrDefault(); + var currentSubject = subjectTaskList.Where(x => x.Index >= 0).OrderBy(x => x.Index).FirstOrDefault(); - var taskquery = _visitTaskRepository.Where(x => x.TrialId == inDto.TrialId && x.ReadingTaskState != ReadingTaskState.HaveSigned && x.SubjectId == newSubjectId && x.DoctorUserId == _userInfo.Id&&x.TaskState==TaskState.Effect).Select(x => new GetReadingTaskDto() - { - VisitTaskId = x.Id, - TaskBlindName = x.TaskBlindName, - ReadingCategory = x.ReadingCategory, - VisistId = x.SourceSubjectVisitId != null ? x.SourceSubjectVisitId.Value : x.ReadModule == null ? default(Guid) : x.ReadModule.SubjectVisitId, - VisitNum = x.VisitTaskNum, - }).OrderBy(x => x.VisitNum).ThenBy(x => x.ReadingCategory); - - task = await taskquery.FirstOrDefaultAsync(); - if (task == null) + if (currentSubject == null) { throw new BusinessValidationFailedException("任务都已经完成"); } - task.SubjectId = inDto.SubjectId.Value; + + task = currentSubject.UnReadTaskList.Select(x => new GetReadingTaskDto() + { + ReadingCategory = x.ReadingCategory, + SubjectCode = currentSubject.SubjectCode, + SubjectId = currentSubject.SubjectId, + TaskBlindName = x.TaskBlindName, + VisitNum = x.VisitNum, + VisistId = x.VisistId ?? default(Guid), + VisitTaskId = x.Id + }).FirstOrDefault(); + }