Spaces:
Sleeping
Sleeping
Update api/__init__.py
Browse files- api/__init__.py +21 -6
api/__init__.py
CHANGED
|
@@ -1,18 +1,33 @@
|
|
| 1 |
-
from fastapi import APIRouter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def get_router():
|
| 4 |
router = APIRouter()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Import sub-modules from the routes directory
|
| 7 |
from .routes.auth import auth
|
| 8 |
from .routes.patients import patients
|
| 9 |
from .routes.pdf import pdf
|
| 10 |
|
| 11 |
-
# Include sub-routers
|
| 12 |
-
router.include_router(patients, prefix="/ehr", tags=["patients"])
|
| 13 |
-
router.include_router(auth, prefix="/auth", tags=["auth"])
|
| 14 |
-
|
| 15 |
-
router.include_router(pdf, prefix="/ehr/patients", tags=["pdf"]) # Use 'pdf' directly
|
| 16 |
|
| 17 |
return router
|
| 18 |
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Request
|
| 2 |
+
import logging
|
| 3 |
+
|
| 4 |
+
# Configure logging
|
| 5 |
+
logging.basicConfig(
|
| 6 |
+
level=logging.INFO,
|
| 7 |
+
format='%(asctime)s - %(levelname)s - %(name)s - %(message)s'
|
| 8 |
+
)
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
def get_router():
|
| 12 |
router = APIRouter()
|
| 13 |
+
|
| 14 |
+
# Middleware to log incoming requests
|
| 15 |
+
@router.middleware("http")
|
| 16 |
+
async def log_requests(request: Request, call_next):
|
| 17 |
+
logger.info(f"Incoming request: {request.method} {request.url.path} from {request.client.host}")
|
| 18 |
+
response = await call_next(request)
|
| 19 |
+
logger.info(f"Response status: {response.status_code} for {request.method} {request.url.path}")
|
| 20 |
+
return response
|
| 21 |
|
| 22 |
# Import sub-modules from the routes directory
|
| 23 |
from .routes.auth import auth
|
| 24 |
from .routes.patients import patients
|
| 25 |
from .routes.pdf import pdf
|
| 26 |
|
| 27 |
+
# Include sub-routers, prioritizing patients to avoid conflicts
|
| 28 |
+
router.include_router(patients, prefix="/ehr", tags=["patients"]) # Moved first
|
| 29 |
+
router.include_router(auth, prefix="/auth", tags=["auth"])
|
| 30 |
+
router.include_router(pdf, prefix="/ehr/patients", tags=["pdf"]) # Moved last
|
|
|
|
| 31 |
|
| 32 |
return router
|
| 33 |
|