Skip to content

Commit

Permalink
BACK-2813 Address code review feedback and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
toddkazakov committed Jan 23, 2024
1 parent 4326869 commit 678b954
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions api/patientInvites.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,19 @@ func (a *Api) AcceptPatientInvite(res http.ResponseWriter, req *http.Request, va
}

accept := models.AcceptPatientInvite{}
if err := json.NewDecoder(req.Body).Decode(&accept); err != nil {
a.logger.Errorw("error decoding accept patient invite body", zap.Error(err))
a.sendModelAsResWithStatus(
res,
&status.StatusError{Status: status.NewStatus(http.StatusInternalServerError, STATUS_ERR_CREATING_PATIENT)},
http.StatusInternalServerError,
)
return
if req.ContentLength > 0 {
if err := json.NewDecoder(req.Body).Decode(&accept); err != nil {
a.logger.Errorw("error decoding accept patient invite body", zap.Error(err))
a.sendModelAsResWithStatus(
res,
&status.StatusError{Status: status.NewStatus(http.StatusInternalServerError, STATUS_ERR_CREATING_PATIENT)},
http.StatusInternalServerError,
)
return
}
}
mrnRequired, err := a.isMrnRequired(ctx, conf.ClinicId)

mrnRequired, err := a.isMRNRequired(ctx, conf.ClinicId)
if err != nil {
a.logger.Errorw("error fetching mrn requirement settings", zap.Error(err))
a.sendModelAsResWithStatus(
Expand All @@ -118,7 +121,7 @@ func (a *Api) AcceptPatientInvite(res http.ResponseWriter, req *http.Request, va
)
return
}
if mrnRequired && strings.TrimSpace(accept.Mrn) == "" {
if mrnRequired && strings.TrimSpace(accept.MRN) == "" {
a.sendModelAsResWithStatus(
res,
&status.StatusError{Status: status.NewStatus(http.StatusBadRequest, STATUS_ERR_MRN_REQUIRED)},
Expand Down Expand Up @@ -249,8 +252,8 @@ func (a *Api) createClinicPatient(ctx context.Context, confirmation models.Confi
if accept.FullName != "" {
body.FullName = &accept.FullName
}
if accept.Mrn != "" {
body.Mrn = &accept.Mrn
if accept.MRN != "" {
body.Mrn = &accept.MRN
}
if count := len(accept.Tags); count > 0 {
tagIds := make(clinics.PatientTagIds, 0, count)
Expand Down Expand Up @@ -285,15 +288,15 @@ func (a *Api) createClinicPatient(ctx context.Context, confirmation models.Confi
return patient, nil
}

func (a *Api) isMrnRequired(ctx context.Context, clinicId string) (bool, error) {
func (a *Api) isMRNRequired(ctx context.Context, clinicId string) (bool, error) {
response, err := a.clinics.GetMRNSettingsWithResponse(ctx, clinicId)
if err != nil {
return false, err
}

// The clinic doesn't have custom MRN settings
if response.StatusCode() == http.StatusNotFound {
return true, nil
return false, nil
} else if response.StatusCode() != http.StatusOK {
return false, fmt.Errorf("unexpected response code when fetching clinic %s settings %v", clinicId, response.StatusCode())
}
Expand Down
2 changes: 1 addition & 1 deletion models/confirmation.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type (
}

AcceptPatientInvite struct {
Mrn string `json:"mrn"`
MRN string `json:"mrn"`
BirthDate string `json:"birthDate"`
FullName string `json:"fullName"`
Tags []string `json:"tags"`
Expand Down

0 comments on commit 678b954

Please sign in to comment.