From 153dc8325d5caa9f22318cdc4da60b643576f8ec Mon Sep 17 00:00:00 2001 From: gered Date: Fri, 18 Jul 2014 15:50:52 -0400 Subject: [PATCH] add some more validation/sanity checks --- src/clj_hl7_fhir/core.clj | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/clj_hl7_fhir/core.clj b/src/clj_hl7_fhir/core.clj index cae402f..30437b5 100644 --- a/src/clj_hl7_fhir/core.clj +++ b/src/clj_hl7_fhir/core.clj @@ -99,12 +99,6 @@ (assoc m name value))) {}))) -(defn- get-bundle-next-page-url [bundle] - (->> (:link bundle) - (filter #(= "next" (:rel %))) - (first) - :href)) - (defn resource? "returns true if the given argument is an EDN representation of a FHIR resource" [x] @@ -118,6 +112,16 @@ (and (map? 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 lt "<") (single-search-op lte "<=") @@ -138,10 +142,18 @@ reference: bundles: http://hl7.org/implement/standards/fhir/extras.html#bundle" [bundle] + (validate-bundle! bundle) (->> bundle :entry (map :content))) +(defn- get-bundle-next-page-url [bundle] + (validate-bundle! bundle) + (->> (:link bundle) + (filter #(= "next" (:rel %))) + (first) + :href)) + (defn fetch-next-page "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