using IRaCIS.Application.Interfaces; using IRaCIS.Core.Infra.EFCore; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Application.Filter; using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Application.Service.WorkLoad.DTO; using Microsoft.AspNetCore.Authorization; using IRaCIS.Core.Application.Auth; using IRaCIS.Core.Application.Service.Reading.Dto; using MassTransit; using IRaCIS.Core.Application.Service.Reading; using IRaCIS.Core.Infra.EFCore.Common; using Panda.DynamicWebApi.Attributes; using AutoMapper; using IRaCIS.Core.Application.Contracts; namespace IRaCIS.Application.Services { /// /// IR影像阅片 /// [ApiExplorerSettings(GroupName = "Reading")] public class ReadingImageTaskService : BaseService, IReadingImageTaskService { private readonly IMapper mapper; private readonly IRepository _noneDicomStudyRepository; private readonly IRepository _visitTaskRepository; private readonly IRepository _readingTaskQuestionAnswerRepository; private readonly IRepository _readingQuestionCriterionTrialRepository; private readonly IRepository _readingQuestionTrialRepository; public ReadingImageTaskService( IMapper mapper, IRepository noneDicomStudyRepository, IRepository visitTaskRepository, IRepository readingTaskQuestionAnswerRepository, IRepository readingQuestionCriterionTrialRepository, IRepository readingQuestionTrialRepository ) { this.mapper = mapper; this._noneDicomStudyRepository = noneDicomStudyRepository; this._visitTaskRepository = visitTaskRepository; this._readingTaskQuestionAnswerRepository = readingTaskQuestionAnswerRepository; this._readingQuestionCriterionTrialRepository = readingQuestionCriterionTrialRepository; this._readingQuestionTrialRepository = readingQuestionTrialRepository; } ///// ///// 获取阅片非Dicom文件 ///// ///// ///// //[HttpPost] //public async Task> GetReadingImageFile(GetReadingImgInDto inDto) //{ // var subjectVisitId=await _visitTaskRepository.Where(x=>x.Id==inDto.VisitTaskId).Select(x=>x.vi) // List imgList =await _noneDicomStudyRepository.Where(x => x.SubjectVisitId == inDto.SubjectVisitId) // .SelectMany(x => x.NoneDicomFileList).Select(x=> new GetReadingImgOutDto() { // FileName=x.FileName, // Path=x.Path // }).ToListAsync(); // return imgList; //} /// /// 获取项目已确认的标准 /// /// /// [HttpPost] public async Task> GetTrialConfirmCriterionList(GetConfirmCriterionInDto inDto) { var result= await _readingQuestionCriterionTrialRepository.Where(x => x.TrialId == inDto.TrialId&&x.IsConfirm&&x.IsCompleteConfig) .Select(x => new GetTrialConfirmCriterionListOutDto() { ReadingQuestionCriterionTrialId = x.Id, ReadingQuestionCriterionTrialName = x.CriterionName }).ToListAsync(); return result; } /// /// 获取项目的阅片问题 /// /// /// [HttpPost] public async Task> GetTrialReadingQuestion(GetTrialReadingQuestionInDto inDto) { var qusetionList = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == inDto.CriterionId).ToListAsync(); List groupList = _mapper.Map>(qusetionList.Where(x => x.ParentId == null)); groupList.ForEach(x => { FindChildQuestion(x, qusetionList); }); return groupList; } /// /// 找子问题 /// /// /// private void FindChildQuestion(GetTrialReadingQuestionOutDto trialReadingQuestion, List questionlists) { trialReadingQuestion.Childrens = _mapper.Map>(questionlists.Where(x => x.ParentId == trialReadingQuestion.ReadingQuestionTrialId)); if (trialReadingQuestion.Childrens != null && trialReadingQuestion.Childrens.Count != 0) { trialReadingQuestion.Childrens.ForEach(x => { FindChildQuestion(x, questionlists); }); } } /// /// 提交问题 /// /// /// [NonDynamicMethod] public async Task SubmitVisitTaskQuestions(SubmitVisitTaskQuestionsInDto inDto) { var subjectId =await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Select(x => x.SubjectId).FirstOrDefaultAsync(); List readingTaskAnswerList = inDto.AnswerList.Select(x => new ReadingTaskQuestionAnswer() { Id = NewId.NextGuid(), SubjectId = subjectId, Answer = x.Answer, ReadingQuestionCriterionTrialId = inDto.ReadingQuestionCriterionTrialId, ReadingQuestionTrialId = x.ReadingQuestionTrialId, VisitTaskId = inDto.VisitTaskId, TrialId = inDto.TrialId }).ToList(); await _readingTaskQuestionAnswerRepository.AddRangeAsync(readingTaskAnswerList); await _visitTaskRepository.UpdatePartialFromQueryAsync(x => x.Id == inDto.VisitTaskId, x => new VisitTask() { ReadingTaskState = ReadingTaskState.HaveSigned }); var result = await _visitTaskRepository.SaveChangesAsync(); return ResponseOutput.Ok(result); } } }