first commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package imagingstudy
|
||||
|
||||
import "time"
|
||||
|
||||
type ImagingStudyRequest struct {
|
||||
PatientID string `json:"patient_id"`
|
||||
PatientName string `json:"patient_name"`
|
||||
EncounterID string `json:"encounter_id"`
|
||||
PractitionerID string `json:"practitioner_id"`
|
||||
PractitionerName string `json:"practitioner_name"`
|
||||
Status string `json:"status"` // registered, available, cancelled, entered-in-error, unknown
|
||||
Started time.Time `json:"started"`
|
||||
NumberOfSeries int `json:"number_of_series"`
|
||||
NumberOfInstances int `json:"number_of_instances"`
|
||||
ProcedureCode string `json:"procedure_code"` // SNOMED CT
|
||||
ProcedureDisplay string `json:"procedure_display"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type ImagingStudyPatchRequest []map[string]interface{}
|
||||
@@ -0,0 +1,39 @@
|
||||
package imagingstudy
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req ImagingStudyRequest) satusehat.FHIRPayload {
|
||||
payload := satusehat.NewFHIRPayload("ImagingStudy").
|
||||
Set("status", req.Status).
|
||||
Set("subject", map[string]interface{}{
|
||||
"reference": "Patient/" + req.PatientID,
|
||||
"display": req.PatientName,
|
||||
}).
|
||||
Set("encounter", map[string]interface{}{
|
||||
"reference": "Encounter/" + req.EncounterID,
|
||||
}).
|
||||
Set("started", req.Started.Format(time.RFC3339)).
|
||||
Set("numberOfSeries", req.NumberOfSeries).
|
||||
Set("numberOfInstances", req.NumberOfInstances).
|
||||
Set("description", req.Description)
|
||||
|
||||
if req.ProcedureCode != "" {
|
||||
payload.Set("procedureCode", []map[string]interface{}{
|
||||
{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://snomed.info/sct",
|
||||
"code": req.ProcedureCode,
|
||||
"display": req.ProcedureDisplay,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package imagingstudy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"service/internal/interfaces/satusehat"
|
||||
)
|
||||
|
||||
// Repository mendefinisikan kontrak untuk operasi penyimpanan data ImagingStudy.
|
||||
type Repository interface {
|
||||
Create(ctx context.Context, payload interface{}) (*satusehat.FHIRResponse, error)
|
||||
Update(ctx context.Context, id string, payload interface{}) (*satusehat.FHIRResponse, error)
|
||||
Patch(ctx context.Context, id string, payload ImagingStudyPatchRequest) (*satusehat.FHIRResponse, error)
|
||||
GetByID(ctx context.Context, id string) (*satusehat.FHIRResponse, error)
|
||||
Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error)
|
||||
}
|
||||
|
||||
type repository struct {
|
||||
client satusehat.SatuSehatClient
|
||||
}
|
||||
|
||||
// NewRepository membuat repositori ImagingStudy baru.
|
||||
func NewRepository(client satusehat.SatuSehatClient) Repository {
|
||||
return &repository{client: client}
|
||||
}
|
||||
|
||||
func (r *repository) executeRequest(ctx context.Context, method, endpoint string, req interface{}) (*satusehat.FHIRResponse, error) {
|
||||
resp, err := r.client.DoRequest(ctx, method, endpoint, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result map[string]interface{}
|
||||
if err := json.Unmarshal(resp, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
|
||||
}
|
||||
|
||||
var resourceID string
|
||||
if id, ok := result["id"].(string); ok {
|
||||
resourceID = id
|
||||
}
|
||||
|
||||
return &satusehat.FHIRResponse{
|
||||
ID: resourceID,
|
||||
FullResponse: result,
|
||||
RawResponse: resp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *repository) Create(ctx context.Context, payload interface{}) (*satusehat.FHIRResponse, error) {
|
||||
return r.executeRequest(ctx, "POST", "/ImagingStudy", payload)
|
||||
}
|
||||
|
||||
func (r *repository) Update(ctx context.Context, id string, payload interface{}) (*satusehat.FHIRResponse, error) {
|
||||
endpoint := fmt.Sprintf("/ImagingStudy/%s", id)
|
||||
return r.executeRequest(ctx, "PUT", endpoint, payload)
|
||||
}
|
||||
|
||||
func (r *repository) Patch(ctx context.Context, id string, payload ImagingStudyPatchRequest) (*satusehat.FHIRResponse, error) {
|
||||
endpoint := fmt.Sprintf("/ImagingStudy/%s", id)
|
||||
return r.executeRequest(ctx, "PATCH", endpoint, payload)
|
||||
}
|
||||
|
||||
func (r *repository) GetByID(ctx context.Context, id string) (*satusehat.FHIRResponse, error) {
|
||||
endpoint := fmt.Sprintf("/ImagingStudy/%s", id)
|
||||
return r.executeRequest(ctx, "GET", endpoint, nil)
|
||||
}
|
||||
|
||||
func (r *repository) Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error) {
|
||||
endpoint := fmt.Sprintf("/ImagingStudy?%s", queryParams.Encode())
|
||||
return r.executeRequest(ctx, "GET", endpoint, nil)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package imagingstudy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"service/internal/interfaces/satusehat"
|
||||
"service/pkg/errors"
|
||||
)
|
||||
|
||||
// Service mendefinisikan kontrak untuk logika bisnis ImagingStudy.
|
||||
type Service interface {
|
||||
Create(ctx context.Context, req ImagingStudyRequest) (*satusehat.FHIRResponse, error)
|
||||
Update(ctx context.Context, id string, req ImagingStudyRequest) (*satusehat.FHIRResponse, error)
|
||||
Patch(ctx context.Context, id string, req ImagingStudyPatchRequest) (*satusehat.FHIRResponse, error)
|
||||
GetByID(ctx context.Context, id string) (*satusehat.FHIRResponse, error)
|
||||
Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error)
|
||||
}
|
||||
|
||||
type service struct {
|
||||
repo Repository
|
||||
}
|
||||
|
||||
// NewService membuat service ImagingStudy baru.
|
||||
func NewService(repo Repository) Service {
|
||||
return &service{repo: repo}
|
||||
}
|
||||
|
||||
func (s *service) Create(ctx context.Context, req ImagingStudyRequest) (*satusehat.FHIRResponse, error) {
|
||||
fhirPayload := MapRequestToFHIR(req)
|
||||
return s.repo.Create(ctx, fhirPayload)
|
||||
}
|
||||
|
||||
func (s *service) Update(ctx context.Context, id string, req ImagingStudyRequest) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("ImagingStudy ID is required").Build()
|
||||
}
|
||||
|
||||
fhirPayload := MapRequestToFHIR(req)
|
||||
fhirPayload.Set("id", id)
|
||||
|
||||
return s.repo.Update(ctx, id, fhirPayload)
|
||||
}
|
||||
|
||||
func (s *service) Patch(ctx context.Context, id string, req ImagingStudyPatchRequest) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("ImagingStudy 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("ImagingStudy ID is required").Build()
|
||||
}
|
||||
return s.repo.GetByID(ctx, id)
|
||||
}
|
||||
|
||||
func (s *service) Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error) {
|
||||
return s.repo.Search(ctx, queryParams)
|
||||
}
|
||||
Reference in New Issue
Block a user