update All feture and service
This commit is contained in:
No files matched your search
@@ -1,40 +1,33 @@
|
||||
package encounter
|
||||
|
||||
import (
|
||||
"service/internal/satusehat/common"
|
||||
"service/pkg/utils/custom"
|
||||
)
|
||||
|
||||
type EncounterRequest struct {
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
EncounterID string `json:"encounter_id,omitempty"`
|
||||
Status string `json:"status" binding:"required,oneof=planned arrived triaged in-progress onleave finished cancelled entered-in-error unknown"`
|
||||
Class string `json:"class" binding:"required,oneof=AMB EMER IMP"`
|
||||
Subject *common.ReferenceDTO `json:"subject" binding:"required"`
|
||||
Participant []common.ReferenceDTO `json:"participant,omitempty"`
|
||||
Location []LocationDTO `json:"location,omitempty"`
|
||||
PeriodStart *custom.CustomTime `json:"period_start" binding:"required"`
|
||||
PeriodEnd *custom.CustomTime `json:"period_end,omitempty"`
|
||||
Diagnosis []DiagnosisDTO `json:"diagnosis,omitempty"`
|
||||
StatusHistory []StatusHistoryDTO `json:"status_history,omitempty"`
|
||||
}
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
EncounterID string `json:"encounter_id,omitempty"`
|
||||
|
||||
type LocationDTO struct {
|
||||
Location *common.ReferenceDTO `json:"location,omitempty"`
|
||||
PeriodStart *custom.CustomTime `json:"period_start,omitempty"`
|
||||
PeriodEnd *custom.CustomTime `json:"period_end,omitempty"`
|
||||
}
|
||||
Status string `json:"status" binding:"required,oneof=planned arrived triaged in-progress onleave finished cancelled entered-in-error unknown"`
|
||||
Class string `json:"class" binding:"required,oneof=AMB EMER IMP"`
|
||||
|
||||
type DiagnosisDTO struct {
|
||||
Condition *common.ReferenceDTO `json:"condition,omitempty"`
|
||||
Use *common.CodeableConceptDTO `json:"use,omitempty"`
|
||||
Rank int `json:"rank,omitempty"`
|
||||
}
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientName string `json:"patient_name,omitempty"`
|
||||
|
||||
type StatusHistoryDTO struct {
|
||||
Status string `json:"status,omitempty"`
|
||||
PeriodStart *custom.CustomTime `json:"period_start,omitempty"`
|
||||
PractitionerID string `json:"practitioner_id,omitempty"`
|
||||
PractitionerName string `json:"practitioner_name,omitempty"`
|
||||
|
||||
LocationID string `json:"location_id,omitempty"`
|
||||
LocationName string `json:"location_name,omitempty"`
|
||||
|
||||
PeriodStart *custom.CustomTime `json:"period_start" binding:"required"`
|
||||
PeriodEnd *custom.CustomTime `json:"period_end,omitempty"`
|
||||
|
||||
DiagnosisConditionID string `json:"diagnosis_condition_id,omitempty"`
|
||||
DiagnosisUseSystem string `json:"diagnosis_use_system,omitempty"`
|
||||
DiagnosisUseCode string `json:"diagnosis_use_code,omitempty"`
|
||||
DiagnosisUseDisplay string `json:"diagnosis_use_display,omitempty"`
|
||||
DiagnosisRank int `json:"diagnosis_rank,omitempty"`
|
||||
}
|
||||
|
||||
type EncounterPatchRequest []map[string]interface{}
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -29,12 +29,8 @@ func NewRepository(client satusehat.SatuSehatClient, db database.Service) Reposi
|
||||
return &repository{client: client, db: db}
|
||||
}
|
||||
|
||||
type hiddenCtx struct {
|
||||
context.Context
|
||||
}
|
||||
|
||||
func (r *repository) executeRequest(ctx context.Context, method, endpoint string, payload interface{}) (*satusehat.FHIRResponse, error) {
|
||||
resp, err := r.client.DoRequest(hiddenCtx{ctx}, method, endpoint, payload)
|
||||
resp, err := r.client.DoRequest(ctx, method, endpoint, payload)
|
||||
if err != nil {
|
||||
return nil, errors.InternalError().Message("Failed to execute request to SatuSehat").Cause(err).Build()
|
||||
}
|
||||
|
||||
@@ -15,13 +15,19 @@ type Service interface {
|
||||
Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error)
|
||||
}
|
||||
|
||||
type service struct{ repo Repository }
|
||||
type service struct {
|
||||
repo Repository
|
||||
orgID string
|
||||
}
|
||||
|
||||
func NewService(repo Repository) Service {
|
||||
return &service{repo: repo}
|
||||
func NewService(repo Repository, orgID string) Service {
|
||||
return &service{repo: repo, orgID: orgID}
|
||||
}
|
||||
|
||||
func (s *service) Create(ctx context.Context, req EncounterRequest) (*satusehat.FHIRResponse, error) {
|
||||
if req.OrganizationID == "" {
|
||||
req.OrganizationID = s.orgID
|
||||
}
|
||||
return s.repo.Create(ctx, MapRequestToFHIR(req))
|
||||
}
|
||||
|
||||
@@ -29,6 +35,9 @@ func (s *service) Update(ctx context.Context, id string, req EncounterRequest) (
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("Encounter ID is required").Build()
|
||||
}
|
||||
if req.OrganizationID == "" {
|
||||
req.OrganizationID = s.orgID
|
||||
}
|
||||
payload := MapRequestToFHIR(req)
|
||||
payload.Set("id", id)
|
||||
return s.repo.Update(ctx, id, payload)
|
||||
|
||||
Reference in New Issue
Block a user