package medicationdispense

import (
	"encoding/json"
	"time"
)

func MapToInternalAPI(dbData *MedicationDispenseDB, orgID string) map[string]interface{} {
	return map[string]interface{}{
		"prescription_id":       dbData.NoJual,
		"patient_id":            dbData.PatientID,
		"encounter_id":          dbData.EncounterID,
		"medication_request_id": dbData.MedicationRequestID,
		"status":                "completed",
		"medication_id":         dbData.MedicationID,
		"practitioner_id":       dbData.PractitionerID,
		"quantity_value":        dbData.JmlhKeluar,
		"quantity_unit":         dbData.Sediaan,
		"location_id":           "bfffca38-ce1e-41f4-ae40-f614d401443a",
		"prepared_date":         dbData.PreparedDate.Format(time.RFC3339),
		"handed_over_date":      dbData.HandedOverDate.Format(time.RFC3339),
	}
}

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