update All feture and service
This commit is contained in:
@@ -1,24 +1,18 @@
|
||||
package encounter
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req EncounterRequest) satusehat.FHIRPayload {
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
payload := satusehat.NewFHIRPayload("Encounter")
|
||||
|
||||
if orgID != "" && req.EncounterID != "" {
|
||||
if req.OrganizationID != "" && req.EncounterID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{
|
||||
"system": "http://sys-ids.kemkes.go.id/encounter/" + orgID,
|
||||
"system": "http://sys-ids.kemkes.go.id/encounter/" + req.OrganizationID,
|
||||
"value": req.EncounterID,
|
||||
},
|
||||
})
|
||||
@@ -36,7 +30,6 @@ func MapRequestToFHIR(req EncounterRequest) satusehat.FHIRPayload {
|
||||
case "IMP":
|
||||
classDisplay = "inpatient encounter"
|
||||
}
|
||||
|
||||
payload.Set("class", map[string]interface{}{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/v3-ActCode",
|
||||
"code": req.Class,
|
||||
@@ -44,22 +37,21 @@ func MapRequestToFHIR(req EncounterRequest) satusehat.FHIRPayload {
|
||||
})
|
||||
}
|
||||
|
||||
if req.Subject != nil {
|
||||
subj := map[string]interface{}{"reference": req.Subject.Reference}
|
||||
if req.Subject.Display != "" {
|
||||
subj["display"] = req.Subject.Display
|
||||
if req.PatientID != "" {
|
||||
subj := map[string]interface{}{"reference": "Patient/" + req.PatientID}
|
||||
if req.PatientName != "" {
|
||||
subj["display"] = req.PatientName
|
||||
}
|
||||
payload.Set("subject", subj)
|
||||
}
|
||||
|
||||
if len(req.Participant) > 0 {
|
||||
var participants []map[string]interface{}
|
||||
for _, p := range req.Participant {
|
||||
ind := map[string]interface{}{"reference": p.Reference}
|
||||
if p.Display != "" {
|
||||
ind["display"] = p.Display
|
||||
}
|
||||
participants = append(participants, map[string]interface{}{
|
||||
if req.PractitionerID != "" {
|
||||
ind := map[string]interface{}{"reference": "Practitioner/" + req.PractitionerID}
|
||||
if req.PractitionerName != "" {
|
||||
ind["display"] = req.PractitionerName
|
||||
}
|
||||
payload.Set("participant", []map[string]interface{}{
|
||||
{
|
||||
"type": []map[string]interface{}{
|
||||
{
|
||||
"coding": []map[string]interface{}{
|
||||
@@ -68,34 +60,24 @@ func MapRequestToFHIR(req EncounterRequest) satusehat.FHIRPayload {
|
||||
},
|
||||
},
|
||||
"individual": ind,
|
||||
})
|
||||
}
|
||||
payload.Set("participant", participants)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if len(req.Location) > 0 {
|
||||
var locations []map[string]interface{}
|
||||
for _, l := range req.Location {
|
||||
if l.Location != nil {
|
||||
locRef := map[string]interface{}{"reference": l.Location.Reference}
|
||||
if l.Location.Display != "" {
|
||||
locRef["display"] = l.Location.Display
|
||||
}
|
||||
locEntry := map[string]interface{}{"location": locRef}
|
||||
period := map[string]interface{}{}
|
||||
if l.PeriodStart != nil && !l.PeriodStart.IsZero() {
|
||||
period["start"] = l.PeriodStart.Format(time.RFC3339)
|
||||
}
|
||||
if l.PeriodEnd != nil && !l.PeriodEnd.IsZero() {
|
||||
period["end"] = l.PeriodEnd.Format(time.RFC3339)
|
||||
}
|
||||
if len(period) > 0 {
|
||||
locEntry["period"] = period
|
||||
}
|
||||
locations = append(locations, locEntry)
|
||||
}
|
||||
if req.LocationID != "" {
|
||||
locRef := map[string]interface{}{"reference": "Location/" + req.LocationID}
|
||||
if req.LocationName != "" {
|
||||
locRef["display"] = req.LocationName
|
||||
}
|
||||
payload.Set("location", locations)
|
||||
locEntry := map[string]interface{}{"location": locRef}
|
||||
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)
|
||||
}
|
||||
locEntry["period"] = period
|
||||
}
|
||||
payload.Set("location", []map[string]interface{}{locEntry})
|
||||
}
|
||||
|
||||
period := map[string]interface{}{}
|
||||
@@ -109,67 +91,40 @@ func MapRequestToFHIR(req EncounterRequest) satusehat.FHIRPayload {
|
||||
payload.Set("period", period)
|
||||
}
|
||||
|
||||
if len(req.Diagnosis) > 0 {
|
||||
var diagnoses []map[string]interface{}
|
||||
for _, d := range req.Diagnosis {
|
||||
diag := map[string]interface{}{}
|
||||
if d.Condition != nil {
|
||||
cond := map[string]interface{}{"reference": d.Condition.Reference}
|
||||
if d.Condition.Display != "" {
|
||||
cond["display"] = d.Condition.Display
|
||||
}
|
||||
diag["condition"] = cond
|
||||
}
|
||||
if d.Use != nil {
|
||||
sys := d.Use.System
|
||||
if sys == "" {
|
||||
sys = "http://terminology.hl7.org/CodeSystem/diagnosis-role"
|
||||
}
|
||||
useCoding := map[string]interface{}{"system": sys, "code": d.Use.Code}
|
||||
if d.Use.Display != "" {
|
||||
useCoding["display"] = d.Use.Display
|
||||
}
|
||||
diag["use"] = map[string]interface{}{"coding": []map[string]interface{}{useCoding}}
|
||||
}
|
||||
if d.Rank > 0 {
|
||||
diag["rank"] = d.Rank
|
||||
}
|
||||
diagnoses = append(diagnoses, diag)
|
||||
if req.DiagnosisConditionID != "" {
|
||||
diag := map[string]interface{}{
|
||||
"condition": map[string]interface{}{"reference": "Condition/" + req.DiagnosisConditionID},
|
||||
}
|
||||
payload.Set("diagnosis", diagnoses)
|
||||
if req.DiagnosisUseCode != "" {
|
||||
sys := req.DiagnosisUseSystem
|
||||
if sys == "" {
|
||||
sys = "http://terminology.hl7.org/CodeSystem/diagnosis-role"
|
||||
}
|
||||
useCoding := map[string]interface{}{"system": sys, "code": req.DiagnosisUseCode}
|
||||
if req.DiagnosisUseDisplay != "" {
|
||||
useCoding["display"] = req.DiagnosisUseDisplay
|
||||
}
|
||||
diag["use"] = map[string]interface{}{"coding": []map[string]interface{}{useCoding}}
|
||||
}
|
||||
if req.DiagnosisRank > 0 {
|
||||
diag["rank"] = req.DiagnosisRank
|
||||
}
|
||||
payload.Set("diagnosis", []map[string]interface{}{diag})
|
||||
}
|
||||
|
||||
if len(req.StatusHistory) > 0 {
|
||||
var statusHistories []map[string]interface{}
|
||||
for _, sh := range req.StatusHistory {
|
||||
shEntry := map[string]interface{}{"status": sh.Status}
|
||||
shp := map[string]interface{}{}
|
||||
if sh.PeriodStart != nil && !sh.PeriodStart.IsZero() {
|
||||
shp["start"] = sh.PeriodStart.Format(time.RFC3339)
|
||||
}
|
||||
if sh.PeriodEnd != nil && !sh.PeriodEnd.IsZero() {
|
||||
shp["end"] = sh.PeriodEnd.Format(time.RFC3339)
|
||||
}
|
||||
if len(shp) > 0 {
|
||||
shEntry["period"] = shp
|
||||
}
|
||||
statusHistories = append(statusHistories, shEntry)
|
||||
if req.Status != "" && req.PeriodStart != nil && !req.PeriodStart.IsZero() {
|
||||
shp := map[string]interface{}{"start": req.PeriodStart.Format(time.RFC3339)}
|
||||
if req.PeriodEnd != nil && !req.PeriodEnd.IsZero() {
|
||||
shp["end"] = req.PeriodEnd.Format(time.RFC3339)
|
||||
}
|
||||
payload.Set("statusHistory", statusHistories)
|
||||
} else if req.Status != "" && req.PeriodStart != nil && !req.PeriodStart.IsZero() {
|
||||
payload.Set("statusHistory", []map[string]interface{}{
|
||||
{
|
||||
"status": req.Status,
|
||||
"period": map[string]interface{}{
|
||||
"start": req.PeriodStart.Format(time.RFC3339),
|
||||
},
|
||||
},
|
||||
{"status": req.Status, "period": shp},
|
||||
})
|
||||
}
|
||||
|
||||
if orgID != "" {
|
||||
if req.OrganizationID != "" {
|
||||
payload.Set("serviceProvider", map[string]interface{}{
|
||||
"reference": "Organization/" + orgID,
|
||||
"reference": "Organization/" + req.OrganizationID,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user