fhirkit 0.1.0

FHIR R4 for Rust: typed models for every resource and datatype generated from the official specification, lossless JSON with path-precise validation, typed search queries, FHIRPath
Documentation
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
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `MedicationKnowledge` resource.

#![allow(
    unused_imports,
    clippy::large_enum_variant,
    clippy::too_many_lines,
    clippy::doc_markdown
)]

use crate::decode::{
    choice_key, required, required_list, resource_type, Choice, Decoder, FhirJson, Obj, ObjWriter,
};
use crate::json::Json;
use crate::primitive::{Decimal, Kind, Primitive};
use crate::r4::*;

/// Information about a medication that is used to support knowledge.
///
/// FHIR path: `MedicationKnowledge`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledge {
    /// `id` (0..1): Logical id of this artifact
    pub id: Option<String>,
    /// `meta` (0..1): Metadata about the resource
    pub meta: Option<Meta>,
    /// `implicitRules` (0..1): A set of rules under which this content was created
    pub implicit_rules: Option<Primitive<String>>,
    /// `language` (0..1): Language of the resource content
    pub language: Option<Primitive<String>>,
    /// `text` (0..1): Text summary of the resource, for human interpretation
    pub text: Option<Narrative>,
    /// `contained` (0..*): Contained, inline Resources
    pub contained: Vec<Resource>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored
    pub modifier_extension: Vec<Extension>,
    /// `code` (0..1): Code that identifies this medication
    pub code: Option<CodeableConcept>,
    /// `status` (0..1): active | inactive | entered-in-error
    pub status: Option<Primitive<String>>,
    /// `manufacturer` (0..1): Manufacturer of the item
    pub manufacturer: Option<Reference>,
    /// `doseForm` (0..1): powder | tablets | capsule +
    pub dose_form: Option<CodeableConcept>,
    /// `amount` (0..1): Amount of drug in package
    pub amount: Option<Quantity>,
    /// `synonym` (0..*): Additional names for a medication
    pub synonym: Vec<Primitive<String>>,
    /// `relatedMedicationKnowledge` (0..*): Associated or related medication information
    pub related_medication_knowledge: Vec<MedicationKnowledgeRelatedMedicationKnowledge>,
    /// `associatedMedication` (0..*): A medication resource that is associated with this medication
    pub associated_medication: Vec<Reference>,
    /// `productType` (0..*): Category of the medication or product
    pub product_type: Vec<CodeableConcept>,
    /// `monograph` (0..*): Associated documentation about the medication
    pub monograph: Vec<MedicationKnowledgeMonograph>,
    /// `ingredient` (0..*): Active or inactive ingredient
    pub ingredient: Vec<MedicationKnowledgeIngredient>,
    /// `preparationInstruction` (0..1): The instructions for preparing the medication
    pub preparation_instruction: Option<Primitive<String>>,
    /// `intendedRoute` (0..*): The intended or approved route of administration
    pub intended_route: Vec<CodeableConcept>,
    /// `cost` (0..*): The pricing of the medication
    pub cost: Vec<MedicationKnowledgeCost>,
    /// `monitoringProgram` (0..*): Program under which a medication is reviewed
    pub monitoring_program: Vec<MedicationKnowledgeMonitoringProgram>,
    /// `administrationGuidelines` (0..*): Guidelines for administration of the medication
    pub administration_guidelines: Vec<MedicationKnowledgeAdministrationGuidelines>,
    /// `medicineClassification` (0..*): Categorization of the medication within a formulary or classification system
    pub medicine_classification: Vec<MedicationKnowledgeMedicineClassification>,
    /// `packaging` (0..1): Details about packaged medications
    pub packaging: Option<MedicationKnowledgePackaging>,
    /// `drugCharacteristic` (0..*): Specifies descriptive properties of the medicine
    pub drug_characteristic: Vec<MedicationKnowledgeDrugCharacteristic>,
    /// `contraindication` (0..*): Potential clinical issue with or between medication(s)
    pub contraindication: Vec<Reference>,
    /// `regulatory` (0..*): Regulatory information about a medication
    pub regulatory: Vec<MedicationKnowledgeRegulatory>,
    /// `kinetics` (0..*): The time course of drug absorption, distribution, metabolism and excretion of a medication from the body
    pub kinetics: Vec<MedicationKnowledgeKinetics>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "MedicationKnowledge");
        let r = MedicationKnowledge {
            id: o.string(d, "id"),
            meta: o.one(d, "meta"),
            implicit_rules: o.prim(d, "implicitRules", Kind::Uri),
            language: o.prim(d, "language", Kind::Code),
            text: o.one(d, "text"),
            contained: o.list(d, "contained"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            code: o.one(d, "code"),
            status: o.prim(d, "status", Kind::Code),
            manufacturer: o.one(d, "manufacturer"),
            dose_form: o.one(d, "doseForm"),
            amount: o.one(d, "amount"),
            synonym: o.prim_list(d, "synonym", Kind::String),
            related_medication_knowledge: o.list(d, "relatedMedicationKnowledge"),
            associated_medication: o.list(d, "associatedMedication"),
            product_type: o.list(d, "productType"),
            monograph: o.list(d, "monograph"),
            ingredient: o.list(d, "ingredient"),
            preparation_instruction: o.prim(d, "preparationInstruction", Kind::Markdown),
            intended_route: o.list(d, "intendedRoute"),
            cost: o.list(d, "cost"),
            monitoring_program: o.list(d, "monitoringProgram"),
            administration_guidelines: o.list(d, "administrationGuidelines"),
            medicine_classification: o.list(d, "medicineClassification"),
            packaging: o.one(d, "packaging"),
            drug_characteristic: o.list(d, "drugCharacteristic"),
            contraindication: o.list(d, "contraindication"),
            regulatory: o.list(d, "regulatory"),
            kinetics: o.list(d, "kinetics"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("MedicationKnowledge".into()));
        w.string("id", &self.id);
        w.one("meta", &self.meta);
        w.prim("implicitRules", &self.implicit_rules);
        w.prim("language", &self.language);
        w.one("text", &self.text);
        w.list("contained", &self.contained);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("code", &self.code);
        w.prim("status", &self.status);
        w.one("manufacturer", &self.manufacturer);
        w.one("doseForm", &self.dose_form);
        w.one("amount", &self.amount);
        w.prim_list("synonym", &self.synonym);
        w.list(
            "relatedMedicationKnowledge",
            &self.related_medication_knowledge,
        );
        w.list("associatedMedication", &self.associated_medication);
        w.list("productType", &self.product_type);
        w.list("monograph", &self.monograph);
        w.list("ingredient", &self.ingredient);
        w.prim("preparationInstruction", &self.preparation_instruction);
        w.list("intendedRoute", &self.intended_route);
        w.list("cost", &self.cost);
        w.list("monitoringProgram", &self.monitoring_program);
        w.list("administrationGuidelines", &self.administration_guidelines);
        w.list("medicineClassification", &self.medicine_classification);
        w.one("packaging", &self.packaging);
        w.list("drugCharacteristic", &self.drug_characteristic);
        w.list("contraindication", &self.contraindication);
        w.list("regulatory", &self.regulatory);
        w.list("kinetics", &self.kinetics);
        w.finish()
    }
}

