Skip to content

Commit 416d54f

Browse files
committed
Implement FHIR Types in Java
1 parent 08db7b0 commit 416d54f

File tree

282 files changed

+16313
-7104
lines changed

Some content is hidden

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

282 files changed

+16313
-7104
lines changed

.github/workflows/build.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,39 @@ jobs:
256256
- name: Test
257257
run: make -C modules/${{ matrix.module }} test-slow
258258

259+
test-mem-size:
260+
runs-on: ubuntu-24.04
261+
262+
steps:
263+
- name: Setup Java
264+
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5
265+
with:
266+
distribution: 'temurin'
267+
java-version: '25'
268+
269+
- name: Setup Clojure
270+
uses: DeLaGuardo/setup-clojure@3fe9b3ae632c6758d0b7757b0838606ef4287b08 # 13.4
271+
with:
272+
cli: '1.12.3.1577'
273+
274+
- name: Check out Git repository
275+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
276+
277+
- name: Cache Local Maven Repo
278+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
279+
with:
280+
path: ~/.m2/repository
281+
key: ${{ runner.os }}-temurin-25-maven-fhir-structure-${{ hashFiles('modules/fhir-structure/deps.edn') }}
282+
283+
- name: Cache Clojure GitLibs
284+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
285+
with:
286+
path: ~/.gitlibs
287+
key: ${{ runner.os }}-gitlibs-fhir-structure-${{ hashFiles('modules/fhir-structure/deps.edn') }}
288+
289+
- name: Test
290+
run: make -C modules/fhir-structure test-mem-size
291+
259292
# Special treatment, because it runs much longer as the other modules.
260293
test-coverage-db:
261294
strategy:
@@ -656,7 +689,7 @@ jobs:
656689
run: .github/scripts/evaluate-measure.sh q36-parameter 86
657690

658691
- name: Check Bloom Filter
659-
run: .github/scripts/check-bloom-filter.sh fbb79d85457069c8e1926c949690deecd60d751942d5b0cd0b61c08e6029224c 86
692+
run: .github/scripts/check-bloom-filter.sh 017a0f079c2a76a731db3cdf68637afc8e4fac34409b032b5ac93958923e0501 86
660693

661694
- name: Evaluate CQL Query 36 - Subject List
662695
run: .github/scripts/evaluate-measure-subject-list.sh q36-parameter 86
@@ -668,7 +701,7 @@ jobs:
668701
run: .github/scripts/evaluate-measure.sh q37-overlaps 24
669702

670703
- name: Check Bloom Filter
671-
run: .github/scripts/check-bloom-filter.sh 9fe779d821d7647831331b490939aa0cdf314d76c9b2a9518ffaf559353db043 24
704+
run: .github/scripts/check-bloom-filter.sh e7d79fd90bce0a8c5abad06027e3b6d57b448076ff41fa36827e5e3b65ca10c2 24
672705

673706
- name: Evaluate CQL Query 37 - Blazectl
674707
run: .github/scripts/evaluate-measure-blazectl.sh q37-overlaps 24
@@ -2693,6 +2726,7 @@ jobs:
26932726
- lint
26942727
- test
26952728
- test-slow
2729+
- test-mem-size
26962730
- test-root
26972731
- image-scan
26982732
- cql-expr-cache-test

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM eclipse-temurin:21.0.8_9-jre-noble@sha256:20e7f7288e1c18eebe8f06a442c9f7183342d9b022d3b9a9677cae2b558ddddd
1+
FROM eclipse-temurin:25-jre-noble
22

33
ENV DEBIAN_FRONTEND=noninteractive
44

@@ -15,11 +15,12 @@ WORKDIR /app
1515
USER 1001
1616

1717
ENV LD_PRELOAD="libjemalloc.so.2"
18+
ENV BASE_JAVA_TOOL_OPTIONS="-XX:+UseCompactObjectHeaders --enable-native-access=ALL-UNNAMED"
1819
ENV STORAGE="standalone"
1920
ENV INDEX_DB_DIR="/app/data/index"
2021
ENV TRANSACTION_DB_DIR="/app/data/transaction"
2122
ENV RESOURCE_DB_DIR="/app/data/resource"
2223
ENV ADMIN_INDEX_DB_DIR="/app/data/admin-index"
2324
ENV ADMIN_TRANSACTION_DB_DIR="/app/data/admin-transaction"
2425

