step 17 : onchange dob

This commit is contained in:
sindhu
2024-06-06 15:06:10 +07:00
parent aa1b553f99
commit a237b56e33
5 changed files with 188 additions and 105 deletions

View File

@@ -15,6 +15,7 @@ import (
"runtime"
"strconv"
"strings"
"time"
dev_mddoctorview "cpone/views/dev/mddoctor"
@@ -50,6 +51,32 @@ type MdDoctorHandler struct {
MdDoctorServices MdDoctorServices
}
// calculate age
func daysInMonth(year int, month time.Month) int {
return time.Date(year, month+1, 0, 0, 0, 0, 0, time.UTC).Day()
}
func CalculateAge(birthDate, currentDate time.Time) (years, months, days int) {
years = currentDate.Year() - birthDate.Year()
months = int(currentDate.Month() - birthDate.Month())
days = currentDate.Day() - birthDate.Day()
// Adjust if birth date is later in the year than current date
if days < 0 {
// Calculate days in the previous month
lastMonth := currentDate.AddDate(0, -1, 0)
days += daysInMonth(lastMonth.Year(), lastMonth.Month())
months--
}
if months < 0 {
months += 12
years--
}
return years, months, days
}
// GET FOTO PROFILE DOCTOR
func (lh *MdDoctorHandler) GetFotoProfile(c echo.Context) error {
// Mengambil nama file dari parameter URL
@@ -3883,6 +3910,18 @@ func (lh *MdDoctorHandler) HandleOpenEditForm(c echo.Context) error {
Code: dataDoctorList.M_DoctorReligionCode,
})
birthDate, err := time.Parse("2006-01-02", dataDoctorList.M_DoctorDOB)
if err != nil {
return fmt.Errorf("Error convert %v", err)
}
currentDate, err := time.Parse("2006-01-02", dataTglNow)
if err != nil {
return fmt.Errorf("Error convert %v", err)
}
tahun, bulan, hari := CalculateAge(birthDate, currentDate)
newForm := dev_mddoctorview.BodyFormDoctor(
// doctor id
models.CustomTextFieldv2Prm{
@@ -3909,7 +3948,7 @@ func (lh *MdDoctorHandler) HandleOpenEditForm(c echo.Context) error {
Placeholder: "Tanggal Lahir Edit",
Type: "hidden",
ID: "doctortgllahiredit",
Value: dataDoctorList.M_DoctorDOB,
// Value: dataDoctorList.M_DoctorDOB,
// Value: "2021-01-01",
},
// sapaan
@@ -3999,7 +4038,7 @@ func (lh *MdDoctorHandler) HandleOpenEditForm(c echo.Context) error {
Placeholder: "Tahun",
Type: "text",
ID: "doctorimbuhantahun",
// Value: "",
Value: strconv.Itoa(tahun) + " Tahun",
},
// bulan
models.CustomTextFieldv2Prm{
@@ -4008,6 +4047,7 @@ func (lh *MdDoctorHandler) HandleOpenEditForm(c echo.Context) error {
Placeholder: "Bulan",
Type: "text",
ID: "doctorimbuhanbulan",
Value: strconv.Itoa(bulan) + " Bulan",
},
// hari
models.CustomTextFieldv2Prm{
@@ -4016,6 +4056,7 @@ func (lh *MdDoctorHandler) HandleOpenEditForm(c echo.Context) error {
Placeholder: "Hari",
Type: "text",
ID: "doctorimbuhanhari",
Value: strconv.Itoa(hari) + " Hari",
},
// pendidikan terakhir
models.CustomDropdownv1Prm{