import React from "react"; import { CodeableConcept, Location } from "fhir/r4"; import { Dialog, DialogContent, DialogTitle } from "../ui/dialog"; import { FhirCodeableConceptDisplay } from "../../utils/fhirCodeableConcept"; import { FHIRAddressDisplay } from "../../utils/fhirAddress"; import { FHIRContactPointDisplay } from "../../utils/fhirContactPoint"; import { FhirIdentifierDisplay } from "../../utils/fhirIdentifier"; import { FhirOperationalHoursDisplay } from "../../utils/fhirOperationalHours"; import { FhirReferenceDisplay } from "../../utils/fhirReference"; import { FieldHistoryProvider, FieldHistoryScope, } from "../FieldHistory/FieldHistoryProvider"; import { ShowFieldHistoryToggle } from "../FieldHistory/ShowFieldHistoryToggle"; import { RecordEditedMarker } from "../FieldHistory/RecordEditedMarker"; import { Field } from "../FieldHistory/Field"; import { FieldGroup, Section } from "../FieldHistory/FieldLayout"; import { StatusBadge } from "../ui/status"; interface FhirLocationDisplayProps { location: Location; isOpen?: boolean; onClose?: () => void; title?: string; asModal?: boolean; } // / D5 - was a hand-rolled pill: a local STATUS_STYLES record of hardcoded hex pairs // applied as an INLINE STYLE, with the raw FHIR code as the text. Colour-only, non-token, and one // of twelve near-identical copies. carries the shared word plus D5's colour AND shape. const renderStatusPill = (status: string | undefined): React.ReactNode => ( ); /** * `FhirCodeableConceptDisplay` renders `concept.text` only. `Location.type` entries are commonly * coded without a `.text` convenience string (the old code's fallback was the fake literal * "General Service", not real data) -- this backfills `.text` from `coding[0].display` before * handing off to the shared display component, same fix `FhirHealthcareServiceDisplay` applies. */ function withCodeableConceptTextFallback( input: CodeableConcept | CodeableConcept[] | undefined, ): CodeableConcept | CodeableConcept[] | undefined { if (!input) { return input; } const applyFallback = (concept: CodeableConcept): CodeableConcept => ({ ...concept, text: concept.text || concept.coding?.[0]?.display, }); return Array.isArray(input) ? input.map(applyFallback) : applyFallback(input); } export const FhirLocationDisplay: React.FC = ({ location, isOpen = true, onClose, title = "Location Details", asModal = true, }) => { const renderAliases = (): React.ReactNode => { if (!location.alias || location.alias.length === 0) return undefined; return location.alias.join(", "); }; const renderContent = () => (

{title}

{location.description && (

{location.description}

)}
} /> } /> } /> } /> } /> } /> } />
); if (!asModal) { return (
{renderContent()}
); } if (!isOpen) return null; return ( { if (!next) onClose?.(); }} > {title} {renderContent()} ); }; export default FhirLocationDisplay;