0
# FHIR Data Types
1
2
Comprehensive set of FHIR primitive and complex data types with full validation according to FHIR specification. These types form the building blocks for all FHIR resources and ensure data integrity and interoperability.
3
4
## Capabilities
5
6
### Primitive Data Types
7
8
Basic data types representing single values with FHIR-specific validation rules and constraints.
9
10
```python { .api }
11
# Boolean type
12
class Boolean:
13
"""FHIR boolean - true or false values"""
14
15
# String types
16
class String:
17
"""Unicode string with FHIR length and character constraints"""
18
19
class Code:
20
"""Coded value from a terminology system"""
21
22
class Id:
23
"""Logical identifier for FHIR resources and elements"""
24
25
class Uri:
26
"""Uniform Resource Identifier"""
27
28
class Url:
29
"""Uniform Resource Locator"""
30
31
class Oid:
32
"""Object Identifier (dot-separated numeric identifier)"""
33
34
class Uuid:
35
"""Universally Unique Identifier"""
36
37
class Markdown:
38
"""Markdown-formatted text content"""
39
40
class Base64Binary:
41
"""Base64 encoded binary data"""
42
43
# Numeric types
44
class Decimal:
45
"""Decimal number with arbitrary precision"""
46
47
class Integer:
48
"""32-bit signed integer"""
49
50
class UnsignedInt:
51
"""Unsigned 32-bit integer (0 or positive)"""
52
53
class PositiveInt:
54
"""Positive integer (> 0)"""
55
56
# Date/time types
57
class Date:
58
"""Date in YYYY-MM-DD format"""
59
60
class DateTime:
61
"""Date and time with optional timezone"""
62
63
class Instant:
64
"""Precise timestamp in ISO 8601 format"""
65
66
class Time:
67
"""Time of day in HH:MM:SS format"""
68
```
69
70
**Usage Examples:**
71
72
```python
73
from fhir.resources.patient import Patient
74
from fhir.resources.datetime import DateTime
75
76
# Primitive types are used within resources
77
patient = Patient(
78
active=True, # Boolean
79
id="patient-123", # Id
80
birthDate="1990-01-15" # Date
81
)
82
83
# DateTime with timezone
84
from datetime import datetime
85
now = datetime.now().isoformat()
86
```
87
88
### Complex Data Types
89
90
Structured data types containing multiple elements that represent complex healthcare concepts.
91
92
```python { .api }
93
class HumanName:
94
"""Person name with components and use context"""
95
def __init__(
96
self,
97
use: Optional[str] = None, # usual | official | temp | nickname | anonymous | old | maiden
98
text: Optional[str] = None,
99
family: Optional[str] = None,
100
given: Optional[List[str]] = None,
101
prefix: Optional[List[str]] = None,
102
suffix: Optional[List[str]] = None,
103
period: Optional["Period"] = None
104
): ...
105
106
class Address:
107
"""Physical/postal address"""
108
def __init__(
109
self,
110
use: Optional[str] = None, # home | work | temp | old | billing
111
type: Optional[str] = None, # postal | physical | both
112
text: Optional[str] = None,
113
line: Optional[List[str]] = None,
114
city: Optional[str] = None,
115
district: Optional[str] = None,
116
state: Optional[str] = None,
117
postalCode: Optional[str] = None,
118
country: Optional[str] = None,
119
period: Optional["Period"] = None
120
): ...
121
122
class ContactPoint:
123
"""Phone, email, or other contact method"""
124
def __init__(
125
self,
126
system: Optional[str] = None, # phone | fax | email | pager | url | sms | other
127
value: Optional[str] = None,
128
use: Optional[str] = None, # home | work | temp | old | mobile
129
rank: Optional[int] = None,
130
period: Optional["Period"] = None
131
): ...
132
133
class Identifier:
134
"""Business identifier for resources"""
135
def __init__(
136
self,
137
use: Optional[str] = None, # usual | official | temp | secondary | old
138
type: Optional["CodeableConcept"] = None,
139
system: Optional[str] = None,
140
value: Optional[str] = None,
141
period: Optional["Period"] = None,
142
assigner: Optional["Reference"] = None
143
): ...
144
145
class CodeableConcept:
146
"""Coded concept with text"""
147
def __init__(
148
self,
149
coding: Optional[List["Coding"]] = None,
150
text: Optional[str] = None
151
): ...
152
153
class Coding:
154
"""Code from a terminology system"""
155
def __init__(
156
self,
157
system: Optional[str] = None,
158
version: Optional[str] = None,
159
code: Optional[str] = None,
160
display: Optional[str] = None,
161
userSelected: Optional[bool] = None
162
): ...
163
164
class Quantity:
165
"""Measured amount with units"""
166
def __init__(
167
self,
168
value: Optional[float] = None,
169
comparator: Optional[str] = None, # < | <= | >= | >
170
unit: Optional[str] = None,
171
system: Optional[str] = None,
172
code: Optional[str] = None
173
): ...
174
175
class Period:
176
"""Time period with start and end"""
177
def __init__(
178
self,
179
start: Optional[str] = None, # DateTime
180
end: Optional[str] = None # DateTime
181
): ...
182
183
class Range:
184
"""Range with low and high values"""
185
def __init__(
186
self,
187
low: Optional["Quantity"] = None,
188
high: Optional["Quantity"] = None
189
): ...
190
191
class Ratio:
192
"""Ratio of two quantities"""
193
def __init__(
194
self,
195
numerator: Optional["Quantity"] = None,
196
denominator: Optional["Quantity"] = None
197
): ...
198
199
class Attachment:
200
"""File attachment with metadata"""
201
def __init__(
202
self,
203
contentType: Optional[str] = None,
204
language: Optional[str] = None,
205
data: Optional[bytes] = None,
206
url: Optional[str] = None,
207
size: Optional[int] = None,
208
hash: Optional[bytes] = None,
209
title: Optional[str] = None,
210
creation: Optional[str] = None # DateTime
211
): ...
212
213
class Reference:
214
"""Reference to another resource"""
215
def __init__(
216
self,
217
reference: Optional[str] = None,
218
type: Optional[str] = None,
219
identifier: Optional["Identifier"] = None,
220
display: Optional[str] = None
221
): ...
222
223
class Annotation:
224
"""Text note with author attribution"""
225
def __init__(
226
self,
227
authorReference: Optional["Reference"] = None,
228
authorString: Optional[str] = None,
229
time: Optional[str] = None, # DateTime
230
text: str
231
): ...
232
```
233
234
**Usage Examples:**
235
236
```python
237
from fhir.resources.patient import Patient
238
from fhir.resources.humanname import HumanName
239
from fhir.resources.address import Address
240
from fhir.resources.contactpoint import ContactPoint
241
from fhir.resources.identifier import Identifier
242
243
# Create a patient with complex data types
244
patient = Patient(
245
identifier=[
246
Identifier(
247
use="usual",
248
system="http://hospital.example.org/patients",
249
value="MRN-123456"
250
)
251
],
252
name=[
253
HumanName(
254
use="official",
255
family="Doe",
256
given=["John", "Michael"],
257
prefix=["Mr."]
258
)
259
],
260
address=[
261
Address(
262
use="home",
263
type="postal",
264
line=["123 Main Street", "Apt 4B"],
265
city="Springfield",
266
state="IL",
267
postalCode="62701",
268
country="US"
269
)
270
],
271
telecom=[
272
ContactPoint(
273
system="phone",
274
value="555-123-4567",
275
use="home"
276
),
277
ContactPoint(
278
system="email",
279
value="john.doe@example.com",
280
use="home"
281
)
282
]
283
)
284
```
285
286
### Specialized Data Types
287
288
Advanced data types for specific clinical and administrative purposes.
289
290
```python { .api }
291
class Dosage:
292
"""Medication dosage instructions"""
293
def __init__(
294
self,
295
sequence: Optional[int] = None,
296
text: Optional[str] = None,
297
additionalInstruction: Optional[List["CodeableConcept"]] = None,
298
patientInstruction: Optional[str] = None,
299
timing: Optional["Timing"] = None,
300
asNeededBoolean: Optional[bool] = None,
301
asNeededCodeableConcept: Optional["CodeableConcept"] = None,
302
site: Optional["CodeableConcept"] = None,
303
route: Optional["CodeableConcept"] = None,
304
method: Optional["CodeableConcept"] = None,
305
doseAndRate: Optional[List["DosageDoseAndRate"]] = None
306
): ...
307
308
class Timing:
309
"""Timing schedule for events"""
310
def __init__(
311
self,
312
event: Optional[List[str]] = None, # List of DateTime
313
repeat: Optional["TimingRepeat"] = None,
314
code: Optional["CodeableConcept"] = None
315
): ...
316
317
class Money:
318
"""Monetary amount with currency"""
319
def __init__(
320
self,
321
value: Optional[float] = None,
322
currency: Optional[str] = None # 3-letter ISO 4217 currency code
323
): ...
324
325
class Signature:
326
"""Digital signature"""
327
def __init__(
328
self,
329
type: List["Coding"],
330
when: str, # Instant
331
who: "Reference",
332
onBehalfOf: Optional["Reference"] = None,
333
targetFormat: Optional[str] = None,
334
sigFormat: Optional[str] = None,
335
data: Optional[bytes] = None
336
): ...
337
```
338
339
### Backbone Elements
340
341
Structural elements that form the backbone of resource definitions.
342
343
```python { .api }
344
class Extension:
345
"""FHIR extension mechanism"""
346
def __init__(
347
self,
348
url: str,
349
valueAddress: Optional["Address"] = None,
350
valueAge: Optional["Age"] = None,
351
valueAnnotation: Optional["Annotation"] = None,
352
valueAttachment: Optional["Attachment"] = None,
353
valueBase64Binary: Optional[bytes] = None,
354
valueBoolean: Optional[bool] = None,
355
valueCanonical: Optional[str] = None,
356
valueCode: Optional[str] = None,
357
# ... many more value[x] options
358
extension: Optional[List["Extension"]] = None
359
): ...
360
361
class Meta:
362
"""Resource metadata"""
363
def __init__(
364
self,
365
versionId: Optional[str] = None,
366
lastUpdated: Optional[str] = None, # Instant
367
source: Optional[str] = None,
368
profile: Optional[List[str]] = None,
369
security: Optional[List["Coding"]] = None,
370
tag: Optional[List["Coding"]] = None
371
): ...
372
373
class Narrative:
374
"""Human-readable narrative"""
375
def __init__(
376
self,
377
status: str, # generated | extensions | additional | empty
378
div: str # XHTML content
379
): ...
380
```