add some more validation/sanity checks

This commit is contained in:
Gered 2014-07-18 15:50:52 -04:00
parent f265a5c4ce
commit 153dc8325d

View file

@ -99,12 +99,6 @@
(assoc m name value))) (assoc m name value)))
{}))) {})))
(defn- get-bundle-next-page-url [bundle]
(->> (:link bundle)
(filter #(= "next" (:rel %)))
(first)
:href))
(defn resource? (defn resource?
"returns true if the given argument is an EDN representation of a FHIR resource" "returns true if the given argument is an EDN representation of a FHIR resource"
[x] [x]
@ -118,6 +112,16 @@
(and (map? x) (and (map? x)
(= "Bundle" (:resourceType x)))) (= "Bundle" (:resourceType x))))
(defn validate-resource! [resource]
(if (and resource
(not (resource? resource)))
(throw (Exception. "Not a valid FHIR resource"))))
(defn validate-bundle! [bundle]
(if (and bundle
(not (bundle? bundle)))
(throw (Exception. "Not a valid FHIR bundle"))))
(single-search-op eq "=") (single-search-op eq "=")
(single-search-op lt "<") (single-search-op lt "<")
(single-search-op lte "<=") (single-search-op lte "<=")
@ -138,10 +142,18 @@
reference: reference:
bundles: http://hl7.org/implement/standards/fhir/extras.html#bundle" bundles: http://hl7.org/implement/standards/fhir/extras.html#bundle"
[bundle] [bundle]
(validate-bundle! bundle)
(->> bundle (->> bundle
:entry :entry
(map :content))) (map :content)))
(defn- get-bundle-next-page-url [bundle]
(validate-bundle! bundle)
(->> (:link bundle)
(filter #(= "next" (:rel %)))
(first)
:href))
(defn fetch-next-page (defn fetch-next-page
"for resources that are returned over more then one page, this will fetch the "for resources that are returned over more then one page, this will fetch the
next page of resources as indicated by the link information contained in the next page of resources as indicated by the link information contained in the