import type { Patient } from 'fhir/r4'; const PROJECTION_TAG = { system: 'http://terminology.hl7.org/CodeSystem/v3-ObservationValue', code: 'SUBSETTED' }; const EDIT_PRECONDITION_URL = 'https://akashichealthrecords.com/fhir/StructureDefinition/demographic-edit-precondition'; type Marked = { meta?: Patient['meta'] }; /** A record the server sent as its demographic projection: what it left out is unknown, and only those fields save. */ export const isDemographicProjection = (record: Marked | undefined): boolean => (record?.meta?.tag ?? []).some((tag) => tag.system === PROJECTION_TAG.system && tag.code === PROJECTION_TAG.code); /** The signed baseline an affiliation-only editor saves against in place of a version it is never shown. */ export const editPreconditionOf = (record: Marked | undefined): string | undefined => record?.meta?.extension?.find((extension) => extension.url === EDIT_PRECONDITION_URL)?.valueString || undefined;