import React, { useMemo, useState } from 'react'; import { DataTable, DataTableSkeleton, Layer, Pagination, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@carbon/react'; import { useTranslation } from 'react-i18next'; import { CardHeader, EmptyCard, ErrorState, usePagination } from '@openmrs/esm-framework'; import { pageSizesOptions, usePatientConditions } from './conditions.resource'; import styles from './conditions.scss'; type PatientConditionsProps = { patientUuid: string; }; const PatientConditions: React.FC = ({ patientUuid }) => { const { t } = useTranslation(); const { conditions, error, isLoading } = usePatientConditions(patientUuid); const [pageSize, setPageSize] = useState(3); const { results, currentPage, goTo } = usePagination(conditions, pageSize); const headers = useMemo( () => [ { header: t('conditions', 'Condition'), key: 'display' }, { header: t('onsetDate', 'Onset date'), key: 'onsetDateTime' }, ], [t], ); const getColumnClass = (key: string) => { switch (key) { case 'display': return styles.conditionColumn; case 'onsetDateTime': return styles.onsetDateColumn; default: return ''; } }; const title = t('activeConditions', 'Active conditions'); const tableRows = useMemo( () => results.map((row) => ({ ...row, onsetDateTime: row.onsetDateTime || '--', })), [results], ); if (isLoading) { return ; } if (error) { return ; } if (!conditions?.length) { return ( ); } return ( {({ rows, headers, getTableProps, getHeaderProps, getRowProps }) => ( {headers.map((header) => ( {header.header} ))} {rows.map((row) => ( {row.cells.map((cell) => ( {cell.value} ))} ))}
)}
{ goTo(page); setPageSize(pageSize); }} />
); }; export default PatientConditions;