This is a REDCap External Module (EM) developed to support the MICA Project — an AI-powered Motivational Interviewing (MI) chatbot for engaging participants in structured conversations about substance use and behavior change.
MICA is designed as a longitudinal digital intervention, embedded in REDCap, with the following goals:
- Support behavior change through MI-aligned chatbot conversations
- Operate securely within Stanford's infrastructure
- Provide flexible follow-up sessions with context-aware chat histories
- Automatically handle scheduling, session flow, logging, and post-survey logic
MICA interacts with Stanford’s SecureChatAI instance, ensuring all data remains compliant with PHI restrictions (site-to-site VPN, no external API calls).
- Installs a standalone chatbot interface inside REDCap
- Handles:
- Participant session detection and routing
- Dynamic System Prompt configuration per session
- Session transcript capture and saving to REDCap fields
- Session catch-up and summarization logic
- Chatbot context management (e.g., system/assistant/user roles)
- Completion logic to forward users to post-surveys
- Extends functionality of SecureChatAI EM (required dependency)
- Built in React; produces a static bundle injected into the EM view
- Resides in
/static/
and renders within REDCap - Can optionally be embedded elsewhere
-
Clone this repo into your REDCap
/modules/
directory:git clone https://github.com/YOUR_ORG/mica-em.git mica_vX.X.X
-
Enable the module only on the REDCap project used for MICA
-
Ensure SecureChatAI EM is installed and configured
Longitudinal enabled:
Must have events such as baseline_arm_1
, session_2_arm_1
, ..., session_7_arm_1
Instruments:
session_info
– stores raw chat logs and timestampsposttest
– post-session surveymonth3_fu
– optional final follow-up survey
Fields:
raw_chat_logs
session_timestamp
session_info_complete
des_mica
– used for opt-in/out decisions
- On login, participant is routed to their eligible session
- If prior sessions exist, a summary is injected into the system prompt
- Chat session completes, logs saved to
session_info
- Participant is redirected to
posttest
, and if applicable, tomonth3_fu
chatbot_system_context_general
– default global system promptchatbot_system_context_session_X
– optional session-specific overrideschatbot_end_session_url_override
– optional redirect override for post-survey
- All chat processing uses Stanford’s SecureChatAI instance
- No third-party API calls (e.g., OpenAI, Claude, Gemini)
- All data remains within Stanford’s secure REDCap and hosting environment
- SecureChatAI EM
- REDCap v13+
- PHP 7.4+
- Node.js for React frontend rebuild
To rebuild the React frontend:
cd frontend
npm install
npm run build