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.

255 lines
9.1 KiB

5 months ago
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Shentun.PeisReport.Api.Dto;
  5. using Shentun.PeisReport.Api.Dto.ReportBusiness;
  6. using Shentun.PeisReport.Api.Jwt;
  7. using SqlSugar;
  8. using System.Data;
  9. using System.Security.Claims;
  10. namespace Shentun.PeisReport.Api.Controllers
  11. {
  12. /// <summary>
  13. /// 监利医院
  14. /// </summary>
  15. [Route("api/[controller]/[action]")]
  16. [ApiController]
  17. [ApiExplorerSettings(GroupName ="JianLiApi")]
  18. //[Authorize]
  19. public class ReportBusinessController : ControllerBase
  20. {
  21. private readonly SqlSugarClient _peisDb;
  22. private readonly SqlSugarClient _lisDb;
  23. private readonly IConfiguration _configuration;
  24. private readonly ILogger<ReportBusinessController> _logger;
  25. /// <summary>
  26. ///
  27. /// </summary>
  28. public ReportBusinessController(
  29. ILogger<ReportBusinessController> logger,
  30. IConfiguration configuration
  31. )
  32. {
  33. _logger = logger;
  34. _configuration = configuration;
  35. _peisDb = new SqlSugarClient(new ConnectionConfig()
  36. {
  37. ConnectionString = _configuration.GetSection("ConnectionStrings:Default").Value,
  38. DbType = SqlSugar.DbType.SqlServer,
  39. IsAutoCloseConnection = true
  40. });
  41. _lisDb = new SqlSugarClient(new ConnectionConfig()
  42. {
  43. ConnectionString = _configuration.GetSection("ConnectionStrings:Lis").Value,
  44. DbType = SqlSugar.DbType.SqlServer,
  45. IsAutoCloseConnection = true
  46. });
  47. }
  48. /// <summary>
  49. /// 根据身份证号码获取体检报告
  50. /// </summary>
  51. /// <param name="input"></param>
  52. /// <returns></returns>
  53. [HttpPost]
  54. public async Task<GetPeisReportByIdNoDto> GetPeisReportByIdNoAsync(GetPeisReportByIdNoInputDto input)
  55. {
  56. var result = new GetPeisReportByIdNoDto
  57. {
  58. Code = 100,
  59. Message = "请求失败"
  60. };
  61. if (string.IsNullOrWhiteSpace(input.IdNo))
  62. {
  63. result.Message = "身份证不能为空";
  64. return result;
  65. }
  66. try
  67. {
  68. var query = await _peisDb.Ado.GetDataTableAsync($"select top {input.ReportCount} patient_register_id,barcode_no,medical_times,id_card_no," +
  69. $"medical_start_date,mobile_telephone,name as patient_name" +
  70. $" from patient_register " +
  71. $" where id_card_no='{input.IdNo}' and create_pdf_flag='1' order by patient_register_id desc ");
  72. if (query.Rows.Count > 0)
  73. {
  74. List<GetPeisReportByIdNoResultDataDto> patientRegisterList = new List<GetPeisReportByIdNoResultDataDto>();
  75. foreach (DataRow row in query.Rows)
  76. {
  77. var patientRegister = new GetPeisReportByIdNoResultDataDto
  78. {
  79. BarcodeNo = row["barcode_no"].ToString(),
  80. MedicalDate = Convert.ToDateTime(row["medical_start_date"].ToString()).ToString("yyyy-MM-dd"),
  81. MedicalTimes = row["medical_times"].ToString(),
  82. MobileTelephone = row["mobile_telephone"].ToString(),
  83. PatientName = row["patient_name"].ToString(),
  84. IdNo = row["id_card_no"].ToString()
  85. };
  86. var patientRegisterId = row["patient_register_id"].ToString();
  87. string directoryDate = patientRegisterId.Substring(0, 6);
  88. string hostAddress = _configuration.GetSection("HostAddress").Value;
  89. string reportVirtual = _configuration.GetSection("ReportVirtualPath:RequestPath").Value;
  90. string reportUrl = $"{hostAddress + reportVirtual}/{directoryDate}/{patientRegisterId}({patientRegister.PatientName}).pdf";
  91. patientRegister.ReportUrl = reportUrl;
  92. patientRegisterList.Add(patientRegister);
  93. }
  94. result.Message = "请求成功";
  95. result.Data = patientRegisterList;
  96. result.Code = 200;
  97. }
  98. else
  99. {
  100. result.Code = 100;
  101. result.Message = "身份证号未查到体检数据";
  102. }
  103. }
  104. catch (Exception ex)
  105. {
  106. result.Message = ex.Message;
  107. _logger.LogError($"访问GetPeisReportByIdNoAsync异常,异常信息:{ex.Message}");
  108. }
  109. return result;
  110. }
  111. /// <summary>
  112. /// 根据身份证号码获取检验报告
  113. /// </summary>
  114. /// <param name="input"></param>
  115. /// <returns></returns>
  116. [HttpPost]
  117. public async Task<GetLisReportByIdNoDto> GetLisReportByIdNoAsync(GetLisReportByIdNoInputDto input)
  118. {
  119. var result = new GetLisReportByIdNoDto
  120. {
  121. Code = 100,
  122. Message = "请求失败"
  123. };
  124. if (string.IsNullOrWhiteSpace(input.IdNo))
  125. {
  126. result.Message = "身份证不能为空";
  127. return result;
  128. }
  129. try
  130. {
  131. var query = await _lisDb.Ado.GetDataTableAsync($" select patient_register_id,patient_name,inspection_purpose,telephone,send_datetime from patient_register" +
  132. $" where upload_web_flag='Y' and inspection_datetime>= DATEADD(DAY,-{input.ReportDay},GETDATE()) " +
  133. $" and recieve_source_primarykey in " +
  134. $" (select recieve_source_primarykey from patient_request where id_card_no='{input.IdNo}' ) order by patient_register_id desc ");
  135. if (query.Rows.Count > 0)
  136. {
  137. List<GetLisReportByIdNoResultDataDto> patientRegisterList = new List<GetLisReportByIdNoResultDataDto>();
  138. foreach (DataRow row in query.Rows)
  139. {
  140. var patientRegister = new GetLisReportByIdNoResultDataDto
  141. {
  142. InspectionPurpose = row["inspection_purpose"].ToString(),
  143. SendDateTime = Convert.ToDateTime(row["send_datetime"].ToString()).ToString("yyyy-MM-dd"),
  144. MobileTelephone = row["telephone"].ToString(),
  145. PatientName = row["patient_name"].ToString(),
  146. IdNo = input.IdNo
  147. };
  148. var patientRegisterId = row["patient_register_id"].ToString();
  149. string hostAddress = _configuration.GetSection("HostAddress").Value;
  150. string reportVirtual = _configuration.GetSection("LisReportVirtualPath:RequestPath").Value;
  151. string reportUrl = $"{hostAddress + reportVirtual}/{patientRegisterId}.pdf";
  152. patientRegister.ReportUrl = reportUrl;
  153. patientRegisterList.Add(patientRegister);
  154. }
  155. result.Message = "请求成功";
  156. result.Data = patientRegisterList;
  157. result.Code = 200;
  158. }
  159. else
  160. {
  161. result.Code = 100;
  162. result.Message = "身份证号未查到检验报告数据";
  163. }
  164. }
  165. catch (Exception ex)
  166. {
  167. result.Message = ex.Message;
  168. _logger.LogError($"访问GetLisReportByIdNoAsync异常,异常信息:{ex.Message}");
  169. }
  170. return result;
  171. }
  172. #region 身份验证
  173. ///// <summary>
  174. ///// 登陆
  175. ///// </summary>
  176. ///// <returns></returns>
  177. //[HttpPost]
  178. //[AllowAnonymous]
  179. //public ActionResult<string> Logon()
  180. //{
  181. // var userId = "001";
  182. // var userName = "wenxiande";
  183. // var roleName = "Bus";
  184. // var claims = new List<Claim>()
  185. // {
  186. // new Claim("UserId",userId),
  187. // new Claim(ClaimTypes.Sid,userId),
  188. // new Claim("UserName",userName),
  189. // new Claim(ClaimTypes.Name,userName)
  190. // };
  191. // claims.Add(new Claim(ClaimTypes.Role, roleName));
  192. // JwtHelper jwtHelper = new JwtHelper();
  193. // return jwtHelper.GetJwt(claims);
  194. //}
  195. ///// <summary>
  196. ///// 查询测试
  197. ///// </summary>
  198. ///// <returns></returns>
  199. //[HttpPost]
  200. //[Authorize(Roles = "Bus")]
  201. //public PublicResultDto TestSqlAsync()
  202. //{
  203. // var result = new PublicResultDto
  204. // {
  205. // Code = 200,
  206. // Message = "请求成功"
  207. // };
  208. // return result;
  209. //}
  210. #endregion
  211. }
  212. }