优化代码

Uat_Study
hang 2022-04-24 08:44:36 +08:00
parent dc076c5231
commit f4e663d228
11 changed files with 379 additions and 281 deletions

View File

@ -100,8 +100,4 @@
<ProjectReference Include="..\IRaCIS.Core.Infra.EFCore\IRaCIS.Core.Infra.EFCore.csproj" /> <ProjectReference Include="..\IRaCIS.Core.Infra.EFCore\IRaCIS.Core.Infra.EFCore.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Triggers\" />
</ItemGroup>
</Project> </Project>

View File

@ -1660,6 +1660,16 @@
<param name="trialConfig"></param> <param name="trialConfig"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="T:IRaCIS.Core.Application.Triggers.AddVisitPlanTrigger">
<summary>
添加访视计划 要给改项目下的所有Subject 添加该访视
</summary>
</member>
<member name="T:IRaCIS.Core.Application.Triggers.SubjectStateTrigger">
<summary>
</summary>
</member>
<member name="M:IRaCIS.Core.Application.MediatR.Handlers.AnonymizeCacheHandler.#ctor(IRaCIS.Core.Infra.EFCore.IRepository,EasyCaching.Core.IEasyCachingProvider)"> <member name="M:IRaCIS.Core.Application.MediatR.Handlers.AnonymizeCacheHandler.#ctor(IRaCIS.Core.Infra.EFCore.IRepository,EasyCaching.Core.IEasyCachingProvider)">
<summary> <summary>
构造函数注入 构造函数注入
@ -2426,7 +2436,7 @@
<summary> 添加或更新访视计划某项[New]</summary> <summary> 添加或更新访视计划某项[New]</summary>
</member> </member>
<member name="M:IRaCIS.Application.Services.VisitPlanService.DeleteVisitStage(System.Guid)"> <member name="M:IRaCIS.Application.Services.VisitPlanService.DeleteVisitStage(System.Guid)">
<summary> 删除项目计划某一项[New]</summary> <summary> 删除项目计划某一项 废弃 </summary>
</member> </member>
<member name="M:IRaCIS.Application.Services.DoctorWorkloadService.UploadReviewerAckSOW(System.Guid,IRaCIS.Application.Contracts.ReviewerAckDTO)"> <member name="M:IRaCIS.Application.Services.DoctorWorkloadService.UploadReviewerAckSOW(System.Guid,IRaCIS.Application.Contracts.ReviewerAckDTO)">
<summary> <summary>

View File

@ -1058,13 +1058,6 @@ namespace IRaCIS.Core.Application.Image.QA
#region 临床数据签名 领取、 设置紧急、RequestToQC QC通过、不通过 #region 临床数据签名 领取、 设置紧急、RequestToQC QC通过、不通过
//[HttpPut("{trialId:guid}/{subjectVisitId:guid}")]
//public async Task<IResponseOutput> SignClinicalData(Guid trialId, Guid subjectVisitId)
//{
// await _repository.UpdateFromQueryAsync<SubjectVisit>(t => t.Id == subjectVisitId, u => new SubjectVisit() { ClinicalDataSignTime = DateTime.Now, ClinicalDataSignUserId = _userInfo.Id });
// return ResponseOutput.Ok();
//}
/// <summary> /// <summary>
@ -1097,8 +1090,14 @@ namespace IRaCIS.Core.Application.Image.QA
} }
if (await _subjectVisitRepository.AnyAsync(t => t.IsTake && t.SubjectId != dbSubjectVisit.SubjectId && t.CurrentActionUserId == _userInfo.Id && t.TrialId == dbSubjectVisit.TrialId)) if (await _subjectVisitRepository.AnyAsync(t => t.IsTake &&
t.SubjectId != dbSubjectVisit.SubjectId &&
t.CurrentActionUserId == _userInfo.Id &&
t.TrialId == dbSubjectVisit.TrialId
))
{ {
return ResponseOutput.NotOk("您已经领取了其他受试者,完成后才允许领取新的受试者"); return ResponseOutput.NotOk("您已经领取了其他受试者,完成后才允许领取新的受试者");
} }

View File

