Created
December 17, 2020 12:14
-
-
Save Ch00k/c644556da5302881f672971f52eee2e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A trait, that implements common methods for all entity kinds | |
pub trait Entity { | |
/// Entity kind | |
fn kind(&self) -> EntityKind; | |
/// The ID of the entity | |
fn id(&self) -> &str; | |
/// The ID of the entity's parent ([`Patient`] for [`Study`], [`Study`] for [`Series`], | |
/// [`Series`] for [`Instance`]. [`None`] if the Entity does not have a parent (e.g. is a | |
/// [`Patient`]) | |
fn parent_id(&self) -> Option<&str> { | |
None | |
} | |
/// Get the value of a DICOM tag from `main_dicom_tags` | |
fn main_dicom_tag(&self, tag: &str) -> Option<&str>; | |
/// The list of ID of the entity's children (studies for [`Patient`], series for [`Study`], | |
/// instances for [`Series`]) | |
fn children(&self) -> &[String] { | |
&[] | |
} | |
/// Number of children that the entity has | |
fn children_len(&self) -> usize { | |
0 | |
} | |
/// Index of the instance in the series in case the entity is an [`Instance`], [`None`] | |
/// otherwise | |
fn index(&self) -> Option<u32> { | |
None | |
} | |
/// Size of the instance file in case the entity is an [`Instance`], [`None`] otherwise | |
fn size(&self) -> u64 { | |
0 | |
} | |
/// The kind of the entity's parent entity. [`None`] if the entity does not have a parent (e.g. | |
/// is a `Patient`) | |
fn parent_kind(&self) -> Option<EntityKind> { | |
None | |
} | |
/// The name of the entity's parent entity. [`None`] if the entity does not have a parent (e.g. | |
/// is a `Patient`) | |
fn parent_kind_name(&self) -> Option<String> { | |
match self.parent_kind() { | |
Some(k) => Some(format!("{:?}", k)), | |
None => None, | |
} | |
} | |
/// Then name of the entity's child entity, pluralized (e.g. "Studies", "Series", "Instances"). | |
/// [`None`] if the entity does not have children (e.g. is an [`Instance`]) | |
fn children_kind_name(&self) -> Option<&str> { | |
None | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment