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
@@ -3,7 +3,9 @@ package servicerequest
import "time"
type ServiceRequestRequest struct {
PatientID string `json:"patient_id,omitempty"`
OrganizationID string `json:"organization_id,omitempty"`
ServiceRequestID string `json:"service_request_id,omitempty"`
PatientID string `json:"patient_id,omitempty"`
PatientName string `json:"patient_name,omitempty"`
EncounterID string `json:"encounter_id,omitempty"`
RequesterID string `json:"requester_id,omitempty"`
@@ -9,6 +9,16 @@ import (
func MapRequestToFHIR(req ServiceRequestRequest) satusehat.FHIRPayload {
payload := satusehat.NewFHIRPayload("ServiceRequest")
if req.OrganizationID != "" && req.ServiceRequestID != "" {
payload.Set("identifier", []map[string]interface{}{
{
"system": "http://sys-ids.kemkes.go.id/servicerequest/" + req.OrganizationID,
"use": "official",
"value": req.ServiceRequestID,
},
})
}
if req.Status != "" {
payload.Set("status", req.Status)
}
@@ -27,12 +27,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,24 +17,29 @@ type Service interface {
}
type service struct {
repo Repository
repo Repository
orgID string
}
// NewService membuat service ServiceRequest baru.
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 ServiceRequestRequest) (*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 ServiceRequestRequest) (*satusehat.FHIRResponse, error) {
if id == "" {
return nil, errors.NewValidationError().Message("ServiceRequest ID is required").Build()
}
if req.OrganizationID == "" {
req.OrganizationID = s.orgID
}
fhirPayload := MapRequestToFHIR(req)
fhirPayload.Set("id", id)