/// Associated or related medication information
///
/// FHIR path: `MedicationKnowledge.relatedMedicationKnowledge`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeRelatedMedicationKnowledge {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `type` (1..1): Category of medicationKnowledge
    pub type_: Option<CodeableConcept>,
    /// `reference` (1..*): Associated documentation about the associated medication knowledge
    pub reference: Vec<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeRelatedMedicationKnowledge {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            reference: o.list(d, "reference"),
        };
        required(d, "type", &r.type_);
        required_list(d, "reference", &r.reference, 1);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("type", &self.type_);
        w.list("reference", &self.reference);
        w.finish()
    }
}

/// Associated documentation about the medication
///
/// FHIR path: `MedicationKnowledge.monograph`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeMonograph {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `type` (0..1): The category of medication document
    pub type_: Option<CodeableConcept>,
    /// `source` (0..1): Associated documentation about the medication
    pub source: Option<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeMonograph {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            source: o.one(d, "source"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("type", &self.type_);
        w.one("source", &self.source);
        w.finish()
    }
}

/// Active or inactive ingredient
///
/// FHIR path: `MedicationKnowledge.ingredient`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeIngredient {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `item[x]` (1..1): Medication(s) or substance(s) contained in the medication
    pub item: Option<MedicationKnowledgeIngredientItem>,
    /// `isActive` (0..1): Active ingredient indicator
    pub is_active: Option<Primitive<bool>>,
    /// `strength` (0..1): Quantity of ingredient present
    pub strength: Option<Ratio>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeIngredient {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            item: o.choice(d, "item"),
            is_active: o.prim(d, "isActive", Kind::Boolean),
            strength: o.one(d, "strength"),
        };
        required(d, "item[x]", &r.item);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.choice("item", &self.item);
        w.prim("isActive", &self.is_active);
        w.one("strength", &self.strength);
        w.finish()
    }
}

