penambahan All case Satu sehat
This commit is contained in:
No files matched your search
@@ -3,22 +3,32 @@ package medicationdispense
|
||||
import "time"
|
||||
|
||||
type MedicationDispenseRequest struct {
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientName string `json:"patient_name" binding:"required"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
MedicationID string `json:"medication_id" binding:"required"`
|
||||
MedicationDisplay string `json:"medication_display" binding:"required"`
|
||||
PractitionerID string `json:"practitioner_id" binding:"required"`
|
||||
PractitionerName string `json:"practitioner_name" binding:"required"`
|
||||
LocationID string `json:"location_id" binding:"required"`
|
||||
LocationName string `json:"location_name" binding:"required"`
|
||||
PrescriptionID string `json:"prescription_id" binding:"required"` // Reference to MedicationRequest
|
||||
Status string `json:"status" binding:"required,oneof=preparation in-progress cancelled on-hold completed entered-in-error stopped declined unknown"`
|
||||
PreparedDate time.Time `json:"prepared_date" binding:"required"`
|
||||
HandedOverDate time.Time `json:"handed_over_date" binding:"required"`
|
||||
DispenseValue float64 `json:"dispense_value" binding:"required"`
|
||||
DispenseUnit string `json:"dispense_unit" binding:"required"`
|
||||
DosagePatientInstr string `json:"dosage_patient_instruction"`
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientName string `json:"patient_name,omitempty"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
MedicationID string `json:"medication_id" binding:"required"`
|
||||
MedicationDisplay string `json:"medication_display,omitempty"`
|
||||
PractitionerID string `json:"practitioner_id" binding:"required"`
|
||||
PractitionerName string `json:"practitioner_name,omitempty"`
|
||||
LocationID string `json:"location_id" binding:"required"`
|
||||
LocationName string `json:"location_name,omitempty"`
|
||||
PrescriptionID string `json:"prescription_id" binding:"required"` // Digunakan untuk Prescription Identifier
|
||||
PrescriptionItemID string `json:"prescription_item_id,omitempty"` // Digunakan untuk Identifier item
|
||||
Status string `json:"status" binding:"required,oneof=preparation in-progress cancelled on-hold completed entered-in-error stopped declined unknown"`
|
||||
Category string `json:"category,omitempty" binding:"omitempty,oneof=outpatient inpatient community discharge"`
|
||||
PreparedDate time.Time `json:"prepared_date" binding:"required"`
|
||||
HandedOverDate time.Time `json:"handed_over_date" binding:"required"`
|
||||
QuantityValue float64 `json:"quantity_value" binding:"required"`
|
||||
QuantityUnit string `json:"quantity_unit" binding:"required"` // e.g. TAB
|
||||
DaysSupplyValue int `json:"days_supply_value,omitempty"`
|
||||
DosageText string `json:"dosage_text,omitempty"`
|
||||
TimingFrequency int `json:"timing_frequency,omitempty"`
|
||||
TimingPeriod int `json:"timing_period,omitempty"`
|
||||
TimingPeriodUnit string `json:"timing_period_unit,omitempty"` // e.g. d, h
|
||||
DoseQuantityValue float64 `json:"dose_quantity_value,omitempty"`
|
||||
DoseQuantityUnit string `json:"dose_quantity_unit,omitempty"` // e.g. TAB
|
||||
MedicationRequestID string `json:"medication_request_id" binding:"required"` //Digunakan untuk authorizingPrescriptionID
|
||||
}
|
||||
|
||||
type MedicationDispensePatchRequest []map[string]interface{}
|
||||
@@ -1,51 +1,171 @@
|
||||
package medicationdispense
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req MedicationDispenseRequest) satusehat.FHIRPayload {
|
||||
payload := satusehat.NewFHIRPayload("MedicationDispense").
|
||||
Set("status", req.Status).
|
||||
Set("category", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://terminology.hl7.org/fhir/CodeSystem/medicationdispense-category",
|
||||
"code": "outpatient",
|
||||
"display": "Outpatient",
|
||||
},
|
||||
},
|
||||
}).
|
||||
Set("medicationReference", map[string]interface{}{
|
||||
"reference": "Medication/" + req.MedicationID,
|
||||
"display": req.MedicationDisplay,
|
||||
}).
|
||||
Set("subject", map[string]interface{}{
|
||||
"reference": "Patient/" + req.PatientID,
|
||||
"display": req.PatientName,
|
||||
}).
|
||||
Set("context", map[string]interface{}{
|
||||
"reference": "Encounter/" + req.EncounterID,
|
||||
}).
|
||||
Set("performer", []map[string]interface{}{
|
||||
payload := satusehat.NewFHIRPayload("MedicationDispense")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.PrescriptionID != "" {
|
||||
identifiers := []map[string]interface{}{
|
||||
{
|
||||
"actor": map[string]interface{}{
|
||||
"reference": "Practitioner/" + req.PractitionerID,
|
||||
"display": req.PractitionerName,
|
||||
},
|
||||
"system": "http://sys-ids.kemkes.go.id/prescription/" + orgID,
|
||||
"use": "official",
|
||||
"value": req.PrescriptionID,
|
||||
},
|
||||
}).
|
||||
Set("location", map[string]interface{}{
|
||||
"reference": "Location/" + req.LocationID,
|
||||
"display": req.LocationName,
|
||||
}).
|
||||
Set("authorizingPrescription", []map[string]interface{}{
|
||||
{"reference": "MedicationRequest/" + req.PrescriptionID},
|
||||
}).
|
||||
Set("whenPrepared", req.PreparedDate.Format(time.RFC3339)).
|
||||
Set("whenHandedOver", req.HandedOverDate.Format(time.RFC3339))
|
||||
}
|
||||
if req.PrescriptionItemID != "" {
|
||||
identifiers = append(identifiers, map[string]interface{}{
|
||||
"system": "http://sys-ids.kemkes.go.id/prescription-item/" + orgID,
|
||||
"use": "official",
|
||||
"value": req.PrescriptionItemID,
|
||||
})
|
||||
}
|
||||
payload.Set("identifier", identifiers)
|
||||
}
|
||||
|
||||
if req.Status != "" {
|
||||
payload.Set("status", req.Status)
|
||||
}
|
||||
|
||||
categoryCode := "outpatient"
|
||||
categoryDisplay := "Outpatient"
|
||||
if req.Category != "" {
|
||||
categoryCode = req.Category
|
||||
switch req.Category {
|
||||
case "inpatient":
|
||||
categoryDisplay = "Inpatient"
|
||||
case "community":
|
||||
categoryDisplay = "Community"
|
||||
case "discharge":
|
||||
categoryDisplay = "Discharge"
|
||||
}
|
||||
}
|
||||
payload.Set("category", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://terminology.hl7.org/fhir/CodeSystem/medicationdispense-category",
|
||||
"code": categoryCode,
|
||||
"display": categoryDisplay,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if req.MedicationID != "" {
|
||||
medRef := map[string]interface{}{"reference": "Medication/" + req.MedicationID}
|
||||
if req.MedicationDisplay != "" {
|
||||
medRef["display"] = req.MedicationDisplay
|
||||
}
|
||||
payload.Set("medicationReference", medRef)
|
||||
}
|
||||
|
||||
if req.PatientID != "" {
|
||||
subj := map[string]interface{}{"reference": "Patient/" + req.PatientID}
|
||||
if req.PatientName != "" {
|
||||
subj["display"] = req.PatientName
|
||||
}
|
||||
payload.Set("subject", subj)
|
||||
}
|
||||
|
||||
if req.EncounterID != "" {
|
||||
payload.Set("context", map[string]interface{}{"reference": "Encounter/" + req.EncounterID})
|
||||
}
|
||||
|
||||
if req.PractitionerID != "" {
|
||||
actor := map[string]interface{}{"reference": "Practitioner/" + req.PractitionerID}
|
||||
if req.PractitionerName != "" {
|
||||
actor["display"] = req.PractitionerName
|
||||
}
|
||||
payload.Set("performer", []map[string]interface{}{{"actor": actor}})
|
||||
}
|
||||
|
||||
if req.LocationID != "" {
|
||||
loc := map[string]interface{}{"reference": "Location/" + req.LocationID}
|
||||
if req.LocationName != "" {
|
||||
loc["display"] = req.LocationName
|
||||
}
|
||||
payload.Set("location", loc)
|
||||
}
|
||||
|
||||
if req.MedicationRequestID != "" {
|
||||
payload.Set("authorizingPrescription", []map[string]interface{}{{"reference": "MedicationRequest/" + req.MedicationRequestID}})
|
||||
}
|
||||
|
||||
if req.QuantityValue != 0 || req.QuantityUnit != "" {
|
||||
qty := map[string]interface{}{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm",
|
||||
}
|
||||
if req.QuantityValue != 0 {
|
||||
qty["value"] = req.QuantityValue
|
||||
}
|
||||
if req.QuantityUnit != "" {
|
||||
qty["code"] = req.QuantityUnit
|
||||
}
|
||||
payload.Set("quantity", qty)
|
||||
}
|
||||
|
||||
if req.DaysSupplyValue != 0 {
|
||||
payload.Set("daysSupply", map[string]interface{}{
|
||||
"value": req.DaysSupplyValue,
|
||||
"unit": "Day",
|
||||
"system": "http://unitsofmeasure.org",
|
||||
"code": "d",
|
||||
})
|
||||
}
|
||||
|
||||
if !req.PreparedDate.IsZero() {
|
||||
payload.Set("whenPrepared", req.PreparedDate.Format(time.RFC3339))
|
||||
}
|
||||
if !req.HandedOverDate.IsZero() {
|
||||
payload.Set("whenHandedOver", req.HandedOverDate.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if req.DosageText != "" || req.TimingFrequency != 0 || req.DoseQuantityValue != 0 {
|
||||
dose := map[string]interface{}{"sequence": 1}
|
||||
if req.DosageText != "" {
|
||||
dose["text"] = req.DosageText
|
||||
}
|
||||
if req.TimingFrequency != 0 && req.TimingPeriod != 0 && req.TimingPeriodUnit != "" {
|
||||
dose["timing"] = map[string]interface{}{
|
||||
"repeat": map[string]interface{}{
|
||||
"frequency": req.TimingFrequency,
|
||||
"period": req.TimingPeriod,
|
||||
"periodUnit": req.TimingPeriodUnit,
|
||||
},
|
||||
}
|
||||
}
|
||||
if req.DoseQuantityValue != 0 && req.DoseQuantityUnit != "" {
|
||||
dose["doseAndRate"] = []map[string]interface{}{
|
||||
{
|
||||
"type": map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/dose-rate-type",
|
||||
"code": "ordered",
|
||||
"display": "Ordered",
|
||||
},
|
||||
},
|
||||
},
|
||||
"doseQuantity": map[string]interface{}{
|
||||
"value": req.DoseQuantityValue,
|
||||
"unit": req.DoseQuantityUnit,
|
||||
"system": "http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm",
|
||||
"code": req.DoseQuantityUnit,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
payload.Set("dosageInstruction", []map[string]interface{}{dose})
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/url"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
"service/pkg/errors"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
@@ -25,14 +26,21 @@ 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 {
|
||||
|
||||
@@ -36,9 +36,18 @@ func (s *service) Update(ctx context.Context, id string, req MedicationDispenseR
|
||||
return s.repo.Update(ctx, id, payload)
|
||||
}
|
||||
func (s *service) Patch(ctx context.Context, id string, req MedicationDispensePatchRequest) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("MedicationDispense 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("MedicationDispense 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