Initial commit
This commit is contained in:
66
omop/src/api/routers/validation.py
Normal file
66
omop/src/api/routers/validation.py
Normal file
@@ -0,0 +1,66 @@
|
||||
"""Validation router."""
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from typing import Optional
|
||||
import logging
|
||||
from sqlalchemy import text
|
||||
|
||||
from ...etl.validator import Validator
|
||||
from ...utils.config import Config
|
||||
from ...utils.db_connection import DatabaseConnection
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/run")
|
||||
async def run_validation(table_name: Optional[str] = None):
|
||||
"""Run data validation."""
|
||||
try:
|
||||
config = Config.load()
|
||||
db = DatabaseConnection(config)
|
||||
validator = Validator(db, config)
|
||||
|
||||
# TODO: Implement validation logic
|
||||
return {
|
||||
"status": "success",
|
||||
"message": f"Validation completed for {table_name if table_name else 'all tables'}"
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Error running validation: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/unmapped-codes")
|
||||
async def get_unmapped_codes(limit: Optional[int] = 50):
|
||||
"""Get unmapped source codes."""
|
||||
try:
|
||||
config = Config.load()
|
||||
db = DatabaseConnection(config)
|
||||
|
||||
with db.get_connection() as conn:
|
||||
result = conn.execute(text(f"""
|
||||
SELECT
|
||||
source_vocabulary,
|
||||
source_code,
|
||||
source_name,
|
||||
frequency,
|
||||
last_seen
|
||||
FROM audit.unmapped_codes
|
||||
ORDER BY frequency DESC
|
||||
LIMIT {limit}
|
||||
"""))
|
||||
|
||||
codes = []
|
||||
for row in result:
|
||||
codes.append({
|
||||
"source_vocabulary": row[0],
|
||||
"source_code": row[1],
|
||||
"source_name": row[2],
|
||||
"frequency": row[3],
|
||||
"last_seen": str(row[4])
|
||||
})
|
||||
|
||||
return {"status": "success", "unmapped_codes": codes}
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting unmapped codes: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
Reference in New Issue
Block a user