View Source ExDicom.Updater (EX_DICOM v0.2.0)

Provides functions to update DICOM elements within an in-memory ExDicom.DataSet struct.

Summary

Functions

Removes the specified tag from the dataset. This operation deletes the element from the :elements map. Note that the old bytes remain in dataset.byte_array, so a subsequent re-parse from the original byte array will “restore” it. For a truly permanent removal, you must fully rewrite the dataset from the updated in-memory structure.

Updates (or inserts) a float value in the dataset.

Updates (or inserts) an integer value in the dataset.

Updates (or inserts) a string value in the DICOM dataset for the given tag.

Functions

remove_element(dataset, tag)

@spec remove_element(ExDicom.DataSet.t(), String.t()) :: ExDicom.DataSet.t()

Removes the specified tag from the dataset. This operation deletes the element from the :elements map. Note that the old bytes remain in dataset.byte_array, so a subsequent re-parse from the original byte array will “restore” it. For a truly permanent removal, you must fully rewrite the dataset from the updated in-memory structure.

Examples

iex> ds = ExDicom.Updater.remove_element(dataset, "x00100010")
%ExDicom.DataSet{ ... }

update_float_string(dataset, tag, float_value)

@spec update_float_string(ExDicom.DataSet.t(), String.t(), float()) ::
  ExDicom.DataSet.t()

Updates (or inserts) a float value in the dataset.

Uses Float.to_string/1 to store the float as text. Useful for VR like DS (Decimal String). You may want to format floats carefully for DICOM compliance (e.g., limiting precision).

Examples

iex> ds = ExDicom.Updater.update_float_string(dataset, "x00181020", 123.456)
%ExDicom.DataSet{ ... }

update_int_string(dataset, tag, int_value)

@spec update_int_string(ExDicom.DataSet.t(), String.t(), integer()) ::
  ExDicom.DataSet.t()

Updates (or inserts) an integer value in the dataset.

Converts the integer to a string before storing. This may be useful for VR types like IS (Integer String). If your logic needs strict VR handling, you may want separate functions for each VR, or an additional parameter.

Parameters

  • dataset - the ExDicom.DataSet struct
  • tag - a string DICOM tag
  • int_value - the integer value to store

Returns

  • Updated DataSet.t

Examples

iex> ds = ExDicom.Updater.update_int_string(dataset, "x00200013", 42)
%ExDicom.DataSet{ ... }

update_string(dataset, tag, new_value)

@spec update_string(ExDicom.DataSet.t(), String.t(), String.t()) ::
  ExDicom.DataSet.t()

Updates (or inserts) a string value in the DICOM dataset for the given tag.

The new_value is stored in the element’s :Value field. The old data_offset and length in the element become stale for the raw bytes, but if your DICOM writing logic honors the Value field, the updated text should be written out correctly.

Parameters

  • dataset - the ExDicom.DataSet struct
  • tag - a string (e.g., "x00100010") identifying the DICOM element
  • new_value - the new string value to store

Returns

  • An updated DataSet.t struct with the modified element.

Examples

iex> ds = ExDicom.Updater.update_string(dataset, "x00100010", "John^Doe")
%ExDicom.DataSet{ ... }