scpsection1.cs

来自「ecg tool kit for medical image retrieval」· CS 代码 · 共 1,473 行 · 第 1/3 页

CS
1,473
字号
			{
				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 = 15;
					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 DateTime TimeAcquisition
		{
			get
			{
				int p = _SearchField(25);
				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);
					DateTime time = new DateTime(scpdate.Year, scpdate.Month, scpdate.Day);

					p = _SearchField(26);
					if ((p >= 0)
					&&  (_Fields[p].Length == 3)
					&&  (_Fields[p].Value != null)
					&&  (_Fields[p].Length <= _Fields[p].Value.Length))
					{
						SCPTime scptime = new SCPTime();
						scptime.Read(_Fields[p].Value, 0);

						time = time.AddHours(scptime.Hour).AddMinutes(scptime.Min).AddSeconds(scptime.Sec);
					}

					return time;
				}
				return DateTime.MinValue;
			}
			set
			{
				DateTime time = value;

				if (time.Year > 1000)
				{
					SCPHeaderField field = new SCPHeaderField();
					field.Tag = 25;
					field.Length = (ushort) Marshal.SizeOf(typeof(SCPDate));
					field.Value = new byte[field.Length];
					SCPDate scpdate = new SCPDate();
					scpdate.Year = (ushort) time.Year;
					scpdate.Month = (byte) time.Month;
					scpdate.Day = (byte) time.Day;
					scpdate.Write(field.Value, 0);
					int ret = Insert(field);

					if (ret != 0)
						return;

					field = new SCPHeaderField();
					field.Tag = 26;
					field.Length = (ushort) Marshal.SizeOf(typeof(SCPTime));
					field.Value = new byte[field.Length];
					SCPTime scptime = new SCPTime();
					scptime.Hour = (byte) time.Hour;
					scptime.Min = (byte) time.Minute;
					scptime.Sec = (byte) time.Second;
					scptime.Write(field.Value, 0);

					Insert(field);
				}
			}
		}
		public ushort BaselineFilter
		{
			get
			{
				int p = _SearchField(27);
				if ((p >= 0)
				&&  (_Fields[p].Length == 1)
				&&  (_Fields[p].Value != null)
				&&  (_Fields[p].Length <= _Fields[p].Value.Length))
				{
					return (ushort) BytesTool.readBytes(_Fields[p].Value, 0, Marshal.SizeOf(typeof(ushort)), true);
				}
				return 0;
			}
			set
			{
				SCPHeaderField field = new SCPHeaderField();
				field.Tag = 27;
				field.Length = (ushort) Marshal.SizeOf(value);
				field.Value = new byte[field.Length];
				BytesTool.writeBytes(value, field.Value, 0, Marshal.SizeOf(value), true);
				Insert(field);
			}
		}
		public ushort LowpassFilter
		{
			get
			{
				int p = _SearchField(28);
				if ((p >= 0)
				&&  (_Fields[p].Length == 1)
				&&  (_Fields[p].Value != null)
				&&  (_Fields[p].Length <= _Fields[p].Value.Length))
				{
					return (ushort) BytesTool.readBytes(_Fields[p].Value, 0, Marshal.SizeOf(typeof(ushort)), true);
				}
				return 0;
			}
			set
			{
				SCPHeaderField field = new SCPHeaderField();
				field.Tag = 28;
				field.Length = (ushort) Marshal.SizeOf(value);
				field.Value = new byte[field.Length];
				BytesTool.writeBytes(value, field.Value, 0, Marshal.SizeOf(value), true);
				Insert(field);
			}
		}
		public byte FilterBitmap
		{
			get
			{
				int p = _SearchField(29);
				if ((p >= 0)
				&&  (_Fields[p].Length == 1)
				&&  (_Fields[p].Value != null)
				&&  (_Fields[p].Length <= _Fields[p].Value.Length))
				{
					return (byte) BytesTool.readBytes(_Fields[p].Value, 0, Marshal.SizeOf(typeof(byte)), true);
				}
				return 0;
			}
			set
			{
				if (value != 0)
				{
					SCPHeaderField field = new SCPHeaderField();
					field.Tag = 29;
					field.Length = (ushort) Marshal.SizeOf(value);
					field.Value = new byte[field.Length];
					BytesTool.writeBytes(value, field.Value, 0, Marshal.SizeOf(value), true);
					Insert(field);
				}
			}
		}
		public string[] FreeTextFields
		{
			get
			{
				int p = _SearchField(30);
				if (p >= 0)
				{
					for (;(p > 0) && (_Fields[p-1].Tag == 30);p--){}
					int len=0;
					for (;((p + len) < _NrFields) && (_Fields[p+len].Tag == 30);len++){}

					if (len > 0)
					{
						string []text = new string[len];
						for (int loper=0;loper < len;loper++)
						{
							if ((_Fields[p + loper].Value != null)
							&&  (_Fields[p + loper].Length <= _Fields[p + loper].Value.Length))
							{
								text[loper] = BytesTool.readString(_Encoding, _Fields[p + loper].Value, 0, _Fields[p + loper].Length);
							}
						}
						return text;
					}
				}
				return null;
			}
			set
			{
				if (value != null)
				{
					for (int loper=0;loper < value.Length;loper++)
					{
						if (value[loper] != null)
						{
							SCPHeaderField field = new SCPHeaderField();
							field.Tag = 30;
							field.Length = (ushort) (value[loper].Length >= _ExceptionsMaximumLength ? _ExceptionsMaximumLength : value[loper].Length + 1);
							field.Value = new byte[field.Length];
							BytesTool.writeString(_Encoding, value[loper], field.Value, 0, field.Length);
							Insert(field);
						}
					}
				}
			}
		}
		public string SequenceNr
		{
			get {return getText(31);}
			set {setText(31, value);}
		}
		public string AcqInstitution
		{
			get {return getText(16);}
			set {setText(16, value);}
		}
		public string AnalyzingInstitution
		{
			get {return getText(17);}
			set {setText(17, value);}
		}
		public string AcqDepartment
		{
			get {return getText(18);}
			set {setText(18, value);}
		}
		public string AnalyzingDepartment
		{
			get {return getText(19);}
			set {setText(19, value);}
		}
		public string ReferringPhysician
		{
			get {return getText(20);}
			set {setText(20, value);}
		}
		public string OverreadingPhysician
		{
			get {return getText(21);}
			set {setText(21, value);}
		}
		public string TechnicianDescription
		{
			get {return getText(22);}
			set {setText(22, value);}
		}
		public ushort SystolicBloodPressure
		{
			get
			{
				int p = _SearchField(11);
				if (p >= 0)
				{
					return (ushort) BytesTool.readBytes(_Fields[p].Value, 0, Marshal.SizeOf(typeof(ushort)), true);
				}
				return 0;
			}
			set
			{
				if (value != 0)
				{
					SCPHeaderField field = new SCPHeaderField();
					field.Tag = 11;
					field.Length = (ushort) Marshal.SizeOf(typeof(ushort));
					field.Value = new byte[field.Length];
					BytesTool.writeBytes(value, field.Value, 0, field.Length, true);
					Insert(field);
				}
			}
		}
		public ushort DiastolicBloodPressure
		{
			get
			{
				int p = _SearchField(12);
				if (p >= 0)
				{
					return (ushort) BytesTool.readBytes(_Fields[p].Value, 0, Marshal.SizeOf(typeof(ushort)), true);
				}
				return 1;
			}
			set
			{
				if (value != 0)
				{
					SCPHeaderField field = new SCPHeaderField();
					field.Tag = 12;
					field.Length = (ushort) Marshal.SizeOf(typeof(ushort));
					field.Value = new byte[field.Length];
					BytesTool.writeBytes(value, field.Value, 0, field.Length, true);
					Insert(field);
				}
			}
		}
		public Drug[] Drugs
		{
			get
			{
				int p = _SearchField(10);
				if (p >= 0)
				{
					for (;(p > 0) && (_Fields[p-1].Tag == 10);p--){}
					int len=0;
					for (;((p + len) < _NrFields) && (_Fields[p+len].Tag == 10);len++){}

					if (len > 0)
					{
						Drug[] drugs = new Drug[len];
						for (int loper=0;loper < len;loper++)
						{
							if ((_Fields[p + loper].Length > 3)
							&&  (_Fields[p + loper].Value != null)
							&&  (_Fields[p + loper].Length <= _Fields[p + loper].Value.Length))
							{
								drugs[loper] = new Drug();
								drugs[loper].DrugClass = _Fields[p + loper].Value[1];
								drugs[loper].ClassCode = _Fields[p + loper].Value[2];
								drugs[loper].TextDesciption = BytesTool.readString(_Encoding, _Fields[p + loper].Value, 3, _Fields[p + loper].Length - 3);
							}
						}
						return drugs;
					}
				}
				return null;
			}
			set
			{
				if (value != null)
				{
					for (int loper=0;loper < value.Length;loper++)
					{
						if (value[loper] != null)
						{
							SCPHeaderField field = new SCPHeaderField();
							field.Tag = 10;
							field.Length = (ushort) (4 + (value[loper].TextDesciption != null ? value[loper].TextDesciption.Length : 0));
							field.Value = new byte[field.Length];
							field.Value[0] = 0;
							field.Value[1] = value[loper].DrugClass;
							field.Value[2] = value[loper].ClassCode;
							BytesTool.writeString(_Encoding, value[loper].TextDesciption, field.Value, 3, field.Length - 3);

							Insert(field);
						}
					}
				}
			}
		}
		public string[] ReferralIndication
		{
			get
			{
				int p = _SearchField(13);
				if (p >= 0)
				{
					for (;(p > 0) && (_Fields[p-1].Tag == 13);p--){}
					int len=0;
					for (;((p + len) < _NrFields) && (_Fields[p+len].Tag == 13);len++){}
					if (len < 0)
					{
						string[] text = new string[len];
						for (int loper=0;loper < len;loper++)
						{
							if ((_Fields[p + loper].Value != null)
								&&  (_Fields[p + loper].Length <= _Fields[p + loper].Value.Length))
							{
								text[loper] = BytesTool.readString(_Encoding, _Fields[p + loper].Value, 0, _Fields[p + loper].Length);
							}
						}
						return text;
					}
				}
				return null;
			}
			set
			{
				if (value != null)
				{
					for (int loper=0;loper < value.Length;loper++)
					{
						if (value[loper] != null)
						{
							SCPHeaderField field = new SCPHeaderField();
							field.Tag = 13;
							field.Length = (ushort) (value[loper].Length >= _ExceptionsMaximumLength ? _ExceptionsMaximumLength : value[loper].Length + 1);
							field.Value = new byte[field.Length];
							BytesTool.writeString(_Encoding, value[loper], field.Value, 0, field.Length);
							Insert(field);
						}
					}
				}
			}
		}
		public string RoomDescription
		{
			get {return getText(23);}
			set {setText(23, value);}
		}
		public byte StatCode
		{
			get
			{
				int p = _SearchField(24);
				if ((p >= 0)
				&&	(_Fields[p].Value != null)
				&&	(_Fields[p].Length == Marshal.SizeOf(typeof(byte))))
				{
					return (byte) BytesTool.readBytes(_Fields[p].Value, 0, Marshal.SizeOf(typeof(byte)), true);
				}
				return 0xff;
			}
			set
			{
				if (value != 0xff)
				{
					SCPHeaderField field = new SCPHeaderField();
					field.Tag = 24;
					field.Length = (ushort) Marshal.SizeOf(value);
					field.Value = new byte[field.Length];
					BytesTool.writeBytes(value, field.Value, 0, Marshal.SizeOf(value), true);
					Insert(field);
				}
			}
		}
		/// <summary>
		/// Class for a header field.
		/// </summary>
		public class SCPHeaderField
		{
			public byte Tag = 0;
			public ushort Length = 0;
			public byte[] Value = null;
			/// <summary>
			/// Constructor to make an SCP header field.
			/// </summary>
			public SCPHeaderField()
			{}
			/// <summary>
			/// Constructor to make an SCP header field.
			/// </summary>
			/// <param name="tag">tag to use</param>
			/// <param name="length">length to use</param>
			/// <param name="value">array to use</param>
			public SCPHeaderField(byte tag, ushort length, byte[] value)
			{
				Tag = tag;
				Length = (value == null ? (ushort)0 : length);
				Value = value;
			}
		}
		public enum ProtocolCompatibility
		{CatI = 0x90, CatII = 0xa0, CatIII = 0xb0, CatIV = 0xc0}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?