Pengambilan Data KFA Pengiriman data medication dan service request

This commit is contained in:
meninjar
2026-05-04 03:24:01 +00:00
parent 24d25aa14a
commit e8a0642291
80 changed files with 1718354 additions and 263 deletions

No files matched your search

@@ -19,6 +19,7 @@ import (
const trackerFile = "internal/worker/satusehat/servicerequest/last_servicerequest_id.txt"
const trackerFileRad = "internal/worker/satusehat/servicerequest/last_servicerequest_rad_time.txt"
const rateLimitSleep = 60 * time.Second
type Config struct {
DBManager database.Service
@@ -134,7 +135,7 @@ func (w *worker) runRadiology(ctx context.Context) {
lastTime := w.readLastTime()
// Custom data: Override membaca mulai tanggal 2025-12-18 (Format: YYYY-MM-DD)
customDate, _ := time.Parse("2006-01-02", "2026-24-04")
customDate, _ := time.Parse("2006-01-02", "2026-04-24")
if lastTime.Before(customDate) {
lastTime = customDate
}
@@ -208,6 +209,20 @@ func (w *worker) runRadiology(ctx context.Context) {
}
}
// isRateLimitResponse mendeteksi respons rate-limit dari Satu Sehat
// (HTTP 429 atau pesan body yang mengindikasikan limit pengiriman terlampaui).
func isRateLimitResponse(statusCode int, respBody []byte) bool {
if statusCode == http.StatusTooManyRequests {
return true
}
body := strings.ToLower(string(respBody))
return strings.Contains(body, "too many requests") ||
strings.Contains(body, "rate limit") ||
strings.Contains(body, "limit exceeded") ||
strings.Contains(body, "limit pengiriman") ||
strings.Contains(body, "quota exceeded")
}
// sendToInternalAPI mengirimkan payload ke internal FHIR server, menangani auth retry (401) dan response error.
func (w *worker) sendToInternalAPI(ctx context.Context, payload map[string]interface{}, sourceID string) (fhirID string, respBody []byte, status string, errMsg string, retryDelay time.Duration) {
reqURL := fmt.Sprintf("%s/satusehat/servicerequest", strings.TrimRight(w.cfg.InternalBaseURL, "/"))
@@ -257,11 +272,11 @@ func (w *worker) sendToInternalAPI(ctx context.Context, payload map[string]inter
logger.String("response", truncate(string(respBody), 200)),
)
// Lakukan Retry jika server Internal error (5xx) atau Rate Limit (429)
if statusCode >= 500 || statusCode == http.StatusTooManyRequests {
delay := 5 * time.Second
if statusCode == http.StatusTooManyRequests {
delay = 60 * time.Second // Default fallback jika parse gagal
// Lakukan Retry jika server Internal error (5xx) atau Rate Limit terdeteksi
if statusCode >= 500 || isRateLimitResponse(statusCode, respBody) {
delay := 5 * time.Second // Default delay untuk 5xx
if isRateLimitResponse(statusCode, respBody) {
delay = rateLimitSleep // Gunakan konstanta dari reference
var errResp struct {
RetryAfter int `json:"retry_after"`
}