forked from rachmadiyanti.annisa.3004/service_antrean
Patient + Visit
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -90,24 +90,29 @@ import (
|
||||
// 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"`
|
||||
Attachments []PatientAttachment `json:"attachments,omitempty"`
|
||||
PaymentTypes []PatientPaymentType `json:"payment_types,omitempty"`
|
||||
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 sql.NullInt64 `json:"fk_sd_provinsi_id,omitempty" db:"fk_sd_provinsi_id"`
|
||||
FKSdKabupatenKotaID sql.NullInt64 `json:"fk_sd_kabupaten_kota_id,omitempty" db:"fk_sd_kabupaten_kota_id"`
|
||||
FKSdKecamatanID sql.NullInt64 `json:"fk_sd_kecamatan_id,omitempty" db:"fk_sd_kecamatan_id"`
|
||||
FKSdKelurahanID sql.NullInt64 `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"`
|
||||
// ProvinsiName sql.NullString `json:"Provinsi,omitempty" db:"Provinsi"`
|
||||
// KabupatenKotaName sql.NullString `json:"Kabupaten_kota,omitempty" db:"Kabupaten_kota"`
|
||||
// KecamatanName sql.NullString `json:"Kecamatan,omitempty" db:"Kecamatan"`
|
||||
// KelurahanName sql.NullString `json:"Desa_kelurahan,omitempty" db:"Desa_kelurahan"`
|
||||
Attachments []PatientAttachment `json:"attachments,omitempty"`
|
||||
PaymentTypes []PatientPaymentType `json:"payment_types,omitempty"`
|
||||
Visits []PatientVisit `json:"visits,omitempty"`
|
||||
}
|
||||
|
||||
type PatientPaymentType struct {
|
||||
@@ -128,6 +133,17 @@ type PatientAttachment struct {
|
||||
FKMsPatientID models.NullableInt32 `json:"fk_ms_patient_id,omitempty" db:"fk_ms_patient_id"`
|
||||
}
|
||||
|
||||
type PatientVisit struct {
|
||||
ID int64 `json:"id" db:"id"`
|
||||
Barcode models.NullableInt32 `json:"barcode,omitempty" db:"barcode"`
|
||||
RegistrationDate sql.NullTime `json:"registration_date,omitempty" db:"registration_date"`
|
||||
ServiceDate sql.NullTime `json:"service_date,omitempty" db:"service_date"`
|
||||
CheckInDate sql.NullTime `json:"check_in_date,omitempty" db:"check_in_date"`
|
||||
CheckIn sql.NullBool `json:"check_in,omitempty" db:"check_in"`
|
||||
Active sql.NullBool `json:"active,omitempty" db:"active"`
|
||||
FKMsPatientID models.NullableInt32 `json:"fk_ms_patient_id,omitempty" db:"fk_ms_patient_id"`
|
||||
}
|
||||
|
||||
// Custom JSON marshaling untuk Patient agar NULL values tidak muncul di response
|
||||
func (r Patient) MarshalJSON() ([]byte, error) {
|
||||
type Alias Patient
|
||||
@@ -139,10 +155,10 @@ func (r Patient) MarshalJSON() ([]byte, error) {
|
||||
BirthDate *string `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"`
|
||||
FKSdProvinsiID *int `json:"fk_sd_provinsi_id,omitempty"`
|
||||
FKSdKabupatenKotaID *int `json:"fk_sd_kabupaten_kota_id,omitempty"`
|
||||
FKSdKecamatanID *int `json:"fk_sd_kecamatan_id,omitempty"`
|
||||
FKSdKelurahanID *int `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"`
|
||||
@@ -175,19 +191,19 @@ func (r Patient) MarshalJSON() ([]byte, error) {
|
||||
aux.Active = &r.Active.Bool
|
||||
}
|
||||
if r.FKSdProvinsiID.Valid {
|
||||
fksp := int32(r.FKSdProvinsiID.Int32)
|
||||
fksp := int(r.FKSdProvinsiID.Int64)
|
||||
aux.FKSdProvinsiID = &fksp
|
||||
}
|
||||
if r.FKSdKabupatenKotaID.Valid {
|
||||
fksk := int32(r.FKSdKabupatenKotaID.Int32)
|
||||
fksk := int(r.FKSdKabupatenKotaID.Int64)
|
||||
aux.FKSdKabupatenKotaID = &fksk
|
||||
}
|
||||
if r.FKSdKecamatanID.Valid {
|
||||
fksc := int32(r.FKSdKecamatanID.Int32)
|
||||
fksc := int(r.FKSdKecamatanID.Int64)
|
||||
aux.FKSdKecamatanID = &fksc
|
||||
}
|
||||
if r.FKSdKelurahanID.Valid {
|
||||
fksl := int32(r.FKSdKelurahanID.Int32)
|
||||
fksl := int(r.FKSdKelurahanID.Int64)
|
||||
aux.FKSdKelurahanID = &fksl
|
||||
}
|
||||
if r.DsSdProvinsi.Valid {
|
||||
@@ -271,6 +287,50 @@ func (r PatientAttachment) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(aux)
|
||||
}
|
||||
|
||||
func (r PatientVisit) MarshalJSON() ([]byte, error) {
|
||||
type Alias PatientVisit
|
||||
aux := &struct {
|
||||
*Alias
|
||||
Barcode *int `json:"barcode,omitempty"`
|
||||
RegistrationDate *string `json:"registration_date,omitempty"`
|
||||
ServiceDate *string `json:"service_date,omitempty"`
|
||||
CheckInDate *string `json:"check_in_date,omitempty"`
|
||||
CheckIn *bool `json:"check_in,omitempty"`
|
||||
Active *bool `json:"active,omitempty"`
|
||||
FKMsPatientID *int `json:"fk_ms_patient_id,omitempty"`
|
||||
}{
|
||||
Alias: (*Alias)(&r),
|
||||
}
|
||||
|
||||
if r.Barcode.Valid {
|
||||
barcode := int(r.Barcode.Int32)
|
||||
aux.Barcode = &barcode
|
||||
}
|
||||
if r.RegistrationDate.Valid {
|
||||
regDateStr := r.RegistrationDate.Time.Format(time.RFC3339)
|
||||
aux.RegistrationDate = ®DateStr
|
||||
}
|
||||
if r.ServiceDate.Valid {
|
||||
svcDateStr := r.ServiceDate.Time.Format(time.RFC3339)
|
||||
aux.ServiceDate = &svcDateStr
|
||||
}
|
||||
if r.CheckInDate.Valid {
|
||||
checkInDateStr := r.CheckInDate.Time.Format(time.RFC3339)
|
||||
aux.CheckInDate = &checkInDateStr
|
||||
}
|
||||
if r.CheckIn.Valid {
|
||||
aux.CheckIn = &r.CheckIn.Bool
|
||||
}
|
||||
if r.Active.Valid {
|
||||
aux.Active = &r.Active.Bool
|
||||
}
|
||||
if r.FKMsPatientID.Valid {
|
||||
fkmp := int(r.FKMsPatientID.Int32)
|
||||
aux.FKMsPatientID = &fkmp
|
||||
}
|
||||
return json.Marshal(aux)
|
||||
}
|
||||
|
||||
// Helper methods untuk mendapatkan nilai yang aman
|
||||
func (r *Patient) GetName() string {
|
||||
if r.Name.Valid {
|
||||
@@ -303,20 +363,41 @@ type PatientCreateRequest struct {
|
||||
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"`
|
||||
FKSdProvinsiID *int `json:"fk_sd_provinsi_id"`
|
||||
FKSdKabupatenKotaID *int `json:"fk_sd_kabupaten_kota_id"`
|
||||
FKSdKecamatanID *int `json:"fk_sd_kecamatan_id"`
|
||||
FKSdKelurahanID *int `json:"fk_sd_kelurahan_id"`
|
||||
DsSdProvinsi *string `json:"ds_sd_provinsi"`
|
||||
DsSdKabupatenKota *string `json:"ds_sd_kabupaten_kota"`
|
||||
DsSdKecamatan *string `json:"ds_sd_kecamatan"`
|
||||
DsSdKelurahan *string `json:"ds_sd_kelurahan"`
|
||||
Attachments []PatientAttachmentCreateRequest `json:"attachments,omitempty"`
|
||||
Payments []PatientPaymentTypeCreateRequest `json:"payment_types,omitempty"`
|
||||
Visits []VisitCreateRequest `json:"visits,omitempty"`
|
||||
}
|
||||
|
||||
type VisitCreateRequest struct {
|
||||
// ID *int `json:"id"`
|
||||
Barcode *int32 `json:"barcode" validate:"omitempty,min=1"`
|
||||
RegistrationDate *time.Time `json:"registration_date" validate:"omitempty"`
|
||||
ServiceDate *time.Time `json:"service_date" validate:"omitempty"`
|
||||
CheckInDate *time.Time `json:"check_in_date" validate:"omitempty"`
|
||||
CheckIn *bool `json:"check_in" validate:"omitempty"`
|
||||
Active *bool `json:"active" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type VisitUpdateRequest struct {
|
||||
ID *int `json:"id" validate:"required"`
|
||||
Barcode *int32 `json:"barcode" validate:"omitempty,min=1"`
|
||||
RegistrationDate *time.Time `json:"registration_date" validate:"omitempty"`
|
||||
ServiceDate *time.Time `json:"service_date" validate:"omitempty"`
|
||||
CheckInDate *time.Time `json:"check_in_date" validate:"omitempty"`
|
||||
CheckIn *bool `json:"check_in" validate:"omitempty"`
|
||||
Active *bool `json:"active" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type PatientPostRequest struct {
|
||||
// ID int64 `json:"id" validate:"required,min=1"`
|
||||
// ID int64 `json:"id" validate:"required"`
|
||||
MedicalRecordNumber string `json:"medical_record_number" validate:"required,min=1"`
|
||||
}
|
||||
|
||||
@@ -328,24 +409,25 @@ type PatientCreateResponse struct {
|
||||
|
||||
// Update request
|
||||
type PatientUpdateRequest struct {
|
||||
ID *int `json:"-" 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:"max=1"`
|
||||
// ID *int `json:"-" validate:"required,min=1"`
|
||||
Name *string `json:"name"`
|
||||
MedicalRecordNumber *string `json:"medical_record_number" validate:"required,min=1,max=20"`
|
||||
PhoneNumber *string `json:"phone_number"`
|
||||
Gender *string `json:"gender"`
|
||||
BirthDate *time.Time `json:"birth_date"`
|
||||
Address *string `json:"address" validate:"min=1,max=255"`
|
||||
Address *string `json:"address"`
|
||||
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"`
|
||||
Attachments []PatientAttachmentCreateRequest `json:"attachments,omitempty"`
|
||||
Payments []PatientPaymentTypeCreateRequest `json:"payment_types,omitempty"`
|
||||
FKSdProvinsiID *int `json:"fk_sd_provinsi_id"`
|
||||
FKSdKabupatenKotaID *int `json:"fk_sd_kabupaten_kota_id"`
|
||||
FKSdKecamatanID *int `json:"fk_sd_kecamatan_id"`
|
||||
FKSdKelurahanID *int `json:"fk_sd_kelurahan_id"`
|
||||
DsSdProvinsi *string `json:"ds_sd_provinsi"`
|
||||
DsSdKabupatenKota *string `json:"ds_sd_kabupaten_kota"`
|
||||
DsSdKecamatan *string `json:"ds_sd_kecamatan"`
|
||||
DsSdKelurahan *string `json:"ds_sd_kelurahan"`
|
||||
Attachments []PatientAttachmentUpdateRequest `json:"attachments,omitempty"`
|
||||
Payments []PatientPaymentTypeUpdateRequest `json:"payment_types,omitempty"`
|
||||
Visits []VisitUpdateRequest `json:"visits,omitempty"`
|
||||
}
|
||||
|
||||
type PatientAttachmentCreateRequest struct {
|
||||
@@ -361,7 +443,7 @@ type PatientPaymentTypeCreateRequest struct {
|
||||
Name *string `json:"name" validate:"omitempty,min=1,max=20"`
|
||||
Number *string `json:"number" validate:"omitempty,min=1,max=20"`
|
||||
Active *bool `json:"active" validate:"omitempty"`
|
||||
FkRefPaymentType *int `json:"fk_ref_payment_type" validate:"omitempty,min=1"`
|
||||
FKRefPaymentType *int `json:"fk_ref_payment_type" validate:"omitempty,min=1"`
|
||||
}
|
||||
|
||||
type PatientAttachmentUpdateRequest struct {
|
||||
|
||||
@@ -195,12 +195,11 @@ func RegisterRoutes(cfg *config.Config) *gin.Engine {
|
||||
patientMspatientHandler := patientMspatientHandlers.NewPatientHandler()
|
||||
patientMspatientGroup := v1.Group("/patient")
|
||||
{
|
||||
// patientMspatientGroup.GET("/", patientMspatientHandler.GetMs_patient)
|
||||
// patientMspatientGroup.POST("/", patientMspatientHandler.CreateMs_patient)
|
||||
// patientMspatientGroup.PUT("/:medical_record_number", patientMspatientHandler.UpdateMs_patient)
|
||||
// patientMspatientGroup.DELETE("/:medical_record_number", patientMspatientHandler.DeleteMs_patient)
|
||||
patientMspatientGroup.PUT("/:medical_record_number", patientMspatientHandler.UpdatePatient)
|
||||
patientMspatientGroup.DELETE("/:medical_record_number", patientMspatientHandler.DeletePatient)
|
||||
patientMspatientGroup.GET("/", patientMspatientHandler.GetPatient)
|
||||
patientMspatientGroup.POST("/detail", patientMspatientHandler.GetPatientByIDPost)
|
||||
patientMspatientGroup.POST("/detail", patientMspatientHandler.GetPatientByMedicalRecordNumberPost)
|
||||
patientMspatientGroup.POST("/", patientMspatientHandler.CreatePatient)
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user