/// The pricing of the medication
///
/// FHIR path: `MedicationKnowledge.cost`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeCost {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `type` (1..1): The category of the cost information
    pub type_: Option<CodeableConcept>,
    /// `source` (0..1): The source or owner for the price information
    pub source: Option<Primitive<String>>,
    /// `cost` (1..1): The price of the medication
    pub cost: Option<Money>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeCost {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            source: o.prim(d, "source", Kind::String),
            cost: o.one(d, "cost"),
        };
        required(d, "type", &r.type_);
        required(d, "cost", &r.cost);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("type", &self.type_);
        w.prim("source", &self.source);
        w.one("cost", &self.cost);
        w.finish()
    }
}

/// Program under which a medication is reviewed
///
/// FHIR path: `MedicationKnowledge.monitoringProgram`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeMonitoringProgram {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `type` (0..1): Type of program under which the medication is monitored
    pub type_: Option<CodeableConcept>,
    /// `name` (0..1): Name of the reviewing program
    pub name: Option<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeMonitoringProgram {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            name: o.prim(d, "name", Kind::String),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("type", &self.type_);
        w.prim("name", &self.name);
        w.finish()
    }
}

/// Guidelines for administration of the medication
///
/// FHIR path: `MedicationKnowledge.administrationGuidelines`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeAdministrationGuidelines {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `dosage` (0..*): Dosage for the medication for the specific guidelines
    pub dosage: Vec<MedicationKnowledgeAdministrationGuidelinesDosage>,
    /// `indication[x]` (0..1): Indication for use that apply to the specific administration guidelines
    pub indication: Option<MedicationKnowledgeAdministrationGuidelinesIndication>,
    /// `patientCharacteristics` (0..*): Characteristics of the patient that are relevant to the administration guidelines
    pub patient_characteristics:
        Vec<MedicationKnowledgeAdministrationGuidelinesPatientCharacteristics>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeAdministrationGuidelines {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            dosage: o.list(d, "dosage"),
            indication: o.choice(d, "indication"),
            patient_characteristics: o.list(d, "patientCharacteristics"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.list("dosage", &self.dosage);
        w.choice("indication", &self.indication);
        w.list("patientCharacteristics", &self.patient_characteristics);
        w.finish()
    }
}

/// Dosage for the medication for the specific guidelines
///
/// FHIR path: `MedicationKnowledge.administrationGuidelines.dosage`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeAdministrationGuidelinesDosage {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `type` (1..1): Type of dosage
    pub type_: Option<CodeableConcept>,
    /// `dosage` (1..*): Dosage for the medication for the specific guidelines
    pub dosage: Vec<Dosage>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeAdministrationGuidelinesDosage {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            dosage: o.list(d, "dosage"),
        };
        required(d, "type", &r.type_);
        required_list(d, "dosage", &r.dosage, 1);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("type", &self.type_);
        w.list("dosage", &self.dosage);
        w.finish()
    }
}

