import type { CarePlan } from 'fhir/r4'; // What a care plan is CALLED, in one place. // // THE RULE WAS WRITTEN FOUR TIMES AND ONE COPY WAS WRONG. The record's plan list read // `category[0].text` - a classification most plans share - so a plan called "Blood pressure management" // appeared as "Assessment and Plan of Treatment", and one called "Knee recovery" appeared as "Plan name // not available" while its name was stored and present. // // THE THREE CORRECT COPIES ARE WHY IT SURVIVED. Every other surface named a plan properly, so nothing in // the product contradicted the wrong one: a clinician seeing the right name in the sheet and the wrong // one in the list reads two screens showing different things, not one of them being incorrect. // // DESCRIPTION BEFORE THE PLACEHOLDER, and never the category. A description is the plan's own words about // itself; a category is a label it shares with every other assessment-and-plan, and a wrong value that // looks right is harder to notice than a missing one. /** * @param whenUnnamed what to show when the plan has neither a title nor a description. REQUIRED, and * deliberately not defaulted: the words differ by audience - a patient's own list says "Care plan", a * staff surface says the name is not available - and a default here would quietly impose one surface's * voice on the next caller. What must not differ is the RULE, which is why the rest is not a parameter. */ export const carePlanName = (plan: CarePlan | undefined, whenUnnamed: string): string => plan?.title?.trim() || plan?.description?.trim() || whenUnnamed;