Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BACK-3323] Ignore tags from orders if they don't conform to the schema #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions redox/processor_neworder.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,18 @@ func (o *newOrderProcessor) createTagsForPatient(ctx context.Context, order mode
if err != nil {
return nil, err
}
if resp.StatusCode() == http.StatusBadRequest {
o.logger.Warnw(
"ignoring tag because it doesn't conform to tag schema",
"tag", tagName,
"order", order.Meta,
"clinicId", match.Clinic.Id,
)
continue
}

if resp.StatusCode() != http.StatusOK && resp.StatusCode() != http.StatusCreated {
return nil, fmt.Errorf("unexpected status code %v when creating tagName %s", resp.StatusCode(), tagName)
return nil, fmt.Errorf("unexpected status code %v when creating tag %s", resp.StatusCode(), tagName)
}
}
}
Expand All @@ -359,8 +369,8 @@ func (o *newOrderProcessor) createTagsForPatient(ctx context.Context, order mode
for _, tagName := range tagNames {
patientTag, ok := existingTags[tagName]
if !ok {
// The tag should have been created. If it was deleted in the meantime returning an error will result in a retry
return nil, fmt.Errorf("patient tag doesn't exist")
// Ignore the tag if the creation wasn't successful
continue
}
patientTagIds = append(patientTagIds, *patientTag.Id)
}
Expand Down
52 changes: 52 additions & 0 deletions redox/processor_neworder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,58 @@ var _ = Describe("NewOrderProcessor", func() {

Expect(processor.ProcessOrder(context.Background(), envelope, order)).To(Succeed())
})

It("ignores tags if creation fails with bad request", func() {
t1dId := "1"
t1dName := "T1D"
adultName := "ADULT"

matchResponse.JSON200.Clinic.PatientTags = &[]clinics.PatientTag{
{&t1dId, t1dName},
}

clinicClient.EXPECT().
CreatePatientTagWithResponse(gomock.Any(), *matchResponse.JSON200.Clinic.Id, testRedox.MatchArg(func(body clinics.CreatePatientTagJSONRequestBody) bool {
return body.Name == adultName
})).
Return(&clinics.CreatePatientTagResponse{
Body: nil,
HTTPResponse: &http.Response{
StatusCode: http.StatusBadRequest,
},
}, nil)

updatedClinic := matchResponse.JSON200.Clinic
updatedClinic.PatientTags = &[]clinics.PatientTag{
{&t1dId, t1dName},
}

clinicClient.EXPECT().
GetClinicWithResponse(gomock.Any(), *matchResponse.JSON200.Clinic.Id).
Return(&clinics.GetClinicResponse{
Body: nil,
HTTPResponse: &http.Response{
StatusCode: http.StatusOK,
},
JSON200: &updatedClinic,
}, nil)

clinicClient.EXPECT().UpdatePatientWithResponse(gomock.Any(),
gomock.Eq(*matchResponse.JSON200.Clinic.Id),
gomock.Eq(*((*matchResponse.JSON200.Patients)[0]).Id),
testRedox.MatchArg(func(body clinics.UpdatePatientJSONRequestBody) bool {
return testRedox.PatientHasTags(body.Tags, []string{"1"})
}),
).Return(&clinics.UpdatePatientResponse{
Body: nil,
HTTPResponse: &http.Response{
StatusCode: http.StatusOK,
},
JSON200: &(*matchResponse.JSON200.Patients)[0],
}, nil)

Expect(processor.ProcessOrder(context.Background(), envelope, order)).To(Succeed())
})
})

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