# Testplan: Cortex Intake Blocks MVP

**Project:** Cortex Intake Blocks - MVP
**Versie:** v1.0
**Datum:** 03-02-2026
**Status:** E6.S2 - E2E Testing

---

## 1. Overzicht

Dit testplan beschrijft de tests voor de 4 MVP intents:
- `intake_status` → IntakeStatusBlock
- `risico_query` → RisicoBlock
- `diagnose_query` → DiagnoseBlock
- `intake_navigeer` → Navigatie handler

### Test Niveaus

| Niveau | Type | Tools | Status |
|--------|------|-------|--------|
| L1 | Unit Tests | Vitest/Jest | ⏳ |
| L2 | API Tests | curl/httpie | ✅ Ready |
| L3 | Component Tests | Browser DevTools | ✅ Ready |
| L4 | E2E Tests | Manual checklist | ✅ Ready |

---

## 2. Prerequisities

### 2.1 Test Data Vereisten

**Patiënt met actieve intake:**
- Patiënt ID: `_______________`
- Intake ID: `_______________`
- Status: `bezig`

**Intake moet bevatten:**
- [x] Minimaal 1 contact moment
- [x] Minimaal 1 anamnese entry
- [x] Minimaal 1 risico assessment (met variërende levels)
- [x] Kindcheck ingevuld
- [x] Minimaal 1 diagnose (primair + secundair)
- [x] Behandeladvies

### 2.2 Browser Setup

```bash
# Start development server
pnpm dev

# Open browser
open http://localhost:3000/epd/dashboard
```

### 2.3 Test Account

- Ingelogd als behandelaar
- Toegang tot testpatiënt

---

## 3. L2: API Tests

### 3.1 Status API

```bash
# Basis test - met patientId
curl -X GET "http://localhost:3000/api/cortex/intake/status?patientId=<UUID>" \
  -H "Cookie: <session_cookie>"

# Met expliciete intakeId
curl -X GET "http://localhost:3000/api/cortex/intake/status?patientId=<UUID>&intakeId=<UUID>" \
  -H "Cookie: <session_cookie>"
```

**Verwachte response:**
```json
{
  "intakeId": "uuid",
  "patientId": "uuid",
  "completionPercentage": 67,
  "status": "bezig",
  "sections": [
    { "id": "contacts", "label": "Contactmomenten", "required": false, "completed": true, "count": 3 },
    { "id": "anamnese", "label": "Anamnese", "required": true, "completed": true, "count": 1 }
  ],
  "completedCount": 6,
  "totalRequired": 5,
  "lastUpdated": "2026-02-03T10:00:00Z"
}
```

| Test Case | Input | Verwacht | ✓/✗ |
|-----------|-------|----------|-----|
| AS-01 | Geldige patientId | 200 + data | |
| AS-02 | Ontbrekende patientId | 400 error | |
| AS-03 | Ongeldige UUID | 400 error | |
| AS-04 | Niet-bestaande patient | 404 "Geen actieve intake" | |
| AS-05 | Geen auth cookie | 401 error | |

---

### 3.2 Risico API

```bash
curl -X GET "http://localhost:3000/api/cortex/intake/risico?patientId=<UUID>" \
  -H "Cookie: <session_cookie>"
```

**Verwachte response:**
```json
{
  "intakeId": "uuid",
  "patientId": "uuid",
  "risks": [
    {
      "id": "uuid",
      "type": "Suïcidaliteit",
      "level": "matig",
      "rationale": "...",
      "measures": "...",
      "assessmentDate": "2026-01-15",
      "evaluationDate": "2026-02-15",
      "notes": "..."
    }
  ],
  "summary": {
    "total": 3,
    "highestLevel": "matig",
    "hasSuicideRisk": true,
    "hasSelfHarmRisk": false,
    "hasAggressionRisk": true
  },
  "lastUpdated": "2026-02-03T10:00:00Z"
}
```

