# πŸ“Š Haalbaarheidsanalyse: Swift Medical Scribe v3.0 **Datum:** 27-12-2024 **Document:** `fo-swift-medical-scribe-v3.md` **Auteur:** AI Assistant --- ## Executive Summary Het v3.0 redesign van Swift naar een medical scribe chatbot interface is **haalbaar**, maar vereist significante architecturale wijzigingen. De bestaande foundation (Command Center, blocks, intent classification) kan worden hergebruikt, maar de conversatie-laag en split-screen layout zijn nieuw. **Kernbevindingen:** - βœ… **Sterke foundation:** Bestaande blocks, intent API, en voice input kunnen worden hergebruikt - ⚠️ **Grote wijzigingen:** Conversatie-interface, chat API, en split-screen layout zijn nieuw - βœ… **AI-infrastructuur:** Streaming chat API bestaat al (docs-chat), kan worden aangepast - ⚠️ **Complexiteit:** Conversatiegeschiedenis en context management vereisen nieuwe state management **Geschatte effort:** 6-8 weken (1 developer, full-time) --- ## 1. Inventarisatie Bestaande Componenten ### 1.1 βœ… Wat bestaat al en kan worden hergebruikt | Component | Status | Locatie | Hergebruik | |-----------|--------|---------|------------| | **Command Center** | βœ… Done | `components/swift/command-center/` | ⚠️ Layout wijzigen naar split-screen | | **Context Bar** | βœ… Done | `components/swift/command-center/context-bar.tsx` | βœ… Direct hergebruikbaar | | **Blocks (Artifacts)** | βœ… Done | `components/swift/blocks/` | βœ… Direct herbruikbaar | | **Intent Classification** | βœ… Done | `/api/intent/classify` | βœ… Herbruikbaar, maar moet worden uitgebreid | | **Voice Input** | βœ… Done | `lib/swift/use-swift-voice.ts` | βœ… Direct herbruikbaar | | **Swift Store** | βœ… Done | `stores/swift-store.ts` | ⚠️ Uitbreiden met chat state | | **Overdracht API** | βœ… Done | `/api/overdracht/generate` | βœ… Bestaat, maar AI-filtering voor psychiater moet worden toegevoegd | | **Streaming Chat API** | βœ… Bestaat | `/api/docs/chat` | βœ… Pattern kan worden gekopieerd | ### 1.2 πŸ†• Wat nieuw moet worden gebouwd | Component | Complexiteit | Geschatte Effort | |-----------|-------------|------------------| | **Chat Panel** | Medium | 1 week | | **Chat Input (conversational)** | Low | 3 dagen | | **Chat API (`/api/swift/chat`)** | High | 1.5 week | | **Artifact Area (split-screen)** | Medium | 1 week | | **Chat Message Components** | Low | 3 dagen | | **Conversation History Management** | Medium | 1 week | | **AI-filtering voor psychiater** | Medium | 1 week | | **Linked Evidence UI** | Low | 3 dagen | **Totaal nieuwe componenten:** ~6-7 weken --- ## 2. Gedetailleerde Analyse per Sectie ### 2.1 Command Center β†’ Split-Screen Layout **Huidige situatie:** - 4-zone layout: Context Bar | Canvas Area | Recent Strip | Command Input - Blocks verschijnen in Canvas Area (centered, full-width) **Vereiste wijziging:** - Split-screen: Chat Panel (40%) links, Artifact Area (60%) rechts - Recent Strip kan worden verwijderd of geΓ―ntegreerd in chat **Haalbaarheid:** βœ… **Goed** - Layout wijziging is relatief eenvoudig met CSS Grid/Flexbox - Bestaande blocks blijven werken, alleen positioning wijzigt - **Effort:** 3-5 dagen **Risico's:** - Responsive design voor mobile/tablet vereist toggle tussen chat en artifact - Keyboard shortcuts moeten worden aangepast --- ### 2.2 Chat Panel & Conversatie **Huidige situatie:** - Geen chat interface - Command Input stuurt direct naar intent classification **Vereiste wijziging:** - Nieuwe Chat Panel component met message bubbles - Conversatiegeschiedenis (max 100 messages) - Streaming responses (zoals docs-chat) **Haalbaarheid:** βœ… **Goed** - Pattern bestaat al in `components/docs-chat/` - `use-docs-chat.ts` hook kan worden aangepast voor Swift - **Effort:** 1 week **Risico's:** - Performance bij lange conversaties (pagination nodig) - State management voor chat history (Zustand store uitbreiden) --- ### 2.3 Medical Scribe Chat API **Huidige situatie:** - `/api/intent/classify` retourneert alleen intent + entities - Geen conversatie, geen streaming **Vereiste wijziging:** - Nieuwe `/api/swift/chat` endpoint - Streaming responses (SSE) - Conversatiegeschiedenis als input - Action objects in response (intent + entities + artifact prefill) **Haalbaarheid:** ⚠️ **Middelmatig** - Pattern bestaat in `/api/docs/chat` (streaming met Claude) - Moet worden uitgebreid met: - Intent detection tijdens conversatie - Action object generation - Context management (activePatient, shift, recentActions) - **Effort:** 1.5 week **Risico's:** - AI prompt engineering voor medical scribe persona - Performance bij hoge load (rate limiting nodig) - Kosten (Claude API calls per message) **Aanbeveling:** ```typescript // Hybrid approach: local intent first, AI voor conversatie 1. Local pattern matching (<50ms) β†’ direct action 2. Als geen match β†’ AI chat API met conversatie context 3. AI detecteert intent + genereert response + action object ``` --- ### 2.4 Intent Engine (Hybrid) **Huidige situatie:** - Two-tier: local patterns β†’ AI fallback - Werkt goed voor directe commando's **Vereiste wijziging:** - Local patterns blijven voor snelle acties - AI chat API voor conversatie + follow-up vragen - Confidence thresholds voor artifact opening **Haalbaarheid:** βœ… **Goed** - Bestaande intent classifier blijft werken - Chat API gebruikt AI voor conversatie + intent detection - **Effort:** 3 dagen (integratie) --- ### 2.5 Artifact Area (Split-Screen) **Huidige situatie:** - Blocks verschijnen centered in Canvas Area - EΓ©n block tegelijk **Vereiste wijziging:** - Artifacts rechts (60% width) - Meerdere artifacts mogelijk (tabs, max 3) - Slide-in animatie van rechts **Haalbaarheid:** βœ… **Goed** - Bestaande blocks blijven werken - Nieuwe wrapper component met tabs - **Effort:** 1 week **Risico's:** - State management voor meerdere open artifacts - Tab switching UX --- ### 2.6 AI-Filtering voor Psychiater **Huidige situatie:** - `/api/overdracht/generate` genereert samenvatting voor alle notities - Geen filtering op behandelrelevantie **Vereiste wijziging:** - AI-filtering: alleen behandelrelevante notities - Linked evidence: elke zin linkt naar bronnotitie - UI: "Behandelrelevant" vs "Geen bijzonderheden" secties **Haalbaarheid:** ⚠️ **Middelmatig** - AI prompt moet worden uitgebreid met filtering criteria - Linked evidence vereist tracking van bronnotities per zin - **Effort:** 1 week **Risico's:** - AI filtering accuracy (false negatives = belangrijke info gemist) - Linked evidence parsing (welke zin komt van welke notitie?) **Aanbeveling:** - Start met simpele keyword-based filtering als fallback - AI filtering als primary, met optie om "alles te tonen" --- ### 2.7 Store Uitbreiding **Huidige situatie:** ```typescript interface SwiftStore { activePatient: Patient | null; activeBlock: BlockType | null; prefillData: BlockPrefillData; // ... geen chat state } ``` **Vereiste wijziging:** ```typescript interface SwiftStore { // Bestaand activePatient: Patient | null; activeBlock: BlockType | null; // Nieuw: Chat state chatMessages: ChatMessage[]; isStreaming: boolean; pendingAction: Action | null; // Nieuw: Artifact state openArtifacts: Artifact[]; // Max 3 activeArtifactId: string | null; } ``` **Haalbaarheid:** βœ… **Goed** - Zustand store is makkelijk uit te breiden - **Effort:** 2 dagen --- ## 3. Technische Risico's & Uitdagingen ### 3.1 πŸ”΄ Hoge Risico's | Risico | Impact | Mitigatie | |--------|--------|-----------| | **AI Prompt Engineering** | High | Medical scribe persona moet natuurlijk klinken, maar ook betrouwbaar zijn. Iteratief testen met echte gebruikers. | | **Performance bij lange conversaties** | Medium | Pagination voor chat history, max 100 messages in view. Virtual scrolling overwegen. | | **AI Kosten** | Medium | Rate limiting, caching van responses waar mogelijk. Local patterns gebruiken voor snelle acties. | | **State Management Complexiteit** | Medium | Duidelijke scheiding tussen chat state en artifact state. UseReducer overwegen voor complexe state. | ### 3.2 🟑 Middelmatige Risico's | Risico | Impact | Mitigatie | |--------|--------|-----------| | **Responsive Design** | Medium | Mobile: toggle tussen chat en artifact. Tablet: 45/55 split. | | **Linked Evidence Parsing** | Medium | AI moet structured output geven met bronverwijzingen per zin. Fallback: keyword matching. | | **Conversatie Context Verlies** | Low | Context manager bewaart actieve patiΓ«nt, shift, recente acties. Max 20 messages in API call. | ### 3.3 🟒 Lage Risico's | Risico | Impact | Mitigatie | |--------|--------|-----------| | **Block Migratie** | Low | Bestaande blocks blijven werken, alleen wrapper wijzigt. | | **Voice Input** | Low | Bestaande implementatie blijft werken. | --- ## 4. Migratie Strategie ### 4.1 Fase 1: Foundation (Week 1-2) - βœ… Split-screen layout implementeren - βœ… Chat Panel component bouwen - βœ… Store uitbreiden met chat state - βœ… Basis chat API endpoint **Deliverable:** Werkende split-screen met chat (zonder AI) ### 4.2 Fase 2: Chat API & Conversatie (Week 3-4) - βœ… Medical scribe chat API implementeren - βœ… Streaming responses - βœ… Intent detection in conversatie - βœ… Action object generation **Deliverable:** Werkende conversatie met artifact opening ### 4.3 Fase 3: Artifact Area (Week 5) - βœ… Artifact Area component met tabs - βœ… Meerdere artifacts ondersteuning - βœ… Slide-in animaties **Deliverable:** Meerdere artifacts tegelijk mogelijk ### 4.4 Fase 4: AI-Filtering & Polish (Week 6-7) - βœ… AI-filtering voor psychiater overdracht - βœ… Linked evidence UI - βœ… Error handling & edge cases - βœ… Performance optimalisatie **Deliverable:** Volledige v3.0 functionaliteit ### 4.5 Fase 5: Testing & Refinement (Week 8) - βœ… User testing - βœ… Bug fixes - βœ… Performance tuning - βœ… Documentatie **Deliverable:** Production-ready v3.0 --- ## 5. Aanbevelingen ### 5.1 βœ… Doen 1. **Hergebruik bestaande patterns** - Kopieer `use-docs-chat.ts` hook als basis voor Swift chat - Hergebruik streaming pattern van `/api/docs/chat` 2. **Incrementele migratie** - Behoud oude Command Center tijdens ontwikkeling - Feature flag voor nieuwe interface - A/B testing mogelijkheid 3. **Local-first approach** - Gebruik local patterns voor snelle acties (zoals nu) - AI alleen voor conversatie en complexe queries 4. **Performance monitoring** - Track AI API response times - Monitor chat history size - Alert bij lange conversaties ### 5.2 ⚠️ Overwegen 1. **Hybrid Intent Detection** - Local patterns voor P1 intents (dagnotitie, zoeken) - AI chat voor P2 intents en follow-up vragen 2. **Conversation Context Window** - Max 20 messages in API call (zoals gespecificeerd) - Summarization voor oudere messages 3. **Artifact Persistence** - Sla open artifacts op in localStorage - Herstel bij page reload ### 5.3 ❌ Niet Doen (YAGNI) 1. **Geen volledige rewrite** - Bestaande blocks blijven werken - Alleen wrapper en layout wijzigen 2. **Geen nieuwe voice engine** - Bestaande Deepgram implementatie is voldoende 3. **Geen real-time collaboration** - Niet nodig voor MVP --- ## 6. Conclusie ### Haalbaarheid: βœ… **HAALBAAR** Het v3.0 redesign is haalbaar binnen 6-8 weken met 1 developer. De bestaande foundation is sterk en kan worden hergebruikt. De grootste uitdagingen zijn: 1. **Chat API ontwikkeling** (1.5 week) 2. **AI prompt engineering** (iteratief, doorlopend) 3. **State management complexiteit** (manageable met Zustand) ### Success Criteria - [ ] Split-screen layout werkt op desktop/tablet/mobile - [ ] Conversatie voelt natuurlijk (niet robotisch) - [ ] Artifacts openen binnen 2 seconden na intent detection - [ ] AI-filtering voor psychiater heeft >90% accuracy - [ ] Performance: <500ms voor local patterns, <3s voor AI responses ### Volgende Stappen 1. βœ… **Go/No-Go beslissing** op basis van deze analyse 2. βœ… **Bouwplan v3.0** opstellen met gedetailleerde stories 3. βœ… **Sprint planning** voor Fase 1-5 4. βœ… **AI prompt engineering** starten (parallel met development) --- ## Bijlagen ### A. Bestaande Componenten Overzicht ``` components/swift/ β”œβ”€β”€ command-center/ β”‚ β”œβ”€β”€ command-center.tsx βœ… Herbruikbaar (layout wijzigen) β”‚ β”œβ”€β”€ context-bar.tsx βœ… Direct herbruikbaar β”‚ β”œβ”€β”€ command-input.tsx ⚠️ Aanpassen naar chat input β”‚ β”œβ”€β”€ canvas-area.tsx ⚠️ Vervangen door artifact-area β”‚ └── recent-strip.tsx ❓ Verwijderen of integreren β”œβ”€β”€ blocks/ β”‚ β”œβ”€β”€ dagnotitie-block.tsx βœ… Direct herbruikbaar β”‚ β”œβ”€β”€ zoeken-block.tsx βœ… Direct herbruikbaar β”‚ β”œβ”€β”€ overdracht-block.tsx ⚠️ Uitbreiden met AI-filtering β”‚ └── patient-context-card.tsx βœ… Direct herbruikbaar ``` ### B. Nieuwe Componenten Overzicht ``` components/swift/ β”œβ”€β”€ chat/ πŸ†• Nieuw β”‚ β”œβ”€β”€ chat-panel.tsx β”‚ β”œβ”€β”€ chat-message.tsx β”‚ β”œβ”€β”€ chat-action-link.tsx β”‚ └── streaming-indicator.tsx β”œβ”€β”€ artifacts/ πŸ†• Nieuw β”‚ β”œβ”€β”€ artifact-container.tsx (wrapper met tabs) β”‚ └── artifact-tab.tsx └── shared/ πŸ†• Nieuw β”œβ”€β”€ linked-evidence.tsx └── relevance-badge.tsx ``` ### C. API Routes Overzicht ``` app/api/ β”œβ”€β”€ swift/ πŸ†• Nieuw β”‚ └── chat/ β”‚ └── route.ts (medical scribe chatbot) β”œβ”€β”€ intent/ β”‚ └── classify/ βœ… Bestaat (herbruikbaar) └── overdracht/ └── generate/ βœ… Bestaat (uitbreiden met filtering) ``` --- **Einde analyse**