diff --git a/clinic/shadow-cljs.edn b/clinic/shadow-cljs.edn index f4e2981..1605d44 100644 --- a/clinic/shadow-cljs.edn +++ b/clinic/shadow-cljs.edn @@ -9,5 +9,4 @@ :output-dir "resources/public/js" :asset-path "/js" :modules {:app {:entries [clinic.core]}} - :devtools {:after-load clinic.core/mount-root}}} - :dev-http {8000 "resources/public"}} + :devtools {:after-load clinic.core/mount-root}}}} diff --git a/clinic/src/clj/clinic/routes/core.clj b/clinic/src/clj/clinic/routes/core.clj index 8ce5551..0ade7a6 100644 --- a/clinic/src/clj/clinic/routes/core.clj +++ b/clinic/src/clj/clinic/routes/core.clj @@ -2,15 +2,21 @@ (:require [clinic.config :as config] [clinic.routes.patient :as patient] [clojure.tools.logging :as log] - [compojure.core :refer [context defroutes]] - [compojure.route :refer [not-found]] + [compojure.core :refer [context defroutes GET]] + [compojure.route :refer [not-found resources]] [ring.middleware.json :refer [wrap-json-body wrap-json-response]] + [ring.middleware.keyword-params :refer [wrap-keyword-params]] + [ring.middleware.params :refer [wrap-params]] [ring.util.response :as r])) (defroutes ^:private routes (context "/api/v1" _ - (context "/patients" _ patient/handler)) - (not-found (r/status 404))) + (context "/patients" _ patient/handler) + (not-found (r/status 404))) + + ;; UI + (resources "/") + (GET "/*" _ (r/resource-response "index.html" {:root "public"}))) (defn- wrap-exception-handler [next-handler] (fn exception-handler [request] @@ -23,6 +29,8 @@ "The default API route handler." (-> routes (config/wrap) + (wrap-keyword-params) + (wrap-params) (wrap-json-body {:keywords? true}) (wrap-json-response) (wrap-exception-handler))) diff --git a/clinic/src/clj/clinic/routes/patient.clj b/clinic/src/clj/clinic/routes/patient.clj index 8aae9ac..23dc1a8 100644 --- a/clinic/src/clj/clinic/routes/patient.clj +++ b/clinic/src/clj/clinic/routes/patient.clj @@ -4,16 +4,21 @@ [ring.util.response :as r])) (defn- create-patient! [{{fhir-server-url :fhir-server-base-url} :config - params :body}] - (try - (-> (svc/create! fhir-server-url params) - (r/response) - (r/status 201)) - (catch Exception e - (case (:type (ex-data e)) - :invalid-params (r/status 400) - :mrn-conflict (r/status 503) - (throw e))))) + content-type :content-type + :as request}] + (let [params (case content-type + "application/x-www-form-urlencoded" (request :params) + "application/json" (request :body) + nil)] + (try + (-> (svc/create! fhir-server-url params) + (r/response) + (r/status 201)) + (catch Exception e + (case (:type (ex-data e)) + :invalid-params (r/status 400) + :mrn-conflict (r/status 503) + (throw e)))))) (defroutes handler (POST "/" _ create-patient!))