Welcome to the HCP CRM & AI Co-Pilot Portal, an intelligent, state-of-the-art solution designed for pharmaceutical field representatives to seamlessly log interaction records, perform real-time regulatory compliance audits, and manage Healthcare Professional (HCP) profiles and follow-ups.
This project is structured as a monorepo containing a high-performance FastAPI backend and a modern, high-fidelity React/TypeScript frontend styled with Tailwind CSS and powered by Redux Toolkit.
The portal leverages an agentic workflow to extract structured medical details and audit communications before saving records:
graph TD
A[Field Rep Input / Chat] -->|Submit Raw Interaction| B[React Frontend]
B -->|API POST Request| C[FastAPI Backend Router]
C -->|Run Agentic Graph| D[LangGraph Coordinator]
D -->|Step 1: Audit Text| E[Compliance Audit Engine]
D -->|Step 2: Parse Details| F[Metadata Extraction Engine]
E -->|If Compliance Passed| F
E -->|If Compliance Failed| G[Raise Warning / Error]
F -->|DB Session| H[SQLAlchemy Database Layer]
H -->|Insert & Commit| I[(SQL DB: Postgres / SQLite)]
H -->|Return Structured JSON| B
B -->|Redux Sync & Glow animation| J[HCP Interaction Workspace Form]
- Rep Log Entry: The field representative types a raw summary (e.g. "Met Dr. Carter today at 10:15 AM to review Keytruda trial safety data, she seemed very positive...") or selects a mock feed.
- FastAPI Route: The backend receives the text via the
log_interactionagent. - Compliance Audit: The text is evaluated by the compliance auditing engine for pharmaceutical guidelines (FDA off-label issues, safety claims, comparative claims, inducements).
- Metadata Extraction: If clear, the extraction engine parses parameters like HCP Name, Product, Sentiment, Attendees, Materials Shared, and Follow-up Date.
- Database Transaction: Profiles, interactions, compliance results, and follow-ups are created/updated in the SQL database (Postgres inside Docker, or local SQLite fallback).
- Dynamic Frontend Sync: The React UI matches the newly created record and triggers Redux-based highlighting with a visual pulse-glow.
- π€ AI Co-Pilot Panel: A chat interface to log notes, extract details, and receive automated follow-up suggestions in real-time.
- βοΈ Pharma Compliance Safeguards: Scans every log entry against regulatory rules, warning reps about potential violations before final database submission.
- π Interactive Workspace: A complete data form that highlights fields autocompleted by the AI to ensure visual clarity and allow for quick review/edit.
- π Auto-Follow-ups: Automatically schedules calendar and task-style reminders based on discussions (e.g. "reconnect in 2 weeks").
- π§ͺ Ingestion Feeds: Built-in mock transcripts (Oncology Audio, Cardiology Call) to instantly test the AI model's extraction capabilities.
hcp-crm/
βββ crm_agent.db # Core SQLite Database File
βββ backend/ # Python FastAPI Backend Project
β βββ app/
β β βββ api/ # API endpoints configuration
β β β βββ v1/
β β β βββ endpoints/
β β β β βββ crm.py # Main CRM & Agent endpoints
β β β β βββ health.py # Health-check api
β β β βββ api.py # Main V1 router index
β β βββ core/ # Global configuration / Pydantic settings
β β βββ models/ # SQLAlchemy DB models definition
β β βββ schemas/ # Pydantic validation schemas
β β βββ services/ # Core Business logic
β β β βββ agent.py # LangGraph workspace flow
β β β βββ compliance.py # Regulatory audit rules & LLM integration
β β β βββ crm_tools.py # Database query & mutation utils
β β β βββ extraction.py # Structured metadata extractor
β β βββ database.py # SQLAlchemy engine and session setup
β β βββ main.py # FastAPI main application entrypoint
β βββ tests/ # Unit and integration test suites
β βββ .env # Backend environment configurations
β βββ requirements.txt # Python dependencies list
β βββ README.md # Backend-specific instructions
βββ frontend/ # React + TypeScript + Vite Web Application
βββ public/ # Static public assets
βββ src/
β βββ assets/ # CSS, images, and logos
β βββ components/ # UI components
β β βββ ChatbotPanel.tsx # AI Co-Pilot chat interface
β β βββ Header.tsx # Session controls and profile details
β β βββ InteractionForm.tsx # Workspace logger form
β βββ services/
β β βββ api.ts # Axios/fetch integration with FastAPI backend
β βββ store/ # Redux state store config and slices
β βββ App.tsx # Main application layout structure
β βββ index.css # Design system stylesheet
β βββ main.tsx # React entrypoint
βββ tailwind.config.js # Tailwind CSS theme configurations
βββ package.json # Frontend Node.js dependencies
βββ README.md # Frontend-specific instructions
Follow these steps to set up and run both the backend and frontend services locally.
Ensure you have the following installed on your machine:
- Python 3.10+
- Node.js v18+
- Groq API Key (Optional: Uses deterministic local heuristics fallback if not present)
-
Navigate to the backend directory:
cd backend -
Create and Activate a Virtual Environment:
- Windows (PowerShell):
python -m venv .venv .\.venv\Scripts\Activate.ps1 - Windows (CMD):
python -m venv .venv .\.venv\Scripts\activate.bat
- macOS / Linux:
python3 -m venv .venv source .venv/bin/activate
- Windows (PowerShell):
-
Install dependencies:
pip install -r requirements.txt
-
Configure Environment Variables: Create a
.envfile in thebackend/directory (or edit the existing one):DATABASE_URL=sqlite:///./crm_agent.db GROQ_API_KEY=your_groq_api_key_here GROQ_MODEL=llama-3.3-70b-versatile
[!NOTE] If
GROQ_API_KEYis blank or missing, the system automatically falls back to regex-based heuristic parsing for compliance check and extraction, allowing local-first development without API charges. -
Run the Uvicorn Dev Server:
uvicorn app.main:app --reload
The server will start at: http://127.0.0.1:8000
- Interactive Swagger Documentation: http://127.0.0.1:8000/docs
- ReDoc Endpoint Docs: http://127.0.0.1:8000/redoc
-
Open a new terminal and navigate to the frontend directory:
cd frontend -
Install Node packages:
npm install
-
Run the Vite development server:
npm run dev
The frontend portal will launch at: http://localhost:5173
You can run the entire stack (PostgreSQL database, FastAPI backend, and React/Vite frontend) in containers using Docker Compose. This handles PostgreSQL database provisioning, linking services, and dependencies automatically.
- Docker Desktop installed and running.
In the project root directory, run:
docker compose up --buildOnce running, the stack is available at:
- Frontend React Portal: http://localhost:5173 (served through Nginx)
- FastAPI Backend Docs: http://localhost:8000/docs
- PostgreSQL DB: Running on port
5432with connection parameters configured in the rootdocker-compose.yml. PostgreSQL data is persistent across runs via thepgdataDocker volume.
docker compose down -vTo execute backend unit tests for the compliance engine or extractors, activate your backend virtual environment and run:
cd backend
python -m unittest discover testsWhen running in local-fallback mode, the compliance engine checks for key phrases in the interaction log text. Any occurrence of these keywords flags the interaction as high risk:
| Key phrase / Trigger | Flagged Violation Message |
|---|---|
off-label |
Possible off-label promotion language. |
unapproved |
Possible claim about an unapproved use or indication. |
guaranteed cure |
Absolute efficacy claim detected. |
no side effects |
Potentially misleading safety claim detected. |
better than |
Comparative claim may require substantiation. |
free gift |
Potential inducement language detected. |
kickback |
Potential anti-kickback concern detected. |
The backend exposes the following API routes under the /api/v1 prefix:
POST /api/v1/crm/agent/log: LangGraph agent workflow that processes raw text logs, extracts fields, performs a compliance review, and writes to database.POST /api/v1/crm/agent/invoke: Multi-action agent dispatcher supportinglog_interaction,edit_interaction,search_hcp_profile,schedule_follow_up, andcompliance_check.POST /api/v1/crm/compliance/check: Independent endpoint to run a compliance scan on raw text.POST /api/v1/crm/follow-ups: Schedules a new calendar/due-date follow-up task.GET /api/v1/crm/hcps/{hcp_name}/profile: Queries preferences, status, and recent interactions for a given Healthcare Professional.
GET /api/v1/crm/ingestion-feeds: Returns available mock transcripts.POST /api/v1/crm/ingestion-feeds/{feed_id}/log: Automatically processes and logs a specific mock transcript.
GET /api/v1/health: Checks system and database connection status.
For modifications and custom updates, inspect the following key application files:
- Entry Point: backend/app/main.py
- FastAPI Routes: backend/app/api/v1/endpoints/crm.py
- Database Models: backend/app/models/crm.py
- Compliance Rules: backend/app/services/compliance.py
- Chat View component: frontend/src/components/ChatbotPanel.tsx
- Form View component: frontend/src/components/InteractionForm.tsx
- API Integration Client: frontend/src/services/api.ts