88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
package careplan
|
|
|
|
import (
|
|
"os"
|
|
"service/internal/interfaces/satusehat"
|
|
"time"
|
|
)
|
|
|
|
func MapRequestToFHIR(req CarePlanRequest) satusehat.FHIRPayload {
|
|
payload := satusehat.NewFHIRPayload("CarePlan")
|
|
|
|
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
|
if orgID == "" {
|
|
orgID = req.OrganizationID
|
|
}
|
|
|
|
if orgID != "" && req.CarePlanID != "" {
|
|
payload.Set("identifier", []map[string]interface{}{
|
|
{"system": "http://sys-ids.kemkes.go.id/careplan/" + orgID, "use": "official", "value": req.CarePlanID},
|
|
})
|
|
}
|
|
|
|
if req.Status != "" {
|
|
payload.Set("status", req.Status)
|
|
}
|
|
if req.Intent != "" {
|
|
payload.Set("intent", req.Intent)
|
|
}
|
|
if len(req.Category) > 0 {
|
|
var categories []map[string]interface{}
|
|
for _, cat := range req.Category {
|
|
sys := cat.System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct" // Default value jika kosong
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": cat.Code}
|
|
if cat.Display != "" {
|
|
coding["display"] = cat.Display
|
|
}
|
|
concept := map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
|
if cat.Text != "" {
|
|
concept["text"] = cat.Text
|
|
}
|
|
categories = append(categories, concept)
|
|
}
|
|
payload.Set("category", categories)
|
|
}
|
|
if req.Title != "" {
|
|
payload.Set("title", req.Title)
|
|
}
|
|
if req.Description != "" {
|
|
payload.Set("description", req.Description)
|
|
}
|
|
if req.PatientID != "" {
|
|
subject := map[string]interface{}{"reference": "Patient/" + req.PatientID}
|
|
if req.PatientDisplay != "" {
|
|
subject["display"] = req.PatientDisplay
|
|
}
|
|
payload.Set("subject", subject)
|
|
}
|
|
if req.EncounterID != "" {
|
|
encounter := map[string]interface{}{"reference": "Encounter/" + req.EncounterID}
|
|
if req.EncounterDisplay != "" {
|
|
encounter["display"] = req.EncounterDisplay
|
|
}
|
|
payload.Set("encounter", encounter)
|
|
}
|
|
if req.AuthorID != "" {
|
|
author := map[string]interface{}{"reference": "Practitioner/" + req.AuthorID}
|
|
if req.AuthorDisplay != "" {
|
|
author["display"] = req.AuthorDisplay
|
|
}
|
|
payload.Set("author", author)
|
|
}
|
|
if req.CreatedDate != nil && !req.CreatedDate.IsZero() {
|
|
payload.Set("created", req.CreatedDate.Format(time.RFC3339))
|
|
}
|
|
if len(req.GoalIDs) > 0 {
|
|
var goals []map[string]interface{}
|
|
for _, id := range req.GoalIDs {
|
|
goals = append(goals, map[string]interface{}{"reference": "Goal/" + id})
|
|
}
|
|
payload.Set("goal", goals)
|
|
}
|
|
|
|
return payload
|
|
}
|