feat(share-links): public clinician view at /c/[token]

A standalone read-only RSC that resolves the path token through the share-token
resolver and renders an owner-scoped clinical summary: provenance header,
clinical vitals and labs, medications with adherence, and a fenced muted card
for the descriptive wellness scores carrying the not-a-clinical-assessment,
not-a-diagnosis disclaimer. KVNR is default off. No app chrome, no coach, no AI,
no session, no markdown — every value renders as escaped text. force-dynamic and
noindex; the page returns a flat 404 for any null resolve.

The route joins the proxy public-path allowlist and the AuthShell standalone
list so it reaches the page bare without a sign-in redirect. New clinicianView
strings land in all six locales.
This commit is contained in:
Marc-André Bombeck committed 2026-06-04 01:21:42 +02:00
1 parent 9830ae8027
commit 6aa3c75d27
13 files changed
+753 -1

No files matched your search

@@ -0,0 +1,105 @@
/**
* v1.11.0 (Epic C, C5) — clinician-view presentation.
*
* Asserts the load-bearing rendering properties: the fenced wellness card
* carries the descriptive "not a clinical assessment / not a diagnosis"
* disclaimer, the provenance header renders, and the view holds no app chrome.
*/
import { describe, it, expect } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import { ClinicianView } from "../clinician-view";
import { getServerTranslator } from "@/lib/i18n/server-translator";
import { DEFAULT_DOCTOR_REPORT_PREFS } from "@/lib/validations/doctor-report-prefs";
import type { DoctorReportData } from "@/lib/doctor-report-data";
function makeReport(
overrides: Partial<DoctorReportData> = {},
): DoctorReportData {
return {
period: {
days: 30,
since: "2026-01-01",
start: "2026-01-01T00:00:00.000Z",
end: "2026-01-31T00:00:00.000Z",
},
patient: {
username: "tester",
dateOfBirth: null,
gender: null,
heightCm: null,
},
practiceName: null,
measurements: {},
stats: {
WEIGHT: { avg: 80, min: 78, max: 82, count: 12, latest: 79 },
},
glucoseStats: {},
glucoseRanges: {},
glucoseUnit: "mg/dL",
bmi: 24.5,
compliance: {},
medications: [],
wellnessScores: [
{
type: "RECOVERY_SCORE",
latest: 72,
avg: 68,
min: 50,
max: 90,
count: 20,
latestAt: "2026-01-30T00:00:00.000Z",
},
],
...overrides,
} as DoctorReportData;
}
function render(report: DoctorReportData) {
const { t } = getServerTranslator("en");
return renderToStaticMarkup(
<ClinicianView
t={(k, v) => t(k, v)}
label="Cardiology clinic"
expiresAt="2026-03-01T00:00:00.000Z"
report={report}
sections={{ ...DEFAULT_DOCTOR_REPORT_PREFS }}
/>,
);
}
describe("<ClinicianView>", () => {
it("renders the fenced wellness card with the descriptive disclaimer", () => {
const html = render(makeReport());
expect(html).toContain("Wellness scores");
expect(html).toContain("not a clinical assessment");
expect(html).toContain("not a diagnosis");
expect(html).toContain("Recovery score");
});
it("renders the provenance header treating values as patient-reported", () => {
const html = render(makeReport());
expect(html).toContain("Shared health record");
expect(html).toContain("patient-reported");
expect(html).toContain("Cardiology clinic");
});
it("renders clinical vitals from the scoped report", () => {
const html = render(makeReport());
expect(html).toContain("Vital signs");
// The measurement-type enum is humanised, not raw.
expect(html).toContain("Weight");
expect(html).not.toContain("WEIGHT");
});
it("omits the wellness card when there are no scores", () => {
const html = render(makeReport({ wellnessScores: [] }));
expect(html).not.toContain("Wellness scores");
});
it("carries no app chrome (no nav / coach landmarks)", () => {
const html = render(makeReport());
expect(html).not.toContain('data-slot="sidebar"');
expect(html).not.toContain("coach");
});
});
+244
View File
@@ -0,0 +1,244 @@
/**
* v1.11.0 — clinician-view presentation (Epic C, C5).
*
* A pure server component: it receives an already-resolved, owner-scoped
* {@link DoctorReportData} plus a server-side translator and renders a
* read-only clinical summary. NO client hooks, NO session, NO AI/coach, NO
* markdown — every value renders as escaped React text.
*
* Layout: provenance header → clinical vitals/labs → medications + adherence →
* a FENCED, muted wellness card carrying the load-bearing "descriptive, not a
* clinical assessment / not a diagnosis" disclaimer.
*/
import type { DoctorReportData } from "@/lib/doctor-report-data";
import type { DoctorReportPrefs } from "@/lib/validations/doctor-report-prefs";
type Translate = (
key: string,
vars?: Record<string, string | number>,
) => string;
interface ClinicianViewProps {
t: Translate;
/** Owner-set label for the share (e.g. a clinic note). */
label: string;
/** ISO expiry instant — surfaced so the clinician knows the link lifetime. */
expiresAt: string;
report: DoctorReportData;
sections: DoctorReportPrefs;
}
/** Human-readable display per persisted wellness-score type (i18n key suffix). */
const WELLNESS_KEY: Record<string, string> = {
RECOVERY_SCORE: "recovery",
STRESS_SCORE: "stress",
STRAIN_SCORE: "strain",
};
/**
* Humanise a measurement-type enum (`BLOOD_PRESSURE_SYS` → "Blood pressure
* sys") for a clinical label. The clinician view is locale-neutral on the raw
* metric name by design — the enum is the stable, language-independent anchor a
* clinician reads alongside the numbers; no per-type i18n bundle is maintained.
*/
function humaniseType(type: string): string {
const lower = type.replace(/_/g, " ").toLowerCase();
return lower.charAt(0).toUpperCase() + lower.slice(1);
}
/** Render a single labelled stat row. */
function StatRow({
label,
value,
}: {
label: string;
value: string;
}) {
return (
<div className="flex items-baseline justify-between gap-4 border-b border-border/40 py-2 last:border-0">
<span className="text-sm text-muted-foreground">{label}</span>
<span className="text-sm font-medium tabular-nums">{value}</span>
</div>
);
}
function Section({
title,
children,
}: {
title: string;
children: React.ReactNode;
}) {
return (
<section className="rounded-lg border border-border bg-card p-5">
<h2 className="mb-3 text-base font-semibold">{title}</h2>
{children}
</section>
);
}
export function ClinicianView({
t,
label,
expiresAt,
report,
sections,
}: ClinicianViewProps) {
const fmtDate = (iso: string) => new Date(iso).toLocaleDateString();
const fmtNum = (n: number) => Math.round(n * 100) / 100;
// Measurement series with at least one stat, mapped to their stats row.
const measurementEntries = Object.entries(report.stats).filter(
([, s]) => s.count > 0,
);
const glucoseEntries = Object.entries(report.glucoseStats).filter(
([, s]) => s.count > 0,
);
const complianceEntries = sections.compliance
? Object.entries(report.compliance).filter(([, c]) => c.total > 0)
: [];
const wellness =
report.wellnessScores?.filter((s) => s.count > 0) ?? [];
return (
<main
id="main-content"
className="mx-auto min-h-dvh w-full max-w-3xl px-4 py-8"
>
{/* ── Provenance header ───────────────────────────────────────── */}
<header className="mb-6">
<h1 className="text-2xl font-bold tracking-tight">
{t("clinicianView.title")}
</h1>
{label ? (
<p className="mt-1 text-sm text-muted-foreground">{label}</p>
) : null}
<p className="mt-3 text-sm text-muted-foreground">
{t("clinicianView.period", {
start: fmtDate(report.period.start),
end: fmtDate(report.period.end),
})}
</p>
<p className="mt-1 text-xs text-muted-foreground">
{t("clinicianView.expires", { date: fmtDate(expiresAt) })}
</p>
<p className="mt-3 rounded-md border border-border bg-muted/40 p-3 text-xs text-muted-foreground">
{t("clinicianView.provenance")}
</p>
</header>
<div className="space-y-5">
{/* ── Clinical vitals ─────────────────────────────────────── */}
{measurementEntries.length > 0 ? (
<Section title={t("clinicianView.vitals")}>
{measurementEntries.map(([type, s]) => (
<StatRow
key={type}
label={humaniseType(type)}
value={t("clinicianView.statSummary", {
latest: fmtNum(s.latest),
avg: fmtNum(s.avg),
min: fmtNum(s.min),
max: fmtNum(s.max),
})}
/>
))}
{report.bmi !== null && report.bmi !== undefined && sections.bmi ? (
<StatRow
label={t("clinicianView.bmi")}
value={String(fmtNum(report.bmi))}
/>
) : null}
</Section>
) : null}
{/* ── Labs (glucose) ──────────────────────────────────────── */}
{glucoseEntries.length > 0 ? (
<Section title={t("clinicianView.labs")}>
{glucoseEntries.map(([ctx, s]) => (
<StatRow
key={ctx}
label={t(`clinicianView.glucose.${ctx}`)}
value={t("clinicianView.statSummary", {
latest: fmtNum(s.latest),
avg: fmtNum(s.avg),
min: fmtNum(s.min),
max: fmtNum(s.max),
})}
/>
))}
</Section>
) : null}
{/* ── Medications + adherence ─────────────────────────────── */}
{report.medications.length > 0 ? (
<Section title={t("clinicianView.medications")}>
{report.medications.map((med) => {
const comp = report.compliance[med.name];
const rate =
sections.compliance && comp && comp.total > 0
? `${Math.round((comp.taken / comp.total) * 100)}%`
: null;
return (
<StatRow
key={med.name}
label={med.dose ? `${med.name} — ${med.dose}` : med.name}
value={
rate
? t("clinicianView.adherence", { rate })
: t("clinicianView.noAdherence")
}
/>
);
})}
{complianceEntries
.filter(
([name]) => !report.medications.some((m) => m.name === name),
)
.map(([name, c]) => (
<StatRow
key={name}
label={name}
value={t("clinicianView.adherence", {
rate: `${Math.round((c.taken / c.total) * 100)}%`,
})}
/>
))}
</Section>
) : null}
{/* ── Fenced wellness card (descriptive, NOT clinical) ────── */}
{wellness.length > 0 ? (
<section className="rounded-lg border border-dashed border-amber-500/50 bg-amber-500/5 p-5">
<h2 className="mb-1 text-base font-semibold text-muted-foreground">
{t("clinicianView.wellness.title")}
</h2>
<p className="mb-3 text-xs text-muted-foreground">
{t("clinicianView.wellness.disclaimer")}
</p>
<div>
{wellness.map((s) => (
<StatRow
key={s.type}
label={t(
`clinicianView.wellness.${WELLNESS_KEY[s.type] ?? "score"}`,
)}
value={t("clinicianView.statSummary", {
latest: fmtNum(s.latest),
avg: fmtNum(s.avg),
min: fmtNum(s.min),
max: fmtNum(s.max),
})}
/>
))}
</div>
</section>
) : null}
</div>
<footer className="mt-8 border-t border-border pt-4 text-center text-xs text-muted-foreground">
{t("clinicianView.footer")}
</footer>
</main>
);
}
+10 -1
View File
@@ -25,6 +25,11 @@ const PUBLIC_PATHS = [
"/auth/register",
"/privacy",
"/about",
// v1.11.0 — the public clinician view renders its own standalone chrome
// (no nav / coach / auth gate). Listed here so the shell hands it through
// bare; the route is also in `proxy.ts` PUBLIC_PATHS so it never round-trips
// the sign-in redirect.
"/c/",
];
export function AuthShell({ children }: { children: React.ReactNode }) {
@@ -41,8 +46,12 @@ export function AuthShell({ children }: { children: React.ReactNode }) {
// auth gate above.
// v1.4.27 MB6 — `/about` follows the same shape (own header, own
// footer, full-width body), so it joins the standalone list.
// v1.11.0 — the clinician view (`/c/*`) renders edge-to-edge with its own
// standalone chrome and no app shell, like the legal pages.
const isStandalonePublicPage =
pathname.startsWith("/privacy") || pathname.startsWith("/about");
pathname.startsWith("/privacy") ||
pathname.startsWith("/about") ||
pathname.startsWith("/c/");
const isAdminPage = pathname.startsWith("/admin");
const isOnboardingPage = pathname === "/onboarding";
const showUnlockNotifier = isAuthenticated && !isPublicPage && !!user?.id;