Files
CatoandClaude 141f60e88c feat(charts): trends, check-in strip and meters on @bitbaum/chartkit 0.7 (#138)
ChartKit 0.7.0 closes the three gaps recorded in package-plan.json
(#136): LineChart labels days on short spans, Sparkline takes per-point
tones and null gaps, and Meter takes a tone and showValue={false}.

- CheckinTrendChart and AssessmentTrendChart render ChartKit's
  LineChart on the server, dated by ISO day in the app's en-GB locale.
  Callers pass the day instead of a pre-formatted label, and the
  assessments page drops its client wrapper.
- The patients table's 7-day strip is a Sparkline: one point a day,
  toned by wellness level (SPARK_LEVEL_TONES), a gap on a day without a
  check-in, and the counts in its accessible name.
- Dimension score bars (/assessments, the public results overlay) and
  the reports adherence bars are toned Meters; scoreColor becomes
  scoreTone. The overlay sets --ck-line to its own hairline.
- --ck-series-4 maps to the gold: it defaulted to --ck-up, the same
  teal as the accent, so Energy and Focus drew in one colour.
- recharts, the metric colour field, --purple and the bar/dot CSS are
  removed; the design gate's allowlist drops the three files that no
  longer need a style prop. All three exceptions leave package-plan.json.


Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-29 20:06:50 +01:00

80 lines
2.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Admin signal thresholds — SSOT, no magic numbers in page files
import { CHECKIN_METRICS, type MetricKey } from "@/lib/config/portal";
/** Days since last check-in before patient is marked critical (has prior check-in history) */
export const NO_CHECKIN_CRITICAL_DAYS = 5;
/** Assessment score must drop by MORE THAN this many points to trigger critical signal (strict >, not >=) */
export const SCORE_DROP_CRITICAL = 10;
/** Days after registration where no activity is expected (new patient grace period) */
export const NEW_PATIENT_GRACE_DAYS = 3;
/** Days after an attended consultation before a follow-up booking is flagged as needed */
export const ATTENDED_FOLLOW_UP_DAYS = 30;
/** Days of check-in history to fetch for sparkline and signal computation */
export const SIGNAL_CHECKIN_WINDOW_DAYS = 7;
export const PATIENT_SIGNAL_VALUES = ["critical", "attention", "active", "new"] as const;
export type PatientSignal = (typeof PATIENT_SIGNAL_VALUES)[number];
/** Named constants for patient signal values — use in comparisons instead of string literals */
export const PATIENT_SIGNAL = {
critical: "critical",
attention: "attention",
active: "active",
new: "new",
} as const satisfies Record<PatientSignal, PatientSignal>;
/** Check-in metric keys that can be linked to clinical goals — derived from CHECKIN_METRICS SSOT */
export const CHECKIN_GOAL_METRICS = CHECKIN_METRICS.map((m) => m.key);
export type CheckinGoalMetric = MetricKey;
/** Sort order for signal severity — lower = shown first */
export const SIGNAL_SORT_ORDER: Record<PatientSignal, number> = {
critical: 0,
attention: 1,
active: 2,
new: 3,
};
export const SIGNAL_LABELS: Record<PatientSignal, string> = {
critical: "Critical",
attention: "Attention",
active: "Active",
new: "New",
};
/** Average check-in wellbeing score (mood+energy+sleep, 1–5) below which a dip is flagged */
export const CHECKIN_DIP_ALERT_THRESHOLD = 2.5;
/** Number of consecutive days at or below the threshold before Manuel is alerted */
export const CHECKIN_DIP_ALERT_DAYS = 3;
/** Wellness sparkline level thresholds (avg of 5 metrics, 1–5 scale) */
export const SPARKLINE_LOW_THRESHOLD = 2.5;
export const SPARKLINE_MID_THRESHOLD = 3.5;
/** A ChartKit bar tone: drawn in --ck-down / --ck-warning / --ck-up (globals.css). */
export type ChartTone = "positive" | "warning" | "negative";
/** Chart tone for each signal severity — SSOT for signal colour in charts. `new` has none: neutral ink. */
export const SIGNAL_TONES: Record<PatientSignal, ChartTone | undefined> = {
critical: "negative",
attention: "warning",
active: "positive",
new: undefined,
};
/** A day's wellness level in the patients table's check-in sparkline. */
export type SparkLevel = "low" | "mid" | "high";
/** Sparkline dot tone for each wellness level — the same scale as the signal tones. */
export const SPARK_LEVEL_TONES: Record<SparkLevel, ChartTone> = {
low: "negative",
mid: "warning",
high: "positive",
};