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.

686 lines
30 KiB

11 months ago
4 months ago
11 months ago
4 months ago
11 months ago
4 months ago
11 months ago
4 months ago
11 months ago
4 months ago
11 months ago
4 months ago
11 months ago
5 months ago
4 months ago
11 months ago
5 months ago
4 months ago
11 months ago
5 months ago
4 months ago
11 months ago
4 months ago
11 months ago
4 months ago
11 months ago
4 months ago
11 months ago
4 months ago
11 months ago
4 months ago
11 months ago
4 months ago
11 months ago
5 months ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
5 months ago
11 months ago
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.EntityFrameworkCore.Metadata.Internal;
  4. using Microsoft.Extensions.Configuration;
  5. using Newtonsoft.Json;
  6. using NPOI.POIFS.Storage;
  7. using Shentun.Peis.DirectorManagement;
  8. using Shentun.Peis.Enums;
  9. using Shentun.Peis.InternalReports;
  10. using Shentun.Peis.Models;
  11. using Shentun.Peis.PatientRegisters;
  12. using Shentun.Peis.PrintReports;
  13. using Shentun.Peis.TransToWebPeiss;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Net.Http;
  19. using System.Net.Http.Headers;
  20. using System.Text;
  21. using System.Threading;
  22. using System.Threading.Tasks;
  23. using Volo.Abp;
  24. using Volo.Abp.Application.Services;
  25. using Volo.Abp.Domain.Repositories;
  26. namespace Shentun.Peis.DirectorManagements
  27. {
  28. /// <summary>
  29. /// 主任管理报表数据
  30. /// </summary>
  31. [ApiExplorerSettings(GroupName = "Work")]
  32. [Authorize]
  33. public class DirectorManagementAppService : ApplicationService
  34. {
  35. private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository;
  36. private readonly IRepository<Patient, Guid> _patientRepository;
  37. private readonly CacheService _cacheService;
  38. private readonly IRepository<RegisterCheck, Guid> _registerCheckRepository;
  39. private readonly IRepository<RegisterCheckAsbitem, Guid> _registerCheckAsbitemRepository;
  40. private readonly IRepository<Asbitem, Guid> _asbitemRepository;
  41. private readonly IRepository<MedicalPackage, Guid> _medicalPackageRepository;
  42. private readonly IRepository<CustomerOrg, Guid> _customerOrgRepository;
  43. private readonly InternalReportAppService _internalReportAppService;
  44. private readonly IRepository<ThirdInterface, Guid> _thirdInterfaceRepository;
  45. private readonly PrintReportAppService _printReportAppService;
  46. public DirectorManagementAppService(
  47. IRepository<PatientRegister, Guid> patientRegisterRepository,
  48. IRepository<Patient, Guid> patientRepository,
  49. CacheService cacheService,
  50. IRepository<RegisterCheck, Guid> registerCheckRepository,
  51. IRepository<RegisterCheckAsbitem, Guid> registerCheckAsbitemRepository,
  52. IRepository<Asbitem, Guid> asbitemRepository,
  53. IRepository<MedicalPackage, Guid> medicalPackageRepository,
  54. IRepository<CustomerOrg, Guid> customerOrgRepository,
  55. InternalReportAppService internalReportAppService,
  56. IRepository<ThirdInterface, Guid> thirdInterfaceRepository,
  57. PrintReportAppService printReportAppService)
  58. {
  59. _patientRegisterRepository = patientRegisterRepository;
  60. _patientRepository = patientRepository;
  61. _cacheService = cacheService;
  62. _registerCheckRepository = registerCheckRepository;
  63. _registerCheckAsbitemRepository = registerCheckAsbitemRepository;
  64. _asbitemRepository = asbitemRepository;
  65. _medicalPackageRepository = medicalPackageRepository;
  66. _customerOrgRepository = customerOrgRepository;
  67. _internalReportAppService = internalReportAppService;
  68. _thirdInterfaceRepository = thirdInterfaceRepository;
  69. _printReportAppService = printReportAppService;
  70. }
  71. /// <summary>
  72. /// 查询客户信息
  73. /// </summary>
  74. /// <returns></returns>
  75. [HttpPost("api/app/DirectorManagement/GetPatientList")]
  76. public async Task<List<GetPatientListDto>> GetPatientListAsync(GetPatientListInputDto input)
  77. {
  78. var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
  79. join patient in await _patientRepository.GetQueryableAsync() on patientRegister.PatientId equals patient.Id
  80. select new
  81. {
  82. idNo = patient.IdNo,
  83. mobileTelephone = patient.MobileTelephone,
  84. nationId = patient.NationId,
  85. patientRegister
  86. };
  87. if (!string.IsNullOrWhiteSpace(input.IdNo))
  88. {
  89. query = query.Where(m => m.idNo == input.IdNo);
  90. }
  91. if (!string.IsNullOrWhiteSpace(input.PatientName))
  92. {
  93. query = query.Where(m => m.patientRegister.PatientName == input.PatientName);
  94. }
  95. if (string.IsNullOrWhiteSpace(input.IdNo) && string.IsNullOrWhiteSpace(input.PatientName))
  96. {
  97. if (input.DateType != null
  98. && !string.IsNullOrWhiteSpace(input.StartDate)
  99. && !string.IsNullOrWhiteSpace(input.EndDate))
  100. {
  101. if (input.DateType == '1')
  102. {
  103. query = query.Where(m => m.patientRegister.CreationTime >= Convert.ToDateTime(input.StartDate)
  104. && m.patientRegister.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1));
  105. }
  106. else if (input.DateType == '2')
  107. {
  108. query = query.Where(m => m.patientRegister.MedicalStartDate != null
  109. && m.patientRegister.MedicalStartDate.Value >= Convert.ToDateTime(input.StartDate)
  110. && m.patientRegister.MedicalStartDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1));
  111. }
  112. else if (input.DateType == '3')
  113. {
  114. query = query.Where(m => m.patientRegister.SummaryDate != null
  115. && m.patientRegister.SummaryDate.Value >= Convert.ToDateTime(input.StartDate)
  116. && m.patientRegister.SummaryDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1));
  117. }
  118. }
  119. else
  120. {
  121. throw new UserFriendlyException("日期参数不完整");
  122. }
  123. }
  124. var entListDto = query.ToList().Select(s => new GetPatientListDto
  125. {
  126. Age = s.patientRegister.Age == null ? "" : s.patientRegister.Age.Value.ToString(),
  127. CompleteFlag = s.patientRegister.CompleteFlag.ToString(),
  128. IdNo = s.idNo,
  129. MaritalStatusName = _cacheService.GetMaritalStatusNameAsync(s.patientRegister.MaritalStatusId).GetAwaiter().GetResult(),
  130. MedicalStartDate = DataHelper.ConversionDateToString(s.patientRegister.MedicalStartDate),
  131. MedicalTimes = s.patientRegister.MedicalTimes,
  132. MobileTelephone = s.mobileTelephone,
  133. NationName = _cacheService.GetNationNameAsync(s.nationId).GetAwaiter().GetResult(),
  134. PatientName = s.patientRegister.PatientName,
  135. SexName = _cacheService.GetSexNameAsync(s.patientRegister.SexId).GetAwaiter().GetResult()
  136. }).ToList();
  137. return entListDto;
  138. }
  139. /// <summary>
  140. /// 收入统计 查询某个时间断
  141. /// </summary>
  142. /// <param name="input"></param>
  143. /// <returns></returns>
  144. [HttpPost("api/app/DirectorManagement/GetRevenueReport")]
  145. public async Task<GetRevenueReportDto> GetRevenueReportAsync(GetRevenueReportInputDto input)
  146. {
  147. if (string.IsNullOrWhiteSpace(input.StartDate) || string.IsNullOrWhiteSpace(input.EndDate))
  148. {
  149. throw new UserFriendlyException("请选择查询时间段");
  150. }
  151. var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
  152. join registerCheck in await _registerCheckRepository.GetQueryableAsync() on patientRegister.Id equals registerCheck.PatientRegisterId
  153. join registerCheckAsbitem in await _registerCheckAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckAsbitem.RegisterCheckId
  154. where patientRegister.MedicalStartDate != null
  155. && patientRegister.MedicalStartDate.Value >= Convert.ToDateTime(input.StartDate)
  156. && patientRegister.MedicalStartDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1)
  157. select new
  158. {
  159. patientRegisterId = patientRegister.Id,
  160. customerOrgId = patientRegister.CustomerOrgId,
  161. ischarge = registerCheckAsbitem.IsCharge,
  162. standardPrice = registerCheckAsbitem.StandardPrice,
  163. chargePrice = registerCheckAsbitem.ChargePrice,
  164. amount = registerCheckAsbitem.Amount
  165. };
  166. if (input.IsCharge != null)
  167. {
  168. query = query.Where(m => m.ischarge == input.IsCharge);
  169. }
  170. var queryList = query.ToList();
  171. if (queryList.Count == 0)
  172. {
  173. return new GetRevenueReportDto
  174. {
  175. ChargeMoney = 0,
  176. CustomerOrgCount = 0,
  177. PersonCount = 0,
  178. StandardMoney = 0,
  179. SumCount = 0
  180. };
  181. }
  182. var chargeMoney = queryList.Sum(s => s.chargePrice * s.amount);
  183. var standardMoney = queryList.Sum(s => s.standardPrice * s.amount);
  184. var sumCount = queryList.GroupBy(g => g.patientRegisterId).Count();
  185. var customerOrgCount = queryList.Where(m => m.customerOrgId != GuidFlag.PersonCustomerOrgId).GroupBy(g => g.patientRegisterId).Count();
  186. var personCount = queryList.Where(m => m.customerOrgId == GuidFlag.PersonCustomerOrgId).GroupBy(g => g.patientRegisterId).Count();
  187. var entDto = new GetRevenueReportDto
  188. {
  189. ChargeMoney = chargeMoney,
  190. StandardMoney = standardMoney,
  191. SumCount = sumCount,
  192. CustomerOrgCount = customerOrgCount,
  193. PersonCount = personCount
  194. };
  195. return entDto;
  196. }
  197. /// <summary>
  198. /// 收入统计 某段时间内组合项目售卖数量和金额排行榜
  199. /// </summary>
  200. /// <param name="input"></param>
  201. /// <returns></returns>
  202. [HttpPost("api/app/DirectorManagement/GetAsbitemRevenueReport")]
  203. public async Task<List<GetAsbitemRevenueReportDto>> GetAsbitemRevenueReportAsync(GetRevenueReportInputDto input)
  204. {
  205. if (string.IsNullOrWhiteSpace(input.StartDate) || string.IsNullOrWhiteSpace(input.EndDate))
  206. {
  207. throw new UserFriendlyException("请选择查询时间段");
  208. }
  209. var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
  210. join registerCheck in await _registerCheckRepository.GetQueryableAsync() on patientRegister.Id equals registerCheck.PatientRegisterId
  211. join registerCheckAsbitem in await _registerCheckAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckAsbitem.RegisterCheckId
  212. join asbitem in await _asbitemRepository.GetQueryableAsync() on registerCheckAsbitem.AsbitemId equals asbitem.Id
  213. where patientRegister.MedicalStartDate != null
  214. && patientRegister.MedicalStartDate.Value >= Convert.ToDateTime(input.StartDate)
  215. && patientRegister.MedicalStartDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1)
  216. select new
  217. {
  218. patientRegisterId = patientRegister.Id,
  219. registerCheckAsbitem,
  220. asbitemName = asbitem.DisplayName
  221. };
  222. if (input.IsCharge != null)
  223. {
  224. query = query.Where(m => m.registerCheckAsbitem.IsCharge == input.IsCharge);
  225. }
  226. var queryList = query.ToList();
  227. var entListDto = queryList.GroupBy(g => g.registerCheckAsbitem.AsbitemId).Select(s => new GetAsbitemRevenueReportDto
  228. {
  229. AsbitemName = s.FirstOrDefault().asbitemName,
  230. SalesCount = s.Sum(sa => sa.registerCheckAsbitem.Amount),
  231. SalesChargeAmount = s.Sum(sa => sa.registerCheckAsbitem.ChargePrice * sa.registerCheckAsbitem.Amount),
  232. SalesStandardAmount = s.Sum(sa => sa.registerCheckAsbitem.StandardPrice * sa.registerCheckAsbitem.Amount)
  233. }).OrderByDescending(o => o.SalesChargeAmount).ToList();
  234. return entListDto;
  235. }
  236. /// <summary>
  237. /// 收入统计 某段时间内套餐售卖数量和金额排行榜
  238. /// </summary>
  239. /// <param name="input"></param>
  240. /// <returns></returns>
  241. [HttpPost("api/app/DirectorManagement/GetMedicalPackageRevenueReport")]
  242. public async Task<List<GetMedicalPackageRevenueReportDto>> GetMedicalPackageRevenueReportAsync(GetMedicalPackageRevenueReportInputDto input)
  243. {
  244. if (string.IsNullOrWhiteSpace(input.StartDate) || string.IsNullOrWhiteSpace(input.EndDate))
  245. {
  246. throw new UserFriendlyException("请选择查询时间段");
  247. }
  248. var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
  249. join medicalPackage in await _medicalPackageRepository.GetQueryableAsync() on patientRegister.MedicalPackageId equals medicalPackage.Id
  250. where patientRegister.MedicalStartDate != null
  251. && patientRegister.MedicalStartDate.Value >= Convert.ToDateTime(input.StartDate)
  252. && patientRegister.MedicalStartDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1)
  253. select new
  254. {
  255. patientRegisterId = patientRegister.Id,
  256. medicalPackage
  257. };
  258. var queryList = query.ToList();
  259. var entListDto = queryList.GroupBy(g => g.medicalPackage).Select(s => new GetMedicalPackageRevenueReportDto
  260. {
  261. MedicalPackageName = s.Key.DisplayName,
  262. SalesCount = s.Count(),
  263. SalesAmount = s.Sum(sa => sa.medicalPackage.Price)
  264. }).OrderByDescending(o => o.SalesAmount).ToList();
  265. return entListDto;
  266. }
  267. /// <summary>
  268. /// 单位体检人数和金额排行榜
  269. /// </summary>
  270. /// <param name="input"></param>
  271. /// <returns></returns>
  272. [HttpPost("api/app/DirectorManagement/GetCustomerOrgPhysicalExaminationStatisticsReport")]
  273. public async Task<List<GetCustomerOrgPhysicalExaminationStatisticsReportDto>> GetCustomerOrgPhysicalExaminationStatisticsReportAsync(GetCustomerOrgPhysicalExaminationStatisticsReportInputDto input)
  274. {
  275. if (string.IsNullOrWhiteSpace(input.StartDate) || string.IsNullOrWhiteSpace(input.EndDate))
  276. {
  277. throw new UserFriendlyException("请选择查询时间段");
  278. }
  279. var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
  280. join customerOrg in await _customerOrgRepository.GetQueryableAsync() on patientRegister.CustomerOrgId equals customerOrg.Id
  281. join registerCheck in await _registerCheckRepository.GetQueryableAsync() on patientRegister.Id equals registerCheck.PatientRegisterId
  282. join registerCheckAsbitem in await _registerCheckAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckAsbitem.RegisterCheckId
  283. where patientRegister.CustomerOrgId != GuidFlag.PersonCustomerOrgId
  284. && patientRegister.MedicalStartDate != null
  285. && patientRegister.MedicalStartDate.Value >= Convert.ToDateTime(input.StartDate)
  286. && patientRegister.MedicalStartDate.Value < Convert.ToDateTime(input.EndDate).AddDays(1)
  287. select new
  288. {
  289. patientRegisterId = patientRegister.Id,
  290. customerOrg,
  291. registerCheckAsbitem
  292. };
  293. if (input.IsCharge != null)
  294. {
  295. query = query.Where(m => m.registerCheckAsbitem.IsCharge == input.IsCharge);
  296. }
  297. var queryList = query.ToList();
  298. var entListDto = queryList.GroupBy(g => g.customerOrg).Select(s => new GetCustomerOrgPhysicalExaminationStatisticsReportDto
  299. {
  300. CustomerOrgName = _cacheService.GetTopCustomerOrgNameAsync(s.Key.Id).GetAwaiter().GetResult(),
  301. CustomerOrgCount = s.Select(x => x.patientRegisterId).Distinct().Count(),
  302. SalesChargeAmount = s.Where(m => m.registerCheckAsbitem.PayTypeFlag == PayTypeFlag.OrgPay).Sum(sa => sa.registerCheckAsbitem.ChargePrice * sa.registerCheckAsbitem.Amount),
  303. SalesStandardAmount = s.Where(m => m.registerCheckAsbitem.PayTypeFlag == PayTypeFlag.OrgPay).Sum(sa => sa.registerCheckAsbitem.StandardPrice * sa.registerCheckAsbitem.Amount)
  304. }).OrderByDescending(o => o.SalesChargeAmount).ToList();
  305. return entListDto;
  306. }
  307. /// <summary>
  308. /// 工作量统计 某段时间科室工作量统计
  309. /// </summary>
  310. /// <param name="input"></param>
  311. /// <returns></returns>
  312. [HttpPost("api/app/DirectorManagement/GetItemTypeWorkLoadReport")]
  313. public async Task<List<GetItemTypeWorkLoadInStandardDto>> GetItemTypeWorkLoadReportAsync(GetItemTypeWorkLoadReportInputDto input)
  314. {
  315. if (string.IsNullOrWhiteSpace(input.StartDate) || string.IsNullOrWhiteSpace(input.EndDate))
  316. {
  317. throw new UserFriendlyException("请选择查询时间段");
  318. }
  319. var entListDto = await _internalReportAppService.GetItemTypeWorkLoadInStandardAsync(new GetItemTypeWorkLoadInStandardRequestDto
  320. {
  321. StartDate = input.StartDate,
  322. EndDate = input.EndDate
  323. });
  324. return entListDto;
  325. }
  326. /// <summary>
  327. /// 工作量统计 某段时间医生工作量统计
  328. /// </summary>
  329. /// <param name="input"></param>
  330. /// <returns></returns>
  331. [HttpPost("api/app/DirectorManagement/GetDoctorWorkLoadReport")]
  332. public async Task<List<GetDoctorPersonnelWorkLoadReportDto>> GetDoctorWorkLoadReportAsync(GetDoctorWorkLoadReportInputDto input)
  333. {
  334. if (string.IsNullOrWhiteSpace(input.StartDate) || string.IsNullOrWhiteSpace(input.EndDate))
  335. {
  336. throw new UserFriendlyException("请选择查询时间段");
  337. }
  338. var entListDto = await _internalReportAppService.GetDoctorPersonnelWorkLoadReportAsync(new GetDoctorPersonnelWorkLoadReportRequestDto
  339. {
  340. StartDate = input.StartDate,
  341. EndDate = input.EndDate
  342. });
  343. return entListDto;
  344. }
  345. /// <summary>
  346. /// 套餐价格查询
  347. /// </summary>
  348. /// <param name="input"></param>
  349. /// <returns></returns>
  350. [HttpPost("api/app/DirectorManagement/GetMedicalPackage")]
  351. public async Task<List<GetMedicalPackageDto>> GetMedicalPackageAsync(GetMedicalPackageInputDto input)
  352. {
  353. var query = from medicalPackage in await _medicalPackageRepository.GetQueryableAsync()
  354. where medicalPackage.IsActive == 'Y'
  355. select medicalPackage;
  356. if (!string.IsNullOrWhiteSpace(input.MedicalPackageName))
  357. {
  358. query = query.Where(m => input.MedicalPackageName.Contains(m.DisplayName));
  359. }
  360. var entListDto = query.ToList().Select(s => new GetMedicalPackageDto
  361. {
  362. DisplayOrder = s.DisplayOrder,
  363. ForSexName = GetForSexName(s.ForSexId),
  364. MaritalStatusName = _cacheService.GetMaritalStatusNameAsync(s.MaritalStatusId).GetAwaiter().GetResult(),
  365. MedicalPackageName = s.DisplayName,
  366. Price = s.Price,
  367. Remark = s.Remark
  368. }).OrderBy(o => o.DisplayOrder).ToList();
  369. return entListDto;
  370. }
  371. /// <summary>
  372. /// 组合项目价格查询
  373. /// </summary>
  374. /// <param name="input"></param>
  375. /// <returns></returns>
  376. [HttpPost("api/app/DirectorManagement/GetAsbitem")]
  377. public async Task<List<GetAsbitemDto>> GetAsbitemAsync(GetAsbitemInputDto input)
  378. {
  379. var query = from asbitem in await _asbitemRepository.GetQueryableAsync()
  380. where asbitem.IsActive == 'Y'
  381. select asbitem;
  382. if (!string.IsNullOrWhiteSpace(input.AsbitemName))
  383. {
  384. query = query.Where(m => input.AsbitemName.Contains(m.DisplayName));
  385. }
  386. var entListDto = query.ToList().Select(s => new GetAsbitemDto
  387. {
  388. DisplayOrder = s.DisplayOrder,
  389. ForSexName = GetForSexName(s.ForSexId),
  390. MaritalStatusName = _cacheService.GetMaritalStatusNameAsync(s.MaritalStatusId).GetAwaiter().GetResult(),
  391. AsbitemName = s.DisplayName,
  392. Price = s.Price
  393. }).OrderBy(o => o.DisplayOrder).ToList();
  394. return entListDto;
  395. }
  396. /// <summary>
  397. /// 客户体检报告查询
  398. /// </summary>
  399. /// <param name="input"></param>
  400. /// <returns></returns>
  401. [HttpPost("api/app/DirectorManagement/GetPeisReport")]
  402. public async Task<List<GetPeisReportDto>> GetPeisReportAsync(GetPeisReportInputDto input)
  403. {
  404. var query = from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
  405. join patient in await _patientRepository.GetQueryableAsync() on patientRegister.PatientId equals patient.Id
  406. where patientRegister.CompleteFlag == PatientRegisterCompleteFlag.Audit || patientRegister.CompleteFlag == PatientRegisterCompleteFlag.SumCheck
  407. select new
  408. {
  409. patientRegister,
  410. patient
  411. };
  412. if (!string.IsNullOrWhiteSpace(input.PatientName))
  413. {
  414. query = query.Where(m => m.patientRegister.PatientName == input.PatientName);
  415. }
  416. if (!string.IsNullOrWhiteSpace(input.MobileTelephone))
  417. {
  418. query = query.Where(m => m.patient.MobileTelephone == input.MobileTelephone);
  419. }
  420. if (!string.IsNullOrWhiteSpace(input.PatientNo))
  421. {
  422. query = query.Where(m => m.patient.PatientNo == input.PatientNo);
  423. }
  424. if (!string.IsNullOrWhiteSpace(input.IdNo))
  425. {
  426. query = query.Where(m => m.patient.IdNo == input.IdNo);
  427. }
  428. if (!string.IsNullOrWhiteSpace(input.PatientRegisterNo))
  429. {
  430. query = query.Where(m => m.patientRegister.PatientRegisterNo == input.PatientRegisterNo);
  431. }
  432. var entListDto = query.Select(s => new GetPeisReportDto
  433. {
  434. Age = s.patientRegister.Age == null ? "" : s.patientRegister.Age.ToString(),
  435. MedicalStartDate = DataHelper.ConversionDateShortToString(s.patientRegister.MedicalStartDate),
  436. AuditDate = DataHelper.ConversionDateShortToString(s.patientRegister.AuditDate),
  437. AuditDoctorName = _cacheService.GetSurnameAsync(s.patientRegister.AuditDoctorId).GetAwaiter().GetResult(),
  438. IdNo = s.patient.IdNo,
  439. MobileTelephone = s.patient.MobileTelephone,
  440. PatientNo = s.patient.PatientNo,
  441. SexName = GetSexName(s.patientRegister.SexId),
  442. CompleteFlag = GetPatientRegisterCompleteFlag(s.patientRegister.CompleteFlag),
  443. IsUpload = s.patientRegister.IsUpload == 'Y' ? "已上传" : "未上传",
  444. PatientName = s.patientRegister.PatientName,
  445. PatientRegisterId = s.patientRegister.Id,
  446. PatientRegisterNo = s.patientRegister.PatientRegisterNo,
  447. SummaryDate = DataHelper.ConversionDateShortToString(s.patientRegister.SummaryDate),
  448. SummaryDoctorName = _cacheService.GetSurnameAsync(s.patientRegister.SummaryDoctorId).GetAwaiter().GetResult(),
  449. CustomerOrgName = _cacheService.GetTopCustomerOrgNameAsync(s.patientRegister.CustomerOrgId).GetAwaiter().GetResult(),
  450. DepartmentName = _cacheService.GetCustomerOrgNameAsync(s.patientRegister.CustomerOrgId).GetAwaiter().GetResult()
  451. }).OrderBy(o => o.PatientRegisterId).ToList();
  452. return entListDto;
  453. }
  454. /// <summary>
  455. /// 根据体检人员Id查询报告 返回的报告base64
  456. /// </summary>
  457. /// <param name="input"></param>
  458. /// <returns></returns>
  459. [HttpPost("api/app/DirectorManagement/GetPeisReportBase64ByPatientRegisterId")]
  460. public async Task<GetPeisReportBase64ByPatientRegisterIdDto> GetPeisReportBase64ByPatientRegisterIdAsync(PatientRegisterIdInputDto input)
  461. {
  462. var entDto = new GetPeisReportBase64ByPatientRegisterIdDto();
  463. entDto.Base64Str = await GetPeisBase64Async(input);
  464. return entDto;
  465. }
  466. /// <summary>
  467. /// 获取报告bse64 调用服务器上客户端
  468. /// </summary>
  469. /// <param name="input"></param>
  470. /// <returns></returns>
  471. /// <exception cref="UserFriendlyException"></exception>
  472. /// <exception cref="Exception"></exception>
  473. private async Task<string> GetPeisBase64Async(PatientRegisterIdInputDto input)
  474. {
  475. var thirdInterface = await _thirdInterfaceRepository.FirstOrDefaultAsync(f => f.ThirdInterfaceType == ThirdInterfaceTypeFlag.TranToWebPeis);
  476. if (thirdInterface.IsActive != 'Y')
  477. {
  478. throw new UserFriendlyException("该接口已禁用");
  479. }
  480. var parmValue = thirdInterface.ParmValue;
  481. var configurationBuilder = new ConfigurationBuilder()
  482. .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
  483. var config = configurationBuilder.Build();
  484. var reportApiBaseAddress = config.GetSection("Interface").GetSection("ReportApiBaseAddress").Value;
  485. var reportApiUrl = config.GetSection("Interface").GetSection("ReportApiUrl").Value;
  486. string reportBase64 = "";
  487. var printReportData = await _printReportAppService.GetMedicalReportConvertToReportAsync(input);
  488. using (var httpClientHandler = new HttpClientHandler())
  489. {
  490. using (var httpClient = new HttpClient(httpClientHandler))
  491. {
  492. httpClient.BaseAddress = new Uri(reportApiBaseAddress);
  493. httpClient.DefaultRequestHeaders.Accept.Add(
  494. new MediaTypeWithQualityHeaderValue("application/json"));//设置accept标头,告诉JSON是可接受的响应类型
  495. var sendData = JsonConvert.SerializeObject(printReportData);
  496. using (HttpContent httpContent = new StringContent(sendData))
  497. {
  498. httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
  499. HttpResponseMessage response = null;
  500. response = await httpClient.PostAsync(reportApiUrl, httpContent);
  501. string result;
  502. if (!response.IsSuccessStatusCode)
  503. {
  504. result = response.Content.ReadAsStringAsync().Result;
  505. throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
  506. }
  507. result = await response.Content.ReadAsStringAsync();
  508. var resultDto = JsonConvert.DeserializeObject<WebApiClientOutDto>(result);
  509. if (resultDto != null)
  510. {
  511. if (resultDto.code != 1)
  512. {
  513. throw new Exception($"调用WebApi失败,返回-1,消息:" + result);
  514. }
  515. reportBase64 = resultDto.data;
  516. }
  517. }
  518. }
  519. }
  520. return reportBase64;
  521. }
  522. /// <summary>
  523. /// 转换适用性别
  524. /// </summary>
  525. /// <param name="ForSexId"></param>
  526. /// <returns></returns>
  527. private string GetForSexName(char ForSexId)
  528. {
  529. string msg = "";
  530. if (ForSexId == 'A')
  531. {
  532. msg = "全部";
  533. }
  534. else if (ForSexId == 'M')
  535. {
  536. msg = "男";
  537. }
  538. else if (ForSexId == 'F')
  539. {
  540. msg = "女";
  541. }
  542. return msg;
  543. }
  544. /// <summary>
  545. /// 转换性别
  546. /// </summary>
  547. /// <param name="SexId"></param>
  548. /// <returns></returns>
  549. private string GetSexName(char SexId)
  550. {
  551. string msg = "";
  552. if (SexId == 'U')
  553. {
  554. msg = "未知";
  555. }
  556. else if (SexId == 'M')
  557. {
  558. msg = "男";
  559. }
  560. else if (SexId == 'F')
  561. {
  562. msg = "女";
  563. }
  564. return msg;
  565. }
  566. /// <summary>
  567. /// 转换人员状态
  568. /// </summary>
  569. /// <param name="completeFlag"></param>
  570. /// <returns></returns>
  571. private string GetPatientRegisterCompleteFlag(char completeFlag)
  572. {
  573. string msg = "";
  574. if (completeFlag == '0')
  575. {
  576. msg = "预登记";
  577. }
  578. else if (completeFlag == '1')
  579. {
  580. msg = "正式登记";
  581. }
  582. else if (completeFlag == '2')
  583. {
  584. msg = "部分已检";
  585. }
  586. else if (completeFlag == '3')
  587. {
  588. msg = "已总检";
  589. }
  590. return msg;
  591. }
  592. }
  593. }