710 lines
		
	
	
		
			33 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			710 lines
		
	
	
		
			33 KiB
		
	
	
	
		
			C#
		
	
	
| using IRaCIS.Core.Application.Contracts;
 | |
| using IRaCIS.Core.Application.Filter;
 | |
| using IRaCIS.Core.Application.ViewModel;
 | |
| using IRaCIS.Core.Domain.Share;
 | |
| using IRaCIS.Core.Infrastructure;
 | |
| using MassTransit;
 | |
| using Microsoft.AspNetCore.Mvc;
 | |
| using System.Linq.Dynamic.Core;
 | |
| 
 | |
| namespace IRaCIS.Core.Application.Service
 | |
| {
 | |
|     /// <summary>
 | |
|     /// 医学审核问题
 | |
|     /// </summary>	
 | |
|     [ApiExplorerSettings(GroupName = "Reading")]
 | |
|     public class ReadingMedicineQuestionService(IRepository<ReadingMedicineTrialQuestion> _readingMedicineTrialQuestionRepository,
 | |
|         IRepository<ReadingQuestionCriterionTrial> _readingQuestionCriterionTrialRepository,
 | |
|         IRepository<Trial> _trialRepository,
 | |
|         IRepository<ReadingMedicineSystemQuestion> _readingMedicineSystemQuestionRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, IReadingMedicineQuestionService
 | |
|     {
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
|         #region 系统   
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取系统的医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<PageOutput<ReadingMedicineSystemQuestionView>> GetReadingMedicineSystemQuestionList(ReadingMedicineSystemQuestionQuery inDto)
 | |
|         {
 | |
|             //避免前端遍历 
 | |
|             var criterionEnum = inDto.TrialReadingCriterionId != null ? _readingQuestionCriterionTrialRepository.Where(t => t.Id == inDto.TrialReadingCriterionId).Select(t => t.CriterionType).FirstOrDefault() : CriterionType.NoCriterion;
 | |
| 
 | |
|             var query = _readingMedicineSystemQuestionRepository.AsQueryable()
 | |
|                   .WhereIf(!inDto.TypeValue.IsNullOrEmpty(), x => x.TypeValue.Contains(inDto.TypeValue))
 | |
|                   .WhereIf(!inDto.ParentTriggerValue.IsNullOrEmpty(), x => x.ParentTriggerValue.Contains(inDto.ParentTriggerValue))
 | |
|                   .WhereIf(!inDto.QuestionName.IsNullOrEmpty(), x => x.QuestionName.Contains(inDto.QuestionName))
 | |
|                   .WhereIf(!inDto.Type.IsNullOrEmpty(), x => x.Type.Contains(inDto.Type))
 | |
|                   .WhereIf(inDto.ReadingCategory != null, x => x.ReadingCategory == inDto.ReadingCategory)
 | |
|                   .WhereIf(inDto.CurrentCriterionType != null, x => x.CriterionTypeEnum == null || x.CriterionTypeEnum == inDto.CurrentCriterionType)
 | |
|                   .WhereIf(inDto.CriterionTypeEnum != null, x => x.CriterionTypeEnum == inDto.CriterionTypeEnum)
 | |
|                   .WhereIf(inDto.TrialReadingCriterionId != null, x => x.CriterionTypeEnum == criterionEnum || x.IsGeneral == true)
 | |
|                   .WhereIf(inDto.IsGeneral != null, x => x.IsGeneral == inDto.IsGeneral)
 | |
|                 .WhereIf(inDto.LanguageType != null, x => x.LanguageType == inDto.LanguageType!.Value)
 | |
|                   .ProjectTo<ReadingMedicineSystemQuestionView>(_mapper.ConfigurationProvider).OrderBy(x => x.ShowOrder);
 | |
| 
 | |
|             var defalutSortArray = new string[] { nameof(ReadingMedicineSystemQuestionView.LanguageType) + " desc", nameof(ReadingMedicineSystemQuestionView.ShowOrder) };
 | |
| 
 | |
|             return await query.ToPagedListAsync(inDto, defalutSortArray);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取系统的其他医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<List<GetReadingMedicineTrialOtherQuestionOutDto>> GetReadingMedicineSystemOtherQuestion(GetReadingMedicineSystemOtherQuestionInDto inDto)
 | |
|         {
 | |
|             var types = new List<string>()
 | |
|             {
 | |
|                 "select","radio"
 | |
|             };
 | |
| 
 | |
|             var questionList = await _readingMedicineSystemQuestionRepository
 | |
|                 .Where(x => types.Contains(x.Type))
 | |
|                 .WhereIf(inDto.Id != null, x => x.Id != inDto.Id && x.ParentId != inDto.Id)
 | |
|                 .WhereIf(inDto.ShowOrder != null, x => x.ShowOrder < inDto.ShowOrder)
 | |
|                     .WhereIf(inDto.ReadingCategory != null, x => x.ReadingCategory == inDto.ReadingCategory)
 | |
|                 .Select(x => new GetReadingMedicineTrialOtherQuestionOutDto()
 | |
|                 {
 | |
|                     Id = x.Id,
 | |
|                     QuestionName = x.QuestionName,
 | |
|                     LanguageType = x.LanguageType,
 | |
|                     TypeValue = x.TypeValue,
 | |
|                     ReadingCategory = x.ReadingCategory,
 | |
|                 }).ToListAsync();
 | |
| 
 | |
|             return questionList;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 新增或修改系统医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<IResponseOutput> AddOrUpdateReadingMedicineSystemQuestion(ReadingMedicineSystemQuestionAddOrEdit inDto)
 | |
|         {
 | |
|             var existsQuery = _readingMedicineSystemQuestionRepository
 | |
|                .WhereIf(inDto.Id != null, x => x.Id != inDto.Id)
 | |
|                .Where(x => x.ShowOrder == inDto.ShowOrder);
 | |
| 
 | |
|             if (await existsQuery.AnyAsync())
 | |
|             {
 | |
|                 //---当前问题序号存在重复
 | |
|                 return ResponseOutput.NotOk(_localizer["ReadingMed_QNumDup"]);
 | |
|             }
 | |
| 
 | |
|             //inDto.CriterionEnumStr = $"|{String.Join('|', inDto.CriterionEnumList)}|";
 | |
| 
 | |
|             var entity = await _readingMedicineSystemQuestionRepository.InsertOrUpdateAsync(inDto);
 | |
|             await _readingMedicineSystemQuestionRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Ok(entity.Id.ToString());
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 删除系统的医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="id"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpDelete("{id:guid}")]
 | |
|         public async Task<IResponseOutput> DeleteReadingMedicineSystemQuestion(Guid id)
 | |
|         {
 | |
|             if (await _readingMedicineSystemQuestionRepository.AnyAsync(x => x.ParentId == id))
 | |
|             {
 | |
|                 //---此问题存在子问题,请先删除子问题
 | |
|                 return ResponseOutput.NotOk(_localizer["ReadingMed_HasSubQ"]);
 | |
|             }
 | |
|             var success = await _readingMedicineSystemQuestionRepository.DeleteFromQueryAsync(t => t.Id == id);
 | |
|             var result = await _readingMedicineSystemQuestionRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Result(result);
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
| 
 | |
|         #region 项目   
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 清空医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<IResponseOutput> EmptMedicineTrialQuestion(EmptMedicineTrialQuestionInDto inDto)
 | |
|         {
 | |
|             await _readingMedicineTrialQuestionRepository.DeleteFromQueryAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId);
 | |
|             await _readingMedicineTrialQuestionRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Result(true);
 | |
|         }
 | |
| 
 | |
|         /// 获取项目的医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<(PageOutput<ReadingMedicineTrialQuestionView>, object)> GetReadingMedicineTrialQuestionList(ReadingMedicineTrialQuestionQuery inQuery)
 | |
|         {
 | |
|             var query = _readingMedicineTrialQuestionRepository.AsQueryable()
 | |
|                    .Where(x => x.TrialId == inQuery.TrialId && x.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)
 | |
|                    .WhereIf(!inQuery.TypeValue.IsNullOrEmpty(), x => x.TypeValue.Contains(inQuery.TypeValue))
 | |
|                    .WhereIf(!inQuery.ParentTriggerValue.IsNullOrEmpty(), x => x.ParentTriggerValue.Contains(inQuery.ParentTriggerValue))
 | |
|                    .WhereIf(!inQuery.QuestionName.IsNullOrEmpty(), x => x.QuestionName.Contains(inQuery.QuestionName))
 | |
|                    .WhereIf(!inQuery.Type.IsNullOrEmpty(), x => x.Type.Contains(inQuery.Type))
 | |
|                        .WhereIf(inQuery.ReadingCategory != null, x => x.ReadingCategory == inQuery.ReadingCategory)
 | |
|                          .WhereIf(inQuery.LanguageType != null, x => x.LanguageType == inQuery.LanguageType)
 | |
|                    .ProjectTo<ReadingMedicineTrialQuestionView>(_mapper.ConfigurationProvider).OrderByDescending(x => x.LanguageType).ThenBy(x => x.ShowOrder);
 | |
| 
 | |
| 
 | |
|             var isConfirmMedicineQuestion = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inQuery.TrialReadingCriterionId).Select(x => x.IsConfirmMedicineQuestion).FirstOrDefaultAsync();
 | |
|             var questionList = await query.ToPagedListAsync(inQuery);
 | |
|             return (questionList, new
 | |
|             {
 | |
| 
 | |
|                 IsHaveQuestion = (await _readingMedicineTrialQuestionRepository.AsQueryable()
 | |
|                    .Where(x => x.TrialId == inQuery.TrialId && x.TrialReadingCriterionId == inQuery.TrialReadingCriterionId).CountAsync()) > 0,
 | |
| 
 | |
|                 IsConfirmMedicineQuestion = isConfirmMedicineQuestion,
 | |
|                 LanguageType = (await _readingMedicineTrialQuestionRepository.FirstOrDefaultAsync(x => x.TrialReadingCriterionId == inQuery.TrialReadingCriterionId && x.SystemQuestionId != null))?.LanguageType,
 | |
|                 //QuestionCount = questionList.Count(),
 | |
|             });
 | |
|         }
 | |
| 
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取项目的其他医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<List<GetReadingMedicineTrialOtherQuestionOutDto>> GetReadingMedicineTrialOtherQuestion(GetReadingMedicineTrialOtherQuestionInDto inDto)
 | |
|         {
 | |
|             var types = new List<string>()
 | |
|             {
 | |
|                 "select","radio"
 | |
|             };
 | |
| 
 | |
|             var questionList = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId)
 | |
|                 .Where(x => types.Contains(x.Type))
 | |
|                 .WhereIf(inDto.Id != null, x => x.Id != inDto.Id && x.ParentId != inDto.Id)
 | |
|                 .WhereIf(inDto.ShowOrder != null, x => x.ShowOrder < inDto.ShowOrder)
 | |
|                     .WhereIf(inDto.ReadingCategory != null, x => x.ReadingCategory == inDto.ReadingCategory)
 | |
|                 .Select(x => new GetReadingMedicineTrialOtherQuestionOutDto()
 | |
|                 {
 | |
|                     Id = x.Id,
 | |
|                     QuestionName = x.QuestionName,
 | |
|                     LanguageType = x.LanguageType,
 | |
|                     TypeValue = x.TypeValue,
 | |
|                     ReadingCategory = x.ReadingCategory,
 | |
|                 }).ToListAsync();
 | |
| 
 | |
|             return questionList;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// <summary>
 | |
|         /// 获取预览问题信息
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<List<GetMedicineQuestionPreviewOutDto>> GetMedicineQuestionPreview(GetMedicineQuestionPreviewInDto inDto)
 | |
|         {
 | |
|             var trialQuestionList = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId)
 | |
|                     .WhereIf(inDto.ReadingCategory != null, x => x.ReadingCategory == inDto.ReadingCategory)
 | |
| 
 | |
|                       .ProjectTo<GetMedicineQuestionPreviewOutDto>(_mapper.ConfigurationProvider, new
 | |
|                       {
 | |
|                           isEn_Us = _userInfo.IsEn_Us
 | |
| 
 | |
|                       })
 | |
|                       .OrderBy(x => x.ShowOrder).ToListAsync();
 | |
| 
 | |
|             List<GetMedicineQuestionPreviewOutDto> readingQuestionList = trialQuestionList.Where(x => x.ParentId == null).ToList();
 | |
|             readingQuestionList.ForEach(x =>
 | |
|             {
 | |
|                 FindChildQuestion(x, trialQuestionList);
 | |
|             });
 | |
| 
 | |
|             return readingQuestionList;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 新增或修改项目医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         [TrialGlobalLimit("AfterStopCannNotOpt")]
 | |
|         public async Task<IResponseOutput> AddOrUpdateReadingMedicineTrialQuestion(ReadingMedicineTrialQuestionAddOrEdit inDto)
 | |
|         {
 | |
|             var existsQuery = _readingMedicineTrialQuestionRepository
 | |
|            .WhereIf(inDto.Id != null, x => x.Id != inDto.Id)
 | |
|            .Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId)
 | |
|            .Where(x => x.ShowOrder == inDto.ShowOrder);
 | |
| 
 | |
|             if (await existsQuery.AnyAsync())
 | |
|             {
 | |
|                 //---当前问题序号存在重复
 | |
|                 return ResponseOutput.NotOk(_localizer["ReadingMed_QNumDup"]);
 | |
|             }
 | |
|             var entity = await _readingMedicineTrialQuestionRepository.InsertOrUpdateAsync(inDto);
 | |
|             await _readingMedicineTrialQuestionRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Ok(entity.Id.ToString());
 | |
| 
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 删除项目的医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         [TrialGlobalLimit( "AfterStopCannNotOpt" )]
 | |
|         public async Task<IResponseOutput> DeleteReadingMedicineTrialQuestion(DeleteReadingMedicineTrialQuestion inDto)
 | |
|         {
 | |
|             if (await _readingMedicineTrialQuestionRepository.AnyAsync(x => x.ParentId == inDto.Id))
 | |
|             {
 | |
|                 //---此问题存在子问题,请先删除子问题
 | |
|                 return ResponseOutput.NotOk(_localizer["ReadingMed_HasSubQ"]);
 | |
|             }
 | |
|             var success = await _readingMedicineTrialQuestionRepository.DeleteFromQueryAsync(t => t.Id == inDto.Id);
 | |
|             var result = await _readingMedicineTrialQuestionRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Result(result);
 | |
|         }
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
| 
 | |
| 
 | |
|         #region 项目 医学审核问题  验证  确认  
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 验证医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         /// <exception cref="BusinessValidationFailedException"></exception>
 | |
|         public async Task<IResponseOutput> VerifyReadingMedicineQuestion(ConfirmReadingMedicineQuestionInDto inDto)
 | |
|         {
 | |
|             var readingMedicineQuestionList = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId)
 | |
|                 .Select(x => new TrialQuestion()
 | |
|                 {
 | |
|                     Id = x.Id,
 | |
|                     ReadingCategory = x.ReadingCategory,
 | |
|                     ParentShowOrder = (int?)x.ParentQuestion.ShowOrder,
 | |
|                     ShowOrder = x.ShowOrder,
 | |
|                 }).ToListAsync();
 | |
|             if (readingMedicineQuestionList.Count == 0)
 | |
|             {
 | |
|                 //---当前未添加医学审核问题。请先添加医学审核问题,再进行确认。
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_NoMedQ"]);
 | |
|             }
 | |
| 
 | |
|             if (readingMedicineQuestionList.Count != readingMedicineQuestionList.Select(t => t.ShowOrder).Distinct().Count())
 | |
|             {
 | |
|                 //---影像医学审核问题显示序号不能重复。
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_MedQNumDup"]);
 | |
|             }
 | |
| 
 | |
| 
 | |
|             if (readingMedicineQuestionList.Where(t => t.ParentShowOrder != null).Any(t => t.ParentShowOrder > t.ShowOrder))
 | |
|             {
 | |
|                 //---父问题的显示序号要比子问题的显示序号小,请确认。
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_ParentNumSmall"]);
 | |
|             }
 | |
| 
 | |
|             var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.TrialReadingCriterionId).Select(x => new
 | |
|             {
 | |
|                 x.IsGlobalReading,
 | |
|                 x.IsOncologyReading,
 | |
|                 x.IsArbitrationReading,
 | |
|             }).FirstNotNullAsync();
 | |
| 
 | |
| 
 | |
| 
 | |
|             if (!readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Visit))
 | |
|             {
 | |
| 
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_VisitQNotConfig"]);
 | |
|             }
 | |
| 
 | |
|             if (criterionInfo.IsGlobalReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Global))
 | |
|             {
 | |
|                 //---当前标准启用了全局阅片,但未配置全局医学审核问题
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_GlobalQNotConfig"]);
 | |
|             }
 | |
| 
 | |
|             if (criterionInfo.IsArbitrationReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Judge))
 | |
