Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 103 additions & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5592,13 +5592,38 @@ paths:
get:
tags: [Cases]
summary: List all Cases
description: Each Case is linked to one Beneficiary and one Project.
description: |
Each Case is linked to one Beneficiary and one Project.

Filter the Cases by their answers to Case Form questions with `custom_field_definition_hash`, as the Manage Cases page does.
Call `GET /cases/filter_fields` first for the question IDs and the shape of value each one takes (its `filter_format`):

- `text`: text the answer contains, ignoring case, e.g. `custom_field_definition_hash[71]=theft`
- `number_range`: `[min]` and/or `[max]`
- `date_range`, `time_range`, `datetime_range`: `[from]` and/or `[to]`, both included (e.g. `2025-01-31`, `09:00`, `2025-01-31T14:00`)
- `choice_ids`: answer choice IDs, e.g. `custom_field_definition_hash[72][]=5`
- `yes_no`: `[]=yes` for ticked, `[]=no` for not ticked
- `has_files_no_files`: `[]=has_files` or `[]=no_files`
- `album_ids`: Album IDs the Case is linked to through the question

A Case must match every question given. A question the user can't filter by is ignored.
operationId: listCases
security: [{tokenAuth: []}]
parameters:
- $ref: '#/components/parameters/Page'
- $ref: '#/components/parameters/PerPage'
- $ref: '#/components/parameters/LastSyncDatetime'
- name: custom_field_definition_hash
in: query
style: deepObject
explode: true
required: false
description: Answers to Case Form questions to filter by, keyed by question (custom field definition) ID. See the description above.
schema:
type: object
additionalProperties: true
example:
"71": theft
responses:
"200":
description: Paginated list of Cases
Expand Down Expand Up @@ -5646,6 +5671,47 @@ paths:
"422":
$ref: '#/components/responses/UnprocessableEntity'

/cases/filter_fields:
get:
tags: [Cases]
summary: List the Case Form questions Cases can be filtered by
description: |
Lists the questions (custom field definitions) on the Case Forms of the organisations whose Cases the user can see, each once, alphabetically.
These are the custom filters on the Manage Cases page. Pass a question's `id` and a value in its `filter_format` to
`GET /cases` as `custom_field_definition_hash`. Select questions list their answer `choices`.
operationId: listCaseFilterFields
security: [{tokenAuth: []}]
parameters:
- $ref: '#/components/parameters/Page'
- $ref: '#/components/parameters/PerPage'
responses:
"200":
description: Paginated list of Case Form questions
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedCaseFilterFields'
example:
page: 1
page_size: 2
page_count: 1
total_count: 2
data:
- id: 71
name: Type of crime
field_type: ratio_set
filter_format: choice_ids
choices:
- { id: 5, name: Harassment }
- { id: 4, name: Theft }
- id: 72
name: Date of incident
field_type: date
filter_format: date_range
choices: []
"401":
$ref: '#/components/responses/Unauthorized'

/projects_beneficiaries_cases:
get:
tags: [Cases]
Expand Down Expand Up @@ -21871,6 +21937,42 @@ components:
items:
$ref: '#/components/schemas/Case'

CaseFilterField:
type: object
properties:
id:
type: integer
description: The question (custom field definition) ID, used as the key in `custom_field_definition_hash`
name:
type: string
field_type:
type: string
description: The question type, e.g. string, text, integer, float, date, time, datetime, ratio_set (select), boolean (checkbox), media (attachment), album, location, email_address
filter_format:
type: string
nullable: true
enum: [text, number_range, date_range, time_range, datetime_range, choice_ids, yes_no, has_files_no_files, album_ids, null]
choices:
type: array
description: A select question's answer choices, alphabetically
items:
type: object
properties:
id:
type: integer
name:
type: string

PaginatedCaseFilterFields:
allOf:
- $ref: '#/components/schemas/PaginationEnvelope'
- type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/CaseFilterField'

PaginatedProjectsBeneficiariesCases:
allOf:
- $ref: '#/components/schemas/PaginationEnvelope'
Expand Down
11 changes: 9 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1947,8 +1947,15 @@ function buildDocsPage() {
${endpointCard("GET", "/cases", "List all Cases", true, [
{ name: "page", type: "integer", required: false, desc: "Page number" },
{ name: "per_page", type: "integer", required: false, desc: "Records per page" },
{ name: "last_sync_datetime", type: "string", required: false, desc: "ISO 8601 incremental sync" }
], [{ code: "200", cls: "response-2xx", desc: "Paginated list of Cases" }])}
{ name: "last_sync_datetime", type: "string", required: false, desc: "ISO 8601 incremental sync" },
{ name: "custom_field_definition_hash", type: "object", required: false, desc: "Filter by answers to Case Form questions, keyed by question ID, e.g. <code>custom_field_definition_hash[71]=theft</code>. Each question's <code>filter_format</code> from <code>GET /cases/filter_fields</code> gives the value's shape." }
], [{ code: "200", cls: "response-2xx", desc: "Paginated list of Cases" }],
"Filter formats: <code>text</code> (contains), <code>number_range</code> (<code>[min]</code>/<code>[max]</code>), <code>date_range</code>, <code>time_range</code> and <code>datetime_range</code> (<code>[from]</code>/<code>[to]</code>, both included), <code>choice_ids</code> (<code>[]=</code> choice IDs), <code>yes_no</code> (<code>[]=yes</code> or <code>[]=no</code>), <code>has_files_no_files</code> (<code>[]=has_files</code> or <code>[]=no_files</code>) and <code>album_ids</code>. A Case must match every question given.")}
${endpointCard("GET", "/cases/filter_fields", "List the Case Form questions Cases can be filtered by", true, [
{ name: "page", type: "integer", required: false, desc: "Page number" },
{ name: "per_page", type: "integer", required: false, desc: "Records per page" }
], [{ code: "200", cls: "response-2xx", desc: "Paginated questions with <code>id</code>, <code>name</code>, <code>field_type</code>, <code>filter_format</code> and, for select questions, <code>choices</code>" }],
"The questions on the Case Forms of the organisations whose Cases you can see, each once, alphabetically. These are the custom filters on the Manage Cases page.")}
${endpointCard("POST", "/cases", "Create a Case", true, [], [
{ code: "200", cls: "response-2xx", desc: "Case created" },
{ code: "422", cls: "response-4xx", desc: "Validation failed" }
Expand Down
Loading