/// Characteristics of the patient that are relevant to the administration guidelines
///
/// FHIR path: `MedicationKnowledge.administrationGuidelines.patientCharacteristics`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeAdministrationGuidelinesPatientCharacteristics {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `characteristic[x]` (1..1): Specific characteristic that is relevant to the administration guideline
    pub characteristic:
        Option<MedicationKnowledgeAdministrationGuidelinesPatientCharacteristicsCharacteristic>,
    /// `value` (0..*): The specific characteristic
    pub value: Vec<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeAdministrationGuidelinesPatientCharacteristics {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            characteristic: o.choice(d, "characteristic"),
            value: o.prim_list(d, "value", Kind::String),
        };
        required(d, "characteristic[x]", &r.characteristic);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.choice("characteristic", &self.characteristic);
        w.prim_list("value", &self.value);
        w.finish()
    }
}

/// Categorization of the medication within a formulary or classification system
///
/// FHIR path: `MedicationKnowledge.medicineClassification`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeMedicineClassification {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `type` (1..1): The type of category for the medication (for example, therapeutic classification, therapeutic sub-classification)
    pub type_: Option<CodeableConcept>,
    /// `classification` (0..*): Specific category assigned to the medication
    pub classification: Vec<CodeableConcept>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeMedicineClassification {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            classification: o.list(d, "classification"),
        };
        required(d, "type", &r.type_);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("type", &self.type_);
        w.list("classification", &self.classification);
        w.finish()
    }
}

/// Details about packaged medications
///
/// FHIR path: `MedicationKnowledge.packaging`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgePackaging {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `type` (0..1): A code that defines the specific type of packaging that the medication can be found in
    pub type_: Option<CodeableConcept>,
    /// `quantity` (0..1): The number of product units the package would contain if fully loaded
    pub quantity: Option<Quantity>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgePackaging {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            quantity: o.one(d, "quantity"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("type", &self.type_);
        w.one("quantity", &self.quantity);
        w.finish()
    }
}

/// Specifies descriptive properties of the medicine
///
/// FHIR path: `MedicationKnowledge.drugCharacteristic`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeDrugCharacteristic {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `type` (0..1): Code specifying the type of characteristic of medication
    pub type_: Option<CodeableConcept>,
    /// `value[x]` (0..1): Description of the characteristic
    pub value: Option<MedicationKnowledgeDrugCharacteristicValue>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeDrugCharacteristic {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            value: o.choice(d, "value"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("type", &self.type_);
        w.choice("value", &self.value);
        w.finish()
    }
}

/// Regulatory information about a medication
///
/// FHIR path: `MedicationKnowledge.regulatory`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeRegulatory {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `regulatoryAuthority` (1..1): Specifies the authority of the regulation
    pub regulatory_authority: Option<Reference>,
    /// `substitution` (0..*): Specifies if changes are allowed when dispensing a medication from a regulatory perspective
    pub substitution: Vec<MedicationKnowledgeRegulatorySubstitution>,
    /// `schedule` (0..*): Specifies the schedule of a medication in jurisdiction
    pub schedule: Vec<MedicationKnowledgeRegulatorySchedule>,
    /// `maxDispense` (0..1): The maximum number of units of the medication that can be dispensed in a period
    pub max_dispense: Option<MedicationKnowledgeRegulatoryMaxDispense>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeRegulatory {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            regulatory_authority: o.one(d, "regulatoryAuthority"),
            substitution: o.list(d, "substitution"),
            schedule: o.list(d, "schedule"),
            max_dispense: o.one(d, "maxDispense"),
        };
        required(d, "regulatoryAuthority", &r.regulatory_authority);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("regulatoryAuthority", &self.regulatory_authority);
        w.list("substitution", &self.substitution);
        w.list("schedule", &self.schedule);
        w.one("maxDispense", &self.max_dispense);
        w.finish()
    }
}

