import React from 'react'; import { EpisodeOfCare } from 'fhir/r4'; import { FhirCodeableConceptDisplay } from '../../utils/fhirCodeableConcept'; import { FhirCodeDisplay } from '../../utils/fhirCode'; import { FhirPeriodDisplay } from '../../utils/fhirPeriod'; 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 FhirEpisodeOfCareDisplayProps { episodeOfCare: EpisodeOfCare; isOpen: boolean; onClose: () => void; title?: string; } export const FhirEpisodeOfCareDisplay: React.FC = ({ episodeOfCare, isOpen, onClose, title = "Episode of Care Details" }) => { const renderDiagnoses = () => { if (!episodeOfCare.diagnosis || episodeOfCare.diagnosis.length === 0) { return (

No diagnoses recorded

); } return (
{episodeOfCare.diagnosis.map((diagnosis, index) => (
Diagnosis {index + 1}
{renderField('Conditions/problems/diagnoses this episode of care is for', )} {renderField('Role that this diagnosis has within the episode of care (e.g. admission, billing, discharge …)', )} {renderField('Ranking of the diagnosis (for each role type)', diagnosis.rank?.toString())}
))}
); }; const renderStatusHistory = () => { if (!episodeOfCare.statusHistory || episodeOfCare.statusHistory.length === 0) { return (

No status history recorded

); } return (
{episodeOfCare.statusHistory.map((statusHistory, index) => (
Status History {index + 1}
{renderField('Status', )} {renderField('Duration the EpisodeOfCare was in the specified status', )}
))}
); }; // `episodeOfCare` 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 // `episodeOfCare.*` so a non-EpisodeOfCare/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('Status', , 'status')} {renderField('Type/class - e.g. specialist referral, disease management', )} {renderField('Interval during responsibility is assumed', )} {renderField('Care manager/care coordinator for the patient', )} {renderField('Other practitioners facilitating this episode of care', )} {renderField('Patient', )} {renderField('Organization that assumes care', )}
{renderDiagnoses()}
{renderStatusHistory()}
); }; export default FhirEpisodeOfCareDisplay;