Spaces:
Sleeping
Sleeping
File size: 911 Bytes
1e732dd 696f787 9659593 1e732dd 696f787 9659593 1e732dd | 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 | """
MediGuard AI — Analysis repository (data-access layer).
"""
from __future__ import annotations
from sqlalchemy.orm import Session
from src.models.analysis import PatientAnalysis
class AnalysisRepository:
"""CRUD operations for patient analyses."""
def __init__(self, db: Session):
self.db = db
def create(self, analysis: PatientAnalysis) -> PatientAnalysis:
self.db.add(analysis)
self.db.flush()
return analysis
def get_by_request_id(self, request_id: str) -> PatientAnalysis | None:
return self.db.query(PatientAnalysis).filter(PatientAnalysis.request_id == request_id).first()
def list_recent(self, limit: int = 20) -> list[PatientAnalysis]:
return self.db.query(PatientAnalysis).order_by(PatientAnalysis.created_at.desc()).limit(limit).all()
def count(self) -> int:
return self.db.query(PatientAnalysis).count()
|