Skip to content

Commit

Permalink
Merge pull request #765 from samply/764-quantity-wo-value
Browse files Browse the repository at this point in the history
Fix Quantity Indexing without Value
  • Loading branch information
alexanderkiel committed Jul 5, 2022
2 parents 6a20209 + a84c303 commit cd22ea8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
20 changes: 9 additions & 11 deletions modules/db/src/blaze/db/impl/search_param/quantity.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion modules/db/test/blaze/db/impl/search_param/quantity_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit cd22ea8

Please sign in to comment.