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 5682 #3046

Merged
merged 5 commits into from
Nov 8, 2019
Merged

Trunk 5682 #3046

merged 5 commits into from
Nov 8, 2019

Conversation

cioan
Copy link
Member

@cioan cioan commented Nov 8, 2019

This is related to the RESTWS-757 PR. We just needed to add a few more search parameters to the OrderSearchCriteria class.

@coveralls
Copy link

coveralls commented Nov 8, 2019

Coverage Status

Coverage increased (+0.06%) to 59.933% when pulling e289780 on cioan:TRUNK-5682 into 0aacf19 on openmrs:master.

Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

Thanks @cioan , I made some comments on code, also, let's add some tests for all of these, thanks!

@@ -183,6 +183,35 @@ public Order getOrder(Integer orderId) throws DAOException {
cal.setTime(searchCriteria.getActivatedOnOrAfterDate());
crit.add(Restrictions.ge("dateActivated", OpenmrsUtil.firstSecondOfDay(cal.getTime())));
}
if (searchCriteria.getDateStoppedOnOrBeforeDate() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

If this criteria is not going to take the date stopped into account, it should be renamed something like "isStopped".

I'm also fine with removing this entirely if the two getCanceledAndExpired methods get you want you need...

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @mogoodrich ! I have changed to isStopped and I added test cases for each of the new parameters we added. Thanks for reviewing this.

if (searchCriteria.getExcludeCanceledAndExpired() == true) {
Calendar cal = Calendar.getInstance();
// exclude expired orders (include only orders with autoExpireDate = null or autoExpireDate in the future)
crit.add(Restrictions.or(Restrictions.isNull("autoExpireDate"), Restrictions.gt("autoExpireDate", OpenmrsUtil.getLastMomentOfDay(cal.getTime()))));
Copy link
Member

Choose a reason for hiding this comment

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

I would think that we don't need the getLastMomentOfDay in this case... it makes sense in the getAutoExpiredOnOrBefore method above, and the getDateStoppedOnOrBefore below, but here we want to compare the auto expired date against the current datettime.... ie I could see a use case where an order might expire after 10 hours... in that case, if the order is placed at 10am then you would not want to exclude it when querying at 3pm, but you would want to exclude it when querying at 11pm.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @mogoodrich , so you are saying to just use current time, Restrictions.gt("autoExpireDate", cal.getTime())?

Copy link
Member

Choose a reason for hiding this comment

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

Yep! (still "or-ed" with is null, of course)

// exclude expired orders (include only orders with autoExpireDate = null or autoExpireDate in the future)
crit.add(Restrictions.or(Restrictions.isNull("autoExpireDate"), Restrictions.gt("autoExpireDate", OpenmrsUtil.getLastMomentOfDay(cal.getTime()))));
// exclude Canceled Orders
crit.add(Restrictions.isNull("dateStopped"));
Copy link
Member

Choose a reason for hiding this comment

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

We should make this logic the same as the autoExpireDate. I would assume that dateStopped shouldn't be in the future, but unfortunately the OrderValidator doesn't seem to enforce this... in the case that someone set a date stopped in the future, we wouldn't want to exclude this order.

Copy link
Member Author

Choose a reason for hiding this comment

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

no problem, I will change this line to:
crit.add(Restrictions.le("dateStopped", cal.getTime()));

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, after reading the next comment, maybe this line should be?
crit.add(Restrictions.le("dateStopped", OpenmrsUtil.getLastMomentOfDay(cal.getTime())));

Copy link
Member Author

@cioan cioan Nov 8, 2019

Choose a reason for hiding this comment

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

third time's the charm:
`// exclude Canceled Orders

crit.add(Restrictions.or(
Restrictions.isNull("dateStopped"),
Restrictions.gt("dateStopped", cal.getTime())));`

Copy link
Member

Choose a reason for hiding this comment

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

yep, that looks right...

// set the date's time to the last millisecond of the date
Calendar cal = Calendar.getInstance();
cal.setTime(searchCriteria.getCanceledOrExpiredOnOrBeforeDate());
crit.add(Restrictions.or(Restrictions.isNotNull("dateStopped"), Restrictions.le("autoExpireDate", OpenmrsUtil.getLastMomentOfDay(cal.getTime()))));
Copy link
Member

Choose a reason for hiding this comment

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

Same thing in the here, let's check that date stopped is also less than the end of the current day, not just that it is null.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @mogoodrich , does this look OK now?
crit.add(Restrictions.or(
Restrictions.and(
Restrictions.isNotNull("dateStopped"),
Restrictions.le("dateStopped", OpenmrsUtil.getLastMomentOfDay(cal.getTime()))),
Restrictions.and(
Restrictions.isNotNull("autoExpireDate"),
Restrictions.le("autoExpireDate", OpenmrsUtil.getLastMomentOfDay(cal.getTime())))));

Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

Thanks @cioan , merging...

@mogoodrich mogoodrich merged commit 3e6cde8 into openmrs:master Nov 8, 2019
@cioan cioan deleted the TRUNK-5682 branch November 14, 2019 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants