127 lines
3.2 KiB
Go
127 lines
3.2 KiB
Go
package immunization
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"service/internal/interfaces/satusehat"
|
|
)
|
|
|
|
func MapRequestToFHIR(req ImmunizationRequest) satusehat.FHIRPayload {
|
|
payload := satusehat.NewFHIRPayload("Immunization")
|
|
|
|
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
|
if orgID == "" {
|
|
orgID = req.OrganizationID
|
|
}
|
|
|
|
if orgID != "" && req.ImmunizationID != "" {
|
|
payload.Set("identifier", []map[string]interface{}{
|
|
{
|
|
"system": "http://sys-ids.kemkes.go.id/immunization/" + orgID,
|
|
"use": "official",
|
|
"value": req.ImmunizationID,
|
|
},
|
|
})
|
|
}
|
|
|
|
if req.Status != "" {
|
|
payload.Set("status", req.Status)
|
|
}
|
|
|
|
if req.VaccineCode != nil {
|
|
sys := req.VaccineCode.System
|
|
if sys == "" {
|
|
sys = "http://sys-ids.kemkes.go.id/kfa"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": req.VaccineCode.Code}
|
|
if req.VaccineCode.Display != "" {
|
|
coding["display"] = req.VaccineCode.Display
|
|
}
|
|
vaccineConcept := map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
|
if req.VaccineCode.Text != "" {
|
|
vaccineConcept["text"] = req.VaccineCode.Text
|
|
}
|
|
payload.Set("vaccineCode", vaccineConcept)
|
|
}
|
|
|
|
if req.PatientID != "" {
|
|
subj := map[string]interface{}{"reference": "Patient/" + req.PatientID}
|
|
if req.PatientName != "" {
|
|
subj["display"] = req.PatientName
|
|
}
|
|
payload.Set("patient", subj)
|
|
}
|
|
|
|
if req.EncounterID != "" {
|
|
enc := map[string]interface{}{"reference": "Encounter/" + req.EncounterID}
|
|
if req.EncounterDisplay != "" {
|
|
enc["display"] = req.EncounterDisplay
|
|
}
|
|
payload.Set("encounter", enc)
|
|
}
|
|
|
|
if req.OccurrenceDateTime != nil && !req.OccurrenceDateTime.IsZero() {
|
|
payload.Set("occurrenceDateTime", req.OccurrenceDateTime.Format(time.RFC3339))
|
|
}
|
|
|
|
if req.PrimarySource != nil {
|
|
payload.Set("primarySource", *req.PrimarySource)
|
|
}
|
|
|
|
if req.Location != nil {
|
|
loc := map[string]interface{}{"reference": req.Location.Reference}
|
|
if req.Location.Display != "" {
|
|
loc["display"] = req.Location.Display
|
|
}
|
|
payload.Set("location", loc)
|
|
}
|
|
|
|
if req.LotNumber != "" {
|
|
payload.Set("lotNumber", req.LotNumber)
|
|
}
|
|
|
|
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 req.DoseQuantity != nil {
|
|
sys := req.DoseQuantity.System
|
|
if sys == "" {
|
|
sys = "http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm"
|
|
}
|
|
payload.Set("doseQuantity", map[string]interface{}{
|
|
"value": req.DoseQuantity.Value,
|
|
"unit": req.DoseQuantity.Unit,
|
|
"system": sys,
|
|
"code": req.DoseQuantity.Code,
|
|
})
|
|
}
|
|
|
|
if req.Route != nil {
|
|
sys := req.Route.System
|
|
if sys == "" {
|
|
sys = "http://www.whocc.no/atc"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": req.Route.Code}
|
|
if req.Route.Display != "" {
|
|
coding["display"] = req.Route.Display
|
|
}
|
|
routeConcept := map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
|
if req.Route.Text != "" {
|
|
routeConcept["text"] = req.Route.Text
|
|
}
|
|
payload.Set("route", routeConcept)
|
|
}
|
|
|
|
return payload
|
|
}
|