scpsection1.cs
来自「ecg tool kit for medical image retrieval」· CS 代码 · 共 1,473 行 · 第 1/3 页
CS
1,473 行
{
ret = 2;
}
p = _SearchField(15);
if ((p >= 0)
&& (_Fields[p] != null)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length)
&& (_Fields[p].Length > 16))
{
_Fields[p].Value[16] = lsc;
}
return ret;
}
/// <summary>
/// Function to get Protocol Compatability Level.
/// </summary>
/// <param name="pc">Protocol Compatability Level</param>
/// <returns>0 on succes</returns>
public int getProtocolCompatibilityLevel(out ProtocolCompatibility pc)
{
pc = 0;
int p = _SearchField(14);
if ((p >= 0)
&& (_Fields[p] != null)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length)
&& (_Fields[p].Length > 15))
{
pc = (ProtocolCompatibility) _Fields[p].Value[15];
return 0;
}
return 1;
}
/// <summary>
/// Function to set Protocol Compatability Level.
/// </summary>
/// <param name="pc">Protocol Compatability Level</param>
/// <returns>0 on succes</returns>
public int setProtocolCompatibilityLevel(ProtocolCompatibility pc)
{
int p = _SearchField(14);
if ((p >= 0)
&& (_Fields[p] != null)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length)
&& (_Fields[p].Length > 15))
{
_Fields[p].Value[15] = (byte) pc;
return 0;
}
return 1;
}
/// <summary>
/// Function to get a text from a certain tag.
/// </summary>
/// <param name="tag">id of tag</param>
/// <param name="text">a string</param>
/// <returns>0 on success</returns>
public string getText(byte tag)
{
int p = _SearchField(tag);
if ((p >= 0)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length))
{
return BytesTool.readString(_Encoding, _Fields[p].Value, 0, _Fields[p].Length);;
}
return null;
}
/// <summary>
/// Function to set a text from a cetain tag.
/// </summary>
/// <param name="tag">id of tag</param>
/// <param name="text">a string</param>
/// <returns>0 on success</returns>
public int setText(byte tag, string text)
{
if (text != null)
{
SCPHeaderField field = new SCPHeaderField();
field.Tag = tag;
field.Length = (ushort) (text.Length >= _MaximumFieldLength ? _MaximumFieldLength : text.Length + 1);
field.Value = new byte[field.Length];
BytesTool.writeString(_Encoding, text, field.Value, 0, field.Length);
return Insert(field) << 1;
}
return 1;
}
// Getting Demographics information
public string LastName
{
get {return getText(0);}
set {setText(0, value);}
}
public string FirstName
{
get {return getText(1);}
set {setText(1, value);}
}
public string PatientID
{
get {return getText(2);}
set {setText(2, value);}
}
public string SecondLastName
{
get {return getText(3);}
set {setText(3, value);}
}
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;
int p = _SearchField(4);
if ((p >= 0)
&& (_Fields[p].Length == 3)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length))
{
val = (ushort) BytesTool.readBytes(_Fields[p].Value, 0, Marshal.SizeOf(val), true);
switch (BytesTool.readBytes(_Fields[p].Value, Marshal.SizeOf(val), 1, true))
{
case 1:
def = AgeDefinition.Years;
break;
case 2:
def = AgeDefinition.Months;
break;
case 3:
def = AgeDefinition.Weeks;
break;
case 4:
def = AgeDefinition.Days;
break;
case 5:
def = AgeDefinition.Hours;
break;
default:
def = AgeDefinition.Unspecified;
break;
}
return 0;
}
return 1;
}
public int setPatientAge(ushort val, AgeDefinition def)
{
SCPHeaderField field = new SCPHeaderField();
field.Tag = 4;
field.Length = (ushort) (Marshal.SizeOf(val) + Marshal.SizeOf(typeof(byte)));
field.Value = new byte[field.Length];
BytesTool.writeBytes(val, field.Value, 0, Marshal.SizeOf(val), true);
BytesTool.writeBytes((byte)def, field.Value, Marshal.SizeOf(val), Marshal.SizeOf(typeof(byte)), true);
return Insert(field) << 1;
}
public Date PatientBirthDate
{
get
{
int p = _SearchField(5);
if ((p >= 0)
&& (_Fields[p].Length == 4)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length))
{
SCPDate scpdate = new SCPDate();
scpdate.Read(_Fields[p].Value, 0);
Date date = new Date();
date.Year = scpdate.Year;
date.Month = scpdate.Month;
date.Day = scpdate.Day;
return date;
}
return null;
}
set
{
if ((value != null)
&& (value.isExistingDate()))
{
SCPHeaderField field = new SCPHeaderField();
field.Tag = 5;
field.Length = (ushort) Marshal.SizeOf(typeof(SCPDate));
field.Value = new byte[field.Length];
SCPDate scpdate = new SCPDate();
scpdate.Year = value.Year;
scpdate.Month = value.Month;
scpdate.Day = value.Day;
scpdate.Write(field.Value, 0);
Insert(field);
}
}
}
public int getPatientHeight(out ushort val, out HeightDefinition def)
{
val = 0; def = HeightDefinition.Unspecified;
int p = _SearchField(6);
if ((p >= 0)
&& (_Fields[p].Length == 3)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length))
{
val = (ushort) BytesTool.readBytes(_Fields[p].Value, 0, Marshal.SizeOf(val), true);
switch (BytesTool.readBytes(_Fields[p].Value, Marshal.SizeOf(val), 1, true))
{
case 1:
def = HeightDefinition.Centimeters;
break;
case 2:
def = HeightDefinition.Inches;
break;
case 3:
def = HeightDefinition.Millimeters;
break;
default:
def = HeightDefinition.Unspecified;
break;
}
return 0;
}
return 1;
}
public int setPatientHeight(ushort val, HeightDefinition def)
{
SCPHeaderField field = new SCPHeaderField();
field.Tag = 6;
field.Length = (ushort) (Marshal.SizeOf(val) + Marshal.SizeOf(typeof(byte)));
field.Value = new byte[field.Length];
BytesTool.writeBytes(val, field.Value, 0, Marshal.SizeOf(val), true);
BytesTool.writeBytes((byte)def, field.Value, Marshal.SizeOf(val), 1, true);
return Insert(field) << 1;
}
public int getPatientWeight(out ushort val, out WeightDefinition def)
{
val = 0; def = WeightDefinition.Unspecified;
int p = _SearchField(7);
if ((p >= 0)
&& (_Fields[p].Length == 3)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length))
{
val = (ushort) BytesTool.readBytes(_Fields[p].Value, 0, Marshal.SizeOf(val), true);
switch (BytesTool.readBytes(_Fields[p].Value, Marshal.SizeOf(val), 1, true))
{
case 1:
def = WeightDefinition.Kilogram;
break;
case 2:
def = WeightDefinition.Gram;
break;
case 3:
def = WeightDefinition.Pound;
break;
case 4:
def = WeightDefinition.Ounce;
break;
default:
def = WeightDefinition.Unspecified;
break;
}
return 0;
}
return 1;
}
public int setPatientWeight(ushort val, WeightDefinition def)
{
SCPHeaderField field = new SCPHeaderField();
field.Tag = 7;
field.Length = (ushort) (Marshal.SizeOf(val) + Marshal.SizeOf(typeof(byte)));
field.Value = new byte[field.Length];
BytesTool.writeBytes(val, field.Value, 0, Marshal.SizeOf(val), true);
BytesTool.writeBytes((byte)def, field.Value, Marshal.SizeOf(val), Marshal.SizeOf(typeof(byte)), true);
return Insert(field) << 1;
}
public Sex Gender
{
get
{
int p = _SearchField(8);
if ((p >= 0)
&& (_Fields[p].Length == 1)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length))
{
switch (BytesTool.readBytes(_Fields[p].Value, 0, 1, true))
{
case 1:
return Sex.Male;
case 2:
return Sex.Female;
default:
return Sex.Unspecified;
}
}
return Sex.Null;
}
set
{
if (value != Sex.Null)
{
SCPHeaderField field = new SCPHeaderField();
field.Tag = 8;
field.Length = (ushort) Marshal.SizeOf(typeof(byte));
field.Value = new byte[field.Length];
BytesTool.writeBytes((byte)value, field.Value, 0, Marshal.SizeOf(typeof(byte)), true);
Insert(field);
}
}
}
public Race PatientRace
{
get
{
int p = _SearchField(9);
if ((p >= 0)
&& (_Fields[p].Length == 1)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length))
{
switch (BytesTool.readBytes(_Fields[p].Value, 0, 1, true))
{
case 1:
return Race.Caucasian;
case 2:
return Race.Black;
case 3:
return Race.Oriental;
default:
return Race.Unspecified;
}
}
return Race.Null;
}
set
{
if (value != Race.Null)
{
SCPHeaderField field = new SCPHeaderField();
field.Tag = 9;
field.Length = (ushort) Marshal.SizeOf(typeof(byte));
field.Value = new byte[field.Length];
BytesTool.writeBytes((byte)value, field.Value, 0, Marshal.SizeOf(typeof(byte)), true);
Insert(field);
}
}
}
public AcquiringDeviceID AcqMachineID
{
get
{
int p = _SearchField(14);
if ((p >= 0)
&& (_Fields[p].Length >= 36)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length))
{
AcquiringDeviceID id = new AcquiringDeviceID();
int offset = 0;
id.InstitutionNr = (ushort) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.InstitutionNr), true);
offset += Marshal.SizeOf(id.InstitutionNr);
id.DepartmentNr = (ushort) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.DepartmentNr), true);
offset += Marshal.SizeOf(id.DepartmentNr);
id.DeviceID = (ushort) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.DeviceID), true);
offset += Marshal.SizeOf(id.DeviceID);
id.DeviceType = (byte) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.DeviceType), true);
offset += Marshal.SizeOf(id.DeviceType);
id.ManufactorID = (byte) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.ManufactorID), true);
offset += Marshal.SizeOf(id.ManufactorID);
offset += BytesTool.copy(id.ModelDescription, 0, _Fields[p].Value, offset, id.ModelDescription.Length);
// Skip some not needed info.
offset += 3;
id.DeviceCapabilities = (byte) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.DeviceCapabilities), true);
offset += Marshal.SizeOf(id.DeviceCapabilities);
id.ACFrequencyEnvironment = (byte) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.ACFrequencyEnvironment), true);
offset += Marshal.SizeOf(id.ACFrequencyEnvironment);
return id;
}
return null;
}
set
{
AcquiringDeviceID id = value;
if ((id != null)
&& (id.ModelDescription != null))
{
SCPHeaderField field = new SCPHeaderField();
string deviceManufactor = (id.ManufactorID == 0 ? ECGConverter.SoftwareName : ((DeviceManufactor)id.ManufactorID).ToString());
string unknown = "unknown";
field.Tag = 14;
field.Length = (ushort) (41 + (ECGConverter.SoftwareName.Length > 24 ? 24 : ECGConverter.SoftwareName.Length) + deviceManufactor.Length + (3 * unknown.Length));
field.Value = new byte[field.Length];
int offset = 0;
BytesTool.writeBytes(id.InstitutionNr, field.Value, offset, Marshal.SizeOf(id.InstitutionNr), true);
offset += Marshal.SizeOf(id.InstitutionNr);
BytesTool.writeBytes(id.DepartmentNr, field.Value, offset, Marshal.SizeOf(id.DepartmentNr), true);
offset += Marshal.SizeOf(id.DepartmentNr);
BytesTool.writeBytes(id.DeviceID, field.Value, offset, Marshal.SizeOf(id.DeviceID), true);
offset += Marshal.SizeOf(id.DeviceID);
BytesTool.writeBytes(id.DeviceType, field.Value, offset, Marshal.SizeOf(id.DeviceType), true);
offset += Marshal.SizeOf(id.DeviceType);
BytesTool.writeBytes((id.ManufactorID == 0 ? (byte) 0xff : id.ManufactorID), field.Value, offset, Marshal.SizeOf(id.ManufactorID), true);
offset += Marshal.SizeOf(id.ManufactorID);
offset += BytesTool.copy(field.Value, offset, id.ModelDescription, 0, id.ModelDescription.Length);
field.Value[offset++] = ProtocolVersionNr;
field.Value[offset++] = 0x00;
field.Value[offset++] = 0x00;
field.Value[offset++] = (id.DeviceCapabilities == 0 ? (byte) 0x8 : id.DeviceCapabilities);
field.Value[offset++] = id.ACFrequencyEnvironment;
// Skip Reserved for Future field
offset += 16;
field.Value[offset++] = (byte) (unknown.Length + 1);
BytesTool.writeString(_Encoding, unknown, field.Value, offset, unknown.Length + 1);
offset+= unknown.Length + 1;
BytesTool.writeString(_Encoding, unknown, field.Value, offset, unknown.Length + 1);
offset+= unknown.Length + 1;
BytesTool.writeString(_Encoding, unknown, field.Value, offset, unknown.Length + 1);
offset+= unknown.Length + 1;
BytesTool.writeString(_Encoding, ECGConverter.SoftwareName, field.Value, offset, (ECGConverter.SoftwareName.Length > 24 ? 24 : ECGConverter.SoftwareName.Length) + 1);
offset+= (ECGConverter.SoftwareName.Length > 24 ? 24 : ECGConverter.SoftwareName.Length) + 1;
BytesTool.writeString(_Encoding, deviceManufactor, field.Value, offset, deviceManufactor.Length + 1);
offset+= deviceManufactor.Length + 1;
int ret = Insert(field);
if (ret == 0)
ret = setLanguageSupportCode(_Encoding);
}
}
}
public AcquiringDeviceID AnalyzingMachineID
{
get
{
int p = _SearchField(15);
if ((p >= 0)
&& (_Fields[p].Length >= 36)
&& (_Fields[p].Value != null)
&& (_Fields[p].Length <= _Fields[p].Value.Length))
{
AcquiringDeviceID id = new AcquiringDeviceID();
int offset = 0;
id.InstitutionNr = (ushort) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.InstitutionNr), true);
offset += Marshal.SizeOf(id.InstitutionNr);
id.DepartmentNr = (ushort) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.DepartmentNr), true);
offset += Marshal.SizeOf(id.DepartmentNr);
id.DeviceID = (ushort) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.DeviceID), true);
offset += Marshal.SizeOf(id.DeviceID);
id.DeviceType = (byte) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.DeviceType), true);
offset += Marshal.SizeOf(id.DeviceType);
id.ManufactorID = (byte) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.ManufactorID), true);
offset += Marshal.SizeOf(id.ManufactorID);
offset += BytesTool.copy(id.ModelDescription, 0, _Fields[p].Value, offset, id.ModelDescription.Length);
// Skip some not needed info.
offset += 3;
id.DeviceCapabilities = (byte) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.DeviceCapabilities), true);
offset += Marshal.SizeOf(id.DeviceCapabilities);
id.ACFrequencyEnvironment = (byte) BytesTool.readBytes(_Fields[p].Value, offset, Marshal.SizeOf(id.ACFrequencyEnvironment), true);
offset += Marshal.SizeOf(id.ACFrequencyEnvironment);
return id;
}
return null;
}
set
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?