From 38fc05e0d94a411cf3f70dcecaf413c70614b134 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 6 Jul 2023 15:10:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_ServiceExtensions/QuartZSetup.cs | 7 +- .../BackGroundJob/CancelTaskQuartZJob.cs | 69 +++ .../Allocation/DTO/VisitTaskViewModel.cs | 30 +- .../Service/Allocation/VisitTaskService.cs | 396 ++++-------------- .../ReadingImageTaskService.cs | 208 ++++++--- .../SiteSurvey/TrialSiteSurveyService.cs | 6 +- IRaCIS.Core.Domain/Allocation/VisitTask.cs | 2 + IRaCIS.Core.Domain/Visit/Subject.cs | 3 + 8 files changed, 324 insertions(+), 397 deletions(-) create mode 100644 IRaCIS.Core.Application/BackGroundJob/CancelTaskQuartZJob.cs diff --git a/IRaCIS.Core.API/_ServiceExtensions/QuartZSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/QuartZSetup.cs index 2f42e8f7c..d3aaacfd9 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/QuartZSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/QuartZSetup.cs @@ -26,11 +26,14 @@ namespace IRaCIS.Core.API ); q.AddTrigger(t => t .WithIdentity("TrialStatusTrigger") - .ForJob(jobKey) - + .ForJob(jobKey) .WithCronSchedule("0 0 * * * ?") .WithDescription("My regular trial work trigger") ); + + + + }); // ASP.NET Core hosting diff --git a/IRaCIS.Core.Application/BackGroundJob/CancelTaskQuartZJob.cs b/IRaCIS.Core.Application/BackGroundJob/CancelTaskQuartZJob.cs new file mode 100644 index 000000000..7a74f8ece --- /dev/null +++ b/IRaCIS.Core.Application/BackGroundJob/CancelTaskQuartZJob.cs @@ -0,0 +1,69 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using EasyCaching.Core; +using IRaCIS.Core.Domain; +using IRaCIS.Core.Infra.EFCore; +using IRaCIS.Core.Domain.Models; +using Microsoft.Extensions.Logging; +using Quartz; +using IRaCIS.Core.Domain.Share; +using IRaCIS.Core.Application.ViewModel; + +namespace IRaCIS.Application.Services.BackGroundJob +{ + + public class CancelTaskQuartZJob : IJob + { + + private readonly IRepository _subjectRepository; + private readonly ILogger _logger; + private readonly IRepository _visitTaskRepository; + + public CancelTaskQuartZJob(IRepository subjectRepository, IEasyCachingProvider provider, ILogger logger, IRepository visitTaskRepository) + { + _subjectRepository = subjectRepository; + _logger = logger; + _visitTaskRepository = visitTaskRepository; + } + + public async Task Execute(IJobExecutionContext context) + + { + _logger.LogInformation($"开始执行QuartZ定时取消任务作业"); + + try + { + JobDataMap dataMap = context.JobDetail.JobDataMap; + + bool isInOrder = (bool)dataMap.Get("IsInOrder"); + + if (isInOrder) + { + Guid id = (Guid)dataMap.Get("SubjectId"); + + await _subjectRepository.UpdatePartialFromQueryAsync(t => t.Id ==id, u => new Subject() { ClaimUserId = null }, true); + } + else + { + Guid id = (Guid)dataMap.Get("VisitTaskId"); + + await _visitTaskRepository.UpdatePartialFromQueryAsync(t => t.Id == id, u => new VisitTask() { ClaimUserId = null }, true); + } + + } + catch (Exception e) + { + _logger.LogError($"QuartZ定时取消任务异常" + e.Message); + } + _logger.LogInformation("QuartZ定时取消任务作业结束"); + } + + + + + + + + } +} \ No newline at end of file diff --git a/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs b/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs index b92e3efe9..7ac16c2c3 100644 --- a/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs +++ b/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs @@ -259,6 +259,9 @@ namespace IRaCIS.Core.Application.ViewModel public Guid SubjectId { get; set; } public string SubjectCode { get; set; } = String.Empty; + public Guid? ClaimUserId { get;set; } + + public bool IsUrgent => UnReadTaskList.Any(t => t.IsUrgent); public int UnReadTaskCount { get; set; } @@ -417,15 +420,15 @@ namespace IRaCIS.Core.Application.ViewModel /// public int FinishTaskCount { get; set; } - /// - /// 未完成裁判任务数量 - /// - public int UnReadJudgeTaskCount { get; set; } + ///// + ///// 未完成裁判任务数量 + ///// + //public int UnReadJudgeTaskCount { get; set; } - /// - /// 完成裁判任务数量 - /// - public int FinishJudgeTaskCount { get; set; } + ///// + ///// 完成裁判任务数量 + ///// + //public int FinishJudgeTaskCount { get; set; } /// /// 建议完成时间 @@ -798,6 +801,17 @@ namespace IRaCIS.Core.Application.ViewModel CancelAssign = 4, } + public class ClaimSubjectDto + { + public bool IsInOrder { get; set; } + + public Guid? VisitTaskId { get; set; } + + public Guid SubejctId { get; set; } + + public bool IsClaim { get; set; } + } + } diff --git a/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs b/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs index 07caf5009..b1588a0ee 100644 --- a/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs +++ b/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs @@ -21,6 +21,8 @@ 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 { @@ -749,7 +751,7 @@ namespace IRaCIS.Core.Application.Service.Allocation .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) @@ -914,10 +916,10 @@ namespace IRaCIS.Core.Application.Service.Allocation var trialReadingCriterionId = iRUnReadSubjectQuery.TrialReadingCriterionId; - var criterionConfig = await _trialReadingCriterionRepository.Where(x => x.Id == iRUnReadSubjectQuery.TrialReadingCriterionId).FirstNotNullAsync(); + var critrion = await _trialReadingCriterionRepository.Where(x => x.Id == iRUnReadSubjectQuery.TrialReadingCriterionId).FirstNotNullAsync(); - var readingTool = criterionConfig.ReadingTool; - var isReadingTaskViewInOrder = criterionConfig.IsReadingTaskViewInOrder; + var readingTool = critrion.ReadingTool; + var isReadingTaskViewInOrder = critrion.IsReadingTaskViewInOrder; #region 按照Subject 维度 if (isReadingTaskViewInOrder) @@ -961,87 +963,61 @@ namespace IRaCIS.Core.Application.Service.Allocation RandomReadInfo = new IRUnReadOutDto(), IsReadingTaskViewInOrder = isReadingTaskViewInOrder, ReadingTool = readingTool, - IseCRFShowInDicomReading = criterionConfig.IseCRFShowInDicomReading, - IsReadingShowSubjectInfo = criterionConfig.IsReadingShowSubjectInfo, - IsReadingShowPreviousResults = criterionConfig.IsReadingShowPreviousResults, - DigitPlaces = criterionConfig.DigitPlaces, - CriterionType = criterionConfig.CriterionType, + IseCRFShowInDicomReading = critrion.IseCRFShowInDicomReading, + IsReadingShowSubjectInfo = critrion.IsReadingShowSubjectInfo, + IsReadingShowPreviousResults = critrion.IsReadingShowPreviousResults, + DigitPlaces = critrion.DigitPlaces, + CriterionType = critrion.CriterionType, }); } else { - var taskQuery = _visitTaskRepository.Where(x => x.TrialId == iRUnReadSubjectQuery.TrialId && x.DoctorUserId == _userInfo.Id && x.TaskState == TaskState.Effect && x.TrialReadingCriterionId == trialReadingCriterionId) - // .Where(x=>x.Subject.ClinicalDataList.Any(c => c.IsSign && (c.ReadingId == x.SouceReadModuleId || c.ReadingId == x.SourceSubjectVisitId))) - .Where(x => !x.Subject.IsDeleted).Where(x => (x.IsNeedClinicalDataSign && x.IsClinicalDataSign) || !x.IsNeedClinicalDataSign); + + 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() { - FinishJudgeTaskCount = await taskQuery.Where(x => x.ReadingCategory == ReadingCategory.Judge && x.ReadingTaskState == ReadingTaskState.HaveSigned).CountAsync(), 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), - UnReadJudgeTaskCount = await taskQuery.Where(x => x.ReadingCategory == ReadingCategory.Judge && x.ReadingTaskState != ReadingTaskState.HaveSigned).CountAsync(), + + UnReadTaskCount = await taskQuery.Where(x => x.ReadingCategory != ReadingCategory.Judge && x.ReadingTaskState != ReadingTaskState.HaveSigned).CountAsync(), }; - - - var visitGroupQuery = taskQuery.GroupBy(x => new { x.SubjectId, x.Subject.Code, x.BlindSubjectCode }); - - - - var visitTaskQuery = visitGroupQuery.Select(x => new IRUnReadSubjectView() - { - SubjectId = x.Key.SubjectId, - SubjectCode = x.Key.BlindSubjectCode == string.Empty ? x.Key.Code : x.Key.BlindSubjectCode, - - 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) - //不能对包含聚合或子查询的表达式执行聚合函数 - //&& !x.Any(t => t.ReadingTaskState != ReadingTaskState.HaveSigned && t.IsNeedClinicalDataSign == true && t.IsClinicalDataSign == false && t.VisitTaskNum 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); - - - var totalCount = await visitGroupQuery.CountAsync(); - var currentPageData = await visitTaskQuery.ToListAsync(); - var result = new PageOutput() { PageSize = iRUnReadSubjectQuery.PageSize, PageIndex = iRUnReadSubjectQuery.PageIndex, - TotalCount = totalCount, - CurrentPageData = currentPageData, }; return (result, new @@ -1049,11 +1025,11 @@ namespace IRaCIS.Core.Application.Service.Allocation IsReadingTaskViewInOrder = isReadingTaskViewInOrder, RandomReadInfo = iRUnReadOut, ReadingTool = readingTool, - IseCRFShowInDicomReading = criterionConfig.IseCRFShowInDicomReading, - IsReadingShowSubjectInfo = criterionConfig.IsReadingShowSubjectInfo, - IsReadingShowPreviousResults = criterionConfig.IsReadingShowPreviousResults, - DigitPlaces = criterionConfig.DigitPlaces, - CriterionType = criterionConfig.CriterionType, + IseCRFShowInDicomReading = critrion.IseCRFShowInDicomReading, + IsReadingShowSubjectInfo = critrion.IsReadingShowSubjectInfo, + IsReadingShowPreviousResults = critrion.IsReadingShowPreviousResults, + DigitPlaces = critrion.DigitPlaces, + CriterionType = critrion.CriterionType, }); } @@ -1081,20 +1057,20 @@ namespace IRaCIS.Core.Application.Service.Allocation var readingDivisionEnum = critrion.ReadingDivisionEnum; - var piReadingScopenEnum= critrion.PIReadingScopenEnum; + var piReadingScopenEnum = critrion.PIReadingScopenEnum; var visitQuery = _visitTaskRepository - .Where(x => x.TrialId == inDto.TrialId && x.TaskState == TaskState.Effect) + .Where(x => x.TrialId == inDto.TrialId && x.TaskState == TaskState.Effect) .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.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.AllBaseline, + t => t.SourceSubjectVisit.IsBaseLine == true) + + //PI 阅片所有 .WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI && piReadingScopenEnum == PIReadingScopenEnum.AllBaselineandVisit, t => true) @@ -1104,27 +1080,28 @@ namespace IRaCIS.Core.Application.Service.Allocation .WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR && piReadingScopenEnum == PIReadingScopenEnum.AllBaseline, t => t.SourceSubjectVisit.IsBaseLine == false) - //SR 不阅片 + //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, + .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) ) + .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)) + .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 }); + 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), @@ -1438,7 +1415,7 @@ namespace IRaCIS.Core.Application.Service.Allocation //添加申请记录 var visitTaskReReading = await _visitTaskReReadingRepository.AddAsync(new VisitTaskReReading() { - TrialId=applyReReadingCommand.TrialId, + TrialId = applyReReadingCommand.TrialId, RootReReadingTaskId = rootReReadingTaskId == Guid.Empty ? task.Id : rootReReadingTaskId, OriginalReReadingTaskId = task.Id, RequestReReadingTime = DateTime.Now, @@ -1572,7 +1549,7 @@ namespace IRaCIS.Core.Application.Service.Allocation //1.1 有附加评估,会影响其他标准的任务 if (criterionConfig.CriterionType == CriterionType.RECIST1Point1 && criterionConfig.IsAdditionalAssessment) { - // PM申请 SPM / CPM审批 + // 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); @@ -2278,7 +2255,7 @@ namespace IRaCIS.Core.Application.Service.Allocation Expression> 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) { //影像退回,必定影响两个标准的任务 @@ -2635,10 +2612,10 @@ namespace IRaCIS.Core.Application.Service.Allocation { // 1.1 基线任务影响BM任务 - if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager && _subjectVisitRepository.Any(t=>t.Id==filterObj.SourceSubjectVisitId && t.IsBaseLine==true)) + if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager && _subjectVisitRepository.Any(t => t.Id == filterObj.SourceSubjectVisitId && t.IsBaseLine == true)) { - isIR1Point1AdditionalAssessmentBaseline=true; + isIR1Point1AdditionalAssessmentBaseline = true; //filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == filterObj.TrialReadingCriterionId || t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB); @@ -2654,7 +2631,7 @@ namespace IRaCIS.Core.Application.Service.Allocation else { filterExpression = filterExpression.And(t => t.TrialReadingCriterionId == filterObj.TrialReadingCriterionId || t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB); - + } } else @@ -2677,10 +2654,10 @@ namespace IRaCIS.Core.Application.Service.Allocation || (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.IndependentReviewer && applyId == null)) { - //当前任务及其之后的所有访视任务、全局任务、裁判任务、肿瘤学阅片任务 + //当前任务及其之后的所有访视任务、全局任务、裁判任务、肿瘤学阅片任务 - //有序 - if (criterionConfig.IsReadingTaskViewInOrder) + //有序 + if (criterionConfig.IsReadingTaskViewInOrder) { switch (filterObj.ReadingCategory) @@ -2704,7 +2681,7 @@ namespace IRaCIS.Core.Application.Service.Allocation )) || t.Id == filterObj.Id) ; } - // IR 申请1.1 基线重阅,影响附加评估所有的任务 + // IR 申请1.1 基线重阅,影响附加评估所有的任务 else if (isIR1Point1AdditionalAssessmentBaseline) { filterExpression = filterExpression.And(t => t.VisitTaskNum >= filterObj.VisitTaskNum && @@ -2713,7 +2690,7 @@ namespace IRaCIS.Core.Application.Service.Allocation // 裁判 肿瘤学是另外的医生做 || t.ReadingCategory == ReadingCategory.Judge || t.ReadingCategory == ReadingCategory.Oncology - )&& t.TrialReadingCriterionId==filterObj.TrialReadingCriterionId )||( t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB)) + ) && t.TrialReadingCriterionId == filterObj.TrialReadingCriterionId) || (t.TrialReadingCriterion.CriterionType == CriterionType.RECIST1Pointt1_MB)) ); } else @@ -3060,229 +3037,6 @@ namespace IRaCIS.Core.Application.Service.Allocation return list; } - - #region 暂时废弃 - - - ///// - ///// 自动一次性分配所有未分配的 Subject 给医生 暂时废弃 - ///// - ///// - ///// - //[HttpPost] - //[UnitOfWork] - //[Obsolete] - //public async Task AutoSubjectAssignDoctor(AutoSubjectAssignCommand autoSubjectAssignCommand) - //{ - // //自动分配的话,需要把手动分配的给删掉 - - - // var trialId = autoSubjectAssignCommand.TrialId; - // var isJudge = autoSubjectAssignCommand.IsJudgeDoctor; - - - // //获取项目配置 判断应该分配几个医生 - // var trialConfig = (await _trialRepository.Where(t => t.Id == trialId).Select(t => new { TrialId = t.Id/*, t.ReadingType*/, t.IsFollowVisitAutoAssign, t.IsFollowGlobalVisitAutoAssign, t.FollowGlobalVisitAutoAssignDefaultState, t.TaskAllocateObjEnum }).FirstOrDefaultAsync()).IfNullThrowException(); - - - // //获取 已产生任务的Subject 目前分配情况 - // var subjectList = _subjectRepository.Where(t => t.TrialId == trialId) - // .WhereIf(isJudge == false, t => t.SubjectVisitTaskList.Where(t => t.ArmEnum != Arm.JudgeArm).Any()) - // .WhereIf(isJudge, t => t.SubjectVisitTaskList.Where(t => t.ArmEnum == Arm.JudgeArm).Any()) - // ////过滤掉 那些回退的subject - // //.Where(t => !t.SubjectVisitList.Any(t => t.IsPMBackOrReReading)) - // .Select(t => new - // { - // SubjectId = t.Id, - - // //给Subject分配医生的时候, 未确认绑定关系的 - // DoctorUserList = t.SubjectDoctorList.Where(t => isJudge ? t.ArmEnum == Arm.JudgeArm : t.ArmEnum != Arm.JudgeArm).Where(t => t.OrignalSubjectUserId == null).Select(t => new { t.DoctorUserId, t.ArmEnum }), - // //IsApplyed = t.SubjectDoctorList.Where(t => isJudge ? t.ArmEnum == Arm.JudgeArm : t.ArmEnum != Arm.JudgeArm).Where(t => t.OrignalSubjectUserId == null).SelectMany(t => t.SubjectArmVisitTaskList).Any(c => c.DoctorUserId != null) - // IsApplyed = false - // }).ToList(); - - // //已产生任务的Subject数量(裁判情况下,就是产生裁判任务Subject 的数量) - // var subjectCount = subjectList.Count; - - // //获取医生列表(裁判是裁判的医生列表) - // var waitAllocationDoctorList = _taskAllocationRuleRepository.Where(t => t.TrialId == trialId && t.IsEnable) - // .Where(t => t.IsJudgeDoctor == isJudge) - // .Select(t => new AutoAssignResultDTO() { DoctorUserId = t.DoctorUserId, PlanReadingRatio = t.PlanReadingRatio, SubjectCount = subjectCount }) - // .ToList(); - - // if (waitAllocationDoctorList.Count == 0) - // { - // throw new BusinessValidationFailedException("启用的医生数量为0"); - // } - - - // //已分配的 医生的情况 - // var haveAssignedSubjectDoctorList = subjectList.Clone().SelectMany(t => t.DoctorUserList.Select(c => new { t.SubjectId, c.DoctorUserId, c.ArmEnum })).ToList(); - - // //将目前已分配的情况 换到医生的维度 - // foreach (var waitAllocationDoctor in waitAllocationDoctorList) - // { - // waitAllocationDoctor.SubjectArmList = haveAssignedSubjectDoctorList.Where(t => t.DoctorUserId == waitAllocationDoctor.DoctorUserId) - // .Select(g => new SubjectArm() - // { - // SubjectId = g.SubjectId, - // ArmEnum = g.ArmEnum - // }).ToList(); - // } - - - // #region 完全按照Subject 遍历去分 - - - // //仅仅分配未应用的 而且 没有分配医生的 - // foreach (var subject in subjectList.Where(t => t.IsApplyed == false && !t.DoctorUserList.Any())) - // { - // //该Subject 已经分配的医生数量 - // var hasAssignDoctorCount = subject.DoctorUserList.Count(); - - // if (isJudge) - // { - // if (hasAssignDoctorCount > 1) - // { - // throw new BusinessValidationFailedException("当前有Subject裁判绑定医生数量大于1"); - - // } - - // var allocateDoctor = waitAllocationDoctorList.OrderByDescending(t => t.Weight).ThenByDescending(t => t.PlanReadingRatio).FirstOrDefault(); - - // //将分配结果记录 - // waitAllocationDoctorList.FirstOrDefault(t => t.DoctorUserId == allocateDoctor.DoctorUserId).SubjectArmList.Add(new SubjectArm() - // { - // SubjectId = subject.SubjectId, - // ArmEnum = Arm.JudgeArm - // }); - - // await _subjectUserRepository.AddAsync(new SubjectUser() { TrialId = trialId, SubjectId = subject.SubjectId, DoctorUserId = allocateDoctor.DoctorUserId, ArmEnum = Arm.JudgeArm, AssignTime = DateTime.Now }); - - // } - // else - // { - - // //分配两个医生 - // if (trialConfig.ReadingType == ReadingMethod.Double) - // { - - - // if (hasAssignDoctorCount > 2) - // { - // throw new BusinessValidationFailedException("双重阅片当前有Subject绑定医生数量大于2"); - - // } - - // var allocateDoctorList = waitAllocationDoctorList.OrderByDescending(t => t.Weight).ThenByDescending(t => t.PlanReadingRatio).Take(2).ToList(); - - - // #region 看阅片人之前在Subject哪个组做的多 - - // var preferredDoctor1Arm = waitAllocationDoctorList.Where(t => t.DoctorUserId == allocateDoctorList[0].DoctorUserId) - // .SelectMany(t => t.SubjectArmList).GroupBy(t => t.ArmEnum) - // .Select(g => new { ArmEnum = g.Key, SubjectCount = g.Count() }) - // .OrderByDescending(t => t.SubjectCount).FirstOrDefault()?.ArmEnum; - - // var preferredDoctor2Arm = waitAllocationDoctorList.Where(t => t.DoctorUserId == allocateDoctorList[1].DoctorUserId) - // .SelectMany(t => t.SubjectArmList).GroupBy(t => t.ArmEnum) - // .Select(g => new { ArmEnum = g.Key, SubjectCount = g.Count() }) - // .OrderByDescending(t => t.SubjectCount).FirstOrDefault()?.ArmEnum; - - // //存放医生分配的Arm - // var doctor1Arm = Arm.DoubleReadingArm1; - // var doctor2Arm = Arm.DoubleReadingArm2; - - // if (preferredDoctor1Arm == null && preferredDoctor2Arm == null || - // preferredDoctor1Arm == null && preferredDoctor2Arm == Arm.DoubleReadingArm2 || - // preferredDoctor1Arm == Arm.DoubleReadingArm1 && preferredDoctor2Arm == null || - // preferredDoctor1Arm == Arm.DoubleReadingArm1 && preferredDoctor2Arm == Arm.DoubleReadingArm2 - // ) - // { - // doctor1Arm = Arm.DoubleReadingArm1; - // doctor2Arm = Arm.DoubleReadingArm2; - // } - // else if (preferredDoctor1Arm == null && preferredDoctor2Arm == Arm.DoubleReadingArm1 || - // preferredDoctor1Arm == Arm.DoubleReadingArm2 && preferredDoctor2Arm == Arm.DoubleReadingArm1 || - // preferredDoctor1Arm == Arm.DoubleReadingArm2 && preferredDoctor2Arm == null) - // { - // doctor1Arm = Arm.DoubleReadingArm2; - // doctor2Arm = Arm.DoubleReadingArm1; - // } - - // else if (preferredDoctor1Arm == Arm.DoubleReadingArm1 && preferredDoctor2Arm == Arm.DoubleReadingArm1) - // { - // doctor1Arm = Arm.DoubleReadingArm1; - // doctor2Arm = Arm.DoubleReadingArm2; - // } - // else if (preferredDoctor1Arm == Arm.DoubleReadingArm2 && preferredDoctor2Arm == Arm.DoubleReadingArm2) - // { - // doctor1Arm = Arm.DoubleReadingArm2; - // doctor2Arm = Arm.DoubleReadingArm1; - // } - - // #endregion - - - // await _subjectUserRepository.AddAsync(new SubjectUser() { TrialId = trialId, SubjectId = subject.SubjectId, DoctorUserId = allocateDoctorList[0].DoctorUserId, ArmEnum = doctor1Arm, AssignTime = DateTime.Now }); - - - // //将分配结果记录 - // waitAllocationDoctorList.FirstOrDefault(t => t.DoctorUserId == allocateDoctorList[0].DoctorUserId).SubjectArmList.Add(new SubjectArm() - // { - // SubjectId = subject.SubjectId, - // ArmEnum = doctor1Arm - // }); - - - // await _subjectUserRepository.AddAsync(new SubjectUser() { TrialId = trialId, SubjectId = subject.SubjectId, DoctorUserId = allocateDoctorList[1].DoctorUserId, ArmEnum = doctor2Arm, AssignTime = DateTime.Now }); - - // //将分配结果记录 - // waitAllocationDoctorList.FirstOrDefault(t => t.DoctorUserId == allocateDoctorList[1].DoctorUserId).SubjectArmList.Add(new SubjectArm() - // { - // SubjectId = subject.SubjectId, - // ArmEnum = doctor2Arm - // }); - // } - // else if (trialConfig.ReadingType == ReadingMethod.Single) - // { - // if (hasAssignDoctorCount > 1) - // { - // throw new BusinessValidationFailedException("单重阅片当前有Subject绑定医生数量大于1"); - // } - - // var allocateDoctor = waitAllocationDoctorList.OrderByDescending(t => t.Weight).ThenByDescending(t => t.PlanReadingRatio).FirstOrDefault(); - - // //将分配结果记录 - // waitAllocationDoctorList.FirstOrDefault(t => t.DoctorUserId == allocateDoctor.DoctorUserId).SubjectArmList.Add(new SubjectArm() - // { - // SubjectId = subject.SubjectId, - // ArmEnum = Arm.SingleReadingArm - // }); - - // await _subjectUserRepository.AddAsync(new SubjectUser() { TrialId = trialId, SubjectId = subject.SubjectId, DoctorUserId = allocateDoctor.DoctorUserId, ArmEnum = Arm.SingleReadingArm, AssignTime = DateTime.Now }); - - // } - - // } - - // } - - - // #endregion - - - - - - - - // await _subjectUserRepository.SaveChangesAsync(); - // return ResponseOutput.Ok(); - - //} - - - #endregion + } } diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingImageTaskService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingImageTaskService.cs index aa85c41ab..29971a7f2 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingImageTaskService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingImageTaskService.cs @@ -15,6 +15,8 @@ using Newtonsoft.Json.Linq; using Microsoft.Extensions.Caching.Memory; using IRaCIS.Core.Application.Filter; using DocumentFormat.OpenXml.Drawing; +using Quartz; +using IRaCIS.Application.Services.BackGroundJob; namespace IRaCIS.Application.Services { @@ -57,7 +59,7 @@ namespace IRaCIS.Application.Services private readonly IRepository _readingQuestionSystem; private readonly IRepository _noneDicomStudyFileSystem; private readonly IRepository _readingQuestionTrialRepository; - + private readonly IScheduler _scheduler; private readonly IMemoryCache _cache; private readonly ITrialEmailNoticeConfigService _trialEmailNoticeConfigService; @@ -97,9 +99,11 @@ namespace IRaCIS.Application.Services IRepository ReadingQuestionSystem, ITrialEmailNoticeConfigService trialEmailNoticeConfigService, IRepository noneDicomStudyFileSystem, - IRepository readingQuestionTrialRepository + IRepository readingQuestionTrialRepository, + IScheduler scheduler ) { + _scheduler = scheduler; base._mapper = mapper; this._noneDicomStudyRepository = noneDicomStudyRepository; this._visitTaskRepository = visitTaskRepository; @@ -159,9 +163,9 @@ namespace IRaCIS.Application.Services return await _trialDocumentRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialDocConfirmedUserList.Any(y => y.ConfirmUserId == _userInfo.Id && y.ConfirmTime != null) && x.NeedConfirmedUserTypeList.Any(y => y.NeedConfirmUserTypeId == _userInfo.UserTypeId)) - .WhereIf(userType== UserTypeEnum.IndependentReviewer, t => t.FileType.Code == "2" || t.FileType.Code == "6") + .WhereIf(userType == UserTypeEnum.IndependentReviewer, t => t.FileType.Code == "2" || t.FileType.Code == "6") .WhereIf(userType == UserTypeEnum.IQC, t => t.FileType.Code == "4" || t.FileType.Code == "5") - .WhereIf(!canViewUserType.Contains(userType),t=>false) + .WhereIf(!canViewUserType.Contains(userType), t => false) .IgnoreQueryFilters() .Select(x => new GetManualListOutDto() { @@ -490,8 +494,8 @@ namespace IRaCIS.Application.Services VisitTaskNum = x.VisitTaskNum, IsBaseLineTask = x.SourceSubjectVisitId == baselineVisitId, IsCurrentTask = x.Id == inDto.VisitTaskId, - IsConvertedTask=x.IsConvertedTask, - IsFirstChangeTask=x.BeforeConvertedTaskId!=null, + IsConvertedTask = x.IsConvertedTask, + IsFirstChangeTask = x.BeforeConvertedTaskId != null, }).ToListAsync(); @@ -627,9 +631,9 @@ namespace IRaCIS.Application.Services } if (await _visitTaskRepository.AnyAsync(x => x.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId - &&x.IsAnalysisCreate&&taskInfo.IsAnalysisCreate - &&x.SubjectId== taskInfo.SubjectId&&x.TaskState==TaskState.Effect&& - ((x.ReReadingApplyState==ReReadingApplyState.DocotorHaveApplyed && x.DoctorUserId == taskInfo.DoctorUserId)|| x.ReReadingApplyState == ReReadingApplyState.TrialGroupHaveApplyed) + && x.IsAnalysisCreate && taskInfo.IsAnalysisCreate + && x.SubjectId == taskInfo.SubjectId && x.TaskState == TaskState.Effect && + ((x.ReReadingApplyState == ReReadingApplyState.DocotorHaveApplyed && x.DoctorUserId == taskInfo.DoctorUserId) || x.ReReadingApplyState == ReReadingApplyState.TrialGroupHaveApplyed) )) { @@ -708,7 +712,7 @@ namespace IRaCIS.Application.Services { questions.ForEach(x => { - x.IsFirstChangeTask =true; + x.IsFirstChangeTask = true; }); } } @@ -786,7 +790,7 @@ namespace IRaCIS.Application.Services var taskInfo = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).ProjectTo(_mapper.ConfigurationProvider).FirstNotNullAsync(); - if (taskInfo.IsConvertedTask &&taskInfo.BeforeConvertedTaskId!=null) + if (taskInfo.IsConvertedTask && taskInfo.BeforeConvertedTaskId != null) { result.ForEach(x => { @@ -960,7 +964,7 @@ namespace IRaCIS.Application.Services } - if (inDto.TaskId != null ) + if (inDto.TaskId != null) { if (taskInfo.IsConvertedTask) { @@ -968,9 +972,9 @@ namespace IRaCIS.Application.Services } else { - qusetionList = qusetionList.Where(x => x.ConvertShowType == ConvertShowType.All || x.ConvertShowType == ConvertShowType.BeforeShow).OrderBy(x => x.ShowOrder).ToList(); - } - + qusetionList = qusetionList.Where(x => x.ConvertShowType == ConvertShowType.All || x.ConvertShowType == ConvertShowType.BeforeShow).OrderBy(x => x.ShowOrder).ToList(); + } + } var usedGuropIds = qusetionList.Where(x => x.Type == ReadingQestionType.Table).Select(x => x.GroupId).ToList(); @@ -1031,18 +1035,18 @@ namespace IRaCIS.Application.Services && x.VisitTaskNum < taskInfo.VisitTaskNum && x.ArmEnum == taskInfo.ArmEnum && x.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId - && x.ReadingCategory == ReadingCategory.Visit)||x.Id==taskInfo.BeforeConvertedTaskId - ).OrderByDescending(x=>x.VisitTaskNum).Select(x => x.Id).FirstOrDefaultAsync(); + && x.ReadingCategory == ReadingCategory.Visit) || x.Id == taskInfo.BeforeConvertedTaskId + ).OrderByDescending(x => x.VisitTaskNum).Select(x => x.Id).FirstOrDefaultAsync(); if (!criterionInfo.IsReadingTaskViewInOrder) { // 无序的话 不要查 laskTaskId = Guid.NewGuid(); } - lastTaskTableAnswer= await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == laskTaskId).Include(x => x.ReadingTableQuestionTrial).ToListAsync(); + lastTaskTableAnswer = await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == laskTaskId).Include(x => x.ReadingTableQuestionTrial).ToListAsync(); - if (taskInfo.BeforeConvertedTaskId!=null ) + if (taskInfo.BeforeConvertedTaskId != null) { isFirstChangeTask = true; @@ -1104,7 +1108,7 @@ namespace IRaCIS.Application.Services /// /// /// - private async void FindChildQuestion(TrialReadQuestionData item, List questionlists, List tableQuestionLists, List tableAnswers, List tableAnsweRowInfos, List organInfos, List baseLineTableAnswer,bool isFirstChangeTask, List lastTaskTableAnswer,Guid? TaskId) + private async void FindChildQuestion(TrialReadQuestionData item, List questionlists, List tableQuestionLists, List tableAnswers, List tableAnsweRowInfos, List organInfos, List baseLineTableAnswer, bool isFirstChangeTask, List lastTaskTableAnswer, Guid? TaskId) { item.Childrens = questionlists.Where(x => x.ParentId == item.Id || (x.GroupId == item.Id && x.ParentId == null)).ToList(); item.TableQuestions = new TrialReadTableQuestion(); @@ -1230,7 +1234,7 @@ namespace IRaCIS.Application.Services }); - answers.Add("LesionType", rowInfo.LesionType.GetEnumNullInt()); + answers.Add("LesionType", rowInfo.LesionType.GetEnumNullInt()); answers.Add("BlindName", rowInfo.BlindName); answers.Add("IsFirstChangeTask", isFirstChangeTask.ToString()); answers.Add("FromMark", rowInfo.FromMark); @@ -1238,20 +1242,20 @@ namespace IRaCIS.Application.Services answers.Add("MeasureData", rowInfo == null ? string.Empty : rowInfo.MeasureData); answers.Add("RowIndex", x.ToString()); answers.Add("RowId", rowInfo.Id.ToString()); - answers.Add("MarkTool", rowInfo.MarkTool); - answers.Add("StudyId", rowInfo.StudyId.ToString()); + answers.Add("MarkTool", rowInfo.MarkTool); + answers.Add("StudyId", rowInfo.StudyId.ToString()); answers.Add("OrganInfoId", rowInfo.OrganInfoId.ToString()); - answers.Add("IsFristAdd", (rowInfo.FristAddTaskId== TaskId).ToString()); - answers.Add("IsCanEditPosition", rowInfo.IsCanEditPosition.ToString()); + answers.Add("IsFristAdd", (rowInfo.FristAddTaskId == TaskId).ToString()); + answers.Add("IsCanEditPosition", rowInfo.IsCanEditPosition.ToString()); answers.Add("InstanceId", rowInfo == null ? string.Empty : rowInfo.InstanceId.ToString()); answers.Add("SeriesId", rowInfo == null ? string.Empty : rowInfo.SeriesId.ToString()); answers.Add("IsCurrentTaskAdd", rowInfo == null ? false.ToString() : rowInfo.IsCurrentTaskAdd.ToString()); answers.Add("SplitOrMergeLesionName", rowInfo.SplitName.IsNullOrEmpty() ? rowInfo.MergeName : rowInfo.SplitName); answers.Add("SplitOrMergeType", rowInfo.SplitOrMergeType == null ? string.Empty : ((int)rowInfo.SplitOrMergeType).ToString()); - answers.Add("LastTaskState", lastTaskTableAnswer.Where(n=>n.QuestionId== item.Id&&n.ReadingTableQuestionTrial.QuestionMark==QuestionMark.State&&n.RowIndex==x).Select(n=>n.Answer).FirstOrDefault()??string.Empty); - answers.Add("LastTaskMajorAxis", lastTaskTableAnswer.Where(n => n.QuestionId == item.Id && n.ReadingTableQuestionTrial.QuestionMark == QuestionMark.MajorAxis && n.RowIndex == x).Select(n => n.Answer).FirstOrDefault() ?? string.Empty); - answers.Add("LastTaskShortAxis", lastTaskTableAnswer.Where(n => n.QuestionId == item.Id && n.ReadingTableQuestionTrial.QuestionMark == QuestionMark.ShortAxis && n.RowIndex == x).Select(n => n.Answer).FirstOrDefault() ?? string.Empty); - if (rowInfo.LesionType == LesionType.BaselineLesions) + answers.Add("LastTaskState", lastTaskTableAnswer.Where(n => n.QuestionId == item.Id && n.ReadingTableQuestionTrial.QuestionMark == QuestionMark.State && n.RowIndex == x).Select(n => n.Answer).FirstOrDefault() ?? string.Empty); + answers.Add("LastTaskMajorAxis", lastTaskTableAnswer.Where(n => n.QuestionId == item.Id && n.ReadingTableQuestionTrial.QuestionMark == QuestionMark.MajorAxis && n.RowIndex == x).Select(n => n.Answer).FirstOrDefault() ?? string.Empty); + answers.Add("LastTaskShortAxis", lastTaskTableAnswer.Where(n => n.QuestionId == item.Id && n.ReadingTableQuestionTrial.QuestionMark == QuestionMark.ShortAxis && n.RowIndex == x).Select(n => n.Answer).FirstOrDefault() ?? string.Empty); + if (rowInfo.LesionType == LesionType.BaselineLesions) { answers.Add("BaseLineLesionNumber", baseLineTableAnswer.Where(n => n.ReadingTableQuestionTrial.QuestionMark == QuestionMark.LesionNumber && n.RowIndex == rowInfo.RowIndex).Select(x => x.Answer).FirstIsNullReturnEmpty()); } @@ -1436,10 +1440,11 @@ namespace IRaCIS.Application.Services if (tumorAnswer != null) { var isConvertedTask = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Select(x => x.IsConvertedTask).FirstOrDefaultAsync(); - var reportVerify = await _readingCalculateService.GetReportVerify(new GetReportVerifyInDto() { - BeforeConvertedTaskId= taskInfo.BeforeConvertedTaskId, - IsConvertTask= isConvertedTask, - VisitTaskId=inDto.VisitTaskId + var reportVerify = await _readingCalculateService.GetReportVerify(new GetReportVerifyInDto() + { + BeforeConvertedTaskId = taskInfo.BeforeConvertedTaskId, + IsConvertTask = isConvertedTask, + VisitTaskId = inDto.VisitTaskId }); if (tumorAnswer.Answer == reportVerify.TumorEvaluate) @@ -1619,7 +1624,7 @@ namespace IRaCIS.Application.Services await _readingTableAnswerRowInfoRepository.SaveChangesAsync(); } - + // 自动计算 await this._readingCalculateService.CalculateTask(new CalculateTaskInDto() { @@ -1997,7 +2002,7 @@ namespace IRaCIS.Application.Services StudyId = rowInfo.StudyId, IsCanEditPosition = rowInfo.IsCanEditPosition, ReportMark = rowInfo.ReportMark - }) ; + }); foreach (var item in inDto.AnswerList) @@ -2159,13 +2164,13 @@ namespace IRaCIS.Application.Services return ResponseOutput.Ok(true); } - + /// - /// 验证访视提交 - /// - /// - /// + /// 验证访视提交 + /// + /// + /// [HttpPost] public async Task VerifyVisitTaskQuestions(VerifyVisitTaskQuestionsInDto inDto) { @@ -2174,9 +2179,9 @@ namespace IRaCIS.Application.Services // 转化后的任务不应该有新病灶 - var isConvertedTask = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Select(x=>x.IsConvertedTask).FirstNotNullAsync(); + var isConvertedTask = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Select(x => x.IsConvertedTask).FirstNotNullAsync(); - if (isConvertedTask&&(await _readingTableAnswerRowInfoRepository.AnyAsync(x => x.ReadingQuestionTrial.LesionType == LesionType.NewLesions && x.VisitTaskId == inDto.VisitTaskId))) + if (isConvertedTask && (await _readingTableAnswerRowInfoRepository.AnyAsync(x => x.ReadingQuestionTrial.LesionType == LesionType.NewLesions && x.VisitTaskId == inDto.VisitTaskId))) { throw new BusinessValidationFailedException(_localizer["ReadingImage_NotNewFocus"]); } @@ -2266,6 +2271,7 @@ namespace IRaCIS.Application.Services throw new BusinessValidationFailedException(_localizer["ReadingImage_IDMust"]); } + //看已阅的任务 if (inDto.VisitTaskId != null) { task = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Select(x => new GetReadingTaskDto() @@ -2327,25 +2333,37 @@ namespace IRaCIS.Application.Services }).FirstOrDefault(); - + if (task != null) + { + // 有序 自动领取该Subject + await ClaimOrCancelSubjectAsync(new ClaimSubjectDto() { IsClaim = true, SubejctId = task.SubjectId, IsInOrder = true }, _scheduler); + } } else { - task = await _visitTaskRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == trialReadingCriterionId && x.ReadingTaskState != ReadingTaskState.HaveSigned && x.DoctorUserId == _userInfo.Id + //无序取数据 + task = await _visitTaskRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == trialReadingCriterionId && x.ReadingTaskState != ReadingTaskState.HaveSigned /*&& x.DoctorUserId == _userInfo.Id*/ && x.TrialReadingCriterionId == trialReadingCriterionId - && x.TaskState == TaskState.Effect).Select(x => new GetReadingTaskDto() - { - VisitTaskId = x.Id, - ArmEnum = x.ArmEnum, - TaskBlindName = x.TaskBlindName, - ReadingCategory = x.ReadingCategory, - VisistId = x.SourceSubjectVisitId != null ? x.SourceSubjectVisitId.Value : x.ReadModule == null ? default(Guid) : x.ReadModule.SubjectVisitId, - VisitNum = x.VisitTaskNum, - SubjectId = x.SubjectId, - SubjectCode = x.Subject.Code, - TrialReadingCriterionId = x.TrialReadingCriterionId, - }).FirstOrDefaultAsync(); + && x.TaskState == TaskState.Effect) + .Where(x => (x.IsNeedClinicalDataSign && x.IsClinicalDataSign) || !x.IsNeedClinicalDataSign) + .Select(x => new GetReadingTaskDto() + { + VisitTaskId = x.Id, + ArmEnum = x.ArmEnum, + TaskBlindName = x.TaskBlindName, + ReadingCategory = x.ReadingCategory, + VisistId = x.SourceSubjectVisitId != null ? x.SourceSubjectVisitId.Value : x.ReadModule == null ? default(Guid) : x.ReadModule.SubjectVisitId, + VisitNum = x.VisitTaskNum, + SubjectId = x.SubjectId, + SubjectCode = x.Subject.Code, + TrialReadingCriterionId = x.TrialReadingCriterionId, + }).OrderByDescending(t => t.TaskBlindName).FirstOrDefaultAsync(); + if (task != null) + { + // 有序 自动领取该Subject + await ClaimOrCancelSubjectAsync(new ClaimSubjectDto() { IsClaim = true, VisitTaskId = task.VisitTaskId, IsInOrder = false }, _scheduler); + } } if (task == null) @@ -2420,7 +2438,7 @@ namespace IRaCIS.Application.Services task.SubjectCode = blindSubjectCode.IsNullOrEmpty() ? task.SubjectCode : blindSubjectCode; task.ExistsManual = (await GetManualList(new GetManualListInDto() { TrialId = visitTaskInfo.TrialId })).Count() > 0; task.ReadingTaskState = visitTaskInfo.ReadingTaskState; - return task; + return task; } /// @@ -2474,6 +2492,70 @@ namespace IRaCIS.Application.Services + } + + + [HttpPost] + public async Task ClaimOrCancelSubjectAsync(ClaimSubjectDto claimSubjectDto, IScheduler _scheduler) + { + if (claimSubjectDto.IsInOrder) + { + if (claimSubjectDto.IsClaim) + { + await _subjectRepository.UpdatePartialFromQueryAsync(t => t.Id == claimSubjectDto.SubejctId, u => new Subject() { ClaimUserId = _userInfo.Id }, true); + + //定时任务24h取消 + + // 创建一个任务 + IJobDetail job = JobBuilder.Create() + .WithIdentity($"CancelTaskQuartZJob_{_userInfo.Id}", "group") + .UsingJobData("SubjectId", claimSubjectDto.SubejctId) // 传递GUID参数给任务 + .UsingJobData("IsInOrder", claimSubjectDto.IsInOrder) + .Build(); + + // 创建一个触发器,设置任务执行时间为24小时后 + ITrigger trigger = TriggerBuilder.Create() + .WithIdentity("CancelTaskQuartZJob", "group1") + .StartAt(DateTimeOffset.UtcNow.AddHours(24)) + .Build(); + + // 将任务和触发器关联起来,将任务安排到调度器中 + await _scheduler.ScheduleJob(job, trigger); + + //BackgroundJob.Schedule(t => t.CancelQCObtaion(subjectVisitId, DateTime.Now), TimeSpan.FromHours(1)); + + } + else + { + await _subjectRepository.UpdatePartialFromQueryAsync(t => t.Id == claimSubjectDto.SubejctId, u => new Subject() { ClaimUserId = null }, true); + } + } + else + { + if (claimSubjectDto.IsClaim) + { + await _visitTaskRepository.UpdatePartialFromQueryAsync(t => t.Id == claimSubjectDto.VisitTaskId, u => new VisitTask() { ClaimUserId = _userInfo.Id }, true); + + IJobDetail job = JobBuilder.Create() + .WithIdentity($"CancelTaskQuartZJob_{_userInfo.Id}", "group") + .UsingJobData("VisitTaskId",(Guid) claimSubjectDto.VisitTaskId) // 传递GUID参数给任务 + .UsingJobData("IsInOrder", claimSubjectDto.IsInOrder).Build(); + + // 创建一个触发器,设置任务执行时间为24小时后 + ITrigger trigger = TriggerBuilder.Create() + .WithIdentity($"CancelTaskQuartZJob_{_userInfo.Id}", "group") + .StartAt(DateTimeOffset.UtcNow.AddHours(24)) + .Build(); + + // 将任务和触发器关联起来,将任务安排到调度器中 + await _scheduler.ScheduleJob(job, trigger); + } + } + + + + + } /// @@ -2494,9 +2576,9 @@ namespace IRaCIS.Application.Services bool isConverted = false; - var taskinfo = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Include(x=>x.TrialReadingCriterion).FirstNotNullAsync(); + var taskinfo = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Include(x => x.TrialReadingCriterion).FirstNotNullAsync(); - var isConvertedTask=await _visitTaskRepository.Where(x => x.Id == visitTaskId).Select(x=>x.IsConvertedTask).FirstNotNullAsync(); + var isConvertedTask = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Select(x => x.IsConvertedTask).FirstNotNullAsync(); switch (taskinfo.TrialReadingCriterion.CriterionType) { case CriterionType.IRECIST1Point1: @@ -2505,7 +2587,7 @@ namespace IRaCIS.Application.Services if (!isConvertedTask && (await _readingTaskQuestionAnswerRepository.AnyAsync(x => x.VisitTaskId == visitTaskId - && x.ReadingQuestionTrial.QuestionType == QuestionType.Tumor && x.Answer==(((int)OverallAssessment.PD)).ToString())) + && x.ReadingQuestionTrial.QuestionType == QuestionType.Tumor && x.Answer == (((int)OverallAssessment.PD)).ToString())) ) { @@ -2539,7 +2621,7 @@ namespace IRaCIS.Application.Services await _trialEmailNoticeConfigService.BaseBusinessScenarioSendEmailAsync(visitTaskId); } - + } @@ -2583,7 +2665,7 @@ namespace IRaCIS.Application.Services x.IsAnalysisCreate == taskInfo.IsAnalysisCreate && x.ReadingCategory == taskInfo.ReadingCategory && x.Id != taskInfo.Id - ).OrderBy(x=>x.VisitTaskNum).ThenBy(x=>x.TaskState).Select(x => x.Id).ToListAsync(); + ).OrderBy(x => x.VisitTaskNum).ThenBy(x => x.TaskState).Select(x => x.Id).ToListAsync(); reportRelatedTaskIdList = await _visitTaskRepository.Where(x => @@ -2594,7 +2676,7 @@ namespace IRaCIS.Application.Services x.DoctorUserId == taskInfo.DoctorUserId && x.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && x.ReadingTaskState == ReadingTaskState.HaveSigned && - (x.TaskState == TaskState.Effect||x.TaskState==TaskState.Freeze) && + (x.TaskState == TaskState.Effect || x.TaskState == TaskState.Freeze) && x.IsSelfAnalysis == taskInfo.IsSelfAnalysis && x.IsAnalysisCreate == taskInfo.IsAnalysisCreate && x.ReadingCategory == taskInfo.ReadingCategory && diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs index 995efa958..c49c2a0e1 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -736,14 +736,14 @@ namespace IRaCIS.Core.Application.Contracts var trialSiteSurvey = (await _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId).FirstOrDefaultAsync()).IfNullThrowException(); - var siteUserList = await _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurvey.SiteId == trialSiteSurvey.SiteId).Select(t => new { t.TrialSiteSurveyId, t.IsGenerateAccount, t.UserTypeId, t.UserTypeRole.UserTypeEnum, t.TrialRoleName.Code }).ToListAsync(); + var siteUserList = await _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurvey.SiteId == trialSiteSurvey.SiteId).Select(t => new { t.TrialSiteSurveyId, t.IsGenerateAccount, t.IsGenerateSuccess, t.UserTypeId, t.UserTypeRole.UserTypeEnum, t.TrialRoleName.Code }).ToListAsync(); if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.Undefined) { //是第一次 - if(!siteUserList.Any(t=>t.IsGenerateAccount)) + if(!siteUserList.Any(t=>t.IsGenerateSuccess)) { var currentUserList = siteUserList.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId).ToList(); @@ -760,7 +760,7 @@ namespace IRaCIS.Core.Application.Contracts //是第一次 - if (!siteUserList.Any(t => t.IsGenerateAccount)) + if (!siteUserList.Any(t => t.IsGenerateSuccess)) { var currentUserList = siteUserList.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId).ToList(); diff --git a/IRaCIS.Core.Domain/Allocation/VisitTask.cs b/IRaCIS.Core.Domain/Allocation/VisitTask.cs index a6ad76911..e471274f9 100644 --- a/IRaCIS.Core.Domain/Allocation/VisitTask.cs +++ b/IRaCIS.Core.Domain/Allocation/VisitTask.cs @@ -426,6 +426,8 @@ namespace IRaCIS.Core.Domain.Models } } + public Guid? ClaimUserId { get; set; } + } /// diff --git a/IRaCIS.Core.Domain/Visit/Subject.cs b/IRaCIS.Core.Domain/Visit/Subject.cs index 0ad19bb43..c88126424 100644 --- a/IRaCIS.Core.Domain/Visit/Subject.cs +++ b/IRaCIS.Core.Domain/Visit/Subject.cs @@ -123,6 +123,9 @@ namespace IRaCIS.Core.Domain.Models public bool IsReReadingOrBackInfluenceAnalysis { get; set; } + public Guid? ClaimUserId { get; set; } + + //是否分配了读片医生 //public bool IsAssignDoctorUser{get;set;} }