Skip to content

Commit 839192c

Browse files
committed
Split Client into an interface and an implementation
1 parent a715a28 commit 839192c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+210
-93
lines changed

appointment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type AppointmentServicer interface {
3636
var _ AppointmentServicer = (*AppointmentService)(nil)
3737

3838
type AppointmentService struct {
39-
client *Client
39+
client *HttpClient
4040
}
4141

4242
type AppointmentCreate struct {

appointment_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestAppointmentService_Create(t *testing.T) {
5555
}))
5656
defer srv.Close()
5757

58-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
58+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
5959
svc := AppointmentService{client}
6060

6161
created, res, err := svc.Create(context.Background(), expected)
@@ -127,7 +127,7 @@ func TestAppointmentService_Find(t *testing.T) {
127127
}))
128128
defer srv.Close()
129129

130-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
130+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
131131
svc := AppointmentService{client}
132132

133133
found, res, err := svc.Find(context.Background(), opts)
@@ -160,7 +160,7 @@ func TestAppointmentService_Get(t *testing.T) {
160160
}))
161161
defer srv.Close()
162162

163-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
163+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
164164
svc := AppointmentService{client}
165165

166166
found, res, err := svc.Get(context.Background(), id)
@@ -210,7 +210,7 @@ func TestAppointmentService_Update(t *testing.T) {
210210
}))
211211
defer srv.Close()
212212

213-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
213+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
214214
svc := AppointmentService{client}
215215

216216
found, res, err := svc.Update(context.Background(), id, expected)
@@ -234,7 +234,7 @@ func TestAppointmentService_Delete(t *testing.T) {
234234
}))
235235
defer srv.Close()
236236

237-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
237+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
238238
svc := AppointmentService{client}
239239

240240
res, err := svc.Delete(context.Background(), id)

