mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
feat(vaccinations): show the planned booster's renewal state on the log
Whether a vaccination is still current was known only on the checkups page. The vaccination log now shows it on each antigen's heading: the booster the person planned when they logged a dose, marked as overdue, due soon (within 30 days) or scheduled, tinted only in the first two cases. The state is resolved on the server from the person's own confirmed booster reminder and published on the list response as renewals, so the web page and the native client read the same answer. Nothing is worked out from age, history or the catalogue: an antigen without a planned booster shows no state. Renewals are null for a grant that does not reach the measurements section the reminders live in. Refs #1005
This commit is contained in:
1 parent
b480ac4543
commit
15d6251ad2
17 files changed
+672
-15
No files matched your search
@@ -133,3 +133,111 @@ describe("VaccinationList grouping", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("VaccinationList renewal state (#1005)", () => {
|
||||
const tdap = record({
|
||||
id: "tdap-1",
|
||||
antigenSlug: "tdap",
|
||||
catalogEntry: { slug: "tdap", atc: "J07AJ52", category: "standard" },
|
||||
series: [
|
||||
{ antigen: "tetanus", position: 3, total: 3, booster: false },
|
||||
{ antigen: "pertussis", position: 1, total: 3, booster: false },
|
||||
],
|
||||
});
|
||||
|
||||
function renderWith(
|
||||
renewals: Parameters<typeof VaccinationList>[0]["renewals"],
|
||||
): string {
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
<VaccinationList records={[tdap]} renewals={renewals} />
|
||||
</I18nProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
it("marks an overdue booster on its antigen's heading, and only there", () => {
|
||||
const html = renderWith([
|
||||
{
|
||||
antigen: "tetanus",
|
||||
reminderId: "rem-1",
|
||||
dueAt: "2026-01-10T09:00:00.000Z",
|
||||
daysUntil: -30,
|
||||
state: "overdue",
|
||||
},
|
||||
]);
|
||||
expect(html.match(/data-slot="vaccination-renewal"/g)).toHaveLength(1);
|
||||
expect(html).toContain('data-state="overdue"');
|
||||
expect(html).toContain("Booster overdue since");
|
||||
expect(html).toContain("text-warning");
|
||||
// It sits inside the tetanus group, not the pertussis one.
|
||||
const tetanusGroup = html.slice(
|
||||
html.indexOf('data-antigen="tetanus"'),
|
||||
html.indexOf('data-antigen="pertussis"') >
|
||||
html.indexOf('data-antigen="tetanus"')
|
||||
? html.indexOf('data-antigen="pertussis"')
|
||||
: undefined,
|
||||
);
|
||||
expect(tetanusGroup).toContain('data-slot="vaccination-renewal"');
|
||||
});
|
||||
|
||||
it("tints a booster that is due soon and leaves a distant one as plain meta", () => {
|
||||
const soon = renderWith([
|
||||
{
|
||||
antigen: "tetanus",
|
||||
reminderId: "rem-1",
|
||||
dueAt: "2026-10-10T09:00:00.000Z",
|
||||
daysUntil: 16,
|
||||
state: "dueSoon",
|
||||
},
|
||||
]);
|
||||
expect(soon).toContain("Booster due");
|
||||
expect(soon).toContain("text-info");
|
||||
const later = renderWith([
|
||||
{
|
||||
antigen: "tetanus",
|
||||
reminderId: "rem-1",
|
||||
dueAt: "2034-10-10T09:00:00.000Z",
|
||||
daysUntil: 2900,
|
||||
state: "current",
|
||||
},
|
||||
]);
|
||||
expect(later).toContain("Next booster");
|
||||
expect(later).not.toContain("text-warning");
|
||||
expect(later).not.toContain("text-info");
|
||||
});
|
||||
|
||||
it("gives each antigen its own renewal when several are planned", () => {
|
||||
const html = renderWith([
|
||||
{
|
||||
antigen: "pertussis",
|
||||
reminderId: "rem-p",
|
||||
dueAt: "2034-10-10T09:00:00.000Z",
|
||||
daysUntil: 2900,
|
||||
state: "current",
|
||||
},
|
||||
{
|
||||
antigen: "tetanus",
|
||||
reminderId: "rem-t",
|
||||
dueAt: "2026-01-10T09:00:00.000Z",
|
||||
daysUntil: -30,
|
||||
state: "overdue",
|
||||
},
|
||||
]);
|
||||
const pertussisAt = html.indexOf('data-antigen="pertussis"');
|
||||
const tetanusAt = html.indexOf('data-antigen="tetanus"');
|
||||
const [first, second] =
|
||||
pertussisAt < tetanusAt
|
||||
? [html.slice(pertussisAt, tetanusAt), html.slice(tetanusAt)]
|
||||
: [html.slice(tetanusAt, pertussisAt), html.slice(pertussisAt)];
|
||||
const pertussis = pertussisAt < tetanusAt ? first : second;
|
||||
const tetanus = pertussisAt < tetanusAt ? second : first;
|
||||
expect(pertussis).toContain('data-state="current"');
|
||||
expect(pertussis).not.toContain('data-state="overdue"');
|
||||
expect(tetanus).toContain('data-state="overdue"');
|
||||
});
|
||||
|
||||
it("shows nothing when there is no renewal or the grant withholds it", () => {
|
||||
expect(renderWith([])).not.toContain("vaccination-renewal");
|
||||
expect(renderWith(null)).not.toContain("vaccination-renewal");
|
||||
});
|
||||
});
|
||||
@@ -18,19 +18,25 @@
|
||||
* `vaccineName` instead — the degrade the DTO's `catalogEntry: null` signals,
|
||||
* now visible.
|
||||
*
|
||||
* ── Neutral, retrospective ─────────────────────────────────────────────────
|
||||
* ── Neutral, retrospective — and the booster the person planned ───────────
|
||||
*
|
||||
* No due status anywhere on this page. A booster the user set shows on
|
||||
* `/checkups` like every other reminder; this surface reproduces the record
|
||||
* and does not adjudicate it. Cards are neutral — content in foreground, meta
|
||||
* in muted, no tint.
|
||||
* The page reproduces the record and does not adjudicate it: nothing here
|
||||
* works out what a person is due from their age or history. The one status it
|
||||
* shows is the booster the person confirmed themselves — the reminder planned
|
||||
* when a dose was logged — resolved server-side into a renewal state
|
||||
* (`src/lib/vaccinations/renewal.ts`) and rendered on the antigen's heading,
|
||||
* tinted only when it has passed or is close. Dose cards stay neutral —
|
||||
* content in foreground, meta in muted, no tint.
|
||||
*/
|
||||
import { Syringe } from "lucide-react";
|
||||
import { AlarmClock, Syringe } from "lucide-react";
|
||||
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { InfoPopover } from "@/components/ui/info-popover";
|
||||
import { useFormatters, useTranslations } from "@/lib/i18n/context";
|
||||
import type { SeriesPosition } from "@/lib/vaccinations/series";
|
||||
import type { VaccinationRenewalDTO } from "@/lib/vaccinations/renewal";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { Vaccination } from "./use-vaccinations";
|
||||
import { CatalogInfo, catalogInfoAvailable } from "./catalog-info";
|
||||
|
||||
@@ -208,15 +214,56 @@ function DoseRow({
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The booster the person planned for this antigen, on its heading. Overdue
|
||||
* and due-soon are tinted so they are seen at a glance; a booster years away
|
||||
* reads as plain meta. Composed from the server's resolved state — the client
|
||||
* never compares dates itself.
|
||||
*/
|
||||
function RenewalBadge({ renewal }: { renewal: VaccinationRenewalDTO }) {
|
||||
const { t } = useTranslations();
|
||||
const format = useFormatters();
|
||||
const date = format.date(renewal.dueAt);
|
||||
const text =
|
||||
renewal.state === "overdue"
|
||||
? t("vaccinations.renewal.overdue", { date })
|
||||
: renewal.state === "dueSoon"
|
||||
? t("vaccinations.renewal.dueSoon", { date })
|
||||
: t("vaccinations.renewal.current", { date });
|
||||
const tone =
|
||||
renewal.state === "overdue"
|
||||
? "border-warning/30 bg-warning/10 text-warning"
|
||||
: renewal.state === "dueSoon"
|
||||
? "border-info/30 bg-info/10 text-info"
|
||||
: "text-muted-foreground";
|
||||
return (
|
||||
<Badge
|
||||
variant="outline"
|
||||
data-slot="vaccination-renewal"
|
||||
data-state={renewal.state}
|
||||
className={cn("tracking-normal normal-case", tone)}
|
||||
>
|
||||
<AlarmClock aria-hidden />
|
||||
{text}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
export function VaccinationList({
|
||||
records,
|
||||
renewals,
|
||||
onEdit,
|
||||
}: {
|
||||
records: readonly Vaccination[];
|
||||
/** Resolved per antigen by the server; null when the grant withholds them. */
|
||||
renewals?: readonly VaccinationRenewalDTO[] | null;
|
||||
onEdit?: (record: Vaccination) => void;
|
||||
}) {
|
||||
const { t } = useTranslations();
|
||||
const groups = groupByAntigen(records);
|
||||
const renewalByAntigen = new Map(
|
||||
(renewals ?? []).map((renewal) => [renewal.antigen, renewal]),
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -227,7 +274,7 @@ export function VaccinationList({
|
||||
data-slot="vaccination-group"
|
||||
data-antigen={group.antigen ?? "free"}
|
||||
>
|
||||
<h2 className="text-muted-foreground flex items-center gap-2 text-xs font-medium tracking-wide uppercase">
|
||||
<h2 className="text-muted-foreground flex flex-wrap items-center gap-2 text-xs font-medium tracking-wide uppercase">
|
||||
<Syringe className="size-3.5" aria-hidden />
|
||||
{group.antigen
|
||||
? t(`vaccinations.catalog.${group.antigen}`)
|
||||
@@ -241,6 +288,9 @@ export function VaccinationList({
|
||||
triggerDataSlot="vaccination-info-trigger"
|
||||
/>
|
||||
) : null}
|
||||
{group.antigen && renewalByAntigen.has(group.antigen) ? (
|
||||
<RenewalBadge renewal={renewalByAntigen.get(group.antigen)!} />
|
||||
) : null}
|
||||
</h2>
|
||||
<div className="space-y-2">
|
||||
{group.rows.map((row, index) => (
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
* doses by their component antigen and shows where each series stands, with the
|
||||
* numbers resolved server-side (`src/lib/vaccinations/series.ts`) so this
|
||||
* client never re-derives "N von M". Neutral cards, status through a discreet
|
||||
* badge only — no red card, no overdue tint. It reproduces the record; it does
|
||||
* not adjudicate what is due.
|
||||
* badge only — no red card. It reproduces the record; it does not adjudicate
|
||||
* what is due. The one status shown is the booster the person planned, on the
|
||||
* antigen's heading (see `vaccination-list.tsx`).
|
||||
*/
|
||||
import { useState } from "react";
|
||||
import { Plus, Syringe } from "lucide-react";
|
||||
@@ -121,6 +122,7 @@ export function VaccinationsView() {
|
||||
) : records.length > 0 ? (
|
||||
<VaccinationList
|
||||
records={records}
|
||||
renewals={data?.renewals}
|
||||
onEdit={canManageProfile ? openEdit : undefined}
|
||||
/>
|
||||
) : (
|
||||
|
||||
Reference in new issue
Block a user