Class DicomElement
One data element of a DicomDataset: its tag, value representation and value, read as the file stores it and decoded on request by its VR (PS3.5 section 6.2).
[Experimental("EGAMIX001", UrlFormat = "https://github.com/inexin/Egami/blob/main/docs/articles/formats/dicom.md")]
public sealed class DicomElement
- Inheritance
-
DicomElement
- Inherited Members
Examples
DicomDataset data = file.Dataset;
DateOnly? studyDate = data["StudyDate"]?.GetDate();
DicomPersonName? patient = data["PatientName"]?.GetPersonName();
double[] window = data["WindowCenter"]?.GetNumbers() ?? [];
// A sequence is a list of datasets; text decodes by the dataset's Specific Character Set.
foreach (DicomDataset item in data["ContentSequence"]?.Items ?? [])
{
Console.WriteLine(item.GetString("ReferencedSOPClassUID"));
}
// Every element prints as a dump line, such as "(0028,0010) US Rows: 4".
foreach (DicomElement element in data)
{
Console.WriteLine(element);
}
Properties
Fragments
Gets the fragments of encapsulated (compressed) pixel data, or null for any other element.
public DicomFragments? Fragments { get; }
Property Value
IsEmpty
Gets whether the value is empty: no bytes, no items and no fragments.
public bool IsEmpty { get; }
Property Value
Items
Gets the items of a sequence (SQ), each a dataset; empty for other elements.
public IReadOnlyList<DicomDataset> Items { get; }
Property Value
RawValue
Gets the value's bytes as the file stores them, padding included, in the byte order of the file's TransferSyntax. Empty for a sequence and for encapsulated pixel data, whose parts are Items and Fragments.
public ReadOnlyMemory<byte> RawValue { get; }
Property Value
Tag
Gets the tag.
public DicomTag Tag { get; }
Property Value
VR
Gets the value representation: the one the file wrote, or for implicit VR files the one PS3.6 gives the tag (UN for private and unknown tags).
public DicomVR VR { get; }
Property Value
Methods
GetDate()
Returns the first date of a Date (DA) value: YYYYMMDD, or the older YYYY.MM.DD.
public DateOnly? GetDate()
Returns
Exceptions
- InvalidOperationException
The VR is not DA.
- FormatException
The value is not a date.
GetDateTime()
Returns the first date and time of a Date Time (DT) value: YYYYMMDDHHMMSS.FFFFFF&ZZXX with trailing parts
optional. A value without its UTC offset (&ZZXX) is given offset zero.
public DateTimeOffset? GetDateTime()
Returns
- DateTimeOffset?
The date and time, or null when the value is empty.
Exceptions
- InvalidOperationException
The VR is not DT.
- FormatException
The value is not a date and time.
GetIntegers()
Returns the integers of an integer VR: integer strings (IS) parsed, and the binary integers of US, SS, UL, SL, UV, SV, OW, OL and OV. UV and OV values above MaxValue come back as their two's-complement bits.
public long[] GetIntegers()
Returns
- long[]
The integers; none when the value is empty.
Exceptions
- InvalidOperationException
The VR holds no integers.
- FormatException
An IS value is not an integer.
GetNumbers()
Returns the numbers of a numeric VR: decimal and integer strings (DS, IS) parsed, and the binary numbers of US, SS, UL, SL, UV, SV, FL, FD, OW, OL, OV, OF and OD.
public double[] GetNumbers()
Returns
- double[]
The numbers; none when the value is empty.
Exceptions
- InvalidOperationException
The VR holds no numbers.
- FormatException
A DS or IS value is not a number.
GetPersonName()
Returns the first name of a Person Name (PN) value.
public DicomPersonName? GetPersonName()
Returns
- DicomPersonName
The name, or null when the value is empty.
Exceptions
- InvalidOperationException
The VR is not PN.
GetString()
Returns the value as text: text VRs decoded by the dataset's Specific Character Set with trailing padding removed, every
value of a multi-valued string included with its </code> separators; numbers and tags of binary VRs written out the same
way, such as 512\512.
public string GetString()
Returns
- string
The value as text; empty when the value is empty.
Exceptions
- InvalidOperationException
The VR holds bytes or items, not values: OB, UN, SQ or encapsulated pixel data.
GetStrings()
Returns each value: a multi-valued string split at its </code> separators with padding removed, or each number or tag of
a binary VR written out. Long Text, Short Text, Unlimited Text and URIs are one value.
public IReadOnlyList<string> GetStrings()
Returns
- IReadOnlyList<string>
The values; none when the value is empty.
Exceptions
- InvalidOperationException
The VR holds bytes or items, not values: OB, UN, SQ or encapsulated pixel data.
GetTags()
Returns the tags of an Attribute Tag (AT) value.
public DicomTag[] GetTags()
Returns
- DicomTag[]
The tags; none when the value is empty.
Exceptions
- InvalidOperationException
The VR is not AT.
GetTime()
Returns the first time of a Time (TM) value: HHMMSS.FFFFFF with trailing parts optional, or the older HH:MM:SS.
public TimeOnly? GetTime()
Returns
Exceptions
- InvalidOperationException
The VR is not TM.
- FormatException
The value is not a time.
ToString()
Returns the element as a line of a dump, such as (0010,0010) PN PatientName: Doe^John.
public override string ToString()
Returns
- string
The element as text.