51
51
(defn safe-conj [a b] (conj a (or b {})))
52
52
53
53
(defn compile-elements [schemas]
54
- (->> (vec schemas)
55
- #_(filter #(not (= (:derivation (last %)) " constraint" )))
56
- (map (fn [[name definition ]]
57
- (->> (help/elements-to-vector definition )
58
- (help/get-typings-and-imports (:type definition ) (or (:required definition ) []))
59
- (test1 (help/get-resource-name name))
60
- (safe-conj (hash-map :base (get definition :base )))
61
- (hash-map name))))
62
- (into {})))
54
+ (map (fn [schema]
55
+ (->> (help/elements-to-vector schema)
56
+ (help/get-typings-and-imports (:type schema) (or (:required schema) []))
57
+ (test1 (help/get-resource-name (:url schema)))
58
+ (safe-conj (hash-map :base (get schema :base ) :url (get schema :url ))))) schemas))
63
59
64
60
(defn combine-elements [schemas]
65
- (->> (vec schemas)
66
- #_(filter #(= " hl7.fhir.r4.core#4.0.1/Observation" (first %)))
67
- (map (fn [[name definition ]]
68
- (->> definition
69
- (mix-parents-elements-circular (dissoc schemas nil ))
70
- (mix-parents-backbones-circular (dissoc schemas nil ))
71
- (hash-map name))))
72
- (into {})))
61
+ (map (fn [schema]
62
+ (->> schema
63
+ (mix-parents-elements-circular schemas)
64
+ (mix-parents-backbones-circular schemas))) schemas))
73
65
74
66
(defn apply-excluded [excluded schema]
75
67
(filter (fn [field-schema]
114
106
115
107
116
108
(defn apply-single-constraint [constraint parent-schema]
109
+ (println parent-schema)
117
110
(->> (:elements parent-schema)
118
111
(apply-required (:required constraint))
119
112
(apply-excluded (:excluded constraint))
120
113
(apply-choises (filter #(contains? (last %) :choices ) (:elements constraint)))
121
114
(hash-map :elements )
122
115
(conj parent-schema)
123
- (apply-patterns (:fqn constraint) (filter #(contains? (last %) :pattern ) (:elements constraint)))))
116
+ (apply-patterns (:url constraint) (filter #(contains? (last %) :pattern ) (:elements constraint)))))
124
117
125
118
(defn apply-constraints [constraint-schemas result base-schemas]
126
- (if (reduce (fn [acc, [schema-name]]
127
- (when (not (get result schema-name)) (reduced true ))) false constraint-schemas)
128
- (apply-constraints constraint-schemas
129
- (reduce (fn [acc [schema-name definition ]]
130
- (if (contains? result (:base definition ))
131
- (conj acc (hash-map schema-name (apply-single-constraint definition (get result (:base definition )))))
132
- (if (contains? base-schemas (:base definition ))
133
- (conj acc (hash-map schema-name (apply-single-constraint definition (get base-schemas (:base definition )))))
134
- acc))) result constraint-schemas) base-schemas) result))
135
-
136
- (defn transform-structure [data] (into {} (map #(hash-map (:fqn %) %) data)))
119
+ (if (reduce (fn [_, constraint-schema]
120
+ (when (not (get result (:url constraint-schema))) (reduced true ))) false constraint-schemas)
121
+ (apply-constraints
122
+ constraint-schemas
123
+ (reduce (fn [acc constraint-schema]
124
+ (if (contains? result (:base constraint-schema))
125
+ (conj acc (hash-map (:url constraint-schema) (apply-single-constraint constraint-schema (get result (:base constraint-schema)))))
126
+
127
+ (if (contains? base-schemas (:base constraint-schema))
128
+ (conj acc (hash-map (:url constraint-schema) (apply-single-constraint constraint-schema (get base-schemas (:base constraint-schema))))) acc))) result constraint-schemas) base-schemas) result))
137
129
138
130
(defn combine-single-class [name elements]
139
131
(->> (map (fn [item]
153
145
(str (str/join (map (fn [definition ] (combine-single-class (:name definition ) (:elements definition ))) (:backbone-elements definition ))))
154
146
(str (str/join (:patterns definition )))
155
147
(str " from ..base import *\n " )
156
- (str " from typing import Optional\n " )
148
+ (str " from typing import Optional, Literal \n " )
157
149
(str " from pydantic import BaseModel\n " )
158
150
(help/write-to-file " /Users/gena.razmakhnin/Documents/aidbox-sdk-js/test_dir/constraint" (help/get-resource-name name))))
159
151
160
152
(defn doallmap [elements] (doall (map save-to-file elements)))
161
153
162
154
(defn main []
163
- (let [schemas (transform-structure ( help/parse-ndjson-gz " /Users/gena.razmakhnin/Documents/aidbox-python-tooklit/fhir-schema-2/1.0.0_hl7.fhir.r4.core#4.0.1_package.ndjson.gz" ) )
164
- base-schemas (->> schemas (filter #(= (:derivation ( last %) ) " specialization" )))
155
+ (let [schemas (help/parse-ndjson-gz " /Users/gena.razmakhnin/Documents/aidbox-python-tooklit/fhir-schema-2/1.0.0_hl7.fhir.r4.core#4.0.1_package.ndjson.gz" )
156
+ base-schemas (->> schemas (filter #(= (:derivation % ) " specialization" )))
165
157
constraint-schemas (->> schemas
166
- (filter #(= (:derivation (last %)) " constraint" ))
167
- (filter #(or (= (first %) " hl7.fhir.r4.core#4.0.1/vitalsigns" ) (= (first %) " hl7.fhir.r4.core#4.0.1/triglyceride" ))))]
158
+ (filter #(= (:derivation %) " constraint" ))
159
+ (filter #(or (= (:url %) " http://hl7.org/fhir/StructureDefinition/vitalsigns" ) (= (:url %) " http://hl7.org/fhir/StructureDefinition/triglyceride" ) (= (:url %) " http://hl7.org/fhir/StructureDefinition/bmi" ))))]
160
+
168
161
(->> base-schemas
169
- #_(compile-elements )
170
- #_(combine-elements )
171
- #_(apply-constraints constraint-schemas {})
172
- #_(map save-to-file))))
162
+ (compile-elements )
163
+ (combine-elements )
164
+ (filter #(not (nil? (:url %))))
165
+ (map (fn [item] (hash-map (:url item) item)))
166
+ (into {})
167
+ (apply-constraints constraint-schemas {})
168
+ (map save-to-file))))
173
169
174
170
(main )
0 commit comments