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
This commit is contained in:
Marc-André Bombeck committed 2026-09-25 08:11:37 +02:00
1 parent ee23409b77
commit ad0d50fa28
43 files changed
+2486 -61

No files matched your search

+5
View File
@@ -48,6 +48,7 @@ import {
InjectionSite,
IntakeAttributionSource,
IntakeSource,
Laterality,
MeasurementAggregationProvenance,
MeasurementReminderEventKind,
MeasurementSource,
@@ -1088,6 +1089,10 @@ const encounterBackupSchema = z
practitionerId: z.string().nullable().optional(),
reasonEncrypted: base64BytesSchema.nullable().optional(),
outcomeEncrypted: base64BytesSchema.nullable().optional(),
// v1.39.1 — the procedure's body site and side. Optional so a file written
// before they existed still parses; the visit restores with neither.
bodySiteEncrypted: base64BytesSchema.nullable().optional(),
laterality: z.enum(Laterality).nullable().optional(),
// Remapped against the restored reminders (they travel since v1.37.20);
// dropped to NULL, with the drop named, only when the file lacks the row.
reminderId: z.string().nullable().optional(),
+33
View File
@@ -61,10 +61,22 @@ export const encounterKindEnum = z.enum([
"HOSPITAL",
"THERAPY",
"OTHER",
"PROCEDURE",
]);
/** The side a procedure's body site is on. Absent or null: not stated. */
export const lateralityEnum = z.enum(["LEFT", "RIGHT", "BOTH"]);
export type EncounterStatusInput = z.infer<typeof encounterStatusEnum>;
export type EncounterKindInput = z.infer<typeof encounterKindEnum>;
export type LateralityInput = z.infer<typeof lateralityEnum>;
/**
* Where on the body, in the person's own words. Becomes `bodySiteEncrypted`.
* Bounded like a label rather than like prose: "left knee, medial meniscus" is
* the long end of what belongs here, and the reason field holds the rest.
*/
const bodySite = z.string().max(200).nullable().optional();
const id = z.string().min(1).max(40);
@@ -88,6 +100,8 @@ export const encounterCreateSchema = z
reason: z.string().max(2000).nullable().optional(),
/** Becomes `outcomeEncrypted`. */
outcome: z.string().max(4000).nullable().optional(),
bodySite,
laterality: lateralityEnum.nullable().optional(),
/** The checkup this visit closes, when it was filed from a due one. */
reminderId: id.nullable().optional(),
documentIds: linkIds,
@@ -113,6 +127,8 @@ export const encounterUpdateSchema = z
practitionerId: id.nullable().optional(),
reason: z.string().max(2000).nullable().optional(),
outcome: z.string().max(4000).nullable().optional(),
bodySite,
laterality: lateralityEnum.nullable().optional(),
reminderId: id.nullable().optional(),
documentIds: linkIds,
labResultIds: linkIds,
@@ -173,6 +189,23 @@ export const encounterSuggestQuerySchema = z
export type EncounterSuggestQuery = z.infer<typeof encounterSuggestQuerySchema>;
/**
* The procedure history query.
*
* `q` is matched after the decrypt, over the body site, the side and the
* reason, every word required (see `src/lib/encounters/procedures.ts`). It is
* named `q` and not `bodySite` because it also searches the reason: a knee
* operation recorded before the site field existed says "knee" only there.
*/
export const procedureListQuerySchema = z
.object({
q: z.string().max(200).optional(),
laterality: lateralityEnum.optional(),
})
.strict();
export type ProcedureListQuery = z.infer<typeof procedureListQuerySchema>;
/* ── links ────────────────────────────────────────────────────────── */
export const encounterLinkTargetEnum = z.enum([