-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatient.go
239 lines (207 loc) · 8.6 KB
/
patient.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package hint
import (
"errors"
"fmt"
"strconv"
"time"
)
const (
PhoneTypeMobile = "mobile"
PhoneTypeOffice = "office"
PhoneTypeHome = "home"
// membership states retreived from http://support.hint.com/knowledgebase/articles/804717-membership-statuses
MembershipStatusActive = "active"
MembershipStatusArchived = "archived"
MembershipStatusEnded = "ended"
MembershipStatusInactive = "inactive"
MembershipStatusPending = "pending"
MembershipStatusUnconfirmed = "unconfirmed"
MembershipStatusUnpaid = "unpaid"
)
type Language string
var (
LanguageEnglish Language = "en"
LanguageSpanish Language = "es"
)
var (
AvailableMembershipStatuses = []string{
MembershipStatusActive,
MembershipStatusArchived,
MembershipStatusEnded,
MembershipStatusInactive,
MembershipStatusPending,
MembershipStatusUnconfirmed,
MembershipStatusUnpaid,
}
)
// Phone represents a typed phone number
type Phone struct {
Type string `json:"type"`
Number string `json:"number"`
}
// PatientParams represents the mutable fields of a patient.
type PatientParams struct {
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
Email string `json:"email,omitempty"`
Gender string `json:"gender,omitempty"`
DOB string `json:"dob,omitempty"`
HealthInsuranceGroupID string `json:"health_insurance_group_id,omitempty"`
HealthInsuranceMemberID string `json:"health_insurance_member_id,omitempty"`
HealthInsurancePayerName string `json:"health_insurance_payer_name,omitempty"`
HealthInsurancePayerID string `json:"health_insurance_payer_id,omitempty"`
AddressLine1 string `json:"address_line_1,omitempty"`
AddressLine2 string `json:"address_line_2,omitempty"`
AddressCity string `json:"address_city,omitempty"`
AddressState string `json:"address_state,omitempty"`
AddressZip string `json:"address_zip,omitempty"`
AddressCountry string `json:"address_country,omitempty"`
ExternalSourceID string `json:"external_source_id,omitempty"`
ExternalSourceName string `json:"external_source_name,omitempty"`
ExternalLinkID string `json:"external_link_id,omitempty"`
IntegrationRecordID string `json:"integration_record_id,omitempty"`
IntegrationSyncStatus string `json:"integration_sync_status,omitempty"`
IntegrationErrorMessage string `json:"integration_error_message,omitempty"`
IntegrationWebLink string `json:"integration_web_link,omitempty"`
Phones []*Phone `json:"phones,omitempty"`
Practitioner *Practitioner `json:"practitioner,omitempty"`
PreferredLanguage Language `json:"preferred_language,omitempty"`
}
// Validate ensures that the required fields in when creating
// or updating a patient are present.
func (p *PatientParams) Validate() error {
if p.FirstName == "" {
return errors.New("first_name required")
} else if p.LastName == "" {
return errors.New("last_name required")
}
return nil
}
// Patient represents a patient registered as part of a practice on hint.
type Patient struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
DOB string `json:"dob,omitempty"`
Age int `json:"age,omitempty"`
Gender string `json:"gender,omitempty"`
MembershipStatus string `json:"membership_status,omitempty"`
JoinedPracticeDate string `json:"date,omitempty"`
ExternalSourceID string `json:"external_source_id,omitempty"`
ExternalSourceName string `json:"external_source_name,omitempty"`
ExternalLinkID string `json:"external_link_id,omitempty"`
Practitioner *Practitioner `json:"practitioner,omitempty"`
HealthInsuranceGroupID string `json:"health_insurance_group_id,omitempty"`
HealthInsuranceMemberID string `json:"health_insurance_member_id,omitempty"`
HealthInsurancePayerName string `json:"health_insurance_payer_name,omitempty"`
HealthInsurancePayerID string `json:"health_insurance_payer_id,omitempty"`
Phones []*Phone `json:"phones,omitempty"`
AddressLine1 string `json:"address_line_1,omitempty"`
AddressLine2 string `json:"address_line_2,omitempty"`
AddressZip string `json:"address_zip,omitempty"`
AddressCity string `json:"address_city,omitempty"`
AddressState string `json:"address_state,omitempty"`
AddressCountry string `json:"address_country,omitempty"`
ProviderWebLink string `json:"provider_web_link,omitempty"`
Memberships []*Membership `json:"memberships"`
IntegrationRecordID string `json:"integration_record_id"`
IntegrationSyncStatus string `json:"integration_sync_status"`
IntegrationErrorMessage string `json:"integration_error_message"`
IntegrationWebLink string `json:"integration_web_link"`
Location *Location `json:"location,omitempty"`
PreferredLanguage Language `json:"preferred_language,omitempty"`
}
func PatientURLForProvider(id string) string {
return ProviderURL() + "/patients/" + id
}
type PatientClient interface {
New(practiceKey string, params *PatientParams) (*Patient, error)
Get(practiceKey, id string) (*Patient, error)
Update(practiceKey, id string, params *PatientParams) (*Patient, error)
Delete(practiceKey, id string) error
List(practiceKey string, params *ListParams) *Iter
}
type patientClient struct {
B Backend
Key string
}
func NewPatientClient(backend Backend, key string) PatientClient {
return &patientClient{
B: backend,
Key: key,
}
}
func (c patientClient) New(practiceKey string, params *PatientParams) (*Patient, error) {
if practiceKey == "" {
return nil, errors.New("practice_key required")
}
patient := &Patient{}
if _, err := c.B.Call("POST", "/provider/patients", practiceKey, params, patient); err != nil {
return nil, err
}
return patient, nil
}
func (c patientClient) Get(practiceKey, id string) (*Patient, error) {
if practiceKey == "" {
return nil, errors.New("practice_key required")
}
patient := &Patient{}
if _, err := c.B.Call("GET", fmt.Sprintf("/provider/patients/%s", id), practiceKey, nil, patient); err != nil {
return nil, err
}
return patient, nil
}
func (c patientClient) Update(practiceKey, id string, params *PatientParams) (*Patient, error) {
if practiceKey == "" {
return nil, errors.New("practice_key required")
}
patient := &Patient{}
if _, err := c.B.Call("PATCH", fmt.Sprintf("/provider/patients/%s", id), practiceKey, params, patient); err != nil {
return nil, err
}
return patient, nil
}
func (c patientClient) Delete(practiceKey, id string) error {
if practiceKey == "" {
return errors.New("practice_key required")
}
if _, err := c.B.Call("DELETE", fmt.Sprintf("/provider/patients/%s", id), practiceKey, nil, nil); err != nil {
return err
}
return nil
}
func (c patientClient) List(practiceKey string, params *ListParams) *Iter {
return GetIter(params, func(lp *ListParams) ([]interface{}, ListMeta, error) {
var meta ListMeta
encodedParams, err := lp.Encode()
if err != nil {
return nil, meta, err
}
var patients []*Patient
resHeaders, err := c.B.Call("GET", fmt.Sprintf("provider/patients?%s", encodedParams), practiceKey, nil, &patients)
if err != nil {
return nil, meta, err
}
if xCountHeader := resHeaders.Get("x-count"); xCountHeader != "" {
meta.CurrentCount, err = strconv.ParseUint(xCountHeader, 10, 64)
if err != nil {
return nil, meta, err
}
}
if xTotalCountHeader := resHeaders.Get("x-total-count"); xTotalCountHeader != "" {
meta.TotalCount, err = strconv.ParseUint(xTotalCountHeader, 10, 64)
if err != nil {
return nil, meta, err
}
}
ret := make([]interface{}, len(patients))
for i, patient := range patients {
ret[i] = patient
}
return ret, meta, nil
})
}