import React from "react"; import { CarePlan, CarePlanActivity } from "fhir/r4"; import { SheetBody, SheetHeader } from "../ui/sheet"; import { Calendar, ChevronRight } from "lucide-react"; import { formatDateForDisplay } from "../../lib/utils"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "../ui/accordion"; import { FhirCodeableConceptDisplay } from "../../utils/fhirCodeableConcept"; import { FhirReferenceDisplay } from "../../utils/fhirReference"; import { FhirAnnotationDisplay } from "../../utils/fhirAnnotation"; import { FhirPeriodDisplay } from "../../utils/fhirPeriod"; import { FhirQuantityDisplay } from "../../utils/fhirQuantity"; import { describeFhirTimingFully } from "../../utils/fhirTiming"; import { FieldHistoryProvider, FieldHistoryScope, } from "../FieldHistory/FieldHistoryProvider"; import { ShowFieldHistoryToggle } from "../FieldHistory/ShowFieldHistoryToggle"; import { PrintRecord } from "../ui/print-record"; import { carePlanName } from "../../utils/carePlanName"; import { RecordEditedMarker } from "../FieldHistory/RecordEditedMarker"; import { Field } from "../FieldHistory/Field"; import { FieldGroup } from "../FieldHistory/FieldLayout"; import { StatusBadge } from "../ui/status"; import { ArchivedNotice } from "../ArchivedNotice/ArchivedNotice"; interface FhirCarePlanDisplayProps { carePlan: CarePlan; isOpen: boolean; onClose: () => void; title?: string; } export const FhirCarePlanDisplay: React.FC = ({ carePlan, isOpen, title, }) => { if (!isOpen) return null; // / 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 => ( ); // detail.product[x] is polymorphic: a CodeableConcept or a Reference. const renderProductValue = (activity: CarePlanActivity): React.ReactNode => { if (activity.detail?.productCodeableConcept) { return ( ); } if (activity.detail?.productReference) { return ( ); } return undefined; }; // detail.scheduled[x] is polymorphic: a Timing, a Period, or a plain string. const renderScheduledValue = ( activity: CarePlanActivity, ): React.ReactNode => { // The schedule's name and its repeat, so a change to how often or on which days is visible. if (activity.detail?.scheduledTiming) { return describeFhirTimingFully(activity.detail.scheduledTiming) || undefined; } if (activity.detail?.scheduledPeriod) { return ; } if (activity.detail?.scheduledString) { return activity.detail.scheduledString; } return undefined; }; return (
{/* The controls wrap under the title on a narrow screen rather than run past its edge. */}
{title || "Care Plan Details"}

{carePlanName(carePlan, "Plan name not available")}

{carePlan?.meta?.lastUpdated && ( {" "} {formatDateForDisplay(carePlan.meta.lastUpdated)} )}{" "}
{/* An archived plan keeps its recorded status below; this says it is no longer the plan in use. */} Overview Activities {carePlan.intent} ) : undefined } path="intent" /> } /> } /> } /> } /> } /> } /> } /> } /> } />
{carePlan?.activity && carePlan.activity.length > 0 ? ( carePlan.activity.map((activity, index) => (
{index + 1}

{activity.detail?.code?.text || activity.detail?.code?.coding?.[0] ?.display || activity.detail?.description || activity.reference?.display || `Activity ${index + 1}`}

{activity.detail?.status && (
{renderStatusPill(activity.detail.status)}
)}
Overview Details } /> } /> } />

Classification & Status

} /> } />

Clinical Rationale

} /> } />

Medication & Dosage

} /> } />

Schedule & Location

} />

Goals & Responsibility

} /> } />
)) ) : (

No activities recorded

)}
); }; export default FhirCarePlanDisplay;