| Test Case | Input | Verwacht | ✓/✗ |
|-----------|-------|----------|-----|
| AR-01 | Geldige patientId | 200 + risks array | |
| AR-02 | Intake zonder risico's | 200 + empty array | |
| AR-03 | Risico met level "acuut" | highestLevel = "acuut" | |
| AR-04 | Suicide keyword | hasSuicideRisk = true | |
| AR-05 | Ontbrekende patientId | 400 error | |

---

### 3.3 Diagnose API

```bash
curl -X GET "http://localhost:3000/api/cortex/intake/diagnose?patientId=<UUID>" \
  -H "Cookie: <session_cookie>"
```

**Verwachte response:**
```json
{
  "intakeId": "uuid",
  "patientId": "uuid",
  "diagnoses": [
    {
      "id": "uuid",
      "code": "F32.1",
      "description": "Depressieve stoornis, matig",
      "codeSystem": "ICD-10",
      "clinicalStatus": "active",
      "severity": "matig",
      "isPrimary": true,
      "notes": "...",
      "recordedDate": "2026-01-15"
    }
  ],
  "summary": {
    "total": 3,
    "primaryDiagnosis": { ... },
    "secondaryCount": 2,
    "hasActiveConditions": true
  },
  "lastUpdated": "2026-02-03T10:00:00Z"
}
```

| Test Case | Input | Verwacht | ✓/✗ |
|-----------|-------|----------|-----|
| AD-01 | Geldige patientId | 200 + diagnoses | |
| AD-02 | Intake zonder diagnoses | 200 + empty array | |
| AD-03 | Primaire diagnose aanwezig | isPrimary = true | |
| AD-04 | Active status | hasActiveConditions = true | |
| AD-05 | ICD-10 code aanwezig | codeSystem = "ICD-10" | |

---

## 4. L3: Intent Classification Tests

### 4.1 Reflex Classifier Tests

Open browser console op `/epd/dashboard` en test:

```javascript
// Test in console (als reflex-classifier beschikbaar is)
// Of test via Cortex input veld
```

**Handmatige tests via Cortex input:**

| Test ID | Input | Verwacht Intent | Confidence | ✓/✗ |
|---------|-------|-----------------|------------|-----|
| RC-01 | "moet ik nog doen" | intake_status | 1.0 | |
| RC-02 | "wat moet ik nog invullen" | intake_status | 1.0 | |
| RC-03 | "is de intake compleet" | intake_status | 0.95 | |
| RC-04 | "intake checklist" | intake_status | 0.95 | |
| RC-05 | "intake status" | intake_status | 0.95 | |
| RC-06 | "wat zijn de risico's" | risico_query | 1.0 | |
| RC-07 | "risicotaxatie" | risico_query | 0.95 | |
| RC-08 | "toon risico's" | risico_query | 0.95 | |
| RC-09 | "welke diagnoses" | diagnose_query | 1.0 | |
| RC-10 | "wat is de diagnose" | diagnose_query | 0.95 | |
| RC-11 | "toon diagnoses" | diagnose_query | 0.95 | |
| RC-12 | "ga naar risico" | intake_navigeer | 1.0 | |
| RC-13 | "ga naar diagnose" | intake_navigeer | 1.0 | |
| RC-14 | "naar anamnese" | intake_navigeer | 0.9 | |
| RC-15 | "open kindcheck" | intake_navigeer | 0.95 | |

### 4.2 Escalation Tests

| Test ID | Input | Verwacht | Reden | ✓/✗ |
|---------|-------|----------|-------|-----|
| ES-01 | "risico's en maak notitie" | Escalate | multi_intent | |
| ES-02 | "diagnoses van hem" | Escalate | needs_context | |
| ES-03 | "risico morgen bekijken" | Escalate | relative_time | |

---

## 5. L4: E2E Scenario Tests

### 5.1 Scenario: Intake Status Bekijken

