|
|
from fastapi import APIRouter, HTTPException |
|
|
import sys |
|
|
import os |
|
|
|
|
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
|
|
|
|
|
from models.request_models import ProviderNotesRequest |
|
|
from models.response_models import CodingResponse |
|
|
from services.groq_service import groq_service |
|
|
|
|
|
router = APIRouter(prefix="/api/v1", tags=["Medical Coding"]) |
|
|
|
|
|
@router.post("/analyze", response_model=CodingResponse) |
|
|
async def analyze_provider_notes(request: ProviderNotesRequest): |
|
|
""" |
|
|
Analyze provider notes and return ICD-10 and CPT codes with explanations. |
|
|
|
|
|
- **provider_notes**: The medical provider notes to analyze |
|
|
|
|
|
Returns ICD-10 codes, CPT codes, and explanations for each. |
|
|
""" |
|
|
try: |
|
|
result = await groq_service.analyze_provider_notes(request.provider_notes) |
|
|
return CodingResponse(**result) |
|
|
except ValueError as e: |
|
|
raise HTTPException(status_code=422, detail=str(e)) |
|
|
except Exception as e: |
|
|
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}") |
|
|
|
|
|
@router.get("/health") |
|
|
async def health_check(): |
|
|
"""Health check endpoint""" |
|
|
return {"status": "healthy", "service": "ICD-CPT Coding API"} |