Skip to main content

fhir_types/r5/
availability.rs

1// @generated by fhir-codegen from hl7.fhir.r5.core 5.0.0. DO NOT EDIT.
2// Change the emitter (tools/fhir-codegen) and regenerate.
3// SPDX-FileCopyrightText: Cadasto B.V.
4// SPDX-License-Identifier: Apache-2.0
5//! Availability data for an {item}
6
7/// Availability data for an {item}.
8#[derive(Debug, Clone, Default, PartialEq, Eq)]
9pub struct Availability {
10    /// Unique id for inter-element referencing
11    ///
12    /// Unique id for the element within a resource (for internal references). This
13    /// may be any string value that does not contain spaces.
14    pub id: Option<std::string::String>,
15    /// Additional content defined by implementations
16    ///
17    /// May be used to represent additional information that is not part of the
18    /// basic definition of the element. To make the use of extensions safe and
19    /// managable, there is a strict set of governance applied to the definition and
20    /// use of extensions. Though any implementer can define an extension, there is
21    /// a set of requirements that SHALL be met as part of the definition of the
22    /// extension.
23    pub extension: Vec<super::extension::Extension>,
24    /// Times the {item} is available.
25    pub available_time: Vec<AvailabilityAvailableTime>,
26    /// Not available during this time due to provided reason.
27    pub not_available_time: Vec<AvailabilityNotAvailableTime>,
28}
29
30impl super::super::codec::Json for Availability {
31    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
32        let mut object = super::super::codec::Object::new();
33        if let Some(v) = &self.id {
34            object.insert(
35                std::string::String::from("id"),
36                super::super::codec::Value::String(v.clone()),
37            );
38        }
39        if !self.extension.is_empty() {
40            let mut items = Vec::with_capacity(self.extension.len());
41            for item in &self.extension {
42                items.push(super::super::codec::Value::Object(
43                    super::super::codec::Json::to_json(item)?,
44                ));
45            }
46            object.insert(
47                std::string::String::from("extension"),
48                super::super::codec::Value::Array(items),
49            );
50        }
51        if !self.available_time.is_empty() {
52            let mut items = Vec::with_capacity(self.available_time.len());
53            for item in &self.available_time {
54                items.push(super::super::codec::Value::Object(
55                    super::super::codec::Json::to_json(item)?,
56                ));
57            }
58            object.insert(
59                std::string::String::from("availableTime"),
60                super::super::codec::Value::Array(items),
61            );
62        }
63        if !self.not_available_time.is_empty() {
64            let mut items = Vec::with_capacity(self.not_available_time.len());
65            for item in &self.not_available_time {
66                items.push(super::super::codec::Value::Object(
67                    super::super::codec::Json::to_json(item)?,
68                ));
69            }
70            object.insert(
71                std::string::String::from("notAvailableTime"),
72                super::super::codec::Value::Array(items),
73            );
74        }
75        Ok(object)
76    }
77
78    fn from_json(
79        object: &super::super::codec::Object,
80        path: &mut super::super::codec::Path,
81    ) -> Result<Self, super::super::codec::DecodeError> {
82        let mut raw_id: Option<&super::super::codec::Value> = None;
83        let mut raw_extension: Option<&super::super::codec::Value> = None;
84        let mut raw_available_time: Option<&super::super::codec::Value> = None;
85        let mut raw_not_available_time: Option<&super::super::codec::Value> = None;
86        for (key, value) in object {
87            match key.as_str() {
88                "id" => {
89                    raw_id = Some(value);
90                }
91                "extension" => {
92                    raw_extension = Some(value);
93                }
94                "availableTime" => {
95                    raw_available_time = Some(value);
96                }
97                "notAvailableTime" => {
98                    raw_not_available_time = Some(value);
99                }
100                other => {
101                    return path.with(other, |path| {
102                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
103                    });
104                }
105            }
106        }
107        let field_id = raw_id
108            .map(|value| {
109                path.with("id", |path| {
110                    let value = super::super::codec::expect_single(value, path)?;
111                    super::primitives::checked_string(
112                        super::super::codec::expect_string(value, path)?,
113                        path,
114                    )
115                })
116            })
117            .transpose()?;
118        let mut field_extension = Vec::new();
119        if let Some(raw) = raw_extension {
120            for (index, value) in path
121                .with("extension", |path| {
122                    super::super::codec::expect_array(raw, path)
123                })?
124                .iter()
125                .enumerate()
126            {
127                field_extension.push(path.with_index("extension", index, |path| {
128                    super::super::codec::Json::from_json(
129                        super::super::codec::expect_object(value, path)?,
130                        path,
131                    )
132                })?);
133            }
134        }
135        let mut field_available_time = Vec::new();
136        if let Some(raw) = raw_available_time {
137            for (index, value) in path
138                .with("availableTime", |path| {
139                    super::super::codec::expect_array(raw, path)
140                })?
141                .iter()
142                .enumerate()
143            {
144                field_available_time.push(path.with_index("availableTime", index, |path| {
145                    super::super::codec::Json::from_json(
146                        super::super::codec::expect_object(value, path)?,
147                        path,
148                    )
149                })?);
150            }
151        }
152        let mut field_not_available_time = Vec::new();
153        if let Some(raw) = raw_not_available_time {
154            for (index, value) in path
155                .with("notAvailableTime", |path| {
156                    super::super::codec::expect_array(raw, path)
157                })?
158                .iter()
159                .enumerate()
160            {
161                field_not_available_time.push(path.with_index(
162                    "notAvailableTime",
163                    index,
164                    |path| {
165                        super::super::codec::Json::from_json(
166                            super::super::codec::expect_object(value, path)?,
167                            path,
168                        )
169                    },
170                )?);
171            }
172        }
173        Ok(Self {
174            id: field_id,
175            extension: field_extension,
176            available_time: field_available_time,
177            not_available_time: field_not_available_time,
178        })
179    }
180}
181
182impl serde::Serialize for Availability {
183    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
184        let mut map = serde::Serializer::serialize_map(serializer, None)?;
185        if !self.available_time.is_empty() {
186            serde::ser::SerializeMap::serialize_entry(
187                &mut map,
188                "availableTime",
189                &self.available_time,
190            )?;
191        }
192        if !self.extension.is_empty() {
193            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
194        }
195        if let Some(v) = &self.id {
196            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
197        }
198        if !self.not_available_time.is_empty() {
199            serde::ser::SerializeMap::serialize_entry(
200                &mut map,
201                "notAvailableTime",
202                &self.not_available_time,
203            )?;
204        }
205        serde::ser::SerializeMap::end(map)
206    }
207}
208
209impl<'de> serde::Deserialize<'de> for Availability {
210    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
211        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
212        let mut path = super::super::codec::Path::root("Availability");
213        let object =
214            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
215        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
216    }
217}
218
219/// Times the {item} is available.
220#[derive(Debug, Clone, Default, PartialEq, Eq)]
221pub struct AvailabilityAvailableTime {
222    /// Unique id for inter-element referencing
223    ///
224    /// Unique id for the element within a resource (for internal references). This
225    /// may be any string value that does not contain spaces.
226    pub id: Option<std::string::String>,
227    /// Additional content defined by implementations
228    ///
229    /// May be used to represent additional information that is not part of the
230    /// basic definition of the element. To make the use of extensions safe and
231    /// managable, there is a strict set of governance applied to the definition and
232    /// use of extensions. Though any implementer can define an extension, there is
233    /// a set of requirements that SHALL be met as part of the definition of the
234    /// extension.
235    pub extension: Vec<super::extension::Extension>,
236    /// mon | tue | wed | thu | fri | sat | sun.
237    pub days_of_week: Vec<super::primitives::Code>,
238    /// Always available? i.e. 24 hour service.
239    pub all_day: Option<super::primitives::Boolean>,
240    /// Opening time of day (ignored if allDay = true).
241    pub available_start_time: Option<super::primitives::Time>,
242    /// Closing time of day (ignored if allDay = true).
243    pub available_end_time: Option<super::primitives::Time>,
244}
245
246impl super::super::codec::Json for AvailabilityAvailableTime {
247    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
248        let mut object = super::super::codec::Object::new();
249        if let Some(v) = &self.id {
250            object.insert(
251                std::string::String::from("id"),
252                super::super::codec::Value::String(v.clone()),
253            );
254        }
255        if !self.extension.is_empty() {
256            let mut items = Vec::with_capacity(self.extension.len());
257            for item in &self.extension {
258                items.push(super::super::codec::Value::Object(
259                    super::super::codec::Json::to_json(item)?,
260                ));
261            }
262            object.insert(
263                std::string::String::from("extension"),
264                super::super::codec::Value::Array(items),
265            );
266        }
267        if !self.days_of_week.is_empty() {
268            let (values, elements) = super::super::codec::primitive_arrays(&self.days_of_week)?;
269            if let Some(values) = values {
270                object.insert(std::string::String::from("daysOfWeek"), values);
271            }
272            if let Some(elements) = elements {
273                object.insert(std::string::String::from("_daysOfWeek"), elements);
274            }
275        }
276        if let Some(item) = &self.all_day {
277            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
278                object.insert(std::string::String::from("allDay"), v);
279            }
280            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
281                object.insert(std::string::String::from("_allDay"), e);
282            }
283        }
284        if let Some(item) = &self.available_start_time {
285            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
286                object.insert(std::string::String::from("availableStartTime"), v);
287            }
288            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
289                object.insert(std::string::String::from("_availableStartTime"), e);
290            }
291        }
292        if let Some(item) = &self.available_end_time {
293            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
294                object.insert(std::string::String::from("availableEndTime"), v);
295            }
296            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
297                object.insert(std::string::String::from("_availableEndTime"), e);
298            }
299        }
300        Ok(object)
301    }
302
303    fn from_json(
304        object: &super::super::codec::Object,
305        path: &mut super::super::codec::Path,
306    ) -> Result<Self, super::super::codec::DecodeError> {
307        let mut raw_id: Option<&super::super::codec::Value> = None;
308        let mut raw_extension: Option<&super::super::codec::Value> = None;
309        let mut raw_days_of_week: Option<&super::super::codec::Value> = None;
310        let mut raw_days_of_week_element: Option<&super::super::codec::Value> = None;
311        let mut raw_all_day: Option<&super::super::codec::Value> = None;
312        let mut raw_all_day_element: Option<&super::super::codec::Value> = None;
313        let mut raw_available_start_time: Option<&super::super::codec::Value> = None;
314        let mut raw_available_start_time_element: Option<&super::super::codec::Value> = None;
315        let mut raw_available_end_time: Option<&super::super::codec::Value> = None;
316        let mut raw_available_end_time_element: Option<&super::super::codec::Value> = None;
317        for (key, value) in object {
318            match key.as_str() {
319                "id" => {
320                    raw_id = Some(value);
321                }
322                "extension" => {
323                    raw_extension = Some(value);
324                }
325                "daysOfWeek" => {
326                    raw_days_of_week = Some(value);
327                }
328                "_daysOfWeek" => {
329                    raw_days_of_week_element = Some(value);
330                }
331                "allDay" => {
332                    raw_all_day = Some(value);
333                }
334                "_allDay" => {
335                    raw_all_day_element = Some(value);
336                }
337                "availableStartTime" => {
338                    raw_available_start_time = Some(value);
339                }
340                "_availableStartTime" => {
341                    raw_available_start_time_element = Some(value);
342                }
343                "availableEndTime" => {
344                    raw_available_end_time = Some(value);
345                }
346                "_availableEndTime" => {
347                    raw_available_end_time_element = Some(value);
348                }
349                other => {
350                    return path.with(other, |path| {
351                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
352                    });
353                }
354            }
355        }
356        let field_id = raw_id
357            .map(|value| {
358                path.with("id", |path| {
359                    let value = super::super::codec::expect_single(value, path)?;
360                    super::primitives::checked_string(
361                        super::super::codec::expect_string(value, path)?,
362                        path,
363                    )
364                })
365            })
366            .transpose()?;
367        let mut field_extension = Vec::new();
368        if let Some(raw) = raw_extension {
369            for (index, value) in path
370                .with("extension", |path| {
371                    super::super::codec::expect_array(raw, path)
372                })?
373                .iter()
374                .enumerate()
375            {
376                field_extension.push(path.with_index("extension", index, |path| {
377                    super::super::codec::Json::from_json(
378                        super::super::codec::expect_object(value, path)?,
379                        path,
380                    )
381                })?);
382            }
383        }
384        let mut field_days_of_week = Vec::new();
385        for (index, (value, element)) in path
386            .with("daysOfWeek", |path| {
387                super::super::codec::pair_arrays(raw_days_of_week, raw_days_of_week_element, path)
388            })?
389            .into_iter()
390            .enumerate()
391        {
392            field_days_of_week.push(path.with_index("daysOfWeek", index, |path| {
393                super::super::codec::Primitive::from_json_parts(value, element, path)
394            })?);
395        }
396        let field_all_day = match (raw_all_day, raw_all_day_element) {
397            (None, None) => None,
398            (value, element) => Some(path.with("allDay", |path| {
399                super::super::codec::Primitive::from_json_parts(value, element, path)
400            })?),
401        };
402        let field_available_start_time =
403            match (raw_available_start_time, raw_available_start_time_element) {
404                (None, None) => None,
405                (value, element) => Some(path.with("availableStartTime", |path| {
406                    super::super::codec::Primitive::from_json_parts(value, element, path)
407                })?),
408            };
409        let field_available_end_time =
410            match (raw_available_end_time, raw_available_end_time_element) {
411                (None, None) => None,
412                (value, element) => Some(path.with("availableEndTime", |path| {
413                    super::super::codec::Primitive::from_json_parts(value, element, path)
414                })?),
415            };
416        Ok(Self {
417            id: field_id,
418            extension: field_extension,
419            days_of_week: field_days_of_week,
420            all_day: field_all_day,
421            available_start_time: field_available_start_time,
422            available_end_time: field_available_end_time,
423        })
424    }
425}
426
427impl serde::Serialize for AvailabilityAvailableTime {
428    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
429        let mut map = serde::Serializer::serialize_map(serializer, None)?;
430        if let Some(item) = &self.all_day {
431            super::super::codec::element_entry(&mut map, "_allDay", item)?;
432        }
433        if let Some(item) = &self.available_end_time {
434            super::super::codec::element_entry(&mut map, "_availableEndTime", item)?;
435        }
436        if let Some(item) = &self.available_start_time {
437            super::super::codec::element_entry(&mut map, "_availableStartTime", item)?;
438        }
439        super::super::codec::element_list_entry(&mut map, "_daysOfWeek", &self.days_of_week)?;
440        if let Some(item) = &self.all_day {
441            super::super::codec::value_entry(&mut map, "allDay", item)?;
442        }
443        if let Some(item) = &self.available_end_time {
444            super::super::codec::value_entry(&mut map, "availableEndTime", item)?;
445        }
446        if let Some(item) = &self.available_start_time {
447            super::super::codec::value_entry(&mut map, "availableStartTime", item)?;
448        }
449        super::super::codec::value_list_entry(&mut map, "daysOfWeek", &self.days_of_week)?;
450        if !self.extension.is_empty() {
451            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
452        }
453        if let Some(v) = &self.id {
454            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
455        }
456        serde::ser::SerializeMap::end(map)
457    }
458}
459
460impl<'de> serde::Deserialize<'de> for AvailabilityAvailableTime {
461    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
462        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
463        let mut path = super::super::codec::Path::root("AvailabilityAvailableTime");
464        let object =
465            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
466        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
467    }
468}
469
470/// Not available during this time due to provided reason.
471#[derive(Debug, Clone, Default, PartialEq, Eq)]
472pub struct AvailabilityNotAvailableTime {
473    /// Unique id for inter-element referencing
474    ///
475    /// Unique id for the element within a resource (for internal references). This
476    /// may be any string value that does not contain spaces.
477    pub id: Option<std::string::String>,
478    /// Additional content defined by implementations
479    ///
480    /// May be used to represent additional information that is not part of the
481    /// basic definition of the element. To make the use of extensions safe and
482    /// managable, there is a strict set of governance applied to the definition and
483    /// use of extensions. Though any implementer can define an extension, there is
484    /// a set of requirements that SHALL be met as part of the definition of the
485    /// extension.
486    pub extension: Vec<super::extension::Extension>,
487    /// Reason presented to the user explaining why time not available.
488    pub description: Option<super::primitives::String>,
489    /// Service not available during this period.
490    pub during: Option<super::period::Period>,
491}
492
493impl super::super::codec::Json for AvailabilityNotAvailableTime {
494    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
495        let mut object = super::super::codec::Object::new();
496        if let Some(v) = &self.id {
497            object.insert(
498                std::string::String::from("id"),
499                super::super::codec::Value::String(v.clone()),
500            );
501        }
502        if !self.extension.is_empty() {
503            let mut items = Vec::with_capacity(self.extension.len());
504            for item in &self.extension {
505                items.push(super::super::codec::Value::Object(
506                    super::super::codec::Json::to_json(item)?,
507                ));
508            }
509            object.insert(
510                std::string::String::from("extension"),
511                super::super::codec::Value::Array(items),
512            );
513        }
514        if let Some(item) = &self.description {
515            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
516                object.insert(std::string::String::from("description"), v);
517            }
518            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
519                object.insert(std::string::String::from("_description"), e);
520            }
521        }
522        if let Some(item) = &self.during {
523            object.insert(
524                std::string::String::from("during"),
525                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
526            );
527        }
528        Ok(object)
529    }
530
531    fn from_json(
532        object: &super::super::codec::Object,
533        path: &mut super::super::codec::Path,
534    ) -> Result<Self, super::super::codec::DecodeError> {
535        let mut raw_id: Option<&super::super::codec::Value> = None;
536        let mut raw_extension: Option<&super::super::codec::Value> = None;
537        let mut raw_description: Option<&super::super::codec::Value> = None;
538        let mut raw_description_element: Option<&super::super::codec::Value> = None;
539        let mut raw_during: Option<&super::super::codec::Value> = None;
540        for (key, value) in object {
541            match key.as_str() {
542                "id" => {
543                    raw_id = Some(value);
544                }
545                "extension" => {
546                    raw_extension = Some(value);
547                }
548                "description" => {
549                    raw_description = Some(value);
550                }
551                "_description" => {
552                    raw_description_element = Some(value);
553                }
554                "during" => {
555                    raw_during = Some(value);
556                }
557                other => {
558                    return path.with(other, |path| {
559                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
560                    });
561                }
562            }
563        }
564        let field_id = raw_id
565            .map(|value| {
566                path.with("id", |path| {
567                    let value = super::super::codec::expect_single(value, path)?;
568                    super::primitives::checked_string(
569                        super::super::codec::expect_string(value, path)?,
570                        path,
571                    )
572                })
573            })
574            .transpose()?;
575        let mut field_extension = Vec::new();
576        if let Some(raw) = raw_extension {
577            for (index, value) in path
578                .with("extension", |path| {
579                    super::super::codec::expect_array(raw, path)
580                })?
581                .iter()
582                .enumerate()
583            {
584                field_extension.push(path.with_index("extension", index, |path| {
585                    super::super::codec::Json::from_json(
586                        super::super::codec::expect_object(value, path)?,
587                        path,
588                    )
589                })?);
590            }
591        }
592        let field_description = match (raw_description, raw_description_element) {
593            (None, None) => None,
594            (value, element) => Some(path.with("description", |path| {
595                super::super::codec::Primitive::from_json_parts(value, element, path)
596            })?),
597        };
598        let field_during = raw_during
599            .map(|value| {
600                path.with("during", |path| {
601                    super::super::codec::Json::from_json(
602                        super::super::codec::expect_object(
603                            super::super::codec::expect_single(value, path)?,
604                            path,
605                        )?,
606                        path,
607                    )
608                })
609            })
610            .transpose()?;
611        Ok(Self {
612            id: field_id,
613            extension: field_extension,
614            description: field_description,
615            during: field_during,
616        })
617    }
618}
619
620impl serde::Serialize for AvailabilityNotAvailableTime {
621    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
622        let mut map = serde::Serializer::serialize_map(serializer, None)?;
623        if let Some(item) = &self.description {
624            super::super::codec::element_entry(&mut map, "_description", item)?;
625        }
626        if let Some(item) = &self.description {
627            super::super::codec::value_entry(&mut map, "description", item)?;
628        }
629        if let Some(item) = &self.during {
630            serde::ser::SerializeMap::serialize_entry(&mut map, "during", item)?;
631        }
632        if !self.extension.is_empty() {
633            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
634        }
635        if let Some(v) = &self.id {
636            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
637        }
638        serde::ser::SerializeMap::end(map)
639    }
640}
641
642impl<'de> serde::Deserialize<'de> for AvailabilityNotAvailableTime {
643    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
644        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
645        let mut path = super::super::codec::Path::root("AvailabilityNotAvailableTime");
646        let object =
647            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
648        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
649    }
650}