import type { NutritionOrder } from 'fhir/r4'; /** * What a nutrition order's oral diet is, line by line, for its list row: the diet's types first (their text, or a * coding's display), then its textures. A coded diet filed from a note carries its type and no texture, and reading * textures alone called it "not available" while its type was right there. */ export const dietLines = (order: NutritionOrder): string[] => { const diet = order.oralDiet; const types = (diet?.type ?? []) .map((type) => type.text?.trim() || type.coding?.find((coding) => coding.display?.trim())?.display?.trim()) .filter((line): line is string => Boolean(line)); const textures = (diet?.texture ?? []) .map((texture) => texture.foodType?.text?.trim()) .filter((line): line is string => Boolean(line)); return [...types, ...textures]; };