import React from 'react'; import { AllergyIntolerance } from 'fhir/r4'; import { FhirCodeableConceptDisplay } from '../../utils/fhirCodeableConcept'; import { FhirCodeDisplay } from '../../utils/fhirCode'; import { FhirAgeDisplay } from '../../utils/fhirAge'; import { FhirPeriodDisplay } from '../../utils/fhirPeriod'; import { FhirRangeDisplay } from '../../utils/fhirRange'; import { FhirAnnotationDisplay } from '../../utils/fhirAnnotation'; import { formatDateTime } from '../../utils/dateUtils'; import { renderField } from '../../utils/renderField'; import { FhirReferenceDisplay } from '../../utils/fhirReference'; 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 { RecordEditedMarker } from '../FieldHistory/RecordEditedMarker'; import { FieldGroup, Section } from '../FieldHistory/FieldLayout'; import { ArchivedNotice } from '../ArchivedNotice/ArchivedNotice'; interface FhirAllergyIntoleranceDisplayProps { allergyIntolerance: AllergyIntolerance; isOpen: boolean; onClose: () => void; title?: string; } export const FhirAllergyIntoleranceDisplay: React.FC = ({ allergyIntolerance, isOpen, onClose, title = "Allergy/Intolerance Details" }) => { const renderOnsetValue = () => { if (allergyIntolerance.onsetDateTime) { return formatDateTime(allergyIntolerance.onsetDateTime); } if (allergyIntolerance.onsetAge) { return ; } if (allergyIntolerance.onsetPeriod) { return ; } if (allergyIntolerance.onsetRange) { return ; } if (allergyIntolerance.onsetString) { return allergyIntolerance.onsetString; } return '-'; }; const renderCategoryValue = () => { if (!allergyIntolerance.category || allergyIntolerance.category.length === 0) { return '-'; } return (
{allergyIntolerance.category.map((cat, index) => (
))}
); }; const renderReactions = () => { if (!allergyIntolerance.reaction || allergyIntolerance.reaction.length === 0) { return (

No reactions recorded

); } return (
{allergyIntolerance.reaction.map((reaction, index) => (
Reaction {index + 1}
{renderField('Substance', )} {renderField('Manifestation', )} {renderField('Description', reaction.description)} {renderField('Onset Date', formatDateTime(reaction.onset))} {renderField('Severity', )} {renderField('Exposure Route', )} {renderField('Notes', )}
))}
); }; // `allergyIntolerance` 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 // `allergyIntolerance.*` so a non-AllergyIntolerance/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('Allergy or Intolerance', , 'code.coding[0].display')} {renderField('Clinical Status', , 'clinicalStatus.coding[0].code')} {renderField('Verification Status', , 'verificationStatus.coding[0].code')} {renderField('Type', , 'type')} {renderField('Category', renderCategoryValue())} {renderField('Criticality', , 'criticality')} {renderField('Date Recorded', formatDateTime(allergyIntolerance.recordedDate), 'recordedDate')} {renderField('Date of Last Occurrence', formatDateTime(allergyIntolerance.lastOccurrence), 'lastOccurrence')}
{renderField('When allergy or intolerance was identified', renderOnsetValue())} {renderField('Encounter', )}
{renderReactions()}
{renderField('Additional Notes', )}
); }; export default FhirAllergyIntoleranceDisplay;