import type { Identifier, Patient } from "fhir/r4"; const MR_TYPE_CODE = "MR"; const IMPORT_SOURCE_ID_SYSTEM = /\/fhir\/import\/[^/]+\/source-id$/; // Only an identifier typed MR is a medical record number; any other one (an SSN, an import's // old-system id) shown under that label would misname it, and an SSN would be exposed in full. export const getMedicalRecordNumber = (patient: Patient): string => (patient.identifier ?? []).find((identifier: Identifier) => identifier.type?.coding?.some((coding) => coding.code === MR_TYPE_CODE), )?.value ?? ""; export const getImportSourceId = (patient: Patient): string => (patient.identifier ?? []).find((identifier: Identifier) => IMPORT_SOURCE_ID_SYSTEM.test(identifier.system ?? ""), )?.value ?? "";