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

Types

Index value to access an element inside a data set.

t()

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

key_type()

@type key_type() :: atom() | integer() | {integer(), integer()}

Index value to access an element inside a data set.

It can be either:

  1. an atom representing a known element keyword from the data dictionary,
  2. a 32-bit integer representing the tag or
  3. a tuple of 2 16-bit integers representing group and element of the tag respectively.

t()

@type t() :: %Dicom.DataSet{elements: term(), file_meta: term()}

Functions

empty()

@spec empty() :: t()

Create an empty data set.

Examples

iex> DataSet.empty()

fetch(ds, key)

@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)

fetch!(ds, key)

@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)

file_meta(data_set)

@spec file_meta(t()) :: t()

Access file_meta of a data set.

Returns an empty data set if no file_meta exists.

from_elements(elements)

@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()

from_keyword_list(value_list)

@spec from_keyword_list([{atom(), any()}]) :: t()

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")

has_key?(data_set, key)

@spec has_key?(t(), key_type()) :: boolean()

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

put(data_set, key, value_representation, values)

@spec put(t(), key_type(), atom(), [any()]) :: t()

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"

put_default(data_set, key, value_representation, values)

@spec put_default(t(), key_type(), atom(), [any()]) :: t()

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"

value_for!(ds, key, index \\ 0)

@spec value_for!(t(), key_type(), integer()) :: any()

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"

with_file_meta_from_keywords(data_set, meta_attributes)

@spec with_file_meta_from_keywords(t(), [{atom(), any()}]) :: t()

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"

with_transfer_syntax(data_set, transfer_syntax_name)

@spec with_transfer_syntax(t(), atom()) :: t()

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"