PdfUtils.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. }
  73. else
  74. {
  75. // 三方lis
  76. }
  77. return "失败";
  78. }
  79. public static string GeneratePdf(int lisVersion, string reportNumber, string bbid)
  80. {
  81. return getPdfParamByLisVersion(lisVersion, reportNumber, bbid);
  82. }
  83. //调用exe
  84. public static bool CallingProgram(string strJson)
  85. {
  86. // 定义要启动的外部程序的路径
  87. string exePath = @"C:\APPSOFT\ReportPrint\zlgyReport.exe";
  88. // 定义要传递给外部程序的参数
  89. string arguments = "strJson " + strJson;
  90. // 创建一个新的 ProcessStartInfo 对象
  91. ProcessStartInfo startInfo = new ProcessStartInfo
  92. {
  93. FileName = exePath, // 设置要启动的程序路径
  94. Arguments = arguments, // 设置传递给程序的参数
  95. RedirectStandardOutput = false, // 是否重定向标准输出(根据需要设置)
  96. RedirectStandardError = false, // 是否重定向标准错误(根据需要设置)
  97. UseShellExecute = true, // 是否使用操作系统的 shell 启动进程(通常设置为 true)
  98. CreateNoWindow = false // 是否创建窗口(如果不需要显示窗口,可以设置为 true)
  99. };
  100. try
  101. {
  102. // 启动外部程序
  103. using (Process process = Process.Start(startInfo))
  104. {
  105. // 如果需要等待程序结束,可以使用 process.WaitForExit()
  106. LogHelper.Info("生成lis报告中");
  107. process.WaitForExit();
  108. LogHelper.Info("成功生成lis报告");
  109. // 如果需要读取输出或错误,可以在这里处理
  110. string output = process.StandardOutput.ReadToEnd();
  111. string error = process.StandardError.ReadToEnd();
  112. LogHelper.Info("output==" + output);
  113. LogHelper.Info("error==" + error);
  114. }
  115. }
  116. catch (Exception ex)
  117. {
  118. // 处理异常,例如文件未找到、路径错误等
  119. LogHelper.Info("启动外部程序时出错: " + ex.Message);
  120. }
  121. return true;
  122. }
  123. static object Instance = null;
  124. public static bool Init()
  125. {
  126. if (Instance != null )
  127. {
  128. return true;
  129. }
  130. var para = JsonConvert.SerializeObject(new UserLogin
  131. {
  132. UserName = ConfigurationManager.AppSettings["UserName"],
  133. PassWord = ConfigurationManager.AppSettings["PasWord"],
  134. Server = ConfigurationManager.AppSettings["Server"]
  135. });
  136. LogHelper.Info("初始化入参" + para);
  137. string strReval = string.Empty;
  138. try
  139. {
  140. Process.GetProcessesByName("zlgyReport").ToList().ForEach(x => x.Kill());
  141. }
  142. catch (Exception ex) {
  143. LogHelper.Info("进程结束异常" + ex.Message); }
  144. var type = Type.GetTypeFromProgID("zlgyReport.clsGyReport");
  145. Instance = Activator.CreateInstance(type);
  146. ParameterModifier modifier = new ParameterModifier(2);
  147. modifier[1] = true;
  148. var result = type.InvokeMember("Init", BindingFlags.Default | BindingFlags.InvokeMethod, null, Instance, new object[] { para, strReval },
  149. new ParameterModifier[] { modifier },
  150. null,
  151. new string[] { "strJson", "strResult" });
  152. LogHelper.Info("出参:" + strReval);
  153. LogHelper.Info("返回:" + result.ToString());
  154. return (bool)result;
  155. }
  156. public static bool OutPdf(string para)
  157. {
  158. var type = Type.GetTypeFromProgID("zlgyReport.clsGyReport");
  159. ParameterModifier modifier = new ParameterModifier(2);
  160. modifier[1] = true;
  161. string strReval = string.Empty;
  162. var result = type.InvokeMember("ReportOpen", BindingFlags.Default | BindingFlags.InvokeMethod, null, Instance, new object[] { para, strReval },
  163. new ParameterModifier[] { modifier },
  164. null,
  165. new string[] { "strJson", "strResult" });
  166. LogHelper.Info("出参:" + strReval);
  167. LogHelper.Info("返回:" + result.ToString());
  168. return (bool)result;
  169. }
  170. public class UserLogin
  171. {
  172. public string UserName { get; set; }
  173. public string PassWord { get; set; }
  174. public string Server { get; set; }
  175. }
  176. }
  177. }