diff --git a/openapi.yaml b/openapi.yaml index cdf7969..b4e0663 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -303,6 +303,8 @@ tags: description: Published money values for outcomes, and the project Metrics they are put against on a project's Financial Value calculator - name: Explore description: The Makerble® ImpactStore™'s Explore pages, with the same search, filters and counts as the app + - name: Reports + description: Makerble® ReportMaker™'s Report Templates (the questions a report answers, and in what shape) and each Report's answers - name: Library description: Search the organisation's library and the public library of reusable building blocks, read an item in full, and see where it is used - name: ImpactStore @@ -12937,7 +12939,7 @@ paths: contract), `corporate_partner`, `internal` - `theme`: `children_and_young_people`, `community`, `employment`, `governance`, `health_and_wellbeing`, `volunteering` - - `output` (Answer formats): `narrative`, `number`, `chart`. A Report Template matches + - `output` (Answer formats): `narrative`, `number`, `chart`, `table`. A Report Template matches when any of its questions asks for that format. - `facets` gives each filter's options with how many Report Templates each would return, given the other filters already chosen. @@ -13066,6 +13068,334 @@ paths: $ref: '#/components/responses/Unauthorized' "404": $ref: '#/components/responses/NotFound' + /report_templates: + get: + tags: [Reports] + summary: List an organisation's Report Templates + operationId: listReportTemplates + description: | + The Report Templates an organisation can use in ReportMaker: its own and those in its + library, with each question's Expected Outputs and their `output_settings`. Requires + someone who can see Report Templates in the organisation; another organisation is a 404. + security: [{tokenAuth: []}] + parameters: + - name: charity_id + in: query + required: true + schema: + type: integer + example: 42 + description: The organisation + - $ref: '#/components/parameters/Page' + - $ref: '#/components/parameters/PerPage' + - $ref: '#/components/parameters/LastSyncDatetime' + responses: + "200": + description: The organisation's Report Templates + content: + application/json: + schema: + $ref: '#/components/schemas/PaginatedReportTemplates' + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntity' + post: + tags: [Reports] + summary: Create a Report Template + operationId: createReportTemplate + description: | + Creates a Report Template, as **Create a Report Template** does. Each question's + `expected_output_types` are any of `narrative`, `number`, `chart` and `table`, and its + `output_settings` hold: + + - `word_limit`: a whole number of words for a Narrative the recipient limits, e.g. "max 250 words". + - `table`: for a Table, `columns` (each a `heading` and a `type` of `text` or `number`; at + least one, at most 20, with different headings), `row_mode` (`reporter_adds`, the default, + or `fixed`) and, for fixed rows, `fixed_row_labels`. With fixed rows, every Report has one row + per label and the first column holds the labels (its type is always `text`). + + Settings for an output the question doesn't expect are dropped. Questions are saved in the + order given. Errors name the question, e.g. `Question 1: Table needs at least one column`. + security: [{tokenAuth: []}] + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ReportTemplateInput' + example: + charity_id: 42 + name: Pilot evaluation + description: Our end-of-year evaluation for the funder + recipient_type: funder + questions: + - question_title: How did each pilot do? + guidance_notes: Give the figures for each pilot + expected_output_types: [narrative, table] + output_settings: + word_limit: 250 + table: + columns: + - heading: Pilot + - heading: People reached + type: number + row_mode: fixed + fixed_row_labels: [Pilot A, Pilot B] + responses: + "201": + description: The new Report Template + content: + application/json: + schema: + type: object + properties: + data: + $ref: '#/components/schemas/ReportTemplate' + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntity' + /report_templates/{id}: + get: + tags: [Reports] + summary: Get a Report Template + operationId: getReportTemplate + description: One Report Template with its questions in order. A template you can't see is a 404. + security: [{tokenAuth: []}] + parameters: + - name: id + in: path + required: true + schema: + type: integer + example: 7 + responses: + "200": + description: The Report Template + content: + application/json: + schema: + type: object + properties: + data: + $ref: '#/components/schemas/ReportTemplate' + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + patch: + tags: [Reports] + summary: Change a Report Template + operationId: updateReportTemplate + description: | + Changes a Report Template, as **Edit Report Template** does. Fields left out stay as they + are. In `questions`, give an existing question's `id` to change it (questions without one are + added), and `{id, _destroy: true}` to remove one. Requires the template's creator or an + Organisation Admin, and the template must not be approved for the ImpactStore; otherwise 403. + security: [{tokenAuth: []}] + parameters: + - name: id + in: path + required: true + schema: + type: integer + example: 7 + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ReportTemplateInput' + example: + questions: + - id: 31 + expected_output_types: [table] + output_settings: + table: + columns: + - heading: Indicator + - heading: Target + type: number + - heading: Actual + type: number + responses: + "200": + description: The changed Report Template + content: + application/json: + schema: + type: object + properties: + data: + $ref: '#/components/schemas/ReportTemplate' + "401": + $ref: '#/components/responses/Unauthorized' + "403": + $ref: '#/components/responses/Forbidden' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntity' + /reports/{report_id}/contents: + get: + tags: [Reports] + summary: List a Report's answers + operationId: listReportContents + description: | + A Report's answers (Report Contents), one per question of its Report Template, answered or + not, in the template's order. A Report you can't see is a 404. + security: [{tokenAuth: []}] + parameters: + - name: report_id + in: path + required: true + schema: + type: integer + example: 15 + - $ref: '#/components/parameters/Page' + - $ref: '#/components/parameters/PerPage' + responses: + "200": + description: The Report's answers + content: + application/json: + schema: + $ref: '#/components/schemas/PaginatedReportContents' + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + /reports/{report_id}/contents/{question_id}: + get: + tags: [Reports] + summary: Get a Report's answer to one question + operationId: getReportContent + security: [{tokenAuth: []}] + parameters: + - name: report_id + in: path + required: true + schema: + type: integer + example: 15 + - name: question_id + in: path + required: true + schema: + type: integer + example: 31 + description: A question of the Report's Report Template + responses: + "200": + description: The answer + content: + application/json: + schema: + type: object + properties: + data: + $ref: '#/components/schemas/ReportContent' + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + patch: + tags: [Reports] + summary: Write a Report's answer to one question + operationId: updateReportContent + description: | + Writes the answer as **Write the Content** does. `table_rows` replaces the whole table: one + array of cells per row, in the order of the template's columns. Cells beyond the columns and + empty rows are dropped, a cell in a Number column must be a number, and with fixed rows the + first cell of each row is the template's label whatever is sent. A Narrative over its word + limit is saved; `words_over_limit` says by how much. Requires a Report Editor, a Report + Reporter or an Organisation Admin; someone who can only read the Report gets a 403. + security: [{tokenAuth: []}] + parameters: + - name: report_id + in: path + required: true + schema: + type: integer + example: 15 + - name: question_id + in: path + required: true + schema: + type: integer + example: 31 + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + narrative_content: + type: string + description: HTML, as the rich text editor saves it + number_content: + type: number + table_rows: + type: array + items: + type: array + items: {} + example: + table_rows: + - [Referrals, 120, 134] + - [Sessions, 40, 38] + responses: + "200": + description: The saved answer + content: + application/json: + schema: + type: object + properties: + data: + $ref: '#/components/schemas/ReportContent' + example: + data: + report_id: 15 + question_id: 31 + question_title: How are we doing against our KPIs? + expected_output_types: [table] + output_settings: + table: + columns: + - {heading: Indicator, type: text} + - {heading: Target, type: number} + - {heading: Actual, type: number} + row_mode: reporter_adds + narrative_content: null + number_content: null + word_count: 0 + words_over_limit: null + table_columns: + - {heading: Indicator, type: text} + - {heading: Target, type: number} + - {heading: Actual, type: number} + table_rows: + - [Referrals, 120, 134] + - [Sessions, 40, 38] + table_changed_in_template: false + ai_status: not_requested + data_gaps: [] + updated_at: "2026-11-29T21:40:00Z" + "401": + $ref: '#/components/responses/Unauthorized' + "403": + $ref: '#/components/responses/Forbidden' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntity' /explore/forms: get: tags: [Explore] @@ -25885,7 +26215,7 @@ components: type: array items: type: string - enum: [narrative, number, chart] + enum: [narrative, number, chart, table] ExploreReportTemplate: type: object @@ -25912,7 +26242,7 @@ components: type: array items: type: string - enum: [narrative, number, chart] + enum: [narrative, number, chart, table] shared_by: type: string libraries_count: @@ -25925,6 +26255,213 @@ components: type: boolean description: Whether it is in the library of one of the caller's organisations + ReportOutputSettings: + type: object + description: The settings of a question's Expected Outputs + properties: + word_limit: + type: integer + minimum: 1 + maximum: 100000 + description: Narrative word limit + table: + type: object + properties: + columns: + type: array + items: + type: object + properties: + heading: + type: string + type: + type: string + enum: [text, number] + row_mode: + type: string + enum: [reporter_adds, fixed] + fixed_row_labels: + type: array + items: + type: string + ReportTemplateQuestion: + type: object + properties: + id: + type: integer + question_title: + type: string + guidance_notes: + type: string + nullable: true + nuance: + type: string + nullable: true + position: + type: integer + expected_output_types: + type: array + items: + type: string + enum: [narrative, number, chart, table] + output_settings: + $ref: '#/components/schemas/ReportOutputSettings' + ReportTemplate: + type: object + properties: + id: + type: integer + charity_id: + type: integer + name: + type: string + description: + type: string + nullable: true + recipient_type: + type: string + nullable: true + enum: [funder, trustees, local_authority, corporate_partner, internal, null] + theme: + type: string + nullable: true + updated_at: + type: string + format: date-time + questions: + type: array + items: + $ref: '#/components/schemas/ReportTemplateQuestion' + ReportTemplateInput: + type: object + properties: + charity_id: + type: integer + description: The organisation, when creating + name: + type: string + description: + type: string + recipient_type: + type: string + enum: [funder, trustees, local_authority, corporate_partner, internal] + theme: + type: string + enum: [children_and_young_people, community, employment, governance, health_and_wellbeing, volunteering] + questions: + type: array + items: + type: object + properties: + id: + type: integer + description: An existing question, to change it + question_title: + type: string + guidance_notes: + type: string + nuance: + type: string + position: + type: integer + description: Defaults to the question's place in the list + expected_output_types: + type: array + items: + type: string + enum: [narrative, number, chart, table] + output_settings: + $ref: '#/components/schemas/ReportOutputSettings' + _destroy: + type: boolean + PaginatedReportTemplates: + type: object + properties: + page: + type: integer + page_size: + type: integer + page_count: + type: integer + total_count: + type: integer + data: + type: array + items: + $ref: '#/components/schemas/ReportTemplate' + ReportContent: + type: object + description: A Report's answer to one question of its Report Template + properties: + report_id: + type: integer + question_id: + type: integer + question_title: + type: string + expected_output_types: + type: array + items: + type: string + output_settings: + $ref: '#/components/schemas/ReportOutputSettings' + narrative_content: + type: string + nullable: true + number_content: + type: number + nullable: true + word_count: + type: integer + words_over_limit: + type: integer + nullable: true + description: How many words the Narrative is over its limit; null within it + table_columns: + type: array + description: The columns the table was saved under + items: + type: object + properties: + heading: + type: string + type: + type: string + table_rows: + type: array + items: + type: array + items: {} + table_changed_in_template: + type: boolean + description: True when the template's columns changed after the table was saved + ai_status: + type: string + enum: [not_requested, queued, writing, written, failed] + data_gaps: + type: array + items: + type: string + updated_at: + type: string + format: date-time + nullable: true + PaginatedReportContents: + type: object + properties: + page: + type: integer + page_size: + type: integer + page_count: + type: integer + total_count: + type: integer + data: + type: array + items: + $ref: '#/components/schemas/ReportContent' + PaginatedExploreReportTemplates: type: object properties: diff --git a/server.js b/server.js index 0ff91a7..96f5fb8 100644 --- a/server.js +++ b/server.js @@ -953,6 +953,8 @@ function buildDocsPage() { GETOutcomes GETLibrary GETExplore Surveys + GETReport Templates + GETReport answers GETExplore Report Templates GETExplore Forms GETExplore Dropdowns @@ -3229,7 +3231,7 @@ function buildDocsPage() { { name: "query", type: "string", required: false, desc: "Words in the Report Template's name or description, or who it's for or its theme" }, { name: "recipient", type: "string", required: false, desc: "Who it's for: funder, trustees, local_authority (Commissioner or contract), corporate_partner, internal" }, { name: "theme", type: "string", required: false, desc: "children_and_young_people, community, employment, governance, health_and_wellbeing, volunteering" }, - { name: "output", type: "string", required: false, desc: "Answer formats any of its questions ask for: narrative, number, chart" }, + { name: "output", type: "string", required: false, desc: "Answer formats any of its questions ask for: narrative, number, chart, table" }, { name: "sort", type: "string", required: false, desc: "added (in the most organisations' libraries first, default), new or az" }, { name: "page", type: "integer", required: false, desc: "Page number" }, { name: "per_page", type: "integer", required: false, desc: "Report Templates per page (default 10, max 200)" }, @@ -3246,6 +3248,93 @@ function buildDocsPage() { + +
+
Reporting
+

