diff --git a/src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs b/src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs index eff2b38..1d3d3e5 100644 --- a/src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs +++ b/src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs @@ -1988,11 +1988,12 @@ namespace Shentun.Peis.DiagnosisFunctions if (registerCheckEnt != null) { registerCheckEnt.CriticalRangeValue = CriticalRangeValue; - registerCheckEnt.IsCriticalValue = isCriticalValue; + if (isCriticalValue == 'Y') { registerCheckEnt.CriticalValueCreatorId = _currentUser.Id; registerCheckEnt.CriticalValueCreationTime = DateTime.Now; + registerCheckEnt.IsCriticalValue = isCriticalValue; } registerCheckEnt.FollowUpCreatorId = _currentUser.Id; registerCheckEnt.FollowUpCreationTime = DateTime.Now; diff --git a/src/Shentun.Peis.Application/FollowUps/FollowUpAppService.cs b/src/Shentun.Peis.Application/FollowUps/FollowUpAppService.cs index 43c63ec..794690a 100644 --- a/src/Shentun.Peis.Application/FollowUps/FollowUpAppService.cs +++ b/src/Shentun.Peis.Application/FollowUps/FollowUpAppService.cs @@ -27,6 +27,8 @@ namespace Shentun.Peis.FollowUps private readonly IRepository _smsSendRepository; private readonly SmsSendAppService _smsSendAppService; private readonly IRepository _patientRegisterRepository; + private readonly IRepository _registerCheckRepository; + private readonly IRepository _registerCheckItemRepository; public FollowUpAppService( IRepository followUpRepository, CacheService cacheService, @@ -34,7 +36,9 @@ namespace Shentun.Peis.FollowUps IRepository phoneFollowUpRepository, IRepository smsSendRepository, SmsSendAppService smsSendAppService, - IRepository patientRegisterRepository) + IRepository patientRegisterRepository, + IRepository registerCheckRepository, + IRepository registerCheckItemRepository) { _followUpRepository = followUpRepository; _cacheService = cacheService; @@ -43,6 +47,8 @@ namespace Shentun.Peis.FollowUps _smsSendRepository = smsSendRepository; _smsSendAppService = smsSendAppService; _patientRegisterRepository = patientRegisterRepository; + _registerCheckRepository = registerCheckRepository; + _registerCheckItemRepository = registerCheckItemRepository; } /// @@ -77,42 +83,58 @@ namespace Shentun.Peis.FollowUps /// 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); } } } diff --git a/src/Shentun.Peis.Application/RegisterCheckItems/RegisterCheckItemAppService.cs b/src/Shentun.Peis.Application/RegisterCheckItems/RegisterCheckItemAppService.cs index 0f4b796..c38a2a3 100644 --- a/src/Shentun.Peis.Application/RegisterCheckItems/RegisterCheckItemAppService.cs +++ b/src/Shentun.Peis.Application/RegisterCheckItems/RegisterCheckItemAppService.cs @@ -409,7 +409,7 @@ namespace Shentun.Peis.RegisterCheckItems } - + if (input.IsCriticalValue == 'Y' && registerCheckItemEnt.CriticalValueCreatorId == null) { registerCheckItemEnt.CriticalValueCreatorId = _currentUser.Id; @@ -444,11 +444,20 @@ namespace Shentun.Peis.RegisterCheckItems } else { - //删除随访表记录 - await _followUpAppService.DeleteByPatientRegisterId(new PatientRegisterIdInputDto + var registerCheckItemCount = await _registerCheckItemRepository.CountAsync(c => c.RegisterCheckId == input.RegisterCheckId && (c.IsFollowUp == 'Y' || c.IsCriticalValue == 'Y')); + if (registerCheckItemCount == 0) { - PatientRegisterId = registerCheckEnt.PatientRegisterId - }); + //更新registerCheck + registerCheckEnt.IsCriticalValue = registerCheckItemEnt.IsCriticalValue; + registerCheckEnt.IsFollowUp= registerCheckItemEnt.IsFollowUp; + await _registerCheckRepository.UpdateAsync(registerCheckEnt); + + //删除随访表记录 + await _followUpAppService.DeleteByPatientRegisterId(new PatientRegisterIdInputDto + { + PatientRegisterId = registerCheckEnt.PatientRegisterId + }); + } } } diff --git a/src/Shentun.Peis.Application/RegisterChecks/RegisterCheckAppService.cs b/src/Shentun.Peis.Application/RegisterChecks/RegisterCheckAppService.cs index d282910..4c36fac 100644 --- a/src/Shentun.Peis.Application/RegisterChecks/RegisterCheckAppService.cs +++ b/src/Shentun.Peis.Application/RegisterChecks/RegisterCheckAppService.cs @@ -736,6 +736,18 @@ namespace Shentun.Peis.RegisterChecks } else { + + #region 更新明细项目的危急值跟随访值状态 + var registerCheckItemList = await _registerCheckItemRepository.GetListAsync(m => m.RegisterCheckId == input.RegisterCheckId); + foreach (var registerCheckItem in registerCheckItemList) + { + registerCheckItem.IsCriticalValue = registerCheckEnt.IsCriticalValue; + registerCheckItem.IsFollowUp = registerCheckEnt.IsFollowUp; + } + + await _registerCheckItemRepository.UpdateManyAsync(registerCheckItemList); + #endregion + //删除随访表记录 await _followUpAppService.DeleteByPatientRegisterId(new PatientRegisterIdInputDto {