@ -5,6 +5,7 @@ using IRaCIS.Core.Application.Filter;
using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Domain.Share;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Application.Service.Inspection.Interface; using IRaCIS.Core.Application.Service.Inspection.Interface;
using IRaCIS.Core.Infrastructure;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IRaCIS.Application.Services namespace IRaCIS.Application.Services
@ -14,11 +15,13 @@ namespace IRaCIS.Application.Services
{ {
private readonly IRepository<Subject> _subjectRepository; private readonly IRepository<Subject> _subjectRepository;
private readonly IInspectionService _inspectionService; private readonly IInspectionService _inspectionService;
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
public SubjectService(IRepository<Subject> subjectRepository, IInspectionService inspectionService) public SubjectService(IRepository<Subject> subjectRepository, IInspectionService inspectionService,IRepository<SubjectVisit> subjectVisitRepository)
{ {
_subjectRepository = subjectRepository; _subjectRepository = subjectRepository;
this._inspectionService = inspectionService; _inspectionService = inspectionService;
_subjectVisitRepository = subjectVisitRepository;
} }
/// <summary> /// <summary>
@ -31,7 +34,6 @@ namespace IRaCIS.Application.Services
[TypeFilter(typeof(TrialResourceFilter))] [TypeFilter(typeof(TrialResourceFilter))]
public async Task<IResponseOutput<string>> AddOrUpdateSubject([FromBody] SubjectCommand subjectCommand) public async Task<IResponseOutput<string>> AddOrUpdateSubject([FromBody] SubjectCommand subjectCommand)
{ {
bool isadd = false;
if (await _repository.AnyAsync<Trial>(t => t.Id == subjectCommand.TrialId && !t.VisitPlanConfirmed)) if (await _repository.AnyAsync<Trial>(t => t.Id == subjectCommand.TrialId && !t.VisitPlanConfirmed))
{ {
return ResponseOutput.NotOk("The trial visit plan has not been confirmed yet.Please contact the project manager to confirm the visit plan before adding subject."); return ResponseOutput.NotOk("The trial visit plan has not been confirmed yet.Please contact the project manager to confirm the visit plan before adding subject.");
@ -43,18 +45,25 @@ namespace IRaCIS.Application.Services
VerifyMsg = "A subjects with the same subject ID already existed in this trial." VerifyMsg = "A subjects with the same subject ID already existed in this trial."
}; };
var mapedSubject = await _subjectRepository.InsertOrUpdateAsync(subjectCommand, false, verifyExp1/*, verifyExp2*/);
bool isadd = false;
Subject mapedSubject = null;
if (subjectCommand.Id == null) //insert if (subjectCommand.Id == null) //insert
{ {
isadd = true; isadd = true;
var IsEnrollementQualificationConfirm = await _repository.Where<Trial>(t => t.Id == mapedSubject.TrialId).Select(u => u.IsEnrollementQualificationConfirm).FirstOrDefaultAsync();
mapedSubject= await _subjectRepository.InsertFromDTOAsync(subjectCommand, false, verifyExp1);
//添加受试者的时候,获取访视计划列表,添加到受试者访视表。 //添加受试者的时候,获取访视计划列表,添加到受试者访视表。
var visitPlan = await _repository.Where<VisitStage>(t => t.TrialId == subjectCommand.TrialId).ToListAsync(); var visitPlan = await _repository.Where<VisitStage>(t => t.TrialId == subjectCommand.TrialId).ToListAsync();
var svlist = _mapper.Map<List<SubjectVisit>>(visitPlan); var svlist = _mapper.Map<List<SubjectVisit>>(visitPlan);
var IsEnrollementQualificationConfirm = await _repository.Where<Trial>(t => t.Id == mapedSubject.TrialId).Select(u => u.IsEnrollementQualificationConfirm).FirstOrDefaultAsync();
svlist.ForEach(t => svlist.ForEach(t =>
{ {
t.TrialId = subjectCommand.TrialId; t.TrialId = subjectCommand.TrialId;
@ -66,35 +75,16 @@ namespace IRaCIS.Application.Services
} }
else //update else //update
{ {
//变更site
if (mapedSubject.SiteId != subjectCommand.SiteId)
{
await _repository.BatchUpdateAsync<SubjectVisit>(t => t.SubjectId == mapedSubject.Id, mapedSubject = await _subjectRepository.UpdateFromDTOAsync(subjectCommand, false,false, verifyExp1/*, verifyExp2*/);
u => new SubjectVisit() { SiteId = mapedSubject.SiteId });
await _repository.BatchUpdateAsync<DicomStudy>(t => t.SubjectId == mapedSubject.Id,
u => new DicomStudy() { SiteId = mapedSubject.SiteId });
};
////如果访视结束了 需要删除计划外未执行的访视
//if (mapedSubject.Status == SubjectStatus.EndOfVisit)
//{
// await _repository.DeleteFromQueryAsync<SubjectVisit>(t => t.VisitExecuted == VisitExecutedEnum.UnExecuted && t.SubjectId == mapedSubject.Id && t.InPlan == false);
//}
////如果是出组了 将受试者未执行的 设置为不可用
//if (mapedSubject.Status == SubjectStatus.OutOfEnrollment)
//{
// await _repository.UpdateFromQueryAsync<SubjectVisit>(t => t.SubjectId == mapedSubject.Id && t.VisitExecuted == VisitExecutedEnum.UnExecuted, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Unavailable });
//}
} }
await _repository.SaveChangesAsync(); await _repository.SaveChangesAsync();
var createtime = DateTime.Now.AddSeconds(1); var createtime = DateTime.Now.AddSeconds(1);
// 添加稽查记录 // 添加稽查记录
if (isadd) if (isadd)
@ -127,24 +117,24 @@ namespace IRaCIS.Application.Services
SiteId = subjectCommand.SiteId, SiteId = subjectCommand.SiteId,
SubjectId = mapedSubject.Id, SubjectId = mapedSubject.Id,
SubjectCode = subjectCommand.Code, SubjectCode = subjectCommand.Code,
SubjectVisitId= item.Id, SubjectVisitId = item.Id,
SubjectVisitName=item.VisitName, SubjectVisitName = item.VisitName,
BlindName=item.BlindName, BlindName = item.BlindName,
IsSign = false, IsSign = false,
CreateTime = visittime, CreateTime = visittime,
Identification = "Add|Visit|Info|Visit-Image Upload", Identification = "Add|Visit|Info|Visit-Image Upload",
JsonDetail = JsonConvert.SerializeObject(new JsonDetail = JsonConvert.SerializeObject(new
{ {
BlindName=item.BlindName, BlindName = item.BlindName,
VisitName = item.VisitName, VisitName = item.VisitName,
VisitNum = item.VisitNum, VisitNum = item.VisitNum,
IsBaseLine=item.IsBaseLine ? "是" : "否", IsBaseLine = item.IsBaseLine ? "是" : "否",
VisitExecuted= "否", VisitExecuted = "否",
IsFinalVisit=item.IsFinalVisit ? "是" : "否", IsFinalVisit = item.IsFinalVisit ? "是" : "否",
PDState=item.PDState== PDStateEnum.PDProgress?"是":"否", PDState = item.PDState == PDStateEnum.PDProgress ? "是" : "否",
InPlan=item.InPlan, InPlan = item.InPlan,
IsUrgent=item.IsUrgent, IsUrgent = item.IsUrgent,
IsLostVisit =item.IsLostVisit?"是":"否", IsLostVisit = item.IsLostVisit ? "是" : "否",
}) })
}); });
@ -176,7 +166,7 @@ namespace IRaCIS.Application.Services
} }
await _inspectionService.AddListInspectionRecordAsync(datas); await _inspectionService.AddListInspectionRecordAsync(datas);
} }
return ResponseOutput.Ok(mapedSubject.Id.ToString()); return ResponseOutput.Ok(mapedSubject.Id.ToString());
@ -184,19 +174,11 @@ namespace IRaCIS.Application.Services
} }
[HttpPut("{trialId:guid}")] [HttpPut("{trialId:guid}")]
[UnitOfWork]
public async Task<IResponseOutput> UpdateSubjectStatus(SubjectStatusChangeCommand subjectStatusChangeCommand) public async Task<IResponseOutput> UpdateSubjectStatus(SubjectStatusChangeCommand subjectStatusChangeCommand)
{ {
var subject = await _subjectRepository.FirstOrDefaultAsync(t => t.Id == subjectStatusChangeCommand.SubjectId);
if (subject == null) return Null404NotFound(subject); var dbBeforeSubject = await _subjectRepository.UpdateFromDTOAsync(subjectStatusChangeCommand, true);
_mapper.Map(subjectStatusChangeCommand, subject);
////如果访视结束了 需要删除计划外未执行的访视
//if (subjectStatusChangeCommand.Status == SubjectStatus.EndOfVisit)
//{
// await _repository.DeleteFromQueryAsync<SubjectVisit>(t => t.VisitExecuted == VisitExecutedEnum.UnExecuted && t.SubjectId == subject.Id && t.InPlan == false);
//}
//如果是出组了 //如果是出组了
if (subjectStatusChangeCommand.Status == SubjectStatus.OutOfVisit) if (subjectStatusChangeCommand.Status == SubjectStatus.OutOfVisit)
@ -205,32 +187,33 @@ namespace IRaCIS.Application.Services
if (subjectStatusChangeCommand.FinalSubjectVisitId != null) if (subjectStatusChangeCommand.FinalSubjectVisitId != null)
{ {
if (await _repository.AnyAsync<SubjectVisit>(t => t.SubjectId == subjectStatusChangeCommand.SubjectId && t.IsFinalVisit && t.Id != subjectStatusChangeCommand.FinalSubjectVisitId)) if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == subjectStatusChangeCommand.SubjectId && t.IsFinalVisit && t.Id != subjectStatusChangeCommand.FinalSubjectVisitId))
{ {
return ResponseOutput.NotOk("该受试者已经有访视设置为末次访视,不允许将该访视设置为末次访视");
throw new BusinessValidationFailedException(
"该受试者已经有访视设置为末次访视,不允许将该访视设置为末次访视");
} }
var sv = await _repository.FirstOrDefaultAsync<SubjectVisit>(t => t.Id == subjectStatusChangeCommand.FinalSubjectVisitId).IfNullThrowException(); var sv = await _subjectVisitRepository.FirstOrDefaultAsync(t => t.Id == subjectStatusChangeCommand.FinalSubjectVisitId).IfNullThrowException();
if (await _repository.AnyAsync<SubjectVisit>(t => t.SubjectId == subjectStatusChangeCommand.SubjectId && t.VisitNum > sv.VisitNum && t.SubmitState == SubmitStateEnum.ToSubmit)) if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == subjectStatusChangeCommand.SubjectId && t.VisitNum > sv.VisitNum && t.SubmitState == SubmitStateEnum.ToSubmit))
{ {
return ResponseOutput.NotOk("该受试者此访视后有影像上传,该访视不允许设置为末次访视");
throw new BusinessValidationFailedException(
"该受试者此访视后有影像上传,该访视不允许设置为末次访视");
} }
sv.IsFinalVisit = true; sv.IsFinalVisit = true;
//末次访视后的 访视设置为不可用 //末次访视后的 访视设置为不可用
await _repository.BatchUpdateAsync<SubjectVisit>(t => t.SubjectId == subjectStatusChangeCommand.SubjectId && t.VisitNum > sv.VisitNum, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Unavailable }); await _subjectVisitRepository.BatchUpdateAsync(t => t.SubjectId == subjectStatusChangeCommand.SubjectId && t.VisitNum > sv.VisitNum, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Unavailable });
} }
//将受试者未执行的 设置为不可用 //将受试者未执行的 设置为不可用
await _repository.BatchUpdateAsync<SubjectVisit>(t => t.SubjectId == subject.Id && t.VisitExecuted == VisitExecutedEnum.UnExecuted, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Unavailable }); await _subjectVisitRepository.BatchUpdateAsync(t => t.SubjectId == dbBeforeSubject.Id && t.VisitExecuted == VisitExecutedEnum.UnExecuted, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Unavailable });
}
else
{
} }
await _repository.SaveChangesAsync(); await _repository.SaveChangesAsync();
@ -240,25 +223,7 @@ namespace IRaCIS.Application.Services
} }
[Obsolete]
[HttpGet("{trialId:guid}/{subjectId:guid}/{finalSubjectVisitId:guid}")]
public async Task<IResponseOutput> VerifySubjectFinalVisit(Guid subjectId, Guid finalSubjectVisitId)
{
if (await _repository.AnyAsync<SubjectVisit>(t => t.SubjectId == subjectId && t.IsFinalVisit))
{
return ResponseOutput.NotOk("该受试者已经有访视设置为末次访视,不允许将该访视设置为末次访视");
}
var sv = (await _repository.FirstOrDefaultAsync<SubjectVisit>(t => t.Id == finalSubjectVisitId)).IfNullThrowException();
if (await _repository.AnyAsync<SubjectVisit>(t => t.SubjectId == subjectId && t.VisitNum > sv.VisitNum && t.SubmitState == SubmitStateEnum.ToSubmit))
{
return ResponseOutput.NotOk("该受试者此访视后有影像上传,该访视不允许设置为末次访视");
}
return ResponseOutput.Ok();
}
[HttpDelete("{id:guid}/{trialId:guid}")] [HttpDelete("{id:guid}/{trialId:guid}")]
@ -268,14 +233,16 @@ namespace IRaCIS.Application.Services
public async Task<IResponseOutput> DeleteSubject(Guid id) public async Task<IResponseOutput> DeleteSubject(Guid id)
{ {
if (await _repository.AnyAsync<SubjectVisit>(u => u.SubjectId == id && u.VisitExecuted == VisitExecutedEnum.Executed)) if (await _subjectVisitRepository.AnyAsync(u => u.SubjectId == id && u.VisitExecuted == VisitExecutedEnum.Executed))
{ {
return ResponseOutput.NotOk("This subject has executed a visit with uploading study images,and couldn't be deleted."); return ResponseOutput.NotOk("This subject has executed a visit with uploading study images,and couldn't be deleted.");
} }
var isSuccess = await _subjectRepository.BatchDeleteAsync(u => u.Id == id); var isSuccess = await _subjectRepository.BatchDeleteAsync(u => u.Id == id);
await _repository.BatchDeleteAsync<SubjectVisit>(u => u.SubjectId == id); await _subjectVisitRepository.BatchDeleteAsync(u => u.SubjectId == id);
var subvisit = await _repository.GetQueryable<SubjectVisit>().Where(x=>x.SubjectId==id).ToListAsync();
var subvisit = await _subjectVisitRepository.Where(x => x.SubjectId == id).ToListAsync();
List<DataInspection> datas = new List<DataInspection>(); List<DataInspection> datas = new List<DataInspection>();
@ -348,6 +315,25 @@ namespace IRaCIS.Application.Services
return query.ToList(); return query.ToList();
} }
[Obsolete]
[HttpGet("{trialId:guid}/{subjectId:guid}/{finalSubjectVisitId:guid}")]
public async Task<IResponseOutput> VerifySubjectFinalVisit(Guid subjectId, Guid finalSubjectVisitId)
{
if (await _repository.AnyAsync<SubjectVisit>(t => t.SubjectId == subjectId && t.IsFinalVisit))
{
return ResponseOutput.NotOk("该受试者已经有访视设置为末次访视,不允许将该访视设置为末次访视");
}
var sv = (await _repository.FirstOrDefaultAsync<SubjectVisit>(t => t.Id == finalSubjectVisitId)).IfNullThrowException();
if (await _repository.AnyAsync<SubjectVisit>(t => t.SubjectId == subjectId && t.VisitNum > sv.VisitNum && t.SubmitState == SubmitStateEnum.ToSubmit))
{
return ResponseOutput.NotOk("该受试者此访视后有影像上传,该访视不允许设置为末次访视");
}
return ResponseOutput.Ok();
}
} }
} }