cli/cmd/messaging.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ var (
1616

1717
var findThreadMembersCmd = &cobra.Command{
1818
Use: "find-thread-members",
19-
Run: wrapRunFunc(func(ctx context.Context, client *elation.Client, args []string) error {
20-
response, _, err := client.ThreadMemberSvc.Find(ctx, &elation.FindThreadMembersOptions{
19+
Run: wrapRunFunc(func(ctx context.Context, client elation.Client, args []string) error {
20+
response, _, err := client.ThreadMembers().Find(ctx, &elation.FindThreadMembersOptions{
2121
Patient: findThreadMembersPatients,
2222
User: findThreadMembersUsers,
2323
})
@@ -34,9 +34,9 @@ var findThreadMembersCmd = &cobra.Command{
3434
var getMessageThreadCmd = &cobra.Command{
3535
Use: "get-message-thread [thread ID]",
3636
Args: cobra.ExactArgs(1),
37-
Run: wrapRunFunc(func(ctx context.Context, client *elation.Client, args []string) error {
37+
Run: wrapRunFunc(func(ctx context.Context, client elation.Client, args []string) error {
3838
threadID, _ := strconv.ParseInt(args[0], 10, 64)
39-
response, _, err := client.MessageThreadSvc.Get(ctx, threadID)
39+
response, _, err := client.MessageThreads().Get(ctx, threadID)
4040
if err != nil {
4141
return err
4242
}

cli/cmd/practice.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
6+
"github.com/authorhealth/go-elation"
7+
"github.com/davecgh/go-spew/spew"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var findPhysiciansCmd = &cobra.Command{
12+
Use: "find-physicians",
13+
Run: wrapRunFunc(func(ctx context.Context, client elation.Client, args []string) error {
14+
response, _, err := client.Physicians().Find(ctx, &elation.FindPhysiciansOptions{})
15+
if err != nil {
16+
return err
17+
}
18+
19+
spew.Dump(response)
20+
21+
return nil
22+
}),
23+
}
24+
25+
func init() {
26+
rootCmd.AddCommand(findPhysiciansCmd)
27+
}

cli/cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func Execute() {
2525
}
2626
}
2727

28-
type runFunc func(ctx context.Context, client *elation.Client, args []string) error
28+
type runFunc func(ctx context.Context, client elation.Client, args []string) error
2929

3030
func wrapRunFunc(runFunc runFunc) func(cmd *cobra.Command, args []string) {
3131
return func(cmd *cobra.Command, args []string) {
@@ -36,7 +36,7 @@ func wrapRunFunc(runFunc runFunc) func(cmd *cobra.Command, args []string) {
3636
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
3737
slog.SetDefault(logger)
3838

39-
client := elation.NewClient(
39+
client := elation.NewHttpClient(
4040
&http.Client{
4141
Timeout: 15 * time.Second,
4242
},

client.go

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,31 @@ const (
3131
WebhookEventActionDeleted string = "deleted"
3232
)
3333

34-
type Client struct {
34+
type Client interface {
35+
Appointments() AppointmentServicer
36+
ClinicalDocuments() ClinicalDocumentServicer
37+
Contacts() ContactServicer
38+
DiscontinuedMedications() DiscontinuedMedicationServicer
39+
HistoryDownloadFills() HistoryDownloadFillServicer
40+
InsuranceCompanies() InsuranceCompanyServicer
41+
InsuranceEligibility() InsuranceEligibilityServicer
42+
InsurancePlans() InsurancePlanServicer
43+
Letters() LetterServicer
44+
Medications() MedicationServicer
45+
MessageThreads() MessageThreadServicer
46+
NonVisitNotes() NonVisitNoteServicer
47+
Patients() PatientServicer
48+
Physicians() PhysicianServicer
49+
Practices() PracticeServicer
50+
PrescriptionFills() PrescriptionFillServicer
51+
Problems() ProblemServicer
52+
RecurringEventGroups() RecurringEventGroupServicer
53+
ServiceLocations() ServiceLocationServicer
54+
Subscriptions() SubscriptionServicer
55+
ThreadMembers() ThreadMemberServicer
56+
}
57+
58+
type HttpClient struct {
3559
httpClient *http.Client
3660
baseURL string
3761
tracer trace.Tracer
@@ -59,7 +83,9 @@ type Client struct {
5983
ThreadMemberSvc *ThreadMemberService
6084
}
6185

62-
func NewClient(httpClient *http.Client, tokenURL, clientID, clientSecret, baseURL string) *Client {
86+
var _ Client = (*HttpClient)(nil)
87+
88+
func NewHttpClient(httpClient *http.Client, tokenURL, clientID, clientSecret, baseURL string) *HttpClient {
6389
config := clientcredentials.Config{
6490
ClientID: clientID,
6591
ClientSecret: clientSecret,
@@ -68,7 +94,7 @@ func NewClient(httpClient *http.Client, tokenURL, clientID, clientSecret, baseUR
6894

6995
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, httpClient)
7096

71-
client := &Client{
97+
client := &HttpClient{
7298
httpClient: config.Client(ctx),
7399
baseURL: baseURL,
74100
tracer: otel.GetTracerProvider().Tracer("github.com/authorhealth/go-elation"),
@@ -99,6 +125,70 @@ func NewClient(httpClient *http.Client, tokenURL, clientID, clientSecret, baseUR
99125
return client
100126
}
101127

128+
func (c *HttpClient) Appointments() AppointmentServicer {
129+
return c.AppointmentSvc
130+
}
131+
func (c *HttpClient) ClinicalDocuments() ClinicalDocumentServicer {
132+
return c.ClinicalDocumentSvc
133+
}
134+
func (c *HttpClient) Contacts() ContactServicer {
135+
return c.ContactSvc
136+
}
137+
func (c *HttpClient) DiscontinuedMedications() DiscontinuedMedicationServicer {
138+
return c.DiscontinuedMedicationSvc
139+
}
140+
func (c *HttpClient) HistoryDownloadFills() HistoryDownloadFillServicer {
141+
return c.HistoryDownloadFillSvc
142+
}
143+
func (c *HttpClient) InsuranceCompanies() InsuranceCompanyServicer {
144+
return c.InsuranceCompanySvc
145+
}
146+
func (c *HttpClient) InsuranceEligibility() InsuranceEligibilityServicer {
147+
return c.InsuranceEligibilitySvc
148+
}
149+
func (c *HttpClient) InsurancePlans() InsurancePlanServicer {
150+
return c.InsurancePlanSvc
151+
}
152+
func (c *HttpClient) Letters() LetterServicer {
153+
return c.LetterSvc
154+
}
155+
func (c *HttpClient) Medications() MedicationServicer {
156+
return c.MedicationSvc
157+
}
158+
func (c *HttpClient) MessageThreads() MessageThreadServicer {
159+
return c.MessageThreadSvc
160+
}
161+
func (c *HttpClient) NonVisitNotes() NonVisitNoteServicer {
162+
return c.NonVisitNoteSvc
163+
}
164+
func (c *HttpClient) Patients() PatientServicer {
165+
return c.PatientSvc
166+
}
167+
func (c *HttpClient) Physicians() PhysicianServicer {
168+
return c.PhysicianSvc
169+
}
170+
func (c *HttpClient) Practices() PracticeServicer {
171+
return c.PracticeSvc
172+
}
173+
func (c *HttpClient) PrescriptionFills() PrescriptionFillServicer {
174+
return c.PrescriptionFillSvc
175+
}
176+
func (c *HttpClient) Problems() ProblemServicer {
177+
return c.ProblemSvc
178+
}
179+
func (c *HttpClient) RecurringEventGroups() RecurringEventGroupServicer {
180+
return c.RecurringEventGroupService
181+
}
182+
func (c *HttpClient) ServiceLocations() ServiceLocationServicer {
183+
return c.ServiceLocationSvc
184+
}
185+
func (c *HttpClient) Subscriptions() SubscriptionServicer {
186+
return c.SubscriptionSvc
187+
}
188+
func (c *HttpClient) ThreadMembers() ThreadMemberServicer {
189+
return c.ThreadMemberSvc
190+
}
191+
102192
type Response[ResultsT any] struct {
103193
Count int `json:"count"`
104194
Next string `json:"next"`
@@ -149,7 +239,7 @@ func (e Error) Error() string {
149239
return fmt.Sprintf("API error (status code %d)", e.StatusCode)
150240
}
151241

152-
func (c *Client) request(ctx context.Context, method string, path string, query any, body any, out any) (*http.Response, error) {
242+
func (c *HttpClient) request(ctx context.Context, method string, path string, query any, body any, out any) (*http.Response, error) {
153243
span := trace.SpanFromContext(ctx)
154244
span.SetAttributes(semconv.HTTPRequestMethodKey.String(method))
155245

clinical_document.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ClinicalDocumentServicer interface {
2020
var _ ClinicalDocumentServicer = (*ClinicalDocumentService)(nil)
2121

2222
type ClinicalDocumentService struct {
23-
client *Client
23+
client *HttpClient
2424
}
2525

2626
type ClinicalDocument struct {

clinical_document_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestClinicalDocumentService_Find(t *testing.T) {
5353
}))
5454
defer srv.Close()
5555

56-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
56+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
5757
svc := ClinicalDocumentService{client}
5858

5959
found, res, err := svc.Find(context.Background(), opts)
@@ -86,7 +86,7 @@ func TestClinicalDocumentService_Get(t *testing.T) {
8686
}))
8787
defer srv.Close()
8888

89-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
89+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
9090
svc := ClinicalDocumentService{client}
9191

9292
found, res, err := svc.Get(context.Background(), id)

contact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ContactServicer interface {
2020
var _ ContactServicer = (*ContactService)(nil)
2121

2222
type ContactService struct {
23-
client *Client
23+
client *HttpClient
2424
}
2525

2626
type Contact struct {

contact_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestContactService_List(t *testing.T) {
5353
}))
5454
defer srv.Close()
5555

56-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
56+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
5757
svc := ContactService{client}
5858

5959
found, res, err := svc.List(context.Background(), opts)
@@ -86,7 +86,7 @@ func TestContactService_Get(t *testing.T) {
8686
}))
8787
defer srv.Close()
8888

89-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
89+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
9090
svc := ContactService{client}
9191

9292
found, res, err := svc.Get(context.Background(), id)

discontinued_medication.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type DiscontinuedMedicationServicer interface {
2222
var _ DiscontinuedMedicationServicer = (*DiscontinuedMedicationService)(nil)
2323

2424
type DiscontinuedMedicationService struct {
25-
client *Client
25+
client *HttpClient
2626
}
2727

2828
type DiscontinuedMedicationCreate struct {

discontinued_medication_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestDiscontinuedMedicationService_Create(t *testing.T) {
6262
}))
6363
defer srv.Close()
6464

65-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
65+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
6666
svc := DiscontinuedMedicationService{client}
6767

6868
created, res, err := svc.Create(context.Background(), testCase.create)
@@ -136,7 +136,7 @@ func TestDiscontinuedMedicationService_Find(t *testing.T) {
136136
}))
137137
defer srv.Close()
138138

139-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
139+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
140140
svc := DiscontinuedMedicationService{client}
141141

142142
found, res, err := svc.Find(context.Background(), opts)
@@ -169,7 +169,7 @@ func TestDiscontinuedMedicationService_Get(t *testing.T) {
169169
}))
170170
defer srv.Close()
171171

172-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
172+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
173173
svc := DiscontinuedMedicationService{client}
174174

175175
found, res, err := svc.Get(context.Background(), id)
@@ -214,7 +214,7 @@ func TestDiscontinuedMedicationService_Update(t *testing.T) {
214214
}))
215215
defer srv.Close()
216216

217-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
217+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
218218
svc := DiscontinuedMedicationService{client}
219219

220220
updated, res, err := svc.Update(context.Background(), id, expected)

history_download_fill.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type HistoryDownloadFillServicer interface {
2020
var _ HistoryDownloadFillServicer = (*HistoryDownloadFillService)(nil)
2121

2222
type HistoryDownloadFillService struct {
23-
client *Client
23+
client *HttpClient
2424
}
2525

2626
type HistoryDownloadFill struct {

history_download_fill_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestHistoryDownloadFillService_Find(t *testing.T) {
5353
}))
5454
defer srv.Close()
5555

56-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
56+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
5757
svc := HistoryDownloadFillService{client}
5858

5959
found, res, err := svc.Find(context.Background(), opts)
@@ -86,7 +86,7 @@ func TestHistoryDownloadFillService_Get(t *testing.T) {
8686
}))
8787
defer srv.Close()
8888

89-
client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
89+
client := NewHttpClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
9090
svc := HistoryDownloadFillService{client}
9191

9292
found, res, err := svc.Get(context.Background(), id)

insurance_company.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type InsuranceCompanyServicer interface {
2222
var _ InsuranceCompanyServicer = (*InsuranceCompanyService)(nil)
2323

2424
type InsuranceCompanyService struct {
25-
client *Client
25+
client *HttpClient
2626
}
2727

2828
type InsuranceCompanyCreate struct {

0 commit comments

Comments
 (0)