adjust with new field
This commit is contained in:
parent
3e6f91f0ab
commit
d8da93fdb4
@ -48,59 +48,6 @@ var Pekerjaan = []EnumObject{
|
||||
{ID: 6, Label: "Lain-lain"},
|
||||
}
|
||||
|
||||
// export const importDataPasienSchema = z.object({
|
||||
// no_rekammedis: z.string(),
|
||||
// nama_pasien: z.string(),
|
||||
// no_ktp: z.string().nullish(),
|
||||
// no_bpjs: z.string().nullish(),
|
||||
// tgl_lahir: z.date(),
|
||||
// kelamin: z.number(),
|
||||
// kebangsaan: z.string().nullish(),
|
||||
// agama: z.string().nullish().transform(val => Agama.find(x => x.label === val)?.id),
|
||||
// suku: z.string().nullish(),
|
||||
// pendidikan: z.coerce.number().nullish(),
|
||||
// pekerjaan: z.string().nullish().transform(val => Pekerjaan.find(x => x.label === val)?.id),
|
||||
// hp: z.coerce.string().nullish().transform(val => validatePhoneRegex(val?.replace(/\s+/g, ''))),
|
||||
// email: z.string().nullish(),
|
||||
// status_nikah: z.string().nullish().transform(val => StatusKawin.find(x => x.label === val)?.id),
|
||||
// provinsi: z.string().nullish(),
|
||||
// kabupaten: z.string().nullish(),
|
||||
// kecamatan: z.string().nullish(),
|
||||
// kelurahan: z.string().nullish(),
|
||||
// kodepos: z.string().nullish(),
|
||||
// namajalan: z.string().nullish(),
|
||||
// hp_penjamin: z.coerce.string().nullish().transform(val => validatePhoneRegex(val?.replace(/\s+/g, ''))),
|
||||
// namapenjamin: z.string().nullish(),
|
||||
// ktp_penjamin: z.coerce.string().nullish(),
|
||||
// hubungan_penjamin: z.coerce.number().nullish(),
|
||||
// pendidikan_penjamin: z.string().nullish().transform(val => Pendidikan.find(x => x.label === val)?.id),
|
||||
// alamat_penjamin: z.string().nullish(),
|
||||
// }).transform(({
|
||||
// no_rekammedis,
|
||||
// nama_pasien,
|
||||
// no_ktp,
|
||||
// no_bpjs,
|
||||
// tgl_lahir,
|
||||
// kelamin,
|
||||
// status_nikah,
|
||||
// namajalan,
|
||||
// hp,
|
||||
// pendidikan_penjamin,
|
||||
// ...rest
|
||||
// }) => ({
|
||||
// noRm: no_rekammedis,
|
||||
// namaPasien: nama_pasien,
|
||||
// nik: no_ktp,
|
||||
// noKartuPesertaBPJS: no_bpjs,
|
||||
// tanggalLahir: tgl_lahir,
|
||||
// jenisKelamin: kelamin,
|
||||
// statusPernikahan: status_nikah,
|
||||
// pendidikanPenjamin: pendidikan_penjamin,
|
||||
// noHp: hp,
|
||||
// nama_jalan: namajalan,
|
||||
// ...rest
|
||||
// }))
|
||||
|
||||
type Patient struct {
|
||||
NoRekamMedis string `json:"no_rekammedis"`
|
||||
NamaPasien string `json:"nama_pasien"`
|
||||
|
@ -279,81 +279,48 @@ func (q *Queries) CreatePatient(ctx context.Context, arg createPatientParams) (m
|
||||
type ImportDataPasienParams struct {
|
||||
NoRekamMedis string
|
||||
NamaPasien string
|
||||
Nik pgtype.Text
|
||||
NoKTP pgtype.Text
|
||||
NoBPJS pgtype.Text
|
||||
TpLahir pgtype.Text
|
||||
TempatLahir pgtype.Int4
|
||||
TglLahir time.Time
|
||||
Kelamin int8
|
||||
Kebangsaan *int8
|
||||
Agama *int8
|
||||
Suku *int32
|
||||
Pendidikan *int8
|
||||
Pekerjaan *int8
|
||||
Kebangsaan pgtype.Int4
|
||||
Agama pgtype.Int4
|
||||
Suku pgtype.Int4
|
||||
Pendidikan pgtype.Int4
|
||||
Pekerjaan pgtype.Int4
|
||||
Hp pgtype.Text
|
||||
Email pgtype.Text
|
||||
StatusNikah *int8
|
||||
Provinsi *string
|
||||
Kabupaten *int32
|
||||
Kecamatan *int32
|
||||
Kelurahan *int32
|
||||
Kodepos *int32
|
||||
StatusKawin pgtype.Int4
|
||||
Provinsi pgtype.Text
|
||||
NamaJalan pgtype.Text
|
||||
HpPenjamin pgtype.Text
|
||||
NamaPenjamin pgtype.Text
|
||||
KtpPenjamin pgtype.Text
|
||||
HubunganPenjamin *int8
|
||||
PendidikanPenjamin *int8
|
||||
AlamatPenjamin pgtype.Text
|
||||
NikPenjamin pgtype.Text
|
||||
HubunganPenjamin pgtype.Int2
|
||||
HpPenjamin pgtype.Text
|
||||
}
|
||||
|
||||
func (store *SQLStore) ImportPatientTx(ctx context.Context, params ImportDataPasienParams, createdBy int32, fasyankesId int32) error {
|
||||
err := store.execTx(ctx, func(q *Queries) error {
|
||||
var err error
|
||||
|
||||
tempNilInt := int8(util.NilIntVal)
|
||||
|
||||
if params.Pendidikan == nil {
|
||||
params.Pendidikan = &tempNilInt
|
||||
}
|
||||
|
||||
if params.Agama == nil {
|
||||
params.Agama = &tempNilInt
|
||||
}
|
||||
|
||||
if params.Pekerjaan == nil {
|
||||
params.Pekerjaan = &tempNilInt
|
||||
}
|
||||
|
||||
if params.StatusNikah == nil {
|
||||
params.StatusNikah = &tempNilInt
|
||||
}
|
||||
|
||||
patient, err := q.CreatePatient(ctx, createPatientParams{
|
||||
NoRm: params.NoRekamMedis,
|
||||
NamaPasien: params.NamaPasien,
|
||||
Pendidikan: pgtype.Int4{Valid: params.Pendidikan != nil, Int32: int32(*params.Pendidikan)},
|
||||
TanggalLahir: params.TglLahir,
|
||||
Nik: params.Nik,
|
||||
Agama: pgtype.Int4{Valid: params.Agama != nil, Int32: int32(*params.Agama)},
|
||||
NoHp: params.Hp,
|
||||
Pekerjaan: pgtype.Int4{Valid: params.Pekerjaan != nil, Int32: int32(*params.Agama)},
|
||||
Email: params.Email,
|
||||
Nik: params.NoKTP,
|
||||
NoKartuPesertaBPJS: params.NoBPJS,
|
||||
KotaLahir: params.TempatLahir,
|
||||
TanggalLahir: params.TglLahir,
|
||||
JenisKelamin: params.Kelamin,
|
||||
StatusPerkawinan: pgtype.Int4{Valid: params.StatusNikah != nil, Int32: int32(*params.StatusNikah)},
|
||||
IsDeleted: false,
|
||||
JenisIdentitas: pgtype.Int4{Valid: false, Int32: 0},
|
||||
NoIdentitas: pgtype.Text{Valid: false, String: ""},
|
||||
FotoProfil: pgtype.Text{Valid: false, String: ""},
|
||||
FotoKtp: pgtype.Text{Valid: false, String: ""},
|
||||
KotaLahir: pgtype.Int4{Valid: false, Int32: 0},
|
||||
Suku: pgtype.Int4{Valid: false, Int32: 0},
|
||||
Kebangsaan: pgtype.Int4{Valid: false, Int32: 0},
|
||||
Bahasa: pgtype.Int4{Valid: false, Int32: 0},
|
||||
Kebangsaan: params.Kebangsaan,
|
||||
Agama: params.Agama,
|
||||
Suku: params.Suku,
|
||||
Pendidikan: params.Pendidikan,
|
||||
Pekerjaan: params.Pekerjaan,
|
||||
NoHp: params.Hp,
|
||||
Email: params.Email,
|
||||
StatusPerkawinan: params.StatusKawin,
|
||||
FasyankesID: int(fasyankesId),
|
||||
CreateBy: int(createdBy),
|
||||
UpdateBy: int(createdBy),
|
||||
NoKk: pgtype.Text{Valid: false, String: ""},
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
})
|
||||
|
||||
@ -363,7 +330,7 @@ func (store *SQLStore) ImportPatientTx(ctx context.Context, params ImportDataPas
|
||||
|
||||
if params.NamaJalan.Valid {
|
||||
var provinsi_id *int32
|
||||
provinsi, err := q.FindWilayahByName(ctx, *params.Provinsi)
|
||||
provinsi, err := q.FindWilayahByName(ctx, params.Provinsi.String)
|
||||
|
||||
if err != nil {
|
||||
if err != pgx.ErrNoRows {
|
||||
@ -400,10 +367,10 @@ func (store *SQLStore) ImportPatientTx(ctx context.Context, params ImportDataPas
|
||||
|
||||
}
|
||||
|
||||
if params.HubunganPenjamin != nil && params.NamaPenjamin.Valid {
|
||||
if params.HubunganPenjamin.Valid && params.NamaPenjamin.Valid {
|
||||
_, err = q.CreateKeluarga(ctx, model.Keluarga{
|
||||
Id: int32(patient.ID),
|
||||
Nama: ¶ms.NamaPenjamin.String,
|
||||
Nama: params.NamaPenjamin,
|
||||
Hubungan: params.HubunganPenjamin,
|
||||
})
|
||||
|
||||
|
@ -60,7 +60,7 @@ func (s *Server) ImportPatientHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
rows, err := f.GetRows("import data pasien")
|
||||
rows, err := f.GetRows("PRODUCTION Pasien Setio")
|
||||
|
||||
if err != nil {
|
||||
json.NewEncoder(w).Encode(err)
|
||||
@ -78,17 +78,19 @@ func (s *Server) ImportPatientHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// tempArr := make([]repository.ImportDataPasienParams, len(rows)-1)
|
||||
var errorMsg []interface{}
|
||||
// var wg = &sync.WaitGroup{}
|
||||
|
||||
for idx, row := range rows {
|
||||
// wg.Add(1)
|
||||
// go func(idx int, row []string) {
|
||||
if idx >= 1 {
|
||||
|
||||
if row[0] == "" || row[1] == "" {
|
||||
errorMsg = append(errorMsg, map[string]any{
|
||||
"baris": idx + 1,
|
||||
"status": "CRITICAL",
|
||||
"error_message": "kolom A 'no_rekam medis' dan kolom B 'nama_pasien' wajib diisi",
|
||||
})
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
tanggalLahir, err := time.Parse(util.TIME_PARSE_LAYOUT, row[5])
|
||||
@ -98,43 +100,37 @@ func (s *Server) ImportPatientHandler(w http.ResponseWriter, r *http.Request) {
|
||||
"status": "CRITICAL",
|
||||
"error_message": "tanggal lahir wajib diisi",
|
||||
})
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
kelamin, err := strconv.Atoi(row[6])
|
||||
if err != nil {
|
||||
log.Printf("row 6: %s, err: %v", row[6], err)
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
value := repository.ImportDataPasienParams{
|
||||
NoRekamMedis: row[0],
|
||||
NamaPasien: row[1],
|
||||
Nik: pgtype.Text{String: row[2], Valid: len(row[2]) > 0},
|
||||
NoKTP: pgtype.Text{String: row[2], Valid: len(row[2]) > 0},
|
||||
NoBPJS: pgtype.Text{String: row[3], Valid: len(row[3]) > 0},
|
||||
TpLahir: pgtype.Text{String: row[4], Valid: len(row[4]) > 0},
|
||||
TempatLahir: pgtype.Int4{Int32: 0, Valid: false},
|
||||
TglLahir: tanggalLahir,
|
||||
Kelamin: int8(kelamin),
|
||||
Kebangsaan: util.StringToIntPtr[int8](row[6]),
|
||||
Agama: util.StringToIntPtr[int8](row[7]),
|
||||
Suku: util.StringToIntPtr[int32](row[8]),
|
||||
Pendidikan: util.StringToIntPtr[int8](row[9]),
|
||||
Pekerjaan: util.StringToIntPtr[int8](row[10]),
|
||||
Hp: pgtype.Text{String: row[11], Valid: len(row[11]) > 0},
|
||||
Email: pgtype.Text{String: row[12], Valid: len(row[12]) > 0},
|
||||
StatusNikah: util.StringToIntPtr[int8](row[13]),
|
||||
Provinsi: util.StringToStringPtr(row[14]),
|
||||
Kabupaten: util.StringToIntPtr[int32](row[15]),
|
||||
Kecamatan: util.StringToIntPtr[int32](row[16]),
|
||||
Kelurahan: util.StringToIntPtr[int32](row[17]),
|
||||
Kodepos: util.StringToIntPtr[int32](row[18]),
|
||||
NamaJalan: pgtype.Text{String: row[19], Valid: len(row[19]) > 0},
|
||||
Kebangsaan: pgtype.Int4{Int32: util.StringToInt[int32](row[7]), Valid: util.StringToInt[int32](row[7]) > 0},
|
||||
Agama: pgtype.Int4{Int32: util.StringToInt[int32](row[8]), Valid: util.StringToInt[int32](row[8]) > 0},
|
||||
Suku: pgtype.Int4{Int32: util.StringToInt[int32](row[9]), Valid: util.StringToInt[int32](row[9]) > 0},
|
||||
Pendidikan: pgtype.Int4{Int32: util.StringToInt[int32](row[10]), Valid: util.StringToInt[int32](row[10]) > 0},
|
||||
Pekerjaan: pgtype.Int4{Int32: util.StringToInt[int32](row[11]), Valid: util.StringToInt[int32](row[11]) > 0},
|
||||
Hp: pgtype.Text{String: row[12], Valid: len(row[12]) > 0},
|
||||
Email: pgtype.Text{String: row[13], Valid: len(row[13]) > 0},
|
||||
StatusKawin: pgtype.Int4{Int32: util.StringToInt[int32](row[14]), Valid: util.StringToInt[int32](row[14]) > 0},
|
||||
Provinsi: pgtype.Text{String: row[15], Valid: len(row[15]) > 0},
|
||||
NamaJalan: pgtype.Text{String: row[16], Valid: len(row[16]) > 0},
|
||||
NamaPenjamin: pgtype.Text{String: row[17], Valid: len(row[17]) > 0},
|
||||
NikPenjamin: pgtype.Text{String: row[18], Valid: len(row[18]) > 0},
|
||||
HubunganPenjamin: pgtype.Int2{Int16: util.StringToInt[int16](row[8]), Valid: util.StringToInt[int16](row[8]) > 0},
|
||||
HpPenjamin: pgtype.Text{String: row[20], Valid: len(row[20]) > 0},
|
||||
NamaPenjamin: pgtype.Text{String: row[21], Valid: len(row[21]) > 0},
|
||||
KtpPenjamin: pgtype.Text{String: row[22], Valid: len(row[22]) > 0},
|
||||
HubunganPenjamin: util.StringToIntPtr[int8](row[23]),
|
||||
PendidikanPenjamin: util.StringToIntPtr[int8](row[24]),
|
||||
AlamatPenjamin: pgtype.Text{String: row[25], Valid: len(row[25]) > 0},
|
||||
}
|
||||
|
||||
patientExist, err := repository.Store.FindPatientByNoRm(s.Store, r.Context(), value.NoRekamMedis)
|
||||
@ -146,7 +142,7 @@ func (s *Server) ImportPatientHandler(w http.ResponseWriter, r *http.Request) {
|
||||
"status": "CRITICAL",
|
||||
"message": fmt.Sprintf("Terjadi kesalahan sistem, mencari data pasien %v", err),
|
||||
})
|
||||
continue
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,7 +155,7 @@ func (s *Server) ImportPatientHandler(w http.ResponseWriter, r *http.Request) {
|
||||
"status": "CRITICAL",
|
||||
"message": fmt.Sprintf("Terjadi kesalahan sistem, gagal generate NoRM %v", err),
|
||||
})
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
errorMsg = append(errorMsg, map[string]any{
|
||||
@ -172,8 +168,8 @@ func (s *Server) ImportPatientHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if value.Nik.Valid {
|
||||
patient, err := repository.Store.FindPatientByNik(s.Store, r.Context(), value.Nik.String)
|
||||
if value.NoKTP.Valid {
|
||||
patient, err := repository.Store.FindPatientByNik(s.Store, r.Context(), value.NoKTP.String)
|
||||
|
||||
if err != nil {
|
||||
if err != pgx.ErrNoRows {
|
||||
@ -185,9 +181,9 @@ func (s *Server) ImportPatientHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if value.Nik.String == patient.Nik.String {
|
||||
if value.NoKTP.String == patient.Nik.String {
|
||||
if patient.TanggalLahir.Before(value.TglLahir) {
|
||||
value.Nik.Valid = false
|
||||
value.NoKTP.Valid = false
|
||||
} else {
|
||||
_, err := repository.Store.UpdatePatient(s.Store, r.Context(), repository.UpdatePatientParams{
|
||||
Nik: repository.UpdateableField[pgtype.Text]{IsFilled: true, Value: pgtype.Text{Valid: false, String: ""}},
|
||||
@ -199,7 +195,7 @@ func (s *Server) ImportPatientHandler(w http.ResponseWriter, r *http.Request) {
|
||||
"message": fmt.Sprintf("Terjadi kesalahan sistem, gagal mendapatakan update pasien lama karena NIK sama %v", err),
|
||||
})
|
||||
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
errorMsg = append(errorMsg, map[string]any{
|
||||
@ -246,7 +242,7 @@ func (s *Server) ImportPatientHandler(w http.ResponseWriter, r *http.Request) {
|
||||
"message": fmt.Sprintf("Terjadi kesalahan sistem, gagal mendapatakan update pasien dengan BPJS %v", err),
|
||||
})
|
||||
}
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
errorMsg = append(errorMsg, map[string]any{
|
||||
@ -268,12 +264,16 @@ func (s *Server) ImportPatientHandler(w http.ResponseWriter, r *http.Request) {
|
||||
"message": fmt.Sprintf("Terjadi kesalahan sistem, gagal saat import pasien dengan %v", err),
|
||||
})
|
||||
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
// wg.Done()
|
||||
// }(idx, row)
|
||||
}
|
||||
|
||||
// wg.Wait()
|
||||
|
||||
if len(errorMsg) > 0 {
|
||||
jsonMarshal, _ := json.MarshalIndent(errorMsg, "", " ")
|
||||
if err := os.WriteFile("foo.txt", []byte(jsonMarshal), 0666); err != nil {
|
||||
|
2
main.go
2
main.go
@ -21,7 +21,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(5)
|
||||
runtime.GOMAXPROCS(2)
|
||||
var wait time.Duration
|
||||
flag.DurationVar(&wait, "graceful-timeout", time.Second*15, "the duration for which the server gracefully wait for existing connections to finish - e.g. 15s or 1m")
|
||||
flag.Parse()
|
||||
|
@ -1,12 +1,16 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Keluarga struct {
|
||||
Id int32 `json:"id"`
|
||||
PasienId int32 `json:"pasien_id"`
|
||||
Nama *string `json:"nama,omitempty"`
|
||||
Hubungan *int8 `json:"hubungan,omitempty"`
|
||||
Nama pgtype.Text `json:"nama,omitempty"`
|
||||
Hubungan pgtype.Int2 `json:"hubungan,omitempty"`
|
||||
NoIdentitas *string `json:"no_identitas,omitempty"`
|
||||
NoHp *string `json:"no_hp,omitempty"`
|
||||
KotaLahir *int32 `json:"kota_lahir,omitempty"`
|
||||
|
@ -2,37 +2,43 @@ package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const TIME_PARSE_LAYOUT = "2/1/2006"
|
||||
const NilIntVal = int8(0)
|
||||
|
||||
func StringToIntPtr[T int8 | int32 | int64](s string) *T {
|
||||
func StringToInt[T int8 | int32 | int16 | int64](s string) T {
|
||||
log.Println(s)
|
||||
var val T
|
||||
switch any(val).(type) {
|
||||
case int8, int32, int64:
|
||||
num, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
return nil
|
||||
if strings.TrimSpace(s) == "" {
|
||||
return 0
|
||||
}
|
||||
switch any(val).(type) {
|
||||
case int8, int16, int32, int64:
|
||||
num, _ := strconv.ParseInt(s, 10, 64)
|
||||
switch any(val).(type) {
|
||||
case int8:
|
||||
val := int8(num)
|
||||
return any(&val).(*T)
|
||||
return any(val).(T)
|
||||
case int16:
|
||||
val := int16(num)
|
||||
return any(val).(T)
|
||||
case int32:
|
||||
val := int32(num)
|
||||
return any(&val).(*T)
|
||||
return any(val).(T)
|
||||
case int64:
|
||||
val := int64(num)
|
||||
return any(&val).(*T)
|
||||
return any(val).(T)
|
||||
default:
|
||||
return nil
|
||||
return 0
|
||||
}
|
||||
default:
|
||||
fmt.Printf("Unsupported type: %s\n", reflect.TypeOf(val).Name())
|
||||
return nil
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user