import React from 'react'; import { Annotation } from 'fhir/r4'; import { formatDate } from './dateUtils'; interface FhirAnnotationDisplayProps { annotation: Annotation | Annotation[] | undefined | null; className?: string; emptyText?: string; multiple?: boolean; } export const formatFhirAnnotation = (annotation: Annotation | undefined | null): string => { if (!annotation) { return ''; } return annotation.text || ''; }; export const FhirAnnotationDisplay: React.FC = ({ annotation, className, emptyText = '', multiple = false }) => { if (!annotation || (Array.isArray(annotation) && annotation.length === 0)) { return {emptyText || '-'}; } if (multiple && Array.isArray(annotation)) { return (
{annotation.map((note, index) => (
{note.text || '-'}
{(note.authorString || note.time) && (
{note.authorString && `By: ${note.authorString}`} {note.authorString && note.time && ' • '} {note.time && formatDate(note.time)}
)}
))}
); } const singleAnnotation = Array.isArray(annotation) ? annotation[0] : annotation; const formattedAnnotation = formatFhirAnnotation(singleAnnotation); return (
{formattedAnnotation || emptyText || '-'}
{singleAnnotation && (singleAnnotation.authorString || singleAnnotation.time) && (
{singleAnnotation.authorString && `By: ${singleAnnotation.authorString}`} {singleAnnotation.authorString && singleAnnotation.time && ' • '} {singleAnnotation.time && formatDate(singleAnnotation.time)}
)}
); };