Enet4 / dicom-rs

Rust implementation of the DICOM standard
https://dicom-rs.github.io
Apache License 2.0
404 stars 76 forks source link

Add attribute operations API #326

Closed Enet4 closed 1 year ago

Enet4 commented 1 year ago

This brings a new common API for applying specific changes to attributes in a DICOM object or object-like type. This has been implemented for all DICOM object types, namely InMemDicomObject, FileDicomObject and FileMetaTable.

Example of use:

use dicom_encoding::ops::{ApplyOp, AttributeAction, AttributeOp};

// given some DICOM object
let mut obj = open_file("I_00001.dcm")?;

// apply patient name change
obj.apply(AttributeOp {
  tag: tags::PATIENT_NAME,
  action: AttributeAction::ReplaceStr("Patient^Anonymous".into())
})?;
assert_eq!(
    obj.get(tags::PATIENT_NAME).unwrap().value().to_str().unwrap(),
    "Patient^Anonymous",
);

Summary