penambahan All case Satu sehat
This commit is contained in:
@@ -1,17 +1,25 @@
|
||||
package allergyintolerance
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"service/internal/satusehat/common"
|
||||
)
|
||||
|
||||
type AllergyIntoleranceRequest 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 inactive resolved"`
|
||||
VerificationStatus string `json:"verification_status" binding:"required,oneof=unconfirmed presumed confirmed refuted entered-in-error"`
|
||||
Category string `json:"category" binding:"required,oneof=food medication environment biologic"`
|
||||
Code string `json:"code" binding:"required"` // SNOMED CT Code
|
||||
Display string `json:"display" binding:"required"` // Display Name
|
||||
RecordedDate time.Time `json:"recorded_date" binding:"required"`
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
AllergyID string `json:"allergy_id,omitempty"`
|
||||
ClinicalStatus string `json:"clinical_status" binding:"required,oneof=active inactive resolved"`
|
||||
VerificationStatus string `json:"verification_status" binding:"required,oneof=unconfirmed presumed confirmed refuted entered-in-error"`
|
||||
Category []string `json:"category,omitempty"`
|
||||
Code *common.CodeableConceptDTO `json:"code" binding:"required"`
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientName string `json:"patient_name,omitempty"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
EncounterDisplay string `json:"encounter_display,omitempty"`
|
||||
RecordedDate *time.Time `json:"recorded_date" binding:"required"`
|
||||
RecorderID string `json:"recorder_id,omitempty"`
|
||||
RecorderDisplay string `json:"recorder_display,omitempty"`
|
||||
}
|
||||
|
||||
type AllergyIntolerancePatchRequest []map[string]interface{}
|
||||
@@ -1,42 +1,115 @@
|
||||
package allergyintolerance
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
)
|
||||
|
||||
var verificationStatusDisplayMap = map[string]string{
|
||||
"unconfirmed": "Unconfirmed",
|
||||
"presumed": "Presumed",
|
||||
"confirmed": "Confirmed",
|
||||
"refuted": "Refuted",
|
||||
"entered-in-error": "Entered in Error",
|
||||
}
|
||||
|
||||
func MapRequestToFHIR(req AllergyIntoleranceRequest) satusehat.FHIRPayload {
|
||||
return satusehat.NewFHIRPayload("AllergyIntolerance").
|
||||
Set("clinicalStatus", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical",
|
||||
"code": req.ClinicalStatus,
|
||||
},
|
||||
payload := satusehat.NewFHIRPayload("AllergyIntolerance")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.AllergyID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{
|
||||
"system": "http://sys-ids.kemkes.go.id/allergy/" + orgID,
|
||||
"use": "official",
|
||||
"value": req.AllergyID,
|
||||
},
|
||||
}).
|
||||
Set("verificationStatus", map[string]interface{}{
|
||||
})
|
||||
}
|
||||
|
||||
if req.ClinicalStatus != "" {
|
||||
payload.Set("clinicalStatus", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/allergyintolerance-verification",
|
||||
"code": req.VerificationStatus,
|
||||
"system": "http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical",
|
||||
"code": req.ClinicalStatus,
|
||||
"display": strings.ToUpper(req.ClinicalStatus[:1]) + req.ClinicalStatus[1:],
|
||||
},
|
||||
},
|
||||
}).
|
||||
Set("category", []string{req.Category}).
|
||||
Set("code", map[string]interface{}{
|
||||
})
|
||||
}
|
||||
|
||||
if req.VerificationStatus != "" {
|
||||
display, ok := verificationStatusDisplayMap[req.VerificationStatus]
|
||||
if !ok {
|
||||
display = strings.ToUpper(req.VerificationStatus[:1]) + req.VerificationStatus[1:]
|
||||
}
|
||||
payload.Set("verificationStatus", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://snomed.info/sct",
|
||||
"code": req.Code,
|
||||
"display": req.Display,
|
||||
},
|
||||
{"system": "http://terminology.hl7.org/CodeSystem/allergyintolerance-verification", "code": req.VerificationStatus, "display": display},
|
||||
},
|
||||
}).
|
||||
Set("patient", map[string]interface{}{
|
||||
"reference": "Patient/" + req.PatientID,
|
||||
"display": req.PatientName,
|
||||
}).
|
||||
Set("recordedDate", req.RecordedDate.Format(time.RFC3339))
|
||||
})
|
||||
}
|
||||
|
||||
if len(req.Category) > 0 {
|
||||
payload.Set("category", req.Category)
|
||||
}
|
||||
|
||||
if req.Code != nil {
|
||||
sys := req.Code.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct" // Default to SNOMED
|
||||
}
|
||||
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{}{coding},
|
||||
}
|
||||
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("patient", subject)
|
||||
}
|
||||
|
||||
if req.EncounterID != "" {
|
||||
encounter := map[string]interface{}{"reference": "Encounter/" + req.EncounterID}
|
||||
if req.EncounterDisplay != "" {
|
||||
encounter["display"] = req.EncounterDisplay
|
||||
}
|
||||
payload.Set("encounter", encounter)
|
||||
}
|
||||
|
||||
if req.RecordedDate != nil && !req.RecordedDate.IsZero() {
|
||||
payload.Set("recordedDate", req.RecordedDate.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if req.RecorderID != "" {
|
||||
recorder := map[string]interface{}{"reference": "Practitioner/" + req.RecorderID}
|
||||
if req.RecorderDisplay != "" {
|
||||
recorder["display"] = req.RecorderDisplay
|
||||
}
|
||||
payload.Set("recorder", recorder)
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"service/internal/interfaces/satusehat"
|
||||
"service/pkg/errors"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
@@ -19,15 +20,24 @@ type repository struct{ client satusehat.SatuSehatClient }
|
||||
|
||||
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
|
||||
if id, ok := result["id"].(string); ok {
|
||||
resourceID = id
|
||||
|
||||
@@ -25,12 +25,23 @@ func (s *service) Update(ctx context.Context, id string, req AllergyIntoleranceR
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("ID is required").Build()
|
||||
}
|
||||
return s.repo.Update(ctx, id, MapRequestToFHIR(req).Set("id", id))
|
||||
payload := MapRequestToFHIR(req)
|
||||
payload.Set("id", id)
|
||||
return s.repo.Update(ctx, id, payload)
|
||||
}
|
||||
func (s *service) Patch(ctx context.Context, id string, req AllergyIntolerancePatchRequest) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("AllergyIntolerance ID is required").Build()
|
||||
}
|
||||
if len(req) == 0 {
|
||||
return nil, errors.NewValidationError().Message("Patch payload cannot be empty").Build()
|
||||
}
|
||||
return s.repo.Patch(ctx, id, req)
|
||||
}
|
||||
func (s *service) GetByID(ctx context.Context, id string) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("AllergyIntolerance ID is required").Build()
|
||||
}
|
||||
return s.repo.GetByID(ctx, id)
|
||||
}
|
||||
func (s *service) Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error) {
|
||||
|
||||
Reference in New Issue
Block a user