penambahan All case Satu sehat

This commit is contained in:
meninjar
2026-05-04 03:48:43 +00:00
parent 135c631021
commit af32d9cfdd
127 changed files with 617690 additions and 1160 deletions

No files matched your search

+3 -1
View File
@@ -3,9 +3,11 @@ package medication
import "time"
type MedicationRequest struct {
MedicationID string `json:"medication_id,omitempty"`
OrganizationID string `json:"organization_id,omitempty"`
StatusCode string `json:"status_code" binding:"required,oneof=active inactive entered-in-error"`
KfaCode string `json:"kfa_code" binding:"required"`
KfaDisplay string `json:"kfa_display" binding:"required"`
KfaDisplay string `json:"kfa_display,omitempty"`
FormCode string `json:"form_code,omitempty"`
FormDisplay string `json:"form_display,omitempty"`
ManufacturerID string `json:"manufacturer_id,omitempty"` // Reference ke ID Organization (Pabrik/Distributor)
+69 -20
View File
@@ -1,33 +1,78 @@
package medication
import (
"os"
"time"
"service/internal/interfaces/satusehat"
)
func MapRequestToFHIR(req MedicationRequest) satusehat.FHIRPayload {
payload := satusehat.NewFHIRPayload("Medication").
Set("status", req.StatusCode).
Set("code", map[string]interface{}{
"coding": []map[string]interface{}{
{
"system": "http://sys-ids.kemkes.go.id/kfa",
"code": req.KfaCode,
"display": req.KfaDisplay,
payload := satusehat.NewFHIRPayload("Medication")
orgID := os.Getenv("SATUSEHAT_ORG_ID")
if orgID == "" {
orgID = req.OrganizationID
}
// Set Meta Profile secara otomatis
payload.Set("meta", map[string]interface{}{
"profile": []string{"https://fhir.kemkes.go.id/r4/StructureDefinition/Medication"},
})
// Set Extension MedicationType (Non-compound) secara otomatis
payload.Set("extension", []map[string]interface{}{
{
"url": "https://fhir.kemkes.go.id/r4/StructureDefinition/MedicationType",
"valueCodeableConcept": map[string]interface{}{
"coding": []map[string]interface{}{
{
"system": "http://terminology.kemkes.go.id/CodeSystem/medication-type",
"code": "NC",
"display": "Non-compound",
},
},
},
},
})
if orgID != "" && req.MedicationID != "" {
payload.Set("identifier", []map[string]interface{}{
{
"system": "http://sys-ids.kemkes.go.id/medication/" + orgID,
"use": "official",
"value": req.MedicationID,
},
})
}
if req.StatusCode != "" {
payload.Set("status", req.StatusCode)
}
if req.KfaCode != "" {
coding := map[string]interface{}{
"system": "http://sys-ids.kemkes.go.id/kfa",
"code": req.KfaCode,
}
if req.KfaDisplay != "" {
coding["display"] = req.KfaDisplay
}
payload.Set("code", map[string]interface{}{
"coding": []map[string]interface{}{coding},
})
}
if req.FormCode != "" {
coding := map[string]interface{}{
"system": "http://terminology.kemkes.go.id/CodeSystem/medication-form",
"code": req.FormCode,
}
if req.FormDisplay != "" {
coding["display"] = req.FormDisplay
}
payload.Set("form", map[string]interface{}{
"coding": []map[string]interface{}{
{
"system": "http://terminology.kemkes.go.id/CodeSystem/medication-form",
"code": req.FormCode,
"display": req.FormDisplay,
},
},
"coding": []map[string]interface{}{coding},
})
}
@@ -37,11 +82,15 @@ func MapRequestToFHIR(req MedicationRequest) satusehat.FHIRPayload {
})
}
if req.BatchNumber != "" && req.ExpirationDate != nil {
payload.Set("batch", map[string]interface{}{
"lotNumber": req.BatchNumber,
"expirationDate": req.ExpirationDate.Format(time.RFC3339),
})
if req.BatchNumber != "" || req.ExpirationDate != nil {
batch := map[string]interface{}{}
if req.BatchNumber != "" {
batch["lotNumber"] = req.BatchNumber
}
if req.ExpirationDate != nil {
batch["expirationDate"] = req.ExpirationDate.Format(time.RFC3339)
}
payload.Set("batch", batch)
}
return payload
@@ -7,6 +7,7 @@ import (
"net/url"
"service/internal/interfaces/satusehat"
"service/pkg/errors"
)
type Repository interface {
@@ -25,15 +26,22 @@ 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
@@ -49,6 +49,9 @@ func (s *service) Patch(ctx context.Context, id string, req MedicationPatchReque
}
func (s *service) GetByID(ctx context.Context, id string) (*satusehat.FHIRResponse, error) {
if id == "" {
return nil, errors.NewValidationError().Message("Medication ID is required").Build()
}
return s.repo.GetByID(ctx, id)
}