import type { DocumentReference, Organization, Practitioner, Reference } from "fhir/r4"; import { formatFhirHumanName } from "../../../utils/fhirHumanName.tsx"; // A practice document is filed by the person who added it AND by the practice. The deck's row names // the person ("added 4 September 2026 by Spencer Fraise"); the practice stays an author because the // drawer lists by `author=`, and an older file with only the practice keeps naming it. export const practiceDocumentAuthors = ( practitioner: Pick | undefined, organization: Pick, ): Reference[] => { const practice: Reference = { reference: `Organization/${organization.id}`, display: organization.name }; if (practitioner?.resourceType !== "Practitioner" || !practitioner.id) return [practice]; return [ { reference: `Practitioner/${practitioner.id}`, display: formatFhirHumanName(practitioner.name) }, practice, ]; }; export const practiceDocumentAddedBy = (doc: DocumentReference): string => { const authors = doc.author ?? []; const person = authors.find((a) => a.reference?.startsWith("Practitioner/") && a.display); return person?.display ?? authors.find((a) => a.display)?.display ?? ""; };