import { CONSENT_INSTRUMENTS } from '../../../config/consentInstruments.ts'; import type { OrgConsentStatusesResponse } from '../../../services/OrgAuthorizationService.tsx'; /** * The board row's marker for the three agreements, or undefined when there is nothing to say. A * booking is not refused for an unanswered agreement, so this is how the desk learns before the visit * that check-in has something to record. A refusal or withdrawal is named, not counted as owed. * Undefined before the read answers, so a patient is never marked before the real status arrives. */ export const owedAgreementsFlag = (statuses: OrgConsentStatusesResponse | undefined): string | undefined => { if (!statuses) return undefined; const answers = CONSENT_INSTRUMENTS.map((instrument) => statuses.instruments[instrument]); if (answers.includes('declined')) return 'declined an agreement'; if (answers.includes('withdrawn')) return 'withdrew an agreement'; const owed = answers.filter((status) => status !== 'active').length; if (owed === 0) return undefined; return owed === 1 ? 'owes 1 agreement' : `owes ${owed} agreements`; };