|             {
 | |
|                 //---当前标准启用了仲裁阅片,但未配置仲裁医学审核问题
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_ArbitrateQNotConfig"]);
 | |
|             }
 | |
| 
 | |
|             if (criterionInfo.IsOncologyReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Oncology))
 | |
|             {
 | |
|                 //---当前标准启用了肿瘤学阅片,但未配置肿瘤学医学审核问题
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_TumorQNotConfig"]);
 | |
|             }
 | |
| 
 | |
|             return ResponseOutput.Ok();
 | |
| 
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 确认医学审核问题
 | |
|         /// </summary>
 | |
|         /// <returns></returns>
 | |
|         public async Task<IResponseOutput> ConfirmReadingMedicineQuestion(ConfirmReadingMedicineQuestionInDto inDto)
 | |
|         {
 | |
| 
 | |
|             var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.TrialReadingCriterionId).Select(x => new
 | |
|             {
 | |
|                 x.IsGlobalReading,
 | |
|                 x.IsOncologyReading,
 | |
|                 x.IsArbitrationReading,
 | |
|             }).FirstNotNullAsync();
 | |
|             var readingMedicineQuestionList = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId)
 | |
|                 .Select(x => new TrialQuestion()
 | |
|                 {
 | |
|                     Id = x.Id,
 | |
|                     ReadingCategory = x.ReadingCategory,
 | |
|                     ParentShowOrder = (int?)x.ParentQuestion.ShowOrder,
 | |
|                     ShowOrder = x.ShowOrder,
 | |
|                 }).ToListAsync();
 | |
