167 lines
4.7 KiB
Go
167 lines
4.7 KiB
Go
package specimen
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"service/internal/interfaces/satusehat"
|
|
)
|
|
|
|
func MapRequestToFHIR(req SpecimenRequest) satusehat.FHIRPayload {
|
|
payload := satusehat.NewFHIRPayload("Specimen")
|
|
|
|
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
|
if orgID == "" {
|
|
orgID = req.OrganizationID
|
|
}
|
|
|
|
if orgID != "" && req.SpecimenID != "" {
|
|
payload.Set("identifier", []map[string]interface{}{
|
|
{
|
|
"system": "http://sys-ids.kemkes.go.id/specimen/" + orgID,
|
|
"value": req.SpecimenID,
|
|
"assigner": map[string]interface{}{
|
|
"reference": "Organization/" + orgID,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
if req.Status != "" {
|
|
payload.Set("status", req.Status)
|
|
}
|
|
|
|
if req.Type != nil {
|
|
sys := req.Type.System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": req.Type.Code}
|
|
if req.Type.Display != "" {
|
|
coding["display"] = req.Type.Display
|
|
}
|
|
payload.Set("type", map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
|
}
|
|
|
|
if req.Collection != nil {
|
|
coll := map[string]interface{}{}
|
|
if req.Collection.Collector != nil {
|
|
collector := map[string]interface{}{"reference": req.Collection.Collector.Reference}
|
|
if req.Collection.Collector.Display != "" {
|
|
collector["display"] = req.Collection.Collector.Display
|
|
}
|
|
coll["collector"] = collector
|
|
}
|
|
|
|
if req.Collection.CollectedDateTime != nil && !req.Collection.CollectedDateTime.IsZero() {
|
|
coll["collectedDateTime"] = req.Collection.CollectedDateTime.Format(time.RFC3339)
|
|
}
|
|
|
|
if req.Collection.Quantity != nil {
|
|
sys := req.Collection.Quantity.System
|
|
if sys == "" {
|
|
sys = "http://unitsofmeasure.org"
|
|
}
|
|
coll["quantity"] = map[string]interface{}{
|
|
"value": req.Collection.Quantity.Value,
|
|
"unit": req.Collection.Quantity.Unit,
|
|
"system": sys,
|
|
"code": req.Collection.Quantity.Code,
|
|
}
|
|
}
|
|
|
|
if req.Collection.Method != nil {
|
|
sys := req.Collection.Method.System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": req.Collection.Method.Code}
|
|
if req.Collection.Method.Display != "" {
|
|
coding["display"] = req.Collection.Method.Display
|
|
}
|
|
coll["method"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
|
}
|
|
|
|
if req.Collection.BodySite != nil {
|
|
sys := req.Collection.BodySite.System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": req.Collection.BodySite.Code}
|
|
if req.Collection.BodySite.Display != "" {
|
|
coding["display"] = req.Collection.BodySite.Display
|
|
}
|
|
coll["bodySite"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
|
}
|
|
|
|
if req.Collection.FastingStatus != nil {
|
|
sys := req.Collection.FastingStatus.System
|
|
if sys == "" {
|
|
sys = "http://terminology.hl7.org/CodeSystem/v2-0916"
|
|
}
|
|
coding := map[string]interface{}{"system": sys, "code": req.Collection.FastingStatus.Code}
|
|
if req.Collection.FastingStatus.Display != "" {
|
|
coding["display"] = req.Collection.FastingStatus.Display
|
|
}
|
|
coll["fastingStatusCodeableConcept"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
|
}
|
|
|
|
if len(coll) > 0 {
|
|
payload.Set("collection", coll)
|
|
}
|
|
}
|
|
|
|
if len(req.Processing) > 0 {
|
|
var processings []map[string]interface{}
|
|
for _, proc := range req.Processing {
|
|
p := map[string]interface{}{}
|
|
if proc.Procedure != nil {
|
|
sys := proc.Procedure.System
|
|
if sys == "" {
|
|
sys = "http://snomed.info/sct"
|
|
}
|
|
p["procedure"] = map[string]interface{}{
|
|
"coding": []map[string]interface{}{
|
|
{"system": sys, "code": proc.Procedure.Code, "display": proc.Procedure.Display},
|
|
},
|
|
}
|
|
}
|
|
if proc.TimeDateTime != nil && !proc.TimeDateTime.IsZero() {
|
|
p["timeDateTime"] = proc.TimeDateTime.Format(time.RFC3339)
|
|
}
|
|
processings = append(processings, p)
|
|
}
|
|
payload.Set("processing", processings)
|
|
}
|
|
|
|
if len(req.Conditions) > 0 {
|
|
var conditions []map[string]interface{}
|
|
for _, c := range req.Conditions {
|
|
conditions = append(conditions, map[string]interface{}{"text": c})
|
|
}
|
|
payload.Set("condition", conditions)
|
|
}
|
|
|
|
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 len(req.Request) > 0 {
|
|
var requests []map[string]interface{}
|
|
for _, r := range req.Request {
|
|
requests = append(requests, map[string]interface{}{"reference": r.Reference})
|
|
}
|
|
payload.Set("request", requests)
|
|
}
|
|
|
|
if req.ReceivedDateTime != nil && !req.ReceivedDateTime.IsZero() {
|
|
payload.Set("receivedTime", req.ReceivedDateTime.Format(time.RFC3339))
|
|
}
|
|
|
|
return payload
|
|
}
|