@openmrs/esm-patient-orders-app 5.0.1-pre.2175

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.
Files changed (71) hide show
  1. package/.turbo/turbo-build.log +36 -0
  2. package/LICENSE +401 -0
  3. package/README.md +4 -0
  4. package/dist/130.js +2 -0
  5. package/dist/130.js.LICENSE.txt +3 -0
  6. package/dist/130.js.map +1 -0
  7. package/dist/193.js +1 -0
  8. package/dist/193.js.map +1 -0
  9. package/dist/232.js +1 -0
  10. package/dist/232.js.map +1 -0
  11. package/dist/235.js +1 -0
  12. package/dist/235.js.map +1 -0
  13. package/dist/255.js +2 -0
  14. package/dist/255.js.LICENSE.txt +9 -0
  15. package/dist/255.js.map +1 -0
  16. package/dist/319.js +1 -0
  17. package/dist/37.js +1 -0
  18. package/dist/37.js.map +1 -0
  19. package/dist/442.js +2 -0
  20. package/dist/442.js.LICENSE.txt +14 -0
  21. package/dist/442.js.map +1 -0
  22. package/dist/47.js +1 -0
  23. package/dist/47.js.map +1 -0
  24. package/dist/574.js +1 -0
  25. package/dist/588.js +1 -0
  26. package/dist/588.js.map +1 -0
  27. package/dist/591.js +2 -0
  28. package/dist/591.js.LICENSE.txt +32 -0
  29. package/dist/591.js.map +1 -0
  30. package/dist/712.js +2 -0
  31. package/dist/712.js.LICENSE.txt +5 -0
  32. package/dist/712.js.map +1 -0
  33. package/dist/757.js +1 -0
  34. package/dist/784.js +2 -0
  35. package/dist/784.js.LICENSE.txt +9 -0
  36. package/dist/784.js.map +1 -0
  37. package/dist/788.js +1 -0
  38. package/dist/807.js +1 -0
  39. package/dist/833.js +1 -0
  40. package/dist/842.js +1 -0
  41. package/dist/842.js.map +1 -0
  42. package/dist/95.js +1 -0
  43. package/dist/95.js.map +1 -0
  44. package/dist/main.js +1 -0
  45. package/dist/main.js.map +1 -0
  46. package/dist/openmrs-esm-patient-orders-app.js +1 -0
  47. package/dist/openmrs-esm-patient-orders-app.js.buildmanifest.json +618 -0
  48. package/dist/openmrs-esm-patient-orders-app.js.map +1 -0
  49. package/dist/routes.json +1 -0
  50. package/jest.config.js +3 -0
  51. package/package.json +57 -0
  52. package/src/api/api.ts +137 -0
  53. package/src/config-schema.ts +13 -0
  54. package/src/declarations.d.ts +3 -0
  55. package/src/index.ts +28 -0
  56. package/src/order-basket/order-basket.scss +39 -0
  57. package/src/order-basket/order-basket.workspace.tsx +177 -0
  58. package/src/order-basket-action-button/order-basket-action-button.extension.tsx +56 -0
  59. package/src/order-basket-action-button/order-basket-action-button.scss +80 -0
  60. package/src/order-basket-action-button/order-basket-action-button.test.tsx +121 -0
  61. package/src/root.scss +67 -0
  62. package/src/routes.json +14 -0
  63. package/src/types/order.ts +5 -0
  64. package/translations/am.json +3 -0
  65. package/translations/en.json +3 -0
  66. package/translations/es.json +3 -0
  67. package/translations/fr.json +3 -0
  68. package/translations/he.json +3 -0
  69. package/translations/km.json +3 -0
  70. package/tsconfig.json +5 -0
  71. package/webpack.config.js +1 -0
