diff --git a/component/customuploadfotodokterv0/customuploadfotodokterv0.templ b/component/customuploadfotodokterv0/customuploadfotodokterv0.templ new file mode 100644 index 0000000..60e4a6a --- /dev/null +++ b/component/customuploadfotodokterv0/customuploadfotodokterv0.templ @@ -0,0 +1,76 @@ +package customuploadfotodokterv0 + +import "cpone/models" + +templ CustomUploadFotoWithPreviewDokterV0(prm models.CustomUploadFotoPrmV0) { +
+
+ +
+
+
+
+ + + +
+
+ @OnSelect(prm.ID) +} + +script OnSelect(id string) { + const updateFotoButton = document.getElementById('updateFotoButton'); + const fileInput = document.getElementById(id); + const previewImage = document.getElementById(id+"-preview-image"); + + updateFotoButton.addEventListener('click', function() { + fileInput.click(); + }); + + fileInput.addEventListener('change', function() { + const fileName = fileInput.files[0].name; + + if (fileInput.files.length > 0) { + if (fileInput.files[0].size > 500000) { + fileInput.value = ""; + Swal.fire("Warning", "File is too big!", "warning"); + } else { + const reader = new FileReader(); + reader.onload = function(e) { + const base64String = e.target.result; + previewImage.src = base64String; + $('#doctorfotobase64string').val(base64String) + }; + reader.readAsDataURL(fileInput.files[0]); + // previewImage.src = URL.createObjectURL(fileInput.files[0]); + } + } + }) +} diff --git a/component/customuploadfotodokterv0/customuploadfotodokterv0_templ.go b/component/customuploadfotodokterv0/customuploadfotodokterv0_templ.go new file mode 100644 index 0000000..a5ca575 --- /dev/null +++ b/component/customuploadfotodokterv0/customuploadfotodokterv0_templ.go @@ -0,0 +1,183 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package customuploadfotodokterv0 + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import "cpone/models" + +func CustomUploadFotoWithPreviewDokterV0(prm models.CustomUploadFotoPrmV0) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = OnSelect(prm.ID).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func OnSelect(id string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_OnSelect_d389`, + Function: `function __templ_OnSelect_d389(id){const updateFotoButton = document.getElementById('updateFotoButton'); + const fileInput = document.getElementById(id); + const previewImage = document.getElementById(id+"-preview-image"); + + updateFotoButton.addEventListener('click', function() { + fileInput.click(); + }); + + fileInput.addEventListener('change', function() { + const fileName = fileInput.files[0].name; + + if (fileInput.files.length > 0) { + if (fileInput.files[0].size > 500000) { + fileInput.value = ""; + Swal.fire("Warning", "File is too big!", "warning"); + } else { + const reader = new FileReader(); + reader.onload = function(e) { + const base64String = e.target.result; + previewImage.src = base64String; + $('#doctorfotobase64string').val(base64String) + }; + reader.readAsDataURL(fileInput.files[0]); + // previewImage.src = URL.createObjectURL(fileInput.files[0]); + } + } + }) +}`, + Call: templ.SafeScript(`__templ_OnSelect_d389`, id), + CallInline: templ.SafeScriptInline(`__templ_OnSelect_d389`, id), + } +} diff --git a/handlers/dev/md.doctor.handlers.go b/handlers/dev/md.doctor.handlers.go index 195355e..a56298e 100644 --- a/handlers/dev/md.doctor.handlers.go +++ b/handlers/dev/md.doctor.handlers.go @@ -11,6 +11,8 @@ import ( "cpone/services" "cpone/utils" "fmt" + "path/filepath" + "runtime" "strconv" "strings" @@ -48,6 +50,21 @@ type MdDoctorHandler struct { MdDoctorServices MdDoctorServices } +// GET FOTO PROFILE DOCTOR +func (lh *MdDoctorHandler) GetFotoProfile(c echo.Context) error { + // Mengambil nama file dari parameter URL + filename := c.Param("filename") + _, b, _, _ := runtime.Caller(0) + basepath := filepath.Dir(b) + println("Basepath") + println(basepath) + // Menentukan path file (relative to the dev/services folder) + filePath := filepath.Join(basepath, "..", "..", "uploads", "doctor", filename) + + // Mengembalikan file sebagai respon + return c.File(filePath) +} + // INITIAL func (lh *MdDoctorHandler) HandleShowMdDoctorScreen(c echo.Context) error { logger, _ := zap.NewProduction() @@ -661,6 +678,13 @@ func (lh *MdDoctorHandler) HandleShowMdDoctorScreen(c echo.Context) error { ID: "doctoragama", }, listItemResultAgamaComponent, + models.CustomUploadFotoPrmV0{ + ID: "doctorfoto", + Name: "doctorfoto", + Accept: ".png, .jpg, .jpeg", + Label: "Update Foto", + LinkFoto: "", + }, dialogAddBodyID, dev_mddoctorview.JsHideModalDoctor("")) modalActioAddCmp := dev_mddoctorview.ActionFormDoctor( @@ -1446,6 +1470,13 @@ func (lh *MdDoctorHandler) HandleCloseFormAdd(c echo.Context) error { ID: "doctoragama", }, listItemResultAgamaComponent, + models.CustomUploadFotoPrmV0{ + ID: "doctorfoto", + Name: "doctorfoto", + Accept: ".png, .jpg, .jpeg", + Label: "Update Foto", + LinkFoto: "", + }, dialogAddBodyID, dev_mddoctorview.JsHideModalDoctor("")) return utils.View(c, newForm) } @@ -1483,6 +1514,12 @@ func (lh *MdDoctorHandler) HandleAddMdDoctor(c echo.Context) error { doctorGolonganEtnis := c.FormValue("doctorgolonganetnis") doctorImbuhanNoHP := c.FormValue("doctorimbuhannohp") doctorAgama := c.FormValue("doctoragama") + // doctorFoto, err := c.FormFile("doctorfoto") + // if err != nil { + // return err + // } + + doctorfotobase64string := c.FormValue("doctorfotobase64string") separator := "$$" @@ -1526,6 +1563,8 @@ func (lh *MdDoctorHandler) HandleAddMdDoctor(c echo.Context) error { zap.String("doctorGolonganEtnis", doctorGolonganEtnis), zap.String("doctorImbuhanNoHP", doctorImbuhanNoHP), zap.String("doctorAgama", doctorAgama), + zap.String("doctorfotobase64string", doctorfotobase64string), + // zap.Any("doctorFoto", doctorFoto), zap.Any("tableid", tableID), zap.Any("search", search), zap.Any("currpage", currPage), @@ -2187,6 +2226,15 @@ func (lh *MdDoctorHandler) HandleAddMdDoctor(c echo.Context) error { ID: "doctoragama", }, listItemResultAgamaComponent, + models.CustomUploadFotoPrmV0{ + ID: "doctorfoto", + Name: "doctorfoto", + Accept: ".png, .jpg, .jpeg", + Label: "Update Foto", + // LinkFoto: "", + LinkFoto: doctorfotobase64string, + Value: doctorfotobase64string, + }, dialogAddBodyID, dev_mddoctorview.JsHideModalDoctor("")) return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm}) } @@ -2457,6 +2505,14 @@ func (lh *MdDoctorHandler) HandleAddMdDoctor(c echo.Context) error { ID: "doctoragama", }, listItemResultAgamaComponent, + models.CustomUploadFotoPrmV0{ + ID: "doctorfoto", + Name: "doctorfoto", + Accept: ".png, .jpg, .jpeg", + Label: "Update Foto", + LinkFoto: doctorfotobase64string, + Value: doctorfotobase64string, + }, dialogAddBodyID, dev_mddoctorview.JsHideModalDoctor("")) return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", "Error Get Doctor Code", "danger"), newForm}) @@ -2492,12 +2548,16 @@ func (lh *MdDoctorHandler) HandleAddMdDoctor(c echo.Context) error { M_DoctorM_SpecialistID: idSpesialisAdd, M_DoctorAddress: "", M_DoctorAddressRegionalCd: 0, + M_DoctorAddressRT: "", + M_DoctorAddressRW: "", + M_DoctorAddressVillage: "", M_DoctorAddressCity: "", M_DoctorAddressDistrict: "", M_DoctorAddressState: "", M_DoctorAddressCountry: "", M_DoctorIsActive: "Y", M_DoctorCreatedUserID: "1", + M_DoctorPhoto: doctorfotobase64string, } dataDoctorAdd, err := lh.MdDoctorServices.AddMdDoctor(doctor) @@ -2791,6 +2851,14 @@ func (lh *MdDoctorHandler) HandleAddMdDoctor(c echo.Context) error { ID: "doctoragama", }, listItemResultAgamaComponent, + models.CustomUploadFotoPrmV0{ + ID: "doctorfoto", + Name: "doctorfoto", + Accept: ".png, .jpg, .jpeg", + Label: "Update Foto", + LinkFoto: doctorfotobase64string, + Value: doctorfotobase64string, + }, dialogAddBodyID, dev_mddoctorview.JsHideModalDoctor("")) return utils.ViewMulti(c, []templ.Component{ customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), @@ -3040,6 +3108,14 @@ func (lh *MdDoctorHandler) HandleAddMdDoctor(c echo.Context) error { ID: "doctoragama", }, listItemResultAgamaComponent, + models.CustomUploadFotoPrmV0{ + ID: "doctorfoto", + Name: "doctorfoto", + Accept: ".png, .jpg, .jpeg", + Label: "Update Foto", + LinkFoto: "", + Value: "", + }, dialogAddBodyID, dev_mddoctorview.JsHideModalDoctor("#"+dialogAddID)) toastSuccess := customtoastv2.CustomToastV2Show("Success", "Success add master doctor "+doctorImbuhanNama, "success") diff --git a/models/customuploadfotov0.models.go b/models/customuploadfotov0.models.go new file mode 100644 index 0000000..e76e6a3 --- /dev/null +++ b/models/customuploadfotov0.models.go @@ -0,0 +1,10 @@ +package models + +type CustomUploadFotoPrmV0 struct { + ID string `desc:"ID"` + Name string `desc:"name"` + Accept string `desc:"ekstension acc (.png, .jpg, .jpeg)"` + Label string `desc:"label title"` + LinkFoto string + Value string `desc:""` +} diff --git a/models/doctor.models.go b/models/doctor.models.go index f1ce7a3..4df637b 100644 --- a/models/doctor.models.go +++ b/models/doctor.models.go @@ -7,96 +7,106 @@ import ( ) type DoctorV1 struct { - Nomor string `db:"nomor"` - M_DoctorID int `db:"M_DoctorID"` - M_DoctorM_TitleID int `db:"M_DoctorM_TitleID"` - M_DoctorCode string `db:"M_DoctorCode"` - M_DoctorPrefix string `db:"M_DoctorPrefix"` - M_DoctorPrefix2 string `db:"M_DoctorPrefix2"` - M_DoctorName string `db:"M_DoctorName"` - M_DoctorSuffix string `db:"M_DoctorSuffix"` - M_DoctorSuffix2 string `db:"M_DoctorSuffix2"` - M_DoctorGender string `db:"M_DoctorGender"` - M_DoctorDOB string `db:"M_DoctorDOB"` - M_DoctorReligionCode string `db:"M_DoctorReligionCode"` - M_DoctorReligionSystem string `db:"M_DoctorReligionSystem"` - M_DoctorBloodTypeCode string `db:"M_DoctorBloodTypeCode"` - M_DoctorBloodTypeSystem string `db:"M_DoctorBloodTypeSystem"` - M_DoctorBloodRhCode string `db:"M_DoctorBloodRhCode"` - M_DoctorBloodRhSystem string `db:"M_DoctorBloodRhSystem"` - M_DoctorEducationCode string `db:"M_DoctorEducationCode"` - M_DoctorEducationSystem string `db:"M_DoctorEducationSystem"` - M_DoctorCitizenship string `db:"M_DoctorCitizenship"` - M_DoctorEtnicCode string `db:"M_DoctorEtnicCode"` - M_DoctorEtnicSystem string `db:"M_DoctorEtnicSystem"` - M_DoctorIdentifierCode string `db:"M_DoctorIdentifierCode"` - M_DoctorIdentifierSystem string `db:"M_DoctorIdentifierSystem"` - M_DoctorIdentifierValue string `db:"M_DoctorIdentifierValue"` - M_DoctorHp string `db:"M_DoctorHp"` - M_DoctorEmail string `db:"M_DoctorEmail"` - M_DoctorM_SpecialistID string `db:"M_DoctorM_SpecialistID"` - M_SpecialistID string `db:"M_SpecialistID"` - M_SpecialistName string `db:"M_SpecialistName"` - M_TitleName string `db:"M_TitleName"` - M_DoctorAddress string `db:"M_DoctorAddress"` - M_DoctorAddressRegionalCd int `db:"M_DoctorAddressRegionalCd"` - M_DoctorAddressCity string `db:"M_DoctorAddressCity"` - M_DoctorAddressDistrict string `db:"M_DoctorAddressDistrict"` - M_DoctorAddressState string `db:"M_DoctorAddressState"` - M_DoctorAddressCountry string `db:"M_DoctorAddressCountry"` - M_DoctorCreated string `db:"M_DoctorCreated"` - M_DoctorCreatedUserID string `db:"M_DoctorCreatedUserID"` - M_DoctorLastUpdated string `db:"M_DoctorLastUpdated"` - M_DoctorLastUpdatedUserID string `db:"M_DoctorLastUpdatedUserID"` - M_DoctorDeletedUserID string `db:"M_DoctorDeletedUserID"` - M_DoctorDeleted string `db:"M_DoctorDeleted"` - M_DoctorIsActive string `db:"M_DoctorIsActive"` + Nomor string `db:"nomor"` + M_DoctorID int `db:"M_DoctorID"` + M_DoctorM_TitleID int `db:"M_DoctorM_TitleID"` + M_DoctorCode string `db:"M_DoctorCode"` + M_DoctorPrefix string `db:"M_DoctorPrefix"` + M_DoctorPrefix2 string `db:"M_DoctorPrefix2"` + M_DoctorName string `db:"M_DoctorName"` + M_DoctorSuffix string `db:"M_DoctorSuffix"` + M_DoctorSuffix2 string `db:"M_DoctorSuffix2"` + M_DoctorGender string `db:"M_DoctorGender"` + M_DoctorDOB string `db:"M_DoctorDOB"` + M_DoctorReligionCode string `db:"M_DoctorReligionCode"` + M_DoctorReligionSystem string `db:"M_DoctorReligionSystem"` + M_DoctorBloodTypeCode string `db:"M_DoctorBloodTypeCode"` + M_DoctorBloodTypeSystem string `db:"M_DoctorBloodTypeSystem"` + M_DoctorBloodRhCode string `db:"M_DoctorBloodRhCode"` + M_DoctorBloodRhSystem string `db:"M_DoctorBloodRhSystem"` + M_DoctorEducationCode string `db:"M_DoctorEducationCode"` + M_DoctorEducationSystem string `db:"M_DoctorEducationSystem"` + M_DoctorCitizenship string `db:"M_DoctorCitizenship"` + M_DoctorEtnicCode string `db:"M_DoctorEtnicCode"` + M_DoctorEtnicSystem string `db:"M_DoctorEtnicSystem"` + M_DoctorIdentifierCode string `db:"M_DoctorIdentifierCode"` + M_DoctorIdentifierSystem string `db:"M_DoctorIdentifierSystem"` + M_DoctorIdentifierValue string `db:"M_DoctorIdentifierValue"` + M_DoctorHp string `db:"M_DoctorHp"` + M_DoctorEmail string `db:"M_DoctorEmail"` + M_DoctorM_SpecialistID string `db:"M_DoctorM_SpecialistID"` + M_DoctorPhoto string `db:"M_DoctorPhoto"` + M_DoctorPhotoLastUpdated string `db:"M_DoctorPhotoLastUpdated"` + M_DoctorPhotoLastUpdatedUserID string `db:"M_DoctorPhotoLastUpdatedUserID"` + M_SpecialistID string `db:"M_SpecialistID"` + M_SpecialistName string `db:"M_SpecialistName"` + M_TitleName string `db:"M_TitleName"` + M_DoctorAddress string `db:"M_DoctorAddress"` + M_DoctorAddressRegionalCd int `db:"M_DoctorAddressRegionalCd"` + M_DoctorAddressRT string `db:"M_DoctorAddressRT"` + M_DoctorAddressRW string `db:"M_DoctorAddressRW"` + M_DoctorAddressCity string `db:"M_DoctorAddressCity"` + M_DoctorAddressVillage string `db:"M_DoctorAddressVillage"` + M_DoctorAddressDistrict string `db:"M_DoctorAddressDistrict"` + M_DoctorAddressState string `db:"M_DoctorAddressState"` + M_DoctorAddressCountry string `db:"M_DoctorAddressCountry"` + M_DoctorCreated string `db:"M_DoctorCreated"` + M_DoctorCreatedUserID string `db:"M_DoctorCreatedUserID"` + M_DoctorLastUpdated string `db:"M_DoctorLastUpdated"` + M_DoctorLastUpdatedUserID string `db:"M_DoctorLastUpdatedUserID"` + M_DoctorDeletedUserID string `db:"M_DoctorDeletedUserID"` + M_DoctorDeleted string `db:"M_DoctorDeleted"` + M_DoctorIsActive string `db:"M_DoctorIsActive"` } // doctor json type DoctorJSONv1 struct { - M_DoctorID int `db:"M_DoctorID"` - M_DoctorM_TitleID int `db:"M_DoctorM_TitleID"` - M_DoctorCode string `db:"M_DoctorCode"` - M_DoctorPrefix string `db:"M_DoctorPrefix"` - M_DoctorPrefix2 string `db:"M_DoctorPrefix2"` - M_DoctorName string `db:"M_DoctorName"` - M_DoctorSuffix string `db:"M_DoctorSuffix"` - M_DoctorSuffix2 string `db:"M_DoctorSuffix2"` - M_DoctorGender string `db:"M_DoctorGender"` - M_DoctorDOB string `db:"M_DoctorDOB"` - M_DoctorReligionCode string `db:"M_DoctorReligionCode"` - M_DoctorReligionSystem string `db:"M_DoctorReligionSystem"` - M_DoctorBloodTypeCode string `db:"M_DoctorBloodTypeCode"` - M_DoctorBloodTypeSystem string `db:"M_DoctorBloodTypeSystem"` - M_DoctorBloodRhCode string `db:"M_DoctorBloodRhCode"` - M_DoctorBloodRhSystem string `db:"M_DoctorBloodRhSystem"` - M_DoctorEducationCode string `db:"M_DoctorEducationCode"` - M_DoctorEducationSystem string `db:"M_DoctorEducationSystem"` - M_DoctorCitizenship string `db:"M_DoctorCitizenship"` - M_DoctorEtnicCode string `db:"M_DoctorEtnicCode"` - M_DoctorEtnicSystem string `db:"M_DoctorEtnicSystem"` - M_DoctorIdentifierCode string `db:"M_DoctorIdentifierCode"` - M_DoctorIdentifierSystem string `db:"M_DoctorIdentifierSystem"` - M_DoctorIdentifierValue string `db:"M_DoctorIdentifierValue"` - M_DoctorHp string `db:"M_DoctorHp"` - M_DoctorEmail string `db:"M_DoctorEmail"` - M_DoctorM_SpecialistID int `db:"M_DoctorM_SpecialistID"` - M_DoctorAddress string `db:"M_DoctorAddress"` - M_DoctorAddressRegionalCd string `db:"M_DoctorAddressRegionalCd"` - M_DoctorAddressRT string `db:"M_DoctorAddressRT"` - M_DoctorAddressRW string `db:"M_DoctorAddressRW"` - M_DoctorAddressCity string `db:"M_DoctorAddressCity"` - M_DoctorAddressDistrict string `db:"M_DoctorAddressDistrict"` - M_DoctorAddressState string `db:"M_DoctorAddressState"` - M_DoctorAddressCountry string `db:"M_DoctorAddressCountry"` - M_DoctorIsActive string `db:"M_DoctorIsActive"` - M_DoctorCreated string `db:"M_DoctorCreated"` - M_DoctorCreatedUserID int `db:"M_DoctorCreatedUserID"` - M_DoctorLastUpdated string `db:"M_DoctorLastUpdated"` - M_DoctorLastUpdatedUserID int `db:"M_DoctorLastUpdatedUserID"` - M_DoctorDeletedUserID int `db:"M_DoctorDeletedUserID"` - M_DoctorDeleted string `db:"M_DoctorDeleted"` + M_DoctorID int `db:"M_DoctorID"` + M_DoctorM_TitleID int `db:"M_DoctorM_TitleID"` + M_DoctorCode string `db:"M_DoctorCode"` + M_DoctorPrefix string `db:"M_DoctorPrefix"` + M_DoctorPrefix2 string `db:"M_DoctorPrefix2"` + M_DoctorName string `db:"M_DoctorName"` + M_DoctorSuffix string `db:"M_DoctorSuffix"` + M_DoctorSuffix2 string `db:"M_DoctorSuffix2"` + M_DoctorGender string `db:"M_DoctorGender"` + M_DoctorDOB string `db:"M_DoctorDOB"` + M_DoctorReligionCode string `db:"M_DoctorReligionCode"` + M_DoctorReligionSystem string `db:"M_DoctorReligionSystem"` + M_DoctorBloodTypeCode string `db:"M_DoctorBloodTypeCode"` + M_DoctorBloodTypeSystem string `db:"M_DoctorBloodTypeSystem"` + M_DoctorBloodRhCode string `db:"M_DoctorBloodRhCode"` + M_DoctorBloodRhSystem string `db:"M_DoctorBloodRhSystem"` + M_DoctorEducationCode string `db:"M_DoctorEducationCode"` + M_DoctorEducationSystem string `db:"M_DoctorEducationSystem"` + M_DoctorCitizenship string `db:"M_DoctorCitizenship"` + M_DoctorEtnicCode string `db:"M_DoctorEtnicCode"` + M_DoctorEtnicSystem string `db:"M_DoctorEtnicSystem"` + M_DoctorIdentifierCode string `db:"M_DoctorIdentifierCode"` + M_DoctorIdentifierSystem string `db:"M_DoctorIdentifierSystem"` + M_DoctorIdentifierValue string `db:"M_DoctorIdentifierValue"` + M_DoctorHp string `db:"M_DoctorHp"` + M_DoctorEmail string `db:"M_DoctorEmail"` + M_DoctorM_SpecialistID int `db:"M_DoctorM_SpecialistID"` + M_DoctorPhoto string `db:"M_DoctorPhoto"` + M_DoctorPhotoLastUpdated string `db:"M_DoctorPhotoLastUpdated"` + M_DoctorPhotoLastUpdatedUserID string `db:"M_DoctorPhotoLastUpdatedUserID"` + M_DoctorAddress string `db:"M_DoctorAddress"` + M_DoctorAddressRegionalCd string `db:"M_DoctorAddressRegionalCd"` + M_DoctorAddressRT string `db:"M_DoctorAddressRT"` + M_DoctorAddressRW string `db:"M_DoctorAddressRW"` + M_DoctorAddressCity string `db:"M_DoctorAddressCity"` + M_DoctorAddressVillage string `db:"M_DoctorAddressVillage"` + M_DoctorAddressDistrict string `db:"M_DoctorAddressDistrict"` + M_DoctorAddressState string `db:"M_DoctorAddressState"` + M_DoctorAddressCountry string `db:"M_DoctorAddressCountry"` + M_DoctorIsActive string `db:"M_DoctorIsActive"` + M_DoctorCreated string `db:"M_DoctorCreated"` + M_DoctorCreatedUserID int `db:"M_DoctorCreatedUserID"` + M_DoctorLastUpdated string `db:"M_DoctorLastUpdated"` + M_DoctorLastUpdatedUserID int `db:"M_DoctorLastUpdatedUserID"` + M_DoctorDeletedUserID int `db:"M_DoctorDeletedUserID"` + M_DoctorDeleted string `db:"M_DoctorDeleted"` } // title diff --git a/services/dev/md.doctor.services.go b/services/dev/md.doctor.services.go index f34b270..16fb900 100644 --- a/services/dev/md.doctor.services.go +++ b/services/dev/md.doctor.services.go @@ -4,11 +4,17 @@ import ( "cpone/db" "cpone/models" dbx "cpone/package/database" + "cpone/utils" + "encoding/base64" "encoding/json" "fmt" "math" + "os" + "path/filepath" + "runtime" "strconv" "strings" + "time" "go.uber.org/zap" ) @@ -851,7 +857,7 @@ func (su *ServicesMdDoctor) GetMdDoctorCode(tipe string) (string, error) { defer logger.Sync() query := ` - select fn_numbering(?) as doctorCode + select fn_numbering_cpone(?) as doctorCode ` logger.Info("QUERY DOCTOR CODE", @@ -1012,6 +1018,12 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e M_DoctorAddressDistrict := "" M_DoctorAddressState := "" M_DoctorAddressCountry := "" + M_DoctorAddressVillage := "" + M_DoctorAddressRT := "" + M_DoctorAddressRW := "" + M_DoctorPhoto := "" + M_DoctorPhotoLastUpdated := "0000-00-00 00:00:00" + M_DoctorPhotoLastUpdatedUserID := 0 // VARIABLE END // CHECK PARAMS @@ -1099,6 +1111,93 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e M_DoctorAddressDistrict = inp.M_DoctorAddressDistrict M_DoctorAddressState = inp.M_DoctorAddressState M_DoctorAddressCountry = inp.M_DoctorAddressCountry + M_DoctorAddressVillage = inp.M_DoctorAddressVillage + } + + if inp.M_DoctorAddressRT != "" { + M_DoctorAddressRT = inp.M_DoctorAddressRT + } + + if inp.M_DoctorAddressRW != "" { + M_DoctorAddressRW = inp.M_DoctorAddressRW + } + + // foto + // inp.M_DoctorPhoto sudah dalam bentuk base64string + if inp.M_DoctorPhoto != "" { + var ext string + M_DoctorPhotoBase64 := inp.M_DoctorPhoto + fileName := M_DoctorCode + time.Now().String() + + // Remove base64 prefix if present + // if strings.HasPrefix(M_DoctorPhotoBase64, "data:image/") { + // M_DoctorPhotoBase64 = M_DoctorPhotoBase64[strings.IndexByte(M_DoctorPhotoBase64, ',')+1:] + // } + + // Check if the base64 string has a valid prefix + if strings.HasPrefix(M_DoctorPhotoBase64, "data:image/") { + // Extract the file type from the prefix + fileType := strings.Split(M_DoctorPhotoBase64[11:], ";")[0] + switch fileType { + case "png": + ext = ".png" + case "jpeg": + ext = ".jpeg" + case "jpg": + ext = ".jpg" + // case "gif": + // ext = ".gif" + default: + return data, fmt.Errorf("unsupported file type") + } + // Remove the prefix from the base64 string + M_DoctorPhotoBase64 = M_DoctorPhotoBase64[strings.IndexByte(M_DoctorPhotoBase64, ',')+1:] + } else { + return data, fmt.Errorf("invalid base64 string") + } + + // Decode base64 string to byte array + decodedBytes, err := base64.StdEncoding.DecodeString(M_DoctorPhotoBase64) + if err != nil { + // return data, fmt.Errorf("error decoding base64 string: %v", err) + defer logger.Sync() + logger.Error("Error Decoding Base64 String", + zap.Any("error decoding base64 string : %v", err), + ) + return data, fmt.Errorf("error decoding base64 string: %v", err) + } + + _, b, _, _ := runtime.Caller(0) + basepath := filepath.Dir(b) + println("Basepath") + println(basepath) + + // ext := filepath.Ext(fileName) + newFileName := utils.GenerateRandomID(fileName) + ext + uploadDir := filepath.Join(basepath, "..", "..", "uploads", "doctor") + println(uploadDir) + + // Menentukan path file tujuan + dstPath := filepath.Join(uploadDir, newFileName) + // Membuat direktori jika belum ada + if err := os.MkdirAll(uploadDir, os.ModePerm); err != nil { + defer logger.Sync() + logger.Error("Error Mkdir", + zap.Any("error mdir : %v", err), + ) + return data, fmt.Errorf("error mkdir: %v", err) + } + + // Menulis konten decoded base64 ke file tujuan + if err := os.WriteFile(dstPath, decodedBytes, 0644); err != nil { + defer logger.Sync() + logger.Error("Error Writing File", + zap.Any("error writing file : %v", err), + ) + return data, fmt.Errorf("error writing file: %v", err) + } + + M_DoctorPhoto = newFileName } // CHECK PARAMS @@ -1142,7 +1241,13 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e M_DoctorAddressCountry, M_DoctorIsActive, M_DoctorCreatedUserID, - M_DoctorCreated + M_DoctorCreated, + M_DoctorPhoto, + M_DoctorPhotoLastUpdated, + M_DoctorPhotoLastUpdatedUserID, + M_DoctorAddressVillage, + M_DoctorAddressRT, + M_DoctorAddressRW ) VALUES ( @@ -1180,7 +1285,13 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e ?, ?, ?, - NOW() + NOW(), + ?, + ?, + ?, + ?, + ?, + ? )` rst := tx.MustExec(query, @@ -1218,6 +1329,12 @@ func (su *ServicesMdDoctor) AddMdDoctor(inp models.DoctorV1) (models.DoctorV1, e M_DoctorAddressCountry, "Y", "1", + M_DoctorPhoto, + M_DoctorPhotoLastUpdated, + M_DoctorPhotoLastUpdatedUserID, + M_DoctorAddressVillage, + M_DoctorAddressRT, + M_DoctorAddressRW, ) insertedID, err := rst.LastInsertId() if err != nil { diff --git a/uploads/doctor/sas02daefc0d842c82ff4ed284f103919da.jpeg b/uploads/doctor/sas02daefc0d842c82ff4ed284f103919da.jpeg new file mode 100644 index 0000000..26dd145 Binary files /dev/null and b/uploads/doctor/sas02daefc0d842c82ff4ed284f103919da.jpeg differ diff --git a/uploads/doctor/sas23a552cabaf06d58032c5a15bf1a5de5.443990901 b/uploads/doctor/sas23a552cabaf06d58032c5a15bf1a5de5.443990901 new file mode 100644 index 0000000..f2d2f59 Binary files /dev/null and b/uploads/doctor/sas23a552cabaf06d58032c5a15bf1a5de5.443990901 differ diff --git a/uploads/doctor/sas31ef4383458421aff961372622e4093f.png b/uploads/doctor/sas31ef4383458421aff961372622e4093f.png new file mode 100644 index 0000000..d9e4cc2 Binary files /dev/null and b/uploads/doctor/sas31ef4383458421aff961372622e4093f.png differ diff --git a/uploads/doctor/sas8d5150bae06cbb1a487b581064ad934b.png b/uploads/doctor/sas8d5150bae06cbb1a487b581064ad934b.png new file mode 100644 index 0000000..5dae677 Binary files /dev/null and b/uploads/doctor/sas8d5150bae06cbb1a487b581064ad934b.png differ diff --git a/uploads/doctor/sasb35bcee2cfbeea6dd6f7a27385fd23b8.319687001 b/uploads/doctor/sasb35bcee2cfbeea6dd6f7a27385fd23b8.319687001 new file mode 100644 index 0000000..f2d2f59 Binary files /dev/null and b/uploads/doctor/sasb35bcee2cfbeea6dd6f7a27385fd23b8.319687001 differ diff --git a/uploads/doctor/sasf67a56f1704c6984680bb13709c306be.554148301 b/uploads/doctor/sasf67a56f1704c6984680bb13709c306be.554148301 new file mode 100644 index 0000000..f2d2f59 Binary files /dev/null and b/uploads/doctor/sasf67a56f1704c6984680bb13709c306be.554148301 differ diff --git a/uploads/doctor/sassas8e03923013e308f7524a9162ba8e9bb2.jpeg b/uploads/doctor/sassas8e03923013e308f7524a9162ba8e9bb2.jpeg new file mode 100644 index 0000000..26dd145 Binary files /dev/null and b/uploads/doctor/sassas8e03923013e308f7524a9162ba8e9bb2.jpeg differ diff --git a/uploads/doctor/sassasb46ef8073e21082f41271eb9a414938b.png b/uploads/doctor/sassasb46ef8073e21082f41271eb9a414938b.png new file mode 100644 index 0000000..f2d2f59 Binary files /dev/null and b/uploads/doctor/sassasb46ef8073e21082f41271eb9a414938b.png differ diff --git a/views/dev/mddoctor/mddoctorformmodal.templ b/views/dev/mddoctor/mddoctorformmodal.templ index 91be2b4..59f068a 100644 --- a/views/dev/mddoctor/mddoctorformmodal.templ +++ b/views/dev/mddoctor/mddoctorformmodal.templ @@ -5,10 +5,12 @@ import "cpone/component/modal" import "cpone/component/customtextfield" import "cpone/component/customdropdown" import "cpone/component/customradiobutton" +import "cpone/component/customuploadfotodokterv0" templ DoctorForm(data models.DoctorFormComponent) {
-
-
- -
-
-
-
- -
-
+ @customuploadfotodokterv0.CustomUploadFotoWithPreviewDokterV0(inputUploadFoto) + //
+ //
+ // + //
+ //
+ //
+ //
+ // + //
+ //
@customtextfield.CustomTextFieldv2( inputId) diff --git a/views/dev/mddoctor/mddoctorformmodal_templ.go b/views/dev/mddoctor/mddoctorformmodal_templ.go index 88bb397..802b934 100644 --- a/views/dev/mddoctor/mddoctorformmodal_templ.go +++ b/views/dev/mddoctor/mddoctorformmodal_templ.go @@ -15,6 +15,7 @@ import "cpone/component/modal" import "cpone/component/customtextfield" import "cpone/component/customdropdown" import "cpone/component/customradiobutton" +import "cpone/component/customuploadfotodokterv0" func DoctorForm(data models.DoctorFormComponent) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { @@ -37,14 +38,14 @@ func DoctorForm(data models.DoctorFormComponent) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customuploadfotodokterv0.CustomUploadFotoWithPreviewDokterV0(inputUploadFoto).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -570,7 +580,7 @@ func ActionFormDoctor(LinkClose string, targetClose string, hxSwapClose string, var templ_7745c5c3_Var14 string templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(LinkClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 434, Col: 22} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 438, Col: 22} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) if templ_7745c5c3_Err != nil { @@ -583,7 +593,7 @@ func ActionFormDoctor(LinkClose string, targetClose string, hxSwapClose string, var templ_7745c5c3_Var15 string templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(targetClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 435, Col: 26} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 439, Col: 26} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) if templ_7745c5c3_Err != nil { @@ -596,7 +606,7 @@ func ActionFormDoctor(LinkClose string, targetClose string, hxSwapClose string, var templ_7745c5c3_Var16 string templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(hxSwapClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 436, Col: 24} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 440, Col: 24} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) if templ_7745c5c3_Err != nil { @@ -637,7 +647,7 @@ func BtnCloseFormDoctor(LinkClose string, targetClose string, hxSwapClose string var templ_7745c5c3_Var18 string templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(LinkClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 457, Col: 21} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 461, Col: 21} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18)) if templ_7745c5c3_Err != nil { @@ -650,7 +660,7 @@ func BtnCloseFormDoctor(LinkClose string, targetClose string, hxSwapClose string var templ_7745c5c3_Var19 string templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(targetClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 458, Col: 25} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 462, Col: 25} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) if templ_7745c5c3_Err != nil { @@ -663,7 +673,7 @@ func BtnCloseFormDoctor(LinkClose string, targetClose string, hxSwapClose string var templ_7745c5c3_Var20 string templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(hxSwapClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 459, Col: 23} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 463, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20)) if templ_7745c5c3_Err != nil { @@ -718,7 +728,7 @@ func DeleteConfirmationBodyDoctor(inputId models.CustomTextFieldv2Prm, var templ_7745c5c3_Var23 string templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(componentID) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 476, Col: 22} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 480, Col: 22} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) if templ_7745c5c3_Err != nil { @@ -740,7 +750,7 @@ func DeleteConfirmationBodyDoctor(inputId models.CustomTextFieldv2Prm, var templ_7745c5c3_Var25 string templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(message) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 477, Col: 14} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 481, Col: 14} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) if templ_7745c5c3_Err != nil { @@ -758,7 +768,7 @@ func DeleteConfirmationBodyDoctor(inputId models.CustomTextFieldv2Prm, var templ_7745c5c3_Var26 string templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(v) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 482, Col: 68} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 486, Col: 68} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) if templ_7745c5c3_Err != nil { @@ -781,7 +791,7 @@ func DeleteConfirmationBodyDoctor(inputId models.CustomTextFieldv2Prm, var templ_7745c5c3_Var27 string templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(v) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 488, Col: 10} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 492, Col: 10} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) if templ_7745c5c3_Err != nil { @@ -848,7 +858,7 @@ func ActionFormDoctorDelete(LinkClose string, targetClose string, hxSwapClose st var templ_7745c5c3_Var30 string templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(LinkClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 502, Col: 22} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 506, Col: 22} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30)) if templ_7745c5c3_Err != nil { @@ -861,7 +871,7 @@ func ActionFormDoctorDelete(LinkClose string, targetClose string, hxSwapClose st var templ_7745c5c3_Var31 string templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(targetClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 503, Col: 26} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 507, Col: 26} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31)) if templ_7745c5c3_Err != nil { @@ -874,7 +884,7 @@ func ActionFormDoctorDelete(LinkClose string, targetClose string, hxSwapClose st var templ_7745c5c3_Var32 string templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(hxSwapClose) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 504, Col: 24} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mddoctor\mddoctorformmodal.templ`, Line: 508, Col: 24} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) if templ_7745c5c3_Err != nil {