@ampath/esm-patient-registration-app 9.2.0-next.22 → 9.2.0-next.25

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.
@@ -183,9 +183,9 @@
183
183
  "entry": false,
184
184
  "recorded": false,
185
185
  "reason": "split chunk (cache group: default)",
186
- "size": 257118,
186
+ "size": 259242,
187
187
  "sizes": {
188
- "javascript": 257118
188
+ "javascript": 259242
189
189
  },
190
190
  "names": [],
191
191
  "idHints": [],
@@ -199,7 +199,7 @@
199
199
  "auxiliaryFiles": [
200
200
  "1453.js.map"
201
201
  ],
202
- "hash": "f43343547e89aa18",
202
+ "hash": "0eb2769a1830d106",
203
203
  "childrenByOrder": {}
204
204
  },
205
205
  {
@@ -1235,9 +1235,9 @@
1235
1235
  "initial": false,
1236
1236
  "entry": false,
1237
1237
  "recorded": false,
1238
- "size": 145351,
1238
+ "size": 153684,
1239
1239
  "sizes": {
1240
- "javascript": 145351
1240
+ "javascript": 153684
1241
1241
  },
1242
1242
  "names": [],
1243
1243
  "idHints": [],
@@ -1250,7 +1250,7 @@
1250
1250
  "auxiliaryFiles": [
1251
1251
  "7821.js.map"
1252
1252
  ],
1253
- "hash": "1a4a403e9b256933",
1253
+ "hash": "b8fb692f41156a1d",
1254
1254
  "childrenByOrder": {}
1255
1255
  },
1256
1256
  {
@@ -1420,10 +1420,10 @@
1420
1420
  "initial": true,
1421
1421
  "entry": true,
1422
1422
  "recorded": false,
1423
- "size": 2686905,
1423
+ "size": 2695238,
1424
1424
  "sizes": {
1425
1425
  "consume-shared": 168,
1426
- "javascript": 2664369,
1426
+ "javascript": 2672702,
1427
1427
  "share-init": 336,
1428
1428
  "runtime": 22032
1429
1429
  },
@@ -1440,7 +1440,7 @@
1440
1440
  "auxiliaryFiles": [
1441
1441
  "main.js.map"
1442
1442
  ],
1443
- "hash": "a045cfc08fd05906",
1443
+ "hash": "f2d7ffbaa324c733",
1444
1444
  "childrenByOrder": {}
1445
1445
  },
1446
1446
  {
package/dist/routes.json CHANGED
@@ -1 +1 @@
1
- {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"webservices.rest":">=2.2.0"},"pages":[{"component":"root","route":"patient-registration","online":true,"offline":true},{"component":"editPatient","routeRegex":"patient\\/([a-zA-Z0-9\\-]+)\\/edit","online":true,"offline":true}],"extensions":[{"component":"addPatientLink","name":"add-patient-action","slot":"top-nav-actions-slot","online":true,"offline":true,"order":30},{"component":"patientPhotoExtension","name":"patient-photo-widget","slot":"patient-photo-slot","online":true,"offline":true},{"component":"editPatientDetailsButton","name":"edit-patient-details-button","slot":"patient-actions-slot","online":true,"offline":true},{"component":"editPatientDetailsButton","name":"edit-patient-details-button","slot":"patient-search-actions-slot","online":true,"offline":true},{"component":"clientRegistryVerificationTag","name":"client-registry-verification-tag","slot":"patient-banner-tags-slot","online":true,"offline":true}],"modals":[{"name":"cancel-patient-edit-modal","component":"cancelPatientEditModal"},{"name":"delete-identifier-confirmation-modal","component":"deleteIdentifierConfirmationModal"},{"name":"client-registry-verification-modal","component":"clientRegistryVerificationModal"}],"version":"9.2.0-next.22"}
1
+ {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"webservices.rest":">=2.2.0"},"pages":[{"component":"root","route":"patient-registration","online":true,"offline":true},{"component":"editPatient","routeRegex":"patient\\/([a-zA-Z0-9\\-]+)\\/edit","online":true,"offline":true}],"extensions":[{"component":"addPatientLink","name":"add-patient-action","slot":"top-nav-actions-slot","online":true,"offline":true,"order":30},{"component":"patientPhotoExtension","name":"patient-photo-widget","slot":"patient-photo-slot","online":true,"offline":true},{"component":"editPatientDetailsButton","name":"edit-patient-details-button","slot":"patient-actions-slot","online":true,"offline":true},{"component":"editPatientDetailsButton","name":"edit-patient-details-button","slot":"patient-search-actions-slot","online":true,"offline":true},{"component":"clientRegistryVerificationTag","name":"client-registry-verification-tag","slot":"patient-banner-tags-slot","online":true,"offline":true}],"modals":[{"name":"cancel-patient-edit-modal","component":"cancelPatientEditModal"},{"name":"delete-identifier-confirmation-modal","component":"deleteIdentifierConfirmationModal"},{"name":"client-registry-verification-modal","component":"clientRegistryVerificationModal"}],"version":"9.2.0-next.25"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampath/esm-patient-registration-app",
3
- "version": "9.2.0-next.22",
3
+ "version": "9.2.0-next.25",
4
4
  "description": "Patient registration microfrontend for O3",
