|
|
|
@ -1,6 +1,7 @@ |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Shentun.Peis.Enums; |
|
|
|
using Shentun.Peis.Models; |
|
|
|
using Shentun.Peis.SumSuggestionContents; |
|
|
|
using Shentun.Peis.SumSummaryContents; |
|
|
|
@ -27,192 +28,256 @@ namespace Shentun.Peis.SumSuggestionHeaders |
|
|
|
private readonly IRepository<SumSuggestionContent, Guid> _sumSuggestionContentRepository; |
|
|
|
private readonly IRepository<RegisterCheck, Guid> _registerCheckRepository; |
|
|
|
private readonly IRepository<SumDiagnosis> _sumDiagnosisRepository; |
|
|
|
|
|
|
|
private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository; |
|
|
|
private readonly IRepository<Diagnosis, Guid> _diagnosisRepository; |
|
|
|
private readonly SumSummaryHeaderManager _sumSummaryHeaderManager; |
|
|
|
public SumSuggestionHeaderAppService( |
|
|
|
IRepository<SumSuggestionHeader, Guid> sumSuggestionHeaderRepository, |
|
|
|
IRepository<SumSuggestionContent, Guid> sumSuggestionContentRepository, |
|
|
|
IRepository<RegisterCheck, Guid> registerCheckRepository, |
|
|
|
IRepository<SumDiagnosis> sumDiagnosisRepository |
|
|
|
IRepository<SumDiagnosis> sumDiagnosisRepository, |
|
|
|
IRepository<PatientRegister, Guid> patientRegisterRepository, |
|
|
|
IRepository<Diagnosis, Guid> diagnosisRepository, |
|
|
|
SumSummaryHeaderManager sumSummaryHeaderManager |
|
|
|
) |
|
|
|
{ |
|
|
|
this._sumSuggestionHeaderRepository = sumSuggestionHeaderRepository; |
|
|
|
this._sumSuggestionContentRepository = sumSuggestionContentRepository; |
|
|
|
this._registerCheckRepository = registerCheckRepository; |
|
|
|
this._sumDiagnosisRepository = sumDiagnosisRepository; |
|
|
|
_patientRegisterRepository = patientRegisterRepository; |
|
|
|
_sumSummaryHeaderManager = sumSummaryHeaderManager; |
|
|
|
_diagnosisRepository = diagnosisRepository; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取人员总检诊台建议 (如还未录入,获取医生诊台录入的建议)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="PatientRegisterId">人员登记ID</param>
|
|
|
|
/// <param name="patientRegisterId">人员登记ID</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("api/app/sumsuggestionheader/getsumsuggestionlist")] |
|
|
|
public async Task<List<SumSuggestionHeaderOrContentDto>> GetSumSuggestionListAsync(Guid PatientRegisterId) |
|
|
|
public async Task<List<SumSuggestionDto>> GetSumSuggestionListAsync(Guid patientRegisterId) |
|
|
|
{ |
|
|
|
|
|
|
|
List<SumSuggestionHeaderOrContentDto> msg = new List<SumSuggestionHeaderOrContentDto>(); |
|
|
|
|
|
|
|
List<SumSuggestionDto> msg = new List<SumSuggestionDto>(); |
|
|
|
|
|
|
|
var query = from a in await _sumSuggestionHeaderRepository.GetQueryableAsync() |
|
|
|
join b in await _sumDiagnosisRepository.GetQueryableAsync() on new { a.PatientRegisterId, a.Id } equals new { b.PatientRegisterId, Id = b.SumSuggestionHeaderId } into bb |
|
|
|
from ab in bb.DefaultIfEmpty() |
|
|
|
join c in await _sumSuggestionContentRepository.GetQueryableAsync() on a.Id equals c.SumSuggestionHeaderId into cc |
|
|
|
from ac in cc.DefaultIfEmpty() |
|
|
|
where (a.PatientRegisterId == PatientRegisterId) |
|
|
|
orderby a.DisplayOrder ascending, ac.DisplayOrder ascending |
|
|
|
var patientRegister = await _patientRegisterRepository.GetAsync(patientRegisterId); |
|
|
|
var query = from sumSuggestionHeader in await _sumSuggestionHeaderRepository.GetQueryableAsync() |
|
|
|
join sumDiagnosis in await _sumDiagnosisRepository.GetQueryableAsync() |
|
|
|
on new { sumSuggestionHeader.PatientRegisterId, sumSuggestionHeader.Id } equals new { sumDiagnosis.PatientRegisterId, Id = sumDiagnosis.SumSuggestionHeaderId } into bb |
|
|
|
from sumDiagnosisHaveEmpty in bb.DefaultIfEmpty() |
|
|
|
join sumSuggestionContent in await _sumSuggestionContentRepository.GetQueryableAsync() |
|
|
|
on sumSuggestionHeader.Id equals sumSuggestionContent.SumSuggestionHeaderId into cc |
|
|
|
from sumSuggestionContentHaveEmpty in cc.DefaultIfEmpty() |
|
|
|
where (sumSuggestionHeader.PatientRegisterId == patientRegisterId) |
|
|
|
orderby sumSuggestionHeader.DisplayOrder ascending, sumSuggestionContentHaveEmpty.DisplayOrder ascending |
|
|
|
select new |
|
|
|
{ |
|
|
|
a, |
|
|
|
ab, |
|
|
|
ac |
|
|
|
sumSuggestionHeader, |
|
|
|
sumDiagnosisHaveEmpty, |
|
|
|
sumSuggestionContentHaveEmpty |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if (query.Any()) |
|
|
|
if (patientRegister.CompleteFlag == PatientRegisterCompleteFlag.GeneralInspected) |
|
|
|
{ |
|
|
|
msg = query.GroupBy(g => g.a.Id).Select(s => new SumSuggestionHeaderOrContentDto |
|
|
|
msg = query.GroupBy(g => g.sumSuggestionHeader.Id).Select(s => new SumSuggestionDto |
|
|
|
{ |
|
|
|
SuggestionTitle = s.FirstOrDefault().a.SuggestionTitle, |
|
|
|
SuggestionFlag = s.FirstOrDefault().a.SuggestionFlag, |
|
|
|
PatientRegisterId = s.FirstOrDefault().a.PatientRegisterId, |
|
|
|
DisplayOrder = s.FirstOrDefault().a.DisplayOrder, |
|
|
|
Id = s.FirstOrDefault().a.Id, |
|
|
|
DiagnosisId = s.FirstOrDefault().ab != null ? s.FirstOrDefault().ab.DiagnosisId : null, |
|
|
|
Details = s.Where(m => m.ac != null).Select(sa => new SumSuggestionContentDto |
|
|
|
SuggestionTitle = s.FirstOrDefault().sumSuggestionHeader.SuggestionTitle, |
|
|
|
SuggestionFlag = s.FirstOrDefault().sumSuggestionHeader.SuggestionFlag, |
|
|
|
DisplayOrder = s.FirstOrDefault().sumSuggestionHeader.DisplayOrder, |
|
|
|
DiagnosisIds = s.Where(o => o.sumDiagnosisHaveEmpty != null). |
|
|
|
Select(x => x.sumDiagnosisHaveEmpty.DiagnosisId).ToList(), |
|
|
|
MedicalInterpretations = s.Where(m => m.sumSuggestionContentHaveEmpty != null && |
|
|
|
m.sumSuggestionContentHaveEmpty.SuggestionType == SuggestionTypeFlag.MedicalInterpretation). |
|
|
|
Select(sa => new SumSuggestionContentData |
|
|
|
{ |
|
|
|
DisplayOrder = sa.sumSuggestionContentHaveEmpty.DisplayOrder, |
|
|
|
SuggestionContent = sa.sumSuggestionContentHaveEmpty.SuggestionContent, |
|
|
|
}).OrderBy(o => o.DisplayOrder).ToList(), |
|
|
|
CommonReasons = s.Where(m => m.sumSuggestionContentHaveEmpty != null && |
|
|
|
m.sumSuggestionContentHaveEmpty.SuggestionType == SuggestionTypeFlag.CommonReasons). |
|
|
|
Select(sa => new SumSuggestionContentData |
|
|
|
{ |
|
|
|
DisplayOrder = sa.ac.DisplayOrder, |
|
|
|
SuggestionContent = sa.ac.SuggestionContent, |
|
|
|
SumSuggestionHeaderId = sa.ac.SumSuggestionHeaderId |
|
|
|
DisplayOrder = sa.sumSuggestionContentHaveEmpty.DisplayOrder, |
|
|
|
SuggestionContent = sa.sumSuggestionContentHaveEmpty.SuggestionContent, |
|
|
|
}).OrderBy(o => o.DisplayOrder).ToList(), |
|
|
|
HealthGuidances = s.Where(m => m.sumSuggestionContentHaveEmpty != null && |
|
|
|
m.sumSuggestionContentHaveEmpty.SuggestionType == SuggestionTypeFlag.HealthGuidance). |
|
|
|
Select(sa => new SumSuggestionContentData |
|
|
|
{ |
|
|
|
DisplayOrder = sa.sumSuggestionContentHaveEmpty.DisplayOrder, |
|
|
|
SuggestionContent = sa.sumSuggestionContentHaveEmpty.SuggestionContent, |
|
|
|
}).OrderBy(o => o.DisplayOrder).ToList(), |
|
|
|
|
|
|
|
}).OrderBy(o => o.DisplayOrder).ToList(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//没有值的情况
|
|
|
|
var checklist = (await _registerCheckRepository.GetDbSetAsync()) |
|
|
|
.Include(x => x.RegisterCheckAsbitems) |
|
|
|
.ThenInclude(x => x.Asbitem) |
|
|
|
.Include(x => x.RegisterCheckSuggestions) |
|
|
|
.Where(m => m.RegisterCheckAsbitems.Select(s => s.PatientRegisterId).Contains(PatientRegisterId) && m.RegisterCheckSuggestions.Count > 0) |
|
|
|
.ToList(); |
|
|
|
var checklist = await _sumSummaryHeaderManager.GetSumSummarysByDoctorCheck(patientRegisterId); |
|
|
|
//获取所有综述
|
|
|
|
var registerCheckSummaries = new List<string>(); |
|
|
|
foreach (var registerCheck in checklist) |
|
|
|
{ |
|
|
|
|
|
|
|
foreach (var registerCheckSummary in registerCheck.RegisterCheckSummaries) |
|
|
|
{ |
|
|
|
registerCheckSummaries.Add(registerCheckSummary.Summary); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
//根据综述生成建议
|
|
|
|
var diagnosis = (await _diagnosisRepository.GetQueryableAsync()).Include(o => o.Suggestions).ToList(); |
|
|
|
|
|
|
|
if (checklist.Any() && checklist.Count(c => c.RegisterCheckSuggestions.Count > 0) > 0) |
|
|
|
foreach (var registerCheckSummary in registerCheckSummaries) |
|
|
|
{ |
|
|
|
msg = checklist.Select(s => new SumSuggestionHeaderOrContentDto |
|
|
|
var matchDiagnosisList = diagnosis.Where(o => registerCheckSummary.Contains(o.DisplayName)).ToList(); |
|
|
|
var matchDiagnosis = matchDiagnosisList.OrderByDescending(o => o.DisplayName.Length).FirstOrDefault(); |
|
|
|
if (matchDiagnosis != null) |
|
|
|
{ |
|
|
|
Id = s.Id, |
|
|
|
SuggestionTitle = string.Join(",", s.RegisterCheckAsbitems.Select(rs => rs.Asbitem.DisplayName).ToList()), |
|
|
|
SuggestionFlag = null, |
|
|
|
PatientRegisterId = s.RegisterCheckAsbitems.FirstOrDefault().PatientRegisterId, |
|
|
|
DisplayOrder = 0, |
|
|
|
Details = s.RegisterCheckSuggestions.OrderBy(o => o.DisplayOrder).Select(sa => new SumSuggestionContentDto |
|
|
|
if (msg.Where(o => o.SuggestionTitle == matchDiagnosis.DisplayName).Count() > 0) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
var sumSuggestionDto = new SumSuggestionDto() |
|
|
|
{ |
|
|
|
DisplayOrder = sa.DisplayOrder, |
|
|
|
SuggestionContent = sa.Suggestion, |
|
|
|
SumSuggestionHeaderId = sa.RegisterCheckId |
|
|
|
}).OrderBy(o => o.DisplayOrder).ToList() |
|
|
|
}).OrderBy(o => o.DisplayOrder).ToList(); |
|
|
|
SuggestionTitle = matchDiagnosis.DisplayName, |
|
|
|
SuggestionFlag = null, |
|
|
|
DisplayOrder = 0, |
|
|
|
DiagnosisIds = new List<Guid>() { matchDiagnosis.Id }, |
|
|
|
MedicalInterpretations = matchDiagnosis.Suggestions. |
|
|
|
Where(o => o.SuggestionType == SuggestionTypeFlag.MedicalInterpretation) |
|
|
|
.OrderBy(o => o.DisplayOrder) |
|
|
|
.Select(x => new SumSuggestionContentData() |
|
|
|
{ |
|
|
|
SuggestionContent = x.SuggestionContent, |
|
|
|
DisplayOrder = x.DisplayOrder, |
|
|
|
} |
|
|
|
).ToList(), |
|
|
|
CommonReasons = matchDiagnosis.Suggestions. |
|
|
|
Where(o => o.SuggestionType == SuggestionTypeFlag.CommonReasons) |
|
|
|
.OrderBy(o => o.DisplayOrder) |
|
|
|
.Select(x => new SumSuggestionContentData() |
|
|
|
{ |
|
|
|
SuggestionContent = x.SuggestionContent, |
|
|
|
DisplayOrder = x.DisplayOrder, |
|
|
|
} |
|
|
|
).ToList(), |
|
|
|
HealthGuidances = matchDiagnosis.Suggestions. |
|
|
|
Where(o => o.SuggestionType == SuggestionTypeFlag.HealthGuidance) |
|
|
|
.OrderBy(o => o.DisplayOrder) |
|
|
|
.Select(x => new SumSuggestionContentData() |
|
|
|
{ |
|
|
|
SuggestionContent = x.SuggestionContent, |
|
|
|
DisplayOrder = x.DisplayOrder, |
|
|
|
} |
|
|
|
).ToList() |
|
|
|
}; |
|
|
|
msg.Add(sumSuggestionDto); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
return msg; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 批量插入总诊台建议
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("api/app/sumsuggestionheader/createsumsuggestion")] |
|
|
|
public async Task CreateSumSuggestionAsync(List<CreateSumSuggestionHeaderOrContentDto> input) |
|
|
|
{ |
|
|
|
if (input.Any()) |
|
|
|
/// <summary>
|
|
|
|
/// 批量插入总诊台建议
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("api/app/sumsuggestionheader/createsumsuggestion")] |
|
|
|
public async Task CreateSumSuggestionAsync(List<CreateSumSuggestionHeaderOrContentDto> input) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("禁止使用"); |
|
|
|
if (input.Any()) |
|
|
|
{ |
|
|
|
|
|
|
|
//先删除总诊头跟内容
|
|
|
|
await _sumSuggestionHeaderRepository.DeleteAsync(m => m.PatientRegisterId == input.FirstOrDefault().PatientRegisterId, true); |
|
|
|
//先删除总诊头跟内容
|
|
|
|
await _sumSuggestionHeaderRepository.DeleteAsync(m => m.PatientRegisterId == input.FirstOrDefault().PatientRegisterId, true); |
|
|
|
|
|
|
|
//删除对应的诊断数据
|
|
|
|
await _sumDiagnosisRepository.DeleteAsync(m => m.PatientRegisterId == input.FirstOrDefault().PatientRegisterId, true); |
|
|
|
//删除对应的诊断数据
|
|
|
|
await _sumDiagnosisRepository.DeleteAsync(m => m.PatientRegisterId == input.FirstOrDefault().PatientRegisterId, true); |
|
|
|
|
|
|
|
foreach (var item in input) |
|
|
|
{ |
|
|
|
#region 插入SumSuggestionHeader
|
|
|
|
SumSuggestionHeader sumSuggestionHeaderEnt = new SumSuggestionHeader |
|
|
|
foreach (var item in input) |
|
|
|
{ |
|
|
|
DisplayOrder = input.IndexOf(item) + 1, |
|
|
|
PatientRegisterId = item.PatientRegisterId, |
|
|
|
SuggestionFlag = null, |
|
|
|
SuggestionTitle = item.SuggestionTitle |
|
|
|
}; |
|
|
|
|
|
|
|
var sumSuggestionHeaderEnt_New = await _sumSuggestionHeaderRepository.InsertAsync(sumSuggestionHeaderEnt, true); |
|
|
|
#region 插入SumSuggestionHeader
|
|
|
|
SumSuggestionHeader sumSuggestionHeaderEnt = new SumSuggestionHeader |
|
|
|
{ |
|
|
|
DisplayOrder = input.IndexOf(item) + 1, |
|
|
|
PatientRegisterId = item.PatientRegisterId, |
|
|
|
SuggestionFlag = null, |
|
|
|
SuggestionTitle = item.SuggestionTitle |
|
|
|
}; |
|
|
|
|
|
|
|
if (sumSuggestionHeaderEnt_New != null) |
|
|
|
{ |
|
|
|
var sumSuggestionHeaderEnt_New = await _sumSuggestionHeaderRepository.InsertAsync(sumSuggestionHeaderEnt, true); |
|
|
|
|
|
|
|
#region 插入SumDiagnosis
|
|
|
|
if (item.DiagnosisId != null && item.DiagnosisId != Guid.Empty) |
|
|
|
if (sumSuggestionHeaderEnt_New != null) |
|
|
|
{ |
|
|
|
|
|
|
|
SumDiagnosis sumDiagnosis = new SumDiagnosis |
|
|
|
#region 插入SumDiagnosis
|
|
|
|
if (item.DiagnosisId != null && item.DiagnosisId != Guid.Empty) |
|
|
|
{ |
|
|
|
DiagnosisId = item.DiagnosisId.Value, |
|
|
|
DisplayOrder = input.IndexOf(item) + 1, |
|
|
|
PatientRegisterId = item.PatientRegisterId, |
|
|
|
SumSuggestionHeaderId = sumSuggestionHeaderEnt_New.Id |
|
|
|
}; |
|
|
|
|
|
|
|
await _sumDiagnosisRepository.InsertAsync(sumDiagnosis); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
SumDiagnosis sumDiagnosis = new SumDiagnosis |
|
|
|
{ |
|
|
|
DiagnosisId = item.DiagnosisId.Value, |
|
|
|
DisplayOrder = input.IndexOf(item) + 1, |
|
|
|
PatientRegisterId = item.PatientRegisterId, |
|
|
|
SumSuggestionHeaderId = sumSuggestionHeaderEnt_New.Id |
|
|
|
}; |
|
|
|
|
|
|
|
#region 插入SumSuggestionContent
|
|
|
|
List<SumSuggestionContent> sumSuggestionContentList = new List<SumSuggestionContent>(); |
|
|
|
foreach (var item2 in item.Details) |
|
|
|
{ |
|
|
|
SumSuggestionContent sumSuggestionContentEnt = new SumSuggestionContent |
|
|
|
await _sumDiagnosisRepository.InsertAsync(sumDiagnosis); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 插入SumSuggestionContent
|
|
|
|
List<SumSuggestionContent> sumSuggestionContentList = new List<SumSuggestionContent>(); |
|
|
|
foreach (var item2 in item.Details) |
|
|
|
{ |
|
|
|
DisplayOrder = item.Details.IndexOf(item2) + 1, |
|
|
|
SuggestionContent = item2.SuggestionContent, |
|
|
|
SumSuggestionHeaderId = sumSuggestionHeaderEnt_New.Id |
|
|
|
}; |
|
|
|
SumSuggestionContent sumSuggestionContentEnt = new SumSuggestionContent |
|
|
|
{ |
|
|
|
DisplayOrder = item.Details.IndexOf(item2) + 1, |
|
|
|
SuggestionContent = item2.SuggestionContent, |
|
|
|
SumSuggestionHeaderId = sumSuggestionHeaderEnt_New.Id |
|
|
|
}; |
|
|
|
|
|
|
|
sumSuggestionContentList.Add(sumSuggestionContentEnt); |
|
|
|
} |
|
|
|
sumSuggestionContentList.Add(sumSuggestionContentEnt); |
|
|
|
} |
|
|
|
|
|
|
|
await _sumSuggestionContentRepository.InsertManyAsync(sumSuggestionContentList); |
|
|
|
await _sumSuggestionContentRepository.InsertManyAsync(sumSuggestionContentList); |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 清空总诊台建议内容
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="PatientRegisterId"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("api/app/sumsuggestionheader/deletesumsuggestionmany")] |
|
|
|
public async Task DeleteSumSuggestionManyAsync(Guid PatientRegisterId) |
|
|
|
{ |
|
|
|
if (PatientRegisterId != Guid.Empty) |
|
|
|
{ |
|
|
|
await _sumSuggestionHeaderRepository.DeleteAsync(d => d.PatientRegisterId == PatientRegisterId); |
|
|
|
//删除对应的诊断数据
|
|
|
|
await _sumDiagnosisRepository.DeleteAsync(m => m.PatientRegisterId == PatientRegisterId); |
|
|
|
} |
|
|
|
else |
|
|
|
/// <summary>
|
|
|
|
/// 清空总诊台建议内容
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="PatientRegisterId"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("api/app/sumsuggestionheader/deletesumsuggestionmany")] |
|
|
|
public async Task DeleteSumSuggestionManyAsync(Guid PatientRegisterId) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("请求参数有误"); |
|
|
|
if (PatientRegisterId != Guid.Empty) |
|
|
|
{ |
|
|
|
await _sumSuggestionHeaderRepository.DeleteAsync(d => d.PatientRegisterId == PatientRegisterId); |
|
|
|
//删除对应的诊断数据
|
|
|
|
await _sumDiagnosisRepository.DeleteAsync(m => m.PatientRegisterId == PatientRegisterId); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("请求参数有误"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |