fix(visits): open an upcoming appointment where it lives

Visits are the second tab of `/checkups`, and the bare path opens the
first one, the preventive-care list, which never shows an appointment.
Every surface that listed an upcoming appointment linked it there: the
dashboard's next-appointment line, the Today rail item, the Today
overview fact and the appointment's push notification. A tap on the
appointment landed on the list it is not on.

Each now opens the visit itself (`/checkups?visit=<id>`), or the visits
tab (`/checkups?view=visits`) for a line naming several appointments.
The checkups page reads `view` to pick a tab. The rail item stops
borrowing the check-up item's action: it carries its own label
("View appointment") and intent `visit.view`. The appointment push names
its visit through the producer's `metadata.url` override; a check-up's
push keeps the checkups list.

The same mis-route sat on three links that lead to visits without
being upcoming: a condition's visit rows, the address book's back link
and the onboarding and timeline prompts to add a visit.

`visit-link-guard.test.ts` keeps the visit paths in the builder and
counts every bare `/checkups` per file, each with the reason it names
the checkups list.
This commit is contained in:
Marc-André Bombeck committed 2026-10-21 12:22:36 +02:00
1 parent 78bacb0d86
commit 0dcafeeb70
29 files changed
+591 -23

No files matched your search

@@ -19,6 +19,7 @@ import {
appointmentNextDueAfterFiring,
appointmentNotifyHour,
appointmentReminderAddress,
appointmentReminderVisitPath,
} from "@/lib/encounters/appointment-reminder";
const TZ = "Europe/Berlin";
@@ -116,3 +117,31 @@ describe("the address an appointment reminder names", () => {
).toBeNull();
});
});
describe("where an appointment's push opens", () => {
const appointment = (visitUserId: string) => ({
userId: "u1",
origin: "ENCOUNTER",
encounters: [{ id: "visit-1", userId: visitUserId }],
});
it("opens the visit, on the visits tab", () => {
expect(appointmentReminderVisitPath(appointment("u1"))).toBe(
"/checkups?visit=visit-1",
);
});
it("counter-check: a checkup keeps the event's default, the checkups list", () => {
expect(
appointmentReminderVisitPath({
...appointment("u1"),
origin: "VORSORGE",
}),
).toBeNull();
expect(
appointmentReminderVisitPath({ ...appointment("u1"), encounters: [] }),
).toBeNull();
// Another account's visit is never a tap target.
expect(appointmentReminderVisitPath(appointment("u2"))).toBeNull();
});
});
@@ -1,10 +1,33 @@
import { describe, expect, it } from "vitest";
import { visitPath } from "../visit-links";
import {
CHECKUPS_VIEWS,
VISITS_PATH,
parseCheckupsView,
visitPath,
visitsPath,
} from "../visit-links";
describe("visit links", () => {
it("opens one visit on the visits tab, never the bare checkups page", () => {
expect(visitPath("v1")).toBe("/checkups?visit=v1");
expect(visitPath("a b&c")).toBe("/checkups?visit=a%20b%26c");
});
it("opens the visit itself for one, the visits list for several", () => {
expect(visitsPath(["v1"])).toBe("/checkups?visit=v1");
expect(visitsPath(["v1", "v2"])).toBe(VISITS_PATH);
expect(visitsPath([])).toBe(VISITS_PATH);
expect(VISITS_PATH).toBe("/checkups?view=visits");
});
it("reads exactly the checkups page's tabs from `view`", () => {
for (const view of CHECKUPS_VIEWS) {
expect(parseCheckupsView(view)).toBe(view);
}
expect(parseCheckupsView("visit")).toBeNull();
expect(parseCheckupsView("")).toBeNull();
expect(parseCheckupsView(null)).toBeNull();
expect(parseCheckupsView(undefined)).toBeNull();
});
});
+24 -2
View File
@@ -39,6 +39,7 @@
* edit of the address reaches a nudge that is already booked.
*/
import type { Prisma } from "@/generated/prisma/client";
import { visitPath } from "@/lib/encounters/visit-links";
import { readPractitionerContact } from "@/lib/practitioners/dto";
import {
computeReminderNextDueAt,
@@ -188,13 +189,15 @@ export function appointmentNextDueAfterFiring(
}
/**
* What the reminder tick reads beside an ENCOUNTER row to name the practice
* address: the practitioner of the live visit that owns it.
* What the reminder tick reads beside an ENCOUNTER row: the live visit that
* owns it, for the push's tap target ({@link appointmentReminderVisitPath}),
* and its practitioner, to name the practice address.
*/
export const APPOINTMENT_REMINDER_ADDRESS_INCLUDE = {
encounters: {
where: { deletedAt: null },
select: {
id: true,
userId: true,
practitioner: {
select: {
@@ -245,3 +248,22 @@ export function appointmentReminderAddress(reminder: {
"location",
);
}
/**
* Where an appointment's push opens: the visit itself.
*
* The nudge rides the checkup event type, whose default target is the bare
* `/checkups` — the preventive-care tab, which never lists an appointment. A
* checkup's push keeps that default (null here); an appointment's names its
* visit, through the producer override `resolveTapPath` already honours.
*/
export function appointmentReminderVisitPath(reminder: {
userId: string;
origin: string;
encounters?: ReadonlyArray<{ id: string; userId: string }>;
}): string | null {
if (reminder.origin !== "ENCOUNTER") return null;
const visit = reminder.encounters?.[0];
if (!visit || visit.userId !== reminder.userId) return null;
return visitPath(visit.id);
}
+39 -4
View File
@@ -2,16 +2,51 @@
* Where a visit lives in the app, spelled once.
*
* Visits have no page of their own: they are the second tab of `/checkups`,
* beside the preventive-care list that opens by default. The checkups page
* opens the visit a `visit` parameter names on the visits tab
* (`src/hooks/use-deep-linked-record.ts`).
* beside the preventive-care list that opens by default. A bare `/checkups`
* therefore lands on the checkups, which is the wrong half of the page for an
* appointment, and every surface that hand-spelled that path for a visit (the
* dashboard's next-appointment line, the Today rail, the Today overview, the
* appointment's push) sent the person to the list the appointment is not on.
*
* Every link to one visit is built here.
* Every link to one visit or to the visits list is built here. The checkups
* page reads both parameters: `visit` opens that visit on the visits tab
* (`src/hooks/use-deep-linked-record.ts`), `view` picks a tab.
* `visit-link-guard.test.ts` refuses a hand-spelled copy elsewhere.
*
* Pure and client-safe: no server imports.
*/
/** The tabs of the checkups page, as the `view` parameter names them. */
export const CHECKUPS_VIEWS = [
"vorsorge",
"visits",
"procedures",
"body-sites",
] as const;
export type CheckupsView = (typeof CHECKUPS_VIEWS)[number];
/** The tab a `view` parameter names, or null for anything else. */
export function parseCheckupsView(
value: string | null | undefined,
): CheckupsView | null {
return (CHECKUPS_VIEWS as readonly string[]).includes(value ?? "")
? (value as CheckupsView)
: null;
}
/** The visits list: the checkups page opened on its visits tab. */
export const VISITS_PATH = "/checkups?view=visits";
/** One visit: the visits tab, scrolled to the visit and opened. */
export function visitPath(id: string): string {
return `/checkups?visit=${encodeURIComponent(id)}`;
}
/**
* Where a group of visits leads: the visit itself when there is one, the
* visits list when several share one line (a day with two appointments).
*/
export function visitsPath(ids: readonly string[]): string {
return ids.length === 1 ? visitPath(ids[0]) : VISITS_PATH;
}