penambahan All case Satu sehat
This commit is contained in:
@@ -3,16 +3,18 @@ package servicerequest
|
||||
import "time"
|
||||
|
||||
type ServiceRequestRequest struct {
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientName string `json:"patient_name" binding:"required"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
RequesterID string `json:"requester_id" binding:"required"`
|
||||
RequesterName string `json:"requester_name" binding:"required"`
|
||||
Status string `json:"status" binding:"required,oneof=draft active on-hold revoked completed entered-in-error unknown"` // draft, active, on-hold, revoked, completed, entered-in-error, unknown
|
||||
Intent string `json:"intent" binding:"required,oneof=proposal plan directive order original-order reflex-order filler-order instance-order option"` // proposal, plan, directive, order, original-order, reflex-order, filler-order, instance-order, option
|
||||
Code string `json:"code" binding:"required"`
|
||||
Display string `json:"display" binding:"required"`
|
||||
AuthoredOn time.Time `json:"authored_on" binding:"required"`
|
||||
PatientID string `json:"patient_id,omitempty"`
|
||||
PatientName string `json:"patient_name,omitempty"`
|
||||
EncounterID string `json:"encounter_id,omitempty"`
|
||||
RequesterID string `json:"requester_id,omitempty"`
|
||||
PerformerID string `json:"performer_id,omitempty"`
|
||||
RequesterName string `json:"requester_name,omitempty"`
|
||||
PerformerName string `json:"performer_name,omitempty"`
|
||||
Status string `json:"status,omitempty" binding:"omitempty,oneof=draft active on-hold revoked completed entered-in-error unknown"`
|
||||
Intent string `json:"intent,omitempty" binding:"omitempty,oneof=proposal plan directive order original-order reflex-order filler-order instance-order option"`
|
||||
Code string `json:"code,omitempty"`
|
||||
Display string `json:"display,omitempty"`
|
||||
AuthoredOn time.Time `json:"authored_on,omitempty"`
|
||||
}
|
||||
|
||||
type ServiceRequestPatchRequest []map[string]interface{}
|
||||
|
||||
@@ -7,32 +7,66 @@ import (
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req ServiceRequestRequest) satusehat.FHIRPayload {
|
||||
payload := satusehat.NewFHIRPayload("ServiceRequest").
|
||||
Set("status", req.Status).
|
||||
Set("intent", req.Intent).
|
||||
Set("code", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://snomed.info/sct",
|
||||
"code": req.Code,
|
||||
"display": req.Display,
|
||||
},
|
||||
},
|
||||
}).
|
||||
Set("subject", map[string]interface{}{
|
||||
payload := satusehat.NewFHIRPayload("ServiceRequest")
|
||||
|
||||
if req.Status != "" {
|
||||
payload.Set("status", req.Status)
|
||||
}
|
||||
|
||||
if req.Intent != "" {
|
||||
payload.Set("intent", req.Intent)
|
||||
}
|
||||
|
||||
if req.Code != "" {
|
||||
coding := map[string]interface{}{
|
||||
"system": "http://snomed.info/sct",
|
||||
"code": req.Code,
|
||||
}
|
||||
if req.Display != "" {
|
||||
coding["display"] = req.Display
|
||||
}
|
||||
payload.Set("code", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{coding},
|
||||
})
|
||||
}
|
||||
|
||||
if req.PatientID != "" {
|
||||
subject := map[string]interface{}{
|
||||
"reference": "Patient/" + req.PatientID,
|
||||
"display": req.PatientName,
|
||||
}).
|
||||
Set("encounter", map[string]interface{}{
|
||||
}
|
||||
if req.PatientName != "" {
|
||||
subject["display"] = req.PatientName
|
||||
}
|
||||
payload.Set("subject", subject)
|
||||
}
|
||||
|
||||
if req.EncounterID != "" {
|
||||
payload.Set("encounter", map[string]interface{}{
|
||||
"reference": "Encounter/" + req.EncounterID,
|
||||
}).
|
||||
Set("authoredOn", req.AuthoredOn.Format(time.RFC3339))
|
||||
})
|
||||
}
|
||||
|
||||
if !req.AuthoredOn.IsZero() {
|
||||
payload.Set("authoredOn", req.AuthoredOn.Format(time.RFC3339))
|
||||
}
|
||||
if req.PerformerID != "" {
|
||||
performer := map[string]interface{}{
|
||||
"reference": "Practitioner/" + req.PerformerID,
|
||||
}
|
||||
if req.PerformerName != "" {
|
||||
performer["display"] = req.PerformerName
|
||||
}
|
||||
payload.Set("performer", []map[string]interface{}{performer})
|
||||
}
|
||||
|
||||
if req.RequesterID != "" {
|
||||
payload.Set("requester", map[string]interface{}{
|
||||
requester := map[string]interface{}{
|
||||
"reference": "Practitioner/" + req.RequesterID,
|
||||
"display": req.RequesterName,
|
||||
})
|
||||
}
|
||||
if req.RequesterName != "" {
|
||||
requester["display"] = req.RequesterName
|
||||
}
|
||||
payload.Set("requester", requester)
|
||||
}
|
||||
|
||||
return payload
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"service/internal/interfaces/satusehat"
|
||||
"service/pkg/errors"
|
||||
)
|
||||
|
||||
// Repository mendefinisikan kontrak untuk operasi penyimpanan data ServiceRequest.
|
||||
@@ -26,15 +27,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
|
||||
|
||||
Reference in New Issue
Block a user