import type { AuditEvent, Bundle } from 'fhir/r4'; const CONDITION_REF = /^Condition\/([A-Za-z0-9._-]+)$/; /** Condition ids from DELETE AuditEvents (`entity.what.reference` = Condition/{id}). * FHIR DELETE drops SEARCH; Provenance search requires `target`. */ export function conditionIdsDeletedInAudit(bundle: Bundle | undefined): string[] { const ids = new Set(); for (const entry of bundle?.entry ?? []) { const event = entry.resource; if (!event || event.resourceType !== 'AuditEvent') continue; if (event.action && event.action !== 'D') continue; for (const entity of event.entity ?? []) { const match = CONDITION_REF.exec(entity.what?.reference ?? ''); if (match) ids.add(match[1]); } } return [...ids]; }