View File

@ -9,6 +9,7 @@ using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.Interfaces;
using IRaCIS.Core.Application.Service.Inspection.Interface; using IRaCIS.Core.Application.Service.Inspection.Interface;
using Newtonsoft.Json; using Newtonsoft.Json;
using IRaCIS.Core.Infrastructure;
namespace IRaCIS.Core.Application.Services namespace IRaCIS.Core.Application.Services
{ {
@ -31,12 +32,6 @@ namespace IRaCIS.Core.Application.Services
[UnitOfWork] [UnitOfWork]
public async Task<IResponseOutput<string>> AddOrUpdateSV(SubjectVisitCommand svCommand) public async Task<IResponseOutput<string>> AddOrUpdateSV(SubjectVisitCommand svCommand)
{ {
bool isadd=false;
if (svCommand.Id == null)
{
isadd=true;
}
var verifyExp1 = new EntityVerifyExp<SubjectVisit>() var verifyExp1 = new EntityVerifyExp<SubjectVisit>()
{ {
@ -53,43 +48,60 @@ namespace IRaCIS.Core.Application.Services
svCommand.BlindName = "B" + ((int)(svCommand.VisitNum * 10)).ToString("D3"); svCommand.BlindName = "B" + ((int)(svCommand.VisitNum * 10)).ToString("D3");
var subject = (await _subjectRepository.FirstOrDefaultAsync(t => t.Id == svCommand.SubjectId)).IfNullThrowException();
svCommand.VisitExecuted = svCommand.IsLostVisit ? VisitExecutedEnum.Executed : svCommand.VisitExecuted; svCommand.VisitExecuted = svCommand.IsLostVisit ? VisitExecutedEnum.Executed : svCommand.VisitExecuted;
//设置末次评估后,不允许添加计划外访视
if (svCommand.InPlan == false && svCommand.Id == null) SubjectVisit dbBeforeEntity = null;
//Add
if (svCommand.Id == null)
{ {
if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == svCommand.SubjectId && t.IsFinalVisit))
//设置末次评估后,不允许添加计划外访视
if (svCommand.InPlan == false)
{ {
return ResponseOutput.NotOk("设置末次评估后,不允许添加计划外访视"); if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == svCommand.SubjectId && t.IsFinalVisit))
{
throw new BusinessValidationFailedException("设置末次评估后,不允许添加计划外访视");
}
}
dbBeforeEntity = await _subjectVisitRepository.InsertFromDTOAsync(svCommand, false, verifyExp1, verifyExp2);
}
else
{
dbBeforeEntity = await _subjectVisitRepository.UpdateFromDTOAsync(svCommand, false,false, verifyExp1, verifyExp2);
if (svCommand.PDState != dbBeforeEntity.PDState && dbBeforeEntity.SubmitState == SubmitStateEnum.Submitted)
{
throw new BusinessValidationFailedException("CRC提交后不允许修改PD确认状态");
}
if (svCommand.PDState != dbBeforeEntity.PDState && dbBeforeEntity.RequestBackState == RequestBackStateEnum.PM_AgressBack)
{
throw new BusinessValidationFailedException("回退的访视不允许修改PD确认状态");
}
if (svCommand.IsLostVisit )
{
if (await _subjectVisitRepository.AnyAsync(t => t.Id == svCommand.Id && t.SubmitState == SubmitStateEnum.ToSubmit))
{
throw new BusinessValidationFailedException("该受试者此访视有影像上传,不允许设置为失访");
}
} }
} }
//更新的时候,返回的是数据库此时的实体数据
var needDealEntity = await _subjectVisitRepository.InsertOrUpdateAsync(svCommand, false, verifyExp1, verifyExp2);
if (svCommand.PDState != needDealEntity.PDState && svCommand.Id != null && needDealEntity.SubmitState == SubmitStateEnum.Submitted) var subject = (await _subjectRepository.FirstOrDefaultAsync(t => t.Id == svCommand.SubjectId)).IfNullThrowException();
{
return ResponseOutput.NotOk("CRC提交后不允许修改PD确认状态");
}
if (svCommand.PDState != needDealEntity.PDState && svCommand.Id != null && needDealEntity.RequestBackState == RequestBackStateEnum.PM_AgressBack)
{
return ResponseOutput.NotOk("回退的访视不允许修改PD确认状态");
}
if (svCommand.IsFinalVisit) if (svCommand.IsFinalVisit)
{ {
if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == svCommand.SubjectId && t.VisitNum > svCommand.VisitNum && t.SubmitState == SubmitStateEnum.ToSubmit)) if (await _subjectVisitRepository.AnyAsync(t => t.SubjectId == svCommand.SubjectId && t.VisitNum > svCommand.VisitNum && t.SubmitState == SubmitStateEnum.ToSubmit))
{ {
return ResponseOutput.NotOk("该受试者此访视后有影像上传,该访视不允许设置为末次访视"); throw new BusinessValidationFailedException("该受试者此访视后有影像上传,该访视不允许设置为末次访视");
} }
@ -107,13 +119,7 @@ namespace IRaCIS.Core.Application.Services
await _subjectVisitRepository.BatchUpdateAsync(t => t.SubjectId == svCommand.SubjectId && t.VisitExecuted == VisitExecutedEnum.Unavailable, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.UnExecuted }); await _subjectVisitRepository.BatchUpdateAsync(t => t.SubjectId == svCommand.SubjectId && t.VisitExecuted == VisitExecutedEnum.Unavailable, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.UnExecuted });
} }
if (svCommand.IsLostVisit && svCommand.Id == null)
{
if (await _subjectVisitRepository.AnyAsync(t => t.Id==svCommand.Id && t.SubmitState == SubmitStateEnum.ToSubmit))
{
return ResponseOutput.NotOk("该受试者此访视有影像上传,不允许设置为失访");
}
}
//更新受试者 首次给药日期 是否入组确认 //更新受试者 首次给药日期 是否入组确认
if (svCommand.SubjectFirstGiveMedicineTime != null) if (svCommand.SubjectFirstGiveMedicineTime != null)
@ -154,6 +160,14 @@ namespace IRaCIS.Core.Application.Services
await _repository.SaveChangesAsync(); await _repository.SaveChangesAsync();
bool isadd = false;
if (svCommand.Id == null)
{
isadd = true;
}
if (isadd) if (isadd)
{ {
List<DataInspection> dataInspection=new List<DataInspection>(); List<DataInspection> dataInspection=new List<DataInspection>();
@ -198,7 +212,7 @@ namespace IRaCIS.Core.Application.Services
return ResponseOutput.Ok(needDealEntity.Id.ToString()); return ResponseOutput.Ok(dbBeforeEntity.Id.ToString());
} }

