@kenyaemr/esm-patient-registration-app 4.3.0 → 4.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/207.js +1 -1
  2. package/dist/207.js.map +1 -1
  3. package/dist/317.js +1 -1
  4. package/dist/317.js.map +1 -1
  5. package/dist/417.js +2 -0
  6. package/dist/417.js.map +1 -0
  7. package/dist/574.js +1 -1
  8. package/dist/591.js +1 -1
  9. package/dist/591.js.map +1 -1
  10. package/dist/62.js +1 -1
  11. package/dist/62.js.map +1 -1
  12. package/dist/635.js +1 -1
  13. package/dist/635.js.map +1 -1
  14. package/dist/68.js +1 -1
  15. package/dist/68.js.map +1 -1
  16. package/dist/698.js +1 -0
  17. package/dist/698.js.map +1 -0
  18. package/dist/735.js +1 -1
  19. package/dist/735.js.map +1 -1
  20. package/dist/757.js +1 -1
  21. package/dist/784.js +1 -1
  22. package/dist/784.js.map +1 -1
  23. package/dist/805.js +1 -1
  24. package/dist/805.js.map +1 -1
  25. package/dist/807.js +1 -1
  26. package/dist/858.js +1 -1
  27. package/dist/858.js.map +1 -1
  28. package/dist/887.js +1 -1
  29. package/dist/887.js.map +1 -1
  30. package/dist/9.js +1 -1
  31. package/dist/9.js.map +1 -1
  32. package/dist/909.js +1 -0
  33. package/dist/{821.js.map → 909.js.map} +1 -1
  34. package/dist/975.js +1 -1
  35. package/dist/975.js.map +1 -1
  36. package/dist/kenyaemr-esm-patient-registration-app.js +1 -0
  37. package/dist/{openmrs-esm-patient-registration-app.js.buildmanifest.json → kenyaemr-esm-patient-registration-app.js.buildmanifest.json} +112 -160
  38. package/dist/kenyaemr-esm-patient-registration-app.js.map +1 -0
  39. package/dist/kenyaemr-esm-patient-registration-app.old +1 -0
  40. package/dist/main.js +1 -1
  41. package/dist/main.js.map +1 -1
  42. package/package.json +3 -3
  43. package/src/constants.ts +1 -1
  44. package/src/index.ts +0 -18
  45. package/src/offline.resources.ts +8 -1
  46. package/src/patient-registration/field/address/address-field.component.tsx +0 -1
  47. package/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx +13 -11
  48. package/src/patient-registration/form-manager.ts +27 -10
  49. package/src/patient-registration/input/basic-input/input/input.test.tsx +47 -10
  50. package/src/patient-registration/input/basic-input/select/select-input.test.tsx +16 -3
  51. package/src/patient-registration/input/custom-input/autosuggest/autosuggest.test.tsx +25 -14
  52. package/src/patient-registration/patient-registration-hooks.ts +21 -75
  53. package/src/patient-registration/patient-registration-types.tsx +2 -8
  54. package/src/patient-registration/patient-registration.component.tsx +3 -26
  55. package/src/patient-registration/section/section-wrapper.component.tsx +1 -1
  56. package/src/root.component.tsx +1 -5
  57. package/translations/en.json +0 -15
  58. package/dist/144.js +0 -2
  59. package/dist/144.js.map +0 -1
  60. package/dist/330.js +0 -1
  61. package/dist/330.js.map +0 -1
  62. package/dist/59.js +0 -1
  63. package/dist/59.js.map +0 -1
  64. package/dist/821.js +0 -1
  65. package/dist/822.js +0 -1
  66. package/dist/822.js.map +0 -1
  67. package/dist/openmrs-esm-patient-registration-app.js +0 -1
  68. package/dist/openmrs-esm-patient-registration-app.js.map +0 -1
  69. package/dist/openmrs-esm-patient-registration-app.old +0 -1
  70. package/src/patient-registration/input/custom-input/estimated-age/estimated-age-input.component.tsx +0 -32
  71. package/src/patient-registration/input/custom-input/estimated-age/estimated-age-input.test.tsx +0 -36
  72. package/src/patient-registration/input/custom-input/unidentified-patient/unidentified-patient-input.component.tsx +0 -24
  73. package/src/patient-registration/input/custom-input/unidentified-patient/unidentified-patient-input.test.tsx +0 -39
  74. package/src/patient-verification/assets/counties.json +0 -236
  75. package/src/patient-verification/assets/verification-assets.ts +0 -11
  76. package/src/patient-verification/patient-verification-hook.tsx +0 -156
  77. package/src/patient-verification/patient-verification-utils.ts +0 -173
  78. package/src/patient-verification/patient-verification.component.tsx +0 -118
  79. package/src/patient-verification/patient-verification.scss +0 -30
  80. package/src/patient-verification/verification-modal/confirm-prompt.component.tsx +0 -69
  81. package/src/patient-verification/verification-modal/empty-prompt.component.tsx +0 -35
  82. package/src/patient-verification/verification-types.ts +0 -50
  83. /package/dist/{144.js.LICENSE.txt → 417.js.LICENSE.txt} +0 -0
