92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package condition
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"service/internal/interfaces/satusehat"
|
|
)
|
|
|
|
func MapRequestToFHIR(req ConditionRequest) satusehat.FHIRPayload {
|
|
payload := satusehat.NewFHIRPayload("Condition")
|
|
|
|
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
|
if orgID == "" {
|
|
orgID = req.OrganizationID
|
|
}
|
|
|
|
if orgID != "" && req.ConditionID != "" {
|
|
payload.Set("identifier", []map[string]interface{}{
|
|
{"system": "http://sys-ids.kemkes.go.id/condition/" + orgID, "use": "official", "value": req.ConditionID},
|
|
})
|
|
}
|
|
|
|
if req.ClinicalStatus != "" {
|
|
payload.Set("clinicalStatus", map[string]interface{}{
|
|
"coding": []map[string]interface{}{
|
|
{"system": "http://terminology.hl7.org/CodeSystem/condition-clinical", "code": req.ClinicalStatus},
|
|
},
|
|
})
|
|
}
|
|
if req.Category != nil {
|
|
sys := req.Category.System
|
|
if sys == "" {
|
|
sys = "http://terminology.hl7.org/CodeSystem/condition-category"
|
|
}
|
|
coding := map[string]interface{}{
|
|
"system": sys,
|
|
"code": req.Category.Code,
|
|
}
|
|
if req.Category.Display != "" {
|
|
coding["display"] = req.Category.Display
|
|
}
|
|
payload.Set("category", []map[string]interface{}{
|
|
{
|
|
"coding": []map[string]interface{}{
|
|
coding,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
if req.Code != nil {
|
|
sys := req.Code.System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct" // Default value jika tidak diset
|
|
}
|
|
coding := map[string]interface{}{
|
|
"system": sys,
|
|
"code": req.Code.Code,
|
|
}
|
|
if req.Code.Display != "" {
|
|
coding["display"] = req.Code.Display
|
|
}
|
|
codeConcept := map[string]interface{}{
|
|
"coding": []map[string]interface{}{
|
|
coding,
|
|
},
|
|
}
|
|
if req.Code.Text != "" {
|
|
codeConcept["text"] = req.Code.Text
|
|
}
|
|
payload.Set("code", codeConcept)
|
|
}
|
|
if req.PatientID != "" {
|
|
subject := map[string]interface{}{"reference": "Patient/" + req.PatientID}
|
|
if req.PatientName != "" {
|
|
subject["display"] = req.PatientName
|
|
}
|
|
payload.Set("subject", subject)
|
|
}
|
|
if req.EncounterID != "" {
|
|
payload.Set("encounter", map[string]interface{}{"reference": "Encounter/" + req.EncounterID})
|
|
}
|
|
if req.OnsetDateTime != nil && !req.OnsetDateTime.IsZero() {
|
|
payload.Set("onsetDateTime", req.OnsetDateTime.Format(time.RFC3339))
|
|
}
|
|
if req.RecordedDate != nil && !req.RecordedDate.IsZero() {
|
|
payload.Set("recordedDate", req.RecordedDate.Format(time.RFC3339))
|
|
}
|
|
|
|
return payload
|
|
}
|