立项配置数据入库、审计日志数据入库、编辑页UI界面美化、设备管理内容补充、审计日志显示优化

This commit is contained in:
Cheng Zhou
2026-02-27 16:16:26 +08:00
parent fd7e3fc948
commit db2d38edbc
48 changed files with 2936 additions and 909 deletions
+51
View File
@@ -25,6 +25,7 @@ from app.schemas.common import PaginatedResponse
from app.schemas.study import StudyCreate, StudyRead, StudyUpdate
from app.schemas.member import StudyMemberCreate
from app.schemas.study_setup_config import (
ProjectPublishSnapshot,
SetupProjectionSummary,
StudySetupConfigData,
StudySetupConfigPublish,
@@ -253,6 +254,42 @@ def _build_default_setup_config_from_study(study, sites: list) -> StudySetupConf
)
def _to_date_text(value: date | None) -> str:
if not value:
return ""
return value.isoformat()
def _build_project_publish_snapshot(study) -> ProjectPublishSnapshot:
return ProjectPublishSnapshot(
code=getattr(study, "code", None) or "",
name=getattr(study, "name", None) or "",
project_full_name=getattr(study, "project_full_name", None) or "",
sponsor=getattr(study, "sponsor", None) or "",
protocol_no=getattr(study, "protocol_no", None) or "",
lead_unit=getattr(study, "lead_unit", None) or "",
principal_investigator=getattr(study, "principal_investigator", None) or "",
main_pm=getattr(study, "main_pm", None) or "",
research_analysis=getattr(study, "research_analysis", None) or "",
research_product=getattr(study, "research_product", None) or "",
control_product=getattr(study, "control_product", None) or "",
indication=getattr(study, "indication", None) or "",
research_population=getattr(study, "research_population", None) or "",
research_design=getattr(study, "research_design", None) or "",
plan_start_date=_to_date_text(getattr(study, "plan_start_date", None)),
plan_end_date=_to_date_text(getattr(study, "plan_end_date", None)),
planned_site_count=getattr(study, "planned_site_count", None),
planned_enrollment_count=getattr(study, "planned_enrollment_count", None),
summary_note=getattr(study, "summary_note", None) or "",
objective_note=getattr(study, "objective_note", None) or "",
status=getattr(study, "status", None) or "",
visit_interval_days=getattr(study, "visit_interval_days", None),
visit_total=getattr(study, "visit_total", None),
visit_window_start_offset=getattr(study, "visit_window_start_offset", None),
visit_window_end_offset=getattr(study, "visit_window_end_offset", None),
)
def _to_setup_config_read(
record,
*,
@@ -268,6 +305,11 @@ def _to_setup_config_read(
data=StudySetupConfigData.model_validate(record.config or {}),
publish_status=record.publish_status or "DRAFT",
published_data=StudySetupConfigData.model_validate(record.published_config) if record.published_config else None,
published_project_snapshot=(
ProjectPublishSnapshot.model_validate(record.published_project_snapshot)
if record.published_project_snapshot
else None
),
published_by=record.published_by,
published_by_name=published_by_name,
published_at=record.published_at,
@@ -764,12 +806,18 @@ async def upsert_study_setup_config(
existing = await study_setup_config_crud.get_by_study(db, study_id)
old_config = dict(existing.config or {}) if existing else {}
force_draft = bool(payload.force_draft)
if existing and existing.publish_status == "PUBLISHED" and existing.published_project_snapshot:
current_project_snapshot = _build_project_publish_snapshot(study).model_dump(mode="json")
if current_project_snapshot != dict(existing.published_project_snapshot or {}):
force_draft = True
record, conflict = await study_setup_config_crud.upsert(
db,
study_id,
expected_version=payload.expected_version,
data=payload.data,
saved_by=current_user.id,
force_draft=force_draft,
)
if conflict:
_raise_conflict_error()
@@ -857,6 +905,9 @@ async def publish_study_setup_config(
for item in projection.skipped_items
],
)
study_after_publish = await study_crud.get(db, study_id)
if study_after_publish:
published.published_project_snapshot = _build_project_publish_snapshot(study_after_publish).model_dump(mode="json")
await audit_crud.log_action(
db,
study_id=study_id,