Commit 9cbc5ae
committed
Overhaul how date & time parsing works.
This commit breaks FHIRDate into four classes:
- FHIRDate
- FHIRDateTime
- FHIRInstant
- FHIRTime
BREAKING CHANGES:
- If consuming code were inspecting the elementProperties array and
doing a check like `element_type is FHIRDate`, that will now fail
for `datetime`, `instant`, and `time` elements. Backwards
compatibility is however maintained for checks written like
`issubclass(element_type, FHIRDate)`.
Instances have a similar resolution: `isinstance(obj, FHIRDate)` will
still work.
- If consuming code were manually creating FHIRDate objects
themselves with a time component, that will now fail with a
ValueError.
Since the first item is unavoidable if we want to fix the bugs listed
below and has a workaround that works before and after this change,
and the second item is not an expected workflow, I hope that such
breaking changes do not cause too much harm for consumers.
BUG FIXES:
- FHIR `time` fields are now correctly parsed. Previously, a time of
"10:12:14" would result in a **date** of "1001-01-01"
- Passing too much detail to a `date` field or too little detail to an
`instant` field will now correctly throw a validation error.
For example, a Patient.birthDate field with a time. Or an
Observation.issued field with just a year.
- Sub-seconds would be incorrectly chopped off of a `datetime`'s
`.isostring` (which the FHIR spec allows us to do) and an `instant`'s
`.isostring` (which the FHIR spec **does not** allow us to do).
The `.date` Python representation and the `.as_json()` call would
both work correctly and keep the sub-seconds. Only `.isostring` was
affected.
IMPROVEMENTS:
- Leap seconds are now half-supported. The FHIR spec says clients
"SHOULD accept and handle leap seconds gracefully", which we do...
By dropping the leap second on the floor and rolling back to :59.
But this is an improvement on previous behavior of a validation
error. The `.as_json()` value will still preserve the leap second.
- The `.date` field is now always the appropriate type (datetime.date
for FHIRDate, datetime.datetime for FHIRDateTime and FHIRInstant,
and datetime.time for FHIRTime). Previously, a `datetime` field might
result in a datetime.date if only given a date portion. (Which isn't
entirely wrong, but consistently providing the same data type is
useful.)
- The new classes have appropriately named fields in addition to the
backwards-compatible `.date` field -- FHIRDateTime.datetime,
FHIRInstant.datetime, and FHIRTime.time. These will always be the
same value as `.date` for now - but in a future major release, the
`.date` alias may be dropped.
- The dependency on isodate can now be dropped. It is lightly
maintained and the stdlib can handle most of its job nowadays.
- Much better class documentation for what sort of things are
supported and which are not.1 parent efcaade commit 9cbc5ae
File tree
344 files changed
+2826
-1633
lines changed- fhir-parser-resources
- fhirclient/models
- tests
- models
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
344 files changed
+2826
-1633
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
Submodule fhir-parser updated 11 files
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
215 | 214 | | |
216 | 215 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
10 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
13 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
14 | 23 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
19 | 34 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
23 | 39 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 40 | + | |
28 | 41 | | |
29 | 42 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
41 | 49 | | |
42 | | - | |
| 50 | + | |
43 | 51 | | |
44 | | - | |
45 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
46 | 58 | | |
47 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
48 | 67 | | |
49 | 68 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 69 | + | |
| 70 | + | |
54 | 71 | | |
55 | | - | |
| 72 | + | |
56 | 73 | | |
57 | 74 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 75 | + | |
62 | 76 | | |
63 | | - | |
| 77 | + | |
64 | 78 | | |
65 | 79 | | |
66 | | - | |
| 80 | + | |
67 | 81 | | |
68 | 82 | | |
69 | | - | |
| 83 | + | |
70 | 84 | | |
71 | | - | |
| 85 | + | |
72 | 86 | | |
73 | 87 | | |
74 | 88 | | |
75 | 89 | | |
76 | | - | |
77 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
78 | 93 | | |
79 | 94 | | |
80 | 95 | | |
81 | | - | |
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments