penambahan All case Satu sehat
This commit is contained in:
@@ -1,41 +1,169 @@
|
||||
package diagnosticreport
|
||||
|
||||
import (
|
||||
"service/internal/interfaces/satusehat"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req DiagnosticReportRequest) satusehat.FHIRPayload {
|
||||
return satusehat.NewFHIRPayload("DiagnosticReport").
|
||||
Set("status", req.Status).
|
||||
Set("category", []map[string]interface{}{
|
||||
payload := satusehat.NewFHIRPayload("DiagnosticReport")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.DiagnosticID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/v2-0074",
|
||||
"code": req.CategoryCode,
|
||||
"display": req.CategoryDisplay,
|
||||
},
|
||||
},
|
||||
"system": "http://sys-ids.kemkes.go.id/diagnostic/" + orgID + "/lab",
|
||||
"use": "official",
|
||||
"value": req.DiagnosticID,
|
||||
},
|
||||
}).
|
||||
Set("code", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://loinc.org",
|
||||
"code": req.Code,
|
||||
"display": req.Display,
|
||||
},
|
||||
},
|
||||
}).
|
||||
Set("subject", map[string]interface{}{
|
||||
})
|
||||
}
|
||||
|
||||
if req.Status != "" {
|
||||
payload.Set("status", req.Status)
|
||||
}
|
||||
|
||||
if len(req.Category) > 0 {
|
||||
var categories []map[string]interface{}
|
||||
for _, c := range req.Category {
|
||||
if c != nil {
|
||||
sys := c.System
|
||||
if sys == "" {
|
||||
sys = "http://terminology.hl7.org/CodeSystem/v2-0074"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": c.Code}
|
||||
if c.Display != "" {
|
||||
coding["display"] = c.Display
|
||||
}
|
||||
categories = append(categories, map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
||||
}
|
||||
}
|
||||
payload.Set("category", categories)
|
||||
}
|
||||
|
||||
if req.Code != nil {
|
||||
sys := req.Code.System
|
||||
if sys == "" {
|
||||
sys = "http://loinc.org"
|
||||
}
|
||||
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 != "" {
|
||||
payload.Set("subject", map[string]interface{}{
|
||||
"reference": "Patient/" + req.PatientID,
|
||||
"display": req.PatientName,
|
||||
}).
|
||||
Set("encounter", map[string]interface{}{"reference": "Encounter/" + req.EncounterID}).
|
||||
Set("performer", []map[string]interface{}{
|
||||
{"reference": "Practitioner/" + req.PractitionerID, "display": req.PractitionerName},
|
||||
}).
|
||||
Set("issued", req.Issued.Format(time.RFC3339)).
|
||||
Set("conclusion", req.Conclusion)
|
||||
})
|
||||
}
|
||||
|
||||
if req.EncounterID != "" {
|
||||
payload.Set("encounter", map[string]interface{}{
|
||||
"reference": "Encounter/" + req.EncounterID,
|
||||
})
|
||||
}
|
||||
|
||||
if req.EffectiveDateTime != nil && !req.EffectiveDateTime.IsZero() {
|
||||
payload.Set("effectiveDateTime", req.EffectiveDateTime.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if req.Issued != nil && !req.Issued.IsZero() {
|
||||
payload.Set("issued", req.Issued.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if len(req.Performer) > 0 {
|
||||
var performers []map[string]interface{}
|
||||
for _, p := range req.Performer {
|
||||
perf := map[string]interface{}{"reference": p.Reference}
|
||||
if p.Display != "" {
|
||||
perf["display"] = p.Display
|
||||
}
|
||||
performers = append(performers, perf)
|
||||
}
|
||||
payload.Set("performer", performers)
|
||||
}
|
||||
|
||||
if len(req.Result) > 0 {
|
||||
var results []map[string]interface{}
|
||||
for _, r := range req.Result {
|
||||
res := map[string]interface{}{"reference": r.Reference}
|
||||
if r.Display != "" {
|
||||
res["display"] = r.Display
|
||||
}
|
||||
results = append(results, res)
|
||||
}
|
||||
payload.Set("result", results)
|
||||
}
|
||||
|
||||
if len(req.Specimen) > 0 {
|
||||
var specimens []map[string]interface{}
|
||||
for _, s := range req.Specimen {
|
||||
spec := map[string]interface{}{"reference": s.Reference}
|
||||
if s.Display != "" {
|
||||
spec["display"] = s.Display
|
||||
}
|
||||
specimens = append(specimens, spec)
|
||||
}
|
||||
payload.Set("specimen", specimens)
|
||||
}
|
||||
|
||||
if len(req.BasedOn) > 0 {
|
||||
var basedOns []map[string]interface{}
|
||||
for _, b := range req.BasedOn {
|
||||
bo := map[string]interface{}{"reference": b.Reference}
|
||||
if b.Display != "" {
|
||||
bo["display"] = b.Display
|
||||
}
|
||||
basedOns = append(basedOns, bo)
|
||||
}
|
||||
payload.Set("basedOn", basedOns)
|
||||
}
|
||||
|
||||
if len(req.ImagingStudy) > 0 {
|
||||
var imagingStudies []map[string]interface{}
|
||||
for _, i := range req.ImagingStudy {
|
||||
is := map[string]interface{}{"reference": i.Reference}
|
||||
if i.Display != "" {
|
||||
is["display"] = i.Display
|
||||
}
|
||||
imagingStudies = append(imagingStudies, is)
|
||||
}
|
||||
payload.Set("imagingStudy", imagingStudies)
|
||||
}
|
||||
|
||||
if len(req.ConclusionCode) > 0 {
|
||||
var concCodes []map[string]interface{}
|
||||
for _, c := range req.ConclusionCode {
|
||||
if c != nil {
|
||||
sys := c.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": c.Code}
|
||||
if c.Display != "" {
|
||||
coding["display"] = c.Display
|
||||
}
|
||||
concCodes = append(concCodes, map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
||||
}
|
||||
}
|
||||
payload.Set("conclusionCode", concCodes)
|
||||
}
|
||||
|
||||
if req.Conclusion != "" {
|
||||
payload.Set("conclusion", req.Conclusion)
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
Reference in New Issue
Block a user