Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OHRI-1857 : Users should only be able to edit the latest MNCH visit/e… #1721

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8732a31
OHRI-1857 : Users should only be able to edit the latest MNCH visit/e…
Herobiam Dec 13, 2023
62067d9
(chore) bump-form-engine (#1720)
larslemos Dec 14, 2023
d64c977
OHRI-1995 MDR TB Enrolment table under TB program management menu (#1…
ODORA0 Dec 14, 2023
668abc2
OHRI-2014 Visits table on the TB Patient Summary page (#1719)
ODORA0 Dec 14, 2023
eb3e2c1
(chore) bump-form-engine (#1722)
larslemos Dec 14, 2023
798e94c
Updates on the All TB Clients Table in the Tuberculosis Treatment das…
lucyjemutai Dec 14, 2023
c637803
(chore) bump-form-engine (#1724)
larslemos Dec 15, 2023
e187a6b
addition of null checks (#1726)
arodidev Dec 18, 2023
add4a44
changed from checking the actionItem index to label
Herobiam Dec 18, 2023
cb13379
removed logs
Herobiam Dec 18, 2023
071b4c5
added an optional prop on the encounter list component to disable edit
Herobiam Dec 18, 2023
3deface
fixed lint
Herobiam Dec 19, 2023
977824b
Refactor state in Mdr-tb encounlist component (#1728)
ODORA0 Dec 19, 2023
7910070
OHRI-2037: Connect the TB dashboard tiles with the mamba reports (#1725)
lucyjemutai Dec 19, 2023
4d87c70
(chore) bump-form-engine (#1729)
larslemos Dec 20, 2023
00dcf1d
fix population of treatment start date, Id and regimen on the list (#…
kajambiya Dec 20, 2023
48c424f
(chore) bump-form-engine (#1731)
larslemos Dec 21, 2023
c72a2e2
(chore) release 2.1.x (#1732)
pirupius Dec 21, 2023
ebc4940
OHRI-2034 make swr peer dependency (#1734)
pirupius Jan 9, 2024
0042298
Remove code duplications on the PMTCT module for mamba reports data f…
lucyjemutai Jan 10, 2024
567ee49
OHRI-2045: synchronous loading added (#1738)
arodidev Jan 10, 2024
d610f9e
OHRI-2048 Update package index.ts to syncronously load pages and exte…
ODORA0 Jan 10, 2024
1f2770c
(chore) Add encounter tile related mock data (#1733)
CynthiaKamau Jan 10, 2024
3839e13
(chore) bump-form-engine (#1737)
larslemos Jan 11, 2024
419162c
OHRI-2051 update metadata to use config in covid esm (#1735)
ODORA0 Jan 11, 2024
689dd4b
OHRI 2082 (#1745)
kirwea Jan 11, 2024
e294482
OHRI-2043 Yarn v4 and migrates monorepo to use yarn workspaces (#1750)
pirupius Jan 11, 2024
7d3798a
OHRI-2053 CaCx - update metadata to use config instead of constants (…
arodidev Jan 11, 2024
2789424
OHRI-2044: HIV - Update package index.ts to syncronously load pages a…
lucyjemutai Jan 11, 2024
058e9fb
OHRI-2079 Add unit tests for OTable in commons lib (#1753)
CynthiaKamau Jan 11, 2024
fcc5499
deletes aaaaaactive-visit-tag.scss (#1749)
kirwea Jan 11, 2024
957ae64
OHRI-2054: PMTCT - update metadata to use config instead of constants…
lucyjemutai Jan 11, 2024
34d0d44
(chore) testing pre-release ci (#1754)
pirupius Jan 11, 2024
4fb8df8
OHRI-2086 Add unit tests for ohri summary tile in commons lib (#1756)
arodidev Jan 12, 2024
56de768
Update imports on summary tile test (#1758)
arodidev Jan 12, 2024
e4a2aeb
PMTCT - Update package index.ts to syncronously load pages and extens…
lucyjemutai Jan 12, 2024
5a8a586
OHRI-2025 making hiv-app configurable (moved constants to config-sche…
eudson Jan 12, 2024
4d1034c
(fix) fixes error with wrong config on mch summary (#1762)
pirupius Jan 15, 2024
43df089
OHRI-2106 Fix tests on MambaReport (#1759)
arodidev Jan 15, 2024
b28779c
OHRI-2050 replace momentjs with dayjs (#1761)
pirupius Jan 15, 2024
56f3552
OHRI-1857 : Users should only be able to edit the latest MNCH visit/e…
Herobiam Dec 13, 2023
5a1f45e
changed from checking the actionItem index to label
Herobiam Dec 18, 2023
3fe8217
removed logs
Herobiam Dec 18, 2023
5552f46
added an optional prop on the encounter list component to disable edit
Herobiam Dec 18, 2023
30f9798
fixed lint
Herobiam Dec 19, 2023
c58492f
added mock for test
Herobiam Jan 15, 2024
957752d
OHRI-1857 : Users should only be able to edit the latest MNCH visit/e…
Herobiam Dec 13, 2023
c32fd38
added an optional prop on the encounter list component to disable edit
Herobiam Dec 18, 2023
ec329c5
changed the check from label to the action index
Herobiam Jan 15, 2024
5aa32fd
Merge branch 'OHRI-1857' of https://github.com/Herobiam/openmrs-esm-o…
Herobiam Jan 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { OTable } from '../data-table/o-table.component';
import { Button, Link, OverflowMenu, OverflowMenuItem, Pagination, DataTableSkeleton } from '@carbon/react';
import { Add } from '@carbon/react/icons';
import { OHRIFormSchema } from '@openmrs/openmrs-form-engine-lib';
import { launchEncounterForm } from './helpers';
import { launchEncounterForm, findEncounterLatestDateIndex } from './helpers';
import { useEncounterRows } from '../../hooks/useEncounterRows';
import { OpenmrsEncounter } from '../../api/types';
import { useFormsJson } from '../../hooks/useFormsJson';
Expand Down Expand Up @@ -67,7 +67,7 @@ export const EncounterList: React.FC<EncounterListProps> = ({
onFormSave,
} = useEncounterRows(patientUuid, encounterType, filter);
const { moduleName, workspaceWindowSize, displayText, hideFormLauncher } = launchOptions;

Herobiam marked this conversation as resolved.
Show resolved Hide resolved
const defaultActions = useMemo(
() => [
{
Expand Down Expand Up @@ -124,16 +124,17 @@ export const EncounterList: React.FC<EncounterListProps> = ({

const constructPaginatedTableRows = useCallback(
(encounters: OpenmrsEncounter[], currentPage: number, pageSize: number) => {
const startIndex = (currentPage - 1) * pageSize;
console.log('counters', encounters);
Herobiam marked this conversation as resolved.
Show resolved Hide resolved
const startIndex = (currentPage - 1) * pageSize;
Herobiam marked this conversation as resolved.
Show resolved Hide resolved
const paginatedEncounters = [];
for (let i = startIndex; i < startIndex + pageSize; i++) {
if (i < encounters.length) {
paginatedEncounters.push(encounters[i]);
}
}
const rows = paginatedEncounters.map((encounter) => {
const rows = paginatedEncounters.map((encounter, encounterIndex: number) => {
const tableRow: { id: string; actions: any } = { id: encounter.uuid, actions: null };
// inject launch actions
// inject launch actions
encounter['launchFormActions'] = {
editEncounter: () =>
launchEncounterForm(
Expand Down Expand Up @@ -180,7 +181,7 @@ export const EncounterList: React.FC<EncounterListProps> = ({
});
// If custom config is available, generate actions accordingly; otherwise, fallback to the default actions.
const actions = tableRow.actions?.length ? tableRow.actions : defaultActions;
tableRow['actions'] = (
tableRow['actions'] = (
Herobiam marked this conversation as resolved.
Show resolved Hide resolved
<OverflowMenu flipped className={styles.flippedOverflowMenu}>
{actions.map((actionItem, index) => (
<OverflowMenuItem
Expand All @@ -198,6 +199,7 @@ export const EncounterList: React.FC<EncounterListProps> = ({
workspaceWindowSize,
);
}}
disabled={actionItem.label == 'Edit form' && findEncounterLatestDateIndex(encounters) != encounterIndex}
/>
))}
</OverflowMenu>
Expand All @@ -212,7 +214,7 @@ export const EncounterList: React.FC<EncounterListProps> = ({
useEffect(() => {
if (encounters?.length) {
constructPaginatedTableRows(encounters, currentPage, pageSize);
}
}
}, [encounters, pageSize, constructPaginatedTableRows, currentPage]);

const formLauncher = useMemo(() => {
Expand Down
23 changes: 23 additions & 0 deletions packages/esm-commons-lib/src/components/encounter-list/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OHRIFormSchema, SessionMode } from '@openmrs/openmrs-form-engine-lib';
import { launchForm } from '../../utils/ohri-forms-commons';
import { capitalize } from 'lodash-es';
import { OpenmrsEncounter } from '../../api/types';

type LaunchAction = 'add' | 'view' | 'edit';

Expand All @@ -26,3 +27,25 @@ export function launchEncounterForm(
workspaceWindowSize,
);
}

export const findEncounterLatestDateIndex = (encounters: OpenmrsEncounter[]) => {

if (!encounters || !encounters.length) {
return;
}

let latestDateIndex: number = 0;

for (let i = 1; i < encounters?.length; i++) {

const currentDate = new Date(encounters[i].encounterDatetime);
const latestDate = new Date(encounters[latestDateIndex].encounterDatetime);

if (currentDate > latestDate) {
latestDateIndex = i;
}
}

return latestDateIndex;

}