Patient
Some checks failed
Go-test / build (push) Has been cancelled

This commit is contained in:
2025-12-01 10:45:50 +07:00
parent 3a53de2ae1
commit f10689c606
6 changed files with 1130 additions and 7 deletions

View File

@@ -100,7 +100,7 @@ type ListkioskCreateRequest struct {
FKRefHealthcareTypeID int32 `json:"fk_ref_healthcare_type_id" validate:"min=1"`
FKRefServiceTypeID int32 `json:"fk_ref_service_type_id" validate:"min=1"`
FKSdLocationID string `json:"fk_sd_location_id"`
DsSdLocation string `json:"ds_sd_location" validate:"min=1,max=255"`
DsSdLocation string `json:"ds_sd_location"`
}
// Response struct untuk create
@@ -118,8 +118,8 @@ type ListkioskUpdateRequest struct {
Active bool `json:"active"`
FKRefHealthcareTypeID int32 `json:"fk_ref_healthcare_type_id" validate:"min=1"`
FKRefServiceTypeID int32 `json:"fk_ref_service_type_id" validate:"min=1"`
FKSdLocationID string `json:"fk_sd_location_id" validate:"min=1"`
DsSdLocation string `json:"ds_sd_location" validate:"min=1,max=255"`
FKSdLocationID string `json:"fk_sd_location_id"`
DsSdLocation string `json:"ds_sd_location" validate:"max=255"`
}
// Response struct untuk update

View File

