@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.
- package/ADDRESS_CONFIGURATION.md +152 -0
- package/IDENTIFIER_CONFIGURATION.md +142 -0
- package/IMPLEMENTATION_SUMMARY.md +111 -0
- package/QUICK_START.md +95 -0
- package/README.md +7 -0
- package/address-required-fields-config.json +26 -0
- package/dist/126.js +1 -0
- package/dist/15.js +1 -0
- package/dist/1564.js +1 -0
- package/dist/1567.js +1 -0
- package/dist/1845.js +1 -0
- package/dist/1953.js +1 -0
- package/dist/200.js +1 -0
- package/dist/200.js.map +1 -0
- package/dist/215.js +1 -0
- package/dist/2178.js +1 -0
- package/dist/250.js +1 -0
- package/dist/250.js.map +1 -0
- package/dist/2523.js +1 -0
- package/dist/2523.js.map +1 -0
- package/dist/2566.js +1 -0
- package/dist/2586.js +1 -0
- package/dist/2586.js.map +1 -0
- package/dist/2716.js +1 -0
- package/dist/2716.js.map +1 -0
- package/dist/2759.js +1 -0
- package/dist/2821.js +6 -0
- package/dist/2821.js.map +1 -0
- package/dist/3089.js +1 -0
- package/dist/3089.js.map +1 -0
- package/dist/3230.js +1 -0
- package/dist/3441.js +1 -0
- package/dist/3565.js +1 -0
- package/dist/3571.js +1 -0
- package/dist/3571.js.map +1 -0
- package/dist/3746.js +1 -0
- package/dist/3925.js +1 -0
- package/dist/3946.js +1 -0
- package/dist/4024.js +1 -0
- package/dist/4024.js.map +1 -0
- package/dist/4744.js +1 -0
- package/dist/4744.js.map +1 -0
- package/dist/4809.js +1 -0
- package/dist/4894.js +1 -0
- package/dist/4970.js +1 -0
- package/dist/4970.js.map +1 -0
- package/dist/5130.js +1 -0
- package/dist/5187.js +1 -0
- package/dist/5491.js +1 -0
- package/dist/5491.js.map +1 -0
- package/dist/5595.js +1 -0
- package/dist/5961.js +1 -0
- package/dist/6133.js +1 -0
- package/dist/634.js +1 -0
- package/dist/634.js.map +1 -0
- package/dist/6456.js +1 -0
- package/dist/6466.js +1 -0
- package/dist/6613.js +1 -0
- package/dist/6783.js +1 -0
- package/dist/7073.js +38 -0
- package/dist/7073.js.map +1 -0
- package/dist/7154.js +1 -0
- package/dist/7154.js.map +1 -0
- package/dist/7348.js +1 -0
- package/dist/7439.js +1 -0
- package/dist/7439.js.map +1 -0
- package/dist/7543.js +1 -0
- package/dist/7607.js +1 -0
- package/dist/772.js +1 -0
- package/dist/7984.js +1 -0
- package/dist/7984.js.map +1 -0
- package/dist/8538.js +1 -0
- package/dist/8538.js.map +1 -0
- package/dist/8599.js +1 -0
- package/dist/8727.js +1 -0
- package/dist/8847.js +1 -0
- package/dist/9015.js +1 -0
- package/dist/906.js +1 -0
- package/dist/9065.js +1 -0
- package/dist/9182.js +1 -0
- package/dist/9339.js +1 -0
- package/dist/9453.js +1 -0
- package/dist/9833.js +1 -0
- package/dist/9833.js.map +1 -0
- package/dist/9856.js +1 -0
- package/dist/9856.js.map +1 -0
- package/dist/9920.js +1 -0
- package/dist/9938.js +1 -0
- package/dist/9943.js +1 -0
- package/dist/9943.js.map +1 -0
- package/dist/main.js +10 -0
- package/dist/main.js.map +1 -0
- package/dist/olaboot-esm-patient-registration-app.js +5 -0
- package/dist/olaboot-esm-patient-registration-app.js.buildmanifest.json +1627 -0
- package/dist/olaboot-esm-patient-registration-app.js.map +1 -0
- package/dist/routes.json +1 -0
- package/docs/images/patient-registration-hierarchy.png +0 -0
- package/example-config.json +14 -0
- package/jest.config.js +3 -0
- package/package.json +60 -0
- package/rspack.config.js +1 -0
- package/src/add-patient-link.extension.tsx +21 -0
- package/src/add-patient-link.scss +3 -0
- package/src/add-patient-link.test.tsx +16 -0
- package/src/config-schema.ts +507 -0
- package/src/constants.ts +14 -0
- package/src/declarations.d.ts +4 -0
- package/src/index.ts +59 -0
- package/src/nav-link.test.tsx +13 -0
- package/src/nav-link.tsx +10 -0
- package/src/offline.resources.ts +157 -0
- package/src/offline.ts +93 -0
- package/src/patient-photo.extension.tsx +11 -0
- package/src/patient-registration/before-save-prompt.component.tsx +72 -0
- package/src/patient-registration/field/__mocks__/field.resource.ts +60 -0
- package/src/patient-registration/field/address/address-field.component.tsx +186 -0
- package/src/patient-registration/field/address/address-hierarchy-levels.component.tsx +71 -0
- package/src/patient-registration/field/address/address-hierarchy.resource.tsx +157 -0
- package/src/patient-registration/field/address/address-hierarchy.test.tsx +296 -0
- package/src/patient-registration/field/address/address-search.component.tsx +87 -0
- package/src/patient-registration/field/address/address-search.scss +53 -0
- package/src/patient-registration/field/address/address-search.test.tsx +141 -0
- package/src/patient-registration/field/address/custom-address-field.component.tsx +32 -0
- package/src/patient-registration/field/cause-of-death/cause-of-death.component.tsx +98 -0
- package/src/patient-registration/field/custom-field.component.tsx +25 -0
- package/src/patient-registration/field/date-and-time-of-death/date-and-time-of-death.component.tsx +79 -0
- package/src/patient-registration/field/dob/dob.component.tsx +167 -0
- package/src/patient-registration/field/dob/dob.test.tsx +90 -0
- package/src/patient-registration/field/field.component.tsx +53 -0
- package/src/patient-registration/field/field.resource.ts +42 -0
- package/src/patient-registration/field/field.scss +171 -0
- package/src/patient-registration/field/field.test.tsx +330 -0
- package/src/patient-registration/field/gender/gender-field.component.tsx +54 -0
- package/src/patient-registration/field/gender/gender-field.test.tsx +99 -0
- package/src/patient-registration/field/id/id-field.component.tsx +136 -0
- package/src/patient-registration/field/id/id-field.test.tsx +121 -0
- package/src/patient-registration/field/id/identifier-selection-overlay.component.tsx +200 -0
- package/src/patient-registration/field/id/identifier-selection.scss +41 -0
- package/src/patient-registration/field/name/name-field.component.tsx +148 -0
- package/src/patient-registration/field/obs/obs-field.component.tsx +261 -0
- package/src/patient-registration/field/obs/obs-field.test.tsx +299 -0
- package/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx +120 -0
- package/src/patient-registration/field/person-attributes/coded-person-attribute-field.test.tsx +141 -0
- package/src/patient-registration/field/person-attributes/location-person-attribute-field.component.tsx +105 -0
- package/src/patient-registration/field/person-attributes/location-person-attribute-field.resource.tsx +48 -0
- package/src/patient-registration/field/person-attributes/person-attribute-field.component.tsx +100 -0
- package/src/patient-registration/field/person-attributes/person-attribute-field.test.tsx +193 -0
- package/src/patient-registration/field/person-attributes/person-attributes.resource.ts +20 -0
- package/src/patient-registration/field/person-attributes/text-person-attribute-field.component.tsx +58 -0
- package/src/patient-registration/field/person-attributes/text-person-attribute-field.test.tsx +90 -0
- package/src/patient-registration/field/phone/phone-field.component.tsx +17 -0
- package/src/patient-registration/form-manager.test.ts +91 -0
- package/src/patient-registration/form-manager.ts +443 -0
- package/src/patient-registration/input/basic-input/input/input.component.tsx +183 -0
- package/src/patient-registration/input/basic-input/input/input.test.tsx +72 -0
- package/src/patient-registration/input/basic-input/select/select-input.component.tsx +32 -0
- package/src/patient-registration/input/basic-input/select/select-input.test.tsx +49 -0
- package/src/patient-registration/input/combo-input/combo-input.component.tsx +130 -0
- package/src/patient-registration/input/combo-input/selection-tick.component.tsx +20 -0
- package/src/patient-registration/input/custom-input/autosuggest/autosuggest.component.tsx +187 -0
- package/src/patient-registration/input/custom-input/autosuggest/autosuggest.scss +62 -0
- package/src/patient-registration/input/custom-input/autosuggest/autosuggest.test.tsx +164 -0
- package/src/patient-registration/input/custom-input/identifier/identifier-input.component.tsx +193 -0
- package/src/patient-registration/input/custom-input/identifier/identifier-input.test.tsx +335 -0
- package/src/patient-registration/input/custom-input/identifier/utils.test.ts +81 -0
- package/src/patient-registration/input/custom-input/identifier/utils.ts +19 -0
- package/src/patient-registration/input/dummy-data/dummy-data-input.component.tsx +56 -0
- package/src/patient-registration/input/dummy-data/dummy-data-input.test.tsx +34 -0
- package/src/patient-registration/input/input.scss +122 -0
- package/src/patient-registration/patient-registration-context.ts +35 -0
- package/src/patient-registration/patient-registration-hooks.ts +376 -0
- package/src/patient-registration/patient-registration-utils.test.ts +33 -0
- package/src/patient-registration/patient-registration-utils.ts +214 -0
- package/src/patient-registration/patient-registration.component.tsx +266 -0
- package/src/patient-registration/patient-registration.resource.test.tsx +22 -0
- package/src/patient-registration/patient-registration.resource.ts +198 -0
- package/src/patient-registration/patient-registration.scss +103 -0
- package/src/patient-registration/patient-registration.test.tsx +580 -0
- package/src/patient-registration/patient-registration.types.ts +322 -0
- package/src/patient-registration/section/death-info/death-info-section.component.tsx +36 -0
- package/src/patient-registration/section/death-info/death-info-section.test.tsx +47 -0
- package/src/patient-registration/section/demographics/demographics-section.component.tsx +30 -0
- package/src/patient-registration/section/demographics/demographics-section.test.tsx +98 -0
- package/src/patient-registration/section/generic-section.component.tsx +17 -0
- package/src/patient-registration/section/patient-relationships/relationships-section.component.tsx +234 -0
- package/src/patient-registration/section/patient-relationships/relationships-section.test.tsx +113 -0
- package/src/patient-registration/section/patient-relationships/relationships.resource.tsx +78 -0
- package/src/patient-registration/section/patient-relationships/relationships.scss +35 -0
- package/src/patient-registration/section/section-wrapper.component.tsx +40 -0
- package/src/patient-registration/section/section.component.tsx +23 -0
- package/src/patient-registration/section/section.scss +21 -0
- package/src/patient-registration/ui-components/overlay/overlay.component.tsx +51 -0
- package/src/patient-registration/ui-components/overlay/overlay.scss +63 -0
- package/src/patient-registration/validation/patient-registration-validation.test.ts +205 -0
- package/src/patient-registration/validation/patient-registration-validation.ts +123 -0
- package/src/resource.ts +12 -0
- package/src/resources-context.ts +14 -0
- package/src/root.component.tsx +63 -0
- package/src/root.scss +7 -0
- package/src/routes.json +61 -0
- package/src/widgets/cancel-patient-edit.modal.tsx +33 -0
- package/src/widgets/cancel-patient-edit.test.tsx +22 -0
- package/src/widgets/delete-identifier-confirmation.modal.tsx +48 -0
- package/src/widgets/delete-identifier-confirmation.test.tsx +32 -0
- package/src/widgets/edit-patient-details-button.component.tsx +33 -0
- package/src/widgets/edit-patient-details-button.scss +3 -0
- package/src/widgets/edit-patient-details-button.test.tsx +35 -0
- package/translations/am.json +120 -0
- package/translations/ar.json +120 -0
- package/translations/ar_SY.json +120 -0
- package/translations/bn.json +120 -0
- package/translations/cs.json +120 -0
- package/translations/de.json +120 -0
- package/translations/en.json +120 -0
- package/translations/en_US.json +120 -0
- package/translations/es.json +120 -0
- package/translations/es_MX.json +120 -0
- package/translations/fr.json +120 -0
- package/translations/he.json +120 -0
- package/translations/hi.json +120 -0
- package/translations/hi_IN.json +120 -0
- package/translations/id.json +120 -0
- package/translations/it.json +120 -0
- package/translations/ka.json +120 -0
- package/translations/km.json +120 -0
- package/translations/ku.json +120 -0
- package/translations/ky.json +120 -0
- package/translations/lg.json +120 -0
- package/translations/ne.json +120 -0
- package/translations/pl.json +120 -0
- package/translations/pt.json +120 -0
- package/translations/pt_BR.json +120 -0
- package/translations/qu.json +120 -0
- package/translations/ro_RO.json +120 -0
- package/translations/ru_RU.json +120 -0
- package/translations/si.json +120 -0
- package/translations/sq.json +120 -0
- package/translations/sw.json +120 -0
- package/translations/sw_KE.json +120 -0
- package/translations/tr.json +120 -0
- package/translations/tr_TR.json +120 -0
- package/translations/uk.json +120 -0
- package/translations/uz.json +120 -0
- package/translations/uz@Latn.json +120 -0
- package/translations/uz_UZ.json +120 -0
- package/translations/vi.json +120 -0
- package/translations/zh.json +120 -0
- package/translations/zh_CN.json +120 -0
- package/translations/zh_TW.json +120 -0
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
2
|
+
import { useField } from 'formik';
|
|
3
|
+
import useSWRImmutable from 'swr/immutable';
|
|
4
|
+
import { type FetchResponse, openmrsFetch } from '@openmrs/esm-framework';
|
|
5
|
+
import { usePatientRegistrationContext } from '../../patient-registration-context';
|
|
6
|
+
|
|
7
|
+
interface AddressFields {
|
|
8
|
+
addressField: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useOrderedAddressHierarchyLevels() {
|
|
12
|
+
const url = '/module/addresshierarchy/ajax/getOrderedAddressHierarchyLevels.form';
|
|
13
|
+
const { data, isLoading, error } = useSWRImmutable<FetchResponse<Array<AddressFields>>, Error>(url, openmrsFetch);
|
|
14
|
+
|
|
15
|
+
const results = useMemo(
|
|
16
|
+
() => ({
|
|
17
|
+
orderedFields: data?.data?.map((field) => field.addressField),
|
|
18
|
+
isLoadingFieldOrder: isLoading,
|
|
19
|
+
errorFetchingFieldOrder: error,
|
|
20
|
+
}),
|
|
21
|
+
[data, isLoading, error],
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return results;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useAddressEntries(fetchResults, searchString) {
|
|
28
|
+
const encodedSearchString = encodeURIComponent(searchString);
|
|
29
|
+
const { data, isLoading, error } = useSWRImmutable<FetchResponse<Array<{ name: string }>>>(
|
|
30
|
+
fetchResults
|
|
31
|
+
? `module/addresshierarchy/ajax/getChildAddressHierarchyEntries.form?searchString=${encodedSearchString}`
|
|
32
|
+
: null,
|
|
33
|
+
openmrsFetch,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (error) {
|
|
38
|
+
console.error(error);
|
|
39
|
+
}
|
|
40
|
+
}, [error]);
|
|
41
|
+
|
|
42
|
+
const results = useMemo(
|
|
43
|
+
() => ({
|
|
44
|
+
entries: data?.data?.map((item) => item.name),
|
|
45
|
+
isLoadingAddressEntries: isLoading,
|
|
46
|
+
errorFetchingAddressEntries: error,
|
|
47
|
+
}),
|
|
48
|
+
[data, isLoading, error],
|
|
49
|
+
);
|
|
50
|
+
return results;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* This hook is being used to fetch ordered address fields as configured in the address hierarchy
|
|
55
|
+
* This hook returns the valid search term for valid fields to get suitable entries for the field
|
|
56
|
+
* This also returns the function to reset the lower ordered fields if the value of a field is changed.
|
|
57
|
+
*/
|
|
58
|
+
export function useAddressEntryFetchConfig(addressField: string) {
|
|
59
|
+
const { orderedFields, isLoadingFieldOrder } = useOrderedAddressHierarchyLevels();
|
|
60
|
+
const { setFieldValue } = usePatientRegistrationContext();
|
|
61
|
+
const [, { value: addressValues }] = useField('address');
|
|
62
|
+
|
|
63
|
+
const index = useMemo(
|
|
64
|
+
() => (!isLoadingFieldOrder ? orderedFields.findIndex((field) => field === addressField) : -1),
|
|
65
|
+
[orderedFields, addressField, isLoadingFieldOrder],
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const addressFieldSearchConfig = useMemo(() => {
|
|
69
|
+
let fetchEntriesForField = true;
|
|
70
|
+
const previousSelectedFields = orderedFields?.slice(0, index) ?? [];
|
|
71
|
+
let previousSelectedValues = [];
|
|
72
|
+
for (const fieldName of previousSelectedFields) {
|
|
73
|
+
if (!addressValues[fieldName]) {
|
|
74
|
+
fetchEntriesForField = false;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
previousSelectedValues.push(addressValues[fieldName]);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
fetchEntriesForField,
|
|
81
|
+
searchString: previousSelectedValues.join('|'),
|
|
82
|
+
};
|
|
83
|
+
}, [orderedFields, index, addressValues]);
|
|
84
|
+
|
|
85
|
+
const updateChildElements = useCallback(() => {
|
|
86
|
+
if (isLoadingFieldOrder) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
orderedFields.slice(index + 1).map((fieldName) => {
|
|
90
|
+
setFieldValue(`address.${fieldName}`, '');
|
|
91
|
+
});
|
|
92
|
+
}, [index, isLoadingFieldOrder, orderedFields, setFieldValue]);
|
|
93
|
+
|
|
94
|
+
const results = useMemo(
|
|
95
|
+
() => ({
|
|
96
|
+
...addressFieldSearchConfig,
|
|
97
|
+
updateChildElements,
|
|
98
|
+
}),
|
|
99
|
+
[addressFieldSearchConfig, updateChildElements],
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
return results;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function useAddressHierarchy(searchString: string, separator: string) {
|
|
106
|
+
const { data, error, isLoading } = useSWRImmutable<
|
|
107
|
+
FetchResponse<
|
|
108
|
+
Array<{
|
|
109
|
+
address: string;
|
|
110
|
+
}>
|
|
111
|
+
>,
|
|
112
|
+
Error
|
|
113
|
+
>(
|
|
114
|
+
searchString
|
|
115
|
+
? `/module/addresshierarchy/ajax/getPossibleFullAddresses.form?separator=${separator}&searchString=${searchString}`
|
|
116
|
+
: null,
|
|
117
|
+
openmrsFetch,
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const results = useMemo(
|
|
121
|
+
() => ({
|
|
122
|
+
addresses: data?.data?.map((address) => address.address) ?? [],
|
|
123
|
+
error,
|
|
124
|
+
isLoading,
|
|
125
|
+
}),
|
|
126
|
+
[data?.data, error, isLoading],
|
|
127
|
+
);
|
|
128
|
+
return results;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function useAddressHierarchyWithParentSearch(addressField: string, parentid: string, query: string) {
|
|
132
|
+
const { data, error, isLoading } = useSWRImmutable<
|
|
133
|
+
FetchResponse<
|
|
134
|
+
Array<{
|
|
135
|
+
uuid: string;
|
|
136
|
+
name: string;
|
|
137
|
+
}>
|
|
138
|
+
>,
|
|
139
|
+
Error
|
|
140
|
+
>(
|
|
141
|
+
query
|
|
142
|
+
? `/module/addresshierarchy/ajax/getPossibleAddressHierarchyEntriesWithParents.form?addressField=${addressField}&limit=20&searchString=${query}&parentUuid=${parentid}`
|
|
143
|
+
: null,
|
|
144
|
+
openmrsFetch,
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const results = useMemo(
|
|
148
|
+
() => ({
|
|
149
|
+
error: error,
|
|
150
|
+
isLoading,
|
|
151
|
+
addresses: data?.data ?? [],
|
|
152
|
+
}),
|
|
153
|
+
[data?.data, error, isLoading],
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
return results;
|
|
157
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { screen } from '@testing-library/react';
|
|
3
|
+
import { Formik, Form } from 'formik';
|
|
4
|
+
import { getDefaultsFromConfigSchema, useConfig } from '@openmrs/esm-framework';
|
|
5
|
+
import { mockedAddressTemplate, mockedOrderedFields, mockOpenmrsId, mockPatient, mockSession } from '__mocks__';
|
|
6
|
+
import { renderWithContext } from 'tools';
|
|
7
|
+
import { type AddressTemplate } from '../../patient-registration.types';
|
|
8
|
+
import { type RegistrationConfig, esmPatientRegistrationSchema } from '../../../config-schema';
|
|
9
|
+
import { type Resources } from '../../../offline.resources';
|
|
10
|
+
import {
|
|
11
|
+
PatientRegistrationContextProvider,
|
|
12
|
+
type PatientRegistrationContextProps,
|
|
13
|
+
} from '../../patient-registration-context';
|
|
14
|
+
import { useOrderedAddressHierarchyLevels } from './address-hierarchy.resource';
|
|
15
|
+
import { ResourcesContextProvider } from '../../../resources-context';
|
|
16
|
+
import { AddressComponent } from './address-field.component';
|
|
17
|
+
|
|
18
|
+
const mockUseConfig = jest.mocked(useConfig<RegistrationConfig>);
|
|
19
|
+
const mockUseOrderedAddressHierarchyLevels = jest.mocked(useOrderedAddressHierarchyLevels);
|
|
20
|
+
|
|
21
|
+
const mockResourcesContextValue = {
|
|
22
|
+
addressTemplate: {} as AddressTemplate,
|
|
23
|
+
currentSession: mockSession.data,
|
|
24
|
+
identifierTypes: [],
|
|
25
|
+
relationshipTypes: [],
|
|
26
|
+
} as Resources;
|
|
27
|
+
|
|
28
|
+
const mockInitialFormValues = {
|
|
29
|
+
additionalFamilyName: '',
|
|
30
|
+
additionalGivenName: '',
|
|
31
|
+
additionalMiddleName: '',
|
|
32
|
+
addNameInLocalLanguage: false,
|
|
33
|
+
address: {},
|
|
34
|
+
birthdate: '',
|
|
35
|
+
birthdateEstimated: false,
|
|
36
|
+
deathCause: '',
|
|
37
|
+
deathDate: '',
|
|
38
|
+
deathTime: '',
|
|
39
|
+
deathTimeFormat: 'AM' as 'AM' | 'PM',
|
|
40
|
+
nonCodedCauseOfDeath: '',
|
|
41
|
+
familyName: 'Doe',
|
|
42
|
+
gender: 'male',
|
|
43
|
+
givenName: 'John',
|
|
44
|
+
identifiers: mockOpenmrsId,
|
|
45
|
+
isDead: false,
|
|
46
|
+
middleName: 'Test',
|
|
47
|
+
monthsEstimated: 0,
|
|
48
|
+
patientUuid: mockPatient.uuid,
|
|
49
|
+
relationships: [],
|
|
50
|
+
telephoneNumber: '',
|
|
51
|
+
yearsEstimated: 0,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const initialContextValues: PatientRegistrationContextProps = {
|
|
55
|
+
currentPhoto: '',
|
|
56
|
+
inEditMode: false,
|
|
57
|
+
identifierTypes: [],
|
|
58
|
+
initialFormValues: mockInitialFormValues,
|
|
59
|
+
isOffline: false,
|
|
60
|
+
setCapturePhotoProps: jest.fn(),
|
|
61
|
+
setFieldValue: jest.fn(),
|
|
62
|
+
setFieldTouched: jest.fn(),
|
|
63
|
+
setInitialFormValues: jest.fn(),
|
|
64
|
+
validationSchema: null,
|
|
65
|
+
values: mockInitialFormValues,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
jest.mock('./address-hierarchy.resource', () => ({
|
|
69
|
+
...jest.requireActual('./address-hierarchy.resource'),
|
|
70
|
+
useOrderedAddressHierarchyLevels: jest.fn(),
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
async function renderAddressHierarchy(contextValues: PatientRegistrationContextProps) {
|
|
74
|
+
await renderWithContext(
|
|
75
|
+
<PatientRegistrationContextProvider value={contextValues}>
|
|
76
|
+
<Formik initialValues={mockInitialFormValues} onSubmit={null}>
|
|
77
|
+
<Form>
|
|
78
|
+
<AddressComponent />
|
|
79
|
+
</Form>
|
|
80
|
+
</Formik>
|
|
81
|
+
</PatientRegistrationContextProvider>,
|
|
82
|
+
ResourcesContextProvider,
|
|
83
|
+
mockResourcesContextValue,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
describe('Address hierarchy', () => {
|
|
88
|
+
it('renders a loading skeleton when the address template is loading', () => {
|
|
89
|
+
mockUseConfig.mockReturnValue({
|
|
90
|
+
...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
|
|
91
|
+
fieldConfigurations: {
|
|
92
|
+
address: {
|
|
93
|
+
useAddressHierarchy: {
|
|
94
|
+
enabled: false,
|
|
95
|
+
useQuickSearch: false,
|
|
96
|
+
searchAddressByLevel: false,
|
|
97
|
+
},
|
|
98
|
+
requiredAddressFields: [],
|
|
99
|
+
},
|
|
100
|
+
} as RegistrationConfig['fieldConfigurations'],
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
mockUseOrderedAddressHierarchyLevels.mockReturnValue({
|
|
104
|
+
orderedFields: [],
|
|
105
|
+
isLoadingFieldOrder: false,
|
|
106
|
+
errorFetchingFieldOrder: undefined,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
renderAddressHierarchy(initialContextValues);
|
|
110
|
+
expect(screen.getByRole('progressbar')).toBeInTheDocument();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('renders a loading skeleton when the address hierarchy feature is enabled and address hierarchy order levels are loading', () => {
|
|
114
|
+
mockUseConfig.mockReturnValue({
|
|
115
|
+
...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
|
|
116
|
+
fieldConfigurations: {
|
|
117
|
+
address: {
|
|
118
|
+
useAddressHierarchy: {
|
|
119
|
+
enabled: true,
|
|
120
|
+
useQuickSearch: false,
|
|
121
|
+
searchAddressByLevel: false,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
} as RegistrationConfig['fieldConfigurations'],
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
mockUseOrderedAddressHierarchyLevels.mockReturnValue({
|
|
128
|
+
orderedFields: [],
|
|
129
|
+
isLoadingFieldOrder: true,
|
|
130
|
+
errorFetchingFieldOrder: undefined,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
renderAddressHierarchy(initialContextValues);
|
|
134
|
+
expect(screen.getByRole('progressbar')).toBeInTheDocument();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('renders a loading skeleton when the address hierarchy feature is enabled and address hierarchy order levels are loading', () => {
|
|
138
|
+
mockUseConfig.mockReturnValue({
|
|
139
|
+
...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
|
|
140
|
+
fieldConfigurations: {
|
|
141
|
+
address: {
|
|
142
|
+
useAddressHierarchy: {
|
|
143
|
+
enabled: true,
|
|
144
|
+
useQuickSearch: false,
|
|
145
|
+
searchAddressByLevel: false,
|
|
146
|
+
},
|
|
147
|
+
requiredAddressFields: [],
|
|
148
|
+
},
|
|
149
|
+
} as RegistrationConfig['fieldConfigurations'],
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
mockUseOrderedAddressHierarchyLevels.mockReturnValue({
|
|
153
|
+
orderedFields: [],
|
|
154
|
+
isLoadingFieldOrder: false,
|
|
155
|
+
errorFetchingFieldOrder: undefined,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
renderAddressHierarchy(initialContextValues);
|
|
159
|
+
expect(screen.getByRole('progressbar')).toBeInTheDocument();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('renders the address component with address hierarchy disabled', () => {
|
|
163
|
+
mockUseConfig.mockReturnValue({
|
|
164
|
+
...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
|
|
165
|
+
fieldConfigurations: {
|
|
166
|
+
address: {
|
|
167
|
+
useAddressHierarchy: {
|
|
168
|
+
enabled: false,
|
|
169
|
+
useQuickSearch: false,
|
|
170
|
+
searchAddressByLevel: false,
|
|
171
|
+
},
|
|
172
|
+
requiredAddressFields: [],
|
|
173
|
+
},
|
|
174
|
+
} as RegistrationConfig['fieldConfigurations'],
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
mockUseOrderedAddressHierarchyLevels.mockReturnValue({
|
|
178
|
+
orderedFields: [],
|
|
179
|
+
isLoadingFieldOrder: false,
|
|
180
|
+
errorFetchingFieldOrder: undefined,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
mockResourcesContextValue.addressTemplate = mockedAddressTemplate;
|
|
184
|
+
|
|
185
|
+
renderAddressHierarchy(initialContextValues);
|
|
186
|
+
|
|
187
|
+
const allFields = mockedAddressTemplate.lines.flat().filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN');
|
|
188
|
+
allFields.forEach((field) => {
|
|
189
|
+
const textFieldInput = screen.getByLabelText(`${field.displayText} (optional)`);
|
|
190
|
+
expect(textFieldInput).toBeInTheDocument();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('renders the address hierarchy fields in order if the address hierarchy feature is enabled', () => {
|
|
195
|
+
mockUseConfig.mockReturnValue({
|
|
196
|
+
...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
|
|
197
|
+
fieldConfigurations: {
|
|
198
|
+
address: {
|
|
199
|
+
useAddressHierarchy: {
|
|
200
|
+
enabled: true,
|
|
201
|
+
useQuickSearch: false,
|
|
202
|
+
searchAddressByLevel: false,
|
|
203
|
+
},
|
|
204
|
+
requiredAddressFields: [],
|
|
205
|
+
},
|
|
206
|
+
} as RegistrationConfig['fieldConfigurations'],
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
mockUseOrderedAddressHierarchyLevels.mockReturnValue({
|
|
210
|
+
orderedFields: [],
|
|
211
|
+
isLoadingFieldOrder: false,
|
|
212
|
+
errorFetchingFieldOrder: undefined,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
mockResourcesContextValue.addressTemplate = mockedAddressTemplate;
|
|
216
|
+
|
|
217
|
+
renderAddressHierarchy(initialContextValues);
|
|
218
|
+
|
|
219
|
+
const allFields = mockedAddressTemplate.lines.flat().filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN');
|
|
220
|
+
const orderMap = Object.fromEntries(mockedOrderedFields.map((field, indx) => [field, indx]));
|
|
221
|
+
allFields.sort(
|
|
222
|
+
(existingField1, existingField2) =>
|
|
223
|
+
orderMap[existingField1.codeName ?? 0] - orderMap[existingField2.codeName ?? 0],
|
|
224
|
+
);
|
|
225
|
+
allFields.forEach((field) => {
|
|
226
|
+
const textFieldInput = screen.getByLabelText(`${field.displayText} (optional)`);
|
|
227
|
+
expect(textFieldInput).toBeInTheDocument();
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('renders the quick search bar above the address hierarchy fields when the address hierarchy feature is enabled and useQuickSearch is set to true', () => {
|
|
232
|
+
mockUseConfig.mockReturnValue({
|
|
233
|
+
...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
|
|
234
|
+
fieldConfigurations: {
|
|
235
|
+
address: {
|
|
236
|
+
useAddressHierarchy: {
|
|
237
|
+
enabled: true,
|
|
238
|
+
useQuickSearch: true,
|
|
239
|
+
searchAddressByLevel: false,
|
|
240
|
+
},
|
|
241
|
+
requiredAddressFields: [],
|
|
242
|
+
},
|
|
243
|
+
} as RegistrationConfig['fieldConfigurations'],
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
mockUseOrderedAddressHierarchyLevels.mockReturnValue({
|
|
247
|
+
orderedFields: [],
|
|
248
|
+
isLoadingFieldOrder: false,
|
|
249
|
+
errorFetchingFieldOrder: undefined,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
mockResourcesContextValue.addressTemplate = mockedAddressTemplate;
|
|
253
|
+
|
|
254
|
+
renderAddressHierarchy(initialContextValues);
|
|
255
|
+
|
|
256
|
+
const searchbox = screen.getByRole('searchbox', { name: /search address/i });
|
|
257
|
+
expect(searchbox).toBeInTheDocument();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('renders combobox fields when address hierarchy is enabled and searchAddressByLevel is set to true', () => {
|
|
261
|
+
mockUseConfig.mockReturnValue({
|
|
262
|
+
...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
|
|
263
|
+
fieldConfigurations: {
|
|
264
|
+
address: {
|
|
265
|
+
useAddressHierarchy: {
|
|
266
|
+
enabled: true,
|
|
267
|
+
useQuickSearch: false,
|
|
268
|
+
searchAddressByLevel: true,
|
|
269
|
+
},
|
|
270
|
+
requiredAddressFields: [],
|
|
271
|
+
},
|
|
272
|
+
} as RegistrationConfig['fieldConfigurations'],
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
mockUseOrderedAddressHierarchyLevels.mockReturnValue({
|
|
276
|
+
orderedFields: [],
|
|
277
|
+
isLoadingFieldOrder: false,
|
|
278
|
+
errorFetchingFieldOrder: undefined,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
mockResourcesContextValue.addressTemplate = mockedAddressTemplate;
|
|
282
|
+
|
|
283
|
+
renderAddressHierarchy(initialContextValues);
|
|
284
|
+
|
|
285
|
+
const allFields = mockedAddressTemplate.lines.flat().filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN');
|
|
286
|
+
const orderMap = Object.fromEntries(mockedOrderedFields.map((field, indx) => [field, indx]));
|
|
287
|
+
allFields.sort(
|
|
288
|
+
(existingField1, existingField2) =>
|
|
289
|
+
orderMap[existingField1.codeName ?? 0] - orderMap[existingField2.codeName ?? 0],
|
|
290
|
+
);
|
|
291
|
+
allFields.forEach((field) => {
|
|
292
|
+
const textFieldInput = screen.getByLabelText(`${field.displayText} (optional)`);
|
|
293
|
+
expect(textFieldInput).toBeInTheDocument();
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React, { useState, useRef, useEffect, useMemo } from 'react';
|
|
2
|
+
import { useFormikContext } from 'formik';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { Search } from '@carbon/react';
|
|
5
|
+
import { useAddressHierarchy } from './address-hierarchy.resource';
|
|
6
|
+
import styles from './address-search.scss';
|
|
7
|
+
|
|
8
|
+
interface AddressSearchComponentProps {
|
|
9
|
+
addressLayout: Array<any>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const AddressSearchComponent: React.FC<AddressSearchComponentProps> = ({ addressLayout }) => {
|
|
13
|
+
const { t } = useTranslation();
|
|
14
|
+
const separator = ' > ';
|
|
15
|
+
const searchBox = useRef(null);
|
|
16
|
+
const wrapper = useRef(null);
|
|
17
|
+
const [searchString, setSearchString] = useState('');
|
|
18
|
+
|
|
19
|
+
const { addresses } = useAddressHierarchy(searchString, separator);
|
|
20
|
+
|
|
21
|
+
const addressOptions: Array<string> = useMemo(() => {
|
|
22
|
+
const options: Set<string> = new Set();
|
|
23
|
+
addresses.forEach((address) => {
|
|
24
|
+
const values = address.split(separator);
|
|
25
|
+
values.forEach((val, index) => {
|
|
26
|
+
if (val.toLowerCase().includes(searchString.toLowerCase())) {
|
|
27
|
+
options.add(values.slice(0, index + 1).join(separator));
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return [...options];
|
|
32
|
+
}, [addresses, searchString]);
|
|
33
|
+
|
|
34
|
+
const { setFieldValue } = useFormikContext();
|
|
35
|
+
|
|
36
|
+
const handleInputChange = (e) => {
|
|
37
|
+
setSearchString(e.target.value);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const handleChange = (address) => {
|
|
41
|
+
if (address) {
|
|
42
|
+
const values = address.split(separator);
|
|
43
|
+
addressLayout.map(({ name }, index) => {
|
|
44
|
+
setFieldValue(`address.${name}`, values?.[index] ?? '');
|
|
45
|
+
});
|
|
46
|
+
setSearchString('');
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const handleClickOutsideComponent = (e) => {
|
|
51
|
+
if (wrapper.current && !wrapper.current.contains(e.target)) {
|
|
52
|
+
setSearchString('');
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
document.addEventListener('mousedown', handleClickOutsideComponent);
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
document.removeEventListener('mousedown', handleClickOutsideComponent);
|
|
61
|
+
};
|
|
62
|
+
}, [wrapper]);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div className={styles.autocomplete} ref={wrapper} style={{ marginBottom: '1rem' }}>
|
|
66
|
+
<Search
|
|
67
|
+
onChange={handleInputChange}
|
|
68
|
+
labelText={t('searchAddress', 'Search address')}
|
|
69
|
+
placeholder={t('searchAddress', 'Search address')}
|
|
70
|
+
ref={searchBox}
|
|
71
|
+
value={searchString}
|
|
72
|
+
/>
|
|
73
|
+
{addressOptions.length > 0 && (
|
|
74
|
+
/* Since the input has a marginBottom of 1rem */
|
|
75
|
+
<ul className={styles.suggestions}>
|
|
76
|
+
{addressOptions.map((address, index) => (
|
|
77
|
+
<li key={index} onClick={(e) => handleChange(address)}>
|
|
78
|
+
{address}
|
|
79
|
+
</li>
|
|
80
|
+
))}
|
|
81
|
+
</ul>
|
|
82
|
+
)}
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default AddressSearchComponent;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
@use '@carbon/layout';
|
|
2
|
+
@use '@carbon/type';
|
|
3
|
+
@use '@openmrs/esm-styleguide/src/vars' as *;
|
|
4
|
+
|
|
5
|
+
.label01 {
|
|
6
|
+
@include type.type-style('label-01');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.suggestions {
|
|
10
|
+
border-top-width: 0;
|
|
11
|
+
list-style: none;
|
|
12
|
+
margin-top: 0;
|
|
13
|
+
max-height: 20rem;
|
|
14
|
+
overflow-y: auto;
|
|
15
|
+
padding-left: 0;
|
|
16
|
+
width: 100%;
|
|
17
|
+
position: absolute;
|
|
18
|
+
left: 0;
|
|
19
|
+
background-color: #fff;
|
|
20
|
+
margin-bottom: 1.25rem;
|
|
21
|
+
z-index: 99;
|
|
22
|
+
border: 1px solid $ui-03;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.suggestions li {
|
|
26
|
+
padding: layout.$spacing-05;
|
|
27
|
+
line-height: 1.29;
|
|
28
|
+
color: #525252;
|
|
29
|
+
border-bottom: 1px solid #8d8d8d;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.suggestions li:hover {
|
|
33
|
+
background-color: #e5e5e5;
|
|
34
|
+
color: #161616;
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.suggestions li:not(:last-of-type) {
|
|
39
|
+
border-bottom: 1px solid #999;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.autocomplete {
|
|
43
|
+
position: relative;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.autocompleteSearch {
|
|
47
|
+
width: 100%;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.suggestions a {
|
|
51
|
+
color: inherit;
|
|
52
|
+
text-decoration: none;
|
|
53
|
+
}
|