        (map-vals #(->> (group-by sex %)
                        (map-vals count)))))
 
+(defn subject-count [visits]
+  (->> (r/map :visit/subject visits)
+       (into #{})
+       (count)))
+
 (defn query [db expr]
   (let [visits (api/query db (edn/read-string expr))]
     (ring-resp/response

       :visit-count-by-study-event (visit-count-by-study-event visits)
       :visit-count-by-age-decade-and-sex
       (visit-count-by-age-decade-and-sex visits)
       :subject-count (->> (r/map :visit/subject visits)
                           (into #{})
                           (count))})))

;; ---- Snapshots -------------------------------------------------------------


            [lens.util :as util]
            [lens.api :as api]
            [clojure.core.async :refer [timeout]]
            [clojure.core.reducers :as r]
            [clojure.set :as set])
  (:import [java.util UUID]))

(def page-size 50)
