// ============================================================ // Visit-status helpers — pure functions used by the WellVisit // "By Visit Age" pane to map AAP visit IDs onto growth/reflex // reference keys, color-code reflex chips, and read tri-state // status values out of the localStorage cache. // // Mirrors public/js/wellVisit.js (@be14578) getGrowthDataForVisit / // getReflexDataForVisit / reflexStatusColor. Lives in shared/ so // the root vitest config can pick the tests up. // ============================================================ export type VisitStatusVal = string | { status: string; note: string }; // Map a visit ID (e.g. "7y") to its GROWTH_REFERENCE key (e.g. "6y_to_10y"). // Returns null when no match — caller should hide the growth section. export function mapToGrowthKey(visitId: string, refs: Record): string | null { if (refs[visitId]) return visitId; const m: Record = { 'newborn': 'newborn', '3-5d': 'newborn', '1mo': '1mo', '2mo': '2mo', '4mo': '4mo', '6mo': '6mo', '9mo': '9mo', '12mo': '12mo', '15mo': '15mo', '18mo': '18mo', '24mo': '24mo', '30mo': '30mo', '3y': '3y', '4y': '4y', '5y': '5y', '6y': '6y_to_10y', '7y': '6y_to_10y', '8y': '6y_to_10y', '9y': '6y_to_10y', '10y': '6y_to_10y', '11y': '11y_to_14y', '12y': '11y_to_14y', '13y': '11y_to_14y', '14y': '11y_to_14y', '15y': '15y_to_21y', '16y': '15y_to_21y', '17y': '15y_to_21y', '18y': '15y_to_21y', '19y': '15y_to_21y', '20y': '15y_to_21y', '21y': '15y_to_21y', }; const k = m[visitId]; return k && refs[k] ? k : null; } // REFLEXES_REFERENCE shares 3y..5y, not split by year — see vanilla. export function mapToReflexKey(visitId: string, refs: Record): string | null { if (refs[visitId]) return visitId; const m: Record = { 'newborn': 'newborn', '3-5d': 'newborn', '1mo': '1mo', '2mo': '2mo', '4mo': '4mo', '6mo': '6mo', '9mo': '9mo', '12mo': '12mo', '15mo': '15mo', '18mo': '18mo', '24mo': '24mo', '30mo': '30mo', '3y': '3y_to_5y', '4y': '3y_to_5y', '5y': '3y_to_5y', '6y': '6y_to_10y', '7y': '6y_to_10y', '8y': '6y_to_10y', '9y': '6y_to_10y', '10y': '6y_to_10y', '11y': '11y_to_14y', '12y': '11y_to_14y', '13y': '11y_to_14y', '14y': '11y_to_14y', '15y': '15y_to_21y', '16y': '15y_to_21y', '17y': '15y_to_21y', '18y': '15y_to_21y', '19y': '15y_to_21y', '20y': '15y_to_21y', '21y': '15y_to_21y', }; const k = m[visitId]; return k && refs[k] ? k : null; } // Color a reflex status chip. Greens = expected resolved/lifelong state, // blues = present and expected, purple = emerging, ambers = transitional, // slate = unspecified. Mirrors reflexStatusColor() exactly. export function reflexStatusColor(status: string): string { const s = (status || '').toLowerCase(); if (s.includes('absent / integrated') || s === 'absent' || s.includes('integrated')) return '#059669'; if (s.includes('present') && s.includes('lifelong')) return '#059669'; if (s.includes('present')) return '#2563eb'; if (s.includes('peak')) return '#2563eb'; if (s.includes('emerging')) return '#7c3aed'; if (s.includes('fading') || s.includes('transition')) return '#d97706'; if (s.includes('down-going')) return '#059669'; if (s.includes('up-going')) return '#d97706'; if (s.includes('2+')) return '#2563eb'; return '#475569'; } // A visit-status value can be a bare string (legacy) or { status, note }. export function getStatusValue(s: VisitStatusVal | undefined): string { if (!s) return ''; return typeof s === 'object' ? s.status : s; } // SSHADESS sub-tab visibility — vanilla shows it only for these visits. export const SSHADESS_VISITS: ReadonlyArray = [ '12y','13y','14y','15y','16y','17y','18y','19y','20y','21y', ]; export function isSshadessVisit(visitId: string): boolean { return SSHADESS_VISITS.includes(visitId); }