Do we usually include or exclude endDate in a date range (for cohort membership)

As Wyclif and I have been reviewing the recent work on expanding cohort membership to support start and end dates, we noticed that there’s an “isActive” method and we wanted to check on what our standard behavior is here.

When we have a domain object with a startDate and endDate, is endDate included in the range or not?

In the codebase I see:

  • PatientState.getActive(Date) which is exclusive of endDate.
  • Relationship has an endDate, but no logic around it
  • PersonAddress has an endDate, but some bad logic that we shouldn’t be copying
  • Visit has a stopDatetime (not quite the same) and in the emrapi module, the “isSuitableVisit” method is inclusive of stopDatetime
  • In the reporting module I recall we did something like “if an ‘onOrBeforeDatetime’ has 00:00:00 time component treat it as 23:59:59, i.e. include the day of the end datetime”

My bias is that for cohort membership we should include the end date. It’s more natural to say “the patient was in the cohort from Jan 1 to Jan 31 (inclusive)” as opposed to “…from Jan 1 to Feb 1 (exclusive)”.

Including the end date makes sense to me too!

Looking at Order.isActive() which delegates to both Order.isExpired() and Order.isDiscontinued(), seems like it’s inclusive of endDate and consistent with HibernateOrderDao.getActiveOrders().

I think I agree with Darius that may be it should be inclusive.

We discuss on today’s design forum and decided that the API should work with timestamps, leaving it up to clients of the API to decide how to manage boundaries when working with dates without times (i.e., @darius will ensure the Javadoc comments for the API point out that the given Date is treated as a timestamp, so, for example, a time like 11:59:59 should be added to the end date to get results inclusive of that end date.