@@ -0,0 +1,121 @@
1
+ import React from 'react';
2
+ import { screen, render, waitFor, renderHook } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { useLayoutType, usePatient } from '@openmrs/esm-framework';
5
+ import { OrderBasketItem, useOrderBasket } from '@openmrs/esm-patient-common-lib';
6
+ import { mockPatient } from '../../../../tools/test-helpers';
7
+ import OrderBasketActionButton from './order-basket-action-button.extension';
8
+ import { orderBasketStore } from '@openmrs/esm-patient-common-lib/src/orders/store';
9
+
10
+ const mockedUseLayoutType = useLayoutType as jest.Mock;
11
+ const mockUsePatient = usePatient as jest.Mock;
12
+
13
+ // This pattern of mocking seems to be required: defining the mocked function here and
14
+ // then assigning it with an arrow function wrapper in jest.mock. It is very particular.
15
+ // I think it is related to this: https://github.com/swc-project/jest/issues/14#issuecomment-1238621942
16
+ const mockLaunchPatientWorkspace = jest.fn();
17
+ const mockLaunchStartVisitPrompt = jest.fn();
18
+ const mockUseVisitOrOfflineVisit = jest.fn(() => ({
19
+ activeVisit: {
20
+ uuid: '8ef90c91-14be-42dd-a1c0-e67fbf904470',
21
+ },
22
+ currentVisit: {
23
+ uuid: '8ef90c91-14be-42dd-a1c0-e67fbf904470',
24
+ },
25
+ }));
26
+ const mockGetPatientUuidFromUrl = jest.fn(() => mockPatient.id);
27
+
28
+ jest.mock('@openmrs/esm-patient-common-lib', () => {
29
+ const originalModule = jest.requireActual('@openmrs/esm-patient-common-lib');
30
+
31
+ return {
32
+ ...originalModule,
33
+ getPatientUuidFromUrl: () => mockGetPatientUuidFromUrl(),
34
+ launchPatientWorkspace: (arg) => mockLaunchPatientWorkspace(arg),
35
+ launchStartVisitPrompt: () => mockLaunchStartVisitPrompt(),
36
+ useWorkspaces: jest.fn(() => {
37
+ return { workspaces: [{ name: 'order-basket' }] };
38
+ }),
39
+ useVisitOrOfflineVisit: () => mockUseVisitOrOfflineVisit(),
40
+ useSystemVisitSetting: jest.fn().mockReturnValue({ data: true }),
41
+ };
42
+ });
43
+
44
+ jest.mock('@openmrs/esm-patient-common-lib/src/get-patient-uuid-from-url', () => {
45
+ return { getPatientUuidFromUrl: () => mockGetPatientUuidFromUrl() };
46
+ });
47
+
48
+ describe('<OrderBasketActionButton/>', () => {
49
+ beforeAll(() => {
50
+ orderBasketStore.setState({
51
+ items: {
52
+ [mockPatient.id]: {
53
+ medications: [{ name: 'order-01', uuid: 'some-uuid' } as unknown as OrderBasketItem],
54
+ },
55
+ },
56
+ });
57
+ mockUsePatient.mockReturnValue({ patientUuid: mockPatient.id });
58
+ });
59
+
60
+ beforeEach(() => {
61
+ jest.clearAllMocks();
62
+ });
63
+
64
+ it('should display tablet view action button', async () => {
65
+ const user = userEvent.setup();
66
+ mockedUseLayoutType.mockReturnValue('tablet');
67
+ render(<OrderBasketActionButton />);
68
+
69
+ const orderBasketButton = screen.getByRole('button', { name: /Order Basket/i });
70
+ expect(orderBasketButton).toBeInTheDocument();
71
+ await waitFor(() => user.click(orderBasketButton));
72
+ expect(mockLaunchPatientWorkspace).toHaveBeenCalledWith('order-basket');
73
+ expect(orderBasketButton).toHaveClass('active');
74
+ });
75
+
76
+ it('should display desktop view action button', async () => {
77
+ const user = userEvent.setup();
78
+ mockedUseLayoutType.mockReturnValue('desktop');
79
+ render(<OrderBasketActionButton />);
80
+
81
+ const orderBasketButton = screen.getByRole('button', { name: /Medications/i });
82
+ expect(orderBasketButton).toBeInTheDocument();
83
+ await waitFor(() => user.click(orderBasketButton));
84
+ expect(mockLaunchPatientWorkspace).toHaveBeenCalledWith('order-basket');
85
+ expect(orderBasketButton).toHaveClass('active');
86
+ });
87
+
88
+ it('should prompt user to start visit if no currentVisit found', async () => {
89
+ const user = userEvent.setup();
90
+ mockedUseLayoutType.mockReturnValue('desktop');
91
+ mockUseVisitOrOfflineVisit.mockImplementation(() => ({
92
+ activeVisit: null,
93
+ currentVisit: null,
94
+ }));
95
+ const screen = render(<OrderBasketActionButton />);
96
+
97
+ const orderBasketButton = screen.getByRole('button', { name: /Medications/i });
98
+ expect(orderBasketButton).toBeInTheDocument();
99
+ await waitFor(() => user.click(orderBasketButton));
100
+ expect(mockLaunchPatientWorkspace).not.toBeCalled();
101
+ expect(mockLaunchStartVisitPrompt).toHaveBeenCalled();
102
+ expect(orderBasketButton).toHaveClass('active');
103
+ });
104
+
105
+ it('should display a count tag when orders are present on the desktop view', () => {
106
+ mockedUseLayoutType.mockReturnValue('desktop');
107
+ const { result } = renderHook(useOrderBasket);
108
+ expect(result.current.orders).toHaveLength(1); // sanity check
109
+ render(<OrderBasketActionButton />);
110
+
111
+ expect(screen.getByText(/medications/i)).toBeInTheDocument();
112
+ expect(screen.getByText(/1/i)).toBeInTheDocument();
113
+ });
114
+
115
+ it('should display the count tag when orders are present on the tablet view', () => {
116
+ mockedUseLayoutType.mockReturnValue('tablet');
117
+ render(<OrderBasketActionButton />);
118
+
119
+ expect(screen.getByRole('button', { name: /1 order basket/i })).toBeInTheDocument();
120
+ });
121
+ });
package/src/root.scss ADDED
@@ -0,0 +1,67 @@
1
+ @use '@carbon/styles/scss/spacing';
2
+ @use '@carbon/styles/scss/type';
3
+ @import '~@openmrs/esm-styleguide/src/vars';
4
+
5
+ .productiveHeading01 {
6
+ @include type.type-style("heading-compact-01");
7
+ margin-bottom: spacing.$spacing-03;
8
+ }
9
+
10
+ .productiveHeading02 {
11
+ @include type.type-style("heading-compact-02");
12
+ margin-bottom: spacing.$spacing-05;
13
+ }
14
+
15
+ .productiveHeading03 {
16
+ @include type.type-style("heading-03");
17
+ margin-bottom: spacing.$spacing-05;
18
+ }
19
+
20
+ .productiveHeading04 {
21
+ @include type.type-style("heading-04");
22
+ margin-bottom: spacing.$spacing-05;
23
+ }
24
+
25
+ .productiveHeading05 {
26
+ @include type.type-style("heading-05");
27
+ margin-bottom: spacing.$spacing-05;
28
+ }
29
+
30
+ .productiveHeading06 {
31
+ @include type.type-style("heading-06");
32
+ margin-bottom: spacing.$spacing-06;
33
+ }
34
+
35
+ .bodyShort01 {
36
+ @include type.type-style("body-compact-01");
37
+ }
38
+
39
+ .bodyShort02 {
40
+ @include type.type-style("body-compact-02");
41
+ }
42
+
43
+ .bodyLong01 {
44
+ @include type.type-style("body-01");
45
+ }
46
+
47
+ .bodyLong02 {
48
+ @include type.type-style("body-02");
49
+ }
50
+
51
+ .label01 {
52
+ @include type.type-style("label-01");
53
+ }
54
+
55
+ .caption01 {
56
+ @include type.type-style("legal-01");
57
+ }
58
+
59
+ .clipTextWithEllipsis {
60
+ text-overflow: ellipsis;
61
+ overflow: hidden;
62
+ white-space: nowrap;
63
+ }
64
+
65
+ .text02 {
66
+ color: $text-02;
67
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "https://json.openmrs.org/routes.schema.json",
3
+ "backendDependencies": {
4
+ "webservices.rest": "^2.2.0"
5
+ },
6
+ "extensions": [
7
+ {
8
+ "name": "order-basket-action-menu",
9
+ "component": "orderBasketActionMenu",
10
+ "slot": "action-menu-chart-items-slot",
11
+ "order": 0
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,5 @@
1
+ import { Order } from '@openmrs/esm-patient-common-lib';
2
+
3
+ export interface PatientMedicationFetchResponse {
4
+ results: Array<Order>;
5
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "Medications": "Medications"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "Medications": "Medications"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "Medications": "Medications"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "Medications": "Medications"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "Medications": "Medications"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "Medications": "Medications"
3
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": ["src/**/*"],
4
+ "exclude": ["src/**/*.test.tsx"]
5
+ }
@@ -0,0 +1 @@
1
+ module.exports = require('openmrs/default-webpack-config');