Skip to main content

fhir_types/
definition.rs

1// @generated by fhir-codegen from hl7.fhir.r4.core 4.0.1, hl7.fhir.r4b.core 4.3.0, hl7.fhir.r5.core 5.0.0, hl7.fhir.r6.core 6.0.0-ballot5, hl7.fhir.r3.core 3.0.2. DO NOT EDIT.
2// Change the emitter (tools/fhir-codegen) and regenerate.
3// SPDX-FileCopyrightText: Cadasto B.V.
4// SPDX-License-Identifier: Apache-2.0
5//! A release-neutral read of `ElementDefinition` and `StructureDefinition`.
6//!
7//! A profile validator reads the same facts from an element definition of
8//! any release: the path, the cardinality, the types with their profiles,
9//! the binding, the fixed and pattern values, the constraints, the slicing
10//! and the content reference (<https://hl7.org/fhir/R4/elementdefinition.html>).
11//! The releases spell some of them differently. STU3 states one
12//! `type.profile` and one `type.targetProfile`, and its binding names the
13//! value set as `valueSetUri` or `valueSetReference`
14//! (<https://hl7.org/fhir/STU3/elementdefinition.html>); R4 and later state
15//! lists of canonicals and one `binding.valueSet`. Every version module
16//! implements [`ElementDefinitionRead`] for its own generated
17//! `ElementDefinition`, emitted from that version's package, so a single
18//! profile becomes a one-item list and either binding form becomes the value
19//! set's URL. A fact a release does not define reads as absent.
20//!
21//! The same holds for the `StructureDefinition` around the elements. STU3
22//! states an extension's context as one `contextType` and a list of `context`
23//! strings (<https://hl7.org/fhir/STU3/structuredefinition-definitions.html#StructureDefinition.contextType>);
24//! R4 states a list of `context` entries, each with its own `type` and
25//! `expression` (<https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.context>).
26//! Both read as a list of [`ContextRead`], the STU3 `contextType` beside each
27//! string. The type codes are each release's own and are not translated.
28//!
29//! Three facts are carried by an extension the core packages define: a
30//! binding's maximum value set
31//! (`http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet`),
32//! a constraint's best-practice flag
33//! (`http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice`)
34//! and a primitive type's lexical form
35//! (`http://hl7.org/fhir/StructureDefinition/regex`, which STU3 spells
36//! `http://hl7.org/fhir/StructureDefinition/structuredefinition-regex`). Each
37//! reads from the extension with that url where the element carries it, and
38//! as absent where it does not.
39//!
40//! A validator deciding a binding from the package set reads the
41//! `ValueSet`'s composition and expansion and the `CodeSystem`'s concepts
42//! (<https://hl7.org/fhir/R4/valueset.html>,
43//! <https://hl7.org/fhir/R4/codesystem.html>). STU3 names an imported value
44//! set as a `uri` and R4 as a `canonical`, and the releases differ in the
45//! value types a concept property takes. [`ValueSetRead`] and
46//! [`CodeSystemRead`] read them alike, a nested concept or expansion entry as
47//! the same type as its parent, and a property value in its JSON form.
48
49use super::codec::{EncodeError, Value};
50
51/// One `ElementDefinition.type` entry.
52#[derive(Debug, Clone, PartialEq, Eq)]
53pub struct TypeRead<'a> {
54    /// The type code (`type.code`).
55    pub code: Option<&'a str>,
56    /// The profiles the type is held to (`type.profile`), one item at most in
57    /// STU3.
58    pub profiles: Vec<&'a str>,
59    /// The profiles a reference target is held to (`type.targetProfile`),
60    /// one item at most in STU3.
61    pub target_profiles: Vec<&'a str>,
62    /// The aggregation modes of a reference (`type.aggregation`).
63    pub aggregation: Vec<&'a str>,
64    /// The versioning rule of a reference (`type.versioning`).
65    pub versioning: Option<&'a str>,
66    /// The lexical form a primitive type states in its `regex` extension, or
67    /// in STU3 its `structuredefinition-regex` extension.
68    pub regex: Option<&'a str>,
69}
70
71/// The `ElementDefinition.binding`.
72#[derive(Debug, Clone, PartialEq, Eq)]
73pub struct BindingRead<'a> {
74    /// The binding strength (`binding.strength`).
75    pub strength: Option<&'a str>,
76    /// The URL of the value set: `binding.valueSet` from R4, and in STU3
77    /// `valueSetUri` or the reference of `valueSetReference`.
78    pub value_set: Option<&'a str>,
79    /// The URL of the maximum value set its `elementdefinition-maxValueSet`
80    /// extension names.
81    pub max_value_set: Option<&'a str>,
82}
83
84/// One `ElementDefinition.constraint`.
85#[derive(Debug, Clone, PartialEq, Eq)]
86pub struct ConstraintRead<'a> {
87    /// The constraint key (`constraint.key`).
88    pub key: Option<&'a str>,
89    /// `error` or `warning` (`constraint.severity`).
90    pub severity: Option<&'a str>,
91    /// The description a person reads (`constraint.human`).
92    pub human: Option<&'a str>,
93    /// The FHIRPath expression (`constraint.expression`).
94    pub expression: Option<&'a str>,
95    /// The XPath expression (`constraint.xpath`), absent from R5.
96    pub xpath: Option<&'a str>,
97    /// The definition that first stated the constraint (`constraint.source`).
98    pub source: Option<&'a str>,
99    /// The boolean its `elementdefinition-bestpractice` extension states.
100    pub best_practice: Option<bool>,
101}
102
103/// One `ElementDefinition.slicing.discriminator`.
104#[derive(Debug, Clone, PartialEq, Eq)]
105pub struct DiscriminatorRead<'a> {
106    /// The discriminator type (`discriminator.type`).
107    pub kind: Option<&'a str>,
108    /// The path the discriminator reads (`discriminator.path`).
109    pub path: Option<&'a str>,
110}
111
112/// The `ElementDefinition.slicing`.
113#[derive(Debug, Clone, PartialEq, Eq)]
114pub struct SlicingRead<'a> {
115    /// The discriminators, in definition order.
116    pub discriminators: Vec<DiscriminatorRead<'a>>,
117    /// The description (`slicing.description`).
118    pub description: Option<&'a str>,
119    /// Whether the slices are ordered (`slicing.ordered`).
120    pub ordered: Option<bool>,
121    /// `closed`, `open` or `openAtEnd` (`slicing.rules`).
122    pub rules: Option<&'a str>,
123}
124
125/// A `fixed[x]` or `pattern[x]` value in its JSON form.
126#[derive(Debug, Clone, PartialEq, Eq)]
127pub struct ChoiceValue {
128    /// The type suffix of the member name, `Code` for `fixedCode`.
129    pub suffix: &'static str,
130    /// The JSON value of the member.
131    pub value: Option<Value>,
132    /// The `_` sibling a primitive value carries its `id` and extensions in.
133    pub element: Option<Value>,
134}
135
136/// The facts of an `ElementDefinition` a validator reads, the same in every
137/// release.
138pub trait ElementDefinitionRead {
139    /// The element id (`ElementDefinition.id`).
140    fn element_id(&self) -> Option<&str>;
141
142    /// The element path (`ElementDefinition.path`).
143    fn path(&self) -> Option<&str>;
144
145    /// The slice name (`ElementDefinition.sliceName`).
146    fn slice_name(&self) -> Option<&str>;
147
148    /// The minimum cardinality (`ElementDefinition.min`).
149    fn min(&self) -> Option<u32>;
150
151    /// The maximum cardinality as written, a number or `*`
152    /// (`ElementDefinition.max`).
153    fn max(&self) -> Option<&str>;
154
155    /// The longest string the element admits (`ElementDefinition.maxLength`).
156    fn max_length(&self) -> Option<i32>;
157
158    /// Whether the element modifies the meaning of its parent
159    /// (`ElementDefinition.isModifier`).
160    fn is_modifier(&self) -> Option<bool>;
161
162    /// The element whose definition this one reuses
163    /// (`ElementDefinition.contentReference`).
164    fn content_reference(&self) -> Option<&str>;
165
166    /// The types, in definition order (`ElementDefinition.type`).
167    fn types(&self) -> Vec<TypeRead<'_>>;
168
169    /// The binding (`ElementDefinition.binding`).
170    fn binding(&self) -> Option<BindingRead<'_>>;
171
172    /// The constraints, in definition order (`ElementDefinition.constraint`).
173    fn constraints(&self) -> Vec<ConstraintRead<'_>>;
174
175    /// The slicing (`ElementDefinition.slicing`).
176    fn slicing(&self) -> Option<SlicingRead<'_>>;
177
178    /// The fixed value (`ElementDefinition.fixed[x]`) in its JSON form.
179    ///
180    /// # Errors
181    ///
182    /// Returns [`EncodeError`] when the held value has no JSON form.
183    fn fixed(&self) -> Result<Option<ChoiceValue>, EncodeError>;
184
185    /// The pattern value (`ElementDefinition.pattern[x]`) in its JSON form.
186    ///
187    /// # Errors
188    ///
189    /// Returns [`EncodeError`] when the held value has no JSON form.
190    fn pattern(&self) -> Result<Option<ChoiceValue>, EncodeError>;
191}
192
193/// One context an extension may be used in.
194#[derive(Debug, Clone, PartialEq, Eq)]
195pub struct ContextRead<'a> {
196    /// The context type, in the release's own codes: STU3 `contextType`
197    /// (`resource`, `datatype`, `extension`), R4 and later `context.type`
198    /// (`fhirpath`, `element`, `extension`).
199    pub kind: Option<&'a str>,
200    /// The context: an STU3 `context` string, or R4 `context.expression`.
201    pub expression: Option<&'a str>,
202}
203
204/// The facts of a `StructureDefinition` a validator reads, the same in every
205/// release.
206pub trait StructureDefinitionRead {
207    /// The release's `ElementDefinition`.
208    type Element: ElementDefinitionRead;
209
210    /// The canonical URL (`StructureDefinition.url`).
211    fn url(&self) -> Option<&str>;
212
213    /// The business version (`StructureDefinition.version`).
214    fn version(&self) -> Option<&str>;
215
216    /// The type the definition constrains or defines
217    /// (`StructureDefinition.type`).
218    fn type_name(&self) -> Option<&str>;
219
220    /// The definition this one derives from
221    /// (`StructureDefinition.baseDefinition`).
222    fn base_definition(&self) -> Option<&str>;
223
224    /// `primitive-type`, `complex-type`, `resource` or `logical`
225    /// (`StructureDefinition.kind`).
226    fn kind(&self) -> Option<&str>;
227
228    /// Whether the type is abstract (`StructureDefinition.abstract`).
229    fn is_abstract(&self) -> Option<bool>;
230
231    /// `specialization` or `constraint` (`StructureDefinition.derivation`).
232    fn derivation(&self) -> Option<&str>;
233
234    /// The snapshot's elements in order, `None` without a snapshot
235    /// (`StructureDefinition.snapshot.element`).
236    fn snapshot(&self) -> Option<&[Self::Element]>;
237
238    /// The contexts an extension may be used in
239    /// (`StructureDefinition.context`).
240    fn contexts(&self) -> Vec<ContextRead<'_>>;
241
242    /// The FHIRPath rules about when an extension may be used
243    /// (`StructureDefinition.contextInvariant`).
244    fn context_invariants(&self) -> Vec<&str>;
245}
246
247/// One `ValueSet.compose.include.filter`.
248#[derive(Debug, Clone, PartialEq, Eq)]
249pub struct FilterRead<'a> {
250    /// The property filtered on (`filter.property`).
251    pub property: Option<&'a str>,
252    /// The operator (`filter.op`).
253    pub op: Option<&'a str>,
254    /// The value (`filter.value`).
255    pub value: Option<&'a str>,
256}
257
258/// One `ValueSet.compose.include` or `ValueSet.compose.exclude`.
259#[derive(Debug, Clone, PartialEq, Eq)]
260pub struct IncludeRead<'a> {
261    /// The code system the codes come from (`include.system`).
262    pub system: Option<&'a str>,
263    /// The code system version (`include.version`).
264    pub version: Option<&'a str>,
265    /// The codes it lists (`include.concept.code`).
266    pub concepts: Vec<&'a str>,
267    /// The filters it selects codes by (`include.filter`).
268    pub filters: Vec<FilterRead<'a>>,
269    /// The value sets it imports (`include.valueSet`): `uri`s in STU3,
270    /// canonicals from R4.
271    pub value_sets: Vec<&'a str>,
272}
273
274/// The `ValueSet.compose`.
275#[derive(Debug, Clone, PartialEq, Eq)]
276pub struct ComposeRead<'a> {
277    /// Whether inactive codes are in the value set (`compose.inactive`).
278    pub inactive: Option<bool>,
279    /// The includes, in order.
280    pub includes: Vec<IncludeRead<'a>>,
281    /// The excludes, in order.
282    pub excludes: Vec<IncludeRead<'a>>,
283}
284
285/// The `ValueSet.expansion`.
286#[derive(Debug, Clone, PartialEq, Eq)]
287pub struct ExpansionRead<'a, C> {
288    /// The number of concepts in the whole expansion (`expansion.total`).
289    pub total: Option<i32>,
290    /// Where this page of a paged expansion starts (`expansion.offset`).
291    pub offset: Option<i32>,
292    /// The entries (`expansion.contains`).
293    pub contains: &'a [C],
294}
295
296/// The facts of a `ValueSet` a validator reads, the same in every release.
297pub trait ValueSetRead {
298    /// The release's `ValueSet.expansion.contains`.
299    type Contains: ContainsRead;
300
301    /// The composition (`ValueSet.compose`).
302    fn compose(&self) -> Option<ComposeRead<'_>>;
303
304    /// The expansion (`ValueSet.expansion`).
305    fn expansion(&self) -> Option<ExpansionRead<'_, Self::Contains>>;
306}
307
308/// One `ValueSet.expansion.contains` entry.
309pub trait ContainsRead: Sized {
310    /// The code system (`contains.system`).
311    fn system(&self) -> Option<&str>;
312
313    /// The code system version (`contains.version`).
314    fn version(&self) -> Option<&str>;
315
316    /// The code (`contains.code`).
317    fn code(&self) -> Option<&str>;
318
319    /// Whether the entry is not selectable (`contains.abstract`).
320    fn is_abstract(&self) -> Option<bool>;
321
322    /// The nested entries (`contains.contains`).
323    fn contains(&self) -> &[Self];
324}
325
326/// One `CodeSystem.property` declaration.
327#[derive(Debug, Clone, PartialEq, Eq)]
328pub struct PropertyRead<'a> {
329    /// The code concepts use for it (`property.code`).
330    pub code: Option<&'a str>,
331    /// The URI that defines it (`property.uri`).
332    pub uri: Option<&'a str>,
333}
334
335/// One `CodeSystem.concept.property` value.
336#[derive(Debug, Clone, PartialEq, Eq)]
337pub struct ConceptPropertyRead<'a> {
338    /// The property code (`concept.property.code`).
339    pub code: Option<&'a str>,
340    /// The value in its JSON form (`concept.property.value[x]`).
341    pub value: Option<ChoiceValue>,
342}
343
344/// The facts of a `CodeSystem` a validator reads, the same in every release.
345pub trait CodeSystemRead {
346    /// The release's `CodeSystem.concept`.
347    type Concept: ConceptRead;
348
349    /// How much of the code system the resource carries
350    /// (`CodeSystem.content`).
351    fn content(&self) -> Option<&str>;
352
353    /// What the concept hierarchy means (`CodeSystem.hierarchyMeaning`).
354    fn hierarchy_meaning(&self) -> Option<&str>;
355
356    /// Whether codes compare case-sensitively (`CodeSystem.caseSensitive`).
357    fn case_sensitive(&self) -> Option<bool>;
358
359    /// The properties concepts may carry (`CodeSystem.property`).
360    fn properties(&self) -> Vec<PropertyRead<'_>>;
361
362    /// The top-level concepts (`CodeSystem.concept`).
363    fn concepts(&self) -> &[Self::Concept];
364}
365
366/// One `CodeSystem.concept`.
367pub trait ConceptRead: Sized {
368    /// The code (`concept.code`).
369    fn code(&self) -> Option<&str>;
370
371    /// The display (`concept.display`).
372    fn display(&self) -> Option<&str>;
373
374    /// The designation values (`concept.designation.value`).
375    fn designations(&self) -> Vec<&str>;
376
377    /// The property values (`concept.property`).
378    ///
379    /// # Errors
380    ///
381    /// Returns [`EncodeError`] when a value has no JSON form.
382    fn properties(&self) -> Result<Vec<ConceptPropertyRead<'_>>, EncodeError>;
383
384    /// The nested concepts (`concept.concept`).
385    fn concepts(&self) -> &[Self];
386}