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

/// A record of a medication that is being consumed by a patient. A MedicationStatement may indicate that the patient may be taking the medication now or has taken the medication in the past or will be taking the medication in the future. The source of this information can be the patient, significant other (such as a family member or spouse), or a clinician. A common scenario where this information is captured is during the history taking process during a patient visit or stay. The medication information may come from sources such as the patient's memory, from a prescription bottle, or from a list of medications the patient, clinician or other party maintains. The primary difference between a medication statement and a medication administration is that the medication administration has complete administration information and is based on actual administration information from the person who administered the medication. A medication statement is often, if not always, less specific. There is no required date/time when the medication was administered, in fact we only know that a source has reported the patient is taking this medication, where details such as time, quantity, or rate or even medication product may be incomplete or missing or less precise. As stated earlier, the medication statement information may come from the patient's memory, from a prescription bottle or from a list of medications the patient, clinician or other party maintains. Medication administration is more formal and is not missing detailed information.
///
/// FHIR path: `MedicationStatement`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationStatement {
    /// `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 identifier
    pub identifier: Vec<Identifier>,
    /// `basedOn` (0..*): Fulfils plan, proposal or order
    pub based_on: Vec<Reference>,
    /// `partOf` (0..*): Part of referenced event
    pub part_of: Vec<Reference>,
    /// `status` (1..1): active | completed | entered-in-error | intended | stopped | on-hold | unknown | not-taken
    pub status: Option<Primitive<String>>,
    /// `statusReason` (0..*): Reason for current status
    pub status_reason: Vec<CodeableConcept>,
    /// `category` (0..1): Type of medication usage
    pub category: Option<CodeableConcept>,
    /// `medication[x]` (1..1): What medication was taken
    pub medication: Option<MedicationStatementMedication>,
    /// `subject` (1..1): Who is/was taking the medication
    pub subject: Option<Reference>,
    /// `context` (0..1): Encounter / Episode associated with MedicationStatement
    pub context: Option<Reference>,
    /// `effective[x]` (0..1): The date/time or interval when the medication is/was/will be taken
    pub effective: Option<MedicationStatementEffective>,
    /// `dateAsserted` (0..1): When the statement was asserted?
    pub date_asserted: Option<Primitive<String>>,
    /// `informationSource` (0..1): Person or organization that provided the information about the taking of this medication
    pub information_source: Option<Reference>,
    /// `derivedFrom` (0..*): Additional supporting information
    pub derived_from: Vec<Reference>,
    /// `reasonCode` (0..*): Reason for why the medication is being/was taken
    pub reason_code: Vec<CodeableConcept>,
    /// `reasonReference` (0..*): Condition or observation that supports why the medication is being/was taken
    pub reason_reference: Vec<Reference>,
    /// `note` (0..*): Further information about the statement
    pub note: Vec<Annotation>,
    /// `dosage` (0..*): Details of how medication is/was taken or should be taken
    pub dosage: Vec<Dosage>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "MedicationStatement");
        let r = MedicationStatement {
            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"),
            based_on: o.list(d, "basedOn"),
            part_of: o.list(d, "partOf"),
            status: o.prim(d, "status", Kind::Code),
            status_reason: o.list(d, "statusReason"),
            category: o.one(d, "category"),
            medication: o.choice(d, "medication"),
            subject: o.one(d, "subject"),
            context: o.one(d, "context"),
            effective: o.choice(d, "effective"),
            date_asserted: o.prim(d, "dateAsserted", Kind::DateTime),
            information_source: o.one(d, "informationSource"),
            derived_from: o.list(d, "derivedFrom"),
            reason_code: o.list(d, "reasonCode"),
            reason_reference: o.list(d, "reasonReference"),
            note: o.list(d, "note"),
            dosage: o.list(d, "dosage"),
        };
        required(d, "status", &r.status);
        required(d, "medication[x]", &r.medication);
        required(d, "subject", &r.subject);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("MedicationStatement".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.list("basedOn", &self.based_on);
        w.list("partOf", &self.part_of);
        w.prim("status", &self.status);
        w.list("statusReason", &self.status_reason);
        w.one("category", &self.category);
        w.choice("medication", &self.medication);
        w.one("subject", &self.subject);
        w.one("context", &self.context);
        w.choice("effective", &self.effective);
        w.prim("dateAsserted", &self.date_asserted);
        w.one("informationSource", &self.information_source);
        w.list("derivedFrom", &self.derived_from);
        w.list("reasonCode", &self.reason_code);
        w.list("reasonReference", &self.reason_reference);
        w.list("note", &self.note);
        w.list("dosage", &self.dosage);
        w.finish()
    }
}

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

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

/// The types `MedicationStatement.effective[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum MedicationStatementEffective {
    /// `dateTime`
    DateTime(Primitive<String>),
    /// `Period`
    Period(Period),
}

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

    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),
            "Period" => o.one(d, key).map(Self::Period),
            _ => None,
        }
    }

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