import React, { useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { DataTable, DataTableSkeleton, Layer, Pagination, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@carbon/react'; import { CardHeader, EmptyCard, ErrorState, usePagination } from '@openmrs/esm-framework'; import { usePatientDiagnosis } from './diagnoses.resource'; import styles from './diagnoses.scss'; type PatientDiagnosesProps = { patientUuid: string; encounterUuid: string; }; const PatientDiagnoses: React.FC = ({ encounterUuid, patientUuid }) => { const { diagnoses, isLoading, error } = usePatientDiagnosis(encounterUuid); const [pageSize, setPageSize] = useState(3); const pageSizesOptions = useMemo(() => [3, 5, 10, 20, 50, 100], []); const { results, totalPages, currentPage, goTo } = usePagination(diagnoses, pageSize); const { t } = useTranslation(); const title = t('diagnoses', 'Diagnoses'); const headers = useMemo( () => [ { header: t('diagnosis', 'Diagnosis'), key: 'text' }, { header: t('status', 'Status'), key: 'certainty' }, ], [t], ); const getColumnClass = (key: string) => { switch (key) { case 'text': return styles.diagnosisColumn; case 'certainty': return styles.statusColumn; default: return ''; } }; if (isLoading) { return ; } if (error) { return ; } if (!diagnoses?.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 PatientDiagnoses;