@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,234 @@
1
+ import React, { useCallback, useEffect, useId, useState } from 'react';
2
+ import { ActionableNotification, Button, Layer, Select, SelectItem, SkeletonText } from '@carbon/react';
3
+ import { TrashCan } from '@carbon/react/icons';
4
+ import { FieldArray } from 'formik';
5
+ import { useTranslation } from 'react-i18next';
6
+ import { Autosuggest } from '../../input/custom-input/autosuggest/autosuggest.component';
7
+ import { usePatientRegistrationContext } from '../../patient-registration-context';
8
+ import { fetchPerson } from '../../patient-registration.resource';
9
+ import { useResourcesContext } from '../../../resources-context';
10
+ import { type RelationshipValue } from '../../patient-registration.types';
11
+ import sectionStyles from '../section.scss';
12
+ import styles from './relationships.scss';
13
+
14
+ interface RelationshipType {
15
+ display: string;
16
+ uuid: string;
17
+ direction: string;
18
+ }
19
+
20
+ interface RelationshipViewProps {
21
+ relationship: RelationshipValue;
22
+ index: number;
23
+ displayRelationshipTypes: RelationshipType[];
24
+ remove: <T>(index: number) => T;
25
+ }
26
+
27
+ const RelationshipView: React.FC<RelationshipViewProps> = ({
28
+ relationship,
29
+ index,
30
+ displayRelationshipTypes,
31
+ remove,
32
+ }) => {
33
+ const { t } = useTranslation();
34
+ const { setFieldValue } = usePatientRegistrationContext();
35
+ const [isInvalid, setIsInvalid] = useState(false);
36
+ const newRelationship = !relationship.uuid;
37
+ const selectId = useId();
38
+
39
+ const handleRelationshipTypeChange = useCallback(
40
+ (event) => {
41
+ const { target } = event;
42
+ const field = target.name;
43
+ const value = target.options[target.selectedIndex].value;
44
+ setFieldValue(field, value);
45
+ if (!relationship?.action) {
46
+ setFieldValue(`relationships[${index}].action`, 'UPDATE');
47
+ }
48
+ },
49
+ [index, relationship?.action, setFieldValue],
50
+ );
51
+
52
+ const handleSuggestionSelected = useCallback(
53
+ (field: string, selectedSuggestion: string) => {
54
+ setIsInvalid(!selectedSuggestion);
55
+ setFieldValue(field, selectedSuggestion);
56
+ },
57
+ [setFieldValue],
58
+ );
59
+
60
+ const searchPerson = async (query: string) => {
61
+ const abortController = new AbortController();
62
+ return await fetchPerson(query, abortController);
63
+ };
64
+
65
+ const deleteRelationship = useCallback(() => {
66
+ if (relationship.action === 'ADD') {
67
+ remove(index);
68
+ } else {
69
+ setFieldValue(`relationships[${index}].action`, 'DELETE');
70
+ }
71
+ }, [relationship, index, remove, setFieldValue]);
72
+
73
+ const restoreRelationship = useCallback(() => {
74
+ setFieldValue(`relationships[${index}]`, {
75
+ ...relationship,
76
+ action: undefined,
77
+ relationshipType: relationship.initialrelationshipTypeValue,
78
+ });
79
+ }, [index, setFieldValue, relationship]);
80
+
81
+ return relationship.action !== 'DELETE' ? (
82
+ <div className={styles.relationship}>
83
+ <div className={styles.searchBox}>
84
+ <div className={styles.relationshipHeader}>
85
+ <h4 className={styles.productiveHeading}>{t('relationshipPlaceholder', 'Relationship')}</h4>
86
+ <Button
87
+ kind="ghost"
88
+ iconDescription={t('deleteRelationshipTooltipText', 'Delete')}
89
+ hasIconOnly
90
+ onClick={deleteRelationship}>
91
+ <TrashCan size={16} className={styles.trashCan} />
92
+ </Button>
93
+ </div>
94
+ <div>
95
+ {newRelationship ? (
96
+ <Autosuggest
97
+ id={`relationships[${index}].relatedPersonUuid`}
98
+ labelText={t('relativeFullNameLabelText', 'Full name')}
99
+ placeholder={t('relativeNamePlaceholder', 'Firstname Familyname')}
100
+ defaultValue={relationship.relatedPersonName}
101
+ onSuggestionSelected={handleSuggestionSelected}
102
+ invalid={isInvalid}
103
+ invalidText={t('relationshipPersonMustExist', 'Related person must be an existing person')}
104
+ getSearchResults={searchPerson}
105
+ getDisplayValue={(item) => item.display}
106
+ getFieldValue={(item) => item.uuid}
107
+ />
108
+ ) : (
109
+ <>
110
+ <span className={styles.labelText}>{t('relativeFullNameLabelText', 'Full name')}</span>
111
+ <p className={styles.bodyShort02}>{relationship.relatedPersonName}</p>
112
+ </>
113
+ )}
114
+ </div>
115
+ </div>
116
+ <div className={styles.selectRelationshipType} style={{ marginBottom: '1rem' }}>
117
+ <Layer>
118
+ <Select
119
+ id={selectId}
120
+ labelText={t('relationship', 'Relationship')}
121
+ onChange={handleRelationshipTypeChange}
122
+ name={`relationships[${index}].relationshipType`}
123
+ defaultValue={relationship?.relationshipType ?? 'placeholder-item'}>
124
+ <SelectItem
125
+ disabled
126
+ hidden
127
+ value="placeholder-item"
128
+ text={t('relationshipToPatient', 'Relationship to patient')}
129
+ />
130
+ {displayRelationshipTypes.map((relationshipType, index) => (
131
+ <SelectItem
132
+ text={relationshipType.display}
133
+ value={`${relationshipType.uuid}/${relationshipType.direction}`}
134
+ key={`relationship-${relationshipType.uuid}-${index}`}
135
+ />
136
+ ))}
137
+ </Select>
138
+ </Layer>
139
+ </div>
140
+ </div>
141
+ ) : (
142
+ <ActionableNotification
143
+ kind="info"
144
+ title={t('relationshipRemovedText', 'Relationship removed')}
145
+ actionButtonLabel={t('restoreRelationshipActionButton', 'Undo')}
146
+ onActionButtonClick={restoreRelationship}
147
+ />
148
+ );
149
+ };
150
+
151
+ export const RelationshipsSection = () => {
152
+ const { relationshipTypes } = useResourcesContext();
153
+ const [displayRelationshipTypes, setDisplayRelationshipTypes] = useState<RelationshipType[]>([]);
154
+ const { t } = useTranslation();
155
+
156
+ useEffect(() => {
157
+ if (relationshipTypes) {
158
+ const tmp: RelationshipType[] = [];
159
+ relationshipTypes.results.forEach((type) => {
160
+ const aIsToB = {
161
+ display: type.displayAIsToB ? type.displayAIsToB : type.displayBIsToA,
162
+ uuid: type.uuid,
163
+ direction: 'aIsToB',
164
+ };
165
+ const bIsToA = {
166
+ display: type.displayBIsToA ? type.displayBIsToA : type.displayAIsToB,
167
+ uuid: type.uuid,
168
+ direction: 'bIsToA',
169
+ };
170
+ if (aIsToB.display === bIsToA.display) {
171
+ tmp.push(aIsToB);
172
+ } else if (bIsToA.display === 'Patient') {
173
+ tmp.push(aIsToB, { display: `Patient (${aIsToB.display})`, uuid: type.uuid, direction: 'bIsToA' });
174
+ } else {
175
+ tmp.push(aIsToB, bIsToA);
176
+ }
177
+ });
178
+ setDisplayRelationshipTypes(tmp);
179
+ }
180
+ }, [relationshipTypes]);
181
+
182
+ if (!relationshipTypes) {
183
+ return (
184
+ <section aria-label="Loading relationships section">
185
+ <SkeletonText
186
+ // @ts-expect-error
187
+ role="progressbar"
188
+ />
189
+ </section>
190
+ );
191
+ }
192
+
193
+ return (
194
+ <section aria-label="Relationships section">
195
+ <FieldArray name="relationships">
196
+ {({
197
+ push,
198
+ remove,
199
+ form: {
200
+ values: { relationships },
201
+ },
202
+ }) => (
203
+ <div>
204
+ {relationships && relationships.length > 0
205
+ ? relationships.map((relationship: RelationshipValue, index) => (
206
+ <div key={index} className={sectionStyles.formSection}>
207
+ <RelationshipView
208
+ relationship={relationship}
209
+ index={index}
210
+ displayRelationshipTypes={displayRelationshipTypes}
211
+ key={index}
212
+ remove={remove}
213
+ />
214
+ </div>
215
+ ))
216
+ : null}
217
+ <div className={styles.actions}>
218
+ <Button
219
+ kind="ghost"
220
+ onClick={() =>
221
+ push({
222
+ relatedPersonUuid: '',
223
+ action: 'ADD',
224
+ })
225
+ }>
226
+ {t('addRelationshipButtonText', 'Add Relationship')}
227
+ </Button>
228
+ </div>
229
+ </div>
230
+ )}
231
+ </FieldArray>
232
+ </section>
233
+ );
234
+ };
@@ -0,0 +1,113 @@
1
+ import React from 'react';
2
+ import { Form, Formik } from 'formik';
3
+ import { screen } from '@testing-library/react';
4
+ import { type Resources } from '../../../offline.resources';
5
+ import { type FormValues } from '../../patient-registration.types';
6
+ import { PatientRegistrationContextProvider } from '../../patient-registration-context';
7
+ import { RelationshipsSection } from './relationships-section.component';
8
+ import { ResourcesContextProvider } from '../../../resources-context';
9
+ import { renderWithContext } from 'tools';
10
+
11
+ jest.mock('../../patient-registration.resource', () => ({
12
+ fetchPerson: jest.fn().mockResolvedValue({
13
+ data: {
14
+ results: [
15
+ { uuid: '42ae5ce0-d64b-11ea-9064-5adc43bbdd24', display: 'Person 1' },
16
+ { uuid: '691eed12-c0f1-11e2-94be-8c13b969e334', display: 'Person 2' },
17
+ ],
18
+ },
19
+ }),
20
+ }));
21
+
22
+ let mockResourcesContextValue = {
23
+ addressTemplate: null,
24
+ currentSession: {
25
+ authenticated: true,
26
+ sessionId: 'JSESSION',
27
+ currentProvider: { uuid: '45ce6c2e-dd5a-11e6-9d9c-0242ac150002', identifier: 'PRO-123' },
28
+ },
29
+ identifierTypes: [],
30
+ relationshipTypes: null,
31
+ } as Resources;
32
+
33
+ const initialContextValues = {
34
+ currentPhoto: 'data:image/png;base64,1234567890',
35
+ identifierTypes: [],
36
+ inEditMode: false,
37
+ initialFormValues: {} as FormValues,
38
+ isOffline: false,
39
+ setCapturePhotoProps: jest.fn(),
40
+ setFieldValue: jest.fn(),
41
+ setFieldTouched: jest.fn(),
42
+ setInitialFormValues: jest.fn(),
43
+ validationSchema: null,
44
+ values: {} as FormValues,
45
+ };
46
+
47
+ describe('RelationshipsSection', () => {
48
+ it('renders a loader when relationshipTypes are not available', () => {
49
+ renderWithContext(
50
+ <Formik initialValues={{}} onSubmit={null}>
51
+ <Form>
52
+ <RelationshipsSection />
53
+ </Form>
54
+ </Formik>,
55
+ ResourcesContextProvider,
56
+ mockResourcesContextValue,
57
+ );
58
+
59
+ expect(screen.getByLabelText(/loading relationships section/i)).toBeInTheDocument();
60
+ expect(screen.getByRole('progressbar')).toBeInTheDocument();
61
+ expect(screen.queryByText(/add relationship/i)).not.toBeInTheDocument();
62
+ });
63
+
64
+ it('renders relationships when relationshipTypes are available', () => {
65
+ const relationshipTypes = {
66
+ results: [
67
+ {
68
+ displayAIsToB: 'Mother',
69
+ aIsToB: 'Mother',
70
+ bIsToA: 'Child',
71
+ displayBIsToA: 'Child',
72
+ uuid: '42ae5ce0-d64b-11ea-9064-5adc43bbdd34',
73
+ },
74
+ {
75
+ displayAIsToB: 'Father',
76
+ aIsToB: 'Father',
77
+ bIsToA: 'Child',
78
+ displayBIsToA: 'Child',
79
+ uuid: '52ae5ce0-d64b-11ea-9064-5adc43bbdd24',
80
+ },
81
+ ],
82
+ };
83
+ mockResourcesContextValue = {
84
+ ...mockResourcesContextValue,
85
+ relationshipTypes: relationshipTypes,
86
+ };
87
+
88
+ renderWithContext(
89
+ <Formik
90
+ initialValues={{
91
+ relationships: [{ action: 'ADD', relatedPersonUuid: '11524ae7-3ef6-4ab6-aff6-804ffc58704a' }],
92
+ }}
93
+ onSubmit={null}>
94
+ <Form>
95
+ <PatientRegistrationContextProvider value={initialContextValues}>
96
+ <RelationshipsSection />
97
+ </PatientRegistrationContextProvider>
98
+ </Form>
99
+ </Formik>,
100
+ ResourcesContextProvider,
101
+ mockResourcesContextValue,
102
+ );
103
+
104
+ expect(screen.getByLabelText(/relationships section/i)).toBeInTheDocument();
105
+ expect(screen.getByRole('heading', { name: /relationship/i })).toBeInTheDocument();
106
+ expect(screen.getByRole('button', { name: /delete/i })).toBeInTheDocument();
107
+ expect(screen.getByRole('button', { name: /add relationship/i })).toBeInTheDocument();
108
+ expect(screen.getByRole('searchbox', { name: /full name/i })).toBeInTheDocument();
109
+ expect(screen.getByRole('option', { name: /mother/i })).toBeInTheDocument();
110
+ expect(screen.getByRole('option', { name: /father/i })).toBeInTheDocument();
111
+ expect(screen.getAllByRole('option', { name: /child/i }).length).toEqual(2);
112
+ });
113
+ });
@@ -0,0 +1,78 @@
1
+ import { useMemo } from 'react';
2
+ import useSWR from 'swr';
3
+ import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
4
+ import { type RelationshipValue } from '../../patient-registration.types';
5
+ import { personRelationshipRepresentation } from '../../../constants';
6
+
7
+ export interface Relationship {
8
+ display: string;
9
+ uuid: string;
10
+ personA: {
11
+ age: number;
12
+ display: string;
13
+ birthdate: string;
14
+ uuid: string;
15
+ };
16
+ personB: {
17
+ age: number;
18
+ display: string;
19
+ birthdate: string;
20
+ uuid: string;
21
+ };
22
+ relationshipType: {
23
+ uuid: string;
24
+ display: string;
25
+ aIsToB: string;
26
+ bIsToA: string;
27
+ };
28
+ }
29
+
30
+ interface RelationshipsResponse {
31
+ results: Array<Relationship>;
32
+ }
33
+
34
+ export function useInitialPatientRelationships(patientUuid: string): {
35
+ data: Array<RelationshipValue>;
36
+ isLoading: boolean;
37
+ } {
38
+ const shouldFetch = !!patientUuid;
39
+ const { data, error, isLoading } = useSWR<FetchResponse<RelationshipsResponse>, Error>(
40
+ shouldFetch ? `${restBaseUrl}/relationship?v=${personRelationshipRepresentation}&person=${patientUuid}` : null,
41
+ openmrsFetch,
42
+ );
43
+
44
+ const result = useMemo(() => {
45
+ const relationships: Array<RelationshipValue> | undefined = data?.data?.results.map((r) =>
46
+ r.personA.uuid === patientUuid
47
+ ? {
48
+ relatedPersonName: r.personB.display,
49
+ relatedPersonUuid: r.personB.uuid,
50
+ relation: r.relationshipType.bIsToA,
51
+ relationshipType: `${r.relationshipType.uuid}/bIsToA`,
52
+ /**
53
+ * Value kept for restoring initial value
54
+ */
55
+ initialrelationshipTypeValue: `${r.relationshipType.uuid}/bIsToA`,
56
+ uuid: r.uuid,
57
+ }
58
+ : {
59
+ relatedPersonName: r.personA.display,
60
+ relatedPersonUuid: r.personA.uuid,
61
+ relation: r.relationshipType.aIsToB,
62
+ relationshipType: `${r.relationshipType.uuid}/aIsToB`,
63
+ /**
64
+ * Value kept for restoring initial value
65
+ */
66
+ initialrelationshipTypeValue: `${r.relationshipType.uuid}/aIsToB`,
67
+ uuid: r.uuid,
68
+ },
69
+ );
70
+ return {
71
+ data: relationships,
72
+ error,
73
+ isLoading,
74
+ };
75
+ }, [data?.data?.results, error, isLoading, patientUuid]);
76
+
77
+ return result;
78
+ }
@@ -0,0 +1,35 @@
1
+ @use '@carbon/layout';
2
+ @use '@carbon/type';
3
+ @use '@openmrs/esm-styleguide/src/vars' as *;
4
+
5
+ .labelText {
6
+ @include type.type-style('label-01');
7
+ }
8
+
9
+ .bodyShort02 {
10
+ @include type.type-style('body-compact-02');
11
+ }
12
+
13
+ .searchBox {
14
+ margin-bottom: layout.$spacing-05;
15
+ }
16
+
17
+ .relationshipHeader {
18
+ display: flex;
19
+ align-items: center;
20
+ }
21
+
22
+ .productiveHeading {
23
+ @include type.type-style('heading-compact-02');
24
+ color: $text-02;
25
+ }
26
+
27
+ .trashCan {
28
+ color: $danger !important;
29
+ }
30
+
31
+ :global(.omrs-breakpoint-lt-desktop) {
32
+ .relationshipHeader {
33
+ justify-content: space-between;
34
+ }
35
+ }
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import { Tile } from '@carbon/react';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { type SectionDefinition } from '../../config-schema';
5
+ import { Section } from './section.component';
6
+ import styles from './section.scss';
7
+
8
+ export interface SectionWrapperProps {
9
+ sectionDefinition: SectionDefinition;
10
+ index: number;
11
+ }
12
+
13
+ export const SectionWrapper = ({ sectionDefinition, index }: SectionWrapperProps) => {
14
+ const { t } = useTranslation();
15
+
16
+ /*
17
+ * This comment exists to provide translation keys for the default section names.
18
+ *
19
+ * DO NOT REMOVE THESE UNLESS A DEFAULT SECTION IS REMOVED
20
+ * t('demographicsSection', 'Basic Info')
21
+ * t('contactSection', 'Contact Details')
22
+ * t('deathSection', 'Death Info')
23
+ * t('relationshipsSection', 'Relationships')
24
+ */
25
+ return (
26
+ <div id={sectionDefinition.id} style={{ scrollMarginTop: '4rem' }}>
27
+ <h3 className={styles.productiveHeading02} style={{ color: '#161616' }}>
28
+ {index + 1}. {t(`${sectionDefinition.id}Section`, sectionDefinition.name)}
29
+ </h3>
30
+ <span className={styles.label01}>
31
+ {t('allFieldsRequiredText', 'All fields are required unless marked optional')}
32
+ </span>
33
+ <div style={{ margin: '1rem 0 1rem' }}>
34
+ <Tile>
35
+ <Section sectionDefinition={sectionDefinition} />
36
+ </Tile>
37
+ </div>
38
+ </div>
39
+ );
40
+ };
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { type SectionDefinition } from '../../config-schema';
3
+ import { GenericSection } from './generic-section.component';
4
+ import { DeathInfoSection } from './death-info/death-info-section.component';
5
+ import { DemographicsSection } from './demographics/demographics-section.component';
6
+ import { RelationshipsSection } from './patient-relationships/relationships-section.component';
7
+
8
+ export interface SectionProps {
9
+ sectionDefinition: SectionDefinition;
10
+ }
11
+
12
+ export function Section({ sectionDefinition }: SectionProps) {
13
+ switch (sectionDefinition.id) {
14
+ case 'demographics':
15
+ return <DemographicsSection fields={sectionDefinition.fields} />;
16
+ case 'death':
17
+ return <DeathInfoSection fields={sectionDefinition.fields} />;
18
+ case 'relationships':
19
+ return <RelationshipsSection />;
20
+ default: // includes 'contact'
21
+ return <GenericSection sectionDefinition={sectionDefinition} />;
22
+ }
23
+ }
@@ -0,0 +1,21 @@
1
+ @use '@carbon/colors';
2
+ @use '@carbon/layout';
3
+ @use '@carbon/type';
4
+ @use '@openmrs/esm-styleguide/src/vars' as *;
5
+
6
+ .label01 {
7
+ @include type.type-style('label-01');
8
+ margin-top: layout.$spacing-05;
9
+ margin-bottom: layout.$spacing-05;
10
+ color: $ui-05;
11
+ }
12
+
13
+ .productiveHeading02 {
14
+ @include type.type-style('heading-compact-02');
15
+ color: $ui-04;
16
+ cursor: pointer;
17
+ }
18
+
19
+ .isDeadFieldContainer {
20
+ margin-bottom: layout.$spacing-05;
21
+ }
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { Button, Header } from '@carbon/react';
4
+ import { ArrowLeft, Close } from '@carbon/react/icons';
5
+ import { useLayoutType, isDesktop } from '@openmrs/esm-framework';
6
+ import styles from './overlay.scss';
7
+
8
+ interface OverlayProps {
9
+ close: () => void;
10
+ header: string;
11
+ buttonsGroup?: React.ReactElement;
12
+ children?: React.ReactNode;
13
+ }
14
+
15
+ const Overlay: React.FC<OverlayProps> = ({ close, children, header, buttonsGroup }) => {
16
+ const { t } = useTranslation();
17
+ const layout = useLayoutType();
18
+
19
+ return (
20
+ <div className={isDesktop(layout) ? styles.desktopOverlay : styles.tabletOverlay}>
21
+ {isDesktop(layout) ? (
22
+ <div className={styles.desktopHeader}>
23
+ <div className={styles.headerContent}>{header}</div>
24
+ <Button
25
+ className={styles.closeButton}
26
+ iconDescription={t('closeOverlay', 'Close overlay')}
27
+ onClick={close}
28
+ kind="ghost"
29
+ hasIconOnly
30
+ renderIcon={(props) => <Close size={16} {...props} />}
31
+ />
32
+ </div>
33
+ ) : (
34
+ <Header className={styles.tabletOverlayHeader} aria-label="Overlay header">
35
+ <Button
36
+ kind="ghost"
37
+ onClick={close}
38
+ hasIconOnly
39
+ iconDescription={t('closeOverlay', 'Close overlay')}
40
+ renderIcon={(props) => <ArrowLeft size={16} onClick={close} {...props} />}
41
+ />
42
+ <div className={styles.headerContent}>{header}</div>
43
+ </Header>
44
+ )}
45
+ <div className={styles.overlayContent}>{children}</div>
46
+ <div>{buttonsGroup}</div>
47
+ </div>
48
+ );
49
+ };
50
+
51
+ export default Overlay;
@@ -0,0 +1,63 @@
1
+ @use '@carbon/layout';
2
+ @use '@carbon/type';
3
+ @use '@openmrs/esm-styleguide/src/vars' as *;
4
+
5
+ .desktopOverlay {
6
+ position: fixed;
7
+ top: layout.$spacing-09;
8
+ right: 0;
9
+ height: calc(100vh - layout.$spacing-09);
10
+ min-width: 27rem;
11
+ background-color: $ui-02;
12
+ border-left: 1px solid $text-03;
13
+ overflow: hidden;
14
+ display: grid;
15
+ grid-template-rows: auto 1fr auto;
16
+ z-index: 999;
17
+ }
18
+
19
+ .tabletOverlay {
20
+ position: fixed;
21
+ top: 0;
22
+ bottom: 0;
23
+ left: 0;
24
+ right: 0;
25
+ z-index: 9999;
26
+ background-color: $ui-02;
27
+ overflow: hidden;
28
+ padding-top: layout.$spacing-09;
29
+ display: grid;
30
+ grid-template-rows: 1fr auto;
31
+ }
32
+
33
+ .tabletOverlayHeader {
34
+ button {
35
+ background-color: $brand-01 !important;
36
+ }
37
+ .headerContent {
38
+ color: $ui-02;
39
+ }
40
+ }
41
+
42
+ .desktopHeader {
43
+ display: flex;
44
+ justify-content: space-between;
45
+ align-items: center;
46
+ background-color: $ui-03;
47
+ border-bottom: 1px solid $text-03;
48
+ }
49
+
50
+ .headerContent {
51
+ @include type.type-style('heading-compact-02');
52
+ padding: 0 layout.$spacing-05;
53
+ color: $ui-05;
54
+ }
55
+
56
+ .closeButton {
57
+ background-color: $ui-02;
58
+ }
59
+
60
+ .overlayContent {
61
+ padding: layout.$spacing-05;
62
+ overflow-y: auto;
63
+ }