diff --git a/src/Shentun.Peis.Domain/DataHelper.cs b/src/Shentun.Peis.Domain/DataHelper.cs index 101aee2..0a4bd26 100644 --- a/src/Shentun.Peis.Domain/DataHelper.cs +++ b/src/Shentun.Peis.Domain/DataHelper.cs @@ -94,6 +94,26 @@ namespace Shentun.Peis return msg.ToString(); } + /// + /// 生成建议 + /// + /// + /// + /// + public static string SetSuggestionInReport(string diagnosisName, List suggestionList) + { + StringBuilder msg = new StringBuilder(); + msg.Append("* " + diagnosisName + ":" + "\n"); + if (suggestionList.Count > 0) + { + foreach (var item in suggestionList) + { + msg.Append("(" + suggestionList.IndexOf(item) + 1 + ")" + item.SuggestionContent + "\n"); + } + } + return msg.ToString(); + } + /// /// 统一转换日期为字符串格式 /// diff --git a/src/Shentun.Peis.Domain/ReportTemplates/CustomerOrgReportManager.cs b/src/Shentun.Peis.Domain/ReportTemplates/CustomerOrgReportManager.cs index c4541c9..79d43d0 100644 --- a/src/Shentun.Peis.Domain/ReportTemplates/CustomerOrgReportManager.cs +++ b/src/Shentun.Peis.Domain/ReportTemplates/CustomerOrgReportManager.cs @@ -33,7 +33,8 @@ namespace Shentun.Peis.ReportTemplates private readonly IRepository _sumSuggestionHeaderRepository; private readonly IRepository _customerOrgRepository; private readonly CacheService _cacheService; - + private readonly IRepository _diagnosisRepository; + private readonly IRepository _suggestionRepository; private readonly string DirectoryName = System.AppDomain.CurrentDomain.BaseDirectory + @"\ReportFile"; public CustomerOrgReportManager( @@ -48,7 +49,9 @@ namespace Shentun.Peis.ReportTemplates IRepository sumDiagnosisRepository, IRepository sumSuggestionHeaderRepository, IRepository customerOrgRepository, - CacheService cacheService) + CacheService cacheService, + IRepository diagnosisRepository, + IRepository suggestionRepository) { _patientRegisterRepository = patientRegisterRepository; _customerOrgManager = customerOrgManager; @@ -62,6 +65,8 @@ namespace Shentun.Peis.ReportTemplates _sumSuggestionHeaderRepository = sumSuggestionHeaderRepository; _customerOrgRepository = customerOrgRepository; _cacheService = cacheService; + _diagnosisRepository = diagnosisRepository; + _suggestionRepository = suggestionRepository; } @@ -260,7 +265,8 @@ namespace Shentun.Peis.ReportTemplates table6.Rows[rowIndex].Cells[4].Paragraphs[0].Append(item.TotalNumber.ToString()); table6.Rows[rowIndex].Cells[5].Paragraphs[0].Append(item.MaleRatio); table6.Rows[rowIndex].Cells[6].Paragraphs[0].Append(item.FemaleRatio); - table6.Rows[rowIndex].Cells[7].Paragraphs[0].Append(item.AverageRatio); + table6.Rows[rowIndex].Cells[7].Paragraphs[0].Append(""); + // table6.Rows[rowIndex].Cells[7].Paragraphs[0].Append(item.AverageRatio); rowIndex++; if (rowIndex - 2 < table6Data.Count) table6.InsertRow(); } @@ -600,9 +606,9 @@ namespace Shentun.Peis.ReportTemplates p3Row2.Cells[4].Paragraphs[0].AppendDocProperty(p3_Register_TotalNumber).Font(f).FontSize(10.5).Alignment = Alignment.center; p3Row2.Cells[5].Paragraphs[0].AppendDocProperty(p3_Register_MaleRatio).Font(f).FontSize(10.5).Alignment = Alignment.center; p3Row2.Cells[6].Paragraphs[0].AppendDocProperty(p3_Register_FemaleRatio).Font(f).FontSize(10.5).Alignment = Alignment.center; - p3Row2.Cells[7].Paragraphs[0].Append("100%").Font(f).FontSize(10.5).Alignment = Alignment.center; - p3Row2.Cells[8].Paragraphs[0].Append("100%").Font(f).FontSize(10.5).Alignment = Alignment.center; - p3Row2.Cells[9].Paragraphs[0].Append("100%").Font(f).FontSize(10.5).Alignment = Alignment.center; + p3Row2.Cells[7].Paragraphs[0].Append("").Font(f).FontSize(10.5).Alignment = Alignment.center; + p3Row2.Cells[8].Paragraphs[0].Append("").Font(f).FontSize(10.5).Alignment = Alignment.center; + p3Row2.Cells[9].Paragraphs[0].Append("").Font(f).FontSize(10.5).Alignment = Alignment.center; Row p3Row3 = p3rowsContent[3]; p3Row3.Cells[0].Paragraphs[0].Append("实检").Font(f).FontSize(10.5).Alignment = Alignment.center; @@ -778,7 +784,7 @@ namespace Shentun.Peis.ReportTemplates p5Table2Row1.Cells[5].FillColor = Color.FromArgb(209, 245, 203); p5Table2Row1.Cells[6].Paragraphs[0].Append("女性").Font(f).FontSize(10.5).Alignment = Alignment.center; p5Table2Row1.Cells[6].FillColor = Color.FromArgb(209, 245, 203); - p5Table2Row1.Cells[7].Paragraphs[0].Append("平均").Font(f).FontSize(10.5).Alignment = Alignment.center; + p5Table2Row1.Cells[7].Paragraphs[0].Append("").Font(f).FontSize(10.5).Alignment = Alignment.center; p5Table2Row1.Cells[7].FillColor = Color.FromArgb(209, 245, 203); p5Content1.InsertTableAfterSelf(p5Contenttable2); @@ -1495,7 +1501,7 @@ namespace Shentun.Peis.ReportTemplates Math.Round(s.Where(m => m.SexId == SexFlag.Female).Count() * 100M / s.Where(m => m.SexId == SexFlag.Male || m.SexId == SexFlag.Female).Count(), 2).ToString() + "%" : "0%", AverageRatio = s.Where(m => m.SexId == SexFlag.Male || m.SexId == SexFlag.Female).Count() != 0 ? Math.Round((Math.Round(s.Where(m => m.SexId == SexFlag.Male).Count() * 100M / s.Where(m => m.SexId == SexFlag.Male || m.SexId == SexFlag.Female).Count(), 2) - + Math.Round(s.Where(m => m.SexId == SexFlag.Female).Count() * 100M / s.Where(m => m.SexId == SexFlag.Male || m.SexId == SexFlag.Female).Count(), 2)) / 2, 2).ToString() : "0%" + + Math.Round(s.Where(m => m.SexId == SexFlag.Female).Count() * 100M / s.Where(m => m.SexId == SexFlag.Male || m.SexId == SexFlag.Female).Count(), 2)) / 2, 2).ToString() + "%" : "0%" }).OrderByDescending(o => o.TotalNumber); documentData.MedicalAbnormalResultStatistics = medicalAbnormalResultStatistics.ToList(); @@ -1504,30 +1510,34 @@ namespace Shentun.Peis.ReportTemplates /// - /// 生成本次体检异常结果检出统计数据 5 + /// 本次体检前十大异常结果分析数据 5 /// /// 数据 /// 参数 /// public async Task CreateMedicalTenAbnormalResultsData(UnitPhysicalExaminationReportExportWordData documentData, CreateInspectionPersonnelPara customerOrgs) { + #region 查询 - var query = from a in (await _sumDiagnosisRepository.GetQueryableAsync()).Include(x => x.Diagnosis) - join b in await _patientRegisterRepository.GetQueryableAsync() on a.PatientRegisterId equals b.Id - join c in (await _sumSuggestionHeaderRepository.GetQueryableAsync()).Include(x => x.SumSuggestionContents) on a.SumSuggestionHeaderId equals c.Id into cc - from ac in cc.DefaultIfEmpty() - where b.CompleteFlag == PatientRegisterCompleteFlag.SumCheck + var query = from sumDiagnosis in await _sumDiagnosisRepository.GetQueryableAsync() + join diagnosis in await _diagnosisRepository.GetQueryableAsync() on sumDiagnosis.DiagnosisId equals diagnosis.Id + join patientRegister in await _patientRegisterRepository.GetQueryableAsync() on sumDiagnosis.PatientRegisterId equals patientRegister.Id + join suggestion in await _suggestionRepository.GetQueryableAsync() on sumDiagnosis.DiagnosisId equals suggestion.DiagnosisId into suggestionTemp + from suggestionEmpty in suggestionTemp.DefaultIfEmpty() + where patientRegister.CompleteFlag == PatientRegisterCompleteFlag.SumCheck + && suggestionEmpty.SuggestionType == SuggestionTypeFlag.HealthGuidance select new { - CustomerOrgGroupId = b.CustomerOrgGroupId, - CustomerOrgRegisterId = b.CustomerOrgRegisterId, - CustomerOrgId = b.CustomerOrgId, - CreationTime = b.CreationTime, - MedicalStartDate = b.MedicalStartDate, - SummaryDate = b.SummaryDate, - DiagnosisId = a.DiagnosisId, - DiagnosisName = a.Diagnosis != null ? a.Diagnosis.DisplayName : "", - ac + CustomerOrgGroupId = patientRegister.CustomerOrgGroupId, + CustomerOrgRegisterId = patientRegister.CustomerOrgRegisterId, + CustomerOrgId = patientRegister.CustomerOrgId, + CreationTime = patientRegister.CreationTime, + MedicalStartDate = patientRegister.MedicalStartDate, + SummaryDate = patientRegister.SummaryDate, + DiagnosisId = sumDiagnosis.DiagnosisId, + DiagnosisName = diagnosis.DisplayName, + suggestionEmpty, + sumDiagnosis }; @@ -1559,13 +1569,86 @@ namespace Shentun.Peis.ReportTemplates } #endregion - var medicalTenAbnormalResults = query.ToList().GroupBy(g => g.DiagnosisId).Select(s => new UnitPhysicalExaminationReportExportWordData_MedicalTenAbnormalResult - { - DiagnosisName = s.FirstOrDefault().DiagnosisName, - DiagnosisSuggestion = DataHelper.SetSumSuggestionInReport(s.Where(m => m.ac != null).Select(ss => ss.ac).ToList()) - }); + + var sumDiagnosisGroup = query.ToList().GroupBy(g => g.sumDiagnosis) + .Select(s => new + { + DiagnosisId = s.FirstOrDefault().DiagnosisId, + DiagnosisName = s.FirstOrDefault().DiagnosisName, + SuggestionEmpty = s.Where(m => m.suggestionEmpty != null).Select(ss => ss.suggestionEmpty).Distinct().ToList() + }).ToList(); + + var medicalTenAbnormalResults = sumDiagnosisGroup.GroupBy(g => g.DiagnosisId) + .OrderByDescending(o => o.Count()) + .Take(10) + .Select(s => new UnitPhysicalExaminationReportExportWordData_MedicalTenAbnormalResult + { + DiagnosisName = s.FirstOrDefault().DiagnosisName, + DiagnosisSuggestion = DataHelper.SetSuggestionInReport(s.FirstOrDefault().DiagnosisName, s.FirstOrDefault().SuggestionEmpty) + }); documentData.MedicalTenAbnormalResults = medicalTenAbnormalResults.ToList(); + + + + + + + // #region 查询 + // var query = from a in (await _sumDiagnosisRepository.GetQueryableAsync()).Include(x => x.Diagnosis) + // join b in await _patientRegisterRepository.GetQueryableAsync() on a.PatientRegisterId equals b.Id + // join c in (await _sumSuggestionHeaderRepository.GetQueryableAsync()).Include(x => x.SumSuggestionContents) on a.SumSuggestionHeaderId equals c.Id into cc + // from ac in cc.DefaultIfEmpty() + // where b.CompleteFlag == PatientRegisterCompleteFlag.SumCheck + // select new + // { + // CustomerOrgGroupId = b.CustomerOrgGroupId, + // CustomerOrgRegisterId = b.CustomerOrgRegisterId, + // CustomerOrgId = b.CustomerOrgId, + // CreationTime = b.CreationTime, + // MedicalStartDate = b.MedicalStartDate, + // SummaryDate = b.SummaryDate, + // DiagnosisId = a.DiagnosisId, + // DiagnosisName = a.Diagnosis != null ? a.Diagnosis.DisplayName : "", + // ac + // }; + + + // if (customerOrgs.CustomerOrgGroupId.Any()) + // { + // query = query.Where(m => m.CustomerOrgGroupId != null && customerOrgs.CustomerOrgGroupId.Contains(m.CustomerOrgGroupId.Value)); + // } + // if (customerOrgs.CustomerOrgRegisterId != GuidFlag.PersonCustomerOrgRegisterId) + // { + // query = query.Where(m => m.CustomerOrgRegisterId == customerOrgs.CustomerOrgRegisterId); + // } + + // var customerOrgIds = await _customerOrgManager.GetCustomerOrgChildrenId(customerOrgs.CustomerOrgId); + // query = query.Where(m => customerOrgIds.Contains(m.CustomerOrgId)); + // if (customerOrgs.DateType == '1') + // { + // query = query.Where(m => m.CreationTime >= Convert.ToDateTime(customerOrgs.StartDate) && + // m.CreationTime < Convert.ToDateTime(customerOrgs.EndDate).AddDays(1)); + // } + // else if (customerOrgs.DateType == '2') + // { + // query = query.Where(m => m.MedicalStartDate != null && m.MedicalStartDate.Value >= Convert.ToDateTime(customerOrgs.StartDate) && + // m.MedicalStartDate.Value < Convert.ToDateTime(customerOrgs.EndDate).AddDays(1)); + // } + // else if (customerOrgs.DateType == '3') + // { + // query = query.Where(m => m.SummaryDate != null && m.SummaryDate.Value >= Convert.ToDateTime(customerOrgs.StartDate) && + //m.SummaryDate.Value < Convert.ToDateTime(customerOrgs.EndDate).AddDays(1)); + // } + // #endregion + + // var medicalTenAbnormalResults = query.ToList().GroupBy(g => g.DiagnosisId).Select(s => new UnitPhysicalExaminationReportExportWordData_MedicalTenAbnormalResult + // { + // DiagnosisName = s.FirstOrDefault().DiagnosisName, + // DiagnosisSuggestion = DataHelper.SetSumSuggestionInReport(s.Where(m => m.ac != null).Select(ss => ss.ac).ToList()) + // }); + + // documentData.MedicalTenAbnormalResults = medicalTenAbnormalResults.ToList(); } diff --git a/src/Shentun.Peis.Domain/ReportTemplates/UnitPhysicalExaminationReportExportWordData.cs b/src/Shentun.Peis.Domain/ReportTemplates/UnitPhysicalExaminationReportExportWordData.cs index a03fae6..c8a9a8c 100644 --- a/src/Shentun.Peis.Domain/ReportTemplates/UnitPhysicalExaminationReportExportWordData.cs +++ b/src/Shentun.Peis.Domain/ReportTemplates/UnitPhysicalExaminationReportExportWordData.cs @@ -298,6 +298,7 @@ namespace Shentun.Peis.ReportTemplates /// public string DiagnosisSuggestion { get; set; } + }