25-
CMD ["java", "-jar", "blaze-1.2.0-standalone.jar"]
26+
CMD ["sh", "-c", "JAVA_TOOL_OPTIONS=\"${BASE_JAVA_TOOL_OPTIONS} ${JAVA_TOOL_OPTIONS}\" exec java -jar blaze-1.2.0-standalone.jar"]

cljfmt.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
reg-collector [[:block 1]]
1717
deftests [[:block 1]]
1818
satisfies-prop [[:block 1]]
19+
mem-size-test [[:block 1]]
1920
clojure.test.check.properties/for-all [[:block 1]]
2021
blaze.metrics.core/collector [[:block 0]]
2122
reify-expr [[:inner 0] [:inner 1]]

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@
188188
:wrap link-headers/wrap-link-headers})
189189

190190
(def ^:private allowed-profiles
191-
#{#fhir/canonical "https://samply.github.io/blaze/fhir/StructureDefinition/AsyncInteractionJob"
192-
#fhir/canonical "https://samply.github.io/blaze/fhir/StructureDefinition/CompactJob"
193-
#fhir/canonical "https://samply.github.io/blaze/fhir/StructureDefinition/ReIndexJob"})
191+
#{"https://samply.github.io/blaze/fhir/StructureDefinition/AsyncInteractionJob"
192+
"https://samply.github.io/blaze/fhir/StructureDefinition/CompactJob"
193+
"https://samply.github.io/blaze/fhir/StructureDefinition/ReIndexJob"})
194194

195195
(defn- check-profile [resource]
196-
(if (some allowed-profiles (-> resource :meta :profile))
196+
(if (some allowed-profiles (map :value (-> resource :meta :profile)))
197197
resource
198198
(ba/incorrect
199199
"No allowed profile found."
@@ -213,7 +213,7 @@
213213
(datafy/datafy)))
214214

215215
(defn- error-issues [outcome]
216-
(update outcome :issue (partial filterv (comp #{#fhir/code "error"} :severity))))
216+
(update outcome :issue (partial filterv (comp #{"error"} :value :severity))))
217217

218218
(def ^:private wrap-validate-job
219219
{:name :wrap-validate-job

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@
735735
{:system #fhir/uri "https://samply.github.io/blaze/fhir/CodeSystem/JobType"
736736
:code #fhir/code "re-index"
737737
:display #fhir/string "(Re)Index a Search Parameter"}]}
738-
:authoredOn #fhir/dateTime "2024-04-13T10:05:20.927Z"
738+
:authoredOn #fhir/dateTime #system/date-time "2024-04-13T10:05:20.927Z"
739739
:input
740740
[{:fhir/type :fhir.Task/input
741741
:type #fhir/CodeableConcept
@@ -756,7 +756,7 @@
756756
{:system #fhir/uri "https://samply.github.io/blaze/fhir/CodeSystem/JobType"
757757
:code #fhir/code "compact"
758758
:display #fhir/string "Compact a Database Column Family"}]}
759-
:authoredOn #fhir/dateTime "2024-04-13T10:05:20.927Z"
759+
:authoredOn #fhir/dateTime #system/date-time "2024-04-13T10:05:20.927Z"
760760
:input
761761
[{:fhir/type :fhir.Task/input
762762
:type #fhir/CodeableConcept

modules/byte-buffer/build.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
{:basis (b/create-basis {:project "deps.edn"})
88
:src-dirs ["java"]
99
:class-dir "target/classes"
10-
:javac-opts ["-Xlint:all" "-proc:none" "--release" "17"]}))
10+
:javac-opts ["-Xlint:all" "-proc:none" "--release" "21"]}))

modules/coll/build.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
{:basis (b/create-basis {:project "deps.edn"})
88
:src-dirs ["java"]
99
:class-dir "target/classes"
10-
:javac-opts ["-Xlint:all" "-proc:none" "--release" "17"]}))
10+
:javac-opts ["-Xlint:all" "-proc:none" "--release" "21"]}))

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,12 @@
6161
(reify-expr core/Expression
6262
(-eval [_ {:keys [db]} resource _]
6363
(prom/inc! retrieve-total)
64-
(let [{{:keys [reference]} :subject} resource]
65-
(when reference
66-
(when-let [[type id] (fsr/split-literal-ref reference)]
67-
(when (and (= "Patient" type) (string? id))
68-
(when-let [handle (d/resource-handle db "Patient" id)]
69-
(when-not (d/deleted? handle)
70-
[(cr/mk-resource db handle)])))))))
64+
(when-let [reference (-> resource :subject :reference :value)]
65+
(when-let [[type id] (fsr/split-literal-ref reference)]
66+
(when (and (= "Patient" type) (string? id))
67+
(when-let [handle (d/resource-handle db "Patient" id)]
68+
(when-not (d/deleted? handle)
69+
[(cr/mk-resource db handle)]))))))
7170
(-form [_]
7271
'(retrieve (Specimen) "Patient"))))
7372

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

Lines changed: 32 additions & 13 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]
@@ -112,7 +112,7 @@
112112
`(~'call "ToQuantity" ~(core/-form operand)))))
113113

114114
(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)))
116116

117117
(defn- to-code-function-expr [operand]
118118
(reify-expr core/Expression
@@ -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]
@@ -140,7 +155,7 @@
140155
(-optimize [_ db]
141156
(core/optimize-helper to-date-function-expr db operand))
142157
(-eval [_ context resource scope]
143-
(type/value (core/-eval operand context resource scope)))
158+
(:value (core/-eval operand context resource scope)))
144159
(-form [_]
145160
`(~'call "ToDate" ~(core/-form operand)))))
146161

@@ -155,7 +170,7 @@
155170
(-optimize [_ parameters]
156171
(to-date-time-function-expr (core/-optimize operand parameters)))
157172
(-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))
159174
(-form [_]
160175
`(~'call "ToDateTime" ~(core/-form operand)))))
161176

@@ -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) (:value value)
192+
:else (str value))))
174193
(-form [_]
175194
`(~'call "ToString" ~(core/-form operand)))))
176195

@@ -181,8 +200,8 @@
181200
Period
182201
(-to-interval [{:keys [start end]} {:keys [now]}]
183202
(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)))
186205

187206
nil
188207
(-to-interval [_ _]))
@@ -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/src/blaze/elm/compiler/structured_values.clj

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
[blaze.elm.compiler.core :as core]
1111
[blaze.elm.compiler.macros :refer [reify-expr]]
1212
[blaze.elm.protocols :as p]
13-
[blaze.fhir.spec.type :as type]
1413
[clojure.string :as str])
1514
(:import
16-
[clojure.lang ILookup IReduceInit]
17-
[java.time Instant LocalDateTime LocalTime OffsetDateTime]
18-
[java.util UUID]))
15+
[clojure.lang ILookup IReduceInit]))
1916

2017
(set! *warn-on-reflection* true)
2118

@@ -35,43 +32,7 @@
3532
(throw-anom (invalid-structured-type-access-anom coll key)))
3633
ILookup
3734
(get [m key]
38-
(.valAt m key))
39-
Boolean
40-
(get [boolean key]
41-
(when (identical? :value key)
42-
boolean))
43-
Integer
44-
(get [int key]
45-
(when (identical? :value key)
46-
int))
47-
String
48-
(get [s key]
49-
(when (identical? :value key)
50-
s))
51-
BigDecimal
52-
(get [decimal key]
53-
(when (identical? :value key)
54-
decimal))
55-
Instant
56-
(get [instant key]
57-
(when (identical? :value key)
58-
instant))
59-
LocalDateTime
60-
(get [date-time key]
61-
(when (identical? :value key)
62-
date-time))
63-
OffsetDateTime
64-
(get [date-time key]
65-
(when (identical? :value key)
66-
date-time))
67-
LocalTime
68-
(get [time key]
69-
(when (identical? :value key)
70-
time))
71-
UUID
72-
(get [uuid key]
73-
(when (identical? :value key)
74-
uuid)))
35+
(.valAt m key)))
7536

7637
(defn- compile-elements [context elements]
7738
(reduce
@@ -143,7 +104,7 @@
143104
(-resolve-params [_ parameters]
144105
(source-property-value-expr (core/-resolve-params source parameters) key))
145106
(-eval [_ context resource scope]
146-
(type/value (p/get (core/-eval source context resource scope) key)))
107+
(:value (key (core/-eval source context resource scope))))
147108
(-form [_]
148109
`(:value (~key ~(core/-form source))))))
149110

@@ -157,7 +118,7 @@
157118
(defn- scope-property-value-expr [scope-key key]
158119
(reify-expr core/Expression
159120
(-eval [_ _ _ scope]
160-
(type/value (p/get (get scope scope-key) key)))
121+
(:value (key (get scope scope-key))))
161122
(-form [_]
162123
`(:value (~key ~(symbol (name scope-key)))))))
163124

0 commit comments

Comments
 (0)