修改末次访视触发
parent
925d224097
commit
02ef623ab4
|
@ -29,7 +29,7 @@ namespace IRaCIS.Core.API
|
|||
|
||||
//options.UseTriggers(triggerOptions => triggerOptions.AddTrigger<SubjectVisitImageDateTrigger>());
|
||||
|
||||
options.UseTriggers(triggerOptions => triggerOptions.AddAssemblyTriggers(typeof(SubjectVisitImageDateTrigger).Assembly));
|
||||
options.UseTriggers(triggerOptions => triggerOptions.AddAssemblyTriggers(typeof(SubjectVisitTrigger).Assembly));
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -1710,6 +1710,22 @@
|
|||
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:IRaCIS.Core.Application.Triggers.SubjectVisitFinalVisitTrigger">
|
||||
<summary>
|
||||
处理 访视 末次评估 会影响Subject 状态
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:IRaCIS.Core.Application.Triggers.SubjectVisitTrigger">
|
||||
<summary>
|
||||
处理 访视 1、提交状态 2、执行状态 3、最早最晚 拍片日期
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Triggers.SubjectVisitTrigger.UpdateSubjectVisitSubmitStateAsync(System.Guid)">
|
||||
<summary>处理提交状态</summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Triggers.SubjectVisitTrigger.UpdateSubjectVisitImageDateAsync(System.Guid)">
|
||||
<summary>处理拍片日期</summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.MediatR.Handlers.AnonymizeCacheHandler.#ctor(IRaCIS.Core.Infra.EFCore.IRepository,EasyCaching.Core.IEasyCachingProvider)">
|
||||
<summary>
|
||||
构造函数注入
|
||||
|
|
|
@ -97,28 +97,6 @@ namespace IRaCIS.Core.Application.Services
|
|||
var subject = (await _subjectRepository.FirstOrDefaultAsync(t => t.Id == svCommand.SubjectId)).IfNullThrowException();
|
||||
|
||||
|
||||
if (svCommand.IsFinalVisit)
|
||||
{
|
||||
|
||||
if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == svCommand.SubjectId && t.VisitNum > svCommand.VisitNum && t.SubmitState == SubmitStateEnum.ToSubmit))
|
||||
{
|
||||
throw new BusinessValidationFailedException("该受试者此访视后有影像上传,该访视不允许设置为末次访视");
|
||||
}
|
||||
|
||||
|
||||
subject.Status = SubjectStatus.OutOfVisit;
|
||||
|
||||
//末次访视后的 访视设置为不可用
|
||||
await _subjectVisitRepository.BatchUpdateAsync(t => t.SubjectId == svCommand.SubjectId && t.VisitNum > svCommand.VisitNum, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Unavailable });
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//回退
|
||||
subject.Status = SubjectStatus.OnVisit;
|
||||
|
||||
await _subjectVisitRepository.BatchUpdateAsync(t => t.SubjectId == svCommand.SubjectId && t.VisitExecuted == VisitExecutedEnum.Unavailable, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.UnExecuted });
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
using EntityFrameworkCore.Triggered;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
|
||||
namespace IRaCIS.Core.Application.Triggers
|
||||
{
|
||||
/// <summary>
|
||||
/// 处理 访视 末次评估 会影响Subject 状态
|
||||
/// </summary>
|
||||
public class SubjectVisitFinalVisitTrigger : IAfterSaveTrigger<SubjectVisit>
|
||||
{
|
||||
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
|
||||
private readonly IRepository<Subject> _subjectRepository;
|
||||
|
||||
public SubjectVisitFinalVisitTrigger(IRepository<SubjectVisit> subjectVisitRepository, IRepository<Subject> subjectRepository)
|
||||
{
|
||||
_subjectVisitRepository = subjectVisitRepository;
|
||||
_subjectRepository = subjectRepository;
|
||||
}
|
||||
|
||||
public async Task AfterSave(ITriggerContext<SubjectVisit> context, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var subjectVisit = context.Entity;
|
||||
|
||||
|
||||
if (context.ChangeType == ChangeType.Modified)
|
||||
{
|
||||
|
||||
// 修改了IsFinalVisit
|
||||
if (context.UnmodifiedEntity.IsFinalVisit != subjectVisit.IsFinalVisit)
|
||||
{
|
||||
if (context.Entity.IsFinalVisit)
|
||||
{
|
||||
if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == subjectVisit.SubjectId && t.VisitNum > subjectVisit.VisitNum && t.SubmitState == SubmitStateEnum.ToSubmit))
|
||||
{
|
||||
throw new BusinessValidationFailedException("该受试者此访视后有影像上传,该访视不允许设置为末次访视");
|
||||
}
|
||||
|
||||
await _subjectRepository.BatchUpdateAsync(t => t.Id == subjectVisit.SubjectId,
|
||||
u => new Subject() { Status = SubjectStatus.OutOfVisit });
|
||||
|
||||
|
||||
//末次访视后的 访视设置为不可用
|
||||
await _subjectVisitRepository.BatchUpdateAsync(t => t.SubjectId == subjectVisit.SubjectId && t.VisitNum > subjectVisit.VisitNum, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Unavailable });
|
||||
}
|
||||
else
|
||||
{
|
||||
//回退
|
||||
|
||||
await _subjectRepository.BatchUpdateAsync(t => t.Id == subjectVisit.SubjectId,
|
||||
u => new Subject() { Status = SubjectStatus.OnVisit });
|
||||
|
||||
await _subjectVisitRepository.BatchUpdateAsync(t => t.SubjectId == subjectVisit.SubjectId && t.VisitExecuted == VisitExecutedEnum.Unavailable, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.UnExecuted });
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -3,11 +3,14 @@ using IRaCIS.Core.Domain.Share;
|
|||
|
||||
namespace IRaCIS.Core.Application.Triggers
|
||||
{
|
||||
public class SubjectVisitImageDateTrigger : IAfterSaveTrigger<NoneDicomStudy>, IAfterSaveTrigger<DicomStudy>
|
||||
/// <summary>
|
||||
/// 处理 访视 1、提交状态 2、执行状态 3、最早最晚 拍片日期
|
||||
/// </summary>
|
||||
public class SubjectVisitTrigger : IAfterSaveTrigger<NoneDicomStudy>, IAfterSaveTrigger<DicomStudy>
|
||||
{
|
||||
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
|
||||
|
||||
public SubjectVisitImageDateTrigger(IRepository<SubjectVisit> subjectVisitRepository)
|
||||
public SubjectVisitTrigger(IRepository<SubjectVisit> subjectVisitRepository)
|
||||
{
|
||||
_subjectVisitRepository = subjectVisitRepository;
|
||||
}
|
||||
|
@ -20,6 +23,7 @@ namespace IRaCIS.Core.Application.Triggers
|
|||
if (context.ChangeType == ChangeType.Added || context.ChangeType == ChangeType.Modified)
|
||||
{
|
||||
await UpdateSubjectVisitImageDateAsync(context.Entity.SubjectVisitId);
|
||||
|
||||
await _subjectVisitRepository.BatchUpdateAsync(t => t.Id == subjectVisitId, u => new SubjectVisit()
|
||||
{
|
||||
VisitExecuted = VisitExecutedEnum.Executed
|
||||
|
@ -55,6 +59,8 @@ namespace IRaCIS.Core.Application.Triggers
|
|||
|
||||
}
|
||||
|
||||
/// <summary>处理提交状态</summary>
|
||||
|
||||
public async Task UpdateSubjectVisitSubmitStateAsync(Guid subjectVisitId)
|
||||
{
|
||||
|
||||
|
@ -70,7 +76,7 @@ namespace IRaCIS.Core.Application.Triggers
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>处理拍片日期</summary>
|
||||
private async Task UpdateSubjectVisitImageDateAsync(Guid subjectVisitId)
|
||||
{
|
||||
var svTime = _subjectVisitRepository.Where(t => t.Id == subjectVisitId).Select(t => new
|
Loading…
Reference in New Issue