import type { CodeableConcept, Reference } from "fhir/r4"; const named = (value: string | undefined) => value?.trim() || undefined; /** * The medicine a medication order or statement records by name: its concept's text, then a coding's display, then the * display given with a referenced Medication. Undefined when none names it; a reference or id is never a name. */ export const medicationNameOf = ( record: { medicationCodeableConcept?: CodeableConcept; medicationReference?: Reference } | undefined, ): string | undefined => named(record?.medicationCodeableConcept?.text) ?? record?.medicationCodeableConcept?.coding?.map((coding) => named(coding.display)).find(Boolean) ?? named(record?.medicationReference?.display);