188 lines
6.5 KiB
Markdown
188 lines
6.5 KiB
Markdown
# Healthcare Management System Backend
|
|
|
|
A comprehensive backend API for a healthcare management system built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- User Authentication and Authorization
|
|
- Patient Management
|
|
- Doctor Management
|
|
- Appointment Scheduling
|
|
- Medical Records Management
|
|
- Doctor Availability Scheduling
|
|
|
|
## Tech Stack
|
|
|
|
- **Framework**: FastAPI
|
|
- **Database**: SQLite with SQLAlchemy ORM
|
|
- **Migrations**: Alembic
|
|
- **Authentication**: JWT Tokens
|
|
- **Password Hashing**: BCrypt
|
|
- **Linting**: Ruff
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
├── alembic.ini # Alembic configuration
|
|
├── main.py # Application entry point
|
|
├── app/ # Main application package
|
|
│ ├── api/ # API endpoints
|
|
│ │ ├── api_v1/ # API version 1
|
|
│ │ │ ├── endpoints/ # API endpoint modules
|
|
│ │ │ │ ├── login.py # Authentication endpoints
|
|
│ │ │ │ ├── users.py # User management endpoints
|
|
│ │ │ │ ├── patients.py # Patient management endpoints
|
|
│ │ │ │ ├── doctors.py # Doctor management endpoints
|
|
│ │ │ │ └── appointments.py # Appointment management endpoints
|
|
│ │ │ └── api.py # API router
|
|
│ │ └── deps.py # Dependency injection
|
|
│ ├── core/ # Core application modules
|
|
│ │ ├── config.py # Application configuration
|
|
│ │ └── security.py # Security utilities
|
|
│ ├── crud/ # CRUD operations
|
|
│ │ ├── base.py # Base CRUD class
|
|
│ │ ├── crud_user.py # User CRUD operations
|
|
│ │ ├── crud_patient.py # Patient CRUD operations
|
|
│ │ ├── crud_doctor.py # Doctor CRUD operations
|
|
│ │ └── crud_appointment.py # Appointment CRUD operations
|
|
│ ├── db/ # Database setup
|
|
│ │ ├── base.py # Base class for models
|
|
│ │ ├── base_class.py # Imports all models for Alembic
|
|
│ │ └── session.py # Database session setup
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ │ ├── user.py # User model
|
|
│ │ ├── patient.py # Patient model
|
|
│ │ ├── doctor.py # Doctor model
|
|
│ │ ├── appointment.py # Appointment model
|
|
│ │ ├── medical_record.py # Medical record model
|
|
│ │ └── doctor_schedule.py # Doctor schedule model
|
|
│ └── schemas/ # Pydantic models (schemas)
|
|
│ ├── user.py # User schemas
|
|
│ ├── patient.py # Patient schemas
|
|
│ ├── doctor.py # Doctor schemas
|
|
│ ├── appointment.py # Appointment schemas
|
|
│ ├── medical_record.py # Medical record schemas
|
|
│ ├── doctor_schedule.py # Doctor schedule schemas
|
|
│ └── token.py # Token schemas
|
|
└── migrations/ # Alembic migrations
|
|
├── versions/ # Migration versions
|
|
│ └── 001_initial_migration.py # Initial migration
|
|
├── env.py # Alembic environment
|
|
├── README # Alembic README
|
|
└── script.py.mako # Alembic script template
|
|
```
|
|
|
|
## Environment Variables
|
|
|
|
The application uses the following environment variables:
|
|
|
|
| Name | Description | Default Value |
|
|
|------|-------------|---------------|
|
|
| SECRET_KEY | Secret key for JWT token generation and verification | development_secret_key |
|
|
| ACCESS_TOKEN_EXPIRE_MINUTES | JWT token expiration time in minutes | 60 |
|
|
| JWT_SECRET | Secret key for JWT token generation | Same as SECRET_KEY |
|
|
|
|
## Getting Started
|
|
|
|
### Prerequisites
|
|
|
|
- Python 3.8+
|
|
- pip (Python package installer)
|
|
|
|
### Installation
|
|
|
|
1. Clone the repository:
|
|
```bash
|
|
git clone https://github.com/yourusername/healthcare-management-system-backend.git
|
|
cd healthcare-management-system-backend
|
|
```
|
|
|
|
2. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Initialize the database:
|
|
```bash
|
|
# Create the database directory
|
|
mkdir -p /app/storage/db
|
|
|
|
# Run the migrations
|
|
alembic upgrade head
|
|
```
|
|
|
|
4. Start the application:
|
|
```bash
|
|
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
|
|
```
|
|
|
|
## API Documentation
|
|
|
|
Once the application is running, you can access the interactive API documentation at:
|
|
|
|
- Swagger UI: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc
|
|
|
|
## API Endpoints
|
|
|
|
### Authentication
|
|
|
|
- **POST /api/v1/login/access-token**: Get access token (OAuth2 compatible)
|
|
|
|
### Users
|
|
|
|
- **GET /api/v1/users/**: Get all users (admin only)
|
|
- **POST /api/v1/users/**: Create a new user (admin only)
|
|
- **GET /api/v1/users/me**: Get current user information
|
|
- **PUT /api/v1/users/me**: Update current user information
|
|
- **GET /api/v1/users/{user_id}**: Get user by ID
|
|
- **PUT /api/v1/users/{user_id}**: Update user by ID (admin only)
|
|
|
|
### Patients
|
|
|
|
- **GET /api/v1/patients/**: Get all patients
|
|
- **POST /api/v1/patients/**: Create a new patient
|
|
- **GET /api/v1/patients/{patient_id}**: Get patient by ID
|
|
- **PUT /api/v1/patients/{patient_id}**: Update patient by ID
|
|
- **DELETE /api/v1/patients/{patient_id}**: Delete patient by ID (admin only)
|
|
|
|
### Doctors
|
|
|
|
- **GET /api/v1/doctors/**: Get all doctors
|
|
- **POST /api/v1/doctors/**: Create a new doctor
|
|
- **GET /api/v1/doctors/{doctor_id}**: Get doctor by ID
|
|
- **PUT /api/v1/doctors/{doctor_id}**: Update doctor by ID
|
|
- **DELETE /api/v1/doctors/{doctor_id}**: Delete doctor by ID (admin only)
|
|
|
|
### Appointments
|
|
|
|
- **GET /api/v1/appointments/**: Get all appointments
|
|
- **POST /api/v1/appointments/**: Create a new appointment
|
|
- **GET /api/v1/appointments/{appointment_id}**: Get appointment by ID
|
|
- **PUT /api/v1/appointments/{appointment_id}**: Update appointment by ID
|
|
- **DELETE /api/v1/appointments/{appointment_id}**: Delete appointment by ID
|
|
- **POST /api/v1/appointments/{appointment_id}/status**: Update appointment status
|
|
|
|
## Development
|
|
|
|
### Running Tests
|
|
|
|
```bash
|
|
pytest
|
|
```
|
|
|
|
### Linting
|
|
|
|
```bash
|
|
ruff check .
|
|
```
|
|
|
|
### Autofixing Linting Issues
|
|
|
|
```bash
|
|
ruff check --fix .
|
|
```
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License - see the LICENSE file for details. |