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

Patient Detail Tabs: Org List Access #10121

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,7 @@
"no_tests_taken": "No tests taken",
"no_treating_physicians_available": "This facility does not have any home facility doctors. Please contact your admin.",
"no_update_available": "No update available",
"no_updates_found": "No updates found",
"no_user_assigned": "No User Assigned to this patient",
"no_users_found": "No Users Found",
"no_vitals_present": "No Vitals Monitor present in this location or facility",
Expand Down
14 changes: 12 additions & 2 deletions src/Routers/routes/PatientRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import FileUploadPage from "@/components/Patient/FileUploadPage";
import { patientTabs } from "@/components/Patient/PatientDetailsTab";
import {
facilityPatientTabs,
patientTabs,
} from "@/components/Patient/PatientDetailsTab";
import { PatientHome } from "@/components/Patient/PatientHome";
import PatientIndex from "@/components/Patient/PatientIndex";
import PatientRegistration from "@/components/Patient/PatientRegistration";
Expand All @@ -19,13 +22,20 @@ const PatientRoutes: AppRoutes = {
<VerifyPatient facilityId={facilityId} />
),
"/patient/:id": ({ id }) => <PatientHome id={id} page="demography" />,
"/patient/:id/update": ({ id }) => <PatientRegistration patientId={id} />,
...patientTabs.reduce((acc: AppRoutes, tab) => {
acc["/patient/:id/" + tab.route] = ({ id }) => (
<PatientHome id={id} page={tab.route} />
);
return acc;
}, {}),
"/facility/:facilityId/patient/create": ({ facilityId }) => (
<PatientRegistration facilityId={facilityId} />
),
"/facility/:facilityId/patient/:id": ({ facilityId, id }) => (
<PatientHome facilityId={facilityId} id={id} page="demography" />
),
...patientTabs.reduce((acc: AppRoutes, tab) => {
...facilityPatientTabs.reduce((acc: AppRoutes, tab) => {
acc["/facility/:facilityId/patient/:id/" + tab.route] = ({
facilityId,
id,
Expand Down
10 changes: 7 additions & 3 deletions src/components/Patient/PatientDetailsTab/Demography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ export const Demography = (props: PatientProps) => {
};

const handleEditClick = (sectionId: string) => {
navigate(
`/facility/${facilityId}/patient/${id}/update?section=${sectionId}`,
);
if (facilityId) {
navigate(
`/facility/${facilityId}/patient/${id}/update?section=${sectionId}`,
);
} else {
navigate(`/patient/${id}/update?section=${sectionId}`);
}
};

const hasEditPermission = () => {
Expand Down
17 changes: 12 additions & 5 deletions src/components/Patient/PatientDetailsTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ export interface PatientProps {
patientData: Patient;
}

export const patientTabs = [
const commonTabs = [
{
route: "demography",
component: Demography,
},
{
route: "appointments",
component: Appointments,
},
{
route: "encounters",
component: EncounterHistory,
Expand All @@ -50,3 +46,14 @@ export const patientTabs = [
component: PatientFilesTab,
},
];

export const facilityPatientTabs = [
commonTabs[0],
{
route: "appointments",
component: Appointments,
},
...commonTabs.slice(1),
];
Comment on lines +50 to +57
Copy link
Member

Choose a reason for hiding this comment

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

works, but not a fan of this :)


export const patientTabs = [...commonTabs];
35 changes: 23 additions & 12 deletions src/components/Patient/PatientHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { Button } from "@/components/ui/button";
import { Avatar } from "@/components/Common/Avatar";
import Loading from "@/components/Common/Loading";
import Page from "@/components/Common/Page";
import { patientTabs } from "@/components/Patient/PatientDetailsTab";
import {
facilityPatientTabs,
patientTabs,
} from "@/components/Patient/PatientDetailsTab";

import { PLUGIN_Component } from "@/PluginEngine";
import routes from "@/Utils/request/api";
Expand All @@ -20,7 +23,7 @@ import { Patient } from "@/types/emr/newPatient";
export const PatientHome = (props: {
facilityId?: string;
id: string;
page: (typeof patientTabs)[0]["route"];
page: (typeof patientTabs | typeof facilityPatientTabs)[0]["route"];
}) => {
const { facilityId, id, page } = props;

Expand All @@ -40,7 +43,9 @@ export const PatientHome = (props: {
return <Loading />;
}

const Tab = patientTabs.find((t) => t.route === page)?.component;
const tabs = facilityId ? facilityPatientTabs : patientTabs;

const Tab = tabs.find((t) => t.route === page)?.component;

if (!patientData) {
return <div>{t("patient_not_found")}</div>;
Expand All @@ -51,13 +56,15 @@ export const PatientHome = (props: {
title={t("patient_details")}
options={
<>
<Button asChild variant="primary">
<Link
href={`/facility/${facilityId}/patient/${id}/book-appointment`}
>
{t("schedule_appointment")}
</Link>
</Button>
{facilityId && (
<Button asChild variant="primary">
<Link
href={`/facility/${facilityId}/patient/${id}/book-appointment`}
>
{t("schedule_appointment")}
</Link>
</Button>
)}
</>
}
>
Expand Down Expand Up @@ -99,10 +106,14 @@ export const PatientHome = (props: {
role="navigation"
>
<div className="flex flex-row" role="tablist">
{patientTabs.map((tab) => (
{tabs.map((tab) => (
<Link
key={tab.route}
href={`/facility/${facilityId}/patient/${id}/${tab.route}`}
href={
facilityId
? `/facility/${facilityId}/patient/${id}/${tab.route}`
: `/patient/${id}/${tab.route}`
}
className={`whitespace-nowrap px-4 py-2 text-sm font-medium ${
page === tab.route
? "border-b-4 border-green-800 text-green-800 md:border-b-2"
Expand Down
14 changes: 8 additions & 6 deletions src/components/Patient/PatientRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { PatientModel } from "@/types/emr/patient";
import { Organization } from "@/types/organization/organization";

interface PatientRegistrationPageProps {
facilityId: string;
facilityId?: string;
patientId?: string;
}

Expand Down Expand Up @@ -224,11 +224,13 @@ export default function PatientRegistration(
return;
}

createPatient({
...values,
facility: facilityId,
ward_old: undefined,
});
if (facilityId) {
createPatient({
...values,
facility: facilityId,
ward_old: undefined,
});
}
Comment on lines +227 to +233
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 for missing facilityId case.

The code correctly checks for facilityId before creating a patient, but doesn't handle the case when facilityId is undefined. Consider adding error feedback for users.

 if (facilityId) {
   createPatient({
     ...values,
     facility: facilityId,
     ward_old: undefined,
   });
+} else {
+  toast.error(t("facility_required_for_patient_creation"));
 }

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

}

const sidebarItems = [
Expand Down
Loading