You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
686 lines
36 KiB
686 lines
36 KiB
using Cronos;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Shentun.Peis.CriticalFollowValues;
|
|
using Shentun.Peis.CustomerOrgs;
|
|
using Shentun.Peis.Enums;
|
|
using Shentun.Peis.Models;
|
|
using Shentun.Peis.PatientRegisters;
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// 电话随访记录
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "Work")]
|
|
[Authorize]
|
|
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;
|
|
private readonly IRepository<RegisterCheck, Guid> _registerCheckRepository;
|
|
private readonly IRepository<RegisterCheckItem> _registerCheckItemRepository;
|
|
private readonly IRepository<RegisterCheckAsbitem, Guid> _registerCheckAsbitemRepository;
|
|
private readonly IRepository<Asbitem, Guid> _asbitemRepository;
|
|
private readonly IRepository<Item, Guid> _itemRepository;
|
|
private readonly IRepository<Patient, Guid> _patientRepository;
|
|
private readonly CustomerOrgManager _customerOrgManager;
|
|
private readonly IRepository<RegisterCheckSummary, Guid> _registerCheckSummaryRepository;
|
|
|
|
public PhoneFollowUpAppService(
|
|
IRepository<PhoneFollowUp, Guid> phoneFollowUpRepository,
|
|
CacheService cacheService,
|
|
IRepository<FollowUp, Guid> followUpRepository,
|
|
IRepository<PatientRegister, Guid> patientRegisterRepository,
|
|
IRepository<RegisterCheck, Guid> registerCheckRepository,
|
|
IRepository<RegisterCheckItem> registerCheckItemRepository,
|
|
IRepository<RegisterCheckAsbitem, Guid> registerCheckAsbitemRepository,
|
|
IRepository<Asbitem, Guid> asbitemRepository,
|
|
IRepository<Item, Guid> itemRepository,
|
|
IRepository<Patient, Guid> patientRepository,
|
|
CustomerOrgManager customerOrgManager,
|
|
IRepository<RegisterCheckSummary, Guid> registerCheckSummaryRepository)
|
|
{
|
|
_phoneFollowUpRepository = phoneFollowUpRepository;
|
|
_cacheService = cacheService;
|
|
_followUpRepository = followUpRepository;
|
|
_patientRegisterRepository = patientRegisterRepository;
|
|
_registerCheckRepository = registerCheckRepository;
|
|
_registerCheckItemRepository = registerCheckItemRepository;
|
|
_registerCheckAsbitemRepository = registerCheckAsbitemRepository;
|
|
_asbitemRepository = asbitemRepository;
|
|
_itemRepository = itemRepository;
|
|
_patientRepository = patientRepository;
|
|
_customerOrgManager = customerOrgManager;
|
|
_registerCheckSummaryRepository = registerCheckSummaryRepository;
|
|
}
|
|
|
|
|
|
/// <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.FollowUpContent,
|
|
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>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/PhoneFollowUp/GetPatientRegisterCriticalList")]
|
|
public async Task<List<PhoneFollowUpWithCriticalItemDto>> GetPatientRegisterCriticalListAsync(GetPatientRegisterCriticalListInputDto input)
|
|
{
|
|
var query = 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
|
|
join registerCheck in await _registerCheckRepository.GetQueryableAsync() on patientRegister.Id equals registerCheck.PatientRegisterId
|
|
join registerCheckAsbitem in await _registerCheckAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckAsbitem.RegisterCheckId
|
|
join asbitem in await _asbitemRepository.GetQueryableAsync() on registerCheckAsbitem.AsbitemId equals asbitem.Id
|
|
join registerCheckItem in await _registerCheckItemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckItem.RegisterCheckId
|
|
join item in await _itemRepository.GetQueryableAsync() on registerCheckItem.ItemId equals item.Id
|
|
join phoneFollowUp in await _phoneFollowUpRepository.GetQueryableAsync() on followUp.Id equals phoneFollowUp.FollowUpId into phoneFollowUpTemp
|
|
from phoneFollowUpEmpty in phoneFollowUpTemp.DefaultIfEmpty()
|
|
select new
|
|
{
|
|
patientRegister,
|
|
registerCheck,
|
|
asbitem,
|
|
registerCheckItem,
|
|
item,
|
|
followUp,
|
|
phoneFollowUpEmpty,
|
|
patient
|
|
};
|
|
|
|
|
|
|
|
#region 查询条件
|
|
|
|
if (!string.IsNullOrEmpty(input.PatientNo))
|
|
query = query.Where(m => m.patient.PatientNo == input.PatientNo);
|
|
|
|
if (!string.IsNullOrEmpty(input.IdNo))
|
|
query = query.Where(m => m.patient.IdNo == input.IdNo);
|
|
|
|
if (!string.IsNullOrEmpty(input.PatientName))
|
|
query = query.Where(m => m.patientRegister.PatientName == input.PatientName);
|
|
|
|
if (!string.IsNullOrEmpty(input.PatientRegisterNo))
|
|
query = query.Where(m => m.patientRegister.PatientRegisterNo == input.PatientRegisterNo);
|
|
|
|
if (!string.IsNullOrEmpty(input.Phone))
|
|
query = query.Where(m => m.patient.MobileTelephone == input.Phone || m.patient.Telephone == input.Phone);
|
|
|
|
if (input.SexId != null && input.SexId != ForSexFlag.All)
|
|
query = query.Where(m => m.patientRegister.SexId == input.SexId);
|
|
|
|
if (!string.IsNullOrEmpty(input.StartDate) && !string.IsNullOrEmpty(input.EndDate))
|
|
{
|
|
if (input.DateType == '1')
|
|
{
|
|
query = query.Where(m => m.patientRegister.CreationTime >= Convert.ToDateTime(input.StartDate) &&
|
|
m.patientRegister.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1));
|
|
}
|
|
else if (input.DateType == '2')
|
|
{
|
|
query = query.Where(m => m.patientRegister.MedicalStartDate >= Convert.ToDateTime(input.StartDate) &&
|
|
m.patientRegister.MedicalStartDate < Convert.ToDateTime(input.EndDate).AddDays(1));
|
|
}
|
|
else
|
|
{
|
|
query = query.Where(m => (m.patientRegister.CreationTime >= Convert.ToDateTime(input.StartDate) &&
|
|
m.patientRegister.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1))
|
|
|| (m.patientRegister.MedicalStartDate >= Convert.ToDateTime(input.StartDate) &&
|
|
m.patientRegister.MedicalStartDate < Convert.ToDateTime(input.EndDate).AddDays(1))
|
|
);
|
|
}
|
|
}
|
|
if (input.CompleteFlags.Any())
|
|
{
|
|
query = query.Where(m => input.CompleteFlags.Contains(m.patientRegister.CompleteFlag));
|
|
}
|
|
|
|
if (input.MedicalTypeIds.Any())
|
|
{
|
|
query = query.Where(m => input.MedicalTypeIds.Contains(m.patientRegister.MedicalTypeId));
|
|
}
|
|
|
|
|
|
if (input.CustomerOrgId != null)
|
|
{
|
|
var CustomerOrgIds = await _customerOrgManager.GetCustomerOrgChildrenId(input.CustomerOrgId.Value);
|
|
query = query.Where(m => CustomerOrgIds.Contains(m.patientRegister.CustomerOrgId));
|
|
}
|
|
|
|
if (input.CustomerOrgRegisterId != null && input.CustomerOrgRegisterId != Guid.Empty)
|
|
{
|
|
query = query.Where(m => m.patientRegister.CustomerOrgRegisterId == input.CustomerOrgRegisterId);
|
|
}
|
|
|
|
if (input.CustomerOrgGroupIds.Any())
|
|
{
|
|
query = query.Where(m => m.patientRegister.CustomerOrgGroupId != null && input.CustomerOrgGroupIds.Contains(m.patientRegister.CustomerOrgGroupId.Value));
|
|
}
|
|
|
|
if (input.IsSmsComplete != null)
|
|
{
|
|
query = query.Where(m => m.followUp.IsSmsComplete == input.IsSmsComplete);
|
|
}
|
|
|
|
if (input.IsPhoneComplete != null)
|
|
{
|
|
query = query.Where(m => m.followUp.IsPhoneComplete == input.IsPhoneComplete);
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
var followUpGroup = query.ToList().GroupBy(g => g.followUp);
|
|
|
|
var entListDto = followUpGroup.Select(s => new PhoneFollowUpWithCriticalItemDto
|
|
{
|
|
FollowUpId = s.Key.Id,
|
|
PatientName = s.FirstOrDefault().patientRegister.PatientName,
|
|
IdNo = s.FirstOrDefault().patient.IdNo,
|
|
PatientRegisterNo = s.FirstOrDefault().patientRegister.PatientRegisterNo,
|
|
PatientRegisterId = s.FirstOrDefault().patientRegister.Id,
|
|
Age = s.FirstOrDefault().patientRegister.Age,
|
|
BirthDate = DataHelper.ConversionDateShortToString(s.FirstOrDefault().patientRegister.BirthDate),
|
|
CompleteFlag = s.FirstOrDefault().patientRegister.CompleteFlag,
|
|
CustomerOrgName = _cacheService.GetCustomerOrgNameAsync(s.FirstOrDefault().patientRegister.CustomerOrgId).GetAwaiter().GetResult(),
|
|
CustomerOrgParentName = _cacheService.GetTopCustomerOrgNameAsync(s.FirstOrDefault().patientRegister.CustomerOrgId).GetAwaiter().GetResult(),
|
|
IsMedicalStart = s.FirstOrDefault().patientRegister.IsMedicalStart,
|
|
IsUpload = s.FirstOrDefault().patientRegister.IsUpload,
|
|
JobCardNo = s.FirstOrDefault().patientRegister.JobCardNo,
|
|
JobPost = s.FirstOrDefault().patientRegister.JobPost,
|
|
JobTitle = s.FirstOrDefault().patientRegister.JobTitle,
|
|
MaritalStatusName = _cacheService.GetMaritalStatusNameAsync(s.FirstOrDefault().patientRegister.MaritalStatusId).GetAwaiter().GetResult(),
|
|
MedicalCardNo = s.FirstOrDefault().patientRegister.MedicalCardNo,
|
|
MedicalStartDate = DataHelper.ConversionDateShortToString(s.FirstOrDefault().patientRegister.MedicalStartDate),
|
|
MedicalTimes = s.FirstOrDefault().patientRegister.MedicalTimes,
|
|
MedicalTypeName = _cacheService.GetMedicalTypeNameAsync(s.FirstOrDefault().patientRegister.MedicalTypeId).GetAwaiter().GetResult(),
|
|
MobileTelephone = s.FirstOrDefault().patient.MobileTelephone,
|
|
NationName = _cacheService.GetNationNameAsync(s.FirstOrDefault().patient.NationId).GetAwaiter().GetResult(),
|
|
PatientNo = s.FirstOrDefault().patient.PatientNo,
|
|
PersonnelTypeName = _cacheService.GetPersonnelTypeNameAsync(s.FirstOrDefault().patientRegister.PersonnelTypeId).GetAwaiter().GetResult(),
|
|
SexName = _cacheService.GetSexNameAsync(s.FirstOrDefault().patientRegister.SexId).GetAwaiter().GetResult(),
|
|
Telephone = s.FirstOrDefault().patient.Telephone,
|
|
PhoneFollowUpDetail = s.Where(m => m.phoneFollowUpEmpty != null).GroupBy(g => g.phoneFollowUpEmpty).OrderBy(o => o.Key.PlanFollowDate).Select(ss => new PhoneFollowUpSimpleDto
|
|
{
|
|
FollowUpContent = ss.Key.FollowUpContent,
|
|
IsComplete = ss.Key.IsComplete,
|
|
PlanFollowDate = DataHelper.ConversionDateToString(ss.Key.PlanFollowDate),
|
|
ReplyContent = ss.Key.ReplyContent
|
|
}).ToList(),
|
|
AbnormalAsbitemDetail = s.Where(m => m.registerCheck.IsCriticalValue != null).GroupBy(g => g.registerCheck).Select(ss => new PhoneFollowUpWithCriticalItemAbnormalAsbitemDto
|
|
{
|
|
CriticalValueContent = ss.Key.CriticalValueContent,
|
|
AsbitemName = string.Join(",", ss.Select(sss => sss.asbitem.DisplayName).Distinct()),
|
|
IsCriticalValue = ss.Key.IsCriticalValue == null ? 'N' : ss.Key.IsCriticalValue.Value,
|
|
IsReview = ss.Key.IsReview == null ? 'N' : ss.Key.IsReview.Value
|
|
}).ToList(),
|
|
AbnormalItemDetail = s.Where(m => m.registerCheckItem.IsCriticalValue != null).GroupBy(g => g.registerCheckItem).Select(ss => new PhoneFollowUpWithCriticalItemAbnormalItemDto
|
|
{
|
|
CriticalValueContent = ss.Key.CriticalValueContent,
|
|
ItemName = ss.FirstOrDefault().item.DisplayName,
|
|
IsCriticalValue = ss.Key.IsCriticalValue == null ? 'N' : ss.Key.IsCriticalValue.Value,
|
|
IsReview = ss.Key.IsReview == null ? 'N' : ss.Key.IsReview.Value
|
|
}).ToList(),
|
|
CriticalValueContents = string.Join("<br>", s.Where(m => !string.IsNullOrWhiteSpace(m.registerCheck.CriticalValueContent)).Select(ss => ss.registerCheck.CriticalValueContent).Distinct()) + "<br>" + string.Join("<br>", s.Where(m => !string.IsNullOrWhiteSpace(m.registerCheckItem.CriticalValueContent)).Select(ss => ss.registerCheckItem.CriticalValueContent).Distinct()),
|
|
IsPhoneComplete = s.Key.IsPhoneComplete,
|
|
IsSmsComplete = s.Key.IsSmsComplete
|
|
}).ToList();
|
|
|
|
return entListDto;
|
|
|
|
//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>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/PhoneFollowUp/GetAsbitemOrItemCriticalByPatientRegisterId")]
|
|
public async Task<List<GetAsbitemOrItemCriticalByPatientRegisterIdDto>> GetAsbitemOrItemCriticalByPatientRegisterIdAsync(PatientRegisterIdInputDto input)
|
|
{
|
|
var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
|
|
join registerCheck in await _registerCheckRepository.GetQueryableAsync() on patientRegister.Id equals registerCheck.PatientRegisterId
|
|
join registerCheckAsbitem in await _registerCheckAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckAsbitem.RegisterCheckId
|
|
join asbitem in await _asbitemRepository.GetQueryableAsync() on registerCheckAsbitem.AsbitemId equals asbitem.Id
|
|
join registerCheckItem in await _registerCheckItemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckItem.RegisterCheckId
|
|
join item in await _itemRepository.GetQueryableAsync() on registerCheckItem.ItemId equals item.Id
|
|
join registerCheckSummary in await _registerCheckSummaryRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckSummary.RegisterCheckId into registerCheckSummaryTemp
|
|
from registerCheckSummaryHaveEmpty in registerCheckSummaryTemp.DefaultIfEmpty()
|
|
select new
|
|
{
|
|
patientRegister,
|
|
registerCheck,
|
|
asbitem,
|
|
registerCheckItem,
|
|
item,
|
|
registerCheckSummaryHaveEmpty
|
|
};
|
|
|
|
if (input.PatientRegisterId == Guid.Empty)
|
|
{
|
|
throw new UserFriendlyException("人员ID格式不正确");
|
|
}
|
|
|
|
query = query.Where(m => m.patientRegister.Id == input.PatientRegisterId);
|
|
|
|
var registerCheckGroup = query.ToList().GroupBy(g => new { g.registerCheck, g.registerCheckItem });
|
|
|
|
|
|
var entListDto = new List<GetAsbitemOrItemCriticalByPatientRegisterIdDto>();
|
|
|
|
foreach (var item in registerCheckGroup)
|
|
{
|
|
if (item.Key.registerCheck.IsFollowUp == 'Y'
|
|
|| item.Key.registerCheck.IsCriticalValue == 'Y'
|
|
|| item.Key.registerCheckItem.IsFollowUp == 'Y'
|
|
|| item.Key.registerCheckItem.IsCriticalValue == 'Y')
|
|
{
|
|
if (item.Key.registerCheckItem.IsFollowUp == 'Y'
|
|
|| item.Key.registerCheckItem.IsCriticalValue == 'Y')
|
|
{
|
|
entListDto.Add(new GetAsbitemOrItemCriticalByPatientRegisterIdDto
|
|
{
|
|
RegisterCheckId = item.Key.registerCheck.Id,
|
|
AsbitemName = string.Join(",", item.Select(ss => ss.asbitem.DisplayName).Distinct()),
|
|
CriticalRangeValue = item.Key.registerCheck.CriticalRangeValue,
|
|
CriticalValueContent = item.Key.registerCheck.CriticalValueContent,
|
|
IsCriticalValue = item.Key.registerCheck.IsCriticalValue,
|
|
IsCriticalValueAudit = item.Key.registerCheck.IsCriticalValueAudit,
|
|
IsFollowUp = item.Key.registerCheck.IsFollowUp,
|
|
IsReview = item.Key.registerCheck.IsReview,
|
|
SummaryDetail = string.Join("<br>", item.Where(m => m.registerCheckSummaryHaveEmpty != null).Select(ss => ss.registerCheckSummaryHaveEmpty.Summary).Distinct()),
|
|
ItemCriticalRangeValue = item.Key.registerCheckItem.CriticalRangeValue,
|
|
ItemCriticalValueContent = item.Key.registerCheckItem.CriticalValueContent,
|
|
ItemIsCriticalValue = item.Key.registerCheckItem.IsCriticalValue,
|
|
ItemIsCriticalValueAudit = item.Key.registerCheckItem.IsCriticalValueAudit,
|
|
ItemIsFollowUp = item.Key.registerCheckItem.IsFollowUp,
|
|
ItemIsReview = item.Key.registerCheckItem.IsReview,
|
|
ItemName = item.FirstOrDefault().item.DisplayName,
|
|
ItemResult = item.Key.registerCheckItem.Result,
|
|
ReferenceRangeValue = item.Key.registerCheckItem.ReferenceRangeValue,
|
|
Unit = item.Key.registerCheckItem.Unit
|
|
});
|
|
}
|
|
else
|
|
{
|
|
if (entListDto.Where(m => m.RegisterCheckId == item.Key.registerCheck.Id).Count() == 0)
|
|
{
|
|
entListDto.Add(new GetAsbitemOrItemCriticalByPatientRegisterIdDto
|
|
{
|
|
RegisterCheckId = item.Key.registerCheck.Id,
|
|
AsbitemName = string.Join(",", item.Select(ss => ss.asbitem.DisplayName).Distinct()),
|
|
CriticalRangeValue = item.Key.registerCheck.CriticalRangeValue,
|
|
CriticalValueContent = item.Key.registerCheck.CriticalValueContent,
|
|
IsCriticalValue = item.Key.registerCheck.IsCriticalValue,
|
|
IsCriticalValueAudit = item.Key.registerCheck.IsCriticalValueAudit,
|
|
IsFollowUp = item.Key.registerCheck.IsFollowUp,
|
|
IsReview = item.Key.registerCheck.IsReview,
|
|
SummaryDetail = string.Join("<br>", item.Where(m => m.registerCheckSummaryHaveEmpty != null).Select(ss => ss.registerCheckSummaryHaveEmpty.Summary).Distinct()),
|
|
ItemCriticalRangeValue = "",
|
|
ItemCriticalValueContent = "",
|
|
ItemIsCriticalValue = null,
|
|
ItemIsCriticalValueAudit = null,
|
|
ItemIsFollowUp = null,
|
|
ItemIsReview = null,
|
|
ItemName = "",
|
|
ItemResult = "",
|
|
ReferenceRangeValue = "",
|
|
Unit = ""
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//var entListDto = registerCheckGroup.Select(s => new GetAsbitemOrItemCriticalByPatientRegisterIdDto
|
|
//{
|
|
// RegisterCheckId = s.Key.registerCheck.Id,
|
|
// AsbitemName = string.Join(",", s.Select(ss => ss.asbitem.DisplayName).Distinct()),
|
|
// CriticalRangeValue = s.Key.registerCheck.CriticalRangeValue,
|
|
// CriticalValueContent = s.Key.registerCheck.CriticalValueContent,
|
|
// IsCriticalValue = s.Key.registerCheck.IsCriticalValue,
|
|
// IsCriticalValueAudit = s.Key.registerCheck.IsCriticalValueAudit,
|
|
// IsFollowUp = s.Key.registerCheck.IsFollowUp,
|
|
// IsReview = s.Key.registerCheck.IsReview,
|
|
// SummaryDetail = string.Join("<br>", s.Where(m => m.registerCheckSummaryHaveEmpty != null).Select(ss => ss.registerCheckSummaryHaveEmpty.Summary).Distinct()),
|
|
// ItemCriticalRangeValue = s.Key.registerCheckItemHaveEmpty.CriticalRangeValue,
|
|
// ItemCriticalValueContent = s.Key.registerCheckItemHaveEmpty.CriticalValueContent,
|
|
// ItemIsCriticalValue = s.Key.registerCheckItemHaveEmpty.IsCriticalValue,
|
|
// ItemIsCriticalValueAudit = s.Key.registerCheckItemHaveEmpty.IsCriticalValueAudit,
|
|
// ItemIsFollowUp = s.Key.registerCheckItemHaveEmpty.IsFollowUp,
|
|
// ItemIsReview = s.Key.registerCheckItemHaveEmpty.IsReview,
|
|
// ItemName = s.FirstOrDefault().item.DisplayName,
|
|
// ItemResult = s.Key.registerCheckItemHaveEmpty.Result,
|
|
// ReferenceRangeValue = s.Key.registerCheckItemHaveEmpty.ReferenceRangeValue,
|
|
// Unit = s.Key.registerCheckItemHaveEmpty.Unit
|
|
//}).ToList();
|
|
|
|
//var entListDto = registerCheckGroup.Select(s => new GetAsbitemOrItemCriticalByPatientRegisterIdDto
|
|
//{
|
|
// AsbitemName = string.Join(",", s.Select(ss => ss.asbitem.DisplayName).Distinct()),
|
|
// CriticalRangeValue = s.Key.CriticalRangeValue,
|
|
// CriticalValueContent = s.Key.CriticalValueContent,
|
|
// IsCriticalValue = s.Key.IsCriticalValue,
|
|
// IsCriticalValueAudit = s.Key.IsCriticalValueAudit,
|
|
// IsFollowUp = s.Key.IsFollowUp,
|
|
// IsReview = s.Key.IsReview,
|
|
// SummaryDetail = string.Join("<br>", s.Where(m => m.registerCheckSummaryHaveEmpty != null).Select(ss => ss.registerCheckSummaryHaveEmpty.Summary).Distinct()),
|
|
// ItemDetails = s.GroupBy(g => g.registerCheckItem).ToList()
|
|
// .Select(ss => new GetAsbitemOrItemCriticalByPatientRegisterIdItemDetail
|
|
// {
|
|
// CriticalRangeValue = ss.Key.CriticalRangeValue,
|
|
// CriticalValueContent = ss.Key.CriticalValueContent,
|
|
// IsCriticalValue = ss.Key.IsCriticalValue,
|
|
// IsCriticalValueAudit = ss.Key.IsCriticalValueAudit,
|
|
// IsFollowUp = ss.Key.IsFollowUp,
|
|
// IsReview = ss.Key.IsReview,
|
|
// ItemName = ss.FirstOrDefault().item.DisplayName,
|
|
// ItemResult = ss.Key.Result,
|
|
// ReferenceRangeValue = ss.Key.ReferenceRangeValue,
|
|
// Unit = ss.Key.Unit
|
|
// }).ToList()
|
|
//}).ToList();
|
|
|
|
return entListDto;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 自动生成电话随访记录
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/PhoneFollowUp/AutoCreate")]
|
|
public async Task AutoCreateAsync(AutoCreatePhoneFollowUpDto input)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(input.StartDate))
|
|
{
|
|
throw new UserFriendlyException("开始时间不能为空");
|
|
}
|
|
|
|
var isPhoneFollowUp = await _phoneFollowUpRepository.CountAsync(c => c.FollowUpId == input.FollowUpId);
|
|
if (isPhoneFollowUp > 0)
|
|
{
|
|
throw new UserFriendlyException("已存在电话随访记录,不允许重复生成");
|
|
}
|
|
|
|
|
|
var followUpEnt = await _followUpRepository.FirstOrDefaultAsync(f => f.Id == input.FollowUpId);
|
|
if (followUpEnt == null)
|
|
{
|
|
throw new UserFriendlyException("随访ID不正确");
|
|
}
|
|
|
|
List<PhoneFollowUp> phoneFollowUpList = new List<PhoneFollowUp>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < input.GenerateCount; i++)
|
|
{
|
|
DateTime planFollowDate = Convert.ToDateTime(input.StartDate);
|
|
|
|
planFollowDate = planFollowDate.AddDays(i * input.IntervalDays);
|
|
|
|
var phoneFollowUpEntity = new PhoneFollowUp(GuidGenerator.Create())
|
|
{
|
|
FollowUpContent = input.FollowUpContent,
|
|
FollowUpId = input.FollowUpId,
|
|
PlanFollowDate = planFollowDate,
|
|
IsComplete = 'N'
|
|
};
|
|
|
|
phoneFollowUpList.Add(phoneFollowUpEntity);
|
|
}
|
|
|
|
|
|
if (phoneFollowUpList.Any())
|
|
{
|
|
await _phoneFollowUpRepository.InsertManyAsync(phoneFollowUpList);
|
|
|
|
followUpEnt.IsPhoneComplete = 'Y';
|
|
await _followUpRepository.UpdateAsync(followUpEnt);
|
|
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 新增电话随访记录
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/PhoneFollowUp/Create")]
|
|
public async Task CreateAsync(CreatePhoneFollowUpDto input)
|
|
{
|
|
|
|
var followUpEnt = await _followUpRepository.FirstOrDefaultAsync(f => f.Id == input.FollowUpId);
|
|
if (followUpEnt == null)
|
|
{
|
|
throw new UserFriendlyException("随访ID不正确");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(input.PlanFollowDate))
|
|
{
|
|
throw new UserFriendlyException("随访日期不能为空");
|
|
}
|
|
|
|
var phoneFollowUpEntity = new PhoneFollowUp(GuidGenerator.Create())
|
|
{
|
|
FollowUpContent = input.FollowUpContent,
|
|
FollowUpId = input.FollowUpId,
|
|
PlanFollowDate = Convert.ToDateTime(input.PlanFollowDate),
|
|
IsComplete = 'N'
|
|
};
|
|
|
|
|
|
await _phoneFollowUpRepository.InsertAsync(phoneFollowUpEntity);
|
|
|
|
followUpEnt.IsPhoneComplete = 'Y';
|
|
await _followUpRepository.UpdateAsync(followUpEnt);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <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)
|
|
{
|
|
var phoneFollowUpEnt = await _phoneFollowUpRepository.FirstOrDefaultAsync(f => f.Id == input.PhoneFollowUpId);
|
|
if (phoneFollowUpEnt == null)
|
|
{
|
|
throw new UserFriendlyException("数据不存在");
|
|
}
|
|
await _phoneFollowUpRepository.DeleteAsync(input.PhoneFollowUpId, true);
|
|
if ((await _phoneFollowUpRepository.CountAsync(c => c.FollowUpId == phoneFollowUpEnt.FollowUpId)) == 0)
|
|
{
|
|
var followUpEnt = await _followUpRepository.FirstOrDefaultAsync(f => f.Id == phoneFollowUpEnt.FollowUpId);
|
|
if (followUpEnt != null)
|
|
{
|
|
followUpEnt.IsPhoneComplete = 'N';
|
|
await _followUpRepository.UpdateAsync(followUpEnt);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|