Files
HealthLog/prisma/migrations/0349_encounter_procedure_body_site/migration.sql
T
Marc-André Bombeck ad0d50fa28 feat(visits): record procedures and surgeries with a body site
A visit can be filed as a procedure or surgery (new EncounterKind
PROCEDURE) and carry a body site in the person's own words, encrypted at
rest, plus an optional side (LEFT, RIGHT, BOTH). An existing visit
switches to the new kind by an ordinary edit, keeping its date, reason,
outcome and links.

- migration 0349: enum value, laterality type, two nullable columns
- GET /api/encounters/procedures: the DONE procedures, newest first,
  searched after the decrypt over site, side and reason, with body-site
  choices and a total computed over the whole history
- create and edit accept bodySite and laterality on any kind
- /checkups gains a Procedures tab with a body-site filter; the visit
  form offers the site for a procedure and keeps it in view on any
  visit that carries one
- backup and restore carry both fields; the body site is registered as
  ciphertext and rotates with the key
- MCP get_visits narrows by kind and reads the whole record for
  procedures when no window is named; the Coach visit block names a
  procedure's site
- i18n in all seven locales, OpenAPI regenerated

Refs #1025
2026-09-25 08:11:37 +02:00

25 lines
1.2 KiB
SQL

-- Procedure and surgery history on visits.
--
-- A visit can now be marked as a procedure or surgery (`PROCEDURE` kind) and
-- carry the body site it was done on: free text, encrypted at rest like the
-- visit's reason and outcome, plus an optional side. The reasoning for a kind
-- rather than a flag, and for searching the site by decrypting server-side
-- rather than storing a plaintext copy, is written at the `Encounter` model.
--
-- Purely additive. `ADD VALUE IF NOT EXISTS` makes a rerun safe, and the new
-- value is not used elsewhere in this migration, which is the one thing
-- Postgres forbids inside the transaction that adds it. No backfill: an
-- existing visit keeps its kind until the person switches it, which is an
-- ordinary edit. Both columns are nullable, so no row is rewritten.
--
-- Reversibility: Postgres cannot drop an enum value, so `PROCEDURE` would stay
-- (inert with no rows); the two columns and the `laterality` type can be
-- dropped.
ALTER TYPE "encounter_kind" ADD VALUE IF NOT EXISTS 'PROCEDURE';
CREATE TYPE "laterality" AS ENUM ('LEFT', 'RIGHT', 'BOTH');
ALTER TABLE "encounters"
ADD COLUMN "body_site_encrypted" BYTEA,
ADD COLUMN "laterality" "laterality";