     )
   
   (defn get-tracker [id]
-    ;; TODO support also fetching with tracker_indentifier
+    ;; TODO support also fetching with tracker_indentifier?
     (first (select tracker
                    (where {:id id}))))  
   

          max-results (:maxResults criteria max-result-count)
          result-limit (min max-result-count max-results)

          ;; TODO ugly hack around Korma macro thing: one condition clause may not hold several references to single field
          conditions1 (merge
                       (when event-start {:event_time ['>= event-start] })
                       (when store-start {:created_on ['>= store-start] })
                       (when tracker-ids {:tracker_id ['in tracker-ids] }))
          conditions2 (merge
                       (when event-end {:event_time ['<= event-end] })
                       (when store-end {:created_on ['<= store-end] }))          
          ]
      (if (not (and (empty? conditions1) (empty? conditions2)))
        (let [results (select event
                              (with event-location)
                              (with event-extension-value (fields :value)
                                    (with event-extension-type (fields :name)))              
                              (where (and (and conditions1) conditions2))
                              (limit result-limit))
                              ]
          
          results
          )
        '())))
  
  (defn get-events [ids]
    (select event

  (:use korma.db)
  (:use korma.core)
  (:use [clojure.tools.logging :only (debug info warn error)])
  (:require [ruuvi-server.util :as util])
  (:import org.joda.time.DateTime)
  )

