diff --git a/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-resource.ts b/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-resource.ts index 38f082d76..daa50292d 100644 --- a/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-resource.ts +++ b/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-resource.ts @@ -61,7 +61,7 @@ class PatientMapper extends Mapper { private mapTelecomToAttributes(telecom: Array): Record { return telecom.reduce>((acc, { system, value }) => { if (system && value && this.config.teleComMap[system]) { - const filteredValue = value.replace(/^254/, '0'); + const filteredValue = value.replace(/^\+254/, '0'); if (filteredValue) { acc[this.config.teleComMap[system]] = filteredValue; } @@ -75,22 +75,24 @@ class PatientMapper extends Mapper { currentFormValues: FormValues, ): Record { const updatedIdentifiers: Record = { ...currentFormValues.identifiers }; - // Map Social Health Authority Unique Identification Number to HIE Patient ID // See https://github.com/palladiumkenya/openmrs-module-kenyaemr/blob/1e1d281eaba8041c45318e60ca0730449b8e4197/api/src/main/distro/metadata/identifierTypes.xml#L33 - updatedIdentifiers.socialHealthAuthorityIdentificationNumber = { - ...currentFormValues.identifiers['socialHealthAuthorityIdentificationNumber'], + updatedIdentifiers.socialHealthInsuranceNumber = { + ...currentFormValues.identifiers['socialHealthInsuranceNumber'], identifierValue: hiePatient.id, }; // Map fhir.Patient.Identifier to identifiers - hiePatient.identifier?.forEach((identifier) => { - const system = identifier.system?.split('/').pop(); - if (system && this.config.identifierMap[system]) { - const key = this.config.identifierMap[system]; - updatedIdentifiers[key] = { - ...currentFormValues.identifiers[key], - identifierValue: identifier.value || '', + hiePatient.identifier?.forEach((identifier: fhir.Identifier) => { + const identifierType = identifier.type?.coding?.[0]?.code; + const mappedIdentifierType = this.convertToCamelCase(identifierType); + const identifierValue = identifier.value; + + const existingIdentifier = currentFormValues.identifiers[mappedIdentifierType]; + if (existingIdentifier) { + updatedIdentifiers[mappedIdentifierType] = { + ...existingIdentifier, + identifierValue, }; } }); @@ -117,6 +119,13 @@ class PatientMapper extends Mapper { return acc; }, {}); } + + private convertToCamelCase(input: string): string { + return input + .split('-') + .map((word, index) => (index === 0 ? word : capitalize(word))) + .join(''); + } } // Update MapperConfig interface in hie-types.ts