penambahan All case Satu sehat
This commit is contained in:
@@ -3,18 +3,21 @@ 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"`
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
AccessionNumber string `json:"accession_number,omitempty"`
|
||||
ServiceRequestID string `json:"service_request_id,omitempty"`
|
||||
PatientID string `json:"patient_id,omitempty"`
|
||||
PatientName string `json:"patient_name,omitempty"`
|
||||
EncounterID string `json:"encounter_id,omitempty"`
|
||||
PractitionerID string `json:"practitioner_id,omitempty"`
|
||||
PractitionerName string `json:"practitioner_name,omitempty"`
|
||||
Status string `json:"status,omitempty"` // registered, available, cancelled, entered-in-error, unknown
|
||||
Started time.Time `json:"started,omitempty"`
|
||||
NumberOfSeries *int `json:"number_of_series,omitempty"`
|
||||
NumberOfInstances *int `json:"number_of_instances,omitempty"`
|
||||
ProcedureCode string `json:"procedure_code,omitempty"` // SNOMED CT
|
||||
ProcedureDisplay string `json:"procedure_display,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
type ImagingStudyPatchRequest []map[string]interface{}
|
||||
|
||||
@@ -1,39 +1,103 @@
|
||||
package imagingstudy
|
||||
|
||||
import (
|
||||
"os"
|
||||
"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)
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if req.ProcedureCode != "" {
|
||||
payload.Set("procedureCode", []map[string]interface{}{
|
||||
payload := satusehat.NewFHIRPayload("ImagingStudy")
|
||||
|
||||
if req.Status != "" {
|
||||
payload.Set("status", req.Status)
|
||||
}
|
||||
|
||||
if req.PatientID != "" {
|
||||
subject := map[string]interface{}{
|
||||
"reference": "Patient/" + req.PatientID,
|
||||
}
|
||||
if req.PatientName != "" {
|
||||
subject["display"] = req.PatientName
|
||||
}
|
||||
payload.Set("subject", subject)
|
||||
}
|
||||
|
||||
if !req.Started.IsZero() {
|
||||
payload.Set("started", req.Started.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if orgID != "" && req.AccessionNumber != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://snomed.info/sct",
|
||||
"code": req.ProcedureCode,
|
||||
"display": req.ProcedureDisplay,
|
||||
"use": "official",
|
||||
"type": map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
|
||||
"code": "ACSN",
|
||||
},
|
||||
},
|
||||
},
|
||||
"system": "http://sys-ids.kemkes.go.id/acsn/" + orgID,
|
||||
"value": req.AccessionNumber,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if req.ServiceRequestID != "" {
|
||||
payload.Set("basedOn", []map[string]interface{}{
|
||||
{
|
||||
"reference": "ServiceRequest/" + req.ServiceRequestID,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if req.ProcedureCode != "" {
|
||||
modality := map[string]interface{}{
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": req.ProcedureCode,
|
||||
}
|
||||
if req.ProcedureDisplay != "" {
|
||||
modality["display"] = req.ProcedureDisplay
|
||||
}
|
||||
payload.Set("modality", []map[string]interface{}{modality})
|
||||
}
|
||||
|
||||
// Menambahkan Practitioner ke kolom `interpreter` jika disediakan
|
||||
if req.PractitionerID != "" {
|
||||
interpreter := map[string]interface{}{
|
||||
"reference": "Practitioner/" + req.PractitionerID,
|
||||
}
|
||||
if req.PractitionerName != "" {
|
||||
interpreter["display"] = req.PractitionerName
|
||||
}
|
||||
payload.Set("interpreter", []map[string]interface{}{interpreter})
|
||||
}
|
||||
|
||||
if req.EncounterID != "" {
|
||||
payload.Set("encounter", map[string]interface{}{
|
||||
"reference": "Encounter/" + req.EncounterID,
|
||||
})
|
||||
}
|
||||
|
||||
if req.NumberOfSeries != nil {
|
||||
payload.Set("numberOfSeries", *req.NumberOfSeries)
|
||||
}
|
||||
|
||||
if req.NumberOfInstances != nil {
|
||||
payload.Set("numberOfInstances", *req.NumberOfInstances)
|
||||
}
|
||||
|
||||
if req.Description != "" {
|
||||
payload.Set("description", req.Description)
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"service/internal/interfaces/satusehat"
|
||||
"service/pkg/errors"
|
||||
)
|
||||
|
||||
// Repository mendefinisikan kontrak untuk operasi penyimpanan data ImagingStudy.
|
||||
@@ -26,15 +27,33 @@ func NewRepository(client satusehat.SatuSehatClient) Repository {
|
||||
return &repository{client: client}
|
||||
}
|
||||
|
||||
// hiddenCtx membungkus context untuk mencegah *HTTP client*
|
||||
// melakukan type-assertion ke *gin.Context dan melakukan auto-print error.
|
||||
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()
|
||||
}
|
||||
|
||||
// Tangkap respons OperationOutcome dan serahkan ke Parser terpusat
|
||||
if resourceType, ok := result["resourceType"].(string); ok && resourceType == "OperationOutcome" {
|
||||
return nil, errors.ParseSatuSehatError(result)
|
||||
}
|
||||
|
||||
var resourceID string
|
||||
|
||||
Reference in New Issue
Block a user