-
Notifications
You must be signed in to change notification settings - Fork 1
/
insurance_plan.go
131 lines (102 loc) · 4.45 KB
/
insurance_plan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package elation
import (
"context"
"fmt"
"net/http"
"strconv"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
type InsurancePlanServicer interface {
Create(ctx context.Context, create *InsurancePlanCreate) (*InsurancePlan, *http.Response, error)
Find(ctx context.Context, opts *FindInsurancePlansOptions) (*Response[[]*InsurancePlan], *http.Response, error)
Get(ctx context.Context, id int64) (*InsurancePlan, *http.Response, error)
Update(ctx context.Context, id int64, update *InsurancePlanUpdate) (*InsurancePlan, *http.Response, error)
Delete(ctx context.Context, id int64) (*http.Response, error)
}
var _ InsurancePlanServicer = (*InsurancePlanService)(nil)
type InsurancePlanService struct {
client *HTTPClient
}
type InsurancePlanCreate struct {
Practice int64 `json:"practice"`
InsuranceCompany int64 `json:"insurance_company"`
Name string `json:"name"`
}
func (s *InsurancePlanService) Create(ctx context.Context, create *InsurancePlanCreate) (*InsurancePlan, *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "create insurance plan", trace.WithSpanKind(trace.SpanKindClient))
defer span.End()
out := &InsurancePlan{}
res, err := s.client.request(ctx, http.MethodPost, "/insurance_plans", nil, create, &out)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "error making request")
return nil, res, fmt.Errorf("making request: %w", err)
}
return out, res, nil
}
type InsurancePlan struct {
ID int64 `json:"id"`
Practice int64 `json:"practice"`
InsuranceCompany int64 `json:"insurance_company"`
Name string `json:"name"`
CreatedDate string `json:"created_date"`
DeletedDate string `json:"deleted_date"`
Patients []int64 `json:"patients"`
}
type FindInsurancePlansOptions struct {
*Pagination
Practice []int64 `url:"practice,omitempty"`
InsuranceCompany []int64 `url:"insurance_company,omitempty"`
}
func (s *InsurancePlanService) Find(ctx context.Context, opts *FindInsurancePlansOptions) (*Response[[]*InsurancePlan], *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "find insurance plans", trace.WithSpanKind(trace.SpanKindClient))
defer span.End()
out := &Response[[]*InsurancePlan]{}
res, err := s.client.request(ctx, http.MethodGet, "/insurance_plans", opts, nil, &out)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "error making request")
return nil, res, fmt.Errorf("making request: %w", err)
}
return out, res, nil
}
func (s *InsurancePlanService) Get(ctx context.Context, id int64) (*InsurancePlan, *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "get insurance plan", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.Int64("elation.insurance_plan_id", id)))
defer span.End()
out := &InsurancePlan{}
res, err := s.client.request(ctx, http.MethodGet, "/insurance_plans/"+strconv.FormatInt(id, 10), nil, nil, &out)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "error making request")
return nil, res, fmt.Errorf("making request: %w", err)
}
return out, res, nil
}
type InsurancePlanUpdate struct {
Name string `json:"name"`
}
func (s *InsurancePlanService) Update(ctx context.Context, id int64, update *InsurancePlanUpdate) (*InsurancePlan, *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "update insurance plan", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.Int64("elation.insurance_plan_id", id)))
defer span.End()
out := &InsurancePlan{}
res, err := s.client.request(ctx, http.MethodPatch, "/insurance_plans/"+strconv.FormatInt(id, 10), nil, update, &out)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "error making request")
return nil, res, fmt.Errorf("making request: %w", err)
}
return out, res, nil
}
func (s *InsurancePlanService) Delete(ctx context.Context, id int64) (*http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "delete insurance plan", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.Int64("elation.insurance_plan_id", id)))
defer span.End()
res, err := s.client.request(ctx, http.MethodDelete, "/insurance_plans/"+strconv.FormatInt(id, 10), nil, nil, nil)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "error making request")
return res, fmt.Errorf("making request: %w", err)
}
return res, nil
}