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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/src/main/java/org/openmrs/validator/AllergyValidator.java
Expand Up @@ -82,6 +82,10 @@ public void validate(Object target, Errors errors) {
} else if (!allergen.isCoded() && StringUtils.isBlank(allergen.getNonCodedAllergen())) {
errors.rejectValue("allergen", "allergyapi.allergen.nonCodedAllergen.required");
}

if (StringUtils.isNumeric(allergen.getNonCodedAllergen())) {
errors.rejectValue("allergen", "allergyapi.allergy.Allergen.cannotContainNumeric");
}

if (allergy.getAllergyId() == null && allergy.getPatient() != null) {
Allergies existingAllergies = patientService.getAllergies(allergy.getPatient());
Expand Down
1 change: 1 addition & 0 deletions api/src/main/resources/messages.properties
Expand Up @@ -94,6 +94,7 @@ error.email.alreadyInUse=Email address is already assigned to another user accou
error.activationkey.invalid =Invalid user activation Key
error.usernameOrEmail.notNullOrBlank =Username Or email cannot be null or blank
error.allergyapi.allergy.ReactionNonCoded.cannotBeNumeric=Reaction Non-coded must not be only a number
error.allergyapi.allergen.nonCodedAllergen.cannotBeNumeric=Non-coded Allergen must not be only a number

general.at=at
general.with=with
Expand Down
Expand Up @@ -191,4 +191,13 @@ public void validate_shouldRejectNumericReactionValue() {
validator.validate(allergy, errors);
assertTrue(errors.hasErrors());
}
@Test
Copy link
Contributor

Choose a reason for hiding this comment

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

Insert a space between the method

Copy link
Member

Choose a reason for hiding this comment

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

@subhamkumarr Did you see this comment?

public void validate_shouldRejectNumericAllergenValue() {
Allergen allergen = new Allergen(AllergenType.DRUG, null , "45" );
allergy.setAllergen(allergen);
Errors errors = new BindException(allergy,"allergy");
validator.validate(allergy, errors);
assertTrue(errors.hasErrors());
Copy link
Member

Choose a reason for hiding this comment

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

This should actually validate the error message.

Copy link
Author

Choose a reason for hiding this comment

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

@ibacher Sir, please check I made the changes.

Copy link
Author

Choose a reason for hiding this comment

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

@ibacher could you please review my PR.

assertTrue(errors.getAllErrors().stream()
.anyMatch(error -> "allergyapi.allergy.Allergen.cannotContainNumeric".equals(error.getCode()))); }
Copy link
Member

Choose a reason for hiding this comment

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

Indent here should be with tabs.

Copy link
Member

Choose a reason for hiding this comment

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

Also, the curly brace belongs on a new line. Please ensure you're following the Java Conventions and see this to setup your IDE (basically, whatever mechanism will take an Eclipse formatting configuration).

}