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.

186 lines
6.5 KiB

3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 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
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
  1. using AutoMapper.Internal.Mappers;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Shentun.Peis.Patients;
  4. using Shentun.Peis.HelperDto;
  5. using Shentun.Peis.Models;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Volo.Abp.Application.Dtos;
  12. using Volo.Abp.Application.Services;
  13. using Volo.Abp.Domain.Repositories;
  14. using Volo.Abp.Identity;
  15. using Shentun.Peis.PatientRegisters;
  16. using Microsoft.AspNetCore.Authorization;
  17. using Volo.Abp;
  18. using Microsoft.EntityFrameworkCore;
  19. using NUglify.Helpers;
  20. using Volo.Abp.ObjectMapping;
  21. namespace Shentun.Peis.Patients
  22. {
  23. /// <summary>
  24. /// 体检人员
  25. /// </summary>
  26. [ApiExplorerSettings(GroupName = "Work")]
  27. [Authorize]
  28. public class PatientAppService : CrudAppService<
  29. Patient, //The Book entity
  30. PatientDto, //Used to show books
  31. Guid, //Primary key of the book entity
  32. PagedAndSortedResultRequestDto, //Used for paging/sorting
  33. CreatePatientDto,
  34. UpdatePatientDto>
  35. {
  36. private readonly IRepository<IdentityUser, Guid> _userRepository;
  37. private readonly PatientRegisterManager _patientRegisterManager;
  38. private readonly PatientManager _manager;
  39. private readonly CacheService _cacheService;
  40. public PatientAppService(
  41. IRepository<Patient, Guid> repository,
  42. IRepository<IdentityUser, Guid> userRepository,
  43. PatientRegisterManager patientRegisterManager,
  44. PatientManager manager,
  45. CacheService cacheService)
  46. : base(repository)
  47. {
  48. _userRepository = userRepository;
  49. this._patientRegisterManager = patientRegisterManager;
  50. _manager = manager;
  51. _cacheService = cacheService;
  52. }
  53. /// <summary>
  54. /// 获取通过主键
  55. /// </summary>
  56. /// <param name="id"></param>
  57. /// <returns></returns>
  58. public override async Task<PatientDto> GetAsync(Guid id)
  59. {
  60. return await base.GetAsync(id);
  61. }
  62. /// <summary>
  63. /// 获取列表 体检人员
  64. /// </summary>
  65. /// <param name="input"></param>
  66. /// <returns></returns>
  67. [RemoteService(false)]
  68. public override async Task<PagedResultDto<PatientDto>> GetListAsync(PagedAndSortedResultRequestDto input)
  69. {
  70. return await base.GetListAsync(input);
  71. }
  72. /// <summary>
  73. /// 获取列表 体检人员 可以带名字或者身份证号码搜索
  74. /// </summary>
  75. /// <param name="input"></param>
  76. /// <returns></returns>
  77. [HttpPost("api/app/patient/getlistinfilter")]
  78. public async Task<List<PatientOrMedicalTimesDto>> GetListInFilterAsync(GetListInFilterDto input)
  79. {
  80. var entlist = await Repository.GetQueryableAsync();
  81. if (!string.IsNullOrEmpty(input.Filter))
  82. {
  83. entlist = entlist.Where(m => m.DisplayName == input.Filter || m.IdNo == input.Filter);
  84. }
  85. var entdto = entlist.Select(s => new PatientOrMedicalTimesDto
  86. {
  87. CreationTime = s.CreationTime,
  88. CreatorId = s.CreatorId,
  89. DisplayName = s.DisplayName,
  90. Id = s.Id,
  91. LastModificationTime = s.LastModificationTime,
  92. LastModifierId = s.LastModifierId,
  93. MaritalStatusId = s.MaritalStatusId,
  94. Telephone = s.Telephone,
  95. SexId = s.SexId,
  96. PostalCode = s.PostalCode,
  97. Address = s.Address,
  98. BirthDate = DataHelper.ConversionDateToString(s.BirthDate),
  99. BirthPlaceId = s.BirthPlaceId,
  100. Email = s.Email,
  101. IdNo = s.IdNo,
  102. MobileTelephone = s.MobileTelephone,
  103. NationId = s.NationId,
  104. PatientNo = s.PatientNo,
  105. MedicalTimes = _patientRegisterManager.GetPatientCountNoAsync(s.Id),
  106. LastTime = _patientRegisterManager.GetPatientRegisterLastTime(s.Id),
  107. CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result,
  108. LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result
  109. }).OrderBy(m => m.Id).ToList();
  110. return entdto;
  111. }
  112. /// <summary>
  113. /// 通过身份证号获取人员信息
  114. /// </summary>
  115. /// <param name="idNoInputDto"></param>
  116. /// <returns></returns>
  117. [HttpPost("api/app/patient/GetByIdNo")]
  118. public async Task<PatientDto> GetByIdNo(IdNoInputDto idNoInputDto)
  119. {
  120. if (string.IsNullOrWhiteSpace(idNoInputDto.IdNo))
  121. {
  122. throw new UserFriendlyException("身份证号不能为空");
  123. }
  124. var entitys = await Repository.GetListAsync(o => o.IdNo == idNoInputDto.IdNo.Trim());
  125. if (entitys == null || !entitys.Any())
  126. {
  127. return null;
  128. }
  129. var dto = ObjectMapper.Map<Patient, PatientDto>(entitys.Last());
  130. return dto;
  131. }
  132. /// <summary>
  133. /// 创建
  134. /// </summary>
  135. /// <param name="input"></param>
  136. /// <returns></returns>
  137. public override async Task<PatientDto> CreateAsync(CreatePatientDto input)
  138. {
  139. var createEntity = ObjectMapper.Map<CreatePatientDto, Patient>(input);
  140. var entity = await _manager.CreateAsync(createEntity);
  141. entity = await Repository.InsertAsync(entity);
  142. var dto = ObjectMapper.Map<Patient, PatientDto>(entity);
  143. return dto;
  144. }
  145. /// <summary>
  146. /// 更新
  147. /// </summary>
  148. /// <param name="id"></param>
  149. /// <param name="input"></param>
  150. /// <returns></returns>
  151. public override async Task<PatientDto> UpdateAsync(Guid id, UpdatePatientDto input)
  152. {
  153. var entity = await Repository.GetAsync(id);
  154. var sourceEntity = ObjectMapper.Map<UpdatePatientDto, Patient>(input);
  155. await _manager.UpdateAsync(sourceEntity, entity);
  156. entity = await Repository.UpdateAsync(entity);
  157. return ObjectMapper.Map<Patient, PatientDto>(entity);
  158. }
  159. /// <summary>
  160. /// 删除
  161. /// </summary>
  162. /// <param name="id"></param>
  163. /// <returns></returns>
  164. public override async Task DeleteAsync(Guid id)
  165. {
  166. await _manager.CheckAndDeleteAsync(id);
  167. }
  168. }
  169. }