Browse Source

随访记录

master
wxd 1 year ago
parent
commit
de2d8210d7
  1. 14
      src/Shentun.Peis.Application.Contracts/PhoneFollowUps/CreatePhoneFollowUpDto.cs
  2. 37
      src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpDto.cs
  3. 12
      src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpIdInputDto.cs
  4. 35
      src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpListInputDto.cs
  5. 11
      src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpWithPatientRegisterDto.cs
  6. 35
      src/Shentun.Peis.Application.Contracts/PhoneFollowUps/UpdatePhoneFollowUpDto.cs
  7. 31
      src/Shentun.Peis.Application.Contracts/SmsSends/CreateSmsSendDto.cs
  8. 51
      src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendDto.cs
  9. 11
      src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendIdInputDto.cs
  10. 44
      src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendListInputDto.cs
  11. 9
      src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs
  12. 259
      src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs
  13. 1
      src/Shentun.Peis.Application/Shentun.Peis.Application.csproj
  14. 276
      src/Shentun.Peis.Application/SmsSends/SmsSendAppService.cs
  15. 40
      src/Shentun.Peis.Domain.Shared/Enums/FollowUpModeFlag.cs
  16. 5
      src/Shentun.Peis.Domain/PhoneFollowUps/PhoneFollowUp.cs
  17. 7
      src/Shentun.Peis.Domain/SmsSends/SmsSend.cs

14
src/Shentun.Peis.Application.Contracts/PhoneFollowUps/CreatePhoneFollowUpDto.cs