View File

@ -26,7 +26,7 @@ namespace IRaCIS.Application.Services
private readonly IRepository<VisitPlanInfluenceStudy> _influnceRepository; private readonly IRepository<VisitPlanInfluenceStudy> _influnceRepository;
private readonly IInspectionService _inspectionService; private readonly IInspectionService _inspectionService;
public VisitPlanService(IRepository<VisitStage> visitStageRepository,IRepository<Trial> trialRepository, IRepository<SubjectVisit> subjectVisitRepository, public VisitPlanService(IRepository<VisitStage> visitStageRepository, IRepository<Trial> trialRepository, IRepository<SubjectVisit> subjectVisitRepository,
IRepository<VisitPlanInfluenceStat> influnceStatRepository, IRepository<VisitPlanInfluenceStat> influnceStatRepository,
IRepository<VisitPlanInfluenceStudy> visitPlanInfluenceStudy, IRepository<VisitPlanInfluenceStudy> visitPlanInfluenceStudy,
@ -61,7 +61,7 @@ namespace IRaCIS.Application.Services
var query = _visitStageRepository.AsQueryable(true).Where(u => u.TrialId == trialId) var query = _visitStageRepository.AsQueryable(true).Where(u => u.TrialId == trialId)
.ProjectTo<VisitStageDTO>(_mapper.ConfigurationProvider).OrderBy(t => t.VisitNum); .ProjectTo<VisitStageDTO>(_mapper.ConfigurationProvider).OrderBy(t => t.VisitNum);
var list = await query.ToListAsync(); var list = await query.ToListAsync();
var trial = await _repository.FirstOrDefaultAsync<Trial>(t => t.Id == trialId).IfNullThrowException(); var trial = (await _repository.FirstOrDefaultAsync<Trial>(t => t.Id == trialId)).IfNullThrowException();
return new VisitPlanView() return new VisitPlanView()
{ {
@ -93,7 +93,6 @@ namespace IRaCIS.Application.Services
[UnitOfWork] [UnitOfWork]
public async Task<IResponseOutput<VisitStage>> AddOrUpdateVisitStage(VisitPlanCommand visitPlan) public async Task<IResponseOutput<VisitStage>> AddOrUpdateVisitStage(VisitPlanCommand visitPlan)
{ {
DateTime createtime = DateTime.Now;
if (!await _trialRepository.Where(t => t.Id == visitPlan.TrialId).IgnoreQueryFilters().AnyAsync(t => t.TrialStatusStr == StaticData.TrialOngoing || t.TrialStatusStr == StaticData.TrialInitializing)) if (!await _trialRepository.Where(t => t.Id == visitPlan.TrialId).IgnoreQueryFilters().AnyAsync(t => t.TrialStatusStr == StaticData.TrialOngoing || t.TrialStatusStr == StaticData.TrialInitializing))
{ {
@ -101,7 +100,7 @@ namespace IRaCIS.Application.Services
} }
var visitPlanList = await _visitStageRepository.Where(t => t.TrialId == visitPlan.TrialId,ignoreQueryFilters:true) var visitPlanList = await _visitStageRepository.Where(t => t.TrialId == visitPlan.TrialId, ignoreQueryFilters: true)
.Select(t => new { t.Id, t.VisitNum, t.VisitDay }).OrderBy(t => t.VisitNum).ToListAsync(); .Select(t => new { t.Id, t.VisitNum, t.VisitDay }).OrderBy(t => t.VisitNum).ToListAsync();
//更新的时候,需要排除自己 //更新的时候,需要排除自己
@ -141,51 +140,21 @@ namespace IRaCIS.Application.Services
throw new BusinessValidationFailedException("A visit already is baseline in the current visit plan."); throw new BusinessValidationFailedException("A visit already is baseline in the current visit plan.");
} }
//已添加受试者 都不存在该新增的计划名称 那么该项目所有受试者都增加一个访视记录 //不用前端传递的值
if (!await _subjectVisitRepository.AnyAsync(t => t.VisitName == visitPlan.VisitName && t.TrialId == visitPlan.TrialId)) visitPlan.BlindName = "B" + ((int)visitPlan.VisitNum * 10).ToString("D3");
{
var subjectSVS = await _subjectVisitRepository.Where(t => t.TrialId == visitPlan.TrialId).Select(t => new { t.SubjectId, t.SiteId,t.IsFinalVisit }).Distinct().ToListAsync();
var subjects = subjectSVS.Select(t => new { t.SubjectId, t.SiteId }).Distinct().ToList(); var visitPlanItem = await _visitStageRepository.InsertFromDTOAsync(visitPlan,true);
foreach (var subject in subjects) #region 废弃前
{
var svItem = _mapper.Map<SubjectVisit>(visitPlan);
svItem.SiteId = subject.SiteId; // var visitPlanItem = _mapper.Map<VisitStage>(visitPlan);
svItem.SubjectId = subject.SubjectId; //visitPlanItem.BlindName = "B" + ((int)visitPlanItem.VisitNum * 10).ToString("D3");
svItem.Id = NewId.NextGuid();
//设置了末次访视,那么加访视计划的时候,设置为不可用 //var result = await _visitStageRepository.AddAsync(visitPlanItem,true);
if (subjectSVS.Any(t => t.SubjectId == svItem.SubjectId && t.IsFinalVisit)) #endregion
{
svItem.VisitExecuted = VisitExecutedEnum.Unavailable;
}
await _repository.AddAsync(svItem);
}
}
var visitPlanItem = _mapper.Map<VisitStage>(visitPlan);
visitPlanItem.BlindName = "B" + ((int)visitPlanItem.VisitNum * 10).ToString("D3");
//var result = await _visitStageRepository.AddAsync(visitPlanItem);
var result = await _repository.AddAsync(visitPlanItem);
//更新项目访视计划状态为未确认
await _trialRepository.BatchUpdateAsync(u => u.Id == visitPlan.TrialId, t => new Trial() { VisitPlanConfirmed = false });
await _repository.SaveChangesAsync();
//return ResponseOutput.Ok(result.Id.ToString());
return ResponseOutput.Ok(visitPlanItem); return ResponseOutput.Ok(visitPlanItem);
} }
@ -193,22 +162,42 @@ namespace IRaCIS.Application.Services
{ {
if (await _visitStageRepository.AnyAsync(t => t.TrialId == visitPlan.TrialId && (t.VisitName == visitPlan.VisitName || t.VisitNum == visitPlan.VisitNum) && t.Id != visitPlan.Id,true)) if (await _visitStageRepository.AnyAsync(t => t.TrialId == visitPlan.TrialId && (t.VisitName == visitPlan.VisitName || t.VisitNum == visitPlan.VisitNum) && t.Id != visitPlan.Id, true))
{ {
throw new BusinessValidationFailedException("A visit with the same VisitName/VisitNum already existed in the current visit plan."); throw new BusinessValidationFailedException("A visit with the same VisitName/VisitNum already existed in the current visit plan.");
} }
if (await _visitStageRepository.AnyAsync(t => t.TrialId == visitPlan.TrialId && t.IsBaseLine && t.Id != visitPlan.Id,true) && visitPlan.IsBaseLine) if (await _visitStageRepository.AnyAsync(t => t.TrialId == visitPlan.TrialId && t.IsBaseLine && t.Id != visitPlan.Id, true) && visitPlan.IsBaseLine)
{ {
throw new BusinessValidationFailedException("A visit already is baseline in the current visit plan."); throw new BusinessValidationFailedException("A visit already is baseline in the current visit plan.");
} }
#region 废弃前
//var stage = (await _visitStageRepository.FirstOrDefaultAsync(t => t.Id == visitPlan.Id, true)).IfNullThrowException();
var stage = await _visitStageRepository.FirstOrDefaultAsync(t => t.Id == visitPlan.Id,true); ////修改是否是基线
if (stage == null) throw new BusinessValidationFailedException("None"); //if (stage.IsBaseLine && stage.IsBaseLine != visitPlan.IsBaseLine)
//{
// if (await _repository.Where<SubjectVisit>(t => t.TrialId == visitPlan.TrialId).AnyAsync(v => v.IsBaseLine && v.SubmitState >= SubmitStateEnum.ToSubmit))
// {
// throw new BusinessValidationFailedException("有CRC已经为基线上传了影像数据,不允许修改基线");
// }
//}
//_mapper.Map(visitPlan, stage);
//stage.BlindName = "B" + ((int)visitPlan.VisitNum * 10).ToString("D3");
//await _visitStageRepository.SaveChangesAsync();
#endregion
//不用前端传递的值
visitPlan.BlindName = "B" + ((int)visitPlan.VisitNum * 10).ToString("D3");
//返回的是数据库查询的数据
var stage = await _visitStageRepository.UpdateFromDTOAsync(visitPlan,true);
//修改是否是基线
if (stage.IsBaseLine && stage.IsBaseLine != visitPlan.IsBaseLine) if (stage.IsBaseLine && stage.IsBaseLine != visitPlan.IsBaseLine)
{ {
if (await _repository.Where<SubjectVisit>(t => t.TrialId == visitPlan.TrialId).AnyAsync(v => v.IsBaseLine && v.SubmitState >= SubmitStateEnum.ToSubmit)) if (await _repository.Where<SubjectVisit>(t => t.TrialId == visitPlan.TrialId).AnyAsync(v => v.IsBaseLine && v.SubmitState >= SubmitStateEnum.ToSubmit))
@ -217,16 +206,8 @@ namespace IRaCIS.Application.Services
} }
} }
_mapper.Map(visitPlan, stage);
stage.BlindName = "B" + ((int)visitPlan.VisitNum * 10).ToString("D3");
//更新项目访视计划状态为未确认
//await _trialRepository.UpdateFromQueryAsync(u => u.Id == visitPlan.TrialId, t => new Trial() { VisitPlanConfirmed = false });
await _repository.SaveChangesAsync();
return ResponseOutput.Ok(stage); return ResponseOutput.Ok(stage);
//return ResponseOutput.Ok();
} }
@ -234,54 +215,6 @@ namespace IRaCIS.Application.Services
} }
/// <summary> 删除项目计划某一项[New]</summary>
[HttpDelete("{id:guid}/{trialId:guid}")]
[TrialAudit(AuditType.TrialAudit, AuditOptType.DeleteTrialVisitPlanItem)]
[TypeFilter(typeof(TrialResourceFilter))]
public async Task<IResponseOutput> DeleteVisitStage(Guid id)
{
var visitPlan = await _visitStageRepository.FirstOrDefaultAsync(t => t.Id == id);
if (visitPlan == null) return Null404NotFound(visitPlan);
if (await _repository.AnyAsync<SubjectVisit>(t => t.VisitName == visitPlan.VisitName && t.TrialId == visitPlan.TrialId && t.VisitExecuted == VisitExecutedEnum.Executed))
{
return ResponseOutput.NotOk("The visit plan has been assigned to the subjects and executed.");
}
var list = await _subjectVisitRepository.Where(t => t.TrialId == visitPlan.TrialId && t.VisitName == visitPlan.VisitName).ToListAsync();
List<DataInspection> datas = new List<DataInspection>();
var createtime = DateTime.Now.AddSeconds(1);
list.ForEach(x =>
{
datas.Add(new DataInspection()
{
BlindName = x.BlindName,
IsSign = false,
SiteId = x.SiteId,
SubjectId = x.SubjectId,
SubjectVisitId = x.Id,
CreateTime = createtime,
SubjectVisitName = x.VisitName,
TrialId = x.TrialId,
JsonDetail = JsonConvert.SerializeObject(x),
Identification = "Delete|Visit|Data|Visit-Image Upload"
});
});
await _inspectionService.AddListInspectionRecordAsync(datas);
await _repository.BatchDeleteAsync<SubjectVisit>(t => t.TrialId == visitPlan.TrialId && t.VisitName == visitPlan.VisitName);
var result = await _visitStageRepository.BatchDeleteAsync(u => u.Id == id);
return ResponseOutput.Result(result);
}
[UnitOfWork] [UnitOfWork]
@ -290,7 +223,7 @@ namespace IRaCIS.Application.Services
public async Task<IResponseOutput> ConfirmTrialVisitPlan(Guid trialId) public async Task<IResponseOutput> ConfirmTrialVisitPlan(Guid trialId)
{ {
if (!await _trialRepository.AnyAsync(t => t.Id == trialId &&( t.TrialStatusStr==StaticData.TrialInitializing || t.TrialStatusStr == StaticData.TrialOngoing))) if (!await _trialRepository.AnyAsync(t => t.Id == trialId && (t.TrialStatusStr == StaticData.TrialInitializing || t.TrialStatusStr == StaticData.TrialOngoing)))
{ {
return ResponseOutput.NotOk("仅仅在项目初始化或者进行中时,才允许修改确认"); return ResponseOutput.NotOk("仅仅在项目初始化或者进行中时,才允许修改确认");
} }
@ -314,16 +247,27 @@ namespace IRaCIS.Application.Services
List<DataInspection> datas = new List<DataInspection>(); List<DataInspection> datas = new List<DataInspection>();
var addvisitStages = await _visitStageRepository.Where(x => !x.IsHaveFirstConfirmed&&x.TrialId== trialId).ToListAsync(); var addvisitStages = await _visitStageRepository.Where(x => !x.IsHaveFirstConfirmed && x.TrialId == trialId).ToListAsync();
//更新项目访视计划状态为已确认 //更新项目访视计划状态为已确认
await _trialRepository.BatchUpdateAsync(u => u.Id == trialId, t => new Trial() { VisitPlanConfirmed = true }); await _trialRepository.BatchUpdateAsync(u => u.Id == trialId, t => new Trial() { VisitPlanConfirmed = true });
//找到访视计划修改的Item //找到访视计划修改的Item
var changedList = await _visitStageRepository.Where(t => t.TrialId == trialId && t.IsConfirmed == false) var changedList = await _visitStageRepository.Where(t => t.TrialId == trialId && t.IsConfirmed == false)
.Select(t => new { t.Trial.IsHaveFirstGiveMedicineDate, t.Id, t.VisitName, t.TrialId, t.VisitWindowLeft, t.VisitWindowRight, .Select(t => new
t.VisitDay, t.VisitNum, t.IsBaseLine, t.BlindName,t.Description, {
IsConfirmed=true, t.Trial.IsHaveFirstGiveMedicineDate,
t.Id,
t.VisitName,
t.TrialId,
t.VisitWindowLeft,
t.VisitWindowRight,
t.VisitDay,
t.VisitNum,
t.IsBaseLine,
t.BlindName,
t.Description,
IsConfirmed = true,
}).ToListAsync(); }).ToListAsync();
var createtime = DateTime.Now.AddSeconds(1); var createtime = DateTime.Now.AddSeconds(1);
@ -347,7 +291,7 @@ namespace IRaCIS.Application.Services
}); });
//访视计划 整体状态变更为 确认 //访视计划 整体状态变更为 确认
await _visitStageRepository.BatchUpdateAsync(u => u.TrialId == trialId, t => new VisitStage() { IsConfirmed = true ,IsHaveFirstConfirmed = true}); await _visitStageRepository.BatchUpdateAsync(u => u.TrialId == trialId, t => new VisitStage() { IsConfirmed = true, IsHaveFirstConfirmed = true });
var stat = new VisitPlanInfluenceStat() { TrialId = trialId }; var stat = new VisitPlanInfluenceStat() { TrialId = trialId };
@ -479,8 +423,9 @@ namespace IRaCIS.Application.Services
CreateTime = createtime, CreateTime = createtime,
SubjectVisitName = x.VisitName, SubjectVisitName = x.VisitName,
TrialId = x.TrialId, TrialId = x.TrialId,
Reason="确认访视修改状态", Reason = "确认访视修改状态",
JsonDetail = JsonConvert.SerializeObject(new { JsonDetail = JsonConvert.SerializeObject(new
{
IsBaseLine = changedItem.IsBaseLine, IsBaseLine = changedItem.IsBaseLine,
VisitName = changedItem.VisitName, VisitName = changedItem.VisitName,
VisitNum = changedItem.VisitNum, VisitNum = changedItem.VisitNum,
@ -519,7 +464,7 @@ namespace IRaCIS.Application.Services
var trial =await _repository.GetQueryable<Trial>().FirstOrDefaultAsync(x => x.Id == trialId); var trial = await _repository.GetQueryable<Trial>().FirstOrDefaultAsync(x => x.Id == trialId);
addvisitStages.ForEach(x => addvisitStages.ForEach(x =>
@ -531,7 +476,7 @@ namespace IRaCIS.Application.Services
// //
datas.Add(new DataInspection() datas.Add(new DataInspection()
{ {
Id= dataindtid, Id = dataindtid,
BlindName = x.BlindName, BlindName = x.BlindName,
IsSign = false, IsSign = false,
SiteId = y.SiteId, SiteId = y.SiteId,
@ -547,14 +492,14 @@ namespace IRaCIS.Application.Services
VisitName = x.VisitName, VisitName = x.VisitName,
VisitNum = x.VisitNum, VisitNum = x.VisitNum,
VisitDay = x.VisitDay, VisitDay = x.VisitDay,
VisitExecuted=false, VisitExecuted = false,
BlindName=x.BlindName, BlindName = x.BlindName,
VisitWindowLeft = x.VisitWindowLeft, VisitWindowLeft = x.VisitWindowLeft,
VisitWindowRight = x.VisitWindowRight, VisitWindowRight = x.VisitWindowRight,
IsEnrollment=y.IsEnrollment, IsEnrollment = y.IsEnrollment,
IsUrgent = trial.IsSubjectExpeditedView, IsUrgent = trial.IsSubjectExpeditedView,
IsFinalVisit=false, IsFinalVisit = false,
IsLostVisit= false, IsLostVisit = false,
PDState = trial.IsPDProgressView, PDState = trial.IsPDProgressView,
}), }),
}); });
@ -570,7 +515,7 @@ namespace IRaCIS.Application.Services
ParentId = dataindtid, ParentId = dataindtid,
SubjectVisitName = x.VisitName, SubjectVisitName = x.VisitName,
IsSign = false, IsSign = false,
TrialId=x.TrialId, TrialId = x.TrialId,
CreateTime = createtime.AddMilliseconds(500), CreateTime = createtime.AddMilliseconds(500),
Identification = "Init|Visit|Status|Visit-Image Upload", Identification = "Init|Visit|Status|Visit-Image Upload",
JsonDetail = JsonConvert.SerializeObject(new JsonDetail = JsonConvert.SerializeObject(new
@ -599,12 +544,12 @@ namespace IRaCIS.Application.Services
SiteId = y.SiteId, SiteId = y.SiteId,
SubjectId = y.Id, SubjectId = y.Id,
Id = guid, Id = guid,
VisitName=x.VisitName, VisitName = x.VisitName,
BlindName=x.BlindName, BlindName = x.BlindName,
IsBaseLine=x.IsBaseLine, IsBaseLine = x.IsBaseLine,
IsCheckBack=x.IsBaseLine, IsCheckBack = x.IsBaseLine,
IsUrgent= trial.IsSubjectExpeditedView, IsUrgent = trial.IsSubjectExpeditedView,
}); });
@ -649,5 +594,30 @@ namespace IRaCIS.Application.Services
} }
/// <summary> 删除项目计划某一项 废弃 </summary>
[HttpDelete("{id:guid}/{trialId:guid}")]
[TrialAudit(AuditType.TrialAudit, AuditOptType.DeleteTrialVisitPlanItem)]
[TypeFilter(typeof(TrialResourceFilter))]
[Obsolete]
public async Task<IResponseOutput> DeleteVisitStage(Guid id)
{
var visitPlan = await _visitStageRepository.FirstOrDefaultAsync(t => t.Id == id);
if (visitPlan == null) return Null404NotFound(visitPlan);
if (await _repository.AnyAsync<SubjectVisit>(t => t.VisitName == visitPlan.VisitName && t.TrialId == visitPlan.TrialId && t.VisitExecuted == VisitExecutedEnum.Executed))
{
return ResponseOutput.NotOk("The visit plan has been assigned to the subjects and executed.");
}
await _repository.BatchDeleteAsync<SubjectVisit>(t => t.TrialId == visitPlan.TrialId && t.VisitName == visitPlan.VisitName);
var result = await _visitStageRepository.BatchDeleteAsync(u => u.Id == id);
return ResponseOutput.Result(result);
}
} }
} }