|             if (readingMedicineQuestionList.Count == 0)
 | |
|             {
 | |
|                 //---当前未添加医学审核问题。请先添加医学审核问题,再进行确认。
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_NoMedQ"]);
 | |
|             }
 | |
| 
 | |
|             if (readingMedicineQuestionList.Count != readingMedicineQuestionList.Select(t => t.ShowOrder).Distinct().Count())
 | |
|             {
 | |
|                 //---影像医学审核问题显示序号不能重复。
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_MedQNumDup"]);
 | |
|             }
 | |
| 
 | |
| 
 | |
|             if (readingMedicineQuestionList.Where(t => t.ParentShowOrder != null).Any(t => t.ParentShowOrder > t.ShowOrder))
 | |
|             {
 | |
|                 //---父问题的显示序号要比子问题的显示序号小,请确认。
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_ParentNumSmall"]);
 | |
|             }
 | |
| 
 | |
| 
 | |
|             var trialInfo = await _trialRepository.Where(x => x.Id == inDto.TrialId).FirstNotNullAsync();
 | |
| 
 | |
|             if (criterionInfo.IsGlobalReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Global))
 | |
|             {
 | |
|                 //---当前标准启用了全局阅片,但未配置全局医学审核问题
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_GlobalQNotConfig"]);
 | |
|             }
 | |
