@ampath/esm-patient-registration-app 6.0.1-pre.6 → 6.0.1-pre.68

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 (161) hide show
  1. package/.turbo/turbo-build.log +23 -24
  2. package/dist/132.js +1 -0
  3. package/dist/197.js +1 -0
  4. package/dist/236.js +1 -0
  5. package/dist/{735.js.map → 236.js.map} +1 -1
  6. package/dist/300.js +1 -0
  7. package/dist/335.js +1 -0
  8. package/dist/372.js +1 -0
  9. package/dist/372.js.map +1 -0
  10. package/dist/41.js +2 -0
  11. package/dist/41.js.map +1 -0
  12. package/dist/449.js +1 -0
  13. package/dist/449.js.map +1 -0
  14. package/dist/464.js +1 -0
  15. package/dist/464.js.map +1 -0
  16. package/dist/495.js +1 -0
  17. package/dist/495.js.map +1 -0
  18. package/dist/55.js +1 -0
  19. package/dist/56.js +1 -0
  20. package/dist/56.js.map +1 -0
  21. package/dist/621.js +1 -1
  22. package/dist/621.js.map +1 -1
  23. package/dist/629.js +2 -0
  24. package/dist/629.js.LICENSE.txt +24 -0
  25. package/dist/629.js.map +1 -0
  26. package/dist/652.js +1 -0
  27. package/dist/661.js +1 -0
  28. package/dist/757.js +1 -1
  29. package/dist/757.js.map +1 -0
  30. package/dist/828.js +1 -0
  31. package/dist/828.js.map +1 -0
  32. package/dist/830.js +1 -0
  33. package/dist/830.js.map +1 -0
  34. package/dist/831.js +2 -0
  35. package/dist/831.js.map +1 -0
  36. package/dist/876.js +2 -0
  37. package/dist/876.js.map +1 -0
  38. package/dist/879.js +1 -1
  39. package/dist/913.js +2 -0
  40. package/dist/{591.js.LICENSE.txt → 913.js.LICENSE.txt} +23 -3
  41. package/dist/913.js.map +1 -0
  42. package/dist/927.js +1 -0
  43. package/dist/927.js.map +1 -0
  44. package/dist/99.js +1 -0
  45. package/dist/ampath-esm-patient-registration-app.js +1 -1
  46. package/dist/ampath-esm-patient-registration-app.js.buildmanifest.json +236 -191
  47. package/dist/ampath-esm-patient-registration-app.js.map +1 -1
  48. package/dist/main.js +1 -1
  49. package/dist/main.js.LICENSE.txt +0 -32
  50. package/dist/main.js.map +1 -1
  51. package/dist/routes.json +1 -1
  52. package/package.json +6 -9
  53. package/src/config-schema.ts +19 -10
  54. package/src/constants.ts +1 -1
  55. package/src/index.ts +11 -4
  56. package/src/offline.resources.ts +13 -18
  57. package/src/offline.ts +6 -4
  58. package/src/patient-photo.extension.tsx +9 -0
  59. package/src/patient-registration/field/address/custom-address-field.component.tsx +1 -0
  60. package/src/patient-registration/field/custom-field.component.tsx +6 -0
  61. package/src/patient-registration/field/dob/dob.component.tsx +17 -14
  62. package/src/patient-registration/field/field.resource.ts +3 -3
  63. package/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx +4 -0
  64. package/src/patient-registration/field/person-attributes/custom-person-attribute-field.component.tsx +56 -0
  65. package/src/patient-registration/field/person-attributes/person-attribute-field.component.tsx +22 -7
  66. package/src/patient-registration/field/person-attributes/person-attributes.resource.ts +2 -2
  67. package/src/patient-registration/field/phone/phone-field.component.tsx +1 -0
  68. package/src/patient-registration/form-manager.ts +13 -6
  69. package/src/patient-registration/patient-registration-hooks.ts +91 -9
  70. package/src/patient-registration/patient-registration.component.tsx +55 -13
  71. package/src/patient-registration/{patient-registration.resource.test.tsx → patient-registration.resource.testt.tsx} +3 -3
  72. package/src/patient-registration/patient-registration.resource.ts +15 -75
  73. package/src/patient-registration/patient-registration.scss +0 -8
  74. package/src/patient-registration/patient-registration.types.ts +7 -1
  75. package/src/patient-registration/section/patient-relationships/relationships-section.component.tsx +5 -1
  76. package/src/patient-registration/section/patient-relationships/relationships.resource.tsx +2 -2
  77. package/src/patient-verification/assets/counties.json +236 -0
  78. package/src/patient-verification/assets/verification-assets.ts +11 -0
  79. package/src/patient-verification/patient-verification-hook.tsx +176 -0
  80. package/src/patient-verification/patient-verification-utils.ts +179 -0
  81. package/src/patient-verification/patient-verification.component.tsx +124 -0
  82. package/src/patient-verification/patient-verification.scss +25 -0
  83. package/src/patient-verification/verification-modal/confirm-prompt.component.tsx +72 -0
  84. package/src/patient-verification/verification-modal/empty-prompt.component.tsx +35 -0
  85. package/src/patient-verification/verification-types.ts +50 -0
  86. package/src/routes.json +12 -3
  87. package/translations/am.json +26 -12
  88. package/translations/ar.json +26 -12
  89. package/translations/en.json +19 -5
  90. package/translations/es.json +10 -0
  91. package/translations/fr.json +6 -0
  92. package/translations/he.json +18 -0
  93. package/translations/km.json +18 -0
  94. package/translations/zh.json +30 -22
  95. package/translations/zh_CN.json +30 -22
  96. package/dist/130.js +0 -2
  97. package/dist/130.js.map +0 -1
  98. package/dist/152.js +0 -1
  99. package/dist/152.js.map +0 -1
  100. package/dist/249.js +0 -2
  101. package/dist/249.js.LICENSE.txt +0 -46
  102. package/dist/249.js.map +0 -1
  103. package/dist/255.js +0 -2
  104. package/dist/255.js.map +0 -1
  105. package/dist/271.js +0 -1
  106. package/dist/303.js +0 -1
  107. package/dist/303.js.map +0 -1
  108. package/dist/319.js +0 -1
  109. package/dist/365.js +0 -1
  110. package/dist/365.js.map +0 -1
  111. package/dist/460.js +0 -1
  112. package/dist/525.js +0 -1
  113. package/dist/525.js.map +0 -1
  114. package/dist/537.js +0 -1
  115. package/dist/537.js.map +0 -1
  116. package/dist/574.js +0 -1
  117. package/dist/591.js +0 -2
  118. package/dist/591.js.map +0 -1
  119. package/dist/644.js +0 -1
  120. package/dist/729.js +0 -1
  121. package/dist/729.js.map +0 -1
  122. package/dist/735.js +0 -1
  123. package/dist/784.js +0 -2
  124. package/dist/784.js.map +0 -1
  125. package/dist/788.js +0 -1
  126. package/dist/807.js +0 -1
  127. package/dist/833.js +0 -1
  128. package/dist/879.js.map +0 -1
  129. package/src/patient-registration/field/address/tests/address-hierarchy.test.tsx +0 -214
  130. package/src/patient-registration/field/address/tests/address-search-component.test.tsx +0 -135
  131. package/src/patient-registration/field/dob/dob.test.tsx +0 -75
  132. package/src/patient-registration/field/field.test.tsx +0 -294
  133. package/src/patient-registration/field/id/id-field.test.tsx +0 -107
  134. package/src/patient-registration/field/person-attributes/coded-attributes.component.tsx +0 -60
  135. package/src/patient-registration/field/person-attributes/coded-person-attribute-field.test.tsx +0 -127
  136. package/src/patient-registration/field/person-attributes/person-attribute-field.test.tsx +0 -187
  137. package/src/patient-registration/field/person-attributes/text-person-attribute-field.test.tsx +0 -88
  138. package/src/patient-registration/form-manager.test.ts +0 -67
  139. package/src/patient-registration/input/basic-input/select/select-input.test.tsx +0 -49
  140. package/src/patient-registration/input/custom-input/autosuggest/autosuggest.test.tsx +0 -132
  141. package/src/patient-registration/input/custom-input/identifier/identifier-input.test.tsx +0 -107
  142. package/src/patient-registration/patient-registration.test.tsx +0 -471
  143. package/src/patient-registration/section/death-info/death-info-section.test.tsx +0 -64
  144. package/src/patient-registration/section/demographics/demographics-section.test.tsx +0 -83
  145. package/src/patient-registration/section/patient-relationships/relationships-section.test.tsx +0 -100
  146. package/src/patient-verification/client-registry-constants.ts +0 -13
  147. package/src/patient-verification/client-registry.component.tsx +0 -66
  148. package/src/patient-verification/client-registry.scss +0 -1
  149. package/src/patient-verification/utils.tsx +0 -56
  150. package/src/patient-verification/verification-modal.scss +0 -20
  151. package/src/patient-verification/verification.component.tsx +0 -48
  152. package/src/root.test.tsx +0 -32
  153. package/src/widgets/cancel-patient-edit.test.tsx +0 -27
  154. package/src/widgets/display-photo.component.tsx +0 -30
  155. package/src/widgets/display-photo.test.tsx +0 -37
  156. package/src/widgets/edit-patient-details-button.test.tsx +0 -41
  157. /package/dist/{784.js.LICENSE.txt → 41.js.LICENSE.txt} +0 -0
  158. /package/dist/{130.js.LICENSE.txt → 831.js.LICENSE.txt} +0 -0
  159. /package/dist/{255.js.LICENSE.txt → 876.js.LICENSE.txt} +0 -0
  160. /package/src/patient-registration/input/custom-input/identifier/{utils.test.ts → utils.testt.ts} +0 -0
  161. /package/src/widgets/{delete-identifier-confirmation-modal.test.tsx → delete-identifier-confirmation-modal.testt.tsx} +0 -0
@@ -0,0 +1,236 @@
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
+ ]
@@ -0,0 +1,11 @@
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' },
11
+ ];
@@ -0,0 +1,176 @@
1
+ import { type FetchResponse, openmrsFetch, showNotification, showToast, showSnackbar } from '@openmrs/esm-framework';
2
+ import { generateNUPIPayload, handleClientRegistryResponse } from './patient-verification-utils';
3
+ import useSWR from 'swr';
4
+ import useSWRImmutable from 'swr/immutable';
5
+ import {
6
+ type ConceptAnswers,
7
+ type ConceptResponse,
8
+ type FormValues,
9
+ } from '../patient-registration/patient-registration.types';
10
+
11
+ export function searchClientRegistry(
12
+ identifierType: string,
13
+ searchTerm: string,
14
+ token: string,
15
+ countryCode: string = 'KE',
16
+ ) {
17
+ const url = `https://afyakenyaapi.health.go.ke/partners/registry/search/${countryCode}/${identifierType}/${searchTerm}`;
18
+ return fetch(url, { headers: { Authorization: `Bearer ${token}` } }).then((r) => r.json());
19
+ }
20
+
21
+ export function savePatientToClientRegistry(formValues: FormValues) {
22
+ const createdRegistryPatient = generateNUPIPayload(formValues);
23
+ return fetch(`https://afyakenyaapi.health.go.ke/partners/registry`, {
24
+ headers: { Authorization: `Bearer ${formValues.token}`, 'Content-Type': 'application/json' },
25
+ method: 'POST',
26
+ body: JSON.stringify(createdRegistryPatient),
27
+ });
28
+ }
29
+
30
+ export async function handleSavePatientToClientRegistry(
31
+ formValues: FormValues,
32
+ setValues: (values: FormValues, shouldValidate?: boolean) => void,
33
+ inEditMode: boolean,
34
+ ) {
35
+ const mode = inEditMode ? 'edit' : 'new';
36
+ switch (mode) {
37
+ case 'edit': {
38
+ try {
39
+ const searchResponse = await searchClientRegistry(
40
+ 'national-id',
41
+ formValues.identifiers['nationalId'].identifierValue,
42
+ formValues.token,
43
+ );
44
+
45
+ // if client does not exists post client to registry
46
+ if (searchResponse?.clientExists === false) {
47
+ postToRegistry(formValues, setValues);
48
+ }
49
+ } catch (error) {
50
+ showSnackbar({
51
+ title: 'Client registry error',
52
+ subtitle: `${error}`,
53
+ timeoutInMs: 10000,
54
+ kind: 'error',
55
+ isLowContrast: true,
56
+ });
57
+ }
58
+ return;
59
+ }
60
+ case 'new': {
61
+ postToRegistry(formValues, setValues);
62
+ }
63
+ }
64
+ }
65
+
66
+ export function useConceptAnswers(conceptUuid: string): { data: Array<ConceptAnswers>; isLoading: boolean } {
67
+ const { data, error, isLoading } = useSWR<FetchResponse<ConceptResponse>, Error>(
68
+ `/ws/rest/v1/concept/${conceptUuid}`,
69
+ openmrsFetch,
70
+ );
71
+ if (error) {
72
+ showToast({
73
+ title: error.name,
74
+ description: error.message,
75
+ kind: 'error',
76
+ });
77
+ }
78
+ return { data: data?.data?.answers ?? [], isLoading };
79
+ }
80
+
81
+ const urlencoded = new URLSearchParams();
82
+ urlencoded.append('client_id', 'palladium.partner.client');
83
+ urlencoded.append('client_secret', '28f95b2a');
84
+ urlencoded.append('grant_type', 'client_credentials');
85
+ urlencoded.append('scope', 'DHP.Gateway DHP.Partners');
86
+
87
+ const swrFetcher = async (url) => {
88
+ const res = await fetch(url, {
89
+ method: 'POST',
90
+ body: urlencoded,
91
+ redirect: 'follow',
92
+ });
93
+
94
+ // If the status code is not in the range 200-299,
95
+ // we still try to parse and throw it.
96
+ if (!res.ok) {
97
+ const error = new Error('An error occurred while fetching the data.') as any;
98
+ // Attach extra info to the error object.
99
+ error.info = await res.json();
100
+ error.status = res.status;
101
+ throw error;
102
+ }
103
+
104
+ return res.json();
105
+ };
106
+
107
+ export function useGlobalProperties() {
108
+ const { data, isLoading, error } = useSWRImmutable(
109
+ `https://afyakenyaidentityapi.health.go.ke/connect/token`,
110
+ swrFetcher,
111
+ { refreshInterval: 864000 },
112
+ );
113
+ return { data: data, isLoading, error };
114
+ }
115
+
116
+ async function postToRegistry(
117
+ formValues: FormValues,
118
+ setValues: (values: FormValues, shouldValidate?: boolean) => void,
119
+ ) {
120
+ try {
121
+ const clientRegistryResponse = await savePatientToClientRegistry(formValues);
122
+ if (clientRegistryResponse.ok) {
123
+ const savedValues = await clientRegistryResponse.json();
124
+ const nupiIdentifier = {
125
+ ['nationalUniquePatientIdentifier']: {
126
+ identifierTypeUuid: 'cba702b9-4664-4b43-83f1-9ab473cbd64d',
127
+ identifierName: 'National Unique patient identifier',
128
+ identifierValue: savedValues['clientNumber'],
129
+ initialValue: savedValues['clientNumber'],
130
+ identifierUuid: undefined,
131
+ selectedSource: { uuid: '', name: '' },
132
+ preferred: false,
133
+ required: false,
134
+ },
135
+ };
136
+ setValues({ ...formValues, identifiers: { ...formValues.identifiers, ...nupiIdentifier } });
137
+ showToast({
138
+ title: 'Posted patient to client registry successfully',
139
+ description: `The patient has been saved to client registry`,
140
+ kind: 'success',
141
+ });
142
+ } else {
143
+ const responseError = await clientRegistryResponse.json();
144
+ const errorMessage = Object.values(responseError.errors ?? {})
145
+ .map((error: any) => error.join())
146
+ .toString();
147
+ setValues({
148
+ ...formValues,
149
+ attributes: {
150
+ ...formValues.attributes,
151
+ ['869f623a-f78e-4ace-9202-0bed481822f5']: 'Failed validation',
152
+ ['752a0331-5293-4aa5-bf46-4d51aaf2cdc5']: 'Failed',
153
+ },
154
+ });
155
+ showNotification({
156
+ title: responseError.title,
157
+ description: errorMessage,
158
+ kind: 'warning',
159
+ millis: 150000,
160
+ });
161
+ }
162
+ } catch (error) {
163
+ showNotification({ kind: 'error', title: 'NUPI Post failed', description: JSON.stringify(error) });
164
+ }
165
+ }
166
+
167
+ export const useFacilityName = (facilityCode) => {
168
+ const apiUrl = `/ws/rest/v1/kenyaemr/facilityName?facilityCode=${facilityCode}`;
169
+ const { data, error, isLoading } = useSWRImmutable<FetchResponse>(apiUrl, openmrsFetch);
170
+
171
+ return {
172
+ facilityName: data ? data?.data : null,
173
+ isLoading: isLoading,
174
+ isError: error,
175
+ };
176
+ };
@@ -0,0 +1,179 @@
1
+ import { showModal } from '@openmrs/esm-framework';
2
+ import { type FormikProps } from 'formik';
3
+ import { type ClientRegistryPatient, type RegistryPatient } from './verification-types';
4
+ import counties from './assets/counties.json';
5
+ import { type FormValues } from '../patient-registration/patient-registration.types';
6
+ import { capitalize } from 'lodash-es';
7
+
8
+ export function handleClientRegistryResponse(
9
+ clientResponse: ClientRegistryPatient,
10
+ props: FormikProps<FormValues>,
11
+ searchTerm: string,
12
+ ) {
13
+ if (clientResponse?.clientExists === false) {
14
+ const nupiIdentifiers = {
15
+ ['nationalId']: {
16
+ initialValue: searchTerm,
17
+ identifierUuid: undefined,
18
+ selectedSource: { uuid: '', name: '' },
19
+ preferred: false,
20
+ required: false,
21
+ identifierTypeUuid: '49af6cdc-7968-4abb-bf46-de10d7f4859f',
22
+ identifierName: 'National ID',
23
+ identifierValue: searchTerm,
24
+ },
25
+ };
26
+ const dispose = showModal('empty-client-registry-modal', {
27
+ onConfirm: () => {
28
+ props.setValues({ ...props.values, identifiers: { ...props.values.identifiers, ...nupiIdentifiers } });
29
+ dispose();
30
+ },
31
+ close: () => dispose(),
32
+ });
33
+ }
34
+
35
+ if (clientResponse?.clientExists) {
36
+ const {
37
+ client: {
38
+ middleName,
39
+ lastName,
40
+ firstName,
41
+ contact,
42
+ country,
43
+ countyOfBirth,
44
+ residence,
45
+ identifications,
46
+ gender,
47
+ dateOfBirth,
48
+ isAlive,
49
+ clientNumber,
50
+ educationLevel,
51
+ occupation,
52
+ maritalStatus,
53
+ },
54
+ } = clientResponse;
55
+
56
+ const nupiIdentifiers = {
57
+ ['nationalId']: {
58
+ initialValue: identifications !== undefined && identifications[0]?.identificationNumber,
59
+ identifierUuid: undefined,
60
+ selectedSource: { uuid: '', name: '' },
61
+ preferred: false,
62
+ required: false,
63
+ identifierTypeUuid: '58a47054-1359-11df-a1f1-0026b9348838',
64
+ identifierName: 'National ID',
65
+ identifierValue: identifications !== undefined && identifications[0]?.identificationNumber,
66
+ },
67
+
68
+ ['nationalUniquePatientIdentifier']: {
69
+ identifierTypeUuid: 'cba702b9-4664-4b43-83f1-9ab473cbd64d',
70
+ identifierName: 'National Unique patient identifier',
71
+ identifierValue: clientNumber,
72
+ initialValue: clientNumber,
73
+ identifierUuid: undefined,
74
+ selectedSource: { uuid: '', name: '' },
75
+ preferred: false,
76
+ required: false,
77
+ },
78
+ };
79
+
80
+ const dispose = showModal('confirm-client-registry-modal', {
81
+ onConfirm: () => {
82
+ props.setValues({
83
+ ...props.values,
84
+ familyName: lastName,
85
+ middleName: middleName,
86
+ givenName: firstName,
87
+ gender: clientResponse.client.gender,
88
+ birthdate: new Date(dateOfBirth),
89
+ isDead: !isAlive,
90
+ attributes: {
91
+ 'b2c38640-2603-4629-aebd-3b54f33f1e3a': contact?.primaryPhone,
92
+ '94614350-84c8-41e0-ac29-86bc107069be': contact?.secondaryPhone,
93
+ 'b8d0b331-1d2d-4a9a-b741-1816f498bdb6': contact?.emailAddress ?? '',
94
+ },
95
+ address: {
96
+ address1: residence?.address,
97
+ address2: '',
98
+ address4: capitalize(residence?.ward ?? ''),
99
+ cityVillage: residence?.village,
100
+ stateProvince: capitalize(residence?.subCounty ?? ''),
101
+ countyDistrict: counties.find((county) => county.code === parseInt(residence?.county))?.name,
102
+ country: 'Kenya',
103
+ postalCode: residence?.address,
104
+ },
105
+ identifiers: { ...props.values.identifiers, ...nupiIdentifiers },
106
+ obs: {
107
+ '1054AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA':
108
+ props.values.concepts.find((concept) =>
109
+ concept.display?.toLowerCase()?.includes(clientResponse.client.maritalStatus?.toLowerCase()),
110
+ )?.uuid ?? '',
111
+ 'a89e48ae-1350-11df-a1f1-0026b9348838':
112
+ props.values.concepts.find((concept) =>
113
+ concept.display?.toLowerCase()?.includes(clientResponse.client.educationLevel?.toLowerCase()),
114
+ )?.uuid ?? '',
115
+ '1542AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA':
116
+ clientResponse.client.occupation === undefined || clientResponse.client.occupation === null
117
+ ? '1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
118
+ : props.values.concepts.find(
119
+ (concept) => concept.display?.toLowerCase() === clientResponse.client.occupation?.toLowerCase(),
120
+ )?.uuid ?? '5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
121
+ },
122
+ });
123
+ dispose();
124
+ },
125
+ close: () => dispose(),
126
+ patient: clientResponse.client,
127
+ });
128
+ }
129
+ }
130
+
131
+ export function generateNUPIPayload(formValues: FormValues): RegistryPatient {
132
+ const educationLevel = formValues.concepts.find(
133
+ (concept) => concept.uuid === formValues.obs['a89e48ae-1350-11df-a1f1-0026b9348838'],
134
+ );
135
+ const occupation = formValues.concepts.find(
136
+ (concept) => concept.uuid === formValues.obs['1542AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'],
137
+ );
138
+ const maritalStatus = formValues.concepts.find(
139
+ (concept) => concept.uuid === formValues.obs['a899a9f2-1350-11df-a1f1-0026b9348838'],
140
+ );
141
+
142
+ let createRegistryPatient: RegistryPatient = {
143
+ firstName: formValues?.givenName,
144
+ middleName: formValues?.middleName,
145
+ lastName: formValues?.familyName,
146
+ gender: formValues?.gender === 'Male' ? 'male' : 'female',
147
+ dateOfBirth: new Date(formValues.birthdate).toISOString(),
148
+ isAlive: !formValues.isDead,
149
+ residence: {
150
+ county: `0${counties.find((county) => county.name.includes(formValues.address['countyDistrict']))?.code}`,
151
+ subCounty: formValues.address['stateProvince']?.toLocaleLowerCase(),
152
+ ward: formValues.address['address4']?.toLocaleLowerCase(),
153
+ village: formValues.address['cityVillage'],
154
+ landmark: formValues.address['address2'],
155
+ address: formValues.address['postalCode'],
156
+ },
157
+ nextOfKins: [],
158
+ contact: {
159
+ primaryPhone: formValues.attributes['b2c38640-2603-4629-aebd-3b54f33f1e3a'],
160
+ secondaryPhone: formValues.attributes['94614350-84c8-41e0-ac29-86bc107069be'],
161
+ emailAddress: formValues.attributes['b8d0b331-1d2d-4a9a-b741-1816f498bdb6'],
162
+ },
163
+ country: 'KE',
164
+ countyOfBirth: `0${counties.find((county) => county.name.includes(formValues.address['countyDistrict']))?.code}`,
165
+ educationLevel: educationLevel?.display?.toLowerCase() ?? '',
166
+ religion: '',
167
+ occupation: occupation?.display?.toLowerCase() ?? '',
168
+ maritalStatus: maritalStatus?.display?.toLowerCase() ?? '',
169
+ originFacilityKmflCode: '',
170
+ nascopCCCNumber: '',
171
+ identifications: [
172
+ {
173
+ identificationType: 'national-id',
174
+ identificationNumber: formValues.identifiers['nationalId']?.identifierValue,
175
+ },
176
+ ],
177
+ };
178
+ return createRegistryPatient;
179
+ }