File size: 5,127 Bytes
29a6fbf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# 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}")