⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dicomformat.cs

📁 ecg tool kit for medical image retrieval system
💻 CS
📖 第 1 页 / 共 4 页
字号:
				_DICOMData.PutAS(Tags.PatientAge, "");
				_DICOMData.PutDS(Tags.PatientSize, "");
				_DICOMData.PutDS(Tags.PatientWeight, "");
				_DICOMData.PutLO(Tags.DeviceSerialNumber, "");
				_DICOMData.PutLO(Tags.SoftwareVersion, "");
				_DICOMData.PutUI(Tags.StudyInstanceUID, "1.1.1.1.1");
				_DICOMData.PutUI(Tags.SeriesInstanceUID, "1.1.1.1.2");
				_DICOMData.PutSH(Tags.StudyID, "");
				_DICOMData.PutIS(Tags.SeriesNumber, "1");
				_DICOMData.PutIS(Tags.InstanceNumber, "1");
				_DICOMData.PutCS(Tags.Laterality, "");
				_DICOMData.PutLO(Tags.CurrentPatientLocation, "");
				_DICOMData.PutLO(Tags.PatientInstitutionResidence, "");
				_DICOMData.PutLT(Tags.VisitComments, "");

				DcmElement temp1 = _DICOMData.PutSQ(Tags.AcquisitionContextSeq);
				Dataset ds = temp1.AddNewItem();

				ds.PutCS(Tags.ValueType, "CODE");

				DcmElement temp2 = ds.PutSQ(Tags.ConceptNameCodeSeq);
				ds = temp2.AddNewItem();

				ds.PutSH(Tags.CodeValue, "5.4.5-33-1");
				ds.PutSH(Tags.CodingSchemeDesignator, "SCPECG");
				ds.PutSH(Tags.CodingSchemeVersion, "1.3");
				ds.PutLO(Tags.CodeMeaning, "Electrode Placement");

				ds = temp1.GetItem(0);
				
				temp2 = ds.PutSQ(Tags.ConceptCodeSeq);
				ds = temp2.AddNewItem();

				ds.PutSH(Tags.CodeValue, "5.4.5-33-1-0");
				ds.PutSH(Tags.CodingSchemeDesignator, "SCPECG");
				ds.PutSH(Tags.CodingSchemeVersion, "1.3");
				ds.PutLO(Tags.CodeMeaning, "Unspecified");

				_DICOMData.PutLO(Tags.ReasonForTheRequestedProcedure, "");
			}
			catch
			{
				int i=0;
				i++;
			}

		}
		private string getName(int pos)
		{
			PersonName pn = new PersonName(_DICOMData.GetString(Tags.PatientName));

			return pn.Get(pos);
		}
		private int setName(string name, int pos)
		{
			PersonName pn = new PersonName(_DICOMData.GetString(Tags.PatientName));

			pn.Set(pos, name);

			_DICOMData.PutPN(Tags.PatientName, pn);

			return 0;
		}
		public string LastName
		{
			get {return getName(PersonName.FAMILY);}
			set {setName(value, PersonName.FAMILY);}
		}
		public string FirstName
		{
			get {return getName(PersonName.GIVEN);}
			set {setName(value, PersonName.GIVEN);}
		}
		public string PatientID
		{
			get {return _DICOMData.GetString(Tags.PatientID);}
			set {if (value != null) _DICOMData.PutLO(Tags.PatientID, value);}
		}
		public string SecondLastName
		{
			get {return getName(PersonName.MIDDLE);}
			set {setName(value, PersonName.MIDDLE);}
		}
		public string PrefixName
		{
			get {return getName(PersonName.PREFIX);}
			set {setName(value, PersonName.PREFIX);}
		}
		public string SuffixName
		{
			get {return getName(PersonName.SUFFIX);}
			set {setName(value, PersonName.SUFFIX);}
		}
		public int getPatientAge(out ushort val, out AgeDefinition def)
		{
			val = 0;
			def = AgeDefinition.Unspecified;

			string temp = _DICOMData.GetString(Tags.PatientAge);

			if (temp != null)
			{
				try
				{
					val = ushort.Parse(temp, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

					switch (temp[temp.Length-1])
					{
						case 'D': case 'd':
							def = AgeDefinition.Days;
							break;
						case 'W': case 'w':
							def = AgeDefinition.Weeks;
							break;
						case 'M': case 'm':
							def = AgeDefinition.Months;
							break;
						case 'Y': case 'y':
							def = AgeDefinition.Years;
							break;
						default:
							def = AgeDefinition.Unspecified;
							break;
					}
				}
				catch {}
			}
			
			return def == AgeDefinition.Unspecified ? 1 : 0;
		}
		public int setPatientAge(ushort val, AgeDefinition def)
		{
			string temp = null;;

			try
			{

				switch (def)
				{
					case AgeDefinition.Hours:
						temp = (((val - 1) / 24) + 1).ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + 'D';
						break;
					case AgeDefinition.Days:
						temp = val.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + 'D';
						break;
					case AgeDefinition.Weeks:
						temp = val.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + 'W';
						break;
					case AgeDefinition.Months:
						temp = val.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + 'M';
						break;
					case AgeDefinition.Years:
						temp = val.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + 'Y';
						break;
					default:
						temp = null;
						break;
				}
			}
			catch
			{
				temp = null;
			}

			if (temp != null)
			{
				_DICOMData.PutAS(Tags.PatientAge, temp);

				return 0;
			}

			return 1;
		}
		public Date PatientBirthDate
		{
			get
			{
				DateTime time = _DICOMData.GetDate(Tags.PatientBirthDate);

				if (time.Year > 1000)
					return new Date((ushort) time.Year, (byte) time.Month, (byte) time.Day);

				return null;
			}
			set
			{
				if ((value != null)
				&&	value.isExistingDate())
				{
					_DICOMData.PutDA(Tags.PatientBirthDate, new DateTime(value.Year, value.Month, value.Day));
				}
			}
		}
		public int getPatientHeight(out ushort val, out HeightDefinition def)
		{
			val = 0;
			def = HeightDefinition.Unspecified;

			try
			{
				double val2 = double.Parse(_DICOMData.GetString(Tags.PatientSize), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

				if (val >= 0.1)
				{
					val = (ushort) (val2 * 100);
					def = HeightDefinition.Centimeters;
				}
				else
				{
					val = (ushort) (val2 * 1000);
					def = HeightDefinition.Millimeters;
				}

				return 0;
			}
			catch {}


			return 1;
		}
		public int setPatientHeight(ushort val, HeightDefinition def)
		{
			double val2 = double.MinValue;

			switch (def)
			{
				case HeightDefinition.Centimeters:
					val2 = val * 0.01;
					break;
				case HeightDefinition.Inches:
					val2 = val * 0.0254;
					break;
				case HeightDefinition.Millimeters:
					val2 = val * 0.001;
					break;

					
			}

			if (val2 > 0)
			{
				val2 = Math.Round(val2 * 100.0) * 0.01;

				_DICOMData.PutDS(Tags.PatientSize, val2.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat));

				return 0;
			}

			return 1;
		}
		public int getPatientWeight(out ushort val, out WeightDefinition def)
		{
			val = 0;
			def = WeightDefinition.Unspecified;

			try
			{
				double val2 = double.Parse(_DICOMData.GetString(Tags.PatientWeight), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

				if (val2 >= 1.0)
				{
					val = (ushort) val2;
					def = WeightDefinition.Kilogram;
				}
				else
				{
					val = (ushort) (val2 * 1000.0);
					def = WeightDefinition.Gram;
				}

				return 0;
			}
			catch {}

			return 1;
		}
		public int setPatientWeight(ushort val, WeightDefinition def)
		{
			double val2 = double.MinValue;

			switch (def)
			{
				case WeightDefinition.Gram:
					val2 = val * 0.001;
					break;
				case WeightDefinition.Kilogram:
					val2 = val;
					break;
				case WeightDefinition.Ounce:
					val2 = (val * 0.0283495231);
					break;
				case WeightDefinition.Pound:
					val2 = (val * 0.45359237);
					break;
			}

			if (val2 > 0)
			{
				val2 = Math.Round(val2 * 100.0) * 0.01;

				_DICOMData.PutDS(Tags.PatientWeight, val2.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat));

				return 0;
			}

			return 1;
		}
		public Sex Gender
		{
			get
			{
				string val = _DICOMData.GetString(Tags.PatientSex);
				if (val != null)
				{
					switch (val)
					{
						case "M":
							return Sex.Male;
						case "F":
							return Sex.Female;
						default:
							return Sex.Unspecified;
					}
				}

				return Sex.Null;
			}
			set
			{
				if (value != Sex.Null)
				{
					string sexText = "N";

					switch (value)
					{
						case Sex.Male:
							sexText = "M";
							break;
						case Sex.Female:
							sexText = "F";
							break;
					}


					if (sexText != null)
						_DICOMData.PutCS(Tags.PatientSex, sexText);
				}
			}
		}
		public Race PatientRace
		{
			get {return Race.Null;}
			set {}
		}
		public AcquiringDeviceID AcqMachineID
		{
			get
			{
				AcquiringDeviceID id = new AcquiringDeviceID(true);

				byte map = FilterBitmap;

				if (map != 0)
				{
					if ((map & 0x1) == 0x1)
						id.ACFrequencyEnvironment = 2;
					else if ((map & 0x2) == 0x2)
						id.ACFrequencyEnvironment = 1;
					else
						id.ACFrequencyEnvironment = 0;
				}

				return id;
			}
			set
			{
				_DICOMData.PutLO(Tags.Manufacturer, ((DeviceManufactor)value.ManufactorID).ToString());
				_DICOMData.PutLO(Tags.ManufacturerModelName, BytesTool.readString(value.ModelDescription, 0, value.ModelDescription.Length));
			}
		}
		public AcquiringDeviceID AnalyzingMachineID
		{
			get {return null;}
			set {}
		}
		public DateTime TimeAcquisition
		{
			get
			{
				DateTime time = _DICOMData.GetDate(Tags.AcquisitionDatetime);

				if (time.Year <= 1000)
					time = _DICOMData.GetDate(Tags.AcquisitionDate);

				return time;
			}
			set
			{
				_DICOMData.PutDA(Tags.StudyDate, value);
				_DICOMData.PutDA(Tags.ContentDate, value);
				_DICOMData.PutDT(Tags.AcquisitionDatetime, value);
				_DICOMData.PutTM(Tags.StudyTime, value);
				_DICOMData.PutTM(Tags.ContentTime, value);

				string uid = "1.2.826.0.1.34471.2.44." + value.ToString("yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat);

				FileMetaInfo fmi = _DICOMData.GetFileMetaInfo();
				if (fmi != null)
					fmi.PutUI(Tags.MediaStorageSOPInstanceUID, uid + ".1.1");

				_DICOMData.PutUI(Tags.SOPInstanceUID, uid + ".1.1");
				_DICOMData.PutUI(Tags.StudyInstanceUID, uid + ".1");
				_DICOMData.PutUI(Tags.SeriesInstanceUID, uid + ".1.2");
			}
		}
		public ushort BaselineFilter
		{
			get
			{
				try
				{
					if (_HighpassFilter == 0)
					{
						float filter = GetFilter(_DICOMData.Get(Tags.WaveformSeq).GetItem(0), Tags.FilterLowFrequency) * 100.0f;

						if ((filter > 0)
						&&	(filter <= ushort.MaxValue))
							_HighpassFilter = (ushort) filter;
					}

					return _HighpassFilter;
				}
				catch {}
			
				return 0;
			}
			set
			{
				_HighpassFilter = value;
			}
		}
		public ushort LowpassFilter
		{
			get
			{
				try
				{
					if (_LowpassFilter == 0)
					{
						float filter = GetFilter(_DICOMData.Get(Tags.WaveformSeq).GetItem(0), Tags.FilterHighFrequency);

						if ((filter > 0)
						&&	(filter <= ushort.MaxValue))
							_LowpassFilter = (ushort) filter;
					}

					return _LowpassFilter;
				}
				catch {}

				return 0;
			}
			set
			{
				_HighpassFilter = value;
			}
		}
		public byte FilterBitmap
		{
			get
			{
				try
				{
					if (_FilterMap > byte.MaxValue)
					{
						byte map = 0;

						Dataset ds = _DICOMData.Get(Tags.WaveformSeq).GetItem(0);

						float filter = GetFilter(ds, Tags.NotchFilterFrequency);

						if (filter == 60.0f)
							map |= 0x1;
						else if (filter == 50.0f)
							map |= 0x2;

						filter = GetFilter(ds, Tags.FilterHighFrequency) * 100;
					
						if ((filter >= 0)
						&&	(filter <= ushort.MaxValue))
							map |= 0x8;

						_FilterMap = map;
					}

					return _FilterMap;
				}
				catch {}

				return 0;
			}
			set
			{
				_FilterMap = value;
			}
		}
		public string[] FreeTextFields
		{
			get {return _DICOMData.GetStrings(Tags.VisitComments);}
			set {if (value != null) _DICOMData.PutLT(Tags.VisitComments, value);}
		}
		public string SequenceNr
		{
			get
			{
				string temp1 = _DICOMData.GetString(Tags.StudyInstanceUID);

				if (temp1 != null)
				{
					string[] temp2 = temp1.Split('.');

					return temp2[temp2.Length-1];
				}

				return null;
			}
			set
			{
				
				string uid = _UIDPrefix + TimeAcquisition.ToString("yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat) + "." + value;

				FileMetaInfo fmi = _DICOMData.GetFileMetaInfo();
				if (fmi != null)
					fmi.PutUI(Tags.MediaStorageSOPInstanceUID, uid + ".1");

				_DICOMData.PutUI(Tags.SOPInstanceUID, uid + ".1");
				_DICOMData.PutUI(Tags.StudyInstanceUID, uid);
				_DICOMData.PutUI(Tags.SeriesInstanceUID, uid + ".2");
			}
		}
		public string AcqInstitution
		{
			get {return _DICOMData.GetString(Tags.InstitutionName);}
			set {if (value != null) _DICOMData.PutLO(Tags.InstitutionName, value);}
		}
		public string AnalyzingInstitution
		{
			get {return null;}
			set {}
		}
		public string AcqDepartment
		{
			get {return _DICOMData.GetString(Tags.InstitutionalDepartmentName);}
			set {if (value != null) _DICOMData.PutLO(Tags.InstitutionalDepartmentName, value);}
		}
		public string AnalyzingDepartment

⌨️ 快捷键说明

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