Skip to content

Commit

Permalink
fix(dotnet): make it being able to pack as nuget package
Browse files Browse the repository at this point in the history
Fixed all the errors I got on running
`dotnet pack --configuration Release`
  • Loading branch information
krvital committed Oct 17, 2024
1 parent bffc4f9 commit 5e7a228
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 256 deletions.
22 changes: 20 additions & 2 deletions src/aidbox_sdk/converter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
(url->resource-name (get schema :base)))
:fhir-version (get schema :fhir-version)
:package (get schema :package)
:service-type? (fhir/service-type? schema)
:url (get schema :url)
:type (get schema :type)
:derivation (get schema :derivation))))))
Expand All @@ -216,6 +217,23 @@
x))
elements))))

(defn add-service-type-flag
"Adds `service-type` flag to each element. The value will be `true` if type of
element belongs to service-types, and `false` otherwise."
[schema]
(letfn [(update-elements [elements]
(walk/postwalk
(fn [x]
(if (:type x)
(let [service-type? (fhir/service-type-element? (:fhir-version schema) x)]
(assoc x :service-type service-type?))
x))
elements))]
(-> schema
(update :elements update-elements)
(update :backbone-elements (fn [backbone-elements]
(for [backbone backbone-elements]
(update backbone :elements update-elements)))))))
;;

(defn find-elements-by-names [element-names schema]
Expand Down Expand Up @@ -267,7 +285,6 @@
;; Convert main function
;;


(defn convert [schemas]
(->> schemas
(map resolve-element-references)
Expand All @@ -276,7 +293,8 @@
(map (fn [schema]
(update schema :backbone-elements #(resolve-choices (flatten-backbones % [])))))
(resolve-choices)
(resolve-dependencies)))
(resolve-dependencies)
(map add-service-type-flag)))

;;
;; Search Params
Expand Down
36 changes: 35 additions & 1 deletion src/aidbox_sdk/fhir.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

;; Base Types and Datatypes

(def r4-base-types #{"Element" "Resource" "DomainResource"})
(def r4-base-types #{"Element" "Resource" "DomainResource"
;; NOTE: technically `Bundle` is not a base type,
;; but it's here for a reason.
"Bundle"})

(def r4-primitive-types
#{"boolean" "integer" "string" "decimal" "uri" "url" "canonical" "base64Binary"
Expand All @@ -32,6 +35,13 @@
r4-metadata-types
r4-special-purpose-datatypes))

(def r4-service-types
"This is special set of types that are not represented in FHIR in no way,
but are needed for SDK generation. Essentially, service schemas are:
base types + datatypes - primitive-types."
(set/union (set/difference r4-datatypes r4-primitive-types)
r4-base-types))

(def r4b-base-types r4-base-types)

(def r4b-primitive-types r4-primitive-types)
Expand All @@ -51,6 +61,13 @@
r4b-metadata-types
r4b-special-purpose-datatypes))

(def r4b-service-types
"This is special set of types that are not represented in FHIR in no way,
but are needed for SDK generation. Essentially, service schemas are:
base types + datatypes - primitive-types."
(set/union (set/difference r4b-datatypes r4b-primitive-types)
r4b-base-types))

(def r5-base-types
#{"Base" "Element" "BackboneElement" "DataType" "PrimitiveType" "BackboneType"
"Resource" "DomainResource" "CanonicalResource" "MetadataResource"})
Expand All @@ -73,6 +90,13 @@
r5-metadata-types
r5-special-purpose-datatypes))

(def r5-service-types
"This is special set of types that are not represented in FHIR in no way,
but are needed for SDK generation. Essentially, service schemas are:
base types + datatypes - primitive-types."
(set/union (set/difference r5-datatypes r5-primitive-types)
r5-base-types))

;; Predicates
(defn resource-type-pred [rt] (fn [schema] (= rt (:resourceType schema))))
(defn kind-pred [kind] (fn [schema] (= kind (:kind schema))))
Expand Down Expand Up @@ -162,3 +186,13 @@

(defn base-package? [schema]
(contains? #{"hl7.fhir.r4.core" "hl7.fhir.r4b.core" "hl7.fhir.r5.core"} (:package schema)))

(defmulti service-type? :fhir-version)
(defmethod service-type? "hl7.fhir.r4.core" [schema] (contains? r4-service-types (:id schema)))
(defmethod service-type? "hl7.fhir.r4b.core" [schema] (contains? r4b-service-types (:id schema)))
(defmethod service-type? "hl7.fhir.r5.core" [schema] (contains? r5-service-types (:id schema)))

(defmulti service-type-element? (fn [package _element] package))
(defmethod service-type-element? "hl7.fhir.r4.core" [_ {:keys [type]}] (contains? r4-service-types type))
(defmethod service-type-element? "hl7.fhir.r4b.core" [_ {:keys [type]}] (contains? r4b-service-types type))
(defmethod service-type-element? "hl7.fhir.r5.core" [_ {:keys [type]}] (contains? r5-service-types type))
Loading

0 comments on commit 5e7a228

Please sign in to comment.