1#![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#[cfg(feature = "clinical")]
22#[derive(Debug, Clone, PartialEq, Default)]
23pub struct Goal {
24 pub id: Option<String>,
26 pub meta: Option<Meta>,
28 pub implicit_rules: Option<Primitive<String>>,
30 pub language: Option<Primitive<String>>,
32 pub text: Option<Narrative>,
34 pub contained: Vec<Resource>,
36 pub extension: Vec<Extension>,
38 pub modifier_extension: Vec<Extension>,
40 pub identifier: Vec<Identifier>,
42 pub lifecycle_status: Option<Primitive<String>>,
44 pub achievement_status: Option<CodeableConcept>,
46 pub category: Vec<CodeableConcept>,
48 pub priority: Option<CodeableConcept>,
50 pub description: Option<CodeableConcept>,
52 pub subject: Option<Reference>,
54 pub start: Option<GoalStart>,
56 pub target: Vec<GoalTarget>,
58 pub status_date: Option<Primitive<String>>,
60 pub status_reason: Option<Primitive<String>>,
62 pub expressed_by: Option<Reference>,
64 pub addresses: Vec<Reference>,
66 pub note: Vec<Annotation>,
68 pub outcome_code: Vec<CodeableConcept>,
70 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#[cfg(feature = "clinical")]
149#[derive(Debug, Clone, PartialEq, Default)]
150pub struct GoalTarget {
151 pub id: Option<String>,
153 pub extension: Vec<Extension>,
155 pub modifier_extension: Vec<Extension>,
157 pub measure: Option<CodeableConcept>,
159 pub detail: Option<GoalTargetDetail>,
161 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#[cfg(feature = "clinical")]
197#[derive(Debug, Clone, PartialEq)]
198pub enum GoalStart {
199 Date(Primitive<String>),
201 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#[cfg(feature = "clinical")]
227#[derive(Debug, Clone, PartialEq)]
228pub enum GoalTargetDetail {
229 Quantity(Quantity),
231 Range(Range),
233 CodeableConcept(CodeableConcept),
235 String(Primitive<String>),
237 Boolean(Primitive<bool>),
239 Integer(Primitive<i32>),
241 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#[cfg(feature = "clinical")]
285#[derive(Debug, Clone, PartialEq)]
286pub enum GoalTargetDue {
287 Date(Primitive<String>),
289 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}