2079 lines
118 KiB
C#
2079 lines
118 KiB
C#
//--------------------------------------------------------------------
|
||
// 此代码由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 IRaCIS.Core.Domain.Share;
|
||
using IRaCIS.Core.Infrastructure;
|
||
using IRaCIS.Core.Application.Contracts;
|
||
using IRaCIS.Core.Infra.EFCore.Common;
|
||
using System.Linq.Expressions;
|
||
using IRaCIS.Application.Contracts;
|
||
using IRaCIS.Core.Application.Filter;
|
||
using DocumentFormat.OpenXml.Office2010.Word;
|
||
using System.Linq.Dynamic.Core;
|
||
using System.Linq;
|
||
using DocumentFormat.OpenXml.Bibliography;
|
||
using Org.BouncyCastle.Crypto;
|
||
using IRaCIS.Core.Domain.Share.Reading;
|
||
using Quartz;
|
||
using IRaCIS.Application.Services.BackGroundJob;
|
||
|
||
namespace IRaCIS.Core.Application.Service.Allocation
|
||
{
|
||
/// <summary>
|
||
/// 访视读片任务
|
||
/// </summary>
|
||
[ApiExplorerSettings(GroupName = "Trial")]
|
||
public class VisitTaskService : BaseService, IVisitTaskService
|
||
{
|
||
|
||
private readonly IRepository<VisitTask> _visitTaskRepository;
|
||
private readonly IRepository<Trial> _trialRepository;
|
||
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
|
||
private readonly IRepository<TaskAllocationRule> _taskAllocationRuleRepository;
|
||
private readonly IRepository<Subject> _subjectRepository;
|
||
private readonly IRepository<SubjectUser> _subjectUserRepository;
|
||
private readonly IRepository<ReadModule> _readModuleRepository;
|
||
|
||
private readonly IRepository<VisitTaskReReading> _visitTaskReReadingRepository;
|
||
private readonly IRepository<TaskMedicalReview> _taskMedicalReviewRepository;
|
||
private readonly IRepository<ReadingTaskQuestionAnswer> _readingTaskQuestionAnswerRepository;
|
||
|
||
private readonly IRepository<ReadingClinicalData> _readingClinicalDataReposiotry;
|
||
private readonly IRepository<SubjectCriteriaEvaluation> _subjectCriteriaEvaluationRepository;
|
||
private readonly IRepository<SubjectCriteriaEvaluationVisitFilter> _subjectCriteriaEvaluationVisitFilterRepository;
|
||
|
||
private readonly IRepository<ReadingQuestionCriterionTrial> _trialReadingCriterionRepository;
|
||
private readonly IRepository<SubjectCriteriaEvaluationVisitStudyFilter> _subjectCriteriaEvaluationVisitStudyFilterRepository;
|
||
|
||
public VisitTaskService(IRepository<SubjectVisit> subjectVisitRepository, IRepository<VisitTask> visitTaskRepository, IRepository<Trial> trialRepository,
|
||
IRepository<Subject> subjectRepository, IRepository<SubjectUser> subjectUserRepository, IRepository<TaskAllocationRule> taskAllocationRuleRepository,
|
||
IRepository<ReadModule> readModuleRepository, IRepository<VisitTaskReReading> visitTaskReReadingRepository,
|
||
IRepository<TaskMedicalReview> taskMedicalReviewRepository,
|
||
IRepository<ReadingTaskQuestionAnswer> readingTaskQuestionAnswerRepository
|
||
, IRepository<ReadingQuestionCriterionTrial> trialReadingCriterionRepository,
|
||
IRepository<ReadingClinicalData> readingClinicalDataReposiotry,
|
||
IRepository<SubjectCriteriaEvaluation> subjectCriteriaEvaluationRepository,
|
||
IRepository<SubjectCriteriaEvaluationVisitFilter> subjectCriteriaEvaluationVisitFilterRepository,
|
||
IRepository<SubjectCriteriaEvaluationVisitStudyFilter> subjectCriteriaEvaluationVisitStudyFilterRepository
|
||
)
|
||
{
|
||
_readingClinicalDataReposiotry = readingClinicalDataReposiotry;
|
||
_taskAllocationRuleRepository = taskAllocationRuleRepository;
|
||
_visitTaskRepository = visitTaskRepository;
|
||
_trialRepository = trialRepository;
|
||
_subjectVisitRepository = subjectVisitRepository;
|
||
_subjectRepository = subjectRepository;
|
||
_subjectUserRepository = subjectUserRepository;
|
||
_readModuleRepository = readModuleRepository;
|
||
_visitTaskReReadingRepository = visitTaskReReadingRepository;
|
||
_taskMedicalReviewRepository = taskMedicalReviewRepository;
|
||
_readingTaskQuestionAnswerRepository = readingTaskQuestionAnswerRepository;
|
||
|
||
_trialReadingCriterionRepository = trialReadingCriterionRepository;
|
||
_subjectCriteriaEvaluationRepository = subjectCriteriaEvaluationRepository;
|
||
_subjectCriteriaEvaluationVisitFilterRepository = subjectCriteriaEvaluationVisitFilterRepository;
|
||
_subjectCriteriaEvaluationVisitStudyFilterRepository = subjectCriteriaEvaluationVisitStudyFilterRepository;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置任务加急
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<bool> SetTaskUrgent(SetTaskUrgentInDto inDto)
|
||
{
|
||
await _visitTaskRepository.UpdatePartialFromQueryAsync(inDto.VisitTaskId, x => new VisitTask()
|
||
{
|
||
IsUrgent = inDto.IsUrgent,
|
||
TaskUrgentType = inDto.TaskUrgentType,
|
||
TaskUrgentRemake = inDto.TaskUrgentRemake,
|
||
|
||
});
|
||
|
||
return await _visitTaskRepository.SaveChangesAsync();
|
||
}
|
||
|
||
public async Task<List<TrialReadingCriterionDto>> GetTrialCriterionList(Guid trialId, bool isHaveSigned = true, bool? isAutoCreate = null)
|
||
{
|
||
var list = await _repository.Where<ReadingQuestionCriterionTrial>(t => t.TrialId == trialId && t.IsConfirm)
|
||
|
||
.OrderBy(t => t.ShowOrder)
|
||
.Select(t => new TrialReadingCriterionDto() { TrialReadingCriterionId = t.Id, IsAutoCreate = t.IsAutoCreate, IsAdditionalAssessment = t.IsAdditionalAssessment, TrialReadingCriterionName = t.CriterionName, CriterionType = t.CriterionType, ReadingType = t.ReadingType, ReadingInfoSignTime = t.ReadingInfoSignTime })
|
||
.ToListAsync();
|
||
|
||
//if (list.Count == 0)
|
||
//{
|
||
// //---该项目还未确认任何一个阅片标准
|
||
// throw new BusinessValidationFailedException(_localizer["VisitTask_VisitTask_TaskAlreadyApplied"]);
|
||
|
||
//}
|
||
|
||
|
||
return list.AsQueryable().WhereIf(isHaveSigned == true, t => t.ReadingInfoSignTime != null)
|
||
.WhereIf(isAutoCreate == false, t => t.IsAutoCreate == isAutoCreate).ToList();
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// Subject 任务类型 统计 +分配情况
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<(PageOutput<SubjectAssignStat>, object?)> GetSubjectAssignAndTaskStatList(SubjectAssignStatQuery querySubjectAssign)
|
||
{
|
||
|
||
var isAddtinoarlCriterion = await _trialReadingCriterionRepository.AnyAsync(t => t.Id == querySubjectAssign.TrialReadingCriterionId && t.IsAutoCreate == false);
|
||
|
||
var subjectQuery = _subjectRepository.Where(t => t.TrialId == querySubjectAssign.TrialId && t.SubjectVisitTaskList.Any())
|
||
.WhereIf(querySubjectAssign.SiteId != null, t => t.SiteId == querySubjectAssign.SiteId)
|
||
.WhereIf(querySubjectAssign.SubjectId != null, t => t.Id == querySubjectAssign.SubjectId)
|
||
.WhereIf(querySubjectAssign.DoctorUserId != null, t => t.SubjectDoctorList.Any(t => t.DoctorUserId == querySubjectAssign.DoctorUserId && t.TrialReadingCriterionId == querySubjectAssign.TrialReadingCriterionId))
|
||
.WhereIf(!string.IsNullOrEmpty(querySubjectAssign.SubjectCode), t => t.Code.Contains(querySubjectAssign.SubjectCode))
|
||
.WhereIf(isAddtinoarlCriterion, t => t.SubjectCriteriaEvaluationList.Where(t => t.TrialReadingCriterionId == querySubjectAssign.TrialReadingCriterionId).Any(t => t.IsJoinEvaluation))
|
||
|
||
|
||
.ProjectTo<SubjectAssignStat>(_mapper.ConfigurationProvider, new { trialReadingCriterionId = querySubjectAssign.TrialReadingCriterionId });
|
||
|
||
|
||
var pageList = await subjectQuery.ToPagedListAsync(querySubjectAssign.PageIndex, querySubjectAssign.PageSize, string.IsNullOrWhiteSpace(querySubjectAssign.SortField) ? nameof(querySubjectAssign.SubjectId) : querySubjectAssign.SortField, querySubjectAssign.Asc);
|
||
|
||
|
||
|
||
var criterionConfig = (await _trialReadingCriterionRepository.Where(x => x.Id == querySubjectAssign.TrialReadingCriterionId).Select(x => new { x.ReadingTool, x.IsReadingTaskViewInOrder, x.ReadingType, x.IsArbitrationReading, x.IsOncologyReading, x.IsGlobalReading }).FirstOrDefaultAsync()).IfNullThrowException();
|
||
|
||
return (pageList, criterionConfig);
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 访视任务
|
||
/// </summary>
|
||
/// <param name="queryVisitTask"></param>
|
||
/// <param name="_visitTaskCommonService"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<PageOutput<VisitTaskView>> GetVisitTaskList(VisitTaskQuery queryVisitTask, [FromServices] IVisitTaskHelpeService _visitTaskCommonService)
|
||
{
|
||
//以前访视未产生任务的,在查询这里要产生
|
||
var svIdList = await _subjectVisitRepository.Where(t => t.TrialId == queryVisitTask.TrialId && t.CheckState == CheckStateEnum.CVPassed && t.IsVisitTaskGenerated == false).Select(t => t.Id).ToListAsync();
|
||
|
||
//之前没有生成任务的逻辑 但是现在加了,任务要自动生成
|
||
await _visitTaskCommonService.GenerateVisitTaskAsync(queryVisitTask.TrialId, svIdList);
|
||
|
||
|
||
var visitTaskQueryable = _visitTaskRepository.Where(t => t.TrialId == queryVisitTask.TrialId && t.IsAnalysisCreate == false)
|
||
.WhereIf(queryVisitTask.ReadingCategory != null, t => t.ReadingCategory == queryVisitTask.ReadingCategory)
|
||
.WhereIf(queryVisitTask.ReadingCategory == null, t => t.ReadingCategory != ReadingCategory.Judge)
|
||
|
||
.WhereIf(queryVisitTask.TaskState != null, t => t.TaskState == queryVisitTask.TaskState)
|
||
.WhereIf(queryVisitTask.SiteId != null, t => t.Subject.SiteId == queryVisitTask.SiteId)
|
||
.WhereIf(queryVisitTask.SubjectId != null, t => t.SubjectId == queryVisitTask.SubjectId)
|
||
.WhereIf(queryVisitTask.IsUrgent != null, t => t.IsUrgent == queryVisitTask.IsUrgent)
|
||
.WhereIf(queryVisitTask.DoctorUserId != null, t => t.DoctorUserId == queryVisitTask.DoctorUserId)
|
||
.WhereIf(queryVisitTask.ReadingCategory != null, t => t.ReadingCategory == queryVisitTask.ReadingCategory)
|
||
.WhereIf(queryVisitTask.TaskAllocationState != null, t => t.TaskAllocationState == queryVisitTask.TaskAllocationState)
|
||
.WhereIf(queryVisitTask.TrialReadingCriterionId != null, t => t.TrialReadingCriterionId == queryVisitTask.TrialReadingCriterionId)
|
||
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TrialSiteCode), t => (t.BlindTrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.IsAnalysisCreate) || (t.Subject.TrialSite.TrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.IsAnalysisCreate == false))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TaskName), t => t.TaskName.Contains(queryVisitTask.TaskName) || t.TaskBlindName.Contains(queryVisitTask.TaskName))
|
||
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.SubjectCode), t => (t.Subject.Code.Contains(queryVisitTask.SubjectCode) && t.IsAnalysisCreate == false) || (t.BlindSubjectCode.Contains(queryVisitTask.SubjectCode) && t.IsAnalysisCreate))
|
||
.WhereIf(queryVisitTask.BeginAllocateDate != null, t => t.AllocateTime > queryVisitTask.BeginAllocateDate)
|
||
.WhereIf(queryVisitTask.EndAllocateDate != null, t => t.AllocateTime < queryVisitTask.EndAllocateDate!.Value.AddDays(1))
|
||
.ProjectTo<VisitTaskView>(_mapper.ConfigurationProvider);
|
||
|
||
var defalutSortArray = new string[] { nameof(VisitTask.IsUrgent) + " desc", nameof(VisitTask.SubjectId), nameof(VisitTask.VisitTaskNum) };
|
||
|
||
var pageList = await visitTaskQueryable.ToPagedListAsync(queryVisitTask.PageIndex, queryVisitTask.PageSize, queryVisitTask.SortField, queryVisitTask.Asc, string.IsNullOrWhiteSpace(queryVisitTask.SortField), defalutSortArray);
|
||
|
||
//var trialTaskConfig = _trialRepository.Where(t => t.Id == queryVisitTask.TrialId).ProjectTo<TrialTaskConfigView>(_mapper.ConfigurationProvider).FirstOrDefault();
|
||
return pageList;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 裁判任务
|
||
/// </summary>
|
||
/// <param name="queryVisitTask"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<PageOutput<JudgeVisitTaskView>/*, object)*/> GetJudgeVisitTaskList(VisitTaskQuery queryVisitTask)
|
||
{
|
||
|
||
var visitTaskQueryable = _visitTaskRepository.Where(t => t.TrialId == queryVisitTask.TrialId && t.IsAnalysisCreate == false)
|
||
.Where(t => t.ReadingCategory == ReadingCategory.Judge)
|
||
|
||
.WhereIf(queryVisitTask.TaskState != null, t => t.TaskState == queryVisitTask.TaskState)
|
||
.WhereIf(queryVisitTask.ReadingCategory != null, t => t.ReadingCategory == queryVisitTask.ReadingCategory)
|
||
.WhereIf(queryVisitTask.SiteId != null, t => t.Subject.SiteId == queryVisitTask.SiteId)
|
||
.WhereIf(queryVisitTask.SubjectId != null, t => t.SubjectId == queryVisitTask.SubjectId)
|
||
.WhereIf(queryVisitTask.IsUrgent != null, t => t.IsUrgent == queryVisitTask.IsUrgent)
|
||
.WhereIf(queryVisitTask.DoctorUserId != null, t => t.DoctorUserId == queryVisitTask.DoctorUserId)
|
||
.WhereIf(queryVisitTask.TaskAllocationState != null, t => t.TaskAllocationState == queryVisitTask.TaskAllocationState)
|
||
.WhereIf(queryVisitTask.ReadingTaskState != null, t => t.ReadingTaskState == queryVisitTask.ReadingTaskState)
|
||
.WhereIf(queryVisitTask.TrialReadingCriterionId != null, t => t.TrialReadingCriterionId == queryVisitTask.TrialReadingCriterionId)
|
||
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TrialSiteCode), t => (t.BlindTrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.IsAnalysisCreate) || (t.Subject.TrialSite.TrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.IsAnalysisCreate == false))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TaskName), t => t.TaskName.Contains(queryVisitTask.TaskName) || t.TaskBlindName.Contains(queryVisitTask.TaskName))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.SubjectCode), t => (t.Subject.Code.Contains(queryVisitTask.SubjectCode) && t.IsAnalysisCreate == false) || (t.BlindSubjectCode.Contains(queryVisitTask.SubjectCode) && t.IsAnalysisCreate))
|
||
.WhereIf(queryVisitTask.BeginAllocateDate != null, t => t.AllocateTime > queryVisitTask.BeginAllocateDate)
|
||
.WhereIf(queryVisitTask.EndAllocateDate != null, t => t.AllocateTime < queryVisitTask.EndAllocateDate!.Value.AddDays(1))
|
||
.ProjectTo<JudgeVisitTaskView>(_mapper.ConfigurationProvider);
|
||
|
||
var defalutSortArray = new string[] { nameof(VisitTask.IsUrgent) + " desc", nameof(VisitTask.SubjectId), nameof(VisitTaskView.VisitTaskNum) };
|
||
|
||
var pageList = await visitTaskQueryable.ToPagedListAsync(queryVisitTask.PageIndex, queryVisitTask.PageSize, queryVisitTask.SortField, queryVisitTask.Asc, string.IsNullOrWhiteSpace(queryVisitTask.SortField), defalutSortArray);
|
||
|
||
return pageList;
|
||
//var trialTaskConfig = _trialRepository.Where(t => t.Id == queryVisitTask.TrialId).ProjectTo<TrialTaskConfig>(_mapper.ConfigurationProvider).FirstOrDefault();
|
||
|
||
//return (pageList, trialTaskConfig);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// PM阅片跟踪
|
||
/// </summary>
|
||
/// <param name="queryVisitTask"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<(PageOutput<ReadingTaskView>, object?)> GetReadingTaskList(VisitTaskQuery queryVisitTask)
|
||
{
|
||
var visitTaskQueryable = _visitTaskRepository.Where(t => t.TrialId == queryVisitTask.TrialId && t.IsAnalysisCreate == false)
|
||
//.Where(t => t.IsAnalysisCreate == false && t.DoctorUserId != null)
|
||
|
||
.WhereIf(queryVisitTask.TaskState != null, t => t.TaskState == queryVisitTask.TaskState)
|
||
.WhereIf(queryVisitTask.SiteId != null, t => t.Subject.SiteId == queryVisitTask.SiteId)
|
||
.WhereIf(queryVisitTask.SubjectId != null, t => t.SubjectId == queryVisitTask.SubjectId)
|
||
.WhereIf(queryVisitTask.IsUrgent != null, t => t.IsUrgent == queryVisitTask.IsUrgent)
|
||
.WhereIf(queryVisitTask.DoctorUserId != null, t => t.DoctorUserId == queryVisitTask.DoctorUserId)
|
||
.WhereIf(queryVisitTask.ReadingCategory != null, t => t.ReadingCategory == queryVisitTask.ReadingCategory)
|
||
.WhereIf(queryVisitTask.ReadingTaskState != null, t => t.ReadingTaskState == queryVisitTask.ReadingTaskState)
|
||
.WhereIf(queryVisitTask.TaskAllocationState != null, t => t.TaskAllocationState == queryVisitTask.TaskAllocationState)
|
||
.WhereIf(queryVisitTask.TrialReadingCriterionId != null, t => t.TrialReadingCriterionId == queryVisitTask.TrialReadingCriterionId)
|
||
.WhereIf(queryVisitTask.ReReadingApplyState != null, t => t.ReReadingApplyState == queryVisitTask.ReReadingApplyState)
|
||
.WhereIf(queryVisitTask.PIAuditState != null, t => t.PIAuditState == queryVisitTask.PIAuditState)
|
||
|
||
.WhereIf(queryVisitTask.CompleteClinicalDataEnum == CompleteClinicalDataEnum.Complete, t => t.IsClinicalDataSign && t.IsNeedClinicalDataSign == true)
|
||
.WhereIf(queryVisitTask.CompleteClinicalDataEnum == CompleteClinicalDataEnum.NotComplete, t => t.IsClinicalDataSign == false && t.IsNeedClinicalDataSign == true)
|
||
.WhereIf(queryVisitTask.CompleteClinicalDataEnum == CompleteClinicalDataEnum.NA, t => t.IsNeedClinicalDataSign == false)
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TrialSiteCode), t => (t.BlindTrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.IsAnalysisCreate) || (t.Subject.TrialSite.TrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.IsAnalysisCreate == false))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TaskName), t => t.TaskName.Contains(queryVisitTask.TaskName) || t.TaskBlindName.Contains(queryVisitTask.TaskName))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.SubjectCode), t => (t.Subject.Code.Contains(queryVisitTask.SubjectCode) && t.IsAnalysisCreate == false) || (t.BlindSubjectCode.Contains(queryVisitTask.SubjectCode) && t.IsAnalysisCreate))
|
||
.WhereIf(queryVisitTask.BeginAllocateDate != null, t => t.AllocateTime > queryVisitTask.BeginAllocateDate)
|
||
.WhereIf(queryVisitTask.EndAllocateDate != null, t => t.AllocateTime < queryVisitTask.EndAllocateDate!.Value.AddDays(1))
|
||
.ProjectTo<ReadingTaskView>(_mapper.ConfigurationProvider);
|
||
|
||
var defalutSortArray = new string[] { nameof(VisitTask.IsUrgent) + " desc", nameof(VisitTask.SubjectId), nameof(VisitTask.VisitTaskNum) };
|
||
|
||
var pageList = await visitTaskQueryable.ToPagedListAsync(queryVisitTask.PageIndex, queryVisitTask.PageSize, queryVisitTask.SortField, queryVisitTask.Asc, string.IsNullOrWhiteSpace(queryVisitTask.SortField), defalutSortArray);
|
||
|
||
var trialTaskConfig = _trialRepository.Where(t => t.Id == queryVisitTask.TrialId).ProjectTo<TrialUrgentConfig>(_mapper.ConfigurationProvider).FirstOrDefault();
|
||
|
||
return (pageList, trialTaskConfig);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// PM 重阅追踪
|
||
/// </summary>
|
||
/// <param name="queryVisitTask"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<PageOutput<ReReadingTaskView>> GetReReadingTaskList(VisitTaskQuery queryVisitTask)
|
||
{
|
||
|
||
|
||
var visitTaskQueryable = _visitTaskReReadingRepository
|
||
.Where(t => t.OriginalReReadingTask.TrialId == queryVisitTask.TrialId /*&& t.OriginalReReadingTask.IsAnalysisCreate == false*/)
|
||
.WhereIf(queryVisitTask.RootReReadingTaskId != null, t => t.RootReReadingTaskId == queryVisitTask.RootReReadingTaskId || t.OriginalReReadingTaskId == queryVisitTask.RootReReadingTaskId)
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TaskCode), t => t.OriginalReReadingTask.TaskCode.Contains(queryVisitTask.TaskCode!) || t.RootReReadingTask.TaskCode.Contains(queryVisitTask.TaskCode!))
|
||
.WhereIf(queryVisitTask.SiteId != null, t => t.OriginalReReadingTask.Subject.SiteId == queryVisitTask.SiteId)
|
||
.WhereIf(queryVisitTask.TaskState != null, t => t.OriginalReReadingTask.TaskState == queryVisitTask.TaskState)
|
||
.WhereIf(queryVisitTask.ReReadingApplyState != null, t => t.OriginalReReadingTask.ReReadingApplyState == queryVisitTask.ReReadingApplyState)
|
||
.WhereIf(queryVisitTask.RequestReReadingType != null, t => t.RequestReReadingType == queryVisitTask.RequestReReadingType)
|
||
.WhereIf(queryVisitTask.SubjectId != null, t => t.OriginalReReadingTask.SubjectId == queryVisitTask.SubjectId)
|
||
.WhereIf(queryVisitTask.IsUrgent != null, t => t.OriginalReReadingTask.IsUrgent == queryVisitTask.IsUrgent)
|
||
.WhereIf(queryVisitTask.DoctorUserId != null, t => t.OriginalReReadingTask.DoctorUserId == queryVisitTask.DoctorUserId)
|
||
.WhereIf(queryVisitTask.ReadingTaskState != null, t => t.OriginalReReadingTask.ReadingTaskState == queryVisitTask.ReadingTaskState)
|
||
.WhereIf(queryVisitTask.TaskAllocationState != null, t => t.OriginalReReadingTask.TaskAllocationState == queryVisitTask.TaskAllocationState)
|
||
.WhereIf(queryVisitTask.TrialReadingCriterionId != null, t => t.OriginalReReadingTask.TrialReadingCriterionId == queryVisitTask.TrialReadingCriterionId)
|
||
.WhereIf(queryVisitTask.ReadingCategory != null, t => t.OriginalReReadingTask.ReadingCategory == queryVisitTask.ReadingCategory)
|
||
|
||
.WhereIf(queryVisitTask.RequestReReadingResultEnum != null, t => t.RequestReReadingResultEnum == queryVisitTask.RequestReReadingResultEnum)
|
||
|
||
.WhereIf(queryVisitTask.PIAuditState != null, t => t.OriginalReReadingTask.PIAuditState == queryVisitTask.PIAuditState)
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TrialSiteCode), t => (t.OriginalReReadingTask.BlindTrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.OriginalReReadingTask.IsAnalysisCreate) || (t.OriginalReReadingTask.Subject.TrialSite.TrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.OriginalReReadingTask.IsAnalysisCreate == false))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TaskName), t => t.OriginalReReadingTask.TaskName.Contains(queryVisitTask.TaskName) || t.OriginalReReadingTask.TaskBlindName.Contains(queryVisitTask.TaskName))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.SubjectCode), t => (t.OriginalReReadingTask.Subject.Code.Contains(queryVisitTask.SubjectCode) && t.OriginalReReadingTask.IsAnalysisCreate == false) || (t.OriginalReReadingTask.BlindSubjectCode.Contains(queryVisitTask.SubjectCode) && t.OriginalReReadingTask.IsAnalysisCreate))
|
||
.WhereIf(queryVisitTask.BeginAllocateDate != null, t => t.OriginalReReadingTask.AllocateTime > queryVisitTask.BeginAllocateDate)
|
||
.WhereIf(queryVisitTask.EndAllocateDate != null, t => t.OriginalReReadingTask.AllocateTime < queryVisitTask.EndAllocateDate!.Value.AddDays(1))
|
||
.ProjectTo<ReReadingTaskView>(_mapper.ConfigurationProvider);
|
||
|
||
//var defalutSortArray = new string[] { nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.IsUrgent) + " desc", nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.SubjectId), nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.VisitTaskNum) };
|
||
|
||
var defalutSortArray = new string[] {
|
||
nameof(ReReadingTaskView.RequestReReadingResultEnum) ,
|
||
nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.IsUrgent) + " desc",
|
||
nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.TaskState),
|
||
nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.SubjectId),nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.VisitTaskNum) };
|
||
|
||
|
||
|
||
var pageList = await visitTaskQueryable.ToPagedListAsync(queryVisitTask.PageIndex, queryVisitTask.PageSize, queryVisitTask.SortField, queryVisitTask.Asc, string.IsNullOrWhiteSpace(queryVisitTask.SortField), defalutSortArray);
|
||
|
||
return pageList;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取IR 重阅影像阅片列表
|
||
/// </summary>
|
||
/// <param name="queryVisitTask"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<PageOutput<ReReadingTaskView>> GetIRReReadingTaskList(VisitTaskQuery queryVisitTask)
|
||
{
|
||
|
||
var visitTaskQueryable = _visitTaskReReadingRepository
|
||
.Where(t => t.RequestReReadingType == RequestReReadingType.DocotorApply)
|
||
.Where(t => t.OriginalReReadingTask.DoctorUserId == _userInfo.Id)
|
||
.Where(t => t.OriginalReReadingTask.TrialId == queryVisitTask.TrialId)
|
||
|
||
.WhereIf(queryVisitTask.RootReReadingTaskId != null, t => t.RootReReadingTaskId == queryVisitTask.RootReReadingTaskId || t.OriginalReReadingTaskId == queryVisitTask.RootReReadingTaskId)
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TaskCode), t => t.OriginalReReadingTask.TaskCode.Contains(queryVisitTask.TaskCode!) || t.RootReReadingTask.TaskCode.Contains(queryVisitTask.TaskCode!))
|
||
.WhereIf(queryVisitTask.TaskState != null, t => t.OriginalReReadingTask.TaskState == queryVisitTask.TaskState)
|
||
.WhereIf(queryVisitTask.ReReadingApplyState != null, t => t.OriginalReReadingTask.ReReadingApplyState == queryVisitTask.ReReadingApplyState)
|
||
.WhereIf(queryVisitTask.SiteId != null, t => t.OriginalReReadingTask.Subject.SiteId == queryVisitTask.SiteId)
|
||
.WhereIf(queryVisitTask.SubjectId != null, t => t.OriginalReReadingTask.SubjectId == queryVisitTask.SubjectId)
|
||
.WhereIf(queryVisitTask.IsUrgent != null, t => t.OriginalReReadingTask.IsUrgent == queryVisitTask.IsUrgent)
|
||
.WhereIf(queryVisitTask.DoctorUserId != null, t => t.OriginalReReadingTask.DoctorUserId == queryVisitTask.DoctorUserId)
|
||
.WhereIf(queryVisitTask.ReadingTaskState != null, t => t.OriginalReReadingTask.ReadingTaskState == queryVisitTask.ReadingTaskState)
|
||
.WhereIf(queryVisitTask.TaskAllocationState != null, t => t.OriginalReReadingTask.TaskAllocationState == queryVisitTask.TaskAllocationState)
|
||
.WhereIf(queryVisitTask.TrialReadingCriterionId != null, t => t.OriginalReReadingTask.TrialReadingCriterionId == queryVisitTask.TrialReadingCriterionId)
|
||
|
||
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TrialSiteCode), t => (t.OriginalReReadingTask.BlindTrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.OriginalReReadingTask.IsAnalysisCreate) || (t.OriginalReReadingTask.Subject.TrialSite.TrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.OriginalReReadingTask.IsAnalysisCreate == false))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TaskName), t => t.OriginalReReadingTask.TaskName.Contains(queryVisitTask.TaskName) || t.NewReReadingTask.TaskBlindName.Contains(queryVisitTask.TaskName))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.SubjectCode), t => (t.OriginalReReadingTask.Subject.Code.Contains(queryVisitTask.SubjectCode) && t.OriginalReReadingTask.IsAnalysisCreate == false) || (t.OriginalReReadingTask.BlindSubjectCode.Contains(queryVisitTask.SubjectCode) && t.OriginalReReadingTask.IsAnalysisCreate))
|
||
.WhereIf(queryVisitTask.BeginAllocateDate != null, t => t.OriginalReReadingTask.AllocateTime > queryVisitTask.BeginAllocateDate)
|
||
.WhereIf(queryVisitTask.EndAllocateDate != null, t => t.OriginalReReadingTask.AllocateTime < queryVisitTask.EndAllocateDate!.Value.AddDays(1))
|
||
.ProjectTo<ReReadingTaskView>(_mapper.ConfigurationProvider);
|
||
|
||
|
||
|
||
var defalutSortArray = new string[] { nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.IsUrgent) + " desc", nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.SubjectId), nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.VisitTaskNum) };
|
||
|
||
var pageList = await visitTaskQueryable.ToPagedListAsync(queryVisitTask.PageIndex, queryVisitTask.PageSize, queryVisitTask.SortField, queryVisitTask.Asc, string.IsNullOrWhiteSpace(queryVisitTask.SortField), defalutSortArray);
|
||
|
||
return pageList;
|
||
}
|
||
|
||
|
||
//SPM 能看到项目组申请记录
|
||
[HttpPost]
|
||
public async Task<PageOutput<ReReadingTaskView>> GetSPMReReadingTaskList(VisitTaskQuery queryVisitTask)
|
||
{
|
||
var visitTaskQueryable = _visitTaskReReadingRepository.Where(t => t.RequestReReadingType == RequestReReadingType.TrialGroupApply && t.OriginalReReadingTask.IsAnalysisCreate == false)
|
||
.Where(t => t.OriginalReReadingTask.TrialId == queryVisitTask.TrialId)
|
||
.WhereIf(queryVisitTask.RootReReadingTaskId != null, t => t.RootReReadingTaskId == queryVisitTask.RootReReadingTaskId || t.OriginalReReadingTaskId == queryVisitTask.RootReReadingTaskId)
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TaskCode), t => t.OriginalReReadingTask.TaskCode.Contains(queryVisitTask.TaskCode!) || t.RootReReadingTask.TaskCode.Contains(queryVisitTask.TaskCode!))
|
||
.WhereIf(queryVisitTask.TaskState != null, t => t.OriginalReReadingTask.TaskState == queryVisitTask.TaskState)
|
||
.WhereIf(queryVisitTask.SiteId != null, t => t.OriginalReReadingTask.Subject.SiteId == queryVisitTask.SiteId)
|
||
.WhereIf(queryVisitTask.SubjectId != null, t => t.OriginalReReadingTask.SubjectId == queryVisitTask.SubjectId)
|
||
.WhereIf(queryVisitTask.IsUrgent != null, t => t.OriginalReReadingTask.IsUrgent == queryVisitTask.IsUrgent)
|
||
.WhereIf(queryVisitTask.DoctorUserId != null, t => t.OriginalReReadingTask.DoctorUserId == queryVisitTask.DoctorUserId)
|
||
.WhereIf(queryVisitTask.ReadingTaskState != null, t => t.OriginalReReadingTask.ReadingTaskState == queryVisitTask.ReadingTaskState)
|
||
.WhereIf(queryVisitTask.TaskAllocationState != null, t => t.OriginalReReadingTask.TaskAllocationState == queryVisitTask.TaskAllocationState)
|
||
.WhereIf(queryVisitTask.TrialReadingCriterionId != null, t => t.OriginalReReadingTask.TrialReadingCriterionId == queryVisitTask.TrialReadingCriterionId)
|
||
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TrialSiteCode), t => (t.OriginalReReadingTask.BlindTrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.OriginalReReadingTask.IsAnalysisCreate) || (t.OriginalReReadingTask.Subject.TrialSite.TrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.OriginalReReadingTask.IsAnalysisCreate == false))
|
||
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TaskName), t => t.OriginalReReadingTask.TaskName.Contains(queryVisitTask.TaskName) || t.NewReReadingTask.TaskBlindName.Contains(queryVisitTask.TaskName))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.SubjectCode), t => (t.OriginalReReadingTask.Subject.Code.Contains(queryVisitTask.SubjectCode) && t.OriginalReReadingTask.IsAnalysisCreate == false) || (t.OriginalReReadingTask.BlindSubjectCode.Contains(queryVisitTask.SubjectCode) && t.OriginalReReadingTask.IsAnalysisCreate))
|
||
.WhereIf(queryVisitTask.BeginAllocateDate != null, t => t.OriginalReReadingTask.AllocateTime > queryVisitTask.BeginAllocateDate)
|
||
.WhereIf(queryVisitTask.EndAllocateDate != null, t => t.OriginalReReadingTask.AllocateTime < queryVisitTask.EndAllocateDate!.Value.AddDays(1))
|
||
.ProjectTo<ReReadingTaskView>(_mapper.ConfigurationProvider);
|
||
|
||
var defalutSortArray = new string[] { nameof(ReReadingTaskView.RequestReReadingTime) };
|
||
|
||
//var defalutSortArray = new string[] { nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.IsUrgent) + " desc", nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.SubjectId), nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.VisitTaskNum) };
|
||
|
||
var pageList = await visitTaskQueryable.ToPagedListAsync(queryVisitTask.PageIndex, queryVisitTask.PageSize, queryVisitTask.SortField, queryVisitTask.Asc, string.IsNullOrWhiteSpace(queryVisitTask.SortField), defalutSortArray);
|
||
|
||
return pageList;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// IR 待阅片任务列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<(PageOutput<IRUnReadSubjectView>, object)> GetIRUnReadSubjectTaskList(IRUnReadSubjectQuery iRUnReadSubjectQuery)
|
||
{
|
||
|
||
var trialId = iRUnReadSubjectQuery.TrialId;
|
||
|
||
var trialReadingCriterionId = iRUnReadSubjectQuery.TrialReadingCriterionId;
|
||
|
||
var critrion = await _trialReadingCriterionRepository.Where(x => x.Id == iRUnReadSubjectQuery.TrialReadingCriterionId).FirstNotNullAsync();
|
||
|
||
var readingTool = critrion.ReadingTool;
|
||
var isReadingTaskViewInOrder = critrion.IsReadingTaskViewInOrder;
|
||
|
||
#region 按照Subject 维度
|
||
if (isReadingTaskViewInOrder)
|
||
{
|
||
|
||
|
||
var visitTaskListInfo = await GetOrderReadingIQueryable(new GetOrderReadingIQueryableInDto()
|
||
{
|
||
TrialId = trialId,
|
||
TrialReadingCriterionId = trialReadingCriterionId,
|
||
SubjectCode = iRUnReadSubjectQuery.SubjectCode,
|
||
Page = new PageInput()
|
||
{
|
||
PageIndex = iRUnReadSubjectQuery.PageIndex,
|
||
PageSize = iRUnReadSubjectQuery.PageSize,
|
||
Asc = iRUnReadSubjectQuery.Asc,
|
||
SortField = iRUnReadSubjectQuery.SortField,
|
||
|
||
}
|
||
|
||
});
|
||
|
||
|
||
var totalCount = visitTaskListInfo.Item1;
|
||
var currentPageData = visitTaskListInfo.Item2;
|
||
|
||
|
||
|
||
var result = new PageOutput<IRUnReadSubjectView>()
|
||
{
|
||
PageSize = iRUnReadSubjectQuery.PageSize,
|
||
PageIndex = iRUnReadSubjectQuery.PageIndex,
|
||
TotalCount = totalCount,
|
||
CurrentPageData = currentPageData,
|
||
};
|
||
|
||
// 封装的方法有问题
|
||
//var result = await visitQuery.ToPagedListAsync(iRUnReadSubjectQuery.PageIndex, iRUnReadSubjectQuery.PageSize, String.IsNullOrEmpty(iRUnReadSubjectQuery.SortField) ? nameof(IRUnReadSubjectView.SubjectId) : iRUnReadSubjectQuery.SortField, iRUnReadSubjectQuery.Asc);
|
||
return (result, new
|
||
{
|
||
RandomReadInfo = new IRUnReadOutDto(),
|
||
IsReadingTaskViewInOrder = isReadingTaskViewInOrder,
|
||
ReadingTool = readingTool,
|
||
IseCRFShowInDicomReading = critrion.IseCRFShowInDicomReading,
|
||
IsReadingShowSubjectInfo = critrion.IsReadingShowSubjectInfo,
|
||
IsReadingShowPreviousResults = critrion.IsReadingShowPreviousResults,
|
||
DigitPlaces = critrion.DigitPlaces,
|
||
CriterionType = critrion.CriterionType,
|
||
});
|
||
}
|
||
else
|
||
{
|
||
|
||
var readingDivisionEnum = critrion.ReadingDivisionEnum;
|
||
|
||
var piReadingScopenEnum = critrion.PIReadingScopenEnum;
|
||
|
||
var taskQuery = _visitTaskRepository.Where(x => x.TrialId == iRUnReadSubjectQuery.TrialId /*&& x.DoctorUserId == _userInfo.Id*/ && x.TaskState == TaskState.Effect && x.TrialReadingCriterionId == trialReadingCriterionId)
|
||
|
||
.Where(x => (x.IsNeedClinicalDataSign && x.IsClinicalDataSign) || !x.IsNeedClinicalDataSign)
|
||
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR, t => t.Subject.TrialSite.CRCUserList.Any(u => u.UserId == _userInfo.Id))
|
||
// 仅仅SR阅片 PI 没有任务列表
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.OnlySR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI, t => t.TrialId == Guid.Empty)
|
||
|
||
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI && piReadingScopenEnum == PIReadingScopenEnum.AllBaseline,
|
||
t => t.SourceSubjectVisit.IsBaseLine == true)
|
||
|
||
//PI 阅片所有
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI && piReadingScopenEnum == PIReadingScopenEnum.AllBaselineandVisit,
|
||
t => true)
|
||
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI && piReadingScopenEnum == PIReadingScopenEnum.AllVisit,
|
||
t => t.SourceSubjectVisit.IsBaseLine == false)
|
||
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR && piReadingScopenEnum == PIReadingScopenEnum.AllBaseline,
|
||
t => t.SourceSubjectVisit.IsBaseLine == false)
|
||
|
||
//SR 不阅片
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR && piReadingScopenEnum == PIReadingScopenEnum.AllBaselineandVisit,
|
||
t => t.TrialId == Guid.Empty)
|
||
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR && piReadingScopenEnum == PIReadingScopenEnum.AllVisit,
|
||
t => t.SourceSubjectVisit.IsBaseLine == true);
|
||
|
||
IRUnReadOutDto iRUnReadOut = new IRUnReadOutDto()
|
||
{
|
||
FinishTaskCount = await taskQuery.Where(x => x.ReadingCategory != ReadingCategory.Judge && x.ReadingTaskState == ReadingTaskState.HaveSigned).CountAsync(),
|
||
SuggesteFinishedTime = await taskQuery.Where(x => x.ReadingTaskState != ReadingTaskState.HaveSigned).MaxAsync(x => x.SuggesteFinishedTime),
|
||
|
||
|
||
UnReadTaskCount = await taskQuery.Where(x => x.ReadingCategory != ReadingCategory.Judge && x.ReadingTaskState != ReadingTaskState.HaveSigned).CountAsync(),
|
||
};
|
||
|
||
var result = new PageOutput<IRUnReadSubjectView>()
|
||
{
|
||
PageSize = iRUnReadSubjectQuery.PageSize,
|
||
PageIndex = iRUnReadSubjectQuery.PageIndex,
|
||
};
|
||
|
||
return (result, new
|
||
{
|
||
IsReadingTaskViewInOrder = isReadingTaskViewInOrder,
|
||
RandomReadInfo = iRUnReadOut,
|
||
ReadingTool = readingTool,
|
||
IseCRFShowInDicomReading = critrion.IseCRFShowInDicomReading,
|
||
IsReadingShowSubjectInfo = critrion.IsReadingShowSubjectInfo,
|
||
IsReadingShowPreviousResults = critrion.IsReadingShowPreviousResults,
|
||
DigitPlaces = critrion.DigitPlaces,
|
||
CriterionType = critrion.CriterionType,
|
||
});
|
||
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取有序阅片IQuery对象
|
||
/// </summary>
|
||
/// <param name="inDto"></param>
|
||
|
||
/// <returns></returns>
|
||
public async Task<(int, List<IRUnReadSubjectView>)> GetOrderReadingIQueryable(GetOrderReadingIQueryableInDto inDto)
|
||
{
|
||
var trialReadingCriterionId = inDto.TrialReadingCriterionId;
|
||
|
||
//Expression<Func<VisitTask, bool>> visitTaskLambda = x => x.DoctorUserId == _userInfo.Id && x.TaskState == TaskState.Effect && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId;
|
||
|
||
var critrion = await _trialReadingCriterionRepository.FindAsync(trialReadingCriterionId);
|
||
|
||
var readingDivisionEnum = critrion.ReadingDivisionEnum;
|
||
|
||
var piReadingScopenEnum = critrion.PIReadingScopenEnum;
|
||
|
||
var visitQuery = _visitTaskRepository
|
||
.Where(x => x.TrialId == inDto.TrialId && x.TaskState == TaskState.Effect)
|
||
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR && piReadingScopenEnum == PIReadingScopenEnum.AllBaseline,
|
||
t => t.Subject.SubjectVisitTaskList.Any(c => c.SourceSubjectVisit.IsBaseLine == true && c.ReadingTaskState == ReadingTaskState.HaveSigned))
|
||
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI && piReadingScopenEnum == PIReadingScopenEnum.AllVisit,
|
||
t => t.Subject.SubjectVisitTaskList.Any(c => c.SourceSubjectVisit.IsBaseLine == true && c.ReadingTaskState == ReadingTaskState.HaveSigned))
|
||
|
||
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR, t => t.Subject.TrialSite.CRCUserList.Any(u => u.UserId == _userInfo.Id))
|
||
// 仅仅SR阅片 PI 没有任务列表
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.OnlySR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI, t => t.TrialId == Guid.Empty)
|
||
|
||
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI && piReadingScopenEnum == PIReadingScopenEnum.AllBaseline,
|
||
t => t.SourceSubjectVisit.IsBaseLine == true)
|
||
|
||
//PI 阅片所有
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI && piReadingScopenEnum == PIReadingScopenEnum.AllBaselineandVisit,
|
||
t => true)
|
||
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI && piReadingScopenEnum == PIReadingScopenEnum.AllVisit,
|
||
t => t.SourceSubjectVisit.IsBaseLine == false)
|
||
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR && piReadingScopenEnum == PIReadingScopenEnum.AllBaseline,
|
||
t => t.SourceSubjectVisit.IsBaseLine == false)
|
||
|
||
//SR 不阅片
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR && piReadingScopenEnum == PIReadingScopenEnum.AllBaselineandVisit,
|
||
t => t.TrialId == Guid.Empty)
|
||
|
||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR && piReadingScopenEnum == PIReadingScopenEnum.AllVisit,
|
||
t => t.SourceSubjectVisit.IsBaseLine == true)
|
||
|
||
//前序 不存在 未生成任务的访视
|
||
.WhereIf(critrion.IsAutoCreate == false, t => !t.Subject.SubjectCriteriaEvaluationVisitFilterList.Where(t => t.TrialReadingCriterionId == trialReadingCriterionId).Any(f => f.IsGeneratedTask == false && t.VisitTaskNum > f.SubjectVisit.VisitNum))
|
||
|
||
// 前序 不存在 未一致性核查未通过的
|
||
.Where(t => !t.Subject.SubjectVisitList.Any(sv => sv.CheckState != CheckStateEnum.CVPassed && t.VisitTaskNum > sv.VisitNum))
|
||
.WhereIf(!string.IsNullOrEmpty(inDto.SubjectCode), t => (t.Subject.Code.Contains(inDto.SubjectCode) && t.IsAnalysisCreate == false) || (t.BlindSubjectCode.Contains(inDto.SubjectCode) && t.IsAnalysisCreate));
|
||
|
||
|
||
var visitGroupQuery = visitQuery.GroupBy(x => new { x.SubjectId, x.Subject.Code, x.BlindSubjectCode, x.Subject.ClaimUserId });
|
||
|
||
var visitTaskQuery = visitGroupQuery.Select(x => new IRUnReadSubjectView()
|
||
{
|
||
SubjectId = x.Key.SubjectId,
|
||
SubjectCode = x.Key.BlindSubjectCode == string.Empty ? x.Key.Code : x.Key.BlindSubjectCode,
|
||
ClaimUserId = x.Key.ClaimUserId,
|
||
|
||
SuggesteFinishedTime = x.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState != ReadingTaskState.HaveSigned).Min(x => x.SuggesteFinishedTime),
|
||
|
||
//未读任务量
|
||
UnReadTaskCount = x.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState != ReadingTaskState.HaveSigned).Count(),
|
||
|
||
//未读 里可读任务量
|
||
UnReadCanReadTaskCount = x.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState != ReadingTaskState.HaveSigned && y.IsFrontTaskNeedSignButNotSign == false && (y.IsNeedClinicalDataSign == false || y.IsClinicalDataSign == true)
|
||
|
||
).Count(),
|
||
|
||
|
||
//已读任务量
|
||
HaveReadTaskCount = x.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState == ReadingTaskState.HaveSigned).Count(),
|
||
|
||
ExistReadingApply = x.Any(y => (y.ReReadingApplyState == ReReadingApplyState.DocotorHaveApplyed && y.TrialReadingCriterionId == trialReadingCriterionId) || y.ReReadingApplyState == ReReadingApplyState.TrialGroupHaveApplyed),
|
||
|
||
//查出所有未读的 未读的可读的 在这个列表基础上 过滤下 y.IsFrontTaskNeedSignButNotSign==false && (y.IsNeedClinicalDataSign == false || y.IsClinicalDataSign == true) 这样容易排错 确认这三个字段是否维护有误
|
||
UnReadTaskList = x.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState != ReadingTaskState.HaveSigned).OrderBy(x => x.VisitTaskNum)
|
||
.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,
|
||
IsAnalysisCreate = u.IsAnalysisCreate,
|
||
ArmEnum = u.ArmEnum,
|
||
TrialReadingCriterionId = u.TrialReadingCriterionId,
|
||
IsNeedClinicalDataSign = u.IsNeedClinicalDataSign,
|
||
IsClinicalDataSign = u.IsClinicalDataSign,
|
||
IsFrontTaskNeedSignButNotSign = u.IsFrontTaskNeedSignButNotSign
|
||
})
|
||
.ToList(),
|
||
}).Where(x => x.UnReadCanReadTaskCount > 0)/*.OrderBy(x => x.UnReadCanReadTaskCount)*/;
|
||
// 有序阅片需要找到最小需要
|
||
|
||
|
||
// 不这样写会有问题
|
||
var count = visitQuery.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState != ReadingTaskState.HaveSigned && y.IsFrontTaskNeedSignButNotSign == false && (y.IsNeedClinicalDataSign == false || y.IsClinicalDataSign == true))
|
||
.GroupBy(x => new { x.SubjectId, x.Subject.Code, x.BlindSubjectCode }).Count();
|
||
|
||
var result = new List<IRUnReadSubjectView>();
|
||
|
||
var propName = string.IsNullOrWhiteSpace(inDto.Page.SortField) ? "UnReadCanReadTaskCount" : inDto.Page.SortField;
|
||
|
||
var visitTaskOrderQuery = inDto.Page.Asc ? visitTaskQuery.OrderBy(propName) : visitTaskQuery.OrderBy(propName + " desc");
|
||
if (inDto.Page != null)
|
||
{
|
||
result = await visitTaskOrderQuery
|
||
.Skip((inDto.Page.PageIndex - 1) * inDto.Page.PageSize)
|
||
.Take(inDto.Page.PageSize).ToListAsync();
|
||
}
|
||
else
|
||
{
|
||
result = await visitTaskOrderQuery.ToListAsync();
|
||
}
|
||
|
||
|
||
return (count, result);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// IR 已阅片任务
|
||
/// </summary>
|
||
/// <param name="queryVisitTask"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<PageOutput<IRHaveReadView>> GetIRHaveReadTaskList(VisitTaskQuery queryVisitTask)
|
||
{
|
||
|
||
|
||
var visitTaskQueryable = _visitTaskRepository.Where(t => t.TrialId == queryVisitTask.TrialId)
|
||
.Where(t => t.DoctorUserId == _userInfo.Id && t.ReadingTaskState == ReadingTaskState.HaveSigned)//该医生 已经签名的数据
|
||
|
||
|
||
.WhereIf(queryVisitTask.SiteId != null, t => t.Subject.SiteId == queryVisitTask.SiteId)
|
||
.WhereIf(queryVisitTask.SubjectId != null, t => t.SubjectId == queryVisitTask.SubjectId)
|
||
.WhereIf(queryVisitTask.IsUrgent != null, t => t.IsUrgent == queryVisitTask.IsUrgent)
|
||
.WhereIf(queryVisitTask.ReadingCategory != null, t => t.ReadingCategory == queryVisitTask.ReadingCategory)
|
||
.WhereIf(queryVisitTask.TaskAllocationState != null, t => t.TaskAllocationState == queryVisitTask.TaskAllocationState)
|
||
.WhereIf(queryVisitTask.TrialReadingCriterionId != null, t => t.TrialReadingCriterionId == queryVisitTask.TrialReadingCriterionId)
|
||
|
||
.WhereIf(queryVisitTask.PIAuditState != null, t => t.PIAuditState == queryVisitTask.PIAuditState)
|
||
.WhereIf(queryVisitTask.TaskState != null, t => t.TaskState == queryVisitTask.TaskState)
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TrialSiteCode), t => (t.BlindTrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.IsAnalysisCreate) || (t.Subject.TrialSite.TrialSiteCode.Contains(queryVisitTask.TrialSiteCode!) && t.IsAnalysisCreate == false))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.TaskName), t => t.TaskName.Contains(queryVisitTask.TaskName) || t.TaskBlindName.Contains(queryVisitTask.TaskName))
|
||
.WhereIf(!string.IsNullOrEmpty(queryVisitTask.SubjectCode), t => (t.Subject.Code.Contains(queryVisitTask.SubjectCode) && t.IsAnalysisCreate == false) || (t.BlindSubjectCode.Contains(queryVisitTask.SubjectCode) && t.IsAnalysisCreate))
|
||
.WhereIf(queryVisitTask.BeginAllocateDate != null, t => t.AllocateTime > queryVisitTask.BeginAllocateDate)
|
||
.WhereIf(queryVisitTask.EndAllocateDate != null, t => t.AllocateTime < queryVisitTask.EndAllocateDate!.Value.AddDays(1))
|
||
.ProjectTo<IRHaveReadView>(_mapper.ConfigurationProvider);
|
||
|
||
var defalutSortArray = new string[] { nameof(VisitTask.IsUrgent) + " desc", nameof(VisitTask.SubjectId), nameof(VisitTask.VisitTaskNum) };
|
||
|
||
var pageList = await visitTaskQueryable.ToPagedListAsync(queryVisitTask.PageIndex, queryVisitTask.PageSize, queryVisitTask.SortField, queryVisitTask.Asc, string.IsNullOrWhiteSpace(queryVisitTask.SortField), defalutSortArray);
|
||
|
||
return pageList;
|
||
}
|
||
|
||
|
||
|
||
[HttpPost]
|
||
[UnitOfWork]
|
||
public async Task<IResponseOutput> AIRReReading(AIRReReadingCommand command, [FromServices] IVisitTaskHelpeService _visitTaskCommonService)
|
||
{
|
||
var baseLineTaskList = await _visitTaskRepository.Where(t => t.TrialId == command.TrialId && t.TrialReadingCriterionId == command.TrialReadingCriterionId && t.DoctorUserId == _userInfo.Id
|
||
&& t.TaskState == TaskState.Effect && t.ReadingCategory == ReadingCategory.Visit && t.ReadingTaskState == ReadingTaskState.HaveSigned && t.SourceSubjectVisit.IsBaseLine == true).ToListAsync();
|
||
|
||
|
||
var baseLineTaskIdList = baseLineTaskList.Select(t => t.Id).ToList();
|
||
|
||
if (baseLineTaskIdList.Count == 0)
|
||
{
|
||
return ResponseOutput.Ok();
|
||
}
|
||
|
||
//if (baseLineTaskList == null)
|
||
//{
|
||
// return ResponseOutput.NotOk("基线任务未阅完,不允许重阅基线任务");
|
||
//}
|
||
|
||
await ApplyReReading(new ApplyReReadingCommand() { IsCopyFollowForms = false, IsCopyOrigenalForms = false, TaskIdList = baseLineTaskIdList, TrialId = command.TrialId, RequestReReadingReason = "AIR自动重阅基线", RequestReReadingType = RequestReReadingType.DocotorApply });
|
||
|
||
|
||
|
||
var requestRecordList = await _visitTaskReReadingRepository.Where(t => baseLineTaskIdList.Contains(t.OriginalReReadingTaskId) && t.RequestReReadingUserId == _userInfo.Id && t.RequestReReadingReason == "AIR自动重阅基线").ToListAsync();
|
||
|
||
if (requestRecordList.Count() != baseLineTaskIdList.Count())
|
||
{
|
||
//---后台数据有错误
|
||
return ResponseOutput.NotOk(_localizer["VisitTask_DoctorConfiguration"]);
|
||
}
|
||
|
||
await ConfirmReReading(new ConfirmReReadingCommand()
|
||
{
|
||
TrialId = command.TrialId,
|
||
RequestReReadingResultEnum = RequestReReadingResult.Agree,
|
||
//ConfirmReReadingList = new List<ConfirmReReadingDTO>() { new ConfirmReReadingDTO() { Id = requestRecord.Id, OriginalReReadingTaskId = task.Id } }
|
||
ConfirmReReadingList = requestRecordList.Select(t => new ConfirmReReadingDTO() { Id = t.Id, OriginalReReadingTaskId = t.OriginalReReadingTaskId }).ToList()
|
||
}, _visitTaskCommonService);
|
||
|
||
return ResponseOutput.Ok();
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 申请重阅 1:IR 2:PM
|
||
/// </summary>
|
||
/// <param name="applyReReadingCommand"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[UnitOfWork]
|
||
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })]
|
||
|
||
public async Task<IResponseOutput> ApplyReReading(ApplyReReadingCommand applyReReadingCommand)
|
||
{
|
||
|
||
|
||
var taskList = await _visitTaskRepository.Where(t => applyReReadingCommand.TaskIdList.Contains(t.Id), true).ToListAsync();
|
||
|
||
var trialReadingCriterionId = taskList.First()!.TrialReadingCriterionId;
|
||
|
||
var criterionConfig = (await _trialReadingCriterionRepository.Where(x => x.Id == trialReadingCriterionId).Select(x => new { x.ReadingTool, x.IsAutoCreate, x.IsReadingTaskViewInOrder }).FirstOrDefaultAsync()).IfNullThrowException();
|
||
|
||
|
||
foreach (var task in taskList)
|
||
{
|
||
|
||
|
||
if (task.ReadingTaskState != ReadingTaskState.HaveSigned || (task.TaskState != TaskState.Effect && task.TaskState != TaskState.Freeze))
|
||
{
|
||
//---未阅片完成,或者未生效的任务不允许申请重阅
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_BackendData"]);
|
||
}
|
||
|
||
if (task.ReReadingApplyState == ReReadingApplyState.DocotorHaveApplyed || task.ReReadingApplyState == ReReadingApplyState.TrialGroupHaveApplyed || task.ReReadingApplyState == ReReadingApplyState.Agree)
|
||
{
|
||
//---重阅已申请,或者重阅已同意状态下不允许申请重阅
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_UnreadTask"]);
|
||
}
|
||
|
||
|
||
|
||
|
||
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager)
|
||
{
|
||
if (criterionConfig.IsAutoCreate == false)
|
||
{
|
||
//---手动生成任务的不允许PM 申请影像重阅
|
||
return ResponseOutput.NotOk(_localizer["VisitTask_NoPMRecheck"]);
|
||
}
|
||
|
||
if (task.IsAnalysisCreate)
|
||
{
|
||
//---PM 不允许对一致性分析任务进行申请重阅
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_Reapply"]);
|
||
}
|
||
|
||
if (task.ReadingCategory != ReadingCategory.Visit)
|
||
{
|
||
//---PM 仅仅允许对访视类型的任务申请重阅
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_ConsistencyAnalysis"]);
|
||
}
|
||
|
||
|
||
// 有序 一个受试者访视重阅未处理完,不能申请其他的
|
||
if (criterionConfig.IsReadingTaskViewInOrder)
|
||
{
|
||
if (await _visitTaskReReadingRepository.AnyAsync(t => t.OriginalReReadingTask.TrialId == task.TrialId && t.OriginalReReadingTask.SubjectId == task.SubjectId && t.OriginalReReadingTask.TaskState == TaskState.Effect
|
||
&& t.OriginalReReadingTask.TrialReadingCriterionId == task.TrialReadingCriterionId
|
||
&& t.OriginalReReadingTask.ReadingTaskState == ReadingTaskState.HaveSigned && t.RequestReReadingType == RequestReReadingType.TrialGroupApply && t.RequestReReadingResultEnum == RequestReReadingResult.Default))
|
||
{
|
||
//---当前为有序阅片,该受试者已有访视已申请重阅还未处理(项目组申请),暂不能继续申请重阅
|
||
return ResponseOutput.NotOk(_localizer["VisitTask_VisitTypeRestriction"]);
|
||
}
|
||
}
|
||
|
||
|
||
task.ReReadingApplyState = ReReadingApplyState.TrialGroupHaveApplyed;
|
||
|
||
|
||
}
|
||
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI)
|
||
{
|
||
task.ReReadingApplyState = ReReadingApplyState.DocotorHaveApplyed;
|
||
|
||
// 有序
|
||
if (criterionConfig.IsReadingTaskViewInOrder)
|
||
{
|
||
// 针对同一个subject 不同阅片人 针对同一个访视申请重阅,是允许的,所以同一阅片人,针对同一suject 有访视申请重阅还未处理,不允许申请重阅
|
||
if (await _visitTaskReReadingRepository.AnyAsync(t => t.OriginalReReadingTask.TrialId == task.TrialId && t.OriginalReReadingTask.SubjectId == task.SubjectId && t.OriginalReReadingTask.TaskState == TaskState.Effect
|
||
&& t.OriginalReReadingTask.TrialReadingCriterionId == task.TrialReadingCriterionId && t.OriginalReReadingTask.DoctorUserId == task.DoctorUserId
|
||
&& t.OriginalReReadingTask.ReadingTaskState == ReadingTaskState.HaveSigned && t.RequestReReadingType == RequestReReadingType.DocotorApply && t.RequestReReadingResultEnum == RequestReReadingResult.Default))
|
||
{
|
||
//---当前为有序阅片,该受试者已有访视已申请重阅还未处理,暂不能继续申请重阅
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_SequentialReading"]);
|
||
}
|
||
|
||
|
||
//在PM 的申请重阅的影响列表里也不能申请重阅
|
||
|
||
var pmApply = await _visitTaskReReadingRepository.Where(t => t.OriginalReReadingTask.TrialId == task.TrialId && t.OriginalReReadingTask.SubjectId == task.SubjectId && t.OriginalReReadingTask.TaskState == TaskState.Effect && t.OriginalReReadingTask.ReadingCategory == ReadingCategory.Visit
|
||
&& t.OriginalReReadingTask.ReadingTaskState == ReadingTaskState.HaveSigned && t.RequestReReadingType == RequestReReadingType.TrialGroupApply && t.RequestReReadingResultEnum == RequestReReadingResult.Default).Include(t => t.OriginalReReadingTask).FirstOrDefaultAsync();
|
||
|
||
if (pmApply != null)
|
||
{
|
||
var originalTask = pmApply.OriginalReReadingTask;
|
||
|
||
//PM 有序影响列表
|
||
if (await _visitTaskRepository.Where(t => t.TrialId == originalTask.TrialId && t.SubjectId == originalTask.SubjectId && t.TaskState == TaskState.Effect /*&& t.TaskAllocationState == TaskAllocationState.Allocated*/ && t.IsAnalysisCreate == false && t.TrialReadingCriterionId == originalTask.TrialReadingCriterionId && t.VisitTaskNum >= originalTask.VisitTaskNum)
|
||
.AnyAsync(t => t.VisitTaskNum == task.VisitTaskNum))
|
||
{
|
||
//---当前为有序阅片,影像存在问题,项目组已申请回退,暂不能申请重阅
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_ImageProblem"]);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
Expression<Func<VisitTask, bool>> filterExpression = t => t.TrialId == task.TrialId && t.SubjectId == task.SubjectId && t.TaskState == TaskState.Effect && t.TrialReadingCriterionId == task.TrialReadingCriterionId
|
||
&& t.DoctorUserId == task.DoctorUserId && t.IsAnalysisCreate == false && t.VisitTaskNum > task.VisitTaskNum;
|
||
|
||
|
||
|
||
if (task.ReadingCategory == ReadingCategory.Global && await _visitTaskRepository.AnyAsync(filterExpression.And(t => t.ReadingCategory == ReadingCategory.Global)))
|
||
{
|
||
//---有序阅片,只允许申请该受试者阅片人最后一次完成全局任务重阅
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_LastReading"]);
|
||
}
|
||
|
||
if (task.ReadingCategory == ReadingCategory.Oncology && await _visitTaskRepository.AnyAsync(filterExpression.And(t => t.ReadingCategory == ReadingCategory.Oncology)))
|
||
{
|
||
//---有序阅片,只允许申请该受试者阅片人最后一次完成肿瘤学任务重阅
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_LastOncologistRecheck"]);
|
||
}
|
||
|
||
if (task.ReadingCategory == ReadingCategory.Judge && await _visitTaskRepository.AnyAsync(filterExpression.And(t => t.ReadingCategory == ReadingCategory.Judge)))
|
||
{
|
||
//---有序阅片,只允许申请该受试者阅片人最后一次完成裁判的任务重阅
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_LastAdjudicatorRecheck"]);
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
if (task.ReadingCategory != ReadingCategory.Visit && task.ReadingCategory != ReadingCategory.Global)
|
||
{
|
||
//---无序阅片,仅仅允许IR 申请 全局和访视类型类别的任务进行重阅
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_IRGlobalRecheck"]);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
//AIR 不加验证
|
||
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.AIR)
|
||
{
|
||
task.ReReadingApplyState = ReReadingApplyState.DocotorHaveApplyed;
|
||
}
|
||
|
||
|
||
|
||
var rootReReadingTaskId = _visitTaskReReadingRepository.Where(t => t.NewReReadingTaskId == task.Id).Select(u => u.RootReReadingTaskId).FirstOrDefault();
|
||
|
||
//添加申请记录
|
||
var visitTaskReReading = await _visitTaskReReadingRepository.AddAsync(new VisitTaskReReading()
|
||
{
|
||
TrialId = applyReReadingCommand.TrialId,
|
||
RootReReadingTaskId = rootReReadingTaskId == Guid.Empty ? task.Id : rootReReadingTaskId,
|
||
OriginalReReadingTaskId = task.Id,
|
||
RequestReReadingTime = DateTime.Now,
|
||
RequestReReadingUserId = _userInfo.Id,
|
||
IsCopyOrigenalForms = applyReReadingCommand.IsCopyOrigenalForms,
|
||
IsCopyFollowForms = applyReReadingCommand.IsCopyFollowForms,
|
||
RequestReReadingReason = applyReReadingCommand.RequestReReadingReason,
|
||
RequestReReadingType = applyReReadingCommand.RequestReReadingType,
|
||
|
||
});
|
||
}
|
||
|
||
|
||
await _visitTaskRepository.SaveChangesAsync();
|
||
|
||
return ResponseOutput.Ok();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 重阅原任务跟踪处理 只会在同意的时候调用这个
|
||
/// </summary>
|
||
/// <param name="origenalTask"></param>
|
||
/// <param name="agreeReReadingCommand"></param>
|
||
private void ReReadingTaskTrackingDeal(VisitTask origenalTask, ConfirmReReadingCommand agreeReReadingCommand)
|
||
{
|
||
if (origenalTask.ReReadingApplyState == ReReadingApplyState.DocotorHaveApplyed || origenalTask.ReReadingApplyState == ReReadingApplyState.TrialGroupHaveApplyed)
|
||
{
|
||
origenalTask.ReReadingApplyState = agreeReReadingCommand.RequestReReadingResultEnum == RequestReReadingResult.Agree ? ReReadingApplyState.Agree : ReReadingApplyState.Reject;
|
||
origenalTask.TaskState = agreeReReadingCommand.RequestReReadingResultEnum == RequestReReadingResult.Agree ? TaskState.HaveReturned : origenalTask.TaskState;
|
||
}
|
||
else
|
||
{
|
||
//---当前重阅任务状态不为已申请状态,不允许进行处理,请刷新页面
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_InvalidReapplyStatus"]);
|
||
}
|
||
|
||
}
|
||
|
||
private async Task SetMedicalReviewInvalidAsync(List<VisitTask> influenceTaskList, bool isPMApply = true)
|
||
{
|
||
//将医学审核设置为失效
|
||
var taskIdList = influenceTaskList.Select(t => t.Id).ToList();
|
||
|
||
//PM 申请 医学审核任务状态为待审核、审核中的,设置为失效。
|
||
|
||
//IR 申请 当前任务进入医学审核,医学审核任务未签名且结论中是否有问题项,答案为否的,设置为失效
|
||
|
||
if (isPMApply)
|
||
{
|
||
await _taskMedicalReviewRepository.UpdatePartialFromQueryAsync(t => taskIdList.Contains(t.VisitTaskId) && t.AuditState != MedicalReviewAuditState.HaveSigned, u => new TaskMedicalReview() { IsInvalid = true });
|
||
|
||
}
|
||
else
|
||
{
|
||
|
||
await _taskMedicalReviewRepository.UpdatePartialFromQueryAsync(t => taskIdList.Contains(t.VisitTaskId) && t.IsHaveQuestion == false && t.AuditState != MedicalReviewAuditState.HaveSigned, u => new TaskMedicalReview() { IsInvalid = true });
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// PM 申请重阅 被同意 或者 PM 直接退回的时候影响
|
||
/// </summary>
|
||
/// <param name="subjectId"></param>
|
||
/// <returns></returns>
|
||
private async Task SetReReadingOrBackInfluenceAnalysisAsync(Guid subjectId)
|
||
{
|
||
if (await _repository.AnyAsync<VisitTask>(t => t.IsAnalysisCreate && t.SubjectId == subjectId))
|
||
{
|
||
await _repository.UpdatePartialFromQueryAsync<Subject>(t => t.Id == subjectId, u => new Subject() { IsReReadingOrBackInfluenceAnalysis = true });
|
||
|
||
}
|
||
|
||
}
|
||
|
||
public DateTime GetSuggessFinishTime(bool isInOrder, UrgentType urgentType)
|
||
{
|
||
|
||
var datetime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 22, 0, 0).AddDays(7);
|
||
|
||
return datetime;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 确认重阅与否 1同意 2 拒绝
|
||
/// </summary>
|
||
/// <param name="agreeReReadingCommand"></param>
|
||
/// <param name="_visitTaskCommonService"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[UnitOfWork]
|
||
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })]
|
||
|
||
public async Task<IResponseOutput> ConfirmReReading(ConfirmReReadingCommand agreeReReadingCommand, [FromServices] IVisitTaskHelpeService _visitTaskCommonService)
|
||
{
|
||
|
||
var trialId = agreeReReadingCommand.TrialId;
|
||
|
||
foreach (var item in agreeReReadingCommand.ConfirmReReadingList)
|
||
{
|
||
|
||
var origenalTask = (await _visitTaskRepository.Where(t => item.OriginalReReadingTaskId == t.Id).FirstOrDefaultAsync()).IfNullThrowException();
|
||
|
||
|
||
if ((origenalTask.TaskState != TaskState.Effect && origenalTask.TaskState != TaskState.Freeze))
|
||
{
|
||
//---当前申请重阅任务的状态,已被其他任务重阅已影响,不允许对该状态下的任务进行重阅同意与否操作
|
||
return ResponseOutput.NotOk(_localizer["VisitTask_ReapplyStatusConflict"]);
|
||
}
|
||
|
||
|
||
var criterionConfig = await _trialReadingCriterionRepository.Where(x => x.Id == origenalTask.TrialReadingCriterionId).Select(x => new { x.ReadingTool, x.CriterionType, x.IsAdditionalAssessment, x.IsReadingTaskViewInOrder }).FirstOrDefaultAsync();
|
||
|
||
//更新申请信息
|
||
var visitTaskReReadingAppply = await _visitTaskReReadingRepository.FirstOrDefaultAsync(t => t.Id == item.Id);
|
||
visitTaskReReadingAppply.RequestReReadingConfirmUserId = _userInfo.Id;
|
||
visitTaskReReadingAppply.RequestReReadingResultEnum = agreeReReadingCommand.RequestReReadingResultEnum;
|
||
visitTaskReReadingAppply.RequestReReadingRejectReason = agreeReReadingCommand.RequestReReadingRejectReason;
|
||
|
||
|
||
Expression<Func<VisitTask, bool>> filterExpression = t => t.TrialId == trialId && t.SubjectId == origenalTask.SubjectId && (t.TaskState == TaskState.Effect || t.TaskState == TaskState.Freeze);
|
||
|
||
//是否是一致性分析任务 正常申请 会影响一致性分析任务
|
||
filterExpression = filterExpression.And(t => t.IsAnalysisCreate == origenalTask.IsAnalysisCreate);
|
||
|
||
//IR 申请1.1 基线重阅,影响附加评估两个IR所有的任务
|
||
var isIR1Point1AdditionalAssessmentBaseline = false;
|
||
|
||
//附加评估 IR 和PM 看到的影响列表不一样
|
||
|
||
//1.1 有附加评估,会影响其他标准的任务
|
||
if (criterionConfig.CriterionType == CriterionType.RECIST1Point1 && criterionConfig.IsAdditionalAssessment)
|
||
{
|
||
// PM申请 SPM / CPM审批
|
||
if (visitTaskReReadingAppply.RequestReReadingType == RequestReReadingType.TrialGroupApply && (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM))
|
||
{
|
||
filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == origenalTask.TrialReadingCriterionId || t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB);
|
||
}
|
||
//IR 申请 PM审批
|
||
else
|
||
{
|
||
|
||
// 1.1 基线任务影响BM任务
|
||
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager && _subjectVisitRepository.Any(t => t.Id == origenalTask.SourceSubjectVisitId && t.IsBaseLine == true))
|
||
{
|
||
|
||
isIR1Point1AdditionalAssessmentBaseline = true;
|
||
|
||
//filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == origenalTask.TrialReadingCriterionId || t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB);
|
||
}
|
||
// 1.1 非基线任务不影响BM任务
|
||
else
|
||
{
|
||
filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == origenalTask.TrialReadingCriterionId);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//默认影响的都是该标准的任务
|
||
filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == origenalTask.TrialReadingCriterionId);
|
||
}
|
||
|
||
|
||
if (agreeReReadingCommand.RequestReReadingResultEnum == RequestReReadingResult.Agree)
|
||
{
|
||
|
||
//IR申请 PM 审批 注意这里有一致性分析的申请同意 不会回退访视,在此要生成影响的访视任务
|
||
if (visitTaskReReadingAppply.RequestReReadingType == RequestReReadingType.DocotorApply && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager )
|
||
{
|
||
|
||
//有序阅片
|
||
if (criterionConfig.IsReadingTaskViewInOrder)
|
||
{
|
||
|
||
filterExpression = filterExpression.And(t => t.VisitTaskNum >= origenalTask.VisitTaskNum);
|
||
|
||
|
||
|
||
#region 这里时影响其他的任务 /*不包括申请的任务 申请的任务,在上面会统一处理*/
|
||
|
||
var influenceTaskList = await _visitTaskRepository.Where(filterExpression, true).OrderBy(t => t.VisitTaskNum).ToListAsync();
|
||
|
||
var trakingOrigenalTask = influenceTaskList.Where(t => t.Id == origenalTask.Id).FirstOrDefault();
|
||
|
||
|
||
|
||
foreach (var influenceTask in influenceTaskList)
|
||
{
|
||
var beforeTaskState = influenceTask.TaskState;
|
||
|
||
//已签名的任务 设置转变后的标志
|
||
if (criterionConfig.CriterionType == CriterionType.IRECIST1Point1 && influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
{
|
||
var isConvertedTask = _visitTaskRepository.Where(t => t.Id == influenceTask.Id).Select(t => t.IsConvertedTask).FirstOrDefault();
|
||
|
||
if (isConvertedTask)
|
||
{
|
||
influenceTask.IsHistoryConvertedTask = true;
|
||
}
|
||
}
|
||
|
||
|
||
//处理申请的任务
|
||
if (influenceTask.Id == origenalTask.Id)
|
||
{
|
||
ReReadingTaskTrackingDeal(influenceTask, agreeReReadingCommand);
|
||
|
||
|
||
await SetMedicalReviewInvalidAsync(influenceTaskList, false);
|
||
|
||
await InfluenceAddtioncalEvaluationCritrionAsync(origenalTask, influenceTaskList.Where(t => t.Id != origenalTask.Id).Where(t => t.SourceSubjectVisitId != null).Select(t => (Guid)t.SourceSubjectVisitId).Distinct().ToList(), false);
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
if (influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
{
|
||
influenceTask.TaskState = TaskState.HaveReturned;
|
||
|
||
trakingOrigenalTask?.TaskInfluenceList.Add(new TaskInfluence() { InfluenceTaskId = influenceTask.Id, OptType = ReReadingOrBackOptType.Return });
|
||
}
|
||
else
|
||
{
|
||
influenceTask.TaskState = TaskState.Adbandon;
|
||
|
||
trakingOrigenalTask?.TaskInfluenceList.Add(new TaskInfluence() { InfluenceTaskId = influenceTask.Id, OptType = ReReadingOrBackOptType.Abandon });
|
||
}
|
||
|
||
// 影响的任务 仅仅访视类别的才生成 或者就是IR 申请的任务
|
||
if (influenceTask.ReadingCategory == ReadingCategory.Visit || influenceTask.Id == origenalTask.Id)
|
||
{
|
||
|
||
|
||
// 影响的其他标准的附加评估的任务不立即生成 比如1.1基线 重阅 PM 同意仅仅生成1.1任务,不生成BM任务
|
||
if (criterionConfig.CriterionType == CriterionType.RECIST1Point1 && criterionConfig.IsAdditionalAssessment && influenceTask.TrialReadingCriterionId != origenalTask.TrialReadingCriterionId)
|
||
{
|
||
//BM标准的不生成任务
|
||
continue;
|
||
}
|
||
|
||
|
||
// i1.1标准 当前任务是转变任务,并且影响列表里有转变之前的任务 那么该访视任务就不生成
|
||
if (criterionConfig.CriterionType == CriterionType.IRECIST1Point1)
|
||
{
|
||
//申请的任务是冻结的任务(该任务发生转变) 影响自己 以及转变后的 以及后续任务 但是生成的时候,仅仅生成转变之前的
|
||
//申请的是转变之后的任务 (转变生成的任务) 影响自己以及后续任务 生成转变后的任务
|
||
if (influenceTask.BeforeConvertedTaskId != null && influenceTaskList.Any(t => t.Id == influenceTask.BeforeConvertedTaskId))
|
||
{
|
||
//有转化的任务 和转化之前的任务时,转化后的任务时不生成的
|
||
continue;
|
||
|
||
}
|
||
|
||
//var canGenerateTaskIdList = influenceTaskList.GroupBy(t => new { t.VisitTaskNum, t.DoctorUserId, t.TrialReadingCriterionId, t.SubjectId })
|
||
// .Select(g => g.First().Id);
|
||
|
||
}
|
||
|
||
#region 影响的任务生成
|
||
|
||
await _visitTaskCommonService.AddTaskAsync(new GenerateTaskCommand()
|
||
{
|
||
TrialId = trialId,
|
||
|
||
ReadingCategory = GenerateTaskCategory.ReReading,
|
||
|
||
ReReadingTask = influenceTask,
|
||
|
||
//同步才可以
|
||
Action = (newTask) =>
|
||
{
|
||
//申请表 设置新任务Id
|
||
visitTaskReReadingAppply.NewReReadingTaskId = newTask.Id;
|
||
|
||
//生成的任务分配给原始医生
|
||
newTask.DoctorUserId = origenalTask.DoctorUserId;
|
||
newTask.TaskAllocationState = TaskAllocationState.Allocated;
|
||
newTask.AllocateTime = DateTime.Now;
|
||
newTask.SuggesteFinishedTime = GetSuggessFinishTime(true, UrgentType.NotUrget);
|
||
|
||
|
||
if (visitTaskReReadingAppply.IsCopyOrigenalForms && influenceTask.Id == origenalTask.Id)
|
||
{
|
||
if (origenalTask.ReadingCategory == ReadingCategory.Visit)
|
||
{
|
||
var list = _readingTaskQuestionAnswerRepository.Where(t => t.VisitTaskId == origenalTask.Id).ToList();
|
||
|
||
foreach (var item in list)
|
||
{
|
||
item.Id = Guid.Empty;
|
||
item.VisitTaskId = newTask.Id;
|
||
}
|
||
|
||
_ = _readingTaskQuestionAnswerRepository.AddRangeAsync(list).Result;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
//拷贝后续表单
|
||
if (visitTaskReReadingAppply.IsCopyFollowForms && origenalTask.VisitTaskNum != influenceTask.VisitTaskNum)
|
||
{
|
||
if (origenalTask.ReadingCategory == ReadingCategory.Visit)
|
||
{
|
||
var list = _readingTaskQuestionAnswerRepository.Where(t => t.VisitTaskId == origenalTask.Id).ToList();
|
||
|
||
foreach (var item in list)
|
||
{
|
||
item.Id = Guid.Empty;
|
||
item.VisitTaskId = newTask.Id;
|
||
}
|
||
|
||
_ = _readingTaskQuestionAnswerRepository.AddRangeAsync(list).Result;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
});
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
|
||
|
||
}
|
||
//无序阅片 只会申请访视类型和裁判类型的任务 注意这里有一致性分析的申请同意
|
||
else
|
||
{
|
||
|
||
|
||
//1.当前任务及裁判任务
|
||
//2.影响当前阅片人的任务
|
||
filterExpression = filterExpression.And(t => t.Id == origenalTask.Id || t.Id == origenalTask.JudgeVisitTaskId);
|
||
|
||
|
||
var influenceTaskList = await _visitTaskRepository.Where(filterExpression, true).ToListAsync();
|
||
|
||
var trakingOrigenalTask = influenceTaskList.Where(t => t.Id == origenalTask.Id).FirstOrDefault();
|
||
|
||
foreach (var influenceTask in influenceTaskList)
|
||
{
|
||
//申请原任务处理
|
||
if (influenceTask.Id == origenalTask.Id)
|
||
{
|
||
ReReadingTaskTrackingDeal(influenceTask, agreeReReadingCommand);
|
||
|
||
await SetMedicalReviewInvalidAsync(influenceTaskList, false);
|
||
|
||
trakingOrigenalTask?.TaskInfluenceList.Add(new TaskInfluence() { InfluenceTaskId = influenceTask.Id, OptType = ReReadingOrBackOptType.Return });
|
||
}
|
||
else
|
||
{
|
||
if (influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
{
|
||
influenceTask.TaskState = TaskState.HaveReturned;
|
||
|
||
trakingOrigenalTask?.TaskInfluenceList.Add(new TaskInfluence() { InfluenceTaskId = influenceTask.Id, OptType = ReReadingOrBackOptType.Return });
|
||
}
|
||
else
|
||
{
|
||
influenceTask.TaskState = TaskState.Adbandon;
|
||
|
||
trakingOrigenalTask?.TaskInfluenceList.Add(new TaskInfluence() { InfluenceTaskId = influenceTask.Id, OptType = ReReadingOrBackOptType.Abandon });
|
||
}
|
||
}
|
||
|
||
|
||
if (influenceTask.ReadingCategory == ReadingCategory.Visit || influenceTask.Id == origenalTask.Id)
|
||
{
|
||
await _visitTaskCommonService.AddTaskAsync(new GenerateTaskCommand()
|
||
{
|
||
TrialId = trialId,
|
||
|
||
ReadingCategory = GenerateTaskCategory.ReReading,
|
||
|
||
ReReadingTask = origenalTask,
|
||
|
||
//同步才可以
|
||
Action = (newTask) =>
|
||
{
|
||
//申请表 设置新任务Id
|
||
visitTaskReReadingAppply.NewReReadingTaskId = newTask.Id;
|
||
|
||
////生成的任务分配给原始医生
|
||
newTask.DoctorUserId = origenalTask.DoctorUserId;
|
||
newTask.TaskAllocationState = TaskAllocationState.Allocated;
|
||
newTask.AllocateTime = DateTime.Now;
|
||
newTask.SuggesteFinishedTime = GetSuggessFinishTime(true, UrgentType.NotUrget);
|
||
|
||
|
||
//裁判任务 需要进行特殊处理 在重阅逻辑里面处理
|
||
|
||
|
||
if (visitTaskReReadingAppply.IsCopyOrigenalForms && influenceTask.Id == origenalTask.Id)
|
||
{
|
||
if (origenalTask.ReadingCategory == ReadingCategory.Visit)
|
||
{
|
||
var list = _readingTaskQuestionAnswerRepository.Where(t => t.VisitTaskId == origenalTask.Id).ToList();
|
||
|
||
foreach (var item in list)
|
||
{
|
||
item.Id = Guid.Empty;
|
||
item.VisitTaskId = newTask.Id;
|
||
}
|
||
|
||
_ = _readingTaskQuestionAnswerRepository.AddRangeAsync(list).Result;
|
||
}
|
||
|
||
}
|
||
|
||
//拷贝后续表单
|
||
if (visitTaskReReadingAppply.IsCopyFollowForms && origenalTask.VisitTaskNum != influenceTask.VisitTaskNum)
|
||
{
|
||
if (origenalTask.ReadingCategory == ReadingCategory.Visit)
|
||
{
|
||
var list = _readingTaskQuestionAnswerRepository.Where(t => t.VisitTaskId == origenalTask.Id).ToList();
|
||
|
||
foreach (var item in list)
|
||
{
|
||
item.Id = Guid.Empty;
|
||
item.VisitTaskId = newTask.Id;
|
||
}
|
||
|
||
_ = _readingTaskQuestionAnswerRepository.AddRangeAsync(list).Result;
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
//---不符合 PM申请 SPM / CPM审批 | IR申请 PM 审批
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_ReReadTaskAlreadyAffected"]);
|
||
}
|
||
|
||
}
|
||
else if (agreeReReadingCommand.RequestReReadingResultEnum == RequestReReadingResult.Reject)
|
||
{
|
||
|
||
if (origenalTask.ReReadingApplyState == ReReadingApplyState.DocotorHaveApplyed || origenalTask.ReReadingApplyState == ReReadingApplyState.TrialGroupHaveApplyed)
|
||
{
|
||
await _visitTaskRepository.UpdatePartialFromQueryAsync(t => t.Id == origenalTask.Id, u => new VisitTask()
|
||
{
|
||
ReReadingApplyState = ReReadingApplyState.Reject
|
||
});
|
||
}
|
||
else
|
||
{
|
||
//---当前重阅任务状态不为已申请状态,不允许进行处理,请刷新页面
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_InvalidReapplyStatus"]);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
await _visitTaskRepository.SaveChangesAsync();
|
||
|
||
return ResponseOutput.Ok();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// PM 设置任务 退回
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPut("{trialId:guid}/{taskId:guid}")]
|
||
[UnitOfWork]
|
||
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })]
|
||
|
||
public async Task<IResponseOutput> PMSetTaskBack(Guid trialId, Guid taskId)
|
||
{
|
||
|
||
//var trialConfig = (await _trialRepository.Where(t => t.Id == trialId).Select(t => new { TrialId = t.Id, t.IsReadingTaskViewInOrder, t.ReadingType }).FirstOrDefaultAsync()).IfNullThrowException();
|
||
|
||
|
||
var task = (await _visitTaskRepository.Where(t => t.Id == taskId).FirstOrDefaultAsync()).IfNullThrowException();
|
||
|
||
var criterionConfig = (await _trialReadingCriterionRepository.Where(x => x.Id == task.TrialReadingCriterionId).Select(x => new { x.ReadingTool, x.CriterionType, x.IsAutoCreate, x.IsAdditionalAssessment, x.IsReadingTaskViewInOrder }).FirstOrDefaultAsync()).IfNullThrowException();
|
||
|
||
if (criterionConfig.IsAutoCreate == false)
|
||
{
|
||
//---手动生成任务的不允许在此入口影像退回
|
||
return ResponseOutput.NotOk(_localizer["VisitTask_NoImageReturn"]);
|
||
}
|
||
|
||
if (task.TaskState != TaskState.Effect || task.ReadingCategory != ReadingCategory.Visit || task.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
{
|
||
//---仅仅允许针对生效、未完成的访视任务进行退回操作,请刷新页面数据
|
||
return ResponseOutput.NotOk(_localizer["VisitTask_NonEffectiveTaskCannotBeReturned"]);
|
||
}
|
||
|
||
|
||
if (await _subjectVisitRepository.AnyAsync(t => t.Id == task.SourceSubjectVisitId && t.CheckState != CheckStateEnum.CVPassed))
|
||
{
|
||
//---当前访视已回退到影像上传,不允许继续回退!
|
||
return ResponseOutput.NotOk(_localizer["VisitTask_NoFurtherReturn"]);
|
||
}
|
||
|
||
|
||
if (task.IsAnalysisCreate)
|
||
{
|
||
//---一致性分析的任务,不允许设置退回
|
||
return ResponseOutput.NotOk(_localizer["VisitTask_ConsistencyTaskCannotBeReturned"]);
|
||
}
|
||
|
||
Expression<Func<VisitTask, bool>> filterExpression = t => t.TrialId == trialId && t.SubjectId == task.SubjectId && (t.TaskState == TaskState.Effect || t.TaskState == TaskState.Freeze) /*&& t.TaskAllocationState == TaskAllocationState.Allocated*/;
|
||
|
||
|
||
if (criterionConfig.CriterionType == CriterionType.RECIST1Point1 && criterionConfig.IsAdditionalAssessment)
|
||
{
|
||
//影像退回,必定影响两个标准的任务
|
||
filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == task.TrialReadingCriterionId || t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB);
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
//默认影响的都是该标准的任务
|
||
filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == task.TrialReadingCriterionId);
|
||
}
|
||
|
||
//PM 才允许操作
|
||
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager)
|
||
{
|
||
|
||
#region 有序 无序公用流程
|
||
|
||
|
||
//执行类似一致性核查回退流程 回退访视到影像上传流程
|
||
await VisitBackAsync(task.SourceSubjectVisitId);
|
||
|
||
#endregion
|
||
|
||
|
||
|
||
//有序
|
||
if (criterionConfig.IsReadingTaskViewInOrder)
|
||
{
|
||
|
||
|
||
filterExpression = filterExpression.And(t => t.IsAnalysisCreate == false);
|
||
|
||
|
||
|
||
//另一个阅片人的任务根据任务进度自动进入PM退回或PM申请重阅
|
||
filterExpression = filterExpression.And(t => t.VisitTaskNum >= task.VisitTaskNum);
|
||
|
||
|
||
var influenceTaskList = await _visitTaskRepository.Where(filterExpression, true).ToListAsync();
|
||
|
||
|
||
|
||
#region 方式二
|
||
|
||
var origenalTask = influenceTaskList.Where(t => t.Id == task.Id).FirstOrDefault();
|
||
|
||
foreach (var influenceTask in influenceTaskList)
|
||
{
|
||
|
||
//已签名的任务 设置转变后的标志
|
||
if (criterionConfig.CriterionType == CriterionType.IRECIST1Point1 && influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
{
|
||
var isConvertedTask = _visitTaskRepository.Where(t => t.Id == influenceTask.Id).Select(t => t.IsConvertedTask).FirstOrDefault();
|
||
|
||
if (isConvertedTask)
|
||
{
|
||
influenceTask.IsHistoryConvertedTask = true;
|
||
}
|
||
}
|
||
|
||
//同意的访视 因为要记录具体的操作,所以废弃
|
||
if (influenceTask.Id == task.Id)
|
||
{
|
||
|
||
await InfluenceAddtioncalEvaluationCritrionAsync(task, influenceTaskList.Where(t => t.Id != task.Id).Where(t => t.SourceSubjectVisitId != null).Select(t => (Guid)t.SourceSubjectVisitId).Distinct().ToList());
|
||
|
||
await SetReReadingOrBackInfluenceAnalysisAsync(influenceTask.SubjectId);
|
||
|
||
await SetMedicalReviewInvalidAsync(influenceTaskList);
|
||
|
||
|
||
influenceTask.IsPMSetBack = true;
|
||
}
|
||
|
||
if (influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
{
|
||
influenceTask.TaskState = TaskState.HaveReturned;
|
||
origenalTask.TaskInfluenceList.Add(new TaskInfluence() { InfluenceTaskId = influenceTask.Id, OptType = ReReadingOrBackOptType.Return });
|
||
}
|
||
else
|
||
{
|
||
influenceTask.TaskState = TaskState.Adbandon;
|
||
origenalTask.TaskInfluenceList.Add(new TaskInfluence() { InfluenceTaskId = influenceTask.Id, OptType = ReReadingOrBackOptType.Abandon });
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
|
||
}
|
||
|
||
else
|
||
{
|
||
//无序 无序阅片没有 全局 肿瘤学
|
||
|
||
// 申请该访视的任务 申请人失效 另外一个人重阅重置或者失效
|
||
|
||
var currentVisitList = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == task.SourceSubjectVisitId && t.ReadingCategory == ReadingCategory.Visit && (t.TaskState == TaskState.Effect || t.TaskState == TaskState.Freeze) && t.VisitTaskNum == task.VisitTaskNum, true).ToListAsync();
|
||
|
||
await SetMedicalReviewInvalidAsync(currentVisitList);
|
||
|
||
var origenalTask = currentVisitList.Where(t => t.Id == task.Id).First();
|
||
|
||
foreach (var influenceTask in currentVisitList)
|
||
{
|
||
if (influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
{
|
||
//另外阅片人完成阅片了 就设置为重阅重置
|
||
influenceTask.TaskState = TaskState.HaveReturned;
|
||
|
||
origenalTask.TaskInfluenceList.Add(new TaskInfluence() { InfluenceTaskId = influenceTask.Id, OptType = ReReadingOrBackOptType.Return });
|
||
}
|
||
else
|
||
{
|
||
influenceTask.TaskState = TaskState.Adbandon;
|
||
|
||
origenalTask.TaskInfluenceList.Add(new TaskInfluence() { InfluenceTaskId = influenceTask.Id, OptType = ReReadingOrBackOptType.Abandon });
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
//---仅PM 可以进行回退操作
|
||
return ResponseOutput.NotOk(_localizer["VisitTask_PMOnlyAllowedForReturn"]);
|
||
}
|
||
|
||
await _visitTaskRepository.SaveChangesAsync();
|
||
|
||
return ResponseOutput.Ok();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 基线退回 影响附加评估标准 是否参与评估
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private async Task InfluenceAddtioncalEvaluationCritrionAsync(VisitTask task, List<Guid> otherVisitIdList, bool isImageBack = true)
|
||
{
|
||
|
||
var criterion = await _trialReadingCriterionRepository.FindAsync(task.TrialReadingCriterionId);
|
||
|
||
if (criterion.CriterionType == CriterionType.RECIST1Point1)
|
||
{
|
||
//影像回退了|| IR 申请及基线重阅
|
||
if (_subjectVisitRepository.Any(t => t.Id == task.SourceSubjectVisitId && t.IsBaseLine))
|
||
{
|
||
await _subjectCriteriaEvaluationRepository.UpdatePartialFromQueryAsync(t => t.TrialReadingCriterion.IsAutoCreate == false && t.SubjectId == task.SubjectId, u => new SubjectCriteriaEvaluation()
|
||
{
|
||
IsJoinEvaluation = false
|
||
});
|
||
|
||
//删除筛选的访视数据
|
||
await _subjectCriteriaEvaluationVisitFilterRepository.BatchDeleteNoTrackingAsync(t => t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB && t.SubjectId == task.SubjectId);
|
||
|
||
//删除筛选的序列数据
|
||
await _subjectCriteriaEvaluationVisitStudyFilterRepository.BatchDeleteNoTrackingAsync(t => t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB && t.SubjectVisit.SubjectId == task.SubjectId);
|
||
}
|
||
else if (isImageBack)
|
||
{
|
||
//当前访视筛选状态重置,任务生成状态重置
|
||
if (task.SourceSubjectVisitId != null)
|
||
{
|
||
await _subjectCriteriaEvaluationVisitFilterRepository.UpdatePartialFromQueryAsync(t => t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB && t.SubjectVisit.SubjectId == task.SubjectId && t.SubjectVisitId == task.SourceSubjectVisitId,
|
||
t => new SubjectCriteriaEvaluationVisitFilter()
|
||
{
|
||
ImageFilterState = ImageFilterState.None,
|
||
ImageDeterminationResultState = ImageDeterminationResultState.None,
|
||
IsGeneratedTask = false
|
||
});
|
||
|
||
//删除序列数据
|
||
await _subjectCriteriaEvaluationVisitStudyFilterRepository.BatchDeleteNoTrackingAsync(t => t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB && t.SubjectVisit.SubjectId == task.SubjectId && t.SubjectVisitId == task.SourceSubjectVisitId);
|
||
}
|
||
|
||
|
||
//BM后续访视 ,筛选状态不变,任务生成状态重置(实际该访视任务状态 可能是重阅重置了或者失效了,需要后续生成,或者取消分配了,需要后续重新分配)
|
||
await _subjectCriteriaEvaluationVisitFilterRepository.UpdatePartialFromQueryAsync(t => t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB && t.SubjectVisit.SubjectId == task.SubjectId && otherVisitIdList.Contains(t.SubjectVisitId),
|
||
t => new SubjectCriteriaEvaluationVisitFilter()
|
||
{
|
||
IsGeneratedTask = false
|
||
});
|
||
}
|
||
else
|
||
{
|
||
//IR 端 非基线申请重阅 不影响
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
//包括临床数据签名状态
|
||
private async Task VisitBackAsync(Guid? subjectVisitId)
|
||
{
|
||
var sv = (await _subjectVisitRepository.FirstOrDefaultAsync(t => t.Id == subjectVisitId)).IfNullThrowException();
|
||
|
||
|
||
//需要重新产生任务
|
||
sv.IsVisitTaskGenerated = false;
|
||
sv.IsPMBackOrReReading = true;
|
||
|
||
sv.AuditState = AuditStateEnum.None;
|
||
sv.SubmitState = SubmitStateEnum.ToSubmit;
|
||
sv.ReadingStatus = ReadingStatusEnum.ImageNotSubmit;
|
||
|
||
//回退后,回退状态恢复
|
||
sv.RequestBackState = RequestBackStateEnum.NotRequest;
|
||
sv.IsCheckBack = false;
|
||
sv.CheckBackTime = null;
|
||
sv.CheckState = CheckStateEnum.None;
|
||
sv.CheckChallengeState = CheckChanllengeTypeEnum.None;
|
||
|
||
sv.SVENDTC = null;
|
||
sv.SVSTDTC = null;
|
||
|
||
sv.PreliminaryAuditTime = null;
|
||
sv.SubmitTime = null;
|
||
sv.ReviewAuditTime = null;
|
||
sv.CurrentActionUserExpireTime = null;
|
||
|
||
|
||
sv.IsTake = false;
|
||
sv.CurrentActionUserId = null;
|
||
sv.PreliminaryAuditUserId = null;
|
||
sv.ReviewAuditUserId = null;
|
||
|
||
|
||
if (sv.IsBaseLine)
|
||
{
|
||
await _readingClinicalDataReposiotry.UpdatePartialFromQueryAsync(t => t.ReadingId == sv.Id && (t.ClinicalDataTrialSet.ClinicalDataLevel == ClinicalLevel.Subject || t.ClinicalDataTrialSet.ClinicalDataLevel == ClinicalLevel.SubjectVisit), c => new ReadingClinicalData() { IsSign = false, ReadingClinicalDataState = ReadingClinicalDataStatus.HaveUploaded });
|
||
|
||
}
|
||
else
|
||
{
|
||
await _readingClinicalDataReposiotry.UpdatePartialFromQueryAsync(t => t.ReadingId == sv.Id && t.ClinicalDataTrialSet.ClinicalDataLevel == ClinicalLevel.SubjectVisit, c => new ReadingClinicalData()
|
||
{
|
||
IsSign = false,
|
||
ReadingClinicalDataState = ReadingClinicalDataStatus.HaveUploaded,
|
||
IsBlind = null,
|
||
IsComplete = null
|
||
});
|
||
}
|
||
|
||
|
||
|
||
//await _repository.AddAsync(new CheckChallengeDialog() { SubjectVisitId = subjectVisitId, TalkContent = "PM/APM同意一致性核查回退。", UserTypeEnum = (UserTypeEnum)_userInfo.UserTypeEnumInt });
|
||
|
||
await _repository.BatchDeleteAsync<TrialQCQuestionAnswer>(t => t.SubjectVisitId == subjectVisitId);
|
||
await _repository.BatchDeleteAsync<DicomInstance>(t => t.DicomSerie.IsDeleted);
|
||
await _repository.BatchDeleteAsync<DicomSeries>(t => t.IsDeleted);
|
||
|
||
var success = await _subjectVisitRepository.SaveChangesAsync();
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 影响提示列表 重阅仅仅针对已完成的任务申请 退回针对的是未完成的(退回仅仅针对是访视类型的)
|
||
/// </summary>
|
||
/// <param name="taskId"></param>
|
||
/// <param name="isReReading"> 重阅还是直接回退</param>
|
||
/// <param name="applyId"> 申请记录的Id</param>
|
||
/// <returns></returns>
|
||
[HttpGet("{taskId:guid}/{isReReading:bool}")]
|
||
public async Task<(List<InfluenceTaskInfo>, object)> GetReReadingOrBackInfluenceTaskList(Guid taskId, bool isReReading, Guid? applyId)
|
||
{
|
||
var isIRAppyTaskInfluenced = false;
|
||
|
||
var filterObj = (await _visitTaskRepository.FirstOrDefaultNoTrackingAsync(t => t.Id == taskId)).IfNullThrowException();
|
||
var trialId = filterObj.TrialId;
|
||
|
||
|
||
var criterionConfig = (await _trialReadingCriterionRepository.Where(x => x.Id == filterObj.TrialReadingCriterionId).Select(x => new { x.ReadingTool, x.CriterionType, x.IsAdditionalAssessment, x.IsReadingTaskViewInOrder }).FirstOrDefaultAsync()).IfNullThrowException();
|
||
|
||
Expression<Func<VisitTask, bool>> filterExpression = t => t.TrialId == trialId && t.SubjectId == filterObj.SubjectId && (t.TaskState == TaskState.Effect || t.TaskState == TaskState.Freeze) /*&& t.TaskAllocationState == TaskAllocationState.Allocated*/;
|
||
|
||
//是否是一致性分析任务 (一致性分析的任务 不会产生裁判 肿瘤学 仅仅有生成的访视和全局)
|
||
|
||
filterExpression = filterExpression.And(t => t.IsAnalysisCreate == filterObj.IsAnalysisCreate);
|
||
|
||
//IR 申请1.1 基线重阅,影响附加评估所有的任务
|
||
var isIR1Point1AdditionalAssessmentBaseline = false;
|
||
|
||
//附加评估 IR 和PM 看到的影响列表不一样
|
||
if (criterionConfig.CriterionType == CriterionType.RECIST1Point1 && criterionConfig.IsAdditionalAssessment)
|
||
{
|
||
|
||
// IR 申请 PM 同意
|
||
if (((_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager && applyId != null && await _visitTaskReReadingRepository.AnyAsync(t => t.Id == applyId && t.CreateUser.UserTypeEnum == UserTypeEnum.IndependentReviewer))
|
||
|| (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.IndependentReviewer && applyId == null)))
|
||
{
|
||
|
||
// 1.1 基线任务影响BM任务
|
||
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager && _subjectVisitRepository.Any(t => t.Id == filterObj.SourceSubjectVisitId && t.IsBaseLine == true))
|
||
{
|
||
|
||
isIR1Point1AdditionalAssessmentBaseline = true;
|
||
//filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == filterObj.TrialReadingCriterionId || t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB);
|
||
|
||
|
||
}
|
||
// 1.1 非基线任务不影响BM任务
|
||
else
|
||
{
|
||
filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == filterObj.TrialReadingCriterionId);
|
||
}
|
||
|
||
}
|
||
//(1、PM回退,PM申请重阅,SPM同意回退)
|
||
else
|
||
{
|
||
filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == filterObj.TrialReadingCriterionId || t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB);
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//默认影响的都是该标准的任务
|
||
filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == filterObj.TrialReadingCriterionId);
|
||
}
|
||
|
||
|
||
|
||
//重阅影响
|
||
if (isReReading)
|
||
{
|
||
|
||
|
||
|
||
//IR 申请 PM 同意 仅仅影响自己
|
||
|
||
if ((_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager && applyId != null && await _visitTaskReReadingRepository.AnyAsync(t => t.Id == applyId && (t.CreateUser.UserTypeEnum == UserTypeEnum.SR|| t.CreateUser.UserTypeEnum == UserTypeEnum.PI)))
|
||
|| ( (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR|| _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI) && applyId == null))
|
||
{
|
||
|
||
//当前任务及其之后的所有访视任务、全局任务、裁判任务、肿瘤学阅片任务
|
||
|
||
//有序
|
||
if (criterionConfig.IsReadingTaskViewInOrder)
|
||
{
|
||
|
||
filterExpression = filterExpression.And(t => t.VisitTaskNum >= filterObj.VisitTaskNum);
|
||
}
|
||
//无序
|
||
else
|
||
{
|
||
//1.当前任务及裁判任务
|
||
//2.影响当前阅片人的任务
|
||
filterExpression = filterExpression.And(t => t.Id == filterObj.Id || t.Id == filterObj.JudgeVisitTaskId);
|
||
}
|
||
|
||
|
||
//throw new BusinessValidationFailedException("仅允许PM 同意 IR 申请的任务");
|
||
}
|
||
else
|
||
{
|
||
//---当前用户查看列表未定义
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_UndefinedList"]);
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
//退回影响 仅仅针对是访视类型的 影响多个标准的任务
|
||
else
|
||
{
|
||
|
||
if (filterObj.IsAnalysisCreate)
|
||
{
|
||
//---不允许退回一致性分析任务
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_NoConsistencyReturn"]);
|
||
}
|
||
|
||
if (filterObj.ReadingCategory == ReadingCategory.Visit && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager)
|
||
{
|
||
//有序
|
||
if (criterionConfig.IsReadingTaskViewInOrder)
|
||
{
|
||
// 当前任务及其之后的所有访视任务 两个阅片人的
|
||
|
||
//2.当前任务未完成,不会产生全局任务。后续任务均为访视任务,且均为待阅片,取消分配;
|
||
filterExpression = filterExpression.And(t => t.VisitTaskNum >= filterObj.VisitTaskNum);
|
||
|
||
|
||
if (await _visitTaskReReadingRepository.AnyAsync(t => t.RequestReReadingType == RequestReReadingType.DocotorApply && t.RequestReReadingResultEnum == RequestReReadingResult.Default &&
|
||
t.OriginalReReadingTask.VisitTaskNum >= filterObj.VisitTaskNum && t.OriginalReReadingTask.SubjectId == filterObj.SubjectId && t.OriginalReReadingTask.TrialReadingCriterionId == filterObj.TrialReadingCriterionId && t.OriginalReReadingTask.IsAnalysisCreate == filterObj.IsAnalysisCreate))
|
||
{
|
||
isIRAppyTaskInfluenced = true;
|
||
}
|
||
}
|
||
//无序
|
||
else
|
||
{
|
||
//自己和另一个人的当前任务 退回针对的是未完成的肯定不会有裁判
|
||
filterExpression = filterExpression.And(t => t.VisitTaskNum == filterObj.VisitTaskNum);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//---仅仅访视类型的任务支持PM退回
|
||
throw new BusinessValidationFailedException(_localizer["VisitTask_VisitTypeTaskAllowedForPMOnly"]);
|
||
}
|
||
|
||
}
|
||
|
||
var list = await _visitTaskRepository.Where(filterExpression)
|
||
//IR 申请的时候,仅仅看到影响自己的
|
||
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.IndependentReviewer, t => t.DoctorUserId == _userInfo.Id)
|
||
.OrderBy(t => t.VisitTaskNum).ProjectTo<InfluenceTaskInfo>(_mapper.ConfigurationProvider).ToListAsync();
|
||
|
||
#region 影响后的操作
|
||
|
||
foreach (var influenceTask in list)
|
||
{
|
||
influenceTask.OptType = influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned ? ReReadingOrBackOptType.Return : ReReadingOrBackOptType.Abandon;
|
||
|
||
|
||
#region 变更前 注释
|
||
|
||
//if (isReReading)
|
||
//{
|
||
|
||
// if ((_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager && applyId != null) || (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.IndependentReviewer && applyId == null))
|
||
// {
|
||
// //有序
|
||
// if (criterionConfig.IsReadingTaskViewInOrder)
|
||
// {
|
||
// if (influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Return;
|
||
// }
|
||
// else
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Abandon;
|
||
// }
|
||
// //else if (influenceTask.ReadingTaskState == ReadingTaskState.Reading)
|
||
// //{
|
||
// // influenceTask.OptType = ReReadingOrBackOptType.Abandon;
|
||
// //}
|
||
// //else
|
||
// //{
|
||
// // throw new BusinessValidationFailedException("IR 申请重阅,不会影响到后续未读的任务,当前影响列表有未读的任务,请核查");
|
||
// //}
|
||
// }
|
||
// else
|
||
// {
|
||
// if (influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Return;
|
||
// }
|
||
// else
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Abandon;
|
||
// }
|
||
// }
|
||
// }
|
||
// if (((_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM) && applyId != null) || (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager && applyId == null))
|
||
// {
|
||
// //有序
|
||
// if (criterionConfig.IsReadingTaskViewInOrder)
|
||
// {
|
||
// //申请的访视 要不是重阅重置,要不就是失效 不会存在取消分配
|
||
// if (influenceTask.ReadingCategory == ReadingCategory.Visit && influenceTask.VisitTaskNum != filterObj.VisitTaskNum)
|
||
// {
|
||
// if (influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Return;
|
||
// }
|
||
// else if (influenceTask.ReadingTaskState == ReadingTaskState.Reading)
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Abandon;
|
||
// }
|
||
// else
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.CancelAssign;
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// if (influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Return;
|
||
// }
|
||
// else
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Abandon;
|
||
// }
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// if (influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Return;
|
||
// }
|
||
// else
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Abandon;
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
//}
|
||
////PM退回
|
||
//else
|
||
//{
|
||
|
||
|
||
|
||
// //有序
|
||
// if (criterionConfig.IsReadingTaskViewInOrder)
|
||
// {
|
||
// //申请的访视 要不是重阅重置,要不就是失效 不会存在取消分配
|
||
// if (influenceTask.ReadingCategory == ReadingCategory.Visit && influenceTask.VisitTaskNum != filterObj.VisitTaskNum)
|
||
// {
|
||
// //后续访视处理访视
|
||
// if (influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Return;
|
||
// }
|
||
// else if (influenceTask.ReadingTaskState == ReadingTaskState.Reading)
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Abandon;
|
||
// }
|
||
// else
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.CancelAssign;
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// //申请的访视 全局肿瘤学
|
||
|
||
// if (influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned)
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Return;
|
||
// }
|
||
// else
|
||
// {
|
||
// influenceTask.OptType = ReReadingOrBackOptType.Abandon;
|
||
// }
|
||
// }
|
||
// }
|
||
// //无序
|
||
// else
|
||
// {
|
||
// //重阅重置或者失效
|
||
// influenceTask.OptType = influenceTask.ReadingTaskState == ReadingTaskState.HaveSigned ? ReReadingOrBackOptType.Return : ReReadingOrBackOptType.Abandon;
|
||
// }
|
||
|
||
|
||
//}
|
||
|
||
|
||
#endregion
|
||
|
||
}
|
||
#endregion
|
||
|
||
|
||
return (list, new { IsIRAppyTaskInfluenced = isIRAppyTaskInfluenced });
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 获取已影响的列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public async Task<List<InfluenceTaskInfo>> GetInfluencedTaskList(Guid taskId)
|
||
{
|
||
var list = await _repository.Where<TaskInfluence>(t => t.OriginalTaskId == taskId)/*.Select(t => t.InfluenceTask)*/.ProjectTo<InfluenceTaskInfo>(_mapper.ConfigurationProvider).ToListAsync();
|
||
|
||
return list;
|
||
}
|
||
|
||
|
||
}
|
||
}
|