import type { CarePlan } from 'fhir/r4'; import { isArchived } from './archivedResource'; // The statuses a plan ends with. The server's stoppedCarePlan.ts names the same three, and cancels the // plan's owed tasks for any of them or for the archive marker. const ENDED_STATUSES = new Set(['revoked', 'completed', 'entered-in-error']); /** * True when the plan owes the patient nothing more: archived, or ended by its status. * * THE MARKER, NOT THE STATUS. A plan archived as "No longer applies" keeps `status: active` and says it * was archived only in its archive extension, so a status check alone reads it as current. */ export const isCarePlanStopped = (plan?: CarePlan | null): boolean => Boolean(plan) && (isArchived(plan) || ENDED_STATUSES.has(plan!.status));