import React from 'react'; import { Immunization } from 'fhir/r4'; import { FhirCodeableConceptDisplay } from '../../utils/fhirCodeableConcept'; import { FhirCodeDisplay } from '../../utils/fhirCode'; import { FhirQuantityDisplay } from '../../utils/fhirQuantity'; import { FhirAnnotationDisplay } from '../../utils/fhirAnnotation'; import { formatDate, 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 FhirImmunizationDisplayProps { immunization: Immunization; isOpen: boolean; onClose: () => void; title?: string; } export const FhirImmunizationDisplay: React.FC = ({ immunization, isOpen, onClose, title = "Immunization Details" }) => { const renderDoseNumberValue = (protocol: any) => { if (protocol.doseNumberPositiveInt) { return protocol.doseNumberPositiveInt.toString(); } if (protocol.doseNumberString) { return protocol.doseNumberString; } return '-'; }; const renderSeriesDosesValue = (protocol: any) => { if (protocol.seriesDosesPositiveInt) { return protocol.seriesDosesPositiveInt.toString(); } if (protocol.seriesDosesString) { return protocol.seriesDosesString; } return '-'; }; const renderPerformers = () => { if (!immunization.performer || immunization.performer.length === 0) { return (

No performers recorded

); } return (
{immunization.performer.map((performer, index) => (
Performer {index + 1}
{renderField('What type of performance was done', )} {renderField('Who performed event', )}
))}
); }; const renderReactions = () => { if (!immunization.reaction || immunization.reaction.length === 0) { return (

No reactions recorded

); } return (
{immunization.reaction.map((reaction, index) => (
Reaction {index + 1}
{renderField('Date', formatDateTime(reaction.date))} {renderField('Additional information on reaction', )} {renderField('Reported', reaction.reported === true ? 'Yes' : 'No')}
))}
); }; const renderProtocolApplied = () => { if (!immunization.protocolApplied || immunization.protocolApplied.length === 0) { return (

No protocols recorded

); } return (
{immunization.protocolApplied.map((protocol, index) => (
Protocol {index + 1}
{renderField('Name of vaccine series', protocol.series)} {renderField('Vaccine preventable disease being targeted', )} {renderField('Dose number within series', renderDoseNumberValue(protocol))} {renderField('Recommended number of doses for immunity', renderSeriesDosesValue(protocol))} {renderField('Authority', )}
))}
); }; const renderEducation = () => { if (!immunization.education || immunization.education.length === 0) { return (

No educational materials recorded

); } return (
{immunization.education.map((education, index) => (
Educational Material {index + 1}
{renderField('Type of educational material', education.documentType)} {renderField('Reference to educational material', education.reference ? ( {education.reference} ) : '-')} {renderField('Educational material publication date', formatDateTime(education.publicationDate))} {renderField('Educational material presentation date', formatDateTime(education.presentationDate))}
))}
); }; // `immunization` 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 // `immunization.*` so a non-Immunization/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('Vaccine product administered', , 'vaccineCode.coding[0].display')} {renderField('Status', , 'status')} {immunization.status === 'not-done' && renderField('Reason not done', , 'statusReason.coding[0].display')} {renderField('Vaccine lot number', immunization.lotNumber, 'lotNumber')} {renderField('Manufacturer', immunization.manufacturer?.display || immunization.manufacturer?.identifier?.value, 'manufacturer')} {renderField('Vaccine expiration date', formatDate(immunization.expirationDate), 'expirationDate')} {renderField('Vaccine administration date', formatDateTime(immunization.occurrenceDateTime), 'occurrenceDateTime')} {renderField('When the immunization was first captured in the subject\'s record', formatDateTime(immunization.recorded), 'recorded')} {renderField('Primary Source', immunization.primarySource === true ? 'Yes' : 'No', 'primarySource')} {immunization.primarySource === false && renderField('Source of a secondarily reported record', , 'reportOrigin.coding[0].display')} {renderField('Encounter immunization was part of', )} {renderField('Where immunization occurred', )}
{renderField('Body site vaccine was administered', , 'site.coding[0].display')} {renderField('How vaccine entered body', , 'route.coding[0].display')} {renderField('Dose Quantity', , 'doseQuantity.value')} {renderField('Subpotent Dose', immunization.isSubpotent === true ? 'Yes' : 'No', 'isSubpotent')} {immunization.isSubpotent && renderField('Reason for being subpotent', )}
{renderField('Why immunization occurred', )} {renderField('Patient eligibility for a vaccination program', )} {renderField('Funding source for the vaccine', , 'fundingSource.coding[0].display')} {renderField('Why immunization occurred (References)', )}
{renderProtocolApplied()}
{renderReactions()}
{renderPerformers()}
{renderEducation()}
{renderField('Additional immunization notes', )}
); }; export default FhirImmunizationDisplay;