| 
 | |
|             if (criterionInfo.IsArbitrationReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Judge))
 | |
|             {
 | |
|                 //---当前标准启用了仲裁阅片,但未配置仲裁医学审核问题
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_ArbitrateQNotConfig"]);
 | |
|             }
 | |
| 
 | |
|             if (criterionInfo.IsOncologyReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Oncology))
 | |
|             {
 | |
|                 //---当前标准启用了肿瘤学阅片,但未配置肿瘤学医学审核问题
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_TumorQNotConfig"]);
 | |
|             }
 | |
| 
 | |
| 
 | |
|             await _readingMedicineTrialQuestionRepository.BatchUpdateNoTrackingAsync(x => x.TrialId == inDto.TrialId, x => new ReadingMedicineTrialQuestion()
 | |
|             {
 | |
|                 IsConfirm = true
 | |
|             });
 | |
| 
 | |
|             await _readingQuestionCriterionTrialRepository.UpdatePartialFromQueryAsync(inDto.TrialReadingCriterionId, x => new ReadingQuestionCriterionTrial()
 | |
|             {
 | |
|                 IsConfirmMedicineQuestion = true
 | |
|             });
 | |
| 
 | |
|             var result = await _trialRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Result(result);
 | |
| 
 | |
| 
 | |
