ecg图片pdf
This commit is contained in:
parent
244e5e58f4
commit
b6e1900460
@ -1,23 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="ftppath" value="ftp://47.94.80.150:21/"/>
|
||||
<add key="username" value="ecg"/>
|
||||
<add key="password" value="ecg"/>
|
||||
<add key="path1" value=""/>
|
||||
<add key="ecgHttpUrl" value=""/>
|
||||
<!--服务启用的ip地址-->
|
||||
<add key="ip" value="0.0.0.0"/>
|
||||
<!--服务启用端口-->
|
||||
<add key="port" value="4050"/>
|
||||
<!--是否屏幕输出信息-->
|
||||
<add key="log" value="1"/>
|
||||
<!--保存心电报告路径-->
|
||||
<add key="path" value=""/>
|
||||
<!--HIS相关-->
|
||||
<add key="flowygtUserName" value="tuguilaEcg" />
|
||||
<add key="flowygtUserPwd" value="Aa123456" />
|
||||
<add key="flowygtLoginUrl" value="https://pacs.gw12320.com/flowygt/thirdLogin" />
|
||||
<add key="flowygtReportAddUrl" value="https://pacs.gw12320.com/flowygt/ecg/record/reportAdd" />
|
||||
</appSettings>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
|
||||
<appSettings>
|
||||
<add key="ftppath" value="ftp://47.94.80.150:21/"/>
|
||||
<add key="username" value="ecg"/>
|
||||
<add key="password" value="ecg"/>
|
||||
<add key="path1" value=""/>
|
||||
<add key="ecgHttpUrl" value=""/>
|
||||
<!--服务启用的ip地址-->
|
||||
<add key="ip" value="0.0.0.0"/>
|
||||
<!--服务启用端口-->
|
||||
<add key="port" value="4050"/>
|
||||
<!--是否屏幕输出信息-->
|
||||
<add key="log" value="1"/>
|
||||
<!--保存心电报告路径-->
|
||||
<add key="path" value=""/>
|
||||
<!--图片型心电报告[诊断结果]位置-->
|
||||
<add key="printecg_image__diagContent_point" value="1390,134"/>
|
||||
<add key="printecg_image__diagContent_wrap" value="32"/>
|
||||
<!--图片型心电报告[签名医生]位置-->
|
||||
<add key="printecg_image__doctorName_point" value="3210,144"/>
|
||||
<add key="printecg_image__doctorNameImg_point" value="3218,148"/>
|
||||
<!--HIS相关-->
|
||||
<add key="flowygtUserName" value="tuguilaEcg" />
|
||||
<add key="flowygtUserPwd" value="Aa123456" />
|
||||
<add key="flowygtLoginUrl" value="https://pacs.gw12320.com/flowygt/thirdLogin" />
|
||||
<add key="flowygtReportAddUrl" value="https://pacs.gw12320.com/flowygt/ecg/record/reportAdd" />
|
||||
</appSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
|
@ -11,8 +11,8 @@ using System.Reflection.Emit;
|
||||
using 心电图绘制;
|
||||
using Newtonsoft.Json;
|
||||
using 心电图绘制.Properties;
|
||||
using 心电图绘制;
|
||||
using System.Drawing;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace _1200Gxml心电图绘制
|
||||
{
|
||||
@ -59,19 +59,72 @@ namespace _1200Gxml心电图绘制
|
||||
//获取客户端传递的参数
|
||||
// string data = request.Params == null ? "" : string.Join(";", request.Params.Select(x => x.Key + "=" + x.Value).ToArray());
|
||||
string strMQName = string.Empty;
|
||||
LogHelper.Info("接收到请求", "");
|
||||
//LogHelper.Info("接收到请求", "");
|
||||
string data = "";
|
||||
try
|
||||
{
|
||||
if (request != null && request.Params != null)
|
||||
{
|
||||
|
||||
if (request.URL.Contains("printecg"))
|
||||
//注意调整URL顺序
|
||||
if (request.URL.StartsWith(@"/printecg_image"))
|
||||
{
|
||||
JObject paramsObj = null;
|
||||
string[] array = request.Params.Select(x => x.Value).ToArray();
|
||||
if (array.Length > 0 && !string.IsNullOrWhiteSpace(array[0]))
|
||||
try
|
||||
{
|
||||
//LogHelper.Info("请求参数", array[0].Trim());
|
||||
paramsObj = JsonConvert.DeserializeObject<JObject>(array[0].Trim());
|
||||
}
|
||||
catch (Exception ex) { paramsObj = null; }
|
||||
if (paramsObj != null)
|
||||
{
|
||||
if (paramsObj.ContainsKey("filepath") &&
|
||||
!string.IsNullOrWhiteSpace(paramsObj["filepath"] == null ? null : paramsObj["filepath"].ToString().Trim()))
|
||||
{
|
||||
try
|
||||
{
|
||||
Log("开始处理请求:" + paramsObj["regid"].ToString().Trim());
|
||||
print.GetEcgViewDataImage_img(paramsObj);
|
||||
if (paramsObj["type"].ToString().Trim().Equals(@"1"))
|
||||
{
|
||||
data = print.imagebase;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = print.filename;
|
||||
}
|
||||
Log("请求处理完成:" + paramsObj["regid"].ToString().Trim());
|
||||
try
|
||||
{
|
||||
if (false)
|
||||
print.FlySubmit3(new PatientInfo()
|
||||
{
|
||||
regid = paramsObj["regid"].ToString().Trim(),
|
||||
examid = paramsObj["examid"].ToString().Trim(),
|
||||
diagContent = paramsObj["diagContent"] == null ? "" : paramsObj["diagContent"].ToString().Trim(),
|
||||
orgid = paramsObj["orgid"] == null ? "" : paramsObj["orgid"].ToString().Trim(),
|
||||
orgname = paramsObj["orgname"] == null ? "" : paramsObj["orgname"].ToString().Trim(),
|
||||
doctorName = paramsObj["doctorName"] == null ? "" : paramsObj["doctorName"].ToString().Trim(),
|
||||
isAbnormal = paramsObj["isAbnormal"] == null ? "" : paramsObj["isAbnormal"].ToString().Trim()
|
||||
});
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
catch (Exception ex) { data = "生成数据文件异常"; }
|
||||
}
|
||||
else
|
||||
data = "心电数据为空";
|
||||
}
|
||||
else
|
||||
data = "解析数据不正确";
|
||||
}
|
||||
else if (request.URL.StartsWith(@"/printecg"))
|
||||
{
|
||||
string[] array = request.Params.Select(x => x.Value).ToArray();
|
||||
if (array.Length > 0)
|
||||
{
|
||||
LogHelper.Info("请求参数", array[0]);
|
||||
//LogHelper.Info("请求参数", array[0]);
|
||||
PatientInfo patientInfo = JsonConvert.DeserializeObject<PatientInfo>(array[0]);
|
||||
print.cBoxSpeed = cBoxSpeed;
|
||||
print.cBoxAmplitude = cBoxAmplitude;
|
||||
@ -80,45 +133,58 @@ namespace _1200Gxml心电图绘制
|
||||
|
||||
if (patientInfo != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(patientInfo.filepath))
|
||||
if (!string.IsNullOrWhiteSpace(patientInfo.filepath))
|
||||
{
|
||||
Log("开始处理请求:" + patientInfo.regid);
|
||||
Image image = null;
|
||||
if (!string.IsNullOrEmpty(patientInfo.image))
|
||||
try
|
||||
{
|
||||
image = UniversalFun.ConvertFromBase64String(patientInfo.image);
|
||||
|
||||
Log("开始处理请求:" + patientInfo.regid);
|
||||
Image image = null;
|
||||
if (!string.IsNullOrWhiteSpace(patientInfo.image))
|
||||
{
|
||||
image = UniversalFun.ConvertFromBase64String(patientInfo.image);
|
||||
}
|
||||
string ecgDataJsonStr = UniversalFun.GetTextFileContent(patientInfo.filepath);
|
||||
print.GetEcgViewDataImage(image, "", patientInfo, patientInfo.type, ecgDataJsonStr);
|
||||
if (patientInfo.type == 1)
|
||||
{
|
||||
data = print.imagebase;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = print.filename;
|
||||
}
|
||||
Log("请求处理完成:" + patientInfo.regid);
|
||||
try
|
||||
{
|
||||
if (false)
|
||||
{
|
||||
patientInfo.diagContent = patientInfo.diagContent == null ? "" : patientInfo.diagContent.Trim();
|
||||
patientInfo.orgid = patientInfo.orgid == null ? "" : patientInfo.orgid.Trim();
|
||||
patientInfo.orgname = patientInfo.orgname == null ? "" : patientInfo.orgname.Trim();
|
||||
patientInfo.doctorName = patientInfo.doctorName == null ? "" : patientInfo.doctorName.Trim();
|
||||
patientInfo.isAbnormal = patientInfo.isAbnormal == null ? "" : patientInfo.isAbnormal.Trim();
|
||||
print.FlySubmit3(patientInfo);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
string ecgDataJsonStr = UniversalFun.GetTextFileContent(patientInfo.filepath);
|
||||
print.GetEcgViewDataImage(image, "", patientInfo, patientInfo.type, ecgDataJsonStr);
|
||||
if (patientInfo.type == 1)
|
||||
{
|
||||
data = print.imagebase;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = print.filename;
|
||||
}
|
||||
Log("请求处理完成:" + patientInfo.regid);
|
||||
catch (Exception ex) { data = "生成数据文件异常"; }
|
||||
}
|
||||
else
|
||||
{
|
||||
data = "心电数据为空";
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
data = "解析数据不正确";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data = "非指定请求方法";
|
||||
data = "非指定请求方法";
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -127,7 +193,7 @@ namespace _1200Gxml心电图绘制
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Info("OnPost Error:", e.Message);
|
||||
//LogHelper.Info("OnPost Error:", e.Message);
|
||||
}
|
||||
//设置返回信息
|
||||
string content = data; //string.Format("<vtma><result>0000</result><desc>Successful!</desc><data><outputXml>{0}</outputXml></data></vtma>", data);
|
||||
@ -146,7 +212,7 @@ namespace _1200Gxml心电图绘制
|
||||
public override void OnGet(HttpRequest request, HttpResponse response)
|
||||
{
|
||||
|
||||
LogHelper.Info("请求到接口", "");
|
||||
//LogHelper.Info("请求到接口", "");
|
||||
|
||||
//当文件不存在时应返回404状态码
|
||||
string requestURL = request.URL;
|
||||
|
@ -62,11 +62,13 @@ namespace 心电图绘制
|
||||
/// <summary>
|
||||
/// 图片转换成PDF
|
||||
/// </summary>
|
||||
/// Margins默认值36
|
||||
/// <param name="bitmap"></param>
|
||||
/// <param name="pdfPath"></param>
|
||||
public static void ConvertBitmapToPdf(Bitmap bitmap, string pdfPath)
|
||||
public static void ConvertBitmapToPdf(Bitmap bitmap, string pdfPath,
|
||||
float? width = null, float? height = null,
|
||||
float? marginLeft = null, float? marginRight = null, float? marginTop = null, float? marginBottom = null)
|
||||
{
|
||||
|
||||
string directoryPath = Path.GetDirectoryName(pdfPath);
|
||||
if (directoryPath != null && !Directory.Exists(directoryPath))
|
||||
{
|
||||
@ -74,6 +76,8 @@ namespace 心电图绘制
|
||||
}
|
||||
// 创建一个文档对象
|
||||
Document document = new Document();
|
||||
if (marginLeft != null && marginRight != null && marginTop != null && marginBottom != null)
|
||||
document.SetMargins(marginLeft.Value, marginRight.Value, marginTop.Value, marginBottom.Value);
|
||||
|
||||
// 创建一个PdfWriter实例
|
||||
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfPath, FileMode.Create));
|
||||
@ -81,7 +85,8 @@ namespace 心电图绘制
|
||||
// 打开文档以便添加内容
|
||||
document.Open();
|
||||
// 设置页面尺寸与图像尺寸一致
|
||||
iTextSharp.text.Rectangle pageSize = new iTextSharp.text.Rectangle(bitmap.Width, bitmap.Height + 50);
|
||||
iTextSharp.text.Rectangle pageSize = new iTextSharp.text.Rectangle(width != null ? width.Value : bitmap.Width,
|
||||
height != null ? height.Value : (bitmap.Height + 50));
|
||||
document.SetPageSize(pageSize);
|
||||
// 将Bitmap转换为iTextSharp的Image对象
|
||||
iTextSharp.text.Image image = ConvertBitmapToImageSharp(bitmap);
|
||||
|
@ -1,13 +1,17 @@
|
||||
using _1200Gxml心电图绘制;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using 心电图绘制;
|
||||
@ -75,6 +79,101 @@ namespace 心电图绘制
|
||||
return quotients;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得心电诊断快照数据
|
||||
/// </summary>
|
||||
public void GetEcgViewDataImage_img(JObject paramsObj)
|
||||
{
|
||||
try
|
||||
{
|
||||
Bitmap bmp = null;
|
||||
Graphics gfx = null;
|
||||
using (HttpClient client_web = new HttpClient(new HttpClientHandler
|
||||
{
|
||||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
|
||||
}))
|
||||
{
|
||||
byte[] imageData = client_web.GetByteArrayAsync(paramsObj["filepath"].ToString().Trim()).Result;
|
||||
using (MemoryStream stream = new MemoryStream(imageData, false))
|
||||
{
|
||||
using (bmp = new Bitmap(stream))
|
||||
{
|
||||
bmp.SetResolution(_printDpi, _printDpi);
|
||||
using (gfx = Graphics.FromImage(bmp))
|
||||
{
|
||||
gfx.SmoothingMode = SmoothingMode.AntiAlias;//抗锯齿
|
||||
|
||||
Font font = new Font(@"微软雅黑", float.Parse(@"9.8"));
|
||||
Brush brush = Brushes.Black;
|
||||
PointF? point = null;
|
||||
|
||||
//image
|
||||
Image image = null;
|
||||
if (paramsObj["image"] != null && !string.IsNullOrWhiteSpace(paramsObj["image"].ToString().Trim()))
|
||||
{
|
||||
try { image = UniversalFun.ConvertFromBase64String(paramsObj["image"].ToString().Trim()); }
|
||||
catch (Exception ex) { image = null; }
|
||||
}
|
||||
if (true)
|
||||
try
|
||||
{
|
||||
if (image == null)
|
||||
{
|
||||
point = new PointF(float.Parse(ConfigurationManager.AppSettings["printecg_image__doctorName_point"].Split(',')[0].Trim()),
|
||||
float.Parse(ConfigurationManager.AppSettings["printecg_image__doctorName_point"].Split(',')[1].Trim()));
|
||||
gfx.DrawString(paramsObj["doctorName"] == null ? "" : paramsObj["doctorName"].ToString().Trim(), font, brush, point.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
point = new PointF(float.Parse(ConfigurationManager.AppSettings["printecg_image__doctorNameImg_point"].Split(',')[0].Trim()),
|
||||
float.Parse(ConfigurationManager.AppSettings["printecg_image__doctorNameImg_point"].Split(',')[1].Trim()));
|
||||
using (Bitmap bmpSource = new Bitmap(image, 160, 80))
|
||||
{
|
||||
bmpSource.SetResolution(_printDpi, _printDpi);
|
||||
gfx.DrawImage(bmpSource, point.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
|
||||
//diagContent
|
||||
string diagContent = paramsObj["diagContent"] == null ? "" : paramsObj["diagContent"].ToString().Trim();
|
||||
string[] diagArray = diagContent.Split(Environment.NewLine.ToCharArray());
|
||||
diagContent = string.Empty;
|
||||
for (int i = 0; i < diagArray.Length; i++) diagContent += diagArray[i].Trim();
|
||||
int wrap = 0;
|
||||
if (!int.TryParse(ConfigurationManager.AppSettings["printecg_image__diagContent_wrap"], out wrap))
|
||||
wrap = 0;
|
||||
diagContent = stringWrap(diagContent, wrap);
|
||||
point = new PointF(float.Parse(ConfigurationManager.AppSettings["printecg_image__diagContent_point"].Split(',')[0].Trim()),
|
||||
float.Parse(ConfigurationManager.AppSettings["printecg_image__diagContent_point"].Split(',')[1].Trim()));
|
||||
gfx.DrawString(diagContent, font, brush, point.Value);
|
||||
|
||||
switch (paramsObj["type"].ToString().Trim())
|
||||
{
|
||||
case "1"://返回base64
|
||||
imagebase = UniversalFun.ConvertToBase64String(bmp, ImageFormat.Jpeg);
|
||||
break;
|
||||
case "2"://生成pdf
|
||||
string path = string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["path"]) ? Application.StartupPath : ConfigurationManager.AppSettings["path"].Trim();
|
||||
UniversalFun.ConvertBitmapToPdf(bmp, path + @"\" + paramsObj["examid"].ToString().Trim() + @"\" + paramsObj["examid"].ToString().Trim() + ".pdf",
|
||||
bmp.Width + 4, bmp.Height + 4, 2, 0, 2, 0);
|
||||
filename = @"/" + paramsObj["examid"].ToString().Trim() + @"/" + paramsObj["examid"].ToString().Trim() + ".pdf";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得心电诊断快照数据
|
||||
/// </summary>
|
||||
@ -350,7 +449,6 @@ namespace 心电图绘制
|
||||
return submitInfoToFLY6(FER);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 提交诊断结论到福乐云
|
||||
/// </summary>
|
||||
@ -362,5 +460,18 @@ namespace 心电图绘制
|
||||
string resultStr = commonOptions.PostByParas(ConfigurationManager.AppSettings["flowygtReportAddUrl"], token, jsonContent);
|
||||
return resultStr;
|
||||
}
|
||||
|
||||
public string stringWrap(string input, int maxCharactersPerLine)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input)) input = "";
|
||||
input = input.Trim().Trim(Environment.NewLine.ToCharArray()).Trim();
|
||||
if (maxCharactersPerLine >= 1)
|
||||
{
|
||||
string pattern = $".{{1,{maxCharactersPerLine}}}";
|
||||
return Regex.Replace(input, pattern, m => $"{m.Value + Environment.NewLine}").Trim(Environment.NewLine.ToCharArray()).TrimEnd();
|
||||
}
|
||||
else
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user