From a84c303fa36f6b3a09c689522ad31c3834f9a575 Mon Sep 17 00:00:00 2001 From: Alexander Kiel Date: Tue, 5 Jul 2022 15:27:30 +0200 Subject: [PATCH] Fix Quantity Indexing without Value Closes: #764 --- .../blaze/db/impl/search_param/quantity.clj | 20 ++++++------- .../db/impl/search_param/quantity_test.clj | 28 ++++++++++++++++++- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/modules/db/src/blaze/db/impl/search_param/quantity.clj b/modules/db/src/blaze/db/impl/search_param/quantity.clj index ba4fa9198..91249e913 100644 --- a/modules/db/src/blaze/db/impl/search_param/quantity.clj +++ b/modules/db/src/blaze/db/impl/search_param/quantity.clj @@ -30,19 +30,17 @@ (defn- index-quantity-entries [{:keys [value system code unit]}] - (let [value (type/value value) - system (type/value system) + (let [system (type/value system) code (type/value code) unit (type/value unit)] - (cond-> [] - value - (conj [nil (codec/quantity nil value)]) - code - (conj [nil (codec/quantity code value)]) - (and unit (not= unit code)) - (conj [nil (codec/quantity unit value)]) - (and system code) - (conj [nil (codec/quantity (str system "|" code) value)])))) + (when-let [value (type/value value)] + (cond-> [[nil (codec/quantity nil value)]] + code + (conj [nil (codec/quantity code value)]) + (and unit (not= unit code)) + (conj [nil (codec/quantity unit value)]) + (and system code) + (conj [nil (codec/quantity (str system "|" code) value)]))))) (defmethod index-entries :fhir/Quantity diff --git a/modules/db/test/blaze/db/impl/search_param/quantity_test.clj b/modules/db/test/blaze/db/impl/search_param/quantity_test.clj index f2f117a34..60724a682 100644 --- a/modules/db/test/blaze/db/impl/search_param/quantity_test.clj +++ b/modules/db/test/blaze/db/impl/search_param/quantity_test.clj @@ -362,7 +362,33 @@ :id := "id-155558" :hash-prefix := (hash/prefix hash) :code := "value-quantity" - :v-hash := (codec/quantity "mmHg" 120M)))))) + :v-hash := (codec/quantity "mmHg" 120M))))) + + (testing "without Quantity value" + (let [observation + {:fhir/type :fhir/Observation + :id "id-155558" + :status #fhir/code"final" + :value + #fhir/Quantity + {:code #fhir/code"mm[Hg]" + :system #fhir/uri"http://unitsofmeasure.org"}} + hash (hash/generate observation)] + + (is (empty? (search-param/index-entries + (sr/get search-param-registry "value-quantity" "Observation") + [] hash observation))))) + + (testing "without value" + (let [observation + {:fhir/type :fhir/Observation + :id "id-155558" + :status #fhir/code"final"} + hash (hash/generate observation)] + + (is (empty? (search-param/index-entries + (sr/get search-param-registry "value-quantity" "Observation") + [] hash observation)))))) (testing "FHIRPath evaluation problem" (let [resource {:fhir/type :fhir/Observation :id "foo"}