Skip to main content

fhir_model/
concepts.rs

1//! Implementations on `Coding`s and `CodeableConcept`s.
2
3use crate::for_all_versions;
4
5/// Implement functions on `CodeableConcept`s.
6macro_rules! impl_codeable_concept {
7	($version:ident) => {
8		mod $version {
9			use $crate::$version::types::CodeableConcept;
10
11			impl CodeableConcept {
12				/// Get all codes matching a specific system.
13				pub fn codes_with_system<'a, 'b>(
14					&'a self,
15					system: &'b str,
16				) -> impl Iterator<Item = &'a str> + Send + 'b
17				where
18					'a: 'b,
19				{
20					self.coding
21						.iter()
22						.flatten()
23						.filter(|coding| coding.system.as_deref() == Some(system))
24						.filter_map(|coding| coding.code.as_deref())
25				}
26
27				/// Get the first code matching a specific system.
28				#[must_use]
29				pub fn code_with_system<'a>(&'a self, system: &str) -> Option<&'a str> {
30					self.codes_with_system(system).next()
31				}
32			}
33		}
34	};
35}
36for_all_versions!(impl_codeable_concept);