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 `MedicinalProductContraindication` 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 clinical particulars - indications, contraindications etc. of a medicinal product, including for regulatory purposes.
///
/// FHIR path: `MedicinalProductContraindication`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProductContraindication {
    /// `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 an indication
    pub subject: Vec<Reference>,
    /// `disease` (0..1): The disease, symptom or procedure for the contraindication
    pub disease: Option<CodeableConcept>,
    /// `diseaseStatus` (0..1): The status of the disease or symptom for the contraindication
    pub disease_status: Option<CodeableConcept>,
    /// `comorbidity` (0..*): A comorbidity (concurrent condition) or coinfection
    pub comorbidity: Vec<CodeableConcept>,
    /// `therapeuticIndication` (0..*): Information about the use of the medicinal product in relation to other therapies as part of the indication
    pub therapeutic_indication: Vec<Reference>,
    /// `otherTherapy` (0..*): Information about the use of the medicinal product in relation to other therapies described as part of the indication
    pub other_therapy: Vec<MedicinalProductContraindicationOtherTherapy>,
    /// `population` (0..*): The population group to which this applies
    pub population: Vec<Population>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "MedicinalProductContraindication");
        let r = MedicinalProductContraindication {
            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"),
            disease: o.one(d, "disease"),
            disease_status: o.one(d, "diseaseStatus"),
            comorbidity: o.list(d, "comorbidity"),
            therapeutic_indication: o.list(d, "therapeuticIndication"),
            other_therapy: o.list(d, "otherTherapy"),
            population: o.list(d, "population"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw(
            "resourceType",
            Json::String("MedicinalProductContraindication".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.one("disease", &self.disease);
        w.one("diseaseStatus", &self.disease_status);
        w.list("comorbidity", &self.comorbidity);
        w.list("therapeuticIndication", &self.therapeutic_indication);
        w.list("otherTherapy", &self.other_therapy);
        w.list("population", &self.population);
        w.finish()
    }
}

/// Information about the use of the medicinal product in relation to other therapies described as part of the indication
///
/// FHIR path: `MedicinalProductContraindication.otherTherapy`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProductContraindicationOtherTherapy {
    /// `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>,
    /// `therapyRelationshipType` (1..1): The type of relationship between the medicinal product indication or contraindication and another therapy
    pub therapy_relationship_type: Option<CodeableConcept>,
    /// `medication[x]` (1..1): Reference to a specific medication (active substance, medicinal product or class of products) as part of an indication or contraindication
    pub medication: Option<MedicinalProductContraindicationOtherTherapyMedication>,
}

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

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

/// The types `MedicinalProductContraindication.otherTherapy.medication[x]` allows.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq)]
pub enum MedicinalProductContraindicationOtherTherapyMedication {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Reference`
    Reference(Reference),
}

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

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

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