5
5
  "browser": "dist/openmrs-esm-patient-registration-app.js",
6
6
  "main": "src/index.ts",
@@ -86,6 +86,8 @@ export interface RegistrationConfig {
86
86
  registrationFormUuid: string | null;
87
87
  };
88
88
  freeTextFieldConceptUuid: string;
89
+ hieBaseUrl: string;
90
+ subDomainUrl: string;
89
91
  }
90
92
 
91
93
  export const builtInSections: Array<SectionDefinition> = [
@@ -416,6 +418,16 @@ export const esmPatientRegistrationSchema = {
416
418
  _type: Type.ConceptUuid,
417
419
  _default: '5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
418
420
  },
421
+ subDomainUrl: {
422
+ _type: Type.String,
423
+ _description: 'Subdomain e.g training,staging',
424
+ _default: '',
425
+ },
426
+ hieBaseUrl: {
427
+ _type: Type.String,
428
+ _description: 'HIE Endpoint',
429
+ _default: '',
430
+ },
419
431
  _validators: [
420
432
  validator(
421
433
  (config: RegistrationConfig) =>
@@ -102,17 +102,16 @@ async function fetchPatientIdentifierTypes(): Promise<Array<FetchedPatientIdenti
102
102
  // Primary identifier type is to be kept at the top of the list.
103
103
  const patientIdentifierTypes = patientIdentifierTypesResponse?.data?.results;
104
104
 
105
- // const primaryIdentifierTypeUuid = primaryIdentifierTypeResponse?.data?.results?.[0]?.metadataUuid;
106
- const primaryIdentifierTypeUuid = '58a4732e-1359-11df-a1f1-0026b9348838';
107
-
108
- let identifierTypes = primaryIdentifierTypeResponse?.ok
109
- ? [
110
- mapPatientIdentifierType(
111
- patientIdentifierTypes?.find((type) => type.uuid === primaryIdentifierTypeUuid),
112
- true,
113
- ),
114
- ]
115
- : [];
105
+ const primaryIdentifierTypeUuid = primaryIdentifierTypeResponse?.data?.results?.[0]?.metadataUuid;
106
+ let identifierTypes =
107
+ primaryIdentifierTypeResponse?.ok && primaryIdentifierTypeUuid
108
+ ? [
109
+ mapPatientIdentifierType(
110
+ patientIdentifierTypes?.find((type) => type.uuid === primaryIdentifierTypeUuid),
111
+ true,
112
+ ),
113
+ ]
114
+ : [];
116
115
 
117
116
  patientIdentifierTypes.forEach((type) => {
118
117
  if (type.uuid !== primaryIdentifierTypeUuid) {
@@ -1,3 +1,4 @@
1
+ import { getHieBaseUrl } from '../../utils/get-base-url';
1
2
  import {
2
3
  type ClientRegistrySearchRequest,
3
4
  type RequestCustomOtpDto,
@@ -6,8 +7,6 @@ import {
6
7
  type ValidateHieCustomOtpDto,
7
8
  } from './types';
8
9
 
9
- const HIE_BASE_URL = 'https://staging.ampath.or.ke/hie';
10
-
11
10
  export type ClientRegistrySearchResponse = any[];
12
11
 
13
12
  async function postJson<T>(url: string, payload: unknown): Promise<T> {
@@ -26,7 +25,8 @@ async function postJson<T>(url: string, payload: unknown): Promise<T> {
26
25
  }
27
26
 
28
27
  export async function requestCustomOtp(payload: RequestCustomOtpDto): Promise<RequestCustomOtpResponse> {
29
- const url = `${HIE_BASE_URL}/client/send-custom-otp`;
28
+ const hieBaseUrl = await getHieBaseUrl();
29
+ const url = `${hieBaseUrl}/client/send-custom-otp`;
30
30
  const formattedPayload = {
31
31
  identificationNumber: payload.identificationNumber,
32
32
  identificationType: payload.identificationType,
@@ -36,7 +36,8 @@ export async function requestCustomOtp(payload: RequestCustomOtpDto): Promise<Re
36
36
  }
37
37
 
38
38
  export async function validateCustomOtp(payload: ValidateHieCustomOtpDto): Promise<ValidateCustomOtpResponse> {
39
- const url = `${HIE_BASE_URL}/client/validate-custom-otp`;
39
+ const hieBaseUrl = await getHieBaseUrl();
40
+ const url = `${hieBaseUrl}/client/validate-custom-otp`;
40
41
  const formattedPayload = {
41
42
  sessionId: payload.sessionId,
42
43
  otp: payload.otp,
@@ -48,7 +49,8 @@ export async function validateCustomOtp(payload: ValidateHieCustomOtpDto): Promi
48
49
  export async function fetchClientRegistryData(
49
50
  payload: ClientRegistrySearchRequest,
50
51
  ): Promise<ClientRegistrySearchResponse> {
51
- const url = `${HIE_BASE_URL}/client/search`;
52
+ const hieBaseUrl = await getHieBaseUrl();
53
+ const url = `${hieBaseUrl}/client/search`;
52
54
  const formattedPayload = {
53
55
  identificationNumber: payload.identificationNumber,
54
56
  identificationType: payload.identificationType,
@@ -12,8 +12,7 @@ import {
12
12
  type CreatePersonDto,
13
13
  } from '../client-registry/types';
14
14
  import { mapAmrsPatientRelationship } from './map-client-registry-to-form-utils';
15
-
16
- const HIE_BASE_URL = 'https://staging.ampath.or.ke/hie';
15
+ import { getHieBaseUrl } from '../../utils/get-base-url';
17
16
 
18
17
  async function postJson<T>(url: string, payload: unknown): Promise<T> {
19
18
  const response = await fetch(url, {
@@ -31,7 +30,8 @@ async function postJson<T>(url: string, payload: unknown): Promise<T> {
31
30
  }
32
31
 
33
32
  export async function requestCustomOtp(payload: RequestCustomOtpDto): Promise<RequestCustomOtpResponse> {
34
- const url = `${HIE_BASE_URL}/client/send-custom-otp`;
33
+ const hieBaseUrl = await getHieBaseUrl();
34
+ const url = `${hieBaseUrl}/client/send-custom-otp`;
35
35
  const formattedPayload = {
36
36
  identificationNumber: payload.identificationNumber,
37
37
  identificationType: payload.identificationType,
@@ -41,7 +41,8 @@ export async function requestCustomOtp(payload: RequestCustomOtpDto): Promise<Re
41
41
  }
42
42
 
43
43
  export async function validateCustomOtp(payload: ValidateHieCustomOtpDto): Promise<ValidateCustomOtpResponse> {
44
- const url = `${HIE_BASE_URL}/client/validate-custom-otp`;
44
+ const hieBaseUrl = await getHieBaseUrl();
45
+ const url = `${hieBaseUrl}/client/validate-custom-otp`;
45
46
  const formattedPayload = {
46
47
  sessionId: payload.sessionId,
47
48
  otp: payload.otp,
@@ -53,7 +54,8 @@ export async function validateCustomOtp(payload: ValidateHieCustomOtpDto): Promi
53
54
  export async function fetchClientRegistryData(
54
55
  payload: ClientRegistrySearchRequest,
55
56
  ): Promise<ClientRegistrySearchResponse> {
56
- const url = `${HIE_BASE_URL}/client/search`;
57
+ const hieBaseUrl = await getHieBaseUrl();
58
+ const url = `${hieBaseUrl}/client/search`;
57
59
  const formattedPayload = {
58
60
  identificationNumber: payload.identificationNumber,
59
61
  identificationType: payload.identificationType,
@@ -1,13 +1,15 @@
1
1
  import { FormManager } from './form-manager';
2
2
  import { type FormValues } from './patient-registration.types';
3
- import { generateIdentifier } from './patient-registration.resource';
3
+ import { generateAmrsUniversalIdentifier, generateIdentifier } from './patient-registration.resource';
4
4
 
5
5
  jest.mock('./patient-registration.resource', () => ({
6
6
  ...jest.requireActual('./patient-registration.resource'),
7
7
  generateIdentifier: jest.fn(),
8
+ generateAmrsUniversalIdentifier: jest.fn(),
8
9
  }));
9
10
 
10
11
  const mockGenerateIdentifier = generateIdentifier as jest.Mock;
12
+ const mockGenerateAmrsUniversalId = generateAmrsUniversalIdentifier as jest.Mock;
11
13
 
12
14
  const formValues: FormValues = {
13
15
  patientUuid: '',
@@ -55,12 +57,24 @@ const formValues: FormValues = {
55
57
  autoGenerationOption: { manualEntryEnabled: true, automaticGenerationEnabled: false },
56
58
  },
57
59
  },
60
+ amrsUniversalId: {
61
+ identifierUuid: 'aUuid2',
62
+ identifierName: 'AmrsUniversalId',
63
+ required: false,
64
+ initialValue: '',
65
+ identifierValue: '',
66
+ identifierTypeUuid: '58a4732e-1359-11df-a1f1-0026b9348838',
67
+ preferred: true,
68
+ autoGeneration: null,
69
+ selectedSource: null,
70
+ },
58
71
  },
59
72
  };
60
73
 
61
74
  describe('FormManager', () => {
62
75
  describe('createIdentifiers', () => {
63
76
  it('uses the uuid of a field name if it exists', async () => {
77
+ mockGenerateAmrsUniversalId.mockReturnValue('123450-6');
64
78
  const result = await FormManager.savePatientIdentifiers(true, undefined, formValues.identifiers, {}, 'Nyc');
65
79
  expect(result).toEqual([
66
80
  {
@@ -70,6 +84,13 @@ describe('FormManager', () => {
70
84
  location: 'Nyc',
71
85
  preferred: true,
72
86
  },
87
+ {
88
+ uuid: null,
89
+ identifier: '123450-6',
90
+ identifierType: '58a4732e-1359-11df-a1f1-0026b9348838',
91
+ location: 'Nyc',
92
+ preferred: true,
93
+ },
73
94
  ]);
74
95
  });
75
96
 
@@ -222,7 +222,22 @@ export class FormManager {
222
222
  initialIdentifierValues: FormValues['identifiers'], // Initial identifiers assigned to the patient
223
223
  location: string,
224
224
  ): Promise<Array<PatientIdentifier>> {
225
- let identifierTypeRequests = Object.values(patientIdentifiers)
225
+ // if its a new patient then generate the amrsUniversalId on the fly
226
+ let amrsIdRequest = [];
227
+ if (isNewPatient) {
228
+ const identifier = await generateAmrsUniversalIdentifier();
229
+ amrsIdRequest.push({
230
+ identifierTypeUuid: '58a4732e-1359-11df-a1f1-0026b9348838',
231
+ identifierValue: identifier,
232
+ identifierUuid: null,
233
+ selectedSource: null,
234
+ preferred: true,
235
+ autoGeneration: null,
236
+ initialValue: null,
237
+ });
238
+ }
239
+ const res = [...Object.values(patientIdentifiers), ...amrsIdRequest];
240
+ let identifierTypeRequests = [...Object.values(patientIdentifiers), ...amrsIdRequest]
226
241
  /* Since default identifier-types will be present on the form and are also in the not-required state,
227
242
  therefore we might be running into situations when there's no value and no source associated,
228
243
  hence filtering these fields out.
@@ -243,17 +258,13 @@ export class FormManager {
243
258
 
244
259
  const autoGenerationManualEntry =
245
260
  autoGeneration && selectedSource?.autoGenerationOption?.manualEntryEnabled && !!identifierValue;
246
- let identifier;
247
- if (identifierTypeUuid === '58a4732e-1359-11df-a1f1-0026b9348838') {
248
- identifier = await generateAmrsUniversalIdentifier();
249
- } else {
250
- identifier =
251
- !autoGeneration || autoGenerationManualEntry
252
- ? identifierValue
253
- : await (
254
- await generateIdentifier(selectedSource.uuid)
255
- ).data.identifier;
256
- }
261
+ const identifier =
262
+ !autoGeneration || autoGenerationManualEntry
263
+ ? identifierValue
264
+ : await (
265
+ await generateIdentifier(selectedSource.uuid)
266
+ ).data.identifier;
267
+
257
268
  const identifierToCreate = {
258
269
  uuid: identifierUuid,
259
270
  identifier,
@@ -1,6 +1,7 @@
1
1
  import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
2
2
  import { type Patient, type Relationship, type PatientIdentifier, type Encounter } from './patient-registration.types';
3
3
  import dayjs from 'dayjs';
4
+ import { getSubDomainUrl } from '../utils/get-base-url';
4
5
 
5
6
  export const uuidIdentifier = '05a29f94-c0ed-11e2-94be-8c13b969e334';
6
7
  export const uuidTelephoneNumber = '14d4f066-15f5-102d-96e4-000c29c2a5d7';
@@ -58,9 +59,10 @@ export function generateIdentifier(source: string) {
58
59
  });
59
60
  }
60
61
 
61
- export async function generateAmrsUniversalIdentifier() {
62
+ export async function generateAmrsUniversalIdentifier(): Promise<string> {
63
+ const subDomainUrl = await getSubDomainUrl();
62
64
  const abortController = new AbortController();
63
- const resp = await openmrsFetch(`https://staging.ampath.or.ke/amrs-id-generator/generateidentifier`, {
65
+ const resp = await openmrsFetch(`${subDomainUrl}/amrs-id-generator/generateidentifier`, {
64
66
  headers: {
65
67
  'Content-Type': 'application/json',
66
68
  },
@@ -0,0 +1,12 @@
1
+ import { getConfig } from '@openmrs/esm-framework';
2
+ import { moduleName } from '../constants';
3
+
4
+ export async function getHieBaseUrl() {
5
+ const { hieBaseUrl } = await getConfig(moduleName);
6
+ return hieBaseUrl ?? null;
7
+ }
8
+
9
+ export async function getSubDomainUrl() {
10
+ const { subDomainUrl } = await getConfig(moduleName);
11
+ return subDomainUrl ?? null;
12
+ }