修改任务分配规则
parent
009fcae3d8
commit
3f9de3c852
|
@ -28,7 +28,7 @@ namespace IRaCIS.Core.Application.ViewModel
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class DoctorVisitTaskStatView: TaskAllocationRuleView
|
public class DoctorVisitTaskStatView : TaskAllocationRuleView
|
||||||
{
|
{
|
||||||
//该医生已经应用的 Subject数量
|
//该医生已经应用的 Subject数量
|
||||||
public int? SelfApplyedSubjectCount { get; set; }
|
public int? SelfApplyedSubjectCount { get; set; }
|
||||||
|
@ -104,7 +104,7 @@ namespace IRaCIS.Core.Application.ViewModel
|
||||||
public string Note { get; set; } = string.Empty;
|
public string Note { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TrialDoctorUserSelectView
|
public class TrialDoctorUserSelectView
|
||||||
{
|
{
|
||||||
public Guid TrialId { get; set; }
|
public Guid TrialId { get; set; }
|
||||||
|
|
||||||
|
@ -121,6 +121,43 @@ namespace IRaCIS.Core.Application.ViewModel
|
||||||
public UserTypeEnum UserTypeEnum { get; set; }
|
public UserTypeEnum UserTypeEnum { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class GenerateTaskCommand
|
||||||
|
{
|
||||||
|
public Guid TrialId { get; set; }
|
||||||
|
|
||||||
|
public ReadingCategory ReadingCategory { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//针对访视产生任务的 有用
|
||||||
|
public bool IsAssignSubjectToDoctor { get; set; }
|
||||||
|
|
||||||
|
//访视任务产生的时候传递
|
||||||
|
|
||||||
|
public List<VisitGenerataTaskDTO> VisitGenerataTaskList { get; set; }
|
||||||
|
|
||||||
|
//裁判的时候传递
|
||||||
|
public List<Guid> JudgeVisitTaskIdList { get; set; } = new List<Guid>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class VisitGenerataTaskDTO
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public Guid SubjectId { get; set; }
|
||||||
|
|
||||||
|
public bool IsUrgent { get; set; }
|
||||||
|
|
||||||
|
public String VisitName { get; set; }
|
||||||
|
|
||||||
|
public String BlindName { get; set; }
|
||||||
|
|
||||||
|
public DateTime? CheckPassedTime { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ using IRaCIS.Core.Application.ViewModel;
|
||||||
using EasyCaching.Core;
|
using EasyCaching.Core;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
using IRaCIS.Core.Infrastructure;
|
using IRaCIS.Core.Infrastructure;
|
||||||
|
using AutoMapper;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Service
|
namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
|
@ -28,8 +29,11 @@ namespace IRaCIS.Core.Application.Service
|
||||||
private readonly IRepository<TaskAllocationRule> _taskAllocationRuleRepository;
|
private readonly IRepository<TaskAllocationRule> _taskAllocationRuleRepository;
|
||||||
private readonly IRepository<SubjectUser> _subjectUserRepository;
|
private readonly IRepository<SubjectUser> _subjectUserRepository;
|
||||||
|
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
public VisitTaskHelpeService(IRepository<VisitTask> visitTaskRepository, IRepository<SubjectUser> subjectUserRepository, IRepository<Trial> trialRepository, IEasyCachingProvider provider, IRepository<SubjectVisit> subjectVisitRepository, IRepository<TaskAllocationRule> taskAllocationRuleRepository)
|
|
||||||
|
public VisitTaskHelpeService(IRepository<VisitTask> visitTaskRepository, IRepository<SubjectUser> subjectUserRepository, IRepository<Trial> trialRepository, IEasyCachingProvider provider,
|
||||||
|
IRepository<SubjectVisit> subjectVisitRepository, IRepository<TaskAllocationRule> taskAllocationRuleRepository, IMapper mapper)
|
||||||
{
|
{
|
||||||
_visitTaskRepository = visitTaskRepository;
|
_visitTaskRepository = visitTaskRepository;
|
||||||
_trialRepository = trialRepository;
|
_trialRepository = trialRepository;
|
||||||
|
@ -37,9 +41,10 @@ namespace IRaCIS.Core.Application.Service
|
||||||
_subjectVisitRepository = subjectVisitRepository;
|
_subjectVisitRepository = subjectVisitRepository;
|
||||||
_taskAllocationRuleRepository = taskAllocationRuleRepository;
|
_taskAllocationRuleRepository = taskAllocationRuleRepository;
|
||||||
_subjectUserRepository = subjectUserRepository;
|
_subjectUserRepository = subjectUserRepository;
|
||||||
|
_mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
//查询列表的时候,一致性核查通过未产生任务的 自动产生任务
|
//查询列表的时候,一致性核查通过未产生任务的 自动产生任务 如果是一致性核查,那么还会自动分配
|
||||||
public async Task GenerateVisitTaskAsync(Guid trialId, List<Guid> subjectVisitIdList, bool isAssignSubjectToDoctor = false)
|
public async Task GenerateVisitTaskAsync(Guid trialId, List<Guid> subjectVisitIdList, bool isAssignSubjectToDoctor = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -48,7 +53,21 @@ namespace IRaCIS.Core.Application.Service
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//以前访视未产生任务的,在查询这里要产生 后期维护到一块
|
var subjectVisitList = _subjectVisitRepository.Where(t => subjectVisitIdList.Contains(t.Id)).ProjectTo<VisitGenerataTaskDTO>(_mapper.ConfigurationProvider).Distinct().ToList();
|
||||||
|
|
||||||
|
|
||||||
|
await AddTaskAsync(new GenerateTaskCommand() { TrialId = trialId, IsAssignSubjectToDoctor = isAssignSubjectToDoctor, VisitGenerataTaskList = subjectVisitList });
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public async Task AddTaskAsync(GenerateTaskCommand generateTaskCommand)
|
||||||
|
{
|
||||||
|
|
||||||
|
var trialId = generateTaskCommand.TrialId;
|
||||||
|
var isAssignSubjectToDoctor = generateTaskCommand.IsAssignSubjectToDoctor;
|
||||||
|
|
||||||
var trialConfig = (await _trialRepository.Where(t => t.Id == trialId).Select(t => new { TrialId = t.Id, t.ReadingType, t.IsFollowVisitAutoAssign, t.IsFollowGlobalVisitAutoAssign, t.FollowGlobalVisitAutoAssignDefaultState, t.FollowVisitAutoAssignDefaultState, t.TaskAllocateObjEnum }).FirstOrDefaultAsync()).IfNullThrowException();
|
var trialConfig = (await _trialRepository.Where(t => t.Id == trialId).Select(t => new { TrialId = t.Id, t.ReadingType, t.IsFollowVisitAutoAssign, t.IsFollowGlobalVisitAutoAssign, t.FollowGlobalVisitAutoAssignDefaultState, t.FollowVisitAutoAssignDefaultState, t.TaskAllocateObjEnum }).FirstOrDefaultAsync()).IfNullThrowException();
|
||||||
|
|
||||||
|
@ -58,159 +77,296 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
int currentMaxCodeInt = cacheMaxCodeInt > dbMaxCode ? cacheMaxCodeInt : dbMaxCode;
|
int currentMaxCodeInt = cacheMaxCodeInt > dbMaxCode ? cacheMaxCodeInt : dbMaxCode;
|
||||||
|
|
||||||
var subjectVisitList = _subjectVisitRepository.Where(t => subjectVisitIdList.Contains(t.Id)).Select(t => new { t.Id, t.SubjectId, t.IsUrgent, t.BlindName, t.VisitName, t.CheckPassedTime, t.TrialId }).Distinct().ToList();
|
if (generateTaskCommand.ReadingCategory == ReadingCategory.Visit)
|
||||||
|
|
||||||
|
|
||||||
foreach (var subjectVisit in subjectVisitList)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
var assignConfigList = await _subjectUserRepository.Where(t => t.TrialId == trialId && t.SubjectId == subjectVisit.SubjectId).Select(u => new { u.DoctorUserId, u.ArmEnum }).ToListAsync();
|
foreach (var subjectVisit in generateTaskCommand.VisitGenerataTaskList)
|
||||||
|
{
|
||||||
|
var assignConfigList = await _subjectUserRepository.Where(t => t.TrialId == trialId && t.SubjectId == subjectVisit.SubjectId).Select(u => new { u.DoctorUserId, u.ArmEnum }).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
if (trialConfig.ReadingType == ReadingMethod.Double)
|
||||||
|
{
|
||||||
|
//每个访视 根据项目配置生成任务 双审生成两个
|
||||||
|
var task1 = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
|
{
|
||||||
|
TrialId = trialId,
|
||||||
|
SubjectId = subjectVisit.SubjectId,
|
||||||
|
IsUrgent = subjectVisit.IsUrgent,
|
||||||
|
TaskBlindName = subjectVisit.BlindName,
|
||||||
|
TaskName = subjectVisit.VisitName,
|
||||||
|
CheckPassedTime = subjectVisit.CheckPassedTime,
|
||||||
|
ArmEnum = Arm.DoubleReadingArm1,//特殊
|
||||||
|
Code = currentMaxCodeInt + 1,
|
||||||
|
SourceSubjectVisitId = subjectVisit.Id,
|
||||||
|
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
||||||
|
ReadingCategory = ReadingCategory.Visit
|
||||||
|
});
|
||||||
|
|
||||||
|
var task2 = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
|
{
|
||||||
|
TrialId = trialId,
|
||||||
|
SubjectId = subjectVisit.SubjectId,
|
||||||
|
IsUrgent = subjectVisit.IsUrgent,
|
||||||
|
TaskBlindName = subjectVisit.BlindName,
|
||||||
|
TaskName = subjectVisit.VisitName,
|
||||||
|
CheckPassedTime = subjectVisit.CheckPassedTime,
|
||||||
|
ArmEnum = Arm.DoubleReadingArm2,//特殊
|
||||||
|
Code = currentMaxCodeInt + 2,
|
||||||
|
SourceSubjectVisitId = subjectVisit.Id,
|
||||||
|
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 2, nameof(VisitTask)),
|
||||||
|
ReadingCategory = ReadingCategory.Visit
|
||||||
|
});
|
||||||
|
|
||||||
|
currentMaxCodeInt = currentMaxCodeInt + 2;
|
||||||
|
|
||||||
|
_provider.Set<int>($"{trialId }_{ StaticData.CacheKey.TaskMaxCode}", currentMaxCodeInt + 2, TimeSpan.FromMinutes(30));
|
||||||
|
|
||||||
|
|
||||||
|
#region 分配
|
||||||
|
if (isAssignSubjectToDoctor)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if (trialConfig.TaskAllocateObjEnum == TaskAllocateObj.Subject)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (trialConfig.IsFollowVisitAutoAssign)
|
||||||
|
{
|
||||||
|
|
||||||
|
#region 验证历史任务
|
||||||
|
|
||||||
|
var allocateSubjectArmList = _visitTaskRepository.Where(t => t.SubjectId == subjectVisit.SubjectId && t.TrialId == trialId && t.DoctorUserId != null && t.ArmEnum != Arm.JudgeArm)
|
||||||
|
.Select(t => new { t.DoctorUserId, t.ArmEnum }).Distinct().ToList();
|
||||||
|
|
||||||
|
|
||||||
|
//不是初次分配 直接分配给Subject 之前的医生
|
||||||
|
if (allocateSubjectArmList.Count != 0)
|
||||||
|
{
|
||||||
|
if (_taskAllocationRuleRepository.Where(t => t.TrialId == trialId && t.IsEnable && t.IsJudgeDoctor == false).Count() < 2)
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException("能参与读片的医生数量必须大于2,自动分配任务中止");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allocateSubjectArmList.GroupBy(t => t.DoctorUserId).Any(g => g.Count() == 2))
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException("请确认是否改了配置,导致同一受试者 分配给同一个医生 在不同的Arm,无法完成自动分配");
|
||||||
|
}
|
||||||
|
|
||||||
|
//手动分配的时候 如果只分配了Arm1 没有分配Arm2 就会有问题
|
||||||
|
if (!(allocateSubjectArmList.Any(t => t.ArmEnum == Arm.DoubleReadingArm1) && allocateSubjectArmList.Any(t => t.ArmEnum == Arm.DoubleReadingArm2)))
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException("请确认是否改了配置,或者手动分配时,只分配了一个Arm ");
|
||||||
|
}
|
||||||
|
|
||||||
|
//配置了医生
|
||||||
|
if (assignConfigList.Count > 0)
|
||||||
|
{
|
||||||
|
var defaultState = trialConfig.FollowVisitAutoAssignDefaultState == TaskAllocateDefaultState.InitAllocated ? TaskState.InitAllocated : TaskState.Allocated;
|
||||||
|
|
||||||
|
|
||||||
|
task1.TaskState = defaultState;
|
||||||
|
task2.TaskState = defaultState;
|
||||||
|
|
||||||
|
//分配给对应Arm的人
|
||||||
|
task1.DoctorUserId = assignConfigList.FirstOrDefault(t => t.ArmEnum == Arm.DoubleReadingArm1).DoctorUserId;
|
||||||
|
task2.DoctorUserId = assignConfigList.FirstOrDefault(t => t.ArmEnum == Arm.DoubleReadingArm1).DoctorUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//找到配置规则表 进行分配
|
||||||
|
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//后续Subect 不自动分配 不处理
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
task1.AllocateTime = DateTime.Now;
|
||||||
|
task2.AllocateTime = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
await _visitTaskRepository.AddAsync(task1);
|
||||||
|
await _visitTaskRepository.AddAsync(task2);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (trialConfig.ReadingType == ReadingMethod.Single)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
var singleTask = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
|
{
|
||||||
|
TrialId = trialId,
|
||||||
|
SubjectId = subjectVisit.SubjectId,
|
||||||
|
IsUrgent = subjectVisit.IsUrgent,
|
||||||
|
TaskBlindName = subjectVisit.BlindName,
|
||||||
|
TaskName = subjectVisit.VisitName,
|
||||||
|
CheckPassedTime = subjectVisit.CheckPassedTime,
|
||||||
|
ArmEnum = Arm.SingleReadingArm, //特殊
|
||||||
|
Code = currentMaxCodeInt + 1,
|
||||||
|
SourceSubjectVisitId = subjectVisit.Id,
|
||||||
|
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
||||||
|
ReadingCategory = ReadingCategory.Visit
|
||||||
|
});
|
||||||
|
|
||||||
|
singleTask.AllocateTime = DateTime.Now;
|
||||||
|
|
||||||
|
currentMaxCodeInt = currentMaxCodeInt + 1;
|
||||||
|
|
||||||
|
_provider.Set<int>($"{trialId }_{ StaticData.CacheKey.TaskMaxCode}", currentMaxCodeInt + 1, TimeSpan.FromMinutes(30));
|
||||||
|
|
||||||
|
#region 分配
|
||||||
|
|
||||||
|
if (isAssignSubjectToDoctor)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (trialConfig.TaskAllocateObjEnum == TaskAllocateObj.Subject)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (trialConfig.IsFollowVisitAutoAssign)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//该Subject 之前是否有已分配的 如果改变配置 可能会出现 一个Subject 分配的同一个医生 有的在Arm1 有的在Arm2
|
||||||
|
var allocateSubjectArmList = _visitTaskRepository.Where(t => t.SubjectId == subjectVisit.SubjectId && t.TrialId == trialId && t.DoctorUserId != null && t.ArmEnum != Arm.JudgeArm)
|
||||||
|
.Select(t => new { t.DoctorUserId, t.ArmEnum }).Distinct().ToList();
|
||||||
|
|
||||||
|
//不是初次分配
|
||||||
|
if (allocateSubjectArmList.Count != 0)
|
||||||
|
{
|
||||||
|
if (_taskAllocationRuleRepository.Where(t => t.TrialId == trialId && t.IsEnable).Count() < 2)
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException("能参与读片的医生数量必须大于2,自动分配任务中止");
|
||||||
|
}
|
||||||
|
|
||||||
|
//配置了医生
|
||||||
|
if (assignConfigList.Count > 0)
|
||||||
|
{
|
||||||
|
var defaultState = trialConfig.FollowVisitAutoAssignDefaultState == TaskAllocateDefaultState.InitAllocated ? TaskState.InitAllocated : TaskState.Allocated;
|
||||||
|
|
||||||
|
singleTask.TaskState = defaultState;
|
||||||
|
|
||||||
|
singleTask.DoctorUserId = assignConfigList.FirstOrDefault(t => t.ArmEnum == 0).DoctorUserId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//后续Subect 不自动分配 不处理
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
await _visitTaskRepository.AddAsync(singleTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
await _subjectVisitRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trialId && t.Id == subjectVisit.Id, u => new SubjectVisit() { IsVisitTaskGenerated = true });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (generateTaskCommand.ReadingCategory == ReadingCategory.Judge)
|
||||||
|
{
|
||||||
|
var firstTask = await _visitTaskRepository.Where(x => generateTaskCommand.JudgeVisitTaskIdList.Contains(x.Id)).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
VisitTask visitTask = new VisitTask()
|
||||||
|
{
|
||||||
|
ArmEnum = Arm.JudgeArm,
|
||||||
|
|
||||||
|
SubjectId = firstTask.SubjectId,
|
||||||
|
ReadingTaskState = ReadingTaskState.WaitReading,
|
||||||
|
TaskName = firstTask.TaskName + "AD",
|
||||||
|
ReadingCategory = ReadingCategory.Judge,
|
||||||
|
TrialId = firstTask.TrialId,
|
||||||
|
|
||||||
|
Code = currentMaxCodeInt + 1,
|
||||||
|
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
||||||
|
};
|
||||||
|
|
||||||
|
currentMaxCodeInt = currentMaxCodeInt + 1;
|
||||||
|
|
||||||
|
_provider.Set<int>($"{trialId }_{ StaticData.CacheKey.TaskMaxCode}", currentMaxCodeInt + 1, TimeSpan.FromMinutes(30));
|
||||||
|
|
||||||
|
await _visitTaskRepository.BatchUpdateNoTrackingAsync(x => generateTaskCommand.JudgeVisitTaskIdList.Contains(x.Id), x => new VisitTask()
|
||||||
|
{
|
||||||
|
JudgeVisitTaskId = visitTask.Id
|
||||||
|
});
|
||||||
|
|
||||||
|
await _visitTaskRepository.AddAsync(visitTask);
|
||||||
|
}
|
||||||
|
else if(generateTaskCommand.ReadingCategory == ReadingCategory.ReadingPeriod)
|
||||||
|
{
|
||||||
if (trialConfig.ReadingType == ReadingMethod.Double)
|
if (trialConfig.ReadingType == ReadingMethod.Double)
|
||||||
{
|
{
|
||||||
//每个访视 根据项目配置生成任务 双审生成两个
|
//每个访视 根据项目配置生成任务 双审生成两个
|
||||||
var task1 = await _visitTaskRepository.AddAsync(new VisitTask()
|
var task1 = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
{
|
{
|
||||||
TrialId = subjectVisit.TrialId,
|
TrialId = trialId,
|
||||||
SubjectId = subjectVisit.SubjectId,
|
//SubjectId = subjectVisit.SubjectId,
|
||||||
IsUrgent = subjectVisit.IsUrgent,
|
//IsUrgent = subjectVisit.IsUrgent,
|
||||||
TaskBlindName = subjectVisit.BlindName,
|
//TaskBlindName = subjectVisit.BlindName,
|
||||||
TaskName = subjectVisit.VisitName,
|
//TaskName = subjectVisit.VisitName,
|
||||||
CheckPassedTime = subjectVisit.CheckPassedTime,
|
|
||||||
ArmEnum = Arm.DoubleReadingArm1,//特殊
|
ArmEnum = Arm.DoubleReadingArm1,//特殊
|
||||||
Code = currentMaxCodeInt + 1,
|
Code = currentMaxCodeInt + 1,
|
||||||
SourceSubjectVisitId=subjectVisit.Id,
|
//SourceSubjectVisitId = subjectVisit.Id,
|
||||||
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
||||||
ReadingCategory = ReadingCategory.Visit
|
ReadingCategory = ReadingCategory.ReadingPeriod
|
||||||
});
|
});
|
||||||
|
|
||||||
var task2 = await _visitTaskRepository.AddAsync(new VisitTask()
|
var task2 = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
{
|
{
|
||||||
TrialId = subjectVisit.TrialId,
|
TrialId = trialId,
|
||||||
SubjectId = subjectVisit.SubjectId,
|
//SubjectId = subjectVisit.SubjectId,
|
||||||
IsUrgent = subjectVisit.IsUrgent,
|
//IsUrgent = subjectVisit.IsUrgent,
|
||||||
TaskBlindName = subjectVisit.BlindName,
|
//TaskBlindName = subjectVisit.BlindName,
|
||||||
TaskName = subjectVisit.VisitName,
|
//TaskName = subjectVisit.VisitName,
|
||||||
CheckPassedTime = subjectVisit.CheckPassedTime,
|
|
||||||
ArmEnum = Arm.DoubleReadingArm2,//特殊
|
ArmEnum = Arm.DoubleReadingArm2,//特殊
|
||||||
Code = currentMaxCodeInt + 2,
|
Code = currentMaxCodeInt + 2,
|
||||||
SourceSubjectVisitId = subjectVisit.Id,
|
//SourceSubjectVisitId = subjectVisit.Id,
|
||||||
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 2, nameof(VisitTask)),
|
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 2, nameof(VisitTask)),
|
||||||
ReadingCategory = ReadingCategory.Visit
|
ReadingCategory = ReadingCategory.ReadingPeriod
|
||||||
});
|
});
|
||||||
|
|
||||||
currentMaxCodeInt = currentMaxCodeInt + 2;
|
currentMaxCodeInt = currentMaxCodeInt + 2;
|
||||||
|
|
||||||
_provider.Set<int>($"{trialId }_{ StaticData.CacheKey.TaskMaxCode}", currentMaxCodeInt + 2, TimeSpan.FromMinutes(30));
|
_provider.Set<int>($"{trialId }_{ StaticData.CacheKey.TaskMaxCode}", currentMaxCodeInt + 2, TimeSpan.FromMinutes(30));
|
||||||
|
|
||||||
|
await _visitTaskRepository.AddAsync(task1);
|
||||||
#region 分配
|
await _visitTaskRepository.AddAsync(task2);
|
||||||
if (isAssignSubjectToDoctor)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (trialConfig.TaskAllocateObjEnum == TaskAllocateObj.Subject)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (trialConfig.IsFollowVisitAutoAssign)
|
|
||||||
{
|
|
||||||
|
|
||||||
#region 验证历史任务
|
|
||||||
|
|
||||||
var allocateSubjectArmList = _visitTaskRepository.Where(t => t.SubjectId == subjectVisit.SubjectId && t.TrialId == subjectVisit.TrialId && t.DoctorUserId != null).Select(t => new { t.DoctorUserId, t.ArmEnum }).Distinct().ToList();
|
|
||||||
|
|
||||||
|
|
||||||
//不是初次分配 直接分配给Subject 之前的医生
|
|
||||||
if (allocateSubjectArmList.Count != 0)
|
|
||||||
{
|
|
||||||
if (_taskAllocationRuleRepository.Where(t => t.TrialId == subjectVisit.TrialId && t.IsEnable).Count() < 2)
|
|
||||||
{
|
|
||||||
throw new BusinessValidationFailedException("能参与读片的医生数量必须大于2,自动分配任务中止");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (allocateSubjectArmList.GroupBy(t => t.DoctorUserId).Any(g => g.Count() == 2))
|
|
||||||
{
|
|
||||||
throw new BusinessValidationFailedException("请确认是否改了配置,导致同一受试者 分配给同一个医生 在不同的Arm,无法完成自动分配");
|
|
||||||
}
|
|
||||||
|
|
||||||
//手动分配的时候 如果只分配了Arm1 没有分配Arm2 就会有问题
|
|
||||||
if (!(allocateSubjectArmList.Any(t => t.ArmEnum == Arm.DoubleReadingArm1) && allocateSubjectArmList.Any(t => t.ArmEnum == Arm.DoubleReadingArm2)))
|
|
||||||
{
|
|
||||||
throw new BusinessValidationFailedException("请确认是否改了配置,或者手动分配时,只分配了一个Arm ");
|
|
||||||
}
|
|
||||||
|
|
||||||
//配置了医生
|
|
||||||
if (assignConfigList.Count > 0)
|
|
||||||
{
|
|
||||||
var defaultState = trialConfig.FollowVisitAutoAssignDefaultState == TaskAllocateDefaultState.InitAllocated ? TaskState.InitAllocated : TaskState.Allocated;
|
|
||||||
|
|
||||||
|
|
||||||
task1.TaskState = defaultState;
|
|
||||||
task2.TaskState = defaultState;
|
|
||||||
|
|
||||||
//分配给对应Arm的人
|
|
||||||
task1.DoctorUserId = assignConfigList.FirstOrDefault(t => t.ArmEnum == Arm.DoubleReadingArm1).DoctorUserId;
|
|
||||||
task2.DoctorUserId = assignConfigList.FirstOrDefault(t => t.ArmEnum == Arm.DoubleReadingArm1).DoctorUserId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//找到配置规则表 进行分配
|
|
||||||
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//后续Subect 不自动分配 不处理
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//else if (trialConfig.IsFollowGlobalVisitAutoAssign)
|
|
||||||
//{
|
|
||||||
// var defaultState = trialConfig.FollowVisitAutoAssignDefaultState == TaskAllocateDefaultState.InitAllocated ? TaskState.InitAllocated : TaskState.Allocated;
|
|
||||||
|
|
||||||
// task1.TaskState = defaultState;
|
|
||||||
// task2.TaskState = defaultState;
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
task1.AllocateTime = DateTime.Now;
|
|
||||||
task2.AllocateTime = DateTime.Now;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (trialConfig.ReadingType == ReadingMethod.Single)
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
var singleTask = await _visitTaskRepository.AddAsync(new VisitTask()
|
var singleTask = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
{
|
{
|
||||||
TrialId = subjectVisit.TrialId,
|
TrialId = trialId,
|
||||||
SubjectId = subjectVisit.SubjectId,
|
//SubjectId = subjectVisit.SubjectId,
|
||||||
IsUrgent = subjectVisit.IsUrgent,
|
//IsUrgent = subjectVisit.IsUrgent,
|
||||||
TaskBlindName = subjectVisit.BlindName,
|
//TaskBlindName = subjectVisit.BlindName,
|
||||||
TaskName = subjectVisit.VisitName,
|
//TaskName = subjectVisit.VisitName,
|
||||||
CheckPassedTime = subjectVisit.CheckPassedTime,
|
ArmEnum = Arm.SingleReadingArm, //特殊
|
||||||
ArmEnum = Arm.DoubleReadingArm1, //特殊
|
|
||||||
Code = currentMaxCodeInt + 1,
|
Code = currentMaxCodeInt + 1,
|
||||||
SourceSubjectVisitId = subjectVisit.Id,
|
//SourceSubjectVisitId = subjectVisit.Id,
|
||||||
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
||||||
ReadingCategory = ReadingCategory.Visit
|
ReadingCategory = ReadingCategory.ReadingPeriod
|
||||||
});
|
});
|
||||||
|
|
||||||
singleTask.AllocateTime = DateTime.Now;
|
singleTask.AllocateTime = DateTime.Now;
|
||||||
|
@ -219,71 +375,18 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
_provider.Set<int>($"{trialId }_{ StaticData.CacheKey.TaskMaxCode}", currentMaxCodeInt + 1, TimeSpan.FromMinutes(30));
|
_provider.Set<int>($"{trialId }_{ StaticData.CacheKey.TaskMaxCode}", currentMaxCodeInt + 1, TimeSpan.FromMinutes(30));
|
||||||
|
|
||||||
#region 分配
|
await _visitTaskRepository.AddAsync(singleTask);
|
||||||
if (isAssignSubjectToDoctor)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
if (trialConfig.TaskAllocateObjEnum == TaskAllocateObj.Subject)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (trialConfig.IsFollowVisitAutoAssign)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
//该Subject 之前是否有已分配的 如果改变配置 可能会出现 一个Subject 分配的同一个医生 有的在Arm1 有的在Arm2
|
|
||||||
var allocateSubjectArmList = _visitTaskRepository.Where(t => t.SubjectId == subjectVisit.SubjectId && t.TrialId == subjectVisit.TrialId && t.DoctorUserId != null).Select(t => new { t.DoctorUserId, t.ArmEnum }).Distinct().ToList();
|
|
||||||
|
|
||||||
//不是初次分配
|
|
||||||
if (allocateSubjectArmList.Count != 0)
|
|
||||||
{
|
|
||||||
if (_taskAllocationRuleRepository.Where(t => t.TrialId == subjectVisit.TrialId && t.IsEnable).Count() < 2)
|
|
||||||
{
|
|
||||||
throw new BusinessValidationFailedException("能参与读片的医生数量必须大于2,自动分配任务中止");
|
|
||||||
}
|
|
||||||
|
|
||||||
//配置了医生
|
|
||||||
if (assignConfigList.Count > 0)
|
|
||||||
{
|
|
||||||
var defaultState = trialConfig.FollowVisitAutoAssignDefaultState == TaskAllocateDefaultState.InitAllocated ? TaskState.InitAllocated : TaskState.Allocated;
|
|
||||||
|
|
||||||
singleTask.TaskState = defaultState;
|
|
||||||
|
|
||||||
singleTask.DoctorUserId = assignConfigList.FirstOrDefault(t => t.ArmEnum == 0).DoctorUserId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//后续Subect 不自动分配 不处理
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await _subjectVisitRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trialId && t.Id == subjectVisit.Id, u => new SubjectVisit() { IsVisitTaskGenerated = true });
|
|
||||||
await _visitTaskRepository.SaveChangesAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
await _visitTaskRepository.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,8 +72,8 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CreateMap<SubjectVisit, VisitGenerataTaskDTO>();
|
||||||
|
|
||||||
|
|
||||||
CreateMap<VisitTask, VisitTaskView>()
|
CreateMap<VisitTask, VisitTaskView>()
|
||||||
.ForMember(o => o.SiteId, t => t.MapFrom(u => u.Subject.SiteId))
|
.ForMember(o => o.SiteId, t => t.MapFrom(u => u.Subject.SiteId))
|
||||||
|
|
|
@ -465,7 +465,7 @@ namespace IRaCIS.Application.Services
|
||||||
|
|
||||||
await VerifyUserEmailAsync(null, userAddModel.UserTypeId, userAddModel.EMail);
|
await VerifyUserEmailAsync(null, userAddModel.UserTypeId, userAddModel.EMail);
|
||||||
|
|
||||||
await VerifyUserPhoneAsync(null, userAddModel.UserTypeId, userAddModel.Phone);
|
//await VerifyUserPhoneAsync(null, userAddModel.UserTypeId, userAddModel.Phone);
|
||||||
|
|
||||||
|
|
||||||
var saveItem = _mapper.Map<User>(userAddModel);
|
var saveItem = _mapper.Map<User>(userAddModel);
|
||||||
|
@ -505,7 +505,7 @@ namespace IRaCIS.Application.Services
|
||||||
|
|
||||||
await VerifyUserEmailAsync(model.Id, model.UserTypeId, model.EMail);
|
await VerifyUserEmailAsync(model.Id, model.UserTypeId, model.EMail);
|
||||||
|
|
||||||
await VerifyUserPhoneAsync(model.Id, model.UserTypeId, model.Phone);
|
//await VerifyUserPhoneAsync(model.Id, model.UserTypeId, model.Phone);
|
||||||
|
|
||||||
var user = await _userRepository.FirstOrDefaultAsync(t => t.Id == model.Id);
|
var user = await _userRepository.FirstOrDefaultAsync(t => t.Id == model.Id);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue