update All feture and service
This commit is contained in:
No files matched your search
@@ -2,25 +2,44 @@ package procedure
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"service/internal/satusehat/common"
|
||||
)
|
||||
|
||||
type ProcedureRequest struct {
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
ProcedureID string `json:"procedure_id,omitempty"`
|
||||
Status string `json:"status" binding:"required,oneof=preparation in-progress not-done on-hold stopped completed entered-in-error unknown"`
|
||||
Category []*common.CodeableConceptDTO `json:"category,omitempty"`
|
||||
Code *common.CodeableConceptDTO `json:"code" binding:"required"`
|
||||
Subject *common.ReferenceDTO `json:"subject" binding:"required"`
|
||||
Encounter *common.ReferenceDTO `json:"encounter,omitempty"`
|
||||
PerformedDateTime *time.Time `json:"performed_date_time,omitempty"`
|
||||
PerformedStart *time.Time `json:"performed_start,omitempty"`
|
||||
PerformedEnd *time.Time `json:"performed_end,omitempty"`
|
||||
Performer []common.ReferenceDTO `json:"performer,omitempty"`
|
||||
ReasonCode []*common.CodeableConceptDTO `json:"reason_code,omitempty"`
|
||||
BodySite []*common.CodeableConceptDTO `json:"body_site,omitempty"`
|
||||
Note []string `json:"note,omitempty"`
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
ProcedureID string `json:"procedure_id,omitempty"`
|
||||
|
||||
Status string `json:"status" binding:"required,oneof=preparation in-progress not-done on-hold stopped completed entered-in-error unknown"`
|
||||
|
||||
CategoryCode string `json:"category_code,omitempty"`
|
||||
CategoryDisplay string `json:"category_display,omitempty"`
|
||||
CategorySystem string `json:"category_system,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,omitempty"`
|
||||
EncounterDisplay string `json:"encounter_display,omitempty"`
|
||||
|
||||
PerformedDateTime *time.Time `json:"performed_date_time,omitempty"`
|
||||
PerformedStart *time.Time `json:"performed_start,omitempty"`
|
||||
PerformedEnd *time.Time `json:"performed_end,omitempty"`
|
||||
|
||||
PerformerID string `json:"performer_id,omitempty"`
|
||||
PerformerName string `json:"performer_name,omitempty"`
|
||||
|
||||
ReasonCode string `json:"reason_code,omitempty"`
|
||||
ReasonDisplay string `json:"reason_display,omitempty"`
|
||||
ReasonSystem string `json:"reason_system,omitempty"`
|
||||
|
||||
BodySiteCode string `json:"body_site_code,omitempty"`
|
||||
BodySiteDisplay string `json:"body_site_display,omitempty"`
|
||||
BodySiteSystem string `json:"body_site_system,omitempty"`
|
||||
|
||||
Note string `json:"note,omitempty"`
|
||||
}
|
||||
|
||||
type ProcedurePatchRequest []map[string]interface{}
|
||||
@@ -1,7 +1,6 @@
|
||||
package procedure
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
@@ -10,15 +9,10 @@ import (
|
||||
func MapRequestToFHIR(req ProcedureRequest) satusehat.FHIRPayload {
|
||||
payload := satusehat.NewFHIRPayload("Procedure")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.ProcedureID != "" {
|
||||
if req.OrganizationID != "" && req.ProcedureID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{
|
||||
"system": "http://sys-ids.kemkes.go.id/procedure/" + orgID,
|
||||
"system": "http://sys-ids.kemkes.go.id/procedure/" + req.OrganizationID,
|
||||
"value": req.ProcedureID,
|
||||
},
|
||||
})
|
||||
@@ -28,50 +22,46 @@ func MapRequestToFHIR(req ProcedureRequest) satusehat.FHIRPayload {
|
||||
payload.Set("status", req.Status)
|
||||
}
|
||||
|
||||
if len(req.Category) > 0 && req.Category[0] != nil {
|
||||
sys := req.Category[0].System
|
||||
if req.CategoryCode != "" {
|
||||
sys := req.CategorySystem
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.Category[0].Code}
|
||||
if req.Category[0].Display != "" {
|
||||
coding["display"] = req.Category[0].Display
|
||||
coding := map[string]interface{}{"system": sys, "code": req.CategoryCode}
|
||||
if req.CategoryDisplay != "" {
|
||||
coding["display"] = req.CategoryDisplay
|
||||
}
|
||||
catObj := map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
if req.Category[0].Text != "" {
|
||||
catObj["text"] = req.Category[0].Text
|
||||
}
|
||||
payload.Set("category", catObj)
|
||||
payload.Set("category", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{coding},
|
||||
})
|
||||
}
|
||||
|
||||
if req.Code != nil {
|
||||
sys := req.Code.System
|
||||
if req.Code != "" {
|
||||
sys := req.CodeSystem
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
sys = "http://hl7.org/fhir/sid/icd-9-cm"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.Code.Code}
|
||||
if req.Code.Display != "" {
|
||||
coding["display"] = req.Code.Display
|
||||
coding := map[string]interface{}{"system": sys, "code": req.Code}
|
||||
if req.CodeDisplay != "" {
|
||||
coding["display"] = req.CodeDisplay
|
||||
}
|
||||
codeObj := map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
if req.Code.Text != "" {
|
||||
codeObj["text"] = req.Code.Text
|
||||
}
|
||||
payload.Set("code", codeObj)
|
||||
payload.Set("code", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{coding},
|
||||
})
|
||||
}
|
||||
|
||||
if req.Subject != nil {
|
||||
subj := map[string]interface{}{"reference": req.Subject.Reference}
|
||||
if req.Subject.Display != "" {
|
||||
subj["display"] = req.Subject.Display
|
||||
if req.PatientID != "" {
|
||||
subj := map[string]interface{}{"reference": "Patient/" + req.PatientID}
|
||||
if req.PatientName != "" {
|
||||
subj["display"] = req.PatientName
|
||||
}
|
||||
payload.Set("subject", subj)
|
||||
}
|
||||
|
||||
if req.Encounter != nil {
|
||||
enc := map[string]interface{}{"reference": req.Encounter.Reference}
|
||||
if req.Encounter.Display != "" {
|
||||
enc["display"] = req.Encounter.Display
|
||||
if req.EncounterID != "" {
|
||||
enc := map[string]interface{}{"reference": "Encounter/" + req.EncounterID}
|
||||
if req.EncounterDisplay != "" {
|
||||
enc["display"] = req.EncounterDisplay
|
||||
}
|
||||
payload.Set("encounter", enc)
|
||||
}
|
||||
@@ -86,60 +76,44 @@ func MapRequestToFHIR(req ProcedureRequest) satusehat.FHIRPayload {
|
||||
payload.Set("performedDateTime", req.PerformedDateTime.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if len(req.Performer) > 0 {
|
||||
var performers []map[string]interface{}
|
||||
for _, p := range req.Performer {
|
||||
actor := map[string]interface{}{"reference": p.Reference}
|
||||
if p.Display != "" {
|
||||
actor["display"] = p.Display
|
||||
}
|
||||
performers = append(performers, map[string]interface{}{"actor": actor})
|
||||
if req.PerformerID != "" {
|
||||
actor := map[string]interface{}{"reference": "Practitioner/" + req.PerformerID}
|
||||
if req.PerformerName != "" {
|
||||
actor["display"] = req.PerformerName
|
||||
}
|
||||
payload.Set("performer", performers)
|
||||
payload.Set("performer", []map[string]interface{}{{"actor": actor}})
|
||||
}
|
||||
|
||||
if len(req.ReasonCode) > 0 {
|
||||
var reasons []map[string]interface{}
|
||||
for _, r := range req.ReasonCode {
|
||||
if r != nil {
|
||||
sys := r.System
|
||||
if sys == "" {
|
||||
sys = "http://hl7.org/fhir/sid/icd-10"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": r.Code}
|
||||
if r.Display != "" {
|
||||
coding["display"] = r.Display
|
||||
}
|
||||
reasons = append(reasons, map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
||||
}
|
||||
if req.ReasonCode != "" {
|
||||
sys := req.ReasonSystem
|
||||
if sys == "" {
|
||||
sys = "http://hl7.org/fhir/sid/icd-10"
|
||||
}
|
||||
payload.Set("reasonCode", reasons)
|
||||
coding := map[string]interface{}{"system": sys, "code": req.ReasonCode}
|
||||
if req.ReasonDisplay != "" {
|
||||
coding["display"] = req.ReasonDisplay
|
||||
}
|
||||
payload.Set("reasonCode", []map[string]interface{}{
|
||||
{"coding": []map[string]interface{}{coding}},
|
||||
})
|
||||
}
|
||||
|
||||
if len(req.BodySite) > 0 {
|
||||
var bodySites []map[string]interface{}
|
||||
for _, b := range req.BodySite {
|
||||
if b != nil {
|
||||
sys := b.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": b.Code}
|
||||
if b.Display != "" {
|
||||
coding["display"] = b.Display
|
||||
}
|
||||
bodySites = append(bodySites, map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
||||
}
|
||||
if req.BodySiteCode != "" {
|
||||
sys := req.BodySiteSystem
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
payload.Set("bodySite", bodySites)
|
||||
coding := map[string]interface{}{"system": sys, "code": req.BodySiteCode}
|
||||
if req.BodySiteDisplay != "" {
|
||||
coding["display"] = req.BodySiteDisplay
|
||||
}
|
||||
payload.Set("bodySite", []map[string]interface{}{
|
||||
{"coding": []map[string]interface{}{coding}},
|
||||
})
|
||||
}
|
||||
|
||||
if len(req.Note) > 0 {
|
||||
var notes []map[string]interface{}
|
||||
for _, text := range req.Note {
|
||||
notes = append(notes, map[string]interface{}{"text": text})
|
||||
}
|
||||
payload.Set("note", notes)
|
||||
if req.Note != "" {
|
||||
payload.Set("note", []map[string]interface{}{{"text": req.Note}})
|
||||
}
|
||||
|
||||
return payload
|
||||
|
||||
@@ -25,12 +25,8 @@ 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()
|
||||
}
|
||||
|
||||
@@ -16,14 +16,18 @@ type Service interface {
|
||||
}
|
||||
|
||||
type service struct {
|
||||
repo Repository
|
||||
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 ProcedureRequest) (*satusehat.FHIRResponse, error) {
|
||||
if req.OrganizationID == "" {
|
||||
req.OrganizationID = s.orgID
|
||||
}
|
||||
return s.repo.Create(ctx, MapRequestToFHIR(req))
|
||||
}
|
||||
|
||||
@@ -31,6 +35,9 @@ func (s *service) Update(ctx context.Context, id string, req ProcedureRequest) (
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("Procedure 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