@ampath/esm-patient-registration-app 6.0.1-pre.6

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 (176) hide show
  1. package/.turbo/turbo-build.log +41 -0
  2. package/README.md +7 -0
  3. package/dist/130.js +2 -0
  4. package/dist/130.js.LICENSE.txt +3 -0
  5. package/dist/130.js.map +1 -0
  6. package/dist/152.js +1 -0
  7. package/dist/152.js.map +1 -0
  8. package/dist/249.js +2 -0
  9. package/dist/249.js.LICENSE.txt +46 -0
  10. package/dist/249.js.map +1 -0
  11. package/dist/255.js +2 -0
  12. package/dist/255.js.LICENSE.txt +9 -0
  13. package/dist/255.js.map +1 -0
  14. package/dist/271.js +1 -0
  15. package/dist/303.js +1 -0
  16. package/dist/303.js.map +1 -0
  17. package/dist/319.js +1 -0
  18. package/dist/365.js +1 -0
  19. package/dist/365.js.map +1 -0
  20. package/dist/460.js +1 -0
  21. package/dist/525.js +1 -0
  22. package/dist/525.js.map +1 -0
  23. package/dist/537.js +1 -0
  24. package/dist/537.js.map +1 -0
  25. package/dist/574.js +1 -0
  26. package/dist/591.js +2 -0
  27. package/dist/591.js.LICENSE.txt +32 -0
  28. package/dist/591.js.map +1 -0
  29. package/dist/621.js +1 -0
  30. package/dist/621.js.map +1 -0
  31. package/dist/644.js +1 -0
  32. package/dist/729.js +1 -0
  33. package/dist/729.js.map +1 -0
  34. package/dist/735.js +1 -0
  35. package/dist/735.js.map +1 -0
  36. package/dist/757.js +1 -0
  37. package/dist/784.js +2 -0
  38. package/dist/784.js.LICENSE.txt +9 -0
  39. package/dist/784.js.map +1 -0
  40. package/dist/788.js +1 -0
  41. package/dist/807.js +1 -0
  42. package/dist/833.js +1 -0
  43. package/dist/879.js +1 -0
  44. package/dist/879.js.map +1 -0
  45. package/dist/ampath-esm-patient-registration-app.js +1 -0
  46. package/dist/ampath-esm-patient-registration-app.js.buildmanifest.json +649 -0
  47. package/dist/ampath-esm-patient-registration-app.js.map +1 -0
  48. package/dist/main.js +2 -0
  49. package/dist/main.js.LICENSE.txt +56 -0
  50. package/dist/main.js.map +1 -0
  51. package/dist/routes.json +1 -0
  52. package/docs/images/patient-registration-hierarchy.png +0 -0
  53. package/jest.config.js +3 -0
  54. package/package.json +61 -0
  55. package/src/add-patient-link.scss +3 -0
  56. package/src/add-patient-link.test.tsx +20 -0
  57. package/src/add-patient-link.tsx +21 -0
  58. package/src/config-schema.ts +410 -0
  59. package/src/constants.ts +14 -0
  60. package/src/declarations.d.ts +6 -0
  61. package/src/index.ts +71 -0
  62. package/src/nav-link.test.tsx +13 -0
  63. package/src/nav-link.tsx +10 -0
  64. package/src/offline.resources.ts +155 -0
  65. package/src/offline.ts +91 -0
  66. package/src/patient-registration/before-save-prompt.tsx +73 -0
  67. package/src/patient-registration/date-util.ts +52 -0
  68. package/src/patient-registration/field/__mocks__/field.resource.ts +60 -0
  69. package/src/patient-registration/field/address/address-field.component.tsx +153 -0
  70. package/src/patient-registration/field/address/address-hierarchy-levels.component.tsx +73 -0
  71. package/src/patient-registration/field/address/address-hierarchy.resource.tsx +157 -0
  72. package/src/patient-registration/field/address/address-search.component.tsx +85 -0
  73. package/src/patient-registration/field/address/address-search.scss +53 -0
  74. package/src/patient-registration/field/address/custom-address-field.component.tsx +31 -0
  75. package/src/patient-registration/field/address/tests/address-hierarchy.test.tsx +214 -0
  76. package/src/patient-registration/field/address/tests/address-search-component.test.tsx +135 -0
  77. package/src/patient-registration/field/custom-field.component.tsx +25 -0
  78. package/src/patient-registration/field/dob/dob.component.tsx +159 -0
  79. package/src/patient-registration/field/dob/dob.test.tsx +75 -0
  80. package/src/patient-registration/field/field.component.tsx +47 -0
  81. package/src/patient-registration/field/field.resource.ts +35 -0
  82. package/src/patient-registration/field/field.scss +127 -0
  83. package/src/patient-registration/field/field.test.tsx +294 -0
  84. package/src/patient-registration/field/gender/gender-field.component.tsx +49 -0
  85. package/src/patient-registration/field/gender/gender-field.test.tsx +59 -0
  86. package/src/patient-registration/field/id/id-field.component.tsx +144 -0
  87. package/src/patient-registration/field/id/id-field.test.tsx +107 -0
  88. package/src/patient-registration/field/id/identifier-selection-overlay.component.tsx +198 -0
  89. package/src/patient-registration/field/id/identifier-selection.scss +37 -0
  90. package/src/patient-registration/field/name/name-field.component.tsx +142 -0
  91. package/src/patient-registration/field/obs/obs-field.component.tsx +204 -0
  92. package/src/patient-registration/field/obs/obs-field.test.tsx +205 -0
  93. package/src/patient-registration/field/person-attributes/coded-attributes.component.tsx +60 -0
  94. package/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx +116 -0
  95. package/src/patient-registration/field/person-attributes/coded-person-attribute-field.test.tsx +127 -0
  96. package/src/patient-registration/field/person-attributes/person-attribute-field.component.tsx +88 -0
  97. package/src/patient-registration/field/person-attributes/person-attribute-field.test.tsx +187 -0
  98. package/src/patient-registration/field/person-attributes/person-attributes.resource.ts +20 -0
  99. package/src/patient-registration/field/person-attributes/text-person-attribute-field.component.tsx +58 -0
  100. package/src/patient-registration/field/person-attributes/text-person-attribute-field.test.tsx +88 -0
  101. package/src/patient-registration/field/phone/phone-field.component.tsx +16 -0
  102. package/src/patient-registration/form-manager.test.ts +67 -0
  103. package/src/patient-registration/form-manager.ts +414 -0
  104. package/src/patient-registration/input/basic-input/input/input.component.tsx +179 -0
  105. package/src/patient-registration/input/basic-input/input/input.test.tsx +72 -0
  106. package/src/patient-registration/input/basic-input/select/select-input.component.tsx +32 -0
  107. package/src/patient-registration/input/basic-input/select/select-input.test.tsx +49 -0
  108. package/src/patient-registration/input/combo-input/combo-input.component.tsx +128 -0
  109. package/src/patient-registration/input/combo-input/selection-tick.component.tsx +20 -0
  110. package/src/patient-registration/input/custom-input/autosuggest/autosuggest.component.tsx +187 -0
  111. package/src/patient-registration/input/custom-input/autosuggest/autosuggest.scss +62 -0
  112. package/src/patient-registration/input/custom-input/autosuggest/autosuggest.test.tsx +132 -0
  113. package/src/patient-registration/input/custom-input/identifier/identifier-input.component.tsx +156 -0
  114. package/src/patient-registration/input/custom-input/identifier/identifier-input.test.tsx +107 -0
  115. package/src/patient-registration/input/custom-input/identifier/utils.test.ts +81 -0
  116. package/src/patient-registration/input/custom-input/identifier/utils.ts +19 -0
  117. package/src/patient-registration/input/dummy-data/dummy-data-input.component.tsx +53 -0
  118. package/src/patient-registration/input/dummy-data/dummy-data-input.test.tsx +43 -0
  119. package/src/patient-registration/input/input.scss +118 -0
  120. package/src/patient-registration/patient-registration-context.ts +24 -0
  121. package/src/patient-registration/patient-registration-hooks.ts +287 -0
  122. package/src/patient-registration/patient-registration-utils.ts +216 -0
  123. package/src/patient-registration/patient-registration.component.tsx +240 -0
  124. package/src/patient-registration/patient-registration.resource.test.tsx +26 -0
  125. package/src/patient-registration/patient-registration.resource.ts +250 -0
  126. package/src/patient-registration/patient-registration.scss +122 -0
  127. package/src/patient-registration/patient-registration.test.tsx +471 -0
  128. package/src/patient-registration/patient-registration.types.ts +318 -0
  129. package/src/patient-registration/section/death-info/death-info-section.component.tsx +31 -0
  130. package/src/patient-registration/section/death-info/death-info-section.test.tsx +64 -0
  131. package/src/patient-registration/section/demographics/demographics-section.component.tsx +30 -0
  132. package/src/patient-registration/section/demographics/demographics-section.test.tsx +83 -0
  133. package/src/patient-registration/section/generic-section.component.tsx +17 -0
  134. package/src/patient-registration/section/patient-relationships/relationships-section.component.tsx +235 -0
  135. package/src/patient-registration/section/patient-relationships/relationships-section.test.tsx +100 -0
  136. package/src/patient-registration/section/patient-relationships/relationships.resource.tsx +78 -0
  137. package/src/patient-registration/section/patient-relationships/relationships.scss +35 -0
  138. package/src/patient-registration/section/section-wrapper.component.tsx +40 -0
  139. package/src/patient-registration/section/section.component.tsx +23 -0
  140. package/src/patient-registration/section/section.scss +1 -0
  141. package/src/patient-registration/ui-components/overlay/overlay.component.tsx +51 -0
  142. package/src/patient-registration/ui-components/overlay/overlay.scss +63 -0
  143. package/src/patient-registration/validation/patient-registration-validation.test.tsx +157 -0
  144. package/src/patient-registration/validation/patient-registration-validation.tsx +60 -0
  145. package/src/patient-verification/client-registry-constants.ts +13 -0
  146. package/src/patient-verification/client-registry.component.tsx +66 -0
  147. package/src/patient-verification/client-registry.scss +1 -0
  148. package/src/patient-verification/utils.tsx +56 -0
  149. package/src/patient-verification/verification-modal.scss +20 -0
  150. package/src/patient-verification/verification.component.tsx +48 -0
  151. package/src/resource.ts +12 -0
  152. package/src/root.component.tsx +63 -0
  153. package/src/root.scss +7 -0
  154. package/src/root.test.tsx +32 -0
  155. package/src/routes.json +66 -0
  156. package/src/widgets/cancel-patient-edit.component.tsx +37 -0
  157. package/src/widgets/cancel-patient-edit.test.tsx +27 -0
  158. package/src/widgets/delete-identifier-confirmation-modal.test.tsx +34 -0
  159. package/src/widgets/delete-identifier-confirmation-modal.tsx +41 -0
  160. package/src/widgets/delete-identifier-modal.scss +34 -0
  161. package/src/widgets/display-photo.component.tsx +30 -0
  162. package/src/widgets/display-photo.test.tsx +37 -0
  163. package/src/widgets/edit-patient-details-button.component.tsx +34 -0
  164. package/src/widgets/edit-patient-details-button.scss +3 -0
  165. package/src/widgets/edit-patient-details-button.test.tsx +41 -0
  166. package/translations/am.json +97 -0
  167. package/translations/ar.json +97 -0
  168. package/translations/en.json +103 -0
  169. package/translations/es.json +97 -0
  170. package/translations/fr.json +97 -0
  171. package/translations/he.json +97 -0
  172. package/translations/km.json +97 -0
  173. package/translations/zh.json +89 -0
  174. package/translations/zh_CN.json +89 -0
  175. package/tsconfig.json +5 -0
  176. package/webpack.config.js +1 -0
