未知(继上次中断)

This commit is contained in:
Cheng Zhou
2026-02-04 10:52:34 +08:00
parent 8e258d21a7
commit 737f84bf54
99 changed files with 5497 additions and 2143 deletions
+35 -4
View File
@@ -5,7 +5,7 @@ from datetime import date
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.deps import get_current_user, get_db_session, require_study_member, require_study_not_locked
from app.core.deps import get_cra_site_scope, get_current_user, get_db_session, require_study_member, require_study_not_locked
from app.crud import ae as ae_crud
from app.crud import audit as audit_crud
from app.crud import member as member_crud
@@ -65,6 +65,14 @@ async def create_ae(
current_user=Depends(get_current_user),
) -> AERead:
await _ensure_study_exists(db, study_id)
cra_scope = await get_cra_site_scope(db, study_id, current_user)
if cra_scope:
if ae_in.site_id and ae_in.site_id not in cra_scope[0]:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="权限不足")
if ae_in.subject_id:
subj = await subject_crud.get_subject(db, ae_in.subject_id)
if subj and subj.site_id not in cra_scope[0]:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="权限不足")
if ae_in.onset_date and ae_in.onset_date > date.today():
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="发生日期不能晚于今天")
member_role = await _get_member_role(db, study_id, current_user.id)
@@ -102,9 +110,23 @@ async def list_ae(
subject_id: uuid.UUID | None = None,
overdue: bool | None = None,
db: AsyncSession = Depends(get_db_session),
current_user=Depends(get_current_user),
) -> list[AERead]:
await _ensure_study_exists(db, study_id)
aes = await ae_crud.list_ae(db, study_id, status=status_filter, seriousness=seriousness, site_id=site_id, subject_id=subject_id, overdue=overdue)
cra_scope = await get_cra_site_scope(db, study_id, current_user)
site_ids = cra_scope[0] if cra_scope else None
if site_id and site_ids is not None and site_id not in site_ids:
return []
aes = await ae_crud.list_ae(
db,
study_id,
status=status_filter,
seriousness=seriousness,
site_id=site_id,
subject_id=subject_id,
overdue=overdue,
site_ids=site_ids,
)
result: list[AERead] = []
for item in aes:
obj = AERead.model_validate(item)
@@ -122,6 +144,7 @@ async def get_ae(
study_id: uuid.UUID,
ae_id: uuid.UUID,
db: AsyncSession = Depends(get_db_session),
current_user=Depends(get_current_user),
) -> AERead:
await _ensure_study_exists(db, study_id)
ae = await ae_crud.get_ae(db, ae_id)
@@ -129,6 +152,14 @@ async def get_ae(
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="AE 不存在")
data = AERead.model_validate(ae)
data.is_overdue = _is_overdue(data)
cra_scope = await get_cra_site_scope(db, study_id, current_user)
if cra_scope:
if data.site_id and data.site_id not in cra_scope[0]:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="权限不足")
if data.subject_id:
subj = await subject_crud.get_subject(db, data.subject_id)
if subj and subj.site_id not in cra_scope[0]:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="权限不足")
return data
@@ -169,7 +200,7 @@ async def update_ae(
detail_before = {
"event": ae.term,
"onset_date": ae.onset_date,
"severity": ae.severity,
"seriousness": ae.seriousness,
"status": ae.status,
"description": ae.description,
}
@@ -177,7 +208,7 @@ async def update_ae(
detail_after = {
"event": updated.term,
"onset_date": updated.onset_date,
"severity": updated.severity,
"seriousness": updated.seriousness,
"status": updated.status,
"description": updated.description,
}