|
|
|
@@ -12,6 +12,7 @@ using IRaCIS.Core.Infrastructure;
|
|
|
|
|
using IRaCIS.Core.Domain.Share;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using IRaCIS.Core.Infra.EFCore.Common;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace IRaCIS.Core.Application.Service
|
|
|
|
|
{
|
|
|
|
@@ -74,25 +75,30 @@ namespace IRaCIS.Core.Application.Service
|
|
|
|
|
/// <param name="inQuery"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<PageOutput<DoctorConsistentRuleSubjectView>> GetDoctorSelfConsistentRuleSubjectList(ConsistentQuery inQuery)
|
|
|
|
|
public async Task<PageOutput<DoctorSelfConsistentSubjectView>> GetDoctorSelfConsistentRuleSubjectList(ConsistentQuery inQuery)
|
|
|
|
|
{
|
|
|
|
|
var filterObj = await _taskConsistentRuleRepository.FirstOrDefaultAsync(t => t.Id == inQuery.TaskConsistentRuleId);
|
|
|
|
|
|
|
|
|
|
var (group, query) = GetIQueryableDoctorSelfConsistentRuleSubjectView(filterObj);
|
|
|
|
|
var pagedList = await GetIQueryableDoctorSelfConsistentSubjectView(filterObj).ToPagedListAsync(inQuery.PageIndex, inQuery.PageSize, string.IsNullOrWhiteSpace(inQuery.SortField) ? nameof(DoctorSelfConsistentSubjectView.SubjectCode) : inQuery.SortField, inQuery.Asc);
|
|
|
|
|
|
|
|
|
|
var count = group.Count();
|
|
|
|
|
|
|
|
|
|
query = query.OrderByDescending(t => t.IsHaveGeneratedTask).Skip((inQuery.PageIndex - 1) * inQuery.PageSize);
|
|
|
|
|
|
|
|
|
|
var items = await query.Take(inQuery.PageSize).ToArrayAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
var pagedList = new PageOutput<DoctorConsistentRuleSubjectView>()
|
|
|
|
|
{
|
|
|
|
|
PageIndex = inQuery.PageIndex,
|
|
|
|
|
PageSize = inQuery.PageSize,
|
|
|
|
|
TotalCount = count,
|
|
|
|
|
CurrentPageData = items
|
|
|
|
|
};
|
|
|
|
|
//var (group, query) = GetIQueryableDoctorSelfConsistentRuleSubjectView(filterObj);
|
|
|
|
|
|
|
|
|
|
//var count = group.Count();
|
|
|
|
|
|
|
|
|
|
//query = query.OrderByDescending(t => t.IsHaveGeneratedTask).Skip((inQuery.PageIndex - 1) * inQuery.PageSize);
|
|
|
|
|
|
|
|
|
|
//var items = await query.Take(inQuery.PageSize).ToArrayAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
//var pagedList = new PageOutput<DoctorConsistentRuleSubjectView>()
|
|
|
|
|
//{
|
|
|
|
|
// PageIndex = inQuery.PageIndex,
|
|
|
|
|
// PageSize = inQuery.PageSize,
|
|
|
|
|
// TotalCount = count,
|
|
|
|
|
// CurrentPageData = items
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return pagedList;
|
|
|
|
@@ -109,9 +115,11 @@ namespace IRaCIS.Core.Application.Service
|
|
|
|
|
var filterObj = await _taskConsistentRuleRepository.FirstOrDefaultAsync(t => t.Id == inCommand.TaskConsistentRuleId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (group, query) = GetIQueryableDoctorSelfConsistentRuleSubjectView(filterObj, inCommand.SubejctIdList);
|
|
|
|
|
var list = await GetIQueryableDoctorSelfConsistentSubjectView(filterObj, inCommand.SubejctIdList).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var list = query.OrderByDescending(t => t.IsHaveGeneratedTask).ToList();
|
|
|
|
|
//var (group, query) = GetIQueryableDoctorSelfConsistentRuleSubjectView(filterObj, inCommand.SubejctIdList);
|
|
|
|
|
|
|
|
|
|
//var list = query.OrderByDescending(t => t.IsHaveGeneratedTask).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var subject in list)
|
|
|
|
|
{
|
|
|
|
@@ -136,26 +144,96 @@ namespace IRaCIS.Core.Application.Service
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IQueryable<DoctorSelfConsistentSubjectView> GetIQueryableDoctorSelfConsistentSubjectView(TaskConsistentRule filterObj, List<Guid>? subejctIdList = null)
|
|
|
|
|
{
|
|
|
|
|
var doctorUserId = filterObj.AnalysisDoctorUserId;
|
|
|
|
|
var trialId = filterObj.TrialId;
|
|
|
|
|
|
|
|
|
|
#region Subejct 维度
|
|
|
|
|
|
|
|
|
|
Expression<Func<VisitTask, bool>> visitTaskFilter = t => t.IsAnalysisCreate == false && t.ReadingCategory == ReadingCategory.Visit && t.DoctorUserId == doctorUserId &&
|
|
|
|
|
t.ReadingTaskState == ReadingTaskState.HaveSigned && t.TaskState == TaskState.Effect &&
|
|
|
|
|
t.SignTime!.Value.AddDays(filterObj.IntervalWeeks * 7) < DateTime.Now &&
|
|
|
|
|
(t.ReReadingApplyState == ReReadingApplyState.Default || t.ReReadingApplyState == ReReadingApplyState.Reject);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (subejctIdList != null && subejctIdList?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
visitTaskFilter.And( t => subejctIdList.Contains(t.SubjectId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//所选访视数量 的访视 其中必有一个访视后有全局任务
|
|
|
|
|
if (filterObj.IsHaveReadingPeriod == true)
|
|
|
|
|
{
|
|
|
|
|
visitTaskFilter = visitTaskFilter.And(t => t.Subject.SubjectVisitTaskList.Any(u => u.VisitTaskNum == t.VisitTaskNum + ReadingCommon.TaskNumDic[ReadingCategory.Global]
|
|
|
|
|
&& t.TaskState == TaskState.Effect && t.ReadingTaskState == ReadingTaskState.HaveSigned && t.SignTime!.Value.AddDays(filterObj.IntervalWeeks * 7) < DateTime.Now));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//var globalWithVisitFilter = visitTaskFilter.And(t => t.VisitTaskNum <=)
|
|
|
|
|
|
|
|
|
|
var subjectQuery = _subjectRepository.Where(t => t.TrialId == trialId && t.SubjectVisitTaskList.AsQueryable().Where(visitTaskFilter).Count() >= filterObj.PlanVisitCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var query = subjectQuery.Select(t => new DoctorSelfConsistentSubjectView()
|
|
|
|
|
{
|
|
|
|
|
TrialId = t.TrialId,
|
|
|
|
|
SiteId = t.SiteId,
|
|
|
|
|
SubjectCode = t.Code,
|
|
|
|
|
TrialSiteCode = t.TrialSite.TrialSiteCode,
|
|
|
|
|
SubjectId = t.Id,
|
|
|
|
|
|
|
|
|
|
IsHaveGeneratedTask = t.SubjectVisitTaskList.Any(c => c.IsAnalysisCreate && c.DoctorUserId == doctorUserId),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ValidVisitCount = t.SubjectVisitTaskList.AsQueryable().Where(visitTaskFilter).Count(),
|
|
|
|
|
|
|
|
|
|
VisitTaskList = t.SubjectVisitTaskList.AsQueryable().Where(visitTaskFilter).Select(c => new VisitTaskSimpleDTO()
|
|
|
|
|
{
|
|
|
|
|
Id = c.Id,
|
|
|
|
|
ReadingCategory = c.ReadingCategory,
|
|
|
|
|
ReadingTaskState = c.ReadingTaskState,
|
|
|
|
|
TaskBlindName = c.TaskBlindName,
|
|
|
|
|
TaskCode = c.TaskCode,
|
|
|
|
|
TaskName = c.TaskName,
|
|
|
|
|
TaskState = c.TaskState,
|
|
|
|
|
ArmEnum = c.ArmEnum,
|
|
|
|
|
SubjectId = c.SubjectId,
|
|
|
|
|
VisitTaskNum = c.VisitTaskNum,
|
|
|
|
|
TrialId = c.TrialId,
|
|
|
|
|
|
|
|
|
|
IsHaveGeneratedTask = c.Subject.SubjectVisitTaskList.Any(t => t.ConsistentAnalysisOriginalTaskId == c.Id),
|
|
|
|
|
|
|
|
|
|
GlobalVisitTaskList = c.Subject.SubjectVisitTaskList.Where(t => t.VisitTaskNum == c.VisitTaskNum + ReadingCommon.TaskNumDic[ReadingCategory.Global] && t.TaskState == TaskState.Effect && t.ReadingTaskState == ReadingTaskState.HaveSigned && t.SignTime!.Value.AddDays(filterObj.IntervalWeeks * 7) < DateTime.Now).Select(c => new VisitTaskSimpleDTO()
|
|
|
|
|
{
|
|
|
|
|
Id = c.Id,
|
|
|
|
|
ReadingCategory = c.ReadingCategory,
|
|
|
|
|
ReadingTaskState = c.ReadingTaskState,
|
|
|
|
|
TaskBlindName = c.TaskBlindName,
|
|
|
|
|
TaskCode = c.TaskCode,
|
|
|
|
|
TaskName = c.TaskName,
|
|
|
|
|
TaskState = c.TaskState,
|
|
|
|
|
ArmEnum = c.ArmEnum,
|
|
|
|
|
SubjectId = c.SubjectId,
|
|
|
|
|
VisitTaskNum = c.VisitTaskNum,
|
|
|
|
|
TrialId = c.TrialId,
|
|
|
|
|
|
|
|
|
|
}).ToList(),
|
|
|
|
|
|
|
|
|
|
}).ToList()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return query.OrderByDescending(t => t.IsHaveGeneratedTask);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private (IQueryable<IGrouping<Guid, VisitTask>>, IQueryable<DoctorConsistentRuleSubjectView>) GetIQueryableDoctorSelfConsistentRuleSubjectView(TaskConsistentRule filterObj, List<Guid>? subejctIdList = null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//IQueryable<Guid> subjectfilter = default;
|
|
|
|
|
|
|
|
|
|
//if (isSelfAnalysis == false)
|
|
|
|
|
//{
|
|
|
|
|
// //过滤不满足的Subject
|
|
|
|
|
|
|
|
|
|
// subjectfilter = _subjectUserRepository.Where(t => t.TrialId == filterObj.TrialId).GroupBy(t => t.SubjectId)
|
|
|
|
|
// .Where(g => g.Any(t => t.DoctorUserId == filterObj.AnalysisDoctorUserId) && !g.Any(t => t.DoctorUserId == filterObj.CompareDoctorUserId)).Select(g => g.Key);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
var doctorUserId = filterObj.AnalysisDoctorUserId;
|
|
|
|
|
var trialId = filterObj.TrialId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 任务维度
|
|
|
|
|
|
|
|
|
|
var group = _visitTaskRepository.Where(t => t.TrialId == filterObj.TrialId && t.IsAnalysisCreate == false && t.ReadingCategory == ReadingCategory.Visit && t.DoctorUserId == doctorUserId)
|
|
|
|
|
|
|
|
|
@@ -170,7 +248,7 @@ namespace IRaCIS.Core.Application.Service
|
|
|
|
|
//重阅产生的访视任务 要把之前的访视任务去除
|
|
|
|
|
.Where(t => t.ReReadingApplyState == ReReadingApplyState.Default || t.ReReadingApplyState == ReReadingApplyState.Reject)
|
|
|
|
|
|
|
|
|
|
.WhereIf(filterObj.IsHaveReadingPeriod == true, t => t.SameSubjectVisiTaskList.Any(u => u.VisitTaskNum == t.VisitTaskNum + ReadingCommon.TaskNumDic[ReadingCategory.Global]
|
|
|
|
|
.WhereIf(filterObj.IsHaveReadingPeriod == true, t => t.Subject.SubjectVisitTaskList.Any(u => u.VisitTaskNum == t.VisitTaskNum + ReadingCommon.TaskNumDic[ReadingCategory.Global]
|
|
|
|
|
&& t.TaskState == TaskState.Effect && t.ReadingTaskState == ReadingTaskState.HaveSigned && t.SignTime!.Value.AddDays(filterObj.IntervalWeeks * 7) < DateTime.Now))
|
|
|
|
|
.GroupBy(t => t.SubjectId)
|
|
|
|
|
.Where(g => g.Count() >= filterObj.PlanVisitCount);
|
|
|
|
@@ -180,7 +258,7 @@ namespace IRaCIS.Core.Application.Service
|
|
|
|
|
{
|
|
|
|
|
SubjectId = g.Key,
|
|
|
|
|
|
|
|
|
|
IsHaveGeneratedTask = g.Any(c => c.SameSubjectVisiTaskList.Any(t => t.IsAnalysisCreate && t.DoctorUserId == doctorUserId && t.TaskConsistentRuleId == filterObj.Id)),
|
|
|
|
|
IsHaveGeneratedTask = g.Any(c => c.Subject.SubjectVisitTaskList.Any(t => t.IsAnalysisCreate && t.DoctorUserId == doctorUserId && t.TaskConsistentRuleId == filterObj.Id)),
|
|
|
|
|
|
|
|
|
|
VisitTaskList = g.OrderBy(t => t.VisitTaskNum)
|
|
|
|
|
|
|
|
|
@@ -200,7 +278,7 @@ namespace IRaCIS.Core.Application.Service
|
|
|
|
|
SubjectCode = c.Subject.Code,
|
|
|
|
|
TrialSiteCode = c.Subject.TrialSite.TrialSiteCode,
|
|
|
|
|
|
|
|
|
|
GlobalVisitTaskList = c.SameSubjectVisiTaskList.Where(t => t.VisitTaskNum == c.VisitTaskNum + ReadingCommon.TaskNumDic[ReadingCategory.Global] && t.TaskState == TaskState.Effect && t.ReadingTaskState == ReadingTaskState.HaveSigned).Select(t => new VisitTaskSimpleView()
|
|
|
|
|
GlobalVisitTaskList = c.Subject.SubjectVisitTaskList.Where(t => t.VisitTaskNum == c.VisitTaskNum + ReadingCommon.TaskNumDic[ReadingCategory.Global] && t.TaskState == TaskState.Effect && t.ReadingTaskState == ReadingTaskState.HaveSigned).Select(t => new VisitTaskSimpleView()
|
|
|
|
|
{
|
|
|
|
|
Id = t.Id,
|
|
|
|
|
ReadingCategory = t.ReadingCategory,
|
|
|
|
@@ -225,15 +303,25 @@ namespace IRaCIS.Core.Application.Service
|
|
|
|
|
// UserName = c.DoctorUser.UserName
|
|
|
|
|
//}).ToList(),
|
|
|
|
|
|
|
|
|
|
IsHaveGeneratedTask = c.SameSubjectVisiTaskList.Any(t => t.ConsistentAnalysisOriginalTaskId == c.Id),
|
|
|
|
|
IsHaveGeneratedTask = c.Subject.SubjectVisitTaskList.Any(t => t.ConsistentAnalysisOriginalTaskId == c.Id),
|
|
|
|
|
|
|
|
|
|
}).ToList(),
|
|
|
|
|
|
|
|
|
|
ValidTaskCount = g.Count()
|
|
|
|
|
|
|
|
|
|
}); ;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (group, query);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@@ -248,7 +336,7 @@ namespace IRaCIS.Core.Application.Service
|
|
|
|
|
#region 是否有新的医生加入 自动加入配置
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (await _taskConsistentRuleRepository.AnyAsync(t => t.TrialId == inQuery.TrialId))
|
|
|
|
|
if (await _taskConsistentRuleRepository.AnyAsync(t => t.TrialId == inQuery.TrialId))
|
|
|
|
|
{
|
|
|
|
|
var rule = await _taskConsistentRuleRepository.Where(t => t.TrialId == inQuery.TrialId).ProjectTo<TaskConsistentRuleBatchAddOrEdit>(_mapper.ConfigurationProvider).FirstAsync();
|
|
|
|
|
|
|
|
|
@@ -275,7 +363,7 @@ namespace IRaCIS.Core.Application.Service
|
|
|
|
|
{
|
|
|
|
|
var query = from enroll in _repository.Where<Enroll>(t => t.TrialId == trialId)
|
|
|
|
|
join user in _repository.Where<User>() on enroll.DoctorId equals user.DoctorId
|
|
|
|
|
join taskConsistentRule in _repository.Where<TaskConsistentRule>(t=>t.TrialId== trialId) on user.Id equals taskConsistentRule.AnalysisDoctorUserId into c
|
|
|
|
|
join taskConsistentRule in _repository.Where<TaskConsistentRule>(t => t.TrialId == trialId) on user.Id equals taskConsistentRule.AnalysisDoctorUserId into c
|
|
|
|
|
from taskConsistentRule in c.DefaultIfEmpty()
|
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
@@ -303,7 +391,7 @@ namespace IRaCIS.Core.Application.Service
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
addOrEdit.AnalysisDoctorUserId = doctor.DoctorUserId;
|
|
|
|
|
addOrEdit.Id = Guid.Empty ;
|
|
|
|
|
addOrEdit.Id = Guid.Empty;
|
|
|
|
|
|
|
|
|
|
var entity = await _taskConsistentRuleRepository.InsertOrUpdateAsync(addOrEdit, true, verifyExp1);
|
|
|
|
|
}
|
|
|
|
|