import { DataTable, DataTableSkeleton, Layer, Pagination, Table, TableBody, TableCell, TableContainer, TableHead, TableHeader, TableRow, Tile, } from '@carbon/react'; import { ConfigurableLink, ErrorState, useConfig } from '@openmrs/esm-framework'; import { CardHeader } from '@openmrs/esm-patient-common-lib'; import { useTranslation } from 'react-i18next'; import React, { useMemo } from 'react'; import { useAdmisiionLocations } from '../../hooks/useAdmissionLocation'; import styles from './linelist-wards.scss'; import { type AdmissionLocationFetchResponse } from '../../types'; import { EmptyState } from '../../ward-patients/table-state-components'; import WardPendingOutCell from './WardPendingOutCell'; import { type WardConfigObject } from '../../config-schema'; const LineListTable = () => { const { admissionLocations, error, isLoading, paginated, currentPage, pageSizes, goTo, currPageSize, setCurrPageSize, totalCount, } = useAdmisiionLocations(); const { t } = useTranslation(); const headerTitle = t('wards', 'Wards'); const { mortuaryAdmissionLoctionTagUuid } = useConfig(); const filteredAdmissionLocations = useMemo(() => { if (!mortuaryAdmissionLoctionTagUuid) return admissionLocations; return admissionLocations.filter((location) => { const hasMortuaryTag = location.ward.tags?.some((tag) => tag.uuid === mortuaryAdmissionLoctionTagUuid); return !hasMortuaryTag; }); }, [admissionLocations, mortuaryAdmissionLoctionTagUuid]); const headers = [ { key: 'ward', header: t('wardName', 'Ward Name') }, { key: 'numberOfBeds', header: t('numberofbeds', 'Number of Beds') }, { key: 'occupiedBeds', header: t('occupiedBeds', 'Occupied Beds') }, { key: 'freebeds', header: t('freebeds', 'Free Beds') }, { key: 'bedOccupancy', header: t('bedOccupancy', 'Bed Occupancy%') }, { key: 'pendingOut', header: t('pendingOut', 'Pending Out') }, { key: 'action', header: t('action', 'Action') }, ]; const calculateOccupancy = (location: AdmissionLocationFetchResponse) => { if (!location.totalBeds) return 0; return (((location?.occupiedBeds ?? 0) / location.totalBeds) * 100).toFixed(2); }; const tableRows = useMemo(() => { return filteredAdmissionLocations.map((location) => { const url = '${openmrsSpaBase}/home/ward/${locationUuid}'; return { id: location.ward.uuid, ward: ( {location.ward.display} ), numberOfBeds: location.totalBeds, occupiedBeds: location.occupiedBeds, freebeds: location.totalBeds - location.occupiedBeds, bedOccupancy: calculateOccupancy(location), pendingOut: , }; }); }, [filteredAdmissionLocations]); if (isLoading) return ( ); if (error) return ( ); return ( <> {({ rows, headers, getHeaderProps, getRowProps, getTableProps, getCellProps }) => ( {headers.map((header) => ( {header.header} ))} {rows.map((row) => { return ( {row.cells.map((cell) => ( {cell.value} ))} ); })}
{rows.length === 0 && } {paginated && !isLoading && ( { if (newPage !== currentPage) { goTo(newPage); } setCurrPageSize(pageSize); }} /> )}
)}
); }; export default LineListTable;