@kenyaemr/esm-patient-registration-app 4.3.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/README.md +7 -0
- package/__mocks__/autogenerationoptions.mock.ts +34 -0
- package/__mocks__/react-i18next.js +49 -0
- package/dist/144.js +2 -0
- package/dist/144.js.LICENSE.txt +27 -0
- package/dist/144.js.map +1 -0
- package/dist/207.js +1 -0
- package/dist/207.js.map +1 -0
- package/dist/317.js +2 -0
- package/dist/317.js.LICENSE.txt +6 -0
- package/dist/317.js.map +1 -0
- package/dist/330.js +1 -0
- package/dist/330.js.map +1 -0
- package/dist/574.js +1 -0
- package/dist/59.js +1 -0
- package/dist/59.js.map +1 -0
- package/dist/591.js +2 -0
- package/dist/591.js.LICENSE.txt +32 -0
- package/dist/591.js.map +1 -0
- package/dist/62.js +1 -0
- package/dist/62.js.map +1 -0
- package/dist/635.js +1 -0
- package/dist/635.js.map +1 -0
- package/dist/68.js +1 -0
- package/dist/68.js.map +1 -0
- package/dist/735.js +1 -0
- package/dist/735.js.map +1 -0
- package/dist/757.js +1 -0
- package/dist/784.js +2 -0
- package/dist/784.js.LICENSE.txt +9 -0
- package/dist/784.js.map +1 -0
- package/dist/805.js +1 -0
- package/dist/805.js.map +1 -0
- package/dist/807.js +1 -0
- package/dist/821.js +1 -0
- package/dist/821.js.map +1 -0
- package/dist/822.js +1 -0
- package/dist/822.js.map +1 -0
- package/dist/858.js +2 -0
- package/dist/858.js.LICENSE.txt +3 -0
- package/dist/858.js.map +1 -0
- package/dist/887.js +1 -0
- package/dist/887.js.map +1 -0
- package/dist/9.js +2 -0
- package/dist/9.js.LICENSE.txt +9 -0
- package/dist/9.js.map +1 -0
- package/dist/975.js +1 -0
- package/dist/975.js.map +1 -0
- package/dist/main.js +2 -0
- package/dist/main.js.LICENSE.txt +9 -0
- package/dist/main.js.map +1 -0
- package/dist/openmrs-esm-patient-registration-app.js +1 -0
- package/dist/openmrs-esm-patient-registration-app.js.buildmanifest.json +623 -0
- package/dist/openmrs-esm-patient-registration-app.js.map +1 -0
- package/dist/openmrs-esm-patient-registration-app.old +1 -0
- package/docs/images/patient-registration-hierarchy.png +0 -0
- package/package.json +55 -0
- package/src/add-patient-link.scss +3 -0
- package/src/add-patient-link.tsx +21 -0
- package/src/config-schema.ts +405 -0
- package/src/constants.ts +14 -0
- package/src/declarations.d.tsx +4 -0
- package/src/index.ts +131 -0
- package/src/nav-link.tsx +10 -0
- package/src/offline.resources.ts +109 -0
- package/src/offline.ts +90 -0
- package/src/patient-registration/before-save-prompt.tsx +72 -0
- package/src/patient-registration/date-util.ts +52 -0
- package/src/patient-registration/field/__mocks__/field.resource.ts +60 -0
- package/src/patient-registration/field/address/address-field.component.tsx +31 -0
- package/src/patient-registration/field/address/address-hierarchy.component.tsx +143 -0
- package/src/patient-registration/field/address/address-hierarchy.test.tsx +181 -0
- package/src/patient-registration/field/address/address-search.component.tsx +98 -0
- package/src/patient-registration/field/address/address-search.scss +53 -0
- package/src/patient-registration/field/custom-field.component.tsx +25 -0
- package/src/patient-registration/field/dob/dob.component.tsx +143 -0
- package/src/patient-registration/field/dob/dob.test.tsx +73 -0
- package/src/patient-registration/field/field.component.tsx +44 -0
- package/src/patient-registration/field/field.resource.ts +35 -0
- package/src/patient-registration/field/field.scss +127 -0
- package/src/patient-registration/field/gender/gender-field.component.tsx +49 -0
- package/src/patient-registration/field/gender/gender-field.test.tsx +66 -0
- package/src/patient-registration/field/id/id-field.component.tsx +142 -0
- package/src/patient-registration/field/id/identifier-selection-overlay.tsx +194 -0
- package/src/patient-registration/field/id/identifier-selection.scss +37 -0
- package/src/patient-registration/field/name/name-field.component.tsx +109 -0
- package/src/patient-registration/field/obs/obs-field.component.tsx +185 -0
- package/src/patient-registration/field/obs/obs-field.test.tsx +127 -0
- package/src/patient-registration/field/person-attributes/coded-attributes.component.tsx +59 -0
- package/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx +68 -0
- package/src/patient-registration/field/person-attributes/person-attribute-field.component.tsx +81 -0
- package/src/patient-registration/field/person-attributes/person-attributes.resource.tsx +20 -0
- package/src/patient-registration/field/person-attributes/text-person-attribute-field.component.tsx +57 -0
- package/src/patient-registration/form-manager.test.ts +68 -0
- package/src/patient-registration/form-manager.ts +413 -0
- package/src/patient-registration/input/basic-input/input/input.component.tsx +59 -0
- package/src/patient-registration/input/basic-input/input/input.test.tsx +170 -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 +32 -0
- package/src/patient-registration/input/combo-input/combo-input.component.tsx +76 -0
- package/src/patient-registration/input/combo-input/combo-input.test.tsx +43 -0
- package/src/patient-registration/input/custom-input/autosuggest/autosuggest.component.tsx +84 -0
- package/src/patient-registration/input/custom-input/autosuggest/autosuggest.scss +53 -0
- package/src/patient-registration/input/custom-input/autosuggest/autosuggest.test.tsx +109 -0
- package/src/patient-registration/input/custom-input/estimated-age/estimated-age-input.component.tsx +32 -0
- package/src/patient-registration/input/custom-input/estimated-age/estimated-age-input.test.tsx +36 -0
- package/src/patient-registration/input/custom-input/identifier/identifier-input.component.tsx +156 -0
- package/src/patient-registration/input/custom-input/identifier/identifier-input.test.tsx +110 -0
- package/src/patient-registration/input/custom-input/identifier/utils.ts +19 -0
- package/src/patient-registration/input/custom-input/unidentified-patient/unidentified-patient-input.component.tsx +24 -0
- package/src/patient-registration/input/custom-input/unidentified-patient/unidentified-patient-input.test.tsx +39 -0
- package/src/patient-registration/input/dummy-data/dummy-data-input.component.tsx +53 -0
- package/src/patient-registration/input/dummy-data/dummy-data-input.test.tsx +43 -0
- package/src/patient-registration/input/input.scss +108 -0
- package/src/patient-registration/patient-registration-context.ts +24 -0
- package/src/patient-registration/patient-registration-hooks.ts +320 -0
- package/src/patient-registration/patient-registration-types.tsx +271 -0
- package/src/patient-registration/patient-registration-utils.ts +219 -0
- package/src/patient-registration/patient-registration.component.tsx +250 -0
- package/src/patient-registration/patient-registration.resource.test.tsx +26 -0
- package/src/patient-registration/patient-registration.resource.tsx +296 -0
- package/src/patient-registration/patient-registration.scss +94 -0
- package/src/patient-registration/patient-registration.test.tsx +436 -0
- package/src/patient-registration/section/death-info/death-info-section.component.tsx +30 -0
- package/src/patient-registration/section/death-info/death-info-section.test.tsx +73 -0
- package/src/patient-registration/section/demographics/demographics-section.component.tsx +30 -0
- package/src/patient-registration/section/demographics/demographics-section.test.tsx +84 -0
- package/src/patient-registration/section/generic-section.component.tsx +17 -0
- package/src/patient-registration/section/patient-relationships/relationships-section.component.tsx +226 -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 +1 -0
- package/src/patient-registration/ui-components/overlay/index.tsx +51 -0
- package/src/patient-registration/ui-components/overlay/overlay.scss +63 -0
- package/src/patient-registration/validation/patient-registration-validation.test.tsx +129 -0
- package/src/patient-registration/validation/patient-registration-validation.tsx +46 -0
- package/src/patient-verification/assets/counties.json +236 -0
- package/src/patient-verification/assets/verification-assets.ts +11 -0
- package/src/patient-verification/patient-verification-hook.tsx +156 -0
- package/src/patient-verification/patient-verification-utils.ts +173 -0
- package/src/patient-verification/patient-verification.component.tsx +118 -0
- package/src/patient-verification/patient-verification.scss +30 -0
- package/src/patient-verification/verification-modal/confirm-prompt.component.tsx +69 -0
- package/src/patient-verification/verification-modal/empty-prompt.component.tsx +35 -0
- package/src/patient-verification/verification-types.ts +50 -0
- package/src/resource.ts +12 -0
- package/src/root.component.tsx +66 -0
- package/src/root.scss +7 -0
- package/src/root.test.tsx +32 -0
- package/src/widgets/cancel-patient-edit.component.tsx +37 -0
- package/src/widgets/delete-identifier-confirmation-modal.tsx +41 -0
- package/src/widgets/delete-identifier-modal.scss +34 -0
- package/src/widgets/display-photo.component.tsx +30 -0
- package/src/widgets/edit-patient-details-button.component.tsx +34 -0
- package/src/widgets/edit-patient-details-button.scss +3 -0
- package/translations/en.json +108 -0
- package/translations/fr.json +89 -0
- package/translations/km.json +89 -0
- package/tsconfig.json +5 -0
- package/webpack.config.js +1 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { FetchResponse, getSynchronizationItems, openmrsFetch, useConfig, usePatient } from '@openmrs/esm-framework';
|
|
2
|
+
import last from 'lodash-es/last';
|
|
3
|
+
import camelCase from 'lodash-es/camelCase';
|
|
4
|
+
import { Dispatch, useEffect, useMemo, useState } from 'react';
|
|
5
|
+
import useSWR from 'swr';
|
|
6
|
+
import { v4 } from 'uuid';
|
|
7
|
+
import { RegistrationConfig } from '../config-schema';
|
|
8
|
+
import { patientRegistration } from '../constants';
|
|
9
|
+
import { useConceptAnswers, useGlobalProperties } from '../patient-verification/patient-verification-hook';
|
|
10
|
+
import {
|
|
11
|
+
FormValues,
|
|
12
|
+
PatientRegistration,
|
|
13
|
+
PatientUuidMapType,
|
|
14
|
+
PersonAttributeResponse,
|
|
15
|
+
PatientIdentifierResponse,
|
|
16
|
+
ObsResponse,
|
|
17
|
+
ConceptAnswers,
|
|
18
|
+
Encounter,
|
|
19
|
+
} from './patient-registration-types';
|
|
20
|
+
import {
|
|
21
|
+
getAddressFieldValuesFromFhirPatient,
|
|
22
|
+
getFormValuesFromFhirPatient,
|
|
23
|
+
getPatientUuidMapFromFhirPatient,
|
|
24
|
+
getPhonePersonAttributeValueFromFhirPatient,
|
|
25
|
+
latestFirstEncounter,
|
|
26
|
+
} from './patient-registration-utils';
|
|
27
|
+
import { useInitialPatientRelationships } from './section/patient-relationships/relationships.resource';
|
|
28
|
+
|
|
29
|
+
export function useInitialFormValues(patientUuid: string): [FormValues, Dispatch<FormValues>] {
|
|
30
|
+
const { martialStatus, education, occupation, educationLoad, loadingStatus } = useConcepts();
|
|
31
|
+
const { isLoading: isLoadingPatientToEdit, patient: patientToEdit } = usePatient(patientUuid);
|
|
32
|
+
const { data: attributes, isLoading: isLoadingAttributes } = useInitialPersonAttributes(patientUuid);
|
|
33
|
+
const { data: identifiers, isLoading: isLoadingIdentifiers } = useInitialPatientIdentifiers(patientUuid);
|
|
34
|
+
const { data: relationships, isLoading: isLoadingRelationships } = useInitialPatientRelationships(patientUuid);
|
|
35
|
+
const { data: obs, isLoading: isLoadingObs, obs: observations } = usePatientObs(patientUuid);
|
|
36
|
+
const { data: token, isLoading: isLoadingToken } = useGlobalProperties();
|
|
37
|
+
const [initialFormValues, setInitialFormValues] = useState<FormValues>({
|
|
38
|
+
patientUuid: v4(),
|
|
39
|
+
givenName: '',
|
|
40
|
+
middleName: '',
|
|
41
|
+
familyName: '',
|
|
42
|
+
unidentifiedPatient: false,
|
|
43
|
+
additionalGivenName: '',
|
|
44
|
+
additionalMiddleName: '',
|
|
45
|
+
additionalFamilyName: '',
|
|
46
|
+
addNameInLocalLanguage: false,
|
|
47
|
+
gender: '',
|
|
48
|
+
birthdate: null,
|
|
49
|
+
yearsEstimated: 0,
|
|
50
|
+
monthsEstimated: 0,
|
|
51
|
+
birthdateEstimated: false,
|
|
52
|
+
telephoneNumber: '',
|
|
53
|
+
isDead: false,
|
|
54
|
+
deathDate: '',
|
|
55
|
+
deathCause: '',
|
|
56
|
+
relationships: [],
|
|
57
|
+
identifiers: {},
|
|
58
|
+
address: {},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
(async () => {
|
|
63
|
+
if (patientToEdit) {
|
|
64
|
+
setInitialFormValues({
|
|
65
|
+
...initialFormValues,
|
|
66
|
+
...getFormValuesFromFhirPatient(patientToEdit),
|
|
67
|
+
address: getAddressFieldValuesFromFhirPatient(patientToEdit),
|
|
68
|
+
...getPhonePersonAttributeValueFromFhirPatient(patientToEdit),
|
|
69
|
+
});
|
|
70
|
+
} else if (!isLoadingPatientToEdit && patientUuid) {
|
|
71
|
+
const registration = await getPatientRegistration(patientUuid);
|
|
72
|
+
|
|
73
|
+
if (!registration._patientRegistrationData.formValues) {
|
|
74
|
+
console.error(
|
|
75
|
+
`Found a queued offline patient registration for patient ${patientUuid}, but without form values. Not using these values.`,
|
|
76
|
+
);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
setInitialFormValues(registration._patientRegistrationData.formValues);
|
|
81
|
+
}
|
|
82
|
+
})();
|
|
83
|
+
}, [isLoadingPatientToEdit, patientToEdit, patientUuid]);
|
|
84
|
+
|
|
85
|
+
// Setting authentication token
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (!isLoadingToken && token) {
|
|
89
|
+
setInitialFormValues((initialFormValues) => ({ ...initialFormValues, token: String(token.access_token) }));
|
|
90
|
+
}
|
|
91
|
+
}, [isLoadingToken, token]);
|
|
92
|
+
|
|
93
|
+
// Set initial patient relationships
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!isLoadingRelationships && relationships) {
|
|
96
|
+
setInitialFormValues((initialFormValues) => ({
|
|
97
|
+
...initialFormValues,
|
|
98
|
+
relationships,
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
}, [isLoadingRelationships, relationships, setInitialFormValues]);
|
|
102
|
+
|
|
103
|
+
// Set Initial patient identifiers
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!isLoadingIdentifiers && identifiers) {
|
|
106
|
+
setInitialFormValues((initialFormValues) => ({
|
|
107
|
+
...initialFormValues,
|
|
108
|
+
identifiers,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
}, [isLoadingIdentifiers, identifiers, setInitialFormValues]);
|
|
112
|
+
|
|
113
|
+
// Set Initial person attributes
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (!isLoadingAttributes && attributes) {
|
|
116
|
+
let personAttributes = {};
|
|
117
|
+
attributes.forEach((attribute) => {
|
|
118
|
+
personAttributes[attribute.attributeType.uuid] =
|
|
119
|
+
attribute.attributeType.format === 'org.openmrs.Concept' && typeof attribute.value === 'object'
|
|
120
|
+
? attribute.value?.uuid
|
|
121
|
+
: attribute.value;
|
|
122
|
+
});
|
|
123
|
+
setInitialFormValues((initialFormValues) => ({
|
|
124
|
+
...initialFormValues,
|
|
125
|
+
attributes: personAttributes,
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
}, [attributes, setInitialFormValues, isLoadingAttributes]);
|
|
129
|
+
|
|
130
|
+
// Set initial patient obs
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (!isLoadingObs) {
|
|
134
|
+
setInitialFormValues((initialFormValues) => ({ ...initialFormValues, obs: obs, observation: observations }));
|
|
135
|
+
}
|
|
136
|
+
}, [isLoadingObs]);
|
|
137
|
+
|
|
138
|
+
// Set Initial encounter
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (!educationLoad || !loadingStatus) {
|
|
142
|
+
setInitialFormValues((initialFormValues) => ({
|
|
143
|
+
...initialFormValues,
|
|
144
|
+
concepts: [...occupation, ...martialStatus, ...education],
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
}, [educationLoad, loadingStatus]);
|
|
148
|
+
|
|
149
|
+
return [initialFormValues, setInitialFormValues];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function useInitialAddressFieldValues(patientUuid: string, fallback = {}): [object, Dispatch<object>] {
|
|
153
|
+
const { isLoading, patient } = usePatient(patientUuid);
|
|
154
|
+
const [initialAddressFieldValues, setInitialAddressFieldValues] = useState<object>(fallback);
|
|
155
|
+
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
(async () => {
|
|
158
|
+
if (patient) {
|
|
159
|
+
setInitialAddressFieldValues({
|
|
160
|
+
...initialAddressFieldValues,
|
|
161
|
+
address: getAddressFieldValuesFromFhirPatient(patient),
|
|
162
|
+
});
|
|
163
|
+
} else if (!isLoading && patientUuid) {
|
|
164
|
+
const registration = await getPatientRegistration(patientUuid);
|
|
165
|
+
setInitialAddressFieldValues(registration?._patientRegistrationData.initialAddressFieldValues ?? fallback);
|
|
166
|
+
}
|
|
167
|
+
})();
|
|
168
|
+
}, [isLoading, patient, patientUuid]);
|
|
169
|
+
|
|
170
|
+
return [initialAddressFieldValues, setInitialAddressFieldValues];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function usePatientUuidMap(
|
|
174
|
+
patientUuid: string,
|
|
175
|
+
fallback: PatientUuidMapType = {},
|
|
176
|
+
): [PatientUuidMapType, Dispatch<PatientUuidMapType>] {
|
|
177
|
+
const { isLoading: isLoadingPatientToEdit, patient: patientToEdit } = usePatient(patientUuid);
|
|
178
|
+
const [patientUuidMap, setPatientUuidMap] = useState(fallback);
|
|
179
|
+
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (patientToEdit) {
|
|
182
|
+
setPatientUuidMap({ ...patientUuidMap, ...getPatientUuidMapFromFhirPatient(patientToEdit) });
|
|
183
|
+
} else if (!isLoadingPatientToEdit && patientUuid) {
|
|
184
|
+
getPatientRegistration(patientUuid).then((registration) =>
|
|
185
|
+
setPatientUuidMap(registration?._patientRegistrationData.initialAddressFieldValues ?? fallback),
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}, [isLoadingPatientToEdit, patientToEdit, patientUuid]);
|
|
189
|
+
|
|
190
|
+
return [patientUuidMap, setPatientUuidMap];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function getPatientRegistration(patientUuid: string) {
|
|
194
|
+
const items = await getSynchronizationItems<PatientRegistration>(patientRegistration);
|
|
195
|
+
return items.find((item) => item._patientRegistrationData.formValues.patientUuid === patientUuid);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function useInitialPatientIdentifiers(patientUuid: string): {
|
|
199
|
+
data: FormValues['identifiers'];
|
|
200
|
+
isLoading: boolean;
|
|
201
|
+
} {
|
|
202
|
+
const shouldFetch = !!patientUuid;
|
|
203
|
+
|
|
204
|
+
const { data, error, isLoading } = useSWR<FetchResponse<{ results: Array<PatientIdentifierResponse> }>, Error>(
|
|
205
|
+
shouldFetch
|
|
206
|
+
? `/ws/rest/v1/patient/${patientUuid}/identifier?v=custom:(uuid,identifier,identifierType:(uuid,required,name),preferred)`
|
|
207
|
+
: null,
|
|
208
|
+
openmrsFetch,
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const result: {
|
|
212
|
+
data: FormValues['identifiers'];
|
|
213
|
+
isLoading: boolean;
|
|
214
|
+
} = useMemo(() => {
|
|
215
|
+
const identifiers: FormValues['identifiers'] = {};
|
|
216
|
+
|
|
217
|
+
data?.data?.results?.forEach((patientIdentifier) => {
|
|
218
|
+
identifiers[camelCase(patientIdentifier.identifierType.name)] = {
|
|
219
|
+
identifierUuid: patientIdentifier.uuid,
|
|
220
|
+
preferred: patientIdentifier.preferred,
|
|
221
|
+
initialValue: patientIdentifier.identifier,
|
|
222
|
+
identifierValue: patientIdentifier.identifier,
|
|
223
|
+
identifierTypeUuid: patientIdentifier.identifierType.uuid,
|
|
224
|
+
identifierName: patientIdentifier.identifierType.name,
|
|
225
|
+
required: patientIdentifier.identifierType.required,
|
|
226
|
+
selectedSource: null,
|
|
227
|
+
autoGeneration: false,
|
|
228
|
+
};
|
|
229
|
+
});
|
|
230
|
+
return {
|
|
231
|
+
data: identifiers,
|
|
232
|
+
isLoading,
|
|
233
|
+
};
|
|
234
|
+
}, [data, error]);
|
|
235
|
+
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function useInitialEncounters(patientUuid: string, patientToEdit: fhir.Patient) {
|
|
240
|
+
const { registrationObs } = useConfig() as RegistrationConfig;
|
|
241
|
+
const { data, error, isLoading } = useSWR<FetchResponse<{ results: Array<Encounter> }>>(
|
|
242
|
+
patientToEdit
|
|
243
|
+
? `/ws/rest/v1/encounter?patient=${patientUuid}&v=full&encounterType=${registrationObs.encounterTypeUuid}`
|
|
244
|
+
: null,
|
|
245
|
+
openmrsFetch,
|
|
246
|
+
);
|
|
247
|
+
const obs = data?.data.results.sort(latestFirstEncounter)?.at(0)?.obs;
|
|
248
|
+
const encounters = obs
|
|
249
|
+
?.map(({ concept, value }) => ({ [concept['uuid']]: value['uuid'] }))
|
|
250
|
+
.reduce((accu, curr) => Object.assign(accu, curr), {});
|
|
251
|
+
|
|
252
|
+
return { data: encounters, isLoading, error };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function useInitialPersonAttributes(personUuid: string) {
|
|
256
|
+
const shouldFetch = !!personUuid;
|
|
257
|
+
const { data, error, isLoading } = useSWR<FetchResponse<{ results: Array<PersonAttributeResponse> }>, Error>(
|
|
258
|
+
shouldFetch
|
|
259
|
+
? `/ws/rest/v1/person/${personUuid}/attribute?v=custom:(uuid,display,attributeType:(uuid,display,format),value)`
|
|
260
|
+
: null,
|
|
261
|
+
openmrsFetch,
|
|
262
|
+
);
|
|
263
|
+
const result = useMemo(() => {
|
|
264
|
+
return {
|
|
265
|
+
data: data?.data?.results,
|
|
266
|
+
isLoading,
|
|
267
|
+
};
|
|
268
|
+
}, [data, error]);
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function usePatientObs(patientUuid: string) {
|
|
273
|
+
const {
|
|
274
|
+
registrationObs: { encounterTypeUuid },
|
|
275
|
+
} = useConfig() as RegistrationConfig;
|
|
276
|
+
const url = `/ws/rest/v1/encounter?patient=${patientUuid}&encounterType=${encounterTypeUuid}&v=custom:(obs:(uuid,display,concept:(uuid,display),value:(uuid,display)))`;
|
|
277
|
+
const { data, isLoading, error } = useSWR<{ data: ObsResponse }>(patientUuid ? url : null, openmrsFetch);
|
|
278
|
+
let obsObject = {};
|
|
279
|
+
const patientObs = last(data?.data?.results)?.obs?.forEach((ob) => {
|
|
280
|
+
Object.assign(obsObject, { [ob.concept.uuid]: ob.value.uuid });
|
|
281
|
+
});
|
|
282
|
+
return { data: obsObject, isLoading, error, obs: data?.data };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function useConcepts() {
|
|
286
|
+
const { data: martialStatus, isLoading: loadingStatus } = useConceptAnswers('1054AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
|
|
287
|
+
const { data: education, isLoading: educationLoad } = useConceptAnswers('1712AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
|
|
288
|
+
const occupation: Array<ConceptAnswers> = [
|
|
289
|
+
{
|
|
290
|
+
uuid: '1538AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
|
291
|
+
display: 'Farmer',
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
uuid: '1540AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
|
295
|
+
display: 'Employee',
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
uuid: '1539AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
|
299
|
+
display: 'Trader',
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
uuid: '159465AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
|
303
|
+
display: 'Student',
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
uuid: '159466AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
|
307
|
+
display: 'Driver',
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
uuid: '1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
|
311
|
+
display: 'None',
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
uuid: '5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
|
315
|
+
display: 'Other',
|
|
316
|
+
},
|
|
317
|
+
];
|
|
318
|
+
|
|
319
|
+
return { martialStatus, education, occupation, loadingStatus, educationLoad };
|
|
320
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { OpenmrsResource, Session } from '@openmrs/esm-framework';
|
|
2
|
+
import { RegistrationConfig } from '../config-schema';
|
|
3
|
+
import { SavePatientTransactionManager } from './form-manager';
|
|
4
|
+
|
|
5
|
+
interface NameValue {
|
|
6
|
+
uuid: string;
|
|
7
|
+
preferred: boolean;
|
|
8
|
+
givenName: string;
|
|
9
|
+
middleName: string;
|
|
10
|
+
familyName: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AttributeValue {
|
|
14
|
+
attributeType: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Patient Identifier data as it is fetched and composed from the APIs.
|
|
20
|
+
*/
|
|
21
|
+
export interface FetchedPatientIdentifierType {
|
|
22
|
+
name: string;
|
|
23
|
+
required: boolean;
|
|
24
|
+
uuid: string;
|
|
25
|
+
fieldName: string;
|
|
26
|
+
format: string;
|
|
27
|
+
isPrimary: boolean;
|
|
28
|
+
/** See: https://github.com/openmrs/openmrs-core/blob/e3fb1ac0a052aeff0f957a150731757dd319693b/api/src/main/java/org/openmrs/PatientIdentifierType.java#L41 */
|
|
29
|
+
uniquenessBehavior: undefined | null | 'UNIQUE' | 'NON_UNIQUE' | 'LOCATION';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface PatientIdentifierValue {
|
|
33
|
+
identifierUuid?: string;
|
|
34
|
+
identifierTypeUuid: string;
|
|
35
|
+
initialValue: string;
|
|
36
|
+
identifierValue: string;
|
|
37
|
+
identifierName: string;
|
|
38
|
+
selectedSource: IdentifierSource;
|
|
39
|
+
autoGeneration?: boolean;
|
|
40
|
+
preferred: boolean;
|
|
41
|
+
required: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Extends the `FetchedPatientIdentifierType` with aggregated data.
|
|
46
|
+
*/
|
|
47
|
+
export interface PatientIdentifierType extends FetchedPatientIdentifierType {
|
|
48
|
+
identifierSources: Array<IdentifierSource>;
|
|
49
|
+
autoGenerationSource?: IdentifierSource;
|
|
50
|
+
checked?: boolean;
|
|
51
|
+
source?: IdentifierSource;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface IdentifierSource {
|
|
55
|
+
uuid: string;
|
|
56
|
+
name: string;
|
|
57
|
+
autoGenerationOption?: IdentifierSourceAutoGenerationOption;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface IdentifierSourceAutoGenerationOption {
|
|
61
|
+
manualEntryEnabled: boolean;
|
|
62
|
+
automaticGenerationEnabled: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface PatientIdentifier {
|
|
66
|
+
uuid?: string;
|
|
67
|
+
identifier: string;
|
|
68
|
+
identifierType?: string;
|
|
69
|
+
location?: string;
|
|
70
|
+
preferred?: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface PatientRegistration {
|
|
74
|
+
id?: number;
|
|
75
|
+
/**
|
|
76
|
+
* The preliminary patient in the FHIR format.
|
|
77
|
+
*/
|
|
78
|
+
fhirPatient: fhir.Patient;
|
|
79
|
+
/**
|
|
80
|
+
* Internal data collected by patient-registration. Required for later syncing and editing.
|
|
81
|
+
* Not supposed to be used outside of this module.
|
|
82
|
+
*/
|
|
83
|
+
_patientRegistrationData: {
|
|
84
|
+
isNewPatient: boolean;
|
|
85
|
+
formValues: FormValues;
|
|
86
|
+
patientUuidMap: PatientUuidMapType;
|
|
87
|
+
initialAddressFieldValues: Record<string, any>;
|
|
88
|
+
capturePhotoProps: CapturePhotoProps;
|
|
89
|
+
currentLocation: string;
|
|
90
|
+
initialIdentifierValues: FormValues['identifiers'];
|
|
91
|
+
currentUser: Session;
|
|
92
|
+
config: RegistrationConfig;
|
|
93
|
+
savePatientTransactionManager: SavePatientTransactionManager;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type Relationship = {
|
|
98
|
+
relationshipType: string;
|
|
99
|
+
personA: string;
|
|
100
|
+
personB: string;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type Patient = {
|
|
104
|
+
uuid: string;
|
|
105
|
+
identifiers: Array<PatientIdentifier>;
|
|
106
|
+
person: {
|
|
107
|
+
uuid: string;
|
|
108
|
+
names: Array<NameValue>;
|
|
109
|
+
gender: string;
|
|
110
|
+
birthdate: string;
|
|
111
|
+
birthdateEstimated: boolean;
|
|
112
|
+
attributes: Array<AttributeValue>;
|
|
113
|
+
addresses: Array<Record<string, string>>;
|
|
114
|
+
dead: boolean;
|
|
115
|
+
deathDate?: string;
|
|
116
|
+
causeOfDeath?: string;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export interface Encounter {
|
|
121
|
+
encounterDatetime: Date | string;
|
|
122
|
+
patient: string;
|
|
123
|
+
encounterType: string;
|
|
124
|
+
location: string;
|
|
125
|
+
encounterProviders: Array<{
|
|
126
|
+
provider: string;
|
|
127
|
+
encounterRole: string;
|
|
128
|
+
}>;
|
|
129
|
+
form: string;
|
|
130
|
+
obs: Array<{
|
|
131
|
+
concept: string;
|
|
132
|
+
value: string | number;
|
|
133
|
+
}>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface RelationshipValue {
|
|
137
|
+
relatedPersonName?: string;
|
|
138
|
+
relatedPersonUuid: string;
|
|
139
|
+
relation?: string;
|
|
140
|
+
relationshipType: string;
|
|
141
|
+
/**
|
|
142
|
+
* Defines the action to be taken on the existing relationship
|
|
143
|
+
* @kind ADD -> adds a new relationship
|
|
144
|
+
* @kind UPDATE -> updates an existing relationship
|
|
145
|
+
* @kind DELETE -> deletes an existing relationship
|
|
146
|
+
* @kind undefined -> no operation on the existing relationship
|
|
147
|
+
*/
|
|
148
|
+
action?: 'ADD' | 'UPDATE' | 'DELETE';
|
|
149
|
+
/**
|
|
150
|
+
* Value kept for restoring initial relationshipType value
|
|
151
|
+
*/
|
|
152
|
+
initialrelationshipTypeValue?: string;
|
|
153
|
+
uuid?: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface FormValues {
|
|
157
|
+
patientUuid: string;
|
|
158
|
+
givenName: string;
|
|
159
|
+
middleName: string;
|
|
160
|
+
familyName: string;
|
|
161
|
+
unidentifiedPatient: boolean;
|
|
162
|
+
additionalGivenName: string;
|
|
163
|
+
additionalMiddleName: string;
|
|
164
|
+
additionalFamilyName: string;
|
|
165
|
+
addNameInLocalLanguage: boolean;
|
|
166
|
+
gender: string;
|
|
167
|
+
birthdate: Date | string;
|
|
168
|
+
yearsEstimated: number;
|
|
169
|
+
monthsEstimated: number;
|
|
170
|
+
birthdateEstimated: boolean;
|
|
171
|
+
telephoneNumber: string;
|
|
172
|
+
isDead: boolean;
|
|
173
|
+
deathDate: string;
|
|
174
|
+
deathCause: string;
|
|
175
|
+
relationships: Array<RelationshipValue>;
|
|
176
|
+
identifiers: {
|
|
177
|
+
[identifierFieldName: string]: PatientIdentifierValue;
|
|
178
|
+
};
|
|
179
|
+
attributes?: {
|
|
180
|
+
[attributeTypeUuid: string]: string;
|
|
181
|
+
};
|
|
182
|
+
obs?: {
|
|
183
|
+
[conceptUuid: string]: string;
|
|
184
|
+
};
|
|
185
|
+
address: {
|
|
186
|
+
[addressField: string]: string;
|
|
187
|
+
};
|
|
188
|
+
observation?: ObsResponse;
|
|
189
|
+
concepts?: Array<ConceptAnswers>;
|
|
190
|
+
token?: string;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface PatientUuidMapType {
|
|
194
|
+
additionalNameUuid?: string;
|
|
195
|
+
preferredNameUuid?: string;
|
|
196
|
+
preferredAddressUuid?: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface CapturePhotoProps {
|
|
200
|
+
imageData: string;
|
|
201
|
+
dateTime: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface AddressValidationSchemaType {
|
|
205
|
+
name: string;
|
|
206
|
+
label: string;
|
|
207
|
+
regex: RegExp;
|
|
208
|
+
regexFormat: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface CodedPersonAttributeConfig {
|
|
212
|
+
personAttributeUuid: string;
|
|
213
|
+
conceptUuid: string;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface TextBasedPersonAttributeConfig {
|
|
217
|
+
personAttributeUuid: string;
|
|
218
|
+
validationRegex: string;
|
|
219
|
+
}
|
|
220
|
+
export interface PatientIdentifierResponse {
|
|
221
|
+
uuid: string;
|
|
222
|
+
identifier: string;
|
|
223
|
+
preferred: boolean;
|
|
224
|
+
identifierType: {
|
|
225
|
+
uuid: string;
|
|
226
|
+
required: boolean;
|
|
227
|
+
name: string;
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
export interface PersonAttributeTypeResponse {
|
|
231
|
+
uuid: string;
|
|
232
|
+
display: string;
|
|
233
|
+
name: string;
|
|
234
|
+
description: string;
|
|
235
|
+
format: string;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface PersonAttributeResponse {
|
|
239
|
+
display: string;
|
|
240
|
+
uuid: string;
|
|
241
|
+
value:
|
|
242
|
+
| string
|
|
243
|
+
| {
|
|
244
|
+
uuid: string;
|
|
245
|
+
display: string;
|
|
246
|
+
};
|
|
247
|
+
attributeType: {
|
|
248
|
+
display: string;
|
|
249
|
+
uuid: string;
|
|
250
|
+
format: 'org.openmrs.Concept' | string;
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export interface ConceptResponse {
|
|
255
|
+
uuid: string;
|
|
256
|
+
display: string;
|
|
257
|
+
datatype: {
|
|
258
|
+
uuid: string;
|
|
259
|
+
display: string;
|
|
260
|
+
};
|
|
261
|
+
answers: Array<ConceptAnswers>;
|
|
262
|
+
setMembers: Array<ConceptAnswers>;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface ConceptAnswers {
|
|
266
|
+
display: string;
|
|
267
|
+
uuid: string;
|
|
268
|
+
}
|
|
269
|
+
export interface ObsResponse {
|
|
270
|
+
results: Array<{ obs: Array<{ uuid: string; display: string; value: OpenmrsResource; concept: OpenmrsResource }> }>;
|
|
271
|
+
}
|