update All feture and service

This commit is contained in:
meninjar
2026-06-03 02:54:26 +00:00
parent af32d9cfdd
commit ce0fa1a291
98 changed files with 272469 additions and 1606 deletions
@@ -1,7 +1,6 @@
package medication
import (
"os"
"time"
"service/internal/interfaces/satusehat"
@@ -10,10 +9,7 @@ import (
func MapRequestToFHIR(req MedicationRequest) satusehat.FHIRPayload {
payload := satusehat.NewFHIRPayload("Medication")
orgID := os.Getenv("SATUSEHAT_ORG_ID")
if orgID == "" {
orgID = req.OrganizationID
}
orgID := req.OrganizationID
// Set Meta Profile secara otomatis
payload.Set("meta", map[string]interface{}{
@@ -26,12 +26,8 @@ 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()
}
@@ -17,22 +17,28 @@ type Service interface {
}
type service struct {
repo Repository
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 MedicationRequest) (*satusehat.FHIRResponse, error) {
fhirPayload := MapRequestToFHIR(req)
return s.repo.Create(ctx, fhirPayload)
if req.OrganizationID == "" {
req.OrganizationID = s.orgID
}
return s.repo.Create(ctx, MapRequestToFHIR(req))
}
func (s *service) Update(ctx context.Context, id string, req MedicationRequest) (*satusehat.FHIRResponse, error) {
if id == "" {
return nil, errors.NewValidationError().Message("Medication ID is required").Build()
}
if req.OrganizationID == "" {
req.OrganizationID = s.orgID
}
fhirPayload := MapRequestToFHIR(req)
fhirPayload.Set("id", id)
return s.repo.Update(ctx, id, fhirPayload)