Skip to content

Commit

Permalink
(fix) O3-4218: Auto generated identifiers with manual entry are not s…
Browse files Browse the repository at this point in the history
…aved (#1386)
  • Loading branch information
ynurmahomed authored Dec 4, 2024
1 parent f512ae8 commit 8f389a7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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<PatientIdentifierValue>(patientIdentifiers).filter(
([key, value]) => value.identifierValue !== undefined,
Object.entries(patientIdentifiers).filter(
([key, value]) =>
(value.autoGeneration && value.selectedSource.autoGenerationOption.manualEntryEnabled) ||
value.identifierValue !== undefined,
),
);

Expand Down

0 comments on commit 8f389a7

Please sign in to comment.