Skip to content

Commit

Permalink
U4X-539: Adding patient DSDM History & Regimen History (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daphne210 authored Apr 23, 2024
1 parent b067b19 commit b6de7ad
Show file tree
Hide file tree
Showing 10 changed files with 457 additions and 71 deletions.
53 changes: 30 additions & 23 deletions packages/esm-care-panel-app/src/care-panel/care-panel.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { StructuredListSkeleton, ContentSwitcher, Switch } from '@carbon/react';
import styles from './care-panel.scss';
import { usePatientPrograms } from '../hooks/usePatientPrograms';
import ProgramEnrollment from '../program-enrollment/program-enrollment.component';
import { CardHeader, EmptyState } from '@openmrs/esm-patient-common-lib';
import { ErrorState } from '@openmrs/esm-framework';
import CarePrograms from '../care-programs/care-programs.component';
import ProgramEnrollmentTB from '../program-enrollment/program-enrollment-tb.component';
import { programs } from '../constants';
import DSDMHistory from '../dsdm-history/dsdm-history.component';
import { CardHeader } from '@openmrs/esm-patient-common-lib';

interface CarePanelProps {
patientUuid: string;
Expand All @@ -23,19 +25,14 @@ type SwitcherItem = {

const CarePanel: React.FC<CarePanelProps> = ({ patientUuid, formEntrySub, launchPatientWorkspace }) => {
const { t } = useTranslation();
const { isLoading, error, enrollments } = usePatientPrograms(patientUuid);
const switcherHeaders = enrollments?.map((item) => item.program.name);
const { isLoading, error, enrollments, dsdmModels } = usePatientPrograms(patientUuid);
const switcherHeaders = enrollments?.map((item) => item.program.name) || [];
const [selectedIndex, setSelectedIndex] = useState(0);
const [switchItem, setSwitcherItem] = useState<SwitcherItem>(() => {
const firstEnrollment = enrollments?.[0];
return firstEnrollment ? { index: 0, name: firstEnrollment.program.name } : undefined;
});
const programs = {
hiv: 'HIV Program',
tb: 'TB Program',
mch: 'MCH Program',
nutrition: 'Nutrition Program',
};

useEffect(() => {
if (!switchItem && enrollments && enrollments.length > 0) {
setSwitcherItem({ index: 0, name: enrollments[0].program.name });
Expand All @@ -51,6 +48,7 @@ const CarePanel: React.FC<CarePanelProps> = ({ patientUuid, formEntrySub, launch
setSelectedIndex(index);
}
};

if (isLoading) {
return (
<div className={styles.widgetCard}>
Expand Down Expand Up @@ -78,8 +76,9 @@ const CarePanel: React.FC<CarePanelProps> = ({ patientUuid, formEntrySub, launch
</ContentSwitcher>
</div>
</CardHeader>
<div style={{ width: '100%', minHeight: '20rem' }}>
{switchItem?.name === programs.hiv && (

{switchItem?.name === programs.hiv && (
<div style={{ width: '100%', minHeight: '20rem' }}>
<ProgramEnrollment
patientUuid={patientUuid}
programName={switchItem?.name}
Expand All @@ -88,20 +87,28 @@ const CarePanel: React.FC<CarePanelProps> = ({ patientUuid, formEntrySub, launch
launchPatientWorkspace={launchPatientWorkspace}
PatientChartProps={''}
/>
)}
</div>
)}
{switchItem?.name === programs.tb && (
<div style={{ width: '100%', minHeight: '20rem' }}>
{switchItem?.name === programs.tb && (
<ProgramEnrollmentTB
patientUuid={patientUuid}
programName={switchItem?.name}
enrollments={enrollments}
formEntrySub={formEntrySub}
launchPatientWorkspace={launchPatientWorkspace}
PatientChartProps={''}
/>
)}
<ProgramEnrollmentTB
patientUuid={patientUuid}
programName={switchItem?.name}
enrollments={enrollments}
formEntrySub={formEntrySub}
launchPatientWorkspace={launchPatientWorkspace}
PatientChartProps={''}
/>
</div>
)}
{switchItem?.name === programs.hiv && dsdmModels && (
<div>
<section className={styles.section}>
<h5 className={styles.section}>{t('dsdmHistory', 'DSD Model History')}</h5>
</section>
<DSDMHistory patientUuid={patientUuid} />
</div>
</div>
)}
</div>
) : (
<div className={styles.careProgramContainer}>
Expand Down
8 changes: 3 additions & 5 deletions packages/esm-care-panel-app/src/care-panel/care-panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.contextSwitcherContainer {
width: 20rem;
min-width: 60%;
margin-right: 1rem;
margin: 1rem 0 0;
}

.desktopContentSwitcher {
Expand Down Expand Up @@ -43,10 +43,8 @@
}
}

.emptyState {
.section {
margin: spacing.$spacing-03;
display: flex;
justify-content: center;
align-items: center;
line-height: 20rem;
font-weight: bold;
}
25 changes: 25 additions & 0 deletions packages/esm-care-panel-app/src/config-schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Type } from '@openmrs/esm-framework';
import _default from 'react-hook-form/dist/utils/createSubject';

export interface CarePanelConfig {
regimenObs: {
Expand Down Expand Up @@ -77,4 +78,28 @@ export const configSchema = {
_type: Type.ConceptUuid,
_default: 'e077f196-c19a-417f-adc6-b175a3343bfd',
},
fbimUuid: {
_type: Type.ConceptUuid,
_default: '733144c0-c321-11e8-a355-529269fb1459',
},
fbgUuid: {
_type: Type.ConceptUuid,
_default: '73313c96-c321-11e8-a355-529269fb1459',
},
ftdrUuid: {
_type: Type.ConceptUuid,
_default: '73313f20-c321-11e8-a355-529269fb1459',
},
ccladUuid: {
_type: Type.ConceptUuid,
_default: '733139e4-c321-11e8-a355-529269fb1459',
},
cddpUuid: {
_type: Type.ConceptUuid,
_default: '73313728-c321-11e8-a355-529269fb1459',
},
currentARVDurationUuid: {
_type: Type.ConceptUuid,
_default: '171de3f4-a500-46f6-8098-8097561dfffb',
},
};
14 changes: 14 additions & 0 deletions packages/esm-care-panel-app/src/constants.ts
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',
};
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;
Loading

0 comments on commit b6de7ad

Please sign in to comment.