Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions backend/api/resolvers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from api.types.patient import PatientType
from database import models
from graphql import GraphQLError
from sqlalchemy import select
from sqlalchemy import desc, func, select
from sqlalchemy.orm import aliased, selectinload


Expand Down Expand Up @@ -153,25 +153,43 @@ async def recent_patients(
info: Info,
limit: int = 5,
) -> list[PatientType]:
auth_service = AuthorizationService(info.context.db)
accessible_location_ids = await auth_service.get_user_accessible_location_ids(
info.context.user, info.context
)

if not accessible_location_ids:
return []

max_task_update_date = (
select(
func.max(models.Task.update_date).label("max_update_date"),
models.Task.patient_id.label("patient_id"),
)
.group_by(models.Task.patient_id)
.subquery()
)

query = (
select(models.Patient)
select(models.Patient, max_task_update_date.c.max_update_date)
.options(
selectinload(models.Patient.assigned_locations),
selectinload(models.Patient.tasks),
selectinload(models.Patient.teams),
)
.outerjoin(
max_task_update_date,
models.Patient.id == max_task_update_date.c.patient_id,
)
.where(models.Patient.deleted.is_(False))
.order_by(desc(max_task_update_date.c.max_update_date), desc(models.Patient.id))
.limit(limit)
)
auth_service = AuthorizationService(info.context.db)
accessible_location_ids = await auth_service.get_user_accessible_location_ids(
info.context.user, info.context
)
query = auth_service.filter_patients_by_access(
info.context.user, query, accessible_location_ids
)
result = await info.context.db.execute(query)
return result.scalars().all()
return [row[0] for row in result.all()]


@strawberry.type
Expand Down
51 changes: 38 additions & 13 deletions web/api/gql/generated.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions web/api/graphql/GetMyTasks.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ query GetMyTasks {
id
name
avatarUrl
lastOnline
isOnline
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions web/api/graphql/GetOverviewData.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ query GetOverviewData {
id
name
avatarUrl
lastOnline
isOnline
}
patient {
id
Expand Down
2 changes: 2 additions & 0 deletions web/api/graphql/GetPatient.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ query GetPatient($id: ID!) {
id
name
avatarUrl
lastOnline
isOnline
}
assigneeTeam {
id
Expand Down
2 changes: 2 additions & 0 deletions web/api/graphql/GetPatients.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ query GetPatients($locationId: ID, $rootLocationIds: [ID!], $states: [PatientSta
id
name
avatarUrl
lastOnline
isOnline
}
assigneeTeam {
id
Expand Down
2 changes: 2 additions & 0 deletions web/api/graphql/GetTask.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ query GetTask($id: ID!) {
id
name
avatarUrl
lastOnline
isOnline
}
assigneeTeam {
id
Expand Down
2 changes: 2 additions & 0 deletions web/api/graphql/GetTasks.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ query GetTasks($rootLocationIds: [ID!], $assigneeId: ID, $assigneeTeamId: ID, $l
id
name
avatarUrl
lastOnline
isOnline
}
assigneeTeam {
id
Expand Down
2 changes: 2 additions & 0 deletions web/api/graphql/GetUser.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ query GetUser($id: ID!) {
lastname
title
avatarUrl
lastOnline
isOnline
}
}

1 change: 1 addition & 0 deletions web/api/graphql/GetUsers.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ query GetUsers {
id
name
avatarUrl
lastOnline
isOnline
}
}
2 changes: 2 additions & 0 deletions web/api/graphql/GlobalData.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ query GetGlobalData($rootLocationIds: [ID!]) {
firstname
lastname
avatarUrl
lastOnline
isOnline
organizations
rootLocations {
id
Expand Down
8 changes: 8 additions & 0 deletions web/api/graphql/TaskMutations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ mutation CreateTask($data: CreateTaskInput!) {
id
name
avatarUrl
lastOnline
isOnline
}
patient {
id
Expand Down Expand Up @@ -37,6 +39,8 @@ mutation UpdateTask($id: ID!, $data: UpdateTaskInput!) {
id
name
avatarUrl
lastOnline
isOnline
}
properties {
definition {
Expand Down Expand Up @@ -66,6 +70,8 @@ mutation AssignTask($id: ID!, $userId: ID!) {
id
name
avatarUrl
lastOnline
isOnline
}
}
}
Expand All @@ -77,6 +83,8 @@ mutation UnassignTask($id: ID!) {
id
name
avatarUrl
lastOnline
isOnline
}
}
}
Expand Down
Loading
Loading