mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 14:16:12 +00:00
fix(insights): show small lab changes and print them like the labs page
"What changed since your last panel" rounded every delta to two decimals, so TSH 0.004 to 0.009 read "no change", and it printed values and deltas through `String()`: a full stop in every language and every digit of a unit conversion (41.999198717948715 ng/mL). The summary now reads each reading at the precision it was recorded at (`recordedPrecision`, with the report's printed figure for a converted value, which the route now selects) and rounds the delta to the finer of the two, so its direction agrees with the printed figures. The card prints both through `useLabNumber()`. 5.9 - 5.6 still comes out as 0.3, so the existing marker-pairing test stands as it was.
This commit is contained in:
1 parent
9d7c99e60c
commit
2c7a0dc3c2
5 files changed
+148
-8
No files matched your search
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* The card prints a lab figure the way the labs page does: in the reader's
|
||||
* notation and with the digits the reading holds. It used to print
|
||||
* `String(value)`, so a German reader saw "4.6" beside a labs page that says
|
||||
* "4,6", and a converted reading showed every digit of the conversion.
|
||||
*/
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
vi.mock("@tanstack/react-query", () => ({
|
||||
useQuery: () => ({
|
||||
data: {
|
||||
present: true,
|
||||
latestDate: "2026-06-01",
|
||||
previousDate: "2026-03-01",
|
||||
generatedAt: "2026-06-02T00:00:00.000Z",
|
||||
changes: [
|
||||
{
|
||||
analyte: "TSH",
|
||||
unit: "mIU/L",
|
||||
latest: 0.009,
|
||||
previous: 0.004,
|
||||
delta: 0.005,
|
||||
direction: "up",
|
||||
status: "unknown",
|
||||
},
|
||||
{
|
||||
analyte: "Potassium",
|
||||
unit: "mmol/L",
|
||||
latest: 4.6,
|
||||
previous: 4.9,
|
||||
delta: -0.3,
|
||||
direction: "down",
|
||||
status: "unknown",
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/hooks/use-auth", () => ({
|
||||
useAuth: () => ({ isAuthenticated: true }),
|
||||
}));
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { LabsChangesCard } from "../labs-changes-card";
|
||||
|
||||
describe("<LabsChangesCard>", () => {
|
||||
it("prints values and deltas in the reader's notation", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="de">
|
||||
<LabsChangesCard />
|
||||
</I18nProvider>,
|
||||
);
|
||||
expect(html).toContain("0,009 mIU/L");
|
||||
expect(html).toContain("+0,005 mIU/L");
|
||||
expect(html).toContain("4,6 mmol/L");
|
||||
expect(html).toContain("-0,3 mmol/L");
|
||||
});
|
||||
});
|
||||
@@ -12,6 +12,7 @@ import { SectionHeading } from "@/components/ui/section-heading";
|
||||
import type { LabChange } from "@/lib/insights/labs-changes";
|
||||
import { InsightSectionCard } from "./insight-section-card";
|
||||
import { withLabUnit } from "@/lib/labs/dimensionless";
|
||||
import { useLabNumber } from "@/components/labs/use-lab-format";
|
||||
|
||||
/**
|
||||
* v1.25 — "what changed since your last panel" card.
|
||||
@@ -55,6 +56,7 @@ export function LabsChangesCard({
|
||||
}: LabsChangesCardProps) {
|
||||
const { t } = useTranslations();
|
||||
const { isAuthenticated } = useAuth();
|
||||
const labNumber = useLabNumber();
|
||||
|
||||
const { data } = useQuery({
|
||||
queryKey: queryKeys.insightsLabsChanges(),
|
||||
@@ -82,7 +84,10 @@ export function LabsChangesCard({
|
||||
const signedDelta =
|
||||
c.direction === "flat"
|
||||
? t("insights.labsChanges.directionFlat")
|
||||
: withLabUnit(`${c.delta > 0 ? "+" : ""}${c.delta}`, c.unit);
|
||||
: withLabUnit(
|
||||
`${c.delta > 0 ? "+" : ""}${labNumber(c.delta)}`,
|
||||
c.unit,
|
||||
);
|
||||
return (
|
||||
<div
|
||||
key={c.analyte}
|
||||
@@ -94,7 +99,7 @@ export function LabsChangesCard({
|
||||
{c.analyte}
|
||||
</p>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{withLabUnit(String(c.latest), c.unit)}
|
||||
{withLabUnit(labNumber(c.latest), c.unit)}
|
||||
{labelKey ? ` · ${t(labelKey)}` : ""}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user