@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,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { DummyDataInput, dummyFormValues } from './dummy-data-input.component';
|
|
5
|
+
import { initialFormValues } from '../../patient-registration.component';
|
|
6
|
+
import { type FormValues } from '../../patient-registration.types';
|
|
7
|
+
|
|
8
|
+
describe('Dummy data input', () => {
|
|
9
|
+
let formValues: FormValues = initialFormValues;
|
|
10
|
+
|
|
11
|
+
const setupInput = async () => {
|
|
12
|
+
render(
|
|
13
|
+
<DummyDataInput
|
|
14
|
+
setValues={(values) => {
|
|
15
|
+
formValues = values;
|
|
16
|
+
}}
|
|
17
|
+
/>,
|
|
18
|
+
);
|
|
19
|
+
return screen.getByLabelText('Dummy Data Input') as HTMLButtonElement;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
it('exists', async () => {
|
|
23
|
+
const input = await setupInput();
|
|
24
|
+
expect(input.type).toEqual('button');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('can input data on button click', async () => {
|
|
28
|
+
const user = userEvent.setup();
|
|
29
|
+
const input = await setupInput();
|
|
30
|
+
|
|
31
|
+
await user.click(input);
|
|
32
|
+
expect(formValues).toEqual(dummyFormValues);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
@use '@carbon/layout';
|
|
2
|
+
@use '@carbon/type';
|
|
3
|
+
@use '@openmrs/esm-styleguide/src/vars' as *;
|
|
4
|
+
|
|
5
|
+
.fieldRow {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: row;
|
|
8
|
+
justify-content: flex-start;
|
|
9
|
+
flex-wrap: wrap;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.subFieldRow {
|
|
13
|
+
margin-bottom: 0.3125rem;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.label {
|
|
17
|
+
@include type.type-style('label-01');
|
|
18
|
+
color: $text-02;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.textID,
|
|
22
|
+
.comboInput {
|
|
23
|
+
margin-bottom: layout.$spacing-05;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.requiredField {
|
|
27
|
+
color: $danger;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.input {
|
|
31
|
+
margin-right: 0.3125rem;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.checkboxField {
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: row;
|
|
37
|
+
justify-content: flex-start;
|
|
38
|
+
width: 25rem;
|
|
39
|
+
margin-left: 0.625rem;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.textInput {
|
|
43
|
+
width: 250px !important;
|
|
44
|
+
height: 40px !important;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.numberInput {
|
|
48
|
+
width: 200px !important;
|
|
49
|
+
height: 40px !important;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.checkboxInput {
|
|
53
|
+
height: layout.$spacing-06 !important;
|
|
54
|
+
width: layout.$spacing-06 !important;
|
|
55
|
+
margin-top: layout.$spacing-03;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.selectInput {
|
|
59
|
+
width: 150px !important;
|
|
60
|
+
height: 40px !important;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.dateInput {
|
|
64
|
+
width: 200px !important;
|
|
65
|
+
height: 40px !important;
|
|
66
|
+
font-size: large !important;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.telInput {
|
|
70
|
+
width: 250px !important;
|
|
71
|
+
height: 40px !important;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.errorInput {
|
|
75
|
+
border: 2px solid $danger !important;
|
|
76
|
+
padding-left: 0.875rem !important;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.errorMessage {
|
|
80
|
+
color: $danger;
|
|
81
|
+
align-self: center;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.dummyData {
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
margin-left: 5px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.IDInput {
|
|
90
|
+
display: grid;
|
|
91
|
+
grid-template-columns: 1fr auto;
|
|
92
|
+
align-items: center;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.trashCan {
|
|
96
|
+
color: $danger;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
:global(.omrs-breakpoint-lt-desktop) {
|
|
100
|
+
.IDInput {
|
|
101
|
+
max-width: unset;
|
|
102
|
+
width: 100%;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.dangerLabel01 {
|
|
107
|
+
@include type.type-style('label-01');
|
|
108
|
+
color: $danger;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.comboInputEntries {
|
|
112
|
+
position: relative;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.comboInputItemOption {
|
|
116
|
+
margin: 0;
|
|
117
|
+
padding-left: layout.$spacing-05;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.actionButtonContainer {
|
|
121
|
+
margin-left: layout.$spacing-05;
|
|
122
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createContext, type SetStateAction, useContext } from 'react';
|
|
2
|
+
import { type PatientIdentifierType, useConfig } from '@openmrs/esm-framework';
|
|
3
|
+
import { type CapturePhotoProps, type FormValues } from './patient-registration.types';
|
|
4
|
+
import { type RegistrationConfig } from '../config-schema';
|
|
5
|
+
|
|
6
|
+
export interface PatientRegistrationContextProps {
|
|
7
|
+
currentPhoto: string;
|
|
8
|
+
identifierTypes: Array<PatientIdentifierType>;
|
|
9
|
+
inEditMode: boolean;
|
|
10
|
+
initialFormValues: FormValues;
|
|
11
|
+
isOffline: boolean;
|
|
12
|
+
setCapturePhotoProps(value: SetStateAction<CapturePhotoProps>): void;
|
|
13
|
+
setFieldTouched(field: string, isTouched?: any, shouldValidate?: boolean): void;
|
|
14
|
+
setFieldValue(field: string, value: any, shouldValidate?: boolean): void;
|
|
15
|
+
setInitialFormValues?: React.Dispatch<SetStateAction<FormValues>>;
|
|
16
|
+
validationSchema: any;
|
|
17
|
+
values: FormValues;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const PatientRegistrationContext = createContext<PatientRegistrationContextProps | undefined>(undefined);
|
|
21
|
+
|
|
22
|
+
export const PatientRegistrationContextProvider = PatientRegistrationContext.Provider;
|
|
23
|
+
|
|
24
|
+
export const usePatientRegistrationContext = () => {
|
|
25
|
+
const context = useContext(PatientRegistrationContext);
|
|
26
|
+
if (!context) {
|
|
27
|
+
throw new Error('usePatientRegistrationContext must be used within a PatientRegistrationContextProvider');
|
|
28
|
+
}
|
|
29
|
+
return context;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function useFieldConfig(field: string) {
|
|
33
|
+
const { fieldConfigurations } = useConfig<RegistrationConfig>();
|
|
34
|
+
return fieldConfigurations[field];
|
|
35
|
+
}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { type Dispatch, useEffect, useMemo, useState, useRef } from 'react';
|
|
2
|
+
import { camelCase } from 'lodash-es';
|
|
3
|
+
import { v4 } from 'uuid';
|
|
4
|
+
import dayjs from 'dayjs';
|
|
5
|
+
import useSWR from 'swr';
|
|
6
|
+
import {
|
|
7
|
+
type FetchResponse,
|
|
8
|
+
type OpenmrsResource,
|
|
9
|
+
getSynchronizationItems,
|
|
10
|
+
openmrsFetch,
|
|
11
|
+
restBaseUrl,
|
|
12
|
+
useConfig,
|
|
13
|
+
} from '@openmrs/esm-framework';
|
|
14
|
+
import { type RegistrationConfig } from '../config-schema';
|
|
15
|
+
import { patientRegistration } from '../constants';
|
|
16
|
+
import { useInitialPatientRelationships } from './section/patient-relationships/relationships.resource';
|
|
17
|
+
import {
|
|
18
|
+
type Encounter,
|
|
19
|
+
type FormValues,
|
|
20
|
+
type PatientIdentifierResponse,
|
|
21
|
+
type PatientRegistration,
|
|
22
|
+
type PatientUuidMapType,
|
|
23
|
+
type PersonAttributeResponse,
|
|
24
|
+
} from './patient-registration.types';
|
|
25
|
+
import {
|
|
26
|
+
getAddressFieldValuesFromFhirPatient,
|
|
27
|
+
getFormValuesFromFhirPatient,
|
|
28
|
+
getPatientUuidMapFromFhirPatient,
|
|
29
|
+
getPhonePersonAttributeValueFromFhirPatient,
|
|
30
|
+
latestFirstEncounter,
|
|
31
|
+
} from './patient-registration-utils';
|
|
32
|
+
|
|
33
|
+
interface AddressFieldValues {
|
|
34
|
+
address?: {
|
|
35
|
+
cityVillage?: string;
|
|
36
|
+
country?: string;
|
|
37
|
+
countyDistrict?: string;
|
|
38
|
+
postalCode?: string;
|
|
39
|
+
stateProvince?: string;
|
|
40
|
+
[key: string]: string | undefined;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface DeathInfoResults {
|
|
45
|
+
causeOfDeath: OpenmrsResource | null;
|
|
46
|
+
causeOfDeathNonCoded: string | null;
|
|
47
|
+
dead: boolean;
|
|
48
|
+
deathDate: string;
|
|
49
|
+
display: string;
|
|
50
|
+
uuid: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function useInitialFormValues(
|
|
54
|
+
isLoadingPatientToEdit: boolean,
|
|
55
|
+
patientToEdit: fhir.Patient,
|
|
56
|
+
patientUuid: string,
|
|
57
|
+
): [FormValues, Dispatch<FormValues>] {
|
|
58
|
+
const { freeTextFieldConceptUuid } = useConfig<RegistrationConfig>();
|
|
59
|
+
const { data: deathInfo, isLoading: isLoadingDeathInfo } = useInitialPersonDeathInfo(patientUuid);
|
|
60
|
+
const { data: attributes, isLoading: isLoadingAttributes } = useInitialPersonAttributes(patientUuid);
|
|
61
|
+
const { data: identifiers, isLoading: isLoadingIdentifiers } = useInitialPatientIdentifiers(patientUuid);
|
|
62
|
+
const { data: relationships, isLoading: isLoadingRelationships } = useInitialPatientRelationships(patientUuid);
|
|
63
|
+
const { data: encounters } = useInitialEncounters(patientUuid, patientToEdit);
|
|
64
|
+
|
|
65
|
+
const [initialFormValues, setInitialFormValues] = useState<FormValues>({
|
|
66
|
+
additionalFamilyName: '',
|
|
67
|
+
additionalGivenName: '',
|
|
68
|
+
additionalMiddleName: '',
|
|
69
|
+
addNameInLocalLanguage: false,
|
|
70
|
+
address: {},
|
|
71
|
+
birthdate: null,
|
|
72
|
+
birthdateEstimated: false,
|
|
73
|
+
deathCause: '',
|
|
74
|
+
deathDate: undefined,
|
|
75
|
+
deathTime: undefined,
|
|
76
|
+
deathTimeFormat: 'AM',
|
|
77
|
+
familyName: '',
|
|
78
|
+
gender: '',
|
|
79
|
+
givenName: '',
|
|
80
|
+
identifiers: {},
|
|
81
|
+
isDead: false,
|
|
82
|
+
middleName: '',
|
|
83
|
+
monthsEstimated: 0,
|
|
84
|
+
nonCodedCauseOfDeath: '',
|
|
85
|
+
patientUuid: v4(),
|
|
86
|
+
relationships: [],
|
|
87
|
+
telephoneNumber: '',
|
|
88
|
+
yearsEstimated: 0,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
(async () => {
|
|
93
|
+
if (patientToEdit) {
|
|
94
|
+
const birthdateEstimated = !/^\d{4}-\d{2}-\d{2}$/.test(patientToEdit.birthDate);
|
|
95
|
+
const [years = 0, months = 0] = patientToEdit.birthDate.split('-').map((val) => parseInt(val));
|
|
96
|
+
const estimatedMonthsAvailable = patientToEdit.birthDate.split('-').length > 1;
|
|
97
|
+
const yearsEstimated = birthdateEstimated ? Math.floor(dayjs().diff(patientToEdit.birthDate, 'month') / 12) : 0;
|
|
98
|
+
const monthsEstimated =
|
|
99
|
+
birthdateEstimated && estimatedMonthsAvailable ? dayjs().diff(patientToEdit.birthDate, 'month') % 12 : 0;
|
|
100
|
+
|
|
101
|
+
setInitialFormValues((currentValues) => ({
|
|
102
|
+
...currentValues,
|
|
103
|
+
...getFormValuesFromFhirPatient(patientToEdit),
|
|
104
|
+
address: getAddressFieldValuesFromFhirPatient(patientToEdit),
|
|
105
|
+
...getPhonePersonAttributeValueFromFhirPatient(patientToEdit),
|
|
106
|
+
birthdateEstimated: !/^\d{4}-\d{2}-\d{2}$/.test(patientToEdit.birthDate),
|
|
107
|
+
yearsEstimated,
|
|
108
|
+
monthsEstimated,
|
|
109
|
+
}));
|
|
110
|
+
} else if (!isLoadingPatientToEdit && patientUuid) {
|
|
111
|
+
const registration = await getPatientRegistration(patientUuid);
|
|
112
|
+
|
|
113
|
+
if (!registration._patientRegistrationData.formValues) {
|
|
114
|
+
console.error(
|
|
115
|
+
`Found a queued offline patient registration for patient ${patientUuid}, but without form values. Not using these values.`,
|
|
116
|
+
);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
setInitialFormValues(registration._patientRegistrationData.formValues);
|
|
121
|
+
}
|
|
122
|
+
})();
|
|
123
|
+
}, [isLoadingPatientToEdit, patientToEdit, patientUuid]);
|
|
124
|
+
|
|
125
|
+
// Set initial patient death info
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (!isLoadingDeathInfo && deathInfo?.dead) {
|
|
128
|
+
const deathDatetime = deathInfo.deathDate || null;
|
|
129
|
+
const deathDate = deathDatetime ? new Date(deathDatetime) : undefined;
|
|
130
|
+
const time = deathDate ? dayjs(deathDate).format('hh:mm') : undefined;
|
|
131
|
+
const timeFormat = deathDate ? (dayjs(deathDate).hour() >= 12 ? 'PM' : 'AM') : 'AM';
|
|
132
|
+
setInitialFormValues((initialFormValues) => ({
|
|
133
|
+
...initialFormValues,
|
|
134
|
+
isDead: deathInfo.dead || false,
|
|
135
|
+
deathDate: deathDate,
|
|
136
|
+
deathTime: time,
|
|
137
|
+
deathTimeFormat: timeFormat,
|
|
138
|
+
deathCause: deathInfo.causeOfDeathNonCoded ? freeTextFieldConceptUuid : deathInfo.causeOfDeath?.uuid,
|
|
139
|
+
nonCodedCauseOfDeath: deathInfo.causeOfDeathNonCoded,
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
}, [isLoadingDeathInfo, deathInfo, freeTextFieldConceptUuid]);
|
|
143
|
+
|
|
144
|
+
// Combined effect for relationships and identifiers
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (!isLoadingRelationships && relationships) {
|
|
147
|
+
setInitialFormValues((initialFormValues) => ({
|
|
148
|
+
...initialFormValues,
|
|
149
|
+
relationships,
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!isLoadingIdentifiers && identifiers) {
|
|
154
|
+
setInitialFormValues((initialFormValues) => ({
|
|
155
|
+
...initialFormValues,
|
|
156
|
+
identifiers,
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
}, [isLoadingRelationships, relationships, isLoadingIdentifiers, identifiers]);
|
|
160
|
+
|
|
161
|
+
// Set Initial person attributes
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (!isLoadingAttributes && attributes) {
|
|
164
|
+
const personAttributes = attributes.reduce(
|
|
165
|
+
(acc, attribute) => ({
|
|
166
|
+
...acc,
|
|
167
|
+
[attribute.attributeType.uuid]:
|
|
168
|
+
attribute.attributeType.format === 'org.openmrs.Concept' && typeof attribute.value === 'object'
|
|
169
|
+
? attribute.value?.uuid
|
|
170
|
+
: attribute.value,
|
|
171
|
+
}),
|
|
172
|
+
{},
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
setInitialFormValues((initialFormValues) => ({
|
|
176
|
+
...initialFormValues,
|
|
177
|
+
attributes: personAttributes,
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
}, [attributes, isLoadingAttributes]);
|
|
181
|
+
|
|
182
|
+
// Set Initial registration encounters
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
if (patientToEdit && encounters) {
|
|
185
|
+
setInitialFormValues((initialFormValues) => ({
|
|
186
|
+
...initialFormValues,
|
|
187
|
+
obs: encounters as Record<string, string>,
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
}, [encounters, patientToEdit]);
|
|
191
|
+
|
|
192
|
+
return [initialFormValues, setInitialFormValues];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function useInitialAddressFieldValues(
|
|
196
|
+
fallback: AddressFieldValues = {},
|
|
197
|
+
isLoadingPatientToEdit: boolean,
|
|
198
|
+
patientToEdit: fhir.Patient,
|
|
199
|
+
patientUuid: string,
|
|
200
|
+
): [AddressFieldValues, Dispatch<AddressFieldValues>] {
|
|
201
|
+
const fallbackRef = useRef(fallback);
|
|
202
|
+
const [initialAddressFieldValues, setInitialAddressFieldValues] = useState<AddressFieldValues>(fallbackRef.current);
|
|
203
|
+
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
(async () => {
|
|
206
|
+
if (patientToEdit) {
|
|
207
|
+
setInitialAddressFieldValues((currentValues) => ({
|
|
208
|
+
...currentValues,
|
|
209
|
+
address: getAddressFieldValuesFromFhirPatient(patientToEdit),
|
|
210
|
+
}));
|
|
211
|
+
} else if (!isLoadingPatientToEdit && patientUuid) {
|
|
212
|
+
const registration = await getPatientRegistration(patientUuid);
|
|
213
|
+
setInitialAddressFieldValues(
|
|
214
|
+
registration?._patientRegistrationData.initialAddressFieldValues ?? fallbackRef.current,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
})();
|
|
218
|
+
}, [isLoadingPatientToEdit, patientToEdit, patientUuid]);
|
|
219
|
+
|
|
220
|
+
return [initialAddressFieldValues, setInitialAddressFieldValues];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function usePatientUuidMap(
|
|
224
|
+
fallback: PatientUuidMapType = {},
|
|
225
|
+
isLoadingPatientToEdit: boolean,
|
|
226
|
+
patientToEdit: fhir.Patient,
|
|
227
|
+
patientUuid: string,
|
|
228
|
+
): [PatientUuidMapType, Dispatch<PatientUuidMapType>] {
|
|
229
|
+
const fallbackRef = useRef(fallback);
|
|
230
|
+
const [patientUuidMap, setPatientUuidMap] = useState(fallbackRef.current);
|
|
231
|
+
const { data: attributes } = useInitialPersonAttributes(patientUuid);
|
|
232
|
+
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
const abortController = new AbortController();
|
|
235
|
+
|
|
236
|
+
async function updatePatientMap() {
|
|
237
|
+
if (patientToEdit) {
|
|
238
|
+
setPatientUuidMap((prevMap) => ({
|
|
239
|
+
...prevMap,
|
|
240
|
+
...getPatientUuidMapFromFhirPatient(patientToEdit),
|
|
241
|
+
}));
|
|
242
|
+
} else if (!isLoadingPatientToEdit && patientUuid) {
|
|
243
|
+
try {
|
|
244
|
+
const registration = await getPatientRegistration(patientUuid);
|
|
245
|
+
if (!abortController.signal.aborted) {
|
|
246
|
+
setPatientUuidMap(registration?._patientRegistrationData.initialAddressFieldValues ?? fallbackRef.current);
|
|
247
|
+
}
|
|
248
|
+
} catch (error) {
|
|
249
|
+
if (!abortController.signal.aborted) {
|
|
250
|
+
console.error('Failed to get patient registration:', error);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
updatePatientMap();
|
|
257
|
+
return () => abortController.abort();
|
|
258
|
+
}, [isLoadingPatientToEdit, patientToEdit, patientUuid]);
|
|
259
|
+
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
if (attributes) {
|
|
262
|
+
setPatientUuidMap((prevMap) => ({
|
|
263
|
+
...prevMap,
|
|
264
|
+
...getPatientAttributeUuidMapForPatient(attributes),
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
267
|
+
}, [attributes]);
|
|
268
|
+
|
|
269
|
+
return [patientUuidMap, setPatientUuidMap];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function getPatientRegistration(patientUuid: string) {
|
|
273
|
+
const items = await getSynchronizationItems<PatientRegistration>(patientRegistration);
|
|
274
|
+
return items.find((item) => item._patientRegistrationData.formValues.patientUuid === patientUuid);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function useInitialPatientIdentifiers(patientUuid: string): {
|
|
278
|
+
data: FormValues['identifiers'];
|
|
279
|
+
isLoading: boolean;
|
|
280
|
+
} {
|
|
281
|
+
const shouldFetch = !!patientUuid;
|
|
282
|
+
|
|
283
|
+
const { data, error, isLoading } = useSWR<FetchResponse<{ results: Array<PatientIdentifierResponse> }>, Error>(
|
|
284
|
+
shouldFetch
|
|
285
|
+
? `${restBaseUrl}/patient/${patientUuid}/identifier?v=custom:(uuid,identifier,identifierType:(uuid,required,name),preferred)`
|
|
286
|
+
: null,
|
|
287
|
+
openmrsFetch,
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const result: {
|
|
291
|
+
data: FormValues['identifiers'];
|
|
292
|
+
isLoading: boolean;
|
|
293
|
+
} = useMemo(() => {
|
|
294
|
+
const identifiers: FormValues['identifiers'] = {};
|
|
295
|
+
|
|
296
|
+
data?.data?.results?.forEach((patientIdentifier) => {
|
|
297
|
+
identifiers[camelCase(patientIdentifier.identifierType.name)] = {
|
|
298
|
+
identifierUuid: patientIdentifier.uuid,
|
|
299
|
+
preferred: patientIdentifier.preferred,
|
|
300
|
+
initialValue: patientIdentifier.identifier,
|
|
301
|
+
identifierValue: patientIdentifier.identifier,
|
|
302
|
+
identifierTypeUuid: patientIdentifier.identifierType.uuid,
|
|
303
|
+
identifierName: patientIdentifier.identifierType.name,
|
|
304
|
+
required: patientIdentifier.identifierType.required,
|
|
305
|
+
selectedSource: null,
|
|
306
|
+
autoGeneration: false,
|
|
307
|
+
};
|
|
308
|
+
});
|
|
309
|
+
return {
|
|
310
|
+
data: identifiers,
|
|
311
|
+
isLoading,
|
|
312
|
+
};
|
|
313
|
+
}, [data?.data?.results, isLoading]);
|
|
314
|
+
|
|
315
|
+
return result;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function useInitialEncounters(patientUuid: string, patientToEdit: fhir.Patient) {
|
|
319
|
+
const { registrationObs } = useConfig<RegistrationConfig>();
|
|
320
|
+
const { data, error, isLoading } = useSWR<FetchResponse<{ results: Array<Encounter> }>>(
|
|
321
|
+
patientToEdit && registrationObs.encounterTypeUuid
|
|
322
|
+
? `${restBaseUrl}/encounter?patient=${patientUuid}&v=custom:(encounterDatetime,obs:(concept:ref,value:ref))&encounterType=${registrationObs.encounterTypeUuid}`
|
|
323
|
+
: null,
|
|
324
|
+
openmrsFetch,
|
|
325
|
+
);
|
|
326
|
+
const obs = data?.data.results.sort(latestFirstEncounter)?.at(0)?.obs;
|
|
327
|
+
const encounters = obs
|
|
328
|
+
?.map(({ concept, value }) => ({
|
|
329
|
+
[(concept as OpenmrsResource).uuid]: typeof value === 'object' ? value?.uuid : value,
|
|
330
|
+
}))
|
|
331
|
+
.reduce((accu, curr) => Object.assign(accu, curr), {});
|
|
332
|
+
|
|
333
|
+
return { data: encounters, isLoading, error };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function useInitialPersonAttributes(personUuid: string) {
|
|
337
|
+
const shouldFetch = !!personUuid;
|
|
338
|
+
const { data, error, isLoading } = useSWR<FetchResponse<{ results: Array<PersonAttributeResponse> }>, Error>(
|
|
339
|
+
shouldFetch
|
|
340
|
+
? `${restBaseUrl}/person/${personUuid}/attribute?v=custom:(uuid,display,attributeType:(uuid,display,format),value)`
|
|
341
|
+
: null,
|
|
342
|
+
openmrsFetch,
|
|
343
|
+
);
|
|
344
|
+
const result = useMemo(() => {
|
|
345
|
+
return {
|
|
346
|
+
data: data?.data?.results,
|
|
347
|
+
isLoading,
|
|
348
|
+
};
|
|
349
|
+
}, [data?.data?.results, isLoading]);
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function useInitialPersonDeathInfo(personUuid: string) {
|
|
354
|
+
const { data, error, isLoading } = useSWR<FetchResponse<DeathInfoResults>, Error>(
|
|
355
|
+
!!personUuid
|
|
356
|
+
? `${restBaseUrl}/person/${personUuid}?v=custom:(uuid,display,causeOfDeath,dead,deathDate,causeOfDeathNonCoded)`
|
|
357
|
+
: null,
|
|
358
|
+
openmrsFetch,
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
const result = useMemo(() => {
|
|
362
|
+
return {
|
|
363
|
+
data: data?.data,
|
|
364
|
+
isLoading,
|
|
365
|
+
};
|
|
366
|
+
}, [data?.data, isLoading]);
|
|
367
|
+
return result;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function getPatientAttributeUuidMapForPatient(attributes: Array<PersonAttributeResponse>) {
|
|
371
|
+
const attributeUuidMap = {};
|
|
372
|
+
attributes.forEach((attribute) => {
|
|
373
|
+
attributeUuidMap[`attribute.${attribute?.attributeType?.uuid}`] = attribute?.uuid;
|
|
374
|
+
});
|
|
375
|
+
return attributeUuidMap;
|
|
376
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { filterOutUndefinedPatientIdentifiers } from './patient-registration-utils';
|
|
2
|
+
|
|
3
|
+
describe('filterOutUndefinedPatientIdentifiers', () => {
|
|
4
|
+
const getIdentifiers = (autoGeneration = true, manualEntryEnabled = false) => ({
|
|
5
|
+
OpenMRSId: {
|
|
6
|
+
autoGeneration: autoGeneration,
|
|
7
|
+
identifierName: 'OpenMRS ID',
|
|
8
|
+
identifierTypeUuid: '05a29f94-c0ed-11e2-94be-8c13b969e334',
|
|
9
|
+
identifierValue: undefined,
|
|
10
|
+
initialValue: '100GEJ',
|
|
11
|
+
preferred: true,
|
|
12
|
+
required: true,
|
|
13
|
+
selectedSource: {
|
|
14
|
+
uuid: '01af8526-cea4-4175-aa90-340acb411771',
|
|
15
|
+
name: 'Generator for OpenMRS ID',
|
|
16
|
+
autoGenerationOption: {
|
|
17
|
+
manualEntryEnabled: manualEntryEnabled,
|
|
18
|
+
automaticGenerationEnabled: autoGeneration,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should fitler out undefined identifiers', () => {
|
|
25
|
+
const filteredIdentifiers = filterOutUndefinedPatientIdentifiers(getIdentifiers());
|
|
26
|
+
expect(filteredIdentifiers.OpenMRSId).not.toBeDefined();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should retain auto-generated identifiers with manual entry', () => {
|
|
30
|
+
const filteredIdentifiers = filterOutUndefinedPatientIdentifiers(getIdentifiers(true, true));
|
|
31
|
+
expect(filteredIdentifiers.OpenMRSId).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
});
|