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

/// Describes the intended objective(s) for a patient, group or organization care, for example, weight loss, restoring an activity of daily living, obtaining herd immunity via immunization, meeting a process improvement objective, etc.
///
/// FHIR path: `Goal`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Goal {
    /// `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 Ids for this goal
    pub identifier: Vec<Identifier>,
    /// `lifecycleStatus` (1..1): proposed | planned | accepted | active | on-hold | completed | cancelled | entered-in-error | rejected
    pub lifecycle_status: Option<Primitive<String>>,
    /// `achievementStatus` (0..1): in-progress | improving | worsening | no-change | achieved | sustaining | not-achieved | no-progress | not-attainable
    pub achievement_status: Option<CodeableConcept>,
    /// `category` (0..*): E.g. Treatment, dietary, behavioral, etc.
    pub category: Vec<CodeableConcept>,
    /// `priority` (0..1): high-priority | medium-priority | low-priority
    pub priority: Option<CodeableConcept>,
    /// `description` (1..1): Code or text describing goal
    pub description: Option<CodeableConcept>,
    /// `subject` (1..1): Who this goal is intended for
    pub subject: Option<Reference>,
    /// `start[x]` (0..1): When goal pursuit begins
    pub start: Option<GoalStart>,
    /// `target` (0..*): Target outcome for the goal
    pub target: Vec<GoalTarget>,
    /// `statusDate` (0..1): When goal status took effect
    pub status_date: Option<Primitive<String>>,
    /// `statusReason` (0..1): Reason for current status
    pub status_reason: Option<Primitive<String>>,
    /// `expressedBy` (0..1): Who's responsible for creating Goal?
    pub expressed_by: Option<Reference>,
    /// `addresses` (0..*): Issues addressed by this goal
    pub addresses: Vec<Reference>,
    /// `note` (0..*): Comments about the goal
    pub note: Vec<Annotation>,
    /// `outcomeCode` (0..*): What result was achieved regarding the goal?
    pub outcome_code: Vec<CodeableConcept>,
    /// `outcomeReference` (0..*): Observation that resulted from goal
    pub outcome_reference: Vec<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Goal");
        let r = Goal {
            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"),
            lifecycle_status: o.prim(d, "lifecycleStatus", Kind::Code),
            achievement_status: o.one(d, "achievementStatus"),
            category: o.list(d, "category"),
            priority: o.one(d, "priority"),
            description: o.one(d, "description"),
            subject: o.one(d, "subject"),
            start: o.choice(d, "start"),
            target: o.list(d, "target"),
            status_date: o.prim(d, "statusDate", Kind::Date),
            status_reason: o.prim(d, "statusReason", Kind::String),
            expressed_by: o.one(d, "expressedBy"),
            addresses: o.list(d, "addresses"),
            note: o.list(d, "note"),
            outcome_code: o.list(d, "outcomeCode"),
            outcome_reference: o.list(d, "outcomeReference"),
        };
        required(d, "lifecycleStatus", &r.lifecycle_status);
        required(d, "description", &r.description);
        required(d, "subject", &r.subject);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Goal".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.prim("lifecycleStatus", &self.lifecycle_status);
        w.one("achievementStatus", &self.achievement_status);
        w.list("category", &self.category);
        w.one("priority", &self.priority);
        w.one("description", &self.description);
        w.one("subject", &self.subject);
        w.choice("start", &self.start);
        w.list("target", &self.target);
        w.prim("statusDate", &self.status_date);
        w.prim("statusReason", &self.status_reason);
        w.one("expressedBy", &self.expressed_by);
        w.list("addresses", &self.addresses);
        w.list("note", &self.note);
        w.list("outcomeCode", &self.outcome_code);
        w.list("outcomeReference", &self.outcome_reference);
        w.finish()
    }
}

/// Target outcome for the goal
///
/// FHIR path: `Goal.target`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct GoalTarget {
    /// `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>,
    /// `measure` (0..1): The parameter whose value is being tracked
    pub measure: Option<CodeableConcept>,
    /// `detail[x]` (0..1): The target value to be achieved
    pub detail: Option<GoalTargetDetail>,
    /// `due[x]` (0..1): Reach goal on or before
    pub due: Option<GoalTargetDue>,
}

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

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

/// The types `Goal.start[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum GoalStart {
    /// `date`
    Date(Primitive<String>),
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
}

#[cfg(feature = "clinical")]
impl Choice for GoalStart {
    const TYPES: &'static [&'static str] = &["date", "CodeableConcept"];

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

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

/// The types `Goal.target.detail[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum GoalTargetDetail {
    /// `Quantity`
    Quantity(Quantity),
    /// `Range`
    Range(Range),
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `string`
    String(Primitive<String>),
    /// `boolean`
    Boolean(Primitive<bool>),
    /// `integer`
    Integer(Primitive<i32>),
    /// `Ratio`
    Ratio(Ratio),
}

#[cfg(feature = "clinical")]
impl Choice for GoalTargetDetail {
    const TYPES: &'static [&'static str] = &[
        "Quantity",
        "Range",
        "CodeableConcept",
        "string",
        "boolean",
        "integer",
        "Ratio",
    ];

    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
        match code {
            "Quantity" => o.one(d, key).map(Self::Quantity),
            "Range" => o.one(d, key).map(Self::Range),
            "CodeableConcept" => o.one(d, key).map(Self::CodeableConcept),
            "string" => o.prim(d, key, Kind::String).map(Self::String),
            "boolean" => o.prim(d, key, Kind::Boolean).map(Self::Boolean),
            "integer" => o.prim(d, key, Kind::Integer).map(Self::Integer),
            "Ratio" => o.one(d, key).map(Self::Ratio),
            _ => None,
        }
    }

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::Quantity(v) => w.value(&choice_key(base, "Quantity"), v),
            Self::Range(v) => w.value(&choice_key(base, "Range"), v),
            Self::CodeableConcept(v) => w.value(&choice_key(base, "CodeableConcept"), v),
            Self::String(v) => w.prim_value(&choice_key(base, "string"), v),
            Self::Boolean(v) => w.prim_value(&choice_key(base, "boolean"), v),
            Self::Integer(v) => w.prim_value(&choice_key(base, "integer"), v),
            Self::Ratio(v) => w.value(&choice_key(base, "Ratio"), v),
        }
    }
}

/// The types `Goal.target.due[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum GoalTargetDue {
    /// `date`
    Date(Primitive<String>),
    /// `Duration`
    Duration(Duration),
}

#[cfg(feature = "clinical")]
impl Choice for GoalTargetDue {
    const TYPES: &'static [&'static str] = &["date", "Duration"];

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

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