//-------------------------------------------------------------------- // 此代码由liquid模板自动生成 byzhouhang 20240909 // 生成时间 2026-03-10 06:17:28Z // 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。 //-------------------------------------------------------------------- using IRaCIS.Core.Domain.Models; using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Infrastructure.Extention; using System.Threading.Tasks; using IRaCIS.Core.Infra.EFCore; using Microsoft.Extensions.Logging; namespace IRaCIS.Core.Application.Service; /// /// 分割 /// /// /// /// /// [ ApiExplorerSettings(GroupName = "Reading")] public class SegmentationService(IRepository _segmentationRepository, IRepository _segmentBindingRepository, IRepository _readingTaskQuestionAnswerRepository, IRepository _visitTaskRepository, IRepository _readingTableAnswerRowInfoRepository, IRepository _readingTableQuestionAnswerRepository, IRepository _segmentRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService, ISegmentationService { /// /// 获取分割组 /// /// /// [HttpPost] public async Task> GetSegmentationList(SegmentationQuery inQuery) { var segmentationQueryable =_segmentationRepository .WhereIf(inQuery.SegmentationName.IsNotNullOrEmpty(),x=>x.SegmentationName.Contains(inQuery.SegmentationName)) .WhereIf(inQuery.TrialId != null, x => x.TrialId == inQuery.TrialId) .WhereIf(inQuery.SeriesId != null, x => x.SeriesId == inQuery.SeriesId) .WhereIf(inQuery.StudyId != null, x => x.StudyId == inQuery.StudyId) .WhereIf(inQuery.SubjectId != null, x => x.SubjectId == inQuery.SubjectId) .WhereIf(inQuery.SubjectVisitId != null, x => x.SubjectVisitId == inQuery.SubjectVisitId) .WhereIf(inQuery.VisitTaskId != null, x => x.VisitTaskId == inQuery.VisitTaskId) .ProjectTo(_mapper.ConfigurationProvider); var pageList= await segmentationQueryable.ToPagedListAsync(inQuery); return pageList; } /// /// 新增修改分割组 /// /// /// [HttpPost] public async Task AddOrUpdateSegmentation(SegmentationAddOrEdit addOrEditSegmentation) { var entity = await _segmentationRepository.InsertOrUpdateAsync(addOrEditSegmentation, true); return ResponseOutput.Ok(entity.Id.ToString()); } /// /// 删除分割组 /// /// /// [HttpDelete("{segmentationId:guid}")] public async Task DeleteSegmentation(Guid segmentationId) { var success = await _segmentationRepository.DeleteFromQueryAsync(t => t.Id == segmentationId,true); return ResponseOutput.Ok(); } /// /// 获取分割 /// /// /// [HttpPost] public async Task> GetSegmentList(SegmentQuery inQuery) { var segmentQueryable = _segmentRepository .WhereIf(inQuery.SegmentationId != null, x => x.SegmentationId == inQuery.SegmentationId) .WhereIf(inQuery.SegmentName.IsNotNullOrEmpty(), x => x.SegmentName.Contains(inQuery.SegmentName)) .WhereIf(inQuery.VisitTaskId != null, x => x.VisitTaskId == inQuery.VisitTaskId) .ProjectTo(_mapper.ConfigurationProvider); var pageList = await segmentQueryable.ToPagedListAsync(inQuery); return pageList; } /// /// 新增修改分割 /// /// /// [HttpPost] public async Task AddOrUpdateSegment(SegmentAddOrEdit addOrEditSegment) { var entity = await _segmentRepository.InsertOrUpdateAsync(addOrEditSegment, true); return ResponseOutput.Ok(entity.Id.ToString()); } /// /// 删除分割 /// /// /// [HttpDelete("{segmentId:guid}")] public async Task DeleteSegment(Guid segmentId) { var success = await _segmentRepository.DeleteFromQueryAsync(t => t.Id == segmentId, true); return ResponseOutput.Ok(); } /// /// 获取分割绑定 /// /// /// [HttpPost] public async Task> GetSegmentBindingList(SegmentBindingQuery inQuery) { var segmentBindingQueryable = _segmentBindingRepository .WhereIf(inQuery.QuestionId != null, x => x.QuestionId == inQuery.QuestionId) .WhereIf(inQuery.RowId != null, x => x.RowId == inQuery.RowId) .WhereIf(inQuery.SegmentId != null, x => x.SegmentId == inQuery.SegmentId) .WhereIf(inQuery.SegmentationId != null, x => x.SegmentationId == inQuery.SegmentationId) .WhereIf(inQuery.TableQuestionId != null, x => x.TableQuestionId == inQuery.TableQuestionId) .WhereIf(inQuery.VisitTaskId != null, x => x.VisitTaskId == inQuery.VisitTaskId) .ProjectTo(_mapper.ConfigurationProvider); var pageList = await segmentBindingQueryable.ToPagedListAsync(inQuery); return pageList; } /// /// 新增修改分割绑定 /// /// /// public async Task AddOrUpdateSegmentBinding(SegmentBindingAddOrEdit addOrEditSegmentBinding) { var entity = await _segmentBindingRepository.InsertOrUpdateAsync(addOrEditSegmentBinding, true); return ResponseOutput.Ok(entity.Id.ToString()); } /// /// 删除分割 /// /// /// [HttpDelete("{segmentBindingId:guid}")] public async Task DeleteSegmentBinding(Guid segmentBindingId) { var success = await _segmentBindingRepository.DeleteFromQueryAsync(t => t.Id == segmentBindingId, true); return ResponseOutput.Ok(); } /// /// 保存分割绑定和答案 /// /// /// public async Task SaveSegmentBindingAndAnswer(SaveSegmentBindingAndAnswerInDto inDto) { var taskinfo = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId) .FirstNotNullAsync(); foreach (var item in inDto.BindingList) { // 处理绑定关系 var binding = await _segmentBindingRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.QuestionId == item.QuestionId && x.RowId == item.RowId && x.TableQuestionId == item.TableQuestionId) .FirstOrDefaultAsync(); if (binding == null) { if (item.SegmentationId != null && item.SegmentId != null) { await _segmentBindingRepository.InsertFromDTOAsync(new SegmentBinding { VisitTaskId = inDto.VisitTaskId, QuestionId = item.QuestionId, RowId = item.RowId, TableQuestionId = item.TableQuestionId, SegmentId = item.SegmentId.Value, SegmentationId = item.SegmentationId.Value, }); } } else { if (item.SegmentationId != null && item.SegmentId != null) { await _segmentBindingRepository.UpdatePartialFromQueryAsync(x => x.Id == binding.Id, t => new SegmentBinding { SegmentId = item.SegmentId.Value, SegmentationId = item.SegmentationId.Value, }); } else { await _segmentBindingRepository.DeleteFromQueryAsync(x => x.Id == binding.Id); } } // 处理问题 if (item.RowId != null && item.TableQuestionId != null) { var answer = await _readingTableQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId && x.RowId == item.VisitTaskId && x.TableQuestionId == item.TableQuestionId) .FirstOrDefaultAsync(); var rowinfo= await _readingTableAnswerRowInfoRepository.Where(x => x.Id==item.RowId) .Include(x=>x.VisitTask) .FirstNotNullAsync(); if (answer != null) { await _readingTableQuestionAnswerRepository.UpdatePartialFromQueryAsync(x => x.Id == answer.Id, t => new ReadingTableQuestionAnswer { Answer = item.Answer }); } else { await _readingTableQuestionAnswerRepository.InsertFromDTOAsync(new ReadingTableQuestionAnswer { VisitTaskId = inDto.VisitTaskId, RowId = item.RowId.Value, TableQuestionId = item.TableQuestionId.Value, Answer = item.Answer, TrialId= rowinfo.VisitTask.TrialId, RowIndex= rowinfo.RowIndex, }); } } else { var answer = await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId &&x.ReadingQuestionTrialId==item.QuestionId) .FirstOrDefaultAsync(); if (answer != null) { await _readingTaskQuestionAnswerRepository.UpdatePartialFromQueryAsync(x => x.Id == answer.Id, t => new ReadingTaskQuestionAnswer { Answer = item.Answer }); } else { await _readingTaskQuestionAnswerRepository.InsertFromDTOAsync(new ReadingTaskQuestionAnswer { ReadingQuestionTrialId= item.QuestionId.Value, ReadingQuestionCriterionTrialId=taskinfo.TrialReadingCriterionId, TrialId= taskinfo.TrialId, SubjectId= taskinfo.SubjectId, VisitTaskId = inDto.VisitTaskId, Answer=item.Answer, }); } } } await _segmentationRepository.SaveChangesAsync(); return ResponseOutput.Ok(); } }