84 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C#
		
	
	
using IRaCIS.Core.Domain.Share;
 | 
						||
using IRaCIS.Core.Infrastructure;
 | 
						||
 | 
						||
 | 
						||
namespace IRaCIS.Core.Application.Service.Verify
 | 
						||
{
 | 
						||
    public static class QCCommonVerify
 | 
						||
    {
 | 
						||
        /// <summary>
 | 
						||
        /// 验证CRC 是否已提交 已提交 就不允许进行任何操作,如果是IQC 那么还验证是否是当前任务领取人
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="_repository"></param>
 | 
						||
        /// <param name="_userInfo"></param>
 | 
						||
        /// <param name="subjectVisitId"></param>
 | 
						||
        /// <returns></returns>
 | 
						||
        /// <exception cref="BusinessValidationFailedException"></exception>
 | 
						||
        public static async Task VerifyIsCRCSubmmitAsync(IRepository _repository, IUserInfo _userInfo, Guid? subjectVisitId=null)
 | 
						||
        {
 | 
						||
            //添加的时候不验证
 | 
						||
            if (subjectVisitId != null)
 | 
						||
            {
 | 
						||
                if (await _repository.AnyAsync<SubjectVisit>(t => t.Id == subjectVisitId && t.SubmitState == SubmitStateEnum.Submitted &&
 | 
						||
                          (!t.QCChallengeList.Any(u => u.ReuploadEnum == QCChanllengeReuploadEnum.QCAgreeUpload))))
 | 
						||
                {
 | 
						||
                    throw new BusinessValidationFailedException("CRC 已提交影像,不能进行操作。");
 | 
						||
                }
 | 
						||
            }
 | 
						||
 | 
						||
            //IQC 的时候 验证是不是当前领取人
 | 
						||
            if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.IQC)
 | 
						||
            {
 | 
						||
 | 
						||
                await VerifyIsCanQCAsync(_repository, _userInfo, null, subjectVisitId);
 | 
						||
 | 
						||
            }
 | 
						||
 | 
						||
        }
 | 
						||
 | 
						||
        public static async Task VerifyIsCanQCAsync(IRepository _repository,IUserInfo _userInfo,  SubjectVisit? subjectVisit=null, Guid? subjectVisitId=null)
 | 
						||
        {
 | 
						||
            if (subjectVisitId != null)
 | 
						||
            {
 | 
						||
                subjectVisit = (await _repository.FirstOrDefaultAsync<SubjectVisit>(t => t.Id == subjectVisitId)).IfNullThrowException();
 | 
						||
            }
 | 
						||
 | 
						||
            if (subjectVisit!.CurrentActionUserId != _userInfo.Id)
 | 
						||
            {
 | 
						||
                throw new BusinessValidationFailedException("您不是该质控任务当前领取人,没有操作权限!");
 | 
						||
            }
 | 
						||
        }
 | 
						||
 | 
						||
 | 
						||
 | 
						||
        public static async Task VerifyStudyImageDataAsync(IRepository _repository,  Guid subjectId, Guid subjectVisitId,DateTime imageDate)
 | 
						||
        {
 | 
						||
            var visitList = await _repository.Where<SubjectVisit>(t => t.SubjectId == subjectId).Select(t => new { t.VisitNum, t.EarliestScanDate, t.LatestScanDate, t.Id }).ToListAsync();
 | 
						||
 | 
						||
            var currentVisitNum = await _repository.Where<SubjectVisit>(t => t.Id == subjectVisitId).Select(t => t.VisitNum).FirstOrDefaultAsync();
 | 
						||
 | 
						||
 | 
						||
 | 
						||
            //小于当前访视 最近的最晚拍片
 | 
						||
            var before = visitList.Where(u => u.VisitNum < currentVisitNum).Max(k => k.LatestScanDate);
 | 
						||
 | 
						||
            if (before != null && before > imageDate)
 | 
						||
            {
 | 
						||
                throw new BusinessValidationFailedException($"当前访视检查时间{imageDate.ToString("yyyy-MM-dd")}不能早于前序访视检查时间{before?.ToString("yyyy-MM-dd")},请核对检查数据是否有误");
 | 
						||
            }
 | 
						||
 | 
						||
 | 
						||
            //大于当前访视 最近的最早拍片日期  
 | 
						||
            var after = visitList.Where(u => u.VisitNum > currentVisitNum).Min(k => k.EarliestScanDate);
 | 
						||
 | 
						||
            if (after != null && after < imageDate)
 | 
						||
            {
 | 
						||
                throw new BusinessValidationFailedException($"当前访视检查时间{imageDate.ToString("yyyy-MM-dd")}不能晚于该访视之后的检查时间{after?.ToString("yyyy-MM-dd")},请核对检查数据是否有误");
 | 
						||
 | 
						||
            }
 | 
						||
        }
 | 
						||
 | 
						||
 | 
						||
    }
 | 
						||
}
 |