Skip to content

Commit

Permalink
Add additional field from patient to the table
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszbachorski committed Jul 16, 2024
1 parent 05a8d8f commit 134e034
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/(dashboard)/patients/PatientsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const columns = [
cell: (props) => props.getValue() ?? '-',
}),
columnHelper.accessor('email', { header: 'Email' }),
columnHelper.accessor('gender', { header: 'Gender' }),
columnHelper.display({
id: 'actions',
cell: () => (
Expand Down
22 changes: 17 additions & 5 deletions app/(dashboard)/patients/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,29 @@ export const listPatients = async () => {
const patientsQuery = await getPatientsQuery()
const patients = await getDocs(patientsQuery)
const userIdsToGet = patients.docs.map((patient) => ({ uid: patient.id }))
const patientsById = new Map(

Check warning on line 42 in app/(dashboard)/patients/page.tsx

View check run for this annotation

Codecov / codecov/patch

app/(dashboard)/patients/page.tsx#L38-L42

Added lines #L38 - L42 were not covered by tests
patients.docs.map(
(patient) => [patient.id, { id: patient.id, ...patient.data() }] as const,

Check warning on line 44 in app/(dashboard)/patients/page.tsx

View check run for this annotation

Codecov / codecov/patch

app/(dashboard)/patients/page.tsx#L44

Added line #L44 was not covered by tests
),
)

const adminApp = getAdminApp()
const adminAuth = getAuth(adminApp)

Check warning on line 49 in app/(dashboard)/patients/page.tsx

View check run for this annotation

Codecov / codecov/patch

app/(dashboard)/patients/page.tsx#L48-L49

Added lines #L48 - L49 were not covered by tests

// TODO: It can take max 100 users. Batch/paginate? Use getting by id? Fetch all and match?
const users = await adminAuth.getUsers(userIdsToGet)
const usersData = users.users.map((user) => ({
uid: user.uid,
email: user.email,
displayName: user.displayName,
}))
const usersData = users.users
.map((user) => {
const patient = patientsById.get(user.uid)

Check warning on line 55 in app/(dashboard)/patients/page.tsx

View check run for this annotation

Codecov / codecov/patch

app/(dashboard)/patients/page.tsx#L52-L55

Added lines #L52 - L55 were not covered by tests
if (!patient) return null
return {

Check warning on line 57 in app/(dashboard)/patients/page.tsx

View check run for this annotation

Codecov / codecov/patch

app/(dashboard)/patients/page.tsx#L57

Added line #L57 was not covered by tests
uid: user.uid,
email: user.email,
displayName: user.displayName,
gender: patient.GenderIdentityKey,
}
})
.filter(Boolean)

return usersData

Check warning on line 66 in app/(dashboard)/patients/page.tsx

View check run for this annotation

Codecov / codecov/patch

app/(dashboard)/patients/page.tsx#L66

Added line #L66 was not covered by tests
}
Expand Down
9 changes: 8 additions & 1 deletion modules/firebase/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ export interface Organization {

export interface Admin {}

export interface User {}
export interface User {
GenderIdentityKey: string
invitationCode: string
clinician?: string
organization?: string
language?: string
timeZone?: string
}

export interface Clinician {
organization?: string
Expand Down

0 comments on commit 134e034

Please sign in to comment.