penambahan All case Satu sehat
This commit is contained in:
No files matched your search
@@ -1,30 +1,141 @@
|
||||
package episodeofcare
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req EpisodeOfCareRequest) satusehat.FHIRPayload {
|
||||
payload := satusehat.NewFHIRPayload("EpisodeOfCare").
|
||||
Set("status", req.Status).
|
||||
Set("patient", map[string]interface{}{
|
||||
"reference": "Patient/" + req.PatientID,
|
||||
"display": req.PatientName,
|
||||
})
|
||||
payload := satusehat.NewFHIRPayload("EpisodeOfCare")
|
||||
|
||||
if req.OrganizationID != "" {
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.EpisodeOfCareID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{
|
||||
"system": "http://sys-ids.kemkes.go.id/episode-of-care/" + orgID,
|
||||
"value": req.EpisodeOfCareID,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if req.Status != "" {
|
||||
payload.Set("status", req.Status)
|
||||
}
|
||||
|
||||
if len(req.StatusHistory) > 0 {
|
||||
var statusHistory []map[string]interface{}
|
||||
for _, sh := range req.StatusHistory {
|
||||
historyItem := map[string]interface{}{"status": sh.Status}
|
||||
period := map[string]interface{}{}
|
||||
if sh.PeriodStart != nil && !sh.PeriodStart.IsZero() {
|
||||
period["start"] = sh.PeriodStart.Format(time.RFC3339)
|
||||
}
|
||||
if sh.PeriodEnd != nil && !sh.PeriodEnd.IsZero() {
|
||||
period["end"] = sh.PeriodEnd.Format(time.RFC3339)
|
||||
}
|
||||
if len(period) > 0 {
|
||||
historyItem["period"] = period
|
||||
}
|
||||
statusHistory = append(statusHistory, historyItem)
|
||||
}
|
||||
payload.Set("statusHistory", statusHistory)
|
||||
}
|
||||
|
||||
if len(req.Type) > 0 {
|
||||
var types []map[string]interface{}
|
||||
for _, t := range req.Type {
|
||||
if t != nil {
|
||||
sys := t.System
|
||||
if sys == "" {
|
||||
sys = "http://terminology.kemkes.go.id/CodeSystem/episodeofcare-type"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": t.Code}
|
||||
if t.Display != "" {
|
||||
coding["display"] = t.Display
|
||||
}
|
||||
typeConcept := map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
if t.Text != "" {
|
||||
typeConcept["text"] = t.Text
|
||||
}
|
||||
types = append(types, typeConcept)
|
||||
}
|
||||
}
|
||||
payload.Set("type", types)
|
||||
}
|
||||
|
||||
if len(req.Diagnosis) > 0 {
|
||||
var diagnoses []map[string]interface{}
|
||||
for _, d := range req.Diagnosis {
|
||||
diagnosisItem := map[string]interface{}{}
|
||||
|
||||
if d.Condition != nil {
|
||||
condition := map[string]interface{}{"reference": d.Condition.Reference}
|
||||
if d.Condition.Display != "" {
|
||||
condition["display"] = d.Condition.Display
|
||||
}
|
||||
diagnosisItem["condition"] = condition
|
||||
}
|
||||
|
||||
if d.Role != nil {
|
||||
sys := d.Role.System
|
||||
if sys == "" {
|
||||
sys = "http://terminology.hl7.org/CodeSystem/diagnosis-role"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": d.Role.Code}
|
||||
if d.Role.Display != "" {
|
||||
coding["display"] = d.Role.Display
|
||||
}
|
||||
diagnosisItem["role"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
}
|
||||
|
||||
if d.Rank > 0 {
|
||||
diagnosisItem["rank"] = d.Rank
|
||||
}
|
||||
|
||||
diagnoses = append(diagnoses, diagnosisItem)
|
||||
}
|
||||
payload.Set("diagnosis", diagnoses)
|
||||
}
|
||||
|
||||
if req.PatientID != "" {
|
||||
subject := map[string]interface{}{"reference": "Patient/" + req.PatientID}
|
||||
if req.PatientName != "" {
|
||||
subject["display"] = req.PatientName
|
||||
}
|
||||
payload.Set("patient", subject)
|
||||
}
|
||||
|
||||
manageOrg := orgID
|
||||
if req.ManagingOrganization != "" {
|
||||
manageOrg = req.ManagingOrganization
|
||||
}
|
||||
if manageOrg != "" {
|
||||
payload.Set("managingOrganization", map[string]interface{}{
|
||||
"reference": "Organization/" + req.OrganizationID,
|
||||
"reference": "Organization/" + manageOrg,
|
||||
})
|
||||
}
|
||||
|
||||
period := map[string]interface{}{"start": req.PeriodStart.Format(time.RFC3339)}
|
||||
if req.PeriodEnd != nil {
|
||||
period["end"] = req.PeriodEnd.Format(time.RFC3339)
|
||||
if req.PeriodStart != nil && !req.PeriodStart.IsZero() {
|
||||
period := map[string]interface{}{"start": req.PeriodStart.Format(time.RFC3339)}
|
||||
if req.PeriodEnd != nil && !req.PeriodEnd.IsZero() {
|
||||
period["end"] = req.PeriodEnd.Format(time.RFC3339)
|
||||
}
|
||||
payload.Set("period", period)
|
||||
}
|
||||
|
||||
if req.CareManager != nil {
|
||||
cm := map[string]interface{}{"reference": req.CareManager.Reference}
|
||||
if req.CareManager.Display != "" {
|
||||
cm["display"] = req.CareManager.Display
|
||||
}
|
||||
payload.Set("careManager", cm)
|
||||
}
|
||||
payload.Set("period", period)
|
||||
|
||||
return payload
|
||||
}
|
||||
Reference in New Issue
Block a user