Skip to content
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

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"DOMESTIC_HEALTHCARE_SUPPORT__NO_SUPPORT": "No support",
"DOMESTIC_HEALTHCARE_SUPPORT__PAID_CAREGIVER": "Paid caregiver",
"ENCOUNTER_TAB__abdm": "ABDM Records",
"ENCOUNTER_TAB__care-plan": "Care Plan",
"ENCOUNTER_TAB__feed": "Feed",
"ENCOUNTER_TAB__files": "Files",
"ENCOUNTER_TAB__medicines": "Medicines",
Expand Down Expand Up @@ -491,6 +492,7 @@
"care": "CARE",
"care_backend": "Care Backend",
"care_frontend": "Care Frontend",
"care_plan": "Care Plan",
"category": "Category",
"category_description": "Choose the category that best describes the resource needed.",
"caution": "Caution",
Expand Down
12 changes: 12 additions & 0 deletions src/Routers/routes/ConsultationRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import EncounterQuestionnaire from "@/components/Patient/EncounterQuestionnaire"
import FileUploadPage from "@/components/Patient/FileUploadPage";

import { AppRoutes } from "@/Routers/AppRouter";
import CarePlan from "@/pages/CarePlan/CarePlan";
import { EncounterShow } from "@/pages/Encounters/EncounterShow";
import { PrintPrescription } from "@/pages/Encounters/PrintPrescription";

Expand Down Expand Up @@ -75,6 +76,17 @@ const consultationRoutes: AppRoutes = {
type="encounter"
/>
),
"/facility/:facilityId/encounter/:encounterId/care-plan/:careplanId": ({
facilityId,
encounterId,
careplanId,
}) => (
<CarePlan
facilityId={facilityId}
encounterId={encounterId}
careplanId={careplanId}
/>
),
};

export default consultationRoutes;
104 changes: 104 additions & 0 deletions src/pages/CarePlan/CarePlan.tsx
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),
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling to the query.

The query should handle error states to provide feedback to users when data fetching fails.

 const planQuery = useQuery({
   queryKey: ["care-plan", props.careplanId],
   queryFn: () => DummyCarePlanRetrieve(props.careplanId),
+  onError: (error) => {
+    // Handle error state
+  }
 });

+if (planQuery.isError) {
+  return <div>Error loading care plan data</div>;
+}

+if (planQuery.isLoading) {
+  return <div>Loading...</div>;
+}

Committable suggestion skipped: line range outside the PR's diff.


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>
))}
Copy link
Contributor

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{careplan?.addresses.map((code, i) => (
<TableRow key={i}>
<TableCell>{code.code}</TableCell>
<TableCell>{code.display}</TableCell>
</TableRow>
))}
{careplan?.addresses.map((code) => (
<TableRow key={`${code.code}-${code.system}`}>
<TableCell>{code.code}</TableCell>
<TableCell>{code.display}</TableCell>
</TableRow>
))}

</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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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

Committable suggestion skipped: line range outside the PR's diff.

</div>
);
}
2 changes: 2 additions & 0 deletions src/pages/Encounters/EncounterShow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { EncounterUpdatesTab } from "@/pages/Encounters/tabs/EncounterUpdatesTab
import { Encounter } from "@/types/emr/encounter";
import { Patient } from "@/types/emr/newPatient";

import { EncounterCarePlanTab } from "./tabs/EncounterCarePlanTab";
import { EncounterNotesTab } from "./tabs/EncounterNotesTab";

export interface EncounterTabProps {
Expand All @@ -35,6 +36,7 @@ const defaultTabs = {
medicines: EncounterMedicinesTab,
files: EncounterFilesTab,
notes: EncounterNotesTab,
"care-plan": EncounterCarePlanTab,
// nursing: EncounterNursingTab,
// neurological_monitoring: EncounterNeurologicalMonitoringTab,
// pressure_sore: EncounterPressureSoreTab,
Expand Down
62 changes: 62 additions & 0 deletions src/pages/Encounters/tabs/EncounterCarePlanTab.tsx
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,
});
Copy link
Contributor

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { data: carePlans } = useQuery({
queryKey: ["patient", patient.id, "care-plans"],
queryFn: DummyCarePlanGet,
});
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>;
}

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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}%`
+                  }}
+                />

Committable suggestion skipped: line range outside the PR's diff.

</div>
</Link>
))}
</div>
</div>
);
};
37 changes: 37 additions & 0 deletions src/types/emr/careplan/careplan.ts
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;
}
Loading
Loading