-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Care Plan #10231
base: develop
Are you sure you want to change the base?
Care Plan #10231
Changes from 1 commit
0fd3547
b329d81
d68680e
6126694
882ea6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,104 @@ | ||||||||||||||||||||||||||
import { useQuery } from "@tanstack/react-query"; | ||||||||||||||||||||||||||
import dayjs from "dayjs"; | ||||||||||||||||||||||||||
import { useTranslation } from "react-i18next"; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import { Button } from "@/components/ui/button"; | ||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||
Table, | ||||||||||||||||||||||||||
TableCell, | ||||||||||||||||||||||||||
TableHead, | ||||||||||||||||||||||||||
TableHeader, | ||||||||||||||||||||||||||
TableRow, | ||||||||||||||||||||||||||
} from "@/components/ui/table"; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import PageTitle from "@/components/Common/PageTitle"; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import { DummyCarePlanRetrieve } from "@/types/emr/careplan/careplanApi"; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export default function CarePlan(props: { | ||||||||||||||||||||||||||
facilityId: string; | ||||||||||||||||||||||||||
encounterId: string; | ||||||||||||||||||||||||||
careplanId: string; | ||||||||||||||||||||||||||
}) { | ||||||||||||||||||||||||||
const { t } = useTranslation(); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const planQuery = useQuery({ | ||||||||||||||||||||||||||
queryKey: ["care-plan", props.careplanId], | ||||||||||||||||||||||||||
queryFn: () => DummyCarePlanRetrieve(props.careplanId), | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const careplan = planQuery.data; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||
<div className="flex flex-col-reverse md:flex-row gap-4 md:justify-between"> | ||||||||||||||||||||||||||
<div> | ||||||||||||||||||||||||||
<PageTitle | ||||||||||||||||||||||||||
title={planQuery.data?.title || t("care_plan")} | ||||||||||||||||||||||||||
breadcrumbs={true} | ||||||||||||||||||||||||||
backUrl={`/facility/${props.facilityId}/encounter/${props.encounterId}/care-plan`} | ||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||
<div className="text-lg text-gray-500"> | ||||||||||||||||||||||||||
{dayjs(careplan?.end_date).isBefore(dayjs()) ? ( | ||||||||||||||||||||||||||
"Completed" | ||||||||||||||||||||||||||
) : dayjs(careplan?.start_date).isAfter(dayjs()) ? ( | ||||||||||||||||||||||||||
<span className="text-blue-500">Upcoming</span> | ||||||||||||||||||||||||||
) : ( | ||||||||||||||||||||||||||
<div className="text-red-500 flex items-center gap-1"> | ||||||||||||||||||||||||||
<div className="bg-red-500 w-2 aspect-square rounded-full inline-block" /> | ||||||||||||||||||||||||||
Active | ||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||
<div className="text-sm text-gray-500 mt-4"> | ||||||||||||||||||||||||||
{dayjs(careplan?.start_date).isAfter(dayjs()) | ||||||||||||||||||||||||||
? "Starts on" | ||||||||||||||||||||||||||
: "Started On"}{" "} | ||||||||||||||||||||||||||
: {dayjs(careplan?.start_date).format("DD/MM/YYYY hh:mm a")} | ||||||||||||||||||||||||||
<br /> | ||||||||||||||||||||||||||
{dayjs(careplan?.end_date).isAfter(dayjs()) | ||||||||||||||||||||||||||
? "Ends on" | ||||||||||||||||||||||||||
: "Ended On"}{" "} | ||||||||||||||||||||||||||
: {dayjs(careplan?.end_date).format("DD/MM/YYYY hh:mm a")} | ||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||
<div className="mt-4">{careplan?.description}</div> | ||||||||||||||||||||||||||
<div className="mt-8"> | ||||||||||||||||||||||||||
<b className="text-lg">Addresses</b> | ||||||||||||||||||||||||||
<Table> | ||||||||||||||||||||||||||
<TableHeader> | ||||||||||||||||||||||||||
<TableRow> | ||||||||||||||||||||||||||
<TableHead>Code</TableHead> | ||||||||||||||||||||||||||
<TableHead>Detail</TableHead> | ||||||||||||||||||||||||||
</TableRow> | ||||||||||||||||||||||||||
</TableHeader> | ||||||||||||||||||||||||||
{careplan?.addresses.map((code, i) => ( | ||||||||||||||||||||||||||
<TableRow key={i}> | ||||||||||||||||||||||||||
<TableCell>{code.code}</TableCell> | ||||||||||||||||||||||||||
<TableCell>{code.display}</TableCell> | ||||||||||||||||||||||||||
</TableRow> | ||||||||||||||||||||||||||
))} | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add key based on unique identifier instead of index. Using array index as key can lead to rendering issues. Use a unique identifier from the address object. - {careplan?.addresses.map((code, i) => (
- <TableRow key={i}>
+ {careplan?.addresses.map((code) => (
+ <TableRow key={`${code.code}-${code.system}`}> 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
</Table> | ||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||
<div className="mt-8"> | ||||||||||||||||||||||||||
<b className="text-lg">Goals</b> | ||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||
<div className="md:w-[200px] w-full flex flex-col gap-2"> | ||||||||||||||||||||||||||
<Button className="w-full" variant={"primary"}> | ||||||||||||||||||||||||||
Update | ||||||||||||||||||||||||||
</Button> | ||||||||||||||||||||||||||
<Button className="w-full" variant={"primary"}> | ||||||||||||||||||||||||||
Prescribe Medication | ||||||||||||||||||||||||||
</Button> | ||||||||||||||||||||||||||
<Button className="w-full" variant={"primary"}> | ||||||||||||||||||||||||||
Order Lab Test | ||||||||||||||||||||||||||
</Button> | ||||||||||||||||||||||||||
<Button className="w-full" variant={"primary"}> | ||||||||||||||||||||||||||
Record Task | ||||||||||||||||||||||||||
</Button> | ||||||||||||||||||||||||||
<Button className="w-full" variant={"primary"}> | ||||||||||||||||||||||||||
Print Plan | ||||||||||||||||||||||||||
</Button> | ||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||
Comment on lines
+141
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement action handlers for buttons. The action buttons are currently non-functional. Implement handlers for each action. <div className="md:w-[200px] w-full flex flex-col gap-2">
- <Button className="w-full" variant={"primary"}>
+ <Button
+ className="w-full"
+ variant={"primary"}
+ onClick={() => handleUpdate()}
+ >
Update
</Button>
- <Button className="w-full" variant={"primary"}>
+ <Button
+ className="w-full"
+ variant={"primary"}
+ onClick={() => handlePrescribeMedication()}
+ >
Prescribe Medication
</Button>
// Similar changes for other buttons
|
||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||||||||||||||||||||||||||||||||
import { useQuery } from "@tanstack/react-query"; | ||||||||||||||||||||||||||||||||||
import dayjs from "dayjs"; | ||||||||||||||||||||||||||||||||||
import { Link } from "raviger"; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
import SubHeading from "@/CAREUI/display/SubHeading"; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
import { EncounterTabProps } from "@/pages/Encounters/EncounterShow"; | ||||||||||||||||||||||||||||||||||
import { DummyCarePlanGet } from "@/types/emr/careplan/careplanApi"; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
export const EncounterCarePlanTab = (props: EncounterTabProps) => { | ||||||||||||||||||||||||||||||||||
const { patient, encounter, facilityId } = props; | ||||||||||||||||||||||||||||||||||
const { data: carePlans } = useQuery({ | ||||||||||||||||||||||||||||||||||
queryKey: ["patient", patient.id, "care-plans"], | ||||||||||||||||||||||||||||||||||
queryFn: DummyCarePlanGet, | ||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling and loading states for data fetching. The query implementation is missing error handling and loading states. - const { data: carePlans } = useQuery({
+ const { data: carePlans, isLoading, error } = useQuery({
queryKey: ["patient", patient.id, "care-plans"],
queryFn: DummyCarePlanGet,
});
+
+ if (isLoading) {
+ return <div className="animate-pulse">Loading care plans...</div>;
+ }
+
+ if (error) {
+ return <div className="text-red-500">Error loading care plans: {error.message}</div>;
+ } 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||
<div className="flex flex-col"> | ||||||||||||||||||||||||||||||||||
<SubHeading title="Care Plan" /> | ||||||||||||||||||||||||||||||||||
<div className="grid grid-cols-3 gap-4"> | ||||||||||||||||||||||||||||||||||
{carePlans?.results.map((careplan, i) => ( | ||||||||||||||||||||||||||||||||||
<Link | ||||||||||||||||||||||||||||||||||
href={`/facility/${facilityId}/encounter/${encounter.id}/care-plan/${careplan.id}`} | ||||||||||||||||||||||||||||||||||
key={i} | ||||||||||||||||||||||||||||||||||
className="bg-white border rounded-lg p-4 hover:text-inherit hover:border-primary-500" | ||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||
<span className="font-bold">{careplan.title}</span> | ||||||||||||||||||||||||||||||||||
<div className="text-sm text-gray-500"> | ||||||||||||||||||||||||||||||||||
{dayjs(careplan.end_date).isBefore(dayjs()) ? ( | ||||||||||||||||||||||||||||||||||
"Completed" | ||||||||||||||||||||||||||||||||||
) : dayjs(careplan.start_date).isAfter(dayjs()) ? ( | ||||||||||||||||||||||||||||||||||
<span className="text-blue-500">Upcoming</span> | ||||||||||||||||||||||||||||||||||
) : ( | ||||||||||||||||||||||||||||||||||
<div className="text-red-500 flex items-center gap-1"> | ||||||||||||||||||||||||||||||||||
<div className="bg-red-500 w-2 aspect-square rounded-full inline-block" /> | ||||||||||||||||||||||||||||||||||
Active | ||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||
<div className="mt-4 text-sm">{careplan.description}</div> | ||||||||||||||||||||||||||||||||||
<div className="text-xs text-gray-500 mt-4"> | ||||||||||||||||||||||||||||||||||
{dayjs(careplan.start_date).isAfter(dayjs()) | ||||||||||||||||||||||||||||||||||
? "Starts on" | ||||||||||||||||||||||||||||||||||
: "Started On"}{" "} | ||||||||||||||||||||||||||||||||||
: {dayjs(careplan.start_date).format("DD/MM/YYYY hh:mm a")} | ||||||||||||||||||||||||||||||||||
<br /> | ||||||||||||||||||||||||||||||||||
{dayjs(careplan.end_date).isAfter(dayjs()) | ||||||||||||||||||||||||||||||||||
? "Ends on" | ||||||||||||||||||||||||||||||||||
: "Ended On"}{" "} | ||||||||||||||||||||||||||||||||||
: {dayjs(careplan.end_date).format("DD/MM/YYYY hh:mm a")} | ||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||
<div className="mt-4"> | ||||||||||||||||||||||||||||||||||
<span className="text-sm font-semibold">3/4 Goals Complete</span> | ||||||||||||||||||||||||||||||||||
<div className="bg-gray-200 rounded-full h-1 overflow-hidden mt-2"> | ||||||||||||||||||||||||||||||||||
<div className="bg-primary-500 rounded-full w-3/4 h-full" /> | ||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||
Comment on lines
+52
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace hardcoded progress values with actual data. The progress bar shows hardcoded values ("3/4 Goals Complete") which should come from the care plan data. - <span className="text-sm font-semibold">3/4 Goals Complete</span>
- <div className="bg-gray-200 rounded-full h-1 overflow-hidden mt-2">
- <div className="bg-primary-500 rounded-full w-3/4 h-full" />
+ <span className="text-sm font-semibold">
+ {careplan.completed_goals}/{careplan.total_goals} Goals Complete
+ </span>
+ <div className="bg-gray-200 rounded-full h-1 overflow-hidden mt-2">
+ <div
+ className="bg-primary-500 rounded-full h-full"
+ style={{
+ width: `${(careplan.completed_goals / careplan.total_goals) * 100}%`
+ }}
+ />
|
||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||
</Link> | ||||||||||||||||||||||||||||||||||
))} | ||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { BaseModel } from "@/Utils/types"; | ||
|
||
export const CARE_PLAN_STATUS = [ | ||
"draft", | ||
"active", | ||
"completed", | ||
"on-hold", | ||
"cancelled", | ||
] as const; | ||
|
||
export const CARE_PLAN_INTENT = [ | ||
"proposal", | ||
"plan", | ||
"order", | ||
"option", | ||
"directive", | ||
] as const; | ||
|
||
interface Code { | ||
code: string; | ||
display: string; | ||
system: string; | ||
} | ||
|
||
export interface CarePlan extends BaseModel { | ||
status: (typeof CARE_PLAN_STATUS)[number]; | ||
intent: (typeof CARE_PLAN_INTENT)[number]; | ||
title: string; | ||
description: string; | ||
start_date: string; | ||
end_date: string; | ||
patient: string; | ||
encounter: string; | ||
custodian: string; | ||
addresses: Code[]; | ||
notes?: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling to the query.
The query should handle error states to provide feedback to users when data fetching fails.