update All feture and service
This commit is contained in:
No files matched your search
@@ -2,24 +2,30 @@ package allergyintolerance
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"service/internal/satusehat/common"
|
||||
)
|
||||
|
||||
type AllergyIntoleranceRequest struct {
|
||||
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"`
|
||||
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"`
|
||||
|
||||
CodeSystem string `json:"code_system,omitempty"`
|
||||
Code string `json:"code" binding:"required"`
|
||||
CodeDisplay string `json:"code_display,omitempty"`
|
||||
|
||||
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,7 +1,6 @@
|
||||
package allergyintolerance
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -19,15 +18,10 @@ var verificationStatusDisplayMap = map[string]string{
|
||||
func MapRequestToFHIR(req AllergyIntoleranceRequest) satusehat.FHIRPayload {
|
||||
payload := satusehat.NewFHIRPayload("AllergyIntolerance")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.AllergyID != "" {
|
||||
if req.OrganizationID != "" && req.AllergyID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{
|
||||
"system": "http://sys-ids.kemkes.go.id/allergy/" + orgID,
|
||||
"system": "http://sys-ids.kemkes.go.id/allergy/" + req.OrganizationID,
|
||||
"use": "official",
|
||||
"value": req.AllergyID,
|
||||
},
|
||||
@@ -58,29 +52,25 @@ func MapRequestToFHIR(req AllergyIntoleranceRequest) satusehat.FHIRPayload {
|
||||
})
|
||||
}
|
||||
|
||||
if len(req.Category) > 0 {
|
||||
payload.Set("category", req.Category)
|
||||
if req.Category != "" {
|
||||
payload.Set("category", []string{req.Category})
|
||||
}
|
||||
|
||||
if req.Code != nil {
|
||||
sys := req.Code.System
|
||||
if req.Code != "" {
|
||||
sys := req.CodeSystem
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct" // Default to SNOMED
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{
|
||||
"system": sys,
|
||||
"code": req.Code.Code,
|
||||
"code": req.Code,
|
||||
}
|
||||
if req.Code.Display != "" {
|
||||
coding["display"] = req.Code.Display
|
||||
if req.CodeDisplay != "" {
|
||||
coding["display"] = req.CodeDisplay
|
||||
}
|
||||
codeConcept := map[string]interface{}{
|
||||
payload.Set("code", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{coding},
|
||||
}
|
||||
if req.Code.Text != "" {
|
||||
codeConcept["text"] = req.Code.Text
|
||||
}
|
||||
payload.Set("code", codeConcept)
|
||||
})
|
||||
}
|
||||
|
||||
if req.PatientID != "" {
|
||||
|
||||
@@ -20,12 +20,8 @@ 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(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()
|
||||
}
|
||||
|
||||
@@ -14,17 +14,28 @@ type Service interface {
|
||||
GetByID(ctx context.Context, id string) (*satusehat.FHIRResponse, error)
|
||||
Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error)
|
||||
}
|
||||
type service struct{ repo Repository }
|
||||
type service struct {
|
||||
repo Repository
|
||||
orgID string
|
||||
}
|
||||
|
||||
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 AllergyIntoleranceRequest) (*satusehat.FHIRResponse, error) {
|
||||
if req.OrganizationID == "" {
|
||||
req.OrganizationID = s.orgID
|
||||
}
|
||||
return s.repo.Create(ctx, MapRequestToFHIR(req))
|
||||
}
|
||||
func (s *service) Update(ctx context.Context, id string, req AllergyIntoleranceRequest) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("ID is required").Build()
|
||||
}
|
||||
if req.OrganizationID == "" {
|
||||
req.OrganizationID = s.orgID
|
||||
}
|
||||
payload := MapRequestToFHIR(req)
|
||||
payload.Set("id", id)
|
||||
return s.repo.Update(ctx, id, payload)
|
||||
|
||||
Reference in New Issue
Block a user