diff --git a/IRaCIS.Core.Application/Service/Visit/SubjectVisitService.cs b/IRaCIS.Core.Application/Service/Visit/SubjectVisitService.cs index 552acc8f4..de1794055 100644 --- a/IRaCIS.Core.Application/Service/Visit/SubjectVisitService.cs +++ b/IRaCIS.Core.Application/Service/Visit/SubjectVisitService.cs @@ -7,10 +7,7 @@ using Microsoft.AspNetCore.Authorization; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Application.Interfaces; -using IRaCIS.Core.Application.Service.Inspection.Interface; -using Newtonsoft.Json; using IRaCIS.Core.Infrastructure; -using IRaCIS.Core.Domain.Common; namespace IRaCIS.Core.Application.Services { @@ -18,13 +15,11 @@ namespace IRaCIS.Core.Application.Services public class SubjectVisitService : BaseService, ISubjectVisitService { private readonly IRepository _subjectVisitRepository; - private readonly IInspectionService _inspectionService; private readonly IRepository _subjectRepository; - public SubjectVisitService(IRepository subjectVisitRepository, IInspectionService inspectionService,IRepository subjectRepository) + public SubjectVisitService(IRepository subjectVisitRepository, IRepository subjectRepository) { _subjectVisitRepository = subjectVisitRepository; - this._inspectionService = inspectionService; _subjectRepository = subjectRepository; } @@ -33,7 +28,7 @@ namespace IRaCIS.Core.Application.Services [UnitOfWork] public async Task> AddOrUpdateSV(SubjectVisitCommand svCommand) { - + var verifyExp1 = new EntityVerifyExp() { VerifyExp = t => t.VisitNum == svCommand.VisitNum && t.SubjectId == svCommand.SubjectId, @@ -44,7 +39,7 @@ namespace IRaCIS.Core.Application.Services { VerifyExp = t => t.SubjectId == svCommand.SubjectId && t.IsFinalVisit, VerifyMsg = "该受试者已经有访视设置为末次访视,不允许将该访视设置为末次访视", - IsVerify=svCommand.IsFinalVisit + IsVerify = svCommand.IsFinalVisit }; @@ -62,16 +57,16 @@ namespace IRaCIS.Core.Application.Services { if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == svCommand.SubjectId && t.IsFinalVisit)) { - throw new BusinessValidationFailedException("设置末次评估后,不允许添加计划外访视"); + throw new BusinessValidationFailedException("设置末次评估后,不允许添加计划外访视"); } } - dbBeforeEntity = await _subjectVisitRepository.InsertFromDTOAsync(svCommand, false, verifyExp1, verifyExp2); + dbBeforeEntity = await _subjectVisitRepository.InsertFromDTOAsync(svCommand, false, verifyExp1, verifyExp2); } else { - dbBeforeEntity = await _subjectVisitRepository.UpdateFromDTOAsync(svCommand, false,false, verifyExp1, verifyExp2); + dbBeforeEntity = await _subjectVisitRepository.UpdateFromDTOAsync(svCommand, false, false, verifyExp1, verifyExp2); if (svCommand.PDState != dbBeforeEntity.PDState && dbBeforeEntity.SubmitState == SubmitStateEnum.Submitted) { @@ -83,7 +78,7 @@ namespace IRaCIS.Core.Application.Services throw new BusinessValidationFailedException("回退的访视,不允许修改PD确认状态"); } - if (svCommand.IsLostVisit ) + if (svCommand.IsLostVisit) { if (await _subjectVisitRepository.AnyAsync(t => t.Id == svCommand.Id && t.SubmitState == SubmitStateEnum.ToSubmit)) { @@ -93,27 +88,19 @@ namespace IRaCIS.Core.Application.Services } - - //更新受试者 首次给药日期 是否入组确认 if (svCommand.SubjectFirstGiveMedicineTime != null && svCommand.IsBaseLine) { - //await _subjectRepository.UpdatePartialSearchFirstAsync(svCommand.SubjectId, - // u => new Subject() { FirstGiveMedicineTime = svCommand.SubjectFirstGiveMedicineTime }); - - - - var subject = (await _subjectRepository.FirstOrDefaultAsync(t => t.Id == svCommand.SubjectId)).IfNullThrowException(); - - // 更新受试者 - subject.FirstGiveMedicineTime = svCommand.SubjectFirstGiveMedicineTime; - + await _subjectRepository.UpdatePartialFromQueryAsync(svCommand.SubjectId, t => new Subject() + { + FirstGiveMedicineTime = svCommand.SubjectFirstGiveMedicineTime + }); } - - await _repository.SaveChangesAsync(); + + await _subjectVisitRepository.SaveChangesAsync(); return ResponseOutput.Ok(dbBeforeEntity.Id.ToString()); @@ -126,7 +113,7 @@ namespace IRaCIS.Core.Application.Services [HttpPut("{trialId:guid}/{subjectVisitId:guid}/{isUrgent:bool}")] public async Task SetSubjectVisitUrgent(Guid subjectVisitId, bool isUrgent) { - await _subjectVisitRepository.BatchUpdateNoTrackingAsync(t => t.Id == subjectVisitId, u => new SubjectVisit() { IsUrgent = isUrgent }); + await _subjectVisitRepository.UpdatePartialFromQueryAsync(subjectVisitId, u => new SubjectVisit() { IsUrgent = isUrgent },true); return ResponseOutput.Ok(); } @@ -145,11 +132,13 @@ namespace IRaCIS.Core.Application.Services { return ResponseOutput.NotOk("This visit is InPlan and couldn't be deleted."); } - if (await _subjectVisitRepository.AnyAsync(t => t.OutPlanPreviousVisitId == id )) + if (await _subjectVisitRepository.AnyAsync(t => t.OutPlanPreviousVisitId == id)) { return ResponseOutput.NotOk("This visit is OutPlanPreviousVisitId and couldn't be deleted."); } - return ResponseOutput.Result(await _repository.BatchDeleteAsync(s => s.Id == id)); + + await _subjectVisitRepository.SoftDeleteFromQueryAsync(s => s.Id == id); + return ResponseOutput.Ok(); } /// @@ -157,12 +146,13 @@ namespace IRaCIS.Core.Application.Services /// /// /// - [HttpPost("{subjectVisitId:guid}/{trialId:guid}")] + [HttpPut("{trialId:guid}/{subjectVisitId:guid}")] [TrialAudit(AuditType.SubjectAudit, AuditOptType.SetSVExecuted)] [TypeFilter(typeof(TrialResourceFilter))] public async Task SetSVExecuted(Guid subjectVisitId) { - return ResponseOutput.Result(await _subjectVisitRepository.BatchUpdateNoTrackingAsync(s => s.Id == subjectVisitId, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Executed })); + await _subjectVisitRepository.UpdatePartialFromQueryAsync(subjectVisitId, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Executed }, true); + return ResponseOutput.Ok(); } @@ -216,6 +206,6 @@ namespace IRaCIS.Core.Application.Services - + } }