View Source Dicom.DataSet (Dicom.ex v0.3.0)
A DICOM data set is a collection of Dicom.DataElements uniquely identified by their numeric tags.
Summary
Functions
Create an empty data set.
Fetches the Dicom.DataElement identified by key from the ds.
Fetches the Dicom.DataElement for key from ds, erroring out if it does not exist.
Access file_meta of a data set.
Create a data set from a enumerable of Dicom.DataElements.
Create a data set from a keyword-value mapping.
Checks if data_set contains an element key.
Updates element identified by key in data_set.
Set a default value for key in data_set if there is no existing value.
Fetches the value of the data element identified by key.
Add file_meta to dataset by the meta_attributes keyword list.
Add transfer syntax by transfer_syntax_name to file_meta of data_set.
Types
Index value to access an element inside a data set.
It can be either:
- an atom representing a known element keyword from the data dictionary,
- a 32-bit integer representing the tag or
- a tuple of 2 16-bit integers representing group and element of the tag respectively.
Functions
@spec empty() :: t()
Create an empty data set.
Examples
iex> DataSet.empty()
@spec fetch(t(), key_type()) :: {:ok, Dicom.DataElement.t()} | {:error, atom()}
Fetches the Dicom.DataElement identified by key from the ds.
If ds contains the element, it is returned in the shape of {:ok, element}. If not,
the atom :error is returned instead.
Examples
iex> ds = DataSet.from_keyword_list(PatientID: "JDOE123")
iex> {:ok, _element} = DataSet.fetch(ds, :PatientID)
iex> {:ok, _element} = DataSet.fetch(ds, {0x0010, 0x0020})
iex> {:ok, _element} = DataSet.fetch(ds, 0x00100020)
iex> :error = DataSet.fetch(ds, :StudyID)
@spec fetch!(t(), key_type()) :: Dicom.DataElement.t()
Fetches the Dicom.DataElement for key from ds, erroring out if it does not exist.
If ds contains key, the Dicom.DataElement is returned. If not,
a KeyError exception is raised.
Examples
iex> ds = DataSet.from_keyword_list(PatientID: "JDOE123")
iex> _element = DataSet.fetch!(ds, :PatientID)
Access file_meta of a data set.
Returns an empty data set if no file_meta exists.
@spec from_elements(Enumerable.t(Dicom.DataElement.t())) :: t()
Create a data set from a enumerable of Dicom.DataElements.
Examples
iex> (for i <- 1..3, do: Dicom.DataElement.from(0x0021, i, :US, i))
...> |> Dicom.DataSet.from_elements()
Create a data set from a keyword-value mapping.
All keywords must be contained in the data dictionary.
Examples
iex> Dicom.DataSet.from_keyword_list(PatientID: "JDOE123", PatientName: "Doe^John")
Checks if data_set contains an element key.
Examples
iex> ds = DataSet.from_keyword_list(StudyID: "1.2.3")
iex> DataSet.has_key?(ds, :StudyID)
true
iex> DataSet.has_key?(ds, :PatientID)
false
Updates element identified by key in data_set.
The element identified by key is updated to value_representation
and values. If key already exists, it is overridden.
Returns the updated data set.
Examples
iex> ds = DataSet.empty()
...> |> DataSet.put(:SOPInstanceUID, :UI, ["1.2.3"])
iex> DataSet.value_for!(ds, :SOPInstanceUID)
"1.2.3"
Set a default value for key in data_set if there is no existing value.
Examples
iex> ds = DataSet.from_keyword_list(StudyID: "1.2.3")
iex> ds = ds
...> |> DataSet.put_default(:PatientID, :SH, ["PAT123"])
...> |> DataSet.put_default(:StudyID, :SH, ["already_set"])
iex> DataSet.value_for!(ds, :PatientID)
"PAT123"
iex> DataSet.value_for!(ds, :StudyID)
"1.2.3"
Fetches the value of the data element identified by key.
This is a shortcut to directly access a specific value. If the
data element has a value multiplicity > 1, a specific index can
be accessed with the index parameter.
Examples
iex> ds = DataSet.from_keyword_list(OtherPatientNames: ["Max", "Tom"])
iex> DataSet.value_for!(ds, :OtherPatientNames, 1)
"Tom"
Add file_meta to dataset by the meta_attributes keyword list.
Examples
iex> ds = DataSet.from_keyword_list(SOPInstanceUID: "1.2.3")
...> |> DataSet.with_file_meta_from_keywords(TransferSyntaxUID: "1.2.840.10008.1.2.1")
iex> ds
...> |> DataSet.file_meta()
...> |> DataSet.value_for!(:TransferSyntaxUID)
"1.2.840.10008.1.2.1"
Add transfer syntax by transfer_syntax_name to file_meta of data_set.
Examples
iex> ds = DataSet.empty()
...> |> DataSet.with_transfer_syntax(:explicit_vr_little_endian)
iex> ds
...> |> DataSet.file_meta()
...> |> DataSet.value_for!(:TransferSyntaxUID)
"1.2.840.10008.1.2.1"