Author SHA256 Message Date
meninjar dev 36cf47313b update docker 2024-09-30 01:34:09 +00:00
mirza.millahsyafiq.0912 6efcb93aff Merge pull request 'bridging-bpjs' (#2) from bridging-bpjs into master
Reviewed-on: mirza.millahsyafiq.0912/bridging-rssa#2
2024-09-25 03:06:30 +00:00
mirza.millahsyafiq.0912 48b2615c9e fix insert daftar jadwal dokter and temp 2024-09-25 10:01:57 +07:00
mirza.millahsyafiq.0912 41a622fda4 fix insert daftar jadwal dokter 2024-09-24 11:45:22 +07:00
mirza.millahsyafiq.0912 d39d254be8 Merge branch 'master' of https://git.rssa.top/mirza.millahsyafiq.0911/bridging-rssa 2024-09-23 09:01:06 +07:00
mirza.millahsyafiq.0912 7ee1e022bc update structure 2024-09-23 09:00:24 +07:00
meninjar dev e0f84d3c15 docker compose 2024-09-23 01:48:30 +00:00
mirza.millahsyafiq.0912 f29ba21c97 udpate code 2024-09-23 08:16:30 +07:00
mirza.millahsyafiq.0912 09224ae2db fix decrypt 2024-09-19 15:02:59 +07:00
mirza.millahsyafiq.0912 51ab6569ad Merge branch 'master' of https://git.rssa.top/mirza.millahsyafiq.0912/bridging-rssa into master-mirza 2024-09-19 14:23:43 +07:00
mirza.millahsyafiq.0912 563b822ce5 update response 2024-09-19 14:22:30 +07:00
mirza.millahsyafiq.0912 377f45f5a9 update structure and bridging bpjs 2024-09-19 13:38:24 +07:00
meninjar dev a2f6aeac1d docker update 2024-09-18 07:32:08 +00:00
meninjar dev 8dac62584d docker project 2024-09-18 06:48:22 +00:00
mirza.millahsyafiq.0912 0b282c0e07 Merge pull request 'master-mirza' (#1) from master-mirza into master
Reviewed-on: mirza.millahsyafiq.0912/bridging-rssa#1
2024-09-18 02:47:42 +00:00
mirza.millahsyafiq.0912 e497eaeefc fix go version 2024-09-18 09:45:56 +07:00
mirza.millahsyafiq.0912 9ecb753abb fix models name 2024-09-18 08:26:29 +07:00
mirza.millahsyafiq.0912 1083a60f6f add subspesialis query 2024-09-18 07:42:46 +07:00
38 changed files with 1543 additions and 648 deletions
-1
View File
@@ -1 +0,0 @@
POSTGRES_DSN="postgres://sa:password@localhost:5432/postgres?sslmode=disable"
Executable
View File
+23 -23
View File
@@ -1,23 +1,23 @@
# ---> Go
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
# ---> Go
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
+22
View File
@@ -0,0 +1,22 @@
FROM golang:1.23-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod tidy
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
# RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/main .
COPY --from=builder /app/.env .
EXPOSE 8080
CMD ["./main"]
+2 -2
View File
@@ -1,2 +1,2 @@
# bridging-rssa
# bridging-rssa
+121
View File
@@ -0,0 +1,121 @@
package config
import (
"bridging-rssa/models/config"
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"log"
"os"
"time"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
var DB *gorm.DB
var localDB *gorm.DB
var SatuDataDB *gorm.DB
var SimrsDataDB *gorm.DB
var err error
func ConnectDB() {
// POSTGRE_DB_HOST=10.10.123.223
// POSTGRE_DB_PORT=5432
// POSTGRE_DB_NAME=simrsbackup
// POSTGRE_DB_USER=simtest
// POSTGRE_DB_PASS=12345
// hostDB := os.Getenv("DB_HOST")
// usernameDB := os.Getenv("DB_USERNAME")
// passwordDB := os.Getenv("DB_PASSWORD")
// dbName := os.Getenv("DB_NAME")
// portDB := os.Getenv("DB_PORT")
hostSatuData := os.Getenv("SATUDATA_HOST")
userNameSatuData := os.Getenv("SATUDATA_USERNAME")
passwordSatuData := os.Getenv("SATUDATA_PASSWORD")
dbNameSatuData := os.Getenv("SATUDATA_NAME")
portSatuData := os.Getenv("SATUDATA_PORT")
hostSimrsDB := os.Getenv("SIMRS_DB_HOST")
usernameSimrsDB := os.Getenv("SIMRS_DB_USERNAME")
passwordSimrsDB := os.Getenv("SIMRS_DB_PASSWORD")
dbNameSimrsDB := os.Getenv("SIMRS_DB_NAME")
portSimrsDB := os.Getenv("SIMRS_DB_PORT")
// local := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Jakarta", hostDB, usernameDB, passwordDB, dbName, portDB)
satuData := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Jakarta", hostSatuData, userNameSatuData, passwordSatuData, dbNameSatuData, portSatuData)
simrsData := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Jakarta", hostSimrsDB, usernameSimrsDB, passwordSimrsDB, dbNameSimrsDB, portSimrsDB)
// localDB, err = gorm.Open(postgres.Open(local), &gorm.Config{})
// if err != nil {
// log.Fatal("Failed to connect to Satu Data database: ", err)
// } else {
// log.Println("Successfully connected to the database")
// }
SatuDataDB, err = gorm.Open(postgres.Open(satuData), &gorm.Config{})
if err != nil {
log.Fatal("Failed to connect to Satu Data database: ", err)
} else {
log.Println("Successfully connected to the database")
}
SimrsDataDB, err = gorm.Open(postgres.Open(simrsData), &gorm.Config{})
if err != nil {
log.Fatal("Failed to connect to Satu Data database: ", err)
} else {
log.Println("Successfully connected to the database")
}
}
func SetHeader(cfg config.ConfigBpjs) (string, string, string, string, string) {
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")
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))
return cfg.Cons_id, cfg.Secret_key, cfg.User_key, fmt.Sprint(tstamp), X_signature
}
// func SetHeaderSatusehat(cfg config.ConfigSatuSehat) (string, string, string, string, string) {
// 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")
// 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))
// return cfg.Cons_id, cfg.Secret_key, cfg.User_key, fmt.Sprint(tstamp), X_signature
// }
-24
View File
@@ -1,24 +0,0 @@
package database
import (
"log"
"os"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
var DB *gorm.DB
var err error
func ConnectDB() {
dsn := os.Getenv("POSTGRES_DSN")
if dsn == "" {
log.Fatal("POSTGRES_DSN environment variable not set")
}
DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
log.Fatal("Failed to connect to database: ", err)
}
}
+42
View File
@@ -0,0 +1,42 @@
package dokter
import (
"bridging-rssa/config"
"bridging-rssa/models/dokter"
"errors"
"log"
"strconv"
"strings"
"gorm.io/gorm"
)
func GetDokter() ([]dokter.DaftarDokterRes, error) {
var listDokter []dokter.DaftarDokter
var res []dokter.DaftarDokterRes
result := config.SatuDataDB.Debug().Raw(`select "id", "HFIS_code" from "data_pegawai" where "HFIS_code" is not null`).Scan(&listDokter)
if result.Error != nil {
if !errors.Is(result.Error, gorm.ErrRecordNotFound) {
log.Fatalf("Error get data : %v", result.Error)
return nil, result.Error
}
log.Fatalf("Data kosong: %v", result.Error)
return nil, nil
}
log.Println("Data Pegawai: ", listDokter)
for _, v := range listDokter {
v.HfisCode = strings.TrimSpace(v.HfisCode)
hfisCode, err := strconv.Atoi(v.HfisCode)
if err != nil {
log.Fatalf("Failed Convert ID to Int %v", err)
return nil, err
}
res = append(res, dokter.DaftarDokterRes{
ID: v.ID,
HfisCode: hfisCode,
})
}
log.Println("Data Pegawai: ", res)
return res, nil
}
@@ -0,0 +1,53 @@
package dokter
import (
"bridging-rssa/config"
"bridging-rssa/models/bpjs/jadwal_dokter"
"log"
"strconv"
"github.com/google/uuid"
)
func DeleteJadwalDokter() error {
err := config.SatuDataDB.Debug().Exec(`truncate table "daftar_jadwal_dokter"`).Error
if err != nil {
log.Fatalf("Failed truncate data : %v", err)
return err
}
log.Println("Success truncate data")
return nil
}
func DeleteJadwalDokterTemp() error {
err := config.SatuDataDB.Debug().Exec(`truncate table "daftar_jadwal_dokter_temp"`).Error
if err != nil {
log.Fatalf("Failed truncate data : %v", err)
return err
}
log.Println("Success truncate data")
return nil
}
func InsertJadwalDokter(reqInsert *jadwal_dokter.JadwalDokterSatuData) error {
err := config.SatuDataDB.Debug().Exec(`insert into "daftar_jadwal_dokter" ("Hari", "Nama_hari", "Waktu", "Dokter", "Spesialis", "Sub_spesialis", "Status") values (?, ? ,?, ?, ?, ?, ?)`, reqInsert.Hari, reqInsert.NamaHari, reqInsert.Waktu, reqInsert.Dokter, reqInsert.Spesialis, reqInsert.SubSpesialis, reqInsert.Status).Error
if err != nil {
log.Fatalf("Failed insert data : %v", err)
return err
}
log.Println("Success insert data")
return nil
}
func InsertJadwalDokterTemp(reqInsert *jadwal_dokter.JadwalDokterSatuData) error {
spesialis := strconv.Itoa(reqInsert.Spesialis)
subspesialis := strconv.Itoa(reqInsert.SubSpesialis)
id := uuid.New()
err := config.SatuDataDB.Debug().Exec(`insert into "daftar_jadwal_dokter_temp" ("id", "Hari", "Nama_hari", "Waktu", "Dokter", "Spesialis", "Sub_spesialis", "Status") values (?, ?, ?, ?, ?, ?, ?, ?)`, id, reqInsert.Hari, reqInsert.NamaHari, reqInsert.Waktu, reqInsert.Dokter, spesialis, subspesialis, reqInsert.Status).Error
if err != nil {
log.Fatalf("Failed insert data : %v", err)
return err
}
log.Println("Success insert data")
return nil
}
+26
View File
@@ -0,0 +1,26 @@
package dokter
import (
"bridging-rssa/config"
"bridging-rssa/models/dokter"
"errors"
"log"
"gorm.io/gorm"
)
func GetSpesialis() ([]dokter.DaftarSpesialis, error) {
var daftarSpesialis []dokter.DaftarSpesialis
result := config.SatuDataDB.Debug().Raw(`select * from "daftar_spesialis"`).Find(&daftarSpesialis)
if result.Error != nil {
if !errors.Is(result.Error, gorm.ErrRecordNotFound) {
log.Fatalf("Error get data : %v", result.Error)
return nil, result.Error
}
log.Fatalf("Data kosong: %v", result.Error)
return daftarSpesialis, nil
}
return daftarSpesialis, nil
}
+27
View File
@@ -0,0 +1,27 @@
package dokter
import (
"bridging-rssa/config"
"bridging-rssa/models/dokter"
"errors"
"log"
"gorm.io/gorm"
)
func GetSubspesialis() ([]dokter.DaftarSubspesialis, error) {
var daftarSubspesialis []dokter.DaftarSubspesialis
result := config.SatuDataDB.Debug().Raw(`select * from "daftar_subspesialis"`).Find(&daftarSubspesialis)
if result.Error != nil {
if !errors.Is(result.Error, gorm.ErrRecordNotFound) {
log.Fatalf("Error get data : %v", result.Error)
return nil, result.Error
}
log.Fatalf("Data kosong: %v", result.Error)
return daftarSubspesialis, nil
}
log.Println(daftarSubspesialis)
return daftarSubspesialis, nil
}
+41
View File
@@ -0,0 +1,41 @@
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: api-rssa
restart: always
ports:
- 8080:8080
volumes:
- .:/app
environment:
# DATABASE SIMRS V3.0
- SIMRS_DB_HOST=10.10.123.223
- SIMRS_DB_NAME=simrsbackup
- SIMRS_DB_USERNAME=simtest
- SIMRS_DB_PASSWORD=12345
- SIMRS_DB_PORT=5432
# DATABASE SATU DATA
- SATUDATA_HOST=10.10.123.165
- SATUDATA_USERNAME=stim
- SATUDATA_PASSWORD=stim*RS54
- SATUDATA_NAME=satu_db
- SATUDATA_PORT=5000
# BPJS
- BASEURL_BPJS=https://apijkn.bpjs-kesehatan.go.id
- CONS_ID=5257
- USER_KEY=4cf1cbef8c008440bbe9ef9ba789e482
- SECRET_KEY=1bV363512D
# SERVICE ANTROL
- ANTREAN_RS=antreanrs
# BPJS VCLAIM
- VCALIM_RS=vclaim-rest
# BPJS PCARE
- PCARE_RS=pcare-rest
# BPJS ICARE
- PCARE_APLICARE=ihs
# SATUSEHAT
- OR=10.10.123.165
+141 -79
View File
@@ -1,79 +1,141 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs
import "github.com/swaggo/swag"
const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/v1/user": {
"get": {
"description": "returs list of all users from the database",
"tags": [
"Users"
],
"summary": "return list of all",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.User"
}
}
}
}
}
},
"definitions": {
"models.User": {
"type": "object",
"properties": {
"agama": {
"type": "string"
},
"alamat": {
"type": "string"
},
"id": {
"type": "string"
},
"jenis_kelamin": {
"type": "string"
},
"nama": {
"type": "string"
},
"umur": {
"type": "integer"
}
}
}
}
}`
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1",
Host: "localhost:8080",
BasePath: "",
Schemes: []string{},
Title: "Crud User",
Description: "Rest API CRUD User",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}
func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs
import "github.com/swaggo/swag"
const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/user": {
"get": {
"description": "returs list of all users from the database",
"tags": [
"Users"
],
"summary": "return list of all",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.User"
}
}
}
}
},
"/api/user/create": {
"post": {
"description": "Insert Data User",
"tags": [
"Users"
],
"summary": "Insert Data User",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Response"
}
}
}
}
},
"/api/user/delete/:id": {
"delete": {
"description": "Delete Data User",
"tags": [
"Users"
],
"summary": "Delete Data User",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Response"
}
}
}
}
},
"/api/user/update/:id": {
"put": {
"description": "Update Data User",
"tags": [
"Users"
],
"summary": "Update Data User",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Response"
}
}
}
}
}
},
"definitions": {
"models.Response": {
"type": "object",
"properties": {
"response_code": {
"type": "string"
},
"response_message": {
"type": "string"
}
}
},
"models.User": {
"type": "object",
"properties": {
"agama": {
"type": "string"
},
"alamat": {
"type": "string"
},
"id": {
"type": "string"
},
"jenis_kelamin": {
"type": "string"
},
"nama": {
"type": "string"
},
"umur": {
"type": "integer"
}
}
}
}
}`
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1",
Host: "localhost:8080",
BasePath: "",
Schemes: []string{},
Title: "Crud User",
Description: "Rest API CRUD User",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}
func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
+46
View File
@@ -0,0 +1,46 @@
package docs
import (
"crypto/aes"
"crypto/cipher"
"crypto/sha256"
"encoding/base64"
"log"
lzstring "github.com/daku10/go-lz-string"
)
func StringDecrypt(key string, encryptedString string) (string, error) {
keyHash := sha256.Sum256([]byte(key))
keyHashBytes := keyHash[:]
iv := keyHashBytes[:16]
encryptedBytes, err := base64.StdEncoding.DecodeString(encryptedString)
if err != nil {
return "", err
}
block, err := aes.NewCipher(keyHashBytes)
if err != nil {
return "", err
}
mode := cipher.NewCBCDecrypter(block, iv)
decrypted := make([]byte, len(encryptedBytes))
mode.CryptBlocks(decrypted, encryptedBytes)
decrypted = RemovePKCS7Padding(decrypted)
dataResp, err := lzstring.DecompressFromEncodedURIComponent(string(decrypted))
if err != nil {
log.Fatalf("Error decompress: %v", err)
}
return dataResp, nil
}
func RemovePKCS7Padding(data []byte) []byte {
paddingLength := int(data[len(data)-1])
return data[:len(data)-paddingLength]
}
+115 -53
View File
@@ -1,54 +1,116 @@
{
"swagger": "2.0",
"info": {
"description": "Rest API CRUD User",
"title": "Crud User",
"contact": {},
"version": "1"
},
"host": "localhost:8080",
"paths": {
"/api/v1/user": {
"get": {
"description": "returs list of all users from the database",
"tags": [
"Users"
],
"summary": "return list of all",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.User"
}
}
}
}
}
},
"definitions": {
"models.User": {
"type": "object",
"properties": {
"agama": {
"type": "string"
},
"alamat": {
"type": "string"
},
"id": {
"type": "string"
},
"jenis_kelamin": {
"type": "string"
},
"nama": {
"type": "string"
},
"umur": {
"type": "integer"
}
}
}
}
{
"swagger": "2.0",
"info": {
"description": "Rest API CRUD User",
"title": "Crud User",
"contact": {},
"version": "1"
},
"host": "localhost:8080",
"paths": {
"/api/user": {
"get": {
"description": "returs list of all users from the database",
"tags": [
"Users"
],
"summary": "return list of all",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.User"
}
}
}
}
},
"/api/user/create": {
"post": {
"description": "Insert Data User",
"tags": [
"Users"
],
"summary": "Insert Data User",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Response"
}
}
}
}
},
"/api/user/delete/:id": {
"delete": {
"description": "Delete Data User",
"tags": [
"Users"
],
"summary": "Delete Data User",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Response"
}
}
}
}
},
"/api/user/update/:id": {
"put": {
"description": "Update Data User",
"tags": [
"Users"
],
"summary": "Update Data User",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Response"
}
}
}
}
}
},
"definitions": {
"models.Response": {
"type": "object",
"properties": {
"response_code": {
"type": "string"
},
"response_message": {
"type": "string"
}
}
},
"models.User": {
"type": "object",
"properties": {
"agama": {
"type": "string"
},
"alamat": {
"type": "string"
},
"id": {
"type": "string"
},
"jenis_kelamin": {
"type": "string"
},
"nama": {
"type": "string"
},
"umur": {
"type": "integer"
}
}
}
}
}
+75 -35
View File
@@ -1,35 +1,75 @@
definitions:
models.User:
properties:
agama:
type: string
alamat:
type: string
id:
type: string
jenis_kelamin:
type: string
nama:
type: string
umur:
type: integer
type: object
host: localhost:8080
info:
contact: {}
description: Rest API CRUD User
title: Crud User
version: "1"
paths:
/api/v1/user:
get:
description: returs list of all users from the database
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.User'
summary: return list of all
tags:
- Users
swagger: "2.0"
definitions:
models.Response:
properties:
response_code:
type: string
response_message:
type: string
type: object
models.User:
properties:
agama:
type: string
alamat:
type: string
id:
type: string
jenis_kelamin:
type: string
nama:
type: string
umur:
type: integer
type: object
host: localhost:8080
info:
contact: {}
description: Rest API CRUD User
title: Crud User
version: "1"
paths:
/api/user:
get:
description: returs list of all users from the database
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.User'
summary: return list of all
tags:
- Users
/api/user/create:
post:
description: Insert Data User
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.Response'
summary: Insert Data User
tags:
- Users
/api/user/delete/:id:
delete:
description: Delete Data User
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.Response'
summary: Delete Data User
tags:
- Users
/api/user/update/:id:
put:
description: Update Data User
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.Response'
summary: Update Data User
tags:
- Users
swagger: "2.0"
+17
View File
@@ -0,0 +1,17 @@
package utils
import "log"
// Function to convert Kode to ID
func KodeToIDConverter(kode string, kodeDokter map[string]int) int {
log.Println("Kode :", kode)
id := kodeDokter[kode]
log.Println("ID :", id)
return id
}
// Convert Hfis Code to ID Satu Data
func HfisCodeToIDConverter(kode int, kodeDokter map[int]string) string {
id := kodeDokter[kode]
return id
}
Executable
View File
BIN
View File
Binary file not shown.
-132
View File
@@ -1,132 +0,0 @@
package ginHandlers
import (
"encoding/json"
"net/http"
"tes-rssa/database"
"tes-rssa/models"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
// GetAllUser returs list of all users from the database
// @Summary return list of all
// @Description returs list of all users from the database
// @Tags Users
// @Success 200 {object} models.User
// @Router /api/v1/user [get]
func GetAllUser(c *gin.Context) {
var users []models.User
result := database.DB.Debug().Raw(`SELECT * FROM "user"`).Find(&users)
if result.Error != nil {
if result.Error == gorm.ErrRecordNotFound {
c.JSON(http.StatusNotFound, result.Error)
} else {
c.JSON(http.StatusInternalServerError, result.Error)
}
return
}
c.JSON(http.StatusOK, users)
}
func GetUserId(c *gin.Context) {
id := c.Request.URL.Query()
var user models.User
query := `select * from "user" where id = ?`
result := database.DB.Debug().Raw(query, id).Find(&user)
if result.Error != nil {
if result.Error == gorm.ErrRecordNotFound {
c.JSON(http.StatusNotFound, result.Error)
} else {
c.JSON(http.StatusInternalServerError, result.Error)
}
return
}
c.JSON(http.StatusOK, user)
}
func CreateUser(c *gin.Context) {
var u models.InsertUser
err := json.NewDecoder(c.Request.Body).Decode(&u)
if err != nil {
c.JSON(http.StatusBadRequest, "Invalid request payload")
return
}
insertData := &models.InsertUser{
Nama: u.Nama,
Umur: u.Umur,
Alamat: u.Alamat,
Agama: u.Agama,
JenisKelamin: u.JenisKelamin,
}
queryInsert := `INSERT INTO "user" (nama, umur, alamat, agama, jenis_kelamin) VALUES (?, ?, ?, ?, ?)`
result := database.DB.Debug().Exec(queryInsert, insertData.Nama, insertData.Umur, insertData.Alamat, insertData.Agama, insertData.JenisKelamin)
if result.Error != nil {
c.JSON(http.StatusInternalServerError, result.Error)
return
}
res := &models.Response{
ResponseCode: "00",
ResponseMessage: "Berhasil Insert Data",
}
c.JSON(http.StatusOK, res)
}
func UpdateUser(c *gin.Context) {
id := c.Request.URL.Query()
var u models.UpdateUser
err := json.NewDecoder(c.Request.Body).Decode(&u)
if err != nil {
c.JSON(http.StatusBadRequest, "Invalid request payload")
return
}
update := &models.UpdateUser{
Nama: u.Nama,
Umur: u.Umur,
Alamat: u.Alamat,
Agama: u.Agama,
JenisKelamin: u.JenisKelamin,
}
res := &models.Response{
ResponseCode: "00",
ResponseMessage: "Berhasil Update Data",
}
result := database.DB.Debug().Exec(`UPDATE "user" SET nama = ?, umur = ?, alamat = ?, agama = ?, jenis_kelamin = ? WHERE ID = ?`, update.Nama, update.Umur, update.Alamat, update.Agama, update.JenisKelamin, id)
if result.RowsAffected == 0 {
res = &models.Response{
ResponseCode: "99",
ResponseMessage: "Gagal update data",
}
} else if result.Error != nil {
c.JSON(http.StatusInternalServerError, result.Error)
return
}
c.JSON(http.StatusOK, res)
}
func DeleteUser(c *gin.Context) {
id := c.Request.URL.Query()
res := &models.Response{
ResponseCode: "00",
ResponseMessage: "Berhasil Delete Data",
}
result := database.DB.Debug().Exec(`DELETE from "user" where id = ?`, id)
if result.RowsAffected == 0 {
res = &models.Response{
ResponseCode: "99",
ResponseMessage: "Gagal delete data",
}
} else if result.Error != nil {
c.JSON(http.StatusInternalServerError, result.Error)
return
}
c.JSON(http.StatusOK, res)
}
+15 -18
View File
@@ -1,28 +1,29 @@
module tes-rssa
module bridging-rssa
go 1.22.0
toolchain go1.23.1
go 1.23.0
require (
github.com/gorilla/mux v1.8.1
github.com/andrean360/bridging-bpjs-go v1.0.1
github.com/daku10/go-lz-string v0.0.6
github.com/gin-gonic/gin v1.10.0
github.com/joho/godotenv v1.5.1
gorm.io/driver/mysql v1.5.7
github.com/mashingan/smapping v0.1.19
github.com/rs/cors v1.11.1
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.3
gorm.io/gorm v1.25.11
)
require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.2.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/bytedance/sonic v1.12.2 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.10.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
@@ -30,7 +31,6 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.1 // indirect
github.com/go-swagger/go-swagger v0.31.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
@@ -42,13 +42,12 @@ require (
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/rs/cors v1.11.1 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/gin-swagger v1.6.0 // indirect
github.com/swaggo/swag v1.16.3 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.10.0 // indirect
@@ -58,13 +57,11 @@ require (
golang.org/x/sys v0.25.0 // indirect
golang.org/x/tools v0.25.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/google/uuid v1.6.0
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
golang.org/x/text v0.18.0 // indirect
+31 -35
View File
@@ -1,31 +1,26 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/PuerkitoBio/purell v1.2.1 h1:QsZ4TjvwiMpat6gBCBxEQI0rcS9ehtkKtSpiUnd9N28=
github.com/PuerkitoBio/purell v1.2.1/go.mod h1:ZwHcC/82TOaovDi//J/804umJFFmbOHPngi8iYYv/Eo=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
github.com/andrean360/bridging-bpjs-go v1.0.1 h1:06eJ23vcI2tNyPryr8p3jxJ+Vy4P4/nneNPWuUrgnLg=
github.com/andrean360/bridging-bpjs-go v1.0.1/go.mod h1:sRBG5zI4Ky/UMCI7u/QuMTlrzREV2UQn043lhrejfFE=
github.com/bytedance/sonic v1.12.2 h1:oaMFuRTpMHYLpCntGca65YWt5ny+wAceDERTkT2L9lg=
github.com/bytedance/sonic v1.12.2/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM=
github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/daku10/go-lz-string v0.0.6 h1:aO8FFp4QPuNp7+WNyh1DyNjGF3UbZu95tUv9xOZNsYQ=
github.com/daku10/go-lz-string v0.0.6/go.mod h1:Vk++rSG3db8HXJaHEAbxiy/ukjTmPBw/iI+SrVZDzfs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4=
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
@@ -38,23 +33,21 @@ github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9Z
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/go-swagger/go-swagger v0.31.0 h1:H8eOYQnY2u7vNKWDNykv2xJP3pBhRG/R+SOCAmKrLlc=
github.com/go-swagger/go-swagger v0.31.0/go.mod h1:WSigRRWEig8zV6t6Sm8Y+EmUjlzA/HoaZJ5edupq7po=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
@@ -77,13 +70,20 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mashingan/smapping v0.1.19 h1:SsEtuPn2UcM1croIupPtGLgWgpYRuS0rSQMvKD9g2BQ=
github.com/mashingan/smapping v0.1.19/go.mod h1:FjfiwFxGOuNxL/OT1WcrNAwTPx0YJeg5JiXwBB1nyig=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -92,6 +92,10 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA=
github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -102,6 +106,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE=
github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg=
github.com/swaggo/gin-swagger v1.6.0 h1:y8sxvQ3E20/RCyrXeFfg60r6H0Z+SwpTjMYsMm+zy8M=
@@ -113,16 +119,15 @@ github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.10.0 h1:S3huipmSclq3PJMNe76NGwkBR504WFkQ5dhzWzP8ZW8=
golang.org/x/arch v0.10.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
@@ -131,8 +136,6 @@ golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -151,8 +154,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -161,21 +162,16 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg=
gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
@@ -0,0 +1,131 @@
package jadwal_dokter
import (
cfg "bridging-rssa/config"
"bridging-rssa/database/satu_data/dokter"
"bridging-rssa/docs/utils"
"bridging-rssa/models/bpjs/jadwal_dokter"
"bridging-rssa/models/config"
"log"
"net/http"
"os"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
func GetJadwalDokter(c *gin.Context) {
baseUrl := os.Getenv("BASEURL_BPJS")
endpoint := os.Getenv("ANTREAN_RS")
url := baseUrl + endpoint
errTruncate := dokter.DeleteJadwalDokter()
if errTruncate != nil {
log.Fatal(errTruncate)
c.JSON(http.StatusInternalServerError, errTruncate)
}
errTruncateTemp := dokter.DeleteJadwalDokterTemp()
if errTruncateTemp != nil {
log.Fatal(errTruncateTemp)
c.JSON(http.StatusInternalServerError, errTruncateTemp)
}
// Select from daftar spesialis
spesialis, err := dokter.GetSpesialis()
if err != nil {
c.JSON(http.StatusInternalServerError, err)
}
var listIdSpesialis = make(map[string]int)
for _, kodeDokter := range spesialis {
listIdSpesialis[kodeDokter.Kode] = kodeDokter.ID
}
subspesialis, err := dokter.GetSubspesialis()
if err != nil {
c.JSON(http.StatusInternalServerError, err)
}
var listIdSubspesialis = make(map[string]int)
for _, kodeDokter := range subspesialis {
listIdSubspesialis[kodeDokter.Kode] = kodeDokter.ID
}
listDokter, err := dokter.GetDokter()
if err != nil {
c.JSON(http.StatusInternalServerError, err)
}
var listIddokter = make(map[int]string)
for _, kodeDokter := range listDokter {
listIddokter[kodeDokter.HfisCode] = kodeDokter.ID
}
conf := config.ConfigBpjs{}
cons_id, secretKey, User_key, tstamp, X_signature := cfg.SetHeader(conf)
headers := map[string]string{
"X-cons-id": cons_id,
"X-timestamp": tstamp,
"X-signature": X_signature,
"user_key": User_key,
}
var res *[]jadwal_dokter.ListDokter
log.Println("Headers : ", headers)
// var reqSelect *jadwal_dokter.JadwalDokterSatuData
var reqInsert *jadwal_dokter.JadwalDokterSatuData
for _, value := range spesialis {
tanggal := time.Now().Format("2006-01-02")
for i := 0; i < 7; i++ {
kdPoly := value.Kode
res, err = JadwalDokterGetResponse(url, secretKey, cons_id, User_key, tstamp, X_signature, kdPoly, tanggal, headers)
if err != nil {
log.Fatalf("Error making external API request: %v", err)
c.JSON(http.StatusInternalServerError, err)
}
if res == nil {
log.Println("Skip Proses")
continue
}
for _, v := range *res {
idSpesialis := utils.KodeToIDConverter(v.KodePoli, listIdSpesialis)
idSubspesialis := utils.KodeToIDConverter(v.KodeSubspesialis, listIdSubspesialis)
idDokter := utils.HfisCodeToIDConverter(v.KodeDokter, listIddokter)
reqInsert = &jadwal_dokter.JadwalDokterSatuData{
Hari: v.Hari,
NamaHari: v.NamaHari,
Waktu: v.Jadwal,
Dokter: idDokter,
Spesialis: idSpesialis,
SubSpesialis: idSubspesialis,
Status: 1, // When available always set to 1
}
if reqInsert.Dokter != "" {
errInsert := dokter.InsertJadwalDokter(reqInsert)
if errInsert != nil {
log.Println(errInsert)
c.JSON(http.StatusInternalServerError, errInsert)
}
} else {
reqInsert.Dokter = strconv.Itoa(v.KodeDokter)
errInsertTemp := dokter.InsertJadwalDokterTemp(reqInsert)
if errInsertTemp != nil {
log.Println(errInsertTemp)
c.JSON(http.StatusInternalServerError, errInsertTemp)
}
}
}
date, errParse := time.Parse("2006-01-02", tanggal)
if errParse != nil {
c.JSON(http.StatusInternalServerError, errParse)
}
tanggal = date.AddDate(0, 0, 1).Format("2006-01-02")
log.Println("Tanggal :", tanggal)
}
}
c.JSON(http.StatusOK, res)
}
+71
View File
@@ -0,0 +1,71 @@
package jadwal_dokter
import (
"bridging-rssa/docs"
"bridging-rssa/models/bpjs/jadwal_dokter"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
)
func JadwalDokterGetResponse(url string, secretKey string, cons_id string, User_keys string, tstamp string, X_signature string, kdPoly string, tanggal string, headers map[string]string) (*[]jadwal_dokter.ListDokter, error) {
param := "/jadwaldokter/kodepoli/" + kdPoly + "/tanggal/" + tanggal
url += param
log.Println("URL", url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatalf("Error creating request: %v", err)
}
for key, value := range headers {
req.Header.Set(key, value)
}
log.Println("REQ", req.Header)
client := http.Client{}
response, err := client.Do(req)
if err != nil {
log.Fatalf("Error making external API request: %v", err)
}
log.Println("RESPONSE: ", response)
key := cons_id + secretKey + tstamp
res, err := io.ReadAll(response.Body)
if err != nil {
fmt.Println(err)
}
var jadwalDokterRaw jadwal_dokter.JadwalDokterRaw
err = json.Unmarshal([]byte(res), &jadwalDokterRaw)
if err != nil {
log.Fatalf("Error Unmarshaling: %v", err)
}
if jadwalDokterRaw.MetaData.Code == 201 {
log.Println("No Data Found")
return nil, nil
}
dataResp, err := docs.StringDecrypt(key, jadwalDokterRaw.Response)
if err != nil {
log.Fatalf("Error Decrypt: %v", err)
log.Println("res: ", dataResp)
}
var listDokter []jadwal_dokter.ListDokter
log.Println("dataresp: ", dataResp)
// err = mapstructure.Decode(dataResp, &listDokter)
err = json.Unmarshal([]byte(dataResp), &listDokter)
if err != nil {
log.Fatalf("Error Decode: %v", err)
}
log.Println("res: ", &listDokter)
return &listDokter, nil
}
+24
View File
@@ -0,0 +1,24 @@
package bpjs
import (
"bridging-rssa/config"
"bridging-rssa/models/dokter"
"net/http"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
func GetAllSubspesialis(c *gin.Context) {
var subspesialis []dokter.DaftarSubspesialis
result := config.SatuDataDB.Debug().Raw(`SELECT * FROM "daftar_subspesialis"`).Find(&subspesialis)
if result.Error != nil {
if result.Error == gorm.ErrRecordNotFound {
c.JSON(http.StatusNotFound, result.Error)
} else {
c.JSON(http.StatusInternalServerError, result.Error)
}
return
}
c.JSON(http.StatusOK, subspesialis)
}
+39
View File
@@ -0,0 +1,39 @@
package Vclaim
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"log"
"time"
)
type ConfigBpjs struct {
Cons_id string
Secret_key string
User_key string
}
func SetHeader(cfg ConfigBpjs) (string, string, string, string, string) {
timenow := time.Now().UTC()
t, err := time.Parse(time.RFC3339, "1970-01-01T00:00:00Z")
if err != nil {
log.Fatal(err)
}
tstamp := timenow.Unix() - t.Unix()
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))
return cfg.Cons_id, cfg.Secret_key, cfg.User_key, fmt.Sprint(tstamp), X_signature
}
+50
View File
@@ -0,0 +1,50 @@
package Vclaim
import (
"crypto/aes"
"crypto/cipher"
"crypto/sha256"
"encoding/base64"
"errors"
"bridging-rssa/docs"
lzstring "github.com/daku10/go-lz-string"
)
func ResponseVclaim(encrypted string, key string) (string, error) {
cipherText, err := base64.StdEncoding.DecodeString(encrypted)
if err != nil {
return "", err
}
hash := sha256.Sum256([]byte(key))
block, err := aes.NewCipher(hash[:])
if err != nil {
return "", err
}
if len(cipherText) < aes.BlockSize {
return "", errors.New("cipherText too short")
}
iv := hash[:aes.BlockSize]
if len(cipherText)%aes.BlockSize != 0 {
return "", errors.New("cipherText is not a multiple of the block size")
}
mode := cipher.NewCBCDecrypter(block, iv)
mode.CryptBlocks(cipherText, cipherText)
// cipherText, _ = pkcs7.Unpad(cipherText, aes.BlockSize)
cipherText = docs.RemovePKCS7Padding(cipherText)
data, err := lzstring.DecompressFromEncodedURIComponent(string(cipherText))
// data, err := helper.DecompressFromEncodedUriComponent(string(cipherText))
if err != nil {
return "", err
}
return data, nil
}
+122
View File
@@ -0,0 +1,122 @@
package Vclaim
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"github.com/mashingan/smapping"
)
type Respon_MentahDTO struct {
MetaData struct {
Code string `json:"code"`
Message string `json:"message"`
} `json:"metaData"`
Response string `json:"response"`
}
type Respon_DTO struct {
MetaData struct {
Code string `json:"code"`
Message string `json:"message"`
} `json:"metaData"`
Response interface{} `json:"response"`
}
func GetRequest(endpoint string, cfg interface{}) interface{} {
conf := ConfigBpjs{}
err := smapping.FillStruct(&conf, smapping.MapFields(&cfg))
if err != nil {
log.Fatalf("Failed map %v: ", err)
}
cons_id, Secret_key, User_key, tstamp, X_signature := SetHeader(conf)
req, _ := http.NewRequest("GET", endpoint, nil)
req.Header.Add("Content-Type", "Application/x-www-form-urlencoded")
req.Header.Add("X-cons-id", cons_id)
req.Header.Add("X-timestamp", tstamp)
req.Header.Add("X-signature", X_signature)
req.Header.Add("user_key", User_key)
res, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err)
}
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
}
var resp_mentah Respon_MentahDTO
var resp Respon_DTO
json.Unmarshal([]byte(body), &resp_mentah)
resp_decrypt, _ := ResponseVclaim(string(resp_mentah.Response), string(cons_id+Secret_key+tstamp))
resp.MetaData = resp_mentah.MetaData
json.Unmarshal([]byte(resp_decrypt), &resp.Response)
return &resp
}
func PostRequest(endpoint string, cfg interface{}, data interface{}) interface{} {
conf := ConfigBpjs{}
err := smapping.FillStruct(&conf, smapping.MapFields(&cfg))
if err != nil {
log.Fatalf("Failed map %v: ", err)
}
cons_id, Secret_key, User_key, tstamp, X_signature := SetHeader(conf)
var buf bytes.Buffer
err = json.NewEncoder(&buf).Encode(data)
if err != nil {
log.Fatal(err)
}
req, _ := http.NewRequest("POST", endpoint, &buf)
req.Header.Add("Content-Type", "Application/x-www-form-urlencoded")
req.Header.Add("X-cons-id", cons_id)
req.Header.Add("X-timestamp", tstamp)
req.Header.Add("X-signature", X_signature)
req.Header.Add("user_key", User_key)
res, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(body))
var resp_mentah Respon_MentahDTO
var resp Respon_DTO
json.Unmarshal([]byte(body), &resp_mentah)
resp_decrypt, _ := ResponseVclaim(string(resp_mentah.Response), string(cons_id+Secret_key+tstamp))
resp.MetaData = resp_mentah.MetaData
json.Unmarshal([]byte(resp_decrypt), &resp.Response)
return &resp
}
-154
View File
@@ -1,154 +0,0 @@
package handlers
import (
"encoding/json"
"fmt"
"net/http"
"tes-rssa/database"
"tes-rssa/models"
"github.com/gorilla/mux"
"gorm.io/gorm"
)
func GetUser(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
fmt.Println(vars)
column := vars["req"]
value := r.URL.Query().Get("value")
var user []models.User
query := fmt.Sprintf(`select * from "user" where %s like ?`, column)
result := database.DB.Debug().Raw(query, "%"+value+"%").Find(&user)
if result.Error != nil {
if result.Error == gorm.ErrRecordNotFound {
http.Error(w, "User not found", http.StatusNotFound)
} else {
http.Error(w, result.Error.Error(), http.StatusInternalServerError)
}
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(user)
}
func GetUserId(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
var user models.User
query := `select * from "user" where id = ?`
result := database.DB.Debug().Raw(query, id).Find(&user)
if result.Error != nil {
if result.Error == gorm.ErrRecordNotFound {
http.Error(w, "User not found", http.StatusNotFound)
} else {
http.Error(w, result.Error.Error(), http.StatusInternalServerError)
}
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(user)
}
func GetAllUser(w http.ResponseWriter, r *http.Request) {
var users []models.User
result := database.DB.Debug().Raw(`SELECT * FROM "user"`).Find(&users)
if result.Error != nil {
if result.Error == gorm.ErrRecordNotFound {
http.Error(w, "Users not found", http.StatusNotFound)
} else {
http.Error(w, result.Error.Error(), http.StatusInternalServerError)
}
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(users)
}
func CreateUser(w http.ResponseWriter, r *http.Request) {
var u models.InsertUser
err := json.NewDecoder(r.Body).Decode(&u)
if err != nil {
http.Error(w, "Invalid request payload", http.StatusBadRequest)
return
}
insertData := &models.InsertUser{
Nama: u.Nama,
Umur: u.Umur,
Alamat: u.Alamat,
Agama: u.Agama,
JenisKelamin: u.JenisKelamin,
}
queryInsert := `INSERT INTO "user" (nama, umur, alamat, agama, jenis_kelamin) VALUES (?, ?, ?, ?, ?)`
result := database.DB.Debug().Exec(queryInsert, insertData.Nama, insertData.Umur, insertData.Alamat, insertData.Agama, insertData.JenisKelamin)
if result.Error != nil {
http.Error(w, result.Error.Error(), http.StatusInternalServerError)
return
}
res := &models.Response{
ResponseCode: "00",
ResponseMessage: "Berhasil Insert Data",
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(res)
}
func UpdateUser(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
var u models.UpdateUser
err := json.NewDecoder(r.Body).Decode(&u)
if err != nil {
http.Error(w, "Invalid request payload", http.StatusBadRequest)
return
}
update := &models.UpdateUser{
Nama: u.Nama,
Umur: u.Umur,
Alamat: u.Alamat,
Agama: u.Agama,
JenisKelamin: u.JenisKelamin,
}
res := &models.Response{
ResponseCode: "00",
ResponseMessage: "Berhasil Update Data",
}
result := database.DB.Debug().Exec(`UPDATE "user" SET nama = ?, umur = ?, alamat = ?, agama = ?, jenis_kelamin = ? WHERE ID = ?`, update.Nama, update.Umur, update.Alamat, update.Agama, update.JenisKelamin, id)
if result.RowsAffected == 0 {
res = &models.Response{
ResponseCode: "99",
ResponseMessage: "Gagal update data",
}
} else if result.Error != nil {
http.Error(w, result.Error.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(res)
}
func DeleteUser(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
result := database.DB.Debug().Exec(`DELETE from "user" where id = ?`, id)
if result.Error != nil {
http.Error(w, result.Error.Error(), http.StatusInternalServerError)
return
}
res := &models.Response{
ResponseCode: "00",
ResponseMessage: "Berhasil Delete Data",
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(res)
}
+54 -60
View File
@@ -1,60 +1,54 @@
package main
import (
"log"
"net/http"
"tes-rssa/database"
"tes-rssa/ginHandlers"
_ "tes-rssa/docs"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/rs/cors"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @title Crud User
// @version 1
// @Description Rest API CRUD User
// @host localhost:8080
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
database.ConnectDB()
r := gin.Default()
v1 := r.Group("/api")
user := v1.Group("/user")
{
user.GET("/", ginHandlers.GetAllUser)
user.GET("/{id}", ginHandlers.GetUserId)
user.POST("/create")
user.PUT("/update/{id}")
user.DELETE("/delete/{id}")
}
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
err = r.Run()
if err != nil {
log.Fatal(err)
}
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"}, // Or specify the domain(s) allowed
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowedHeaders: []string{"Content-Type"},
AllowCredentials: true,
})
handler := c.Handler(r)
log.Println("Server berjalan di port 8002")
log.Fatal(http.ListenAndServe(":8002", handler))
}
package main
import (
"bridging-rssa/config"
"bridging-rssa/handlers/bpjs"
"bridging-rssa/handlers/bpjs/jadwal_dokter"
"log"
_ "bridging-rssa/docs"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @title Crud User
// @version 1
// @Description Rest API CRUD User
// @host localhost:8080
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
config.ConnectDB()
r := gin.Default()
v1 := r.Group("/api")
subspesialis := v1.Group("/subspesialis")
{
subspesialis.GET("/", bpjs.GetAllSubspesialis)
}
jadwalDokter := v1.Group("/jadwaldokter")
{
jadwalDokter.GET("/", jadwal_dokter.GetJadwalDokter)
}
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
r.POST("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
r.PUT("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
r.DELETE("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
log.Println("JALAN DI PORT : 8081")
err = r.Run(":8081")
if err != nil {
log.Fatal(err)
}
}
@@ -0,0 +1,53 @@
package jadwal_dokter
type JadwalDokterRaw struct {
Response string `json:"response"`
MetaData Metadata `json:"metadata"`
}
type Metadata struct {
Code int `json:"code"`
Message string `json:"message"`
}
type ListDokter struct {
KodeSubspesialis string `json:"kodesubspesialis"`
Hari int `json:"hari"`
KapasitasPasien int `json:"kapasitaspasien"`
Libur int `json:"libur"`
NamaHari string `json:"namahari"`
Jadwal string `json:"jadwal"`
NamaSubspesialis string `json:"namasubspesialis"`
NamaDokter string `json:"namadokter"`
KodePoli string `json:"kodepoli"`
NamaPoli string `json:"namapoli"`
KodeDokter int `json:"kodedokter"`
}
type DaftarSpesialis struct {
ID int `json:"id"`
Kode string `json:"Kode"`
Spesialis string `json:"Spesialis"`
}
type JadwalDokterSatuData struct {
ID int `gorm:"id" json:"id"`
Hari int `gorm:"Hari" json:"Hari"`
NamaHari string `gorm:"Nama_hari" json:"Nama_hari"`
Waktu string `gorm:"Waktu" json:"Waktu"`
Dokter string `gorm:"Dokter" json:"Dokter"`
Spesialis int `gorm:"Spesialis" json:"Spesialis"`
SubSpesialis int `gorm:"Sub_spesialis" json:"Sub_spesialis"`
Status int `gorm:"Status" json:"Status"`
}
type JadwalDokterTempSatuData struct {
ID int `gorm:"id" json:"id"`
Hari int `gorm:"Hari" json:"Hari"`
NamaHari string `gorm:"Nama_hari" json:"Nama_hari"`
Waktu string `gorm:"Waktu" json:"Waktu"`
Dokter string `gorm:"Dokter" json:"Dokter"`
Spesialis string `gorm:"Spesialis" json:"Spesialis"`
SubSpesialis string `gorm:"Sub_spesialis" json:"Sub_spesialis"`
Status int `gorm:"Status" json:"Status"`
}
+14
View File
@@ -0,0 +1,14 @@
package config
type ConfigBpjs struct {
Cons_id string
Secret_key string
User_key string
}
type ConfigSatuSehat struct {
Org_id string
Client_id string
Client_secret string
Token string
}
+11
View File
@@ -0,0 +1,11 @@
package dokter
type DaftarDokter struct {
ID string `gorm:"column:id" json:"id"`
HfisCode string `gorm:"column:HFIS_code" json:"HFIS_code"`
}
type DaftarDokterRes struct {
ID string `gorm:"column:id" json:"id"`
HfisCode int `gorm:"column:HFIS_code" json:"HFIS_code"`
}
+7
View File
@@ -0,0 +1,7 @@
package dokter
type DaftarSpesialis struct {
ID int `json:"id"`
Kode string `json:"Kode"`
Spesialis string `json:"Spesialis"`
}
+9
View File
@@ -0,0 +1,9 @@
package dokter
type DaftarSubspesialis struct {
ID int `json:"id"`
Kode string `json:"Kode"`
Subspesialis string `json:"Subspesialis"`
FKDaftarSpesialisID int `json:"FK_daftar_spesialis_ID" gorm:"column:FK_daftar_spesialis_ID"`
}
+20
View File
@@ -0,0 +1,20 @@
package satusehat
import (
"github.com/go-playground/validator/v10"
)
type Procedure struct {
VisitId int `db:"visit_id" json:"visit_id" validate:"required"`
ProcedureCode string `db:"procedure_code" json:"procedure_code" validate:"required"`
ProcedureName string `db:"procedure_name" json:"procedure_name" validate:"required"`
}
func (o *Procedure) Invalid() bool {
val := validator.New()
err := val.Struct(o)
if err != nil {
return true
}
return false
}
+109
View File
@@ -0,0 +1,109 @@
package satusehat
import (
"time"
"github.com/go-playground/validator/v10"
)
type Visit struct {
VisitID string
PatientSatusehatID string
PatientNIK string
PatientName string
PatientSex string
PatientBirthDate *time.Time
PatientAddress string
PractitionerNIK string
PractitionerSatusehatID string
PractitionerName string
ClinicSatusehatID string
ClinicName string
Systole string
Diastole string
HeartRate string
RespirationRate string
OxygenSaturation string
Temperature string
PeriodStartDate time.Time
PeriodEndDate time.Time
ArrivedStartTime *time.Time
ArrivedEndTime *time.Time
InProgressStartTime *time.Time
InProgressEndTime *time.Time
FinishStartTime *time.Time
FinishEndTime *time.Time
}
type VisitDetail struct {
VisitId string `json:"visit_id" validate:"required"`
PatientSatusehatId string `json:"patient_satusehat_id" validate:"required"`
PatientNik string `json:"patient_nik" `
PatientName string `json:"patient_name" validate:"required"`
PatientSex string `json:"patient_sex"`
PatientBirthDate *time.Time `json:"patient_birth_date"`
PatientAddress string `json:"patient_address"`
PractitionerNik string `json:"practitioner_nik"`
PractitionerId string `json:"practitioner_satusehat_id" validate:"required"`
PractitionerName string `json:"practitioner_name" validate:"required"`
ClinicName string `json:"clinic_name" validate:"required"`
ClinicSatuSehatId string `json:"clinic_id" validate:"required"`
PeriodStartDate time.Time `json:"period_start_date" validate:"required"`
PeriodEndDate time.Time `json:"period_end_date" validate:"required"`
ArrivedStartTime *time.Time `json:"arrived_start_time" validate:"required"`
ArrivedEndTime *time.Time `json:"arrived_end_time" validate:"required"`
InProgressStartTime *time.Time `json:"in_progress_start_time" validate:"required"`
InProgressEndTime *time.Time `json:"in_progress_end_time" validate:"required"`
FinishStartTime *time.Time `json:"finish_start_time" validate:"required"`
FinishEndTime *time.Time `json:"finish_end_time" validate:"required"`
}
func (v VisitDetail) Invalid() error {
val := validator.New()
return val.Struct(v)
}
type VitalSign struct {
Systole string `json:"sistole"`
Diastole string `json:"diastole"`
HeartRate string `json:"heart_rate"`
RespirationRate string `json:"respiration_rate"`
Temperature string `json:"temperature"`
OxygenSaturation string `json:"oxygen_saturation"`
}
func (v *Visit) VitalSign() VitalSign {
return VitalSign{
Systole: v.Systole,
Diastole: v.Diastole,
HeartRate: v.HeartRate,
RespirationRate: v.RespirationRate,
Temperature: v.Temperature,
OxygenSaturation: v.OxygenSaturation,
}
}
func (v *Visit) VisitDetail() VisitDetail {
return VisitDetail{
VisitId: v.VisitID,
PatientSatusehatId: v.PatientSatusehatID,
PatientNik: v.PatientNIK,
PatientName: v.PatientName,
PatientSex: v.PatientSex,
PatientBirthDate: v.PatientBirthDate,
PatientAddress: v.PatientAddress,
ClinicName: v.ClinicName,
ClinicSatuSehatId: v.ClinicSatusehatID,
PeriodStartDate: v.PeriodStartDate,
PeriodEndDate: v.PeriodEndDate,
PractitionerNik: v.PractitionerNIK,
PractitionerId: v.PractitionerSatusehatID,
PractitionerName: v.PractitionerName,
ArrivedStartTime: v.ArrivedStartTime,
ArrivedEndTime: v.ArrivedEndTime,
InProgressStartTime: v.InProgressStartTime,
InProgressEndTime: v.InProgressEndTime,
FinishStartTime: v.FinishStartTime,
FinishEndTime: v.FinishEndTime,
}
}
+32 -32
View File
@@ -1,32 +1,32 @@
package models
type User struct {
ID string `json:"id"`
Nama string `json:"nama"`
Umur int `json:"umur"`
Alamat string `json:"alamat"`
Agama string `json:"agama"`
JenisKelamin string `json:"jenis_kelamin"`
}
type UpdateUser struct {
ID string `json:"id"`
Nama string `json:"nama"`
Umur int `json:"umur"`
Alamat string `json:"alamat"`
Agama string `json:"agama"`
JenisKelamin string `json:"jenis_kelamin"`
}
type InsertUser struct {
Nama string `json:"nama"`
Umur int `json:"umur"`
Alamat string `json:"alamat"`
Agama string `json:"agama"`
JenisKelamin string `json:"jenis_kelamin"`
}
type Response struct {
ResponseCode string `json:"response_code"`
ResponseMessage string `json:"response_message"`
}
package models
type User struct {
ID string `json:"id"`
Nama string `json:"nama"`
Umur int `json:"umur"`
Alamat string `json:"alamat"`
Agama string `json:"agama"`
JenisKelamin string `json:"jenis_kelamin"`
}
type UpdateUser struct {
ID string `json:"id"`
Nama string `json:"nama"`
Umur int `json:"umur"`
Alamat string `json:"alamat"`
Agama string `json:"agama"`
JenisKelamin string `json:"jenis_kelamin"`
}
type InsertUser struct {
Nama string `json:"nama"`
Umur int `json:"umur"`
Alamat string `json:"alamat"`
Agama string `json:"agama"`
JenisKelamin string `json:"jenis_kelamin"`
}
type Response struct {
ResponseCode string `json:"response_code"`
ResponseMessage string `json:"response_message"`
}