@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,53 @@
1
+ import React from 'react';
2
+ import { reportError, useConfig } from '@openmrs/esm-framework';
3
+ import { builtInFields, type RegistrationConfig } from '../../config-schema';
4
+ import { AddressComponent } from './address/address-field.component';
5
+ import { CauseOfDeathField } from './cause-of-death/cause-of-death.component';
6
+ import { CustomField } from './custom-field.component';
7
+ import { DateAndTimeOfDeathField } from './date-and-time-of-death/date-and-time-of-death.component';
8
+ import { DobField } from './dob/dob.component';
9
+ import { GenderField } from './gender/gender-field.component';
10
+ import { Identifiers } from './id/id-field.component';
11
+ import { NameField } from './name/name-field.component';
12
+ import { PhoneField } from './phone/phone-field.component';
13
+
14
+ export interface FieldProps {
15
+ name: string;
16
+ }
17
+
18
+ export function Field({ name }: FieldProps) {
19
+ const config = useConfig<RegistrationConfig>();
20
+ if (
21
+ !(builtInFields as ReadonlyArray<string>).includes(name) &&
22
+ !config.fieldDefinitions.some((def) => def.id == name)
23
+ ) {
24
+ reportError(
25
+ `Invalid field name '${name}'. Valid options are '${config.fieldDefinitions
26
+ .map((def) => def.id)
27
+ .concat(builtInFields)
28
+ .join("', '")}'.`,
29
+ );
30
+ return null;
31
+ }
32
+
33
+ switch (name) {
34
+ case 'name':
35
+ return <NameField />;
36
+ case 'gender':
37
+ return <GenderField />;
38
+ case 'dob':
39
+ return <DobField />;
40
+ case 'dateAndTimeOfDeath':
41
+ return <DateAndTimeOfDeathField />;
42
+ case 'causeOfDeath':
43
+ return <CauseOfDeathField />;
44
+ case 'address':
45
+ return <AddressComponent />;
46
+ case 'id':
47
+ return <Identifiers />;
48
+ case 'phone':
49
+ return <PhoneField />;
50
+ default:
51
+ return <CustomField name={name} />;
52
+ }
53
+ }
@@ -0,0 +1,42 @@
1
+ import { type FetchResponse, openmrsFetch, restBaseUrl, showSnackbar } from '@openmrs/esm-framework';
2
+ import useSWRImmutable from 'swr/immutable';
3
+ import { type ConceptAnswers, type ConceptResponse } from '../patient-registration.types';
4
+ import { useMemo } from 'react';
5
+
6
+ export function useConcept(conceptUuid: string): { data: ConceptResponse; isLoading: boolean } {
7
+ const shouldFetch = typeof conceptUuid === 'string' && conceptUuid !== '';
8
+ const { data, error, isLoading } = useSWRImmutable<FetchResponse<ConceptResponse>, Error>(
9
+ shouldFetch ? `${restBaseUrl}/concept/${conceptUuid}` : null,
10
+ openmrsFetch,
11
+ );
12
+ if (error) {
13
+ showSnackbar({
14
+ title: error.name,
15
+ subtitle: error.message,
16
+ kind: 'error',
17
+ });
18
+ }
19
+ const results = useMemo(() => ({ data: data?.data, isLoading }), [data, isLoading]);
20
+ return results;
21
+ }
22
+
23
+ export function useConceptAnswers(conceptUuid: string): {
24
+ data: Array<ConceptAnswers>;
25
+ isLoading: boolean;
26
+ error: Error;
27
+ } {
28
+ const shouldFetch = typeof conceptUuid === 'string' && conceptUuid !== '';
29
+ const { data, error, isLoading } = useSWRImmutable<FetchResponse<ConceptResponse>, Error>(
30
+ shouldFetch ? `${restBaseUrl}/concept/${conceptUuid}` : null,
31
+ openmrsFetch,
32
+ );
33
+ if (error) {
34
+ showSnackbar({
35
+ title: error.name,
36
+ subtitle: error.message,
37
+ kind: 'error',
38
+ });
39
+ }
40
+ const results = useMemo(() => ({ data: data?.data?.answers, isLoading, error }), [isLoading, error, data]);
41
+ return results;
42
+ }
@@ -0,0 +1,171 @@
1
+ @use '@carbon/colors';
2
+ @use '@carbon/layout';
3
+ @use '@carbon/type';
4
+ @use '@openmrs/esm-styleguide/src/vars' as *;
5
+
6
+ .productiveHeading02 {
7
+ @include type.type-style('heading-compact-02');
8
+ margin-bottom: layout.$spacing-05;
9
+ }
10
+
11
+ .productiveHeading02Light {
12
+ @include type.type-style('heading-compact-02');
13
+ margin-bottom: layout.$spacing-05;
14
+ color: colors.$gray-70;
15
+ }
16
+
17
+ .label01 {
18
+ @include type.type-style('label-01');
19
+ }
20
+
21
+ .grid {
22
+ display: grid;
23
+ grid-template-columns: 1fr 1fr;
24
+ column-gap: layout.$spacing-05;
25
+ }
26
+
27
+ .halfWidthInDesktopView {
28
+ width: calc(50% - layout.$spacing-05);
29
+ }
30
+
31
+ .patientPhoto {
32
+ display: flex;
33
+ justify-content: center;
34
+ }
35
+
36
+ .nameField {
37
+ grid-row: 1;
38
+ grid-column: 1;
39
+ }
40
+
41
+ .nameField > :global(.cds--content-switcher) {
42
+ display: grid;
43
+ grid-template-columns: 1fr 1fr;
44
+ width: max-content;
45
+ justify-content: flex-start;
46
+ }
47
+
48
+ .contentSwitcher {
49
+ margin-bottom: layout.$spacing-05;
50
+ }
51
+
52
+ .dobField > :global(.cds--content-switcher) {
53
+ display: grid;
54
+ grid-template-columns: 1fr 1fr;
55
+ width: max-content;
56
+ justify-content: flex-start;
57
+ }
58
+
59
+ .photoExtension {
60
+ margin-bottom: layout.$spacing-05;
61
+ grid-row: 1;
62
+ grid-column: 2;
63
+ justify-self: center;
64
+ }
65
+
66
+ .sexField,
67
+ .dobField,
68
+ .dodField {
69
+ margin-bottom: layout.$spacing-05;
70
+
71
+ span {
72
+ display: flex;
73
+ flex-flow: row nowrap;
74
+ justify-content: space-between;
75
+ align-items: start;
76
+ }
77
+ }
78
+
79
+ .nonCodedCauseOfDeath {
80
+ margin-top: layout.$spacing-04;
81
+ }
82
+
83
+ .timeOfDeathContainer {
84
+ display: flex;
85
+ align-items: center;
86
+ }
87
+
88
+ .timeOfDeathField {
89
+ flex: none;
90
+ margin-left: layout.$spacing-02;
91
+ }
92
+
93
+ .dobContentSwitcherLabel {
94
+ margin-bottom: layout.$spacing-03;
95
+ }
96
+
97
+ .identifierLabelText {
98
+ display: flex;
99
+ align-items: center;
100
+ }
101
+
102
+ .arrowRightIcon {
103
+ fill: currentColor !important;
104
+ }
105
+
106
+ .configureIdentifiersButton {
107
+ display: flex;
108
+ align-items: center;
109
+ margin: 0 0 layout.$spacing-05 layout.$spacing-05;
110
+
111
+ svg {
112
+ margin-left: layout.$spacing-03;
113
+ }
114
+
115
+ .customField {
116
+ margin-bottom: layout.$spacing-05;
117
+ }
118
+ }
119
+
120
+ .attributeField {
121
+ margin-bottom: layout.$spacing-05;
122
+ }
123
+
124
+ .locationAttributeFieldContainer {
125
+ position: relative;
126
+
127
+ .loadingContainer {
128
+ background-color: colors.$white;
129
+ position: absolute;
130
+ right: layout.$spacing-07;
131
+ bottom: layout.$spacing-02;
132
+ }
133
+ }
134
+
135
+ :global(.omrs-breakpoint-lt-desktop) {
136
+ .grid {
137
+ grid-template-columns: 1fr;
138
+ grid-template-rows: auto auto;
139
+ }
140
+
141
+ .nameField {
142
+ grid-row: 2;
143
+ grid-column: 1;
144
+ }
145
+
146
+ .photoExtension {
147
+ grid-column: 1;
148
+ grid-row: 1;
149
+ justify-self: start;
150
+ }
151
+
152
+ .radioButton label {
153
+ height: layout.$spacing-09 !important;
154
+ }
155
+
156
+ .halfWidthInDesktopView {
157
+ width: 100%;
158
+ }
159
+ }
160
+
161
+ .radioFieldError {
162
+ color: colors.$red-60;
163
+ display: block;
164
+ font-weight: 400;
165
+ max-height: 12.5rem;
166
+ overflow: visible;
167
+ font-size: layout.$spacing-04;
168
+ letter-spacing: 0.32px;
169
+ line-height: 1.34;
170
+ margin: layout.$spacing-02 0 0;
171
+ }
@@ -0,0 +1,330 @@
1
+ import React from 'react';
2
+ import { Form, Formik } from 'formik';
3
+ import { render, screen } from '@testing-library/react';
4
+ import { getDefaultsFromConfigSchema, useConfig } from '@openmrs/esm-framework';
5
+ import { Field } from './field.component';
6
+ import { esmPatientRegistrationSchema, type RegistrationConfig } from '../../config-schema';
7
+ import { type Resources } from '../../offline.resources';
8
+ import type { AddressTemplate, FormValues } from '../patient-registration.types';
9
+ import { PatientRegistrationContextProvider } from '../patient-registration-context';
10
+ import { ResourcesContextProvider } from '../../resources-context';
11
+ import { renderWithContext } from 'tools';
12
+
13
+ const mockUseConfig = jest.mocked(useConfig<RegistrationConfig>);
14
+
15
+ const predefinedAddressTemplate = {
16
+ uuid: 'test-address-template-uuid',
17
+ property: 'layout.address.format',
18
+ description: 'Test Address Template',
19
+ display:
20
+ 'Layout - Address Format = <org.openmrs.layout.address.AddressTemplate>\n <nameMappings class="properties">\n <property name="postalCode" value="Location.postalCode"/>\n <property name="address2" value="Location.address2"/>\n <property name="address1" value="Location.address1"/>\n <property name="country" value="Location.country"/>\n <property name="stateProvince" value="Location.stateProvince"/>\n <property name="cityVillage" value="Location.cityVillage"/>\n </nameMappings>\n <sizeMappings class="properties">\n <property name="postalCode" value="10"/>\n <property name="address2" value="40"/>\n <property name="address1" value="40"/>\n <property name="country" value="10"/>\n <property name="stateProvince" value="10"/>\n <property name="cityVillage" value="10"/>\n </sizeMappings>\n <lineByLineFormat>\n <string>address1</string>\n <string>address2</string>\n <string>cityVillage stateProvince country postalCode</string>\n </lineByLineFormat>\n </org.openmrs.layout.address.AddressTemplate>',
21
+ value:
22
+ '<org.openmrs.layout.address.AddressTemplate>\r\n <nameMappings class="properties">\r\n <property name="postalCode" value="Location.postalCode"/>\r\n <property name="address2" value="Location.address2"/>\r\n <property name="address1" value="Location.address1"/>\r\n <property name="country" value="Location.country"/>\r\n <property name="stateProvince" value="Location.stateProvince"/>\r\n <property name="cityVillage" value="Location.cityVillage"/>\r\n </nameMappings>\r\n <sizeMappings class="properties">\r\n <property name="postalCode" value="4"/>\r\n <property name="address1" value="40"/>\r\n <property name="address2" value="40"/>\r\n <property name="country" value="10"/>\r\n <property name="stateProvince" value="10"/>\r\n <property name="cityVillage" value="10"/>\r\n <asset name="cityVillage" value="10"/>\r\n </sizeMappings>\r\n <lineByLineFormat>\r\n <string>address1 address2</string>\r\n <string>cityVillage stateProvince postalCode</string>\r\n <string>country</string>\r\n </lineByLineFormat>\r\n <elementDefaults class="properties">\r\n <property name="country" value=""/>\r\n </elementDefaults>\r\n <elementRegex class="properties">\r\n <property name="address1" value="[a-zA-Z]+$"/>\r\n </elementRegex>\r\n <elementRegexFormats class="properties">\r\n <property name="address1" value="Countries can only be letters"/>\r\n </elementRegexFormats>\r\n </org.openmrs.layout.address.AddressTemplate>',
23
+ };
24
+
25
+ const mockIdentifierTypes = [
26
+ {
27
+ fieldName: 'openMrsId',
28
+ format: '',
29
+ identifierSources: [
30
+ {
31
+ uuid: '8549f706-7e85-4c1d-9424-217d50a2988b',
32
+ name: 'Generator for OpenMRS ID',
33
+ description: 'Generator for OpenMRS ID',
34
+ baseCharacterSet: '0123456789ACDEFGHJKLMNPRTUVWXY',
35
+ prefix: '',
36
+ },
37
+ ],
38
+ isPrimary: true,
39
+ name: 'OpenMRS ID',
40
+ required: true,
41
+ uniquenessBehavior: 'UNIQUE' as const,
42
+ uuid: '05a29f94-c0ed-11e2-94be-8c13b969e334',
43
+ },
44
+ {
45
+ fieldName: 'idCard',
46
+ format: '',
47
+ identifierSources: [],
48
+ isPrimary: false,
49
+ name: 'ID Card',
50
+ required: false,
51
+ uniquenessBehavior: 'UNIQUE' as const,
52
+ uuid: 'b4143563-16cd-4439-b288-f83d61670fc8',
53
+ },
54
+ {
55
+ fieldName: 'legacyId',
56
+ format: '',
57
+ identifierSources: [],
58
+ isPrimary: false,
59
+ name: 'Legacy ID',
60
+ required: false,
61
+ uniquenessBehavior: null,
62
+ uuid: '22348099-3873-459e-a32e-d93b17eda533',
63
+ },
64
+ {
65
+ fieldName: 'oldIdentificationNumber',
66
+ format: '',
67
+ identifierSources: [],
68
+ isPrimary: false,
69
+ name: 'Old Identification Number',
70
+ required: false,
71
+ uniquenessBehavior: null,
72
+ uuid: '8d79403a-c2cc-11de-8d13-0010c6dffd0f',
73
+ },
74
+ {
75
+ fieldName: 'openMrsIdentificationNumber',
76
+ format: '',
77
+ identifierSources: [],
78
+ isPrimary: false,
79
+ name: 'OpenMRS Identification Number',
80
+ required: false,
81
+ uniquenessBehavior: null,
82
+ uuid: '8d793bee-c2cc-11de-8d13-0010c6dffd0f',
83
+ },
84
+ ];
85
+
86
+ const mockResourcesContextValue: Resources = {
87
+ addressTemplate: predefinedAddressTemplate as unknown as AddressTemplate,
88
+ currentSession: {
89
+ authenticated: true,
90
+ sessionId: 'JSESSION',
91
+ currentProvider: { uuid: 'provider-uuid', identifier: 'PRO-123' },
92
+ },
93
+ relationshipTypes: [],
94
+ identifierTypes: [...mockIdentifierTypes],
95
+ };
96
+
97
+ const initialContextValues = {
98
+ currentPhoto: 'data:image/png;base64,1234567890',
99
+ identifierTypes: [],
100
+ inEditMode: false,
101
+ initialFormValues: {} as FormValues,
102
+ isOffline: false,
103
+ setCapturePhotoProps: jest.fn(),
104
+ setFieldValue: jest.fn(),
105
+ setFieldTouched: jest.fn(),
106
+ setInitialFormValues: jest.fn(),
107
+ validationSchema: null,
108
+ values: {} as FormValues,
109
+ };
110
+
111
+ describe('Field', () => {
112
+ beforeEach(() => {
113
+ mockUseConfig.mockReturnValue({
114
+ ...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
115
+ });
116
+ });
117
+
118
+ it('should render NameField component when name prop is "name"', () => {
119
+ mockUseConfig.mockReturnValue({
120
+ ...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
121
+ fieldConfigurations: {
122
+ name: {
123
+ allowUnidentifiedPatients: true,
124
+ displayMiddleName: true,
125
+ defaultUnknownGivenName: 'UNKNOWN',
126
+ defaultUnknownFamilyName: 'UNKNOWN',
127
+ },
128
+ } as RegistrationConfig['fieldConfigurations'],
129
+ });
130
+
131
+ renderWithContext(
132
+ <Formik initialValues={{}} onSubmit={jest.fn()}>
133
+ <Form>
134
+ <PatientRegistrationContextProvider value={initialContextValues}>
135
+ <Field name="name" />
136
+ </PatientRegistrationContextProvider>
137
+ </Form>
138
+ </Formik>,
139
+ ResourcesContextProvider,
140
+ mockResourcesContextValue,
141
+ );
142
+
143
+ expect(screen.getByText('Full Name')).toBeInTheDocument();
144
+ });
145
+
146
+ it('should render GenderField component when name prop is "gender"', () => {
147
+ mockUseConfig.mockReturnValue({
148
+ ...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
149
+ fieldConfigurations: {
150
+ gender: [
151
+ {
152
+ value: 'Male',
153
+ label: 'Male',
154
+ id: 'male',
155
+ },
156
+ ],
157
+ } as unknown as RegistrationConfig['fieldConfigurations'],
158
+ });
159
+
160
+ renderWithContext(
161
+ <Formik initialValues={{}} onSubmit={jest.fn()}>
162
+ <Form>
163
+ <PatientRegistrationContextProvider value={initialContextValues}>
164
+ <Field name="gender" />
165
+ </PatientRegistrationContextProvider>
166
+ </Form>
167
+ </Formik>,
168
+ ResourcesContextProvider,
169
+ mockResourcesContextValue,
170
+ );
171
+ expect(screen.getByLabelText('Male')).toBeInTheDocument();
172
+ });
173
+
174
+ it('should render DobField component when name prop is "dob"', () => {
175
+ renderWithContext(
176
+ <Formik initialValues={{}} onSubmit={jest.fn()}>
177
+ <Form>
178
+ <PatientRegistrationContextProvider value={initialContextValues}>
179
+ <Field name="dob" />
180
+ </PatientRegistrationContextProvider>
181
+ </Form>
182
+ </Formik>,
183
+ ResourcesContextProvider,
184
+ mockResourcesContextValue,
185
+ );
186
+
187
+ expect(screen.getByText('Birth')).toBeInTheDocument();
188
+ });
189
+
190
+ it('should render AddressComponent component when name prop is "address"', () => {
191
+ jest.mock('./address/address-hierarchy.resource', () => ({
192
+ ...jest.requireActual('../address-hierarchy.resource'),
193
+ useOrderedAddressHierarchyLevels: jest.fn(),
194
+ }));
195
+
196
+ mockUseConfig.mockReturnValue({
197
+ ...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
198
+ fieldConfigurations: {
199
+ address: {
200
+ useAddressHierarchy: {
201
+ enabled: false,
202
+ useQuickSearch: false,
203
+ searchAddressByLevel: false,
204
+ },
205
+ requiredAddressFields: [],
206
+ },
207
+ } as RegistrationConfig['fieldConfigurations'],
208
+ });
209
+
210
+ renderWithContext(
211
+ <Formik initialValues={{}} onSubmit={jest.fn()}>
212
+ <Form>
213
+ <PatientRegistrationContextProvider value={initialContextValues}>
214
+ <Field name="address" />
215
+ </PatientRegistrationContextProvider>
216
+ </Form>
217
+ </Formik>,
218
+ ResourcesContextProvider,
219
+ mockResourcesContextValue,
220
+ );
221
+
222
+ expect(screen.getByText('Address')).toBeInTheDocument();
223
+ });
224
+
225
+ it('should render Identifiers component when name prop is "id"', () => {
226
+ mockUseConfig.mockReturnValue({
227
+ ...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
228
+ defaultPatientIdentifierTypes: ['OpenMRS ID'],
229
+ });
230
+
231
+ const openmrsID = {
232
+ name: 'OpenMRS ID',
233
+ fieldName: 'openMrsId',
234
+ required: true,
235
+ uuid: '05a29f94-c0ed-11e2-94be-8c13b969e334',
236
+ format: null,
237
+ isPrimary: true,
238
+ identifierSources: [
239
+ {
240
+ uuid: '691eed12-c0f1-11e2-94be-8c13b969e334',
241
+ name: 'Generator 1 for OpenMRS ID',
242
+ autoGenerationOption: {
243
+ manualEntryEnabled: false,
244
+ automaticGenerationEnabled: true,
245
+ },
246
+ },
247
+ {
248
+ uuid: '01af8526-cea4-4175-aa90-340acb411771',
249
+ name: 'Generator 2 for OpenMRS ID',
250
+ autoGenerationOption: {
251
+ manualEntryEnabled: true,
252
+ automaticGenerationEnabled: true,
253
+ },
254
+ },
255
+ ],
256
+ identifierUuid: 'openmrs-identifier-uuid',
257
+ identifierTypeUuid: 'openmrs-id-identifier-type-uuid',
258
+ initialValue: '12345',
259
+ identifierValue: '12345',
260
+ identifierName: 'OpenMRS ID',
261
+ preferred: true,
262
+ selectedSource: {
263
+ uuid: 'openmrs-id-selected-source-uuid',
264
+ name: 'Generator 1 for OpenMRS ID',
265
+ autoGenerationOption: {
266
+ manualEntryEnabled: false,
267
+ automaticGenerationEnabled: true,
268
+ },
269
+ },
270
+ autoGenerationSource: null,
271
+ };
272
+
273
+ const updatedContextValues = {
274
+ currentPhoto: 'data:image/png;base64,1234567890',
275
+ identifierTypes: [],
276
+ inEditMode: false,
277
+ initialFormValues: { identifiers: { openmrsID } } as unknown as FormValues,
278
+ isOffline: false,
279
+ setCapturePhotoProps: jest.fn(),
280
+ setFieldValue: jest.fn(),
281
+ setInitialFormValues: jest.fn(),
282
+ validationSchema: null,
283
+ values: { identifiers: { openmrsID } } as unknown as FormValues,
284
+ setFieldTouched: jest.fn(),
285
+ };
286
+
287
+ renderWithContext(
288
+ <Formik initialValues={{}} onSubmit={jest.fn()}>
289
+ <Form>
290
+ <PatientRegistrationContextProvider value={updatedContextValues}>
291
+ <Field name="id" />
292
+ </PatientRegistrationContextProvider>
293
+ </Form>
294
+ </Formik>,
295
+ ResourcesContextProvider,
296
+ mockResourcesContextValue,
297
+ );
298
+ expect(screen.getByText('Identifiers')).toBeInTheDocument();
299
+ });
300
+
301
+ it('should return null and report an error for an invalid field name', () => {
302
+ const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
303
+
304
+ mockUseConfig.mockReturnValue({
305
+ ...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
306
+ fieldDefinitions: [{ id: 'weight' }] as RegistrationConfig['fieldDefinitions'],
307
+ });
308
+
309
+ let error = null;
310
+
311
+ try {
312
+ renderWithContext(
313
+ <Formik initialValues={{}} onSubmit={jest.fn()}>
314
+ <Form>
315
+ <Field name="invalidField" />
316
+ </Form>
317
+ </Formik>,
318
+ ResourcesContextProvider,
319
+ mockResourcesContextValue,
320
+ );
321
+ } catch (err) {
322
+ error = err;
323
+ }
324
+
325
+ expect(error).toMatch(/Invalid field name 'invalidField'. Valid options are /);
326
+ expect(screen.queryByTestId('invalid-field')).not.toBeInTheDocument();
327
+
328
+ consoleError.mockRestore();
329
+ });
330
+ });
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import { RadioButton, RadioButtonGroup } from '@carbon/react';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { useField } from 'formik';
5
+ import { type RegistrationConfig } from '../../../config-schema';
6
+ import { usePatientRegistrationContext } from '../../patient-registration-context';
7
+ import { useConfig } from '@openmrs/esm-framework';
8
+ import styles from '../field.scss';
9
+
10
+ export const GenderField: React.FC = () => {
11
+ const { t } = useTranslation();
12
+ const { fieldConfigurations } = useConfig<RegistrationConfig>();
13
+ const { setFieldValue, setFieldTouched } = usePatientRegistrationContext();
14
+ const [field, meta] = useField('gender');
15
+ const fieldConfigs = fieldConfigurations?.gender;
16
+
17
+ const setGender = (gender: string) => {
18
+ setFieldValue('gender', gender);
19
+ setFieldTouched('gender', true, false);
20
+ };
21
+ /**
22
+ * DO NOT REMOVE THIS COMMENT HERE, ADDS TRANSLATION FOR SEX OPTIONS
23
+ * t('male', 'Male')
24
+ * t('female', 'Female')
25
+ * t('other', 'Other')
26
+ * t('unknown', 'Unknown')
27
+ */
28
+
29
+ return (
30
+ <div className={styles.halfWidthInDesktopView}>
31
+ <h4 className={styles.productiveHeading02Light}>{t('sexFieldLabelText', 'Sex')}</h4>
32
+ <div className={styles.sexField}>
33
+ <RadioButtonGroup
34
+ name="gender"
35
+ legendText={t('genderLabelText', 'Sex')}
36
+ orientation="vertical"
37
+ onChange={setGender}
38
+ valueSelected={field.value}>
39
+ {fieldConfigs.map((option) => (
40
+ <RadioButton
41
+ id={`gender-option-${option.value}`}
42
+ key={option.label ?? option.value}
43
+ labelText={t(option.label ?? option.value, option.label ?? option.value)}
44
+ value={option.value}
45
+ />
46
+ ))}
47
+ </RadioButtonGroup>
48
+ {meta.touched && meta.error && (
49
+ <div className={styles.radioFieldError}>{t(meta.error, 'Gender is required')}</div>
50
+ )}
51
+ </div>
52
+ </div>
53
+ );
54
+ };