About the Project: DTx Cognitive SaaS

This document tells the story of our project—what inspired us, what we learned, how we built it, and the challenges we faced during development.


Inspiration

Traditional clinical approaches to cognitive assessment and attention-deficit/hyperactivity disorder (ADHD) training are slow, paper-heavy, and unlocalized. Patients—particularly children—struggle to stay engaged with outdated cognitive training tasks, while clinicians lack real-time access to high-resolution telemetry data.

Inspired by the rapid growth of Digital Therapeutics (DTx) and the potential of serverless relational databases, we set out to build a secure, multi-tenant B2B SaaS platform that enables closed-loop clinical intervention: where patient game pacing automatically adapts to clinical severity and results are immediately synthesized into multilingual diagnostic summaries.


What it does

DTx Cognitive SaaS establishes a closed-loop feedback mechanism between the patient terminal and the clinician console:

  • Gamified Testing Paradigms: The patient terminal runs three core cognitive tasks targeting sustained attention, rule flexibility, and response inhibition.
  • Real-Time Telemetry Tracking: The application tracks the exact time-series accuracy and processing speed. For a patient session with \(N\) total trials, the overall Accuracy \(A\) is calculated as: $$A = \frac{\sum_{i=1}^{N} C_i}{N} \times 100\%$$ where \(C_i \in {0, 1}\) denotes whether the \(i\)-th trial is correct.

    The average Reaction Time \(RT_{\text{avg}}\) for registered correct hits (where \(RT_k > 0\)) is calculated as: $$RT_{\text{avg}} = \frac{1}{|K|} \sum_{k \in K} RT_k$$ where \(K \subseteq {1, \dots, N}\) is the set of correct hit trial indices.

  • Severity-Adaptive Calibration: Game parameters automatically adjust to reduce frustration and cognitive overload. The stimulus duration \(D_s\) and the error ceiling \(E_{\max}\) scale dynamically as a function of clinical severity: $$D_s(\text{Severity}) = \begin{cases} 1500\text{ ms} & \text{if Severity} = \text{Mild} \ 2000\text{ ms} & \text{if Severity} = \text{Moderate} \ 2500\text{ ms} & \text{if Severity} = \text{Severe} \end{cases}$$ $$E_{\max}(\text{Severity}) = \begin{cases} 7 & \text{if Severity} = \text{Mild} \ 5 & \text{if Severity} = \text{Moderate} \ 3 & \text{if Severity} = \text{Severe} \end{cases}$$

  • AI Medical Copilot: Uses the Gemini API to analyze session data, recommend priority training focuses, and generate clinical summaries cached in 4 languages.


How we built it

We built this project using a modern serverless stack:

  • Frontend: Built with React, Vite, and custom CSS glassmorphism styling, hosted on Vercel Edge.
  • Backend: Designed with Python + FastAPI, utilizing threadpools to execute relational operations without blocking the event loop.
  • Database (The Core): Powered by Amazon Aurora PostgreSQL (Serverless v2). We secure it using IAM Database Authentication via the AWS SDK (boto3) to dynamically request a 15-minute temporary database token: $$\text{AuthToken} = \text{generate_db_auth_token}(\text{DBHostname}, \text{Port}, \text{DBUsername}, \text{Region})$$ This token acts as the database password, requiring no static credentials to be stored.

    Here is a snippet of our dynamic connection creation code:

    def get_auth_token():
        client = boto3.client('rds', region_name=REGION)
        return client.generate_db_auth_token(
            DBHostname=DB_HOST,
            Port=DB_PORT,
            DBUsername=DB_USER,
            Region=REGION
        )
    
  • Multilingual Caching: By using composite primary keys (patient_id, lang), the backend caches translation matrices from a single Gemini request, delivering instantaneous, localized UI updates.


Challenges we ran into

  1. High Connection Latency over SSL: Enforcing SSL connection handshake (sslmode="require") on database queries across regions introduced significant latency. To solve this, we implemented SQLAlchemy's dynamic creator argument pointing to a connection generator that updates IAM auth tokens only on expiration, avoiding excessive generation overhead.
  2. Network Connection Storms: High-frequency game telemetry can lead to hundreds of telemetry events per minute, which could overwhelm database connections. We designed an in-memory batch caching system on the patient terminal that logs game trial arrays locally, uploading the entire collection in a single transaction via POST /api/logs.

Accomplishments that we're proud of

  • Zero Password DB Infrastructure: A fully production-ready database connection setup protected strictly under AWS IAM policies.
  • Closed-Loop Calibration: Seamless combination of telemetry logs, custom rule engines, and Gemini API to calibrate adaptive thresholds automatically.
  • Glassmorphic Multi-language Support: Immediate localization support for English, Chinese, Malay, and Tamil via cache layers.

What we learned

  • Clinical Compliance: Building digital health software requires prioritizing database transaction safety and user authentication (via RDS IAM).
  • Relational Optimization: Relational tables with proper primary keys and indexing (e.g., (patient_id, lang)) are highly effective for managing AI-generated cache objects.

What's next for dtx-cognitive-training

  • Physiological Integration: Correlating game telemetry with real-time biometric inputs (e.g., heart rate variability and eye-tracking metrics).
  • Clinical Trials: Setting up localized clinical studies to evaluate the efficacy of the adaptive pacing formula and validate ADHD symptom reduction.
  • Database Scaling: Monitoring and testing Aurora Serverless v2 auto-scaling limits under high concurrent client loads.

Built With

Share this project:

Updates