@@ -0,0 +1,235 @@
1
+ import React, { useCallback, useContext, useEffect, useState } from 'react';
2
+ import {
3
+ Button,
4
+ Layer,
5
+ Select,
6
+ SelectItem,
7
+ InlineNotification,
8
+ NotificationActionButton,
9
+ SkeletonText,
10
+ } from '@carbon/react';
11
+ import { TrashCan } from '@carbon/react/icons';
12
+ import { FieldArray } from 'formik';
13
+ import { useTranslation } from 'react-i18next';
14
+ import { Autosuggest } from '../../input/custom-input/autosuggest/autosuggest.component';
15
+ import { PatientRegistrationContext } from '../../patient-registration-context';
16
+ import { ResourcesContext } from '../../../offline.resources';
17
+ import { fetchPerson } from '../../patient-registration.resource';
18
+ import { type RelationshipValue } from '../../patient-registration.types';
19
+ import sectionStyles from '../section.scss';
20
+ import styles from './relationships.scss';
21
+
22
+ interface RelationshipType {
23
+ display: string;
24
+ uuid: string;
25
+ direction: string;
26
+ }
27
+
28
+ interface RelationshipViewProps {
29
+ relationship: RelationshipValue;
30
+ index: number;
31
+ displayRelationshipTypes: RelationshipType[];
32
+ remove: <T>(index: number) => T;
33
+ }
34
+
35
+ const RelationshipView: React.FC<RelationshipViewProps> = ({
36
+ relationship,
37
+ index,
38
+ displayRelationshipTypes,
39
+ remove,
40
+ }) => {
41
+ const { t } = useTranslation();
42
+ const { setFieldValue } = React.useContext(PatientRegistrationContext);
43
+ const [isInvalid, setIsInvalid] = useState<boolean>(false);
44
+ const newRelationship = !relationship.uuid;
45
+
46
+ const handleRelationshipTypeChange = useCallback(
47
+ (event) => {
48
+ const { target } = event;
49
+ const field = target.name;
50
+ const value = target.options[target.selectedIndex].value;
51
+ setFieldValue(field, value);
52
+ if (!relationship?.action) {
53
+ setFieldValue(`relationships[${index}].action`, 'UPDATE');
54
+ }
55
+ },
56
+ [index, relationship?.action, setFieldValue],
57
+ );
58
+
59
+ const handleSuggestionSelected = useCallback(
60
+ (field: string, selectedSuggestion: string) => {
61
+ setIsInvalid(!selectedSuggestion);
62
+ setFieldValue(field, selectedSuggestion);
63
+ },
64
+ [setFieldValue],
65
+ );
66
+
67
+ const searchPerson = async (query: string) => {
68
+ const abortController = new AbortController();
69
+ return await fetchPerson(query, abortController);
70
+ };
71
+
72
+ const deleteRelationship = useCallback(() => {
73
+ if (relationship.action === 'ADD') {
74
+ remove(index);
75
+ } else {
76
+ setFieldValue(`relationships[${index}].action`, 'DELETE');
77
+ }
78
+ }, [relationship, index, remove, setFieldValue]);
79
+
80
+ const restoreRelationship = useCallback(() => {
81
+ setFieldValue(`relationships[${index}]`, {
82
+ ...relationship,
83
+ action: undefined,
84
+ relationshipType: relationship.initialrelationshipTypeValue,
85
+ });
86
+ }, [index, setFieldValue, relationship]);
87
+
88
+ return relationship.action !== 'DELETE' ? (
89
+ <div className={styles.relationship}>
90
+ <div className={styles.searchBox}>
91
+ <div className={styles.relationshipHeader}>
92
+ <h4 className={styles.productiveHeading}>{t('relationshipPlaceholder', 'Relationship')}</h4>
93
+ <Button
94
+ kind="ghost"
95
+ iconDescription={t('deleteRelationshipTooltipText', 'Delete')}
96
+ hasIconOnly
97
+ onClick={deleteRelationship}>
98
+ <TrashCan size={16} className={styles.trashCan} />
99
+ </Button>
100
+ </div>
101
+ <div>
102
+ {newRelationship ? (
103
+ <Autosuggest
104
+ id={`relationships[${index}].relatedPersonUuid`}
105
+ labelText={t('relativeFullNameLabelText', 'Full name')}
106
+ placeholder={t('relativeNamePlaceholder', 'Firstname Familyname')}
107
+ defaultValue={relationship.relatedPersonName}
108
+ onSuggestionSelected={handleSuggestionSelected}
109
+ invalid={isInvalid}
110
+ invalidText={t('relationshipPersonMustExist', 'Related person must be an existing person')}
111
+ getSearchResults={searchPerson}
112
+ getDisplayValue={(item) => item.display}
113
+ getFieldValue={(item) => item.uuid}
114
+ />
115
+ ) : (
116
+ <>
117
+ <span className={styles.labelText}>{t('relativeFullNameLabelText', 'Full name')}</span>
118
+ <p className={styles.bodyShort02}>{relationship.relatedPersonName}</p>
119
+ </>
120
+ )}
121
+ </div>
122
+ </div>
123
+ <div className={styles.selectRelationshipType} style={{ marginBottom: '1rem' }}>
124
+ <Layer>
125
+ <Select
126
+ id="select"
127
+ labelText={t('relationship', 'Relationship')}
128
+ onChange={handleRelationshipTypeChange}
129
+ name={`relationships[${index}].relationshipType`}
130
+ defaultValue={relationship?.relationshipType ?? 'placeholder-item'}>
131
+ <SelectItem
132
+ disabled
133
+ hidden
134
+ value="placeholder-item"
135
+ text={t('relationshipToPatient', 'Relationship to patient')}
136
+ />
137
+ {displayRelationshipTypes.map((relationshipType, index) => (
138
+ <SelectItem
139
+ text={relationshipType.display}
140
+ value={`${relationshipType.uuid}/${relationshipType.direction}`}
141
+ key={`relationship-${relationshipType.uuid}-${index}`}
142
+ />
143
+ ))}
144
+ </Select>
145
+ </Layer>
146
+ </div>
147
+ </div>
148
+ ) : (
149
+ <InlineNotification
150
+ kind="info"
151
+ title={t('relationshipRemovedText', 'Relationship removed')}
152
+ actions={
153
+ <NotificationActionButton onClick={restoreRelationship}>
154
+ {t('restoreRelationshipActionButton', 'Undo')}
155
+ </NotificationActionButton>
156
+ }
157
+ />
158
+ );
159
+ };
160
+
161
+ export const RelationshipsSection = () => {
162
+ const { relationshipTypes } = useContext(ResourcesContext);
163
+ const [displayRelationshipTypes, setDisplayRelationshipTypes] = useState<RelationshipType[]>([]);
164
+ const { t } = useTranslation();
165
+
166
+ useEffect(() => {
167
+ if (relationshipTypes) {
168
+ const tmp: RelationshipType[] = [];
169
+ relationshipTypes.results.forEach((type) => {
170
+ const aIsToB = {
171
+ display: type.displayAIsToB ? type.displayAIsToB : type.displayBIsToA,
172
+ uuid: type.uuid,
173
+ direction: 'aIsToB',
174
+ };
175
+ const bIsToA = {
176
+ display: type.displayBIsToA ? type.displayBIsToA : type.displayAIsToB,
177
+ uuid: type.uuid,
178
+ direction: 'bIsToA',
179
+ };
180
+ aIsToB.display === bIsToA.display ? tmp.push(aIsToB) : tmp.push(aIsToB, bIsToA);
181
+ });
182
+ setDisplayRelationshipTypes(tmp);
183
+ }
184
+ }, [relationshipTypes]);
185
+
186
+ if (!relationshipTypes) {
187
+ return (
188
+ <section aria-label="Loading relationships section">
189
+ <SkeletonText role="progressbar" />
190
+ </section>
191
+ );
192
+ }
193
+
194
+ return (
195
+ <section aria-label="Relationships section">
196
+ <FieldArray name="relationships">
197
+ {({
198
+ push,
199
+ remove,
200
+ form: {
201
+ values: { relationships },
202
+ },
203
+ }) => (
204
+ <div>
205
+ {relationships && relationships.length > 0
206
+ ? relationships.map((relationship: RelationshipValue, index) => (
207
+ <div key={index} className={sectionStyles.formSection}>
208
+ <RelationshipView
209
+ relationship={relationship}
210
+ index={index}
211
+ displayRelationshipTypes={displayRelationshipTypes}
212
+ key={index}
213
+ remove={remove}
214
+ />
215
+ </div>
216
+ ))
217
+ : null}
218
+ <div className={styles.actions}>
219
+ <Button
220
+ kind="ghost"
221
+ onClick={() =>
222
+ push({
223
+ relatedPersonUuid: '',
224
+ action: 'ADD',
225
+ })
226
+ }>
227
+ {t('addRelationshipButtonText', 'Add Relationship')}
228
+ </Button>
229
+ </div>
230
+ </div>
231
+ )}
232
+ </FieldArray>
233
+ </section>
234
+ );
235
+ };
@@ -0,0 +1,100 @@
1
+ import React from 'react';
2
+ import { Form, Formik } from 'formik';
3
+ import { render, screen } from '@testing-library/react';
4
+ import { PatientRegistrationContext } from '../../patient-registration-context';
5
+ import { type Resources, ResourcesContext } from '../../../offline.resources';
6
+ import { RelationshipsSection } from './relationships-section.component';
7
+
8
+ jest.mock('../../patient-registration.resource', () => ({
9
+ fetchPerson: jest.fn().mockResolvedValue({
10
+ data: {
11
+ results: [
12
+ { uuid: '42ae5ce0-d64b-11ea-9064-5adc43bbdd24', display: 'Person 1' },
13
+ { uuid: '691eed12-c0f1-11e2-94be-8c13b969e334', display: 'Person 2' },
14
+ ],
15
+ },
16
+ }),
17
+ }));
18
+
19
+ let mockResourcesContextValue = {
20
+ addressTemplate: null,
21
+ currentSession: {
22
+ authenticated: true,
23
+ sessionId: 'JSESSION',
24
+ currentProvider: { uuid: '45ce6c2e-dd5a-11e6-9d9c-0242ac150002', identifier: 'PRO-123' },
25
+ },
26
+ identifierTypes: [],
27
+ relationshipTypes: null,
28
+ } as Resources;
29
+
30
+ describe('RelationshipsSection', () => {
31
+ it('renders a loader when relationshipTypes are not available', () => {
32
+ render(
33
+ <ResourcesContext.Provider value={mockResourcesContextValue}>
34
+ <Formik initialValues={{}} onSubmit={null}>
35
+ <Form>
36
+ <RelationshipsSection />
37
+ </Form>
38
+ </Formik>
39
+ </ResourcesContext.Provider>,
40
+ );
41
+
42
+ expect(screen.getByLabelText(/loading relationships section/i)).toBeInTheDocument();
43
+ expect(screen.getByRole('progressbar')).toBeInTheDocument();
44
+ expect(screen.queryByText(/add relationship/i)).not.toBeInTheDocument();
45
+ });
46
+
47
+ it('renders relationships when relationshipTypes are available', () => {
48
+ const relationshipTypes = {
49
+ results: [
50
+ {
51
+ displayAIsToB: 'Mother',
52
+ aIsToB: 'Mother',
53
+ bIsToA: 'Child',
54
+ displayBIsToA: 'Child',
55
+ uuid: '42ae5ce0-d64b-11ea-9064-5adc43bbdd34',
56
+ },
57
+ {
58
+ displayAIsToB: 'Father',
59
+ aIsToB: 'Father',
60
+ bIsToA: 'Child',
61
+ displayBIsToA: 'Child',
62
+ uuid: '52ae5ce0-d64b-11ea-9064-5adc43bbdd24',
63
+ },
64
+ ],
65
+ };
66
+ mockResourcesContextValue = {
67
+ ...mockResourcesContextValue,
68
+ relationshipTypes: relationshipTypes,
69
+ };
70
+
71
+ render(
72
+ <ResourcesContext.Provider value={mockResourcesContextValue}>
73
+ <Formik
74
+ initialValues={{
75
+ relationships: [{ action: 'ADD', relatedPersonUuid: '11524ae7-3ef6-4ab6-aff6-804ffc58704a' }],
76
+ }}
77
+ onSubmit={null}>
78
+ <Form>
79
+ <PatientRegistrationContext.Provider
80
+ value={{
81
+ setFieldValue: jest.fn(),
82
+ setInitialFormValues: jest.fn(),
83
+ }}>
84
+ <RelationshipsSection />
85
+ </PatientRegistrationContext.Provider>
86
+ </Form>
87
+ </Formik>
88
+ </ResourcesContext.Provider>,
89
+ );
90
+
91
+ expect(screen.getByLabelText(/relationships section/i)).toBeInTheDocument();
92
+ expect(screen.getByRole('heading', { name: /relationship/i })).toBeInTheDocument();
93
+ expect(screen.getByRole('button', { name: /delete/i })).toBeInTheDocument();
94
+ expect(screen.getByRole('button', { name: /add relationship/i })).toBeInTheDocument();
95
+ expect(screen.getByRole('searchbox', { name: /full name/i })).toBeInTheDocument();
96
+ expect(screen.getByRole('option', { name: /mother/i })).toBeInTheDocument();
97
+ expect(screen.getByRole('option', { name: /father/i })).toBeInTheDocument();
98
+ expect(screen.getAllByRole('option', { name: /child/i }).length).toEqual(2);
99
+ });
100
+ });
@@ -0,0 +1,78 @@
1
+ import { useMemo } from 'react';
2
+ import useSWR from 'swr';
3
+ import { type FetchResponse, openmrsFetch } from '@openmrs/esm-framework';
4
+ import { type RelationshipValue } from '../../patient-registration.types';
5
+ import { personRelationshipRepresentation } from '../../../constants';
6
+
7
+ export function useInitialPatientRelationships(patientUuid: string): {
8
+ data: Array<RelationshipValue>;
9
+ isLoading: boolean;
10
+ } {
11
+ const shouldFetch = !!patientUuid;
12
+ const { data, error, isLoading } = useSWR<FetchResponse<RelationshipsResponse>, Error>(
13
+ shouldFetch ? `/ws/rest/v1/relationship?v=${personRelationshipRepresentation}&person=${patientUuid}` : null,
14
+ openmrsFetch,
15
+ );
16
+
17
+ const result = useMemo(() => {
18
+ const relationships: Array<RelationshipValue> | undefined = data?.data?.results.map((r) =>
19
+ r.personA.uuid === patientUuid
20
+ ? {
21
+ relatedPersonName: r.personB.display,
22
+ relatedPersonUuid: r.personB.uuid,
23
+ relation: r.relationshipType.bIsToA,
24
+ relationshipType: `${r.relationshipType.uuid}/bIsToA`,
25
+ /**
26
+ * Value kept for restoring initial value
27
+ */
28
+ initialrelationshipTypeValue: `${r.relationshipType.uuid}/bIsToA`,
29
+ uuid: r.uuid,
30
+ }
31
+ : {
32
+ relatedPersonName: r.personA.display,
33
+ relatedPersonUuid: r.personA.uuid,
34
+ relation: r.relationshipType.aIsToB,
35
+ relationshipType: `${r.relationshipType.uuid}/aIsToB`,
36
+ /**
37
+ * Value kept for restoring initial value
38
+ */
39
+ initialrelationshipTypeValue: `${r.relationshipType.uuid}/aIsToB`,
40
+ uuid: r.uuid,
41
+ },
42
+ );
43
+ return {
44
+ data: relationships,
45
+ error,
46
+ isLoading,
47
+ };
48
+ }, [patientUuid, data, error]);
49
+
50
+ return result;
51
+ }
52
+
53
+ export interface Relationship {
54
+ display: string;
55
+ uuid: string;
56
+ personA: {
57
+ age: number;
58
+ display: string;
59
+ birthdate: string;
60
+ uuid: string;
61
+ };
62
+ personB: {
63
+ age: number;
64
+ display: string;
65
+ birthdate: string;
66
+ uuid: string;
67
+ };
68
+ relationshipType: {
69
+ uuid: string;
70
+ display: string;
71
+ aIsToB: string;
72
+ bIsToA: string;
73
+ };
74
+ }
75
+
76
+ interface RelationshipsResponse {
77
+ results: Array<Relationship>;
78
+ }
@@ -0,0 +1,35 @@
1
+ @use '@carbon/styles/scss/spacing';
2
+ @use '@carbon/styles/scss/type';
3
+ @import '../../patient-registration.scss';
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: spacing.$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 styles from '../patient-registration.scss';
3
+ import { Tile } from '@carbon/react';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { type SectionDefinition } from '../../config-schema';
6
+ import { Section } from './section.component';
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 />;
18
+ case 'relationships':
19
+ return <RelationshipsSection />;
20
+ default: // includes 'contact'
21
+ return <GenericSection sectionDefinition={sectionDefinition} />;
22
+ }
23
+ }
@@ -0,0 +1 @@
1
+ @import '../patient-registration.scss';
@@ -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/styles/scss/spacing';
2
+ @use '@carbon/styles/scss/type';
3
+ @import '../../patient-registration.scss';
4
+
5
+ .desktopOverlay {
6
+ position: fixed;
7
+ top: spacing.$spacing-09;
8
+ right: 0;
9
+ height: calc(100vh - 3rem);
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: spacing.$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 spacing.$spacing-05;
53
+ color: $ui-05;
54
+ }
55
+
56
+ .closeButton {
57
+ background-color: $ui-02;
58
+ }
59
+
60
+ .overlayContent {
61
+ padding: spacing.$spacing-05;
62
+ overflow-y: auto;
63
+ }