A Flask-based web application that helps caregivers and healthcare professionals identify potential cognitive and emotional patterns in post-stroke patient communications. The system analyzes journal entries, speech transcripts, or daily updates to flag signs of confusion, mental fatigue, and emotional loops.
Post-stroke patients often experience cognitive challenges that can be difficult to track consistently. This tool provides structured analysis of patient communications to help identify patterns that may require clinical attention, supporting better care coordination between patients, caregivers, and healthcare providers.
-
Real-time streaming analysis using local LLM (Ollama)
-
Pattern detection for:
- Cognitive confusion (disorientation, memory lapses)
- Mental fatigue (concentration difficulty, simplified language)
- Emotion loops (recurring negative emotions, rumination)
-
Sample data loader with pre-written patient scenarios
-
Markdown-formatted output for clear, structured results
-
Privacy-first design - runs entirely locally with no data sent to external APIs
run_tracker.py: Main Flask application with streaming endpointprompts.py: System prompt engineering and Ollama configuration- Streaming response handling via Server-Sent Events pattern
- Vanilla JavaScript with Fetch API for streaming
marked.jsfor Markdown rendering- Progressive content display as LLM generates response
- Ollama local inference server
- Default model: Mistral (configurable in
prompts.py) - Custom system prompt for clinical pattern recognition
- Backend: Python 3.x, Flask
- LLM: Ollama (Mistral model)
- Frontend: HTML5, CSS3, JavaScript (ES6+)
requestsfor Ollama API communicationmarked.jsfor client-side Markdown parsing
- Install Ollama
- Pull the Mistral model:
ollama pull mistralNote: If you use PowerShell on Windows, the same command applies. Ensure Ollama is installed and accessible from your PATH.
# Clone repository
git clone <repository-url>
Set-Location post-stroke-tracker
# Install Python dependencies
pip install flask requests
# Ensure directory structure:
# project/
# ├── run_tracker.py
# ├── prompts.py
# ├── templates/
# │ └── index.html
# ├── static/
# │ ├── script.js
# │ └── style.css
# └── sample_data/
# ├── entry_normal.txt
# ├── entry_confusion.txt
# ├── entry_emotion_loop.txt
# ├── entry_fatigue.txt
# └── entry_mixed.txtStart Ollama (if not running):
ollama serveRun the Flask application:
python run_tracker.pyAccess the web interface:
- Open browser to
http://localhost:5001 - Enter patient text or load sample data
- Click "Analyze Text" to receive structured analysis
Included examples demonstrate various cognitive patterns:
entry_normal.txt: Baseline cognitive functioningentry_confusion.txt: Memory lapses and disorientationentry_emotion_loop.txt: Rumination and negative emotion cyclesentry_fatigue.txt: Mental exhaustion and concentration difficultyentry_mixed.txt: Multiple concurrent patterns
The system provides:
- Summary: Concise overview of patient input
- Confusion: Signs of disorientation or memory issues
- Mental Fatigue: Indicators of cognitive exhaustion
- Emotion Loops: Detection of recurring negative emotions
- Evidence: Specific text phrases supporting each finding
Modify prompts.py to:
- Change Ollama model (
OLLAMA_MODEL) - Adjust endpoint URL (
OLLAMA_ENDPOINT) - Customize analysis criteria in
SYSTEM_PROMPT
- Requires local Ollama installation
- Analysis quality depends on LLM model capabilities
- No data persistence or longitudinal tracking
- Text-only input (no speech-to-text integration)
- Database integration for patient history tracking
- Trend visualization over time
- Multi-language support
- Audio input with transcription
- Clinical terminology extraction
- Export functionality for medical records
This tool is for informational purposes only and does not provide medical diagnoses. All analyses should be reviewed by qualified healthcare professionals. It is designed to assist in pattern recognition, not replace clinical judgment.
This project is licensed under the MIT License — see the LICENSE file in the repository root for full terms.