fix code get jadwal dokter
This commit is contained in:
@@ -42,9 +42,48 @@ func SetHeader(cfg config.ConfigBpjs) *config.Header {
|
||||
time := time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
tstamp := timenow.Unix() - time.Unix()
|
||||
|
||||
cfg.Cons_id = os.Getenv("CONS_ID_DEV")
|
||||
cfg.User_key = os.Getenv("USER_KEY_DEV")
|
||||
cfg.Secret_key = os.Getenv("SECRET_KEY_DEV")
|
||||
// cfg.Cons_id = os.Getenv("CONS_ID_DEV")
|
||||
// cfg.User_key = os.Getenv("USER_KEY_DEV")
|
||||
// cfg.Secret_key = os.Getenv("SECRET_KEY_DEV")
|
||||
|
||||
cfg.Cons_id = os.Getenv("CONS_ID")
|
||||
cfg.User_key = os.Getenv("USER_KEY")
|
||||
cfg.Secret_key = os.Getenv("SECRET_KEY")
|
||||
|
||||
secret := []byte(cfg.Secret_key)
|
||||
message := []byte(cfg.Cons_id + "&" + fmt.Sprint(tstamp))
|
||||
hash := hmac.New(sha256.New, secret)
|
||||
hash.Write(message)
|
||||
// to lowercase hexits
|
||||
hex.EncodeToString(hash.Sum(nil))
|
||||
// to base64
|
||||
X_signature := base64.StdEncoding.EncodeToString(hash.Sum(nil))
|
||||
|
||||
header := &config.Header{
|
||||
ConsID: cfg.Cons_id,
|
||||
SecretKey: cfg.Secret_key,
|
||||
UserKey: cfg.User_key,
|
||||
TimeStamp: fmt.Sprint(tstamp),
|
||||
XSignature: X_signature,
|
||||
}
|
||||
|
||||
return header
|
||||
|
||||
}
|
||||
|
||||
func SetHeaderDev(cfg config.ConfigBpjs) *config.Header {
|
||||
|
||||
timenow := time.Now().UTC()
|
||||
time := time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
tstamp := timenow.Unix() - time.Unix()
|
||||
|
||||
cfg.Cons_id = os.Getenv("CONS_ID_DEV")
|
||||
cfg.User_key = os.Getenv("USER_KEY_DEV")
|
||||
cfg.Secret_key = os.Getenv("SECRET_KEY_DEV")
|
||||
|
||||
// cfg.Cons_id = os.Getenv("CONS_ID")
|
||||
// cfg.User_key = os.Getenv("USER_KEY")
|
||||
// cfg.Secret_key = os.Getenv("SECRET_KEY")
|
||||
|
||||
secret := []byte(cfg.Secret_key)
|
||||
message := []byte(cfg.Cons_id + "&" + fmt.Sprint(tstamp))
|
||||
|
||||
@@ -9,6 +9,45 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func GetJadwalDokterByDPJP(dpjp string) (string, error) {
|
||||
var id string
|
||||
errSelect := config.SatuDataDB.Debug().Raw(`select "id" from "data_pegawai" where "Code_dpjp" = ?`, dpjp).First(&id).Error
|
||||
if errSelect != nil {
|
||||
log.Printf("Failed get data : %v", errSelect)
|
||||
return "", errSelect
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func GetJadwalSpesialisDokterByID(id string) (string, error) {
|
||||
var spesialis string
|
||||
errSelect := config.SatuDataDB.Debug().Raw(`select "Spesialis" from "daftar_jadwal_dokter" where "Dokter" = ? order by "Spesialis"`, id).First(&spesialis).Error
|
||||
if errSelect != nil {
|
||||
log.Printf("Failed get data : %v", errSelect)
|
||||
return "", errSelect
|
||||
}
|
||||
return spesialis, nil
|
||||
}
|
||||
|
||||
func GetJadwalHariDokterBySpesialis(id string) ([]jadwal_dokter.ListHari, error) {
|
||||
var hari []jadwal_dokter.ListHari
|
||||
errSelect := config.SatuDataDB.Debug().Raw(`select distinct "id", "Spesialis", "Nama_hari" from "daftar_jadwal_dokter" where "Spesialis" = ? order by "id"`, id).Scan(&hari).Error
|
||||
if errSelect != nil {
|
||||
log.Printf("Failed get data : %v", errSelect)
|
||||
return nil, errSelect
|
||||
}
|
||||
return hari, nil
|
||||
}
|
||||
|
||||
func GetJadwalDokterByIDDokter(hari string) ([]string, error) {
|
||||
var spesialis []string
|
||||
errSelect := config.SatuDataDB.Debug().Raw(`select distinct "Spesialis" from "daftar_jadwal_dokter" where "Nama_hari" = ? order by "Spesialis"`, hari).Scan(&spesialis).Error
|
||||
if errSelect != nil {
|
||||
log.Printf("Failed get data : %v", errSelect)
|
||||
return nil, errSelect
|
||||
}
|
||||
return spesialis, nil
|
||||
}
|
||||
func GetJadwalDokterByDate(hari string) ([]string, error) {
|
||||
var spesialis []string
|
||||
errSelect := config.SatuDataDB.Debug().Raw(`select distinct "Spesialis" from "daftar_jadwal_dokter" where "Nama_hari" = ? order by "Spesialis"`, hari).Scan(&spesialis).Error
|
||||
|
||||
@@ -124,6 +124,7 @@ func GetJadwalDokter(c *gin.Context) {
|
||||
date, errParse := time.Parse("2006-01-02", tanggal)
|
||||
if errParse != nil {
|
||||
c.JSON(http.StatusInternalServerError, errParse)
|
||||
return
|
||||
}
|
||||
tanggal = date.AddDate(0, 0, 1).Format("2006-01-02")
|
||||
log.Println("Tanggal :", tanggal)
|
||||
@@ -132,6 +133,54 @@ func GetJadwalDokter(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
func GetDokterByDPJP(c *gin.Context) {
|
||||
dpjp := c.Param("dpjp")
|
||||
idDokter, err := dokter.GetJadwalDokterByDPJP(dpjp)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
spesialis, err := dokter.GetJadwalSpesialisDokterByID(idDokter)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
listHari, err := dokter.GetJadwalHariDokterBySpesialis(spesialis)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
var idSpesialis []string
|
||||
idSpesialis = append(idSpesialis, spesialis)
|
||||
|
||||
listSpesialis, err := dokter.GetSpesialisByID(idSpesialis)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
var res *jadwal_dokter.ResponseListHari
|
||||
|
||||
for _, v := range listSpesialis {
|
||||
for _, key := range listHari {
|
||||
res = &jadwal_dokter.ResponseListHari{
|
||||
IDSpesialis: v.ID,
|
||||
Kode: v.Kode,
|
||||
Spesialis: v.Spesialis,
|
||||
NamaHari: key.NamaHari,
|
||||
}
|
||||
}
|
||||
}
|
||||
// listSpesialis, err := dokter.GetSpesialisByID(listHari)
|
||||
// if err != nil {
|
||||
// c.JSON(http.StatusInternalServerError, err)
|
||||
// return
|
||||
// }
|
||||
c.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
func GetSpesialisByDate(c *gin.Context) {
|
||||
tanggal := c.Param("tanggal")
|
||||
date, err := time.Parse("2006-01-02", tanggal)
|
||||
|
||||
@@ -34,7 +34,7 @@ func InsertSuratKontrol(c *gin.Context) {
|
||||
|
||||
conf := config.ConfigBpjs{}
|
||||
|
||||
header := cfg.SetHeader(conf)
|
||||
header := cfg.SetHeaderDev(conf)
|
||||
|
||||
headers := map[string]string{
|
||||
"X-cons-id": header.ConsID,
|
||||
@@ -105,7 +105,7 @@ func UpdateSuratKontrol(c *gin.Context) {
|
||||
|
||||
conf := config.ConfigBpjs{}
|
||||
|
||||
header := cfg.SetHeader(conf)
|
||||
header := cfg.SetHeaderDev(conf)
|
||||
|
||||
headers := map[string]string{
|
||||
"X-cons-id": header.ConsID,
|
||||
@@ -140,50 +140,50 @@ func UpdateSuratKontrol(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
func DeleteSuratKontrol(c *gin.Context) {
|
||||
baseUrl := os.Getenv("BASEURL_BPJS_DEV")
|
||||
endpoint := os.Getenv("SURAT_KONTROL_RS_DEV")
|
||||
param := os.Getenv("UPDATE_SURAT_KONTROL")
|
||||
url := baseUrl + endpoint + param
|
||||
// func DeleteSuratKontrol(c *gin.Context) {
|
||||
// baseUrl := os.Getenv("BASEURL_BPJS_DEV")
|
||||
// endpoint := os.Getenv("SURAT_KONTROL_RS_DEV")
|
||||
// param := os.Getenv("UPDATE_SURAT_KONTROL")
|
||||
// url := baseUrl + endpoint + param
|
||||
|
||||
var req sk.RequestInsertRencanaKontrol
|
||||
// var req sk.RequestInsertRencanaKontrol
|
||||
|
||||
err := c.Bind(req)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
// err := c.Bind(req)
|
||||
// if err != nil {
|
||||
// log.Println(err)
|
||||
// c.JSON(http.StatusInternalServerError, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
conf := config.ConfigBpjs{}
|
||||
// conf := config.ConfigBpjs{}
|
||||
|
||||
header := cfg.SetHeader(conf)
|
||||
// header := cfg.SetHeaderDev(conf)
|
||||
|
||||
headers := map[string]string{
|
||||
"X-cons-id": header.ConsID,
|
||||
"X-timestamp": header.TimeStamp,
|
||||
"X-signature": header.XSignature,
|
||||
"user_key": header.UserKey,
|
||||
"Content-Type": "Application/x-www-form-urlencoded",
|
||||
}
|
||||
log.Println("Headers : ", headers)
|
||||
// headers := map[string]string{
|
||||
// "X-cons-id": header.ConsID,
|
||||
// "X-timestamp": header.TimeStamp,
|
||||
// "X-signature": header.XSignature,
|
||||
// "user_key": header.UserKey,
|
||||
// "Content-Type": "Application/x-www-form-urlencoded",
|
||||
// }
|
||||
// log.Println("Headers : ", headers)
|
||||
|
||||
request := &sk.RequestHeaderRencanaKontrol{
|
||||
Request: &sk.RequestDeleteRencanaKontrol{
|
||||
NoSuratKontrol: "",
|
||||
User: "",
|
||||
},
|
||||
}
|
||||
// request := &sk.RequestHeaderRencanaKontrol{
|
||||
// Request: &sk.RequestDeleteRencanaKontrol{
|
||||
// NoSuratKontrol: "",
|
||||
// User: "",
|
||||
// },
|
||||
// }
|
||||
|
||||
res, err := ResponseDeleteSuratKontrol(url, header, headers, request)
|
||||
if err != nil {
|
||||
log.Printf("Error making external API request: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
// res, err := ResponseDeleteSuratKontrol(url, header, headers, request)
|
||||
// if err != nil {
|
||||
// log.Printf("Error making external API request: %v", err)
|
||||
// c.JSON(http.StatusInternalServerError, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
c.JSON(http.StatusOK, res)
|
||||
}
|
||||
// c.JSON(http.StatusOK, res)
|
||||
// }
|
||||
|
||||
func GetNomorSuratKontrol(c *gin.Context) {
|
||||
baseUrl := os.Getenv("BASEURL_BPJS_DEV")
|
||||
|
||||
1
main.go
1
main.go
@@ -42,6 +42,7 @@ func main() {
|
||||
jadwalDokter := v1.Group("/jadwaldokter")
|
||||
{
|
||||
jadwalDokter.GET("/", jadwal_dokter.GetJadwalDokter)
|
||||
jadwalDokter.GET("/dpjp/:dpjp", jadwal_dokter.GetDokterByDPJP)
|
||||
jadwalDokter.GET("/tanggal/:tanggal", jadwal_dokter.GetSpesialisByDate)
|
||||
jadwalDokter.GET("/tanggal/:tanggal/spesialis/:spesialis", jadwal_dokter.GetDokterBySpesialis)
|
||||
}
|
||||
|
||||
@@ -51,3 +51,16 @@ type JadwalDokterTempSatuData struct {
|
||||
SubSpesialis string `gorm:"Sub_spesialis" json:"Sub_spesialis"`
|
||||
Status int `gorm:"Status" json:"Status"`
|
||||
}
|
||||
|
||||
type ResponseListHari struct {
|
||||
IDSpesialis int `json:"id_spesialis"`
|
||||
Kode string `json:"Kode"`
|
||||
Spesialis string `json:"Spesialis"`
|
||||
NamaHari string `json:"Nama_hari"`
|
||||
}
|
||||
|
||||
type ListHari struct {
|
||||
ID int `gorm:"column:id" json:"id"`
|
||||
Spesialis int `gorm:"column:Spesialis" json:"Spesialis"`
|
||||
NamaHari string `gorm:"column:Nama_hari" json:"Nama_hari"`
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package config
|
||||
|
||||
type ConfigBpjs struct {
|
||||
Cons_id string
|
||||
Secret_key string
|
||||
User_key string
|
||||
Cons_id string
|
||||
Secret_key string
|
||||
User_key string
|
||||
Cons_id_dev string
|
||||
Secret_key_dev string
|
||||
User_key_dev string
|
||||
}
|
||||
|
||||
type Header struct {
|
||||
|
||||
Reference in New Issue
Block a user