36 lines
1023 B
Go
36 lines
1023 B
Go
package immunization
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// TODO: Sesuaikan dengan payload internal API Immunization
|
|
func MapToInternalAPI(dbData *ImmunizationDB, orgID string) map[string]interface{} {
|
|
waktu := time.Now()
|
|
if dbData.TglImunisasi.Valid {
|
|
waktu = dbData.TglImunisasi.Time
|
|
}
|
|
payload := map[string]interface{}{
|
|
"immunization_id": fmt.Sprintf("%d", dbData.IdxImunisasi),
|
|
"encounter_id": fmt.Sprintf("%d", dbData.IdxDaftar),
|
|
"patient_id": dbData.NoMR.String,
|
|
"vaccine_code": dbData.KodeVaksin.String,
|
|
"occurrence_date": waktu.Format(time.RFC3339),
|
|
}
|
|
return payload
|
|
}
|
|
|
|
func MapToSyncLog(idx int64, fhirID string, reqPayload interface{}, respBody []byte, status string, errMsg string) ImmunizationSyncLog {
|
|
reqBytes, _ := json.MarshalIndent(reqPayload, "", " ")
|
|
return ImmunizationSyncLog{
|
|
IdxImunisasi: idx,
|
|
ImmunizationID: fhirID,
|
|
RequestPayload: string(reqBytes),
|
|
ResponsePayload: string(respBody),
|
|
Status: status,
|
|
ErrorMessage: errMsg,
|
|
}
|
|
}
|