Skip to content

Commit 0c03fa1

Browse files
committed
Implement FHIR Types in Java
1 parent be07f7f commit 0c03fa1

File tree

231 files changed

+11944
-5031
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+11944
-5031
lines changed

.github/scripts/fetch-resource-0-with-missing-resource-content.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ RESULT=$(curl -sH "Accept: application/fhir+json" "$BASE/Patient/0")
1515
test "resource type" "$(echo "$RESULT" | jq -r .resourceType)" "OperationOutcome"
1616
test "severity" "$(echo "$RESULT" | jq -r '.issue[0].severity')" "error"
1717
test "code" "$(echo "$RESULT" | jq -r '.issue[0].code')" "incomplete"
18-
test "diagnostics" "$(echo "$RESULT" | jq -r '.issue[0].diagnostics')" "The resource content of \`Patient/0\` with hash \`C9ADE22457D5AD750735B6B166E3CE8D6878D09B64C2C2868DCB6DE4C9EFBD4F\` was not found."
18+
test "diagnostics" "$(echo "$RESULT" | jq -r '.issue[0].diagnostics')" "The resource content of \`Patient/0\` with hash \`5EE37C94FB1626111B5C2D37F7C2ECAF21B50B9D0FB45FA189889F38D0F9A470\` was not found."

docs/implementation/fhir-data-model.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ The internal representation of the example above looks like this:
7979
```clojure
8080
{:fhir/type :fhir/Patient
8181
:id "0"
82-
:name [#fhir/HumanName{:text "John Doe"}]
83-
:birthDate #fhir/date"2020"
84-
:deceased false}
82+
:name [#fhir/HumanName{:text #fhir/string "John Doe"}]
83+
:birthDate #fhir/date #system/date "2020"
84+
:deceased #fhir/boolean false}
8585
```
8686

8787
Although, this internal representation is nearly identical to the JSON representation, there are two main differences:

modules/admin-api/src/blaze/admin_api.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
:severity #fhir/code"error"
205205
:code #fhir/code"value"
206206
:details #fhir/CodeableConcept
207-
{:text "No allowed profile found."}}]})))
207+
{:text #fhir/string "No allowed profile found."}}]})))
208208

209209
(defn- validate [^FhirValidator validator writing-context resource]
210210
(->> ^String (fhir-spec/write-json-as-string writing-context resource)

modules/admin-api/src/blaze/admin_api/validation.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
(.hasDetails issue)
2727
(assoc :details (datafy/datafy (.getDetails issue)))
2828
(.hasDiagnostics issue)
29-
(assoc :diagnostics (.getDiagnostics issue))))
29+
(assoc :diagnostics (type/string (.getDiagnostics issue)))))
3030

3131
CodeableConcept
3232
(datafy [concept]
3333
(cond-> {:fhir/type :fhir.CodeableConcept}
3434
(.hasText concept)
35-
(assoc :text (.getText concept)))))
35+
(assoc :text (type/string (.getText concept))))))

modules/admin-api/test/blaze/admin_api_test.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@
691691
[#fhir/Coding
692692
{:system #fhir/uri"system-192253"
693693
:code #fhir/code"code-192300"}]}
694-
:subject (type/reference {:reference (str "Patient/" pat-id)})}]))
694+
:subject (type/reference {:reference (type/string (str "Patient/" pat-id))})}]))
695695
(range 120)))
696696
(mapv (range 100)))
697697

