Skip to content

Commit

Permalink
Support additional patient create fields (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
gffking authored Dec 13, 2023
1 parent 3213a5e commit 034ee93
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 40 deletions.
15 changes: 9 additions & 6 deletions patient.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ type PatientService struct {
}

type PatientCreate struct {
LastName string `json:"last_name"`
FirstName string `json:"first_name"`
Sex string `json:"sex"`
DOB string `json:"dob"`
PrimaryPhysician int64 `json:"primary_physician"`
CaregiverPractice int64 `json:"caregiver_practice"`
LastName string `json:"last_name"`
FirstName string `json:"first_name"`
Sex string `json:"sex"`
DOB string `json:"dob"`
PrimaryPhysician int64 `json:"primary_physician"`
CaregiverPractice int64 `json:"caregiver_practice"`
Address *PatientAddress `json:"address,omitempty"`
Phones []*PatientPhone `json:"phones,omitempty"`
Emails []*PatientEmail `json:"emails,omitempty"`
}

func (s *PatientService) Create(ctx context.Context, create *PatientCreate) (*Patient, *http.Response, error) {
Expand Down
112 changes: 78 additions & 34 deletions patient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,94 @@ import (
)

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

expected := &PatientCreate{
LastName: "last name",
FirstName: "first name",
Sex: "sex",
DOB: "dob",
PrimaryPhysician: 1,
CaregiverPractice: 2,
testCases := map[string]struct {
create *PatientCreate
}{
"minimally-specified request": {
create: &PatientCreate{
LastName: "last name",
FirstName: "first name",
Sex: "sex",
DOB: "dob",
PrimaryPhysician: 1,
CaregiverPractice: 2,
},
},
"fully-specified request": {
create: &PatientCreate{
LastName: "last name",
FirstName: "first name",
Sex: "sex",
DOB: "dob",
PrimaryPhysician: 1,
CaregiverPractice: 2,
Address: &PatientAddress{
AddressLine1: "123 Any St",
AddressLine2: "Unit 5B",
City: "Schenectady",
State: "NY",
Zip: "12345",
},
Phones: []*PatientPhone{
{
Phone: "555-234-5678",
PhoneType: "Mobile",
},
{
Phone: "555-987-6543",
PhoneType: "Home",
},
},
Emails: []*PatientEmail{
{
Email: "[email protected]",
},
{
Email: "[email protected]",
},
},
},
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)

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

assert.Equal(http.MethodPost, r.Method)
assert.Equal("/patients", r.URL.Path)
assert.Equal(http.MethodPost, r.Method)
assert.Equal("/patients", r.URL.Path)

body, err := io.ReadAll(r.Body)
assert.NoError(err)
body, err := io.ReadAll(r.Body)
assert.NoError(err)

actual := &PatientCreate{}
err = json.Unmarshal(body, actual)
assert.NoError(err)
create := &PatientCreate{}
err = json.Unmarshal(body, create)
assert.NoError(err)

assert.Equal(expected, actual)
assert.Equal(testCase.create, create)

b, err := json.Marshal(&Patient{})
assert.NoError(err)
b, err := json.Marshal(&Patient{})
assert.NoError(err)

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

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

created, res, err := svc.Create(context.Background(), expected)
assert.NotNil(created)
assert.NotNil(res)
assert.NoError(err)
created, res, err := svc.Create(context.Background(), testCase.create)
assert.NotNil(created)
assert.NotNil(res)
assert.NoError(err)
})
}
}

func TestPatientService_Find(t *testing.T) {
Expand Down

0 comments on commit 034ee93

Please sign in to comment.