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.
		
		
		
		
		
			
		
			
				
					
					
						
							480 lines
						
					
					
						
							25 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							480 lines
						
					
					
						
							25 KiB
						
					
					
				
								using JetBrains.Annotations;
							 | 
						|
								using Microsoft.AspNetCore.Authorization;
							 | 
						|
								using Microsoft.AspNetCore.Mvc;
							 | 
						|
								using Microsoft.EntityFrameworkCore;
							 | 
						|
								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;
							 | 
						|
								using System.Linq;
							 | 
						|
								using System.Text;
							 | 
						|
								using System.Threading.Tasks;
							 | 
						|
								using Volo.Abp.Account;
							 | 
						|
								using Volo.Abp.Application.Services;
							 | 
						|
								using Volo.Abp.Domain.Repositories;
							 | 
						|
								using Volo.Abp.Identity;
							 | 
						|
								
							 | 
						|
								namespace Shentun.Peis.SumSummaryReports
							 | 
						|
								{
							 | 
						|
								    /// <summary>
							 | 
						|
								    /// 总诊台报告
							 | 
						|
								    /// </summary>
							 | 
						|
								    [ApiExplorerSettings(GroupName = "Work")]
							 | 
						|
								    [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> _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> registerCheckAsbitemRepository,
							 | 
						|
								            ISumSummaryReportRepository sumSummaryReportRepository,
							 | 
						|
								            IRepository<ResultStatus> resultStatusRepository,
							 | 
						|
								            CacheService cacheService,
							 | 
						|
								            IRepository<RegisterCheckSummary, Guid> registerCheckSummaryRepository,
							 | 
						|
								            IRepository<Asbitem, Guid> asbitemRepository,
							 | 
						|
								            IRepository<Item, Guid> itemRepository,
							 | 
						|
								            IRepository<RegisterCheckItem> registerCheckItemRepository)
							 | 
						|
								        {
							 | 
						|
								            this._registerCheckRepository = registerCheckRepository;
							 | 
						|
								            this._identityUserRepository = identityUserRepository;
							 | 
						|
								            this._itemTypeRepository = itemTypeRepository;
							 | 
						|
								            this._patientRegisterRepository = patientRegisterRepository;
							 | 
						|
								            this._registerCheckAsbitemRepository = registerCheckAsbitemRepository;
							 | 
						|
								            this._sumSummaryReportRepository = sumSummaryReportRepository;
							 | 
						|
								            _cacheService = cacheService;
							 | 
						|
								            _resultStatusRepository = resultStatusRepository;
							 | 
						|
								            _registerCheckSummaryRepository = registerCheckSummaryRepository;
							 | 
						|
								            _asbitemRepository = asbitemRepository;
							 | 
						|
								            _itemRepository = itemRepository;
							 | 
						|
								            _registerCheckItemRepository = registerCheckItemRepository;
							 | 
						|
								            _patientRepository = patientRepository;
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 获取明细结果报告
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="input">人员登记ID</param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        [HttpPost("api/app/SumSummaryReport/GetDetailResults")]
							 | 
						|
								        public async Task<List<SumSummaryReportDetailResultDto>> GetDetailResultsAsync(PatientRegisterIdInputDto input)
							 | 
						|
								        {
							 | 
						|
								            List<SumSummaryReportDetailResultDto> msg = new List<SumSummaryReportDetailResultDto>();
							 | 
						|
								
							 | 
						|
								            var userlist = await _identityUserRepository.GetListAsync();
							 | 
						|
								            var resultStatus = await _resultStatusRepository.GetListAsync();
							 | 
						|
								            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
							 | 
						|
								
							 | 
						|
								                        }).AsNoTracking().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.itemType.DisplayOrder * 1000 + listItem.asbitem.DisplayOrder;
							 | 
						|
								                    listItem.itemType.DisplayName = parentItemType.DisplayName;
							 | 
						|
								                    listItem.itemType.DisplayOrder = parentItemType.DisplayOrder;
							 | 
						|
								
							 | 
						|
								                }
							 | 
						|
								            }
							 | 
						|
								            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)
							 | 
						|
								            {
							 | 
						|
								                var listItem = list.Where(o => o.registerCheck.Id == registerCheckId).First();
							 | 
						|
								                var detailedResultsList_Asbitem = new SumSummaryReportDetailResultWithAsbitem()
							 | 
						|
								                {
							 | 
						|
								
							 | 
						|
								                    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()),
							 | 
						|
								                    ItemTypeDisplayOrder = listItem.itemType.DisplayOrder,
							 | 
						|
								                    AsbitemDisplayOrder = listItem.asbitem.DisplayOrder,
							 | 
						|
								                    CheckDate = ((DateTime)listItem.registerCheck.CheckDate).Date,
							 | 
						|
								                    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) ? 16777215 : 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.Summary)
							 | 
						|
								                               .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)
							 | 
						|
								                {
							 | 
						|
								                    var historyRegisterCheckItems = histroyList.GroupBy(o=>o.registerCheckItem)
							 | 
						|
								                         .Select(o => o.First().registerCheckItem )
							 | 
						|
								                         .Where(o => o.ItemId == registerCheckItem.ItemId)
							 | 
						|
								                         .Distinct().ToList();
							 | 
						|
								
							 | 
						|
								                    for (var i = 0; i < historyRegisterCheckItems.Count; i++)
							 | 
						|
								                    {
							 | 
						|
								                        if(i== 0)
							 | 
						|
								                        {
							 | 
						|
								                            registerCheckItem.PreviousItemResult = historyRegisterCheckItems[i].Result;
							 | 
						|
								                            registerCheckItem.PreviousReportFontColor = (resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].ResultStatusId).FirstOrDefault() == null) ? 0 : resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].ResultStatusId).FirstOrDefault().ReportFontColor;
							 | 
						|
								                            registerCheckItem.PreviousReportBackgroundColor = (resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].ResultStatusId).FirstOrDefault() == null) ? 16777215 : resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].ResultStatusId).FirstOrDefault().ReportBackgroundColor;
							 | 
						|
								                        }
							 | 
						|
								                        else if(i== 1)
							 | 
						|
								                        {
							 | 
						|
								                            registerCheckItem.PreviousTwoItemResult = historyRegisterCheckItems[i].Result;
							 | 
						|
								                            registerCheckItem.PreviousTwoReportFontColor = (resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].ResultStatusId).FirstOrDefault() == null) ? 0 : resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].ResultStatusId).FirstOrDefault().ReportFontColor;
							 | 
						|
								                            registerCheckItem.PreviousTwoReportBackgroundColor = (resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].ResultStatusId).FirstOrDefault() == null) ? 16777215 : resultStatus.Where(x => x.Id == historyRegisterCheckItems[i].ResultStatusId).FirstOrDefault().ReportBackgroundColor;
							 | 
						|
								                        }
							 | 
						|
								                    }
							 | 
						|
								                }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								                detailedResultsList_Asbitems.Add(detailedResultsList_Asbitem);
							 | 
						|
								
							 | 
						|
								            }
							 | 
						|
								
							 | 
						|
								            var grouplist = detailedResultsList_Asbitems.OrderBy(o=>o.ItemTypeDisplayOrder)
							 | 
						|
								                .OrderBy(o=>o.AsbitemDisplayOrder)
							 | 
						|
								                .GroupBy(g => g.ItemTypeName);
							 | 
						|
								
							 | 
						|
								            foreach (var g in grouplist)
							 | 
						|
								            {
							 | 
						|
								                var glist = g.ToList();
							 | 
						|
								                var resultlist = new SumSummaryReportDetailResultDto
							 | 
						|
								                {
							 | 
						|
								                    ItemTypeName = glist.FirstOrDefault().ItemTypeName,
							 | 
						|
								                    Asbitems = glist
							 | 
						|
								                };
							 | 
						|
								
							 | 
						|
								                msg.Add(resultlist);
							 | 
						|
								            }
							 | 
						|
								
							 | 
						|
								            return msg;
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 获取项目类别对比报告
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="PatientId">档案ID(不是档案号)</param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        [HttpGet("api/app/sumsummaryreport/getitemtypecontrastlist")]
							 | 
						|
								        public async Task<List<ItemTypeContrastListDto>> GetItemTypeContrastListAsync(Guid PatientId)
							 | 
						|
								        {
							 | 
						|
								            List<ItemTypeContrastListDto> msg = new List<ItemTypeContrastListDto>();
							 | 
						|
								
							 | 
						|
								            var query = from a in await _patientRegisterRepository.GetQueryableAsync()
							 | 
						|
								                        join b in await _registerCheckRepository.GetQueryableAsync() on a.Id equals b.PatientRegisterId
							 | 
						|
								                        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
							 | 
						|
								                        join f in await _registerCheckSummaryRepository.GetQueryableAsync() on b.Id equals f.RegisterCheckId into ff
							 | 
						|
								                        from af in ff.DefaultIfEmpty()
							 | 
						|
								                        where a.PatientId == PatientId && a.CompleteFlag != PatientRegisterCompleteFlag.PreRegistration
							 | 
						|
								                        select new
							 | 
						|
								                        {
							 | 
						|
								                            RegisterDate = a.CreationTime,
							 | 
						|
								                            PatientRegisterId = a.Id,
							 | 
						|
								                            ItemTypeName = e.DisplayName,
							 | 
						|
								                            Summary = af != null ? af.Summary : ""
							 | 
						|
								                        };
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								            var grouplist = query.ToList().GroupBy(g => new { g.PatientRegisterId, g.ItemTypeName });
							 | 
						|
								
							 | 
						|
								            foreach (var g in grouplist)
							 | 
						|
								            {
							 | 
						|
								                var glist = g.ToList();
							 | 
						|
								                var resultlist = new ItemTypeContrastListDto
							 | 
						|
								                {
							 | 
						|
								
							 | 
						|
								                    ItemTypeName = glist.FirstOrDefault().ItemTypeName,
							 | 
						|
								                    RegisterDate = DataHelper.ConversionDateToString(glist.FirstOrDefault().RegisterDate),
							 | 
						|
								                    Summarys = string.Join("\n", glist.Select(s => s.Summary).ToList())
							 | 
						|
								                };
							 | 
						|
								                msg.Add(resultlist);
							 | 
						|
								            }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								            return msg.OrderBy(o => o.ItemTypeName).ThenBy(o => o.RegisterDate).ToList();
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 获取历次综述
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="PatientId">档案ID(不是档案号)</param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        [HttpGet("api/app/sumsummaryreport/gethistoricalreviewlist")]
							 | 
						|
								        public async Task<List<HistoricalReviewListDto>> GetHistoricalReviewListAsync(Guid PatientId)
							 | 
						|
								        {
							 | 
						|
								            List<ItemTypeContrastListDto> msg = new List<ItemTypeContrastListDto>();
							 | 
						|
								
							 | 
						|
								            var userlist = await _identityUserRepository.GetListAsync();
							 | 
						|
								
							 | 
						|
								            var entlist = (await _patientRegisterRepository.GetDbSetAsync())
							 | 
						|
								                 .Include(x => x.SumSummaryHeaders)
							 | 
						|
								                 .ThenInclude(x => x.SumSummaryContents)
							 | 
						|
								                 .Include(x => x.SumSuggestionHeaders)
							 | 
						|
								                 .ThenInclude(x => x.SumSuggestionContents)
							 | 
						|
								                 .Where(m => m.PatientId == PatientId && (m.SumSummaryHeaders.Count > 0 || m.SumSuggestionHeaders.Count > 0)
							 | 
						|
								                 && m.CompleteFlag != PatientRegisterCompleteFlag.PreRegistration)
							 | 
						|
								                 .ToList();
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								            //以registercheck表为主
							 | 
						|
								            var registercheckList = entlist.Select(s => new HistoricalReviewListDto
							 | 
						|
								            {
							 | 
						|
								                MedicalTimes = s.MedicalTimes,
							 | 
						|
								                SummaryDate = DataHelper.ConversionDateToString(s.SummaryDate),
							 | 
						|
								                SummaryDoctor = _cacheService.GetSurnameAsync(s.SummaryDoctorId).Result,
							 | 
						|
								                SumSuggestions = SetSumSuggestions(s.SumSuggestionHeaders.ToList()),
							 | 
						|
								                SumSummarys = SetSumSummarys(s.SumSummaryHeaders.ToList())
							 | 
						|
								            }).OrderByDescending(o => o.MedicalTimes).ToList();
							 | 
						|
								
							 | 
						|
								            return registercheckList;
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 获取横向对比 左侧组合项目
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="PatientId"></param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        [HttpGet("api/app/sumsummaryreport/gethorizontalcomparisonasbitemlist")]
							 | 
						|
								        public async Task<List<HorizontalComparisonAsbitemListDto>> GetHorizontalComparisonAsbitemListAsync(Guid PatientId)
							 | 
						|
								        {
							 | 
						|
								
							 | 
						|
								            List<HorizontalComparisonAsbitemListDto> entdto = new List<HorizontalComparisonAsbitemListDto>();
							 | 
						|
								
							 | 
						|
								            var entlist = (await _registerCheckAsbitemRepository.GetDbSetAsync())
							 | 
						|
								            .Include(x => x.Asbitem)
							 | 
						|
								            .Include(x => x.RegisterCheck)
							 | 
						|
								            .Include(x => x.PatientRegister)
							 | 
						|
								            .Where(m => m.PatientRegister.PatientId == PatientId && m.PatientRegister.CompleteFlag != PatientRegisterCompleteFlag.PreRegistration)
							 | 
						|
								            .ToList();
							 | 
						|
								
							 | 
						|
								            var grouplist = entlist.GroupBy(o => o.AsbitemId);
							 | 
						|
								
							 | 
						|
								            foreach (var g in grouplist)
							 | 
						|
								            {
							 | 
						|
								                //var resultlist = new ItemTypeContrastListDto
							 | 
						|
								                //{
							 | 
						|
								
							 | 
						|
								                //    ItemTypeName = glist.FirstOrDefault().ItemTypeName,
							 | 
						|
								                //    RegisterDate = glist.FirstOrDefault().RegisterDate,
							 | 
						|
								                //    Summarys = string.Join("\n", glist.Select(s => s.Summarys).ToList())
							 | 
						|
								                //};
							 | 
						|
								
							 | 
						|
								                var glist = g.ToList();
							 | 
						|
								
							 | 
						|
								                var ent = new HorizontalComparisonAsbitemListDto
							 | 
						|
								                {
							 | 
						|
								                    AsbitemId = glist.Any() ? glist.FirstOrDefault().AsbitemId : Guid.Empty,
							 | 
						|
								                    AsbitemName = glist.Any() ? glist.FirstOrDefault().Asbitem.DisplayName : "",
							 | 
						|
								                    CompleteFlag = glist.Any() ? glist.OrderByDescending(m => m.CreationTime).FirstOrDefault().RegisterCheck.CompleteFlag : RegisterCheckCompleteFlag.UnChecked
							 | 
						|
								                };
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								                entdto.Add(ent);
							 | 
						|
								            }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								            //var entdto = entlist.Select(s => new HorizontalComparisonAsbitemListDto
							 | 
						|
								            //{
							 | 
						|
								            //    AsbitemId = s.AsbitemId,
							 | 
						|
								            //    AsbitemName = s.Asbitem.DisplayName,
							 | 
						|
								            //    CompleteFlag = s.RegisterChecks.FirstOrDefault(m => m.CreationTime)
							 | 
						|
								            //}).ToList();
							 | 
						|
								
							 | 
						|
								            return entdto;
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 获取横向对比数据
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="PatientId"></param>
							 | 
						|
								        /// <param name="AsbitemId"></param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        [HttpGet("api/app/sumsummaryreport/gethorizontalcomparisonlist")]
							 | 
						|
								        public async Task<List<HorizontalComparisonListDto>> GetHorizontalComparisonListAsync(Guid PatientId, Guid AsbitemId)
							 | 
						|
								        {
							 | 
						|
								
							 | 
						|
								            var entlist = await _sumSummaryReportRepository.GetHorizontalComparisonListAsync(PatientId, AsbitemId);
							 | 
						|
								
							 | 
						|
								            var entdto = ObjectMapper.Map<List<HorizontalComparisonListEntity>, List<HorizontalComparisonListDto>>(entlist);
							 | 
						|
								
							 | 
						|
								            return entdto;
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 生成历次综述医生小结
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="SumSummaryHeaders"></param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        private string SetSumSummarys(List<SumSummaryHeader> SumSummaryHeaders)
							 | 
						|
								        {
							 | 
						|
								            StringBuilder msg = new StringBuilder();
							 | 
						|
								            if (SumSummaryHeaders.Count > 0)
							 | 
						|
								            {
							 | 
						|
								                foreach (var item in SumSummaryHeaders)
							 | 
						|
								                {
							 | 
						|
								                    msg.Append("*  " + item.SummaryTitle + ":" + "<br/>");
							 | 
						|
								                    if (item.SumSummaryContents.Count > 0)
							 | 
						|
								                    {
							 | 
						|
								                        var SumSummaryContents = item.SumSummaryContents.ToList();
							 | 
						|
								                        foreach (var item2 in SumSummaryContents)
							 | 
						|
								                        {
							 | 
						|
								                            msg.Append("(" + SumSummaryContents.IndexOf(item2) + 1 + ")" + item2.SummaryContent + "<br/>");
							 | 
						|
								                        }
							 | 
						|
								                    }
							 | 
						|
								                }
							 | 
						|
								            }
							 | 
						|
								            return msg.ToString();
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 生成历次综述医生建议
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="SumSuggestionHeaders"></param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        private string SetSumSuggestions(List<SumSuggestionHeader> SumSuggestionHeaders)
							 | 
						|
								        {
							 | 
						|
								            StringBuilder msg = new StringBuilder();
							 | 
						|
								            if (SumSuggestionHeaders.Count > 0)
							 | 
						|
								            {
							 | 
						|
								                foreach (var item in SumSuggestionHeaders)
							 | 
						|
								                {
							 | 
						|
								                    msg.Append("*  " + item.SuggestionTitle + ":" + "<br/>");
							 | 
						|
								                    if (item.SumSuggestionContents.Count > 0)
							 | 
						|
								                    {
							 | 
						|
								                        var SumSuggestionContents = item.SumSuggestionContents.ToList();
							 | 
						|
								                        foreach (var item2 in SumSuggestionContents)
							 | 
						|
								                        {
							 | 
						|
								                            msg.Append("(" + SumSuggestionContents.IndexOf(item2) + 1 + ")" + item2.SuggestionContent + "<br/>");
							 | 
						|
								                        }
							 | 
						|
								                    }
							 | 
						|
								                }
							 | 
						|
								            }
							 | 
						|
								            return msg.ToString();
							 | 
						|
								        }
							 | 
						|
								    }
							 | 
						|
								}
							 |