create antrian validation handling
This commit is contained in:
@@ -39,11 +39,11 @@ func (h AntrianOperasiHandler) CreateAntrianOperasi(c *gin.Context) {
|
||||
var req CreatePasienOperasiRequest
|
||||
// Binding format JSON
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
log.Printf("error bind json : %s", err)
|
||||
c.JSON(500, shared.BaseErrorResponse{
|
||||
Success: false,
|
||||
Code: 500,
|
||||
Message: "error bind json",
|
||||
Errors: shared.ValidationError(err),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ func (r antrianOperasiRepo) CreateAntrianOperasi(c *gin.Context, req CreatePasie
|
||||
// INSERT data_telepon_pasien_operasi
|
||||
var valuesInsertTelepon [][]interface{}
|
||||
|
||||
for _, telp := range *req.FormData.NoTelepon {
|
||||
for _, telp := range req.FormData.NoTelepon {
|
||||
idTelepon := uuid.New().String()
|
||||
itemValues := []interface{}{idTelepon, telp, idAntrian}
|
||||
valuesInsertTelepon = append(valuesInsertTelepon, itemValues)
|
||||
|
||||
@@ -5,31 +5,31 @@ import (
|
||||
)
|
||||
|
||||
type FormDataRequest struct {
|
||||
NoRekamMedis string `json:"noRekamMedis"`
|
||||
NoKtp *string `json:"noKtp"`
|
||||
NamaPasien *string `json:"namaPasien"`
|
||||
JenisKelamin *string `json:"jenisKelamin"`
|
||||
TglLahir *string `json:"tanggalLahir"`
|
||||
Umur *string `json:"umur"`
|
||||
Alamat *string `json:"alamat"`
|
||||
NoTelepon *[]string `json:"nomorTelepon"`
|
||||
NoRekamMedis string `json:"noRekamMedis"`
|
||||
NoKtp *string `json:"noKtp"`
|
||||
NamaPasien *string `json:"namaPasien"`
|
||||
JenisKelamin *string `json:"jenisKelamin"`
|
||||
TglLahir *string `json:"tanggalLahir"`
|
||||
Umur *string `json:"umur"`
|
||||
Alamat *string `json:"alamat"`
|
||||
NoTelepon []string `json:"nomorTelepon" binding:"required,min=1"`
|
||||
}
|
||||
|
||||
type DiagnosisItemRequest struct {
|
||||
KodeDiagnosa *string `json:"kodeDiagnosa"`
|
||||
Diagnosa *string `json:"diagnosa"`
|
||||
JenisDiagnosa *string `json:"jenisDiagnosa"`
|
||||
KodeDiagnosa string `json:"kodeDiagnosa" binding:"required"`
|
||||
Diagnosa string `json:"diagnosa" binding:"required"`
|
||||
JenisDiagnosa string `json:"jenisDiagnosa" binding:"required"`
|
||||
}
|
||||
|
||||
type TindakanItemRequest struct {
|
||||
KodeTindakan *string `json:"kodeTindakan"`
|
||||
Tindakan *string `json:"tindakan"`
|
||||
TindakanTambahan *string `json:"tindakanTambahan"`
|
||||
KodeTindakan *string `json:"kodeTindakan" binding:"required"`
|
||||
Tindakan *string `json:"tindakan" binding:"required"`
|
||||
TindakanTambahan *string `json:"tindakanTambahan" binding:"required"`
|
||||
}
|
||||
|
||||
type RencanaOperasiRequest struct {
|
||||
Spesialis int `json:"spesialis"`
|
||||
SubSpesialis int `json:"subSpesialis"`
|
||||
Spesialis int `json:"spesialis" binding:"required"`
|
||||
SubSpesialis int `json:"subSpesialis" binding:"required"`
|
||||
TanggalDaftar *time.Time `json:"tanggalDaftar"`
|
||||
KategoriOperasi int `json:"kategoriOperasi"`
|
||||
RencanaOperasi *string `json:"rencanaOperasi"`
|
||||
@@ -51,8 +51,8 @@ type StatusPasienRequest struct {
|
||||
|
||||
type CreatePasienOperasiRequest struct {
|
||||
FormData FormDataRequest `json:"formData"`
|
||||
DiagnosisItem []DiagnosisItemRequest `json:"diagnosisItems"`
|
||||
TindakanItems []TindakanItemRequest `json:"tindakanItems"`
|
||||
DiagnosisItem []DiagnosisItemRequest `json:"diagnosisItems" binding:"required,min=1,dive"`
|
||||
TindakanItems []TindakanItemRequest `json:"tindakanItems" binding:"required,min=1,dive"`
|
||||
RencanaOperasiData RencanaOperasiRequest `json:"rencanaOperasiData"`
|
||||
DokterPelaksanaItems []DokterPelaksanaItemRequest `json:"dokterPelaksanaItems"`
|
||||
StatusPasienData StatusPasienRequest `json:"statusPasienData"`
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
func ValidationError(err error) []string {
|
||||
var ve validator.ValidationErrors
|
||||
var result []string
|
||||
|
||||
if !errors.As(err, &ve) {
|
||||
return []string{
|
||||
err.Error(),
|
||||
}
|
||||
}
|
||||
|
||||
for _, fe := range ve {
|
||||
result = append(result, errorMessage(fe))
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func errorMessage(fe validator.FieldError) string {
|
||||
var errorInfo string
|
||||
|
||||
switch fe.Tag() {
|
||||
case "required":
|
||||
errorInfo = "tidak boleh kosong"
|
||||
case "min":
|
||||
errorInfo = "harus diisi minimal " + fe.Param()
|
||||
default:
|
||||
errorInfo = "tidak valid"
|
||||
}
|
||||
|
||||
return fe.Field() + " " + errorInfo
|
||||
}
|
||||
Reference in New Issue
Block a user