26 lines
942 B
Python
26 lines
942 B
Python
|
|
from sqlalchemy import select
|
||
|
|
from sqlalchemy.orm import Session, selectinload
|
||
|
|
|
||
|
|
from app.models.source_case import CaseBase
|
||
|
|
|
||
|
|
|
||
|
|
class TeachingRepository:
|
||
|
|
"""教学互动仓储:读取 case_base + teaching_case 以及评分相关扩展数据。"""
|
||
|
|
|
||
|
|
def __init__(self, db: Session) -> None:
|
||
|
|
self.db = db
|
||
|
|
|
||
|
|
def get_active_teaching_case(self, case_id: int) -> CaseBase | None:
|
||
|
|
"""教学病例读取:校验病例已发布、已启用且存在 teaching_case 扩展。"""
|
||
|
|
stmt = (
|
||
|
|
select(CaseBase)
|
||
|
|
.options(
|
||
|
|
selectinload(CaseBase.teaching_case),
|
||
|
|
selectinload(CaseBase.traditional_case),
|
||
|
|
selectinload(CaseBase.scoring_rules),
|
||
|
|
)
|
||
|
|
.where(CaseBase.id == case_id, CaseBase.status == 1, CaseBase.publish_status == 1)
|
||
|
|
)
|
||
|
|
case = self.db.scalar(stmt)
|
||
|
|
return case if case and case.teaching_case else None
|