import React from 'react'; import { Encounter } 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'; import { EncounterVisitNote } from './EncounterVisitNote'; import type { VisitNoteSource } from './useEncounterVisitNote'; interface FhirEncounterDisplayProps { encounter: Encounter; isOpen: boolean; onClose: () => void; title?: string; /** Omitted where the encounter is a past version or a bare reference: no note is shown. */ visitNote?: VisitNoteSource; } export const FhirEncounterDisplay: React.FC = ({ encounter, isOpen, onClose, title = "Encounter Details", visitNote, }) => { const renderParticipants = () => { if (!encounter.participant || encounter.participant.length === 0) { return (

No participants recorded

); } return (
{encounter.participant.map((participant, index) => (
Participant {index + 1}
{renderField('Role of participant in encounter', )} {renderField('List of participants involved in the encounter', )} {renderField('Period of time during the encounter that the participant participated', )}
))}
); }; const renderDiagnoses = () => { if (!encounter.diagnosis || encounter.diagnosis.length === 0) { return (

No diagnoses recorded

); } return (
{encounter.diagnosis.map((diagnosis, index) => (
Diagnosis {index + 1}
{renderField('The diagnosis or procedure relevant to the encounter', )} {renderField('Role that this diagnosis has within the encounter', )} {renderField('Ranking of the diagnosis (for each role type)', diagnosis.rank?.toString())}
))}
); }; const renderLocations = () => { if (!encounter.location || encounter.location.length === 0) { return (

No locations recorded

); } return (
{encounter.location.map((location, index) => (
Location {index + 1}
{renderField('Location the encounter takes place', )} {renderField('Status', )} {renderField('The physical type of the location', )} {renderField('Time period during which the patient was present at the location', )}
))}
); }; const renderStatusHistory = () => { if (!encounter.statusHistory || encounter.statusHistory.length === 0) { return (

No status history recorded

); } return (
{encounter.statusHistory.map((statusHistory, index) => (
Status History {index + 1}
{renderField('Status', )} {renderField('The time that the episode was in the specified status', )}
))}
); }; const renderClassHistory = () => { if (!encounter.classHistory || encounter.classHistory.length === 0) { return (

No class history recorded

); } return (
{encounter.classHistory.map((classHistory, index) => (
Class History {index + 1}
{renderField('Class', )} {renderField('The time that the episode was in the specified class', )}
))}
); }; if (!isOpen) return null; return ( { if (!next) onClose(); }}>
{title}
{renderField('Status', , 'status')} {renderField('Classification of patient encounter', )} {renderField('Specific type of encounter', )} {renderField('Specific type of service', , 'serviceType.coding[0].display')} {renderField('Priority', , 'priority.coding[0].display')} {renderField('The start and end time of the encounter', )} {renderField('The appointment that scheduled this encounter', )} {renderField('Another Encounter this encounter is part of', )} {renderField('Episode(s) of care that this encounter should be recorded against', )} {visitNote && }
{renderField('Reason the encounter takes place', )} {renderField('Reason the encounter takes place (reference)', )}
{renderParticipants()}
{renderDiagnoses()}
{renderLocations()}
{renderField('The location/organization from which the patient came before admission', )} {renderField('From where patient was admitted (physician referral, transfer)', , 'hospitalization.admitSource.coding[0].display')} {renderField('The type of hospital re-admission that has occurred', , 'hospitalization.reAdmission.coding[0].display')} {renderField('Diet preferences reported by the patient', )} {renderField('Special courtesies (VIP, board member)', )} {renderField('Wheelchair, translator, stretcher, etc.', )} {renderField('Location/organization to which the patient is discharged', )} {renderField('Category or kind of location after discharge', , 'hospitalization.dischargeDisposition.coding[0].display')}
{renderStatusHistory()}
{renderClassHistory()}
); }; export default FhirEncounterDisplay;