@@ -1,236 +0,0 @@
1
- [
2
- {
3
- "name": "Mombasa",
4
- "code": 1,
5
- "capital": "Mombasa City"
6
- },
7
- {
8
- "name": "Kwale",
9
- "code": 2,
10
- "capital": "Kwale"
11
- },
12
- {
13
- "name": "Kilifi",
14
- "code": 3,
15
- "capital": "Kilifi"
16
- },
17
- {
18
- "name": "Tana River",
19
- "code": 4,
20
- "capital": "Hola"
21
- },
22
- {
23
- "name": "Lamu",
24
- "code": 5,
25
- "capital": "Lamu"
26
- },
27
- {
28
- "name": "Taita taveta",
29
- "code": 6,
30
- "capital": "Voi"
31
- },
32
- {
33
- "name": "Garissa",
34
- "code": 7,
35
- "capital": "Garissa"
36
- },
37
- {
38
- "name": "Wajir",
39
- "code": 8,
40
- "capital": "Wajir"
41
- },
42
- {
43
- "name": "Mandera",
44
- "code": 9,
45
- "capital": "Mandera"
46
- },
47
- {
48
- "name": "Marsabit",
49
- "code": 10,
50
- "capital": "Marsabit"
51
- },
52
- {
53
- "name": "Isiolo",
54
- "code": 11,
55
- "capital": "Isiolo"
56
- },
57
- {
58
- "name": "Meru",
59
- "code": 12,
60
- "capital": "Meru"
61
- },
62
- {
63
- "name": "Tharaka nithi",
64
- "code": 13,
65
- "capital": "Chuka"
66
- },
67
- {
68
- "name": "Embu",
69
- "code": 14,
70
- "capital": "Embu"
71
- },
72
- {
73
- "name": "Kitui",
74
- "code": 15,
75
- "capital": "Kitui"
76
- },
77
- {
78
- "name": "Machakos",
79
- "code": 16,
80
- "capital": "Machakos"
81
- },
82
- {
83
- "name": "Makueni",
84
- "code": 17,
85
- "capital": "Wote"
86
- },
87
- {
88
- "name": "Nyandarua",
89
- "code": 18,
90
- "capital": "Ol Kalou"
91
- },
92
- {
93
- "name": "Nyeri",
94
- "code": 19,
95
- "capital": "Nyeri"
96
- },
97
- {
98
- "name": "Kirinyaga",
99
- "code": 20,
100
- "capital": "Kerugoya/Kutus"
101
- },
102
- {
103
- "name": "Murang'a",
104
- "code": 21,
105
- "capital": "Murang'a"
106
- },
107
- {
108
- "name": "Kiambu",
109
- "code": 22,
110
- "capital": "Kiambu"
111
- },
112
- {
113
- "name": "Turkana",
114
- "code": 23,
115
- "capital": "Lodwar"
116
- },
117
- {
118
- "name": "West pokot",
119
- "code": 24,
120
- "capital": "Kapenguria"
121
- },
122
- {
123
- "name": "Samburu",
124
- "code": 25,
125
- "capital": "Maralal"
126
- },
127
- {
128
- "name": "Trans nzoia",
129
- "code": 26,
130
- "capital": "Kitale"
131
- },
132
- {
133
- "name": "Uasin gishu",
134
- "code": 27,
135
- "capital": "Eldoret"
136
- },
137
- {
138
- "name": "Elgeyo marakwet",
139
- "code": 28,
140
- "capital": "Iten"
141
- },
142
- {
143
- "name": "Nandi",
144
- "code": 29,
145
- "capital": "Kapsabet"
146
- },
147
- {
148
- "name": "Baringo",
149
- "code": 30,
150
- "capital": "Kabarnet"
151
- },
152
- {
153
- "name": "Laikipia",
154
- "code": 31,
155
- "capital": "Rumuruti"
156
- },
157
- {
158
- "name": "Nakuru",
159
- "code": 32,
160
- "capital": "Nakuru"
161
- },
162
- {
163
- "name": "Narok",
164
- "code": 33,
165
- "capital": "Narok"
166
- },
167
- {
168
- "name": "Kajiado",
169
- "code": 34
170
- },
171
- {
172
- "name": "Kericho",
173
- "code": 35,
174
- "capital": "Kericho"
175
- },
176
- {
177
- "name": "Bomet",
178
- "code": 36,
179
- "capital": "Bomet"
180
- },
181
- {
182
- "name": "Kakamega",
183
- "code": 37,
184
- "capital": "Kakamega"
185
- },
186
- {
187
- "name": "Vihiga",
188
- "code": 38,
189
- "capital": "Vihiga"
190
- },
191
- {
192
- "name": "Bungoma",
193
- "code": 39,
194
- "capital": "Bungoma"
195
- },
196
- {
197
- "name": "Busia",
198
- "code": 40,
199
- "capital": "Busia"
200
- },
201
- {
202
- "name": "Siaya",
203
- "code": 41,
204
- "capital": "Siaya"
205
- },
206
- {
207
- "name": "Kisumu",
208
- "code": 42,
209
- "capital": "Kisumu"
210
- },
211
- {
212
- "name": "Homa bay",
213
- "code": 43,
214
- "capital": "Homa Bay"
215
- },
216
- {
217
- "name": "Migori",
218
- "code": 44,
219
- "capital": "Migori"
220
- },
221
- {
222
- "name": "Kisii",
223
- "code": 45,
224
- "capital": "Kisii"
225
- },
226
- {
227
- "name": "Nyamira",
228
- "code": 46,
229
- "capital": "Nyamira"
230
- },
231
- {
232
- "name": "Nairobi",
233
- "code": 47,
234
- "capital": "Nairobi City"
235
- }
236
- ]
@@ -1,11 +0,0 @@
1
- export const countries = [
2
- { name: 'Kenya', initials: 'KE' },
3
- { name: 'Uganda', initials: 'UG' },
4
- { name: 'Tanzania', initials: 'TZ' },
5
- ];
6
-
7
- export const verificationIdentifierTypes = [
8
- { name: 'National ID', value: 'national-id' },
9
- { name: 'Passport', value: 'passport' },
10
- { name: 'Birth certificate number', value: 'birth-certificate-number' },
11
- ];
@@ -1,156 +0,0 @@
1
- import { FetchResponse, openmrsFetch, showNotification, showToast } from '@openmrs/esm-framework';
2
- import { ConceptAnswers, ConceptResponse, FormValues } from '../patient-registration/patient-registration-types';
3
- import { generateNUPIPayload, handleClientRegistryResponse } from './patient-verification-utils';
4
- import useSWR from 'swr';
5
- import useSWRImmutable from 'swr/immutable';
6
-
7
- export function searchClientRegistry(identifierType: string, searchTerm: string, token: string) {
8
- const url = `https://afyakenyaapi.health.go.ke/partners/registry/search/KE/${identifierType}/${searchTerm}`;
9
- return fetch(url, { headers: { Authorization: `Bearer ${token}` } }).then((r) => r.json());
10
- }
11
-
12
- export function savePatientToClientRegistry(formValues: FormValues) {
13
- const createdRegistryPatient = generateNUPIPayload(formValues);
14
- return fetch(`https://afyakenyaapi.health.go.ke/partners/registry`, {
15
- headers: { Authorization: `Bearer ${formValues.token}`, 'Content-Type': 'application/json' },
16
- method: 'POST',
17
- body: JSON.stringify(createdRegistryPatient),
18
- });
19
- }
20
-
21
- export async function handleSavePatientToClientRegistry(
22
- formValues: FormValues,
23
- setValues: (values: FormValues, shouldValidate?: boolean) => void,
24
- inEditMode: boolean,
25
- ) {
26
- const mode = inEditMode ? 'edit' : 'new';
27
- switch (mode) {
28
- case 'edit': {
29
- try {
30
- const searchResponse = await searchClientRegistry(
31
- 'national-id',
32
- formValues.identifiers['nationalId'].identifierValue,
33
- formValues.token,
34
- );
35
-
36
- // if client does not exists post client to registry
37
- if (searchResponse?.clientExists === false) {
38
- postToRegistry(formValues, setValues);
39
- }
40
- } catch (error) {
41
- showToast({
42
- title: 'Client registry error',
43
- description: `${error}`,
44
- millis: 10000,
45
- kind: 'error',
46
- critical: true,
47
- });
48
- }
49
- return;
50
- }
51
- case 'new': {
52
- postToRegistry(formValues, setValues);
53
- }
54
- }
55
- }
56
-
57
- export function useConceptAnswers(conceptUuid: string): { data: Array<ConceptAnswers>; isLoading: boolean } {
58
- const { data, error, isLoading } = useSWR<FetchResponse<ConceptResponse>, Error>(
59
- `/ws/rest/v1/concept/${conceptUuid}`,
60
- openmrsFetch,
61
- );
62
- if (error) {
63
- showToast({
64
- title: error.name,
65
- description: error.message,
66
- kind: 'error',
67
- });
68
- }
69
- return { data: data?.data?.answers ?? [], isLoading };
70
- }
71
-
72
- const urlencoded = new URLSearchParams();
73
- urlencoded.append('client_id', 'palladium.partner.client');
74
- urlencoded.append('client_secret', '28f95b2a');
75
- urlencoded.append('grant_type', 'client_credentials');
76
- urlencoded.append('scope', 'DHP.Gateway DHP.Partners');
77
-
78
- const swrFetcher = async (url) => {
79
- const res = await fetch(url, {
80
- method: 'POST',
81
- body: urlencoded,
82
- redirect: 'follow',
83
- });
84
-
85
- // If the status code is not in the range 200-299,
86
- // we still try to parse and throw it.
87
- if (!res.ok) {
88
- const error = new Error('An error occurred while fetching the data.') as any;
89
- // Attach extra info to the error object.
90
- error.info = await res.json();
91
- error.status = res.status;
92
- throw error;
93
- }
94
-
95
- return res.json();
96
- };
97
-
98
- export function useGlobalProperties() {
99
- const { data, isLoading, error } = useSWRImmutable(
100
- `https://afyakenyaidentityapi.health.go.ke/connect/token`,
101
- swrFetcher,
102
- { refreshInterval: 864000 },
103
- );
104
- return { data: data, isLoading, error };
105
- }
106
-
107
- async function postToRegistry(
108
- formValues: FormValues,
109
- setValues: (values: FormValues, shouldValidate?: boolean) => void,
110
- ) {
111
- try {
112
- const clientRegistryResponse = await savePatientToClientRegistry(formValues);
113
- if (clientRegistryResponse.ok) {
114
- const savedValues = await clientRegistryResponse.json();
115
- const nupiIdentifier = {
116
- ['nationalUniquePatientIdentifier']: {
117
- identifierTypeUuid: 'f85081e2-b4be-4e48-b3a4-7994b69bb101',
118
- identifierName: 'National Unique patient identifier',
119
- identifierValue: savedValues['clientNumber'],
120
- initialValue: savedValues['clientNumber'],
121
- identifierUuid: undefined,
122
- selectedSource: { uuid: '', name: '' },
123
- preferred: false,
124
- required: false,
125
- },
126
- };
127
- setValues({ ...formValues, identifiers: { ...formValues.identifiers, ...nupiIdentifier } });
128
- showToast({
129
- title: 'Posted patient to client registry successfully',
130
- description: `The patient has been saved to client registry`,
131
- kind: 'success',
132
- });
133
- } else {
134
- const responseError = await clientRegistryResponse.json();
135
- const errorMessage = Object.values(responseError.errors ?? {})
136
- .map((error: any) => error.join())
137
- .toString();
138
- setValues({
139
- ...formValues,
140
- attributes: {
141
- ...formValues.attributes,
142
- ['869f623a-f78e-4ace-9202-0bed481822f5']: 'Failed validation',
143
- ['752a0331-5293-4aa5-bf46-4d51aaf2cdc5']: 'Failed',
144
- },
145
- });
146
- showNotification({
147
- title: responseError.title,
148
- description: errorMessage,
149
- kind: 'warning',
150
- millis: 150000,
151
- });
152
- }
153
- } catch (error) {
154
- showNotification({ kind: 'error', title: 'NUPI Post failed', description: JSON.stringify(error) });
155
- }
156
- }
@@ -1,173 +0,0 @@
1
- import { showModal } from '@openmrs/esm-framework';
2
- import { FormikProps } from 'formik';
3
- import { FormValues } from '../patient-registration/patient-registration-types';
4
- import { ClientRegistryPatient, RegistryPatient } from './verification-types';
5
- import counties from './assets/counties.json';
6
-
7
- export function handleClientRegistryResponse(
8
- clientResponse: ClientRegistryPatient,
9
- props: FormikProps<FormValues>,
10
- searchTerm: string,
11
- ) {
12
- if (clientResponse?.clientExists === false) {
13
- const nupiIdentifiers = {
14
- ['nationalId']: {
15
- initialValue: searchTerm,
16
- identifierUuid: undefined,
17
- selectedSource: { uuid: '', name: '' },
18
- preferred: false,
19
- required: false,
20
- identifierTypeUuid: '49af6cdc-7968-4abb-bf46-de10d7f4859f',
21
- identifierName: 'National ID',
22
- identifierValue: searchTerm,
23
- },
24
- };
25
- const dispose = showModal('empty-client-registry-modal', {
26
- onConfirm: () => {
27
- props.setValues({ ...props.values, identifiers: { ...props.values.identifiers, ...nupiIdentifiers } });
28
- dispose();
29
- },
30
- close: () => dispose(),
31
- });
32
- }
33
-
34
- if (clientResponse?.clientExists) {
35
- const {
36
- client: {
37
- middleName,
38
- lastName,
39
- firstName,
40
- contact,
41
- country,
42
- countyOfBirth,
43
- residence,
44
- identifications,
45
- gender,
46
- dateOfBirth,
47
- isAlive,
48
- clientNumber,
49
- educationLevel,
50
- occupation,
51
- maritalStatus,
52
- },
53
- } = clientResponse;
54
-
55
- const nupiIdentifiers = {
56
- ['nationalId']: {
57
- initialValue: identifications !== undefined && identifications[0]?.identificationNumber,
58
- identifierUuid: undefined,
59
- selectedSource: { uuid: '', name: '' },
60
- preferred: false,
61
- required: false,
62
- identifierTypeUuid: '49af6cdc-7968-4abb-bf46-de10d7f4859f',
63
- identifierName: 'National ID',
64
- identifierValue: identifications !== undefined && identifications[0]?.identificationNumber,
65
- },
66
-
67
- ['nationalUniquePatientIdentifier']: {
68
- identifierTypeUuid: 'f85081e2-b4be-4e48-b3a4-7994b69bb101',
69
- identifierName: 'National Unique patient identifier',
70
- identifierValue: clientNumber,
71
- initialValue: clientNumber,
72
- identifierUuid: undefined,
73
- selectedSource: { uuid: '', name: '' },
74
- preferred: false,
75
- required: false,
76
- },
77
- };
78
-
79
- const dispose = showModal('confirm-client-registry-modal', {
80
- onConfirm: () => {
81
- props.setValues({
82
- ...props.values,
83
- familyName: lastName,
84
- middleName: middleName,
85
- givenName: firstName,
86
- gender: gender === 'male' ? 'Male' : 'Female',
87
- birthdate: new Date(dateOfBirth),
88
- isDead: !isAlive,
89
- attributes: {
90
- 'b2c38640-2603-4629-aebd-3b54f33f1e3a': contact?.primaryPhone,
91
- '94614350-84c8-41e0-ac29-86bc107069be': contact?.secondaryPhone,
92
- 'b8d0b331-1d2d-4a9a-b741-1816f498bdb6': contact?.emailAddress ?? '',
93
- },
94
- address: {
95
- address1: residence?.address,
96
- address2: '',
97
- address4: residence?.ward,
98
- cityVillage: residence?.village,
99
- stateProvince: residence?.subCounty,
100
- countyDistrict: counties.find((county) => county.code === parseInt(residence?.county))?.name,
101
- country: 'Kenya',
102
- postalCode: residence?.address,
103
- },
104
- identifiers: { ...props.values.identifiers, ...nupiIdentifiers },
105
- obs: {
106
- '1054AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA':
107
- props.values.concepts.find((concept) => concept.display?.toLowerCase() === maritalStatus?.toLowerCase())
108
- ?.uuid ?? '',
109
- '1712AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA':
110
- props.values.concepts.find((concept) => concept.display?.toLowerCase() === educationLevel?.toLowerCase())
111
- ?.uuid ?? '',
112
- '1542AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA':
113
- props.values.concepts.find((concept) => concept.display?.toLowerCase() === occupation?.toLowerCase())
114
- ?.uuid ?? '',
115
- },
116
- });
117
- dispose();
118
- },
119
- close: () => dispose(),
120
- patient: clientResponse.client,
121
- });
122
- }
123
- }
124
-
125
- export function generateNUPIPayload(formValues: FormValues): RegistryPatient {
126
- const educationLevel = formValues.concepts.find(
127
- (concept) => concept.uuid === formValues.obs['1712AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'],
128
- );
129
- const occupation = formValues.concepts.find(
130
- (concept) => concept.uuid === formValues.obs['1542AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'],
131
- );
132
- const maritalStatus = formValues.concepts.find(
133
- (concept) => concept.uuid === formValues.obs['1054AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'],
134
- );
135
-
136
- let createRegistryPatient: RegistryPatient = {
137
- firstName: formValues?.givenName,
138
- middleName: formValues?.middleName,
139
- lastName: formValues?.familyName,
140
- gender: formValues?.gender === 'Male' ? 'male' : 'female',
141
- dateOfBirth: new Date(formValues.birthdate).toISOString(),
142
- isAlive: !formValues.isDead,
143
- residence: {
144
- county: `0${counties.find((county) => county.name.includes(formValues.address['countyDistrict']))?.code}`,
145
- subCounty: formValues.address['stateProvince']?.toLocaleLowerCase(),
146
- ward: formValues.address['address4']?.toLocaleLowerCase(),
147
- village: formValues.address['cityVillage'],
148
- landmark: formValues.address['address2'],
149
- address: formValues.address['postalCode'],
150
- },
151
- nextOfKins: [],
152
- contact: {
153
- primaryPhone: formValues.attributes['b2c38640-2603-4629-aebd-3b54f33f1e3a'],
154
- secondaryPhone: formValues.attributes['94614350-84c8-41e0-ac29-86bc107069be'],
155
- emailAddress: formValues.attributes['b8d0b331-1d2d-4a9a-b741-1816f498bdb6'],
156
- },
157
- country: 'KE',
158
- countyOfBirth: `0${counties.find((county) => county.name.includes(formValues.address['countyDistrict']))?.code}`,
159
- educationLevel: educationLevel?.display?.toLowerCase() ?? '',
160
- religion: '',
161
- occupation: occupation?.display?.toLowerCase() ?? '',
162
- maritalStatus: maritalStatus?.display?.toLowerCase() ?? '',
163
- originFacilityKmflCode: '',
164
- nascopCCCNumber: '',
165
- identifications: [
166
- {
167
- identificationType: 'national-id',
168
- identificationNumber: formValues.identifiers['nationalId']?.identifierValue,
169
- },
170
- ],
171
- };
172
- return createRegistryPatient;
173
- }
@@ -1,118 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { useTranslation } from 'react-i18next';
3
- import { Tile, ComboBox, Layer, Button, Search, InlineLoading, InlineNotification } from '@carbon/react';
4
- import styles from './patient-verification.scss';
5
- import { countries, verificationIdentifierTypes } from './assets/verification-assets';
6
- import { searchClientRegistry, useGlobalProperties } from './patient-verification-hook';
7
- import { showToast } from '@openmrs/esm-framework';
8
- import { handleClientRegistryResponse } from './patient-verification-utils';
9
- import { FormValues } from '../patient-registration/patient-registration-types';
10
- import { FormikProps } from 'formik';
11
-
12
- interface PatientVerificationProps {
13
- props: FormikProps<FormValues>;
14
- }
15
-
16
- const PatientVerification: React.FC<PatientVerificationProps> = ({ props }) => {
17
- const { t } = useTranslation();
18
- const { data, isLoading, error } = useGlobalProperties();
19
- const [verificationCriteria, setVerificationCriteria] = useState({
20
- searchTerm: '',
21
- identifierType: '',
22
- });
23
- const [isLoadingSearch, setIsLoadingSearch] = useState(false);
24
-
25
- const handleSearch = async () => {
26
- setIsLoadingSearch(true);
27
- try {
28
- const clientRegistryResponse = await searchClientRegistry(
29
- verificationCriteria.identifierType,
30
- verificationCriteria.searchTerm,
31
- props.values.token,
32
- );
33
- setIsLoadingSearch(false);
34
- handleClientRegistryResponse(clientRegistryResponse, props, verificationCriteria.searchTerm);
35
- } catch (error) {
36
- showToast({
37
- title: 'Client registry error',
38
- description: `Please reload the registration page and re-try again, if the issue persist contact system administrator`,
39
- millis: 10000,
40
- kind: 'error',
41
- critical: true,
42
- });
43
- setIsLoadingSearch(false);
44
- }
45
- };
46
-
47
- if (isLoading) {
48
- <InlineLoading status="active" iconDescription="Loading" description="Loading data..." />;
49
- }
50
-
51
- if (error) {
52
- return (
53
- <InlineNotification
54
- lowContrast
55
- hideCloseButton
56
- title="Client registry network error"
57
- subtitle="Could not connect to client registry, please proceed with registration and try again later"
58
- style={{ marginBottom: '0.5rem' }}
59
- />
60
- );
61
- }
62
- return (
63
- <div id={'patientVerification'}>
64
- <h3 className={styles.productiveHeading02} style={{ color: '#161616' }}>
65
- {t('clientVerificationWithClientRegistry', 'Client verification with client registry')}
66
- </h3>
67
- <div style={{ margin: '1rem 0 1rem' }}>
68
- <Layer>
69
- {isLoading && <InlineLoading status="active" iconDescription="Loading" description="Loading data..." />}
70
- </Layer>
71
- <Tile className={styles.verificationWrapper}>
72
- <Layer>
73
- <ComboBox
74
- ariaLabel={t('selectCountry', 'Select country')}
75
- id="selectCountry"
76
- items={countries}
77
- itemToString={(item) => item?.name ?? ''}
78
- label="Combo box menu options"
79
- titleText={t('selectCountry', 'Select country')}
80
- initialSelectedItem={countries[0]}
81
- />
82
- </Layer>
83
- <Layer>
84
- <ComboBox
85
- ariaLabel={t('selectIdentifierType', 'Select identifier type')}
86
- id="selectIdentifierType"
87
- items={verificationIdentifierTypes}
88
- itemToString={(item) => item?.name ?? ''}
89
- label="Combo box menu options"
90
- titleText={t('selectIdentifierType', 'Select identifier type')}
91
- onChange={({ selectedItem }) =>
92
- setVerificationCriteria({ ...verificationCriteria, identifierType: selectedItem.value })
93
- }
94
- />
95
- </Layer>
96
- <Layer>
97
- <Search
98
- id="search-1"
99
- autoFocus
100
- placeHolderText="Search"
101
- disabled={!verificationCriteria.identifierType}
102
- onChange={(event) => setVerificationCriteria({ ...verificationCriteria, searchTerm: event.target.value })}
103
- />
104
- </Layer>
105
- {!isLoadingSearch ? (
106
- <Button disabled={!verificationCriteria.identifierType && !isLoading} size="md" onClick={handleSearch}>
107
- {t('validate', 'Validate')}
108
- </Button>
109
- ) : (
110
- <InlineLoading status="active" iconDescription="Loading" description="Searching client registry" />
111
- )}
112
- </Tile>
113
- </div>
114
- </div>
115
- );
116
- };
117
-
118
- export default PatientVerification;