dicom_core/dictionary/
uid.rs1use std::str::FromStr;
4
5pub trait UidDictionary {
13 type Entry: UidDictionaryEntry;
15
16 fn by_keyword(&self, keyword: &str) -> Option<&Self::Entry>;
22
23 fn by_uid(&self, uid: &str) -> Option<&Self::Entry>;
25}
26
27pub trait UidDictionaryEntry {
29 fn uid(&self) -> &str;
31
32 fn name(&self) -> &str;
34
35 fn alias(&self) -> &str;
37
38 fn is_retired(&self) -> bool;
40}
41
42#[derive(Debug, PartialEq, Clone)]
45pub struct UidDictionaryEntryRef<'a> {
46 pub uid: &'a str,
48 pub name: &'a str,
51 pub alias: &'a str,
54 pub r#type: UidType,
56 pub retired: bool,
58}
59
60impl<'a> UidDictionaryEntryRef<'a> {
61 pub const fn new(
62 uid: &'a str,
63 name: &'a str,
64 alias: &'a str,
65 r#type: UidType,
66 retired: bool,
67 ) -> Self {
68 UidDictionaryEntryRef {
69 uid,
70 name,
71 alias,
72 r#type,
73 retired,
74 }
75 }
76}
77
78impl<'a> UidDictionaryEntry for UidDictionaryEntryRef<'a> {
79 fn uid(&self) -> &str {
80 self.uid
81 }
82
83 fn name(&self) -> &str {
84 self.name
85 }
86
87 fn alias(&self) -> &str {
88 self.alias
89 }
90
91 fn is_retired(&self) -> bool {
92 self.retired
93 }
94}
95
96#[non_exhaustive]
98#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq)]
99pub enum UidType {
100 SopClass,
102 MetaSopClass,
104 TransferSyntax,
106 WellKnownSopInstance,
108 DicomUidsAsCodingScheme,
110 CodingScheme,
112 ApplicationContextName,
114 ServiceClass,
116 ApplicationHostingModel,
118 MappingResource,
120 LdapOid,
122 SynchronizationFrameOfReference,
124}
125
126impl FromStr for UidType {
127 type Err = ();
128
129 fn from_str(s: &str) -> Result<Self, Self::Err> {
130 match s.trim() {
131 "SOP Class" => Ok(UidType::SopClass),
132 "Meta SOP Class" => Ok(UidType::MetaSopClass),
133 "Transfer Syntax" => Ok(UidType::TransferSyntax),
134 "Well-known SOP Instance" => Ok(UidType::WellKnownSopInstance),
135 "DICOM UIDs as a Coding Scheme" => Ok(UidType::DicomUidsAsCodingScheme),
136 "Coding Scheme" => Ok(UidType::CodingScheme),
137 "Application Context Name" => Ok(UidType::ApplicationContextName),
138 "Service Class" => Ok(UidType::ServiceClass),
139 "Application Hosting Model" => Ok(UidType::ApplicationHostingModel),
140 "Mapping Resource" => Ok(UidType::MappingResource),
141 "LDAP OID" => Ok(UidType::LdapOid),
142 "Synchronization Frame of Reference" => Ok(UidType::SynchronizationFrameOfReference),
143 _ => Err(()),
144 }
145 }
146}
147
148impl std::fmt::Display for UidType {
149 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
150 let str = match self {
151 UidType::SopClass => "SOP Class",
152 UidType::MetaSopClass => "Meta SOP Class",
153 UidType::TransferSyntax => "Transfer Syntax",
154 UidType::WellKnownSopInstance => "Well-known SOP Instance",
155 UidType::DicomUidsAsCodingScheme => "DICOM UIDs as a Coding Scheme",
156 UidType::CodingScheme => "Coding Scheme",
157 UidType::ApplicationContextName => "Application Context Name",
158 UidType::ServiceClass => "Service Class",
159 UidType::ApplicationHostingModel => "Application Hosting Modle",
160 UidType::MappingResource => "Mapping Resource",
161 UidType::LdapOid => "LDAP OID",
162 UidType::SynchronizationFrameOfReference => "Synchronization Frame of Reference",
163 };
164 f.write_str(str)
165 }
166}