-
Notifications
You must be signed in to change notification settings - Fork 1
/
prescription_fill.go
79 lines (63 loc) · 2.6 KB
/
prescription_fill.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
package elation
import (
"context"
"fmt"
"net/http"
"strconv"
"time"
"cloud.google.com/go/civil"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
type PrescriptionFillServicer interface {
Find(ctx context.Context, opts *FindPrescriptionFillsOptions) (*Response[[]*PrescriptionFill], *http.Response, error)
Get(ctx context.Context, id int64) (*PrescriptionFill, *http.Response, error)
}
var _ PrescriptionFillServicer = (*PrescriptionFillService)(nil)
type PrescriptionFillService struct {
client *HTTPClient
}
type PrescriptionFill struct {
ID int64 `json:"id"`
MedicationOrder int64 `json:"medication_order"`
PharmacyNCPDPID string `json:"pharmacy_ncpdpid"`
FillStatus string `json:"fill_status"`
FillDate *civil.Date `json:"fill_date"`
NoteFromPharmacy string `json:"note_from_pharmacy"`
Patient int64 `json:"patient"`
Practice int64 `json:"practice"`
}
type FindPrescriptionFillsOptions struct {
*Pagination
Practice []int64 `url:"practice,omitempty"`
Patient []int64 `url:"patient,omitempty"`
FillDateIsNull *bool `url:"fill_date__isnull,omitempty"`
FillDateGTE time.Time `url:"fill_date__gte,omitempty"`
FillDateLTE time.Time `url:"fill_date__lte,omitempty"`
FillStatus string `url:"fill_status,omitempty"`
}
func (s *PrescriptionFillService) Find(ctx context.Context, opts *FindPrescriptionFillsOptions) (*Response[[]*PrescriptionFill], *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "find prescription fills", trace.WithSpanKind(trace.SpanKindClient))
defer span.End()
out := &Response[[]*PrescriptionFill]{}
res, err := s.client.request(ctx, http.MethodGet, "/prescription_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 *PrescriptionFillService) Get(ctx context.Context, id int64) (*PrescriptionFill, *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "get prescription fill", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.Int64("elation.prescription_fill_id", id)))
defer span.End()
out := &PrescriptionFill{}
res, err := s.client.request(ctx, http.MethodGet, "/prescription_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
}