Skip to content
kennyklfokPublic

About

ECG generator for interpretation practice

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

22 Commits

Folders and files

Repository files navigation

CapyECG

Hosted on https://capyecg.onrender.com/

CapyECG is an educational ECG rhythm trainer for med students, ECG techs, paramedics, and nurses. It shows a synthetic 12-lead ECG with a 10-second Lead II rhythm strip, asks the learner to identify the rhythm, then reveals the known answer with short teaching points.

For training only. Not for clinical diagnosis.

MVP Features

  • React frontend with a cozy, clean practice workflow
  • FastAPI backend with SQLite storage
  • Local ECG simulator with curated explanations and single-answer choices
  • 150 instantly available strips across 30 supported rhythm and conduction patterns
  • Standard 12-lead ECG view on continuous grid paper
  • Cozy green spa theme with real capybara photo accents
  • Single-choice rhythm practice with a clear feedback panel
  • Rhythm-specific LITFL links in answer feedback
  • A searchable CSCT study guide with 82 expandable topics, attributed LITFL reference images and further-reading links
  • Basic session score tracking
  • Backend stores known rhythm labels and explanations

Rhythm Categories

Rhythm practice follows topics in the CSCT ECG Analysis Study Guide. The active quiz pool is a subset with dedicated simulator templates; the broader reference catalog is not a claim of complete study-guide coverage. See coverage and sources.

  • Beginner: sinus rhythms, sinus arrhythmia, PACs, PVCs
  • Intermediate: sinus node disorders, atrial rhythms, junctional rhythms, first-degree and Mobitz I AV block, bundle branch blocks, paced rhythm
  • Advanced practice: ventricular rhythms, SVT, multifocal atrial tachycardia, junctional tachycardia, advanced AV blocks, WPW

ECG patterns are tracked separately because they are not rhythms. The current catalog includes chamber enlargement, ischemia/infarction, ST abnormalities, electrolyte patterns, electrical alternans, hypothermia, pulmonary embolism, dextrocardia, and PEA categories for future practice modes.

Each case has one canonical answer. The API still returns that answer in a one-item correct_answers array for a consistent feedback shape.

Study guide

Open Study guide in the main navigation, or visit /#study-guide directly. Fourteen sections organize the CSCT checklist into basic measurements, rhythm families, conduction blocks, structural and repolarization patterns, electrolytes, other clinical patterns and pacemaker function. Search spans topic names, abbreviations and explanations. Topics expand individually to show unaltered LITFL reference images, recognition clues, context notes and LITFL links. Images load from LITFL only when their topic opens, retain their original aspect ratio, and link to the full-size original and source article. Images are used under LITFL’s CC BY-NC-SA 4.0 terms; linked third-party rights remain with their respective owners. Concepts without a verified matching image keep their explanation and further-reading links rather than showing a substitute rhythm.

The guide includes subjects outside the supported quiz pool; listing a topic here does not make it an eligible generated case. Diagrams are not calibrated patient recordings, and context-dependent diagnoses are identified as such. CSCT's undefined pre-excitation type labels are preserved with a naming caveat. Guide code and styles load only when opened. Switching to the guide preserves an in-progress practice answer.

Project Structure

CapyECG/
  backend/
    app/
      database.py       SQLite cases and answer attempts
      catalog.py        Rhythm, pattern, priority, and simulator-template catalog
      ecg_generator.py  Synthetic educational 12-lead waveform generation
      case_factory.py   Local case selection and curated teaching content
      main.py           FastAPI routes
      schemas.py        API request/response models
      seed_data.py      Rhythm features, explanations, and fallbacks
    tests/
      test_api.py
    requirements.txt
  frontend/
    src/
      main.jsx          React entry point
      App.jsx           Session flow and screens
      practiceSelection.js  Browser history and session planning
      styles.css        UI styling and ECG grid styling
    index.html
    package.json
    vite.config.js
  README.md

One-Command Dev

After backend and frontend dependencies are installed, run both servers from the project root:

npm run dev

This starts:

  • FastAPI at http://localhost:8000
  • Vite at http://localhost:5173

Press Ctrl+C to stop both.

Backend Setup

First-time setup from the project root:

cd backend
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
uvicorn app.main:app --reload

