diff --git a/src/Components/Facility/FacilityCard.tsx b/src/Components/Facility/FacilityCard.tsx
index d6c2dce2b6c..6f05d6aec72 100644
--- a/src/Components/Facility/FacilityCard.tsx
+++ b/src/Components/Facility/FacilityCard.tsx
@@ -10,19 +10,38 @@ import { formatPhoneNumber, parsePhoneNumber } from "../../Utils/utils";
import DialogModal from "../Common/Dialog";
import TextAreaFormField from "../Form/FormFields/TextAreaFormField";
import useConfig from "../../Common/hooks/useConfig";
-import { classNames } from "../../Utils/utils";
import request from "../../Utils/request/request";
import routes from "../../Redux/api";
-
+import { getBedTypes } from "../../Common/constants";
+import useQuery from "../../Utils/request/useQuery";
+import { Occupany_badge } from "./Facilitybedoccupancybadge";
export const FacilityCard = (props: { facility: any; userType: any }) => {
const { facility, userType } = props;
const { kasp_string } = useConfig();
+ const config = useConfig();
+ const capacityQuery = useQuery(routes.getCapacity, {
+ pathParams: { facilityId: `${facility.id}` },
+ });
const { t } = useTranslation();
const [notifyModalFor, setNotifyModalFor] = useState(undefined);
const [notifyMessage, setNotifyMessage] = useState("");
const [notifyError, setNotifyError] = useState("");
-
+ const occupancy = {
+ total_occupancy: {
+ occupied: facility.patient_count,
+ total: facility.total_count,
+ tooltip:
+ "Total patients marked as admitted in consultation/ Total no. of registered bed",
+ badge_title: "Occupancy",
+ },
+ icu: {
+ occupied: 0,
+ total: 0,
+ tooltip: "ICU bed type/ Number of ICU beds registered",
+ badge_title: "ICU Occupancy",
+ },
+ };
const handleNotifySubmit = async (id: any) => {
if (notifyMessage.trim().length >= 1) {
setNotifyError("");
@@ -45,6 +64,34 @@ export const FacilityCard = (props: { facility: any; userType: any }) => {
}
};
+ getBedTypes(config).forEach((x) => {
+ const res = capacityQuery.data?.results.find((data) => {
+ return data.room_type === x.id;
+ });
+ if (
+ res &&
+ res.current_capacity !== undefined &&
+ res.total_capacity !== undefined &&
+ (res.room_type === 20 || res.room_type === 10)
+ ) {
+ occupancy.icu.total = occupancy.icu.total + res.total_capacity;
+ occupancy.icu.occupied = occupancy.icu.occupied + res.current_capacity;
+ }
+ });
+ const Badge: JSX.Element[] = [];
+ for (const key in occupancy) {
+ const element = occupancy[key as keyof typeof occupancy];
+ Badge.push(
+