Skip to content

Commit

Permalink
Fix bug with a CodeSystem being present multiple times in edge cases
Browse files Browse the repository at this point in the history
This bug took place when a certain CodeSystem was:
- `:bundled` as included and `:not-present` as excluded
- `:bundled` as excluded and `:not-present` as excluded
  • Loading branch information
katibov committed Nov 24, 2022
1 parent befb7e3 commit 3e7b9f0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/zen/fhir/generator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,22 @@
(if (= inclusion-status :exclude)
(filter #(not= :bundled (:zen.fhir/content %)) nested-systems)
nested-systems))))
compose-elements)]
compose-elements)

code-systems-by-url
(group-by :fhir/url code-systems)]
(into #{}
code-systems)))
(mapcat
(fn [[_url css-for-url]]
;; Filter so that there is only one entry per URL
(let [unique-css (set css-for-url)]
(case (count unique-css)
1 unique-css
;; When count is 2, CodeSystem comes as both :bundled and :not-present.
;; In this case only :not-present variant is kept
;; as :bundled implies that entire CodeSystem is present (i.e. it can’t be :not-bundled)
2 (filter #(= :not-present (:zen.fhir/content %)) unique-css)))))
code-systems-by-url)))


(defmethod generate-zen-schema :ValueSet [rt fhir-inter [url inter-res]]
Expand Down
16 changes: 14 additions & 2 deletions test/zen/fhir/generator_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
(def from-network-extension (-> "zen/fhir/plannet_fromnetwork_stripped.edn" io/resource slurp read-string))
(def new-patients-extension (-> "zen/fhir/plannet_newpatients_stripped.edn" io/resource slurp read-string))
(def practitioner-role-profile (-> "zen/fhir/plannet_practitionerrole_stripped.edn" io/resource slurp read-string))
(def multiple-same-url-includes-excludes-vs (-> "zen/fhir/ig-fiction_multiple-same-url-includes-excludes.edn" io/resource slurp read-string))
(zen.fhir.core/load-definiton ztx {:url (:url practitioner-role-profile)} (assoc practitioner-role-profile :zen.fhir/package-ns "plannet"))
(zen.fhir.core/load-definiton ztx {:url (:url new-patients-extension)} (assoc new-patients-extension :zen.fhir/package-ns "plannet"))
(zen.fhir.core/load-definiton ztx {:url (:url from-network-extension)} (assoc from-network-extension :zen.fhir/package-ns "plannet")))
(zen.fhir.core/load-definiton ztx {:url (:url from-network-extension)} (assoc from-network-extension :zen.fhir/package-ns "plannet"))
(zen.fhir.core/load-definiton ztx {:url (:url multiple-same-url-includes-excludes-vs)} (assoc multiple-same-url-includes-excludes-vs :zen.fhir/package-ns "ig-fiction")))

(zen.fhir.core/load-all ztx nil
{:params {"hl7.fhir.r4.core" {:zen.fhir/package-ns 'fhir-r4}
Expand Down Expand Up @@ -408,7 +410,17 @@
:keys
{:dateTime {:confirms #{'fhir-r4.dateTime/schema}, :fhir/flags #{:MS}},
:_dateTime {:confirms #{'fhir-r4.Element/schema}}},
:require #{:dateTime}}}}}})
:require #{:dateTime}}}}}

;; Check that a CodeSystem present multiple times
;; in compose.include and compose.exclude
;; is not duplicated.
'ig-fiction.value-set.multiple-same-url-includes-excludes
{'value-set
{:zen/tags #{'zen.fhir/value-set}
:fhir/code-systems
#{{:fhir/url "http://example.com",
:zen.fhir/content :not-present}}}}})

(t/testing "Intermediate representation is correct for"
(t/testing "polymorphic keys defined on an element"
Expand Down
25 changes: 25 additions & 0 deletions test/zen/fhir/ig-fiction_multiple-same-url-includes-excludes.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{:resourceType "ValueSet"
:id "multiple-same-url-includes-excludes"
:url "ig-fiction/multiple-same-url-includes-excludes"
:version "4.0.1"
:status "active"
:compose
{:include
[{:system "http://example.com"
:concept
[{:code "1"}
{:code "2"}
{:code "3"}]}
{:system "http://example.com"
:concept
[{:code "4"}
{:code "5"}]}
;; Concepts for this element are not present on purpose
{:system "http://example.com"}]
:exclude
[{:system "http://example.com"
:concept
[{:code "6"}
{:code "7"}]}
;; Concepts for this element are not present on purpose
{:system "http://example.com"}]}}

0 comments on commit 3e7b9f0

Please sign in to comment.