-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
241 lines (196 loc) Β· 8.61 KB
/
Copy pathconfig.py
File metadata and controls
241 lines (196 loc) Β· 8.61 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env python3
"""
Configuration manager for Healthcare Provider Validation System.
Allows switching between API mode and mock mode.
"""
import os
import sys
from pathlib import Path
from typing import Dict, Any
class ConfigManager:
"""Manages system configuration and mode switching."""
def __init__(self):
self.config_file = Path("system_config.json")
self.default_config = {
"mode": "mock", # "api" or "mock"
"apis": {
"npi_registry": {"enabled": False, "url": "https://npiregistry.cms.hhs.gov/api/"},
"google_maps": {"enabled": False, "url": "https://maps.googleapis.com/maps/api/"},
"twilio": {"enabled": False, "url": "https://lookups.twilio.com/v1/"},
"openai": {"enabled": False, "url": "https://api.openai.com/v1/"}
},
"mock_settings": {
"success_rate": 0.85,
"delay_simulation": True,
"realistic_responses": True
}
}
self.load_config()
def load_config(self):
"""Load configuration from file."""
if self.config_file.exists():
import json
with open(self.config_file, 'r') as f:
self.config = json.load(f)
else:
self.config = self.default_config.copy()
self.save_config()
def save_config(self):
"""Save configuration to file."""
import json
with open(self.config_file, 'w') as f:
json.dump(self.config, f, indent=2)
def set_mode(self, mode: str):
"""Set system mode (api or mock)."""
if mode not in ["api", "mock"]:
raise ValueError("Mode must be 'api' or 'mock'")
self.config["mode"] = mode
if mode == "api":
# Enable all APIs
for api in self.config["apis"]:
self.config["apis"][api]["enabled"] = True
else:
# Disable all APIs
for api in self.config["apis"]:
self.config["apis"][api]["enabled"] = False
self.save_config()
print(f"β
System mode set to: {mode.upper()}")
def toggle_api(self, api_name: str, enabled: bool = None):
"""Toggle specific API on/off."""
if api_name not in self.config["apis"]:
raise ValueError(f"Unknown API: {api_name}")
if enabled is None:
# Toggle current state
self.config["apis"][api_name]["enabled"] = not self.config["apis"][api_name]["enabled"]
else:
self.config["apis"][api_name]["enabled"] = enabled
self.save_config()
status = "enabled" if self.config["apis"][api_name]["enabled"] else "disabled"
print(f"β
{api_name.upper()} API {status}")
def get_status(self):
"""Get current system status."""
mode = self.config["mode"]
enabled_apis = [api for api, config in self.config["apis"].items() if config["enabled"]]
disabled_apis = [api for api, config in self.config["apis"].items() if not config["enabled"]]
return {
"mode": mode,
"enabled_apis": enabled_apis,
"disabled_apis": disabled_apis,
"total_apis": len(self.config["apis"])
}
def print_status(self):
"""Print current system status."""
status = self.get_status()
print("\nπ₯ Healthcare Provider Validation System - Configuration")
print("=" * 60)
print(f"π Current Mode: {status['mode'].upper()}")
print(f"π Enabled APIs: {', '.join(status['enabled_apis']) if status['enabled_apis'] else 'None'}")
print(f"π« Disabled APIs: {', '.join(status['disabled_apis']) if status['disabled_apis'] else 'None'}")
print(f"π Total APIs: {status['total_apis']}")
if status['mode'] == 'mock':
print("\nπ Mock Mode Features:")
print(" β’ Simulated API responses")
print(" β’ Realistic delays and success rates")
print(" β’ No external API calls")
print(" β’ Perfect for development and testing")
else:
print("\nπ API Mode Features:")
print(" β’ Real external API calls")
print(" β’ Live data validation")
print(" β’ Production-ready functionality")
print(" β’ Requires valid API keys")
def setup_api_keys(self):
"""Interactive API key setup."""
print("\nπ API Key Setup")
print("=" * 30)
api_keys = {}
# OpenAI
if self.config["apis"]["openai"]["enabled"]:
key = input("Enter OpenAI API Key (or press Enter to skip): ").strip()
if key:
api_keys["OPENAI_API_KEY"] = key
# Google Maps
if self.config["apis"]["google_maps"]["enabled"]:
key = input("Enter Google Maps API Key (or press Enter to skip): ").strip()
if key:
api_keys["GOOGLE_MAPS_API_KEY"] = key
# Twilio
if self.config["apis"]["twilio"]["enabled"]:
sid = input("Enter Twilio Account SID (or press Enter to skip): ").strip()
token = input("Enter Twilio Auth Token (or press Enter to skip): ").strip()
if sid and token:
api_keys["TWILIO_ACCOUNT_SID"] = sid
api_keys["TWILIO_AUTH_TOKEN"] = token
# Update .env file
if api_keys:
env_file = Path(".env")
env_content = env_file.read_text() if env_file.exists() else ""
for key, value in api_keys.items():
if f"{key}=" in env_content:
# Update existing key
import re
env_content = re.sub(f"{key}=.*", f"{key}={value}", env_content)
else:
# Add new key
env_content += f"\n{key}={value}\n"
env_file.write_text(env_content)
print(f"β
Updated .env file with {len(api_keys)} API keys")
else:
print("βΉοΈ No API keys provided")
def main():
"""Main CLI interface."""
if len(sys.argv) < 2:
print("π₯ Healthcare Provider Validation System - Configuration Manager")
print("=" * 70)
print("\nUsage:")
print(" python config.py status - Show current status")
print(" python config.py mode <api|mock> - Set system mode")
print(" python config.py toggle <api_name> - Toggle specific API")
print(" python config.py enable <api_name> - Enable specific API")
print(" python config.py disable <api_name> - Disable specific API")
print(" python config.py setup - Interactive API key setup")
print(" python config.py reset - Reset to default config")
print("\nAvailable APIs: npi_registry, google_maps, twilio, openai")
return
config = ConfigManager()
command = sys.argv[1].lower()
try:
if command == "status":
config.print_status()
elif command == "mode":
if len(sys.argv) < 3:
print("β Please specify mode: 'api' or 'mock'")
return
mode = sys.argv[2].lower()
config.set_mode(mode)
elif command == "toggle":
if len(sys.argv) < 3:
print("β Please specify API name")
return
api_name = sys.argv[2].lower()
config.toggle_api(api_name)
elif command == "enable":
if len(sys.argv) < 3:
print("β Please specify API name")
return
api_name = sys.argv[2].lower()
config.toggle_api(api_name, True)
elif command == "disable":
if len(sys.argv) < 3:
print("β Please specify API name")
return
api_name = sys.argv[2].lower()
config.toggle_api(api_name, False)
elif command == "setup":
config.setup_api_keys()
elif command == "reset":
config.config = config.default_config.copy()
config.save_config()
print("β
Configuration reset to defaults")
else:
print(f"β Unknown command: {command}")
print("Run 'python config.py' for help")
except Exception as e:
print(f"β Error: {e}")
if __name__ == "__main__":
main()