Skip to content

Commit

Permalink
Allow Extensions on Primitive Data Types
Browse files Browse the repository at this point in the history
Closes: #371
  • Loading branch information
alexanderkiel committed May 23, 2022
1 parent 238ad89 commit 429340e
Show file tree
Hide file tree
Showing 28 changed files with 4,540 additions and 1,826 deletions.
2 changes: 1 addition & 1 deletion modules/db-stub/src/blaze/db/api_stub.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
:resource-handle-cache (ig/ref :blaze.db/resource-handle-cache)
:tx-cache (ig/ref :blaze.db/tx-cache)
:indexer-executor (ig/ref :blaze.db.node/indexer-executor)
:resource-store (ig/ref :blaze.db/resource-store)
:resource-store (ig/ref ::rs/kv)
:kv-store (ig/ref :blaze.db/index-kv-store)
:resource-indexer (ig/ref :blaze.db.node/resource-indexer)
:search-param-registry (ig/ref :blaze.db/search-param-registry)}
Expand Down
2 changes: 1 addition & 1 deletion modules/db/test-perf/blaze/db/api_test_perf.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
:resource-handle-cache (ig/ref :blaze.db/resource-handle-cache)
:tx-cache (ig/ref :blaze.db/tx-cache)
:indexer-executor (ig/ref :blaze.db.node/indexer-executor)
:resource-store (ig/ref :blaze.db/resource-store)
:resource-store (ig/ref ::rs/kv)
:kv-store (ig/ref :blaze.db/index-kv-store)
:resource-indexer (ig/ref :blaze.db.node/resource-indexer)
:search-param-registry (ig/ref :blaze.db/search-param-registry)
Expand Down
20 changes: 19 additions & 1 deletion modules/db/test/blaze/db/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

(def slow-resource-store-system
(-> (assoc-in system [:blaze.db/node :resource-store] (ig/ref ::slow-resource-store))
(assoc ::slow-resource-store {:resource-store (ig/ref :blaze.db/resource-store)})))
(assoc ::slow-resource-store {:resource-store (ig/ref ::rs/kv)})))


(defmethod ig/init-key ::resource-store-failing-on-put [_ _]
Expand Down Expand Up @@ -245,6 +245,24 @@
[:meta :versionId] := #fhir/id"1"
[meta :blaze.db/op] := :put))))

(testing "one Patient with an Extension on birthDate"
(with-system-data [{:blaze.db/keys [node]} system]
[[[:put {:fhir/type :fhir/Patient :id "0"
:birthDate
#fhir/date
{:extension [#fhir/Extension{:url "foo" :value #fhir/code"bar"}]
:value "2022"}}]]]

(testing "the Patient was created"
(given @(d/pull node (d/resource-handle (d/db node) "Patient" "0"))
:fhir/type := :fhir/Patient
:id := "0"
[:meta :versionId] := #fhir/id"1"
[meta :blaze.db/op] := :put
[:birthDate :extension 0 :url] := "foo"
[:birthDate :extension 0 :value] := #fhir/code"bar"
[:birthDate :value] := #fhir/date"2022"))))

(testing "one Patient with one Observation"
(with-system-data [{:blaze.db/keys [node]} system]
;; the create ops are purposely disordered in order to test the
Expand Down
2 changes: 1 addition & 1 deletion modules/db/test/blaze/db/node_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
(-> (assoc-in system [:blaze.db/node :resource-store]
(ig/ref ::resource-store-slow-on-put))
(assoc ::resource-store-slow-on-put
{:resource-store (ig/ref :blaze.db/resource-store)})))
{:resource-store (ig/ref ::rs/kv)})))


(deftest init-test
Expand Down
6 changes: 5 additions & 1 deletion modules/db/test/blaze/db/test_util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
:resource-handle-cache (ig/ref :blaze.db/resource-handle-cache)
:tx-cache (ig/ref :blaze.db/tx-cache)
:indexer-executor (ig/ref :blaze.db.node/indexer-executor)
:resource-store (ig/ref :blaze.db/resource-store)
:resource-store (ig/ref ::rs/kv)
:kv-store (ig/ref :blaze.db/index-kv-store)
:resource-indexer (ig/ref :blaze.db.node/resource-indexer)
:search-param-registry (ig/ref :blaze.db/search-param-registry)
Expand All @@ -31,8 +31,10 @@
::tx-log/local
{:kv-store (ig/ref :blaze.db/transaction-kv-store)
:clock (ig/ref :blaze.test/clock)}

[::kv/mem :blaze.db/transaction-kv-store]
{:column-families {}}

:blaze.test/clock {}

:blaze.db/resource-handle-cache {}
Expand Down Expand Up @@ -61,8 +63,10 @@
::rs/kv
{:kv-store (ig/ref :blaze.db/resource-kv-store)
:executor (ig/ref ::rs-kv/executor)}

[::kv/mem :blaze.db/resource-kv-store]
{:column-families {}}

::rs-kv/executor {}

:blaze.db.node/resource-indexer
Expand Down
4 changes: 2 additions & 2 deletions modules/fhir-path/src/blaze/fhir_path.clj
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,13 @@
fhirpathParser$DateLiteralContext
(-compile [ctx]
(let [text (subs (.getText (.getSymbol (.DATE ctx))) 1)]
[(type/->Date text)]))
[(type/date text)]))

fhirpathParser$DateTimeLiteralContext
(-compile [ctx]
(let [text (subs (.getText (.getSymbol (.DATETIME ctx))) 1)
text (if (str/ends-with? text "T") (subs text 0 (dec (count text))) text)]
[(type/->DateTime text)]))
[(type/dateTime text)]))

