细节优化——1
This commit is contained in:
@@ -52,7 +52,7 @@ async def create_ae(
|
||||
severity=ae_in.severity,
|
||||
causality=ae_in.causality,
|
||||
action_taken=None,
|
||||
outcome=None,
|
||||
outcome=ae_in.outcome,
|
||||
reported_to_sponsor=False,
|
||||
report_due_date=due_date,
|
||||
status="NEW",
|
||||
@@ -96,8 +96,10 @@ async def list_ae(
|
||||
return result.scalars().all()
|
||||
|
||||
|
||||
async def update_ae(db: AsyncSession, ae: AdverseEvent, ae_in: AEUpdate) -> AdverseEvent:
|
||||
async def update_ae(db: AsyncSession, study_id: uuid.UUID, ae: AdverseEvent, ae_in: AEUpdate) -> AdverseEvent:
|
||||
update_data = ae_in.model_dump(exclude_unset=True)
|
||||
if "subject_id" in update_data:
|
||||
await _validate_site_subject(db, study_id, None, update_data["subject_id"])
|
||||
if "onset_date" in update_data or "seriousness" in update_data:
|
||||
onset = update_data.get("onset_date", ae.onset_date)
|
||||
seriousness = update_data.get("seriousness", ae.seriousness)
|
||||
|
||||
@@ -40,6 +40,7 @@ async def list_logs(
|
||||
entity_type: str | None = None,
|
||||
entity_id: uuid.UUID | None = None,
|
||||
action: str | None = None,
|
||||
operator_id: uuid.UUID | None = None,
|
||||
skip: int = 0,
|
||||
limit: int = 100,
|
||||
) -> Sequence[AuditLog]:
|
||||
@@ -50,6 +51,18 @@ async def list_logs(
|
||||
stmt = stmt.where(AuditLog.entity_id == entity_id)
|
||||
if action:
|
||||
stmt = stmt.where(AuditLog.action == action)
|
||||
if operator_id:
|
||||
stmt = stmt.where(AuditLog.operator_id == operator_id)
|
||||
stmt = stmt.order_by(AuditLog.created_at.desc()).offset(skip).limit(limit)
|
||||
result = await db.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
|
||||
async def get_log(db: AsyncSession, log_id: uuid.UUID) -> AuditLog | None:
|
||||
result = await db.execute(select(AuditLog).where(AuditLog.id == log_id))
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def delete_log(db: AsyncSession, log: AuditLog) -> None:
|
||||
await db.delete(log)
|
||||
await db.commit()
|
||||
|
||||
@@ -21,6 +21,7 @@ async def create_comment(
|
||||
entity_type=entity_type,
|
||||
entity_id=entity_id,
|
||||
content=comment_in.content,
|
||||
quote_comment_id=comment_in.quote_comment_id,
|
||||
created_by=created_by,
|
||||
)
|
||||
db.add(comment)
|
||||
@@ -46,3 +47,35 @@ async def list_comments(
|
||||
.order_by(Comment.created_at.asc())
|
||||
)
|
||||
return result.scalars().all()
|
||||
|
||||
|
||||
async def get_comment(db: AsyncSession, comment_id: uuid.UUID, *, include_deleted: bool = False) -> Comment | None:
|
||||
stmt = select(Comment).where(Comment.id == comment_id)
|
||||
if not include_deleted:
|
||||
stmt = stmt.where(Comment.is_deleted.is_(False))
|
||||
result = await db.execute(stmt)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def get_comments_by_ids(
|
||||
db: AsyncSession,
|
||||
ids: set[uuid.UUID],
|
||||
*,
|
||||
include_deleted: bool = False,
|
||||
) -> dict[uuid.UUID, Comment]:
|
||||
if not ids:
|
||||
return {}
|
||||
stmt = select(Comment).where(Comment.id.in_(ids))
|
||||
if not include_deleted:
|
||||
stmt = stmt.where(Comment.is_deleted.is_(False))
|
||||
result = await db.execute(stmt)
|
||||
comments = result.scalars().all()
|
||||
return {c.id: c for c in comments}
|
||||
|
||||
|
||||
async def soft_delete_comment(db: AsyncSession, comment: Comment) -> Comment:
|
||||
comment.is_deleted = True
|
||||
db.add(comment)
|
||||
await db.commit()
|
||||
await db.refresh(comment)
|
||||
return comment
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
from typing import Sequence
|
||||
|
||||
from sqlalchemy import select, update as sa_update
|
||||
from sqlalchemy import delete, select, update as sa_update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.milestone import Milestone
|
||||
@@ -47,3 +47,8 @@ async def update(db: AsyncSession, milestone: Milestone, milestone_in: Milestone
|
||||
await db.commit()
|
||||
await db.refresh(milestone)
|
||||
return milestone
|
||||
|
||||
|
||||
async def delete_milestone(db: AsyncSession, milestone: Milestone) -> None:
|
||||
await db.execute(delete(Milestone).where(Milestone.id == milestone.id))
|
||||
await db.commit()
|
||||
|
||||
@@ -71,6 +71,15 @@ async def list_users(db: AsyncSession, skip: int = 0, limit: int = 100) -> Seque
|
||||
return result.scalars().all()
|
||||
|
||||
|
||||
async def count_active_admins(db: AsyncSession) -> int:
|
||||
result = await db.execute(
|
||||
select(func.count())
|
||||
.select_from(User)
|
||||
.where(User.role == UserRole.ADMIN, User.status == UserStatus.ACTIVE)
|
||||
)
|
||||
return int(result.scalar_one() or 0)
|
||||
|
||||
|
||||
async def list_users_by_status(
|
||||
db: AsyncSession, status: UserStatus | None = None, skip: int = 0, limit: int = 100
|
||||
) -> Sequence[User]:
|
||||
|
||||
Reference in New Issue
Block a user