Skip to content

Commit

Permalink
Add patient crud
Browse files Browse the repository at this point in the history
  • Loading branch information
xamelon committed Dec 28, 2023
1 parent cf34551 commit bc864d6
Show file tree
Hide file tree
Showing 8 changed files with 438 additions and 56 deletions.
2 changes: 1 addition & 1 deletion routes/ui/$dev-mode_get.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function debugButton() {
button.onclick = () => showDebugOverlay();
button.innerHTML = "DEBUG"
button.style.cssText = `
position: absolute;
position: fixed;
bottom: 0; right: 0;
background-color: rgba(124,0,124,0.3);
padding: 5px 10px`;
Expand Down
5 changes: 3 additions & 2 deletions routes/ui/forms/responses/search_get.clj
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ where q.resource::text ilike ?" (str "%" (:query params) "%")])
(get-in f [:resource :subject :name 0 :family]))
]]]
[:div
{:class "bg-white border-b px-4 py-4 text-sm whitespace-nowrap cursor-pointer text-blue-500"}
{:data-turbo "false"
:class "bg-white border-b px-4 py-4 text-sm whitespace-nowrap cursor-pointer text-blue-500"}
[:a {:class "px-3 py-2 text-gray-500 transition-colors duration-200 rounded-lg dark:text-gray-300 hover:bg-gray-100"

:data-turbo "false"
:href (str "/ui/sdc#/questionnaire-response/" (get-in f [:resource :id]))}
"Open"
]]])
Expand Down
9 changes: 9 additions & 0 deletions routes/ui/patients/:id_delete.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(box/set-header! "Content-Type" "text/vnd.turbo-stream.html; charset=utf-8")

(let [params (box/route-params)
result (box/delete {:id (:id params) :resourceType "Patient"})]
(when (= (:resourceType result) "Patient")
[:turbo-stream {:target (str "patient-" (:id result))
:action "remove"}]
)
)
100 changes: 100 additions & 0 deletions routes/ui/patients/edit_get.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
(box/set-header! "Content-Type" "text/vnd.turbo-stream.html; charset=utf-8")

(let [params (box/url-params)
patient (when (:patient-id params)
(box/read {:id (:patient-id params) :resourceType "Patient"}))]
[:turbo-stream {:target "modal"
:action "update"}
[:template
[:section {:id "edit-patient"
:class "fixed top-0 bottom-0 right-0 left-0 z-10"}
[:script
"function removeModal(e) {
if(e.target.id == 'edit-patient-root') {
e.target.parentElement.remove();
}
}"
]
[:div
{:class "min-h-screen p-6 bg-gray-100 flex items-center justify-center bg-opacity-80"
:id "edit-patient-root"
:onclick "removeModal(event)"
}
[:div
{:class "container max-w-screen-lg mx-auto"
:id "edit-patient-modal"}
[:div
[:div
{:class "bg-white rounded shadow-lg p-4 px-4 md:p-8 mb-6"}
[:div
{:class "grid gap-4 gap-y-2 text-sm grid-cols-1 lg:grid-cols-3"}
[:div
{:class "text-gray-600"}
[:p {:class "font-medium text-lg"} "Personal Details"]
[:p "Please fill out all the fields."]]
[:form {:action "/ui/patients/save" :method "POST"
:class "lg:col-span-2"}
(when (:id patient)
[:input {:type "hidden"
:name "id"
:value (:id patient)}]
)
[:div
{:class
"grid gap-4 gap-y-2 text-sm grid-cols-1 md:grid-cols-5"}
[:div
{:class "md:col-span-5"}
[:label {:for "full_name"} "First Name"]
[:input
{:type "text",
:name "given",
:id "full_name",
:required true
:class "h-10 border mt-1 rounded px-4 w-full bg-gray-50",
:value (get-in patient [:name 0 :given 0])}]]
[:div
{:class "md:col-span-5"}
[:label {:for "full_name"} "Last Name"]
[:input
{:type "text",
:name "family",
:id "full_name",
:required true
:class "h-10 border mt-1 rounded px-4 w-full bg-gray-50",
:value (get-in patient [:name 0 :family])}]]
[:div
{:class "md:col-span-3"}
[:label {:for "birth-date"} "Date of Birth"]
[:input
{:type "date",
:name "birth-date",
:required true
:id "birth-date",
:class "h-10 border mt-1 rounded px-4 w-full bg-gray-50",
:value (get-in patient [:birthDate])
:placeholder ""}]]
[:div
{:class "md:col-span-2"}
[:label {:for "gender"} "Gender"]
[:select {:name "gender"
:required true
:class "h-10 border mt-1 rounded px-4 w-full bg-gray-50"}
[:option {:value "male" :selected (= (:gender patient) "male")} "Male"]
[:option {:value "female" :selected (= (:gender patient) "female")} "Female"]]]

[:div
{:class "md:col-span-5 text-right"}
[:div
{:class "inline-flex items-end"}
[:button
{:class
"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"}
"Submit"]]]]]]]]]]]]

])

#_[:turbo-stream {:target "modal"
:action "update"}
[:template
[:span "hello"]]
]
15 changes: 15 additions & 0 deletions routes/ui/patients/forms_get.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[:html
[:title "Aidbox | Patients | Forms"]
[:script {:src "https://cdn.tailwindcss.com"}]
[:link {:href "/static/assets/img/fav.svg" :rel "shortcut icon" :type "image/x-icon"}]
[:body
[:script {:src "/ui/$dev-mode"}]
(let [forms (box/sql "select * from questionnaire")
_ (m/set :forms forms)]
[:div
(for [f forms]
[:div
[:span (get-in f [:resource :title])]])]
)
]
]
69 changes: 69 additions & 0 deletions routes/ui/patients/save_post.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
(box/set-header! "Content-Type" "text/vnd.turbo-stream.html; charset=utf-8")

(let [params (box/form-params)
patient (cond-> {:resourceType "Patient"
:name [{:given [(get-in params [:given])]
:family (get-in params [:family])}]
:gender (get-in params [:gender])
:birthDate (get-in params [:birth-date])}
(:id params)
(assoc :id (:id params)))
saved-patient (box/create patient)]

(if (= (:resourceType saved-patient) "Patient")
[:<>
[:turbo-stream {:target "edit-patient"
:action "remove"}]

[:turbo-stream (if-not (:id params)
{:target "patients"
:action "append"}
{:target (str "patient-" (:id patient))
:action "replace"})
[:template
[:div {:class "contents"
:id (str "patient-" (:id saved-patient))}
[:div
{:class "px-4 py-4 text-sm font-medium whitespace-nowrap flex items-center border-b"}
[:h2
{:class "font-medium text-gray-800 dark:text-white"}
(str (get-in saved-patient [:name 0 :given 0]) ", "
(get-in saved-patient [:name 0 :family]))]]
[:div
{:class "px-12 py-4 text-sm font-medium whitespace-nowrap flex items-center border-b"}
(when-let [birth-date (get-in saved-patient [:birthDate])]
[:div
{:class
"inline px-3 py-1 text-sm font-normal rounded-full text-emerald-500 gap-x-2 bg-emerald-100/60 dark:bg-gray-800"}
birth-date])]
[:div
{:class "px-4 py-4 text-sm whitespace-nowrap flex items-center border-b"}
[:div
[:h4 {:class "text-gray-700 dark:text-gray-200"} (get-in saved-patient [:gender])]]]
[:div
{:class "px-4 py-4 text-sm whitespace-nowrap flex items-center border-b"}
[:form {:action "/ui/patients/edit"
:class "mb-0"}
[:input {:type "hidden"
:name "patient-id"
:value (:id saved-patient)}]
[:button
{:class
"px-3 py-2 text-gray-500 transition-colors duration-200 rounded-lg dark:text-gray-300 hover:bg-gray-100"}
[:i.fas.fa-pencil]]]
[:a
{:class
"px-3 py-2 text-gray-500 transition-colors duration-200 rounded-lg dark:text-gray-300 hover:bg-gray-100"
:href (str "/ui/patients/" (str (:id saved-patient)))
:data-turbo-method "DELETE"
:data-turbo-confirm "Do you want to delete patient?"}
[:i.fas.fa-trash]]]]]

]
]
[:turbo-stream {:target "edit-patient-modal"
:action "update"}
[:template [:div {:class "bg-white p-10" }][:code (pr-str saved-patient)]]]
)

)
54 changes: 54 additions & 0 deletions routes/ui/patients/search_get.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
(box/set-header! "Content-Type" "text/vnd.turbo-stream.html; charset=utf-8")

(let [params (box/url-params)
patients (->> (box/sql ["select resource || jsonb_build_object('id', id) resource from Patient
where resource::text ilike ?" (str "%" (:query params) "%")])
(mapv :resource))
_ (m/set :patients patients)
]

[:turbo-stream {:target "patients"
:action "update"}
(into [:template]
(map (fn [p]
[:div {:class "contents"
:id (str "patient-" (:id p))}
[:div
{:class "px-4 py-4 text-sm font-medium whitespace-nowrap flex items-center border-b"}
[:h2
{:class "font-medium text-gray-800 dark:text-white"}
(str (get-in p [:name 0 :given 0]) ", "
(get-in p [:name 0 :family]))]]
[:div
{:class "px-12 py-4 text-sm font-medium whitespace-nowrap flex items-center border-b"}
(when-let [birth-date (get-in p [:birthDate])]
[:div
{:class
"inline px-3 py-1 text-sm font-normal rounded-full text-emerald-500 gap-x-2 bg-emerald-100/60 dark:bg-gray-800"}
birth-date])]
[:div
{:class "px-4 py-4 text-sm whitespace-nowrap flex items-center border-b"}
[:div
[:h4 {:class "text-gray-700 dark:text-gray-200"} (get-in p [:gender])]]]
[:div
{:class "px-4 py-4 text-sm whitespace-nowrap flex items-center border-b"}
[:form {:action "/ui/patients/edit"
:class "mb-0"}
[:input {:type "hidden"
:name "patient-id"
:value (:id p)}]
[:button
{:class
"px-3 py-2 text-gray-500 transition-colors duration-200 rounded-lg dark:text-gray-300 hover:bg-gray-100"}
[:i.fas.fa-pencil]]]
[:a
{:class
"px-3 py-2 text-gray-500 transition-colors duration-200 rounded-lg dark:text-gray-300 hover:bg-gray-100"
:href (str "/ui/patients/" (str (:id p)))
:data-turbo-method "DELETE"
:data-turbo-confirm "Do you want to delete patient?"}
[:i.fas.fa-trash]]]]) patients))


]
)
Loading

0 comments on commit bc864d6

Please sign in to comment.