Report Templates

+
+

A Report Template is the list of questions a report has to answer, for Makerble® ReportMaker™. Each question says what kind of answer it needs in expected_output_types: any of narrative, number, chart and table.

+

output_settings holds each output's settings: word_limit for a Narrative the recipient limits (e.g. "max 250 words"), and for a Table, table with columns (each a heading and a type of text or number), row_mode (reporter_adds or fixed) and, for fixed rows, fixed_row_labels. With fixed rows the first column holds the labels.

+
+
+ ${endpointCard("GET", "/report_templates", "List an organisation's Report Templates", true, [ + { name: "charity_id", type: "integer", required: true, desc: "The organisation" }, + { name: "page", type: "integer", required: false, desc: "Page number" }, + { name: "per_page", type: "integer", required: false, desc: "Report Templates per page (default 10, max 200)" }, + { name: "last_synced_datetime", type: "string", required: false, desc: "ISO 8601 — only Report Templates updated after this" } + ], [ + { code: "200", cls: "response-2xx", desc: "The organisation's own and library Report Templates, each with id, charity_id, name, description, recipient_type, theme, updated_at and questions (id, question_title, guidance_notes, nuance, position, expected_output_types, output_settings)" }, + { code: "404", cls: "response-4xx", desc: "An organisation you can't see Report Templates in" }, + { code: "422", cls: "response-4xx", desc: "No charity_id" } + ])} + ${endpointCard("GET", "/report_templates/{id}", "Get a Report Template", true, [ + { name: "id", in: "path", type: "integer", required: true, desc: "The Report Template" } + ], [ + { code: "200", cls: "response-2xx", desc: "The Report Template as above, in data" }, + { code: "404", cls: "response-4xx", desc: "Not found, or one you can't see" } + ])} + ${endpointCard("POST", "/report_templates", "Create a Report Template", true, [ + { name: "charity_id", in: "body", type: "integer", required: true, desc: "The organisation" }, + { name: "name", in: "body", type: "string", required: true, desc: "e.g. the funder and the report name" }, + { name: "description", in: "body", type: "string", required: false, desc: "Who the report is for and when it's used" }, + { name: "recipient_type", in: "body", type: "string", required: false, desc: "funder, trustees, local_authority, corporate_partner or internal" }, + { name: "theme", in: "body", type: "string", required: false, desc: "children_and_young_people, community, employment, governance, health_and_wellbeing or volunteering" }, + { name: "questions", in: "body", type: "array", required: false, desc: "In order, each with question_title, guidance_notes, nuance, expected_output_types and output_settings" } + ], [ + { code: "201", cls: "response-2xx", desc: "The new Report Template, in data" }, + { code: "404", cls: "response-4xx", desc: "An organisation you can't create Report Templates in" }, + { code: "422", cls: "response-4xx", desc: "errors naming the question, e.g. Question 1: Table needs at least one column" } + ])} + ${endpointCard("PATCH", "/report_templates/{id}", "Change a Report Template", true, [ + { name: "id", in: "path", type: "integer", required: true, desc: "The Report Template" }, + { name: "questions", in: "body", type: "array", required: false, desc: "Give an existing question's id to change it; questions without one are added; {id, _destroy: true} removes one" } + ], [ + { code: "200", cls: "response-2xx", desc: "The changed Report Template, in data" }, + { code: "403", cls: "response-4xx", desc: "Not its creator or an Organisation Admin, or it is approved for the ImpactStore" }, + { code: "404", cls: "response-4xx", desc: "Not found, or one you can't see" }, + { code: "422", cls: "response-4xx", desc: "errors" } + ], "Fields left out stay as they are.")} +
+
+ + +
+
Reporting
+

