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.

329 lines
17 KiB

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