Skip to content

Commit

Permalink
refactor: add parameter: get-param-value (WIP 2)
Browse files Browse the repository at this point in the history
* create `invalid-string-param-msg`
* create `invalid-string-param-anom` so it uses
`invalid-string-param-msg`
* create `validate-string`
* 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 7513e32 commit e73caa3
Showing 1 changed file with 17 additions and 2 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 @@ -57,6 +61,14 @@
:fhir/operation-outcome "MSG_PARAM_INVALID"
:fhir.issue/expression name))

(defn- invalid-string-param-anom
[name value]
(ba/incorrect
(invalid-string-param-msg name value)
:fhir/issue "value"
:fhir/operation-outcome "MSG_PARAM_INVALID"
:fhir.issue/expression name))

(defn- coerce-date
"Coerces `value` into a System.Date.
Expand All @@ -70,6 +82,9 @@
(defn- validate-date [name value]
(if (system/date? value) value (invalid-date-param-anom name value)))

(defn- validate-string [name value]
(if (string? value) value (invalid-string-param-anom name value)))

(defn- invalid-report-type-param-msg [report-type]
(format "Invalid parameter `reportType` with value `%s`. Should be one of `subject`, `subject-list` or `population`."
report-type))
Expand Down Expand Up @@ -105,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 e73caa3

Please sign in to comment.