mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 13:22:14 +00:00
Largest feature delta in the v1.4.x line. Insights expands into seven dedicated metric sub-pages; GLP-1 medication tracking lands end-to-end (drug-level chart with Research Mode acknowledgment, EMA titration ladder, cadence + compliance, side-effect taxonomy, pen/vial inventory); cross-source priority becomes a two-axis resolver; per-user timezone threads through ten analytics surfaces; Withings activity + sleep v2 sync; onboarding rebuilt as a nested-route wizard; Personal Records ship end-to-end; Health Score provenance accordion; Coach runs native first-party prompts across six locales with a 1800-assertion refusal-probe matrix; OpenAPI drift gate hard-fails; multi-arch GHCR image. Migrations 0043 through 0060 are additive and forward-only. PROMPT_VERSION 4.24.0 → 4.25.0 with GROUND RULE 9 (refuses dose recommendations) and GROUND RULE 15 (refuses drug-level estimates with MDR + MDCG 2021-24 cites). See CHANGELOG.md for the full per-section delta.
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
/**
|
|
* v1.4.25 W21 Fix-N — unified dose-string → mg parser.
|
|
*
|
|
* Replaces two near-identical helpers previously hand-rolled inside
|
|
* `<DrugLevelChart>` (`parseDoseMg`) and the titration route
|
|
* (`parseDoseString`). The DrugLevelChart variant returned `NaN` for
|
|
* unparseable strings; the titration variant returned `null`. Both
|
|
* code paths now go through this module — the legacy null-returning
|
|
* shape is preserved as `parseDoseMgOrNull` so the titration route
|
|
* keeps its "no current step" semantics.
|
|
*
|
|
* Accepts comma OR dot as decimal separator (Marc-memory: the German
|
|
* UI lets the user type "0,25 mg"). Trailing unit text after the
|
|
* number is ignored — the parser only owns the numeric extraction.
|
|
*/
|
|
|
|
/**
|
|
* Parse a dose string like "7.5 mg" → 7.5 or "0,25" → 0.25. Returns
|
|
* `NaN` when the string carries no recognisable number (e.g. "as
|
|
* needed") so callers can use `Number.isFinite` for the gate.
|
|
*/
|
|
export function parseDoseMg(input: string): number {
|
|
if (!input) return Number.NaN;
|
|
const match = input.match(/([0-9]+(?:[.,][0-9]+)?)/);
|
|
if (!match) return Number.NaN;
|
|
return Number.parseFloat(match[1].replace(",", "."));
|
|
}
|
|
|
|
/**
|
|
* Same as `parseDoseMg` but returns `null` instead of `NaN` for the
|
|
* unparseable case. The titration route reads this as "no current
|
|
* step" — null signals "we couldn't resolve a dose" rather than "the
|
|
* dose is zero".
|
|
*/
|
|
export function parseDoseMgOrNull(input: string): number | null {
|
|
const value = parseDoseMg(input);
|
|
return Number.isFinite(value) ? value : null;
|
|
}
|