198 lines
5.6 KiB
Go
198 lines
5.6 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// Peserta BPJS Models with Enhanced Validation
|
|
// Generated at: 2025-08-24 20:09:32
|
|
// Category: antrol
|
|
|
|
// Base request/response structures
|
|
type BaseRequest struct {
|
|
RequestID string `json:"request_id,omitempty"`
|
|
Timestamp time.Time `json:"timestamp,omitempty"`
|
|
}
|
|
|
|
type BaseResponse struct {
|
|
Status string `json:"status"`
|
|
Message string `json:"message"`
|
|
Data interface{} `json:"data,omitempty"`
|
|
Error *ErrorResponse `json:"error,omitempty"`
|
|
Metadata *ResponseMetadata `json:"metadata,omitempty"`
|
|
}
|
|
|
|
type ErrorResponse struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
Details string `json:"details,omitempty"`
|
|
}
|
|
|
|
type ResponseMetadata struct {
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Version string `json:"version"`
|
|
RequestID string `json:"request_id,omitempty"`
|
|
}
|
|
|
|
// Peserta Response Structure
|
|
type PesertaResponse struct {
|
|
BaseResponse
|
|
}
|
|
|
|
// BPJS Raw Response Structure
|
|
type BpjsRawResponse struct {
|
|
MetaData struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
} `json:"metaData"`
|
|
Response interface{} `json:"response"`
|
|
}
|
|
|
|
// Peserta POST Request Structure with Enhanced Validation
|
|
type PesertaPostRequest struct {
|
|
BaseRequest
|
|
TPeserta PesertaPost `json:"t_sep" binding:"required" validate:"required"`
|
|
}
|
|
|
|
type PesertaPost struct {
|
|
// Core BPJS fields - customize based on your specific requirements
|
|
NoKartu string `json:"noKartu" binding:"required" validate:"required,min=13,max=13"`
|
|
TglLayanan string `json:"tglLayanan" binding:"required" validate:"required"`
|
|
JnsPelayanan string `json:"jnsPelayanan" binding:"required" validate:"required,oneof=1 2"`
|
|
PpkPelayanan string `json:"ppkPelayanan" binding:"required" validate:"required"`
|
|
Catatan string `json:"catatan" validate:"omitempty,max=200"`
|
|
User string `json:"user" binding:"required" validate:"required"`
|
|
}
|
|
|
|
// Validate validates the PesertaPostRequest
|
|
func (r *PesertaPostRequest) Validate() error {
|
|
if r.TPeserta.NoKartu == "" {
|
|
return fmt.Errorf("nomor kartu tidak boleh kosong")
|
|
}
|
|
|
|
if len(r.TPeserta.NoKartu) != 13 {
|
|
return fmt.Errorf("nomor kartu harus 13 digit")
|
|
}
|
|
|
|
if _, err := time.Parse("2006-01-02", r.TPeserta.TglLayanan); err != nil {
|
|
return fmt.Errorf("format tanggal layanan tidak valid, gunakan yyyy-MM-dd")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ToJSON converts struct to JSON string
|
|
func (r *PesertaPostRequest) ToJSON() (string, error) {
|
|
data, err := json.Marshal(r)
|
|
return string(data), err
|
|
}
|
|
|
|
// Peserta PUT Request Structure with Enhanced Validation
|
|
type PesertaPutRequest struct {
|
|
BaseRequest
|
|
TPeserta PesertaPut `json:"t_sep" binding:"required" validate:"required"`
|
|
}
|
|
|
|
type PesertaPut struct {
|
|
ID string `json:"id" binding:"required" validate:"required"`
|
|
NoKartu string `json:"noKartu" validate:"omitempty,min=13,max=13"`
|
|
TglLayanan string `json:"tglLayanan" validate:"omitempty"`
|
|
JnsPelayanan string `json:"jnsPelayanan" validate:"omitempty,oneof=1 2"`
|
|
PpkPelayanan string `json:"ppkPelayanan" validate:"omitempty"`
|
|
Catatan string `json:"catatan" validate:"omitempty,max=200"`
|
|
User string `json:"user" binding:"required" validate:"required"`
|
|
}
|
|
|
|
// Validate validates the PesertaPutRequest
|
|
func (r *PesertaPutRequest) Validate() error {
|
|
if r.TPeserta.ID == "" {
|
|
return fmt.Errorf("ID tidak boleh kosong")
|
|
}
|
|
|
|
if r.TPeserta.NoKartu != "" && len(r.TPeserta.NoKartu) != 13 {
|
|
return fmt.Errorf("nomor kartu harus 13 digit")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ToJSON converts struct to JSON string
|
|
func (r *PesertaPutRequest) ToJSON() (string, error) {
|
|
data, err := json.Marshal(r)
|
|
return string(data), err
|
|
}
|
|
|
|
// Peserta DELETE Request Structure with Enhanced Validation
|
|
type PesertaDeleteRequest struct {
|
|
BaseRequest
|
|
TPeserta PesertaDeleteData `json:"t_sep" binding:"required" validate:"required"`
|
|
}
|
|
|
|
type PesertaDeleteData struct {
|
|
ID string `json:"id" binding:"required" validate:"required"`
|
|
User string `json:"user" binding:"required" validate:"required"`
|
|
}
|
|
|
|
// Validate validates the PesertaDeleteRequest
|
|
func (r *PesertaDeleteRequest) Validate() error {
|
|
if r.TPeserta.ID == "" {
|
|
return fmt.Errorf("ID tidak boleh kosong")
|
|
}
|
|
|
|
if r.TPeserta.User == "" {
|
|
return fmt.Errorf("User tidak boleh kosong")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ToJSON converts struct to JSON string
|
|
func (r *PesertaDeleteRequest) ToJSON() (string, error) {
|
|
data, err := json.Marshal(r)
|
|
return string(data), err
|
|
}
|
|
|
|
// Common Helper Structures for BPJS
|
|
type Flag struct {
|
|
Flag string `json:"flag" binding:"required" validate:"required,oneof=0 1"`
|
|
}
|
|
|
|
type Poli struct {
|
|
Tujuan string `json:"tujuan" binding:"required" validate:"required"`
|
|
Eksekutif string `json:"eksekutif" binding:"required" validate:"required,oneof=0 1"`
|
|
}
|
|
|
|
type KlsRawat struct {
|
|
KlsRawatHak string `json:"klsRawatHak" binding:"required" validate:"required,oneof=1 2 3"`
|
|
KlsRawatNaik string `json:"klsRawatNaik" validate:"omitempty,oneof=1 2 3 4 5 6 7"`
|
|
Pembiayaan string `json:"pembiayaan" validate:"omitempty,oneof=1 2 3"`
|
|
PenanggungJawab string `json:"penanggungJawab" validate:"omitempty,max=100"`
|
|
}
|
|
|
|
// Validation helper functions
|
|
func IsValidStatus(status string) bool {
|
|
validStatuses := []string{"active", "inactive", "pending", "processed"}
|
|
for _, v := range validStatuses {
|
|
if v == status {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func IsValidJnsPelayanan(jns string) bool {
|
|
return jns == "1" || jns == "2" // 1: rawat jalan, 2: rawat inap
|
|
}
|
|
|
|
func IsValidKlsRawat(kls string) bool {
|
|
validKelas := []string{"1", "2", "3"}
|
|
for _, v := range validKelas {
|
|
if v == kls {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|