update All feture and service
This commit is contained in:
No files matched your search
@@ -2,47 +2,59 @@ package observation
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"service/internal/satusehat/common"
|
||||
)
|
||||
|
||||
type ObservationRequest struct {
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
ObservationID string `json:"observation_id,omitempty"`
|
||||
Status string `json:"status" binding:"required,oneof=registered preliminary final amended corrected cancelled entered-in-error unknown"`
|
||||
Category []*common.CodeableConceptDTO `json:"category" binding:"required,min=1"`
|
||||
Code *common.CodeableConceptDTO `json:"code" binding:"required"`
|
||||
Subject *common.ReferenceDTO `json:"subject" binding:"required"` // Patient
|
||||
Encounter *common.ReferenceDTO `json:"encounter,omitempty"`
|
||||
EffectiveDateTime *time.Time `json:"effective_datetime,omitempty"`
|
||||
Issued *time.Time `json:"issued,omitempty"`
|
||||
Performer []common.ReferenceDTO `json:"performer,omitempty"`
|
||||
BasedOn []common.ReferenceDTO `json:"based_on,omitempty"`
|
||||
PartOf []common.ReferenceDTO `json:"part_of,omitempty"`
|
||||
DerivedFrom []common.ReferenceDTO `json:"derived_from,omitempty"`
|
||||
Specimen *common.ReferenceDTO `json:"specimen,omitempty"`
|
||||
BodySite *common.CodeableConceptDTO `json:"body_site,omitempty"`
|
||||
ValueQuantity *common.QuantityDTO `json:"value_quantity,omitempty"`
|
||||
ValueCodeableConcept *common.CodeableConceptDTO `json:"value_codeable_concept,omitempty"`
|
||||
ValueString string `json:"value_string,omitempty"`
|
||||
ValueBoolean *bool `json:"value_boolean,omitempty"`
|
||||
Interpretation []*common.CodeableConceptDTO `json:"interpretation,omitempty"`
|
||||
ReferenceRange []ReferenceRangeDTO `json:"reference_range,omitempty"`
|
||||
Components []ComponentDTO `json:"components,omitempty"`
|
||||
}
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
ObservationID string `json:"observation_id,omitempty"`
|
||||
|
||||
type ReferenceRangeDTO struct {
|
||||
Low *common.QuantityDTO `json:"low,omitempty"`
|
||||
High *common.QuantityDTO `json:"high,omitempty"`
|
||||
Text string `json:"text,omitempty"`
|
||||
}
|
||||
Status string `json:"status" binding:"required,oneof=registered preliminary final amended corrected cancelled entered-in-error unknown"`
|
||||
|
||||
type ComponentDTO struct {
|
||||
Code *common.CodeableConceptDTO `json:"code,omitempty"`
|
||||
ValueQuantity *common.QuantityDTO `json:"value_quantity,omitempty"`
|
||||
ValueCodeableConcept *common.CodeableConceptDTO `json:"value_codeable_concept,omitempty"`
|
||||
ValueString string `json:"value_string,omitempty"`
|
||||
ValueBoolean *bool `json:"value_boolean,omitempty"`
|
||||
CategorySystem string `json:"category_system,omitempty"`
|
||||
CategoryCode string `json:"category_code" binding:"required"`
|
||||
CategoryDisplay string `json:"category_display,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"`
|
||||
|
||||
EffectiveDateTime *time.Time `json:"effective_datetime,omitempty"`
|
||||
Issued *time.Time `json:"issued,omitempty"`
|
||||
|
||||
PerformerID string `json:"performer_id,omitempty"`
|
||||
PerformerName string `json:"performer_name,omitempty"`
|
||||
|
||||
SpecimenID string `json:"specimen_id,omitempty"`
|
||||
|
||||
BodySiteSystem string `json:"body_site_system,omitempty"`
|
||||
BodySiteCode string `json:"body_site_code,omitempty"`
|
||||
BodySiteDisplay string `json:"body_site_display,omitempty"`
|
||||
|
||||
ValueQuantityValue *float64 `json:"value_quantity_value,omitempty"`
|
||||
ValueQuantityUnit string `json:"value_quantity_unit,omitempty"`
|
||||
ValueQuantitySystem string `json:"value_quantity_system,omitempty"`
|
||||
ValueQuantityCode string `json:"value_quantity_code,omitempty"`
|
||||
|
||||
ValueCodeSystem string `json:"value_code_system,omitempty"`
|
||||
ValueCode string `json:"value_code,omitempty"`
|
||||
ValueCodeDisplay string `json:"value_code_display,omitempty"`
|
||||
|
||||
ValueString string `json:"value_string,omitempty"`
|
||||
ValueBoolean *bool `json:"value_boolean,omitempty"`
|
||||
|
||||
InterpretationSystem string `json:"interpretation_system,omitempty"`
|
||||
InterpretationCode string `json:"interpretation_code,omitempty"`
|
||||
InterpretationDisplay string `json:"interpretation_display,omitempty"`
|
||||
|
||||
ReferenceRangeLowValue *float64 `json:"reference_range_low_value,omitempty"`
|
||||
ReferenceRangeHighValue *float64 `json:"reference_range_high_value,omitempty"`
|
||||
ReferenceRangeUnit string `json:"reference_range_unit,omitempty"`
|
||||
ReferenceRangeText string `json:"reference_range_text,omitempty"`
|
||||
}
|
||||
|
||||
type ObservationPatchRequest []map[string]interface{}
|
||||
@@ -1,7 +1,6 @@
|
||||
package observation
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
@@ -10,15 +9,10 @@ import (
|
||||
func MapRequestToFHIR(req ObservationRequest) satusehat.FHIRPayload {
|
||||
payload := satusehat.NewFHIRPayload("Observation")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if req.ObservationID != "" {
|
||||
if req.ObservationID != "" && req.OrganizationID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{
|
||||
"system": "http://sys-ids.kemkes.go.id/observation/" + orgID,
|
||||
"system": "http://sys-ids.kemkes.go.id/observation/" + req.OrganizationID,
|
||||
"value": req.ObservationID,
|
||||
},
|
||||
})
|
||||
@@ -30,54 +24,44 @@ func MapRequestToFHIR(req ObservationRequest) satusehat.FHIRPayload {
|
||||
}
|
||||
payload.Set("status", status)
|
||||
|
||||
if len(req.Category) > 0 {
|
||||
var categories []map[string]interface{}
|
||||
for _, c := range req.Category {
|
||||
if c != nil {
|
||||
sys := c.System
|
||||
if sys == "" {
|
||||
sys = "http://terminology.hl7.org/CodeSystem/observation-category"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": c.Code}
|
||||
if c.Display != "" {
|
||||
coding["display"] = c.Display
|
||||
}
|
||||
categories = append(categories, map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
||||
}
|
||||
if req.CategoryCode != "" {
|
||||
sys := req.CategorySystem
|
||||
if sys == "" {
|
||||
sys = "http://terminology.hl7.org/CodeSystem/observation-category"
|
||||
}
|
||||
payload.Set("category", categories)
|
||||
coding := map[string]interface{}{"system": sys, "code": req.CategoryCode}
|
||||
if req.CategoryDisplay != "" {
|
||||
coding["display"] = req.CategoryDisplay
|
||||
}
|
||||
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://loinc.org"
|
||||
}
|
||||
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
|
||||
}
|
||||
codeConcept := map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
if req.Code.Text != "" {
|
||||
codeConcept["text"] = req.Code.Text
|
||||
}
|
||||
payload.Set("code", codeConcept)
|
||||
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
|
||||
}
|
||||
payload.Set("encounter", enc)
|
||||
if req.EncounterID != "" {
|
||||
payload.Set("encounter", map[string]interface{}{"reference": "Encounter/" + req.EncounterID})
|
||||
}
|
||||
|
||||
if req.EffectiveDateTime != nil && !req.EffectiveDateTime.IsZero() {
|
||||
@@ -87,171 +71,99 @@ func MapRequestToFHIR(req ObservationRequest) satusehat.FHIRPayload {
|
||||
payload.Set("issued", req.Issued.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if len(req.Performer) > 0 {
|
||||
var performers []map[string]interface{}
|
||||
for _, p := range req.Performer {
|
||||
perf := map[string]interface{}{"reference": p.Reference}
|
||||
if p.Display != "" {
|
||||
perf["display"] = p.Display
|
||||
}
|
||||
performers = append(performers, perf)
|
||||
if req.PerformerID != "" {
|
||||
perf := map[string]interface{}{"reference": "Practitioner/" + req.PerformerID}
|
||||
if req.PerformerName != "" {
|
||||
perf["display"] = req.PerformerName
|
||||
}
|
||||
payload.Set("performer", performers)
|
||||
payload.Set("performer", []map[string]interface{}{perf})
|
||||
}
|
||||
|
||||
if len(req.BasedOn) > 0 {
|
||||
var refs []map[string]interface{}
|
||||
for _, r := range req.BasedOn {
|
||||
refs = append(refs, map[string]interface{}{"reference": r.Reference})
|
||||
}
|
||||
payload.Set("basedOn", refs)
|
||||
}
|
||||
if len(req.PartOf) > 0 {
|
||||
var refs []map[string]interface{}
|
||||
for _, r := range req.PartOf {
|
||||
refs = append(refs, map[string]interface{}{"reference": r.Reference})
|
||||
}
|
||||
payload.Set("partOf", refs)
|
||||
}
|
||||
if len(req.DerivedFrom) > 0 {
|
||||
var refs []map[string]interface{}
|
||||
for _, r := range req.DerivedFrom {
|
||||
refs = append(refs, map[string]interface{}{"reference": r.Reference})
|
||||
}
|
||||
payload.Set("derivedFrom", refs)
|
||||
if req.SpecimenID != "" {
|
||||
payload.Set("specimen", map[string]interface{}{"reference": "Specimen/" + req.SpecimenID})
|
||||
}
|
||||
|
||||
if req.Specimen != nil {
|
||||
spec := map[string]interface{}{"reference": req.Specimen.Reference}
|
||||
if req.Specimen.Display != "" {
|
||||
spec["display"] = req.Specimen.Display
|
||||
}
|
||||
payload.Set("specimen", spec)
|
||||
}
|
||||
|
||||
if req.BodySite != nil {
|
||||
sys := req.BodySite.System
|
||||
if req.BodySiteCode != "" {
|
||||
sys := req.BodySiteSystem
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.BodySite.Code}
|
||||
if req.BodySite.Display != "" {
|
||||
coding["display"] = req.BodySite.Display
|
||||
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 req.ValueQuantity != nil {
|
||||
sys := req.ValueQuantity.System
|
||||
switch {
|
||||
case req.ValueQuantityValue != nil:
|
||||
sys := req.ValueQuantitySystem
|
||||
if sys == "" {
|
||||
sys = "http://unitsofmeasure.org"
|
||||
}
|
||||
payload.Set("valueQuantity", map[string]interface{}{
|
||||
"value": req.ValueQuantity.Value,
|
||||
"unit": req.ValueQuantity.Unit,
|
||||
q := map[string]interface{}{
|
||||
"value": *req.ValueQuantityValue,
|
||||
"system": sys,
|
||||
"code": req.ValueQuantity.Code,
|
||||
})
|
||||
} else if req.ValueCodeableConcept != nil {
|
||||
sys := req.ValueCodeableConcept.System
|
||||
}
|
||||
if req.ValueQuantityUnit != "" {
|
||||
q["unit"] = req.ValueQuantityUnit
|
||||
}
|
||||
if req.ValueQuantityCode != "" {
|
||||
q["code"] = req.ValueQuantityCode
|
||||
}
|
||||
payload.Set("valueQuantity", q)
|
||||
case req.ValueCode != "":
|
||||
sys := req.ValueCodeSystem
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.ValueCodeableConcept.Code}
|
||||
if req.ValueCodeableConcept.Display != "" {
|
||||
coding["display"] = req.ValueCodeableConcept.Display
|
||||
coding := map[string]interface{}{"system": sys, "code": req.ValueCode}
|
||||
if req.ValueCodeDisplay != "" {
|
||||
coding["display"] = req.ValueCodeDisplay
|
||||
}
|
||||
payload.Set("valueCodeableConcept", map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
||||
} else if req.ValueString != "" {
|
||||
case req.ValueString != "":
|
||||
payload.Set("valueString", req.ValueString)
|
||||
} else if req.ValueBoolean != nil {
|
||||
case req.ValueBoolean != nil:
|
||||
payload.Set("valueBoolean", *req.ValueBoolean)
|
||||
}
|
||||
|
||||
if len(req.Interpretation) > 0 {
|
||||
var interps []map[string]interface{}
|
||||
for _, interp := range req.Interpretation {
|
||||
if interp != nil {
|
||||
sys := interp.System
|
||||
if sys == "" {
|
||||
sys = "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": interp.Code}
|
||||
if interp.Display != "" {
|
||||
coding["display"] = interp.Display
|
||||
}
|
||||
interps = append(interps, map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
||||
}
|
||||
if req.InterpretationCode != "" {
|
||||
sys := req.InterpretationSystem
|
||||
if sys == "" {
|
||||
sys = "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation"
|
||||
}
|
||||
payload.Set("interpretation", interps)
|
||||
coding := map[string]interface{}{"system": sys, "code": req.InterpretationCode}
|
||||
if req.InterpretationDisplay != "" {
|
||||
coding["display"] = req.InterpretationDisplay
|
||||
}
|
||||
payload.Set("interpretation", []map[string]interface{}{
|
||||
{"coding": []map[string]interface{}{coding}},
|
||||
})
|
||||
}
|
||||
|
||||
if len(req.ReferenceRange) > 0 {
|
||||
var ranges []map[string]interface{}
|
||||
for _, r := range req.ReferenceRange {
|
||||
rng := map[string]interface{}{}
|
||||
if r.Low != nil {
|
||||
sys := r.Low.System
|
||||
if sys == "" {
|
||||
sys = "http://unitsofmeasure.org"
|
||||
}
|
||||
rng["low"] = map[string]interface{}{"value": r.Low.Value, "unit": r.Low.Unit, "system": sys, "code": r.Low.Code}
|
||||
if req.ReferenceRangeLowValue != nil || req.ReferenceRangeHighValue != nil || req.ReferenceRangeText != "" {
|
||||
rng := map[string]interface{}{}
|
||||
if req.ReferenceRangeLowValue != nil {
|
||||
low := map[string]interface{}{"value": *req.ReferenceRangeLowValue, "system": "http://unitsofmeasure.org"}
|
||||
if req.ReferenceRangeUnit != "" {
|
||||
low["unit"] = req.ReferenceRangeUnit
|
||||
low["code"] = req.ReferenceRangeUnit
|
||||
}
|
||||
if r.High != nil {
|
||||
sys := r.High.System
|
||||
if sys == "" {
|
||||
sys = "http://unitsofmeasure.org"
|
||||
}
|
||||
rng["high"] = map[string]interface{}{"value": r.High.Value, "unit": r.High.Unit, "system": sys, "code": r.High.Code}
|
||||
}
|
||||
if r.Text != "" {
|
||||
rng["text"] = r.Text
|
||||
}
|
||||
ranges = append(ranges, rng)
|
||||
rng["low"] = low
|
||||
}
|
||||
payload.Set("referenceRange", ranges)
|
||||
}
|
||||
|
||||
if len(req.Components) > 0 {
|
||||
var components []map[string]interface{}
|
||||
for _, comp := range req.Components {
|
||||
c := make(map[string]interface{})
|
||||
if comp.Code != nil {
|
||||
sys := comp.Code.System
|
||||
if sys == "" {
|
||||
sys = "http://loinc.org"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": comp.Code.Code}
|
||||
if comp.Code.Display != "" {
|
||||
coding["display"] = comp.Code.Display
|
||||
}
|
||||
c["code"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
if req.ReferenceRangeHighValue != nil {
|
||||
high := map[string]interface{}{"value": *req.ReferenceRangeHighValue, "system": "http://unitsofmeasure.org"}
|
||||
if req.ReferenceRangeUnit != "" {
|
||||
high["unit"] = req.ReferenceRangeUnit
|
||||
high["code"] = req.ReferenceRangeUnit
|
||||
}
|
||||
|
||||
if comp.ValueQuantity != nil {
|
||||
sysVQ := comp.ValueQuantity.System
|
||||
if sysVQ == "" {
|
||||
sysVQ = "http://unitsofmeasure.org"
|
||||
}
|
||||
c["valueQuantity"] = map[string]interface{}{"value": comp.ValueQuantity.Value, "unit": comp.ValueQuantity.Unit, "system": sysVQ, "code": comp.ValueQuantity.Code}
|
||||
} else if comp.ValueCodeableConcept != nil {
|
||||
sysVCC := comp.ValueCodeableConcept.System
|
||||
if sysVCC == "" {
|
||||
sysVCC = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sysVCC, "code": comp.ValueCodeableConcept.Code}
|
||||
if comp.ValueCodeableConcept.Display != "" {
|
||||
coding["display"] = comp.ValueCodeableConcept.Display
|
||||
}
|
||||
c["valueCodeableConcept"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
} else if comp.ValueString != "" {
|
||||
c["valueString"] = comp.ValueString
|
||||
} else if comp.ValueBoolean != nil {
|
||||
c["valueBoolean"] = *comp.ValueBoolean
|
||||
}
|
||||
components = append(components, c)
|
||||
rng["high"] = high
|
||||
}
|
||||
payload.Set("component", components)
|
||||
if req.ReferenceRangeText != "" {
|
||||
rng["text"] = req.ReferenceRangeText
|
||||
}
|
||||
payload.Set("referenceRange", []map[string]interface{}{rng})
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -15,15 +15,19 @@ type Service interface {
|
||||
Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error)
|
||||
}
|
||||
type service struct {
|
||||
repo Repository
|
||||
repo Repository
|
||||
orgID string
|
||||
}
|
||||
|
||||
// NewService membuat service observasi baru.
|
||||
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 ObservationRequest) (*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 ObservationRequest)
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("Observation 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