441 lines
		
	
	
		
			22 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			441 lines
		
	
	
		
			22 KiB
		
	
	
	
		
			C#
		
	
	
| using IRaCIS.Core.Domain.Share;
 | |
| using Microsoft.AspNetCore.Mvc;
 | |
| using IRaCIS.Core.Application.Service.Reading.Dto;
 | |
| using MassTransit;
 | |
| using IRaCIS.Core.Infra.EFCore.Common;
 | |
| using System.Linq.Dynamic.Core;
 | |
| using IRaCIS.Core.Application.Service;
 | |
| using IRaCIS.Core.Application.ViewModel;
 | |
| using IRaCIS.Core.Infrastructure;
 | |
| 
 | |
| namespace IRaCIS.Application.Services
 | |
| {
 | |
|     /// <summary>
 | |
|     /// 生成的阅片模块(在大列表上展示的) 阅片期
 | |
|     /// </summary>
 | |
|     [ApiExplorerSettings(GroupName = "Reading")]
 | |
|     public class ReadModuleService :  BaseService
 | |
|     {
 | |
| 
 | |
|         public IRepository<SubjectVisit> _subjectVisitRepository;
 | |
|         private readonly IRepository<Subject> _subjectRepository;
 | |
|         private readonly IRepository<VisitStage> _visitstageRepository;
 | |
|         private readonly IRepository<User> _userRepository;
 | |
|         private readonly IRepository<Trial> _trialRepository;
 | |
|         private readonly IVisitTaskHelpeService _visitTaskHelpeService;
 | |
|         private readonly IRepository<VisitTask> _visitTaskRepository;
 | |
|         private readonly IRepository<ClinicalDataTrialSet> _clinicalDataTrialSetRepository;
 | |
|         private readonly IRepository<ReadModuleView> _readModuleViewRepository;
 | |
|         private readonly IRepository<ReadingQuestionCriterionTrial> _readingQuestionCriterionTrialRepository;
 | |
|         private readonly IRepository<DicomInstance> _dicomInstanceRepository;
 | |
|         private readonly IRepository<NoneDicomStudyFile> _noneDicomStudyFileRepository;
 | |
|         private readonly IRepository<ReadingPeriodSet> _readingPeriodSetRepository;
 | |
|         private readonly IRepository<ReadModule> _readModuleRepository;
 | |
| 
 | |
| 
 | |
|         public ReadModuleService(IRepository<SubjectVisit> subjectVisitRepository,
 | |
|             IRepository<Subject> subjectRepository,
 | |
|             IRepository<VisitStage> visitstageRepository,
 | |
|             IRepository<User> UserRepository,
 | |
|             IRepository<Trial> trialRepository,
 | |
|             IVisitTaskHelpeService visitTaskHelpeService,
 | |
|              IRepository<VisitTask> visitTaskRepository,
 | |
|             IRepository<ClinicalDataTrialSet> clinicalDataTrialSetRepository,
 | |
|             IRepository<ReadModuleView> readModuleViewRepository,
 | |
|             IRepository<ReadingQuestionCriterionTrial> readingQuestionCriterionTrialRepository,
 | |
|             IRepository<DicomInstance> dicomInstanceRepository,
 | |
|             IRepository<NoneDicomStudyFile> noneDicomStudyFileRepository,
 | |
|             IRepository<ReadingPeriodSet> readingPeriodSetRepository,
 | |
|             IRepository<ReadModule> readModuleRepository
 | |
|           )
 | |
|         {
 | |
|             this._subjectVisitRepository = subjectVisitRepository;
 | |
|             this._subjectRepository = subjectRepository;
 | |
|             this._visitstageRepository = visitstageRepository;
 | |
|             this._userRepository = UserRepository;
 | |
|             this._trialRepository = trialRepository;
 | |
|             this._visitTaskHelpeService = visitTaskHelpeService;
 | |
|             this._visitTaskRepository = visitTaskRepository;
 | |
|             this._clinicalDataTrialSetRepository = clinicalDataTrialSetRepository;
 | |
|             this._readModuleViewRepository = readModuleViewRepository;
 | |
|             this._readingQuestionCriterionTrialRepository = readingQuestionCriterionTrialRepository;
 | |
|             this._dicomInstanceRepository = dicomInstanceRepository;
 | |
|             this._noneDicomStudyFileRepository = noneDicomStudyFileRepository;
 | |
|             this._readingPeriodSetRepository = readingPeriodSetRepository;
 | |
|             this._readModuleRepository = readModuleRepository;
 | |
|         }
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取读片模块  //加了标准参数
 | |
|         /// </summary>
 | |
|         [HttpPost]
 | |
|         public async Task<(PageOutput<GetReadModuleDtoOut>,object)> GetReadModuleList(GetReadModuleDto dto)
 | |
|         {
 | |
| 
 | |
|             #region MyRegion
 | |
|             dto.SortField = dto.SortField.IsNullOrEmpty() ? nameof(ReadModuleView.TrialSiteCode) : dto.SortField;
 | |
|             dto.SortField = dto.Asc ? dto.SortField : dto.SortField + " desc";
 | |
|            var subjectQuery = _readModuleViewRepository.Where(x => x.TrialReadingCriterionId == dto.TrialReadingCriterionId)
 | |
|             .WhereIf(dto.TrialId != null, x => x.TrialId == dto.TrialId)
 | |
|             .WhereIf(dto.SubjectId != null, x => x.SubjectId == dto.SubjectId)
 | |
|             .WhereIf(dto.TrialSiteCode != null && dto.TrialSiteCode != string.Empty, x => x.TrialSiteCode == dto.TrialSiteCode)
 | |
|             .WhereIf(dto.SubjectCode != null && dto.SubjectCode != string.Empty, x => x.SubjectCode == dto.SubjectCode)
 | |
|             .WhereIf(dto.ModuleType != null, x => x.ModuleType == dto.ModuleType)
 | |
|             .WhereIf(dto.ReadingStatus != null, x => x.ReadingStatus == dto.ReadingStatus)
 | |
|             .WhereIf(dto.Name != null, x => x.Name.Contains(dto.Name!)).OrderBy(x => x.SiteCode); 
 | |
| 
 | |
|             var subjectIds = await subjectQuery.OrderBy(dto.SortField).Select(x => x.SubjectId).Distinct().Skip((dto.PageIndex - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
 | |
| 
 | |
|             List<ReadModuleView> ReadModuleViewList = await subjectQuery.Where(x => subjectIds.Contains(x.SubjectId)).OrderBy(dto.SortField).ToListAsync();
 | |
|             List<GetReadModuleDtoOut> getReadList = ReadModuleViewList.GroupBy(x => new { x.SubjectId, x.SiteId, x.TrialSiteCode, x.SubjectCode })
 | |
|                 .Select(x => new GetReadModuleDtoOut()
 | |
|                 {
 | |
|                     TrialSiteCode = x.Key.TrialSiteCode,
 | |
|                     SiteId = x.Key.SiteId,
 | |
|                     SubjectCode = x.Key.SubjectCode,
 | |
|                     SubjectId = x.Key.SubjectId,
 | |
|                     Data = x.OrderBy(x=>x.ModuleType).ThenBy(x=>x.VisitNum).ToList(),
 | |
|                 }).ToList();
 | |
|             PageOutput<GetReadModuleDtoOut> pageOutput = new PageOutput<GetReadModuleDtoOut>()
 | |
|             {
 | |
|                 PageSize = dto.PageSize,
 | |
|                 CurrentPageData = getReadList,
 | |
|                 PageIndex = dto.PageIndex,
 | |
|                 TotalCount = await subjectQuery.Select(x => x.SubjectId).Distinct().CountAsync(),
 | |
|             };
 | |
|             var maxcount = 0;
 | |
|             pageOutput.CurrentPageData.ForEach(x =>
 | |
|             {
 | |
|                 maxcount = maxcount < x.Data.Count ? x.Data.Count : maxcount;
 | |
|             });
 | |
| 
 | |
|             var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == dto.TrialReadingCriterionId).Select(x => new
 | |
|             {
 | |
|                 x.IsReadingTaskViewInOrder,
 | |
|                 x.IsOncologyReading,
 | |
|                 x.IsGlobalReading,
 | |
|                 x.IsReadingPeriod,
 | |
|             }).FirstNotNullAsync();
 | |
|           
 | |
|             return (pageOutput, new
 | |
|             {
 | |
|                 MaxLength = maxcount,
 | |
|                 IsReadingTaskViewInOrder= criterionInfo.IsReadingTaskViewInOrder,
 | |
|                 IsClinicalReading = criterionInfo.IsOncologyReading,
 | |
|                // OnlyExistsMedicalHistory = !(await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataSetName != "既往局部治疗史" && x.IsConfirm)),
 | |
|                 IsExistsSubjectClinicalData= await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId&&x.ClinicalDataLevel== ClinicalLevel.Subject && x.IsConfirm),
 | |
|                 IsExistsVisitClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataLevel == ClinicalLevel.SubjectVisit && x.IsConfirm),
 | |
|                 IsExistsReadingClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataLevel == ClinicalLevel.ImageRead && x.IsConfirm),
 | |
|                 IsGlobalReading= criterionInfo.IsGlobalReading,
 | |
|                 IsReadingPeriod=criterionInfo.IsReadingPeriod,
 | |
| 
 | |
|             }) ;
 | |
| 
 | |
|             #endregion
 | |
|         }
 | |
