Skip to main content

fhirkit/r4/resources/
goal.rs

1// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
2//! The FHIR R4 `Goal` resource.
3
4#![allow(
5    unused_imports,
6    clippy::large_enum_variant,
7    clippy::too_many_lines,
8    clippy::doc_markdown
9)]
10
11use crate::decode::{
12    choice_key, required, required_list, resource_type, Choice, Decoder, FhirJson, Obj, ObjWriter,
13};
14use crate::json::Json;
15use crate::primitive::{Decimal, Kind, Primitive};
16use crate::r4::*;
17
18/// 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.
19///
20/// FHIR path: `Goal`.
21#[cfg(feature = "clinical")]
22#[derive(Debug, Clone, PartialEq, Default)]
23pub struct Goal {
24    /// `id` (0..1): Logical id of this artifact
25    pub id: Option<String>,
26    /// `meta` (0..1): Metadata about the resource
27    pub meta: Option<Meta>,
28    /// `implicitRules` (0..1): A set of rules under which this content was created
29    pub implicit_rules: Option<Primitive<String>>,
30    /// `language` (0..1): Language of the resource content
31    pub language: Option<Primitive<String>>,
32    /// `text` (0..1): Text summary of the resource, for human interpretation
33    pub text: Option<Narrative>,
34    /// `contained` (0..*): Contained, inline Resources
35    pub contained: Vec<Resource>,
36    /// `extension` (0..*): Additional content defined by implementations
37    pub extension: Vec<Extension>,
38    /// `modifierExtension` (0..*): Extensions that cannot be ignored
39    pub modifier_extension: Vec<Extension>,
40    /// `identifier` (0..*): External Ids for this goal
41    pub identifier: Vec<Identifier>,
42    /// `lifecycleStatus` (1..1): proposed | planned | accepted | active | on-hold | completed | cancelled | entered-in-error | rejected
43    pub lifecycle_status: Option<Primitive<String>>,
44    /// `achievementStatus` (0..1): in-progress | improving | worsening | no-change | achieved | sustaining | not-achieved | no-progress | not-attainable
45    pub achievement_status: Option<CodeableConcept>,
46    /// `category` (0..*): E.g. Treatment, dietary, behavioral, etc.
47    pub category: Vec<CodeableConcept>,
48    /// `priority` (0..1): high-priority | medium-priority | low-priority
49    pub priority: Option<CodeableConcept>,
50    /// `description` (1..1): Code or text describing goal
51    pub description: Option<CodeableConcept>,
52    /// `subject` (1..1): Who this goal is intended for
53    pub subject: Option<Reference>,
54    /// `start[x]` (0..1): When goal pursuit begins
55    pub start: Option<GoalStart>,
56    /// `target` (0..*): Target outcome for the goal
57    pub target: Vec<GoalTarget>,
58    /// `statusDate` (0..1): When goal status took effect
59    pub status_date: Option<Primitive<String>>,
60    /// `statusReason` (0..1): Reason for current status
61    pub status_reason: Option<Primitive<String>>,
62    /// `expressedBy` (0..1): Who's responsible for creating Goal?
63    pub expressed_by: Option<Reference>,
64    /// `addresses` (0..*): Issues addressed by this goal
65    pub addresses: Vec<Reference>,
66    /// `note` (0..*): Comments about the goal
67    pub note: Vec<Annotation>,
68    /// `outcomeCode` (0..*): What result was achieved regarding the goal?
69    pub outcome_code: Vec<CodeableConcept>,
70    /// `outcomeReference` (0..*): Observation that resulted from goal
71    pub outcome_reference: Vec<Reference>,
72}
73
74#[cfg(feature = "clinical")]
75impl FhirJson for Goal {
76    const TYPE_NAME: &'static str = "Goal";
77
78    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
79        let mut o = Obj::new(v, d)?;
80        resource_type(&mut o, d, "Goal");
81        let r = Goal {
82            id: o.string(d, "id"),
83            meta: o.one(d, "meta"),
84            implicit_rules: o.prim(d, "implicitRules", Kind::Uri),
85            language: o.prim(d, "language", Kind::Code),
86            text: o.one(d, "text"),
87            contained: o.list(d, "contained"),
88            extension: o.list(d, "extension"),
89            modifier_extension: o.list(d, "modifierExtension"),
90            identifier: o.list(d, "identifier"),
91            lifecycle_status: o.prim(d, "lifecycleStatus", Kind::Code),
92            achievement_status: o.one(d, "achievementStatus"),
93            category: o.list(d, "category"),
94            priority: o.one(d, "priority"),
95            description: o.one(d, "description"),
96            subject: o.one(d, "subject"),
97            start: o.choice(d, "start"),
98            target: o.list(d, "target"),
99            status_date: o.prim(d, "statusDate", Kind::Date),
100            status_reason: o.prim(d, "statusReason", Kind::String),
101            expressed_by: o.one(d, "expressedBy"),
102            addresses: o.list(d, "addresses"),
103            note: o.list(d, "note"),
104            outcome_code: o.list(d, "outcomeCode"),
105            outcome_reference: o.list(d, "outcomeReference"),
106        };
107        required(d, "lifecycleStatus", &r.lifecycle_status);
108        required(d, "description", &r.description);
109        required(d, "subject", &r.subject);
110        o.finish(d);
111        Some(r)
112    }
113
114    fn encode(&self) -> Json {
115        let mut w = ObjWriter::new();
116        w.raw("resourceType", Json::String("Goal".into()));
117        w.string("id", &self.id);
118        w.one("meta", &self.meta);
119        w.prim("implicitRules", &self.implicit_rules);
120        w.prim("language", &self.language);
121        w.one("text", &self.text);
122        w.list("contained", &self.contained);
123        w.list("extension", &self.extension);
124        w.list("modifierExtension", &self.modifier_extension);
125        w.list("identifier", &self.identifier);
126        w.prim("lifecycleStatus", &self.lifecycle_status);
127        w.one("achievementStatus", &self.achievement_status);
128        w.list("category", &self.category);
129        w.one("priority", &self.priority);
130        w.one("description", &self.description);
131        w.one("subject", &self.subject);
132        w.choice("start", &self.start);
133        w.list("target", &self.target);
134        w.prim("statusDate", &self.status_date);
135        w.prim("statusReason", &self.status_reason);
136        w.one("expressedBy", &self.expressed_by);
137        w.list("addresses", &self.addresses);
138        w.list("note", &self.note);
139        w.list("outcomeCode", &self.outcome_code);
140        w.list("outcomeReference", &self.outcome_reference);
141        w.finish()
142    }
143}
144
145/// Target outcome for the goal
146///
147/// FHIR path: `Goal.target`.
148#[cfg(feature = "clinical")]
149#[derive(Debug, Clone, PartialEq, Default)]
150pub struct GoalTarget {
151    /// `id` (0..1): Unique id for inter-element referencing
152    pub id: Option<String>,
153    /// `extension` (0..*): Additional content defined by implementations
154    pub extension: Vec<Extension>,
155    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
156    pub modifier_extension: Vec<Extension>,
157    /// `measure` (0..1): The parameter whose value is being tracked
158    pub measure: Option<CodeableConcept>,
159    /// `detail[x]` (0..1): The target value to be achieved
160    pub detail: Option<GoalTargetDetail>,
161    /// `due[x]` (0..1): Reach goal on or before
162    pub due: Option<GoalTargetDue>,
163}
164
165#[cfg(feature = "clinical")]
166impl FhirJson for GoalTarget {
167    const TYPE_NAME: &'static str = "GoalTarget";
168
169    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
170        let mut o = Obj::new(v, d)?;
171        let r = GoalTarget {
172            id: o.string(d, "id"),
173            extension: o.list(d, "extension"),
174            modifier_extension: o.list(d, "modifierExtension"),
175            measure: o.one(d, "measure"),
176            detail: o.choice(d, "detail"),
177            due: o.choice(d, "due"),
178        };
179        o.finish(d);
180        Some(r)
181    }
182
183    fn encode(&self) -> Json {
184        let mut w = ObjWriter::new();
185        w.string("id", &self.id);
186        w.list("extension", &self.extension);
187        w.list("modifierExtension", &self.modifier_extension);
188        w.one("measure", &self.measure);
189        w.choice("detail", &self.detail);
190        w.choice("due", &self.due);
191        w.finish()
192    }
193}
194
195/// The types `Goal.start[x]` allows.
196#[cfg(feature = "clinical")]
197#[derive(Debug, Clone, PartialEq)]
198pub enum GoalStart {
199    /// `date`
200    Date(Primitive<String>),
201    /// `CodeableConcept`
202    CodeableConcept(CodeableConcept),
203}
204
205#[cfg(feature = "clinical")]
206impl Choice for GoalStart {
207    const TYPES: &'static [&'static str] = &["date", "CodeableConcept"];
208
209    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
210        match code {
211            "date" => o.prim(d, key, Kind::Date).map(Self::Date),
212            "CodeableConcept" => o.one(d, key).map(Self::CodeableConcept),
213            _ => None,
214        }
215    }
216
217    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
218        match self {
219            Self::Date(v) => w.prim_value(&choice_key(base, "date"), v),
220            Self::CodeableConcept(v) => w.value(&choice_key(base, "CodeableConcept"), v),
221        }
222    }
223}
224
225/// The types `Goal.target.detail[x]` allows.
226#[cfg(feature = "clinical")]
227#[derive(Debug, Clone, PartialEq)]
228pub enum GoalTargetDetail {
229    /// `Quantity`
230    Quantity(Quantity),
231    /// `Range`
232    Range(Range),
233    /// `CodeableConcept`
234    CodeableConcept(CodeableConcept),
235    /// `string`
236    String(Primitive<String>),
237    /// `boolean`
238    Boolean(Primitive<bool>),
239    /// `integer`
240    Integer(Primitive<i32>),
241    /// `Ratio`
242    Ratio(Ratio),
243}
244
245#[cfg(feature = "clinical")]
246impl Choice for GoalTargetDetail {
247    const TYPES: &'static [&'static str] = &[
248        "Quantity",
249        "Range",
250        "CodeableConcept",
251        "string",
252        "boolean",
253        "integer",
254        "Ratio",
255    ];
256
257    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
258        match code {
259            "Quantity" => o.one(d, key).map(Self::Quantity),
260            "Range" => o.one(d, key).map(Self::Range),
261            "CodeableConcept" => o.one(d, key).map(Self::CodeableConcept),
262            "string" => o.prim(d, key, Kind::String).map(Self::String),
263            "boolean" => o.prim(d, key, Kind::Boolean).map(Self::Boolean),
264            "integer" => o.prim(d, key, Kind::Integer).map(Self::Integer),
265            "Ratio" => o.one(d, key).map(Self::Ratio),
266            _ => None,
267        }
268    }
269
270    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
271        match self {
272            Self::Quantity(v) => w.value(&choice_key(base, "Quantity"), v),
273            Self::Range(v) => w.value(&choice_key(base, "Range"), v),
274            Self::CodeableConcept(v) => w.value(&choice_key(base, "CodeableConcept"), v),
275            Self::String(v) => w.prim_value(&choice_key(base, "string"), v),
276            Self::Boolean(v) => w.prim_value(&choice_key(base, "boolean"), v),
277            Self::Integer(v) => w.prim_value(&choice_key(base, "integer"), v),
278            Self::Ratio(v) => w.value(&choice_key(base, "Ratio"), v),
279        }
280    }
281}
282
283/// The types `Goal.target.due[x]` allows.
284#[cfg(feature = "clinical")]
285#[derive(Debug, Clone, PartialEq)]
286pub enum GoalTargetDue {
287    /// `date`
288    Date(Primitive<String>),
289    /// `Duration`
290    Duration(Duration),
291}
292
293#[cfg(feature = "clinical")]
294impl Choice for GoalTargetDue {
295    const TYPES: &'static [&'static str] = &["date", "Duration"];
296
297    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
298        match code {
299            "date" => o.prim(d, key, Kind::Date).map(Self::Date),
300            "Duration" => o.one(d, key).map(Self::Duration),
301            _ => None,
302        }
303    }
304
305    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
306        match self {
307            Self::Date(v) => w.prim_value(&choice_key(base, "date"), v),
308            Self::Duration(v) => w.value(&choice_key(base, "Duration"), v),
309        }
310    }
311}