@@ -729,7 +729,7 @@
729729
{:system #fhir/uri"https://samply.github.io/blaze/fhir/CodeSystem/JobType"
730730
:code #fhir/code"re-index"
731731
:display #fhir/string"(Re)Index a Search Parameter"}]}
732-
:authoredOn #fhir/dateTime"2024-04-13T10:05:20.927Z"
732+
:authoredOn #fhir/dateTime #system/date-time "2024-04-13T10:05:20.927Z"
733733
:input
734734
[{:fhir/type :fhir.Task/input
735735
:type #fhir/CodeableConcept
@@ -750,7 +750,7 @@
750750
{:system #fhir/uri"https://samply.github.io/blaze/fhir/CodeSystem/JobType"
751751
:code #fhir/code"compact"
752752
:display #fhir/string"Compact a Database Column Family"}]}
753-
:authoredOn #fhir/dateTime"2024-04-13T10:05:20.927Z"
753+
:authoredOn #fhir/dateTime #system/date-time "2024-04-13T10:05:20.927Z"
754754
:input
755755
[{:fhir/type :fhir.Task/input
756756
:type #fhir/CodeableConcept
@@ -850,7 +850,7 @@
850850
{:request-method :post
851851
:uri "/fhir/__admin/Task"
852852
:headers {"content-type" "application/fhir+json"}
853-
:body (json-writer (update-in re-index-job [:code :coding 0] merge {:code #fhir/code"compact" :display "Compact a Database Column Family"}))})]
853+
:body (json-writer (update-in re-index-job [:code :coding 0] merge {:code #fhir/code"compact" :display #fhir/string "Compact a Database Column Family"}))})]
854854

855855
(is (= 400 status))
856856

modules/cql/src/blaze/elm/compiler/external_data.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
(reify-expr core/Expression
6262
(-eval [_ {:keys [db]} resource _]
6363
(prom/inc! retrieve-total)
64-
(let [{{:keys [reference]} :subject} resource]
64+
(let [{{{reference :value} :reference} :subject} resource]
6565
(when reference
6666
(when-let [[type id] (fsr/split-literal-ref reference)]
6767
(when (and (= "Patient" type) (string? id))

modules/cql/src/blaze/elm/compiler/reusing_logic.clj

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
[blaze.elm.interval :as interval]
1414
[blaze.elm.protocols :as p]
1515
[blaze.elm.quantity :as quantity]
16+
[blaze.fhir.spec :as fhir-spec]
1617
[blaze.fhir.spec.type :as type])
1718
(:import
18-
[blaze.fhir.spec.type Period]
19-
[java.util Map]))
19+
[blaze.fhir.spec.type Period Quantity]))
2020

2121
(set! *warn-on-reflection* true)
2222

@@ -84,10 +84,10 @@
8484
(-to-quantity [x]))
8585

8686
(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"))))
9191

9292
Object
9393
(-to-quantity [x]
@@ -129,6 +129,21 @@
129129
(-form [_]
130130
`(~'call "ToCode" ~(core/-form operand)))))
131131

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+
132147
(defn- to-date-function-expr [operand]
133148
(reify-expr core/Expression
134149
(-attach-cache [_ cache]
@@ -170,7 +185,11 @@
170185
(-optimize [_ db]
171186
(core/optimize-helper to-string-function-expr db operand))
172187
(-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) (type/value value)
192+
:else (str value))))
174193
(-form [_]
175194
`(~'call "ToString" ~(core/-form operand)))))
176195

@@ -250,7 +269,7 @@
250269
(to-code-function-expr (first operands))
251270

252271
"ToDecimal"
253-
(first operands)
272+
(to-decimal-function-expr (first operands))
254273

255274
"ToInterval"
256275
(to-interval-function-expr (first operands))

modules/cql/test/blaze/elm/compiler/external_data_test.clj

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181

8282
(testing "eval"
8383
(given (expr/eval (eval-context db) expr patient)
84-
[0 fhir-spec/fhir-type] := :fhir/Patient
84+
[0 :fhir/type] := :fhir/Patient
8585
[0 :id] := "0"))
8686

8787
(testing "expression is dynamic"
@@ -104,7 +104,7 @@
104104
(with-system-data [{:blaze.db/keys [node]} mem-node-config]
105105
[[[:put {:fhir/type :fhir/Patient :id "0"}]
106106
[:put {:fhir/type :fhir/Observation :id "1"
107-
:subject #fhir/Reference{:reference "Patient/0"}}]]]
107+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]]]
108108

109109
(let [context
110110
{:node node
@@ -116,7 +116,7 @@
116116

117117
(testing "eval"
118118
(given (expr/eval (eval-context db) expr patient)
119-
[0 fhir-spec/fhir-type] := :fhir/Observation
119+
[0 :fhir/type] := :fhir/Observation
120120
[0 :id] := "1"))
121121

122122
(testing "expression is dynamic"
@@ -139,15 +139,15 @@
139139
(with-system-data [{:blaze.db/keys [node]} mem-node-config]
140140
[[[:put {:fhir/type :fhir/Patient :id "0"}]
141141
[:put {:fhir/type :fhir/Observation :id "0"
142-
:subject #fhir/Reference{:reference "Patient/0"}}]
142+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]
143143
[:put {:fhir/type :fhir/Observation :id "1"
144144
:code
145145
#fhir/CodeableConcept
146146
{:coding
147147
[#fhir/Coding
148148
{:system #fhir/uri"system-192253"
149149
:code #fhir/code"code-192300"}]}
150-
:subject #fhir/Reference{:reference "Patient/0"}}]]]
150+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]]]
151151

152152
(let [context
153153
{:node node
@@ -168,7 +168,7 @@
168168
(testing "eval"
169169
(given (expr/eval (eval-context db) expr patient)
170170
count := 1
171-
[0 fhir-spec/fhir-type] := :fhir/Observation
171+
[0 :fhir/type] := :fhir/Observation
172172
[0 :id] := "1"))
173173

174174
(testing "expression is dynamic"
@@ -212,23 +212,23 @@
212212
(with-system-data [{:blaze.db/keys [node]} mem-node-config]
213213
[[[:put {:fhir/type :fhir/Patient :id "0"}]
214214
[:put {:fhir/type :fhir/Observation :id "0"
215-
:subject #fhir/Reference{:reference "Patient/0"}}]
215+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]
216216
[:put {:fhir/type :fhir/Observation :id "1"
217217
:code
218218
#fhir/CodeableConcept
219219
{:coding
220220
[#fhir/Coding
221221
{:system #fhir/uri"system-192253"
222222
:code #fhir/code"code-192300"}]}
223-
:subject #fhir/Reference{:reference "Patient/0"}}]
223+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]
224224
[:put {:fhir/type :fhir/Observation :id "2"
225225
:code
226226
#fhir/CodeableConcept
227227
{:coding
228228
[#fhir/Coding
229229
{:system #fhir/uri"system-192253"
230230
:code #fhir/code"code-140541"}]}
231-
:subject #fhir/Reference{:reference "Patient/0"}}]]]
231+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]]]
232232

233233
(let [context
234234
{:node node
@@ -250,9 +250,9 @@
250250
(testing "eval"
251251
(given (expr/eval (eval-context db) expr patient)
252252
count := 2
253-
[0 fhir-spec/fhir-type] := :fhir/Observation
253+
[0 :fhir/type] := :fhir/Observation
254254
[0 :id] := "1"
255-
[1 fhir-spec/fhir-type] := :fhir/Observation
255+
[1 :fhir/type] := :fhir/Observation
256256
[1 :id] := "2"))
257257

258258
(testing "expression is dynamic"
@@ -281,23 +281,23 @@
281281
(with-system-data [{:blaze.db/keys [node]} mem-node-config]
282282
[[[:put {:fhir/type :fhir/Patient :id "0"}]
283283
[:put {:fhir/type :fhir/Observation :id "0"
284-
:subject #fhir/Reference{:reference "Patient/0"}}]
284+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]
285285
[:put {:fhir/type :fhir/Observation :id "1"
286286
:code
287287
#fhir/CodeableConcept
288288
{:coding
289289
[#fhir/Coding
290290
{:system #fhir/uri"system-192253"
291291
:code #fhir/code"code-192300"}]}
292-
:subject #fhir/Reference{:reference "Patient/0"}}]
292+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]
293293
[:put {:fhir/type :fhir/Observation :id "2"
294294
:code
295295
#fhir/CodeableConcept
296296
{:coding
297297
[#fhir/Coding
298298
{:system #fhir/uri"system-192253"
299299
:code #fhir/code"code-140541"}]}
300-
:subject #fhir/Reference{:reference "Patient/0"}}]]]
300+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]]]
301301

302302
(let [context
303303
{:node node
@@ -322,9 +322,9 @@
322322
(testing "eval"
323323
(given (expr/eval (eval-context db) expr patient)
324324
count := 2
325-
[0 fhir-spec/fhir-type] := :fhir/Observation
325+
[0 :fhir/type] := :fhir/Observation
326326
[0 :id] := "1"
327-
[1 fhir-spec/fhir-type] := :fhir/Observation
327+
[1 :fhir/type] := :fhir/Observation
328328
[1 :id] := "2"))
329329

330330
(testing "expression is dynamic"
@@ -374,7 +374,7 @@
374374
(with-system-data [{:blaze.db/keys [node]} mem-node-config]
375375
[[[:put {:fhir/type :fhir/Patient :id "0"}]
376376
[:put {:fhir/type :fhir/Specimen :id "0"
377-
:subject #fhir/Reference{:reference "Patient/0"}}]]]
377+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]]]
378378

379379
(let [context
380380
{:node node
@@ -387,7 +387,7 @@
387387
(testing "eval"
388388
(given (expr/eval (eval-context db) expr specimen)
389389
count := 1
390-
[0 fhir-spec/fhir-type] := :fhir/Patient
390+
[0 :fhir/type] := :fhir/Patient
391391
[0 :id] := "0"))
392392

393393
(testing "expression is dynamic"
@@ -436,7 +436,7 @@
436436
(testing "eval"
437437
(given (expr/eval (eval-context db) expr nil)
438438
count := 1
439-
[0 fhir-spec/fhir-type] := :fhir/Medication
439+
[0 :fhir/type] := :fhir/Medication
440440
[0 :id] := "0"))
441441

442442
(testing "expression is dynamic"
@@ -486,7 +486,7 @@
486486
(with-system-data [{:blaze.db/keys [node]} mem-node-config]
487487
[[[:put {:fhir/type :fhir/Patient :id "0"}]
488488
[:put {:fhir/type :fhir/Observation :id "0"
489-
:subject #fhir/Reference{:reference "Patient/0"}}]]]
489+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]]]
490490

491491
(let [library (t/translate
492492
"library test
@@ -510,7 +510,7 @@
510510
(testing "eval"
511511
(given (expr/eval eval-context expr patient)
512512
count := 1
513-
[0 fhir-spec/fhir-type] := :fhir/Observation
513+
[0 :fhir/type] := :fhir/Observation
514514
[0 :id] := "0"))
515515

516516
(testing "expression is dynamic"
@@ -540,7 +540,7 @@
540540
[#fhir/Coding
541541
{:system #fhir/uri"system-133620"
542542
:code #fhir/code"code-133657"}]}
543-
:subject #fhir/Reference{:reference "Patient/0"}}]]]
543+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]]]
544544

545545
(let [library (t/translate
546546
"library test
@@ -566,7 +566,7 @@
566566
(testing "eval"
567567
(given (expr/eval eval-context expr patient)
568568
count := 1
569-
[0 fhir-spec/fhir-type] := :fhir/Observation
569+
[0 :fhir/type] := :fhir/Observation
570570
[0 :id] := "0"))
571571

572572
(testing "expression is dynamic"

modules/cql/test/blaze/elm/compiler/library_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
(def ^:private expr-form (comp c/form :expression))
3030

3131
(defn- codeable-concept [system code]
32-
(type/map->CodeableConcept
32+
(type/codeable-concept
3333
{:coding
34-
[(type/map->Coding
34+
[(type/coding
3535
{:system (type/uri system)
3636
:code (type/code code)})]}))
3737

modules/cql/test/blaze/elm/compiler/list_operators_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
(is (false? (expr/eval eval-context expr patient)))))
336336

337337
(let [tx-op [:put {:fhir/type :fhir/Observation :id "0"
338-
:subject #fhir/Reference{:reference "Patient/0"}}]
338+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]
339339
db-after @(d/transact node [tx-op])]
340340

341341
(testing "has an Observation after transaction"
@@ -372,7 +372,7 @@
372372
(is (false? (expr/eval eval-context expr patient))))
373373

374374
(let [tx-op [:put {:fhir/type :fhir/Observation :id "0"
375-
:subject #fhir/Reference{:reference "Patient/0"}}]
375+
:subject #fhir/Reference{:reference #fhir/string"Patient/0"}}]
376376
db-after @(d/transact node [tx-op])]
377377

378378
(testing "has an Observation after transaction"

0 commit comments

Comments
 (0)