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.

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