A FastAPI application for managing patient records with automatic BMI calculation and health verdict determination.
This is a comprehensive FastAPI project that provides a RESTful API for managing patient records. It includes features such as:
- Creating new patient records
- Viewing all patients or specific patients by ID
- Updating existing patient information
- Deleting patient records
- Sorting patients by age
- Automatic BMI calculation and health verdict based on height and weight
The application uses SQLAlchemy for database operations with SQLite, and Pydantic for data validation and serialization.
-
Clone or download this repository.
-
Navigate to the project directory:
cd FastApis2026 -
Activate the virtual environment:
- On Windows:
myenv\Scripts\activate - On macOS/Linux:
source myenv/bin/activate
- On Windows:
-
Install dependencies (if not already installed):
pip install fastapi uvicorn sqlalchemy pydantic
To run the application:
uvicorn main:app --reload
The API will be available at http://127.0.0.1:8000
Returns a welcome message for the Patient Management System API.
Response:
{
"message": "Patient Management System API"
}Returns information about the application.
Response:
{
"data": "This is a simple FastAPI application for managing patient records."
}Creates a new patient record.
Request Body:
{
"patient_id": "P001",
"name": "John Doe",
"city": "New York",
"age": 30,
"gender": "Male",
"height": 175.5,
"weight": 70.2
}Response:
{
"message": "Patient created successfully",
"patient": {
"patient_id": "P001",
"name": "John Doe",
"city": "New York",
"age": 30,
"gender": "Male",
"height": 175.5,
"weight": 70.2,
"bmi": 22.78,
"verdict": "Normal weight"
}
}Retrieves all patient records.
Response:
{
"patients": [
{
"patient_id": "P001",
"name": "John Doe",
"city": "New York",
"age": 30,
"gender": "Male",
"height": 175.5,
"weight": 70.2,
"bmi": 22.78,
"verdict": "Normal weight"
}
]
}Retrieves a specific patient record by patient ID.
Parameters:
patient_id(path): The unique identifier of the patient (e.g., "P001")
Response:
{
"patient": {
"patient_id": "P001",
"name": "John Doe",
"city": "New York",
"age": 30,
"gender": "Male",
"height": 175.5,
"weight": 70.2,
"bmi": 22.78,
"verdict": "Normal weight"
}
}Retrieves all patients sorted by age.
Query Parameters:
order(optional): Sort order - "asc" for ascending (default), "desc" for descending
Response:
{
"patients": [
{
"patient_id": "P001",
"name": "John Doe",
"city": "New York",
"age": 30,
"gender": "Male",
"height": 175.5,
"weight": 70.2,
"bmi": 22.78,
"verdict": "Normal weight"
}
]
}Updates an existing patient record.
Parameters:
patient_id(path): The unique identifier of the patient to update
Request Body: (only include fields to update)
{
"name": "Jane Doe",
"weight": 65.0
}Response:
{
"message": "Patient updated successfully",
"patient": {
"patient_id": "P001",
"name": "Jane Doe",
"city": "New York",
"age": 30,
"gender": "Male",
"height": 175.5,
"weight": 65.0,
"bmi": 21.11,
"verdict": "Normal weight"
}
}Deletes a patient record.
Parameters:
patient_id(path): The unique identifier of the patient to delete
Response:
{
"message": "Patient deleted successfully"
}FastAPI automatically generates interactive API documentation. Once the server is running, you can access it at:
- Swagger UI:
http://127.0.0.1:8000/docs - ReDoc:
http://127.0.0.1:8000/redoc