split up iso date formatting into 2 functions for timestamps and dates

This commit is contained in:
Gered 2014-07-08 08:30:36 -04:00
parent 5b2354fd0f
commit 5d8717c74c
2 changed files with 35 additions and 7 deletions

View file

@ -56,7 +56,7 @@
(str (:namespace value) "|" (format-search-value (:value value)))
(instance? Date value)
(->iso-date value)
(->iso-timestamp value)
:else
(-> value str escape-parameter)))
@ -187,3 +187,23 @@
(merge
(search-params->query-map where)
(apply hash-map params)))))
;(def server-url "http://fhir.healthintersections.com.au/open")
;(def server-url "http://spark.furore.com/fhir")
(def server-url "http://uhnvesb01d.uhn.on.ca:25180/hapi-fhir-jpaserver/base")
;(get-resource server-url :patient 1)
;(get-resource server-url :patient 181)
;(search server-url :patient [(lt :birthdate "1984-12-13")])
;(search server-url :patient [(eq :birthdate "1985-01-01")])
;(search server-url :patient [(eq :birthdate "1925-08-27T00:00:00")])
;(search server-url :patient [(eq :birthdate (new Date 25 7 27))])
;(search server-url :patient [(eq :birthdate (new Date 90 0 1))])
;(search server-url :patient [(eq :name "king") (eq :age 1337)])
;(search-params->query-kvs [(eq :name "king") (eq :age 1337)])

View file

@ -7,17 +7,25 @@
[cheshire.core :as json]))
(def tz (TimeZone/getDefault))
(def iso8601 "yyyy-MM-dd'T'HH:mm:ssZZ")
(def iso8601-timestamp "yyyy-MM-dd'T'HH:mm:ss")
(def iso8601-date "yyyy-MM-dd")
(defn ->iso-date
"returns an ISO8601 formatted date/time string for the given date. this is the format
which FHIR expects all date/times to be in"
[^Date date]
(defn format-date [^Date date ^String format]
(if date
(let [df (SimpleDateFormat. iso8601)]
(let [df (SimpleDateFormat. format)]
(.setTimeZone df tz)
(.format df date))))
(defn ->iso-timestamp
"returns an ISO8601 formatted date/time string for the given date object"
[^Date date]
(format-date date iso8601-timestamp))
(defn ->iso-date
"returns an ISO8601 formatted date string for the given date object"
[^Date date]
(format-date date iso8601-date))
(defn map->query-string [m]
(->> m
(reduce