dicom_anonymization::config

Struct ConfigBuilder

Source
pub struct ConfigBuilder(/* private fields */);
Expand description

A builder for Config to configure DICOM de-identification settings.

The builder provides methods to customize various aspects of de-identification, including:

  • Setting the UID root prefix for generating UIDs
  • Configuring actions for specific DICOM tags
  • Setting policies for private tags, curves, and overlays

§Example

use dicom_anonymization::config::ConfigBuilder;
use dicom_anonymization::actions::Action;
use dicom_dictionary_std::tags;

let config = ConfigBuilder::new()
    .uid_root("1.2.840.123".parse().unwrap())
    .tag_action(tags::PATIENT_NAME, Action::Empty)
    .tag_action(tags::PATIENT_ID, Action::Hash(None))
    .remove_private_tags(true)
    .build();

Implementations§

Source§

impl ConfigBuilder

Source

pub fn new() -> Self

Source

pub fn uid_root(self, uid_root: UidRoot) -> Self

Sets the UID root for the configuration.

The UidRoot provides the prefix that will be used when creating new UIDs with Action::HashUID. It must follow DICOM UID format rules: start with a digit 1-9 and contain only numbers and dots. It must also have no more than 32 characters.

Setting it is optional. In that case, no specific UID prefix will be used when creating new UIDs.

§Example
use dicom_anonymization::config::ConfigBuilder;

let config = ConfigBuilder::new()
    .uid_root("1.2.840.123".parse().unwrap())
    .build();
Source

pub fn tag_action(self, tag: Tag, action: Action) -> Self

Sets the action to take for a specific DICOM tag.

The action determines how the tag value will be handled during de-identification.

§Arguments
  • tag - The DICOM tag to apply the action to
  • action - The Action to take
§Examples
use dicom_anonymization::actions::{Action, HashLength};
use dicom_anonymization::config::ConfigBuilder;
use dicom_dictionary_std::tags;

let mut config_builder = ConfigBuilder::new();

// Keep the tag value unchanged
config_builder = config_builder.tag_action(tags::MODALITY, Action::Keep);

// Remove the tag completely
config_builder = config_builder.tag_action(tags::SERIES_DATE, Action::Remove);

// Replace with empty value
config_builder = config_builder.tag_action(tags::PATIENT_SEX, Action::Empty);

// Hash the value with specified length
config_builder = config_builder.tag_action(tags::PATIENT_ID, Action::Hash(Some(HashLength::new(10).unwrap())));

// Hash a UID
config_builder = config_builder.tag_action(tags::STUDY_INSTANCE_UID, Action::HashUID);

// Replace a date with another date using a hash of another tag value to determine the offset
config_builder = config_builder.tag_action(tags::STUDY_DATE, Action::HashDate(tags::PATIENT_ID));

// Replace with specific value
config_builder = config_builder.tag_action(tags::DEIDENTIFICATION_METHOD, Action::Replace("MYAPP".into()));

// No specific tag action
//
// Mainly for documentation purposes to show that certain tags were considered, but
// that no specific tag actions are applied to those.
config_builder = config_builder.tag_action(tags::IMAGE_TYPE, Action::None);
Source

pub fn remove_private_tags(self, remove: bool) -> Self

Controls whether private DICOM tags will be removed during de-identification.

Private DICOM tags are those with odd group numbers. This function configures whether these tags should be removed or preserved.

By default (i.e. if not explicitly set to false) all private tags will be removed. If enabled, individual private tags can still be kept by setting a specific tag Action for those (except Action::None).

§Arguments
  • remove - If true, all private tags will be removed. If false, they will be kept.
§Examples
use dicom_anonymization::config::ConfigBuilder;

// Remove private tags (default)
let config = ConfigBuilder::new()
    .remove_private_tags(true)
    .build();

// Keep private tags
let config = ConfigBuilder::new()
    .remove_private_tags(false)
    .build();
Source

pub fn remove_curves(self, remove: bool) -> Self

Controls whether DICOM curve tags (from groups 0x5000-0x50FF) will be removed during de-identification.

By default (i.e. if not explicitly set to false) all curve tags will be removed. If enabled, individual curve tags can still be kept by setting a specific tag Action for those (except Action::None).

§Arguments
  • remove - If true, all curve tags will be removed. If false, they will be kept.
§Examples
use dicom_anonymization::config::ConfigBuilder;

// Remove curve tags (default)
let config = ConfigBuilder::new()
    .remove_curves(true)
    .build();

// Keep curve tags
let config = ConfigBuilder::new()
    .remove_curves(false)
    .build();
Source

pub fn remove_overlays(self, remove: bool) -> Self

Controls whether DICOM overlay tags (from groups 0x6000-0x60FF) will be removed during de-identification.

By default (i.e. if not explicitly set to false) all overlay tags will be removed. If enabled, individual overlay tags can still be kept by setting a specific tag Action for those (except Action::None).

§Arguments
  • remove - If true, all overlay tags will be removed. If false, they will be kept.
§Examples
use dicom_anonymization::config::ConfigBuilder;

// Remove overlay tags (default)
let config = ConfigBuilder::new()
    .remove_overlays(true)
    .build();

// Keep overlay tags
let config = ConfigBuilder::new()
    .remove_overlays(false)
    .build();
Source

pub fn build(self) -> Config

Transforms the ConfigBuilder into a Config with all configured options.

§Example
use dicom_anonymization::config::ConfigBuilder;
use dicom_anonymization::actions::Action;
use dicom_core::Tag;
use dicom_dictionary_std::tags;

let config = ConfigBuilder::new()
    .uid_root("1.2.840.123".parse().unwrap())
    .tag_action(tags::SOP_INSTANCE_UID, Action::HashUID)
    .tag_action(tags::PATIENT_NAME, Action::Empty)
    .tag_action(Tag(0x0033, 0x0010), Action::Keep)
    .build();

Trait Implementations§

Source§

impl Default for ConfigBuilder

Source§

fn default() -> Self

Creates a new ConfigBuilder with the default configuration.

The default configuration includes a standard set of tag actions for DICOM de-identification, as well as default settings for removing private tags, curves, and overlays. Also, a default UidRoot value is used (i.e. "9999").

Returns a ConfigBuilder initialized with these default settings, which can be further customized if needed before building the final Config.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more