package questionnaireresponse

import (
	"time"

	"service/internal/interfaces/satusehat"
)

func MapRequestToFHIR(req QuestionnaireResponseRequest) satusehat.FHIRPayload {
	payload := satusehat.NewFHIRPayload("QuestionnaireResponse").
		Set("questionnaire", req.QuestionnaireURL).
		Set("status", req.Status).
		Set("subject", map[string]interface{}{
			"reference": "Patient/" + req.PatientID,
			"display":   req.PatientName,
		}).
		Set("encounter", map[string]interface{}{
			"reference": "Encounter/" + req.EncounterID,
		}).
		Set("authored", req.AuthoredDate.Format(time.RFC3339)).
		Set("author", map[string]interface{}{
			"reference": "Practitioner/" + req.AuthorID,
			"display":   req.AuthorName,
		}).
		Set("item", req.Items)

	return payload
}
