自动产生一致性核查任务列表
parent
92274e954d
commit
d1068711b4
|
@ -47,6 +47,11 @@
|
||||||
<param name="_enrollRepository"></param>
|
<param name="_enrollRepository"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:IRaCIS.Core.Application.Service.VisitTaskHelpeService">
|
||||||
|
<summary>
|
||||||
|
访视读片任务
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:IRaCIS.Core.Application.Service.VisitTaskService">
|
<member name="T:IRaCIS.Core.Application.Service.VisitTaskService">
|
||||||
<summary>
|
<summary>
|
||||||
访视读片任务
|
访视读片任务
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||||
|
// 生成时间 2022-06-07 14:10:49
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
namespace IRaCIS.Core.Application.Service
|
||||||
|
{
|
||||||
|
public interface IVisitTaskHelpeService
|
||||||
|
{
|
||||||
|
Task GenerateVisitTaskAsync(Guid trialId, List<Guid> subjectVisitIdList, bool isAssignSubjectToDoctor = false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,233 @@
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||||
|
// 生成时间 2022-06-07 14:10:49
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
using IRaCIS.Core.Domain.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using IRaCIS.Core.Application.Interfaces;
|
||||||
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
|
using EasyCaching.Core;
|
||||||
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
using IRaCIS.Core.Infrastructure;
|
||||||
|
|
||||||
|
namespace IRaCIS.Core.Application.Service
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 访视读片任务
|
||||||
|
/// </summary>
|
||||||
|
[ApiExplorerSettings(GroupName = "Trial")]
|
||||||
|
public class VisitTaskHelpeService : IVisitTaskHelpeService
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly IRepository<VisitTask> _visitTaskRepository;
|
||||||
|
private readonly IRepository<Trial> _trialRepository;
|
||||||
|
private readonly IEasyCachingProvider _provider;
|
||||||
|
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
|
||||||
|
private readonly IRepository<TaskAllocationRule> _taskAllocationRuleRepository;
|
||||||
|
|
||||||
|
|
||||||
|
public VisitTaskHelpeService(IRepository<VisitTask> visitTaskRepository, IRepository<Trial> trialRepository, IEasyCachingProvider provider, IRepository<SubjectVisit> subjectVisitRepository, IRepository<TaskAllocationRule> taskAllocationRuleRepository)
|
||||||
|
{
|
||||||
|
_visitTaskRepository = visitTaskRepository;
|
||||||
|
_trialRepository = trialRepository;
|
||||||
|
_provider = provider;
|
||||||
|
_subjectVisitRepository = subjectVisitRepository;
|
||||||
|
_taskAllocationRuleRepository = taskAllocationRuleRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询列表的时候,一致性核查通过未产生任务的 自动产生任务
|
||||||
|
public async Task GenerateVisitTaskAsync(Guid trialId, List<Guid> subjectVisitIdList, bool isAssignSubjectToDoctor=false)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (subjectVisitIdList.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//以前访视未产生任务的,在查询这里要产生 后期维护到一块
|
||||||
|
|
||||||
|
var trialConfig = (await _trialRepository.Where(t => t.Id == trialId).Select(t => new { TrialId = t.Id, t.ReadingType, t.TaskAllocateDefaultState, t.TaskAllocateObjEnum }).FirstOrDefaultAsync()).IfNullThrowException();
|
||||||
|
|
||||||
|
var dbMaxCode = _visitTaskRepository.Where(t => t.TrialId == trialId).Select(t => t.Code).DefaultIfEmpty().Max();
|
||||||
|
|
||||||
|
var cacheMaxCodeInt = _provider.Get<int>($"{trialId }_{ StaticData.CacheKey.TaskMaxCode}").Value;
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var subjectVisit in subjectVisitList)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (trialConfig.ReadingType == ReadingMethod.Double)
|
||||||
|
{
|
||||||
|
//每个访视 根据项目配置生成任务 双审生成两个
|
||||||
|
var task1 = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
|
{
|
||||||
|
TrialId = subjectVisit.TrialId,
|
||||||
|
SubjectId = subjectVisit.SubjectId,
|
||||||
|
IsUrgent = subjectVisit.IsUrgent,
|
||||||
|
TaskBlindName = subjectVisit.BlindName,
|
||||||
|
TaskName = subjectVisit.VisitName,
|
||||||
|
CheckPassedTime = subjectVisit.CheckPassedTime,
|
||||||
|
ArmEnum = 1,//特殊
|
||||||
|
Code = currentMaxCodeInt + 1,
|
||||||
|
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
||||||
|
ReadingCategory = ReadingCategory.Visit
|
||||||
|
});
|
||||||
|
|
||||||
|
var task2 = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
|
{
|
||||||
|
TrialId = subjectVisit.TrialId,
|
||||||
|
SubjectId = subjectVisit.SubjectId,
|
||||||
|
IsUrgent = subjectVisit.IsUrgent,
|
||||||
|
TaskBlindName = subjectVisit.BlindName,
|
||||||
|
TaskName = subjectVisit.VisitName,
|
||||||
|
CheckPassedTime = subjectVisit.CheckPassedTime,
|
||||||
|
ArmEnum = 2,//特殊
|
||||||
|
Code = currentMaxCodeInt + 2,
|
||||||
|
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 (_taskAllocationRuleRepository.Where(t => t.TrialId == subjectVisit.TrialId && t.IsEnable).Count() < 2)
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException("能参与读片的医生数量必须大于2,自动分配任务中止");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trialConfig.TaskAllocateDefaultState == TaskAllocateDefaultState.Allocated)
|
||||||
|
{
|
||||||
|
task1.TaskState = TaskState.Allocated;
|
||||||
|
task2.TaskState = TaskState.Allocated;
|
||||||
|
}
|
||||||
|
else if (trialConfig.TaskAllocateDefaultState == TaskAllocateDefaultState.InitAllocated)
|
||||||
|
{
|
||||||
|
task1.TaskState = TaskState.InitAllocated;
|
||||||
|
task2.TaskState = TaskState.InitAllocated;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trialConfig.TaskAllocateObjEnum == TaskAllocateObj.Subject)
|
||||||
|
{
|
||||||
|
|
||||||
|
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 (allocateSubjectArmList.GroupBy(t => t.DoctorUserId).Any(g => g.Count() == 2))
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException("请确认是否改了配置,导致同一受试者 分配给同一个医生 在不同的Arm,无法完成自动分配");
|
||||||
|
}
|
||||||
|
|
||||||
|
//手动分配的时候 如果只分配了Arm1 没有分配Arm2 就会有问题
|
||||||
|
if (!(allocateSubjectArmList.Any(t => t.ArmEnum == 1) && allocateSubjectArmList.Any(t => t.ArmEnum == 2)))
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException("请确认是否改了配置,或者手动分配时,只分配了一个Arm ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//分配给对应Arm的人
|
||||||
|
task1.DoctorUserId = allocateSubjectArmList.FirstOrDefault(t => t.ArmEnum == 1).DoctorUserId;
|
||||||
|
task2.DoctorUserId = allocateSubjectArmList.FirstOrDefault(t => t.ArmEnum == 2).DoctorUserId;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task1.AllocateTime = DateTime.Now;
|
||||||
|
task2.AllocateTime = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (trialConfig.ReadingType == ReadingMethod.Single)
|
||||||
|
{
|
||||||
|
if (_taskAllocationRuleRepository.Where(t => t.TrialId == subjectVisit.TrialId && t.IsEnable).Count() < 2)
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException("能参与读片的医生数量必须大于2,自动分配任务中止");
|
||||||
|
}
|
||||||
|
|
||||||
|
var singleTask = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
|
{
|
||||||
|
TrialId = subjectVisit.TrialId,
|
||||||
|
SubjectId = subjectVisit.SubjectId,
|
||||||
|
IsUrgent = subjectVisit.IsUrgent,
|
||||||
|
TaskBlindName = subjectVisit.BlindName,
|
||||||
|
TaskName = subjectVisit.VisitName,
|
||||||
|
CheckPassedTime = subjectVisit.CheckPassedTime,
|
||||||
|
ArmEnum = 0, //特殊
|
||||||
|
Code = currentMaxCodeInt + 1,
|
||||||
|
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
||||||
|
ReadingCategory = ReadingCategory.Visit
|
||||||
|
});
|
||||||
|
|
||||||
|
currentMaxCodeInt = currentMaxCodeInt + 1;
|
||||||
|
|
||||||
|
_provider.Set<int>($"{trialId }_{ StaticData.CacheKey.TaskMaxCode}", currentMaxCodeInt + 1, TimeSpan.FromMinutes(30));
|
||||||
|
|
||||||
|
#region 分配
|
||||||
|
if (isAssignSubjectToDoctor)
|
||||||
|
{
|
||||||
|
if (trialConfig.TaskAllocateDefaultState == TaskAllocateDefaultState.Allocated)
|
||||||
|
{
|
||||||
|
singleTask.TaskState = TaskState.Allocated;
|
||||||
|
}
|
||||||
|
else if (trialConfig.TaskAllocateDefaultState == TaskAllocateDefaultState.InitAllocated)
|
||||||
|
{
|
||||||
|
singleTask.TaskState = TaskState.InitAllocated;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trialConfig.TaskAllocateObjEnum == TaskAllocateObj.Subject)
|
||||||
|
{
|
||||||
|
//该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)
|
||||||
|
{
|
||||||
|
singleTask.DoctorUserId = allocateSubjectArmList.FirstOrDefault(t => t.ArmEnum == 0).DoctorUserId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
singleTask.AllocateTime = DateTime.Now;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
await _subjectVisitRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trialId && t.Id == subjectVisit.Id, u => new SubjectVisit() { IsVisitTaskGenerated = true });
|
||||||
|
await _visitTaskRepository.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,8 @@ using IRaCIS.Core.Domain.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using IRaCIS.Core.Application.Interfaces;
|
using IRaCIS.Core.Application.Interfaces;
|
||||||
using IRaCIS.Core.Application.ViewModel;
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Service
|
namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -18,15 +20,26 @@ namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly IRepository<VisitTask> _visitTaskRepository;
|
private readonly IRepository<VisitTask> _visitTaskRepository;
|
||||||
|
private readonly IRepository<Trial> _trialRepository;
|
||||||
|
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
|
||||||
|
|
||||||
public VisitTaskService(IRepository<VisitTask> visitTaskRepository)
|
|
||||||
|
public VisitTaskService(IRepository<VisitTask> visitTaskRepository, IRepository<Trial> trialRepository, IRepository<SubjectVisit> subjectVisitRepository)
|
||||||
{
|
{
|
||||||
_visitTaskRepository = visitTaskRepository;
|
_visitTaskRepository = visitTaskRepository;
|
||||||
|
_trialRepository = trialRepository;
|
||||||
|
_subjectVisitRepository = subjectVisitRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<PageOutput<VisitTaskView>> GetVisitTaskList(VisitTaskQuery queryVisitTask)
|
public async Task<PageOutput<VisitTaskView>> GetVisitTaskList(VisitTaskQuery queryVisitTask, [FromServices] IVisitTaskHelpeService _visitTaskCommonService)
|
||||||
{
|
{
|
||||||
|
var trialId = queryVisitTask.TrialId;
|
||||||
|
//以前访视未产生任务的,在查询这里要产生 后期维护到一块
|
||||||
|
|
||||||
|
var svIdList = await _subjectVisitRepository.Where(t => t.TrialId == trialId && t.CheckState == CheckStateEnum.CVPassed && t.IsVisitTaskGenerated == false).Select(t => t.Id).ToListAsync();
|
||||||
|
await _visitTaskCommonService.GenerateVisitTaskAsync(trialId,svIdList);
|
||||||
|
|
||||||
|
|
||||||
var visitTaskQueryable = _visitTaskRepository.Where(t => t.TrialId == queryVisitTask.TrialId)
|
var visitTaskQueryable = _visitTaskRepository.Where(t => t.TrialId == queryVisitTask.TrialId)
|
||||||
.WhereIf(queryVisitTask.SiteId != null, t => t.Subject.SiteId == queryVisitTask.SiteId)
|
.WhereIf(queryVisitTask.SiteId != null, t => t.Subject.SiteId == queryVisitTask.SiteId)
|
||||||
|
|
|
@ -9,6 +9,7 @@ using IRaCIS.Core.Application.Auth;
|
||||||
using IRaCIS.Core.Application.Service.Reading.Dto;
|
using IRaCIS.Core.Application.Service.Reading.Dto;
|
||||||
using IRaCIS.Core.Domain.Share.Reading;
|
using IRaCIS.Core.Domain.Share.Reading;
|
||||||
using MassTransit;
|
using MassTransit;
|
||||||
|
|
||||||
using IRaCIS.Core.Infra.EFCore.Common;
|
using IRaCIS.Core.Infra.EFCore.Common;
|
||||||
using IRaCIS.Core.Infrastructure.Extention;
|
using IRaCIS.Core.Infrastructure.Extention;
|
||||||
|
|
||||||
|
@ -115,7 +116,9 @@ namespace IRaCIS.Application.Services
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<PageOutput<PreviewTheReadingListOutDto>> GetPreviewTheReadingList(PreviewTheReadingListInDto inDto)
|
public async Task<PageOutput<PreviewTheReadingListOutDto>> GetPreviewTheReadingList(PreviewTheReadingListInDto inDto)
|
||||||
{
|
{
|
||||||
var visitQuery = _subjectVisitRepository.Where(x => x.TrialId == inDto.TrialId &&x.LatestScanDate!=null)
|
|
||||||
|
|
||||||
|
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));
|
.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);
|
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))
|
visitQuery = visitQuery.Where(x => !existsBubjectVisitsQuery.Contains(x.Id))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using EasyCaching.Core;
|
using EasyCaching.Core;
|
||||||
using EntityFrameworkCore.Triggered;
|
using EntityFrameworkCore.Triggered;
|
||||||
|
using IRaCIS.Core.Application.Service;
|
||||||
using IRaCIS.Core.Application.ViewModel;
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
using IRaCIS.Core.Infrastructure;
|
using IRaCIS.Core.Infrastructure;
|
||||||
|
@ -19,6 +20,7 @@ namespace IRaCIS.Core.Application.Triggers
|
||||||
private readonly IRepository<TaskAllocationRule> _taskAllocationRuleRepository;
|
private readonly IRepository<TaskAllocationRule> _taskAllocationRuleRepository;
|
||||||
|
|
||||||
private readonly IEasyCachingProvider _provider;
|
private readonly IEasyCachingProvider _provider;
|
||||||
|
private readonly IVisitTaskHelpeService _visitTaskHelpeService;
|
||||||
|
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
|
@ -26,6 +28,7 @@ namespace IRaCIS.Core.Application.Triggers
|
||||||
IRepository<Trial> trialRepository,
|
IRepository<Trial> trialRepository,
|
||||||
IRepository<TaskAllocationRule> taskAllocationRuleRepository,
|
IRepository<TaskAllocationRule> taskAllocationRuleRepository,
|
||||||
IEasyCachingProvider provider,
|
IEasyCachingProvider provider,
|
||||||
|
IVisitTaskHelpeService visitTaskHelpeService,
|
||||||
IMapper mapper)
|
IMapper mapper)
|
||||||
{
|
{
|
||||||
_subjectVisitRepository = subjectVisitRepository;
|
_subjectVisitRepository = subjectVisitRepository;
|
||||||
|
@ -34,6 +37,7 @@ namespace IRaCIS.Core.Application.Triggers
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_taskAllocationRuleRepository = taskAllocationRuleRepository;
|
_taskAllocationRuleRepository = taskAllocationRuleRepository;
|
||||||
_trialRepository = trialRepository;
|
_trialRepository = trialRepository;
|
||||||
|
_visitTaskHelpeService = visitTaskHelpeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AfterSave(ITriggerContext<SubjectVisit> context, CancellationToken cancellationToken)
|
public async Task AfterSave(ITriggerContext<SubjectVisit> context, CancellationToken cancellationToken)
|
||||||
|
@ -49,150 +53,185 @@ namespace IRaCIS.Core.Application.Triggers
|
||||||
if (context.UnmodifiedEntity?.CheckState != subjectVisit.CheckState && subjectVisit.CheckState == CheckStateEnum.CVPassed)
|
if (context.UnmodifiedEntity?.CheckState != subjectVisit.CheckState && subjectVisit.CheckState == CheckStateEnum.CVPassed)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (_taskAllocationRuleRepository.Where(t => t.TrialId == subjectVisit.TrialId && t.IsEnable).Count() < 2)
|
#region 产生任务并分配 暂时废弃
|
||||||
{
|
|
||||||
throw new BusinessValidationFailedException("能参与读片的医生数量必须大于2,自动分配任务中止");
|
|
||||||
}
|
|
||||||
|
|
||||||
var dbMaxCode = _visitTaskRepository.Where(t => t.TrialId == subjectVisit.TrialId).Select(t => t.Code).DefaultIfEmpty().Max();
|
//if (_taskAllocationRuleRepository.Where(t => t.TrialId == subjectVisit.TrialId && t.IsEnable).Count() < 2)
|
||||||
|
//{
|
||||||
|
// throw new BusinessValidationFailedException("能参与读片的医生数量必须大于2,自动分配任务中止");
|
||||||
|
//}
|
||||||
|
|
||||||
var cacheMaxCodeInt = _provider.Get<int>($"{subjectVisit.TrialId }_{ StaticData.CacheKey.TaskMaxCode}").Value;
|
//var dbMaxCode = _visitTaskRepository.Where(t => t.TrialId == subjectVisit.TrialId).Select(t => t.Code).DefaultIfEmpty().Max();
|
||||||
|
|
||||||
int currentMaxCodeInt = cacheMaxCodeInt > dbMaxCode ? cacheMaxCodeInt : dbMaxCode;
|
//var cacheMaxCodeInt = _provider.Get<int>($"{subjectVisit.TrialId }_{ StaticData.CacheKey.TaskMaxCode}").Value;
|
||||||
|
|
||||||
_provider.Set<int>($"{subjectVisit.TrialId }_{ StaticData.CacheKey.TaskMaxCode}", currentMaxCodeInt + 2, TimeSpan.FromMinutes(30));
|
//int currentMaxCodeInt = cacheMaxCodeInt > dbMaxCode ? cacheMaxCodeInt : dbMaxCode;
|
||||||
|
|
||||||
var trialConfig = (await _trialRepository.Where(t => t.Id == subjectVisit.TrialId).Select(t => new { TrialId = t.Id, t.ReadingType, t.TaskAllocateDefaultState, t.TaskAllocateObjEnum }).FirstOrDefaultAsync()).IfNullThrowException();
|
//_provider.Set<int>($"{subjectVisit.TrialId }_{ StaticData.CacheKey.TaskMaxCode}", currentMaxCodeInt + 2, TimeSpan.FromMinutes(30));
|
||||||
|
|
||||||
//统计当前医生分配信息 有效医生数量必须大于2 已做验证
|
//var trialConfig = (await _trialRepository.Where(t => t.Id == subjectVisit.TrialId).Select(t => new { TrialId = t.Id, t.ReadingType, t.TaskAllocateDefaultState, t.TaskAllocateObjEnum }).FirstOrDefaultAsync()).IfNullThrowException();
|
||||||
var allocateStat = _taskAllocationRuleRepository.Where(t => t.TrialId == subjectVisit.TrialId && t.IsEnable).ProjectTo<AllocateInfo>(_mapper.ConfigurationProvider).ToList();
|
|
||||||
|
|
||||||
if (trialConfig.ReadingType == ReadingMethod.Double)
|
////统计当前医生分配信息 有效医生数量必须大于2 已做验证
|
||||||
{
|
//var allocateStat = _taskAllocationRuleRepository.Where(t => t.TrialId == subjectVisit.TrialId && t.IsEnable).ProjectTo<AllocateInfo>(_mapper.ConfigurationProvider).ToList();
|
||||||
|
|
||||||
//每个访视 根据项目配置生成任务 双审生成两个
|
//if (trialConfig.ReadingType == ReadingMethod.Double)
|
||||||
var task1 = await _visitTaskRepository.AddAsync(new VisitTask()
|
//{
|
||||||
{
|
|
||||||
TrialId = subjectVisit.TrialId,
|
|
||||||
SubjectId = subjectVisit.SubjectId,
|
|
||||||
IsUrgent = subjectVisit.IsUrgent,
|
|
||||||
TaskBlindName = subjectVisit.BlindName,
|
|
||||||
TaskName = subjectVisit.VisitName,
|
|
||||||
CheckPassedTime = subjectVisit.CheckPassedTime,
|
|
||||||
ArmEnum = 1,//特殊
|
|
||||||
Code = currentMaxCodeInt + 1,
|
|
||||||
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
|
||||||
ReadingCategory = ReadingCategory.Visit
|
|
||||||
});
|
|
||||||
|
|
||||||
var task2 = await _visitTaskRepository.AddAsync(new VisitTask()
|
// //每个访视 根据项目配置生成任务 双审生成两个
|
||||||
{
|
// var task1 = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
TrialId = subjectVisit.TrialId,
|
// {
|
||||||
SubjectId = subjectVisit.SubjectId,
|
// TrialId = subjectVisit.TrialId,
|
||||||
IsUrgent = subjectVisit.IsUrgent,
|
// SubjectId = subjectVisit.SubjectId,
|
||||||
TaskBlindName = subjectVisit.BlindName,
|
// IsUrgent = subjectVisit.IsUrgent,
|
||||||
TaskName = subjectVisit.VisitName,
|
// TaskBlindName = subjectVisit.BlindName,
|
||||||
CheckPassedTime = subjectVisit.CheckPassedTime,
|
// TaskName = subjectVisit.VisitName,
|
||||||
ArmEnum = 2,//特殊
|
// CheckPassedTime = subjectVisit.CheckPassedTime,
|
||||||
Code = currentMaxCodeInt + 2,
|
// ArmEnum = 1,//特殊
|
||||||
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 2, nameof(VisitTask)),
|
// Code = currentMaxCodeInt + 1,
|
||||||
ReadingCategory = ReadingCategory.Visit
|
// TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
||||||
});
|
// ReadingCategory = ReadingCategory.Visit
|
||||||
|
// });
|
||||||
|
|
||||||
|
// var task2 = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
|
// {
|
||||||
|
// TrialId = subjectVisit.TrialId,
|
||||||
|
// SubjectId = subjectVisit.SubjectId,
|
||||||
|
// IsUrgent = subjectVisit.IsUrgent,
|
||||||
|
// TaskBlindName = subjectVisit.BlindName,
|
||||||
|
// TaskName = subjectVisit.VisitName,
|
||||||
|
// CheckPassedTime = subjectVisit.CheckPassedTime,
|
||||||
|
// ArmEnum = 2,//特殊
|
||||||
|
// Code = currentMaxCodeInt + 2,
|
||||||
|
// TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 2, nameof(VisitTask)),
|
||||||
|
// ReadingCategory = ReadingCategory.Visit
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
if (trialConfig.TaskAllocateDefaultState == TaskAllocateDefaultState.Allocated)
|
// if (trialConfig.TaskAllocateDefaultState == TaskAllocateDefaultState.Allocated)
|
||||||
{
|
// {
|
||||||
task1.TaskState =TaskState.Allocated;
|
// task1.TaskState = TaskState.Allocated;
|
||||||
task2.TaskState = TaskState.Allocated;
|
// task2.TaskState = TaskState.Allocated;
|
||||||
}
|
// }
|
||||||
else if (trialConfig.TaskAllocateDefaultState == TaskAllocateDefaultState.InitAllocated)
|
// else if (trialConfig.TaskAllocateDefaultState == TaskAllocateDefaultState.InitAllocated)
|
||||||
{
|
// {
|
||||||
task1.TaskState = TaskState.InitAllocated;
|
// task1.TaskState = TaskState.InitAllocated;
|
||||||
task2.TaskState = TaskState.InitAllocated;
|
// task2.TaskState = TaskState.InitAllocated;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (trialConfig.TaskAllocateObjEnum == TaskAllocateObj.Subject)
|
// if (trialConfig.TaskAllocateObjEnum == TaskAllocateObj.Subject)
|
||||||
{
|
// {
|
||||||
|
|
||||||
//该Subject 之前是否有已分配的 如果改变配置 可能会出现 一个Subject 分配的同一个医生 有的在Arm1 有的在Arm2
|
// //该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();
|
// 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 (allocateSubjectArmList.Count == 0)
|
||||||
{
|
// {
|
||||||
//排除已经入选其他Arm的阅片人
|
// //排除已经入选其他Arm的阅片人
|
||||||
|
|
||||||
//是否有做过Arm1的医生 有新的医生未分配 按照最优法找
|
// //是否有做过Arm1的医生 没有新的医生未分配
|
||||||
if (allocateStat.Any(t => t.ArmList.Any(t => t == 1)) && !allocateStat.Any(t=>t.ArmList.Count==0))
|
// if (allocateStat.Any(t => t.ArmList.Any(t => t == 1)) && !allocateStat.Any(t => t.ArmList.Count == 0))
|
||||||
{
|
// {
|
||||||
|
|
||||||
task1.DoctorUserId = allocateStat.Where(t => t.ArmList.Any(t => t == 1)).OrderByDescending(t => t.TotalTaskCount * t.PlanReadingRatio * 0.01 - t.SelfTaskCount).ThenByDescending(t => t.PlanReadingRatio).FirstOrDefault().DoctorUserId;
|
// task1.DoctorUserId = allocateStat.Where(t => t.ArmList.Any(t => t == 1)).OrderByDescending(t => t.TotalTaskCount * t.PlanReadingRatio * 0.01 - t.SelfTaskCount).ThenByDescending(t => t.PlanReadingRatio).FirstOrDefault().DoctorUserId;
|
||||||
|
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
//找到最优的需要分配任务的医生
|
// //找到最优的需要分配任务的医生
|
||||||
task1.DoctorUserId = allocateStat.OrderByDescending(t => t.TotalTaskCount * t.PlanReadingRatio * 0.01 - t.SelfTaskCount).ThenByDescending(t => t.PlanReadingRatio).FirstOrDefault().DoctorUserId;
|
// task1.DoctorUserId = allocateStat.OrderByDescending(t => t.TotalTaskCount * t.PlanReadingRatio * 0.01 - t.SelfTaskCount).ThenByDescending(t => t.PlanReadingRatio).FirstOrDefault().DoctorUserId;
|
||||||
|
|
||||||
allocateStat.FirstOrDefault(t => t.DoctorUserId == task1.DoctorUserId).ArmList.Add(1);
|
// //分配之后,加入进去
|
||||||
}
|
// allocateStat.FirstOrDefault(t => t.DoctorUserId == task1.DoctorUserId).ArmList.Add(1);
|
||||||
|
// }
|
||||||
//是否有做过Arm2的医生 有新的医生未分配 按照最优法找
|
|
||||||
if (allocateStat.Any(t => t.ArmList.Any(t => t == 2)) && !allocateStat.Any(t => t.ArmList.Count == 0))
|
|
||||||
{
|
|
||||||
|
|
||||||
task2.DoctorUserId = allocateStat.Where(t => t.ArmList.Any(t => t == 2)).OrderByDescending(t => t.TotalTaskCount * t.PlanReadingRatio * 0.01 - t.SelfTaskCount).ThenByDescending(t => t.PlanReadingRatio).FirstOrDefault().DoctorUserId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//找到最优的需要分配任务的医生
|
|
||||||
task2.DoctorUserId = allocateStat.OrderByDescending(t => t.TotalTaskCount * t.PlanReadingRatio * 0.01 - t.SelfTaskCount).ThenByDescending(t => t.PlanReadingRatio).Skip(1).FirstOrDefault().DoctorUserId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (allocateSubjectArmList.GroupBy(t => t.DoctorUserId).Any(g => g.Count() == 2))
|
|
||||||
{
|
|
||||||
throw new BusinessValidationFailedException("请确认是否改了配置,导致同一受试者 分配给同一个医生 在不同的Arm,无法完成自动分配");
|
|
||||||
}
|
|
||||||
|
|
||||||
//手动分配的时候 如果只分配了Arm1 没有分配Arm2 就会有问题
|
|
||||||
if (!(allocateSubjectArmList.Any(t => t.ArmEnum == 1) && allocateSubjectArmList.Any(t => t.ArmEnum == 2)))
|
|
||||||
{
|
|
||||||
throw new BusinessValidationFailedException("请确认是否改了配置,或者手动分配时,只分配了一个Arm ");
|
|
||||||
}
|
|
||||||
|
|
||||||
//分配给对应Arm的人
|
|
||||||
task1.DoctorUserId = allocateSubjectArmList.FirstOrDefault(t => t.ArmEnum == 1).DoctorUserId;
|
|
||||||
task2.DoctorUserId = allocateSubjectArmList.FirstOrDefault(t => t.ArmEnum == 2).DoctorUserId;
|
|
||||||
}
|
|
||||||
|
|
||||||
task1.AllocateTime = DateTime.Now;
|
|
||||||
task2.AllocateTime = DateTime.Now;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (trialConfig.ReadingType == ReadingMethod.Single)
|
|
||||||
{
|
|
||||||
await _visitTaskRepository.AddAsync(new VisitTask()
|
|
||||||
{
|
|
||||||
TrialId = subjectVisit.TrialId,
|
|
||||||
SubjectId = subjectVisit.SubjectId,
|
|
||||||
IsUrgent = subjectVisit.IsUrgent,
|
|
||||||
TaskBlindName = subjectVisit.BlindName,
|
|
||||||
TaskName = subjectVisit.VisitName,
|
|
||||||
CheckPassedTime = subjectVisit.CheckPassedTime,
|
|
||||||
ArmEnum = 0, //特殊
|
|
||||||
Code = currentMaxCodeInt + 1,
|
|
||||||
TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
|
||||||
ReadingCategory = ReadingCategory.Visit
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
await _visitTaskRepository.SaveChangesAsync();
|
// //是否有做过Arm2的医生 有新的医生未分配 按照最优法找
|
||||||
|
// if (allocateStat.Any(t => t.ArmList.Any(t => t == 2)) && !allocateStat.Any(t => t.ArmList.Count == 0))
|
||||||
|
// {
|
||||||
|
|
||||||
|
// task2.DoctorUserId = allocateStat.Where(t => t.ArmList.Any(t => t == 2)).OrderByDescending(t => t.TotalTaskCount * t.PlanReadingRatio * 0.01 - t.SelfTaskCount).ThenByDescending(t => t.PlanReadingRatio).FirstOrDefault().DoctorUserId;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// //找到最优的需要分配任务的医生
|
||||||
|
// task2.DoctorUserId = allocateStat.OrderByDescending(t => t.TotalTaskCount * t.PlanReadingRatio * 0.01 - t.SelfTaskCount).ThenByDescending(t => t.PlanReadingRatio).Skip(1).FirstOrDefault().DoctorUserId;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// if (allocateSubjectArmList.GroupBy(t => t.DoctorUserId).Any(g => g.Count() == 2))
|
||||||
|
// {
|
||||||
|
// throw new BusinessValidationFailedException("请确认是否改了配置,导致同一受试者 分配给同一个医生 在不同的Arm,无法完成自动分配");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //手动分配的时候 如果只分配了Arm1 没有分配Arm2 就会有问题
|
||||||
|
// if (!(allocateSubjectArmList.Any(t => t.ArmEnum == 1) && allocateSubjectArmList.Any(t => t.ArmEnum == 2)))
|
||||||
|
// {
|
||||||
|
// throw new BusinessValidationFailedException("请确认是否改了配置,或者手动分配时,只分配了一个Arm ");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //分配给对应Arm的人
|
||||||
|
// task1.DoctorUserId = allocateSubjectArmList.FirstOrDefault(t => t.ArmEnum == 1).DoctorUserId;
|
||||||
|
// task2.DoctorUserId = allocateSubjectArmList.FirstOrDefault(t => t.ArmEnum == 2).DoctorUserId;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// task1.AllocateTime = DateTime.Now;
|
||||||
|
// task2.AllocateTime = DateTime.Now;
|
||||||
|
// }
|
||||||
|
|
||||||
|
//}
|
||||||
|
//else if (trialConfig.ReadingType == ReadingMethod.Single)
|
||||||
|
//{
|
||||||
|
// var singleTask = await _visitTaskRepository.AddAsync(new VisitTask()
|
||||||
|
// {
|
||||||
|
// TrialId = subjectVisit.TrialId,
|
||||||
|
// SubjectId = subjectVisit.SubjectId,
|
||||||
|
// IsUrgent = subjectVisit.IsUrgent,
|
||||||
|
// TaskBlindName = subjectVisit.BlindName,
|
||||||
|
// TaskName = subjectVisit.VisitName,
|
||||||
|
// CheckPassedTime = subjectVisit.CheckPassedTime,
|
||||||
|
// ArmEnum = 0, //特殊
|
||||||
|
// Code = currentMaxCodeInt + 1,
|
||||||
|
// TaskCode = AppSettings.GetCodeStr(currentMaxCodeInt + 1, nameof(VisitTask)),
|
||||||
|
// ReadingCategory = ReadingCategory.Visit
|
||||||
|
// });
|
||||||
|
|
||||||
|
// if (trialConfig.TaskAllocateDefaultState == TaskAllocateDefaultState.Allocated)
|
||||||
|
// {
|
||||||
|
// singleTask.TaskState = TaskState.Allocated;
|
||||||
|
// }
|
||||||
|
// else if (trialConfig.TaskAllocateDefaultState == TaskAllocateDefaultState.InitAllocated)
|
||||||
|
// {
|
||||||
|
// singleTask.TaskState = TaskState.InitAllocated;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (trialConfig.TaskAllocateObjEnum == TaskAllocateObj.Subject)
|
||||||
|
// {
|
||||||
|
// //该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)
|
||||||
|
// {
|
||||||
|
// singleTask.DoctorUserId = allocateStat.OrderByDescending(t => t.TotalTaskCount * t.PlanReadingRatio * 0.01 - t.SelfTaskCount).ThenByDescending(t => t.PlanReadingRatio).FirstOrDefault().DoctorUserId;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// singleTask.DoctorUserId = allocateSubjectArmList.FirstOrDefault(t => t.ArmEnum == 0).DoctorUserId;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
//await _visitTaskRepository.SaveChangesAsync();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
await _visitTaskHelpeService.GenerateVisitTaskAsync(subjectVisit.TrialId, new List<Guid>() { subjectVisit.Id }, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,6 +155,8 @@ namespace IRaCIS.Core.Domain.Models
|
||||||
|
|
||||||
public bool IsEnrollmentConfirm { get; set; }
|
public bool IsEnrollmentConfirm { get; set; }
|
||||||
|
|
||||||
|
public bool IsVisitTaskGenerated { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 关闭一致性质疑原因
|
/// 关闭一致性质疑原因
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -825,8 +825,6 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
||||||
entityTypeName = "New/" + "UserSigned";
|
entityTypeName = "New/" + "UserSigned";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dynamic entity;
|
dynamic entity;
|
||||||
switch (entityobj.GetType().Name)
|
switch (entityobj.GetType().Name)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue