116 lines
2.9 KiB
Go
116 lines
2.9 KiB
Go
package allergyintolerance
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"service/internal/interfaces/satusehat"
|
|
)
|
|
|
|
var verificationStatusDisplayMap = map[string]string{
|
|
"unconfirmed": "Unconfirmed",
|
|
"presumed": "Presumed",
|
|
"confirmed": "Confirmed",
|
|
"refuted": "Refuted",
|
|
"entered-in-error": "Entered in Error",
|
|
}
|
|
|
|
func MapRequestToFHIR(req AllergyIntoleranceRequest) satusehat.FHIRPayload {
|
|
payload := satusehat.NewFHIRPayload("AllergyIntolerance")
|
|
|
|
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
|
if orgID == "" {
|
|
orgID = req.OrganizationID
|
|
}
|
|
|
|
if orgID != "" && req.AllergyID != "" {
|
|
payload.Set("identifier", []map[string]interface{}{
|
|
{
|
|
"system": "http://sys-ids.kemkes.go.id/allergy/" + orgID,
|
|
"use": "official",
|
|
"value": req.AllergyID,
|
|
},
|
|
})
|
|
}
|
|
|
|
if req.ClinicalStatus != "" {
|
|
payload.Set("clinicalStatus", map[string]interface{}{
|
|
"coding": []map[string]interface{}{
|
|
{
|
|
"system": "http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical",
|
|
"code": req.ClinicalStatus,
|
|
"display": strings.ToUpper(req.ClinicalStatus[:1]) + req.ClinicalStatus[1:],
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
if req.VerificationStatus != "" {
|
|
display, ok := verificationStatusDisplayMap[req.VerificationStatus]
|
|
if !ok {
|
|
display = strings.ToUpper(req.VerificationStatus[:1]) + req.VerificationStatus[1:]
|
|
}
|
|
payload.Set("verificationStatus", map[string]interface{}{
|
|
"coding": []map[string]interface{}{
|
|
{"system": "http://terminology.hl7.org/CodeSystem/allergyintolerance-verification", "code": req.VerificationStatus, "display": display},
|
|
},
|
|
})
|
|
}
|
|
|
|
if len(req.Category) > 0 {
|
|
payload.Set("category", req.Category)
|
|
}
|
|
|
|
if req.Code != nil {
|
|
sys := req.Code.System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct" // Default to SNOMED
|
|
}
|
|
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("patient", 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.RecordedDate != nil && !req.RecordedDate.IsZero() {
|
|
payload.Set("recordedDate", req.RecordedDate.Format(time.RFC3339))
|
|
}
|
|
|
|
if req.RecorderID != "" {
|
|
recorder := map[string]interface{}{"reference": "Practitioner/" + req.RecorderID}
|
|
if req.RecorderDisplay != "" {
|
|
recorder["display"] = req.RecorderDisplay
|
|
}
|
|
payload.Set("recorder", recorder)
|
|
}
|
|
|
|
return payload
|
|
}
|