147 lines
3.9 KiB
Go
147 lines
3.9 KiB
Go
package procedure
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"service/internal/interfaces/satusehat"
|
|
)
|
|
|
|
func MapRequestToFHIR(req ProcedureRequest) satusehat.FHIRPayload {
|
|
payload := satusehat.NewFHIRPayload("Procedure")
|
|
|
|
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
|
if orgID == "" {
|
|
orgID = req.OrganizationID
|
|
}
|
|
|
|
if orgID != "" && req.ProcedureID != "" {
|
|
payload.Set("identifier", []map[string]interface{}{
|
|
{
|
|
"system": "http://sys-ids.kemkes.go.id/procedure/" + orgID,
|
|
"value": req.ProcedureID,
|
|
},
|
|
})
|
|
}
|
|
|
|
if req.Status != "" {
|
|
payload.Set("status", req.Status)
|
|
}
|
|
|
|
if len(req.Category) > 0 && req.Category[0] != nil {
|
|
sys := req.Category[0].System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": req.Category[0].Code}
|
|
if req.Category[0].Display != "" {
|
|
coding["display"] = req.Category[0].Display
|
|
}
|
|
catObj := map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
|
if req.Category[0].Text != "" {
|
|
catObj["text"] = req.Category[0].Text
|
|
}
|
|
payload.Set("category", catObj)
|
|
}
|
|
|
|
if req.Code != nil {
|
|
sys := req.Code.System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": req.Code.Code}
|
|
if req.Code.Display != "" {
|
|
coding["display"] = req.Code.Display
|
|
}
|
|
codeObj := map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
|
if req.Code.Text != "" {
|
|
codeObj["text"] = req.Code.Text
|
|
}
|
|
payload.Set("code", codeObj)
|
|
}
|
|
|
|
if req.Subject != nil {
|
|
subj := map[string]interface{}{"reference": req.Subject.Reference}
|
|
if req.Subject.Display != "" {
|
|
subj["display"] = req.Subject.Display
|
|
}
|
|
payload.Set("subject", subj)
|
|
}
|
|
|
|
if req.Encounter != nil {
|
|
enc := map[string]interface{}{"reference": req.Encounter.Reference}
|
|
if req.Encounter.Display != "" {
|
|
enc["display"] = req.Encounter.Display
|
|
}
|
|
payload.Set("encounter", enc)
|
|
}
|
|
|
|
if req.PerformedStart != nil && !req.PerformedStart.IsZero() {
|
|
period := map[string]interface{}{"start": req.PerformedStart.Format(time.RFC3339)}
|
|
if req.PerformedEnd != nil && !req.PerformedEnd.IsZero() {
|
|
period["end"] = req.PerformedEnd.Format(time.RFC3339)
|
|
}
|
|
payload.Set("performedPeriod", period)
|
|
} else if req.PerformedDateTime != nil && !req.PerformedDateTime.IsZero() {
|
|
payload.Set("performedDateTime", req.PerformedDateTime.Format(time.RFC3339))
|
|
}
|
|
|
|
if len(req.Performer) > 0 {
|
|
var performers []map[string]interface{}
|
|
for _, p := range req.Performer {
|
|
actor := map[string]interface{}{"reference": p.Reference}
|
|
if p.Display != "" {
|
|
actor["display"] = p.Display
|
|
}
|
|
performers = append(performers, map[string]interface{}{"actor": actor})
|
|
}
|
|
payload.Set("performer", performers)
|
|
}
|
|
|
|
if len(req.ReasonCode) > 0 {
|
|
var reasons []map[string]interface{}
|
|
for _, r := range req.ReasonCode {
|
|
if r != nil {
|
|
sys := r.System
|
|
if sys == "" {
|
|
sys = "http://hl7.org/fhir/sid/icd-10"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": r.Code}
|
|
if r.Display != "" {
|
|
coding["display"] = r.Display
|
|
}
|
|
reasons = append(reasons, map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
|
}
|
|
}
|
|
payload.Set("reasonCode", reasons)
|
|
}
|
|
|
|
if len(req.BodySite) > 0 {
|
|
var bodySites []map[string]interface{}
|
|
for _, b := range req.BodySite {
|
|
if b != nil {
|
|
sys := b.System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": b.Code}
|
|
if b.Display != "" {
|
|
coding["display"] = b.Display
|
|
}
|
|
bodySites = append(bodySites, map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
|
}
|
|
}
|
|
payload.Set("bodySite", bodySites)
|
|
}
|
|
|
|
if len(req.Note) > 0 {
|
|
var notes []map[string]interface{}
|
|
for _, text := range req.Note {
|
|
notes = append(notes, map[string]interface{}{"text": text})
|
|
}
|
|
payload.Set("note", notes)
|
|
}
|
|
|
|
return payload
|
|
}
|