File size: 1,239 Bytes
1441b40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from fastapi import APIRouter, HTTPException
import sys
import os

# Add parent directory to path for imports
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"}