1#![cfg_attr(
4 not(feature = "builders"),
5 allow(
6 dead_code,
7 unused_imports,
8 unused_macros,
9 reason = "Many impls missing without builders"
10 )
11)]
12
13use std::{
14 fmt::{Debug, Display},
15 str::FromStr,
16};
17
18use fhir_model::for_all_versions;
19use serde::{Serialize, de::DeserializeOwned};
20
21use crate::{
22 extensions::{BundleEntryExt, BundleExt, GenericResource, ParametersExt, ReferenceExt},
23 utils::Sealed,
24};
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
28pub struct FhirStu3;
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31pub struct FhirR4B;
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
34pub struct FhirR5;
35
36#[cfg(feature = "r5")]
37pub type DefaultVersion = FhirR5;
39#[cfg(all(not(feature = "r5"), feature = "r4b"))]
40pub type DefaultVersion = FhirR4B;
42#[cfg(all(not(feature = "r5"), not(feature = "r4b"), feature = "stu3"))]
43pub type DefaultVersion = FhirStu3;
45
46macro_rules! fhir_version {
49 (stu3) => {
50 $crate::version::FhirStu3
51 };
52 (r4b) => {
53 $crate::version::FhirR4B
54 };
55 (r5) => {
56 $crate::version::FhirR5
57 };
58}
59pub(crate) use fhir_version;
60
61pub trait FhirVersion: Sealed + Unpin + Send + Sync + 'static {
64 const VERSION: &'static str;
66 const MIME_TYPE: &'static str;
68
69 type ResourceType: Serialize
71 + DeserializeOwned
72 + Debug
73 + FromStr
74 + AsRef<str>
75 + Display
76 + Clone
77 + Copy
78 + PartialEq
79 + Eq
80 + Unpin
81 + Send
82 + Sync;
83 type Resource: GenericResource
85 + Serialize
86 + DeserializeOwned
87 + Debug
88 + Clone
89 + PartialEq
90 + Unpin
91 + Send
92 + Sync;
93
94 type Bundle: BundleExt<Entry: BundleEntryExt<Resource = Self::Resource>>
96 + Serialize
97 + DeserializeOwned
98 + Debug
99 + Clone
100 + PartialEq
101 + Unpin
102 + Send
103 + Sync;
104 type CapabilityStatement: Serialize
106 + DeserializeOwned
107 + Debug
108 + Clone
109 + PartialEq
110 + Unpin
111 + Send
112 + Sync;
113 type OperationOutcome: Serialize
115 + DeserializeOwned
116 + Debug
117 + Clone
118 + PartialEq
119 + Unpin
120 + Send
121 + Sync;
122 type Parameters: ParametersExt
124 + Serialize
125 + DeserializeOwned
126 + Debug
127 + Clone
128 + PartialEq
129 + Unpin
130 + Send
131 + Sync;
132
133 type Reference: ReferenceExt
135 + Serialize
136 + DeserializeOwned
137 + Debug
138 + Clone
139 + PartialEq
140 + Unpin
141 + Send
142 + Sync;
143
144 type SearchComparator: Serialize
146 + DeserializeOwned
147 + Debug
148 + FromStr
149 + AsRef<str>
150 + Display
151 + Clone
152 + Copy
153 + PartialEq
154 + Eq
155 + Unpin
156 + Send
157 + Sync;
158}
159
160impl Sealed for FhirStu3 {}
161impl Sealed for FhirR4B {}
162impl Sealed for FhirR5 {}
163
164macro_rules! impl_fhir_version {
166 ($version:ident) => {
167 use fhir_model::$version;
168
169 impl FhirVersion for fhir_version!($version) {
170 const VERSION: &'static str = $version::VERSION;
171 const MIME_TYPE: &'static str = $version::JSON_MIME_TYPE;
172
173 type ResourceType = $version::resources::ResourceType;
174 type Resource = $version::resources::Resource;
175
176 type Bundle = $version::resources::Bundle;
177 type CapabilityStatement = $version::resources::CapabilityStatement;
178 type OperationOutcome = $version::resources::OperationOutcome;
179 type Parameters = $version::resources::Parameters;
180
181 type Reference = $version::types::Reference;
182
183 type SearchComparator = $version::codes::SearchComparator;
184 }
185 };
186}
187#[cfg(feature = "builders")] for_all_versions!(impl_fhir_version);