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.

272 lines
12 KiB

1 month ago
2 days ago
1 month ago
2 days ago
1 month ago
2 days ago
1 month ago
2 days ago
1 month ago
2 days ago
1 month ago
2 days ago
1 month ago
  1. using Dapper;
  2. using Npgsql;
  3. using ServiceReferenceAiDiKangLisResult;
  4. using ServiceReferenceDianLisReport;
  5. using ServiceReferenceDianLisResult;
  6. using Shentun.Peis.ImportLisResults;
  7. using Shentun.Peis.PlugIns.Extensions.ImportLisResults.Dian;
  8. using Shentun.Peis.PlugIns.ImportLisResults;
  9. using Shentun.Peis.PrintReports;
  10. using Shentun.Peis.RegisterCheckPictures;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Data.Common;
  14. using System.Linq;
  15. using System.ServiceModel;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace Shentun.Peis.PlugIns.Extensions.ImportLisResults.AiDiKang
  19. {
  20. public class ImportLisResultPlugInsAiDiKang : ImportLisResultPlugInsBase
  21. {
  22. private readonly string _userName;
  23. private readonly string _passWord;
  24. public ImportLisResultPlugInsAiDiKang(Guid thirdInterfaceId) : base(thirdInterfaceId)
  25. {
  26. _userName = InterfaceConfig.GetSection("Interface").GetSection("UserName").Value;
  27. _passWord = InterfaceConfig.GetSection("Interface").GetSection("PassWord").Value;
  28. }
  29. public ImportLisResultPlugInsAiDiKang(string parmValue) : base(parmValue)
  30. {
  31. _userName = InterfaceConfig.GetSection("Interface").GetSection("UserName").Value;
  32. _passWord = InterfaceConfig.GetSection("Interface").GetSection("PassWord").Value;
  33. }
  34. public override Task<ImportLisResultPlugInsOut> ImportResultByPatientRegisterIdAsync(Guid patientRegisterId)
  35. {
  36. return base.ImportResultByPatientRegisterIdAsync(patientRegisterId);
  37. }
  38. public override async Task DoWork()
  39. {
  40. var queryDaysStr = InterfaceConfig.GetSection("Interface").GetSection("Scheduler").GetSection("QueryDays").Value;
  41. if (string.IsNullOrWhiteSpace(queryDaysStr))
  42. {
  43. queryDaysStr = "1";
  44. }
  45. if (!int.TryParse(queryDaysStr, out int days))
  46. {
  47. days = 1;
  48. }
  49. var patientRegisters = GetRequestPatientRegistersDianAsync(days).Result;
  50. foreach (var patientRegister in patientRegisters)
  51. {
  52. await ImportOueSendResultByPatientRegisterIdAsync(patientRegister.PatientRegisterId);
  53. }
  54. }
  55. public async Task<ImportLisResultPlugInsOut> ImportOueSendResultByPatientRegisterIdAsync(Guid patientRegisterId)
  56. {
  57. var lisResultAddress = InterfaceConfig.GetSection("Interface").GetSection("LisResultAddress").Value;
  58. using (var client = CreateClient(lisResultAddress))
  59. {
  60. // 设置超时时间
  61. client.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(2);
  62. var aiDiKangKeyValue = await client.LoginAsync(_userName, _passWord);
  63. if (aiDiKangKeyValue == "失败")
  64. {
  65. return new ImportLisResultPlugInsOut();
  66. }
  67. var execOrganizationUnitIdStr = InterfaceConfig.GetSection("Interface").GetSection("ExecOrganizationUnitId").Value;
  68. var defaultCheckDoctorName = InterfaceConfig.GetSection("Interface").GetSection("DefaultCheckDoctorName").Value;
  69. var barcodeMode = InterfaceConfig.GetSection("Interface").GetSection("BarcodeMode").Value; //0-人员条码 1-检验条码
  70. #region 导入数据
  71. List<CommonTableOut> itemCommonTableOuts = new List<CommonTableOut>();
  72. //List<CommonTableOut> asbitemCommonTableOuts = new List<CommonTableOut>();
  73. string sql_item = $"select data_code as dian_code,display_name as item_id from common_table " +
  74. $" where common_table_type_id='{InterfaceConfig.GetSection("Interface").GetSection("ItemCommonTableTypeId").Value}' ";
  75. //string sql_asbitem = $"select data_code as dian_code,display_name as item_id from common_table " +
  76. // $" where common_table_type_id='{InterfaceConfig.GetSection("Interface").GetSection("AsbitemCommonTableTypeId").Value}' ";
  77. var result = new ImportLisResultPlugInsOut();
  78. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  79. {
  80. itemCommonTableOuts = (await conn.QueryAsync<CommonTableOut>(sql_item)).ToList();
  81. //asbitemCommonTableOuts = (await conn.QueryAsync<CommonTableOut>(sql_asbitem)).ToList();
  82. try
  83. {
  84. var createImportLisResultDtos = new List<CreateImportLisResultDto>();
  85. //设置结果,生成小结
  86. string register_item_sql = $"select d.lis_request_no,f.item_id::TEXT as item_id,g.display_name as item_name,patient_register_no" +
  87. " from patient_register as a " +
  88. " left join register_check as b on a.id=b.patient_register_id " +
  89. " left join register_check_asbitem as c on b.id=c.register_check_id " +
  90. " left join lis_request as d on c.lis_request_id=d.id " +
  91. " left join asbitem as e on c.asbitem_id=e.id " +
  92. " left join register_check_item as f on b.id=f.register_check_id " +
  93. " left join item as g on f.item_id=g.id " +
  94. $" where a.id='{patientRegisterId}' and e.is_outsend='Y' and b.is_audit='N' ";
  95. var lisResultFromInterfaces = (await conn.QueryAsync<LisResultFromImportInterface>(register_item_sql)).ToList();
  96. string barCode = lisResultFromInterfaces.FirstOrDefault().PatientRegisterNo;
  97. var isCheck = await client.ExistsByYYtmAsync(barCode, aiDiKangKeyValue);
  98. if (isCheck == "True")
  99. {
  100. //检查完
  101. var result_cg = await client.GetReportItemListByCustomerBarocdeAsync(aiDiKangKeyValue, barCode, "常规报告");
  102. var resultObj_cg = XmlHelper.DeserializeXml<GetReportItemListByCustomerBarocdeCGOut>(result_cg);
  103. foreach (var li in lisResultFromInterfaces)
  104. {
  105. var dian_code = itemCommonTableOuts.FirstOrDefault(f => f.ItemId == li.ItemId);
  106. if (dian_code != null)
  107. {
  108. if (resultObj_cg.Items != null && resultObj_cg.Items.Any())
  109. {
  110. var dianResult = resultObj_cg.Items.FirstOrDefault(f => f.ItemCode == dian_code.DianCode);
  111. if (dianResult != null)
  112. {
  113. DateTime collectionDate = DateTime.Now;
  114. if (DateTime.TryParse(dianResult.CollectionDate, out var itemCollectionDate))
  115. {
  116. // 使用 collectionDate
  117. collectionDate = itemCollectionDate;
  118. }
  119. var createImportLisResultDto = new CreateImportLisResultDto()
  120. {
  121. LisRequestNo = li.LisRequestNo,
  122. ItemId = Guid.Parse(li.ItemId),
  123. ItemName = li.ItemName,
  124. Result = dianResult.Result,
  125. // Unit = lisResult.Unit,
  126. // ReferenceRangeValue = lisResult.ReferenceRangeValue,
  127. // CriticalRangeValue = lisResult.CriticalRangeValue,
  128. // ResultStatusId = lisResult.ResultStatusId,
  129. // ReportPrompt = lisResult.ReportPrompt,
  130. CheckDoctorName = defaultCheckDoctorName,
  131. //CheckDate = dianResult.ApproveDate,
  132. CheckDate = collectionDate,
  133. ExecOrganizationUnitId = Guid.Parse(execOrganizationUnitIdStr)
  134. };
  135. createImportLisResultDtos.Add(createImportLisResultDto);
  136. }
  137. }
  138. }
  139. }
  140. if (createImportLisResultDtos.Any())
  141. {
  142. var callResult = await CallAppServiceAsync<List<CreateImportLisResultDto>, object>("api/app/ImportLisResult/ImportResult", createImportLisResultDtos);
  143. }
  144. }
  145. }
  146. catch (Exception ex)
  147. { }
  148. }
  149. #endregion
  150. }
  151. return new ImportLisResultPlugInsOut();
  152. }
  153. private AdiconWebServiceSoapClient CreateClient(string url)
  154. {
  155. // 创建自定义绑定,设置更大的消息大小限制
  156. var binding = new BasicHttpBinding();
  157. // 设置最大接收消息大小(根据需要调整,建议先设为 10MB)
  158. binding.MaxReceivedMessageSize = 10485760; // 10MB = 10 * 1024 * 1024
  159. binding.MaxBufferSize = 10485760; // 必须与 MaxReceivedMessageSize 保持一致
  160. // 设置 ReaderQuotas 以支持大字符串和大数组
  161. binding.ReaderQuotas.MaxDepth = 2147483647;
  162. binding.ReaderQuotas.MaxStringContentLength = 10485760;
  163. binding.ReaderQuotas.MaxArrayLength = 10485760;
  164. binding.ReaderQuotas.MaxBytesPerRead = 10485760;
  165. binding.ReaderQuotas.MaxNameTableCharCount = 10485760;
  166. // 可选:增加超时时间(因为大数据传输需要更长时间)
  167. binding.SendTimeout = TimeSpan.FromMinutes(5);
  168. binding.ReceiveTimeout = TimeSpan.FromMinutes(5);
  169. binding.OpenTimeout = TimeSpan.FromMinutes(5);
  170. binding.CloseTimeout = TimeSpan.FromMinutes(1);
  171. return new AdiconWebServiceSoapClient(binding,
  172. new EndpointAddress(url));
  173. }
  174. //private string ToBase64(string filename)
  175. //{
  176. // Stream stream;
  177. // string fileBase64;
  178. // if (filename.StartsWith("http"))
  179. // {
  180. // using (var httpClient = new HttpClient())
  181. // {
  182. // var response = httpClient.GetAsync(filename).Result;
  183. // if (response.IsSuccessStatusCode)
  184. // {
  185. // var contentStream = response.Content.ReadAsStreamAsync().Result;
  186. // using var memoryStream = new MemoryStream();
  187. // contentStream.CopyTo(memoryStream);
  188. // var fileBytes = memoryStream.ToArray();
  189. // return Convert.ToBase64String(fileBytes);
  190. // }
  191. // else
  192. // {
  193. // throw new Exception("转换base64时,返回错误:" + response.StatusCode);
  194. // }
  195. // }
  196. // }
  197. // else
  198. // {
  199. // using (stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
  200. // {
  201. // byte[] byteData = new byte[stream.Length];
  202. // stream.Read(byteData, 0, byteData.Length);
  203. // fileBase64 = Convert.ToBase64String(byteData);
  204. // stream.Close();
  205. // }
  206. // return fileBase64;
  207. // }
  208. //}
  209. }
  210. }