penambahan All case Satu sehat
This commit is contained in:
@@ -3,21 +3,41 @@ package medicationrequest
|
||||
import "time"
|
||||
|
||||
type MedicationRequestRequest 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"`
|
||||
MedicationID string `json:"medication_id" binding:"required"` // Reference to Medication resource
|
||||
MedicationDisplay string `json:"medication_display" binding:"required"`
|
||||
Status string `json:"status" binding:"required,oneof=active on-hold cancelled completed entered-in-error stopped draft unknown"`
|
||||
Intent string `json:"intent" binding:"required,oneof=proposal plan order original-order reflex-order filler-order instance-order option"`
|
||||
AuthoredOn time.Time `json:"authored_on" binding:"required"`
|
||||
DosageText string `json:"dosage_text" binding:"required"`
|
||||
PatientInstr string `json:"patient_instruction"`
|
||||
DispenseValue float64 `json:"dispense_value" binding:"required"`
|
||||
DispenseUnit string `json:"dispense_unit" binding:"required"`
|
||||
SupplyDuration int `json:"supply_duration" binding:"required"` // in days
|
||||
MedicationRequestID string `json:"medicationrequest_id,omitempty"` // Contoh: No Resep / ID Resep
|
||||
PrescriptionItemID string `json:"prescription_item_id,omitempty"`
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
Category string `json:"category,omitempty" binding:"omitempty,oneof=outpatient inpatient community discharge"`
|
||||
Priority string `json:"priority,omitempty" binding:"omitempty,oneof=routine urgent asap stat"`
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientName string `json:"patient_name,omitempty"`
|
||||
EncounterID string `json:"encounter_id" binding:"required"`
|
||||
PractitionerID string `json:"practitioner_id" binding:"required"`
|
||||
PractitionerName string `json:"practitioner_name,omitempty"`
|
||||
MedicationID string `json:"medication_id" binding:"required"` // Reference to Medication resource
|
||||
MedicationDisplay string `json:"medication_display,omitempty"`
|
||||
ReasonCode string `json:"reason_code,omitempty"`
|
||||
ReasonDisplay string `json:"reason_display,omitempty"`
|
||||
CourseOfTherapyCode string `json:"course_of_therapy_code,omitempty"`
|
||||
CourseOfTherapyDisplay string `json:"course_of_therapy_display,omitempty"`
|
||||
Status string `json:"status" binding:"required,oneof=active on-hold cancelled completed entered-in-error stopped draft unknown"`
|
||||
Intent string `json:"intent" binding:"required,oneof=proposal plan order original-order reflex-order filler-order instance-order option"`
|
||||
AuthoredOn time.Time `json:"authored_on" binding:"required"`
|
||||
DosageText string `json:"dosage_text,omitempty"`
|
||||
AdditionalInstruction string `json:"additional_instruction,omitempty"`
|
||||
PatientInstr string `json:"patient_instruction"`
|
||||
TimingFrequency int `json:"timing_frequency,omitempty"`
|
||||
TimingPeriod int `json:"timing_period,omitempty"`
|
||||
TimingPeriodUnit string `json:"timing_period_unit,omitempty"` // d (days), h (hours), etc
|
||||
RouteCode string `json:"route_code,omitempty"` // e.g. O (Oral)
|
||||
RouteDisplay string `json:"route_display,omitempty"`
|
||||
DoseQuantityValue float64 `json:"dose_quantity_value,omitempty"`
|
||||
DoseQuantityUnit string `json:"dose_quantity_unit,omitempty"` // TAB, CAP, etc
|
||||
DispenseInterval int `json:"dispense_interval,omitempty"`
|
||||
DispenseValue float64 `json:"dispense_value,omitempty"`
|
||||
DispenseUnit string `json:"dispense_unit,omitempty"`
|
||||
SupplyDuration int `json:"supply_duration,omitempty"` // in days
|
||||
ValidityPeriodStart *time.Time `json:"validity_period_start,omitempty"`
|
||||
ValidityPeriodEnd *time.Time `json:"validity_period_end,omitempty"`
|
||||
}
|
||||
|
||||
type MedicationRequestPatchRequest []map[string]interface{}
|
||||
|
||||
@@ -1,60 +1,245 @@
|
||||
package medicationrequest
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
)
|
||||
|
||||
func MapRequestToFHIR(req MedicationRequestRequest) satusehat.FHIRPayload {
|
||||
payload := satusehat.NewFHIRPayload("MedicationRequest").
|
||||
Set("status", req.Status).
|
||||
Set("intent", req.Intent).
|
||||
Set("category", []map[string]interface{}{
|
||||
payload := satusehat.NewFHIRPayload("MedicationRequest")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
// Set Meta Profile
|
||||
payload.Set("meta", map[string]interface{}{
|
||||
"profile": []string{"https://fhir.kemkes.go.id/r4/StructureDefinition/MedicationRequest"},
|
||||
})
|
||||
|
||||
// Set Identifier (ID Resep)
|
||||
if orgID != "" && req.MedicationRequestID != "" {
|
||||
identifiers := []map[string]interface{}{
|
||||
{
|
||||
"coding": []map[string]interface{}{
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/medicationrequest-category",
|
||||
"code": "outpatient",
|
||||
"display": "Outpatient",
|
||||
},
|
||||
"system": "http://sys-ids.kemkes.go.id/prescription/" + orgID,
|
||||
"use": "official",
|
||||
"value": req.MedicationRequestID,
|
||||
},
|
||||
}
|
||||
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)
|
||||
}
|
||||
if req.Intent != "" {
|
||||
payload.Set("intent", req.Intent)
|
||||
}
|
||||
if req.Priority != "" {
|
||||
payload.Set("priority", req.Priority)
|
||||
}
|
||||
|
||||
// Penanganan Category dinamis dengan default 'outpatient'
|
||||
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/CodeSystem/medicationrequest-category",
|
||||
"code": categoryCode,
|
||||
"display": categoryDisplay,
|
||||
},
|
||||
},
|
||||
}).
|
||||
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("encounter", map[string]interface{}{
|
||||
"reference": "Encounter/" + req.EncounterID,
|
||||
}).
|
||||
Set("authoredOn", req.AuthoredOn.Format(time.RFC3339)).
|
||||
Set("requester", map[string]interface{}{
|
||||
"reference": "Practitioner/" + req.PractitionerID,
|
||||
"display": req.PractitionerName,
|
||||
}).
|
||||
Set("dosageInstruction", []map[string]interface{}{
|
||||
{
|
||||
"sequence": 1,
|
||||
"text": req.DosageText,
|
||||
"patientInstruction": req.PatientInstr,
|
||||
},
|
||||
}).
|
||||
Set("dispenseRequest", map[string]interface{}{
|
||||
"quantity": map[string]interface{}{
|
||||
"value": req.DispenseValue,
|
||||
"code": req.DispenseUnit,
|
||||
},
|
||||
"expectedSupplyDuration": map[string]interface{}{
|
||||
},
|
||||
})
|
||||
|
||||
if req.MedicationID != "" {
|
||||
medRef := map[string]interface{}{"reference": "Medication/" + req.MedicationID}
|
||||
if req.MedicationDisplay != "" {
|
||||
medRef["display"] = req.MedicationDisplay
|
||||
}
|
||||
payload.Set("medicationReference", medRef)
|
||||
}
|
||||
|
||||
if req.ReasonCode != "" {
|
||||
reasonCoding := map[string]interface{}{
|
||||
"system": "http://hl7.org/fhir/sid/icd-10",
|
||||
"code": req.ReasonCode,
|
||||
}
|
||||
if req.ReasonDisplay != "" {
|
||||
reasonCoding["display"] = req.ReasonDisplay
|
||||
}
|
||||
payload.Set("reasonCode", []map[string]interface{}{
|
||||
{"coding": []map[string]interface{}{reasonCoding}},
|
||||
})
|
||||
}
|
||||
|
||||
if req.CourseOfTherapyCode != "" {
|
||||
courseCoding := map[string]interface{}{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/medicationrequest-course-of-therapy",
|
||||
"code": req.CourseOfTherapyCode,
|
||||
}
|
||||
if req.CourseOfTherapyDisplay != "" {
|
||||
courseCoding["display"] = req.CourseOfTherapyDisplay
|
||||
}
|
||||
payload.Set("courseOfTherapyType", map[string]interface{}{
|
||||
"coding": []map[string]interface{}{courseCoding},
|
||||
})
|
||||
}
|
||||
|
||||
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("encounter", map[string]interface{}{"reference": "Encounter/" + req.EncounterID})
|
||||
}
|
||||
|
||||
if !req.AuthoredOn.IsZero() {
|
||||
payload.Set("authoredOn", req.AuthoredOn.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if req.PractitionerID != "" {
|
||||
reqRef := map[string]interface{}{"reference": "Practitioner/" + req.PractitionerID}
|
||||
if req.PractitionerName != "" {
|
||||
reqRef["display"] = req.PractitionerName
|
||||
}
|
||||
payload.Set("requester", reqRef)
|
||||
}
|
||||
|
||||
if req.DosageText != "" || req.PatientInstr != "" || req.DoseQuantityValue != 0 || req.TimingFrequency != 0 {
|
||||
dose := map[string]interface{}{"sequence": 1}
|
||||
if req.DosageText != "" {
|
||||
dose["text"] = req.DosageText
|
||||
}
|
||||
if req.AdditionalInstruction != "" {
|
||||
dose["additionalInstruction"] = []map[string]interface{}{
|
||||
{"text": req.AdditionalInstruction},
|
||||
}
|
||||
}
|
||||
if req.PatientInstr != "" {
|
||||
dose["patientInstruction"] = req.PatientInstr
|
||||
}
|
||||
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.RouteCode != "" {
|
||||
routeCoding := map[string]interface{}{
|
||||
"system": "http://www.whocc.no/atc",
|
||||
"code": req.RouteCode,
|
||||
}
|
||||
if req.RouteDisplay != "" {
|
||||
routeCoding["display"] = req.RouteDisplay
|
||||
}
|
||||
dose["route"] = map[string]interface{}{
|
||||
"coding": []map[string]interface{}{routeCoding},
|
||||
}
|
||||
}
|
||||
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})
|
||||
}
|
||||
|
||||
if req.DispenseValue != 0 || req.SupplyDuration != 0 || req.DispenseInterval != 0 {
|
||||
dispenseReq := map[string]interface{}{}
|
||||
if req.DispenseInterval != 0 {
|
||||
dispenseReq["dispenseInterval"] = map[string]interface{}{
|
||||
"value": req.DispenseInterval,
|
||||
"unit": "days",
|
||||
"system": "http://unitsofmeasure.org",
|
||||
"code": "d",
|
||||
}
|
||||
}
|
||||
if req.ValidityPeriodStart != nil || req.ValidityPeriodEnd != nil {
|
||||
validity := map[string]interface{}{}
|
||||
if req.ValidityPeriodStart != nil {
|
||||
validity["start"] = req.ValidityPeriodStart.Format("2006-01-02")
|
||||
}
|
||||
if req.ValidityPeriodEnd != nil {
|
||||
validity["end"] = req.ValidityPeriodEnd.Format("2006-01-02")
|
||||
}
|
||||
dispenseReq["validityPeriod"] = validity
|
||||
}
|
||||
|
||||
dispenseReq["numberOfRepeatsAllowed"] = 0
|
||||
|
||||
if req.DispenseValue != 0 {
|
||||
qty := map[string]interface{}{
|
||||
"value": req.DispenseValue,
|
||||
"system": "http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm",
|
||||
}
|
||||
if req.DispenseUnit != "" {
|
||||
qty["unit"] = req.DispenseUnit
|
||||
qty["code"] = req.DispenseUnit
|
||||
}
|
||||
dispenseReq["quantity"] = qty
|
||||
}
|
||||
if req.SupplyDuration != 0 {
|
||||
dispenseReq["expectedSupplyDuration"] = map[string]interface{}{
|
||||
"value": req.SupplyDuration,
|
||||
"unit": "days",
|
||||
"system": "http://unitsofmeasure.org",
|
||||
"code": "d",
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
if orgID != "" {
|
||||
dispenseReq["performer"] = map[string]interface{}{
|
||||
"reference": "Organization/" + orgID,
|
||||
}
|
||||
}
|
||||
payload.Set("dispenseRequest", dispenseReq)
|
||||
}
|
||||
|
||||
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 MedicationRequestRe
|
||||
return s.repo.Update(ctx, id, payload)
|
||||
}
|
||||
func (s *service) Patch(ctx context.Context, id string, req MedicationRequestPatchRequest) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("MedicationRequest 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("MedicationRequest 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