Suject 状态修改触发逻辑
parent
227dec2c94
commit
925d224097
|
@ -167,44 +167,7 @@ namespace IRaCIS.Application.Services
|
||||||
public async Task<IResponseOutput> UpdateSubjectStatus(SubjectStatusChangeCommand subjectStatusChangeCommand)
|
public async Task<IResponseOutput> UpdateSubjectStatus(SubjectStatusChangeCommand subjectStatusChangeCommand)
|
||||||
{
|
{
|
||||||
|
|
||||||
var dbBeforeSubject = await _subjectRepository.UpdateFromDTOAsync(subjectStatusChangeCommand, true);
|
await _subjectRepository.UpdateFromDTOAsync(subjectStatusChangeCommand, true);
|
||||||
|
|
||||||
//如果是出组了
|
|
||||||
if (subjectStatusChangeCommand.Status == SubjectStatus.OutOfVisit)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (subjectStatusChangeCommand.FinalSubjectVisitId != null)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == subjectStatusChangeCommand.SubjectId && t.IsFinalVisit && t.Id != subjectStatusChangeCommand.FinalSubjectVisitId))
|
|
||||||
{
|
|
||||||
|
|
||||||
throw new BusinessValidationFailedException(
|
|
||||||
"该受试者已经有访视设置为末次访视,不允许将该访视设置为末次访视");
|
|
||||||
}
|
|
||||||
|
|
||||||
var sv = await _subjectVisitRepository.FirstOrDefaultAsync(t => t.Id == subjectStatusChangeCommand.FinalSubjectVisitId).IfNullThrowException();
|
|
||||||
|
|
||||||
if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == subjectStatusChangeCommand.SubjectId && t.VisitNum > sv.VisitNum && t.SubmitState == SubmitStateEnum.ToSubmit))
|
|
||||||
{
|
|
||||||
|
|
||||||
throw new BusinessValidationFailedException(
|
|
||||||
"该受试者此访视后有影像上传,该访视不允许设置为末次访视");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
sv.IsFinalVisit = true;
|
|
||||||
|
|
||||||
//末次访视后的 访视设置为不可用
|
|
||||||
await _subjectVisitRepository.BatchUpdateAsync(t => t.SubjectId == subjectStatusChangeCommand.SubjectId && t.VisitNum > sv.VisitNum, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Unavailable });
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//将受试者未执行的 设置为不可用
|
|
||||||
await _subjectVisitRepository.BatchUpdateAsync(t => t.SubjectId == dbBeforeSubject.Id && t.VisitExecuted == VisitExecutedEnum.UnExecuted, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Unavailable });
|
|
||||||
}
|
|
||||||
await _repository.SaveChangesAsync();
|
|
||||||
|
|
||||||
return ResponseOutput.Ok();
|
return ResponseOutput.Ok();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using EntityFrameworkCore.Triggered;
|
using EntityFrameworkCore.Triggered;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
using IRaCIS.Core.Infrastructure;
|
||||||
using MassTransit;
|
using MassTransit;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Triggers
|
namespace IRaCIS.Core.Application.Triggers
|
||||||
|
@ -24,6 +25,8 @@ namespace IRaCIS.Core.Application.Triggers
|
||||||
public async Task AfterSave(ITriggerContext<Subject> context, CancellationToken cancellationToken)
|
public async Task AfterSave(ITriggerContext<Subject> context, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var dbSubject = context.Entity;
|
||||||
|
|
||||||
if (context.ChangeType == ChangeType.Modified )
|
if (context.ChangeType == ChangeType.Modified )
|
||||||
{
|
{
|
||||||
//Site变更
|
//Site变更
|
||||||
|
@ -55,6 +58,35 @@ namespace IRaCIS.Core.Application.Triggers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 出组 状态发生了变更
|
||||||
|
if (context.Entity.Status == SubjectStatus.OutOfVisit && context.Entity.Status != context.UnmodifiedEntity.Status)
|
||||||
|
{
|
||||||
|
if (context.Entity.FinalSubjectVisitId != null)
|
||||||
|
{
|
||||||
|
if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == dbSubject.Id && t.IsFinalVisit && t.Id != dbSubject.FinalSubjectVisitId))
|
||||||
|
{
|
||||||
|
|
||||||
|
throw new BusinessValidationFailedException(
|
||||||
|
"该受试者已经有访视设置为末次访视,不允许将该访视设置为末次访视");
|
||||||
|
}
|
||||||
|
|
||||||
|
var sv = await _subjectVisitRepository.FirstOrDefaultAsync(t => t.Id == dbSubject.FinalSubjectVisitId).IfNullThrowException();
|
||||||
|
|
||||||
|
if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == dbSubject.Id && t.VisitNum > sv.VisitNum && t.SubmitState == SubmitStateEnum.ToSubmit))
|
||||||
|
{
|
||||||
|
|
||||||
|
throw new BusinessValidationFailedException(
|
||||||
|
"该受试者此访视后有影像上传,该访视不允许设置为末次访视");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sv.IsFinalVisit = true;
|
||||||
|
|
||||||
|
//末次访视后的 访视设置为不可用
|
||||||
|
await _subjectVisitRepository.BatchUpdateAsync(t => t.SubjectId == dbSubject.Id && t.VisitNum > sv.VisitNum, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Unavailable });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue