fhirkit 0.1.0

FHIR R4 for Rust: typed models for every resource and datatype generated from the official specification, lossless JSON with path-precise validation, typed search queries, FHIRPath
Documentation
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `AllergyIntolerance` resource.

#![allow(
    unused_imports,
    clippy::large_enum_variant,
    clippy::too_many_lines,
    clippy::doc_markdown
)]

use crate::decode::{
    choice_key, required, required_list, resource_type, Choice, Decoder, FhirJson, Obj, ObjWriter,
};
use crate::json::Json;
use crate::primitive::{Decimal, Kind, Primitive};
use crate::r4::*;

/// Risk of harmful or undesirable, physiological response which is unique to an individual and associated with exposure to a substance.
///
/// FHIR path: `AllergyIntolerance`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AllergyIntolerance {
    /// `id` (0..1): Logical id of this artifact
    pub id: Option<String>,
    /// `meta` (0..1): Metadata about the resource
    pub meta: Option<Meta>,
    /// `implicitRules` (0..1): A set of rules under which this content was created
    pub implicit_rules: Option<Primitive<String>>,
    /// `language` (0..1): Language of the resource content
    pub language: Option<Primitive<String>>,
    /// `text` (0..1): Text summary of the resource, for human interpretation
    pub text: Option<Narrative>,
    /// `contained` (0..*): Contained, inline Resources
    pub contained: Vec<Resource>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored
    pub modifier_extension: Vec<Extension>,
    /// `identifier` (0..*): External ids for this item
    pub identifier: Vec<Identifier>,
    /// `clinicalStatus` (0..1): active | inactive | resolved
    pub clinical_status: Option<CodeableConcept>,
    /// `verificationStatus` (0..1): unconfirmed | confirmed | refuted | entered-in-error
    pub verification_status: Option<CodeableConcept>,
    /// `type` (0..1): allergy | intolerance - Underlying mechanism (if known)
    pub type_: Option<Primitive<String>>,
    /// `category` (0..*): food | medication | environment | biologic
    pub category: Vec<Primitive<String>>,
    /// `criticality` (0..1): low | high | unable-to-assess
    pub criticality: Option<Primitive<String>>,
    /// `code` (0..1): Code that identifies the allergy or intolerance
    pub code: Option<CodeableConcept>,
    /// `patient` (1..1): Who the sensitivity is for
    pub patient: Option<Reference>,
    /// `encounter` (0..1): Encounter when the allergy or intolerance was asserted
    pub encounter: Option<Reference>,
    /// `onset[x]` (0..1): When allergy or intolerance was identified
    pub onset: Option<AllergyIntoleranceOnset>,
    /// `recordedDate` (0..1): Date first version of the resource instance was recorded
    pub recorded_date: Option<Primitive<String>>,
    /// `recorder` (0..1): Who recorded the sensitivity
    pub recorder: Option<Reference>,
    /// `asserter` (0..1): Source of the information about the allergy
    pub asserter: Option<Reference>,
    /// `lastOccurrence` (0..1): Date(/time) of last known occurrence of a reaction
    pub last_occurrence: Option<Primitive<String>>,
    /// `note` (0..*): Additional text not captured in other fields
    pub note: Vec<Annotation>,
    /// `reaction` (0..*): Adverse Reaction Events linked to exposure to substance
    pub reaction: Vec<AllergyIntoleranceReaction>,
}