| 
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
| 
 | |
| 
 | |
|         private void FindChildQuestion(GetMedicineQuestionPreviewOutDto trialReadingQuestion, List<GetMedicineQuestionPreviewOutDto> questionlists)
 | |
|         {
 | |
|             trialReadingQuestion.Childrens = questionlists.Where(x => x.ParentId == trialReadingQuestion.Id).ToList();
 | |
|             if (trialReadingQuestion.Childrens != null && trialReadingQuestion.Childrens.Count != 0)
 | |
|             {
 | |
|                 trialReadingQuestion.Childrens.ForEach(x =>
 | |
|                 {
 | |
|                     this.FindChildQuestion(x, questionlists);
 | |
|                 });
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 批量删除项目标准医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<IResponseOutput> BatchDeteteCriterionMedicineQuestion(BatchDeteteCriterionMedicineQuestionInDto inDto)
 | |
|         {
 | |
| 
 | |
|             var questionlist = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId).ToListAsync();
 | |
| 
 | |
|             var count = inDto.Ids.Count;
 | |
|             var childids = inDto.Ids.Clone();
 | |
|             while (count > 0)
 | |
|             {
 | |
|                 childids = questionlist.Where(x => childids.Contains(x.ParentId ?? default(Guid))).Select(x => x.Id).ToList();
 | |
|                 inDto.Ids.AddRange(childids);
 | |
|                 count = childids.Count;
 | |
| 
 | |
|             }
 | |
| 
 | |
|             await _readingMedicineTrialQuestionRepository.BatchDeleteNoTrackingAsync(x => inDto.Ids.Contains(x.Id));
 | |
|             //var result=	await _readingMedicineTrialQuestionRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Result(true);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 一键添加默认医学审核问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<IResponseOutput> AddDefaultQuestions(AddDefaultQuestionsInDto inDto)
 | |
|         {
 | |
|             //if (await _readingMedicineTrialQuestionRepository.AnyAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId && x.LanguageType == inDto.LanguageType && x.SystemQuestionId != null))
 | |
|             //{
 | |
|             //	await _readingMedicineTrialQuestionRepository.BatchDeleteNoTrackingAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId && x.LanguageType == inDto.LanguageType && x.SystemQuestionId != null);
 | |
|             //}
 | |
|             //else
 | |
|             //{
 | |
|             //	await _readingMedicineTrialQuestionRepository.BatchDeleteNoTrackingAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId && x.LanguageType != inDto.LanguageType);
 | |
|             //}
 | |
| 
 | |
|             await _readingMedicineTrialQuestionRepository.BatchDeleteNoTrackingAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId);
 | |
|             var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.TrialReadingCriterionId).FirstNotNullAsync();
 | |
|             List<ReadingCategory> needAddCategory = new List<ReadingCategory>() { ReadingCategory.Visit };
 | |
|             if (criterionInfo.IsGlobalReading)
 | |
|             {
 | |
|                 needAddCategory.Add(ReadingCategory.Global);
 | |
|             }
 | |
|             if (criterionInfo.IsArbitrationReading)
 | |
|             {
 | |
|                 needAddCategory.Add(ReadingCategory.Judge);
 | |
|             }
 | |
|             if (criterionInfo.IsOncologyReading)
 | |
|             {
 | |
|                 needAddCategory.Add(ReadingCategory.Oncology);
 | |
|             }
 | |
| 
 | |
|             var maxOrder = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId).OrderByDescending(x => x.ShowOrder).Select(x => x.ShowOrder).FirstOrDefaultAsync();
 | |
