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 `MedicinalProductInteraction` 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::*;

/// The interactions of the medicinal product with other medicinal products, or other forms of interactions.
///
/// FHIR path: `MedicinalProductInteraction`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProductInteraction {
    /// `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>,
    /// `subject` (0..*): The medication for which this is a described interaction
    pub subject: Vec<Reference>,
    /// `description` (0..1): The interaction described
    pub description: Option<Primitive<String>>,
    /// `interactant` (0..*): The specific medication, food or laboratory test that interacts
    pub interactant: Vec<MedicinalProductInteractionInteractant>,
    /// `type` (0..1): The type of the interaction e.g. drug-drug interaction, drug-food interaction, drug-lab test interaction
    pub type_: Option<CodeableConcept>,
    /// `effect` (0..1): The effect of the interaction, for example "reduced gastric absorption of primary medication"
    pub effect: Option<CodeableConcept>,
    /// `incidence` (0..1): The incidence of the interaction, e.g. theoretical, observed
    pub incidence: Option<CodeableConcept>,
    /// `management` (0..1): Actions for managing the interaction
    pub management: Option<CodeableConcept>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "MedicinalProductInteraction");
        let r = MedicinalProductInteraction {
            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"),
            subject: o.list(d, "subject"),
            description: o.prim(d, "description", Kind::String),
            interactant: o.list(d, "interactant"),
            type_: o.one(d, "type"),
            effect: o.one(d, "effect"),
            incidence: o.one(d, "incidence"),
            management: o.one(d, "management"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw(
            "resourceType",
            Json::String("MedicinalProductInteraction".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("subject", &self.subject);
        w.prim("description", &self.description);
        w.list("interactant", &self.interactant);
        w.one("type", &self.type_);
        w.one("effect", &self.effect);
        w.one("incidence", &self.incidence);
        w.one("management", &self.management);
        w.finish()
    }
}

/// The specific medication, food or laboratory test that interacts
///
/// FHIR path: `MedicinalProductInteraction.interactant`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProductInteractionInteractant {
    /// `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>,
    /// `item[x]` (1..1): The specific medication, food or laboratory test that interacts
    pub item: Option<MedicinalProductInteractionInteractantItem>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicinalProductInteractionInteractant {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            item: o.choice(d, "item"),
        };
        required(d, "item[x]", &r.item);
        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.choice("item", &self.item);
        w.finish()
    }
}

/// The types `MedicinalProductInteraction.interactant.item[x]` allows.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq)]
pub enum MedicinalProductInteractionInteractantItem {
    /// `Reference`
    Reference(Reference),
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
}

#[cfg(feature = "specialized")]
impl Choice for MedicinalProductInteractionInteractantItem {
    const TYPES: &'static [&'static str] = &["Reference", "CodeableConcept"];

    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
        match code {
            "Reference" => o.one(d, key).map(Self::Reference),
            "CodeableConcept" => o.one(d, key).map(Self::CodeableConcept),
            _ => None,
        }
    }

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::Reference(v) => w.value(&choice_key(base, "Reference"), v),
            Self::CodeableConcept(v) => w.value(&choice_key(base, "CodeableConcept"), v),
        }
    }
}