From d3599ee48ac47dcacbcd973f32447bcbf9423055 Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 3 Sep 2014 09:12:55 -0400 Subject: [PATCH] helper function for finding resources in a bundle by url --- src/clj_hl7_fhir/core.clj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/clj_hl7_fhir/core.clj b/src/clj_hl7_fhir/core.clj index 7280d06..c8d2de2 100644 --- a/src/clj_hl7_fhir/core.clj +++ b/src/clj_hl7_fhir/core.clj @@ -341,6 +341,21 @@ (= rel "previous")))) (vec))))) +(defn find-resource-in + "finds and returns a resource contained in the given bundle, identified by a + relative or absolute resource URL. if not found, nil is returned. throws an + exception if the bundle and/or url supplied is invalid." + [bundle resource-url] + (when bundle + (validate-bundle! bundle) + (let [base-url (get-base-url-from-bundle bundle) + search-url (if (absolute-url? resource-url) + resource-url + (relative->absolute-url base-url resource-url))] + (->> (:entry bundle) + (filter #(= search-url (:id %))) + (first))))) + (defn fetch-all "for resources that are returned over more then one page, this will automatically fetch all pages of resources and them into a single bundle that contains all of