2024-09-11 21:08:35 +00:00
|
|
|
package patient
|
2024-09-11 17:31:40 +00:00
|
|
|
|
|
|
|
|
import (
|
2024-09-17 17:13:22 +00:00
|
|
|
"github.com/labstack/echo/v4"
|
2024-09-14 00:05:55 +00:00
|
|
|
"github.com/maddalax/htmgo/framework-ui/ui"
|
|
|
|
|
"github.com/maddalax/htmgo/framework/h"
|
2024-09-13 21:33:50 +00:00
|
|
|
"starter-template/features/patient"
|
|
|
|
|
"starter-template/partials/sheet"
|
2024-09-12 18:13:15 +00:00
|
|
|
"strings"
|
2024-09-11 17:31:40 +00:00
|
|
|
)
|
|
|
|
|
|
2024-09-17 17:13:22 +00:00
|
|
|
func List(ctx echo.Context) *h.Partial {
|
2024-09-13 01:31:18 +00:00
|
|
|
patients, err := patient.NewService(ctx).List()
|
2024-09-11 17:31:40 +00:00
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return h.NewPartial(h.Div(
|
|
|
|
|
h.Class("patient-list"),
|
2024-09-13 15:47:18 +00:00
|
|
|
h.Pf("Error loading patients"),
|
2024-09-11 17:31:40 +00:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(patients) == 0 {
|
|
|
|
|
return h.NewPartial(h.Div(
|
|
|
|
|
h.Class("patient-list"),
|
2024-09-13 15:47:18 +00:00
|
|
|
h.Pf("No patients found"),
|
2024-09-11 17:31:40 +00:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return h.NewPartial(h.Div(
|
2024-09-11 18:09:55 +00:00
|
|
|
h.Class("mt-8"),
|
2024-09-11 17:31:40 +00:00
|
|
|
h.Id("patient-list"),
|
2024-09-11 21:08:35 +00:00
|
|
|
h.List(patients, Row),
|
2024-09-11 17:31:40 +00:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 17:13:22 +00:00
|
|
|
func AddPatientSheetPartial(ctx echo.Context) *h.Partial {
|
2024-09-12 17:15:17 +00:00
|
|
|
closePathQs := h.GetQueryParam(ctx, "onClosePath")
|
2024-09-12 02:06:34 +00:00
|
|
|
return h.NewPartialWithHeaders(
|
|
|
|
|
h.PushQsHeader(ctx, "adding", "true"),
|
2024-09-12 17:15:17 +00:00
|
|
|
AddPatientSheet(
|
|
|
|
|
h.Ternary(closePathQs != "", closePathQs, h.CurrentPath(ctx)),
|
|
|
|
|
),
|
2024-09-12 02:06:34 +00:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 01:24:44 +00:00
|
|
|
func AddPatientSheet(onClosePath string) h.Ren {
|
2024-09-12 02:06:34 +00:00
|
|
|
return sheet.Opened(
|
2024-09-11 18:09:55 +00:00
|
|
|
sheet.Props{
|
2024-09-12 02:06:34 +00:00
|
|
|
OnClosePath: onClosePath,
|
|
|
|
|
ClassName: "w-[400px] bg-gray-100 p-4",
|
2024-09-11 18:09:55 +00:00
|
|
|
Root: h.Div(
|
|
|
|
|
h.Class("flex flex-col gap-4"),
|
2024-09-13 15:47:18 +00:00
|
|
|
h.P(h.Text("Add Patient"), h.Class("text-lg font-bold")),
|
2024-09-11 18:09:55 +00:00
|
|
|
addPatientForm(),
|
|
|
|
|
),
|
2024-09-12 02:06:34 +00:00
|
|
|
})
|
2024-09-11 17:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 17:13:22 +00:00
|
|
|
func ValidateForm(ctx echo.Context) *h.Partial {
|
2024-09-12 18:13:15 +00:00
|
|
|
trigger := h.GetTriggerName(ctx)
|
|
|
|
|
value := ctx.FormValue(trigger)
|
|
|
|
|
|
|
|
|
|
if trigger == "name" {
|
|
|
|
|
if strings.ToLower(value) == "sydne" {
|
2024-09-13 15:47:18 +00:00
|
|
|
return h.NewPartial(h.Pf("that name is reserved"))
|
2024-09-12 18:13:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if trigger == "reason-for-visit" {
|
|
|
|
|
if strings.ToLower(value) == "arm hurts" {
|
2024-09-13 15:47:18 +00:00
|
|
|
return h.NewPartial(h.Pf("lol that reason is fake"))
|
2024-09-12 18:13:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if trigger == "location-name" {
|
|
|
|
|
if strings.ToLower(value) == "hospital" {
|
2024-09-13 15:47:18 +00:00
|
|
|
return h.NewPartial(h.Pf("that location is reserved"))
|
2024-09-12 18:13:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return h.NewPartial(h.Fragment())
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 01:24:44 +00:00
|
|
|
func addPatientForm() h.Ren {
|
2024-09-11 18:09:55 +00:00
|
|
|
return h.Form(
|
2024-09-13 01:31:18 +00:00
|
|
|
h.HxExtension("debug, trigger-children"),
|
|
|
|
|
h.Attribute("hx-target-5*", "#submit-error"),
|
2024-09-11 21:08:35 +00:00
|
|
|
h.Post(h.GetPartialPath(Create)),
|
2024-09-11 17:31:40 +00:00
|
|
|
h.Class("flex flex-col gap-2"),
|
2024-09-11 18:09:55 +00:00
|
|
|
ui.Input(ui.InputProps{
|
2024-09-12 18:13:15 +00:00
|
|
|
Type: "text",
|
|
|
|
|
Label: "Name",
|
|
|
|
|
Name: "name",
|
|
|
|
|
DefaultValue: "",
|
|
|
|
|
ValidationPath: h.GetPartialPath(ValidateForm),
|
2024-09-11 18:09:55 +00:00
|
|
|
}),
|
|
|
|
|
ui.Input(ui.InputProps{
|
2024-09-12 18:13:15 +00:00
|
|
|
Type: "text",
|
|
|
|
|
Label: "Reason for visit",
|
|
|
|
|
Name: "reason-for-visit",
|
|
|
|
|
ValidationPath: h.GetPartialPath(ValidateForm),
|
2024-09-11 18:09:55 +00:00
|
|
|
}),
|
|
|
|
|
ui.Input(ui.InputProps{
|
|
|
|
|
Type: "date",
|
|
|
|
|
Label: "Appointment Date",
|
|
|
|
|
Name: "appointment-date",
|
|
|
|
|
}),
|
|
|
|
|
ui.Input(ui.InputProps{
|
2024-09-12 18:13:15 +00:00
|
|
|
Type: "text",
|
|
|
|
|
Label: "Location Name",
|
|
|
|
|
Name: "location-name",
|
|
|
|
|
ValidationPath: h.GetPartialPath(ValidateForm),
|
2024-09-11 18:09:55 +00:00
|
|
|
}),
|
|
|
|
|
ui.PrimaryButton(ui.ButtonProps{
|
|
|
|
|
Text: "Add Patient",
|
|
|
|
|
Class: "rounded p-2",
|
|
|
|
|
Type: "submit",
|
|
|
|
|
}),
|
2024-09-13 01:31:18 +00:00
|
|
|
h.Div(
|
|
|
|
|
h.Id("submit-error"),
|
|
|
|
|
h.Class("text-red-500"),
|
|
|
|
|
),
|
2024-09-11 18:09:55 +00:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 01:24:44 +00:00
|
|
|
func Row(patient *patient.Patient, index int) h.Ren {
|
2024-09-11 18:09:55 +00:00
|
|
|
return h.Div(
|
|
|
|
|
h.Class("flex flex-col gap-2 rounded p-4", h.Ternary(index%2 == 0, "bg-red-100", "")),
|
2024-09-11 17:31:40 +00:00
|
|
|
h.Pf("Name: %s", patient.Name),
|
|
|
|
|
h.Pf("Reason for visit: %s", patient.ReasonForVisit),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 01:24:44 +00:00
|
|
|
func AddPatientButton() h.Ren {
|
2024-09-11 17:31:40 +00:00
|
|
|
return ui.Button(ui.ButtonProps{
|
2024-09-12 17:15:17 +00:00
|
|
|
Id: "add-patient",
|
|
|
|
|
Text: "Add Patient",
|
|
|
|
|
Class: "bg-blue-700 text-white rounded p-2 h-12",
|
|
|
|
|
Trigger: "qs:adding, click",
|
|
|
|
|
Target: sheet.Id,
|
|
|
|
|
Get: h.GetPartialPathWithQs(AddPatientSheetPartial, "onClosePath=/patients"),
|
2024-09-11 17:31:40 +00:00
|
|
|
})
|
|
|
|
|
}
|