View File

@ -30,7 +30,8 @@ namespace IRaCIS.Core.Application.Service
CreateMap<SubjectStatusChangeCommand, Subject>(); CreateMap<SubjectStatusChangeCommand, Subject>()
.ForMember(d => d.Id, t => t.MapFrom(u=>u.SubjectId));
CreateMap<VisitStage, VisitStageDTO>(); CreateMap<VisitStage, VisitStageDTO>();
CreateMap<Subject, SubjectQueryView>() CreateMap<Subject, SubjectQueryView>()

View File

@ -0,0 +1,56 @@
using AutoMapper;
using EntityFrameworkCore.Triggered;
using IRaCIS.Core.Domain.Share;
using MassTransit;
namespace IRaCIS.Core.Application.Triggers
{
/// <summary>
/// 添加访视计划 要给改项目下的所有Subject 添加该访视
/// </summary>
public class AddVisitPlanTrigger : IAfterSaveTrigger<VisitStage>
{
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
private readonly IMapper _mapper;
public AddVisitPlanTrigger(IRepository<SubjectVisit> subjectVisitRepository,IMapper mapper)
{
_subjectVisitRepository = subjectVisitRepository;
_mapper = mapper;
}
public async Task AfterSave(ITriggerContext<VisitStage> context, CancellationToken cancellationToken)
{
var visitPlan = context.Entity;
if (context.ChangeType == ChangeType.Added)
{
//已添加受试者 都不存在该新增的计划名称 那么该项目所有受试者都增加一个访视记录
if (!await _subjectVisitRepository.AnyAsync(t => t.VisitName == visitPlan.VisitName && t.TrialId == visitPlan.TrialId))
{
var subjectSVS = await _subjectVisitRepository.Where(t => t.TrialId == visitPlan.TrialId).Select(t => new { t.SubjectId, t.SiteId, t.IsFinalVisit }).Distinct().ToListAsync();
var subjects = subjectSVS.Select(t => new { t.SubjectId, t.SiteId }).Distinct().ToList();
foreach (var subject in subjects)
{
var svItem = _mapper.Map<SubjectVisit>(visitPlan);
svItem.SiteId = subject.SiteId;
svItem.SubjectId = subject.SubjectId;
svItem.Id = NewId.NextGuid();
//设置了末次访视,那么加访视计划的时候,设置为不可用
if (subjectSVS.Any(t => t.SubjectId == svItem.SubjectId && t.IsFinalVisit))
{
svItem.VisitExecuted = VisitExecutedEnum.Unavailable;
}
await _subjectVisitRepository.AddAsync(svItem);
}
}
}
}
}
}

