Skip to content

Flask web app for detecting cognitive and emotional patterns in post-stroke patient texts.

License

Notifications You must be signed in to change notification settings

maitrisavaliya/post-stroke-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Post-Stroke Cognitive Tracker

Overview

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.

Problem Statement

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.

Key Features

  • 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

Technical Architecture

Backend (Flask)

  • run_tracker.py: Main Flask application with streaming endpoint
  • prompts.py: System prompt engineering and Ollama configuration
  • Streaming response handling via Server-Sent Events pattern

Frontend

  • Vanilla JavaScript with Fetch API for streaming
  • marked.js for Markdown rendering
  • Progressive content display as LLM generates response

LLM Integration

  • Ollama local inference server
  • Default model: Mistral (configurable in prompts.py)
  • Custom system prompt for clinical pattern recognition

Technologies Used

  • Backend: Python 3.x, Flask
  • LLM: Ollama (Mistral model)
  • Frontend: HTML5, CSS3, JavaScript (ES6+)

Libraries:

  • requests for Ollama API communication
  • marked.js for client-side Markdown parsing

Installation

Prerequisites

  • Install Ollama
    • Pull the Mistral model:
ollama pull mistral

Note: If you use PowerShell on Windows, the same command applies. Ensure Ollama is installed and accessible from your PATH.

Setup

# 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.txt

Usage

Start Ollama (if not running):

ollama serve

Run the Flask application:

python run_tracker.py

Access the web interface:

  • Open browser to http://localhost:5001
  • Enter patient text or load sample data
  • Click "Analyze Text" to receive structured analysis

Sample Data

Included examples demonstrate various cognitive patterns:

  • entry_normal.txt: Baseline cognitive functioning
  • entry_confusion.txt: Memory lapses and disorientation
  • entry_emotion_loop.txt: Rumination and negative emotion cycles
  • entry_fatigue.txt: Mental exhaustion and concentration difficulty
  • entry_mixed.txt: Multiple concurrent patterns

Analysis Output Format

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

Configuration

Modify prompts.py to:

  • Change Ollama model (OLLAMA_MODEL)
  • Adjust endpoint URL (OLLAMA_ENDPOINT)
  • Customize analysis criteria in SYSTEM_PROMPT

Limitations & Future Work

Current Limitations:

  • 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)

Future Enhancements:

  • 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

Important Disclaimer

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.

License

This project is licensed under the MIT License — see the LICENSE file in the repository root for full terms.

About

Flask web app for detecting cognitive and emotional patterns in post-stroke patient texts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published