File size: 10,432 Bytes
cc678b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# Agent instructions — CarePath unified

CarePath is one unified medical AI product with two clearly separated user-facing modules:

1. **Ghi chép bệnh án AI**
   Internal/technical term: AI Scribe / scriber
   Backend: `scribe/carepath`, `/api/v1/*`
   Purpose: listen to a consultation and help generate structured clinical notes.

2. **Phiên dịch khám bệnh trực tiếp**
   Internal/technical term: Medical Interpreter / interpreter
   Backend: `interpreter/app`, `/api/*` + `/ws/*`
   Purpose: live two-way interpretation between Vietnamese doctors and English-speaking patients.

The app is served by one FastAPI process plus two Vite frontends:

* `scribe/frontend/` at `/`
* `interpreter/frontend/` at `/phien-dich-y-khoa/` (`/console/` is a legacy redirect)

## Interpreter status

After restructure Phase 7, the Interpreter is on hold. Accept only bug fixes,
safety fixes, and required operational maintenance there; new product work is
focused on the Scribe training track unless the owner explicitly reopens it.

`docs/history/PLAN.md` and `docs/history/DEMO-SITE-PLAN.md` are historical build
plans for the interpreter and demo site. `docs/history/MERGE-PLAN.md` is the
executed unification plan, M.0–M.8 done, and `docs/history/JUDGE.md` is its
review protocol.
`docs/research.md` holds the interpreter safety background.

## Product UX contract

CarePath must be Vietnamese-first.

The target users may include Vietnamese doctors who are not comfortable with English medical software terms. Therefore, the UI must explain workflows by user intent, not by English product names.

### Primary user-facing labels

Use these as primary UI labels:

* `Ghi chép bệnh án AI`
* `Phiên dịch khám bệnh trực tiếp`

Use these as primary CTAs:

* `Bắt đầu ghi chép`
* `Bắt đầu phiên dịch`

Use this homepage framing:

```text
Bạn muốn hỗ trợ việc gì hôm nay?
```

### Secondary/internal labels

The following English terms may appear only as secondary helper text, developer labels, comments, docs, or internal route/component names:

* Scribe
* AI Scribe
* Interpreter
* Medical Interpreter
* Console
* Transcript
* Encounter
* Session

Do not use `Scribe` or `Interpreter` as primary labels on user-facing screens.

### Required distinction between the two modules

The landing page must make it obvious that these are two different workflows:

#### Ghi chép bệnh án AI

Explain as:

```text
AI nghe buổi khám và tạo ghi chú y khoa có cấu trúc.
```

Use when:

```text
Phù hợp khi bác sĩ muốn giảm thời gian nhập liệu sau khám.
```

Clarify that the doctor must review the output before use.

#### Phiên dịch khám bệnh trực tiếp

Explain as:

```text
Dịch hai chiều giữa bác sĩ tiếng Việt và bệnh nhân tiếng Anh trong lúc khám.
```

Use when:

```text
Phù hợp khi bác sĩ và bệnh nhân không cùng ngôn ngữ.
```

Clarify that the system translates only and must not provide medical advice.

### Every user-facing screen must answer

1. Tôi đang dùng chức năng nào?
2. Chức năng này giúp việc gì?
3. Tôi cần bấm gì tiếp theo?
4. Có rủi ro hoặc giới hạn nào bác sĩ cần biết không?

### Vietnamese copy rules

* Vietnamese text must be clear, short, and professional.
* Preserve Vietnamese diacritics.
* Keep text NFC-normalized.
* Avoid unnecessary English.
* Avoid startup/marketing buzzwords on clinical workflow screens.
* Prefer concrete action language over abstract product names.

Good:

```text
Ghi chép bệnh án AI
Phiên dịch khám bệnh trực tiếp
Bắt đầu ghi chép
Bắt đầu phiên dịch
Bác sĩ nói tiếng Việt, bệnh nhân nghe tiếng Anh
```

Avoid as primary UI:

```text
Scribe
Interpreter
Session
Encounter
Transcript
Start session
Launch interpreter
```

## Non-negotiable safety invariants

This file is the current safety contract. `docs/history/PLAN.md §2` preserves
the original MVP source for historical context.

1. Translate-only: never generate medical advice, diagnoses, or drug recommendations.
2. High/critical-risk turns are blocked from patient display and TTS until doctor confirms.
3. Low-confidence output is always visibly flagged, never silently delivered.
4. Raw audio is never persisted. Use memory-only processing. No audio columns, no temp files.
5. No mic capture before recorded consent.
6. On any pipeline or reviewer failure, fail closed: keep the turn blocked, show the doctor raw source and translation, offer escalation. Never fail open to the patient.

## Implementation workflow for agents

For UX or product-flow changes, do not implement immediately.

First produce or update a plan in `docs/ux-redesign-carepath.md` with:

1. Current UX problem
2. Proposed flow
3. Affected routes/pages/components
4. Vietnamese-first copy
5. Implementation stories
6. Dependencies between stories
7. Acceptance criteria
8. Validation commands
9. Risks and fallback behavior

Then implement one story at a time.

### Recommended story order for UX redesign

