@kenyaemr/esm-patient-registration-app 8.0.3-pre.140 → 8.0.3-pre.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/routes.json CHANGED
@@ -1 +1 @@
1
- {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"webservices.rest":"^2.24.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},{"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}],"modals":[{"name":"cancel-patient-edit-modal","component":"cancelPatientEditModal"},{"name":"delete-identifier-confirmation-modal","component":"deleteIdentifierConfirmationModal"},{"component":"emptyClientRegistryModal","name":"empty-client-registry-modal"},{"component":"confirmClientRegistryModal","name":"confirm-client-registry-modal"},{"component":"hieConfirmationModal","name":"hie-confirmation-modal"}],"version":"8.0.3-pre.140"}
1
+ {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"webservices.rest":"^2.24.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},{"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}],"modals":[{"name":"cancel-patient-edit-modal","component":"cancelPatientEditModal"},{"name":"delete-identifier-confirmation-modal","component":"deleteIdentifierConfirmationModal"},{"component":"emptyClientRegistryModal","name":"empty-client-registry-modal"},{"component":"confirmClientRegistryModal","name":"confirm-client-registry-modal"},{"component":"hieConfirmationModal","name":"hie-confirmation-modal"}],"version":"8.0.3-pre.143"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kenyaemr/esm-patient-registration-app",
3
- "version": "8.0.3-pre.140",
3
+ "version": "8.0.3-pre.143",
4
4
  "description": "Patient registration microfrontend for the OpenMRS SPA",
5
5
  "browser": "dist/kenyaemr-esm-patient-registration-app.js",
6
6
  "main": "src/index.ts",
@@ -14,15 +14,13 @@ const DependentInfo: React.FC<{ dependents: any[] }> = ({ dependents }) => {
14
14
  const name = dependent?.name?.text;
15
15
  const relationship =
16
16
  dependent?.relationship?.[0]?.coding?.[0]?.display || t('unknownRelationship', 'Unknown');
17
+
17
18
  const nationalID = dependent?.extension?.find(
18
- (ext) =>
19
- ext.url === 'http://cr.tiberbu.app/fhir/StructureDefinition/dependants-id-number' &&
20
- ext.valueIdentifier?.type?.coding?.[0]?.code === 'national-id',
19
+ (ext) => ext?.valueIdentifier?.type?.coding?.some((coding) => coding.code === 'national-id'),
21
20
  )?.valueIdentifier?.value;
21
+
22
22
  const birthCertificate = dependent?.extension?.find(
23
- (ext) =>
24
- ext.url === 'http://cr.tiberbu.app/fhir/StructureDefinition/dependants-id-number' &&
25
- ext.valueIdentifier?.type?.coding?.[0]?.code === 'birth-certificate-number',
23
+ (ext) => ext?.valueIdentifier?.type?.coding?.some((coding) => coding.code === 'birth-certificate'),
26
24
  )?.valueIdentifier?.value;
27
25
 
28
26
  const primaryIdentifier = nationalID || birthCertificate;
@@ -34,7 +32,7 @@ const DependentInfo: React.FC<{ dependents: any[] }> = ({ dependents }) => {
34
32
  <div key={index} className={styles.dependentInfo}>
35
33
  <PatientInfo label={t('name', 'Name')} value={name} />
36
34
  <PatientInfo label={t('relationship', 'Relationship')} value={relationship} />
37
- <PatientInfo label={identifierLabel} value={primaryIdentifier} />
35
+ {primaryIdentifier && <PatientInfo label={identifierLabel} value={primaryIdentifier} />}
38
36
  </div>
39
37
  );
40
38
  })}
@@ -11,7 +11,7 @@ import { type RegistrationConfig } from '../../config-schema';
11
11
  import { useForm, Controller, type SubmitHandler } from 'react-hook-form';
12
12
  import { zodResolver } from '@hookform/resolvers/zod';
13
13
  import { fetchPatientFromHIE, mapHIEPatientToFormValues } from './hie-resource';
14
- import { type HIEPatient } from './hie-types';
14
+ import { type HIEPatientResponse, type HIEPatient } from './hie-types';
15
15
 