View File

@ -0,0 +1,65 @@
using AutoMapper;
using EntityFrameworkCore.Triggered;
using IRaCIS.Core.Domain.Share;
using MassTransit;
namespace IRaCIS.Core.Application.Triggers
{
/// <summary>
///
/// </summary>
public class SubjectStateTrigger : IAfterSaveTrigger<Subject>
{
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
private readonly IRepository _repository;
private readonly IMapper _mapper;
public SubjectStateTrigger(IRepository<SubjectVisit> subjectVisitRepository, IRepository repository, IMapper mapper)
{
_subjectVisitRepository = subjectVisitRepository;
_repository = repository;
_mapper = mapper;
}
public async Task AfterSave(ITriggerContext<Subject> context, CancellationToken cancellationToken)
{
if (context.ChangeType == ChangeType.Modified )
{
//Site变更
if ( context.Entity.SiteId != context.UnmodifiedEntity.SiteId)
{
var subjectId = context.Entity.Id;
var siteId = context.Entity.SiteId;
await _repository.BatchUpdateAsync<SubjectVisit>(t => t.SubjectId == subjectId, u => new SubjectVisit() { SiteId = siteId });
await _repository.BatchUpdateAsync<DicomStudy>(t => t.SubjectId == subjectId, u => new DicomStudy() { SiteId = siteId });
#region 废弃
////如果访视结束了 需要删除计划外未执行的访视
//if (mapedSubject.Status == SubjectStatus.EndOfVisit)
//{
// await _repository.DeleteFromQueryAsync<SubjectVisit>(t => t.VisitExecuted == VisitExecutedEnum.UnExecuted && t.SubjectId == mapedSubject.Id && t.InPlan == false);
//}
////如果是出组了 将受试者未执行的 设置为不可用
//if (mapedSubject.Status == SubjectStatus.OutOfEnrollment)
//{
// await _repository.UpdateFromQueryAsync<SubjectVisit>(t => t.SubjectId == mapedSubject.Id && t.VisitExecuted == VisitExecutedEnum.UnExecuted, u => new SubjectVisit() { VisitExecuted = VisitExecutedEnum.Unavailable });
//}
#endregion
}
}
}
}
}

View File

@ -35,7 +35,7 @@ namespace IRaCIS.Core.Infra.EFCore
/// <summary>批量删除EF跟踪方式所有查询出来再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary> /// <summary>批量删除EF跟踪方式所有查询出来再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary>
Task TrackingBatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter); Task<List<TEntity>> TrackingBatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter);
} }

View File

@ -242,7 +242,7 @@ namespace IRaCIS.Core.Infra.EFCore
/// <summary>批量删除EF跟踪方式所有查询出来再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary> /// <summary>批量删除EF跟踪方式所有查询出来再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary>
public async Task TrackingBatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter) public async Task<List<TEntity>> TrackingBatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter)
{ {
var waitDeleteList = await _dbSet.IgnoreQueryFilters().Where(deleteFilter).ToListAsync(); var waitDeleteList = await _dbSet.IgnoreQueryFilters().Where(deleteFilter).ToListAsync();
@ -250,6 +250,7 @@ namespace IRaCIS.Core.Infra.EFCore
{ {
await DeleteAsync(deleteItem, false); await DeleteAsync(deleteItem, false);
} }
return waitDeleteList;
} }