feat(visits): resolve where the window before a booked visit starts

The visit preparation and the doctor report offered for an appointment
started at the last visit of any kind. An internist one week and a
dermatologist the next gave the dermatologist a one-week window of
nothing it is about.

The list read now publishes `preparation` on every booked upcoming
visit: the first day of the window, the rule that chose it and the
earlier visit it is the day of. First match wins over the visits that
took place before it: the same practitioner, else a practitioner of
the same specialty (free text, compared without case or spacing), else
the same kind for routine, preventive and therapy visits, else the last
90 days. One query of past visits per page, independent of the list's
own filters. Null on every other row; absent on the detail and on
write responses.
This commit is contained in:
Marc-André Bombeck committed 2026-10-21 12:32:12 +02:00
1 parent 0dcafeeb70
commit 402cf1a35a
8 files changed
+781 -8

No files matched your search

+73
View File
@@ -71911,6 +71911,12 @@ components:
$ref: "#/components/schemas/EncounterLinks"
skipped:
$ref: "#/components/schemas/EncounterSkipReport"
preparation:
description: "On the list read only (`GET /api/encounters`): the window before this visit when it is booked (PLANNED,
upcoming), null on every other row. Absent on the detail and on write responses."
anyOf:
- $ref: "#/components/schemas/EncounterPreparation"
- type: "null"
createdAt:
type: string
updatedAt:
@@ -72062,6 +72068,73 @@ components:
checkup, which is a measurements-domain write a health-background delegate cannot perform. The visit still
saves; the checkup stays due and the response says so, because somebody who believes a checkup was closed will
not look at it again."
EncounterPreparation:
type: object
properties:
from:
type: string
description: "First day of the window, `YYYY-MM-DD` on the record's own calendar: the day of `since`, or 90 days before
today on `default`."
basis:
type: string
enum:
- practitioner
- specialty
- kind
- default
description: "The rule that chose `from`, first match wins over the visits that took place (DONE) before this one:
`practitioner` (the last visit with the same practitioner), `specialty` (the last visit with a practitioner
of the same specialty, compared without case or extra spaces), `kind` (the last visit of the same kind, for
ROUTINE, PREVENTIVE and THERAPY only), `default` (none matched: the last 90 days)."
since:
anyOf:
- $ref: "#/components/schemas/EncounterPreparationAnchor"
- type: "null"
required:
- from
- basis
- since
additionalProperties: false
description: "The window before a booked visit, resolved server-side: where the visit preparation and the doctor report
offered for the appointment start, and why there. Never the last visit of any kind, which is how a dermatology
appointment was offered a week of data from an internist visit. A client shows `from` with its reason and lets
the person change the dates; it does not recompute the rule."
EncounterPreparationAnchor:
type: object
properties:
id:
type: string
occurredAt:
type: string
kind:
type: string
enum:
- ROUTINE
- ACUTE
- SPECIALIST
- PREVENTIVE
- EMERGENCY
- HOSPITAL
- THERAPY
- OTHER
- PROCEDURE
practitionerName:
type:
- string
- "null"
specialty:
type:
- string
- "null"
required:
- id
- occurredAt
- kind
- practitionerName
- specialty
additionalProperties: false
description: "The earlier visit the window starts at: its id, instant and kind, and the practitioner's name and
specialty as they read now."
CreateEncounterEnvelope:
type: object
properties: