Skip to content

Commit

Permalink
Add dosage instructions (#36)
Browse files Browse the repository at this point in the history
# Add dosage instructions

## ♻️ Current situation & Problem
This PR adds dosage instructions to medications

### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
arkadiuszbachorski authored Aug 24, 2024
1 parent 7fc0617 commit 4d84be8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 22 deletions.
50 changes: 48 additions & 2 deletions app/(dashboard)/patients/Medications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@
// SPDX-License-Identifier: MIT
//
'use client'
import { Plus, Check, Trash } from 'lucide-react'
import { Plus, Check, Trash, Pencil } from 'lucide-react'
import { z } from 'zod'
import { useMedicationsMap } from '@/app/(dashboard)/patients/clientUtils'
import { MedicationSelect } from '@/app/(dashboard)/patients/MedicationSelect'
import { type MedicationsData } from '@/app/(dashboard)/patients/utils'
import { Button } from '@/packages/design-system/src/components/Button'
import { Card } from '@/packages/design-system/src/components/Card'
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
DialogClose,
} from '@/packages/design-system/src/components/Dialog'
import { EmptyState } from '@/packages/design-system/src/components/EmptyState'
import {
Select,
Expand All @@ -28,6 +37,7 @@ import {
TableRow,
TableBody,
} from '@/packages/design-system/src/components/Table'
import { Textarea } from '@/packages/design-system/src/components/Textarea'
import { Tooltip } from '@/packages/design-system/src/components/Tooltip'
import { Field } from '@/packages/design-system/src/forms/Field'
import { useForm } from '@/packages/design-system/src/forms/useForm'
Expand All @@ -49,6 +59,7 @@ const formSchema = z.object({
medications: z.array(
z.object({
id: z.string(),
instructions: z.string(),
medication: z.string({ required_error: 'Medication is required' }),
drug: z.string({ required_error: 'Drug is required' }),
quantity: z.number().min(0),
Expand Down Expand Up @@ -86,6 +97,7 @@ export const Medications = ({
// `undefined` doesn't get submitted anywhere
medication: undefined as unknown as string,
drug: undefined as unknown as string,
instructions: '',
quantity: 1,
frequencyPerDay: 1,
},
Expand Down Expand Up @@ -117,7 +129,8 @@ export const Medications = ({
<TableCell className="w-[130px]">Quantity</TableCell>
<TableCell className="w-[190px]">Frequency</TableCell>
<TableCell className="w-[190px]">Daily dosage</TableCell>
<TableCell className="w-[75px]" />
<TableCell className="w-[120px]">Instructions</TableCell>
<TableCell className="w-[75px]"></TableCell>
</TableRow>
</TableHeader>
<TableBody>
Expand Down Expand Up @@ -305,6 +318,39 @@ export const Medications = ({
</div>
}
</TableCell>
<TableCell>
<Dialog>
<DialogTrigger asChild>
<Button
variant="ghost"
size="sm"
className="relative -left-3"
>
{medicationValue.instructions && (
<span className="max-w-[70px] truncate">
{medicationValue.instructions}
</span>
)}
<Pencil className="size-4 opacity-80" />
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Modify instructions</DialogTitle>
</DialogHeader>
<Field
control={form.control}
name={nestedKey('instructions')}
render={({ field }) => <Textarea {...field} />}
/>
<DialogFooter>
<DialogClose>
<Button>Close</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
</TableCell>
<TableCell>
<Tooltip tooltip="Delete">
<Button
Expand Down
24 changes: 12 additions & 12 deletions app/(dashboard)/patients/[id]/AllergyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ export const AllergyForm = ({

return (
<form onSubmit={handleSubmit}>
<Field
control={form.control}
name="medication"
label="Medication"
render={({ field }) => (
<MedicationSelect
medications={medications}
onValueChange={field.onChange}
{...field}
/>
)}
/>
<Field
control={form.control}
name="type"
Expand All @@ -97,6 +85,18 @@ export const AllergyForm = ({
</Select>
)}
/>
<Field
control={form.control}
name="medication"
label="Medication"
render={({ field }) => (
<MedicationSelect
medications={medications}
onValueChange={field.onChange}
{...field}
/>
)}
/>
<Button type="submit" isPending={form.formState.isSubmitting}>
{isEdit ? 'Edit' : 'Create'} allergy
</Button>
Expand Down
11 changes: 5 additions & 6 deletions app/(dashboard)/patients/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ const getUserMedications = async (payload: {
const medicationRequests = await getDocsData(refs.medicationRequests(payload))
return medicationRequests.map((request) => {
const ids = getMedicationRequestMedicationIds(request)
const dosage = request.dosageInstruction?.at(0)
return {
id: request.id,
medication: ids.medicationId ?? '',
drug: ids.drugId ?? '',
frequencyPerDay:
request.dosageInstruction?.at(0)?.timing?.repeat?.frequency ?? 1,
quantity:
request.dosageInstruction?.at(0)?.doseAndRate?.at(0)?.doseQuantity
?.value ?? 1,
frequencyPerDay: dosage?.timing?.repeat?.frequency ?? 1,
quantity: dosage?.doseAndRate?.at(0)?.doseQuantity?.value ?? 1,
instructions: dosage?.text ?? '',
}
})
}
Expand Down Expand Up @@ -178,7 +177,7 @@ const PatientPage = async ({ params }: PatientPageProps) => {
/>
}
>
<Tabs defaultValue={Tab.information}>
<Tabs defaultValue={Tab.medications}>
<TabsList className="mb-6 w-full">
<TabsTrigger value={Tab.information} className="grow">
Information
Expand Down
2 changes: 2 additions & 0 deletions modules/firebase/models/medication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ export const getMedicationRequestData = (medication: {
drug: string
frequencyPerDay: number
quantity: number
instructions: string
}): FHIRMedicationRequest => ({
medicationReference: {
reference: `medications/${medication.medication}/drugs/${medication.drug}`,
},
dosageInstruction: [
{
text: medication.instructions,
timing: {
repeat: {
frequency: medication.frequencyPerDay,
Expand Down
4 changes: 2 additions & 2 deletions modules/firebase/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ export const getDocData = async <T>(reference: DocumentReference<T>) => {
const data = doc.data()
return data ?
{
id: doc.id,
...data,
id: doc.id,
}
: undefined
}
Expand All @@ -365,8 +365,8 @@ export const getDocsData = async <T>(query: Query<T>) => {
const data = doc.data()
if (!data) throw new Error(`No data for ${doc.id} ${doc.ref.path}`)
return {
id: doc.id,
...data,
id: doc.id,
}
})
}

0 comments on commit 4d84be8

Please sign in to comment.