Skip to content

[CEP] date_add function for case search #31325

Description

@snopoke

Abstract
Support basic date arithmetic in case search query language. Specifically adding / subtracting static values from dates to enable calculating values like '1 month ago'.

Motivation
The Case Search Query language is used in Case List Explorer and in Applications via Case Search expressions.

In Case List Explorer it would be useful to be able to generate date ranges dynamically so that you could have saved reports which report on data in sliding date ranges. e.g. monthly report of cases closed in that month.

In Applications it is possible to do some date calculations by using the application xpath engine however these need to be done at the integer level (days since epoch) and so it is impossible to reliably compute month based intervals.

Specification
This CEP proposes a new Case Search query function to support adding and subtracting intervals from dates.

date_add(today(), 'month', -1)
date_add('2020-01-01', 'day', 1)

The function accepts 3 arguments:

  • A date value (or an expression that evaluates to a date)
  • An interval name. One of 'day', 'week', 'month', 'year'
  • An integer value (positive or negative)

Impact on users
Allow users to create queries with dynamic dates.

Impact on hosting
NA

Backwards compatibility
Since this is a new function there are no comparability issues

Release Timeline
NA

Open questions and issues
None at this time

Metadata

Metadata

Assignees

No one assigned

    Labels

    CEPCommCare Enhancement ProposalCEP: done

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions