2024-09-11 21:08:35 +00:00
|
|
|
package patient
|
2024-09-11 17:31:40 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
|
"mhtml/database"
|
|
|
|
|
"mhtml/h"
|
|
|
|
|
"mhtml/partials/sheet"
|
|
|
|
|
"mhtml/ui"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Patient struct {
|
|
|
|
|
Name string
|
|
|
|
|
ReasonForVisit string
|
|
|
|
|
AppointmentDate time.Time
|
|
|
|
|
LocationName string
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-11 21:08:35 +00:00
|
|
|
func List(ctx *fiber.Ctx) *h.Partial {
|
2024-09-11 17:31:40 +00:00
|
|
|
patients, err := database.HList[Patient]("patients")
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return h.NewPartial(h.Div(
|
|
|
|
|
h.Class("patient-list"),
|
|
|
|
|
h.P("Error loading patients"),
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(patients) == 0 {
|
|
|
|
|
return h.NewPartial(h.Div(
|
|
|
|
|
h.Class("patient-list"),
|
|
|
|
|
h.P("No patients found"),
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return h.NewPartial(h.Div(
|
2024-09-12 17:15:17 +00:00
|
|
|
h.HxExtension("debug"),
|
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-12 02:06:34 +00:00
|
|
|
func AddPatientSheetPartial(ctx *fiber.Ctx) *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
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func AddPatientSheet(onClosePath string) h.Renderable {
|
|
|
|
|
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"),
|
|
|
|
|
h.P("Add Patient", h.Class("text-lg font-bold")),
|
|
|
|
|
addPatientForm(),
|
|
|
|
|
),
|
2024-09-12 02:06:34 +00:00
|
|
|
})
|
2024-09-11 17:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-11 23:41:21 +00:00
|
|
|
func addPatientForm() h.Renderable {
|
2024-09-11 18:09:55 +00:00
|
|
|
return h.Form(
|
2024-09-12 02:06:34 +00:00
|
|
|
h.TriggerChildren(),
|
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 02:06:34 +00:00
|
|
|
Type: "text",
|
|
|
|
|
Label: "Name",
|
|
|
|
|
Name: "name",
|
|
|
|
|
DefaultValue: "fart",
|
2024-09-11 18:09:55 +00:00
|
|
|
}),
|
|
|
|
|
ui.Input(ui.InputProps{
|
|
|
|
|
Type: "text",
|
|
|
|
|
Label: "Reason for visit",
|
|
|
|
|
Name: "reason-for-visit",
|
|
|
|
|
}),
|
|
|
|
|
ui.Input(ui.InputProps{
|
|
|
|
|
Type: "date",
|
|
|
|
|
Label: "Appointment Date",
|
|
|
|
|
Name: "appointment-date",
|
|
|
|
|
}),
|
|
|
|
|
ui.Input(ui.InputProps{
|
|
|
|
|
Type: "text",
|
|
|
|
|
Label: "Location Name",
|
|
|
|
|
Name: "location-name",
|
|
|
|
|
}),
|
|
|
|
|
ui.PrimaryButton(ui.ButtonProps{
|
|
|
|
|
Text: "Add Patient",
|
|
|
|
|
Class: "rounded p-2",
|
|
|
|
|
Type: "submit",
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-11 23:41:21 +00:00
|
|
|
func Row(patient *Patient, index int) h.Renderable {
|
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-11 23:41:21 +00:00
|
|
|
func AddPatientButton() h.Renderable {
|
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
|
|
|
})
|
|
|
|
|
}
|