Skip to content

Commit 86be462

Browse files
committed
Merge pull request #80 from tidepool-org/tk-ignore-tag-errors
[BACK-3323] Ignore tags from orders if they don't conform to the schema
2 parents 40dc84f + 8c349cd commit 86be462

File tree

8 files changed

+275
-208
lines changed

8 files changed

+275
-208
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ require (
1414
github.com/oapi-codegen/runtime v1.1.1
1515
github.com/onsi/ginkgo/v2 v2.19.0
1616
github.com/onsi/gomega v1.33.1
17-
github.com/tidepool-org/clinic/client v0.0.0-20241126104542-715a2a8b0a0f
18-
github.com/tidepool-org/clinic/redox_models v0.0.0-20250110131311-70b99601f0b3
17+
github.com/tidepool-org/clinic/client v0.0.0-20250204095937-863b79a60c42
18+
github.com/tidepool-org/clinic/redox_models v0.0.0-20250204095937-863b79a60c42
1919
github.com/tidepool-org/go-common v0.12.2-0.20240612192926-de6d5c5a742c
2020
github.com/tidepool-org/hydrophone/client v0.0.0-20240613035211-756659d74c0d
2121
go.mongodb.org/mongo-driver v1.16.0

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,16 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
107107
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
108108
github.com/tidepool-org/clinic/client v0.0.0-20241126104542-715a2a8b0a0f h1:RUVq1p3w0FUG5Y32frtkzBOQRc23S/WJDf+vn7ZECFA=
109109
github.com/tidepool-org/clinic/client v0.0.0-20241126104542-715a2a8b0a0f/go.mod h1:7BpAdFdGJNB3aw/xvCz5XnWjSWRoUtWIX4xcMc4Bsko=
110+
github.com/tidepool-org/clinic/client v0.0.0-20250204095937-863b79a60c42 h1:bjmGKTWHyyps/nyCRVabDYGmAc7G+PwctPhtLKJLp1s=
111+
github.com/tidepool-org/clinic/client v0.0.0-20250204095937-863b79a60c42/go.mod h1:7BpAdFdGJNB3aw/xvCz5XnWjSWRoUtWIX4xcMc4Bsko=
110112
github.com/tidepool-org/clinic/redox_models v0.0.0-20240802193352-3f912afe2109 h1:NVsWq93dgv1mQ/ELrJW1lv4pwMQaoSO0BLaK4qHZ8Xc=
111113
github.com/tidepool-org/clinic/redox_models v0.0.0-20240802193352-3f912afe2109/go.mod h1:bQ9DZxk015RhmGG1tR6jRScP9KxyHvS8tzPbVtr82DE=
112114
github.com/tidepool-org/clinic/redox_models v0.0.0-20241223102045-e1ade5167fb9 h1:2gB+zOEey9/cTEF1doveudDncRfq2FtZThU5jWMDBsc=
113115
github.com/tidepool-org/clinic/redox_models v0.0.0-20241223102045-e1ade5167fb9/go.mod h1:bQ9DZxk015RhmGG1tR6jRScP9KxyHvS8tzPbVtr82DE=
114116
github.com/tidepool-org/clinic/redox_models v0.0.0-20250110131311-70b99601f0b3 h1:Y8nTwbDBJiX6002WJx2V6iWLxFyT+LVSHEPHIedaXdE=
115117
github.com/tidepool-org/clinic/redox_models v0.0.0-20250110131311-70b99601f0b3/go.mod h1:bQ9DZxk015RhmGG1tR6jRScP9KxyHvS8tzPbVtr82DE=
118+
github.com/tidepool-org/clinic/redox_models v0.0.0-20250204095937-863b79a60c42 h1:IZHbissruy0CqHnuuW+/f9sWNXPJKDx6gntfB8o1mKI=
119+
github.com/tidepool-org/clinic/redox_models v0.0.0-20250204095937-863b79a60c42/go.mod h1:bQ9DZxk015RhmGG1tR6jRScP9KxyHvS8tzPbVtr82DE=
116120
github.com/tidepool-org/go-common v0.12.2-0.20240612192926-de6d5c5a742c h1:hJZyiHNGeqyLA/5p60/0H9CZtJi4fAuzOuyQF0TpF7E=
117121
github.com/tidepool-org/go-common v0.12.2-0.20240612192926-de6d5c5a742c/go.mod h1:mIzYteUyPf//fhee4e2KEZhmcm2iE4IQ/2dyQr5pRKA=
118122
github.com/tidepool-org/hydrophone/client v0.0.0-20240613035211-756659d74c0d h1:iGbmFspW6X9S67U4FO6chcoLalCOPBudWNCn0oHvP4Q=

redox/processor_neworder.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,18 @@ func (o *newOrderProcessor) createTagsForPatient(ctx context.Context, order mode
340340
if err != nil {
341341
return nil, err
342342
}
343+
if resp.StatusCode() == http.StatusBadRequest {
344+
o.logger.Warnw(
345+
"ignoring tag because it doesn't conform to tag schema",
346+
"tag", tagName,
347+
"order", order.Meta,
348+
"clinicId", match.Clinic.Id,
349+
)
350+
continue
351+
}
352+
343353
if resp.StatusCode() != http.StatusOK && resp.StatusCode() != http.StatusCreated {
344-
return nil, fmt.Errorf("unexpected status code %v when creating tagName %s", resp.StatusCode(), tagName)
354+
return nil, fmt.Errorf("unexpected status code %v when creating tag %s", resp.StatusCode(), tagName)
345355
}
346356
}
347357
}
@@ -359,8 +369,8 @@ func (o *newOrderProcessor) createTagsForPatient(ctx context.Context, order mode
359369
for _, tagName := range tagNames {
360370
patientTag, ok := existingTags[tagName]
361371
if !ok {
362-
// The tag should have been created. If it was deleted in the meantime returning an error will result in a retry
363-
return nil, fmt.Errorf("patient tag doesn't exist")
372+
// Ignore the tag if the creation wasn't successful
373+
continue
364374
}
365375
patientTagIds = append(patientTagIds, *patientTag.Id)
366376
}

redox/processor_neworder_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,58 @@ var _ = Describe("NewOrderProcessor", func() {
186186

187187
Expect(processor.ProcessOrder(context.Background(), envelope, order)).To(Succeed())
188188
})
189+
190+
It("ignores tags if creation fails with bad request", func() {
191+
t1dId := "1"
192+
t1dName := "T1D"
193+
adultName := "ADULT"
194+
195+
matchResponse.JSON200.Clinic.PatientTags = &[]clinics.PatientTag{
196+
{&t1dId, t1dName},
197+
}
198+
199+
clinicClient.EXPECT().
200+
CreatePatientTagWithResponse(gomock.Any(), *matchResponse.JSON200.Clinic.Id, testRedox.MatchArg(func(body clinics.CreatePatientTagJSONRequestBody) bool {
201+
return body.Name == adultName
202+
})).
203+
Return(&clinics.CreatePatientTagResponse{
204+
Body: nil,
205+
HTTPResponse: &http.Response{
206+
StatusCode: http.StatusBadRequest,
207+
},
208+
}, nil)
209+
210+
updatedClinic := matchResponse.JSON200.Clinic
211+
updatedClinic.PatientTags = &[]clinics.PatientTag{
212+
{&t1dId, t1dName},
213+
}
214+
215+
clinicClient.EXPECT().
216+
GetClinicWithResponse(gomock.Any(), *matchResponse.JSON200.Clinic.Id).
217+
Return(&clinics.GetClinicResponse{
218+
Body: nil,
219+
HTTPResponse: &http.Response{
220+
StatusCode: http.StatusOK,
221+
},
222+
JSON200: &updatedClinic,
223+
}, nil)
224+
225+
clinicClient.EXPECT().UpdatePatientWithResponse(gomock.Any(),
226+
gomock.Eq(*matchResponse.JSON200.Clinic.Id),
227+
gomock.Eq(*((*matchResponse.JSON200.Patients)[0]).Id),
228+
testRedox.MatchArg(func(body clinics.UpdatePatientJSONRequestBody) bool {
229+
return testRedox.PatientHasTags(body.Tags, []string{"1"})
230+
}),
231+
).Return(&clinics.UpdatePatientResponse{
232+
Body: nil,
233+
HTTPResponse: &http.Response{
234+
StatusCode: http.StatusOK,
235+
},
236+
JSON200: &(*matchResponse.JSON200.Patients)[0],
237+
}, nil)
238+
239+
Expect(processor.ProcessOrder(context.Background(), envelope, order)).To(Succeed())
240+
})
189241
})
190242

191243
When("clinic settings don't have ehr tag settings", func() {

0 commit comments

Comments
 (0)