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.

612 lines
31 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.EntityFrameworkCore;
  4. using Shentun.Peis.Enums;
  5. using Shentun.Peis.Models;
  6. using Shentun.Peis.OcCheckTypes;
  7. using Shentun.Peis.PatientOccupationalDiseases;
  8. using Shentun.Peis.PatientRegisters;
  9. using Shentun.Peis.SumSummaryReports;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using Volo.Abp;
  16. using Volo.Abp.Application.Services;
  17. using Volo.Abp.Domain.Repositories;
  18. using Volo.Abp.Identity;
  19. using Volo.Abp.ObjectMapping;
  20. namespace Shentun.Peis.OccupationalDiseases
  21. {
  22. /// <summary>
  23. /// 职业病业务
  24. /// </summary>
  25. [ApiExplorerSettings(GroupName = "Work")]
  26. [Authorize]
  27. public class OccupationalDiseaseAppService : ApplicationService
  28. {
  29. private readonly IRepository<PatientOccupationalDisease, Guid> _patientOccupationalDiseaseRepository;
  30. private readonly IRepository<PatientOccupationalHistory, Guid> _patientOccupationalHistoryRepository;
  31. private readonly IRepository<PatientPoison> _patientPoisonRepository;
  32. private readonly IRepository<PatientSymptom> _patientSymptomRepository;
  33. private readonly IRepository<PatientOccupationalMedicalHistory, Guid> _patientOccupationalMedicalHistoryRepository;
  34. private readonly PatientOccupationalDiseaseManager _patientOccupationalDiseaseManager;
  35. private readonly CacheService _cacheService;
  36. private readonly IRepository<Patient, Guid> _patientRepository;
  37. private readonly IRepository<RegisterCheck, Guid> _registerCheckRepository;
  38. private readonly IRepository<IdentityUser, Guid> _identityUserRepository;
  39. private readonly IRepository<ItemType, Guid> _itemTypeRepository;
  40. private readonly IRepository<RegisterCheckItem> _registerCheckItemRepository;
  41. private readonly IRepository<Item, Guid> _itemRepository;
  42. private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository;
  43. private readonly IRepository<RegisterCheckAsbitem, Guid> _registerCheckAsbitemRepository;
  44. private readonly IRepository<ResultStatus> _resultStatusRepository;
  45. private readonly IRepository<RegisterCheckSummary, Guid> _registerCheckSummaryRepository;
  46. private readonly IRepository<Asbitem, Guid> _asbitemRepository;
  47. public OccupationalDiseaseAppService(
  48. IRepository<PatientOccupationalDisease, Guid> patientOccupationalDiseaseRepository,
  49. IRepository<PatientOccupationalHistory, Guid> patientOccupationalHistoryRepository,
  50. IRepository<PatientPoison> patientPoisonRepository,
  51. IRepository<PatientSymptom> patientSymptomRepository,
  52. PatientOccupationalDiseaseManager patientOccupationalDiseaseManager,
  53. CacheService cacheService,
  54. IRepository<Patient, Guid> patientRepository,
  55. IRepository<RegisterCheck, Guid> registerCheckRepository,
  56. IRepository<IdentityUser, Guid> identityUserRepository,
  57. IRepository<ItemType, Guid> itemTypeRepository,
  58. IRepository<RegisterCheckItem> registerCheckItemRepository,
  59. IRepository<Item, Guid> itemRepository,
  60. IRepository<PatientRegister, Guid> patientRegisterRepository,
  61. IRepository<RegisterCheckAsbitem, Guid> registerCheckAsbitemRepository,
  62. IRepository<ResultStatus> resultStatusRepository,
  63. IRepository<RegisterCheckSummary, Guid> registerCheckSummaryRepository,
  64. IRepository<Asbitem, Guid> asbitemRepository,
  65. IRepository<PatientOccupationalMedicalHistory, Guid> patientOccupationalMedicalHistoryRepository)
  66. {
  67. _patientOccupationalDiseaseRepository = patientOccupationalDiseaseRepository;
  68. _patientOccupationalHistoryRepository = patientOccupationalHistoryRepository;
  69. _patientPoisonRepository = patientPoisonRepository;
  70. _patientSymptomRepository = patientSymptomRepository;
  71. _patientOccupationalDiseaseManager = patientOccupationalDiseaseManager;
  72. _cacheService = cacheService;
  73. _patientRepository = patientRepository;
  74. _registerCheckRepository = registerCheckRepository;
  75. _identityUserRepository = identityUserRepository;
  76. _itemTypeRepository = itemTypeRepository;
  77. _registerCheckItemRepository = registerCheckItemRepository;
  78. _itemRepository = itemRepository;
  79. _patientRegisterRepository = patientRegisterRepository;
  80. _registerCheckAsbitemRepository = registerCheckAsbitemRepository;
  81. _resultStatusRepository = resultStatusRepository;
  82. _registerCheckSummaryRepository = registerCheckSummaryRepository;
  83. _asbitemRepository = asbitemRepository;
  84. _patientOccupationalMedicalHistoryRepository = patientOccupationalMedicalHistoryRepository;
  85. }
  86. /// <summary>
  87. /// 创建职业病信息
  88. /// </summary>
  89. /// <returns></returns>
  90. [HttpPost("api/app/OccupationalDisease/CreateOccupationalDiseaseWithDetail")]
  91. public async Task<OccupationalDiseaseWithDetailByPatientRegisterIdDto> CreateOccupationalDiseaseWithDetailAsync(OccupationalDiseaseWithDetailInputDto input)
  92. {
  93. if (input == null)
  94. {
  95. throw new UserFriendlyException("请求参数有误");
  96. }
  97. if (input.PatientRegisterId == Guid.Empty)
  98. throw new UserFriendlyException("人员ID不正确");
  99. #region 基础信息
  100. if (input.PatientOccupationalDisease == null)
  101. throw new UserFriendlyException("职业病基础信息有误");
  102. var patientOccupationalDiseaseInput = ObjectMapper.Map<PatientOccupationalDiseaseInputDto, PatientOccupationalDisease>(input.PatientOccupationalDisease);
  103. patientOccupationalDiseaseInput.PatientRegisterId = input.PatientRegisterId;
  104. var patientOccupationalDiseaseEnt = await _patientOccupationalDiseaseRepository.FirstOrDefaultAsync(f => f.PatientRegisterId == input.PatientRegisterId);
  105. if (patientOccupationalDiseaseEnt == null)
  106. {
  107. var entity = _patientOccupationalDiseaseManager.CreateAsync(patientOccupationalDiseaseInput);
  108. await _patientOccupationalDiseaseRepository.InsertAsync(entity, true);
  109. }
  110. else
  111. {
  112. _patientOccupationalDiseaseManager.UpdateAsync(patientOccupationalDiseaseInput, patientOccupationalDiseaseEnt);
  113. await _patientOccupationalDiseaseRepository.UpdateAsync(patientOccupationalDiseaseEnt, true);
  114. }
  115. #endregion
  116. #region 毒害因素
  117. var patientPoisonsInput = ObjectMapper.Map<List<PatientPoisonInputDto>, List<PatientPoison>>(input.PatientPoisons);
  118. await _patientPoisonRepository.DeleteAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  119. List<PatientPoison> patientPoisonList = new List<PatientPoison>();
  120. foreach (var item in patientPoisonsInput)
  121. {
  122. patientPoisonList.Add(new PatientPoison
  123. {
  124. PatientRegisterId = input.PatientRegisterId,
  125. PoisonId = item.PoisonId
  126. });
  127. }
  128. await _patientPoisonRepository.InsertManyAsync(patientPoisonList, true);
  129. #endregion
  130. #region 症状
  131. var patientSymptomsInput = ObjectMapper.Map<List<PatientSymptomInputDto>, List<PatientSymptom>>(input.PatientSymptoms);
  132. await _patientSymptomRepository.DeleteAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  133. List<PatientSymptom> patientSymptomList = new List<PatientSymptom>();
  134. foreach (var item in patientSymptomsInput)
  135. {
  136. patientSymptomList.Add(new PatientSymptom
  137. {
  138. PatientRegisterId = input.PatientRegisterId,
  139. Degree = item.Degree,
  140. SymptomId = item.SymptomId,
  141. TimeLength = item.TimeLength
  142. });
  143. }
  144. await _patientSymptomRepository.InsertManyAsync(patientSymptomList, true);
  145. #endregion
  146. #region 职业病史
  147. var patientOccupationalMedicalHistorysInput = ObjectMapper.Map<List<PatientOccupationalMedicalHistoryInputDto>, List<PatientOccupationalMedicalHistory>>(input.PatientOccupationalMedicalHistorys);
  148. await _patientOccupationalMedicalHistoryRepository.DeleteAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  149. List<PatientOccupationalMedicalHistory> patientOccupationalMedicalHistoryList = new List<PatientOccupationalMedicalHistory>();
  150. foreach (var item in patientOccupationalMedicalHistorysInput)
  151. {
  152. patientOccupationalMedicalHistoryList.Add(new PatientOccupationalMedicalHistory
  153. {
  154. PatientRegisterId = input.PatientRegisterId,
  155. DiagnosisDate = item.DiagnosisDate,
  156. DiagnosisHospital = item.DiagnosisHospital,
  157. IsRecovery = item.IsRecovery,
  158. OccupationalDisease = item.OccupationalDisease,
  159. TreatmentMethods = item.TreatmentMethods
  160. });
  161. }
  162. await _patientOccupationalMedicalHistoryRepository.InsertManyAsync(patientOccupationalMedicalHistoryList, true);
  163. #endregion
  164. #region 职业史
  165. var patientOccupationalHistorysInput = ObjectMapper.Map<List<PatientOccupationalHistoryInputDto>, List<PatientOccupationalHistory>>(input.PatientOccupationalHistorys);
  166. await _patientOccupationalHistoryRepository.DeleteAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  167. List<PatientOccupationalHistory> patientOccupationalHistoryList = new List<PatientOccupationalHistory>();
  168. foreach (var item in patientOccupationalHistorysInput)
  169. {
  170. patientOccupationalHistoryList.Add(new PatientOccupationalHistory
  171. {
  172. PatientRegisterId = input.PatientRegisterId,
  173. BeginDate = item.BeginDate,
  174. EndDate = item.EndDate,
  175. Org = item.Org,
  176. Poison = item.Poison,
  177. ProtectiveMeasures = item.ProtectiveMeasures,
  178. WorkShop = item.WorkShop,
  179. WorkType = item.WorkType
  180. });
  181. }
  182. await _patientOccupationalHistoryRepository.InsertManyAsync(patientOccupationalHistoryList, true);
  183. #endregion
  184. return await GetOccupationalDiseaseWithDetailByPatientRegisterIdAsync(new PatientRegisterIdInputDto
  185. {
  186. PatientRegisterId = input.PatientRegisterId
  187. });
  188. }
  189. /// <summary>
  190. /// 获取职业病信息 根据人员登记ID
  191. /// </summary>
  192. /// <returns></returns>
  193. [HttpPost("api/app/OccupationalDisease/GetOccupationalDiseaseWithDetailByPatientRegisterId")]
  194. public async Task<OccupationalDiseaseWithDetailByPatientRegisterIdDto> GetOccupationalDiseaseWithDetailByPatientRegisterIdAsync(PatientRegisterIdInputDto input)
  195. {
  196. if (input == null)
  197. {
  198. throw new UserFriendlyException("请求参数有误");
  199. }
  200. if (input.PatientRegisterId == Guid.Empty)
  201. throw new UserFriendlyException("人员ID不正确");
  202. var result = new OccupationalDiseaseWithDetailByPatientRegisterIdDto();
  203. #region 基础信息
  204. var patientOccupationalDiseaseEnt = await _patientOccupationalDiseaseRepository.FirstOrDefaultAsync(f => f.PatientRegisterId == input.PatientRegisterId);
  205. if (patientOccupationalDiseaseEnt != null)
  206. {
  207. result.PatientOccupationalDisease = new PatientOccupationalDiseaseDto
  208. {
  209. AbnormalTimes = patientOccupationalDiseaseEnt.AbnormalTimes,
  210. AbortionTimes = patientOccupationalDiseaseEnt.AbortionTimes,
  211. ChildrenNum = patientOccupationalDiseaseEnt.ChildrenNum,
  212. CreationTime = patientOccupationalDiseaseEnt.CreationTime,
  213. CreatorId = patientOccupationalDiseaseEnt.CreatorId,
  214. DrinkFlag = patientOccupationalDiseaseEnt.DrinkFlag,
  215. DrinkNum = patientOccupationalDiseaseEnt.DrinkNum,
  216. DrinkYears = patientOccupationalDiseaseEnt.DrinkYears,
  217. FirstMenstruation = patientOccupationalDiseaseEnt.FirstMenstruation,
  218. HandleSuggestion = patientOccupationalDiseaseEnt.HandleSuggestion,
  219. Id = patientOccupationalDiseaseEnt.Id,
  220. JobType = patientOccupationalDiseaseEnt.JobType,
  221. LastMenstrualPeriodDate = patientOccupationalDiseaseEnt.LastMenstrualPeriodDate,
  222. LastModificationTime = patientOccupationalDiseaseEnt.LastModificationTime,
  223. LastModifierId = patientOccupationalDiseaseEnt.LastModifierId,
  224. MenstruationCycle = patientOccupationalDiseaseEnt.MenstruationCycle,
  225. MenstruationEndAge = patientOccupationalDiseaseEnt.MenstruationEndAge,
  226. MenstruationFlag = patientOccupationalDiseaseEnt.MenstruationFlag,
  227. MenstruationTimeLength = patientOccupationalDiseaseEnt.MenstruationTimeLength,
  228. NoOccupAbSuggestion = patientOccupationalDiseaseEnt.NoOccupAbSuggestion,
  229. NoOccupationalAbnormal = patientOccupationalDiseaseEnt.NoOccupationalAbnormal,
  230. OcCheckTypeId = patientOccupationalDiseaseEnt.OcCheckTypeId,
  231. OccupationalAbnormal = patientOccupationalDiseaseEnt.OccupationalAbnormal,
  232. OccupationalAbSuggestion = patientOccupationalDiseaseEnt.OccupationalAbSuggestion,
  233. Other = patientOccupationalDiseaseEnt.Other,
  234. PoisonWorkTime = patientOccupationalDiseaseEnt.PoisonWorkTime,
  235. PrematureBirthTimes = patientOccupationalDiseaseEnt.PrematureBirthTimes,
  236. PreviousHistory = patientOccupationalDiseaseEnt.PreviousHistory,
  237. SmokeFlag = patientOccupationalDiseaseEnt.SmokeFlag,
  238. SmokeNum = patientOccupationalDiseaseEnt.SmokeNum,
  239. SmokeYears = patientOccupationalDiseaseEnt.SmokeYears,
  240. StillbirthTimes = patientOccupationalDiseaseEnt.StillbirthTimes,
  241. TotalWorkTime = patientOccupationalDiseaseEnt.TotalWorkTime,
  242. CreatorName = _cacheService.GetSurnameAsync(patientOccupationalDiseaseEnt.CreatorId).Result,
  243. LastModifierName = _cacheService.GetSurnameAsync(patientOccupationalDiseaseEnt.LastModifierId).Result
  244. };
  245. }
  246. #endregion
  247. #region 毒害因素
  248. List<PatientPoisonDto> patientPoisonDtos = new List<PatientPoisonDto>();
  249. var patientPoisonList = await _patientPoisonRepository.GetListAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  250. patientPoisonDtos = patientPoisonList.Select(s => new PatientPoisonDto
  251. {
  252. PoisonId = s.PoisonId,
  253. SuspectedOccupationalDiseaseId = s.SuspectedOccupationalDiseaseId,
  254. OccupationalContraindicationsId = s.OccupationalContraindicationsId,
  255. OccupationalAbnormalId = s.OccupationalAbnormalId,
  256. OtherDiseases = s.OtherDiseases,
  257. CreationTime = s.CreationTime,
  258. CreatorId = s.CreatorId,
  259. LastModificationTime = s.LastModificationTime,
  260. LastModifierId = s.LastModifierId,
  261. CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result,
  262. LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result
  263. }).ToList();
  264. result.PatientPoisonDtos = patientPoisonDtos;
  265. #endregion
  266. #region 职业病史
  267. List<PatientOccupationalMedicalHistoryDto> patientOccupationalMedicalHistoryDtos = new List<PatientOccupationalMedicalHistoryDto>();
  268. var patientOccupationalMedicalHistoryList = await _patientOccupationalMedicalHistoryRepository.GetListAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  269. patientOccupationalMedicalHistoryDtos = patientOccupationalMedicalHistoryList.Select(s => new PatientOccupationalMedicalHistoryDto
  270. {
  271. DiagnosisDate = s.DiagnosisDate,
  272. DiagnosisHospital = s.DiagnosisHospital,
  273. Id = s.Id,
  274. IsRecovery = s.IsRecovery,
  275. OccupationalDisease = s.OccupationalDisease,
  276. TreatmentMethods = s.TreatmentMethods,
  277. CreationTime = s.CreationTime,
  278. CreatorId = s.CreatorId,
  279. LastModificationTime = s.LastModificationTime,
  280. LastModifierId = s.LastModifierId,
  281. CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result,
  282. LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result
  283. }).ToList();
  284. result.PatientOccupationalMedicalHistoryDtos = patientOccupationalMedicalHistoryDtos;
  285. #endregion
  286. #region 症状
  287. var patientSymptomList = await _patientSymptomRepository.GetListAsync(m => m.PatientRegisterId == input.PatientRegisterId);
  288. List<PatientSymptomDto> patientSymptomDtos = patientSymptomList.Select(s => new PatientSymptomDto
  289. {
  290. Degree = s.Degree,
  291. SymptomId = s.SymptomId,
  292. TimeLength = s.TimeLength,
  293. CreationTime = s.CreationTime,
  294. CreatorId = s.CreatorId,
  295. LastModificationTime = s.LastModificationTime,
  296. LastModifierId = s.LastModifierId,
  297. CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result,
  298. LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result
  299. }).ToList();
  300. result.PatientSymptomDtos = patientSymptomDtos;
  301. #endregion
  302. #region 职业史
  303. var patientOccupationalHistoryList = await _patientOccupationalHistoryRepository.GetListAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  304. List<PatientOccupationalHistoryDto> patientOccupationalHistoryDtos = patientOccupationalHistoryList.Select(s => new PatientOccupationalHistoryDto
  305. {
  306. BeginDate = s.BeginDate,
  307. EndDate = s.EndDate,
  308. Org = s.Org,
  309. Poison = s.Poison,
  310. ProtectiveMeasures = s.ProtectiveMeasures,
  311. WorkShop = s.WorkShop,
  312. WorkType = s.WorkType,
  313. CreationTime = s.CreationTime,
  314. CreatorId = s.CreatorId,
  315. Id = s.Id,
  316. LastModifierId = s.LastModifierId,
  317. LastModificationTime = s.LastModificationTime,
  318. CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result,
  319. LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result
  320. }).ToList();
  321. result.PatientOccupationalHistoryDtos = patientOccupationalHistoryDtos;
  322. #endregion
  323. return result;
  324. }
  325. /// <summary>
  326. /// 修改检查结论
  327. /// </summary>
  328. /// <returns></returns>
  329. [HttpPost("api/app/OccupationalDisease/UpdateOccupationalDiseaseInspectionConclusion")]
  330. public async Task UpdateOccupationalDiseaseInspectionConclusionAsync(OccupationalDiseaseInspectionConclusionInputDto input)
  331. {
  332. var patientOccupationalDiseaseEnt = await _patientOccupationalDiseaseRepository.FirstOrDefaultAsync(F => F.PatientRegisterId == input.PatientRegisterId);
  333. if (patientOccupationalDiseaseEnt == null)
  334. {
  335. throw new UserFriendlyException("请先登记职业病信息");
  336. }
  337. patientOccupationalDiseaseEnt.NoOccupAbSuggestion = input.NoOccupAbSuggestion;
  338. patientOccupationalDiseaseEnt.NoOccupationalAbnormal = input.NoOccupationalAbnormal;
  339. patientOccupationalDiseaseEnt.OccupationalAbnormal = input.OccupationalAbnormal;
  340. patientOccupationalDiseaseEnt.OccupationalAbSuggestion = input.OccupationalAbSuggestion;
  341. patientOccupationalDiseaseEnt.HandleSuggestion = input.HandleSuggestion;
  342. await _patientOccupationalDiseaseRepository.UpdateAsync(patientOccupationalDiseaseEnt);
  343. }
  344. /// <summary>
  345. /// 获取检查结论
  346. /// </summary>
  347. /// <returns></returns>
  348. [HttpPost("api/app/OccupationalDisease/GetOccupationalDiseaseInspectionConclusion")]
  349. public async Task<OccupationalDiseaseInspectionConclusionDto> GetOccupationalDiseaseInspectionConclusionAsync(PatientRegisterIdInputDto input)
  350. {
  351. var patientOccupationalDiseaseEnt = await _patientOccupationalDiseaseRepository.FirstOrDefaultAsync(F => F.PatientRegisterId == input.PatientRegisterId);
  352. if (patientOccupationalDiseaseEnt == null)
  353. {
  354. throw new UserFriendlyException("暂无职业病信息");
  355. }
  356. var entDto = new OccupationalDiseaseInspectionConclusionDto
  357. {
  358. HandleSuggestion = patientOccupationalDiseaseEnt.HandleSuggestion,
  359. NoOccupAbSuggestion = patientOccupationalDiseaseEnt.NoOccupAbSuggestion,
  360. NoOccupationalAbnormal = patientOccupationalDiseaseEnt.NoOccupationalAbnormal,
  361. OccupationalAbnormal = patientOccupationalDiseaseEnt.OccupationalAbnormal,
  362. OccupationalAbSuggestion = patientOccupationalDiseaseEnt.OccupationalAbSuggestion
  363. };
  364. return entDto;
  365. }
  366. /// <summary>
  367. /// 获取体征结果
  368. /// </summary>
  369. /// <param name="input">人员登记ID</param>
  370. /// <returns></returns>
  371. [HttpPost("api/app/OccupationalDisease/GetDetailResults")]
  372. public async Task<List<SumSummaryReportDetailResultDto>> GetDetailResultsAsync(PatientRegisterIdInputDto input)
  373. {
  374. List<SumSummaryReportDetailResultDto> msg = new List<SumSummaryReportDetailResultDto>();
  375. var userlist = await _identityUserRepository.GetListAsync();
  376. var resultStatus = await _resultStatusRepository.GetListAsync();
  377. var list = (from patient in await _patientRepository.GetQueryableAsync()
  378. join patientRegister in await _patientRegisterRepository.GetQueryableAsync()
  379. on patient.Id equals patientRegister.PatientId
  380. join registerCheck in await _registerCheckRepository.GetQueryableAsync()
  381. on patientRegister.Id equals registerCheck.PatientRegisterId
  382. join registerCheckAsbitem in await _registerCheckAsbitemRepository.GetQueryableAsync()
  383. on registerCheck.Id equals registerCheckAsbitem.RegisterCheckId
  384. join registerCheckSummary in await _registerCheckSummaryRepository.GetQueryableAsync()
  385. on registerCheck.Id equals registerCheckSummary.RegisterCheckId
  386. join asbitem in await _asbitemRepository.GetQueryableAsync()
  387. on registerCheckAsbitem.AsbitemId equals asbitem.Id
  388. join registerCheckItem in await _registerCheckItemRepository.GetQueryableAsync()
  389. on registerCheck.Id equals registerCheckItem.RegisterCheckId
  390. join item in await _itemRepository.GetQueryableAsync()
  391. on registerCheckItem.ItemId equals item.Id
  392. join itemType in await _itemTypeRepository.GetQueryableAsync()
  393. on asbitem.ItemTypeId equals itemType.Id
  394. where patientRegister.Id == input.PatientRegisterId
  395. && registerCheck.CompleteFlag == RegisterCheckCompleteFlag.Checked
  396. && asbitem.IsCheck == 'Y'
  397. select new
  398. {
  399. patient,
  400. patientRegister,
  401. registerCheck,
  402. registerCheckSummary,
  403. registerCheckAsbitem,
  404. asbitem,
  405. registerCheckItem,
  406. item,
  407. itemType
  408. }).AsNoTracking().ToList();
  409. if (!list.Any())
  410. {
  411. return null;
  412. }
  413. //将子项目类别设置为父项目类别
  414. var itemTypes = await _itemTypeRepository.GetListAsync();
  415. foreach (var listItem in list)
  416. {
  417. var parentItemType = itemTypes.Where(o => o.Id == listItem.itemType.ParentId).FirstOrDefault();
  418. if (parentItemType != null)
  419. {
  420. listItem.asbitem.DisplayOrder = listItem.itemType.DisplayOrder * 1000 + listItem.asbitem.DisplayOrder;
  421. listItem.itemType.DisplayName = parentItemType.DisplayName;
  422. listItem.itemType.DisplayOrder = parentItemType.DisplayOrder;
  423. }
  424. }
  425. var detailedResultsList_Asbitems = new List<SumSummaryReportDetailResultWithAsbitem>();
  426. var registerCheckIds = list.OrderBy(o => o.itemType.DisplayOrder)
  427. .OrderBy(o => o.asbitem.DisplayOrder)
  428. .Select(o => o.registerCheck.Id).Distinct().ToList();
  429. foreach (var registerCheckId in registerCheckIds)
  430. {
  431. var listItem = list.Where(o => o.registerCheck.Id == registerCheckId).First();
  432. var detailedResultsList_Asbitem = new SumSummaryReportDetailResultWithAsbitem()
  433. {
  434. ItemTypeName = listItem.itemType.DisplayName,
  435. AsbitemNames = string.Join(",", list.Where(o => o.registerCheck.Id == registerCheckId)
  436. .OrderBy(o => o.itemType.DisplayOrder).OrderBy(o => o.asbitem.DisplayOrder)
  437. .Select(o => o.asbitem.DisplayName).Distinct().ToList()),
  438. ItemTypeDisplayOrder = listItem.itemType.DisplayOrder,
  439. AsbitemDisplayOrder = listItem.asbitem.DisplayOrder,
  440. CheckDate = ((DateTime)listItem.registerCheck.CheckDate).Date,
  441. CheckDoctorName = EntityHelper.GetCheckDoctorName(listItem.registerCheck.CheckDoctorId, userlist),
  442. Items = list.Where(o => o.registerCheck.Id == registerCheckId)
  443. .OrderBy(o => o.itemType.DisplayOrder)
  444. .OrderBy(o => o.asbitem.DisplayOrder)
  445. .OrderBy(o => o.item.DisplayOrder)
  446. .GroupBy(o => o.registerCheckItem.ItemId)
  447. .Select(o => new SumSummaryReportDetailResultWithItem()
  448. {
  449. ItemId = o.FirstOrDefault().registerCheckItem.ItemId,
  450. ItemName = o.FirstOrDefault().item.DisplayName,
  451. ItemResult = o.FirstOrDefault().registerCheckItem.Result,
  452. ReferenceRangeValue = o.FirstOrDefault().registerCheckItem.ReferenceRangeValue,
  453. CriticalRangeValue = o.FirstOrDefault().registerCheckItem.CriticalRangeValue,
  454. Unit = o.FirstOrDefault().registerCheckItem.Unit,
  455. ResultStatusId = o.FirstOrDefault().registerCheckItem.ResultStatusId,
  456. ResultStatusName = (resultStatus.Where(x => x.Id == o.FirstOrDefault().registerCheckItem.ResultStatusId).FirstOrDefault() == null) ? "" : resultStatus.Where(x => x.Id == o.FirstOrDefault().registerCheckItem.ResultStatusId).FirstOrDefault().ReportPrompt,
  457. ReportFontColor = (resultStatus.Where(x => x.Id == o.FirstOrDefault().registerCheckItem.ResultStatusId).FirstOrDefault() == null) ? 0 : resultStatus.Where(x => x.Id == o.FirstOrDefault().registerCheckItem.ResultStatusId).FirstOrDefault().ReportFontColor,
  458. ReportBackgroundColor = (resultStatus.Where(x => x.Id == o.FirstOrDefault().registerCheckItem.ResultStatusId).FirstOrDefault() == null) ? 16777215 : resultStatus.Where(x => x.Id == o.FirstOrDefault().registerCheckItem.ResultStatusId).FirstOrDefault().ReportBackgroundColor,
  459. }).ToList(),
  460. Summarys = list.Where(o => o.registerCheck.Id == registerCheckId)
  461. .OrderBy(o => o.registerCheckSummary.DisplayOrder)
  462. .GroupBy(o => o.registerCheckSummary.Summary)
  463. .Select(o => new SumSummaryReportDetailResultWithSummary()
  464. {
  465. Summary = o.FirstOrDefault().registerCheckSummary.Summary
  466. })
  467. .ToList<SumSummaryReportDetailResultWithSummary>(),
  468. };
  469. detailedResultsList_Asbitem.Summarys = detailedResultsList_Asbitem.Summarys.Distinct().ToList();
  470. detailedResultsList_Asbitems.Add(detailedResultsList_Asbitem);
  471. }
  472. var grouplist = detailedResultsList_Asbitems.OrderBy(o => o.ItemTypeDisplayOrder)
  473. .OrderBy(o => o.AsbitemDisplayOrder)
  474. .GroupBy(g => g.ItemTypeName);
  475. foreach (var g in grouplist)
  476. {
  477. var glist = g.OrderBy(o => o.ItemTypeDisplayOrder).OrderBy(o => o.AsbitemDisplayOrder).ToList();
  478. var resultlist = new SumSummaryReportDetailResultDto
  479. {
  480. ItemTypeDisplayOrder = glist.FirstOrDefault().ItemTypeDisplayOrder,
  481. ItemTypeName = glist.FirstOrDefault().ItemTypeName,
  482. Asbitems = glist
  483. };
  484. msg.Add(resultlist);
  485. }
  486. msg = msg.OrderBy(o => o.ItemTypeDisplayOrder).ToList();
  487. return msg;
  488. }
  489. /// <summary>
  490. /// 删除职业病相关信息
  491. /// </summary>
  492. /// <param name="input"></param>
  493. /// <returns></returns>
  494. [HttpPost("api/app/OccupationalDisease/DeleteOccupationalDiseaseWithDetail")]
  495. public async Task DeleteOccupationalDiseaseWithDetailAsync(PatientRegisterIdInputDto input)
  496. {
  497. if (input == null)
  498. {
  499. throw new UserFriendlyException("请求参数有误");
  500. }
  501. if (input.PatientRegisterId == Guid.Empty)
  502. throw new UserFriendlyException("人员ID不正确");
  503. await _patientOccupationalDiseaseRepository.DeleteAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  504. await _patientOccupationalHistoryRepository.DeleteAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  505. await _patientPoisonRepository.DeleteAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  506. await _patientOccupationalMedicalHistoryRepository.DeleteAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  507. await _patientSymptomRepository.DeleteAsync(d => d.PatientRegisterId == input.PatientRegisterId);
  508. }
  509. }
  510. }