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

Fixes:Gives access of consultation details to users for only allowed facilities. #8727

16 changes: 15 additions & 1 deletion src/Components/Facility/ConsultationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { useState } from "react";
import DialogModal from "../Common/Dialog.js";
import Beds from "./Consultations/Beds";
import careConfig from "@careConfig";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";
Comment on lines +13 to +14
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 loading and error handling for facility data fetching.

The facility data fetching implementation could be enhanced to handle edge cases and improve user experience.

Consider these improvements:

 import useQuery from "../../Utils/request/useQuery";
 import routes from "../../Redux/api";
+import { LoadingIndicator } from "../Common/LoadingIndicator";

 export const ConsultationCard = (props: ConsultationProps) => {
-  const facilities = useQuery(routes.getPermittedFacilities).data?.results;
+  const { data: facilitiesData, error: facilitiesError, loading } = useQuery(routes.getPermittedFacilities);
+  const facilities = facilitiesData?.results;
+
+  if (loading) {
+    return <LoadingIndicator />;
+  }
+
+  if (facilitiesError) {
+    Notification.Error({
+      msg: "Failed to fetch facility permissions",
+    });
+  }

Also applies to: 30-30


interface ConsultationProps {
itemData: ConsultationModel;
Expand All @@ -25,6 +27,7 @@ export const ConsultationCard = (props: ConsultationProps) => {
: !itemData.current_bed
? "Assign Bed"
: "Switch Bed";
const facilities = useQuery(routes.getPermittedFacilities).data?.results;
return (
<>
<DialogModal
Expand Down Expand Up @@ -173,6 +176,9 @@ export const ConsultationCard = (props: ConsultationProps) => {
`/facility/${itemData.facility}/patient/${itemData.patient}/consultation/${itemData.id}`,
)
}
disabled={
!facilities?.some((item) => item.name === itemData.facility_name)
Copy link
Member

Choose a reason for hiding this comment

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

don't we have facility id in the api ? 🤔

}
>
View Consultation / Consultation Updates
</ButtonV2>
Expand All @@ -183,6 +189,9 @@ export const ConsultationCard = (props: ConsultationProps) => {
`/facility/${itemData.facility}/patient/${itemData.patient}/consultation/${itemData.id}/files/`,
)
}
disabled={
!facilities?.some((item) => item.name === itemData.facility_name)
}
>
View / Upload Consultation Files
</ButtonV2>
Expand All @@ -201,7 +210,12 @@ export const ConsultationCard = (props: ConsultationProps) => {
);
}
}}
disabled={!!itemData.discharge_date}
disabled={
!!itemData.discharge_date ||
!facilities?.some(
(item) => item.name === itemData.facility_name,
)
}
authorizeFor={NonReadOnlyUsers}
>
Add Consultation Updates
Expand Down
Loading