# app/controllers/health_controller.py """ HealthSync AI 건강 분석 컨트롤러 """ from fastapi import APIRouter, status, HTTPException, Query from app.controllers.base_controller import BaseController from app.services.health_service import HealthService from app.dto.response.health_response import HealthDiagnosisResponse class HealthController(BaseController): """건강 분석 관련 컨트롤러""" def __init__(self): super().__init__() self.health_service = HealthService() self.router = APIRouter() self._setup_routes() def _setup_routes(self): """라우트 설정""" @self.router.get("/diagnosis", response_model=HealthDiagnosisResponse, status_code=status.HTTP_200_OK, summary="🔬 AI 건강검진 3줄 요약 진단", description=""" 사용자의 건강검진 데이터를 기반으로 AI가 3줄로 요약 진단을 제공합니다. **처리 과정:** 1. 사용자 기본 정보 조회 (직업, 나이 등) 2. 최신 건강검진 데이터 조회 3. Claude AI를 통한 의학적 분석 4. 3문장으로 구성된 요약 진단 반환 **진단 특징:** - 객관적이고 정확한 의학적 판단 - 가장 중요한 건강 지표 우선 분석 - 직업 특성을 고려한 맞춤형 조언 - 개선점과 긍정적 요소의 균형 있는 제시 """) async def get_health_diagnosis(user_id: int = Query(..., gt=0, description="사용자 ID")) -> HealthDiagnosisResponse: """AI 기반 건강검진 3줄 요약 진단""" try: self.log_request("get_health_diagnosis", user_id=user_id) # 건강 진단 서비스 호출 diagnosis = await self.health_service.get_three_sentence_diagnosis(user_id) # 응답 생성 response = HealthDiagnosisResponse(threeSentenceSummary=diagnosis) self.logger.info(f"건강 진단 성공 - user_id: {user_id}, " f"진단 길이: {len(diagnosis)} 문자") return response except ValueError as e: # 사용자나 데이터를 찾을 수 없는 경우 self.logger.warning(f"데이터 없음 - user_id: {user_id}, error: {str(e)}") raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, detail=str(e) ) except Exception as e: self.handle_service_error(e, "get_health_diagnosis") # 컨트롤러 인스턴스 생성 health_controller = HealthController()