@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,141 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { screen } from '@testing-library/react';
|
|
4
|
+
import { Formik, Form, useFormikContext } from 'formik';
|
|
5
|
+
import { renderWithContext } from 'tools';
|
|
6
|
+
import { type Resources } from '../../../offline.resources';
|
|
7
|
+
import { PatientRegistrationContextProvider } from '../../patient-registration-context';
|
|
8
|
+
import { getDefaultsFromConfigSchema, useConfig } from '@openmrs/esm-framework';
|
|
9
|
+
import { useAddressHierarchy, useOrderedAddressHierarchyLevels } from './address-hierarchy.resource';
|
|
10
|
+
import { type RegistrationConfig, esmPatientRegistrationSchema } from '../../../config-schema';
|
|
11
|
+
import { mockedAddressTemplate, mockedAddressOptions, mockedOrderedFields } from '__mocks__';
|
|
12
|
+
import { ResourcesContextProvider } from '../../../resources-context';
|
|
13
|
+
import AddressSearchComponent from './address-search.component';
|
|
14
|
+
|
|
15
|
+
const mockUseConfig = jest.mocked(useConfig<RegistrationConfig>);
|
|
16
|
+
const mockUseAddressHierarchy = jest.mocked(useAddressHierarchy);
|
|
17
|
+
const mockUseOrderedAddressHierarchyLevels = jest.mocked(useOrderedAddressHierarchyLevels);
|
|
18
|
+
const mockUseFormikContext = useFormikContext as jest.Mock;
|
|
19
|
+
|
|
20
|
+
jest.mock('./address-hierarchy.resource', () => ({
|
|
21
|
+
...(jest.requireActual('./address-hierarchy.resource') as jest.Mock),
|
|
22
|
+
useAddressHierarchy: jest.fn(),
|
|
23
|
+
useOrderedAddressHierarchyLevels: jest.fn(),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
jest.mock('../../patient-registration.resource', () => ({
|
|
27
|
+
...(jest.requireActual('../../../patient-registration.resource') as jest.Mock),
|
|
28
|
+
useAddressHierarchy: jest.fn(),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
jest.mock('formik', () => ({
|
|
32
|
+
...(jest.requireActual('formik') as jest.Mock),
|
|
33
|
+
useFormikContext: jest.fn(() => ({})),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
const allFields = mockedAddressTemplate.lines
|
|
37
|
+
.flat()
|
|
38
|
+
.filter((field) => field.isToken === 'IS_ADDR_TOKEN')
|
|
39
|
+
.map(({ codeName, displayText }) => ({
|
|
40
|
+
id: codeName,
|
|
41
|
+
name: codeName,
|
|
42
|
+
label: displayText,
|
|
43
|
+
}));
|
|
44
|
+
const orderMap = Object.fromEntries(mockedOrderedFields.map((field, indx) => [field, indx]));
|
|
45
|
+
allFields.sort((existingField1, existingField2) => orderMap[existingField1.name] - orderMap[existingField2.name]);
|
|
46
|
+
|
|
47
|
+
async function renderAddressHierarchy(addressTemplate = mockedAddressTemplate) {
|
|
48
|
+
const mockResourcesContextValue = { addressTemplate } as unknown as Resources;
|
|
49
|
+
|
|
50
|
+
await renderWithContext(
|
|
51
|
+
<Formik initialValues={{}} onSubmit={null}>
|
|
52
|
+
<Form>
|
|
53
|
+
<PatientRegistrationContextProvider value={{ setFieldValue: jest.fn() } as any}>
|
|
54
|
+
<AddressSearchComponent addressLayout={allFields} />
|
|
55
|
+
</PatientRegistrationContextProvider>
|
|
56
|
+
</Form>
|
|
57
|
+
</Formik>,
|
|
58
|
+
ResourcesContextProvider,
|
|
59
|
+
mockResourcesContextValue,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const setFieldValue = jest.fn();
|
|
64
|
+
|
|
65
|
+
describe('Testing address search bar', () => {
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
mockUseConfig.mockReturnValue({
|
|
68
|
+
...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
|
|
69
|
+
fieldConfigurations: {
|
|
70
|
+
address: {
|
|
71
|
+
useAddressHierarchy: {
|
|
72
|
+
enabled: true,
|
|
73
|
+
useQuickSearch: true,
|
|
74
|
+
searchAddressByLevel: false,
|
|
75
|
+
},
|
|
76
|
+
requiredAddressFields: [],
|
|
77
|
+
},
|
|
78
|
+
} as RegistrationConfig['fieldConfigurations'],
|
|
79
|
+
});
|
|
80
|
+
mockUseOrderedAddressHierarchyLevels.mockReturnValue({
|
|
81
|
+
orderedFields: mockedOrderedFields,
|
|
82
|
+
isLoadingFieldOrder: false,
|
|
83
|
+
errorFetchingFieldOrder: null,
|
|
84
|
+
});
|
|
85
|
+
mockUseFormikContext.mockReturnValue({
|
|
86
|
+
setFieldValue,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should render the search bar', () => {
|
|
91
|
+
mockUseAddressHierarchy.mockReturnValue({
|
|
92
|
+
addresses: [],
|
|
93
|
+
error: null,
|
|
94
|
+
isLoading: false,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
renderAddressHierarchy();
|
|
98
|
+
|
|
99
|
+
const searchbox = screen.getByRole('searchbox');
|
|
100
|
+
expect(searchbox).toBeInTheDocument();
|
|
101
|
+
|
|
102
|
+
const ul = screen.queryByRole('list');
|
|
103
|
+
expect(ul).not.toBeInTheDocument();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should render only the results for the search term matched address' parents", async () => {
|
|
107
|
+
const user = userEvent.setup();
|
|
108
|
+
|
|
109
|
+
mockUseAddressHierarchy.mockReturnValue({
|
|
110
|
+
addresses: mockedAddressOptions,
|
|
111
|
+
error: null,
|
|
112
|
+
isLoading: false,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
renderAddressHierarchy();
|
|
116
|
+
|
|
117
|
+
const searchString = 'nea';
|
|
118
|
+
const separator = ' > ';
|
|
119
|
+
const options: Set<string> = new Set();
|
|
120
|
+
|
|
121
|
+
mockedAddressOptions.forEach((address) => {
|
|
122
|
+
const values = address.split(separator);
|
|
123
|
+
values.forEach((val, index) => {
|
|
124
|
+
if (val.toLowerCase().includes(searchString.toLowerCase())) {
|
|
125
|
+
options.add(values.slice(0, index + 1).join(separator));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const addressOptions = [...options];
|
|
131
|
+
addressOptions.forEach(async (address) => {
|
|
132
|
+
const optionElement = screen.getByText(address);
|
|
133
|
+
expect(optionElement).toBeInTheDocument();
|
|
134
|
+
await user.click(optionElement);
|
|
135
|
+
const values = address.split(separator);
|
|
136
|
+
allFields.map(({ name }, index) => {
|
|
137
|
+
expect(setFieldValue).toHaveBeenCalledWith(`address.${name}`, values?.[index]);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { Field } from 'formik';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { Input } from '../../input/basic-input/input/input.component';
|
|
6
|
+
import styles from '../field.scss';
|
|
7
|
+
import { type FieldDefinition } from '../../../config-schema';
|
|
8
|
+
|
|
9
|
+
export interface AddressFieldProps {
|
|
10
|
+
fieldDefinition: FieldDefinition;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const AddressField: React.FC<AddressFieldProps> = ({ fieldDefinition }) => {
|
|
14
|
+
const { t } = useTranslation();
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div className={classNames(styles.customField, styles.halfWidthInDesktopView)}>
|
|
18
|
+
<Field name={fieldDefinition.id}>
|
|
19
|
+
{({ field, form: { touched, errors }, meta }) => {
|
|
20
|
+
return (
|
|
21
|
+
<Input
|
|
22
|
+
id={fieldDefinition.id}
|
|
23
|
+
labelText={t(`${fieldDefinition.label}`, `${fieldDefinition.label}`)}
|
|
24
|
+
required={fieldDefinition?.validation?.required ?? false}
|
|
25
|
+
{...field}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}}
|
|
29
|
+
</Field>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { Field, useField } from 'formik';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { InlineNotification, Layer, Select, SelectItem, SelectSkeleton, TextInput } from '@carbon/react';
|
|
6
|
+
import { useConfig } from '@openmrs/esm-framework';
|
|
7
|
+
import { type RegistrationConfig } from '../../../config-schema';
|
|
8
|
+
import { useConceptAnswers } from '../field.resource';
|
|
9
|
+
import styles from '../field.scss';
|
|
10
|
+
|
|
11
|
+
export const CauseOfDeathField: React.FC = () => {
|
|
12
|
+
const { t } = useTranslation();
|
|
13
|
+
const { fieldConfigurations, freeTextFieldConceptUuid } = useConfig<RegistrationConfig>();
|
|
14
|
+
const [deathCause, deathCauseMeta] = useField('deathCause');
|
|
15
|
+
|
|
16
|
+
const conceptUuid = fieldConfigurations?.causeOfDeath?.conceptUuid;
|
|
17
|
+
const required = fieldConfigurations?.causeOfDeath?.required;
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
data: conceptAnswers,
|
|
21
|
+
isLoading: isLoadingConceptAnswers,
|
|
22
|
+
error: errorLoadingConceptAnswers,
|
|
23
|
+
} = useConceptAnswers(conceptUuid);
|
|
24
|
+
|
|
25
|
+
const answers = useMemo(() => {
|
|
26
|
+
if (!isLoadingConceptAnswers && conceptAnswers) {
|
|
27
|
+
return conceptAnswers.map((answer) => ({ ...answer, label: answer.display }));
|
|
28
|
+
}
|
|
29
|
+
return [];
|
|
30
|
+
}, [conceptAnswers, isLoadingConceptAnswers]);
|
|
31
|
+
|
|
32
|
+
if (isLoadingConceptAnswers) {
|
|
33
|
+
return (
|
|
34
|
+
<div className={classNames(styles.customField, styles.halfWidthInDesktopView)}>
|
|
35
|
+
<h4 className={styles.productiveHeading02Light}>{t('causeOfDeathInputLabel', 'Cause of death')}</h4>
|
|
36
|
+
<SelectSkeleton />
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div className={classNames(styles.customField, styles.halfWidthInDesktopView)}>
|
|
43
|
+
<h4 className={styles.productiveHeading02Light}>{t('causeOfDeathInputLabel', 'Cause of death')}</h4>
|
|
44
|
+
{errorLoadingConceptAnswers || !conceptUuid ? (
|
|
45
|
+
<InlineNotification
|
|
46
|
+
hideCloseButton
|
|
47
|
+
kind="error"
|
|
48
|
+
title={t('errorFetchingCodedCausesOfDeath', 'Error fetching coded causes of death')}
|
|
49
|
+
subtitle={t('refreshOrContactAdmin', 'Try refreshing the page or contact your system administrator')}
|
|
50
|
+
/>
|
|
51
|
+
) : (
|
|
52
|
+
<>
|
|
53
|
+
<Field name="deathCause">
|
|
54
|
+
{({ field, form: { touched, errors }, meta }) => {
|
|
55
|
+
return (
|
|
56
|
+
<Layer>
|
|
57
|
+
<Select
|
|
58
|
+
{...field}
|
|
59
|
+
id="deathCause"
|
|
60
|
+
invalid={errors.deathCause && touched.deathCause}
|
|
61
|
+
invalidText={errors.deathCause?.message}
|
|
62
|
+
labelText={t('causeOfDeathInputLabel', 'Cause of Death')}
|
|
63
|
+
name="deathCause"
|
|
64
|
+
required={required}>
|
|
65
|
+
<SelectItem id="empty-default-option" value={null} text={t('selectAnOption', 'Select an option')} />
|
|
66
|
+
{answers.map((answer) => (
|
|
67
|
+
<SelectItem id={answer.uuid} key={answer.uuid} text={answer.label} value={answer.uuid} />
|
|
68
|
+
))}
|
|
69
|
+
</Select>
|
|
70
|
+
</Layer>
|
|
71
|
+
);
|
|
72
|
+
}}
|
|
73
|
+
</Field>
|
|
74
|
+
{deathCause.value === freeTextFieldConceptUuid && (
|
|
75
|
+
<div className={styles.nonCodedCauseOfDeath}>
|
|
76
|
+
<Field name="nonCodedCauseOfDeath">
|
|
77
|
+
{({ field, form: { touched, errors }, meta }) => {
|
|
78
|
+
return (
|
|
79
|
+
<Layer>
|
|
80
|
+
<TextInput
|
|
81
|
+
{...field}
|
|
82
|
+
id="nonCodedCauseOfDeath"
|
|
83
|
+
invalid={errors?.nonCodedCauseOfDeath && touched.nonCodedCauseOfDeath}
|
|
84
|
+
invalidText={errors?.nonCodedCauseOfDeath?.message}
|
|
85
|
+
labelText={t('nonCodedCauseOfDeath', 'Non-coded cause of death')}
|
|
86
|
+
placeholder={t('enterNonCodedCauseOfDeath', 'Enter non-coded cause of death')}
|
|
87
|
+
/>
|
|
88
|
+
</Layer>
|
|
89
|
+
);
|
|
90
|
+
}}
|
|
91
|
+
</Field>
|
|
92
|
+
</div>
|
|
93
|
+
)}
|
|
94
|
+
</>
|
|
95
|
+
)}
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useConfig } from '@openmrs/esm-framework';
|
|
3
|
+
import { AddressField } from './address/custom-address-field.component';
|
|
4
|
+
import { ObsField } from './obs/obs-field.component';
|
|
5
|
+
import { PersonAttributeField } from './person-attributes/person-attribute-field.component';
|
|
6
|
+
import { type RegistrationConfig } from '../../config-schema';
|
|
7
|
+
|
|
8
|
+
export interface CustomFieldProps {
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function CustomField({ name }: CustomFieldProps) {
|
|
13
|
+
const config = useConfig<RegistrationConfig>();
|
|
14
|
+
const fieldDefinition = config.fieldDefinitions.filter((def) => def.id == name)[0];
|
|
15
|
+
|
|
16
|
+
if (fieldDefinition.type === 'person attribute') {
|
|
17
|
+
return <PersonAttributeField fieldDefinition={fieldDefinition} />;
|
|
18
|
+
} else if (fieldDefinition.type === 'obs') {
|
|
19
|
+
return <ObsField fieldDefinition={fieldDefinition} />;
|
|
20
|
+
} else if (fieldDefinition.type === 'address') {
|
|
21
|
+
return <AddressField fieldDefinition={fieldDefinition} />;
|
|
22
|
+
} else {
|
|
23
|
+
return <div>Error: Unknown field type {fieldDefinition.type}</div>;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/patient-registration/field/date-and-time-of-death/date-and-time-of-death.component.tsx
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import { Layer, SelectItem, TimePicker, TimePickerSelect } from '@carbon/react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { useField } from 'formik';
|
|
7
|
+
import { OpenmrsDatePicker } from '@openmrs/esm-framework';
|
|
8
|
+
import { usePatientRegistrationContext } from '../../patient-registration-context';
|
|
9
|
+
import type { FormValues } from '../../patient-registration.types';
|
|
10
|
+
import styles from '../field.scss';
|
|
11
|
+
|
|
12
|
+
export const DateAndTimeOfDeathField: React.FC = () => {
|
|
13
|
+
const { t } = useTranslation();
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div className={classNames(styles.dodField, styles.halfWidthInDesktopView)}>
|
|
17
|
+
<h4 className={styles.productiveHeading02Light}>{t('deathDateInputLabel', 'Date of Death')}</h4>
|
|
18
|
+
<span>
|
|
19
|
+
<DeathDateField />
|
|
20
|
+
<DeathTimeField />
|
|
21
|
+
</span>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function DeathDateField() {
|
|
27
|
+
const { values, setFieldValue } = usePatientRegistrationContext();
|
|
28
|
+
const [deathDate, deathDateMeta] = useField<keyof FormValues>('deathDate');
|
|
29
|
+
const { t } = useTranslation();
|
|
30
|
+
const today = dayjs().hour(23).minute(59).second(59).toDate();
|
|
31
|
+
const onDateChange = useCallback(
|
|
32
|
+
(selectedDate: Date) => {
|
|
33
|
+
setFieldValue(
|
|
34
|
+
'deathDate',
|
|
35
|
+
selectedDate ? dayjs(selectedDate).hour(0).minute(0).second(0).millisecond(0).toDate() : undefined,
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
[setFieldValue],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Layer>
|
|
43
|
+
<OpenmrsDatePicker
|
|
44
|
+
{...deathDate}
|
|
45
|
+
id="deathDate"
|
|
46
|
+
invalidText={t(deathDateMeta.error)}
|
|
47
|
+
invalid={!!(deathDateMeta.touched && deathDateMeta.error)}
|
|
48
|
+
isRequired={values.isDead}
|
|
49
|
+
labelText={t('deathDateInputLabel', 'Date of death')}
|
|
50
|
+
maxDate={today}
|
|
51
|
+
onChange={onDateChange}
|
|
52
|
+
/>
|
|
53
|
+
</Layer>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function DeathTimeField() {
|
|
58
|
+
const { t } = useTranslation();
|
|
59
|
+
const [deathTimeField, deathTimeMeta] = useField<keyof FormValues>('deathTime');
|
|
60
|
+
const [deathTimeFormatField, deathTimeFormatMeta] = useField<keyof FormValues>('deathTimeFormat');
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Layer>
|
|
64
|
+
<TimePicker
|
|
65
|
+
{...deathTimeField}
|
|
66
|
+
id="time-picker"
|
|
67
|
+
labelText={t('timeOfDeathInputLabel', 'Time of death (hh:mm)')}
|
|
68
|
+
className={styles.timeOfDeathField}
|
|
69
|
+
pattern="^(1[0-2]|0?[1-9]):([0-5]?[0-9])$"
|
|
70
|
+
invalid={!!(deathTimeMeta.touched && deathTimeMeta.error)}
|
|
71
|
+
invalidText={t(deathTimeMeta.error)}>
|
|
72
|
+
<TimePickerSelect {...deathTimeFormatField} id="time-format-picker" aria-label={t('timeFormat', 'Time Format')}>
|
|
73
|
+
<SelectItem value="AM" text="AM" />
|
|
74
|
+
<SelectItem value="PM" text="PM" />
|
|
75
|
+
</TimePickerSelect>
|
|
76
|
+
</TimePicker>
|
|
77
|
+
</Layer>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import React, { type ChangeEvent, useCallback } from 'react';
|
|
2
|
+
import { ContentSwitcher, Layer, Switch, TextInput } from '@carbon/react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { useField } from 'formik';
|
|
5
|
+
import { OpenmrsDatePicker, useConfig } from '@openmrs/esm-framework';
|
|
6
|
+
import { usePatientRegistrationContext } from '../../patient-registration-context';
|
|
7
|
+
import { type RegistrationConfig } from '../../../config-schema';
|
|
8
|
+
import styles from '../field.scss';
|
|
9
|
+
|
|
10
|
+
const calcBirthdate = (yearDelta, monthDelta, dateOfBirth) => {
|
|
11
|
+
const { enabled, month, dayOfMonth } = dateOfBirth.useEstimatedDateOfBirth;
|
|
12
|
+
const startDate = new Date();
|
|
13
|
+
const resultMonth = new Date(startDate.getFullYear() - yearDelta, startDate.getMonth() - monthDelta, 1);
|
|
14
|
+
const daysInResultMonth = new Date(resultMonth.getFullYear(), resultMonth.getMonth() + 1, 0).getDate();
|
|
15
|
+
const resultDate = new Date(
|
|
16
|
+
resultMonth.getFullYear(),
|
|
17
|
+
resultMonth.getMonth(),
|
|
18
|
+
Math.min(startDate.getDate(), daysInResultMonth),
|
|
19
|
+
);
|
|
20
|
+
return enabled ? new Date(resultDate.getFullYear(), month, dayOfMonth) : resultDate;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const DobField: React.FC = () => {
|
|
24
|
+
const { t } = useTranslation();
|
|
25
|
+
const {
|
|
26
|
+
fieldConfigurations: { dateOfBirth },
|
|
27
|
+
} = useConfig<RegistrationConfig>();
|
|
28
|
+
const allowEstimatedBirthDate = dateOfBirth?.allowEstimatedDateOfBirth;
|
|
29
|
+
const [{ value: dobUnknown }] = useField('birthdateEstimated');
|
|
30
|
+
const [birthdate, birthdateMeta] = useField('birthdate');
|
|
31
|
+
const [yearsEstimated, yearsEstimateMeta] = useField('yearsEstimated');
|
|
32
|
+
const [monthsEstimated, monthsEstimateMeta] = useField('monthsEstimated');
|
|
33
|
+
const { setFieldValue, setFieldTouched } = usePatientRegistrationContext();
|
|
34
|
+
const today = new Date();
|
|
35
|
+
|
|
36
|
+
const onToggle = useCallback(
|
|
37
|
+
(e: { name?: string | number }) => {
|
|
38
|
+
setFieldValue('birthdateEstimated', e.name === 'unknown');
|
|
39
|
+
setFieldValue('birthdate', '');
|
|
40
|
+
setFieldValue('yearsEstimated', 0);
|
|
41
|
+
setFieldValue('monthsEstimated', '');
|
|
42
|
+
setFieldTouched('birthdateEstimated', true, false);
|
|
43
|
+
},
|
|
44
|
+
[setFieldTouched, setFieldValue],
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const onDateChange = useCallback(
|
|
48
|
+
(birthdate: Date) => {
|
|
49
|
+
setFieldValue('birthdate', birthdate);
|
|
50
|
+
setFieldTouched('birthdate', true, false);
|
|
51
|
+
},
|
|
52
|
+
[setFieldValue, setFieldTouched],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const onEstimatedYearsChange = useCallback(
|
|
56
|
+
(ev: ChangeEvent<HTMLInputElement>) => {
|
|
57
|
+
const years = +ev.target.value;
|
|
58
|
+
|
|
59
|
+
if (!isNaN(years) && years < 140 && years >= 0) {
|
|
60
|
+
setFieldValue('yearsEstimated', years);
|
|
61
|
+
setFieldValue('birthdate', calcBirthdate(years, monthsEstimateMeta.value, dateOfBirth));
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
[setFieldValue, dateOfBirth, monthsEstimateMeta.value],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const onEstimatedMonthsChange = useCallback(
|
|
68
|
+
(ev: ChangeEvent<HTMLInputElement>) => {
|
|
69
|
+
const months = +ev.target.value;
|
|
70
|
+
|
|
71
|
+
if (!isNaN(months)) {
|
|
72
|
+
setFieldValue('monthsEstimated', months);
|
|
73
|
+
setFieldValue('birthdate', calcBirthdate(yearsEstimateMeta.value, months, dateOfBirth));
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
[setFieldValue, dateOfBirth, yearsEstimateMeta.value],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const updateBirthdate = useCallback(() => {
|
|
80
|
+
const months = +monthsEstimateMeta.value % 12;
|
|
81
|
+
const years = +yearsEstimateMeta.value + Math.floor(monthsEstimateMeta.value / 12);
|
|
82
|
+
setFieldValue('yearsEstimated', years);
|
|
83
|
+
setFieldValue('monthsEstimated', months > 0 ? months : '');
|
|
84
|
+
setFieldValue('birthdate', calcBirthdate(years, months, dateOfBirth));
|
|
85
|
+
setFieldTouched('yearsEstimated', true, false);
|
|
86
|
+
setFieldTouched('monthsEstimated', true, false);
|
|
87
|
+
setFieldTouched('birthdate', true, false);
|
|
88
|
+
}, [setFieldValue, setFieldTouched, monthsEstimateMeta, yearsEstimateMeta, dateOfBirth]);
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<div className={styles.halfWidthInDesktopView}>
|
|
92
|
+
<h4 className={styles.productiveHeading02Light}>{t('birthFieldLabelText', 'Birth')}</h4>
|
|
93
|
+
{(allowEstimatedBirthDate || dobUnknown) && (
|
|
94
|
+
<div className={styles.dobField}>
|
|
95
|
+
<div className={styles.dobContentSwitcherLabel}>
|
|
96
|
+
<span className={styles.label01}>{t('dobToggleLabelText', 'Date of birth known?')}</span>
|
|
97
|
+
</div>
|
|
98
|
+
<ContentSwitcher size="md" onChange={onToggle} selectedIndex={dobUnknown ? 1 : 0}>
|
|
99
|
+
<Switch name="known" text={t('yes', 'Yes')} />
|
|
100
|
+
<Switch name="unknown" text={t('no', 'No')} />
|
|
101
|
+
</ContentSwitcher>
|
|
102
|
+
</div>
|
|
103
|
+
)}
|
|
104
|
+
<Layer>
|
|
105
|
+
{!dobUnknown ? (
|
|
106
|
+
<div className={styles.dobField}>
|
|
107
|
+
<OpenmrsDatePicker
|
|
108
|
+
id="birthdate"
|
|
109
|
+
data-testid="birthdate"
|
|
110
|
+
{...birthdate}
|
|
111
|
+
onChange={onDateChange}
|
|
112
|
+
onBlur={() => setFieldTouched('birthdate', true, false)}
|
|
113
|
+
maxDate={today}
|
|
114
|
+
labelText={t('dateOfBirthLabelText', 'Date of birth')}
|
|
115
|
+
isInvalid={!!(birthdateMeta.touched && birthdateMeta.error)}
|
|
116
|
+
invalidText={t(birthdateMeta.error)}
|
|
117
|
+
value={birthdate.value}
|
|
118
|
+
/>
|
|
119
|
+
</div>
|
|
120
|
+
) : (
|
|
121
|
+
<div className={styles.grid}>
|
|
122
|
+
<div className={styles.dobField}>
|
|
123
|
+
<TextInput
|
|
124
|
+
id="yearsEstimated"
|
|
125
|
+
type="number"
|
|
126
|
+
name={yearsEstimated.name}
|
|
127
|
+
onChange={onEstimatedYearsChange}
|
|
128
|
+
labelText={t('estimatedAgeInYearsLabelText', 'Estimated age in years')}
|
|
129
|
+
invalid={!!(yearsEstimateMeta.touched && yearsEstimateMeta.error)}
|
|
130
|
+
invalidText={yearsEstimateMeta.error && t(yearsEstimateMeta.error)}
|
|
131
|
+
value={yearsEstimated.value}
|
|
132
|
+
min={0}
|
|
133
|
+
required
|
|
134
|
+
{...yearsEstimated}
|
|
135
|
+
onBlur={(e) => {
|
|
136
|
+
yearsEstimated.onBlur(e);
|
|
137
|
+
setFieldTouched('yearsEstimated', true, false);
|
|
138
|
+
updateBirthdate();
|
|
139
|
+
}}
|
|
140
|
+
/>
|
|
141
|
+
</div>
|
|
142
|
+
<div className={styles.dobField}>
|
|
143
|
+
<TextInput
|
|
144
|
+
id="monthsEstimated"
|
|
145
|
+
type="number"
|
|
146
|
+
name={monthsEstimated.name}
|
|
147
|
+
onChange={onEstimatedMonthsChange}
|
|
148
|
+
labelText={t('estimatedAgeInMonthsLabelText', 'Estimated age in months')}
|
|
149
|
+
invalid={!!(monthsEstimateMeta.touched && monthsEstimateMeta.error)}
|
|
150
|
+
invalidText={monthsEstimateMeta.error && t(monthsEstimateMeta.error)}
|
|
151
|
+
value={monthsEstimated.value}
|
|
152
|
+
min={0}
|
|
153
|
+
{...monthsEstimated}
|
|
154
|
+
required={!yearsEstimateMeta.value}
|
|
155
|
+
onBlur={(e) => {
|
|
156
|
+
monthsEstimated.onBlur(e);
|
|
157
|
+
setFieldTouched('monthsEstimated', true, false);
|
|
158
|
+
updateBirthdate();
|
|
159
|
+
}}
|
|
160
|
+
/>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
)}
|
|
164
|
+
</Layer>
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Formik, Form } from 'formik';
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
5
|
+
import { getDefaultsFromConfigSchema, useConfig } from '@openmrs/esm-framework';
|
|
6
|
+
import { type RegistrationConfig, esmPatientRegistrationSchema } from '../../../config-schema';
|
|
7
|
+
import { PatientRegistrationContextProvider } from '../../patient-registration-context';
|
|
8
|
+
import { initialFormValues } from '../../patient-registration.component';
|
|
9
|
+
import { DobField } from './dob.component';
|
|
10
|
+
|
|
11
|
+
const mockUseConfig = jest.mocked(useConfig<RegistrationConfig>);
|
|
12
|
+
|
|
13
|
+
describe('Dob', () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
mockUseConfig.mockReturnValue({
|
|
16
|
+
...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
|
|
17
|
+
fieldConfigurations: {
|
|
18
|
+
dateOfBirth: {
|
|
19
|
+
allowEstimatedDateOfBirth: true,
|
|
20
|
+
useEstimatedDateOfBirth: { enabled: true, dayOfMonth: 0, month: 0 },
|
|
21
|
+
},
|
|
22
|
+
} as RegistrationConfig['fieldConfigurations'],
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('renders the fields in the birth section of the registration form', async () => {
|
|
27
|
+
render(
|
|
28
|
+
<Formik initialValues={{ birthdate: '' }} onSubmit={() => {}}>
|
|
29
|
+
<Form>
|
|
30
|
+
<PatientRegistrationContextProvider
|
|
31
|
+
value={{
|
|
32
|
+
identifierTypes: [],
|
|
33
|
+
values: initialFormValues,
|
|
34
|
+
validationSchema: null,
|
|
35
|
+
inEditMode: false,
|
|
36
|
+
setFieldValue: () => {},
|
|
37
|
+
setCapturePhotoProps: (value) => {},
|
|
38
|
+
setFieldTouched: () => {},
|
|
39
|
+
currentPhoto: '',
|
|
40
|
+
isOffline: false,
|
|
41
|
+
initialFormValues: initialFormValues,
|
|
42
|
+
}}>
|
|
43
|
+
<DobField />
|
|
44
|
+
</PatientRegistrationContextProvider>
|
|
45
|
+
</Form>
|
|
46
|
+
</Formik>,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
expect(screen.getByRole('heading', { name: /birth/i })).toBeInTheDocument();
|
|
50
|
+
expect(screen.getByText(/date of birth known?/i)).toBeInTheDocument();
|
|
51
|
+
expect(screen.getByRole('tab', { name: /no/i })).toBeInTheDocument();
|
|
52
|
+
expect(screen.getByRole('tab', { name: /yes/i })).toBeInTheDocument();
|
|
53
|
+
expect(screen.getByRole('tab', { name: /yes/i })).toHaveAttribute('aria-selected', 'true');
|
|
54
|
+
expect(screen.getByRole('tab', { name: /no/i })).toHaveAttribute('aria-selected', 'false');
|
|
55
|
+
expect(screen.getByLabelText(/date of birth/i)).toBeInTheDocument();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('typing in the date picker input sets the date of birth', async () => {
|
|
59
|
+
const user = userEvent.setup();
|
|
60
|
+
|
|
61
|
+
render(
|
|
62
|
+
<Formik initialValues={{ birthdate: '' }} onSubmit={() => {}}>
|
|
63
|
+
<Form>
|
|
64
|
+
<PatientRegistrationContextProvider
|
|
65
|
+
value={{
|
|
66
|
+
identifierTypes: [],
|
|
67
|
+
values: initialFormValues,
|
|
68
|
+
validationSchema: null,
|
|
69
|
+
inEditMode: false,
|
|
70
|
+
setFieldValue: () => {},
|
|
71
|
+
setCapturePhotoProps: (value) => {},
|
|
72
|
+
currentPhoto: '',
|
|
73
|
+
isOffline: false,
|
|
74
|
+
initialFormValues: initialFormValues,
|
|
75
|
+
setFieldTouched: () => {},
|
|
76
|
+
}}>
|
|
77
|
+
<DobField />
|
|
78
|
+
</PatientRegistrationContextProvider>
|
|
79
|
+
</Form>
|
|
80
|
+
</Formik>,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const dateOfBirthInput = screen.getByLabelText(/date of birth/i);
|
|
84
|
+
expect(dateOfBirthInput).toBeInTheDocument();
|
|
85
|
+
await user.clear(dateOfBirthInput);
|
|
86
|
+
await user.type(dateOfBirthInput, '10/10/2022');
|
|
87
|
+
// FIXME: Make the date input work
|
|
88
|
+
// expect(dateOfBirthInput).toHaveValue('10/10/2022');
|
|
89
|
+
});
|
|
90
|
+
});
|