@ -9,9 +9,19 @@ namespace Shentun.Peis.PhoneFollowUps
public class CreatePhoneFollowUpDto
{
/// <summary>
/// 表达式
/// 0-corn表达式 1-按天 2-按周 3-按月 4-按年
/// </summary>
public string CornValue { get; set; }
public char FollowUpMode { get; set; } = '0';
/// <summary>
/// FollowUpMode为0时 为corn表达式 其他模式为具体数字
/// </summary>
public string ModeValue { get; set; }
/// <summary>
/// 截止时间
/// </summary>
public string EndDate { get; set; }
/// <summary>
/// 随访主表ID

37
src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpDto.cs

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Shentun.Peis.PhoneFollowUps
{
public class PhoneFollowUpDto : AuditedEntityDtoName
{
/// <summary>
/// 随访内容
/// </summary>
public string FollowUpContent { get; set; }
/// <summary>
/// 回复内容
/// </summary>
public string ReplyContent { get; set; }
/// <summary>
/// 随访ID
/// </summary>
public Guid FollowUpId { get; set; }
/// <summary>
/// 随访日期
/// </summary>
public string PlanFollowDate { get; set; }
/// <summary>
/// 是否完成
/// </summary>
public char IsComplete { get; set; }
}
}

12
src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpIdInputDto.cs

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.PhoneFollowUps
{
public class PhoneFollowUpIdInputDto
{
public Guid PhoneFollowUpId { get; set; }
}
}

35
src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpListInputDto.cs

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.PhoneFollowUps
{
public class PhoneFollowUpListInputDto
{
/// <summary>
/// 随访ID
/// </summary>
public Guid? FollowUpId { get; set; }
/// <summary>
/// 随访内容、回复内容 支持模糊查询
/// </summary>
public string KeyWord { get; set; }
/// <summary>
/// 随访日期 格式1999-01-01
/// </summary>
public string StartDate { get; set; }
/// <summary>
/// 随访日期 格式1999-01-01
/// </summary>
public string EndDate { get; set; }
/// <summary>
/// 是否完成
/// </summary>
public char? IsComplete { get; set; }
}
}

11
src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpWithPatientRegisterDto.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.PhoneFollowUps
{
public class PhoneFollowUpWithPatientRegisterDto : PhoneFollowUpDto
{
public string PatientName { get; set; }
}
}

35
src/Shentun.Peis.Application.Contracts/PhoneFollowUps/UpdatePhoneFollowUpDto.cs

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Shentun.Peis.PhoneFollowUps
{
public class UpdatePhoneFollowUpDto
{
/// <summary>
/// 主键
/// </summary>
public Guid PhoneFollowUpId { get; set; }
/// <summary>
/// 随访内容
/// </summary>
public string FollowUpContent { get; set; }
/// <summary>
/// 回复内容
/// </summary>
public string ReplyContent { get; set; }
/// <summary>
/// 随访日期
/// </summary>
public DateTime? PlanFollowDate { get; set; }
/// <summary>
/// 是否完成
/// </summary>
public char IsComplete { get; set; }
}
}

31
src/Shentun.Peis.Application.Contracts/SmsSends/CreateSmsSendDto.cs

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.SmsSends
{
public class CreateSmsSendDto
{
/// <summary>
/// 0-corn表达式 1-按天 2-按周 3-按月 4-按年
/// </summary>
public char FollowUpMode { get; set; } = '0';
/// <summary>
/// FollowUpMode为0时 为corn表达式 其他模式为具体数字
/// </summary>
public string ModeValue { get; set; }
/// <summary>
/// 截止时间
/// </summary>
public string EndDate { get; set; }
/// <summary>
/// 随访主表ID
/// </summary>
public Guid FollowUpId { get; set; }
}
}

51
src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendDto.cs

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Shentun.Peis.SmsSends
{
public class SmsSendDto : AuditedEntityDtoName
{
/// <summary>
/// 短信类别ID
/// </summary>
public string SmsTypeId { get; set; }
/// <summary>
/// 随访ID
/// </summary>
public Guid FollowUpId { get; set; }
/// <summary>
/// 人员ID
/// </summary>
public Guid? PatientId { get; set; }
/// <summary>
/// 姓名
/// </summary>
public string PatientName { get; set; }
/// <summary>
/// 手机号
/// </summary>
public string MobileTelephone { get; set; }
/// <summary>
/// 短信内容 默认一个姓名
/// </summary>
public string Content { get; set; }
/// <summary>
/// 是完成
/// </summary>
public char IsComplete { get; set; }
/// <summary>
/// 短信推送时间
/// </summary>
public string PlanSendDate { get; set; }
}
}

11
src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendIdInputDto.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.SmsSends
{
public class SmsSendIdInputDto
{
public Guid SmsSendId { get; set; }
}
}

44
src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendListInputDto.cs

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Shentun.Peis.SmsSends
{
public class SmsSendListInputDto
{
/// <summary>
/// 随访ID
/// </summary>
public Guid? FollowUpId { get; set; }
/// <summary>
/// 姓名
/// </summary>
public string PatientName { get; set; }
/// <summary>
/// 手机号
/// </summary>
public string MobileTelephone { get; set; }
/// <summary>
/// 是完成
/// </summary>
public char? IsComplete { get; set; }
/// <summary>
/// 随访日期 格式1999-01-01
/// </summary>
public string StartDate { get; set; }
/// <summary>
/// 随访日期 格式1999-01-01
/// </summary>
public string EndDate { get; set; }
}
}

9
src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs

@ -63,6 +63,7 @@ using Shentun.Peis.PatientRegisters;
using Shentun.Peis.Patients;
using Shentun.Peis.PayModes;
using Shentun.Peis.PersonnelTypes;
using Shentun.Peis.PhoneFollowUps;
using Shentun.Peis.Poisons;
using Shentun.Peis.PoisonTypes;
using Shentun.Peis.PriceItems;
@ -87,6 +88,7 @@ using Shentun.Peis.SampleTypes;
using Shentun.Peis.SexHormoneReferenceRanges;
using Shentun.Peis.SexHormoneTerms;
using Shentun.Peis.Sexs;
using Shentun.Peis.SmsSends;
using Shentun.Peis.SumSummaryReports;
using Shentun.Peis.SuspectedOccupationalDiseases;
using Shentun.Peis.Symptoms;
@ -591,5 +593,12 @@ public class PeisApplicationAutoMapperProfile : Profile
CreateMap<CreateCriticalFollowValueDto, CriticalFollowValue>();
CreateMap<UpdateCriticalFollowValueDto, CriticalFollowValue>();
CreateMap<PhoneFollowUp, PhoneFollowUpDto>();
CreateMap<UpdatePhoneFollowUpDto, PhoneFollowUp>();
CreateMap<SmsSend, SmsSendDto>();
}
}

