import React from "react"; import { Dosage, MedicationStatement } from "fhir/r4"; import { SheetDescription, SheetHeader } from "../ui/sheet"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs"; import { Card, CardContent, CardHeader } from "../ui/card"; import { Clock, Syringe, TriangleAlert, Zap } from "lucide-react"; import { formatDateForDisplay } from "../../lib/utils"; 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 { FhirRatioDisplay } from "../../utils/fhirRatio"; import { FieldHistoryProvider, FieldHistoryScope, } from "../FieldHistory/FieldHistoryProvider"; import { ShowFieldHistoryToggle } from "../FieldHistory/ShowFieldHistoryToggle"; import { RecordEditedMarker } from "../FieldHistory/RecordEditedMarker"; import { Field } from "../FieldHistory/Field"; import { FieldGroup } from "../FieldHistory/FieldLayout"; import { StatusBadge } from "../ui/status"; import { medicationNameOf } from "../../utils/medicationName"; interface FhirMedicationStatementDisplayProps { medicationStatement: MedicationStatement; isOpen: boolean; onClose: () => void; title?: string; } export const FhirMedicationStatementDisplay: React.FC< FhirMedicationStatementDisplayProps > = ({ medicationStatement, 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 statusPill = ; // effective[x] is polymorphic: either a dateTime or a Period, never both. const effectiveField: { label: string; value: React.ReactNode } = medicationStatement.effectiveDateTime ? { label: "Effective Date", value: formatDateForDisplay(medicationStatement.effectiveDateTime), } : medicationStatement.effectivePeriod ? { label: "Effective Period", value: ( ), } : { label: "Effective Date", value: undefined }; // dosage[x].asNeeded[x] is polymorphic: a boolean or a CodeableConcept. const renderAsNeeded = (dosage: Dosage): React.ReactNode => { if (dosage.asNeededCodeableConcept) { return ( ); } if (dosage.asNeededBoolean !== undefined) { return dosage.asNeededBoolean ? "Yes" : "No"; } return undefined; }; return (
{title || "Medication Statement Details"}

{medicationNameOf(medicationStatement) ?? "No name provided"}

Overview Dosage Details } path="category.coding[0].display" /> } /> } /> } /> } /> } /> } />
Dosages {medicationStatement.dosage && medicationStatement.dosage.length > 0 ? ( medicationStatement.dosage.map((dos, index) => (
Dosage {index + 1}

Timing

Route

As Needed

{renderAsNeeded(dos)}

} /> } /> } />

Maximum Dose Limits

} /> } /> } />
)) ) : (

No dosage instructions recorded

)}
} /> } /> } />
); }; export default FhirMedicationStatementDisplay;