penambahan All case Satu sehat
This commit is contained in:
No files matched your search
@@ -1,18 +1,27 @@
|
||||
package careplan
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"service/internal/satusehat/common"
|
||||
)
|
||||
|
||||
type CarePlanRequest struct {
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientName string `json:"patient_name" binding:"required"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
PractitionerID string `json:"practitioner_id" binding:"required"`
|
||||
PractitionerName string `json:"practitioner_name" binding:"required"`
|
||||
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"`
|
||||
Title string `json:"title" binding:"required"`
|
||||
Description string `json:"description" binding:"required"`
|
||||
CreatedDate time.Time `json:"created_date" binding:"required"`
|
||||
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}"
|
||||
}
|
||||
|
||||
type CarePlanPatchRequest []map[string]interface{}
|
||||
@@ -1,24 +1,87 @@
|
||||
package careplan
|
||||
|
||||
import (
|
||||
"os"
|
||||
"service/internal/interfaces/satusehat"
|
||||
"time"
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req CarePlanRequest) satusehat.FHIRPayload {
|
||||
return satusehat.NewFHIRPayload("CarePlan").
|
||||
Set("status", req.Status).
|
||||
Set("intent", req.Intent).
|
||||
Set("title", req.Title).
|
||||
Set("description", req.Description).
|
||||
Set("subject", map[string]interface{}{
|
||||
"reference": "Patient/" + req.PatientID,
|
||||
"display": req.PatientName,
|
||||
}).
|
||||
Set("encounter", map[string]interface{}{"reference": "Encounter/" + req.EncounterID}).
|
||||
Set("author", map[string]interface{}{
|
||||
"reference": "Practitioner/" + req.PractitionerID,
|
||||
"display": req.PractitionerName,
|
||||
}).
|
||||
Set("created", req.CreatedDate.Format(time.RFC3339))
|
||||
payload := satusehat.NewFHIRPayload("CarePlan")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.CarePlanID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{"system": "http://sys-ids.kemkes.go.id/careplan/" + orgID, "use": "official", "value": req.CarePlanID},
|
||||
})
|
||||
}
|
||||
|
||||
if req.Status != "" {
|
||||
payload.Set("status", req.Status)
|
||||
}
|
||||
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)
|
||||
}
|
||||
payload.Set("category", categories)
|
||||
}
|
||||
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 != "" {
|
||||
subject["display"] = req.PatientDisplay
|
||||
}
|
||||
payload.Set("subject", subject)
|
||||
}
|
||||
if req.EncounterID != "" {
|
||||
encounter := map[string]interface{}{"reference": "Encounter/" + req.EncounterID}
|
||||
if req.EncounterDisplay != "" {
|
||||
encounter["display"] = req.EncounterDisplay
|
||||
}
|
||||
payload.Set("encounter", encounter)
|
||||
}
|
||||
if req.AuthorID != "" {
|
||||
author := map[string]interface{}{"reference": "Practitioner/" + req.AuthorID}
|
||||
if req.AuthorDisplay != "" {
|
||||
author["display"] = req.AuthorDisplay
|
||||
}
|
||||
payload.Set("author", author)
|
||||
}
|
||||
if req.CreatedDate != nil && !req.CreatedDate.IsZero() {
|
||||
payload.Set("created", req.CreatedDate.Format(time.RFC3339))
|
||||
}
|
||||
if len(req.GoalIDs) > 0 {
|
||||
var goals []map[string]interface{}
|
||||
for _, id := range req.GoalIDs {
|
||||
goals = append(goals, map[string]interface{}{"reference": "Goal/" + id})
|
||||
}
|
||||
payload.Set("goal", goals)
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"service/internal/interfaces/satusehat"
|
||||
"service/pkg/errors"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
@@ -19,14 +20,22 @@ 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(ctx, method, endpoint, req)
|
||||
resp, err := r.client.DoRequest(hiddenCtx{ctx}, method, endpoint, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.InternalError().Message("Failed to execute request to SatuSehat").Cause(err).Build()
|
||||
}
|
||||
var result map[string]interface{}
|
||||
if err := json.Unmarshal(resp, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
|
||||
return nil, errors.InternalError().Message("Failed to parse SatuSehat response").Cause(err).Metadata("raw_response", string(resp)).Build()
|
||||
}
|
||||
|
||||
if resourceType, ok := result["resourceType"].(string); ok && resourceType == "OperationOutcome" {
|
||||
return nil, errors.ParseSatuSehatError(result)
|
||||
}
|
||||
var resourceID string
|
||||
if id, ok := result["id"].(string); ok {
|
||||
|
||||
@@ -24,12 +24,23 @@ func (s *service) Update(ctx context.Context, id string, req CarePlanRequest) (*
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("ID is required").Build()
|
||||
}
|
||||
return s.repo.Update(ctx, id, MapRequestToFHIR(req).Set("id", id))
|
||||
payload := MapRequestToFHIR(req)
|
||||
payload.Set("id", id)
|
||||
return s.repo.Update(ctx, id, payload)
|
||||
}
|
||||
func (s *service) Patch(ctx context.Context, id string, req CarePlanPatchRequest) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("CarePlan ID is required").Build()
|
||||
}
|
||||
if len(req) == 0 {
|
||||
return nil, errors.NewValidationError().Message("Patch payload cannot be empty").Build()
|
||||
}
|
||||
return s.repo.Patch(ctx, id, req)
|
||||
}
|
||||
func (s *service) GetByID(ctx context.Context, id string) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("CarePlan ID is required").Build()
|
||||
}
|
||||
return s.repo.GetByID(ctx, id)
|
||||
}
|
||||
func (s *service) Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error) {
|
||||
|
||||
Reference in New Issue
Block a user