📄 pdfformat.cs
字号:
float
fStartY = 15.0f,
fIncrement = 20.0f;
if (sigs.NrLeads > 12)
{
float fMaxHeight = (_PaperType == SupportedPaper.LETTER ? 240.0f : 255.0f) - 20.0f;
fStartY = 15.0f;
fIncrement = (fMaxHeight / (sigs.NrLeads-1));
}
while ((start < end)
&& (start != prev))
{
if (gridRect.Bottom > (height - 5.0f))
{
if (bFirst)
bFirst = false;
else
{
document.NewPage();
cb = writer.DirectContent;
cb.Transform(new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, writer.PageSize.Height));
cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, false), 8.0f);
}
cb.SetLineWidth(0.5f);
cb.SetRGBColorStroke(0, 0, 0);
gridRect = (_PaperType == SupportedPaper.LETTER) ? PDFTool.CreateRectangle(width, height, 205.0f, (20.0f * sigs.NrLeads), 240.0f) : PDFTool.CreateRectangle(width, height, 180.0f, (20.0f * sigs.NrLeads) + 5.0f, 255.0f);
DrawPageHeader(cb, new RectangleF(gridRect.X, 5.0f, gridRect.Width, gridRect.Y - 5.0f), 3.5f);
}
cb.SetLineWidth(0.25f);
cb.SetRGBColorStroke(0xf9, 0xcb, 0xcb);
PDFTool.DrawGrid(cb, 1.0f, gridRect);
cb.SetLineWidth(0.5f);
cb.SetRGBColorStroke(0xf9, 0xba, 0xba);
PDFTool.DrawGrid(cb, 5.0f, gridRect);
PointF point = new PointF(gridRect.X, gridRect.Y + fStartY);
cb.SetLineWidth(0.5f);
cb.SetRGBColorStroke(0, 0, 0);
PDFTool.DrawGridHeader(cb, gridRect, dtStart.AddMilliseconds((start * 1000.0) / sigs.RhythmSamplesPerSecond), 25.0f, _Gain);
int temp = 0;
for (int i=0;i < sigs.NrLeads;i++)
{
temp = Math.Max(temp, PDFTool.DrawSignal(cb, point, gridRect.Width, 25.0f, _Gain, sigs, i, start, 5.0f, false));
point.Y += fIncrement;
}
prev = start;
start = temp;
gridRect.Y += gridRect.Height + 5.0f;
}
}
return 0;
}
catch(DocumentException de)
{
Console.Error.WriteLine(de.ToString());
}
catch(IOException ioe)
{
Console.Error.WriteLine(ioe.ToString());
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.ToString());
}
finally
{
document.Close();
}
}
}
return 0x1;
}
public override int Write(byte[] buffer, int offset)
{
System.IO.MemoryStream ms = null;
try
{
ms = new MemoryStream(buffer, offset, buffer.Length-offset, true);
return Write(ms);
}
catch {}
finally
{
if (ms != null)
{
ms.Close();
ms = null;
}
}
return 0x1;
}
public override bool CheckFormat(Stream input, int offset)
{
return false;
}
public override bool CheckFormat(string file, int offset)
{
return false;
}
public override bool CheckFormat(byte[] buffer, int offset)
{
return false;
}
public override void Anonymous(byte type)
{
ECGTool.Anonymous(_Demographics, (char) type);
}
public override int getFileSize()
{
return -1;
}
private void DrawPageHeader(PdfContentByte cb, RectangleF headerRect, float fLineHeight)
{
StringBuilder sb = new StringBuilder();
PointF point = new PointF(headerRect.X + 1.25f, headerRect.Y);
float fTempY = point.Y;
sb.Append("Name: ").Append(_Demographics.LastName);
sb.Append("\nPatient ID: ").Append(_Demographics.PatientID);
GlobalMeasurements gms = _GlobalMeasurements;
if ((gms != null)
&& (gms.measurment != null)
&& (gms.measurment.Length > 0)
&& (gms.measurment[0] != null))
{
int ventRate = (gms.VentRate == GlobalMeasurement.NoValue) ? 0 : (int) gms.VentRate,
PRint = (gms.PRint == GlobalMeasurement.NoValue) ? 0 : (int) gms.measurment[0].PRint,
QRSdur = (gms.QRSdur == GlobalMeasurement.NoValue) ? 0 : (int) gms.measurment[0].QRSdur,
QT = (gms.QTdur == GlobalMeasurement.NoValue) ? 0 : (int) gms.measurment[0].QTdur,
QTc = (gms.QTc == GlobalMeasurement.NoValue) ? 0 : (int) gms.QTc;
sb.Append("\n\nVent rate: ");
PrintValue(sb, ventRate, 3);
sb.Append(" BPM");
sb.Append("\nPR int: ");
PrintValue(sb, PRint, 3);
sb.Append(" ms");
sb.Append("\nQRS dur: ");
PrintValue(sb, QRSdur, 3);
sb.Append(" ms");
sb.Append("\nQT\\QTc: ");
PrintValue(sb, QT, 3);
sb.Append('/');
PrintValue(sb, QTc, 3);
sb.Append(" ms");
sb.Append("\nP-R-T axes: ");
sb.Append((gms.measurment[0].Paxis != GlobalMeasurement.NoAxisValue) ? gms.measurment[0].Paxis.ToString() : "999");
sb.Append(' ');
sb.Append((gms.measurment[0].QRSaxis != GlobalMeasurement.NoAxisValue) ? gms.measurment[0].QRSaxis.ToString() : "999");
sb.Append(' ');
sb.Append((gms.measurment[0].Taxis != GlobalMeasurement.NoAxisValue) ? gms.measurment[0].Taxis.ToString() : "999");
}
DrawText(cb, point, sb, fLineHeight, 50.0f);
point.X += 52.5f;
DateTime dt = _Demographics.TimeAcquisition;
DrawText(cb, point, new string[] {(dt.Year > 1000) ? dt.ToString("dd/MM/yyyy HH:mm:ss") : "Time Unknown"}, fLineHeight, 35.0f);
point.X += 2.5f;
point.Y += 2 * fLineHeight;
sb = new StringBuilder();
sb.Append("DOB: ");
ECGConversion.ECGDemographics.Date birthDate = _Demographics.PatientBirthDate;
if (birthDate != null)
{
sb.Append(birthDate.Day.ToString("00"));
sb.Append(birthDate.Month.ToString("00"));
sb.Append(birthDate.Year.ToString("0000"));
}
sb.Append("\nAge: ");
ushort ageVal;
ECGConversion.ECGDemographics.AgeDefinition ad;
if (_Demographics.getPatientAge(out ageVal, out ad) == 0)
{
sb.Append(ageVal);
if (ad != ECGConversion.ECGDemographics.AgeDefinition.Years)
{
sb.Append(" ");
sb.Append(ad.ToString());
}
}
else
sb.Append("0");
sb.Append("\nGen: ");
if (_Demographics.Gender != ECGConversion.ECGDemographics.Sex.Null)
sb.Append(_Demographics.Gender.ToString());
sb.Append("\nDep: ");
sb.Append(_Demographics.AcqDepartment);
DrawText(cb, point, sb, fLineHeight, 32.0f);
point.X += 35.0f;
point.Y = fTempY;
if ((_Diagnostic != null)
&& (_Diagnostic.statement != null))
{
sb = new StringBuilder();
foreach (string temp in _Diagnostic.statement)
{
sb.Append(temp);
sb.Append('\n');
}
string temp2 = _Diagnostic.statement[_Diagnostic.statement.Length-1];
if ((temp2 != null)
&& !temp2.StartsWith("Confirmed by")
&& !temp2.StartsWith("Interpreted by")
&& !temp2.StartsWith("Reviewed by"))
{
if ((_Demographics.OverreadingPhysician != null)
&& (_Demographics.OverreadingPhysician.Length != 0))
{
if (_Diagnostic.confirmed)
sb.Append("Confirmed by ");
else if (_Diagnostic.interpreted)
sb.Append("Interpreted by ");
else
sb.Append("Reviewed by ");
sb.Append(_Demographics.OverreadingPhysician);
}
else
sb.Append("UNCONFIRMED AUTOMATED INTERPRETATION");
}
DrawText(cb, point, sb, fLineHeight, headerRect.Right - point.X);
}
}
private static void PrintValue(StringBuilder sb, int val, int len)
{
int temp = sb.Length;
sb.Append(val.ToString());
if ((sb.Length - temp) < len)
sb.Append(' ', len - (sb.Length - temp));
}
public static void DrawText(PdfContentByte cb, PointF point, StringBuilder sb, float fLineHeight, float fMaxWidth)
{
if ((cb != null)
&& (sb != null)
&& (sb.Length > 0))
DrawText(cb, point, sb.ToString().Split('\n'), fLineHeight, fMaxWidth);
}
public static void DrawText(PdfContentByte cb, PointF point, string[] strs, float fLineHeight, float fMaxWidth)
{
fMaxWidth = (fMaxWidth * PDFTool.PdfDocumentDpi) / PDFTool.mm_Per_Inch;
if ((strs != null)
&& (strs.Length != 0))
{
cb.BeginText();
ArrayList allLines = null;
if ((cb.GetEffectiveStringWidth("i", false) == cb.GetEffectiveStringWidth("w", false))
&& (fMaxWidth > 0.1f))
{
float c = cb.GetEffectiveStringWidth("i", false);
allLines = new ArrayList();
foreach (string line in strs)
{
if ((line != null)
&& (line.Length != 0)
&& ((c * line.Length) > fMaxWidth))
{
int maxLineSize = (int) Math.Floor(fMaxWidth / c);
StringBuilder sb = new StringBuilder(line);
while (sb.Length > 0)
{
if (maxLineSize >= sb.Length)
{
allLines.Add(sb.ToString());
sb.Remove(0, sb.Length);
}
else
{
int i=maxLineSize-1;
for (;i > 0;i--)
if (line[i] == ' ')
{
break;
}
if (i > 0)
{
allLines.Add(sb.ToString(0, i));
sb.Remove(0, i+1);
}
else
{
allLines.Add(sb.ToString(0, maxLineSize));
sb.Remove(0, maxLineSize);
}
}
}
}
else
{
allLines.Add(line);
}
}
}
else
{
allLines = new ArrayList(strs);
}
foreach (string line in allLines)
{
point.Y += fLineHeight;
if ((line == null)
|| (line.Length == 0))
continue;
cb.ShowTextAligned(
PdfContentByte.ALIGN_LEFT,
line,
(point.X * PDFTool.PdfDocumentDpi) / PDFTool.mm_Per_Inch,
(-point.Y * PDFTool.PdfDocumentDpi) / PDFTool.mm_Per_Inch,
0);
}
cb.EndText();
}
}
public override ECGConversion.ECGDemographics.IDemographic Demographics
{
get
{
return _Demographics;
}
}
public override IDiagnostic Diagnostics
{
get
{
return this;
}
}
public override IGlobalMeasurement GlobalMeasurements
{
get
{
return this;
}
}
public override ISignal Signals
{
get
{
return this;
}
}
public override bool Works()
{
return _Demographics.Works()
&& (_Signals != null);
}
public override void Empty()
{
_Demographics = new PDFDemographics();
_Signals = null;
_GlobalMeasurements = null;
_Diagnostic = null;
}
#endregion
#region ISignal Members
public int getSignalsToObj(Signals signals)
{
return 1;
}
public int getSignals(out Signals signals)
{
signals = null;
return 1;
}
public int setSignals(Signals signals)
{
if (signals != null)
{
_Signals = signals;
return 0;
}
return 1;
}
#endregion
#region IGlobalMeasurement Members
public int getGlobalMeasurements(out GlobalMeasurements mes)
{
mes = null;
return 1;
}
public int setGlobalMeasurements(GlobalMeasurements mes)
{
if (mes != null)
{
_GlobalMeasurements = mes;
return 0;
}
return 1;
}
#endregion
#region IDiagnostic Members
public int getDiagnosticStatements(out Statements stat)
{
stat = null;
return 1;
}
public int setDiagnosticStatements(Statements stat)
{
if (stat != null)
{
_Diagnostic = stat;
return 0;
}
return 1;
}
#endregion
#region IDisposable Members
public override void Dispose()
{
base.Dispose();
_Demographics = null;
_Signals = null;
_GlobalMeasurements = null;
_Diagnostic = null;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -