fhir-types 0.1.97

Generated per-version FHIR types and terminology operation contracts
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
// @generated by fhir-codegen from hl7.fhir.r4b.core 4.3.0. DO NOT EDIT.
// Change the emitter (tools/fhir-codegen) and regenerate.
//! A timing schedule that specifies an event that may occur multiple times

/// A timing schedule that specifies an event that may occur multiple times
///
/// Specifies an event that may occur multiple times. Timing schedules are used
/// to record when things are planned, expected or requested to occur. The most
/// common usage is in dosage instructions for medications. They are also used
/// when planning care of various kinds, and may be used for reporting the
/// schedule to which past regular activities were carried out.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Timing {
    /// Unique id for inter-element referencing
    ///
    /// Unique id for the element within a resource (for internal references). This
    /// may be any string value that does not contain spaces.
    pub id: Option<std::string::String>,
    /// Additional content defined by implementations
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the element. To make the use of extensions safe and
    /// manageable, there is a strict set of governance applied to the definition
    /// and use of extensions. Though any implementer can define an extension, there
    /// is a set of requirements that SHALL be met as part of the definition of the
    /// extension.
    pub extension: Vec<super::extension::Extension>,
    /// Extensions that cannot be ignored even if unrecognized
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the element and that modifies the understanding of the
    /// element in which it is contained and/or the understanding of the containing
    /// element's descendants. Usually modifier elements provide negation or
    /// qualification. To make the use of extensions safe and manageable, there is a
    /// strict set of governance applied to the definition and use of extensions.
    /// Though any implementer can define an extension, there is a set of
    /// requirements that SHALL be met as part of the definition of the extension.
    /// Applications processing a resource are required to check for modifier
    /// extensions. Modifier extensions SHALL NOT change the meaning of any elements
    /// on Resource or DomainResource (including cannot change the meaning of
    /// modifierExtension itself).
    pub modifier_extension: Vec<super::extension::Extension>,
    /// When the event occurs
    ///
    /// Identifies specific times when the event occurs.
    pub event: Vec<super::primitives::DateTime>,
    /// When the event is to occur
    ///
    /// A set of rules that describe when the event is scheduled.
    pub repeat: Option<TimingRepeat>,
    /// BID | TID | QID | AM | PM | QD | QOD | +
    ///
    /// A code for the timing schedule (or just text in code.text). Some codes such
    /// as BID are ubiquitous, but many institutions define their own additional
    /// codes. If a code is provided, the code is understood to be a complete
    /// statement of whatever is specified in the structured timing data, and either
    /// the code or the data may be used to interpret the Timing, with the exception
    /// that .repeat.bounds still applies over the code (and is not contained in the
    /// code).
    pub code: Option<super::codeable_concept::CodeableConcept>,
}

impl super::super::codec::Json for Timing {
    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
        let mut object = super::super::codec::Object::new();
        if let Some(v) = &self.id {
            object.insert(
                std::string::String::from("id"),
                super::super::codec::Value::String(v.clone()),
            );
        }
        if !self.extension.is_empty() {
            let mut items = Vec::with_capacity(self.extension.len());
            for item in &self.extension {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("extension"),
                super::super::codec::Value::Array(items),
            );
        }
        if !self.modifier_extension.is_empty() {
            let mut items = Vec::with_capacity(self.modifier_extension.len());
            for item in &self.modifier_extension {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("modifierExtension"),
                super::super::codec::Value::Array(items),
            );
        }
        if !self.event.is_empty() {
            let (values, elements) = super::super::codec::primitive_arrays(&self.event)?;
            object.insert(std::string::String::from("event"), values);
            if let Some(elements) = elements {
                object.insert(std::string::String::from("_event"), elements);
            }
        }
        if let Some(item) = &self.repeat {
            object.insert(
                std::string::String::from("repeat"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.code {
            object.insert(
                std::string::String::from("code"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        Ok(object)
    }

    fn from_json(
        object: &super::super::codec::Object,
        path: &mut super::super::codec::Path,
    ) -> Result<Self, super::super::codec::DecodeError> {
        let mut raw_id: Option<&super::super::codec::Value> = None;
        let mut raw_extension: Option<&super::super::codec::Value> = None;
        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
        let mut raw_event: Option<&super::super::codec::Value> = None;
        let mut raw_event_element: Option<&super::super::codec::Value> = None;
        let mut raw_repeat: Option<&super::super::codec::Value> = None;
        let mut raw_code: Option<&super::super::codec::Value> = None;
        for (key, value) in object {
            match key.as_str() {
                "id" => raw_id = Some(value),
                "extension" => raw_extension = Some(value),
                "modifierExtension" => raw_modifier_extension = Some(value),
                "event" => raw_event = Some(value),
                "_event" => raw_event_element = Some(value),
                "repeat" => raw_repeat = Some(value),
                "code" => raw_code = Some(value),
                other => {
                    return path.with(other, |path| {
                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
                    });
                }
            }
        }
        let field_id = raw_id
            .map(|value| {
                path.with("id", |path| {
                    let value = super::super::codec::expect_single(value, path)?;
                    super::super::codec::expect_string(value, path)
                })
            })
            .transpose()?;
        let mut field_extension = Vec::new();
        if let Some(raw) = raw_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_extension.push(path.with_index("extension", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let mut field_modifier_extension = Vec::new();
        if let Some(raw) = raw_modifier_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_modifier_extension.push(path.with_index(
                    "modifierExtension",
                    index,
                    |path| {
                        super::super::codec::Json::from_json(
                            super::super::codec::expect_object(value, path)?,
                            path,
                        )
                    },
                )?);
            }
        }
        let mut field_event = Vec::new();
        for (index, (value, element)) in
            super::super::codec::pair_arrays(raw_event, raw_event_element, path)?
                .into_iter()
                .enumerate()
        {
            field_event.push(path.with_index("event", index, |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?);
        }
        let field_repeat = raw_repeat
            .map(|value| {
                path.with("repeat", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_code = raw_code
            .map(|value| {
                path.with("code", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        Ok(Self {
            id: field_id,
            extension: field_extension,
            modifier_extension: field_modifier_extension,
            event: field_event,
            repeat: field_repeat,
            code: field_code,
        })
    }
}

impl serde::Serialize for Timing {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let mut map = serde::Serializer::serialize_map(serializer, None)?;
        super::super::codec::element_list_entry(&mut map, "_event", &self.event)?;
        if let Some(item) = &self.code {
            serde::ser::SerializeMap::serialize_entry(&mut map, "code", item)?;
        }
        super::super::codec::value_list_entry(&mut map, "event", &self.event)?;
        if !self.extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
        }
        if let Some(v) = &self.id {
            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
        }
        if !self.modifier_extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(
                &mut map,
                "modifierExtension",
                &self.modifier_extension,
            )?;
        }
        if let Some(item) = &self.repeat {
            serde::ser::SerializeMap::serialize_entry(&mut map, "repeat", item)?;
        }
        serde::ser::SerializeMap::end(map)
    }
}

impl<'de> serde::Deserialize<'de> for Timing {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
        let mut path = super::super::codec::Path::root("Timing");
        let object =
            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
    }
}

/// When the event is to occur
///
/// A set of rules that describe when the event is scheduled.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct TimingRepeat {
    /// Unique id for inter-element referencing
    ///
    /// Unique id for the element within a resource (for internal references). This
    /// may be any string value that does not contain spaces.
    pub id: Option<std::string::String>,
    /// Additional content defined by implementations
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the element. To make the use of extensions safe and
    /// manageable, there is a strict set of governance applied to the definition
    /// and use of extensions. Though any implementer can define an extension, there
    /// is a set of requirements that SHALL be met as part of the definition of the
    /// extension.
    pub extension: Vec<super::extension::Extension>,
    /// Length/Range of lengths, or (Start and/or end) limits
    ///
    /// Either a duration for the length of the timing schedule, a range of possible
    /// length, or outer bounds for start and/or end limits of the timing schedule.
    pub bounds: Option<TimingRepeatBounds>,
    /// Number of times to repeat
    ///
    /// A total count of the desired number of repetitions across the duration of
    /// the entire timing specification. If countMax is present, this element
    /// indicates the lower bound of the allowed range of count values.
    pub count: Option<super::primitives::PositiveInt>,
    /// Maximum number of times to repeat
    ///
    /// If present, indicates that the count is a range - so to perform the action
    /// between \[count\] and \[countMax\] times.
    pub count_max: Option<super::primitives::PositiveInt>,
    /// How long when it happens
    ///
    /// How long this thing happens for when it happens. If durationMax is present,
    /// this element indicates the lower bound of the allowed range of the duration.
    pub duration: Option<super::primitives::Decimal>,
    /// How long when it happens (Max)
    ///
    /// If present, indicates that the duration is a range - so to perform the
    /// action between \[duration\] and \[durationMax\] time length.
    pub duration_max: Option<super::primitives::Decimal>,
    /// s | min | h | d | wk | mo | a - unit of time (UCUM)
    ///
    /// The units of time for the duration, in UCUM units.
    pub duration_unit: Option<super::primitives::Code>,
    /// Event occurs frequency times per period
    ///
    /// The number of times to repeat the action within the specified period. If
    /// frequencyMax is present, this element indicates the lower bound of the
    /// allowed range of the frequency.
    pub frequency: Option<super::primitives::PositiveInt>,
    /// Event occurs up to frequencyMax times per period
    ///
    /// If present, indicates that the frequency is a range - so to repeat between
    /// \[frequency\] and \[frequencyMax\] times within the period or period range.
    pub frequency_max: Option<super::primitives::PositiveInt>,
    /// Event occurs frequency times per period
    ///
    /// Indicates the duration of time over which repetitions are to occur; e.g. to
    /// express "3 times per day", 3 would be the frequency and "1 day" would be the
    /// period. If periodMax is present, this element indicates the lower bound of
    /// the allowed range of the period length.
    pub period: Option<super::primitives::Decimal>,
    /// Upper limit of period (3-4 hours)
    ///
    /// If present, indicates that the period is a range from \[period\] to
    /// \[periodMax\], allowing expressing concepts such as "do this once every 3-5
    /// days.
    pub period_max: Option<super::primitives::Decimal>,
    /// s | min | h | d | wk | mo | a - unit of time (UCUM)
    ///
    /// The units of time for the period in UCUM units.
    pub period_unit: Option<super::primitives::Code>,
    /// mon | tue | wed | thu | fri | sat | sun
    ///
    /// If one or more days of week is provided, then the action happens only on the
    /// specified day(s).
    pub day_of_week: Vec<super::primitives::Code>,
    /// Time of day for action
    ///
    /// Specified time of day for action to take place.
    pub time_of_day: Vec<super::primitives::Time>,
    /// Code for time period of occurrence
    ///
    /// An approximate time period during the day, potentially linked to an event of
    /// daily living that indicates when the action should occur.
    pub when: Vec<super::primitives::Code>,
    /// Minutes from event (before or after)
    ///
    /// The number of minutes from the event. If the event code does not indicate
    /// whether the minutes is before or after the event, then the offset is assumed
    /// to be after the event.
    pub offset: Option<super::primitives::UnsignedInt>,
}

impl super::super::codec::Json for TimingRepeat {
    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
        let mut object = super::super::codec::Object::new();
        if let Some(v) = &self.id {
            object.insert(
                std::string::String::from("id"),
                super::super::codec::Value::String(v.clone()),
            );
        }
        if !self.extension.is_empty() {
            let mut items = Vec::with_capacity(self.extension.len());
            for item in &self.extension {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("extension"),
                super::super::codec::Value::Array(items),
            );
        }
        if let Some(item) = &self.bounds {
            let (suffix, value, element) = item.to_json_parts()?;
            if let Some(value) = value {
                object.insert(format!("bounds{suffix}"), value);
            }
            if let Some(element) = element {
                object.insert(format!("_bounds{suffix}"), element);
            }
        }
        if let Some(item) = &self.count {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("count"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_count"), e);
            }
        }
        if let Some(item) = &self.count_max {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("countMax"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_countMax"), e);
            }
        }
        if let Some(item) = &self.duration {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("duration"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_duration"), e);
            }
        }
        if let Some(item) = &self.duration_max {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("durationMax"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_durationMax"), e);
            }
        }
        if let Some(item) = &self.duration_unit {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("durationUnit"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_durationUnit"), e);
            }
        }
        if let Some(item) = &self.frequency {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("frequency"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_frequency"), e);
            }
        }
        if let Some(item) = &self.frequency_max {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("frequencyMax"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_frequencyMax"), e);
            }
        }
        if let Some(item) = &self.period {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("period"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_period"), e);
            }
        }
        if let Some(item) = &self.period_max {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("periodMax"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_periodMax"), e);
            }
        }
        if let Some(item) = &self.period_unit {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("periodUnit"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_periodUnit"), e);
            }
        }
        if !self.day_of_week.is_empty() {
            let (values, elements) = super::super::codec::primitive_arrays(&self.day_of_week)?;
            object.insert(std::string::String::from("dayOfWeek"), values);
            if let Some(elements) = elements {
                object.insert(std::string::String::from("_dayOfWeek"), elements);
            }
        }
        if !self.time_of_day.is_empty() {
            let (values, elements) = super::super::codec::primitive_arrays(&self.time_of_day)?;
            object.insert(std::string::String::from("timeOfDay"), values);
            if let Some(elements) = elements {
                object.insert(std::string::String::from("_timeOfDay"), elements);
            }
        }
        if !self.when.is_empty() {
            let (values, elements) = super::super::codec::primitive_arrays(&self.when)?;
            object.insert(std::string::String::from("when"), values);
            if let Some(elements) = elements {
                object.insert(std::string::String::from("_when"), elements);
            }
        }
        if let Some(item) = &self.offset {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("offset"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_offset"), e);
            }
        }
        Ok(object)
    }

    fn from_json(
        object: &super::super::codec::Object,
        path: &mut super::super::codec::Path,
    ) -> Result<Self, super::super::codec::DecodeError> {
        let mut raw_id: Option<&super::super::codec::Value> = None;
        let mut raw_extension: Option<&super::super::codec::Value> = None;
        let mut raw_bounds = super::super::codec::ChoiceSlot::default();
        let mut raw_count: Option<&super::super::codec::Value> = None;
        let mut raw_count_element: Option<&super::super::codec::Value> = None;
        let mut raw_count_max: Option<&super::super::codec::Value> = None;
        let mut raw_count_max_element: Option<&super::super::codec::Value> = None;
        let mut raw_duration: Option<&super::super::codec::Value> = None;
        let mut raw_duration_element: Option<&super::super::codec::Value> = None;
        let mut raw_duration_max: Option<&super::super::codec::Value> = None;
        let mut raw_duration_max_element: Option<&super::super::codec::Value> = None;
        let mut raw_duration_unit: Option<&super::super::codec::Value> = None;
        let mut raw_duration_unit_element: Option<&super::super::codec::Value> = None;
        let mut raw_frequency: Option<&super::super::codec::Value> = None;
        let mut raw_frequency_element: Option<&super::super::codec::Value> = None;
        let mut raw_frequency_max: Option<&super::super::codec::Value> = None;
        let mut raw_frequency_max_element: Option<&super::super::codec::Value> = None;
        let mut raw_period: Option<&super::super::codec::Value> = None;
        let mut raw_period_element: Option<&super::super::codec::Value> = None;
        let mut raw_period_max: Option<&super::super::codec::Value> = None;
        let mut raw_period_max_element: Option<&super::super::codec::Value> = None;
        let mut raw_period_unit: Option<&super::super::codec::Value> = None;
        let mut raw_period_unit_element: Option<&super::super::codec::Value> = None;
        let mut raw_day_of_week: Option<&super::super::codec::Value> = None;
        let mut raw_day_of_week_element: Option<&super::super::codec::Value> = None;
        let mut raw_time_of_day: Option<&super::super::codec::Value> = None;
        let mut raw_time_of_day_element: Option<&super::super::codec::Value> = None;
        let mut raw_when: Option<&super::super::codec::Value> = None;
        let mut raw_when_element: Option<&super::super::codec::Value> = None;
        let mut raw_offset: Option<&super::super::codec::Value> = None;
        let mut raw_offset_element: Option<&super::super::codec::Value> = None;
        for (key, value) in object {
            match key.as_str() {
                "id" => raw_id = Some(value),
                "extension" => raw_extension = Some(value),
                "boundsDuration" => {
                    raw_bounds.value("Duration", value, path)?;
                }
                "_boundsDuration" => {
                    raw_bounds.element("Duration", value, path)?;
                }
                "boundsRange" => {
                    raw_bounds.value("Range", value, path)?;
                }
                "_boundsRange" => {
                    raw_bounds.element("Range", value, path)?;
                }
                "boundsPeriod" => {
                    raw_bounds.value("Period", value, path)?;
                }
                "_boundsPeriod" => {
                    raw_bounds.element("Period", value, path)?;
                }
                "count" => raw_count = Some(value),
                "_count" => raw_count_element = Some(value),
                "countMax" => raw_count_max = Some(value),
                "_countMax" => raw_count_max_element = Some(value),
                "duration" => raw_duration = Some(value),
                "_duration" => raw_duration_element = Some(value),
                "durationMax" => raw_duration_max = Some(value),
                "_durationMax" => raw_duration_max_element = Some(value),
                "durationUnit" => raw_duration_unit = Some(value),
                "_durationUnit" => raw_duration_unit_element = Some(value),
                "frequency" => raw_frequency = Some(value),
                "_frequency" => raw_frequency_element = Some(value),
                "frequencyMax" => raw_frequency_max = Some(value),
                "_frequencyMax" => raw_frequency_max_element = Some(value),
                "period" => raw_period = Some(value),
                "_period" => raw_period_element = Some(value),
                "periodMax" => raw_period_max = Some(value),
                "_periodMax" => raw_period_max_element = Some(value),
                "periodUnit" => raw_period_unit = Some(value),
                "_periodUnit" => raw_period_unit_element = Some(value),
                "dayOfWeek" => raw_day_of_week = Some(value),
                "_dayOfWeek" => raw_day_of_week_element = Some(value),
                "timeOfDay" => raw_time_of_day = Some(value),
                "_timeOfDay" => raw_time_of_day_element = Some(value),
                "when" => raw_when = Some(value),
                "_when" => raw_when_element = Some(value),
                "offset" => raw_offset = Some(value),
                "_offset" => raw_offset_element = Some(value),
                other => {
                    return path.with(other, |path| {
                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
                    });
                }
            }
        }
        let field_id = raw_id
            .map(|value| {
                path.with("id", |path| {
                    let value = super::super::codec::expect_single(value, path)?;
                    super::super::codec::expect_string(value, path)
                })
            })
            .transpose()?;
        let mut field_extension = Vec::new();
        if let Some(raw) = raw_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_extension.push(path.with_index("extension", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_bounds = match raw_bounds.suffix {
            None => None,
            Some(suffix) => Some(path.with("bounds", |path| {
                TimingRepeatBounds::from_json_parts(
                    suffix,
                    raw_bounds.value,
                    raw_bounds.element,
                    path,
                )
            })?),
        };
        let field_count = match (raw_count, raw_count_element) {
            (None, None) => None,
            (value, element) => Some(path.with("count", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_count_max = match (raw_count_max, raw_count_max_element) {
            (None, None) => None,
            (value, element) => Some(path.with("countMax", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_duration = match (raw_duration, raw_duration_element) {
            (None, None) => None,
            (value, element) => Some(path.with("duration", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_duration_max = match (raw_duration_max, raw_duration_max_element) {
            (None, None) => None,
            (value, element) => Some(path.with("durationMax", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_duration_unit = match (raw_duration_unit, raw_duration_unit_element) {
            (None, None) => None,
            (value, element) => Some(path.with("durationUnit", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_frequency = match (raw_frequency, raw_frequency_element) {
            (None, None) => None,
            (value, element) => Some(path.with("frequency", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_frequency_max = match (raw_frequency_max, raw_frequency_max_element) {
            (None, None) => None,
            (value, element) => Some(path.with("frequencyMax", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_period = match (raw_period, raw_period_element) {
            (None, None) => None,
            (value, element) => Some(path.with("period", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_period_max = match (raw_period_max, raw_period_max_element) {
            (None, None) => None,
            (value, element) => Some(path.with("periodMax", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_period_unit = match (raw_period_unit, raw_period_unit_element) {
            (None, None) => None,
            (value, element) => Some(path.with("periodUnit", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let mut field_day_of_week = Vec::new();
        for (index, (value, element)) in
            super::super::codec::pair_arrays(raw_day_of_week, raw_day_of_week_element, path)?
                .into_iter()
                .enumerate()
        {
            field_day_of_week.push(path.with_index("dayOfWeek", index, |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?);
        }
        let mut field_time_of_day = Vec::new();
        for (index, (value, element)) in
            super::super::codec::pair_arrays(raw_time_of_day, raw_time_of_day_element, path)?
                .into_iter()
                .enumerate()
        {
            field_time_of_day.push(path.with_index("timeOfDay", index, |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?);
        }
        let mut field_when = Vec::new();
        for (index, (value, element)) in
            super::super::codec::pair_arrays(raw_when, raw_when_element, path)?
                .into_iter()
                .enumerate()
        {
            field_when.push(path.with_index("when", index, |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?);
        }
        let field_offset = match (raw_offset, raw_offset_element) {
            (None, None) => None,
            (value, element) => Some(path.with("offset", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        Ok(Self {
            id: field_id,
            extension: field_extension,
            bounds: field_bounds,
            count: field_count,
            count_max: field_count_max,
            duration: field_duration,
            duration_max: field_duration_max,
            duration_unit: field_duration_unit,
            frequency: field_frequency,
            frequency_max: field_frequency_max,
            period: field_period,
            period_max: field_period_max,
            period_unit: field_period_unit,
            day_of_week: field_day_of_week,
            time_of_day: field_time_of_day,
            when: field_when,
            offset: field_offset,
        })
    }
}

impl serde::Serialize for TimingRepeat {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let mut map = serde::Serializer::serialize_map(serializer, None)?;
        if let Some(item) = &self.count {
            super::super::codec::element_entry(&mut map, "_count", item)?;
        }
        if let Some(item) = &self.count_max {
            super::super::codec::element_entry(&mut map, "_countMax", item)?;
        }
        super::super::codec::element_list_entry(&mut map, "_dayOfWeek", &self.day_of_week)?;
        if let Some(item) = &self.duration {
            super::super::codec::element_entry(&mut map, "_duration", item)?;
        }
        if let Some(item) = &self.duration_max {
            super::super::codec::element_entry(&mut map, "_durationMax", item)?;
        }
        if let Some(item) = &self.duration_unit {
            super::super::codec::element_entry(&mut map, "_durationUnit", item)?;
        }
        if let Some(item) = &self.frequency {
            super::super::codec::element_entry(&mut map, "_frequency", item)?;
        }
        if let Some(item) = &self.frequency_max {
            super::super::codec::element_entry(&mut map, "_frequencyMax", item)?;
        }
        if let Some(item) = &self.offset {
            super::super::codec::element_entry(&mut map, "_offset", item)?;
        }
        if let Some(item) = &self.period {
            super::super::codec::element_entry(&mut map, "_period", item)?;
        }
        if let Some(item) = &self.period_max {
            super::super::codec::element_entry(&mut map, "_periodMax", item)?;
        }
        if let Some(item) = &self.period_unit {
            super::super::codec::element_entry(&mut map, "_periodUnit", item)?;
        }
        super::super::codec::element_list_entry(&mut map, "_timeOfDay", &self.time_of_day)?;
        super::super::codec::element_list_entry(&mut map, "_when", &self.when)?;
        match &self.bounds {
            Some(TimingRepeatBounds::Duration(inner)) => {
                serde::ser::SerializeMap::serialize_entry(
                    &mut map,
                    "boundsDuration",
                    inner.as_ref(),
                )?;
            }
            Some(TimingRepeatBounds::Period(inner)) => {
                serde::ser::SerializeMap::serialize_entry(
                    &mut map,
                    "boundsPeriod",
                    inner.as_ref(),
                )?;
            }
            Some(TimingRepeatBounds::Range(inner)) => {
                serde::ser::SerializeMap::serialize_entry(&mut map, "boundsRange", inner.as_ref())?;
            }
            None => {}
        }
        if let Some(item) = &self.count {
            super::super::codec::value_entry(&mut map, "count", item)?;
        }
        if let Some(item) = &self.count_max {
            super::super::codec::value_entry(&mut map, "countMax", item)?;
        }
        super::super::codec::value_list_entry(&mut map, "dayOfWeek", &self.day_of_week)?;
        if let Some(item) = &self.duration {
            super::super::codec::value_entry(&mut map, "duration", item)?;
        }
        if let Some(item) = &self.duration_max {
            super::super::codec::value_entry(&mut map, "durationMax", item)?;
        }
        if let Some(item) = &self.duration_unit {
            super::super::codec::value_entry(&mut map, "durationUnit", item)?;
        }
        if !self.extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
        }
        if let Some(item) = &self.frequency {
            super::super::codec::value_entry(&mut map, "frequency", item)?;
        }
        if let Some(item) = &self.frequency_max {
            super::super::codec::value_entry(&mut map, "frequencyMax", item)?;
        }
        if let Some(v) = &self.id {
            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
        }
        if let Some(item) = &self.offset {
            super::super::codec::value_entry(&mut map, "offset", item)?;
        }
        if let Some(item) = &self.period {
            super::super::codec::value_entry(&mut map, "period", item)?;
        }
        if let Some(item) = &self.period_max {
            super::super::codec::value_entry(&mut map, "periodMax", item)?;
        }
        if let Some(item) = &self.period_unit {
            super::super::codec::value_entry(&mut map, "periodUnit", item)?;
        }
        super::super::codec::value_list_entry(&mut map, "timeOfDay", &self.time_of_day)?;
        super::super::codec::value_list_entry(&mut map, "when", &self.when)?;
        serde::ser::SerializeMap::end(map)
    }
}

impl<'de> serde::Deserialize<'de> for TimingRepeat {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
        let mut path = super::super::codec::Path::root("TimingRepeat");
        let object =
            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
    }
}

/// The \`bounds\[x\]\` choice of \`TimingRepeat\`.
///
/// Either a duration for the length of the timing schedule, a range of possible
/// length, or outer bounds for start and/or end limits of the timing schedule.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TimingRepeatBounds {
    /// The `Duration` form.
    Duration(Box<super::duration::Duration>),
    /// The `Range` form.
    Range(Box<super::range::Range>),
    /// The `Period` form.
    Period(Box<super::period::Period>),
}

impl TimingRepeatBounds {
    /// The key suffix, the value part, and the `_name` part of this form.
    ///
    /// # Errors
    ///
    /// Returns [`super::super::codec::EncodeError`] when a held value has no JSON form.
    pub fn to_json_parts(
        &self,
    ) -> Result<
        (
            &'static str,
            Option<super::super::codec::Value>,
            Option<super::super::codec::Value>,
        ),
        super::super::codec::EncodeError,
    > {
        match self {
            Self::Duration(inner) => Ok((
                "Duration",
                Some(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(inner.as_ref())?,
                )),
                None,
            )),
            Self::Range(inner) => Ok((
                "Range",
                Some(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(inner.as_ref())?,
                )),
                None,
            )),
            Self::Period(inner) => Ok((
                "Period",
                Some(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(inner.as_ref())?,
                )),
                None,
            )),
        }
    }

    /// Decodes the form named by `suffix` from its value and `_name` parts.
    ///
    /// # Errors
    ///
    /// Returns [`super::super::codec::DecodeError`] for an unknown suffix or a malformed part.
    pub fn from_json_parts(
        suffix: &str,
        value: Option<&super::super::codec::Value>,
        element: Option<&super::super::codec::Value>,
        path: &mut super::super::codec::Path,
    ) -> Result<Self, super::super::codec::DecodeError> {
        match suffix {
            "Duration" => {
                if element.is_some() {
                    return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
                        expected: "no underscore form for a complex type",
                    }));
                }
                let value = value.ok_or_else(|| {
                    path.error(super::super::codec::DecodeErrorKind::MissingProperty)
                })?;
                let inner = super::super::codec::Json::from_json(
                    super::super::codec::expect_object(
                        super::super::codec::expect_single(value, path)?,
                        path,
                    )?,
                    path,
                )?;
                Ok(Self::Duration(Box::new(inner)))
            }
            "Range" => {
                if element.is_some() {
                    return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
                        expected: "no underscore form for a complex type",
                    }));
                }
                let value = value.ok_or_else(|| {
                    path.error(super::super::codec::DecodeErrorKind::MissingProperty)
                })?;
                let inner = super::super::codec::Json::from_json(
                    super::super::codec::expect_object(
                        super::super::codec::expect_single(value, path)?,
                        path,
                    )?,
                    path,
                )?;
                Ok(Self::Range(Box::new(inner)))
            }
            "Period" => {
                if element.is_some() {
                    return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
                        expected: "no underscore form for a complex type",
                    }));
                }
                let value = value.ok_or_else(|| {
                    path.error(super::super::codec::DecodeErrorKind::MissingProperty)
                })?;
                let inner = super::super::codec::Json::from_json(
                    super::super::codec::expect_object(
                        super::super::codec::expect_single(value, path)?,
                        path,
                    )?,
                    path,
                )?;
                Ok(Self::Period(Box::new(inner)))
            }
            _ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
        }
    }
}