Skip to content

Commit 1bb36be

Browse files
committed
Refacto routes and menu layout
1 parent 7c7755a commit 1bb36be

2 files changed

Lines changed: 66 additions & 90 deletions

File tree

src/containers/App/index.tsx

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Navigate, Route } from 'react-router-dom';
1+
import { Route } from 'react-router-dom';
22

33
import {
44
Auth as ImplicitGrantAuth,
@@ -9,12 +9,9 @@ import {
99
PractitionerList,
1010
} from '@beda.software/emr/containers';
1111
import { MenuLayout } from '@beda.software/emr/dist/components/BaseLayout/Sidebar/SidebarTop/context';
12-
import config from '@beda.software/emr-config';
13-
14-
import { AuthProvider, authProvidersConfig } from 'src/services/auth.ts';
1512

1613
import { useApp } from './hooks';
17-
import { digitalHealthMenuLayout, menuLayout } from './layout';
14+
import { menuLayout } from './layout';
1815
import { LocationResourceList } from '../LocationResourceList';
1916
import { OrganizationResourceList } from '../OrganizationResourceList';
2017
import { PatientDetails } from '../PatientDetails';
@@ -24,59 +21,22 @@ import { SignIn } from '../SignIn';
2421

2522
export function App() {
2623
const { sharedUserInitService, setAuthProvider } = useApp();
27-
const isDigitalHealth = config.baseURL === authProvidersConfig[AuthProvider.DigitalHealth].baseUrl;
28-
const isEpic = config.baseURL === authProvidersConfig[AuthProvider.Epic].baseUrl;
29-
const isOrionHealth = config.baseURL === authProvidersConfig[AuthProvider.OrionHealth].baseUrl;
30-
const digitalHealthRoutes = (
31-
<>
32-
<Route path="/practitioners" element={<PractitionerList />} />
33-
<Route path="/practitioners/:id/*" element={<PractitionerDetails />} />
34-
<Route path="/healthcare-services" element={<HealthcareServiceList />} />
35-
<Route path="/organizations" element={<OrganizationResourceList />} />
36-
<Route path="/locations" element={<LocationResourceList />} />
37-
</>
38-
);
39-
40-
const renderRoutes = () => {
41-
if (isDigitalHealth) {
42-
return digitalHealthRoutes;
43-
} else if (isEpic) {
44-
return (
45-
<>
46-
<Route path="/patients" element={<Navigate to="/patients/e0lof40pd7mW6R7f0v.4POw3" />} />
47-
<Route path="/patients/:id/*" element={<PatientDetails />} />
48-
</>
49-
);
50-
} else if (isOrionHealth) {
51-
return (
52-
<>
53-
<Route path="/patients" element={<Navigate to="/patients/GE3DQMRZHE4UAU2ZKNPUC" />} />
54-
<Route path="/patients/:id/*" element={<PatientDetails />} />
55-
</>
56-
);
57-
}
58-
59-
return (
60-
<>
61-
<Route path="/patients" element={<PatientResourceList />} />
62-
<Route path="/patients/:id/encounter/:encounter/*" element={<EncounterPage />} />
63-
<Route path="/patients/:id/*" element={<PatientDetails />} />
64-
</>
65-
);
66-
};
67-
68-
const getMenuLayout = () => {
69-
if (isDigitalHealth) {
70-
return digitalHealthMenuLayout;
71-
}
72-
73-
return menuLayout;
74-
};
7524

7625
return (
77-
<MenuLayout.Provider value={getMenuLayout()}>
26+
<MenuLayout.Provider value={menuLayout}>
7827
<EMR
79-
authenticatedRoutes={renderRoutes()}
28+
authenticatedRoutes={
29+
<>
30+
<Route path="/practitioners" element={<PractitionerList />} />
31+
<Route path="/practitioners/:id/*" element={<PractitionerDetails />} />
32+
<Route path="/healthcare-services" element={<HealthcareServiceList />} />
33+
<Route path="/organizations" element={<OrganizationResourceList />} />
34+
<Route path="/locations" element={<LocationResourceList />} />
35+
<Route path="/patients" element={<PatientResourceList />} />
36+
<Route path="/patients/:id/encounter/:encounter/*" element={<EncounterPage />} />
37+
<Route path="/patients/:id/*" element={<PatientDetails />} />
38+
</>
39+
}
8040
anonymousRoutes={
8141
<>
8242
<Route path="/signin" element={<SignIn onSwitchService={setAuthProvider} />} />
@@ -85,7 +45,7 @@ export function App() {
8545
</>
8646
}
8747
populateUserInfoSharedState={sharedUserInitService}
88-
menuLayout={getMenuLayout()}
48+
menuLayout={menuLayout}
8949
/>
9050
</MenuLayout.Provider>
9151
);

src/containers/App/layout.tsx

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,54 @@
1-
import { t } from "@lingui/macro";
2-
3-
import { MenuLayoutValue } from "@beda.software/emr/dist/components/BaseLayout/Sidebar/SidebarTop/context";
4-
import {OrganizationsIcon, PatientsIcon, PractitionersIcon, ServicesIcon} from '@beda.software/emr/icons';
5-
import {matchCurrentUserRole, Role} from '@beda.software/emr/utils'
6-
7-
export const menuLayout: MenuLayoutValue = () =>
8-
matchCurrentUserRole({
9-
[Role.Admin]: () => [
10-
{ label: t`Patients`, path: '/patients', icon: <PatientsIcon /> },
11-
],
12-
[Role.Practitioner]: () => [
13-
{ label: t`Patients`, path: '/patients', icon: <PatientsIcon /> },
14-
],
15-
[Role.Patient]: (patient) => [
16-
{ label: 'Me', path: `/patients/${patient.id}`, icon: <PatientsIcon /> },
17-
],
18-
[Role.Receptionist]: () => [],
19-
});
1+
import { t } from '@lingui/macro';
2+
3+
import { MenuLayoutValue } from '@beda.software/emr/dist/components/BaseLayout/Sidebar/SidebarTop/context';
4+
import { OrganizationsIcon, PatientsIcon, PractitionersIcon, ServicesIcon } from '@beda.software/emr/icons';
5+
import { matchCurrentUserRole, Role } from '@beda.software/emr/utils';
6+
import config from '@beda.software/emr-config';
7+
8+
import { AuthProvider, authProvidersConfig } from 'src/services/auth.ts';
9+
10+
const EPIC_PATIENT_ID = 'e0lof40pd7mW6R7f0v.4POw3';
11+
const ORION_HEALTH_PATIENT_ID = 'GE3DQMRZHE4UAU2ZKNPUC';
12+
13+
const digitalHealthMenuItems = [
14+
{ label: t`Services`, path: '/healthcare-services', icon: <ServicesIcon /> },
15+
{ label: t`Practitioners`, path: '/practitioners', icon: <PractitionersIcon /> },
16+
{ label: t`Organizations`, path: '/organizations', icon: <OrganizationsIcon /> },
17+
{ label: t`Locations`, path: '/locations', icon: <OrganizationsIcon /> },
18+
];
19+
20+
function getPatientsPath() {
21+
if (config.baseURL === authProvidersConfig[AuthProvider.Epic].baseUrl) {
22+
return `/patients/${EPIC_PATIENT_ID}`;
23+
}
24+
25+
if (config.baseURL === authProvidersConfig[AuthProvider.OrionHealth].baseUrl) {
26+
return `/patients/${ORION_HEALTH_PATIENT_ID}`;
27+
}
28+
29+
return '/patients';
30+
}
31+
32+
function isDigitalHealth() {
33+
return config.baseURL === authProvidersConfig[AuthProvider.DigitalHealth].baseUrl;
34+
}
35+
36+
export const menuLayout: MenuLayoutValue = () => {
37+
if (isDigitalHealth()) {
38+
return matchCurrentUserRole({
39+
[Role.Admin]: () => digitalHealthMenuItems,
40+
[Role.Practitioner]: () => digitalHealthMenuItems,
41+
[Role.Patient]: () => [],
42+
[Role.Receptionist]: () => [],
43+
});
44+
}
2045

46+
const patientsPath = getPatientsPath();
2147

22-
export const digitalHealthMenuLayout: MenuLayoutValue = () =>
23-
matchCurrentUserRole({
24-
[Role.Admin]: () => [
25-
{ label: t`Services`, path: '/healthcare-services', icon: <ServicesIcon /> },
26-
{ label: t`Practitioners`, path: '/practitioners', icon: <PractitionersIcon /> },
27-
{ label: t`Organizations`, path: '/organizations', icon: <OrganizationsIcon /> },
28-
{ label: t`Locations`, path: '/locations', icon: <OrganizationsIcon /> },
29-
],
30-
[Role.Practitioner]: () => [
31-
{ label: t`Services`, path: '/healthcare-services', icon: <ServicesIcon /> },
32-
{ label: t`Practitioners`, path: '/practitioners', icon: <PractitionersIcon /> },
33-
{ label: t`Organizations`, path: '/organizations', icon: <OrganizationsIcon /> },
34-
{ label: t`Locations`, path: '/locations', icon: <OrganizationsIcon /> },
35-
],
36-
[Role.Patient]: () => [],
48+
return matchCurrentUserRole({
49+
[Role.Admin]: () => [{ label: t`Patients`, path: patientsPath, icon: <PatientsIcon /> }],
50+
[Role.Practitioner]: () => [{ label: t`Patients`, path: patientsPath, icon: <PatientsIcon /> }],
51+
[Role.Patient]: (patient) => [{ label: 'Me', path: `/patients/${patient.id}`, icon: <PatientsIcon /> }],
3752
[Role.Receptionist]: () => [],
3853
});
54+
};

0 commit comments

Comments
 (0)