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.

290 lines
12 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month 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,b.address,b.mobile_telephone,b.telephone,
  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. #region 单位信息
  73. string sql_cusomter = @"select c.display_name from patient_register as a
  74. left join customer_org_register as b on a.customer_org_register_id=b.id
  75. left join customer_org as c on b.customer_org_id=c.id where a.id=@patient_register_id ";
  76. var customerOrgName = conn.QuerySingleOrDefault<string>(sql_cusomter, new { patient_register_id = patientRegisterId });
  77. #endregion
  78. var pushRequest = new PushHtyDataInputDto();
  79. pushRequest.info = new PushHtyDataInputPatientDto
  80. {
  81. USERID = patientRegisterSqlEntity.patient_no.ToString(),
  82. CERTNO = patientRegisterSqlEntity.id_no?.ToString() ?? "",
  83. BIRTHDATE = !string.IsNullOrWhiteSpace(patientRegisterSqlEntity.birth_date?.ToString()) ? Convert.ToDateTime(patientRegisterSqlEntity.birth_date).ToString("yyyy-MM-dd") : "",
  84. USERTIMES = patientRegisterSqlEntity.medical_times.ToString(),
  85. GENDER = ConertSex(patientRegisterSqlEntity.sex_id.ToString()),
  86. NAME = patientRegisterSqlEntity.patient_name.ToString(),
  87. MEDICALDATE = Convert.ToDateTime(patientRegisterSqlEntity.medical_start_date).ToString("yyyy-MM-dd HH:mm:ss"),
  88. MEDICALCODE = patientRegisterSqlEntity.patient_register_no.ToString(),
  89. RORGNAME = customerOrgName,
  90. ADDRESS = patientRegisterSqlEntity.address?.ToString() ?? "",
  91. MOBILE = patientRegisterSqlEntity.mobile_telephone?.ToString() ?? "",
  92. TEL = patientRegisterSqlEntity.telephone?.ToString() ?? "",
  93. };
  94. //查看项目
  95. var sql_item = $@" select c.display_name as item_name,b.* from register_check as a
  96. left join register_check_item as b on a.id=b.register_check_id
  97. left join item as c on b.item_id=c.id where a.complete_flag='1' and a.patient_register_id=@patient_register_id ";
  98. var registerItemSqlEntity = await conn.QueryAsync(sql_item,
  99. new { patient_register_id = patientRegisterId });
  100. if (registerItemSqlEntity.Count() > 0)
  101. {
  102. #region 获取对照数据
  103. var sql_dz = $@" select a.code_value,b.interface_code_value from column_reference_code as a
  104. left join column_reference_interface as b on a.id=b.column_reference_code_id
  105. where a.column_reference_id=@column_reference_id ";
  106. var itemDZSqlEntity = (await conn.QueryAsync(sql_dz,
  107. new { column_reference_id = Guid.Parse(columnReferenceId) })).ToList();
  108. #endregion
  109. Dictionary<string, pushHtyDataItemDto> contents = new Dictionary<string, pushHtyDataItemDto>();
  110. foreach (var itemRow in registerItemSqlEntity)
  111. {
  112. var itemCode = itemDZSqlEntity.FirstOrDefault(f => f.code_value == itemRow.item_id.ToString());
  113. if (itemCode != null)
  114. {
  115. var constr = new pushHtyDataItemDto
  116. {
  117. dicValue = itemRow.reference_range_value?.ToString() ?? "",
  118. ordinary = 1,
  119. p_value = itemRow.result?.ToString() ?? "",
  120. sysCode = itemCode.interface_code_value,
  121. unit = itemRow.unit?.ToString() ?? ""
  122. };
  123. var dcIndex = contents.Count + 1;
  124. contents.Add("con" + dcIndex, constr);
  125. }
  126. }
  127. pushRequest.content = contents;
  128. }
  129. string pushRequestJsonString = JsonConvert.SerializeObject(pushRequest, Formatting.Indented);
  130. //推送信息
  131. var formContent = new MultipartFormDataContent();
  132. formContent.Add(new StringContent(token), "token");
  133. formContent.Add(new StringContent("fbpc"), "urlFrom");
  134. formContent.Add(new StringContent("-1"), "tmId");
  135. formContent.Add(new StringContent(pushRequestJsonString, Encoding.UTF8, "application/json"), "pushData");
  136. var result = await HtyHttpPostHelper.PostFormDataAsync($"{pushBaseApi}/api/manageFrame/healthCheck/medicalInterfaceDataFetch.action", formContent, "PostmanRuntime-ApipostRuntime/1.1.0");
  137. var resultModel = JsonConvert.DeserializeObject<PushHtyDataResultDto>(result);
  138. if (resultModel.stateMessage == "suc")
  139. {
  140. #region 更新人员状态
  141. conn.Execute("update patient_register set is_push_third_result='Y' where id=@patient_register_id", new { patient_register_id = patientRegisterId });
  142. #endregion
  143. }
  144. return $"{pushRequest.info.NAME}_{pushRequest.info.MEDICALCODE}_推送结果:{resultModel.stateMessage}";
  145. }
  146. else
  147. {
  148. throw new UserFriendlyException("人员不存在");
  149. }
  150. }
  151. }
  152. /// <summary>
  153. /// 获取需要推送的人员id集合
  154. /// </summary>
  155. /// <returns></returns>
  156. public async Task<List<Guid>> GetRequestPatientRegistersHtyAsync()
  157. {
  158. var patientRegisterIds = new List<Guid>();
  159. var queryDaysStr = InterfaceConfig.GetValue("Interface:Scheduler:QueryDays", "");
  160. var isAuditWhere = InterfaceConfig.GetValue("Interface:Scheduler:IsAuditWhere", "");
  161. var uploadDateType = InterfaceConfig.GetValue("Interface:Scheduler:UploadDateType", "");
  162. var otherWhere = InterfaceConfig.GetValue("Interface:Scheduler:OtherWhere", "");
  163. var uploadCountLimit = InterfaceConfig.GetValue("Interface:Scheduler:UploadCountLimit", "");
  164. if (string.IsNullOrWhiteSpace(queryDaysStr))
  165. {
  166. queryDaysStr = "1";
  167. }
  168. if (!int.TryParse(queryDaysStr, out int days))
  169. {
  170. days = 1;
  171. }
  172. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  173. {
  174. string sql;
  175. sql = @"
  176. SELECT
  177. id
  178. from patient_register
  179. where complete_flag = @CompleteFlag ";
  180. if (uploadDateType == "1")
  181. {
  182. sql += " and summary_date>= @HandDate ";
  183. }
  184. else if (uploadDateType == "2")
  185. {
  186. sql += " and audit_date>= @HandDate ";
  187. }
  188. else
  189. {
  190. sql += " and last_modification_time>= @HandDate ";
  191. }
  192. if (isAuditWhere == "Y")
  193. {
  194. sql += " and is_audit='Y' ";
  195. }
  196. if (!string.IsNullOrWhiteSpace(otherWhere))
  197. {
  198. sql += otherWhere;
  199. }
  200. var parameters = new DynamicParameters();
  201. parameters.Add("HandDate", DateTime.Now.Date.AddDays(-days));
  202. parameters.Add("CompleteFlag", PatientRegisterCompleteFlag.SumCheck);
  203. sql += $" limit {uploadCountLimit} ";
  204. var patientRegisterSqlList = (await conn.QueryAsync<SyncPatientRegisterIdsDto>(sql, parameters)).ToList();
  205. patientRegisterIds = patientRegisterSqlList.Select(s => s.Id).ToList();
  206. }
  207. return patientRegisterIds;
  208. }
  209. private string ConertSex(string sexId)
  210. {
  211. string res = "";
  212. if (sexId == "M")
  213. {
  214. res = "男";
  215. }
  216. else if (sexId == "F")
  217. {
  218. res = "女";
  219. }
  220. else
  221. {
  222. res = "未知";
  223. }
  224. return res;
  225. }
  226. }
  227. }