Skip to content

Commit 6b92b13

Browse files
committed
Load environment from .env file in each service entrypoint
Running outside of docker we need the flexibility of setting up the environment with appropriate paths and secrets. Use dotenv for this.
1 parent 8534278 commit 6b92b13

4 files changed

Lines changed: 60 additions & 6 deletions

File tree

src/mwl_main.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33
import logging
44
import os
55

6+
from dotenv import load_dotenv
7+
68
from server import MWLServer
79

10+
load_dotenv()
11+
812

913
def main():
10-
"""Main entry point for MWL server."""
14+
"""
15+
Main entry point for MWL server.
16+
17+
Environment variables:
18+
MWL_AET: AE Title for the MWL server (default: MWL_SCP)
19+
MWL_PORT: Port to listen on (default: 4243)
20+
MWL_DB_PATH: Path to the SQLite database file (default: /var/lib/pacs/worklist.db)
21+
"""
1122
logging.basicConfig(
1223
level=os.getenv("LOG_LEVEL", "INFO").upper(),
1324
format=os.getenv("LOG_FORMAT", "%(asctime)s - %(name)s - %(levelname)s - %(message)s"),

src/pacs_main.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@
33
import logging
44
import os
55

6+
from dotenv import load_dotenv
7+
68
from server import PACSServer
79

10+
load_dotenv()
11+
812

913
def main():
10-
"""Main entry point for PACS server."""
14+
"""
15+
Main entry point for PACS server.
16+
17+
Environment variables:
18+
PACS_AET: AE Title for the PACS server (default: SCREENING_PACS)
19+
PACS_PORT: Port to listen on (default: 4244)
20+
PACS_STORAGE_PATH: Path to store incoming DICOM files (default: /var/lib/pacs/storage)
21+
PACS_DB_PATH: Path to the SQLite database file (default: /var/lib/pacs/pacs.db)
22+
"""
1123
logging.basicConfig(
1224
level=os.getenv("LOG_LEVEL", "INFO").upper(),
1325
format=os.getenv("LOG_FORMAT", "%(asctime)s - %(name)s - %(levelname)s - %(message)s"),

src/relay_listener.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
import time
1515
import urllib.parse
1616

17+
from dotenv import load_dotenv
1718
from websockets.asyncio.client import connect
1819

1920
from services.mwl.create_worklist_item import CreateWorklistItem
2021
from services.storage import MWLStorage
2122

23+
load_dotenv()
24+
2225
logger = logging.getLogger(__name__)
2326

2427
DB_PATH = os.getenv("MWL_DB_PATH", "/var/lib/pacs/worklist.db")
@@ -30,7 +33,17 @@
3033

3134

3235
class RelayListener:
33-
"""Socket Listener for Azure Relay."""
36+
"""
37+
Socket Listener for Azure Relay.
38+
39+
Listens for incoming messages from Azure Relay and processes worklist actions.
40+
Environment variables:
41+
AZURE_RELAY_NAMESPACE: Azure Relay namespace (default: relay-test.servicebus.windows.net)
42+
AZURE_RELAY_HYBRID_CONNECTION: Azure Relay hybrid connection name (default: relay-test-hc)
43+
AZURE_RELAY_KEY_NAME: Azure Relay shared access key name (default: RootManageSharedAccessKey)
44+
AZURE_RELAY_SHARED_ACCESS_KEY: Azure Relay shared access key (default: none)
45+
MWL_DB_PATH: Path to the MWL SQLite database file (default: /var/lib/pacs/worklist.db)
46+
"""
3447

3548
def __init__(self, storage: MWLStorage):
3649
self.storage = storage

src/upload_main.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,30 @@
33
import logging
44
import os
55

6+
from dotenv import load_dotenv
7+
68
from services.dicom.dicom_uploader import DICOMUploader
79
from services.dicom.upload_listener import UploadListener
810
from services.dicom.upload_processor import UploadProcessor
911
from services.storage import MWLStorage, PACSStorage
1012

13+
load_dotenv()
14+
1115

1216
def main():
13-
"""Main entry point for upload listener service."""
17+
"""
18+
Main entry point for upload listener service.
19+
20+
Environment variables:
21+
CLOUD_API_ENDPOINT: URL of the cloud API endpoint to upload to (default: http://localhost:8000/api/dicom/upload)
22+
CLOUD_API_KEY: API key for authenticating with the cloud API (default: none)
23+
MAX_UPLOAD_RETRIES: Maximum number of upload retries before giving up (default: 3)
24+
MWL_DB_PATH: Path to the MWL SQLite database file (default: /var/lib/pacs/worklist.db)
25+
PACS_DB_PATH: Path to the PACS SQLite database file (default: /var/lib/pacs/pacs.db)
26+
PACS_STORAGE_PATH: Path to the directory where DICOM files are stored (default: /var/lib/pacs/storage)
27+
UPLOAD_POLL_INTERVAL: Time in seconds between polling for new uploads (default: 2)
28+
UPLOAD_BATCH_SIZE: Number of pending uploads to process in each batch (default: 10)
29+
"""
1430
logging.basicConfig(
1531
level=os.getenv("LOG_LEVEL", "INFO").upper(),
1632
format=os.getenv("LOG_FORMAT", "%(asctime)s - %(name)s - %(levelname)s - %(message)s"),
@@ -20,8 +36,10 @@ def main():
2036
batch_size = int(os.getenv("UPLOAD_BATCH_SIZE", "10"))
2137
max_retries = int(os.getenv("MAX_UPLOAD_RETRIES", "3"))
2238

23-
pacs_storage = PACSStorage()
24-
mwl_storage = MWLStorage()
39+
pacs_storage = PACSStorage(
40+
os.getenv("PACS_DB_PATH", "/var/lib/pacs/pacs.db"), os.getenv("PACS_STORAGE_PATH", "/var/lib/pacs/storage")
41+
)
42+
mwl_storage = MWLStorage(os.getenv("MWL_DB_PATH", "/var/lib/pacs/worklist.db"))
2543
uploader = DICOMUploader()
2644

2745
processor = UploadProcessor(

0 commit comments

Comments
 (0)