first commit
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package dpho
|
||||
|
||||
// DPHOData merepresentasikan detail referensi DPHO dari API Apotek
|
||||
type DPHOData struct {
|
||||
KodeObat string `json:"kodeobat"`
|
||||
NamaObat string `json:"namaobat"`
|
||||
PRB string `json:"prb"`
|
||||
Kronis string `json:"kronis"`
|
||||
Kemo string `json:"kemo"`
|
||||
Harga string `json:"harga"`
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package dpho
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"service/internal/interfaces/bpjs"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
GetDPHO(ctx context.Context) ([]DPHOData, error)
|
||||
}
|
||||
|
||||
type repository struct {
|
||||
client bpjs.BpjsClient
|
||||
}
|
||||
|
||||
func NewRepository(client bpjs.BpjsClient) Repository {
|
||||
return &repository{client: client}
|
||||
}
|
||||
|
||||
func (r *repository) GetDPHO(ctx context.Context) ([]DPHOData, error) {
|
||||
respBytes, err := r.client.DoRequest(ctx, "GET", "referensi/dpho", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Coba parsing ke dalam format object { "list": [...] }
|
||||
var result struct {
|
||||
List []DPHOData `json:"list"`
|
||||
}
|
||||
if err := json.Unmarshal(respBytes, &result); err != nil {
|
||||
// Fallback jika API mengembalikan array langsung [...]
|
||||
var directList []DPHOData
|
||||
if err2 := json.Unmarshal(respBytes, &directList); err2 == nil {
|
||||
return directList, nil
|
||||
}
|
||||
return nil, fmt.Errorf("failed to unmarshal apotek dpho response: %w", err)
|
||||
}
|
||||
return result.List, nil
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package dpho
|
||||
|
||||
import (
|
||||
"context"
|
||||
"service/pkg/errors"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
GetDPHO(ctx context.Context) ([]DPHOData, error)
|
||||
}
|
||||
|
||||
type service struct {
|
||||
repo Repository
|
||||
}
|
||||
|
||||
func NewService(repo Repository) Service {
|
||||
return &service{repo: repo}
|
||||
}
|
||||
|
||||
func (s *service) GetDPHO(ctx context.Context) ([]DPHOData, error) {
|
||||
res, err := s.repo.GetDPHO(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.ExternalError().Message("Gagal mengambil referensi DPHO Apotek BPJS").Cause(err).Build()
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package poli
|
||||
|
||||
// PoliData merepresentasikan detail referensi Poli dari API Apotek
|
||||
type PoliData struct {
|
||||
KodePoli string `json:"kodepoli"`
|
||||
NamaPoli string `json:"namapoli"`
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package poli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"service/internal/interfaces/bpjs"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
GetPoli(ctx context.Context, param string) ([]PoliData, error)
|
||||
}
|
||||
|
||||
type repository struct {
|
||||
client bpjs.BpjsClient
|
||||
}
|
||||
|
||||
func NewRepository(client bpjs.BpjsClient) Repository {
|
||||
return &repository{client: client}
|
||||
}
|
||||
|
||||
func (r *repository) GetPoli(ctx context.Context, param string) ([]PoliData, error) {
|
||||
endpoint := fmt.Sprintf("referensi/poli/%s", param)
|
||||
respBytes, err := r.client.DoRequest(ctx, "GET", endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result struct {
|
||||
List []PoliData `json:"list"`
|
||||
}
|
||||
if err := json.Unmarshal(respBytes, &result); err != nil {
|
||||
var directList []PoliData
|
||||
if err2 := json.Unmarshal(respBytes, &directList); err2 == nil {
|
||||
return directList, nil
|
||||
}
|
||||
return nil, fmt.Errorf("failed to unmarshal apotek poli response: %w", err)
|
||||
}
|
||||
return result.List, nil
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package poli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"service/pkg/errors"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
GetPoli(ctx context.Context, param string) ([]PoliData, error)
|
||||
}
|
||||
|
||||
type service struct {
|
||||
repo Repository
|
||||
}
|
||||
|
||||
func NewService(repo Repository) Service {
|
||||
return &service{repo: repo}
|
||||
}
|
||||
|
||||
func (s *service) GetPoli(ctx context.Context, param string) ([]PoliData, error) {
|
||||
if param == "" {
|
||||
return nil, errors.NewValidationError().Message("Parameter pencarian Poli wajib diisi").Build()
|
||||
}
|
||||
res, err := s.repo.GetPoli(ctx, param)
|
||||
if err != nil {
|
||||
return nil, errors.ExternalError().Message("Gagal mengambil referensi Poli Apotek BPJS").Cause(err).Build()
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
Reference in New Issue
Block a user