Merge branch 'fix/v14311-visits' into release/v1.43.11

This commit is contained in:
Marc-André Bombeck committed 2026-10-21 14:13:52 +02:00
commit 8d16799479
53 files changed
+1837 -118

No files matched your search

+20 -8
View File
@@ -35,6 +35,7 @@ import {
} from "@/lib/validations/encounters";
import { encounterKindLabel } from "@/lib/encounters/kind-label";
import { toEncounterDTO, type EncounterListDTO } from "@/lib/encounters/dto";
import { loadVisitPreparations } from "@/lib/encounters/preparation-read";
import {
ENCOUNTER_INCLUDE,
applyEncounterLinks,
@@ -143,12 +144,17 @@ export const GET = apiHandler(async (request: NextRequest) => {
// them makes the first read zero and the second unfile everything on save.
// Three grouped queries for the page, not three per row.
const visible = await actingDomainVisibility(prisma, grantId);
const links = await loadEncounterLinksForMany(
prisma,
user.id,
[...upcoming, ...past].map((row) => row.id),
visible,
);
// The window before each booked visit reads the whole history, not this
// page of it: the visit it starts at may sit outside the caller's filter.
const [links, preparations] = await Promise.all([
loadEncounterLinksForMany(
prisma,
user.id,
[...upcoming, ...past].map((row) => row.id),
visible,
),
loadVisitPreparations(prisma, user.id, upcoming, now),
]);
annotate({
action: { name: "encounter.visit.list", entity_type: "encounter" },
@@ -156,8 +162,14 @@ export const GET = apiHandler(async (request: NextRequest) => {
});
const body: EncounterListDTO = {
upcoming: upcoming.map((row) => toEncounterDTO(row, links.get(row.id))),
past: past.map((row) => toEncounterDTO(row, links.get(row.id))),
upcoming: upcoming.map((row) => ({
...toEncounterDTO(row, links.get(row.id)),
preparation: preparations.get(row.id) ?? null,
})),
past: past.map((row) => ({
...toEncounterDTO(row, links.get(row.id)),
preparation: null,
})),
};
return apiListSuccess(body, combinedCap(upcomingCap, pastCap));
});
@@ -0,0 +1,75 @@
/**
* Which tab a link to `/checkups` opens.
*
* Visits are the page's second tab. `?visit=<id>` opens one, `?view=visits`
* the list, and the bare path keeps opening the checkups, which is what the
* nav entry and the checkup surfaces mean by it.
*/
import { describe, expect, it, vi } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
let search = new URLSearchParams();
vi.mock("next/navigation", () => ({
useRouter: () => ({ push: vi.fn(), replace: vi.fn() }),
usePathname: () => "/checkups",
useSearchParams: () => search,
}));
vi.mock("@tanstack/react-query", async (importOriginal) => ({
...(await importOriginal<typeof import("@tanstack/react-query")>()),
useQueryClient: () => ({}),
}));
vi.mock("@/hooks/use-auth", () => ({
useAuth: () => ({ isAuthenticated: true, isLoading: false }),
}));
vi.mock("@/hooks/use-mounted", () => ({ useMounted: () => true }));
vi.mock("@/hooks/use-pull-to-refresh", () => ({
usePullToRefresh: () => ({}),
}));
vi.mock("@/components/ui/pull-to-refresh-indicator", () => ({
PullToRefreshIndicator: () => null,
}));
vi.mock("@/components/measurement-reminders/vorsorge-section", () => ({
VorsorgeSection: () => <div data-section="vorsorge" />,
}));
vi.mock("@/components/encounters/visits-section", () => ({
VisitsSection: () => <div data-section="visits" />,
}));
vi.mock("@/components/encounters/procedures-section", () => ({
ProceduresSection: () => <div data-section="procedures" />,
}));
vi.mock("@/components/body-sites/body-sites-section", () => ({
BodySitesSection: () => <div data-section="body-sites" />,
}));
import { I18nProvider } from "@/lib/i18n/context";
import CheckupsPageClient from "../page-client";
function openTab(query: string): string | null {
search = new URLSearchParams(query);
const html = renderToStaticMarkup(
<I18nProvider initialLocale="en">
<CheckupsPageClient />
</I18nProvider>,
);
return html.match(/data-section="([^"]+)"/)?.[1] ?? null;
}
describe("/checkups — the tab a link opens", () => {
it("opens the checkups on the bare path", () => {
expect(openTab("")).toBe("vorsorge");
});
it("opens the visits for a link to one visit", () => {
expect(openTab("visit=v1")).toBe("visits");
});
it("opens the tab `view` names", () => {
expect(openTab("view=visits")).toBe("visits");
expect(openTab("view=procedures")).toBe("procedures");
});
it("ignores a `view` it does not know", () => {
expect(openTab("view=elsewhere")).toBe("vorsorge");
});
});
+16 -3
View File
@@ -15,6 +15,7 @@ import { VisitsSection } from "@/components/encounters/visits-section";
import { ProceduresSection } from "@/components/encounters/procedures-section";
import { BodySitesSection } from "@/components/body-sites/body-sites-section";
import type { BodySiteSide } from "@/hooks/use-body-sites";
import { parseCheckupsView } from "@/lib/encounters/visit-links";
import { useTranslations } from "@/lib/i18n/context";
import { invalidateKeys, queryKeys } from "@/lib/query-keys";
@@ -66,17 +67,29 @@ export default function CheckupsPageClient() {
linkedSideParam === "BOTH"
? linkedSideParam
: null;
const [view, setView] = useState(
linkedVisit ? "visits" : linkedSite ? "body-sites" : "vorsorge",
// A link to one tab (`?view=visits`, from a line naming several
// appointments). Built by `src/lib/encounters/visit-links.ts`, never by hand.
const linkedView = parseCheckupsView(searchParams?.get("view"));
const [view, setView] = useState<string>(
linkedVisit
? "visits"
: linkedSite
? "body-sites"
: (linkedView ?? "vorsorge"),
);
// A link to a visit can arrive while the page is already open (the search
// opens one from wherever the person is): it moves to the visits tab then
// too, rather than only on the first render.
// too, rather than only on the first render. A link to a tab does the same.
const [observedVisit, setObservedVisit] = useState(linkedVisit);
if (linkedVisit !== observedVisit) {
setObservedVisit(linkedVisit);
if (linkedVisit) setView("visits");
}
const [observedView, setObservedView] = useState(linkedView);
if (linkedView !== observedView) {
setObservedView(linkedView);
if (linkedView && !linkedVisit) setView(linkedView);
}
const refresh = useCallback(
() =>