@adminide-stack/yantra-mobile 12.0.149-alpha.2 → 12.0.150-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/features/apps/mobileAppCatalog.js +2 -2
- package/lib/features/apps/mobileAppCatalog.js.map +1 -1
- package/lib/features/dictate/DictateExperience.js +125 -8
- package/lib/features/dictate/DictateExperience.js.map +1 -1
- package/lib/features/dictate/components/DictationList.js +4 -4
- package/lib/features/dictate/components/DictationList.js.map +1 -1
- package/lib/features/dictate/components/NoteChat.js +272 -0
- package/lib/features/dictate/components/NoteChat.js.map +1 -0
- package/lib/features/dictate/components/NoteView.js +219 -86
- package/lib/features/dictate/components/NoteView.js.map +1 -1
- package/lib/features/dictate/components/Redacted.js +19 -0
- package/lib/features/dictate/components/Redacted.js.map +1 -0
- package/lib/features/dictate/dictateClient.js +177 -90
- package/lib/features/dictate/dictateClient.js.map +1 -1
- package/lib/features/dictate/dictationStore.js +2 -2
- package/lib/features/dictate/dictationStore.js.map +1 -1
- package/lib/features/dictate/kinds.js +76 -0
- package/lib/features/dictate/kinds.js.map +1 -0
- package/lib/features/dictate/noteShape.js +132 -0
- package/lib/features/dictate/noteShape.js.map +1 -0
- package/lib/features/dictate/noteText.js +8 -17
- package/lib/features/dictate/noteText.js.map +1 -1
- package/lib/features/dictate/privacy.js +68 -8
- package/lib/features/dictate/privacy.js.map +1 -1
- package/lib/features/dictate/shownNote.js +18 -9
- package/lib/features/dictate/shownNote.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dictateClient.js","sources":["../../../src/features/dictate/dictateClient.ts"],"sourcesContent":["/**\n * Recording -> SOAP note. The recording is uploaded first and handed to the\n * connector as a URL (connector params travel as one CLI argument, capped at\n * 128 KB - audio never rides inline), then YANTRA_MEETINGS_CLINICAL_NOTE\n * transcribes it with a medical speech model and writes the note from a\n * transcript whose identifiers are placeholders; it returns the note both ways.\n *\n * Suggestions: YANTRA_MEETINGS_CLINICAL_SUGGEST reads the hidden version only,\n * so nothing identifying goes back to the AI from this phone.\n */\nimport type { RemoteConnectorExec } from '../canvas/videoEditor/remoteMediaClient';\nimport type {\n ClinicalNote,\n MedicationAction,\n NoteIdentifier,\n NoteRedaction,\n NoteSuggestion,\n SuggestionKind,\n} from './types';\n\nexport const DICTATE_CONNECTOR = 'yantra-meetings';\nexport const CLINICAL_NOTE_ACTION = 'YANTRA_MEETINGS_CLINICAL_NOTE';\nexport const SUGGEST_ACTION = 'YANTRA_MEETINGS_CLINICAL_SUGGEST';\n/** A read of one note runs about ten seconds. */\nexport const SUGGEST_TIMEOUT_MS = 4 * 60_000;\n/** Transcription plus the note runs ~10 s for two minutes of speech; an hour's dictation stays well inside this. */\nexport const NOTE_TIMEOUT_MS = 10 * 60_000;\n\nexport type DictateStage = 'uploading' | 'writing';\n\nexport interface DictateDeps {\n exec: RemoteConnectorExec;\n upload: (localUri: string) => Promise<string>;\n}\n\nexport interface WrittenNote {\n note: ClinicalNote;\n transcript: string;\n model?: string;\n /** Absent from a connector that does not hide identifiers yet. */\n redaction?: NoteRedaction;\n}\n\nexport class DictateError extends Error {\n constructor(\n readonly kind: 'offline' | 'unavailable' | 'empty' | 'failed',\n message: string,\n ) {\n super(message);\n this.name = 'DictateError';\n }\n}\n\ntype Json = Record<string, unknown>;\nconst asRecord = (v: unknown): Json | null => (v && typeof v === 'object' && !Array.isArray(v) ? (v as Json) : null);\nconst str = (v: unknown): string => (typeof v === 'string' ? v.trim() : '');\nconst strings = (v: unknown): string[] => {\n if (Array.isArray(v)) return v.map(str).filter(Boolean);\n return str(v) ? [str(v)] : [];\n};\nconst ACTIONS: MedicationAction[] = ['start', 'continue', 'change', 'stop', 'mentioned'];\nconst KINDS: SuggestionKind[] = ['missing', 'safety', 'coding', 'follow_up'];\n\nfunction shapeNote(note: Json): ClinicalNote {\n const meds = Array.isArray(note.medications) ? note.medications : [];\n return {\n title: str(note.title) || 'Clinical note',\n subjective: strings(note.subjective),\n objective: strings(note.objective),\n assessment: strings(note.assessment),\n plan: strings(note.plan),\n medications: meds\n .map(asRecord)\n .filter((m): m is Json => !!m && !!str(m.name))\n .map((m) => {\n const action = str(m.action).toLowerCase() as MedicationAction;\n return {\n name: str(m.name),\n dose: str(m.dose),\n route: str(m.route),\n frequency: str(m.frequency),\n action: ACTIONS.includes(action) ? action : 'mentioned',\n };\n }),\n follow_up: str(note.follow_up),\n to_verify: strings(note.to_verify),\n };\n}\n\n/** Only well-formed placeholders: a malformed one could not be put back. */\nexport function identifiersOf(v: unknown): NoteIdentifier[] {\n return (Array.isArray(v) ? v : [])\n .map(asRecord)\n .filter((i): i is Json => !!i && /^\\[[A-Z]+_\\d+\\]$/.test(str(i.token)) && !!str(i.value))\n .map((i) => ({ token: str(i.token), value: str(i.value), kind: str(i.kind) }));\n}\n\nfunction redactionOf(v: unknown): NoteRedaction | undefined {\n const r = asRecord(v);\n const note = asRecord(r?.note);\n if (!r || !note) return undefined;\n return {\n method: r.method === 'patterns' ? 'patterns' : 'entities',\n note: shapeNote(note),\n transcript: str(r.transcript),\n identifiers: identifiersOf(r.identifiers),\n };\n}\n\n/** The note whatever wraps it ({ data: { note } }, { result: ... }), shaped defensively. */\nexport function unwrapNote(raw: unknown): WrittenNote {\n let layer = asRecord(raw);\n const seen: Json[] = [];\n for (let depth = 0; layer && depth < 6; depth += 1) {\n seen.push(layer);\n const note = asRecord(layer.note);\n if (note) {\n const transcript = asRecord(layer.transcript);\n const redaction = redactionOf(layer.redaction);\n return {\n note: shapeNote(note),\n transcript: str(transcript?.text),\n model: str(layer.model) || undefined,\n ...(redaction ? { redaction } : {}),\n };\n }\n layer = asRecord(layer.data) ?? asRecord(layer.result);\n }\n const reason = seen\n .flatMap((l) => [l.error, l.message, l.stderr])\n .find((v): v is string => typeof v === 'string' && v.trim().length > 0);\n throw new DictateError('failed', reason ?? 'The note came back empty.');\n}\n\n/** A message a clinician can act on, never a stack trace. */\nexport function dictateErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (err instanceof DictateError && err.kind === 'empty')\n return 'No speech was heard in the recording. Try again closer to the phone.';\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. The recording is saved; try again when you are back online.';\n if (/no speech|has no speech/i.test(message))\n return 'No speech was heard in the recording. Try again closer to the phone.';\n // Every exec failure starts with the action's name (\"YANTRA_MEETINGS_CLINICAL_NOTE failed: ...\"), so\n // only cdecli's own words for a missing connector or action mean Dictate is not set up here.\n if (\n /action '[^']*' not found in connector|not found in registry|is not installed|auto-install (failed|did not complete)/i.test(\n message,\n )\n )\n return 'Dictate is not available on this workspace yet. The recording is saved.';\n // Ours, not theirs: the service behind the note (the connector's neutral \"temporarily unavailable\",\n // or, from an older connector, its raw \"all LLM providers failed\"), or the agent itself failing.\n if (\n /temporarily unavailable|problem on our side|all LLM providers failed|transcription failed|HTTP 5\\d\\d/i.test(\n message,\n )\n )\n return 'Yantra could not write the note right now. This is a problem on our side; the recording is saved, so try again in a few minutes.';\n if (/declined by the content safety rules/i.test(message))\n return 'The note could not be written from this dictation. The recording is saved.';\n if (/timed? ?out|abort/i.test(message)) return 'Writing the note took too long. The recording is saved; try again.';\n return 'The note could not be written. The recording is saved; try again.';\n}\n\nexport async function writeNoteFromRecording(\n audioUri: string,\n deps: DictateDeps,\n opts: { keyterms?: string[]; context?: string } = {},\n onStage: (stage: DictateStage) => void = () => undefined,\n): Promise<WrittenNote> {\n onStage('uploading');\n const inputUrl = await deps.upload(audioUri);\n onStage('writing');\n const raw = await deps.exec(\n DICTATE_CONNECTOR,\n CLINICAL_NOTE_ACTION,\n {\n input_url: inputUrl,\n ...(opts.keyterms?.length ? { keyterms: opts.keyterms } : {}),\n ...(opts.context?.trim() ? { context: opts.context.trim() } : {}),\n },\n { timeoutMs: NOTE_TIMEOUT_MS },\n );\n const written = unwrapNote(raw);\n const n = written.note;\n const empty = !written.transcript && ![n.subjective, n.objective, n.assessment, n.plan].some((s) => s.length);\n if (empty) throw new DictateError('empty', 'The dictation has no speech.');\n return written;\n}\n\n/** The AI's suggestions on a note, asked for with its hidden version only. */\nexport async function suggestFromNote(\n redaction: NoteRedaction,\n deps: Pick<DictateDeps, 'exec'>,\n): Promise<{ items: NoteSuggestion[]; identifiers: NoteIdentifier[] }> {\n const raw = await deps.exec(\n DICTATE_CONNECTOR,\n SUGGEST_ACTION,\n {\n note: redaction.note,\n transcript: redaction.transcript,\n // Which placeholders exist, so a new one numbers on; never what they stand for.\n identifiers: redaction.identifiers.map(({ token, kind }) => ({ token, kind })),\n },\n { timeoutMs: SUGGEST_TIMEOUT_MS },\n );\n let layer = asRecord(raw);\n for (let depth = 0; layer && depth < 6; depth += 1) {\n if (Array.isArray(layer.suggestions)) {\n const items = layer.suggestions\n .map(asRecord)\n .filter((s): s is Json => !!s && KINDS.includes(str(s.kind) as SuggestionKind) && !!str(s.text))\n .map((s) => ({ kind: str(s.kind) as SuggestionKind, text: str(s.text), why: str(s.why) }));\n return { items, identifiers: identifiersOf(layer.identifiers) };\n }\n const reason = [layer.error, layer.message].find((v): v is string => typeof v === 'string' && !!v.trim());\n if (layer.successful === false && reason) throw new DictateError('failed', reason);\n layer = asRecord(layer.data) ?? asRecord(layer.result);\n }\n throw new DictateError('failed', 'The suggestions came back empty.');\n}\n\n/** Why there are no suggestions, in words a clinician can act on. */\nexport function suggestErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. Try again when you are back online.';\n if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message))\n return 'Suggestions are not available on this workspace yet.';\n if (/temporarily unavailable|problem on our side|all LLM providers failed|HTTP 5\\d\\d/i.test(message))\n return 'Yantra could not read the note right now. This is a problem on our side; try again in a few minutes.';\n if (/timed? ?out|abort/i.test(message)) return 'Reading the note took too long. Try again.';\n return 'The suggestions could not be written. Try again.';\n}\n"],"names":[],"mappings":";;;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A;AAC1G,EAAA,IAAI,kFAAmF,CAAA,IAAA,CAAK,OAAO,CAAA,EAAU,OAAA,sGAAA;AAC7G,EAAA,IAAI,oBAAqB,CAAA,IAAA,CAAK,OAAO,CAAA,EAAU,OAAA,4CAAA;AAC/C,EAAO,OAAA,kDAAA;AACT"}
|
|
1
|
+
{"version":3,"file":"dictateClient.js","sources":["../../../src/features/dictate/dictateClient.ts"],"sourcesContent":["/**\n * Recording -> notes that fit it. The recording is uploaded first and handed\n * to the connector as a URL (connector params travel as one CLI argument,\n * capped at 128 KB - audio never rides inline), then\n * YANTRA_MEETINGS_DICTATION_NOTE transcribes it, works out what it is (a\n * visit, a class, a meeting, an idea, a story...) and writes the note from a\n * transcript whose identifiers are placeholders; it returns the note both ways.\n *\n * Everything after that reads the hidden version only, so nothing identifying\n * goes back to the AI from this phone: the suggestions\n * (YANTRA_MEETINGS_DICTATION_SUGGEST), a rewrite as another kind (the note\n * action again, from the hidden transcript), and the chat about the note\n * (YANTRA_MEETINGS_DICTATION_ASK), whose messages have every name and number\n * the note knows swapped for its placeholder here first.\n *\n * A workspace whose connector predates the dictation actions still gets a\n * visit note and its suggestions from the clinical ones.\n */\nimport type { RemoteConnectorExec } from '../canvas/videoEditor/remoteMediaClient';\nimport { asRecord, noteIsEmpty, shapeNote, str, toClinical } from './noteShape';\nimport { hideKnown, knownIdentifiers } from './privacy';\nimport type {\n ChatTurn,\n DictationKind,\n DictationNote,\n DictationRecord,\n NoteIdentifier,\n NoteRedaction,\n NoteSuggestion,\n SuggestionKind,\n} from './types';\n\nexport const DICTATE_CONNECTOR = 'yantra-meetings';\nexport const NOTE_ACTION = 'YANTRA_MEETINGS_DICTATION_NOTE';\nexport const SUGGEST_ACTION = 'YANTRA_MEETINGS_DICTATION_SUGGEST';\nexport const ASK_ACTION = 'YANTRA_MEETINGS_DICTATION_ASK';\n/** What a connector from before the dictation actions offers: a visit note and its suggestions. */\nexport const CLINICAL_NOTE_ACTION = 'YANTRA_MEETINGS_CLINICAL_NOTE';\nexport const CLINICAL_SUGGEST_ACTION = 'YANTRA_MEETINGS_CLINICAL_SUGGEST';\n/** A read of one note runs about ten seconds. */\nexport const SUGGEST_TIMEOUT_MS = 4 * 60_000;\nexport const ASK_TIMEOUT_MS = 3 * 60_000;\n/** Transcription plus the note runs ~10 s for two minutes of speech; an hour's dictation stays well inside this. */\nexport const NOTE_TIMEOUT_MS = 10 * 60_000;\n/** Connector params ride as one CLI argument capped at 128 KB; what goes back to the AI stays under this. */\nexport const PARAMS_MAX_BYTES = 110_000;\n/** The earlier turns a chat message carries. */\nexport const CHAT_CONTEXT_TURNS = 16;\n\nexport type DictateStage = 'uploading' | 'writing';\n\nexport interface DictateDeps {\n exec: RemoteConnectorExec;\n upload: (localUri: string) => Promise<string>;\n}\n\nexport interface WrittenNote {\n note: DictationNote;\n transcript: string;\n model?: string;\n /** Absent from a connector that does not hide identifiers yet. */\n redaction?: NoteRedaction;\n}\n\nexport class DictateError extends Error {\n constructor(\n readonly kind: 'offline' | 'unavailable' | 'empty' | 'failed',\n message: string,\n ) {\n super(message);\n this.name = 'DictateError';\n }\n}\n\ntype Json = Record<string, unknown>;\nconst SUGGESTION_KINDS: SuggestionKind[] = ['missing', 'safety', 'coding', 'follow_up', 'check', 'question'];\n\n/** cdecli's words for an action this workspace's connector does not have (yet). */\nconst MISSING_ACTION = /action '[^']*' not found in connector/i;\n\n/** `action`, or on a connector that does not have it, `legacy` (when there is one). */\nasync function execOr(\n deps: Pick<DictateDeps, 'exec'>,\n action: string,\n params: Json,\n timeoutMs: number,\n legacy?: { action: string; params: Json },\n): Promise<unknown> {\n try {\n return await deps.exec(DICTATE_CONNECTOR, action, params, { timeoutMs });\n } catch (err) {\n if (!legacy || !MISSING_ACTION.test(err instanceof Error ? err.message : String(err))) throw err;\n return deps.exec(DICTATE_CONNECTOR, legacy.action, legacy.params, { timeoutMs });\n }\n}\n\n/** The first layer (the reply, its `data`, its `result`...) that `has` accepts; the connector's own error if none. */\nfunction findLayer(raw: unknown, has: (layer: Json) => boolean, empty: string): Json {\n let layer = asRecord(raw);\n const seen: Json[] = [];\n for (let depth = 0; layer && depth < 6; depth += 1) {\n if (has(layer)) return layer;\n seen.push(layer);\n layer = asRecord(layer.data) ?? asRecord(layer.result);\n }\n const reason = seen\n .flatMap((l) => [l.error, l.message, l.stderr])\n .find((v): v is string => typeof v === 'string' && v.trim().length > 0);\n throw new DictateError('failed', reason ?? empty);\n}\n\n/** UTF-8 bytes, over-counted for astral characters (which only makes the budget safer). */\nfunction utf8Bytes(text: string): number {\n let n = 0;\n for (let i = 0; i < text.length; i += 1) {\n const c = text.charCodeAt(i);\n if (c < 0x80) n += 1;\n else if (c < 0x800) n += 2;\n else n += 3;\n }\n return n;\n}\n\n/** The transcript cut (at the end) until the params carrying it fit one connector call. */\nexport function fitTranscript(rest: Json, transcript: string): string {\n const budget = PARAMS_MAX_BYTES - utf8Bytes(JSON.stringify(rest)) - 32;\n let fitted = transcript;\n while (fitted && utf8Bytes(JSON.stringify(fitted)) > budget)\n fitted = fitted.slice(0, Math.floor(fitted.length * 0.9));\n return fitted;\n}\n\n/** Only well-formed placeholders: a malformed one could not be put back. */\nexport function identifiersOf(v: unknown): NoteIdentifier[] {\n return (Array.isArray(v) ? v : [])\n .map(asRecord)\n .filter((i): i is Json => !!i && /^\\[[A-Z]+_\\d+\\]$/.test(str(i.token)) && !!str(i.value))\n .map((i) => ({ token: str(i.token), value: str(i.value), kind: str(i.kind) }));\n}\n\n/** Which placeholders exist, so a new one numbers on; never what they stand for. */\nconst tokensOf = (ids: NoteIdentifier[]) => ids.map(({ token, kind }) => ({ token, kind }));\n\nfunction redactionOf(v: unknown): NoteRedaction | undefined {\n const r = asRecord(v);\n const note = asRecord(r?.note);\n if (!r || !note) return undefined;\n return {\n method: r.method === 'patterns' ? 'patterns' : 'entities',\n note: shapeNote(note),\n transcript: str(r.transcript),\n identifiers: identifiersOf(r.identifiers),\n };\n}\n\n/** The note whatever wraps it ({ data: { note } }, { result: ... }), shaped defensively. */\nexport function unwrapNote(raw: unknown): WrittenNote {\n const layer = findLayer(raw, (l) => !!asRecord(l.note), 'The note came back empty.');\n const redaction = redactionOf(layer.redaction);\n return {\n note: shapeNote(asRecord(layer.note)!),\n transcript: str(asRecord(layer.transcript)?.text),\n model: str(layer.model) || undefined,\n ...(redaction ? { redaction } : {}),\n };\n}\n\n/** A message a person can act on, never a stack trace. */\nexport function dictateErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (err instanceof DictateError && err.kind === 'empty')\n return 'No speech was heard in the recording. Try again closer to the phone.';\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. The recording is saved; try again when you are back online.';\n if (/no speech|has no speech/i.test(message))\n return 'No speech was heard in the recording. Try again closer to the phone.';\n // Every exec failure starts with the action's name (\"YANTRA_MEETINGS_DICTATION_NOTE failed: ...\"), so\n // only cdecli's own words for a missing connector or action mean Dictate is not set up here.\n if (\n /action '[^']*' not found in connector|not found in registry|is not installed|auto-install (failed|did not complete)/i.test(\n message,\n )\n )\n return 'Dictate is not available on this workspace yet. The recording is saved.';\n // Ours, not theirs: the service behind the note (the connector's neutral \"temporarily unavailable\",\n // or, from an older connector, its raw \"all LLM providers failed\"), or the agent itself failing.\n if (\n /temporarily unavailable|problem on our side|all LLM providers failed|transcription failed|HTTP 5\\d\\d/i.test(\n message,\n )\n )\n return 'Yantra could not write the note right now. This is a problem on our side; the recording is saved, so try again in a few minutes.';\n if (/declined by the content safety rules/i.test(message))\n return 'The note could not be written from this dictation. The recording is saved.';\n if (/timed? ?out|abort/i.test(message)) return 'Writing the note took too long. The recording is saved; try again.';\n return 'The note could not be written. The recording is saved; try again.';\n}\n\nexport async function writeNoteFromRecording(\n audioUri: string,\n deps: DictateDeps,\n opts: { keyterms?: string[]; context?: string; kind?: DictationKind } = {},\n onStage: (stage: DictateStage) => void = () => undefined,\n): Promise<WrittenNote> {\n onStage('uploading');\n const inputUrl = await deps.upload(audioUri);\n onStage('writing');\n const params: Json = {\n input_url: inputUrl,\n ...(opts.keyterms?.length ? { keyterms: opts.keyterms } : {}),\n ...(opts.context?.trim() ? { context: opts.context.trim() } : {}),\n };\n const raw = await execOr(deps, NOTE_ACTION, opts.kind ? { ...params, kind: opts.kind } : params, NOTE_TIMEOUT_MS, {\n action: CLINICAL_NOTE_ACTION,\n params,\n });\n const written = unwrapNote(raw);\n if (!written.transcript && noteIsEmpty(written.note))\n throw new DictateError('empty', 'The dictation has no speech.');\n return written;\n}\n\n/** Whether the hidden transcript fits one call, so the note can be written again from it. */\nexport function canRewrite(redaction: NoteRedaction | undefined): redaction is NoteRedaction {\n if (!redaction?.transcript) return false;\n return (\n fitTranscript({ identifiers: tokensOf(redaction.identifiers), kind: 'general' }, redaction.transcript) ===\n redaction.transcript\n );\n}\n\n/**\n * The note written again as `kind`, from the transcript as the AI first read\n * it: nothing is transcribed and no value leaves the phone. Returns the hidden\n * note and any placeholder the connector added.\n */\nexport async function rewriteNote(\n redaction: NoteRedaction,\n kind: DictationKind,\n deps: Pick<DictateDeps, 'exec'>,\n): Promise<{ note: DictationNote; identifiers: NoteIdentifier[]; model?: string }> {\n const raw = await deps.exec(\n DICTATE_CONNECTOR,\n NOTE_ACTION,\n { redacted_transcript: redaction.transcript, identifiers: tokensOf(redaction.identifiers), kind },\n { timeoutMs: NOTE_TIMEOUT_MS },\n );\n const layer = findLayer(raw, (l) => !!asRecord(asRecord(l.redaction)?.note), 'The note came back empty.');\n const rewritten = redactionOf(layer.redaction)!;\n return { note: rewritten.note, identifiers: rewritten.identifiers, model: str(layer.model) || undefined };\n}\n\n/** The AI's suggestions on a note, asked for with its hidden version only. */\nexport async function suggestFromNote(\n redaction: NoteRedaction,\n deps: Pick<DictateDeps, 'exec'>,\n): Promise<{ items: NoteSuggestion[]; identifiers: NoteIdentifier[] }> {\n const rest = { note: redaction.note, identifiers: tokensOf(redaction.identifiers) };\n const transcript = fitTranscript(rest, redaction.transcript);\n const raw = await execOr(\n deps,\n SUGGEST_ACTION,\n { ...rest, transcript },\n SUGGEST_TIMEOUT_MS,\n redaction.note.kind === 'clinical'\n ? { action: CLINICAL_SUGGEST_ACTION, params: { ...rest, note: toClinical(redaction.note), transcript } }\n : undefined,\n );\n const layer = findLayer(\n raw,\n (l) => Array.isArray(l.suggestions) || (l.successful === false && !!str(l.error)),\n 'The suggestions came back empty.',\n );\n if (!Array.isArray(layer.suggestions)) throw new DictateError('failed', str(layer.error));\n const items = layer.suggestions\n .map(asRecord)\n .filter((s): s is Json => !!s && SUGGESTION_KINDS.includes(str(s.kind) as SuggestionKind) && !!str(s.text))\n .map((s) => ({ kind: str(s.kind) as SuggestionKind, text: str(s.text), why: str(s.why) }));\n return { items, identifiers: identifiersOf(layer.identifiers) };\n}\n\n/** Why there are no suggestions, in words a person can act on. */\nexport function suggestErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. Try again when you are back online.';\n if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message))\n return 'Suggestions are not available on this workspace yet.';\n if (/temporarily unavailable|problem on our side|all LLM providers failed|HTTP 5\\d\\d/i.test(message))\n return 'Yantra could not read the note right now. This is a problem on our side; try again in a few minutes.';\n if (/timed? ?out|abort/i.test(message)) return 'Reading the note took too long. Try again.';\n return 'The suggestions could not be written. Try again.';\n}\n\n/** Why the note could not be written again. */\nexport function rewriteErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. Try again when you are back online.';\n if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message))\n return 'Rewriting is not available on this workspace yet.';\n if (/temporarily unavailable|problem on our side|all LLM providers failed|HTTP 5\\d\\d/i.test(message))\n return 'Yantra could not rewrite the note right now. This is a problem on our side; try again in a few minutes.';\n if (/timed? ?out|abort/i.test(message)) return 'Rewriting the note took too long. Try again.';\n return 'The note could not be rewritten. Try again.';\n}\n\nexport interface Answer {\n /** The message as the AI read it: known names and numbers as placeholders. */\n asked: string;\n answer: string;\n /** Placeholders the connector added (a new number typed in), with what they stand for. */\n identifiers: NoteIdentifier[];\n}\n\n/**\n * A chat message about the note. The AI reads the hidden note and transcript,\n * the earlier turns as it saw them, and the message with every name and number\n * this dictation knows swapped for its placeholder before it leaves the phone.\n */\nexport async function askAboutNote(\n record: DictationRecord,\n message: string,\n deps: Pick<DictateDeps, 'exec'>,\n): Promise<Answer> {\n const { redaction } = record;\n if (!redaction) throw new DictateError('unavailable', 'This note was written before names were hidden.');\n const known = knownIdentifiers(record);\n const asked = hideKnown(message.trim(), known).text;\n const turns: Array<Pick<ChatTurn, 'role' | 'text'>> = (record.chat?.turns ?? [])\n .slice(-CHAT_CONTEXT_TURNS)\n .map(({ role, text }) => ({ role, text }));\n const rest = { note: redaction.note, identifiers: tokensOf(known), turns, message: asked };\n const raw = await deps.exec(\n DICTATE_CONNECTOR,\n ASK_ACTION,\n { ...rest, transcript: fitTranscript(rest, redaction.transcript) },\n { timeoutMs: ASK_TIMEOUT_MS },\n );\n const layer = findLayer(raw, (l) => typeof l.answer === 'string', 'The answer came back empty.');\n const answer = str(layer.answer);\n if (!answer) throw new DictateError('failed', 'The answer came back empty.');\n return { asked: str(layer.message) || asked, answer, identifiers: identifiersOf(layer.identifiers) };\n}\n\n/** Why a chat message got no answer. */\nexport function askErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. Try again when you are back online.';\n if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message))\n return 'Asking about a note is not available on this workspace yet.';\n if (/temporarily unavailable|problem on our side|all LLM providers failed|HTTP 5\\d\\d/i.test(message))\n return 'Yantra could not answer right now. This is a problem on our side; try again in a few minutes.';\n if (/timed? ?out|abort/i.test(message)) return 'The answer took too long. Try again.';\n return 'No answer came back. Try again.';\n}\n"],"names":[],"mappings":";;;;;;;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eRecord}from'./noteShape.js';var __defProp = Object.defineProperty;
|
|
2
2
|
var __defProps = Object.defineProperties;
|
|
3
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -40,7 +40,7 @@ function createDictationStore(fs = loadFs(), now = () => /* @__PURE__ */ new Dat
|
|
|
40
40
|
try {
|
|
41
41
|
if (!(await fs.getInfoAsync(indexUri)).exists) return [];
|
|
42
42
|
const parsed = JSON.parse(await fs.readAsStringAsync(indexUri));
|
|
43
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
43
|
+
return Array.isArray(parsed) ? parsed.map(upgradeRecord) : [];
|
|
44
44
|
} catch (e) {
|
|
45
45
|
return [];
|
|
46
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dictationStore.js","sources":["../../../src/features/dictate/dictationStore.ts"],"sourcesContent":["/**\n * Dictations live on this device only: an index file plus, until its note is\n * written, the recording itself. A recording is moved out of the recorder's\n * cache the moment it stops, so a failed upload or a closed app never loses\n * it, and it is deleted as soon as the note exists - the less
|
|
1
|
+
{"version":3,"file":"dictationStore.js","sources":["../../../src/features/dictate/dictationStore.ts"],"sourcesContent":["/**\n * Dictations live on this device only: an index file plus, until its note is\n * written, the recording itself. A recording is moved out of the recorder's\n * cache the moment it stops, so a failed upload or a closed app never loses\n * it, and it is deleted as soon as the note exists - the less audio a phone\n * keeps, the better. A record saved by an earlier build (a SOAP note) is read\n * in today's shape (noteShape.ts).\n */\nimport { upgradeRecord } from './noteShape';\nimport type { DictationRecord } from './types';\n\n/** The slice of expo-file-system (legacy API) this needs; injectable for tests. */\nexport interface DictationFs {\n documentDirectory: string | null;\n getInfoAsync(uri: string): Promise<{ exists: boolean }>;\n makeDirectoryAsync(uri: string, options?: { intermediates?: boolean }): Promise<void>;\n readAsStringAsync(uri: string): Promise<string>;\n writeAsStringAsync(uri: string, contents: string): Promise<void>;\n moveAsync(options: { from: string; to: string }): Promise<void>;\n deleteAsync(uri: string, options?: { idempotent?: boolean }): Promise<void>;\n}\n\nfunction loadFs(): DictationFs {\n // Lazy: the module is native, and a test or a build without it must still load this file.\n // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require\n return require('expo-file-system') as DictationFs;\n}\n\n/** Keeps the list from growing without bound; the oldest go first. */\nconst MAX_RECORDS = 200;\n\nexport interface DictationStore {\n list(): Promise<DictationRecord[]>;\n /** Moves a finished recording into the store and records it as saved. */\n keepRecording(tempUri: string, durationMs: number): Promise<DictationRecord>;\n update(id: string, patch: Partial<DictationRecord>): Promise<DictationRecord | null>;\n /** The note exists: the recording is no longer needed. */\n dropAudio(id: string): Promise<void>;\n remove(id: string): Promise<void>;\n /** A recording the person threw away before it was kept. */\n discardRecording(tempUri: string): Promise<void>;\n}\n\nexport function createDictationStore(fs: DictationFs = loadFs(), now: () => Date = () => new Date()): DictationStore {\n const root = `${fs.documentDirectory ?? ''}dictations/`;\n const indexUri = `${root}index.json`;\n // One write at a time: two quick updates must not race the index file.\n let queue: Promise<unknown> = Promise.resolve();\n const serial = <T>(task: () => Promise<T>): Promise<T> => {\n const next = queue.then(task, task);\n queue = next.catch(() => undefined);\n return next;\n };\n\n const ensureDir = async () => {\n if (!(await fs.getInfoAsync(root)).exists) await fs.makeDirectoryAsync(root, { intermediates: true });\n };\n const read = async (): Promise<DictationRecord[]> => {\n try {\n if (!(await fs.getInfoAsync(indexUri)).exists) return [];\n const parsed = JSON.parse(await fs.readAsStringAsync(indexUri));\n return Array.isArray(parsed) ? (parsed as DictationRecord[]).map(upgradeRecord) : [];\n } catch {\n return []; // a damaged index must not lock anyone out of recording\n }\n };\n const write = async (records: DictationRecord[]) => {\n await ensureDir();\n await fs.writeAsStringAsync(indexUri, JSON.stringify(records.slice(0, MAX_RECORDS)));\n };\n\n return {\n list: () => serial(read),\n keepRecording: (tempUri, durationMs) =>\n serial(async () => {\n await ensureDir();\n const at = now();\n const id = `d${at.getTime().toString(36)}${Math.random().toString(36).slice(2, 6)}`;\n const ext = /\\.[a-z0-9]{2,4}$/i.exec(tempUri)?.[0] ?? '.m4a';\n const audioUri = `${root}${id}${ext}`;\n await fs.moveAsync({ from: tempUri, to: audioUri });\n const record: DictationRecord = {\n id,\n createdAt: at.toISOString(),\n durationMs,\n status: 'saved',\n audioUri,\n };\n await write([record, ...(await read())]);\n return record;\n }),\n update: (id, patch) =>\n serial(async () => {\n const records = await read();\n const i = records.findIndex((r) => r.id === id);\n if (i < 0) return null;\n records[i] = { ...records[i], ...patch, id };\n await write(records);\n return records[i];\n }),\n dropAudio: (id) =>\n serial(async () => {\n const records = await read();\n const record = records.find((r) => r.id === id);\n if (!record?.audioUri) return;\n await fs.deleteAsync(record.audioUri, { idempotent: true }).catch(() => undefined);\n delete record.audioUri;\n await write(records);\n }),\n remove: (id) =>\n serial(async () => {\n const records = await read();\n const record = records.find((r) => r.id === id);\n if (record?.audioUri)\n await fs.deleteAsync(record.audioUri, { idempotent: true }).catch(() => undefined);\n await write(records.filter((r) => r.id !== id));\n }),\n discardRecording: (tempUri) => fs.deleteAsync(tempUri, { idempotent: true }).catch(() => undefined),\n };\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,SAAS,MAAsB,GAAA;AAG7B,EAAA,OAAO,QAAQ,kBAAkB,CAAA;AACnC;AAGA,MAAM,WAAc,GAAA,GAAA;AAYJ,SAAA,oBAAA,CAAqB,KAAkB,MAAO,EAAA,EAAG,MAAkB,sBAAM,IAAI,MAAwB,EAAA;AAjDrH,EAAA,IAAA,EAAA;AAkDE,EAAA,MAAM,IAAO,GAAA,CAAA,EAAA,CAAG,EAAG,GAAA,EAAA,CAAA,iBAAA,KAAH,YAAwB,EAAE,CAAA,WAAA,CAAA;AAC1C,EAAM,MAAA,QAAA,GAAW,GAAG,IAAI,CAAA,UAAA,CAAA;AAExB,EAAI,IAAA,KAAA,GAA0B,QAAQ,OAAQ,EAAA;AAC9C,EAAM,MAAA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B,EAAA,CAAA,OAAA,KAAW,EAAG,CAAA,WAAA,CAAY,OAAS,EAAA;AAAA,MACnD,UAAY,EAAA;AAAA,KACb,CAAA,CAAE,KAAM,CAAA,MAAM,MAAS;AAAA,GAC1B;AACF"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const DICTATION_KINDS = ["general", "lecture", "meeting", "ideas", "todo", "journal", "story", "clinical"];
|
|
2
|
+
const KIND_LABEL = {
|
|
3
|
+
clinical: "Visit note",
|
|
4
|
+
lecture: "Class notes",
|
|
5
|
+
meeting: "Meeting notes",
|
|
6
|
+
ideas: "Ideas",
|
|
7
|
+
journal: "Journal",
|
|
8
|
+
story: "Story",
|
|
9
|
+
todo: "To-do list",
|
|
10
|
+
general: "Notes"
|
|
11
|
+
};
|
|
12
|
+
const KIND_ICON = {
|
|
13
|
+
clinical: "stethoscope",
|
|
14
|
+
lecture: "school-outline",
|
|
15
|
+
meeting: "account-group-outline",
|
|
16
|
+
ideas: "lightbulb-outline",
|
|
17
|
+
journal: "notebook-outline",
|
|
18
|
+
story: "book-open-page-variant-outline",
|
|
19
|
+
todo: "format-list-checks",
|
|
20
|
+
general: "file-document-outline"
|
|
21
|
+
};
|
|
22
|
+
const ACTIONS_HEADING = {
|
|
23
|
+
clinical: "TO DO",
|
|
24
|
+
lecture: "TO DO",
|
|
25
|
+
meeting: "ACTION ITEMS",
|
|
26
|
+
ideas: "NEXT STEPS",
|
|
27
|
+
journal: "NEXT STEPS",
|
|
28
|
+
story: "NEXT STEPS",
|
|
29
|
+
todo: "TO DO",
|
|
30
|
+
general: "NEXT STEPS"
|
|
31
|
+
};
|
|
32
|
+
const SUGGESTION_ICON = {
|
|
33
|
+
safety: "alert-octagon-outline",
|
|
34
|
+
missing: "text-box-plus-outline",
|
|
35
|
+
check: "magnify-scan",
|
|
36
|
+
coding: "tag-outline",
|
|
37
|
+
question: "help-circle-outline",
|
|
38
|
+
follow_up: "calendar-check-outline"
|
|
39
|
+
};
|
|
40
|
+
const SUGGESTION_ORDER = ["safety", "missing", "check", "coding", "question", "follow_up"];
|
|
41
|
+
function suggestionHeading(kind, noteKind) {
|
|
42
|
+
switch (kind) {
|
|
43
|
+
case "safety":
|
|
44
|
+
return "Check for safety";
|
|
45
|
+
case "missing":
|
|
46
|
+
return noteKind === "story" ? "Your story could add" : "Missing from the note";
|
|
47
|
+
case "check":
|
|
48
|
+
return "Worth checking";
|
|
49
|
+
case "coding":
|
|
50
|
+
return "Coding";
|
|
51
|
+
case "question":
|
|
52
|
+
if (noteKind === "lecture") return "Test yourself";
|
|
53
|
+
if (noteKind === "story") return "What could happen next";
|
|
54
|
+
if (noteKind === "journal") return "To reflect on";
|
|
55
|
+
return "Questions to think about";
|
|
56
|
+
default:
|
|
57
|
+
return noteKind === "clinical" ? "Follow-up" : "Next steps";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function suggestionDisclaimer(noteKind) {
|
|
61
|
+
return noteKind === "clinical" ? "AI suggestions for you to consider, not medical advice." : "AI suggestions for you to consider.";
|
|
62
|
+
}
|
|
63
|
+
function suggestionInvite(noteKind) {
|
|
64
|
+
if (noteKind === "clinical") return "Ask the AI to read the note and point out what to add or check before you sign. It reads the note with names and numbers hidden.";
|
|
65
|
+
return "Ask the AI to read the note and point out what to add, check or do next. It reads the note with names and numbers hidden.";
|
|
66
|
+
}
|
|
67
|
+
const CHAT_STARTERS = {
|
|
68
|
+
clinical: ["Write a referral letter", "Patient instructions in plain words", "What is not documented yet?"],
|
|
69
|
+
lecture: ["Quiz me on this", "Explain the main idea simply", "Make flashcards"],
|
|
70
|
+
meeting: ["Draft a follow-up email", "Who owes what, by when?", "What is still undecided?"],
|
|
71
|
+
ideas: ["Poke holes in this idea", "Write a one-paragraph pitch", "What should I do first?"],
|
|
72
|
+
journal: ["What stands out to you?", "Give me one question to reflect on"],
|
|
73
|
+
story: ["Give it a happy ending", "Make it a bedtime story", "Think of a title"],
|
|
74
|
+
todo: ["Put these in order", "What can I do today?"],
|
|
75
|
+
general: ["Summarize in three bullets", "What is the main point?", "What should I do next?"]
|
|
76
|
+
};export{ACTIONS_HEADING,CHAT_STARTERS,DICTATION_KINDS,KIND_ICON,KIND_LABEL,SUGGESTION_ICON,SUGGESTION_ORDER,suggestionDisclaimer,suggestionHeading,suggestionInvite};//# sourceMappingURL=kinds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kinds.js","sources":["../../../src/features/dictate/kinds.ts"],"sourcesContent":["/**\n * The kinds of recording Dictate writes notes for, and how each reads on\n * screen: its name, its icon, what its tasks are called, the suggestion\n * headings that fit it, and the first questions worth asking about it.\n */\nimport type { ComponentProps } from 'react';\nimport type { MaterialCommunityIcons } from '@expo/vector-icons';\nimport type { DictationKind, SuggestionKind } from './types';\n\ntype IconName = ComponentProps<typeof MaterialCommunityIcons>['name'];\n\n/** In the order the kind picker offers them. */\nexport const DICTATION_KINDS: DictationKind[] = [\n 'general',\n 'lecture',\n 'meeting',\n 'ideas',\n 'todo',\n 'journal',\n 'story',\n 'clinical',\n];\n\nexport const KIND_LABEL: Record<DictationKind, string> = {\n clinical: 'Visit note',\n lecture: 'Class notes',\n meeting: 'Meeting notes',\n ideas: 'Ideas',\n journal: 'Journal',\n story: 'Story',\n todo: 'To-do list',\n general: 'Notes',\n};\n\nexport const KIND_ICON: Record<DictationKind, IconName> = {\n clinical: 'stethoscope',\n lecture: 'school-outline',\n meeting: 'account-group-outline',\n ideas: 'lightbulb-outline',\n journal: 'notebook-outline',\n story: 'book-open-page-variant-outline',\n todo: 'format-list-checks',\n general: 'file-document-outline',\n};\n\n/** What the tasks that were said are called in each kind of note. */\nexport const ACTIONS_HEADING: Record<DictationKind, string> = {\n clinical: 'TO DO',\n lecture: 'TO DO',\n meeting: 'ACTION ITEMS',\n ideas: 'NEXT STEPS',\n journal: 'NEXT STEPS',\n story: 'NEXT STEPS',\n todo: 'TO DO',\n general: 'NEXT STEPS',\n};\n\nexport const SUGGESTION_ICON: Record<SuggestionKind, IconName> = {\n safety: 'alert-octagon-outline',\n missing: 'text-box-plus-outline',\n check: 'magnify-scan',\n coding: 'tag-outline',\n question: 'help-circle-outline',\n follow_up: 'calendar-check-outline',\n};\n\n/** In the order the screen and the shared text show suggestion groups. */\nexport const SUGGESTION_ORDER: SuggestionKind[] = ['safety', 'missing', 'check', 'coding', 'question', 'follow_up'];\n\nexport function suggestionHeading(kind: SuggestionKind, noteKind: DictationKind): string {\n switch (kind) {\n case 'safety':\n return 'Check for safety';\n case 'missing':\n return noteKind === 'story' ? 'Your story could add' : 'Missing from the note';\n case 'check':\n return 'Worth checking';\n case 'coding':\n return 'Coding';\n case 'question':\n if (noteKind === 'lecture') return 'Test yourself';\n if (noteKind === 'story') return 'What could happen next';\n if (noteKind === 'journal') return 'To reflect on';\n return 'Questions to think about';\n default:\n return noteKind === 'clinical' ? 'Follow-up' : 'Next steps';\n }\n}\n\nexport function suggestionDisclaimer(noteKind: DictationKind): string {\n return noteKind === 'clinical'\n ? 'AI suggestions for you to consider, not medical advice.'\n : 'AI suggestions for you to consider.';\n}\n\n/** What the suggestions card offers before it is asked. */\nexport function suggestionInvite(noteKind: DictationKind): string {\n if (noteKind === 'clinical')\n return 'Ask the AI to read the note and point out what to add or check before you sign. It reads the note with names and numbers hidden.';\n return 'Ask the AI to read the note and point out what to add, check or do next. It reads the note with names and numbers hidden.';\n}\n\n/** First questions worth asking about each kind of note; a tap sends one. */\nexport const CHAT_STARTERS: Record<DictationKind, string[]> = {\n clinical: ['Write a referral letter', 'Patient instructions in plain words', 'What is not documented yet?'],\n lecture: ['Quiz me on this', 'Explain the main idea simply', 'Make flashcards'],\n meeting: ['Draft a follow-up email', 'Who owes what, by when?', 'What is still undecided?'],\n ideas: ['Poke holes in this idea', 'Write a one-paragraph pitch', 'What should I do first?'],\n journal: ['What stands out to you?', 'Give me one question to reflect on'],\n story: ['Give it a happy ending', 'Make it a bedtime story', 'Think of a title'],\n todo: ['Put these in order', 'What can I do today?'],\n general: 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,CAAA;AAAA,EAC/E,IAAA,EAAM,CAAC,oBAAA,EAAsB,sBAAsB,CAAA;AAAA,EACnD,OAAS,EAAA,CAAC,4BAA8B,EAAA,yBAAA,EAA2B,wBAAwB;AAC7F"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {DICTATION_KINDS}from'./kinds.js';var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
const asRecord = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
21
|
+
const str = (v) => typeof v === "string" ? v.trim() : "";
|
|
22
|
+
const strings = (v) => {
|
|
23
|
+
if (Array.isArray(v)) return v.map(str).filter(Boolean);
|
|
24
|
+
return str(v) ? [str(v)] : [];
|
|
25
|
+
};
|
|
26
|
+
const ACTIONS = ["start", "continue", "change", "stop", "mentioned"];
|
|
27
|
+
const SOAP = ["Subjective", "Objective", "Assessment", "Plan"];
|
|
28
|
+
function isDictationKind(v) {
|
|
29
|
+
return typeof v === "string" && DICTATION_KINDS.includes(v);
|
|
30
|
+
}
|
|
31
|
+
function medicationsOf(v) {
|
|
32
|
+
return (Array.isArray(v) ? v : []).map(asRecord).filter((m) => !!m && !!str(m.name)).map((m) => {
|
|
33
|
+
const action = str(m.action).toLowerCase();
|
|
34
|
+
return {
|
|
35
|
+
name: str(m.name),
|
|
36
|
+
dose: str(m.dose),
|
|
37
|
+
route: str(m.route),
|
|
38
|
+
frequency: str(m.frequency),
|
|
39
|
+
action: ACTIONS.includes(action) ? action : "mentioned"
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function fromClinical(note) {
|
|
44
|
+
const followUp = str(note.follow_up);
|
|
45
|
+
return {
|
|
46
|
+
kind: "clinical",
|
|
47
|
+
title: str(note.title) || "Visit note",
|
|
48
|
+
summary: "",
|
|
49
|
+
sections: [{
|
|
50
|
+
heading: "Subjective",
|
|
51
|
+
items: strings(note.subjective)
|
|
52
|
+
}, {
|
|
53
|
+
heading: "Objective",
|
|
54
|
+
items: strings(note.objective)
|
|
55
|
+
}, {
|
|
56
|
+
heading: "Assessment",
|
|
57
|
+
items: strings(note.assessment)
|
|
58
|
+
}, {
|
|
59
|
+
heading: "Plan",
|
|
60
|
+
items: strings(note.plan)
|
|
61
|
+
}, ...followUp ? [{
|
|
62
|
+
heading: "Follow-up",
|
|
63
|
+
items: [followUp]
|
|
64
|
+
}] : []],
|
|
65
|
+
actions: [],
|
|
66
|
+
medications: medicationsOf(note.medications),
|
|
67
|
+
to_verify: strings(note.to_verify)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function shapeNote(raw) {
|
|
71
|
+
if (!Array.isArray(raw.sections)) return fromClinical(raw);
|
|
72
|
+
const kind = isDictationKind(raw.kind) ? raw.kind : "general";
|
|
73
|
+
const sections = raw.sections.map(asRecord).filter((s) => !!s && !!str(s.heading)).map((s) => ({
|
|
74
|
+
heading: str(s.heading),
|
|
75
|
+
items: strings(s.items)
|
|
76
|
+
}));
|
|
77
|
+
return {
|
|
78
|
+
kind,
|
|
79
|
+
title: str(raw.title) || "Notes",
|
|
80
|
+
summary: str(raw.summary),
|
|
81
|
+
sections,
|
|
82
|
+
actions: strings(raw.actions),
|
|
83
|
+
medications: medicationsOf(raw.medications),
|
|
84
|
+
to_verify: strings(raw.to_verify)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function noteIsEmpty(note) {
|
|
88
|
+
return !note.summary && !note.actions.length && !note.sections.some((s) => s.items.length);
|
|
89
|
+
}
|
|
90
|
+
function toClinical(note) {
|
|
91
|
+
const items = (heading) => {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
return (_b = (_a = note.sections.find((s) => s.heading.toLowerCase() === heading.toLowerCase())) == null ? void 0 : _a.items) != null ? _b : [];
|
|
94
|
+
};
|
|
95
|
+
const others = note.sections.filter((s) => !SOAP.some((h) => h.toLowerCase() === s.heading.toLowerCase()) && s.heading !== "Follow-up");
|
|
96
|
+
return {
|
|
97
|
+
title: note.title,
|
|
98
|
+
subjective: items("Subjective"),
|
|
99
|
+
objective: items("Objective"),
|
|
100
|
+
assessment: items("Assessment"),
|
|
101
|
+
plan: [...items("Plan"), ...others.flatMap((s) => s.items)],
|
|
102
|
+
medications: note.medications,
|
|
103
|
+
follow_up: items("Follow-up").join(" "),
|
|
104
|
+
to_verify: note.to_verify
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function turnsOf(v) {
|
|
108
|
+
return (Array.isArray(v) ? v : []).map(asRecord).filter((t) => !!t && !!str(t.text)).map((t) => ({
|
|
109
|
+
role: t.role === "assistant" ? "assistant" : "user",
|
|
110
|
+
text: str(t.text),
|
|
111
|
+
at: str(t.at)
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
function upgradeRecord(record) {
|
|
115
|
+
var _a, _b;
|
|
116
|
+
const note = asRecord(record.note);
|
|
117
|
+
const redaction = asRecord(record.redaction);
|
|
118
|
+
const redactedNote = asRecord(redaction == null ? void 0 : redaction.note);
|
|
119
|
+
const chat = asRecord(record.chat);
|
|
120
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, record), note ? {
|
|
121
|
+
note: shapeNote(note)
|
|
122
|
+
} : {}), record.redaction && redactedNote ? {
|
|
123
|
+
redaction: __spreadProps(__spreadValues({}, record.redaction), {
|
|
124
|
+
note: shapeNote(redactedNote)
|
|
125
|
+
})
|
|
126
|
+
} : {}), chat ? {
|
|
127
|
+
chat: {
|
|
128
|
+
turns: turnsOf(chat.turns),
|
|
129
|
+
identifiers: Array.isArray(chat.identifiers) ? (_b = (_a = record.chat) == null ? void 0 : _a.identifiers) != null ? _b : [] : []
|
|
130
|
+
}
|
|
131
|
+
} : {});
|
|
132
|
+
}export{asRecord,fromClinical,isDictationKind,noteIsEmpty,shapeNote,str,strings,toClinical,upgradeRecord};//# sourceMappingURL=noteShape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noteShape.js","sources":["../../../src/features/dictate/noteShape.ts"],"sourcesContent":["/**\n * A note in the one shape the screen draws, whatever wrote it: the dictation\n * note (any kind), or the SOAP note YANTRA_MEETINGS_CLINICAL_NOTE writes and\n * earlier builds of Dictate saved on the phone, read as a visit note. The\n * store runs every saved record through `upgradeRecord`, so nothing past it\n * sees the old shape.\n */\nimport { DICTATION_KINDS } from './kinds';\nimport type {\n ChatTurn,\n ClinicalNote,\n DictationKind,\n DictationNote,\n DictationRecord,\n MedicationAction,\n NoteMedication,\n NoteSection,\n} from './types';\n\ntype Json = Record<string, unknown>;\nexport const asRecord = (v: unknown): Json | null =>\n v && typeof v === 'object' && !Array.isArray(v) ? (v as Json) : null;\nexport const str = (v: unknown): string => (typeof v === 'string' ? v.trim() : '');\nexport const strings = (v: unknown): string[] => {\n if (Array.isArray(v)) return v.map(str).filter(Boolean);\n return str(v) ? [str(v)] : [];\n};\nconst ACTIONS: MedicationAction[] = ['start', 'continue', 'change', 'stop', 'mentioned'];\nconst SOAP = ['Subjective', 'Objective', 'Assessment', 'Plan'];\n\nexport function isDictationKind(v: unknown): v is DictationKind {\n return typeof v === 'string' && (DICTATION_KINDS as string[]).includes(v);\n}\n\nfunction medicationsOf(v: unknown): NoteMedication[] {\n return (Array.isArray(v) ? v : [])\n .map(asRecord)\n .filter((m): m is Json => !!m && !!str(m.name))\n .map((m) => {\n const action = str(m.action).toLowerCase() as MedicationAction;\n return {\n name: str(m.name),\n dose: str(m.dose),\n route: str(m.route),\n frequency: str(m.frequency),\n action: ACTIONS.includes(action) ? action : 'mentioned',\n };\n });\n}\n\n/** A SOAP note as a visit note: the four sections in order, follow-up after them. */\nexport function fromClinical(note: Pick<ClinicalNote, 'title'> & Partial<ClinicalNote>): DictationNote {\n const followUp = str(note.follow_up);\n return {\n kind: 'clinical',\n title: str(note.title) || 'Visit note',\n summary: '',\n sections: [\n { heading: 'Subjective', items: strings(note.subjective) },\n { heading: 'Objective', items: strings(note.objective) },\n { heading: 'Assessment', items: strings(note.assessment) },\n { heading: 'Plan', items: strings(note.plan) },\n ...(followUp ? [{ heading: 'Follow-up', items: [followUp] }] : []),\n ],\n actions: [],\n medications: medicationsOf(note.medications),\n to_verify: strings(note.to_verify),\n };\n}\n\n/** Either shape, defensively: a field of the wrong type reads empty, an unknown kind as plain notes. */\nexport function shapeNote(raw: Json): DictationNote {\n if (!Array.isArray(raw.sections)) return fromClinical(raw as unknown as ClinicalNote);\n const kind = isDictationKind(raw.kind) ? raw.kind : 'general';\n const sections: NoteSection[] = raw.sections\n .map(asRecord)\n .filter((s): s is Json => !!s && !!str(s.heading))\n .map((s) => ({ heading: str(s.heading), items: strings(s.items) }));\n return {\n kind,\n title: str(raw.title) || 'Notes',\n summary: str(raw.summary),\n sections,\n actions: strings(raw.actions),\n medications: medicationsOf(raw.medications),\n to_verify: strings(raw.to_verify),\n };\n}\n\n/** Nothing worth a note was said: no summary, no task, no section with anything in it. */\nexport function noteIsEmpty(note: DictationNote): boolean {\n return !note.summary && !note.actions.length && !note.sections.some((s) => s.items.length);\n}\n\n/** The SOAP note a visit note came from, for a connector that only reads that shape. */\nexport function toClinical(note: DictationNote): ClinicalNote {\n const items = (heading: string) =>\n note.sections.find((s) => s.heading.toLowerCase() === heading.toLowerCase())?.items ?? [];\n const others = note.sections.filter(\n (s) => !SOAP.some((h) => h.toLowerCase() === s.heading.toLowerCase()) && s.heading !== 'Follow-up',\n );\n return {\n title: note.title,\n subjective: items('Subjective'),\n objective: items('Objective'),\n assessment: items('Assessment'),\n plan: [...items('Plan'), ...others.flatMap((s) => s.items)],\n medications: note.medications,\n follow_up: items('Follow-up').join(' '),\n to_verify: note.to_verify,\n };\n}\n\nfunction turnsOf(v: unknown): ChatTurn[] {\n return (Array.isArray(v) ? v : [])\n .map(asRecord)\n .filter((t): t is Json => !!t && !!str(t.text))\n .map((t) => ({ role: t.role === 'assistant' ? 'assistant' : 'user', text: str(t.text), at: str(t.at) }));\n}\n\n/** A saved record as this build reads it: notes in the dictation shape, the chat well formed. */\nexport function upgradeRecord(record: DictationRecord): DictationRecord {\n const note = asRecord(record.note);\n const redaction = asRecord(record.redaction);\n const redactedNote = asRecord(redaction?.note);\n const chat = asRecord(record.chat);\n return {\n ...record,\n ...(note ? { note: shapeNote(note) } : {}),\n ...(record.redaction && redactedNote\n ? { redaction: { ...record.redaction, note: shapeNote(redactedNote) } }\n : {}),\n ...(chat\n ? {\n chat: {\n turns: turnsOf(chat.turns),\n identifiers: Array.isArray(chat.identifiers) ? (record.chat?.identifiers ?? []) : [],\n },\n }\n : {}),\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAUO,MAAM,QAAW,GAAA,CAAC,CAA4B,KAAA,CAAA,IAAK,OAAO,CAAA,KAAM,QAAY,IAAA,CAAC,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA,GAAI,CAAY,GAAA;AACtG,MAAA,GAAA,GAAM,CAAC,CAAuB,KAAA,OAAO,MAAM,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NOTE_DISCLAIMER = "AI draft from a dictation. Review before use.";
|
|
2
|
-
const SUGGESTION_DISCLAIMER = "AI suggestions for you to consider, not medical advice.";
|
|
3
|
-
const SUGGESTION_HEADINGS = {
|
|
4
|
-
safety: "Check for safety",
|
|
5
|
-
missing: "Missing from the note",
|
|
6
|
-
coding: "Coding",
|
|
7
|
-
follow_up: "Follow-up"
|
|
8
|
-
};
|
|
1
|
+
import {ACTIONS_HEADING,suggestionDisclaimer,SUGGESTION_ORDER,suggestionHeading}from'./kinds.js';const NOTE_DISCLAIMER = "AI draft from a dictation. Review before use.";
|
|
9
2
|
const ACTION_LABEL = {
|
|
10
3
|
start: "start",
|
|
11
4
|
continue: "continue",
|
|
@@ -24,17 +17,15 @@ function noteToText(note, transcript, suggestions) {
|
|
|
24
17
|
lines.push("", heading, ...items.map((item) => `- ${item}`));
|
|
25
18
|
};
|
|
26
19
|
section("CHECK BEFORE USE", note.to_verify);
|
|
27
|
-
|
|
28
|
-
section(
|
|
29
|
-
section(
|
|
30
|
-
section("PLAN", note.plan);
|
|
20
|
+
if (note.summary) lines.push("", note.summary);
|
|
21
|
+
for (const s of note.sections) section(s.heading.toUpperCase(), s.items);
|
|
22
|
+
section(ACTIONS_HEADING[note.kind], note.actions);
|
|
31
23
|
section("MEDICATIONS", note.medications.map(medicationLine));
|
|
32
|
-
if (note.follow_up.trim()) lines.push("", "FOLLOW-UP", note.follow_up.trim());
|
|
33
24
|
if (suggestions == null ? void 0 : suggestions.length) {
|
|
34
|
-
lines.push("", "SUGGESTIONS",
|
|
35
|
-
for (const kind of
|
|
25
|
+
lines.push("", "SUGGESTIONS", suggestionDisclaimer(note.kind));
|
|
26
|
+
for (const kind of SUGGESTION_ORDER) {
|
|
36
27
|
const group = suggestions.filter((s) => s.kind === kind);
|
|
37
|
-
if (group.length) lines.push(`${
|
|
28
|
+
if (group.length) lines.push(`${suggestionHeading(kind, note.kind)}:`, ...group.map((s) => `- ${s.text}${s.why ? ` (${s.why})` : ""}`));
|
|
38
29
|
}
|
|
39
30
|
}
|
|
40
31
|
if (transcript == null ? void 0 : transcript.trim()) lines.push("", "TRANSCRIPT", transcript.trim());
|
|
@@ -47,4 +38,4 @@ function formatDuration(ms) {
|
|
|
47
38
|
const s = total % 60;
|
|
48
39
|
const ss = String(s).padStart(2, "0");
|
|
49
40
|
return h ? `${h}:${String(m).padStart(2, "0")}:${ss}` : `${m}:${ss}`;
|
|
50
|
-
}export{NOTE_DISCLAIMER,
|
|
41
|
+
}export{NOTE_DISCLAIMER,formatDuration,medicationLine,noteToText};//# sourceMappingURL=noteText.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noteText.js","sources":["../../../src/features/dictate/noteText.ts"],"sourcesContent":["/**\n * The note as plain text, for Copy and Share: section headings in capitals,\n * one item per line, the checks first so they cannot be missed once pasted,\n * and the transcript last, as the screen shows it under the note.\n */\nimport type {
|
|
1
|
+
{"version":3,"file":"noteText.js","sources":["../../../src/features/dictate/noteText.ts"],"sourcesContent":["/**\n * The note as plain text, for Copy and Share: section headings in capitals,\n * one item per line, the checks first so they cannot be missed once pasted,\n * and the transcript last, as the screen shows it under the note.\n */\nimport { ACTIONS_HEADING, SUGGESTION_ORDER, suggestionDisclaimer, suggestionHeading } from './kinds';\nimport type { DictationNote, NoteMedication, NoteSuggestion } from './types';\n\nexport const NOTE_DISCLAIMER = 'AI draft from a dictation. Review before use.';\n\nconst ACTION_LABEL: Record<NoteMedication['action'], string> = {\n start: 'start',\n continue: 'continue',\n change: 'change',\n stop: 'stop',\n mentioned: 'mentioned',\n};\n\n/** \"lisinopril 20 mg PO once daily (change)\" - only the parts that were dictated. */\nexport function medicationLine(med: NoteMedication): string {\n const parts = [med.name, med.dose, med.route, med.frequency].map((p) => p.trim()).filter(Boolean);\n return `${parts.join(' ')} (${ACTION_LABEL[med.action]})`;\n}\n\nexport function noteToText(note: DictationNote, transcript?: string, suggestions?: NoteSuggestion[] | null): string {\n const lines: string[] = [note.title, NOTE_DISCLAIMER];\n const section = (heading: string, items: string[]) => {\n if (!items.length) return;\n lines.push('', heading, ...items.map((item) => `- ${item}`));\n };\n section('CHECK BEFORE USE', note.to_verify);\n if (note.summary) lines.push('', note.summary);\n for (const s of note.sections) section(s.heading.toUpperCase(), s.items);\n section(ACTIONS_HEADING[note.kind], note.actions);\n section('MEDICATIONS', note.medications.map(medicationLine));\n if (suggestions?.length) {\n lines.push('', 'SUGGESTIONS', suggestionDisclaimer(note.kind));\n for (const kind of SUGGESTION_ORDER) {\n const group = suggestions.filter((s) => s.kind === kind);\n if (group.length)\n lines.push(\n `${suggestionHeading(kind, note.kind)}:`,\n ...group.map((s) => `- ${s.text}${s.why ? ` (${s.why})` : ''}`),\n );\n }\n }\n if (transcript?.trim()) lines.push('', 'TRANSCRIPT', transcript.trim());\n return lines.join('\\n');\n}\n\n/** \"4:07\" or \"1:02:09\". */\nexport function formatDuration(ms: number): string {\n const total = Math.max(0, Math.floor(ms / 1000));\n const h = Math.floor(total / 3600);\n const m = Math.floor((total % 3600) / 60);\n const s = total % 60;\n const ss = String(s).padStart(2, '0');\n return h ? `${h}:${String(m).padStart(2, '0')}:${ss}` : `${m}:${ss}`;\n}\n"],"names":[],"mappings":"iGAOO,MAAM,eAAkB,GAAA;AAC/B,MAAM,YAAyD,GAAA;AAAA,EAC7D,KAAO,EAAA,OAAA;AAAA,EACP,QAAU,EAAA,UAAA;AAAA,EACV,MAAQ,EAAA,QAAA;AAAA,EACR,IAAM,EAAA,MAAA;AAAA,EACN,SAAW,EAAA;AACb,CAAA;AAGO,SAAS,eAAe,GAA6B,EAAA;AAC1D,EAAA,MAAM,QAAQ,CAAC,GAAA,CAAI,MAAM,GAAI,CAAA,IAAA,EAAM,IAAI,KAAO,EAAA,GAAA,CAAI,SAAS,CAAA,CAAE,IAAI,CAAK,CAAA,KAAA,CAAA,CAAE,MAAM,CAAA,CAAE,OAAO,OAAO,CAAA;AAC9F,EAAO,OAAA,CAAA,EAAG,MAAM,IAAK,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,25 +72,85 @@ function labelText(text) {
|
|
|
72
72
|
return text.replace(PLACEHOLDER, (token) => `[${placeholderLabel(token)}]`);
|
|
73
73
|
}
|
|
74
74
|
function mapNote(note, fn) {
|
|
75
|
-
return {
|
|
75
|
+
return __spreadProps(__spreadValues({}, note), {
|
|
76
76
|
title: fn(note.title),
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
summary: fn(note.summary),
|
|
78
|
+
sections: note.sections.map((s) => ({
|
|
79
|
+
heading: fn(s.heading),
|
|
80
|
+
items: s.items.map(fn)
|
|
81
|
+
})),
|
|
82
|
+
actions: note.actions.map(fn),
|
|
81
83
|
medications: note.medications.map((m) => __spreadProps(__spreadValues({}, m), {
|
|
82
84
|
name: fn(m.name),
|
|
83
85
|
dose: fn(m.dose),
|
|
84
86
|
route: fn(m.route),
|
|
85
87
|
frequency: fn(m.frequency)
|
|
86
88
|
})),
|
|
87
|
-
follow_up: fn(note.follow_up),
|
|
88
89
|
to_verify: note.to_verify.map(fn)
|
|
89
|
-
};
|
|
90
|
+
});
|
|
90
91
|
}
|
|
91
92
|
function mapSuggestions(items, fn) {
|
|
92
93
|
return items.map((s) => __spreadProps(__spreadValues({}, s), {
|
|
93
94
|
text: fn(s.text),
|
|
94
95
|
why: fn(s.why)
|
|
95
96
|
}));
|
|
96
|
-
}
|
|
97
|
+
}
|
|
98
|
+
function mapTurns(turns, fn) {
|
|
99
|
+
return turns.map((t) => __spreadProps(__spreadValues({}, t), {
|
|
100
|
+
text: fn(t.text)
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
function knownIdentifiers(record) {
|
|
104
|
+
var _a, _b, _c, _d, _e, _f;
|
|
105
|
+
const seen = /* @__PURE__ */ new Set();
|
|
106
|
+
return [...(_b = (_a = record.redaction) == null ? void 0 : _a.identifiers) != null ? _b : [], ...(_d = (_c = record.suggestions) == null ? void 0 : _c.identifiers) != null ? _d : [], ...(_f = (_e = record.chat) == null ? void 0 : _e.identifiers) != null ? _f : []].filter((id) => !seen.has(id.token) && !!seen.add(id.token));
|
|
107
|
+
}
|
|
108
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
109
|
+
function wordRe(value, ignoreCase) {
|
|
110
|
+
const flags = ignoreCase ? "gi" : "g";
|
|
111
|
+
try {
|
|
112
|
+
return new RegExp(`(^|[^\\p{L}\\p{N}_])(${escapeRe(value)})(?![\\p{L}\\p{N}_])`, `${flags}u`);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
return new RegExp(`(^|[^A-Za-z0-9_\\u00C0-\\u024F])(${escapeRe(value)})(?![A-Za-z0-9_\\u00C0-\\u024F])`, flags);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const NOT_A_NAME = /* @__PURE__ */ new Set(["dr", "doctor", "mr", "mrs", "ms", "miss", "mx", "prof", "professor", "nurse", "the", "and", "of"]);
|
|
118
|
+
const capitalised = (word) => word[0] !== word[0].toLowerCase();
|
|
119
|
+
const digitsRe = (digits) => new RegExp(`(^|[^0-9])(\\(?${digits.split("").join("[\\s().-]*")})(?![0-9])`, "g");
|
|
120
|
+
const MIN_ID_DIGITS = 6;
|
|
121
|
+
function hideKnown(text, identifiers) {
|
|
122
|
+
const swaps = identifiers.map((id) => __spreadProps(__spreadValues({}, id), {
|
|
123
|
+
value: id.value.trim()
|
|
124
|
+
})).filter((id) => id.value.length >= 2).flatMap((id) => {
|
|
125
|
+
const whole = {
|
|
126
|
+
size: id.value.length,
|
|
127
|
+
token: id.token,
|
|
128
|
+
re: wordRe(id.value, true)
|
|
129
|
+
};
|
|
130
|
+
const digits = id.value.replace(/\D/g, "");
|
|
131
|
+
if (digits.length >= MIN_ID_DIGITS) return [whole, __spreadProps(__spreadValues({}, whole), {
|
|
132
|
+
re: digitsRe(digits)
|
|
133
|
+
})];
|
|
134
|
+
if (id.kind !== "name" && id.kind !== "clinician") return [whole];
|
|
135
|
+
const parts = id.value.split(/\s+/).map((part) => part.replace(/[.,]/g, "")).filter((word) => word.length >= 3 && capitalised(word) && !NOT_A_NAME.has(word.toLowerCase())).map((word) => ({
|
|
136
|
+
size: word.length,
|
|
137
|
+
token: id.token,
|
|
138
|
+
re: wordRe(word, false)
|
|
139
|
+
}));
|
|
140
|
+
return [whole, ...parts];
|
|
141
|
+
}).sort((a, b) => b.size - a.size);
|
|
142
|
+
return swaps.reduce((acc, swap) => {
|
|
143
|
+
let hidden = 0;
|
|
144
|
+
const out = acc.text.replace(swap.re, (_m, before) => {
|
|
145
|
+
hidden += 1;
|
|
146
|
+
return `${before}${swap.token}`;
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
text: out,
|
|
150
|
+
hidden: acc.hidden + hidden
|
|
151
|
+
};
|
|
152
|
+
}, {
|
|
153
|
+
text,
|
|
154
|
+
hidden: 0
|
|
155
|
+
});
|
|
156
|
+
}export{hideKnown,knownIdentifiers,labelText,mapNote,mapSuggestions,mapTurns,placeholderLabel,restoreText,splitPlaceholders};//# sourceMappingURL=privacy.js.map
|