Skip to content

Commit

Permalink
Clean-up redundant :confirms on non base profiles
Browse files Browse the repository at this point in the history
Co-authored-by: @yurii_makhotkin <[email protected]>
  • Loading branch information
ApricotLace and KGOH committed Nov 28, 2022
1 parent 3e7b9f0 commit 62988e2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
6 changes: 5 additions & 1 deletion bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@
(println (str "Version: " bold current-git-repo-tag bold-end))
(spit "resources/zen-fhir-lib-version" current-git-repo-tag))}

clean-up-npm {:doc "Deletes node_module directory to prevent npm fail because of custom-populated node_modules directory."
:task (shell "rm -rf node_modules")}

install-npm
{:task (do
{:depends [clean-up-npm]
:task (do
(when (.exists (io/file "node_modules/fhir.org.nz.ig.base"))
(shell "mv node_modules/fhir.org.nz.ig.base ."))
(shell "npm --registry=https://packages.simplifier.net install")
Expand Down
41 changes: 28 additions & 13 deletions src/zen/fhir/generator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@
set)
pattern)}))

(defn get-schema-type-by-url [fhir-inter url]
(let [inter-res (get-in fhir-inter ["StructureDefinition" url])
instantiated-resource?
(and (not (:abstract inter-res))
(= "resource" (:kind inter-res)))]
(case (and instantiated-resource?
(:derivation inter-res))
"constraint" 'zen.fhir/profile-schema
"specialization" 'zen.fhir/base-schema
'zen.fhir/structure-schema)))


(defn el-schema [fhir-inter [url el]]
(let [sch (merge-with
Expand All @@ -152,7 +163,9 @@
(url->symbol fhir-inter
(str "http://hl7.org/fhir/StructureDefinition/" tp)
{:type :element-type :e el :url url}))))]
{:confirms #{type-sym}})
(when (not= (get-schema-type-by-url fhir-inter url)
'zen.fhir/profile-schema)
{:confirms #{type-sym}}))
(when-let [ext-sym (when-let [ext (:fhir/extension el)]
(url->symbol fhir-inter ext {:type :extension :el el :url url}))]
{:confirms #{ext-sym}})
Expand Down Expand Up @@ -198,18 +211,20 @@


(defn els-schema [fhir-inter [url inter-res]]
(merge (when-let [els (not-empty (:| inter-res))]
{:type 'zen/map
:keys (sp/transform [sp/MAP-VALS]
#(el-schema fhir-inter [url %])
els)})
(when-let [requires (->> (:| inter-res)
(into #{}
(comp
(filter (comp :required val))
(map key)))
not-empty)]
{:require requires})))
(when-let [schema (not-empty
(merge (when-let [els (not-empty (:| inter-res))]
(not-empty
(utils/strip-nils
{:keys (->> (update-vals els #(not-empty (el-schema fhir-inter [url %])))
(utils/strip-nils))})))
(when-let [requires (->> (:| inter-res)
(into #{}
(comp
(filter (comp :required val))
(map key)))
not-empty)]
{:require requires})))]
(merge {:type 'zen/map} schema)))


(defmethod generate-kind-schema :complex-type [fhir-inter [url inter-res]]
Expand Down
10 changes: 5 additions & 5 deletions test/zen/fhir/generator_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@
:fhir/extensionUri "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex"}
:identifier {:type 'zen/vector
:minItems 1
:every {:confirms #{'fhir-r4.Identifier/schema}
:every {:confirms nil?
:type 'zen/map
:keys {:system {:confirms #{'fhir-r4.uri/schema}}
:keys {:system {:confirms nil?}
:value {:zen/desc "The value that is unique within the system."
:confirms #{'fhir-r4.string/schema}}}}}}}}
:confirms nil?}}}}}}}

'us-core.value-set.birthsex
{'ns 'us-core.value-set.birthsex
Expand Down Expand Up @@ -408,8 +408,8 @@
:keys {:effective
{:type 'zen/map,
:keys
{:dateTime {:confirms #{'fhir-r4.dateTime/schema}, :fhir/flags #{:MS}},
:_dateTime {:confirms #{'fhir-r4.Element/schema}}},
{:dateTime {:confirms nil?, :fhir/flags #{:MS}},
:_dateTime nil?},
:require #{:dateTime}}}}}

;; Check that a CodeSystem present multiple times
Expand Down

0 comments on commit 62988e2

Please sign in to comment.