1. Update Vietnamese-first product naming and copy.
2. Redesign the landing page into two clear workflow cards.
3. Add or clarify separate entry routes for the two modules.
4. Add pre-start onboarding/explanation screens.
5. Improve empty/loading/error states in Vietnamese.
6. Run QA for mobile, accessibility, safety copy, and route regressions.

Do not combine homepage redesign, routing changes, and audio/backend logic changes in one large patch.

### Agent behavior

* Keep changes small and focused.
* Preserve existing working functionality.
* Do not rewrite backend, audio, risk, or websocket logic unless the current story explicitly requires it.
* Do not introduce new dependencies without documenting why.
* Prefer existing components and styling patterns.
* When changing user-facing Vietnamese text, check diacritics and consistency.
* When changing risk-engine behavior, update fixtures and evals.
* When changing product copy only, avoid touching medical logic.

## Commands

### Combined service

```bash
uvicorn carepath.main:app --app-dir scribe --reload
```

Requires:

```bash
pip install -e ".[dev]" -e "./shared" -e "./interpreter[dev]"
```

### Scriber and combined tests

```bash
pytest
python scripts/smoke_backend.py
python scripts/build_term_artifacts.py --check
```

### Interpreter backend alone

```bash
cd interpreter && uvicorn app.main:app --reload
pytest
```

### Console

```bash
cd interpreter/frontend && npm run dev
npm test
npx playwright test
```

### Demo site

```bash
cd scribe/frontend && npm run dev
npm test
npm run build
npm run e2e
```

`npm run build` is also the diacritics gate.

### Full mock-mode run

Set this in `.env`:

```bash
PROVIDER_MODE=mock
```

Mock mode must work with no API keys.

### Eval regression

```bash
python interpreter/eval/run_eval.py --set interpreter/eval/fixtures/eval_starter.tsv --providers mock
```

## Conventions

* Python 3.12.
* Python code must be ruff-formatted and type-hinted.
* Use pure functions for normalization and risk rules.
* TypeScript must be strict.
* Components should be small.
* Keep state minimal: context/zustand is allowed, Redux is not.
* `shared/carepath_shared/terms/medical_terms.json` is the canonical medical
  term source. Regenerate `data/medical_lexicon.json` and
  `interpreter/app/glossary/data/seed_glossary.csv` with
  `python scripts/build_term_artifacts.py`; do not hand-edit generated artifacts.
* Risk lexicons under `interpreter/app/risk/lexicons/` remain separate
  interpreter safety data. Clinicians edit data, not code.
* Every risk-engine behavior change updates `interpreter/eval/fixtures/risk_cases.jsonl`.
* The fixture run is the test.
* Zero misses on critical fixtures is a hard gate.
* Secrets only via env.
* `.env` is gitignored.
* `.env.example` must stay current.
* No new dependencies without noting why in the PR.
* Vietnamese text is data, not decoration: always NFC-normalized, diacritics preserved.
* Tests must include diacritic-stripped variants where matching allows it.

## Acceptance criteria for UX clarity changes

A UX clarity change is not done un  less all of the following are true:

1. A Vietnamese doctor can understand the two workflows without knowing the words `Scribe` or `Interpreter`.
2. The landing page clearly separates:

   * `Ghi chép bệnh án AI`
   * `Phiên dịch khám bệnh trực tiếp`
3. Each workflow has a distinct CTA.
4. Each workflow explains when to use it.
5. English terms appear only as secondary helper text, not primary labels.
6. Mobile layout remains clear.
7. Existing core functionality still works.
8. Safety invariants remain unchanged.
9. Build and relevant tests pass.

<!-- HARNESS:START -->
## Harness workflow

This repository uses Repository Harness for durable task intake, proof, and
decision records. This block adds to the CarePath instructions above; it does
not replace them.

Priority, highest first:

1. The current user request and the safety and product rules in this file.
2. Current product contracts in `docs/product/`.
3. Selected story packets in `docs/stories/` and accepted decisions in
   `docs/decisions/`.
4. Executable tests and the Harness proof matrix.
5. `docs/history/` as context only.

Before any task, read `README.md`, `docs/HARNESS.md`, and
`docs/FEATURE_INTAKE.md`; then run
`.\scripts\bin\harness-cli.exe query matrix` on Windows. Classify and record
the task as `tiny`, `normal`, or `high-risk` before changing code.

- Tiny work records an intake and runs the relevant quick proof.
- Normal work also updates one story packet and its proof record.
- High-risk work uses `docs/templates/high-risk-story/`, records a decision
  when it changes architecture, data, safety, APIs, or validation, and waits
  for human direction if its scope is ambiguous.
- A UX or product-flow task still must first update
  `docs/ux-redesign-carepath.md`, then follow the Harness lane requirements.
- Before a step that could use an external tool, query the available provider:
  `.\scripts\bin\harness-cli.exe query tools --capability <capability> --status present`.
  A missing provider is a clean skip, never a reason to invent a dependency.
- Finish normal and high-risk work with a Harness trace that records the real
  validation outcome and any friction. Do not claim proof that was not run.
<!-- HARNESS:END -->