Skip to content

Commit

Permalink
Merge pull request #572 from Enet4/bug/pixeldata/transcode-update-met…
Browse files Browse the repository at this point in the history
…a-length

Update meta information group length in dicom-transcode + add FileDicomObject::update_meta
  • Loading branch information
Enet4 authored Oct 22, 2024
2 parents 287f84f + 0d0e366 commit c522fc1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
39 changes: 39 additions & 0 deletions object/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,26 @@ impl<O> FileDicomObject<O> {
///
/// Considerable care should be taken when modifying this table,
/// as it may influence object reading and writing operations.
/// When modifying the table through this method,
/// the user is responsible for updating the meta information group length as well,
/// which can be done by calling
/// [`update_information_group_length`](FileMetaTable::update_information_group_length).
///
/// See also [`update_meta`](Self::update_meta).
pub fn meta_mut(&mut self) -> &mut FileMetaTable {
&mut self.meta
}

/// Update the processed meta header table through a function.
///
/// Considerable care should be taken when modifying this table,
/// as it may influence object reading and writing operations.
/// The meta information group length is updated automatically.
pub fn update_meta(&mut self, f: impl FnOnce(&mut FileMetaTable)) {
f(&mut self.meta);
self.meta.update_information_group_length();
}

/// Retrieve the inner DICOM object structure, discarding the meta table.
pub fn into_inner(self) -> O {
self.obj
Expand Down Expand Up @@ -870,4 +886,27 @@ mod tests {
);
assert_eq!(iter.next(), None);
}

#[test]
pub fn file_dicom_can_update_meta() {
let meta = FileMetaTableBuilder::new()
.transfer_syntax(
dicom_transfer_syntax_registry::entries::EXPLICIT_VR_LITTLE_ENDIAN.uid(),
)
.media_storage_sop_class_uid("1.2.840.10008.5.1.4.1.1.1")
.media_storage_sop_instance_uid("2.25.280986007517028771599125034987786349815")
.implementation_class_uid("1.2.345.6.7890.1.234")
.build()
.unwrap();
let mut obj = FileDicomObject::new_empty_with_meta(meta);

obj.update_meta(|meta| {
meta.receiving_application_entity_title = Some("SOMETHING".to_string());
});

assert_eq!(
obj.meta().receiving_application_entity_title.as_deref(),
Some("SOMETHING"),
);
}
}
9 changes: 5 additions & 4 deletions pixeldata/src/bin/dicom-transcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ fn run() -> Result<(), Whatever> {

// override implementation class UID and version name
if !retain_implementation {
obj.meta_mut().implementation_class_uid =
dicom_object::IMPLEMENTATION_CLASS_UID.to_string();
obj.meta_mut().implementation_version_name =
Some(dicom_object::IMPLEMENTATION_VERSION_NAME.to_string());
obj.update_meta(|meta| {
meta.implementation_class_uid = dicom_object::IMPLEMENTATION_CLASS_UID.to_string();
meta.implementation_version_name =
Some(dicom_object::IMPLEMENTATION_VERSION_NAME.to_string());
});
}

// write to file
Expand Down

0 comments on commit c522fc1

Please sign in to comment.