How case intake is handled on the server. createCase now serves only the
demo seed, the guided tour and tests: staff add cases through a request's
case step (src/cases/caseStep.ts; see "The case step" in api.md). See also api.md and
../MAPPING.md.
- Request validation:
src/intake/validation.tsdefines a Zod schema forcreateCase's input (uuid format, required fields, identifier completeness, explicit ISO timestamp or internal Date). Malformed input (e.g. a non-UUIDpersonId) is rejected there, before any query runs — the DB layer never sees a value that could otherwise surface as a raw driver error instead of a field-levelValidationError. - Error responses: domain actions throw subclasses of
AppError(src/errors.ts:ValidationError400,ForbiddenError403,NotFoundError404,ConflictError409,ConfigurationError500), and the error middleware insrc/app.tsturns them into JSON responses, so routes have no per-action catch blocks. Reference rows are looked up withgetReferenceId/getSeededRoleId(src/db/referenceLookups.ts), which throwConfigurationErrorwhen a provisioned row is missing. - Retry handling: the form retains its request ID for retries of an unchanged payload. The handler recovers the original result after either request-ID or identifier uniqueness conflicts from concurrent replays.
- Office compatibility: when both organization and office are supplied, the office must belong to that organization.
- Demo seeding:
npm run seedexplicitly resets all application data; normal Docker Compose startup only migrates and starts the server, preserving records. - Settings layout (design I, I36–I39;
client/src/pages/Settings.tsx, one file per section inpages/settings/,components/ui/SegmentedChoice.tsx): an "On this page" index of Invoice review (routing beside the reason lists, whose list is a segmented Approving part / Rejecting / Both / Case rate choice), People who use this tool (what each role can do, then staff), Rates (a card per kind, mileage, travel and waiting time) and Billing rules and codes (one row per rule with an Off / Warn / Require choice); Demo comes last. Design I37's three staff roles are replaced by Staff and Administrator, as decided. - Case pages (design I, I47–I49;
client/src/pages/Overview.tsx,CaseList.tsx,CaseDetail.tsx;server/src/cases/caseSummaries.ts):GET /api/casesadds each case's number, the people working on it, its pre-authorized amounts added up and the invoices waiting (loadCaseListExtras). Cases come in with their invoices, so stages follow them (server/src/cases/caseStage.ts): Needs assignment when a waiting invoice has no reviewer, Billing when every waiting one has, Closing after an approved one, else Represented. Case overview (off the sidebar since design K, which leads with Invoice overview) has a card per stage with its count and a "Recently changed" table (GET /api/cases/recent-changes: the latest invoice events on cases, as words, such as "sent, no reviewer assigned yet", and case openings and closings, with who). Neither list has Add case, and the case page has no Add person (corrected in design I). All cases has All / Open / Closed chips, the county filter and a search, with design I's columns and, from design K48, an inert "Open ↗" to the case in the external system. A case's page says when it may be a duplicate of another (K49). A case's page has its facts, a "Pre-authorized and billed" card per pre-authorization (approved, waiting, what would be left, and a bar) beside the people on it, then its invoices and case rates, and at the foot "Closing the case here": a cleanup any staff member may do once no invoice is in review and every decided one is marked completed. Matching a later invoice to a closed case (from the case step on the check or review page) reopens it. - Look-up pages (design I, I51–I53; design K30, K51): Providers (
/people) lists everyone who bills, read-only. Settings › Providers lists each provider with their kind (changed inline by administrators), today's rate, their office, who can send their invoices (themselves once they can sign in, and their office's billing delegates) and Active, whether they may sign in (GET /api/professionalswithsrc/professionals/providerOffices.ts); the old/vendorsaddress redirects there. Clients lists every case's client with its case, county, opened date and status (fromGET /api/cases). Organizations adds how many cases each has. Gap: organizations can't be edited here, so I53's Edit isn't built. - Demo tools (Settings, "Demo"): only while the staff demo sign-in is on
(
src/auth/demoSettings.ts; otherwise the routes are 404s, and/auth/mereportsdemoMode). Every staff member then sees Settings, andGET/PUT /api/settings/demo/rolelets them switch their own role, an administrator included, which the regular role setting forbids; the change is audited like any role change.POST /api/settings/demo/reset("Reset demo data", administrators) runs the seed's reset (src/db/demoData.ts), removes stored import files no longer referenced, refuses a second concurrent reset, and ends the caller's session, since accounts are recreated. Other users' requests during the reset may fail. - Reference/active checks run via the pool, not inside the transaction:
createCasevalidates that every referenced id exists and (where the table has anactiveflag) is active, viaPromise.allover the connection pool, before opening the write transaction. A single Postgres connection can't usefully run queries concurrently — issuing them that way against an open transaction's connection produced apgdeprecation warning in practice, not a real speedup. Running the checks over separate pool connections first gives genuine concurrency and keeps the transaction open for as little time as possible. These checks are a friendly-error convenience, not the integrity boundary — the FK constraints insrc/db/schema.tsenforce referential integrity regardless. - Constraint-name constants: unique-violation → friendly-error
translation (idempotent replay, duplicate identifier) matches on
Postgres constraint names. Those names are exported as constants from
src/db/schema.ts(CASE_IDENTIFIER_ISSUER_TYPE_VALUE_UNIQUE_CONSTRAINT,INTAKE_REQUEST_PRIMARY_KEY_CONSTRAINT) and imported intosrc/intake/createCase.ts, rather than duplicated as separate string literals, so renaming a constraint in one place can't silently desync the other. - Reporting time zone:
opened_on(and any other calendar-date field derived from an instant) is computed via a namedREPORTING_TIME_ZONEconstant (src/intake/createCase.ts), currently'UTC'. Time zone is explicitly called out as an unresolved, per-organization configuration choice indocs/case-intake-comparison-plan.md; this constant is a synthetic single-environment default, not a resolved product decision — changing it to a real IANA zone is a one-line change, not a logic rewrite.