add support for parsing relative resource urls
This commit is contained in:
parent
74337341d2
commit
08a07dadc2
|
@ -164,26 +164,33 @@
|
||||||
url))
|
url))
|
||||||
|
|
||||||
(defn parse-resource-url
|
(defn parse-resource-url
|
||||||
"given an absolute URL to a FHIR resource and the base URL for the FHIR server, parses the
|
"parses an absolute URL to a FHIR resource or a relative URL to a FHIR resource. if an
|
||||||
URL returning a map containing the resource type, id and version number (if present). if
|
absolute URL is provided, any present version number will also be parsed. returns a map
|
||||||
the URL cannot be parsed, returns nil"
|
containing the discrete components of the URL that can be used to identify the resouce.
|
||||||
[server-url url]
|
if the URL cannot be parsed, returns nil"
|
||||||
(if (and server-url
|
([relative-url]
|
||||||
url
|
(let [parts (-> (strip-query-params relative-url)
|
||||||
(.startsWith url server-url))
|
(str/split #"/"))]
|
||||||
(let [parts (-> (strip-query-params url)
|
(if (= 2 (count parts))
|
||||||
(strip-base-url server-url)
|
{:type (-> parts first ->kebab-case keyword)
|
||||||
(str/split #"/"))]
|
:id (second parts)})))
|
||||||
(cond
|
([server-url absolute-url]
|
||||||
(= 2 (count parts))
|
(if (and server-url
|
||||||
{:type (-> parts first ->kebab-case keyword)
|
absolute-url
|
||||||
:id (second parts)}
|
(.startsWith absolute-url server-url))
|
||||||
|
(let [parts (-> (strip-query-params absolute-url)
|
||||||
|
(strip-base-url server-url)
|
||||||
|
(str/split #"/"))]
|
||||||
|
(cond
|
||||||
|
(= 2 (count parts))
|
||||||
|
{:type (-> parts first ->kebab-case keyword)
|
||||||
|
:id (second parts)}
|
||||||
|
|
||||||
(and (= 4 (count parts))
|
(and (= 4 (count parts))
|
||||||
(= "_history" (nth parts 2)))
|
(= "_history" (nth parts 2)))
|
||||||
{:type (-> parts first ->kebab-case keyword)
|
{:type (-> parts first ->kebab-case keyword)
|
||||||
:id (second parts)
|
:id (second parts)
|
||||||
:version (last parts)}))))
|
:version (last parts)})))))
|
||||||
|
|
||||||
(defn collect-resources
|
(defn collect-resources
|
||||||
"returns a sequence containing all of the resources contained in the given bundle.
|
"returns a sequence containing all of the resources contained in the given bundle.
|
||||||
|
|
Reference in a new issue