import React, { useState, useEffect } from 'react'; import usePatientInfo from '../../hooks/usePatientInfo'; import { Icons } from '@ohif/ui-next'; export enum PatientInfoVisibility { VISIBLE = 'visible', VISIBLE_COLLAPSED = 'visibleCollapsed', DISABLED = 'disabled', VISIBLE_READONLY = 'visibleReadOnly', } const formatWithEllipsis = (str, maxLength) => { if (str?.length > maxLength) { return str.substring(0, maxLength) + '...'; } return str; }; function HeaderPatientInfo({ servicesManager, appConfig }: withAppTypes) { const initialExpandedState = appConfig.showPatientInfo === PatientInfoVisibility.VISIBLE || appConfig.showPatientInfo === PatientInfoVisibility.VISIBLE_READONLY; const [expanded, setExpanded] = useState(initialExpandedState); const { patientInfo, isMixedPatients } = usePatientInfo(servicesManager); useEffect(() => { if (isMixedPatients && expanded) { setExpanded(false); } }, [isMixedPatients, expanded]); const handleOnClick = () => { if (!isMixedPatients && appConfig.showPatientInfo !== PatientInfoVisibility.VISIBLE_READONLY) { setExpanded(!expanded); } }; const formattedPatientName = formatWithEllipsis(patientInfo.PatientName, 27); const formattedPatientID = formatWithEllipsis(patientInfo.PatientID, 15); return (