Skip to content

Commit

Permalink
fix: add Bundle, Parameters and Binary to resources
Browse files Browse the repository at this point in the history
  • Loading branch information
krvital committed Oct 4, 2024
1 parent 1810613 commit 5d20243
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 47 deletions.
113 changes: 70 additions & 43 deletions dev/user.clj
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
(ns user
(:require
[aidbox-sdk.converter :as converter]
[aidbox-sdk.core :as sdk]
[aidbox-sdk.fhir :as fhir]
[aidbox-sdk.converter :as converter]
[aidbox-sdk.models :as models]
[aidbox-sdk.fixtures.schemas :as fixtures]
[aidbox-sdk.generator :as gen]
[aidbox-sdk.generator.python :as gen.python]
[aidbox-sdk.schema :as import]
[aidbox-sdk.cli :as cli]
[malli.core :as m]
[clojure.spec.alpha :as s]
[clojure.data]
[clojure.java.io :as io]
[aidbox-sdk.generator.typescript :as gen.typescript]
[clojure.data.json :as json]))
[clojure.walk :as walk]
[meander.epsilon :as m]
[aidbox-sdk.generator.helpers :as helpers]
[aidbox-sdk.models :as models]
[clojure.set :as set]
[clojure.string :as str]
[clojure.data]))

(defonce aidbox-schemas (atom nil))

