Created
December 8, 2021 11:01
-
-
Save niquola/6fb5bc0a0664ae8871ace9ecb057ded5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns proto.zen.loader-test | |
(:require [proto.zen.loader :as sut] | |
[box.world :as world] | |
[pg.core] | |
[clojure.test :refer [deftest testing is]] | |
[matcho.core :as matcho])) | |
(deftest bundle-integration | |
(def test-zrc-dir "test-temp-zrc") | |
(def profile-libs {'carin-bb.test | |
["http://hl7.org/fhir/us/carin-bb/StructureDefinition/C4BB-ExplanationOfBenefit-Pharmacy"] | |
'pdex.test | |
["http://hl7.org/fhir/us/davinci-pdex/StructureDefinition/pdex-medicationdispense"]}) | |
(def profile-location-urls {"http://terminology.hl7.org/CodeSystem/medicationdispense-status" | |
"http://hl7.org/fhir/R4/codesystem-medicationdispense-status.json"}) | |
(def _ (reset! sut/load-resource-cache | |
(-> (clojure.java.io/resource "fixtures/load-resource-cache.edn") | |
.getPath | |
slurp | |
read-string))) | |
(def r (sut/create-zen-projects&valueset-bundle! test-zrc-dir profile-libs profile-location-urls)) | |
#_(spit "test/fixtures/load-resource-cache.edn" | |
(with-out-str | |
(binding [*print-meta* true] | |
(prn @sut/load-resource-cache)))) | |
(testing "start box" | |
(def box-config | |
{:id "mybox-with-bundle-integraiton" | |
:import {:zen {}, :fhir-4.0.0 {}} | |
:config {:db (pg.core/db-spec-from-env) | |
:root-db (pg.core/db-spec-from-env) | |
:zen {:deps (sut/get-zen-deps profile-libs)}}}) | |
#_(world/force-start-box box-config) | |
(world/ensure-box box-config) | |
(world/prune box-config :ValueSet) | |
(world/prune box-config :CodeSystem) | |
(world/prune box-config :Concept) | |
(matcho/match @(:zen/ctx (world/manifest box-config)) {:errors empty?})) | |
(testing "$load bundle and check integrity" | |
(box.world/match | |
box-config | |
{:uri "/fhir/$load" | |
:request-method :post | |
:resource {:source (.getPath (clojure.java.io/resource "project_resources.ndjson.gz"))}} | |
{:status 200 | |
:body {:ValueSet (:valuesets r) | |
:CodeSystem (:codesystems r) | |
:Concept (:concepts r)}})) | |
(testing "validate medication dispense" | |
(def medication-dispense | |
(-> (clojure.java.io/resource "fixtures/MedicationDispense-1.edn") | |
.getPath | |
slurp | |
read-string)) | |
(box.world/match box-config | |
{:uri "/fhir/MedicationDispense/$validate" | |
:request-method :post | |
:resource medication-dispense} | |
{:body {:id "allok"}}) | |
(box.world/match box-config | |
{:uri "/fhir/MedicationDispense/$validate" | |
:request-method :post | |
:resource (assoc medication-dispense :status "invalid status")} | |
{:body {:issue [{:expression ["MedicationDispense.status.aidbox-fx/valueset"]}] | |
:id "validationfail"}}))) | |
[({:id "PractitionerRole.specialty.coding", | |
:path "PractitionerRole.specialty.coding", | |
:slicing {:discriminator [{:type "value", :path "system"}], :rules "open"}} | |
{:id "PractitionerRole.specialty.coding:SpecialtyUZI", | |
:path "PractitionerRole.specialty.coding", | |
:sliceName "SpecialtyUZI", | |
:short "SpecialtyUZI", | |
:alias ["SpecialismeUZI"], | |
:binding | |
{:extension | |
[{:url | |
"http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName", | |
:valueString "PractitionerSpecialty"}], | |
:strength "required", | |
:valueSetReference | |
{:reference | |
"http://decor.nictiz.nl/fhir/ValueSet/2.16.840.1.113883.2.4.3.11.60.40.2.17.1.6--20171231000000", | |
:display "SpecialismeUZICodelijst"}}})] | |
[{:id "PractitionerRole.specialty.coding", | |
:path "PractitionerRole.specialty.coding", | |
:slicing {:discriminator [{:type "value", :path "system"}], :rules "open"}} | |
{:id "PractitionerRole.specialty.coding:SpecialtyUZI", | |
:path "PractitionerRole.specialty.coding", | |
:sliceName "SpecialtyUZI", | |
:short "SpecialtyUZI", | |
:alias ["SpecialismeUZI"], | |
:binding {:strength "required", | |
:valueSetReference {:reference "http://decor.nictiz.nl/fhir/ValueSet/2.16.840.1.113883.2.4.3.11.60.40.2.17.1.6--20171231000000", | |
:display "SpecialismeUZICodelijst"}}} | |
{:id "PractitionerRole.specialty.coding:SpecialtyUZI.system", | |
:path "PractitionerRole.specialty.coding.system", | |
:min 1, | |
:fixedUri "http://fhir.nl/fhir/NamingSystem/uzi-rolcode"}] | |
;; 1. | |
;; fixed (without slicing) -> const | |
;; pattern -> match | |
;; collection slicing -> fhir/slicing | |
;; :speciality | |
;; {:keys {:coding | |
;; {:fhir/slice | |
;; {:slices {:SpecialityUZI {:match {:system "http://fhir.nl/fhir/NamingSystem/uzi-rolcode"} | |
;; :schema {:type 'zen/vector :every {}}} | |
;; :Other {:match {:system "other"} | |
;; :schema {:type 'zen/vector :every {}}}} | |
;; :default {:type 'zen/vector :every {}}}}}} | |
;; ;; slicing -> match | |
;; ;; slicing -> filter -> constraints | schema | |
;; [{} {} {} {}] | |
;; ;; split-by descriminator | |
;; [{}] [{} {}] [{}] | |
;; schema for slices | |
;; schema for each element |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment