CareLoop / config.py
gsingh24's picture
Upload 5 files
29a6fbf verified
# config.py
# CareLoop Configuration Management
import os
from dataclasses import dataclass
from typing import Dict, List, Optional
@dataclass
class DatabaseConfig:
"""Database configuration settings"""
url: str = "sqlite:///careloop_demo.db"
echo: bool = False
pool_size: int = 10
max_overflow: int = 20
@dataclass
class AIConfig:
"""AI and LLM configuration"""
openai_api_key: str = "demo-key-not-required"
model_name: str = "gpt-4"
temperature: float = 0.1
max_tokens: int = 2000
# For hackathon demo, we mock AI responses
use_mock_responses: bool = True
@dataclass
class NotificationConfig:
"""Notification service configuration"""
twilio_account_sid: str = "demo-account"
twilio_auth_token: str = "demo-token"
twilio_phone_number: str = "+1-555-CARELOOP"
email_service: str = "sendgrid"
email_api_key: str = "demo-email-key"
@dataclass
class HealthIntegrationConfig:
"""Health device and service integrations"""
apple_health_enabled: bool = True
fitbit_enabled: bool = True
omron_enabled: bool = True # Blood pressure monitors
dexcom_enabled: bool = False # Continuous glucose monitoring
epic_fhir_enabled: bool = False # Electronic health records
@dataclass
class SecurityConfig:
"""Security and privacy settings"""
encryption_key: str = "demo-encryption-key-32-chars-long"
jwt_secret: str = "demo-jwt-secret-key"
session_timeout_hours: int = 24
max_login_attempts: int = 5
require_2fa: bool = False # For demo
@dataclass
class CareLoopConfig:
"""Main application configuration"""
# Subsystem configs - non-default parameters must come first
database: DatabaseConfig
ai: AIConfig
notifications: NotificationConfig
health_integrations: HealthIntegrationConfig
security: SecurityConfig
# Environment
environment: str = "development"
debug: bool = True
# Web server
host: str = "0.0.0.0"
port: int = 8000
workers: int = 1
# Feature flags
enable_web_interface: bool = True
enable_api: bool = True
enable_websockets: bool = True
enable_background_tasks: bool = True
# Monitoring intervals
health_check_interval_hours: int = 4
medication_check_interval_hours: int = 2
emergency_check_interval_minutes: int = 15
def __init__(self):
self.database = DatabaseConfig()
self.ai = AIConfig()
self.notifications = NotificationConfig()
self.health_integrations = HealthIntegrationConfig()
self.security = SecurityConfig()
def load_config() -> CareLoopConfig:
"""Load configuration from environment variables"""
config = CareLoopConfig()
# Override with environment variables if present
config.environment = os.getenv("CARELOOP_ENV", "development")
config.debug = os.getenv("CARELOOP_DEBUG", "true").lower() == "true"
config.host = os.getenv("CARELOOP_HOST", "0.0.0.0")
config.port = int(os.getenv("CARELOOP_PORT", "8000"))
# Database
config.database.url = os.getenv("DATABASE_URL", "sqlite:///careloop_demo.db")
# AI Configuration
config.ai.openai_api_key = os.getenv("OPENAI_API_KEY", "demo-key")
config.ai.use_mock_responses = os.getenv("USE_MOCK_AI", "true").lower() == "true"
# Notifications
config.notifications.twilio_account_sid = os.getenv("TWILIO_ACCOUNT_SID", "demo")
config.notifications.twilio_auth_token = os.getenv("TWILIO_AUTH_TOKEN", "demo")
config.notifications.email_api_key = os.getenv("EMAIL_API_KEY", "demo")
# Security
config.security.encryption_key = os.getenv("ENCRYPTION_KEY", "demo-key-32-chars-very-secure!!")
config.security.jwt_secret = os.getenv("JWT_SECRET", "demo-jwt-secret")
return config
# Global config instance
CONFIG = load_config()
# Environment-specific configurations
ENVIRONMENT_CONFIGS = {
"development": {
"debug": True,
"log_level": "DEBUG",
"database_echo": True,
"use_mock_integrations": True,
"enable_hot_reload": True
},
"staging": {
"debug": False,
"log_level": "INFO",
"database_echo": False,
"use_mock_integrations": True,
"enable_hot_reload": False
},
"production": {
"debug": False,
"log_level": "WARNING",
"database_echo": False,
"use_mock_integrations": False,
"enable_hot_reload": False,
"require_https": True,
"enable_rate_limiting": True
}
}
def get_environment_config(env: str) -> Dict:
"""Get configuration for specific environment"""
return ENVIRONMENT_CONFIGS.get(env, ENVIRONMENT_CONFIGS["development"])
if __name__ == "__main__":
print("CareLoop Configuration")
print("=" * 30)
print(f"Environment: {CONFIG.environment}")
print(f"Debug mode: {CONFIG.debug}")
print(f"Database: {CONFIG.database.url}")
print(f"AI Mock mode: {CONFIG.ai.use_mock_responses}")
print(f"Web interface: {CONFIG.enable_web_interface}")
print(f"Host: {CONFIG.host}:{CONFIG.port}")