/** * Asking the overview to open one visit's workspace from somewhere else - the chart's View encounter on * a past visit (deck practitioner#s-encounter board 11, "After the visit has ended"). Carried in router * state, so a reload does not reopen it. */ export interface OpenVisitRequest { encounterId: string; patientId: string; } interface OpenVisitState { openVisit?: Partial; } export const openVisitState = (encounterId: string, patientId: string): OpenVisitState => ({ openVisit: { encounterId, patientId }, }); export const readOpenVisit = (state: unknown): OpenVisitRequest | undefined => { const asked = (state as OpenVisitState | null | undefined)?.openVisit; return asked?.encounterId && asked.patientId ? { encounterId: asked.encounterId, patientId: asked.patientId } : undefined; }; /** The encounter a record row is the visit of - a row id is `/`. */ export const visitEncounterId = (event: { id: string; kind: string }): string | undefined => { if (event.kind !== 'visit' || !event.id.startsWith('Encounter/')) return undefined; return event.id.slice('Encounter/'.length) || undefined; };