penambahan All case Satu sehat
This commit is contained in:
No files matched your search
@@ -1,17 +1,40 @@
|
||||
package clinicalimpression
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"service/internal/satusehat/common"
|
||||
)
|
||||
|
||||
type ClinicalImpressionRequest struct {
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientName string `json:"patient_name" binding:"required"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
PractitionerID string `json:"practitioner_id" binding:"required"`
|
||||
PractitionerName string `json:"practitioner_name" binding:"required"`
|
||||
Status string `json:"status" binding:"required,oneof=in-progress completed entered-in-error"`
|
||||
Date time.Time `json:"date" binding:"required"`
|
||||
Summary string `json:"summary" binding:"required"`
|
||||
Description string `json:"description" binding:"required"`
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
ClinicalImpressionID string `json:"clinical_impression_id,omitempty"`
|
||||
Status string `json:"status" binding:"required,oneof=in-progress completed entered-in-error"`
|
||||
Code *common.CodeableConceptDTO `json:"code,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientDisplay string `json:"patient_display,omitempty"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
EncounterDisplay string `json:"encounter_display,omitempty"`
|
||||
EffectiveDateTime *time.Time `json:"effective_datetime,omitempty"`
|
||||
Date *time.Time `json:"date,omitempty"`
|
||||
AssessorID string `json:"assessor_id,omitempty"`
|
||||
AssessorDisplay string `json:"assessor_display,omitempty"`
|
||||
Problem []common.ReferenceDTO `json:"problem,omitempty"`
|
||||
Investigations []InvestigationDTO `json:"investigations,omitempty"`
|
||||
Summary string `json:"summary,omitempty"`
|
||||
Findings []FindingDTO `json:"findings,omitempty"`
|
||||
Prognosis []*common.CodeableConceptDTO `json:"prognosis,omitempty"`
|
||||
}
|
||||
|
||||
type InvestigationDTO struct {
|
||||
Code *common.CodeableConceptDTO `json:"code,omitempty"`
|
||||
Item []common.ReferenceDTO `json:"item,omitempty"`
|
||||
}
|
||||
|
||||
type FindingDTO struct {
|
||||
ItemCodeableConcept *common.CodeableConceptDTO `json:"item_codeable_concept,omitempty"`
|
||||
ItemReference *common.ReferenceDTO `json:"item_reference,omitempty"`
|
||||
}
|
||||
|
||||
type ClinicalImpressionPatchRequest []map[string]interface{}
|
||||
@@ -1,23 +1,186 @@
|
||||
package clinicalimpression
|
||||
|
||||
import (
|
||||
"os"
|
||||
"service/internal/interfaces/satusehat"
|
||||
"time"
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req ClinicalImpressionRequest) satusehat.FHIRPayload {
|
||||
return satusehat.NewFHIRPayload("ClinicalImpression").
|
||||
Set("status", req.Status).
|
||||
Set("description", req.Description).
|
||||
Set("summary", req.Summary).
|
||||
Set("subject", map[string]interface{}{
|
||||
"reference": "Patient/" + req.PatientID,
|
||||
"display": req.PatientName,
|
||||
}).
|
||||
Set("encounter", map[string]interface{}{"reference": "Encounter/" + req.EncounterID}).
|
||||
Set("assessor", map[string]interface{}{
|
||||
"reference": "Practitioner/" + req.PractitionerID,
|
||||
"display": req.PractitionerName,
|
||||
}).
|
||||
Set("date", req.Date.Format(time.RFC3339))
|
||||
payload := satusehat.NewFHIRPayload("ClinicalImpression")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.ClinicalImpressionID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{
|
||||
"system": "http://sys-ids.kemkes.go.id/clinicalimpression/" + orgID,
|
||||
"use": "official",
|
||||
"value": req.ClinicalImpressionID,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if req.Status != "" {
|
||||
payload.Set("status", req.Status)
|
||||
}
|
||||
|
||||
if req.Code != nil {
|
||||
sys := req.Code.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.Code.Code}
|
||||
if req.Code.Display != "" {
|
||||
coding["display"] = req.Code.Display
|
||||
}
|
||||
payload.Set("code", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
coding,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if req.Description != "" {
|
||||
payload.Set("description", req.Description)
|
||||
}
|
||||
|
||||
if req.PatientID != "" {
|
||||
subject := map[string]interface{}{"reference": "Patient/" + req.PatientID}
|
||||
if req.PatientDisplay != "" {
|
||||
subject["display"] = req.PatientDisplay
|
||||
}
|
||||
payload.Set("subject", 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.EffectiveDateTime != nil && !req.EffectiveDateTime.IsZero() {
|
||||
payload.Set("effectiveDateTime", req.EffectiveDateTime.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if req.Date != nil && !req.Date.IsZero() {
|
||||
payload.Set("date", req.Date.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if req.AssessorID != "" {
|
||||
assessor := map[string]interface{}{"reference": "Practitioner/" + req.AssessorID}
|
||||
if req.AssessorDisplay != "" {
|
||||
assessor["display"] = req.AssessorDisplay
|
||||
}
|
||||
payload.Set("assessor", assessor)
|
||||
}
|
||||
|
||||
if len(req.Problem) > 0 {
|
||||
var problems []map[string]interface{}
|
||||
for _, p := range req.Problem {
|
||||
problem := map[string]interface{}{"reference": p.Reference}
|
||||
if p.Display != "" {
|
||||
problem["display"] = p.Display
|
||||
}
|
||||
problems = append(problems, problem)
|
||||
}
|
||||
payload.Set("problem", problems)
|
||||
}
|
||||
|
||||
if len(req.Investigations) > 0 {
|
||||
var investigations []map[string]interface{}
|
||||
for _, inv := range req.Investigations {
|
||||
invObject := map[string]interface{}{}
|
||||
if inv.Code != nil {
|
||||
codeConcept := map[string]interface{}{}
|
||||
sys := inv.Code.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": inv.Code.Code}
|
||||
if inv.Code.Display != "" {
|
||||
coding["display"] = inv.Code.Display
|
||||
}
|
||||
codeConcept["coding"] = []map[string]interface{}{coding}
|
||||
if inv.Code.Text != "" {
|
||||
codeConcept["text"] = inv.Code.Text
|
||||
}
|
||||
invObject["code"] = codeConcept
|
||||
}
|
||||
|
||||
if len(inv.Item) > 0 {
|
||||
var items []map[string]interface{}
|
||||
for _, item := range inv.Item {
|
||||
ref := map[string]interface{}{"reference": item.Reference}
|
||||
if item.Display != "" {
|
||||
ref["display"] = item.Display
|
||||
}
|
||||
items = append(items, ref)
|
||||
}
|
||||
invObject["item"] = items
|
||||
}
|
||||
investigations = append(investigations, invObject)
|
||||
}
|
||||
payload.Set("investigation", investigations)
|
||||
}
|
||||
|
||||
if req.Summary != "" {
|
||||
payload.Set("summary", req.Summary)
|
||||
}
|
||||
|
||||
if len(req.Findings) > 0 {
|
||||
var findings []map[string]interface{}
|
||||
for _, f := range req.Findings {
|
||||
findingObject := map[string]interface{}{}
|
||||
if f.ItemCodeableConcept != nil {
|
||||
sys := f.ItemCodeableConcept.System
|
||||
if sys == "" {
|
||||
sys = "http://hl7.org/fhir/sid/icd-10"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": f.ItemCodeableConcept.Code}
|
||||
if f.ItemCodeableConcept.Display != "" {
|
||||
coding["display"] = f.ItemCodeableConcept.Display
|
||||
}
|
||||
findingObject["itemCodeableConcept"] = map[string]interface{}{
|
||||
"coding": []map[string]interface{}{coding},
|
||||
}
|
||||
}
|
||||
if f.ItemReference != nil {
|
||||
ref := map[string]interface{}{"reference": f.ItemReference.Reference}
|
||||
if f.ItemReference.Display != "" {
|
||||
ref["display"] = f.ItemReference.Display
|
||||
}
|
||||
findingObject["itemReference"] = ref
|
||||
}
|
||||
if len(findingObject) > 0 {
|
||||
findings = append(findings, findingObject)
|
||||
}
|
||||
}
|
||||
payload.Set("finding", findings)
|
||||
}
|
||||
|
||||
if len(req.Prognosis) > 0 {
|
||||
var prognosis []map[string]interface{}
|
||||
for _, p := range req.Prognosis {
|
||||
if p != nil {
|
||||
sys := p.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": p.Code}
|
||||
if p.Display != "" {
|
||||
coding["display"] = p.Display
|
||||
}
|
||||
prognosis = append(prognosis, map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
||||
}
|
||||
}
|
||||
payload.Set("prognosisCodeableConcept", prognosis)
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"service/internal/interfaces/satusehat"
|
||||
"service/pkg/errors"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
@@ -19,14 +20,21 @@ 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 {
|
||||
|
||||
@@ -24,12 +24,23 @@ func (s *service) Update(ctx context.Context, id string, req ClinicalImpressionR
|
||||
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 ClinicalImpressionPatchRequest) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("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("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