From 8f389a7d80b483915424b3c18294aaf883c18af4 Mon Sep 17 00:00:00 2001 From: Yassin Date: Wed, 4 Dec 2024 21:17:29 +0200 Subject: [PATCH] (fix) O3-4218: Auto generated identifiers with manual entry are not saved (#1386) --- .../patient-registration-utils.test.ts | 33 +++++++++++++++++++ .../patient-registration-utils.ts | 9 +++-- 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.test.ts diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.test.ts b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.test.ts new file mode 100644 index 000000000..f5b636b88 --- /dev/null +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.test.ts @@ -0,0 +1,33 @@ +import { filterOutUndefinedPatientIdentifiers } from './patient-registration-utils'; + +describe('filterOutUndefinedPatientIdentifiers', () => { + const getIdentifiers = (autoGeneration = true, manualEntryEnabled = false) => ({ + OpenMRSId: { + autoGeneration: autoGeneration, + identifierName: 'OpenMRS ID', + identifierTypeUuid: '05a29f94-c0ed-11e2-94be-8c13b969e334', + identifierValue: undefined, + initialValue: '100GEJ', + preferred: true, + required: true, + selectedSource: { + uuid: '01af8526-cea4-4175-aa90-340acb411771', + name: 'Generator for OpenMRS ID', + autoGenerationOption: { + manualEntryEnabled: manualEntryEnabled, + automaticGenerationEnabled: autoGeneration, + }, + }, + }, + }); + + it('should fitler out undefined identifiers', () => { + const filteredIdentifiers = filterOutUndefinedPatientIdentifiers(getIdentifiers()); + expect(filteredIdentifiers.OpenMRSId).not.toBeDefined(); + }); + + it('should retain auto-generated identifiers with manual entry', () => { + const filteredIdentifiers = filterOutUndefinedPatientIdentifiers(getIdentifiers(true, true)); + expect(filteredIdentifiers.OpenMRSId).toBeDefined(); + }); +}); diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts index 3aa777a2c..971543b95 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts @@ -200,10 +200,13 @@ export function getPhonePersonAttributeValueFromFhirPatient(patient: fhir.Patien return result; } -export const filterOutUndefinedPatientIdentifiers = (patientIdentifiers) => +type IdentifierMap = { [identifierFieldName: string]: PatientIdentifierValue }; +export const filterOutUndefinedPatientIdentifiers = (patientIdentifiers: IdentifierMap): IdentifierMap => Object.fromEntries( - Object.entries(patientIdentifiers).filter( - ([key, value]) => value.identifierValue !== undefined, + Object.entries(patientIdentifiers).filter( + ([key, value]) => + (value.autoGeneration && value.selectedSource.autoGenerationOption.manualEntryEnabled) || + value.identifierValue !== undefined, ), );