Skip to content

Commit

Permalink
refactor: add parameter: get-param-value (WIP 3)
Browse files Browse the repository at this point in the history
DONE:
* create `invalid-string-param-msg`
* fix `invalid-string-param-anom` so it uses `invalid-string-param-msg`
* fix calls to `get-param-value` so they use `validate-string`
("measure" and "reportType")

TODO: make sure `validate-string` is the right validator for "measure"
and "reportType".

There is a chance I will have to create new validators for:
- measure
- report-type
  • Loading branch information
allentiak committed Oct 1, 2024
1 parent 717e374 commit 48d71c5
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
(format "Invalid parameter `%s` with value `%s`. Should be a date in format YYYY, YYYY-MM or YYYY-MM-DD."
name value))

(defn- invalid-string-param-msg [name value]
(format "Invalid parameter `%s` with value `%s`. Should be a string."
name value))

(defn- get-param-value-from-resource [body name]
(when (identical? :fhir/Parameters (fhir-spec/fhir-type body))
(some #(when (= name (:name %)) (:value %)) (:parameter body))))
Expand Down Expand Up @@ -58,10 +62,9 @@
:fhir.issue/expression name))

(defn- invalid-string-param-anom
;; TODO: fix this
[name value]
(ba/incorrect
(invalid-date-param-msg name value)
(invalid-string-param-msg name value)
:fhir/issue "value"
:fhir/operation-outcome "MSG_PARAM_INVALID"
:fhir.issue/expression name))
Expand Down Expand Up @@ -117,9 +120,9 @@
period-end (get-required-param-value
request "periodEnd" coerce-date validate-date)
measure (get-param-value
request "measure" (fn [_n v] v))
request "measure" (fn [_n v] v) validate-string)
report-type (get-param-value
request "reportType" coerce-report-type)
request "reportType" coerce-report-type validate-string)
subject-ref (coerce-subject-ref-param request)]
(let [report-type (some-> report-type type/value)]
(if (and (= :get request-method) (= "subject-list" report-type))
Expand Down

0 comments on commit 48d71c5

Please sign in to comment.