import os | |
from motor.motor_asyncio import AsyncIOMotorClient | |
# MongoDB URI (must be set in Hugging Face Secrets) | |
MONGO_URI = os.environ.get("MONGODB_URI") | |
if not MONGO_URI: | |
raise ValueError("MONGODB_URI environment variable is not set.") | |
# Initialize MongoDB client | |
client = AsyncIOMotorClient(MONGO_URI) | |
# Use the correct database name explicitly | |
db = client["cps_db"] | |
# Collections | |
patients_collection = db["patients"] | |
results_collection = db["patient_analysis_results"] | |
# Optional utility function to reuse the client | |
def get_mongo_client(): | |
return client | |