|
13 | 13 | [blaze.elm.interval :as interval] |
14 | 14 | [blaze.elm.protocols :as p] |
15 | 15 | [blaze.elm.quantity :as quantity] |
| 16 | + [blaze.fhir.spec :as fhir-spec] |
16 | 17 | [blaze.fhir.spec.type :as type]) |
17 | 18 | (:import |
18 | | - [blaze.fhir.spec.type Period] |
19 | | - [java.util Map])) |
| 19 | + [blaze.fhir.spec.type Period Quantity])) |
20 | 20 |
|
21 | 21 | (set! *warn-on-reflection* true) |
22 | 22 |
|
|
84 | 84 | (-to-quantity [x])) |
85 | 85 |
|
86 | 86 | (extend-protocol ToQuantity |
87 | | - Map |
88 | | - (-to-quantity [m] |
89 | | - (when-let [value (:value m)] |
90 | | - (quantity/quantity value (or (-> m :code type/value) "1")))) |
| 87 | + Quantity |
| 88 | + (-to-quantity [fhir-quantity] |
| 89 | + (when-let [decimal (-> fhir-quantity :value :value)] |
| 90 | + (quantity/quantity decimal (or (-> fhir-quantity :code :value) "1")))) |
91 | 91 |
|
92 | 92 | Object |
93 | 93 | (-to-quantity [x] |
|
112 | 112 | `(~'call "ToQuantity" ~(core/-form operand))))) |
113 | 113 |
|
114 | 114 | (defn- to-code [{:keys [system version code]}] |
115 | | - (code/code (type/value system) (type/value version) (type/value code))) |
| 115 | + (code/code (:value system) (:value version) (:value code))) |
116 | 116 |
|
117 | 117 | (defn- to-code-function-expr [operand] |
118 | 118 | (reify-expr core/Expression |
|
129 | 129 | (-form [_] |
130 | 130 | `(~'call "ToCode" ~(core/-form operand))))) |
131 | 131 |
|
| 132 | +(defn- to-decimal-function-expr [operand] |
| 133 | + (reify-expr core/Expression |
| 134 | + (-attach-cache [_ cache] |
| 135 | + (core/attach-cache-helper to-decimal-function-expr cache operand)) |
| 136 | + (-resolve-refs [_ expression-defs] |
| 137 | + (to-decimal-function-expr (core/-resolve-refs operand expression-defs))) |
| 138 | + (-resolve-params [_ parameters] |
| 139 | + (core/resolve-params-helper to-decimal-function-expr parameters operand)) |
| 140 | + (-optimize [_ db] |
| 141 | + (core/optimize-helper to-decimal-function-expr db operand)) |
| 142 | + (-eval [_ context resource scope] |
| 143 | + (:value (core/-eval operand context resource scope))) |
| 144 | + (-form [_] |
| 145 | + `(~'call "ToDecimal" ~(core/-form operand))))) |
| 146 | + |
132 | 147 | (defn- to-date-function-expr [operand] |
133 | 148 | (reify-expr core/Expression |
134 | 149 | (-attach-cache [_ cache] |
|
140 | 155 | (-optimize [_ db] |
141 | 156 | (core/optimize-helper to-date-function-expr db operand)) |
142 | 157 | (-eval [_ context resource scope] |
143 | | - (type/value (core/-eval operand context resource scope))) |
| 158 | + (:value (core/-eval operand context resource scope))) |
144 | 159 | (-form [_] |
145 | 160 | `(~'call "ToDate" ~(core/-form operand))))) |
146 | 161 |
|
|
155 | 170 | (-optimize [_ parameters] |
156 | 171 | (to-date-time-function-expr (core/-optimize operand parameters))) |
157 | 172 | (-eval [_ {:keys [now] :as context} resource scope] |
158 | | - (p/to-date-time (type/value (core/-eval operand context resource scope)) now)) |
| 173 | + (p/to-date-time (:value (core/-eval operand context resource scope)) now)) |
159 | 174 | (-form [_] |
160 | 175 | `(~'call "ToDateTime" ~(core/-form operand))))) |
161 | 176 |
|
|
170 | 185 | (-optimize [_ db] |
171 | 186 | (core/optimize-helper to-string-function-expr db operand)) |
172 | 187 | (-eval [_ context resource scope] |
173 | | - (some-> (type/value (core/-eval operand context resource scope)) str)) |
| 188 | + (let [value (core/-eval operand context resource scope)] |
| 189 | + (cond |
| 190 | + (or (string? value) (nil? value)) value |
| 191 | + (fhir-spec/primitive-val? value) (:value value) |
| 192 | + :else (str value)))) |
174 | 193 | (-form [_] |
175 | 194 | `(~'call "ToString" ~(core/-form operand))))) |
176 | 195 |
|
|
181 | 200 | Period |
182 | 201 | (-to-interval [{:keys [start end]} {:keys [now]}] |
183 | 202 | (interval/interval |
184 | | - (p/to-date-time (type/value start) now) |
185 | | - (p/to-date-time (type/value end) now))) |
| 203 | + (p/to-date-time (:value start) now) |
| 204 | + (p/to-date-time (:value end) now))) |
186 | 205 |
|
187 | 206 | nil |
188 | 207 | (-to-interval [_ _])) |
|
250 | 269 | (to-code-function-expr (first operands)) |
251 | 270 |
|
252 | 271 | "ToDecimal" |
253 | | - (first operands) |
| 272 | + (to-decimal-function-expr (first operands)) |
254 | 273 |
|
255 | 274 | "ToInterval" |
256 | 275 | (to-interval-function-expr (first operands)) |
|
0 commit comments