penambahan All case Satu sehat
This commit is contained in:
No files matched your search
@@ -1,20 +1,28 @@
|
||||
package diagnosticreport
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"service/internal/satusehat/common"
|
||||
)
|
||||
|
||||
type DiagnosticReportRequest 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=registered partial preliminary final amended corrected appended cancelled entered-in-error unknown"`
|
||||
CategoryCode string `json:"category_code" binding:"required"` // e.g. LAB
|
||||
CategoryDisplay string `json:"category_display" binding:"required"`
|
||||
Code string `json:"code" binding:"required"` // LOINC code
|
||||
Display string `json:"display" binding:"required"`
|
||||
Issued time.Time `json:"issued" binding:"required"`
|
||||
Conclusion string `json:"conclusion" binding:"required"`
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
DiagnosticID string `json:"diagnostic_id,omitempty"` // e.g. "5234342"
|
||||
Status string `json:"status" binding:"required,oneof=registered partial preliminary final amended corrected appended cancelled entered-in-error unknown"`
|
||||
Category []*common.CodeableConceptDTO `json:"category,omitempty"`
|
||||
Code *common.CodeableConceptDTO `json:"code" binding:"required"`
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
EffectiveDateTime *time.Time `json:"effective_datetime,omitempty"`
|
||||
Issued *time.Time `json:"issued,omitempty"`
|
||||
Performer []common.ReferenceDTO `json:"performer,omitempty"`
|
||||
Result []common.ReferenceDTO `json:"result,omitempty"`
|
||||
Specimen []common.ReferenceDTO `json:"specimen,omitempty"`
|
||||
BasedOn []common.ReferenceDTO `json:"based_on,omitempty"`
|
||||
ImagingStudy []common.ReferenceDTO `json:"imaging_study,omitempty"`
|
||||
ConclusionCode []*common.CodeableConceptDTO `json:"conclusion_code,omitempty"`
|
||||
Conclusion string `json:"conclusion,omitempty"`
|
||||
}
|
||||
|
||||
type DiagnosticReportPatchRequest []map[string]interface{}
|
||||
@@ -1,41 +1,169 @@
|
||||
package diagnosticreport
|
||||
|
||||
import (
|
||||
"service/internal/interfaces/satusehat"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req DiagnosticReportRequest) satusehat.FHIRPayload {
|
||||
return satusehat.NewFHIRPayload("DiagnosticReport").
|
||||
Set("status", req.Status).
|
||||
Set("category", []map[string]interface{}{
|
||||
payload := satusehat.NewFHIRPayload("DiagnosticReport")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.DiagnosticID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/v2-0074",
|
||||
"code": req.CategoryCode,
|
||||
"display": req.CategoryDisplay,
|
||||
},
|
||||
},
|
||||
"system": "http://sys-ids.kemkes.go.id/diagnostic/" + orgID + "/lab",
|
||||
"use": "official",
|
||||
"value": req.DiagnosticID,
|
||||
},
|
||||
}).
|
||||
Set("code", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://loinc.org",
|
||||
"code": req.Code,
|
||||
"display": req.Display,
|
||||
},
|
||||
},
|
||||
}).
|
||||
Set("subject", map[string]interface{}{
|
||||
})
|
||||
}
|
||||
|
||||
if req.Status != "" {
|
||||
payload.Set("status", req.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/v2-0074"
|
||||
}
|
||||
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}})
|
||||
}
|
||||
}
|
||||
payload.Set("category", categories)
|
||||
}
|
||||
|
||||
if req.Code != nil {
|
||||
sys := req.Code.System
|
||||
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
|
||||
}
|
||||
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 != "" {
|
||||
payload.Set("subject", map[string]interface{}{
|
||||
"reference": "Patient/" + req.PatientID,
|
||||
"display": req.PatientName,
|
||||
}).
|
||||
Set("encounter", map[string]interface{}{"reference": "Encounter/" + req.EncounterID}).
|
||||
Set("performer", []map[string]interface{}{
|
||||
{"reference": "Practitioner/" + req.PractitionerID, "display": req.PractitionerName},
|
||||
}).
|
||||
Set("issued", req.Issued.Format(time.RFC3339)).
|
||||
Set("conclusion", req.Conclusion)
|
||||
})
|
||||
}
|
||||
|
||||
if req.EncounterID != "" {
|
||||
payload.Set("encounter", map[string]interface{}{
|
||||
"reference": "Encounter/" + req.EncounterID,
|
||||
})
|
||||
}
|
||||
|
||||
if req.EffectiveDateTime != nil && !req.EffectiveDateTime.IsZero() {
|
||||
payload.Set("effectiveDateTime", req.EffectiveDateTime.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if req.Issued != nil && !req.Issued.IsZero() {
|
||||
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)
|
||||
}
|
||||
payload.Set("performer", performers)
|
||||
}
|
||||
|
||||
if len(req.Result) > 0 {
|
||||
var results []map[string]interface{}
|
||||
for _, r := range req.Result {
|
||||
res := map[string]interface{}{"reference": r.Reference}
|
||||
if r.Display != "" {
|
||||
res["display"] = r.Display
|
||||
}
|
||||
results = append(results, res)
|
||||
}
|
||||
payload.Set("result", results)
|
||||
}
|
||||
|
||||
if len(req.Specimen) > 0 {
|
||||
var specimens []map[string]interface{}
|
||||
for _, s := range req.Specimen {
|
||||
spec := map[string]interface{}{"reference": s.Reference}
|
||||
if s.Display != "" {
|
||||
spec["display"] = s.Display
|
||||
}
|
||||
specimens = append(specimens, spec)
|
||||
}
|
||||
payload.Set("specimen", specimens)
|
||||
}
|
||||
|
||||
if len(req.BasedOn) > 0 {
|
||||
var basedOns []map[string]interface{}
|
||||
for _, b := range req.BasedOn {
|
||||
bo := map[string]interface{}{"reference": b.Reference}
|
||||
if b.Display != "" {
|
||||
bo["display"] = b.Display
|
||||
}
|
||||
basedOns = append(basedOns, bo)
|
||||
}
|
||||
payload.Set("basedOn", basedOns)
|
||||
}
|
||||
|
||||
if len(req.ImagingStudy) > 0 {
|
||||
var imagingStudies []map[string]interface{}
|
||||
for _, i := range req.ImagingStudy {
|
||||
is := map[string]interface{}{"reference": i.Reference}
|
||||
if i.Display != "" {
|
||||
is["display"] = i.Display
|
||||
}
|
||||
imagingStudies = append(imagingStudies, is)
|
||||
}
|
||||
payload.Set("imagingStudy", imagingStudies)
|
||||
}
|
||||
|
||||
if len(req.ConclusionCode) > 0 {
|
||||
var concCodes []map[string]interface{}
|
||||
for _, c := range req.ConclusionCode {
|
||||
if c != nil {
|
||||
sys := c.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": c.Code}
|
||||
if c.Display != "" {
|
||||
coding["display"] = c.Display
|
||||
}
|
||||
concCodes = append(concCodes, map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
||||
}
|
||||
}
|
||||
payload.Set("conclusionCode", concCodes)
|
||||
}
|
||||
|
||||
if req.Conclusion != "" {
|
||||
payload.Set("conclusion", req.Conclusion)
|
||||
}
|
||||
|
||||
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 DiagnosticReportReq
|
||||
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 DiagnosticReportPatchRequest) (*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