#[cfg(feature = "clinical")]
impl FhirJson for AllergyIntolerance {
    const TYPE_NAME: &'static str = "AllergyIntolerance";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "AllergyIntolerance");
        let r = AllergyIntolerance {
            id: o.string(d, "id"),
            meta: o.one(d, "meta"),
            implicit_rules: o.prim(d, "implicitRules", Kind::Uri),
            language: o.prim(d, "language", Kind::Code),
            text: o.one(d, "text"),
            contained: o.list(d, "contained"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            identifier: o.list(d, "identifier"),
            clinical_status: o.one(d, "clinicalStatus"),
            verification_status: o.one(d, "verificationStatus"),
            type_: o.prim(d, "type", Kind::Code),
            category: o.prim_list(d, "category", Kind::Code),
            criticality: o.prim(d, "criticality", Kind::Code),
            code: o.one(d, "code"),
            patient: o.one(d, "patient"),
            encounter: o.one(d, "encounter"),
            onset: o.choice(d, "onset"),
            recorded_date: o.prim(d, "recordedDate", Kind::DateTime),
            recorder: o.one(d, "recorder"),
            asserter: o.one(d, "asserter"),
            last_occurrence: o.prim(d, "lastOccurrence", Kind::DateTime),
            note: o.list(d, "note"),
            reaction: o.list(d, "reaction"),
        };
        required(d, "patient", &r.patient);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("AllergyIntolerance".into()));
        w.string("id", &self.id);
        w.one("meta", &self.meta);
        w.prim("implicitRules", &self.implicit_rules);
        w.prim("language", &self.language);
        w.one("text", &self.text);
        w.list("contained", &self.contained);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.list("identifier", &self.identifier);
        w.one("clinicalStatus", &self.clinical_status);
        w.one("verificationStatus", &self.verification_status);
        w.prim("type", &self.type_);
        w.prim_list("category", &self.category);
        w.prim("criticality", &self.criticality);
        w.one("code", &self.code);
        w.one("patient", &self.patient);
        w.one("encounter", &self.encounter);
        w.choice("onset", &self.onset);
        w.prim("recordedDate", &self.recorded_date);
        w.one("recorder", &self.recorder);
        w.one("asserter", &self.asserter);
        w.prim("lastOccurrence", &self.last_occurrence);
        w.list("note", &self.note);
        w.list("reaction", &self.reaction);
        w.finish()
    }
}

/// Adverse Reaction Events linked to exposure to substance
///
/// FHIR path: `AllergyIntolerance.reaction`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AllergyIntoleranceReaction {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `substance` (0..1): Specific substance or pharmaceutical product considered to be responsible for event
    pub substance: Option<CodeableConcept>,
    /// `manifestation` (1..*): Clinical symptoms/signs associated with the Event
    pub manifestation: Vec<CodeableConcept>,
    /// `description` (0..1): Description of the event as a whole
    pub description: Option<Primitive<String>>,
    /// `onset` (0..1): Date(/time) when manifestations showed
    pub onset: Option<Primitive<String>>,
    /// `severity` (0..1): mild | moderate | severe (of event as a whole)
    pub severity: Option<Primitive<String>>,
    /// `exposureRoute` (0..1): How the subject was exposed to the substance
    pub exposure_route: Option<CodeableConcept>,
    /// `note` (0..*): Text about event not captured in other fields
    pub note: Vec<Annotation>,
}

#[cfg(feature = "clinical")]
impl FhirJson for AllergyIntoleranceReaction {
    const TYPE_NAME: &'static str = "AllergyIntoleranceReaction";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = AllergyIntoleranceReaction {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            substance: o.one(d, "substance"),
            manifestation: o.list(d, "manifestation"),
            description: o.prim(d, "description", Kind::String),
            onset: o.prim(d, "onset", Kind::DateTime),
            severity: o.prim(d, "severity", Kind::Code),
            exposure_route: o.one(d, "exposureRoute"),
            note: o.list(d, "note"),
        };
        required_list(d, "manifestation", &r.manifestation, 1);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("substance", &self.substance);
        w.list("manifestation", &self.manifestation);
        w.prim("description", &self.description);
        w.prim("onset", &self.onset);
        w.prim("severity", &self.severity);
        w.one("exposureRoute", &self.exposure_route);
        w.list("note", &self.note);
        w.finish()
    }
}

/// The types `AllergyIntolerance.onset[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum AllergyIntoleranceOnset {
    /// `dateTime`
    DateTime(Primitive<String>),
    /// `Age`
    Age(Age),
    /// `Period`
    Period(Period),
    /// `Range`
    Range(Range),
    /// `string`
    String(Primitive<String>),
}

#[cfg(feature = "clinical")]
impl Choice for AllergyIntoleranceOnset {
    const TYPES: &'static [&'static str] = &["dateTime", "Age", "Period", "Range", "string"];

    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
        match code {
            "dateTime" => o.prim(d, key, Kind::DateTime).map(Self::DateTime),
            "Age" => o.one(d, key).map(Self::Age),
            "Period" => o.one(d, key).map(Self::Period),
            "Range" => o.one(d, key).map(Self::Range),
            "string" => o.prim(d, key, Kind::String).map(Self::String),
            _ => None,
        }
    }

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::DateTime(v) => w.prim_value(&choice_key(base, "dateTime"), v),
            Self::Age(v) => w.value(&choice_key(base, "Age"), v),
            Self::Period(v) => w.value(&choice_key(base, "Period"), v),
            Self::Range(v) => w.value(&choice_key(base, "Range"), v),
            Self::String(v) => w.prim_value(&choice_key(base, "string"), v),
        }
    }
}