Skip to content

Commit

Permalink
implemeted a dedicated component for bed capacity in facility home
Browse files Browse the repository at this point in the history
  • Loading branch information
sriharsh05 committed Nov 11, 2023
1 parent da9c599 commit dc5fe3e
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 151 deletions.
118 changes: 118 additions & 0 deletions src/Components/Facility/FacilityBedCapacity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { useState } from "react";
import { getBedTypes } from "../../Common/constants";
import routes from "../../Redux/api";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import useQuery from "../../Utils/request/useQuery";
import DialogModal from "../Common/Dialog";
import ButtonV2 from "../Common/components/ButtonV2";
import { BedCapacity } from "./BedCapacity";
import BedTypeCard from "./BedTypeCard";
import useConfig from "../../Common/hooks/useConfig";

export const FacilityBedCapacity = (props: any) => {
const [bedCapacityModalOpen, setBedCapacityModalOpen] = useState(false);
const config = useConfig();

const capacityQuery = useQuery(routes.getCapacity, {
pathParams: { facilityId: props.facilityId },
});

let capacityList: any = null;
let totalBedCount = 0;
let totalOccupiedBedCount = 0;
if (!capacityQuery.data || !capacityQuery.data.results.length) {
capacityList = (
<h5 className="mt-4 flex w-full items-center justify-center rounded-lg bg-white p-4 text-xl font-bold text-gray-500 shadow">
No Bed Types Found
</h5>
);
} else {
capacityQuery.data.results.forEach((x) => {
totalBedCount += x.total_capacity ? x.total_capacity : 0;
totalOccupiedBedCount += x.current_capacity ? x.current_capacity : 0;
});

capacityList = (
<div className="mt-4 grid w-full gap-7 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
<BedTypeCard
label="Total Beds"
used={totalOccupiedBedCount}
total={totalBedCount}
handleUpdate={() => {
return;
}}
/>
{getBedTypes(config).map((x) => {
const res = capacityQuery.data?.results.find((data) => {
return data.room_type === x.id;
});
if (
res &&
res.current_capacity !== undefined &&
res.total_capacity !== undefined
) {
const removeCurrentBedType = (bedTypeId: number | undefined) => {
if (capacityQuery.data !== undefined) {
capacityQuery.data.results = capacityQuery.data.results.filter(
(i) => i.id !== bedTypeId
);
}
};
return (
<BedTypeCard
facilityId={props.facilityId}
bedCapacityId={res.id}
key={`bed_${res.id}`}
room_type={res.room_type}
label={x.text}
used={res.current_capacity}
total={res.total_capacity}
lastUpdated={res.modified_date}
removeBedType={removeCurrentBedType}
handleUpdate={() => {
capacityQuery.refetch();
}}
/>
);
}
})}
</div>
);
}

return (
<div>
<div className="mt-5 rounded bg-white p-3 shadow-sm md:p-6">
<div className="justify-between md:flex md:border-b md:pb-2">
<div className="mb-2 text-xl font-semibold">Bed Capacity</div>
<ButtonV2
className="w-full md:w-auto"
onClick={() => setBedCapacityModalOpen(true)}
authorizeFor={NonReadOnlyUsers}
>
<i className="fas fa-bed mr-2 text-white" />
Add More Bed Types
</ButtonV2>
</div>
<div>{capacityList}</div>
</div>

{bedCapacityModalOpen && (
<DialogModal
show={bedCapacityModalOpen}
onClose={() => setBedCapacityModalOpen(false)}
title="Add Bed Capacity"
className="max-w-md md:min-w-[600px]"
>
<BedCapacity
facilityId={props.facilityId}
handleClose={() => setBedCapacityModalOpen(false)}
handleUpdate={async () => {
capacityQuery.refetch();
}}
/>
</DialogModal>
)}
</div>
);
};
127 changes: 9 additions & 118 deletions src/Components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,22 @@ import * as Notification from "../../Utils/Notifications.js";

