import React from 'react'; import { ImmunizationRecommendation } from 'fhir/r4'; import { FhirCodeableConceptDisplay } from '../../utils/fhirCodeableConcept'; 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 FhirImmunizationRecommendationDisplayProps { immunizationRecommendation: ImmunizationRecommendation; isOpen: boolean; onClose: () => void; title?: string; } export const FhirImmunizationRecommendationDisplay: React.FC = ({ immunizationRecommendation, isOpen, onClose, title = "Immunization Recommendation Details" }) => { const renderDoseNumberValue = (recommendation: any) => { if (recommendation.doseNumberPositiveInt) { return recommendation.doseNumberPositiveInt.toString(); } if (recommendation.doseNumberString) { return recommendation.doseNumberString; } return '-'; }; const renderSeriesDosesValue = (recommendation: any) => { if (recommendation.seriesDosesPositiveInt) { return recommendation.seriesDosesPositiveInt.toString(); } if (recommendation.seriesDosesString) { return recommendation.seriesDosesString; } return '-'; }; // Nested one level inside `renderRecommendations()` -- each `recommendation[]` entry embeds its // own `dateCriterion[]`. Kept as its own function (rather than inlined) so the doubly-nested // Card-in-Card structure stays readable: a "Date Criterion" card renders inside a "Recommendation" // card's CardContent. const renderDateCriteria = (dateCriteria: any[] | undefined) => { if (!dateCriteria || dateCriteria.length === 0) { return (

No date criteria recorded

); } return (
{dateCriteria.map((criterion, index) => (
Date Criterion {index + 1}
{renderField('Type of date', )} {renderField('Recommended date', formatDateTime(criterion.value))}
))}
); }; const renderRecommendations = () => { if (!immunizationRecommendation.recommendation || immunizationRecommendation.recommendation.length === 0) { return (

No recommendations recorded

); } return (
{immunizationRecommendation.recommendation.map((recommendation, index) => (
Recommendation {index + 1}
{renderField('Vaccine recommendation status', )} {renderField('Vaccine recommendation status reason', )} {renderField('Vaccine or vaccine group recommendation applies to', )} {renderField('Disease to be immunized against', )} {renderField('Vaccine which is contraindicated to fulfill the recommendation', )} {renderField('Description', recommendation.description || '')} {renderField('Name of vaccination series', recommendation.series)} {renderField('Recommended dose number within series', renderDoseNumberValue(recommendation))} {renderField('Recommended number of doses for immunity', renderSeriesDosesValue(recommendation))} {renderField('Past immunizations supporting recommendation', )} {renderField('Supporting patient information', )}
Dates governing proposed immunization
{renderDateCriteria(recommendation.dateCriterion)}
))}
); }; // `immunizationRecommendation` 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 // `immunizationRecommendation.*` so a non-ImmunizationRecommendation/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('Date recommendation(s) created', formatDateTime(immunizationRecommendation.date), 'date')} {renderField('Patient', )} {renderField('Authority', )}
{renderRecommendations()}
); }; export default FhirImmunizationRecommendationDisplay;