The API runs at http://localhost:8000.

No AI provider, API key or external generation service is required. Previously configured AI-provider secrets are no longer read and can be removed from the hosting environment.

Useful endpoints:

  • GET /api/health
  • GET /api/rhythms
  • GET /api/cases/new?difficulty=Easy
  • POST /api/answers
  • GET /api/cases/{case_id}/learn-more

SQLite data is created at backend/data/capyecg.sqlite3 when the app starts.

Frontend Setup

First-time setup:

cd frontend
npm install

After that, prefer the root npm run dev command.

If the backend is running somewhere else, set:

$env:VITE_API_BASE="http://localhost:8000"
npm run dev

Tests

From the project root after installing backend dependencies:

npm test

Educational content

CapyECG does not diagnose patients. Explanations use a known stored label and curated teaching features. Strips are mathematical educational simulations, not patient recordings or a clinically validated ECG generator.

The home screen starts an API request in the background while the learner practices a bundled starter case. A ready API case may be used on a later visit to that selection; a late response never replaces the current strip. The simulator varies supported rate ranges, beat timing, ectopic-beat placement, voltage and noise. Explanations and answer choices come from the local teaching catalog; no LLM is called.

Future Real ECG Dataset Integration

The current MVP stores CapyECG-rendered simulator waveform JSON in SQLite. To add AI-generated files, real samples, or reference-influenced generated cases later:

  • Import source metadata into ecg_cases
  • Store calibrated waveform arrays or image paths in waveform_json
  • Use source_type = 'dataset'
  • Keep the verified rhythm label and explanation attached to the case
  • Add provenance fields such as dataset name, license, generation prompt/version, reference source category, lead, sampling rate, and annotator notes

Add dataset retrieval as a separate case source when the MVP is ready for imported examples.

Image Credits

CapyECG uses real capybara photos from Wikimedia Commons and Unsplash:

Fast first visit

The frontend ships 150 simulator-generated starter cases: five distinct examples for each of 30 supported rhythms and conduction patterns. Each case is a separate downloadable asset. The home screen preloads the first planned strip; practice preloads the next one. While the API connects in the background, these bundled cases support local answer checking and learning notes. A ready API case follows the planned rhythm and may be used on a subsequent visit to that selection; a late response never replaces the strip being answered. Starter answers contribute to the current session score but are not written to the backend database. These are educational cases, not secure exams; their answer keys are included in the frontend assets.

Practice selection and history

Sessions are planned in the browser from the verified difficulty pool. Selection favours different strips, less-recent rhythms, and less-practiced material. One in three positions may favour a missed rhythm or a related rhythm from the existing teaching catalog. Wrong answers increase a capped review need; correct answers gradually reduce it. Repeated rhythms are separated by at least three positions when the pool allows, and exact strip repeats only occur after the eligible strips have been exhausted.

Anonymous history lives in browser localStorage under capyecg.practice.v1: rhythm exposure and answer counts, review need, recent strip identifiers, and the last five completed session selections. Preloading does not count as practice. Blocked or full storage falls back to history for the current page lifetime. There is no account or cross-device sync. API cases are fresh simulator examples of the chosen rhythm, requested with GET /api/cases/new?difficulty=Medium&rhythm=Atrial%20flutter.

The verified pools contain six Easy, thirteen Medium, and eleven Hard rhythms and conduction patterns. Longer sessions necessarily repeat some rhythms, using different examples. The larger reference catalog remains excluded where the simulator cannot represent a diagnosis faithfully.

Regenerate and commit the assets whenever the simulator, catalog, or built-in explanations change:

backend/.venv/Scripts/python.exe scripts/export_starter_cases.py
node --test frontend/src/*.test.js
npm run build

A frontend rebuild/redeploy is required for the live site to receive this change. Serve frontend/dist as a static site/CDN, including its generated asset chunks. Set VITE_API_BASE to the deployed API URL at build time. Bundled cases remove the API startup dependency after the frontend has loaded; they cannot accelerate the initial HTML response if the frontend itself is hosted on a sleeping web service. Render free web services can spin down on idle; see https://render.com/docs/free#spinning-down-on-idle.

About

ECG generator for interpretation practice

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages