generated from openmrs/openmrs-esm-template-app
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
U4X-539: Adding patient DSDM History & Regimen History (#223)
- Loading branch information
Showing
10 changed files
with
457 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const programs = { | ||
hiv: 'HIV Program', | ||
tb: 'TB Program', | ||
mch: 'MCH Program', | ||
nutrition: 'Nutrition Program', | ||
}; | ||
|
||
export const dsdms = { | ||
fbim: ' Facility Based Individual Management', | ||
fbg: 'Facility Based Groups', | ||
ftdr: 'Fast Track Drug Refill', | ||
cclad: 'Community Client Led ART Delivery', | ||
cddp: 'Community Client Led ART Delivery', | ||
}; |
132 changes: 132 additions & 0 deletions
132
packages/esm-care-panel-app/src/dsdm-history/dsdm-history.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import React, { useMemo, useState } from 'react'; | ||
import { | ||
DataTable, | ||
DataTableSkeleton, | ||
Pagination, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableContainer, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
TableToolbar, | ||
Layer, | ||
Tile, | ||
} from '@carbon/react'; | ||
|
||
import { useTranslation } from 'react-i18next'; | ||
import { formatDate, parseDate, usePagination } from '@openmrs/esm-framework'; | ||
import styles from './dsdm-history.scss'; | ||
import { usePatientPrograms } from '../hooks/usePatientPrograms'; | ||
|
||
interface dsdmnProps { | ||
patientUuid: string; | ||
} | ||
|
||
const DSDMHistory: React.FC<dsdmnProps> = ({ patientUuid }) => { | ||
const { t } = useTranslation(); | ||
|
||
const { isLoading, error, dsdmModels } = usePatientPrograms(patientUuid); | ||
|
||
const pageSizes = [10, 20, 30, 40, 50]; | ||
const [currentPageSize, setPageSize] = useState(10); | ||
|
||
const { goTo, results: paginatedDSDM, currentPage } = usePagination(dsdmModels, currentPageSize); | ||
let columns = [ | ||
{ id: 0, header: t('model', 'Model'), key: 'model' }, | ||
|
||
{ id: 1, header: t('dateEnrolled', 'Date Enrolled'), key: 'dateEnrolled' }, | ||
{ id: 2, header: t('dateCompleted', 'Date Completed'), key: 'dateCompleted' }, | ||
]; | ||
|
||
const tableRows = useMemo(() => { | ||
const currentDate = new Date(); | ||
|
||
return paginatedDSDM?.map((model) => { | ||
const enrolledDate = model.dateEnrolled ? parseDate(model.dateEnrolled) : null; | ||
const formattedEnrolledDate = enrolledDate ? formatDate(enrolledDate) : ''; | ||
|
||
const completedDate = model.dateCompleted ? parseDate(model.dateCompleted) : currentDate; | ||
const formattedCompletedDate = model.dateCompleted ? formatDate(completedDate) : 'Current'; | ||
|
||
return { | ||
...model, | ||
id: model?.program?.concept?.uuid, | ||
model: model?.display, | ||
dateEnrolled: formattedEnrolledDate, | ||
dateCompleted: formattedCompletedDate, | ||
}; | ||
}); | ||
}, [paginatedDSDM]); | ||
|
||
if (isLoading) { | ||
return <DataTableSkeleton role="progressbar" />; | ||
} | ||
|
||
if (paginatedDSDM?.length >= 0) { | ||
return ( | ||
<DataTable rows={tableRows} headers={columns} useZebraStyles overflowMenuOnHover={true}> | ||
{({ rows, headers, getHeaderProps, getTableProps, getRowProps }) => ( | ||
<TableContainer className={styles.tableContainer}> | ||
<TableToolbar | ||
style={{ | ||
position: 'static', | ||
}} | ||
></TableToolbar> | ||
<Table {...getTableProps()} className={styles.activePatientsTable}> | ||
<TableHead> | ||
<TableRow> | ||
{headers.map((header) => ( | ||
<TableHeader {...getHeaderProps({ header })}>{header.header}</TableHeader> | ||
))} | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.map((row, index) => { | ||
return ( | ||
<React.Fragment key={row.id}> | ||
<TableRow {...getRowProps({ row })} key={row.id}> | ||
{row.cells.map((cell) => ( | ||
<TableCell key={cell.id}>{cell.value?.content ?? cell.value}</TableCell> | ||
))} | ||
</TableRow> | ||
</React.Fragment> | ||
); | ||
})} | ||
</TableBody> | ||
</Table> | ||
{rows.length === 0 ? ( | ||
<div className={styles.tileContainer}> | ||
<Tile className={styles.tile}> | ||
<div className={styles.tileContent}> | ||
<p className={styles.content}>{t('noWorklistsToDisplay', 'No worklists orders to display')}</p> | ||
</div> | ||
</Tile> | ||
</div> | ||
) : null} | ||
<Pagination | ||
forwardText="Next page" | ||
backwardText="Previous page" | ||
page={currentPage} | ||
pageSize={currentPageSize} | ||
pageSizes={pageSizes} | ||
totalItems={dsdmModels?.length} | ||
className={styles.pagination} | ||
onChange={({ pageSize, page }) => { | ||
if (pageSize !== currentPageSize) { | ||
setPageSize(pageSize); | ||
} | ||
if (page !== currentPage) { | ||
goTo(page); | ||
} | ||
}} | ||
/> | ||
</TableContainer> | ||
)} | ||
</DataTable> | ||
); | ||
} | ||
}; | ||
|
||
export default DSDMHistory; |
Oops, something went wrong.