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

/// Indicates that a medication product is to be or has been dispensed for a named person/patient. This includes a description of the medication product (supply) provided and the instructions for administering the medication. The medication dispense is the result of a pharmacy system responding to a medication order.
///
/// FHIR path: `MedicationDispense`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationDispense {
    /// `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>,
    /// `partOf` (0..*): Event that dispense is part of
    pub part_of: Vec<Reference>,
    /// `status` (1..1): preparation | in-progress | cancelled | on-hold | completed | entered-in-error | stopped | declined | unknown
    pub status: Option<Primitive<String>>,
    /// `statusReason[x]` (0..1): Why a dispense was not performed
    pub status_reason: Option<MedicationDispenseStatusReason>,
    /// `category` (0..1): Type of medication dispense
    pub category: Option<CodeableConcept>,
    /// `medication[x]` (1..1): What medication was supplied
    pub medication: Option<MedicationDispenseMedication>,
    /// `subject` (0..1): Who the dispense is for
    pub subject: Option<Reference>,
    /// `context` (0..1): Encounter / Episode associated with event
    pub context: Option<Reference>,
    /// `supportingInformation` (0..*): Information that supports the dispensing of the medication
    pub supporting_information: Vec<Reference>,
    /// `performer` (0..*): Who performed event
    pub performer: Vec<MedicationDispensePerformer>,
    /// `location` (0..1): Where the dispense occurred
    pub location: Option<Reference>,
    /// `authorizingPrescription` (0..*): Medication order that authorizes the dispense
    pub authorizing_prescription: Vec<Reference>,
    /// `type` (0..1): Trial fill, partial fill, emergency fill, etc.
    pub type_: Option<CodeableConcept>,
    /// `quantity` (0..1): Amount dispensed
    pub quantity: Option<Quantity>,
    /// `daysSupply` (0..1): Amount of medication expressed as a timing amount
    pub days_supply: Option<Quantity>,
    /// `whenPrepared` (0..1): When product was packaged and reviewed
    pub when_prepared: Option<Primitive<String>>,
    /// `whenHandedOver` (0..1): When product was given out
    pub when_handed_over: Option<Primitive<String>>,
    /// `destination` (0..1): Where the medication was sent
    pub destination: Option<Reference>,
    /// `receiver` (0..*): Who collected the medication
    pub receiver: Vec<Reference>,
    /// `note` (0..*): Information about the dispense
    pub note: Vec<Annotation>,
    /// `dosageInstruction` (0..*): How the medication is to be used by the patient or administered by the caregiver
    pub dosage_instruction: Vec<Dosage>,
    /// `substitution` (0..1): Whether a substitution was performed on the dispense
    pub substitution: Option<MedicationDispenseSubstitution>,
    /// `detectedIssue` (0..*): Clinical issue with action
    pub detected_issue: Vec<Reference>,
    /// `eventHistory` (0..*): A list of relevant lifecycle events
    pub event_history: Vec<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "MedicationDispense");
        let r = MedicationDispense {
            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"),
            part_of: o.list(d, "partOf"),
            status: o.prim(d, "status", Kind::Code),
            status_reason: o.choice(d, "statusReason"),
            category: o.one(d, "category"),
            medication: o.choice(d, "medication"),
            subject: o.one(d, "subject"),
            context: o.one(d, "context"),
            supporting_information: o.list(d, "supportingInformation"),
            performer: o.list(d, "performer"),
            location: o.one(d, "location"),
            authorizing_prescription: o.list(d, "authorizingPrescription"),
            type_: o.one(d, "type"),
            quantity: o.one(d, "quantity"),
            days_supply: o.one(d, "daysSupply"),
            when_prepared: o.prim(d, "whenPrepared", Kind::DateTime),
            when_handed_over: o.prim(d, "whenHandedOver", Kind::DateTime),
            destination: o.one(d, "destination"),
            receiver: o.list(d, "receiver"),
            note: o.list(d, "note"),
            dosage_instruction: o.list(d, "dosageInstruction"),
            substitution: o.one(d, "substitution"),
            detected_issue: o.list(d, "detectedIssue"),
            event_history: o.list(d, "eventHistory"),
        };
        required(d, "status", &r.status);
        required(d, "medication[x]", &r.medication);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("MedicationDispense".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("partOf", &self.part_of);
        w.prim("status", &self.status);
        w.choice("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.list("supportingInformation", &self.supporting_information);
        w.list("performer", &self.performer);
        w.one("location", &self.location);
        w.list("authorizingPrescription", &self.authorizing_prescription);
        w.one("type", &self.type_);
        w.one("quantity", &self.quantity);
        w.one("daysSupply", &self.days_supply);
        w.prim("whenPrepared", &self.when_prepared);
        w.prim("whenHandedOver", &self.when_handed_over);
        w.one("destination", &self.destination);
        w.list("receiver", &self.receiver);
        w.list("note", &self.note);
        w.list("dosageInstruction", &self.dosage_instruction);
        w.one("substitution", &self.substitution);
        w.list("detectedIssue", &self.detected_issue);
        w.list("eventHistory", &self.event_history);
        w.finish()
    }
}

/// Who performed event
///
/// FHIR path: `MedicationDispense.performer`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationDispensePerformer {
    /// `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>,
    /// `function` (0..1): Who performed the dispense and what they did
    pub function: Option<CodeableConcept>,
    /// `actor` (1..1): Individual who was performing
    pub actor: Option<Reference>,
}

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

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

/// Whether a substitution was performed on the dispense
///
/// FHIR path: `MedicationDispense.substitution`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationDispenseSubstitution {
    /// `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>,
    /// `wasSubstituted` (1..1): Whether a substitution was or was not performed on the dispense
    pub was_substituted: Option<Primitive<bool>>,
    /// `type` (0..1): Code signifying whether a different drug was dispensed from what was prescribed
    pub type_: Option<CodeableConcept>,
    /// `reason` (0..*): Why was substitution made
    pub reason: Vec<CodeableConcept>,
    /// `responsibleParty` (0..*): Who is responsible for the substitution
    pub responsible_party: Vec<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationDispenseSubstitution {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            was_substituted: o.prim(d, "wasSubstituted", Kind::Boolean),
            type_: o.one(d, "type"),
            reason: o.list(d, "reason"),
            responsible_party: o.list(d, "responsibleParty"),
        };
        required(d, "wasSubstituted", &r.was_substituted);
        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.prim("wasSubstituted", &self.was_substituted);
        w.one("type", &self.type_);
        w.list("reason", &self.reason);
        w.list("responsibleParty", &self.responsible_party);
        w.finish()
    }
}

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

#[cfg(feature = "clinical")]
impl Choice for MedicationDispenseStatusReason {
    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 `MedicationDispense.medication[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum MedicationDispenseMedication {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Reference`
    Reference(Reference),
}

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