@olaboot/esm-patient-registration-app 9.2.0

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 (250) hide show
  1. package/ADDRESS_CONFIGURATION.md +152 -0
  2. package/IDENTIFIER_CONFIGURATION.md +142 -0
  3. package/IMPLEMENTATION_SUMMARY.md +111 -0
  4. package/QUICK_START.md +95 -0
  5. package/README.md +7 -0
  6. package/address-required-fields-config.json +26 -0
  7. package/dist/126.js +1 -0
  8. package/dist/15.js +1 -0
  9. package/dist/1564.js +1 -0
  10. package/dist/1567.js +1 -0
  11. package/dist/1845.js +1 -0
  12. package/dist/1953.js +1 -0
  13. package/dist/200.js +1 -0
  14. package/dist/200.js.map +1 -0
  15. package/dist/215.js +1 -0
  16. package/dist/2178.js +1 -0
  17. package/dist/250.js +1 -0
  18. package/dist/250.js.map +1 -0
  19. package/dist/2523.js +1 -0
  20. package/dist/2523.js.map +1 -0
  21. package/dist/2566.js +1 -0
  22. package/dist/2586.js +1 -0
  23. package/dist/2586.js.map +1 -0
  24. package/dist/2716.js +1 -0
  25. package/dist/2716.js.map +1 -0
  26. package/dist/2759.js +1 -0
  27. package/dist/2821.js +6 -0
  28. package/dist/2821.js.map +1 -0
  29. package/dist/3089.js +1 -0
  30. package/dist/3089.js.map +1 -0
  31. package/dist/3230.js +1 -0
  32. package/dist/3441.js +1 -0
  33. package/dist/3565.js +1 -0
  34. package/dist/3571.js +1 -0
  35. package/dist/3571.js.map +1 -0
  36. package/dist/3746.js +1 -0
  37. package/dist/3925.js +1 -0
  38. package/dist/3946.js +1 -0
  39. package/dist/4024.js +1 -0
  40. package/dist/4024.js.map +1 -0
  41. package/dist/4744.js +1 -0
  42. package/dist/4744.js.map +1 -0
  43. package/dist/4809.js +1 -0
  44. package/dist/4894.js +1 -0
  45. package/dist/4970.js +1 -0
  46. package/dist/4970.js.map +1 -0
  47. package/dist/5130.js +1 -0
  48. package/dist/5187.js +1 -0
  49. package/dist/5491.js +1 -0
  50. package/dist/5491.js.map +1 -0
  51. package/dist/5595.js +1 -0
  52. package/dist/5961.js +1 -0
  53. package/dist/6133.js +1 -0
  54. package/dist/634.js +1 -0
  55. package/dist/634.js.map +1 -0
  56. package/dist/6456.js +1 -0
  57. package/dist/6466.js +1 -0
  58. package/dist/6613.js +1 -0
  59. package/dist/6783.js +1 -0
  60. package/dist/7073.js +38 -0
  61. package/dist/7073.js.map +1 -0
  62. package/dist/7154.js +1 -0
  63. package/dist/7154.js.map +1 -0
  64. package/dist/7348.js +1 -0
  65. package/dist/7439.js +1 -0
  66. package/dist/7439.js.map +1 -0
  67. package/dist/7543.js +1 -0
  68. package/dist/7607.js +1 -0
  69. package/dist/772.js +1 -0
  70. package/dist/7984.js +1 -0
  71. package/dist/7984.js.map +1 -0
  72. package/dist/8538.js +1 -0
  73. package/dist/8538.js.map +1 -0
  74. package/dist/8599.js +1 -0
  75. package/dist/8727.js +1 -0
  76. package/dist/8847.js +1 -0
  77. package/dist/9015.js +1 -0
  78. package/dist/906.js +1 -0
  79. package/dist/9065.js +1 -0
  80. package/dist/9182.js +1 -0
  81. package/dist/9339.js +1 -0
  82. package/dist/9453.js +1 -0
  83. package/dist/9833.js +1 -0
  84. package/dist/9833.js.map +1 -0
  85. package/dist/9856.js +1 -0
  86. package/dist/9856.js.map +1 -0
  87. package/dist/9920.js +1 -0
  88. package/dist/9938.js +1 -0
  89. package/dist/9943.js +1 -0
  90. package/dist/9943.js.map +1 -0
  91. package/dist/main.js +10 -0
  92. package/dist/main.js.map +1 -0
  93. package/dist/olaboot-esm-patient-registration-app.js +5 -0
  94. package/dist/olaboot-esm-patient-registration-app.js.buildmanifest.json +1627 -0
  95. package/dist/olaboot-esm-patient-registration-app.js.map +1 -0
  96. package/dist/routes.json +1 -0
  97. package/docs/images/patient-registration-hierarchy.png +0 -0
  98. package/example-config.json +14 -0
  99. package/jest.config.js +3 -0
  100. package/package.json +60 -0
  101. package/rspack.config.js +1 -0
  102. package/src/add-patient-link.extension.tsx +21 -0
  103. package/src/add-patient-link.scss +3 -0
  104. package/src/add-patient-link.test.tsx +16 -0
  105. package/src/config-schema.ts +507 -0
  106. package/src/constants.ts +14 -0
  107. package/src/declarations.d.ts +4 -0
  108. package/src/index.ts +59 -0
  109. package/src/nav-link.test.tsx +13 -0
  110. package/src/nav-link.tsx +10 -0
  111. package/src/offline.resources.ts +157 -0
  112. package/src/offline.ts +93 -0
  113. package/src/patient-photo.extension.tsx +11 -0
  114. package/src/patient-registration/before-save-prompt.component.tsx +72 -0
  115. package/src/patient-registration/field/__mocks__/field.resource.ts +60 -0
  116. package/src/patient-registration/field/address/address-field.component.tsx +186 -0
  117. package/src/patient-registration/field/address/address-hierarchy-levels.component.tsx +71 -0
  118. package/src/patient-registration/field/address/address-hierarchy.resource.tsx +157 -0
  119. package/src/patient-registration/field/address/address-hierarchy.test.tsx +296 -0
  120. package/src/patient-registration/field/address/address-search.component.tsx +87 -0
  121. package/src/patient-registration/field/address/address-search.scss +53 -0
  122. package/src/patient-registration/field/address/address-search.test.tsx +141 -0
  123. package/src/patient-registration/field/address/custom-address-field.component.tsx +32 -0
  124. package/src/patient-registration/field/cause-of-death/cause-of-death.component.tsx +98 -0
  125. package/src/patient-registration/field/custom-field.component.tsx +25 -0
  126. package/src/patient-registration/field/date-and-time-of-death/date-and-time-of-death.component.tsx +79 -0
  127. package/src/patient-registration/field/dob/dob.component.tsx +167 -0
  128. package/src/patient-registration/field/dob/dob.test.tsx +90 -0
  129. package/src/patient-registration/field/field.component.tsx +53 -0
  130. package/src/patient-registration/field/field.resource.ts +42 -0
  131. package/src/patient-registration/field/field.scss +171 -0
  132. package/src/patient-registration/field/field.test.tsx +330 -0
  133. package/src/patient-registration/field/gender/gender-field.component.tsx +54 -0
  134. package/src/patient-registration/field/gender/gender-field.test.tsx +99 -0
  135. package/src/patient-registration/field/id/id-field.component.tsx +136 -0
  136. package/src/patient-registration/field/id/id-field.test.tsx +121 -0
  137. package/src/patient-registration/field/id/identifier-selection-overlay.component.tsx +200 -0
  138. package/src/patient-registration/field/id/identifier-selection.scss +41 -0
  139. package/src/patient-registration/field/name/name-field.component.tsx +148 -0
  140. package/src/patient-registration/field/obs/obs-field.component.tsx +261 -0
  141. package/src/patient-registration/field/obs/obs-field.test.tsx +299 -0
  142. package/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx +120 -0
  143. package/src/patient-registration/field/person-attributes/coded-person-attribute-field.test.tsx +141 -0
  144. package/src/patient-registration/field/person-attributes/location-person-attribute-field.component.tsx +105 -0
  145. package/src/patient-registration/field/person-attributes/location-person-attribute-field.resource.tsx +48 -0
  146. package/src/patient-registration/field/person-attributes/person-attribute-field.component.tsx +100 -0
  147. package/src/patient-registration/field/person-attributes/person-attribute-field.test.tsx +193 -0
  148. package/src/patient-registration/field/person-attributes/person-attributes.resource.ts +20 -0
  149. package/src/patient-registration/field/person-attributes/text-person-attribute-field.component.tsx +58 -0
  150. package/src/patient-registration/field/person-attributes/text-person-attribute-field.test.tsx +90 -0
  151. package/src/patient-registration/field/phone/phone-field.component.tsx +17 -0
  152. package/src/patient-registration/form-manager.test.ts +91 -0
  153. package/src/patient-registration/form-manager.ts +443 -0
  154. package/src/patient-registration/input/basic-input/input/input.component.tsx +183 -0
  155. package/src/patient-registration/input/basic-input/input/input.test.tsx +72 -0
  156. package/src/patient-registration/input/basic-input/select/select-input.component.tsx +32 -0
  157. package/src/patient-registration/input/basic-input/select/select-input.test.tsx +49 -0
  158. package/src/patient-registration/input/combo-input/combo-input.component.tsx +130 -0
  159. package/src/patient-registration/input/combo-input/selection-tick.component.tsx +20 -0
  160. package/src/patient-registration/input/custom-input/autosuggest/autosuggest.component.tsx +187 -0
  161. package/src/patient-registration/input/custom-input/autosuggest/autosuggest.scss +62 -0
  162. package/src/patient-registration/input/custom-input/autosuggest/autosuggest.test.tsx +164 -0
  163. package/src/patient-registration/input/custom-input/identifier/identifier-input.component.tsx +193 -0
  164. package/src/patient-registration/input/custom-input/identifier/identifier-input.test.tsx +335 -0
  165. package/src/patient-registration/input/custom-input/identifier/utils.test.ts +81 -0
  166. package/src/patient-registration/input/custom-input/identifier/utils.ts +19 -0
  167. package/src/patient-registration/input/dummy-data/dummy-data-input.component.tsx +56 -0
  168. package/src/patient-registration/input/dummy-data/dummy-data-input.test.tsx +34 -0
  169. package/src/patient-registration/input/input.scss +122 -0
  170. package/src/patient-registration/patient-registration-context.ts +35 -0
  171. package/src/patient-registration/patient-registration-hooks.ts +376 -0
  172. package/src/patient-registration/patient-registration-utils.test.ts +33 -0
  173. package/src/patient-registration/patient-registration-utils.ts +214 -0
  174. package/src/patient-registration/patient-registration.component.tsx +266 -0
  175. package/src/patient-registration/patient-registration.resource.test.tsx +22 -0
  176. package/src/patient-registration/patient-registration.resource.ts +198 -0
  177. package/src/patient-registration/patient-registration.scss +103 -0
  178. package/src/patient-registration/patient-registration.test.tsx +580 -0
  179. package/src/patient-registration/patient-registration.types.ts +322 -0
  180. package/src/patient-registration/section/death-info/death-info-section.component.tsx +36 -0
  181. package/src/patient-registration/section/death-info/death-info-section.test.tsx +47 -0
  182. package/src/patient-registration/section/demographics/demographics-section.component.tsx +30 -0
  183. package/src/patient-registration/section/demographics/demographics-section.test.tsx +98 -0
  184. package/src/patient-registration/section/generic-section.component.tsx +17 -0
  185. package/src/patient-registration/section/patient-relationships/relationships-section.component.tsx +234 -0
  186. package/src/patient-registration/section/patient-relationships/relationships-section.test.tsx +113 -0
  187. package/src/patient-registration/section/patient-relationships/relationships.resource.tsx +78 -0
  188. package/src/patient-registration/section/patient-relationships/relationships.scss +35 -0
  189. package/src/patient-registration/section/section-wrapper.component.tsx +40 -0
  190. package/src/patient-registration/section/section.component.tsx +23 -0
  191. package/src/patient-registration/section/section.scss +21 -0
  192. package/src/patient-registration/ui-components/overlay/overlay.component.tsx +51 -0
  193. package/src/patient-registration/ui-components/overlay/overlay.scss +63 -0
  194. package/src/patient-registration/validation/patient-registration-validation.test.ts +205 -0
  195. package/src/patient-registration/validation/patient-registration-validation.ts +123 -0
  196. package/src/resource.ts +12 -0
  197. package/src/resources-context.ts +14 -0
  198. package/src/root.component.tsx +63 -0
  199. package/src/root.scss +7 -0
  200. package/src/routes.json +61 -0
  201. package/src/widgets/cancel-patient-edit.modal.tsx +33 -0
  202. package/src/widgets/cancel-patient-edit.test.tsx +22 -0
  203. package/src/widgets/delete-identifier-confirmation.modal.tsx +48 -0
  204. package/src/widgets/delete-identifier-confirmation.test.tsx +32 -0
  205. package/src/widgets/edit-patient-details-button.component.tsx +33 -0
  206. package/src/widgets/edit-patient-details-button.scss +3 -0
  207. package/src/widgets/edit-patient-details-button.test.tsx +35 -0
  208. package/translations/am.json +120 -0
  209. package/translations/ar.json +120 -0
  210. package/translations/ar_SY.json +120 -0
  211. package/translations/bn.json +120 -0
  212. package/translations/cs.json +120 -0
  213. package/translations/de.json +120 -0
  214. package/translations/en.json +120 -0
  215. package/translations/en_US.json +120 -0
  216. package/translations/es.json +120 -0
  217. package/translations/es_MX.json +120 -0
  218. package/translations/fr.json +120 -0
  219. package/translations/he.json +120 -0
  220. package/translations/hi.json +120 -0
  221. package/translations/hi_IN.json +120 -0
  222. package/translations/id.json +120 -0
  223. package/translations/it.json +120 -0
  224. package/translations/ka.json +120 -0
  225. package/translations/km.json +120 -0
  226. package/translations/ku.json +120 -0
  227. package/translations/ky.json +120 -0
  228. package/translations/lg.json +120 -0
  229. package/translations/ne.json +120 -0
  230. package/translations/pl.json +120 -0
  231. package/translations/pt.json +120 -0
  232. package/translations/pt_BR.json +120 -0
  233. package/translations/qu.json +120 -0
  234. package/translations/ro_RO.json +120 -0
  235. package/translations/ru_RU.json +120 -0
  236. package/translations/si.json +120 -0
  237. package/translations/sq.json +120 -0
  238. package/translations/sw.json +120 -0
  239. package/translations/sw_KE.json +120 -0
  240. package/translations/tr.json +120 -0
  241. package/translations/tr_TR.json +120 -0
  242. package/translations/uk.json +120 -0
  243. package/translations/uz.json +120 -0
  244. package/translations/uz@Latn.json +120 -0
  245. package/translations/uz_UZ.json +120 -0
  246. package/translations/vi.json +120 -0
  247. package/translations/zh.json +120 -0
  248. package/translations/zh_CN.json +120 -0
  249. package/translations/zh_TW.json +120 -0
  250. package/tsconfig.json +5 -0
@@ -0,0 +1,103 @@
1
+ @use '@carbon/layout';
2
+ @use '@carbon/type';
3
+ @use '@openmrs/esm-styleguide/src/vars' as *;
4
+
5
+ .submit {
6
+ width: 15.625rem;
7
+ }
8
+
9
+ .submit:hover {
10
+ cursor: pointer;
11
+ }
12
+
13
+ .cancelButton {
14
+ width: 11.688rem;
15
+ }
16
+
17
+ .submitButton {
18
+ margin-bottom: layout.$spacing-05;
19
+ width: 11.688rem;
20
+ display: block;
21
+ }
22
+
23
+ .infoGrid {
24
+ width: 100%;
25
+ padding-left: layout.$spacing-07;
26
+ margin-bottom: 40vh;
27
+ margin-top: layout.$spacing-05;
28
+ max-width: 50rem;
29
+ }
30
+
31
+ :global(.omrs-breakpoint-lt-desktop) {
32
+ .infoGrid {
33
+ max-width: unset;
34
+ }
35
+ }
36
+
37
+ .label01 {
38
+ @include type.type-style('label-01');
39
+ margin-top: layout.$spacing-05;
40
+ margin-bottom: layout.$spacing-05;
41
+ color: $ui-05;
42
+ }
43
+
44
+ .space05 {
45
+ margin: layout.$spacing-05 0;
46
+ }
47
+
48
+ .formContainer {
49
+ display: flex;
50
+ width: 100%;
51
+ }
52
+
53
+ .stickyColumn {
54
+ position: sticky;
55
+ margin-top: layout.$spacing-05;
56
+ // layout.$spacing-09 for the nav height and layout.$spacing-05 for top margin
57
+ top: layout.$spacing-10;
58
+ }
59
+
60
+ .touchTarget a:active {
61
+ color: $color-gray-100;
62
+ }
63
+
64
+ .linkName {
65
+ color: $color-gray-70;
66
+ line-height: 1.38;
67
+ font-size: layout.$spacing-05;
68
+ font-weight: 600;
69
+
70
+ &:active {
71
+ text-decoration: none;
72
+ color: $color-gray-100;
73
+ }
74
+
75
+ &:hover {
76
+ text-decoration: none;
77
+ color: $color-gray-100;
78
+ cursor: pointer;
79
+ }
80
+ }
81
+
82
+ .spinner {
83
+ min-height: layout.$spacing-05;
84
+ width: max-content;
85
+
86
+ :global(.cds--inline-loading__text) {
87
+ @include type.type-style('body-01');
88
+ }
89
+ }
90
+
91
+ // Overriding styles for RTL support
92
+ html[dir='rtl'] {
93
+ .linkName {
94
+ & > svg {
95
+ transform: scale(-1, 1);
96
+ }
97
+ }
98
+
99
+ .infoGrid {
100
+ padding-left: unset;
101
+ padding-right: layout.$spacing-07;
102
+ }
103
+ }
@@ -0,0 +1,580 @@
1
+ import React from 'react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { useParams } from 'react-router-dom';
4
+ import { screen, within } from '@testing-library/react';
5
+ import {
6
+ type FetchResponse,
7
+ getDefaultsFromConfigSchema,
8
+ showSnackbar,
9
+ useConfig,
10
+ usePatient,
11
+ } from '@openmrs/esm-framework';
12
+ import type { AddressTemplate, Encounter, FormValues } from './patient-registration.types';
13
+ import { mockedAddressTemplate } from '__mocks__';
14
+ import { mockPatient, renderWithContext } from 'tools';
15
+ import { saveEncounter, savePatient } from './patient-registration.resource';
16
+ import { esmPatientRegistrationSchema, type RegistrationConfig } from '../config-schema';
17
+ import { FormManager } from './form-manager';
18
+ import { PatientRegistration } from './patient-registration.component';
19
+ import { useInitialFormValues } from './patient-registration-hooks';
20
+ import { ResourcesContextProvider } from '../resources-context';
21
+
22
+ const mockSaveEncounter = jest.mocked(saveEncounter);
23
+ const mockSavePatient = savePatient as jest.Mock;
24
+ const mockShowSnackbar = jest.mocked(showSnackbar);
25
+ const mockUseConfig = jest.mocked(useConfig<RegistrationConfig>);
26
+ const mockUsePatient = jest.mocked(usePatient);
27
+ const mockUseParams = useParams as jest.Mock;
28
+ const mockUseInitialFormValues = jest.mocked(useInitialFormValues);
29
+
30
+ jest.mock('./field/field.resource', () => ({
31
+ useConcept: jest.fn().mockImplementation((uuid: string) => {
32
+ let data;
33
+ if (uuid == 'weight-uuid') {
34
+ data = {
35
+ uuid: 'weight-uuid',
36
+ display: 'Weight (kg)',
37
+ datatype: { display: 'Numeric', uuid: 'num' },
38
+ answers: [],
39
+ setMembers: [],
40
+ };
41
+ } else if (uuid == 'chief-complaint-uuid') {
42
+ data = {
43
+ uuid: 'chief-complaint-uuid',
44
+ display: 'Chief Complaint',
45
+ datatype: { display: 'Text', uuid: 'txt' },
46
+ answers: [],
47
+ setMembers: [],
48
+ };
49
+ } else if (uuid == 'nationality-uuid') {
50
+ data = {
51
+ uuid: 'nationality-uuid',
52
+ display: 'Nationality',
53
+ datatype: { display: 'Coded', uuid: 'cdd' },
54
+ answers: [
55
+ { display: 'USA', uuid: 'usa' },
56
+ { display: 'Mexico', uuid: 'mex' },
57
+ ],
58
+ setMembers: [],
59
+ };
60
+ }
61
+ return {
62
+ data: data ?? null,
63
+ isLoading: !data,
64
+ };
65
+ }),
66
+ useConceptAnswers: jest.fn().mockImplementation((uuid: string) => {
67
+ if (uuid == 'nationality-uuid') {
68
+ return {
69
+ data: [
70
+ { display: 'USA', uuid: 'usa' },
71
+ { display: 'Mexico', uuid: 'mex' },
72
+ ],
73
+ isLoading: false,
74
+ };
75
+ } else if (uuid == 'other-countries-uuid') {
76
+ return {
77
+ data: [
78
+ { display: 'Kenya', uuid: 'ke' },
79
+ { display: 'Uganda', uuid: 'ug' },
80
+ ],
81
+ isLoading: false,
82
+ };
83
+ }
84
+ }),
85
+ }));
86
+
87
+ jest.mock('react-router-dom', () => ({
88
+ ...jest.requireActual('react-router-dom'),
89
+ useLocation: () => ({
90
+ pathname: 'openmrs/spa/patient-registration',
91
+ }),
92
+ useHistory: () => [],
93
+ useParams: jest.fn().mockReturnValue({ patientUuid: undefined }),
94
+ }));
95
+
96
+ jest.mock('./patient-registration.resource', () => ({
97
+ ...jest.requireActual('./patient-registration.resource'),
98
+ saveEncounter: jest.fn(),
99
+ savePatient: jest.fn(),
100
+ }));
101
+
102
+ jest.mock('./patient-registration-hooks', () => ({
103
+ ...jest.requireActual('./patient-registration-hooks'),
104
+ useInitialFormValues: jest.fn().mockReturnValue([{}, jest.fn()]),
105
+ useInitialAddressFieldValues: jest.fn().mockReturnValue([{}, jest.fn()]),
106
+ usePatientUuidMap: jest.fn().mockReturnValue([{}, jest.fn()]),
107
+ }));
108
+
109
+ const mockResourcesContextValue = {
110
+ addressTemplate: mockedAddressTemplate as AddressTemplate,
111
+ currentSession: {
112
+ authenticated: true,
113
+ sessionId: 'JSESSION',
114
+ currentProvider: { uuid: 'provider-uuid', identifier: 'PRO-123' },
115
+ },
116
+ relationshipTypes: [],
117
+ identifierTypes: [],
118
+ };
119
+
120
+ const mockOpenmrsConfig: RegistrationConfig = {
121
+ sections: ['demographics', 'contact'],
122
+ sectionDefinitions: [
123
+ { id: 'demographics', name: 'Demographics', fields: ['name', 'gender', 'dob'] },
124
+ { id: 'contact', name: 'Contact Info', fields: ['address'] },
125
+ { id: 'relationships', name: 'Relationships', fields: ['relationship'] },
126
+ ],
127
+ fieldDefinitions: [],
128
+ fieldConfigurations: {
129
+ phone: {
130
+ personAttributeUuid: '14d4f066-15f5-102d-96e4-000c29c2a5d7',
131
+ },
132
+ dateOfBirth: {
133
+ allowEstimatedDateOfBirth: true,
134
+ useEstimatedDateOfBirth: {
135
+ enabled: true,
136
+ dayOfMonth: new Date().getDate(),
137
+ month: new Date().getMonth(),
138
+ },
139
+ },
140
+ name: {
141
+ displayMiddleName: true,
142
+ allowUnidentifiedPatients: true,
143
+ defaultUnknownGivenName: 'UNKNOWN',
144
+ defaultUnknownFamilyName: 'UNKNOWN',
145
+ displayReverseFieldOrder: false,
146
+ displayCapturePhoto: true,
147
+ },
148
+ gender: [
149
+ {
150
+ value: 'male',
151
+ label: 'Male',
152
+ },
153
+ {
154
+ value: 'female',
155
+ label: 'Female',
156
+ },
157
+ ],
158
+ address: {
159
+ useAddressHierarchy: {
160
+ enabled: true,
161
+ useQuickSearch: true,
162
+ searchAddressByLevel: true,
163
+ },
164
+ requiredAddressFields: [],
165
+ },
166
+ causeOfDeath: {
167
+ conceptUuid: 'cause-of-death-concept-uuid',
168
+ },
169
+ },
170
+ links: {
171
+ submitButton: '#',
172
+ },
173
+ defaultPatientIdentifierTypes: [],
174
+ registrationObs: {
175
+ encounterTypeUuid: null,
176
+ encounterProviderRoleUuid: 'asdf',
177
+ registrationFormUuid: null,
178
+ },
179
+ freeTextFieldConceptUuid: '',
180
+ };
181
+ const configWithObs = JSON.parse(JSON.stringify(mockOpenmrsConfig));
182
+
183
+ configWithObs.fieldDefinitions = [
184
+ {
185
+ id: 'weight',
186
+ type: 'obs',
187
+ label: null,
188
+ uuid: 'weight-uuid',
189
+ placeholder: '',
190
+ validation: { required: false, matches: null },
191
+ answerConceptSetUuid: null,
192
+ customConceptAnswers: [],
193
+ },
194
+ {
195
+ id: 'chief complaint',
196
+ type: 'obs',
197
+ label: null,
198
+ uuid: 'chief-complaint-uuid',
199
+ placeholder: '',
200
+ validation: { required: false, matches: null },
201
+ answerConceptSetUuid: null,
202
+ customConceptAnswers: [],
203
+ },
204
+ {
205
+ id: 'nationality',
206
+ type: 'obs',
207
+ label: null,
208
+ uuid: 'nationality-uuid',
209
+ placeholder: '',
210
+ validation: { required: false, matches: null },
211
+ answerConceptSetUuid: null,
212
+ customConceptAnswers: [],
213
+ },
214
+ ];
215
+ configWithObs.sectionDefinitions?.push({
216
+ id: 'custom',
217
+ name: 'Custom',
218
+ fields: ['weight', 'chief complaint', 'nationality'],
219
+ });
220
+ configWithObs.sections.push('custom');
221
+ configWithObs.registrationObs.encounterTypeUuid = 'reg-enc-uuid';
222
+
223
+ const fillRequiredFields = async () => {
224
+ const user = userEvent.setup();
225
+
226
+ const demographicsSection = await screen.findByLabelText('Demographics Section');
227
+ const givenNameInput = within(demographicsSection).getByLabelText(/first/i) as HTMLInputElement;
228
+ const familyNameInput = within(demographicsSection).getByLabelText(/family/i) as HTMLInputElement;
229
+ const dateInput = within(demographicsSection).getByRole('spinbutton', {
230
+ name: /day, date of birth/i,
231
+ }) as HTMLInputElement;
232
+ const monthInput = within(demographicsSection).getByRole('spinbutton', {
233
+ name: /month, date of birth/i,
234
+ }) as HTMLInputElement;
235
+ const yearInput = within(demographicsSection).getByRole('spinbutton', {
236
+ name: /year, date of birth/i,
237
+ }) as HTMLInputElement;
238
+ const genderInput = within(demographicsSection).getByLabelText(/Male/) as HTMLSelectElement;
239
+ await user.type(givenNameInput, 'Paul');
240
+ await user.type(familyNameInput, 'Gaihre');
241
+ await user.clear(dateInput);
242
+ await user.type(dateInput, '02');
243
+ await user.clear(monthInput);
244
+ await user.type(monthInput, '08');
245
+ await user.clear(yearInput);
246
+ await user.type(yearInput, '1993');
247
+ await user.click(genderInput);
248
+ };
249
+
250
+ describe('Registering a new patient', () => {
251
+ beforeEach(() => {
252
+ mockUseConfig.mockReturnValue({
253
+ ...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
254
+ ...mockOpenmrsConfig,
255
+ });
256
+ mockSavePatient.mockReturnValue({ data: { uuid: 'new-pt-uuid' }, ok: true });
257
+ });
258
+
259
+ it('should render all the required fields and sections', async () => {
260
+ renderWithContext(
261
+ <PatientRegistration isOffline={false} savePatientForm={jest.fn()} />,
262
+ ResourcesContextProvider,
263
+ mockResourcesContextValue,
264
+ );
265
+
266
+ await screen.findByRole('heading', { name: /create new patient/i });
267
+
268
+ const demographicSection = screen.getByRole('region', { name: /demographics section/i });
269
+ const contactSection = screen.getByRole('region', { name: /contact info section/i });
270
+
271
+ expect(demographicSection).toBeInTheDocument();
272
+ expect(contactSection).toBeInTheDocument();
273
+ expect(screen.getByText(/jump to/i)).toBeInTheDocument();
274
+ expect(within(demographicSection).getByLabelText(/first name/i)).toBeInTheDocument();
275
+ expect(within(demographicSection).getByLabelText(/middle name \(optional\)/i)).toBeInTheDocument();
276
+ expect(within(demographicSection).getByLabelText(/family name/i)).toBeInTheDocument();
277
+ const dateOfBirthInput = within(demographicSection).getByLabelText(/date of birth/i);
278
+ expect(dateOfBirthInput).toBeInTheDocument();
279
+ expect(within(demographicSection).getByRole('radio', { name: /^male$/i })).toBeInTheDocument();
280
+ expect(within(demographicSection).getByRole('radio', { name: /^female$/i })).toBeInTheDocument();
281
+ expect(within(demographicSection).getByText(/date of birth known\?/i)).toBeInTheDocument();
282
+
283
+ expect(within(contactSection).getByRole('heading', { name: /address/i })).toBeInTheDocument();
284
+
285
+ expect(screen.getByRole('button', { name: /register patient/i })).toBeInTheDocument();
286
+ expect(screen.getByRole('button', { name: /cancel/i })).toBeInTheDocument();
287
+ });
288
+
289
+ // FIXME the register patient button is missing
290
+ it.skip('saves the patient without extra info', async () => {
291
+ const user = userEvent.setup();
292
+
293
+ renderWithContext(
294
+ <PatientRegistration isOffline={false} savePatientForm={FormManager.savePatientFormOnline} />,
295
+ ResourcesContextProvider,
296
+ mockResourcesContextValue,
297
+ );
298
+
299
+ await fillRequiredFields();
300
+ await user.click(await screen.findByText(/Register Patient/i));
301
+ expect(mockSavePatient).toHaveBeenCalledWith(
302
+ expect.objectContaining({
303
+ identifiers: [], //TODO when the identifer story is finished: { identifier: '', identifierType: '05a29f94-c0ed-11e2-94be-8c13b969e334', location: '' },
304
+ person: {
305
+ addresses: expect.arrayContaining([expect.any(Object)]),
306
+ attributes: [],
307
+ birthdate: '1993-8-2',
308
+ birthdateEstimated: false,
309
+ gender: expect.stringMatching(/^M$/),
310
+ names: [{ givenName: 'Paul', middleName: '', familyName: 'Gaihre', preferred: true, uuid: undefined }],
311
+ dead: false,
312
+ uuid: expect.anything(),
313
+ },
314
+ uuid: expect.anything(),
315
+ }),
316
+ undefined,
317
+ );
318
+ });
319
+
320
+ it('should not save the patient if validation fails', async () => {
321
+ const user = userEvent.setup();
322
+ const mockSavePatientForm = jest.fn();
323
+
324
+ renderWithContext(
325
+ <PatientRegistration isOffline={false} savePatientForm={mockSavePatientForm} />,
326
+ ResourcesContextProvider,
327
+ mockResourcesContextValue,
328
+ );
329
+
330
+ await screen.findByRole('heading', { name: /create new patient/i });
331
+ await user.click(screen.getByRole('button', { name: /register patient/i }));
332
+
333
+ expect(mockSavePatientForm).not.toHaveBeenCalled();
334
+ });
335
+
336
+ // FIXME: the register patient button is missing
337
+ it.skip('renders and saves registration obs', async () => {
338
+ const user = userEvent.setup();
339
+
340
+ mockSaveEncounter.mockResolvedValue({} as unknown as FetchResponse);
341
+ mockUseConfig.mockReturnValue(configWithObs);
342
+
343
+ renderWithContext(
344
+ <PatientRegistration isOffline={false} savePatientForm={FormManager.savePatientFormOnline} />,
345
+ ResourcesContextProvider,
346
+ mockResourcesContextValue,
347
+ );
348
+
349
+ await fillRequiredFields();
350
+ const customSection = screen.getByLabelText('Custom Section');
351
+ const weight = within(customSection).getByLabelText('Weight (kg) (optional)');
352
+ await user.type(weight, '50');
353
+ const complaint = within(customSection).getByLabelText('Chief Complaint (optional)');
354
+ await user.type(complaint, 'sad');
355
+ const nationality = within(customSection).getByLabelText('Nationality');
356
+ await user.selectOptions(nationality, 'USA');
357
+
358
+ await user.click(screen.getByText(/Register Patient/i));
359
+
360
+ expect(mockSavePatient).toHaveBeenCalled();
361
+
362
+ expect(mockSaveEncounter).toHaveBeenCalledWith(
363
+ expect.objectContaining<Partial<Encounter>>({
364
+ encounterType: 'reg-enc-uuid',
365
+ patient: 'new-pt-uuid',
366
+ obs: [
367
+ { concept: 'weight-uuid', value: 50 },
368
+ { concept: 'chief-complaint-uuid', value: 'sad' },
369
+ { concept: 'nationality-uuid', value: 'usa' },
370
+ ],
371
+ }),
372
+ );
373
+ });
374
+
375
+ // FIXME register patient button is missing
376
+ it.skip('retries saving registration obs after a failed attempt', async () => {
377
+ const user = userEvent.setup();
378
+
379
+ mockUseConfig.mockReturnValue(configWithObs);
380
+
381
+ renderWithContext(
382
+ <PatientRegistration isOffline={false} savePatientForm={FormManager.savePatientFormOnline} />,
383
+ ResourcesContextProvider,
384
+ mockResourcesContextValue,
385
+ );
386
+
387
+ await fillRequiredFields();
388
+ const customSection = screen.getByLabelText('Custom Section');
389
+ const weight = within(customSection).getByLabelText('Weight (kg) (optional)');
390
+ await user.type(weight, '-999');
391
+
392
+ mockSaveEncounter.mockRejectedValue({ status: 400, responseBody: { error: { message: 'an error message' } } });
393
+
394
+ const registerPatientButton = screen.getByText(/Register Patient/i);
395
+
396
+ await user.click(registerPatientButton);
397
+
398
+ expect(mockSavePatient).toHaveBeenCalledTimes(1);
399
+ expect(mockSaveEncounter).toHaveBeenCalledTimes(1);
400
+
401
+ expect(mockShowSnackbar).toHaveBeenCalledWith(expect.objectContaining({ subtitle: 'an error message' }));
402
+ mockSaveEncounter.mockResolvedValue({} as FetchResponse);
403
+
404
+ await user.click(registerPatientButton);
405
+ expect(mockSavePatient).toHaveBeenCalledTimes(2);
406
+ expect(mockSaveEncounter).toHaveBeenCalledTimes(2);
407
+
408
+ expect(mockShowSnackbar).toHaveBeenCalledWith(expect.objectContaining({ kind: 'success' }));
409
+ });
410
+ });
411
+
412
+ describe('Updating an existing patient record', () => {
413
+ beforeEach(() => {
414
+ mockUseConfig.mockReturnValue({
415
+ ...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
416
+ ...mockOpenmrsConfig,
417
+ });
418
+ mockUsePatient.mockImplementation(() => {
419
+ return {
420
+ error: null,
421
+ isLoading: false,
422
+ patient: mockPatient,
423
+ patientUuid: mockPatient.id,
424
+ };
425
+ });
426
+ mockSavePatient.mockReturnValue({ data: { uuid: 'new-pt-uuid' }, ok: true });
427
+ mockUseParams.mockReturnValue({ patientUuid: mockPatient.id });
428
+ });
429
+
430
+ it('edits patient demographics', async () => {
431
+ const user = userEvent.setup();
432
+ const mockSavePatientForm = jest.fn();
433
+
434
+ mockUseInitialFormValues.mockReturnValue([
435
+ {
436
+ additionalFamilyName: '',
437
+ additionalGivenName: '',
438
+ additionalMiddleName: '',
439
+ addNameInLocalLanguage: false,
440
+ address: {},
441
+ birthdate: mockPatient.birthDate,
442
+ birthdateEstimated: false,
443
+ deathCause: '',
444
+ deathDate: undefined,
445
+ deathTime: undefined,
446
+ deathTimeFormat: 'AM',
447
+ familyName: mockPatient.name[0].family,
448
+ gender: mockPatient.gender,
449
+ givenName: mockPatient.name[0].given[0],
450
+ identifiers: {
451
+ openMrsId: {
452
+ autoGeneration: false,
453
+ identifierName: 'OpenMRS ID',
454
+ identifierTypeUuid: '05a29f94-c0ed-11e2-94be-8c13b969e334',
455
+ identifierUuid: '1f0ad7a1-430f-4397-b571-59ea654a52db',
456
+ identifierValue: '100GEJ',
457
+ initialValue: '100GEJ',
458
+ preferred: true,
459
+ required: true,
460
+ selectedSource: null,
461
+ },
462
+ idCard: {
463
+ autoGeneration: false,
464
+ identifierName: 'ID Card',
465
+ identifierTypeUuid: 'b4143563-16cd-4439-b288-f83d61670fc8',
466
+ identifierUuid: '346d09b1-8509-43c6-9697-3b4d1ce06ad6',
467
+ identifierValue: '1234567890',
468
+ initialValue: '1234567890',
469
+ preferred: false,
470
+ required: false,
471
+ selectedSource: null,
472
+ },
473
+ },
474
+ isDead: false,
475
+ middleName: '',
476
+ monthsEstimated: 0,
477
+ nonCodedCauseOfDeath: '',
478
+ patientUuid: mockPatient.id,
479
+ relationships: [],
480
+ telephoneNumber: '',
481
+ yearsEstimated: 0,
482
+ } as FormValues,
483
+ jest.fn(),
484
+ ]);
485
+
486
+ renderWithContext(
487
+ <PatientRegistration isOffline={false} savePatientForm={mockSavePatientForm} />,
488
+ ResourcesContextProvider,
489
+ mockResourcesContextValue,
490
+ );
491
+
492
+ await screen.findByRole('heading', { name: /edit patient details/i });
493
+
494
+ expect(screen.queryByRole('button', { name: /register patient/i })).not.toBeInTheDocument();
495
+ expect(screen.getByRole('button', { name: /update patient/i })).toBeInTheDocument();
496
+ expect(screen.getByRole('button', { name: /cancel/i })).toBeInTheDocument();
497
+
498
+ expect(screen.getByLabelText(/first name/i)).toHaveValue(mockPatient.name[0].given[0]);
499
+ expect(screen.getByLabelText(/family name/i)).toHaveValue(mockPatient.name[0].family);
500
+ // FIXME: Fix the mock so that this value is visible
501
+ // expect(screen.getByLabelText(/date of birth/i)).toHaveValue(mockPatient.birthDate);
502
+ expect(
503
+ screen.getByRole('radio', {
504
+ name: /^male$/i,
505
+ }),
506
+ ).toBeChecked();
507
+ expect(
508
+ screen.getByRole('radio', {
509
+ name: /^female$/i,
510
+ }),
511
+ ).not.toBeChecked();
512
+ expect(screen.getAllByRole('tab', { name: /yes/i })).toHaveLength(2);
513
+
514
+ await user.click(screen.getByRole('button', { name: /update patient/i }));
515
+
516
+ expect(mockSavePatientForm).toHaveBeenCalledWith(
517
+ false,
518
+ {
519
+ addNameInLocalLanguage: false,
520
+ additionalFamilyName: '',
521
+ additionalGivenName: '',
522
+ additionalMiddleName: '',
523
+ address: {
524
+ country: 'កម្ពុជា (Cambodia)',
525
+ },
526
+ birthdate: '1972-04-04',
527
+ birthdateEstimated: false,
528
+ deathCause: '',
529
+ nonCodedCauseOfDeath: '',
530
+ deathDate: undefined,
531
+ deathTime: undefined,
532
+ deathTimeFormat: 'AM',
533
+ familyName: 'Wilson',
534
+ gender: 'male',
535
+ givenName: 'John',
536
+ identifiers: {
537
+ idCard: {
538
+ autoGeneration: false,
539
+ identifierName: 'ID Card',
540
+ identifierTypeUuid: 'b4143563-16cd-4439-b288-f83d61670fc8',
541
+ identifierUuid: '346d09b1-8509-43c6-9697-3b4d1ce06ad6',
542
+ identifierValue: '1234567890',
543
+ initialValue: '1234567890',
544
+ preferred: false,
545
+ required: false,
546
+ selectedSource: null,
547
+ },
548
+ openMrsId: {
549
+ autoGeneration: false,
550
+ identifierName: 'OpenMRS ID',
551
+ identifierTypeUuid: '05a29f94-c0ed-11e2-94be-8c13b969e334',
552
+ identifierUuid: '1f0ad7a1-430f-4397-b571-59ea654a52db',
553
+ identifierValue: '100GEJ',
554
+ initialValue: '100GEJ',
555
+ preferred: true,
556
+ required: true,
557
+ selectedSource: null,
558
+ },
559
+ },
560
+ isDead: false,
561
+ middleName: '',
562
+ monthsEstimated: 0,
563
+ patientUuid: '8673ee4f-e2ab-4077-ba55-4980f408773e',
564
+ relationships: [],
565
+ telephoneNumber: '',
566
+ unidentifiedPatient: undefined,
567
+ yearsEstimated: 0,
568
+ },
569
+ expect.anything(),
570
+ expect.anything(),
571
+ null,
572
+ undefined,
573
+ expect.anything(),
574
+ expect.anything(),
575
+ expect.anything(),
576
+ { patientSaved: false },
577
+ expect.anything(),
578
+ );
579
+ });
580
+ });