16
16
  type HIEClientRegistryProps = {
17
17
  props: FormikProps<FormValues>;
@@ -43,16 +43,18 @@ const HIEClientRegistry: React.FC<HIEClientRegistryProps> = ({ setInitialFormVal
43
43
  try {
44
44
  const hieClientRegistry = await fetchPatientFromHIE(data.identifierType, data.identifierValue);
45
45
 
46
- if (hieClientRegistry && hieClientRegistry.resourceType === 'Patient') {
46
+ if (hieClientRegistry && hieClientRegistry.resourceType === 'Bundle') {
47
47
  const dispose = showModal('hie-confirmation-modal', {
48
48
  patient: hieClientRegistry,
49
49
  closeModal: () => dispose(),
50
50
  onUseValues: () =>
51
- setInitialFormValues(mapHIEPatientToFormValues(hieClientRegistry as HIEPatient, props.values)),
51
+ setInitialFormValues(
52
+ mapHIEPatientToFormValues(hieClientRegistry as unknown as HIEPatientResponse, props.values),
53
+ ),
52
54
  });
53
55
  }
54
56
 
55
- if (hieClientRegistry && hieClientRegistry.resourceType === 'OperationOutcome') {
57
+ if (hieClientRegistry && hieClientRegistry?.resourceType === 'OperationOutcome') {
56
58
  const issueMessage = hieClientRegistry?.['issue']?.map((issue) => issue.diagnostics).join(', ');
57
59
  const dispose = showModal('empty-client-registry-modal', {
58
60
  onConfirm: () => dispose(),
@@ -1,6 +1,6 @@
1
1
  import capitalize from 'lodash-es/capitalize';
2
2
  import { type PatientIdentifierValue, type FormValues } from '../../patient-registration/patient-registration.types';
3
- import { type MapperConfig, type HIEPatient, type ErrorResponse } from './hie-types';
3
+ import { type MapperConfig, type HIEPatient, type ErrorResponse, type HIEPatientResponse } from './hie-types';
4
4
  import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
5
5
  import { v4 } from 'uuid';
6
6
  import { z } from 'zod';
@@ -13,7 +13,6 @@ class HealthInformationExchangeClient<T> {
13
13
  async fetchResource(resourceType: string, params: Record<string, string>): Promise<T> {
14
14
  const [identifierType, identifierValue] = Object.entries(params)[0];
15
15
  const url = `${restBaseUrl}/kenyaemr/getSHAPatient/${identifierValue}/${identifierType}`;
16
-
17
16
  const response = await openmrsFetch(url);
18
17
  return response.json();
19
18
  }
@@ -35,19 +34,19 @@ class Mapper<T, U> {
35
34
  /**
36
35
  * Maps HIEPatient objects to FormValues objects.
37
36
  */
38
- class PatientMapper extends Mapper<HIEPatient, FormValues> {
39
- mapHIEPatientToFormValues(hiePatient: HIEPatient, currentFormValues: FormValues): FormValues {
37
+ class PatientMapper extends Mapper<HIEPatientResponse, FormValues> {
38
+ mapHIEPatientToFormValues(hiePatient: HIEPatientResponse, currentFormValues: FormValues): FormValues {
40
39
  const { familyName, givenName, middleName } = getPatientName(hiePatient);
41
- const telecom = hiePatient.telecom || [];
40
+ const telecom = hiePatient?.entry[0]?.resource.telecom || [];
42
41
 
43
42
  const telecomAttributes = this.mapTelecomToAttributes(telecom);
44
43
  const updatedIdentifiers = this.mapIdentifiers(hiePatient, currentFormValues);
45
- const extensionAddressEntries = this.mapExtensionsToAddress(hiePatient.extension);
44
+ const extensionAddressEntries = this.mapExtensionsToAddress(hiePatient?.entry[0]?.resource.extension);
46
45
 
47
46
  return {
48
- isDead: hiePatient.deceasedBoolean || false,
49
- gender: hiePatient.gender || '',
50
- birthdate: hiePatient.birthDate || '',
47
+ isDead: hiePatient?.entry[0]?.resource?.active || false,
48
+ gender: hiePatient?.entry[0]?.resource.gender || '',
49
+ birthdate: hiePatient?.entry[0]?.resource?.birthDate || '',
51
50
  givenName,
52
51
  familyName,
53
52
  telephoneNumber: telecom.find((t) => t.system === 'phone')?.value || '',
@@ -73,7 +72,7 @@ class PatientMapper extends Mapper<HIEPatient, FormValues> {
73
72
  }
74
73
 
75
74
  private mapIdentifiers(
76
- hiePatient: HIEPatient,
75
+ hiePatient: HIEPatientResponse,
77
76
  currentFormValues: FormValues,
78
77
  ): Record<string, PatientIdentifierValue> {
79
78
  const updatedIdentifiers: Record<string, PatientIdentifierValue> = { ...currentFormValues.identifiers };
@@ -81,11 +80,11 @@ class PatientMapper extends Mapper<HIEPatient, FormValues> {
81
80
  // See https://github.com/palladiumkenya/openmrs-module-kenyaemr/blob/1e1d281eaba8041c45318e60ca0730449b8e4197/api/src/main/distro/metadata/identifierTypes.xml#L33
82
81
  updatedIdentifiers.socialHealthAuthorityIdentificationNumber = {
83
82
  ...currentFormValues.identifiers['socialHealthAuthorityIdentificationNumber'],
84
- identifierValue: hiePatient.id,
83
+ identifierValue: hiePatient?.entry[0]?.resource?.id,
85
84
  };
86
85
 
87
86
  // Map fhir.Patient.Identifier to identifiers
88
- hiePatient.identifier?.forEach((identifier: fhir.Identifier) => {
87
+ hiePatient.entry[0]?.resource.identifier?.forEach((identifier: fhir.Identifier) => {
89
88
  const identifierType = identifier.type?.coding?.[0]?.code;
90
89
  const mappedIdentifierType = this.convertToCamelCase(identifierType);
91
90
  const identifierValue = identifier.value;
@@ -159,7 +158,10 @@ export const fetchPatientFromHIE = async (
159
158
  return hieApiClient.fetchResource('Patient', { [identifierType]: identifierValue });
160
159
  };
161
160
 
162
- export const mapHIEPatientToFormValues = (hiePatient: HIEPatient, currentFormValues: FormValues): FormValues => {
161
+ export const mapHIEPatientToFormValues = (
162
+ hiePatient: HIEPatientResponse,
163
+ currentFormValues: FormValues,
164
+ ): FormValues => {
163
165
  return patientMapper.mapHIEPatientToFormValues(hiePatient, currentFormValues);
164
166
  };
165
167
 
@@ -169,7 +171,7 @@ export const mapHIEPatientToFormValues = (hiePatient: HIEPatient, currentFormVal
169
171
  * @returns {string} - The masked data
170
172
  */
171
173
  export const maskData = (data: string): string => {
172
- const maskedData = data.slice(0, 2) + '*'.repeat(data.length - 2);
174
+ const maskedData = data.slice(0, 2) + '*'.repeat(Math.max(0, data.length - 2));
173
175
  return maskedData;
174
176
  };
175
177
 
@@ -178,10 +180,13 @@ export const maskData = (data: string): string => {
178
180
  * @param patient {fhir.Patient} - The FHIR Patient resource
179
181
  * @returns {object} - The patient name
180
182
  */
181
- export const getPatientName = (patient: fhir.Patient) => {
182
- const familyName = patient?.name[0]?.['family'] ?? '';
183
- const givenName = patient.name[0]?.['given']?.[0]?.split(' ')?.[0] ?? '';
184
- const middleName = patient.name[0]?.['given']?.[0]?.replace(givenName, '')?.trim() ?? '';
183
+ export const getPatientName = (patient: HIEPatientResponse) => {
184
+ const familyName = patient?.entry?.[0]?.resource?.name?.[0]?.family ?? ''; // Safely access the family name
185
+ const givenNames = patient?.entry?.[0]?.resource?.name?.[0]?.given ?? []; // Safely access the given names array
186
+
187
+ const givenName = givenNames?.[0] ?? ''; // The first item is the given name (first name)
188
+ const middleName = givenNames.slice(1).join(' ').trim(); // Combine all other given names as middle name(s)
189
+
185
190
  return { familyName, givenName, middleName };
186
191
  };
187
192
 
@@ -5,6 +5,106 @@ export type HIEPatient = fhir.Patient & {
5
5
  }>;
6
6
  };
7
7
 
8
+ export interface HIEPatientResponse {
9
+ id: string;
10
+ meta: Metadata;
11
+ link: Link[];
12
+ entry: Entry[];
13
+ }
14
+
15
+ interface Metadata {
16
+ lastUpdated: string;
17
+ }
18
+
19
+ interface Link {
20
+ relation: string;
21
+ url: string;
22
+ }
23
+
24
+ interface Entry {
25
+ resource: Resource;
26
+ }
27
+
28
+ interface Resource {
29
+ id: string;
30
+ extension: Extension[];
31
+ identifier: Identifier[];
32
+ active: boolean;
33
+ name: Name[];
34
+ telecom: Telecom[];
35
+ birthDate: string;
36
+ address: Address[];
37
+ gender: string;
38
+ maritalStatus: MaritalStatus;
39
+ contact: Contact[];
40
+ }
41
+
42
+ interface Extension {
43
+ url: string;
44
+ valueString: string;
45
+ }
46
+
47
+ interface Identifier {
48
+ type: CodingType;
49
+ value: string;
50
+ }
51
+
52
+ interface CodingType {
53
+ coding: Coding[];
54
+ }
55
+
56
+ interface Coding {
57
+ system?: string;
58
+ code: string;
59
+ display: string;
60
+ }
61
+
62
+ interface Name {
63
+ text: string;
64
+ family: string;
65
+ given: string[];
66
+ }
67
+
68
+ interface Telecom {
69
+ system: string;
70
+ value?: string;
71
+ }
72
+
73
+ interface Address {
74
+ extension: AddressExtension[];
75
+ city: string;
76
+ country: string;
77
+ }
78
+
79
+ interface AddressExtension {
80
+ url: string;
81
+ valueString: string;
82
+ }
83
+
84
+ interface MaritalStatus {
85
+ coding: Coding[];
86
+ }
87
+
88
+ interface Contact {
89
+ id: string;
90
+ extension: ContactExtension[];
91
+ relationship: Relationship[];
92
+ name: Name;
93
+ telecom: Telecom[];
94
+ address: Address;
95
+ gender: string;
96
+ }
97
+
98
+ interface ContactExtension {
99
+ url: string;
100
+ valueIdentifier?: Identifier;
101
+ valueString?: string;
102
+ }
103
+
104
+ interface Relationship {
105
+ coding: Coding[];
106
+ }
107
+
8
108
  export type APIClientConfig = {
9
109
  baseUrl: string;
10
110
  credentials: string;
@@ -1,7 +1,7 @@
1
1
  import { Button, ModalBody, ModalFooter, ModalHeader } from '@carbon/react';
2
2
  import React, { useState } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
- import { type HIEPatient } from '../hie-types';
4
+ import { type HIEPatientResponse, type HIEPatient } from '../hie-types';
5
5
  import styles from './confirm-hie.scss';
6
6
  import { authorizationFormSchema, generateOTP, getPatientName, persistOTP, sendOtp, verifyOtp } from '../hie-resource';
7
7
  import HIEPatientDetailPreview from './hie-patient-detail-preview.component';
@@ -14,7 +14,7 @@ import { showSnackbar } from '@openmrs/esm-framework';
14
14
 
15
15
  interface HIEConfirmationModalProps {
16
16
  closeModal: () => void;
17
- patient: HIEPatient;
17
+ patient: HIEPatientResponse;
18
18
  onUseValues: () => void;
19
19
  }
20
20
 
@@ -22,9 +22,11 @@ const HIEConfirmationModal: React.FC<HIEConfirmationModalProps> = ({ closeModal,
22
22
  const { t } = useTranslation();
23
23
  const [mode, setMode] = useState<'authorization' | 'preview'>('preview');
24
24
  const [status, setStatus] = useState<'loadingOtp' | 'otpSendSuccessfull' | 'otpFetchError'>();
25
- const phoneNumber = patient?.telecom?.find((num) => num.value)?.value;
25
+ const phoneNumber = patient?.entry[0]?.resource.telecom?.find((num) => num.system === 'phone')?.value;
26
26
  const getidentifier = (code: string) =>
27
- patient?.identifier?.find((identifier) => identifier?.type?.coding?.some((coding) => coding?.code === code));
27
+ patient?.entry[0]?.resource.identifier?.find(
28
+ (identifier) => identifier?.type?.coding?.some((coding) => coding?.code === code),
29
+ );
28
30
  const patientId = patient?.id ?? getidentifier('SHA-number')?.value;
29
31
  const form = useForm<z.infer<typeof authorizationFormSchema>>({
30
32
  defaultValues: {
@@ -7,16 +7,19 @@ import DependentInfo from '../dependants/dependants.component';
7
7
  import { getPatientName, maskData } from '../hie-resource';
8
8
  import PatientInfo from '../patient-info/patient-info.component';
9
9
  import styles from './confirm-hie.scss';
10
+ import { type HIEPatientResponse } from '../hie-types';
10
11
 
11
12
  type HIEPatientDetailPreviewProps = {
12
- patient: fhir.Patient;
13
+ patient: HIEPatientResponse;
13
14
  };
14
15
 
15
16
  const HIEPatientDetailPreview: React.FC<HIEPatientDetailPreviewProps> = ({ patient }) => {
16
17
  const { familyName, givenName, middleName } = getPatientName(patient);
17
18
  const { t } = useTranslation();
18
19
  const getidentifier = (code: string) =>
19
- patient?.identifier?.find((identifier) => identifier?.type?.coding?.some((coding) => coding?.code === code));
20
+ patient?.entry[0]?.resource.identifier?.find(
21
+ (identifier) => identifier?.type?.coding?.some((coding) => coding?.code === code),
22
+ );
20
23
 
21
24
  return (
22
25
  <>
@@ -41,21 +44,22 @@ const HIEPatientDetailPreview: React.FC<HIEPatientDetailPreviewProps> = ({ patie
41
44
  }
42
45
  />
43
46
 
44
- <PatientInfo label={t('age', 'Age')} value={age(patient?.birthDate)} />
45
- <PatientInfo label={t('dateOfBirth', 'Date of birth')} value={formatDate(new Date(patient?.birthDate))} />
46
- <PatientInfo label={t('gender', 'Gender')} value={capitalize(patient?.gender)} />
47
+ <PatientInfo label={t('age', 'Age')} value={age(patient?.entry[0]?.resource.birthDate)} />
48
+ <PatientInfo
49
+ label={t('dateOfBirth', 'Date of birth')}
50
+ value={formatDate(new Date(patient?.entry[0]?.resource?.birthDate))}
51
+ />
52
+ <PatientInfo label={t('gender', 'Gender')} value={capitalize(patient?.entry[0]?.resource.gender)} />
47
53
  <PatientInfo
48
54
  label={t('maritalStatus', 'Marital status')}
49
- value={patient?.maritalStatus?.coding?.map((m) => m.code).join('')}
55
+ value={patient?.entry[0]?.resource.maritalStatus?.coding?.map((m) => m.code).join('')}
50
56
  />
51
57
 
52
- {(!patient?.contact || patient?.contact.length === 0) && (
53
- <PatientInfo label={t('dependents', 'Dependents')} value="--" />
54
- )}
58
+ {!patient?.entry[0]?.resource.contact && <PatientInfo label={t('dependents', 'Dependents')} value="--" />}
55
59
  </div>
56
60
  </div>
57
61
 
58
- <DependentInfo dependents={patient?.contact} />
62
+ <DependentInfo dependents={patient?.entry[0]?.resource.contact} />
59
63
 
60
64
  <div>
61
65
  <Accordion>
@@ -416,7 +416,7 @@ export const esmPatientRegistrationSchema = {
416
416
  },
417
417
  },
418
418
  _default: [
419
- { identifierType: 'National ID', identifierValue: 'national-id' },
419
+ { identifierType: 'National ID', identifierValue: 'National ID' },
420
420
  { identifierType: 'Passport Number', identifierValue: 'passport-number' },
421
421
  { identifierType: 'Birth Certificate Number', identifierValue: 'birth-certificate-number' },
422
422
  { identifierType: 'Alien ID Number', identifierValue: 'alien-id-number' },