add some simple validation sanity checks on the create/update functions

This commit is contained in:
Gered 2014-07-18 14:12:41 -04:00
parent 68480a3ca0
commit f265a5c4ce

View file

@ -105,6 +105,19 @@
(first) (first)
:href)) :href))
(defn resource?
"returns true if the given argument is an EDN representation of a FHIR resource"
[x]
(and (map? x)
(string? (:resourceType x))
(not= "Bundle" (:resourceType x))))
(defn bundle?
"returns true if the given argument is an EDN representation of a FHIR bundle"
[x]
(and (map? x)
(= "Bundle" (:resourceType x))))
(single-search-op eq "=") (single-search-op eq "=")
(single-search-op lt "<") (single-search-op lt "<")
(single-search-op lte "<=") (single-search-op lte "<=")
@ -277,6 +290,8 @@
reference: reference:
create: http://hl7.org/implement/standards/fhir/http.html#create" create: http://hl7.org/implement/standards/fhir/http.html#create"
[base-url type resource] [base-url type resource]
(if-not (resource? resource)
(throw (Exception. "Not a valid FHIR resource")))
(let [resource-name (->fhir-resource-name type) (let [resource-name (->fhir-resource-name type)
uri-components ["/" resource-name]] uri-components ["/" resource-name]]
(fhir-request :post (fhir-request :post
@ -292,6 +307,8 @@
reference: reference:
update: http://hl7.org/implement/standards/fhir/http.html#update" update: http://hl7.org/implement/standards/fhir/http.html#update"
[base-url type id resource & {:keys [version]}] [base-url type id resource & {:keys [version]}]
(if-not (resource? resource)
(throw (Exception. "Not a valid FHIR resource")))
(let [resource-name (->fhir-resource-name type) (let [resource-name (->fhir-resource-name type)
uri-components (if version uri-components (if version
["/" resource-name id "_history" version] ["/" resource-name id "_history" version]