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

/// Indication for the Medicinal Product.
///
/// FHIR path: `MedicinalProductIndication`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProductIndication {
    /// `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>,
    /// `diseaseSymptomProcedure` (0..1): The disease, symptom or procedure that is the indication for treatment
    pub disease_symptom_procedure: Option<CodeableConcept>,
    /// `diseaseStatus` (0..1): The status of the disease or symptom for which the indication applies
    pub disease_status: Option<CodeableConcept>,
    /// `comorbidity` (0..*): Comorbidity (concurrent condition) or co-infection as part of the indication
    pub comorbidity: Vec<CodeableConcept>,
    /// `intendedEffect` (0..1): The intended effect, aim or strategy to be achieved by the indication
    pub intended_effect: Option<CodeableConcept>,
    /// `duration` (0..1): Timing or duration information as part of the indication
    pub duration: Option<Quantity>,
    /// `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<MedicinalProductIndicationOtherTherapy>,
    /// `undesirableEffect` (0..*): Describe the undesirable effects of the medicinal product
    pub undesirable_effect: Vec<Reference>,
    /// `population` (0..*): The population group to which this applies
    pub population: Vec<Population>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "MedicinalProductIndication");
        let r = MedicinalProductIndication {
            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_symptom_procedure: o.one(d, "diseaseSymptomProcedure"),
            disease_status: o.one(d, "diseaseStatus"),
            comorbidity: o.list(d, "comorbidity"),
            intended_effect: o.one(d, "intendedEffect"),
            duration: o.one(d, "duration"),
            other_therapy: o.list(d, "otherTherapy"),
            undesirable_effect: o.list(d, "undesirableEffect"),
            population: o.list(d, "population"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw(
            "resourceType",
            Json::String("MedicinalProductIndication".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("diseaseSymptomProcedure", &self.disease_symptom_procedure);
        w.one("diseaseStatus", &self.disease_status);
        w.list("comorbidity", &self.comorbidity);
        w.one("intendedEffect", &self.intended_effect);
        w.one("duration", &self.duration);
        w.list("otherTherapy", &self.other_therapy);
        w.list("undesirableEffect", &self.undesirable_effect);
        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: `MedicinalProductIndication.otherTherapy`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProductIndicationOtherTherapy {
    /// `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<MedicinalProductIndicationOtherTherapyMedication>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicinalProductIndicationOtherTherapy {
            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 `MedicinalProductIndication.otherTherapy.medication[x]` allows.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq)]
pub enum MedicinalProductIndicationOtherTherapyMedication {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Reference`
    Reference(Reference),
}

#[cfg(feature = "specialized")]
impl Choice for MedicinalProductIndicationOtherTherapyMedication {
    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),
        }
    }
}