细节优化——1

This commit is contained in:
Cheng Zhou
2025-12-30 14:07:57 +08:00
parent 71db309e12
commit 0c1fc49f17
40 changed files with 1610 additions and 389 deletions
+21 -4
View File
@@ -1,3 +1,4 @@
import json
import uuid
from datetime import date
@@ -46,6 +47,8 @@ async def create_ae(
current_user=Depends(get_current_user),
) -> AERead:
await _ensure_study_exists(db, study_id)
if ae_in.onset_date and ae_in.onset_date > date.today():
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Onset date cannot be in the future")
member_role = await _get_member_role(db, study_id, current_user.id)
if current_user.role != "ADMIN" and member_role not in ALLOWED_CREATE_ROLES:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Insufficient permissions")
@@ -124,6 +127,8 @@ async def update_ae(
current_user=Depends(get_current_user),
) -> AERead:
await _ensure_study_exists(db, study_id)
if ae_in.onset_date and ae_in.onset_date > date.today():
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Onset date cannot be in the future")
ae = await ae_crud.get_ae(db, ae_id)
if not ae or ae.study_id != study_id:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="AE not found")
@@ -142,12 +147,24 @@ async def update_ae(
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Insufficient permissions")
old_status = ae.status
updated = await ae_crud.update_ae(db, ae, ae_in)
detail_before = {
"event": ae.term,
"onset_date": ae.onset_date,
"severity": ae.severity,
"status": ae.status,
"description": ae.description,
}
updated = await ae_crud.update_ae(db, study_id, ae, ae_in)
detail_after = {
"event": updated.term,
"onset_date": updated.onset_date,
"severity": updated.severity,
"status": updated.status,
"description": updated.description,
}
detail = None
action = "UPDATE_AE"
if ae_in.status and ae_in.status != old_status:
detail = f"AE {ae_id} status {old_status} -> {ae_in.status}"
action = "AE_STATUS_CHANGE"
await audit_crud.log_action(
db,
@@ -155,7 +172,7 @@ async def update_ae(
entity_type="ae",
entity_id=ae_id,
action=action,
detail=detail or "AE updated",
detail=json.dumps({"before": detail_before, "after": detail_after}, ensure_ascii=False, default=str),
operator_id=current_user.id,
operator_role=current_user.role,
)