立项配置页初步优化
This commit is contained in:
+37
-19
@@ -9,23 +9,29 @@ from app.schemas.study import StudyCreate, StudyUpdate
|
||||
|
||||
|
||||
async def create(db: AsyncSession, study_in: StudyCreate, *, created_by: uuid.UUID | None = None) -> Study:
|
||||
import uuid as uuid_lib # Import uuid to generate unique code if needed
|
||||
|
||||
code = study_in.code
|
||||
if not code:
|
||||
# Generate a unique code if not provided
|
||||
# Use first 8 chars of a new UUID, uppercase
|
||||
code = f"P-{str(uuid_lib.uuid4())[:8].upper()}"
|
||||
|
||||
study = Study(
|
||||
code=code,
|
||||
code=study_in.code.strip(),
|
||||
name=study_in.name,
|
||||
# sponsor is removed from schema, but model has it. Set to None/empty or keep existing value if schema had it (which it doesn't now)
|
||||
# If we removed it from schema, study_in.sponsor will fail if we try to access it via .sponsor attribute directly if it's not in the pydantic model anymore.
|
||||
# Since we removed `sponsor` field from StudyCreate, `study_in` object won't have `sponsor` attribute unless we access dict or use default.
|
||||
# However, the Study MODEL still has sponsor. We should set it to None.
|
||||
sponsor=None,
|
||||
project_full_name=study_in.project_full_name,
|
||||
sponsor=study_in.sponsor,
|
||||
protocol_no=study_in.protocol_no,
|
||||
lead_unit=study_in.lead_unit,
|
||||
principal_investigator=study_in.principal_investigator,
|
||||
main_pm=study_in.main_pm,
|
||||
research_analysis=study_in.research_analysis,
|
||||
research_product=study_in.research_product,
|
||||
control_product=study_in.control_product,
|
||||
indication=study_in.indication,
|
||||
research_population=study_in.research_population,
|
||||
research_design=study_in.research_design,
|
||||
plan_start_date=study_in.plan_start_date,
|
||||
plan_end_date=study_in.plan_end_date,
|
||||
planned_site_count=study_in.planned_site_count,
|
||||
planned_enrollment_count=study_in.planned_enrollment_count,
|
||||
enrollment_monthly_goal_note=study_in.enrollment_monthly_goal_note,
|
||||
enrollment_stage_breakdown=study_in.enrollment_stage_breakdown,
|
||||
summary_note=study_in.summary_note,
|
||||
objective_note=study_in.objective_note,
|
||||
phase=study_in.phase,
|
||||
status=study_in.status,
|
||||
visit_interval_days=study_in.visit_interval_days,
|
||||
@@ -114,6 +120,10 @@ async def delete(db: AsyncSession, study_id: uuid.UUID) -> None:
|
||||
from app.models.faq_category import FaqCategory
|
||||
from app.models.faq_item import FaqItem
|
||||
from app.models.faq_reply import FaqReply
|
||||
from app.models.study_setup_config import StudySetupConfig
|
||||
from app.models.study_setup_config_version import StudySetupConfigVersion
|
||||
from app.models.study_monitoring_strategy import StudyMonitoringStrategy
|
||||
from app.models.study_center_confirm import StudyCenterConfirm
|
||||
|
||||
# 按依赖关系顺序删除关联数据
|
||||
# 1. 删除审计日志
|
||||
@@ -160,13 +170,21 @@ async def delete(db: AsyncSession, study_id: uuid.UUID) -> None:
|
||||
await db.execute(sa_delete(SubjectHistory).where(SubjectHistory.study_id == study_id))
|
||||
await db.execute(sa_delete(Subject).where(Subject.study_id == study_id))
|
||||
|
||||
# 13. 删除站点
|
||||
# 13. 删除立项联动实体(需先于站点删除,避免外键约束)
|
||||
await db.execute(sa_delete(StudyMonitoringStrategy).where(StudyMonitoringStrategy.study_id == study_id))
|
||||
await db.execute(sa_delete(StudyCenterConfirm).where(StudyCenterConfirm.study_id == study_id))
|
||||
|
||||
# 14. 删除站点
|
||||
await db.execute(sa_delete(Site).where(Site.study_id == study_id))
|
||||
|
||||
# 14. 删除成员
|
||||
|
||||
# 15. 删除成员
|
||||
await db.execute(sa_delete(StudyMember).where(StudyMember.study_id == study_id))
|
||||
|
||||
# 15. 最后删除项目本身
|
||||
|
||||
# 16. 删除立项配置
|
||||
await db.execute(sa_delete(StudySetupConfigVersion).where(StudySetupConfigVersion.study_id == study_id))
|
||||
await db.execute(sa_delete(StudySetupConfig).where(StudySetupConfig.study_id == study_id))
|
||||
|
||||
# 17. 最后删除项目本身
|
||||
await db.execute(sa_delete(Study).where(Study.id == study_id))
|
||||
|
||||
await db.commit()
|
||||
|
||||
Reference in New Issue
Block a user