Skip to content

Database

Database and client modules for Quill Medical.

This module provides database connections and API clients for the three-database architecture: - auth_db: Authentication and application state (PostgreSQL) - fhir_client: FHIR server API client (HAPI FHIR) - ehrbase_client: EHRbase server API client (OpenEHR)

AuthBase

Bases: DeclarativeBase

Base class for auth database models.

Source code in app/db/auth_db.py
32
33
34
35
class AuthBase(DeclarativeBase):
    """Base class for auth database models."""

    pass

get_auth_db

get_auth_db()

FastAPI dependency to provide auth database sessions.

Yields:

Name Type Description
Session Generator[Session]

SQLAlchemy database session for auth database.

Example
@router.get("/users")
def list_users(db: Session = Depends(get_auth_db)):
    users = db.query(User).all()
    return users
Source code in app/db/auth_db.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def get_auth_db() -> Generator[Session]:
    """FastAPI dependency to provide auth database sessions.

    Yields:
        Session: SQLAlchemy database session for auth database.

    Example:
        ```python
        @router.get("/users")
        def list_users(db: Session = Depends(get_auth_db)):
            users = db.query(User).all()
            return users
        ```
    """
    db = AuthSessionLocal()
    try:
        yield db
    finally:
        db.close()