update All feture and service
This commit is contained in:
No files matched your search
@@ -2,35 +2,51 @@ package specimen
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"service/internal/satusehat/common"
|
||||
)
|
||||
|
||||
type SpecimenRequest struct {
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
SpecimenID string `json:"specimen_id,omitempty"`
|
||||
Status string `json:"status" binding:"required,oneof=available,unavailable,unsatisfactory,entered-in-error"`
|
||||
Type *common.CodeableConceptDTO `json:"type" binding:"required"`
|
||||
Subject *common.ReferenceDTO `json:"subject" binding:"required"`
|
||||
Collection *CollectionDTO `json:"collection,omitempty"`
|
||||
ReceivedDateTime *time.Time `json:"received_date_time,omitempty"`
|
||||
Processing []ProcessingDTO `json:"processing,omitempty"`
|
||||
Conditions []string `json:"conditions,omitempty"`
|
||||
Request []common.ReferenceDTO `json:"request,omitempty"`
|
||||
}
|
||||
OrganizationID string `json:"organization_id,omitempty"`
|
||||
SpecimenID string `json:"specimen_id,omitempty"`
|
||||
|
||||
type CollectionDTO struct {
|
||||
CollectedDateTime *time.Time `json:"collected_date_time,omitempty"`
|
||||
Collector *common.ReferenceDTO `json:"collector,omitempty"`
|
||||
Quantity *common.QuantityDTO `json:"quantity,omitempty"`
|
||||
Method *common.CodeableConceptDTO `json:"method,omitempty"`
|
||||
BodySite *common.CodeableConceptDTO `json:"body_site,omitempty"`
|
||||
FastingStatus *common.CodeableConceptDTO `json:"fasting_status,omitempty"`
|
||||
}
|
||||
Status string `json:"status" binding:"required,oneof=available unavailable unsatisfactory entered-in-error"`
|
||||
|
||||
type ProcessingDTO struct {
|
||||
Procedure *common.CodeableConceptDTO `json:"procedure,omitempty"`
|
||||
TimeDateTime *time.Time `json:"time_datetime,omitempty"`
|
||||
TypeSystem string `json:"type_system,omitempty"`
|
||||
TypeCode string `json:"type_code" binding:"required"`
|
||||
TypeDisplay string `json:"type_display,omitempty"`
|
||||
|
||||
PatientID string `json:"patient_id" binding:"required"`
|
||||
PatientName string `json:"patient_name,omitempty"`
|
||||
|
||||
ReceivedDateTime *time.Time `json:"received_date_time,omitempty"`
|
||||
|
||||
CollectedDateTime *time.Time `json:"collected_date_time,omitempty"`
|
||||
CollectorID string `json:"collector_id,omitempty"`
|
||||
CollectorName string `json:"collector_name,omitempty"`
|
||||
|
||||
CollectionQuantityValue *float64 `json:"collection_quantity_value,omitempty"`
|
||||
CollectionQuantityUnit string `json:"collection_quantity_unit,omitempty"`
|
||||
CollectionQuantitySystem string `json:"collection_quantity_system,omitempty"`
|
||||
|
||||
CollectionMethodSystem string `json:"collection_method_system,omitempty"`
|
||||
CollectionMethodCode string `json:"collection_method_code,omitempty"`
|
||||
CollectionMethodDisplay string `json:"collection_method_display,omitempty"`
|
||||
|
||||
BodySiteSystem string `json:"body_site_system,omitempty"`
|
||||
BodySiteCode string `json:"body_site_code,omitempty"`
|
||||
BodySiteDisplay string `json:"body_site_display,omitempty"`
|
||||
|
||||
FastingStatusSystem string `json:"fasting_status_system,omitempty"`
|
||||
FastingStatusCode string `json:"fasting_status_code,omitempty"`
|
||||
FastingStatusDisplay string `json:"fasting_status_display,omitempty"`
|
||||
|
||||
ProcessingProcedureSystem string `json:"processing_procedure_system,omitempty"`
|
||||
ProcessingProcedureCode string `json:"processing_procedure_code,omitempty"`
|
||||
ProcessingProcedureDisplay string `json:"processing_procedure_display,omitempty"`
|
||||
ProcessingTimeDateTime *time.Time `json:"processing_time_datetime,omitempty"`
|
||||
|
||||
Conditions []string `json:"conditions,omitempty"`
|
||||
|
||||
RequestServiceRequestIDs []string `json:"request_service_request_ids,omitempty"`
|
||||
}
|
||||
|
||||
type SpecimenPatchRequest []map[string]interface{}
|
||||
@@ -1,7 +1,6 @@
|
||||
package specimen
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"service/internal/interfaces/satusehat"
|
||||
@@ -10,18 +9,13 @@ import (
|
||||
func MapRequestToFHIR(req SpecimenRequest) satusehat.FHIRPayload {
|
||||
payload := satusehat.NewFHIRPayload("Specimen")
|
||||
|
||||
orgID := os.Getenv("SATUSEHAT_ORG_ID")
|
||||
if orgID == "" {
|
||||
orgID = req.OrganizationID
|
||||
}
|
||||
|
||||
if orgID != "" && req.SpecimenID != "" {
|
||||
if req.OrganizationID != "" && req.SpecimenID != "" {
|
||||
payload.Set("identifier", []map[string]interface{}{
|
||||
{
|
||||
"system": "http://sys-ids.kemkes.go.id/specimen/" + orgID,
|
||||
"system": "http://sys-ids.kemkes.go.id/specimen/" + req.OrganizationID,
|
||||
"value": req.SpecimenID,
|
||||
"assigner": map[string]interface{}{
|
||||
"reference": "Organization/" + orgID,
|
||||
"reference": "Organization/" + req.OrganizationID,
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -31,136 +25,123 @@ func MapRequestToFHIR(req SpecimenRequest) satusehat.FHIRPayload {
|
||||
payload.Set("status", req.Status)
|
||||
}
|
||||
|
||||
if req.Type != nil {
|
||||
sys := req.Type.System
|
||||
if req.TypeCode != "" {
|
||||
sys := req.TypeSystem
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.Type.Code}
|
||||
if req.Type.Display != "" {
|
||||
coding["display"] = req.Type.Display
|
||||
coding := map[string]interface{}{"system": sys, "code": req.TypeCode}
|
||||
if req.TypeDisplay != "" {
|
||||
coding["display"] = req.TypeDisplay
|
||||
}
|
||||
payload.Set("type", map[string]interface{}{"coding": []map[string]interface{}{coding}})
|
||||
}
|
||||
|
||||
if req.Collection != nil {
|
||||
coll := map[string]interface{}{}
|
||||
if req.Collection.Collector != nil {
|
||||
collector := map[string]interface{}{"reference": req.Collection.Collector.Reference}
|
||||
if req.Collection.Collector.Display != "" {
|
||||
collector["display"] = req.Collection.Collector.Display
|
||||
}
|
||||
coll["collector"] = collector
|
||||
}
|
||||
|
||||
if req.Collection.CollectedDateTime != nil && !req.Collection.CollectedDateTime.IsZero() {
|
||||
coll["collectedDateTime"] = req.Collection.CollectedDateTime.Format(time.RFC3339)
|
||||
}
|
||||
|
||||
if req.Collection.Quantity != nil {
|
||||
sys := req.Collection.Quantity.System
|
||||
if sys == "" {
|
||||
sys = "http://unitsofmeasure.org"
|
||||
}
|
||||
coll["quantity"] = map[string]interface{}{
|
||||
"value": req.Collection.Quantity.Value,
|
||||
"unit": req.Collection.Quantity.Unit,
|
||||
"system": sys,
|
||||
"code": req.Collection.Quantity.Code,
|
||||
}
|
||||
}
|
||||
|
||||
if req.Collection.Method != nil {
|
||||
sys := req.Collection.Method.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.Collection.Method.Code}
|
||||
if req.Collection.Method.Display != "" {
|
||||
coding["display"] = req.Collection.Method.Display
|
||||
}
|
||||
coll["method"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
}
|
||||
|
||||
if req.Collection.BodySite != nil {
|
||||
sys := req.Collection.BodySite.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.Collection.BodySite.Code}
|
||||
if req.Collection.BodySite.Display != "" {
|
||||
coding["display"] = req.Collection.BodySite.Display
|
||||
}
|
||||
coll["bodySite"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
}
|
||||
|
||||
if req.Collection.FastingStatus != nil {
|
||||
sys := req.Collection.FastingStatus.System
|
||||
if sys == "" {
|
||||
sys = "http://terminology.hl7.org/CodeSystem/v2-0916"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.Collection.FastingStatus.Code}
|
||||
if req.Collection.FastingStatus.Display != "" {
|
||||
coding["display"] = req.Collection.FastingStatus.Display
|
||||
}
|
||||
coll["fastingStatusCodeableConcept"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
}
|
||||
|
||||
if len(coll) > 0 {
|
||||
payload.Set("collection", coll)
|
||||
}
|
||||
}
|
||||
|
||||
if len(req.Processing) > 0 {
|
||||
var processings []map[string]interface{}
|
||||
for _, proc := range req.Processing {
|
||||
p := map[string]interface{}{}
|
||||
if proc.Procedure != nil {
|
||||
sys := proc.Procedure.System
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
p["procedure"] = map[string]interface{}{
|
||||
"coding": []map[string]interface{}{
|
||||
{"system": sys, "code": proc.Procedure.Code, "display": proc.Procedure.Display},
|
||||
},
|
||||
}
|
||||
}
|
||||
if proc.TimeDateTime != nil && !proc.TimeDateTime.IsZero() {
|
||||
p["timeDateTime"] = proc.TimeDateTime.Format(time.RFC3339)
|
||||
}
|
||||
processings = append(processings, p)
|
||||
}
|
||||
payload.Set("processing", processings)
|
||||
}
|
||||
|
||||
if len(req.Conditions) > 0 {
|
||||
var conditions []map[string]interface{}
|
||||
for _, c := range req.Conditions {
|
||||
conditions = append(conditions, map[string]interface{}{"text": c})
|
||||
}
|
||||
payload.Set("condition", conditions)
|
||||
}
|
||||
|
||||
if req.Subject != nil {
|
||||
subject := map[string]interface{}{"reference": req.Subject.Reference}
|
||||
if req.Subject.Display != "" {
|
||||
subject["display"] = req.Subject.Display
|
||||
if req.PatientID != "" {
|
||||
subject := map[string]interface{}{"reference": "Patient/" + req.PatientID}
|
||||
if req.PatientName != "" {
|
||||
subject["display"] = req.PatientName
|
||||
}
|
||||
payload.Set("subject", subject)
|
||||
}
|
||||
|
||||
if len(req.Request) > 0 {
|
||||
var requests []map[string]interface{}
|
||||
for _, r := range req.Request {
|
||||
requests = append(requests, map[string]interface{}{"reference": r.Reference})
|
||||
}
|
||||
payload.Set("request", requests)
|
||||
}
|
||||
|
||||
if req.ReceivedDateTime != nil && !req.ReceivedDateTime.IsZero() {
|
||||
payload.Set("receivedTime", req.ReceivedDateTime.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
coll := map[string]interface{}{}
|
||||
if req.CollectorID != "" {
|
||||
collector := map[string]interface{}{"reference": "Practitioner/" + req.CollectorID}
|
||||
if req.CollectorName != "" {
|
||||
collector["display"] = req.CollectorName
|
||||
}
|
||||
coll["collector"] = collector
|
||||
}
|
||||
if req.CollectedDateTime != nil && !req.CollectedDateTime.IsZero() {
|
||||
coll["collectedDateTime"] = req.CollectedDateTime.Format(time.RFC3339)
|
||||
}
|
||||
if req.CollectionQuantityValue != nil {
|
||||
sys := req.CollectionQuantitySystem
|
||||
if sys == "" {
|
||||
sys = "http://unitsofmeasure.org"
|
||||
}
|
||||
q := map[string]interface{}{"value": *req.CollectionQuantityValue, "system": sys}
|
||||
if req.CollectionQuantityUnit != "" {
|
||||
q["unit"] = req.CollectionQuantityUnit
|
||||
q["code"] = req.CollectionQuantityUnit
|
||||
}
|
||||
coll["quantity"] = q
|
||||
}
|
||||
if req.CollectionMethodCode != "" {
|
||||
sys := req.CollectionMethodSystem
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.CollectionMethodCode}
|
||||
if req.CollectionMethodDisplay != "" {
|
||||
coding["display"] = req.CollectionMethodDisplay
|
||||
}
|
||||
coll["method"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
}
|
||||
if req.BodySiteCode != "" {
|
||||
sys := req.BodySiteSystem
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.BodySiteCode}
|
||||
if req.BodySiteDisplay != "" {
|
||||
coding["display"] = req.BodySiteDisplay
|
||||
}
|
||||
coll["bodySite"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
}
|
||||
if req.FastingStatusCode != "" {
|
||||
sys := req.FastingStatusSystem
|
||||
if sys == "" {
|
||||
sys = "http://terminology.hl7.org/CodeSystem/v2-0916"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.FastingStatusCode}
|
||||
if req.FastingStatusDisplay != "" {
|
||||
coding["display"] = req.FastingStatusDisplay
|
||||
}
|
||||
coll["fastingStatusCodeableConcept"] = map[string]interface{}{"coding": []map[string]interface{}{coding}}
|
||||
}
|
||||
if len(coll) > 0 {
|
||||
payload.Set("collection", coll)
|
||||
}
|
||||
|
||||
if req.ProcessingProcedureCode != "" {
|
||||
sys := req.ProcessingProcedureSystem
|
||||
if sys == "" {
|
||||
sys = "http://snomed.info/sct"
|
||||
}
|
||||
coding := map[string]interface{}{"system": sys, "code": req.ProcessingProcedureCode}
|
||||
if req.ProcessingProcedureDisplay != "" {
|
||||
coding["display"] = req.ProcessingProcedureDisplay
|
||||
}
|
||||
p := map[string]interface{}{
|
||||
"procedure": map[string]interface{}{"coding": []map[string]interface{}{coding}},
|
||||
}
|
||||
if req.ProcessingTimeDateTime != nil && !req.ProcessingTimeDateTime.IsZero() {
|
||||
p["timeDateTime"] = req.ProcessingTimeDateTime.Format(time.RFC3339)
|
||||
}
|
||||
payload.Set("processing", []map[string]interface{}{p})
|
||||
}
|
||||
|
||||
if len(req.Conditions) > 0 {
|
||||
conditions := make([]map[string]interface{}, 0, len(req.Conditions))
|
||||
for _, c := range req.Conditions {
|
||||
conditions = append(conditions, map[string]interface{}{"text": c})
|
||||
}
|
||||
payload.Set("condition", conditions)
|
||||
}
|
||||
|
||||
if len(req.RequestServiceRequestIDs) > 0 {
|
||||
requests := make([]map[string]interface{}, 0, len(req.RequestServiceRequestIDs))
|
||||
for _, id := range req.RequestServiceRequestIDs {
|
||||
requests = append(requests, map[string]interface{}{"reference": "ServiceRequest/" + id})
|
||||
}
|
||||
payload.Set("request", requests)
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
@@ -20,12 +20,8 @@ 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(hiddenCtx{ctx}, method, endpoint, req)
|
||||
resp, err := r.client.DoRequest(ctx, method, endpoint, req)
|
||||
if err != nil {
|
||||
return nil, errors.InternalError().Message("Failed to execute request to SatuSehat").Cause(err).Build()
|
||||
}
|
||||
|
||||
@@ -14,16 +14,27 @@ type Service interface {
|
||||
GetByID(ctx context.Context, id string) (*satusehat.FHIRResponse, error)
|
||||
Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error)
|
||||
}
|
||||
type service struct{ repo Repository }
|
||||
type service struct {
|
||||
repo Repository
|
||||
orgID string
|
||||
}
|
||||
|
||||
func NewService(repo Repository) Service { return &service{repo: repo} }
|
||||
func NewService(repo Repository, orgID string) Service {
|
||||
return &service{repo: repo, orgID: orgID}
|
||||
}
|
||||
func (s *service) Create(ctx context.Context, req SpecimenRequest) (*satusehat.FHIRResponse, error) {
|
||||
if req.OrganizationID == "" {
|
||||
req.OrganizationID = s.orgID
|
||||
}
|
||||
return s.repo.Create(ctx, MapRequestToFHIR(req))
|
||||
}
|
||||
func (s *service) Update(ctx context.Context, id string, req SpecimenRequest) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("Specimen ID is required").Build()
|
||||
}
|
||||
if req.OrganizationID == "" {
|
||||
req.OrganizationID = s.orgID
|
||||
}
|
||||
payload := MapRequestToFHIR(req)
|
||||
payload.Set("id", id)
|
||||
return s.repo.Update(ctx, id, payload)
|
||||
|
||||
Reference in New Issue
Block a user