feat(mental-health): accept client source + externalId with durable dedup

The screener POST hardcoded source=WEB and ignored any client-supplied
externalId, so the native client could not tag provenance and an outbox
replay beyond the 24h idempotency-key window minted duplicate
administrations plus duplicate trend points.

Accept an optional closed source enum (WEB|IOS, default WEB) and an optional
bounded externalId, and persist both. Deduplicate on (userId, externalId)
when present: the route returns the existing administration on replay, and a
partial unique index over (user_id, external_id) WHERE external_id IS NOT
NULL (migration 0221) backstops a concurrent insert race (P2002 resolved to
the winner). The derived *_SCORE measurement keeps its stable per-assessment
externalId, so dedup at the assessment level prevents duplicate trend points.
Item answers stay encrypted and out of AI/MCP/export. Regenerate OpenAPI.
This commit is contained in:
Marc-André Bombeck committed 2026-06-28 19:06:21 +02:00
1 parent e93f74381e
commit 930cb227eb
6 files changed
+250 -32

No files matched your search

+10
View File
@@ -8137,6 +8137,16 @@ paths:
locale:
type: string
maxLength: 16
source:
default: WEB
type: string
enum:
- WEB
- IOS
externalId:
type: string
minLength: 1
maxLength: 120
required:
- instrument
- items