feat: implement Contec patient monitor discovery tool and server framework
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import json
|
||||
import os
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
class Settings(BaseSettings):
|
||||
hl7_host: str = "0.0.0.0"
|
||||
hl7_port: int = 6060
|
||||
contec_ports: list = [511, 515, 516, 517, 518, 519, 520]
|
||||
monitor_ip: str = ""
|
||||
monitor_model: str = "CMS7000PLUS"
|
||||
device_models: dict = {}
|
||||
target_api_url: str = "https://api.example.com/vitals"
|
||||
api_token: str = ""
|
||||
retry_interval_seconds: int = 60
|
||||
log_file: str = "hl7_forwarder.log"
|
||||
database_url: str = "sqlite:///./hl7_forwarder.db"
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
|
||||
def get_settings() -> Settings:
|
||||
base_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
config_file = os.path.join(base_dir, "config.json")
|
||||
|
||||
settings_obj = Settings()
|
||||
|
||||
if os.path.exists(config_file):
|
||||
with open(config_file, "r") as f:
|
||||
try:
|
||||
data = json.load(f)
|
||||
for k, v in data.items():
|
||||
setattr(settings_obj, k, v)
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
|
||||
if settings_obj.database_url.startswith("sqlite:///./"):
|
||||
db_name = settings_obj.database_url.split("sqlite:///./")[1]
|
||||
settings_obj.database_url = f"sqlite:///{os.path.join(base_dir, db_name)}"
|
||||
|
||||
if not os.path.isabs(settings_obj.log_file):
|
||||
settings_obj.log_file = os.path.join(base_dir, settings_obj.log_file)
|
||||
|
||||
return settings_obj
|
||||
|
||||
settings = get_settings()
|
||||
Reference in New Issue
Block a user