import AuthorizeFor, { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import { FacilityModel } from "./models";
import {
FACILITY_FEATURE_TYPES,
USER_TYPES,
getBedTypes,
} from "../../Common/constants";
import { FACILITY_FEATURE_TYPES, USER_TYPES } from "../../Common/constants";
import DropdownMenu, { DropdownItem } from "../Common/components/Menu";
import { lazy, useState } from "react";
import { BedCapacity } from "./BedCapacity";
import BedTypeCard from "./BedTypeCard";

import ButtonV2 from "../Common/components/ButtonV2";
import CareIcon from "../../CAREUI/icons/CareIcon";
import Chip from "../../CAREUI/display/Chip";
import ConfirmDialog from "../Common/ConfirmDialog";
import ContactLink from "../Common/components/ContactLink";
import CoverImageEditModal from "./CoverImageEditModal";
import DialogModal from "../Common/Dialog";

import Page from "../Common/components/Page";
import RecordMeta from "../../CAREUI/display/RecordMeta";
import Table from "../Common/components/Table";

import { navigate } from "raviger";
import useConfig from "../../Common/hooks/useConfig";
import { useMessageListener } from "../../Common/hooks/useMessageListener";
import { useTranslation } from "react-i18next";
import useAuthUser from "../../Common/hooks/useAuthUser.js";
Expand All @@ -33,6 +26,7 @@ import routes from "../../Redux/api.js";
import useQuery from "../../Utils/request/useQuery.js";
import { FacilityHomeTriage } from "./FacilityHomeTriage.js";
import { FacilityDoctorList } from "./FacilityDoctorList.js";
import { FacilityBedCapacity } from "./FacilityBedCapacity.js";

const Loading = lazy(() => import("../Common/Loading"));

Expand All @@ -52,9 +46,7 @@ export const FacilityHome = (props: any) => {
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
const [editCoverImage, setEditCoverImage] = useState(false);
const [imageKey, setImageKey] = useState(Date.now());
const [bedCapacityModalOpen, setBedCapacityModalOpen] = useState(false);
const authUser = useAuthUser();
const config = useConfig();

useMessageListener((data) => console.log(data));

Expand All @@ -65,19 +57,13 @@ export const FacilityHome = (props: any) => {
id: facilityId,
},
onResponse: ({ res }) => {
if (res?.ok) {
capacityQuery.refetch();
} else {
if (!res?.ok) {
navigate("/not-found");
}
},
}
);

const capacityQuery = useQuery(routes.getCapacity, {
pathParams: { facilityId },
});

const handleDeleteClose = () => {
setOpenDeleteDialog(false);
};
Expand All @@ -99,68 +85,6 @@ export const FacilityHome = (props: any) => {
if (isLoading) {
return <Loading />;
}
let capacityList: any = null;
let totalBedCount = 0;
let totalOccupiedBedCount = 0;
if (!capacityQuery.data || !capacityQuery.data.results.length) {
capacityList = (
<h5 className="mt-4 flex w-full items-center justify-center rounded-lg bg-white p-4 text-xl font-bold text-gray-500 shadow">
No Bed Types Found
</h5>
);
} else {
capacityQuery.data.results.forEach((x) => {
totalBedCount += x.total_capacity ? x.total_capacity : 0;
totalOccupiedBedCount += x.current_capacity ? x.current_capacity : 0;
});

capacityList = (
<div className="mt-4 grid w-full gap-7 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
<BedTypeCard
label="Total Beds"
used={totalOccupiedBedCount}
total={totalBedCount}
handleUpdate={() => {
return;
}}
/>
{getBedTypes(config).map((x) => {
const res = capacityQuery.data?.results.find((data) => {
return data.room_type === x.id;
});
if (
res &&
res.current_capacity !== undefined &&
res.total_capacity !== undefined
) {
const removeCurrentBedType = (bedTypeId: number | undefined) => {
if (capacityQuery.data !== undefined) {
capacityQuery.data.results = capacityQuery.data.results.filter(
(i) => i.id !== bedTypeId
);
}
};
return (
<BedTypeCard
facilityId={facilityId}
bedCapacityId={res.id}
key={`bed_${res.id}`}
room_type={res.room_type}
label={x.text}
used={res.current_capacity}
total={res.total_capacity}
lastUpdated={res.modified_date}
removeBedType={removeCurrentBedType}
handleUpdate={() => {
capacityQuery.refetch();
}}
/>
);
}
})}
</div>
);
}

const hasCoverImage = !!facilityData?.read_cover_image_url;

Expand Down Expand Up @@ -533,46 +457,13 @@ export const FacilityHome = (props: any) => {
/>
</div>
</div>
<div className="mt-5 rounded bg-white p-3 shadow-sm md:p-6">
<div className="justify-between md:flex md:border-b md:pb-2">
<div className="mb-2 text-xl font-semibold">Bed Capacity</div>
<ButtonV2
className="w-full md:w-auto"
onClick={() => setBedCapacityModalOpen(true)}
authorizeFor={NonReadOnlyUsers}
>
<i className="fas fa-bed mr-2 text-white" />
Add More Bed Types
</ButtonV2>
</div>
<div>{capacityList}</div>
</div>

<FacilityBedCapacity facilityId={facilityId} />
<FacilityDoctorList facilityId={facilityId} />

<div className="mt-5 rounded bg-white p-3 shadow-sm md:p-6">
<FacilityHomeTriage
facilityId={facilityId}
NonReadOnlyUsers={NonReadOnlyUsers}
/>
</div>

{bedCapacityModalOpen && (
<DialogModal
show={bedCapacityModalOpen}
onClose={() => setBedCapacityModalOpen(false)}
title="Add Bed Capacity"
className="max-w-md md:min-w-[600px]"
>
<BedCapacity
facilityId={facilityId}
handleClose={() => setBedCapacityModalOpen(false)}
handleUpdate={async () => {
capacityQuery.refetch();
}}
/>
</DialogModal>
)}
<FacilityHomeTriage
facilityId={facilityId}
NonReadOnlyUsers={NonReadOnlyUsers}
/>
</Page>
);
};
68 changes: 35 additions & 33 deletions src/Components/Facility/FacilityHomeTriage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,41 @@ export const FacilityHomeTriage = (props: any) => {
}

return (
<div className="-my-2 py-2 sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8">
<div className="justify-between md:flex md:pb-2">
<div className="mb-2 text-xl font-bold">Corona Triage</div>
<ButtonV2
className="w-full md:w-auto"
onClick={() => navigate(`/facility/${props.facilityId}/triage`)}
authorizeFor={props.NonReadOnlyUsers}
>
<i className="fas fa-notes-medical mr-2 text-white" />
Add Triage
</ButtonV2>
</div>
<div className="mt-4 overflow-x-auto overflow-y-hidden">
<Table
rows={stats}
headings={[
"Date",
"Total Triaged",
"Advised Home Quarantine",
"Suspects Isolated",
"Referred",
"Confirmed positives",
"Actions",
]}
/>
{stats.length === 0 && (
<>
<hr />
<div className="mt-3 flex min-w-[1000px] items-center justify-center rounded-sm border border-[#D2D6DC] p-4 text-xl font-bold text-gray-600">
No Data Found
</div>
</>
)}
<div className="mt-5 rounded bg-white p-3 shadow-sm md:p-6">
<div className="-my-2 py-2 sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8">
<div className="justify-between md:flex md:pb-2">
<div className="mb-2 text-xl font-bold">Corona Triage</div>
<ButtonV2
className="w-full md:w-auto"
onClick={() => navigate(`/facility/${props.facilityId}/triage`)}
authorizeFor={props.NonReadOnlyUsers}
>
<i className="fas fa-notes-medical mr-2 text-white" />
Add Triage
</ButtonV2>
</div>
<div className="mt-4 overflow-x-auto overflow-y-hidden">
<Table
rows={stats}
headings={[
"Date",
"Total Triaged",
"Advised Home Quarantine",
"Suspects Isolated",
"Referred",
"Confirmed positives",
"Actions",
]}
/>
{stats.length === 0 && (
<>
<hr />
<div className="mt-3 flex min-w-[1000px] items-center justify-center rounded-sm border border-[#D2D6DC] p-4 text-xl font-bold text-gray-600">
No Data Found
</div>
</>
)}
</div>
</div>
</div>
);
Expand Down

0 comments on commit dc5fe3e

Please sign in to comment.