@ampath/esm-dha-workflow-app 4.0.0-next.4 → 4.0.0-next.41

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 (167) hide show
  1. package/dist/104.js +2 -0
  2. package/dist/104.js.LICENSE.txt +9 -0
  3. package/dist/104.js.map +1 -0
  4. package/dist/15.js +1 -0
  5. package/dist/15.js.map +1 -0
  6. package/dist/246.js +2 -0
  7. package/dist/246.js.LICENSE.txt +54 -0
  8. package/dist/246.js.map +1 -0
  9. package/dist/327.js +1 -0
  10. package/dist/327.js.map +1 -0
  11. package/dist/339.js +1 -0
  12. package/dist/339.js.map +1 -0
  13. package/dist/709.js +1 -0
  14. package/dist/709.js.map +1 -0
  15. package/dist/710.js +2 -0
  16. package/dist/710.js.map +1 -0
  17. package/dist/729.js +1 -0
  18. package/dist/729.js.map +1 -0
  19. package/dist/752.js +1 -0
  20. package/dist/752.js.map +1 -0
  21. package/dist/833.js +1 -0
  22. package/dist/833.js.map +1 -0
  23. package/dist/91.js +1 -1
  24. package/dist/91.js.map +1 -1
  25. package/dist/93.js +1 -0
  26. package/dist/93.js.map +1 -0
  27. package/dist/938.js +1 -0
  28. package/dist/938.js.map +1 -0
  29. package/dist/esm-dha-workflow-app.js +1 -0
  30. package/dist/{openmrs-esm-home-app.js.buildmanifest.json → esm-dha-workflow-app.js.buildmanifest.json} +294 -55
  31. package/dist/{openmrs-esm-home-app.js.map → esm-dha-workflow-app.js.map} +1 -1
  32. package/dist/main.js +1 -1
  33. package/dist/main.js.map +1 -1
  34. package/dist/routes.json +1 -1
  35. package/package.json +3 -3
  36. package/src/accounting/accounting.component.tsx +13 -0
  37. package/src/appointments/appointments.component.tsx +13 -0
  38. package/src/bookings/daily/daily-bookings.component.scss +38 -0
  39. package/src/bookings/daily/daily-bookings.component.tsx +138 -0
  40. package/src/bookings/daily/daily-bookings.resource.ts +27 -0
  41. package/src/bookings/daily/filters/daily-bookings-filter.component.scss +15 -0
  42. package/src/bookings/daily/filters/daily-bookings-filter.component.tsx +80 -0
  43. package/src/bookings/daily/patient-list/daily-bookings-patient-list.component.tsx +97 -0
  44. package/src/bookings/types/index.ts +68 -0
  45. package/src/config-schema.ts +132 -32
  46. package/src/dashboard/dashboard.component.scss +7 -0
  47. package/src/dashboard/dashboard.component.tsx +63 -0
  48. package/src/dashboard/overview/overview.component.scss +70 -0
  49. package/src/dashboard/overview/overview.component.tsx +107 -0
  50. package/src/dashboard/patient-list/patient-list.component.tsx +41 -0
  51. package/src/hooks/useActions.ts +165 -0
  52. package/src/index.ts +23 -2
  53. package/src/laboratory/laboratory.component.tsx +13 -0
  54. package/src/left-panel/left-panel.component.tsx +20 -0
  55. package/src/left-panel/left-panel.scss +42 -0
  56. package/src/mch/queues/consultation/mch-consultation.tsx +18 -0
  57. package/src/mch/queues/triage/mch-triage.tsx +15 -0
  58. package/src/modals/sign-off-modal.scss +7 -0
  59. package/src/modals/sign-off-modal.tsx +52 -0
  60. package/src/mortuary/mortuary.component.tsx +13 -0
  61. package/src/pharmacy/pharmacy.component.tsx +13 -0
  62. package/src/registry/client-details/client-details.tsx +40 -0
  63. package/src/registry/modal/client-details-modal/client-details-modal.scss +28 -0
  64. package/src/registry/modal/client-details-modal/client-details-modal.tsx +81 -0
  65. package/src/registry/modal/otp-verification-modal/otp-verification-modal.scss +31 -0
  66. package/src/registry/modal/otp-verification-modal/otp-verification-modal.tsx +186 -0
  67. package/src/registry/modal/send-to-triage/send-to-triage.modal.scss +34 -0
  68. package/src/registry/modal/send-to-triage/send-to-triage.modal.tsx +302 -0
  69. package/src/registry/payment-details/payment-options/payment-options.tsx +21 -0
  70. package/src/registry/registry.component.scss +83 -0
  71. package/src/registry/registry.component.tsx +397 -2
  72. package/src/registry/registry.resource.ts +60 -0
  73. package/src/registry/types/index.ts +309 -0
  74. package/src/registry/utils/error-handler.ts +37 -0
  75. package/src/registry/utils/format-dependant-display-data.ts +8 -0
  76. package/src/registry/utils/hie-adapter.ts +56 -0
  77. package/src/registry/utils/hie-client-adapter.ts +309 -0
  78. package/src/registry/utils/mask-data.ts +21 -0
  79. package/src/resources/hie-amrs-automatic-registration.service.ts +16 -0
  80. package/src/resources/identifier-types.ts +27 -0
  81. package/src/resources/patient-resource.ts +62 -0
  82. package/src/resources/patient-search.resource.ts +22 -0
  83. package/src/resources/queue.resource.ts +60 -0
  84. package/src/resources/visit.resource.ts +38 -0
  85. package/src/root.component.tsx +42 -30
  86. package/src/root.scss +5 -9
  87. package/src/routes.json +43 -4
  88. package/src/service-queues/action-button.component.tsx +34 -0
  89. package/src/service-queues/action-overflow-menu-item.component.tsx +34 -0
  90. package/src/service-queues/consultation/consultation.component.scss +7 -0
  91. package/src/service-queues/consultation/consultation.component.tsx +15 -0
  92. package/src/service-queues/metrics/metrics-cards/attended-patients.extension.tsx +38 -0
  93. package/src/service-queues/metrics/metrics-cards/metrics-card.component.tsx +86 -0
  94. package/src/service-queues/metrics/metrics-cards/metrics-card.scss +106 -0
  95. package/src/service-queues/metrics/metrics-cards/waiting-patients.extension.tsx +34 -0
  96. package/src/service-queues/metrics/metrics-container.component.tsx +23 -0
  97. package/src/service-queues/metrics/metrics-container.scss +36 -0
  98. package/src/service-queues/metrics/metrics.resource.ts +65 -0
  99. package/src/service-queues/modals/move/move-patient.component.scss +35 -0
  100. package/src/service-queues/modals/move/move-patient.component.tsx +138 -0
  101. package/src/service-queues/modals/serve/serve-patient.comppnent.scss +0 -0
  102. package/src/service-queues/modals/serve/serve-patient.comppnent.tsx +80 -0
  103. package/src/service-queues/modals/sign-off/sign-off.modal.scss +0 -0
  104. package/src/service-queues/modals/sign-off/sign-off.modal.tsx +79 -0
  105. package/src/service-queues/modals/transition/transition-patient.component.scss +0 -0
  106. package/src/service-queues/modals/transition/transition-patient.component.tsx +122 -0
  107. package/src/service-queues/queue-list/queue-list.component.scss +19 -0
  108. package/src/service-queues/queue-list/queue-list.component.tsx +169 -0
  109. package/src/service-queues/queue-room.component.tsx +39 -0
  110. package/src/service-queues/room/room.component.tsx +58 -0
  111. package/src/service-queues/service-queue/service-queue.component.scss +14 -0
  112. package/src/service-queues/service-queue/service-queue.component.tsx +245 -0
  113. package/src/service-queues/service-queue/stats/stat-card/stat-card.component.scss +10 -0
  114. package/src/service-queues/service-queue/stats/stat-card/stat-card.component.tsx +23 -0
  115. package/src/service-queues/service-queue/stats/stat-details/stat-details.component.scss +7 -0
  116. package/src/service-queues/service-queue/stats/stat-details/stat-details.component.tsx +34 -0
  117. package/src/service-queues/service-queue.scss +27 -0
  118. package/src/service-queues/service-queue.tsx +31 -0
  119. package/src/service-queues/service-queues.resource.ts +177 -0
  120. package/src/service-queues/service.resource.ts +28 -0
  121. package/src/shared/constants/civil-status.ts +29 -0
  122. package/src/shared/constants/concepts.ts +30 -0
  123. package/src/shared/constants/index.ts +1 -0
  124. package/src/shared/constants/person-attributes.ts +33 -0
  125. package/src/shared/services/location.resource.ts +9 -0
  126. package/src/shared/ui/otp-input/otp-input.component.scss +14 -0
  127. package/src/shared/ui/otp-input/otp-input.component.tsx +90 -0
  128. package/src/shared/ui/timer/timer.component.scss +5 -0
  129. package/src/shared/ui/timer/timer.component.tsx +40 -0
  130. package/src/shared/utils/get-base-url.ts +17 -0
  131. package/src/side-nav-menu/nav-link-config.ts +82 -0
  132. package/src/side-nav-menu/nav-links.tsx +31 -11
  133. package/src/triage/metrics/attended-patients.extension.tsx +42 -0
  134. package/src/triage/metrics/metrics.scss +36 -0
  135. package/src/triage/metrics/triage-metrics.component.tsx +21 -0
  136. package/src/triage/metrics/waiting-patients.extension.tsx +39 -0
  137. package/src/triage/room/room.scss +29 -0
  138. package/src/triage/triage.component.tsx +15 -0
  139. package/src/triage/triage.resource.ts +19 -0
  140. package/src/triage/types.ts +16 -0
  141. package/src/types/types.ts +128 -0
  142. package/dist/561.js +0 -2
  143. package/dist/561.js.map +0 -1
  144. package/dist/70.js +0 -1
  145. package/dist/70.js.map +0 -1
  146. package/dist/731.js +0 -2
  147. package/dist/731.js.LICENSE.txt +0 -39
  148. package/dist/731.js.map +0 -1
  149. package/dist/819.js +0 -1
  150. package/dist/819.js.map +0 -1
  151. package/dist/openmrs-esm-home-app.js +0 -1
  152. package/src/boxes/extensions/blue-box.component.tsx +0 -15
  153. package/src/boxes/extensions/box.scss +0 -23
  154. package/src/boxes/extensions/brand-box.component.tsx +0 -15
  155. package/src/boxes/extensions/red-box.component.tsx +0 -15
  156. package/src/boxes/slot/boxes.component.tsx +0 -25
  157. package/src/boxes/slot/boxes.scss +0 -29
  158. package/src/greeter/greeter.component.tsx +0 -42
  159. package/src/greeter/greeter.scss +0 -20
  160. package/src/greeter/greeter.test.tsx +0 -28
  161. package/src/patient-getter/patient-getter.component.tsx +0 -40
  162. package/src/patient-getter/patient-getter.resource.ts +0 -39
  163. package/src/patient-getter/patient-getter.scss +0 -16
  164. package/src/patient-getter/patient-getter.test.tsx +0 -40
  165. package/src/resources/resources.component.tsx +0 -56
  166. package/src/resources/resources.scss +0 -68
  167. /package/dist/{561.js.LICENSE.txt → 710.js.LICENSE.txt} +0 -0