**Precondities:**
- Ingelogd
- Patiënt met actieve intake geselecteerd in context

**Stappen:**

| Stap | Actie | Verwacht Resultaat | ✓/✗ |
|------|-------|-------------------|-----|
| 1 | Open Cortex (⌘K) | Command input verschijnt | |
| 2 | Type "wat moet ik nog doen" | Input wordt herkend | |
| 3 | Submit (⌘Enter of Enter) | IntakeStatusBlock opent | |
| 4 | Wacht op laden | Loading spinner → data | |
| 5 | Check completion ring | Percentage en kleur correct | |
| 6 | Check verplichte secties | Gemarkeerd met badge | |
| 7 | Check openstaande secties | Amber highlighted | |
| 8 | Klik op sectie | Navigeert naar EPD tab | |

**Verwachte States:**

| State | Trigger | Weergave |
|-------|---------|----------|
| Loading | API call actief | Spinner + "Intake status laden..." |
| Success | Data ontvangen | Completion ring + secties lijst |
| Error | API fout | Foutmelding + "Opnieuw proberen" |
| Empty | Geen intake | "Geen intake gevonden" |
| No Patient | Geen context | "Selecteer eerst een patiënt" |

---

### 5.2 Scenario: Risico's Bekijken

**Stappen:**

| Stap | Actie | Verwacht Resultaat | ✓/✗ |
|------|-------|-------------------|-----|
| 1 | Type "wat zijn de risico's" | Input herkend | |
| 2 | Submit | RisicoBlock opent | |
| 3 | Check summary card | Totaal + hoogste level | |
| 4 | Check risk flags | Suïcide/zelfbesch./agressie | |
| 5 | Check risk items | Level badges correct | |
| 6 | Klik "Naar risicotaxaties" | Navigeert naar EPD | |

**Level Kleuren:**

| Level | Badge Kleur | Achtergrond |
|-------|-------------|-------------|
| laag | Groen | bg-green-50 |
| matig | Oranje | bg-amber-50 |
| hoog | Rood (licht) | bg-red-50 |
| acuut | Rood | bg-red-100 |

---

### 5.3 Scenario: Diagnoses Bekijken

**Stappen:**

| Stap | Actie | Verwacht Resultaat | ✓/✗ |
|------|-------|-------------------|-----|
| 1 | Type "welke diagnoses" | Input herkend | |
| 2 | Submit | DiagnoseBlock opent | |
| 3 | Check hoofddiagnose | Highlighted card | |
| 4 | Check ICD-10 code | Code + omschrijving | |
| 5 | Check nevendiagnoses | Lijst met badges | |
| 6 | Check status badges | Actief/Remissie/etc | |
| 7 | Klik "Naar diagnoses" | Navigeert naar EPD | |

---

### 5.4 Scenario: Navigatie naar Intake Tab

**Stappen:**

| Stap | Actie | Verwacht Resultaat | ✓/✗ |
|------|-------|-------------------|-----|
| 1 | Selecteer patiënt | Context bar toont naam | |
| 2 | Type "ga naar risico" | Intent herkend | |
| 3 | Submit | Toast verschijnt | |
| 4 | Check toast | "Navigeren... Naar risico sectie" | |
| 5 | Check URL | /epd/patients/{id}/intakes | |

**Tab Mapping Test:**

| Input | Verwachte Tab | ✓/✗ |
|-------|---------------|-----|
| "ga naar risico" | risk | |
| "ga naar diagnose" | diagnosis | |
| "ga naar anamnese" | anamnese | |
| "ga naar kindcheck" | kindcheck | |
| "ga naar contact" | contacts | |
| "ga naar rom" | rom | |
| "ga naar behandeladvies" | behandeladvies | |
| "ga naar onderzoek" | examination | |

---

### 5.5 Scenario: Error Handling

