Filtering Base Resources by Date

Utilizing the lastUpdated Parameter with the SearchDate Class in the b.well SDK

The lastUpdated parameter, combined with the SearchDate class, offers a powerful tool for fetching base health data resources based on their modification dates. This feature allows for fine-grained control over the data retrieval process, ensuring you access the most recent and relevant information.

Defining Search Criteria with SearchDate

The SearchDate class encapsulates search criteria based on dates, utilizing operations like equals, not equals, greater than, and less than. This flexibility enables SDK users to precisely target the retrieval of health data updates.

Specific operations are utilized to refine search queries by date, each with unique characteristics and combinability rules:

  • equals: Finds records exactly matching a specified date. Cannot be combined with other operations.
  • notEquals: Excludes records matching a specified date. Cannot be combined with other operations.
  • greaterThan: Selects records updated after the specified date. Cannot be combined with greaterThanOrEqualTo, equals, notEquals, or approximately. Exception thrown if lessThan or lessThanOrEqualTo set a date that occurs before the greaterThan date.
  • greaterThanOrEqualTo: Similar to "Greater Than" but includes the exact date. Cannot be combined with greaterThan, equals, notEquals, or approximately. Exception thrown if lessThan or lessThanOrEqualTo set a date that occurs before the greaterThan date.
  • lessThan: Retrieves records updated before the specified date. Cannot be combined with lessThanOrEqualsTo, equals, notEquals, or approximately. Exception thrown if greaterThan or greaterThanOrEqualsTo set a date that occurs after the lessThan date.
  • lessThanOrEqualTo: Similar to "Less Than" but includes the exact date. Cannot be combined with lessThan, equals, notEquals, or approximately. Exception thrown if greaterThan or greaterThanOrEqualsTo set a date that occurs after the lessThanOrEqualsTo date.
  • approximately: Searches for records around a specified date and returns results within a 10% margin. Cannot be combined with other operations.

Building a SearchDate Instance

To use the lastUpdated parameter effectively, you construct a SearchDate instance with the desired search criteria using its builder pattern. Here’s how you can specify different date conditions:

val lastUpdateSearchDate = SearchDate.Builder()
    .greaterThanOrEqualTo(SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2024-01-12 22:00:00"))
    .build()

Applying SearchDate to Data Retrieval Requests

With the SearchDate object ready, you can include it in your data retrieval requests. For example, when fetching immunizations updated after a specific date, your request might look like this:

val request = ImmunizationRequest.Builder()
    .lastUpdated(lastUpdateSearchDate)
    .build()