from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from database import get_db
import models

router = APIRouter(
    prefix="/patients",
    tags=["patients"]
)

@router.get("/")
def get_patients(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    patients = db.query(models.Person).offset(skip).limit(limit).all()
    return patients

@router.get("/{person_id}")
def get_patient(person_id: int, db: Session = Depends(get_db)):
    patient = db.query(models.Person).filter(models.Person.person_id == person_id).first()
    if patient is None:
        raise HTTPException(status_code=404, detail="Patient not found")
    return patient
