diff --git a/modules/db/test/blaze/db/api_test.clj b/modules/db/test/blaze/db/api_test.clj index 094bd7e0c..f94274454 100644 --- a/modules/db/test/blaze/db/api_test.clj +++ b/modules/db/test/blaze/db/api_test.clj @@ -2239,6 +2239,38 @@ count := 1 [0 :id] := "0")))) + (testing "Medication" + (testing "with one ingredient reference" + (with-system-data [{:blaze.db/keys [node]} config] + [[[:put {:fhir/type :fhir/Medication :id "0" + :ingredient + [{:fhir/type :fhir.Medication/ingredient + :item #fhir/Reference{:reference "Substance/0"}}]}] + [:put {:fhir/type :fhir/Substance :id "0"}] + [:put {:fhir/type :fhir/Medication :id "1"}]]] + + (testing "ingredient" + (given (pull-type-query node "Medication" [["ingredient" "Substance/0"]]) + count := 1 + [0 :id] := "0")))) + + (testing "with two ingredient references" + (with-system-data [{:blaze.db/keys [node]} config] + [[[:put {:fhir/type :fhir/Medication :id "0" + :ingredient + [{:fhir/type :fhir.Medication/ingredient + :item #fhir/Reference{:reference "Substance/0"}} + {:fhir/type :fhir.Medication/ingredient + :item #fhir/Reference{:reference "Substance/1"}}]}] + [:put {:fhir/type :fhir/Substance :id "0"}] + [:put {:fhir/type :fhir/Substance :id "1"}] + [:put {:fhir/type :fhir/Medication :id "1"}]]] + + (testing "ingredient" + (given (pull-type-query node "Medication" [["ingredient" "Substance/0"]]) + count := 1 + [0 :id] := "0"))))) + (testing "Observation" (with-system-data [{:blaze.db/keys [node]} config] [[[:put {:fhir/type :fhir/Observation :id "id-0" diff --git a/modules/fhir-path/src/blaze/fhir_path.clj b/modules/fhir-path/src/blaze/fhir_path.clj index 9add4a57c..270ce13ae 100644 --- a/modules/fhir-path/src/blaze/fhir_path.clj +++ b/modules/fhir-path/src/blaze/fhir_path.clj @@ -172,22 +172,21 @@ (throw-anom (ba/incorrect (is-type-specifier-msg coll))))))) -(defn- as-type-specifier-msg [coll] - (format "as type specifier with more than one item at the left side `%s`" - (pr-str coll))) - (deftype AsTypeExpression [expression type-specifier] Expression (-eval [_ context coll] (let [coll (-eval expression context coll)] (case (coll/count coll) - 0 coll + 0 [] 1 (if (identical? type-specifier (fhir-spec/fhir-type (coll/nth coll 0))) coll []) - (throw-anom (ba/incorrect (as-type-specifier-msg coll))))))) + ;; HACK: normally multiple items should throw an error. However in R4 many + ;; FHIRPath expressions of search parameters use the as type specifier wrongly. + ;; Please remove that hack for R5. + (filterv #(identical? type-specifier (fhir-spec/fhir-type %)) coll))))) (deftype UnionExpression [e1 e2] Expression @@ -260,7 +259,10 @@ coll []) - (throw-anom (ba/incorrect (as-type-specifier-msg coll)))))) + ;; HACK: normally multiple items should throw an error. However in R4 many + ;; FHIRPath expressions of search parameters use the as type specifier wrongly. + ;; Please remove that hack for R5. + (filterv #(identical? type-specifier (fhir-spec/fhir-type %)) coll)))) (deftype OfTypeFunctionExpression [type-specifier] Expression diff --git a/modules/fhir-path/test/blaze/fhir_path_test.clj b/modules/fhir-path/test/blaze/fhir_path_test.clj index b74994d8d..d0b454ae8 100644 --- a/modules/fhir-path/test/blaze/fhir_path_test.clj +++ b/modules/fhir-path/test/blaze/fhir_path_test.clj @@ -18,7 +18,7 @@ [taoensso.timbre :as log])) (st/instrument) -(log/set-level! :trace) +(log/set-min-level! :trace) (test/use-fixtures :each tu/fixture) @@ -506,15 +506,19 @@ {:fhir/type :fhir/Patient :id "foo"}) count := 0)) - (testing "multiple item returns an error" + ;; HACK: normally multiple items should throw an error. However in R4 many + ;; FHIRPath expressions of search parameters use the as type specifier wrongly. + ;; Please remove that hack for R5. + (testing "multiple items are filtered" (given (eval - "Patient.identifier as string" + "Patient.identifier as Identifier" {:fhir/type :fhir/Patient :id "id-162953" :identifier [#fhir/Identifier{:value "value-163922"} #fhir/Identifier{:value "value-163928"}]}) - ::anom/category := ::anom/incorrect - ::anom/message := "as type specifier with more than one item at the left side `[#fhir/Identifier{:value \"value-163922\"} #fhir/Identifier{:value \"value-163928\"}]`"))) + count := 2 + [0] := #fhir/Identifier{:value "value-163922"} + [1] := #fhir/Identifier{:value "value-163928"}))) ;; 6.3.4 as(type : type specifier) (deftest as-function-test @@ -538,15 +542,19 @@ {:fhir/type :fhir/Patient :id "foo"}) count := 0)) - (testing "multiple item returns an error" + ;; HACK: normally multiple items should throw an error. However in R4 many + ;; FHIRPath expressions of search parameters use the as type specifier wrongly. + ;; Please remove that hack for R5. + (testing "multiple items are filtered" (given (eval - "Patient.identifier.as(string)" + "Patient.identifier.as(Identifier)" {:fhir/type :fhir/Patient :id "id-162953" :identifier [#fhir/Identifier{:value "value-163922"} #fhir/Identifier{:value "value-163928"}]}) - ::anom/category := ::anom/incorrect - ::anom/message := "as type specifier with more than one item at the left side `[#fhir/Identifier{:value \"value-163922\"} #fhir/Identifier{:value \"value-163928\"}]`"))) + count := 2 + [0] := #fhir/Identifier{:value "value-163922"} + [1] := #fhir/Identifier{:value "value-163928"}))) ;; 6.5. Boolean logic