@@ -0,0 +1,309 @@
1
+ import { type Location, type Patient } from '@openmrs/esm-framework';
2
+
3
+ export type IdentifierType = 'National ID' | 'Alien ID' | 'Passport' | 'Mandate Number' | 'Refugee ID';
4
+
5
+ export const IDENTIFIER_TYPES: IdentifierType[] = [
6
+ 'National ID',
7
+ 'Alien ID',
8
+ 'Passport',
9
+ 'Mandate Number',
10
+ 'Refugee ID',
11
+ ];
12
+
13
+ export enum OtpStatus {
14
+ Draft = 'DRAFT',
15
+ Sent = 'SENT',
16
+ Verified = 'VERIFIED',
17
+ }
18
+
19
+ export interface ValidateCustomOtpResponse {
20
+ message: string;
21
+ isValid?: boolean;
22
+ }
23
+
24
+ export type ClientRegistrySearchRequest = {
25
+ identificationNumber: string | number;
26
+ identificationType: string;
27
+ locationUuid: string;
28
+ };
29
+
30
+ export interface RequestCustomOtpResponse {
31
+ message: string;
32
+ sessionId: string;
33
+ maskedPhone: string;
34
+ }
35
+
36
+ export interface ValidateHieCustomOtpDto {
37
+ sessionId: string;
38
+ otp: number | string;
39
+ locationUuid: string;
40
+ }
41
+
42
+ export interface ValidateCustomOtpResponse {
43
+ message: string;
44
+ isValid?: boolean;
45
+ }
46
+
47
+ export type RequestCustomOtpDto = {
48
+ identificationNumber: string | number;
49
+ identificationType: string;
50
+ locationUuid: string;
51
+ };
52
+
53
+ export interface RequestCustomOtpResponse {
54
+ message: string;
55
+ sessionId: string;
56
+ maskedPhone: string;
57
+ }
58
+
59
+ export interface ValidateHieCustomOtpDto {
60
+ sessionId: string;
61
+ otp: number | string;
62
+ locationUuid: string;
63
+ }
64
+
65
+ export enum HieIdentificationType {
66
+ NationalID = 'National ID',
67
+ SHANumber = 'SHA Number',
68
+ HouseholdNumber = 'Household Number',
69
+ RefugeeID = 'Refugee ID',
70
+ AlienID = 'Alien ID',
71
+ MandateNumber = 'Mandate Number',
72
+ Cr = 'id',
73
+ TemporaryDependantID = 'Temporary Dependant ID',
74
+ BirthCertificate = 'Birth Certificate',
75
+ }
76
+
77
+ export interface HieIdentifications {
78
+ identification_number: string;
79
+ identification_type: HieIdentificationType;
80
+ }
81
+
82
+ export interface HieDependant {
83
+ date_added: string;
84
+ relationship: string;
85
+ total: number;
86
+ result: HieClient[];
87
+ }
88
+
89
+ export interface AlternateContact {
90
+ contact_type: string;
91
+ contact_id: string;
92
+ contact_name: string;
93
+ relationship: string;
94
+ remarks: string;
95
+ }
96
+
97
+ export interface HieClient {
98
+ resourceType: string;
99
+ id: string;
100
+ meta: {
101
+ versionId: string;
102
+ creationTime: string;
103
+ lastUpdated: string;
104
+ source: string;
105
+ };
106
+ originSystem: {
107
+ system: string;
108
+ record_id: string;
109
+ };
110
+ title: string;
111
+ first_name: string;
112
+ middle_name: string;
113
+ last_name: string;
114
+ gender: string;
115
+ date_of_birth: string;
116
+ place_of_birth: string;
117
+ person_with_disability: number;
118
+ citizenship: string;
119
+ kra_pin: string;
120
+ preferred_primary_care_network: string;
121
+ employment_type: string;
122
+ domestic_worker_type: string;
123
+ civil_status: string;
124
+ identification_type: HieIdentificationType;
125
+ identification_number: string;
126
+ other_identifications: HieIdentifications[];
127
+ dependants: HieDependant[];
128
+ is_alive: number;
129
+ deceased_datetime: string;
130
+ phone: string;
131
+ biometrics_verified: number;
132
+ biometrics_score: number;
133
+ email: string;
134
+ country: string;
135
+ county: string;
136
+ sub_county: string;
137
+ ward: string;
138
+ village_estate: string;
139
+ building_house_no: string;
140
+ latitude: string;
141
+ longitude: string;
142
+ province_state_country: string;
143
+ zip_code: string;
144
+ identification_residence: string;
145
+ employer_name: string;
146
+ employer_pin: string;
147
+ disability_category: string;
148
+ disability_subcategory: string;
149
+ disability_cause: string;
150
+ in_lawful_custody: string;
151
+ admission_remand_number: string;
152
+ document_uploads: any[];
153
+ alternative_contacts: AlternateContact[];
154
+ gross_income: number;
155
+ gross_income_currency: string;
156
+ postal_address: string;
157
+ estimated_contribution: number;
158
+ estimated_annual_contribution: number;
159
+ city: string;
160
+ id_serial: string;
161
+ learning_institution_code: string;
162
+ learning_institution_name: string;
163
+ grade_level: string;
164
+ admission_number: string;
165
+ expected_year_of_graduation: string;
166
+ unconfirmed_dependants: HieDependant[];
167
+ is_agent: number;
168
+ agent_id: string;
169
+ }
170
+
171
+ export type PatientSearchResponse = {
172
+ results: Patient[];
173
+ totalCount: number;
174
+ };
175
+
176
+ export type QueuePriority = {
177
+ uuid: string;
178
+ display: string;
179
+ };
180
+ export type QueueStatus = {
181
+ uuid: string;
182
+ display: string;
183
+ };
184
+ export type ServiceQueue = {
185
+ uuid: string;
186
+ display: string;
187
+ name: string;
188
+ description: string;
189
+ service: {
190
+ uuid: string;
191
+ display: string;
192
+ };
193
+ allowedPriorities: QueuePriority[];
194
+ allowedStatuses: QueueStatus[];
195
+ location: Location;
196
+ };
197
+
198
+ export type ServiceQueueApiResponse = {
199
+ results: ServiceQueue[];
200
+ };
201
+
202
+ export type QueueEntryDto = {
203
+ visit: {
204
+ uuid: string;
205
+ };
206
+ queueEntry: {
207
+ status: {
208
+ uuid: string;
209
+ };
210
+ priority: {
211
+ uuid: string;
212
+ };
213
+ queue: {
214
+ uuid: string;
215
+ };
216
+ patient: {
217
+ uuid: string;
218
+ };
219
+ startedAt: string;
220
+ sortWeight: number;
221
+ };
222
+ };
223
+
224
+ export type CreateVisitDto = {
225
+ visitType: string;
226
+ location: string;
227
+ startDatetime: null | string;
228
+ stopDatetime: null | string;
229
+ patient: string;
230
+ };
231
+
232
+ export type EndVisitDto = {
233
+ stopDatetime: string;
234
+ };
235
+
236
+ export interface GlobalError {
237
+ code: string;
238
+ message: string;
239
+ }
240
+
241
+ export interface AmrsErrorResponse {
242
+ message: string;
243
+ error: {
244
+ error: {
245
+ message: string;
246
+ code: string;
247
+ globalErrors?: GlobalError[];
248
+ fieldErrors?: any;
249
+ };
250
+ };
251
+ }
252
+
253
+ export interface CreatePersonDto {
254
+ gender?: string;
255
+ birthdate?: string;
256
+ dead?: boolean;
257
+ deathDate?: string;
258
+ names?: {
259
+ givenName?: string;
260
+ middleName?: string;
261
+ familyName?: string;
262
+ }[];
263
+ addresses?: {
264
+ country?: string;
265
+ address1?: string;
266
+ address2?: string;
267
+ address4?: string;
268
+ address7?: string;
269
+ address10?: string;
270
+ countyDistrict?: string;
271
+ stateProvince?: string;
272
+ cityVillage?: string;
273
+ longitude?: string;
274
+ latitude?: string;
275
+ }[];
276
+ attributes?: {
277
+ value: string | number;
278
+ attributeType: string;
279
+ }[];
280
+ }
281
+
282
+ export type CreatePatientDto = {
283
+ person: CreatePersonDto;
284
+ identifiers?: any;
285
+ };
286
+
287
+ export type QueueEntryResult = {
288
+ name: string;
289
+ queue_entry_id: number;
290
+ priority_comment: string;
291
+ wait_time_in_min: number;
292
+ queue_entry_uuid: string;
293
+ service_uuid: string;
294
+ location_id: number;
295
+ location: string;
296
+ service: number;
297
+ queue_id: number;
298
+ queue_room: string;
299
+ priority: string;
300
+ patient_id: number;
301
+ visit_id: number;
302
+ patient_uuid: string;
303
+ family_name: string;
304
+ given_name: string;
305
+ middle_name: string;
306
+ status: string;
307
+ visit_uuid: string;
308
+ queue_coming_from: string;
309
+ };
@@ -0,0 +1,37 @@
1
+ import { type AmrsErrorResponse } from '../types';
2
+
3
+ export function generateErrorMessage(error: any): string[] {
4
+ const errors: string[] = [];
5
+ return errors;
6
+ }
7
+
8
+ export function getErrorMessages(error: AmrsErrorResponse) {
9
+ const errors = [];
10
+ if (error && error.error) {
11
+ if (error.error.error) {
12
+ const globalErrors = error.error.error.globalErrors || null;
13
+ if (globalErrors) {
14
+ for (const err of globalErrors) {
15
+ errors.push(err.message);
16
+ }
17
+ }
18
+ } else if (error.error) {
19
+ if (error.error['globalErrors']) {
20
+ const globalErrors = error.error['globalErrors'] || null;
21
+ if (globalErrors) {
22
+ for (const err of globalErrors) {
23
+ errors.push(err.message);
24
+ }
25
+ }
26
+ } else if (error.error['message']) {
27
+ errors.push(error.error['message']);
28
+ }
29
+ } else {
30
+ errors.push(
31
+ error.error.error.message ||
32
+ 'An error occurred while creating the patient. Please try again or contact support',
33
+ );
34
+ }
35
+ }
36
+ return errors;
37
+ }
@@ -0,0 +1,8 @@
1
+ import { type HieClient } from '../types';
2
+ import { maskExceptFirstAndLast } from './mask-data';
3
+
4
+ export function formatDependantDisplayData(dependant: HieClient, relationship: string): string {
5
+ const stringData = `${dependant.first_name} ${maskExceptFirstAndLast(dependant.middle_name)} (${dependant.gender}) (DOB: ${dependant.date_of_birth}) (${relationship}) (CR: ${dependant.id})`;
6
+
7
+ return stringData;
8
+ }
@@ -0,0 +1,56 @@
1
+ import { type HieIdentifications, type HieClient } from '../types';
2
+
3
+ const clientDatailsFields = [
4
+ 'id',
5
+ 'other_identifications',
6
+ 'first_name',
7
+ 'middle_name',
8
+ 'last_name',
9
+ 'gender',
10
+ 'date_of_birth',
11
+ 'is_alive',
12
+ 'deceased_datetime',
13
+ 'phone',
14
+ 'email',
15
+ 'civil_status',
16
+ 'place_of_birth',
17
+ 'citizenship',
18
+ 'country',
19
+ 'county',
20
+ 'sub_county',
21
+ 'ward',
22
+ 'village_estate',
23
+ 'longitude',
24
+ 'latitude',
25
+ 'identification_type',
26
+ ];
27
+
28
+ export function generateHieClientDetails(hieClient: HieClient) {
29
+ let data = {};
30
+ Object.keys(hieClient)
31
+ .filter((key) => {
32
+ return clientDatailsFields.includes(key);
33
+ })
34
+ .forEach((key) => {
35
+ if (key === 'other_identifications') {
36
+ const otherIds = generateOtherIdentifications(hieClient[key]);
37
+ data = {
38
+ ...data,
39
+ ...otherIds,
40
+ };
41
+ } else if (key === 'identification_type') {
42
+ data[hieClient['identification_type']] = hieClient.identification_number;
43
+ } else {
44
+ const value = hieClient[key];
45
+ data[key] = value;
46
+ }
47
+ });
48
+ return data;
49
+ }
50
+ function generateOtherIdentifications(hieIdentifications: HieIdentifications[]) {
51
+ const other = {};
52
+ hieIdentifications.forEach((id) => {
53
+ other[id.identification_type] = id.identification_number;
54
+ });
55
+ return other;
56
+ }
@@ -0,0 +1,309 @@
1
+ import { IdentifierTypesUuids } from '../../resources/identifier-types';
2
+ import { CivilStatusUids } from '../../shared/constants/civil-status';
3
+ import { PersonAttributeTypeUuids } from '../../shared/constants/person-attributes';
4
+ import {
5
+ type AlternateContact,
6
+ type CreatePersonDto,
7
+ type HieClient,
8
+ type HieIdentifications,
9
+ HieIdentificationType,
10
+ } from '../types';
11
+
12
+ const clientDatailsFields = [
13
+ 'id',
14
+ 'other_identifications',
15
+ 'first_name',
16
+ 'middle_name',
17
+ 'last_name',
18
+ 'gender',
19
+ 'date_of_birth',
20
+ 'is_alive',
21
+ 'deceased_datetime',
22
+ 'phone',
23
+ 'email',
24
+ 'civil_status',
25
+ 'place_of_birth',
26
+ 'citizenship',
27
+ 'country',
28
+ 'county',
29
+ 'sub_county',
30
+ 'ward',
31
+ 'village_estate',
32
+ 'longitude',
33
+ 'latitude',
34
+ 'identification_type',
35
+ ];
36
+
37
+ const nameFields = ['first_name', 'middle_name', 'last_name'];
38
+ const otherPersonFields = ['gender', 'date_of_birth', 'is_alive', 'deceased_datetime'];
39
+ const attributeFields = ['phone', 'email', 'civil_status', 'place_of_birth', 'citizenship'];
40
+ const addressFields = ['country', 'county', 'sub_county', 'ward', 'village_estate', 'longitude', 'latitude'];
41
+ const otherFields = ['gender', 'date_of_birth'];
42
+ const identifierFields = [
43
+ HieIdentificationType.Cr,
44
+ HieIdentificationType.SHANumber,
45
+ HieIdentificationType.HouseholdNumber,
46
+ HieIdentificationType.RefugeeID,
47
+ HieIdentificationType.MandateNumber,
48
+ HieIdentificationType.AlienID,
49
+ HieIdentificationType.NationalID,
50
+ HieIdentificationType.TemporaryDependantID,
51
+ ];
52
+ const hieAmrsSyncFields = [
53
+ ...identifierFields,
54
+ ...nameFields,
55
+ ...otherPersonFields,
56
+ ...attributeFields,
57
+ ...addressFields,
58
+ ];
59
+
60
+ export function generateHieClientDetails(hieClient: HieClient) {
61
+ let data = {};
62
+ Object.keys(hieClient)
63
+ .filter((key) => {
64
+ return clientDatailsFields.includes(key);
65
+ })
66
+ .forEach((key) => {
67
+ if (key === 'other_identifications') {
68
+ const otherIds = generateOtherIdentifications(hieClient[key]);
69
+ data = {
70
+ ...data,
71
+ ...otherIds,
72
+ };
73
+ } else if (key === 'identification_type') {
74
+ data[hieClient['identification_type']] = hieClient.identification_number;
75
+ } else {
76
+ const value = hieClient[key];
77
+ data[key] = value;
78
+ }
79
+ });
80
+ return data;
81
+ }
82
+ function generateOtherIdentifications(hieIdentifications: HieIdentifications[]) {
83
+ const other = {};
84
+ hieIdentifications.forEach((id) => {
85
+ other[id.identification_type] = id.identification_number;
86
+ });
87
+ return other;
88
+ }
89
+
90
+ export function generateAmrsPersonPayload(hieClient: HieClient): CreatePersonDto {
91
+ const createPersonPayload: CreatePersonDto = {};
92
+ const namesAttribute = {};
93
+ const addresses = {};
94
+ let attributes = [];
95
+ hieAmrsSyncFields.forEach((d) => {
96
+ if (d === 'first_name') {
97
+ namesAttribute['givenName'] = hieClient.first_name;
98
+ }
99
+ if (d === 'middle_name') {
100
+ namesAttribute['middleName'] = hieClient.middle_name;
101
+ }
102
+ if (d === 'last_name') {
103
+ namesAttribute['familyName'] = hieClient.last_name;
104
+ }
105
+ if (d === 'gender') {
106
+ createPersonPayload['gender'] = hieClient.gender === 'Male' ? 'M' : 'F';
107
+ }
108
+ if (d === 'date_of_birth') {
109
+ createPersonPayload['birthdate'] = hieClient.date_of_birth;
110
+ createPersonPayload['birthdateEstimated'] = false;
111
+ }
112
+ if (d === 'is_alive') {
113
+ createPersonPayload['dead'] = hieClient.is_alive === 0 ? true : false;
114
+ }
115
+ if (d === 'deceased_datetime') {
116
+ if (hieClient.deceased_datetime.length > 0) {
117
+ createPersonPayload['deathDate'] = hieClient.deceased_datetime;
118
+ }
119
+ }
120
+ if (d === 'country' && hieClient.country.length > 0) {
121
+ addresses['country'] = hieClient.country;
122
+ addresses['address1'] = hieClient.country;
123
+ }
124
+ if (d === 'place_of_birth' && hieClient.place_of_birth.length > 0) {
125
+ addresses['address10'] = hieClient.place_of_birth;
126
+ }
127
+ if (d === 'county' && hieClient.county.length > 0) {
128
+ addresses['countyDistrict'] = hieClient.county;
129
+ }
130
+ if (d === 'sub_county' && hieClient.sub_county.length > 0) {
131
+ addresses['address2'] = hieClient.sub_county;
132
+ addresses['stateProvince'] = hieClient.sub_county;
133
+ }
134
+ if (d === 'ward' && hieClient.sub_county.length > 0) {
135
+ addresses['address7'] = hieClient.sub_county;
136
+ addresses['address4'] = hieClient.sub_county;
137
+ }
138
+ if (d === 'village_estate' && hieClient.village_estate.length > 0) {
139
+ addresses['cityVillage'] = hieClient.village_estate;
140
+ }
141
+ if (d === 'longitude' && hieClient.longitude.length > 0) {
142
+ addresses['longitude'] = hieClient.longitude;
143
+ }
144
+ if (d === 'latitude' && hieClient.latitude.length > 0) {
145
+ addresses['latitude'] = hieClient.latitude;
146
+ }
147
+ if (d === 'place_of_birth' && hieClient.place_of_birth.length > 0) {
148
+ attributes.push({
149
+ value: hieClient.place_of_birth,
150
+ attributeType: PersonAttributeTypeUuids.PLACE_OF_BIRTH_UUID,
151
+ });
152
+ }
153
+ if (d === 'phone' && hieClient.phone.length > 0) {
154
+ attributes.push({
155
+ value: hieClient.phone,
156
+ attributeType: PersonAttributeTypeUuids.CONTACT_PHONE_NUMBER_UUID,
157
+ });
158
+ }
159
+ if (d === 'email' && hieClient.email.length > 0) {
160
+ attributes.push({
161
+ value: hieClient.email,
162
+ attributeType: PersonAttributeTypeUuids.CONTACT_EMAIL_ADDRESS_UUID,
163
+ });
164
+ }
165
+ if (d === 'civil_status' && hieClient.civil_status.length > 0) {
166
+ attributes.push({
167
+ value: getAmrsConceptUuidFromField(hieClient.civil_status),
168
+ attributeType: PersonAttributeTypeUuids.CIVIL_STATUS_UUID,
169
+ });
170
+ }
171
+ if (d === 'id' && hieClient.id) {
172
+ attributes.push({
173
+ value: hieClient.id,
174
+ attributeType: PersonAttributeTypeUuids.CLIENT_REGISTRY_ID_UUID,
175
+ });
176
+ }
177
+ if (d === 'citizenship' && hieClient.citizenship) {
178
+ attributes.push({
179
+ value: hieClient.citizenship,
180
+ attributeType: PersonAttributeTypeUuids.CITIZENSHIP_UUID,
181
+ });
182
+ }
183
+ });
184
+ // Add next of kin details
185
+ const nextOfKinAndAlternativeAttributes = generateNextOfKinAndAlternateContactDetails(hieClient.alternative_contacts);
186
+ attributes = [...attributes, ...nextOfKinAndAlternativeAttributes];
187
+ if (Object.keys(namesAttribute).length > 0) {
188
+ createPersonPayload['names'] = [namesAttribute];
189
+ }
190
+ if (Object.keys(addresses).length > 0) {
191
+ createPersonPayload['addresses'] = [addresses];
192
+ }
193
+ if (attributes.length > 0) {
194
+ createPersonPayload['attributes'] = attributes;
195
+ }
196
+ return createPersonPayload;
197
+ }
198
+ function generateNextOfKinAndAlternateContactDetails(alternativeContacts: AlternateContact[]) {
199
+ const attributes = [];
200
+ const alterNativeClientContact = alternativeContacts.find((a) => {
201
+ return a.relationship === 'Alternative Phone Number';
202
+ });
203
+ const nextOfKinContact = alternativeContacts.find((a) => {
204
+ return a.remarks === 'Next Of Kin';
205
+ });
206
+ if (alterNativeClientContact) {
207
+ if (alterNativeClientContact.contact_type === 'Phone') {
208
+ attributes.push({
209
+ value: alterNativeClientContact.contact_id,
210
+ attributeType: PersonAttributeTypeUuids.ALTERNATIVE_CONTACT_PHONE_NUMBER_UUID,
211
+ });
212
+ }
213
+ }
214
+ if (nextOfKinContact) {
215
+ if (nextOfKinContact.contact_type === 'Phone') {
216
+ attributes.push({
217
+ value: nextOfKinContact.contact_id,
218
+ attributeType: PersonAttributeTypeUuids.NEXT_OF_KIN_CONTACT_PHONE_NUMBER_UUID,
219
+ });
220
+ }
221
+ attributes.push({
222
+ value: nextOfKinContact.relationship,
223
+ attributeType: PersonAttributeTypeUuids.NEXT_OF_KIN_RELATIONSHIP_UUID,
224
+ });
225
+ attributes.push({
226
+ value: nextOfKinContact.contact_name,
227
+ attributeType: PersonAttributeTypeUuids.NEXT_OF_KIN_NAME_UUID,
228
+ });
229
+ }
230
+ return attributes;
231
+ }
232
+ function getAmrsConceptUuidFromField(fieldName: string): string {
233
+ let conceptUuid = '';
234
+ switch (fieldName) {
235
+ case 'Divorced':
236
+ conceptUuid = CivilStatusUids.DIVORCED_UUID;
237
+ break;
238
+ case 'Married':
239
+ conceptUuid = CivilStatusUids.MARRIED_UUID;
240
+ break;
241
+ case 'Single':
242
+ conceptUuid = CivilStatusUids.SINGLE_UUID;
243
+ break;
244
+ default:
245
+ conceptUuid = CivilStatusUids.NOT_APPLICABLE_UUID;
246
+ }
247
+ return conceptUuid;
248
+ }
249
+ export function generateAmrsCreatePatientIdentifiersPayload(hieClient: HieClient, identifierLocation: string) {
250
+ const identifiers = [];
251
+ // add CR number
252
+ identifiers.push({
253
+ identifierType: getAmrsIdentifierTypeUuid(HieIdentificationType.Cr),
254
+ identifier: hieClient.id,
255
+ location: identifierLocation,
256
+ });
257
+
258
+ // add main identifier
259
+ identifiers.push({
260
+ identifierType: getAmrsIdentifierTypeUuid(hieClient.identification_type),
261
+ identifier: hieClient.identification_number,
262
+ location: identifierLocation,
263
+ });
264
+
265
+ // add other idenfications
266
+ hieClient.other_identifications.forEach((id) => {
267
+ identifiers.push({
268
+ identifierType: getAmrsIdentifierTypeUuid(id.identification_type),
269
+ identifier: id.identification_number,
270
+ location: identifierLocation,
271
+ });
272
+ });
273
+
274
+ return identifiers;
275
+ }
276
+
277
+ export function getAmrsIdentifierTypeUuid(hieIdentifierName: string) {
278
+ let idTypeUuid;
279
+ switch (hieIdentifierName) {
280
+ case HieIdentificationType.NationalID:
281
+ idTypeUuid = IdentifierTypesUuids.NATIONAL_ID_UUID;
282
+ break;
283
+ case HieIdentificationType.HouseholdNumber:
284
+ idTypeUuid = IdentifierTypesUuids.HOUSE_HOLD_NUMBER_UUID;
285
+ break;
286
+ case HieIdentificationType.AlienID:
287
+ idTypeUuid = IdentifierTypesUuids.ALIEN_ID_UUID;
288
+ break;
289
+ case HieIdentificationType.SHANumber:
290
+ idTypeUuid = IdentifierTypesUuids.SHA_UUID;
291
+ break;
292
+ case HieIdentificationType.MandateNumber:
293
+ idTypeUuid = IdentifierTypesUuids.MANDATE_NUMBER_UUID;
294
+ break;
295
+ case HieIdentificationType.RefugeeID:
296
+ idTypeUuid = IdentifierTypesUuids.REFUGEE_ID_UUID;
297
+ break;
298
+ case HieIdentificationType.Cr:
299
+ idTypeUuid = IdentifierTypesUuids.CLIENT_REGISTRY_NO_UUID;
300
+ break;
301
+ case HieIdentificationType.BirthCertificate:
302
+ idTypeUuid = IdentifierTypesUuids.BIRTH_CERTIFICATE_NUMBER_UUID;
303
+ break;
304
+ case HieIdentificationType.TemporaryDependantID:
305
+ idTypeUuid = IdentifierTypesUuids.TEMPORARY_DEPENDANT_ID_UUID;
306
+ break;
307
+ }
308
+ return idTypeUuid;
309
+ }