|             List<TrialDataFromSystem> needList = await _readingMedicineSystemQuestionRepository
 | |
|                 .Where(x => x.IsEnable)
 | |
|                 .Where(x => x.LanguageType == inDto.LanguageType)
 | |
|                 .Where(x => needAddCategory.Contains(x.ReadingCategory) && x.CriterionTypeEnum == criterionInfo.CriterionType)
 | |
|                 .Select(x => new TrialDataFromSystem()
 | |
|                 {
 | |
| 
 | |
|                     ShowOrder = x.ShowOrder,
 | |
|                     IsEnable = x.IsEnable,
 | |
|                     LanguageType = x.LanguageType,
 | |
|                     IsRequired = x.IsRequired,
 | |
|                     QuestionName = x.QuestionName,
 | |
|                     TrialReadingCriterionId = inDto.TrialReadingCriterionId,
 | |
|                     Type = x.Type,
 | |
|                     ParentId = x.ParentId,
 | |
|                     SystemQuestionId = x.Id,
 | |
|                     ReadingCategory = x.ReadingCategory,
 | |
|                     TypeValue = x.TypeValue,
 | |
|                     TrialId = inDto.TrialId,
 | |
|                 }).ToListAsync();
 | |
| 
 | |
|             foreach (var item in needAddCategory.Where(x => x != ReadingCategory.Visit).ToList())
 | |
