-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbb.edn
245 lines (213 loc) · 15.7 KB
/
bb.edn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
{:deps {}
:tasks {:requires ([clojure.string :as str]
[clojure.java.io :as io]
[clojure.java.shell]
[babashka.fs :as fs]
[cheshire.core :as json]
[clojure.pprint])
:init (do
(def green "\u001B[32m")
(def purple "\u001B[35m")
(def clear-color "\u001B[0m")
(def bold "\033[0;1m")
(def bold-end "\033[22m")
(def green-underline "\033[32;4m")
(defn colored-printer [map & [ks]]
(doseq [[k v] (if ks (select-keys map ks) map)]
(println (str bold (str/capitalize (name k)) ": " bold-end (str v)))))
(defn sh
"clojure.java.shell/sh wrapper-simplifier
command - shell command represented as a single string"
[command & {:keys [dir]}]
(let [args (str/split command (re-pattern "\\s"))
args-w-dir (concat args (when dir [:dir dir]))
cmd-str (str "$ " command (when dir (str " :dir " dir)))]
(println cmd-str)
(:out (apply clojure.java.shell/sh args-w-dir))))
(defn pull-deps
"deps-maps - [{:url url, :dirname dirname} ...]
:url - FHIR NPM package url
:dirname - destination folder"
[deps-maps]
(doseq [{:keys [url dirname]} deps-maps]
(let [arch-name (format "%s_arch.tgz" (gensym))]
(shell (format "mkdir -p %s" dirname))
(shell (format "curl -o %s %s" (str dirname \/ arch-name) url))
(shell {:dir dirname} (format "tar -xzf %s" arch-name))
(shell {:dir dirname} (format "rm -rf %s" arch-name))
(shell {:dir dirname} (format "cp -a package/. ." arch-name))
(shell {:dir dirname} "rm -rf package")))))
:enter (do
(println (str purple "Executing: " clear-color bold (:name (current-task)) bold-end))
(def task-start-ts (System/currentTimeMillis)))
:leave (do
(println
(str green "Task: " bold (:name (current-task)) bold-end
" " green-underline "finished in "
(- (System/currentTimeMillis) task-start-ts) " ms" clear-color \newline)))
set-zen-fhir-version {:doc "Setup zen.fhir/version regex"
:task (let [current-git-repo-tag (or (first *command-line-args*) (-> "git describe --tag --abbrev=0" sh str/trim-newline))
semantic-version-pattern (re-pattern "(\\d+)\\.(\\d+)\\.(\\d+)(-.+)?")
[match major minor _patch _pre-release] (re-find semantic-version-pattern current-git-repo-tag)]
(println (str "Version: " bold match bold-end))
(spit "resources/zen-fhir-version" match))}
set-zen-fhir-lib-version {:doc "Setup zen.fhir lib version"
:task (let [current-git-repo-tag (or (first *command-line-args*)
(str/trim-newline (sh "git describe --tag --abbrev=0"
:dir "zen.fhir")))]
(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
{:depends [clean-up-npm]
:task (let [s1 (rand-int 100000)
s2 (rand-int 100000)]
(println "- SLEEP #1" s1)
(Thread/sleep s1)
(println "- SLEEP #1 done")
(shell "npm --registry=https://packages.simplifier.net install")
(println "- SLEEP #2")
(Thread/sleep s2)
(println "- SLEEP #2 done")
(shell "npm --registry=https://packages.simplifier.net install"))}
pull-nz-igs
{:task (do
(shell "mkdir -p node_modules")
(clojure "-X zen.fhir.igs-etl.nz/etl! :package-dir-dest '\"node_modules\"'"))}
pull-r4b
{:task (pull-deps [{:url "http://packages2.fhir.org/packages/hl7.fhir.r4b.core/4.3.0"
:dirname "r4b/hl7.fhir.r4b.core"}
{:url "http://packages2.fhir.org/packages/hl7.terminology.r4/5.0.0"
:dirname "r4b/hl7.terminology.r4"}
{:url "http://packages2.fhir.org/packages/hl7.fhir.uv.subscriptions-backport.r4b/1.1.0"
:dirname "r4b/hl7.fhir.uv.subscriptions-backport.r4b"}])}
pull-r5
{:task (pull-deps [{:url "http://packages2.fhir.org/packages/hl7.fhir.r5.core/5.0.0"
:dirname "r5/hl7.fhir.r5.core"}
{:url "http://packages2.fhir.org/packages/hl7.terminology.r5/4.0.0"
:dirname "r5/hl7.terminology.r5"}
{:url "http://packages2.fhir.org/packages/hl7.fhir.uv.extensions.r5/1.0.0"
:dirname "r5/hl7.fhir.uv.extensions.r5"}
#_{:url "http://packages2.fhir.org/packages/hl7.fhir.r5.search/5.0.0"
:dirname "r5/hl7.fhir.r5.search"}])}
pull-au-igs
{:task (pull-deps [{:url "http://hl7.org.au/fhir/4.1.0/package.tgz"
:dirname "node_modules/hl7.fhir.au.base"}
{:url "http://hl7.org.au/fhir/core/0.1.0-draft/package.tgz"
:dirname "node_modules/hl7.fhir.au.core"}
{:url "https://build.fhir.org/ig/hl7au/draft-diagnostic-orders/package.tgz"
:dirname "node_modules/hl7.fhir.au.draft.diagnostic-orders"}])}
pull-chile-igs
{:task (pull-deps [{:url "https://hl7chile.cl/fhir/ig/CoreCL/package.tgz"
:dirname "node_modules/hl7.fhir.cl.corecl"}
{:url "http://hl7.org/fhir/uv/ips/STU1/package.tgz"
:dirname "node_modules/hl7.fhir.uv.ips"}])}
my-debug {:task (sh "cat node_modules/hl7.org.nz.fhir.ig.nhi/ValueSet-nhi-address-type.json || echo \"FAIL. but it's ok\"")}
kbv-basis-patch
{:task (shell "cp resources/KBV_PR_Base_Patient.json node_modules/kbv.basis/KBV_PR_Base_Patient.json")}
init {:depends [set-zen-fhir-version set-zen-fhir-lib-version install-npm kbv-basis-patch #_pull-nz-igs pull-r4b pull-r5 #_pull-au-igs #_pull-chile-igs build-us-core-601]}
repl {:depends [set-zen-fhir-version set-zen-fhir-lib-version]
:task (clojure "-M:test:nrepl -m nrepl.cmdline --middleware [cider.nrepl/cider-middleware]")}
test {:depends [set-zen-fhir-version set-zen-fhir-lib-version pull-au-igs]
:task (clojure "-M:test:kaocha")}
ci-test {:depends [set-zen-fhir-version set-zen-fhir-lib-version init test]}
init-r3 {:depends [set-zen-fhir-version set-zen-fhir-lib-version]
:task (do
(Thread/sleep (rand-int 100000))
(shell {:dir "r3"} "npm --registry=https://packages.simplifier.net install")
(Thread/sleep (rand-int 100000))
(shell {:dir "r3"} "npm --registry=https://packages.simplifier.net install"))}
init-r3-nictiz-hack {:depends [set-zen-fhir-version set-zen-fhir-lib-version]
:task (do
(Thread/sleep (rand-int 100000))
(shell {:dir "r3-tmp-nictiz-hack"} "npm --registry=https://packages.simplifier.net install")
(Thread/sleep (rand-int 100000))
(shell {:dir "r3-tmp-nictiz-hack"} "npm --registry=https://packages.simplifier.net install"))}
build-r3-nictiz-hack (binding [*command-line-args* (list "r3-tmp-nictiz-hack/"
"zrc/standalone_projects/"
nil
nil
true)]
(run 'build-stanadlone-projects))
build-us-core-601 {:task (do
(Thread/sleep (rand-int 100000))
(shell {:dir "us-core-610"} "npm --registry=https://packages.simplifier.net install")
(Thread/sleep (rand-int 100000))
(shell {:dir "us-core-610"} "npm --registry=https://packages.simplifier.net install")
(let [root-manifest-file (io/file "us-core-610/package.json")
root-manifest-deps (:dependencies (json/parse-string (slurp root-manifest-file) keyword))
us-core-manifest-file (io/file "us-core-610/node_modules/hl7.fhir.us.core/package.json")
updated-manifest (assoc (json/parse-string (slurp us-core-manifest-file) keyword)
:name "hl7.fhir.us.core610"
:dependencies (dissoc root-manifest-deps :hl7.fhir.us.core))
_ (spit us-core-manifest-file (json/generate-string updated-manifest))
_ (.renameTo
^File (io/file "us-core-610/node_modules/hl7.fhir.us.core")
(io/file "us-core-610/node_modules/hl7.fhir.us.core610"))]))}
build (clojure "-X:build all")
zen-profiles (let [[node-modules zrc ver package] *command-line-args*]
(clojure (str "-M -m zen.fhir.tooling " node-modules " " zrc " " ver " " package)))
zen-profiles-packages (clojure (str "-J-Xmx16g -M -m zen.fhir.tooling-packages " (str/join " " *command-line-args*)))
build-stanadlone-projects (let [[node-modules zrc preserve-package alt-package-name rename-package] *command-line-args*
opts (cond-> {}
preserve-package
(assoc "preserve-package" preserve-package)
alt-package-name
(assoc "alt-package-name" alt-package-name)
rename-package
(assoc "rename-package" rename-package))]
(clojure (str "-M -m zen.fhir.tooling.aidbox-standalone-v2 " node-modules " " zrc " " (str/join " " (flatten (seq opts))))))
build-standalone-zen-profiles-all-versions
(let [get-dependency-meta (fn [dependency] (-> (sh (str "npm --registry https://packages.simplifier.net --json view " dependency))
(json/parse-string keyword)))
{:as top-level-deps, :keys [dependencies]} (read-string (slurp "resources/package.edn"))]
(doseq [dependency dependencies
:let [{:as npm-view-obj, versions :versions dependency-name :name {latest-dep-version :latest} :dist-tags}
(get-dependency-meta dependency)]]
(doseq [v versions
:let [dependency-meta (get-dependency-meta (str dependency "@" v))
dep-folder (str dependency "-" v "/")]
:when (= "R4" (:fhirVersion dependency-meta))]
(try
(println "\nProcessing dependency...")
(colored-printer dependency-meta [:fhirVersion :name :version])
(sh (str "npm --prefix " dep-folder " --registry https://packages.simplifier.net install " (:url dependency-meta)))
(let [package-json-path (str/join "/" [dep-folder "node_modules" dependency-name "package.json"])
package-json (slurp package-json-path)
package-info (json/parse-string package-json keyword)
fhir-dep (get-in package-info [:dependencies :hl7.fhir.r4.core])
fhir-4.0.1-core-iself? (and (= (:name package-info) "hl7.fhir.r4.core")
(= (:version package-info) "4.0.1"))]
(cond
(and (nil? fhir-dep) (not fhir-4.0.1-core-iself?))
(println (str purple "WARNING:" clear-color " package doesn't contain FHIR core dependency"))
#_(str/starts-with? (str fhir-dep) "4")
(or fhir-4.0.1-core-iself? (= "4.0.1" fhir-dep)) #_"NOTE: simplifier hosts onle 4.0.1 currently"
(binding [*command-line-args* (list (str dep-folder "node_modules/")
"zrc/standalone_projects/"
dependency-name
(if (= v latest-dep-version)
dependency
(str dependency "-" v)))]
(run 'build-stanadlone-projects)
#_"NOTE: this is latest IG version zip name hotfix"
(when (= v latest-dep-version)
(let [zip-location "zrc/standalone_projects/"
zip-name (str dependency ".zip")
zip-fixed-name (str (str/replace dependency \. \-) ".zip")
zip-version-name (str dependency "-" v ".zip")]
(sh (str "cp " zip-name " " zip-fixed-name) :dir zip-location)
(sh (str "cp " zip-name " " zip-version-name) :dir zip-location))))
:else
(println (str purple "WARNING:" clear-color " package FHIR core version is not r4"))))
(catch Exception e
(println (str purple "ERROR:" clear-color " " (.getMessage e))))
(finally
(try (sh (str "rm -rf " dep-folder))
(catch Exception _)))))))
build-terminology-bundles (clojure "-M:terminology-build -m zen.fhir.tooling.terminology")
outdated {:doc "Check outdated libraries"
:task (clojure " -Sdeps '{:deps {com.github.liquidz/antq {:mvn/version \"RELEASE\"}}} '-M -m antq.core ")}
lint {:doc "Lint source code"
:task (clojure "-Sdeps '{:deps {clj-kondo/clj-kondo {:mvn/version \"RELEASE\"}}} '-m clj-kondo.main --lint src:test --parallel --fail-level error")}}}