ECGPrint/1200Gxml心电图绘制/服务/print.cs

330 lines
13 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using _1200Gxml心电图绘制;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ;
namespace
{
internal class print
{
/// <summary>
/// 报告样式类型
/// </summary>
public int reportMode = 0;
/// <summary>
/// 报告样式类型名称
/// </summary>
public string strreportMode = string.Empty;
/// <summary>
/// 走速
/// </summary>
public int cBoxSpeed = 0;
/// <summary>
/// 振幅
/// </summary>
public int cBoxAmplitude = 0;
/// <summary>
/// PDF文件名称
/// </summary>
public string filename = string.Empty;
/// <summary>
/// 生成报告base64
/// </summary>
public string imagebase = string.Empty;
private string _printFilter = "0Hz";
private Bitmap _ecgBitMap;
private static int _printDpi = 300;//打印DPI
private const int Dpi = 96; //屏幕DIP
private readonly string _isQiBo;//是否是起搏信号
private int _leadindexdata;
private const string LeaderName15 = "5x3+1导报告模式";
private const string LeaderName18 = "18导报告模式";
private string _reportTitleContent = string.Empty;
private string _idStr;
private string collectTime;//心电数据采集时间
private const double Coefficient = 1.02; //放大缩小的系数
private List<int> _longLeadInfo = new List<int>(); //存储任意长两导联的导联下标
private readonly List<int> _longLeadInfo3 = new List<int>(); //存储任意长三导联的导联下标
public string LeaderType; //导联类别
private Dictionary<int, List<float>> _ecgDataDicAfterFilter = new Dictionary<int, List<float>>(); //滤波后的数据都存在这个字典中
private int _filterIndex; //滤波时 此标志 指示从数组中 哪一个位置开始滤波
private double _paperSpeed = 25.0; //走速
private string _ps = "25mm/s"; //打印时的走速
private double _amplitude = 10.0; //振幅
private string _amp = "10mm/mV"; //打印时的振幅
private double _calibrationVoltage = 2.0;//定标电压
float[] valueConvert(float[] valueArray)
{
float[] quotients = valueArray.Select(n => n / 500).ToArray();
return quotients;
}
/// <summary>
/// 获得心电诊断快照数据
/// </summary>
public void GetEcgViewDataImage(Image img, string addr, PatientInfo info, int type, string json)
{
_ecgDataDicAfterFilter.Clear();
// string ecgDataJsonStr = File.ReadAllText(Application.StartupPath + @"\60心拍心电图数据JSON.txt");
string ecgDataJsonStr = json;
leadDataModel LDM = JsonConvert.DeserializeObject<leadDataModel>(ecgDataJsonStr);
float[] LEAD_I = valueConvert(Array.ConvertAll(LDM.LEAD_I, float.Parse));
_ecgDataDicAfterFilter.Add(0, LEAD_I.ToList());
float[] LEAD_II = valueConvert(Array.ConvertAll(LDM.LEAD_II, float.Parse));
_ecgDataDicAfterFilter.Add(1, LEAD_II.ToList());
float[] LEAD_III = valueConvert(Array.ConvertAll(LDM.LEAD_III, float.Parse));
_ecgDataDicAfterFilter.Add(2, LEAD_III.ToList());
float[] LEAD_AVR = valueConvert(Array.ConvertAll(LDM.LEAD_AVR, float.Parse));
_ecgDataDicAfterFilter.Add(3, LEAD_AVR.ToList());
float[] LEAD_AVL = valueConvert(Array.ConvertAll(LDM.LEAD_AVL, float.Parse));
_ecgDataDicAfterFilter.Add(4, LEAD_AVL.ToList());
float[] LEAD_AVF = valueConvert(Array.ConvertAll(LDM.LEAD_AVF, float.Parse));
_ecgDataDicAfterFilter.Add(5, LEAD_AVF.ToList());
float[] LEAD_V1 = valueConvert(Array.ConvertAll(LDM.LEAD_V1, float.Parse));
_ecgDataDicAfterFilter.Add(6, LEAD_V1.ToList());
float[] LEAD_V2 = valueConvert(Array.ConvertAll(LDM.LEAD_V2, float.Parse));
_ecgDataDicAfterFilter.Add(7, LEAD_V2.ToList());
float[] LEAD_V3 = valueConvert(Array.ConvertAll(LDM.LEAD_V3, float.Parse));
_ecgDataDicAfterFilter.Add(8, LEAD_V3.ToList());
float[] LEAD_V4 = valueConvert(Array.ConvertAll(LDM.LEAD_V4, float.Parse));
_ecgDataDicAfterFilter.Add(9, LEAD_V4.ToList());
float[] LEAD_V5 = valueConvert(Array.ConvertAll(LDM.LEAD_V5, float.Parse));
_ecgDataDicAfterFilter.Add(10, LEAD_V5.ToList());
float[] LEAD_V6 = valueConvert(Array.ConvertAll(LDM.LEAD_V6, float.Parse));
_ecgDataDicAfterFilter.Add(11, LEAD_V6.ToList());
if (!string.IsNullOrEmpty(info.orgname))
{
_reportTitleContent = info.orgname;
}
else
{
_reportTitleContent = "心电图报告";
}
_idStr = info.examid;//编号
collectTime = info.doctorDiagTime;//报告日期
//长两导的模式下 默认添加 第一导 和 第二导联 为 长显示两导联
_longLeadInfo.Add(0);
_longLeadInfo.Add(1);
//长三导的模式下 默认添加 第一导 和 第二导联和第三导联 为 长显示三导联
_longLeadInfo3.Add(0);
_longLeadInfo3.Add(1);
_longLeadInfo3.Add(2);
var cpew = new CommonPrintEcgWave();
var filter = _printFilter;
_ecgBitMap = new Bitmap(1090 * _printDpi / Dpi, 760 * _printDpi / Dpi);
_ecgBitMap.SetResolution(_printDpi, _printDpi);
cpew.InitEcgParameter(_ecgBitMap, _ecgDataDicAfterFilter, _isQiBo, _paperSpeed, _amplitude);
//************************************************************************
var ecgInfoList = new string[14];
ecgInfoList[0] = "姓名:" + info.name;//姓名
ecgInfoList[1] = "性别:" + info.gender;
ecgInfoList[2] = "年龄:" + info.age;
ecgInfoList[3] = "RV5+SV1" + info.rv5sv1plus + " mV";
ecgInfoList[4] = "PR间期" + info.pr + " ms";
ecgInfoList[5] = "P/T/QRS°" + info.pt + "°";
ecgInfoList[6] = "QT/QTC" + info.qtqtc + " ms";
ecgInfoList[7] = "QRS时限" + info.qrs + " ms";
ecgInfoList[8] = "RV5/SV1" + info.rv5sv1 + " mV";
ecgInfoList[9] = "HR" + info.hr + " bpm";
ecgInfoList[10] = "病室:" + info.ward;
ecgInfoList[11] = "床号";
ecgInfoList[12] = "住院号:" + info.regid;
ecgInfoList[13] = "P波时限" + info.ptimelimit + " ms";
SetAandP(); //设置增益和走速
var diagContent = info.diagContent;
var diagArray = diagContent.Split('\n');
diagContent = string.Empty;
for (var i = 0; i < diagArray.Length; i++) diagContent += diagArray[i].Trim();
if (_ecgDataDicAfterFilter.Count > 0)
_filterIndex = 0;
else
_filterIndex = 0;
// _leadindexdata = hScrollBar_Lead.Value * _filterIndex;
_leadindexdata = _filterIndex;
if (strreportMode == LeaderName15) filter += " 十五加一长导模式";
if (strreportMode == LeaderName18) filter += " 十八导模式";
if (reportMode == 2)
{
cpew.PrintBackGroundGrid(16, 196);
cpew.PrintLongReportHeadInfo(_reportTitleContent);
cpew.PrintLongEcgInfo(ecgInfoList, _idStr);
cpew.PrintLongDiagInfo(diagContent, info.doctorName,
collectTime, filter,
collectTime, "科室:" + info.DepartName, _amp, _ps, img, addr);
}
else
{
cpew.PrintBackGroundGrid(40, 196); //(197-42)*12=1860像素
cpew.PrintReportHeadInfo(_reportTitleContent, collectTime);
cpew.PrintEcgInfo(ecgInfoList, _idStr);
cpew.PrintDiagInfo(diagContent, info.doctorName, filter,
collectTime, "科室:" + info.DepartName, _amp, _ps, img, addr);
}
//6x2
if (reportMode == 0)
{
cpew.PrintEcgWave(8, 1, _leadindexdata);
cpew.PrintEcgLeadName(_calibrationVoltage * Coefficient);
}
//6x2+2
if (reportMode == 1)
{
cpew.PrintEcgWave(8, 1, _longLeadInfo, _leadindexdata, _leadindexdata);
cpew.PrintEcgLeadName(_calibrationVoltage * Coefficient, _longLeadInfo);
}
//十二长导
if (reportMode == 2)
{
cpew.PrintLongEcgWave(5, 1, _leadindexdata);
//cpew.PrintLongEcgWave(8, 1, _leadindexdata);
cpew.PrintLongEcgLeadName(_calibrationVoltage * Coefficient);
}
//4*3 II长导模式
if (reportMode == 3)
{
cpew.PrintEcgWaveFourOne(8, 1, _leadindexdata, _leadindexdata);
cpew.PrintLeadNameFourOne(_calibrationVoltage * Coefficient, _longLeadInfo);
}
//4*3+3 长导模式
if (reportMode == 4)
{
cpew.PrintEcgWaveFourThree(8, 1, _longLeadInfo3, _leadindexdata, _leadindexdata);
cpew.PrintLeadNameFourThree(_calibrationVoltage * Coefficient, _longLeadInfo3);
}
//15x1+1导
if (strreportMode == LeaderName15)
{
cpew.PrintEcgWaveFifteen(8, 1, _leadindexdata);
cpew.PrintLeadNameFifteen(_calibrationVoltage * Coefficient, LeaderType);
}
//十八导
if (strreportMode == LeaderName18)
{
cpew.PrintEcgWaveEighteen(8, 1, _leadindexdata);
cpew.PrintLeadNameEighteen(_calibrationVoltage * Coefficient);
}
switch (type)
{
case 1://返回base64
imagebase = UniversalFun.ConvertToBase64String(_ecgBitMap, ImageFormat.Jpeg);
break;
case 2://生成pdf
string path = string.IsNullOrEmpty(ConfigurationManager.AppSettings["path"]) ? Application.StartupPath : ConfigurationManager.AppSettings["path"];
UniversalFun.ConvertBitmapToPdf(_ecgBitMap, path + @"\" + info.examid + @"\" + info.examid + ".pdf");
filename = @"/" + info.examid + @"/" + info.examid + ".pdf";
// _ecgBitMap.Save("心电图报告.jpg", ImageFormat.Jpeg);
break;
default:
break;
}
//_sourceCegBmp = _ecgBitMap;
}
/// <summary>
/// 设置增益和走速和定标电压
/// </summary>
private void SetAandP()
{
if (cBoxSpeed == 0) //走速
{
_paperSpeed = 5;
_ps = "5mm/s";
}
if (cBoxSpeed == 1)
{
_paperSpeed = 10;
_ps = "10mm/s";
}
if (cBoxSpeed == 2) //走速
{
_paperSpeed = 12.5;
_ps = "12.5mm/s";
}
if (cBoxSpeed == 3)
{
_paperSpeed = 25.0;
_ps = "25mm/s";
}
if (cBoxSpeed == 4)
{
_paperSpeed = 50.0;
_ps = "50mm/s";
}
if (cBoxAmplitude == 0) //振幅
{
_amplitude = 2.5;
_amp = "2.5mm/mV";
_calibrationVoltage = 0.5;
}
if (cBoxAmplitude == 1)
{
_amplitude = 5.0;
_amp = "5mm/mV";
_calibrationVoltage = 1.0;
}
if (cBoxAmplitude == 2)
{
_amplitude = 10.0;
_amp = "10mm/mV";
_calibrationVoltage = 2.0;
}
if (cBoxAmplitude == 3)
{
_amplitude = 20.0;
_amp = "20mm/mV";
_calibrationVoltage = 4.0;
}
if (cBoxAmplitude == 4)
{
_amplitude = 40.0;
_amp = "40mm/mV";
_calibrationVoltage = 8.0;
}
}
}
}