|             {
 | |
|                 if (!needList.Any(x => x.ReadingCategory == item))
 | |
|                 {
 | |
|                     needList.AddRange(await _readingMedicineSystemQuestionRepository
 | |
|                 .Where(x => x.IsEnable)
 | |
|                 .Where(x => x.LanguageType == inDto.LanguageType)
 | |
|                 .Where(x => x.ReadingCategory == item && x.IsGeneral)
 | |
|                 .Select(x => new TrialDataFromSystem()
 | |
|                 {
 | |
| 
 | |
|                     ShowOrder = x.ShowOrder,
 | |
|                     IsEnable = x.IsEnable,
 | |
| 
 | |
|                     LanguageType = x.LanguageType,
 | |
|                     IsRequired = x.IsRequired,
 | |
|                     QuestionName = x.QuestionName,
 | |
|                     TrialReadingCriterionId = inDto.TrialReadingCriterionId,
 | |
|                     Type = x.Type,
 | |
|                     ParentId = x.ParentId,
 | |
|                     SystemQuestionId = x.Id,
 | |
|                     ReadingCategory = x.ReadingCategory,
 | |
|                     TypeValue = x.TypeValue,
 | |
|                     TrialId = inDto.TrialId,
 | |
|                 }).ToListAsync());
 | |
|                 }
 | |
|             }
 | |
| 
 | |
| 
 | |
|             needList.ForEach(x =>
 | |
|             {
 | |
|                 x.Id = NewId.NextGuid();
 | |
|                 maxOrder++;
 | |
|                 x.ShowOrder = maxOrder;
 | |
|             });
 | |
| 
 | |
|             foreach (var item in needList.Where(x => x.ParentId != null))
 | |
|             {
 | |
|                 var parent = needList.Where(x => x.SystemQuestionId == item.ParentId).FirstOrDefault();
 | |
|                 if (parent == null)
 | |
|                 {
 | |
|                     item.ParentId = null;
 | |
|                     item.ParentTriggerValue = String.Empty;
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     item.ParentId = parent.Id;
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             await _readingMedicineTrialQuestionRepository.AddRangeAsync(_mapper.Map<List<ReadingMedicineTrialQuestion>>(needList));
 | |
|             var result = await _readingMedicineTrialQuestionRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Result(result);
 | |
| 
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 验证医学审核问题是否可确认
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         /// <exception cref="BusinessValidationFailedException"></exception>
 | |
|         [HttpPost]
 | |
|         public async Task VerifyIsCanConfirm(VerifyIsCanConfirmInDto inDto)
 | |
|         {
 | |
|             var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.TrialReadingCriterionId).FirstNotNullAsync();
 | |
| 
 | |
|             if (!criterionInfo.IsSigned)
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_NoConfirmed"]);
 | |
|             }
 | |
|             if (!(await _readingMedicineTrialQuestionRepository.AnyAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId && x.ReadingCategory == ReadingCategory.Visit)))
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_NoVisitQ"]);
 | |
