This is the backend service for MedQuery, a clinical data analytics platform. It uses FastAPI to provide a robust API for natural language querying, RAG (Retrieval-Augmented Generation) capabilities, and secure clinical data management.
The React-based dashboard can be found here: MedQuery-Frontend
- Text-to-SQL Engine: Translates natural language into SQL queries for clinical datasets.
- Hybrid Database Support: Combines MySQL for relational clinical data and MongoDB for audit logs and history.
- JWT Security: Secure endpoint protection with role-based access for doctors and admins.
- Audit Logging: Every query and system action is tracked for clinical compliance.
- RAG Integration: Specialized endpoints for querying unstructured clinical notes.
The backend expects a MySQL instance to store relational clinical data (e.g., MIMIC-IV) and core application data.
- Create Database: Create a database named
medquery. - Configuration: Update the
DATABASE_URLin your environment variables using the format:mysql+pymysql://user:password@localhost:3306/medquery.
MongoDB is used for storing query history and audit logs. Run the following command in your terminal to start a container via Docker Desktop:
docker run --name medquery-mongo -d -p 27017:27017 mongo:latest
Ensure you have Python 3.10+ installed, then run:
pip install -r requirements.txt
Before starting the server, initialize the MySQL tables and add default users (admin/doctor) by running the seed script:
python seed_users.py
Start the FastAPI application using Uvicorn:
uvicorn app.main:app --reload
The API documentation will be available at http://localhost:8000/docs.
app/routers/: Contains API endpoints forquery,analytics,auth,notes, andhistory.app/database.py: Connection logic for both MySQL and MongoDB.app/auth_utils.py: JWT token generation and password hashing.app/models.py&app/schemas.py: SQL Alchemy models and Pydantic validation schemas.