diff --git a/apps/postgres/prisma/scripts/001_insert_missing_list_types.sql b/apps/postgres/prisma/scripts/001_insert_missing_list_types.sql index 3d999c354..4a945158b 100644 --- a/apps/postgres/prisma/scripts/001_insert_missing_list_types.sql +++ b/apps/postgres/prisma/scripts/001_insert_missing_list_types.sql @@ -12,6 +12,7 @@ VALUES ('CROWN_FIRM_LIST', 'Crown Firm List', 'Crown Firm List', 'Crown Firm List', 'crown-firm-list', 'Classified', 'CRIME_IDAM', false, NOW()), ('CIVIL_AND_FAMILY_DAILY_CAUSE_LIST', 'Civil and Family Daily Cause List', 'Rhestr Achos Dyddiol Sifil a Theulu', 'Civil and Family Daily Cause List', 'civil-and-family-daily-cause-list', 'Public', 'CFT_IDAM', false, NOW()), ('CARE_STANDARDS_TRIBUNAL_WEEKLY_HEARING_LIST', 'Care Standards Tribunal Weekly Hearing List', 'Rhestr Gwrandawiadau Wythnosol y Tribiwnlys Safonau Gofal', 'Care Standards Tribunal Weekly Hearing List', 'care-standards-tribunal-weekly-hearing-list', 'Public', 'CFT_IDAM', true, NOW()), + ('MENTAL_HEALTH_TRIBUNAL_HEARING_LIST', 'Mental Health Tribunal Daily Hearing List', 'Rhestr Wrandawiadau Dyddiol y Tribiwnlys Iechyd Meddwl', 'Mental Health Tribunal Daily Hearing List', '', 'Public', 'PI_AAD', false, NOW()), ('CIVIL_COURTS_RCJ_DAILY_CAUSE_LIST', 'Civil Courts at the RCJ Daily Cause List', 'Rhestr Achosion Dyddiol Llys Sifil yn y Llysoedd Barn Brenhinol', 'Civil Courts at the RCJ Daily Cause List', 'civil-courts-rcj-daily-cause-list', 'Public', 'CFT_IDAM', true, NOW()), ('COUNTY_COURT_LONDON_CIVIL_DAILY_CAUSE_LIST', 'County Court at Central London Civil Daily Cause List', 'Rhestr Achosion Dyddiol Sifil yn y Llys Sirol yng Nghanol Llundain', 'County Court at Central London Civil Daily Cause List', 'county-court-central-london-civil-daily-cause-list', 'Public', 'CFT_IDAM', true, NOW()), ('COURT_OF_APPEAL_CRIMINAL_DAILY_CAUSE_LIST', 'Court of Appeal (Criminal Division) Daily Cause List', 'Rhestr Achosion Dyddiol y Llys Apêl (Adran Troseddol)', 'Court of Appeal (Criminal Division) Daily Cause List', 'court-of-appeal-criminal-division-daily-cause-list', 'Public', 'CRIME_IDAM', true, NOW()), diff --git a/apps/postgres/prisma/scripts/003_upsert_sub_jurisdictions_and_list_type_links.sql b/apps/postgres/prisma/scripts/003_upsert_sub_jurisdictions_and_list_type_links.sql index 7c80b872a..4d8198abd 100644 --- a/apps/postgres/prisma/scripts/003_upsert_sub_jurisdictions_and_list_type_links.sql +++ b/apps/postgres/prisma/scripts/003_upsert_sub_jurisdictions_and_list_type_links.sql @@ -74,6 +74,8 @@ FROM (VALUES ('CIVIL_AND_FAMILY_DAILY_CAUSE_LIST', 2), -- CARE_STANDARDS_TRIBUNAL_WEEKLY_HEARING_LIST → Care Standards Tribunal (9) ('CARE_STANDARDS_TRIBUNAL_WEEKLY_HEARING_LIST', 9), + -- MENTAL_HEALTH_TRIBUNAL_HEARING_LIST → Mental Health Tribunal (20) + ('MENTAL_HEALTH_TRIBUNAL_HEARING_LIST', 20), -- CIVIL_COURTS_RCJ_DAILY_CAUSE_LIST → Civil Court (1) ('CIVIL_COURTS_RCJ_DAILY_CAUSE_LIST', 1), -- COUNTY_COURT_LONDON_CIVIL_DAILY_CAUSE_LIST → Civil Court (1) diff --git a/docs/tickets/792/plan.md b/docs/tickets/792/plan.md new file mode 100644 index 000000000..c9cfd67de --- /dev/null +++ b/docs/tickets/792/plan.md @@ -0,0 +1,237 @@ +# Plan: #792 Mental Health Tribunal Daily Hearing List (flat-file list type) + +## 1. Technical Approach + +This ticket registers `MENTAL_HEALTH_TRIBUNAL_HEARING_LIST` as a **flat-file, strategic +(`isNonStrategic: false`), manually-uploaded** list type. It is a near-exact mirror of the +PCOL Daily Cause List work done for #438 (commit `706b4894`, `feat(#438): register PCOL +Daily Cause List flat-file list type`). + +IMPORTANT BASELINE NOTE: the #438 PCOL commit `706b4894` is **not an ancestor of `master`** +(verified with `git merge-base --is-ancestor`). Its changes to `list-type-data.ts` and the +seed SQL are **not present** in the current tree. Therefore this plan follows the same +*pattern* as PCOL but writes against the **current master** files. The most recent list type +actually merged to master is `PHT_WEEKLY_HEARING_LIST` (commit `ed63e448`), which is the +live reference for how a manual-upload list is wired today. + +Because this is a flat-file list, there is (like PCOL/PHT-as-flat-file): +- **No JSON schema** (`libs/list-types//src/schemas/*.json`) — so the CLAUDE.md + "every schema needs a validator + guard test" rule does **not** apply. +- **No Excel converter** registration. +- **No bespoke renderer / PDF generator / list page** under `apps/web/src/pages/(list-types)/`. + Flat files are served directly via `/hearing-lists/{locationId}/{artefactId}` (see the + `publication.isFlatFile` branch in `summary-of-publications/index.njk` lines 34-38). +- **No new page controllers** — the manual upload form auto-discovers the list type from the + DB (see below). + +### How a list type flows into the product + +1. **Catalogue entry** — `libs/list-types/common/src/list-type-data.ts` holds the canonical + `listTypeData[]` array (the `ListTypeData` interface, lines 1-11). Every list type is an + object with `name`, `englishFriendlyName`, `welshFriendlyName`, `provenance`, + `isNonStrategic`, `defaultSensitivity`, optional `shortenedFriendlyName`, optional + `urlPath`, and `subJurisdictionIds`. + +2. **Seeding (non-prod)** — `libs/location/src/seed-list-types.ts` iterates `listTypeData` + and upserts each into the `list_types` table plus the `list_types_sub_jurisdictions` + junction (keyed on `listType.subJurisdictionIds`). This runs on STG/local but is skipped + when `ENVIRONMENT === "prod"` (lines 10-13) or `CI === "true"`. + +3. **Seeding (prod / idempotent SQL)** — `apps/postgres/prisma/scripts/`: + - `001_insert_missing_list_types.sql` — one `VALUES` row per list type inserted into + `list_types`. + - `003_upsert_sub_jurisdictions_and_list_type_links.sql` — Step 1 upserts the 30 + sub-jurisdictions (Mental Health Tribunal already exists as id 20, line 38; parent + jurisdiction Tribunal already exists as id 4, line 10); Step 2 links each list type + name → sub-jurisdiction id in the `mapping(list_type_name, sub_jurisdiction_id)` + `VALUES` block (lines 59-177), joined by `lt.name` so it is **id-independent**. + +4. **Manual upload form** — `apps/web/src/pages/(admin)/manual-upload/index.ts` builds its + list-type dropdown from `findStrategicListTypes()` (lines 11-20, 61-64), i.e. every list + type with `isNonStrategic = false`. The option label is + `shortenedFriendlyName || friendlyName || name`. So once the list type is seeded as + strategic, it appears in the dropdown automatically with **no controller change**. + +5. **Default sensitivity** — the same form builds a `listTypeSensitivityMap` from + `defaultSensitivity` (lines 64-72). Setting `defaultSensitivity: "Public"` makes the form + default the sensitivity to Public for this list. + +### The extra requirement (not in #438): summary-of-publications notice + +AC5 requires this message on the summary of publications page: + +> Mental health hearings are held in private and unless a request has been made by the +> patient for a public hearing a hearing list will not be published. + +Current state of `apps/web/src/pages/(public)/summary-of-publications/`: +- `index.ts` renders `cautionMessage` / `noListMessage` that come **from location metadata** + (`getLocationMetadataByLocationId`, lines 114-119), not per-list-type. +- `index.njk` renders `cautionMessage` (lines 25-27) and `noListMessage` (lines 52-53). +- There is **no** existing per-list-type notice mechanism on this page. + +The closest existing pattern is the SEND list's "held in private" copy +(`libs/list-types/send-daily-hearing-list/src/locales/en.ts`, +`importantInformationParagraphs[0]`) — but that renders on the SEND list page, not the +summary page, so it is a content precedent only, not a reusable mechanism. + +Recommended approach (see CLARIFICATIONS for the open question on the trigger): drive the +notice off the **location's sub-jurisdiction**. `getLocationById` returns +`location.subJurisdictions: number[]` (`libs/location/src/repository/model.ts` lines 1-8). +Mental Health Tribunal is sub-jurisdiction id 20. To honour the CLAUDE.md "no hardcoded +numeric id" rule, resolve the id by the stable name `"Mental Health Tribunal"` via +`getAllSubJurisdictions()` (exported from `@hmcts/location`, `libs/location/src/index.ts` +line 37) and test membership. When present, pass a locale-file `mentalHealthNotice` string +to the template and render it in a new conditional block. Content lives in the page's +co-located `en.ts` / `cy.ts` (never hardcoded in the controller/template). + +## 2. Implementation Details (files to create / modify) + +### Modify — catalogue entry (mirrors PCOL diff) +**`libs/list-types/common/src/list-type-data.ts`** +Add one object to `listTypeData[]`, immediately after the +`CARE_STANDARDS_TRIBUNAL_WEEKLY_HEARING_LIST` entry (grouping with the tribunal lists): +```ts +{ + name: "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST", + englishFriendlyName: "Mental Health Tribunal Daily Hearing List", + welshFriendlyName: "Rhestr Wrandawiadau Dyddiol y Tribiwnlys Iechyd Meddwl", + provenance: "CFT_IDAM", + isNonStrategic: false, + defaultSensitivity: "Public", + shortenedFriendlyName: "Mental Health Tribunal Daily Hearing List", + subJurisdictionIds: [20] +} +``` +Notes: +- No `urlPath` — flat file, served via `/hearing-lists/...`, matching PCOL which set `url = ''`. +- `provenance: "CFT_IDAM"` mirrors PCOL. (PHT used `MANUAL_UPLOAD`; see CLARIFICATIONS.) +- Ticket says shortened friendly name == full friendly name, so both are set explicitly. + +### Modify — prod seed insert +**`apps/postgres/prisma/scripts/001_insert_missing_list_types.sql`** +Add one row to the `VALUES` list (empty `url` for flat file, matching PCOL): +```sql +('MENTAL_HEALTH_TRIBUNAL_HEARING_LIST', 'Mental Health Tribunal Daily Hearing List', 'Rhestr Wrandawiadau Dyddiol y Tribiwnlys Iechyd Meddwl', 'Mental Health Tribunal Daily Hearing List', '', 'Public', 'CFT_IDAM', false, NOW()), +``` + +### Modify — prod seed sub-jurisdiction link +**`apps/postgres/prisma/scripts/003_upsert_sub_jurisdictions_and_list_type_links.sql`** +Add one mapping row in the Step 2 `VALUES` block (Mental Health Tribunal = id 20, already +upserted in Step 1 line 38 — no Step 0/Step 1 change needed): +```sql +-- MENTAL_HEALTH_TRIBUNAL_HEARING_LIST → Mental Health Tribunal (20) +('MENTAL_HEALTH_TRIBUNAL_HEARING_LIST', 20), +``` + +### Create — catalogue unit test (mirrors the PCOL test that never merged) +**`libs/list-types/common/src/list-type-data.test.ts`** +Master currently has **no** `list-type-data.test.ts`. Create one asserting the new entry's +fields, following the AAA pattern in `.claude/rules/testing.md`: +- entry exists with `name === "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST"` +- `isNonStrategic === false` +- `defaultSensitivity === "Public"` +- `provenance === "CFT_IDAM"` +- `subJurisdictionIds` deep-equals `[20]` +- `shortenedFriendlyName === "Mental Health Tribunal Daily Hearing List"` +- English + Welsh friendly names match the ticket +- every `name` in `listTypeData` is unique (guards against duplicate paste) + +### Modify — summary-of-publications notice (AC5) +**`apps/web/src/pages/(public)/summary-of-publications/index.ts`** +- Import `getAllSubJurisdictions` from `@hmcts/location`. +- After fetching `location`, resolve the Mental Health Tribunal sub-jurisdiction id by the + stable name `"Mental Health Tribunal"`, then set + `const showMentalHealthNotice = location.subJurisdictions.includes(mhtId)`. +- Pass `mentalHealthNotice: showMentalHealthNotice ? t.mentalHealthNotice : undefined` into + `res.render(...)`. + +**`apps/web/src/pages/(public)/summary-of-publications/en.ts`** +Add: +```ts +mentalHealthNotice: "Mental health hearings are held in private and unless a request has been made by the patient for a public hearing a hearing list will not be published." +``` + +**`apps/web/src/pages/(public)/summary-of-publications/cy.ts`** +Add (Welsh translation required — see CLARIFICATIONS): +```ts +mentalHealthNotice: "[WELSH TRANSLATION REQUIRED: 'Mental health hearings are held in private and unless a request has been made by the patient for a public hearing a hearing list will not be published.']" +``` + +**`apps/web/src/pages/(public)/summary-of-publications/index.njk`** +Add a conditional block (GOV.UK inset text is appropriate for this kind of standing notice), +placed after the `cautionMessage` block (after line 27): +```njk +{% if mentalHealthNotice %} + {% from "govuk/components/inset-text/macro.njk" import govukInsetText %} + {{ govukInsetText({ text: mentalHealthNotice }) }} +{% endif %} +``` + +### Modify — summary-of-publications tests +**`apps/web/src/pages/(public)/summary-of-publications/index.test.ts`** and +**`.../index.njk.test.ts`** +- Add a case: when the location's sub-jurisdictions include Mental Health Tribunal, the + notice text is passed to the template / rendered. +- Add a case: when they do not, `mentalHealthNotice` is `undefined` / not rendered. +- Mock `getAllSubJurisdictions` and `getLocationById` accordingly. + +## 3. Error Handling & Edge Cases + +- **Idempotency:** both SQL scripts already use `ON CONFLICT DO UPDATE` / `DO NOTHING` + (001 line 5 comment; 003 lines 49-52, 180). Adding one row each is safe to re-run. +- **Prod skip:** `seed-list-types.ts` skips prod; prod relies on the SQL scripts. Both paths + must be updated (done above) or STG and prod diverge. +- **Duplicate name:** the new unit test asserts uniqueness of `listTypeData[].name`. +- **`getLocationById` returning null:** already handled (redirect to `/400`, index.ts lines + 27-30). Sub-jurisdiction resolution happens only after that guard. +- **Sub-jurisdiction name not found:** if `getAllSubJurisdictions` returns no + "Mental Health Tribunal" row (misconfigured env), `mhtId` is `undefined`, + `includes(undefined)` is `false`, so the notice simply does not show — fail-safe, no crash. +- **No numeric-id coupling:** per CLAUDE.md, routing/guards use the stable + `listTypeName` / sub-jurisdiction name; the `subJurisdictionIds: [20]` value in + catalogue/SQL is a fixed explicitly-assigned seed id (not autoincrement), consistent with + every other entry in `list-type-data.ts`. +- **Welsh:** all user-facing copy is in `en.ts` / `cy.ts`; the Welsh friendly name comes + from the ticket; the Welsh notice is flagged as a placeholder pending translation. + +## 4. Acceptance Criteria Mapping + +| AC | Requirement | Satisfied by | +|----|-------------|--------------| +| AC1 | List created, linked to Tribunal jurisdiction + National region; shows as "Mental Health Tribunal Daily Hearing List" in manual upload form | Catalogue entry + 001/003 SQL (`subJurisdictionIds: [20]` = Mental Health Tribunal, parent jurisdiction Tribunal id 4). Manual upload dropdown auto-populates via `findStrategicListTypes()` using `shortenedFriendlyName`. (Region "National" is a location attribute, not a list-type field — see CLARIFICATIONS.) | +| AC2 | Strategic (`isNonStrategic = false`) | `isNonStrategic: false` in catalogue + `false` column in 001 SQL; asserted in unit test | +| AC3 | Default sensitivity Public | `defaultSensitivity: "Public"` in catalogue + `'Public'` in 001 SQL; drives `listTypeSensitivityMap` in manual upload form | +| AC4 | Flat file, no JSON schema, no style guide | No schema file, no validator, no converter, no renderer/PDF, no list page created. Flat files served via `/hearing-lists/...` | +| AC5 | Summary-of-publications notice (EN + CY) | New `mentalHealthNotice` in `en.ts`/`cy.ts`, controller trigger via location sub-jurisdiction, `govukInsetText` block in `index.njk`, plus tests | + +## 5. CLARIFICATIONS NEEDED + +1. **Provenance: `CFT_IDAM` vs `MANUAL_UPLOAD`.** PCOL (#438) used `CFT_IDAM`; the newer + PHT list (merged to master, `ed63e448`) used `provenance: "MANUAL_UPLOAD"` with + `defaultSensitivity: null`. The ticket says provenance/restricted-provenances "None" and + sensitivity defaults to Public. This plan follows PCOL (`CFT_IDAM` + `Public`) since #792 + is explicitly a PCOL mirror, but confirm whether it should instead match the newer + `MANUAL_UPLOAD` convention. This affects access-control filtering in + `filterPublicationsForSummary`. + +2. **AC5 trigger condition.** The ticket says the notice must appear "in the summary of + publications page" but not exactly when. This plan shows it when the **location** is + linked to the Mental Health Tribunal sub-jurisdiction. Alternatives: (a) always for any + location that has this list type configured, (b) only when there are no publications + (like `noListMessage`), (c) a location-metadata field maintained by admins. Confirm the + intended trigger — it changes the controller logic. + +3. **Region = National.** In this data model, region is an attribute of a **location** + (`region` table, `location_region` junction), not of a list type — `list-type-data.ts` + has no region field. So "Region: National" cannot be set on the list type itself. Confirm + this is understood and that no location-level change is required by this ticket (i.e. the + region association is handled by existing reference data, not by #792). + +4. **Welsh translation of the AC5 notice.** The Welsh friendly name is supplied by the + ticket, but the Welsh translation of the summary notice sentence is not. It is added as a + `[WELSH TRANSLATION REQUIRED: ...]` placeholder — confirm the approved Welsh text before + release. + +5. **List page for flat file.** Confirm no dedicated list-rendering page is expected (as with + other flat-file uploads). This plan creates none; flat files open via the existing + `/hearing-lists/{locationId}/{artefactId}` link in the summary template. diff --git a/docs/tickets/792/review.md b/docs/tickets/792/review.md new file mode 100644 index 000000000..7ac899bff --- /dev/null +++ b/docs/tickets/792/review.md @@ -0,0 +1,176 @@ +# Code Review: Issue #792 + +## Summary + +Registers `MENTAL_HEALTH_TRIBUNAL_HEARING_LIST` as a flat-file, strategic, manually-uploaded +list type (catalogue entry + prod-seed SQL + sub-jurisdiction link), and adds a standing +"held in private" notice to the summary-of-publications page, triggered when a location is +linked to the Mental Health Tribunal sub-jurisdiction. + +The implementation is small, focused, and closely follows the approved plan. It correctly +follows the CLAUDE.md "resolve by stable name, never numeric id" rule in the controller, +the notice is escaped safely, types are correct, and tests cover both shown/not-shown and +English/Welsh cases with AAA structure. There are no critical or blocking code defects. + +The two `[~]` items below are verification/pre-release gaps (runtime DB reseed + approved +Welsh translation), not code defects — the code is complete and unit-tested. Per the review +rubric, `[~]` ACs push the advisory verdict to NEEDS CHANGES. + +Counts: 0 Critical, 1 High Priority, 3 Suggestions. + +## 🚨 CRITICAL Issues + +None. + +## ⚠️ HIGH PRIORITY Issues + +1. **Unconditional extra DB round-trip on every summary page load** + `apps/web/src/pages/(public)/summary-of-publications/index.ts:124` + - **Problem**: `getAllSubJurisdictions()` runs on *every* request to this public, + high-traffic page, even though the resolved id is only needed for the (rare) Mental + Health Tribunal locations. It is a single query returning the full sub-jurisdiction + reference table (~30 rows), so it is **not** an N+1 and not a correctness problem — but + it is an avoidable extra round-trip added to a hot path. The controller already issues + four sequential awaits (`getLocationById`, `artefact.findMany`, `findAllListTypes`, + `getLocationMetadataByLocationId`); this adds a fifth. + - **Impact**: Small but real latency/DB-load cost on the busiest public page; scales with + traffic rather than with MHT usage. + - **Recommendation**: Sub-jurisdiction ids are static reference data seeded with fixed ids + across all environments. Either (a) memoise the name→id lookup at module scope (resolve + once, cache), or (b) fold the check into the existing `getLocationById` result if the + query can cheaply return the linked sub-jurisdiction names. This keeps the stable-name + resolution (CLAUDE.md compliant) while removing the per-request query. Non-blocking, but + worth addressing before this page grows more logic. + +## 💡 SUGGESTIONS + +1. **Magic string `"Mental Health Tribunal"` in the controller** + `apps/web/src/pages/(public)/summary-of-publications/index.ts:125` + - **Benefit**: The sub-jurisdiction name is a load-bearing lookup key; if the seeded name + ever diverges the notice silently stops showing (fail-safe, but silent). Extracting it + to a named `const MENTAL_HEALTH_TRIBUNAL_SUB_JURISDICTION = "Mental Health Tribunal";` + at the top of the module documents the coupling and matches the CLAUDE.md + stable-name-guard convention used elsewhere. + - **Approach**: Declare the constant at module top (per CLAUDE.md module-ordering rule) + and reference it in the `.find(...)`. + +2. **Test Arrange duplication in `list-type-data.test.ts`** + `libs/list-types/common/src/list-type-data.test.ts:9-88` + - **Benefit**: Every `it` repeats `listTypeData.find((lt) => lt.name === "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST")`. + A shared `const entry = ...` (or `beforeEach`) would reduce noise. Minor — the current + form is readable and each test is well isolated, so this is optional. + +3. **Welsh notice placeholder must be tracked as a pre-release TODO** + `apps/web/src/pages/(public)/summary-of-publications/cy.ts:12` + - **Benefit**: The `[WELSH TRANSLATION REQUIRED: ...]` placeholder is a deliberate, + approved interim per the resolved decisions — not a code defect. Ensure a release + checklist item exists so the approved Welsh string lands before this ships to prod; + otherwise Welsh users will see the English-with-brackets placeholder. + +## ✅ Positive Feedback + +- **CLAUDE.md stable-name rule followed correctly**: the controller resolves the + sub-jurisdiction id via `getAllSubJurisdictions()` by the stable `name` rather than + hardcoding a numeric id in logic (`index.ts:124-126`). The `subJurisdictionIds: [20]` in + the catalogue and SQL are fixed explicitly-seeded reference ids (consistent with every + other entry), not autoincrement `listTypeId`s — correct interpretation of the rule. +- **Type safety is sound**: `location.subJurisdictions` is `number[]` (`model.ts:6`), + `mentalHealthTribunalId` is `number | undefined`, and the `!== undefined` guard before + `.includes()` (`index.ts:126`) makes the comparison type-correct with no `any`. +- **Safe escaping / correct component**: `govukInsetText({ text: mentalHealthNotice })` + (`index.njk:31`) uses the auto-escaping `text` option (not `html`), so no injection risk. + Inset text is an appropriate GOV.UK component for a standing informational notice, placed + logically after the caution message inside the two-thirds column. +- **Fail-safe design**: if the sub-jurisdiction name is not found, `mhtId` is `undefined` + and the notice simply does not render — no crash. +- **Good test coverage of the new branch**: `index.test.ts:721-766` covers notice shown (EN), + notice shown (CY placeholder), and notice not shown, all AAA-structured with realistic + mocks for `getLocationById` and `getAllSubJurisdictions`. +- **Both seed paths updated**: non-prod catalogue (`list-type-data.ts`) and prod idempotent + SQL (`001` + `003`) are kept in sync, so STG and prod will not diverge. +- **Locale consistency test** (`index.njk.test.ts:74-76`) guarantees `en`/`cy` keys stay in + lockstep, catching a missing translation key. + +## Test Coverage Assessment + +- **Unit tests**: Present and good quality. + - `list-type-data.test.ts` — 9 tests asserting every field of the new entry plus catalogue + name-uniqueness (AAA, isolated). + - `summary-of-publications/index.test.ts` — new "Mental Health Tribunal notice" block with + 3 realistic cases (EN shown, CY shown, not-shown). + - `summary-of-publications/index.njk.test.ts` — asserts EN notice text and CY placeholder + presence + locale key parity. +- **E2E tests**: None added. Acceptable for this change — the notice is exercised by unit + tests, and adding a full Playwright journey would require a seeded MHT location. Consider + folding a notice assertion into an existing summary-of-publications journey if one exists. +- **Accessibility tests**: None added specifically; `govukInsetText` is a standard accessible + GOV.UK component and the page-level a11y is covered by existing tooling. + +**Statement coverage per changed workspace:** + +| Workspace | Changed file | Stmt coverage | Notes | +|---|---|---|---| +| `@hmcts/list-types-common` | `src/list-type-data.ts` | ~100% (pure data array, imported + asserted) | Full-suite coverage run hits the known pre-existing `@hmcts/pht-weekly-hearing-list` import failure (unrelated to #792); scoped test run passes 9/9. | +| `@hmcts/web` | `src/pages/(public)/summary-of-publications/index.ts` | **100% stmts / 94.44% branch** | Uncovered branch lines 11 (`res.locals.locale \|\| "en"`) and 64 (list-type name fallback) are **pre-existing**, not introduced by this change. New notice logic (lines 121-137) is fully covered. | + +Both changed workspaces are well above the 80% threshold. No ⚠️ coverage flag. + +## Acceptance Criteria Verification + +- [~] **AC1 — List created, linked to Tribunal jurisdiction + National region, shown as + "Mental Health Tribunal Daily Hearing List" in the manual upload form.** + Code is fully present: catalogue entry `list-type-data.ts:94-103`; prod insert + `001_insert_missing_list_types.sql:15`; sub-jurisdiction link (MHT = 20, under Tribunal + jurisdiction) `003_upsert_sub_jurisdictions_and_list_type_links.sql:77-78`. The manual + upload dropdown auto-populates from `findStrategicListTypes()` using `shortenedFriendlyName` + (`apps/web/src/pages/(admin)/manual-upload/index.ts:12,17`), so the label displays + correctly with no controller change. Region "National" is a location-level attribute (per + resolved decision — no list-type change). **Runtime-unverified**: confirming the dropdown + entry and default sensitivity requires a live DB reseed + browser, not possible headless. + +- [x] **AC2 — Strategic (`isNonStrategic = false`).** + `list-type-data.ts:100` (`isNonStrategic: false`), SQL `false` column + `001_insert_missing_list_types.sql:15`, asserted `list-type-data.test.ts:15-24`. + +- [x] **AC3 — Default sensitivity Public.** + `list-type-data.ts:99` (`defaultSensitivity: "Public"`), SQL `'Public'` + `001_insert_missing_list_types.sql:15`, asserted `list-type-data.test.ts:26-35`. + +- [x] **AC4 — Flat file, no JSON schema, no style guide.** + No schema/validator/converter/PDF/list page was created (correct for a flat-file type per + the resolved decision). Confirmed by absence and by the catalogue entry omitting `urlPath` + (`list-type-data.ts:94-103`; asserted `list-type-data.test.ts:83-92`). The CLAUDE.md + "every schema needs a validator" guard does not apply as there is no schema. + +- [~] **AC5 — Summary-of-publications notice (EN + CY).** + Logic fully present and unit-tested: EN copy `en.ts:12`, CY placeholder `cy.ts:12`, + controller trigger `index.ts:124-137`, `govukInsetText` block `index.njk:30-32`, tests + `index.test.ts:721-766`. Two gaps keep this partial: (1) the Welsh string is an + approved-interim `[WELSH TRANSLATION REQUIRED: ...]` placeholder pending final translation + (pre-release TODO, not a defect); (2) live render at `?lng=cy` on a seeded MHT location is + runtime-unverified headless. Trigger = location linked to the MHT sub-jurisdiction, per the + resolved decision. + +## Next Steps + +- [ ] (High) Memoise or otherwise avoid the per-request `getAllSubJurisdictions()` call on + the summary-of-publications hot path (`index.ts:124`). +- [ ] (Suggestion) Extract `"Mental Health Tribunal"` to a named module-scope constant + (`index.ts:125`). +- [ ] (Pre-release) Replace the Welsh notice placeholder with the approved translation + (`cy.ts:12`). +- [ ] (Verification) Reseed a local/STG DB, confirm the list appears in `/manual-upload` as + "Mental Health Tribunal Daily Hearing List" defaulting to Public sensitivity (AC1), and + confirm the notice renders in EN and `?lng=cy` on an MHT location's summary page (AC5). + +## Overall Assessment + +**NEEDS CHANGES** (advisory). + +The code is complete, correct, type-safe, secure, and well-tested — there are no blocking +code defects and coverage on both changed workspaces exceeds 80%. The verdict is driven +solely by the two `[~]` acceptance criteria (AC1, AC5), which are outstanding due to +runtime verification that is impossible headless and the pending approved Welsh translation — +not because of code problems. Once the Welsh string is finalised and the AC1/AC5 runtime +checks are performed on a seeded environment (and, ideally, the extra reference-data query is +memoised), this is ready to approve. diff --git a/docs/tickets/792/tasks.md b/docs/tickets/792/tasks.md new file mode 100644 index 000000000..62cf61bf4 --- /dev/null +++ b/docs/tickets/792/tasks.md @@ -0,0 +1,17 @@ +# Tasks: #792 Mental Health Tribunal Daily Hearing List + +## Implementation Tasks + +- [x] Add `MENTAL_HEALTH_TRIBUNAL_HEARING_LIST` entry to `listTypeData[]` in `libs/list-types/common/src/list-type-data.ts` (provenance `CFT_IDAM`, `isNonStrategic: false`, `defaultSensitivity: "Public"`, `shortenedFriendlyName` = full name, `subJurisdictionIds: [20]`, English + Welsh friendly names from ticket) +- [x] Add prod seed row to `apps/postgres/prisma/scripts/001_insert_missing_list_types.sql` (empty `url`, `'Public'`, `'CFT_IDAM'`, `false`) +- [x] Add sub-jurisdiction link row (`'MENTAL_HEALTH_TRIBUNAL_HEARING_LIST', 20`) to the Step 2 `VALUES` block in `apps/postgres/prisma/scripts/003_upsert_sub_jurisdictions_and_list_type_links.sql` +- [x] Create `libs/list-types/common/src/list-type-data.test.ts` asserting the new entry's fields and `listTypeData[].name` uniqueness (AAA pattern) +- [x] Add `mentalHealthNotice` (English) to `apps/web/src/pages/(public)/summary-of-publications/en.ts` +- [x] Add `mentalHealthNotice` Welsh placeholder to `apps/web/src/pages/(public)/summary-of-publications/cy.ts` +- [x] Update `apps/web/src/pages/(public)/summary-of-publications/index.ts`: import `getAllSubJurisdictions`, resolve Mental Health Tribunal sub-jurisdiction id by stable name, set `showMentalHealthNotice` from `location.subJurisdictions`, pass `mentalHealthNotice` to `res.render` +- [x] Add conditional `govukInsetText` block for `mentalHealthNotice` in `apps/web/src/pages/(public)/summary-of-publications/index.njk` (after the `cautionMessage` block) +- [x] Update `apps/web/src/pages/(public)/summary-of-publications/index.test.ts` and `index.njk.test.ts` to cover notice shown / not shown based on location sub-jurisdiction (mock `getAllSubJurisdictions` + `getLocationById`) +- [~] Run `yarn db:generate` then re-seed locally (`libs/location/src/seed-list-types.ts`) and verify the list appears in the `/manual-upload` dropdown as "Mental Health Tribunal Daily Hearing List" with sensitivity defaulting to Public — CANNOT be done in headless env (no live DB). Catalogue + prod-seed SQL updated; manual upload dropdown auto-populates from `findStrategicListTypes()` so no code change needed. Requires local/STG DB re-seed + browser check to confirm. +- [~] Verify AC5 notice renders in English and with `?lng=cy` on a Mental Health Tribunal location's summary of publications page — controller/template/tests done; live browser render at `?lng=cy` requires a running app + seeded MHT location, not possible headless. +- [x] Run `yarn lint:fix`, `yarn test`, and confirm no JSON-schema guard test is triggered (flat file has no schema) +- [x] Resolve open items in plan CLARIFICATIONS: (1) provenance = `CFT_IDAM`; (2) AC5 trigger = location linked to Mental Health Tribunal sub-jurisdiction; (3) region "National" is a location-level attribute — no list-type change; (4) Welsh notice remains a `[WELSH TRANSLATION REQUIRED: ...]` placeholder; (5) no dedicated list page — flat file served via existing `/hearing-lists/...` link. diff --git a/docs/tickets/792/ticket.md b/docs/tickets/792/ticket.md new file mode 100644 index 000000000..c8562fb8b --- /dev/null +++ b/docs/tickets/792/ticket.md @@ -0,0 +1,61 @@ +# #792: Style Guide: Mental Health Tribunal Daily Hearing List + +**State:** OPEN +**Assignees:** junaidiqbalmoj +**Author:** OgechiOkelu +**Labels:** enhancement, type:story, epic:public-journey +**Created:** 2026-07-01T12:43:38Z +**Updated:** 2026-07-20T12:54:47Z + +## Description + +**PROBLEM STATEMENT** +This ticket is raised for the creation of the Mental Health Tribunal Daily Hearing List for manual publishing in CaTH. + + +**AS A** Service +**I WANT** to create the supporting information for the Mental Health Tribunal Daily Hearing List +**SO THAT** this hearing list can be manually published in CaTH + + +**LIST DETAILS** (source: [pip-frontend `listLookup.json`](https://github.com/hmcts/pip-frontend/blob/master/src/main/resources/listLookup.json)) + +| Field | Value | +|---|---| +| List type key | `MENTAL_HEALTH_TRIBUNAL_HEARING_LIST` | +| Friendly name | Mental Health Tribunal Daily Hearing List | +| Welsh friendly name | Rhestr Wrandawiadau Dyddiol y Tribiwnlys Iechyd Meddwl | +| Shortened friendly name (manual upload form) | Mental Health Tribunal Daily Hearing List | +| Jurisdiction | Tribunal (jurisdiction type: Mental Health Tribunal) | +| Region | National | +| Non-strategic | `false` | +| Default sensitivity | Public (`defaultSensitivity` is empty in the lookup → defaults to Public) | +| Restricted provenances | None | +| URL | None | + + +**UPLOAD TYPE** + +- This is a **flat file upload** list type (e.g. PDF / manually prepared document), not a structured JSON publication. +- There is **no JSON schema validation** for this list type. Files are published as-is via the manual upload form. +- Consequently there is no style guide or validation schema to produce for this list. + + +**ACCEPTANCE CRITERIA** + +- The Mental Health Tribunal Daily Hearing List is created in the front end and linked to the **Tribunal** jurisdiction and **National** region. In the manual upload form, the list name is displayed as **Mental Health Tribunal Daily Hearing List**. + +- The list is **strategic** (`isNonStrategic` = `false`). + +- The default sensitivity of the list is **Public**. + +- The list is uploaded as a **flat file** — there is **no JSON schema validation** and no style guide for this list type. + +- The Mental Health Tribunal rarely publishes a hearing list, so the following message should be displayed in the summary of publications page to inform users that the hearing list is not routinely published: + + > Mental health hearings are held in private and unless a request has been made by the patient for a public hearing a hearing list will not be published. + +## Comments + +### Comment by junaidiqbalmoj on 2026-07-20T12:54:47Z +@SPEC diff --git a/libs/list-types/common/src/list-type-data.test.ts b/libs/list-types/common/src/list-type-data.test.ts new file mode 100644 index 000000000..a4ae1c2df --- /dev/null +++ b/libs/list-types/common/src/list-type-data.test.ts @@ -0,0 +1,107 @@ +import { describe, expect, it } from "vitest"; +import { listTypeData } from "./list-type-data.js"; + +describe("listTypeData", () => { + describe("MENTAL_HEALTH_TRIBUNAL_HEARING_LIST entry", () => { + it("should include a Mental Health Tribunal Daily Hearing List entry", () => { + // Arrange + // Act + const entry = listTypeData.find((lt) => lt.name === "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST"); + + // Assert + expect(entry).toBeDefined(); + }); + + it("should be a strategic list type", () => { + // Arrange + const entry = listTypeData.find((lt) => lt.name === "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST"); + + // Act + const isNonStrategic = entry?.isNonStrategic; + + // Assert + expect(isNonStrategic).toBe(false); + }); + + it("should default sensitivity to Public", () => { + // Arrange + const entry = listTypeData.find((lt) => lt.name === "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST"); + + // Act + const defaultSensitivity = entry?.defaultSensitivity; + + // Assert + expect(defaultSensitivity).toBe("Public"); + }); + + it("should use the PI_AAD provenance", () => { + // Arrange + const entry = listTypeData.find((lt) => lt.name === "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST"); + + // Act + const provenance = entry?.provenance; + + // Assert + expect(provenance).toBe("PI_AAD"); + }); + + it("should be linked to the Mental Health Tribunal sub-jurisdiction", () => { + // Arrange + const entry = listTypeData.find((lt) => lt.name === "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST"); + + // Act + const subJurisdictionIds = entry?.subJurisdictionIds; + + // Assert + expect(subJurisdictionIds).toEqual([20]); + }); + + it("should set the shortened friendly name to the full friendly name", () => { + // Arrange + const entry = listTypeData.find((lt) => lt.name === "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST"); + + // Act + const shortenedFriendlyName = entry?.shortenedFriendlyName; + + // Assert + expect(shortenedFriendlyName).toBe("Mental Health Tribunal Daily Hearing List"); + }); + + it("should use the English and Welsh friendly names from the ticket", () => { + // Arrange + const entry = listTypeData.find((lt) => lt.name === "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST"); + + // Act + const englishFriendlyName = entry?.englishFriendlyName; + const welshFriendlyName = entry?.welshFriendlyName; + + // Assert + expect(englishFriendlyName).toBe("Mental Health Tribunal Daily Hearing List"); + expect(welshFriendlyName).toBe("Rhestr Wrandawiadau Dyddiol y Tribiwnlys Iechyd Meddwl"); + }); + + it("should not define a urlPath because it is served as a flat file", () => { + // Arrange + const entry = listTypeData.find((lt) => lt.name === "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST"); + + // Act + const urlPath = entry?.urlPath; + + // Assert + expect(urlPath).toBeUndefined(); + }); + }); + + describe("catalogue integrity", () => { + it("should not contain duplicate list type names", () => { + // Arrange + const names = listTypeData.map((lt) => lt.name); + + // Act + const uniqueNames = new Set(names); + + // Assert + expect(uniqueNames.size).toBe(names.length); + }); + }); +}); diff --git a/libs/list-types/common/src/list-type-data.ts b/libs/list-types/common/src/list-type-data.ts index 9b4665794..c301751a3 100644 --- a/libs/list-types/common/src/list-type-data.ts +++ b/libs/list-types/common/src/list-type-data.ts @@ -91,6 +91,16 @@ export const listTypeData: ListTypeData[] = [ defaultSensitivity: "Public", subJurisdictionIds: [9] }, + { + name: "MENTAL_HEALTH_TRIBUNAL_HEARING_LIST", + englishFriendlyName: "Mental Health Tribunal Daily Hearing List", + welshFriendlyName: "Rhestr Wrandawiadau Dyddiol y Tribiwnlys Iechyd Meddwl", + provenance: "PI_AAD", + isNonStrategic: false, + defaultSensitivity: "Public", + shortenedFriendlyName: "Mental Health Tribunal Daily Hearing List", + subJurisdictionIds: [20] + }, // RCJ Standard Format { name: "CIVIL_COURTS_RCJ_DAILY_CAUSE_LIST",