A FastAPI-based backend service for managing prescription medications and tracking adherence.
- User management
- Prescription tracking
- Medication usage logging
- Adherence calculation
- RESTful API endpoints
- Python 3.8+
- SQLite3
- pip (Python package manager)
- Clone the repository:
git clone <repository-url>
cd pillai-backend- Create and activate a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtThe application uses SQLite as its database. The database file (prescriptions.db) will be created automatically when you first run the application.
Start the FastAPI server:
uvicorn main:app --reloadThe API will be available at http://localhost:8000
Once the server is running, you can access:
- Interactive API documentation:
http://localhost:8000/docs - Alternative API documentation:
http://localhost:8000/redoc
POST /users/- Create a new userGET /users/{user_id}- Get user detailsPUT /users/{user_id}- Update user detailsDELETE /users/{user_id}- Delete a user
POST /users/{user_id}/prescriptions/- Create a new prescriptionGET /users/{user_id}/prescriptions- Get all prescriptions for a user
POST /users/{user_id}/usage/- Log medication usageGET /users/{user_id}/usage/- Get usage logsGET /users/{user_id}/prescriptions/{prescription_id}/adherence- Get adherence metrics
curl -X POST http://localhost:8000/users/ \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"full_name": "Test User"
}'curl -X POST http://localhost:8000/users/1/prescriptions/ \
-H "Content-Type: application/json" \
-d '{
"medication_name": "Amoxicillin",
"dosage": "500mg",
"pills_per_dose": 1,
"times_per_day": 2,
"start_date": "2024-03-20T00:00:00",
"end_date": "2024-03-27T00:00:00"
}'curl -X POST http://localhost:8000/users/1/usage/ \
-H "Content-Type: application/json" \
-d '{
"prescription_id": 1,
"taken_at": "2024-03-20T08:00:00"
}'curl "http://localhost:8000/users/1/prescriptions/1/adherence"pytestTo clear all usage logs:
sqlite3 prescriptions.db "DELETE FROM usage;"pillai-backend/
├── main.py # FastAPI application and routes
├── models.py # SQLAlchemy models
├── schemas.py # Pydantic schemas
├── database.py # Database configuration
├── adherence.py # Adherence calculation logic
├── requirements.txt # Project dependencies
└── README.md # This file
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
[Add your license information here]