package clinicalimpression

import (
	"encoding/json"
	"fmt"
	"time"
)

// TODO: Sesuaikan dengan payload internal API ClinicalImpression
func MapToInternalAPI(dbData *ClinicalImpressionDB, orgID string) map[string]interface{} {
	waktu := time.Now()
	if dbData.TglKesan.Valid {
		waktu = dbData.TglKesan.Time
	}
	return map[string]interface{}{
		"clinicalimpression_id": fmt.Sprintf("%d", dbData.IdxKesan),
		"encounter_id":          fmt.Sprintf("%d", dbData.IdxDaftar),
		"patient_id":            dbData.NoMR.String,
		"date":                  waktu.Format(time.RFC3339),
	}
}

func MapToSyncLog(idx int64, fhirID string, reqPayload interface{}, respBody []byte, status string, errMsg string) ClinicalImpressionSyncLog {
	reqBytes, _ := json.MarshalIndent(reqPayload, "", "  ")
	return ClinicalImpressionSyncLog{
		IdxKesan:             idx,
		ClinicalImpressionID: fhirID,
		RequestPayload:       string(reqBytes),
		ResponsePayload:      string(respBody),
		Status:               status,
		ErrorMessage:         errMsg,
	}
}
