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.

276 lines
11 KiB

2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
  1. using Dapper;
  2. using Microsoft.Extensions.Configuration;
  3. using Microsoft.Identity.Client;
  4. using Newtonsoft.Json;
  5. using Npgsql;
  6. using ServiceReferenceDianLisReport;
  7. using ServiceReferenceDianLisResult;
  8. using Shentun.Peis.Enums;
  9. using Shentun.Peis.ImportLisResults;
  10. using Shentun.Peis.PlugIns.ColumnReferences;
  11. using Shentun.Peis.PlugIns.Extensions.ImportLisResults.Dian;
  12. using Shentun.Peis.PlugIns.ImportLisResults;
  13. using Shentun.Peis.PlugIns.ThirdPushs.Hty;
  14. using Shentun.Peis.PlugIns.WebAppoints;
  15. using Shentun.Peis.PrintReports;
  16. using Shentun.Peis.RegisterCheckPictures;
  17. using Shentun.Peis.ThirdInterfaces;
  18. using Spire.Pdf.Exporting.XPS.Schema;
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Data;
  22. using System.Data.Common;
  23. using System.Linq;
  24. using System.ServiceModel;
  25. using System.Text;
  26. using System.Threading.Tasks;
  27. using Volo.Abp;
  28. using static OpenIddict.Abstractions.OpenIddictConstants;
  29. namespace Shentun.Peis.PlugIns.Extensions.ThirdPushs.Hty
  30. {
  31. public class PushPeisResultPlugInsHty : PushPeisResultPlugInsBase
  32. {
  33. public PushPeisResultPlugInsHty(Guid thirdInterfaceId) : base(thirdInterfaceId)
  34. {
  35. }
  36. public async Task DoWork()
  37. {
  38. List<Guid> patientRegisters = await GetRequestPatientRegistersHtyAsync();
  39. foreach (var patientRegisterId in patientRegisters)
  40. {
  41. await PushHtyPeisResultByPatientRegisterIdAsync(patientRegisterId);
  42. }
  43. }
  44. /// <summary>
  45. /// 根据id推送信息到海豚云
  46. /// </summary>
  47. /// <param name="patientRegisterId"></param>
  48. /// <returns></returns>
  49. /// <exception cref="UserFriendlyException"></exception>
  50. public async Task<string> PushHtyPeisResultByPatientRegisterIdAsync(Guid patientRegisterId)
  51. {
  52. var pushBaseApi = InterfaceConfig.GetValue("Interface:PushBaseApi", "");
  53. var columnReferenceId = InterfaceConfig.GetValue("Interface:ColumnReferenceId", "");
  54. var token = GetThirdToken();
  55. if (string.IsNullOrWhiteSpace(token))
  56. {
  57. throw new UserFriendlyException("获取token失败");
  58. }
  59. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  60. {
  61. var sql_patient = $@" select b.patient_no,b.id_no,b.birth_date,a.medical_times,b.sex_id,a.patient_name,
  62. a.medical_start_date,a.patient_register_no,a.complete_flag from patient_register as a left join
  63. patient as b on a.patient_id=b.id where a.id=@patient_register_id ";
  64. var patientRegisterSqlEntity = (await conn.QueryFirstAsync(sql_patient,
  65. new { patient_register_id = patientRegisterId }));
  66. if (patientRegisterSqlEntity != null)
  67. {
  68. if (patientRegisterSqlEntity.complete_flag != "3")
  69. {
  70. throw new UserFriendlyException("人员为总检");
  71. }
  72. var pushRequest = new PushHtyDataInputDto();
  73. pushRequest.info = new PushHtyDataInputPatientDto
  74. {
  75. USERID = patientRegisterSqlEntity.patient_no.ToString(),
  76. CERTNO = patientRegisterSqlEntity.id_no.ToString(),
  77. BIRTHDATE = !string.IsNullOrWhiteSpace(patientRegisterSqlEntity.birth_date.ToString()) ? Convert.ToDateTime(patientRegisterSqlEntity.birth_date).ToString("yyyy-MM-dd") : "",
  78. USERTIMES = patientRegisterSqlEntity.medical_times.ToString(),
  79. GENDER = ConertSex(patientRegisterSqlEntity.sex_id.ToString()),
  80. NAME = patientRegisterSqlEntity.patient_name.ToString(),
  81. MEDICALDATE = Convert.ToDateTime(patientRegisterSqlEntity.medical_start_date).ToString("yyyy-MM-dd HH:mm:ss"),
  82. MEDICALCODE = patientRegisterSqlEntity.patient_register_no.ToString(),
  83. RORGNAME = ""
  84. };
  85. //查看项目
  86. var sql_item = $@" select c.display_name as item_name,b.* from register_check as a
  87. left join register_check_item as b on a.id=b.register_check_id
  88. left join item as c on b.item_id=c.id where a.patient_register_id=@patient_register_id ";
  89. var registerItemSqlEntity = await conn.QueryAsync(sql_item,
  90. new { patient_register_id = patientRegisterId });
  91. if (registerItemSqlEntity.Count() > 0)
  92. {
  93. #region 获取对照数据
  94. var sql_dz = $@" select a.code_value,b.interface_code_value from column_reference_code as a
  95. left join column_reference_interface as b on a.id=b.column_reference_code_id
  96. where a.column_reference_id=@column_reference_id ";
  97. var itemDZSqlEntity = (await conn.QueryAsync(sql_dz,
  98. new { column_reference_id = Guid.Parse(columnReferenceId) })).ToList();
  99. #endregion
  100. Dictionary<string, pushHtyDataItemDto> contents = new Dictionary<string, pushHtyDataItemDto>();
  101. foreach (var itemRow in registerItemSqlEntity)
  102. {
  103. var itemCode = itemDZSqlEntity.FirstOrDefault(f => f.code_value == itemRow.item_id.ToString());
  104. if (itemCode != null)
  105. {
  106. var constr = new pushHtyDataItemDto
  107. {
  108. dicValue = itemRow.reference_range_value,
  109. ordinary = 1,
  110. p_value = itemRow.result,
  111. sysCode = itemCode.interface_code_value,
  112. unit = itemRow.unit
  113. };
  114. var dcIndex = contents.Count + 1;
  115. contents.Add("con" + dcIndex, constr);
  116. }
  117. }
  118. pushRequest.content = contents;
  119. }
  120. string pushRequestJsonString = JsonConvert.SerializeObject(pushRequest, Formatting.Indented);
  121. //推送信息
  122. var formContent = new MultipartFormDataContent();
  123. formContent.Add(new StringContent(token), "token");
  124. formContent.Add(new StringContent("fbpc"), "urlFrom");
  125. formContent.Add(new StringContent("-1"), "tmId");
  126. formContent.Add(new StringContent(pushRequestJsonString, Encoding.UTF8, "application/json"), "pushData");
  127. var result = await HtyHttpPostHelper.PostFormDataAsync($"{pushBaseApi}/api/manageFrame/healthCheck/medicalInterfaceDataFetch.action", formContent, "PostmanRuntime-ApipostRuntime/1.1.0");
  128. var resultModel = JsonConvert.DeserializeObject<PushHtyDataResultDto>(result);
  129. if (resultModel.stateMessage == "suc")
  130. {
  131. #region 更新人员状态
  132. conn.Execute("update patient_register set is_push_third_result='Y' where id=@patient_register_id", new { patient_register_id = patientRegisterId });
  133. #endregion
  134. }
  135. return $"{pushRequest.info.NAME}_{pushRequest.info.MEDICALCODE}_推送结果:{resultModel.stateMessage}";
  136. }
  137. else
  138. {
  139. throw new UserFriendlyException("人员不存在");
  140. }
  141. }
  142. }
  143. /// <summary>
  144. /// 获取需要推送的人员id集合
  145. /// </summary>
  146. /// <returns></returns>
  147. public async Task<List<Guid>> GetRequestPatientRegistersHtyAsync()
  148. {
  149. var patientRegisterIds = new List<Guid>();
  150. var queryDaysStr = InterfaceConfig.GetValue("Interface:Scheduler:QueryDays", "");
  151. var isAuditWhere = InterfaceConfig.GetValue("Interface:Scheduler:IsAuditWhere", "");
  152. var uploadDateType = InterfaceConfig.GetValue("Interface:Scheduler:UploadDateType", "");
  153. var otherWhere = InterfaceConfig.GetValue("Interface:Scheduler:OtherWhere", "");
  154. var uploadCountLimit = InterfaceConfig.GetValue("Interface:Scheduler:UploadCountLimit", "");
  155. if (string.IsNullOrWhiteSpace(queryDaysStr))
  156. {
  157. queryDaysStr = "1";
  158. }
  159. if (!int.TryParse(queryDaysStr, out int days))
  160. {
  161. days = 1;
  162. }
  163. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  164. {
  165. string sql;
  166. sql = @"
  167. SELECT
  168. id
  169. from patient_register
  170. where complete_flag = @CompleteFlag ";
  171. if (uploadDateType == "1")
  172. {
  173. sql += " and summary_date>= @HandDate ";
  174. }
  175. else if (uploadDateType == "2")
  176. {
  177. sql += " and audit_date>= @HandDate ";
  178. }
  179. else
  180. {
  181. sql += " and last_modification_time>= @HandDate ";
  182. }
  183. if (isAuditWhere == "Y")
  184. {
  185. sql += " and is_audit='Y' ";
  186. }
  187. if (!string.IsNullOrWhiteSpace(otherWhere))
  188. {
  189. sql += otherWhere;
  190. }
  191. var parameters = new DynamicParameters();
  192. parameters.Add("HandDate", DateTime.Now.Date.AddDays(-days));
  193. parameters.Add("CompleteFlag", PatientRegisterCompleteFlag.SumCheck);
  194. sql += $" limit {uploadCountLimit} ";
  195. var patientRegisterSqlList = (await conn.QueryAsync<SyncPatientRegisterIdsDto>(sql, parameters)).ToList();
  196. patientRegisterIds = patientRegisterSqlList.Select(s => s.Id).ToList();
  197. }
  198. return patientRegisterIds;
  199. }
  200. private string ConertSex(string sexId)
  201. {
  202. string res = "";
  203. if (sexId == "M")
  204. {
  205. res = "男";
  206. }
  207. else if (sexId == "F")
  208. {
  209. res = "女";
  210. }
  211. else
  212. {
  213. res = "未知";
  214. }
  215. return res;
  216. }
  217. }
  218. }