using Common; using LisPacsDataUpload.Models; using LisPacsDataUpload.Models.Report; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace LisPacsDataUpload.business { /// /// pdf 工具类 /// public class PdfUtils { /// /// 根据lis版本获取请求生成pdf报告的参数 0中联老版lis 1 中联新版lis 2 专业版临生免 10 标准服务老版lis 11标准服务新版lis 3 三方lis /// /// public static string getPdfParamByLisVersion(int lisVersion, string reportNumber,string bbid) { string dicLis = AppDomain.CurrentDomain.BaseDirectory + "Lis\\"; if (!Directory.Exists(dicLis)) { Directory.CreateDirectory(dicLis); } string path = dicLis + "LIS" + bbid+ ".pdf"; Paramater paramter = new Paramater { ZlSysCode = 2500, RePortCode = reportNumber, PdfPath = $"pdf={path}", InvokeType = 4 }; paramter.Params.Add(new SubParameter { Param = $"标本id={bbid}" }); if (lisVersion==0) { //老版lis /* Select Distinct 'ZLCISBILL' || Trim(To_Char(b.编号, '00000')) || '-2' 报表编号, a.相关id, d.id 标本id From 病人医嘱记录 A,检验标本记录 d, 病历文件列表 B, 病历单据应用 C Where a.诊疗项目id = c.诊疗项目id And a.病人来源 = c.应用场合 And c.病历文件id = b.Id And a.Id = :id and a.相关id = d.医嘱id*/ var id = ""; // 标本id paramter.Params.Add(new SubParameter { Param = $"标本id={id}" }); } else if (lisVersion == 1) { // 新版lis /* Select distinct 'ZLLISBILL00' || Decode(b.病人来源, 2, c.住院单据, 3, c.体检单据, 4, c.院外单据, c.门诊单据) || '-2' 报表编号, a.Id 标本id From 检验报告记录 A, 检验申请组合 B, 检验仪器记录 C Where a.Id = b.标本id And a.仪器id = c.Id And b.医嘱id = :id*/ string strJson= JsonConvert.SerializeObject(paramter); LogHelper.Info("strJson=="+ strJson); if (!Init()) { LogHelper.Info("Init初始化异常"); return "Init初始化异常"; } //生成pdf成功 if (OutPdf(strJson)) { return path; } } else if (lisVersion == 2) { //专业版临生免 } else { // 三方lis } return "失败"; } public static string GeneratePdf(int lisVersion, string reportNumber, string bbid) { return getPdfParamByLisVersion(lisVersion, reportNumber, bbid); } //调用exe public static bool CallingProgram(string strJson) { // 定义要启动的外部程序的路径 string exePath = @"C:\APPSOFT\ReportPrint\zlgyReport.exe"; // 定义要传递给外部程序的参数 string arguments = "strJson " + strJson; // 创建一个新的 ProcessStartInfo 对象 ProcessStartInfo startInfo = new ProcessStartInfo { FileName = exePath, // 设置要启动的程序路径 Arguments = arguments, // 设置传递给程序的参数 RedirectStandardOutput = false, // 是否重定向标准输出(根据需要设置) RedirectStandardError = false, // 是否重定向标准错误(根据需要设置) UseShellExecute = true, // 是否使用操作系统的 shell 启动进程(通常设置为 true) CreateNoWindow = false // 是否创建窗口(如果不需要显示窗口,可以设置为 true) }; try { // 启动外部程序 using (Process process = Process.Start(startInfo)) { // 如果需要等待程序结束,可以使用 process.WaitForExit() LogHelper.Info("生成lis报告中"); process.WaitForExit(); LogHelper.Info("成功生成lis报告"); // 如果需要读取输出或错误,可以在这里处理 string output = process.StandardOutput.ReadToEnd(); string error = process.StandardError.ReadToEnd(); LogHelper.Info("output==" + output); LogHelper.Info("error==" + error); } } catch (Exception ex) { // 处理异常,例如文件未找到、路径错误等 LogHelper.Info("启动外部程序时出错: " + ex.Message); } return true; } static object Instance = null; public static bool Init() { if (Instance != null ) { return true; } var para = JsonConvert.SerializeObject(new UserLogin { UserName = ConfigurationManager.AppSettings["UserName"], PassWord = ConfigurationManager.AppSettings["PasWord"], Server = ConfigurationManager.AppSettings["Server"] }); LogHelper.Info("初始化入参" + para); string strReval = string.Empty; try { Process.GetProcessesByName("zlgyReport").ToList().ForEach(x => x.Kill()); } catch (Exception ex) { LogHelper.Info("进程结束异常" + ex.Message); } var type = Type.GetTypeFromProgID("zlgyReport.clsGyReport"); Instance = Activator.CreateInstance(type); ParameterModifier modifier = new ParameterModifier(2); modifier[1] = true; var result = type.InvokeMember("Init", BindingFlags.Default | BindingFlags.InvokeMethod, null, Instance, new object[] { para, strReval }, new ParameterModifier[] { modifier }, null, new string[] { "strJson", "strResult" }); LogHelper.Info("出参:" + strReval); LogHelper.Info("返回:" + result.ToString()); return (bool)result; } public static bool OutPdf(string para) { var type = Type.GetTypeFromProgID("zlgyReport.clsGyReport"); ParameterModifier modifier = new ParameterModifier(2); modifier[1] = true; string strReval = string.Empty; var result = type.InvokeMember("ReportOpen", BindingFlags.Default | BindingFlags.InvokeMethod, null, Instance, new object[] { para, strReval }, new ParameterModifier[] { modifier }, null, new string[] { "strJson", "strResult" }); LogHelper.Info("出参:" + strReval); LogHelper.Info("返回:" + result.ToString()); return (bool)result; } public class UserLogin { public string UserName { get; set; } public string PassWord { get; set; } public string Server { get; set; } } } }