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.

327 lines
16 KiB

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 sdsd = client.GetJSONReportItemListByCustomerBarocdeAsync(barCode, aiDiKangKeyValue);
  102. }
  103. ////病理结果
  104. //var result_bl = await client.GetDetailByHospCodeAsync(_clientID, _clientGUID, barCode, 1);
  105. //var resultObj_bl = XmlHelper.DeserializeXmlAddRoot<GetDetailByHospCodePathologyOut>(result_bl.Body.GetDetailByHospCodeResult);
  106. //if (resultObj_bl.ResultsDataSet != null && resultObj_bl.ResultsDataSet.Tables.Count > 0 && string.IsNullOrWhiteSpace(barCodeDian))
  107. //{
  108. // barCodeDian = resultObj_bl.ResultsDataSet.Tables.FirstOrDefault().Barcode;
  109. //}
  110. //foreach (var li in lisResultFromInterfaces)
  111. //{
  112. // var dian_code = itemCommonTableOuts.FirstOrDefault(f => f.ItemId == li.ItemId);
  113. // if (dian_code != null)
  114. // {
  115. // if (resultObj_cg.ResultsDataSet != null)
  116. // {
  117. // var dianResult = resultObj_cg.ResultsDataSet.Tables.FirstOrDefault(f => f.S == dian_code.DianCode);
  118. // if (dianResult != null)
  119. // {
  120. // var createImportLisResultDto = new CreateImportLisResultDto()
  121. // {
  122. // LisRequestNo = li.LisRequestNo,
  123. // ItemId = Guid.Parse(li.ItemId),
  124. // ItemName = li.ItemName,
  125. // Result = dianResult.FinalResult,
  126. // // Unit = lisResult.Unit,
  127. // // ReferenceRangeValue = lisResult.ReferenceRangeValue,
  128. // // CriticalRangeValue = lisResult.CriticalRangeValue,
  129. // // ResultStatusId = lisResult.ResultStatusId,
  130. // // ReportPrompt = lisResult.ReportPrompt,
  131. // CheckDoctorName = defaultCheckDoctorName,
  132. // //CheckDate = dianResult.ApproveDate,
  133. // CheckDate = dianResult.CollectDate,
  134. // ExecOrganizationUnitId = Guid.Parse(execOrganizationUnitIdStr)
  135. // };
  136. // createImportLisResultDtos.Add(createImportLisResultDto);
  137. // }
  138. // }
  139. // if (resultObj_bl.ResultsDataSet != null)
  140. // {
  141. // var dianResult = resultObj_bl.ResultsDataSet.Tables.FirstOrDefault(f => f.TestCode == dian_code.DianCode);
  142. // if (dianResult != null)
  143. // {
  144. // var createImportLisResultDto = new CreateImportLisResultDto()
  145. // {
  146. // LisRequestNo = li.LisRequestNo,
  147. // ItemId = Guid.Parse(li.ItemId),
  148. // ItemName = li.ItemName,
  149. // Result = dianResult.Repidea,
  150. // // Unit = lisResult.Unit,
  151. // // ReferenceRangeValue = lisResult.ReferenceRangeValue,
  152. // // CriticalRangeValue = lisResult.CriticalRangeValue,
  153. // // ResultStatusId = lisResult.ResultStatusId,
  154. // // ReportPrompt = lisResult.ReportPrompt,
  155. // CheckDoctorName = defaultCheckDoctorName,
  156. // // CheckDate = dianResult.ReportDate,
  157. // CheckDate = dianResult.CollectDate,
  158. // ExecOrganizationUnitId = Guid.Parse(execOrganizationUnitIdStr)
  159. // };
  160. // createImportLisResultDtos.Add(createImportLisResultDto);
  161. // }
  162. // }
  163. // }
  164. //}
  165. //if (createImportLisResultDtos.Any())
  166. //{
  167. // var callResult = await CallAppServiceAsync<List<CreateImportLisResultDto>, object>("api/app/ImportLisResult/ImportResult", createImportLisResultDtos);
  168. //}
  169. ////导入图片
  170. //using (var clientReport = CreateReportClient(lisReportAddress))
  171. //{
  172. // var result_report = await clientReport.GetReportInfoAsync(_clientID, _clientGUID, barCodeDian, "0");
  173. // var resultObj_report = XmlHelper.DeserializeXmlAddRoot<GetReportInfoOut>(result_report.Body.GetReportInfoResult);
  174. // if (resultObj_report.Msg.Code == "1" && resultObj_report.ResultsDataSetReport != null && resultObj_report.ResultsDataSetReport.Tables.Any())
  175. // {
  176. // var ImportReportInputs = new List<UploadRegisterCheckPictureManyDto>();
  177. // foreach (var itemReport in resultObj_report.ResultsDataSetReport.Tables)
  178. // {
  179. // var base64str = ToBase64(itemReport.PicReportUrl);
  180. // var asbitemIds = asbitemCommonTableOuts.Where(m => m.DianCode == itemReport.TestCode).ToList();
  181. // if (asbitemIds.Any())
  182. // {
  183. // string sql_register_check_id = "select distinct b.id as register_check_id from patient_register as a " +
  184. // " left join register_check as b on a.id=b.patient_register_id " +
  185. // " left join register_check_asbitem as c on b.id=c.register_check_id " +
  186. // $" where a.id='{patientRegisterId}' and c.asbitem_id=ANY(@asbitemIds) ";
  187. // var registerCheckIds = (await conn.QueryAsync<RegisterCheckIdInputDto>(sql_register_check_id, new
  188. // {
  189. // asbitemIds = asbitemIds.Select(s => Guid.Parse(s.ItemId)).ToArray()
  190. // })).ToList();
  191. // foreach (var registerCheckId in registerCheckIds)
  192. // {
  193. // List<UploadRegisterCheckPictureManyPictureBaseStrsDto> pictureBaseStrs = new List<UploadRegisterCheckPictureManyPictureBaseStrsDto>();
  194. // pictureBaseStrs.Add(new UploadRegisterCheckPictureManyPictureBaseStrsDto
  195. // {
  196. // PictureBaseStr = base64str,
  197. // FileName = itemReport.TestCode,
  198. // IsPrint = 'Y'
  199. // });
  200. // ImportReportInputs.Add(new UploadRegisterCheckPictureManyDto
  201. // {
  202. // PictureBaseStrs = pictureBaseStrs,
  203. // PictureFileType = '0',
  204. // RegisterCheckId = registerCheckId.RegisterCheckId
  205. // });
  206. // }
  207. // }
  208. // }
  209. // foreach (var importReportInput in ImportReportInputs)
  210. // {
  211. // var callResult = await CallAppServiceAsync<UploadRegisterCheckPictureManyDto, object>("api/app/registercheckpicture/uploadregistercheckpicturemany", importReportInput);
  212. // }
  213. // }
  214. //}
  215. }
  216. catch (Exception ex)
  217. { }
  218. }
  219. #endregion
  220. }
  221. return new ImportLisResultPlugInsOut();
  222. }
  223. private AdiconWebServiceSoapClient CreateClient(string url)
  224. {
  225. return new AdiconWebServiceSoapClient(new BasicHttpBinding(),
  226. new EndpointAddress(url));
  227. }
  228. //private string ToBase64(string filename)
  229. //{
  230. // Stream stream;
  231. // string fileBase64;
  232. // if (filename.StartsWith("http"))
  233. // {
  234. // using (var httpClient = new HttpClient())
  235. // {
  236. // var response = httpClient.GetAsync(filename).Result;
  237. // if (response.IsSuccessStatusCode)
  238. // {
  239. // var contentStream = response.Content.ReadAsStreamAsync().Result;
  240. // using var memoryStream = new MemoryStream();
  241. // contentStream.CopyTo(memoryStream);
  242. // var fileBytes = memoryStream.ToArray();
  243. // return Convert.ToBase64String(fileBytes);
  244. // }
  245. // else
  246. // {
  247. // throw new Exception("转换base64时,返回错误:" + response.StatusCode);
  248. // }
  249. // }
  250. // }
  251. // else
  252. // {
  253. // using (stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
  254. // {
  255. // byte[] byteData = new byte[stream.Length];
  256. // stream.Read(byteData, 0, byteData.Length);
  257. // fileBase64 = Convert.ToBase64String(byteData);
  258. // stream.Close();
  259. // }
  260. // return fileBase64;
  261. // }
  262. //}
  263. }
  264. }