package condition

import (
	"time"

	"service/internal/interfaces/satusehat"
)

func MapRequestToFHIR(req ConditionRequest) satusehat.FHIRPayload {
	payload := satusehat.NewFHIRPayload("Condition").
		Set("clinicalStatus", map[string]interface{}{
			"coding": []map[string]interface{}{
				{
					"system": "http://terminology.hl7.org/CodeSystem/condition-clinical",
					"code":   req.ClinicalStatus,
				},
			},
		}).
		Set("category", []map[string]interface{}{
			{
				"coding": []map[string]interface{}{
					{
						"system":  "http://terminology.hl7.org/CodeSystem/condition-category",
						"code":    req.CategoryCode,
						"display": req.CategoryDisplay,
					},
				},
			},
		}).
		Set("code", map[string]interface{}{
			"coding": []map[string]interface{}{
				{
					"system":  "http://snomed.info/sct",
					"code":    req.Code,
					"display": req.Display,
				},
			},
		}).
		Set("subject", map[string]interface{}{
			"reference": "Patient/" + req.PatientID,
			"display":   req.PatientName,
		}).
		Set("encounter", map[string]interface{}{
			"reference": "Encounter/" + req.EncounterID,
		}).
		Set("onsetDateTime", req.OnsetDateTime.Format(time.RFC3339)).
		Set("recordedDate", req.RecordedDate.Format(time.RFC3339))

	return payload
}
