mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
Both surfaces read the start of their window from `preparation` and say why it starts there: "Since your last visit with <practice> on <date>", "Since your last <specialty> visit on <date>", "Since your last visit of the same kind (<kind>) on <date>", or "The last 90 days" with the reason that no earlier visit matched. The visits tab no longer picks the last visit of any kind from the past list. The report panel's appointment offer now sets both dates, the start from the server and the end on the appointment's day, instead of the end alone beside whatever start the panel held. Both stay editable.
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
/**
|
|
* The window before a booked visit, in words: the line that says where the
|
|
* visit preparation and the offered doctor report start, and why there.
|
|
*
|
|
* Spells only what the server resolved (`EncounterDTO.preparation`); nothing
|
|
* here chooses a date. One spelling for both surfaces that show it, so the
|
|
* visits tab and the report panel cannot give two reasons for one window.
|
|
*/
|
|
import type { EncounterKind } from "@/generated/prisma/client";
|
|
import {
|
|
PREPARATION_DEFAULT_DAYS,
|
|
type EncounterPreparationDTO,
|
|
} from "@/lib/encounters/preparation";
|
|
|
|
import { encounterKindText } from "./encounter-labels";
|
|
|
|
type Translate = (
|
|
key: string,
|
|
params?: Record<string, string | number>,
|
|
) => string;
|
|
|
|
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. */
|
|
reason: string | null;
|
|
}
|
|
|
|
export function preparationText(
|
|
t: Translate,
|
|
formatDay: (day: string) => string,
|
|
preparation: EncounterPreparationDTO,
|
|
): PreparationText {
|
|
const date = formatDay(preparation.from);
|
|
const since = preparation.since;
|
|
switch (preparation.basis) {
|
|
case "practitioner":
|
|
return {
|
|
title: t("encounters.preparation.practitioner", {
|
|
name: since?.practitionerName ?? "",
|
|
date,
|
|
}),
|
|
reason: null,
|
|
};
|
|
case "specialty":
|
|
return {
|
|
title: t("encounters.preparation.specialty", {
|
|
specialty: since?.specialty ?? "",
|
|
date,
|
|
}),
|
|
reason: null,
|
|
};
|
|
case "kind":
|
|
return {
|
|
title: t("encounters.preparation.kind", {
|
|
kind: since ? encounterKindText(t, since.kind as EncounterKind) : "",
|
|
date,
|
|
}),
|
|
reason: null,
|
|
};
|
|
case "default":
|
|
return {
|
|
title: t("encounters.preparation.default", {
|
|
days: PREPARATION_DEFAULT_DAYS,
|
|
}),
|
|
reason: t("encounters.preparation.defaultReason"),
|
|
};
|
|
}
|
|
}
|