mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 06:06:10 +00:00
fix(visits): cap the window before a visit at the longest report
The window before a booked visit started at the last matching visit however far back it lay, while the health-report export covers 730 days and fell back to its 90-day default for anything longer. The card then offered a report the export did not build. The window now stops at the export's limit, read from one shared constant, and preparation.capped says when it did; the web says "The last two years" for it. The export clamps an over-long explicit range to the last 730 days before its end instead of falling back to 90 days, so a custom range or a linked window cannot shrink silently either, and its day count forgives the hour a clock change adds, so two years of local days count as 730.
This commit is contained in:
1 parent
f39598f2e7
commit
da3d29424d
22 files changed
+282
-32
No files matched your search
@@ -197,6 +197,7 @@ describe("<VisitsSection> since the last visit", () => {
|
||||
to: "2026-12-01",
|
||||
basis: "practitioner",
|
||||
since: sameDoctor,
|
||||
capped: false,
|
||||
},
|
||||
});
|
||||
const unprepared = visit({ ...next, preparation: null });
|
||||
@@ -346,6 +347,7 @@ describe("<VisitsSection> since the last visit", () => {
|
||||
to: "2026-12-01",
|
||||
basis: "default",
|
||||
since: null,
|
||||
capped: false,
|
||||
},
|
||||
}),
|
||||
],
|
||||
|
||||
@@ -22,7 +22,10 @@ type Translate = (
|
||||
export interface PreparationText {
|
||||
/** Where the window starts: "Since your last visit with … on …". */
|
||||
title: string;
|
||||
/** Why, when the title alone does not say: only on the default window. */
|
||||
/**
|
||||
* Why, when the title alone does not say: on the default window, and on a
|
||||
* window capped at the longest report.
|
||||
*/
|
||||
reason: string | null;
|
||||
}
|
||||
|
||||
@@ -33,6 +36,14 @@ export function preparationText(
|
||||
): PreparationText {
|
||||
const date = formatDay(preparation.from);
|
||||
const since = preparation.since;
|
||||
// The matched visit is further back than a report covers: the window is
|
||||
// the last two years, and the title must not promise everything since.
|
||||
if (preparation.capped) {
|
||||
return {
|
||||
title: t("encounters.preparation.capped"),
|
||||
reason: t("encounters.preparation.cappedReason"),
|
||||
};
|
||||
}
|
||||
switch (preparation.basis) {
|
||||
case "practitioner":
|
||||
return {
|
||||
|
||||
@@ -127,6 +127,7 @@ describe("<ReportVisitOffer>", () => {
|
||||
practitionerName: "Former skin practice",
|
||||
specialty: "Dermatology",
|
||||
},
|
||||
capped: false,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
@@ -144,6 +145,7 @@ describe("<ReportVisitOffer>", () => {
|
||||
to: "2026-12-01",
|
||||
basis: "default",
|
||||
since: null,
|
||||
capped: false,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
@@ -153,6 +155,31 @@ describe("<ReportVisitOffer>", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("says the last two years on a window capped at the longest report", () => {
|
||||
const html = render([
|
||||
visit({
|
||||
id: "derm",
|
||||
preparation: {
|
||||
from: "2024-12-02",
|
||||
to: "2026-12-01",
|
||||
basis: "practitioner",
|
||||
since: {
|
||||
id: "old-derm",
|
||||
occurredAt: "2022-03-02T09:00:00.000Z",
|
||||
kind: "SPECIALIST",
|
||||
practitionerName: "Skin practice",
|
||||
specialty: "Dermatology",
|
||||
},
|
||||
capped: true,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
expect(html).toContain("The last two years");
|
||||
expect(html).toContain("a report covers two years at most");
|
||||
// Not "since your last visit", which would promise the whole stretch.
|
||||
expect(html).not.toContain("Since your last visit");
|
||||
});
|
||||
|
||||
it("applies the server's start and the appointment's day on a press", () => {
|
||||
const at = new Date(Date.now() + 5 * DAY_MS);
|
||||
const window = visitReportWindow(
|
||||
@@ -164,6 +191,7 @@ describe("<ReportVisitOffer>", () => {
|
||||
to: "2026-12-01",
|
||||
basis: "default",
|
||||
since: null,
|
||||
capped: false,
|
||||
},
|
||||
}),
|
||||
"Europe/Berlin",
|
||||
@@ -188,6 +216,7 @@ describe("<ReportVisitOffer>", () => {
|
||||
to: "2026-11-12",
|
||||
basis: "default",
|
||||
since: null,
|
||||
capped: false,
|
||||
},
|
||||
});
|
||||
expect(visitReportWindow(early, "America/New_York")).toEqual({
|
||||
|
||||
Reference in new issue
Block a user