openmrs-esm-core

O3 Framework / selectPreferredName

Function: selectPreferredName()

selectPreferredName(patient, …preferredNames): undefined | HumanName

Defined in: packages/framework/esm-utils/src/patient-helpers.ts:60

Select the preferred name from the collection of names associated with a patient.

Names may be specified with a usage such as ‘usual’, ‘official’, ‘nickname’, ‘maiden’, etc. A name with no usage specified is treated as the ‘usual’ name.

The chosen name will be selected according to the priority order of preferredNames.

Parameters

patient

Patient

The patient from whom a name will be selected.

preferredNames

NameUse[]

Optional ordered sequence of preferred name usages; defaults to ‘usual’ if not specified.

Returns

undefined | HumanName

The preferred name for the patient, or undefined if no acceptable name could be found.

Example

// normal use case; prefer usual name, fallback to official name
selectPreferredName(patient, 'usual', 'official')

// prefer usual name over nickname, fallback to official name
selectPreferredName(patient, 'usual', 'nickname', 'official')