using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Shentun.Peis.Models; using Shentun.Peis.PatientRegisters; using Shentun.Peis.SumSuggestionContents; using Shentun.Peis.SumSuggestionHeaders; using Shentun.Peis.SumSummaryContents; using Shentun.Peis.SumSummaryHeaders; using Shentun.Peis.SumSummaryReports; using Shentun.Peis.SysParmValues; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TencentCloud.Wedata.V20210820.Models; using Volo.Abp; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; using Volo.Abp.Identity; namespace Shentun.Peis.PrintReports { /// /// 打印报告服务 /// [ApiExplorerSettings(GroupName = "Work")] [Authorize] public class PrintReportAppService : ApplicationService { private readonly IRepository _customerOrgRepository; private readonly IRepository _patientRegisterRepository; private readonly IRepository _sexRegisterRepository; private readonly IRepository _resultStatusRepository; private readonly IRepository _sumSummaryHeaderRepository; private readonly IRepository _identityUserRepository; private readonly IRepository _sumSuggestionHeaderRepository; private readonly IRepository _registerCheckRepository; private readonly IOrganizationUnitRepository _organizationUnitRepository; private readonly IPatientRegisterGuideReportRepository _patientRegisterGuideReportRepository; private readonly ILisRequestReportRepository _lisRequestReportRepository; private readonly ICheckRequestNoReportRepository _checkRequestNoReportRepository; private readonly IChargeReportRepository _chargeReportRepository; private readonly SysParmValueManager _sysParmValueManager; public PrintReportAppService( IRepository customerOrgRepository, IRepository patientRegisterRepository, IRepository sexRegisterRepository, IRepository resultStatusRepository, IRepository sumSummaryHeaderRepository, IRepository identityUserRepository, IRepository sumSuggestionHeaderRepository, IRepository registerCheckRepository, IOrganizationUnitRepository organizationUnitRepository, IPatientRegisterGuideReportRepository patientRegisterGuideReportRepository, ILisRequestReportRepository lisRequestReportRepository, ICheckRequestNoReportRepository checkRequestNoReportRepository, IChargeReportRepository chargeReportRepository, SysParmValueManager sysParmValueManager ) { this._customerOrgRepository = customerOrgRepository; this._patientRegisterRepository = patientRegisterRepository; this._sexRegisterRepository = sexRegisterRepository; this._resultStatusRepository = resultStatusRepository; this._sumSummaryHeaderRepository = sumSummaryHeaderRepository; this._identityUserRepository = identityUserRepository; this._sumSuggestionHeaderRepository = sumSuggestionHeaderRepository; this._registerCheckRepository = registerCheckRepository; this._organizationUnitRepository = organizationUnitRepository; this._patientRegisterGuideReportRepository = patientRegisterGuideReportRepository; this._lisRequestReportRepository = lisRequestReportRepository; this._checkRequestNoReportRepository = checkRequestNoReportRepository; this._chargeReportRepository = chargeReportRepository; this._sysParmValueManager = sysParmValueManager; } /// /// 获取体检人员指引单报告数据 /// /// /// [HttpPost("api/app/printreport/getpatientregisterguidereport")] public async Task GetPatientRegisterGuideReportAsync(Guid PatientRegisterId) { return await _patientRegisterGuideReportRepository.GetPatientRegisterGuideReportAsync(PatientRegisterId); } /// /// 批量获取体检人员指引单报告数据 /// /// /// [HttpPost("api/app/printreport/getpatientregisterguidereportmany")] public async Task> GetPatientRegisterGuideReportManyAsync(List PatientRegisterIds) { return await _patientRegisterGuideReportRepository.GetPatientRegisterGuideReportManyAsync(PatientRegisterIds); } /// /// 打印检验申请单 /// /// /// [HttpPost("api/app/printreport/getlisrequestreport")] public async Task> GetLisRequestReportAsync(Guid PatientRegisterId) { return await _lisRequestReportRepository.GetLisRequestReportAsync(PatientRegisterId); } /// /// 打印体检报告 /// /// /// [HttpPost("api/app/printreport/getpeisreport")] public async Task GetPeisReportAsync(Guid PatientRegisterId) { PeisReportDto msg = new PeisReportDto(); var userlist = await _identityUserRepository.GetListAsync(); var customerOrgList = await _customerOrgRepository.GetListAsync(); var organizationUnitList = await _organizationUnitRepository.GetListAsync(); var sexList = await _sexRegisterRepository.GetListAsync(); var patientRegisterEnt = (await _patientRegisterRepository.GetDbSetAsync()) .Include(x => x.Patient) .Where(m => m.Id == PatientRegisterId).FirstOrDefault(); if (patientRegisterEnt != null) { #region 系统参数配置 var MedicalCenterAddress = await _sysParmValueManager.GetSysParmValueInMedicalCenterId(patientRegisterEnt.MedicalCenterId, "medical_center_address"); var MedicalCenterFax = await _sysParmValueManager.GetSysParmValueInMedicalCenterId(patientRegisterEnt.MedicalCenterId, "medical_center_fax"); var MedicalCenterTelphone = await _sysParmValueManager.GetSysParmValueInMedicalCenterId(patientRegisterEnt.MedicalCenterId, "medical_center_telphone"); #endregion msg = new PeisReportDto { Age = patientRegisterEnt.Age, CustomerOrgName = EntityHelper.GetCustomerOrgParentNameNoSql(customerOrgList, patientRegisterEnt.CustomerOrgId), DepartmentName = EntityHelper.GetCustomerOrgNameNoSql(customerOrgList, patientRegisterEnt.CustomerOrgId), MedicalCenterTelphone = MedicalCenterTelphone, detailedResultsListDtos = new List(), MedicalCenterAddress = MedicalCenterAddress, MedicalStartDate = patientRegisterEnt.MedicalStartDate.ToString(), OrganizationUnitId = patientRegisterEnt.MedicalCenterId, OrganizationUnitName = organizationUnitList.Where(m => m.Id == patientRegisterEnt.MedicalCenterId).Select(s => s.DisplayName).FirstOrDefault(), PatientName = patientRegisterEnt.PatientName, PatientNo = patientRegisterEnt.Patient.PatientNo, PatientRegisterNo = patientRegisterEnt.PatientRegisterNo, resultStatusDtos = new List(), sumSuggestionHeaderOrContentDtos = new List(), SexName = sexList.Where(m => m.Id == patientRegisterEnt.SexId).Select(s => s.DisplayName).FirstOrDefault(), SummaryDate = patientRegisterEnt.SummaryDate.ToString(), sumSummaryHeaderOrContentDtos = new List() }; #region 结果状态 var resultStatusList = (await _resultStatusRepository.GetListAsync()); if (resultStatusList.Any()) { msg.resultStatusDtos = resultStatusList.Select(s => new ResultStatuses.ResultStatusDto { DataInputBackgroundColor = s.DataInputBackgroundColor, DataInputFontColor = s.DataInputFontColor, DataInputPrompt = s.DataInputPrompt, DisplayName = s.DisplayName, DisplayOrder = s.DisplayOrder, Id = s.Id, ReportBackgroundColor = s.ReportBackgroundColor, ReportFontColor = s.ReportFontColor, ReportPrompt = s.ReportPrompt }).OrderBy(o => o.DisplayOrder).ToList(); } #endregion #region 小结 var sumSummarylist = (await _sumSummaryHeaderRepository.GetDbSetAsync()) .Include(x => x.SumSummaryContents) .Where(m => m.PatientRegisterId == PatientRegisterId).OrderBy(o => o.DisplayOrder).ToList(); if (sumSummarylist.Any()) { msg.sumSummaryHeaderOrContentDtos = sumSummarylist.Select(s => new SumSummaryHeaderOrContentDto { SummaryTitle = s.SummaryTitle, SummaryFlag = s.SummaryFlag, PatientRegisterId = s.PatientRegisterId, DisplayOrder = s.DisplayOrder, Id = s.Id, Details = s.SumSummaryContents.OrderBy(o => o.DisplayOrder).Select(sa => new SumSummaryContentDto { DisplayOrder = sa.DisplayOrder, SummaryContent = sa.SummaryContent, SumSummaryHeaderId = sa.SumSummaryHeaderId, }).OrderBy(o => o.DisplayOrder).ToList() }).OrderBy(o => o.DisplayOrder).ToList(); } #endregion #region 建议 var sumSuggestionlist = (await _sumSuggestionHeaderRepository.GetDbSetAsync()) .Include(x => x.SumSuggestionContents) .Where(m => m.PatientRegisterId == PatientRegisterId).OrderBy(o => o.DisplayOrder).ToList(); if (sumSuggestionlist.Any()) { msg.sumSuggestionHeaderOrContentDtos = sumSuggestionlist.Select(s => new SumSuggestionHeaderOrContentDto { SuggestionTitle = s.SuggestionTitle, SuggestionFlag = s.SuggestionFlag, PatientRegisterId = s.PatientRegisterId, DisplayOrder = s.DisplayOrder, Id = s.Id, Details = s.SumSuggestionContents.OrderBy(o => o.DisplayOrder).Select(sa => new SumSuggestionContentDto { DisplayOrder = sa.DisplayOrder, SuggestionContent = sa.SuggestionContent, SumSuggestionHeaderId = sa.SumSuggestionHeaderId }).OrderBy(o => o.DisplayOrder).ToList() }).OrderBy(o => o.DisplayOrder).ToList(); } #endregion #region 明细结果 var detailedResultsList = new List(); var registerChecklist = (await _registerCheckRepository.GetDbSetAsync()) .Include(x => x.RegisterCheckAsbitems) .ThenInclude(x => x.Asbitem) .ThenInclude(x => x.ItemType) .Include(x => x.RegisterCheckSummaries) .Include(x => x.RegisterCheckItems) .ThenInclude(x => x.Item) .Where(m => m.RegisterCheckAsbitems.Select(s => s.PatientRegisterId).Contains(PatientRegisterId)) .ToList(); var asbitemList = registerChecklist.Select(s => new DetailedResultsList_Asbitem { AsbitemName = string.Join(",", s.RegisterCheckAsbitems.Select(rs => rs.Asbitem.DisplayName).ToList()), ItemTypeName = string.Join(",", s.RegisterCheckAsbitems.Select(rs => rs.Asbitem.ItemType.DisplayName).ToList()), CheckDate = s.CheckDate.ToString(), CheckDoctorName = EntityHelper.GetCheckDoctorName(s.CheckDoctorId, userlist), Items = s.RegisterCheckItems.Select(sa => new DetailedResultsList_Asbitem_Item { CriticalRangeValue = sa.CriticalRangeValue, ItemName = sa.Item.DisplayName, ItemResult = sa.Result, ReferenceRangeValue = sa.ReferenceRangeValue, ResultStatusName = sa.ResultStatusId, Unit = sa.Unit }).ToList(), Summarys = s.RegisterCheckSummaries.Count > 0 ? s.RegisterCheckSummaries.Select(sb => new DetailedResultsList_Asbitem_Summary { Summary = sb.Summary, }).ToList() : new List() }).ToList(); var grouplist = asbitemList.GroupBy(g => g.ItemTypeName); foreach (var g in grouplist) { var glist = g.ToList(); var resultlist = new DetailedResultsListDto { ItemTypeName = glist.FirstOrDefault().ItemTypeName, Asbitems = glist }; detailedResultsList.Add(resultlist); } if (detailedResultsList.Any()) { msg.detailedResultsListDtos = detailedResultsList; } #endregion } return msg; } /// /// 打印Pacs条码数据 /// /// /// [HttpPost("api/app/printreport/getpacsnoreport")] public async Task> GetPacsNoReportAsync(Guid PatientRegisterId) { return await _checkRequestNoReportRepository.GetPacsNoReportAsync(PatientRegisterId); } /// /// 打印收费单 /// /// 收费主表ID /// [HttpPost("api/app/printreport/getchargereport")] public async Task GetChargeReportAsync(Guid ChargeId) { return await _chargeReportRepository.GetChargeReportAsync(ChargeId); } } }