|
|
|
@ -27,6 +27,8 @@ namespace Shentun.Peis.FollowUps |
|
|
|
private readonly IRepository<SmsSend, Guid> _smsSendRepository; |
|
|
|
private readonly SmsSendAppService _smsSendAppService; |
|
|
|
private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository; |
|
|
|
private readonly IRepository<RegisterCheck, Guid> _registerCheckRepository; |
|
|
|
private readonly IRepository<RegisterCheckItem> _registerCheckItemRepository; |
|
|
|
public FollowUpAppService( |
|
|
|
IRepository<FollowUp, Guid> followUpRepository, |
|
|
|
CacheService cacheService, |
|
|
|
@ -34,7 +36,9 @@ namespace Shentun.Peis.FollowUps |
|
|
|
IRepository<PhoneFollowUp, Guid> phoneFollowUpRepository, |
|
|
|
IRepository<SmsSend, Guid> smsSendRepository, |
|
|
|
SmsSendAppService smsSendAppService, |
|
|
|
IRepository<PatientRegister, Guid> patientRegisterRepository) |
|
|
|
IRepository<PatientRegister, Guid> patientRegisterRepository, |
|
|
|
IRepository<RegisterCheck, Guid> registerCheckRepository, |
|
|
|
IRepository<RegisterCheckItem> registerCheckItemRepository) |
|
|
|
{ |
|
|
|
_followUpRepository = followUpRepository; |
|
|
|
_cacheService = cacheService; |
|
|
|
@ -43,6 +47,8 @@ namespace Shentun.Peis.FollowUps |
|
|
|
_smsSendRepository = smsSendRepository; |
|
|
|
_smsSendAppService = smsSendAppService; |
|
|
|
_patientRegisterRepository = patientRegisterRepository; |
|
|
|
_registerCheckRepository = registerCheckRepository; |
|
|
|
_registerCheckItemRepository = registerCheckItemRepository; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -77,42 +83,58 @@ namespace Shentun.Peis.FollowUps |
|
|
|
/// <returns></returns>
|
|
|
|
public async Task DeleteByPatientRegisterId(PatientRegisterIdInputDto input) |
|
|
|
{ |
|
|
|
var isFollowUp = await _followUpRepository.FirstOrDefaultAsync(f => f.PatientRegisterId == input.PatientRegisterId); |
|
|
|
if (isFollowUp != null) |
|
|
|
//检查是否所有项目都没有
|
|
|
|
|
|
|
|
var isFollowUpDelete = (from patientRegister in await _patientRegisterRepository.GetQueryableAsync() |
|
|
|
join registerCheck in await _registerCheckRepository.GetQueryableAsync() on patientRegister.Id equals registerCheck.PatientRegisterId |
|
|
|
join registerCheckItem in await _registerCheckItemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckItem.RegisterCheckId |
|
|
|
where patientRegister.Id == input.PatientRegisterId |
|
|
|
&& (registerCheck.IsFollowUp == 'Y' |
|
|
|
|| registerCheck.IsCriticalValue == 'Y' |
|
|
|
|| registerCheckItem.IsCriticalValue == 'Y' |
|
|
|
|| registerCheckItem.IsFollowUp == 'Y') |
|
|
|
select patientRegister.Id |
|
|
|
).Count(); |
|
|
|
|
|
|
|
if (isFollowUpDelete == 0) |
|
|
|
{ |
|
|
|
var phoneFollowUpList = await _phoneFollowUpRepository.GetListAsync(m => m.FollowUpId == isFollowUp.Id); |
|
|
|
var smsSendList = await _smsSendRepository.GetListAsync(m => m.FollowUpId == isFollowUp.Id); |
|
|
|
bool isDelete = true; //是否需要删除
|
|
|
|
if (phoneFollowUpList.Any()) |
|
|
|
var isFollowUp = await _followUpRepository.FirstOrDefaultAsync(f => f.PatientRegisterId == input.PatientRegisterId); |
|
|
|
if (isFollowUp != null) |
|
|
|
{ |
|
|
|
isDelete = false; |
|
|
|
phoneFollowUpList = phoneFollowUpList.Where(m => m.PlanFollowDate > DateTime.Now).ToList(); |
|
|
|
var phoneFollowUpList = await _phoneFollowUpRepository.GetListAsync(m => m.FollowUpId == isFollowUp.Id); |
|
|
|
var smsSendList = await _smsSendRepository.GetListAsync(m => m.FollowUpId == isFollowUp.Id); |
|
|
|
bool isDelete = true; //是否需要删除
|
|
|
|
if (phoneFollowUpList.Any()) |
|
|
|
{ |
|
|
|
await _phoneFollowUpRepository.DeleteManyAsync(phoneFollowUpList); |
|
|
|
isDelete = false; |
|
|
|
phoneFollowUpList = phoneFollowUpList.Where(m => m.PlanFollowDate > DateTime.Now).ToList(); |
|
|
|
if (phoneFollowUpList.Any()) |
|
|
|
{ |
|
|
|
await _phoneFollowUpRepository.DeleteManyAsync(phoneFollowUpList); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (smsSendList.Any()) |
|
|
|
{ |
|
|
|
isDelete = false; |
|
|
|
smsSendList = smsSendList.Where(m => m.PlanSendDate > DateTime.Now).ToList(); |
|
|
|
if (smsSendList.Any()) |
|
|
|
{ |
|
|
|
await _smsSendRepository.DeleteManyAsync(smsSendList); |
|
|
|
//删除任务计划
|
|
|
|
var patientRegisterEnt = await _patientRegisterRepository.FirstOrDefaultAsync(f => f.Id == input.PatientRegisterId); |
|
|
|
if (patientRegisterEnt != null) |
|
|
|
isDelete = false; |
|
|
|
smsSendList = smsSendList.Where(m => m.PlanSendDate > DateTime.Now).ToList(); |
|
|
|
if (smsSendList.Any()) |
|
|
|
{ |
|
|
|
await _smsSendAppService.DeleteCriticalSmsAsync(patientRegisterEnt, smsSendList.First().Content); |
|
|
|
} |
|
|
|
await _smsSendRepository.DeleteManyAsync(smsSendList); |
|
|
|
//删除任务计划
|
|
|
|
var patientRegisterEnt = await _patientRegisterRepository.FirstOrDefaultAsync(f => f.Id == input.PatientRegisterId); |
|
|
|
if (patientRegisterEnt != null) |
|
|
|
{ |
|
|
|
await _smsSendAppService.DeleteCriticalSmsAsync(patientRegisterEnt, smsSendList.First().Content); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (isDelete) |
|
|
|
{ |
|
|
|
await _followUpRepository.DeleteAsync(isFollowUp); |
|
|
|
} |
|
|
|
} |
|
|
|
if (isDelete) |
|
|
|
{ |
|
|
|
await _followUpRepository.DeleteAsync(isFollowUp); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|