fhir-types 0.1.126

Generated per-version FHIR types and terminology operation contracts
Documentation
// @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.
// Change the emitter (tools/fhir-codegen) and regenerate.
// SPDX-FileCopyrightText: Cadasto B.V.
// SPDX-License-Identifier: Apache-2.0
//! A release-neutral read of `ElementDefinition` and `StructureDefinition`.
//!
//! A profile validator reads the same facts from an element definition of
//! any release: the path, the cardinality, the types with their profiles,
//! the binding, the fixed and pattern values, the constraints, the slicing
//! and the content reference (<https://hl7.org/fhir/R4/elementdefinition.html>).
//! The releases spell some of them differently. STU3 states one
//! `type.profile` and one `type.targetProfile`, and its binding names the
//! value set as `valueSetUri` or `valueSetReference`
//! (<https://hl7.org/fhir/STU3/elementdefinition.html>); R4 and later state
//! lists of canonicals and one `binding.valueSet`. Every version module
//! implements [`ElementDefinitionRead`] for its own generated
//! `ElementDefinition`, emitted from that version's package, so a single
//! profile becomes a one-item list and either binding form becomes the value
//! set's URL. A fact a release does not define reads as absent.
//!
//! The same holds for the `StructureDefinition` around the elements. STU3
//! states an extension's context as one `contextType` and a list of `context`
//! strings (<https://hl7.org/fhir/STU3/structuredefinition-definitions.html#StructureDefinition.contextType>);
//! R4 states a list of `context` entries, each with its own `type` and
//! `expression` (<https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.context>).
//! Both read as a list of [`ContextRead`], the STU3 `contextType` beside each
//! string. The type codes are each release's own and are not translated.
//!
//! Three facts are carried by an extension the core packages define: a
//! binding's maximum value set
//! (`http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet`),
//! a constraint's best-practice flag
//! (`http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice`)
//! and a primitive type's lexical form
//! (`http://hl7.org/fhir/StructureDefinition/regex`, which STU3 spells
//! `http://hl7.org/fhir/StructureDefinition/structuredefinition-regex`). Each
//! reads from the extension with that url where the element carries it, and
//! as absent where it does not.
//!
//! A validator deciding a binding from the package set reads the
//! `ValueSet`'s composition and expansion and the `CodeSystem`'s concepts
//! (<https://hl7.org/fhir/R4/valueset.html>,
//! <https://hl7.org/fhir/R4/codesystem.html>). STU3 names an imported value
//! set as a `uri` and R4 as a `canonical`, and the releases differ in the
//! value types a concept property takes. [`ValueSetRead`] and
//! [`CodeSystemRead`] read them alike, a nested concept or expansion entry as
//! the same type as its parent, and a property value in its JSON form.

use super::codec::{EncodeError, Value};

/// One `ElementDefinition.type` entry.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TypeRead<'a> {
    /// The type code (`type.code`).
    pub code: Option<&'a str>,
    /// The profiles the type is held to (`type.profile`), one item at most in
    /// STU3.
    pub profiles: Vec<&'a str>,
    /// The profiles a reference target is held to (`type.targetProfile`),
    /// one item at most in STU3.
    pub target_profiles: Vec<&'a str>,
    /// The aggregation modes of a reference (`type.aggregation`).
    pub aggregation: Vec<&'a str>,
    /// The versioning rule of a reference (`type.versioning`).
    pub versioning: Option<&'a str>,
    /// The lexical form a primitive type states in its `regex` extension, or
    /// in STU3 its `structuredefinition-regex` extension.
    pub regex: Option<&'a str>,
}

/// The `ElementDefinition.binding`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BindingRead<'a> {
    /// The binding strength (`binding.strength`).
    pub strength: Option<&'a str>,
    /// The URL of the value set: `binding.valueSet` from R4, and in STU3
    /// `valueSetUri` or the reference of `valueSetReference`.
    pub value_set: Option<&'a str>,
    /// The URL of the maximum value set its `elementdefinition-maxValueSet`
    /// extension names.
    pub max_value_set: Option<&'a str>,
}

/// One `ElementDefinition.constraint`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConstraintRead<'a> {
    /// The constraint key (`constraint.key`).
    pub key: Option<&'a str>,
    /// `error` or `warning` (`constraint.severity`).
    pub severity: Option<&'a str>,
    /// The description a person reads (`constraint.human`).
    pub human: Option<&'a str>,
    /// The FHIRPath expression (`constraint.expression`).
    pub expression: Option<&'a str>,
    /// The XPath expression (`constraint.xpath`), absent from R5.
    pub xpath: Option<&'a str>,
    /// The definition that first stated the constraint (`constraint.source`).
    pub source: Option<&'a str>,
    /// The boolean its `elementdefinition-bestpractice` extension states.
    pub best_practice: Option<bool>,
}

