diff --git a/src/Shentun.Peis.Application.Contracts/PeisReports/HealthStatisticsDto.cs b/src/Shentun.Peis.Application.Contracts/PeisReports/HealthStatisticsDto.cs new file mode 100644 index 0000000..1e100bb --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/PeisReports/HealthStatisticsDto.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.PeisReports +{ + public class HealthStatisticsDto + { + /// + /// 男性人数 + /// + public int MaleCount { get; set; } + + /// + /// 女性人数 + /// + public int FemaleCount { get; set; } + + /// + /// 合计人数 包含了未知 + /// + public int SumCount { get; set; } + + /// + /// 标准金额 + /// + public decimal StandardMoney { get; set; } + + /// + /// 实收金额 + /// + public decimal ChargeMoney { get; set; } + + + } +} diff --git a/src/Shentun.Peis.Application.Contracts/PeisReports/HealthStatisticsInputDto.cs b/src/Shentun.Peis.Application.Contracts/PeisReports/HealthStatisticsInputDto.cs new file mode 100644 index 0000000..99168fb --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/PeisReports/HealthStatisticsInputDto.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace Shentun.Peis.PeisReports +{ + public class HealthStatisticsInputDto + { + /// + /// 体检类别ID集合 + /// + public List MedicalTypeIds { get; set; } + + /// + /// 是否查询未填写体检类别 Y=查询未填写体检类别的数据 N=不查询 + /// + public char IsMedicalTypeId { get; set; }= 'Y'; + + /// + /// 单位ID 集合 + /// + public List CustomerOrgIds { get; set; } = new List(); + + /// + /// 日期类型(1、登记日期 2、体检日期 3、总检日期) + /// + public char DateType { get; set; } = '1'; + + /// + /// 开始日期 + /// + public string StartDate { get; set; } + + + /// + /// 结束日期 + /// + public string EndDate { get; set; } + } +} diff --git a/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs b/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs index 296f8ab..b233583 100644 --- a/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs +++ b/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using Shentun.Peis.CustomerOrgs; using Shentun.Peis.Enums; using Shentun.Peis.Models; @@ -33,7 +34,7 @@ namespace Shentun.Peis.PeisReports private readonly IRepository _medicalPackageRepository; private readonly IRepository _customerOrgRepository; private readonly IRepository _sexRepository; - private readonly IRepository _registerAsbitemRepository; + private readonly IRepository _registerCheckAsbitemRepository; private readonly IRepository _registerCheckRepository; private readonly IRepository _asbitemRepository; private readonly CustomerOrgManager _customerOrgManager; @@ -48,7 +49,7 @@ namespace Shentun.Peis.PeisReports IRepository medicalPackageRepository, IRepository customerOrgRepository, IRepository sexRepository, - IRepository registerAsbitemRepository, + IRepository registerCheckAsbitemRepository, IRepository registerCheckRepository, IRepository asbitemRepository, CustomerOrgManager customerOrgManager, @@ -63,7 +64,7 @@ namespace Shentun.Peis.PeisReports this._medicalPackageRepository = medicalPackageRepository; this._customerOrgRepository = customerOrgRepository; this._sexRepository = sexRepository; - this._registerAsbitemRepository = registerAsbitemRepository; + this._registerCheckAsbitemRepository = registerCheckAsbitemRepository; this._registerCheckRepository = registerCheckRepository; this._asbitemRepository = asbitemRepository; this._customerOrgManager = customerOrgManager; @@ -83,7 +84,7 @@ namespace Shentun.Peis.PeisReports join b in await _patientRepository.GetQueryableAsync() on a.PatientId equals b.Id into bb from ab in bb.DefaultIfEmpty() join registerCheck in await _registerCheckRepository.GetQueryableAsync() on a.Id equals registerCheck.PatientRegisterId - join registerAsbitem in await _registerAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerAsbitem.RegisterCheckId + join registerAsbitem in await _registerCheckAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerAsbitem.RegisterCheckId join asbitem in await _asbitemRepository.GetQueryableAsync() on registerAsbitem.AsbitemId equals asbitem.Id join c in await _customerOrgGroupRepository.GetQueryableAsync() on a.CustomerOrgGroupId equals c.Id into cc from ac in cc.DefaultIfEmpty() @@ -366,7 +367,7 @@ namespace Shentun.Peis.PeisReports [HttpPost("api/app/peisreport/getregisterasbitemregistercheckstatus")] public async Task> GetRegisterAsbitemRegisterCheckStatusAsync(GetRegisterAsbitemRegisterCheckStatusRequestDto input) { - var query = from j in await _registerAsbitemRepository.GetQueryableAsync() + var query = from j in await _registerCheckAsbitemRepository.GetQueryableAsync() join k in await _registerCheckRepository.GetQueryableAsync() on j.RegisterCheckId equals k.Id into kk from jk in kk.DefaultIfEmpty() join l in await _patientRegisterRepository.GetQueryableAsync() on j.PatientRegisterId equals l.Id into ll @@ -534,7 +535,7 @@ namespace Shentun.Peis.PeisReports public async Task> GetRegisterAsbitemChargeStatusAsync(GetRegisterAsbitemChargeStatusRequestDto input) { - var query = from j in await _registerAsbitemRepository.GetQueryableAsync() + var query = from j in await _registerCheckAsbitemRepository.GetQueryableAsync() join k in await _registerCheckRepository.GetQueryableAsync() on j.RegisterCheckId equals k.Id into kk from jk in kk.DefaultIfEmpty() join l in await _patientRegisterRepository.GetQueryableAsync() on j.PatientRegisterId equals l.Id into ll @@ -712,7 +713,7 @@ namespace Shentun.Peis.PeisReports from af in ff.DefaultIfEmpty() join g in await _sexRepository.GetQueryableAsync() on a.SexId equals g.Id into gg from ag in gg.DefaultIfEmpty() - join aj in await _registerAsbitemRepository.GetQueryableAsync() on a.Id equals aj.PatientRegisterId + join aj in await _registerCheckAsbitemRepository.GetQueryableAsync() on a.Id equals aj.PatientRegisterId join ak in await _registerCheckRepository.GetQueryableAsync() on aj.RegisterCheckId equals ak.Id join al in await _asbitemRepository.GetQueryableAsync() on aj.AsbitemId equals al.Id //join j in await _registerAsbitemRepository.GetQueryableAsync() on a.Id equals j.PatientRegisterId into jj @@ -866,5 +867,89 @@ namespace Shentun.Peis.PeisReports return entlist; } + + /// + /// 健康统计数据 + /// + /// + [HttpPost("api/app/PeisReport/GetHealthStatistics")] + public async Task GetHealthStatisticsAsync(HealthStatisticsInputDto input) + { + var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync() + join registerCheck in await _registerCheckRepository.GetQueryableAsync() on patientRegister.Id equals registerCheck.PatientRegisterId + join registerCheckAsbitem in await _registerCheckAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckAsbitem.RegisterCheckId + select new + { + patientRegister, + registerCheck, + registerCheckAsbitem + }; + if (input.MedicalTypeIds.Any()) + { + if (input.IsMedicalTypeId == 'Y') + { + query = query.Where(m => input.MedicalTypeIds.Contains(m.patientRegister.MedicalTypeId) || m.patientRegister.MedicalTypeId == null); + } + else + { + query = query.Where(m => input.MedicalTypeIds.Contains(m.patientRegister.MedicalTypeId)); + } + } + if (input.CustomerOrgIds.Any()) + { + List ids = new List(); + + foreach (var item in input.CustomerOrgIds) + { + var CustomerOrgIds = await _customerOrgManager.GetCustomerOrgChildrenId(item); + ids.AddRange(CustomerOrgIds); + } + + + query = query.Where(m => ids.Contains(m.patientRegister.CustomerOrgId)); + } + + if (!string.IsNullOrEmpty(input.StartDate) && !string.IsNullOrEmpty(input.EndDate)) + { + if (input.DateType == '1') + { + query = query.Where(m => m.patientRegister.CreationTime >= Convert.ToDateTime(input.StartDate) && + m.patientRegister.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1)); + } + else if (input.DateType == '2') + { + query = query.Where(m => m.patientRegister.MedicalStartDate != null && m.patientRegister.MedicalStartDate.Value >= Convert.ToDateTime(input.StartDate) && + m.patientRegister.MedicalStartDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1)); + } + else if (input.DateType == '3') + { + query = query.Where(m => m.patientRegister.SummaryDate != null && m.patientRegister.SummaryDate.Value >= Convert.ToDateTime(input.StartDate) && + m.patientRegister.SummaryDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1)); + } + } + + var dataList = query.ToList(); + + var patientRegisterGroup = dataList.GroupBy(g => g.patientRegister); + + var maleCount = patientRegisterGroup.Where(m => m.Key.SexId == SexFlag.Male).Count(); + var femaleCount = patientRegisterGroup.Where(m => m.Key.SexId == SexFlag.Female).Count(); + var sumCount = patientRegisterGroup.Count(); + + var standardPrice = dataList.Sum(s => s.registerCheckAsbitem.StandardPrice * s.registerCheckAsbitem.Amount); + var chargePrice = dataList.Sum(s => s.registerCheckAsbitem.ChargePrice * s.registerCheckAsbitem.Amount); + + var resultDto = new HealthStatisticsDto + { + ChargeMoney = chargePrice, + FemaleCount = femaleCount, + MaleCount = maleCount, + SumCount = sumCount, + StandardMoney = standardPrice + }; + + return resultDto; + } + } }