import React from 'react'; import { MedicationAdministration } from 'fhir/r4'; import { FhirCodeableConceptDisplay } from '../../utils/fhirCodeableConcept'; import { FhirCodeDisplay } from '../../utils/fhirCode'; import { FhirPeriodDisplay } from '../../utils/fhirPeriod'; import { FhirQuantityDisplay } from '../../utils/fhirQuantity'; import { FhirRatioDisplay } from '../../utils/fhirRatio'; import { FhirAnnotationDisplay } from '../../utils/fhirAnnotation'; import { formatDateTime } from '../../utils/dateUtils'; import { FhirReferenceDisplay } from '../../utils/fhirReference'; import { renderField } from '../../utils/renderField'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from '../ui/dialog'; import { Card, CardHeader, CardContent } from '../ui/card'; import { FieldHistoryProvider, FieldHistoryScope } from '../FieldHistory/FieldHistoryProvider'; import { ShowFieldHistoryToggle } from '../FieldHistory/ShowFieldHistoryToggle'; import { PrintRecord } from '../ui/print-record'; import { RecordEditedMarker } from '../FieldHistory/RecordEditedMarker'; import { FieldGroup, Section } from '../FieldHistory/FieldLayout'; interface FhirMedicationAdministrationDisplayProps { medicationAdministration: MedicationAdministration; isOpen: boolean; onClose: () => void; title?: string; } export const FhirMedicationAdministrationDisplay: React.FC = ({ medicationAdministration, isOpen, onClose, title = "Medication Administration Details" }) => { const renderEffectiveValue = () => { if (medicationAdministration.effectiveDateTime) { return formatDateTime(medicationAdministration.effectiveDateTime); } if (medicationAdministration.effectivePeriod) { return ; } return '-'; }; const renderMedicationValue = () => { if (medicationAdministration.medicationCodeableConcept) { return ; } if (medicationAdministration.medicationReference) { return ; } return '-'; }; const renderDosage = () => { if (!medicationAdministration.dosage) { return (

No dosage information recorded

); } const dosage = medicationAdministration.dosage; return (
Dosage Information
{renderField('Rate (Ratio)', )} {renderField('Rate (Quantity)', )} {renderField('Dosage Instructions', dosage.text || '', 'dosage.text')} {renderField('Body Site Administered To', )} {renderField('Path of Substance Into Body', )} {renderField('Method', )} {renderField('Dose', )}
); }; const renderPerformers = () => { if (!medicationAdministration.performer || medicationAdministration.performer.length === 0) { return (

No performers recorded

); } return (
{medicationAdministration.performer.map((performer, index) => (
Performer {index + 1}
{renderField('Type of Performance', )} {renderField('Who Performed the Medication Administration', )}
))}
); }; // `medicationAdministration` is frequently a forced cast over a union of resource types (several // callers keep one `selectedItem`/`selected.resource` and multiplex it across many `Fhir*Display` // modals, gating only via `isOpen`) -- it can be the wrong resource shape, or undefined, whenever // `isOpen` is false. This guard must run before anything below touches `medicationAdministration.*` // so a non-MedicationAdministration/absent value while closed never throws (mirrors the original // `if (!isOpen) return null;` that ran before WP's `` was ever constructed). if (!isOpen) return null; return ( { if (!next) onClose(); }} >
{title}
{renderField('What was administered', renderMedicationValue(), medicationAdministration.medicationCodeableConcept ? 'medicationCodeableConcept.coding[0].display' : undefined)} {renderField('Status', , 'status')} {renderField('Reason administration not performed', )} {renderField('Type of medication usage', , 'category.coding[0].display')} {renderField('Start and end time of administration', renderEffectiveValue(), medicationAdministration.effectiveDateTime ? 'effectiveDateTime' : undefined)} {renderField('Request administration performed against', )} {renderField('Device used to administer', )} {renderField('Encounter or Episode of Care administered as part of', )}
{renderDosage()}
{renderField('Reason administration performed', )} {renderField('Condition or observation that supports why the medication was administered', )}
{renderPerformers()}
{renderField('Part of referenced event', )}
{renderField('Information about the administration', )}
); }; export default FhirMedicationAdministrationDisplay;