Skip to content

πŸ₯ A RESTful API built with FastAPI for managing patient records with automatic BMI calculation and health assessment βš•οΈ

License

Notifications You must be signed in to change notification settings

ZohaibCodez/patient-management-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯Patient Management System API

Transform your patient records into a smart and structured RESTful API with FastAPI and Pydantic.


Python FastAPI Pydantic License: MIT Stars Forks Issues Last Commit

🎯 Overview

A RESTful API built with FastAPI for managing patient records with automatic BMI calculation and health assessment. This project demonstrates fundamental concepts of API development including CRUD operations, data validation, and error handling.

πŸš€ Features

  • Complete CRUD Operations: Create, read, update, and delete patient records
  • Automatic BMI Calculation: Computes BMI based on height and weight
  • Health Assessment: Provides health verdict based on BMI ranges
  • Data Validation: Robust input validation using Pydantic models
  • Sorting Capabilities: Sort patients by age, height, weight, or BMI
  • Error Handling: Comprehensive error responses with proper HTTP status codes
  • Interactive Documentation: Auto-generated API documentation with Swagger UI

πŸ› οΈ Technologies Used

  • FastAPI: Modern, fast web framework for building APIs
  • Pydantic: Data validation and settings management using Python type annotations
  • Python 3.8+: Core programming language
  • JSON: Data storage format

πŸ“‹ Prerequisites

  • Python 3.8 or higher
  • uv - Ultra-fast Python package installer and resolver

πŸ”§ Installation & Setup

Option 1: Using uv (Recommended)

  1. Install uv (if you haven't already)

    # On macOS and Linux
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
    # On Windows
    powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
  2. Clone the repository

    git clone https://github.com/ZohaibCodez/patient-management-api.git
    cd patient-management-api
  3. Create and activate virtual environment with uv

    uv venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  4. Install dependencies

    uv pip install fastapi uvicorn[standard] pydantic
  5. Run the application

    uv run uvicorn main:app --reload

Option 2: Traditional pip method

  1. Clone the repository

    git clone https://github.com/ZohaibCodez/patient-management-api.git
    cd patient-management-api
  2. Create a virtual environment

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Create the data file

    echo "{}" > patients.json
  5. Run the application

    uvicorn main:app --reload

The API will be available at http://localhost:8000

πŸ“š API Documentation

Once the server is running, visit:

Swagger UI Interface

Swagger Documentation

πŸ”— API Endpoints

Base Information

  • GET / - Welcome message
  • GET /about - API description

Patient Operations

  • GET /view - Retrieve all patients
  • GET /patient/{patient_id} - Get specific patient by ID
  • POST /create - Create new patient
  • PUT /edit/{patient_id} - Update existing patient
  • DELETE /delete/{patient_id} - Delete patient

Utility Operations

  • GET /sort - Sort patients by specified criteria
flowchart LR
    Client[Client Request] --> API[FastAPI Endpoints]
    API --> DB[patients.json File]
    DB --> API
    API --> Client
Loading

πŸ’‘ Usage Examples

Create a Patient

curl -X POST "http://localhost:8000/create" \
-H "Content-Type: application/json" \
-d '{
  "id": "P001",
  "name": "John Doe",
  "city": "New York",
  "age": 30,
  "gender": "male",
  "height": 1.75,
  "weight": 70.5
}'

Get All Patients

curl -X GET "http://localhost:8000/view"

Sort Patients

curl -X GET "http://localhost:8000/sort?sort_by=bmi&order=desc"

πŸ“Š Patient Data Model

{
  "id": "P001",
  "name": "John Doe",
  "city": "New York",
  "age": 30,
  "gender": "male",
  "height": 1.75,
  "weight": 70.5,
  "bmi": 23.0,
  "verdict": "Normal"
}

Field Descriptions

  • id: Unique patient identifier (string)
  • name: Patient's full name (string)
  • city: Patient's city of residence (string)
  • age: Patient's age in years (integer, 1-119)
  • gender: Patient's gender (male/female/others)
  • height: Patient's height in meters (float, > 0)
  • weight: Patient's weight in kilograms (float, > 0)
  • bmi: Auto-calculated Body Mass Index (computed field)
  • verdict: Health assessment based on BMI (computed field)

πŸ₯ BMI Categories

BMI Range Verdict
< 18.5 Underweight
18.5 - 24.9 Normal
25.0 - 29.9 Overweight
β‰₯ 30.0 Obese

πŸ”§ Requirements

For uv users:

uv pip install fastapi uvicorn[standard] pydantic

For pip users (requirements.txt):

fastapi==0.104.1
uvicorn[standard]==0.24.0
pydantic==2.5.0

πŸ“ Project Structure

patient-management-api/
β”‚
β”œβ”€β”€ main.py              # FastAPI application
β”œβ”€β”€ patients.json        # Data storage file
β”œβ”€β”€ requirements.txt     # Python dependencies (for pip users)
β”œβ”€β”€ README.md           # Project documentation
β”œβ”€β”€ .gitignore          # Git ignore file
└── .venv/              # Virtual environment (created by uv)

🚧 Future Enhancements

  • Database integration (PostgreSQL/MySQL)
  • User authentication and authorization
  • Advanced filtering and search capabilities
  • Patient medical history tracking
  • Export functionality (PDF/Excel)
  • Unit tests and integration tests
  • Docker containerization
  • API rate limiting

🀝 Contributing

This is a learning project, but contributions are welcome! Please feel free to:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

πŸ“„ License

This project is open source and available under the MIT License.

πŸŽ“ Learning Journey

This project was built as part of my FastAPI learning journey. It demonstrates:

  • RESTful API design principles
  • Data validation and error handling
  • Automatic documentation generation
  • Clean code practices

πŸ“ž Contact

If you have any questions or suggestions, feel free to reach out:


⭐ If you found this project helpful, please give it a star!

About

πŸ₯ A RESTful API built with FastAPI for managing patient records with automatic BMI calculation and health assessment βš•οΈ

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages