-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 6124 Eliminated unnecessary methods (toDatetime(), getDatetime(), and getDate() should all do the same thing) #4533
base: master
Are you sure you want to change the base?
Conversation
Eliminate unnecessary methods (toDatetime(), getDatetime(), and getDate() should all do the same thing)
Eliminate unnecessary methods (toDatetime(), getDatetime(), and getDate() should all do the same thing)
@subhamkumarr change the title to reflect what's being done in the ticket |
@tendomart added |
@tendomart should i also add test to the code? import org.junit.Test; public class ResultTest {
} |
Yes please, just to make sure nothing is breaking. |
@tendomart Sir everything is good from my end. Please merge it. |
The allergy field in the Allergy UI allows the user to enter a numeric value, considering allergies cannot have numeric name, we must validate the input string before allowing the user to procced further
@@ -21,6 21,8 @@ | |||
import org.openmrs.Obs; | |||
import org.openmrs.api.context.Context; | |||
import org.openmrs.logic.LogicException; | |||
import org.junit.Test; | |||
import static org.junit.Assert.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the wild card
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tendomart Wild card? i did not get you
yes @subhamkumarr line 25 import static org.junit.Assert.*; avoid imports like which end with .*, always import a specific class that you're using, avoid importing an entire package look at this https://wiki.openmrs.org/display/docs/Java Conventions in short , use onlly absolute paths |
@tendomart done the changes. Could you please review and merge. |
@@ -191,4 191,12 @@ public void validate_shouldRejectNumericReactionValue() { | |||
validator.validate(allergy, errors); | |||
assertTrue(errors.hasErrors()); | |||
} | |||
@Test | |||
public void validate_shouldRejectNumericAllergenValue() { | |||
Allergen allergen = new Allergen(AllergenType.DRUG, null , "45" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the space after null and "45"
@@ -64,6 64,11 @@ public void validate(Object target, Errors errors) { | |||
|
|||
Allergy allergy = (Allergy) target; | |||
|
|||
// Additional validation: Ensure allergen does not contain numeric values | |||
if (allergy.getAllergen() != null && StringUtils.isNumeric(allergy.getAllergen().getNonCodedAllergen())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid using null instead do something llike
if (StringUtils.isNotEmpty(allergy.getAllergen()) && StringUtils.isNumeric(allergy.getAllergen().getNonCodedAllergen()))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (StringUtils.isNumeric(Objects.requireNonNull(allergy.getAllergen(), "Allergen must not be null").getNonCodedAllergen()))
Is this is ok?
if (allergy.getAllergen() != null && StringUtils.isNumeric(allergy.getAllergen().getNonCodedAllergen())) { | ||
errors.rejectValue("allergen", "error.allergyapi.allergy.Allergen.cannotContainNumeric"); | ||
} | ||
|
||
if (allergy.getReactionNonCoded() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (Objects.nonNull(allergy.getReactionNonCoded()))
is this is OK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to do as described above or follow the the OpenMRS Java Conventions
public void validate_shouldRejectNumericAllergenValue() { | ||
Allergen allergen = new Allergen(AllergenType.DRUG, null , "45" ); | ||
allergy.setAllergen(allergen); | ||
Errors errors = new BindException(allergy,"allergy"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space between allergy and "allergy like
Errors errors = new BindException(allergy, "allergy");
@@ -543,9 543,13 @@ public Date toDatetime() { | |||
} | |||
catch (Exception e) {} | |||
} | |||
return valueDatetime; | |||
else { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need this extra space ?
@@ -94,6 94,7 @@ error.email.alreadyInUse=Email address is already assigned to another user accou | |||
error.activationkey.invalid =Invalid user activation Key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can choose to remove the spaces before and after the Equal signs(=)
@subhamkumarr have you responded to all the changes which I requested above ? |
@tendomart I made all the changes you asked me to do. Please review. |
@@ -91,7 91,7 @@ Context.DAO.only=This method can only be called from the ContextDAO class, not { | |||
error.rank.notPositiveInteger=Rank can only be a positive integer | |||
error.email.invalid =Invalid Email address | |||
error.email.alreadyInUse=Email address is already assigned to another user account | |||
error.activationkey.invalid =Invalid user activation Key | |||
error.activationkey.invalid=Invalid user activation Key | |||
error.usernameOrEmail.notNullOrBlank =Username Or email cannot be null or blank |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra space here
public void validate_shouldRejectNumericAllergenValue() { | ||
Allergen allergen = new Allergen(AllergenType.DRUG, null, "45"); | ||
allergy.setAllergen(allergen); | ||
Errors errors = new BindException (allergy,"allergy"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too...extra spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tendomart Done Please check
@tendomart is this good for merge? |
@@ -191,4 191,12 @@ public void validate_shouldRejectNumericReactionValue() { | |||
validator.validate(allergy, errors); | |||
assertTrue(errors.hasErrors()); | |||
} | |||
@Test | |||
public void validate_shouldRejectNumericAllergenValue() { | |||
Allergen allergen=new Allergen(AllergenType.DRUG, null, "45"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put spaces around the equal signs
public void validate_shouldRejectNumericAllergenValue() { | ||
Allergen allergen=new Allergen(AllergenType.DRUG, null, "45"); | ||
allergy.setAllergen(allergen); | ||
Errors errors=new BindException (allergy, "allergy"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be like this
Errors errors = new BindException(allergy, "allergy");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tendomart Done
@dkayiwa could you please review my PR. |
You have some failing tests.. do you need help in that ?
|
@tendomart yes i need help |
@tendomart what changes i need to make? |
tl;dr our action detected no activity on this PR and will close it in 30 days if the stale label is not removed. OpenMRS welcomes your contribution! It means a lot to us that you want to contribute to equity in healthcare! This PR has not seen any activity in the last 5 months. That is why we wanted to check whether you are still working on it or need assistance from our side. If you do not have time to continue the work or have moved on you don’t need to do anything. We will automatically close the PR in 30 days. We hope to see you back soon :) |
Description of what I changed
Eliminated unnecessary methods (toDatetime(), getDatetime(), and getDate() should all do the same thing)
Issue I worked on
https://openmrs.atlassian.net/browse/TRUNK-6124
Checklist: I completed these to help reviewers :)
My IDE is configured to follow the code style of this project.
I ran
mvn clean package
right before creating this pull request andadded all formatting changes to my commit.
All new and existing tests passed.
My pull request is based on the latest changes of the master branch.