chore: finalize backend feature scope
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from sqlalchemy import exists, select
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session, selectinload
|
||||
|
||||
from app.models.source_case import CaseBase, CaseExamItem, TeachingCase, TraditionalCase
|
||||
from app.models.source_case import CaseBase, CaseExamItem
|
||||
|
||||
|
||||
class CaseRepository:
|
||||
@@ -10,31 +10,8 @@ class CaseRepository:
|
||||
def __init__(self, db: Session) -> None:
|
||||
self.db = db
|
||||
|
||||
def list_active_cases(
|
||||
self,
|
||||
department_id: int | None = None,
|
||||
training_type: str | None = None,
|
||||
mode: str | None = None,
|
||||
) -> list[CaseBase]:
|
||||
"""病例列表:从 case_base 读取已发布病例,并按模式匹配扩展表。"""
|
||||
normalized_mode = "practice" if mode == "novice" else mode
|
||||
stmt = (
|
||||
select(CaseBase)
|
||||
.options(selectinload(CaseBase.traditional_case), selectinload(CaseBase.teaching_case))
|
||||
.where(CaseBase.status == 1, CaseBase.publish_status == 1)
|
||||
)
|
||||
if department_id:
|
||||
stmt = stmt.where(CaseBase.department_id == department_id)
|
||||
if training_type:
|
||||
stmt = stmt.where(CaseBase.case_type == training_type)
|
||||
if normalized_mode == "practice":
|
||||
stmt = stmt.where(exists().where(TraditionalCase.case_id == CaseBase.id))
|
||||
if normalized_mode == "teaching":
|
||||
stmt = stmt.where(exists().where(TeachingCase.case_id == CaseBase.id))
|
||||
return list(self.db.scalars(stmt.order_by(CaseBase.id.desc())).all())
|
||||
|
||||
def get_active_case(self, case_id: int) -> CaseBase | None:
|
||||
"""病例详情:读取病例主表及训练所需的扩展表、评分规则和检查项目。"""
|
||||
"""病例读取:读取病例主表及训练所需的扩展表、评分规则和检查项目。"""
|
||||
stmt = (
|
||||
select(CaseBase)
|
||||
.options(
|
||||
|
||||
Reference in New Issue
Block a user