/// One `ElementDefinition.slicing.discriminator`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DiscriminatorRead<'a> {
    /// The discriminator type (`discriminator.type`).
    pub kind: Option<&'a str>,
    /// The path the discriminator reads (`discriminator.path`).
    pub path: Option<&'a str>,
}

/// The `ElementDefinition.slicing`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SlicingRead<'a> {
    /// The discriminators, in definition order.
    pub discriminators: Vec<DiscriminatorRead<'a>>,
    /// The description (`slicing.description`).
    pub description: Option<&'a str>,
    /// Whether the slices are ordered (`slicing.ordered`).
    pub ordered: Option<bool>,
    /// `closed`, `open` or `openAtEnd` (`slicing.rules`).
    pub rules: Option<&'a str>,
}

/// A `fixed[x]` or `pattern[x]` value in its JSON form.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ChoiceValue {
    /// The type suffix of the member name, `Code` for `fixedCode`.
    pub suffix: &'static str,
    /// The JSON value of the member.
    pub value: Option<Value>,
    /// The `_` sibling a primitive value carries its `id` and extensions in.
    pub element: Option<Value>,
}

/// The facts of an `ElementDefinition` a validator reads, the same in every
/// release.
pub trait ElementDefinitionRead {
    /// The element id (`ElementDefinition.id`).
    fn element_id(&self) -> Option<&str>;

    /// The element path (`ElementDefinition.path`).
    fn path(&self) -> Option<&str>;

    /// The slice name (`ElementDefinition.sliceName`).
    fn slice_name(&self) -> Option<&str>;

    /// The minimum cardinality (`ElementDefinition.min`).
    fn min(&self) -> Option<u32>;

    /// The maximum cardinality as written, a number or `*`
    /// (`ElementDefinition.max`).
    fn max(&self) -> Option<&str>;

    /// The longest string the element admits (`ElementDefinition.maxLength`).
    fn max_length(&self) -> Option<i32>;

    /// Whether the element modifies the meaning of its parent
    /// (`ElementDefinition.isModifier`).
    fn is_modifier(&self) -> Option<bool>;

    /// The element whose definition this one reuses
    /// (`ElementDefinition.contentReference`).
    fn content_reference(&self) -> Option<&str>;

    /// The types, in definition order (`ElementDefinition.type`).
    fn types(&self) -> Vec<TypeRead<'_>>;

    /// The binding (`ElementDefinition.binding`).
    fn binding(&self) -> Option<BindingRead<'_>>;

    /// The constraints, in definition order (`ElementDefinition.constraint`).
    fn constraints(&self) -> Vec<ConstraintRead<'_>>;

    /// The slicing (`ElementDefinition.slicing`).
    fn slicing(&self) -> Option<SlicingRead<'_>>;

    /// The fixed value (`ElementDefinition.fixed[x]`) in its JSON form.
    ///
    /// # Errors
    ///
    /// Returns [`EncodeError`] when the held value has no JSON form.
    fn fixed(&self) -> Result<Option<ChoiceValue>, EncodeError>;

    /// The pattern value (`ElementDefinition.pattern[x]`) in its JSON form.
    ///
    /// # Errors
    ///
    /// Returns [`EncodeError`] when the held value has no JSON form.
    fn pattern(&self) -> Result<Option<ChoiceValue>, EncodeError>;
}

/// One context an extension may be used in.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ContextRead<'a> {
    /// The context type, in the release's own codes: STU3 `contextType`
    /// (`resource`, `datatype`, `extension`), R4 and later `context.type`
    /// (`fhirpath`, `element`, `extension`).
    pub kind: Option<&'a str>,
    /// The context: an STU3 `context` string, or R4 `context.expression`.
    pub expression: Option<&'a str>,
}

/// The facts of a `StructureDefinition` a validator reads, the same in every
/// release.
pub trait StructureDefinitionRead {
    /// The release's `ElementDefinition`.
    type Element: ElementDefinitionRead;

    /// The canonical URL (`StructureDefinition.url`).
    fn url(&self) -> Option<&str>;

    /// The business version (`StructureDefinition.version`).
    fn version(&self) -> Option<&str>;

    /// The type the definition constrains or defines
    /// (`StructureDefinition.type`).
    fn type_name(&self) -> Option<&str>;

    /// The definition this one derives from
    /// (`StructureDefinition.baseDefinition`).
    fn base_definition(&self) -> Option<&str>;

    /// `primitive-type`, `complex-type`, `resource` or `logical`
    /// (`StructureDefinition.kind`).
    fn kind(&self) -> Option<&str>;

    /// Whether the type is abstract (`StructureDefinition.abstract`).
    fn is_abstract(&self) -> Option<bool>;

    /// `specialization` or `constraint` (`StructureDefinition.derivation`).
    fn derivation(&self) -> Option<&str>;

    /// The snapshot's elements in order, `None` without a snapshot
    /// (`StructureDefinition.snapshot.element`).
    fn snapshot(&self) -> Option<&[Self::Element]>;

    /// The contexts an extension may be used in
    /// (`StructureDefinition.context`).
    fn contexts(&self) -> Vec<ContextRead<'_>>;