@@ -0,0 +1,197 @@
package patient
import (
"api-service/internal/models"
"database/sql"
"encoding/json"
"time"
)
// Patient represents the data structure for the patient table
// with proper null handling and optimized JSON marshaling
type Patient struct {
ID int64 `json:"id" db:"id"`
Name sql.NullString `json:"name,omitempty" db:"name"`
MedicalRecordNumber sql.NullString `json:"medical_record_number,omitempty" db:"medical_record_number"`
PhoneNumber sql.NullString `json:"phone_number,omitempty" db:"phone_number"`
Gender sql.NullString `json:"gender,omitempty" db:"gender"`
BirthDate sql.NullTime `json:"birth_date,omitempty" db:"birth_date"`
Address sql.NullString `json:"address,omitempty" db:"address"`
Active sql.NullBool `json:"active,omitempty" db:"active"`
FKSdProvinsiID models.NullableInt32 `json:"fk_sd_provinsi_id,omitempty" db:"fk_sd_provinsi_id"`
FKSdKabupatenKotaID models.NullableInt32 `json:"fk_sd_kabupaten_kota_id,omitempty" db:"fk_sd_kabupaten_kota_id"`
FKSdKecamatanID models.NullableInt32 `json:"fk_sd_kecamatan_id,omitempty" db:"fk_sd_kecamatan_id"`
FKSdKelurahanID models.NullableInt32 `json:"fk_sd_kelurahan_id,omitempty" db:"fk_sd_kelurahan_id"`
DsSdProvinsi sql.NullString `json:"ds_sd_provinsi,omitempty" db:"ds_sd_provinsi"`
DsSdKabupatenKota sql.NullString `json:"ds_sd_kabupaten_kota,omitempty" db:"ds_sd_kabupaten_kota"`
DsSdKecamatan sql.NullString `json:"ds_sd_kecamatan,omitempty" db:"ds_sd_kecamatan"`
DsSdKelurahan sql.NullString `json:"ds_sd_kelurahan,omitempty" db:"ds_sd_kelurahan"`
}
// Custom JSON marshaling untuk Patient agar NULL values tidak muncul di response
func (r Patient) MarshalJSON() ([]byte, error) {
type Alias Patient
aux := &struct {
Name *string `json:"name,omitempty"`
MedicalRecordNumber *string `json:"medical_record_number,omitempty"`
PhoneNumber *string `json:"phone_number,omitempty"`
Gender *string `json:"gender,omitempty"`
BirthDate *time.Time `json:"birth_date,omitempty"`
Address *string `json:"address,omitempty"`
Active *bool `json:"active,omitempty"`
FKSdProvinsiID *int32 `json:"fk_sd_provinsi_id,omitempty"`
FKSdKabupatenKotaID *int32 `json:"fk_sd_kabupaten_kota_id,omitempty"`
FKSdKecamatanID *int32 `json:"fk_sd_kecamatan_id,omitempty"`
FKSdKelurahanID *int32 `json:"fk_sd_kelurahan_id,omitempty"`
DsSdProvinsi *string `json:"ds_sd_provinsi,omitempty"`
DsSdKabupatenKota *string `json:"ds_sd_kabupaten_kota,omitempty"`
DsSdKecamatan *string `json:"ds_sd_kecamatan,omitempty"`
DsSdKelurahan *string `json:"ds_sd_kelurahan,omitempty"`
*Alias
}{
Alias: (*Alias)(&r),
}
if r.Name.Valid {
aux.Name = &r.Name.String
}
if r.MedicalRecordNumber.Valid {
aux.MedicalRecordNumber = &r.MedicalRecordNumber.String
}
if r.PhoneNumber.Valid {
aux.PhoneNumber = &r.PhoneNumber.String
}
if r.Gender.Valid {
aux.Gender = &r.Gender.String
}
if r.BirthDate.Valid {
aux.BirthDate = &r.BirthDate.Time
}
if r.Address.Valid {
aux.Address = &r.Address.String
}
if r.Active.Valid {
aux.Active = &r.Active.Bool
}
if r.FKSdProvinsiID.Valid {
fksp := int32(r.FKSdProvinsiID.Int32)
aux.FKSdProvinsiID = &fksp
}
if r.FKSdKabupatenKotaID.Valid {
fksk := int32(r.FKSdKabupatenKotaID.Int32)
aux.FKSdKabupatenKotaID = &fksk
}
if r.FKSdKecamatanID.Valid {
fksc := int32(r.FKSdKecamatanID.Int32)
aux.FKSdKecamatanID = &fksc
}
if r.FKSdKelurahanID.Valid {
fksl := int32(r.FKSdKelurahanID.Int32)
aux.FKSdKelurahanID = &fksl
}
if r.DsSdProvinsi.Valid {
aux.DsSdProvinsi = &r.DsSdProvinsi.String
}
if r.DsSdKabupatenKota.Valid {
aux.DsSdKabupatenKota = &r.DsSdKabupatenKota.String
}
if r.DsSdKecamatan.Valid {
aux.DsSdKecamatan = &r.DsSdKecamatan.String
}
if r.DsSdKelurahan.Valid {
aux.DsSdKelurahan = &r.DsSdKelurahan.String
}
return json.Marshal(aux)
}
// Helper methods untuk mendapatkan nilai yang aman
func (r *Patient) GetName() string {
if r.Name.Valid {
return r.Name.String
}
return ""
}
// Response struct untuk GET by ID
type PatientGetByIDResponse struct {
Message string `json:"message"`
Data *Patient `json:"data"`
}
// Enhanced GET response dengan pagination dan aggregation
type PatientGetResponse struct {
Message string `json:"message"`
Data []Patient `json:"data"`
Meta models.MetaResponse `json:"meta"`
Summary *models.AggregateData `json:"summary,omitempty"`
}
// Request struct untuk create
type PatientCreateRequest struct {
Name string `json:"name" validate:"min=1,max=100"`
MedicalRecordNumber string `json:"medical_record_number" validate:"min=1,max=20"`
PhoneNumber string `json:"phone_number" validate:"min=1,max=20"`
Gender string `json:"gender" validate:"min=1,max=20"`
BirthDate time.Time `json:"birth_date"`
Address string `json:"address" validate:"min=1,max=255"`
Active bool `json:"active"`
FKSdProvinsiID int32 `json:"fk_sd_provinsi_id"`
FKSdKabupatenKotaID int32 `json:"fk_sd_kabupaten_kota_id"`
FKSdKecamatanID int32 `json:"fk_sd_kecamatan_id"`
FKSdKelurahanID int32 `json:"fk_sd_kelurahan_id"`
DsSdProvinsi string `json:"ds_sd_provinsi" validate:"min=1,max=255"`
DsSdKabupatenKota string `json:"ds_sd_kabupaten_kota" validate:"min=1,max=255"`
DsSdKecamatan string `json:"ds_sd_kecamatan" validate:"min=1,max=255"`
DsSdKelurahan string `json:"ds_sd_kelurahan" validate:"min=1,max=255"`
}
type PatientPostRequest struct {
ID int64 `json:"id" validate:"required,min=1"`
}
// Response struct untuk create
type PatientCreateResponse struct {
Message string `json:"message"`
Data *Patient `json:"data"`
}
// Update request
type PatientUpdateRequest struct {
ID int `json:"id" validate:"required,min=1"`
Name string `json:"name" validate:"min=1,max=100"`
MedicalRecordNumber string `json:"medical_record_number" validate:"min=1,max=20"`
PhoneNumber string `json:"phone_number" validate:"min=1,max=20"`
Gender string `json:"gender" validate:"min=1,max=20"`
BirthDate time.Time `json:"birth_date"`
Address string `json:"address" validate:"min=1,max=255"`
Active bool `json:"active"`
FKSdProvinsiID int32 `json:"fk_sd_provinsi_id"`
FKSdKabupatenKotaID int32 `json:"fk_sd_kabupaten_kota_id"`
FKSdKecamatanID int32 `json:"fk_sd_kecamatan_id"`
FKSdKelurahanID int32 `json:"fk_sd_kelurahan_id"`
DsSdProvinsi string `json:"ds_sd_provinsi" validate:"max=255"`
DsSdKabupatenKota string `json:"ds_sd_kabupaten_kota" validate:"max=255"`
DsSdKecamatan string `json:"ds_sd_kecamatan" validate:"max=255"`
DsSdKelurahan string `json:"ds_sd_kelurahan" validate:"max=255"`
}
// Response struct untuk update
type PatientUpdateResponse struct {
Message string `json:"message"`
Data *Patient `json:"data"`
}
// Response struct untuk delete
type PatientDeleteResponse struct {
Message string `json:"message"`
ID string `json:"id"`
}
// Filter struct untuk query parameters
type PatientFilter struct {
Status *string `json:"status,omitempty" form:"status"`
Search *string `json:"search,omitempty" form:"search"`
DateFrom *time.Time `json:"date_from,omitempty" form:"date_from"`
DateTo *time.Time `json:"date_to,omitempty" form:"date_to"`
}