Skip to content

Commit

Permalink
Support recursive schemas on profiles too
Browse files Browse the repository at this point in the history
  • Loading branch information
ApricotLace committed Mar 23, 2023
1 parent 6f6f26b commit cd718c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/zen/fhir/structure_definition/loader.clj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
(defn enrich-slicing [ctx el base-els]
(update-in el [:fhir/slicing :slices] #(sp/transform [sp/MAP-VALS] fix-match-vectors %)))


(defn replace-ns-in-sym [sym ns]
(symbol (str ns)
(name sym)))


(defn enrich-element [ctx el base-els]
;; TODO: if vector do min/max items
;; required/prohibited
Expand All @@ -115,6 +121,11 @@
(make-first-class-ext-keys acc el)
(assoc acc k el)))]
(let [v? (some :vector (cons el base-els))
recur? (first (filter (fn [el'] (get-in el' [:| (last (:path ctx)) :recur])) (cons el base-els)))
recur (when recur? (update (get-in recur? [:| (last (:path ctx)) :recur]) :symbol
replace-ns-in-sym (:zen.fhir/schema-ns ctx)))
recur-refs? (first (filter :recur-refs (cons el base-els)))
recur-refs (when recur-refs? (set (map #(update % :symbol replace-ns-in-sym (:zen.fhir/schema-ns ctx)) (:recur-refs recur-refs?))))
tp (or (:type el)
(->> base-els
(filter (fn [{tp :type}] (and (not (nil? tp))
Expand All @@ -127,6 +138,8 @@
(assoc :required true)

v? (assoc :vector true)
recur? (assoc-in [:| (last (:path ctx)) :recur] recur)
recur-refs? (assoc :recur-refs recur-refs)
(not v?) (dissoc :minItems :maxItems)
tp (assoc :type tp)
(contains? el :fhir/slicing) (as-> $ (enrich-slicing ctx $ base-els))
Expand Down Expand Up @@ -256,6 +269,7 @@
(walk-with-bases ztx {:lvl 0
:path [url]
:derivation (:derivation subj)
:zen.fhir/schema-ns (get subj :zen.fhir/schema-ns)
:do-not-handle-first-class-ext?
(or (= "http://hl7.org/fhir/StructureDefinition/Element"
(:url subj))
Expand Down
6 changes: 6 additions & 0 deletions test/zen/fhir/load_all_core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@
:operator {}
:answer {}}}}}}})

(match-inter ztx "StructureDefinition" "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-behave"
{:| {:item {:| {:item {:recur {:symbol 'hl7-fhir-uv-sdc.sdc-questionnaire-behave/item-schema
:path [:item nil]}}}}}
:recur-refs #{{:symbol 'hl7-fhir-uv-sdc.sdc-questionnaire-behave/item-schema,
:path [:item]}}})

(comment
(inspect/inspect "/tmp/pres.html" (get-in @ztx [:fhir/inter "StructureDefinition"]) {:closed true})

Expand Down

0 comments on commit cd718c0

Please sign in to comment.