feat(report): name the analysed window of each medication effect

The effect is fitted on up to 90 days before a start and 180 after
it, which can lie outside the report period. The PDF notes and the
clinician view now state the fitted window for every effect shown.
This commit is contained in:
Marc-André Bombeck committed 2026-10-21 23:37:09 +02:00
1 parent cfe5e2d3c6
commit bb6982aea2
12 files changed
+84 -12

No files matched your search

@@ -200,6 +200,43 @@ describe("<ClinicianView>", () => {
],
});
const leaves = ["MEDICATION_EFFECT", "BLOOD_PRESSURE_SYS"] as const;
const est = {
estimate: -5,
ciLow: -7,
ciHigh: -3,
standardError: 1,
includesZero: false,
};
const fitted = makeReport({
medicationEffects: [
{
...report.medicationEffects![0],
targets: [
{
type: "BLOOD_PRESSURE_SYS",
effect: {
...report.medicationEffects![0].targets[0].effect,
present: true,
reason: undefined,
levelChange: est,
slopeChangePerWeek: est,
preSlopePerWeek: est,
window: {
from: "2025-10-07",
to: "2026-01-20",
endReason: "today",
},
},
},
],
},
],
});
expect(
render(fitted, {
selection: selectionFromLeaves([...leaves, "MEDICATION_LIST"]),
}),
).toContain("This window can reach beyond the report period.");
expect(
render(report, {
selection: selectionFromLeaves([...leaves, "MEDICATION_LIST"]),
@@ -163,6 +163,14 @@ export function MedicationEffectSection({
unit,
})}
</p>
{e.window ? (
<p className="text-muted-foreground text-xs">
{t("doctorReport.medicationEffect.windowLine", {
from: fmtDay(e.window.from),
to: fmtDay(e.window.to),
})}
</p>
) : null}
<p className="text-muted-foreground text-xs">
{t("doctorReport.medicationEffect.days", {
before: e.days.before,
@@ -217,6 +217,11 @@ describe("doctor report v1.44 sections", () => {
expect(text).toContain("-0.3 mmHg/week");
expect(text).toContain("84 / 61");
expect(text).toContain("5 days after the start left out");
// The fitted window (Dec to Apr) reaches outside the Feb to May report
// period; the report says which days the figures rest on.
expect(text).toMatch(
/analysed \S+ to \S+, which can reach beyond the report period/,
);
expect(text).toContain("Other drug started on");
expect(text).toContain("not a proven effect");
expect(text).not.toContain("carry-over");
@@ -213,7 +213,15 @@ export function buildMedicationEffectSection(
`${slope.value} ${unit}/${t("doctorReport.medicationEffect.week")}\n(${slope.low} ${t("doctorReport.medicationEffect.to")} ${slope.high})`,
`${e.days.before} / ${e.days.after}`,
]);
const extras: string[] = [];
// The fitted window reaches up to 90 days before the start and 180
// after it, so it can lie partly outside the report period: always
// say which days the figures rest on.
const extras: string[] = [
t("doctorReport.medicationEffect.window", {
from: dayLabel(fmtDate, e.window.from),
to: dayLabel(fmtDate, e.window.to),
}),
];
if (e.days.excludedLowAdherence > 0) {
extras.push(
t("doctorReport.medicationEffect.excludedAdherence", {
@@ -250,9 +258,7 @@ export function buildMedicationEffectSection(
}),
);
}
if (extras.length > 0) {
notes.push(`${med.medicationName}, ${label}: ${extras.join("; ")}.`);
}
notes.push(`${med.medicationName}, ${label}: ${extras.join("; ")}.`);
}
}
if (rows.length === 0) return state;