|
|
|
@ -6,6 +6,8 @@ using Microsoft.VisualBasic; |
|
|
|
using NPOI.OpenXmlFormats.Wordprocessing; |
|
|
|
using Shentun.Peis.Enums; |
|
|
|
using Shentun.Peis.Models; |
|
|
|
using Shentun.Peis.PatientRegisters; |
|
|
|
using SqlSugar; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Immutable; |
|
|
|
@ -26,93 +28,216 @@ namespace Shentun.Peis.SumSummaryReports |
|
|
|
[Authorize] |
|
|
|
public class SumSummaryReportAppService : ApplicationService |
|
|
|
{ |
|
|
|
private readonly IRepository<Patient, Guid> _patientRepository; |
|
|
|
private readonly IRepository<RegisterCheck, Guid> _registerCheckRepository; |
|
|
|
private readonly IRepository<IdentityUser, Guid> _identityUserRepository; |
|
|
|
private readonly IRepository<ItemType, Guid> _itemTypeRepository; |
|
|
|
private readonly IRepository<RegisterCheckItem> _registerCheckItemRepository; |
|
|
|
private readonly IRepository<Item, Guid> _itemRepository; |
|
|
|
private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository; |
|
|
|
private readonly IRepository<RegisterCheckAsbitem, Guid> _registerAsbitemRepository; |
|
|
|
private readonly IRepository<RegisterCheckAsbitem, Guid> _registerCheckAsbitemRepository; |
|
|
|
private readonly IRepository<ResultStatus> _resultStatusRepository; |
|
|
|
private readonly ISumSummaryReportRepository _sumSummaryReportRepository; |
|
|
|
private readonly CacheService _cacheService; |
|
|
|
private readonly IRepository<RegisterCheckSummary, Guid> _registerCheckSummaryRepository; |
|
|
|
private readonly IRepository<Asbitem, Guid> _asbitemRepository; |
|
|
|
public SumSummaryReportAppService( |
|
|
|
IRepository<Patient, Guid> patientRepository, |
|
|
|
IRepository<RegisterCheck, Guid> registerCheckRepository, |
|
|
|
IRepository<IdentityUser, Guid> identityUserRepository, |
|
|
|
IRepository<ItemType, Guid> itemTypeRepository, |
|
|
|
IRepository<PatientRegister, Guid> patientRegisterRepository, |
|
|
|
IRepository<RegisterCheckAsbitem, Guid> registerAsbitemRepository, |
|
|
|
IRepository<RegisterCheckAsbitem, Guid> registerCheckAsbitemRepository, |
|
|
|
ISumSummaryReportRepository sumSummaryReportRepository, |
|
|
|
IRepository<ResultStatus> resultStatusRepository, |
|
|
|
CacheService cacheService, |
|
|
|
IRepository<RegisterCheckSummary, Guid> registerCheckSummaryRepository, |
|
|
|
IRepository<Asbitem, Guid> asbitemRepository) |
|
|
|
IRepository<Asbitem, Guid> asbitemRepository, |
|
|
|
IRepository<Item, Guid> itemRepository, |
|
|
|
IRepository<RegisterCheckItem> registerCheckItemRepository) |
|
|
|
{ |
|
|
|
this._registerCheckRepository = registerCheckRepository; |
|
|
|
this._identityUserRepository = identityUserRepository; |
|
|
|
this._itemTypeRepository = itemTypeRepository; |
|
|
|
this._patientRegisterRepository = patientRegisterRepository; |
|
|
|
this._registerAsbitemRepository = registerAsbitemRepository; |
|
|
|
this._registerCheckAsbitemRepository = registerCheckAsbitemRepository; |
|
|
|
this._sumSummaryReportRepository = sumSummaryReportRepository; |
|
|
|
_cacheService = cacheService; |
|
|
|
_resultStatusRepository = resultStatusRepository; |
|
|
|
_registerCheckSummaryRepository = registerCheckSummaryRepository; |
|
|
|
_asbitemRepository = asbitemRepository; |
|
|
|
_itemRepository = itemRepository; |
|
|
|
_registerCheckItemRepository = registerCheckItemRepository; |
|
|
|
_patientRepository = patientRepository; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取明细结果报告
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="PatientRegisterId">人员登记ID</param>
|
|
|
|
/// <param name="input">人员登记ID</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("api/app/sumsummaryreport/getdetailedresultslist")] |
|
|
|
public async Task<List<DetailedResultsListDto>> GetDetailedResultsListAsync(Guid PatientRegisterId) |
|
|
|
[HttpGet("api/app/SumSummaryReport/GetDetailResults")] |
|
|
|
public async Task<List<SumSummaryReportDetailResultDto>> GetDetailResultsAsync(PatientRegisterIdInputDto input) |
|
|
|
{ |
|
|
|
List<DetailedResultsListDto> msg = new List<DetailedResultsListDto>(); |
|
|
|
List<SumSummaryReportDetailResultDto> msg = new List<SumSummaryReportDetailResultDto>(); |
|
|
|
|
|
|
|
var userlist = await _identityUserRepository.GetListAsync(); |
|
|
|
var resultStatus = await _resultStatusRepository.GetListAsync(); |
|
|
|
var entlist = (await _registerCheckRepository.GetDbSetAsync()) |
|
|
|
.Include(x => x.RegisterCheckAsbitems) |
|
|
|
.ThenInclude(x => x.Asbitem) |
|
|
|
.ThenInclude(x => x.ItemType) |
|
|
|
.ThenInclude(x => x.MedicalReportType) |
|
|
|
.Include(x => x.RegisterCheckSummaries) |
|
|
|
.Include(x => x.RegisterCheckItems) |
|
|
|
.ThenInclude(x => x.Item) |
|
|
|
.Where(m => m.RegisterCheckAsbitems.Select(s => s.PatientRegisterId).Contains(PatientRegisterId) && |
|
|
|
m.CompleteFlag == RegisterCheckCompleteFlag.Checked) |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
var list = (from patient in await _patientRepository.GetQueryableAsync() |
|
|
|
join patientRegister in await _patientRegisterRepository.GetQueryableAsync() |
|
|
|
on patient.Id equals patientRegister.PatientId |
|
|
|
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 registerCheckSummary in await _registerCheckSummaryRepository.GetQueryableAsync() |
|
|
|
on registerCheck.Id equals registerCheckSummary.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 itemType in await _itemTypeRepository.GetQueryableAsync() |
|
|
|
on asbitem.ItemTypeId equals itemType.Id |
|
|
|
where patientRegister.Id == input.PatientRegisterId |
|
|
|
select new |
|
|
|
{ |
|
|
|
patient, |
|
|
|
patientRegister, |
|
|
|
registerCheck, |
|
|
|
registerCheckSummary, |
|
|
|
registerCheckAsbitem, |
|
|
|
asbitem, |
|
|
|
registerCheckItem, |
|
|
|
item, |
|
|
|
itemType |
|
|
|
|
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
if (!list.Any()) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
//获取历次结果
|
|
|
|
var histroyList = (from patient in await _patientRepository.GetQueryableAsync() |
|
|
|
join patientRegister in await _patientRegisterRepository.GetQueryableAsync() |
|
|
|
on patient.Id equals patientRegister.PatientId |
|
|
|
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 registerCheckSummary in await _registerCheckSummaryRepository.GetQueryableAsync() |
|
|
|
on registerCheck.Id equals registerCheckSummary.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 itemType in await _itemTypeRepository.GetQueryableAsync() |
|
|
|
on asbitem.ItemTypeId equals itemType.Id |
|
|
|
where patient.Id == list.First().patient.Id |
|
|
|
&& (patientRegister.CompleteFlag == PatientRegisterCompleteFlag.SumCheck || patientRegister.CompleteFlag == PatientRegisterCompleteFlag.Audit) |
|
|
|
&& patientRegister.MedicalTimes < list.First().patientRegister.MedicalTimes |
|
|
|
select new |
|
|
|
{ |
|
|
|
patient, |
|
|
|
patientRegister, |
|
|
|
registerCheck, |
|
|
|
registerCheckSummary, |
|
|
|
registerCheckAsbitem, |
|
|
|
asbitem, |
|
|
|
registerCheckItem, |
|
|
|
item, |
|
|
|
itemType |
|
|
|
|
|
|
|
}).OrderByDescending(o => o.patientRegister.MedicalTimes).ToList(); |
|
|
|
//将子项目类别设置为父项目类别
|
|
|
|
var itemTypes = await _itemTypeRepository.GetListAsync(); |
|
|
|
foreach (var listItem in list) |
|
|
|
{ |
|
|
|
var parentItemType = itemTypes.Where(o => o.Id == listItem.itemType.ParentId).FirstOrDefault(); |
|
|
|
if (parentItemType != null) |
|
|
|
{ |
|
|
|
listItem.asbitem.DisplayOrder = listItem.asbitem.ItemType.DisplayOrder * 1000 + listItem.asbitem.DisplayOrder; |
|
|
|
listItem.itemType.DisplayName = parentItemType.DisplayName; |
|
|
|
listItem.itemType.DisplayOrder = parentItemType.DisplayOrder; |
|
|
|
|
|
|
|
var asbitemList = entlist.Select(s => new DetailedResultsList_Asbitem |
|
|
|
} |
|
|
|
} |
|
|
|
var detailedResultsList_Asbitems = new List<SumSummaryReportDetailResultWithAsbitem>(); |
|
|
|
var registerCheckIds = list.OrderBy(o => o.itemType.DisplayOrder) |
|
|
|
.OrderBy(o => o.asbitem.DisplayOrder) |
|
|
|
.Select(o => o.registerCheck.Id).Distinct().ToList(); |
|
|
|
foreach (var registerCheckId in registerCheckIds) |
|
|
|
{ |
|
|
|
AsbitemName = string.Join(",", s.RegisterCheckAsbitems.Select(rs => rs.Asbitem.DisplayName).ToList()), |
|
|
|
ItemTypeName = string.Join(",", s.RegisterCheckAsbitems.Select(rs => rs.Asbitem.ItemType.DisplayName).ToList()), |
|
|
|
CheckDate = DataHelper.ConversionDateToString(s.CheckDate), |
|
|
|
CheckDoctorName = EntityHelper.GetCheckDoctorName(s.CheckDoctorId, userlist), |
|
|
|
Items = s.RegisterCheckItems.Select(sa => new DetailedResultsList_Asbitem_Item |
|
|
|
var listItem = list.Where(o => o.registerCheck.Id == registerCheckId).First(); |
|
|
|
var detailedResultsList_Asbitem = new SumSummaryReportDetailResultWithAsbitem() |
|
|
|
{ |
|
|
|
CriticalRangeValue = sa.CriticalRangeValue, |
|
|
|
ItemName = sa.Item.DisplayName, |
|
|
|
ItemResult = sa.Result, |
|
|
|
ReferenceRangeValue = sa.ReferenceRangeValue, |
|
|
|
ResultStatusName = (resultStatus.Where(o => o.Id == sa.ResultStatusId).FirstOrDefault() == null) ? "" : resultStatus.Where(o => o.Id == sa.ResultStatusId).FirstOrDefault().ReportPrompt, |
|
|
|
Unit = sa.Unit |
|
|
|
}).ToList(), |
|
|
|
Summarys = s.RegisterCheckSummaries.Count > 0 ? s.RegisterCheckSummaries.Select(sb => new DetailedResultsList_Asbitem_Summary |
|
|
|
ItemTypeName = listItem.itemType.DisplayName, |
|
|
|
AsbitemName = string.Join(",", list.Where(o => o.registerCheck.Id == registerCheckId) |
|
|
|
.OrderBy(o => o.itemType.DisplayOrder).OrderBy(o => o.asbitem.DisplayOrder) |
|
|
|
.Select(o => o.asbitem.DisplayName).Distinct().ToList()), |
|
|
|
CheckDate = (DateTime)listItem.registerCheck.CheckDate, |
|
|
|
CheckDoctorName = EntityHelper.GetCheckDoctorName(listItem.registerCheck.CheckDoctorId, userlist), |
|
|
|
Items = list.Where(o => o.registerCheck.Id == registerCheckId) |
|
|
|
.OrderBy(o => o.itemType.DisplayOrder).OrderBy(o => o.asbitem.DisplayOrder).OrderBy(o => o.item.DisplayOrder) |
|
|
|
.Select(o => new SumSummaryReportDetailResultWithItem() |
|
|
|
{ |
|
|
|
ItemId = o.registerCheckItem.ItemId, |
|
|
|
ItemName = o.item.DisplayName, |
|
|
|
ItemResult = o.registerCheckItem.Result, |
|
|
|
ReferenceRangeValue = o.registerCheckItem.ReferenceRangeValue, |
|
|
|
CriticalRangeValue = o.registerCheckItem.CriticalRangeValue, |
|
|
|
Unit = o.registerCheckItem.Unit, |
|
|
|
ResultStatusId = o.registerCheckItem.ResultStatusId, |
|
|
|
ResultStatusName = (resultStatus.Where(x => x.Id == o.registerCheckItem.ResultStatusId).FirstOrDefault() == null) ? "" : resultStatus.Where(x => x.Id == o.registerCheckItem.ResultStatusId).FirstOrDefault().ReportPrompt, |
|
|
|
ReportFontColor = (resultStatus.Where(x => x.Id == o.registerCheckItem.ResultStatusId).FirstOrDefault() == null) ? 0 : resultStatus.Where(x => x.Id == o.registerCheckItem.ResultStatusId).FirstOrDefault().ReportFontColor, |
|
|
|
ReportBackgroundColor = (resultStatus.Where(x => x.Id == o.registerCheckItem.ResultStatusId).FirstOrDefault() == null) ? 16579836 : resultStatus.Where(x => x.Id == o.registerCheckItem.ResultStatusId).FirstOrDefault().ReportBackgroundColor, |
|
|
|
}).Distinct().ToList(), |
|
|
|
Summarys = list.Where(o => o.registerCheck.Id == registerCheckId) |
|
|
|
.OrderBy(o=>o.registerCheckSummary.DisplayOrder) |
|
|
|
.GroupBy(o=>o.registerCheckSummary) |
|
|
|
.Select(o=> new SumSummaryReportDetailResultWithSummary(){ |
|
|
|
Summary = o.FirstOrDefault().registerCheckSummary.Summary }) |
|
|
|
.ToList<SumSummaryReportDetailResultWithSummary>(), |
|
|
|
|
|
|
|
}; |
|
|
|
detailedResultsList_Asbitem.Summarys = detailedResultsList_Asbitem.Summarys.Distinct().ToList(); |
|
|
|
foreach (var registerCheckItem in detailedResultsList_Asbitem.Items) |
|
|
|
{ |
|
|
|
Summary = sb.Summary, |
|
|
|
}).ToList() : new List<DetailedResultsList_Asbitem_Summary>() |
|
|
|
}).ToList(); |
|
|
|
var historyRegisterCheckItems = histroyList.Select(o => new { o.registerCheckItem }) |
|
|
|
.Where(o => o.registerCheckItem.ItemId == registerCheckItem.ItemId).Distinct().ToList(); |
|
|
|
|
|
|
|
for (var i = 0; i < historyRegisterCheckItems.Count; i++) |
|
|
|
{ |
|
|
|
if(i== 0) |
|
|
|
{ |
|
|
|
registerCheckItem.PreviousItemResult = historyRegisterCheckItems[i].registerCheckItem.Result; |
|
|
|
registerCheckItem.PreviousReportFontColor = (resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].registerCheckItem.ResultStatusId).FirstOrDefault() == null) ? 0 : resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].registerCheckItem.ResultStatusId).FirstOrDefault().ReportFontColor; |
|
|
|
registerCheckItem.PreviousReportBackgroundColor = (resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].registerCheckItem.ResultStatusId).FirstOrDefault() == null) ? 0 : resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].registerCheckItem.ResultStatusId).FirstOrDefault().ReportBackgroundColor; |
|
|
|
} |
|
|
|
else if(i== 1) |
|
|
|
{ |
|
|
|
registerCheckItem.PreviousTwoItemResult = historyRegisterCheckItems[i].registerCheckItem.Result; |
|
|
|
registerCheckItem.PreviousTwoReportFontColor = (resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].registerCheckItem.ResultStatusId).FirstOrDefault() == null) ? 0 : resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].registerCheckItem.ResultStatusId).FirstOrDefault().ReportFontColor; |
|
|
|
registerCheckItem.PreviousTwoReportBackgroundColor = (resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].registerCheckItem.ResultStatusId).FirstOrDefault() == null) ? 0 : resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].registerCheckItem.ResultStatusId).FirstOrDefault().ReportBackgroundColor; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var grouplist = asbitemList.GroupBy(g => g.ItemTypeName); |
|
|
|
detailedResultsList_Asbitems.Add(detailedResultsList_Asbitem); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var grouplist = detailedResultsList_Asbitems.GroupBy(g => g.ItemTypeName); |
|
|
|
|
|
|
|
foreach (var g in grouplist) |
|
|
|
{ |
|
|
|
var glist = g.ToList(); |
|
|
|
var resultlist = new DetailedResultsListDto |
|
|
|
var resultlist = new SumSummaryReportDetailResultDto |
|
|
|
{ |
|
|
|
ItemTypeName = glist.FirstOrDefault().ItemTypeName, |
|
|
|
Asbitems = glist |
|
|
|
@ -137,7 +262,7 @@ namespace Shentun.Peis.SumSummaryReports |
|
|
|
|
|
|
|
var query = from a in await _patientRegisterRepository.GetQueryableAsync() |
|
|
|
join b in await _registerCheckRepository.GetQueryableAsync() on a.Id equals b.PatientRegisterId |
|
|
|
join c in await _registerAsbitemRepository.GetQueryableAsync() on b.Id equals c.RegisterCheckId |
|
|
|
join c in await _registerCheckAsbitemRepository.GetQueryableAsync() on b.Id equals c.RegisterCheckId |
|
|
|
join d in await _asbitemRepository.GetQueryableAsync() on c.AsbitemId equals d.Id into dd |
|
|
|
from ad in dd.DefaultIfEmpty() |
|
|
|
join e in await _itemTypeRepository.GetQueryableAsync() on ad.ItemTypeId equals e.Id |
|
|
|
@ -225,7 +350,7 @@ namespace Shentun.Peis.SumSummaryReports |
|
|
|
|
|
|
|
List<HorizontalComparisonAsbitemListDto> entdto = new List<HorizontalComparisonAsbitemListDto>(); |
|
|
|
|
|
|
|
var entlist = (await _registerAsbitemRepository.GetDbSetAsync()) |
|
|
|
var entlist = (await _registerCheckAsbitemRepository.GetDbSetAsync()) |
|
|
|
.Include(x => x.Asbitem) |
|
|
|
.Include(x => x.RegisterCheck) |
|
|
|
.Include(x => x.PatientRegister) |
|
|
|
|