|             }
 | |
|             if (criterionInfo.IsGlobalReading && !(await _readingMedicineTrialQuestionRepository.AnyAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId && x.ReadingCategory == ReadingCategory.Global)))
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_NoGlobalQ"]);
 | |
|             }
 | |
|             if (criterionInfo.IsArbitrationReading && !(await _readingMedicineTrialQuestionRepository.AnyAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId && x.ReadingCategory == ReadingCategory.Judge)))
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_NoJudgeQ"]);
 | |
|             }
 | |
|             if (criterionInfo.IsOncologyReading && !(await _readingMedicineTrialQuestionRepository.AnyAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId && x.ReadingCategory == ReadingCategory.Oncology)))
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_NoOncologyQ"]);
 | |
|             }
 | |
|             if (!criterionInfo.IsGlobalReading && (await _readingMedicineTrialQuestionRepository.AnyAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId && x.ReadingCategory == ReadingCategory.Global)))
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_HaveGlobalQ"]);
 | |
|             }
 | |
|             if (!criterionInfo.IsArbitrationReading && (await _readingMedicineTrialQuestionRepository.AnyAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId && x.ReadingCategory == ReadingCategory.Judge)))
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_HaveJudgeQ"]);
 | |
|             }
 | |
|             if (!criterionInfo.IsOncologyReading && (await _readingMedicineTrialQuestionRepository.AnyAsync(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId && x.ReadingCategory == ReadingCategory.Oncology)))
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException(_localizer["ReadingMed_HaveOncologyQ"]);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 从系统里面选择问题添加到项目里面
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<IResponseOutput> AddTrialDataFromSystem(AddTrialDataFromSystemInDto inDto)
 | |
|         {
 | |
|             // 直接写??
 | |
|             var systemList = await _readingMedicineSystemQuestionRepository.Where(x => inDto.SystemQuestionIds.Contains(x.Id)).ToListAsync();
 | |
| 
 | |
|             var maxOrder = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId).OrderByDescending(x => x.ShowOrder).Select(x => x.ShowOrder).FirstOrDefaultAsync();
 | |
| 
 | |
| 
 | |
|             var needList = systemList.Select(x => new TrialDataFromSystem()
 | |
|             {
 | |
|                 Id = NewId.NextGuid(),
 | |
|                 ShowOrder = x.ShowOrder,
 | |
|                 IsEnable = x.IsEnable,
 | |
|                 LanguageType = x.LanguageType,
 | |
|                 IsRequired = x.IsRequired,
 | |
|                 QuestionName = x.QuestionName,
 | |
|                 TrialReadingCriterionId = inDto.TrialReadingCriterionId,
 | |
|                 Type = x.Type,
 | |
|                 ParentId = x.ParentId,
 | |
|                 SystemQuestionId = x.Id,
 | |
|                 ReadingCategory = x.ReadingCategory,
 | |
|                 TypeValue = x.TypeValue,
 | |
|                 TrialId = inDto.TrialId,
 | |
|             }).ToList();
 | |
| 
 | |
|             needList.ForEach(x =>
 | |
|             {
 | |
|                 maxOrder++;
 | |
|                 x.ShowOrder = maxOrder;
 | |
|             });
 | |
| 
 | |
|             foreach (var item in needList.Where(x => x.ParentId != null))
 | |
|             {
 | |
|                 var parent = needList.Where(x => x.SystemQuestionId == item.ParentId).FirstOrDefault();
 | |
|                 if (parent == null)
 | |
|                 {
 | |
|                     item.ParentId = null;
 | |
|                     item.ParentTriggerValue = String.Empty;
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     item.ParentId = parent.Id;
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             await _readingMedicineTrialQuestionRepository.AddRangeAsync(_mapper.Map<List<ReadingMedicineTrialQuestion>>(needList));
 | |
|             var result = await _readingMedicineTrialQuestionRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Result(result);
 | |
|         }
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
|     }
 | |
| }
 |