htmgo/partials/patient/create.go

39 lines
800 B
Go
Raw Normal View History

2024-09-11 21:08:35 +00:00
package patient
import (
"github.com/gofiber/fiber/v2"
"mhtml/features/patient"
2024-09-11 21:08:35 +00:00
"mhtml/h"
"mhtml/partials/sheet"
)
func Create(ctx *fiber.Ctx) *h.Partial {
name := ctx.FormValue("name")
reason := ctx.FormValue("reason-for-visit")
location := ctx.FormValue("location-name")
err := patient.NewService(ctx).Create(patient.CreatePatientRequest{
Name: name,
ReasonForVisit: reason,
LocationName: location,
2024-09-11 21:08:35 +00:00
})
if err != nil {
ctx.Status(500)
return h.NewPartialWithHeaders(h.NewHeaders(""),
h.Div(
h.Text("Error creating patient"),
h.Class("text-red-500"),
),
)
}
2024-09-12 02:06:34 +00:00
headers := h.CombineHeaders(h.PushQsHeader(ctx, "adding", ""), &map[string]string{
2024-09-11 21:08:35 +00:00
"HX-Trigger": "patient-added",
2024-09-12 02:06:34 +00:00
})
2024-09-11 21:08:35 +00:00
2024-09-12 02:06:34 +00:00
return h.NewPartialWithHeaders(
headers,
sheet.Close(ctx))
2024-09-11 21:08:35 +00:00
}