penambahan All case Satu sehat
This commit is contained in:
@@ -1,18 +1,22 @@
|
||||
package condition
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"service/internal/satusehat/common"
|
||||
)
|
||||
|
||||
type ConditionRequest struct {
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientName string `json:"patient_name" binding:"required"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
ClinicalStatus string `json:"clinical_status" binding:"required,oneof=active recurrence relapse inactive remission resolved"` // active, recurrence, relapse, inactive, remission, resolved
|
||||
CategoryCode string `json:"category_code" binding:"required"` // problem-list-item, encounter-diagnosis
|
||||
CategoryDisplay string `json:"category_display" binding:"required"`
|
||||
Code string `json:"code" binding:"required"` // SNOMED CT / ICD-10 code
|
||||
Display string `json:"display" binding:"required"` // Diagnosis text
|
||||
OnsetDateTime time.Time `json:"onset_date_time" binding:"required"`
|
||||
RecordedDate time.Time `json:"recorded_date" binding:"required"`
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
ConditionID string `json:"condition_id,omitempty"`
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientName string `json:"patient_name,omitempty"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
ClinicalStatus string `json:"clinical_status" binding:"required,oneof=active recurrence relapse inactive remission resolved"`
|
||||
Category *common.CodeableConceptDTO `json:"category,omitempty"`
|
||||
Code *common.CodeableConceptDTO `json:"code,omitempty" binding:"required"`
|
||||
OnsetDateTime *time.Time `json:"onset_date_time,omitempty"`
|
||||
RecordedDate *time.Time `json:"recorded_date,omitempty"`
|
||||
}
|
||||
|
||||
type ConditionPatchRequest []map[string]interface{}
|
||||
|
||||
@@ -1,50 +1,91 @@
|
||||
package condition
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req ConditionRequest) satusehat.FHIRPayload {
|
||||
payload := satusehat.NewFHIRPayload("Condition").
|
||||
Set("clinicalStatus", map[string]interface{}{
|
||||
payload := satusehat.NewFHIRPayload("Condition")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.ConditionID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{"system": "http://sys-ids.kemkes.go.id/condition/" + orgID, "use": "official", "value": req.ConditionID},
|
||||
})
|
||||
}
|
||||
|
||||
if req.ClinicalStatus != "" {
|
||||
payload.Set("clinicalStatus", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/condition-clinical",
|
||||
"code": req.ClinicalStatus,
|
||||
},
|
||||
{"system": "http://terminology.hl7.org/CodeSystem/condition-clinical", "code": req.ClinicalStatus},
|
||||
},
|
||||
}).
|
||||
Set("category", []map[string]interface{}{
|
||||
})
|
||||
}
|
||||
if req.Category != nil {
|
||||
sys := req.Category.System
|
||||
if sys == "" {
|
||||
sys = "http://terminology.hl7.org/CodeSystem/condition-category"
|
||||
}
|
||||
coding := map[string]interface{}{
|
||||
"system": sys,
|
||||
"code": req.Category.Code,
|
||||
}
|
||||
if req.Category.Display != "" {
|
||||
coding["display"] = req.Category.Display
|
||||
}
|
||||
payload.Set("category", []map[string]interface{}{
|
||||
{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/condition-category",
|
||||
"code": req.CategoryCode,
|
||||
"display": req.CategoryDisplay,
|
||||
},
|
||||
coding,
|
||||
},
|
||||
},
|
||||
}).
|
||||
Set("code", map[string]interface{}{
|
||||
})
|
||||
}
|
||||
if req.Code != nil {
|
||||
sys := req.Code.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct" // Default value jika tidak diset
|
||||
}
|
||||
coding := map[string]interface{}{
|
||||
"system": sys,
|
||||
"code": req.Code.Code,
|
||||
}
|
||||
if req.Code.Display != "" {
|
||||
coding["display"] = req.Code.Display
|
||||
}
|
||||
codeConcept := map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://snomed.info/sct",
|
||||
"code": req.Code,
|
||||
"display": req.Display,
|
||||
},
|
||||
coding,
|
||||
},
|
||||
}).
|
||||
Set("subject", map[string]interface{}{
|
||||
"reference": "Patient/" + req.PatientID,
|
||||
"display": req.PatientName,
|
||||
}).
|
||||
Set("encounter", map[string]interface{}{
|
||||
"reference": "Encounter/" + req.EncounterID,
|
||||
}).
|
||||
Set("onsetDateTime", req.OnsetDateTime.Format(time.RFC3339)).
|
||||
Set("recordedDate", req.RecordedDate.Format(time.RFC3339))
|
||||
}
|
||||
if req.Code.Text != "" {
|
||||
codeConcept["text"] = req.Code.Text
|
||||
}
|
||||
payload.Set("code", codeConcept)
|
||||
}
|
||||
if req.PatientID != "" {
|
||||
subject := map[string]interface{}{"reference": "Patient/" + req.PatientID}
|
||||
if req.PatientName != "" {
|
||||
subject["display"] = req.PatientName
|
||||
}
|
||||
payload.Set("subject", subject)
|
||||
}
|
||||
if req.EncounterID != "" {
|
||||
payload.Set("encounter", map[string]interface{}{"reference": "Encounter/" + req.EncounterID})
|
||||
}
|
||||
if req.OnsetDateTime != nil && !req.OnsetDateTime.IsZero() {
|
||||
payload.Set("onsetDateTime", req.OnsetDateTime.Format(time.RFC3339))
|
||||
}
|
||||
if req.RecordedDate != nil && !req.RecordedDate.IsZero() {
|
||||
payload.Set("recordedDate", req.RecordedDate.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"service/internal/interfaces/satusehat"
|
||||
"service/pkg/errors"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
@@ -24,15 +25,23 @@ 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
|
||||
@@ -40,11 +49,7 @@ func (r *repository) executeRequest(ctx context.Context, method, endpoint string
|
||||
resourceID = id
|
||||
}
|
||||
|
||||
return &satusehat.FHIRResponse{
|
||||
ID: resourceID,
|
||||
FullResponse: result,
|
||||
RawResponse: resp,
|
||||
}, nil
|
||||
return &satusehat.FHIRResponse{ID: resourceID, FullResponse: result, RawResponse: resp}, nil
|
||||
}
|
||||
|
||||
func (r *repository) Create(ctx context.Context, payload interface{}) (*satusehat.FHIRResponse, error) {
|
||||
|
||||
@@ -57,6 +57,5 @@ func (s *service) GetByID(ctx context.Context, id string) (*satusehat.FHIRRespon
|
||||
}
|
||||
|
||||
func (s *service) Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error) {
|
||||
// Tambahkan validasi untuk query params jika diperlukan
|
||||
return s.repo.Search(ctx, queryParams)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user