187 lines
4.9 KiB
Go
187 lines
4.9 KiB
Go
package clinicalimpression
|
|
|
|
import (
|
|
"os"
|
|
"service/internal/interfaces/satusehat"
|
|
"time"
|
|
)
|
|
|
|
func MapRequestToFHIR(req ClinicalImpressionRequest) satusehat.FHIRPayload {
|
|
payload := satusehat.NewFHIRPayload("ClinicalImpression")
|
|
|
|
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
|
if orgID == "" {
|
|
orgID = req.OrganizationID
|
|
}
|
|
|
|
if orgID != "" && req.ClinicalImpressionID != "" {
|
|
payload.Set("identifier", []map[string]interface{}{
|
|
{
|
|
"system": "http://sys-ids.kemkes.go.id/clinicalimpression/" + orgID,
|
|
"use": "official",
|
|
"value": req.ClinicalImpressionID,
|
|
},
|
|
})
|
|
}
|
|
|
|
if req.Status != "" {
|
|
payload.Set("status", req.Status)
|
|
}
|
|
|
|
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
|
|
}
|
|
payload.Set("code", map[string]interface{}{
|
|
"coding": []map[string]interface{}{
|
|
coding,
|
|
},
|
|
})
|
|
}
|
|
|
|
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.EffectiveDateTime != nil && !req.EffectiveDateTime.IsZero() {
|
|
payload.Set("effectiveDateTime", req.EffectiveDateTime.Format(time.RFC3339))
|
|
}
|
|
|
|
if req.Date != nil && !req.Date.IsZero() {
|
|
payload.Set("date", req.Date.Format(time.RFC3339))
|
|
}
|
|
|
|
if req.AssessorID != "" {
|
|
assessor := map[string]interface{}{"reference": "Practitioner/" + req.AssessorID}
|
|
if req.AssessorDisplay != "" {
|
|
assessor["display"] = req.AssessorDisplay
|
|
}
|
|
payload.Set("assessor", assessor)
|
|
}
|
|
|
|
if len(req.Problem) > 0 {
|
|
var problems []map[string]interface{}
|
|
for _, p := range req.Problem {
|
|
problem := map[string]interface{}{"reference": p.Reference}
|
|
if p.Display != "" {
|
|
problem["display"] = p.Display
|
|
}
|
|
problems = append(problems, problem)
|
|
}
|
|
payload.Set("problem", problems)
|
|
}
|
|
|
|
if len(req.Investigations) > 0 {
|
|
var investigations []map[string]interface{}
|
|
for _, inv := range req.Investigations {
|
|
invObject := map[string]interface{}{}
|
|
if inv.Code != nil {
|
|
codeConcept := map[string]interface{}{}
|
|
sys := inv.Code.System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": inv.Code.Code}
|
|
if inv.Code.Display != "" {
|
|
coding["display"] = inv.Code.Display
|
|
}
|
|
codeConcept["coding"] = []map[string]interface{}{coding}
|
|
if inv.Code.Text != "" {
|
|
codeConcept["text"] = inv.Code.Text
|
|
}
|
|
invObject["code"] = codeConcept
|
|
}
|
|
|
|
if len(inv.Item) > 0 {
|
|
var items []map[string]interface{}
|
|
for _, item := range inv.Item {
|
|
ref := map[string]interface{}{"reference": item.Reference}
|
|
if item.Display != "" {
|
|
ref["display"] = item.Display
|
|
}
|
|
items = append(items, ref)
|
|
}
|
|
invObject["item"] = items
|
|
}
|
|
investigations = append(investigations, invObject)
|
|
}
|
|
payload.Set("investigation", investigations)
|
|
}
|
|
|
|
if req.Summary != "" {
|
|
payload.Set("summary", req.Summary)
|
|
}
|
|
|
|
if len(req.Findings) > 0 {
|
|
var findings []map[string]interface{}
|
|
for _, f := range req.Findings {
|
|
findingObject := map[string]interface{}{}
|
|
if f.ItemCodeableConcept != nil {
|
|
sys := f.ItemCodeableConcept.System
|
|
if sys == "" {
|
|
sys = "http://hl7.org/fhir/sid/icd-10"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": f.ItemCodeableConcept.Code}
|
|
if f.ItemCodeableConcept.Display != "" {
|
|
coding["display"] = f.ItemCodeableConcept.Display
|
|
}
|
|
findingObject["itemCodeableConcept"] = map[string]interface{}{
|
|
"coding": []map[string]interface{}{coding},
|
|
}
|
|
}
|
|
if f.ItemReference != nil {
|
|
ref := map[string]interface{}{"reference": f.ItemReference.Reference}
|
|
if f.ItemReference.Display != "" {
|
|
ref["display"] = f.ItemReference.Display
|
|
}
|
|
findingObject["itemReference"] = ref
|
|
}
|
|
if len(findingObject) > 0 {
|
|
findings = append(findings, findingObject)
|
|
}
|
|
}
|
|
payload.Set("finding", findings)
|
|
}
|
|
|
|
if len(req.Prognosis) > 0 {
|
|
var prognosis []map[string]interface{}
|
|
for _, p := range req.Prognosis {
|
|
if p != nil {
|
|
sys := p.System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": p.Code}
|
|
if p.Display != "" {
|
|
coding["display"] = p.Display
|
|
}
|
|
prognosis = append(prognosis, map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
|
}
|
|
}
|
|
payload.Set("prognosisCodeableConcept", prognosis)
|
|
}
|
|
|
|
return payload
|
|
}
|