/// Specifies if changes are allowed when dispensing a medication from a regulatory perspective
///
/// FHIR path: `MedicationKnowledge.regulatory.substitution`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeRegulatorySubstitution {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `type` (1..1): Specifies the type of substitution allowed
    pub type_: Option<CodeableConcept>,
    /// `allowed` (1..1): Specifies if regulation allows for changes in the medication when dispensing
    pub allowed: Option<Primitive<bool>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeRegulatorySubstitution {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            allowed: o.prim(d, "allowed", Kind::Boolean),
        };
        required(d, "type", &r.type_);
        required(d, "allowed", &r.allowed);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("type", &self.type_);
        w.prim("allowed", &self.allowed);
        w.finish()
    }
}

/// Specifies the schedule of a medication in jurisdiction
///
/// FHIR path: `MedicationKnowledge.regulatory.schedule`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeRegulatorySchedule {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `schedule` (1..1): Specifies the specific drug schedule
    pub schedule: Option<CodeableConcept>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeRegulatorySchedule {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            schedule: o.one(d, "schedule"),
        };
        required(d, "schedule", &r.schedule);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("schedule", &self.schedule);
        w.finish()
    }
}

/// The maximum number of units of the medication that can be dispensed in a period
///
/// FHIR path: `MedicationKnowledge.regulatory.maxDispense`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeRegulatoryMaxDispense {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `quantity` (1..1): The maximum number of units of the medication that can be dispensed
    pub quantity: Option<Quantity>,
    /// `period` (0..1): The period that applies to the maximum number of units
    pub period: Option<Duration>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeRegulatoryMaxDispense {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            quantity: o.one(d, "quantity"),
            period: o.one(d, "period"),
        };
        required(d, "quantity", &r.quantity);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("quantity", &self.quantity);
        w.one("period", &self.period);
        w.finish()
    }
}

/// The time course of drug absorption, distribution, metabolism and excretion of a medication from the body
///
/// FHIR path: `MedicationKnowledge.kinetics`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicationKnowledgeKinetics {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `areaUnderCurve` (0..*): The drug concentration measured at certain discrete points in time
    pub area_under_curve: Vec<Quantity>,
    /// `lethalDose50` (0..*): The median lethal dose of a drug
    pub lethal_dose50: Vec<Quantity>,
    /// `halfLifePeriod` (0..1): Time required for concentration in the body to decrease by half
    pub half_life_period: Option<Duration>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicationKnowledgeKinetics {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            area_under_curve: o.list(d, "areaUnderCurve"),
            lethal_dose50: o.list(d, "lethalDose50"),
            half_life_period: o.one(d, "halfLifePeriod"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.list("areaUnderCurve", &self.area_under_curve);
        w.list("lethalDose50", &self.lethal_dose50);
        w.one("halfLifePeriod", &self.half_life_period);
        w.finish()
    }
}

/// The types `MedicationKnowledge.ingredient.item[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum MedicationKnowledgeIngredientItem {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Reference`
    Reference(Reference),
}

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

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

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

/// The types `MedicationKnowledge.administrationGuidelines.indication[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum MedicationKnowledgeAdministrationGuidelinesIndication {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Reference`
    Reference(Reference),
}

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

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

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

/// The types `MedicationKnowledge.administrationGuidelines.patientCharacteristics.characteristic[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum MedicationKnowledgeAdministrationGuidelinesPatientCharacteristicsCharacteristic {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Quantity`
    Quantity(Quantity),
}

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

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

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

/// The types `MedicationKnowledge.drugCharacteristic.value[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum MedicationKnowledgeDrugCharacteristicValue {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `string`
    String(Primitive<String>),
    /// `Quantity`
    Quantity(Quantity),
    /// `base64Binary`
    Base64Binary(Primitive<String>),
}

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

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

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::CodeableConcept(v) => w.value(&choice_key(base, "CodeableConcept"), v),
            Self::String(v) => w.prim_value(&choice_key(base, "string"), v),
            Self::Quantity(v) => w.value(&choice_key(base, "Quantity"), v),
            Self::Base64Binary(v) => w.prim_value(&choice_key(base, "base64Binary"), v),
        }
    }
}