(defn load-aidbox-schemas []
(reset! aidbox-schemas
(import/retrieve
(import/resource "http://localhost:3333/r4/fhir-packages") {:auth "YmFzaWM6c2VjcmV0"}))
(defn load-aidbox-schemas [from]
(let [from (case from
:r4 "http://localhost:3333/r4/fhir-packages"
:r5 "http://localhost:3333/r5/fhir-packages"
:aidbox "http://localhost:8765/api/sdk/fhir-packages")]
(reset! aidbox-schemas
(import/retrieve
(import/resource from) {:auth "YmFzaWM6c2VjcmV0"})))
nil)

(comment
(load-aidbox-schemas)
(load-aidbox-schemas :r4)

(defonce r4-schemas (import/retrieve (import/resource "resources/r4") {}))
(defonce r4b-schemas (import/retrieve (import/resource "resources/r4b") {}))
Expand All @@ -37,9 +37,6 @@

(defn exclude-keys [m keys] (apply dissoc m keys))

(defn filter-by-url [url schemas]
(filter #(= url (:url %)) schemas))

(comment

(kinds r4-schemas)
Expand All @@ -61,47 +58,78 @@
;; "ValueSet"
;; "StructureDefinition")

(->> @aidbox-schemas
(filter #(= "Patient" (:id %)))
(converter/convert))

(converter/convert-search-params
(->> @aidbox-schemas
(filter fhir/search-parameter?)
(remove fhir/search-parameter-from-extension?))
(->> @aidbox-schemas
(filter fhir/fhir-schema?)))

(let [all-schemas @aidbox-schemas

base-type? (every-pred fhir/fhir-schema? fhir/base-type?)
datatype? (every-pred fhir/fhir-schema? fhir/datatype? (complement fhir/primitive-type?))
domain-resource? (every-pred fhir/fhir-schema? fhir/domain-resource?)
resource? (every-pred fhir/fhir-schema? fhir/resource?)
constraint? (every-pred fhir/fhir-schema? fhir/constraint? (complement fhir/extension?))
search-param? (every-pred fhir/search-parameter? (complement fhir/search-parameter-from-extension?))

fhir-schemas (filter fhir/fhir-schema? all-schemas)
base-schemas (filter base-type? all-schemas)
datatype-schemas (filter datatype? all-schemas)
resource-schemas (filter #(or (domain-resource? %)
(fhir/backbone-element? %)) all-schemas)
resource-schemas (filter #(and
(fhir/fhir-schema? %)
(not (fhir/base-type? %))
(not (fhir/datatype? %))
(or (fhir/resource-type? %)
(fhir/domain-resource? %)
(fhir/backbone-element? %)))
all-schemas)
constraint-schemas (filter constraint? all-schemas)
search-param-schemas [filter search-param? all-schemas]
search-param-schemas (filter search-param? all-schemas)

ir-schemas (converter/convert fhir-schemas)
base-ir-schemas (converter/convert base-schemas)
datatype-ir-schemas (converter/convert datatype-schemas)
resource-ir-schemas (converter/convert resource-schemas)
search-param-ir-schemas (converter/convert-search-params search-param-schemas
fhir-schemas)
constraint-ir-schemas (converter/convert-constraints constraint-schemas
(remove fhir/constraint? ir-schemas))]
fhir-schemas)]

;; (def css constraint-schemas)

;; (def cssi constraint-ir-schemas)

(map models/validate-fhir-schema fhir-schemas)
;; (->> (remove fhir/constraint? ir-schemas)
;; (filter #(contains? (set (map :base css)) %))
;; helpers/vector->map)

#_(filter-by-url "http://hl7.org/fhir/StructureDefinition/Resource" fhir-schemas))
;; (reduce (fn [acc v] (assoc acc (:url v) v)) css)

;
;; (let [name->map (reduce (fn [acc v] (assoc acc (:url v) v)) css)]
;; (reduce (fn [graph {:keys [url base]}]
;; (if (and base (contains? name->map base))
;; (update graph url conj base)
;; graph))
;; (zipmap (map :url css) (repeat #{}))
;; css))

;; (fhir/filter-by-url "http://hl7.org/fhir/StructureDefinition/bmi" ir-schemas)

;; (let [base-schemas (->> (remove fhir/constraint? ir-schemas)
;; (filter #(contains? (set (map :base constraint-schemas)) (:url %)))
;; helpers/vector->map)]
;; (reduce (fn [acc constraint]
;; (let [base-schema (or (get base-schemas (:base constraint))
;; (get acc (:url constraint)))]

;; (assoc acc
;; (:url constraint)
;; (converter/apply-constraint base-schema constraint))))

;; {} (converter/sort-by-base constraint-schemas)))

;; (converter/apply-constraints (remove fhir/constraint? ir-schemas) constraint-schemas)

(->> all-schemas
(filter #(or (fhir/domain-resource? %)
(fhir/backbone-element? %)))
(filter fhir/backbone-element?))
;let
)

;comment
)

(comment
Expand All @@ -117,7 +145,6 @@
;
)


(comment
(sdk/generate! :dotnet
"http://localhost:3333/r4/fhir-packages"
Expand All @@ -137,5 +164,5 @@
:auth-token "YmFzaWM6c2VjcmV0"
:exit (fn [_] nil)})

;
;
)
12 changes: 8 additions & 4 deletions src/aidbox_sdk/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,22 @@

base-type? (every-pred fhir/fhir-schema? fhir/base-type?)
datatype? (every-pred fhir/fhir-schema? fhir/datatype? (complement fhir/primitive-type?))
domain-resource? (every-pred fhir/fhir-schema? fhir/domain-resource?)
constraint? (every-pred fhir/fhir-schema? fhir/constraint? (complement fhir/extension?))
search-param? (every-pred fhir/search-parameter? (complement fhir/search-parameter-from-extension?))

fhir-schemas (filter fhir/fhir-schema? all-schemas)
base-schemas (filter base-type? all-schemas)
datatype-schemas (filter datatype? all-schemas)
resource-schemas (filter #(or (domain-resource? %)
(fhir/backbone-element? %))
all-schemas)
constraint-schemas (filter constraint? all-schemas)
search-param-schemas (filter search-param? all-schemas)
resource-schemas (filter #(and
(fhir/fhir-schema? %)
(not (fhir/base-type? %))
(not (fhir/datatype? %))
(or (fhir/resource-type? %)
(fhir/domain-resource? %)
(fhir/backbone-element? %)))
all-schemas)

ir-schemas (converter/convert fhir-schemas)
base-ir-schemas (converter/convert base-schemas)
Expand Down
4 changes: 4 additions & 0 deletions src/aidbox_sdk/fhir.clj
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@
[schema]
(= (:base schema) "http://hl7.org/fhir/StructureDefinition/DomainResource"))

(defn resource-type?
[schema]
(= (:base schema) "http://hl7.org/fhir/StructureDefinition/Resource"))

(defn search-parameter-from-extension? [search-parameter]
(str/includes? (:id search-parameter) "-extensions-"))

Expand Down

0 comments on commit 5d20243

Please sign in to comment.