142 lines
3.9 KiB
Go
142 lines
3.9 KiB
Go
package medicationstatement
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"service/internal/interfaces/satusehat"
|
|
)
|
|
|
|
func MapRequestToFHIR(req MedicationStatementRequest) satusehat.FHIRPayload {
|
|
payload := satusehat.NewFHIRPayload("MedicationStatement")
|
|
|
|
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
|
if orgID == "" {
|
|
orgID = req.OrganizationID
|
|
}
|
|
|
|
if orgID != "" && req.StatementID != "" {
|
|
payload.Set("identifier", []map[string]interface{}{
|
|
{
|
|
"system": "http://sys-ids.kemkes.go.id/medicationstatement/" + orgID,
|
|
"use": "official",
|
|
"value": req.StatementID,
|
|
},
|
|
})
|
|
}
|
|
|
|
if req.Status != "" {
|
|
payload.Set("status", req.Status)
|
|
}
|
|
|
|
if req.Category != nil {
|
|
sys := req.Category.System
|
|
if sys == "" {
|
|
sys = "http://terminology.hl7.org/CodeSystem/medication-statement-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.Medication != nil {
|
|
sys := req.Medication.System
|
|
if sys == "" {
|
|
sys = "http://sys-ids.kemkes.go.id/kfa"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": req.Medication.Code}
|
|
if req.Medication.Display != "" {
|
|
coding["display"] = req.Medication.Display
|
|
}
|
|
medConcept := map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
|
if req.Medication.Text != "" {
|
|
medConcept["text"] = req.Medication.Text
|
|
}
|
|
payload.Set("medicationCodeableConcept", medConcept)
|
|
}
|
|
|
|
if req.Subject != nil {
|
|
subject := map[string]interface{}{"reference": req.Subject.Reference}
|
|
if req.Subject.Display != "" {
|
|
subject["display"] = req.Subject.Display
|
|
}
|
|
payload.Set("subject", subject)
|
|
}
|
|
|
|
if req.Context != nil {
|
|
context := map[string]interface{}{"reference": req.Context.Reference}
|
|
if req.Context.Display != "" {
|
|
context["display"] = req.Context.Display
|
|
}
|
|
payload.Set("context", context)
|
|
}
|
|
|
|
if req.EffectiveDateTime != nil && !req.EffectiveDateTime.IsZero() {
|
|
payload.Set("effectiveDateTime", req.EffectiveDateTime.Format(time.RFC3339))
|
|
}
|
|
|
|
if req.DateAsserted != nil && !req.DateAsserted.IsZero() {
|
|
payload.Set("dateAsserted", req.DateAsserted.Format(time.RFC3339))
|
|
}
|
|
|
|
if req.InformationSource != nil {
|
|
infoSource := map[string]interface{}{"reference": req.InformationSource.Reference}
|
|
if req.InformationSource.Display != "" {
|
|
infoSource["display"] = req.InformationSource.Display
|
|
}
|
|
payload.Set("informationSource", infoSource)
|
|
}
|
|
|
|
if len(req.Dosage) > 0 {
|
|
var dosages []map[string]interface{}
|
|
for _, d := range req.Dosage {
|
|
dosageObj := map[string]interface{}{}
|
|
if d.Sequence > 0 {
|
|
dosageObj["sequence"] = d.Sequence
|
|
}
|
|
if d.Text != "" {
|
|
dosageObj["text"] = d.Text
|
|
}
|
|
if d.PatientInstruction != "" {
|
|
dosageObj["patientInstruction"] = d.PatientInstruction
|
|
}
|
|
if d.Route != nil {
|
|
sys := d.Route.System
|
|
if sys == "" {
|
|
sys = "http://www.whocc.no/atc"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": d.Route.Code}
|
|
if d.Route.Display != "" {
|
|
coding["display"] = d.Route.Display
|
|
}
|
|
dosageObj["route"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
|
}
|
|
if len(d.DoseAndRate) > 0 {
|
|
var doseAndRates []map[string]interface{}
|
|
for _, dar := range d.DoseAndRate {
|
|
if dar.DoseQuantity != nil {
|
|
dq := dar.DoseQuantity
|
|
sys := dq.System
|
|
if sys == "" {
|
|
sys = "http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm"
|
|
}
|
|
doseQuantity := map[string]interface{}{"value": dq.Value, "unit": dq.Unit, "system": sys, "code": dq.Code}
|
|
doseAndRates = append(doseAndRates, map[string]interface{}{"doseQuantity": doseQuantity})
|
|
}
|
|
}
|
|
if len(doseAndRates) > 0 {
|
|
dosageObj["doseAndRate"] = doseAndRates
|
|
}
|
|
}
|
|
dosages = append(dosages, dosageObj)
|
|
}
|
|
payload.Set("dosage", dosages)
|
|
}
|
|
|
|
return payload
|
|
}
|