/** * - remembers which documentation tab (public / private) was open, per encounter. * * WHY. `EncounterDocumentation` held the selected tab in local `useState`, so any remount reset it to * Public. floating notes pane remounts this component three ways during a live visit - pop out, * dock back, minimise - and each one silently returned a practitioner who was writing a PRIVATE note to the * PUBLIC editor, the one visible in the patient's record. * * The loud banner in `EncounterDocumentation` tells them which mode they are in, which is why this is a * quiet failure rather than a disclosure bug: nothing tells them they were MOVED. * * Keyed per encounter, deliberately: being on the private tab for one visit must not open the next * patient's visit on it. * * In memory only, like the note drafts themselves. This holds no note content - only which tab - but it * stays in memory anyway so there is one rule for this whole surface rather than two to keep straight. */ // 'care-plan' joins the two notes here rather than getting its own memory, because it is the same // question - which of these am I writing right now - and two mechanisms would drift apart. export type DocumentationTab = 'public' | 'private' | 'care-plan'; const tabs = new Map(); export function readTabMemory(encounterId: string | undefined): DocumentationTab | undefined { return encounterId ? tabs.get(encounterId) : undefined; } export function writeTabMemory(encounterId: string | undefined, tab: DocumentationTab): void { if (!encounterId) return; // nothing to key on - a tab with no encounter is not worth remembering tabs.set(encounterId, tab); } export function clearTabMemory(encounterId: string): void { tabs.delete(encounterId); }