    /// The FHIRPath rules about when an extension may be used
    /// (`StructureDefinition.contextInvariant`).
    fn context_invariants(&self) -> Vec<&str>;
}

/// One `ValueSet.compose.include.filter`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FilterRead<'a> {
    /// The property filtered on (`filter.property`).
    pub property: Option<&'a str>,
    /// The operator (`filter.op`).
    pub op: Option<&'a str>,
    /// The value (`filter.value`).
    pub value: Option<&'a str>,
}

/// One `ValueSet.compose.include` or `ValueSet.compose.exclude`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IncludeRead<'a> {
    /// The code system the codes come from (`include.system`).
    pub system: Option<&'a str>,
    /// The code system version (`include.version`).
    pub version: Option<&'a str>,
    /// The codes it lists (`include.concept.code`).
    pub concepts: Vec<&'a str>,
    /// The filters it selects codes by (`include.filter`).
    pub filters: Vec<FilterRead<'a>>,
    /// The value sets it imports (`include.valueSet`): `uri`s in STU3,
    /// canonicals from R4.
    pub value_sets: Vec<&'a str>,
}

/// The `ValueSet.compose`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ComposeRead<'a> {
    /// Whether inactive codes are in the value set (`compose.inactive`).
    pub inactive: Option<bool>,
    /// The includes, in order.
    pub includes: Vec<IncludeRead<'a>>,
    /// The excludes, in order.
    pub excludes: Vec<IncludeRead<'a>>,
}

/// The `ValueSet.expansion`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExpansionRead<'a, C> {
    /// The number of concepts in the whole expansion (`expansion.total`).
    pub total: Option<i32>,
    /// Where this page of a paged expansion starts (`expansion.offset`).
    pub offset: Option<i32>,
    /// The entries (`expansion.contains`).
    pub contains: &'a [C],
}

/// The facts of a `ValueSet` a validator reads, the same in every release.
pub trait ValueSetRead {
    /// The release's `ValueSet.expansion.contains`.
    type Contains: ContainsRead;

    /// The composition (`ValueSet.compose`).
    fn compose(&self) -> Option<ComposeRead<'_>>;

    /// The expansion (`ValueSet.expansion`).
    fn expansion(&self) -> Option<ExpansionRead<'_, Self::Contains>>;
}

/// One `ValueSet.expansion.contains` entry.
pub trait ContainsRead: Sized {
    /// The code system (`contains.system`).
    fn system(&self) -> Option<&str>;

    /// The code system version (`contains.version`).
    fn version(&self) -> Option<&str>;

    /// The code (`contains.code`).
    fn code(&self) -> Option<&str>;

    /// Whether the entry is not selectable (`contains.abstract`).
    fn is_abstract(&self) -> Option<bool>;

    /// The nested entries (`contains.contains`).
    fn contains(&self) -> &[Self];
}

/// One `CodeSystem.property` declaration.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PropertyRead<'a> {
    /// The code concepts use for it (`property.code`).
    pub code: Option<&'a str>,
    /// The URI that defines it (`property.uri`).
    pub uri: Option<&'a str>,
}

/// One `CodeSystem.concept.property` value.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConceptPropertyRead<'a> {
    /// The property code (`concept.property.code`).
    pub code: Option<&'a str>,
    /// The value in its JSON form (`concept.property.value[x]`).
    pub value: Option<ChoiceValue>,
}

/// The facts of a `CodeSystem` a validator reads, the same in every release.
pub trait CodeSystemRead {
    /// The release's `CodeSystem.concept`.
    type Concept: ConceptRead;

    /// How much of the code system the resource carries
    /// (`CodeSystem.content`).
    fn content(&self) -> Option<&str>;

    /// What the concept hierarchy means (`CodeSystem.hierarchyMeaning`).
    fn hierarchy_meaning(&self) -> Option<&str>;

    /// Whether codes compare case-sensitively (`CodeSystem.caseSensitive`).
    fn case_sensitive(&self) -> Option<bool>;

    /// The properties concepts may carry (`CodeSystem.property`).
    fn properties(&self) -> Vec<PropertyRead<'_>>;

    /// The top-level concepts (`CodeSystem.concept`).
    fn concepts(&self) -> &[Self::Concept];
}

/// One `CodeSystem.concept`.
pub trait ConceptRead: Sized {
    /// The code (`concept.code`).
    fn code(&self) -> Option<&str>;

    /// The display (`concept.display`).
    fn display(&self) -> Option<&str>;

    /// The designation values (`concept.designation.value`).
    fn designations(&self) -> Vec<&str>;

    /// The property values (`concept.property`).
    ///
    /// # Errors
    ///
    /// Returns [`EncodeError`] when a value has no JSON form.
    fn properties(&self) -> Result<Vec<ConceptPropertyRead<'_>>, EncodeError>;

    /// The nested concepts (`concept.concept`).
    fn concepts(&self) -> &[Self];
}