update All feture and service
This commit is contained in:
No files matched your search
@@ -2,26 +2,34 @@ package careplan
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"service/internal/satusehat/common"
|
||||
)
|
||||
|
||||
type CarePlanRequest struct {
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
CarePlanID string `json:"care_plan_id,omitempty"`
|
||||
Status string `json:"status" binding:"required,oneof=draft active on-hold revoked completed entered-in-error unknown"`
|
||||
Intent string `json:"intent" binding:"required,oneof=proposal plan order option"`
|
||||
Category []common.CodeableConceptDTO `json:"category,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientDisplay string `json:"patient_display,omitempty"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
EncounterDisplay string `json:"encounter_display,omitempty"`
|
||||
CreatedDate *time.Time `json:"created_date,omitempty"`
|
||||
AuthorID string `json:"author_id,omitempty"` // cth: "N10000001"
|
||||
AuthorDisplay string `json:"author_display,omitempty"`
|
||||
GoalIDs []string `json:"goal_ids,omitempty"` // Akan direferensikan sebagai "Goal/{id}"
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
CarePlanID string `json:"care_plan_id,omitempty"`
|
||||
|
||||
Status string `json:"status" binding:"required,oneof=draft active on-hold revoked completed entered-in-error unknown"`
|
||||
Intent string `json:"intent" binding:"required,oneof=proposal plan order option"`
|
||||
|
||||
CategoryCode string `json:"category_code,omitempty"`
|
||||
CategoryDisplay string `json:"category_display,omitempty"`
|
||||
CategorySystem string `json:"category_system,omitempty"`
|
||||
|
||||
Title string `json:"title,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientDisplay string `json:"patient_display,omitempty"`
|
||||
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
EncounterDisplay string `json:"encounter_display,omitempty"`
|
||||
|
||||
CreatedDate *time.Time `json:"created_date,omitempty"`
|
||||
|
||||
AuthorID string `json:"author_id,omitempty"`
|
||||
AuthorDisplay string `json:"author_display,omitempty"`
|
||||
|
||||
GoalIDs []string `json:"goal_ids,omitempty"`
|
||||
}
|
||||
|
||||
type CarePlanPatchRequest []map[string]interface{}
|
||||
@@ -1,22 +1,17 @@
|
||||
package careplan
|
||||
|
||||
import (
|
||||
"os"
|
||||
"service/internal/interfaces/satusehat"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req CarePlanRequest) satusehat.FHIRPayload {
|
||||
payload := satusehat.NewFHIRPayload("CarePlan")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.CarePlanID != "" {
|
||||
if req.OrganizationID != "" && req.CarePlanID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{"system": "http://sys-ids.kemkes.go.id/careplan/" + orgID, "use": "official", "value": req.CarePlanID},
|
||||
{"system": "http://sys-ids.kemkes.go.id/careplan/" + req.OrganizationID, "use": "official", "value": req.CarePlanID},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -26,31 +21,28 @@ func MapRequestToFHIR(req CarePlanRequest) satusehat.FHIRPayload {
|
||||
if req.Intent != "" {
|
||||
payload.Set("intent", req.Intent)
|
||||
}
|
||||
if len(req.Category) > 0 {
|
||||
var categories []map[string]interface{}
|
||||
for _, cat := range req.Category {
|
||||
sys := cat.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct" // Default value jika kosong
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": cat.Code}
|
||||
if cat.Display != "" {
|
||||
coding["display"] = cat.Display
|
||||
}
|
||||
concept := map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
if cat.Text != "" {
|
||||
concept["text"] = cat.Text
|
||||
}
|
||||
categories = append(categories, concept)
|
||||
|
||||
if req.CategoryCode != "" {
|
||||
sys := req.CategorySystem
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
payload.Set("category", categories)
|
||||
coding := map[string]interface{}{"system": sys, "code": req.CategoryCode}
|
||||
if req.CategoryDisplay != "" {
|
||||
coding["display"] = req.CategoryDisplay
|
||||
}
|
||||
payload.Set("category", []map[string]interface{}{
|
||||
{"coding": []map[string]interface{}{coding}},
|
||||
})
|
||||
}
|
||||
|
||||
if req.Title != "" {
|
||||
payload.Set("title", req.Title)
|
||||
}
|
||||
if req.Description != "" {
|
||||
payload.Set("description", req.Description)
|
||||
}
|
||||
|
||||
if req.PatientID != "" {
|
||||
subject := map[string]interface{}{"reference": "Patient/" + req.PatientID}
|
||||
if req.PatientDisplay != "" {
|
||||
@@ -76,7 +68,7 @@ func MapRequestToFHIR(req CarePlanRequest) satusehat.FHIRPayload {
|
||||
payload.Set("created", req.CreatedDate.Format(time.RFC3339))
|
||||
}
|
||||
if len(req.GoalIDs) > 0 {
|
||||
var goals []map[string]interface{}
|
||||
goals := make([]map[string]interface{}, 0, len(req.GoalIDs))
|
||||
for _, id := range req.GoalIDs {
|
||||
goals = append(goals, map[string]interface{}{"reference": "Goal/" + id})
|
||||
}
|
||||
|
||||
@@ -20,12 +20,8 @@ type repository struct{ client satusehat.SatuSehatClient }
|
||||
|
||||
func NewRepository(client satusehat.SatuSehatClient) Repository { return &repository{client: client} }
|
||||
|
||||
type hiddenCtx struct {
|
||||
context.Context
|
||||
}
|
||||
|
||||
func (r *repository) executeRequest(ctx context.Context, method, endpoint string, req interface{}) (*satusehat.FHIRResponse, error) {
|
||||
resp, err := r.client.DoRequest(hiddenCtx{ctx}, method, endpoint, req)
|
||||
resp, err := r.client.DoRequest(ctx, method, endpoint, req)
|
||||
if err != nil {
|
||||
return nil, errors.InternalError().Message("Failed to execute request to SatuSehat").Cause(err).Build()
|
||||
}
|
||||
|
||||
@@ -14,16 +14,27 @@ type Service interface {
|
||||
GetByID(ctx context.Context, id string) (*satusehat.FHIRResponse, error)
|
||||
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 CarePlanRequest) (*satusehat.FHIRResponse, error) {
|
||||
if req.OrganizationID == "" {
|
||||
req.OrganizationID = s.orgID
|
||||
}
|
||||
return s.repo.Create(ctx, MapRequestToFHIR(req))
|
||||
}
|
||||
func (s *service) Update(ctx context.Context, id string, req CarePlanRequest) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("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