import type { PractitionerRole } from 'fhir/r4'; /** * The roles a person actually HOLDS, as opposed to every role ever minted for them. * * `active: false` is this system's soft-delete for a PractitionerRole. Revoking an agency assignment * deactivates the role it minted rather than deleting it, deliberately, so the record can still answer * what access somebody had and when. * * THE DEFECT THIS IS NAMED FOR, measured on staging 2026-08-29. An agency staffer assigned to one * practice, holding one job function, read as "Dana Reyes - 4 roles" on that practice's own staff * directory, because every assign/unassign cycle had left a deactivated role behind. A practice reading * that row would reasonably conclude somebody had been granted more than they have, and on a permissions * screen that is the worst available thing to be wrong about. * * `active !== false` rather than `active === true`, matching every other reader of this field in the * product: a role with no `active` at all is live. Treating an absent flag as deactivated would hide * legitimate roles, which is the same defect pointing the other way. */ export const heldPractitionerRoles = ( roles: readonly PractitionerRole[] | undefined | null, ): PractitionerRole[] => (roles ?? []).filter((role) => role.active !== false);