@kenyaemr/esm-admin-app 5.4.4-pre.36 → 5.4.4-pre.360
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -12
- package/dist/100.js +1 -0
- package/dist/100.js.map +1 -0
- package/dist/1074.js +1 -0
- package/dist/1074.js.map +1 -0
- package/dist/1242.js +1 -0
- package/dist/1242.js.map +1 -0
- package/dist/1311.js +1 -0
- package/dist/1311.js.map +1 -0
- package/dist/1442.js +1 -0
- package/dist/1442.js.map +1 -0
- package/dist/1462.js +1 -0
- package/dist/1462.js.map +1 -0
- package/dist/1469.js +1 -0
- package/dist/1469.js.map +1 -0
- package/dist/1506.js +13 -0
- package/dist/1506.js.map +1 -0
- package/dist/1718.js +1 -0
- package/dist/1718.js.map +1 -0
- package/dist/1722.js +1 -0
- package/dist/1722.js.map +1 -0
- package/dist/1772.js +1 -0
- package/dist/1772.js.map +1 -0
- package/dist/1889.js +1 -0
- package/dist/1889.js.map +1 -0
- package/dist/1972.js +1 -0
- package/dist/1972.js.map +1 -0
- package/dist/1990.js +1 -0
- package/dist/1990.js.map +1 -0
- package/dist/2016.js +1 -0
- package/dist/2016.js.map +1 -0
- package/dist/2080.js +1 -0
- package/dist/2080.js.map +1 -0
- package/dist/2096.js +1 -0
- package/dist/2096.js.map +1 -0
- package/dist/2153.js +1 -0
- package/dist/2153.js.map +1 -0
- package/dist/216.js +1 -0
- package/dist/216.js.map +1 -0
- package/dist/2270.js +1 -0
- package/dist/2270.js.map +1 -0
- package/dist/2294.js +1 -0
- package/dist/2294.js.map +1 -0
- package/dist/2345.js +1 -0
- package/dist/2345.js.map +1 -0
- package/dist/2467.js +1 -0
- package/dist/2467.js.map +1 -0
- package/dist/2500.js +1 -0
- package/dist/2500.js.map +1 -0
- package/dist/251.js +1 -0
- package/dist/251.js.map +1 -0
- package/dist/257.js +1 -0
- package/dist/257.js.map +1 -0
- package/dist/2586.js +1 -0
- package/dist/2586.js.map +1 -0
- package/dist/2625.js +1 -0
- package/dist/2625.js.map +1 -0
- package/dist/2652.js +1 -0
- package/dist/2652.js.map +1 -0
- package/dist/2685.js +1 -0
- package/dist/2685.js.map +1 -0
- package/dist/2948.js +1 -0
- package/dist/2948.js.map +1 -0
- package/dist/3089.js +1 -0
- package/dist/3089.js.map +1 -0
- package/dist/3190.js +1 -0
- package/dist/3190.js.map +1 -0
- package/dist/3224.js +1 -0
- package/dist/3224.js.map +1 -0
- package/dist/3380.js +1 -0
- package/dist/3380.js.map +1 -0
- package/dist/3548.js +1 -0
- package/dist/3548.js.map +1 -0
- package/dist/3571.js +1 -0
- package/dist/3571.js.map +1 -0
- package/dist/3691.js +1 -0
- package/dist/3691.js.map +1 -0
- package/dist/3775.js +1 -0
- package/dist/3775.js.map +1 -0
- package/dist/3816.js +1 -0
- package/dist/3816.js.map +1 -0
- package/dist/3906.js +1 -0
- package/dist/3906.js.map +1 -0
- package/dist/3963.js +1 -0
- package/dist/3963.js.map +1 -0
- package/dist/405.js +1 -0
- package/dist/405.js.map +1 -0
- package/dist/4296.js +1 -0
- package/dist/4296.js.map +1 -0
- package/dist/4337.js +1 -0
- package/dist/4337.js.map +1 -0
- package/dist/4584.js +1 -0
- package/dist/4584.js.map +1 -0
- package/dist/4687.js +1 -0
- package/dist/4687.js.map +1 -0
- package/dist/4735.js +1 -0
- package/dist/4735.js.map +1 -0
- package/dist/4744.js +1 -0
- package/dist/4744.js.map +1 -0
- package/dist/4813.js +2 -0
- package/dist/4813.js.map +1 -0
- package/dist/4858.js +1 -0
- package/dist/4858.js.map +1 -0
- package/dist/487.js +1 -0
- package/dist/487.js.map +1 -0
- package/dist/4970.js +1 -0
- package/dist/4970.js.map +1 -0
- package/dist/5202.js +1 -0
- package/dist/5202.js.map +1 -0
- package/dist/5294.js +1 -0
- package/dist/5294.js.map +1 -0
- package/dist/5297.js +1 -0
- package/dist/5297.js.map +1 -0
- package/dist/545.js +1 -0
- package/dist/545.js.map +1 -0
- package/dist/5592.js +1 -0
- package/dist/5592.js.map +1 -0
- package/dist/5669.js +1 -0
- package/dist/5669.js.map +1 -0
- package/dist/5884.js +1 -0
- package/dist/5884.js.map +1 -0
- package/dist/5910.js +1 -0
- package/dist/5910.js.map +1 -0
- package/dist/5940.js +1 -0
- package/dist/5940.js.map +1 -0
- package/dist/6155.js +1 -0
- package/dist/6155.js.map +1 -0
- package/dist/6178.js +1 -0
- package/dist/6178.js.map +1 -0
- package/dist/6253.js +1 -0
- package/dist/6253.js.map +1 -0
- package/dist/6455.js +1 -0
- package/dist/6455.js.map +1 -0
- package/dist/6456.js +1 -0
- package/dist/6466.js +3 -0
- package/dist/6466.js.map +1 -0
- package/dist/6492.js +1 -0
- package/dist/6492.js.map +1 -0
- package/dist/6800.js +1 -0
- package/dist/6800.js.map +1 -0
- package/dist/6925.js +1 -0
- package/dist/6925.js.map +1 -0
- package/dist/7005.js +1 -0
- package/dist/7005.js.map +1 -0
- package/dist/7201.js +1 -0
- package/dist/7201.js.map +1 -0
- package/dist/7210.js +1 -0
- package/dist/7210.js.map +1 -0
- package/dist/7234.js +1 -0
- package/dist/7234.js.map +1 -0
- package/dist/7261.js +1 -0
- package/dist/7261.js.map +1 -0
- package/dist/7326.js +1 -0
- package/dist/7463.js +1 -0
- package/dist/7463.js.map +1 -0
- package/dist/7528.js +1 -0
- package/dist/7528.js.map +1 -0
- package/dist/7607.js +1 -0
- package/dist/7717.js +1 -0
- package/dist/7717.js.map +1 -0
- package/dist/7737.js +1 -0
- package/dist/7737.js.map +1 -0
- package/dist/7739.js +1 -0
- package/dist/7739.js.map +1 -0
- package/dist/7765.js +1 -0
- package/dist/7765.js.map +1 -0
- package/dist/7820.js +1 -0
- package/dist/7820.js.map +1 -0
- package/dist/7844.js +1 -0
- package/dist/7844.js.map +1 -0
- package/dist/7866.js +1 -0
- package/dist/7866.js.map +1 -0
- package/dist/7971.js +1 -0
- package/dist/7971.js.map +1 -0
- package/dist/8159.js +7 -0
- package/dist/8159.js.map +1 -0
- package/dist/8206.js +1 -0
- package/dist/8206.js.map +1 -0
- package/dist/8244.js +1 -0
- package/dist/8244.js.map +1 -0
- package/dist/8262.js +1 -0
- package/dist/8262.js.map +1 -0
- package/dist/8376.js +1 -0
- package/dist/8376.js.map +1 -0
- package/dist/845.js +1 -0
- package/dist/845.js.map +1 -0
- package/dist/846.js +17 -0
- package/dist/846.js.map +1 -0
- package/dist/8487.js +1 -0
- package/dist/8487.js.map +1 -0
- package/dist/8528.js +1 -0
- package/dist/8528.js.map +1 -0
- package/dist/8570.js +1 -0
- package/dist/8570.js.map +1 -0
- package/dist/87.js +1 -0
- package/dist/87.js.map +1 -0
- package/dist/8727.js +1 -0
- package/dist/8828.js +1 -0
- package/dist/8828.js.map +1 -0
- package/dist/8860.js +1 -0
- package/dist/8860.js.map +1 -0
- package/dist/9036.js +1 -0
- package/dist/9036.js.map +1 -0
- package/dist/9124.js +1 -0
- package/dist/9124.js.map +1 -0
- package/dist/9182.js +1 -0
- package/dist/921.js +1 -0
- package/dist/921.js.map +1 -0
- package/dist/9404.js +1 -0
- package/dist/9404.js.map +1 -0
- package/dist/9446.js +1 -0
- package/dist/9446.js.map +1 -0
- package/dist/9449.js +1 -0
- package/dist/9449.js.map +1 -0
- package/dist/9566.js +5 -0
- package/dist/9566.js.map +1 -0
- package/dist/9585.js +1 -0
- package/dist/9585.js.map +1 -0
- package/dist/9641.js +1 -0
- package/dist/9641.js.map +1 -0
- package/dist/9647.js +1 -0
- package/dist/9647.js.map +1 -0
- package/dist/9801.js +1 -0
- package/dist/9801.js.map +1 -0
- package/dist/9835.js +11 -0
- package/dist/9835.js.map +1 -0
- package/dist/kenyaemr-esm-admin-app.js +5 -5
- package/dist/kenyaemr-esm-admin-app.js.buildmanifest.json +2672 -154
- package/dist/kenyaemr-esm-admin-app.js.map +1 -1
- package/dist/main.js +5 -31
- package/dist/main.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +5 -7
- package/rspack.config.js +1 -1
- package/src/components/confirm-modal/confirmation-operation.test.tsx +8 -19
- package/src/components/dashboard/dashboard.component.tsx +4 -1
- package/src/components/empty-state/empty-state-log.test.tsx +3 -4
- package/src/components/facility-setup/constant/index.ts +3 -0
- package/src/components/facility-setup/facility-info.component.tsx +247 -108
- package/src/components/facility-setup/facility-info.scss +136 -55
- package/src/components/facility-setup/facility-setup.component.tsx +2 -2
- package/src/components/facility-setup/header/header.component.tsx +4 -10
- package/src/components/facility-setup/header/header.scss +3 -9
- package/src/components/facility-setup/shared/custom-info.component.tsx +9 -0
- package/src/components/facility-setup/shared/custom-section-card.component.tsx +10 -0
- package/src/components/facility-setup/shared/custom-status-tag.component.tsx +22 -0
- package/src/components/facility-setup/type/index.ts +61 -0
- package/src/components/facility-setup/useFacilityRegistry.ts +29 -0
- package/src/components/global-property/dashboard/global-property-dashboard.component.tsx +23 -0
- package/src/components/global-property/dashboard/global-property-dashboard.scss +6 -0
- package/src/components/global-property/hooks/useGlobalProperty.ts +64 -0
- package/src/components/global-property/index.ts +14 -0
- package/src/components/global-property/modal/delete-global-property-modal.component.tsx +71 -0
- package/src/components/global-property/modal/delete-global-property-modal.test.tsx +131 -0
- package/src/components/global-property/table/global-property-table.component.tsx +249 -0
- package/src/components/global-property/table/global-property-table.scss +34 -0
- package/src/components/global-property/table/global-property-table.test.tsx +198 -0
- package/src/components/global-property/workspace/global-property-form-schema.ts +32 -0
- package/src/components/global-property/workspace/global-property.workspace.scss +40 -0
- package/src/components/global-property/workspace/global-property.workspace.test.tsx +172 -0
- package/src/components/global-property/workspace/global-property.workspace.tsx +260 -0
- package/src/components/hook/healthWorkerRegistry.ts +78 -0
- package/src/components/hook/useProfessionalRegistryEnums.ts +59 -0
- package/src/components/locations/forms/add-location/add-location.workspace.tsx +96 -95
- package/src/components/locations/forms/search-location/search-location.workspace.tsx +90 -85
- package/src/components/locations/tables/locations-table.component.tsx +117 -121
- package/src/components/logs-table/operation-log-table.component.tsx +87 -75
- package/src/components/logs-table/operation-log.test.tsx +134 -28
- package/src/components/modal/hwr-confirmation.modal.scss +80 -4
- package/src/components/modal/hwr-confirmation.modal.tsx +118 -128
- package/src/components/modal/hwr-sync.modal.tsx +194 -106
- package/src/components/users/manage-users/manage-user-role-scope/user-role-scope-workspace/user-role-scope.workspace.tsx +13 -13
- package/src/components/users/manage-users/user-details/user-detail.scss +167 -39
- package/src/components/users/manage-users/user-details/user-details.component.tsx +130 -122
- package/src/components/users/manage-users/user-list/user-list.component.tsx +22 -9
- package/src/components/users/manage-users/user-management.workspace.scss +233 -95
- package/src/components/users/manage-users/user-management.workspace.tsx +800 -687
- package/src/components/users/userManagementFormSchema.tsx +17 -8
- package/src/config-schema.ts +48 -68
- package/src/index.ts +64 -31
- package/src/left-pannel-link.component.tsx +5 -3
- package/src/root.component.tsx +13 -13
- package/src/routes.json +57 -38
- package/src/types/index.ts +40 -3
- package/translations/am.json +196 -13
- package/translations/en.json +207 -24
- package/translations/fr.json +243 -58
- package/translations/sw.json +312 -129
- package/tsconfig.json +1 -1
- package/dist/127.js +0 -1
- package/dist/267.js +0 -1
- package/dist/267.js.map +0 -1
- package/dist/281.js +0 -15
- package/dist/281.js.map +0 -1
- package/dist/329.js +0 -1
- package/dist/329.js.map +0 -1
- package/dist/40.js +0 -1
- package/dist/466.js +0 -1
- package/dist/466.js.map +0 -1
- package/dist/472.js +0 -1
- package/dist/472.js.map +0 -1
- package/dist/478.js +0 -1
- package/dist/478.js.map +0 -1
- package/dist/585.js +0 -1
- package/dist/585.js.map +0 -1
- package/dist/630.js +0 -1
- package/dist/630.js.map +0 -1
- package/dist/675.js +0 -1
- package/dist/675.js.map +0 -1
- package/dist/689.js +0 -1
- package/dist/689.js.map +0 -1
- package/dist/706.js +0 -27
- package/dist/706.js.map +0 -1
- package/dist/729.js +0 -17
- package/dist/729.js.map +0 -1
- package/dist/774.js +0 -1
- package/dist/774.js.map +0 -1
- package/dist/847.js +0 -1
- package/dist/847.js.map +0 -1
- package/dist/85.js +0 -1
- package/dist/85.js.map +0 -1
- package/dist/882.js +0 -1
- package/dist/91.js +0 -1
- package/dist/91.js.map +0 -1
- package/dist/916.js +0 -1
- package/dist/998.js +0 -1
- package/dist/998.js.map +0 -1
- package/jest.config.js +0 -8
- package/src/components/facility-setup/card.component.tsx +0 -16
- package/src/components/facility-setup/facility-setup.resource.tsx +0 -7
- package/src/components/hook/healthWorkerAdapter.ts +0 -213
- package/src/components/hook/useFacilityInfo.tsx +0 -37
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
|
6
|
+
import GlobalPropertyWorkspace from './global-property.workspace';
|
|
7
|
+
|
|
8
|
+
const mockShowSnackbar = vi.fn();
|
|
9
|
+
const mockSaveOrUpdateGlobalProperty = vi.fn();
|
|
10
|
+
const mockCloseWorkspace = vi.fn();
|
|
11
|
+
const mockMutateGlobalProperty = vi.fn();
|
|
12
|
+
|
|
13
|
+
vi.mock('react-i18next', () => ({
|
|
14
|
+
useTranslation: () => ({ t: (_key: string, fallback: string) => fallback }),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
vi.mock('@openmrs/esm-framework', () => ({
|
|
18
|
+
useLayoutType: vi.fn(() => 'desktop'),
|
|
19
|
+
showSnackbar: (...args: unknown[]) => mockShowSnackbar(...args),
|
|
20
|
+
ResponsiveWrapper: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
|
21
|
+
Workspace2: ({ children, title }: { children: React.ReactNode; title: string }) => (
|
|
22
|
+
<div>
|
|
23
|
+
<h2>{title}</h2>
|
|
24
|
+
{children}
|
|
25
|
+
</div>
|
|
26
|
+
),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
vi.mock('../hooks/useGlobalProperty', () => ({
|
|
30
|
+
saveOrUpdateGlobalProperty: (...args: unknown[]) => mockSaveOrUpdateGlobalProperty(...args),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
vi.mock('@hookform/resolvers/zod', () => ({
|
|
34
|
+
zodResolver: () => async (values: unknown) => ({ values, errors: {} }),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const baseProps = {
|
|
38
|
+
closeWorkspace: mockCloseWorkspace,
|
|
39
|
+
workspaceProps: {
|
|
40
|
+
systemSetting: null,
|
|
41
|
+
mutateGlobalProperty: mockMutateGlobalProperty,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
describe('GlobalPropertyWorkspace', () => {
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
vi.clearAllMocks();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('shows "Add global property" title in add mode', () => {
|
|
51
|
+
render(<GlobalPropertyWorkspace {...baseProps} />);
|
|
52
|
+
expect(screen.getByText('Add global property')).toBeInTheDocument();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('shows "Edit global property" title when editing an existing property', () => {
|
|
56
|
+
const props = {
|
|
57
|
+
...baseProps,
|
|
58
|
+
workspaceProps: {
|
|
59
|
+
systemSetting: { uuid: 'uuid-1', property: 'setting.one', value: 'value1' },
|
|
60
|
+
mutateGlobalProperty: mockMutateGlobalProperty,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
render(<GlobalPropertyWorkspace {...props} />);
|
|
64
|
+
expect(screen.getByText('Edit global property')).toBeInTheDocument();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('pre-fills form fields when editing an existing property', () => {
|
|
68
|
+
const props = {
|
|
69
|
+
...baseProps,
|
|
70
|
+
workspaceProps: {
|
|
71
|
+
systemSetting: { uuid: 'uuid-1', property: 'my.setting', value: 'my-value' },
|
|
72
|
+
mutateGlobalProperty: mockMutateGlobalProperty,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
render(<GlobalPropertyWorkspace {...props} />);
|
|
76
|
+
expect(screen.getByDisplayValue('my.setting')).toBeInTheDocument();
|
|
77
|
+
expect(screen.getByDisplayValue('my-value')).toBeInTheDocument();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('disables the property field when editing an existing property', () => {
|
|
81
|
+
const props = {
|
|
82
|
+
...baseProps,
|
|
83
|
+
workspaceProps: {
|
|
84
|
+
systemSetting: { uuid: 'uuid-1', property: 'setting.one', value: 'value1' },
|
|
85
|
+
mutateGlobalProperty: mockMutateGlobalProperty,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
render(<GlobalPropertyWorkspace {...props} />);
|
|
89
|
+
expect(screen.getByLabelText(/Property/i)).toBeDisabled();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('enables the property field in add mode', () => {
|
|
93
|
+
render(<GlobalPropertyWorkspace {...baseProps} />);
|
|
94
|
+
expect(screen.getByLabelText(/Property/i)).not.toBeDisabled();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('renders the Cancel and Save & close buttons', () => {
|
|
98
|
+
render(<GlobalPropertyWorkspace {...baseProps} />);
|
|
99
|
+
expect(screen.getByText('Cancel')).toBeInTheDocument();
|
|
100
|
+
expect(screen.getByText('Save & close')).toBeInTheDocument();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('calls closeWorkspace when Cancel is clicked', () => {
|
|
104
|
+
render(<GlobalPropertyWorkspace {...baseProps} />);
|
|
105
|
+
fireEvent.click(screen.getByText('Cancel'));
|
|
106
|
+
expect(mockCloseWorkspace).toHaveBeenCalledTimes(1);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('shows validation error when form is submitted with empty required fields', async () => {
|
|
110
|
+
render(<GlobalPropertyWorkspace {...baseProps} />);
|
|
111
|
+
const saveButton = screen.getByText('Save & close');
|
|
112
|
+
fireEvent.click(saveButton);
|
|
113
|
+
await waitFor(() => {
|
|
114
|
+
expect(mockSaveOrUpdateGlobalProperty).not.toHaveBeenCalled();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('saves a new property with the entered values', async () => {
|
|
119
|
+
mockSaveOrUpdateGlobalProperty.mockResolvedValue(undefined);
|
|
120
|
+
render(<GlobalPropertyWorkspace {...baseProps} />);
|
|
121
|
+
|
|
122
|
+
await userEvent.type(screen.getByLabelText(/Property/i), 'new.setting');
|
|
123
|
+
await userEvent.type(screen.getByLabelText(/Value/i), 'new-value');
|
|
124
|
+
|
|
125
|
+
fireEvent.submit(screen.getByLabelText(/Property/i).closest('form')!);
|
|
126
|
+
|
|
127
|
+
await waitFor(() => {
|
|
128
|
+
expect(mockSaveOrUpdateGlobalProperty).toHaveBeenCalledWith(
|
|
129
|
+
expect.objectContaining({ property: 'new.setting', value: 'new-value' }),
|
|
130
|
+
undefined,
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('shows a success snackbar and closes workspace after saving', async () => {
|
|
136
|
+
mockSaveOrUpdateGlobalProperty.mockResolvedValue(undefined);
|
|
137
|
+
render(<GlobalPropertyWorkspace {...baseProps} />);
|
|
138
|
+
|
|
139
|
+
await userEvent.type(screen.getByLabelText(/Property/i), 'new.setting');
|
|
140
|
+
await userEvent.type(screen.getByLabelText(/Value/i), 'new-value');
|
|
141
|
+
|
|
142
|
+
fireEvent.submit(screen.getByLabelText(/Property/i).closest('form')!);
|
|
143
|
+
|
|
144
|
+
await waitFor(() => {
|
|
145
|
+
expect(mockShowSnackbar).toHaveBeenCalledWith(expect.objectContaining({ kind: 'success' }));
|
|
146
|
+
expect(mockMutateGlobalProperty).toHaveBeenCalled();
|
|
147
|
+
expect(mockCloseWorkspace).toHaveBeenCalled();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('shows an error snackbar when saving fails', async () => {
|
|
152
|
+
mockSaveOrUpdateGlobalProperty.mockRejectedValue(new Error('Failed to save'));
|
|
153
|
+
render(<GlobalPropertyWorkspace {...baseProps} />);
|
|
154
|
+
|
|
155
|
+
await userEvent.type(screen.getByLabelText(/Property/i), 'new.setting');
|
|
156
|
+
await userEvent.type(screen.getByLabelText(/Value/i), 'new-value');
|
|
157
|
+
|
|
158
|
+
fireEvent.submit(screen.getByLabelText(/Property/i).closest('form')!);
|
|
159
|
+
|
|
160
|
+
await waitFor(() => {
|
|
161
|
+
expect(mockShowSnackbar).toHaveBeenCalledWith(expect.objectContaining({ kind: 'error' }));
|
|
162
|
+
expect(mockCloseWorkspace).not.toHaveBeenCalled();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('renders optional fields: description, datatype config, handler config', () => {
|
|
167
|
+
render(<GlobalPropertyWorkspace {...baseProps} />);
|
|
168
|
+
expect(screen.getByLabelText(/Description/i)).toBeInTheDocument();
|
|
169
|
+
expect(screen.getByLabelText(/Datatype config/i)).toBeInTheDocument();
|
|
170
|
+
expect(screen.getByLabelText(/Handler config/i)).toBeInTheDocument();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ResponsiveWrapper,
|
|
4
|
+
Workspace2,
|
|
5
|
+
showSnackbar,
|
|
6
|
+
useLayoutType,
|
|
7
|
+
type Workspace2DefinitionProps,
|
|
8
|
+
} from '@openmrs/esm-framework';
|
|
9
|
+
import { useTranslation } from 'react-i18next';
|
|
10
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
11
|
+
import { Button, ButtonSet, ComboBox, Form, FormGroup, InlineLoading, Stack, TextArea, TextInput } from '@carbon/react';
|
|
12
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
13
|
+
import classNames from 'classnames';
|
|
14
|
+
|
|
15
|
+
import styles from './global-property.workspace.scss';
|
|
16
|
+
import { type SystemSettings } from '../../../types';
|
|
17
|
+
import { saveOrUpdateGlobalProperty } from '../hooks/useGlobalProperty';
|
|
18
|
+
import {
|
|
19
|
+
createGlobalPropertyFormSchema,
|
|
20
|
+
openmrsCustomDatatypes,
|
|
21
|
+
type GlobalPropertyFormType,
|
|
22
|
+
} from './global-property-form-schema';
|
|
23
|
+
|
|
24
|
+
type GlobalPropertyWorkspaceProps = {
|
|
25
|
+
systemSetting?: SystemSettings | null;
|
|
26
|
+
mutateGlobalProperty: () => void;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const GlobalPropertyWorkspace: React.FC<Workspace2DefinitionProps<GlobalPropertyWorkspaceProps, {}, {}>> = ({
|
|
30
|
+
closeWorkspace,
|
|
31
|
+
workspaceProps: { systemSetting, mutateGlobalProperty },
|
|
32
|
+
}) => {
|
|
33
|
+
const { t } = useTranslation();
|
|
34
|
+
const isTablet = useLayoutType() === 'tablet';
|
|
35
|
+
const isEditMode = Boolean(systemSetting?.uuid);
|
|
36
|
+
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
handleSubmit,
|
|
40
|
+
control,
|
|
41
|
+
formState: { isSubmitting, isDirty, errors },
|
|
42
|
+
} = useForm<GlobalPropertyFormType>({
|
|
43
|
+
resolver: zodResolver(createGlobalPropertyFormSchema(t)),
|
|
44
|
+
defaultValues: {
|
|
45
|
+
property: systemSetting?.property ?? '',
|
|
46
|
+
description: systemSetting?.description ?? '',
|
|
47
|
+
datatypeClassname: systemSetting?.datatypeClassname ?? '',
|
|
48
|
+
datatypeConfig: systemSetting?.datatypeConfig ?? '',
|
|
49
|
+
preferredHandlerClassname: systemSetting?.preferredHandlerClassname ?? '',
|
|
50
|
+
handlerConfig: systemSetting?.handlerConfig ?? '',
|
|
51
|
+
value: systemSetting?.value ?? '',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
setHasUnsavedChanges(isDirty);
|
|
57
|
+
}, [isDirty]);
|
|
58
|
+
|
|
59
|
+
const onSubmit = async (data: GlobalPropertyFormType) => {
|
|
60
|
+
const payload = {
|
|
61
|
+
property: data.property,
|
|
62
|
+
value: data.value,
|
|
63
|
+
description: data.description,
|
|
64
|
+
datatypeClassname: data.datatypeClassname,
|
|
65
|
+
datatypeConfig: data.datatypeConfig,
|
|
66
|
+
preferredHandlerClassname: data.preferredHandlerClassname,
|
|
67
|
+
handlerConfig: data.handlerConfig,
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
await saveOrUpdateGlobalProperty(payload, systemSetting?.uuid);
|
|
71
|
+
|
|
72
|
+
showSnackbar({
|
|
73
|
+
title: t('success', 'Success'),
|
|
74
|
+
kind: 'success',
|
|
75
|
+
subtitle: isEditMode
|
|
76
|
+
? t('gpUpdated', 'Global property {{property}} was updated successfully.', { property: data.property })
|
|
77
|
+
: t('gpCreated', 'Global property {{property}} was created successfully.', { property: data.property }),
|
|
78
|
+
});
|
|
79
|
+
mutateGlobalProperty();
|
|
80
|
+
closeWorkspace({ discardUnsavedChanges: true });
|
|
81
|
+
} catch (error: any) {
|
|
82
|
+
showSnackbar({
|
|
83
|
+
title: t('error', 'Error'),
|
|
84
|
+
kind: 'error',
|
|
85
|
+
subtitle: error?.message ?? t('gpSaveError', 'Error saving global property'),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const title = isEditMode
|
|
91
|
+
? t('editGlobalProperty', 'Edit global property')
|
|
92
|
+
: t('addGlobalProperty', 'Add global property');
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<Workspace2 title={title} hasUnsavedChanges={hasUnsavedChanges}>
|
|
96
|
+
<Form onSubmit={handleSubmit(onSubmit)} className={styles.form}>
|
|
97
|
+
<div className={styles.formContainer}>
|
|
98
|
+
<Stack gap={4}>
|
|
99
|
+
<ResponsiveWrapper>
|
|
100
|
+
<FormGroup legendText="">
|
|
101
|
+
<Controller
|
|
102
|
+
control={control}
|
|
103
|
+
name="property"
|
|
104
|
+
render={({ field }) => (
|
|
105
|
+
<TextInput
|
|
106
|
+
id="gpProperty"
|
|
107
|
+
labelText={t('property', 'Property (required)')}
|
|
108
|
+
placeholder={t('gpPropertyPlaceholder', 'e.g. setting.name')}
|
|
109
|
+
value={field.value}
|
|
110
|
+
onChange={field.onChange}
|
|
111
|
+
invalid={!!errors.property}
|
|
112
|
+
invalidText={errors.property?.message}
|
|
113
|
+
disabled={isEditMode}
|
|
114
|
+
/>
|
|
115
|
+
)}
|
|
116
|
+
/>
|
|
117
|
+
</FormGroup>
|
|
118
|
+
</ResponsiveWrapper>
|
|
119
|
+
|
|
120
|
+
<ResponsiveWrapper>
|
|
121
|
+
<FormGroup legendText="">
|
|
122
|
+
<Controller
|
|
123
|
+
control={control}
|
|
124
|
+
name="value"
|
|
125
|
+
render={({ field }) => (
|
|
126
|
+
<TextArea
|
|
127
|
+
id="gpValue"
|
|
128
|
+
labelText={t('value', 'Value (required)')}
|
|
129
|
+
placeholder={t('gpValuePlaceholder', 'Enter value')}
|
|
130
|
+
value={field.value}
|
|
131
|
+
onChange={field.onChange}
|
|
132
|
+
invalid={!!errors.value}
|
|
133
|
+
invalidText={errors.value?.message}
|
|
134
|
+
rows={3}
|
|
135
|
+
/>
|
|
136
|
+
)}
|
|
137
|
+
/>
|
|
138
|
+
</FormGroup>
|
|
139
|
+
</ResponsiveWrapper>
|
|
140
|
+
|
|
141
|
+
<ResponsiveWrapper>
|
|
142
|
+
<FormGroup legendText="">
|
|
143
|
+
<Controller
|
|
144
|
+
control={control}
|
|
145
|
+
name="description"
|
|
146
|
+
render={({ field }) => (
|
|
147
|
+
<TextArea
|
|
148
|
+
id="gpDescription"
|
|
149
|
+
labelText={t('description', 'Description')}
|
|
150
|
+
placeholder={t('gpDescriptionPlaceholder', 'Optional description')}
|
|
151
|
+
value={field.value ?? ''}
|
|
152
|
+
onChange={field.onChange}
|
|
153
|
+
rows={2}
|
|
154
|
+
/>
|
|
155
|
+
)}
|
|
156
|
+
/>
|
|
157
|
+
</FormGroup>
|
|
158
|
+
</ResponsiveWrapper>
|
|
159
|
+
|
|
160
|
+
<ResponsiveWrapper>
|
|
161
|
+
<FormGroup legendText="">
|
|
162
|
+
<Controller
|
|
163
|
+
control={control}
|
|
164
|
+
name="datatypeClassname"
|
|
165
|
+
render={({ field }) => (
|
|
166
|
+
<ComboBox
|
|
167
|
+
id="datatypeClassname"
|
|
168
|
+
invalidText={errors.datatypeClassname?.message}
|
|
169
|
+
items={openmrsCustomDatatypes}
|
|
170
|
+
onChange={function Zye() {}}
|
|
171
|
+
titleText={t('datatypeClassname', 'Datatype classname')}
|
|
172
|
+
typeahead
|
|
173
|
+
placeholder={t('selectDatatypeClassname', 'Select datatype classname')}
|
|
174
|
+
/>
|
|
175
|
+
)}
|
|
176
|
+
/>
|
|
177
|
+
</FormGroup>
|
|
178
|
+
</ResponsiveWrapper>
|
|
179
|
+
|
|
180
|
+
<ResponsiveWrapper>
|
|
181
|
+
<FormGroup legendText="">
|
|
182
|
+
<Controller
|
|
183
|
+
control={control}
|
|
184
|
+
name="datatypeConfig"
|
|
185
|
+
render={({ field }) => (
|
|
186
|
+
<TextInput
|
|
187
|
+
id="gpDatatypeConfig"
|
|
188
|
+
labelText={t('datatypeConfig', 'Datatype config')}
|
|
189
|
+
placeholder={t('gpDatatypeConfigPlaceholder', 'Optional datatype configuration')}
|
|
190
|
+
value={field.value ?? ''}
|
|
191
|
+
onChange={field.onChange}
|
|
192
|
+
/>
|
|
193
|
+
)}
|
|
194
|
+
/>
|
|
195
|
+
</FormGroup>
|
|
196
|
+
</ResponsiveWrapper>
|
|
197
|
+
|
|
198
|
+
<ResponsiveWrapper>
|
|
199
|
+
<FormGroup legendText="">
|
|
200
|
+
<Controller
|
|
201
|
+
control={control}
|
|
202
|
+
name="preferredHandlerClassname"
|
|
203
|
+
render={({ field }) => (
|
|
204
|
+
<TextInput
|
|
205
|
+
id="gpPreferredHandlerClassname"
|
|
206
|
+
labelText={t('preferredHandlerClassname', 'Preferred handler classname')}
|
|
207
|
+
placeholder={t('gpPreferredHandlerPlaceholder', 'Optional preferred handler classname')}
|
|
208
|
+
value={field.value ?? ''}
|
|
209
|
+
onChange={field.onChange}
|
|
210
|
+
/>
|
|
211
|
+
)}
|
|
212
|
+
/>
|
|
213
|
+
</FormGroup>
|
|
214
|
+
</ResponsiveWrapper>
|
|
215
|
+
|
|
216
|
+
<ResponsiveWrapper>
|
|
217
|
+
<FormGroup legendText="">
|
|
218
|
+
<Controller
|
|
219
|
+
control={control}
|
|
220
|
+
name="handlerConfig"
|
|
221
|
+
render={({ field }) => (
|
|
222
|
+
<TextInput
|
|
223
|
+
id="gpHandlerConfig"
|
|
224
|
+
labelText={t('handlerConfig', 'Handler config')}
|
|
225
|
+
placeholder={t('gpHandlerConfigPlaceholder', 'Optional handler configuration')}
|
|
226
|
+
value={field.value ?? ''}
|
|
227
|
+
onChange={field.onChange}
|
|
228
|
+
/>
|
|
229
|
+
)}
|
|
230
|
+
/>
|
|
231
|
+
</FormGroup>
|
|
232
|
+
</ResponsiveWrapper>
|
|
233
|
+
</Stack>
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
<ButtonSet
|
|
237
|
+
className={classNames({
|
|
238
|
+
[styles.tablet]: isTablet,
|
|
239
|
+
[styles.desktop]: !isTablet,
|
|
240
|
+
})}>
|
|
241
|
+
<Button className={styles.buttonContainer} kind="secondary" onClick={() => closeWorkspace()}>
|
|
242
|
+
{t('cancel', 'Cancel')}
|
|
243
|
+
</Button>
|
|
244
|
+
<Button className={styles.buttonContainer} disabled={isSubmitting || !isDirty} kind="primary" type="submit">
|
|
245
|
+
{isSubmitting ? (
|
|
246
|
+
<span className={styles.inlineLoading}>
|
|
247
|
+
{t('submitting', 'Submitting...')}
|
|
248
|
+
<InlineLoading status="active" iconDescription="Loading" />
|
|
249
|
+
</span>
|
|
250
|
+
) : (
|
|
251
|
+
t('saveAndClose', 'Save & close')
|
|
252
|
+
)}
|
|
253
|
+
</Button>
|
|
254
|
+
</ButtonSet>
|
|
255
|
+
</Form>
|
|
256
|
+
</Workspace2>
|
|
257
|
+
);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
export default GlobalPropertyWorkspace;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
|
|
2
|
+
import useSWR from 'swr';
|
|
3
|
+
import { HWR_API_NO_CREDENTIALS, PROVIDER_NOT_FOUND, RESOURCE_NOT_FOUND, UNKNOWN } from '../../constants';
|
|
4
|
+
|
|
5
|
+
export interface ProfessionalRegistryResponse {
|
|
6
|
+
success: boolean;
|
|
7
|
+
regulator: string;
|
|
8
|
+
identification_type: string;
|
|
9
|
+
identification_number: string;
|
|
10
|
+
professional: {
|
|
11
|
+
membership: {
|
|
12
|
+
id: string;
|
|
13
|
+
full_name: string;
|
|
14
|
+
gender: string;
|
|
15
|
+
first_name: string;
|
|
16
|
+
middle_name: string;
|
|
17
|
+
last_name: string;
|
|
18
|
+
registration_id: string;
|
|
19
|
+
external_reference_id: string;
|
|
20
|
+
licensing_body: string;
|
|
21
|
+
specialty: string;
|
|
22
|
+
is_active: number;
|
|
23
|
+
};
|
|
24
|
+
licenses?: Array<{
|
|
25
|
+
id: string;
|
|
26
|
+
external_reference_id: string;
|
|
27
|
+
license_type: string;
|
|
28
|
+
license_start: string;
|
|
29
|
+
license_end: string;
|
|
30
|
+
}>;
|
|
31
|
+
professional_details?: {
|
|
32
|
+
professional_cadre?: string;
|
|
33
|
+
practice_type?: string;
|
|
34
|
+
educational_qualifications?: string;
|
|
35
|
+
};
|
|
36
|
+
contacts?: {
|
|
37
|
+
phone?: string;
|
|
38
|
+
email?: string;
|
|
39
|
+
postal_address?: string;
|
|
40
|
+
};
|
|
41
|
+
identifiers?: {
|
|
42
|
+
identification_type?: string;
|
|
43
|
+
identification_number?: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const searchHealthCareWork = async (
|
|
49
|
+
identifierType: string,
|
|
50
|
+
identifierNumber: string,
|
|
51
|
+
regulator: string,
|
|
52
|
+
): Promise<ProfessionalRegistryResponse> => {
|
|
53
|
+
const url = `${restBaseUrl}/virtualclaims/professional-registry?${new URLSearchParams({
|
|
54
|
+
identification_number: identifierNumber,
|
|
55
|
+
identification_type: identifierType,
|
|
56
|
+
regulator,
|
|
57
|
+
}).toString()}`;
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const response = await openmrsFetch<ProfessionalRegistryResponse>(url);
|
|
61
|
+
if (!response.data?.success || !response.data?.professional) {
|
|
62
|
+
throw new Error(PROVIDER_NOT_FOUND);
|
|
63
|
+
}
|
|
64
|
+
return response.data;
|
|
65
|
+
} catch (err: any) {
|
|
66
|
+
if (err?.message === PROVIDER_NOT_FOUND) {
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
const status = err?.response?.status;
|
|
70
|
+
if (status === 401) {
|
|
71
|
+
throw new Error(HWR_API_NO_CREDENTIALS);
|
|
72
|
+
}
|
|
73
|
+
if (status === 404) {
|
|
74
|
+
throw new Error(RESOURCE_NOT_FOUND);
|
|
75
|
+
}
|
|
76
|
+
throw new Error(UNKNOWN);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { FetchResponse, openmrsFetch, restBaseUrl, useSession } from '@openmrs/esm-framework';
|
|
2
|
+
import useSWR from 'swr';
|
|
3
|
+
|
|
4
|
+
export type EnumEntry = {
|
|
5
|
+
code: string;
|
|
6
|
+
label: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type RegulatorsResponse = {
|
|
10
|
+
count: number;
|
|
11
|
+
regulators: Array<EnumEntry>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type IdentificationTypesResponse = {
|
|
15
|
+
count: number;
|
|
16
|
+
identification_types: Array<EnumEntry>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ONE_DAY_MS = 24 * 60 * 60 * 1000;
|
|
20
|
+
|
|
21
|
+
export const useProfessionalRegistryRegulators = () => {
|
|
22
|
+
const { authenticated } = useSession();
|
|
23
|
+
const url = `${restBaseUrl}/virtualclaims/professional-registry/regulators`;
|
|
24
|
+
|
|
25
|
+
const { data, error, isLoading } = useSWR<FetchResponse<RegulatorsResponse>>(
|
|
26
|
+
authenticated ? url : null,
|
|
27
|
+
openmrsFetch,
|
|
28
|
+
{
|
|
29
|
+
revalidateOnFocus: false,
|
|
30
|
+
dedupingInterval: ONE_DAY_MS,
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
regulators: data?.data?.regulators ?? [],
|
|
36
|
+
isLoading,
|
|
37
|
+
error,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const useProfessionalRegistryIdentificationTypes = () => {
|
|
42
|
+
const { authenticated } = useSession();
|
|
43
|
+
const url = `${restBaseUrl}/virtualclaims/professional-registry/identification-types`;
|
|
44
|
+
|
|
45
|
+
const { data, error, isLoading } = useSWR<FetchResponse<IdentificationTypesResponse>>(
|
|
46
|
+
authenticated ? url : null,
|
|
47
|
+
openmrsFetch,
|
|
48
|
+
{
|
|
49
|
+
revalidateOnFocus: false,
|
|
50
|
+
dedupingInterval: ONE_DAY_MS,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
identificationTypes: data?.data?.identification_types ?? [],
|
|
56
|
+
isLoading,
|
|
57
|
+
error,
|
|
58
|
+
};
|
|
59
|
+
};
|