Filtering, sorting & pagination

Filtering

When making requests to some of Capable Health's API endpoints, you may add filtering criteria. Please refer to the API reference for more information regarding which filters are applicable to which endpoints.

Filters are applied as a query string.

Query parameter: filters[]
Multiple filters may be applied to a single endpoint. For this reason, when applying filters, you must use the query parameter filters[] no matter if you're applying a single filter or multiple filters.
By default, when multiple filters are passed, the resource will be filtered using the logical operator AND. Filtering using the logical operator OR is possible by passing an additional query parameter, filters_operator. filters_operator can receive either value: and or or.

Query value:
Filters are stringified and encoded json objects containing information regarding the field, the operator and the value by which to filter by.

FieldOperatorValue (data types)
Please refer to the API referenceeq (equals)boolean, datetime, integer, string
not_eq (does not equal)boolean, datetime, integer, string
matches (contains)string
does_not_match (does not contain)string
gt (greater than)datetime, integer
gteq (greater than or equal to)datetime, integer
lt (less than)datetime, integer
lteq (less than or equal to)datetime, integer
in (included in array)integer, string (note that the values must be passed in an array, i.e., [1,2,3])
not_in (not included in array)integer, string (note that the values must be passed in an array, i.e., [1,2,3])

Query value example:
JSON object:

{
"field": "id",
"operator": "eq",
"value": "123",
}

Stringified and encoded JSON object:

%7B%22field%22%3A%22id%22%2C%22operator%22%3A%22eq%22%2C%22value%22%3A%22123%22%7D

Query string example:
/patients?filters[]=%7B%22field%22%3A%22id%22%2C%22operator%22%3A%22eq%22%2C%22value%22%3A%22123%22%7D

The above query string will find a patient with an ID equal to "123".

Sorting

When making requests to some of Capable Health's API endpoints, you may request the data to be sorted. You can sort the data by created_at and updated_at using sort_by. A - will sort the data in desc order.

created_at
-created_at
updated_at
-updated_at

We currently support sorting on the following endpoints:

Modelendpoint
Care Plan Templates/care_plans/templates
Care Plans/care_plans
Goal Templates/goals/templates
Goals/goals
Leads/leads
Medication Orders/medication_orders
Observation Types/observation_types
Patients/patients
Patient Medications/patient_medications
Patient Related Persons/patient_related_persons
Practitioners/practitioners
Products/products
Questionnaires/questionnaires
Submissions/submissions
Target Templates/targets/templates
Targets/targets
Task Templates/tasks/templates
Tasks/tasks

Pagination

When an index endpoint is queried, such as /goals, pagination headers will be returned. The headers will look like the following:

Link <https://api.sandbox.capablehealth.com/goals?page=1>; rel="first", <https://api.sandbox.capablehealth.com/goals?page=2>; rel="next", <https://api.sandbox.capablehealth.com/goals?page=10>; rel="last"
Current-Page 1
Page-Items 20
Total-Pages 10
Total-Count 200

You may query specific pages by appending a ?page=[PAGE_NUMBER] query string parameter on requests to index endpoints. For example, /goals?page=2 will return the second page of goals results.

HeaderDescription
linkThe link header is compatible with RFC8288.
The first, previous, next, and last pages will be present in the link header.
current-pagecurrent-page indicates the page currently being queried.
page-itemspage-items indicates the number of items per page.
total-pagestotal-page indicates how many pages there are total.
total-counttotal-count provides the total amount of results in the query.