fhirpathParser$MemberInvocationContext
(-compile [ctx]
Expand Down
5 changes: 3 additions & 2 deletions modules/fhir-structure/.clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{:lint-as
{blaze.fhir.spec.type.macros/defprimitivetype clojure.core/deftype
{blaze.fhir.spec.type.macros/def-primitive-type clojure.core/deftype
blaze.fhir.spec.type.macros/defextended clojure.core/defrecord
blaze.test-util/with-system clojure.core/with-open}

:hooks
{:macroexpand
{blaze.fhir.spec.type.macros/defcomplextype macros/defcomplextype}}
{blaze.fhir.spec.type.macros/def-complex-type macros/def-complex-type}}

:linters
{:unsorted-required-namespaces
Expand Down
2 changes: 1 addition & 1 deletion modules/fhir-structure/.clj-kondo/macros.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns macros)


(defmacro defcomplextype
(defmacro def-complex-type
[name [& fields] & {:keys [fhir-type hash-num interned references field-serializers]
:or {interned false}}]
`(defrecord ~name [~@fields]
Expand Down
11 changes: 3 additions & 8 deletions modules/fhir-structure/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@

:extra-deps
{blaze/test-util
{:local/root "../test-util"}

criterium/criterium
{:mvn/version "0.4.6"}

org.openjdk.jol/jol-core
{:mvn/version "0.16"}}}
{:local/root "../test-util"}}}

:kaocha
{:extra-deps
Expand All @@ -77,4 +71,5 @@
{cloverage/cloverage
{:mvn/version "1.2.3"}}

:main-opts ["-m" "cloverage.coverage" "--codecov" "-p" "src" "-s" "test"]}}}
:main-opts ["-m" "cloverage.coverage" "--codecov" "-p" "src" "-s" "test"
"-e" ".*spec$"]}}}
31 changes: 17 additions & 14 deletions modules/fhir-structure/resources/data_readers.clj
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{blaze/hash blaze.fhir.hash/from-hex
blaze/hash-prefix blaze.fhir.hash/prefix-from-hex
fhir/integer clojure.core/int
fhir/long clojure.core/long
fhir/boolean blaze.fhir.spec.type/boolean
fhir/integer blaze.fhir.spec.type/integer
fhir/long blaze.fhir.spec.type/long
fhir/string blaze.fhir.spec.type/string
fhir/decimal blaze.fhir.spec.type/decimal
fhir/uri blaze.fhir.spec.type/uri
fhir/url blaze.fhir.spec.type/->Url
fhir/url blaze.fhir.spec.type/url
fhir/canonical blaze.fhir.spec.type/canonical
fhir/base64Binary blaze.fhir.spec.type/->Base64Binary
fhir/instant blaze.fhir.spec.type/->Instant
fhir/date blaze.fhir.spec.type/->Date
fhir/dateTime blaze.fhir.spec.type/->DateTime
fhir/time blaze.fhir.spec.type/->Time
fhir/base64Binary blaze.fhir.spec.type/base64Binary
fhir/instant blaze.fhir.spec.type/instant
fhir/date blaze.fhir.spec.type/date
fhir/dateTime blaze.fhir.spec.type/dateTime
fhir/time blaze.fhir.spec.type/time
fhir/code blaze.fhir.spec.type/code
fhir/oid blaze.fhir.spec.type/->Oid
fhir/id blaze.fhir.spec.type/->Id
fhir/markdown blaze.fhir.spec.type/->Markdown
fhir/unsignedInt blaze.fhir.spec.type/->UnsignedInt
fhir/positiveInt blaze.fhir.spec.type/->PositiveInt
fhir/uuid blaze.fhir.spec.type/->Uuid
fhir/oid blaze.fhir.spec.type/oid
fhir/id blaze.fhir.spec.type/id
fhir/markdown blaze.fhir.spec.type/markdown
fhir/unsignedInt blaze.fhir.spec.type/unsignedInt
fhir/positiveInt blaze.fhir.spec.type/positiveInt
fhir/uuid blaze.fhir.spec.type/uuid
fhir/xhtml blaze.fhir.spec.type/->Xhtml
fhir/Attachment blaze.fhir.spec.type/map->Attachment
fhir/Extension blaze.fhir.spec.type/extension
Expand Down
17 changes: 7 additions & 10 deletions modules/fhir-structure/src/blaze/fhir/spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[cognitect.anomalies :as anom]
[jsonista.core :as j])
(:import
[com.fasterxml.jackson.databind DeserializationFeature]
[com.fasterxml.jackson.databind DeserializationFeature ObjectMapper]
[com.fasterxml.jackson.dataformat.cbor CBORFactory]
[java.util.regex Pattern]))

Expand All @@ -22,11 +22,10 @@


(def ^:private json-object-mapper
(-> (j/object-mapper
{:decode-key-fn true
:bigdecimals true
:modules [type/fhir-module]})
(.enable DeserializationFeature/FAIL_ON_TRAILING_TOKENS)))
(doto (ObjectMapper.)
(.registerModule type/fhir-module)
(.enable DeserializationFeature/USE_BIG_DECIMAL_FOR_FLOATS)
(.enable DeserializationFeature/FAIL_ON_TRAILING_TOKENS)))


(defn parse-json
Expand All @@ -44,10 +43,8 @@


(def ^:private cbor-object-mapper
(j/object-mapper
{:factory (CBORFactory.)
:decode-key-fn true
:modules [type/fhir-module]}))
(doto (ObjectMapper. (CBORFactory.))
(.registerModule type/fhir-module)))


(defn parse-cbor
Expand Down
Loading

0 comments on commit 429340e

Please sign in to comment.