Skip to content

Commit

Permalink
Support prescription fill and history download fill APIs (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
gffking authored Jun 14, 2024
1 parent 987a776 commit 1fe6aeb
Show file tree
Hide file tree
Showing 7 changed files with 400 additions and 8 deletions.
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Client struct {
ClinicalDocumentSvc *ClinicalDocumentService
ContactSvc *ContactService
DiscontinuedMedicationSvc *DiscontinuedMedicationService
HistoryDownloadFillSvc *HistoryDownloadFillService
InsuranceCompanySvc *InsuranceCompanyService
InsuranceEligibilitySvc *InsuranceEligibilityService
InsurancePlanSvc *InsurancePlanService
Expand All @@ -49,6 +50,7 @@ type Client struct {
PatientSvc *PatientService
PhysicianSvc *PhysicianService
PracticeSvc *PracticeService
PrescriptionFillSvc *PrescriptionFillService
ProblemSvc *ProblemService
RecurringEventGroupService *RecurringEventGroupService
ServiceLocationSvc *ServiceLocationService
Expand All @@ -74,6 +76,7 @@ func NewClient(httpClient *http.Client, tokenURL, clientID, clientSecret, baseUR
client.ClinicalDocumentSvc = &ClinicalDocumentService{client}
client.ContactSvc = &ContactService{client}
client.DiscontinuedMedicationSvc = &DiscontinuedMedicationService{client}
client.HistoryDownloadFillSvc = &HistoryDownloadFillService{client}
client.InsuranceCompanySvc = &InsuranceCompanyService{client}
client.InsuranceEligibilitySvc = &InsuranceEligibilityService{client}
client.InsurancePlanSvc = &InsurancePlanService{client}
Expand All @@ -83,6 +86,7 @@ func NewClient(httpClient *http.Client, tokenURL, clientID, clientSecret, baseUR
client.PatientSvc = &PatientService{client}
client.PhysicianSvc = &PhysicianService{client}
client.PracticeSvc = &PracticeService{client}
client.PrescriptionFillSvc = &PrescriptionFillService{client}
client.ProblemSvc = &ProblemService{client}
client.RecurringEventGroupService = &RecurringEventGroupService{client}
client.ServiceLocationSvc = &ServiceLocationService{client}
Expand Down
17 changes: 9 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ module github.com/authorhealth/go-elation
go 1.21.5

require (
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/trace v1.21.0
golang.org/x/oauth2 v0.15.0
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
golang.org/x/oauth2 v0.20.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/golang/protobuf v1.5.3 // indirect
cloud.google.com/go v0.114.0
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-querystring v1.1.0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
)
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
cloud.google.com/go v0.114.0 h1:OIPFAdfrFDFO2ve2U7r/H5SwSbBzEdrBdE7xkgwc+kY=
cloud.google.com/go v0.114.0/go.mod h1:ZV9La5YYxctro1HTPug5lXH/GefROyW8PPD4T8n9J8E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand All @@ -19,13 +24,21 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc=
go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4=
go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc=
go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand All @@ -34,6 +47,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.15.0 h1:s8pnnxNVzjWyrvYdFUQq5llS1PX2zhPXmccZv99h7uQ=
golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM=
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -58,6 +73,7 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
100 changes: 100 additions & 0 deletions history_download_fill.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package elation

import (
"context"
"fmt"
"net/http"
"strconv"
"time"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)

type HistoryDownloadFillServicer interface {
Find(ctx context.Context, opts *FindHistoryDownloadFillsOptions) (*Response[[]*HistoryDownloadFill], *http.Response, error)
Get(ctx context.Context, id int64) (*HistoryDownloadFill, *http.Response, error)
}

var _ HistoryDownloadFillServicer = (*HistoryDownloadFillService)(nil)

type HistoryDownloadFillService struct {
client *Client
}

type HistoryDownloadFill struct {
ID int64 `json:"id"`
Patient int64 `json:"patient"`
Practice int64 `json:"practice"`
CreateDate time.Time `json:"create_date"`
MedicationOrder int64 `json:"medication_order"`
HistoryDownload int64 `json:"history_download"`
Medication int64 `json:"medication"`
MedicationDescription string `json:"medication_description"`
Quantity string `json:"quantity"`
QuantityUnit string `json:"quantity_unit"`
QuantityNote string `json:"quantity_note"`
DaysSupply string `json:"days_supply"`
Directions string `json:"directions"`
Note string `json:"note"`
Substitutions string `json:"substitutions"`
LastFillDate time.Time `json:"last_fill_date"`
WrittenDate *time.Time `json:"written_date"`
Refills []int64 `json:"refills"`
Diagnoses []int64 `json:"diagnoses"`
PriorAuth string `json:"prior_auth"`
PriorAuthQualifier string `json:"prior_auth_qualifier"`
PharmacyNCPDPID string `json:"pharmacy_ncpdpid"`
Prescriber int64 `json:"prescriber"`
PrescribingPhysician int64 `json:"prescribing_physician"`
RequestingPhysicianAction string `json:"requesting_physician_action"`
IsActive bool `json:"is_active"`
RequestingPhysician int64 `json:"requesting_physician"`
}

type FindHistoryDownloadFillsOptions struct {
*Pagination

Practice []int64 `url:"practice,omitempty"`
Patient []int64 `url:"patient,omitempty"`
HistoryDownload string `url:"history_download,omitempty"`
LastFillDateGTE time.Time `url:"last_fill_date__gte,omitempty"`
LastFillDateLTE time.Time `url:"last_fill_date__lte,omitempty"`
WrittenDateLTE time.Time `url:"written_date__lte,omitempty"`
WrittenDateGTE time.Time `url:"written_date__gte,omitempty"`
LastFillDateIsNull *bool `url:"last_fill_date__isnull,omitempty"`
WrittenDateIsNull *bool `url:"written_date__isnull,omitempty"`
}

func (s *HistoryDownloadFillService) Find(ctx context.Context, opts *FindHistoryDownloadFillsOptions) (*Response[[]*HistoryDownloadFill], *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "find history download fills", trace.WithSpanKind(trace.SpanKindClient))
defer span.End()

out := &Response[[]*HistoryDownloadFill]{}

res, err := s.client.request(ctx, http.MethodGet, "/medication_history_download_fills", 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 *HistoryDownloadFillService) Get(ctx context.Context, id int64) (*HistoryDownloadFill, *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "get history download fill", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.Int64("elation.medication_history_download_fill_id", id)))
defer span.End()

out := &HistoryDownloadFill{}

res, err := s.client.request(ctx, http.MethodGet, "/medication_history_download_fills/"+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
}
96 changes: 96 additions & 0 deletions history_download_fill_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package elation

import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"strconv"
"testing"

"github.com/stretchr/testify/assert"
)

func TestHistoryDownloadFillService_Find(t *testing.T) {
assert := assert.New(t)

opts := &FindHistoryDownloadFillsOptions{
Pagination: &Pagination{
Limit: 1,
Offset: 2,
},
}

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if tokenRequest(w, r) {
return
}

assert.Equal(http.MethodGet, r.Method)
assert.Equal("/medication_history_download_fills", r.URL.Path)

limit := r.URL.Query().Get("limit")
offset := r.URL.Query().Get("offset")

assert.Equal(opts.Pagination.Limit, strToInt(limit))
assert.Equal(opts.Pagination.Offset, strToInt(offset))

b, err := json.Marshal(Response[[]*HistoryDownloadFill]{
Results: []*HistoryDownloadFill{
{
ID: 1,
},
{
ID: 2,
},
},
})
assert.NoError(err)

w.Header().Set("Content-Type", "application/json")
//nolint
w.Write(b)
}))
defer srv.Close()

client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
svc := HistoryDownloadFillService{client}

found, res, err := svc.Find(context.Background(), opts)
assert.NotNil(found)
assert.NotNil(res)
assert.NoError(err)
}

func TestHistoryDownloadFillService_Get(t *testing.T) {
assert := assert.New(t)

var id int64 = 1

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if tokenRequest(w, r) {
return
}

assert.Equal(http.MethodGet, r.Method)
assert.Equal("/medication_history_download_fills/"+strconv.FormatInt(id, 10), r.URL.Path)

b, err := json.Marshal(&HistoryDownloadFill{
ID: id,
})
assert.NoError(err)

w.Header().Set("Content-Type", "application/json")
//nolint
w.Write(b)
}))
defer srv.Close()

client := NewClient(srv.Client(), srv.URL+"/token", "", "", srv.URL)
svc := HistoryDownloadFillService{client}

found, res, err := svc.Get(context.Background(), id)
assert.NotNil(found)
assert.NotNil(res)
assert.NoError(err)
}
Loading

0 comments on commit 1fe6aeb

Please sign in to comment.