Skip to content

Commit

Permalink
fix: resolving deps for non base package specializations
Browse files Browse the repository at this point in the history
  • Loading branch information
krvital committed Oct 10, 2024
1 parent 024b8e8 commit 966cc2b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 42 deletions.
3 changes: 2 additions & 1 deletion src/aidbox_sdk/converter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
(map resolve-schema-choices schemas))

(defn collect-dependencies [schema]
(let [primitive-element? (partial fhir/primitive-element? (:package schema))]
(let [primitive-element? (partial fhir/primitive-element? (:fhir-version schema))]
(set/union
(cond-> #{}
(:base-resource-name schema) (conj (:base-resource-name schema))
Expand Down Expand Up @@ -289,6 +289,7 @@
(->> all-schemas
(map (fn [schema]
{:name (:id schema)
:package (:package schema)
:deps (if-let [base (:base schema)]
[(->pascal-case (url->resource-name base))]
[])
Expand Down
87 changes: 47 additions & 40 deletions src/aidbox_sdk/models.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,48 @@
[aidbox-sdk.fixtures.schemas :as fix]))

(def FHIRElement
[:schema {:registry {::fhir-element
[:map
;; shape
[:array {:optional true} :boolean]
[:scalar {:optional true} :boolean]

;; cardinality
[:min {:optional true} :int]
[:max {:optional true} :int]

;; choice type
[:choiceOf {:optional true} :string]
[:choices {:optional true} [:vector :string]]

;; type reference
[:type {:optional true} :string]
[:elementReference {:optional true} [:vector :string]]

;; nested elements (for BackboneElement type)
[:elements {:optional true} [:map-of :keyword [:ref ::fhir-element]]]
[:required {:optional true} [:vector :string]]
[:excluded {:optional true} [:vector :string]]

[:constraints {:optional true} :any]
[:slicing {:optional true} :any]
[:binding {:optional true} [:map
[:valueSet :string]
[:strength :string]]]

;; constants definition
[:fixed {:optional true} :any]
[:pattern {:optional true} :any]

;; reference target
[:refers {:optional true} [:vector :string]]

;; informational
[:modifier {:optional true} :boolean]
[:mustSupport {:optional true} :boolean]
[:summary {:optional true} :boolean]]}}
[:schema
{:registry
{::fhir-element
[:map
;; shape
[:array {:optional true} :boolean]
[:scalar {:optional true} :boolean]

;; cardinality
[:min {:optional true} :int]
[:max {:optional true} :int]

;; choice type
[:choiceOf {:optional true} :string]
[:choices {:optional true} [:vector :string]]

;; type reference
[:type {:optional true} :string]
[:elementReference {:optional true} [:vector :string]]

;; nested elements (for BackboneElement type)
[:elements {:optional true} [:map-of :keyword [:ref ::fhir-element]]]
[:required {:optional true} [:vector :string]]
[:excluded {:optional true} [:vector :string]]

[:constraints {:optional true} :any]
[:slicing {:optional true} :any]
[:binding {:optional true} [:map
[:valueSet :string]
[:strength :string]]]

;; constants definition
[:fixed {:optional true} :any]
[:pattern {:optional true} :any]

;; reference target
[:refers {:optional true} [:vector :string]]

;; informational
[:modifier {:optional true} :boolean]
[:mustSupport {:optional true} :boolean]
[:summary {:optional true} :boolean]]}}
::fhir-element])

(def BaseFHIRSchema
Expand All @@ -57,12 +59,17 @@

[:elements {:optional true} [:map-of :keyword FHIRElement]]

;; NOTE: This field is not a part of FHIRSchema standars. But is has been added on
;; import stage. Need for generation.
[:fhir-version :string]

;; NOTE: shapes of constraints and extensions are not specified here since
;; they are not used in generation
[:constraints {:optional true} :any]
[:extensions {:optional true} :any]])

(def FHIRSchema
"NOTE: This is the enriched FHIR Schema version"
[:or BaseFHIRSchema
(-> BaseFHIRSchema
(mu/assoc :derivation [:enum "specialization" "constraint"])
Expand Down
6 changes: 6 additions & 0 deletions test/aidbox_sdk/converter_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
"Identifier"
"BackboneElement"}
(-> (sut/resolve-dependencies [(dissoc (fixt/get-data :patient-ir-schema) :deps)])
first
:deps))))

(testing "another package specialization demanding base types"
(is (= #{"Resource" "Element"}
(-> (sut/resolve-dependencies [(fixt/get-data :sdc-question-library-ir-schema-no-deps)])
first
:deps)))))

Expand Down
1 change: 1 addition & 0 deletions test/aidbox_sdk/fixtures/patient_ir_schema.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{:package "hl7.fhir.r4.core",
:fhir-version "hl7.fhir.r4.core",
:derivation "specialization",
:name "Patient",
:type "Patient",
Expand Down
2 changes: 1 addition & 1 deletion test/aidbox_sdk/fixtures/schemas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@
:technical-id
"hl7.fhir.r4.core/4.0.1/FHIRSchema/http://hl7.org/fhir/StructureDefinition/Patient/4.0.1",
:derivation "specialization",
:fhirVersion nil,
:fhir-version "hl7.fhir.r4.core",
:name "Patient",
:type "Patient",
:resourceType "FHIRSchema",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{:package "hl7.fhir.uv.sdc",
:derivation "specialization",
:name "Demographics",
:resource-name "sdc-question-library",
:type "Demographics",
:elements
[{:name "dob",
:base "Demographics",
:array false,
:required false,
:value "string",
:type "date",
:choice-option false}
{:name "sex",
:base "Demographics",
:array false,
:required false,
:value "string",
:type "code",
:choice-option false}
{:name "name",
:base "Demographics",
:array false,
:required false,
:value "Base.Element",
:type "Element",
:choice-option false}
{:name "address",
:base "Demographics",
:array false,
:required false,
:value "Base.Element",
:type "Element",
:choice-option false}],
:url "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-question-library",
:base-resource-name "Resource",
:backbone-elements (),
:base "http://hl7.org/fhir/StructureDefinition/Resource",
:fhir-version "hl7.fhir.r4.core"}

0 comments on commit 966cc2b

Please sign in to comment.