diff --git a/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs b/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs index 384008e24..52d3f7a1f 100644 --- a/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs @@ -11,6 +11,8 @@ using IRaCIS.Core.Application.Service.Reading.Dto; using IRaCIS.Core.Infra.EFCore.Common; using IRaCIS.Core.Domain.Share; using MassTransit; +using IRaCIS.Core.Infrastructure; +using IRaCIS.Core.Domain.Models; namespace IRaCIS.Core.Application.Service { @@ -38,6 +40,8 @@ namespace IRaCIS.Core.Application.Service private readonly IRepository _clinicalTableAnswerRepository; + private readonly IRepository _clinicalAnswerRowInfoRepository; + private readonly IClinicalQuestionService _iClinicalQuestionService; @@ -48,10 +52,12 @@ namespace IRaCIS.Core.Application.Service IRepository clinicalTableAnswerRepository, IRepository clinicalQuestionAnswerRepository, IClinicalQuestionService iClinicalQuestionService, - IRepository clinicalDataTrialSetRepository, + IRepository clinicalAnswerRowInfoRepository, + IRepository clinicalDataTrialSetRepository, IRepository systemClinicalQuestionRepository ) { + _clinicalAnswerRowInfoRepository = clinicalAnswerRowInfoRepository; _clinicalQuestionAnswerRepository = clinicalQuestionAnswerRepository; _systemClinicalTableQuestionRepository = systemClinicalTableQuestionRepository; _trialClinicalQuestionRepository = trialClinicalQuestionRepository; @@ -130,6 +136,7 @@ namespace IRaCIS.Core.Application.Service /// /// /// + [HttpPost] public async Task GetClinicalFormInfo(GetClinicalFormInfoInDto inDto) { var formInfo = await _clinicalFormRepository.Where(x => x.Id == inDto.ClinicalFormId).FirstNotNullAsync(); @@ -176,9 +183,90 @@ namespace IRaCIS.Core.Application.Service /// /// /// - public async Task SubmitClinicalForm(SubmitClinicalFormInDto inDto) + [HttpPost] + public async Task SubmitClinicalForm(SubmitClinicalFormInDto inDto) { - + + var checkDateQuestionId = await _trialClinicalQuestionRepository.Where(x => x.TrialClinicalId == inDto.ClinicalDataTrialSetId && x.IsCheckDate).Select(x => x.Id).FirstNotNullAsync(); + ClinicalForm clinicalForm = new ClinicalForm() { }; + try + { + clinicalForm = new ClinicalForm() + { + ClinicalDataTrialSetId = inDto.ClinicalDataTrialSetId, + SubjectId = inDto.SubjectId, + Id = inDto.ClinicalFormId ?? NewId.NextGuid(), + ReadingId=inDto.ReadingId, + VisitId=inDto.VisitId, + CheckDate = DateTime.Parse(inDto.QuestionAnswers.Where(x => x.QuestionId == checkDateQuestionId).Select(x => x.Answer).First()), + }; + } + catch (Exception) + { + throw new BusinessValidationFailedException("检查日期问题答案填写错误!"); + } + + List clinicalQuestionAnswers = inDto.QuestionAnswers.Select(x => new ClinicalQuestionAnswer() + { + Answer=x.Answer, + ClinicalDataTrialSetId=inDto.ClinicalDataTrialSetId, + SubjectId=inDto.SubjectId, + ClinicalFormId= clinicalForm.Id, + QuestionId=x.QuestionId, + }).ToList(); + + List clinicalAnswerRowInfos = new List(); + + List clinicalTableAnswers = new List(); + + inDto.TableQuestionAnswerList.ForEach(x => { + var questionid = x.QuestionId; + + for (int i = 0; i < x.TableQuestionAnswers.Count(); i++) + { + var rowInfo = new ClinicalAnswerRowInfo() + { + Id = NewId.NextGuid(), + SubjectId = inDto.SubjectId, + ClinicalFormId = clinicalForm.Id, + QuestionId = questionid, + RowIndex = i+1, + }; + clinicalAnswerRowInfos.Add(rowInfo); + + x.TableQuestionAnswers[i].ForEach(y => { + + clinicalTableAnswers.Add(new ClinicalTableAnswer() + { + Answer=y.Answer, + ClinicalFormId= clinicalForm.Id, + QuestionId= questionid, + RowId= rowInfo.Id, + TableQuestionId=y.TableQuestionId, + SubjectId= inDto.SubjectId, + + + }); + + }); + } + + }); + + if (inDto.ClinicalFormId != null) + { + await _clinicalFormRepository.BatchDeleteNoTrackingAsync(x => x.Id == inDto.ClinicalFormId); + await _clinicalQuestionAnswerRepository.BatchDeleteNoTrackingAsync(x => x.ClinicalFormId == inDto.ClinicalFormId); + await _clinicalAnswerRowInfoRepository.BatchDeleteNoTrackingAsync(x => x.ClinicalFormId == inDto.ClinicalFormId); + await _clinicalTableAnswerRepository.BatchDeleteNoTrackingAsync(x => x.ClinicalFormId == inDto.ClinicalFormId); + } + + await _clinicalFormRepository.AddAsync(clinicalForm); + await _clinicalQuestionAnswerRepository.AddRangeAsync(clinicalQuestionAnswers); + await _clinicalAnswerRowInfoRepository.AddRangeAsync(clinicalAnswerRowInfos); + await _clinicalTableAnswerRepository.AddRangeAsync(clinicalTableAnswers); + await _clinicalTableAnswerRepository.SaveChangesAsync(); + return ResponseOutput.Ok(true); } } diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalAnswerDto.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalAnswerDto.cs index 18322e2d7..49806b73a 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalAnswerDto.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalAnswerDto.cs @@ -71,6 +71,16 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto public class SubmitClinicalFormInDto { + /// + /// VisitId + /// + public Guid? VisitId { get; set; } + + /// + /// VisitId + /// + public Guid? ReadingId { get; set; } + public Guid? ClinicalFormId { get; set; } public Guid SubjectId { get; set; } @@ -80,6 +90,22 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto public List QuestionAnswers { get; set; } - public List> TableQuestionAnswer { get; set; } + public List TableQuestionAnswerList { get; set; } + } + + + public class ClinicalQuestionForm + { + public Guid QuestionId { get; set; } + + public List> TableQuestionAnswers { get; set; } + } + + + public class ClinicalTableQuestionForm + { + public Guid TableQuestionId { get; set; } + + public string Answer { get; set; } = string.Empty; } } diff --git a/IRaCIS.Core.Domain/Reading/ClinicalQuestionAnswer/ClinicalForm.cs b/IRaCIS.Core.Domain/Reading/ClinicalQuestionAnswer/ClinicalForm.cs index ffbec7848..7a292cfd6 100644 --- a/IRaCIS.Core.Domain/Reading/ClinicalQuestionAnswer/ClinicalForm.cs +++ b/IRaCIS.Core.Domain/Reading/ClinicalQuestionAnswer/ClinicalForm.cs @@ -40,7 +40,17 @@ namespace IRaCIS.Core.Domain.Models /// ClinicalDataTrialSetId /// public Guid ClinicalDataTrialSetId { get; set; } - - } + + /// + /// VisitId + /// + public Guid? VisitId { get; set; } + + /// + /// VisitId + /// + public Guid? ReadingId { get; set; } + + } }