Report answers

+
+

A Report's answers (Report Contents), one per question of its Report Template, as Write the Content shows them. A Table answer is table_rows: one array of cells per row, in the order of the template's columns.

+
+
+ ${endpointCard("GET", "/reports/{report_id}/contents", "List a Report's answers", true, [ + { name: "report_id", in: "path", type: "integer", required: true, desc: "The Report" }, + { name: "page", type: "integer", required: false, desc: "Page number" }, + { name: "per_page", type: "integer", required: false, desc: "Answers per page (default 10, max 200)" } + ], [ + { code: "200", cls: "response-2xx", desc: "Every question's answer, answered or not, with question_id, question_title, expected_output_types, output_settings, narrative_content, number_content, word_count, words_over_limit, table_columns, table_rows, table_changed_in_template, ai_status, data_gaps and updated_at" }, + { code: "404", cls: "response-4xx", desc: "A Report you can't see" } + ])} + ${endpointCard("GET", "/reports/{report_id}/contents/{question_id}", "Get a Report's answer to one question", true, [ + { name: "report_id", in: "path", type: "integer", required: true, desc: "The Report" }, + { name: "question_id", in: "path", type: "integer", required: true, desc: "A question of the Report's Report Template" } + ], [ + { code: "200", cls: "response-2xx", desc: "The answer as above, in data" }, + { code: "404", cls: "response-4xx", desc: "A Report you can't see, or a question from another template" } + ])} + ${endpointCard("PATCH", "/reports/{report_id}/contents/{question_id}", "Write a Report's answer to one question", true, [ + { name: "report_id", in: "path", type: "integer", required: true, desc: "The Report" }, + { name: "question_id", in: "path", type: "integer", required: true, desc: "A question of the Report's Report Template" }, + { name: "narrative_content", in: "body", type: "string", required: false, desc: "HTML, as the rich text editor saves it" }, + { name: "number_content", in: "body", type: "number", required: false, desc: "The figure" }, + { name: "table_rows", in: "body", type: "array", required: false, desc: "Replaces the whole table. Cells beyond the columns and empty rows are dropped; a Number column's cells must be numbers; with fixed rows the first cell of each row is the template's label" } + ], [ + { code: "200", cls: "response-2xx", desc: "The saved answer, in data. A Narrative over its word limit is saved, with words_over_limit saying by how much" }, + { code: "403", cls: "response-4xx", desc: "Not a Report Editor, Report Reporter or Organisation Admin" }, + { code: "404", cls: "response-4xx", desc: "A Report you can't see, or a question from another template" }, + { code: "422", cls: "response-4xx", desc: "errors, e.g. Row 1: Target must be a number" } + ])} +
+
+
Forms and surveys