| Test | Actie | Verwacht | ✓/✗ |
|------|-------|----------|-----|
| EH-01 | Geen patiënt + "risico's" | BlockEmpty: "Selecteer eerst een patiënt" | |
| EH-02 | Geen intake + "status" | BlockEmpty: "Geen intake gevonden" | |
| EH-03 | Netwerk uit + refetch | BlockError met retry optie | |
| EH-04 | Geen patiënt + "ga naar risico" | Toast: "Geen patiënt geselecteerd" | |

---

## 6. Voice Input Tests

**Vereist:** Deepgram API key geconfigureerd

| Test | Gesproken Input | Verwacht | ✓/✗ |
|------|-----------------|----------|-----|
| V-01 | "Wat moet ik nog doen?" | intake_status | |
| V-02 | "Wat zijn de risico's?" | risico_query | |
| V-03 | "Welke diagnoses?" | diagnose_query | |
| V-04 | "Ga naar risico" | intake_navigeer | |
| V-05 | "Toon risicotaxatie" | risico_query | |

---

## 7. Edge Cases

### 7.1 Data Edge Cases

| Test | Scenario | Verwacht | ✓/✗ |
|------|----------|----------|-----|
| EC-01 | 0 risico's | "Geen specifieke risico's" | |
| EC-02 | 0 diagnoses | "Geen diagnoses gevonden" | |
| EC-03 | Geen primaire diagnose | "Geen hoofddiagnose" placeholder | |
| EC-04 | Alle secties compleet | 100% ring (groen) | |
| EC-05 | 0 secties compleet | 0% ring (rood) | |
| EC-06 | Zeer lange diagnose tekst | Truncatie/wrap | |

### 7.2 Input Edge Cases

| Test | Input | Verwacht | ✓/✗ |
|------|-------|----------|-----|
| IC-01 | "" (leeg) | Geen actie | |
| IC-02 | "RISICO'S" (uppercase) | risico_query | |
| IC-03 | "  diagnoses  " (spaties) | diagnose_query | |
| IC-04 | "risico diagnose" (ambiguous) | Escalate of hoogste | |

---

## 8. Performance Tests

| Metric | Target | Acceptabel | Meting | ✓/✗ |
|--------|--------|------------|--------|-----|
| Reflex classification | <20ms | <50ms | ___ms | |
| API /status | <500ms | <2s | ___ms | |
| API /risico | <500ms | <2s | ___ms | |
| API /diagnose | <500ms | <2s | ___ms | |
| Block render | <100ms | <300ms | ___ms | |

---

## 9. Test Resultaten Samenvatting

### API Tests
- [ ] AS-01 t/m AS-05: ___/5 passed
- [ ] AR-01 t/m AR-05: ___/5 passed
- [ ] AD-01 t/m AD-05: ___/5 passed

### Intent Classification
- [ ] RC-01 t/m RC-15: ___/15 passed
- [ ] ES-01 t/m ES-03: ___/3 passed

### E2E Scenarios
- [ ] Intake Status: ___/8 stappen OK
- [ ] Risico's: ___/6 stappen OK
- [ ] Diagnoses: ___/7 stappen OK
- [ ] Navigatie: ___/5 stappen OK + ___/8 tabs OK

### Edge Cases
- [ ] Data: ___/6 passed
- [ ] Input: ___/4 passed

### Voice Input
- [ ] V-01 t/m V-05: ___/5 passed

### Performance
- [ ] Alle metrics binnen target: Ja/Nee

---

## 10. Bekende Issues / Opmerkingen

| # | Issue | Prioriteit | Status |
|---|-------|------------|--------|
| 1 | | | |
| 2 | | | |
| 3 | | | |

---

## 11. Sign-off

| Rol | Naam | Datum | Akkoord |
|-----|------|-------|---------|
| Tester | | | |
| Developer | | | |
| Product Owner | | | |

---

## Versiehistorie

| Versie | Datum | Auteur | Wijziging |
|--------|-------|--------|-----------|
| v1.0 | 03-02-2026 | Colin Lit | Initieel testplan |
