import React, { useCallback } from 'react'; import { Checkbox } from '@carbon/react'; import { useTranslation } from 'react-i18next'; import { type DosageInstruction, type MedicationRequestBundle } from '../types'; import { getDosageInstruction, getMedicationDisplay, getMedicationReferenceOrCodeableConcept } from '../utils'; type PrintablePrescriptionsSelectorProps = { medicationRequests: Array; excludedPrescription: Array; onExcludedPrescriptionChange: React.Dispatch>; }; const PrintablePrescriptionsSelector: React.FC = ({ medicationRequests, onExcludedPrescriptionChange, excludedPrescription, }) => { const { t } = useTranslation(); const handleChange = useCallback( (checked: boolean, medicationEventId: string) => { if (checked) { onExcludedPrescriptionChange(excludedPrescription.filter((id) => id !== medicationEventId)); } else { onExcludedPrescriptionChange([...excludedPrescription, medicationEventId]); } }, [onExcludedPrescriptionChange, excludedPrescription], ); return (

{t('selectPrescriptions', 'Check prescriptions to print')}

{medicationRequests?.map((request) => { const medicationEvent = request.request; const dosageInstruction: DosageInstruction = getDosageInstruction(medicationEvent.dosageInstruction); return (
{dosageInstruction && ( handleChange(checked, medicationEvent.id)} /> )}
); })}
); }; export default PrintablePrescriptionsSelector;