import React, { useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, Layer, OverflowMenu, SkeletonPlaceholder, Tag } from '@carbon/react'; import { age, ConfigurableLink, ErrorState, getCoreTranslation, PatientPhoto, useConfig } from '@openmrs/esm-framework'; import EmptyState from '../empty-state/empty-state.component'; import QueuePriority from '../queue-table/components/queue-priority.component'; import { useActionOverflowMenuItems } from '../queue-table/cells/queue-table-action-cell.component'; import { useConcept } from '../hooks/useConcept'; import { useQueueEntries } from '../hooks/useQueueEntries'; import { useServiceQueuesStore } from '../store/store'; import { type ConfigObject, type QueueEntryAction } from '../config-schema'; import { type QueueEntry } from '../types'; import styles from './attending-patients.scss'; const collapsedCardCount = 3; const cardActions: QueueEntryAction[] = ['move', 'edit', 'remove', 'undo']; interface AttendingPatientsProps { /** Scope to a single queue. Without it, the selected location and service are used. */ queueUuid?: string; } // Renders patients currently being attended (queue entries with an "In Service" status) as cards. const AttendingPatients: React.FC = ({ queueUuid }) => { const { t } = useTranslation(); const { concepts: { defaultTransitionStatus }, } = useConfig(); const { selectedServiceUuid, selectedQueueLocationUuid } = useServiceQueuesStore(); const { concept: inServiceStatus } = useConcept(defaultTransitionStatus); const heading = inServiceStatus?.display ?? t('inService', 'In Service'); const searchCriteria = useMemo( () => queueUuid ? { queue: queueUuid, status: defaultTransitionStatus, isEnded: false } : { service: selectedServiceUuid, location: selectedQueueLocationUuid, status: defaultTransitionStatus, isEnded: false, }, [queueUuid, selectedServiceUuid, selectedQueueLocationUuid, defaultTransitionStatus], ); const { queueEntries, isLoading, error } = useQueueEntries(searchCriteria); const [showAll, setShowAll] = useState(false); const visibleEntries = showAll ? queueEntries : queueEntries.slice(0, collapsedCardCount); return (

{heading}

{!isLoading && !error && {queueEntries.length}} {queueEntries.length > collapsedCardCount && ( )}
{isLoading ? (
{Array.from({ length: collapsedCardCount }, (_, index) => ( ))}
) : error ? ( ) : queueEntries.length === 0 ? ( ) : (
{visibleEntries.map((queueEntry) => ( ))}
)}
); }; function AttendingPatientCard({ queueEntry }: { queueEntry: QueueEntry }) { const { t } = useTranslation(); const { customPatientChartUrl, priorityConfigs } = useConfig(); const { person } = queueEntry.patient; const actionItems = useActionOverflowMenuItems(cardActions, queueEntry); const demographics = [ person?.gender ? getGenderLabel(person.gender) : null, person?.birthdate ? age(person.birthdate) : null, ] .filter(Boolean) .join(' ยท '); // The service row sits below the link, so the card's bottom bar and its menu are outside the chart link's hitbox. return (
{person?.display}

{demographics}

{queueEntry.queue?.display} {actionItems}
); } function getGenderLabel(gender: string) { switch (gender.charAt(0).toUpperCase()) { case 'F': return getCoreTranslation('female', 'Female'); case 'M': return getCoreTranslation('male', 'Male'); case 'O': return getCoreTranslation('other', 'Other'); default: return getCoreTranslation('unknown', 'Unknown'); } } export default AttendingPatients;