rawecgheader.cs
来自「ecg tool kit for medical image retrieval」· CS 代码 · 共 1,264 行 · 第 1/3 页
CS
1,264 行
Height = (short) 0;
Weight = (short) 0;
SysBP = (short) 0;
DiaBP = (short) 0;
return 0;
}
/// <summary>
/// Function to write id record into a buffer.
/// </summary>
/// <param name="buffer">buffer to write in</param>
/// <param name="offset">position to start writing</param>
/// <param name="littleEndian">true if little endian is used</param>
/// <returns>0 on success</returns>
public int Write(byte[] buffer, int offset, bool littleEndian)
{
// empty, shoudl nog be called
throw new SystemException();
}
/// <summary>
/// Function to empty header.
/// </summary>
public void Empty()
{
AgeYears = 0;
AgeMonths = 0;
AgeDays = 0;
Drugs = new short[MaxNrDrugs];
ClinClass = new short[MaxNrClinClass];
Height = 0;
Weight = 0;
SysBP = 0;
DiaBP = 0;
}
}
/// <summary>
/// Class containing ecg info.
/// </summary>
public class RawECGInfo
{
// static variables for definition of structure.
public static int Size = 42;
public static int Padding = 6;
public static int MaxNrLeads = 12;
// structure of data.
public short ECGSampFreq;
public short ECGLSBPerMV;
public short ElecSetting;
public short AMType;
public short TremorType;
public short NrOfLeads;
public short[] LeadConfig = new short[MaxNrLeads];
public short ECGType = 1;
public uint NrECGSamples;
/// <summary>
/// Function to read ecg info from buffer.
/// </summary>
/// <param name="buffer">buffer to read from</param>
/// <param name="offset">position to start reading</param>
/// <param name="littleEndian">true if little endian is used</param>
/// <returns>0 on success</returns>
public int Read(byte[] buffer, int offset, bool littleEndian)
{
if (ECGSampFreq == 0)
{
ECGSampFreq = 500;
}
ElecSetting = 0;
AMType = 0;
TremorType = 0;
for (int loper=0;loper < MaxNrLeads;loper++)
{
LeadConfig[loper] = loper < NrOfLeads? (short)loper : (short)-1;
}
ECGType = 1;
return 0;
}
/// <summary>
/// Function to write ecg info into a buffer.
/// </summary>
/// <param name="buffer">buffer to write in</param>
/// <param name="offset">position to start writing</param>
/// <param name="littleEndian">true if little endian is used</param>
/// <returns>0 on success</returns>
public int Write(byte[] buffer, int offset, bool littleEndian)
{
// empty, should nog be called
throw new SystemException();
}
/// <summary>
/// Function to empty header.
/// </summary>
public void Empty()
{
ECGSampFreq = 0;
ECGLSBPerMV = 0;
ElecSetting = 0;
AMType = 0;
TremorType = 0;
NrOfLeads = 0;
LeadConfig = new short[MaxNrLeads];
for (int loper=0;loper < MaxNrLeads;loper++)
{
LeadConfig[loper] = -1;
}
ECGType = 1;
NrECGSamples = 0;
}
}
/// <summary>
/// Class containing record info.
/// </summary>
public class RawECGRecordInfo
{
// static variables for definition of structure.
public static int Size = 92;
public static int Padding = 28;
public static int MaxECGIdLen = 19;
public static int MaxRecDateLen = 9;
public static int MaxRecTimeLen = 7;
public static int MaxCartIdLen = 6;
public static int MaxLocationLen = 11;
public static int MaxSiteLen = 11;
public static int MaxProgramVersionLen = 26;
// structure of data.
public short CartType = -1;
public byte[] ECGId = new byte[MaxECGIdLen];
public byte[] RecDate = new byte[MaxRecDateLen];
public byte[] RecTime = new byte[MaxRecTimeLen];
public byte[] CartId = new byte[MaxCartIdLen];
public byte[] Location = new byte[MaxLocationLen];
public byte[] Site = new byte[MaxSiteLen];
public byte[] ProgramVersion = new byte[MaxProgramVersionLen];
public byte ByteOrder = (byte) 'M';
/// <summary>
/// Function to read record id from buffer.
/// </summary>
/// <param name="buffer">buffer to read from</param>
/// <param name="offset">position to start reading</param>
/// <param name="littleEndian">true if little endian is used</param>
/// <returns>0 on success</returns>
public int Read(byte[] buffer, int offset, bool littleEndian)
{
CartType = (short) -1;
ECGId[0] = 0;
Date myDate = new Date(1901,1,1);
BytesTool.writeString(myDate.Year.ToString("d4"), RecDate, 0, 5);
BytesTool.writeString(myDate.Month.ToString("d2"),RecDate, 4, 3);
BytesTool.writeString(myDate.Day.ToString("d2"), RecDate, 6, 3);
BytesTool.writeString("01", RecTime, 0, 3);
BytesTool.writeString("01", RecTime, 2, 3);
BytesTool.writeString("01", RecTime, 4, 3);
AcquiringDeviceID id = new AcquiringDeviceID();
BytesTool.writeString(id.DeviceID.ToString("d5"), CartId, 0, RawECGRecordInfo.MaxCartIdLen);
BytesTool.writeString("ErasmusMC", Location, 0, RawECGRecordInfo.MaxLocationLen);
BytesTool.writeString(((DeviceManufactor)id.ManufactorID).ToString(), Site, 0, RawECGRecordInfo.MaxSiteLen);
BytesTool.writeString("ECGConversion 1.1", ProgramVersion, 0, RawECGRecordInfo.MaxProgramVersionLen);
ByteOrder = (byte) 'I';
return 0;
}
/// <summary>
/// Function to write record id into a buffer.
/// </summary>
/// <param name="buffer">buffer to write in</param>
/// <param name="offset">position to start writing</param>
/// <param name="littleEndian">true if little endian is used</param>
/// <returns>0 on success</returns>
public int Write(byte[] buffer, int offset, bool littleEndian)
{
// empty, shoudl nog be called
throw new SystemException();
}
/// <summary>
/// Function to empty header.
/// </summary>
public void Empty()
{
CartType = -1;
ECGId = new byte[MaxECGIdLen];
RecDate = new byte[MaxRecDateLen];
RecTime = new byte[MaxRecTimeLen];
CartId = new byte[MaxCartIdLen];
Location = new byte[MaxLocationLen];
Site = new byte[MaxSiteLen];
ProgramVersion = new byte[MaxProgramVersionLen];
ByteOrder = (byte) 'M';
}
}
/// <summary>
/// A class to store GRI setup.
/// </summary>
public class Analys2000GRISetup
{
// static variables for definition of structure.
public static int Size = 4;
public static int Padding = 188;
// structure of data.
public short BradyLimit = 60;
public short TachyLimit = 100;
/// <summary>
/// Function to read GRI Setup from buffer.
/// </summary>
/// <param name="buffer">buffer to read from</param>
/// <param name="offset">position to start reading</param>
/// <param name="littleEndian">true if little endian is used</param>
/// <returns>0 on success</returns>
public int Read(byte[] buffer, int offset, bool littleEndian)
{
BradyLimit = (short) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(BradyLimit), littleEndian);
offset += Marshal.SizeOf(BradyLimit);
TachyLimit = (short) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(TachyLimit), littleEndian);
offset += Marshal.SizeOf(TachyLimit);
return 0;
}
/// <summary>
/// Function to write GRI Setup into a buffer.
/// </summary>
/// <param name="buffer">buffer to write in</param>
/// <param name="offset">position to start writing</param>
/// <param name="littleEndian">true if little endian is used</param>
/// <returns>0 on success</returns>
public int Write(byte[] buffer, int offset, bool littleEndian)
{
BytesTool.writeBytes(BradyLimit, buffer, offset, Marshal.SizeOf(BradyLimit), littleEndian);
offset += Marshal.SizeOf(BradyLimit);
BytesTool.writeBytes(TachyLimit, buffer, offset, Marshal.SizeOf(TachyLimit), littleEndian);
offset += Marshal.SizeOf(TachyLimit);
return 0;
}
/// <summary>
/// Function to empty header.
/// </summary>
public void Empty()
{
BradyLimit = 60;
TachyLimit = 100;
}
}
public void Init()
{
Empty();
}
public string LastName
{
get
{
if (_PatId.LastName[0] != 0)
{
return BytesTool.readString(_PatId.LastName, 0, RawECGPatientId.MaxNameLen);
}
return null;
}
set
{
if (value != null)
{
BytesTool.writeString(value, _PatId.LastName, 0, RawECGPatientId.MaxNameLen);
}
}
}
public string FirstName
{
get
{
if (_PatId.FirstName[0] != 0)
{
return BytesTool.readString(_PatId.FirstName, 0, RawECGPatientId.MaxNameLen);
}
return null;
}
set
{
if (value != null)
{
BytesTool.writeString(value, _PatId.FirstName, 0, RawECGPatientId.MaxNameLen);
}
}
}
public string PatientID
{
get
{
if (_PatId.Id[0] != 0)
{
return BytesTool.readString(_PatId.Id, 0, RawECGPatientId.MaxIdLen);;
}
return null;
}
set
{
if (value != null)
{
BytesTool.writeString(value, _PatId.Id, 0, RawECGPatientId.MaxNameLen);
_PatId.IdFormat = 0;
}
}
}
public string SecondLastName
{
get {return null;}
set {}
}
public string PrefixName
{
get {return null;}
set {}
}
public string SuffixName
{
get {return null;}
set {}
}
public int getPatientAge(out ushort val, out AgeDefinition def)
{
val = 0;
def = AgeDefinition.Unspecified;
if (_IdRecInfo.AgeYears != 0)
{
val = (ushort) _IdRecInfo.AgeYears;
def = AgeDefinition.Years;
return 0;
}
else if (_IdRecInfo.AgeMonths != 0)
{
val = (ushort) _IdRecInfo.AgeMonths;
def = AgeDefinition.Months;
return 0;
}
else if (_IdRecInfo.AgeDays != 0)
{
val = (ushort) _IdRecInfo.AgeDays;
def = AgeDefinition.Days;
return 0;
}
return 1;
}
public int setPatientAge(ushort val, AgeDefinition def)
{
if ((val != 0)
&& (def != AgeDefinition.Unspecified))
{
switch (def)
{
case AgeDefinition.Years:
_IdRecInfo.AgeYears = (short) val;
break;
case AgeDefinition.Months:
_IdRecInfo.AgeMonths = (short) val;
break;
case AgeDefinition.Weeks:
_IdRecInfo.AgeDays = (short) (val * 7);
break;
case AgeDefinition.Days:
_IdRecInfo.AgeDays = (short) val;
break;
case AgeDefinition.Hours:
_IdRecInfo.AgeDays = (short) (val / 24);
break;
}
return 0;
}
return 1;
}
public Date PatientBirthDate
{
get
{
if (_PatId.BirthDate[0] != 0)
{
try
{
Date date = new Date();
string year = BytesTool.readString(_PatId.BirthDate, 0, 4);
string month = BytesTool.readString(_PatId.BirthDate, 4, 2);
string day = BytesTool.readString(_PatId.BirthDate, 6, 2);
date.Year = ushort.Parse(year);
date.Month = byte.Parse(month);
date.Day = byte.Parse(day);
return date;
}
catch (Exception)
{
}
}
return null;
}
set
{
if (value != null)
{
BytesTool.writeString(value.Year.ToString("d4"), _PatId.BirthDate, 0, 5);
BytesTool.writeString(value.Month.ToString("d2"), _PatId.BirthDate, 4, 3);
BytesTool.writeString(value.Day.ToString("d2"), _PatId.BirthDate, 6, 3);
}
}
}
public int getPatientHeight(out ushort val, out HeightDefinition def)
{
val = 0;
def = HeightDefinition.Unspecified;
if (_IdRecInfo.Weight != 0)
{
val = (ushort) _IdRecInfo.Height;
def = HeightDefinition.Centimeters;
}
return 1;
}
public int setPatientHeight(ushort val, HeightDefinition def)
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?