Skip to content

Commit

Permalink
Add user info
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszbachorski committed Oct 7, 2024
1 parent 55b5a66 commit d070087
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 20 deletions.
32 changes: 25 additions & 7 deletions routes/~_dashboard/~patients/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
UserType,
} from '@stanfordbdhg/engagehf-models'
import { groupBy } from 'es-toolkit'
import { query, where } from 'firebase/firestore'
import { limit, orderBy, query, where } from 'firebase/firestore'

Check warning on line 14 in routes/~_dashboard/~patients/utils.ts

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/utils.ts#L14

Added line #L14 was not covered by tests
import { AllergyType } from '@/modules/firebase/allergy'
import { getCurrentUser, refs } from '@/modules/firebase/app'
import {
Expand All @@ -20,13 +20,13 @@ import {
} from '@/modules/firebase/appointment'
import { type FHIRAllergyIntolerance } from '@/modules/firebase/models'
import { mapAuthData } from '@/modules/firebase/user'
import {
getDocsData,
ObservationType,
type ResourceType,
} from '@/modules/firebase/utils'
import { getDocsData, type ResourceType } from '@/modules/firebase/utils'

Check warning on line 23 in routes/~_dashboard/~patients/utils.ts

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/utils.ts#L23

Added line #L23 was not covered by tests
import { queryClient } from '@/modules/query/queryClient'
import { userOrganizationQueryOptions } from '@/modules/user/queries'
import {
type getUserData,
userOrganizationQueryOptions,
} from '@/modules/user/queries'
import { labsObservationCollections } from '@/routes/~_dashboard/~patients/clientUtils'

Check warning on line 29 in routes/~_dashboard/~patients/utils.ts

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/utils.ts#L28-L29

Added lines #L28 - L29 were not covered by tests

const getUserClinicians = async () => {
const { user } = await getCurrentUser()
Expand Down Expand Up @@ -216,6 +216,24 @@ export const getAppointmentsData = async ({
}
}

export const getUserActivity = async ({
user,
resourceType,
authUser,
}: Awaited<ReturnType<typeof getUserData>>) => {
const latestQuestionnaires = await getDocsData(
query(
refs.questionnaireResponses({ resourceType, userId: authUser.uid }),
orderBy('authored'),
limit(1),
),
)
return {
lastActiveDate: user.lastActiveDate,
latestQuestionnaireDate: latestQuestionnaires.at(0)?.authored,
}
}

Check warning on line 235 in routes/~_dashboard/~patients/utils.ts

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/utils.ts#L219-L235

Added lines #L219 - L235 were not covered by tests

export type AllergiesData = Awaited<ReturnType<typeof getAllergiesData>>
export type Allergy = AllergiesData['allergyIntolerances'][number]
export type AppointmentsData = Awaited<ReturnType<typeof getAppointmentsData>>
Expand Down
17 changes: 10 additions & 7 deletions routes/~_dashboard/~patients/~$id/LabForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
import { type ComponentProps } from 'react'
import { z } from 'zod'
import { ObservationType } from '@/modules/firebase/utils'
import { UserObservationCollection } from '@/modules/firebase/utils'

Check warning on line 10 in routes/~_dashboard/~patients/~$id/LabForm.tsx

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/~$id/LabForm.tsx#L10

Added line #L10 was not covered by tests
import { Button } from '@/packages/design-system/src/components/Button'
import { DatePicker } from '@/packages/design-system/src/components/DatePicker'
import {
Expand All @@ -29,11 +29,12 @@ import { useForm } from '@/packages/design-system/src/forms/useForm'
import {
getObservationTypeUnits,
getUnitOfObservationType,
labsObservationCollections,
} from '@/routes/~_dashboard/~patients/clientUtils'
import { type Observation } from '@/routes/~_dashboard/~patients/utils'

export const labFormSchema = z.object({
type: z.nativeEnum(ObservationType),
type: z.nativeEnum(UserObservationCollection),

Check warning on line 37 in routes/~_dashboard/~patients/~$id/LabForm.tsx

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/~$id/LabForm.tsx#L37

Added line #L37 was not covered by tests
effectiveDateTime: z.date(),
unit: z.string(),
value: z.number(),
Expand All @@ -48,7 +49,7 @@ interface LabFormProps {

export const LabForm = ({ observation, onSubmit }: LabFormProps) => {
const isEdit = !!observation
const defaultType = observation?.type ?? ObservationType.potassium
const defaultType = observation?.type ?? UserObservationCollection.potassium

Check warning on line 52 in routes/~_dashboard/~patients/~$id/LabForm.tsx

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/~$id/LabForm.tsx#L52

Added line #L52 was not covered by tests
const form = useForm({
formSchema: labFormSchema,
defaultValues: {
Expand Down Expand Up @@ -81,8 +82,10 @@ export const LabForm = ({ observation, onSubmit }: LabFormProps) => {
field.onChange(type)
form.setValue(
'unit',
getUnitOfObservationType(type as ObservationType, formUnit)
.unit,
getUnitOfObservationType(
type as UserObservationCollection,
formUnit,
).unit,

Check warning on line 88 in routes/~_dashboard/~patients/~$id/LabForm.tsx

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/~$id/LabForm.tsx#L85-L88

Added lines #L85 - L88 were not covered by tests
)
}}
{...field}
Expand All @@ -91,7 +94,7 @@ export const LabForm = ({ observation, onSubmit }: LabFormProps) => {
<SelectValue placeholder="Type" />
</SelectTrigger>
<SelectContent>
{Object.values(ObservationType).map((type) => (
{labsObservationCollections.map((type) => (

Check warning on line 97 in routes/~_dashboard/~patients/~$id/LabForm.tsx

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/~$id/LabForm.tsx#L97

Added line #L97 was not covered by tests
<SelectItem key={type} value={type}>
{type}
</SelectItem>
Expand All @@ -110,7 +113,7 @@ export const LabForm = ({ observation, onSubmit }: LabFormProps) => {
<SelectValue placeholder="Unit" />
</SelectTrigger>
<SelectContent>
{units.map((unit) => (
{units?.map((unit) => (

Check warning on line 116 in routes/~_dashboard/~patients/~$id/LabForm.tsx

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/~$id/LabForm.tsx#L116

Added line #L116 was not covered by tests
<SelectItem key={unit.unit} value={unit.unit}>
{unit.unit}
</SelectItem>
Expand Down
44 changes: 38 additions & 6 deletions routes/~_dashboard/~patients/~$id/~index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import {
type ResourceType,
} from '@/modules/firebase/utils'
import { getUserData } from '@/modules/user/queries'
import {
Card,
CardHeader,
CardTitle,
} from '@/packages/design-system/src/components/Card'

Check warning on line 29 in routes/~_dashboard/~patients/~$id/~index.tsx

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/~$id/~index.tsx#L29

Added line #L29 was not covered by tests
import {
Tabs,
TabsContent,
Expand All @@ -30,6 +35,7 @@ import {
} from '@/packages/design-system/src/components/Tabs'
import { getUserName } from '@/packages/design-system/src/modules/auth/user'
import { PageTitle } from '@/packages/design-system/src/molecules/DashboardLayout'
import { formatISODateTime } from '@/packages/design-system/src/utils/date'

Check warning on line 38 in routes/~_dashboard/~patients/~$id/~index.tsx

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/~$id/~index.tsx#L38

Added line #L38 was not covered by tests
import {
Medications,
type MedicationsFormSchema,
Expand All @@ -44,6 +50,7 @@ import {
getFormProps,
getLabsData,
getMedicationsData,
getUserActivity,
} from '@/routes/~_dashboard/~patients/utils'
import { Allergies } from '@/routes/~_dashboard/~patients/~$id/Allergies'
import { Appointments } from '@/routes/~_dashboard/~patients/~$id/Appointments'
Expand Down Expand Up @@ -94,6 +101,7 @@ const PatientPage = () => {
user,
authUser,
resourceType,
activity,

Check warning on line 104 in routes/~_dashboard/~patients/~$id/~index.tsx

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/~$id/~index.tsx#L104

Added line #L104 was not covered by tests
} = Route.useLoaderData()

const updatePatient = async (form: PatientFormSchema) => {
Expand Down Expand Up @@ -205,12 +213,35 @@ const PatientPage = () => {
</TabsTrigger>
</TabsList>
<TabsContent value={PatientPageTab.information}>
<PatientForm
user={user}
userInfo={authUser}
onSubmit={updatePatient}
{...formProps}
/>
<div className="flex flex-col gap-6 xl:flex-row">
<Card className="xl:min-w-max xl:self-start">
<CardHeader>
<CardTitle>User activity</CardTitle>
</CardHeader>
<div className="px-5 pb-4 marker:text-primary">
<ul className="list-disc pl-4">
<li>
latest activity:{' '}
{activity.lastActiveDate ?
formatISODateTime(activity.lastActiveDate)
: '-'}
</li>
<li>
latest questionnaire answer:{' '}
{activity.latestQuestionnaireDate ?
formatISODateTime(activity.latestQuestionnaireDate)
: '-'}
</li>
</ul>
</div>
</Card>
<PatientForm
user={user}
userInfo={authUser}
onSubmit={updatePatient}
{...formProps}
/>
</div>

Check warning on line 244 in routes/~_dashboard/~patients/~$id/~index.tsx

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/~$id/~index.tsx#L216-L244

Added lines #L216 - L244 were not covered by tests
</TabsContent>
<TabsContent value={PatientPageTab.notifications}>
<Notifications userId={userId} />
Expand Down Expand Up @@ -259,6 +290,7 @@ export const Route = createFileRoute('/_dashboard/patients/$id/')({
allergiesData: await getAllergiesData({ userId, resourceType }),
labsData: await getLabsData({ userId, resourceType }),
appointmentsData: await getAppointmentsData({ userId, resourceType }),
activity: await getUserActivity(userData),

Check warning on line 293 in routes/~_dashboard/~patients/~$id/~index.tsx

View check run for this annotation

Codecov / codecov/patch

routes/~_dashboard/~patients/~$id/~index.tsx#L293

Added line #L293 was not covered by tests
}
},
})

0 comments on commit d070087

Please sign in to comment.