// The owner record stores `Practitioner/` and auth carries the bare id; same person, exact id, as the server's isSamePractitioner. export const referencesPractitioner = (reference: string | undefined, practitionerId: string | undefined): boolean => { const bare = (value: string | undefined) => (value?.startsWith('Practitioner/') ? value.slice('Practitioner/'.length) : value); const left = bare(reference); const right = bare(practitionerId); return Boolean(left && right && left === right); }; /** An owner as read for one practice. */ export interface OwnerRead { organizationId: string; practitionerId: string | undefined; } // A read belongs to the practice it was made for; on any other practice it marks nobody. export const ownerOf = (read: OwnerRead | undefined, organizationId: string | undefined): string | undefined => read && organizationId && read.organizationId === organizationId ? read.practitionerId : undefined;