259
src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs

@ -1,13 +1,19 @@
using Microsoft.AspNetCore.Authorization;
using Cronos;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.CriticalFollowValues;
using Shentun.Peis.Enums;
using Shentun.Peis.Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;
namespace Shentun.Peis.PhoneFollowUps
{
@ -19,21 +25,252 @@ namespace Shentun.Peis.PhoneFollowUps
public class PhoneFollowUpAppService : ApplicationService
{
private readonly IRepository<PhoneFollowUp, Guid> _phoneFollowUpRepository;
private readonly CacheService _cacheService;
private readonly IRepository<FollowUp, Guid> _followUpRepository;
private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository;
public PhoneFollowUpAppService(IRepository<PhoneFollowUp, Guid> phoneFollowUpRepository)
public PhoneFollowUpAppService(
IRepository<PhoneFollowUp, Guid> phoneFollowUpRepository,
CacheService cacheService,
IRepository<FollowUp, Guid> followUpRepository,
IRepository<PatientRegister, Guid> patientRegisterRepository
)
{
_phoneFollowUpRepository = phoneFollowUpRepository;
_cacheService = cacheService;
_followUpRepository = followUpRepository;
_patientRegisterRepository = patientRegisterRepository;
}
///// <summary>
///// 创建电话随访记录
///// </summary>
///// <param name="input"></param>
///// <returns></returns>
//public async Task CreateAsync(CreatePhoneFollowUpDto input)
//{
//}
/// <summary>
/// 获取电话随访记录信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/PhoneFollowUp/Get")]
public async Task<PhoneFollowUpDto> GetAsync(PhoneFollowUpIdInputDto input)
{
var phoneFollowUpEnt = await _phoneFollowUpRepository.GetAsync(input.PhoneFollowUpId);
var entityDto = ObjectMapper.Map<PhoneFollowUp, PhoneFollowUpDto>(phoneFollowUpEnt);
entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
return entityDto;
}
/// <summary>
/// 获取电话随访记录信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/PhoneFollowUp/GetList")]
public async Task<List<PhoneFollowUpWithPatientRegisterDto>> GetListAsync(PhoneFollowUpListInputDto input)
{
var query = from phoneFollowUp in await _phoneFollowUpRepository.GetQueryableAsync()
join followUp in await _followUpRepository.GetQueryableAsync() on phoneFollowUp.FollowUpId equals followUp.Id
join patientRegister in await _patientRegisterRepository.GetQueryableAsync() on followUp.PatientRegisterId equals patientRegister.Id
orderby patientRegister.Id, phoneFollowUp.PlanFollowDate
select new
{
patientName = patientRegister.PatientName,
phoneFollowUp
};
if (input.FollowUpId != null)
{
query = query.Where(m => m.phoneFollowUp.FollowUpId == input.FollowUpId);
}
if (!string.IsNullOrWhiteSpace(input.KeyWord))
{
query = query.Where(m => (!string.IsNullOrWhiteSpace(m.phoneFollowUp.FollowUpContent) && m.phoneFollowUp.FollowUpContent.Contains(input.KeyWord))
|| (!string.IsNullOrWhiteSpace(m.phoneFollowUp.ReplyContent) && m.phoneFollowUp.ReplyContent.Contains(input.KeyWord))
);
}
if (input.IsComplete != null)
{
query = query.Where(m => m.phoneFollowUp.IsComplete == input.IsComplete);
}
if (!string.IsNullOrWhiteSpace(input.StartDate) && !string.IsNullOrWhiteSpace(input.EndDate))
{
query = query.Where(m => m.phoneFollowUp.PlanFollowDate >= Convert.ToDateTime(input.StartDate)
&& m.phoneFollowUp.PlanFollowDate <= Convert.ToDateTime(input.EndDate).AddDays(1));
}
var entListDto = query.ToList().Select(s => new PhoneFollowUpWithPatientRegisterDto
{
FollowUpId = s.phoneFollowUp.FollowUpId,
CreationTime = s.phoneFollowUp.CreationTime,
ReplyContent = s.phoneFollowUp.ReplyContent,
PlanFollowDate = DataHelper.ConversionDateToString(s.phoneFollowUp.PlanFollowDate),
CreatorId = s.phoneFollowUp.CreatorId,
FollowUpContent = s.phoneFollowUp.ReplyContent,
Id = s.phoneFollowUp.Id,
IsComplete = s.phoneFollowUp.IsComplete,
LastModificationTime = s.phoneFollowUp.LastModificationTime,
LastModifierId = s.phoneFollowUp.LastModifierId,
CreatorName = _cacheService.GetSurnameAsync(s.phoneFollowUp.CreatorId).GetAwaiter().GetResult(),
LastModifierName = _cacheService.GetSurnameAsync(s.phoneFollowUp.LastModifierId).GetAwaiter().GetResult(),
PatientName = s.patientName
}).ToList();
return entListDto;
}
/// <summary>
/// 创建电话随访记录
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/PhoneFollowUp/Create")]
public async Task CreateAsync(CreatePhoneFollowUpDto input)
{
if (string.IsNullOrWhiteSpace(input.ModeValue))
{
throw new UserFriendlyException("计划周期不能为空");
}
if (input.FollowUpMode == FollowUpModeFlag.Corn && string.IsNullOrWhiteSpace(input.EndDate))
{
throw new UserFriendlyException("采用corn表达式时需要截止日期");
}
var isPhoneFollowUp = await _phoneFollowUpRepository.CountAsync(c => c.FollowUpId == input.FollowUpId);
if (isPhoneFollowUp > 0)
{
throw new UserFriendlyException("已存在电话随访记录,不允许重复生成");
}
List<PhoneFollowUp> phoneFollowUpList = new List<PhoneFollowUp>();
if (input.FollowUpMode == FollowUpModeFlag.Corn)
{
//corn表达式
#region 解析Cron表达式
try
{
var schedule = CronExpression.Parse(input.ModeValue, CronFormat.IncludeSeconds);
var occurrences = schedule.GetOccurrences(DateTime.UtcNow, Convert.ToDateTime(input.EndDate).ToUniversalTime()); //获取截止时间前所有的计划时间
foreach (var occurrence in occurrences)
{
var phoneFollowUpEntity = new PhoneFollowUp(GuidGenerator.Create())
{
FollowUpContent = input.FollowUpContent,
FollowUpId = input.FollowUpId,
ReplyContent = input.ReplyContent,
PlanFollowDate = occurrence,
IsComplete = 'N'
};
phoneFollowUpList.Add(phoneFollowUpEntity);
}
}
catch (Exception ex)
{
throw new UserFriendlyException("Corn表达式不正确");
}
#endregion
}
else
{
//其他模式
int planCount = 0;
try
{
planCount = Convert.ToInt32(input.ModeValue);
}
catch (Exception ex)
{
throw new UserFriendlyException("Corn表达式不正确");
}
for (int i = 0; i < planCount; i++)
{
DateTime planFollowDate = DateTime.Now;
if (input.FollowUpMode == FollowUpModeFlag.Day)
{
planFollowDate = planFollowDate.AddDays(i);
}
else if (input.FollowUpMode == FollowUpModeFlag.Week)
{
planFollowDate = planFollowDate.AddDays(7 * i);
}
else if (input.FollowUpMode == FollowUpModeFlag.Month)
{
planFollowDate = planFollowDate.AddMonths(i);
}
else if (input.FollowUpMode == FollowUpModeFlag.Year)
{
planFollowDate = planFollowDate.AddYears(i);
}
var phoneFollowUpEntity = new PhoneFollowUp(GuidGenerator.Create())
{
FollowUpContent = input.FollowUpContent,
FollowUpId = input.FollowUpId,
ReplyContent = input.ReplyContent,
PlanFollowDate = planFollowDate,
IsComplete = 'N'
};
phoneFollowUpList.Add(phoneFollowUpEntity);
}
}
if (phoneFollowUpList.Any())
{
await _phoneFollowUpRepository.InsertManyAsync(phoneFollowUpList);
}
}
/// <summary>
/// 修改电话随访记录
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/PhoneFollowUp/Update")]
public async Task UpdateAsync(UpdatePhoneFollowUpDto input)
{
var entity = await _phoneFollowUpRepository.GetAsync(input.PhoneFollowUpId);
entity.IsComplete = input.IsComplete;
if (input.PlanFollowDate != null)
{
entity.PlanFollowDate = Convert.ToDateTime(input.PlanFollowDate);
}
if (!string.IsNullOrWhiteSpace(input.ReplyContent))
{
entity.ReplyContent = input.ReplyContent;
}
if (!string.IsNullOrWhiteSpace(input.FollowUpContent))
{
entity.FollowUpContent = input.FollowUpContent;
}
await _phoneFollowUpRepository.UpdateAsync(entity);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/PhoneFollowUp/Delete")]
public async Task DeleteAsync(PhoneFollowUpIdInputDto input)
{
await _phoneFollowUpRepository.DeleteAsync(input.PhoneFollowUpId);
}
}
}

1
src/Shentun.Peis.Application/Shentun.Peis.Application.csproj

@ -27,6 +27,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Cronos" Version="0.8.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.153-preview12" />
<PackageReference Include="System.DirectoryServices" Version="8.0.0" />

276
src/Shentun.Peis.Application/SmsSends/SmsSendAppService.cs

@ -0,0 +1,276 @@
using Cronos;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.Enums;
using Shentun.Peis.Models;
using Shentun.Peis.SmsSends;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
namespace Shentun.Peis.SmsSends
{
/// <summary>
/// 短信随访记录
/// </summary>
[ApiExplorerSettings(GroupName = "Work")]
[Authorize]
public class SmsSendAppService : ApplicationService
{
private readonly IRepository<SmsSend, Guid> _smsSendRepository;
private readonly CacheService _cacheService;
private readonly IRepository<FollowUp, Guid> _followUpRepository;
private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository;
private readonly IRepository<Patient, Guid> _patientRepository;
public SmsSendAppService(
CacheService cacheService,
IRepository<FollowUp, Guid> followUpRepository,
IRepository<PatientRegister, Guid> patientRegisterRepository,
IRepository<SmsSend, Guid> smsSendRepository,
IRepository<Patient, Guid> patientRepository)
{
_cacheService = cacheService;
_followUpRepository = followUpRepository;
_patientRegisterRepository = patientRegisterRepository;
_smsSendRepository = smsSendRepository;
_patientRepository = patientRepository;
}
/// <summary>
/// 获取短信随访记录信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/SmsSend/Get")]
public async Task<SmsSendDto> GetAsync(SmsSendIdInputDto input)
{
var smsSendEnt = await _smsSendRepository.GetAsync(input.SmsSendId);
var entityDto = ObjectMapper.Map<SmsSend, SmsSendDto>(smsSendEnt);
entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
return entityDto;
}
/// <summary>
/// 获取短信随访记录信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/SmsSend/GetList")]
public async Task<List<SmsSendDto>> GetListAsync(SmsSendListInputDto input)
{
var query = from smsSend in await _smsSendRepository.GetQueryableAsync()
orderby smsSend.FollowUpId, smsSend.PlanSendDate
select new
{
smsSend
};
if (input.FollowUpId != null)
{
query = query.Where(m => m.smsSend.FollowUpId == input.FollowUpId);
}
if (!string.IsNullOrWhiteSpace(input.PatientName))
{
query = query.Where(m => !string.IsNullOrWhiteSpace(m.smsSend.PatientName) && m.smsSend.PatientName.Contains(input.PatientName));
}
if (!string.IsNullOrWhiteSpace(input.MobileTelephone))
{
query = query.Where(m => !string.IsNullOrWhiteSpace(m.smsSend.MobileTelephone) && m.smsSend.MobileTelephone.Contains(input.MobileTelephone));
}
if (input.IsComplete != null)
{
query = query.Where(m => m.smsSend.IsComplete == input.IsComplete);
}
if (!string.IsNullOrWhiteSpace(input.StartDate) && !string.IsNullOrWhiteSpace(input.EndDate))
{
query = query.Where(m => m.smsSend.PlanSendDate >= Convert.ToDateTime(input.StartDate)
&& m.smsSend.PlanSendDate <= Convert.ToDateTime(input.EndDate).AddDays(1));
}
var entListDto = query.ToList().Select(s => new SmsSendDto
{
FollowUpId = s.smsSend.FollowUpId,
CreationTime = s.smsSend.CreationTime,
CreatorId = s.smsSend.CreatorId,
Id = s.smsSend.Id,
IsComplete = s.smsSend.IsComplete,
LastModificationTime = s.smsSend.LastModificationTime,
LastModifierId = s.smsSend.LastModifierId,
CreatorName = _cacheService.GetSurnameAsync(s.smsSend.CreatorId).GetAwaiter().GetResult(),
LastModifierName = _cacheService.GetSurnameAsync(s.smsSend.LastModifierId).GetAwaiter().GetResult(),
PatientName = s.smsSend.PatientName,
Content = s.smsSend.Content,
MobileTelephone = s.smsSend.MobileTelephone,
PlanSendDate = DataHelper.ConversionDateToString(s.smsSend.PlanSendDate),
PatientId = s.smsSend.PatientId,
SmsTypeId = s.smsSend.SmsTypeId
}).ToList();
return entListDto;
}
/// <summary>
/// 创建短信随访记录
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/SmsSend/Create")]
public async Task CreateAsync(CreateSmsSendDto input)
{
if (string.IsNullOrWhiteSpace(input.ModeValue))
{
throw new UserFriendlyException("计划周期不能为空");
}
if (input.FollowUpMode == FollowUpModeFlag.Corn && string.IsNullOrWhiteSpace(input.EndDate))
{
throw new UserFriendlyException("采用corn表达式时需要截止日期");
}
var isSmsSend = await _smsSendRepository.CountAsync(c => c.FollowUpId == input.FollowUpId);
if (isSmsSend > 0)
{
throw new UserFriendlyException("已存在短信随访记录,不允许重复生成");
}
List<SmsSend> smsSendList = new List<SmsSend>();
var patientRegisterEnt = (from followUp in await _followUpRepository.GetQueryableAsync()
join patientRegister in await _patientRegisterRepository.GetQueryableAsync()
on followUp.PatientRegisterId equals patientRegister.Id
join patient in await _patientRepository.GetQueryableAsync()
on patientRegister.PatientId equals patient.Id
where followUp.Id == input.FollowUpId
select new
{
patientName = patientRegister.PatientName,
mobileTelephone = patient.MobileTelephone,
patientId = patient.Id
}).FirstOrDefault();
if (patientRegisterEnt == null)
{
throw new UserFriendlyException("随访数据不存在");
}
if (input.FollowUpMode == FollowUpModeFlag.Corn)
{
//corn表达式
#region 解析Cron表达式
try
{
var schedule = CronExpression.Parse(input.ModeValue, CronFormat.IncludeSeconds);
var occurrences = schedule.GetOccurrences(DateTime.UtcNow, Convert.ToDateTime(input.EndDate).ToUniversalTime()); //获取截止时间前所有的计划时间
foreach (var occurrence in occurrences)
{
var smsSendEntity = new SmsSend(GuidGenerator.Create())
{
FollowUpId = input.FollowUpId,
Content = patientRegisterEnt.patientName,
MobileTelephone = patientRegisterEnt.mobileTelephone,
PatientName = patientRegisterEnt.patientName,
PatientId = patientRegisterEnt.patientId,
PlanSendDate = occurrence,
SmsTypeId = "01",
IsComplete = 'N'
};
smsSendList.Add(smsSendEntity);
}
}
catch (Exception ex)
{
throw new UserFriendlyException("Corn表达式不正确");
}
#endregion
}
else
{
//其他模式
int planCount = 0;
try
{
planCount = Convert.ToInt32(input.ModeValue);
}
catch (Exception ex)
{
throw new UserFriendlyException("Corn表达式不正确");
}
for (int i = 0; i < planCount; i++)
{
DateTime planFollowDate = DateTime.Now;
if (input.FollowUpMode == FollowUpModeFlag.Day)
{
planFollowDate = planFollowDate.AddDays(i);
}
else if (input.FollowUpMode == FollowUpModeFlag.Week)
{
planFollowDate = planFollowDate.AddDays(7 * i);
}
else if (input.FollowUpMode == FollowUpModeFlag.Month)
{
planFollowDate = planFollowDate.AddMonths(i);
}
else if (input.FollowUpMode == FollowUpModeFlag.Year)
{
planFollowDate = planFollowDate.AddYears(i);
}
var smsSendEntity = new SmsSend(GuidGenerator.Create())
{
FollowUpId = input.FollowUpId,
Content = patientRegisterEnt.patientName,
MobileTelephone = patientRegisterEnt.mobileTelephone,
PatientName = patientRegisterEnt.patientName,
PatientId = patientRegisterEnt.patientId,
PlanSendDate = planFollowDate,
SmsTypeId = "01",
IsComplete = 'N'
};
smsSendList.Add(smsSendEntity);
}
}
if (smsSendList.Any())
{
await _smsSendRepository.InsertManyAsync(smsSendList);
}
}
/// <summary>
/// 删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/SmsSend/Delete")]
public async Task DeleteAsync(SmsSendIdInputDto input)
{
await _smsSendRepository.DeleteAsync(input.SmsSendId);
}
}
}

40
src/Shentun.Peis.Domain.Shared/Enums/FollowUpModeFlag.cs

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace Shentun.Peis.Enums
{
public static class FollowUpModeFlag
{
/// <summary>
/// 按corn表达式生成
/// </summary>
[Description("按corn表达式生成")]
public const char Corn = '0';
/// <summary>
/// 按天生成
/// </summary>
[Description("按周生成")]
public const char Day = '1';
/// <summary>
/// 按周生成
/// </summary>
[Description("按周生成")]
public const char Week = '2';
/// <summary>
/// 按月生成
/// </summary>
[Description("按月生成")]
public const char Month = '3';
/// <summary>
/// 按年生成
/// </summary>
[Description("按年生成")]
public const char Year = '4';
}
}

5
src/Shentun.Peis.Domain/PhoneFollowUps/PhoneFollowUp.cs

@ -14,6 +14,11 @@ namespace Shentun.Peis.Models
[Table("phone_follow_up")]
public class PhoneFollowUp : AuditedEntity<Guid>, IHasConcurrencyStamp
{
public PhoneFollowUp(Guid id) : base(id)
{
}
///// <summary>
///// 病人登记ID
///// </summary>

7
src/Shentun.Peis.Domain/SmsSends/SmsSend.cs

@ -14,10 +14,11 @@ namespace Shentun.Peis.Models
[Table("sms_send")]
public class SmsSend : AuditedEntity<Guid>, IHasConcurrencyStamp
{
public SmsSend(Guid id) : base(id) { }
/// <summary>
/// 短信类别ID
/// 短信类别ID 随访-01
/// </summary>
[Column("sms_type_id")]
[StringLength(2)]
public string SmsTypeId { get; set; }
@ -26,7 +27,7 @@ namespace Shentun.Peis.Models
/// 随访ID
/// </summary>
[Column("follow_up_id")]
public Guid? FollowUpId { get; set; }
public Guid FollowUpId { get; set; }
///// <summary>
///// 随访计划ID

Loading…
Cancel
Save