| 
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取单条详情信息   
 | |
|         /// </summary>
 | |
|         /// <param name="dto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<GetReadModuleSingleOutdto> GetReadModule(GetReadModuleSingleIndto dto)
 | |
|         {
 | |
|             var data = await GetReadModuleList(new GetReadModuleDto()
 | |
|             {
 | |
|                 SubjectId = dto.SubjectId,
 | |
|                 TrialId=dto.TrialId,
 | |
|                 TrialReadingCriterionId=dto.TrialReadingCriterionId,
 | |
|             });
 | |
| 
 | |
|             GetReadModuleSingleOutdto? readModule = data.Item1.CurrentPageData.FirstOrDefault().Data.Where(x => x.Id == dto.Id).Select(x => new GetReadModuleSingleOutdto()
 | |
|             {
 | |
|                 Id = x.Id,
 | |
|                 ModuleType = x.ModuleType,
 | |
|                 SubjectVisitId = x.SubjectVisitId,
 | |
|                 SubjectVisitName = x.SubjectVisitName,
 | |
|              
 | |
|                 Status = x.ReadingStatus,
 | |
|             }).FirstOrDefault();
 | |
| 
 | |
| 
 | |
|             var stakeholderIds = new List<Guid>();
 | |
| 
 | |
|             var subjectVisit =await _subjectVisitRepository.FirstOrDefaultAsync(x => x.Id == readModule.SubjectVisitId);
 | |
| 
 | |
|             switch (readModule.Status)
 | |
|             {
 | |
|                 case ReadingStatusEnum.ImageNotSubmit:
 | |
|                     stakeholderIds.AddRange(await _dicomInstanceRepository.Where(x => x.SubjectVisitId == readModule.SubjectVisitId).Select(x => x.CreateUserId).Distinct().ToListAsync());
 | |
|                     stakeholderIds.AddRange(await _noneDicomStudyFileRepository.Where(x => x.NoneDicomStudy.SubjectVisitId == readModule.SubjectVisitId).Select(x => x.CreateUserId).Distinct().ToListAsync());
 | |
|                     break;
 | |
|                 case ReadingStatusEnum.ImageQuality:
 | |
|                     if (subjectVisit.PreliminaryAuditUserId != null)
 | |
|                     {
 | |
|                         stakeholderIds.Add(subjectVisit.PreliminaryAuditUserId.Value);
 | |
|                     }
 | |
|                     if (subjectVisit.ReviewAuditUserId != null)
 | |
|                     {
 | |
|                         stakeholderIds.Add(subjectVisit.ReviewAuditUserId.Value);
 | |
|                     }
 | |
|                     break;
 | |
|                 case ReadingStatusEnum.TaskAllocate:
 | |
|                     if (subjectVisit.CheckUserId != null)
 | |
|                     {
 | |
|                         stakeholderIds.Add(subjectVisit.CheckUserId.Value);
 | |
|                     }
 | |
|                     break;
 | |
|                 case ReadingStatusEnum.ImageReading:
 | |
|                 case ReadingStatusEnum.ReadCompleted:
 | |
| 
 | |
|                     var doctorUserId = await _visitTaskRepository.Where(x => (x.SouceReadModuleId == dto.Id || x.SourceSubjectVisitId == dto.Id)&&x.TaskState==TaskState.Effect)
 | |
|                         .Where(x => x.DoctorUserId != null).Select(x => x.DoctorUserId.Value).ToListAsync();
 | |
| 
 | |
|                     stakeholderIds.AddRange(doctorUserId);
 | |
|                   
 | |
|                     break;
 | |
|             };
 | |
| 
 | |
|             readModule.StakeholderIds = stakeholderIds.Distinct().ToList();
 | |
|             readModule.StakeholderNames = await _userRepository.Where(x => readModule.StakeholderIds.Contains(x.Id)).Select(x => x.FirstName + "/" + x.LastName).ToListAsync();
 | |
| 
 | |
|             return readModule;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 添加阅片的时候 获取访视  //标准参数必传
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         public async Task<List<GetSubjectReadVisitsOutDto>> GetSubjectReadVisitList(GetSubjectReadVisitsInDto inDto)
 | |
|         {
 | |
|             //增加标准
 | |
|             var maxReadVisit = await _readModuleRepository.Where(x => x.SubjectId == inDto.SubjectId && x.ReadingSetType==inDto.ReadingSetType && x.TrialReadingCriterionId==inDto.TrialReadingCriterionId).Include(x=>x.SubjectVisit).OrderByDescending(x=>x.SubjectVisit.VisitNum).FirstOrDefaultAsync();
 | |
| 
 | |
|             var maxReadVisitNum= maxReadVisit==null?-1:maxReadVisit.SubjectVisit.VisitNum;
 | |
|             var visitQuery = _subjectVisitRepository.Where(x => x.SubjectId == inDto.SubjectId && x.LatestScanDate != null && !x.IsLostVisit);
 | |
|             var finalVisitNum = await visitQuery.Where(x => x.IsFinalVisit).Select(x => x.VisitNum).FirstOrDefaultAsync();
 | |
| 
 | |
|             //增加标准
 | |
|             var readModulequery = _readModuleRepository.AsQueryable().Where(x=>x.TrialReadingCriterionId == inDto.TrialReadingCriterionId);
 | |
| 
 | |
|            var resultlist= await visitQuery.WhereIf(finalVisitNum != null&& finalVisitNum!=0, x => x.VisitNum <= finalVisitNum)
 | |
|                 .WhereIf(inDto.ReadingSetType== ReadingSetType.TumorReading, x => readModulequery.Where(y => y.SubjectVisitId == x.Id&&y.TrialReadingCriterionId== inDto.TrialReadingCriterionId && y.ReadingSetType == ReadingSetType.ImageReading).Count() > 0)
 | |
|                 .Where(x=>x.VisitNum> maxReadVisitNum)
 | |
|                 .Where(x=>!x.IsBaseLine) // 排除基线
 | |
|                 .Where(x => readModulequery.Where(y => y.SubjectVisitId == x.Id&& y.TrialReadingCriterionId == inDto.TrialReadingCriterionId && y.ReadingSetType == inDto.ReadingSetType).Count() == 0).OrderBy(x => finalVisitNum)
 | |
|                 .Select(x => new GetSubjectReadVisitsOutDto()
 | |
|                 {
 | |
|                     SubjectVisitId = x.Id,
 | |
|                     VisitName = x.VisitName,
 | |
|                     VisitNum = x.VisitNum,
 | |
|                 }).ToListAsync();
 | |
| 
 | |
|             return resultlist;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 添加阅片期
 | |
|         /// </summary>
 | |
|         /// <param name="dto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<IResponseOutput> AddReadModule(ReadModuleAddDto dto)
 | |
|         {
 | |
| 
 | |
|             
 | |
|             var visitQuery =  _subjectVisitRepository.Where(x => x.SubjectId == dto.SubjectId);
 | |
| 
 | |
|             visitQuery = visitQuery
 | |
|                 //.WhereIf(dto.ExpirationDate != null, x => x.LatestScanDate <= dto.ExpirationDate.Value)
 | |
|                 .WhereIf(dto.ExpirationVisitNum != null, x => x.VisitNum == dto.ExpirationVisitNum!);
 | |
|             var visit = visitQuery.OrderByDescending(x => x.VisitNum).FirstOrDefault();
 | |
| 
 | |
|             var moduleType = dto.ReadingSetType == ReadingSetType.ImageReading ? ModuleTypeEnum.Global : ModuleTypeEnum.Oncology;
 | |
| 
 | |
|             if (visit != null)
 | |
|             {
 | |
| 
 | |
|                 if (await _readModuleRepository.AnyAsync(x => x.SubjectVisitId == visit.Id&&x.ModuleType== moduleType && x.TrialReadingCriterionId == dto.TrialReadingCriterionId))
 | |
|                 {
 | |
|                     throw new BusinessValidationFailedException($"当前访视已经添加过阅片期");
 | |
|                 }
 | |
|                 var readModuleData = new ReadModule()
 | |
|                 {
 | |
|                     Id = NewId.NextGuid(),
 | |
|                     SubjectId = dto.SubjectId,
 | |
|                     ModuleType = moduleType,
 | |
|                     IsUrgent = visit.IsUrgent,
 | |
|                     ModuleName = dto.Name,
 | |
|                     SubjectVisitId = visit.Id,
 | |
|                     ReadingSetType = dto.ReadingSetType,
 | |
|                     TrialId = dto.TrialId,
 | |
|                
 | |
|                     ReadingStatus = ReadingStatusEnum.TaskAllocate,
 | |
| 
 | |
|                     //增加标准
 | |
|                     TrialReadingCriterionId = dto.TrialReadingCriterionId,
 | |
| 
 | |
|                 };
 | |
| 
 | |
|                 await _readModuleRepository.AddAsync(readModuleData);
 | |
| 
 | |
|                 // 判断是否要添加肿瘤学或者全局阅片任务
 | |
|                 switch (readModuleData.ModuleType)
 | |
|                 {
 | |
|                     case ModuleTypeEnum.Global:
 | |
|                         //增加标准
 | |
|                         var taskListInfo = await _visitTaskRepository.Where(x => x.SourceSubjectVisitId == readModuleData.SubjectVisitId&&x.TaskState==TaskState.Effect && x.ReadingTaskState == ReadingTaskState.HaveSigned
 | |
|                         &&!x.IsAnalysisCreate  && x.TrialReadingCriterionId==dto.TrialReadingCriterionId
 | |
|                         
 | |
|                         ).ToListAsync();
 | |
|                         foreach (var taskInfo in taskListInfo)
 | |
|                         {
 | |
|                             await _visitTaskHelpeService.AddTaskAsync(new GenerateTaskCommand()
 | |
|                             {
 | |
|                                 OriginalVisitId = taskInfo.Id,
 | |
|                                 ReadingCategory = GenerateTaskCategory.Global,
 | |
|                                 TrialId = dto.TrialId,
 | |
|                                 ReadingGenerataTaskList = new List<ReadingGenerataTaskDTO>() {
 | |
|                                 new ReadingGenerataTaskDTO()
 | |
|                                  {
 | |
|                                    IsUrgent = readModuleData.IsUrgent ?? false,
 | |
|                                    SubjectId = readModuleData.SubjectId,
 | |
|                                  
 | |
|                                    ReadingName = readModuleData.ModuleName,
 | |
|                                    ReadModuleId =readModuleData.Id,
 | |
|                                    ReadingCategory = ReadingCategory.Global,
 | |
|                                  }
 | |
|                                 }
 | |
|                             });
 | |
|                         }
 | |
|                         break;
 | |
| 
 | |
|                     case ModuleTypeEnum.Oncology:
 | |
| 
 | |
| 
 | |
|                         var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == dto.TrialReadingCriterionId).Select(x => new
 | |
|                         {
 | |
|                             x.ReadingType,
 | |
|                          
 | |
|                         }).FirstNotNullAsync();
 | |
| 
 | |
|                      
 | |
|                         //增加标准
 | |
|                         var globalModule = await _readModuleRepository.Where(x => x.SubjectId == readModuleData.SubjectId && x.SubjectVisitId == readModuleData.SubjectVisitId&& x.ModuleType == ModuleTypeEnum.Global && x.TrialReadingCriterionId == dto.TrialReadingCriterionId).FirstOrDefaultAsync();
 | |
| 
 | |
|                         if (globalModule != null)
 | |
|                         {
 | |
|                             var globalTaskInfoList = await _visitTaskRepository.Where(x => x.SouceReadModuleId == globalModule.Id
 | |
|                             && x.TrialReadingCriterionId == dto.TrialReadingCriterionId
 | |
|                             && x.TaskState == TaskState.Effect && x.ReadingTaskState == ReadingTaskState.HaveSigned&&!x.IsAnalysisCreate).ToListAsync();
 | |
| 
 | |
|                             if (globalTaskInfoList.Count() > 0 && globalTaskInfoList.Count == (int)criterionInfo.ReadingType)
 | |
|                             {
 | |
|                                 var isAdd = false;
 | |
|                                 if (globalTaskInfoList[0].JudgeVisitTaskId == null)
 | |
|                                 {
 | |
|                                     isAdd = true;
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     isAdd = await _visitTaskRepository.AnyAsync(x => x.Id == globalTaskInfoList[0].JudgeVisitTaskId && x.ReadingTaskState == ReadingTaskState.HaveSigned);
 | |
|                                 }
 | |
|                                 if (isAdd)
 | |
|                                 {
 | |
|                                     await _visitTaskHelpeService.AddTaskAsync(new GenerateTaskCommand()
 | |
|                                     {
 | |
|                                         OriginalVisitId = globalTaskInfoList[0].Id,
 | |
|                                         ReadingCategory = GenerateTaskCategory.Oncology,
 | |
|                                         TrialId = dto.TrialId,
 | |
|                                         ReadingGenerataTaskList = new List<ReadingGenerataTaskDTO>() {
 | |
|                                 new ReadingGenerataTaskDTO()
 | |
|                                  {
 | |
|                                    IsUrgent = readModuleData.IsUrgent ?? false,
 | |
|                                    SubjectId = readModuleData.SubjectId,
 | |
|                                    VisitNum=visit.VisitNum,
 | |
|                                    ReadingName = readModuleData.ModuleName,
 | |
|                                    
 | |
|                                    ReadModuleId =readModuleData.Id,
 | |
|                                    ReadingCategory = ReadingCategory.Oncology,
 | |
|                                  }
 | |
|                                 }
 | |
|                                     });
 | |
|                                 }
 | |
|                             }
 | |
| 
 | |
| 
 | |
| 
 | |
|                         }
 | |
|                         else 
 | |
|                         {
 | |
|                             return ResponseOutput.NotOk("请先添加全局阅片");
 | |
|                         }
 | |
|                         break;
 | |
|                 }
 | |
|                 var res = await _readModuleRepository.SaveChangesAsync();
 | |
|                 return ResponseOutput.Ok(res);
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 return ResponseOutput.NotOk("未找到符合要求的访视");
 | |
|             }
 | |
| 
 | |
|           
 | |
| 
 | |
|         }
 | |
| 
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 删除
 | |
|         /// </summary>
 | |
|         /// <param name="readModuleId"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpDelete("{readModuleId:guid}")]
 | |
|         public async Task<IResponseOutput> DeleteReadModule(Guid readModuleId)
 | |
|         {
 | |
| 
 | |
|             var readModule = await _readModuleRepository.Where(x => x.Id == readModuleId).FirstNotNullAsync();
 | |
| 
 | |
| 
 | |
|             if(await _repository.Where<ReadingClinicalData>(t => t.ReadingId == readModuleId).AnyAsync(t => t.ReadingClinicalDataState == ReadingClinicalDataStatus.HaveSigned))
 | |
|             {
 | |
|                 return ResponseOutput.NotOk("临床资料已签名,不允许删除");
 | |
|             }
 | |
| 
 | |
|             //增加标准
 | |
|             if (readModule.ModuleType==ModuleTypeEnum.Global&&(await _readModuleRepository.AnyAsync(x=>x.ModuleType==ModuleTypeEnum.Oncology&&x.SubjectVisitId== readModule.SubjectVisitId && x.TrialReadingCriterionId==readModule.TrialReadingCriterionId)))
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException("当前访视存在肿瘤学阅片,请先删除肿瘤学阅片");
 | |
|             }
 | |
| 
 | |
|             if (await _visitTaskRepository.AnyAsync(x => readModuleId==x.SouceReadModuleId  && x.ReadingTaskState == ReadingTaskState.HaveSigned && x.TaskState == TaskState.Effect))
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException("当前阅片已生成任务并且阅片完成,操作失败。");
 | |
|             }
 | |
| 
 | |
| 
 | |
|             await _visitTaskRepository.BatchUpdateNoTrackingAsync(x => readModuleId==x.SouceReadModuleId, x => new VisitTask()
 | |
|             {
 | |
|                 TaskState = TaskState.Adbandon
 | |
|             });
 | |
| 
 | |
| 
 | |
|             await _readModuleRepository.UpdatePartialFromQueryAsync(t => t.Id == readModuleId, x => new ReadModule()
 | |
|             {
 | |
| 
 | |
|                 IsDeleted = true
 | |
|             });
 | |
|             await _readModuleRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Result(true);
 | |
|         }
 | |
| 
 | |
| 
 | |
|     }
 | |
| }
 |