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.

311 lines
13 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 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
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 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
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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 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
2 years ago
3 years ago
2 years ago
3 years ago
  1. using AutoMapper.Internal.Mappers;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.EntityFrameworkCore;
  5. using Shentun.Peis.Diagnosises;
  6. using Shentun.Peis.Enums;
  7. using Shentun.Peis.GuidTypes;
  8. using Shentun.Peis.HelperDto;
  9. using Shentun.Peis.Items;
  10. using Shentun.Peis.Models;
  11. using Shentun.Peis.SuggestionDtos;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using Volo.Abp.Application.Dtos;
  18. using Volo.Abp.Application.Services;
  19. using Volo.Abp.Domain.Repositories;
  20. using Volo.Abp.Identity;
  21. namespace Shentun.Peis.Diagnosises
  22. {
  23. /// <summary>
  24. /// 诊断
  25. /// </summary>
  26. [ApiExplorerSettings(GroupName = "Work")]
  27. [Authorize]
  28. public class DiagnosisAppService : CrudAppService<
  29. Diagnosis, //The Book entity
  30. DiagnosisDto, //Used to show books
  31. Guid, //Primary key of the book entity
  32. PagedAndSortedResultRequestDto, //Used for paging/sorting
  33. CreateDiagnosisDto,
  34. UpdateDiagnosisDto>
  35. {
  36. private readonly IRepository<Suggestion, Guid> _suggestionRepository;
  37. private readonly IRepository<IdentityUser, Guid> _userRepository;
  38. private readonly DiagnosisManager _manager;
  39. public DiagnosisAppService(
  40. IRepository<Diagnosis, Guid> repository,
  41. IRepository<Suggestion, Guid> suggestionRepository,
  42. IRepository<IdentityUser, Guid> userRepository,
  43. DiagnosisManager manager)
  44. : base(repository)
  45. {
  46. this._suggestionRepository = suggestionRepository;
  47. this._userRepository = userRepository;
  48. _manager = manager;
  49. }
  50. /// <summary>
  51. /// 获取通过主键
  52. /// </summary>
  53. /// <param name="id"></param>
  54. /// <returns></returns>
  55. [HttpGet("api/app/diagnosis/getdiagnosis")]
  56. public override async Task<DiagnosisDto> GetAsync(Guid id)
  57. {
  58. var userList = await _userRepository.GetListAsync();
  59. var entity = await Repository.FindAsync(o => o.Id == id);
  60. if (entity == null)
  61. return null;
  62. var entdto = new DiagnosisDto
  63. {
  64. CreationTime = entity.CreationTime,
  65. CreatorId = entity.CreatorId,
  66. DiagnosisLevelId = entity.DiagnosisLevelId,
  67. DisplayName = entity.DisplayName,
  68. DisplayOrder = entity.DisplayOrder,
  69. ForSexId = entity.ForSexId,
  70. Id = entity.Id,
  71. IsIll = entity.IsIll,
  72. IsSummaryTemplate = entity.IsSummaryTemplate,
  73. ItemTypeId = entity.ItemTypeId,
  74. LastModificationTime = entity.LastModificationTime,
  75. LastModifierId = entity.LastModifierId,
  76. CreatorName = EntityHelper.GetUserNameNoSql(userList, entity.CreatorId),
  77. LastModifierName = EntityHelper.GetUserNameNoSql(userList, entity.LastModifierId),
  78. SimpleCode = entity.SimpleCode,
  79. SuggestionName = entity.SuggestionName
  80. };
  81. return entdto;
  82. }
  83. /// <summary>
  84. /// 获取列表 诊断 可以按项目类别搜 两个接口组合到一起
  85. /// </summary>
  86. /// <param name="input"></param>
  87. /// <returns></returns>
  88. [HttpPost("api/app/diagnosis/getlistinsuggestion")]
  89. public async Task<List<DiagnosisInSuggestionDto>> GetListInSuggestionAsync(DiagnosisInSuggestionRequestDto input)
  90. {
  91. var query = from a in await Repository.GetQueryableAsync()
  92. join b in await _suggestionRepository.GetQueryableAsync() on a.Id equals b.DiagnosisId into bb
  93. from ab in bb.DefaultIfEmpty()
  94. join c in await _userRepository.GetQueryableAsync() on a.CreatorId equals c.Id into cc
  95. from ac in cc.DefaultIfEmpty()
  96. join d in await _userRepository.GetQueryableAsync() on a.LastModifierId equals d.Id into dd
  97. from ad in dd.DefaultIfEmpty()
  98. join e in await _userRepository.GetQueryableAsync() on ab.CreatorId equals e.Id into ee
  99. from ae in ee.DefaultIfEmpty()
  100. join f in await _userRepository.GetQueryableAsync() on ab.LastModifierId equals f.Id into ff
  101. from af in ff.DefaultIfEmpty()
  102. select new { a, ab, ac, ad, ae, af };
  103. if (input.ItemTypeId != null)
  104. {
  105. query = query.Where(m => m.a.ItemTypeId == input.ItemTypeId);
  106. }
  107. if (!string.IsNullOrEmpty(input.KeyWords))
  108. {
  109. query = query.Where(m => (string.IsNullOrEmpty(m.a.DisplayName) && m.a.DisplayName.Contains(input.KeyWords))
  110. || (string.IsNullOrEmpty(m.a.SuggestionName) && m.a.SuggestionName.Contains(input.KeyWords))
  111. || (string.IsNullOrEmpty(m.a.SimpleCode) && m.a.SimpleCode.Contains(input.KeyWords))
  112. );
  113. }
  114. var entlist = query.GroupBy(g => g.a.Id).Select(s => new DiagnosisInSuggestionDto
  115. {
  116. CreationTime = s.FirstOrDefault().a.CreationTime,
  117. CreatorId = s.FirstOrDefault().a.CreatorId,
  118. DisplayName = s.FirstOrDefault().a.DisplayName,
  119. DisplayOrder = s.FirstOrDefault().a.DisplayOrder,
  120. Id = s.FirstOrDefault().a.Id,
  121. LastModificationTime = s.FirstOrDefault().a.LastModificationTime,
  122. LastModifierId = s.FirstOrDefault().a.LastModifierId,
  123. SimpleCode = s.FirstOrDefault().a.SimpleCode,
  124. CreatorName = s.FirstOrDefault().ac != null ? s.FirstOrDefault().ac.UserName : "",
  125. LastModifierName = s.FirstOrDefault().ad != null ? s.FirstOrDefault().ad.UserName : "",
  126. DiagnosisLevelId = s.FirstOrDefault().a.DiagnosisLevelId,
  127. ForSexId = s.FirstOrDefault().a.ForSexId,
  128. IsIll = s.FirstOrDefault().a.IsIll,
  129. IsSummaryTemplate = s.FirstOrDefault().a.IsSummaryTemplate,
  130. ItemTypeId = s.FirstOrDefault().a.ItemTypeId,
  131. SuggestionName = s.FirstOrDefault().a.SuggestionName,
  132. HealthGuidances = s.Where(m => m.ab != null && m.ab.SuggestionType == SuggestionTypeFlag.HealthGuidance).Select(ss => new SuggestionDto
  133. {
  134. CreationTime = ss.ab.CreationTime,
  135. CreatorId = ss.ab.CreatorId,
  136. CreatorName = s.FirstOrDefault().ae != null ? s.FirstOrDefault().ae.UserName : "",
  137. LastModifierName = s.FirstOrDefault().af != null ? s.FirstOrDefault().af.UserName : "",
  138. DiagnosisId = ss.ab.DiagnosisId,
  139. DisplayOrder = ss.ab.DisplayOrder,
  140. Id = ss.ab.Id,
  141. LastModificationTime = ss.ab.LastModificationTime,
  142. LastModifierId = ss.ab.LastModifierId,
  143. SuggestionContent = ss.ab.SuggestionContent
  144. }).OrderBy(o => o.DisplayOrder).ToList(),
  145. MedicalInterpretations = s.Where(m => m.ab != null && m.ab.SuggestionType == SuggestionTypeFlag.MedicalInterpretation).Select(ss => new SuggestionDto
  146. {
  147. CreationTime = ss.ab.CreationTime,
  148. CreatorId = ss.ab.CreatorId,
  149. CreatorName = s.FirstOrDefault().ae != null ? s.FirstOrDefault().ae.UserName : "",
  150. LastModifierName = s.FirstOrDefault().af != null ? s.FirstOrDefault().af.UserName : "",
  151. DiagnosisId = ss.ab.DiagnosisId,
  152. DisplayOrder = ss.ab.DisplayOrder,
  153. Id = ss.ab.Id,
  154. LastModificationTime = ss.ab.LastModificationTime,
  155. LastModifierId = ss.ab.LastModifierId,
  156. SuggestionContent = ss.ab.SuggestionContent
  157. }).OrderBy(o => o.DisplayOrder).ToList(),
  158. }).OrderBy(o => o.ItemTypeId).ThenBy(o => o.DisplayOrder).ToList();
  159. return entlist;
  160. }
  161. ///// <summary>
  162. ///// 获取列表 根据项目类别获取
  163. ///// </summary>
  164. ///// <param name="ItemTypeId"></param>
  165. ///// <returns></returns>
  166. //public async Task<List<DiagnosisDto>> GetListInItemTypeAsync(Guid ItemTypeId)
  167. //{
  168. // var entlist = await Repository.GetListAsync(m => m.ItemTypeId == ItemTypeId);
  169. // var userList = await _userRepository.GetListAsync();
  170. // var entdto = entlist.Select(s => new DiagnosisDto
  171. // {
  172. // CreationTime = s.CreationTime,
  173. // CreatorId = s.CreatorId,
  174. // DisplayName = s.DisplayName,
  175. // DisplayOrder = s.DisplayOrder,
  176. // Id = s.Id,
  177. // LastModificationTime = s.LastModificationTime,
  178. // LastModifierId = s.LastModifierId,
  179. // SimpleCode = s.SimpleCode,
  180. // CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId),
  181. // LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId)
  182. // }).ToList();
  183. // return entdto;
  184. //}
  185. ///// <summary>
  186. ///// 获取列表 诊断 带搜索
  187. ///// </summary>
  188. ///// <param name="input"></param>
  189. ///// <returns></returns>
  190. //[HttpPost("api/app/diagnosis/getlistinfilter")]
  191. //public async Task<PagedResultDto<DiagnosisDto>> GetListInFilterAsync(GetListInFilterDto input)
  192. //{
  193. // int totalCount = 0;
  194. // if (!string.IsNullOrEmpty(input.Filter))
  195. // totalCount = (await Repository.GetListAsync()).Where(m => m.DisplayName.Contains(input.Filter)).Count();
  196. // else
  197. // totalCount = await Repository.CountAsync();
  198. // var entlist = await PageHelper.GetPageListInFitler(Repository, _userRepository, input);
  199. // var userList = await _userRepository.GetListAsync();
  200. // var entdto = entlist.Select(s => new DiagnosisDto
  201. // {
  202. // CreationTime = s.CreationTime,
  203. // CreatorId = s.CreatorId,
  204. // DisplayName = s.DisplayName,
  205. // DisplayOrder = s.DisplayOrder,
  206. // Id = s.Id,
  207. // LastModificationTime = s.LastModificationTime,
  208. // LastModifierId = s.LastModifierId,
  209. // SimpleCode = s.SimpleCode,
  210. // CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId),
  211. // LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId)
  212. // }).ToList();
  213. // return new PagedResultDto<DiagnosisDto>(totalCount, entdto);
  214. //}
  215. /// <summary>
  216. /// 创建
  217. /// </summary>
  218. /// <param name="input"></param>
  219. /// <returns></returns>
  220. [HttpPost("api/app/diagnosis/creatediagnosis")]
  221. public override async Task<DiagnosisDto> CreateAsync(CreateDiagnosisDto input)
  222. {
  223. var createEntity = ObjectMapper.Map<CreateDiagnosisDto, Diagnosis>(input);
  224. var entity = await _manager.CreateAsync(createEntity);
  225. entity = await Repository.InsertAsync(entity, true);
  226. var entdto = await GetAsync(entity.Id);
  227. return entdto;
  228. }
  229. /// <summary>
  230. /// 更新
  231. /// </summary>
  232. /// <param name="id"></param>
  233. /// <param name="input"></param>
  234. /// <returns></returns>
  235. [HttpPost("api/app/diagnosis/updatediagnosis")]
  236. public override async Task<DiagnosisDto> UpdateAsync(Guid id, UpdateDiagnosisDto input)
  237. {
  238. var entity = await Repository.GetAsync(id);
  239. var sourceEntity = ObjectMapper.Map<UpdateDiagnosisDto, Diagnosis>(input);
  240. await _manager.UpdateAsync(sourceEntity, entity);
  241. entity = await Repository.UpdateAsync(entity);
  242. var entdto = await GetAsync(id);
  243. return entdto;
  244. }
  245. /// <summary>
  246. /// 删除
  247. /// </summary>
  248. /// <param name="id"></param>
  249. /// <returns></returns>
  250. [HttpPost("api/app/diagnosis/deletediagnosis")]
  251. public override Task DeleteAsync(Guid id)
  252. {
  253. return base.DeleteAsync(id);
  254. }
  255. /// <summary>
  256. /// 修改排序 置顶,置底
  257. /// </summary>
  258. /// <param name="id">需要修改的ID</param>
  259. /// <param name="SortType">修改方式:1 置顶 2 置底</param>
  260. /// <returns></returns>
  261. [HttpPut("api/app/diagnosis/updatemanysort")]
  262. public async Task UpdateManySortAsync(Guid id, int SortType)
  263. {
  264. await _manager.UpdateManySortAsync(id, SortType);
  265. }
  266. /// <summary>
  267. /// 修改排序 拖拽
  268. /// </summary>
  269. /// <param name="input"></param>
  270. /// <returns></returns>
  271. [HttpPut("api/app/diagnosis/updatesortmany")]
  272. public async Task UpdateSortManyAsync(UpdateSortManyDto input)
  273. {
  274. await _manager.UpdateSortManyAsync(input);
  275. }
  276. }
  277. }