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

TRUNK-6030 : The allergy field in the Allergy UI should validate the input string #4534

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
TRUNK-6030
moved `if` inside the `else` block
  • Loading branch information
subhamkumarr committed Jan 17, 2024
commit c6877eaf3f5026f8f89040686a0dd1f53b2f5a38
10 changes: 5 additions & 5 deletions api/src/main/java/org/openmrs/validator/AllergyValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ public void validate(Object target, Errors errors) {
ValidationUtils.rejectIfEmpty(errors, "patient", "allergyapi.patient.required");

Allergy allergy = (Allergy) target;

// Additional validation: Ensure allergen does not contain numeric values
if (allergy.getAllergen() != null && StringUtils.isNumeric(allergy.getAllergen().getNonCodedAllergen())) {
errors.rejectValue("allergen", "error.allergyapi.allergy.Allergen.cannotContainNumeric");
}

if (allergy.getReactionNonCoded() != null) {
if (NumberUtils.isParsable(allergy.getReactionNonCoded())) {
Expand All @@ -87,6 +82,11 @@ public void validate(Object target, Errors errors) {
} else if (!allergen.isCoded() && StringUtils.isBlank(allergen.getNonCodedAllergen())) {
errors.rejectValue("allergen", "allergyapi.allergen.nonCodedAllergen.required");
}

// Additional validation: Ensure allergen does not contain numeric values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the comment

if (allergy.getAllergen() != null && StringUtils.isNumeric(allergy.getAllergen().getNonCodedAllergen())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the condition allergy.getAllergen() != null && as it has already been checked

Copy link
Author

@subhamkumarr subhamkumarr Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ManojLL Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@subhamkumarr When committing, include a meaningful commit message that references the relevant JIRA ticket ID,
ex:- TRUNK-6030 : validate the input string

errors.rejectValue("allergen", "error.allergyapi.allergy.Allergen.cannotContainNumeric");
}

if (allergy.getAllergyId() == null && allergy.getPatient() != null) {
Allergies existingAllergies = patientService.getAllergies(allergy.getPatient());
Expand Down