PdfUtils.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using Common;
  2. using LisPacsDataUpload.Models;
  3. using LisPacsDataUpload.Models.Report;
  4. using Newtonsoft.Json;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Configuration;
  8. using System.Data;
  9. using System.Diagnostics;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Text;
  14. namespace LisPacsDataUpload.business
  15. {
  16. /// <summary>
  17. /// pdf 工具类
  18. /// </summary>
  19. public class PdfUtils
  20. {
  21. /// <summary>
  22. /// 根据lis版本获取请求生成pdf报告的参数 0中联老版lis 1 中联新版lis 2 专业版临生免 10 标准服务老版lis 11标准服务新版lis 3 三方lis
  23. /// </summary>
  24. /// <returns></returns>
  25. public static string getPdfParamByLisVersion(int lisVersion, string reportNumber,string bbid)
  26. {
  27. string dicLis = AppDomain.CurrentDomain.BaseDirectory + "Lis\\";
  28. if (!Directory.Exists(dicLis))
  29. {
  30. Directory.CreateDirectory(dicLis);
  31. }
  32. string path = dicLis + "LIS" + bbid+ ".pdf";
  33. Paramater paramter = new Paramater
  34. {
  35. ZlSysCode = 2500,
  36. RePortCode = reportNumber,
  37. PdfPath = $"pdf={path}",
  38. InvokeType = 4
  39. };
  40. paramter.Params.Add(new SubParameter { Param = $"标本id={bbid}" });
  41. if (lisVersion==0)
  42. {
  43. //老版lis
  44. /* Select Distinct 'ZLCISBILL' || Trim(To_Char(b.编号, '00000')) || '-2' 报表编号, a.相关id, d.id 标本id
  45. From 病人医嘱记录 A,检验标本记录 d, 病历文件列表 B, 病历单据应用 C
  46. Where a.诊疗项目id = c.诊疗项目id And a.病人来源 = c.应用场合 And c.病历文件id = b.Id And a.Id = :id and a.相关id = d.医嘱id*/
  47. var id = ""; // 标本id
  48. paramter.Params.Add(new SubParameter { Param = $"标本id={id}" });
  49. }
  50. else if (lisVersion == 1)
  51. {
  52. // 新版lis
  53. /* Select distinct 'ZLLISBILL00' || Decode(b.病人来源, 2, c.住院单据, 3, c.体检单据, 4, c.院外单据, c.门诊单据) || '-2' 报表编号, a.Id 标本id
  54. From 检验报告记录 A, 检验申请组合 B, 检验仪器记录 C
  55. Where a.Id = b.标本id And a.仪器id = c.Id And b.医嘱id = :id*/
  56. string strJson= JsonConvert.SerializeObject(paramter);
  57. LogHelper.Info("strJson=="+ strJson);
  58. if (!Init())
  59. {
  60. LogHelper.Info("Init初始化异常");
  61. return "Init初始化异常";
  62. }
  63. //生成pdf成功
  64. if (OutPdf(strJson))
  65. {
  66. return path;
  67. }
  68. }
  69. else if (lisVersion == 2)
  70. {
  71. //专业版临生免
  72. string sql_zlhr = @"select standard_url from 互认配置表";
  73. DataTable dt_lis = OracleHelper<object>.RunQueryDS(sql_zlhr);
  74. string standard_url = dt_lis.Rows[0]["standard_url"].ToString();
  75. string jsonTemplate = "{\"input\":{\"req_info\":{\"rpt_id\":\"{rpt_id}\",\"rpt_type\":\"0\"},\"head\":{\"bizno\":\"S4021\",\"sysno\":\"zlhr\",\"tarno\":\"ZLHIS\",\"time\":\"{time}\",\"action_no\":\"{action_no}\"}}}";
  76. // 使用字符串插值替换占位符
  77. string data = jsonTemplate
  78. .Replace("{rpt_id}", bbid)
  79. .Replace("{time}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  80. .Replace("{action_no}", Guid.NewGuid().ToString());
  81. string responseString = Tools.WSDataToZlsoftInterface(standard_url, data);
  82. ZlsoftOutVO zlsoftOutVO = JsonConvert.DeserializeObject<ZlsoftOutVO>(responseString);
  83. if (!"A".Equals(zlsoftOutVO.input.ack_info.exe_status))
  84. {
  85. return zlsoftOutVO.input.ack_info.err_msg;
  86. }
  87. return zlsoftOutVO.input.file_info.rpt_content;
  88. }
  89. else
  90. {
  91. // 三方lis
  92. }
  93. return "失败";
  94. }
  95. public static string GeneratePdf(int lisVersion, string reportNumber, string bbid)
  96. {
  97. return getPdfParamByLisVersion(lisVersion, reportNumber, bbid);
  98. }
  99. //调用exe
  100. public static bool CallingProgram(string strJson)
  101. {
  102. // 定义要启动的外部程序的路径
  103. string exePath = @"C:\APPSOFT\ReportPrint\zlgyReport.exe";
  104. // 定义要传递给外部程序的参数
  105. string arguments = "strJson " + strJson;
  106. // 创建一个新的 ProcessStartInfo 对象
  107. ProcessStartInfo startInfo = new ProcessStartInfo
  108. {
  109. FileName = exePath, // 设置要启动的程序路径
  110. Arguments = arguments, // 设置传递给程序的参数
  111. RedirectStandardOutput = false, // 是否重定向标准输出(根据需要设置)
  112. RedirectStandardError = false, // 是否重定向标准错误(根据需要设置)
  113. UseShellExecute = true, // 是否使用操作系统的 shell 启动进程(通常设置为 true)
  114. CreateNoWindow = false // 是否创建窗口(如果不需要显示窗口,可以设置为 true)
  115. };
  116. try
  117. {
  118. // 启动外部程序
  119. using (Process process = Process.Start(startInfo))
  120. {
  121. // 如果需要等待程序结束,可以使用 process.WaitForExit()
  122. LogHelper.Info("生成lis报告中");
  123. process.WaitForExit();
  124. LogHelper.Info("成功生成lis报告");
  125. // 如果需要读取输出或错误,可以在这里处理
  126. string output = process.StandardOutput.ReadToEnd();
  127. string error = process.StandardError.ReadToEnd();
  128. LogHelper.Info("output==" + output);
  129. LogHelper.Info("error==" + error);
  130. }
  131. }
  132. catch (Exception ex)
  133. {
  134. // 处理异常,例如文件未找到、路径错误等
  135. LogHelper.Info("启动外部程序时出错: " + ex.Message);
  136. }
  137. return true;
  138. }
  139. static object Instance = null;
  140. public static bool Init()
  141. {
  142. if (Instance != null )
  143. {
  144. return true;
  145. }
  146. var para = JsonConvert.SerializeObject(new UserLogin
  147. {
  148. UserName = ConfigurationManager.AppSettings["UserName"],
  149. PassWord = ConfigurationManager.AppSettings["PasWord"],
  150. Server = ConfigurationManager.AppSettings["Server"]
  151. });
  152. LogHelper.Info("初始化入参" + para);
  153. string strReval = string.Empty;
  154. try
  155. {
  156. Process.GetProcessesByName("zlgyReport").ToList().ForEach(x => x.Kill());
  157. }
  158. catch (Exception ex) {
  159. LogHelper.Info("进程结束异常" + ex.Message); }
  160. var type = Type.GetTypeFromProgID("zlgyReport.clsGyReport");
  161. Instance = Activator.CreateInstance(type);
  162. ParameterModifier modifier = new ParameterModifier(2);
  163. modifier[1] = true;
  164. var result = type.InvokeMember("Init", BindingFlags.Default | BindingFlags.InvokeMethod, null, Instance, new object[] { para, strReval },
  165. new ParameterModifier[] { modifier },
  166. null,
  167. new string[] { "strJson", "strResult" });
  168. LogHelper.Info("出参:" + strReval);
  169. LogHelper.Info("返回:" + result.ToString());
  170. return (bool)result;
  171. }
  172. public static bool OutPdf(string para)
  173. {
  174. var type = Type.GetTypeFromProgID("zlgyReport.clsGyReport");
  175. ParameterModifier modifier = new ParameterModifier(2);
  176. modifier[1] = true;
  177. string strReval = string.Empty;
  178. var result = type.InvokeMember("ReportOpen", BindingFlags.Default | BindingFlags.InvokeMethod, null, Instance, new object[] { para, strReval },
  179. new ParameterModifier[] { modifier },
  180. null,
  181. new string[] { "strJson", "strResult" });
  182. LogHelper.Info("出参:" + strReval);
  183. LogHelper.Info("返回:" + result.ToString());
  184. return (bool)result;
  185. }
  186. public class UserLogin
  187. {
  188. public string UserName { get; set; }
  189. public string PassWord { get; set; }
  190. public string Server { get; set; }
  191. }
  192. }
  193. }