feat: AI patient onboarding backend and documentation
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from dotenv import load_dotenv
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import DeclarativeBase, sessionmaker
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# Ensure data directory exists relative to project root
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
||||
DATA_DIR = BASE_DIR / "data"
|
||||
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Build absolute SQLite URI so it works regardless of process working directory
|
||||
DEFAULT_DB_PATH = DATA_DIR / "onboarding.db"
|
||||
env_db_url = os.getenv("DATABASE_URL")
|
||||
|
||||
if env_db_url and not env_db_url.startswith("sqlite:///./"):
|
||||
DATABASE_URL = env_db_url
|
||||
else:
|
||||
# Use robust absolute path for SQLite
|
||||
DATABASE_URL = f"sqlite:///{DEFAULT_DB_PATH.as_posix()}"
|
||||
|
||||
engine = create_engine(
|
||||
DATABASE_URL,
|
||||
connect_args={
|
||||
"check_same_thread": False
|
||||
},
|
||||
)
|
||||
|
||||
SessionLocal = sessionmaker(
|
||||
bind=engine,
|
||||
autoflush=False,
|
||||
autocommit=False,
|
||||
)
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
Reference in New Issue
Block a user